"; $output = shell_exec("sudo -u $user ".$home."/BirdNET-Pi/scripts/disk_species_count.sh 2>&1"); $escaped_output = htmlspecialchars($output, ENT_QUOTES | ENT_SUBSTITUTE); echo "alert(`$escaped_output`);"; echo ""; } if(isset($_GET['submit'])) { $contents = file_get_contents('/etc/birdnet/birdnet.conf'); $restart_livestream = false; $update_caddyfile = false; if(isset($_GET["caddy_pwd"])) { $caddy_pwd = $_GET["caddy_pwd"]; if(strcmp($caddy_pwd,$config['CADDY_PWD']) !== 0) { $contents = preg_replace("/CADDY_PWD=.*/", "CADDY_PWD=\"$caddy_pwd\"", $contents); $update_caddyfile = true; } } if(isset($_GET["ice_pwd"])) { $ice_pwd = $_GET["ice_pwd"]; if(strcmp($ice_pwd,$config['ICE_PWD']) !== 0) { $contents = preg_replace("/ICE_PWD=.*/", "ICE_PWD=$ice_pwd", $contents); $restart_livestream = true; } } if(isset($_GET["birdnetpi_url"])) { $birdnetpi_url = $_GET["birdnetpi_url"]; // remove trailing slash to prevent conf from becoming broken $birdnetpi_url = rtrim($birdnetpi_url, '/'); if(strcmp($birdnetpi_url,$config['BIRDNETPI_URL']) !== 0) { $contents = preg_replace("/BIRDNETPI_URL=.*/", "BIRDNETPI_URL=$birdnetpi_url", $contents); $update_caddyfile = true; } } if(isset($_GET["rtsp_stream"])) { $rtsp_stream = str_replace("\r\n", ",", $_GET["rtsp_stream"]); if(strcmp($rtsp_stream,$config['RTSP_STREAM']) !== 0) { $contents = preg_replace("/RTSP_STREAM=.*/", "RTSP_STREAM=\"$rtsp_stream\"", $contents); $restart_livestream = True; } } if (isset($_GET["rtsp_stream_to_livestream"])) { $rtsp_stream_selected = trim($_GET["rtsp_stream_to_livestream"]); //Setting exists already, see if the value changed if (strcmp($rtsp_stream_selected, $config['RTSP_STREAM_TO_LIVESTREAM']) !== 0) { $contents = preg_replace("/RTSP_STREAM_TO_LIVESTREAM=.*/", "RTSP_STREAM_TO_LIVESTREAM=\"$rtsp_stream_selected\"", $contents); $restart_livestream = True; } } if (isset($_GET["activate_freqshift_in_livestream"])) { $activate_freqshift_in_livestream = trim($_GET["activate_freqshift_in_livestream"]); //Setting exists already, see if the value changed if (strcmp($activate_freqshift_in_livestream, $config['ACTIVATE_FREQSHIFT_IN_LIVESTREAM']) !== 0) { $contents = preg_replace("/ACTIVATE_FREQSHIFT_IN_LIVESTREAM=.*/", "ACTIVATE_FREQSHIFT_IN_LIVESTREAM=\"$activate_freqshift_in_livestream\"", $contents); $restart_livestream = True; } } if(isset($_GET["overlap"])) { $overlap = $_GET["overlap"]; if(strcmp($overlap,$config['OVERLAP']) !== 0) { $contents = preg_replace("/OVERLAP=.*/", "OVERLAP=$overlap", $contents); } } if(isset($_GET["confidence"])) { $confidence = $_GET["confidence"]; if(strcmp($confidence,$config['CONFIDENCE']) !== 0) { $contents = preg_replace("/CONFIDENCE=.*/", "CONFIDENCE=$confidence", $contents); } } if(isset($_GET["sensitivity"])) { $sensitivity = $_GET["sensitivity"]; if(strcmp($sensitivity,$config['SENSITIVITY']) !== 0) { $contents = preg_replace("/SENSITIVITY=.*/", "SENSITIVITY=$sensitivity", $contents); } } if(isset($_GET["freqshift_hi"]) && is_numeric($_GET['freqshift_hi'])) { $freqshift_hi = $_GET["freqshift_hi"]; if(strcmp($freqshift_hi,$config['FREQSHIFT_HI']) !== 0) { $contents = preg_replace("/FREQSHIFT_HI=.*/", "FREQSHIFT_HI=$freqshift_hi", $contents); } } if(isset($_GET["freqshift_lo"]) && is_numeric($_GET['freqshift_lo'])) { $freqshift_lo = $_GET["freqshift_lo"]; if(strcmp($freqshift_lo,$config['FREQSHIFT_LO']) !== 0) { $contents = preg_replace("/FREQSHIFT_LO=.*/", "FREQSHIFT_LO=$freqshift_lo", $contents); } } if(isset($_GET["freqshift_pitch"]) && is_numeric($_GET['freqshift_pitch'])) { $freqshift_pitch = $_GET["freqshift_pitch"]; if(strcmp($freqshift_pitch,$config['FREQSHIFT_PITCH']) !== 0) { $contents = preg_replace("/FREQSHIFT_PITCH=.*/", "FREQSHIFT_PITCH=$freqshift_pitch", $contents); } } if(isset($_GET["freqshift_tool"])) { $freqshift_tool = $_GET["freqshift_tool"]; if(strcmp($freqshift_tool,$config['FREQSHIFT_TOOL']) !== 0) { $contents = preg_replace("/FREQSHIFT_TOOL=.*/", "FREQSHIFT_TOOL=$freqshift_tool", $contents); } } if(isset($_GET["freqshift_reconnect_delay"]) && is_numeric($_GET['freqshift_reconnect_delay'])) { $freqshift_reconnect_delay = $_GET["freqshift_reconnect_delay"]; if(strcmp($freqshift_hi,$config['FREQSHIFT_RECONNECT_DELAY']) !== 0) { $contents = preg_replace("/FREQSHIFT_RECONNECT_DELAY=.*/", "FREQSHIFT_RECONNECT_DELAY=$freqshift_reconnect_delay", $contents); } } if(isset($_GET["full_disk"])) { $full_disk = $_GET["full_disk"]; if(strcmp($full_disk,$config['FULL_DISK']) !== 0) { $contents = preg_replace("/FULL_DISK=.*/", "FULL_DISK=$full_disk", $contents); } } if (isset($_GET["purge_threshold"])) { $purge_threshold = $_GET["purge_threshold"]; if (strcmp($purge_threshold, $config['PURGE_THRESHOLD']) !== 0) { $contents = preg_replace("/PURGE_THRESHOLD=.*/", "PURGE_THRESHOLD=$purge_threshold", $contents); } } if (isset($_GET["max_files_species"])) { $max_files_species = $_GET["max_files_species"]; if (strcmp($max_files_species, $config['MAX_FILES_SPECIES']) !== 0) { $contents = preg_replace("/MAX_FILES_SPECIES=.*/", "MAX_FILES_SPECIES=$max_files_species", $contents); } } if(isset($_GET["privacy_threshold"])) { $privacy_threshold = $_GET["privacy_threshold"]; if(strcmp($privacy_threshold,$config['PRIVACY_THRESHOLD']) !== 0) { $contents = preg_replace("/PRIVACY_THRESHOLD=.*/", "PRIVACY_THRESHOLD=$privacy_threshold", $contents); } } if(isset($_GET["rec_card"])) { $rec_card = $_GET["rec_card"]; if(strcmp($rec_card,$config['REC_CARD']) !== 0) { $contents = preg_replace("/REC_CARD=.*/", "REC_CARD=\"$rec_card\"", $contents); } } if(isset($_GET["channels"])) { $channels = $_GET["channels"]; if(strcmp($channels,$config['CHANNELS']) !== 0) { $contents = preg_replace("/CHANNELS=.*/", "CHANNELS=$channels", $contents); } } if(isset($_GET["recording_length"])) { $recording_length = $_GET["recording_length"]; if(strcmp($recording_length,$config['RECORDING_LENGTH']) !== 0) { $contents = preg_replace("/RECORDING_LENGTH=.*/", "RECORDING_LENGTH=$recording_length", $contents); } } if(isset($_GET["extraction_length"])) { $extraction_length = $_GET["extraction_length"]; if(strcmp($extraction_length,$config['EXTRACTION_LENGTH']) !== 0) { $contents = preg_replace("/EXTRACTION_LENGTH=.*/", "EXTRACTION_LENGTH=$extraction_length", $contents); } } if(isset($_GET["audiofmt"])) { $audiofmt = $_GET["audiofmt"]; if(strcmp($audiofmt,$config['AUDIOFMT']) !== 0) { $contents = preg_replace("/AUDIOFMT=.*/", "AUDIOFMT=$audiofmt", $contents); } } if(isset($_GET["silence_update_indicator"])) { $silence_update_indicator = 1; if(strcmp($silence_update_indicator,$config['SILENCE_UPDATE_INDICATOR']) !== 0) { $contents = preg_replace("/SILENCE_UPDATE_INDICATOR=.*/", "SILENCE_UPDATE_INDICATOR=$silence_update_indicator", $contents); } } else { $contents = preg_replace("/SILENCE_UPDATE_INDICATOR=.*/", "SILENCE_UPDATE_INDICATOR=0", $contents); } if(isset($_GET["automatic_update"])) { $automatic_update = 1; if(strcmp($automatic_update,$config['AUTOMATIC_UPDATE']) !== 0) { $contents = preg_replace("/AUTOMATIC_UPDATE=.*/", "AUTOMATIC_UPDATE=$automatic_update", $contents); } } else { $contents = preg_replace("/AUTOMATIC_UPDATE=.*/", "AUTOMATIC_UPDATE=0", $contents); } if(isset($_GET["raw_spectrogram"])) { $raw_spectrogram = 1; if(strcmp($RAW_SPECTROGRAM,$config['RAW_SPECTROGRAM']) !== 0) { $contents = preg_replace("/RAW_SPECTROGRAM=.*/", "RAW_SPECTROGRAM=$raw_spectrogram", $contents); } } else { $contents = preg_replace("/RAW_SPECTROGRAM=.*/", "RAW_SPECTROGRAM=0", $contents); } if(isset($_GET["rare_species_threshold"])) { $rare_species_threshold = $_GET["rare_species_threshold"]; if(strcmp($rare_species_threshold, $config['RARE_SPECIES_THRESHOLD']) !== 0) { $contents = preg_replace("/RARE_SPECIES_THRESHOLD=.*/", "RARE_SPECIES_THRESHOLD=$rare_species_threshold", $contents); } } else { $contents = preg_replace("/RARE_SPECIES_THRESHOLD=.*/", "RARE_SPECIES_THRESHOLD=30", $contents); } if(isset($_GET["custom_image"])) { $custom_image = $_GET["custom_image"]; if(strcmp($custom_image,$config['CUSTOM_IMAGE']) !== 0) { $contents = preg_replace("/CUSTOM_IMAGE=.*/", "CUSTOM_IMAGE=$custom_image", $contents); } } if(isset($_GET["custom_image_label"])) { $custom_image_label = $_GET["custom_image_label"]; if(strcmp($custom_image_label,$config['CUSTOM_IMAGE_TITLE']) !== 0) { $contents = preg_replace("/CUSTOM_IMAGE_TITLE=.*/", "CUSTOM_IMAGE_TITLE=\"$custom_image_label\"", $contents); } } if (isset($_GET["LogLevel_BirdnetRecordingService"])) { $birdnet_recording_service_log_level = trim($_GET["LogLevel_BirdnetRecordingService"]); if (strcmp($birdnet_recording_service_log_level, $config['LogLevel_BirdnetRecordingService']) !== 0) { $contents = preg_replace("/LogLevel_BirdnetRecordingService=.*/", "LogLevel_BirdnetRecordingService=\"$birdnet_recording_service_log_level\"", $contents); } } if (isset($_GET["LogLevel_SpectrogramViewerService"])) { $spectrogram_viewer_service_log_level = trim($_GET["LogLevel_SpectrogramViewerService"]); if (strcmp($spectrogram_viewer_service_log_level, $config['LogLevel_SpectrogramViewerService']) !== 0) { $contents = preg_replace("/LogLevel_SpectrogramViewerService=.*/", "LogLevel_SpectrogramViewerService=\"$spectrogram_viewer_service_log_level\"", $contents); } } if (isset($_GET["LogLevel_LiveAudioStreamService"])) { $livestream_audio_service_log_level = trim($_GET["LogLevel_LiveAudioStreamService"]); if (strcmp($livestream_audio_service_log_level, $config['LogLevel_LiveAudioStreamService']) !== 0) { $contents = preg_replace("/LogLevel_LiveAudioStreamService=.*/", "LogLevel_LiveAudioStreamService=\"$livestream_audio_service_log_level\"", $contents); $restart_livestream = True; } } //Finally write the data out. some sections do this themselves in order to have the new settings ready for the services that will be restarted //but will doubly ensure the settings are saved after any modification $fh = fopen('/etc/birdnet/birdnet.conf', "w"); fwrite($fh, $contents); $config = get_config($force_reload=true); syslog(LOG_INFO, "Restarting Services"); if ($update_caddyfile){ exec('sudo /usr/local/bin/update_caddyfile.sh > /dev/null 2>&1 &'); } shell_exec("sudo restart_services.sh"); if ($restart_livestream) { exec("sudo systemctl restart livestream.service"); } } $count_labels = count(file($home."/BirdNET-Pi/model/labels.txt")); $count = $count_labels; ?>