diff --git a/root/app/www/public/ajax/settings.php b/root/app/www/public/ajax/settings.php new file mode 100644 index 0000000..f729370 --- /dev/null +++ b/root/app/www/public/ajax/settings.php @@ -0,0 +1,35 @@ + $val) { + if (str_equals_any($key, ['m', 'apikey'])) { + continue; + } + + $newSettings[$key] = $val; + } + + $proxyDb->setSettings($newSettings, $settingsTable); + + if ($_POST['apikey'] && $_POST['apikey'] != APP_APIKEY) { + file_put_contents(APP_APIKEY_FILE, $_POST['apikey']); + } +} diff --git a/root/app/www/public/includes/constants.php b/root/app/www/public/includes/constants.php index fb6d5ce..bbf1ce3 100644 --- a/root/app/www/public/includes/constants.php +++ b/root/app/www/public/includes/constants.php @@ -11,8 +11,6 @@ define('APP_API_ERROR', APP_NAME .': %s'); define('APP_URL', ($_SERVER['REQUEST_SCHEME'] ?: 'http') . '://'. $_SERVER['HTTP_HOST']); -define('LOG_AGE', 2); //-- DELETE AFTER THIS AMOUNT OF DAYS -define('BACKUP_AGE', 7); //-- DELETE AFTER THIS AMOUNT OF DAYS define('STARR_BACKUP_AGE', 2); //-- DELETE AFTER THIS AMOUNT OF DAYS //-- DATABASE @@ -45,5 +43,4 @@ define('SYSTEM_LOG', LOGS_PATH . 'system/app.log'); define('MIGRATION_LOG', LOGS_PATH . 'system/migrations.log'); define('CRON_HOUSEKEEPER_LOG', LOGS_PATH . 'system/cron-housekeeper.log'); -define('LOG_ROTATE_SIZE', 2); //-- MB UNTIL ROTATE define('LOG_LINES_PER_PAGE', 1000); diff --git a/root/app/www/public/js/settings.js b/root/app/www/public/js/settings.js new file mode 100644 index 0000000..c3a55ea --- /dev/null +++ b/root/app/www/public/js/settings.js @@ -0,0 +1,25 @@ +function saveSettings() +{ + let params = []; + + $.each($('[id^=setting-]'), function() { + let val = ''; + if ($(this).is(':checkbox') || $(this).is(':radio')) { + val = $(this).prop('checked') ? 1 : 0; + } else { + val = $(this).val(); + } + + params += '&' + $(this).attr('id').replace('setting-', '') + '=' + val; + }); + + $.ajax({ + type: 'POST', + url: 'ajax/settings.php', + data: '&m=saveSettings' + params, + success: function (resultData) { + toast('Settings', 'The settings have been updated', 'success'); + } + }); +} +// ------------------------------------------------------------------------------------------- diff --git a/root/app/www/public/loader.php b/root/app/www/public/loader.php index 6ab1aca..af873da 100644 --- a/root/app/www/public/loader.php +++ b/root/app/www/public/loader.php @@ -21,6 +21,11 @@ } } +//-- USED FOR MIGRATIONS, DEFINES SET BELOW +$LOG_ROTATE_SIZE = 2; //-- MB UNTIL ROTATE +$LOG_AGE = 2; //-- DELETE AFTER THIS AMOUNT OF DAYS +$BACKUP_AGE = 7; //-- DELETE AFTER THIS AMOUNT OF DAYS + //-- SETUP SOME SHARED VARIABLES $page = $_GET['page'] ?: $_POST['page']; $app = $_GET['app'] ?: $_POST['app']; @@ -70,6 +75,7 @@ //-- LOAD THE TABLES $starrsTable = $proxyDb->getStarrsTable(); $appsTable = $proxyDb->getAppsTable(); +$settingsTable = $proxyDb->getSettings(); $usageTable = $usageDb->getUsageTable(); //-- SOMETIMES THE TABLE IS BUSY, RETRY @@ -77,3 +83,8 @@ sleep(1); $usageTable = $usageDb->getUsageTable(); } + +//-- CONSTANTS BASED ON DATABASE SETTINGS +define('LOG_ROTATE_SIZE', $settingsTable['logRotationSize'] ?: $LOG_ROTATE_SIZE); +define('LOG_AGE', $settingsTable['logRetentionLength'] ?: $LOG_AGE); +define('BACKUP_AGE', $settingsTable['backupRetentionLength'] ?: $BACKUP_AGE); diff --git a/root/app/www/public/migrations/002_settings.php b/root/app/www/public/migrations/002_settings.php new file mode 100644 index 0000000..4585596 --- /dev/null +++ b/root/app/www/public/migrations/002_settings.php @@ -0,0 +1,43 @@ + $BACKUP_AGE, + 'logRotationSize' => $LOG_ROTATE_SIZE, + 'logRetentionLength' => $LOG_AGE, + ]; + +$settingRows = []; +foreach ($settings as $key => $val) { + $settingRows[] = "('" . $key . "', '" . $val . "')"; +} + +$q[] = "INSERT INTO " . SETTINGS_TABLE . " + (`name`, `value`) + VALUES " . implode(', ', $settingRows); + +foreach ($q as $query) { + logger(MIGRATION_LOG, '[Q] ' . preg_replace('!\s+!', ' ', $query)); + + $proxyDb->query($query); + + if ($proxyDb->error() != 'not an error') { + logger(MIGRATION_LOG, '[R] ' . $proxyDb->error(), 'error'); + } else { + logger(MIGRATION_LOG, '[R] query applied!'); + } +} diff --git a/root/app/www/public/pages/settings.php b/root/app/www/public/pages/settings.php index dbd6508..ece12e0 100644 --- a/root/app/www/public/pages/settings.php +++ b/root/app/www/public/pages/settings.php @@ -14,3 +14,102 @@ if (!$_SESSION['IN_UI']) { exit('Invalid session, refresh the page'); } + +$migrations = ''; +$dir = opendir(MIGRATIONS_PATH); +while ($migration = readdir($dir)) { + if (str_contains($migration, '.php')) { + $migrations .= ''; + } +} +closedir($dir); + +?> +
+ +
+
+
+
+
System
+
+
+ + + + + + + +
+ API key
+ File: +
+
+ + +
+
+
+
+
+
+
+
+
Database
+
+
+ + + + + + + + + + + +
+ Migration
+ Newest: getNewestMigration() ?> +
+ + If you change this, refresh the page after you click save. +
+ Backup retention length
+ Default: +
days
+
+
+
+
+
+
+
Logging
+
+
+ + + + + + + + + + + +
+ Rotation size
+ Default: +
MiB
+ Log retention length
+ Default: +
days
+
+
+
+
+
+