diff options
| author | Horus3 | 2014-12-04 14:34:24 +0100 |
|---|---|---|
| committer | Horus3 | 2014-12-04 14:34:24 +0100 |
| commit | bbe481a7fa159db107c7005f8b024bf4657c0bd6 (patch) | |
| tree | 8f40683e61db3d8ac774820163e67ce6d1701439 /isup/ajax.php | |
| parent | 33affa31742f0bc9d735349763f639087ea4e7ff (diff) | |
| download | tools.iamfabulous.de-bbe481a7fa159db107c7005f8b024bf4657c0bd6.tar.gz | |
Backend for checking uptime
Diffstat (limited to 'isup/ajax.php')
| -rw-r--r-- | isup/ajax.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/isup/ajax.php b/isup/ajax.php new file mode 100644 index 0000000..3e21a20 --- /dev/null +++ b/isup/ajax.php @@ -0,0 +1,48 @@ +<?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; +} + +switch($_REQUEST["action"]){ + case("ping"): + require 'ping.php'; + if ( ping( sanitizeHost($_REQUEST["url"]), ipv6($_REQUEST["url"]) ) ){ + echo "up"; + } else { + echo "down"; + } + 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"]) ){ + echo "up"; + } else { + echo "down"; + } + } + break; + default: + header($_SERVER["SERVER_PROTOCOL"] . " 400 Bad Request"); + header("X-Debug: Please define a valid action."); + break; +} |
