forked from leonardoxc/leonardoxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EXT_perform_sync.php
205 lines (165 loc) · 5.6 KB
/
EXT_perform_sync.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?
//************************************************************************
// Leonardo XC Server, http://www.leonardoxc.net
//
// Copyright (c) 2004-2010 by Andreadakis Manolis
//
// This program is free software. You can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License.
//
// $Id: EXT_perform_sync.php,v 1.11 2012/01/16 07:21:22 manolis Exp $
//
//************************************************************************
// modification to call thie file also from the command line,
if (count($argv) > 1 ) {
foreach($argv as $i=>$arg) {
if ($i==0) continue;
list($name,$val)=split("=",$arg);
if ($name && $val) {
// echo "$name=$val";
$_GET[$name]=$val;
}
}
}
// var_dump($argv);
require_once dirname(__FILE__)."/EXT_config_pre.php";
require_once dirname(__FILE__)."/config.php";
require_once dirname(__FILE__)."/EXT_config.php";
$pass=makeSane($_GET['pass'],0);
if ($pass != $CONF_SitePassword || ! $pass) {
return;
}
require_once dirname(__FILE__)."/CL_server.php";
require_once dirname(__FILE__)."/FN_waypoint.php";
require_once dirname(__FILE__)."/FN_functions.php";
require_once dirname(__FILE__).'/CL_brands.php';
$id=makeSane($_GET['id'],1);
$action=makeSane($_GET['action']);
$DBGlvl=makeSane($_GET['DBGlvl'],1);
$server=new Server($id);
// set to 1 for debug
if ($DBGlvl) $server->DEBUG=1;
function initHtml () {
?><head>
<style type="text/css">
body { background-color: #EDF3F1;}
body , p, table, td {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-style: normal;
text-align:left;
margin:0;
}
.ok {
font-weight:bold;
color:#00CC33;
display:inline;
}
.error {
font-weight:bold;
color:#FF3300;
display:inline;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<?
}
if ($action==1) { // server info
list($server_version,$server_releaseDate, $server_opMode,
$server_isMasterServer, $server_admin_email,
$php_version, $mysql_server_info ,$mysql_client_info )=$server->getInfo();
echo "Leonardo version: $server_version<br>
version releaseDate: $server_releaseDate<br>
opMode: $server_opMode<br>
isMasterServer: $server_isMasterServer<br>
admin_email: $server_admin_email<br>
php_version: $php_version<br>
mysql_server_info: $mysql_server_info<BR>
mysql_client_info: $mysql_client_info<BR>";
} else if ($action==2) {
$takeoffsList=$server->getTakeoffs(0); // takeoffs from time 0
echo "<HR>Takeoff list<hr>";
//print_r($takeoffsList);
foreach($takeoffsList as $takeoff){
$takeoff=(object) $takeoff;
echo "#".urldecode($takeoff->intName).
"#".urldecode($takeoff->name).
"#<BR>";
}
} else if ($action==3) { //flights
} else if ($action==4) { //send op files
$files_send=$server->sendOPfiles();
echo "Send $files_send files to slave server <BR>";
} else if ($action==5) { // sync (pull data from server )
$moduleRelPath=moduleRelPath(0);
$waypointsWebPath=$moduleRelPath."/".$waypointsRelPath;
$chunkSize=$_GET['chunkSize']+0;
if (! $chunkSize ) $chunkSize=5;
$sParts=split("/",$server->data['url']);
$serverName=$sParts[0];
// make dirs and
$logDir=dirname(__FILE__).'/site/sync/'.$serverName;
$logFilename=$logDir.'/'.date("Y_m_d").".html";
if ( ! is_dir($logDir) ) {
makeDir($logDir);
}
$logStr='';
if ( ! is_file($logFilename) ) {
ob_start();
initHtml();
$logStr= ob_get_contents();
ob_end_clean();
}
ob_start();
list($result,$extra)=$server->sync($chunkSize,0);
$outStr = ob_get_contents();
ob_end_clean();
if ($result==0) {
$logStr.="<b>".date("d/m/Y H:i:s")."</b> No entries<BR>\n";
} else {
$logStr.="<hr><strong>".date("d/m/Y H:i:s")."</strong>";
if ($result==1) {
$logStr.=" <span class='ok'>OK</span> ";
} else if ($result<0) {
$logStr.=" <span class='error'>ERROR</span> ";
$msg="<pre>".date("d/m/Y H:i:s")."<br>\r\nServer: ". $serverName." [".$server->ID."]<br>\r\nError code: $result<br>\r\nError: $extra <br></pre>\r\n ";
sendMailToAdmin("Problem in syncing",$msg);
// mail($CONF_admin_email,"Problem in sync of master ".$_SERVER['SERVER_NAME'],$msg);
}
$logStr.=$outStr;
}
if (!$handle = fopen($logFilename, 'a')) {
echo "Cannot open file ($logFilename)";
exit;
}
if (fwrite($handle, $logStr) === FALSE) {
echo "Cannot write to file ($logFilename)";
exit;
}
fclose($handle);
} else if ($action==6) { // delete all external flights from this server
$moduleRelPath=moduleRelPath(0);
$waypointsWebPath=$moduleRelPath."/".$waypointsRelPath;
$server->deleteAllSyncedFlights();
} else if ($action==7) { // guess identical pilots
$moduleRelPath=moduleRelPath(0);
$waypointsWebPath=$moduleRelPath."/".$waypointsRelPath;
$server->guessPilots();
} else if ($action==8) { // delete pilots -> only use if you know what you are doing , must be sed only after delete flights
$server->deleteAllSyncedPilots();
} else if ($action==9) { // move sync pointer back (in effect will reprocess last n log entries next time
$server->getFromDB();
echo "Sync Pointer was ".$server->lastPullUpdateID."<BR>";
$server->moveSyncPointer($_GET['moveCounterBack']+0);
echo "Sync Pointer is ".$server->lastPullUpdateID."<BR>";
} else if ($action==99) { //test
echo $server->data['url_op'];
echo "<BR>$action<br>";
$pilotsList=$server->getPilots( 3 );
print_r($pilotsList);
//list($nearestWaypoint,$minTakeoffDistance)=$server->findTakeoff(49.4619,-8.67848);
//echo "wpt: ".$nearestWaypoint->intName. "~ $minTakeoffDistance<BR>";
}
echo "\n";
?>