From bf3847219714d71e59bfa04569089ab52f852960 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Dec 2014 17:10:49 +0100 Subject: Finished tool for checking downtime --- down/ajax.php | 60 ++++++++++++++++++++++ down/http.php | 31 ++++++++++++ down/index.php | 18 +++++++ down/ping.php | 26 ++++++++++ down/view/templ-index.php | 117 +++++++++++++++++++++++++++++++++++++++++++ down/view/templ-noscript.php | 87 ++++++++++++++++++++++++++++++++ 6 files changed, 339 insertions(+) create mode 100644 down/ajax.php create mode 100644 down/http.php create mode 100644 down/index.php create mode 100644 down/ping.php create mode 100644 down/view/templ-index.php create mode 100644 down/view/templ-noscript.php (limited to 'down') diff --git a/down/ajax.php b/down/ajax.php new file mode 100644 index 0000000..63a63d1 --- /dev/null +++ b/down/ajax.php @@ -0,0 +1,60 @@ + $_REQUEST["url"]); + +switch($_REQUEST["action"]){ + case("ping"): + require 'ping.php'; + if ( ping( sanitizeHost($_REQUEST["url"]), ipv6($_REQUEST["url"]) ) ){ + $r["status"] = "Looks like it's up from here."; + $r["data"] = 1; + } else { + $r["status"] = "Seems down. :("; + $r["data"] = 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"; + } else { + if( isUp($_REQUEST["url"]) ){ + $r["status"] = "Looks like it's up from here."; + $r["data"] = 1; + } else { + $r["status"] = "Seems down. :("; + $r["data"] = 0; + } + } + break; + default: + header($_SERVER["SERVER_PROTOCOL"] . " 400 Bad Request"); + header("X-Debug: Please define a valid action."); + $r["status"] = "not valid"; + $r["data"] = 0; + break; +} + +echo json_encode($r); diff --git a/down/http.php b/down/http.php new file mode 100644 index 0000000..9973cb4 --- /dev/null +++ b/down/http.php @@ -0,0 +1,31 @@ +=200 && $httpcode<400 ) + return true; + else + return false; +} + +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); + + return $url; +} diff --git a/down/index.php b/down/index.php new file mode 100644 index 0000000..e71e76a --- /dev/null +++ b/down/index.php @@ -0,0 +1,18 @@ + /dev/null 2>&1", $ret); + + if ( $ret != 0 ) + return false; + + return true; +} + +function sanitizeHost($host){ + + if ( preg_match("|^[a-zA-Z]+://|", $host, $match) ) + $host = str_replace($match[0], "", $host); + if ( preg_match("|(?/.*)|", $host, $match) ) + $host = str_replace($match["query"], "", $host); + + return escapeshellarg($host); +} diff --git a/down/view/templ-index.php b/down/view/templ-index.php new file mode 100644 index 0000000..cc554e1 --- /dev/null +++ b/down/view/templ-index.php @@ -0,0 +1,117 @@ + + + + + + + + + + Is it down? | iamfabulous.de + + + + + +
+
+
+ +
+
+ + + +

Uptime is the game

+

Is your favourite website down?

+
+ + +
+ +
+ + autofocus> + + + +
+
+ + +
+ +
+ + +
+
+ + +
+ +
+ +
+
+ +
+
+ +
+
+
+ + + + diff --git a/down/view/templ-noscript.php b/down/view/templ-noscript.php new file mode 100644 index 0000000..d15b665 --- /dev/null +++ b/down/view/templ-noscript.php @@ -0,0 +1,87 @@ + + + + + + + + + Is it down? | iamfabulous.de + + + + + +
+
+
+ + +

Uptime is the game

+

Is your favourite website down?

+
+ + + +
+
+ + -- cgit v1.2.3