Merge pull request #285 from mcguirepr89/offline-time-testy

Offline time testy
This commit is contained in:
Patrick McGuire
2022-05-15 15:35:12 -04:00
committed by GitHub
+47 -1
View File
@@ -1,5 +1,5 @@
<?php
error_reporting(E_ALL);
error_reporting(E_ERROR);
ini_set('display_errors',1);
# Basic Settings
@@ -21,6 +21,21 @@ if(isset($_GET['apprise_notify_each_species'])) {
exec('sudo systemctl stop pushed_notifications.service');
}
// logic for setting the date and time based on user inputs from the form below
if(isset($_GET['date']) && isset($_GET['time'])) {
// can't set the date manually if it's getting it from the internet, disable ntp
exec("sudo timedatectl set-ntp false");
exec("sudo date -s '".$_GET['date']." ".$_GET['time']."'");
} else {
// user checked 'use time from internet if available,' so make sure that's on
if(strlen(trim(exec("sudo timedatectl | grep \"NTP service: active\""))) == 0){
exec("sudo timedatectl set-ntp true");
sleep(3);
}
}
$contents = file_get_contents("/etc/birdnet/birdnet.conf");
@@ -164,6 +179,37 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}
<option value="labels_uk.txt">Ukrainian</option>
</select>
<br><br>
<script>
function handleChange(checkbox) {
// this disables the input of manual date and time if the user wants to use the internet time
var date=document.getElementById("date");
var time=document.getElementById("time");
if(checkbox.checked) {
date.setAttribute("disabled", "disabled");
time.setAttribute("disabled", "disabled");
} else {
date.removeAttribute("disabled");
time.removeAttribute("disabled");
}
}
</script>
<?php
// if NTP service is active, show the checkboxes as checked, and disable the manual input
$tdc = trim(exec("sudo timedatectl | grep \"NTP service: active\""));
if (strlen($tdc) > 0) {
$checkedvalue = "checked";
$disabledvalue = "disabled";
} else {
$checkedvalue = "";
$disabledvalue = "";
}
?>
<label for="appt">Select a Date and Time:</label><br>
<span>If connected to the internet, retrieve time automatically?</span>
<input type="checkbox" onchange='handleChange(this)' name="apprise_notify_each_detection" <?php echo $checkedvalue; ?> ><br>
<input onclick="this.showPicker()" type="date" id="date" name="date" value="<?php echo date('Y-m-d') ?>" <?php echo $disabledvalue; ?>>
<input onclick="this.showPicker()" type="time" id="time" name="time" value="<?php echo date('H:i') ?>" <?php echo $disabledvalue; ?>>
<br><br><br>
<input type="hidden" name="status" value="success">
<input type="hidden" name="submit" value="settings">