summaryrefslogtreecommitdiff
path: root/down/ajax.php
diff options
context:
space:
mode:
authorroot2014-12-04 17:10:49 +0100
committerroot2014-12-04 17:10:49 +0100
commitbf3847219714d71e59bfa04569089ab52f852960 (patch)
tree1eaa8255ea1a522c16f7267cf3639bb1681279c9 /down/ajax.php
parentbbe481a7fa159db107c7005f8b024bf4657c0bd6 (diff)
downloadtools.iamfabulous.de-bf3847219714d71e59bfa04569089ab52f852960.tar.gz
Finished tool for checking downtime
Diffstat (limited to 'down/ajax.php')
-rw-r--r--down/ajax.php60
1 files changed, 60 insertions, 0 deletions
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 @@
+<?php
+
+if( !isset($_REQUEST["action"]) || $_REQUEST["action"] == "" ){
+ header($_SERVER["SERVER_PROTOCOL"] . " 400 Bad Request");
+ header("X-Debug: Please define a action.");
+ exit;
+}
+if( !isset($_REQUEST["url"]) || $_REQUEST["url"] == "" ){
+ header($_SERVER["SERVER_PROTOCOL"] . " 400 Bad Request");
+ header("X-Debug: Please define a valid host.");
+ exit;
+}
+
+function ipv6($host){
+
+ if ( filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ) {
+ return true;
+ }
+
+ return false;
+}
+
+header("Content-Type: application/json");
+// response
+$r = array("host" => $_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);