Skip to content

A live bird collage card for your Home Assistant dashboard.

Merge branch 'BirdNET-pi-main' into New-UI-API

jaredb7eee84587f975
diff --cc homepage/views.php
index fed2bcf9,e7537002..543f109c
--- a/homepage/views.php
+++ b/homepage/views.php
@@@ -118,6 -150,6 +118,8 @@@ if(isset($_GET['view']))
if($_GET['view'] == "Streamlit"){echo "<iframe src=\"/stats\"></iframe>";}
if($_GET['view'] == "Daily Charts"){include('history.php');}
if($_GET['view'] == "Tools"){
++ parseConfig();
++ //Authenticate before proceeding
$caddypwd = $config['CADDY_PWD'];
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
@@@ -209,7 -241,11 +211,8 @@@
echo "<iframe src='scripts/filemanager/filemanager.php'></iframe>";
}
if($_GET['view'] == "Webterm"){
- 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');
- }
+ parseConfig();
++ //Authenticate before proceeding
$caddypwd = $config['CADDY_PWD'];
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
@@@ -231,7 -267,11 +234,8 @@@
}
}
} elseif(isset($_GET['submit'])) {
- 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');
- }
+ parseConfig();
++ //Authenticate before proceeding
$caddypwd = $config['CADDY_PWD'];
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
@@@ -310,7 -341,7 +314,7 @@@
//explode the string by " " space so we can get each individual component of the command
//and eventually the service name at the end
$separate_command_tmp = explode(" ", trim($indiv_service_command));
- //get the service names so we can poll th status
- //get the service names
++ //get the service names so we can poll the status
$new_multiservice_status_command .= " " . trim(end($separate_command_tmp));
}
diff --cc scripts/config.php
index 9bb88585,ceb5e0aa..6c8deaca
--- a/scripts/config.php
+++ b/scripts/config.php
@@@ -1,10 -1,48 +1,34 @@@
<?php
-error_reporting(E_ERROR);
-ini_set('display_errors',1);
+if(file_exists('./scripts/common.php')){
+ include_once "./scripts/common.php";
+}else{
+ include_once "./common.php";
+
-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');
-}
-$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/apprise.txt")) {
- $apprise_config = file_get_contents($home."/BirdNET-Pi/apprise.txt");
-} else {
- $apprise_config = "";
-}
++//Parse the ini files to get the current config
++parseConfig();
++
++//Authenticate first before allowing further execution
+ $caddypwd = $config['CADDY_PWD'];
+ if (!isset($_SERVER['PHP_AUTH_USER'])) {
+ header('WWW-Authenticate: Basic realm="My Realm"');
+ header('HTTP/1.0 401 Unauthorized');
+ echo '<table><tr><td>You cannot edit the settings for this installation</td></tr></table>';
+ exit;
+ } else {
+ $submittedpwd = $_SERVER['PHP_AUTH_PW'];
+ $submitteduser = $_SERVER['PHP_AUTH_USER'];
+ if($submittedpwd !== $caddypwd || $submitteduser !== 'birdnet'){
+ header('WWW-Authenticate: Basic realm="My Realm"');
+ header('HTTP/1.0 401 Unauthorized');
+ echo '<table><tr><td>You cannot edit the settings for this installation</td></tr></table>';
+ exit;
+ }
}
-function syslog_shell_exec($cmd, $sudo_user = null) {
- if ($sudo_user) {
- $cmd = "sudo -u $sudo_user $cmd";
- }
- $output = shell_exec($cmd);
-
- if (strlen($output) > 0) {
- syslog(LOG_INFO, $output);
- }
-}
++//Authenticated
++//Read in the apprise config
++$apprise_config = getAppriseConfig();
+
if(isset($_GET['threshold'])) {
$threshold = $_GET['threshold'];
if (!is_numeric($threshold) || $threshold < 0 || $threshold > 1) {
@@@ -207,26 -323,8 +231,7 @@@ if(isset($_GET['sendtest']) && $_GET['s
<div class="settings">
<div class="brbanner"><h1>Basic Settings</h1></div><br>
<form id="basicform" action="" method="GET">
- <?php
- $apprise_config = getAppriseConfig();
- $caddypwd = $config['CADDY_PWD'];
- if (!isset($_SERVER['PHP_AUTH_USER'])) {
- header('WWW-Authenticate: Basic realm="My Realm"');
- header('HTTP/1.0 401 Unauthorized');
- echo '<table><tr><td>You cannot edit the settings for this installation</td></tr></table>';
- exit;
- } else {
- $submittedpwd = $_SERVER['PHP_AUTH_PW'];
- $submitteduser = $_SERVER['PHP_AUTH_USER'];
- if($submittedpwd !== $caddypwd || $submitteduser !== 'birdnet'){
- header('WWW-Authenticate: Basic realm="My Realm"');
- header('HTTP/1.0 401 Unauthorized');
- echo '<table><tr><td>You cannot edit the settings for this installation</td></tr></table>';
- exit;
- }
- }
- ?>
-
<script>
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('modelsel').addEventListener('change', function() {
diff --cc scripts/play.php
index e507ef81,0d3bb340..5b53d76f
--- a/scripts/play.php
+++ b/scripts/play.php
@@@ -64,14 -101,58 +64,36 @@@ $shifted_path = getDirectory('shifted_d
if(isset($_GET['shiftfile'])) {
- 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');
-}
-$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
-$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
-$home = trim($home);
++//Parse the ini files
++parseConfig();
++
++//Authenticate before going any further
+ $caddypwd = $config['CADDY_PWD'];
+ if (!isset($_SERVER['PHP_AUTH_USER'])) {
+ header('WWW-Authenticate: Basic realm="My Realm"');
+ header('HTTP/1.0 401 Unauthorized');
+ echo '<table><tr><td>You cannot shift files for this installation</td></tr></table>';
+ exit;
+ } else {
+ $submittedpwd = $_SERVER['PHP_AUTH_PW'];
+ $submitteduser = $_SERVER['PHP_AUTH_USER'];
+ if($submittedpwd !== $caddypwd || $submitteduser !== 'birdnet'){
+ header('WWW-Authenticate: Basic realm="My Realm"');
+ header('HTTP/1.0 401 Unauthorized');
+ echo '<table><tr><td>You cannot shift files for this installation<</td></tr></table>';
+ exit;
+ }
+ }
+
- $filename = $_GET['shiftfile'];
- $pp = pathinfo($filename);
- $dir = $pp['dirname'];
- $fn = $pp['filename'];
- $ext = $pp['extension'];
- $pi = $home."/BirdSongs/Extracted/By_Date/";
-
- if(isset($_GET['doshift'])) {
- $freqshift_tool = $config['FREQSHIFT_TOOL'];
-
- if ($freqshift_tool == "ffmpeg") {
- $cmd = "sudo /usr/bin/nohup /usr/bin/ffmpeg -y -i ".escapeshellarg($pi.$filename)." -af \"rubberband=pitch=".$config['FREQSHIFT_LO']."/".$config['FREQSHIFT_HI']."\" ".escapeshellarg($shifted_path.$filename)."";
- shell_exec("sudo mkdir -p ".$shifted_path.$dir." && ".$cmd);
-
- } else if ($freqshift_tool == "sox") {
- //linux.die.net/man/1/sox
- $soxopt = "-q";
- $soxpitch = $config['FREQSHIFT_PITCH'];
- $cmd = "sudo /usr/bin/nohup /usr/bin/sox ".escapeshellarg($pi.$filename)." ".escapeshellarg($shifted_path.$filename)." pitch ".$soxopt." ".$soxpitch;
- shell_exec("sudo mkdir -p ".$shifted_path.$dir." && ".$cmd);
- }
- } else {
- $cmd = "sudo rm -f " . escapeshellarg($shifted_path.$filename);
- shell_exec($cmd);
- }
++//Authenticated
+ $filename = $_GET['shiftfile'];
+ $doShift = null;
+ if (isset($_GET['doshift'])) {
+ $doShift = true;
+ }
- echo "OK";
+ $response_data = frequencyShiftDetectionAudio($filename, $doShift);
+ echo $response_data['message'];
die();
}
@@@ -393,25 -466,27 +415,25 @@@ $confidence = null
if(isset($_SESSION['date'])) {
$date = $_SESSION['date'];
if(isset($_GET['sort']) && $_GET['sort'] == "confidence") {
- $statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" AND Date == \"$date\" ORDER BY Confidence DESC");
- } else {
- $statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" AND Date == \"$date\" ORDER BY Time DESC");
+ $confidence = $_GET['sort'];
}
+ $result2_data = getSpeciesDetectionInfo($name, $date, $confidence);
} else {
if(isset($_GET['sort']) && $_GET['sort'] == "confidence") {
- $statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" ORDER BY Confidence DESC");
- } else {
- $statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" ORDER BY Date DESC, Time DESC");
+ $confidence = $_GET['sort'];
}
+ $result2_data = getSpeciesDetectionInfo($name, null, $confidence);
}
-if($statement2 == False){
- echo "Database is busy";
- header("refresh: 0;");
-}
-$result2 = $statement2->execute();
-$num_rows = 0;
-while ($result2->fetchArray(SQLITE3_ASSOC)) {
- $num_rows++;
+
- if ($result2_data['success'] == False) {
- echo $result2_data['message'];
- header("refresh: 0;");
- }
- $result2 = $result2_data['data'];
++if ($result2_data['success'] == False) {
++ echo $result2_data['message'];
++ header("refresh: 0;");
+ }
-$result2->reset(); // reset the pointer to the beginning of the result set
++$result2 = $result2_data['data'];
+
+//Count number of records we have
+$num_rows = count($result2);
+
echo "<table>
<tr>
<th>$name</th>