Skip to content

Commit

Permalink
Allows name to be displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
Cale-Torino committed Jan 19, 2022
1 parent 7a42dad commit 4407ec5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 52 deletions.
88 changes: 38 additions & 50 deletions takcar_scripts/serverUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,30 @@
//get the Traccar positions
$positions = get_TraccarPosition("$TraccarProtocol://$TraccarIP:$TraccarPort/api/positions?token=$TraccarAPIToken", $JSESSIONID);

$json = json_decode($positions);
//get the Traccar devices
$devices = get_TraccarDevice("$TraccarProtocol://$TraccarIP:$TraccarPort/api/devices?token=$TraccarAPIToken", $JSESSIONID);

$jpositions = json_decode($positions);

$jdevices = json_decode($devices);

//loop through the positions
$devices = array();
foreach($json as $key => $item){

//forward the positions to the FTS API endpoint
//$result = get_FTSAPI($item->id, $item->latitude, $item->longitude, $FTSProtocol, $FTSIP, $FTSAPIPort, $FTSAPIToken);
if (in_array($item->id, $devices)) {
//forward the positions to the FTS TCP port
$result = get_FTSSOCKETPING($item->id, $item->latitude, $item->longitude, $FTSIP, $FTSPort);
}else {
//forward the positions to the FTS TCP port
$result = get_FTSSOCKET($item->id, $item->latitude, $item->longitude, $FTSIP, $FTSPort);
$devices[] = $item->id;
foreach($jpositions as $pkey => $pitem){
foreach($jdevices as $dkey => $ditem){
if ($pitem->id == $ditem->id) {

//forward the positions to the FTS API endpoint
if (in_array($pitem->id, $devices)) {
//forward the positions to the FTS TCP port
$result = get_FTSSOCKETPING($pitem->id, $ditem->name, $pitem->latitude, $pitem->longitude, $FTSIP, $FTSPort);
}else {
//forward the positions to the FTS TCP port
$result = get_FTSSOCKET($pitem->id, $ditem->name, $pitem->latitude, $pitem->longitude, $FTSIP, $FTSPort);
$devices[] = $pitem->id;
}
}

}

$markers[] = json_encode(
Expand Down Expand Up @@ -79,47 +88,26 @@ function get_TraccarPosition($url,$JSESSIONID) {
return $file;
}

function get_FTSAPI($id, $latitude, $longitude, $FTSProtocol, $FTSIP, $FTSAPIPort, $FTSAPIToken) {

//generate GUID
$guid = vsprintf('%s%s-%s-4000-8%.3s-%s%s%s0',str_split(dechex( microtime(true) * 1000 ) . bin2hex( random_bytes(8) ),4));

//Json data to post
$postData = array(
"uid" => $guid,
"how" => "nonCoT",
"name" => "ID_".$id,
"longitude" => $longitude,
"latitude" => $latitude,
"role" => "Team Member",
"team" => "Red"
);

$ch = curl_init("$FTSProtocol://$FTSIP:$FTSAPIPort/ManagePresence/postPresence");
//set cURL options
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
'Content-Type: application/json',
'Authorization: '.$FTSAPIToken
function get_TraccarDevice($url,$JSESSIONID) {
//set the headers and cookie
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: JSESSIONID=$JSESSIONID\r\n"
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
//execute cURL call
$result = curl_exec($ch);
curl_close($ch);

return $result;
}
);

// Open the file using the HTTP headers set above
$file = file_get_contents($url, false, stream_context_create($opts));
return $file;
}

//https://www.latlong.net/
function get_FTSSOCKET($id, $latitude, $longitude, $FTSIP, $FTSPort) {
function get_FTSSOCKET($id, $name, $latitude, $longitude, $FTSIP, $FTSPort) {
//generate GUID
//$guid = vsprintf('%s%s40-%s%s3-%s%s43-%s1',str_split(dechex( microtime(true) * 1000 ) . bin2hex( random_bytes(8) ),4));
$data = '<?xml version="1.0" encoding="utf-8" standalone="yes"?><event version="2.0" uid="S-1-5-21-1568504889-667903775-1938598950-'.$id.'" type="a-f-G-U-C-I" time="'.date("Y-m-d\TH:i:s.000\Z",time()).'" start="'.date("Y-m-d\TH:i:s.000\Z",time()).'" stale="'.date("Y-m-d\TH:i:s.000\Z", strtotime('+1 minutes', time())).'" how="h-g-i-g-o"><point lat="'.$latitude.'" lon="'.$longitude.'" hae="0" ce="9999999" le="9999999"/><detail><takv version="4.1.0.231" platform="WinTAK-CIV" os="Microsoft Windows 10 Pro" device="System manufacturer System Product Name"/><contact callsign="callsign_'.$id.'" endpoint="*:-1:stcp"/><uid Droid="Droid_'.$id.'"/><__group name="Red" role="Team Member"/><status battery="100"/><track course="0.00000000" speed="0.00000000"/></detail></event>';
$data = '<?xml version="1.0" encoding="utf-8" standalone="yes"?><event version="2.0" uid="S-1-5-21-1568504889-667903775-1938598950-'.$id.'_'.$name.'" type="a-f-G-U-C-I" time="'.date("Y-m-d\TH:i:s.000\Z",time()).'" start="'.date("Y-m-d\TH:i:s.000\Z",time()).'" stale="'.date("Y-m-d\TH:i:s.000\Z", strtotime('+1 minutes', time())).'" how="h-g-i-g-o"><point lat="'.$latitude.'" lon="'.$longitude.'" hae="0" ce="9999999" le="9999999"/><detail><takv version="4.1.0.231" platform="WinTAK-CIV" os="Microsoft Windows 10 Pro" device="System manufacturer System Product Name"/><contact callsign="callsign_'.$name.'" endpoint="*:-1:stcp"/><uid Droid="Droid_'.$name.'"/><__group name="Red" role="Team Member"/><status battery="100"/><track course="0.00000000" speed="0.00000000"/></detail></event>';
$SocketConnection = fsockopen($FTSIP, $FTSPort, $errno, $errstr);
if (!$SocketConnection) {
return "Failed_no_Socket_Connection";
Expand All @@ -138,11 +126,11 @@ function get_FTSSOCKET($id, $latitude, $longitude, $FTSIP, $FTSPort) {
return "Done";
}

function get_FTSSOCKETPING($id, $latitude, $longitude, $FTSIP, $FTSPort) {
function get_FTSSOCKETPING($id, $name, $latitude, $longitude, $FTSIP, $FTSPort) {
//generate GUID
//S-1-5-21-1568504889-667903775-1938598950-1001-ping
//$guid = vsprintf('%s%s40-%s%s3-%s%s43-%s1',str_split(dechex( microtime(true) * 1000 ) . bin2hex( random_bytes(8) ),4));
$data = '<?xml version="1.0"?><event version="2.0" uid="S-1-5-21-1568504889-667903775-1938598950-'.$id.'-ping" type="t-x-c-t" time="'.date("Y-m-d\TH:i:s.000\Z",time()).'" start="'.date("Y-m-d\TH:i:s.000\Z",time()).'" stale="'.date("Y-m-d\TH:i:s.000\Z", strtotime('+1 minutes', time())).'" how="m-g"><point lat="'.$latitude.'" lon="'.$longitude.'" hae="0.00000000" ce="9999999" le="9999999"/><detail/></event>';
$data = '<?xml version="1.0"?><event version="2.0" uid="S-1-5-21-1568504889-667903775-1938598950-'.$id.'_'.$name.'-ping" type="t-x-c-t" time="'.date("Y-m-d\TH:i:s.000\Z",time()).'" start="'.date("Y-m-d\TH:i:s.000\Z",time()).'" stale="'.date("Y-m-d\TH:i:s.000\Z", strtotime('+1 minutes', time())).'" how="m-g"><point lat="'.$latitude.'" lon="'.$longitude.'" hae="0.00000000" ce="9999999" le="9999999"/><detail/></event>';
$SocketConnection = fsockopen($FTSIP, $FTSPort, $errno, $errstr);
if (!$SocketConnection) {
return "Failed_no_Socket_Connection";
Expand Down
9 changes: 7 additions & 2 deletions takcar_scripts/tester.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@
<tr>
<td>1</td>
<td><code>http://YOUR_IP:8082/api/session?token=YOUR_TOKEN</code></td>
<td>Get the Traccar Jsession coockie</td>
<td>Get the Traccar Jsession cookie</td>
</tr>
<tr>
<td>2</td>
<td><code>http://YOUR_IP:8082/api/positions?token=YOUR_TOKEN</code></td>
<td>Get the Traccar positions via</td>
<td>Get the Traccar positions via endpoint</td>
</tr>
<tr>
<td>3</td>
<td><code>http://YOUR_IP:8082/api/devices?token=YOUR_TOKEN</code></td>
<td>Get the Traccar devices via endpoint</td>
</tr>
<tr>
<td>4</td>
<td><code>http://YOUR_IP:19023/ManagePresence/postPresence</code></td>
<td>Post the Traccar positions to FreeTakServer</td>
</tr>
Expand Down

0 comments on commit 4407ec5

Please sign in to comment.