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

Commit

Permalink
Add logging to takePic.php
Browse files Browse the repository at this point in the history
Squashed changes, closes #277

Change-Id: Ieab78796ad38f1a5ec105cf31b017045d5fc2b0e
  • Loading branch information
Metropo authored and andi34 committed Jul 30, 2021
1 parent 3f4e8ba commit 48b7c4a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
2 changes: 1 addition & 1 deletion admin/debugpanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function html_src_indent($num)
echo '<li><a class="adminnavlistelement" href="#myconfig" id="nav-myconfig"><div><span data-i18n="myconfig">myconfig</span></div></a></li>';
echo '<li><a class="adminnavlistelement" href="#remotebuzzerlog" id="nav-remotebuzzerlog"><div><span data-i18n="remotebuzzer">remotebuzzer</span></div></a></li>';
echo '<li><a class="adminnavlistelement" href="#synctodrivelog" id="nav-synctodrivelog"><div><span data-i18n="synctodrive">synctodrive</span></div></a></li>';
echo '<li><a class="adminnavlistelement" href="#cameralog" id="nav-cameralog"><div><span data-i18n="cameralog">cameralog</span></div></a></li>';
echo '<li><a class="adminnavlistelement" href="#cameralog" id="nav-cameralog"><div><span data-i18n="cameralog">cameralog</span></div></a></li>';
echo '<li><a class="adminnavlistelement" href="#serverprocesses" id="nav-serverprocesses"><div><span data-i18n="serverprocesses">serverprocesses</span></div></a></li>';
echo '<li><a class="adminnavlistelement" href="#bootconfig" id="nav-bootconfig"><div><span data-i18n="bootconfig">bootconfig</span></div></a></li>';

Expand Down
4 changes: 4 additions & 0 deletions api/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
}
}
}
$logFile = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $config['take_picture']['logfile'];
if (is_file($logFile)) {
unlink($logFile);
}
}

if ($config['reset']['remove_mailtxt']) {
Expand Down
50 changes: 34 additions & 16 deletions api/takePic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
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 +44,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
6 changes: 6 additions & 0 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
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

0 comments on commit 48b7c4a

Please sign in to comment.