Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
manolis committed Jan 5, 2007
1 parent 00de0e5 commit 33d6647
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 31 deletions.
84 changes: 75 additions & 9 deletions CL_server.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Server {
var $isLeo ;
var $installation_type;
var $leonardo_version;
var $url;
var $url_base;
var $url_op;
var $admin_email;
Expand All @@ -33,7 +34,7 @@ function Server($id="") {
if ($id!="") {
$this->ID=$id;
}
$this->valuesArray=array("ID","isLeo","installation_type","leonardo_version","url_base",
$this->valuesArray=array("ID","isLeo","installation_type","leonardo_version","url", "url_base",
"url_op","admin_email","site_pass","is_active","gives_waypoints","waypoint_countries"
);
$this->gotValues=0;
Expand All @@ -47,10 +48,11 @@ function version() {
}

function findTakeoff($lat,$lon) {
require_once dirname(__FILE__)."/CL_gpsPoint.php";
list($version,$sub_version,$revision)=$this->version();
if ($version>=2) { // new rpc method
require_once dirname(__FILE__)."/lib/xml_rpc/IXR_Library.inc.php";
require_once dirname(__FILE__)."/CL_gpsPoint.php";

$serverURL="http://".$this->url_op;
$client = new IXR_Client($serverURL);
// $client->debug=true;
Expand All @@ -59,20 +61,84 @@ function findTakeoff($lat,$lon) {
echo 'findTakeoff: Error '.$client->getErrorCode()." -> ".$client->getErrorMessage();
return array(0,-1); // $client->getErrorCode();
} else {
$nearestWaypoint=new waypoint();
$nearestWaypoint=new gpsPoint();
list($nearestWaypoint,$minTakeoffDistance)= $client->getResponse();
echo "^".$nearestWaypoint->name;
list( $nearestWaypoint,$minTakeoffDistance)= $client->getResponse();
$nearestWaypoint=(object) $nearestWaypoint;
return array($nearestWaypoint,$minTakeoffDistance);
}


} else {


} else if ($version==1 && $sub_version >=4) { // use EXT_takeoff.php method
require_once dirname(__FILE__)."/FN_functions.php";
$serverURL="http://".$this->url_base."/EXT_takeoff.php?op=find_wpt&lat=$lat&lon=$lon";
$contents=fetchURL($serverURL);
if (!$contents) {
echo "SERVER at: ".$this->url_base." is NOT ACTIVE<br>";
return array(0,-1);
}

require_once dirname(__FILE__).'/lib/miniXML/minixml.inc.php';
$xmlDoc = new MiniXMLDoc();
$xmlDoc->fromString($contents);
$xmlArray=$xmlDoc->toArray();

$wpt=new waypoint();

$wpt->waypointID=$xmlArray[search][waypoint][name];
$wpt->name =$xmlArray[search][waypoint][name];
$wpt->intName =$xmlArray[search][waypoint][intName];
$wpt->location =$xmlArray[search][waypoint][location];
$wpt->intLocation=$xmlArray[search][waypoint][intLocation];
$wpt->type =$xmlArray[search][waypoint][type];
$wpt->countryCode=$xmlArray[search][waypoint][countryCode];
$wpt->lat =$xmlArray[search][waypoint][lat];
$wpt->lon =$xmlArray[search][waypoint][lon];
$wpt->link =$xmlArray[search][waypoint][link];
$wpt->description=$xmlArray[search][waypoint][description];
$wpt->modifyDate=$xmlArray[search][waypoint][modifyDate];

$distance=$xmlArray[search][distance];

return array($wpt,$distance);
} else if ( $version==0 && !$this->isLeo ) { // we are dealing with 'alien' servers
require_once dirname(__FILE__)."/FN_functions.php";
//the installation_type in this case point to the ID of the alien server
$takeoffsList=getExtrernalServerTakeoffs($this->installation_type,$lat,$lon,1000,1);
$wpt=new waypoint();
$distance=$takeoffsList[0]['distance'];

$wpt->intName=$takeoffsList[0]['name'];
$wpt->name=$takeoffsList[0]['name'];
$wpt->location=$takeoffsList[0]['area'];
$wpt->intLocation=$takeoffsList[0]['area'];
$wpt->countryCode=$takeoffsList[0]['countryCode'];
$wpt->link=$takeoffsList[0]['url'];
$wpt->lat=$takeoffsList[0]['lat'];
$wpt->lon=$takeoffsList[0]['lon'];

return array($wpt,$distance);
}

}

function registerServerToMaster() {
require_once dirname(__FILE__)."/lib/xml_rpc/IXR_Library.inc.php";
$masterServer=new Server($CONF_master_server_id);
$masterServer->getFromDB();

$masterServerURL="http://".$masterServer->url_op;
$thisServerURL="http://".$this->url_op;
$client = new IXR_Client($masterServerURL);
// $client->debug=true;

if ( ! $client->query('server.registerSlave',$this->site_pass, $lat, $lon ) ) {
echo 'registerSlave: Error '.$client->getErrorCode()." -> ".$client->getErrorMessage();
return 0; // $client->getErrorCode();
} else {
$newServerID= $client->getResponse();
return $newServerID;
}
}

function getServers() {
global $db,$serversTable;
$res= $db->sql_query("SELECT * FROM $serversTable order BY ID");
Expand Down
27 changes: 14 additions & 13 deletions FN_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@ function getExtrernalServerTakeoffs($serverID,$lat,$lon,$limitKm,$limitNum ) {
$arrayToUse=0;
}

$takoffsList=array();
$takeoffsList=array();
$takeoffsNum=0;
if ($arrayToUse) {
//echo "#";
//print_r($arrayToUse);
//echo "#";
//print_r($arrayToUse);
foreach ($arrayToUse as $flightareaNum=>$flightarea) {
$XML_name=$takeoffServers[$serverID]["XML_name"];
$XML_distance=$takeoffServers[$serverID]["XML_distance"];
Expand All @@ -415,22 +415,23 @@ function getExtrernalServerTakeoffs($serverID,$lat,$lon,$limitKm,$limitNum ) {
$XML_url=$takeoffServers[$serverID]["XML_url"];
$XML_lat=$takeoffServers[$serverID]["XML_lat"];
$XML_lon=$takeoffServers[$serverID]["XML_lon"];
if ( $flightareaNum!=="_num" && $flightarea[$XML_name]) {
if ( $flightareaNum!=="_num" && $flightarea[$XML_name]) {
$distance=$flightarea[$XML_distance];
if ($distance>$limitKm*10000) continue;
$takoffsList[$takeoffsNum]['distance']=$flightarea[$XML_distance];
$takoffsList[$takeoffsNum]['name']=$flightarea[$XML_name];
$takoffsList[$takeoffsNum]['area']=$flightarea[$XML_area];
$takoffsList[$takeoffsNum]['countryCode']=$flightarea[$XML_countryCode];
$takoffsList[$takeoffsNum]['url']=$flightarea[$XML_url];
$takoffsList[$takeoffsNum]['lat']=$flightarea[$XML_lat];
$takoffsList[$takeoffsNum]['lon']=$flightarea[$XML_lon];
if ($distance>$limitKm*1000) continue;
$takeoffsList[$takeoffsNum]['distance']=$flightarea[$XML_distance];
$takeoffsList[$takeoffsNum]['name']=$flightarea[$XML_name];
$takeoffsList[$takeoffsNum]['area']=$flightarea[$XML_area];
$takeoffsList[$takeoffsNum]['countryCode']=$flightarea[$XML_countryCode];
$takeoffsList[$takeoffsNum]['url']=$flightarea[$XML_url];
$takeoffsList[$takeoffsNum]['lat']=$flightarea[$XML_lat];
$takeoffsList[$takeoffsNum]['lon']=$flightarea[$XML_lon];
$takeoffsNum++;
if ($takeoffsNum==$limitNum) break;
}
}
}
return $takoffsList;

return $takeoffsList;
} // if we have content
return array();

Expand Down
2 changes: 1 addition & 1 deletion FN_waypoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,4 @@ function makeWaypointPlacemark($waypointID,$returnCountryCode=0) {
} else return $xml_text;

}
?>
?>
2 changes: 1 addition & 1 deletion GUI_EXT_server_action.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
echo $server->url_op;
echo "<BR>$action<br>";

list($nearestWaypoint,$minTakeoffDistance)=$server->findTakeoff(30,30);
list($nearestWaypoint,$minTakeoffDistance)=$server->findTakeoff(40,22);
echo "wpt: ".$nearestWaypoint->intName. "~ $minTakeoffDistance<BR>";


Expand Down
2 changes: 1 addition & 1 deletion GUI_servers_manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function serverAction(id,action) {
if ( $server->waypoint_countries ) $wpt.=" (".$server->waypoint_countries.")";
} else $wpt="NO";

$url="<a href='".$server->url_base."' target='_blank'>".substr($server->url_base,0,50)."...</a>";
$url="<a href='http://".$server->url."' target='_blank'>".substr($server->url_base,0,50)."...</a>";

echo "<TR><td><a href='javascript:serverAction(".$server->ID.",1);'>Info</a> :: <a href='javascript:serverAction(".$server->ID.",2);'>Takeoffs</a> :: <a href='javascript:serverAction(".$server->ID.",3);'>Flights</a></td>".
"<td>".$server->ID."</td><td>".$url."</td><td>".$server->leonardo_version."</td><td>".
Expand Down
6 changes: 6 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
// 3 = standalone -- still work in progress
$opMode= 2;

// Here we define which server Id is the master server of the leonardo Network
$CONF_master_server_id=1;

// Our server ID -> usually 0 for non network operation
$CONF_server_id=0;

// if it is a phpbb module we can use our own template
// and not the onw of the forum
$CONF_use_own_template=1;
Expand Down
2 changes: 2 additions & 0 deletions doc/install/upgrade_1.6.01_1.7.01/upgrade_1.6.01_1.7.01.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ ALTER TABLE `leonardo_servers` ADD `leonardo_version` VARCHAR( 20 ) NOT NULL AFT

ALTER TABLE `leonardo_servers` CHANGE `type` `installation_type` SMALLINT UNSIGNED NOT NULL DEFAULT '2';

ALTER TABLE `leonardo_servers` ADD `url` VARCHAR( 255 ) NOT NULL AFTER `leonardo_version` ;

57 changes: 51 additions & 6 deletions op.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ function securityCheck($sitePass) {
return 1;
}

function flights_count($arg) {
global $db,$flightsTable;
$sitePass=$arg[0];
$from_tm=$arg[1];
$limit= $arg[2];

if ( ! securityCheck($sitePass) ) return new IXR_Error(4000, 'Access Denied');;

$where_clause="AND dateAdded >= FROM_UNIXTIME(".$tm.") ";

if ($limit) $lim=" LIMIT 1,$limit ";
else $lim="";

$query="SELECT count() as flights_num FROM $flightsTable WHERE private=0 $where_clause ORDER BY dateAdded DESC $lim ";
//echo $query;
$res= $db->sql_query($query);
if($res <= 0) return new IXR_Error(4000, 'Error in query! '.$query);

$row = mysql_fetch_assoc($res);
$flights_num=$row['flights_num'];
return $flights_num;
}

function flights_find($arg) {
global $db,$flightsTable;
global $baseInstallationPath,$module_name,$takeoffRadious;
Expand Down Expand Up @@ -160,6 +183,11 @@ function flights_find($arg) {

}


// this runs on the master so that slaves can upload flights
// !!!!!!!!!!!!!!!!!!!!!!!!!!!
// more security needed!!!!!!!!!!!!!!!!!!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!
function flights_submit($args) {
require_once dirname(__FILE__)."/FN_flight.php";

Expand Down Expand Up @@ -217,15 +245,15 @@ function flights_submit($args) {

}


// this runs on the slave servers so that the master can upload updates
function uploadFile($arg) {
$sitePass=$arg[0];
$remoteFile=$arg[1];
$localFile=$arg[2];

global $CONF_SitePassword;

if ($sitePass!=$CONF_SitePassword) return new IXR_Error(4000, "Access denied");
if ( ! securityCheck($sitePass) ) return new IXR_Error(4000, 'Access Denied');;

if ( ($fileStr=@file_get_contents($remoteFile)) === FALSE)
return new IXR_Error(4001, "Cant access file ($remoteFile) to upload");
Expand All @@ -244,17 +272,32 @@ function uploadFile($arg) {
return 1;
}

function server_info($arg) {
$sitePass=$arg[0];
global $CONF_SitePassword;
global $CONF_version,$CONF_releaseDate, $opMode, $CONF_isMasterServer, $CONF_admin_email

if ( ! securityCheck($sitePass) ) return new IXR_Error(4000, 'Access Denied');;
return array($CONF_version,$CONF_releaseDate, $opMode, $CONF_isMasterServer, $CONF_admin_email);
}


// this function runs only on the Master Server to register slave servers
function registerSlave($arg) {
$installType=$arg[0];
$url=$arg[1];
$adminEmail=$arg[2];
$sitePass=$arg[3];
$leonardo_version=arg[1];
$url=$arg[2];
$url_base=$arg[3];
$url_op=$arg[4];
$adminEmail=$arg[5];
$sitePass=$arg[6];

global $CONF_isMasterServer;
if (!$CONF_isMasterServer)
return new IXR_Error(5001, "Not a Master server");

$fileStr="$installType#$url#$adminEmail#$sitePass\n";

$fileStr="$installType#$leonardo_version#$url#$adminEmail#$sitePass\n";
$filename=dirname(__FILE__)."/clientServers.txt";
if (!$handle = fopen($filename, 'a'))
return new IXR_Error(5002, "Cannot open file ($filename)");
Expand All @@ -268,11 +311,13 @@ function registerSlave($arg) {

/* Create the server and map the XML-RPC method names to the relevant functions */
$server = new IXR_Server(array(
'server.info'=>'server_info',
'server.uploadFile'=>'uploadFile',
'server.registerSlave'=>'registerSlave',
'takeoffs.findTakeoff'=>'findTakeoff',
'takeoffs.getAll'=>'takeoffs_findAll',
'flights.find'=>'flights_find',
'flights.count'=>'flights_count',
'flights.submit'=>'flights_submit',
));

Expand Down

0 comments on commit 33d6647

Please sign in to comment.