11
11
//get the Traccar positions
12
12
$ positions = get_TraccarPosition ("$ TraccarProtocol:// $ TraccarIP: $ TraccarPort/api/positions?token= $ TraccarAPIToken " , $ JSESSIONID );
13
13
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 );
15
20
16
21
//loop through the positions
17
22
$ 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
+
29
38
}
30
39
31
40
$ markers [] = json_encode (
@@ -79,47 +88,26 @@ function get_TraccarPosition($url,$JSESSIONID) {
79
88
return $ file ;
80
89
}
81
90
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"
106
98
)
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
+ }
117
105
118
106
//https://www.latlong.net/
119
- function get_FTSSOCKET ($ id , $ latitude , $ longitude , $ FTSIP , $ FTSPort ) {
107
+ function get_FTSSOCKET ($ id , $ name , $ latitude , $ longitude , $ FTSIP , $ FTSPort ) {
120
108
//generate GUID
121
109
//$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> ' ;
123
111
$ SocketConnection = fsockopen ($ FTSIP , $ FTSPort , $ errno , $ errstr );
124
112
if (!$ SocketConnection ) {
125
113
return "Failed_no_Socket_Connection " ;
@@ -138,11 +126,11 @@ function get_FTSSOCKET($id, $latitude, $longitude, $FTSIP, $FTSPort) {
138
126
return "Done " ;
139
127
}
140
128
141
- function get_FTSSOCKETPING ($ id , $ latitude , $ longitude , $ FTSIP , $ FTSPort ) {
129
+ function get_FTSSOCKETPING ($ id , $ name , $ latitude , $ longitude , $ FTSIP , $ FTSPort ) {
142
130
//generate GUID
143
131
//S-1-5-21-1568504889-667903775-1938598950-1001-ping
144
132
//$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> ' ;
146
134
$ SocketConnection = fsockopen ($ FTSIP , $ FTSPort , $ errno , $ errstr );
147
135
if (!$ SocketConnection ) {
148
136
return "Failed_no_Socket_Connection " ;
0 commit comments