Skip to content

Commit

Permalink
Updates scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Cale-Torino committed Sep 6, 2021
1 parent b076d53 commit 640b33b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
13 changes: 13 additions & 0 deletions Scripts/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

//Token vars
$TraccarAPIToken = "hdbtrsy6576hyw84567cSiOuqqhA";
$FreeTakServerAPIToken = "Bearer token";

//`Test Service` button config
$How = "nonCoT";
$Name = "POTUS";
$Longitude = -77.01385;
$Latitude = 38.889;
$Role = "Team Member";
$Team = "Yellow";
21 changes: 10 additions & 11 deletions index.php → Scripts/index.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?php include_once("config.php");//include config?>

<!DOCTYPE html>
<html>
<head>
<title>TAKCAR SERVICE</title>

<!-- Optional theme -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/4.5.2/darkly/bootstrap.min.css">

<!-- Jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

</head>

<body>
<br>
<div class="container-fluid">
Expand Down Expand Up @@ -111,20 +110,20 @@ function error(err) {
alert('Failed: ' + JSON.stringify(err));
}

var Authorization = "Bearer token";
var Authorization = "<?php echo$FreeTakServerAPIToken;?>";

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

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

xhr.open('POST', 'http://127.0.0.1:19023/ManagePresence/postPresence', true); // open a GET request
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');//application/json;charset=UTF-8
Expand Down
26 changes: 9 additions & 17 deletions serverUpdater.php → Scripts/serverUpdater.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php
//include config
include_once("config.php");
// set headers
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
header('Connection: keep-alive');

//get the session cookie
$session = json_encode(get_TraccarSession("http://127.0.0.1:8082/api/session?token=hdbtrsy6576hyw84567cSiOuqqhA"));
$session = json_encode(get_TraccarSession("http://127.0.0.1:8082/api/session?token=$TraccarAPIToken"));

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

//get the Traccar positions
$positions = get_TraccarPosition("http://127.0.0.1:8082/api/positions?token=hdbtrsy6576hyw84567cSiOuqqhA",$JSESSIONID);
$positions = get_TraccarPosition("http://127.0.0.1:8082/api/positions?token=$TraccarAPIToken",$JSESSIONID);

$json = json_decode($positions);

Expand Down Expand Up @@ -76,20 +78,13 @@ function get_TraccarPosition($url,$JSESSIONID) {
)
);

$context = stream_context_create($opts);

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

function get_FTSAPI($id, $latitude, $longitude) {
function get_FTSAPI($id, $latitude, $longitude, $FreeTakServerAPIToken) {

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

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

// for sending data as json type
$fields = json_encode($postData);

$ch = curl_init($url);
$ch = curl_init("http://127.0.0.1:19023/ManagePresence/postPresence");
//set cURL options
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
'Content-Type: application/json',
'Authorization: '.$token
'Authorization: '.$FreeTakServerAPIToken
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
//execute cURL call
$result = curl_exec($ch);
curl_close($ch);
Expand Down

0 comments on commit 640b33b

Please sign in to comment.