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
wt-security / library / WT.php

WT.php in WebTotem Security 2.3.24, at library/WT.php

525 lines 27.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php defined('ABSPATH') or die("Protected By WT!");
2
3
4 class WTSEC_LIBRARY_WT
5 {
6
7 const URL = "https://api.wtotem.com/graphql";
8
9 public static function auth($key)
10 {
11 $source = WTSEC_SITE_URL;
12 $payload = '{"query":"mutation{ guest{ apiKeys{ auth(apiKey:\"' . $key . '\", source:\"' . $source . '\"),{ token{ value,refreshToken,expiresIn } } } } }"}';
13 return self::requestApi($payload, false, true);
14 }
15
16 protected static function requestApi($payload, $token = false, $repeat = false)
17 {
18 if ($token) {
19 $token = WTSEC_LIBRARY_App::getToken();
20 }
21
22 $token_expired = wtsec_app()->get("token_expired");
23
24 if($token_expired <= time() && !$repeat){
25 $result = WTSEC_LIBRARY_WT::auth(wtsec_app()->get("api_key"));
26 if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) {
27 $expiresIn = $result['data']['guest']['apiKeys']['auth']['token']['expiresIn'];
28 $token_expired = time() + $expiresIn - 60;
29 wtsec_app()->set("token_expired", $token_expired);
30
31 $token_ = $result['data']['guest']['apiKeys']['auth']['token']['value'];
32 WTSEC_LIBRARY_App::login($token_);
33 return self::requestApi($payload, $token, true);
34 } else {
35 WTSEC_LIBRARY_App::logout();
36 }
37 }
38
39
40 $args = [
41 'body' => $payload,
42 'timeout' => '60',
43 'sslverify' => false,
44 'headers' => ['Content-Type:application/json', 'Content-Type' => 'application/json', 'source:WORDPRESS', 'Accept: application/json'],
45 ];
46 if (!is_null($token) && $token) {
47 $authorization = "Bearer " . $token;
48 $args['headers'] = array_merge($args['headers'], ["Authorization" => $authorization]);
49 }
50 $response = wp_remote_post(self::URL, $args);
51 $httpcode = wp_remote_retrieve_response_code($response);
52
53 if ($httpcode < 200) {
54 WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server'));
55 }
56 $response = wp_remote_retrieve_body($response);
57 $result = json_decode($response, true);
58 if (isset($result['errors'][0]['message'])) {
59 $message = self::diffMesageForHuman($result['errors'][0]['message']);
60 if (stripos($result['errors'][0]['message'], "token") !== false && !$repeat) {
61 $result = WTSEC_LIBRARY_WT::auth(wtsec_app()->get("api_key"));
62 if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) {
63 $token_ = $result['data']['guest']['apiKeys']['auth']['token']['value'];
64 WTSEC_LIBRARY_App::login($token_);
65 return self::requestApi($payload, $token, true);
66 } else {
67 WTSEC_LIBRARY_App::logout();
68 }
69 } else {
70 if ($message !== false) {
71 WTSEC_LIBRARY_Session::setNotification("warning", $message);
72 }
73 }
74 }
75 return $result;
76 }
77
78 public static function diffMesageForHuman($message)
79 {
80 $definition = $message;
81 $excepts = [
82 "RESOURCE_NOT_FOUND", "DUPLICATE_HOST", "INVALID_CREDENTIALS", "INVALID_API_KEY", "Invalid token",
83 ];
84 if (in_array($message, $excepts)) {
85 return false;
86 }
87 switch ($message) {
88 case 'HOSTS_LIMIT_EXCEEDED':
89 $definition = WTSEC_LIBRARY_Localization::lmsg('hosts_limit_exceed');
90 break;
91 case 'Invalid token':
92 $definition = WTSEC_LIBRARY_Localization::lmsg('invalid_token');
93 break;
94 case 'USER_ALREADY_REGISTERED':
95 $definition = WTSEC_LIBRARY_Localization::lmsg('user_already_exist');
96 break;
97 case 'DUPLICATE_HOST':
98 $definition = WTSEC_LIBRARY_Localization::lmsg('duplicate_host');
99 break;
100 case 'INVALID_DOMAIN_NAME':
101 $definition = WTSEC_LIBRARY_Localization::lmsg('invalid_domain_name');
102 break;
103 }
104 return $definition;
105 }
106
107 //del
108 public static function requestURL($url)
109 {
110 $args = [
111 'timeout' => '30',
112 'sslverify' => false,
113 ];
114 $response = wp_remote_get($url, $args);
115 $httpcode = wp_remote_retrieve_response_code($response);
116 if ($httpcode < 200) {
117 WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server')." requestURL");
118 }
119 $response = wp_remote_retrieve_body($response);
120 return $response;
121 }
122
123
124 public static function getFileByUrl($url, $fileName)
125 {
126 $url = $url.'/'.$fileName;
127 $args = [
128 'timeout' => '30',
129 'sslverify' => false,
130 ];
131 $response = wp_remote_get($url, $args);
132 $httpcode = wp_remote_retrieve_response_code($response);
133 if ($httpcode < 200) {
134 WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server')." getFileByUrl");
135 }
136
137 $response = wp_remote_retrieve_body($response);
138 return ["body" => $response, "filename" => $fileName];
139 }
140
141
142 public static function getEmail(){
143 $payload = '{"query":"query { auth { viewer { email __typename } __typename } }"}';
144 $result = self::requestApi($payload, true);
145
146 return $result['data']['auth']['viewer']['email'];
147 }
148
149 public static function getOwnSite($attempt = false)
150 {
151 $sites = [
152 WTSEC_LIBRARY_Idn::idn_to_utf8(WTSEC_SITE_URL),
153 WTSEC_LIBRARY_Idn::idn_to_utf8('www.'.WTSEC_SITE_URL)
154 ];
155
156 foreach ($sites as $site){
157 $payload = '{"query":"query getSites { auth { viewer { sites { ...sites } } } }fragment sites on SiteQueries { list( filter: {search: \"'.$site.'\"} ) { edges { node { id hostname title ssl { status } availability { status } reputation { status } ports { status } deface { status } domain { status } antivirus { status } firewall { status } maliciousScript { stack { name } } } } } }"}';
158 $result = self::requestApi($payload, true);
159
160 if (isset($result['data']['auth']['viewer']['sites']['list']['edges'][0]['node'])){
161 return $result['data']['auth']['viewer']['sites']['list']['edges'][0]['node'];
162 }
163 }
164
165 $add_site = self::addSite(WTSEC_SITE_URL);
166 if (isset($add_site['errors'])) {
167 return $result['data']['node'] = [];
168 } else {
169 if (!$attempt) {
170 return self::getOwnSite(true);
171 }
172 }
173
174 return [];
175 }
176
177 public static function addSite($url)
178 {
179 $payload = '{"variables":{"input":{"title":"' . $url . '","hostname":"' . $url . '","configs":{"scheme":"http","port":80,"wa":{},"dec":{},"ps":{}}}},"query":"mutation ($input: CreateSiteInput) { auth { sites { create(input: $input) { id hostname title } } }}"}';
180 return self::requestApi($payload, true);
181 }
182
183 public static function getAllChecks($host_id)
184 {
185 $from = time() - (60 * 60 * 24 * 7);
186 $to = time();
187 $from_waf = time() - (60 * 60 * 24 * 30);
188 $language = WTSEC_LANGUAGE;
189 $payload = '{"query":"query($id: ID!, $dateRange: DateRangeInput!, $language: Language!, $dateRangeWeek: DateRangeInput!, $wafLogFilter: WafLogFilter!) { auth { viewer { sites { one(id: $id) { ports { status ip tcp lastTest { time } } availability { status lastTest { time } responseTime downTime(dateRange: $dateRange) percent(dateRange: $dateRange) } deface { status lastTest { time } words count } domain { status registrar owner email createdDate expiredDate } ports { status lastTest { time } ip tcp country } ssl { status daysLeft expiryDate issueDate } reputation { status lastTest { time } virusList { virus{ type path } antiVirus } } firewall { lastTest { time } logs(wafLogFilter: $wafLogFilter){ edges{ node{ type blocked payload ip location{ country{ nameEn } } time request status country category } } } map(dateRange: $dateRange) { attacks, country } status chart(dateRange: $dateRange) { time attacks blocked } report(dateRange: $dateRange) { time attacks ip } } serverStatus { info { phpVersion phpServerUser phpServerSoftware phpGatewayInterface phpServerProtocol osInfo cpuCount cpuModel CpuFreq cpuFamily lsCpu maxExecTime mathLibraries } ramChart(dateRange: $dateRangeWeek){ total value time } cpuChart(dateRange: $dateRangeWeek){ value time } discUsage{ total free } status } maliciousScript { lastTest { time } status } scoring( language: $language ){ score lastTest{ time } result{ ip country isHigherThan }} agentManager{ createdAt } antivirus { status stats { changed deleted scaned infected error } lastTest { time } isFirstCheck } } } } } }","variables":{"id":"' . $host_id . '","dateRange":{"to":' . $to . ',"from":' . $from_waf . '}, "dateRangeWeek":{"to":' . $to . ',"from":' . $from . '}, "wafLogFilter": {"order":{"direction":"DESC","field":"time"},"pagination":{"first":5,"cursor":null}}, "language":"'.$language.'"}}';
190 $response = self::requestApi($payload, true);
191 if (isset($response['data']['auth']['viewer']['sites']['one'])) {
192 return $response['data']['auth']['viewer']['sites']['one'];
193 }
194 return [];
195 }
196
197 public static function getFirewall($host_id, $limit = 20, $cursor = null, $days = 365)
198 {
199 $from = (is_array($days)) ? $days['from'] : time() - (60 * 60 * 24 * $days);
200 $to = (is_array($days)) ? $days['to'] : time();
201 $cursor = ($cursor == null) ? 'null' : '"'.$cursor.'"';
202
203 $payload = '{"operationName":"FirewallAttackLog","variables":{"dateRange":{"to":'.$to.',"from":'.$from.'},"id":"'.$host_id.'","wafLogFilter":{"dateRange":{"to":'.$to.',"from":'.$from.'},"order":{"direction":"DESC","field":"time"},"pagination":{"first":'.$limit.',"cursor":' . $cursor . '}}},"query":"query FirewallAttackLog($id: ID!, $wafLogFilter: WafLogFilter!, $dateRange: DateRangeInput!) { auth { viewer { sites { one(id: $id) { firewall { lastTest { time } settings{ gdn dosProtection dosLimit loginAttemptsProtection loginAttemptsLimit } status... FirewallLogFragment map(dateRange: $dateRange) { attacks, country } __typename } __typename } __typename } __typename } __typename } } fragment FirewallLogFragment on Waf { logs(wafLogFilter: $wafLogFilter) { edges { cursor node { type blocked payload ip location { country { nameEn __typename } __typename } time request status country category __typename } __typename } pageInfo { endCursor hasNextPage __typename } __typename } __typename }"}';
204 $res = self::requestApi($payload, true);
205
206 return $res;
207 }
208
209 public static function getAntivirus($params)
210 {
211 $permissionsChanged = $params['permissionsChanged'] ? ' "permissionsChanged":true, ' : '';
212
213 $event = $params['event'] ?: 'new';
214 $event = $params['permissionsChanged'] ? '' : '"event":"'.$event.'", ';
215
216 $days = $params['days'];
217
218 $from = (is_array($days)) ? $days['from'] : time() - (60 * 60 * 24 * $days);
219 $to = (is_array($days)) ? $days['to'] : time();
220 $cursor = ($params['endCursor'] == null) ? 'null' : '"' . $params['endCursor'] . '"';
221 $payload = '{"operationName":null,"variables":{"id":"' . $params['host_id'] . '","avLogFilter":{'. $permissionsChanged . $event .' "dateRange":{"to":'.$to.',"from":'.$from.'},"order":{"direction":"DESC","field":"time"},"pagination":{"first":' . $params['limit'] . ',"cursor":' . $cursor . '}}},"query":"query ($id: ID!, $avLogFilter: AvLogFilter!) { auth { viewer { sites { one(id: $id) { id ... on Site { configs { ... on AvConfig { isActive id } } } antivirus { status log(avLogFilter: $avLogFilter) { edges { node { filePath matches event signatures time permissions permissionsChanged } } pageInfo { endCursor hasNextPage __typename } } lastTest { time } stats { changed deleted scaned infected } } } } } } }"}';
222 return self::requestApi($payload, true);
223 }
224
225 public static function getFirewallChart($host_id, $days = 7)
226 {
227 $to = time();
228 $from_waf = ($days <= 1) ? strtotime(date('Y-m-d 00:00:01')) : time() - (60 * 60 * 24 * $days);
229
230 $payload = '{ "query":"query($id: ID!, $dateRange: DateRangeInput!, $wafLogFilter: WafLogFilter!) { auth { viewer { sites { one(id: $id) { firewall { lastTest { time } status logs(wafLogFilter: $wafLogFilter) { edges { node { status country type userAgent } } } chart(dateRange: $dateRange) { time attacks blocked } report(dateRange: $dateRange) { time attacks ip } } } } } } }", "operationName":null,"variables":{"id":"' . $host_id . '","dateRange":{"to":' . $to . ',"from":' . $from_waf . '}, "wafLogFilter": { "dateRange": { "from": ' .$from_waf. ', "to": ' .$to. ' }, "pagination": { "cursor": null }, "order": { "direction": "DESC", "field": "time" } } } }';
231 $response = self::requestApi($payload, true);
232 return $response['data']['auth']['viewer']['sites']['one']['firewall']['chart'];
233 }
234
235 public static function forceCheck($host_id, $service)
236 {
237 $payload = '{"variables":{"id":"'.$host_id.'","service":"'.$service.'"},"query":"mutation ($id: ID!, $service: ForceCheckService!) { auth { sites { forceCheck(siteId: $id, service: $service) } } }"} ';
238 return self::requestApi($payload, true);
239 }
240
241 public static function avExport($host_id)
242 {
243 $from = time() - (60 * 60 * 24 * 30);
244 $to = time();
245 $payload = '{"variables":{ "input":{"siteId":"'.$host_id.'", "dateRange":{"to":'.$to.',"from":'.$from.'} }},"query":"mutation ($input: AvLogExportInput!) { auth { sites { av { export(input: $input) } } } }"} ';
246 return self::requestApi($payload, true);
247 }
248
249 public static function wafGetIpList($host_id)
250 {
251 $payload = '{"variables":{ "id": "'.$host_id.'" },"query":"query($id: ID!) { auth { viewer { sites{ one(id: $id){ firewall{ blackList{ id ip createdAt } whiteList{ id ip createdAt } settings{ gdn dosProtection dosLimit loginAttemptsProtection loginAttemptsLimit } } } } } } }"} ';
252 return self::requestApi($payload, true);
253 }
254
255 public static function wafAddIpToList($host_id, $ips, $color)
256 {
257 $payload = '{"variables":{ "input": { "siteId": "'.$host_id.'", "ips": "'.$ips.'", "color": "'.$color.'" } }, "query":"mutation($input: WafListInput!) { auth { sites { waf { addToList(input: $input) } } } }"} ';
258 return self::requestApi($payload, true);
259 }
260
261 public static function wafRemoveIpToList($id)
262 {
263 $payload = '{"variables":{ "id": "'.$id.'" },"query":"mutation($id: ID!) { auth { sites { waf { removeFromList(id: $id) } } } }"} ';
264 return self::requestApi($payload, true);
265 }
266
267 public static function changeStatus($config_id, $host_id)
268 {
269 $payload = '{"query":"\n mutation {\n toggleServiceConfig(\n id: ' . $config_id . '\n userhostId: ' . $host_id . '\n ) {\n isActive\n }\n }\n "}';
270 return self::requestApi($payload, true);
271 }
272
273 public static function serviceConnect($id, $service)
274 {
275 $payload = '{"query":"mutation {\n auth {\n agents{\n check(siteId:\"' . $id . '\",service:' . strtolower($service) . ',plugin:WORDPRESS)\n }\n }\n}\n"}';
276 return self::requestApi($payload, true);
277 }
278
279 public static function generateFile($id, $service)
280 {
281 $payload = '{"query":"mutation {\n auth {\n agents{\n generate(siteId:\"' . $id . '\",service:' . strtolower($service) . '){\n agentName\n }\n }\n }\n}\n"}';
282 return self::requestApi($payload, true);
283 }
284
285 public static function generateAmFile($id)
286 {
287 $payload = '{ "operationName":null, "variables":{}, "query":"mutation { auth { am { install(siteId: \"'.$id.'\"){ downloadLink, amFilename, wafFilename, avFilename } } } }"}';
288 return self::requestApi($payload, true);
289 }
290
291 public static function deleteAm($id)
292 {
293 $payload = '{ "query":"mutation { auth { am { delete(siteId: \"'.$id.'\") } } }"}';
294 return self::requestApi($payload, true);
295 }
296
297 public static function checkStatus($id, $service)
298 {
299 $payload = '{"operationName":null,"variables":{"id":"' . $id . '"},"query":"query ($id: ID!) {\n auth {\n viewer {\n sites {\n one(id: $id) {\n ... on Site {\n configs {\n ... on ' . $service . 'Config {\n isActive\n id\n }\n }\n }\n }\n }\n }\n }\n}\n"}';
300 return self::requestApi($payload, true);
301 }
302
303
304 public static function getQuarantineList($host_id)
305 {
306 $payload = '{"query":"query{ auth{ viewer{ sites{ one(id:\"'.$host_id.'\"){ antivirus{ quarantine{ id path date } } } } } } } "}';
307 return self::requestApi($payload, true);
308 }
309
310 public static function moveToQuarantine($host_id, $path)
311 {
312 $payload = '{"query":"mutation{ auth{ sites{ av{ moveToQuarantine(input:{ siteId:\"'.$host_id.'\", path:\"'.$path.'\" }) } } } } "}';
313 return self::requestApi($payload, true);
314 }
315
316 public static function moveFromQuarantine($id)
317 {
318 $payload = '{"query":"mutation{ auth{ sites{ av{ moveFromQuarantine(id: \"'.$id.'\") } } } } "}';
319 return self::requestApi($payload, true);
320 }
321
322 public static function reportsList($host_id, $limit = 10, $cursor = null)
323 {
324 $cursor = ($cursor == null) ? 'null' : '"' . $cursor . '"';
325 $payload = '{"variables":{ "filter": { "order": { "direction": "DESC", "field": "created_at"}, "siteId":"'.$host_id.'", "pagination":{"first":' . $limit . ', "cursor":' . $cursor . '} } },"query":"query ReportsQuery($filter: ReportListFilter!) { auth { viewer { reports { list(filter: $filter) { edges { node { id site { hostname } createdAt wa dc ps rc sc av waf } cursor } pageInfo { endCursor hasNextPage } } } } } }"}';
326 return self::requestApi($payload, true);
327 }
328
329 public static function reportGenerate($host_id, $period, $services, $language = "en")
330 {
331 $from = (is_array($period)) ? $period['from'] : time() - (60 * 60 * 24 * $period);
332 $to = (is_array($period)) ? $period['to'] : time();
333 $payload = '{"query":"query ($input: GenerateReportInput) { auth { viewer { reports { generate(input: $input) } } } }", "variables":{ "input": { "siteId": "' . $host_id . '", "from": ' . $from . ', "to": ' . $to . ', "wa": '.$services['wa'].', "dc": '.$services['dc'].', "ps": '.$services['ps'].', "rc": '.$services['rc'].', "sc": '.$services['sc'].', "av": '.$services['av'].', "waf": '.$services['waf'].', "language": "'.$language.'" } } }';
334
335 return self::requestApi($payload, true);
336 }
337
338 public static function reportDownload($id)
339 {
340 $payload = '{"query": "query { auth { viewer { reports { download(id: \"' . $id . '\") } } } }"}';
341 return self::requestApi($payload, true);
342 }
343
344 public static function getConfigs($host_id)
345 {
346 $payload = '{"query":"query{ auth{ viewer{ sites{ one(id:\"'.$host_id.'\"){ configs{ ... on WaConfig { id service isActive } ... on AvConfig { id service isActive } ... on DcConfig { id service isActive } ... on DecConfig { id service isActive } ... on RcConfig { id service isActive } ... on CmsConfig { id service isActive } ... on PsConfig { id service isActive } ... on WafConfig { id service isActive } } } } } } } "}';
347 return self::requestApi($payload, true);
348 }
349
350 public static function toggleConfigs($service_id)
351 {
352 $payload = '{"query":"mutation{ auth{ configs{ toggle(id: \"'.$service_id.'\"){ ... on WaConfig { service isActive } ... on AvConfig { service isActive } ... on DcConfig { service isActive } ... on DecConfig { service isActive } ... on RcConfig { service isActive } ... on CmsConfig { service isActive } ... on PsConfig { service isActive } ... on WafConfig { service isActive } } } } } "}';
353 return self::requestApi($payload, true);
354 }
355
356 public static function wafSettings($host_id, $settings)
357 {
358 $payload = '{"variables":{"input": {"siteId": "'.$host_id.'", "gdn": '. $settings['gdn'] .', "dosProtection": '.$settings['dosProtection'].', "dosLimit": '.$settings['dosLimit'].', "loginAttemptsProtection": '.$settings['loginAttemptsProtection'].', "loginAttemptsLimit": '.$settings['loginAttemptsLimit'].'}},"query":"mutation WafSettings($input: WafSettingsInput!) { auth { sites { waf{ settings(input: $input) { gdn dosProtection loginAttemptsProtection dosLimit loginAttemptsLimit } } } } }"}';
359 return self::requestApi($payload, true);
360 }
361
362 public static function getServerStatusChart($host_id, $days = 7)
363 {
364 $to = time();
365 $from = ($days <= 1) ? strtotime(date('Y-m-d 00:00:01')) : time() - (60 * 60 * 24 * $days);
366
367 $payload = '{ "query":"query($id: ID!, $dateRange: DateRangeInput!) { auth { viewer { sites { one(id: $id) { serverStatus { ramChart(dateRange: $dateRange){ total value time } cpuChart(dateRange: $dateRange){ value time } } } } } } }", "variables":{"id":"' . $host_id . '","dateRange":{"to":' . $to . ',"from":' . $from . '} } }';
368
369 $response = self::requestApi($payload, true);
370 return $response['data']['auth']['viewer']['sites']['one']['serverStatus'];
371 }
372
373 public static function getStatusIcon($status)
374 {
375 $statuses = [
376 "clean" => [
377 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.ok'),
378 "color" => self::getColor("success"),
379 "image" => "check-mark.svg"
380 ],
381 "pending" => [
382 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.pending'),
383 "color" => self::getColor("grey"),
384 "image" => "loading.svg"
385 ],
386 "pause" => [
387 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.pause'),
388 "color" => self::getColor("grey"),
389 "image" => "warning.svg"
390 ],
391 "expired" => [
392 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.expired'),
393 "color" => self::getColor("orange"),
394 "image" => "warning.svg"
395
396 ],
397 "invalid" => [
398 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.invalid'),
399 "color" => self::getColor("error"),
400 "image" => "warning.svg"
401 ],
402 "no_cert" => [
403 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.no_cert'),
404 "color" => self::getColor("orange"),
405 "image" => "warning.svg"
406 ],
407 "error" => [
408 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.error'),
409 "color" => self::getColor("error"),
410 "image" => "warning.svg"
411 ],
412 "expires" => [
413 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.expires'),
414 "color" => self::getColor("orange"),
415 "image" => "warning.svg"
416 ],
417 "expires_today" => [
418 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.expires_today'),
419 "color" => self::getColor("error"),
420 "image" => "warning.svg"
421 ],
422 "down" => [
423 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.down'),
424 "color" => self::getColor("error"),
425 "image" => "warning.svg"
426 ],
427 "up" => [
428 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.up'),
429 "color" => self::getColor("success"),
430 "image" => "check-mark.svg"
431 ],
432 "infected" => [
433 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.infected'),
434 "color" => self::getColor("error"),
435 "image" => "warning.svg"
436 ],
437 "open_ports" => [
438 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.open'),
439 "color" => self::getColor("orange"),
440 "image" => "warning.svg"
441 ],
442 "deface" => [
443 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.deface'),
444 "color" => self::getColor("error"),
445 "image" => "warning.svg"
446 ],
447 "modified" => [
448 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.modified'),
449 "color" => self::getColor("grey"),
450 "image" => "warning.svg"
451 ],
452 "not_supported" => [
453 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.unsupported'),
454 "color" => self::getColor("orange"),
455 "image" => "warning.svg"
456 ],
457 "not_registered" => [
458 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.not_registered'),
459 "color" => self::getColor("orange"),
460 "image" => "warning.svg"
461 ],
462 "not_installed" => [
463 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.not_installed'),
464 "color" => self::getColor("error"),
465 "image" => "warning.svg"
466 ],
467 "working" => [
468 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.working'),
469 "color" => self::getColor("success"),
470 "image" => "check-mark.svg"
471 ],
472 ];
473 if (isset($statuses[$status])) {
474 $statuses[$status]['type'] = $status;
475 $statuses[$status]["text"] = "<span data-status='$status' class='" . $statuses[$status]["color"]["color"] . "'>" . $statuses[$status]["text"] . "</span>";
476 return $statuses[$status];
477 } else {
478 return ["image" => "warning.svg", "color" => "ww--status_unknow", "text" => "<span class='ww--status_unknow'>Unknown status</span>"];
479 }
480 }
481
482 public static function getColor($type)
483 {
484 $types = [
485 "green" => "is--status--ok",
486 "red" => "is--status--error",
487 "success" => "is--status--ok",
488 "error" => "is--status--error",
489 "orange" => "is--status--warning",
490 "warning" => "is--status--warning",
491 "grey" => "ww--status_unknow"
492 ];
493 $icon_types = [
494 "green" => "ww-icon--status_ok",
495 "red" => "ww-icon--status_error",
496 "success" => "ww-icon--status_ok",
497 "error" => "ww-icon--status_error",
498 "orange" => "ww-icon--status_warning",
499 "warning" => "ww-icon--status_warning",
500 "grey" => "ww-icon--status_unknow"
501 ];
502 return ["icon" => $icon_types[$type], "color" => $types[$type]];
503 }
504
505 public static function getConfigId($configs)
506 {
507 $id = 0;
508 $is_active = false;
509 foreach ($configs as &$config) {
510 if (!empty($config)) {
511 $id = $config['id'];
512 $is_active = $config['isActive'];
513 break;
514 }
515 }
516 return compact('id', 'is_active');
517 }
518
519 public static function getScore(){
520 return self::requestURL("https://api.wtotem.com/site/score?url=".WTSEC_SITE_URL);
521 }
522
523 }
524
525