Skip to content

Commit

Permalink
admin: improve logging
Browse files Browse the repository at this point in the history
Change-Id: I6186bf0de529ba46bcd125f5aec54456ccdaa0ff
  • Loading branch information
andi34 committed Sep 24, 2022
1 parent 4bda966 commit d65a14f
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions api/admin.php
Expand Up @@ -4,13 +4,22 @@
require_once '../lib/config.php';
require_once '../lib/db.php';

$LogData = [
'php' => basename($_SERVER['PHP_SELF']),
];

$data = $_POST;
if (!isset($data['type'])) {
echo json_encode('error');
$LogData[] = ['type' => 'ERROR: Unknown action.'];
logError($LogData);
die(json_encode('error'));
}

if ($data['type'] == 'reset') {
$LogData[] = ['reset' => 'Resetting Photobooth'];

if ($config['reset']['remove_images']) {
$LogData[] = ['remove_images' => 'Removing images'];
// empty folders
foreach ($config['foldersAbs'] as $folder) {
if (is_dir($folder)) {
Expand All @@ -20,6 +29,7 @@
if (is_file($file)) {
// delete file
unlink($file);
$LogData[] = [$file => 'deleted'];
}
}
}
Expand All @@ -29,13 +39,15 @@
if ($config['reset']['remove_mailtxt']) {
if (is_file(MAIL_FILE)) {
unlink(MAIL_FILE); // delete file
$LogData[] = [MAIL_FILE => 'deleted'];
}
}

if ($config['reset']['remove_config']) {
// delete personal config
if (is_file('../config/my.config.inc.php')) {
unlink('../config/my.config.inc.php');
$LogData[] = ['my.config.inc.php' => 'deleted'];
}
}

Expand All @@ -45,20 +57,24 @@
if (is_file($logFile)) {
// delete file
unlink($logFile);
$LogData[] = [$logFile => 'deleted'];
}
}

// delete db.txt
if (is_file(DB_FILE)) {
// delete file
unlink(DB_FILE);
$LogData[] = [DB_FILE => 'deleted'];
}

logError($LogData);
die(json_encode('success'));
}

if ($data['type'] == 'config') {
$newConfig = [];
$LogData[] = ['config' => 'Saving Photobooth configuration'];

foreach ($config as $k => $conf) {
if (is_array($conf)) {
Expand Down Expand Up @@ -94,11 +110,7 @@
}
} else {
$newConfig['login']['enabled'] = false;
$LogData = [
'error' => 'Password not set. Login disabled.',
'php' => basename($_SERVER['PHP_SELF']),
];
logError($LogData);
$LogData[] = ['login' => 'Password not set. Login disabled.'];
}
} else {
$newConfig['login']['password'] = null;
Expand All @@ -107,10 +119,8 @@
if ($newConfig['preview']['camTakesPic'] && $newConfig['preview']['mode'] != 'device_cam' && $newConfig['preview']['mode'] != 'gphoto') {
$newConfig['preview']['camTakesPic'] = false;
$LogData = [
'error' => 'Device cam takes picture disabled. Can take images from preview only from gphoto2 and device cam preview.',
'php' => basename($_SERVER['PHP_SELF']),
'preview' => 'Device cam takes picture disabled. Can take images from preview only from gphoto2 and device cam preview.',
];
logError($LogData);
}

if ($newConfig['ui']['style'] === 'custom') {
Expand All @@ -122,11 +132,9 @@
!is_readable('../resources/css/custom_live_chromakeying.css')
) {
$newConfig['ui']['style'] = 'modern_squared';
$LogData = [
'error' => 'No custom style resources found. Falling back to modern squared style.',
'php' => basename($_SERVER['PHP_SELF']),
$LogData[] = [
'ui' => 'No custom style resources found. Falling back to modern squared style.',
];
logError($LogData);
} else {
if (!file_exists('../template/custom.template.php')) {
copy('../template/modern.template.php', '../template/custom.template.php');
Expand All @@ -147,14 +155,17 @@
}

if (SERVER_OS === 'windows') {
if (!empty($newConfig['remotebuzzer']['enabled']) || !empty($newConfig['synctodrive']['enabled'])) {
if (!empty($newConfig['remotebuzzer']['enabled'])) {
$newConfig['remotebuzzer']['enabled'] = false;
$LogData[] = [
'remotebuzzer' => 'Remotebuzzer server unsupported on Windows.',
];
}
if (!empty($newConfig['synctodrive']['enabled'])) {
$newConfig['synctodrive']['enabled'] = false;
$LogData = [
'error' => 'Remotebuzzer and Sync pictures to USB stick unsupported on Windows.',
'php' => basename($_SERVER['PHP_SELF']),
$LogData[] = [
'synctodrive' => 'Sync pictures to USB stick unsupported on Windows.',
];
logError($LogData);
}
}

Expand All @@ -174,11 +185,9 @@
if (isset($newConfig['get_request']['server']) && empty($newConfig['get_request']['server'])) {
$newConfig['get_request']['countdown'] = false;
$newConfig['get_request']['processed'] = false;
$LogData = [
'error' => 'No GET request server entered. Disabled GET request options.',
'php' => basename($_SERVER['PHP_SELF']),
$LogData[] = [
'get_request' => 'No GET request server entered. Disabled GET request options.',
];
logError($LogData);
}
}

Expand Down Expand Up @@ -211,12 +220,16 @@

if (file_put_contents($my_config_file, $content)) {
clearCache($my_config_file);
$LogData[] = ['config' => 'New config saved'];

echo json_encode('success');
} else {
$LogData[] = ['config' => 'ERROR: Config can not be saved!'];

echo json_encode('error');
}
}
logError($LogData);

/* Kill service daemons after config has changed */
require_once '../lib/services_stop.php';
Expand Down

0 comments on commit d65a14f

Please sign in to comment.