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 | library/WT.php +148 -50 2.1.72.3.14 View file →
@@ -2,13 +2,15 @@
2 2
3 3
4 4 class WTSEC_LIBRARY_WT
5 5 {
6 - const URL = "https://api.wtotem.com/graphql";
7 6
7 + const URL = "https://api.wtotem.com/graphql";
8 +
8 9 public static function auth($key)
9 10 {
10 - $payload = '{"query":"mutation{\n guest{\n apiKeys{\n auth(apiKey:\"' . $key . '\"),{\n token{\n value,refreshToken,expiresIn\n }\n }\n }\n }\n}"}';
11 + $source = get_site_url();
12 + $payload = '{"query":"mutation{ guest{ apiKeys{ auth(apiKey:\"' . $key . '\", source:\"' . $source . '\"),{ token{ value,refreshToken,expiresIn } } } } }"}';
11 13 return self::requestApi($payload);
12 14 }
13 15
14 16 protected static function requestApi($payload, $token = false, $repeat = false)
@@ -15,11 +17,31 @@
15 17 {
16 18 if ($token) {
17 19 $token = WTSEC_LIBRARY_App::getToken();
18 20 }
21 +
22 + $token_expired = wtsec_app()->get("token_expired");
23 +
24 + if($token_expired && $token_expired <= time()){
25 + $token_expired = wtsec_app()->get("token_expired");
26 + if($token_expired <= time()){
27 + $result = WTSEC_LIBRARY_WT::auth(wtsec_app()->get("api_key"));
28 + if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) {
29 + $expiresIn = $result['data']['guest']['apiKeys']['auth']['token']['expiresIn'];
30 + wtsec_app()->set("token_expired", time() + $expiresIn - 60);
31 +
32 + $token_ = $result['data']['guest']['apiKeys']['auth']['token']['value'];
33 + WTSEC_LIBRARY_App::login($token_);
34 + return self::requestApi($payload, $token, true);
35 + } else {
36 + WTSEC_LIBRARY_App::logout();
37 + }
38 + }
39 + }
40 +
19 41 $args = [
20 42 'body' => $payload,
21 - 'timeout' => '30',
43 + 'timeout' => '60',
22 44 'sslverify' => false,
23 45 'headers' => ['Content-Type:application/json', 'Content-Type' => 'application/json', 'source:WORDPRESS', 'Accept: application/json'],
24 46 ];
25 47 if (!is_null($token) && $token) {
@@ -35,21 +57,11 @@
35 57 $response = wp_remote_retrieve_body($response);
36 58 $result = json_decode($response, true);
37 59 if (isset($result['errors'][0]['message'])) {
38 60 $message = self::diffMesageForHuman($result['errors'][0]['message']);
39 - if (stripos($result['errors'][0]['message'], "token") !== false && !$repeat) {
40 - $result = WTSEC_LIBRARY_WT::auth(wtsec_app()->get("api_key"));
41 - if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) {
42 - $token_ = $result['data']['guest']['apiKeys']['auth']['token']['value'];
43 - WTSEC_LIBRARY_App::login($token_);
44 - return self::requestApi($payload, $token, true);
45 - } else {
46 - WTSEC_LIBRARY_App::logout();
47 - }
48 - } else {
49 - if ($message !== false) {
50 - WTSEC_LIBRARY_Session::setNotification("warning", $message);
51 - }
61 +
62 + if ($message !== false) {
63 + WTSEC_LIBRARY_Session::setNotification("warning", $message);
52 64 }
53 65 }
54 66 return $result;
55 67 }
@@ -92,9 +104,9 @@
92 104 ];
93 105 $response = wp_remote_get($url, $args);
94 106 $httpcode = wp_remote_retrieve_response_code($response);
95 107 if ($httpcode < 200) {
96 - WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server'));
108 + WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server')." requestURL");
97 109 }
98 110 $response = wp_remote_retrieve_body($response);
99 111 return $response;
100 112 }
@@ -99,10 +111,11 @@
99 111 return $response;
100 112 }
101 113
102 114
103 - public static function getFileByUrl($url)
115 + public static function getFileByUrl($url, $fileName)
104 116 {
117 + $url = $url.'/'.$fileName;
105 118 $args = [
106 119 'timeout' => '30',
107 120 'sslverify' => false,
108 121 ];
@@ -108,21 +121,23 @@
108 121 ];
109 122 $response = wp_remote_get($url, $args);
110 123 $httpcode = wp_remote_retrieve_response_code($response);
111 124 if ($httpcode < 200) {
112 - WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server'));
125 + WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server')." getFileByUrl");
113 126 }
114 - $filename = null;
115 - $metas = explode(";",$response['headers']["content-disposition"]);
116 - foreach ($metas as $meta){
117 - if(stripos($meta,"filename") !== false){
118 - $filename = trim(str_replace(["filename=","=","\""],"",$meta));
119 - }
120 - }
127 +
121 128 $response = wp_remote_retrieve_body($response);
122 - return ["body" => $response, "filename" => $filename];
129 + return ["body" => $response, "filename" => $fileName];
123 130 }
124 131
132 +
133 + public static function getEmail(){
134 + $payload = '{"query":"query { auth { viewer { email __typename } __typename } }"}';
135 + $result = self::requestApi($payload, true);
136 +
137 + return $result['data']['auth']['viewer']['email'];
138 + }
139 +
125 140 public static function getOwnSite($attempt = false)
126 141 {
127 142 $payload = '{"query":"query getSites { auth { viewer { sites { ...sites __typename } __typename } __typename }}fragment sites on SiteQueries { list(filter: {}) { edges { node { id hostname title ssl { status __typename } availability { status __typename } reputation { status __typename } ports { status __typename } deface { status __typename } domain { status __typename } antivirus { status __typename } firewall { status __typename } maliciousScript { stack { name __typename } __typename } __typename } __typename } __typename } __typename}"}';
128 143
@@ -131,11 +146,9 @@
131 146 //mutator
132 147 foreach ($result['data']['auth']['viewer']['sites']['list']['edges'] as &$m) {
133 148 if (isset($m['node']['hostname'])) {
134 149 $m['node']['hostname'] = WTSEC_LIBRARY_Idn::idn_to_utf8($m['node']['hostname']);
135 -// if ($m['node']['id'] == "c2l0ZV8yNTg=") {
136 -// return $m['node'];
137 -// }
150 +
138 151 if (self::isSiteUrl($m['node']['hostname'])) {
139 152 return $m['node'];
140 153 }
141 154 }
@@ -164,13 +177,13 @@
164 177 }
165 178
166 179 public static function getAllChecks($host_id)
167 180 {
168 - $from = time() - (60 * 60 * 24);
181 + $from = time() - (60 * 60 * 24 * 7);
169 182 $to = time();
170 - $from_waf = time() - (60 * 60 * 24 * 7);
171 - $payload = '{"query":"query($id: ID!, $dateRange:DateRangeInput!) {\n auth {\n viewer {\n sites {\n one(id: $id) {\n ports{\n status\n ip\n tcp\n lastTest{\n time\n }\n }\n availability {\n status\n lastTest {\n time\n }\n responseTime\n downTime(dateRange: $dateRange)\n percent(dateRange: $dateRange)\n }\n deface {\n status\n lastTest {\n time\n }\n words\n count\n }\n domain {\n status\n registrar\n owner\n email\n createdDate\n expiredDate\n }\n ports {\n status\n lastTest {\n time\n }\n ip\n tcp\n country\n }\n ssl {\n status\n daysLeft\n expiryDate\n issueDate\n }\n reputation {\n status\n lastTest {\n time\n }\n virusList {\n viruses\n antiVirus\n }\n }\n firewall {\n lastTest { \n time\n } \n status\n chart(dateRange: $dateRange) {\n time\n attacks\n blocked\n }\n report(dateRange: $dateRange) {\n time\n attacks\n ip\n }\n }\n maliciousScript{\n lastTest{\n time\n }\n status\n }\n antivirus{\n status \n stats { \n changed\n deleted\n scaned\n infected\n error\n } \n lastTest { \n time\n } \n isFirstCheck\n }\n }\n }\n }\n }\n}","variables":{"id":"' . $host_id . '","dateRange":{"to":' . $to . ',"from":' . $from_waf . '}}}';
172 -// $payload = '{"query":"query($id: ID!, $dateRange:DateRangeInput!) {\n auth {\n viewer {\n sites {\n one(id: $id) {\n ports{\n status\n ip\n tcp\n lastTest{\n time\n }\n }\n availability {\n status\n lastTest {\n time\n }\n responseTime\n downTime(dateRange: $dateRange)\n percent(dateRange: $dateRange)\n }\n deface {\n status\n lastTest {\n time\n }\n words\n count\n }\n domain {\n status\n registrar\n owner\n email\n createdDate\n expiredDate\n }\n ports {\n status\n lastTest {\n time\n }\n ip\n tcp\n country\n }\n ssl {\n status\n daysLeft\n expiryDate\n issueDate\n }\n reputation {\n status\n lastTest {\n time\n }\n virusList {\n viruses\n antiVirus\n }\n }\n firewall {\n lastTest { \n time\n } \n status\n logs{\n edges\n{\n node{\n status\n country\n type\n}\n}\n}\n chart(dateRange: $dateRange) {\n time\n attacks\n blocked\n }\n report(dateRange: $dateRange) {\n time\n attacks\n ip\n }\n }\n maliciousScript{\n lastTest{\n time\n }\n status\n }\n antivirus{\n status \n stats { \n changed\n deleted\n scaned\n infected\n error\n } \n lastTest { \n time\n } \n isFirstCheck\n }\n }\n }\n }\n }\n}","variables":{"id":"' . $host_id . '","dateRange":{"to":' . $to . ',"from":' . $from_waf . '}}}';
183 + $from_waf = time() - (60 * 60 * 24 * 30);
184 + $language = WTSEC_LANGUAGE;
185 + $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.'"}}';
173 186 $response = self::requestApi($payload, true);
174 187 if (isset($response['data']['auth']['viewer']['sites']['one'])) {
175 188 return $response['data']['auth']['viewer']['sites']['one'];
176 189 }
@@ -176,8 +189,40 @@
176 189 }
177 190 return [];
178 191 }
179 192
193 + public static function getFirewall($host_id, $limit = 20, $cursor = null, $days = 365)
194 + {
195 + $from = (is_array($days)) ? $days['from'] : time() - (60 * 60 * 24 * $days);
196 + $to = (is_array($days)) ? $days['to'] : time();
197 + $cursor = ($cursor == null) ? 'null' : '"'.$cursor.'"';
198 +
199 + $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 }"}';
200 + $res = self::requestApi($payload, true);
201 +
202 + return $res;
203 + }
204 +
205 +
206 + public static function getAntivirus($host_id, $limit = 10, $cursor = null, $days = 365, $event = 'new')
207 + {
208 + $from = (is_array($days)) ? $days['from'] : time() - (60 * 60 * 24 * $days);
209 + $to = (is_array($days)) ? $days['to'] : time();
210 + $cursor = ($cursor == null) ? 'null' : '"' . $cursor . '"';
211 + $payload = '{"operationName":null,"variables":{"id":"' . $host_id . '","avLogFilter":{"event":"'.$event.'","dateRange":{"to":'.$to.',"from":'.$from.'},"order":{"direction":"DESC","field":"time"},"pagination":{"first":' . $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 } } } } } } }"}';
212 + return self::requestApi($payload, true);
213 + }
214 +
215 + public static function getFirewallChart($host_id, $days = 7)
216 + {
217 + $to = time();
218 + $from_waf = ($days <= 1) ? strtotime(date('Y-m-d 00:00:01')) : time() - (60 * 60 * 24 * $days);
219 +
220 + $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" } } } }';
221 + $response = self::requestApi($payload, true);
222 + return $response['data']['auth']['viewer']['sites']['one']['firewall']['chart'];
223 + }
224 +
180 225 public static function changeStatus($config_id, $host_id)
181 226 {
182 227 $payload = '{"query":"\n mutation {\n toggleServiceConfig(\n id: ' . $config_id . '\n userhostId: ' . $host_id . '\n ) {\n isActive\n }\n }\n "}';
183 228 return self::requestApi($payload, true);
@@ -196,12 +241,18 @@
196 241 }
197 242
198 243 public static function generateAmFile($id)
199 244 {
200 - $payload = '{"operationName":null,"variables":{},"query":"mutation {\n auth {\n am {\n install(siteId: \"'.$id.'\")\n }\n }\n}\n"}';
245 + $payload = '{ "operationName":null, "variables":{}, "query":"mutation { auth { am { install(siteId: \"'.$id.'\"){ downloadLink, amFilename, wafFilename, avFilename } } } }"}';
201 246 return self::requestApi($payload, true);
202 247 }
203 248
249 + public static function deleteAm($id)
250 + {
251 + $payload = '{ "query":"mutation { auth { am { delete(siteId: \"'.$id.'\") } } }"}';
252 + return self::requestApi($payload, true);
253 + }
254 +
204 255 public static function checkStatus($id, $service)
205 256 {
206 257 $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"}';
207 258 return self::requestApi($payload, true);
@@ -206,37 +257,76 @@
206 257 $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"}';
207 258 return self::requestApi($payload, true);
208 259 }
209 260
210 - public static function getOptions($host_id)
261 +
262 + public static function getQuarantineList($host_id)
211 263 {
212 - $payload = '{"query":"query{\nuserHost(id:' . $host_id . '){\n id\n title\n hostname\n stack\n createdAt\n services {\n id\n name\n configs {\n id\n \tdata\n isActive\n }\n }\n }\n}"}';
264 + $payload = '{"query":"query{ auth{ viewer{ sites{ one(id:\"'.$host_id.'\"){ antivirus{ quarantine{ id path date } } } } } } } "}';
213 265 return self::requestApi($payload, true);
214 266 }
215 267
216 - public static function getAntivirus($host_id)
268 + public static function moveToQuarantine($host_id, $path)
217 269 {
218 - $payload = '{"operationName":null,"variables":{"id":"' . $host_id . '","avLogFilter":{"event":"infected","order":{"direction":"DESC","field":"time"},"pagination":{"first":20,"cursor":null}}},"query":"query ($id: ID!, $avLogFilter: AvLogFilter!) {\n auth {\n viewer {\n sites {\n one(id: $id) {\n id\n ... on Site {\n configs {\n ... on AvConfig {\n isActive\n id\n }\n }\n }\n antivirus {\n status\n log(avLogFilter: $avLogFilter) {\n edges {\n node {\n filePath\n matches\n event\n signatures\n time\n }\n }\n }\n lastTest {\n time\n }\n stats {\n changed\n deleted\n scaned\n infected\n }\n }\n }\n }\n }\n }\n}\n"}';
270 + $payload = '{"query":"mutation{ auth{ sites{ av{ moveToQuarantine(input:{ siteId:\"'.$host_id.'\", path:\"'.$path.'\" }) } } } } "}';
219 271 return self::requestApi($payload, true);
220 272 }
221 273
274 + public static function moveFromQuarantine($id)
275 + {
276 + $payload = '{"query":"mutation{ auth{ sites{ av{ moveFromQuarantine(id: \"'.$id.'\") } } } } "}';
277 + return self::requestApi($payload, true);
278 + }
222 279
223 - public static function getFirewall($host_id)
280 + public static function reportsList($host_id, $limit = 10, $cursor = null)
224 281 {
225 - $to = time();
226 - $from_waf = time() - (60 * 60 * 24 * 7);
227 - $payload = '{"operationName":"FirewallAttackLog","variables":{"dateRange":{"to":'.$to.',"from":'.$from_waf.'},"id":"'.$host_id.'","wafLogFilter":{"dateRange":{"to":'.$to.',"from":'.$from_waf.'},"order":{"direction":"DESC","field":"time"},"pagination":{"first":20,"cursor":null}}},"query":"query FirewallAttackLog($id: ID!, $wafLogFilter: WafLogFilter! ,$dateRange: DateRangeInput!) {\n auth {\n viewer {\n sites {\n one(id: $id) {\n firewall {\n lastTest{\n time\n }\n status\n ...FirewallLogFragment\n map(dateRange: $dateRange) { attacks, country } __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n}\n\nfragment FirewallLogFragment on Waf {\n logs(wafLogFilter: $wafLogFilter) {\n edges {\n cursor\n node {\n type\n blocked\n payload\n ip\n location {\n country {\n nameEn\n __typename\n }\n __typename\n }\n time\n request\n status\n country\n category\n __typename\n }\n __typename\n }\n pageInfo {\n endCursor\n hasNextPage\n __typename\n }\n __typename\n }\n __typename\n}\n"}';
282 + $cursor = ($cursor == null) ? 'null' : '"' . $cursor . '"';
283 + $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 } } } } } }"}';
228 284 return self::requestApi($payload, true);
229 285 }
230 286
287 + public static function reportGenerate($host_id, $period, $services, $language = "en")
288 + {
289 + $from = (is_array($period)) ? $period['from'] : time() - (60 * 60 * 24 * $period);
290 + $to = (is_array($period)) ? $period['to'] : time();
291 + $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.'" } } }';
231 292
293 + return self::requestApi($payload, true);
294 + }
232 295
233 - public static function getFirewallChart($host_id)
296 + public static function reportDownload($id)
234 297 {
298 + $payload = '{"query": "query { auth { viewer { reports { download(id: \"' . $id . '\") } } } }"}';
299 + return self::requestApi($payload, true);
300 + }
301 +
302 + public static function getConfigs($host_id)
303 + {
304 + $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 } } } } } } } "}';
305 + return self::requestApi($payload, true);
306 + }
307 +
308 + public static function toggleConfigs($service_id)
309 + {
310 + $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 } } } } } "}';
311 + return self::requestApi($payload, true);
312 + }
313 +
314 + public static function wafSettings($host_id, $settings)
315 + {
316 + $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 } } } } }"}';
317 + return self::requestApi($payload, true);
318 + }
319 +
320 + public static function getServerStatusChart($host_id, $days = 7)
321 + {
235 322 $to = time();
236 - $from_waf = time() - (60 * 60 * 24 * 7);
237 - $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": { "first": 20, "cursor": null }, "order": { "direction": "DESC", "field": "time" } } } }';
238 - return self::requestApi($payload, true);
323 + $from = ($days <= 1) ? strtotime(date('Y-m-d 00:00:01')) : time() - (60 * 60 * 24 * $days);
324 +
325 + $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 . '} } }';
326 +
327 + $response = self::requestApi($payload, true);
328 + return $response['data']['auth']['viewer']['sites']['one']['serverStatus'];
239 329 }
240 330
241 331 public static function getStatusIcon($status)
242 332 {
@@ -250,8 +340,13 @@
250 340 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.pending'),
251 341 "color" => self::getColor("grey"),
252 342 "image" => "loading.svg"
253 343 ],
344 + "pause" => [
345 + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.pause'),
346 + "color" => self::getColor("grey"),
347 + "image" => "warning.svg"
348 + ],
254 349 "expired" => [
255 350 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.expired'),
256 351 "color" => self::getColor("orange"),
257 352 "image" => "warning.svg"
@@ -333,11 +428,13 @@
333 428 "image" => "check-mark.svg"
334 429 ],
335 430 ];
336 431 if (isset($statuses[$status])) {
337 - return ["image" => $statuses[$status]["image"], "icon" => $statuses[$status]["color"]["icon"], "color" => $statuses[$status]["color"]["color"], "text" => "<span class='" . $statuses[$status]["color"]["color"] . "'>" . $statuses[$status]["text"] . "</span>"];
432 + $statuses[$status]['type'] = $status;
433 + $statuses[$status]["text"] = "<span data-status='$status' class='" . $statuses[$status]["color"]["color"] . "'>" . $statuses[$status]["text"] . "</span>";
434 + return $statuses[$status];
338 435 } else {
339 - return ["image" => "warning.svg", "icon" => "ww-icon--status_unknow", "color" => "ww--status_unknow", "text" => "<span class='ww--status_unknow'>Unknown status</span>"];
436 + return ["image" => "warning.svg", "color" => "ww--status_unknow", "text" => "<span class='ww--status_unknow'>Unknown status</span>"];
340 437 }
341 438 }
342 439
343 440 public static function getColor($type)
@@ -380,5 +477,6 @@
380 477 public static function getScore(){
381 478 return self::requestURL("https://api.wtotem.com/site/score?url=".WTSEC_SITE_URL);
382 479 }
383 480
384 -}
481 +}
482 +