convert play.php
This commit is contained in:
+40
-103
@@ -7,126 +7,63 @@ $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
|
|||||||
error_reporting(E_ERROR);
|
error_reporting(E_ERROR);
|
||||||
ini_set('display_errors',1);
|
ini_set('display_errors',1);
|
||||||
require_once 'scripts/common.php';
|
require_once 'scripts/common.php';
|
||||||
|
$home = get_home();
|
||||||
|
$config = get_config();
|
||||||
|
|
||||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);
|
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);
|
||||||
$db->busyTimeout(1000);
|
$db->busyTimeout(1000);
|
||||||
|
|
||||||
if (file_exists('./scripts/thisrun.txt')) {
|
|
||||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
|
||||||
} elseif (file_exists('firstrun.ini')) {
|
|
||||||
$config = parse_ini_file('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(isset($_GET['deletefile'])) {
|
if(isset($_GET['deletefile'])) {
|
||||||
if(isset($_SERVER['PHP_AUTH_USER'])) {
|
ensure_authenticated('You must be authenticated to delete files.');
|
||||||
$submittedpwd = $_SERVER['PHP_AUTH_PW'];
|
$db_writable = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READWRITE);
|
||||||
$submitteduser = $_SERVER['PHP_AUTH_USER'];
|
$db->busyTimeout(1000);
|
||||||
if($submittedpwd == $config['CADDY_PWD'] && $submitteduser == 'birdnet'){
|
$statement1 = $db_writable->prepare('DELETE FROM detections WHERE File_Name = :file_name LIMIT 1');
|
||||||
$db_writable = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READWRITE);
|
ensure_db_ok($statement1);
|
||||||
$db->busyTimeout(1000);
|
$statement1->bindValue(':file_name', explode("/", $_GET['deletefile'])[2]);
|
||||||
$statement1 = $db_writable->prepare('DELETE FROM detections WHERE File_Name = :file_name LIMIT 1');
|
$file_pointer = $home."/BirdSongs/Extracted/By_Date/".$_GET['deletefile'];
|
||||||
ensure_db_ok($statement1);
|
if (!exec("sudo rm $file_pointer && sudo rm $file_pointer.png")) {
|
||||||
$statement1->bindValue(':file_name', explode("/", $_GET['deletefile'])[2]);
|
echo "OK";
|
||||||
$file_pointer = $home."/BirdSongs/Extracted/By_Date/".$_GET['deletefile'];
|
|
||||||
if (!exec("sudo rm $file_pointer && sudo rm $file_pointer.png")) {
|
|
||||||
echo "OK";
|
|
||||||
} else {
|
|
||||||
echo "Error";
|
|
||||||
}
|
|
||||||
$result1 = $statement1->execute();
|
|
||||||
$db_writable->close();
|
|
||||||
die();
|
|
||||||
} else {
|
|
||||||
header('WWW-Authenticate: Basic realm="My Realm"');
|
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
|
||||||
echo 'You must be authenticated to change the protection of files.';
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
header('WWW-Authenticate: Basic realm="My Realm"');
|
echo "Error";
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
|
||||||
echo 'You must be authenticated to change the protection of files.';
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
$result1 = $statement1->execute();
|
||||||
|
$db_writable->close();
|
||||||
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($_GET['excludefile'])) {
|
if(isset($_GET['excludefile'])) {
|
||||||
if(isset($_SERVER['PHP_AUTH_USER'])) {
|
ensure_authenticated('You must be authenticated to change the protection of files.');
|
||||||
$submittedpwd = $_SERVER['PHP_AUTH_PW'];
|
if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt")) {
|
||||||
$submitteduser = $_SERVER['PHP_AUTH_USER'];
|
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start\n##end\n");
|
||||||
if($submittedpwd == $config['CADDY_PWD'] && $submitteduser == 'birdnet'){
|
}
|
||||||
if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt")) {
|
if(isset($_GET['exclude_add'])) {
|
||||||
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start\n##end\n");
|
$myfile = fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "a") or die("Unable to open file!");
|
||||||
}
|
$txt = $_GET['excludefile'];
|
||||||
if(isset($_GET['exclude_add'])) {
|
fwrite($myfile, $txt."\n");
|
||||||
$myfile = fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "a") or die("Unable to open file!");
|
fwrite($myfile, $txt.".png\n");
|
||||||
$txt = $_GET['excludefile'];
|
fclose($myfile);
|
||||||
fwrite($myfile, $txt."\n");
|
echo "OK";
|
||||||
fwrite($myfile, $txt.".png\n");
|
die();
|
||||||
fclose($myfile);
|
|
||||||
echo "OK";
|
|
||||||
die();
|
|
||||||
} else {
|
|
||||||
$lines = file($home."/BirdNET-Pi/scripts/disk_check_exclude.txt");
|
|
||||||
$search = $_GET['excludefile'];
|
|
||||||
|
|
||||||
$result = '';
|
|
||||||
foreach($lines as $line) {
|
|
||||||
if(stripos($line, $search) === false && stripos($line, $search.".png") === false) {
|
|
||||||
$result .= $line;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", $result);
|
|
||||||
echo "OK";
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
header('WWW-Authenticate: Basic realm="My Realm"');
|
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
|
||||||
echo 'You must be authenticated to change the protection of files.';
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
header('WWW-Authenticate: Basic realm="My Realm"');
|
$lines = file($home."/BirdNET-Pi/scripts/disk_check_exclude.txt");
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
$search = $_GET['excludefile'];
|
||||||
echo 'You must be authenticated to change the protection of files.';
|
|
||||||
exit;
|
$result = '';
|
||||||
|
foreach($lines as $line) {
|
||||||
|
if(stripos($line, $search) === false && stripos($line, $search.".png") === false) {
|
||||||
|
$result .= $line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", $result);
|
||||||
|
echo "OK";
|
||||||
|
die();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$shifted_path = $home."/BirdSongs/Extracted/By_Date/shifted/";
|
$shifted_path = $home."/BirdSongs/Extracted/By_Date/shifted/";
|
||||||
|
|
||||||
if(isset($_GET['shiftfile'])) {
|
if(isset($_GET['shiftfile'])) {
|
||||||
|
ensure_authenticated('You cannot shift files for this installation');
|
||||||
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);
|
|
||||||
$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'];
|
$filename = $_GET['shiftfile'];
|
||||||
$pp = pathinfo($filename);
|
$pp = pathinfo($filename);
|
||||||
|
|||||||
Reference in New Issue
Block a user