Completed
Push — master ( 130544...e699fe )
by Yannick
08:48
created
scripts/daemon-spotter.php 1 patch
Indentation   +857 added lines, -857 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,42 +24,42 @@  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','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::'));
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
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
58
-    else $globalSources[] = array('host' => $options['s']);
56
+	$globalSources = array();
57
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
58
+	else $globalSources[] = array('host' => $options['s']);
59 59
 } elseif (isset($options['source'])) {
60
-    $globalSources = array();
61
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
62
-    else $globalSources[] = array('host' => $options['source']);
60
+	$globalSources = array();
61
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
62
+	else $globalSources[] = array('host' => $options['source']);
63 63
 }
64 64
 if (isset($options['aprsserverhost'])) $globalServerAPRShost = $options['aprsserverhost'];
65 65
 if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 if (isset($options['idsource'])) $id_source = $options['idsource'];
71 71
 else $id_source = 1;
72 72
 if (isset($globalServer) && $globalServer) {
73
-    if ($globalDebug) echo "Using Server Mode\n";
74
-    $SI=new SpotterServer();
73
+	if ($globalDebug) echo "Using Server Mode\n";
74
+	$SI=new SpotterServer();
75 75
 /*
76 76
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
77 77
     $SI = new adsb2aprs();
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 } else $SI=new SpotterImport($Connection->db);
81 81
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
82 82
 if (isset($globalMarine) && $globalMarine) {
83
-    $AIS = new AIS();
84
-    $MI = new MarineImport($Connection->db);
83
+	$AIS = new AIS();
84
+	$MI = new MarineImport($Connection->db);
85 85
 }
86 86
 //$APRS=new APRS($Connection->db);
87 87
 $SBS=new SBS();
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
 //$servertz = system('date +%Z');
92 92
 // signal handler - playing nice with sockets and dump1090
93 93
 if (function_exists('pcntl_fork')) {
94
-    pcntl_signal(SIGINT,  function() {
95
-        global $sockets;
96
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
97
-        die("Bye!\n");
98
-    });
99
-    pcntl_signal_dispatch();
94
+	pcntl_signal(SIGINT,  function() {
95
+		global $sockets;
96
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
97
+		die("Bye!\n");
98
+	});
99
+	pcntl_signal_dispatch();
100 100
 }
101 101
 
102 102
 // let's try and connect
@@ -106,153 +106,153 @@  discard block
 block discarded – undo
106 106
 $reset = 0;
107 107
 
108 108
 function connect_all($hosts) {
109
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
110
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
111
-    $reset++;
112
-    if ($globalDebug) echo 'Connect to all...'."\n";
113
-    foreach ($hosts as $id => $value) {
109
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
110
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
111
+	$reset++;
112
+	if ($globalDebug) echo 'Connect to all...'."\n";
113
+	foreach ($hosts as $id => $value) {
114 114
 	$host = $value['host'];
115 115
 	$globalSources[$id]['last_exec'] = 0;
116 116
 	// Here we check type of source(s)
117 117
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
118
-            if (preg_match('/deltadb.txt$/i',$host)) {
119
-        	//$formats[$id] = 'deltadbtxt';
120
-        	$globalSources[$id]['format'] = 'deltadbtxt';
121
-        	//$last_exec['deltadbtxt'] = 0;
122
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
123
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
124
-        	//$formats[$id] = 'vatsimtxt';
125
-        	$globalSources[$id]['format'] = 'vatsimtxt';
126
-        	//$last_exec['vatsimtxt'] = 0;
127
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
128
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
129
-        	//$formats[$id] = 'aircraftlistjson';
130
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
131
-        	//$last_exec['aircraftlistjson'] = 0;
132
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
133
-    	    } else if (preg_match('/opensky/i',$host)) {
134
-        	//$formats[$id] = 'aircraftlistjson';
135
-        	$globalSources[$id]['format'] = 'opensky';
136
-        	//$last_exec['aircraftlistjson'] = 0;
137
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
138
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
139
-        	//$formats[$id] = 'radarvirtueljson';
140
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
141
-        	//$last_exec['radarvirtueljson'] = 0;
142
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
143
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
144
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
145
-        	    exit(0);
146
-        	}
147
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
148
-        	//$formats[$id] = 'planeupdatefaa';
149
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
150
-        	//$last_exec['planeupdatefaa'] = 0;
151
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
152
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
153
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
154
-        	    exit(0);
155
-        	}
156
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
157
-        	//$formats[$id] = 'phpvmacars';
158
-        	$globalSources[$id]['format'] = 'phpvmacars';
159
-        	//$last_exec['phpvmacars'] = 0;
160
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
161
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
162
-        	//$formats[$id] = 'phpvmacars';
163
-        	$globalSources[$id]['format'] = 'vam';
164
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
165
-            } else if (preg_match('/whazzup/i',$host)) {
166
-        	//$formats[$id] = 'whazzup';
167
-        	$globalSources[$id]['format'] = 'whazzup';
168
-        	//$last_exec['whazzup'] = 0;
169
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
170
-            } else if (preg_match('/recentpireps/i',$host)) {
171
-        	//$formats[$id] = 'pirepsjson';
172
-        	$globalSources[$id]['format'] = 'pirepsjson';
173
-        	//$last_exec['pirepsjson'] = 0;
174
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
175
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
176
-        	//$formats[$id] = 'fr24json';
177
-        	$globalSources[$id]['format'] = 'fr24json';
178
-        	//$last_exec['fr24json'] = 0;
179
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
180
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
181
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
182
-        	    exit(0);
183
-        	}
184
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
185
-        	//$formats[$id] = 'fr24json';
186
-        	$globalSources[$id]['format'] = 'myshiptracking';
187
-        	//$last_exec['fr24json'] = 0;
188
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
189
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
190
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
191
-        	    exit(0);
192
-        	}
193
-            //} else if (preg_match('/10001/',$host)) {
194
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
195
-        	//$formats[$id] = 'tsv';
196
-        	$globalSources[$id]['format'] = 'tsv';
197
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
198
-            }
199
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
200
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
201
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
202
-    		    if ($idf !== false) {
203
-    			$httpfeeds[$id] = $idf;
204
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
205
-    		    }
206
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
207
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
208
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
209
-	    $hostport = explode(':',$host);
210
-	    if (isset($hostport[1])) {
118
+			if (preg_match('/deltadb.txt$/i',$host)) {
119
+			//$formats[$id] = 'deltadbtxt';
120
+			$globalSources[$id]['format'] = 'deltadbtxt';
121
+			//$last_exec['deltadbtxt'] = 0;
122
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
123
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
124
+			//$formats[$id] = 'vatsimtxt';
125
+			$globalSources[$id]['format'] = 'vatsimtxt';
126
+			//$last_exec['vatsimtxt'] = 0;
127
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
128
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
129
+			//$formats[$id] = 'aircraftlistjson';
130
+			$globalSources[$id]['format'] = 'aircraftlistjson';
131
+			//$last_exec['aircraftlistjson'] = 0;
132
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
133
+			} else if (preg_match('/opensky/i',$host)) {
134
+			//$formats[$id] = 'aircraftlistjson';
135
+			$globalSources[$id]['format'] = 'opensky';
136
+			//$last_exec['aircraftlistjson'] = 0;
137
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
138
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
139
+			//$formats[$id] = 'radarvirtueljson';
140
+			$globalSources[$id]['format'] = 'radarvirtueljson';
141
+			//$last_exec['radarvirtueljson'] = 0;
142
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
143
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
144
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
145
+				exit(0);
146
+			}
147
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
148
+			//$formats[$id] = 'planeupdatefaa';
149
+			$globalSources[$id]['format'] = 'planeupdatefaa';
150
+			//$last_exec['planeupdatefaa'] = 0;
151
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
152
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
153
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
154
+				exit(0);
155
+			}
156
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
157
+			//$formats[$id] = 'phpvmacars';
158
+			$globalSources[$id]['format'] = 'phpvmacars';
159
+			//$last_exec['phpvmacars'] = 0;
160
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
161
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
162
+			//$formats[$id] = 'phpvmacars';
163
+			$globalSources[$id]['format'] = 'vam';
164
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
165
+			} else if (preg_match('/whazzup/i',$host)) {
166
+			//$formats[$id] = 'whazzup';
167
+			$globalSources[$id]['format'] = 'whazzup';
168
+			//$last_exec['whazzup'] = 0;
169
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
170
+			} else if (preg_match('/recentpireps/i',$host)) {
171
+			//$formats[$id] = 'pirepsjson';
172
+			$globalSources[$id]['format'] = 'pirepsjson';
173
+			//$last_exec['pirepsjson'] = 0;
174
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
175
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
176
+			//$formats[$id] = 'fr24json';
177
+			$globalSources[$id]['format'] = 'fr24json';
178
+			//$last_exec['fr24json'] = 0;
179
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
180
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
181
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
182
+				exit(0);
183
+			}
184
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
185
+			//$formats[$id] = 'fr24json';
186
+			$globalSources[$id]['format'] = 'myshiptracking';
187
+			//$last_exec['fr24json'] = 0;
188
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
189
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
190
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
191
+				exit(0);
192
+			}
193
+			//} else if (preg_match('/10001/',$host)) {
194
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
195
+			//$formats[$id] = 'tsv';
196
+			$globalSources[$id]['format'] = 'tsv';
197
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
198
+			}
199
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
200
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
201
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
202
+				if ($idf !== false) {
203
+				$httpfeeds[$id] = $idf;
204
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
205
+				}
206
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
207
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
208
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
209
+		$hostport = explode(':',$host);
210
+		if (isset($hostport[1])) {
211 211
 		$port = $hostport[1];
212 212
 		$hostn = $hostport[0];
213
-	    } else {
213
+		} else {
214 214
 		$port = $globalSources[$id]['port'];
215 215
 		$hostn = $globalSources[$id]['host'];
216
-	    }
217
-	    $Common = new Common();
218
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
219
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
220
-    	    } else {
221
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
222
-	    }
223
-	    if ($s) {
224
-    	        $sockets[$id] = $s;
225
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
226
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
216
+		}
217
+		$Common = new Common();
218
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
219
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
220
+			} else {
221
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
222
+		}
223
+		if ($s) {
224
+				$sockets[$id] = $s;
225
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
226
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
227 227
 			//$formats[$id] = 'aprs';
228 228
 			$globalSources[$id]['format'] = 'aprs';
229 229
 			//$aprs_connect = 0;
230 230
 			//$use_aprs = true;
231
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
231
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
232 232
 			$globalSources[$id]['format'] = 'vrstcp';
233
-    		    } elseif ($port == '10001') {
234
-        		//$formats[$id] = 'tsv';
235
-        		$globalSources[$id]['format'] = 'tsv';
236
-		    } elseif ($port == '30002') {
237
-        		//$formats[$id] = 'raw';
238
-        		$globalSources[$id]['format'] = 'raw';
239
-		    } elseif ($port == '5001') {
240
-        		//$formats[$id] = 'raw';
241
-        		$globalSources[$id]['format'] = 'flightgearmp';
242
-		    } elseif ($port == '30005') {
233
+				} elseif ($port == '10001') {
234
+				//$formats[$id] = 'tsv';
235
+				$globalSources[$id]['format'] = 'tsv';
236
+			} elseif ($port == '30002') {
237
+				//$formats[$id] = 'raw';
238
+				$globalSources[$id]['format'] = 'raw';
239
+			} elseif ($port == '5001') {
240
+				//$formats[$id] = 'raw';
241
+				$globalSources[$id]['format'] = 'flightgearmp';
242
+			} elseif ($port == '30005') {
243 243
 			// Not yet supported
244
-        		//$formats[$id] = 'beast';
245
-        		$globalSources[$id]['format'] = 'beast';
246
-		    //} else $formats[$id] = 'sbs';
247
-		    } else $globalSources[$id]['format'] = 'sbs';
248
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
244
+				//$formats[$id] = 'beast';
245
+				$globalSources[$id]['format'] = 'beast';
246
+			//} else $formats[$id] = 'sbs';
247
+			} else $globalSources[$id]['format'] = 'sbs';
248
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
249 249
 		}
250 250
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
251
-            } else {
251
+			} else {
252 252
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
253
-    	    }
254
-        }
255
-    }
253
+			}
254
+		}
255
+	}
256 256
 }
257 257
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
258 258
 
@@ -275,9 +275,9 @@  discard block
 block discarded – undo
275 275
 //connect_all($globalSources);
276 276
 
277 277
 if (isset($globalProxy) && $globalProxy) {
278
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
278
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
279 279
 } else {
280
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
280
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
281 281
 }
282 282
 
283 283
 // APRS Configuration
@@ -286,18 +286,18 @@  discard block
 block discarded – undo
286 286
 	die;
287 287
 }
288 288
 foreach ($globalSources as $key => $source) {
289
-    if (!isset($source['format'])) {
290
-        $globalSources[$key]['format'] = 'auto';
291
-    }
289
+	if (!isset($source['format'])) {
290
+		$globalSources[$key]['format'] = 'auto';
291
+	}
292 292
 }
293 293
 connect_all($globalSources);
294 294
 foreach ($globalSources as $key => $source) {
295
-    if (isset($source['format']) && $source['format'] == 'aprs') {
295
+	if (isset($source['format']) && $source['format'] == 'aprs') {
296 296
 	$aprs_connect = 0;
297 297
 	$use_aprs = true;
298 298
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
299 299
 	break;
300
-    }
300
+	}
301 301
 }
302 302
 
303 303
 if ($use_aprs) {
@@ -338,152 +338,152 @@  discard block
 block discarded – undo
338 338
 
339 339
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
340 340
 while ($i > 0) {
341
-    if (!$globalDaemon) $i = $endtime-time();
342
-    // Delete old ATC
343
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
341
+	if (!$globalDaemon) $i = $endtime-time();
342
+	// Delete old ATC
343
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
344 344
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
345
-        $ATC->deleteOldATC();
346
-    }
345
+		$ATC->deleteOldATC();
346
+	}
347 347
     
348
-    //if (count($last_exec) > 0) {
349
-    if (count($last_exec) == count($globalSources)) {
348
+	//if (count($last_exec) > 0) {
349
+	if (count($last_exec) == count($globalSources)) {
350 350
 	$max = $globalMinFetch;
351 351
 	foreach ($last_exec as $last) {
352
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
352
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
353 353
 	}
354 354
 	if ($max != $globalMinFetch) {
355
-	    if ($globalDebug) echo 'Sleeping...'."\n";
356
-	    sleep($globalMinFetch-$max+2);
355
+		if ($globalDebug) echo 'Sleeping...'."\n";
356
+		sleep($globalMinFetch-$max+2);
357
+	}
357 358
 	}
358
-    }
359 359
 
360 360
     
361
-    //foreach ($formats as $id => $value) {
362
-    foreach ($globalSources as $id => $value) {
361
+	//foreach ($formats as $id => $value) {
362
+	foreach ($globalSources as $id => $value) {
363 363
 	date_default_timezone_set('UTC');
364 364
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
365 365
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
366
-	    //$buffer = $Common->getData($hosts[$id]);
367
-	    $buffer = $Common->getData($value['host']);
368
-	    if ($buffer != '') $reset = 0;
369
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
370
-	    $buffer = explode('\n',$buffer);
371
-	    foreach ($buffer as $line) {
372
-    		if ($line != '' && count($line) > 7) {
373
-    		    $line = explode(',', $line);
374
-	            $data = array();
375
-	            $data['hex'] = $line[1]; // hex
376
-	            $data['ident'] = $line[2]; // ident
377
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
378
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
379
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
380
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
381
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
382
-	            $data['verticalrate'] = ''; // vertical rate
383
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
384
-	            $data['emergency'] = ''; // emergency
385
-		    $data['datetime'] = date('Y-m-d H:i:s');
386
-		    $data['format_source'] = 'deltadbtxt';
387
-    		    $data['id_source'] = $id_source;
388
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
389
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
390
-    		    $SI->add($data);
391
-		    unset($data);
392
-    		}
393
-    	    }
394
-    	    $last_exec[$id]['last'] = time();
366
+		//$buffer = $Common->getData($hosts[$id]);
367
+		$buffer = $Common->getData($value['host']);
368
+		if ($buffer != '') $reset = 0;
369
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
370
+		$buffer = explode('\n',$buffer);
371
+		foreach ($buffer as $line) {
372
+			if ($line != '' && count($line) > 7) {
373
+				$line = explode(',', $line);
374
+				$data = array();
375
+				$data['hex'] = $line[1]; // hex
376
+				$data['ident'] = $line[2]; // ident
377
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
378
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
379
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
380
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
381
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
382
+				$data['verticalrate'] = ''; // vertical rate
383
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
384
+				$data['emergency'] = ''; // emergency
385
+			$data['datetime'] = date('Y-m-d H:i:s');
386
+			$data['format_source'] = 'deltadbtxt';
387
+				$data['id_source'] = $id_source;
388
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
389
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
390
+				$SI->add($data);
391
+			unset($data);
392
+			}
393
+			}
394
+			$last_exec[$id]['last'] = time();
395 395
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
396
-	    date_default_timezone_set('CET');
397
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
398
-	    date_default_timezone_set('UTC');
399
-	    if ($buffer != '') $reset = 0;
400
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
401
-	    $buffer = explode('\n',$buffer);
402
-	    foreach ($buffer as $line) {
396
+		date_default_timezone_set('CET');
397
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
398
+		date_default_timezone_set('UTC');
399
+		if ($buffer != '') $reset = 0;
400
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
401
+		$buffer = explode('\n',$buffer);
402
+		foreach ($buffer as $line) {
403 403
 		if ($line != '') {
404
-		    echo "'".$line."'\n";
405
-		    $add = false;
406
-		    $ais_data = $AIS->parse_line(trim($line));
407
-		    $data = array();
408
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
409
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
410
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
411
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
412
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
413
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
414
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
415
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
416
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
417
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
418
-		    if (isset($ais_data['timestamp'])) {
404
+			echo "'".$line."'\n";
405
+			$add = false;
406
+			$ais_data = $AIS->parse_line(trim($line));
407
+			$data = array();
408
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
409
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
410
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
411
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
412
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
413
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
414
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
415
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
416
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
417
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
418
+			if (isset($ais_data['timestamp'])) {
419 419
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
420 420
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
421
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
422
-			    $add = true;
421
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
422
+				$add = true;
423 423
 			}
424
-		    } else {
424
+			} else {
425 425
 			$data['datetime'] = date('Y-m-d H:i:s');
426 426
 			$add = true;
427
-		    }
428
-		    $data['format_source'] = 'aisnmeatxt';
429
-    		    $data['id_source'] = $id_source;
430
-		    print_r($data);
431
-		    echo 'Add...'."\n";
432
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
433
-		    unset($data);
427
+			}
428
+			$data['format_source'] = 'aisnmeatxt';
429
+				$data['id_source'] = $id_source;
430
+			print_r($data);
431
+			echo 'Add...'."\n";
432
+			if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
433
+			unset($data);
434 434
 		}
435
-    	    }
436
-    	    $last_exec[$id]['last'] = time();
435
+			}
436
+			$last_exec[$id]['last'] = time();
437 437
 	} elseif ($value['format'] == 'aisnmeahttp') {
438
-	    $arr = $httpfeeds;
439
-	    $w = $e = null;
438
+		$arr = $httpfeeds;
439
+		$w = $e = null;
440 440
 	    
441
-	    if (isset($arr[$id])) {
442
-	    $nn = stream_select($arr,$w,$e,$timeout);
443
-	    if ($nn > 0) {
441
+		if (isset($arr[$id])) {
442
+		$nn = stream_select($arr,$w,$e,$timeout);
443
+		if ($nn > 0) {
444 444
 		foreach ($httpfeeds as $feed) {
445
-		    $buffer = stream_get_line($feed,2000,"\n");
446
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
447
-		    $buffer = explode('\n',$buffer);
448
-		    foreach ($buffer as $line) {
445
+			$buffer = stream_get_line($feed,2000,"\n");
446
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
447
+			$buffer = explode('\n',$buffer);
448
+			foreach ($buffer as $line) {
449 449
 			if ($line != '') {
450
-			    $ais_data = $AIS->parse_line(trim($line));
451
-			    $data = array();
452
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
453
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
454
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
455
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
456
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
457
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
458
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
459
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
460
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
461
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
462
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
463
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
464
-			    if (isset($ais_data['timestamp'])) {
450
+				$ais_data = $AIS->parse_line(trim($line));
451
+				$data = array();
452
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
453
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
454
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
455
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
456
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
457
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
458
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
459
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
460
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
461
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
462
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
463
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
464
+				if (isset($ais_data['timestamp'])) {
465 465
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
466
-			    } else {
466
+				} else {
467 467
 				$data['datetime'] = date('Y-m-d H:i:s');
468
-			    }
469
-			    $data['format_source'] = 'aisnmeahttp';
470
-			    $data['id_source'] = $id_source;
471
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
472
-			    unset($data);
468
+				}
469
+				$data['format_source'] = 'aisnmeahttp';
470
+				$data['id_source'] = $id_source;
471
+				if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
472
+				unset($data);
473 473
 			}
474
-		    }
474
+			}
475
+		}
475 476
 		}
476 477
 		}
477
-	    }
478 478
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
479
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
480
-	    if ($buffer != '') {
479
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
480
+		if ($buffer != '') {
481 481
 		//echo $buffer;
482 482
 		$all_data = json_decode($buffer,true);
483 483
 		//print_r($all_data);
484 484
 		if (isset($all_data[0]['DATA'])) {
485 485
 		foreach ($all_data[0]['DATA'] as $line) {
486
-		    if ($line != '') {
486
+			if ($line != '') {
487 487
 			$data = array();
488 488
 			$data['ident'] = $line['NAME'];
489 489
 			$data['mmsi'] = $line['MMSI'];
@@ -499,87 +499,87 @@  discard block
 block discarded – undo
499 499
 			$data['id_source'] = $id_source;
500 500
 			$MI->add($data);
501 501
 			unset($data);
502
-		    }
502
+			}
503 503
 		}
504 504
 		}
505 505
 		
506
-	    }
507
-    	    $last_exec[$id]['last'] = time();
506
+		}
507
+			$last_exec[$id]['last'] = time();
508 508
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
509
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
510
-	    if ($buffer != '') {
509
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
510
+		if ($buffer != '') {
511 511
 		$all_data = json_decode($buffer,true);
512 512
 		if (isset($all_data[0]['mmsi'])) {
513
-		    foreach ($all_data as $line) {
513
+			foreach ($all_data as $line) {
514 514
 			if ($line != '') {
515
-			    $data = array();
516
-			    $data['ident'] = $line['shipname'];
517
-			    $data['callsign'] = $line['callsign'];
518
-			    $data['mmsi'] = $line['mmsi'];
519
-			    $data['speed'] = $line['sog'];
520
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
521
-			    $data['latitude'] = $line['latitude'];
522
-			    $data['longitude'] = $line['longitude'];
523
-			    $data['type_id'] = $line['shiptype'];
524
-			    $data['arrival_code'] = $line['destination'];
525
-			    $data['datetime'] = $line['time'];
526
-			    $data['format_source'] = 'boatbeaconapp';
527
-			    $data['id_source'] = $id_source;
528
-			    $MI->add($data);
529
-			    unset($data);
515
+				$data = array();
516
+				$data['ident'] = $line['shipname'];
517
+				$data['callsign'] = $line['callsign'];
518
+				$data['mmsi'] = $line['mmsi'];
519
+				$data['speed'] = $line['sog'];
520
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
521
+				$data['latitude'] = $line['latitude'];
522
+				$data['longitude'] = $line['longitude'];
523
+				$data['type_id'] = $line['shiptype'];
524
+				$data['arrival_code'] = $line['destination'];
525
+				$data['datetime'] = $line['time'];
526
+				$data['format_source'] = 'boatbeaconapp';
527
+				$data['id_source'] = $id_source;
528
+				$MI->add($data);
529
+				unset($data);
530
+			}
530 531
 			}
531
-		    }
532 532
 		}
533 533
 		
534
-	    }
535
-    	    $last_exec[$id]['last'] = time();
534
+		}
535
+			$last_exec[$id]['last'] = time();
536 536
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
537
-	    echo 'download...';
538
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
539
-	    echo 'done !'."\n";
540
-	    if ($buffer != '') $reset = 0;
541
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
542
-	    $buffer = explode('\n',$buffer);
543
-	    foreach ($buffer as $line) {
537
+		echo 'download...';
538
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
539
+		echo 'done !'."\n";
540
+		if ($buffer != '') $reset = 0;
541
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
542
+		$buffer = explode('\n',$buffer);
543
+		foreach ($buffer as $line) {
544 544
 		if ($line != '') {
545
-		    $data = array();
546
-		    $data['mmsi'] = (int)substr($line,0,9);
547
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
548
-		    //$data['status'] = substr($line,21,2);
549
-		    //$data['type'] = substr($line,24,3);
550
-		    $data['latitude'] = substr($line,29,9);
551
-		    $data['longitude'] = substr($line,41,9);
552
-		    $data['speed'] = round(substr($line,51,5));
553
-		    //$data['course'] = substr($line,57,5);
554
-		    $data['heading'] = round(substr($line,63,3));
555
-		    //$data['draft'] = substr($line,67,4);
556
-		    //$data['length'] = substr($line,72,3);
557
-		    //$data['beam'] = substr($line,76,2);
558
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
559
-		    //$data['callsign'] = trim(substr($line,100,7);
560
-		    //$data['dest'] = substr($line,108,20);
561
-		    //$data['etaDate'] = substr($line,129,5);
562
-		    //$data['etaTime'] = substr($line,135,5);
563
-		    $data['format_source'] = 'shipplotter';
564
-    		    $data['id_source'] = $id_source;
565
-		    print_r($data);
566
-		    echo 'Add...'."\n";
567
-		    $MI->add($data);
568
-		    unset($data);
545
+			$data = array();
546
+			$data['mmsi'] = (int)substr($line,0,9);
547
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
548
+			//$data['status'] = substr($line,21,2);
549
+			//$data['type'] = substr($line,24,3);
550
+			$data['latitude'] = substr($line,29,9);
551
+			$data['longitude'] = substr($line,41,9);
552
+			$data['speed'] = round(substr($line,51,5));
553
+			//$data['course'] = substr($line,57,5);
554
+			$data['heading'] = round(substr($line,63,3));
555
+			//$data['draft'] = substr($line,67,4);
556
+			//$data['length'] = substr($line,72,3);
557
+			//$data['beam'] = substr($line,76,2);
558
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
559
+			//$data['callsign'] = trim(substr($line,100,7);
560
+			//$data['dest'] = substr($line,108,20);
561
+			//$data['etaDate'] = substr($line,129,5);
562
+			//$data['etaTime'] = substr($line,135,5);
563
+			$data['format_source'] = 'shipplotter';
564
+				$data['id_source'] = $id_source;
565
+			print_r($data);
566
+			echo 'Add...'."\n";
567
+			$MI->add($data);
568
+			unset($data);
569 569
 		}
570
-    	    }
571
-    	    $last_exec[$id]['last'] = time();
570
+			}
571
+			$last_exec[$id]['last'] = time();
572 572
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
573 573
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
574
-	    //$buffer = $Common->getData($hosts[$id]);
575
-	    $buffer = $Common->getData($value['host']);
576
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
577
-	    $buffer = explode('\n',$buffer);
578
-	    $reset = 0;
579
-	    foreach ($buffer as $line) {
580
-    		if ($line != '') {
581
-    		    $line = explode(':', $line);
582
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
574
+		//$buffer = $Common->getData($hosts[$id]);
575
+		$buffer = $Common->getData($value['host']);
576
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
577
+		$buffer = explode('\n',$buffer);
578
+		$reset = 0;
579
+		foreach ($buffer as $line) {
580
+			if ($line != '') {
581
+				$line = explode(':', $line);
582
+				if (count($line) > 30 && $line[0] != 'callsign') {
583 583
 			$data = array();
584 584
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
585 585
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -592,36 +592,36 @@  discard block
 block discarded – undo
592 592
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
593 593
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
594 594
 			$data['latitude'] = $line[5]; // lat
595
-	        	$data['longitude'] = $line[6]; // long
596
-	        	$data['verticalrate'] = ''; // vertical rate
597
-	        	$data['squawk'] = ''; // squawk
598
-	        	$data['emergency'] = ''; // emergency
599
-	        	$data['waypoints'] = $line[30];
595
+				$data['longitude'] = $line[6]; // long
596
+				$data['verticalrate'] = ''; // vertical rate
597
+				$data['squawk'] = ''; // squawk
598
+				$data['emergency'] = ''; // emergency
599
+				$data['waypoints'] = $line[30];
600 600
 			$data['datetime'] = date('Y-m-d H:i:s');
601 601
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
602 602
 			//if (isset($line[37])) $data['last_update'] = $line[37];
603
-		        $data['departure_airport_icao'] = $line[11];
604
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
605
-		        $data['arrival_airport_icao'] = $line[13];
603
+				$data['departure_airport_icao'] = $line[11];
604
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
605
+				$data['arrival_airport_icao'] = $line[13];
606 606
 			$data['frequency'] = $line[4];
607 607
 			$data['type'] = $line[18];
608 608
 			$data['range'] = $line[19];
609 609
 			if (isset($line[35])) $data['info'] = $line[35];
610
-    			$data['id_source'] = $id_source;
611
-	    		//$data['arrival_airport_time'] = ;
612
-	    		if ($line[9] != '') {
613
-	    		    $aircraft_data = explode('/',$line[9]);
614
-	    		    if (isset($aircraft_data[1])) {
615
-	    			$data['aircraft_icao'] = $aircraft_data[1];
616
-	    		    }
617
-        		}
618
-	    		/*
610
+				$data['id_source'] = $id_source;
611
+				//$data['arrival_airport_time'] = ;
612
+				if ($line[9] != '') {
613
+					$aircraft_data = explode('/',$line[9]);
614
+					if (isset($aircraft_data[1])) {
615
+					$data['aircraft_icao'] = $aircraft_data[1];
616
+					}
617
+				}
618
+				/*
619 619
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
620 620
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
621 621
 	    		*/
622
-	    		$data['format_source'] = $value['format'];
622
+				$data['format_source'] = $value['format'];
623 623
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
624
-    			if ($line[3] == 'PILOT') $SI->add($data);
624
+				if ($line[3] == 'PILOT') $SI->add($data);
625 625
 			elseif ($line[3] == 'ATC') {
626 626
 				//print_r($data);
627 627
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -639,247 +639,247 @@  discard block
 block discarded – undo
639 639
 				if (!isset($data['source_name'])) $data['source_name'] = '';
640 640
 				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']);
641 641
 			}
642
-    			unset($data);
643
-    		    }
644
-    		}
645
-    	    }
646
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
647
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
648
-    	    $last_exec[$id]['last'] = time();
649
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
650
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
651
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
652
-	    if ($buffer != '') {
653
-	    $all_data = json_decode($buffer,true);
654
-	    if (isset($all_data['acList'])) {
642
+				unset($data);
643
+				}
644
+			}
645
+			}
646
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
647
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
648
+			$last_exec[$id]['last'] = time();
649
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
650
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
651
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
652
+		if ($buffer != '') {
653
+		$all_data = json_decode($buffer,true);
654
+		if (isset($all_data['acList'])) {
655 655
 		$reset = 0;
656 656
 		foreach ($all_data['acList'] as $line) {
657
-		    $data = array();
658
-		    $data['hex'] = $line['Icao']; // hex
659
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
660
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
661
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
662
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
663
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
664
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
665
-		    //$data['verticalrate'] = $line['']; // verticale rate
666
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
667
-		    $data['emergency'] = ''; // emergency
668
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
669
-		    /*
657
+			$data = array();
658
+			$data['hex'] = $line['Icao']; // hex
659
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
660
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
661
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
662
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
663
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
664
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
665
+			//$data['verticalrate'] = $line['']; // verticale rate
666
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
667
+			$data['emergency'] = ''; // emergency
668
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
669
+			/*
670 670
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
671 671
 		    else $data['datetime'] = date('Y-m-d H:i:s');
672 672
 		    */
673
-		    $data['datetime'] = date('Y-m-d H:i:s');
674
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
675
-	    	    $data['format_source'] = 'aircraftlistjson';
676
-		    $data['id_source'] = $id_source;
677
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
678
-		    if (isset($data['latitude'])) $SI->add($data);
679
-		    unset($data);
673
+			$data['datetime'] = date('Y-m-d H:i:s');
674
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
675
+				$data['format_source'] = 'aircraftlistjson';
676
+			$data['id_source'] = $id_source;
677
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
678
+			if (isset($data['latitude'])) $SI->add($data);
679
+			unset($data);
680 680
 		}
681
-	    } elseif (is_array($all_data)) {
681
+		} elseif (is_array($all_data)) {
682 682
 		$reset = 0;
683 683
 		foreach ($all_data as $line) {
684
-		    $data = array();
685
-		    $data['hex'] = $line['hex']; // hex
686
-		    $data['ident'] = $line['flight']; // ident
687
-		    $data['altitude'] = $line['altitude']; // altitude
688
-		    $data['speed'] = $line['speed']; // speed
689
-		    $data['heading'] = $line['track']; // heading
690
-		    $data['latitude'] = $line['lat']; // lat
691
-		    $data['longitude'] = $line['lon']; // long
692
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
693
-		    $data['squawk'] = $line['squawk']; // squawk
694
-		    $data['emergency'] = ''; // emergency
695
-		    $data['datetime'] = date('Y-m-d H:i:s');
696
-	    	    $data['format_source'] = 'aircraftlistjson';
697
-    		    $data['id_source'] = $id_source;
698
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
699
-		    $SI->add($data);
700
-		    unset($data);
684
+			$data = array();
685
+			$data['hex'] = $line['hex']; // hex
686
+			$data['ident'] = $line['flight']; // ident
687
+			$data['altitude'] = $line['altitude']; // altitude
688
+			$data['speed'] = $line['speed']; // speed
689
+			$data['heading'] = $line['track']; // heading
690
+			$data['latitude'] = $line['lat']; // lat
691
+			$data['longitude'] = $line['lon']; // long
692
+			$data['verticalrate'] = $line['vrt']; // verticale rate
693
+			$data['squawk'] = $line['squawk']; // squawk
694
+			$data['emergency'] = ''; // emergency
695
+			$data['datetime'] = date('Y-m-d H:i:s');
696
+				$data['format_source'] = 'aircraftlistjson';
697
+				$data['id_source'] = $id_source;
698
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
699
+			$SI->add($data);
700
+			unset($data);
701
+		}
702
+		}
701 703
 		}
702
-	    }
703
-	    }
704
-    	    //$last_exec['aircraftlistjson'] = time();
705
-    	    $last_exec[$id]['last'] = time();
706
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
707
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
708
-	    $buffer = $Common->getData($value['host']);
709
-	    $all_data = json_decode($buffer,true);
710
-	    if (isset($all_data['planes'])) {
704
+			//$last_exec['aircraftlistjson'] = time();
705
+			$last_exec[$id]['last'] = time();
706
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
707
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
708
+		$buffer = $Common->getData($value['host']);
709
+		$all_data = json_decode($buffer,true);
710
+		if (isset($all_data['planes'])) {
711 711
 		$reset = 0;
712 712
 		foreach ($all_data['planes'] as $key => $line) {
713
-		    $data = array();
714
-		    $data['hex'] = $key; // hex
715
-		    $data['ident'] = $line[3]; // ident
716
-		    $data['altitude'] = $line[6]; // altitude
717
-		    $data['speed'] = $line[8]; // speed
718
-		    $data['heading'] = $line[7]; // heading
719
-		    $data['latitude'] = $line[4]; // lat
720
-		    $data['longitude'] = $line[5]; // long
721
-		    //$data['verticalrate'] = $line[]; // verticale rate
722
-		    $data['squawk'] = $line[10]; // squawk
723
-		    $data['emergency'] = ''; // emergency
724
-		    $data['registration'] = $line[2];
725
-		    $data['aircraft_icao'] = $line[0];
726
-		    $deparr = explode('-',$line[1]);
727
-		    if (count($deparr) == 2) {
713
+			$data = array();
714
+			$data['hex'] = $key; // hex
715
+			$data['ident'] = $line[3]; // ident
716
+			$data['altitude'] = $line[6]; // altitude
717
+			$data['speed'] = $line[8]; // speed
718
+			$data['heading'] = $line[7]; // heading
719
+			$data['latitude'] = $line[4]; // lat
720
+			$data['longitude'] = $line[5]; // long
721
+			//$data['verticalrate'] = $line[]; // verticale rate
722
+			$data['squawk'] = $line[10]; // squawk
723
+			$data['emergency'] = ''; // emergency
724
+			$data['registration'] = $line[2];
725
+			$data['aircraft_icao'] = $line[0];
726
+			$deparr = explode('-',$line[1]);
727
+			if (count($deparr) == 2) {
728 728
 			$data['departure_airport_icao'] = $deparr[0];
729 729
 			$data['arrival_airport_icao'] = $deparr[1];
730
-		    }
731
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
732
-	    	    $data['format_source'] = 'planeupdatefaa';
733
-    		    $data['id_source'] = $id_source;
734
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
735
-		    $SI->add($data);
736
-		    unset($data);
730
+			}
731
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
732
+				$data['format_source'] = 'planeupdatefaa';
733
+				$data['id_source'] = $id_source;
734
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
735
+			$SI->add($data);
736
+			unset($data);
737
+		}
737 738
 		}
738
-	    }
739
-    	    //$last_exec['planeupdatefaa'] = time();
740
-    	    $last_exec[$id]['last'] = time();
741
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
742
-	    $buffer = $Common->getData($value['host']);
743
-	    $all_data = json_decode($buffer,true);
744
-	    if (isset($all_data['states'])) {
739
+			//$last_exec['planeupdatefaa'] = time();
740
+			$last_exec[$id]['last'] = time();
741
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
742
+		$buffer = $Common->getData($value['host']);
743
+		$all_data = json_decode($buffer,true);
744
+		if (isset($all_data['states'])) {
745 745
 		$reset = 0;
746 746
 		foreach ($all_data['states'] as $key => $line) {
747
-		    $data = array();
748
-		    $data['hex'] = $line[0]; // hex
749
-		    $data['ident'] = trim($line[1]); // ident
750
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
751
-		    $data['speed'] = round($line[9]*1.94384); // speed
752
-		    $data['heading'] = round($line[10]); // heading
753
-		    $data['latitude'] = $line[5]; // lat
754
-		    $data['longitude'] = $line[6]; // long
755
-		    $data['verticalrate'] = $line[11]; // verticale rate
756
-		    //$data['squawk'] = $line[10]; // squawk
757
-		    //$data['emergency'] = ''; // emergency
758
-		    //$data['registration'] = $line[2];
759
-		    //$data['aircraft_icao'] = $line[0];
760
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
761
-	    	    $data['format_source'] = 'opensky';
762
-    		    $data['id_source'] = $id_source;
763
-		    $SI->add($data);
764
-		    unset($data);
747
+			$data = array();
748
+			$data['hex'] = $line[0]; // hex
749
+			$data['ident'] = trim($line[1]); // ident
750
+			$data['altitude'] = round($line[7]*3.28084); // altitude
751
+			$data['speed'] = round($line[9]*1.94384); // speed
752
+			$data['heading'] = round($line[10]); // heading
753
+			$data['latitude'] = $line[5]; // lat
754
+			$data['longitude'] = $line[6]; // long
755
+			$data['verticalrate'] = $line[11]; // verticale rate
756
+			//$data['squawk'] = $line[10]; // squawk
757
+			//$data['emergency'] = ''; // emergency
758
+			//$data['registration'] = $line[2];
759
+			//$data['aircraft_icao'] = $line[0];
760
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
761
+				$data['format_source'] = 'opensky';
762
+				$data['id_source'] = $id_source;
763
+			$SI->add($data);
764
+			unset($data);
765 765
 		}
766
-	    }
767
-    	    //$last_exec['planeupdatefaa'] = time();
768
-    	    $last_exec[$id]['last'] = time();
769
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
770
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
771
-	    //$buffer = $Common->getData($hosts[$id]);
772
-	    $buffer = $Common->getData($value['host']);
773
-	    $all_data = json_decode($buffer,true);
774
-	    if (!empty($all_data)) $reset = 0;
775
-	    foreach ($all_data as $key => $line) {
766
+		}
767
+			//$last_exec['planeupdatefaa'] = time();
768
+			$last_exec[$id]['last'] = time();
769
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
770
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
771
+		//$buffer = $Common->getData($hosts[$id]);
772
+		$buffer = $Common->getData($value['host']);
773
+		$all_data = json_decode($buffer,true);
774
+		if (!empty($all_data)) $reset = 0;
775
+		foreach ($all_data as $key => $line) {
776 776
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
777
-		    $data = array();
778
-		    $data['hex'] = $line[0];
779
-		    $data['ident'] = $line[16]; //$line[13]
780
-	    	    $data['altitude'] = $line[4]; // altitude
781
-	    	    $data['speed'] = $line[5]; // speed
782
-	    	    $data['heading'] = $line[3]; // heading
783
-	    	    $data['latitude'] = $line[1]; // lat
784
-	    	    $data['longitude'] = $line[2]; // long
785
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
786
-	    	    $data['squawk'] = $line[6]; // squawk
787
-	    	    $data['aircraft_icao'] = $line[8];
788
-	    	    $data['registration'] = $line[9];
789
-		    $data['departure_airport_iata'] = $line[11];
790
-		    $data['arrival_airport_iata'] = $line[12];
791
-	    	    $data['emergency'] = ''; // emergency
792
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
793
-	    	    $data['format_source'] = 'fr24json';
794
-    		    $data['id_source'] = $id_source;
795
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
796
-		    $SI->add($data);
797
-		    unset($data);
777
+			$data = array();
778
+			$data['hex'] = $line[0];
779
+			$data['ident'] = $line[16]; //$line[13]
780
+				$data['altitude'] = $line[4]; // altitude
781
+				$data['speed'] = $line[5]; // speed
782
+				$data['heading'] = $line[3]; // heading
783
+				$data['latitude'] = $line[1]; // lat
784
+				$data['longitude'] = $line[2]; // long
785
+				$data['verticalrate'] = $line[15]; // verticale rate
786
+				$data['squawk'] = $line[6]; // squawk
787
+				$data['aircraft_icao'] = $line[8];
788
+				$data['registration'] = $line[9];
789
+			$data['departure_airport_iata'] = $line[11];
790
+			$data['arrival_airport_iata'] = $line[12];
791
+				$data['emergency'] = ''; // emergency
792
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
793
+				$data['format_source'] = 'fr24json';
794
+				$data['id_source'] = $id_source;
795
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
796
+			$SI->add($data);
797
+			unset($data);
798
+		}
798 799
 		}
799
-	    }
800
-    	    //$last_exec['fr24json'] = time();
801
-    	    $last_exec[$id]['last'] = time();
802
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
803
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
804
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
805
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
806
-	    //echo $buffer;
807
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
808
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
809
-	    $all_data = json_decode($buffer,true);
810
-	    if (json_last_error() != JSON_ERROR_NONE) {
800
+			//$last_exec['fr24json'] = time();
801
+			$last_exec[$id]['last'] = time();
802
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
803
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
804
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
805
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
806
+		//echo $buffer;
807
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
808
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
809
+		$all_data = json_decode($buffer,true);
810
+		if (json_last_error() != JSON_ERROR_NONE) {
811 811
 		die(json_last_error_msg());
812
-	    }
813
-	    if (isset($all_data['mrkrs'])) {
812
+		}
813
+		if (isset($all_data['mrkrs'])) {
814 814
 		$reset = 0;
815 815
 		foreach ($all_data['mrkrs'] as $key => $line) {
816
-		    if (isset($line['inf'])) {
816
+			if (isset($line['inf'])) {
817 817
 			$data = array();
818 818
 			$data['hex'] = $line['inf']['ia'];
819 819
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
820
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
821
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
822
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
823
-	    		$data['latitude'] = $line['pt'][0]; // lat
824
-	    		$data['longitude'] = $line['pt'][1]; // long
825
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
826
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
827
-	    		//$data['aircraft_icao'] = $line[8];
828
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
820
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
821
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
822
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
823
+				$data['latitude'] = $line['pt'][0]; // lat
824
+				$data['longitude'] = $line['pt'][1]; // long
825
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
826
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
827
+				//$data['aircraft_icao'] = $line[8];
828
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
829 829
 			//$data['departure_airport_iata'] = $line[11];
830 830
 			//$data['arrival_airport_iata'] = $line[12];
831
-	    		//$data['emergency'] = ''; // emergency
831
+				//$data['emergency'] = ''; // emergency
832 832
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
833
-	    		$data['format_source'] = 'radarvirtueljson';
834
-    			$data['id_source'] = $id_source;
833
+				$data['format_source'] = 'radarvirtueljson';
834
+				$data['id_source'] = $id_source;
835 835
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
836 836
 			$SI->add($data);
837 837
 			unset($data);
838
-		    }
838
+			}
839
+		}
839 840
 		}
840
-	    }
841
-    	    //$last_exec['radarvirtueljson'] = time();
842
-    	    $last_exec[$id]['last'] = time();
843
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
844
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
845
-	    //$buffer = $Common->getData($hosts[$id]);
846
-	    $buffer = $Common->getData($value['host'].'?'.time());
847
-	    $all_data = json_decode(utf8_encode($buffer),true);
841
+			//$last_exec['radarvirtueljson'] = time();
842
+			$last_exec[$id]['last'] = time();
843
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
844
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
845
+		//$buffer = $Common->getData($hosts[$id]);
846
+		$buffer = $Common->getData($value['host'].'?'.time());
847
+		$all_data = json_decode(utf8_encode($buffer),true);
848 848
 	    
849
-	    if (isset($all_data['pireps'])) {
849
+		if (isset($all_data['pireps'])) {
850 850
 		$reset = 0;
851
-	        foreach ($all_data['pireps'] as $line) {
852
-		    $data = array();
853
-		    $data['id'] = $line['id'];
854
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
855
-		    $data['ident'] = $line['callsign']; // ident
856
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
857
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
858
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
859
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
860
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
861
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
862
-		    $data['latitude'] = $line['lat']; // lat
863
-		    $data['longitude'] = $line['lon']; // long
864
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
865
-		    //$data['squawk'] = $line['squawk']; // squawk
866
-		    //$data['emergency'] = ''; // emergency
867
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
868
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
869
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
870
-		    //$data['arrival_airport_time'] = $line['arrtime'];
871
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
872
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
873
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
874
-		    else $data['info'] = '';
875
-		    $data['format_source'] = 'pireps';
876
-    		    $data['id_source'] = $id_source;
877
-		    $data['datetime'] = date('Y-m-d H:i:s');
878
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
879
-		    if ($line['icon'] == 'plane') {
851
+			foreach ($all_data['pireps'] as $line) {
852
+			$data = array();
853
+			$data['id'] = $line['id'];
854
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
855
+			$data['ident'] = $line['callsign']; // ident
856
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
857
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
858
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
859
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
860
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
861
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
862
+			$data['latitude'] = $line['lat']; // lat
863
+			$data['longitude'] = $line['lon']; // long
864
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
865
+			//$data['squawk'] = $line['squawk']; // squawk
866
+			//$data['emergency'] = ''; // emergency
867
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
868
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
869
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
870
+			//$data['arrival_airport_time'] = $line['arrtime'];
871
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
872
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
873
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
874
+			else $data['info'] = '';
875
+			$data['format_source'] = 'pireps';
876
+				$data['id_source'] = $id_source;
877
+			$data['datetime'] = date('Y-m-d H:i:s');
878
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
879
+			if ($line['icon'] == 'plane') {
880 880
 			$SI->add($data);
881
-		    //    print_r($data);
882
-    		    } elseif ($line['icon'] == 'ct') {
881
+			//    print_r($data);
882
+				} elseif ($line['icon'] == 'ct') {
883 883
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
884 884
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
885 885
 			$typec = substr($data['ident'],-3);
@@ -894,192 +894,192 @@  discard block
 block discarded – undo
894 894
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
895 895
 			else $data['type'] = 'Observer';
896 896
 			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']);
897
-		    }
898
-		    unset($data);
897
+			}
898
+			unset($data);
899
+		}
899 900
 		}
900
-	    }
901
-    	    //$last_exec['pirepsjson'] = time();
902
-    	    $last_exec[$id]['last'] = time();
903
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
904
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
905
-	    //$buffer = $Common->getData($hosts[$id]);
906
-	    if ($globalDebug) echo 'Get Data...'."\n";
907
-	    $buffer = $Common->getData($value['host']);
908
-	    $all_data = json_decode($buffer,true);
909
-	    if ($buffer != '' && is_array($all_data)) {
901
+			//$last_exec['pirepsjson'] = time();
902
+			$last_exec[$id]['last'] = time();
903
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
904
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
905
+		//$buffer = $Common->getData($hosts[$id]);
906
+		if ($globalDebug) echo 'Get Data...'."\n";
907
+		$buffer = $Common->getData($value['host']);
908
+		$all_data = json_decode($buffer,true);
909
+		if ($buffer != '' && is_array($all_data)) {
910 910
 		$reset = 0;
911 911
 		foreach ($all_data as $line) {
912
-	    	    $data = array();
913
-	    	    //$data['id'] = $line['id']; // id not usable
914
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
915
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
916
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
917
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
918
-	    	    $data['ident'] = $line['flightnum']; // ident
919
-	    	    $data['altitude'] = $line['alt']; // altitude
920
-	    	    $data['speed'] = $line['gs']; // speed
921
-	    	    $data['heading'] = $line['heading']; // heading
922
-	    	    $data['latitude'] = $line['lat']; // lat
923
-	    	    $data['longitude'] = $line['lng']; // long
924
-	    	    $data['verticalrate'] = ''; // verticale rate
925
-	    	    $data['squawk'] = ''; // squawk
926
-	    	    $data['emergency'] = ''; // emergency
927
-	    	    //$data['datetime'] = $line['lastupdate'];
928
-	    	    $data['last_update'] = $line['lastupdate'];
929
-		    $data['datetime'] = date('Y-m-d H:i:s');
930
-	    	    $data['departure_airport_icao'] = $line['depicao'];
931
-	    	    $data['departure_airport_time'] = $line['deptime'];
932
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
933
-    		    $data['arrival_airport_time'] = $line['arrtime'];
934
-    		    $data['registration'] = $line['aircraft'];
935
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
936
-		    if (isset($line['aircraftname'])) {
912
+				$data = array();
913
+				//$data['id'] = $line['id']; // id not usable
914
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
915
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
916
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
917
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
918
+				$data['ident'] = $line['flightnum']; // ident
919
+				$data['altitude'] = $line['alt']; // altitude
920
+				$data['speed'] = $line['gs']; // speed
921
+				$data['heading'] = $line['heading']; // heading
922
+				$data['latitude'] = $line['lat']; // lat
923
+				$data['longitude'] = $line['lng']; // long
924
+				$data['verticalrate'] = ''; // verticale rate
925
+				$data['squawk'] = ''; // squawk
926
+				$data['emergency'] = ''; // emergency
927
+				//$data['datetime'] = $line['lastupdate'];
928
+				$data['last_update'] = $line['lastupdate'];
929
+			$data['datetime'] = date('Y-m-d H:i:s');
930
+				$data['departure_airport_icao'] = $line['depicao'];
931
+				$data['departure_airport_time'] = $line['deptime'];
932
+				$data['arrival_airport_icao'] = $line['arricao'];
933
+				$data['arrival_airport_time'] = $line['arrtime'];
934
+				$data['registration'] = $line['aircraft'];
935
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
936
+			if (isset($line['aircraftname'])) {
937 937
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
938 938
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
939
-	    		$aircraft_data = explode('-',$line['aircraftname']);
940
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
941
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
942
-	    		else {
943
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
944
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
945
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
946
-	    		}
947
-	    	    }
948
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
949
-    		    $data['id_source'] = $id_source;
950
-	    	    $data['format_source'] = 'phpvmacars';
951
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
952
-		    $SI->add($data);
953
-		    unset($data);
939
+				$aircraft_data = explode('-',$line['aircraftname']);
940
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
941
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
942
+				else {
943
+					$aircraft_data = explode(' ',$line['aircraftname']);
944
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
945
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
946
+				}
947
+				}
948
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
949
+				$data['id_source'] = $id_source;
950
+				$data['format_source'] = 'phpvmacars';
951
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
952
+			$SI->add($data);
953
+			unset($data);
954 954
 		}
955 955
 		if ($globalDebug) echo 'No more data...'."\n";
956 956
 		unset($buffer);
957 957
 		unset($all_data);
958
-	    }
959
-    	    //$last_exec['phpvmacars'] = time();
960
-    	    $last_exec[$id]['last'] = time();
961
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
962
-	    //$buffer = $Common->getData($hosts[$id]);
963
-	    if ($globalDebug) echo 'Get Data...'."\n";
964
-	    $buffer = $Common->getData($value['host']);
965
-	    $all_data = json_decode($buffer,true);
966
-	    if ($buffer != '' && is_array($all_data)) {
958
+		}
959
+			//$last_exec['phpvmacars'] = time();
960
+			$last_exec[$id]['last'] = time();
961
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
962
+		//$buffer = $Common->getData($hosts[$id]);
963
+		if ($globalDebug) echo 'Get Data...'."\n";
964
+		$buffer = $Common->getData($value['host']);
965
+		$all_data = json_decode($buffer,true);
966
+		if ($buffer != '' && is_array($all_data)) {
967 967
 		$reset = 0;
968 968
 		foreach ($all_data as $line) {
969
-	    	    $data = array();
970
-	    	    //$data['id'] = $line['id']; // id not usable
971
-	    	    $data['id'] = trim($line['flight_id']);
972
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
973
-	    	    $data['pilot_name'] = $line['pilot_name'];
974
-	    	    $data['pilot_id'] = $line['pilot_id'];
975
-	    	    $data['ident'] = trim($line['callsign']); // ident
976
-	    	    $data['altitude'] = $line['altitude']; // altitude
977
-	    	    $data['speed'] = $line['gs']; // speed
978
-	    	    $data['heading'] = $line['heading']; // heading
979
-	    	    $data['latitude'] = $line['latitude']; // lat
980
-	    	    $data['longitude'] = $line['longitude']; // long
981
-	    	    $data['verticalrate'] = ''; // verticale rate
982
-	    	    $data['squawk'] = ''; // squawk
983
-	    	    $data['emergency'] = ''; // emergency
984
-	    	    //$data['datetime'] = $line['lastupdate'];
985
-	    	    $data['last_update'] = $line['last_update'];
986
-		    $data['datetime'] = date('Y-m-d H:i:s');
987
-	    	    $data['departure_airport_icao'] = $line['departure'];
988
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
989
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
990
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
991
-    		    //$data['registration'] = $line['aircraft'];
992
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
993
-	    	    $data['aircraft_icao'] = $line['plane_type'];
994
-    		    $data['id_source'] = $id_source;
995
-	    	    $data['format_source'] = 'vam';
996
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
997
-		    $SI->add($data);
998
-		    unset($data);
969
+				$data = array();
970
+				//$data['id'] = $line['id']; // id not usable
971
+				$data['id'] = trim($line['flight_id']);
972
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
973
+				$data['pilot_name'] = $line['pilot_name'];
974
+				$data['pilot_id'] = $line['pilot_id'];
975
+				$data['ident'] = trim($line['callsign']); // ident
976
+				$data['altitude'] = $line['altitude']; // altitude
977
+				$data['speed'] = $line['gs']; // speed
978
+				$data['heading'] = $line['heading']; // heading
979
+				$data['latitude'] = $line['latitude']; // lat
980
+				$data['longitude'] = $line['longitude']; // long
981
+				$data['verticalrate'] = ''; // verticale rate
982
+				$data['squawk'] = ''; // squawk
983
+				$data['emergency'] = ''; // emergency
984
+				//$data['datetime'] = $line['lastupdate'];
985
+				$data['last_update'] = $line['last_update'];
986
+			$data['datetime'] = date('Y-m-d H:i:s');
987
+				$data['departure_airport_icao'] = $line['departure'];
988
+				//$data['departure_airport_time'] = $line['departure_time'];
989
+				$data['arrival_airport_icao'] = $line['arrival'];
990
+				//$data['arrival_airport_time'] = $line['arrival_time'];
991
+				//$data['registration'] = $line['aircraft'];
992
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
993
+				$data['aircraft_icao'] = $line['plane_type'];
994
+				$data['id_source'] = $id_source;
995
+				$data['format_source'] = 'vam';
996
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
997
+			$SI->add($data);
998
+			unset($data);
999 999
 		}
1000 1000
 		if ($globalDebug) echo 'No more data...'."\n";
1001 1001
 		unset($buffer);
1002 1002
 		unset($all_data);
1003
-	    }
1004
-    	    //$last_exec['phpvmacars'] = time();
1005
-    	    $last_exec[$id]['last'] = time();
1003
+		}
1004
+			//$last_exec['phpvmacars'] = time();
1005
+			$last_exec[$id]['last'] = time();
1006 1006
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1007 1007
 	} 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' || $value['format'] == 'vrstcp') {
1008
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1009
-    	    //$last_exec[$id]['last'] = time();
1008
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1009
+			//$last_exec[$id]['last'] = time();
1010 1010
 
1011
-	    //$read = array( $sockets[$id] );
1012
-	    $read = $sockets;
1013
-	    $write = NULL;
1014
-	    $e = NULL;
1015
-	    $n = socket_select($read, $write, $e, $timeout);
1016
-	    if ($e != NULL) var_dump($e);
1017
-	    if ($n > 0) {
1011
+		//$read = array( $sockets[$id] );
1012
+		$read = $sockets;
1013
+		$write = NULL;
1014
+		$e = NULL;
1015
+		$n = socket_select($read, $write, $e, $timeout);
1016
+		if ($e != NULL) var_dump($e);
1017
+		if ($n > 0) {
1018 1018
 		$reset = 0;
1019 1019
 		foreach ($read as $nb => $r) {
1020
-		    //$value = $formats[$nb];
1021
-		    $format = $globalSources[$nb]['format'];
1022
-		    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1020
+			//$value = $formats[$nb];
1021
+			$format = $globalSources[$nb]['format'];
1022
+			if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1023 1023
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1024
-		    } elseif ($format == 'vrstcp') {
1024
+			} elseif ($format == 'vrstcp') {
1025 1025
 			$buffer = @socket_read($r, 6000);
1026
-		    } else {
1026
+			} else {
1027 1027
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1028
-		    }
1029
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1030
-		    //echo $buffer."\n";
1031
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1032
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1033
-		    $error = false;
1034
-		    //$SI::del();
1035
-		    if ($format == 'vrstcp') {
1028
+			}
1029
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1030
+			//echo $buffer."\n";
1031
+			// lets play nice and handle signals such as ctrl-c/kill properly
1032
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1033
+			$error = false;
1034
+			//$SI::del();
1035
+			if ($format == 'vrstcp') {
1036 1036
 			$buffer = explode('},{',$buffer);
1037
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1038
-		    // SBS format is CSV format
1039
-		    if ($buffer !== FALSE && $buffer != '') {
1037
+			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1038
+			// SBS format is CSV format
1039
+			if ($buffer !== FALSE && $buffer != '') {
1040 1040
 			$tt[$format] = 0;
1041 1041
 			if ($format == 'acarssbs3') {
1042
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1043
-			    $ACARS->add(trim($buffer));
1044
-			    $ACARS->deleteLiveAcarsData();
1042
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1043
+				$ACARS->add(trim($buffer));
1044
+				$ACARS->deleteLiveAcarsData();
1045 1045
 			} elseif ($format == 'raw') {
1046
-			    // AVR format
1047
-			    $data = $SBS->parse($buffer);
1048
-			    if (is_array($data)) {
1046
+				// AVR format
1047
+				$data = $SBS->parse($buffer);
1048
+				if (is_array($data)) {
1049 1049
 				$data['datetime'] = date('Y-m-d H:i:s');
1050 1050
 				$data['format_source'] = 'raw';
1051 1051
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1052 1052
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1053 1053
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1054
-			    }
1054
+				}
1055 1055
 			} elseif ($format == 'ais') {
1056
-			    $ais_data = $AIS->parse_line(trim($buffer));
1057
-			    $data = array();
1058
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1059
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1060
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1061
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1062
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1063
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1064
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1065
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1066
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1067
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1068
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1069
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1056
+				$ais_data = $AIS->parse_line(trim($buffer));
1057
+				$data = array();
1058
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1059
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1060
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1061
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1062
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1063
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1064
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1065
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1066
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1067
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1068
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1069
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1070 1070
 
1071
-			    if (isset($ais_data['timestamp'])) {
1071
+				if (isset($ais_data['timestamp'])) {
1072 1072
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1073
-			    } else {
1073
+				} else {
1074 1074
 				$data['datetime'] = date('Y-m-d H:i:s');
1075
-			    }
1076
-			    $data['format_source'] = 'aisnmea';
1077
-    			    $data['id_source'] = $id_source;
1078
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1079
-			    unset($data);
1080
-                        } elseif ($format == 'flightgearsp') {
1081
-                    	    //echo $buffer."\n";
1082
-                    	    if (strlen($buffer) > 5) {
1075
+				}
1076
+				$data['format_source'] = 'aisnmea';
1077
+					$data['id_source'] = $id_source;
1078
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1079
+				unset($data);
1080
+						} elseif ($format == 'flightgearsp') {
1081
+							//echo $buffer."\n";
1082
+							if (strlen($buffer) > 5) {
1083 1083
 				$line = explode(',',$buffer);
1084 1084
 				$data = array();
1085 1085
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1095,37 +1095,37 @@  discard block
 block discarded – undo
1095 1095
 				$data['format_source'] = 'flightgearsp';
1096 1096
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1097 1097
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1098
-			    }
1099
-                        } elseif ($format == 'acars') {
1100
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1101
-			    $ACARS->add(trim($buffer));
1102
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1103
-			    $ACARS->deleteLiveAcarsData();
1098
+				}
1099
+						} elseif ($format == 'acars') {
1100
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1101
+				$ACARS->add(trim($buffer));
1102
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1103
+				$ACARS->deleteLiveAcarsData();
1104 1104
 			} elseif ($format == 'flightgearmp') {
1105
-			    if (substr($buffer,0,1) != '#') {
1105
+				if (substr($buffer,0,1) != '#') {
1106 1106
 				$data = array();
1107 1107
 				//echo $buffer."\n";
1108 1108
 				$line = explode(' ',$buffer);
1109 1109
 				if (count($line) == 11) {
1110
-				    $userserver = explode('@',$line[0]);
1111
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1112
-				    $data['ident'] = $userserver[0];
1113
-				    $data['registration'] = $userserver[0];
1114
-				    $data['latitude'] = $line[4];
1115
-				    $data['longitude'] = $line[5];
1116
-				    $data['altitude'] = $line[6];
1117
-				    $data['datetime'] = date('Y-m-d H:i:s');
1118
-				    $aircraft_type = $line[10];
1119
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1120
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1121
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1110
+					$userserver = explode('@',$line[0]);
1111
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1112
+					$data['ident'] = $userserver[0];
1113
+					$data['registration'] = $userserver[0];
1114
+					$data['latitude'] = $line[4];
1115
+					$data['longitude'] = $line[5];
1116
+					$data['altitude'] = $line[6];
1117
+					$data['datetime'] = date('Y-m-d H:i:s');
1118
+					$aircraft_type = $line[10];
1119
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1120
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1121
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1122
+				}
1122 1123
 				}
1123
-			    }
1124 1124
 			} elseif ($format == 'beast') {
1125
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1126
-			    die;
1125
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1126
+				die;
1127 1127
 			} elseif ($format == 'vrstcp') {
1128
-			    foreach($buffer as $all_data) {
1128
+				foreach($buffer as $all_data) {
1129 1129
 				$line = json_decode('{'.$all_data.'}',true);
1130 1130
 				$data = array();
1131 1131
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1145,100 +1145,100 @@  discard block
 block discarded – undo
1145 1145
 				*/
1146 1146
 				$data['datetime'] = date('Y-m-d H:i:s');
1147 1147
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1148
-		    		$data['format_source'] = 'vrstcp';
1148
+					$data['format_source'] = 'vrstcp';
1149 1149
 				$data['id_source'] = $id_source;
1150 1150
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1151 1151
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1152 1152
 				unset($data);
1153
-			    }
1153
+				}
1154 1154
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1155
-			    $line = explode("\t", $buffer);
1156
-			    for($k = 0; $k < count($line); $k=$k+2) {
1155
+				$line = explode("\t", $buffer);
1156
+				for($k = 0; $k < count($line); $k=$k+2) {
1157 1157
 				$key = $line[$k];
1158
-			        $lined[$key] = $line[$k+1];
1159
-			    }
1160
-    			    if (count($lined) > 3) {
1161
-    				$data['hex'] = $lined['hexid'];
1162
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1163
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1164
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1165
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1166
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1167
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1168
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1169
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1170
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1171
-    				$data['id_source'] = $id_source;
1172
-    				$data['format_source'] = 'tsv';
1173
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1174
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1175
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1176
-    				unset($lined);
1177
-    				unset($data);
1178
-    			    } else $error = true;
1158
+					$lined[$key] = $line[$k+1];
1159
+				}
1160
+					if (count($lined) > 3) {
1161
+					$data['hex'] = $lined['hexid'];
1162
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1163
+					$data['datetime'] = date('Y-m-d H:i:s');;
1164
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1165
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1166
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1167
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1168
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1169
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1170
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1171
+					$data['id_source'] = $id_source;
1172
+					$data['format_source'] = 'tsv';
1173
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1174
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1175
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1176
+					unset($lined);
1177
+					unset($data);
1178
+					} else $error = true;
1179 1179
 			} elseif ($format == 'aprs' && $use_aprs) {
1180
-			    if ($aprs_connect == 0) {
1180
+				if ($aprs_connect == 0) {
1181 1181
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1182 1182
 				$aprs_connect = 1;
1183
-			    }
1183
+				}
1184 1184
 			    
1185
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1185
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1186 1186
 				$aprs_last_tx = time();
1187 1187
 				$data_aprs = "# Keep alive";
1188 1188
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1189
-			    }
1189
+				}
1190 1190
 			    
1191
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1192
-			    //echo 'APRS data : '.$buffer."\n";
1193
-			    $buffer = str_replace('APRS <- ','',$buffer);
1194
-			    $buffer = str_replace('APRS -> ','',$buffer);
1195
-			    //echo $buffer."\n";
1196
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1191
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1192
+				//echo 'APRS data : '.$buffer."\n";
1193
+				$buffer = str_replace('APRS <- ','',$buffer);
1194
+				$buffer = str_replace('APRS -> ','',$buffer);
1195
+				//echo $buffer."\n";
1196
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1197 1197
 				$line = $APRS->parse($buffer);
1198 1198
 				//print_r($line);
1199 1199
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1200 1200
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']))) {
1201
-				    $aprs_last_tx = time();
1202
-				    $data = array();
1203
-				    //print_r($line);
1204
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1205
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1206
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1207
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1208
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1209
-				    $data['latitude'] = $line['latitude'];
1210
-				    $data['longitude'] = $line['longitude'];
1211
-				    //$data['verticalrate'] = $line[16];
1212
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1213
-				    else $data['speed'] = 0;
1214
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1215
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1216
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1217
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1218
-				    //else $data['heading'] = 0;
1219
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1220
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1221
-    				    $data['id_source'] = $id_source;
1222
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1223
-				    else $data['format_source'] = 'aprs';
1224
-				    $data['source_name'] = $line['source'];
1225
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1226
-				    else $data['source_type'] = 'flarm';
1227
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1228
-				    $currentdate = date('Y-m-d H:i:s');
1229
-				    $aprsdate = strtotime($data['datetime']);
1230
-				    // Accept data if time <= system time + 20s
1231
-				    if (($data['source_type'] == 'modes') || 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'])))) {
1201
+					$aprs_last_tx = time();
1202
+					$data = array();
1203
+					//print_r($line);
1204
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1205
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1206
+					else $data['datetime'] = date('Y-m-d H:i:s');
1207
+					//$data['datetime'] = date('Y-m-d H:i:s');
1208
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1209
+					$data['latitude'] = $line['latitude'];
1210
+					$data['longitude'] = $line['longitude'];
1211
+					//$data['verticalrate'] = $line[16];
1212
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1213
+					else $data['speed'] = 0;
1214
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1215
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1216
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1217
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1218
+					//else $data['heading'] = 0;
1219
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1220
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1221
+						$data['id_source'] = $id_source;
1222
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1223
+					else $data['format_source'] = 'aprs';
1224
+					$data['source_name'] = $line['source'];
1225
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1226
+					else $data['source_type'] = 'flarm';
1227
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1228
+					$currentdate = date('Y-m-d H:i:s');
1229
+					$aprsdate = strtotime($data['datetime']);
1230
+					// Accept data if time <= system time + 20s
1231
+					if (($data['source_type'] == 'modes') || 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'])))) {
1232 1232
 					$send = $SI->add($data);
1233
-				    } elseif (isset($line['stealth'])) {
1233
+					} elseif (isset($line['stealth'])) {
1234 1234
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1235 1235
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1236
-				    //} 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')) {
1237
-				    } 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') {
1236
+					//} 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')) {
1237
+					} 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') {
1238 1238
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1239 1239
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1240
-				    }
1241
-				    unset($data);
1240
+					}
1241
+					unset($data);
1242 1242
 				} 
1243 1243
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1244 1244
 					echo '!! Weather Station not yet supported'."\n";
@@ -1248,12 +1248,12 @@  discard block
 block discarded – undo
1248 1248
 				}
1249 1249
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1250 1250
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1251
-			    }
1251
+				}
1252 1252
 			} else {
1253
-			    $line = explode(',', $buffer);
1254
-    			    if (count($line) > 20) {
1255
-    			    	$data['hex'] = $line[4];
1256
-    				/*
1253
+				$line = explode(',', $buffer);
1254
+					if (count($line) > 20) {
1255
+						$data['hex'] = $line[4];
1256
+					/*
1257 1257
     				$data['datetime'] = $line[6].' '.$line[7];
1258 1258
     					date_default_timezone_set($globalTimezone);
1259 1259
     					$datetime = new DateTime($data['datetime']);
@@ -1261,29 +1261,29 @@  discard block
 block discarded – undo
1261 1261
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1262 1262
     					date_default_timezone_set('UTC');
1263 1263
     				*/
1264
-    				// Force datetime to current UTC datetime
1265
-    				date_default_timezone_set('UTC');
1266
-    				$data['datetime'] = date('Y-m-d H:i:s');
1267
-    				$data['ident'] = trim($line[10]);
1268
-    				$data['latitude'] = $line[14];
1269
-    				$data['longitude'] = $line[15];
1270
-    				$data['verticalrate'] = $line[16];
1271
-    				$data['emergency'] = $line[20];
1272
-    				$data['speed'] = $line[12];
1273
-    				$data['squawk'] = $line[17];
1274
-    				$data['altitude'] = $line[11];
1275
-    				$data['heading'] = $line[13];
1276
-    				$data['ground'] = $line[21];
1277
-    				$data['emergency'] = $line[19];
1278
-    				$data['format_source'] = 'sbs';
1264
+					// Force datetime to current UTC datetime
1265
+					date_default_timezone_set('UTC');
1266
+					$data['datetime'] = date('Y-m-d H:i:s');
1267
+					$data['ident'] = trim($line[10]);
1268
+					$data['latitude'] = $line[14];
1269
+					$data['longitude'] = $line[15];
1270
+					$data['verticalrate'] = $line[16];
1271
+					$data['emergency'] = $line[20];
1272
+					$data['speed'] = $line[12];
1273
+					$data['squawk'] = $line[17];
1274
+					$data['altitude'] = $line[11];
1275
+					$data['heading'] = $line[13];
1276
+					$data['ground'] = $line[21];
1277
+					$data['emergency'] = $line[19];
1278
+					$data['format_source'] = 'sbs';
1279 1279
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1280
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1281
-    				$data['id_source'] = $id_source;
1282
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1283
-    				else $error = true;
1284
-    				unset($data);
1285
-    			    } else $error = true;
1286
-			    if ($error) {
1280
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1281
+					$data['id_source'] = $id_source;
1282
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1283
+					else $error = true;
1284
+					unset($data);
1285
+					} else $error = true;
1286
+				if ($error) {
1287 1287
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1288 1288
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1289 1289
 				} else {
@@ -1299,13 +1299,13 @@  discard block
 block discarded – undo
1299 1299
 					connect_all($sourceer);
1300 1300
 					$sourceer = array();
1301 1301
 				}
1302
-			    }
1302
+				}
1303 1303
 			}
1304 1304
 			// Sleep for xxx microseconds
1305 1305
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1306
-		    } else {
1306
+			} else {
1307 1307
 			if ($format == 'flightgearmp') {
1308
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1308
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1309 1309
 				//@socket_close($r);
1310 1310
 				sleep($globalMinFetch);
1311 1311
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1314,9 +1314,9 @@  discard block
 block discarded – undo
1314 1314
 				break;
1315 1315
 				
1316 1316
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1317
-			    if (isset($tt[$format])) $tt[$format]++;
1318
-			    else $tt[$format] = 0;
1319
-			    if ($tt[$format] > 30) {
1317
+				if (isset($tt[$format])) $tt[$format]++;
1318
+				else $tt[$format] = 0;
1319
+				if ($tt[$format] > 30) {
1320 1320
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1321 1321
 				//@socket_close($r);
1322 1322
 				sleep(2);
@@ -1327,23 +1327,23 @@  discard block
 block discarded – undo
1327 1327
 				//connect_all($globalSources);
1328 1328
 				$tt[$format]=0;
1329 1329
 				break;
1330
-			    }
1330
+				}
1331
+			}
1331 1332
 			}
1332
-		    }
1333 1333
 		}
1334
-	    } else {
1334
+		} else {
1335 1335
 		$error = socket_strerror(socket_last_error());
1336 1336
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1337 1337
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1338 1338
 			if (isset($globalDebug)) echo "Restarting...\n";
1339 1339
 			// Restart the script if possible
1340 1340
 			if (is_array($sockets)) {
1341
-			    if ($globalDebug) echo "Shutdown all sockets...";
1341
+				if ($globalDebug) echo "Shutdown all sockets...";
1342 1342
 			    
1343
-			    foreach ($sockets as $sock) {
1343
+				foreach ($sockets as $sock) {
1344 1344
 				@socket_shutdown($sock,2);
1345 1345
 				@socket_close($sock);
1346
-			    }
1346
+				}
1347 1347
 			    
1348 1348
 			}
1349 1349
 			if ($globalDebug) echo "Restart all connections...";
@@ -1357,13 +1357,13 @@  discard block
 block discarded – undo
1357 1357
 			if ($reset > 100) exit('Too many attempts...');
1358 1358
 			connect_all($globalSources);
1359 1359
 		}
1360
-	    }
1360
+		}
1361 1361
 	}
1362 1362
 	if ($globalDaemon === false) {
1363
-	    if ($globalDebug) echo 'Check all...'."\n";
1364
-	    $SI->checkAll();
1363
+		if ($globalDebug) echo 'Check all...'."\n";
1364
+		$SI->checkAll();
1365
+	}
1365 1366
 	}
1366
-    }
1367 1367
 }
1368 1368
 
1369 1369
 ?>
Please login to merge, or discard this patch.