Skip to content

Commit

Permalink
php can log to /var/log/scanner.log now
Browse files Browse the repository at this point in the history
  • Loading branch information
vgarcia007 committed Sep 30, 2024
1 parent 55d37f9 commit ffc227d
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions files/runScanner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "-----"
Expand Down
26 changes: 26 additions & 0 deletions www/html/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
<?php
define('E_API', 1024);
define('E_FRONTEND', 1025);

function customErrorHandler($errno, $errstr, $errfile, $errline) {
$date = date("Y-m-d H:i:s");

$errorType = match ($errno) {
E_WARNING => "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');
Expand Down
1 change: 0 additions & 1 deletion www/private/helper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


function json($data){

header('Content-Type: application/json');
Expand Down
2 changes: 1 addition & 1 deletion www/private/views/api/dev-timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'timezone' => 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);

?>
3 changes: 2 additions & 1 deletion www/private/views/api/file-delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

?>
3 changes: 3 additions & 0 deletions www/private/views/api/file-rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -36,6 +37,7 @@ function getFileTimes($original_filename) {


} else {
trigger_error("JSON decoding error", E_API);
send_json_error(400, "JSON decoding error");
}

Expand Down Expand Up @@ -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");
}

Expand Down
2 changes: 2 additions & 0 deletions www/private/views/api/scanner-scanto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down
2 changes: 1 addition & 1 deletion www/private/views/frontend/common-head.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<link rel="icon" href="favicon.ico">
<link rel="stylesheet" href="/assets/bootstrap.5.1.3/bootstrap.min.css ">
<link rel="stylesheet" href="/assets/fontawesome.5.15.4/css/all.min.css">
<link rel="stylesheet" href="/assets/style.css">
<link rel="stylesheet" href="/assets/style.min.css?ver=1.0">
2 changes: 1 addition & 1 deletion www/private/views/frontend/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class="far fa-smile fa-fw fa-10x"></i></span>
<?php include('views/frontend/common-javascript.php'); ?>


<script src="/assets/scripts.min.js"></script>
<script src="/assets/scripts.min.js?ver=1.0"></script>


</body>
Expand Down

0 comments on commit ffc227d

Please sign in to comment.