Jump to content

You're browsing the 2004-2023 VATSIM Forums archive. All content is preserved in a read-only fashion.
For the latest forum posts, please visit https://forum.vatsim.net.

Need to find something? Use the Google search below.
PLEASE READ - Webmaster Support Forum
This forum will be retired in the near future. Please direct all queries to our dedicated GitHub support page https://github.com/vatsimnetwork/developer-info/discussions 
Here you can find documentation on our services and we are continuing to migrate pertinent information into the Wiki pages https://github.com/vatsimnetwork/developer-info/wiki

ATC online code.


Luca Benelli
 Share

Recommended Posts

Luca Benelli
Posted
Posted

Here you can see some code sent by Rahul Parkar from VATUSA:

(code used on the vACC Italy website follows).

 

 

<?php

echo '<table width="180" align="center" cellpadding="0" cellspacing="0">';
echo '<tr><td height="20" colspan="2" cl[Mod - Happy Thoughts]="footerTextW" 
align="center">Controllers Online</td></tr>';

// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
   switch ($errno) {
   case E_USER_ERROR:
       echo '<b>My ERROR</b> [$errno] $errstr<br />n';
       echo '  Fatal error on line $errline in file $errfile';
       echo ', PHP ' . PHP_VERSION . ' (' . PHP_OS . ')<br />n';
       echo 'Aborting...<br />n';
       exit(1);
       break;

   case E_USER_WARNING:
       echo '<b>My WARNING</b> [$errno] $errstr<br />n';
       break;

   case E_USER_NOTICE:
       echo '<b>My NOTICE</b> [$errno] $errstr<br />n';
       break;

   default:
       //echo "Unknown error type: [$errno] $errstr $errline in
$errfile<br />n";
       break;
   }

   /* Don't execute PHP internal error handler */
   return true;
}


// set to the user defined error handler
$old_error_handler = set_error_handler("myErrorHandler");

//OPEN UP THE VATSIM STATS FILE
	$row_count = 0; 
$color1 = "#F5F5F5"; 
$color2 = "#FFFFFF"; 
if(file_exists("../vatsim-data.txt")){
$fp = fopen("../vatsim-data.txt", "r");


      while (!feof($fp))
        {
          $line = fgets($fp, 999);


//Put the Callsign Prefixes in : e.g. if callsign = VTBB_CTR enter VTBB or
VTBA_APP enter VTBA
if(preg_match('/^(ZME|MEM|BNA|RZC|XNA|JAN|CBM|GLH|GWO|MKL|PAH|MQY|LIT|FSM|ROG|HSV|MEI|NMM|HOP|GTR|OLV|NQA)_[A-Z0-9]*_*(DEL|GND|TWR|APP|DEP|CTR)/',
$line))
          {
                 list($position, $cid, $name, $clienttype, $frequency,
$latitude, $longitude, $altitude, $groundspeed, $planned_aircraft,
$planned_tascruise, $planned_depairport, $planned_altitude,
$planned_destairport, $server, $protrevision, $rating, $transponder,
$facilitytype, $visualrange, $planned_revision, $planned_flighttype,
$planned_deptime, $planned_actdeptime, $planned_hrsenroute,
$planned_minenroute, $planned_hrsfuel, $planned_minfuel,
$planned_altairport, $planned_remarks, $planned_route,
$planned_depairport_lat, $planned_depairport_lon,
$planned_destairport_lat,
$planned_destairport_lon, $atis_message, $time_last_atis_received,
$time_logon, $heading) = split(":", $line);
		if($rating == 1) { $rating = "Observer"; }
		if($rating == 2) { $rating = "Ground Controller"; }
		if($rating == 3) { $rating = "Tower Controller"; }
		if($rating == 4) { $rating = "Approach Controller"; }
		if($rating == 5) { $rating = "Controller"; }
		if($rating == 7) { $rating = "Senior Controller"; }
		if($rating == 8) { $rating = "Instructor"; }
		if($rating == 10) { $rating = "Senior Instructor"; }
		if($rating == 11) { $rating = "Supervisor"; }
		if($rating == 12) { $rating = "Administrator"; }
		$rowcolor = ($row_count % 2) ? $color1 : $color2;
		$newatis = str_replace('^§', '<br>', $atis_message);
		$newatis = str_replace("'", "", $newatis);
		$newatis = str_replace('"', "", $newatis);

echo '<tr>';
echo '<td style="padding:2px" align="left" >'. $position .'</td>';
echo '<td style="padding:2px" align="right">';

//FIND THE CONTROLLER IN THE CONTROLLERS TABLE
$query = "SELECT Opinit FROM controllers WHERE cid = '$cid'";
$result = @mysql_query($query);
if (mysql_num_rows($result) == 0) {
echo 'Uncertified Controller';
}
if (mysql_num_rows($result) > 0) {
//HYPERLINK TO MEMBERS PAGE
echo $name;
}

echo'</td>
</tr>';

		$row_count++;
          }
    }
echo '</table>'; 
echo '<table width="200" align="center" cellpadding="2" cellspacing="0">';


if($row_count == 0)
{
	echo '<tr><td align="center"><br>There are no controllers
online.</td></tr>';
}
else if($row_count == 1)
{
	//MODIFY NEXT LINE WITH CORRECT ICAO FOR YOUR ARTCC/FIR
	echo '<tr><td align="center"><br><font size="1">Currently 1 ZME
Controller Online</font></td></tr>';
}
else
{
     		//MODIFY NEXT LINE WITH CORRECT ICAO FOR YOUR ARTCC/FIR
		echo '<tr><td align="center"><br><font size="1">Currently $row_count
ZME Controllers Online</font></td></tr>';
}
}

echo '</table>';
?>

 

And here another version which comes from the http://www.vatita.net site:

 

<?php
error_reporting(2); 
/*
*** Online atc visualization script ***
15th July 2006 - version 0.1.3
created by Luca Benelli and Luca Vetturi
[email protected] - [email protected]
*/

// We tried to put quotes and comments on the code.
// If something desn't appear so clear, feel free to contact us.

//Here we we start with some connection stuff....
// We get the status file from Vatsim, in order to understand where to get the data file...
// ...but we also have to cache the file in local, in order to save vatsim's bandwidth

$statusmodtime=filemtime("/path/to/directory/status.txt");
$now=time();
$etastatus=$now-$statusmodtime;
$remotestatusfilename="http://status.vatsim.net";
$tempomaxstatus=86400;
//FOR DEBUG ONLY!!!! RIMETTERE SEMPRE LA RIGA SOPRA! 
//$tempomaxstatus=1;
if ($etastatus >= $tempomaxstatus) {
$statusremote=fopen($remotestatusfilename,"rb");
if ($statusremote!=NULL) {
	$statuslocal=fopen("/path/to/directory/status.txt","w");
	if (!$statuslocal){
		fclose ($statusremote);
	} else {
		while (strlen($data = fgets($statusremote, 1024)) != 0 ){
			fwrite($statuslocal,$data);
		}
	}
}
}

$tempomaxdata=127;
$statuslocal=fopen("/path/to/directory/status.txt","r");
$i=0;
while (strlen($data = fgets($statuslocal, 1024)) != 0 ){
if (substr($data,0,4)=="url0"){
	$url[$i]=substr($data,5);
	$i++;
}
if (substr($data,0,6)=="metar0"){
	$metar=substr($data,7);
}
if (substr($data,0,5)=="atis0"){
	$atis=substr($data,6);
}
}

$j=rand(0,$i-1);
$remotedatafilename=$url[$j];
fclose($statuslocal);

$lung=strlen($remotedatafilename);
$lung--;
$lung--;
$remotedatafilename=substr($remotedatafilename,0,$lung);

// Here we look at the time when the datafile was generated...

$datamodtime=filemtime("/path/to/directory/data.txt");
$now=time();
$etadata=$now-$datamodtime;
if ($etadata >= $tempomaxdata) {
$dataremote=fopen($remotedatafilename,"rb");
if ($dataremote==NULL) {
} else {
	$datalocal=fopen("/path/to/directory/data.txt","w");
	if (!$datalocal){
		fclose ($dataremote);
	} else {
		while (strlen($data = fgets($dataremote, 1024)) != 0 ){
			fwrite($datalocal,$data);
		}
	}
}
}

// Ok, it's time to open this datafile... explode the fields.... and get the arrays :-)

$i=0;
$file = fopen ("/path/to/directory/data.txt", "r");
while (strlen($data = fgets($file,2048)) != 0 ){
$riga = explode(':', $data);
//now there's something we used to prevent wrong atcs to display.... let me give you and example:
//in italy icao codes are LIxx... well in usa there's a LIT_APP position, and it came up on our homepage sometimes.
//reminding that italian airports have only LIBx, LICx, LIEx, LIMx, LIPx, LIRx icao codes, so we'll take only those facilities!
//feel free to edit and change it to your nation/fir/vacc :-)
$callab = substr($riga[0], 2, 1);
$staff = substr($riga[0], 0, 5);
if (substr($riga[0],0,2) == "LI" AND $riga[3]=="ATC" AND $riga[18] > "0"){
	if ($callab == "B" OR $callab == "C" OR $callab == "E" OR $callab == "M" OR $callab == "P" OR $callab == "R" OR $callab == "L" OR $callab == "D" OR $callab == "U") {
		//echo "<tr><td><B>".$riga[0]."</B></td><td>".$riga[4]."</td></tr>";
		$ctr[$i][1]=$riga[0];//callsign
		$ctr[$i][2]=$riga[2];//nome
		$ctr[$i][3]=$riga[4];//freq
		$ctr[$i][4]=$riga[35];//atis
		$i++;
	}
} elseif ($riga[3] == "ATC" AND $staff == "ACCIT") {
	$ctr[$i][1]=$riga[0];//callsign
	$ctr[$i][2]=$riga[2];//name
	$ctr[$i][3]=$riga[4];//freq
	$ctr[$i][4]=$riga[35];//atis
	$i++;
}
}
fclose($file);

// ATTENTION!
// you must install the OverLib libraries on your server, in order to get the "pop-up" of the details when you
// move your mouse over the "Details" link...
// get it here: http://www.bosrup.com/web/overlib/ 
// and put the files in the directory "/ol" at the root of the webserver.

// Here we look at the online atcs, [Mod - Happy Thoughts]ign a facility type ($descriz) and a simple image ($immagine)
// ...and print (row by row) the list with the image, the callsign, and the popup link (look at bottom)

if ($i){
echo "<table>";
for ($j=0;$j<$i;$j++){
	$callsign = $ctr[$j][1];
	$cosahaaperto = substr($callsign, -3);
	$atcnome = $ctr[$j][2];
	$freq = $ctr[$j][3];
	$freqcorta = substr($freq, 0, 6);
	if (substr($callsign, -4) != "ATIS") {
		if ($cosahaaperto == "CTR") {
			if (substr($callsign, 0, 4) == "LIUP") {
				$immagine = "./img/stat/upp.gif";
				$descriz = "Upper Center";
			} else {
				$immagine = "./img/stat/ctr.gif";
				$descriz = "Center";
			}
		} elseif ($cosahaaperto == "APP") {
			$immagine = "./img/stat/app.gif";
			$descriz = "Approach";
			if (substr($callsign, -6) == "_F_APP"){
				$cosahaaperto == "DIRECTOR";
				$descriz = "Approach Director";
			}
		} elseif ($cosahaaperto == "TWR") {
			$immagine = "./img/stat/twr.gif";
			$descriz = "Tower";
		} elseif ($cosahaaperto == "GND"){
			$immagine = "./img/stat/gnd.gif";
			$descriz = "Ground";
		} elseif ($cosahaaperto == "DEL"){
			$immagine = "./img/stat/gnd.gif";
			$descriz = "Clearance Delivery";
		} elseif (substr($callsign, 0, 5) == "ACCIT") {
			$immagine = "./img/stat/eye.gif";
			$descriz = "Italy vACC Staff member";
		}
	} else {
		$cosahaaperto = "ATIS";
		$immagine = "./img/stat/atis.png";
		$descriz = "Voice ATIS";
	}

	if (substr($callsign, 0, 5) != "ACCIT") {
		$atistxt = str_replace('"', '', $ctr[$j][4]);
		$atistxt = str_replace("^§","<br>",$atistxt);

		if (strpos($atistxt, "$") == 0) {
			$atistxt = strstr($atistxt, "<br>");
			$atistxt = substr($atistxt, 4);
			$atistxt = "<br><u>Atis:</u><br><i>".$atistxt."</i>";
		}			
	}


	echo "<tr><td align=\"center\"><img src=\"".$immagine."\"></td><td><b>".$ctr[$j][1]."</B></td>";
	echo "<td><a href=\"javascript:void(0);\" onmouseover=\"return overlib('<img src=\'$immagine\'> <b>".$ctr[$j][1]." details</b><br><u>ATC Name:</u> $atcnome<br><u>Frequency:</u> $freqcorta<br><u>Facility type:</u> $descriz".$atistxt."');\" onmouseout=\"return nd();\">Details</a></td></tr>";
}
echo "</table>";
}


?>

 

At a quick glance it looks like the ZME code has way more error handling...

the second one has the data fiel fetching code which might be useful if you don't already have it...

 

Any ideas or additions are very welcome

Luca Benelli - C3 - P2

Link to comment
Share on other sites

Rahul Parkar
Posted
Posted

Yeah, The error handling left by my predecessor was amazing, Edited stuff that was necessary and really just used the least amount of code as possible

 

Cheers!

Rahul

Rahul Parkar

"On second thoughts Nappa, catch it, catch it with your teeth" -- Vegeta

Professional Nerd. (Professionally not professional)

Link to comment
Share on other sites

Luca Benelli
Posted
Posted

Thanks for sharing it

Luca Benelli - C3 - P2

Link to comment
Share on other sites

Luke Kolin
Posted
Posted

Crazy question, but what happens if little Bobby Tables is a controller? Don't you want to use mysql_real_escape_string or a prepared statement? I'm not a PHP coder, but I am curious.

 

Cheers!

 

Luke

... I spawn hundreds of children a day. They are daemons because they are easier to kill. The first four remain stubbornly alive despite my (and their) best efforts.

... Normal in my household makes you a member of a visible minority.

Link to comment
Share on other sites

Rahul Parkar
Posted
Posted

Hey Luke,

 

Is that question directed to myself of Luca?? The code I posted looks for CID not name

 

Cheers!

Rahul

Rahul Parkar

"On second thoughts Nappa, catch it, catch it with your teeth" -- Vegeta

Professional Nerd. (Professionally not professional)

Link to comment
Share on other sites

Rahul Parkar
Posted
Posted

Righty-O...

 

I found some more Hand me down code... This code is all duck-taped together but I believe the original props go to Gerry Hattendorf... With a lot of edits along the way... xD

 

First file : Name - "datafeed.php"

 

<?php
include('/path/to/file/df_functions.php');
$local_file = '/path/to/file/datafeed.txt';
if (!connect_to_db()) exit(1);
$streamupdate = get_data_feed($local_file);
if (!$streamupdate) exit(2);
$file = file($local_file);
$in_client_section = FALSE;
mysql_query('DELETE FROM atc_online');
mysql_query('DELETE FROM pilotos_online');
foreach($file as $record) {
if($in_client_section && substr($record, 0, 1) == ';') {
	$in_client_section = FALSE;
}
if($in_client_section) {
	$data_record = explode(':', $record);
	if (is_ZBW_controller($data_record)) {
		save_controller_stats($data_record, $streamupdate);
	} elseif (is_ZBW_pilot($data_record)) {
		save_pilot_online($data_record);
	}
}
if(substr($record, 0, 8) == '!CLIENTS') {
	$in_client_section = TRUE;
}
}
$zulu = date('H:i:s',time()-date('Z')) . 'z';
mysql_query("UPDATE last_update SET time = '$zulu'");
?>

 

Second File - "df_functions.php"

<?php
/**
* This file contains a set of functions to support the ZBW processes for:
*
*    - controller stats (saved in MySQL table controller_log
*    - who is online (saved in tables atc_online and pilotos_online)
*
*/

/*
* General information about the data feed file:
*
* Client records are available in the data feed file for pilots and ATC.
* Each client record contains 41 fields separated by colon ":" character
* (shown here with field offset number relative to zero)
*
*     [0] callsign                  [21] planned_flighttype
*     [1] cid                       [22] planned_deptime
*     [2] realname                  [23] planned_actdeptime
*     [3] clienttype                [24] planned_hrsenroute
*     [4] frequency                 [25] planned_minenroute
*     [5] latitude                  [26] planned_hrsfuel
*     [6] longitude                 [27] planned_minfuel
*     [7] altitude                  [28] planned_altairport
*     [8] groundspeed               [29] planned_remarks
*     [9] planned_aircraft          [30] planned_route
*    [10] planned_tascruise         [31] planned_depairport_lat
*    [11] planned_depairport        [32] planned_depairport_lon
*    [12] planned_altitude          [33] planned_destairport_lat
*    [13] planned_destairport       [34] planned_destairport_lon
*    [14] server                    [35] atis_message
*    [15] protrevision              [36] time_last_atis_received
*    [16] rating                    [37] time_logon (format yyyymmddhhmmss)
*    [17] transponder               [38] heading
*    [18] facilitytype              [39] QNH_iHg
*    [19] visualrange               [40] QNH_Mb
*    [20] planned_revision
*/

/**
* function connect_to_db()
*
* Creates a connection to MySQL and selects the ZBW database
*
* Arguments:
*    none
*
* Returns:
*    The MySQL link identifier, or FALSE if failure
*
*/
function connect_to_db() {
$mysql_link = mysql_connect('localhost','my_database_username','my_database_p[Mod - Happy Thoughts]word');
if ($mysql_link === FALSE) {
	df_log_error('ERROR: Connection to MySQL database failed: ' . mysql_error());
} else {
	if (!mysql_select_db('eaglesfm_ZBW')) {
		df_log_error('ERROR: Could not select (use) the database: ' . mysql_error());
		mysql_close();
		$mysql_link = FALSE;
	}
}
return $mysql_link;
}

/**
* function get_data_feed($local_file_name)
*
* Retrieves the vatsim data feed from a data server. Usually multiple data
* feed servers are available, so this function will try them in random order
* as recommended by vatsim administrators to "spread the load".
*
* Arguments:
*    $local_file_name  -  the file path to the location where the data file
*                         should be stored locally
*
* Returns:
*    The data update time (yyyymmddhhmmss) if the file is successfully retrieved,
*    otherwise FALSE
*
*/
function get_data_feed($local_file_name) {
$data_update_time = FALSE;
$servers = array();
$server_status_feed = 'http://usa-s1.vatsim.net/data/status.txt';
$local_server_file = '/path/to/file/servers.txt';
if (date('i') < 2 || !is_file($local_server_file)) {
	copy($server_status_feed, $local_server_file);
}
$server_file = file($local_server_file);
foreach($server_file as $server_record) {
	if (substr($server_record, 0, 5) == 'url0=') {
		$servers[] = rtrim(substr($server_record, 5));
	}
}
if (empty($servers)) {
	df_log_error("ERROR: there are no data feeds available!");
} else {
	if (!shuffle($servers)) df_log_error('WARNING: the random shuffle for the server list failed');
	foreach($servers as $source_feed) {
		if (copy($source_feed, $local_file_name)) {
			$data_file = file($local_file_name);
			/*
			 * We want to confirm that the data in the file is recently updated.
			 */
			foreach($data_file as $data_record) {
				if (substr($data_record, 0, 9) == 'UPDATE = ') {
					$streamupdate = rtrim(substr($data_record, 9));
					$update_time = gmmktime(
							substr($streamupdate,8,2),
							substr($streamupdate,10,2),
							substr($streamupdate,12,2),
							substr($streamupdate,4,2),
							substr($streamupdate,6,2),
							substr($streamupdate,0,4));
					break;
				}
			}
			/*
			if (!$streamupdate) {
				df_log_error('ERROR: Did not find a value for the data feed file update timestamp (UPDATE = )');
			}
			 */
			$age = time() - $update_time;
			if ($age < 600) {
				$data_update_time = $streamupdate;
				break;
			/* } else {
				df_log_error("WARNING: age for $source_feed is $age seconds (from $streamupdate)");
			 */
			}
		/*
		} else {
			df_log_error("WARNING: failed to download vatsim data feed from $source_feed");
		 */
		}
	}
}
if (!$data_update_time) df_log_error("ERROR: did not successfully download from any of the data feeds!");
return $data_update_time;
}

/**
* function get_facilities()
*
* Builds an array containing the 3-character code for ZBW facilities used
* Builds an array containing the 4-character code for Non-US facilities used
* in callsigns
*
* Arguments:
*    none
*
* Returns:
*    Array of 3-character codes for all ZBW facilities used in callsigns
*    Array of 4-character codes for all FIR facilities used in callsigns (Only for use in Non-US situations)
*
*/
function get_facilities() {
$prefixes = array(
		/* BRAVO */
		'SFO',
		/* CHARLIE */
		'OAK', 'FAT', 'MRY', 'BAB', 'RNO', 'SJC', 'SMF',
		/* DELTA */
		'APC', 'CCR', 'CIC', 'HWD', 'LVK', 'MHR', 'MER', 'MOD', 'NFL', 'NLC',
		'NUQ', 'PAO', 'RDD', 'RHV', 'SAC', 'SCK', 'SNS', 'SQL', 'STS', 'SUU' );
return $prefixes;
}

/**
* function is_ZBW_controller()
*
* Determines whether a record from the vatsim data feed is a ZBW controller online
*
* Arguments:
*    $data_record  =  array containing the vatsim data feed record (client record type)
*
* Returns:
*    TRUE if this is an ATC record for a valid ZBW controller position, otherwise FALSE
*
*/
function is_ZBW_controller($data_record) {
   $ZBW_match = FALSE;
if($data_record[3] == 'ATC' && $data_record[16] != '1' && $data_record[18] != '0' && stristr($data_record[0],'OBS') === FALSE) {
    $prefixes = get_facilities();
	for($a = 0; $a < count($prefixes); $a++) {
		if(($prefixes[$a] . '_') == substr($data_record[0], 0, 4)) {
			$ZBW_match = TRUE;
			break;
		}
	}
}
return $ZBW_match;
}

/**
* function is_ZBW_pilot()
*
* Determines whether a record from the vatsim data feed is a pilot flying to/from ZBW
*
* Arguments:
*    $data_record  =  array containing the vatsim data feed record (client record type)
*
* Returns:
*    TRUE if this is a pilot record for a flight to/from ZBW, otherwise FALSE
*
*/
function is_ZBW_pilot($data_record) {
   $ZBW_match = FALSE;
if ($data_record[3] == 'PILOT' and $data_record[11] != '' and $data_record[13] != '') {
	$result = mysql_query("SELECT icao FROM icaos WHERE icao = '$data_record[11]' OR icao = '$data_record[13]' ");
	if (mysql_num_rows($result) > 0) $ZBW_match = TRUE;
}
return $ZBW_match;
}

/**
* function save_controller_stats()
*
* Saves to the database a matched atc client record from the vatsim data feed.
* This updates both the individual controllers' stats in the controller_log table,
* as well as the atc_online table.
*
* Arguments:
*    $atc_array     -  array holding all of the fields from the vatsim data feed (ATC record)
*    $streamupdate  -  the update datetime value from the vatsim data feed file header
*
* Returns:
*    none
*
*/
function save_controller_stats($atc_array, $streamupdate) {
$position  = $atc_array[0];
$cid       = $atc_array[1];
$realname  = $atc_array[2];
$frequency = $atc_array[4];
$rating    = $atc_array[16];
$starttimestamp = gmmktime(substr($atc_array[37], 8, 2), substr($atc_array[37], 10, 2), substr($atc_array[37], 12, 2), substr($atc_array[37], 4, 2), substr($atc_array[37], 6, 2), substr($atc_array[37], 0, 4));
$date = date("n/j/y");
$duration = time() - $starttimestamp;
$lastsession = mysql_query("SELECT id, start, streamupdate FROM controller_log WHERE cid = '$cid' ORDER BY start DESC");
$row = mysql_fetch_array($lastsession);

if($streamupdate != $row["streamupdate"]) {
	if(($row['start'] != $starttimestamp) || !mysql_num_rows($lastsession)) {
		mysql_query("INSERT INTO controller_log (cid, date, start, duration, position, streamupdate) VALUES ('$cid', '$date', '$starttimestamp', '$duration', '$position', '$streamupdate')");
	} else {
		$id = $row["id"];
		mysql_query("UPDATE controller_log SET duration = '$duration', streamupdate = '$streamupdate' WHERE id = '$id'");
	}
}
mysql_query("INSERT INTO atc_online (atc, freq, name, rango, atis) VALUES ('$position','$frequency','$realname','$rating','no atis available') ");
}

/**
* function save_pilot_online()
*
* Saves to the database a matched pilot client record from the vatsim data feed.
* This inserts a row into the pilotos_online table.
*
* Arguments:
*    $pilot_array  -  array holding all of the fields from the vatsim data feed (pilot record)
*
* Returns:
*    none
*
*/
function save_pilot_online($pilot_array) {
$position  = $pilot_array[0];
$realname  = $pilot_array[2];
$depart    = $pilot_array[11];
$dest      = $pilot_array[13];
mysql_query("INSERT INTO pilotos_online (callsign, icao1, icao2, name) VALUES ('$position','$depart','$dest','$realname') ");
}

/**
* function df_log_error()
*
* Logs an error message.
*
* Arguments:
*    $message
*
* Returns:
*    none
*
*/
function df_log_error($message) {
$log_path = '/path/to/file/stats_error_log';
$fmt_msg = '[' . date('Y.m.d.H:i:s') . '] ' . $message . "\n";
error_log($fmt_msg,3,$log_path);
// echo $fmt_msg;
}

?>

 

Third File - "df_monitor.php"

<?php
include('/path/to/file/df_functions.php');
$errors = '';
$servers_file = '/path/to/file/servers.txt';
$datafeed_file = '/path/to/file/datafeed.txt';
$error_log_file = '/path/to/file/stats_error_log';
$mail_to = '[email protected]';
$mail_from = '[email protected]';
if (file_exists($servers_file)) {
$updated = filemtime($servers_file);
$age = time() - $updated;
if ($age > 7200) {
	$fmt_date = date('Y-m-d H:i:s T', $updated);
	$errors .= "The VATSIM servers status file has not been updated since $fmt_date.\n";
}
} else {
$errors .= "The VATSIM servers status file $servers_file was not found.\n";
}
if (file_exists($datafeed_file)) {
$updated = filemtime($datafeed_file);
$age = time() - $updated;
if ($age > 600) {
	$fmt_date = date('Y-m-d H:i:s T', $updated);
	$errors .= "The VATSIM data feed file has not been updated since $fmt_date.\n";
}
$streamupdate = 0;
$file = file($datafeed_file);
foreach($file as $record) {
	if (substr($record, 0, 9) == 'UPDATE = ') {
		$streamupdate = rtrim(substr($record, 9));
		$update_time = gmmktime(
				substr($streamupdate,8,2),
				substr($streamupdate,10,2),
				substr($streamupdate,12,2),
				substr($streamupdate,4,2),
				substr($streamupdate,6,2),
				substr($streamupdate,0,4));
		break;
	}
}
$age = time() - $update_time;
if ($age > 600) {
	$fmt_date = date('Y-m-d H:i:s T', $update_time);
	$errors .= "The VATSIM data feed contains data was last generated $fmt_date.\n";
	$errors .= "streamupdate = $streamupdate, record -> $record\n";
}
} else {
$errors .= "The VATSIM data feed file $datafeed_file was not found.\n";
}
if (file_exists($error_log_file)) {
$errors .= "There is an error log file created at $error_log_file.\n";
}
if (!empty($errors)) {
mail($mail_to,
		"Errors detected for ZBW data feed!",
		"The data feed monitor program has detected potential errors:\n\n$errors\n",
		"From: ARTCC Datafeed Checker <$mail_from>\r\nReply-To: $mail_from\r\n");
}
?>

 

Please don't hesitate to shoot me a PM for any help, especially if I messed something up along the way

 

Cheers!

Rahul

Rahul Parkar

"On second thoughts Nappa, catch it, catch it with your teeth" -- Vegeta

Professional Nerd. (Professionally not professional)

Link to comment
Share on other sites

Rahul Parkar
Posted
Posted

Forgot the SQL Code to go with it

 

Replace the Values for the icaos table as needed

 

--
-- Table structure for table `atc_online`
--

CREATE TABLE IF NOT EXISTS `atc_online` (
 `id` int(10) NOT NULL AUTO_INCREMENT,
 `atc` varchar(10) NOT NULL DEFAULT '',
 `freq` varchar(20) NOT NULL DEFAULT '',
 `name` varchar(50) NOT NULL DEFAULT '',
 `rango` varchar(30) NOT NULL DEFAULT '',
 `atis` text NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CH[Mod - Happy Thoughts]T=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `atc_online`
--


-- --------------------------------------------------------

--
-- Table structure for table `controller_log`
--

CREATE TABLE IF NOT EXISTS `controller_log` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `cid` varchar(7) NOT NULL DEFAULT '',
 `date` varchar(10) NOT NULL DEFAULT '',
 `start` int(11) NOT NULL DEFAULT '0',
 `duration` int(11) NOT NULL DEFAULT '0',
 `position` varchar(11) NOT NULL DEFAULT '',
 `streamupdate` varchar(30) NOT NULL DEFAULT '',
 PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CH[Mod - Happy Thoughts]T=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `controller_log`
--


-- --------------------------------------------------------

--
-- Table structure for table `icaos`
--

CREATE TABLE IF NOT EXISTS `icaos` (
 `id` int(10) NOT NULL AUTO_INCREMENT,
 `icao` varchar(10) NOT NULL DEFAULT '',
 PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CH[Mod - Happy Thoughts]T=latin1 AUTO_INCREMENT=79 ;

--
-- Dumping data for table `icaos`
--

INSERT INTO `icaos` (`id`, `icao`) VALUES
(1, 'KSFO'),
(2, 'KOAK'),
(3, 'KSJC'),
(4, 'KSMF'),
(5, 'KRNO'),
(6, 'KFAT'),
(7, 'KMRY'),
(8, 'KAPC'),
(9, 'KCCR'),
(10, 'KCIC'),
(11, 'KHWD'),
(12, 'KLVK'),
(13, 'KMHR'),
(14, 'KMOD'),
(15, 'KPAO'),
(16, 'KRDD'),
(17, 'KRHV'),
(18, 'KSAC'),
(19, 'KSCK'),
(20, 'KSNS'),
(21, 'KSQL'),
(22, 'KSTS'),
(23, 'KMMH'),
(24, 'KMYV'),
(25, 'KMCE'),
(26, 'KPRB'),
(27, 'KRBL'),
(28, 'KTVL'),
(29, 'KUKI'),
(30, 'KVIS'),
(31, 'KAUN'),
(32, 'KBIH'),
(33, 'KCPU'),
(34, 'KDVO'),
(35, 'KFCH'),
(36, 'KFLX'),
(37, 'KHAF'),
(38, 'KHJO'),
(39, 'KLHM'),
(40, 'KLSN'),
(41, 'KMAE'),
(42, 'KMCC'),
(43, 'KMER'),
(44, 'KMEV'),
(45, 'KOAR'),
(46, 'KOVE'),
(47, 'KPVF'),
(48, 'KTCY'),
(49, 'KTLR'),
(50, 'KTRK'),
(51, 'KVCB'),
(52, 'KWLW'),
(53, 'KWVI'),
(54, '0O5'),
(55, '1O2'),
(56, '1O3'),
(57, '2Q3'),
(58, '3O7'),
(59, '4SD'),
(60, 'C83'),
(61, 'O08'),
(62, 'O17'),
(63, 'O22'),
(64, 'O27'),
(65, 'O28'),
(66, 'O37'),
(67, 'O41'),
(68, 'O69'),
(69, 'O70'),
(70, 'O88'),
(71, 'Q49'),
(72, 'Q68'),
(73, 'Q99'),
(74, 'KBAB'),
(75, 'KNFL'),
(76, 'KNLC'),
(77, 'KNUQ'),
(78, 'KSUU');

-- --------------------------------------------------------

--
-- Table structure for table `last_update`
--

CREATE TABLE IF NOT EXISTS `last_update` (
 `time` varchar(50) NOT NULL DEFAULT ''
) ENGINE=MyISAM DEFAULT CH[Mod - Happy Thoughts]T=latin1;

--
-- Dumping data for table `last_update`
--

INSERT INTO `last_update` (`time`) VALUES
('01:01:01z');

-- --------------------------------------------------------

--
-- Table structure for table `pilotos_online`
--

CREATE TABLE IF NOT EXISTS `pilotos_online` (
 `id` int(10) NOT NULL AUTO_INCREMENT,
 `callsign` varchar(15) NOT NULL DEFAULT '',
 `icao1` varchar(4) NOT NULL DEFAULT '',
 `icao2` varchar(4) NOT NULL DEFAULT '',
 `name` varchar(30) NOT NULL DEFAULT '',
 PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CH[Mod - Happy Thoughts]T=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `pilotos_online`
--

 

Cheers!

Rahul

Rahul Parkar

"On second thoughts Nappa, catch it, catch it with your teeth" -- Vegeta

Professional Nerd. (Professionally not professional)

Link to comment
Share on other sites

Rahul Parkar
Posted
Posted (edited)

Double Post

 

Cheers!

Rahul

Edited by Guest

Rahul Parkar

"On second thoughts Nappa, catch it, catch it with your teeth" -- Vegeta

Professional Nerd. (Professionally not professional)

Link to comment
Share on other sites

Luke Kolin
Posted
Posted
Is that question directed to myself of Luca?? The code I posted looks for CID not name

 

Are you p[Mod - Happy Thoughts]ing any data from an external source directly into your SQL statements without escaping?

 

Cheers!

 

Luke

... I spawn hundreds of children a day. They are daemons because they are easier to kill. The first four remain stubbornly alive despite my (and their) best efforts.

... Normal in my household makes you a member of a visible minority.

Link to comment
Share on other sites

Luca Benelli
Posted
Posted
Crazy question, but what happens if little Bobby Tables is a controller? Don't you want to use mysql_real_escape_string or a prepared statement? I'm not a PHP coder, but I am curious.

 

Cheers!

 

Luke

 

I think i missed the point of the question...

 

We are looking for callsigns which have some particular form. The users name is reported as it is fetched from the data feed (which should be already mysql_safe, but we shouldn't rely on this).

 

Considering the first script which takes data from a mysql table it would be the feed reader which has to make sure that the data is mysql-safe not this script which uses the data nas there is no user provided data... or did i really miss something in your question?

 

Luca

Luca Benelli - C3 - P2

Link to comment
Share on other sites

Rahul Parkar
Posted
Posted

Luke,

 

To answer your question, I am p[Mod - Happy Thoughts]ing the CID No. into the SQL Statement without escaping or needing to escape it .

 

Cheers!

Rahul

Rahul Parkar

"On second thoughts Nappa, catch it, catch it with your teeth" -- Vegeta

Professional Nerd. (Professionally not professional)

Link to comment
Share on other sites

Luke Kolin
Posted
Posted
To answer your question, I am p[Mod - Happy Thoughts]ing the CID No. into the SQL Statement without escaping or needing to escape it .

 

Ah. Good luck!

 

Cheers!

 

Luke

... I spawn hundreds of children a day. They are daemons because they are easier to kill. The first four remain stubbornly alive despite my (and their) best efforts.

... Normal in my household makes you a member of a visible minority.

Link to comment
Share on other sites

Rahul Parkar
Posted
Posted

Thanks Luke!

 

If you want my *Special* reasoning as to why I don't escape it, feel free to PM me

 

Cheers!

Rahul

Rahul Parkar

"On second thoughts Nappa, catch it, catch it with your teeth" -- Vegeta

Professional Nerd. (Professionally not professional)

Link to comment
Share on other sites

Luke Kolin
Posted
Posted
If you want my *Special* reasoning as to why I don't escape it, feel free to PM me

 

I'm game. Why?

 

Cheers!

 

Luke

... I spawn hundreds of children a day. They are daemons because they are easier to kill. The first four remain stubbornly alive despite my (and their) best efforts.

... Normal in my household makes you a member of a visible minority.

Link to comment
Share on other sites

Rahul Parkar
Posted
Posted

Seeing as my explanation was sort of Long winded, and went into our e-mail conversation there Luke... We'll leave that question there

 

If anybody else want's the very boring very long-winded explanation put together by your "Resident Idiot" Please feel free to ask away.. I'm more then happy to answer your questions.

 

Cheers!

Rahul

Rahul Parkar

"On second thoughts Nappa, catch it, catch it with your teeth" -- Vegeta

Professional Nerd. (Professionally not professional)

Link to comment
Share on other sites

Gerry Hattendorf 935415
Posted
Posted

Hmmm, that code looks familiar! Any idea who the predessor is?

Gerry Hattendorf

ZLA Webmaster

VATSIM Supervisor

Link to comment
Share on other sites

John Cierpial 1008209
Posted
Posted
Righty-O...

 

I found some more Hand me down code... This code is all duck-taped together but I believe the original props go to Gerry Hattendorf... With a lot of edits along the way... xD

 

I think he does

CTP Planning Team Member

Link to comment
Share on other sites

Rahul Parkar
Posted
Posted

Hehe.

 

I'm sure it isn't Gerry's LOL. Before the duck-taping.

 

Cheers!

Rahul

Rahul Parkar

"On second thoughts Nappa, catch it, catch it with your teeth" -- Vegeta

Professional Nerd. (Professionally not professional)

Link to comment
Share on other sites

Gerry Hattendorf 935415
Posted
Posted
Hehe.

 

I'm sure it isn't Gerry's LOL. Before the duck-taping.

 

Cheers!

Rahul

 

LOL, I'm just messing with your head Rahul! I'm a strong beliver of the "mysql_real_escape_string" function for anything that touches my database and recommed you use it even with internal scripts. The tiny bit of overhead it takes is good insurance you won't have to perform restore functions on your database in the wee hours of the morning!

 

Cheers!

Gerry Hattendorf

ZLA Webmaster

VATSIM Supervisor

Link to comment
Share on other sites

  • 8 months later...
Ahmed Radwan
Posted
Posted

Thanks for the great help Luca! I'm trying to use the VATITA script but I got that error:

 

Warning: fopen() [function.fopen]: Filename cannot be empty in /path/online.php on line 70

 

Any idea how I could overcome this?

AHMED RADWAN
Deputy Director
##  [email protected]   
##  www.vatme.net
    
     Signature.png.ebeb12713b17feaba5b97c3b8a413f39.png

 

 

 

 

Link to comment
Share on other sites

Luca Benelli
Posted
Posted

What is on line 70 ? any variables? and their content?

Luca Benelli - C3 - P2

Link to comment
Share on other sites

Ahmed Radwan
Posted
Posted

In:

 

// Here we look at the time when the datafile was generated...

$datamodtime=filemtime("path/vatsim-data.txt");
$now=time();
$etadata=$now-$datamodtime;
if ($etadata >= $tempomaxdata) {
  $dataremote=fopen($remotedatafilename,"rb");
  if ($dataremote==NULL) {
  } else {
     $datalocal=fopen("path/vatsim-data.txt","w");
     if (!$datalocal){
        fclose ($dataremote);
     } else {
        while (strlen($data = fgets($dataremote, 1024)) != 0 ){
           fwrite($datalocal,$data);
        }
     }
  }
}

 

Line 70 is:

$dataremote=fopen($remotedatafilename,"rb");

AHMED RADWAN
Deputy Director
##  [email protected]   
##  www.vatme.net
    
     Signature.png.ebeb12713b17feaba5b97c3b8a413f39.png

 

 

 

 

Link to comment
Share on other sites

Luke Kolin
Posted
Posted

Sounds like it's telling you that remotedatafilename is empty.

 

Cheers!

 

Luke

... I spawn hundreds of children a day. They are daemons because they are easier to kill. The first four remain stubbornly alive despite my (and their) best efforts.

... Normal in my household makes you a member of a visible minority.

Link to comment
Share on other sites

Ahmed Radwan
Posted
Posted
Sounds like it's telling you that remotedatafilename is empty.

 

Cheers!

 

Luke

 

The thing is, it is not :/

AHMED RADWAN
Deputy Director
##  [email protected]   
##  www.vatme.net
    
     Signature.png.ebeb12713b17feaba5b97c3b8a413f39.png

 

 

 

 

Link to comment
Share on other sites

Daniel Hawton
Posted
Posted

Paste the code to a paste bin type service and post it here. Bet you anyone would be willing to look through it and/or run it locally to help find the exact cause.

Link to comment
Share on other sites

 Share