Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Feature/error log #277

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ vendor/simple-translator/
/.htaccess
.htpasswd
*.patch
.vscode
5 changes: 5 additions & 0 deletions api/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
}
}
}
$logFile = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $config['take_picture']['logfile'];
if (is_file($logFile)) {
unlink($logFile);
}

}

if ($config['reset']['remove_mailtxt']) {
Expand Down
49 changes: 33 additions & 16 deletions api/takePic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
require_once '../lib/config.php';
require_once '../lib/db.php';

function logError($data) {
global $config;
$logfile = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $config['take_picture']['logfile'];

$file_data = date('c') . ":\n" . print_r($data, true) . "\n";
if(is_file($logfile))
$file_data .= file_get_contents($logfile);
file_put_contents($logfile, $file_data);

//$fp = fopen($logfile, 'a'); //opens file in append mode.
//fwrite($fp, date('c') . ":\n\t" . $message . "\n");
//fclose($fp);
}

function takePicture($filename) {
global $config;

Expand All @@ -29,27 +43,30 @@ function takePicture($filename) {
$dir = dirname($filename);
chdir($dir); //gphoto must be executed in a dir with write permission
$cmd = sprintf($config['take_picture']['cmd'], $filename);
$cmd .= " 2>&1"; //Redirect stderr to stdout, otherwise error messages get lost.

exec($cmd, $output, $returnValue);

if ($returnValue) {
die(
json_encode([
'error' => 'Gphoto returned with an error code',
'cmd' => $cmd,
'returnValue' => $returnValue,
'output' => $output,
])
);
$ErrorData = [
'error' => 'Gphoto returned with an error code',
'cmd' => $cmd,
'returnValue' => $returnValue,
'output' => $output,
];
$ErrorString = json_encode($ErrorData);
logError($ErrorData);
die($ErrorString);
} elseif (!file_exists($filename)) {
die(
json_encode([
'error' => 'File was not created',
'cmd' => $cmd,
'returnValue' => $returnValue,
'output' => $output,
])
);
$ErrorData = [
'error' => 'File was not created',
'cmd' => $cmd,
'returnValue' => $returnValue,
'output' => $output,
];
$ErrorString = json_encode($ErrorData);
logError($ErrorData);
die($ErrorString);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@

$config['remotebuzzer']['logfile'] = 'remotebuzzer_server.log';
$config['synctodrive']['logfile'] = 'synctodrive_server.log';
$config['take_picture']['logfile'] = 'take_picture.log';

$config['ui']['github'] = 'andi34';
$config['ui']['branding'] = 'Photobooth';
Expand Down
8 changes: 7 additions & 1 deletion lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@
'placeholder' => $defaultConfig['textonpicture']['linespace'],
'name' => 'textonpicture[linespace]',
'value' => $config['textonpicture']['linespace'],
],
]
],
'collage' => [
'view' => 'basic',
Expand Down Expand Up @@ -1738,6 +1738,12 @@
'name' => 'take_picture[cmd]',
'value' => htmlentities($config['take_picture']['cmd']),
],
'take_picture_logfile' => [
'view' => 'expert',
'type' => 'hidden',
'name' => 'take_picture[logfile]',
'value' => $config['take_picture']['logfile'],
],
'take_picture_msg' => [
'view' => 'expert',
'type' => 'input',
Expand Down