Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
added dynamic open search and ip or user agent blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Parkinson committed May 15, 2011
1 parent 0445294 commit f320868
Show file tree
Hide file tree
Showing 15 changed files with 259 additions and 309 deletions.
94 changes: 63 additions & 31 deletions check.php
@@ -1,11 +1,17 @@
<?php
// if the site is offline
require_once("settings.php");

if (in_array($_SERVER["REMOTE_ADDR"], $setting["banned_ips"]) || in_array($_SERVER["HTTP_USER_AGENT"], $setting["banned_ua"]) || empty($_SERVER["HTTP_USER_AGENT"])) {
header('HTTP/1.1 403 Forbidden');
exit(); }

if ($setting["live"] != true) {
header('Location: http://' . $setting["host"] . '/offline');
exit(); }

require_once("functions.php");
//require_once("classes.php");

// retrieve the url to test, then clean it up
$domain = preg_replace("/[^A-Za-z0-9-\/\.\:]/", "", trim($_GET["domain"]));
Expand All @@ -21,62 +27,88 @@
else {
$port = 80; };

// check the site and get the messages
// check the site and get the response code
$data = get_response($domain, $port);

// start the timmer
$time_start = microtiming();

$code = get_response($domain, $port);

// stop the timmer
$time_stop = microtiming();
// split the code and data into seperate vars
$code = $data["code"];
$time = $data["time"];

// caluate and format the time taken to connect
$time = round($time_stop - $time_start, 3);
$time = round($time, 3);

if (preg_match("/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i", gethostbyname($domain))) {
$ip = gethostbyname($domain);
} else {
$ip = "NULL"; };

$id = gen_id($code);
$title = gen_title($id, $domain);
$html = gen_html($id, $domain, $port, $time, $code);

if ($id == 1 || $id == 2) {

set_auto_domains($domain, $port, $setting["auto_domains"]);

if (isset($_GET["output"])) {
$output = $_GET["output"];

$result = array(
"domain" => $domain,
"port" => $port,
"status_code" => $id,
"response_ip" => $ip,
"response_code" => $code,
"response_time" => $time );

if ($output == "txt") {

foreach ($result as &$value) {
if (empty($value)) { $value = "NULL"; };
};

unset($value);

header('Content-type: text/plain');

// domain, id, ip, http_code, response_time
print $result["domain"] . ", " . $result["port"] . ", " . $result["status_code"] . ", " . $result["response_ip"] . ", " . $result["response_code"] . ", " . $result["response_time"];

exit();
} elseif ( $output == "json" ) {

foreach ($result as &$value) {
if (empty($value)) { $value = null; };
};

unset($value);

header('Content-type: application/json');

print json_encode($result);

exit();
};
};
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>

<title><?php echo $title; // display the dynamic title ?></title>

<?php if ($id == 0): ?>
<title><?php echo $title . " // isitup.org"; // display the dynamic title ?></title>

<meta name="robots" content="noindex" />
<?php endif; ?>
<meta name="description" content="The availability results for <?php echo $domain; ?>." />
<meta name="keywords" content="is it up, isitup, is it up?, is <?php echo $domain; ?> up?, is <?php echo $domain; ?> down?, is it up website monitor, is it up website, is it down, is it just me, is it up yet" />

<meta name="description" content="The availability results for <?php echo $domain; ?>. // isitup.org" />
<meta name="keywords" content="is it up, isitup, is it up?, is <?php echo $domain; ?> up?, is <?php echo $domain; ?> down?, it is up, website down, site down, is site down, is it down, is it just me" />

<link rel="icon" type="image/png" href="<?php echo $setting["static"]; ?>/img/icon.png" />
<link rel="stylesheet" type="text/css" media="screen, print" href="<?php echo $setting["static"]; ?>/css/reset.css" />
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $setting["static"]; ?>/css/style.css" />
<link rel="stylesheet" type="text/css" media="print" href="<?php echo $setting["static"]; ?>/css/print.css" />

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready(function () {
$("a").click(function() { this.blur(); });
});
/* ]]> */
</script>
<link rel="stylesheet" type="text/css" media="screen, print" href="<?php echo $setting["static"]; ?>/css/style.css" />
</head>
<body>
<div id="container">
<?php echo $html; // displays the response for the site we're checking ?>

<?php if ($id != 0 && $domain != "isitup.org" && $domain != "127.0.0.1"): ?>

<?php echo display_ad(); ?>
<?php endif; ?>
</div>
</body>
Expand Down
7 changes: 3 additions & 4 deletions error.php
Expand Up @@ -5,19 +5,18 @@
header('Location: http://' . $setting["host"] . '/offline');
exit(); }

header('HTTP/1.1 404 Not found');
header('HTTP/1.1 404 Not Found');
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Oh noes, an error!</title>
<title>Oh noes, an error! // isitup.org</title>

<link rel="icon" type="image/png" href="<?php echo $setting["static"]; ?>/img/icon.png" />
<link rel="stylesheet" type="text/css" media="screen, print" href="<?php echo $setting["static"]; ?>/css/reset.css" />
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $setting["static"]; ?>/css/style.css" />
<link rel="stylesheet" type="text/css" media="print" href="<?php echo $setting["static"]; ?>/css/print.css" />
<link rel="stylesheet" type="text/css" media="screen, print" href="<?php echo $setting["static"]; ?>/css/style.css" />
<meta name="robots" content="noindex" />
</head>
<body>
Expand Down
106 changes: 32 additions & 74 deletions functions.php
@@ -1,12 +1,4 @@
<?php
/**
* Generate the current time.
* @return string
*/
function microtiming() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec); }

/**
* Generates a domain, with or without a port.
* @param string $domain
Expand All @@ -30,7 +22,7 @@ function show_ip($domain) {
$ip = gethostbyname($domain);

if (preg_match($domexprcheck, $domain) == true) {
$text = " with an ip of <a href=\"http://" . $ip . "\" title=\"Visit " . $ip . "\">" . $ip . "</a>";
$text = " with an ip of <a href=\"http://" . $ip . "\" title=\"" . $ip . "\">" . $ip . "</a>";
} else {
$text = null; }
return $text; }
Expand All @@ -45,7 +37,7 @@ function test_domain($domain) {
$domexprcheck = "/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/i";
$ipexpcheck = "/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i";

return (preg_match($domexprcheck, $domain) == true || preg_match($ipexpcheck, $domain) == true) ? true : false; }
return (preg_match($domexprcheck, $domain) || preg_match($ipexpcheck, $domain)) ? true : false; }

/**
* Generates the units for the response time.
Expand All @@ -65,21 +57,21 @@ function gen_units($time) {
* @return mixed
*/
function get_response($domain, $port) {
global $setting;
if (test_domain($domain)) {
// retrieves just the http header response
$headers = @get_headers("http://" . $domain . ":" . $port);

// extract the response code
preg_match("/[0-9]{3}/", $headers[0], $matches);

if (!empty($matches)) {

// get the first thing from the matches array, it should be the response code
$code = (int)$matches[0];
} else {
/// old code: $headers = @get_headers("http://" . $domain . ":" . $port);
$start = microtime(true);
$r = @http_head("http://" . $domain . ":" . $port, array('timeout' => $setting["timeout"]), $headers);
$end = microtime(true);

$code = array("code" => $headers["response_code"],
"time" => $end - $start);
if ($headers["response_code"] == 0) {
return false; }
} else {
$code = "invalid"; }
$code = array("code" => "invalid",
"time" => 0); }
return $code; }

/**
Expand All @@ -94,23 +86,26 @@ function get_response($domain, $port) {
function gen_html($id, $domain, $port, $time, $code) {
$units = gen_units($time);
if ($time < 1) { $time = $time * 1000; } else { $time = round($time, 2); }
if ($time <= 0) { $time = "< 1"; }
if ($id == 1) {
$html = "<p><a href=\"http://" . gen_domain($domain, $port) . "\" class=\"domain\" title=\"Visit " . $domain . "\">" . $domain . "</a> is working :)</p>\n\n";
$html = "<p><a href=\"http://" . gen_domain($domain, $port) . "\" class=\"domain\" title=\"" . $domain . "\" rel=\"nofollow\">" . $domain . "</a> is working <span class=\"smile\">:)</span></p>\n\n";
$html .= "\t<p class=\"smaller\">It took " . $time . " " . $units . " for a <a href=\"http://en.wikipedia.org/wiki/List_of_HTTP_status_codes\" title=\"Wikipedia - HTTP Status Codes\">" . $code . "</a> response" . show_ip($domain) . ".</p>\n\n";
$html .= "\t<p class=\"smaller\">Check <a href=\"/\" id=\"print\">something else</a>" . gen_save($domain) . ".</p>\n";
$html .= "\t<p class=\"smaller\">Check <a href=\"/\" title=\"Home\">another site</a>" . gen_save($domain) . ".</p>\n";
} else if ($id == 2) {
if (!empty($code) && is_numeric($code)) {
$text = "We got a <a href=\"http://en.wikipedia.org/wiki/List_of_HTTP_status_codes\" title=\"Wikipedia - HTTP Status Codes\">" . $code . "</a> http status code" . show_ip($domain) . ".";
} else {
$text = "Check it's the right domain"; };
};

$html = "<p><a href=\"http://" . gen_domain($domain, $port) . "\" class=\"domain\" title=\"Visit " . $domain . "\">" . $domain . "</a> seems to be down :(</p>\n\n";
$html .= "\t<p class=\"smaller\">" . $text . " or <a href=\"/\" id=\"print\">check another?</a></p>\n";
$html = "<p><a href=\"http://" . gen_domain($domain, $port) . "\" class=\"domain\" title=\"" . $domain . "\" rel=\"nofollow\">" . $domain . "</a> seems to be down <span class=\"smile\">:(</span></p>\n\n";
if (isset($text)) {
$html .= "\t<p class=\"smaller\">" . $text . "</p>\n";
};
$html .= "\t<p class=\"smaller\">Check <a href=\"/\" title=\"Home\">another site</a>" . gen_save($domain) . ".</p>\n";
} else if ($id == 0) {
$html = "<p>We need a valid domain to check! <a href=\"/d/" . gen_domain($domain, $port) . "\">Try again.</a></p>\n"; };

if ($domain == "isitup.org" || $domain == "127.0.0.1") {
$html = "<p>Have a think about what you've just done. <a href=\"/\">Try again.</a></p>\n"; };
$html = "<p>Have a think about what you've just done. <a href=\"/\" title=\"Better luck next time.\">Try again.</a></p>\n"; };
return $html; }

/**
Expand All @@ -134,7 +129,7 @@ function gen_title($id, $domain) {
* @return int
*/
function gen_id($code) {
$good = array(200, 301, 302, 303, 304, 307);
$good = array(200, 301, 302, 303, 304, 307, 400, 401, 403, 405);

if ($code == "invalid") {
$id = 0;
Expand Down Expand Up @@ -167,43 +162,6 @@ function gen_cookie_string($array) {
return $cookie; };
return false; }

/**
* Sets the cookie for autocomplete.
* @param string $custom
* @param int $port
* @param array $default
* @param string $cookie
* @return bool
*/
function set_auto_domains($custom = null, $port = null, $default = array(), $cookie = "custom") {
$array = get_cookie_array($cookie);

if (!is_array($array)) { $array = array(); };

if ($port != 80 && is_numeric($port)) { $custom = $custom .":". $port; };

if (!empty($custom) && !in_array($custom, $default) && !in_array($custom, $array)) {
$array[] = $custom;
$string = gen_cookie_string($array);
if ($string != false) { setcookie($cookie, $string, time() + 60 * 60 * 24 * 7); }; };

return false; }

/**
* Generates the autocomplete list.
* @param array $custom
* @param array $default
* @return string
*/
function gen_auto_domains($custom = null) {
if (is_array($custom) && !empty($custom) && !isset($_GET["clear"])) {
sort($custom);
$string = implode("\",\"", $custom);
} else {
$string = ""; };

return $string; }

/**
* Gets the correct input value for the homepage.
* @param string $a the remote domain
Expand Down Expand Up @@ -259,7 +217,7 @@ function gen_save($domain) {
$array[] = $setting["input"];

if (!in_array($domain, $array)) {
return " or use as the <a href=\"http://isitup.org/save/" . $domain . "\" title=\"Use " . $domain . " as the default site to check\">default</a>"; };
return " or save as your <a href=\"http://isitup.org/save/" . $domain . "\" title=\"Use " . $domain . " as the default site to check\">default</a>"; };
return false; }

/**
Expand All @@ -268,18 +226,18 @@ function gen_save($domain) {
* @return bool|string
*/
function display_ad($ad = 0) {
$link[] = '<a href="https://secure.eveonline.com/ft/?aid=105433"><img src="http://static.im/isitup/img/eve_ad.jpg"></a>';
$link[] = '<a href="https://secure.eveonline.com/ft/?aid=105433"><img src="http://static.im/isitup/img/eve_ad2.jpg"></a>';
$link[] = '<a href="http://codecanyon.net?ref=r3morse"><img src="http://static.im/isitup/img/cc_ad.gif"></a>';
$link[] = 'Free online storage with <a href="https://www.dropbox.com/referrals/NTQwNTI2ODk" target="_blank" title="Get Dropbox!">Dropbox</a>!';
$link[] = 'Sync to the cloud with <a href="https://www.dropbox.com/referrals/NTQwNTI2ODk" target="_blank" title="Get Dropbox!">Dropbox</a>!';
$link[] = 'Share files online with <a href="https://www.dropbox.com/referrals/NTQwNTI2ODk" target="_blank" title="Get Dropbox!">Dropbox</a>!';

$seed = microtiming();
$seed = microtime(true);
mt_srand($seed);

if ($ad != 0) {
return $link[$ad];
return $link[$ad]."\n";
} else {
$adnum = mt_rand(0,count($link)-1);
return $link[$adnum]; };
$adnum = mt_rand(0, count($link) - 1);
return "<p id=\"ad\">" . $link[$adnum]."</p>\n"; };
return false; }

/**
Expand Down

0 comments on commit f320868

Please sign in to comment.