From f27e734fc07c381f4e51cec50bdb2fc4e1155848 Mon Sep 17 00:00:00 2001 From: ChrisWi Date: Fri, 5 Jan 2018 03:12:14 +0100 Subject: [PATCH] make Quota configurable, add Soft-/Hard-Quota [Min|Max] --- setup.php | 10 ++++++++++ weave_utils.php | 28 +++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/setup.php b/setup.php index 27916d1..01868c3 100644 --- a/setup.php +++ b/setup.php @@ -23,6 +23,7 @@ # Contributor(s): # Daniel Triendl # balu +# Christian Wittmer # # Alternatively, the contents of this file may be used under the terms of # either the GNU General Public License Version 2 or later (the "GPL"), or @@ -156,6 +157,15 @@ function write_config_file($dbt, $dbh, $dbn, $dbu, $dbp, $fsRoot) { $cfg_content .= " define(\"BCRYPT\", true);\n"; $cfg_content .= " define(\"BCRYPT_ROUNDS\", 12);\n"; + $cfg_content .= "\n"; + $cfg_content .= " // you can enable logging to syslog for MINQUOTA_ERROR_OVER_QUOTA\n"; + $cfg_content .= " // if (quota_used > MINQUOTA && quota_used < MAXQUOTA)\n"; + $cfg_content .= " define(\"MINQUOTA_LOG_ERROR_OVER_QUOTA_ENABLE\", false);\n"; + $cfg_content .= "\n"; + $cfg_content .= " // set MinQuota and MaxQuota\n"; + $cfg_content .= " define(\"MINQUOTA\", 30000);\n"; + $cfg_content .= " define(\"MAXQUOTA\", 35000);\n"; + $cfg_content .= "\n?>\n"; // now write everything diff --git a/weave_utils.php b/weave_utils.php index ae3371a..3868b84 100644 --- a/weave_utils.php +++ b/weave_utils.php @@ -21,6 +21,7 @@ # Contributor(s): # Daniel Triendl # Mark Straver +# Christian Wittmer # # Alternatively, the contents of this file may be used under the terms of # either the GNU General Public License Version 2 or later (the "GPL"), or @@ -257,20 +258,29 @@ function check_quota(&$db) { - // Checks the quota and if over limit, returns "over quota" to the user. - $auth_user = array_key_exists('PHP_AUTH_USER', $_SERVER) ? $_SERVER['PHP_AUTH_USER'] : null; - try { + // Checks the quota and if over limit, returns "over quota" to the user. + $auth_user = array_key_exists('PHP_AUTH_USER', $_SERVER) ? $_SERVER['PHP_AUTH_USER'] : null; + try { $quota_used = $db->get_storage_total(); // log_quota("Debug quota: ".$auth_user." @ ".$quota_used." KB."); } catch (Exception $e) { log_error($e->getMessage(), $e->getCode()); } - - if ($quota_used > 35000) { - log_quota("[!!] Over quota: ".$auth_user." @ ".$quota_used." KB."); - // HTTP 400 with body error code 14 means over quota. - report_problem(WEAVE_ERROR_OVER_QUOTA, 400); - } + + if ((defined("MINQUOTA") && MINQUOTA) && (defined("MAXQUOTA") && MAXQUOTA)) { + if ($quota_used > MINQUOTA && $quota_used < MAXQUOTA) { + report_problem(WEAVE_ERROR_OVER_QUOTA, 400); + log_quota("[!!] Over quota [MINQUOTA:MAXQUOTA]: ".$auth_user." @ ".$quota_used." KB."); + if (defined(MINQUOTA_LOG_ERROR_OVER_QUOTA_ENABLE) && MINQUOTA_LOG_ERROR_OVER_QUOTA_ENABLE) { + log_error(" MinQUOTA exceeding: ".$quota_used." KB."); + } + } + if ($quota_used > MAXQUOTA) { + log_quota("[!!] Over quota: ".$auth_user." @ ".$quota_used." KB."); + // HTTP 400 with body error code 14 means over quota. + report_problem(WEAVE_ERROR_OVER_QUOTA, 400); + } + } } function check_timestamp($collection, &$db)