From 6ec371bff3d3eda0c535fe773c292f66bd746a7a Mon Sep 17 00:00:00 2001 From: root Date: Sun, 7 Dec 2014 00:33:54 +0100 Subject: Bug fixed and added warning for HTTP status codes. --- down/ajax.php | 20 +++++++++++++------- down/http.php | 14 +++++++------- down/view/templ-index.php | 15 +++++++++------ 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/down/ajax.php b/down/ajax.php index f5a4ce6..7ebc334 100644 --- a/down/ajax.php +++ b/down/ajax.php @@ -29,23 +29,29 @@ switch($_REQUEST["action"]){ require 'ping.php'; if ( ping( sanitizeHost($_REQUEST["url"]), ipv6($_REQUEST["url"]) ) ){ $r["status"] = "Looks like it's up from here."; - $r["data"] = 1; + $r["resp_code"] = 2; } else { $r["status"] = "Seems down. :("; - $r["data"] = 0; + $r["resp_code"] = 0; } break; case("http"): require 'http.php'; if ( !ipv6($_REQUEST["url"]) && filter_var(sanitizeUrl($_REQUEST["url"]), FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === false ){ - echo "not valid"; + $r["status"] = "Host not valid"; + $r["resp_code"] = 0; } else { - if( isUp($_REQUEST["url"], ipv6($_REQUEST["url"]) ) ){ + $status = isUp($_REQUEST["url"], ipv6($_REQUEST["url"])); + if ( $status == 2 ) { $r["status"] = "Looks like it's up from here."; - $r["data"] = 1; - } else { + $r["resp_code"] = 2; + } else if ($status >= 400) { + $r["status"] = "Site responded with a ".$status." code."; + $r["resp_code"] = 1; + } + else { $r["status"] = "Seems down. :("; - $r["data"] = 0; + $r["resp_code"] = 0; } } break; diff --git a/down/http.php b/down/http.php index 5e0351d..cf2a302 100644 --- a/down/http.php +++ b/down/http.php @@ -1,6 +1,5 @@ =200 && $httpcode<400 ) - return true; - else - return false; + return 2; + else if ( $httpcode >= 400) + return $httpcode; + else + return 0; } function sanitizeUrl($url){ if ( ! preg_match("|^[a-zA-Z]+://|", $url) ) $url = "http://" . $url; - if ( preg_match("|^[a-zA-Z]+://.+\.[a-zA-Z]+(?/.*)|", $url, $match) ) - $url = str_replace($match["query"], "", $url); + if ( preg_match("|^(?[a-zA-Z]+://(.+\.[a-zA-Z]+){1,})/.*|", $url, $match) ) + $url = $match["host"]; return $url; } diff --git a/down/view/templ-index.php b/down/view/templ-index.php index bfa68ab..4186ed5 100644 --- a/down/view/templ-index.php +++ b/down/view/templ-index.php @@ -56,12 +56,12 @@
@@ -95,9 +95,12 @@ success: function( response ){ - if ( response.data == 1 ) { + if ( response.resp_code == 2 ) { var type = "success"; var button= "btn-success"; + } else if ( response.resp_code == 1){ + var type= "warning"; + var button= "btn-warning"; } else { var type= "error"; var button= "btn-danger"; @@ -126,4 +129,4 @@ }) }; - + -- cgit v1.2.3