<?php
/**
 * Simple automated site test
 *
 * @author  Paul Bissex <pb@e-scribe.com>
 * @license  MIT
 * 
 * USAGE
 * 
 * 1. In each page to be tested, place code that returns "OK" if the GET parameter
 * "TEST" is set to 1. This code must execute before the page has sent any output.
 *
 * PHP code:
 *   if ($_GET['TEST'] == 1) { print "OK"; exit; }
 *
 * Smarty template code;
 *   {php}if ($_GET['TEST'] == 1) { print "OK"; exit; }{/php}
 *
 * 2. Place the URLs of the pages to be tested in the $urls array below
 * 
 * 3. Run this script whenever you want to check on the status of your site(s).
 * 
 * A line of HTML output is produced for each URL, starting with a green "OK 
 * if the page responded as expected and a red "ERROR" if it didn't. Each line
 * also contains a testing link and a link to the bare site URL.
 * 
 * The page title will either say "ALL OK" or, if there are errors, 
 * "ERRORS (n)" where n is the number of pages that failed.
 */

$urls = array (
);


function 
testable ($url)
    {
    return 
"$url?TEST=1";
    }

function 
clickable ($url)
    {
    return 
"<a href='" testable ($url) . "'>test</a> <a href='$url'>$url</a>";
    }

function 
test_all ($urls)
    {
    
$error_count 0;
    foreach (
$urls as $url)
        {
        
$lines file (testable ($url));
        
$response $lines[0];
        if (
substr ($response02) == "OK")
            {
            
$html .= "<span class='good'>OK</span>: " clickable ($url) . "<br />";
            }
        else 
            {
            
$error_count++;
            
$html .= "<span class='bad'>ERROR</span>: " clickable ($url) . "<br />";
            }
        }
    
$status = ($error_count "ERRORS ($error_count)" "ALL OK");
    return array (
$html$status);
    }
    
list (
$body$status) = test_all ($urls); 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Site Status: <?= $status ?></title>
    <style type='text/css'>
    .good {color: green; font-weight: bold }
    .bad {color: red; font-weight: bold }
    </style>
</head>
<body>
<h1><?= $status ?></h1>
<?= $body ?>
</body>
</html>