| @@ -1,418 +1,1460 @@ | ||
| 1 | -<?php defined('ABSPATH') or die("Protected By WT!"); | |
| 2 | - | |
| 3 | -add_action('admin_menu', 'wtsec_add_menu_link'); | |
| 4 | -add_action('wp_ajax_change_status', 'wtsec_ajax_changeStatus'); | |
| 5 | -add_action('admin_post_change_status', 'wtsec_changeStatus'); | |
| 6 | -add_action('wp_ajax_cmd', 'wtsec_cmd_ajax'); | |
| 7 | -add_action('admin_post_login_form', 'wtsec_login_form'); | |
| 8 | -add_action('admin_post_ajax_cmd', 'wtsec_cmd_ajax'); | |
| 9 | - | |
| 10 | -function wtsec_add_menu_link() | |
| 11 | -{ | |
| 12 | - add_menu_page( | |
| 13 | - WTSEC_PAGE_TITLE, | |
| 14 | - WTSEC_MENU_TITLE, | |
| 15 | - 'manage_options', | |
| 16 | - wtsec_getRoute('dashboard'), | |
| 17 | - 'wtsec_index_page', | |
| 18 | - '', | |
| 19 | - '1' | |
| 20 | - ); | |
| 21 | - $parent = wtsec_getRoute('dashboard'); | |
| 22 | - if (WTSEC_LIBRARY_App::authorized()) { | |
| 23 | - $capability = 'manage_options'; | |
| 24 | - foreach (wtsec_pages() as $page => $arguments) { | |
| 25 | - add_submenu_page($parent, $arguments['page_title'], $arguments['menu_title'], $capability, wtsec_getRoute($page), $arguments['function']); | |
| 26 | - } | |
| 27 | - add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('sign_in'), WTSEC_LIBRARY_Localization::lmsg('sign_in'), 'manage_options', wtsec_getRoute('login'), 'wtsec_login'); | |
| 28 | - add_submenu_page($parent, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout'); | |
| 29 | - } else { | |
| 30 | - $capability = 'manage_options'; | |
| 31 | - foreach (wtsec_pages() as $page => $arguments) { | |
| 32 | - add_submenu_page(null, $arguments['page_title'], $arguments['menu_title'], $capability, wtsec_getRoute($page), function () { | |
| 33 | - wp_safe_redirect(wtsec_getUrl('login')); | |
| 34 | - }); | |
| 35 | - } | |
| 36 | - add_submenu_page($parent, WTSEC_LIBRARY_Localization::lmsg('sign_in'), WTSEC_LIBRARY_Localization::lmsg('sign_in'), 'manage_options', wtsec_getRoute('login'), 'wtsec_login'); | |
| 37 | - add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout'); | |
| 38 | - } | |
| 39 | - | |
| 40 | -} | |
| 41 | - | |
| 42 | -function wtsec_index_page() | |
| 43 | -{ | |
| 44 | - $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 45 | - $services = []; | |
| 46 | - if (!empty($host)) { | |
| 47 | - $checks = WTSEC_LIBRARY_WT::getAllChecks($host['id']); | |
| 48 | - foreach ($checks['data'] as $service => $site) { | |
| 49 | - if (empty($site) || !is_array($site)) { | |
| 50 | - continue; | |
| 51 | - } | |
| 52 | - $site = $site[0]; | |
| 53 | - switch ($service) { | |
| 54 | - case "waServiceChecks": | |
| 55 | - $services["wa"] = [ | |
| 56 | - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']), | |
| 57 | - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "wa"), | |
| 58 | - "response_time" => $site['responseTime']['avg'] . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'), | |
| 59 | - "availability" => ceil($site['average']['uptimePercent'] * 100) . '%', | |
| 60 | - "availability_percent" => ceil($site['average']['uptimePercent'] * 100), | |
| 61 | - "downtime" => ceil($site['average']['totalDown'] / 1000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('sec'), | |
| 62 | - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.availability') | |
| 63 | - ]; | |
| 64 | - break; | |
| 65 | - case "sslServiceChecks": | |
| 66 | - $services["ssl"] = [ | |
| 67 | - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']), | |
| 68 | - "information" => wtsec_getInformation($service, $site['status']), | |
| 69 | - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "ssl"), | |
| 70 | - "days_left" => $site['daysLeft'], | |
| 71 | - "issue_date" => date("Y-m-d H:i", $site['issued'] / 1000), | |
| 72 | - "expiry_date" => date("Y-m-d H:i", $site['expires'] / 1000), | |
| 73 | - "tls" => $site['tls'], | |
| 74 | - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.ssl') | |
| 75 | - ]; | |
| 76 | - break; | |
| 77 | - case "decServiceChecks": | |
| 78 | - $services["dec"] = [ | |
| 79 | - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']), | |
| 80 | - "registrar" => $site['registrar'], | |
| 81 | - "owner" => $site['owner'], | |
| 82 | - "information" => wtsec_getInformation($service, $site['status']), | |
| 83 | - "email" => $site['email'], | |
| 84 | - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "dec"), | |
| 85 | - "days_left" => $site['daysLeft'], | |
| 86 | - "created" => date("Y-m-d", $site['created'] / 1000), | |
| 87 | - "expiry_date" => date("Y-m-d", $site['expires'] / 1000), | |
| 88 | - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.domain') | |
| 89 | - ]; | |
| 90 | - break; | |
| 91 | - case "avServiceChecks": | |
| 92 | - $services["av"] = [ | |
| 93 | - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']), | |
| 94 | - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "av"), | |
| 95 | - "time_of_the_last_test" => date("Y-m-d H:i", $site['lastTestTime'] / 1000), | |
| 96 | - "blacklists_entries" => $site['count'], | |
| 97 | - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.reputation') | |
| 98 | - ]; | |
| 99 | - break; | |
| 100 | - case "cmsServiceChecks": | |
| 101 | - $services["cms"] = [ | |
| 102 | - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']), | |
| 103 | - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "cms"), | |
| 104 | - "time_of_the_last_test" => date("Y-m-d H:i", $site['lastTestTime'] / 1000), | |
| 105 | - "detected_keywords" => $site['count'], | |
| 106 | - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.malicious') | |
| 107 | - ]; | |
| 108 | - break; | |
| 109 | - case "dcServiceChecks": | |
| 110 | - $services["dc"] = [ | |
| 111 | - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']), | |
| 112 | - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "dc"), | |
| 113 | - "time_of_the_last_test" => date("Y-m-d H:i", $site['lastTestTime'] / 1000), | |
| 114 | - "number" => $site['count'], | |
| 115 | - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.deface') | |
| 116 | - ]; | |
| 117 | - break; | |
| 118 | - case "psServiceChecks": | |
| 119 | - $services["ps"] = [ | |
| 120 | - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']), | |
| 121 | - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "ps"), | |
| 122 | - "ip" => $site['ip'], | |
| 123 | - "time_of_the_last_test" => date("Y-m-d H:i", $site['lastTestTime'] / 1000), | |
| 124 | - "number" => $site['count'], | |
| 125 | - "tcp" => !empty($site['openTCPs']) ? implode(",", $site['openTCPs']) : '', | |
| 126 | - "udp" => !empty($site['openUDPs']) ? implode(",", $site['openUDPs']) : '', | |
| 127 | - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.port') | |
| 128 | - ]; | |
| 129 | - break; | |
| 130 | - case "wafServiceChecks": | |
| 131 | - $service = "WAF"; | |
| 132 | - $_service = strtolower($service); | |
| 133 | - $domain = $host['hostname']; | |
| 134 | - $uid = $host['id']; | |
| 135 | - $status = wtsec_checkStatus($uid, $service); | |
| 136 | - $services["waf"] = [ | |
| 137 | - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $uid), | |
| 138 | - "site_address" => $domain, | |
| 139 | - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "waf"), | |
| 140 | - "time_of_the_last_check" => empty($site['lastTestTime']) ? '' : date("Y-m-d H:i", $site['lastTestTime'] / 1000), | |
| 141 | - "signatures" => $site['count'], | |
| 142 | - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'), | |
| 143 | - "actions" => wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL), | |
| 144 | - "chart" => json_encode((array)generateChart($site['chart']), true) | |
| 145 | - ]; | |
| 146 | - break; | |
| 147 | - case "vcServiceChecks": | |
| 148 | - $service = "VC"; | |
| 149 | - $_service = strtolower($service); | |
| 150 | - $domain = $host['hostname']; | |
| 151 | - $uid = $host['id']; | |
| 152 | - $status = wtsec_checkStatus($uid, $service); | |
| 153 | - $services["vc"] = [ | |
| 154 | - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $uid), | |
| 155 | - "site_address" => $domain, | |
| 156 | - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "vc"), | |
| 157 | - "signatures" => $site['signaturesCount'], | |
| 158 | - "changes" => $site['fileChangesCount'], | |
| 159 | - "list" => $site["list"], | |
| 160 | - "actions" => wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL), | |
| 161 | - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus') | |
| 162 | - ]; | |
| 163 | - break; | |
| 164 | - } | |
| 165 | - } | |
| 166 | - } | |
| 167 | - wtsec_layout("dashboard", $services); | |
| 168 | -} | |
| 169 | - | |
| 170 | -function generateChart($charts) | |
| 171 | -{ | |
| 172 | - $d = date("d"); | |
| 173 | - $m = date("m"); | |
| 174 | - $c = []; | |
| 175 | - $first_day = $d - 6; | |
| 176 | - if ($first_day < 1) { | |
| 177 | - $lastmonth = (int)date('d', strtotime('last day of previous month')); | |
| 178 | - $lastmonth_day = $lastmonth; | |
| 179 | - $lastmonth_month = (int)date('m', strtotime('last day of previous month')); | |
| 180 | - $lastmonth = $lastmonth - ($first_day * -1); | |
| 181 | - for ($i = $lastmonth; $i <= $lastmonth_day; $i++) { | |
| 182 | - $c[$i] = [ | |
| 183 | - 'day' => "{$i}/$lastmonth_month", | |
| 184 | - 'count' => 0, | |
| 185 | - ]; | |
| 186 | - } | |
| 187 | - $first_day = 1; | |
| 188 | - } | |
| 189 | - for ($i = $first_day; $i <= $d; $i++) { | |
| 190 | - $c[$i] = [ | |
| 191 | - 'day' => "{$i}/$m", | |
| 192 | - 'count' => 0, | |
| 193 | - ]; | |
| 194 | - } | |
| 195 | - foreach ($charts as $chart) { | |
| 196 | - $d = (int)date("d", strtotime($chart['date'])); | |
| 197 | - $c[$d]['count'] = $chart['count']; | |
| 198 | - } | |
| 199 | - | |
| 200 | - //unset keys, because the js parser sorting by key in integer | |
| 201 | - $result = []; | |
| 202 | - foreach ($c as $d) { | |
| 203 | - $result[] = $d; | |
| 204 | - } | |
| 205 | - return $result; | |
| 206 | -} | |
| 207 | - | |
| 208 | -function wtsec_getInformation($service, $status) | |
| 209 | -{ | |
| 210 | - $information = [ | |
| 211 | - "sslServiceChecks" => [ | |
| 212 | - WTSEC_LIBRARY_Localization::lmsg("statuses.ok"), | |
| 213 | - WTSEC_LIBRARY_Localization::lmsg("statuses.invalid"), | |
| 214 | - WTSEC_LIBRARY_Localization::lmsg("statuses.expired"), | |
| 215 | - WTSEC_LIBRARY_Localization::lmsg("statuses.expires"), | |
| 216 | - "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.missing"), | |
| 217 | - ], | |
| 218 | - "decServiceChecks" => [ | |
| 219 | - WTSEC_LIBRARY_Localization::lmsg("statuses.ok"), | |
| 220 | - WTSEC_LIBRARY_Localization::lmsg("statuses.expires"), | |
| 221 | - "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.error"), | |
| 222 | - ] | |
| 223 | - ]; | |
| 224 | - return isset($information[$service][$status]) ? $information[$service][$status] : $information[$service]["unknown_status"]; | |
| 225 | -} | |
| 226 | -function wtsec_getStatusStartPauseIcon($status, $config_id, $host_id) | |
| 227 | -{ | |
| 228 | - $icon = ''; | |
| 229 | - switch ($status) { | |
| 230 | - case "1": | |
| 231 | - $icon = '<div class="v-pause ww-icon ww-icon--pause" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>'; | |
| 232 | - break; | |
| 233 | - case "0": | |
| 234 | - $icon = '<div class="v-pause ww-icon ww-icon--play" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>'; | |
| 235 | - break; | |
| 236 | - } | |
| 237 | - return $icon; | |
| 238 | -} | |
| 239 | - | |
| 240 | -function wtsec_options_page() | |
| 241 | -{ | |
| 242 | - $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 243 | - $result = WTSEC_LIBRARY_WT::getOptions($host['id']); | |
| 244 | - $options = []; | |
| 245 | - if (isset($result['data']['userHost']['services'])) { | |
| 246 | - foreach ($result['data']['userHost']['services'] as $service) { | |
| 247 | - $configs = $service['configs'][0]; | |
| 248 | - $options[$service['name']] = ['config_id' => $configs['id'], 'is_active' => $configs['isActive']]; | |
| 249 | - } | |
| 250 | - } | |
| 251 | - $options['host_id'] = $host['id']; | |
| 252 | - wtsec_layout("options", $options); | |
| 253 | -} | |
| 254 | - | |
| 255 | -function wtsec_services_page() | |
| 256 | -{ | |
| 257 | - wtsec_layout("services"); | |
| 258 | -} | |
| 259 | - | |
| 260 | -function wtsec_antivirus_page() | |
| 261 | -{ | |
| 262 | - $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 263 | - $site = WTSEC_LIBRARY_WT::getAntivirus($host['id']); | |
| 264 | - if (isset($site['data']['vcServiceChecks'][0])) { | |
| 265 | - $site = $site['data']['vcServiceChecks'][0]; | |
| 266 | - $service = "VC"; | |
| 267 | - $_service = strtolower($service); | |
| 268 | - $signatures = []; | |
| 269 | - $changes = []; | |
| 270 | - $errors = []; | |
| 271 | - $sign_count = 0; | |
| 272 | - $changes_count = 0; | |
| 273 | - $domain = $host['hostname']; | |
| 274 | - if (!empty($site['list'])) { | |
| 275 | - foreach ($site['list'] as $list) { | |
| 276 | - if ($list['event'] > -1 && empty($list['matches'])) { | |
| 277 | - $changes[$host['id']][] = $list; | |
| 278 | - $changes_count++; | |
| 279 | - } elseif ($list['event'] > -1 && !empty($list['matches'])) { | |
| 280 | - $signatures[$host['id']][] = $list; | |
| 281 | - $sign_count++; | |
| 282 | - } else { | |
| 283 | - $errors[$host['id']][] = $list; | |
| 284 | - } | |
| 285 | - } | |
| 286 | - } | |
| 287 | - $uid = $host['id']; | |
| 288 | - $status = wtsec_checkStatus($uid, $service); | |
| 289 | - $services["vc"] = [ | |
| 290 | - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $uid), | |
| 291 | - "site_address" => $domain, | |
| 292 | - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "vc"), | |
| 293 | - "signatures" => $sign_count, | |
| 294 | - "changes" => $changes_count, | |
| 295 | - "list" => $site["list"], | |
| 296 | - "actions" => $buttons = wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL), | |
| 297 | - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus') | |
| 298 | - ]; | |
| 299 | - } | |
| 300 | - wtsec_layout("antivirus", $services); | |
| 301 | -} | |
| 302 | - | |
| 303 | -function wtsec_login_form() | |
| 304 | -{ | |
| 305 | - if (wtsec_request()->method === "POST") { | |
| 306 | - $result = WTSEC_LIBRARY_WT::auth(wtsec_request()->key); | |
| 307 | - if (isset($result['data']['apiServiceMutation']['auth']['value'])) { | |
| 308 | - WTSEC_LIBRARY_Session::setNotification("success", WTSEC_LIBRARY_Localization::lmsg('successfully_activated')); | |
| 309 | - $token = $result['data']['apiServiceMutation']['auth']['value']; | |
| 310 | - WTSEC_LIBRARY_App::login($token); | |
| 311 | - wtsec_app()->set("api_key", wtsec_request()->key); | |
| 312 | - wp_safe_redirect(wtsec_getUrl('dashboard')); | |
| 313 | - exit; | |
| 314 | - } else { | |
| 315 | - WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg("form.incorrect")); | |
| 316 | - } | |
| 317 | - } | |
| 318 | - wp_safe_redirect(wtsec_getUrl('login')); | |
| 319 | -} | |
| 320 | - | |
| 321 | -function wtsec_cmd_ajax() | |
| 322 | -{ | |
| 323 | - $service = strtoupper(wtsec_request()->service); | |
| 324 | - $_service = strtolower(wtsec_request()->service); | |
| 325 | - $uid = wtsec_request()->uid; | |
| 326 | - $cmd = wtsec_request()->cmd; | |
| 327 | - $status = wtsec_checkStatus($uid, $service); | |
| 328 | - global $wp_filesystem; | |
| 329 | - if (mb_stripos($cmd, "install") === false) { | |
| 330 | - wtsec_cmd($wp_filesystem, $cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL); | |
| 331 | - wp_safe_redirect(wp_get_referer()); | |
| 332 | - } else { | |
| 333 | - $redirect = wtsec_getUrl("dashboard"); | |
| 334 | - $form_url = wp_nonce_url(admin_url('admin-post.php?cmd=' . $cmd . '&action=ajax_cmd&service=' . $service . '&uid=' . $uid), "ajax_cmd"); | |
| 335 | - if (wtsec_filesystem_init($form_url, '', false, false)) { | |
| 336 | - wtsec_cmd($wp_filesystem, $cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL); | |
| 337 | - wp_safe_redirect($redirect); | |
| 338 | - } | |
| 339 | - } | |
| 340 | -} | |
| 341 | - | |
| 342 | -function wtsec_login() | |
| 343 | -{ | |
| 344 | - wtsec_layout("login"); | |
| 345 | -} | |
| 346 | - | |
| 347 | -function wtsec_logout() | |
| 348 | -{ | |
| 349 | - WTSEC_LIBRARY_App::logout(); | |
| 350 | -} | |
| 351 | - | |
| 352 | - | |
| 353 | -function wtsec_layout($template, $arguments = [], $faq = "faq") | |
| 354 | -{ | |
| 355 | - $body = WTSEC_PLUGIN_PATH . "includes/" . $template . ".php"; | |
| 356 | - $faq = WTSEC_PLUGIN_PATH . "includes/" . $faq . ".php"; | |
| 357 | - require_once WTSEC_PLUGIN_PATH . "includes/layout.php"; | |
| 358 | -} | |
| 359 | - | |
| 360 | - | |
| 361 | -function wtsec_ajax_changeStatus() | |
| 362 | -{ | |
| 363 | - if (wtsec_request()->method === "POST") { | |
| 364 | - $host_id = wtsec_request()->host_id; | |
| 365 | - $config_id = wtsec_request()->config_id; | |
| 366 | - $result = WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id); | |
| 367 | - echo json_encode($result); | |
| 368 | - } | |
| 369 | - wp_die(); | |
| 370 | -} | |
| 371 | - | |
| 372 | -function wtsec_changeStatus() | |
| 373 | -{ | |
| 374 | - if (wtsec_request()->method === "POST") { | |
| 375 | - $host_id = wtsec_request()->host_id; | |
| 376 | - $config_id = wtsec_request()->config_id; | |
| 377 | - WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id); | |
| 378 | - } | |
| 379 | - wp_safe_redirect(wp_get_referer()); | |
| 380 | -} | |
| 381 | - | |
| 382 | -function wtsec_page($page) | |
| 383 | -{ | |
| 384 | - return wtsec_pages()[$page]; | |
| 385 | -} | |
| 386 | - | |
| 387 | -function wtsec_getUrl($page) | |
| 388 | -{ | |
| 389 | - return admin_url('admin.php?page=' . WTSEC_PAGE_PREFIX . $page); | |
| 390 | -} | |
| 391 | - | |
| 392 | -function wtsec_getRoute($page) | |
| 393 | -{ | |
| 394 | - return WTSEC_PAGE_PREFIX . $page; | |
| 395 | -} | |
| 396 | - | |
| 397 | -function wtsec_pages() | |
| 398 | -{ | |
| 399 | - return [ | |
| 400 | - "options" => [ | |
| 401 | - "page_title" => WTSEC_LIBRARY_Localization::lmsg('options'), | |
| 402 | - "menu_title" => WTSEC_LIBRARY_Localization::lmsg('options'), | |
| 403 | - "function" => "wtsec_options_page", | |
| 404 | - ], | |
| 405 | - "services" => [ | |
| 406 | - "page_title" => WTSEC_LIBRARY_Localization::lmsg('services'), | |
| 407 | - "menu_title" => WTSEC_LIBRARY_Localization::lmsg('services'), | |
| 408 | - "function" => "wtsec_services_page", | |
| 409 | - ], | |
| 410 | - "vc" => [ | |
| 411 | - "page_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'), | |
| 412 | - "menu_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'), | |
| 413 | - "function" => "wtsec_antivirus_page", | |
| 414 | - "vc_action" => "vc-action", | |
| 415 | - "vc_function" => "wtsec_vc_function" | |
| 416 | - ], | |
| 417 | - ]; | |
| 418 | -} | |
| 1 | +<?php defined('ABSPATH') or die("Protected By WT!"); | |
| 2 | + | |
| 3 | +add_action('admin_menu', 'wtsec_add_menu_link'); | |
| 4 | +add_action('wp_ajax_change_status', 'wtsec_ajax_changeStatus'); | |
| 5 | +add_action('admin_post_change_status', 'wtsec_changeStatus'); | |
| 6 | +add_action('admin_post_login_form', 'wtsec_login_form'); | |
| 7 | +add_action('wp_ajax_cmd', 'wtsec_cmd_ajax'); | |
| 8 | +add_action('admin_post_ajax_cmd', 'wtsec_cmd_ajax'); | |
| 9 | +add_action('wp_ajax_ajax_firewall', 'wtsec_ajax_firewall'); | |
| 10 | +add_action('wp_ajax_ajax_antivirus', 'wtsec_ajax_antivirus'); | |
| 11 | +add_action('wp_ajax_chart_filter', 'wtsec_chart_filter'); | |
| 12 | +add_action('wp_ajax_map_filter', 'wtsec_map_filter'); | |
| 13 | +add_action('wp_ajax_color_scheme_toggle', 'wtsec_color_scheme'); | |
| 14 | +add_action('wp_ajax_configs_toggle', 'wtsec_configs_toggle'); | |
| 15 | +add_action('wp_ajax_generate_report', 'wtsec_generate_report'); | |
| 16 | +add_action('wp_ajax_ajax_reports', 'wtsec_ajax_reports'); | |
| 17 | +add_action('wp_ajax_report_link', 'wtsec_report_link'); | |
| 18 | +add_action('wp_ajax_settings', 'wtsec_settings'); | |
| 19 | +add_action('wp_ajax_move_to_quarantine', 'wtsec_move_to_quarantine'); | |
| 20 | +add_action('wp_ajax_move_from_quarantine', 'wtsec_move_from_quarantine'); | |
| 21 | +add_action('wp_ajax_reinstall', 'wtsec_reinstall'); | |
| 22 | +add_action('wp_ajax_setTimeZone', 'wtsec_setTimeZone'); | |
| 23 | +add_action('wp_ajax_waf_settings', 'wtsec_waf_settings'); | |
| 24 | +add_action('wp_ajax_notification', 'wtsec_notification'); | |
| 25 | +add_action('wp_ajax_refresh_index', 'wtsec_index_page'); | |
| 26 | + | |
| 27 | + | |
| 28 | +function wtsec_add_menu_link() | |
| 29 | +{ | |
| 30 | + add_menu_page( | |
| 31 | + WTSEC_PAGE_TITLE, | |
| 32 | + WTSEC_MENU_TITLE, | |
| 33 | + 'manage_options', | |
| 34 | + wtsec_getRoute('dashboard'), | |
| 35 | + 'wtsec_index_page', | |
| 36 | + '', | |
| 37 | + '1' | |
| 38 | + ); | |
| 39 | + $parent = wtsec_getRoute('dashboard'); | |
| 40 | + if (WTSEC_LIBRARY_App::authorized()) { | |
| 41 | + $capability = 'manage_options'; | |
| 42 | + foreach (wtsec_pages() as $page => $arguments) { | |
| 43 | + add_submenu_page($parent, $arguments['page_title'], $arguments['menu_title'], $capability, wtsec_getRoute($page), $arguments['function']); | |
| 44 | + } | |
| 45 | + add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('sign_in'), WTSEC_LIBRARY_Localization::lmsg('sign_in'), 'manage_options', wtsec_getRoute('login'), 'wtsec_login'); | |
| 46 | + add_submenu_page($parent, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout'); | |
| 47 | + } else { | |
| 48 | + $capability = 'manage_options'; | |
| 49 | + foreach (wtsec_pages() as $page => $arguments) { | |
| 50 | + add_submenu_page(null, $arguments['page_title'], $arguments['menu_title'], $capability, wtsec_getRoute($page), function () { | |
| 51 | + wp_safe_redirect(wtsec_getUrl('login')); | |
| 52 | + }); | |
| 53 | + } | |
| 54 | + add_submenu_page($parent, WTSEC_LIBRARY_Localization::lmsg('sign_in'), WTSEC_LIBRARY_Localization::lmsg('sign_in'), 'manage_options', wtsec_getRoute('login'), 'wtsec_login'); | |
| 55 | + add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout'); | |
| 56 | + } | |
| 57 | +} | |
| 58 | + | |
| 59 | +function wtsec_myGrading($score) | |
| 60 | +{ | |
| 61 | + if ($score < 0 || $score > 100) return ['grade' => '','color' => '']; | |
| 62 | + $scores = [100 => 'A+', 90 => 'A', 80 => 'A-', 70 => 'B+', 60 => 'B', 50 => 'B-', 35 => 'C+', 20 => 'C', 0 => 'C-' ]; | |
| 63 | + foreach ($scores as $key => $value){ | |
| 64 | + if($score >= $key){ | |
| 65 | + $grade = $value; | |
| 66 | + break; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + $color = ($score >= 80) ? 'green' : (($score >= 50) ? 'orange' : 'red'); | |
| 71 | + | |
| 72 | + return ['grade' => $grade,'color' => $color]; | |
| 73 | +} | |
| 74 | + | |
| 75 | + | |
| 76 | +function convertTimeToReadable($date) | |
| 77 | +{ | |
| 78 | + if(!$date){ | |
| 79 | + return WTSEC_LIBRARY_Localization::lmsg('unknown'); | |
| 80 | + } | |
| 81 | + | |
| 82 | + $lang = get_locale(); | |
| 83 | + //enable russian language | |
| 84 | + if ($lang === "ru_RU") { | |
| 85 | + $lang .= ".UTF-8"; | |
| 86 | + setlocale(LC_ALL, $lang); | |
| 87 | + } | |
| 88 | + if(strpos($date, ".") !== false){ | |
| 89 | + $date = substr($date, 0, strpos($date, ".")); | |
| 90 | + } | |
| 91 | + | |
| 92 | + $time_zone = WTSEC_LIBRARY_App::_get('time_zone'); | |
| 93 | + $userTime = ($time_zone) ? strtotime( $time_zone . 'hours', strtotime($date)) : strtotime($date); | |
| 94 | + | |
| 95 | + return date_i18n('F j, Y \/ H:i', $userTime); | |
| 96 | + //return strftime("%B %e, %Y / %R", strtotime($date." UTC")); | |
| 97 | +} | |
| 98 | + | |
| 99 | + | |
| 100 | +function convertToCurrentTime($date) | |
| 101 | +{ | |
| 102 | + $lang = get_locale(); | |
| 103 | + //enable russian language | |
| 104 | + if ($lang === "ru_RU") { | |
| 105 | + $lang .= ".UTF-8"; | |
| 106 | + setlocale(LC_ALL, $lang); | |
| 107 | + } | |
| 108 | + if(strpos($date, ".") !== false){ | |
| 109 | + $date = substr($date, 0, strpos($date, ".")); | |
| 110 | + } | |
| 111 | + $date .= " UTC"; | |
| 112 | + | |
| 113 | + $time_zone = WTSEC_LIBRARY_App::_get('time_zone'); | |
| 114 | + $userTime = ($time_zone) ? strtotime($time_zone . 'hours', strtotime($date)) : strtotime($date); | |
| 115 | + | |
| 116 | + return ['date' => date("Y-m-d", $userTime),'time' => date("H:i:s",$userTime)]; | |
| 117 | +} | |
| 118 | + | |
| 119 | +function wtsec_index_page() | |
| 120 | +{ | |
| 121 | + $ajax = false; | |
| 122 | + if (wtsec_request()->method === "POST") { | |
| 123 | + if(wtsec_request()->ajax){ | |
| 124 | + $ajax = true; | |
| 125 | + } | |
| 126 | + } | |
| 127 | + | |
| 128 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 129 | + | |
| 130 | + $services = []; | |
| 131 | + if (!empty($host)) { | |
| 132 | + $services = [ | |
| 133 | + "settings" => [ | |
| 134 | + "token" => WTSEC_LIBRARY_App::getToken(), | |
| 135 | + "email" => WTSEC_LIBRARY_WT::getEmail(), | |
| 136 | + "site_id" => $host['id'], | |
| 137 | + ], | |
| 138 | + "score" => [ | |
| 139 | + "total_score" => 0, | |
| 140 | + "tested_on" => "", | |
| 141 | + "server_ip" => "", | |
| 142 | + "location" => "", | |
| 143 | + "description" => wtsec_locale("score.description"), | |
| 144 | + "information" => "", | |
| 145 | + "grade" => "", | |
| 146 | + ], | |
| 147 | + 'wafTraining' => true, | |
| 148 | + ]; | |
| 149 | + | |
| 150 | + $checks = WTSEC_LIBRARY_WT::getAllChecks($host['id']); | |
| 151 | + $services = wtsec_dashboard_getData($checks, $services, $host); | |
| 152 | + | |
| 153 | + } | |
| 154 | + | |
| 155 | + if(!$ajax){ | |
| 156 | + wtsec_layout("dashboard", $services); | |
| 157 | + } else { | |
| 158 | + wtsec_layout_part("dashboard", $services,false); | |
| 159 | + wp_die(); | |
| 160 | + } | |
| 161 | +} | |
| 162 | + | |
| 163 | +function wtsec_dashboard_getData($checks, $services, $host){ | |
| 164 | + foreach ($checks as $service => $site) { | |
| 165 | + if (empty($site) || !is_array($site)) { | |
| 166 | + continue; | |
| 167 | + } | |
| 168 | + | |
| 169 | + switch ($service) { | |
| 170 | + case "scoring": | |
| 171 | + $total_score = round($site['score']); | |
| 172 | + $my_grading = wtsec_myGrading($total_score); | |
| 173 | + $services["score"] = [ | |
| 174 | + "total_score" => $total_score."%", | |
| 175 | + "tested_on" => convertTimeToReadable($site['lastTest']['time']), | |
| 176 | + "server_ip" => $site['result']['ip'], | |
| 177 | + "location" => $site['result']['country'], | |
| 178 | + "description" => wtsec_locale("score.description"), | |
| 179 | + "information" => wtsec_locale("score.higher_than_percent", ['percent' => $site['result']['isHigherThan']]), | |
| 180 | + "grade" => $my_grading['grade'], | |
| 181 | + "color" => $my_grading['color'], | |
| 182 | + ]; | |
| 183 | + break; | |
| 184 | + | |
| 185 | + | |
| 186 | + case "serverStatus": | |
| 187 | + $services["serverStatus"] = [ | |
| 188 | + "info" => $site['info'], | |
| 189 | + "ramChart" => (!empty($site['ramChart']))?wtsec_chartData($site['ramChart'],7):false, | |
| 190 | + "cpuChart" => (!empty($site['cpuChart']))?wtsec_chartData($site['cpuChart'],7):false, | |
| 191 | + | |
| 192 | + "discUsage" => $site['discUsage'], | |
| 193 | + ]; | |
| 194 | + $services["serverStatus"]['discUsage']['use'] = $site['discUsage']['total'] - $site['discUsage']['free']; | |
| 195 | + break; | |
| 196 | + | |
| 197 | + | |
| 198 | + case "availability": | |
| 199 | + $services["wa"] = [ | |
| 200 | +// "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']), | |
| 201 | + "pause" => "", | |
| 202 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']), | |
| 203 | + "response_time" => ceil($site['responseTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'), | |
| 204 | + "availability" => $site['percent'] . '%', | |
| 205 | + "availability_percent" => $site['percent'], | |
| 206 | + "last_test" => convertTimeToReadable($site['lastTest']['time']), | |
| 207 | + "downtime" => ceil($site['downTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'), | |
| 208 | + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.availability') | |
| 209 | + ]; | |
| 210 | + break; | |
| 211 | + case "ssl": | |
| 212 | + if ((int)$site['expiryDate'] === 0) { | |
| 213 | + $days_left = 0; | |
| 214 | + } else { | |
| 215 | + $earlier = new DateTime(); | |
| 216 | + $later = new DateTime($site['expiryDate']); | |
| 217 | + $days_left = $later->diff($earlier)->format("%a"); | |
| 218 | + } | |
| 219 | + $services["ssl"] = [ | |
| 220 | + "pause" => "", | |
| 221 | + "information" => wtsec_getInformation($service, $site['status']), | |
| 222 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']), | |
| 223 | + "days_left" => $days_left, | |
| 224 | + "issue_date" => convertTimeToReadable($site['issueDate']), | |
| 225 | + "expiry_date" => convertTimeToReadable($site['expiryDate']), | |
| 226 | + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.ssl'), | |
| 227 | + "solve_it" => in_array($site['status'],['clean','pending']) ? '' : wtsec_locale('solve_it'), | |
| 228 | + ]; | |
| 229 | + break; | |
| 230 | + case "domain": | |
| 231 | + if ((int)$site['expiredDate'] === 0) { | |
| 232 | + $days_left = 0; | |
| 233 | + } else { | |
| 234 | + $earlier = new DateTime(); | |
| 235 | + $later = new DateTime($site['expiredDate']); | |
| 236 | + $days_left = $later->diff($earlier)->format("%a"); | |
| 237 | + } | |
| 238 | + | |
| 239 | + $services["dec"] = [ | |
| 240 | + "pause" => "", | |
| 241 | + "registrar" => $site['registrar'], | |
| 242 | + "owner" => $site['owner'], | |
| 243 | + "information" => wtsec_getInformation($service, $site['status']), | |
| 244 | + "email" => $site['email'], | |
| 245 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']), | |
| 246 | + "days_left" => $days_left, | |
| 247 | + "created" => convertTimeToReadable($site['createdDate']), | |
| 248 | + "expiry_date" => convertTimeToReadable($site['expiredDate']), | |
| 249 | + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.domain') | |
| 250 | + ]; | |
| 251 | + break; | |
| 252 | + case "reputation": | |
| 253 | + $count = 0; | |
| 254 | + if ($site['status'] != "clean") { | |
| 255 | + foreach ($site['virusList'] as &$list) { | |
| 256 | + if (!empty($list['virus']['type'])) { | |
| 257 | + $count++; | |
| 258 | + } | |
| 259 | + } | |
| 260 | + } | |
| 261 | + $status_text = wtsec_locale('na_reputation'); | |
| 262 | + if($site['status'] === "infected") $status_text = wtsec_locale('bad_reputation'); | |
| 263 | + if($site['status'] === "clean") $status_text = wtsec_locale('good_reputation'); | |
| 264 | + | |
| 265 | + $services["av"] = [ | |
| 266 | + "pause" => "", | |
| 267 | + 'status_' => $site['status'], | |
| 268 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']), | |
| 269 | + "time_of_the_last_test" => convertTimeToReadable($site['lastTest']['time']), | |
| 270 | + "blacklists_entries" => $count, | |
| 271 | + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.reputation'), | |
| 272 | + "reputation" => $status_text, | |
| 273 | + ]; | |
| 274 | + break; | |
| 275 | + case "maliciousScript": | |
| 276 | + $services["cms"] = [ | |
| 277 | + "pause" => "", | |
| 278 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']), | |
| 279 | + "time_of_the_last_test" => $site['lastTest']['time'], | |
| 280 | + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.malicious') | |
| 281 | + ]; | |
| 282 | + break; | |
| 283 | + case "deface": | |
| 284 | + $services["dc"] = [ | |
| 285 | + "pause" => "", | |
| 286 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']), | |
| 287 | + "time_of_the_last_test" => convertTimeToReadable($site['lastTest']['time']), | |
| 288 | + "number" => $site['count'], | |
| 289 | + "words" => !empty($site['words']) ? implode(",", $site['words']) : '', | |
| 290 | + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.deface') | |
| 291 | + ]; | |
| 292 | + break; | |
| 293 | + case "ports": | |
| 294 | + $services["ps"] = [ | |
| 295 | + "pause" => "", | |
| 296 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']), | |
| 297 | + "ip" => $site['ip'], | |
| 298 | + "last_test" => convertTimeToReadable($site['lastTest']['time']), | |
| 299 | + "number" => count($site['tcp']), | |
| 300 | + "tcp" => !empty($site['tcp']) ? implode(",", $site['tcp']) : '', | |
| 301 | + "udp" => "", | |
| 302 | + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.port') | |
| 303 | + ]; | |
| 304 | + break; | |
| 305 | + case "firewall": | |
| 306 | + $service = "WAF"; | |
| 307 | + $_service = strtolower($service); | |
| 308 | + $domain = $host['hostname']; | |
| 309 | + $uid = $host['id']; | |
| 310 | + | |
| 311 | + $chart = wtsec_generateChart($site['chart'], 30); | |
| 312 | +// $status = wtsec_checkStatus($uid, $service); | |
| 313 | + | |
| 314 | + $countryAttacks = wtsec_getCountryAttacks($site['map'], $chart['count_attacks']); | |
| 315 | + $edges = $site['logs']['edges']; | |
| 316 | + | |
| 317 | + $services["waf"] = [ | |
| 318 | + "pause" => "", | |
| 319 | + "site_address" => $domain, | |
| 320 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']), | |
| 321 | + "_status" => $site['status'], | |
| 322 | + "installed_status" => in_array($site['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true, | |
| 323 | + "time_of_the_last_check" => convertTimeToReadable($site['lastTest']['time']), | |
| 324 | + "attacks" => $chart['count_attacks'], | |
| 325 | + "blocking" => $chart['count_blocks'], | |
| 326 | + "non-blocking" => $chart['count_attacks'] - $chart['count_blocks'], | |
| 327 | + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'), | |
| 328 | + "actions" => wtsec_generateButtons($uid, $_service, $service, $site['status'], WTSEC_SITE_URL), | |
| 329 | + "chart" => $chart['chart'], | |
| 330 | + "edges" => $edges, | |
| 331 | + "countryAttacks" => $countryAttacks, | |
| 332 | + "hasNextPage" => null, | |
| 333 | + ]; | |
| 334 | + break; | |
| 335 | + case "agentManager": | |
| 336 | + $wafTestingTime = strtotime('+2 day',strtotime($site['createdAt'])); | |
| 337 | + $today = strtotime('today'); | |
| 338 | + $services["wafTraining"] = ($wafTestingTime < $today) ? false : true; | |
| 339 | + | |
| 340 | + break; | |
| 341 | + case "antivirus": | |
| 342 | + $service = "AV"; | |
| 343 | + $_service = strtolower($service); | |
| 344 | + $domain = $host['hostname']; | |
| 345 | + $uid = $host['id']; | |
| 346 | +// $status = wtsec_checkStatus($uid, $service); | |
| 347 | + $services["vc"] = [ | |
| 348 | + "pause" => "", | |
| 349 | + "site_address" => $domain, | |
| 350 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']), | |
| 351 | + "installed_status" => in_array($site['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true, | |
| 352 | + "_status" => $site['status'], | |
| 353 | + "signatures" => (int)$site['stats']['infected'], | |
| 354 | + "changes" => (int)$site['stats']['changed'], | |
| 355 | + "scanned" => (int)$site['stats']['scaned'], | |
| 356 | + "deleted" => (int)$site['stats']['deleted'], | |
| 357 | + "list" => $site['stats']["infected"], | |
| 358 | + "actions" => wtsec_generateButtons($uid, $_service, $service, $site['status'], WTSEC_SITE_URL), | |
| 359 | + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus'), | |
| 360 | + "hasNextPage" => null | |
| 361 | + ]; | |
| 362 | + break; | |
| 363 | + } | |
| 364 | + } | |
| 365 | + | |
| 366 | + //check AM, if not installed , run install | |
| 367 | + $process = "installing"; | |
| 368 | + $check_am_file = wtsec_checkInstalledFile("am"); | |
| 369 | + $am_installed = $check_am_file["status"]; | |
| 370 | + $am_installed_status = wtsec_app()->get('am_installed'); | |
| 371 | + | |
| 372 | + if (!$am_installed || !$am_installed_status) { | |
| 373 | + $am_is_installed = wtsec_cmd("am_install", "AM", "am", $host['id'], [], WTSEC_SITE_URL); | |
| 374 | + if (!$am_is_installed) { | |
| 375 | + $process = "failed"; | |
| 376 | + wtsec_app()->set('am_installed', false); | |
| 377 | + } else { | |
| 378 | + wtsec_app()->set('am_installed', true); | |
| 379 | + } | |
| 380 | + } elseif ($services["vc"]["_status"] === "not_installed" || !$services["vc"]["_status"] || | |
| 381 | + $services["waf"]["_status"] === "not_installed"|| !$services["waf"]["_status"] || | |
| 382 | + !isset($services["vc"]["_status"]) || !isset($services["waf"]["_status"])) { | |
| 383 | + $process = "installing"; | |
| 384 | + } else { | |
| 385 | + $process = "installed"; | |
| 386 | + } | |
| 387 | + | |
| 388 | + $services["am"] = [ | |
| 389 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($am_installed ? "working" : "not_installed"), | |
| 390 | + "actions" => wtsec_generateButtons($host['id'], "am", "AM", ["active" => $check_am_file], WTSEC_SITE_URL), | |
| 391 | + "process_status" => $process, | |
| 392 | + "installed" => $am_installed, | |
| 393 | + ]; | |
| 394 | + | |
| 395 | + return $services; | |
| 396 | +} | |
| 397 | + | |
| 398 | +function wtsec_reinstall(){ | |
| 399 | + wtsec_app()->set('am_installed', false); | |
| 400 | + echo wtsec_getUrl('dashboard'); | |
| 401 | + wp_die(); | |
| 402 | +} | |
| 403 | + | |
| 404 | +function wtsec_getCountryAttacks($map, $countAttacks){ | |
| 405 | + | |
| 406 | + if($map){ | |
| 407 | + $attackKey = array_search(max(array_column($map, 'attacks')), array_column($map, 'attacks')); | |
| 408 | + $map[$attackKey]['percent'] = ($countAttacks) ? round($map[$attackKey]['attacks'] / $countAttacks * 100) : 0; | |
| 409 | + $map[$attackKey]['country'] = wtsec_getCountryName($map[$attackKey]['country']); | |
| 410 | + return $map[$attackKey]; | |
| 411 | + } | |
| 412 | + | |
| 413 | + return ['percent' => 0, 'country' => false]; | |
| 414 | +} | |
| 415 | + | |
| 416 | +function wtsec_getAttacksMap($map){ | |
| 417 | + $attacks = []; | |
| 418 | + $countries = []; | |
| 419 | + foreach ($map as $value){ | |
| 420 | + $attacks[] = $value['attacks']; | |
| 421 | + $countries[] = wtsec_getCountryName($value['country']); | |
| 422 | + } | |
| 423 | + return ['attacks' => $attacks, 'countries' => $countries]; | |
| 424 | +} | |
| 425 | + | |
| 426 | +// Server Status chart | |
| 427 | +function wtsec_chartData($charts, $days) | |
| 428 | +{ | |
| 429 | + | |
| 430 | + $sum = 0; | |
| 431 | + foreach ($charts as $chart){ | |
| 432 | + $sum += $chart['value']; | |
| 433 | + } | |
| 434 | + if($sum == 0){ | |
| 435 | + return false; | |
| 436 | + } | |
| 437 | + | |
| 438 | + if($days <= 1) {$time_zone = WTSEC_LIBRARY_App::_get('time_zone');} | |
| 439 | + $result = []; | |
| 440 | + foreach ($charts as $chart){ | |
| 441 | + if($days <= 1) {$userTime = ($time_zone) ? strtotime( $time_zone . 'hours', strtotime($chart['time'])) : strtotime($chart['time']);} | |
| 442 | + $result[] = [ | |
| 443 | + 'date' => ($days <= 1) ? date("Y-m-d H:00:00", $userTime) : date("Y-m-d", strtotime($chart['time'])), | |
| 444 | + 'value' => $chart['value'], | |
| 445 | + ]; | |
| 446 | + } | |
| 447 | + | |
| 448 | + return json_encode($result, true); | |
| 449 | +} | |
| 450 | + | |
| 451 | +// WAF chart | |
| 452 | +function wtsec_generateChart($charts, $days = 7) | |
| 453 | +{ | |
| 454 | + $sum = 0; | |
| 455 | + foreach ($charts as $chart){ | |
| 456 | + $sum += $chart['attacks']; | |
| 457 | + } | |
| 458 | + if($sum == 0){ | |
| 459 | + return ['chart' => false, 'count_attacks' => 0, 'count_blocks' => 0]; | |
| 460 | + } | |
| 461 | + | |
| 462 | + $result = []; | |
| 463 | + $count_attacks = 0; | |
| 464 | + $count_blocks = 0; | |
| 465 | + | |
| 466 | + if($days <= 1) {$time_zone = WTSEC_LIBRARY_App::_get('time_zone');} | |
| 467 | + | |
| 468 | + foreach ($charts as $chart){ | |
| 469 | + if($days <= 1) {$userTime = ($time_zone) ? strtotime( $time_zone . 'hours', strtotime($chart['time'])) : strtotime($chart['time']);} | |
| 470 | + $result[] = [ | |
| 471 | + 'date' => ($days <= 1) ? date("Y-m-d H:00:00", $userTime) : date("Y-m-d", strtotime($chart['time'])), | |
| 472 | + 'count' => $chart['blocked'], | |
| 473 | + 'attacks' => $chart['attacks'], | |
| 474 | + 'blocked' => $chart['blocked'], | |
| 475 | + ]; | |
| 476 | + $count_attacks += $chart['attacks']; | |
| 477 | + $count_blocks += $chart['blocked']; | |
| 478 | + } | |
| 479 | + | |
| 480 | + | |
| 481 | + return ['chart' => json_encode($result), 'count_attacks' => $count_attacks, 'count_blocks' => $count_blocks]; | |
| 482 | +} | |
| 483 | + | |
| 484 | +function wtsec_getInformation($service, $status) | |
| 485 | +{ | |
| 486 | + $information = [ | |
| 487 | + "ssl" => [ | |
| 488 | + WTSEC_LIBRARY_Localization::lmsg("statuses.ok"), | |
| 489 | + WTSEC_LIBRARY_Localization::lmsg("statuses.invalid"), | |
| 490 | + WTSEC_LIBRARY_Localization::lmsg("statuses.expired"), | |
| 491 | + WTSEC_LIBRARY_Localization::lmsg("statuses.expires"), | |
| 492 | + "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.missing"), | |
| 493 | + ], | |
| 494 | + "domain" => [ | |
| 495 | + WTSEC_LIBRARY_Localization::lmsg("statuses.ok"), | |
| 496 | + WTSEC_LIBRARY_Localization::lmsg("statuses.expires"), | |
| 497 | + "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.error"), | |
| 498 | + ] | |
| 499 | + ]; | |
| 500 | + return isset($information[$service][$status]) ? $information[$service][$status] : $information[$service]["unknown_status"]; | |
| 501 | +} | |
| 502 | + | |
| 503 | +function wtsec_getStatusStartPauseIcon($status, $config_id, $host_id) | |
| 504 | +{ | |
| 505 | + $icon = ''; | |
| 506 | + switch ($status) { | |
| 507 | + case "1": | |
| 508 | + $icon = '<div class="v-pause ww-icon ww-icon--pause" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>'; | |
| 509 | + break; | |
| 510 | + case "0": | |
| 511 | + $icon = '<div class="v-pause ww-icon ww-icon--play" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>'; | |
| 512 | + break; | |
| 513 | + } | |
| 514 | + return $icon; | |
| 515 | +} | |
| 516 | + | |
| 517 | +function wtsec_options_page() | |
| 518 | +{ | |
| 519 | + $options = []; | |
| 520 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 521 | + if(!empty($host)){ | |
| 522 | + $options = wtsec_getConfigs($host['id']); | |
| 523 | + $options['settings']['login_attempt'] = WTSEC_LIBRARY_App::_get('check_login_attempt'); | |
| 524 | + } | |
| 525 | + | |
| 526 | + wtsec_layout("options", $options); | |
| 527 | +} | |
| 528 | + | |
| 529 | +function wtsec_services_page() | |
| 530 | +{ | |
| 531 | + wtsec_layout("services"); | |
| 532 | +} | |
| 533 | + | |
| 534 | +function wtsec_information_page() | |
| 535 | +{ | |
| 536 | + wtsec_layout("information"); | |
| 537 | +} | |
| 538 | + | |
| 539 | +function wtsec_antivirus_page() | |
| 540 | +{ | |
| 541 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 542 | + $services = []; | |
| 543 | + if (!empty($host)) { | |
| 544 | + $services = wtsec_antivirus_getData($host); | |
| 545 | + } | |
| 546 | + wtsec_layout("antivirus", $services); | |
| 547 | + | |
| 548 | +} | |
| 549 | + | |
| 550 | +function wtsec_antivirus_getData($host){ | |
| 551 | + $site = WTSEC_LIBRARY_WT::getAntivirus($host['id']); | |
| 552 | + $quarantine = WTSEC_LIBRARY_WT::getQuarantineList($host['id']); | |
| 553 | + if(isset($quarantine['data']['auth']['viewer']['sites']['one']['antivirus']['quarantine'])){ | |
| 554 | + $services["quarantine"]['list'] = $quarantine['data']['auth']['viewer']['sites']['one']['antivirus']['quarantine']; | |
| 555 | + $services["quarantine"]['count'] = count($services["quarantine"]['list']); | |
| 556 | + } | |
| 557 | + if (isset($site['data']['auth']['viewer']['sites']['one']['antivirus']['log'])) { | |
| 558 | + $site = $site['data']['auth']['viewer']['sites']['one']['antivirus']; | |
| 559 | + | |
| 560 | + WTSEC_LIBRARY_Session::_set('antivirus_endCursor', $site['log']['pageInfo']['endCursor']); | |
| 561 | + WTSEC_LIBRARY_Session::_set('antivirus_hasNextPage', $site['log']['pageInfo']['hasNextPage']); | |
| 562 | + | |
| 563 | + $service = "AV"; | |
| 564 | + $_service = strtolower($service); | |
| 565 | + $domain = $host['hostname']; | |
| 566 | + $uid = $host['id']; | |
| 567 | + $status = wtsec_checkStatus($uid, $service); | |
| 568 | + $services["vc"] = [ | |
| 569 | + "pause" => "", | |
| 570 | + "site_address" => $domain, | |
| 571 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']), | |
| 572 | + "signatures" => (int)$site['stats']['infected'], | |
| 573 | + "changes" => (int)$site['stats']['changed'], | |
| 574 | + "scanned" => (int)$site['stats']['scaned'], | |
| 575 | + "deleted" => (int)$site['stats']['deleted'], | |
| 576 | + "list" => wtsec_AVLogsData($site["log"]['edges']), | |
| 577 | + "actions" => $buttons = wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL), | |
| 578 | + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus'), | |
| 579 | + "hasNextPage" => $site['log']['pageInfo']['hasNextPage'] | |
| 580 | + ]; | |
| 581 | + } | |
| 582 | + return $services; | |
| 583 | +} | |
| 584 | + | |
| 585 | +function wtsec_firewall_page() | |
| 586 | +{ | |
| 587 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 588 | + $services = []; | |
| 589 | + | |
| 590 | + if (!empty($host)) { | |
| 591 | + $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10,null,30); | |
| 592 | + $chart = WTSEC_LIBRARY_WT::getFirewallChart($host['id'], 30); | |
| 593 | + if (isset($site['data']['auth']['viewer']['sites']['one']['firewall']['logs'])) { | |
| 594 | + $logs = $site['data']['auth']['viewer']['sites']['one']['firewall']['logs']; | |
| 595 | + $firewall = $site['data']['auth']['viewer']['sites']['one']['firewall']; | |
| 596 | + $edges = $logs['edges']; | |
| 597 | + | |
| 598 | + $chart_ = wtsec_generateChart($chart, 30); | |
| 599 | + | |
| 600 | + $domain = $host['hostname']; | |
| 601 | + | |
| 602 | + WTSEC_LIBRARY_Session::_set('firewall_endCursor', $logs['pageInfo']['endCursor']); | |
| 603 | + WTSEC_LIBRARY_Session::_set('firewall_hasNextPage', $logs['pageInfo']['hasNextPage']); | |
| 604 | + | |
| 605 | + $countryAttacks = wtsec_getCountryAttacks($firewall['map'], $chart_['count_attacks']); | |
| 606 | + $attacksMap = ($firewall['map'])?wtsec_getAttacksMap($firewall['map']):false; | |
| 607 | + | |
| 608 | + $services["waf"] = [ | |
| 609 | + "pause" => "", | |
| 610 | + "site_address" => $domain, | |
| 611 | + "status" => WTSEC_LIBRARY_WT::getStatusIcon($firewall['status']), | |
| 612 | + "_status" => $firewall['status'], | |
| 613 | + "installed_status" => in_array($firewall['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true, | |
| 614 | + "time_of_the_last_check" => convertTimeToReadable($firewall['lastTest']['time']), | |
| 615 | + "attacks" => $chart_['count_attacks'], | |
| 616 | + "blocking" => $chart_['count_blocks'], | |
| 617 | + "non-blocking" => $chart_['count_attacks'] - $chart_['count_blocks'], | |
| 618 | + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'), | |
| 619 | + "chart" => $chart_['chart'], | |
| 620 | + "edges" => $edges, | |
| 621 | + "countryAttacks" => $countryAttacks, | |
| 622 | + "attacksMap" => $attacksMap, | |
| 623 | + "hasNextPage" => $logs['pageInfo']['hasNextPage'], | |
| 624 | + 'settings' => $firewall['settings'] | |
| 625 | + ]; | |
| 626 | + } | |
| 627 | + } | |
| 628 | + wtsec_layout("firewall", $services); | |
| 629 | +} | |
| 630 | + | |
| 631 | + | |
| 632 | +function wtsec_reports_page() | |
| 633 | +{ | |
| 634 | + | |
| 635 | + $arguments = []; | |
| 636 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 637 | + if(!empty($host)){ | |
| 638 | + $result = WTSEC_LIBRARY_WT::reportsList($host['id']); | |
| 639 | + | |
| 640 | + if (isset($result['data']['auth']['viewer']['reports']['list']['edges'])) { | |
| 641 | + $arguments = $result['data']['auth']['viewer']['reports']['list']; | |
| 642 | + | |
| 643 | + $arguments['edges'] = wtsec_check_modules($arguments['edges']); | |
| 644 | + | |
| 645 | + WTSEC_LIBRARY_Session::_set('reports_endCursor', $arguments['pageInfo']['endCursor']); | |
| 646 | + WTSEC_LIBRARY_Session::_set('reports_hasNextPage', $arguments['pageInfo']['hasNextPage']); | |
| 647 | + } | |
| 648 | + } | |
| 649 | + | |
| 650 | + | |
| 651 | + wtsec_layout("reports", $arguments); | |
| 652 | +} | |
| 653 | + | |
| 654 | + | |
| 655 | +function wtsec_check_modules($edges){ | |
| 656 | + $modulesLang = [ | |
| 657 | + 'wa' => WTSEC_LIBRARY_Localization::lmsg('reports_page.wa_log'), | |
| 658 | + 'dc' => WTSEC_LIBRARY_Localization::lmsg('reports_page.dc_log'), | |
| 659 | + 'ps' => WTSEC_LIBRARY_Localization::lmsg('reports_page.ps_log'), | |
| 660 | + 'rc' => WTSEC_LIBRARY_Localization::lmsg('reports_page.rc_log'), | |
| 661 | + 'sc' => WTSEC_LIBRARY_Localization::lmsg('reports_page.sc_log'), | |
| 662 | + 'av' => WTSEC_LIBRARY_Localization::lmsg('reports_page.av_log'), | |
| 663 | + 'waf' => WTSEC_LIBRARY_Localization::lmsg('reports_page.waf_log') | |
| 664 | + ]; | |
| 665 | + | |
| 666 | + foreach ($edges as $key => $edge){ | |
| 667 | + if(in_array(false, $edge["node"])){ | |
| 668 | + $arr = []; | |
| 669 | + foreach ($edge["node"] as $k => $v){ | |
| 670 | + if($v == true && array_key_exists($k,$modulesLang)){ | |
| 671 | + $arr[] = $modulesLang[$k]; | |
| 672 | + } | |
| 673 | + } | |
| 674 | + $modules = implode(", ", $arr); | |
| 675 | + } else{ | |
| 676 | + $modules = WTSEC_LIBRARY_Localization::lmsg('reports_page.all_modules'); | |
| 677 | + } | |
| 678 | + | |
| 679 | + $edges[$key]["node"]['modules'] = $modules; | |
| 680 | + } | |
| 681 | + | |
| 682 | + return $edges; | |
| 683 | + | |
| 684 | +} | |
| 685 | + | |
| 686 | +function wtsec_generate_report(){ | |
| 687 | + | |
| 688 | + if ($_POST) { | |
| 689 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 690 | + $post = ($_POST) ? wtsec_clean($_POST):[];; | |
| 691 | + | |
| 692 | + $modules = ['wa' => 'false', 'dc' => 'false', 'ps' => 'false', 'rc' => 'false', 'sc' => 'false', 'av' => 'false', 'waf' => 'false' ]; | |
| 693 | + | |
| 694 | + foreach ($modules as $key => $module){ | |
| 695 | + if(array_key_exists($key, $post['modules'])){ | |
| 696 | + $modules[$key] = 'true'; | |
| 697 | + } | |
| 698 | + } | |
| 699 | + | |
| 700 | + if($post['datePeriod']){ | |
| 701 | + $date = explode( ' to ', $post['datePeriod'] ); | |
| 702 | + $period = wtsec_period_as_time($date); | |
| 703 | + } | |
| 704 | + | |
| 705 | + if(!$period){ | |
| 706 | + switch ($post['period']){ | |
| 707 | + case 'month-1': $period = 30; | |
| 708 | + break; | |
| 709 | + case 'month-3': $period = 90; | |
| 710 | + break; | |
| 711 | + case 'month-6': $period = 180; | |
| 712 | + break; | |
| 713 | + case 'year-1': $period = 365; | |
| 714 | + break; | |
| 715 | + default: | |
| 716 | + $period = 30; | |
| 717 | + break; | |
| 718 | + } | |
| 719 | + } | |
| 720 | + | |
| 721 | + $result = WTSEC_LIBRARY_WT::reportGenerate($host['id'], $period, $modules, WTSEC_LANGUAGE); | |
| 722 | + | |
| 723 | + if (isset($result['data']['auth']['viewer']['reports']['generate'])) { | |
| 724 | + WTSEC_LIBRARY_Session::setNotification("success", WTSEC_LIBRARY_Localization::lmsg('reports_page.generate_success')); | |
| 725 | + echo $result['data']['auth']['viewer']['reports']['generate']; | |
| 726 | + exit; | |
| 727 | + } else { | |
| 728 | + WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg("reports_page.generate_error")); | |
| 729 | + } | |
| 730 | + } | |
| 731 | + echo 'false'; | |
| 732 | + wp_die(); | |
| 733 | +} | |
| 734 | + | |
| 735 | +/** | |
| 736 | + * ajax load firewall | |
| 737 | + */ | |
| 738 | +function wtsec_ajax_firewall() | |
| 739 | +{ | |
| 740 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 741 | + $arguments = []; | |
| 742 | + | |
| 743 | + $post = ($_POST) ? wtsec_clean($_POST):[]; | |
| 744 | + $days = ($post['period']) ? wtsec_period_as_time($post['period']) : 365; | |
| 745 | + | |
| 746 | + if (!empty($host)) { | |
| 747 | + | |
| 748 | + $endCursor = WTSEC_LIBRARY_Session::_get('firewall_endCursor'); | |
| 749 | + | |
| 750 | + if(!$endCursor || $post['filter'] == 'period_filter') $endCursor = null; | |
| 751 | + | |
| 752 | + $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10, $endCursor, $days); | |
| 753 | + if (isset($site['data']['auth']['viewer']['sites']['one']['firewall']['logs'])) { | |
| 754 | + $logs = $site['data']['auth']['viewer']['sites']['one']['firewall']['logs']; | |
| 755 | + | |
| 756 | + $arguments["waf"]['edges'] = $logs['edges']; | |
| 757 | + $arguments["waf"]['hasNextPage'] = $logs['pageInfo']['hasNextPage']; | |
| 758 | + | |
| 759 | + WTSEC_LIBRARY_Session::_set('firewall_endCursor', $logs['pageInfo']['endCursor']); | |
| 760 | + WTSEC_LIBRARY_Session::_set('firewall_hasNextPage', $logs['pageInfo']['hasNextPage']); | |
| 761 | + } | |
| 762 | + | |
| 763 | + } | |
| 764 | + | |
| 765 | + wtsec_layout_part("_firewall_lazy", $arguments); | |
| 766 | + wp_die(); | |
| 767 | +} | |
| 768 | + | |
| 769 | +/** | |
| 770 | + * ajax load antivirus | |
| 771 | + */ | |
| 772 | +function wtsec_ajax_antivirus() | |
| 773 | +{ | |
| 774 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 775 | + $arguments = []; | |
| 776 | + | |
| 777 | + $post = ($_POST) ? wtsec_clean($_POST):[]; | |
| 778 | + $days = ($post['period']) ? wtsec_period_as_time($post['period']) : 365; | |
| 779 | + | |
| 780 | + if (!empty($host)) { | |
| 781 | + $endCursor = WTSEC_LIBRARY_Session::_get('antivirus_endCursor'); | |
| 782 | + $event = WTSEC_LIBRARY_Session::_get('antivirus_event'); | |
| 783 | + | |
| 784 | + if(!$endCursor || $post['filter'] == 'period_filter') $endCursor = null; | |
| 785 | + if($post['event'] || $event){ | |
| 786 | + if($post['event']){ | |
| 787 | + WTSEC_LIBRARY_Session::_set('antivirus_event', $post['event']); | |
| 788 | + $event = $post['event']; | |
| 789 | + } | |
| 790 | + $site = WTSEC_LIBRARY_WT::getAntivirus($host['id'],10, $endCursor, $days, $event); | |
| 791 | + } else { | |
| 792 | + $site = WTSEC_LIBRARY_WT::getAntivirus($host['id'],10, $endCursor, $days); | |
| 793 | + } | |
| 794 | + | |
| 795 | + if (isset($site['data']['auth']['viewer']['sites']['one']['antivirus']['log'])) { | |
| 796 | + $logs = $site['data']['auth']['viewer']['sites']['one']['antivirus']['log']; | |
| 797 | + | |
| 798 | + $arguments["vc"]['list'] = wtsec_AVLogsData($logs['edges']); | |
| 799 | + $arguments["vc"]['hasNextPage'] = $logs['pageInfo']['hasNextPage']; | |
| 800 | + | |
| 801 | + WTSEC_LIBRARY_Session::_set('antivirus_endCursor', $logs['pageInfo']['endCursor']); | |
| 802 | + WTSEC_LIBRARY_Session::_set('antivirus_hasNextPage', $logs['pageInfo']['hasNextPage']); | |
| 803 | + | |
| 804 | + } | |
| 805 | + } | |
| 806 | + wtsec_layout_part("_antivirus_lazy", $arguments); | |
| 807 | + | |
| 808 | + wp_die(); | |
| 809 | +} | |
| 810 | + | |
| 811 | +function wtsec_move_to_quarantine(){ | |
| 812 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 813 | + $result = WTSEC_LIBRARY_WT::moveToQuarantine($host['id'], wtsec_request()->path); | |
| 814 | + if($result['data']['auth']['sites']['av']['moveToQuarantine']){ | |
| 815 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 816 | + $arguments = []; | |
| 817 | + if (!empty($host)) { | |
| 818 | + $arguments = wtsec_antivirus_getData($host); | |
| 819 | + } | |
| 820 | + wtsec_layout_part("antivirus", $arguments,false); | |
| 821 | + } else{ | |
| 822 | + echo 'false'; | |
| 823 | + } | |
| 824 | + | |
| 825 | + wp_die(); | |
| 826 | +} | |
| 827 | + | |
| 828 | +function wtsec_move_from_quarantine(){ | |
| 829 | + $result = WTSEC_LIBRARY_WT::moveFromQuarantine(wtsec_request()->id); | |
| 830 | + if($result['data']['auth']['sites']['av']['moveFromQuarantine']){ | |
| 831 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 832 | + $arguments = []; | |
| 833 | + if (!empty($host)) { | |
| 834 | + $arguments = wtsec_antivirus_getData($host); | |
| 835 | + } | |
| 836 | + wtsec_layout_part("antivirus", $arguments,false); | |
| 837 | + } else{ | |
| 838 | + echo 'false'; | |
| 839 | + } | |
| 840 | + | |
| 841 | + wp_die(); | |
| 842 | +} | |
| 843 | + | |
| 844 | +function wtsec_ajax_reports() | |
| 845 | +{ | |
| 846 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 847 | + $post = ($_POST) ? wtsec_clean($_POST):[]; | |
| 848 | + $layout = ($post['type'] == 'mobile')? '_reports_lazy_mobile' : '_reports_lazy'; | |
| 849 | + | |
| 850 | + $arguments = []; | |
| 851 | + $endCursor = WTSEC_LIBRARY_Session::_get('reports_endCursor'); | |
| 852 | + | |
| 853 | + $result = WTSEC_LIBRARY_WT::reportsList($host['id'],10, $endCursor); | |
| 854 | + if (isset($result['data']['auth']['viewer']['reports']['list']['edges'])) { | |
| 855 | + $arguments = $result['data']['auth']['viewer']['reports']['list']; | |
| 856 | + | |
| 857 | + $arguments['edges'] = wtsec_check_modules($arguments['edges']); | |
| 858 | + | |
| 859 | + WTSEC_LIBRARY_Session::_set('reports_endCursor', $arguments['pageInfo']['endCursor']); | |
| 860 | + WTSEC_LIBRARY_Session::_set('reports_hasNextPage', $arguments['pageInfo']['hasNextPage']); | |
| 861 | + } | |
| 862 | + | |
| 863 | + wtsec_layout_part($layout, $arguments); | |
| 864 | + wp_die(); | |
| 865 | +} | |
| 866 | + | |
| 867 | +function wtsec_report_link() | |
| 868 | +{ | |
| 869 | + $post = ($_POST) ? wtsec_clean($_POST):[]; | |
| 870 | + | |
| 871 | + $result = WTSEC_LIBRARY_WT::reportDownload($post['id']); | |
| 872 | + | |
| 873 | + if (isset($result['data']['auth']['viewer']['reports']['download'])) { | |
| 874 | + echo $result['data']['auth']['viewer']['reports']['download']; | |
| 875 | + } | |
| 876 | + | |
| 877 | + wp_die(); | |
| 878 | +} | |
| 879 | + | |
| 880 | +/** | |
| 881 | + * ajax load chart | |
| 882 | + */ | |
| 883 | +function wtsec_chart_filter() | |
| 884 | +{ | |
| 885 | + | |
| 886 | + if (wtsec_request()->method === "POST") { | |
| 887 | + $service = wtsec_request()->service; | |
| 888 | + $days = (int)wtsec_request()->days; | |
| 889 | + $days = $days ?: 7; | |
| 890 | + | |
| 891 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 892 | + | |
| 893 | + $arguments['days'] = $days; | |
| 894 | + | |
| 895 | + switch($service){ | |
| 896 | + case 'waf': | |
| 897 | + $chart = WTSEC_LIBRARY_WT::getFirewallChart($host['id'], $days); | |
| 898 | + $chart = wtsec_generateChart($chart, $days); | |
| 899 | + $arguments['chart'] = $chart['chart'] ?: false; | |
| 900 | + $layout = "_chart_ajax"; | |
| 901 | + break; | |
| 902 | + | |
| 903 | + case 'ram': | |
| 904 | + $chart = WTSEC_LIBRARY_WT::getServerStatusChart($host['id'], $days); | |
| 905 | + $arguments['chart'] = (!empty($chart['ramChart']))? wtsec_chartData($chart['ramChart'],$days) : false; | |
| 906 | + $layout = "_chart_ram_ajax"; | |
| 907 | + break; | |
| 908 | + | |
| 909 | + case 'cpu': | |
| 910 | + $chart = WTSEC_LIBRARY_WT::getServerStatusChart($host['id'], $days); | |
| 911 | + $arguments['chart'] = (!empty($chart['cpuChart']))? wtsec_chartData($chart['cpuChart'],$days) : false; | |
| 912 | + $layout = "_chart_cpu_ajax"; | |
| 913 | + break; | |
| 914 | + } | |
| 915 | + | |
| 916 | + wtsec_layout_part($layout, $arguments); | |
| 917 | + } | |
| 918 | + | |
| 919 | + | |
| 920 | + wp_die(); | |
| 921 | +} | |
| 922 | + | |
| 923 | +/** | |
| 924 | + * ajax load attack map | |
| 925 | + */ | |
| 926 | +function wtsec_map_filter() | |
| 927 | +{ | |
| 928 | + $days = (int)$_POST['days']; | |
| 929 | + $days = $days ?: 7; | |
| 930 | + | |
| 931 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 932 | + $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10,null,$days); | |
| 933 | + $firewall = $site['data']['auth']['viewer']['sites']['one']['firewall']; | |
| 934 | + | |
| 935 | + $attacksMap = ($firewall['map'])?wtsec_getAttacksMap($firewall['map']):false; | |
| 936 | + $res["waf"]['attacksMap'] = $attacksMap; | |
| 937 | + $res['days'] = $days; | |
| 938 | + | |
| 939 | + wtsec_layout_part("_map_view", $res); | |
| 940 | + | |
| 941 | + wp_die(); | |
| 942 | +} | |
| 943 | + | |
| 944 | +function wtsec_color_scheme() | |
| 945 | +{ | |
| 946 | + $checked = (bool)$_POST['checked']; | |
| 947 | + | |
| 948 | + if($checked){ | |
| 949 | + WTSEC_LIBRARY_App::_set('color_scheme', 'dark'); | |
| 950 | + echo 'dark'; | |
| 951 | + } else { | |
| 952 | + WTSEC_LIBRARY_App::_set('color_scheme', 'light'); | |
| 953 | + echo 'light'; | |
| 954 | + } | |
| 955 | + | |
| 956 | + wp_die(); | |
| 957 | +} | |
| 958 | + | |
| 959 | +function wtsec_configs_toggle() | |
| 960 | +{ | |
| 961 | + $post = ($_POST) ? wtsec_clean($_POST):[]; | |
| 962 | + $service_id = $post['service']; | |
| 963 | + $config = WTSEC_LIBRARY_WT::toggleConfigs($service_id); | |
| 964 | + echo json_encode($config['data']['auth']['configs']['toggle']); | |
| 965 | + | |
| 966 | + wp_die(); | |
| 967 | +} | |
| 968 | + | |
| 969 | +function wtsec_settings(){ | |
| 970 | + if (wtsec_request()->method === "POST") { | |
| 971 | + if(wtsec_request()->checked){ | |
| 972 | + $check_login_attempt = 1; | |
| 973 | + } else { | |
| 974 | + $check_login_attempt = 0; | |
| 975 | + } | |
| 976 | + WTSEC_LIBRARY_App::_set('check_login_attempt', $check_login_attempt); | |
| 977 | + echo $check_login_attempt; | |
| 978 | + } | |
| 979 | + | |
| 980 | + wp_die(); | |
| 981 | +} | |
| 982 | + | |
| 983 | +function wtsec_waf_settings(){ | |
| 984 | + if (wtsec_request()->method === "POST") { | |
| 985 | + | |
| 986 | + $host = WTSEC_LIBRARY_WT::getOwnSite(); | |
| 987 | + | |
| 988 | + $settings = [ | |
| 989 | + 'gdn' => wtsec_request()->gdn ? 'true' : 'false', | |
| 990 | + 'dosProtection' => (bool)wtsec_request()->dosProtection ? 'true' : 'false', | |
| 991 | + 'dosLimit' => (int)wtsec_request()->dosLimit, | |
| 992 | + 'loginAttemptsProtection' => (bool)wtsec_request()->loginAttemptsProtection ? 'true' : 'false', | |
| 993 | + 'loginAttemptsLimit' => (int)wtsec_request()->loginAttemptsLimit, | |
| 994 | + ]; | |
| 995 | + | |
| 996 | + $result = WTSEC_LIBRARY_WT::wafSettings($host['id'],$settings); | |
| 997 | + if(!$result['errors']){ | |
| 998 | + echo 'error'; | |
| 999 | + } | |
| 1000 | + | |
| 1001 | + } | |
| 1002 | + | |
| 1003 | + wp_die(); | |
| 1004 | +} | |
| 1005 | + | |
| 1006 | +function wtsec_notification(){ | |
| 1007 | + | |
| 1008 | + if (wtsec_request()->method === "POST") { | |
| 1009 | + $notification = wtsec_request()->notification; | |
| 1010 | + $type = wtsec_request()->type; //"error","info","warning","success" | |
| 1011 | + | |
| 1012 | + $styles = ["error" => ["color" => "red", "class" => "wtotem_alert__img_cross", "img" => ""], "info" => ["color" => "", "class" => "", "img" => ""], "warning" => ["color" => "yellow", "class" => "", "img" => '<img src="' . wtsec_getImagePath("alert-warning.svg") . '">'], "success" => ["color" => "green", "class" => "", "img" => '<img src="' . wtsec_getImagePath("alert-success.svg") . '">']]; | |
| 1013 | + | |
| 1014 | + $style = $styles[$type]; | |
| 1015 | + echo '<div class="wtotem_alert wt_card" id="wtotem_alert" style="margin-bottom:0"> | |
| 1016 | + <div class="wtotem_alert__desc"> | |
| 1017 | + <div class="wtotem_alert__img ' . $style["class"] . '">' . $style["img"] . '</div> | |
| 1018 | + <div class="wtotem_alert__title wtotem_alert__title_' . $style["color"] . '">' . WTSEC_LIBRARY_Localization::lmsg('statuses.' . $type) . ': </div> | |
| 1019 | + <p class="wtotem_alert__text">' . WTSEC_LIBRARY_Localization::lmsg($notification) . '</p> | |
| 1020 | + </div> | |
| 1021 | + <div class="wtotem_alert__close" onclick="removeAlert()"></div> | |
| 1022 | + </div>'; | |
| 1023 | + } | |
| 1024 | + wp_die(); | |
| 1025 | +} | |
| 1026 | + | |
| 1027 | +function wtsec_setTimeZone() | |
| 1028 | +{ | |
| 1029 | + if (wtsec_request()->method === "POST") { | |
| 1030 | + $timeZone = wtsec_request()->timeZone; | |
| 1031 | + WTSEC_LIBRARY_App::_set('time_zone', $timeZone); | |
| 1032 | + | |
| 1033 | + } | |
| 1034 | + wp_die(); | |
| 1035 | +} | |
| 1036 | + | |
| 1037 | +function wtsec_login_form() | |
| 1038 | +{ | |
| 1039 | + if (wtsec_request()->method === "POST") { | |
| 1040 | + $result = WTSEC_LIBRARY_WT::auth(wtsec_request()->key); | |
| 1041 | + if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) { | |
| 1042 | + | |
| 1043 | + $expiresIn = $result['data']['guest']['apiKeys']['auth']['token']['expiresIn']; | |
| 1044 | + wtsec_app()->set("token_expired", time() + $expiresIn - 60); | |
| 1045 | + | |
| 1046 | + WTSEC_LIBRARY_Session::setNotification("success", WTSEC_LIBRARY_Localization::lmsg('successfully_activated')); | |
| 1047 | + $token = $result['data']['guest']['apiKeys']['auth']['token']['value']; | |
| 1048 | + WTSEC_LIBRARY_App::login($token); | |
| 1049 | + wtsec_app()->set("api_key", wtsec_request()->key); | |
| 1050 | + wp_safe_redirect(wtsec_getUrl('dashboard')); | |
| 1051 | + exit; | |
| 1052 | + } else { | |
| 1053 | + WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg("form.incorrect")); | |
| 1054 | + } | |
| 1055 | + } | |
| 1056 | + wp_safe_redirect(wtsec_getUrl('login')); | |
| 1057 | +} | |
| 1058 | + | |
| 1059 | +function wtsec_cmd_ajax() | |
| 1060 | +{ | |
| 1061 | + $service = strtoupper(wtsec_request()->service); | |
| 1062 | + $_service = strtolower(wtsec_request()->service); | |
| 1063 | + $uid = wtsec_request()->uid; | |
| 1064 | + $cmd = wtsec_request()->cmd; | |
| 1065 | + $status = wtsec_checkStatus($uid, $service); | |
| 1066 | + | |
| 1067 | + if (stripos($cmd, "install") === false) { | |
| 1068 | + wtsec_cmd($cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL); | |
| 1069 | + wp_safe_redirect(wp_get_referer()); | |
| 1070 | + } else { | |
| 1071 | + $redirect = wtsec_getUrl("dashboard"); | |
| 1072 | + $form_url = wp_nonce_url(admin_url('admin-post.php?cmd=' . $cmd . '&action=ajax_cmd&service=' . $service . '&uid=' . $uid), "ajax_cmd"); | |
| 1073 | + if (wtsec_filesystem_init($form_url, '', false, false)) { | |
| 1074 | + wtsec_cmd($cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL); | |
| 1075 | + wp_safe_redirect($redirect); | |
| 1076 | + } | |
| 1077 | + } | |
| 1078 | +} | |
| 1079 | + | |
| 1080 | +function wtsec_login() | |
| 1081 | +{ | |
| 1082 | + require_once WTSEC_PLUGIN_PATH . "includes/login.php"; | |
| 1083 | +} | |
| 1084 | + | |
| 1085 | +function wtsec_logout() | |
| 1086 | +{ | |
| 1087 | + WTSEC_LIBRARY_App::logout(); | |
| 1088 | +} | |
| 1089 | + | |
| 1090 | +function wtsec_layout_part($template, $arguments = [], $components = true) | |
| 1091 | +{ | |
| 1092 | + | |
| 1093 | + wp_register_script( 'ajaxHandle', get_template_directory() . 'PATH TO YOUR JS FILE', array(), false, true ); | |
| 1094 | + wp_enqueue_script( 'ajaxHandle' ); | |
| 1095 | + wp_localize_script( 'ajaxHandle', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + if($components){ | |
| 1099 | + require WTSEC_PLUGIN_PATH . "includes/components/" . $template . ".php"; | |
| 1100 | + } else { | |
| 1101 | + require WTSEC_PLUGIN_PATH . "includes/" . $template . ".php"; | |
| 1102 | + } | |
| 1103 | + | |
| 1104 | +} | |
| 1105 | + | |
| 1106 | +function wtsec_layout($template, $arguments = []) | |
| 1107 | +{ | |
| 1108 | + $body = WTSEC_PLUGIN_PATH . "includes/" . $template . ".php"; | |
| 1109 | + require_once WTSEC_PLUGIN_PATH . "includes/layout.php"; | |
| 1110 | +} | |
| 1111 | + | |
| 1112 | + | |
| 1113 | +function wtsec_ajax_changeStatus() | |
| 1114 | +{ | |
| 1115 | + if (wtsec_request()->method === "POST") { | |
| 1116 | + $host_id = wtsec_request()->host_id; | |
| 1117 | + $config_id = wtsec_request()->config_id; | |
| 1118 | + $result = WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id); | |
| 1119 | + echo json_encode($result); | |
| 1120 | + } | |
| 1121 | + wp_die(); | |
| 1122 | +} | |
| 1123 | + | |
| 1124 | +function wtsec_changeStatus() | |
| 1125 | +{ | |
| 1126 | + if (wtsec_request()->method === "POST") { | |
| 1127 | + $host_id = wtsec_request()->host_id; | |
| 1128 | + $config_id = wtsec_request()->config_id; | |
| 1129 | + WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id); | |
| 1130 | + } | |
| 1131 | + wp_safe_redirect(wp_get_referer()); | |
| 1132 | +} | |
| 1133 | + | |
| 1134 | + | |
| 1135 | +function wtsec_page($page) | |
| 1136 | +{ | |
| 1137 | + return wtsec_pages()[$page]; | |
| 1138 | +} | |
| 1139 | + | |
| 1140 | +function wtsec_clean($data) | |
| 1141 | +{ | |
| 1142 | + if (is_array($data)) { | |
| 1143 | + foreach ($data as $key => $value) { | |
| 1144 | + unset($data[$key]); | |
| 1145 | + $data[wtsec_clean($key)] = wtsec_clean($value); | |
| 1146 | + } | |
| 1147 | + } else { | |
| 1148 | + $data = htmlspecialchars(strip_tags($data), ENT_COMPAT, 'UTF-8'); | |
| 1149 | + } | |
| 1150 | + return $data; | |
| 1151 | +} | |
| 1152 | + | |
| 1153 | +function wtsec_period_as_time($period){ | |
| 1154 | + $end = $period[1] ?: $period[0]; | |
| 1155 | + $array['from'] = strtotime(date('d-m-Y 00:00:00',strtotime($period[0]))); | |
| 1156 | + $array['to'] = strtotime(date('d-m-Y 23:59:59',strtotime($end))); | |
| 1157 | + | |
| 1158 | + return $array; | |
| 1159 | +} | |
| 1160 | + | |
| 1161 | +function wtsec_getUrl($page) | |
| 1162 | +{ | |
| 1163 | + return admin_url('admin.php?page=' . WTSEC_PAGE_PREFIX . $page); | |
| 1164 | +} | |
| 1165 | + | |
| 1166 | +function wtsec_getRoute($page) | |
| 1167 | +{ | |
| 1168 | + return WTSEC_PAGE_PREFIX . $page; | |
| 1169 | +} | |
| 1170 | + | |
| 1171 | +function wtsec_pages() | |
| 1172 | +{ | |
| 1173 | + return [ | |
| 1174 | + "options" => [ | |
| 1175 | + "page_title" => WTSEC_LIBRARY_Localization::lmsg('settings'), | |
| 1176 | + "menu_title" => WTSEC_LIBRARY_Localization::lmsg('settings'), | |
| 1177 | + "function" => "wtsec_options_page", | |
| 1178 | + ], | |
| 1179 | + "services" => [ | |
| 1180 | + "page_title" => WTSEC_LIBRARY_Localization::lmsg('services'), | |
| 1181 | + "menu_title" => WTSEC_LIBRARY_Localization::lmsg('services'), | |
| 1182 | + "function" => "wtsec_services_page", | |
| 1183 | + ], | |
| 1184 | + "vc" => [ | |
| 1185 | + "page_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'), | |
| 1186 | + "menu_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'), | |
| 1187 | + "function" => "wtsec_antivirus_page", | |
| 1188 | + "vc_action" => "vc-action", | |
| 1189 | + "vc_function" => "wtsec_vc_function" | |
| 1190 | + ], | |
| 1191 | + "waf" => [ | |
| 1192 | + "page_title" => WTSEC_LIBRARY_Localization::lmsg('firewall'), | |
| 1193 | + "menu_title" => WTSEC_LIBRARY_Localization::lmsg('firewall'), | |
| 1194 | + "function" => "wtsec_firewall_page", | |
| 1195 | + "vc_action" => "firewall-action", | |
| 1196 | + "vc_function" => "wtsec_firewall_function" | |
| 1197 | + ], | |
| 1198 | + "reports" => [ | |
| 1199 | + "page_title" => WTSEC_LIBRARY_Localization::lmsg('reports'), | |
| 1200 | + "menu_title" => WTSEC_LIBRARY_Localization::lmsg('reports'), | |
| 1201 | + "function" => "wtsec_reports_page", | |
| 1202 | + ], | |
| 1203 | + "information" => [ | |
| 1204 | + "page_title" => WTSEC_LIBRARY_Localization::lmsg('information'), | |
| 1205 | + "menu_title" => WTSEC_LIBRARY_Localization::lmsg('information'), | |
| 1206 | + "function" => "wtsec_information_page", | |
| 1207 | + ], | |
| 1208 | + ]; | |
| 1209 | +} | |
| 1210 | + | |
| 1211 | + | |
| 1212 | +function wtsec_getCountryName($key){ | |
| 1213 | + $countries = [ | |
| 1214 | + 'AD' => 'Andorra', | |
| 1215 | + 'AE' => 'United Arab Emirates', | |
| 1216 | + 'AF' => 'Afghanistan', | |
| 1217 | + 'AG' => 'Antigua and Barbuda', | |
| 1218 | + 'AI' => 'Anguilla', | |
| 1219 | + 'AL' => 'Albania', | |
| 1220 | + 'AM' => 'Armenia', | |
| 1221 | + 'AN' => 'Netherlands Antilles', | |
| 1222 | + 'AO' => 'Angola', | |
| 1223 | + 'AP' => 'Asia/Pacific Region', | |
| 1224 | + 'AQ' => 'Antarctica', | |
| 1225 | + 'AR' => 'Argentina', | |
| 1226 | + 'AS' => 'American Samoa', | |
| 1227 | + 'AT' => 'Austria', | |
| 1228 | + 'AU' => 'Australia', | |
| 1229 | + 'AW' => 'Aruba', | |
| 1230 | + 'AZ' => 'Azerbaijan', | |
| 1231 | + 'BA' => 'Bosnia and Herz.', | |
| 1232 | + 'BB' => 'Barbados', | |
| 1233 | + 'BD' => 'Bangladesh', | |
| 1234 | + 'BE' => 'Belgium', | |
| 1235 | + 'BF' => 'Burkina Faso', | |
| 1236 | + 'BG' => 'Bulgaria', | |
| 1237 | + 'BH' => 'Brunei', | |
| 1238 | + 'BI' => 'Burundi', | |
| 1239 | + 'BJ' => 'Benin', | |
| 1240 | + 'BM' => 'Bermuda', | |
| 1241 | + 'BN' => 'Brunei Darussalam', | |
| 1242 | + 'BO' => 'Bolivia', | |
| 1243 | + 'BR' => 'Brazil', | |
| 1244 | + 'BS' => 'Bahamas', | |
| 1245 | + 'BT' => 'Bhutan', | |
| 1246 | + 'BV' => 'Bouvet Island', | |
| 1247 | + 'BW' => 'Botswana', | |
| 1248 | + 'BY' => 'Belarus', | |
| 1249 | + 'BZ' => 'Belize', | |
| 1250 | + 'CA' => 'Canada', | |
| 1251 | + 'CC' => 'Cocos (Keeling) Islands', | |
| 1252 | + 'CD' => 'Dem. Rep. Congo', | |
| 1253 | + 'CF' => 'Central African Rep.', | |
| 1254 | + 'CG' => 'Congo', | |
| 1255 | + 'CH' => 'Switzerland', | |
| 1256 | + 'CI' => 'Côte d\'Ivoire', | |
| 1257 | + 'CK' => 'Cook Islands', | |
| 1258 | + 'CL' => 'Chile', | |
| 1259 | + 'CM' => 'Cameroon', | |
| 1260 | + 'CN' => 'China', | |
| 1261 | + 'CO' => 'Colombia', | |
| 1262 | + 'CR' => 'Costa Rica', | |
| 1263 | + 'CS' => 'Serbia', | |
| 1264 | + 'CU' => 'Cuba', | |
| 1265 | + 'CV' => 'Cape Verde', | |
| 1266 | + 'CX' => 'Christmas Island', | |
| 1267 | + 'CY' => 'Cyprus', | |
| 1268 | + 'CZ' => 'Czech Rep.', | |
| 1269 | + 'DE' => 'Germany', | |
| 1270 | + 'DJ' => 'Djibouti', | |
| 1271 | + 'DK' => 'Denmark', | |
| 1272 | + 'DM' => 'Dominica', | |
| 1273 | + 'DO' => 'Dominican Rep.', | |
| 1274 | + 'DZ' => 'Algeria', | |
| 1275 | + 'EC' => 'Ecuador', | |
| 1276 | + 'EE' => 'Estonia', | |
| 1277 | + 'EG' => 'Egypt', | |
| 1278 | + 'EH' => 'W. Sahara', | |
| 1279 | + 'ER' => 'Eritrea', | |
| 1280 | + 'ES' => 'Spain', | |
| 1281 | + 'ET' => 'Ethiopia', | |
| 1282 | + 'EU' => 'Europe', | |
| 1283 | + 'FI' => 'Finland', | |
| 1284 | + 'FJ' => 'Fiji', | |
| 1285 | + 'FK' => 'Falkland Is.', | |
| 1286 | + 'FM' => 'Micronesia, Federated States of', | |
| 1287 | + 'FO' => 'Faroe Islands', | |
| 1288 | + 'FR' => 'France', | |
| 1289 | + 'FX' => 'France, Metropolitan', | |
| 1290 | + 'GA' => 'Gabon', | |
| 1291 | + 'GB' => 'United Kingdom', | |
| 1292 | + 'GD' => 'Grenada', | |
| 1293 | + 'GE' => 'Georgia', | |
| 1294 | + 'GF' => 'French Guiana', | |
| 1295 | + 'GH' => 'Ghana', | |
| 1296 | + 'GI' => 'Gibraltar', | |
| 1297 | + 'GL' => 'Greenland', | |
| 1298 | + 'GM' => 'Gambia', | |
| 1299 | + 'GN' => 'Guinea', | |
| 1300 | + 'GP' => 'Guadeloupe', | |
| 1301 | + 'GQ' => 'Eq. Guinea', | |
| 1302 | + 'GR' => 'Greece', | |
| 1303 | + 'GS' => 'South Georgia and the South Sandwich Islands', | |
| 1304 | + 'GT' => 'Guatemala', | |
| 1305 | + 'GU' => 'Guam', | |
| 1306 | + 'GW' => 'Guinea-Bissau', | |
| 1307 | + 'GY' => 'Guyana', | |
| 1308 | + 'HK' => 'Hong Kong', | |
| 1309 | + 'HM' => 'Heard Island and McDonald Islands', | |
| 1310 | + 'HN' => 'Honduras', | |
| 1311 | + 'HR' => 'Croatia', | |
| 1312 | + 'HT' => 'Haiti', | |
| 1313 | + 'HU' => 'Hungary', | |
| 1314 | + 'ID' => 'Indonesia', | |
| 1315 | + 'IE' => 'Ireland', | |
| 1316 | + 'IL' => 'Israel', | |
| 1317 | + 'IN' => 'India', | |
| 1318 | + 'IO' => 'British Indian Ocean Territory', | |
| 1319 | + 'IQ' => 'Iraq', | |
| 1320 | + 'IR' => 'Iran', | |
| 1321 | + 'IS' => 'Iceland', | |
| 1322 | + 'IT' => 'Italy', | |
| 1323 | + 'JM' => 'Jamaica', | |
| 1324 | + 'JO' => 'Jordan', | |
| 1325 | + 'JP' => 'Japan', | |
| 1326 | + 'KE' => 'Kenya', | |
| 1327 | + 'KG' => 'Kyrgyzstan', | |
| 1328 | + 'KH' => 'Cambodia', | |
| 1329 | + 'KI' => 'Kiribati', | |
| 1330 | + 'KM' => 'Comoros', | |
| 1331 | + 'KN' => 'Saint Kitts and Nevis', | |
| 1332 | + 'KP' => 'Dem. Rep. Korea', | |
| 1333 | + 'KR' => 'Korea', | |
| 1334 | + 'KW' => 'Kuwait', | |
| 1335 | + 'KY' => 'Cayman Islands', | |
| 1336 | + 'KZ' => 'Kazakhstan', | |
| 1337 | + 'LA' => 'Lao PDR', | |
| 1338 | + 'LB' => 'Lebanon', | |
| 1339 | + 'LC' => 'Saint Lucia', | |
| 1340 | + 'LI' => 'Liechtenstein', | |
| 1341 | + 'LK' => 'Sri Lanka', | |
| 1342 | + 'LR' => 'Liberia', | |
| 1343 | + 'LS' => 'Lesotho', | |
| 1344 | + 'LT' => 'Lithuania', | |
| 1345 | + 'LU' => 'Luxembourg', | |
| 1346 | + 'LV' => 'Latvia', | |
| 1347 | + 'LY' => 'Libya', | |
| 1348 | + 'MA' => 'Morocco', | |
| 1349 | + 'MC' => 'Monaco', | |
| 1350 | + 'MD' => 'Moldova', | |
| 1351 | + 'MG' => 'Madagascar', | |
| 1352 | + 'MH' => 'Marshall Islands', | |
| 1353 | + 'MK' => 'Macedonia', | |
| 1354 | + 'ML' => 'Mali', | |
| 1355 | + 'MM' => 'Myanmar', | |
| 1356 | + 'MN' => 'Mongolia', | |
| 1357 | + 'MO' => 'Macau', | |
| 1358 | + 'MP' => 'Northern Mariana Islands', | |
| 1359 | + 'MQ' => 'Martinique', | |
| 1360 | + 'MR' => 'Mauritania', | |
| 1361 | + 'MS' => 'Montserrat', | |
| 1362 | + 'MT' => 'Malta', | |
| 1363 | + 'MU' => 'Mauritius', | |
| 1364 | + 'MV' => 'Maldives', | |
| 1365 | + 'MW' => 'Malawi', | |
| 1366 | + 'MX' => 'Mexico', | |
| 1367 | + 'MY' => 'Malaysia', | |
| 1368 | + 'MZ' => 'Mozambique', | |
| 1369 | + 'NA' => 'Namibia', | |
| 1370 | + 'NC' => 'New Caledonia', | |
| 1371 | + 'NE' => 'Niger', | |
| 1372 | + 'NF' => 'Norfolk Island', | |
| 1373 | + 'NG' => 'Nigeria', | |
| 1374 | + 'NI' => 'Nicaragua', | |
| 1375 | + 'NL' => 'Netherlands', | |
| 1376 | + 'NO' => 'Norway', | |
| 1377 | + 'NP' => 'Nepal', | |
| 1378 | + 'NR' => 'Nauru', | |
| 1379 | + 'NU' => 'Niue', | |
| 1380 | + 'NZ' => 'New Zealand', | |
| 1381 | + 'OM' => 'Oman', | |
| 1382 | + 'PA' => 'Panama', | |
| 1383 | + 'PE' => 'Peru', | |
| 1384 | + 'PF' => 'French Polynesia', | |
| 1385 | + 'PG' => 'Papua New Guinea', | |
| 1386 | + 'PH' => 'Philippines', | |
| 1387 | + 'PK' => 'Pakistan', | |
| 1388 | + 'PL' => 'Poland', | |
| 1389 | + 'PM' => 'Saint Pierre and Miquelon', | |
| 1390 | + 'PN' => 'Pitcairn Islands', | |
| 1391 | + 'PR' => 'Puerto Rico', | |
| 1392 | + 'PS' => 'Palestine', | |
| 1393 | + 'PT' => 'Portugal', | |
| 1394 | + 'PW' => 'Palau', | |
| 1395 | + 'PY' => 'Paraguay', | |
| 1396 | + 'QA' => 'Qatar', | |
| 1397 | + 'RE' => 'Reunion', | |
| 1398 | + 'RO' => 'Romania', | |
| 1399 | + 'RU' => 'Russia', | |
| 1400 | + 'RW' => 'Rwanda', | |
| 1401 | + 'SA' => 'Saudi Arabia', | |
| 1402 | + 'SB' => 'Solomon Is.', | |
| 1403 | + 'SC' => 'Seychelles', | |
| 1404 | + 'SD' => 'Sudan', | |
| 1405 | + 'SE' => 'Sweden', | |
| 1406 | + 'SG' => 'Singapore', | |
| 1407 | + 'SH' => 'Saint Helena', | |
| 1408 | + 'SI' => 'Slovenia', | |
| 1409 | + 'SJ' => 'Svalbard and Jan Mayen', | |
| 1410 | + 'SK' => 'Slovakia', | |
| 1411 | + 'SL' => 'Sierra Leone', | |
| 1412 | + 'SM' => 'San Marino', | |
| 1413 | + 'SN' => 'Senegal', | |
| 1414 | + 'SO' => 'Somalia', | |
| 1415 | + 'SR' => 'Suriname', | |
| 1416 | + 'ST' => 'Sao Tome and Principe', | |
| 1417 | + 'SV' => 'El Salvador', | |
| 1418 | + 'SY' => 'Syria', | |
| 1419 | + 'SZ' => 'Swaziland', | |
| 1420 | + 'TC' => 'Turks and Caicos Islands', | |
| 1421 | + 'TD' => 'Chad', | |
| 1422 | + 'TF' => 'French Southern Territories', | |
| 1423 | + 'TG' => 'Togo', | |
| 1424 | + 'TH' => 'Thailand', | |
| 1425 | + 'TJ' => 'Tajikistan', | |
| 1426 | + 'TK' => 'Tokelau', | |
| 1427 | + 'TM' => 'Turkmenistan', | |
| 1428 | + 'TN' => 'Tunisia', | |
| 1429 | + 'TO' => 'Tonga', | |
| 1430 | + 'TP' => 'East Timor', | |
| 1431 | + 'TR' => 'Turkey', | |
| 1432 | + 'TT' => 'Trinidad and Tobago', | |
| 1433 | + 'TV' => 'Tuvalu', | |
| 1434 | + 'TW' => 'Taiwan', | |
| 1435 | + 'TZ' => 'Tanzania', | |
| 1436 | + 'UA' => 'Ukraine', | |
| 1437 | + 'UG' => 'Uganda', | |
| 1438 | + 'UM' => 'United States Minor Outlying Islands', | |
| 1439 | + 'US' => 'United States', | |
| 1440 | + 'UY' => 'Uruguay', | |
| 1441 | + 'UZ' => 'Uzbekistan', | |
| 1442 | + 'VA' => 'Holy See (Vatican City State)', | |
| 1443 | + 'VC' => 'Saint Vincent and the Grenadines', | |
| 1444 | + 'VE' => 'Venezuela', | |
| 1445 | + 'VG' => 'Virgin Islands, British', | |
| 1446 | + 'VI' => 'Virgin Islands, U.S.', | |
| 1447 | + 'VN' => 'Vietnam', | |
| 1448 | + 'VU' => 'Vanuatu', | |
| 1449 | + 'WF' => 'Wallis and Futuna', | |
| 1450 | + 'WS' => 'Samoa', | |
| 1451 | + 'YE' => 'Yemen', | |
| 1452 | + 'YT' => 'Mayotte', | |
| 1453 | + 'ZA' => 'South Africa', | |
| 1454 | + 'ZM' => 'Zambia', | |
| 1455 | + 'ZR' => 'Zaire', | |
| 1456 | + 'ZW' => 'Zimbabwe', | |
| 1457 | + ]; | |
| 1458 | + | |
| 1459 | + return $countries[$key]; | |
| 1460 | +} | |