Skip to content

A live bird collage card for your Home Assistant dashboard.

smarter advanced.php -- handles updating system with new settings instead of jsut files

mcguirepr89e37663cfc1b0
diff --git a/scripts/update_caddyfile.sh b/scripts/update_caddyfile.sh
new file mode 100755
index 00000000..f2da5023
--- /dev/null
+++ b/scripts/update_caddyfile.sh
@@ -0,0 +1,66 @@
+#!/usr/bin/env bash
+source /etc/birdnet/birdnet.conf
+set -x
+[ -d /etc/caddy ] || mkdir /etc/caddy
+if [ -f /etc/caddy/Caddyfile ];then
+ cp /etc/caddy/Caddyfile{,.original}
+fi
+if ! [ -z ${CADDY_PWD} ];then
+HASHWORD=$(caddy hash-password -plaintext ${CADDY_PWD})
+cat << EOF > /etc/caddy/Caddyfile
+http://localhost http://$(hostname).local ${BIRDNETPI_URL} {
+ root * ${EXTRACTED}
+ file_server browse
+ basicauth /Processed* {
+ birdnet ${HASHWORD}
+ }
+ basicauth /scripts* {
+ birdnet ${HASHWORD}
+ }
+ basicauth /stream {
+ birdnet ${HASHWORD}
+ }
+ basicauth /phpsysinfo* {
+ birdnet ${HASHWORD}
+ }
+ reverse_proxy /stream localhost:8000
+ php_fastcgi unix//run/php/php7.4-fpm.sock
+}
+EOF
+else
+ cat << EOF > /etc/caddy/Caddyfile
+http://localhost http://$(hostname).local ${BIRDNETPI_URL} {
+ root * ${EXTRACTED}
+ file_server browse
+ reverse_proxy /stream localhost:8000
+ php_fastcgi unix//run/php/php7.4-fpm.sock
+}
+EOF
+fi
+
+if [ ! -z ${WEBTERMINAL_URL} ] && [ ! -z ${HASHWORD} ];then
+ cat << EOF >> /etc/caddy/Caddyfile
+${WEBTERMINAL_URL} {
+ basicauth {
+ birdnet ${HASHWORD}
+ }
+ reverse_proxy localhost:8888
+}
+EOF
+elif [ ! -z ${WEBTERMINAL_URL} ] && [ -z ${HASHWORD} ];then
+ cat << EOF >> /etc/caddy/Caddyfile
+${WEBTERMINAL_URL} {
+ reverse_proxy localhost:8888
+}
+EOF
+fi
+if [ ! -z ${BIRDNETLOG_URL} ];then
+ cat << EOF >> /etc/caddy/Caddyfile
+
+${BIRDNETLOG_URL} {
+ reverse_proxy localhost:8080
+}
+EOF
+fi
+
+( systemctl reload caddy ) &
diff --git a/scripts/update_settings_inprogress.php b/scripts/update_settings_inprogress.php
new file mode 100644
index 00000000..0977e533
--- /dev/null
+++ b/scripts/update_settings_inprogress.php
@@ -0,0 +1,40 @@
+<?php
+$timer=30;
+header( "refresh:$timer;url=/advanced.php" );
+?>
+<html lang="en">
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <head></head>
+ <body style="background-color: rgb(119, 196, 135)">
+<script>
+
+function countDown(secs,elem) {
+
+ var element = document.getElementById(elem);
+
+ element.innerHTML = "Updating settings... Please allow another "+secs+" seconds for it to complete.";
+
+ if(secs < 1) {
+
+ clearTimeout(timer);
+
+ element.innerHTML = '<h4>Let\'s see</h4>';
+
+ element.innerHTML += '<a href="https://birdnetpi.pmcgui.xyz"></a>';
+
+ }
+
+ secs--;
+
+ var timer = setTimeout('countDown('+secs+',"'+elem+'")',1000);
+
+}
+
+</script>
+
+<div id="status"style="font-size:30px;"></div>
+
+<script>countDown(<?php echo $timer;?>,"status");</script>
+ </body>
+</html>
diff --git a/scripts/write_advanced.php b/scripts/write_advanced.php
deleted file mode 100644
index fd13f396..00000000
--- a/scripts/write_advanced.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-$caddy_pwd = $_POST["caddy_pwd"];
-$db_pwd = $_POST["db_pwd"];
-$ice_pwd = $_POST["ice_pwd"];
-$birdnetpi_url = $_POST["birdnetpi_url"];
-$webterminal_url = $_POST["webterminal_url"];
-$birdnetlog_url = $_POST["birdnetlog_url"];
-$overlap = $_POST["overlap"];
-$confidence = $_POST["confidence"];
-$sensitivity = $_POST["sensitivity"];
-$full_disk = $_POST["full_disk"];
-$rec_card = $_POST["rec_card"];
-$channels = $_POST["channels"];
-$recording_length = $_POST["recording_length"];
-$extraction_length = $_POST["extraction_length"];
-
-$contents = file_get_contents("/home/pi/BirdNET-Pi/birdnet.conf");
-$contents = preg_replace("/CADDY_PWD=.*/", "CADDY_PWD=$caddy_pwd", $contents);
-$contents = preg_replace("/DB_PWD=.*/", "DB_PWD=$db_pwd", $contents);
-$contents = preg_replace("/ICE_PWD=.*/", "ICE_PWD=$ice_pwd", $contents);
-$contents = preg_replace("/BIRDNETPI_URL=.*/", "BIRDNETPI_URL=$birdnetpi_url", $contents);
-$contents = preg_replace("/WEBTERMINAL_URL=.*/", "WEBTERMINAL_URL=$webterminal_url", $contents);
-$contents = preg_replace("/BIRDNETLOG_URL=.*/", "BIRDNETLOG_URL=$birdnetlog_url", $contents);
-$contents = preg_replace("/OVERLAP=.*/", "OVERLAP=$overlap", $contents);
-$contents = preg_replace("/CONFIDENCE=.*/", "CONFIDENCE=$confidence", $contents);
-$contents = preg_replace("/SENSITIVITY=.*/", "SENSITIVITY=$sensitivity", $contents);
-$contents = preg_replace("/FULL_DISK=.*/", "FULL_DISK=$full_disk", $contents);
-$contents = preg_replace("/REC_CARD=.*/", "REC_CARD=$rec_card", $contents);
-$contents = preg_replace("/CHANNELS=.*/", "CHANNELS=$channels", $contents);
-$contents = preg_replace("/RECORDING_LENGTH=.*/", "RECORDING_LENGTH=$recording_length", $contents);
-$contents = preg_replace("/EXTRACTION_LENGTH=.*/", "EXTRACTION_LENGTH=$extraction_length", $contents);
-
-$contents2 = file_get_contents("/home/pi/BirdNET-Pi/thisrun.txt");
-$contents2 = preg_replace("/CADDY_PWD=.*/", "CADDY_PWD=$caddy_pwd", $contents2);
-$contents2 = preg_replace("/DB_PWD=.*/", "DB_PWD=$db_pwd", $contents2);
-$contents2 = preg_replace("/ICE_PWD=.*/", "ICE_PWD=$ice_pwd", $contents2);
-$contents2 = preg_replace("/BIRDNETPI_URL=.*/", "BIRDNETPI_URL=$birdnetpi_url", $contents2);
-$contents2 = preg_replace("/WEBTERMINAL_URL=.*/", "WEBTERMINAL_URL=$webterminal_url", $contents2);
-$contents2 = preg_replace("/BIRDNETLOG_URL=.*/", "BIRDNETLOG_URL=$birdnetlog_url", $contents2);
-$contents2 = preg_replace("/OVERLAP=.*/", "OVERLAP=$overlap", $contents2);
-$contents2 = preg_replace("/CONFIDENCE=.*/", "CONFIDENCE=$confidence", $contents2);
-$contents2 = preg_replace("/SENSITIVITY=.*/", "SENSITIVITY=$sensitivity", $contents2);
-$contents2 = preg_replace("/FULL_DISK=.*/", "FULL_DISK=$full_disk", $contents2);
-$contents2 = preg_replace("/REC_CARD=.*/", "REC_CARD=$rec_card", $contents2);
-$contents2 = preg_replace("/CHANNELS=.*/", "CHANNELS=$channels", $contents2);
-$contents2 = preg_replace("/RECORDING_LENGTH=.*/", "RECORDING_LENGTH=$recording_length", $contents2);
-$contents2 = preg_replace("/EXTRACTION_LENGTH=.*/", "EXTRACTION_LENGTH=$extraction_length", $contents2);
-
-$fh = fopen("/home/pi/BirdNET-Pi/birdnet.conf", "w");
-$fh2 = fopen("/home/pi/BirdNET-Pi/thisrun.txt", "w");
-fwrite($fh, $contents);
-fwrite($fh2, $contents2);
-@session_start();
-
-if(true){
- $_SESSION['success'] = 1;
- header("Location:advanced.php");
-}
-?>
-