initial commit

This commit is contained in:
2025-08-19 11:40:26 -07:00
commit c34b325cf0
18 changed files with 1803 additions and 0 deletions

View File

@ -0,0 +1,233 @@
<?php
date_default_timezone_set('America/Los_Angeles');
# set default values
$status = "Unchecked";
$message = "No attempt made yet.";
$button_text = "Pending";
$button_active = false;
$button_recent = false;
$button_action = "";
$button_result = "";
$http_host = $_SERVER['HTTP_HOST'];
$debug_string = "";
if (isset($_GET['action'])) {
$debug_string = $debug_string."GET called, ".$_GET['action']."<br>";
$button_recent = true;
$button_result = runAPI($_GET['action']);
$debug_string = $debug_string."Button Result: ".$button_result."<br>";
sleep(1);
}
function runAPI($submitted_status) {
if(!isset($debug_string)){
$debug_string = "";
}
$debug_string = $debug_string."runAPI called, ".$submitted_status."<br>";
switch ($submitted_status) {
case "stop":
$apiUrl = "http://172.17.0.1:5000/stop";
break;
case "start":
$apiUrl = "http://172.17.0.1:5000/start";
break;
default:
$apiUrl = "http://172.17.0.1:5000/status";
break;
}
// API URL
$debug_string = $debug_string."After switch, apiUrl is ".$apiUrl."<br>";
// Use file_get_contents or cURL to fetch the API data
try {
$response = file_get_contents($apiUrl);
} catch (Exception $e) {
$response = '{ "Message": "unknowable", "Status": "unknowable" }';
}
if ($response === FALSE) {
$debug_string = $debug_string."Response ERROR!!<br>";
return "error"; // API error
}
// Decode the JSON response (assuming the API returns JSON)
$data = json_decode($response, true);
$debug_string = $debug_string."Data from API call: ".$data['Message']."<br>";
// Assuming the API returns a single word result (like "success", "failure", etc.)
return isset($data['Status']) ? $data['Status'] : 'unknown';
}
// | awk '{printf(\"%.5f\n\", $1)}'
// | awk '{printf(\"%.5f\n\", $1)}'
function getGPS(){
// check the API
$gps_data = file_get_contents("http://172.17.0.1:5000/return_gps");
try {
$gps_data = json_decode($gps_data, true);
} catch (Exception $e){
$gps_data = '{c}';
}
//set the vars
$LAT = $gps_data['lat'];
$LON = $gps_data['lon'];
$SPEED = $gps_data['speed'];
if (is_null($LAT) || $LAT == 0) {
return "No GPS data available - null LAT";
}
if (is_null($LON) || $LON == 0) {
return "No GPS data available - null LON";
}
return $LAT.", ".$LON.", ".$SPEED."mph";
}
// URL of the external API
$apiUrl = "http://172.17.0.1:5000/status";
// Use file_get_contents to fetch data from the API
try {
$response = file_get_contents($apiUrl);
} catch (Exception $e) {
$response = '{ "Message": "unknowable", "Status": "unknowable" }';
}
// Check if the request was successful
if ($response === FALSE) {
$data = "Failed to fetch data.";
}
else {
// Decode the JSON response (assuming the API returns JSON)
$data = json_decode($response, true);
// If you want to display specific data, adjust this part
// For example, if the API returns a 'message' key, display it
if (isset($data['Message'])) {
$message = $data['Message'];
} else {
$message = "No message found in the response.";
}
if (isset($data['Status'])) {
$status = $data['Status'];
} else {
$status = "None";
}
}
switch ($status) {
case "active":
$button_text = "Stop Service";
$button_active = true;
break;
case "inactive":
$button_text = "Start Service";
$button_active = true;
break;
case "failed":
$button_text = "Start Service - Warning";
$button_active = true;
break;
case "deactivating":
$button_text = "Service Stopping...";
$button_active = false;
break;
case "unknowable":
$button_text = "Service Manager Down...";
$button_active = false;
break;
default:
$button_text = "Error, No Status";
$button_active = false;
$status="unknown";
break;
}
if($button_active && !$button_recent){
$action = "";
if($status == "active"){
$action = "stop";
}
else if($status == "inactive"){
$action = "start";
}
else if($status == "failed"){
$action = "start";
}
$button_action = ' onclick="location.href=\'/?action='.$action.'\'" ';
}
if($button_recent){
/*
$delay = 5; // Number of seconds before redirection
echo "You will be redirected in $delay seconds.";
header("Refresh: $delay; url=https://example.com");
exit();
*/
header("Location: http://".$http_host);
exit(); // Always include exit() after headers are sent
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Data Display</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<div class="button-container">
<button <?php echo $button_action; ?> class="<?php echo $status; ?>" id="phpButton"<?php if(!$button_active || $button_recent) {echo " disabled";} ?>>
<?php echo $button_text; ?>
</button>
<p>
</div>
<p>
<div class="api-data">
<!-- PHP will inject the data here -->
<?php
echo "Full Message:<br>".htmlspecialchars($message)."<p>";
echo "Current Date:<br>".date("F j, Y, g:i:s a")."<p>";
echo "Current GPS Data:<br>".getGPS();
?>
</div>
</div>
<script>
// When the button is clicked, send an AJAX request to fetch new data
document.getElementById('phpButton').addEventListener('click', function() {
// Disable button to avoid multiple clicks
this.disabled = true;
this.innerText = 'Loading...';
// Make an AJAX request
fetch('index.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
'status': '<?php echo $status; ?>'
},
body: 'action=fetch_data' // Trigger the PHP function via POST
})
});
</script>
<script>
// Automatically refresh the page every second
setTimeout(function() {
location.reload();
}, <?php if($button_recent){ echo "5000"; } else{ echo "1000"; } ?>); // Refresh interval (1000 ms = 1 second)
</script>
</body>
</html>

View File

@ -0,0 +1,86 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #2c3e50; /* Dark background color */
color: #bdc3c7; /* Dimmer text color */
zoom: 1.5;
overflow: hidden; /* Hide scrollbars */
}
.container {
max-width: 500px;
margin: 0 auto;
margin-top: 20px;
padding: 20px;
background-color: #34495e; /* Darker background for container */
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); /* Slightly darker shadow */
}
.api-data {
font-size: 1.4rem;
color: #bdc3c7; /* Dimmer text color */
}
.loading {
font-size: 1.2rem;
background-color: #34495e; /* Darker background for container-wide */
}
.status-button {
padding: 10px 20px;
font-size: 1.5rem;
border: none;
cursor: pointer;
margin-top: 20px;
border-radius: 5px;
}
.button-container {
display: flex;
justify-content: center; /* This centers the button horizontally */
}
button {
background: radial-gradient(circle, #ff7e5f 0%, #feb47b 100%);
border: none;
color: white;
font-size: 30px;
padding: 25px 50px;
text-align: center;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
border-radius: 30px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
}
button:hover {
transform: scale(1.05);
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
}
.inactive {
background-color: #0b660e;
background: radial-gradient(circle, #0b660e 0%, #2b922f 100%);
color: #bdc3c7; /* Dimmer text color */
}
.active {
background-color: #a5150b;
background: radial-gradient(circle, #a5150b 0%, #d6382d 100%);
color: #bdc3c7; /* Dimmer text color */
}
.failed {
background-color: #671281;
background: radial-gradient(circle, #671281 0%, #8423a1 100%);
color: #bdc3c7; /* Dimmer text color */
}
.deactivating {
background-color: #003699;
background: radial-gradient(circle, #003699 0%, #337aff 100%);
color: #bdc3c7; /* Dimmer text color */
}
.deactivating {
background-color: #0d2b2c;
background: radial-gradient(circle, #0d2b2c 0%, #123738 100%);
color: #bdc3c7; /* Dimmer text color */
}
.unknown {
background-color: #ec701e;
background: radial-gradient(circle, #c9580d 0%, #ec701e 100%);
color: #bdc3c7; /* Dimmer text color */
}