' . wp_kses(self::credit_html(), ['a' => ['href' => true, 'class' => true, 'rel' => true, 'aria-label' => true], 'span' => ['class' => true], 'i' => ['class' => true]]) . '
'; } /* ---------- Plugins: updates and known vulnerabilities ---------- */ /** Installed plugins: slug => [file, name, version, active, update]. */ public static function installed_plugins() { if (!function_exists('get_plugins')) require_once ABSPATH . 'wp-admin/includes/plugin.php'; $up = get_site_transient('update_plugins'); $out = []; foreach (get_plugins() as $file => $p) { $slug = dirname($file); if ($slug === '.') $slug = basename($file, '.php'); $slug = strtolower($slug); if (!preg_match('/^[a-z0-9][a-z0-9._-]{0,190}$/', $slug)) continue; $new = (is_object($up) && isset($up->response[$file]) && is_object($up->response[$file]) && !empty($up->response[$file]->new_version)) ? (string) $up->response[$file]->new_version : ''; $out[$slug] = ['file' => $file, 'name' => (string) ($p['Name'] ?? $slug), 'version' => (string) ($p['Version'] ?? ''), 'active' => is_plugin_active($file) || is_plugin_active_for_network($file), 'update' => $new]; } return $out; } /** The stored answer of the last check; anything of the wrong shape is dropped. */ public static function vuln_data() { $d = get_option(self::OPT_VULNS, []); if (!is_array($d)) return []; $plugins = []; foreach ((isset($d['plugins']) && is_array($d['plugins'])) ? $d['plugins'] : [] as $slug => $row) { if (!is_array($row) || !isset($row['status'], $row['version']) || !is_scalar($row['status']) || !is_scalar($row['version'])) continue; $vs = []; foreach ((isset($row['vulns']) && is_array($row['vulns'])) ? $row['vulns'] : [] as $v) { if (!is_array($v)) continue; $x = ['cvss' => (isset($v['cvss']) && is_numeric($v['cvss'])) ? (float) $v['cvss'] : null, 'epss' => (isset($v['epss']) && is_numeric($v['epss'])) ? (float) $v['epss'] : null]; foreach (['urgent', 'kev', 'unfixed'] as $k) $x[$k] = empty($v[$k]) ? 0 : 1; foreach (['cve', 'needs', 'fixed_in', 'fixed_after', 'title', 'url'] as $k) $x[$k] = (isset($v[$k]) && is_scalar($v[$k])) ? (string) $v[$k] : ''; $vs[] = $x; } $plugins[(string) $slug] = ['status' => (string) $row['status'], 'version' => (string) $row['version'], 'closed' => empty($row['closed']) ? 0 : 1, 'closed_date' => (isset($row['closed_date']) && is_scalar($row['closed_date'])) ? (string) $row['closed_date'] : '', 'vulns' => $vs]; } return ['t' => (int) ($d['t'] ?? 0), 'tried' => (int) ($d['tried'] ?? 0), 'sig' => (isset($d['sig']) && is_string($d['sig'])) ? $d['sig'] : '', 'at' => (int) ($d['at'] ?? 0), 'plugins' => $plugins, 'alerted' => array_values(array_filter((isset($d['alerted']) && is_array($d['alerted'])) ? $d['alerted'] : [], 'is_string')), 'error' => (isset($d['error']) && is_scalar($d['error'])) ? (string) $d['error'] : '']; } /** Link to the description of a vulnerability: only the known reference sites, otherwise the CVE record. */ private static function vuln_link($url, $cve) { $host = strtolower((string) wp_parse_url((string) $url, PHP_URL_HOST)); if (strpos((string) $url, 'https://') === 0 && in_array($host, ['www.wordfence.com', 'wordfence.com', 'patchstack.com', 'wpscan.com', 'www.cve.org', 'nvd.nist.gov', 'www.wpvulnerability.com', 'www.wpvulnerability.net'], true)) return esc_url_raw((string) $url, ['https']); return $cve ? 'https://www.cve.org/CVERecord?id=' . $cve : ''; } /** * Asks data.aguard.lt which of the installed plugins have known vulnerabilities. * Runs only after an administrator has turned the check on in the Plugins tab. * Sent: the plugin slugs and their versions, with the plugin's own User-Agent (no site address). */ public static function vuln_refresh($force = false) { if (empty(self::opts()['vuln_check'])) return null; $list = []; foreach (self::installed_plugins() as $slug => $p) $list[$slug] = $p['version']; if (!$list) return null; ksort($list); $sig = md5((string) wp_json_encode($list)); $d = self::vuln_data(); $now = time(); if (!$force && $now - (int) ($d['tried'] ?? 0) < 50 * MINUTE_IN_SECONDS) return $d; if (!$force && ($d['sig'] ?? '') === $sig && $now - (int) ($d['t'] ?? 0) < 20 * HOUR_IN_SECONDS) return $d; $d['tried'] = $now; $r = wp_remote_post(self::FEED_URL, ['timeout' => 15, 'redirection' => 0, 'limit_response_size' => 512 * KB_IN_BYTES, 'user-agent' => 'AGuard Safe/' . self::VERSION, 'headers' => ['Content-Type' => 'application/json'], 'body' => wp_json_encode(['plugins' => $list])]); $code = is_wp_error($r) ? 0 : (int) wp_remote_retrieve_response_code($r); $j = $code === 200 ? json_decode((string) wp_remote_retrieve_body($r), true) : null; if (!is_array($j) || !isset($j['plugins']) || !is_array($j['plugins'])) { $d['error'] = is_wp_error($r) ? $r->get_error_message() : ($code === 200 ? __('the answer could not be read', 'aguard-safe') : 'HTTP ' . $code); update_option(self::OPT_VULNS, $d, false); return $d; } // The answer is treated as untrusted text: every field is checked and cut before it is stored. $str = function ($x, $max) { return is_scalar($x) ? substr((string) $x, 0, $max) : ''; }; $plugins = []; foreach ($j['plugins'] as $slug => $row) { $slug = (string) $slug; // json_decode turns an all-digit key into a number if (!isset($list[$slug]) || !is_array($row)) continue; $vs = []; foreach (array_slice((isset($row['vulns']) && is_array($row['vulns'])) ? $row['vulns'] : [], 0, 25) as $v) { if (!is_array($v)) continue; $cve = $str($v['cve'] ?? '', 30); if (!preg_match('/^CVE-\d{4}-\d{3,8}$/', $cve)) $cve = ''; $ver = function ($k) use ($v, $str) { return (string) preg_replace('/[^0-9A-Za-z.+-]/', '', $str($v[$k] ?? '', 30)); }; $vs[] = [ 'cve' => $cve, 'cvss' => (isset($v['cvss']) && is_numeric($v['cvss'])) ? round(min(10, max(0, (float) $v['cvss'])), 1) : null, 'epss' => (isset($v['epss']) && is_numeric($v['epss'])) ? round(min(1, max(0, (float) $v['epss'])), 3) : null, 'urgent' => empty($v['urgent']) ? 0 : 1, 'kev' => empty($v['kev']) ? 0 : 1, 'unfixed' => empty($v['unfixed']) ? 0 : 1, 'needs' => (string) preg_replace('/[^lhuca]/', '', $str($v['needs'] ?? '', 10)), 'fixed_in' => $ver('fixed_in'), 'fixed_after' => $ver('fixed_after'), 'title' => sanitize_text_field(mb_substr($str($v['title'] ?? '', 800), 0, 160)), 'url' => self::vuln_link($str($v['url'] ?? '', 300), $cve), ]; } $st = $str($row['status'] ?? '', 20); if (!in_array($st, ['vulnerable', 'ok', 'none', 'pending'], true)) $st = 'none'; if ($st === 'vulnerable' && !$vs) $st = 'ok'; $plugins[$slug] = ['status' => $st, 'version' => $list[$slug], 'closed' => empty($row['closed']) ? 0 : 1, 'closed_date' => (string) preg_replace('/[^0-9-]/', '', $str($row['closed_date'] ?? '', 10)), 'vulns' => $vs]; } // One e-mail about urgent findings that have not been reported yet. // Reported findings are remembered while that plugin version stays installed, also when an answer comes back empty for a while. $seen = array_values(array_filter((array) ($d['alerted'] ?? []), function ($k) use ($list) { $p = explode('|', (string) $k, 3); return count($p) === 3 && isset($list[$p[0]]) && (string) $list[$p[0]] === $p[1]; })); $new = []; $fresh = []; foreach ($plugins as $slug => $row) { foreach ($row['vulns'] as $v) { if (!$v['urgent']) continue; $k = $slug . '|' . $row['version'] . '|' . ($v['cve'] ?: md5($v['title'])); if (!in_array($k, $seen, true)) { $new[$slug][] = $v; $fresh[] = $k; } } } $d = ['t' => $now, 'tried' => $now, 'sig' => $sig, 'at' => (int) ($j['at'] ?? 0), 'plugins' => $plugins, 'alerted' => $seen, 'error' => '']; if ($new) { $names = self::installed_plugins(); $info = []; foreach ($new as $slug => $vs) { $parts = []; foreach (array_slice($vs, 0, 5) as $v) { /* translators: %s: plugin version number */ $parts[] = ($v['cve'] ?: $v['title']) . ($v['fixed_in'] ? ' (' . sprintf(__('fixed in %s', 'aguard-safe'), $v['fixed_in']) . ')' : ''); } $info[($names[$slug]['name'] ?? $slug) . ' ' . ($names[$slug]['version'] ?? '')] = implode(', ', $parts); } sort($fresh); $e = self::event('vuln', __('Plugins with a vulnerability that needs an urgent update:', 'aguard-safe') . ' ' . count($new), $info, true, 'vuln_' . md5(implode(',', $fresh)), DAY_IN_SECONDS); // Only the hourly e-mail limit makes the next check report the finding again. if (empty($e['data']['_note'])) $d['alerted'] = array_slice(array_merge($seen, $fresh), -500); } update_option(self::OPT_VULNS, $d, false); return $d; } /** Installed plugins joined with the last answer of the vulnerability check, worst first. */ public static function plugin_rows() { $d = self::vuln_data(); $on = !empty(self::opts()['vuln_check']); $rows = []; foreach (self::installed_plugins() as $slug => $p) { $v = $d['plugins'][$slug] ?? null; // An answer about another version of the plugin is out of date: wait for the next check. if (!$on) $state = 'off'; elseif (!is_array($v) || (string) $v['version'] !== (string) $p['version']) $state = 'wait'; else $state = $v['status']; $vs = ($state === 'vulnerable') ? $v['vulns'] : []; $urgent = 0; foreach ($vs as $x) $urgent += $x['urgent']; $closed = (is_array($v) && $on) ? (int) $v['closed'] : 0; $rank = $urgent ? 0 : ($vs ? 1 : ($closed ? 2 : ($p['update'] ? 3 : 4))); $rows[] = ['slug' => $slug, 'name' => $p['name'], 'version' => $p['version'], 'active' => $p['active'], 'update' => $p['update'], 'state' => $state, 'vulns' => $vs, 'urgent' => $urgent, 'closed' => $closed, 'closed_date' => $closed ? (string) $v['closed_date'] : '', 'rank' => $rank]; } usort($rows, function ($a, $b) { return $a['rank'] <=> $b['rank'] ?: strcasecmp($a['name'], $b['name']); }); return $rows; } public static function vuln_counts() { $c = ['urgent' => 0, 'vulnerable' => 0, 'closed' => 0, 'updates' => 0]; foreach (self::plugin_rows() as $r) { if ($r['urgent']) $c['urgent']++; if ($r['vulns']) $c['vulnerable']++; if ($r['closed']) $c['closed']++; if ($r['update']) $c['updates']++; } return $c; } /** What an attacker needs, from the letters the feed sends. */ private static function vuln_needs($s) { $m = ['l' => __('needs a signed-in user', 'aguard-safe'), 'h' => __('needs an administrator account', 'aguard-safe'), 'u' => __('needs an action by a user', 'aguard-safe'), 'c' => __('hard to exploit', 'aguard-safe'), 'a' => __('not reachable over the network', 'aguard-safe')]; $out = []; foreach (str_split((string) $s) as $ch) if (isset($m[$ch])) $out[] = $m[$ch]; return implode(', ', $out); } public static function activate() { if (!wp_next_scheduled(self::CRON)) wp_schedule_event(time() + 300, 'aguard_hourly', self::CRON); self::logins_install(); $fresh = get_option(self::OPT, null) === null; // a new install, not an update of a site that already has settings $o = self::opts(); if ($fresh) { $o['tool_files'] = (defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) ? 0 : 1; $o['tool_logs'] = 1; } if (empty($o['installed']) || $fresh) { if (empty($o['installed'])) $o['installed'] = time(); update_option(self::OPT, $o, true); self::$opts = null; } // the administrator who turns the plugin on is at a known address from the first minute if (function_exists('is_user_logged_in') && is_user_logged_in() && current_user_can('manage_options')) { $ip = (self::srv('HTTP_CF_CONNECTING_IP') ?: self::srv('REMOTE_ADDR')); $k = get_option(self::OPT . '_known_logins', []); if (!is_array($k)) $k = []; if ($ip !== '') { $k[wp_get_current_user()->user_login][$ip] = time(); update_option(self::OPT . '_known_logins', $k, false); } } self::build_baseline(); self::event('plugin', __('AGuard Safe activated', 'aguard-safe'), [], false); } public static function deactivate() { wp_clear_scheduled_hook(self::CRON); self::event('plugin', __('AGuard Safe deactivated', 'aguard-safe'), [], self::loud()); } /* ------------------------------------------------------------ helpers */ /** Notifications go to the site administrator unless another address is set in Settings. */ public static function default_mail() { return (string) get_option('admin_email'); } /** Optional read-only tools (file browser, log viewer). Off until an administrator enables them in Settings. */ public static function tool_on($tab) { $o = self::opts(); if ($tab === 'files') return !empty($o['tool_files']); if ($tab === 'logs') return !empty($o['tool_logs']); return true; } /** A sanitized $_SERVER value. */ private static function srv($k) { return isset($_SERVER[$k]) ? sanitize_text_field(wp_unslash($_SERVER[$k])) : ''; } private static function srv_uri() { return isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : ''; } public static function opts() { if (self::$opts === null) { $d = ['email' => self::default_mail(), 'notify_cc' => '', 'notify' => 1, 'notify_admin_login' => 1, 'failed_threshold' => 20, 'cloak_check' => 1, 'whitelist' => ['service-worker.js'], 'block_php_uploads' => 0, 'lockdown' => 0, 'login_slug' => '', 'login_mode' => 'off', 'twofa' => 0, 'tool_files' => 0, 'tool_logs' => 0, 'credit' => 0, 'vuln_check' => 0, 'setup_done' => 0, 'lockout' => 1, 'lockout_after' => 10, 'pw_check' => 0, 'hd_headers' => 0, 'hd_version' => 0, 'hd_users' => 0]; $o = get_option(self::OPT, []); self::$opts = is_array($o) ? array_merge($d, $o) : $d; } return self::$opts; } private static function ip() { $ip = self::srv('REMOTE_ADDR'); foreach (['HTTP_CF_CONNECTING_IP', 'HTTP_X_FORWARDED_FOR'] as $h) { if (!empty($_SERVER[$h])) { $ip .= ' (' . $h . ': ' . substr(sanitize_text_field(wp_unslash($_SERVER[$h])), 0, 80) . ')'; break; } } return $ip; } private static function who() { $u = function_exists('wp_get_current_user') ? wp_get_current_user() : null; $s = ($u && $u->ID) ? $u->user_login . ' (#' . $u->ID . ')' : (defined('DOING_CRON') && DOING_CRON ? 'cron' : (defined('WP_CLI') && WP_CLI ? 'wp-cli' : 'anonymous')); return $s . ' | IP ' . self::ip() . ' | ' . (isset($_SERVER['REQUEST_URI']) ? substr(esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])), 0, 120) : ''); } private static function ua() { return isset($_SERVER['HTTP_USER_AGENT']) ? substr(sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])), 0, 160) : ''; } /** Record an event and (optionally) e-mail it. $mail: true/false; rate-limited per $key. */ public static function event($type, $title, $data = [], $mail = true, $key = null, $ttl = 600) { $events = get_option(self::OPT_EVENTS, []); if (!is_array($events)) $events = []; if (!is_array($data)) $data = ($data === null || $data === '') ? [] : ['info' => is_scalar($data) ? (string) $data : (string) wp_json_encode($data)]; // details are always stored as a list if (strlen((string) wp_json_encode($data)) > 10000) { $data = ['_note' => __('data truncated (too large for the log)', 'aguard-safe'), 'summary' => mb_substr((string) wp_json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), 0, 4000)]; } $e = ['t' => time(), 'type' => $type, 'title' => $title, 'data' => $data, 'who' => self::who(), 'ua' => self::ua(), 'mailed' => false]; if ($mail && !empty(self::opts()['notify'])) { $key = 'aguard_safe_rl_' . md5($key === null ? $type . '|' . $title : $key); $hour = 'aguard_safe_mails_' . wp_date('YmdH'); $sent = (int) get_transient($hour); if (!get_transient($key) && $sent < 10) { set_transient($key, 1, max(60, (int) $ttl)); set_transient($hour, $sent + 1, HOUR_IN_SECONDS); $e['mailed'] = self::mail($type, $title, $data, $e); } elseif ($sent >= 10) { $e['data']['_note'] = __('e-mail not sent: limit of 10 messages per hour reached', 'aguard-safe'); } } array_unshift($events, $e); if (count($events) > self::MAX_EVENTS) $events = array_slice($events, 0, self::MAX_EVENTS); update_option(self::OPT_EVENTS, $events, false); return $e; } private static function mail($type, $title, $data, $e) { $o = self::opts(); $to = $o['email']; if (!is_email($to)) return false; $data = self::mail_short($data); // the mail shows the first lines of a long list; the whole list stays in the Events feed // Papildomi adresai (užsakovas) gauna tik incidentus – ne techninį srautą; ne daugiau 5 laiškų per parą. $critical = self::is_critical($type, $title, $data); $cc = []; if ($critical) { $cc = array_values(array_filter(array_map('trim', explode(',', (string) ($o['notify_cc'] ?? ''))), 'is_email')); if ($cc) { $dk = 'aguard_safe_cc_' . wp_date('Ymd'); $n = (int) get_transient($dk); if ($n >= 5) { $cc = []; } else { set_transient($dk, $n + 1, DAY_IN_SECONDS); } } } $site = wp_parse_url(home_url(), PHP_URL_HOST); $subj = '[AGuard Safe] ' . $site . ': ' . ($critical ? __('IMPORTANT –', 'aguard-safe') . ' ' : '') . $title; $lines = [__('Site:', 'aguard-safe') . ' ' . home_url(), __('Time:', 'aguard-safe') . ' ' . wp_date('Y-m-d H:i:s T'), __('Type:', 'aguard-safe') . ' ' . $type, __('Event:', 'aguard-safe') . ' ' . $title, '']; $w = self::who_words($e['who'], $type); array_pop($lines); if ($w[0] !== '') $lines[] = __('Who:', 'aguard-safe') . ' ' . $w[0]; if ($w[1] !== '') $lines[] = __('IP address', 'aguard-safe') . ': ' . $w[1]; if ($w[2] !== '') $lines[] = __('Address', 'aguard-safe') . ': ' . $w[2]; if ($w[1] !== '' && (string) $e['ua'] !== '') $lines[] = __('Browser:', 'aguard-safe') . ' ' . $e['ua']; $lines[] = ''; foreach ((array) $data as $k => $v) { $lines[] = $k . ': ' . (is_scalar($v) ? $v : wp_json_encode($v, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); } $lines[] = ''; $lines[] = __('View:', 'aguard-safe') . ' ' . admin_url('admin.php?page=aguard-safe'); $lines[] = '— AGuard Safe ' . self::VERSION; return self::send_html(array_merge([$to], $cc), $subj, self::mail_event_html($type, $title, $data, $e, $critical), implode("\n", $lines), self::mail_knight($type, $critical)); } /** Long lists are cut for the mail: the first MAIL_LIST lines and one line saying how many more there are. */ private static function mail_short($data, $depth = 0) { if (!is_array($data)) return $data; $list = $data && array_values($data) === $data && count(array_filter($data, 'is_scalar')) === count($data); if ($list && count($data) > self::MAIL_LIST + 2) { $more = count($data) - self::MAIL_LIST; $data = array_slice($data, 0, self::MAIL_LIST); /* translators: %d: how many more lines of a list were left out of the e-mail */ $data[] = sprintf(_n('… and %d more. The full list is in the plugin, under Events.', '… and %d more. The full list is in the plugin, under Events.', $more, 'aguard-safe'), $more); return $data; } if ($depth < 3) foreach ($data as $k => $v) if (is_array($v)) $data[$k] = self::mail_short($v, $depth + 1); return $data; } /** Who did it, in words, as in the Events feed: [name, ip, request]. An empty name means the title already says who (logins). */ private static function who_words($who, $type) { $p = array_map('trim', explode(' | ', (string) $who, 3)); $u = $p[0] ?? ''; $auto = ($u === 'cron' || $u === 'wp-cli'); if ($u === 'cron') $by = __('automatic check', 'aguard-safe'); elseif ($u === 'wp-cli') $by = __('server command line', 'aguard-safe'); elseif ($u === 'anonymous' || $u === '') $by = in_array($type, ['login', 'attack'], true) ? '' : __('visitor who is not signed in', 'aguard-safe'); else $by = $u; return [$by, $auto ? '' : (string) preg_replace('/^IP\s+/', '', $p[1] ?? ''), $auto ? '' : ($p[2] ?? '')]; } /** False when a signed-in administrator does it from an address they signed in from during the last 30 days: the owner's own routine work goes to the log, not to the mailbox. */ private static function loud() { if (!function_exists('is_user_logged_in') || !is_user_logged_in() || !current_user_can('manage_options')) return true; $ip = (self::srv('HTTP_CF_CONNECTING_IP') ?: self::srv('REMOTE_ADDR')); $login = wp_get_current_user()->user_login; $known = get_option(self::OPT . '_known_logins', []); $is = is_array($known) && isset($known[$login][$ip]) && (time() - (int) $known[$login][$ip]) < 30 * DAY_IN_SECONDS; if ($is && time() - (int) $known[$login][$ip] > DAY_IN_SECONDS) { $known[$login][$ip] = time(); update_option(self::OPT . '_known_logins', $known, false); } return !$is; } /** Suggested paragraph for the site's privacy policy (Settings > Privacy > Policy Guide). It follows the current settings: the external service is mentioned only when an optional check is on. */ public static function privacy_text() { if (!function_exists('wp_add_privacy_policy_content')) return; $o = self::opts(); $vc = !empty($o['vuln_check']); $pw = !empty($o['pw_check']); $t = '' . esc_html__('AGuard Safe keeps a security log on this site and, if you have turned on its optional checks, contacts the service of its author. The text below describes exactly what the plugin does with the settings this site has now.', 'aguard-safe') . '
' . '' . esc_html__('Suggested text:', 'aguard-safe') . ' ' . '' . esc_html__('This site uses the AGuard Safe security plugin to notice break-ins. The plugin keeps a log of sign-ins, failed sign-in attempts and administrative actions, together with the IP address and the browser name of whoever made them. It also notes requests that look like a search for a weak spot (for example, for a backup of the configuration file), with the IP address and the browser name. The records are stored on this site, sign-ins and actions for 90 days and such requests for 30 days, and are not shared with anyone.', 'aguard-safe') . '
'; if ($vc || $pw) { $t .= '' . esc_html__('The plugin also uses a service run by its author, AGuard (data.aguard.lt):', 'aguard-safe') . ($vc ? ' ' . esc_html__('once a day it sends the folder names and versions of the installed plugins to learn about known vulnerabilities.', 'aguard-safe') : '') . ($pw ? ' ' . esc_html__('When an administrator signs in, it sends the first 5 characters of a hash of the password to check it against lists of leaked passwords; the password itself is never sent.', 'aguard-safe') : '') . ' ' . esc_html__('The address of this site and the data of its visitors are not sent.', 'aguard-safe') . ' ' . esc_html__('AGuard privacy policy', 'aguard-safe') . '.
'; } wp_add_privacy_policy_content('AGuard Safe', wp_kses_post($t)); } /** Event type in words, the same names as the filters of the Events feed. */ private static function type_label($type) { $m = ['login' => __('Logins', 'aguard-safe'), 'scan' => __('Checks', 'aguard-safe'), 'file' => __('Files', 'aguard-safe'), 'user' => __('Users', 'aguard-safe'), 'plugin' => __('Plugins', 'aguard-safe'), 'theme' => __('Themes', 'aguard-safe'), 'settings' => __('Settings', 'aguard-safe'), 'option' => __('Settings', 'aguard-safe'), 'vuln' => __('Vulnerabilities', 'aguard-safe'), 'quarantine' => __('Quarantine', 'aguard-safe'), 'tools' => __('Viewers', 'aguard-safe'), 'test' => __('Tests', 'aguard-safe'), 'error' => __('Errors', 'aguard-safe')]; return isset($m[$type]) ? $m[$type] : __('Incidents', 'aguard-safe'); } private static function mail_knight($type, $critical) { $m = ['scan' => 'scan', 'file' => 'scan', 'plugin' => 'plugins', 'theme' => 'plugins', 'vuln' => 'plugins', 'settings' => 'settings', 'option' => 'settings', 'test' => 'settings', 'login' => 'activity', 'user' => 'activity', 'tools' => 'activity']; return plugin_dir_path(__FILE__) . 'assets/knight-' . (isset($m[$type]) ? $m[$type] : ($critical ? 'emergency' : 'overview')) . '.png'; } /** Notification e-mail in the plugin's look: what happened, who did it, the details and one button. */ private static function mail_event_html($type, $title, $data, $e, $critical) { $h = 'esc_html'; $ink = '#0f1f45'; $mint = '#3fb9a8'; $red = '#d62828'; $who = self::who_words($e['who'], $type); $rows = [__('Site', 'aguard-safe') => home_url(), __('Time', 'aguard-safe') => wp_date('Y-m-d H:i:s T'), __('Type', 'aguard-safe') => self::type_label($type)]; if ($who[0] !== '') $rows[__('Who', 'aguard-safe')] = $who[0]; if ($who[1] !== '') $rows[__('IP address', 'aguard-safe')] = $who[1]; if ($who[2] !== '') $rows[__('Address', 'aguard-safe')] = $who[2]; if ((string) $e['ua'] !== '' && ($who[1] !== '' || $who[2] !== '')) $rows[__('Browser', 'aguard-safe')] = $e['ua']; $td = 'padding:8px 0;border-top:1px solid #e8edf2;font-size:13px;line-height:1.45;vertical-align:top;'; $tr = ''; foreach ($rows as $k => $v) $tr .= ''
. '
|