__( '1. Core files', 'aftersweep' ), 2 => __( '2. Plugins', 'aftersweep' ), 3 => __( '3. Uploads folder', 'aftersweep' ), 4 => __( '4. Must-use plugins and drop-ins', 'aftersweep' ), 5 => __( '5. Accounts with high capabilities', 'aftersweep' ), 6 => __( '6. .htaccess and PHP settings files', 'aftersweep' ), 7 => __( '7. Contents', 'aftersweep' ), 8 => __( '8. Scheduled tasks', 'aftersweep' ), 9 => __( '9. Settings', 'aftersweep' ), 10 => __( '10. Not looked at', 'aftersweep' ), ); } /** Labels of the levels. */ public static function levels() { return array( 'anomaly' => __( 'Anomaly', 'aftersweep' ), 'suspect' => __( 'Suspect', 'aftersweep' ), 'to_identify' => __( 'To identify', 'aftersweep' ), ); } /** Labels of the silent counters. */ public static function counted_labels() { return array( 'plugin_extra_file' => __( 'Files other than PHP added to a plugin folder', 'aftersweep' ), 'plugin_silence_index' => __( 'Small index.php files running no code in a plugin folder', 'aftersweep' ), 'uploads_silence_index' => __( 'Empty index.php files in the uploads folder', 'aftersweep' ), 'cron_attributed' => __( 'Scheduled events attributed to the core, an active plugin or the active theme', 'aftersweep' ), 'option_plugin_rules' => __( 'Options where an installed firewall keeps its detection rules', 'aftersweep' ), ); } /** * Translated summary line. * * @param array $report Report::toArray(). * @return string Plain text. */ public static function summary_text( array $report ) { $s = $report['summary']; return Catalogue::render( Messages::summary(), array( $s['anomaly'], $s['suspect'], $s['to_identify'], $s['not_looked'] ) ); } /** * Translated texts of one finding. * * @param array $f Finding::toArray(). * @return array{compared:string, action:string, items:string[]} */ public static function finding_texts( array $f ) { $all = Messages::findings(); $tpl = isset( $all[ $f['code'] ] ) ? $all[ $f['code'] ] : array( (string) $f['compared'], (string) $f['action'] ); $out = array( 'compared' => Catalogue::render( $tpl[0], $f['args'] ), 'action' => Catalogue::render( $tpl[1], $f['args'] ), 'items' => array(), ); if ( ! empty( $f['items'] ) ) { $member = ''; foreach ( Catalogue::AGGREGATES as $code => $def ) { if ( $def[0] === $f['code'] ) { $member = $code; } } foreach ( $f['items'] as $item ) { $out['items'][] = isset( $all[ $member ] ) ? Catalogue::render( $all[ $member ][0], (array) $item['args'] ) : (string) $item['subject']; } } return $out; } /** * Lines "N more findings with the code ..." of one control (D-13). * * @param array $report Report::toArray(). * @param int $control Control number. * @return string[] */ public static function capped_lines( array $report, $control ) { $out = array(); foreach ( isset( $report['capped'] ) ? (array) $report['capped'] : array() as $code => $n ) { if ( isset( Catalogue::FINDINGS[ $code ] ) && Catalogue::FINDINGS[ $code ][0] === (int) $control ) { $out[] = Catalogue::render( Messages::capped(), array( number_format_i18n( (int) $n ), $code ) ); } } return $out; } /** * Translated text of one "Not looked at" line. * * @param array $e NotLookedEntry::toArray(). * @return string */ public static function not_looked_text( array $e ) { $all = Messages::not_looked(); return isset( $all[ $e['code'] ] ) ? Catalogue::render( $all[ $e['code'] ], $e['args'] ) : (string) $e['text']; } /** * Report::toArray() with every text translated in the current locale: each finding keeps * code and args and carries compared, action, items[].text and control_title; each * not_looked entry carries text; summary_text is translated; control_titles added. * * @param array $report Report::toArray() (English texts of the domain). * @return array */ public static function translate( array $report ) { $titles = self::control_titles(); foreach ( $report['controls'] as $i => $list ) { foreach ( $list as $n => $f ) { $t = self::finding_texts( $f ); $f['compared'] = $t['compared']; $f['action'] = $t['action']; $f['control_title'] = isset( $titles[ $f['control'] ] ) ? $titles[ $f['control'] ] : ''; foreach ( $t['items'] as $k => $text ) { $f['items'][ $k ]['text'] = $text; } $report['controls'][ $i ][ $n ] = $f; } } foreach ( $report['not_looked'] as $n => $e ) { $report['not_looked'][ $n ]['text'] = self::not_looked_text( $e ); } $report['summary_text'] = self::summary_text( $report ); $report['control_titles'] = $titles; return $report; } /** * Whole report. * * @param array $last ahcl_last_report. * @return string HTML, escaped. */ public static function report( array $last ) { $report = $last['report']; $context = $last['context']; $levels = self::levels(); $titles = self::control_titles(); ob_start(); ?>