Skip to content

Commit 4407ec5

Browse files
committed
Allows name to be displayed
1 parent 7a42dad commit 4407ec5

File tree

2 files changed

+45
-52
lines changed

2 files changed

+45
-52
lines changed

takcar_scripts/serverUpdater.php

+38-50
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,30 @@
1111
//get the Traccar positions
1212
$positions = get_TraccarPosition("$TraccarProtocol://$TraccarIP:$TraccarPort/api/positions?token=$TraccarAPIToken", $JSESSIONID);
1313

14-
$json = json_decode($positions);
14+
//get the Traccar devices
15+
$devices = get_TraccarDevice("$TraccarProtocol://$TraccarIP:$TraccarPort/api/devices?token=$TraccarAPIToken", $JSESSIONID);
16+
17+
$jpositions = json_decode($positions);
18+
19+
$jdevices = json_decode($devices);
1520

1621
//loop through the positions
1722
$devices = array();
18-
foreach($json as $key => $item){
19-
20-
//forward the positions to the FTS API endpoint
21-
//$result = get_FTSAPI($item->id, $item->latitude, $item->longitude, $FTSProtocol, $FTSIP, $FTSAPIPort, $FTSAPIToken);
22-
if (in_array($item->id, $devices)) {
23-
//forward the positions to the FTS TCP port
24-
$result = get_FTSSOCKETPING($item->id, $item->latitude, $item->longitude, $FTSIP, $FTSPort);
25-
}else {
26-
//forward the positions to the FTS TCP port
27-
$result = get_FTSSOCKET($item->id, $item->latitude, $item->longitude, $FTSIP, $FTSPort);
28-
$devices[] = $item->id;
23+
foreach($jpositions as $pkey => $pitem){
24+
foreach($jdevices as $dkey => $ditem){
25+
if ($pitem->id == $ditem->id) {
26+
27+
//forward the positions to the FTS API endpoint
28+
if (in_array($pitem->id, $devices)) {
29+
//forward the positions to the FTS TCP port
30+
$result = get_FTSSOCKETPING($pitem->id, $ditem->name, $pitem->latitude, $pitem->longitude, $FTSIP, $FTSPort);
31+
}else {
32+
//forward the positions to the FTS TCP port
33+
$result = get_FTSSOCKET($pitem->id, $ditem->name, $pitem->latitude, $pitem->longitude, $FTSIP, $FTSPort);
34+
$devices[] = $pitem->id;
35+
}
36+
}
37+
2938
}
3039

3140
$markers[] = json_encode(
@@ -79,47 +88,26 @@ function get_TraccarPosition($url,$JSESSIONID) {
7988
return $file;
8089
}
8190

82-
function get_FTSAPI($id, $latitude, $longitude, $FTSProtocol, $FTSIP, $FTSAPIPort, $FTSAPIToken) {
83-
84-
//generate GUID
85-
$guid = vsprintf('%s%s-%s-4000-8%.3s-%s%s%s0',str_split(dechex( microtime(true) * 1000 ) . bin2hex( random_bytes(8) ),4));
86-
87-
//Json data to post
88-
$postData = array(
89-
"uid" => $guid,
90-
"how" => "nonCoT",
91-
"name" => "ID_".$id,
92-
"longitude" => $longitude,
93-
"latitude" => $latitude,
94-
"role" => "Team Member",
95-
"team" => "Red"
96-
);
97-
98-
$ch = curl_init("$FTSProtocol://$FTSIP:$FTSAPIPort/ManagePresence/postPresence");
99-
//set cURL options
100-
curl_setopt(
101-
$ch,
102-
CURLOPT_HTTPHEADER,
103-
array(
104-
'Content-Type: application/json',
105-
'Authorization: '.$FTSAPIToken
91+
function get_TraccarDevice($url,$JSESSIONID) {
92+
//set the headers and cookie
93+
$opts = array(
94+
'http'=>array(
95+
'method'=>"GET",
96+
'header'=>"Accept-language: en\r\n" .
97+
"Cookie: JSESSIONID=$JSESSIONID\r\n"
10698
)
107-
);
108-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
109-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
110-
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
111-
//execute cURL call
112-
$result = curl_exec($ch);
113-
curl_close($ch);
114-
115-
return $result;
116-
}
99+
);
100+
101+
// Open the file using the HTTP headers set above
102+
$file = file_get_contents($url, false, stream_context_create($opts));
103+
return $file;
104+
}
117105

118106
//https://www.latlong.net/
119-
function get_FTSSOCKET($id, $latitude, $longitude, $FTSIP, $FTSPort) {
107+
function get_FTSSOCKET($id, $name, $latitude, $longitude, $FTSIP, $FTSPort) {
120108
//generate GUID
121109
//$guid = vsprintf('%s%s40-%s%s3-%s%s43-%s1',str_split(dechex( microtime(true) * 1000 ) . bin2hex( random_bytes(8) ),4));
122-
$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>';
110+
$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>';
123111
$SocketConnection = fsockopen($FTSIP, $FTSPort, $errno, $errstr);
124112
if (!$SocketConnection) {
125113
return "Failed_no_Socket_Connection";
@@ -138,11 +126,11 @@ function get_FTSSOCKET($id, $latitude, $longitude, $FTSIP, $FTSPort) {
138126
return "Done";
139127
}
140128

141-
function get_FTSSOCKETPING($id, $latitude, $longitude, $FTSIP, $FTSPort) {
129+
function get_FTSSOCKETPING($id, $name, $latitude, $longitude, $FTSIP, $FTSPort) {
142130
//generate GUID
143131
//S-1-5-21-1568504889-667903775-1938598950-1001-ping
144132
//$guid = vsprintf('%s%s40-%s%s3-%s%s43-%s1',str_split(dechex( microtime(true) * 1000 ) . bin2hex( random_bytes(8) ),4));
145-
$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>';
133+
$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>';
146134
$SocketConnection = fsockopen($FTSIP, $FTSPort, $errno, $errstr);
147135
if (!$SocketConnection) {
148136
return "Failed_no_Socket_Connection";

takcar_scripts/tester.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,20 @@
4040
<tr>
4141
<td>1</td>
4242
<td><code>http://YOUR_IP:8082/api/session?token=YOUR_TOKEN</code></td>
43-
<td>Get the Traccar Jsession coockie</td>
43+
<td>Get the Traccar Jsession cookie</td>
4444
</tr>
4545
<tr>
4646
<td>2</td>
4747
<td><code>http://YOUR_IP:8082/api/positions?token=YOUR_TOKEN</code></td>
48-
<td>Get the Traccar positions via</td>
48+
<td>Get the Traccar positions via endpoint</td>
4949
</tr>
5050
<tr>
5151
<td>3</td>
52+
<td><code>http://YOUR_IP:8082/api/devices?token=YOUR_TOKEN</code></td>
53+
<td>Get the Traccar devices via endpoint</td>
54+
</tr>
55+
<tr>
56+
<td>4</td>
5257
<td><code>http://YOUR_IP:19023/ManagePresence/postPresence</code></td>
5358
<td>Post the Traccar positions to FreeTakServer</td>
5459
</tr>

0 commit comments

Comments
 (0)