From ffc227d50e2a2aa25cb044f8783b1b15d9840cbd Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 30 Sep 2024 19:59:15 +0200 Subject: [PATCH] php can log to /var/log/scanner.log now --- files/runScanner.sh | 1 + www/html/index.php | 26 ++++++++++++++++++++++ www/private/helper.php | 1 - www/private/views/api/dev-timezone.php | 2 +- www/private/views/api/file-delete.php | 3 ++- www/private/views/api/file-rename.php | 3 +++ www/private/views/api/scanner-scanto.php | 2 ++ www/private/views/frontend/common-head.php | 2 +- www/private/views/frontend/home.php | 2 +- 9 files changed, 37 insertions(+), 5 deletions(-) diff --git a/files/runScanner.sh b/files/runScanner.sh index 567ba30..042607e 100755 --- a/files/runScanner.sh +++ b/files/runScanner.sh @@ -18,6 +18,7 @@ mkdir -p /scans chmod 777 /scans touch /var/log/scanner.log chown "$NAME" /var/log/scanner.log +chmod 666 /var/log/scanner.log env >/opt/brother/scanner/env.txt chmod -R 777 /opt/brother echo "-----" diff --git a/www/html/index.php b/www/html/index.php index bf0a380..1cb3507 100644 --- a/www/html/index.php +++ b/www/html/index.php @@ -1,5 +1,31 @@ "Warning", + E_NOTICE => "Notice", + E_ERROR => "Error", + E_API => "API", // Custom log type + E_FRONTEND => "Frontend", // Custom log type + default => "Unknown" + }; + + if (($errno == E_API) OR ($errno == E_FRONTEND)) { + $logMessage = "[$errorType] $errstr\n"; + } else { + $logMessage = "[$date] [$errorType] $errstr in $errfile on line $errline\n"; + } + + error_log($logMessage, 3, '/var/log/scanner.log'); +} + +set_error_handler("customErrorHandler"); set_include_path('/var/www/private/'); + include('config.php'); require_once('classes/AltoRouter.php'); require_once('helper.php'); diff --git a/www/private/helper.php b/www/private/helper.php index 1d2f93f..133e644 100755 --- a/www/private/helper.php +++ b/www/private/helper.php @@ -1,6 +1,5 @@ date_default_timezone_get(), 'datetime' => date("Y-m-d H:i:s") ); - +trigger_error("Timezone: ".$timezone_data['timezone'] . " DateTime: ".$timezone_data['datetime'], E_API); json($timezone_data); ?> \ No newline at end of file diff --git a/www/private/views/api/file-delete.php b/www/private/views/api/file-delete.php index 803848a..06e8a3a 100755 --- a/www/private/views/api/file-delete.php +++ b/www/private/views/api/file-delete.php @@ -19,7 +19,8 @@ if(unlink($file_info['full_path'])){ json(array('status' => 'success')); } else { - send_json_error(500, "Could not delete file"); + trigger_error("can not deleted file ".$file_info['full_path'], E_API); + send_json_error(500, "Could not delete file"); } ?> \ No newline at end of file diff --git a/www/private/views/api/file-rename.php b/www/private/views/api/file-rename.php index 5238017..a7b6049 100755 --- a/www/private/views/api/file-rename.php +++ b/www/private/views/api/file-rename.php @@ -5,6 +5,7 @@ if (isset($ALLOW_GUI_FILEOPERATIONS) && $ALLOW_GUI_FILEOPERATIONS) { $file_op = True; } else { + trigger_error("File operations are disabled in config", E_API); send_json_error(403, "File operations are disabled in config"); } @@ -36,6 +37,7 @@ function getFileTimes($original_filename) { } else { + trigger_error("JSON decoding error", E_API); send_json_error(400, "JSON decoding error"); } @@ -66,6 +68,7 @@ function getFileTimes($original_filename) { @touch($final_filename, $times['modification_time'], $times['access_time']); send_json_error(200, "Renamed file successfully"); } else { + trigger_error("Error renaming the file", E_API); send_json_error(400, "Error renaming the file"); } diff --git a/www/private/views/api/scanner-scanto.php b/www/private/views/api/scanner-scanto.php index 7e9ba5b..4b02898 100644 --- a/www/private/views/api/scanner-scanto.php +++ b/www/private/views/api/scanner-scanto.php @@ -16,12 +16,14 @@ function safe_guard_target($target) { if (empty($target)) { + trigger_error("Invalid scan target", E_API); send_json_error(400, 'Invalid target'); } if (in_array($target, array('file','email','image','ocr'))) { return escapeshellcmd($target); } else { + trigger_error("Invalid scan target", E_API); send_json_error(400, 'Invalid target'); } } diff --git a/www/private/views/frontend/common-head.php b/www/private/views/frontend/common-head.php index fdcb51a..0fa1695 100755 --- a/www/private/views/frontend/common-head.php +++ b/www/private/views/frontend/common-head.php @@ -3,4 +3,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/www/private/views/frontend/home.php b/www/private/views/frontend/home.php index 055910a..8135db6 100755 --- a/www/private/views/frontend/home.php +++ b/www/private/views/frontend/home.php @@ -105,7 +105,7 @@ class="far fa-smile fa-fw fa-10x"> - +