Completed
Push — master ( 96a3ac...a10f5e )
by Yannick
08:58
created
scripts/daemon-spotter.php 2 patches
Indentation   +854 added lines, -854 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17 17
 if (isset($globalMarine) && $globalMarine) {
18
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 20
 }
21 21
 
22 22
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -24,47 +24,47 @@  discard block
 block discarded – undo
24 24
 // Check if schema is at latest version
25 25
 $Connection = new Connection();
26 26
 if ($Connection->latest() === false) {
27
-    echo "You MUST update to latest schema. Run install/index.php";
28
-    exit();
27
+	echo "You MUST update to latest schema. Run install/index.php";
28
+	exit();
29 29
 }
30 30
 if (PHP_SAPI != 'cli') {
31
-    echo "This script MUST be called from console, not a web browser.";
31
+	echo "This script MUST be called from console, not a web browser.";
32 32
 //    exit();
33 33
 }
34 34
 
35 35
 // This is to be compatible with old version of settings.php
36 36
 if (!isset($globalSources)) {
37
-    if (isset($globalSBS1Hosts)) {
38
-        //$hosts = $globalSBS1Hosts;
39
-        foreach ($globalSBS1Hosts as $host) {
40
-	    $globalSources[] = array('host' => $host);
41
-    	}
42
-    } else {
43
-        if (!isset($globalSBS1Host)) {
44
-	    echo '$globalSources MUST be defined !';
45
-	    die;
37
+	if (isset($globalSBS1Hosts)) {
38
+		//$hosts = $globalSBS1Hosts;
39
+		foreach ($globalSBS1Hosts as $host) {
40
+		$globalSources[] = array('host' => $host);
41
+		}
42
+	} else {
43
+		if (!isset($globalSBS1Host)) {
44
+		echo '$globalSources MUST be defined !';
45
+		die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48 48
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
49
-    }
49
+	}
50 50
 }
51 51
 
52 52
 $options = getopt('s::',array('source::','server','idsource::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
56
-    $globalSources = array();
57
-    $globalSources[] = array('host' => $options['s']);
56
+	$globalSources = array();
57
+	$globalSources[] = array('host' => $options['s']);
58 58
 } elseif (isset($options['source'])) {
59
-    $globalSources = array();
60
-    $globalSources[] = array('host' => $options['source']);
59
+	$globalSources = array();
60
+	$globalSources[] = array('host' => $options['source']);
61 61
 }
62 62
 if (isset($options['server'])) $globalServer = TRUE;
63 63
 if (isset($options['idsource'])) $id_source = $options['idsource'];
64 64
 else $id_source = 1;
65 65
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
67
-    $SI=new SpotterServer();
66
+	if ($globalDebug) echo "Using Server Mode\n";
67
+	$SI=new SpotterServer();
68 68
 /*
69 69
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
70 70
     $SI = new adsb2aprs();
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 } else $SI=new SpotterImport($Connection->db);
74 74
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
75 75
 if (isset($globalMarine) && $globalMarine) {
76
-    $AIS = new AIS();
77
-    $MI = new MarineImport($Connection->db);
76
+	$AIS = new AIS();
77
+	$MI = new MarineImport($Connection->db);
78 78
 }
79 79
 //$APRS=new APRS($Connection->db);
80 80
 $SBS=new SBS();
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
 //$servertz = system('date +%Z');
85 85
 // signal handler - playing nice with sockets and dump1090
86 86
 if (function_exists('pcntl_fork')) {
87
-    pcntl_signal(SIGINT,  function() {
88
-        global $sockets;
89
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
90
-        die("Bye!\n");
91
-    });
92
-    pcntl_signal_dispatch();
87
+	pcntl_signal(SIGINT,  function() {
88
+		global $sockets;
89
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
90
+		die("Bye!\n");
91
+	});
92
+	pcntl_signal_dispatch();
93 93
 }
94 94
 
95 95
 // let's try and connect
@@ -99,151 +99,151 @@  discard block
 block discarded – undo
99 99
 $reset = 0;
100 100
 
101 101
 function connect_all($hosts) {
102
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104
-    $reset++;
105
-    if ($globalDebug) echo 'Connect to all...'."\n";
106
-    foreach ($hosts as $id => $value) {
102
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104
+	$reset++;
105
+	if ($globalDebug) echo 'Connect to all...'."\n";
106
+	foreach ($hosts as $id => $value) {
107 107
 	$host = $value['host'];
108 108
 	$globalSources[$id]['last_exec'] = 0;
109 109
 	// Here we check type of source(s)
110 110
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
111
-            if (preg_match('/deltadb.txt$/i',$host)) {
112
-        	//$formats[$id] = 'deltadbtxt';
113
-        	$globalSources[$id]['format'] = 'deltadbtxt';
114
-        	//$last_exec['deltadbtxt'] = 0;
115
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
116
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
-        	//$formats[$id] = 'vatsimtxt';
118
-        	$globalSources[$id]['format'] = 'vatsimtxt';
119
-        	//$last_exec['vatsimtxt'] = 0;
120
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
121
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122
-        	//$formats[$id] = 'aircraftlistjson';
123
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
124
-        	//$last_exec['aircraftlistjson'] = 0;
125
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
126
-    	    } else if (preg_match('/opensky/i',$host)) {
127
-        	//$formats[$id] = 'aircraftlistjson';
128
-        	$globalSources[$id]['format'] = 'opensky';
129
-        	//$last_exec['aircraftlistjson'] = 0;
130
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
131
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132
-        	//$formats[$id] = 'radarvirtueljson';
133
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
134
-        	//$last_exec['radarvirtueljson'] = 0;
135
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
136
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138
-        	    exit(0);
139
-        	}
140
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
141
-        	//$formats[$id] = 'planeupdatefaa';
142
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
143
-        	//$last_exec['planeupdatefaa'] = 0;
144
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
145
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147
-        	    exit(0);
148
-        	}
149
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
150
-        	//$formats[$id] = 'phpvmacars';
151
-        	$globalSources[$id]['format'] = 'phpvmacars';
152
-        	//$last_exec['phpvmacars'] = 0;
153
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
154
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
155
-        	//$formats[$id] = 'phpvmacars';
156
-        	$globalSources[$id]['format'] = 'vam';
157
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
158
-            } else if (preg_match('/whazzup/i',$host)) {
159
-        	//$formats[$id] = 'whazzup';
160
-        	$globalSources[$id]['format'] = 'whazzup';
161
-        	//$last_exec['whazzup'] = 0;
162
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
163
-            } else if (preg_match('/recentpireps/i',$host)) {
164
-        	//$formats[$id] = 'pirepsjson';
165
-        	$globalSources[$id]['format'] = 'pirepsjson';
166
-        	//$last_exec['pirepsjson'] = 0;
167
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
168
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169
-        	//$formats[$id] = 'fr24json';
170
-        	$globalSources[$id]['format'] = 'fr24json';
171
-        	//$last_exec['fr24json'] = 0;
172
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
173
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175
-        	    exit(0);
176
-        	}
177
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
178
-        	//$formats[$id] = 'fr24json';
179
-        	$globalSources[$id]['format'] = 'myshiptracking';
180
-        	//$last_exec['fr24json'] = 0;
181
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
182
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184
-        	    exit(0);
185
-        	}
186
-            //} else if (preg_match('/10001/',$host)) {
187
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188
-        	//$formats[$id] = 'tsv';
189
-        	$globalSources[$id]['format'] = 'tsv';
190
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
191
-            }
192
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
195
-    		    if ($idf !== false) {
196
-    			$httpfeeds[$id] = $idf;
197
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
-    		    }
199
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202
-	    $hostport = explode(':',$host);
203
-	    if (isset($hostport[1])) {
111
+			if (preg_match('/deltadb.txt$/i',$host)) {
112
+			//$formats[$id] = 'deltadbtxt';
113
+			$globalSources[$id]['format'] = 'deltadbtxt';
114
+			//$last_exec['deltadbtxt'] = 0;
115
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
116
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
+			//$formats[$id] = 'vatsimtxt';
118
+			$globalSources[$id]['format'] = 'vatsimtxt';
119
+			//$last_exec['vatsimtxt'] = 0;
120
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
121
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
122
+			//$formats[$id] = 'aircraftlistjson';
123
+			$globalSources[$id]['format'] = 'aircraftlistjson';
124
+			//$last_exec['aircraftlistjson'] = 0;
125
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
126
+			} else if (preg_match('/opensky/i',$host)) {
127
+			//$formats[$id] = 'aircraftlistjson';
128
+			$globalSources[$id]['format'] = 'opensky';
129
+			//$last_exec['aircraftlistjson'] = 0;
130
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
131
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132
+			//$formats[$id] = 'radarvirtueljson';
133
+			$globalSources[$id]['format'] = 'radarvirtueljson';
134
+			//$last_exec['radarvirtueljson'] = 0;
135
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
136
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138
+				exit(0);
139
+			}
140
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
141
+			//$formats[$id] = 'planeupdatefaa';
142
+			$globalSources[$id]['format'] = 'planeupdatefaa';
143
+			//$last_exec['planeupdatefaa'] = 0;
144
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
145
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147
+				exit(0);
148
+			}
149
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
150
+			//$formats[$id] = 'phpvmacars';
151
+			$globalSources[$id]['format'] = 'phpvmacars';
152
+			//$last_exec['phpvmacars'] = 0;
153
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
154
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
155
+			//$formats[$id] = 'phpvmacars';
156
+			$globalSources[$id]['format'] = 'vam';
157
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
158
+			} else if (preg_match('/whazzup/i',$host)) {
159
+			//$formats[$id] = 'whazzup';
160
+			$globalSources[$id]['format'] = 'whazzup';
161
+			//$last_exec['whazzup'] = 0;
162
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
163
+			} else if (preg_match('/recentpireps/i',$host)) {
164
+			//$formats[$id] = 'pirepsjson';
165
+			$globalSources[$id]['format'] = 'pirepsjson';
166
+			//$last_exec['pirepsjson'] = 0;
167
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
168
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169
+			//$formats[$id] = 'fr24json';
170
+			$globalSources[$id]['format'] = 'fr24json';
171
+			//$last_exec['fr24json'] = 0;
172
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
173
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175
+				exit(0);
176
+			}
177
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
178
+			//$formats[$id] = 'fr24json';
179
+			$globalSources[$id]['format'] = 'myshiptracking';
180
+			//$last_exec['fr24json'] = 0;
181
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
182
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184
+				exit(0);
185
+			}
186
+			//} else if (preg_match('/10001/',$host)) {
187
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188
+			//$formats[$id] = 'tsv';
189
+			$globalSources[$id]['format'] = 'tsv';
190
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
191
+			}
192
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
195
+				if ($idf !== false) {
196
+				$httpfeeds[$id] = $idf;
197
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
+				}
199
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202
+		$hostport = explode(':',$host);
203
+		if (isset($hostport[1])) {
204 204
 		$port = $hostport[1];
205 205
 		$hostn = $hostport[0];
206
-	    } else {
206
+		} else {
207 207
 		$port = $globalSources[$id]['port'];
208 208
 		$hostn = $globalSources[$id]['host'];
209
-	    }
210
-	    $Common = new Common();
211
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
212
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
213
-    	    } else {
214
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
215
-	    }
216
-	    if ($s) {
217
-    	        $sockets[$id] = $s;
218
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
219
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
209
+		}
210
+		$Common = new Common();
211
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
212
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
213
+			} else {
214
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
215
+		}
216
+		if ($s) {
217
+				$sockets[$id] = $s;
218
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
219
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
220 220
 			//$formats[$id] = 'aprs';
221 221
 			$globalSources[$id]['format'] = 'aprs';
222 222
 			//$aprs_connect = 0;
223 223
 			//$use_aprs = true;
224
-    		    } elseif ($port == '10001') {
225
-        		//$formats[$id] = 'tsv';
226
-        		$globalSources[$id]['format'] = 'tsv';
227
-		    } elseif ($port == '30002') {
228
-        		//$formats[$id] = 'raw';
229
-        		$globalSources[$id]['format'] = 'raw';
230
-		    } elseif ($port == '5001') {
231
-        		//$formats[$id] = 'raw';
232
-        		$globalSources[$id]['format'] = 'flightgearmp';
233
-		    } elseif ($port == '30005') {
224
+				} elseif ($port == '10001') {
225
+				//$formats[$id] = 'tsv';
226
+				$globalSources[$id]['format'] = 'tsv';
227
+			} elseif ($port == '30002') {
228
+				//$formats[$id] = 'raw';
229
+				$globalSources[$id]['format'] = 'raw';
230
+			} elseif ($port == '5001') {
231
+				//$formats[$id] = 'raw';
232
+				$globalSources[$id]['format'] = 'flightgearmp';
233
+			} elseif ($port == '30005') {
234 234
 			// Not yet supported
235
-        		//$formats[$id] = 'beast';
236
-        		$globalSources[$id]['format'] = 'beast';
237
-		    //} else $formats[$id] = 'sbs';
238
-		    } else $globalSources[$id]['format'] = 'sbs';
239
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
235
+				//$formats[$id] = 'beast';
236
+				$globalSources[$id]['format'] = 'beast';
237
+			//} else $formats[$id] = 'sbs';
238
+			} else $globalSources[$id]['format'] = 'sbs';
239
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
240 240
 		}
241 241
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
242
-            } else {
242
+			} else {
243 243
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
244
-    	    }
245
-        }
246
-    }
244
+			}
245
+		}
246
+	}
247 247
 }
248 248
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
249 249
 
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
 //connect_all($globalSources);
267 267
 
268 268
 if (isset($globalProxy) && $globalProxy) {
269
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
269
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
270 270
 } else {
271
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
271
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
272 272
 }
273 273
 
274 274
 // APRS Configuration
@@ -277,18 +277,18 @@  discard block
 block discarded – undo
277 277
 	die;
278 278
 }
279 279
 foreach ($globalSources as $key => $source) {
280
-    if (!isset($source['format'])) {
281
-        $globalSources[$key]['format'] = 'auto';
282
-    }
280
+	if (!isset($source['format'])) {
281
+		$globalSources[$key]['format'] = 'auto';
282
+	}
283 283
 }
284 284
 connect_all($globalSources);
285 285
 foreach ($globalSources as $key => $source) {
286
-    if (isset($source['format']) && $source['format'] == 'aprs') {
286
+	if (isset($source['format']) && $source['format'] == 'aprs') {
287 287
 	$aprs_connect = 0;
288 288
 	$use_aprs = true;
289 289
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
290 290
 	break;
291
-    }
291
+	}
292 292
 }
293 293
 
294 294
 if ($use_aprs) {
@@ -330,152 +330,152 @@  discard block
 block discarded – undo
330 330
 
331 331
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
332 332
 while ($i > 0) {
333
-    if (!$globalDaemon) $i = $endtime-time();
334
-    // Delete old ATC
335
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
333
+	if (!$globalDaemon) $i = $endtime-time();
334
+	// Delete old ATC
335
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
336 336
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
337
-        $ATC->deleteOldATC();
338
-    }
337
+		$ATC->deleteOldATC();
338
+	}
339 339
     
340
-    //if (count($last_exec) > 0) {
341
-    if (count($last_exec) == count($globalSources)) {
340
+	//if (count($last_exec) > 0) {
341
+	if (count($last_exec) == count($globalSources)) {
342 342
 	$max = $globalMinFetch;
343 343
 	foreach ($last_exec as $last) {
344
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
344
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
345 345
 	}
346 346
 	if ($max != $globalMinFetch) {
347
-	    if ($globalDebug) echo 'Sleeping...'."\n";
348
-	    sleep($globalMinFetch-$max+2);
347
+		if ($globalDebug) echo 'Sleeping...'."\n";
348
+		sleep($globalMinFetch-$max+2);
349
+	}
349 350
 	}
350
-    }
351 351
 
352 352
     
353
-    //foreach ($formats as $id => $value) {
354
-    foreach ($globalSources as $id => $value) {
353
+	//foreach ($formats as $id => $value) {
354
+	foreach ($globalSources as $id => $value) {
355 355
 	date_default_timezone_set('UTC');
356 356
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
357 357
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
358
-	    //$buffer = $Common->getData($hosts[$id]);
359
-	    $buffer = $Common->getData($value['host']);
360
-	    if ($buffer != '') $reset = 0;
361
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
362
-	    $buffer = explode('\n',$buffer);
363
-	    foreach ($buffer as $line) {
364
-    		if ($line != '' && count($line) > 7) {
365
-    		    $line = explode(',', $line);
366
-	            $data = array();
367
-	            $data['hex'] = $line[1]; // hex
368
-	            $data['ident'] = $line[2]; // ident
369
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
370
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
371
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
372
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
373
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
374
-	            $data['verticalrate'] = ''; // vertical rate
375
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
376
-	            $data['emergency'] = ''; // emergency
377
-		    $data['datetime'] = date('Y-m-d H:i:s');
378
-		    $data['format_source'] = 'deltadbtxt';
379
-    		    $data['id_source'] = $id_source;
380
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
381
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
382
-    		    $SI->add($data);
383
-		    unset($data);
384
-    		}
385
-    	    }
386
-    	    $last_exec[$id]['last'] = time();
358
+		//$buffer = $Common->getData($hosts[$id]);
359
+		$buffer = $Common->getData($value['host']);
360
+		if ($buffer != '') $reset = 0;
361
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
362
+		$buffer = explode('\n',$buffer);
363
+		foreach ($buffer as $line) {
364
+			if ($line != '' && count($line) > 7) {
365
+				$line = explode(',', $line);
366
+				$data = array();
367
+				$data['hex'] = $line[1]; // hex
368
+				$data['ident'] = $line[2]; // ident
369
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
370
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
371
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
372
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
373
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
374
+				$data['verticalrate'] = ''; // vertical rate
375
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
376
+				$data['emergency'] = ''; // emergency
377
+			$data['datetime'] = date('Y-m-d H:i:s');
378
+			$data['format_source'] = 'deltadbtxt';
379
+				$data['id_source'] = $id_source;
380
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
381
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
382
+				$SI->add($data);
383
+			unset($data);
384
+			}
385
+			}
386
+			$last_exec[$id]['last'] = time();
387 387
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
388
-	    date_default_timezone_set('CET');
389
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
390
-	    date_default_timezone_set('UTC');
391
-	    if ($buffer != '') $reset = 0;
392
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
393
-	    $buffer = explode('\n',$buffer);
394
-	    foreach ($buffer as $line) {
388
+		date_default_timezone_set('CET');
389
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
390
+		date_default_timezone_set('UTC');
391
+		if ($buffer != '') $reset = 0;
392
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
393
+		$buffer = explode('\n',$buffer);
394
+		foreach ($buffer as $line) {
395 395
 		if ($line != '') {
396
-		    echo "'".$line."'\n";
397
-		    $add = false;
398
-		    $ais_data = $AIS->parse_line(trim($line));
399
-		    $data = array();
400
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
401
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
402
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
403
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
404
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
405
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
406
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
407
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
408
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
409
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
410
-		    if (isset($ais_data['timestamp'])) {
396
+			echo "'".$line."'\n";
397
+			$add = false;
398
+			$ais_data = $AIS->parse_line(trim($line));
399
+			$data = array();
400
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
401
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
402
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
403
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
404
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
405
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
406
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
407
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
408
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
409
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
410
+			if (isset($ais_data['timestamp'])) {
411 411
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
412 412
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
413
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
414
-			    $add = true;
413
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
414
+				$add = true;
415 415
 			}
416
-		    } else {
416
+			} else {
417 417
 			$data['datetime'] = date('Y-m-d H:i:s');
418 418
 			$add = true;
419
-		    }
420
-		    $data['format_source'] = 'aisnmeatxt';
421
-    		    $data['id_source'] = $id_source;
422
-		    print_r($data);
423
-		    echo 'Add...'."\n";
424
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
425
-		    unset($data);
419
+			}
420
+			$data['format_source'] = 'aisnmeatxt';
421
+				$data['id_source'] = $id_source;
422
+			print_r($data);
423
+			echo 'Add...'."\n";
424
+			if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
425
+			unset($data);
426 426
 		}
427
-    	    }
428
-    	    $last_exec[$id]['last'] = time();
427
+			}
428
+			$last_exec[$id]['last'] = time();
429 429
 	} elseif ($value['format'] == 'aisnmeahttp') {
430
-	    $arr = $httpfeeds;
431
-	    $w = $e = null;
430
+		$arr = $httpfeeds;
431
+		$w = $e = null;
432 432
 	    
433
-	    if (isset($arr[$id])) {
434
-	    $nn = stream_select($arr,$w,$e,$timeout);
435
-	    if ($nn > 0) {
433
+		if (isset($arr[$id])) {
434
+		$nn = stream_select($arr,$w,$e,$timeout);
435
+		if ($nn > 0) {
436 436
 		foreach ($httpfeeds as $feed) {
437
-		    $buffer = stream_get_line($feed,2000,"\n");
438
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
439
-		    $buffer = explode('\n',$buffer);
440
-		    foreach ($buffer as $line) {
437
+			$buffer = stream_get_line($feed,2000,"\n");
438
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
439
+			$buffer = explode('\n',$buffer);
440
+			foreach ($buffer as $line) {
441 441
 			if ($line != '') {
442
-			    $ais_data = $AIS->parse_line(trim($line));
443
-			    $data = array();
444
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
445
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
446
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
447
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
448
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
449
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
450
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
451
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
452
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
453
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
454
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
455
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
456
-			    if (isset($ais_data['timestamp'])) {
442
+				$ais_data = $AIS->parse_line(trim($line));
443
+				$data = array();
444
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
445
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
446
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
447
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
448
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
449
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
450
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
451
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
452
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
453
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
454
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
455
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
456
+				if (isset($ais_data['timestamp'])) {
457 457
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
458
-			    } else {
458
+				} else {
459 459
 				$data['datetime'] = date('Y-m-d H:i:s');
460
-			    }
461
-			    $data['format_source'] = 'aisnmeahttp';
462
-			    $data['id_source'] = $id_source;
463
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
464
-			    unset($data);
460
+				}
461
+				$data['format_source'] = 'aisnmeahttp';
462
+				$data['id_source'] = $id_source;
463
+				if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
464
+				unset($data);
465
+			}
465 466
 			}
466
-		    }
467 467
 		}
468 468
 		}
469
-	    }
469
+		}
470 470
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
471
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
472
-	    if ($buffer != '') {
471
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
472
+		if ($buffer != '') {
473 473
 		//echo $buffer;
474 474
 		$all_data = json_decode($buffer,true);
475 475
 		//print_r($all_data);
476 476
 		if (isset($all_data[0]['DATA'])) {
477 477
 		foreach ($all_data[0]['DATA'] as $line) {
478
-		    if ($line != '') {
478
+			if ($line != '') {
479 479
 			$data = array();
480 480
 			$data['ident'] = $line['NAME'];
481 481
 			$data['mmsi'] = $line['MMSI'];
@@ -491,87 +491,87 @@  discard block
 block discarded – undo
491 491
 			$data['id_source'] = $id_source;
492 492
 			$MI->add($data);
493 493
 			unset($data);
494
-		    }
494
+			}
495 495
 		}
496 496
 		}
497 497
 		
498
-	    }
499
-    	    $last_exec[$id]['last'] = time();
498
+		}
499
+			$last_exec[$id]['last'] = time();
500 500
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
501
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
502
-	    if ($buffer != '') {
501
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
502
+		if ($buffer != '') {
503 503
 		$all_data = json_decode($buffer,true);
504 504
 		if (isset($all_data[0]['mmsi'])) {
505
-		    foreach ($all_data as $line) {
505
+			foreach ($all_data as $line) {
506 506
 			if ($line != '') {
507
-			    $data = array();
508
-			    $data['ident'] = $line['shipname'];
509
-			    $data['callsign'] = $line['callsign'];
510
-			    $data['mmsi'] = $line['mmsi'];
511
-			    $data['speed'] = $line['sog'];
512
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
513
-			    $data['latitude'] = $line['latitude'];
514
-			    $data['longitude'] = $line['longitude'];
515
-			    $data['type_id'] = $line['shiptype'];
516
-			    $data['arrival_code'] = $line['destination'];
517
-			    $data['datetime'] = $line['time'];
518
-			    $data['format_source'] = 'boatbeaconapp';
519
-			    $data['id_source'] = $id_source;
520
-			    $MI->add($data);
521
-			    unset($data);
507
+				$data = array();
508
+				$data['ident'] = $line['shipname'];
509
+				$data['callsign'] = $line['callsign'];
510
+				$data['mmsi'] = $line['mmsi'];
511
+				$data['speed'] = $line['sog'];
512
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
513
+				$data['latitude'] = $line['latitude'];
514
+				$data['longitude'] = $line['longitude'];
515
+				$data['type_id'] = $line['shiptype'];
516
+				$data['arrival_code'] = $line['destination'];
517
+				$data['datetime'] = $line['time'];
518
+				$data['format_source'] = 'boatbeaconapp';
519
+				$data['id_source'] = $id_source;
520
+				$MI->add($data);
521
+				unset($data);
522
+			}
522 523
 			}
523
-		    }
524 524
 		}
525 525
 		
526
-	    }
527
-    	    $last_exec[$id]['last'] = time();
526
+		}
527
+			$last_exec[$id]['last'] = time();
528 528
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
529
-	    echo 'download...';
530
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
531
-	    echo 'done !'."\n";
532
-	    if ($buffer != '') $reset = 0;
533
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
534
-	    $buffer = explode('\n',$buffer);
535
-	    foreach ($buffer as $line) {
529
+		echo 'download...';
530
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
531
+		echo 'done !'."\n";
532
+		if ($buffer != '') $reset = 0;
533
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
534
+		$buffer = explode('\n',$buffer);
535
+		foreach ($buffer as $line) {
536 536
 		if ($line != '') {
537
-		    $data = array();
538
-		    $data['mmsi'] = (int)substr($line,0,9);
539
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
540
-		    //$data['status'] = substr($line,21,2);
541
-		    //$data['type'] = substr($line,24,3);
542
-		    $data['latitude'] = substr($line,29,9);
543
-		    $data['longitude'] = substr($line,41,9);
544
-		    $data['speed'] = round(substr($line,51,5));
545
-		    //$data['course'] = substr($line,57,5);
546
-		    $data['heading'] = round(substr($line,63,3));
547
-		    //$data['draft'] = substr($line,67,4);
548
-		    //$data['length'] = substr($line,72,3);
549
-		    //$data['beam'] = substr($line,76,2);
550
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
551
-		    //$data['callsign'] = trim(substr($line,100,7);
552
-		    //$data['dest'] = substr($line,108,20);
553
-		    //$data['etaDate'] = substr($line,129,5);
554
-		    //$data['etaTime'] = substr($line,135,5);
555
-		    $data['format_source'] = 'shipplotter';
556
-    		    $data['id_source'] = $id_source;
557
-		    print_r($data);
558
-		    echo 'Add...'."\n";
559
-		    $MI->add($data);
560
-		    unset($data);
537
+			$data = array();
538
+			$data['mmsi'] = (int)substr($line,0,9);
539
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
540
+			//$data['status'] = substr($line,21,2);
541
+			//$data['type'] = substr($line,24,3);
542
+			$data['latitude'] = substr($line,29,9);
543
+			$data['longitude'] = substr($line,41,9);
544
+			$data['speed'] = round(substr($line,51,5));
545
+			//$data['course'] = substr($line,57,5);
546
+			$data['heading'] = round(substr($line,63,3));
547
+			//$data['draft'] = substr($line,67,4);
548
+			//$data['length'] = substr($line,72,3);
549
+			//$data['beam'] = substr($line,76,2);
550
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
551
+			//$data['callsign'] = trim(substr($line,100,7);
552
+			//$data['dest'] = substr($line,108,20);
553
+			//$data['etaDate'] = substr($line,129,5);
554
+			//$data['etaTime'] = substr($line,135,5);
555
+			$data['format_source'] = 'shipplotter';
556
+				$data['id_source'] = $id_source;
557
+			print_r($data);
558
+			echo 'Add...'."\n";
559
+			$MI->add($data);
560
+			unset($data);
561 561
 		}
562
-    	    }
563
-    	    $last_exec[$id]['last'] = time();
562
+			}
563
+			$last_exec[$id]['last'] = time();
564 564
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
565 565
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
566
-	    //$buffer = $Common->getData($hosts[$id]);
567
-	    $buffer = $Common->getData($value['host']);
568
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
569
-	    $buffer = explode('\n',$buffer);
570
-	    $reset = 0;
571
-	    foreach ($buffer as $line) {
572
-    		if ($line != '') {
573
-    		    $line = explode(':', $line);
574
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
566
+		//$buffer = $Common->getData($hosts[$id]);
567
+		$buffer = $Common->getData($value['host']);
568
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
569
+		$buffer = explode('\n',$buffer);
570
+		$reset = 0;
571
+		foreach ($buffer as $line) {
572
+			if ($line != '') {
573
+				$line = explode(':', $line);
574
+				if (count($line) > 30 && $line[0] != 'callsign') {
575 575
 			$data = array();
576 576
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
577 577
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -584,36 +584,36 @@  discard block
 block discarded – undo
584 584
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
585 585
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
586 586
 			$data['latitude'] = $line[5]; // lat
587
-	        	$data['longitude'] = $line[6]; // long
588
-	        	$data['verticalrate'] = ''; // vertical rate
589
-	        	$data['squawk'] = ''; // squawk
590
-	        	$data['emergency'] = ''; // emergency
591
-	        	$data['waypoints'] = $line[30];
587
+				$data['longitude'] = $line[6]; // long
588
+				$data['verticalrate'] = ''; // vertical rate
589
+				$data['squawk'] = ''; // squawk
590
+				$data['emergency'] = ''; // emergency
591
+				$data['waypoints'] = $line[30];
592 592
 			$data['datetime'] = date('Y-m-d H:i:s');
593 593
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
594 594
 			//if (isset($line[37])) $data['last_update'] = $line[37];
595
-		        $data['departure_airport_icao'] = $line[11];
596
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
597
-		        $data['arrival_airport_icao'] = $line[13];
595
+				$data['departure_airport_icao'] = $line[11];
596
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
597
+				$data['arrival_airport_icao'] = $line[13];
598 598
 			$data['frequency'] = $line[4];
599 599
 			$data['type'] = $line[18];
600 600
 			$data['range'] = $line[19];
601 601
 			if (isset($line[35])) $data['info'] = $line[35];
602
-    			$data['id_source'] = $id_source;
603
-	    		//$data['arrival_airport_time'] = ;
604
-	    		if ($line[9] != '') {
605
-	    		    $aircraft_data = explode('/',$line[9]);
606
-	    		    if (isset($aircraft_data[1])) {
607
-	    			$data['aircraft_icao'] = $aircraft_data[1];
608
-	    		    }
609
-        		}
610
-	    		/*
602
+				$data['id_source'] = $id_source;
603
+				//$data['arrival_airport_time'] = ;
604
+				if ($line[9] != '') {
605
+					$aircraft_data = explode('/',$line[9]);
606
+					if (isset($aircraft_data[1])) {
607
+					$data['aircraft_icao'] = $aircraft_data[1];
608
+					}
609
+				}
610
+				/*
611 611
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
612 612
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
613 613
 	    		*/
614
-	    		$data['format_source'] = $value['format'];
614
+				$data['format_source'] = $value['format'];
615 615
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
616
-    			if ($line[3] == 'PILOT') $SI->add($data);
616
+				if ($line[3] == 'PILOT') $SI->add($data);
617 617
 			elseif ($line[3] == 'ATC') {
618 618
 				//print_r($data);
619 619
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -631,247 +631,247 @@  discard block
 block discarded – undo
631 631
 				if (!isset($data['source_name'])) $data['source_name'] = '';
632 632
 				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
633 633
 			}
634
-    			unset($data);
635
-    		    }
636
-    		}
637
-    	    }
638
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
639
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
640
-    	    $last_exec[$id]['last'] = time();
641
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
642
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
643
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
644
-	    if ($buffer != '') {
645
-	    $all_data = json_decode($buffer,true);
646
-	    if (isset($all_data['acList'])) {
634
+				unset($data);
635
+				}
636
+			}
637
+			}
638
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
639
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
640
+			$last_exec[$id]['last'] = time();
641
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
642
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
643
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
644
+		if ($buffer != '') {
645
+		$all_data = json_decode($buffer,true);
646
+		if (isset($all_data['acList'])) {
647 647
 		$reset = 0;
648 648
 		foreach ($all_data['acList'] as $line) {
649
-		    $data = array();
650
-		    $data['hex'] = $line['Icao']; // hex
651
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
652
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
653
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
654
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
655
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
656
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
657
-		    //$data['verticalrate'] = $line['']; // verticale rate
658
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
659
-		    $data['emergency'] = ''; // emergency
660
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
661
-		    /*
649
+			$data = array();
650
+			$data['hex'] = $line['Icao']; // hex
651
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
652
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
653
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
654
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
655
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
656
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
657
+			//$data['verticalrate'] = $line['']; // verticale rate
658
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
659
+			$data['emergency'] = ''; // emergency
660
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
661
+			/*
662 662
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
663 663
 		    else $data['datetime'] = date('Y-m-d H:i:s');
664 664
 		    */
665
-		    $data['datetime'] = date('Y-m-d H:i:s');
666
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
667
-	    	    $data['format_source'] = 'aircraftlistjson';
668
-		    $data['id_source'] = $id_source;
669
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
670
-		    if (isset($data['datetime'])) $SI->add($data);
671
-		    unset($data);
665
+			$data['datetime'] = date('Y-m-d H:i:s');
666
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
667
+				$data['format_source'] = 'aircraftlistjson';
668
+			$data['id_source'] = $id_source;
669
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
670
+			if (isset($data['datetime'])) $SI->add($data);
671
+			unset($data);
672 672
 		}
673
-	    } else {
673
+		} else {
674 674
 		$reset = 0;
675 675
 		foreach ($all_data as $line) {
676
-		    $data = array();
677
-		    $data['hex'] = $line['hex']; // hex
678
-		    $data['ident'] = $line['flight']; // ident
679
-		    $data['altitude'] = $line['altitude']; // altitude
680
-		    $data['speed'] = $line['speed']; // speed
681
-		    $data['heading'] = $line['track']; // heading
682
-		    $data['latitude'] = $line['lat']; // lat
683
-		    $data['longitude'] = $line['lon']; // long
684
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
685
-		    $data['squawk'] = $line['squawk']; // squawk
686
-		    $data['emergency'] = ''; // emergency
687
-		    $data['datetime'] = date('Y-m-d H:i:s');
688
-	    	    $data['format_source'] = 'aircraftlistjson';
689
-    		    $data['id_source'] = $id_source;
690
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
691
-		    $SI->add($data);
692
-		    unset($data);
676
+			$data = array();
677
+			$data['hex'] = $line['hex']; // hex
678
+			$data['ident'] = $line['flight']; // ident
679
+			$data['altitude'] = $line['altitude']; // altitude
680
+			$data['speed'] = $line['speed']; // speed
681
+			$data['heading'] = $line['track']; // heading
682
+			$data['latitude'] = $line['lat']; // lat
683
+			$data['longitude'] = $line['lon']; // long
684
+			$data['verticalrate'] = $line['vrt']; // verticale rate
685
+			$data['squawk'] = $line['squawk']; // squawk
686
+			$data['emergency'] = ''; // emergency
687
+			$data['datetime'] = date('Y-m-d H:i:s');
688
+				$data['format_source'] = 'aircraftlistjson';
689
+				$data['id_source'] = $id_source;
690
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
691
+			$SI->add($data);
692
+			unset($data);
693 693
 		}
694
-	    }
695
-	    }
696
-    	    //$last_exec['aircraftlistjson'] = time();
697
-    	    $last_exec[$id]['last'] = time();
698
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
699
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
700
-	    $buffer = $Common->getData($value['host']);
701
-	    $all_data = json_decode($buffer,true);
702
-	    if (isset($all_data['planes'])) {
694
+		}
695
+		}
696
+			//$last_exec['aircraftlistjson'] = time();
697
+			$last_exec[$id]['last'] = time();
698
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
699
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
700
+		$buffer = $Common->getData($value['host']);
701
+		$all_data = json_decode($buffer,true);
702
+		if (isset($all_data['planes'])) {
703 703
 		$reset = 0;
704 704
 		foreach ($all_data['planes'] as $key => $line) {
705
-		    $data = array();
706
-		    $data['hex'] = $key; // hex
707
-		    $data['ident'] = $line[3]; // ident
708
-		    $data['altitude'] = $line[6]; // altitude
709
-		    $data['speed'] = $line[8]; // speed
710
-		    $data['heading'] = $line[7]; // heading
711
-		    $data['latitude'] = $line[4]; // lat
712
-		    $data['longitude'] = $line[5]; // long
713
-		    //$data['verticalrate'] = $line[]; // verticale rate
714
-		    $data['squawk'] = $line[10]; // squawk
715
-		    $data['emergency'] = ''; // emergency
716
-		    $data['registration'] = $line[2];
717
-		    $data['aircraft_icao'] = $line[0];
718
-		    $deparr = explode('-',$line[1]);
719
-		    if (count($deparr) == 2) {
705
+			$data = array();
706
+			$data['hex'] = $key; // hex
707
+			$data['ident'] = $line[3]; // ident
708
+			$data['altitude'] = $line[6]; // altitude
709
+			$data['speed'] = $line[8]; // speed
710
+			$data['heading'] = $line[7]; // heading
711
+			$data['latitude'] = $line[4]; // lat
712
+			$data['longitude'] = $line[5]; // long
713
+			//$data['verticalrate'] = $line[]; // verticale rate
714
+			$data['squawk'] = $line[10]; // squawk
715
+			$data['emergency'] = ''; // emergency
716
+			$data['registration'] = $line[2];
717
+			$data['aircraft_icao'] = $line[0];
718
+			$deparr = explode('-',$line[1]);
719
+			if (count($deparr) == 2) {
720 720
 			$data['departure_airport_icao'] = $deparr[0];
721 721
 			$data['arrival_airport_icao'] = $deparr[1];
722
-		    }
723
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
724
-	    	    $data['format_source'] = 'planeupdatefaa';
725
-    		    $data['id_source'] = $id_source;
726
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
727
-		    $SI->add($data);
728
-		    unset($data);
722
+			}
723
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
724
+				$data['format_source'] = 'planeupdatefaa';
725
+				$data['id_source'] = $id_source;
726
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
727
+			$SI->add($data);
728
+			unset($data);
729 729
 		}
730
-	    }
731
-    	    //$last_exec['planeupdatefaa'] = time();
732
-    	    $last_exec[$id]['last'] = time();
733
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
734
-	    $buffer = $Common->getData($value['host']);
735
-	    $all_data = json_decode($buffer,true);
736
-	    if (isset($all_data['states'])) {
730
+		}
731
+			//$last_exec['planeupdatefaa'] = time();
732
+			$last_exec[$id]['last'] = time();
733
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
734
+		$buffer = $Common->getData($value['host']);
735
+		$all_data = json_decode($buffer,true);
736
+		if (isset($all_data['states'])) {
737 737
 		$reset = 0;
738 738
 		foreach ($all_data['states'] as $key => $line) {
739
-		    $data = array();
740
-		    $data['hex'] = $line[0]; // hex
741
-		    $data['ident'] = trim($line[1]); // ident
742
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
743
-		    $data['speed'] = round($line[9]*1.94384); // speed
744
-		    $data['heading'] = round($line[10]); // heading
745
-		    $data['latitude'] = $line[5]; // lat
746
-		    $data['longitude'] = $line[6]; // long
747
-		    $data['verticalrate'] = $line[11]; // verticale rate
748
-		    //$data['squawk'] = $line[10]; // squawk
749
-		    //$data['emergency'] = ''; // emergency
750
-		    //$data['registration'] = $line[2];
751
-		    //$data['aircraft_icao'] = $line[0];
752
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
753
-	    	    $data['format_source'] = 'opensky';
754
-    		    $data['id_source'] = $id_source;
755
-		    $SI->add($data);
756
-		    unset($data);
739
+			$data = array();
740
+			$data['hex'] = $line[0]; // hex
741
+			$data['ident'] = trim($line[1]); // ident
742
+			$data['altitude'] = round($line[7]*3.28084); // altitude
743
+			$data['speed'] = round($line[9]*1.94384); // speed
744
+			$data['heading'] = round($line[10]); // heading
745
+			$data['latitude'] = $line[5]; // lat
746
+			$data['longitude'] = $line[6]; // long
747
+			$data['verticalrate'] = $line[11]; // verticale rate
748
+			//$data['squawk'] = $line[10]; // squawk
749
+			//$data['emergency'] = ''; // emergency
750
+			//$data['registration'] = $line[2];
751
+			//$data['aircraft_icao'] = $line[0];
752
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
753
+				$data['format_source'] = 'opensky';
754
+				$data['id_source'] = $id_source;
755
+			$SI->add($data);
756
+			unset($data);
757 757
 		}
758
-	    }
759
-    	    //$last_exec['planeupdatefaa'] = time();
760
-    	    $last_exec[$id]['last'] = time();
761
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
762
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
763
-	    //$buffer = $Common->getData($hosts[$id]);
764
-	    $buffer = $Common->getData($value['host']);
765
-	    $all_data = json_decode($buffer,true);
766
-	    if (!empty($all_data)) $reset = 0;
767
-	    foreach ($all_data as $key => $line) {
758
+		}
759
+			//$last_exec['planeupdatefaa'] = time();
760
+			$last_exec[$id]['last'] = time();
761
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
762
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
763
+		//$buffer = $Common->getData($hosts[$id]);
764
+		$buffer = $Common->getData($value['host']);
765
+		$all_data = json_decode($buffer,true);
766
+		if (!empty($all_data)) $reset = 0;
767
+		foreach ($all_data as $key => $line) {
768 768
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
769
-		    $data = array();
770
-		    $data['hex'] = $line[0];
771
-		    $data['ident'] = $line[16]; //$line[13]
772
-	    	    $data['altitude'] = $line[4]; // altitude
773
-	    	    $data['speed'] = $line[5]; // speed
774
-	    	    $data['heading'] = $line[3]; // heading
775
-	    	    $data['latitude'] = $line[1]; // lat
776
-	    	    $data['longitude'] = $line[2]; // long
777
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
778
-	    	    $data['squawk'] = $line[6]; // squawk
779
-	    	    $data['aircraft_icao'] = $line[8];
780
-	    	    $data['registration'] = $line[9];
781
-		    $data['departure_airport_iata'] = $line[11];
782
-		    $data['arrival_airport_iata'] = $line[12];
783
-	    	    $data['emergency'] = ''; // emergency
784
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
785
-	    	    $data['format_source'] = 'fr24json';
786
-    		    $data['id_source'] = $id_source;
787
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
788
-		    $SI->add($data);
789
-		    unset($data);
769
+			$data = array();
770
+			$data['hex'] = $line[0];
771
+			$data['ident'] = $line[16]; //$line[13]
772
+				$data['altitude'] = $line[4]; // altitude
773
+				$data['speed'] = $line[5]; // speed
774
+				$data['heading'] = $line[3]; // heading
775
+				$data['latitude'] = $line[1]; // lat
776
+				$data['longitude'] = $line[2]; // long
777
+				$data['verticalrate'] = $line[15]; // verticale rate
778
+				$data['squawk'] = $line[6]; // squawk
779
+				$data['aircraft_icao'] = $line[8];
780
+				$data['registration'] = $line[9];
781
+			$data['departure_airport_iata'] = $line[11];
782
+			$data['arrival_airport_iata'] = $line[12];
783
+				$data['emergency'] = ''; // emergency
784
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
785
+				$data['format_source'] = 'fr24json';
786
+				$data['id_source'] = $id_source;
787
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
788
+			$SI->add($data);
789
+			unset($data);
790 790
 		}
791
-	    }
792
-    	    //$last_exec['fr24json'] = time();
793
-    	    $last_exec[$id]['last'] = time();
794
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
795
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
796
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
797
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
798
-	    //echo $buffer;
799
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
800
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
801
-	    $all_data = json_decode($buffer,true);
802
-	    if (json_last_error() != JSON_ERROR_NONE) {
791
+		}
792
+			//$last_exec['fr24json'] = time();
793
+			$last_exec[$id]['last'] = time();
794
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
795
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
796
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
797
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
798
+		//echo $buffer;
799
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
800
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
801
+		$all_data = json_decode($buffer,true);
802
+		if (json_last_error() != JSON_ERROR_NONE) {
803 803
 		die(json_last_error_msg());
804
-	    }
805
-	    if (isset($all_data['mrkrs'])) {
804
+		}
805
+		if (isset($all_data['mrkrs'])) {
806 806
 		$reset = 0;
807 807
 		foreach ($all_data['mrkrs'] as $key => $line) {
808
-		    if (isset($line['inf'])) {
808
+			if (isset($line['inf'])) {
809 809
 			$data = array();
810 810
 			$data['hex'] = $line['inf']['ia'];
811 811
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
812
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
813
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
814
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
815
-	    		$data['latitude'] = $line['pt'][0]; // lat
816
-	    		$data['longitude'] = $line['pt'][1]; // long
817
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
818
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
819
-	    		//$data['aircraft_icao'] = $line[8];
820
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
812
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
813
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
814
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
815
+				$data['latitude'] = $line['pt'][0]; // lat
816
+				$data['longitude'] = $line['pt'][1]; // long
817
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
818
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
819
+				//$data['aircraft_icao'] = $line[8];
820
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
821 821
 			//$data['departure_airport_iata'] = $line[11];
822 822
 			//$data['arrival_airport_iata'] = $line[12];
823
-	    		//$data['emergency'] = ''; // emergency
823
+				//$data['emergency'] = ''; // emergency
824 824
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
825
-	    		$data['format_source'] = 'radarvirtueljson';
826
-    			$data['id_source'] = $id_source;
825
+				$data['format_source'] = 'radarvirtueljson';
826
+				$data['id_source'] = $id_source;
827 827
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
828 828
 			$SI->add($data);
829 829
 			unset($data);
830
-		    }
830
+			}
831
+		}
831 832
 		}
832
-	    }
833
-    	    //$last_exec['radarvirtueljson'] = time();
834
-    	    $last_exec[$id]['last'] = time();
835
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
836
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
837
-	    //$buffer = $Common->getData($hosts[$id]);
838
-	    $buffer = $Common->getData($value['host'].'?'.time());
839
-	    $all_data = json_decode(utf8_encode($buffer),true);
833
+			//$last_exec['radarvirtueljson'] = time();
834
+			$last_exec[$id]['last'] = time();
835
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
836
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
837
+		//$buffer = $Common->getData($hosts[$id]);
838
+		$buffer = $Common->getData($value['host'].'?'.time());
839
+		$all_data = json_decode(utf8_encode($buffer),true);
840 840
 	    
841
-	    if (isset($all_data['pireps'])) {
841
+		if (isset($all_data['pireps'])) {
842 842
 		$reset = 0;
843
-	        foreach ($all_data['pireps'] as $line) {
844
-		    $data = array();
845
-		    $data['id'] = $line['id'];
846
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
847
-		    $data['ident'] = $line['callsign']; // ident
848
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
849
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
850
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
851
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
852
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
853
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
854
-		    $data['latitude'] = $line['lat']; // lat
855
-		    $data['longitude'] = $line['lon']; // long
856
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
857
-		    //$data['squawk'] = $line['squawk']; // squawk
858
-		    //$data['emergency'] = ''; // emergency
859
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
860
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
861
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
862
-		    //$data['arrival_airport_time'] = $line['arrtime'];
863
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
864
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
865
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
866
-		    else $data['info'] = '';
867
-		    $data['format_source'] = 'pireps';
868
-    		    $data['id_source'] = $id_source;
869
-		    $data['datetime'] = date('Y-m-d H:i:s');
870
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
871
-		    if ($line['icon'] == 'plane') {
843
+			foreach ($all_data['pireps'] as $line) {
844
+			$data = array();
845
+			$data['id'] = $line['id'];
846
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
847
+			$data['ident'] = $line['callsign']; // ident
848
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
849
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
850
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
851
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
852
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
853
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
854
+			$data['latitude'] = $line['lat']; // lat
855
+			$data['longitude'] = $line['lon']; // long
856
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
857
+			//$data['squawk'] = $line['squawk']; // squawk
858
+			//$data['emergency'] = ''; // emergency
859
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
860
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
861
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
862
+			//$data['arrival_airport_time'] = $line['arrtime'];
863
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
864
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
865
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
866
+			else $data['info'] = '';
867
+			$data['format_source'] = 'pireps';
868
+				$data['id_source'] = $id_source;
869
+			$data['datetime'] = date('Y-m-d H:i:s');
870
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
871
+			if ($line['icon'] == 'plane') {
872 872
 			$SI->add($data);
873
-		    //    print_r($data);
874
-    		    } elseif ($line['icon'] == 'ct') {
873
+			//    print_r($data);
874
+				} elseif ($line['icon'] == 'ct') {
875 875
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
876 876
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
877 877
 			$typec = substr($data['ident'],-3);
@@ -886,188 +886,188 @@  discard block
 block discarded – undo
886 886
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
887 887
 			else $data['type'] = 'Observer';
888 888
 			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
889
-		    }
890
-		    unset($data);
889
+			}
890
+			unset($data);
891
+		}
891 892
 		}
892
-	    }
893
-    	    //$last_exec['pirepsjson'] = time();
894
-    	    $last_exec[$id]['last'] = time();
895
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
896
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
897
-	    //$buffer = $Common->getData($hosts[$id]);
898
-	    if ($globalDebug) echo 'Get Data...'."\n";
899
-	    $buffer = $Common->getData($value['host']);
900
-	    $all_data = json_decode($buffer,true);
901
-	    if ($buffer != '' && is_array($all_data)) {
893
+			//$last_exec['pirepsjson'] = time();
894
+			$last_exec[$id]['last'] = time();
895
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
896
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
897
+		//$buffer = $Common->getData($hosts[$id]);
898
+		if ($globalDebug) echo 'Get Data...'."\n";
899
+		$buffer = $Common->getData($value['host']);
900
+		$all_data = json_decode($buffer,true);
901
+		if ($buffer != '' && is_array($all_data)) {
902 902
 		$reset = 0;
903 903
 		foreach ($all_data as $line) {
904
-	    	    $data = array();
905
-	    	    //$data['id'] = $line['id']; // id not usable
906
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
907
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
908
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
909
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
910
-	    	    $data['ident'] = $line['flightnum']; // ident
911
-	    	    $data['altitude'] = $line['alt']; // altitude
912
-	    	    $data['speed'] = $line['gs']; // speed
913
-	    	    $data['heading'] = $line['heading']; // heading
914
-	    	    $data['latitude'] = $line['lat']; // lat
915
-	    	    $data['longitude'] = $line['lng']; // long
916
-	    	    $data['verticalrate'] = ''; // verticale rate
917
-	    	    $data['squawk'] = ''; // squawk
918
-	    	    $data['emergency'] = ''; // emergency
919
-	    	    //$data['datetime'] = $line['lastupdate'];
920
-	    	    $data['last_update'] = $line['lastupdate'];
921
-		    $data['datetime'] = date('Y-m-d H:i:s');
922
-	    	    $data['departure_airport_icao'] = $line['depicao'];
923
-	    	    $data['departure_airport_time'] = $line['deptime'];
924
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
925
-    		    $data['arrival_airport_time'] = $line['arrtime'];
926
-    		    $data['registration'] = $line['aircraft'];
927
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
928
-		    if (isset($line['aircraftname'])) {
904
+				$data = array();
905
+				//$data['id'] = $line['id']; // id not usable
906
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
907
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
908
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
909
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
910
+				$data['ident'] = $line['flightnum']; // ident
911
+				$data['altitude'] = $line['alt']; // altitude
912
+				$data['speed'] = $line['gs']; // speed
913
+				$data['heading'] = $line['heading']; // heading
914
+				$data['latitude'] = $line['lat']; // lat
915
+				$data['longitude'] = $line['lng']; // long
916
+				$data['verticalrate'] = ''; // verticale rate
917
+				$data['squawk'] = ''; // squawk
918
+				$data['emergency'] = ''; // emergency
919
+				//$data['datetime'] = $line['lastupdate'];
920
+				$data['last_update'] = $line['lastupdate'];
921
+			$data['datetime'] = date('Y-m-d H:i:s');
922
+				$data['departure_airport_icao'] = $line['depicao'];
923
+				$data['departure_airport_time'] = $line['deptime'];
924
+				$data['arrival_airport_icao'] = $line['arricao'];
925
+				$data['arrival_airport_time'] = $line['arrtime'];
926
+				$data['registration'] = $line['aircraft'];
927
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
928
+			if (isset($line['aircraftname'])) {
929 929
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
930 930
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
931
-	    		$aircraft_data = explode('-',$line['aircraftname']);
932
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
933
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
934
-	    		else {
935
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
936
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
937
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
938
-	    		}
939
-	    	    }
940
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
941
-    		    $data['id_source'] = $id_source;
942
-	    	    $data['format_source'] = 'phpvmacars';
943
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
944
-		    $SI->add($data);
945
-		    unset($data);
931
+				$aircraft_data = explode('-',$line['aircraftname']);
932
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
933
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
934
+				else {
935
+					$aircraft_data = explode(' ',$line['aircraftname']);
936
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
937
+					else $data['aircraft_icao'] = $line['aircraftname'];
938
+				}
939
+				}
940
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
941
+				$data['id_source'] = $id_source;
942
+				$data['format_source'] = 'phpvmacars';
943
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
944
+			$SI->add($data);
945
+			unset($data);
946 946
 		}
947 947
 		if ($globalDebug) echo 'No more data...'."\n";
948 948
 		unset($buffer);
949 949
 		unset($all_data);
950
-	    }
951
-    	    //$last_exec['phpvmacars'] = time();
952
-    	    $last_exec[$id]['last'] = time();
953
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
954
-	    //$buffer = $Common->getData($hosts[$id]);
955
-	    if ($globalDebug) echo 'Get Data...'."\n";
956
-	    $buffer = $Common->getData($value['host']);
957
-	    $all_data = json_decode($buffer,true);
958
-	    if ($buffer != '' && is_array($all_data)) {
950
+		}
951
+			//$last_exec['phpvmacars'] = time();
952
+			$last_exec[$id]['last'] = time();
953
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
954
+		//$buffer = $Common->getData($hosts[$id]);
955
+		if ($globalDebug) echo 'Get Data...'."\n";
956
+		$buffer = $Common->getData($value['host']);
957
+		$all_data = json_decode($buffer,true);
958
+		if ($buffer != '' && is_array($all_data)) {
959 959
 		$reset = 0;
960 960
 		foreach ($all_data as $line) {
961
-	    	    $data = array();
962
-	    	    //$data['id'] = $line['id']; // id not usable
963
-	    	    $data['id'] = trim($line['flight_id']);
964
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
965
-	    	    $data['pilot_name'] = $line['pilot_name'];
966
-	    	    $data['pilot_id'] = $line['pilot_id'];
967
-	    	    $data['ident'] = trim($line['callsign']); // ident
968
-	    	    $data['altitude'] = $line['altitude']; // altitude
969
-	    	    $data['speed'] = $line['gs']; // speed
970
-	    	    $data['heading'] = $line['heading']; // heading
971
-	    	    $data['latitude'] = $line['latitude']; // lat
972
-	    	    $data['longitude'] = $line['longitude']; // long
973
-	    	    $data['verticalrate'] = ''; // verticale rate
974
-	    	    $data['squawk'] = ''; // squawk
975
-	    	    $data['emergency'] = ''; // emergency
976
-	    	    //$data['datetime'] = $line['lastupdate'];
977
-	    	    $data['last_update'] = $line['last_update'];
978
-		    $data['datetime'] = date('Y-m-d H:i:s');
979
-	    	    $data['departure_airport_icao'] = $line['departure'];
980
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
981
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
982
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
983
-    		    //$data['registration'] = $line['aircraft'];
984
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
985
-	    	    $data['aircraft_icao'] = $line['plane_type'];
986
-    		    $data['id_source'] = $id_source;
987
-	    	    $data['format_source'] = 'vam';
988
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
989
-		    $SI->add($data);
990
-		    unset($data);
961
+				$data = array();
962
+				//$data['id'] = $line['id']; // id not usable
963
+				$data['id'] = trim($line['flight_id']);
964
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
965
+				$data['pilot_name'] = $line['pilot_name'];
966
+				$data['pilot_id'] = $line['pilot_id'];
967
+				$data['ident'] = trim($line['callsign']); // ident
968
+				$data['altitude'] = $line['altitude']; // altitude
969
+				$data['speed'] = $line['gs']; // speed
970
+				$data['heading'] = $line['heading']; // heading
971
+				$data['latitude'] = $line['latitude']; // lat
972
+				$data['longitude'] = $line['longitude']; // long
973
+				$data['verticalrate'] = ''; // verticale rate
974
+				$data['squawk'] = ''; // squawk
975
+				$data['emergency'] = ''; // emergency
976
+				//$data['datetime'] = $line['lastupdate'];
977
+				$data['last_update'] = $line['last_update'];
978
+			$data['datetime'] = date('Y-m-d H:i:s');
979
+				$data['departure_airport_icao'] = $line['departure'];
980
+				//$data['departure_airport_time'] = $line['departure_time'];
981
+				$data['arrival_airport_icao'] = $line['arrival'];
982
+				//$data['arrival_airport_time'] = $line['arrival_time'];
983
+				//$data['registration'] = $line['aircraft'];
984
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
985
+				$data['aircraft_icao'] = $line['plane_type'];
986
+				$data['id_source'] = $id_source;
987
+				$data['format_source'] = 'vam';
988
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
989
+			$SI->add($data);
990
+			unset($data);
991 991
 		}
992 992
 		if ($globalDebug) echo 'No more data...'."\n";
993 993
 		unset($buffer);
994 994
 		unset($all_data);
995
-	    }
996
-    	    //$last_exec['phpvmacars'] = time();
997
-    	    $last_exec[$id]['last'] = time();
995
+		}
996
+			//$last_exec['phpvmacars'] = time();
997
+			$last_exec[$id]['last'] = time();
998 998
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
999 999
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais') {
1000
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1001
-    	    //$last_exec[$id]['last'] = time();
1000
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1001
+			//$last_exec[$id]['last'] = time();
1002 1002
 
1003
-	    //$read = array( $sockets[$id] );
1004
-	    $read = $sockets;
1005
-	    $write = NULL;
1006
-	    $e = NULL;
1007
-	    $n = socket_select($read, $write, $e, $timeout);
1008
-	    if ($e != NULL) var_dump($e);
1009
-	    if ($n > 0) {
1003
+		//$read = array( $sockets[$id] );
1004
+		$read = $sockets;
1005
+		$write = NULL;
1006
+		$e = NULL;
1007
+		$n = socket_select($read, $write, $e, $timeout);
1008
+		if ($e != NULL) var_dump($e);
1009
+		if ($n > 0) {
1010 1010
 		$reset = 0;
1011 1011
 		foreach ($read as $nb => $r) {
1012
-		    //$value = $formats[$nb];
1013
-		    $format = $globalSources[$nb]['format'];
1014
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1015
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1016
-        	    } else {
1017
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1018
-	    	    }
1019
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1020
-        	    //echo $buffer."\n";
1021
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1022
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1023
-		    $error = false;
1024
-		    //$SI::del();
1025
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1026
-		    // SBS format is CSV format
1027
-		    if ($buffer != '') {
1012
+			//$value = $formats[$nb];
1013
+			$format = $globalSources[$nb]['format'];
1014
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1015
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1016
+				} else {
1017
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1018
+				}
1019
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1020
+				//echo $buffer."\n";
1021
+			// lets play nice and handle signals such as ctrl-c/kill properly
1022
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1023
+			$error = false;
1024
+			//$SI::del();
1025
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1026
+			// SBS format is CSV format
1027
+			if ($buffer != '') {
1028 1028
 			$tt[$format] = 0;
1029 1029
 			if ($format == 'acarssbs3') {
1030
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1031
-			    $ACARS->add(trim($buffer));
1032
-			    $ACARS->deleteLiveAcarsData();
1030
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1031
+				$ACARS->add(trim($buffer));
1032
+				$ACARS->deleteLiveAcarsData();
1033 1033
 			} elseif ($format == 'raw') {
1034
-			    // AVR format
1035
-			    $data = $SBS->parse($buffer);
1036
-			    if (is_array($data)) {
1034
+				// AVR format
1035
+				$data = $SBS->parse($buffer);
1036
+				if (is_array($data)) {
1037 1037
 				$data['datetime'] = date('Y-m-d H:i:s');
1038 1038
 				$data['format_source'] = 'raw';
1039 1039
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1040
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1041
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1042
-                            }
1043
-                        } elseif ($format == 'ais') {
1044
-			    $ais_data = $AIS->parse_line(trim($buffer));
1045
-			    $data = array();
1046
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1047
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1048
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1049
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1050
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1051
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1052
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1053
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1054
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1055
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1056
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1057
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1040
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1041
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1042
+							}
1043
+						} elseif ($format == 'ais') {
1044
+				$ais_data = $AIS->parse_line(trim($buffer));
1045
+				$data = array();
1046
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1047
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1048
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1049
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1050
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1051
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1052
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1053
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1054
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1055
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1056
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1057
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1058 1058
 
1059
-			    if (isset($ais_data['timestamp'])) {
1059
+				if (isset($ais_data['timestamp'])) {
1060 1060
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1061
-			    } else {
1061
+				} else {
1062 1062
 				$data['datetime'] = date('Y-m-d H:i:s');
1063
-			    }
1064
-			    $data['format_source'] = 'aisnmea';
1065
-    			    $data['id_source'] = $id_source;
1066
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1067
-			    unset($data);
1068
-                        } elseif ($format == 'flightgearsp') {
1069
-                    	    //echo $buffer."\n";
1070
-                    	    if (strlen($buffer) > 5) {
1063
+				}
1064
+				$data['format_source'] = 'aisnmea';
1065
+					$data['id_source'] = $id_source;
1066
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1067
+				unset($data);
1068
+						} elseif ($format == 'flightgearsp') {
1069
+							//echo $buffer."\n";
1070
+							if (strlen($buffer) > 5) {
1071 1071
 				$line = explode(',',$buffer);
1072 1072
 				$data = array();
1073 1073
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1083,123 +1083,123 @@  discard block
 block discarded – undo
1083 1083
 				$data['format_source'] = 'flightgearsp';
1084 1084
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1085 1085
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1086
-			    }
1087
-                        } elseif ($format == 'acars') {
1088
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1089
-			    $ACARS->add(trim($buffer));
1090
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1091
-			    $ACARS->deleteLiveAcarsData();
1086
+				}
1087
+						} elseif ($format == 'acars') {
1088
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1089
+				$ACARS->add(trim($buffer));
1090
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1091
+				$ACARS->deleteLiveAcarsData();
1092 1092
 			} elseif ($format == 'flightgearmp') {
1093
-			    if (substr($buffer,0,1) != '#') {
1093
+				if (substr($buffer,0,1) != '#') {
1094 1094
 				$data = array();
1095 1095
 				//echo $buffer."\n";
1096 1096
 				$line = explode(' ',$buffer);
1097 1097
 				if (count($line) == 11) {
1098
-				    $userserver = explode('@',$line[0]);
1099
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1100
-				    $data['ident'] = $userserver[0];
1101
-				    $data['registration'] = $userserver[0];
1102
-				    $data['latitude'] = $line[4];
1103
-				    $data['longitude'] = $line[5];
1104
-				    $data['altitude'] = $line[6];
1105
-				    $data['datetime'] = date('Y-m-d H:i:s');
1106
-				    $aircraft_type = $line[10];
1107
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1108
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1109
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1098
+					$userserver = explode('@',$line[0]);
1099
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1100
+					$data['ident'] = $userserver[0];
1101
+					$data['registration'] = $userserver[0];
1102
+					$data['latitude'] = $line[4];
1103
+					$data['longitude'] = $line[5];
1104
+					$data['altitude'] = $line[6];
1105
+					$data['datetime'] = date('Y-m-d H:i:s');
1106
+					$aircraft_type = $line[10];
1107
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1108
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1109
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1110
+				}
1110 1111
 				}
1111
-			    }
1112 1112
 			} elseif ($format == 'beast') {
1113
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1114
-			    die;
1113
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1114
+				die;
1115 1115
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1116
-			    $line = explode("\t", $buffer);
1117
-			    for($k = 0; $k < count($line); $k=$k+2) {
1116
+				$line = explode("\t", $buffer);
1117
+				for($k = 0; $k < count($line); $k=$k+2) {
1118 1118
 				$key = $line[$k];
1119
-			        $lined[$key] = $line[$k+1];
1120
-			    }
1121
-    			    if (count($lined) > 3) {
1122
-    				$data['hex'] = $lined['hexid'];
1123
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1124
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1125
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1126
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1127
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1128
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1129
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1130
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1131
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1132
-    				$data['id_source'] = $id_source;
1133
-    				$data['format_source'] = 'tsv';
1134
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1135
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1136
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1137
-    				unset($lined);
1138
-    				unset($data);
1139
-    			    } else $error = true;
1119
+					$lined[$key] = $line[$k+1];
1120
+				}
1121
+					if (count($lined) > 3) {
1122
+					$data['hex'] = $lined['hexid'];
1123
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1124
+					$data['datetime'] = date('Y-m-d H:i:s');;
1125
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1126
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1127
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1128
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1129
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1130
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1131
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1132
+					$data['id_source'] = $id_source;
1133
+					$data['format_source'] = 'tsv';
1134
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1135
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1136
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1137
+					unset($lined);
1138
+					unset($data);
1139
+					} else $error = true;
1140 1140
 			} elseif ($format == 'aprs' && $use_aprs) {
1141
-			    if ($aprs_connect == 0) {
1141
+				if ($aprs_connect == 0) {
1142 1142
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1143 1143
 				$aprs_connect = 1;
1144
-			    }
1144
+				}
1145 1145
 			    
1146
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1146
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1147 1147
 				$aprs_last_tx = time();
1148 1148
 				$data_aprs = "# Keep alive";
1149 1149
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1150
-			    }
1150
+				}
1151 1151
 			    
1152
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1153
-			    //echo 'APRS data : '.$buffer."\n";
1154
-			    $buffer = str_replace('APRS <- ','',$buffer);
1155
-			    $buffer = str_replace('APRS -> ','',$buffer);
1156
-			    //echo $buffer."\n";
1157
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1152
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1153
+				//echo 'APRS data : '.$buffer."\n";
1154
+				$buffer = str_replace('APRS <- ','',$buffer);
1155
+				$buffer = str_replace('APRS -> ','',$buffer);
1156
+				//echo $buffer."\n";
1157
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1158 1158
 				$line = $APRS->parse($buffer);
1159 1159
 				//print_r($line);
1160 1160
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1161 1161
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && isset($line['ident'])) {
1162
-				    $aprs_last_tx = time();
1163
-				    $data = array();
1164
-				    //print_r($line);
1165
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1166
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1167
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1168
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1169
-				    $data['ident'] = $line['ident'];
1170
-				    $data['latitude'] = $line['latitude'];
1171
-				    $data['longitude'] = $line['longitude'];
1172
-				    //$data['verticalrate'] = $line[16];
1173
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1174
-				    else $data['speed'] = 0;
1175
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1176
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1177
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1178
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1179
-				    //else $data['heading'] = 0;
1180
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1181
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1182
-    				    $data['id_source'] = $id_source;
1183
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1184
-				    else $data['format_source'] = 'aprs';
1185
-				    $data['source_name'] = $line['source'];
1186
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1187
-				    else $data['source_type'] = 'flarm';
1188
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1189
-				    $currentdate = date('Y-m-d H:i:s');
1190
-				    $aprsdate = strtotime($data['datetime']);
1191
-				    // Accept data if time <= system time + 20s
1192
-				    if (($data['source_type'] == 'sbs') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1162
+					$aprs_last_tx = time();
1163
+					$data = array();
1164
+					//print_r($line);
1165
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1166
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1167
+					else $data['datetime'] = date('Y-m-d H:i:s');
1168
+					//$data['datetime'] = date('Y-m-d H:i:s');
1169
+					$data['ident'] = $line['ident'];
1170
+					$data['latitude'] = $line['latitude'];
1171
+					$data['longitude'] = $line['longitude'];
1172
+					//$data['verticalrate'] = $line[16];
1173
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1174
+					else $data['speed'] = 0;
1175
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1176
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1177
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1178
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1179
+					//else $data['heading'] = 0;
1180
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1181
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1182
+						$data['id_source'] = $id_source;
1183
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1184
+					else $data['format_source'] = 'aprs';
1185
+					$data['source_name'] = $line['source'];
1186
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1187
+					else $data['source_type'] = 'flarm';
1188
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1189
+					$currentdate = date('Y-m-d H:i:s');
1190
+					$aprsdate = strtotime($data['datetime']);
1191
+					// Accept data if time <= system time + 20s
1192
+					if (($data['source_type'] == 'sbs') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1193 1193
 					$send = $SI->add($data);
1194
-				    } elseif (isset($line['stealth'])) {
1194
+					} elseif (isset($line['stealth'])) {
1195 1195
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1196 1196
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1197
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1198
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1197
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1198
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1199 1199
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1200 1200
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1201
-				    }
1202
-				    unset($data);
1201
+					}
1202
+					unset($data);
1203 1203
 				} 
1204 1204
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1205 1205
 					echo '!! Weather Station not yet supported'."\n";
@@ -1209,12 +1209,12 @@  discard block
 block discarded – undo
1209 1209
 				}
1210 1210
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1211 1211
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1212
-			    }
1212
+				}
1213 1213
 			} else {
1214
-			    $line = explode(',', $buffer);
1215
-    			    if (count($line) > 20) {
1216
-    			    	$data['hex'] = $line[4];
1217
-    				/*
1214
+				$line = explode(',', $buffer);
1215
+					if (count($line) > 20) {
1216
+						$data['hex'] = $line[4];
1217
+					/*
1218 1218
     				$data['datetime'] = $line[6].' '.$line[7];
1219 1219
     					date_default_timezone_set($globalTimezone);
1220 1220
     					$datetime = new DateTime($data['datetime']);
@@ -1222,29 +1222,29 @@  discard block
 block discarded – undo
1222 1222
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1223 1223
     					date_default_timezone_set('UTC');
1224 1224
     				*/
1225
-    				// Force datetime to current UTC datetime
1226
-    				date_default_timezone_set('UTC');
1227
-    				$data['datetime'] = date('Y-m-d H:i:s');
1228
-    				$data['ident'] = trim($line[10]);
1229
-    				$data['latitude'] = $line[14];
1230
-    				$data['longitude'] = $line[15];
1231
-    				$data['verticalrate'] = $line[16];
1232
-    				$data['emergency'] = $line[20];
1233
-    				$data['speed'] = $line[12];
1234
-    				$data['squawk'] = $line[17];
1235
-    				$data['altitude'] = $line[11];
1236
-    				$data['heading'] = $line[13];
1237
-    				$data['ground'] = $line[21];
1238
-    				$data['emergency'] = $line[19];
1239
-    				$data['format_source'] = 'sbs';
1225
+					// Force datetime to current UTC datetime
1226
+					date_default_timezone_set('UTC');
1227
+					$data['datetime'] = date('Y-m-d H:i:s');
1228
+					$data['ident'] = trim($line[10]);
1229
+					$data['latitude'] = $line[14];
1230
+					$data['longitude'] = $line[15];
1231
+					$data['verticalrate'] = $line[16];
1232
+					$data['emergency'] = $line[20];
1233
+					$data['speed'] = $line[12];
1234
+					$data['squawk'] = $line[17];
1235
+					$data['altitude'] = $line[11];
1236
+					$data['heading'] = $line[13];
1237
+					$data['ground'] = $line[21];
1238
+					$data['emergency'] = $line[19];
1239
+					$data['format_source'] = 'sbs';
1240 1240
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1241
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1242
-    				$data['id_source'] = $id_source;
1243
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1244
-    				else $error = true;
1245
-    				unset($data);
1246
-    			    } else $error = true;
1247
-			    if ($error) {
1241
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1242
+					$data['id_source'] = $id_source;
1243
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1244
+					else $error = true;
1245
+					unset($data);
1246
+					} else $error = true;
1247
+				if ($error) {
1248 1248
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1249 1249
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1250 1250
 				} else {
@@ -1260,13 +1260,13 @@  discard block
 block discarded – undo
1260 1260
 					connect_all($sourceer);
1261 1261
 					$sourceer = array();
1262 1262
 				}
1263
-			    }
1263
+				}
1264 1264
 			}
1265 1265
 			// Sleep for xxx microseconds
1266 1266
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1267
-		    } else {
1267
+			} else {
1268 1268
 			if ($format == 'flightgearmp') {
1269
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1269
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1270 1270
 				//@socket_close($r);
1271 1271
 				sleep($globalMinFetch);
1272 1272
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1275,9 +1275,9 @@  discard block
 block discarded – undo
1275 1275
 				break;
1276 1276
 				
1277 1277
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1278
-			    if (isset($tt[$format])) $tt[$format]++;
1279
-			    else $tt[$format] = 0;
1280
-			    if ($tt[$format] > 30) {
1278
+				if (isset($tt[$format])) $tt[$format]++;
1279
+				else $tt[$format] = 0;
1280
+				if ($tt[$format] > 30) {
1281 1281
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1282 1282
 				//@socket_close($r);
1283 1283
 				sleep(2);
@@ -1288,23 +1288,23 @@  discard block
 block discarded – undo
1288 1288
 				//connect_all($globalSources);
1289 1289
 				$tt[$format]=0;
1290 1290
 				break;
1291
-			    }
1291
+				}
1292
+			}
1292 1293
 			}
1293
-		    }
1294 1294
 		}
1295
-	    } else {
1295
+		} else {
1296 1296
 		$error = socket_strerror(socket_last_error());
1297 1297
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1298 1298
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1299 1299
 			if (isset($globalDebug)) echo "Restarting...\n";
1300 1300
 			// Restart the script if possible
1301 1301
 			if (is_array($sockets)) {
1302
-			    if ($globalDebug) echo "Shutdown all sockets...";
1302
+				if ($globalDebug) echo "Shutdown all sockets...";
1303 1303
 			    
1304
-			    foreach ($sockets as $sock) {
1304
+				foreach ($sockets as $sock) {
1305 1305
 				@socket_shutdown($sock,2);
1306 1306
 				@socket_close($sock);
1307
-			    }
1307
+				}
1308 1308
 			    
1309 1309
 			}
1310 1310
 			if ($globalDebug) echo "Restart all connections...";
@@ -1315,13 +1315,13 @@  discard block
 block discarded – undo
1315 1315
 			if ($reset > 40) exit('Too many attempts...');
1316 1316
 			connect_all($globalSources);
1317 1317
 		}
1318
-	    }
1318
+		}
1319 1319
 	}
1320 1320
 	if ($globalDaemon === false) {
1321
-	    if ($globalDebug) echo 'Check all...'."\n";
1322
-	    $SI->checkAll();
1321
+		if ($globalDebug) echo 'Check all...'."\n";
1322
+		$SI->checkAll();
1323
+	}
1323 1324
 	}
1324
-    }
1325 1325
 }
1326 1326
 
1327 1327
 ?>
Please login to merge, or discard this patch.
Braces   +716 added lines, -247 removed lines patch added patch discarded remove patch
@@ -13,13 +13,17 @@  discard block
 block discarded – undo
13 13
 require_once(dirname(__FILE__).'/../require/class.SBS.php');
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
16
+if (isset($globalTracker) && $globalTracker) {
17
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+}
17 19
 if (isset($globalMarine) && $globalMarine) {
18 20
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
19 21
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 22
 }
21 23
 
22
-if (!isset($globalDebug)) $globalDebug = FALSE;
24
+if (!isset($globalDebug)) {
25
+	$globalDebug = FALSE;
26
+}
23 27
 
24 28
 // Check if schema is at latest version
25 29
 $Connection = new Connection();
@@ -59,19 +63,30 @@  discard block
 block discarded – undo
59 63
     $globalSources = array();
60 64
     $globalSources[] = array('host' => $options['source']);
61 65
 }
62
-if (isset($options['server'])) $globalServer = TRUE;
63
-if (isset($options['idsource'])) $id_source = $options['idsource'];
64
-else $id_source = 1;
66
+if (isset($options['server'])) {
67
+	$globalServer = TRUE;
68
+}
69
+if (isset($options['idsource'])) {
70
+	$id_source = $options['idsource'];
71
+} else {
72
+	$id_source = 1;
73
+}
65 74
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
75
+    if ($globalDebug) {
76
+    	echo "Using Server Mode\n";
77
+    }
67 78
     $SI=new SpotterServer();
68 79
 /*
69 80
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
70 81
     $SI = new adsb2aprs();
71 82
     $SI->connect();
72 83
 */
73
-} else $SI=new SpotterImport($Connection->db);
74
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
84
+} else {
85
+	$SI=new SpotterImport($Connection->db);
86
+}
87
+if (isset($globalTracker) && $globalTracker) {
88
+	$TI = new TrackerImport($Connection->db);
89
+}
75 90
 if (isset($globalMarine) && $globalMarine) {
76 91
     $AIS = new AIS();
77 92
     $MI = new MarineImport($Connection->db);
@@ -93,7 +108,9 @@  discard block
 block discarded – undo
93 108
 }
94 109
 
95 110
 // let's try and connect
96
-if ($globalDebug) echo "Connecting...\n";
111
+if ($globalDebug) {
112
+	echo "Connecting...\n";
113
+}
97 114
 $use_aprs = false;
98 115
 $aprs_full = false;
99 116
 $reset = 0;
@@ -102,7 +119,9 @@  discard block
 block discarded – undo
102 119
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103 120
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104 121
     $reset++;
105
-    if ($globalDebug) echo 'Connect to all...'."\n";
122
+    if ($globalDebug) {
123
+    	echo 'Connect to all...'."\n";
124
+    }
106 125
     foreach ($hosts as $id => $value) {
107 126
 	$host = $value['host'];
108 127
 	$globalSources[$id]['last_exec'] = 0;
@@ -112,27 +131,37 @@  discard block
 block discarded – undo
112 131
         	//$formats[$id] = 'deltadbtxt';
113 132
         	$globalSources[$id]['format'] = 'deltadbtxt';
114 133
         	//$last_exec['deltadbtxt'] = 0;
115
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
134
+        	if ($globalDebug) {
135
+        		echo "Connect to deltadb source (".$host.")...\n";
136
+        	}
116 137
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117 138
         	//$formats[$id] = 'vatsimtxt';
118 139
         	$globalSources[$id]['format'] = 'vatsimtxt';
119 140
         	//$last_exec['vatsimtxt'] = 0;
120
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
141
+        	if ($globalDebug) {
142
+        		echo "Connect to vatsim source (".$host.")...\n";
143
+        	}
121 144
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122 145
         	//$formats[$id] = 'aircraftlistjson';
123 146
         	$globalSources[$id]['format'] = 'aircraftlistjson';
124 147
         	//$last_exec['aircraftlistjson'] = 0;
125
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
148
+        	if ($globalDebug) {
149
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
150
+        	}
126 151
     	    } else if (preg_match('/opensky/i',$host)) {
127 152
         	//$formats[$id] = 'aircraftlistjson';
128 153
         	$globalSources[$id]['format'] = 'opensky';
129 154
         	//$last_exec['aircraftlistjson'] = 0;
130
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
155
+        	if ($globalDebug) {
156
+        		echo "Connect to opensky source (".$host.")...\n";
157
+        	}
131 158
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132 159
         	//$formats[$id] = 'radarvirtueljson';
133 160
         	$globalSources[$id]['format'] = 'radarvirtueljson';
134 161
         	//$last_exec['radarvirtueljson'] = 0;
135
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
162
+        	if ($globalDebug) {
163
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
164
+        	}
136 165
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137 166
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138 167
         	    exit(0);
@@ -141,7 +170,9 @@  discard block
 block discarded – undo
141 170
         	//$formats[$id] = 'planeupdatefaa';
142 171
         	$globalSources[$id]['format'] = 'planeupdatefaa';
143 172
         	//$last_exec['planeupdatefaa'] = 0;
144
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
173
+        	if ($globalDebug) {
174
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
175
+        	}
145 176
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146 177
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147 178
         	    exit(0);
@@ -150,26 +181,36 @@  discard block
 block discarded – undo
150 181
         	//$formats[$id] = 'phpvmacars';
151 182
         	$globalSources[$id]['format'] = 'phpvmacars';
152 183
         	//$last_exec['phpvmacars'] = 0;
153
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
184
+        	if ($globalDebug) {
185
+        		echo "Connect to phpvmacars source (".$host.")...\n";
186
+        	}
154 187
             } else if (preg_match('/VAM-json.php$/i',$host)) {
155 188
         	//$formats[$id] = 'phpvmacars';
156 189
         	$globalSources[$id]['format'] = 'vam';
157
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
190
+        	if ($globalDebug) {
191
+        		echo "Connect to Vam source (".$host.")...\n";
192
+        	}
158 193
             } else if (preg_match('/whazzup/i',$host)) {
159 194
         	//$formats[$id] = 'whazzup';
160 195
         	$globalSources[$id]['format'] = 'whazzup';
161 196
         	//$last_exec['whazzup'] = 0;
162
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
197
+        	if ($globalDebug) {
198
+        		echo "Connect to whazzup source (".$host.")...\n";
199
+        	}
163 200
             } else if (preg_match('/recentpireps/i',$host)) {
164 201
         	//$formats[$id] = 'pirepsjson';
165 202
         	$globalSources[$id]['format'] = 'pirepsjson';
166 203
         	//$last_exec['pirepsjson'] = 0;
167
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
204
+        	if ($globalDebug) {
205
+        		echo "Connect to pirepsjson source (".$host.")...\n";
206
+        	}
168 207
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169 208
         	//$formats[$id] = 'fr24json';
170 209
         	$globalSources[$id]['format'] = 'fr24json';
171 210
         	//$last_exec['fr24json'] = 0;
172
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
211
+        	if ($globalDebug) {
212
+        		echo "Connect to fr24 source (".$host.")...\n";
213
+        	}
173 214
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174 215
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175 216
         	    exit(0);
@@ -178,7 +219,9 @@  discard block
 block discarded – undo
178 219
         	//$formats[$id] = 'fr24json';
179 220
         	$globalSources[$id]['format'] = 'myshiptracking';
180 221
         	//$last_exec['fr24json'] = 0;
181
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to myshiptracking source (".$host.")...\n";
224
+        	}
182 225
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183 226
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184 227
         	    exit(0);
@@ -187,17 +230,24 @@  discard block
 block discarded – undo
187 230
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188 231
         	//$formats[$id] = 'tsv';
189 232
         	$globalSources[$id]['format'] = 'tsv';
190
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
233
+        	if ($globalDebug) {
234
+        		echo "Connect to tsv source (".$host.")...\n";
235
+        	}
191 236
             }
192 237
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193 238
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194 239
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
195 240
     		    if ($idf !== false) {
196 241
     			$httpfeeds[$id] = $idf;
197
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
242
+        		if ($globalDebug) {
243
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
244
+        		}
245
+    		    } elseif ($globalDebug) {
246
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
198 247
     		    }
199
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
248
+    		} elseif ($globalDebug) {
249
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
250
+    		}
201 251
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202 252
 	    $hostport = explode(':',$host);
203 253
 	    if (isset($hostport[1])) {
@@ -235,17 +285,25 @@  discard block
 block discarded – undo
235 285
         		//$formats[$id] = 'beast';
236 286
         		$globalSources[$id]['format'] = 'beast';
237 287
 		    //} else $formats[$id] = 'sbs';
238
-		    } else $globalSources[$id]['format'] = 'sbs';
288
+		    } else {
289
+		    	$globalSources[$id]['format'] = 'sbs';
290
+		    }
239 291
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
240 292
 		}
241
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
293
+		if ($globalDebug) {
294
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
295
+		}
242 296
             } else {
243
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
297
+		if ($globalDebug) {
298
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
299
+		}
244 300
     	    }
245 301
         }
246 302
     }
247 303
 }
248
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
304
+if (!isset($globalMinFetch)) {
305
+	$globalMinFetch = 15;
306
+}
249 307
 
250 308
 // Initialize all
251 309
 $status = array();
@@ -254,13 +312,19 @@  discard block
 block discarded – undo
254 312
 $formats = array();
255 313
 $last_exec = array();
256 314
 $time = time();
257
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
258
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
259
-else $timeout = 20;
315
+if (isset($globalSourcesTimeout)) {
316
+	$timeout = $globalSourcesTimeOut;
317
+} else if (isset($globalSBS1TimeOut)) {
318
+	$timeout = $globalSBS1TimeOut;
319
+} else {
320
+	$timeout = 20;
321
+}
260 322
 $errno = '';
261 323
 $errstr='';
262 324
 
263
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
325
+if (!isset($globalDaemon)) {
326
+	$globalDaemon = TRUE;
327
+}
264 328
 /* Initiate connections to all the hosts simultaneously */
265 329
 //connect_all($hosts);
266 330
 //connect_all($globalSources);
@@ -286,7 +350,9 @@  discard block
 block discarded – undo
286 350
     if (isset($source['format']) && $source['format'] == 'aprs') {
287 351
 	$aprs_connect = 0;
288 352
 	$use_aprs = true;
289
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
353
+	if (isset($source['port']) && $source['port'] == '10152') {
354
+		$aprs_full = true;
355
+	}
290 356
 	break;
291 357
     }
292 358
 }
@@ -297,26 +363,49 @@  discard block
 block discarded – undo
297 363
 	$aprs_connect = 0;
298 364
 	$aprs_keep = 120;
299 365
 	$aprs_last_tx = time();
300
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
301
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
302
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
303
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
304
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
305
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
306
-	if ($aprs_full) $aprs_filter = '';
307
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
308
-	else $aprs_pass = '-1';
366
+	if (isset($globalAPRSversion)) {
367
+		$aprs_version = $globalAPRSversion;
368
+	} else {
369
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
370
+	}
371
+	if (isset($globalAPRSssid)) {
372
+		$aprs_ssid = $globalAPRSssid;
373
+	} else {
374
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
375
+	}
376
+	if (isset($globalAPRSfilter)) {
377
+		$aprs_filter = $globalAPRSfilter;
378
+	} else {
379
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
380
+	}
381
+	if ($aprs_full) {
382
+		$aprs_filter = '';
383
+	}
384
+	if (isset($globalAPRSpass)) {
385
+		$aprs_pass = $globalAPRSpass;
386
+	} else {
387
+		$aprs_pass = '-1';
388
+	}
309 389
 
310
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
311
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
390
+	if ($aprs_filter != '') {
391
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
392
+	} else {
393
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
394
+	}
312 395
 	echo $aprs_login."\n";
313 396
 }
314 397
 
315 398
 // connected - lets do some work
316
-if ($globalDebug) echo "Connected!\n";
399
+if ($globalDebug) {
400
+	echo "Connected!\n";
401
+}
317 402
 sleep(1);
318
-if ($globalDebug) echo "SCAN MODE \n\n";
319
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
403
+if ($globalDebug) {
404
+	echo "SCAN MODE \n\n";
405
+}
406
+if (!isset($globalCronEnd)) {
407
+	$globalCronEnd = 60;
408
+}
320 409
 $endtime = time()+$globalCronEnd;
321 410
 $i = 1;
322 411
 $tt = array();
@@ -330,10 +419,14 @@  discard block
 block discarded – undo
330 419
 
331 420
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
332 421
 while ($i > 0) {
333
-    if (!$globalDaemon) $i = $endtime-time();
422
+    if (!$globalDaemon) {
423
+    	$i = $endtime-time();
424
+    }
334 425
     // Delete old ATC
335 426
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
336
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
427
+	if ($globalDebug) {
428
+		echo 'Delete old ATC...'."\n";
429
+	}
337 430
         $ATC->deleteOldATC();
338 431
     }
339 432
     
@@ -341,10 +434,14 @@  discard block
 block discarded – undo
341 434
     if (count($last_exec) == count($globalSources)) {
342 435
 	$max = $globalMinFetch;
343 436
 	foreach ($last_exec as $last) {
344
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
437
+	    if ((time() - $last['last']) < $max) {
438
+	    	$max = time() - $last['last'];
439
+	    }
345 440
 	}
346 441
 	if ($max != $globalMinFetch) {
347
-	    if ($globalDebug) echo 'Sleeping...'."\n";
442
+	    if ($globalDebug) {
443
+	    	echo 'Sleeping...'."\n";
444
+	    }
348 445
 	    sleep($globalMinFetch-$max+2);
349 446
 	}
350 447
     }
@@ -353,11 +450,15 @@  discard block
 block discarded – undo
353 450
     //foreach ($formats as $id => $value) {
354 451
     foreach ($globalSources as $id => $value) {
355 452
 	date_default_timezone_set('UTC');
356
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
453
+	if (!isset($last_exec[$id]['last'])) {
454
+		$last_exec[$id]['last'] = 0;
455
+	}
357 456
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
358 457
 	    //$buffer = $Common->getData($hosts[$id]);
359 458
 	    $buffer = $Common->getData($value['host']);
360
-	    if ($buffer != '') $reset = 0;
459
+	    if ($buffer != '') {
460
+	    	$reset = 0;
461
+	    }
361 462
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
362 463
 	    $buffer = explode('\n',$buffer);
363 464
 	    foreach ($buffer as $line) {
@@ -366,19 +467,38 @@  discard block
 block discarded – undo
366 467
 	            $data = array();
367 468
 	            $data['hex'] = $line[1]; // hex
368 469
 	            $data['ident'] = $line[2]; // ident
369
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
370
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
371
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
372
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
373
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
470
+	            if (isset($line[3])) {
471
+	            	$data['altitude'] = $line[3];
472
+	            }
473
+	            // altitude
474
+	            if (isset($line[4])) {
475
+	            	$data['speed'] = $line[4];
476
+	            }
477
+	            // speed
478
+	            if (isset($line[5])) {
479
+	            	$data['heading'] = $line[5];
480
+	            }
481
+	            // heading
482
+	            if (isset($line[6])) {
483
+	            	$data['latitude'] = $line[6];
484
+	            }
485
+	            // lat
486
+	            if (isset($line[7])) {
487
+	            	$data['longitude'] = $line[7];
488
+	            }
489
+	            // long
374 490
 	            $data['verticalrate'] = ''; // vertical rate
375 491
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
376 492
 	            $data['emergency'] = ''; // emergency
377 493
 		    $data['datetime'] = date('Y-m-d H:i:s');
378 494
 		    $data['format_source'] = 'deltadbtxt';
379 495
     		    $data['id_source'] = $id_source;
380
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
381
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
496
+		    if (isset($value['name']) && $value['name'] != '') {
497
+		    	$data['source_name'] = $value['name'];
498
+		    }
499
+		    if (isset($value['sourcestats'])) {
500
+		    	$data['sourcestats'] = $value['sourcestats'];
501
+		    }
382 502
     		    $SI->add($data);
383 503
 		    unset($data);
384 504
     		}
@@ -388,7 +508,9 @@  discard block
 block discarded – undo
388 508
 	    date_default_timezone_set('CET');
389 509
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
390 510
 	    date_default_timezone_set('UTC');
391
-	    if ($buffer != '') $reset = 0;
511
+	    if ($buffer != '') {
512
+	    	$reset = 0;
513
+	    }
392 514
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
393 515
 	    $buffer = explode('\n',$buffer);
394 516
 	    foreach ($buffer as $line) {
@@ -397,16 +519,36 @@  discard block
 block discarded – undo
397 519
 		    $add = false;
398 520
 		    $ais_data = $AIS->parse_line(trim($line));
399 521
 		    $data = array();
400
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
401
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
402
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
403
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
404
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
405
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
406
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
407
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
408
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
409
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
522
+		    if (isset($ais_data['ident'])) {
523
+		    	$data['ident'] = $ais_data['ident'];
524
+		    }
525
+		    if (isset($ais_data['mmsi'])) {
526
+		    	$data['mmsi'] = $ais_data['mmsi'];
527
+		    }
528
+		    if (isset($ais_data['speed'])) {
529
+		    	$data['speed'] = $ais_data['speed'];
530
+		    }
531
+		    if (isset($ais_data['heading'])) {
532
+		    	$data['heading'] = $ais_data['heading'];
533
+		    }
534
+		    if (isset($ais_data['latitude'])) {
535
+		    	$data['latitude'] = $ais_data['latitude'];
536
+		    }
537
+		    if (isset($ais_data['longitude'])) {
538
+		    	$data['longitude'] = $ais_data['longitude'];
539
+		    }
540
+		    if (isset($ais_data['status'])) {
541
+		    	$data['status'] = $ais_data['status'];
542
+		    }
543
+		    if (isset($ais_data['type'])) {
544
+		    	$data['type'] = $ais_data['type'];
545
+		    }
546
+		    if (isset($ais_data['imo'])) {
547
+		    	$data['imo'] = $ais_data['imo'];
548
+		    }
549
+		    if (isset($ais_data['callsign'])) {
550
+		    	$data['callsign'] = $ais_data['callsign'];
551
+		    }
410 552
 		    if (isset($ais_data['timestamp'])) {
411 553
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
412 554
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -421,7 +563,9 @@  discard block
 block discarded – undo
421 563
     		    $data['id_source'] = $id_source;
422 564
 		    print_r($data);
423 565
 		    echo 'Add...'."\n";
424
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
566
+		    if ($add && $ais_data['mmsi_type'] == 'Ship') {
567
+		    	$MI->add($data);
568
+		    }
425 569
 		    unset($data);
426 570
 		}
427 571
     	    }
@@ -441,18 +585,42 @@  discard block
 block discarded – undo
441 585
 			if ($line != '') {
442 586
 			    $ais_data = $AIS->parse_line(trim($line));
443 587
 			    $data = array();
444
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
445
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
446
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
447
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
448
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
449
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
450
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
451
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
452
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
453
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
454
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
455
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
588
+			    if (isset($ais_data['ident'])) {
589
+			    	$data['ident'] = $ais_data['ident'];
590
+			    }
591
+			    if (isset($ais_data['mmsi'])) {
592
+			    	$data['mmsi'] = $ais_data['mmsi'];
593
+			    }
594
+			    if (isset($ais_data['speed'])) {
595
+			    	$data['speed'] = $ais_data['speed'];
596
+			    }
597
+			    if (isset($ais_data['heading'])) {
598
+			    	$data['heading'] = $ais_data['heading'];
599
+			    }
600
+			    if (isset($ais_data['latitude'])) {
601
+			    	$data['latitude'] = $ais_data['latitude'];
602
+			    }
603
+			    if (isset($ais_data['longitude'])) {
604
+			    	$data['longitude'] = $ais_data['longitude'];
605
+			    }
606
+			    if (isset($ais_data['status'])) {
607
+			    	$data['status'] = $ais_data['status'];
608
+			    }
609
+			    if (isset($ais_data['type'])) {
610
+			    	$data['type'] = $ais_data['type'];
611
+			    }
612
+			    if (isset($ais_data['imo'])) {
613
+			    	$data['imo'] = $ais_data['imo'];
614
+			    }
615
+			    if (isset($ais_data['callsign'])) {
616
+			    	$data['callsign'] = $ais_data['callsign'];
617
+			    }
618
+			    if (isset($ais_data['destination'])) {
619
+			    	$data['arrival_code'] = $ais_data['destination'];
620
+			    }
621
+			    if (isset($ais_data['eta_ts'])) {
622
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
623
+			    }
456 624
 			    if (isset($ais_data['timestamp'])) {
457 625
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
458 626
 			    } else {
@@ -460,7 +628,9 @@  discard block
 block discarded – undo
460 628
 			    }
461 629
 			    $data['format_source'] = 'aisnmeahttp';
462 630
 			    $data['id_source'] = $id_source;
463
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
631
+			    if ($ais_data['mmsi_type'] == 'Ship') {
632
+			    	$MI->add($data);
633
+			    }
464 634
 			    unset($data);
465 635
 			}
466 636
 		    }
@@ -509,7 +679,9 @@  discard block
 block discarded – undo
509 679
 			    $data['callsign'] = $line['callsign'];
510 680
 			    $data['mmsi'] = $line['mmsi'];
511 681
 			    $data['speed'] = $line['sog'];
512
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
682
+			    if ($line['heading'] != '511') {
683
+			    	$data['heading'] = $line['heading'];
684
+			    }
513 685
 			    $data['latitude'] = $line['latitude'];
514 686
 			    $data['longitude'] = $line['longitude'];
515 687
 			    $data['type_id'] = $line['shiptype'];
@@ -529,7 +701,9 @@  discard block
 block discarded – undo
529 701
 	    echo 'download...';
530 702
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
531 703
 	    echo 'done !'."\n";
532
-	    if ($buffer != '') $reset = 0;
704
+	    if ($buffer != '') {
705
+	    	$reset = 0;
706
+	    }
533 707
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
534 708
 	    $buffer = explode('\n',$buffer);
535 709
 	    foreach ($buffer as $line) {
@@ -573,16 +747,28 @@  discard block
 block discarded – undo
573 747
     		    $line = explode(':', $line);
574 748
     		    if (count($line) > 30 && $line[0] != 'callsign') {
575 749
 			$data = array();
576
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
577
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
750
+			if (isset($line[37]) && $line[37] != '') {
751
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
752
+			} else {
753
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
754
+			}
578 755
 			$data['pilot_id'] = $line[1];
579 756
 			$data['pilot_name'] = $line[2];
580 757
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
581 758
 			$data['ident'] = $line[0]; // ident
582
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
759
+			if ($line[7] != '' && $line[7] != 0) {
760
+				$data['altitude'] = $line[7];
761
+			}
762
+			// altitude
583 763
 			$data['speed'] = $line[8]; // speed
584
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
585
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
764
+			if (isset($line[45])) {
765
+				$data['heading'] = $line[45];
766
+			}
767
+			// heading
768
+			elseif (isset($line[38])) {
769
+				$data['heading'] = $line[38];
770
+			}
771
+			// heading
586 772
 			$data['latitude'] = $line[5]; // lat
587 773
 	        	$data['longitude'] = $line[6]; // long
588 774
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -598,7 +784,9 @@  discard block
 block discarded – undo
598 784
 			$data['frequency'] = $line[4];
599 785
 			$data['type'] = $line[18];
600 786
 			$data['range'] = $line[19];
601
-			if (isset($line[35])) $data['info'] = $line[35];
787
+			if (isset($line[35])) {
788
+				$data['info'] = $line[35];
789
+			}
602 790
     			$data['id_source'] = $id_source;
603 791
 	    		//$data['arrival_airport_time'] = ;
604 792
 	    		if ($line[9] != '') {
@@ -612,24 +800,41 @@  discard block
 block discarded – undo
612 800
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
613 801
 	    		*/
614 802
 	    		$data['format_source'] = $value['format'];
615
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
616
-    			if ($line[3] == 'PILOT') $SI->add($data);
617
-			elseif ($line[3] == 'ATC') {
803
+			if (isset($value['name']) && $value['name'] != '') {
804
+				$data['source_name'] = $value['name'];
805
+			}
806
+    			if ($line[3] == 'PILOT') {
807
+    				$SI->add($data);
808
+    			} elseif ($line[3] == 'ATC') {
618 809
 				//print_r($data);
619 810
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
620 811
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
621 812
 				$typec = substr($data['ident'],-3);
622
-				if ($typec == 'APP') $data['type'] = 'Approach';
623
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
624
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
625
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
626
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
627
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
628
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
629
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
630
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
631
-				if (!isset($data['source_name'])) $data['source_name'] = '';
632
-				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
813
+				if ($typec == 'APP') {
814
+					$data['type'] = 'Approach';
815
+				} elseif ($typec == 'TWR') {
816
+					$data['type'] = 'Tower';
817
+				} elseif ($typec == 'OBS') {
818
+					$data['type'] = 'Observer';
819
+				} elseif ($typec == 'GND') {
820
+					$data['type'] = 'Ground';
821
+				} elseif ($typec == 'DEL') {
822
+					$data['type'] = 'Delivery';
823
+				} elseif ($typec == 'DEP') {
824
+					$data['type'] = 'Departure';
825
+				} elseif ($typec == 'FSS') {
826
+					$data['type'] = 'Flight Service Station';
827
+				} elseif ($typec == 'CTR') {
828
+					$data['type'] = 'Control Radar or Centre';
829
+				} elseif ($data['type'] == '') {
830
+					$data['type'] = 'Observer';
831
+				}
832
+				if (!isset($data['source_name'])) {
833
+					$data['source_name'] = '';
834
+				}
835
+				if (isset($ATC)) {
836
+					echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
837
+				}
633 838
 			}
634 839
     			unset($data);
635 840
     		    }
@@ -648,26 +853,55 @@  discard block
 block discarded – undo
648 853
 		foreach ($all_data['acList'] as $line) {
649 854
 		    $data = array();
650 855
 		    $data['hex'] = $line['Icao']; // hex
651
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
652
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
653
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
654
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
655
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
656
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
856
+		    if (isset($line['Call'])) {
857
+		    	$data['ident'] = $line['Call'];
858
+		    }
859
+		    // ident
860
+		    if (isset($line['Alt'])) {
861
+		    	$data['altitude'] = $line['Alt'];
862
+		    }
863
+		    // altitude
864
+		    if (isset($line['Spd'])) {
865
+		    	$data['speed'] = $line['Spd'];
866
+		    }
867
+		    // speed
868
+		    if (isset($line['Trak'])) {
869
+		    	$data['heading'] = $line['Trak'];
870
+		    }
871
+		    // heading
872
+		    if (isset($line['Lat'])) {
873
+		    	$data['latitude'] = $line['Lat'];
874
+		    }
875
+		    // lat
876
+		    if (isset($line['Long'])) {
877
+		    	$data['longitude'] = $line['Long'];
878
+		    }
879
+		    // long
657 880
 		    //$data['verticalrate'] = $line['']; // verticale rate
658
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
881
+		    if (isset($line['Sqk'])) {
882
+		    	$data['squawk'] = $line['Sqk'];
883
+		    }
884
+		    // squawk
659 885
 		    $data['emergency'] = ''; // emergency
660
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
886
+		    if (isset($line['Reg'])) {
887
+		    	$data['registration'] = $line['Reg'];
888
+		    }
661 889
 		    /*
662 890
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
663 891
 		    else $data['datetime'] = date('Y-m-d H:i:s');
664 892
 		    */
665 893
 		    $data['datetime'] = date('Y-m-d H:i:s');
666
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
894
+		    if (isset($line['Type'])) {
895
+		    	$data['aircraft_icao'] = $line['Type'];
896
+		    }
667 897
 	    	    $data['format_source'] = 'aircraftlistjson';
668 898
 		    $data['id_source'] = $id_source;
669
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
670
-		    if (isset($data['datetime'])) $SI->add($data);
899
+		    if (isset($value['name']) && $value['name'] != '') {
900
+		    	$data['source_name'] = $value['name'];
901
+		    }
902
+		    if (isset($data['datetime'])) {
903
+		    	$SI->add($data);
904
+		    }
671 905
 		    unset($data);
672 906
 		}
673 907
 	    } else {
@@ -687,7 +921,9 @@  discard block
 block discarded – undo
687 921
 		    $data['datetime'] = date('Y-m-d H:i:s');
688 922
 	    	    $data['format_source'] = 'aircraftlistjson';
689 923
     		    $data['id_source'] = $id_source;
690
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
924
+		    if (isset($value['name']) && $value['name'] != '') {
925
+		    	$data['source_name'] = $value['name'];
926
+		    }
691 927
 		    $SI->add($data);
692 928
 		    unset($data);
693 929
 		}
@@ -723,7 +959,9 @@  discard block
 block discarded – undo
723 959
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
724 960
 	    	    $data['format_source'] = 'planeupdatefaa';
725 961
     		    $data['id_source'] = $id_source;
726
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
962
+		    if (isset($value['name']) && $value['name'] != '') {
963
+		    	$data['source_name'] = $value['name'];
964
+		    }
727 965
 		    $SI->add($data);
728 966
 		    unset($data);
729 967
 		}
@@ -763,7 +1001,9 @@  discard block
 block discarded – undo
763 1001
 	    //$buffer = $Common->getData($hosts[$id]);
764 1002
 	    $buffer = $Common->getData($value['host']);
765 1003
 	    $all_data = json_decode($buffer,true);
766
-	    if (!empty($all_data)) $reset = 0;
1004
+	    if (!empty($all_data)) {
1005
+	    	$reset = 0;
1006
+	    }
767 1007
 	    foreach ($all_data as $key => $line) {
768 1008
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
769 1009
 		    $data = array();
@@ -784,7 +1024,9 @@  discard block
 block discarded – undo
784 1024
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
785 1025
 	    	    $data['format_source'] = 'fr24json';
786 1026
     		    $data['id_source'] = $id_source;
787
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1027
+		    if (isset($value['name']) && $value['name'] != '') {
1028
+		    	$data['source_name'] = $value['name'];
1029
+		    }
788 1030
 		    $SI->add($data);
789 1031
 		    unset($data);
790 1032
 		}
@@ -808,23 +1050,39 @@  discard block
 block discarded – undo
808 1050
 		    if (isset($line['inf'])) {
809 1051
 			$data = array();
810 1052
 			$data['hex'] = $line['inf']['ia'];
811
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1053
+			if (isset($line['inf']['cs'])) {
1054
+				$data['ident'] = $line['inf']['cs'];
1055
+			}
1056
+			//$line[13]
812 1057
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
813
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
814
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1058
+	    		if (isset($line['inf']['gs'])) {
1059
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1060
+	    		}
1061
+	    		// speed
1062
+	    		if (isset($line['inf']['tr'])) {
1063
+	    			$data['heading'] = $line['inf']['tr'];
1064
+	    		}
1065
+	    		// heading
815 1066
 	    		$data['latitude'] = $line['pt'][0]; // lat
816 1067
 	    		$data['longitude'] = $line['pt'][1]; // long
817 1068
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
818
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1069
+	    		if (isset($line['inf']['sq'])) {
1070
+	    			$data['squawk'] = $line['inf']['sq'];
1071
+	    		}
1072
+	    		// squawk
819 1073
 	    		//$data['aircraft_icao'] = $line[8];
820
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1074
+	    		if (isset($line['inf']['rc'])) {
1075
+	    			$data['registration'] = $line['inf']['rc'];
1076
+	    		}
821 1077
 			//$data['departure_airport_iata'] = $line[11];
822 1078
 			//$data['arrival_airport_iata'] = $line[12];
823 1079
 	    		//$data['emergency'] = ''; // emergency
824 1080
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
825 1081
 	    		$data['format_source'] = 'radarvirtueljson';
826 1082
     			$data['id_source'] = $id_source;
827
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1083
+			if (isset($value['name']) && $value['name'] != '') {
1084
+				$data['source_name'] = $value['name'];
1085
+			}
828 1086
 			$SI->add($data);
829 1087
 			unset($data);
830 1088
 		    }
@@ -845,29 +1103,62 @@  discard block
 block discarded – undo
845 1103
 		    $data['id'] = $line['id'];
846 1104
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
847 1105
 		    $data['ident'] = $line['callsign']; // ident
848
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
849
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
850
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
851
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
852
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
853
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1106
+		    if (isset($line['pilotid'])) {
1107
+		    	$data['pilot_id'] = $line['pilotid'];
1108
+		    }
1109
+		    // pilot id
1110
+		    if (isset($line['name'])) {
1111
+		    	$data['pilot_name'] = $line['name'];
1112
+		    }
1113
+		    // pilot name
1114
+		    if (isset($line['alt'])) {
1115
+		    	$data['altitude'] = $line['alt'];
1116
+		    }
1117
+		    // altitude
1118
+		    if (isset($line['gs'])) {
1119
+		    	$data['speed'] = $line['gs'];
1120
+		    }
1121
+		    // speed
1122
+		    if (isset($line['heading'])) {
1123
+		    	$data['heading'] = $line['heading'];
1124
+		    }
1125
+		    // heading
1126
+		    if (isset($line['route'])) {
1127
+		    	$data['waypoints'] = $line['route'];
1128
+		    }
1129
+		    // route
854 1130
 		    $data['latitude'] = $line['lat']; // lat
855 1131
 		    $data['longitude'] = $line['lon']; // long
856 1132
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
857 1133
 		    //$data['squawk'] = $line['squawk']; // squawk
858 1134
 		    //$data['emergency'] = ''; // emergency
859
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
860
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
861
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1135
+		    if (isset($line['depicao'])) {
1136
+		    	$data['departure_airport_icao'] = $line['depicao'];
1137
+		    }
1138
+		    if (isset($line['deptime'])) {
1139
+		    	$data['departure_airport_time'] = $line['deptime'];
1140
+		    }
1141
+		    if (isset($line['arricao'])) {
1142
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1143
+		    }
862 1144
 		    //$data['arrival_airport_time'] = $line['arrtime'];
863
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
864
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
865
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
866
-		    else $data['info'] = '';
1145
+		    if (isset($line['aircraft'])) {
1146
+		    	$data['aircraft_icao'] = $line['aircraft'];
1147
+		    }
1148
+		    if (isset($line['transponder'])) {
1149
+		    	$data['squawk'] = $line['transponder'];
1150
+		    }
1151
+		    if (isset($line['atis'])) {
1152
+		    	$data['info'] = $line['atis'];
1153
+		    } else {
1154
+		    	$data['info'] = '';
1155
+		    }
867 1156
 		    $data['format_source'] = 'pireps';
868 1157
     		    $data['id_source'] = $id_source;
869 1158
 		    $data['datetime'] = date('Y-m-d H:i:s');
870
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1159
+		    if (isset($value['name']) && $value['name'] != '') {
1160
+		    	$data['source_name'] = $value['name'];
1161
+		    }
871 1162
 		    if ($line['icon'] == 'plane') {
872 1163
 			$SI->add($data);
873 1164
 		    //    print_r($data);
@@ -876,16 +1167,28 @@  discard block
 block discarded – undo
876 1167
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
877 1168
 			$typec = substr($data['ident'],-3);
878 1169
 			$data['type'] = '';
879
-			if ($typec == 'APP') $data['type'] = 'Approach';
880
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
881
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
882
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
883
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
884
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
885
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
886
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
887
-			else $data['type'] = 'Observer';
888
-			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1170
+			if ($typec == 'APP') {
1171
+				$data['type'] = 'Approach';
1172
+			} elseif ($typec == 'TWR') {
1173
+				$data['type'] = 'Tower';
1174
+			} elseif ($typec == 'OBS') {
1175
+				$data['type'] = 'Observer';
1176
+			} elseif ($typec == 'GND') {
1177
+				$data['type'] = 'Ground';
1178
+			} elseif ($typec == 'DEL') {
1179
+				$data['type'] = 'Delivery';
1180
+			} elseif ($typec == 'DEP') {
1181
+				$data['type'] = 'Departure';
1182
+			} elseif ($typec == 'FSS') {
1183
+				$data['type'] = 'Flight Service Station';
1184
+			} elseif ($typec == 'CTR') {
1185
+				$data['type'] = 'Control Radar or Centre';
1186
+			} else {
1187
+				$data['type'] = 'Observer';
1188
+			}
1189
+			if (isset($ATC)) {
1190
+				echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1191
+			}
889 1192
 		    }
890 1193
 		    unset($data);
891 1194
 		}
@@ -895,7 +1198,9 @@  discard block
 block discarded – undo
895 1198
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
896 1199
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
897 1200
 	    //$buffer = $Common->getData($hosts[$id]);
898
-	    if ($globalDebug) echo 'Get Data...'."\n";
1201
+	    if ($globalDebug) {
1202
+	    	echo 'Get Data...'."\n";
1203
+	    }
899 1204
 	    $buffer = $Common->getData($value['host']);
900 1205
 	    $all_data = json_decode($buffer,true);
901 1206
 	    if ($buffer != '' && is_array($all_data)) {
@@ -903,10 +1208,16 @@  discard block
 block discarded – undo
903 1208
 		foreach ($all_data as $line) {
904 1209
 	    	    $data = array();
905 1210
 	    	    //$data['id'] = $line['id']; // id not usable
906
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1211
+	    	    if (isset($line['pilotid'])) {
1212
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1213
+	    	    }
907 1214
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
908
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
909
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1215
+	    	    if (isset($line['pilotname'])) {
1216
+	    	    	$data['pilot_name'] = $line['pilotname'];
1217
+	    	    }
1218
+	    	    if (isset($line['pilotid'])) {
1219
+	    	    	$data['pilot_id'] = $line['pilotid'];
1220
+	    	    }
910 1221
 	    	    $data['ident'] = $line['flightnum']; // ident
911 1222
 	    	    $data['altitude'] = $line['alt']; // altitude
912 1223
 	    	    $data['speed'] = $line['gs']; // speed
@@ -924,27 +1235,41 @@  discard block
 block discarded – undo
924 1235
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
925 1236
     		    $data['arrival_airport_time'] = $line['arrtime'];
926 1237
     		    $data['registration'] = $line['aircraft'];
927
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1238
+		    if (isset($line['route'])) {
1239
+		    	$data['waypoints'] = $line['route'];
1240
+		    }
1241
+		    // route
928 1242
 		    if (isset($line['aircraftname'])) {
929 1243
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
930 1244
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
931 1245
 	    		$aircraft_data = explode('-',$line['aircraftname']);
932
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
933
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
934
-	    		else {
1246
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
1247
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1248
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
1249
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1250
+	    		} else {
935 1251
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
936
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
937
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
1252
+	    		    if (isset($aircraft_data[1])) {
1253
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
1254
+	    		    } else {
1255
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
1256
+	    		    }
938 1257
 	    		}
939 1258
 	    	    }
940
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1259
+    		    if (isset($line['route'])) {
1260
+    		    	$data['waypoints'] = $line['route'];
1261
+    		    }
941 1262
     		    $data['id_source'] = $id_source;
942 1263
 	    	    $data['format_source'] = 'phpvmacars';
943
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1264
+		    if (isset($value['name']) && $value['name'] != '') {
1265
+		    	$data['source_name'] = $value['name'];
1266
+		    }
944 1267
 		    $SI->add($data);
945 1268
 		    unset($data);
946 1269
 		}
947
-		if ($globalDebug) echo 'No more data...'."\n";
1270
+		if ($globalDebug) {
1271
+			echo 'No more data...'."\n";
1272
+		}
948 1273
 		unset($buffer);
949 1274
 		unset($all_data);
950 1275
 	    }
@@ -952,7 +1277,9 @@  discard block
 block discarded – undo
952 1277
     	    $last_exec[$id]['last'] = time();
953 1278
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
954 1279
 	    //$buffer = $Common->getData($hosts[$id]);
955
-	    if ($globalDebug) echo 'Get Data...'."\n";
1280
+	    if ($globalDebug) {
1281
+	    	echo 'Get Data...'."\n";
1282
+	    }
956 1283
 	    $buffer = $Common->getData($value['host']);
957 1284
 	    $all_data = json_decode($buffer,true);
958 1285
 	    if ($buffer != '' && is_array($all_data)) {
@@ -981,15 +1308,22 @@  discard block
 block discarded – undo
981 1308
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
982 1309
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
983 1310
     		    //$data['registration'] = $line['aircraft'];
984
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1311
+		    if (isset($line['route'])) {
1312
+		    	$data['waypoints'] = $line['route'];
1313
+		    }
1314
+		    // route
985 1315
 	    	    $data['aircraft_icao'] = $line['plane_type'];
986 1316
     		    $data['id_source'] = $id_source;
987 1317
 	    	    $data['format_source'] = 'vam';
988
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1318
+		    if (isset($value['name']) && $value['name'] != '') {
1319
+		    	$data['source_name'] = $value['name'];
1320
+		    }
989 1321
 		    $SI->add($data);
990 1322
 		    unset($data);
991 1323
 		}
992
-		if ($globalDebug) echo 'No more data...'."\n";
1324
+		if ($globalDebug) {
1325
+			echo 'No more data...'."\n";
1326
+		}
993 1327
 		unset($buffer);
994 1328
 		unset($all_data);
995 1329
 	    }
@@ -997,7 +1331,9 @@  discard block
 block discarded – undo
997 1331
     	    $last_exec[$id]['last'] = time();
998 1332
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
999 1333
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais') {
1000
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1334
+	    if (function_exists('pcntl_fork')) {
1335
+	    	pcntl_signal_dispatch();
1336
+	    }
1001 1337
     	    //$last_exec[$id]['last'] = time();
1002 1338
 
1003 1339
 	    //$read = array( $sockets[$id] );
@@ -1005,7 +1341,9 @@  discard block
 block discarded – undo
1005 1341
 	    $write = NULL;
1006 1342
 	    $e = NULL;
1007 1343
 	    $n = socket_select($read, $write, $e, $timeout);
1008
-	    if ($e != NULL) var_dump($e);
1344
+	    if ($e != NULL) {
1345
+	    	var_dump($e);
1346
+	    }
1009 1347
 	    if ($n > 0) {
1010 1348
 		$reset = 0;
1011 1349
 		foreach ($read as $nb => $r) {
@@ -1027,7 +1365,9 @@  discard block
 block discarded – undo
1027 1365
 		    if ($buffer != '') {
1028 1366
 			$tt[$format] = 0;
1029 1367
 			if ($format == 'acarssbs3') {
1030
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1368
+                    	    if ($globalDebug) {
1369
+                    	    	echo 'ACARS : '.$buffer."\n";
1370
+                    	    }
1031 1371
 			    $ACARS->add(trim($buffer));
1032 1372
 			    $ACARS->deleteLiveAcarsData();
1033 1373
 			} elseif ($format == 'raw') {
@@ -1036,25 +1376,55 @@  discard block
 block discarded – undo
1036 1376
 			    if (is_array($data)) {
1037 1377
 				$data['datetime'] = date('Y-m-d H:i:s');
1038 1378
 				$data['format_source'] = 'raw';
1039
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1040
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1041
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1379
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1380
+					$data['source_name'] = $globalSources[$nb]['name'];
1381
+				}
1382
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1383
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1384
+    				}
1385
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1386
+                                	$SI->add($data);
1387
+                                }
1042 1388
                             }
1043 1389
                         } elseif ($format == 'ais') {
1044 1390
 			    $ais_data = $AIS->parse_line(trim($buffer));
1045 1391
 			    $data = array();
1046
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1047
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1048
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1049
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1050
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1051
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1052
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1053
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1054
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1055
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1056
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1057
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1392
+			    if (isset($ais_data['ident'])) {
1393
+			    	$data['ident'] = $ais_data['ident'];
1394
+			    }
1395
+			    if (isset($ais_data['mmsi'])) {
1396
+			    	$data['mmsi'] = $ais_data['mmsi'];
1397
+			    }
1398
+			    if (isset($ais_data['speed'])) {
1399
+			    	$data['speed'] = $ais_data['speed'];
1400
+			    }
1401
+			    if (isset($ais_data['heading'])) {
1402
+			    	$data['heading'] = $ais_data['heading'];
1403
+			    }
1404
+			    if (isset($ais_data['latitude'])) {
1405
+			    	$data['latitude'] = $ais_data['latitude'];
1406
+			    }
1407
+			    if (isset($ais_data['longitude'])) {
1408
+			    	$data['longitude'] = $ais_data['longitude'];
1409
+			    }
1410
+			    if (isset($ais_data['status'])) {
1411
+			    	$data['status'] = $ais_data['status'];
1412
+			    }
1413
+			    if (isset($ais_data['type'])) {
1414
+			    	$data['type'] = $ais_data['type'];
1415
+			    }
1416
+			    if (isset($ais_data['imo'])) {
1417
+			    	$data['imo'] = $ais_data['imo'];
1418
+			    }
1419
+			    if (isset($ais_data['callsign'])) {
1420
+			    	$data['callsign'] = $ais_data['callsign'];
1421
+			    }
1422
+			    if (isset($ais_data['destination'])) {
1423
+			    	$data['arrival_code'] = $ais_data['destination'];
1424
+			    }
1425
+			    if (isset($ais_data['eta_ts'])) {
1426
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1427
+			    }
1058 1428
 
1059 1429
 			    if (isset($ais_data['timestamp'])) {
1060 1430
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1063,7 +1433,9 @@  discard block
 block discarded – undo
1063 1433
 			    }
1064 1434
 			    $data['format_source'] = 'aisnmea';
1065 1435
     			    $data['id_source'] = $id_source;
1066
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1436
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1437
+			    	$MI->add($data);
1438
+			    }
1067 1439
 			    unset($data);
1068 1440
                         } elseif ($format == 'flightgearsp') {
1069 1441
                     	    //echo $buffer."\n";
@@ -1081,11 +1453,15 @@  discard block
 block discarded – undo
1081 1453
 				$data['speed'] = round($line[5]*1.94384);
1082 1454
 				$data['datetime'] = date('Y-m-d H:i:s');
1083 1455
 				$data['format_source'] = 'flightgearsp';
1084
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1456
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1457
+					$SI->add($data);
1458
+				}
1085 1459
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1086 1460
 			    }
1087 1461
                         } elseif ($format == 'acars') {
1088
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1462
+                    	    if ($globalDebug) {
1463
+                    	    	echo 'ACARS : '.$buffer."\n";
1464
+                    	    }
1089 1465
 			    $ACARS->add(trim($buffer));
1090 1466
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1091 1467
 			    $ACARS->deleteLiveAcarsData();
@@ -1106,7 +1482,9 @@  discard block
 block discarded – undo
1106 1482
 				    $aircraft_type = $line[10];
1107 1483
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1108 1484
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1109
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1485
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1486
+				    	$SI->add($data);
1487
+				    }
1110 1488
 				}
1111 1489
 			    }
1112 1490
 			} elseif ($format == 'beast') {
@@ -1122,21 +1500,43 @@  discard block
 block discarded – undo
1122 1500
     				$data['hex'] = $lined['hexid'];
1123 1501
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1124 1502
     				$data['datetime'] = date('Y-m-d H:i:s');;
1125
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1126
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1127
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1128
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1129
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1130
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1131
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1503
+    				if (isset($lined['ident'])) {
1504
+    					$data['ident'] = $lined['ident'];
1505
+    				}
1506
+    				if (isset($lined['lat'])) {
1507
+    					$data['latitude'] = $lined['lat'];
1508
+    				}
1509
+    				if (isset($lined['lon'])) {
1510
+    					$data['longitude'] = $lined['lon'];
1511
+    				}
1512
+    				if (isset($lined['speed'])) {
1513
+    					$data['speed'] = $lined['speed'];
1514
+    				}
1515
+    				if (isset($lined['squawk'])) {
1516
+    					$data['squawk'] = $lined['squawk'];
1517
+    				}
1518
+    				if (isset($lined['alt'])) {
1519
+    					$data['altitude'] = $lined['alt'];
1520
+    				}
1521
+    				if (isset($lined['heading'])) {
1522
+    					$data['heading'] = $lined['heading'];
1523
+    				}
1132 1524
     				$data['id_source'] = $id_source;
1133 1525
     				$data['format_source'] = 'tsv';
1134
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1135
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1136
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1526
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1527
+    					$data['source_name'] = $globalSources[$nb]['name'];
1528
+    				}
1529
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1530
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1531
+    				}
1532
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1533
+    					$SI->add($data);
1534
+    				}
1137 1535
     				unset($lined);
1138 1536
     				unset($data);
1139
-    			    } else $error = true;
1537
+    			    } else {
1538
+    			    	$error = true;
1539
+    			    }
1140 1540
 			} elseif ($format == 'aprs' && $use_aprs) {
1141 1541
 			    if ($aprs_connect == 0) {
1142 1542
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1162,49 +1562,80 @@  discard block
 block discarded – undo
1162 1562
 				    $aprs_last_tx = time();
1163 1563
 				    $data = array();
1164 1564
 				    //print_r($line);
1165
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1166
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1167
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1565
+				    if (isset($line['address'])) {
1566
+				    	$data['hex'] = $line['address'];
1567
+				    }
1568
+				    if (isset($line['timestamp'])) {
1569
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1570
+				    } else {
1571
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1572
+				    }
1168 1573
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1169 1574
 				    $data['ident'] = $line['ident'];
1170 1575
 				    $data['latitude'] = $line['latitude'];
1171 1576
 				    $data['longitude'] = $line['longitude'];
1172 1577
 				    //$data['verticalrate'] = $line[16];
1173
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1174
-				    else $data['speed'] = 0;
1175
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1176
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1177
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1178
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1578
+				    if (isset($line['speed'])) {
1579
+				    	$data['speed'] = $line['speed'];
1580
+				    } else {
1581
+				    	$data['speed'] = 0;
1582
+				    }
1583
+				    if (isset($line['altitude'])) {
1584
+				    	$data['altitude'] = $line['altitude'];
1585
+				    }
1586
+				    if (isset($line['comment'])) {
1587
+				    	$data['comment'] = $line['comment'];
1588
+				    }
1589
+				    if (isset($line['symbol'])) {
1590
+				    	$data['type'] = $line['symbol'];
1591
+				    }
1592
+				    if (isset($line['heading'])) {
1593
+				    	$data['heading'] = $line['heading'];
1594
+				    }
1179 1595
 				    //else $data['heading'] = 0;
1180
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1181
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1596
+				    if (isset($line['stealth'])) {
1597
+				    	$data['aircraft_type'] = $line['stealth'];
1598
+				    }
1599
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1600
+				    	$data['noarchive'] = true;
1601
+				    }
1182 1602
     				    $data['id_source'] = $id_source;
1183
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1184
-				    else $data['format_source'] = 'aprs';
1603
+    				    if (isset($line['format_source'])) {
1604
+    				    	$data['format_source'] = $line['format_source'];
1605
+    				    } else {
1606
+				    	$data['format_source'] = 'aprs';
1607
+				    }
1185 1608
 				    $data['source_name'] = $line['source'];
1186
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1187
-				    else $data['source_type'] = 'flarm';
1188
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1609
+				    if (isset($line['source_type'])) {
1610
+				    	$data['source_type'] = $line['source_type'];
1611
+				    } else {
1612
+				    	$data['source_type'] = 'flarm';
1613
+				    }
1614
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1615
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1616
+    				    }
1189 1617
 				    $currentdate = date('Y-m-d H:i:s');
1190 1618
 				    $aprsdate = strtotime($data['datetime']);
1191 1619
 				    // Accept data if time <= system time + 20s
1192 1620
 				    if (($data['source_type'] == 'sbs') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1193 1621
 					$send = $SI->add($data);
1194 1622
 				    } elseif (isset($line['stealth'])) {
1195
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1196
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1623
+					if ($line['stealth'] != 0) {
1624
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1625
+					} else {
1626
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1627
+					}
1197 1628
 				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1198 1629
 				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1199 1630
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1200
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1631
+					if (isset($globalTracker) && $globalTracker) {
1632
+						$send = $TI->add($data);
1633
+					}
1201 1634
 				    }
1202 1635
 				    unset($data);
1203
-				} 
1204
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1636
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1205 1637
 					echo '!! Weather Station not yet supported'."\n";
1206
-				}
1207
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1638
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1208 1639
 					echo '!! Car & Trucks not yet supported'."\n";
1209 1640
 				}
1210 1641
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1237,25 +1668,42 @@  discard block
 block discarded – undo
1237 1668
     				$data['ground'] = $line[21];
1238 1669
     				$data['emergency'] = $line[19];
1239 1670
     				$data['format_source'] = 'sbs';
1240
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1241
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1671
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1672
+					$data['source_name'] = $globalSources[$nb]['name'];
1673
+				}
1674
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1675
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1676
+    				}
1242 1677
     				$data['id_source'] = $id_source;
1243
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1244
-    				else $error = true;
1678
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1679
+    					$send = $SI->add($data);
1680
+    				} else {
1681
+    					$error = true;
1682
+    				}
1245 1683
     				unset($data);
1246
-    			    } else $error = true;
1684
+    			    } else {
1685
+    			    	$error = true;
1686
+    			    }
1247 1687
 			    if ($error) {
1248 1688
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1249
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1689
+					if ($globalDebug) {
1690
+						echo "Not a message. Ignoring... \n";
1691
+					}
1250 1692
 				} else {
1251
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1693
+					if ($globalDebug) {
1694
+						echo "Wrong line format. Ignoring... \n";
1695
+					}
1252 1696
 					if ($globalDebug) {
1253 1697
 						echo $buffer;
1254 1698
 						print_r($line);
1255 1699
 					}
1256 1700
 					//socket_close($r);
1257
-					if ($globalDebug) echo "Reconnect after an error...\n";
1258
-					if ($format == 'aprs') $aprs_connect = 0;
1701
+					if ($globalDebug) {
1702
+						echo "Reconnect after an error...\n";
1703
+					}
1704
+					if ($format == 'aprs') {
1705
+						$aprs_connect = 0;
1706
+					}
1259 1707
 					$sourceer[$nb] = $globalSources[$nb];
1260 1708
 					connect_all($sourceer);
1261 1709
 					$sourceer = array();
@@ -1263,10 +1711,14 @@  discard block
 block discarded – undo
1263 1711
 			    }
1264 1712
 			}
1265 1713
 			// Sleep for xxx microseconds
1266
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1714
+			if (isset($globalSBSSleep)) {
1715
+				usleep($globalSBSSleep);
1716
+			}
1267 1717
 		    } else {
1268 1718
 			if ($format == 'flightgearmp') {
1269
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1719
+			    	if ($globalDebug) {
1720
+			    		echo "Reconnect FlightGear MP...";
1721
+			    	}
1270 1722
 				//@socket_close($r);
1271 1723
 				sleep($globalMinFetch);
1272 1724
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1275,10 +1727,15 @@  discard block
 block discarded – undo
1275 1727
 				break;
1276 1728
 				
1277 1729
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1278
-			    if (isset($tt[$format])) $tt[$format]++;
1279
-			    else $tt[$format] = 0;
1730
+			    if (isset($tt[$format])) {
1731
+			    	$tt[$format]++;
1732
+			    } else {
1733
+			    	$tt[$format] = 0;
1734
+			    }
1280 1735
 			    if ($tt[$format] > 30) {
1281
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1736
+				if ($globalDebug) {
1737
+					echo "ERROR : Reconnect ".$format."...";
1738
+				}
1282 1739
 				//@socket_close($r);
1283 1740
 				sleep(2);
1284 1741
 				$aprs_connect = 0;
@@ -1295,11 +1752,17 @@  discard block
 block discarded – undo
1295 1752
 	    } else {
1296 1753
 		$error = socket_strerror(socket_last_error());
1297 1754
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1298
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1299
-			if (isset($globalDebug)) echo "Restarting...\n";
1755
+			if ($globalDebug) {
1756
+				echo "ERROR : socket_select give this error ".$error . "\n";
1757
+			}
1758
+			if (isset($globalDebug)) {
1759
+				echo "Restarting...\n";
1760
+			}
1300 1761
 			// Restart the script if possible
1301 1762
 			if (is_array($sockets)) {
1302
-			    if ($globalDebug) echo "Shutdown all sockets...";
1763
+			    if ($globalDebug) {
1764
+			    	echo "Shutdown all sockets...";
1765
+			    }
1303 1766
 			    
1304 1767
 			    foreach ($sockets as $sock) {
1305 1768
 				@socket_shutdown($sock,2);
@@ -1307,18 +1770,24 @@  discard block
 block discarded – undo
1307 1770
 			    }
1308 1771
 			    
1309 1772
 			}
1310
-			if ($globalDebug) echo "Restart all connections...";
1773
+			if ($globalDebug) {
1774
+				echo "Restart all connections...";
1775
+			}
1311 1776
 			sleep(2);
1312 1777
 			$time = time();
1313 1778
 			//connect_all($hosts);
1314 1779
 			$aprs_connect = 0;
1315
-			if ($reset > 40) exit('Too many attempts...');
1780
+			if ($reset > 40) {
1781
+				exit('Too many attempts...');
1782
+			}
1316 1783
 			connect_all($globalSources);
1317 1784
 		}
1318 1785
 	    }
1319 1786
 	}
1320 1787
 	if ($globalDaemon === false) {
1321
-	    if ($globalDebug) echo 'Check all...'."\n";
1788
+	    if ($globalDebug) {
1789
+	    	echo 'Check all...'."\n";
1790
+	    }
1322 1791
 	    $SI->checkAll();
1323 1792
 	}
1324 1793
     }
Please login to merge, or discard this patch.
require/class.APRS.php 2 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@  discard block
 block discarded – undo
2 2
 require_once(dirname(__FILE__).'/settings.php');
3 3
 require_once(dirname(__FILE__).'/class.Common.php');
4 4
 class aprs {
5
-    private $socket;
6
-    private $connected = false;
5
+	private $socket;
6
+	private $connected = false;
7 7
 
8
-    protected $symbols = array('!' => 'Police',
8
+	protected $symbols = array('!' => 'Police',
9 9
 	'#' => 'DIGI',
10 10
 	'$' => 'Phone',
11 11
 	'%' => 'DX Cluster',
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
 	'y' => 'Yagi At QTH');
90 90
 	
91 91
 
92
-    private function urshift($n, $s) {
92
+	private function urshift($n, $s) {
93 93
 	return ($n >= 0) ? ($n >> $s) :
94
-	    (($n & 0x7fffffff) >> $s) | 
94
+		(($n & 0x7fffffff) >> $s) | 
95 95
 		(0x40000000 >> ($s - 1));
96
-    }
96
+	}
97 97
 
98
-    public function parse($input) {
98
+	public function parse($input) {
99 99
 	global $globalDebug;
100 100
 	$debug = false;
101 101
 	$result = array();
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
111
-	    return false;
110
+		if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
111
+		return false;
112 112
 	}
113 113
 	
114 114
 	if ($debug) echo 'input : '.$input."\n";
@@ -122,30 +122,30 @@  discard block
 block discarded – undo
122 122
 	/* Parse source, target and path. */
123 123
 	//FLRDF0A52>APRS,qAS,LSTB
124 124
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
125
-	    $ident = $matches[1];
126
-	    if ($ident == 'AIRCRAFT') {
125
+		$ident = $matches[1];
126
+		if ($ident == 'AIRCRAFT') {
127 127
 		$result['format_source'] = 'famaprs';
128 128
 		$result['source_type'] = 'sbs';
129
-	    } elseif ($ident == 'MARINE') {
129
+		} elseif ($ident == 'MARINE') {
130 130
 		$result['format_source'] = 'famaprs';
131 131
 		$result['source_type'] = 'ais';
132
-	    }
133
-	    $all_elements = $matches[2];
134
-	    if ($debug) echo 'ident : '.$ident."\n";
135
-	    $result['ident'] = $ident;
132
+		}
133
+		$all_elements = $matches[2];
134
+		if ($debug) echo 'ident : '.$ident."\n";
135
+		$result['ident'] = $ident;
136 136
 	} else return false;
137 137
 	$elements = explode(',',$all_elements);
138 138
 	$source = end($elements);
139 139
 	$result['source'] = $source;
140 140
 	foreach ($elements as $element) {
141
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
142
-	        //echo "ok";
143
-	        //if ($element == 'TCPIP*') return false;
144
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
141
+		if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
142
+			//echo "ok";
143
+			//if ($element == 'TCPIP*') return false;
144
+		} elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
145 145
 		if ($debug) echo 'element : '.$element."\n";
146 146
 		return false;
147
-	    }
148
-	    /*
147
+		}
148
+		/*
149 149
 	    } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) {
150 150
 		//echo "ok";
151 151
 	    } else {
@@ -168,49 +168,49 @@  discard block
 block discarded – undo
168 168
 	$body_parse = substr($body,1);
169 169
 	//echo 'Body : '.$body."\n";
170 170
 	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
171
-	    $body_parse = substr($body_parse,10);
172
-	    $find = true;
173
-	    //echo $body_parse."\n";
171
+		$body_parse = substr($body_parse,10);
172
+		$find = true;
173
+		//echo $body_parse."\n";
174 174
 	}
175 175
 	if (preg_match('/^`(.*)\//',$body,$matches)) {
176
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
177
-	    $find = true;
178
-	    //echo $body_parse."\n";
176
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
177
+		$find = true;
178
+		//echo $body_parse."\n";
179 179
 	}
180 180
 	if (preg_match("/^'(.*)\//",$body,$matches)) {
181
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
182
-	    $find = true;
183
-	    //echo $body_parse."\n";
181
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
182
+		$find = true;
183
+		//echo $body_parse."\n";
184 184
 	}
185 185
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
186
-	    $find = true;
187
-	    //print_r($matches);
188
-	    $timestamp = $matches[0];
189
-	    if ($matches[4] == 'h') {
186
+		$find = true;
187
+		//print_r($matches);
188
+		$timestamp = $matches[0];
189
+		if ($matches[4] == 'h') {
190 190
 		$timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]);
191 191
 		//echo 'timestamp : '.$timestamp.' - now : '.time()."\n";
192 192
 		/*
193 193
 		if (time() + 3900 < $timestamp) $timestamp -= 86400;
194 194
 		elseif (time() - 82500 > $timestamp) $timestamp += 86400;
195 195
 		*/
196
-	    } elseif ($matches[4] == 'z' || $matches[4] == '/') {
196
+		} elseif ($matches[4] == 'z' || $matches[4] == '/') {
197 197
 		// This work or not ?
198 198
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
199
-	    }
200
-	    $body_parse = substr($body_parse,7);
201
-	    $result['timestamp'] = $timestamp;
202
-	    //echo date('Ymd H:i:s',$timestamp);
199
+		}
200
+		$body_parse = substr($body_parse,7);
201
+		$result['timestamp'] = $timestamp;
202
+		//echo date('Ymd H:i:s',$timestamp);
203 203
 	}
204 204
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
205
-	    $find = true;
206
-	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
207
-	    $body_parse = substr($body_parse,8);
208
-	    $result['timestamp'] = $timestamp;
209
-	    //echo date('Ymd H:i:s',$timestamp);
205
+		$find = true;
206
+		$timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
207
+		$body_parse = substr($body_parse,8);
208
+		$result['timestamp'] = $timestamp;
209
+		//echo date('Ymd H:i:s',$timestamp);
210 210
 	}
211 211
 	//if (strlen($body_parse) > 19) {
212
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
213
-	    $find = true;
212
+		if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
213
+		$find = true;
214 214
 		// 4658.70N/00707.78Ez
215 215
 		//print_r(str_split($body_parse));
216 216
 		
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 		$lon = intval($lon_deg);
228 228
 		if ($lat > 89 || $lon > 179) return false;
229 229
 	    
230
-	    /*
230
+		/*
231 231
 	    $tmp_5b = str_replace('.','',$lat_min);
232 232
 	    if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) {
233 233
 	        print_r($matches);
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
 		$result['longitude'] = $longitude;
242 242
 		$body_parse = substr($body_parse,18);
243 243
 		$body_parse_len = strlen($body_parse);
244
-	    }
245
-	    $body_parse_len = strlen($body_parse);
246
-	    if ($body_parse_len > 0) {
244
+		}
245
+		$body_parse_len = strlen($body_parse);
246
+		if ($body_parse_len > 0) {
247 247
 		/*
248 248
 		if (!isset($result['timestamp']) && !isset($result['latitude'])) {
249 249
 			$body_split = str_split($body);
@@ -272,85 +272,85 @@  discard block
 block discarded – undo
272 272
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
273 273
 			if ($symbol_code != '_') {
274 274
 			}
275
-		    //$body_parse = substr($body_parse,1);
276
-		    //$body_parse = trim($body_parse);
277
-		    //$body_parse_len = strlen($body_parse);
278
-		    if ($body_parse_len >= 7) {
275
+			//$body_parse = substr($body_parse,1);
276
+			//$body_parse = trim($body_parse);
277
+			//$body_parse_len = strlen($body_parse);
278
+			if ($body_parse_len >= 7) {
279 279
 			
280
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
281
-		    	    $course = substr($body_parse,0,3);
282
-		    	    $tmp_s = intval($course);
283
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
284
-		    	    $speed = substr($body_parse,4,3);
285
-		    	    if ($speed != '...') {
286
-		    		    $result['speed'] = round($speed*1.852);
287
-		    	    }
288
-		    	    $body_parse = substr($body_parse,7);
289
-		        }
290
-		        // Check PHGR, PHG, RNG
291
-		    } 
292
-		    /*
280
+				if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
281
+					$course = substr($body_parse,0,3);
282
+					$tmp_s = intval($course);
283
+					if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
284
+					$speed = substr($body_parse,4,3);
285
+					if ($speed != '...') {
286
+						$result['speed'] = round($speed*1.852);
287
+					}
288
+					$body_parse = substr($body_parse,7);
289
+				}
290
+				// Check PHGR, PHG, RNG
291
+			} 
292
+			/*
293 293
 		    else if ($body_parse_len > 0) {
294 294
 			$rest = $body_parse;
295 295
 		    }
296 296
 		    */
297
-		    if (strlen($body_parse) > 0) {
298
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
299
-		            $altitude = intval($matches[1]);
300
-		            //$result['altitude'] = round($altitude*0.3048);
301
-		            $result['altitude'] = $altitude;
302
-		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
303
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
304
-		        }
305
-		    }
297
+			if (strlen($body_parse) > 0) {
298
+				if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
299
+					$altitude = intval($matches[1]);
300
+					//$result['altitude'] = round($altitude*0.3048);
301
+					$result['altitude'] = $altitude;
302
+					//$body_parse = trim(substr($body_parse,strlen($matches[0])));
303
+					$body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
304
+				}
305
+			}
306 306
 		    
307
-		    // Telemetry
308
-		    /*
307
+			// Telemetry
308
+			/*
309 309
 		    if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) {
310 310
 		        // Nothing yet...
311 311
 		    }
312 312
 		    */
313
-		    // DAO
314
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
315
-			    $dao = $matches[1];
316
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
313
+			// DAO
314
+			if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
315
+				$dao = $matches[1];
316
+				if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
317 317
 				$dao_split = str_split($dao);
318
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
319
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
318
+					$lat_off = (($dao_split[1])-48.0)*0.001/60.0;
319
+					$lon_off = (($dao_split[2])-48.0)*0.001/60.0;
320 320
 			    
321 321
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
322 322
 				else $result['latitude'] += $lat_off;
323 323
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
324 324
 				else $result['longitude'] += $lon_off;
325
-			    }
326
-		            $body_parse = substr($body_parse,6);
327
-		    }
325
+				}
326
+					$body_parse = substr($body_parse,6);
327
+			}
328 328
 		    
329
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
329
+			if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
330 330
 			$result['callsign'] = $matches[1];
331
-		    }
332
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
331
+			}
332
+			if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
333 333
 			$result['squawk'] = $matches[1];
334
-		    }
335
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
334
+			}
335
+			if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
336 336
 			$result['aircraft_icao'] = $matches[1];
337
-		    }
338
-		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
337
+			}
338
+			if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
339 339
 			$result['typeid'] = $matches[1];
340
-		    }
341
-		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
340
+			}
341
+			if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
342 342
 			$result['imo'] = $matches[1];
343
-		    }
344
-		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
343
+			}
344
+			if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
345 345
 			$result['arrival_date'] = $matches[1];
346
-		    }
347
-		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
346
+			}
347
+			if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
348 348
 			$result['arrival_code'] = $matches[1];
349
-		    }
350
-		    // OGN comment
349
+			}
350
+			// OGN comment
351 351
 		   // echo "Before OGN : ".$body_parse."\n";
352
-		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
353
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
352
+			//if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
353
+			if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
354 354
 			$id = $matches[1];
355 355
 			//$mode = substr($id,0,2);
356 356
 			$address = substr($id,2);
@@ -380,53 +380,53 @@  discard block
 block discarded – undo
380 380
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
381 381
 			$result['stealth'] = $stealth;
382 382
 			$result['address'] = $address;
383
-		    }
383
+			}
384 384
 		    
385
-		    //Comment
386
-		    $result['comment'] = trim($body_parse);
385
+			//Comment
386
+			$result['comment'] = trim($body_parse);
387 387
 		} else {
388
-		    // parse weather
389
-		    //$body_parse = substr($body_parse,1);
390
-		    //$body_parse_len = strlen($body_parse);
388
+			// parse weather
389
+			//$body_parse = substr($body_parse,1);
390
+			//$body_parse_len = strlen($body_parse);
391 391
 
392
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
393
-			    $result['wind_dir'] = intval($matches[1]);
394
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
395
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
396
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
397
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
398
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
392
+			if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
393
+				$result['wind_dir'] = intval($matches[1]);
394
+				$result['wind_speed'] = round(intval($matches[2])*1.60934,1);
395
+				$result['wind_gust'] = round(intval($matches[3])*1.60934,1);
396
+				$result['temp'] = round(5/9*((intval($matches[4]))-32),1);
397
+					$body_parse = substr($body_parse,strlen($matches[0])+1);
398
+			} elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
399 399
 			$result['wind_dir'] = intval($matches[1]);
400 400
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
401 401
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
402 402
 			$result['temp'] = round(5/9*(($matches[4])-32),1);
403
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
404
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
403
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
404
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
405 405
 			$result['wind_dir'] = intval($matches[1]);
406 406
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
407 407
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
408
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
409
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
408
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
409
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
410 410
 			$result['wind_dir'] = intval($matches[1]);
411 411
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
412 412
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
413
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
414
-		    }
415
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
413
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
414
+			}
415
+			if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
416 416
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
417
-		    }
417
+			}
418 418
 		}
419 419
 		} else $result['comment'] = trim($body_parse);
420 420
 
421
-	    }
421
+		}
422 422
 	//}
423 423
 	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
424 424
 	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
425 425
 	if ($debug) print_r($result);
426 426
 	return $result;
427
-    }
427
+	}
428 428
     
429
-    function connect() {
429
+	function connect() {
430 430
 	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
431 431
 	$aprs_connect = 0;
432 432
 	$aprs_keep = 120;
@@ -449,24 +449,24 @@  discard block
 block discarded – undo
449 449
 		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
450 450
 		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
451 451
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
452
-			    echo 'APRS user verified !'."\n";
453
-			    $this->connected = true;
454
-			    return true;
455
-			    break;
452
+				echo 'APRS user verified !'."\n";
453
+				$this->connected = true;
454
+				return true;
455
+				break;
456 456
 			}
457 457
 			if (time()-$authstart > 5) {
458
-			    echo 'APRS timeout'."\n";
459
-			    break;
458
+				echo 'APRS timeout'."\n";
459
+				break;
460 460
 			}
461 461
 		}
462 462
 	}
463
-    }
463
+	}
464 464
     
465
-    function send($data) {
465
+	function send($data) {
466 466
 	if ($this->connected === false) $this->connect();
467 467
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
468 468
 	if ($send === FALSE) $this->connect();
469
-    }
469
+	}
470 470
 }
471 471
 
472 472
 class APRSSpotter extends APRS {
Please login to merge, or discard this patch.
Braces   +149 added lines, -57 removed lines patch added patch discarded remove patch
@@ -107,17 +107,23 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
+	    if ($globalDebug) {
111
+	    	echo '!!! APRS invalid : '.$input."\n";
112
+	    }
111 113
 	    return false;
112 114
 	}
113 115
 	
114
-	if ($debug) echo 'input : '.$input."\n";
116
+	if ($debug) {
117
+		echo 'input : '.$input."\n";
118
+	}
115 119
 	/* Save header and body. */
116 120
 	$body = substr($input,$splitpos+1,$input_len);
117 121
 	$body_len = strlen($body);
118 122
 	$header = substr($input,0,$splitpos);
119 123
 	//$header_len = strlen($header);
120
-	if ($debug) echo 'header : '.$header."\n";
124
+	if ($debug) {
125
+		echo 'header : '.$header."\n";
126
+	}
121 127
 	
122 128
 	/* Parse source, target and path. */
123 129
 	//FLRDF0A52>APRS,qAS,LSTB
@@ -131,9 +137,13 @@  discard block
 block discarded – undo
131 137
 		$result['source_type'] = 'ais';
132 138
 	    }
133 139
 	    $all_elements = $matches[2];
134
-	    if ($debug) echo 'ident : '.$ident."\n";
140
+	    if ($debug) {
141
+	    	echo 'ident : '.$ident."\n";
142
+	    }
135 143
 	    $result['ident'] = $ident;
136
-	} else return false;
144
+	} else {
145
+		return false;
146
+	}
137 147
 	$elements = explode(',',$all_elements);
138 148
 	$source = end($elements);
139 149
 	$result['source'] = $source;
@@ -142,7 +152,9 @@  discard block
 block discarded – undo
142 152
 	        //echo "ok";
143 153
 	        //if ($element == 'TCPIP*') return false;
144 154
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
145
-		if ($debug) echo 'element : '.$element."\n";
155
+		if ($debug) {
156
+			echo 'element : '.$element."\n";
157
+		}
146 158
 		return false;
147 159
 	    }
148 160
 	    /*
@@ -155,7 +167,9 @@  discard block
 block discarded – undo
155 167
 	}
156 168
 	
157 169
 	$type = substr($body,0,1);
158
-	if ($debug) echo 'type : '.$type."\n";
170
+	if ($debug) {
171
+		echo 'type : '.$type."\n";
172
+	}
159 173
 	if ($type == ';') {
160 174
 		$result['ident'] = trim(substr($body,1,9));
161 175
 	} elseif ($type == ',') {
@@ -225,7 +239,9 @@  discard block
 block discarded – undo
225 239
 		//$symbol_table = $matches[4];
226 240
 		$lat = intval($lat_deg);
227 241
 		$lon = intval($lon_deg);
228
-		if ($lat > 89 || $lon > 179) return false;
242
+		if ($lat > 89 || $lon > 179) {
243
+			return false;
244
+		}
229 245
 	    
230 246
 	    /*
231 247
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -235,8 +251,12 @@  discard block
 block discarded – undo
235 251
 	    */
236 252
 		$latitude = $lat + floatval($lat_min)/60;
237 253
 		$longitude = $lon + floatval($lon_min)/60;
238
-		if ($sind == 'S') $latitude = 0-$latitude;
239
-		if ($wind == 'W') $longitude = 0-$longitude;
254
+		if ($sind == 'S') {
255
+			$latitude = 0-$latitude;
256
+		}
257
+		if ($wind == 'W') {
258
+			$longitude = 0-$longitude;
259
+		}
240 260
 		$result['latitude'] = $latitude;
241 261
 		$result['longitude'] = $longitude;
242 262
 		$body_parse = substr($body_parse,18);
@@ -269,7 +289,9 @@  discard block
 block discarded – undo
269 289
 			$body_parse = substr($body_parse,1);
270 290
 			$body_parse_len = strlen($body_parse);
271 291
 			$result['symbol_code'] = $symbol_code;
272
-			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
292
+			if (isset($this->symbols[$symbol_code])) {
293
+				$result['symbol'] = $this->symbols[$symbol_code];
294
+			}
273 295
 			if ($symbol_code != '_') {
274 296
 			}
275 297
 		    //$body_parse = substr($body_parse,1);
@@ -280,7 +302,9 @@  discard block
 block discarded – undo
280 302
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
281 303
 		    	    $course = substr($body_parse,0,3);
282 304
 		    	    $tmp_s = intval($course);
283
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
305
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
306
+		    	    	$result['heading'] = intval($course);
307
+		    	    }
284 308
 		    	    $speed = substr($body_parse,4,3);
285 309
 		    	    if ($speed != '...') {
286 310
 		    		    $result['speed'] = round($speed*1.852);
@@ -318,10 +342,16 @@  discard block
 block discarded – undo
318 342
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
319 343
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
320 344
 			    
321
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
322
-				else $result['latitude'] += $lat_off;
323
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
324
-				else $result['longitude'] += $lon_off;
345
+				if ($result['latitude'] < 0) {
346
+					$result['latitude'] -= $lat_off;
347
+				} else {
348
+					$result['latitude'] += $lat_off;
349
+				}
350
+				if ($result['longitude'] < 0) {
351
+					$result['longitude'] -= $lon_off;
352
+				} else {
353
+					$result['longitude'] += $lon_off;
354
+				}
325 355
 			    }
326 356
 		            $body_parse = substr($body_parse,6);
327 357
 		    }
@@ -356,27 +386,48 @@  discard block
 block discarded – undo
356 386
 			$address = substr($id,2);
357 387
 			//print_r($matches);
358 388
 			$addressType = (intval(substr($id,0,2),16))&3;
359
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
360
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
361
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
362
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
389
+			if ($addressType == 0) {
390
+				$result['addresstype'] = "RANDOM";
391
+			} elseif ($addressType == 1) {
392
+				$result['addresstype'] = "ICAO";
393
+			} elseif ($addressType == 2) {
394
+				$result['addresstype'] = "FLARM";
395
+			} elseif ($addressType == 3) {
396
+				$result['addresstype'] = "OGN";
397
+			}
363 398
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
364 399
 			$result['aircrafttype_code'] = $aircraftType;
365
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
366
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
367
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
368
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
369
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
370
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
371
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
372
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
373
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
374
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
375
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
376
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
377
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
378
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
379
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
400
+			if ($aircraftType == 0) {
401
+				$result['aircrafttype'] = "UNKNOWN";
402
+			} elseif ($aircraftType == 1) {
403
+				$result['aircrafttype'] = "GLIDER";
404
+			} elseif ($aircraftType == 2) {
405
+				$result['aircrafttype'] = "TOW_PLANE";
406
+			} elseif ($aircraftType == 3) {
407
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
408
+			} elseif ($aircraftType == 4) {
409
+				$result['aircrafttype'] = "PARACHUTE";
410
+			} elseif ($aircraftType == 5) {
411
+				$result['aircrafttype'] = "DROP_PLANE";
412
+			} elseif ($aircraftType == 6) {
413
+				$result['aircrafttype'] = "HANG_GLIDER";
414
+			} elseif ($aircraftType == 7) {
415
+				$result['aircrafttype'] = "PARA_GLIDER";
416
+			} elseif ($aircraftType == 8) {
417
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
418
+			} elseif ($aircraftType == 9) {
419
+				$result['aircrafttype'] = "JET_AIRCRAFT";
420
+			} elseif ($aircraftType == 10) {
421
+				$result['aircrafttype'] = "UFO";
422
+			} elseif ($aircraftType == 11) {
423
+				$result['aircrafttype'] = "BALLOON";
424
+			} elseif ($aircraftType == 12) {
425
+				$result['aircrafttype'] = "AIRSHIP";
426
+			} elseif ($aircraftType == 13) {
427
+				$result['aircrafttype'] = "UAV";
428
+			} elseif ($aircraftType == 15) {
429
+				$result['aircrafttype'] = "STATIC_OBJECT";
430
+			}
380 431
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
381 432
 			$result['stealth'] = $stealth;
382 433
 			$result['address'] = $address;
@@ -416,13 +467,21 @@  discard block
 block discarded – undo
416 467
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
417 468
 		    }
418 469
 		}
419
-		} else $result['comment'] = trim($body_parse);
470
+		} else {
471
+			$result['comment'] = trim($body_parse);
472
+		}
420 473
 
421 474
 	    }
422 475
 	//}
423
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
424
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
425
-	if ($debug) print_r($result);
476
+	if (isset($result['latitude'])) {
477
+		$result['latitude'] = round($result['latitude'],4);
478
+	}
479
+	if (isset($result['longitude'])) {
480
+		$result['longitude'] = round($result['longitude'],4);
481
+	}
482
+	if ($debug) {
483
+		print_r($result);
484
+	}
426 485
 	return $result;
427 486
     }
428 487
     
@@ -431,12 +490,21 @@  discard block
 block discarded – undo
431 490
 	$aprs_connect = 0;
432 491
 	$aprs_keep = 120;
433 492
 	$aprs_last_tx = time();
434
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
435
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
436
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
437
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
438
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
439
-	else $aprs_pass = '-1';
493
+	if (isset($globalAPRSversion)) {
494
+		$aprs_version = $globalAPRSversion;
495
+	} else {
496
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
497
+	}
498
+	if (isset($globalServerAPRSssid)) {
499
+		$aprs_ssid = $globalServerAPRSssid;
500
+	} else {
501
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
502
+	}
503
+	if (isset($globalServerAPRSpass)) {
504
+		$aprs_pass = $globalServerAPRSpass;
505
+	} else {
506
+		$aprs_pass = '-1';
507
+	}
440 508
 	
441 509
 	$aprs_filter  = '';
442 510
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -463,9 +531,13 @@  discard block
 block discarded – undo
463 531
     }
464 532
     
465 533
     function send($data) {
466
-	if ($this->connected === false) $this->connect();
534
+	if ($this->connected === false) {
535
+		$this->connect();
536
+	}
467 537
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
468
-	if ($send === FALSE) $this->connect();
538
+	if ($send === FALSE) {
539
+		$this->connect();
540
+	}
469 541
     }
470 542
 }
471 543
 
@@ -482,18 +554,26 @@  discard block
 block discarded – undo
482 554
 			//$w = '00';
483 555
 			$custom = '';
484 556
 			if ($ident != '') {
485
-				if ($custom != '') $custom .= '/';
557
+				if ($custom != '') {
558
+					$custom .= '/';
559
+				}
486 560
 				$custom .= 'CS='.$ident;
487 561
 			}
488 562
 			if ($squawk != '') {
489
-				if ($custom != '') $custom .= '/';
563
+				if ($custom != '') {
564
+					$custom .= '/';
565
+				}
490 566
 				$custom .= 'SQ='.$squawk;
491 567
 			}
492 568
 			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
493
-				if ($custom != '') $custom .= '/';
569
+				if ($custom != '') {
570
+					$custom .= '/';
571
+				}
494 572
 				$custom .= 'AI='.$aircraft_icao;
495 573
 			}
496
-			if ($custom != '') $custom = ' '.$custom;
574
+			if ($custom != '') {
575
+				$custom = ' '.$custom;
576
+			}
497 577
 			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
498 578
 		}
499 579
 	}
@@ -511,26 +591,38 @@  discard block
 block discarded – undo
511 591
 			//$w = '00';
512 592
 			$custom = '';
513 593
 			if ($ident != '') {
514
-				if ($custom != '') $custom .= '/';
594
+				if ($custom != '') {
595
+					$custom .= '/';
596
+				}
515 597
 				$custom .= 'CS='.$ident;
516 598
 			}
517 599
 			if ($typeid != '') {
518
-				if ($custom != '') $custom .= '/';
600
+				if ($custom != '') {
601
+					$custom .= '/';
602
+				}
519 603
 				$custom .= 'TI='.$typeid;
520 604
 			}
521 605
 			if ($imo != '') {
522
-				if ($custom != '') $custom .= '/';
606
+				if ($custom != '') {
607
+					$custom .= '/';
608
+				}
523 609
 				$custom .= 'IMO='.$imo;
524 610
 			}
525 611
 			if ($arrival_date != '') {
526
-				if ($custom != '') $custom .= '/';
612
+				if ($custom != '') {
613
+					$custom .= '/';
614
+				}
527 615
 				$custom .= 'AD='.strtotime($arrival_date);
528 616
 			}
529 617
 			if ($arrival_code != '') {
530
-				if ($custom != '') $custom .= '/';
618
+				if ($custom != '') {
619
+					$custom .= '/';
620
+				}
531 621
 				$custom .= 'AC='.$arrival_code;
532 622
 			}
533
-			if ($custom != '') $custom = ' '.$custom;
623
+			if ($custom != '') {
624
+				$custom = ' '.$custom;
625
+			}
534 626
 			$altitude = 0;
535 627
 			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
536 628
 		}
Please login to merge, or discard this patch.