Skip to content

Commit

Permalink
Use latest Sailaway API
Browse files Browse the repository at this point in the history
  • Loading branch information
Ysurac committed Mar 9, 2018
1 parent 6980ff7 commit 8cab2f8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 11 deletions.
13 changes: 11 additions & 2 deletions install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,16 @@
<p>
<label for="sailawayemail">Sailaway email</label>
<input type="text" name="sailawayemail" id="sailawayemail" value="<?php if (isset($globalSailaway['email'])) print $globalSailaway['email']; ?>" />
<p class="help-block">Only needed for Sailaway full format</p>
</p>
<p>
<label for="sailawaypassword">Sailaway password</label>
<input type="text" name="sailawaypassword" id="sailawaypassword" value="<?php if (isset($globalSailaway['password'])) print $globalSailaway['password']; ?>" />
<p class="help-block">Only needed for Sailaway full format</p>
</p>
<p>
<label for="sailawaykey">Sailaway API key</label>
<input type="text" name="sailawaykey" id="sailawaykey" value="<?php if (isset($globalSailaway['key'])) print $globalSailaway['key']; ?>" />
</p>
</div>

Expand Down Expand Up @@ -626,6 +632,7 @@
<option value="hidnseek_callback" <?php if (isset($source['format']) && $source['format'] == 'hidnseek_callback') print 'selected'; ?>>HidnSeek Callback</option>
<option value="blitzortung" <?php if (isset($source['format']) && $source['format'] == 'blitzortung') print 'selected'; ?>>Blitzortung</option>
<option value="sailaway" <?php if (isset($source['format']) && $source['format'] == 'sailaway') print 'selected'; ?>>Sailaway</option>
<option value="sailawayfull" <?php if (isset($source['format']) && $source['format'] == 'sailawayfull') print 'selected'; ?>>Sailaway with missions, races,...</option>
</select>
</td>
<td>
Expand Down Expand Up @@ -666,7 +673,7 @@
<option value="planefinderclient">Planefinder client</option>
<option value="aprs">APRS</option>
<option value="deltadbtxt">Radarcape deltadb.txt</option>
<option value="radarcapejson">Radarcape json</option>
<option value="radarcapejson">Radarcape json</option>
<option value="vatsimtxt">Vatsim</option>
<option value="aircraftlistjson">Virtual Radar Server AircraftList.json</option>
<option value="vrstcp">Virtual Radar Server TCP</option>
Expand All @@ -685,6 +692,7 @@
<option value="hidnseek_callback">HidnSeek Callback</option>
<option value="blitzortung">Blitzortung</option>
<option value="sailaway">Sailaway</option>
<option value="sailawayfull">Sailaway with missions, races,...</option>
</select>
</td>
<td>
Expand Down Expand Up @@ -1341,7 +1349,8 @@

$sailawayemail = filter_input(INPUT_POST,'sailawayemail',FILTER_SANITIZE_STRING);
$sailawaypass = filter_input(INPUT_POST,'sailawaypassword',FILTER_SANITIZE_STRING);
$settings = array_merge($settings,array('globalSailaway' => array('email' => $sailawayemail,'password' => $sailawaypass)));
$sailawaykey = filter_input(INPUT_POST,'sailawaykey',FILTER_SANITIZE_STRING);
$settings = array_merge($settings,array('globalSailaway' => array('email' => $sailawayemail,'password' => $sailawaypass,'key' => $sailawaykey)));

$source_name = $_POST['source_name'];
$source_latitude = $_POST['source_latitude'];
Expand Down
12 changes: 6 additions & 6 deletions require/class.MarineImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function add($line) {

// SBS format is CSV format
if(is_array($line) && (isset($line['mmsi']) || isset($line['id']))) {
//print_r($line);
print_r($line);
if (isset($line['mmsi']) || isset($line['id'])) {


Expand Down Expand Up @@ -330,7 +330,7 @@ public function add($line) {
$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
$speed = $speed*3.6;
if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['id']." : ".$speed." - distance : ".$distance."\n";
}
}

Expand Down Expand Up @@ -460,7 +460,7 @@ public function add($line) {
if($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
{
if ($globalDebug) {
if ($this->all_tracked[$id]['mmsi'] == '') echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
if ($this->all_tracked[$id]['mmsi'] != '') echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
else echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
}
//adds the spotter data for the archive
Expand All @@ -470,7 +470,7 @@ public function add($line) {
if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
$timeelapsed = microtime(true);
$Marine = new Marine($this->db);
if (isset($globalVM) && $globalVM && $this->all_tracked[$id]['race_begin'] != '') {
if (isset($globalVM) && $globalVM && ($this->all_tracked[$id]['race_begin'] != '' || $this->all_tracked[$id]['format_source'] == 'sailaway')) {
$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['race_begin'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
} else {
$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
Expand Down Expand Up @@ -512,7 +512,7 @@ public function add($line) {
$this->all_tracked[$id]['addedMarine'] = 1;
//print_r($this->all_tracked[$id]);
if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
if ($globalDebug) echo "---- Deleting Live Marine data older than 12 hours...";
//MarineLive->deleteLiveMarineDataNotUpdated();
if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
$MarineLive = new MarineLive($this->db);
Expand Down Expand Up @@ -554,7 +554,7 @@ public function add($line) {
echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
}
$ignoreImport = false;
if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true;
if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] == 'sailawayfull' && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true;
if (!$ignoreImport) {
if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
Expand Down
2 changes: 2 additions & 0 deletions require/class.MarineLive.php
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,9 @@ public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '
$race_id = filter_var($race_id,FILTER_SANITIZE_STRING);
$race_name = filter_var($race_name,FILTER_SANITIZE_STRING);
$race_rank = filter_var($race_rank,FILTER_SANITIZE_NUMBER_INT);
if ($race_rank == '') $race_rank = NULL;
$race_time = filter_var($race_time,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
if ($race_time == '') $race_time = NULL;
if ($typeid == '') $typeid = NULL;
if ($statusid == '') $statusid = NULL;
if ($distance == '') $distance = NULL;
Expand Down
53 changes: 50 additions & 3 deletions scripts/daemon-spotter.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,15 @@ function connect_all($hosts) {
$globalSources[$id]['format'] = 'tsv';
if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
}
} elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
} elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
$idf = fopen($globalSources[$id]['host'],'r',false,$context);
if ($idf !== false) {
$httpfeeds[$id] = $idf;
if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
} elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
$hostport = explode(':',$host);
Expand Down Expand Up @@ -785,7 +786,7 @@ function connect_all($hosts) {
}
}
$last_exec[$id]['last'] = time();
} elseif ($value['format'] === 'sailaway' &&
} elseif ($value['format'] === 'sailawayfull' &&
(
(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > 5*60))
)
Expand Down Expand Up @@ -886,7 +887,7 @@ function connect_all($hosts) {
$data['race_name'] = $mission_name;
}
//$data['callsign'] = trim(substr($line,100,7);
$data['format_source'] = 'sailaway';
$data['format_source'] = 'sailawayfull';
$data['id_source'] = $id_source;
if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
//print_r($data);
Expand All @@ -906,6 +907,52 @@ function connect_all($hosts) {
sleep(5);
}
$last_exec[$id]['last'] = time();
} elseif ($value['format'] === 'sailaway' &&
(
(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > 5*60))
)
) {
/*
if (isset($globalSailaway['email']) && $globalSailaway['email'] != '' && isset($globalSailaway['password']) && $globalSailaway['password'] != '') {
$authsailaway = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/weblogin.pl','post',array('submitlogin' => 'Login','email' => $globalSailaway['email'],'pwd' => $globalSailaway['password'], 'page' => 'http://sailaway.world/cgi-bin/sailaway/missions.pl'),'','','','','',false,false,true);
//echo $authsailaway;
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $authsailaway, $setcookie);
if (isset($setcookie[1][0])) {
$sailaway_authcookie = $setcookie[1][0];
echo $sailaway_authcookie."\n";
}
}
*/
if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
echo 'Sailaway API key MUST be defined';
exit(0);
}
if ($globalDebug) echo '! Download... ';
$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?key='.$globalSailaway['key']);
if ($buffer != '') {
$data = json_decode($buffer,true);
//print_r($race_data);
if (isset($data['boats'])) {
foreach ($data['boats'] as $sail) {
$data = array();
$data['id'] = $sail['ubtnr'];
$data['datetime'] = date('Y-m-d H:i:s');
$data['last_update'] = date('Y-m-d H:i:s');
$data['latitude'] = $sail['ubtlat'];
$data['longitude'] = $sail['ubtlon'];
$data['type_id'] = 36;
$data['heading'] = $sail['ubtheading'];
$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($sail['ubtname'])));
$data['captain_name'] = $sail['usrname'];
$data['format_source'] = 'sailaway';
$data['id_source'] = $id_source;
if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
$MI->add($data);
unset($data);
}
}
}
$last_exec[$id]['last'] = time();
//} elseif (($value === 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value === 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
} elseif (
(
Expand Down

0 comments on commit 8cab2f8

Please sign in to comment.