diff --git a/.gitignore b/.gitignore index 543deb66b..573d97ee8 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ vendor/simple-translator/ /.htaccess .htpasswd *.patch +.vscode \ No newline at end of file diff --git a/api/admin.php b/api/admin.php index b77708cac..d2fe1845e 100644 --- a/api/admin.php +++ b/api/admin.php @@ -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']) { diff --git a/api/takePic.php b/api/takePic.php index 39e05b57a..fc4774550 100644 --- a/api/takePic.php +++ b/api/takePic.php @@ -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; @@ -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); } } } diff --git a/lib/config.php b/lib/config.php index 93a3b4482..79f4a4ea7 100644 --- a/lib/config.php +++ b/lib/config.php @@ -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'; diff --git a/lib/configsetup.inc.php b/lib/configsetup.inc.php index 07bb42e24..ad197ab44 100644 --- a/lib/configsetup.inc.php +++ b/lib/configsetup.inc.php @@ -538,7 +538,7 @@ 'placeholder' => $defaultConfig['textonpicture']['linespace'], 'name' => 'textonpicture[linespace]', 'value' => $config['textonpicture']['linespace'], - ], + ] ], 'collage' => [ 'view' => 'basic', @@ -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',