diff --git a/config/filepath_map.json b/config/filepath_map.json new file mode 100644 index 0000000..15c0062 --- /dev/null +++ b/config/filepath_map.json @@ -0,0 +1,280 @@ +{ + "directories": { + "home": { + "description": "The home path for the user with User ID of 1000, this is normally the 'pi' user", + "read_setting": null, + "return_var": "home" + }, + "birdnet-pi": { + "alias_for": "birdnet_pi" + }, + "birdnet_pi": { + "description": "The root directory of the BirdNET-pi install", + "lives_under": "home", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/BirdNET-Pi", + "return_var": "" + }, + "recs_dir": { + "alias_for": "recordings_dir" + }, + "recordings_dir": { + "description": "The recording directory as specified in the config file (default: BirdSongs)", + "lives_under": "home", + "read_setting": "RECS_DIR", + "replace_setting_text": "$HOME", + "replace_setting_text_with": "", + "append": "" + }, + "processed": { + "description": "The directory which holds the recordings that have been processed", + "lives_under": "recordings_dir", + "read_setting": "PROCESSED", + "replace_setting_text": "${RECS_DIR}", + "replace_setting_text_with": "", + "append": "" + }, + "extracted": { + "description": "The directory which holds the extraction related data from detections", + "lives_under": "recordings_dir", + "read_setting": "EXTRACTED", + "replace_setting_text": "${RECS_DIR}", + "replace_setting_text_with": "", + "append": "" + }, + "extracted_bydate": { + "alias_for": "extracted_by_date" + }, + "extracted_by_date": { + "description": "The directory which holds the the extractions from detections as folders by date", + "lives_under": "extracted", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/By_Date" + }, + "extracted_charts": { + "description": "The directory which holds the spectrogram charts for detections", + "lives_under": "extracted", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/Charts" + }, + "shifted_dir": { + "alias_for": "shifted_audio" + }, + "shifted_audio": { + "description": "The directory which stores any frequency shifted audio", + "lives_under": "extracted_by_date", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/shifted" + }, + "database": { + "description": "**NOT CURRENTLY USED** The directory which holds files related to the detections database", + "lives_under": "birdnet_pi", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/database" + }, + "config": { + "description": "The directory which holds configuration files for BirdNET-pi", + "lives_under": "birdnet_pi", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/config" + }, + "models": { + "alias_for": "model" + }, + "model": { + "description": "The directory which holds AI detection models", + "lives_under": "birdnet_pi", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/model" + }, + "python3_ve": { + "description": "The directory which contains the Python 3 Virtual Environment", + "lives_under": "birdnet_pi", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/birdnet\/bin" + }, + "scripts": { + "description": "The directory which contains the script files like PHP and Shell scripts", + "lives_under": "birdnet_pi", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/scripts" + }, + "stream_data": { + "description": "The directory which contains the recordings from RTSP streams", + "lives_under": "recordings_dir", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/StreamData" + }, + "templates": { + "description": "The directory which contains the templates, like html, CRON script templates", + "lives_under": "birdnet_pi", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/templates" + }, + "www": { + "alias_for": "web" + }, + "web": { + "description": "The directory which any files related to generating the Web UI, index.php, views.php, stylesheets etc", + "lives_under": "birdnet_pi", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/homepage" + }, + "www_fonts": { + "alias_for": "web_fonts" + }, + "web_fonts": { + "description": "The directory which any fonts used by the WebUI or Python scripts", + "lives_under": "www", + "read_setting": "", + "replace_setting_text": "", + "replace_setting_text_with": "", + "append": "\/static" + } + }, + "files": { + "analyzing_now.txt": { + "lives_under": "birdnet_pi", + "append": "\/analyzing_now.txt" + }, + "apprise.txt": { + "lives_under": "birdnet_pi", + "append": "\/apprise.txt" + }, + "birdnet.conf": { + "lives_under": "birdnet_pi", + "append": "\/birdnet.conf" + }, + "etc_birdnet.conf": { + "lives_under": "", + "append": "", + "return_var": "\/etc\/birdnet\/birdnet.conf" + }, + "BirdDB.txt": { + "lives_under": "birdnet_pi", + "append": "\/BirdDB.txt" + }, + "birds.db": { + "lives_under": "scripts", + "append": "\/birds.db" + }, + "blacklisted_images.txt": { + "lives_under": "scripts", + "append": "\/blacklisted_images.txt" + }, + "disk_check_exclude.txt": { + "lives_under": "scripts", + "append": "\/disk_check_exclude.txt" + }, + "email_template": { + "lives_under": "scripts", + "append": "\/email_template" + }, + "email_template2": { + "lives_under": "scripts", + "append": "\/email_template2" + }, + "exclude_species_list.txt": { + "lives_under": "scripts", + "append": "\/exclude_species_list.txt" + }, + "filepath_map.json": { + "lives_under": "config", + "append": "\/filepath_map.json" + }, + "firstrun.ini": { + "lives_under": "birdnet_pi", + "append": "\/firstrun.ini" + }, + ".gotty": { + "lives_under": "home", + "append": "\/.gotty" + }, + "HUMAN.txt": { + "lives_under": "birdnet_pi", + "append": "\/HUMAN.txt" + }, + "IDFILE": { + "alias_for": "IdentifiedSoFar.txt" + }, + "IdentifiedSoFar.txt": { + "lives_under": "home", + "read_setting": "IDFILE", + "replace_setting_text": "$HOME", + "replace_setting_text_with": "", + "append": "" + }, + "include_species_list.txt": { + "lives_under": "scripts", + "append": "\/include_species_list.txt" + }, + "labels.txt": { + "lives_under": "model", + "append": "\/labels.txt" + }, + "labels.txt.old": { + "lives_under": "model", + "append": "\/labels.txt.old" + }, + "labels_flickr.txt": { + "lives_under": "model", + "append": "\/labels_flickr.txt" + }, + "labels_lang.txt": { + "lives_under": "model", + "append": "\/labels_lang.txt" + }, + "labels_l18n.zip": { + "lives_under": "model", + "append": "\/labels_l18n.zip" + }, + "labels_nm.zip": { + "lives_under": "model", + "append": "\/labels_nm.zip" + }, + "lastrun.txt": { + "lives_under": "scripts", + "append": "\/lastrun.txt" + }, + "python3": { + "lives_under": "python3_ve", + "append": "\/python3 " + }, + "python3_appraise": { + "lives_under": "python3_ve", + "append": "\/apprise " + }, + "species.py": { + "lives_under": "scripts", + "append": "\/species.py" + }, + "thisrun.txt": { + "lives_under": "scripts", + "append": "\/thisrun.txt" + } + } +} \ No newline at end of file diff --git a/config/generate_filepath_map_file.php b/config/generate_filepath_map_file.php new file mode 100644 index 0000000..06cfbdb --- /dev/null +++ b/config/generate_filepath_map_file.php @@ -0,0 +1,327 @@ + "The home path for the user with User ID of 1000, this is normally the 'pi' user", + 'read_setting' => null, + 'return_var' => 'home' +); + + +$file_path_map_array['directories']['birdnet-pi'] = array('alias_for' => 'birdnet_pi'); +$file_path_map_array['directories']['birdnet_pi'] = array( + 'description' => "The root directory of the BirdNET-pi install", + 'lives_under' => 'home', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/BirdNET-Pi', + 'return_var' => '' +); + + +$file_path_map_array['directories']['recs_dir'] = array('alias_for' => 'recordings_dir'); +$file_path_map_array['directories']['recordings_dir'] = array( + 'description' => "The recording directory as specified in the config file (default: BirdSongs)", + 'lives_under' => 'home', + 'read_setting' => 'RECS_DIR', + 'replace_setting_text' => '$HOME', + 'replace_setting_text_with' => '', + 'append' => '', +); + + +$file_path_map_array['directories']['processed'] = array( + 'description' => "The directory which holds the recordings that have been processed", + 'lives_under' => 'recordings_dir', + 'read_setting' => 'PROCESSED', + 'replace_setting_text' => '${RECS_DIR}', + 'replace_setting_text_with' => '', + 'append' => '', +); + + +$file_path_map_array['directories']['extracted'] = array( + 'description' => "The directory which holds the extraction related data from detections", + 'lives_under' => 'recordings_dir', + 'read_setting' => 'EXTRACTED', + 'replace_setting_text' => '${RECS_DIR}', + 'replace_setting_text_with' => '', + 'append' => '', +); + + +$file_path_map_array['directories']['extracted_bydate'] = array('alias_for' => 'extracted_by_date'); +$file_path_map_array['directories']['extracted_by_date'] = array( + 'description' => "The directory which holds the the extractions from detections as folders by date", + 'lives_under' => 'extracted', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/By_Date', +); + + +$file_path_map_array['directories']['extracted_charts'] = array( + 'description' => "The directory which holds the spectrogram charts for detections", + 'lives_under' => 'extracted', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/Charts', +); + +$file_path_map_array['directories']['shifted_dir'] = array('alias_for' => 'shifted_audio'); +$file_path_map_array['directories']['shifted_audio'] = array( + 'description' => "The directory which stores any frequency shifted audio", + 'lives_under' => 'extracted_by_date', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/shifted', +); + + +$file_path_map_array['directories']['database'] = array( + 'description' => "**NOT CURRENTLY USED** The directory which holds files related to the detections database", + 'lives_under' => 'birdnet_pi', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/database', +); + +$file_path_map_array['directories']['config'] = array( + 'description' => "The directory which holds configuration files for BirdNET-pi", + 'lives_under' => 'birdnet_pi', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/config', +); + +$file_path_map_array['directories']['models'] = array('alias_for' => 'model'); +$file_path_map_array['directories']['model'] = array( + 'description' => "The directory which holds AI detection models", + 'lives_under' => 'birdnet_pi', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/model', +); + +$file_path_map_array['directories']['python3_ve'] = array( + 'description' => "The directory which contains the Python 3 Virtual Environment", + 'lives_under' => 'birdnet_pi', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/birdnet/bin', +); + +$file_path_map_array['directories']['scripts'] = array( + 'description' => "The directory which contains the script files like PHP and Shell scripts", + 'lives_under' => 'birdnet_pi', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/scripts', +); + +$file_path_map_array['directories']['stream_data'] = array( + 'description' => "The directory which contains the recordings from RTSP streams", + 'lives_under' => 'recordings_dir', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/StreamData', +); + +$file_path_map_array['directories']['templates'] = array( + 'description' => "The directory which contains the templates, like html, CRON script templates", + 'lives_under' => 'birdnet_pi', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/templates', +); + +$file_path_map_array['directories']['www'] = array('alias_for' => 'web'); +$file_path_map_array['directories']['web'] = array( + 'description' => "The directory which any files related to generating the Web UI, index.php, views.php, stylesheets etc", + 'lives_under' => 'birdnet_pi', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/homepage', +); + +$file_path_map_array['directories']['www_fonts'] = array('alias_for' => 'web_fonts'); +$file_path_map_array['directories']['web_fonts'] = array( + 'description' => "The directory which any fonts used by the WebUI or Python scripts", + 'lives_under' => 'www', + 'read_setting' => '', + 'replace_setting_text' => '', + 'replace_setting_text_with' => '', + 'append' => '/static', +); + + +############################ +# FILE PATH DECLARATIONS +############################ +$file_path_map_array['files']['analyzing_now.txt'] = array( + 'lives_under' => 'birdnet_pi', + 'append' => '/analyzing_now.txt' +); + +$file_path_map_array['files']['apprise.txt'] = array( + 'lives_under' => 'birdnet_pi', + 'append' => '/apprise.txt' +); + +$file_path_map_array['files']['birdnet.conf'] = array( + 'lives_under' => 'birdnet_pi', + 'append' => '/birdnet.conf' +); + +$file_path_map_array['files']['etc_birdnet.conf'] = array( + 'lives_under' => '', + 'append' => '', + 'return_var' => '/etc/birdnet/birdnet.conf' +); + +$file_path_map_array['files']['BirdDB.txt'] = array( + 'lives_under' => 'birdnet_pi', + 'append' => '/BirdDB.txt', +); + +$file_path_map_array['files']['birds.db'] = array( + 'lives_under' => 'scripts', + 'append' => '/birds.db', +); + +$file_path_map_array['files']['blacklisted_images.txt'] = array( + 'lives_under' => 'scripts', + 'append' => '/blacklisted_images.txt', +); + +$file_path_map_array['files']['disk_check_exclude.txt'] = array( + 'lives_under' => 'scripts', + 'append' => '/disk_check_exclude.txt', +); + +$file_path_map_array['files']['email_template'] = array( + 'lives_under' => 'scripts', + 'append' => '/email_template', +); + +$file_path_map_array['files']['email_template2'] = array( + 'lives_under' => 'scripts', + 'append' => '/email_template2', +); + +$file_path_map_array['files']['exclude_species_list.txt'] = array( + 'lives_under' => 'scripts', + 'append' => '/exclude_species_list.txt', +); + +$file_path_map_array['files']['filepath_map.json'] = array( + 'lives_under' => 'config', + 'append' => '/filepath_map.json', +); + +$file_path_map_array['files']['firstrun.ini'] = array( + 'lives_under' => 'birdnet_pi', + 'append' => '/firstrun.ini', +); + +$file_path_map_array['files']['.gotty'] = array( + 'lives_under' => 'home', + 'append' => '/.gotty', +); + +$file_path_map_array['files']['HUMAN.txt'] = array( + 'lives_under' => 'birdnet_pi', + 'append' => '/HUMAN.txt', +); + +$file_path_map_array['files']['IDFILE'] = array('alias_for' => 'IdentifiedSoFar.txt'); +$file_path_map_array['files']['IdentifiedSoFar.txt'] = array( + 'lives_under' => 'home', + 'read_setting' => 'IDFILE', + 'replace_setting_text' => '$HOME', + 'replace_setting_text_with' => '', + 'append' => '', +); + +$file_path_map_array['files']['include_species_list.txt'] = array( + 'lives_under' => 'scripts', + 'append' => '/include_species_list.txt', +); + +$file_path_map_array['files']['labels.txt'] = array( + 'lives_under' => 'model', + 'append' => '/labels.txt', +); + +$file_path_map_array['files']['labels.txt.old'] = array( + 'lives_under' => 'model', + 'append' => '/labels.txt.old', +); + +$file_path_map_array['files']['labels_flickr.txt'] = array( + 'lives_under' => 'model', + 'append' => '/labels_flickr.txt', +); + +$file_path_map_array['files']['labels_lang.txt'] = array( + 'lives_under' => 'model', + 'append' => '/labels_lang.txt', +); + +$file_path_map_array['files']['labels_l18n.zip'] = array( + 'lives_under' => 'model', + 'append' => '/labels_l18n.zip', +); + +$file_path_map_array['files']['labels_nm.zip'] = array( + 'lives_under' => 'model', + 'append' => '/labels_nm.zip', +); + + +$file_path_map_array['files']['lastrun.txt'] = array( + 'lives_under' => 'scripts', + 'append' => '/lastrun.txt', +); + + +$file_path_map_array['files']['python3'] = array( + 'lives_under' => 'python3_ve', + 'append' => '/python3 ', +); + +$file_path_map_array['files']['python3_appraise'] = array( + 'lives_under' => 'python3_ve', + 'append' => '/apprise ', +); + +$file_path_map_array['files']['species.py'] = array( + 'lives_under' => 'scripts', + 'append' => '/species.py', +); + +$file_path_map_array['files']['thisrun.txt'] = array( + 'lives_under' => 'scripts', + 'append' => '/thisrun.txt', +); + +//Output array as JSON and pretty print it +file_put_contents('./filepath_map.json', json_encode($file_path_map_array, JSON_PRETTY_PRINT)); \ No newline at end of file diff --git a/homepage/index.php b/homepage/index.php index eeae423..e4e51b1 100644 --- a/homepage/index.php +++ b/homepage/index.php @@ -1,34 +1,10 @@ <?php echo $site_name; ?> @@ -53,33 +29,14 @@ echo "

$site_name

"; - } else { - header('WWW-Authenticate: Basic realm="My Realm"'); - header('HTTP/1.0 401 Unauthorized'); - echo 'You cannot listen to the live audio stream'; - exit; - } - } + } } else { echo "
diff --git a/homepage/views.php b/homepage/views.php index e753700..235676f 100644 --- a/homepage/views.php +++ b/homepage/views.php @@ -1,42 +1,14 @@ &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)) { - $num_commits_behind = $matches[1]; - $_SESSION['behind'] = $num_commits_behind; - } - if (preg_match('/\b(\d+)\b and \b(\d+)\b different commits each/', $str, $matches)) { - $num1 = (int) $matches[1]; - $num2 = (int) $matches[2]; - $sum = $num1 + $num2; - $_SESSION['behind'] = $sum; - } + $_SESSION['behind'] = getGitStatus(); if(isset($_SESSION['behind'])&&intval($_SESSION['behind']) >= 99) {?> WARNING: Your latitude and longitude are not set properly. Please do so now in Tools -> Settings."; @@ -150,18 +118,11 @@ if(isset($_GET['view'])){ if($_GET['view'] == "Streamlit"){echo "";} if($_GET['view'] == "Daily Charts"){include('history.php');} if($_GET['view'] == "Tools"){ - $caddypwd = $config['CADDY_PWD']; - if (!isset($_SERVER['PHP_AUTH_USER'])) { - header('WWW-Authenticate: Basic realm="My Realm"'); - header('HTTP/1.0 401 Unauthorized'); - echo '
You cannot edit the settings for this installation
'; - exit; - } else { - $submittedpwd = $_SERVER['PHP_AUTH_PW']; - $submitteduser = $_SERVER['PHP_AUTH_USER']; - if($submittedpwd == $caddypwd && $submitteduser == 'birdnet'){ - $url = $_SERVER['SERVER_NAME']."/scripts/adminer.php"; - echo "
+ //Authenticate before proceeding + $user_is_authenticated = authenticateUser(); + if ($user_is_authenticated) { + $url = $_SERVER['SERVER_NAME'] . "/scripts/adminer.php"; + echo "
@@ -174,38 +135,33 @@ if(isset($_GET['view'])){
"; - } else { - header('WWW-Authenticate: Basic realm="My Realm"'); - header('HTTP/1.0 401 Unauthorized'); - echo '
You cannot edit the settings for this installation
'; - exit; - } - } + } } if($_GET['view'] == "Recordings"){include('play.php');} if($_GET['view'] == "Settings"){include('scripts/config.php');} if($_GET['view'] == "Advanced"){include('scripts/advanced.php');} if($_GET['view'] == "Included"){ - if(isset($_GET['species']) && isset($_GET['add'])){ - $file = './scripts/include_species_list.txt'; + $user_is_authenticated = authenticateUser('You cannot modify the system'); + if(isset($_GET['species']) && isset($_GET['add']) && $user_is_authenticated){ + $file = getFilePath('include_species_list.txt'); $str = file_get_contents("$file"); $str = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $str); file_put_contents("$file", "$str"); if(isset($_GET['species'])){ foreach ($_GET['species'] as $selectedOption) - file_put_contents("./scripts/include_species_list.txt", $selectedOption."\n", FILE_APPEND); + file_put_contents( getFilePath('include_species_list.txt'), $selectedOption."\n", FILE_APPEND); } } elseif(isset($_GET['species']) && isset($_GET['del'])){ - $file = './scripts/include_species_list.txt'; + $file = getFilePath('include_species_list.txt'); $str = file_get_contents("$file"); $str = preg_replace('/^\h*\v+/m', '', $str); file_put_contents("$file", "$str"); foreach($_GET['species'] as $selectedOption) { - $content = file_get_contents("../BirdNET-Pi/include_species_list.txt"); + $content = file_get_contents( getFilePath('include_species_list.txt')); $newcontent = str_replace($selectedOption, "", "$content"); - file_put_contents("./scripts/include_species_list.txt", "$newcontent"); + file_put_contents( getFilePath('include_species_list.txt'), "$newcontent"); } - $file = './scripts/include_species_list.txt'; + $file = getFilePath('include_species_list.txt'); $str = file_get_contents("$file"); $str = preg_replace('/^\h*\v+/m', '', $str); file_put_contents("$file", "$str"); @@ -213,24 +169,25 @@ if(isset($_GET['view'])){ include('./scripts/include_list.php'); } if($_GET['view'] == "Excluded"){ - if(isset($_GET['species']) && isset($_GET['add'])){ - $file = './scripts/exclude_species_list.txt'; + $user_is_authenticated = authenticateUser('You cannot modify the system'); + if(isset($_GET['species']) && isset($_GET['add']) && $user_is_authenticated){ + $file = getFilePath('exclude_species_list.txt'); $str = file_get_contents("$file"); $str = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $str); file_put_contents("$file", "$str"); foreach ($_GET['species'] as $selectedOption) - file_put_contents("./scripts/exclude_species_list.txt", $selectedOption."\n", FILE_APPEND); + file_put_contents(getFilePath('exclude_species_list.txt'), $selectedOption."\n", FILE_APPEND); } elseif (isset($_GET['species']) && isset($_GET['del'])){ - $file = './scripts/exclude_species_list.txt'; + $file = getFilePath('exclude_species_list.txt'); $str = file_get_contents("$file"); $str = preg_replace('/^\h*\v+/m', '', $str); file_put_contents("$file", "$str"); foreach($_GET['species'] as $selectedOption) { - $content = file_get_contents("./scripts/exclude_species_list.txt"); + $content = file_get_contents(getFilePath('exclude_species_list.txt')); $newcontent = str_replace($selectedOption, "", "$content"); - file_put_contents("./scripts/exclude_species_list.txt", "$newcontent"); + file_put_contents(getFilePath('exclude_species_list.txt'), "$newcontent"); } - $file = './scripts/exclude_species_list.txt'; + $file = getFilePath('exclude_species_list.txt'); $str = file_get_contents("$file"); $str = preg_replace('/^\h*\v+/m', '', $str); file_put_contents("$file", "$str"); @@ -241,123 +198,104 @@ if(isset($_GET['view'])){ echo ""; } 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'); - } - $caddypwd = $config['CADDY_PWD']; - if (!isset($_SERVER['PHP_AUTH_USER'])) { - header('WWW-Authenticate: Basic realm="My Realm"'); - header('HTTP/1.0 401 Unauthorized'); - echo '
You cannot access the web terminal
'; - exit; - } else { - $submittedpwd = $_SERVER['PHP_AUTH_PW']; - $submitteduser = $_SERVER['PHP_AUTH_USER']; - if($submittedpwd == $caddypwd && $submitteduser == 'birdnet'){ + //Authenticate before proceeding + $user_is_authenticated = authenticateUser("You cannot access the web terminal"); + if ($user_is_authenticated) { #ACCESS THE WEB TERMINAL echo ""; - } else { - header('WWW-Authenticate: Basic realm="My Realm"'); - header('HTTP/1.0 401 Unauthorized'); - echo '
You cannot access the web terminal
'; - exit; - } - } + } } } 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'); - } - $caddypwd = $config['CADDY_PWD']; - if (!isset($_SERVER['PHP_AUTH_USER'])) { - header('WWW-Authenticate: Basic realm="My Realm"'); - header('HTTP/1.0 401 Unauthorized'); - echo 'You cannot access the web terminal'; - exit; - } else { - $submittedpwd = $_SERVER['PHP_AUTH_PW']; - $submitteduser = $_SERVER['PHP_AUTH_USER']; - $allowedCommands = array('sudo systemctl stop livestream.service && sudo systemctl stop icecast2.service', - 'sudo systemctl restart livestream.service && sudo systemctl restart icecast2.service', - 'sudo systemctl disable --now livestream.service && sudo systemctl disable icecast2 && sudo systemctl stop icecast2.service', - 'sudo systemctl enable icecast2 && sudo systemctl start icecast2.service && sudo systemctl enable --now livestream.service', - 'sudo systemctl stop web_terminal.service', - 'sudo systemctl restart web_terminal.service', - 'sudo systemctl disable --now web_terminal.service', - 'sudo systemctl enable --now web_terminal.service', - 'sudo systemctl stop birdnet_log.service', - 'sudo systemctl restart birdnet_log.service', - 'sudo systemctl disable --now birdnet_log.service', - 'sudo systemctl enable --now birdnet_log.service', - 'sudo systemctl stop extraction.service', - 'sudo systemctl restart extraction.service', - 'sudo systemctl disable --now extraction.service', - 'sudo systemctl enable --now extraction.service', - 'sudo systemctl stop birdnet_server.service', - 'sudo systemctl restart birdnet_server.service', - 'sudo systemctl disable --now birdnet_server.service', - 'sudo systemctl enable --now birdnet_server.service', - 'sudo systemctl stop birdnet_analysis.service', - 'sudo systemctl restart birdnet_analysis.service', - 'sudo systemctl disable --now birdnet_analysis.service', - 'sudo systemctl enable --now birdnet_analysis.service', - 'sudo systemctl stop birdnet_stats.service', - 'sudo systemctl restart birdnet_stats.service', - 'sudo systemctl disable --now birdnet_stats.service', - 'sudo systemctl enable --now birdnet_stats.service', - 'sudo systemctl stop birdnet_recording.service', - 'sudo systemctl restart birdnet_recording.service', - 'sudo systemctl disable --now birdnet_recording.service', - 'sudo systemctl enable --now birdnet_recording.service', - 'sudo systemctl stop chart_viewer.service', - 'sudo systemctl restart chart_viewer.service', - 'sudo systemctl disable --now chart_viewer.service', - 'sudo systemctl enable --now chart_viewer.service', - 'sudo systemctl stop spectrogram_viewer.service', - 'sudo systemctl restart spectrogram_viewer.service', - 'sudo systemctl disable --now spectrogram_viewer.service', - 'sudo systemctl enable --now spectrogram_viewer.service', - 'stop_core_services.sh', - 'restart_services.sh', + //Authenticate before proceeding + $user_is_authenticated = authenticateUser('You cannot modify the system'); + + $allowedCommands = array('service stop livestream.service && service stop icecast2.service', + 'service restart livestream.service && service restart icecast2.service', + 'service disable livestream.service && service disable icecast2 && service stop icecast2.service', + 'service enable icecast2 && service start icecast2.service && service enable livestream.service', + 'service stop web_terminal.service', + 'service restart web_terminal.service', + 'service disable web_terminal.service', + 'service enable web_terminal.service', + 'service stop birdnet_log.service', + 'service restart birdnet_log.service', + 'service disable birdnet_log.service', + 'service enable birdnet_log.service', + 'service stop extraction.service', + 'service restart extraction.service', + 'service disable extraction.service', + 'service enable extraction.service', + 'service stop birdnet_server.service', + 'service restart birdnet_server.service', + 'service disable birdnet_server.service', + 'service enable birdnet_server.service', + 'service stop birdnet_analysis.service', + 'service restart birdnet_analysis.service', + 'service disable birdnet_analysis.service', + 'service enable birdnet_analysis.service', + 'service stop birdnet_stats.service', + 'service restart birdnet_stats.service', + 'service disable birdnet_stats.service', + 'service enable birdnet_stats.service', + 'service stop birdnet_recording.service', + 'service restart birdnet_recording.service', + 'service disable birdnet_recording.service', + 'service enable birdnet_recording.service', + 'service stop chart_viewer.service', + 'service restart chart_viewer.service', + 'service disable chart_viewer.service', + 'service enable chart_viewer.service', + 'service stop spectrogram_viewer.service', + 'service restart spectrogram_viewer.service', + 'service disable spectrogram_viewer.service', + 'service enable spectrogram_viewer.service', + 'system stop core.services', + 'system restart core.services', 'sudo reboot', 'update_birdnet.sh', 'sudo shutdown now', 'sudo clear_all_data.sh'); $command = $_GET['submit']; - if($submittedpwd == $caddypwd && $submitteduser == 'birdnet' && in_array($command,$allowedCommands)){ + if($user_is_authenticated && in_array($command,$allowedCommands)){ if(isset($command)){ $initcommand = $command; - if (strpos($command, "systemctl") !== false) { + $results = ""; + //Process the system commands differently + if (strpos($command, "system") !== false) { + $results = serviceMaintenance($command); + //clear the command so we skip the next bits and go straight to output processing + $command = ''; + } + if (strpos($command, "service") !== false) { //If there more than one command to execute, processes then separately //currently only livestream service uses multiple commands to interact with the required services if (strpos($command, " && ") !== false) { $separate_commands = explode("&&", trim($command)); $new_multiservice_status_command = ""; foreach ($separate_commands as $indiv_service_command) { + //Action the command + serviceMaintenance($indiv_service_command); //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 + //get the service names so we can poll the status $new_multiservice_status_command .= " " . trim(end($separate_command_tmp)); } $service_names = $new_multiservice_status_command; } else { - //only one service needs restarting so we only need to query the status of one service + serviceMaintenance($command); + //only one service needs restarting so we only need to query the status of one service $tmp = explode(" ", trim($command)); $service_names = end($tmp); } - - $command .= " & sleep 3;sudo systemctl status " . $service_names; + //Build up the command that will query the service status + $command = "sleep 3;sudo systemctl status " . $service_names; } if($initcommand == "update_birdnet.sh") { unset($_SESSION['behind']); } - $results = shell_exec("$command 2>&1"); + $results .= shell_exec("$command 2>&1"); $results = str_replace("FAILURE", "FAILURE", $results); $results = str_replace("failed", "failed",$results); $results = str_replace("active (running)", "active (running)",$results); @@ -409,15 +347,16 @@ if(isset($_GET['view'])){ } echo "
Output of command:`".$initcommand."`
$results
"; } else { - header('WWW-Authenticate: Basic realm="My Realm"'); + header('WWW-Authenticate: Basic realm="BirdNET-Pi"'); header('HTTP/1.0 401 Unauthorized'); - echo 'You cannot access the web terminal'; + echo 'You cannot modify the system'; exit; } } - } ob_end_flush(); -} else {include('overview.php');} +} else { + include('overview.php'); +} ?> "; } - $fh = fopen("/etc/birdnet/birdnet.conf", "w"); - $fh2 = fopen("./scripts/thisrun.txt", "w"); - fwrite($fh, $contents); - fwrite($fh2, $contents2); + updateAppriseConfig($apprise_input); - if(isset($apprise_input)){ - $user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd"); - $home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd"); - $home = trim($home); - - $appriseconfig = fopen($home."/BirdNET-Pi/apprise.txt", "w"); - fwrite($appriseconfig, $apprise_input); - } - - syslog(LOG_INFO, "Restarting Services"); - shell_exec("sudo restart_services.sh"); + serviceMaintenance('restart core.services'); } if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") { - $db = new SQLite3('./birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE); - - $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('./thisrun.txt')) { - $config = parse_ini_file('./thisrun.txt'); - } elseif (file_exists('./firstrun.ini')) { - $config = parse_ini_file('./firstrun.ini'); - } - $cf = explode("\n",$_GET['apprise_config']); $cf = "'".implode("' '", $cf)."'"; - $statement0 = $db->prepare('SELECT * FROM detections WHERE Date == DATE(\'now\', \'localtime\') ORDER BY TIME DESC LIMIT 1'); - $result0 = $statement0->execute(); - while($todaytable=$result0->fetchArray(SQLITE3_ASSOC)) + $result0 = getMostRecentDetectionToday(); + foreach ($result0['data'] as $todaytable) { $sciname = $todaytable['Sci_Name']; $comname = $todaytable['Com_Name']; @@ -310,7 +204,7 @@ if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") { $body = str_replace("\$overlap", $overlap, $body); $body = str_replace("\$flickrimage", $exampleimage, $body); - echo "
".shell_exec($home."/BirdNET-Pi/birdnet/bin/apprise -vv --plugin-path ".$home."/.apprise/plugins "." -t '".escapeshellcmd($title)."' -b '".escapeshellcmd($body)."' ".$attach." ".$cf." ")."
"; + echo "
" . executeSysCommand('appraise_notification', ['title' => $title, 'body' => $body, 'attach' => $attach, 'cf' => $cf]) . "
"; die(); } @@ -324,11 +218,10 @@ if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") {

Basic Settings


- @@ -360,7 +253,6 @@ function sendTestNotification(e) { ' />
- > + >
- > + >
- > + >
- > + >

@@ -575,39 +467,6 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken} prepare("SELECT COUNT(*) FROM detections - WHERE Date == \"$theDate\""); -$result1 = $statement1->execute(); -$totalcount = $result1->fetchArray(SQLITE3_ASSOC); +$statement1 = getDetectionCountByDate($theDate); +if($statement1['success'] == False){ + echo $statement1['message']; + header("refresh: 0;"); +} if(isset($_GET['blocation']) ) { @@ -32,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"]); @@ -45,16 +36,17 @@ if(isset($_GET['blocation']) ) { $hrsinday = 24; for($i=0;$i<$hrsinday;$i++) { $starttime = strtotime("12 AM") + (3600*$i); + $endtime = date("H:i",$starttime + 3600); - $statement1 = $db->prepare("SELECT DISTINCT(Com_Name), COUNT(*) FROM detections WHERE Date == \"$theDate\" AND Time > '".date("H:i", $starttime)."' AND Time < '".date("H:i",$starttime + 3600)."' AND Confidence > 0.75 GROUP By Com_Name ORDER BY COUNT(*) DESC"); - if($statement1 == False){ - echo "Database is busy"; - header("refresh: 0;"); + $statement1 = getDetectionBreakdownByTime($theDate,$starttime,$endtime); + if($statement1['success'] == False){ + echo $statement1['message']; + header("refresh: 0;"); } - $result1 = $statement1->execute(); + $result1 = $statement1['data']; $detections = []; - while($detection=$result1->fetchArray(SQLITE3_ASSOC)) + foreach ($result1 as $detection) { $detections[$detection["Com_Name"]] = $detection["COUNT(*)"]; } diff --git a/scripts/include_list.php b/scripts/include_list.php index ad663be..ac78990 100644 --- a/scripts/include_list.php +++ b/scripts/include_list.php @@ -3,10 +3,7 @@ @@ -47,7 +44,7 @@ $eachlines = file($filename, FILE_IGNORE_NEW_LINES);