diff --git a/admin/debugpanel.php b/admin/debugpanel.php index 006911737..bb5878a33 100644 --- a/admin/debugpanel.php +++ b/admin/debugpanel.php @@ -89,7 +89,7 @@ function html_src_indent($num) echo '
  • myconfig
  • '; echo '
  • remotebuzzer
  • '; echo '
  • synctodrive
  • '; - echo '
  • cameralog
  • '; + echo '
  • cameralog
  • '; echo '
  • serverprocesses
  • '; echo '
  • bootconfig
  • '; diff --git a/api/admin.php b/api/admin.php index b77708cac..0acf40917 100644 --- a/api/admin.php +++ b/api/admin.php @@ -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']) { diff --git a/api/takePic.php b/api/takePic.php index 39e05b57a..186072d39 100644 --- a/api/takePic.php +++ b/api/takePic.php @@ -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; @@ -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); } } } 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..da3a0306d 100644 --- a/lib/configsetup.inc.php +++ b/lib/configsetup.inc.php @@ -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',