From 6af59a2908165e4765e0da76365e809148b4a0e2 Mon Sep 17 00:00:00 2001 From: jaredb7 Date: Wed, 10 May 2023 23:56:23 +1000 Subject: [PATCH] Fix caddyfile not updating due to command execution being intercepted by auth prompt We always want this command to execute regardless and rebuild the caddy config accordingly. --- scripts/advanced.php | 7 +++++-- scripts/common.php | 13 ++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/advanced.php b/scripts/advanced.php index 85cdbe5..751ccb8 100644 --- a/scripts/advanced.php +++ b/scripts/advanced.php @@ -25,7 +25,9 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) { if(isset($_GET['submit'])) { if(isset($_GET["caddy_pwd"])) { $caddy_pwd = $_GET["caddy_pwd"]; - saveSetting('CADDY_PWD', "\"$caddy_pwd\"",'update_caddyfile'); + saveSetting('CADDY_PWD', "\"$caddy_pwd\""); + //Make sure the caddy file is set directly + update_caddyfile(); } if(isset($_GET["ice_pwd"])) { @@ -37,7 +39,8 @@ if(isset($_GET['submit'])) { $birdnetpi_url = $_GET["birdnetpi_url"]; // remove trailing slash to prevent conf from becoming broken $birdnetpi_url = rtrim($birdnetpi_url, '/'); - saveSetting('BIRDNETPI_URL', $birdnetpi_url,'update_caddyfile'); + saveSetting('BIRDNETPI_URL', $birdnetpi_url); + update_caddyfile(); } if(isset($_GET["rtsp_stream"])) { diff --git a/scripts/common.php b/scripts/common.php index d239edb..96c533d 100644 --- a/scripts/common.php +++ b/scripts/common.php @@ -1338,9 +1338,6 @@ function executeSysCommand($command_type, $extra_data_to_pass = null) $command = "sudo -u $user " . getFilePath('python3') . ' ' . getFilePath('species.py') . " --threshold " . escapeshellcmd($extra_data_to_pass) . " 2>&1"; $result = shell_exec($command); // - } else if ($command_type == "update_caddyfile") { - $result = exec("sudo /usr/local/bin/update_caddyfile.sh > /dev/null 2>&1 &"); - // } else if ($command_type == "update_birdnet") { $result = shell_exec("update_birdnet.sh"); // @@ -1358,6 +1355,16 @@ function executeSysCommand($command_type, $extra_data_to_pass = null) return $result; } +/** + * Updates the caddy configuration, only ever called when BirdNET-Pi Password or Site URL is set + * + * @return void + */ +function update_caddyfile() +{ + exec("sudo /usr/local/bin/update_caddyfile.sh > /dev/null 2>&1 &"); +} + /** * Performs tasks such as stop, restart, disable and enable on the supplied service * input command must contain the service name and must contain a keyword that describes the action