From e19ef43bb43bf6f0393f6432ddad6242f28a8678 Mon Sep 17 00:00:00 2001 From: Christian Tarne Date: Wed, 21 Jul 2021 13:40:45 +0200 Subject: [PATCH 1/5] add logging to takePic.php --- .gitignore | 1 + admin/logview.php | 81 +++++++++++++++++++++++++++++++++++++++++ api/takePic.php | 48 ++++++++++++++++-------- lib/config.php | 1 + lib/configsetup.inc.php | 13 +++++++ resources/lang/en.json | 4 ++ src/js/admin.js | 8 ++++ 7 files changed, 140 insertions(+), 16 deletions(-) create mode 100644 admin/logview.php 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/admin/logview.php b/admin/logview.php new file mode 100644 index 000000000..683b5b2da --- /dev/null +++ b/admin/logview.php @@ -0,0 +1,81 @@ + + + + + + + + + + + + <?=$config['ui']['branding']?> Logfiles + + + + + + + + + + + + + + + + + + + + + +
+

+ +
+
+	
+ +
+
+ adminsettings +
+
+ + + + + + + + + + + + diff --git a/api/takePic.php b/api/takePic.php index 39e05b57a..696a6e4ef 100644 --- a/api/takePic.php +++ b/api/takePic.php @@ -4,6 +4,19 @@ 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"; + $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 +42,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 4378391ab..df3249aae 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 7a0b1d3b9..429a0d7f8 100644 --- a/lib/configsetup.inc.php +++ b/lib/configsetup.inc.php @@ -532,6 +532,13 @@ 'name' => 'textonpicture[linespace]', 'value' => $config['textonpicture']['linespace'], ], + 'logfile_button' => [ + 'view' => 'basic', + 'type' => 'button', + 'placeholder' => 'pictures:logfile', + 'name' => 'PICTURELOGBUTTON', + 'value' => 'pictures-logfile-btn', + ], ], 'collage' => [ 'view' => 'basic', @@ -1731,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', diff --git a/resources/lang/en.json b/resources/lang/en.json index 682bdddd8..a6b1fe016 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -63,6 +63,7 @@ "degrees": "°", "delete": "Delete", "disk_usage": "Disk Usage", + "log_viewer": "Logfile viewer", "dot": ".", "download_zip": "Download data folder as zip", "error": "Something went wrong. Please try it again.", @@ -327,6 +328,7 @@ "manual:pictures:textonpicture_locationx": "X-Coordinates of the text while adding text to your picture.", "manual:pictures:textonpicture_locationy": "Y-Coordinates of the text while adding text to your picture.", "manual:pictures:textonpicture_rotation": "Enter a value which is used as degrees the text on your gets rotated.", + "manual:pictures:logfile_button": "Show the error log of the camera API to troubleshoot taking images.", "manual:preview:preview_asBackground": "If enabled, a stream from your device cam is used as background on start screen.", "manual:preview:preview_camTakesPic": "If enabled, a picture is taken from device cam instead executing the \"Take picture command\". Please note that the resolution depends on the given hight and width because it's acts like taking a screenshot.", "manual:preview:preview_camera_mode": "Choose between front- or back facing camera mode of your device cam.", @@ -430,6 +432,8 @@ "pictures:textonpicture_locationx": "X Coordinate", "pictures:textonpicture_locationy": "Y Coordinate", "pictures:textonpicture_rotation": "Text rotation", + "pictures:logfile": "View", + "pictures:logfile_button": "View error log", "preview": "Live preview", "preview:preview_asBackground": "Use stream from device cam as background", "preview:preview_camTakesPic": "Device cam takes picture", diff --git a/src/js/admin.js b/src/js/admin.js index 635fa7185..3a310e287 100644 --- a/src/js/admin.js +++ b/src/js/admin.js @@ -139,6 +139,14 @@ $(function () { }); }); + $('#pictures-logfile-btn').on('click', function (e) { + e.preventDefault(); + location.assign('logview.php'); + + return false; + }); + + // Admin Panel active section at init $('#nav-general').addClass('active'); From 8250087dd97eaa9bf35bcf9822dfe3875dfbeaa2 Mon Sep 17 00:00:00 2001 From: Christian Tarne Date: Thu, 29 Jul 2021 12:19:44 +0200 Subject: [PATCH 2/5] fix php error messages, delete log file when pictures are deleted --- admin/logview.php | 5 ++++- api/admin.php | 5 +++++ api/takePic.php | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/admin/logview.php b/admin/logview.php index 683b5b2da..7e10d20b5 100644 --- a/admin/logview.php +++ b/admin/logview.php @@ -55,7 +55,10 @@
 
 	
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 696a6e4ef..fc4774550 100644 --- a/api/takePic.php +++ b/api/takePic.php @@ -9,7 +9,8 @@ function logError($data) { $logfile = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $config['take_picture']['logfile']; $file_data = date('c') . ":\n" . print_r($data, true) . "\n"; - $file_data .= file_get_contents($logfile); + 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. From 68267f2ac80907bfa4fe1565bbd32398873ef66d Mon Sep 17 00:00:00 2001 From: Christian Tarne Date: Thu, 29 Jul 2021 12:33:27 +0200 Subject: [PATCH 3/5] add german translation for error log --- resources/lang/de.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/lang/de.json b/resources/lang/de.json index dd38af844..45b74b81a 100644 --- a/resources/lang/de.json +++ b/resources/lang/de.json @@ -61,6 +61,7 @@ "disk_usage": "Festplattenbelegung", "dot": ".", "download_zip": "Datenordner als Zip-Datei herunterladen", + "log_viewer": "Logdatei-Anzeige", "error": "Es ist ein Fehler aufgetreten, bitte versuche es erneut.", "event": "Veranstaltungen", "filecount": "Anzahl der Dateien im Ordner:", @@ -318,6 +319,7 @@ "manual:pictures:textonpicture_locationx": "X-Koordinaten des Textes beim Hinzufügen von Text auf Bilder.", "manual:pictures:textonpicture_locationy": "Y-Koordinaten des Textes beim Hinzufügen von Text auf Bilder.", "manual:pictures:textonpicture_rotation": "Geben Sie einen Wert ein, der als Grad verwendet wird, um die der Text auf dem Bild gedreht wird.", + "manual:pictures:logfile_button": "Anzeigen der Fehler-Logdatei vom Aufnehmen der Fotos.", "manual:preview:preview_asBackground": "Wenn diese Option aktiviert ist, wird ein Stream von Ihrer Gerätekamera als Hintergrund auf dem Startbildschirm verwendet.", "manual:preview:preview_camTakesPic": "Wenn diese Option aktiviert ist, wird ein Bild von der Gerätekamera aufgenommen, anstatt den Befehl \"Bild aufnehmen\" auszuführen. Bitte beachten Sie, dass die Auflösung des Bildes von der angegebenen Höhe und Breite abhängt, da dies wie ein Screenshot aufgenommen wird.", "manual:preview:preview_camera_mode": "Wählen Sie den Kameramodus Ihrer Gerätekamera (Kamera mit Blick nach vorne oder hinten).", @@ -411,6 +413,8 @@ "pictures:textonpicture_locationx": "X-Koordinaten", "pictures:textonpicture_locationy": "Y-Koordinaten", "pictures:textonpicture_rotation": "Textdrehung", + "pictures:logfile": "Anzeigen", + "pictures:logfile_button": "Fehler-Log anzeigen", "preview": "Live-Vorschau", "preview:preview_asBackground": "Stream der Gerätekamera als Hintergrund nutzen", "preview:preview_camTakesPic": "Gerätekamera zur Bildaufnahme verwenden", From d8fec48abb295b855c64595371db25ffd97b7290 Mon Sep 17 00:00:00 2001 From: Christian Tarne Date: Thu, 29 Jul 2021 13:46:40 +0200 Subject: [PATCH 4/5] fix lint error --- src/js/admin.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/js/admin.js b/src/js/admin.js index 3a310e287..5c8fb669b 100644 --- a/src/js/admin.js +++ b/src/js/admin.js @@ -145,7 +145,6 @@ $(function () { return false; }); - // Admin Panel active section at init $('#nav-general').addClass('active'); From 870937bfd7c4fc89c9b5530fc9ac6b496206c00b Mon Sep 17 00:00:00 2001 From: Christian Tarne Date: Fri, 30 Jul 2021 10:35:13 +0200 Subject: [PATCH 5/5] Revert UI changes in preparation to add the picture log to debug panel --- admin/logview.php | 84 ----------------------------------------- lib/configsetup.inc.php | 9 +---- resources/lang/de.json | 4 -- resources/lang/en.json | 4 -- src/js/admin.js | 7 ---- 5 files changed, 1 insertion(+), 107 deletions(-) delete mode 100644 admin/logview.php diff --git a/admin/logview.php b/admin/logview.php deleted file mode 100644 index 7e10d20b5..000000000 --- a/admin/logview.php +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - <?=$config['ui']['branding']?> Logfiles - - - - - - - - - - - - - - - - - - - - - - - -
-
- adminsettings -
-
- - - - - - - - - - - - diff --git a/lib/configsetup.inc.php b/lib/configsetup.inc.php index 429a0d7f8..3dc6c2952 100644 --- a/lib/configsetup.inc.php +++ b/lib/configsetup.inc.php @@ -531,14 +531,7 @@ 'placeholder' => $defaultConfig['textonpicture']['linespace'], 'name' => 'textonpicture[linespace]', 'value' => $config['textonpicture']['linespace'], - ], - 'logfile_button' => [ - 'view' => 'basic', - 'type' => 'button', - 'placeholder' => 'pictures:logfile', - 'name' => 'PICTURELOGBUTTON', - 'value' => 'pictures-logfile-btn', - ], + ] ], 'collage' => [ 'view' => 'basic', diff --git a/resources/lang/de.json b/resources/lang/de.json index 45b74b81a..dd38af844 100644 --- a/resources/lang/de.json +++ b/resources/lang/de.json @@ -61,7 +61,6 @@ "disk_usage": "Festplattenbelegung", "dot": ".", "download_zip": "Datenordner als Zip-Datei herunterladen", - "log_viewer": "Logdatei-Anzeige", "error": "Es ist ein Fehler aufgetreten, bitte versuche es erneut.", "event": "Veranstaltungen", "filecount": "Anzahl der Dateien im Ordner:", @@ -319,7 +318,6 @@ "manual:pictures:textonpicture_locationx": "X-Koordinaten des Textes beim Hinzufügen von Text auf Bilder.", "manual:pictures:textonpicture_locationy": "Y-Koordinaten des Textes beim Hinzufügen von Text auf Bilder.", "manual:pictures:textonpicture_rotation": "Geben Sie einen Wert ein, der als Grad verwendet wird, um die der Text auf dem Bild gedreht wird.", - "manual:pictures:logfile_button": "Anzeigen der Fehler-Logdatei vom Aufnehmen der Fotos.", "manual:preview:preview_asBackground": "Wenn diese Option aktiviert ist, wird ein Stream von Ihrer Gerätekamera als Hintergrund auf dem Startbildschirm verwendet.", "manual:preview:preview_camTakesPic": "Wenn diese Option aktiviert ist, wird ein Bild von der Gerätekamera aufgenommen, anstatt den Befehl \"Bild aufnehmen\" auszuführen. Bitte beachten Sie, dass die Auflösung des Bildes von der angegebenen Höhe und Breite abhängt, da dies wie ein Screenshot aufgenommen wird.", "manual:preview:preview_camera_mode": "Wählen Sie den Kameramodus Ihrer Gerätekamera (Kamera mit Blick nach vorne oder hinten).", @@ -413,8 +411,6 @@ "pictures:textonpicture_locationx": "X-Koordinaten", "pictures:textonpicture_locationy": "Y-Koordinaten", "pictures:textonpicture_rotation": "Textdrehung", - "pictures:logfile": "Anzeigen", - "pictures:logfile_button": "Fehler-Log anzeigen", "preview": "Live-Vorschau", "preview:preview_asBackground": "Stream der Gerätekamera als Hintergrund nutzen", "preview:preview_camTakesPic": "Gerätekamera zur Bildaufnahme verwenden", diff --git a/resources/lang/en.json b/resources/lang/en.json index a6b1fe016..682bdddd8 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -63,7 +63,6 @@ "degrees": "°", "delete": "Delete", "disk_usage": "Disk Usage", - "log_viewer": "Logfile viewer", "dot": ".", "download_zip": "Download data folder as zip", "error": "Something went wrong. Please try it again.", @@ -328,7 +327,6 @@ "manual:pictures:textonpicture_locationx": "X-Coordinates of the text while adding text to your picture.", "manual:pictures:textonpicture_locationy": "Y-Coordinates of the text while adding text to your picture.", "manual:pictures:textonpicture_rotation": "Enter a value which is used as degrees the text on your gets rotated.", - "manual:pictures:logfile_button": "Show the error log of the camera API to troubleshoot taking images.", "manual:preview:preview_asBackground": "If enabled, a stream from your device cam is used as background on start screen.", "manual:preview:preview_camTakesPic": "If enabled, a picture is taken from device cam instead executing the \"Take picture command\". Please note that the resolution depends on the given hight and width because it's acts like taking a screenshot.", "manual:preview:preview_camera_mode": "Choose between front- or back facing camera mode of your device cam.", @@ -432,8 +430,6 @@ "pictures:textonpicture_locationx": "X Coordinate", "pictures:textonpicture_locationy": "Y Coordinate", "pictures:textonpicture_rotation": "Text rotation", - "pictures:logfile": "View", - "pictures:logfile_button": "View error log", "preview": "Live preview", "preview:preview_asBackground": "Use stream from device cam as background", "preview:preview_camTakesPic": "Device cam takes picture", diff --git a/src/js/admin.js b/src/js/admin.js index 5c8fb669b..635fa7185 100644 --- a/src/js/admin.js +++ b/src/js/admin.js @@ -139,13 +139,6 @@ $(function () { }); }); - $('#pictures-logfile-btn').on('click', function (e) { - e.preventDefault(); - location.assign('logview.php'); - - return false; - }); - // Admin Panel active section at init $('#nav-general').addClass('active');