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 | |
| parent | 33affa31742f0bc9d735349763f639087ea4e7ff (diff) | |
| download | tools.iamfabulous.de-bbe481a7fa159db107c7005f8b024bf4657c0bd6.tar.gz | |
Backend for checking uptime
Diffstat (limited to 'isup')
| -rw-r--r-- | isup/ajax.php | 48 | ||||
| -rw-r--r-- | isup/http.php | 31 | ||||
| -rw-r--r-- | isup/index.php | 25 | ||||
| -rw-r--r-- | isup/ping.php | 26 |
4 files changed, 130 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; +} diff --git a/isup/http.php b/isup/http.php new file mode 100644 index 0000000..9973cb4 --- /dev/null +++ b/isup/http.php @@ -0,0 +1,31 @@ +<?php +function isUp($url){ + $agent = "Just checking if you are up or not."; + $ch=curl_init(); + curl_setopt ($ch, CURLOPT_URL,$url ); + curl_setopt($ch, CURLOPT_USERAGENT, $agent); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); + 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); + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if($httpcode>=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]+(?<query>/.*)|", $url, $match) ) + $url = str_replace($match["query"], "", $url); + + return $url; +} diff --git a/isup/index.php b/isup/index.php new file mode 100644 index 0000000..9c856c8 --- /dev/null +++ b/isup/index.php @@ -0,0 +1,25 @@ +<!doctype html> +<html> +<head> + <meta charset="utf-8"> + <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> + <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> + <style> + <?php echo file_get_contents("../tools/style.css"); ?> + </style> + <noscript><style>.navbar{margin-bottom:0;}</style></noscript> + <title>IsUP | iamfabulous.de</title> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <link rel='shortcut icon' href='../tools/favicon.ico' type='image/x-icon'> +</head> +<body> + <?php require("../tools/navbar.php"); ?> +<div class="container"> + <div class="text-center"> + <div class="row"> + + </div> + </div> +</div> + + <?php require("../tools/footer.php"); ?> diff --git a/isup/ping.php b/isup/ping.php new file mode 100644 index 0000000..4c1bea7 --- /dev/null +++ b/isup/ping.php @@ -0,0 +1,26 @@ +<?php + +function ping($host, $ipv6){ + + if ( $ipv6 ) + $ping = "/usr/bin/fping6"; + else + $ping = "/usr/bin/fping"; + + system($ping . " " . $host . " > /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("|(?<query>/.*)|", $host, $match) ) + $host = str_replace($match["query"], "", $host); + + return escapeshellarg($host); +} |
