| @@ -1,14 +1,14 @@ | ||
| 1 | -<?php defined('ABSPATH') or die("Protected By Webtotem Wordpress Security!"); | |
| 1 | +<?php defined('ABSPATH') or die("Protected By WT!"); | |
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | class WTSEC_LIBRARY_WT |
| 5 | 5 | { |
| 6 | - const URL = "https://api.wtotem.com/v1/graphql"; | |
| 6 | + const URL = "https://api.wtotem.com/graphql"; | |
| 7 | 7 | |
| 8 | 8 | public static function auth($key) |
| 9 | 9 | { |
| 10 | - $payload = '{"query":"mutation{\n apiServiceMutation{\n auth(apiKey:\"' . $key . '\"){\n value\n refreshToken\n expiresIn\n }\n }\n}\n\n"}'; | |
| 10 | + $payload = '{"query":"mutation{\n guest{\n apiKeys{\n auth(apiKey:\"' . $key . '\"),{\n token{\n value,refreshToken,expiresIn\n }\n }\n }\n }\n}"}'; | |
| 11 | 11 | return self::requestApi($payload); |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | protected static function requestApi($payload, $token = false, $repeat = false) |
| @@ -19,9 +19,9 @@ | ||
| 19 | 19 | $args = [ |
| 20 | 20 | 'body' => $payload, |
| 21 | 21 | 'timeout' => '15', |
| 22 | 22 | 'sslverify' => false, |
| 23 | - 'headers' => ['Content-Type:application/json'], | |
| 23 | + 'headers' => ['Content-Type:application/json', 'Content-Type' => 'application/json', 'source:WORDPRESS', 'Accept: application/json'], | |
| 24 | 24 | ]; |
| 25 | 25 | if (!is_null($token) && $token) { |
| 26 | 26 | $authorization = "Bearer " . $token; |
| 27 | 27 | $args['headers'] = array_merge($args['headers'], ["Authorization" => $authorization]); |
| @@ -38,10 +38,10 @@ | ||
| 38 | 38 | if (isset($result['errors'][0]['message'])) { |
| 39 | 39 | $message = self::diffMesageForHuman($result['errors'][0]['message']); |
| 40 | 40 | if (stripos($result['errors'][0]['message'], "token") !== false && !$repeat) { |
| 41 | 41 | $result = WTSEC_LIBRARY_WT::auth(wtsec_app()->get("api_key")); |
| 42 | - if (isset($result['data']['apiServiceMutation']['auth']['value'])) { | |
| 43 | - $token_ = $result['data']['apiServiceMutation']['auth']['value']; | |
| 42 | + if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) { | |
| 43 | + $token_ = $result['data']['guest']['apiKeys']['auth']['token']['value']; | |
| 44 | 44 | WTSEC_LIBRARY_App::login($token_); |
| 45 | 45 | return self::requestApi($payload, $token, true); |
| 46 | 46 | } else { |
| 47 | 47 | WTSEC_LIBRARY_App::logout(); |
| @@ -95,9 +95,9 @@ | ||
| 95 | 95 | $args = [ |
| 96 | 96 | 'timeout' => '15', |
| 97 | 97 | 'sslverify' => false, |
| 98 | 98 | ]; |
| 99 | - $response = wp_remote_post($url, $args); | |
| 99 | + $response = wp_remote_get($url, $args); | |
| 100 | 100 | $httpcode = wp_remote_retrieve_response_code($response); |
| 101 | 101 | if ($httpcode < 200) { |
| 102 | 102 | WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server')); |
| 103 | 103 | } |
| @@ -104,28 +104,33 @@ | ||
| 104 | 104 | $response = wp_remote_retrieve_body($response); |
| 105 | 105 | return $response; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - public static function getOwnSite() | |
| 108 | + public static function getOwnSite($attempt = false) | |
| 109 | 109 | { |
| 110 | - $payload = '{"query":"{\n userHostsList{\n id\n hostname\n }\n}"}'; | |
| 110 | + $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}"}'; | |
| 111 | + | |
| 111 | 112 | $result = self::requestApi($payload, true); |
| 112 | - if (isset($result['data']['userHostsList'])) { | |
| 113 | + if (isset($result['data']['auth']['viewer']['sites']['list']['edges'])) { | |
| 113 | 114 | //mutator |
| 114 | - foreach ($result['data']['userHostsList'] as &$m) { | |
| 115 | - if (isset($m['hostname'])) { | |
| 116 | - $m['hostname'] = WTSEC_LIBRARY_Idn::idn_to_utf8($m['hostname']); | |
| 117 | - if (self::isSiteUrl($m['hostname'])) { | |
| 118 | - return $result['data']['userHostsList'] = $m; | |
| 119 | - break; | |
| 115 | + foreach ($result['data']['auth']['viewer']['sites']['list']['edges'] as &$m) { | |
| 116 | + if (isset($m['node']['hostname'])) { | |
| 117 | + $m['node']['hostname'] = WTSEC_LIBRARY_Idn::idn_to_utf8($m['node']['hostname']); | |
| 118 | +// if ($m['node']['id'] == "c2l0ZV8yNTg=") { | |
| 119 | +// return $m['node']; | |
| 120 | +// } | |
| 121 | + if (self::isSiteUrl($m['node']['hostname'])) { | |
| 122 | + return $m['node']; | |
| 120 | 123 | } |
| 121 | 124 | } |
| 122 | 125 | } |
| 123 | 126 | $add_site = self::addSite(WTSEC_SITE_URL); |
| 124 | 127 | if (isset($add_site['errors'])) { |
| 125 | - return $result['data']['userHostsList'] = []; | |
| 128 | + return $result['data']['node'] = []; | |
| 126 | 129 | } else { |
| 127 | - return self::getOwnSite(); | |
| 130 | + if (!$attempt) { | |
| 131 | + return self::getOwnSite(true); | |
| 132 | + } | |
| 128 | 133 | } |
| 129 | 134 | } |
| 130 | 135 | return []; |
| 131 | 136 | } |
| @@ -136,9 +141,9 @@ | ||
| 136 | 141 | } |
| 137 | 142 | |
| 138 | 143 | public static function addSite($url) |
| 139 | 144 | { |
| 140 | - $payload = '{"query":"\n mutation($input: AddUserHostInput!) {\n addUserHost(input: $input) {\n id\n title\n hostname\n tags\n stack\n services {\n id\n name\n configs {\n id\n data\n isActive\n createdAt\n }\n }\n isActive\n createdAt\n }\n }\n ","variables":{"input":{"hostname":"' . $url . '","services":[{"id":1,"configs":[{"scheme":"http","port":80,"check_interval":1,"responsetime_threshold":30,"path":"/","http_errors":[400,401,402,403,404,500,501,502,503],"alert_after":0}]},{"id":2,"configs":[{"check_interval":5,"notify_expiry_day":true,"notify_expiry_month":true,"notify_expiry_week":true,"port":443}]},{"id":4,"configs":[{"check_interval":5,"path":"/","scheme":"http","port":80}]},{"id":5,"configs":[{"check_interval":5,"path":"/","scheme":"http","port":80}]},{"id":6,"configs":[{"check_interval":5,"path":"/","scheme":"http","port":80}]},{"id":7,"configs":[{"check_interval":5,"ports_udp":[18,19,53,27,29,31,71,74],"ports_tcp":[21,22,25,3306,5432,80,443,88,8000,8080]}]},{"id":9,"configs":[{"scheme":"http","port":80,"path":"/"}]},{"id":8,"configs":[{"check_interval":30,"scheme":"http","port":80,"path":"/"}]},{"id":3,"configs":[{"check_interval":60,"notify_expiry_day":true,"notify_expiry_month":true,"notify_expiry_week":true}]},{"id":10,"configs":[{"check_interval":30,"path":"/","scheme":"http","port":80}]}],"title":"' . $url . '"}}}'; | |
| 145 | + $payload = '{"variables":{"input":{"title":"' . $url . '","hostname":"' . $url . '","configs":{"scheme":"http","port":80,"wa":{},"dec":{},"ps":{}}}},"query":"mutation ($input: CreateSiteInput) {\n auth {\n sites {\n create(input: $input) {\n id\n hostname\n title\n __typename\n }\n __typename\n }\n __typename\n }\n}\n"}'; | |
| 141 | 146 | return self::requestApi($payload, true); |
| 142 | 147 | } |
| 143 | 148 | |
| 144 | 149 | public static function getAllChecks($host_id) |
| @@ -145,10 +150,14 @@ | ||
| 145 | 150 | { |
| 146 | 151 | $from = time() - (60 * 60 * 24); |
| 147 | 152 | $to = time(); |
| 148 | 153 | $from_waf = time() - (60 * 60 * 24 * 7); |
| 149 | - $payload = '{"query":"query getAllChecks( $hostId:Int!, $dateRange: DateRangeInput!, $dateRangeWaf:DateRangeInput! ){\n waServiceChecks(userHostId:$hostId){\n config{\n id\n isActive\n }\n isDown\n status\n average(dateRange: $dateRange)\n responseTime(dateRange: $dateRange)\n testsResults(dateRange: $dateRange)\n }\n sslServiceChecks(userHostId:$hostId){\n config{\n id\n isActive\n }\n status\n issued\n expires\n daysLeft\n tls\n }\n decServiceChecks(userHostId:$hostId){\n config{\n id\n isActive\n }\n email\n daysLeft\n created\n expires\n registrar\n owner\n status\n }\n avServiceChecks(userHostId:$hostId){\n config{\n id\n isActive\n }\n lastTestId\n lastTestTime\n status\n count\n list\n }\n cmsServiceChecks(userHostId:$hostId){\n config{\n id\n isActive\n }\n lastTestId\n lastTestTime\n status\n count\n list\n }\n dcServiceChecks(userHostId:$hostId){\n config{\n id\n isActive\n }\n lastTestTime\n status\n count\n list\n }\n psServiceChecks(userHostId:$hostId){\n config{\n id\n isActive\n }\n ip\n lastTestId\n lastTestTime\n status\n count\n openTCPs\n openUDPs\n }\n wafServiceChecks(userHostId:$hostId){\n config{\n id\n isActive\n }\n lastTestTime\n status\n count\n countIP \n chart(dateRangeWaf:$dateRangeWaf){\n date\n count\n }\n }\n vcServiceChecks(userHostId:$hostId){\n config{\n id\n isActive\n }\n status\n list\n fileChangesCount\n errorsCount\n signaturesCount\n }\n \n}\n\n\n\n","variables":{"hostId":' . $host_id . ',"dateRange":{"from":' . $from . ',"to":' . $to . '},"dateRangeWaf":{"to":' . $to . ',"from":' . $from_waf . '}}}'; | |
| 150 | - return self::requestApi($payload, true); | |
| 154 | + $payload = '{"query":"query($id: ID!, $dateRange:DateRangeInput!) {\n auth {\n viewer {\n sites {\n one(id: $id) {\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 . '}}}'; | |
| 155 | + $response = self::requestApi($payload, true); | |
| 156 | + if (isset($response['data']['auth']['viewer']['sites']['one'])) { | |
| 157 | + return $response['data']['auth']['viewer']['sites']['one']; | |
| 158 | + } | |
| 159 | + return []; | |
| 151 | 160 | } |
| 152 | 161 | |
| 153 | 162 | public static function changeStatus($config_id, $host_id) |
| 154 | 163 | { |
| @@ -157,21 +166,21 @@ | ||
| 157 | 166 | } |
| 158 | 167 | |
| 159 | 168 | public static function serviceConnect($id, $service) |
| 160 | 169 | { |
| 161 | - $payload = '{"query":"{ checkAgent(userHostId: ' . $id . ', service: ' . strtoupper($service) . ') }"}'; | |
| 170 | + $payload = '{"query":"mutation {\n auth {\n agents{\n check(siteId:\"' . $id . '\",service:' . strtolower($service) . ',plugin:WORDPRESS)\n }\n }\n}\n"}'; | |
| 162 | 171 | return self::requestApi($payload, true); |
| 163 | 172 | } |
| 164 | 173 | |
| 165 | 174 | public static function generateFile($id, $service) |
| 166 | 175 | { |
| 167 | - $payload = '{"query":"{ generateAgent(userHostId: ' . $id . ', service: ' . strtoupper($service) . ') }"}'; | |
| 176 | + $payload = '{"query":"mutation {\n auth {\n agents{\n generate(siteId:\"' . $id . '\",service:' . strtolower($service) . '){\n agentName\n }\n }\n }\n}\n"}'; | |
| 168 | 177 | return self::requestApi($payload, true); |
| 169 | 178 | } |
| 170 | 179 | |
| 171 | 180 | public static function checkStatus($id, $service) |
| 172 | 181 | { |
| 173 | - $payload = '{"query":"{\n ' . strtolower($service) . 'ServiceChecks(userHostId:' . $id . '){\n status\n config{\n isActive\n id\n }\n }\n}"}'; | |
| 182 | + $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"}'; | |
| 174 | 183 | return self::requestApi($payload, true); |
| 175 | 184 | } |
| 176 | 185 | |
| 177 | 186 | public static function getOptions($host_id) |
| @@ -181,254 +190,97 @@ | ||
| 181 | 190 | } |
| 182 | 191 | |
| 183 | 192 | public static function getAntivirus($host_id) |
| 184 | 193 | { |
| 185 | - $payload = '{"query":"query{\n vcServiceChecks(userHostId:' . $host_id . '){\n config{\n id,\n isActive\n }\n status\n list\n fileChangesCount\n errorsCount\n signaturesCount\n }\n}\n\n"}'; | |
| 194 | + $from = time() - (60 * 60 * 24); | |
| 195 | + $to = time(); | |
| 196 | + $from_waf = time() - (60 * 60 * 24 * 7); | |
| 197 | + $payload = '{"operationName":null,"variables":{"id":"' . $host_id . '","avLogFilter":{"event":"infected","order":{"direction":"DESC","field":"time"},"pagination":{"first":10,"cursor":null},"dateRange":{"to":' . $to . ',"from":' . $from_waf . '}}},"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"}'; | |
| 186 | 198 | return self::requestApi($payload, true); |
| 187 | 199 | } |
| 188 | 200 | |
| 189 | - public static function getStatusIcon($status, $service) | |
| 201 | + public static function getStatusIcon($status) | |
| 190 | 202 | { |
| 191 | - $color = [ | |
| 192 | - "icon" => "", | |
| 193 | - "color" => "", | |
| 203 | + $statuses = [ | |
| 204 | + "clean" => [ | |
| 205 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.ok'), | |
| 206 | + "color" => self::getColor("success") | |
| 207 | + ], | |
| 208 | + "pending" => [ | |
| 209 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.pending'), | |
| 210 | + "color" => self::getColor("grey") | |
| 211 | + ], | |
| 212 | + "expired" => [ | |
| 213 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.expired'), | |
| 214 | + "color" => self::getColor("orange") | |
| 215 | + | |
| 216 | + ], | |
| 217 | + "invalid" => [ | |
| 218 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.invalid'), | |
| 219 | + "color" => self::getColor("error") | |
| 220 | + ], | |
| 221 | + "no_cert" => [ | |
| 222 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.no_cert'), | |
| 223 | + "color" => self::getColor("orange") | |
| 224 | + ], | |
| 225 | + "error" => [ | |
| 226 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.error'), | |
| 227 | + "color" => self::getColor("error") | |
| 228 | + ], | |
| 229 | + "expires" => [ | |
| 230 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.expires'), | |
| 231 | + "color" => self::getColor("orange") | |
| 232 | + ], | |
| 233 | + "expires_today" => [ | |
| 234 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.expires_today'), | |
| 235 | + "color" => self::getColor("error") | |
| 236 | + ], | |
| 237 | + "down" => [ | |
| 238 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.down'), | |
| 239 | + "color" => self::getColor("error") | |
| 240 | + ], | |
| 241 | + "up" => [ | |
| 242 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.up'), | |
| 243 | + "color" => self::getColor("success") | |
| 244 | + ], | |
| 245 | + "infected" => [ | |
| 246 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.infected'), | |
| 247 | + "color" => self::getColor("error") | |
| 248 | + ], | |
| 249 | + "open_ports" => [ | |
| 250 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.open'), | |
| 251 | + "color" => self::getColor("orange") | |
| 252 | + ], | |
| 253 | + "deface" => [ | |
| 254 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.deface'), | |
| 255 | + "color" => self::getColor("error") | |
| 256 | + ], | |
| 257 | + "modified" => [ | |
| 258 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.modified'), | |
| 259 | + "color" => self::getColor("grey") | |
| 260 | + ], | |
| 261 | + "not_supported" => [ | |
| 262 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.unsupported'), | |
| 263 | + "color" => self::getColor("orange") | |
| 264 | + ], | |
| 265 | + "not_registered" => [ | |
| 266 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.not_registered'), | |
| 267 | + "color" => self::getColor("orange") | |
| 268 | + ], | |
| 269 | + "not_installed" => [ | |
| 270 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.not_installed'), | |
| 271 | + "color" => self::getColor("error") | |
| 272 | + ], | |
| 273 | + "working" => [ | |
| 274 | + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.working'), | |
| 275 | + "color" => self::getColor("success") | |
| 276 | + ], | |
| 194 | 277 | ]; |
| 195 | - $definition = ''; | |
| 196 | - switch ($service) { | |
| 197 | - case 'wa': | |
| 198 | - switch ((string)$status) { | |
| 199 | - case '-1': | |
| 200 | - $color = self::getColor("error"); | |
| 201 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.error'); | |
| 202 | - break; | |
| 203 | - case '-200': | |
| 204 | - $color = self::getColor("grey"); | |
| 205 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.pending'); | |
| 206 | - break; | |
| 207 | - case '0': | |
| 208 | - $color = self::getColor("success"); | |
| 209 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.ok'); | |
| 210 | - break; | |
| 211 | - case '1': | |
| 212 | - $color = self::getColor("error"); | |
| 213 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.unavailable'); | |
| 214 | - break; | |
| 215 | - } | |
| 216 | - break; | |
| 217 | - case 'ssl': | |
| 218 | - switch ((string)$status) { | |
| 219 | - case '-1': | |
| 220 | - $color = self::getColor("grey"); | |
| 221 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.error'); | |
| 222 | - break; | |
| 223 | - case '-200': | |
| 224 | - $color = self::getColor("grey"); | |
| 225 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.pending'); | |
| 226 | - break; | |
| 227 | - case '0': | |
| 228 | - $color = self::getColor("green"); | |
| 229 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.ok'); | |
| 230 | - break; | |
| 231 | - case '1': | |
| 232 | - $color = self::getColor("red"); | |
| 233 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.invalid'); | |
| 234 | - break; | |
| 235 | - case '2': | |
| 236 | - $color = self::getColor("red"); | |
| 237 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.expired'); | |
| 238 | - break; | |
| 239 | - case '3': | |
| 240 | - $color = self::getColor("orange"); | |
| 241 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.expires'); | |
| 242 | - break; | |
| 243 | - case '4': | |
| 244 | - $color = self::getColor("red"); | |
| 245 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.expires_today'); | |
| 246 | - break; | |
| 247 | - } | |
| 248 | - break; | |
| 249 | - case 'dec': | |
| 250 | - switch ((string)$status) { | |
| 251 | - case '-3': | |
| 252 | - $color = self::getColor("grey"); | |
| 253 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.not_registered'); | |
| 254 | - break; | |
| 255 | - case '-2': | |
| 256 | - $color = self::getColor("grey"); | |
| 257 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.unsupported'); | |
| 258 | - break; | |
| 259 | - case '-1': | |
| 260 | - $color = self::getColor("grey"); | |
| 261 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.error'); | |
| 262 | - break; | |
| 263 | - case '-200': | |
| 264 | - $color = self::getColor("grey"); | |
| 265 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.pending'); | |
| 266 | - break; | |
| 267 | - case '0': | |
| 268 | - $color = self::getColor("green"); | |
| 269 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.ok'); | |
| 270 | - break; | |
| 271 | - case '1': | |
| 272 | - $color = self::getColor("orange"); | |
| 273 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.expires'); | |
| 274 | - break; | |
| 275 | - case '2': | |
| 276 | - $color = self::getColor("orange"); | |
| 277 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.expired'); | |
| 278 | - break; | |
| 279 | - case '3': | |
| 280 | - $color = self::getColor("red"); | |
| 281 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.expires_today'); | |
| 282 | - break; | |
| 283 | - } | |
| 284 | - break; | |
| 285 | - case 'av': | |
| 286 | - switch ((string)$status) { | |
| 287 | - case '-1': | |
| 288 | - $color = self::getColor("grey"); | |
| 289 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.error'); | |
| 290 | - break; | |
| 291 | - case '-200': | |
| 292 | - $color = self::getColor("grey"); | |
| 293 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.pending'); | |
| 294 | - break; | |
| 295 | - case '0': | |
| 296 | - $color = self::getColor("green"); | |
| 297 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.ok'); | |
| 298 | - break; | |
| 299 | - case '1': | |
| 300 | - $color = self::getColor("red"); | |
| 301 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.blacklisted'); | |
| 302 | - break; | |
| 303 | - } | |
| 304 | - break; | |
| 305 | - case 'cms': | |
| 306 | - switch ((string)$status) { | |
| 307 | - case '-1': | |
| 308 | - $color = self::getColor("grey"); | |
| 309 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.error'); | |
| 310 | - break; | |
| 311 | - case '-200': | |
| 312 | - $color = self::getColor("grey"); | |
| 313 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.pending'); | |
| 314 | - break; | |
| 315 | - case '0': | |
| 316 | - $color = self::getColor("green"); | |
| 317 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.ok'); | |
| 318 | - break; | |
| 319 | - case '1': | |
| 320 | - $color = self::getColor("red"); | |
| 321 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.miner_detected'); | |
| 322 | - break; | |
| 323 | - } | |
| 324 | - break; | |
| 325 | - case 'dc': | |
| 326 | - switch ((string)$status) { | |
| 327 | - case '-1': | |
| 328 | - $color = self::getColor("grey"); | |
| 329 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.error'); | |
| 330 | - break; | |
| 331 | - case '-200': | |
| 332 | - $color = self::getColor("grey"); | |
| 333 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.pending'); | |
| 334 | - break; | |
| 335 | - case '0': | |
| 336 | - $color = self::getColor("green"); | |
| 337 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.ok'); | |
| 338 | - break; | |
| 339 | - case '1': | |
| 340 | - $color = self::getColor("red"); | |
| 341 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.deface'); | |
| 342 | - break; | |
| 343 | - case '2': | |
| 344 | - $color = self::getColor("orange"); | |
| 345 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.modified'); | |
| 346 | - break; | |
| 347 | - } | |
| 348 | - break; | |
| 349 | - case 'ps': | |
| 350 | - switch ((string)$status) { | |
| 351 | - case '-1': | |
| 352 | - $color = self::getColor("grey"); | |
| 353 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.error'); | |
| 354 | - break; | |
| 355 | - case '-200': | |
| 356 | - $color = self::getColor("grey"); | |
| 357 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.pending'); | |
| 358 | - break; | |
| 359 | - case '0': | |
| 360 | - $color = self::getColor("green"); | |
| 361 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.ok'); | |
| 362 | - break; | |
| 363 | - case '1': | |
| 364 | - $color = self::getColor("orange"); | |
| 365 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.open'); | |
| 366 | - break; | |
| 367 | - } | |
| 368 | - break; | |
| 369 | - case 'waf': | |
| 370 | - switch ((string)$status) { | |
| 371 | - case '-400': | |
| 372 | - $color = self::getColor("red"); | |
| 373 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.blocked'); | |
| 374 | - break; | |
| 375 | - case '-300': | |
| 376 | - $color = self::getColor("orange"); | |
| 377 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.not_installed'); | |
| 378 | - break; | |
| 379 | - case '-1': | |
| 380 | - $color = self::getColor("grey"); | |
| 381 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.error'); | |
| 382 | - break; | |
| 383 | - case '-200': | |
| 384 | - $color = self::getColor("grey"); | |
| 385 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.pending'); | |
| 386 | - break; | |
| 387 | - case '0': | |
| 388 | - $color = self::getColor("green"); | |
| 389 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.ok'); | |
| 390 | - break; | |
| 391 | - case '1': | |
| 392 | - $color = self::getColor("red"); | |
| 393 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.attacks_detected'); | |
| 394 | - break; | |
| 395 | - } | |
| 396 | - break; | |
| 397 | - case 'vc': | |
| 398 | - switch ((string)$status) { | |
| 399 | - case '-400': | |
| 400 | - $color = self::getColor("red"); | |
| 401 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.blocked'); | |
| 402 | - break; | |
| 403 | - case '-300': | |
| 404 | - $color = self::getColor("orange"); | |
| 405 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.not_installed'); | |
| 406 | - break; | |
| 407 | - case '-1': | |
| 408 | - $color = self::getColor("grey"); | |
| 409 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.error'); | |
| 410 | - break; | |
| 411 | - case '-200': | |
| 412 | - $color = self::getColor("grey"); | |
| 413 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.pending'); | |
| 414 | - break; | |
| 415 | - case '0': | |
| 416 | - $color = self::getColor("green"); | |
| 417 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.ok'); | |
| 418 | - break; | |
| 419 | - case '1': | |
| 420 | - $color = self::getColor("orange"); | |
| 421 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.file_changes'); | |
| 422 | - break; | |
| 423 | - case '2': | |
| 424 | - $color = self::getColor("red"); | |
| 425 | - $definition = WTSEC_LIBRARY_Localization::lmsg('statuses.signature_found'); | |
| 426 | - break; | |
| 427 | - } | |
| 428 | - break; | |
| 278 | + if (isset($statuses[$status])) { | |
| 279 | + return ["icon" => $statuses[$status]["color"]["icon"], "color" => $statuses[$status]["color"]["color"], "text" => "<span class='" . $statuses[$status]["color"]["color"] . "'>" . $statuses[$status]["text"] . "</span>"]; | |
| 280 | + } else { | |
| 281 | + return ["icon" => "ww-icon--status_unknow", "color" => "ww--status_unknow", "text" => "<span class='ww--status_unknow'>Unknown status</span>"]; | |
| 429 | 282 | } |
| 430 | - return ["icon" => $color["icon"], "color" => $color["color"], "text" => "<span class='" . $color["color"] . "'>" . $definition . "</span>"]; | |
| 431 | 283 | } |
| 432 | 284 | |
| 433 | 285 | public static function getColor($type) |
| 434 | 286 | { |
| @@ -437,8 +289,9 @@ | ||
| 437 | 289 | "red" => "is--status--error", |
| 438 | 290 | "success" => "is--status--ok", |
| 439 | 291 | "error" => "is--status--error", |
| 440 | 292 | "orange" => "is--status--warning", |
| 293 | + "warning" => "is--status--warning", | |
| 441 | 294 | "grey" => "ww--status_unknow" |
| 442 | 295 | ]; |
| 443 | 296 | $icon_types = [ |
| 444 | 297 | "green" => "ww-icon--status_ok", |
| @@ -445,10 +298,25 @@ | ||
| 445 | 298 | "red" => "ww-icon--status_error", |
| 446 | 299 | "success" => "ww-icon--status_ok", |
| 447 | 300 | "error" => "ww-icon--status_error", |
| 448 | 301 | "orange" => "ww-icon--status_warning", |
| 302 | + "warning" => "ww-icon--status_warning", | |
| 449 | 303 | "grey" => "ww-icon--status_unknow" |
| 450 | 304 | ]; |
| 451 | 305 | return ["icon" => $icon_types[$type], "color" => $types[$type]]; |
| 306 | + } | |
| 307 | + | |
| 308 | + public static function getConfigId($configs) | |
| 309 | + { | |
| 310 | + $id = 0; | |
| 311 | + $is_active = false; | |
| 312 | + foreach ($configs as &$config) { | |
| 313 | + if (!empty($config)) { | |
| 314 | + $id = $config['id']; | |
| 315 | + $is_active = $config['isActive']; | |
| 316 | + break; | |
| 317 | + } | |
| 318 | + } | |
| 319 | + return compact('id', 'is_active'); | |
| 452 | 320 | } |
| 453 | 321 | |
| 454 | 322 | } |