Skip to content

A live bird collage card for your Home Assistant dashboard.

convert service_controls.php system_controls.php

frederika48bda055b9a
diff --git a/scripts/service_controls.php b/scripts/service_controls.php
index 555c8040..410db177 100644
--- a/scripts/service_controls.php
+++ b/scripts/service_controls.php
@@ -1,7 +1,9 @@
<?php
-$home = trim(shell_exec("awk -F: '/1000/{print $6}' /etc/passwd"));
+require_once "scripts/common.php";
+$home = get_home();
+
function do_service_mount($action) {
- echo "value=\"sudo systemctl ".$action." ".service_mount()." && sudo reboot\"";
+ echo "value=\"sudo systemctl ".$action." ".get_service_mount_name()." && sudo reboot\"";
}
function service_status($name) {
global $home;
@@ -81,7 +83,7 @@ function service_status($name) {
<button type="submit" name="submit" value="sudo systemctl enable --now spectrogram_viewer.service">Enable</button>
</form>
<form action="" method="GET">
- <h3>Ram drive (!experimental!) <?php echo service_status(service_mount());?></h3>
+ <h3>Ram drive (!experimental!) <?php echo service_status(get_service_mount_name());?></h3>
<button type="submit" name="submit" <?php do_service_mount("disable");?> onclick="return confirm('This will reboot, are you sure?')">Disable</button>
<button type="submit" name="submit" <?php do_service_mount("enable");?> onclick="return confirm('This will reboot, are you sure?')">Enable</button>
</form>
diff --git a/scripts/stats.php b/scripts/stats.php
index 831a8f0b..84ae9f7d 100644
--- a/scripts/stats.php
+++ b/scripts/stats.php
@@ -8,6 +8,7 @@ ini_set('user_agent', 'PHP_Flickr/1.0');
error_reporting(0);
ini_set('display_errors', 0);
require_once 'scripts/common.php';
+$home = get_home();
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);
$db->busyTimeout(1000);
@@ -41,9 +42,6 @@ if(isset($_GET['species'])){
$result3 = $statement3->execute();
}
-$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
-$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
-$home = trim($home);
if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt") || strpos(file_get_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt"),"##start") === false) {
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "");
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start\n##end\n");
@@ -192,11 +190,8 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){
ob_flush();
flush();
- if (file_exists('./scripts/thisrun.txt')) {
- $config = parse_ini_file('./scripts/thisrun.txt');
- } elseif (file_exists('./scripts/firstrun.ini')) {
- $config = parse_ini_file('./scripts/firstrun.ini');
- }
+ $config = get_config();
+
if (! empty($config["FLICKR_API_KEY"])) {
// only open the file once per script execution
if(!isset($lines)) {
diff --git a/scripts/system_controls.php b/scripts/system_controls.php
index c63b2aca..8be71356 100644
--- a/scripts/system_controls.php
+++ b/scripts/system_controls.php
@@ -1,9 +1,9 @@
<?php
session_start();
-$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
-$user = trim($user);
-$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
-$home = trim($home);
+require_once "scripts/common.php";
+$user = get_user();
+$home = get_home();
+
$fetch = shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi fetch 2>&1");
$str = trim(shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi status"));
if (preg_match("/behind '.*?' by (\d+) commit(s?)\b/", $str, $matches)) {