Skip to content

A live bird collage card for your Home Assistant dashboard.

Move remaining files to use new code

jaredb769c4a6d3b134
diff --git a/homepage/index.php b/homepage/index.php
index eeae4231..bfbd6fac 100644
--- a/homepage/index.php
+++ b/homepage/index.php
@@ -1,34 +1,10 @@
<?php
-$sys_timezone = "";
-// If we can get the timezome from the systems timezone file ust that
-if (file_exists('/etc/timezone')) {
- $tz_data = file_get_contents('/etc/timezone');
- if ($tz_data !== false) {
- $sys_timezone = trim($tz_data);
- }
-} else {
-// Else get timezone from the timedatectl command
- $tz_data = shell_exec('timedatectl show');
- $tz_data_array = parse_ini_string($tz_data);
- if (is_array($tz_data_array) && array_key_exists('Timezone', $tz_data_array)) {
- $sys_timezone = $tz_data_array['Timezone'];
- }
-}
-//Finally if we have a valod timezone, set it as the one PHP uses
-if ($sys_timezone !== "") {
- date_default_timezone_set($sys_timezone);
+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');
- }
- if($config["SITE_NAME"] == "") {
- $site_name = "BirdNET-Pi";
- } else {
- $site_name = $config['SITE_NAME'];
- }
?>
<title><?php echo $site_name; ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -53,11 +29,6 @@ echo "<a href=\"https://github.com/mcguirepr89/BirdNET-Pi.git\" target=\"_blank\
<div class="stream">
<?php
if(isset($_GET['stream'])){
- 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');
- }
$caddypwd = $config['CADDY_PWD'];
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
diff --git a/homepage/views.php b/homepage/views.php
index d4b45f33..fed2bcf9 100644
--- a/homepage/views.php
+++ b/homepage/views.php
@@ -6,6 +6,7 @@ if(file_exists('./scripts/common.php')){
}
session_start();
+
if(!isset($_SESSION['behind'])) {
$_SESSION['behind'] = getGitStatus();
if(isset($_SESSION['behind'])&&intval($_SESSION['behind']) >= 99) {?>
diff --git a/scripts/advanced.php b/scripts/advanced.php
index dd03e673..85cdbe5d 100644
--- a/scripts/advanced.php
+++ b/scripts/advanced.php
@@ -25,142 +25,142 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) {
if(isset($_GET['submit'])) {
if(isset($_GET["caddy_pwd"])) {
$caddy_pwd = $_GET["caddy_pwd"];
- setSetting('CADDY_PWD', "\"$caddy_pwd\"",'update_caddyfile');
+ saveSetting('CADDY_PWD', "\"$caddy_pwd\"",'update_caddyfile');
}
if(isset($_GET["ice_pwd"])) {
$ice_pwd = $_GET["ice_pwd"];
- setSetting('ICE_PWD', $ice_pwd);
+ saveSetting('ICE_PWD', $ice_pwd);
}
if(isset($_GET["birdnetpi_url"])) {
$birdnetpi_url = $_GET["birdnetpi_url"];
// remove trailing slash to prevent conf from becoming broken
$birdnetpi_url = rtrim($birdnetpi_url, '/');
- setSetting('BIRDNETPI_URL', $birdnetpi_url,'update_caddyfile');
+ saveSetting('BIRDNETPI_URL', $birdnetpi_url,'update_caddyfile');
}
if(isset($_GET["rtsp_stream"])) {
$rtsp_stream = str_replace("\r\n", ",", $_GET["rtsp_stream"]);
- setSetting('RTSP_STREAM', "\"$rtsp_stream\"", ['restart birdnet_recording', 'restart livestream']);
+ saveSetting('RTSP_STREAM', "\"$rtsp_stream\"", ['restart birdnet_recording', 'restart livestream']);
}
if (isset($_GET["rtsp_stream_to_livestream"])) {
$rtsp_stream_selected = trim($_GET["rtsp_stream_to_livestream"]);
- setSetting('RTSP_STREAM_TO_LIVESTREAM', "\"$rtsp_stream_selected\"", 'restart livestream');
+ saveSetting('RTSP_STREAM_TO_LIVESTREAM', "\"$rtsp_stream_selected\"", 'restart livestream');
}
if(isset($_GET["overlap"])) {
$overlap = $_GET["overlap"];
- setSetting('OVERLAP', $overlap);
+ saveSetting('OVERLAP', $overlap);
}
if(isset($_GET["confidence"])) {
$confidence = $_GET["confidence"];
- setSetting('CONFIDENCE', $confidence);
+ saveSetting('CONFIDENCE', $confidence);
}
if(isset($_GET["sensitivity"])) {
$sensitivity = $_GET["sensitivity"];
- setSetting('SENSITIVITY', $sensitivity);
+ saveSetting('SENSITIVITY', $sensitivity);
}
if(isset($_GET["freqshift_hi"]) && is_numeric($_GET['freqshift_hi'])) {
$freqshift_hi = $_GET["freqshift_hi"];
- setSetting('FREQSHIFT_HI', $freqshift_hi);
+ saveSetting('FREQSHIFT_HI', $freqshift_hi);
}
if(isset($_GET["freqshift_lo"]) && is_numeric($_GET['freqshift_lo'])) {
$freqshift_lo = $_GET["freqshift_lo"];
- setSetting('FREQSHIFT_HI', $freqshift_hi);
+ saveSetting('FREQSHIFT_HI', $freqshift_hi);
}
if(isset($_GET["freqshift_pitch"]) && is_numeric($_GET['freqshift_pitch'])) {
$freqshift_pitch = $_GET["freqshift_pitch"];
- setSetting('FREQSHIFT_PITCH', $freqshift_pitch);
+ saveSetting('FREQSHIFT_PITCH', $freqshift_pitch);
}
if(isset($_GET["freqshift_tool"])) {
$freqshift_tool = $_GET["freqshift_tool"];
- setSetting('FREQSHIFT_TOOL', $freqshift_tool);
+ saveSetting('FREQSHIFT_TOOL', $freqshift_tool);
}
if(isset($_GET["full_disk"])) {
$full_disk = $_GET["full_disk"];
- setSetting('FULL_DISK', $full_disk);
+ saveSetting('FULL_DISK', $full_disk);
}
if(isset($_GET["privacy_threshold"])) {
$privacy_threshold = $_GET["privacy_threshold"];
- setSetting('PRIVACY_THRESHOLD', $privacy_threshold,'restart_services');
+ saveSetting('PRIVACY_THRESHOLD', $privacy_threshold,'restart_services');
}
if(isset($_GET["rec_card"])) {
$rec_card = trim($_GET["rec_card"]);
- setSetting('REC_CARD', "\"$rec_card\"");
+ saveSetting('REC_CARD', "\"$rec_card\"");
}
if(isset($_GET["channels"])) {
$channels = $_GET["channels"];
- setSetting('CHANNELS', $channels);
+ saveSetting('CHANNELS', $channels);
}
if(isset($_GET["recording_length"])) {
$recording_length = $_GET["recording_length"];
- setSetting('RECORDING_LENGTH', $recording_length);
+ saveSetting('RECORDING_LENGTH', $recording_length);
}
if(isset($_GET["extraction_length"])) {
$extraction_length = $_GET["extraction_length"];
- setSetting('EXTRACTION_LENGTH', $extraction_length);
+ saveSetting('EXTRACTION_LENGTH', $extraction_length);
}
if(isset($_GET["audiofmt"])) {
$audiofmt = $_GET["audiofmt"];
- setSetting('AUDIOFMT', $audiofmt);
+ saveSetting('AUDIOFMT', $audiofmt);
}
if(isset($_GET["silence_update_indicator"])) {
$silence_update_indicator = 1;
- setSetting('SILENCE_UPDATE_INDICATOR', $silence_update_indicator);
+ saveSetting('SILENCE_UPDATE_INDICATOR', $silence_update_indicator);
} else {
- setSetting('SILENCE_UPDATE_INDICATOR', 0);
+ saveSetting('SILENCE_UPDATE_INDICATOR', 0);
}
if(isset($_GET["raw_spectrogram"])) {
$raw_spectrogram = 1;
- setSetting('RAW_SPECTROGRAM', $raw_spectrogram);
+ saveSetting('RAW_SPECTROGRAM', $raw_spectrogram);
} else {
- setSetting('RAW_SPECTROGRAM', 0);
+ saveSetting('RAW_SPECTROGRAM', 0);
}
if(isset($_GET["custom_image"])) {
$custom_image = $_GET["custom_image"];
- setSetting('CUSTOM_IMAGE', $custom_image);
+ saveSetting('CUSTOM_IMAGE', $custom_image);
}
if(isset($_GET["custom_image_label"])) {
$custom_image_label = $_GET["custom_image_label"];
- setSetting('CUSTOM_IMAGE_TITLE', "\"$custom_image_label\"");
+ saveSetting('CUSTOM_IMAGE_TITLE', "\"$custom_image_label\"");
}
if (isset($_GET["LogLevel_BirdnetRecordingService"])) {
$birdnet_recording_service_log_level = trim($_GET["LogLevel_BirdnetRecordingService"]);
- setSetting('LogLevel_BirdnetRecordingService', "\"$birdnet_recording_service_log_level\"",'restart birdnet_recording');
+ saveSetting('LogLevel_BirdnetRecordingService', "\"$birdnet_recording_service_log_level\"",'restart birdnet_recording');
}
if (isset($_GET["LogLevel_SpectrogramViewerService"])) {
$spectrogram_viewer_service_log_level = trim($_GET["LogLevel_SpectrogramViewerService"]);
- setSetting('LogLevel_SpectrogramViewerService', "\"$spectrogram_viewer_service_log_level\"",'restart spectrogram_viewer');
+ saveSetting('LogLevel_SpectrogramViewerService', "\"$spectrogram_viewer_service_log_level\"",'restart spectrogram_viewer');
}
if (isset($_GET["LogLevel_LiveAudioStreamService"])) {
$livestream_audio_service_log_level = trim($_GET["LogLevel_LiveAudioStreamService"]);
- setSetting('LogLevel_LiveAudioStreamService', "\"$livestream_audio_service_log_level\"",['restart livestream','restart icecast2']);
+ saveSetting('LogLevel_LiveAudioStreamService', "\"$livestream_audio_service_log_level\"",['restart livestream','restart icecast2']);
}
}
diff --git a/scripts/birdnetpi_request.php b/scripts/birdnetpi_request.php
index 968c1745..6cfa606e 100644
--- a/scripts/birdnetpi_request.php
+++ b/scripts/birdnetpi_request.php
@@ -1,10 +1,10 @@
<?php
-if (file_exists('thisrun.txt')) {
- $config = parse_ini_file('thisrun.txt');
-} elseif (file_exists('firstrun.ini')) {
- $config = parse_ini_file('firstrun.ini');
-}
-$template = file_get_contents("./scripts/email_template2");
+if(file_exists('./scripts/common.php')){
+ include_once "./scripts/common.php";
+}else{
+ include_once "./common.php";
+}
+$template = file_get_contents(getFilePath('email_template2'));
foreach($config as $key => $value)
{
diff --git a/scripts/birdweather_request.php b/scripts/birdweather_request.php
index a8b82ab3..add8e761 100644
--- a/scripts/birdweather_request.php
+++ b/scripts/birdweather_request.php
@@ -1,10 +1,10 @@
<?php
-if (file_exists('thisrun.txt')) {
- $config = parse_ini_file('thisrun.txt');
-} elseif (file_exists('firstrun.ini')) {
- $config = parse_ini_file('firstrun.ini');
-}
-$template = file_get_contents("./scripts/email_template");
+if(file_exists('./scripts/common.php')){
+ include_once "./scripts/common.php";
+}else{
+ include_once "./common.php";
+}
+$template = file_get_contents(getFilePath('email_template'));
foreach($config as $key => $value)
{
diff --git a/scripts/common.php b/scripts/common.php
index 1766e332..dbb14cf0 100644
--- a/scripts/common.php
+++ b/scripts/common.php
@@ -104,10 +104,6 @@ function connect_to_birdsdb()
try {
$DB_CONN = new SQLite3(getFilePath('birds.db'), SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
if ($DB_CONN == False) {
- if (!$api_incl) {
- echo "connect_to_birdsdb:: Database is busy";
- header("refresh: 0;");
- }
birdnet_error_log("connect_to_birdsdb:: birds.db database is busy");
}
} catch (Exception $sql_exec) {
@@ -445,10 +441,10 @@ function getDetectionsBySpecies($species_name = null, $sort = null)
//Rearrange data
$newReturnData = [];
- $newReturnData['species'] = $speciesDetections;
+ $newReturnData['species'] = $speciesDetections['data'];
//Check to see if we have to get max confidence results for the species also
if (isset($speciesDetections_MaxConf)) {
- $newReturnData['species_MaxConf'] = $speciesDetections_MaxConf;
+ $newReturnData['species_MaxConf'] = $speciesDetections_MaxConf['data'];
}
$speciesDetections['data'] = $newReturnData;
@@ -1040,9 +1036,9 @@ function getDirectory($dir)
} else if ($dir == "extracted") {
$extracted_dir_setting = $config['EXTRACTED'];
return getDirectory('recs_dir') . str_replace('${RECS_DIR}', '', $extracted_dir_setting);
- } elseif ($dir == "extracted_bydate") {
+ } elseif ($dir == "extracted_bydate" || $dir == "extracted_by_date") {
return getDirectory('extracted') . '/By_Date';
- } elseif ($dir == "shifted_audio") {
+ } elseif ($dir == "shifted_audio" || $dir == "shifted_dir") {
return getDirectory('home') . '/BirdSongs/Extracted/By_Date/shifted';
} elseif ($dir == "database") {
// NOT USED
@@ -1094,6 +1090,12 @@ function getFilePath($filename)
} else if ($filename == "disk_check_exclude.txt") {
return getDirectory('scripts') . "/disk_check_exclude.txt";
//
+ } else if ($filename == "email_template") {
+ return getDirectory('scripts') . "/email_template";
+ //
+ } else if ($filename == "email_template2") {
+ return getDirectory('scripts') . "/email_template2";
+ //
} else if ($filename == "exclude_species_list.txt") {
return getDirectory('scripts') . "/exclude_species_list.txt";
//
@@ -1149,7 +1151,7 @@ function getFilePath($filename)
* @param $post_save_command string CommaAnd to execute after saving
* @return void
*/
-function setSetting($setting_name, $setting_value, $post_save_command = null)
+function saveSetting($setting_name, $setting_value, $post_save_command = null)
{
global $config;
diff --git a/scripts/config.php b/scripts/config.php
index b73cb63b..9bb88585 100644
--- a/scripts/config.php
+++ b/scripts/config.php
@@ -95,24 +95,24 @@ if(isset($_GET["latitude"])){
changeLanguage($model, $language);
- setSetting('SITE_NAME', "\"$site_name\"");
- setSetting('LATITUDE', $latitude);
- setSetting('LONGITUDE', $longitude);
- setSetting('BIRDWEATHER_ID', $birdweather_id);
- setSetting('APPRISE_NOTIFICATION_TITLE', "\"$apprise_notification_title\"");
- setSetting('APPRISE_NOTIFICATION_BODY', "'$apprise_notification_body'");
- setSetting('APPRISE_NOTIFY_EACH_DETECTION', $apprise_notify_each_detection);
- setSetting('APPRISE_NOTIFY_NEW_SPECIES', $apprise_notify_new_species);
- setSetting('APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY', $apprise_notify_new_species_each_day);
- setSetting('APPRISE_WEEKLY_REPORT', $apprise_weekly_report);
- setSetting('FLICKR_API_KEY', $flickr_api_key);
- setSetting('DATABASE_LANG', $language);
- setSetting('FLICKR_FILTER_EMAIL', $flickr_filter_email);
- setSetting('APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES', $minimum_time_limit);
- setSetting('MODEL', $model);
- setSetting('SF_THRESH', $sf_thresh);
- setSetting('APPRISE_ONLY_NOTIFY_SPECIES_NAMES', "\"$only_notify_species_names\"");
- setSetting('APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2', "\"$only_notify_species_names_2\"");
+ saveSetting('SITE_NAME', "\"$site_name\"");
+ saveSetting('LATITUDE', $latitude);
+ saveSetting('LONGITUDE', $longitude);
+ saveSetting('BIRDWEATHER_ID', $birdweather_id);
+ saveSetting('APPRISE_NOTIFICATION_TITLE', "\"$apprise_notification_title\"");
+ saveSetting('APPRISE_NOTIFICATION_BODY', "'$apprise_notification_body'");
+ saveSetting('APPRISE_NOTIFY_EACH_DETECTION', $apprise_notify_each_detection);
+ saveSetting('APPRISE_NOTIFY_NEW_SPECIES', $apprise_notify_new_species);
+ saveSetting('APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY', $apprise_notify_new_species_each_day);
+ saveSetting('APPRISE_WEEKLY_REPORT', $apprise_weekly_report);
+ saveSetting('FLICKR_API_KEY', $flickr_api_key);
+ saveSetting('DATABASE_LANG', $language);
+ saveSetting('FLICKR_FILTER_EMAIL', $flickr_filter_email);
+ saveSetting('APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES', $minimum_time_limit);
+ saveSetting('MODEL', $model);
+ saveSetting('SF_THRESH', $sf_thresh);
+ saveSetting('APPRISE_ONLY_NOTIFY_SPECIES_NAMES', "\"$only_notify_species_names\"");
+ saveSetting('APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2', "\"$only_notify_species_names_2\"");
if($site_name != $config["SITE_NAME"]) {
diff --git a/scripts/history.php b/scripts/history.php
index 27f44482..b59b870a 100644
--- a/scripts/history.php
+++ b/scripts/history.php
@@ -1,5 +1,9 @@
<?php
-include_once "./scripts/common.php";
+if(file_exists('./scripts/common.php')){
+ include_once "./scripts/common.php";
+}else{
+ include_once "./common.php";
+}
if(isset($_GET['date'])){
$theDate = $_GET['date'];
@@ -23,10 +27,6 @@ if(isset($_GET['blocation']) ) {
header("Expires: 0");
- $user = trim(shell_exec("awk -F: '/1000/{print $1}' /etc/passwd"));
- $home = trim(shell_exec("awk -F: '/1000/{print $6}' /etc/passwd"));
-
-
//$sunrise = date_sunrise(time(), SUNFUNCS_RET_TIMESTAMP, $config["LATITUDE"], $config["LONGITUDE"]);
//$sunset = date_sunset(time(), SUNFUNCS_RET_TIMESTAMP, $config["LATITUDE"], $config["LONGITUDE"]);
diff --git a/scripts/include_list.php b/scripts/include_list.php
index 77c6b3f2..ac789901 100644
--- a/scripts/include_list.php
+++ b/scripts/include_list.php
@@ -44,7 +44,7 @@ $eachlines = file($filename, FILE_IGNORE_NEW_LINES);
<select name="species[]" id="value2" multiple size="30">
<option selected value="base">Please Select</option>
<?php
- $filename = getFilePath('include_species_list');
+ $filename = getFilePath('include_species_list.txt');
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
foreach($eachlines as $lines){echo
"<option value=\"".$lines."\">$lines</option>";}
diff --git a/scripts/overview.php b/scripts/overview.php
index 848a025c..7a34e582 100644
--- a/scripts/overview.php
+++ b/scripts/overview.php
@@ -1,32 +1,13 @@
<?php
-include_once "./scripts/common.php";
-
-//error_reporting(E_ERROR);
-//ini_set('display_errors',1);
-//ini_set('session.gc_maxlifetime', 7200);
-//ini_set('user_agent', 'PHP_Flickr/1.0');
-//session_set_cookie_params(7200);
-//session_start();
+if(file_exists('./scripts/common.php')){
+ include_once "./scripts/common.php";
+}else{
+ include_once "./common.php";
+}
$myDate = date('Y-m-d');
$chart = "Combo-$myDate.png";
-//$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
-//if($db == False) {
-// echo "Database is busy";
-// header("refresh: 0;");
-//}
-//
-//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);
-
$todaycount_data = getDetectionCountToday();
if($todaycount_data['success'] == False){
@@ -109,7 +90,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse
echo $comname . "," . $filename;
die();
}
-
+ //Because the spectrogram image exists for this detection it's been processed
$processed_detections++;
//Get the flickr image for this detection
@@ -167,13 +148,13 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse
</table> <?php break;
}
}
- if($processed_detections == 0) {
if($todaycount['COUNT(*)'] > 0) {
- echo "<h3>Your system is currently processing a backlog of audio. This can take several hours before normal functionality of your BirdNET-Pi resumes.</h3>";
+ if($processed_detections == 0) {
+ echo "<h3>Your system is currently processing a backlog of audio. This can take several hours before normal functionality of your BirdNET-Pi resumes.</h3>";
+ }
} else {
echo "<h3>No Detections For Today.</h3>";
}
- }
die();
}
diff --git a/scripts/play.php b/scripts/play.php
index a47d8c8e..7a48b4c7 100644
--- a/scripts/play.php
+++ b/scripts/play.php
@@ -1,5 +1,9 @@
<?php
-include_once "./scripts/common.php";
+if(file_exists('./scripts/common.php')){
+ include_once "./scripts/common.php";
+}else{
+ include_once "./common.php";
+}
if(isset($_GET['deletefile'])) {
if(isset($_SERVER['PHP_AUTH_USER'])) {
@@ -56,7 +60,7 @@ if(isset($_GET['excludefile'])) {
}
}
-$shifted_path = $home."/BirdSongs/Extracted/By_Date/shifted/";
+$shifted_path = getDirectory('shifted_dir');
if(isset($_GET['shiftfile'])) {
@@ -261,7 +265,7 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){
if($view == "bydate") {
foreach ($result as $bd_result){
$date = $bd_result['Date'];
- if(realpath($home."/BirdSongs/Extracted/By_Date/".$date) !== false){
+ if(realpath(getDirectory('extracted_by_date') . "/" . $date) !== false){
echo "<td>
<button action=\"submit\" name=\"date\" value=\"$date\">".($date == date('Y-m-d') ? "Today" : $date)."</button></td></tr>";}
}
@@ -304,7 +308,7 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){
$birds = array();
foreach ($result as $species_bird_name) {
$name = $species_bird_name['Com_Name'];
- if (realpath($home . "/BirdSongs/Extracted/By_Date/" . $date . "/" . str_replace(" ", "_", $name)) !== false) {
+ if (realpath(getDirectory('extracted_by_date') . "/" . $date . "/" . str_replace(" ", "_", $name)) !== false) {
$birds[] = $name;
}
}
@@ -367,10 +371,11 @@ if(isset($_GET['species'])){ ?>
</form>
</div>
<?php
+ $disk_check_exclude_path = getFilePath('disk_check_exclude.txt');
// add disk_check_exclude.txt lines into an array for grepping
- $fp = @fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", 'r');
+ $fp = @fopen($disk_check_exclude_path, 'r');
if ($fp) {
- $disk_check_exclude_arr = explode("\n", fread($fp, filesize($home."/BirdNET-Pi/scripts/disk_check_exclude.txt")));
+ $disk_check_exclude_arr = explode("\n", fread($fp, filesize($disk_check_exclude_path)));
}
$name = $_GET['species'];
@@ -419,7 +424,7 @@ echo "<table>
$iter++;
// file was deleted by disk check, no need to show the detection in recordings
- if(!file_exists($home."/BirdSongs/Extracted/".$filename)) {
+ if(!file_exists(getDirectory('extracted') . "/" . $filename)) {
continue;
}
if(!in_array($filename_formatted, $disk_check_exclude_arr) && isset($_GET['only_excluded'])) {
@@ -476,7 +481,8 @@ echo "<table>
}if($iter == 0){ echo "<tr><td><b>No recordings were found.</b><br><br><span style='font-size:medium'>They may have been deleted to make space for new recordings. You can prevent this from happening in the future by clicking the <img src='images/unlock.svg' style='width:20px'> icon in the top right of a recording.<br>You can also modify this behavior globally under \"Full Disk Behavior\" <a href='views.php?view=Advanced'>here.</a></span></td></tr>";}echo "</table>";}
if(isset($_GET['filename'])){
- $name = $_GET['filename'];
+ $disk_check_exclude_path = getFilePath('disk_check_exclude.txt');
+ $name = $_GET['filename'];
$result2_data = getDetectionsByFilename($name);
if($result2_data['success'] == False){
echo $result2_data['message'];
@@ -502,9 +508,9 @@ echo "<table>
$filename_formatted = $date."/".$comname."/".$results['File_Name'];
// add disk_check_exclude.txt lines into an array for grepping
- $fp = @fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", 'r');
+ $fp = @fopen($disk_check_exclude_path, 'r');
if ($fp) {
- $disk_check_exclude_arr = explode("\n", fread($fp, filesize($home."/BirdNET-Pi/scripts/disk_check_exclude.txt")));
+ $disk_check_exclude_arr = explode("\n", fread($fp, filesize($disk_check_exclude_path)));
}
if($config["FULL_DISK"] == "purge") {
diff --git a/scripts/spectrogram.php b/scripts/spectrogram.php
index 9bbbbccc..f03e485e 100644
--- a/scripts/spectrogram.php
+++ b/scripts/spectrogram.php
@@ -1,22 +1,14 @@
<?php
-error_reporting(E_ERROR);
-ini_set('display_errors',1);
-
-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');
+if(file_exists('./scripts/common.php')){
+ include_once "./scripts/common.php";
+}else{
+ include_once "./common.php";
}
if(isset($_GET['ajax_csv'])) {
$RECS_DIR = $config["RECS_DIR"];
-
-$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
-$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
-$home = trim($home);
-
//Replace variables to Fix up the file paths just in case the ENV environment variables don't resolve via PHP
-$RECS_DIR = str_replace("\$HOME", $home, $RECS_DIR);
+$RECS_DIR = str_replace("\$HOME", getDirectory('home'), $RECS_DIR);
$STREAM_DATA_DIR = $RECS_DIR . "/StreamData/";
//Try find the latest file out of the soundcard recording folder
@@ -144,12 +136,7 @@ window.onload = function(){
document.body.querySelector('h1').remove();
document.getElementsByClassName("centered")[0].remove()
- <?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');
- }
+ <?php
$refresh = $config['RECORDING_LENGTH'];
$time = time();
?>
@@ -432,15 +419,7 @@ h1 {
//maybe the list of streams has been modified
//This isn't the ideal for this, but needed a way to fix this setting without calling the advanced setting page
if (array_key_exists($config['RTSP_STREAM_TO_LIVESTREAM'], $RTSP_Stream_Config) === false) {
- $contents = file_get_contents('/etc/birdnet/birdnet.conf');
- $contents2 = file_get_contents('./scripts/thisrun.txt');
- $contents = preg_replace("/RTSP_STREAM_TO_LIVESTREAM=.*/", "RTSP_STREAM_TO_LIVESTREAM=\"0\"", $contents);
- $contents2 = preg_replace("/RTSP_STREAM_TO_LIVESTREAM=.*/", "RTSP_STREAM_TO_LIVESTREAM=\"0\"", $contents2);
- $fh = fopen("/etc/birdnet/birdnet.conf", "w");
- $fh2 = fopen("./scripts/thisrun.txt", "w");
- fwrite($fh, $contents);
- fwrite($fh2, $contents2);
- exec("sudo systemctl restart livestream.service");
+ saveSetting('RTSP_STREAM_TO_LIVESTREAM',"\"0\"",'restart livestream"');
}
//Print out the dropdown list for the RTSP streams
diff --git a/scripts/stats.php b/scripts/stats.php
index 6c240f36..9a818427 100644
--- a/scripts/stats.php
+++ b/scripts/stats.php
@@ -1,31 +1,14 @@
<?php
-include_once "./scripts/common.php";
-
-//$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
-//if($db == False) {
-// echo "Database busy";
-// header("refresh: 0;");
-//}
+if(file_exists('./scripts/common.php')){
+ include_once "./scripts/common.php";
+}else{
+ include_once "./common.php";
+}
+$disk_check_exclude_path = getFilePath('disk_check_exclude.txt');
if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {
-
-// $statement = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');
-// if($statement == False) {
-// echo "Database busy";
-// header("refresh: 0;");
-// }
-// $result = $statement->execute();
-//
-// $statement2 = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');
-// if($statement == False) {
-// echo "Database busy";
-// header("refresh: 0;");
-// }
-//
-// $result2 = $statement2->execute();
-
- $sort = "occurrences";
+ $sort = "occurrences";
$result2_data = getSpeciesBestRecordingList($sort);
if ($result2_data['success'] == False) {
@@ -34,21 +17,6 @@ if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {
}
$result2 = $result2_data['data'];
} else {
-
-// $statement = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY Com_Name ASC');
-// if($statement == False) {
-// echo "Database busy";
-// header("refresh: 0;");
-// }
-// $result = $statement->execute();
-//
-// $statement2 = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY Com_Name ASC');
-// if($statement == False) {
-// echo "Database busy";
-// header("refresh: 0;");
-// }
-// $result2 = $statement2->execute();
-
$result2_data = getSpeciesBestRecordingList();
if ($result2_data['success'] == False) {
@@ -62,12 +30,6 @@ if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {
if(isset($_GET['species'])){
$selection = $_GET['species'];
-// $statement3 = $db->prepare("SELECT Com_Name, Sci_Name, COUNT(*), MAX(Confidence), File_Name, Date, Time from detections WHERE Com_Name = \"$selection\"");
-// if($statement3 == False) {
-// echo "Database busy";
-// header("refresh: 0;");
-// }
-// $result3 = $statement3->execute();
$result3_data = getBestRecordingsForSpecies($selection);
if($result3_data['success'] == False){
echo $result3_data['message'];
@@ -76,12 +38,9 @@ if(isset($_GET['species'])){
$result3 = $result3_data['data'];
}
-//$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");
+if(!file_exists($disk_check_exclude_path) || strpos(file_get_contents($disk_check_exclude_path),"##start") === false) {
+ file_put_contents($disk_check_exclude_path, "");
+ file_put_contents($disk_check_exclude_path, "##start\n##end\n");
}
?>
@@ -276,8 +235,8 @@ array_push($excludelines, $results['Date']."/".$comname."/".$results['File_Name'
<?php
}
-$file = file_get_contents(getDirectory('home')."/BirdNET-Pi/scripts/disk_check_exclude.txt");
-file_put_contents(getDirectory('home')."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start"."\n".implode("\n",$excludelines)."\n".substr($file, strpos($file, "##end")));
+$file = file_get_contents($disk_check_exclude_path);
+file_put_contents($disk_check_exclude_path, "##start"."\n".implode("\n",$excludelines)."\n".substr($file, strpos($file, "##end")));
?>
</table>
</form>
diff --git a/scripts/weekly_report.php b/scripts/weekly_report.php
index b5ad3445..fe74108c 100644
--- a/scripts/weekly_report.php
+++ b/scripts/weekly_report.php
@@ -1,5 +1,9 @@
<?php
-include_once "./scripts/common.php";
+if(file_exists('./scripts/common.php')){
+ include_once "./scripts/common.php";
+}else{
+ include_once "./common.php";
+}
$startdate = strtotime('last sunday') - (7*86400);
$enddate = strtotime('last sunday') - (1*86400);
@@ -7,13 +11,6 @@ $enddate = strtotime('last sunday') - (1*86400);
$debug = false;
if(isset($_GET['ascii'])) {
-
- $db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
- if($db == False){
- echo "Database is busy";
- header("refresh: 0;");
- }
-
$weekly_species_counts = getWeeklyReportSpeciesDetectionCounts();
if($weekly_species_counts['detections']['success'] == False){