<?php

    
// This program is licensed under the Creative Commons license, which can be found at:
    // http://creativecommons.org/licenses/by-nc-sa/2.5/
    // - Attribution. You must give the original author credit.
    // - Non-Commercial. You may not use this work for commercial purposes.
    // - Share Alike. If you alter, transform, or build upon this work, you
    //   may distribute the resulting work only under a licence identical to this one.
    //
    // Created by Mariusz Maroszek - mariusz@maroszek.org
    // Homepage of phpPing: http://phpping.maroszek.org/
    //
    // phpPing version 1.1b (beta)


    // Configuration
    
$txtTitle          "Dostępność serwerów";         // Title of this document
    
$txtGenerated      "Wygenerowano w";              // Time of generating for this page
    
$txtSeconds        "sek.";                        // Shortcut for seconds
    
$txtMiliseconds    "ms";                          // Shortcut for miliseconds
    
$txtPing           "Ping:";                       // Ping row name
    
$txtServerName     "Nazwa serwera:";              // Server row name
    
$txtServerStatus   "Status serwera:";             // Server status row name
    
$txtServerDead     "serwer niedostępny";          // Server offline
    
$txtServerAlive    "serwer dostępny";             // Server online
    
$getArrayFromUrl   TRUE;                            // Gives a posibility to check ip by setting var $ip in the URL,
                                                        // i.e. http://yourdomain/phpPing/?ip=leon.pl
    
$getArrayFrom      "array";                        // If "file" - loads array from file "ip.txt", if "array" - loads from array abowe
    
$displayHeader     TRUE;                          // Displays title of document on the top of the page
    
$displayPing       TRUE;                          // Displays ping row in the table
    
$displayFooter     TRUE;                          // Displays footer with generation time of the page
    
$sendingPacks      "5";                           // How much packs should send the script to check
                                                        // the ping (work only if displayHeader is on)
    
$serverArrayList   = array("leon.pl""dc.leon.com.pl""poczta.rybnik.pl""tim.nowiny.net""lelek.nowiny.net""rybnet.pl""maroszek.org:83.149.77.147");
                                                        
// Input the servers separated with a coma and in the quotation-marks
                                                        // If you would like to add a name to the server first write the
                                                        // name of the server and the directly after server name the 
                                                        // colon and the IP adress of the server or server host name, i.e.
                                                        // "maroszek.org:83.149.77.147"



    // Don't change anything below if you don't know what you are doing

    // Generating page
    
function genWww() {
        
$time explode(" "microtime());
        
$usec = (double)$time[0];
        
$sec = (double)$time[1];
        return 
$sec $usec;
        }
    
$start genWww();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
<head>
<title><?php echo $txtTitle?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="phpPing - http://phpping.maroszek.org/" />
<meta name="Copyright" content="Mariusz Maroszek" />
<style type="text/css">

html, body {
    text-align: center;
    background: #7F0909;
    }
caption {
    margin: auto;
    font-family: Impact, Arial, sans-serif;
    font-size: 22px;
    color: #FFFFFF;
    }
table {
    margin: auto;
    background: #BF1919;
    border: solid 10px #BF1919;
    }
th, td {
    background: #FFFFFF;
    font-family: Trebuchet MS, Arial, sans-serif;
    font-size: 11px;
    padding: 10px;
    }
td.y {
    color: #44BF19;
    }
td.n {
    color: #BF1919;
    }
td.a {
    text-align: left;
    }
a {
    text-decoration: underline;
    color: #000000;
    }
a:hover {
    text-decoration: none;
    color: #000000;
    }
#foot {
    margin: auto;
    font-family: Verdana, Tahoma, sans-serif;
    font-size: 10px;
    color: #FFFFFF;
    }
#foot a {
    color: #FFFFFF;
    text-decoration: underline;
    }
#foot a:hover {
    color: #FFFFFF;
    text-decoration: none;
    }

</style>
</head>

<body>

<table>
<?php

    
if($displayHeader) {
        echo 
"<caption>".$txtTitle."</caption>";
        }

?>
<tr><th><?php echo $txtServerName?></th><th><?php echo $txtServerStatus?></th><?php if($displayPing) { echo "<th>".$txtPing."</th>"; } ?></tr>
<?php

    
function getmstime() {
        return (
substr(microtime(),11,9)+substr(microtime(),0,10));
        }


    
$ip $_GET['ip'];
    if ((
$getArrayFromUrl) && (!empty($ip))) {
        
$serverArray[0] = $ip;
        }
    else if (
$getArrayFrom == "file") {
        
$fileTxt "./ip.txt";
        
$openTxt fopen($fileTxt,"rtb");
        
$readTxt fread($openTxtfilesize($fileTxt));
        
$serverArray explode("\n"$readTxt);

        
fclose($openTxt);
        }
    else if (
$getArrayFrom == "array") {
        
$serverArray $serverArrayList;
        }

    
$serverCount count($serverArray) - "1";
    
$a "0";
    while (
$a <= $serverCount) {


        
// Searching for name in array
        
$searchAdress strpos($serverArray[$a], ":");
        if (
$searchAdress) {
            
$cutName strstr($serverArray[$a], ":");
            
$cutAdress substr($cutName1);
            
$cutLength strlen($cutName);
            
$adressLength strlen($serverArray[$a]);
            
$arrayLength $adressLength $cutLength;
            
$serverArrayOne $cutAdress;
            
$serverArrayTwo substr($serverArray[$a], 0$arrayLength);
            }
        else {
            
$serverArrayOne $serverArray[$a];
            
$serverArrayTwo $serverArray[$a];
            }

        echo 
"<tr>";

        
// Checking server (up/down)
        
$openServer = @fsockopen($serverArrayOne80, &$errno, &$errstr20);
        if(!
$openServer) {
            echo 
"<td class=\"a\">".$serverArrayTwo."</td><td class=\"n\">".$txtServerDead."</td>";
            if (
$displayPing) { echo "<td></td>"; }
            }
        else {
            echo 
"<td class=\"a\"><a href=\"http://".$serverArrayOne."\">".$serverArrayTwo."</a></td><td class=\"y\">".$txtServerAlive."</td>";


            
// Pinging
            
if ($displayPing) {

                
$sendingPacks "5";
                for (
$b "0"$b <= $sendingPacks$b++) {
                    
$sendPack getmstime();
                    
$sendingPack = @fsockopen($serverArrayOne80, &$errno, &$errstr20);
                    
$replyPack getmstime();
    
                    if (!
$sendingPack) {
                        
$txtPinging "-";
                        break;
                        }
                    else {
                        
$txtPinging $txtPinging round(($replyPack-$sendPack) * 1000);
                        
$txtPinging $txtPinging/$sendingPacks;
                        
$txtPinging round($txtPinging1);
                        if (
$txtPinging "1") { $txtPinging "&lt; 1"; }
                        }
                    }
                echo 
"<td>".$txtPinging." ".$txtMiliseconds."</td>";
                }
            }

        @
fclose($openServer);

        echo 
"</tr>\n";
        
$a++;
        }

?>
</table>

<?php

    
echo "<div id=\"foot\">";

    if(
$displayFooter) {
        
$end genWww();
        
$run $end $start;
        echo 
$txtGenerated." ".substr($run05)." ".$txtSeconds."<br />";
        }

    echo 
"<a href=\"http://phpping.maroszek.org\">phpPing</a> v.1.1b";
    echo 
"</div>";

?>

</body>
</html>