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 +1117 -335 2.1.82.3.24 View file →
@@ -2,14 +2,32 @@
2 2
3 3 add_action('admin_menu', 'wtsec_add_menu_link');
4 4 add_action('wp_ajax_change_status', 'wtsec_ajax_changeStatus');
5 5 add_action('admin_post_change_status', 'wtsec_changeStatus');
6 -add_action('admin_post_login_form', 'wtsec_login_form');
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');
7 9 add_action('wp_ajax_cmd', 'wtsec_cmd_ajax');
8 10 add_action('admin_post_ajax_cmd', 'wtsec_cmd_ajax');
9 11 add_action('wp_ajax_ajax_firewall', 'wtsec_ajax_firewall');
10 12 add_action('wp_ajax_ajax_antivirus', 'wtsec_ajax_antivirus');
11 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');
12 30
13 31
14 32 function wtsec_add_menu_link()
15 33 {
@@ -18,10 +36,10 @@
18 36 WTSEC_MENU_TITLE,
19 37 'manage_options',
20 38 wtsec_getRoute('dashboard'),
21 39 'wtsec_index_page',
22 - '',
23 - '1'
40 + wtsec_getImagePath('logo_17x17_w.png'),
41 + '80.8'
24 42 );
25 43 $parent = wtsec_getRoute('dashboard');
26 44 if (WTSEC_LIBRARY_App::authorized()) {
27 45 $capability = 'manage_options';
@@ -41,18 +59,10 @@
41 59 add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout');
42 60 }
43 61 }
44 62
45 -function dd($vl)
63 +function wtsec_myGrading($score)
46 64 {
47 - echo '<pre>';
48 - print_r($vl);
49 - echo '</pre>';
50 - die();
51 -}
52 -
53 -function myGrading($score)
54 -{
55 65 if ($score < 0 || $score > 100) return ['grade' => '','color' => ''];
56 66 $scores = [100 => 'A+', 90 => 'A', 80 => 'A-', 70 => 'B+', 60 => 'B', 50 => 'B-', 35 => 'C+', 20 => 'C', 0 => 'C-' ];
57 67 foreach ($scores as $key => $value){
58 68 if($score >= $key){
@@ -60,9 +70,9 @@
60 70 break;
61 71 }
62 72 }
63 73
64 - $color = ($score >= 80) ? 'green' : ($score >= 50) ? 'orange' : 'red';
74 + $color = ($score >= 80) ? 'green' : (($score >= 50) ? 'orange' : 'red');
65 75
66 76 return ['grade' => $grade,'color' => $color];
67 77 }
68 78
@@ -68,8 +78,12 @@
68 78
69 79
70 80 function convertTimeToReadable($date)
71 81 {
82 + if(!$date){
83 + return WTSEC_LIBRARY_Localization::lmsg('unknown');
84 + }
85 +
72 86 $lang = get_locale();
73 87 //enable russian language
74 88 if ($lang === "ru_RU") {
75 89 $lang .= ".UTF-8";
@@ -77,9 +91,14 @@
77 91 }
78 92 if(strpos($date, ".") !== false){
79 93 $date = substr($date, 0, strpos($date, "."));
80 94 }
81 - return strftime("%B %e, %Y / %R", strtotime($date." UTC"));
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"));
82 101 }
83 102
84 103
85 104 function convertToCurrentTime($date)
@@ -93,14 +112,25 @@
93 112 if(strpos($date, ".") !== false){
94 113 $date = substr($date, 0, strpos($date, "."));
95 114 }
96 115 $date .= " UTC";
97 - $current_time = strtotime($date);
98 - return ['date' => date("Y-m-d", $current_time),'time' => date("H:i:s",$current_time)];
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)];
99 121 }
100 122
123 +
101 124 function wtsec_index_page()
102 125 {
126 + $ajax = false;
127 + if (wtsec_request()->method === "POST") {
128 + if(wtsec_request()->ajax){
129 + $ajax = true;
130 + }
131 + }
132 +
103 133 $host = WTSEC_LIBRARY_WT::getOwnSite();
104 134
105 135 $services = [];
106 136 if (!empty($host)) {
@@ -106,8 +136,9 @@
106 136 if (!empty($host)) {
107 137 $services = [
108 138 "settings" => [
109 139 "token" => WTSEC_LIBRARY_App::getToken(),
140 + "email" => WTSEC_LIBRARY_WT::getEmail(),
110 141 "site_id" => $host['id'],
111 142 ],
112 143 "score" => [
113 144 "total_score" => 0,
@@ -117,289 +148,343 @@
117 148 "description" => wtsec_locale("score.description"),
118 149 "information" => "",
119 150 "grade" => "",
120 151 ],
152 + 'wafTraining' => true,
121 153 ];
122 154
123 - $score = json_decode(WTSEC_LIBRARY_WT::getScore(), true);
124 - if (!empty($score)) {
125 - $total_score = round($score['totalScore']);
126 - $my_grading = myGrading($total_score);
127 - $services["score"] = [
128 - "total_score" => $total_score."%",
129 - "tested_on" => convertTimeToReadable($score['date']),
130 - "server_ip" => $score['ip'],
131 - "location" => $score['country'],
132 - "description" => wtsec_locale("score.description"),
133 - "information" => wtsec_locale("score.higher_than_percent", ['percent' => $score['ishigherthan']]),
134 - "grade" => $my_grading['grade'],
135 - "color" => $my_grading['color'],
136 - ];
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;
137 172 }
138 173
139 - $checks = WTSEC_LIBRARY_WT::getAllChecks($host['id']);
140 - foreach ($checks as $service => $site) {
141 - if (empty($site) || !is_array($site)) {
142 - continue;
143 - }
144 - switch ($service) {
145 - case "availability":
146 - $services["wa"] = [
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"] = [
147 205 // "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
148 - "pause" => "",
149 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
150 - "response_time" => ceil($site['responseTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'),
151 - "availability" => $site['percent'] . '%',
152 - "availability_percent" => $site['percent'],
153 - "last_test" => convertTimeToReadable($site['lastTest']['time']),
154 - "downtime" => ceil($site['downTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'),
155 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.availability')
156 - ];
157 - break;
158 - case "ssl":
159 - if ((int)$site['expiryDate'] === 0) {
160 - $days_left = 0;
161 - } else {
162 - $earlier = new DateTime();
163 - $later = new DateTime($site['expiryDate']);
164 - $days_left = $later->diff($earlier)->format("%a");
165 - }
166 - $services["ssl"] = [
167 - "pause" => "",
168 - "information" => wtsec_getInformation($service, $site['status']),
169 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
170 - "days_left" => $days_left,
171 - "issue_date" => convertTimeToReadable($site['issueDate']),
172 - "expiry_date" => convertTimeToReadable($site['expiryDate']),
173 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.ssl'),
174 - "solve_it" => in_array($site['status'],['clean','pending']) ? '' : wtsec_locale('solve_it'),
175 - ];
176 - break;
177 - case "domain":
178 - if ((int)$site['expiredDate'] === 0) {
179 - $days_left = 0;
180 - } else {
181 - $earlier = new DateTime();
182 - $later = new DateTime($site['expiredDate']);
183 - $days_left = $later->diff($earlier)->format("%a");
184 - }
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 + }
185 243
186 - $services["dec"] = [
187 - "pause" => "",
188 - "registrar" => $site['registrar'],
189 - "owner" => $site['owner'],
190 - "information" => wtsec_getInformation($service, $site['status']),
191 - "email" => $site['email'],
192 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
193 - "days_left" => $days_left,
194 - "created" => convertTimeToReadable($site['createdDate']),
195 - "expiry_date" => convertTimeToReadable($site['expiredDate']),
196 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.domain')
197 - ];
198 - break;
199 - case "reputation":
200 - $count = 0;
201 - if ($site['status'] != "clean") {
202 - foreach ($site['virusList'] as &$list) {
203 - if (!empty($list['viruses'])) {
204 - $count++;
205 - }
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++;
206 263 }
207 264 }
208 - $services["av"] = [
209 - "pause" => "",
210 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
211 - "time_of_the_last_test" => convertTimeToReadable($site['lastTest']['time']),
212 - "blacklists_entries" => $count,
213 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.reputation'),
214 - "reputation" => $site['status'] === "infected" ? wtsec_locale('bad_reputation') : wtsec_locale('good_reputation'),
215 - ];
216 - break;
217 - case "maliciousScript":
218 - $services["cms"] = [
219 - "pause" => "",
220 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
221 - "time_of_the_last_test" => $site['lastTest']['time'],
222 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.malicious')
223 - ];
224 - break;
225 - case "deface":
226 - $services["dc"] = [
227 - "pause" => "",
228 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
229 - "time_of_the_last_test" => convertTimeToReadable($site['lastTest']['time']),
230 - "number" => $site['count'],
231 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.deface')
232 - ];
233 - break;
234 - case "ports":
235 - $services["ps"] = [
236 - "pause" => "",
237 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
238 - "ip" => $site['ip'],
239 - "last_test" => convertTimeToReadable($site['lastTest']['time']),
240 - "number" => count($site['tcp']),
241 - "tcp" => !empty($site['tcp']) ? implode(",", $site['tcp']) : '',
242 - "udp" => "",
243 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.port')
244 - ];
245 - break;
246 - case "firewall":
247 - $service = "WAF";
248 - $_service = strtolower($service);
249 - $domain = $host['hostname'];
250 - $uid = $host['id'];
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');
251 269
252 - $chart = generateChart($site['chart'], 7);
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);
253 317 // $status = wtsec_checkStatus($uid, $service);
254 318
255 - $data = WTSEC_LIBRARY_WT::getFirewall($host['id']);
256 - $data = $data['data']['auth']['viewer']['sites']['one']['firewall'];
319 + $countryAttacks = wtsec_getCountryAttacks($site['map'], $chart['count_attacks']);
320 + $edges = $site['logs']['edges'];
257 321
258 - $countryAttacks = getCountryAttacks($data['map'], $chart['count_attacks']);
259 - $edges = $data['logs']['edges'];
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;
260 344
261 - $services["waf"] = [
262 - "pause" => "",
263 - "site_address" => $domain,
264 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
265 - "_status" => $site['status'],
266 - "installed_status" => in_array($site['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true,
267 - "time_of_the_last_check" => convertTimeToReadable($site['lastTest']['time']),
268 - "attacks" => $chart['count_attacks'],
269 - "blocking" => $chart['count_blocks'],
270 - "non-blocking" => $chart['count_attacks'] - $chart['count_blocks'],
271 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'),
272 - "actions" => wtsec_generateButtons($uid, $_service, $service, $site['status'], WTSEC_SITE_URL),
273 - "chart" => json_encode($chart['chart'], true),
274 - "edges" => $edges,
275 - "countryAttacks" => $countryAttacks,
276 - ];
277 - break;
278 - case "antivirus":
279 - $service = "AV";
280 - $_service = strtolower($service);
281 - $domain = $host['hostname'];
282 - $uid = $host['id'];
345 + break;
346 + case "antivirus":
347 + $service = "AV";
348 + $_service = strtolower($service);
349 + $domain = $host['hostname'];
350 + $uid = $host['id'];
283 351 // $status = wtsec_checkStatus($uid, $service);
284 - $services["vc"] = [
285 - "pause" => "",
286 - "site_address" => $domain,
287 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
288 - "installed_status" => in_array($site['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true,
289 - "_status" => $site['status'],
290 - "signatures" => (int)$site['stats']['infected'],
291 - "changes" => (int)$site['stats']['changed'],
292 - "scanned" => (int)$site['stats']['scaned'],
293 - "deleted" => (int)$site['stats']['deleted'],
294 - "list" => $site['stats']["infected"],
295 - "actions" => wtsec_generateButtons($uid, $_service, $service, $site['status'], WTSEC_SITE_URL),
296 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
297 - ];
298 - break;
299 - }
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;
300 368 }
369 + }
301 370
302 - //check AM, if not installed , run install
303 - $process = "installing";
304 - $check_am_file = wtsec_checkInstalledFile("AM");
305 - $am_installed = $check_am_file["status"];
306 - $am_installed_status = wtsec_app()->get('am_installed');
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');
307 376
308 - if (!$am_installed || !$am_installed_status) {
309 - $am_is_installed = wtsec_cmd("am_install", "AM", "am", $host['id'], [], WTSEC_SITE_URL);
310 - if (!$am_is_installed) {
311 - $process = "failed";
312 - wtsec_app()->set('am_installed', false);
313 - } else {
314 - wtsec_app()->set('am_installed', true);
315 - }
316 - } elseif ($services["vc"]["_status"] === "not_installed" || $services["waf"]["_status"] === "not_installed") {
317 - $process = "installing";
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);
318 382 } else {
319 - $process = "installed";
383 + wtsec_app()->set('am_installed', true);
320 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 + }
321 392
322 - $services["am"] = [
323 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($am_installed ? "working" : "not_installed"),
324 - "actions" => wtsec_generateButtons($host['id'], "am", "AM", ["active" => $check_am_file], WTSEC_SITE_URL),
325 - "process_status" => $process,
326 - "installed" => $am_installed,
327 - ];
328 - }
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 + ];
329 399
330 - wtsec_layout("dashboard", $services);
400 + return $services;
331 401 }
332 402
333 -function getCountryAttacks($map, $countAttacks){
403 +function wtsec_reinstall(){
404 + wtsec_app()->set('am_installed', false);
405 + echo wtsec_getUrl('dashboard');
406 + wp_die();
407 +}
334 408
409 +function wtsec_getCountryAttacks($map, $countAttacks){
410 +
335 411 if($map){
336 412 $attackKey = array_search(max(array_column($map, 'attacks')), array_column($map, 'attacks'));
337 - $map[$attackKey]['percent'] = round($map[$attackKey]['attacks'] / $countAttacks * 100);
338 - $map[$attackKey]['country'] = wtsec_locale("countries.".$map[$attackKey]['country']);
413 + $map[$attackKey]['percent'] = ($countAttacks) ? round($map[$attackKey]['attacks'] / $countAttacks * 100) : 0;
414 + $map[$attackKey]['country'] = wtsec_getCountryName($map[$attackKey]['country']);
339 415 return $map[$attackKey];
340 416 }
341 417
342 418 return ['percent' => 0, 'country' => false];
419 +}
343 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];
344 429 }
345 430
346 -function generateChart($charts, $days = 7)
431 +// Server Status chart
432 +function wtsec_chartData($charts, $days)
347 433 {
348 434
349 - if(is_array($days)) {
350 - $beginDate = new DateTime( $days['begin'] );
351 - $endDate = new DateTime( $days['end'] );
352 - $dateDiff = strtotime($days['end'] - strtotime($days['begin']));
353 - $days = floor($dateDiff / (60 * 60 * 24));
435 + $sum = 0;
436 + foreach ($charts as $chart){
437 + $sum += $chart['value'];
354 438 }
439 + if($sum == 0){
440 + return false;
441 + }
355 442
356 - if($days <= 1){
357 - $begin = new DateTime( date('Y-m-d 00:00:00') );
358 - $end = new DateTime( date('Y-m-d 23:59:59') );
359 - $step = 'hour';
360 - } elseif($days <= 31){
361 - $begin = new DateTime( date('Y-m-d', strtotime('-'.($days - 1).' day')) );
362 - $end = new DateTime( date('Y-m-d') );
363 - $step = 'day';
364 - } else {
365 - $begin = new DateTime( date('Y-m-01', strtotime('- 11 month')) );
366 - $end = new DateTime( date('Y-m-01', time()) );
367 - $step = 'month';
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 + ];
368 451 }
369 452
453 + return json_encode($result, true);
454 +}
370 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 = [];
371 468 $count_attacks = 0;
372 469 $count_blocks = 0;
373 - $c = [];
374 470
375 - for($i = $begin; $i <= $end; $i->modify('+1 '.$step)){
471 + if($days <= 1) {$time_zone = WTSEC_LIBRARY_App::_get('time_zone');}
376 472
377 - $c[$i->format('U')] = [
378 - 'date' => ($days <= 1) ? $i->format("Y-m-d H:00:00") : $i->format("Y-m-d"),
379 - 'count' => 0,
380 - 'attacks' => 0,
381 - 'blocked' => 0,
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'],
382 480 ];
383 - }
384 -
385 - foreach ($charts as $chart) {
386 - $d = strtotime($chart['time']);
387 - $c[$d]['count'] = $chart['blocked'];
388 - $c[$d]['attacks'] = $chart['attacks'];
389 - $c[$d]['blocked'] = $chart['blocked'];
390 481 $count_attacks += $chart['attacks'];
391 482 $count_blocks += $chart['blocked'];
392 483 }
393 484
394 485
395 - //unset keys, because the js parser sorting by key in integer
396 - $result = [];
397 - foreach ($c as $d) {
398 - $result[] = $d;
399 - }
400 -
401 - return ['chart' => $result, 'count_attacks' => $count_attacks, 'count_blocks' => $count_blocks];
486 + return ['chart' => json_encode($result), 'count_attacks' => $count_attacks, 'count_blocks' => $count_blocks];
402 487 }
403 488
404 489 function wtsec_getInformation($service, $status)
405 490 {
@@ -435,24 +520,21 @@
435 520 }
436 521
437 522 function wtsec_options_page()
438 523 {
524 + $options = [];
439 525 $host = WTSEC_LIBRARY_WT::getOwnSite();
440 - $result = WTSEC_LIBRARY_WT::getOptions($host['id']);
441 - $options = [];
442 - if (isset($result['data']['userHost']['services'])) {
443 - foreach ($result['data']['userHost']['services'] as $service) {
444 - $configs = $service['configs'][0];
445 - $options[$service['name']] = ['config_id' => $configs['id'], 'is_active' => $configs['isActive']];
446 - }
526 + if(!empty($host)){
527 + $options = wtsec_getConfigs($host['id']);
528 + $options['settings']['login_attempt'] = WTSEC_LIBRARY_App::_get('check_login_attempt');
447 529 }
448 - $options['host_id'] = $host['id'];
530 +
449 531 wtsec_layout("options", $options);
450 532 }
451 533
452 -function wtsec_services_page()
534 +function wtsec_information_page()
453 535 {
454 - wtsec_layout("services");
536 + wtsec_layout("information");
455 537 }
456 538
457 539 function wtsec_antivirus_page()
458 540 {
@@ -458,38 +540,61 @@
458 540 {
459 541 $host = WTSEC_LIBRARY_WT::getOwnSite();
460 542 $services = [];
461 543 if (!empty($host)) {
462 - $site = WTSEC_LIBRARY_WT::getAntivirus($host['id']);
463 - if (isset($site['data']['auth']['viewer']['sites']['one']['antivirus']['log'])) {
464 - $site = $site['data']['auth']['viewer']['sites']['one']['antivirus'];
544 + $services = wtsec_antivirus_getData($host);
545 + }
546 + wtsec_layout("antivirus", $services);
465 547
466 - $_SESSION['antivirus_endCursor'] = $site['log']['pageInfo']['endCursor'];
467 - $_SESSION['antivirus_hasNextPage'] = $site['log']['pageInfo']['hasNextPage'];
548 +}
468 549
469 - $service = "AV";
470 - $_service = strtolower($service);
471 - $domain = $host['hostname'];
472 - $uid = $host['id'];
473 - $status = wtsec_checkStatus($uid, $service);
474 - $services["vc"] = [
475 - "pause" => "",
476 - "site_address" => $domain,
477 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
478 - "signatures" => (int)$site['stats']['infected'],
479 - "changes" => (int)$site['stats']['changed'],
480 - "scanned" => (int)$site['stats']['scaned'],
481 - "deleted" => (int)$site['stats']['deleted'],
482 - "list" => $site["log"]['edges'],
483 - "actions" => $buttons = wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL),
484 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
485 - ];
486 - }
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']);
487 568 }
488 - wtsec_layout("antivirus", $services);
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;
489 595 }
490 596
491 -
492 597 function wtsec_firewall_page()
493 598 {
494 599 $host = WTSEC_LIBRARY_WT::getOwnSite();
495 600 $services = [];
@@ -494,25 +599,24 @@
494 599 $host = WTSEC_LIBRARY_WT::getOwnSite();
495 600 $services = [];
496 601
497 602 if (!empty($host)) {
498 - $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10,null,7);
499 - $chart = WTSEC_LIBRARY_WT::getFirewallChart($host['id'], 7);
603 + $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10,null,30);
604 + $chart = WTSEC_LIBRARY_WT::getFirewallChart($host['id'], 30);
500 605 if (isset($site['data']['auth']['viewer']['sites']['one']['firewall']['logs'])) {
501 606 $logs = $site['data']['auth']['viewer']['sites']['one']['firewall']['logs'];
502 607 $firewall = $site['data']['auth']['viewer']['sites']['one']['firewall'];
503 608 $edges = $logs['edges'];
504 609
505 - $chart = $chart['data']['auth']['viewer']['sites']['one']['firewall']['chart'];
610 + $chart_ = wtsec_generateChart($chart, 30);
506 611
507 - $chart = generateChart($chart, 7);
508 -
509 612 $domain = $host['hostname'];
510 613
511 - $_SESSION['firewall_endCursor'] = $logs['pageInfo']['endCursor'];
512 - $_SESSION['firewall_hasNextPage'] = $logs['pageInfo']['hasNextPage'];
614 + WTSEC_LIBRARY_App::_set('firewall_endCursor', $logs['pageInfo']['endCursor']);
615 + WTSEC_LIBRARY_App::_set('firewall_hasNextPage', $logs['pageInfo']['hasNextPage']);
513 616
514 - $countryAttacks = getCountryAttacks($firewall['map'], $chart['count_attacks']);
617 + $countryAttacks = wtsec_getCountryAttacks($firewall['map'], $chart_['count_attacks']);
618 + $attacksMap = ($firewall['map'])?wtsec_getAttacksMap($firewall['map']):false;
515 619
516 620 $services["waf"] = [
517 621 "pause" => "",
518 622 "site_address" => $domain,
@@ -519,15 +623,18 @@
519 623 "status" => WTSEC_LIBRARY_WT::getStatusIcon($firewall['status']),
520 624 "_status" => $firewall['status'],
521 625 "installed_status" => in_array($firewall['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true,
522 626 "time_of_the_last_check" => convertTimeToReadable($firewall['lastTest']['time']),
523 - "attacks" => $chart['count_attacks'],
524 - "blocking" => $chart['count_blocks'],
525 - "non-blocking" => $chart['count_attacks'] - $chart['count_blocks'],
627 + "attacks" => $chart_['count_attacks'],
628 + "blocking" => $chart_['count_blocks'],
629 + "non-blocking" => $chart_['count_attacks'] - $chart_['count_blocks'],
526 630 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'),
527 - "chart" => json_encode($chart['chart'], true),
631 + "chart" => $chart_['chart'],
528 632 "edges" => $edges,
529 633 "countryAttacks" => $countryAttacks,
634 + "attacksMap" => $attacksMap,
635 + "hasNextPage" => $logs['pageInfo']['hasNextPage'],
636 + 'settings' => $firewall['settings']
530 637 ];
531 638 }
532 639 }
533 640 wtsec_layout("firewall", $services);
@@ -532,8 +639,123 @@
532 639 }
533 640 wtsec_layout("firewall", $services);
534 641 }
535 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 +
536 758 /**
537 759 * ajax load firewall
538 760 */
539 761 function wtsec_ajax_firewall()
@@ -538,30 +760,33 @@
538 760 */
539 761 function wtsec_ajax_firewall()
540 762 {
541 763 $host = WTSEC_LIBRARY_WT::getOwnSite();
542 - $services = [];
764 + $arguments = [];
543 765
544 766 $post = ($_POST) ? wtsec_clean($_POST):[];
545 - $days = ($post['period']) ? wtsec_period_as_time($post['period']) : 7;
767 + $days = ($post['value']) ? wtsec_period_as_time($post['value']) : 365;
546 768
547 769 if (!empty($host)) {
548 770
549 - if(!$_SESSION['firewall_endCursor'] || $post['filter'] == 'period_filter') $_SESSION['firewall_endCursor'] = null;
771 + $endCursor = WTSEC_LIBRARY_App::_get('firewall_endCursor');
550 772
551 - $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10, $_SESSION['firewall_endCursor'], $days);
773 + if(!$endCursor || $post['filter'] == 'period_filter') $endCursor = null;
774 +
775 + $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10, $endCursor, $days);
552 776 if (isset($site['data']['auth']['viewer']['sites']['one']['firewall']['logs'])) {
553 777 $logs = $site['data']['auth']['viewer']['sites']['one']['firewall']['logs'];
554 778
555 - $services["waf"]['edges'] = $logs['edges'];
779 + $arguments["waf"]['edges'] = $logs['edges'];
780 + $arguments["waf"]['hasNextPage'] = $logs['pageInfo']['hasNextPage'];
556 781
557 - $_SESSION['firewall_endCursor'] = $logs['pageInfo']['endCursor'];
558 - $_SESSION['firewall_hasNextPage'] = $logs['pageInfo']['hasNextPage'];
782 + WTSEC_LIBRARY_App::_set('firewall_endCursor', $logs['pageInfo']['endCursor']);
783 + WTSEC_LIBRARY_App::_set('firewall_hasNextPage', $logs['pageInfo']['hasNextPage']);
559 784 }
560 785
561 786 }
562 787
563 - wtsec_layout_part("_firewall_lazy", $services);
788 + wtsec_layout_part("_firewall_lazy", $arguments);
564 789 wp_die();
565 790 }
566 791
567 792 /**
@@ -569,65 +794,357 @@
569 794 */
570 795 function wtsec_ajax_antivirus()
571 796 {
572 797 $host = WTSEC_LIBRARY_WT::getOwnSite();
573 - $services = [];
798 + $arguments = [];
574 799
575 800 $post = ($_POST) ? wtsec_clean($_POST):[];
576 - $days = ($post['period']) ? wtsec_period_as_time($post['period']) : 7;
577 801
578 802 if (!empty($host)) {
803 + $endCursor = WTSEC_LIBRARY_App::_get('antivirus_endCursor');
579 804
580 - if(!$_SESSION['antivirus_endCursor'] || $post['filter'] == 'period_filter') $_SESSION['antivirus_endCursor'] = null;
581 - if($post['event'] || $_SESSION['antivirus_event']){
582 - if($post['event']){
583 - $_SESSION['antivirus_event'] = $post['event'];
584 - }
585 - $site = WTSEC_LIBRARY_WT::getAntivirus($host['id'],10, $_SESSION['antivirus_endCursor'],$days, $_SESSION['antivirus_event']);
805 + if($post['event']){
806 + WTSEC_LIBRARY_App::_set('antivirus_event', $post['event']);
807 + $event = $post['event'];
586 808 } else {
587 - $site = WTSEC_LIBRARY_WT::getAntivirus($host['id'],10, $_SESSION['antivirus_endCursor'],$days);
809 + $event = WTSEC_LIBRARY_App::_get('antivirus_event');
588 810 }
589 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 +
590 827 if (isset($site['data']['auth']['viewer']['sites']['one']['antivirus']['log'])) {
591 828 $logs = $site['data']['auth']['viewer']['sites']['one']['antivirus']['log'];
592 829
593 - $services["vc"]['list'] = $logs['edges'];
830 + $arguments["vc"]['list'] = wtsec_AVLogsData($logs['edges']);
831 + $arguments["vc"]['hasNextPage'] = $logs['pageInfo']['hasNextPage'];
594 832
595 - $_SESSION['antivirus_endCursor'] = $logs['pageInfo']['endCursor'];
596 - $_SESSION['antivirus_hasNextPage'] = $logs['pageInfo']['hasNextPage'];
833 + WTSEC_LIBRARY_App::_set('antivirus_endCursor', $logs['pageInfo']['endCursor']);
834 + WTSEC_LIBRARY_App::_set('antivirus_hasNextPage', $logs['pageInfo']['hasNextPage']);
597 835
598 836 }
599 837 }
600 - wtsec_layout_part("_antivirus_lazy", $services);
838 + wtsec_layout_part("_antivirus_lazy", $arguments);
601 839
602 840 wp_die();
603 841 }
604 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 +
605 936 /**
606 937 * ajax load chart
607 938 */
608 939 function wtsec_chart_filter()
609 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 +{
610 984 $days = (int)$_POST['days'];
611 985 $days = $days ?: 7;
612 986
613 987 $host = WTSEC_LIBRARY_WT::getOwnSite();
614 - $chart = WTSEC_LIBRARY_WT::getFirewallChart($host['id'], $days);
615 - $chart = $chart['data']['auth']['viewer']['sites']['one']['firewall']['chart'];
616 - $chart = generateChart($chart, $days);
617 - $res['chart'] = json_encode($chart['chart'], true);
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;
618 993 $res['days'] = $days;
619 994
620 - wtsec_layout_part("_chart_ajax", $res);
995 + wtsec_layout_part("_map_view", $res);
621 996
622 997 wp_die();
623 998 }
624 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 +
625 1138 function wtsec_login_form()
626 1139 {
627 1140 if (wtsec_request()->method === "POST") {
628 1141 $result = WTSEC_LIBRARY_WT::auth(wtsec_request()->key);
629 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 +
630 1147 WTSEC_LIBRARY_Session::setNotification("success", WTSEC_LIBRARY_Localization::lmsg('successfully_activated'));
631 1148 $token = $result['data']['guest']['apiKeys']['auth']['token']['value'];
632 1149 WTSEC_LIBRARY_App::login($token);
633 1150 wtsec_app()->set("api_key", wtsec_request()->key);
@@ -646,8 +1163,9 @@
646 1163 $_service = strtolower(wtsec_request()->service);
647 1164 $uid = wtsec_request()->uid;
648 1165 $cmd = wtsec_request()->cmd;
649 1166 $status = wtsec_checkStatus($uid, $service);
1167 +
650 1168 if (stripos($cmd, "install") === false) {
651 1169 wtsec_cmd($cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL);
652 1170 wp_safe_redirect(wp_get_referer());
653 1171 } else {
@@ -669,18 +1187,21 @@
669 1187 {
670 1188 WTSEC_LIBRARY_App::logout();
671 1189 }
672 1190
673 -function wtsec_layout_part($template, $arguments = [])
1191 +function wtsec_layout_part($template, $arguments = [], $components = true)
674 1192 {
675 - require WTSEC_PLUGIN_PATH . "includes/components/" . $template . ".php";
1193 + if($components){
1194 + require WTSEC_PLUGIN_PATH . "includes/components/" . $template . ".php";
1195 + } else {
1196 + require WTSEC_PLUGIN_PATH . "includes/" . $template . ".php";
1197 + }
676 1198
677 1199 }
678 1200
679 -function wtsec_layout($template, $arguments = [], $faq = "faq")
1201 +function wtsec_layout($template, $arguments = [])
680 1202 {
681 1203 $body = WTSEC_PLUGIN_PATH . "includes/" . $template . ".php";
682 - $faq = WTSEC_PLUGIN_PATH . "includes/" . $faq . ".php";
683 1204 require_once WTSEC_PLUGIN_PATH . "includes/layout.php";
684 1205 }
685 1206
686 1207
@@ -704,8 +1225,9 @@
704 1225 }
705 1226 wp_safe_redirect(wp_get_referer());
706 1227 }
707 1228
1229 +
708 1230 function wtsec_page($page)
709 1231 {
710 1232 return wtsec_pages()[$page];
711 1233 }
@@ -724,10 +1246,10 @@
724 1246 }
725 1247
726 1248 function wtsec_period_as_time($period){
727 1249 $end = $period[1] ?: $period[0];
728 - $array['begin'] = strtotime(date('d-m-Y 00:00:00',strtotime($period[0])));
729 - $array['end'] = strtotime(date('d-m-Y 23:59:59',strtotime($end)));
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)));
730 1252
731 1253 return $array;
732 1254 }
733 1255
@@ -743,17 +1265,12 @@
743 1265
744 1266 function wtsec_pages()
745 1267 {
746 1268 return [
747 -// "options" => [
748 -// "page_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
749 -// "menu_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
750 -// "function" => "wtsec_options_page",
751 -// ],
752 - "services" => [
753 - "page_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
754 - "menu_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
755 - "function" => "wtsec_services_page",
1269 + "options" => [
1270 + "page_title" => WTSEC_LIBRARY_Localization::lmsg('settings'),
1271 + "menu_title" => WTSEC_LIBRARY_Localization::lmsg('settings'),
1272 + "function" => "wtsec_options_page",
756 1273 ],
757 1274 "vc" => [
758 1275 "page_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'),
759 1276 "menu_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'),
@@ -767,7 +1284,272 @@
767 1284 "function" => "wtsec_firewall_page",
768 1285 "vc_action" => "firewall-action",
769 1286 "vc_function" => "wtsec_firewall_function"
770 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 + ],
771 1303 ];
772 1304 }
773 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 +}