diff options
| author | root | 2014-12-07 00:33:54 +0100 |
|---|---|---|
| committer | root | 2014-12-07 00:33:54 +0100 |
| commit | 6ec371bff3d3eda0c535fe773c292f66bd746a7a (patch) | |
| tree | bbca16b736bae30363b34eebdcdfcb94ebda0148 | |
| parent | 60070877e8e0d862bf342b5c83fd011819ebcdea (diff) | |
| download | tools.iamfabulous.de-6ec371bff3d3eda0c535fe773c292f66bd746a7a.tar.gz | |
Bug fixed and added warning for HTTP status codes.
| -rw-r--r-- | down/ajax.php | 20 | ||||
| -rw-r--r-- | down/http.php | 14 | ||||
| -rw-r--r-- | 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 @@ <?php function isUp($url, $ipv6 = false){ - $agent = "Just checking if you are up or not."; $ch=curl_init(); @@ -16,7 +15,6 @@ function isUp($url, $ipv6 = false){ curl_setopt ($ch,CURLOPT_VERBOSE,false); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch,CURLOPT_SSLVERSION,3); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE); $page=curl_exec($ch); @@ -24,16 +22,18 @@ function isUp($url, $ipv6 = false){ curl_close($ch); if($httpcode>=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]+(?<query>/.*)|", $url, $match) ) - $url = str_replace($match["query"], "", $url); + if ( preg_match("|^(?<host>[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 @@ <label class="col-md-4 control-label" for="action">Check Type:</label> <div class="col-md-4 text-left"> <label class="radio-inline" for="action-0"> - <input name="action" id="action-0" value="ping" checked="checked" type="radio"> - Ping + <input name="action" id="action-0" value="http" checked="checked" type="radio"> + HTTP </label> <label class="radio-inline" for="action-1"> - <input name="action" id="action-1" value="http" type="radio"> - HTTP + <input name="action" id="action-1" value="ping" type="radio"> + Ping </label> </div> </div> @@ -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 @@ }) }; </script> - <script defer src="../tools/static/sweet-alert.js"></script> + <script defer async src="../tools/static/sweet-alert.js"></script> |
