commit 9aabd8bd77252a8e2a6e741908621acee15254ae
parent f0355bd31b3e8a361c5e71d5aa7af4ffcac59697
Author: Jan Dankert <develop@jandankert.de>
Date: Wed, 21 Apr 2021 21:15:17 +0200
New: Accept human readable values for durations and memory sizes in the configuration.
Diffstat:
3 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/modules/cms/auth/InternalAuth.class.php b/modules/cms/auth/InternalAuth.class.php
@@ -67,7 +67,7 @@ SQL
// Wenn das kennwort abgelaufen ist, kann es eine bestimmte Dauer noch benutzt und geändert werden.
// Nach Ablauf dieser Dauer wird das Login abgelehnt.
- if ($row_user['password_expires'] + (Configuration::subset('security')->get('deny_after_expiration_duration',72) * 60 * 60) < time())
+ if ($row_user['password_expires'] + (Configuration::subset('security')->getSeconds('deny_after_expiration_duration',3*24*60*60)) < time())
return Auth::STATUS_FAILED + Auth::STATUS_PW_EXPIRED; // Abgelaufenes Kennwort wird nicht mehr akzeptiert.
else
return Auth::STATUS_SUCCESS + Auth::STATUS_PW_EXPIRED; // Kennwort ist abgelaufen, kann aber noch geändert werden.
diff --git a/modules/cms/base/DefaultConfig.class.php b/modules/cms/base/DefaultConfig.class.php
@@ -579,7 +579,7 @@ class DefaultConfig {
'random_length' => 10,
'min_length' => 6,
'pepper' => '',
- 'deny_after_expiration_duration' => 72,
+ 'deny_after_expiration_duration' => '3d',
'force_change_if_cleartext' => false,
],
'http' =>
diff --git a/modules/configuration/Config.class.php b/modules/configuration/Config.class.php
@@ -66,6 +66,42 @@ class Config
}
+ /**
+ * Gets the configuration value in seconds for this key.
+ *
+ * @param $name
+ * @param null $default
+ * @return int
+ */
+ public function getSeconds( $name, $default = 0 ) {
+ return $this->parseSuffix( $this->get( $name, (string)$default ),[
+ 's' => 1, // seconds
+ 'm' => 60, // minutes
+ 'h' => 60*60, // hours
+ 'd' => 60*60*24, // days
+ 'y' => 60*60*24*365, // years
+ ] );
+ }
+
+ /**
+ * Gets the configuration value in bytes for this key.
+ *
+ * @param $name
+ * @param null $default
+ * @return int
+ */
+ public function getBytes( $name, $default = 0 ) {
+ return $this->parseSuffix( $this->get( $name, (string)$default ),[
+ 'b' => 1, // bytes
+ 'k' => 1024, // kibibyte
+ 'm' => 1024*1024, // mibibyte
+ 'g' => 1024*1024*1024, // gibibyte
+ 't' => 1024*1024*1024*1024, // tebibyte
+ 'p' => 1024*1024*1024*1024*1024, // pebibyte
+ // exabyte, zettabyte, yottabyte, google, buuum...
+ ] );
+ }
+
/**
* Gets the configuration value for this key.
*
@@ -147,4 +183,14 @@ class Config
{
return !$this->isEmpty();
}
+
+ private function parseSuffix( $value, array $map)
+ {
+ $suffix = substr($value,-1,1);
+ $value = substr($value,1);
+ if ( isset($map[$suffix] ) )
+ return $value * $map[$suffix];
+ else
+ return (int) $value;
+ }
}
\ No newline at end of file