summaryrefslogtreecommitdiff
path: root/down
diff options
context:
space:
mode:
Diffstat (limited to 'down')
-rw-r--r--down/ajax.php60
-rw-r--r--down/http.php31
-rw-r--r--down/index.php18
-rw-r--r--down/ping.php26
-rw-r--r--down/view/templ-index.php117
-rw-r--r--down/view/templ-noscript.php87
6 files changed, 339 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);
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 @@
+<?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/down/index.php b/down/index.php
new file mode 100644
index 0000000..e71e76a
--- /dev/null
+++ b/down/index.php
@@ -0,0 +1,18 @@
+<?php
+
+if( !isset($_REQUEST["action"]) || $_REQUEST["action"] == "" ){
+ require 'view/templ-index.php';
+} else {
+ if ( isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest"){
+ require 'ajax.php';
+ } else {
+ ob_start();
+ require 'ajax.php';
+ $json = json_decode(ob_get_contents(), true);
+ ob_end_clean();
+ header("Content-Type: text/html; charset=UTF-8");
+
+ require 'view/templ-noscript.php';
+
+ }
+}
diff --git a/down/ping.php b/down/ping.php
new file mode 100644
index 0000000..4c1bea7
--- /dev/null
+++ b/down/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);
+}
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 @@
+<!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">
+ <link rel="stylesheet" href="../tools/static/sweet-alert.css">
+ <style>
+ <?php echo file_get_contents("../tools/style.css"); ?>
+ </style>
+ <noscript><style>.navbar{margin-bottom:0;}</style></noscript>
+ <title>Is it down? | 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">
+
+ <form id="theform" class="form-horizontal">
+ <fieldset>
+
+ <!-- Form Name -->
+ <legend>
+ <h1>Uptime is the game</h1>
+ <h4>Is your favourite website down?</h4>
+ </legend>
+
+ <!-- Text input-->
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="url">Check if up: </label>
+ <div class="col-md-4">
+ <?php if ( isset($_REQUEST["url"]) && $_REQUEST["url"] != "" ){
+ ?>
+ <input id="url" name="url" placeholder="kernel.org" class="form-control input-md" required="" type="text" <?php echo 'value="'.htmlentities($_REQUEST["url"]) . '"'; ?> autofocus>
+ <?php
+ } else {
+ ?>
+ <input id="url" name="url" placeholder="kernel.org" class="form-control input-md" required="" type="text" autofocus>
+ <?php
+ }
+ ?>
+ </div>
+ </div>
+
+ <!-- Multiple Radios (inline) -->
+ <div class="form-group">
+ <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
+ </label>
+ <label class="radio-inline" for="action-1">
+ <input name="action" id="action-1" value="http" type="radio">
+ HTTP
+ </label>
+ </div>
+ </div>
+
+ <!-- Button -->
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="submit"></label>
+ <div class="col-md-4">
+ <button type="submit" id="submit" name="" value="" class="btn btn-success">Check it</button>
+ </div>
+ </div>
+
+ </fieldset>
+ </form>
+
+ </div>
+ </div>
+</div>
+
+ <?php require("../tools/footer.php"); ?>
+ <script>
+ window.onload = function(){
+
+ $("#theform").submit( function(e){
+
+ $.ajax({
+ url: "",
+ data: $("#theform").serialize(),
+ dataType: "json",
+ type: "GET",
+
+ success: function( response ){
+
+ if ( response.data == 1 ) {
+ var type = "success";
+ var button= "btn-success";
+ } else {
+ var type= "error";
+ var button= "btn-danger";
+ }
+ swal({
+ title: response.host,
+ text: response.status,
+ type: type,
+ confirmButtonClass: button
+ });
+
+ $("#url").val('');
+ },
+ });
+
+ e.preventDefault();
+ });
+
+ $(".fa-spinner").addClass("fa-spin");
+
+ };
+ </script>
+ <script defer src="../tools/static/sweet-alert.js"></script>
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 @@
+<!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>Is it down? | 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">
+
+
+ <h1>Uptime is the game</h1>
+ <h4>Is your favourite website down?</h4>
+ <hr>
+
+ <?php
+ if($json["data"] == 1){
+ ?>
+ <div class="alert alert-success" role="alert">
+ <?php
+ } else {
+ ?>
+ <div class="alert alert-danger" role="alert">
+ <?php
+ }
+ ?>
+ <h1><?php echo htmlentities($json["host"]); ?></h1>
+ <h4><?php echo htmlentities($json["status"]); ?></h4>
+ </div>
+
+ <form id="theform" class="form-horizontal">
+ <fieldset>
+
+ <!-- Form Name -->
+ <legend>
+ <h1>Check another one</h1>
+ </legend>
+
+ <!-- Text input-->
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="url">Check if up: </label>
+ <div class="col-md-4">
+ <input id="url" name="url" placeholder="kernel.org" class="form-control input-md" required="" type="text" autofocus>
+ </div>
+ </div>
+
+ <!-- Multiple Radios (inline) -->
+ <div class="form-group">
+ <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
+ </label>
+ <label class="radio-inline" for="action-1">
+ <input name="action" id="action-1" value="http" type="radio">
+ HTTP
+ </label>
+ </div>
+ </div>
+
+ <!-- Button -->
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="submit"></label>
+ <div class="col-md-4">
+ <button type="submit" id="submit" name="" value="" class="btn btn-success">Check it</button>
+ </div>
+ </div>
+
+ </fieldset>
+ </form>
+
+ </div>
+ </div>
+</div>
+
+ <?php require("../tools/footer.php"); ?>