Skip to content

Commit 640b33b

Browse files
committed
Updates scripts
1 parent b076d53 commit 640b33b

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

Scripts/config.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
//Token vars
4+
$TraccarAPIToken = "hdbtrsy6576hyw84567cSiOuqqhA";
5+
$FreeTakServerAPIToken = "Bearer token";
6+
7+
//`Test Service` button config
8+
$How = "nonCoT";
9+
$Name = "POTUS";
10+
$Longitude = -77.01385;
11+
$Latitude = 38.889;
12+
$Role = "Team Member";
13+
$Team = "Yellow";

index.php Scripts/index.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1+
<?php include_once("config.php");//include config?>
2+
13
<!DOCTYPE html>
24
<html>
35
<head>
46
<title>TAKCAR SERVICE</title>
5-
67
<!-- Optional theme -->
78
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/4.5.2/darkly/bootstrap.min.css">
8-
99
<!-- Jquery -->
1010
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
11-
1211
<!-- Latest compiled and minified JavaScript -->
1312
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
14-
1513
</head>
14+
1615
<body>
1716
<br>
1817
<div class="container-fluid">
@@ -111,20 +110,20 @@ function error(err) {
111110
alert('Failed: ' + JSON.stringify(err));
112111
}
113112

114-
var Authorization = "Bearer token";
113+
var Authorization = "<?php echo$FreeTakServerAPIToken;?>";
115114

116115
function testFunction(){
117116
var xhr = new XMLHttpRequest(); //invoke a new instance of the XMLHttpRequest
118117
xhr.onload = success; // call success function if request is successful
119118
xhr.onerror = error; // call error function if request failed
120119

121120
var json = {uid: uuidv4(),
122-
how: "nonCoT",
123-
name: "POTUS",
124-
longitude: -77.01385,
125-
latitude: 38.889,
126-
role: "Team Member",
127-
team: "Yellow"};//JSON object
121+
how: "<?php echo$How;?>",
122+
name: "<?php echo$Name;?>",
123+
longitude: <?php echo$Longitude;?>,
124+
latitude: <?php echo$Latitude;?>,
125+
role: "<?php echo$Role;?>",
126+
team: "<?php echo$Team;?>"};//JSON object
128127

129128
xhr.open('POST', 'http://127.0.0.1:19023/ManagePresence/postPresence', true); // open a GET request
130129
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');//application/json;charset=UTF-8

serverUpdater.php Scripts/serverUpdater.php

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<?php
2+
//include config
3+
include_once("config.php");
24
// set headers
35
header('Content-Type: text/event-stream');
46
header('Cache-Control: no-cache');
57
header('Connection: keep-alive');
68

79
//get the session cookie
8-
$session = json_encode(get_TraccarSession("http://127.0.0.1:8082/api/session?token=hdbtrsy6576hyw84567cSiOuqqhA"));
10+
$session = json_encode(get_TraccarSession("http://127.0.0.1:8082/api/session?token=$TraccarAPIToken"));
911

1012
$api_result = json_decode($session, true);
1113
$JSESSIONID = $api_result['JSESSIONID'];
1214

1315
//get the Traccar positions
14-
$positions = get_TraccarPosition("http://127.0.0.1:8082/api/positions?token=hdbtrsy6576hyw84567cSiOuqqhA",$JSESSIONID);
16+
$positions = get_TraccarPosition("http://127.0.0.1:8082/api/positions?token=$TraccarAPIToken",$JSESSIONID);
1517

1618
$json = json_decode($positions);
1719

@@ -76,20 +78,13 @@ function get_TraccarPosition($url,$JSESSIONID) {
7678
)
7779
);
7880

79-
$context = stream_context_create($opts);
80-
8181
// Open the file using the HTTP headers set above
82-
$file = file_get_contents($url, false, $context);
82+
$file = file_get_contents($url, false, stream_context_create($opts));
8383
return $file;
8484
}
8585

86-
function get_FTSAPI($id, $latitude, $longitude) {
86+
function get_FTSAPI($id, $latitude, $longitude, $FreeTakServerAPIToken) {
8787

88-
//http://127.0.0.1:19023/ManagePresence/putPresence
89-
//http://127.0.0.1:19023/ManagePresence/postPresence
90-
$url = "http://127.0.0.1:19023/ManagePresence/postPresence";
91-
//FTS Bearer token
92-
$token = "Bearer token";
9388
//generate GUID
9489
$guid = vsprintf('%s%s-%s-4000-8%.3s-%s%s%s0',str_split(dechex( microtime(true) * 1000 ) . bin2hex( random_bytes(8) ),4));
9590

@@ -104,22 +99,19 @@ function get_FTSAPI($id, $latitude, $longitude) {
10499
"team" => "Red"
105100
);
106101

107-
// for sending data as json type
108-
$fields = json_encode($postData);
109-
110-
$ch = curl_init($url);
102+
$ch = curl_init("http://127.0.0.1:19023/ManagePresence/postPresence");
111103
//set cURL options
112104
curl_setopt(
113105
$ch,
114106
CURLOPT_HTTPHEADER,
115107
array(
116108
'Content-Type: application/json',
117-
'Authorization: '.$token
109+
'Authorization: '.$FreeTakServerAPIToken
118110
)
119111
);
120112
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
121113
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
122-
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
114+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
123115
//execute cURL call
124116
$result = curl_exec($ch);
125117
curl_close($ch);

0 commit comments

Comments
 (0)