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