PluginProbe
WebTotem Security / 2.3.14
WebTotem Security v2.3.14
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 2.2.4 All 109 releases
← All changes | routes.php +712 -329 2.2.22.3.14 View file →
@@ -10,8 +10,20 @@
10 10 add_action('wp_ajax_ajax_antivirus', 'wtsec_ajax_antivirus');
11 11 add_action('wp_ajax_chart_filter', 'wtsec_chart_filter');
12 12 add_action('wp_ajax_map_filter', 'wtsec_map_filter');
13 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');
14 26
15 27
16 28 function wtsec_add_menu_link()
17 29 {
@@ -43,18 +55,10 @@
43 55 add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout');
44 56 }
45 57 }
46 58
47 -function dd($vl)
59 +function wtsec_myGrading($score)
48 60 {
49 - echo '<pre>';
50 - print_r($vl);
51 - echo '</pre>';
52 - die();
53 -}
54 -
55 -function myGrading($score)
56 -{
57 61 if ($score < 0 || $score > 100) return ['grade' => '','color' => ''];
58 62 $scores = [100 => 'A+', 90 => 'A', 80 => 'A-', 70 => 'B+', 60 => 'B', 50 => 'B-', 35 => 'C+', 20 => 'C', 0 => 'C-' ];
59 63 foreach ($scores as $key => $value){
60 64 if($score >= $key){
@@ -62,9 +66,9 @@
62 66 break;
63 67 }
64 68 }
65 69
66 - $color = ($score >= 80) ? 'green' : ($score >= 50) ? 'orange' : 'red';
70 + $color = ($score >= 80) ? 'green' : (($score >= 50) ? 'orange' : 'red');
67 71
68 72 return ['grade' => $grade,'color' => $color];
69 73 }
70 74
@@ -70,8 +74,12 @@
70 74
71 75
72 76 function convertTimeToReadable($date)
73 77 {
78 + if(!$date){
79 + return WTSEC_LIBRARY_Localization::lmsg('unknown');
80 + }
81 +
74 82 $lang = get_locale();
75 83 //enable russian language
76 84 if ($lang === "ru_RU") {
77 85 $lang .= ".UTF-8";
@@ -79,9 +87,14 @@
79 87 }
80 88 if(strpos($date, ".") !== false){
81 89 $date = substr($date, 0, strpos($date, "."));
82 90 }
83 - return strftime("%B %e, %Y / %R", strtotime($date." UTC"));
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"));
84 97 }
85 98
86 99
87 100 function convertToCurrentTime($date)
@@ -95,14 +108,24 @@
95 108 if(strpos($date, ".") !== false){
96 109 $date = substr($date, 0, strpos($date, "."));
97 110 }
98 111 $date .= " UTC";
99 - $current_time = strtotime($date);
100 - return ['date' => date("Y-m-d", $current_time),'time' => date("H:i:s",$current_time)];
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)];
101 117 }
102 118
103 119 function wtsec_index_page()
104 120 {
121 + $ajax = false;
122 + if (wtsec_request()->method === "POST") {
123 + if(wtsec_request()->ajax){
124 + $ajax = true;
125 + }
126 + }
127 +
105 128 $host = WTSEC_LIBRARY_WT::getOwnSite();
106 129
107 130 $services = [];
108 131 if (!empty($host)) {
@@ -108,8 +131,9 @@
108 131 if (!empty($host)) {
109 132 $services = [
110 133 "settings" => [
111 134 "token" => WTSEC_LIBRARY_App::getToken(),
135 + "email" => WTSEC_LIBRARY_WT::getEmail(),
112 136 "site_id" => $host['id'],
113 137 ],
114 138 "score" => [
115 139 "total_score" => 0,
@@ -119,222 +143,267 @@
119 143 "description" => wtsec_locale("score.description"),
120 144 "information" => "",
121 145 "grade" => "",
122 146 ],
147 + 'wafTraining' => true,
123 148 ];
124 149
125 - $score = json_decode(WTSEC_LIBRARY_WT::getScore(), true);
126 - if (!empty($score)) {
127 - $total_score = round($score['totalScore']);
128 - $my_grading = myGrading($total_score);
129 - $services["score"] = [
130 - "total_score" => $total_score."%",
131 - "tested_on" => convertTimeToReadable($score['date']),
132 - "server_ip" => $score['ip'],
133 - "location" => $score['country'],
134 - "description" => wtsec_locale("score.description"),
135 - "information" => wtsec_locale("score.higher_than_percent", ['percent' => $score['ishigherthan']]),
136 - "grade" => $my_grading['grade'],
137 - "color" => $my_grading['color'],
138 - ];
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;
139 167 }
140 168
141 - $checks = WTSEC_LIBRARY_WT::getAllChecks($host['id']);
142 - foreach ($checks as $service => $site) {
143 - if (empty($site) || !is_array($site)) {
144 - continue;
145 - }
146 - switch ($service) {
147 - case "availability":
148 - $services["wa"] = [
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"] = [
149 200 // "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
150 - "pause" => "",
151 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
152 - "response_time" => ceil($site['responseTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'),
153 - "availability" => $site['percent'] . '%',
154 - "availability_percent" => $site['percent'],
155 - "last_test" => convertTimeToReadable($site['lastTest']['time']),
156 - "downtime" => ceil($site['downTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'),
157 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.availability')
158 - ];
159 - break;
160 - case "ssl":
161 - if ((int)$site['expiryDate'] === 0) {
162 - $days_left = 0;
163 - } else {
164 - $earlier = new DateTime();
165 - $later = new DateTime($site['expiryDate']);
166 - $days_left = $later->diff($earlier)->format("%a");
167 - }
168 - $services["ssl"] = [
169 - "pause" => "",
170 - "information" => wtsec_getInformation($service, $site['status']),
171 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
172 - "days_left" => $days_left,
173 - "issue_date" => convertTimeToReadable($site['issueDate']),
174 - "expiry_date" => convertTimeToReadable($site['expiryDate']),
175 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.ssl'),
176 - "solve_it" => in_array($site['status'],['clean','pending']) ? '' : wtsec_locale('solve_it'),
177 - ];
178 - break;
179 - case "domain":
180 - if ((int)$site['expiredDate'] === 0) {
181 - $days_left = 0;
182 - } else {
183 - $earlier = new DateTime();
184 - $later = new DateTime($site['expiredDate']);
185 - $days_left = $later->diff($earlier)->format("%a");
186 - }
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 + }
187 238
188 - $services["dec"] = [
189 - "pause" => "",
190 - "registrar" => $site['registrar'],
191 - "owner" => $site['owner'],
192 - "information" => wtsec_getInformation($service, $site['status']),
193 - "email" => $site['email'],
194 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
195 - "days_left" => $days_left,
196 - "created" => convertTimeToReadable($site['createdDate']),
197 - "expiry_date" => convertTimeToReadable($site['expiredDate']),
198 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.domain')
199 - ];
200 - break;
201 - case "reputation":
202 - $count = 0;
203 - if ($site['status'] != "clean") {
204 - foreach ($site['virusList'] as &$list) {
205 - if (!empty($list['virus']['type'])) {
206 - $count++;
207 - }
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++;
208 258 }
209 259 }
210 - $services["av"] = [
211 - "pause" => "",
212 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
213 - "time_of_the_last_test" => convertTimeToReadable($site['lastTest']['time']),
214 - "blacklists_entries" => $count,
215 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.reputation'),
216 - "reputation" => $site['status'] === "infected" ? wtsec_locale('bad_reputation') : wtsec_locale('good_reputation'),
217 - ];
218 - break;
219 - case "maliciousScript":
220 - $services["cms"] = [
221 - "pause" => "",
222 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
223 - "time_of_the_last_test" => $site['lastTest']['time'],
224 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.malicious')
225 - ];
226 - break;
227 - case "deface":
228 - $services["dc"] = [
229 - "pause" => "",
230 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
231 - "time_of_the_last_test" => convertTimeToReadable($site['lastTest']['time']),
232 - "number" => $site['count'],
233 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.deface')
234 - ];
235 - break;
236 - case "ports":
237 - $services["ps"] = [
238 - "pause" => "",
239 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
240 - "ip" => $site['ip'],
241 - "last_test" => convertTimeToReadable($site['lastTest']['time']),
242 - "number" => count($site['tcp']),
243 - "tcp" => !empty($site['tcp']) ? implode(",", $site['tcp']) : '',
244 - "udp" => "",
245 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.port')
246 - ];
247 - break;
248 - case "firewall":
249 - $service = "WAF";
250 - $_service = strtolower($service);
251 - $domain = $host['hostname'];
252 - $uid = $host['id'];
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');
253 264
254 - $chart = generateChart($site['chart'], 30);
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);
255 312 // $status = wtsec_checkStatus($uid, $service);
256 313
257 - $data = WTSEC_LIBRARY_WT::getFirewall($host['id']);
258 - $data = $data['data']['auth']['viewer']['sites']['one']['firewall'];
314 + $countryAttacks = wtsec_getCountryAttacks($site['map'], $chart['count_attacks']);
315 + $edges = $site['logs']['edges'];
259 316
260 - $countryAttacks = getCountryAttacks($data['map'], $chart['count_attacks']);
261 - $edges = $data['logs']['edges'];
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;
262 339
263 - $services["waf"] = [
264 - "pause" => "",
265 - "site_address" => $domain,
266 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
267 - "_status" => $site['status'],
268 - "installed_status" => in_array($site['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true,
269 - "time_of_the_last_check" => convertTimeToReadable($site['lastTest']['time']),
270 - "attacks" => $chart['count_attacks'],
271 - "blocking" => $chart['count_blocks'],
272 - "non-blocking" => $chart['count_attacks'] - $chart['count_blocks'],
273 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'),
274 - "actions" => wtsec_generateButtons($uid, $_service, $service, $site['status'], WTSEC_SITE_URL),
275 - "chart" => json_encode($chart['chart'], true),
276 - "edges" => $edges,
277 - "countryAttacks" => $countryAttacks,
278 - ];
279 - break;
280 - case "antivirus":
281 - $service = "AV";
282 - $_service = strtolower($service);
283 - $domain = $host['hostname'];
284 - $uid = $host['id'];
340 + break;
341 + case "antivirus":
342 + $service = "AV";
343 + $_service = strtolower($service);
344 + $domain = $host['hostname'];
345 + $uid = $host['id'];
285 346 // $status = wtsec_checkStatus($uid, $service);
286 - $services["vc"] = [
287 - "pause" => "",
288 - "site_address" => $domain,
289 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
290 - "installed_status" => in_array($site['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true,
291 - "_status" => $site['status'],
292 - "signatures" => (int)$site['stats']['infected'],
293 - "changes" => (int)$site['stats']['changed'],
294 - "scanned" => (int)$site['stats']['scaned'],
295 - "deleted" => (int)$site['stats']['deleted'],
296 - "list" => $site['stats']["infected"],
297 - "actions" => wtsec_generateButtons($uid, $_service, $service, $site['status'], WTSEC_SITE_URL),
298 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
299 - ];
300 - break;
301 - }
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;
302 363 }
364 + }
303 365
304 - //check AM, if not installed , run install
305 - $process = "installing";
306 - $check_am_file = wtsec_checkInstalledFile("am");
307 - $am_installed = $check_am_file["status"];
308 - $am_installed_status = wtsec_app()->get('am_installed');
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');
309 371
310 - if (!$am_installed || !$am_installed_status) {
311 - $am_is_installed = wtsec_cmd("am_install", "AM", "am", $host['id'], [], WTSEC_SITE_URL);
312 - if (!$am_is_installed) {
313 - $process = "failed";
314 - wtsec_app()->set('am_installed', false);
315 - } else {
316 - wtsec_app()->set('am_installed', true);
317 - }
318 - } elseif ($services["vc"]["_status"] === "not_installed" || $services["waf"]["_status"] === "not_installed") {
319 - $process = "installing";
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);
320 377 } else {
321 - $process = "installed";
378 + wtsec_app()->set('am_installed', true);
322 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 + }
323 387
324 - $services["am"] = [
325 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($am_installed ? "working" : "not_installed"),
326 - "actions" => wtsec_generateButtons($host['id'], "am", "AM", ["active" => $check_am_file], WTSEC_SITE_URL),
327 - "process_status" => $process,
328 - "installed" => $am_installed,
329 - ];
330 - }
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 + ];
331 394
332 - wtsec_layout("dashboard", $services);
395 + return $services;
333 396 }
334 397
335 -function getCountryAttacks($map, $countAttacks){
398 +function wtsec_reinstall(){
399 + wtsec_app()->set('am_installed', false);
400 + echo wtsec_getUrl('dashboard');
401 + wp_die();
402 +}
336 403
404 +function wtsec_getCountryAttacks($map, $countAttacks){
405 +
337 406 if($map){
338 407 $attackKey = array_search(max(array_column($map, 'attacks')), array_column($map, 'attacks'));
339 408 $map[$attackKey]['percent'] = ($countAttacks) ? round($map[$attackKey]['attacks'] / $countAttacks * 100) : 0;
340 409 $map[$attackKey]['country'] = wtsec_getCountryName($map[$attackKey]['country']);
@@ -341,11 +410,11 @@
341 410 return $map[$attackKey];
342 411 }
343 412
344 413 return ['percent' => 0, 'country' => false];
414 +}
345 415
346 -}
347 -function getAttacksMap($map){
416 +function wtsec_getAttacksMap($map){
348 417 $attacks = [];
349 418 $countries = [];
350 419 foreach ($map as $value){
351 420 $attacks[] = $value['attacks'];
@@ -353,65 +422,64 @@
353 422 }
354 423 return ['attacks' => $attacks, 'countries' => $countries];
355 424 }
356 425
357 -
358 -function generateChart($charts, $days = 7)
426 +// Server Status chart
427 +function wtsec_chartData($charts, $days)
359 428 {
360 429
361 - if(is_array($days)) {
362 - $beginDate = new DateTime( $days['begin'] );
363 - $endDate = new DateTime( $days['end'] );
364 - $dateDiff = strtotime($days['end'] - strtotime($days['begin']));
365 - $days = floor($dateDiff / (60 * 60 * 24));
430 + $sum = 0;
431 + foreach ($charts as $chart){
432 + $sum += $chart['value'];
366 433 }
434 + if($sum == 0){
435 + return false;
436 + }
367 437
368 - if($days <= 1){
369 - $begin = new DateTime( date('Y-m-d 00:00:00') );
370 - $end = new DateTime( date('Y-m-d 23:59:59') );
371 - $step = 'hour';
372 - } elseif($days <= 31){
373 - $begin = new DateTime( date('Y-m-d', strtotime('-'.($days - 1).' day')) );
374 - $end = new DateTime( date('Y-m-d') );
375 - $step = 'day';
376 - } else {
377 - $begin = new DateTime( date('Y-m-01', strtotime('- 11 month')) );
378 - $end = new DateTime( date('Y-m-01', time()) );
379 - $step = 'month';
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 + ];
380 446 }
381 447
448 + return json_encode($result, true);
449 +}
382 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 = [];
383 463 $count_attacks = 0;
384 464 $count_blocks = 0;
385 - $c = [];
386 465
387 - for($i = $begin; $i <= $end; $i->modify('+1 '.$step)){
466 + if($days <= 1) {$time_zone = WTSEC_LIBRARY_App::_get('time_zone');}
388 467
389 - $c[$i->format('U')] = [
390 - 'date' => ($days <= 1) ? $i->format("Y-m-d H:00:00") : $i->format("Y-m-d"),
391 - 'count' => 0,
392 - 'attacks' => 0,
393 - 'blocked' => 0,
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'],
394 475 ];
395 - }
396 -
397 - foreach ($charts as $chart) {
398 - $d = strtotime($chart['time']);
399 - $c[$d]['count'] = $chart['blocked'];
400 - $c[$d]['attacks'] = $chart['attacks'];
401 - $c[$d]['blocked'] = $chart['blocked'];
402 476 $count_attacks += $chart['attacks'];
403 477 $count_blocks += $chart['blocked'];
404 478 }
405 479
406 480
407 - //unset keys, because the js parser sorting by key in integer
408 - $result = [];
409 - foreach ($c as $d) {
410 - $result[] = $d;
411 - }
412 -
413 - return ['chart' => $result, 'count_attacks' => $count_attacks, 'count_blocks' => $count_blocks];
481 + return ['chart' => json_encode($result), 'count_attacks' => $count_attacks, 'count_blocks' => $count_blocks];
414 482 }
415 483
416 484 function wtsec_getInformation($service, $status)
417 485 {
@@ -447,18 +515,15 @@
447 515 }
448 516
449 517 function wtsec_options_page()
450 518 {
519 + $options = [];
451 520 $host = WTSEC_LIBRARY_WT::getOwnSite();
452 - $result = WTSEC_LIBRARY_WT::getOptions($host['id']);
453 - $options = [];
454 - if (isset($result['data']['userHost']['services'])) {
455 - foreach ($result['data']['userHost']['services'] as $service) {
456 - $configs = $service['configs'][0];
457 - $options[$service['name']] = ['config_id' => $configs['id'], 'is_active' => $configs['isActive']];
458 - }
521 + if(!empty($host)){
522 + $options = wtsec_getConfigs($host['id']);
523 + $options['settings']['login_attempt'] = WTSEC_LIBRARY_App::_get('check_login_attempt');
459 524 }
460 - $options['host_id'] = $host['id'];
525 +
461 526 wtsec_layout("options", $options);
462 527 }
463 528
464 529 function wtsec_services_page()
@@ -465,43 +530,59 @@
465 530 {
466 531 wtsec_layout("services");
467 532 }
468 533
534 +function wtsec_information_page()
535 +{
536 + wtsec_layout("information");
537 +}
538 +
469 539 function wtsec_antivirus_page()
470 540 {
471 541 $host = WTSEC_LIBRARY_WT::getOwnSite();
472 542 $services = [];
473 543 if (!empty($host)) {
474 - $site = WTSEC_LIBRARY_WT::getAntivirus($host['id']);
475 - if (isset($site['data']['auth']['viewer']['sites']['one']['antivirus']['log'])) {
476 - $site = $site['data']['auth']['viewer']['sites']['one']['antivirus'];
544 + $services = wtsec_antivirus_getData($host);
545 + }
546 + wtsec_layout("antivirus", $services);
477 547
478 - $_SESSION['antivirus_endCursor'] = $site['log']['pageInfo']['endCursor'];
479 - $_SESSION['antivirus_hasNextPage'] = $site['log']['pageInfo']['hasNextPage'];
548 +}
480 549
481 - $service = "AV";
482 - $_service = strtolower($service);
483 - $domain = $host['hostname'];
484 - $uid = $host['id'];
485 - $status = wtsec_checkStatus($uid, $service);
486 - $services["vc"] = [
487 - "pause" => "",
488 - "site_address" => $domain,
489 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
490 - "signatures" => (int)$site['stats']['infected'],
491 - "changes" => (int)$site['stats']['changed'],
492 - "scanned" => (int)$site['stats']['scaned'],
493 - "deleted" => (int)$site['stats']['deleted'],
494 - "list" => $site["log"]['edges'],
495 - "actions" => $buttons = wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL),
496 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
497 - ];
498 - }
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']);
499 556 }
500 - wtsec_layout("antivirus", $services);
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;
501 583 }
502 584
503 -
504 585 function wtsec_firewall_page()
505 586 {
506 587 $host = WTSEC_LIBRARY_WT::getOwnSite();
507 588 $services = [];
@@ -513,19 +594,17 @@
513 594 $logs = $site['data']['auth']['viewer']['sites']['one']['firewall']['logs'];
514 595 $firewall = $site['data']['auth']['viewer']['sites']['one']['firewall'];
515 596 $edges = $logs['edges'];
516 597
517 - $chart = $chart['data']['auth']['viewer']['sites']['one']['firewall']['chart'];
598 + $chart_ = wtsec_generateChart($chart, 30);
518 599
519 - $chart = generateChart($chart, 30);
520 -
521 600 $domain = $host['hostname'];
522 601
523 - $_SESSION['firewall_endCursor'] = $logs['pageInfo']['endCursor'];
524 - $_SESSION['firewall_hasNextPage'] = $logs['pageInfo']['hasNextPage'];
602 + WTSEC_LIBRARY_Session::_set('firewall_endCursor', $logs['pageInfo']['endCursor']);
603 + WTSEC_LIBRARY_Session::_set('firewall_hasNextPage', $logs['pageInfo']['hasNextPage']);
525 604
526 - $countryAttacks = getCountryAttacks($firewall['map'], $chart['count_attacks']);
527 - $attacksMap = getAttacksMap($firewall['map']);
605 + $countryAttacks = wtsec_getCountryAttacks($firewall['map'], $chart_['count_attacks']);
606 + $attacksMap = ($firewall['map'])?wtsec_getAttacksMap($firewall['map']):false;
528 607
529 608 $services["waf"] = [
530 609 "pause" => "",
531 610 "site_address" => $domain,
@@ -532,16 +611,18 @@
532 611 "status" => WTSEC_LIBRARY_WT::getStatusIcon($firewall['status']),
533 612 "_status" => $firewall['status'],
534 613 "installed_status" => in_array($firewall['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true,
535 614 "time_of_the_last_check" => convertTimeToReadable($firewall['lastTest']['time']),
536 - "attacks" => $chart['count_attacks'],
537 - "blocking" => $chart['count_blocks'],
538 - "non-blocking" => $chart['count_attacks'] - $chart['count_blocks'],
615 + "attacks" => $chart_['count_attacks'],
616 + "blocking" => $chart_['count_blocks'],
617 + "non-blocking" => $chart_['count_attacks'] - $chart_['count_blocks'],
539 618 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'),
540 - "chart" => json_encode($chart['chart'], true),
619 + "chart" => $chart_['chart'],
541 620 "edges" => $edges,
542 621 "countryAttacks" => $countryAttacks,
543 622 "attacksMap" => $attacksMap,
623 + "hasNextPage" => $logs['pageInfo']['hasNextPage'],
624 + 'settings' => $firewall['settings']
544 625 ];
545 626 }
546 627 }
547 628 wtsec_layout("firewall", $services);
@@ -546,8 +627,112 @@
546 627 }
547 628 wtsec_layout("firewall", $services);
548 629 }
549 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 +
550 735 /**
551 736 * ajax load firewall
552 737 */
553 738 function wtsec_ajax_firewall()
@@ -552,30 +737,33 @@
552 737 */
553 738 function wtsec_ajax_firewall()
554 739 {
555 740 $host = WTSEC_LIBRARY_WT::getOwnSite();
556 - $services = [];
741 + $arguments = [];
557 742
558 743 $post = ($_POST) ? wtsec_clean($_POST):[];
559 - $days = ($post['period']) ? wtsec_period_as_time($post['period']) : 7;
744 + $days = ($post['period']) ? wtsec_period_as_time($post['period']) : 365;
560 745
561 746 if (!empty($host)) {
562 747
563 - if(!$_SESSION['firewall_endCursor'] || $post['filter'] == 'period_filter') $_SESSION['firewall_endCursor'] = null;
748 + $endCursor = WTSEC_LIBRARY_Session::_get('firewall_endCursor');
564 749
565 - $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10, $_SESSION['firewall_endCursor'], $days);
750 + if(!$endCursor || $post['filter'] == 'period_filter') $endCursor = null;
751 +
752 + $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10, $endCursor, $days);
566 753 if (isset($site['data']['auth']['viewer']['sites']['one']['firewall']['logs'])) {
567 754 $logs = $site['data']['auth']['viewer']['sites']['one']['firewall']['logs'];
568 755
569 - $services["waf"]['edges'] = $logs['edges'];
756 + $arguments["waf"]['edges'] = $logs['edges'];
757 + $arguments["waf"]['hasNextPage'] = $logs['pageInfo']['hasNextPage'];
570 758
571 - $_SESSION['firewall_endCursor'] = $logs['pageInfo']['endCursor'];
572 - $_SESSION['firewall_hasNextPage'] = $logs['pageInfo']['hasNextPage'];
759 + WTSEC_LIBRARY_Session::_set('firewall_endCursor', $logs['pageInfo']['endCursor']);
760 + WTSEC_LIBRARY_Session::_set('firewall_hasNextPage', $logs['pageInfo']['hasNextPage']);
573 761 }
574 762
575 763 }
576 764
577 - wtsec_layout_part("_firewall_lazy", $services);
765 + wtsec_layout_part("_firewall_lazy", $arguments);
578 766 wp_die();
579 767 }
580 768
581 769 /**
@@ -583,57 +771,153 @@
583 771 */
584 772 function wtsec_ajax_antivirus()
585 773 {
586 774 $host = WTSEC_LIBRARY_WT::getOwnSite();
587 - $services = [];
775 + $arguments = [];
588 776
589 777 $post = ($_POST) ? wtsec_clean($_POST):[];
590 - $days = ($post['period']) ? wtsec_period_as_time($post['period']) : 7;
778 + $days = ($post['period']) ? wtsec_period_as_time($post['period']) : 365;
591 779
592 780 if (!empty($host)) {
781 + $endCursor = WTSEC_LIBRARY_Session::_get('antivirus_endCursor');
782 + $event = WTSEC_LIBRARY_Session::_get('antivirus_event');
593 783
594 - if(!$_SESSION['antivirus_endCursor'] || $post['filter'] == 'period_filter') $_SESSION['antivirus_endCursor'] = null;
595 - if($post['event'] || $_SESSION['antivirus_event']){
784 + if(!$endCursor || $post['filter'] == 'period_filter') $endCursor = null;
785 + if($post['event'] || $event){
596 786 if($post['event']){
597 - $_SESSION['antivirus_event'] = $post['event'];
787 + WTSEC_LIBRARY_Session::_set('antivirus_event', $post['event']);
788 + $event = $post['event'];
598 789 }
599 - $site = WTSEC_LIBRARY_WT::getAntivirus($host['id'],10, $_SESSION['antivirus_endCursor'],$days, $_SESSION['antivirus_event']);
790 + $site = WTSEC_LIBRARY_WT::getAntivirus($host['id'],10, $endCursor, $days, $event);
600 791 } else {
601 - $site = WTSEC_LIBRARY_WT::getAntivirus($host['id'],10, $_SESSION['antivirus_endCursor'],$days);
792 + $site = WTSEC_LIBRARY_WT::getAntivirus($host['id'],10, $endCursor, $days);
602 793 }
603 794
604 795 if (isset($site['data']['auth']['viewer']['sites']['one']['antivirus']['log'])) {
605 796 $logs = $site['data']['auth']['viewer']['sites']['one']['antivirus']['log'];
606 797
607 - $services["vc"]['list'] = $logs['edges'];
798 + $arguments["vc"]['list'] = wtsec_AVLogsData($logs['edges']);
799 + $arguments["vc"]['hasNextPage'] = $logs['pageInfo']['hasNextPage'];
608 800
609 - $_SESSION['antivirus_endCursor'] = $logs['pageInfo']['endCursor'];
610 - $_SESSION['antivirus_hasNextPage'] = $logs['pageInfo']['hasNextPage'];
801 + WTSEC_LIBRARY_Session::_set('antivirus_endCursor', $logs['pageInfo']['endCursor']);
802 + WTSEC_LIBRARY_Session::_set('antivirus_hasNextPage', $logs['pageInfo']['hasNextPage']);
611 803
612 804 }
613 805 }
614 - wtsec_layout_part("_antivirus_lazy", $services);
806 + wtsec_layout_part("_antivirus_lazy", $arguments);
615 807
616 808 wp_die();
617 809 }
618 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 +
619 880 /**
620 881 * ajax load chart
621 882 */
622 883 function wtsec_chart_filter()
623 884 {
624 - $days = (int)$_POST['days'];
625 - $days = $days ?: 7;
626 885
627 - $host = WTSEC_LIBRARY_WT::getOwnSite();
628 - $chart = WTSEC_LIBRARY_WT::getFirewallChart($host['id'], $days);
629 - $chart = $chart['data']['auth']['viewer']['sites']['one']['firewall']['chart'];
630 - $chart = generateChart($chart, $days);
631 - $res['chart'] = json_encode($chart['chart'], true);
632 - $res['days'] = $days;
886 + if (wtsec_request()->method === "POST") {
887 + $service = wtsec_request()->service;
888 + $days = (int)wtsec_request()->days;
889 + $days = $days ?: 7;
633 890
634 - wtsec_layout_part("_chart_ajax", $res);
891 + $host = WTSEC_LIBRARY_WT::getOwnSite();
635 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 +
636 920 wp_die();
637 921 }
638 922
639 923 /**
@@ -647,9 +931,9 @@
647 931 $host = WTSEC_LIBRARY_WT::getOwnSite();
648 932 $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10,null,$days);
649 933 $firewall = $site['data']['auth']['viewer']['sites']['one']['firewall'];
650 934
651 - $attacksMap = getAttacksMap($firewall['map']);
935 + $attacksMap = ($firewall['map'])?wtsec_getAttacksMap($firewall['map']):false;
652 936 $res["waf"]['attacksMap'] = $attacksMap;
653 937 $res['days'] = $days;
654 938
655 939 wtsec_layout_part("_map_view", $res);
@@ -671,13 +955,95 @@
671 955
672 956 wp_die();
673 957 }
674 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 +
675 1037 function wtsec_login_form()
676 1038 {
677 1039 if (wtsec_request()->method === "POST") {
678 1040 $result = WTSEC_LIBRARY_WT::auth(wtsec_request()->key);
679 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 +
680 1046 WTSEC_LIBRARY_Session::setNotification("success", WTSEC_LIBRARY_Localization::lmsg('successfully_activated'));
681 1047 $token = $result['data']['guest']['apiKeys']['auth']['token']['value'];
682 1048 WTSEC_LIBRARY_App::login($token);
683 1049 wtsec_app()->set("api_key", wtsec_request()->key);
@@ -720,22 +1086,27 @@
720 1086 {
721 1087 WTSEC_LIBRARY_App::logout();
722 1088 }
723 1089
724 -function wtsec_layout_part($template, $arguments = [])
1090 +function wtsec_layout_part($template, $arguments = [], $components = true)
725 1091 {
1092 +
726 1093 wp_register_script( 'ajaxHandle', get_template_directory() . 'PATH TO YOUR JS FILE', array(), false, true );
727 1094 wp_enqueue_script( 'ajaxHandle' );
728 1095 wp_localize_script( 'ajaxHandle', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
729 1096
730 - require WTSEC_PLUGIN_PATH . "includes/components/" . $template . ".php";
731 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 +
732 1104 }
733 1105
734 -function wtsec_layout($template, $arguments = [], $faq = "faq")
1106 +function wtsec_layout($template, $arguments = [])
735 1107 {
736 1108 $body = WTSEC_PLUGIN_PATH . "includes/" . $template . ".php";
737 - $faq = WTSEC_PLUGIN_PATH . "includes/" . $faq . ".php";
738 1109 require_once WTSEC_PLUGIN_PATH . "includes/layout.php";
739 1110 }
740 1111
741 1112
@@ -759,8 +1130,9 @@
759 1130 }
760 1131 wp_safe_redirect(wp_get_referer());
761 1132 }
762 1133
1134 +
763 1135 function wtsec_page($page)
764 1136 {
765 1137 return wtsec_pages()[$page];
766 1138 }
@@ -779,10 +1151,10 @@
779 1151 }
780 1152
781 1153 function wtsec_period_as_time($period){
782 1154 $end = $period[1] ?: $period[0];
783 - $array['begin'] = strtotime(date('d-m-Y 00:00:00',strtotime($period[0])));
784 - $array['end'] = strtotime(date('d-m-Y 23:59:59',strtotime($end)));
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)));
785 1157
786 1158 return $array;
787 1159 }
788 1160
@@ -798,13 +1170,13 @@
798 1170
799 1171 function wtsec_pages()
800 1172 {
801 1173 return [
802 -// "options" => [
803 -// "page_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
804 -// "menu_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
805 -// "function" => "wtsec_options_page",
806 -// ],
1174 + "options" => [
1175 + "page_title" => WTSEC_LIBRARY_Localization::lmsg('settings'),
1176 + "menu_title" => WTSEC_LIBRARY_Localization::lmsg('settings'),
1177 + "function" => "wtsec_options_page",
1178 + ],
807 1179 "services" => [
808 1180 "page_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
809 1181 "menu_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
810 1182 "function" => "wtsec_services_page",
@@ -822,10 +1194,21 @@
822 1194 "function" => "wtsec_firewall_page",
823 1195 "vc_action" => "firewall-action",
824 1196 "vc_function" => "wtsec_firewall_function"
825 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 + ],
826 1208 ];
827 1209 }
1210 +
828 1211
829 1212 function wtsec_getCountryName($key){
830 1213 $countries = [
831 1214 'AD' => 'Andorra',