diff --git a/config.php b/config.php index 2af910b..0980c66 100644 --- a/config.php +++ b/config.php @@ -28,15 +28,15 @@ require_once "include/initialize.inc.php"; if ($_SERVER["REQUEST_METHOD"] == "GET") { - $message = ""; - if (isset($_GET["message"])) { - switch ($_GET["message"]) { - case "edited": - $message = "The config has been edited"; break; - } - } - - $error = ""; + $message = ""; + if (isset($_GET["message"])) { + switch ($_GET["message"]) { + case "edited": + $message = "The config has been edited"; break; + } + } + + $error = ""; if (isset($_GET["error"])) { switch ($_GET["error"]) { case "emptyfields": @@ -45,28 +45,28 @@ if ($_SERVER["REQUEST_METHOD"] == "GET") { } - $loader = new Twig_Loader_Filesystem('templates'); - $twig = new Twig_Environment($loader, array('cache' => 'cache', "debug" => true)); + $loader = new Twig_Loader_Filesystem('templates'); + $twig = new Twig_Environment($loader, array('cache' => 'cache', "debug" => true)); - $configs = load_config_categorized(); + $configs = load_config_categorized(); - $twig_vars = array('config' => $configs, "error" => $error, "message" => $message); + $twig_vars = array('config' => $configs, "error" => $error, "message" => $message); - echo $twig->render('config.html.twig', $twig_vars); + echo $twig->render('config.html.twig', $twig_vars); } elseif ($_SERVER["REQUEST_METHOD"] == "POST") { - foreach($_POST as $key => $value) { - if (empty($value)) { - header("location:config.php?error=emptyfields"); exit; - } + foreach($_POST as $key => $value) { + if (empty($value)) { + header("location:config.php?error=emptyfields"); exit; + } - $keydb = str_replace('_', '.', $key); - $stmt = $db->prepare("UPDATE config SET value = ? WHERE conf = ?"); - $stmt->execute(array($value, $keydb)); - } + $keydb = str_replace('_', '.', $key); + $stmt = $db->prepare("UPDATE config SET value = ? WHERE conf = ?"); + $stmt->execute(array($value, $keydb)); + } - header("location:config.php?message=edited"); + header("location:config.php?message=edited"); exit; } diff --git a/database.sql b/database.sql index 30782fe..9363272 100644 --- a/database.sql +++ b/database.sql @@ -36,7 +36,9 @@ CREATE TABLE IF NOT EXISTS `config` ( -- INSERT INTO `config` (`conf`, `category`, `type`, `label`, `description`, `value`) VALUES -('dbclean.expireruns', 'Database Cleanup', 'number(0,-1)', 'Retention value', 'How many days does the database keep the runs', '30'), +('dbclean.delay', 'Database Cleanup', 'number(0)', 'Cleanup Delay', 'How many days until the database cleanup is triggered', '7'), +('dbclean.expireruns', 'Database Cleanup', 'number(0)', 'Retention value', 'How many days does the database keep the runs', '30'), +('dbclean.lastrun', 'Database Cleanup', 'hidden', 'Last run', 'Last run of database cleanup', UNIX_TIMESTAMP()), ('jobs.reboottime', 'Jobs', 'number(0,30)', 'Reboot delay', 'The amount of delay in minutes between scheduling a reboot and the actual reboot', '5'); -- -------------------------------------------------------- diff --git a/include/functions.php b/include/functions.php index f1c220b..6fb9d07 100644 --- a/include/functions.php +++ b/include/functions.php @@ -48,7 +48,8 @@ function load_config_categorized() { $configCategorized[$value['category']][$count]['label'] = $value['label']; $configCategorized[$value['category']][$count]['description'] = $value['description']; $configCategorized[$value['category']][$count]['type'] = parse_config_type($value['type']); - $count++; + + if ($configCategorized[$value['category']][$count]['type']['type'] != 'hidden') $count++; } // into a easy twig array @@ -74,18 +75,20 @@ function get_configvalue($conf) { } function parse_config_type($type) { - $splittype = explode('(', substr($type, 0, -1)); + $splittype = explode('(', explode(')', $type)[0]); $r_var['type'] = $splittype[0]; - $splitargs = explode(',', $splittype[1]); + if (isset($splittype[1])) { + $splitargs = explode(',', $splittype[1]); - switch($r_var['type']) - { - case 'number': - $r_var['args'][] = $splitargs[0] != '-1' ? 'min="' . $splitargs[0] . '"' : ''; - $r_var['args'][] = $splitargs[1] != '-1' ? 'max="' . $splitargs[1] . '"' : ''; - break; - } + switch($r_var['type']) + { + case 'number': + $r_var['args'][] = isset($splitargs[0]) ? 'min="' . $splitargs[0] . '"' : ''; + $r_var['args'][] = isset($splitargs[1]) ? 'max="' . $splitargs[1] . '"' : ''; + break; + } + } return $r_var; } @@ -96,4 +99,7 @@ function clean_database() { $stmt = $db->prepare("DELETE FROM runs WHERE timestamp < ?"); $stmt->execute(array($oldestrun)); + + $stmt = $db->prepare("UPDATE config SET value = ? WHERE conf = ?"); + $stmt->execute(array(time(), 'dbclean.lastrun')); } \ No newline at end of file diff --git a/webcron.php b/webcron.php index 20a8109..9a12cf6 100644 --- a/webcron.php +++ b/webcron.php @@ -105,7 +105,7 @@ foreach ($results as $result) { $nosave = false; } -clean_database(); +if (get_configvalue('dbclean.lastrun') + (60 * 60 * 24 * get_configvalue('dbclean.delay')) < time()) clean_database(); unlink('/tmp/webcron.lock');