This is a lfs server query script
<?php
$serverCount = count($serverprot);
$c = 0;
while($c < $serverCount)
{
include setLanguage($showLanguage);
$filepath[$c] = $serverprot[$c] . "://" . $ftpuser[$c] . ":". $ftppw[$c] . "@" . $serverip[$c] . $hostpath[$c] . "/host" . $lfsport[$c] . ".txt";
/*$sock = @fsockopen($serverip[$c], $lfsport[$c], $errno, $errstr, 0.01);
if (!$output)
{
$status = "offline";
}
else
{
$status = "online";
}
@fclose($output);
if ($status == offline)
{
echo "Status: offline";
break;
}
else */
{
if( !file_exists( $filepath[$c] ) )
{
echo "Server <span style=\"color: red;\">offline</span>";
}
else
{
$datei[$c] = @fopen($filepath[$c], r);
if($datei[$c]==FALSE)
{
die("File access error!");
}
while(!feof($datei[$c]))
{
$zeile[$c] = $zeile[$c] . "\n" . fread($datei[$c], 4096);
}
fclose($datei[$c]);
//echo "<font face=\"Courier New\" size=\"2\">$zeile</font><br><br>"; //can be enabled to get some kind of debug output ;-)
$splitted[$c] = explode("\n", $zeile[$c]);
$version[$c] = explode("=", $splitted[$c][1]);
$version[$c] = trim($version[$c][1]);
$status[$c] = explode("=", $splitted[$c][2]);
$status[$c] = trim($status[$c][1]);
$guests[$c] = explode("=", $splitted[$c][3]);
$guests[$c] = trim($guests[$c][1]);
$maxguests[$c] = explode("=", $splitted[$c][4]);
$maxguests[$c] = trim($maxguests[$c][1]);
$hostname[$c] = explode("=", $splitted[$c][5]);
$hostname[$c] = trim($hostname[$c][1]);
$pass[$c] = explode("=", $splitted[$c][6]);
$pass[$c] = trim($pass[$c][1]);
$track[$c] = explode("=", $splitted[$c][8]);
$track[$c] = trim($track[$c][1]);
$cars[$c] = explode("=", $splitted[$c][9]);
$cars[$c] = trim($cars[$c][1]);
$qual[$c] = explode("=", $splitted[$c][10]);
$qual[$c] = trim($qual[$c][1]);
$length[$c] = explode("=", $splitted[$c][11]);
if(trim($pass[$c]) != "")
$public[$c] = $strServerPrivate;
else
$public[$c] = $strServerPublic;
if(trim($length[$c][1]) == "" || trim($length[$c][1]) == "0")
{
$length[$c] = $strTraining;
$qual[$c] = $strNone;
}
else
{
if(trim($length[$c][0])=="hours")
{
if(trim($length[$c][1]) > 1)
$length[$c] = trim($length[$c][1]) . " " . $strHours;
else
$length[$c] = trim($length[$c][1]) . " " . $strHour;
}
else if(trim($length[$c][0])=="laps")
{
if(trim($length[$c][1]) > 1)
$length[$c] = trim($length[$c][1]) . " " . $strLaps;
else
$length[$c] = trim($length[$c][1]) . " " . $strLap;
}
if($qual[$c]=="1")
$qual[$c] .= " " . $strMinute;
else
$qual[$c] .= " " . $strMinutes;
}
$i1 = 12;
while($i1 <= count($splitted[$c]))
{
$racer[$c] = explode("=", $splitted[$c][$i1]);
$racer[$c] = trim($racer[$c][1]);
if(trim($racer[$c]!="host"))
{
$racer[$c] = get_racer($racer[$c]);
$online_racer[$c] .= $racer[$c] . "<br>";
}
$i1++;
}
$hostname_clear[$c] = get_clearHostname($hostname[$c]);
$host[$c] = get_hostname($hostname[$c]);
$status[$c] = get_onlineStatus($status[$c]);
$cars[$c] = get_cars($cars[$c], $showInfo[$c][4], $showLanguage);
$track[$c] = get_trackName($track[$c]);
}
if($host[$c]==NULL)
$status[$c] = "<font color=\"red\">" . $strError_connect . "</font>";
/*if($datei==FALSE && $host!=NULL)
$status = "<font color=\"red\">" . $strError_file . "</font>";*/
if($guests[$c]==0)
$online_racer[$c] = "<i>" . $strNo_racer . "</i>";
output($showInfo, $bgColor, $hostname_clear[$c], $host[$c], $status[$c], $version[$c], $guests[$c], $maxguests[$c], $track[$c], $cars[$c], $qual[$c], $length[$c], $online_racer[$c], $showLanguage, $public[$c]);
$c++;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
// !!! ALL FUNCTIONS USED IN THE SCRIPT WILL BE BEHIND THIS LINE !!! //
//////////////////////////////////////////////////////////////////////////////////////////////
/***************************************************\
|* output()
|* =========================
|* This function formats all gained information and
|* creates the output and also writes the output.
\***************************************************/
function output($showInfo, $bgColor, $hostname_clear, $host, $status, $version, $guests, $maxguests, $track, $cars, $qual, $length, $online_racer, $showLanguage, $strServerPub)
{
include "_data_config.php";
include setLanguage($showLanguage);
echo "<body bgcolor = \"$bgColor\"><font face=\"Verdana\" size=\"2\">";
echo $strHostname ;
echo ": <b><a href=\"lfs://|$hostname_clear|0|S2|/\">$host</a></b><br>";
echo $strStatus . ": <b>$status</b><br>";
if($showInfo[8]==1)
echo "$strServerPub<br>";
if($showInfo[0]==1)
echo $strVersion . ": $version<br>";
if($showInfo[1]==1)
echo $strUserConnected . ": $guests/$maxguests<br>";
if($showInfo[2]==1)
echo $strTrack . ": $track<br>";
if($showInfo[3]==1)
echo $strCars . ": $cars<br>";
if($showInfo[5]==1)
echo $strQualifying . ": $qual<br>";
if($showInfo[6]==1)
echo $strRacelength . ": $length<br><br>";
if($showInfo[7]==1)
echo $strRacersOnline . ": <br>$online_racer";
echo "<br><br><br><br>";
echo "</font></body>";
return FALSE;
}
/***************************************************\
|* setLanguage()
|* =========================
|* This will get the language string from the config.
|* If no language string (e.g. "enu" or "deu") is
|* supplied, English will be used by default.
\***************************************************/
function setLanguage($showLanguage)
{
$lang = strtolower($showLanguage); //Always convert the language shortcut to lower case characters
if($lang=="")
$lang = "enu";
$LangSet = "lang/lang_" . $lang . ".php";
if(is_file($LangSet)==false)
$LangSet = "lang/lang_enu.php";
return $LangSet;
}
/***************************************************\
|* get_trackName($track)
|* =========================
|* This function converts the short Track tag (e.g.
|* BL1, KY2, SO2R and so on) to the complete name
|* of the current track combination.
\***************************************************/
function get_trackName($track)
{
///////////////////////////
// BLACKWOOD
///////////////////////////
if($track=="BL1")
$trackName = "Blackwood GP";
if($track=="BL1R")
$trackName = "Blackwood GP Rev.";
if($track=="BL2")
$trackName = "Blackwood RallyX";
if($track=="BL2R")
$trackName = "Blackwood RallyX Rev.";
if($track=="BL3")
$trackName = "Blackwood Car Park";