blob: 7ebc334f61e7191b623655ad600f7ebefb6387a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
<?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($ip){
if ( filter_var($ip, 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["resp_code"] = 2;
} else {
$r["status"] = "Seems down. :(";
$r["resp_code"] = 0;
}
break;
case("http"):
require 'http.php';
if ( !ipv6($_REQUEST["url"]) && filter_var(sanitizeUrl($_REQUEST["url"]), FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === false ){
$r["status"] = "Host not valid";
$r["resp_code"] = 0;
} else {
$status = isUp($_REQUEST["url"], ipv6($_REQUEST["url"]));
if ( $status == 2 ) {
$r["status"] = "Looks like it's up from here.";
$r["resp_code"] = 2;
} else if ($status >= 400) {
$r["status"] = "Site responded with a ".$status." code.";
$r["resp_code"] = 1;
}
else {
$r["status"] = "Seems down. :(";
$r["resp_code"] = 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);
|