New Admin Panel settings (enableWebDAV & shareMaxUploadSize)
This commit is contained in:
@@ -5,6 +5,23 @@ require_once PROJECT_ROOT . '/config/config.php';
|
||||
|
||||
class AdminModel
|
||||
{
|
||||
/**
|
||||
* Parse a shorthand size value (e.g. "5G", "500M", "123K") into bytes.
|
||||
*
|
||||
* @param string $val
|
||||
* @return int
|
||||
*/
|
||||
private static function parseSize(string $val): int
|
||||
{
|
||||
$unit = strtolower(substr($val, -1));
|
||||
$num = (int) rtrim($val, 'bkmgtpezyBKMGTPESY');
|
||||
switch ($unit) {
|
||||
case 'g': return $num * 1024 ** 3;
|
||||
case 'm': return $num * 1024 ** 2;
|
||||
case 'k': return $num * 1024;
|
||||
default: return $num;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the admin configuration file.
|
||||
@@ -24,6 +41,28 @@ class AdminModel
|
||||
return ["error" => "Incomplete OIDC configuration."];
|
||||
}
|
||||
|
||||
// Ensure enableWebDAV flag is boolean (default to false if missing)
|
||||
$configUpdate['enableWebDAV'] = isset($configUpdate['enableWebDAV'])
|
||||
? (bool)$configUpdate['enableWebDAV']
|
||||
: false;
|
||||
|
||||
// Validate sharedMaxUploadSize if provided
|
||||
if (isset($configUpdate['sharedMaxUploadSize'])) {
|
||||
$sms = filter_var(
|
||||
$configUpdate['sharedMaxUploadSize'],
|
||||
FILTER_VALIDATE_INT,
|
||||
["options" => ["min_range" => 1]]
|
||||
);
|
||||
if ($sms === false) {
|
||||
return ["error" => "Invalid sharedMaxUploadSize."];
|
||||
}
|
||||
$totalBytes = self::parseSize(TOTAL_UPLOAD_SIZE);
|
||||
if ($sms > $totalBytes) {
|
||||
return ["error" => "sharedMaxUploadSize must be ≤ TOTAL_UPLOAD_SIZE."];
|
||||
}
|
||||
$configUpdate['sharedMaxUploadSize'] = $sms;
|
||||
}
|
||||
|
||||
// Convert configuration to JSON.
|
||||
$plainTextConfig = json_encode($configUpdate, JSON_PRETTY_PRINT);
|
||||
if ($plainTextConfig === false) {
|
||||
@@ -59,7 +98,8 @@ class AdminModel
|
||||
*
|
||||
* @return array The configuration array, or defaults if not found.
|
||||
*/
|
||||
public static function getConfig(): array {
|
||||
public static function getConfig(): array
|
||||
{
|
||||
$configFile = USERS_DIR . 'adminConfig.json';
|
||||
if (file_exists($configFile)) {
|
||||
$encryptedContent = file_get_contents($configFile);
|
||||
@@ -72,10 +112,9 @@ class AdminModel
|
||||
if (!is_array($config)) {
|
||||
$config = [];
|
||||
}
|
||||
|
||||
// Normalize login options.
|
||||
|
||||
// Normalize login options if missing
|
||||
if (!isset($config['loginOptions'])) {
|
||||
// Create loginOptions array from top-level keys if missing.
|
||||
$config['loginOptions'] = [
|
||||
'disableFormLogin' => isset($config['disableFormLogin']) ? (bool)$config['disableFormLogin'] : false,
|
||||
'disableBasicAuth' => isset($config['disableBasicAuth']) ? (bool)$config['disableBasicAuth'] : false,
|
||||
@@ -88,31 +127,43 @@ class AdminModel
|
||||
$config['loginOptions']['disableBasicAuth'] = (bool)$config['loginOptions']['disableBasicAuth'];
|
||||
$config['loginOptions']['disableOIDCLogin'] = (bool)$config['loginOptions']['disableOIDCLogin'];
|
||||
}
|
||||
|
||||
|
||||
// Default values for other keys
|
||||
if (!isset($config['globalOtpauthUrl'])) {
|
||||
$config['globalOtpauthUrl'] = "";
|
||||
}
|
||||
if (!isset($config['header_title']) || empty($config['header_title'])) {
|
||||
$config['header_title'] = "FileRise";
|
||||
}
|
||||
if (!isset($config['enableWebDAV'])) {
|
||||
$config['enableWebDAV'] = false;
|
||||
}
|
||||
// Default sharedMaxUploadSize to 50MB or TOTAL_UPLOAD_SIZE if smaller
|
||||
if (!isset($config['sharedMaxUploadSize'])) {
|
||||
$defaultSms = min(50 * 1024 * 1024, self::parseSize(TOTAL_UPLOAD_SIZE));
|
||||
$config['sharedMaxUploadSize'] = $defaultSms;
|
||||
}
|
||||
|
||||
return $config;
|
||||
} else {
|
||||
// Return defaults.
|
||||
return [
|
||||
'header_title' => "FileRise",
|
||||
'oidc' => [
|
||||
'header_title' => "FileRise",
|
||||
'oidc' => [
|
||||
'providerUrl' => 'https://your-oidc-provider.com',
|
||||
'clientId' => 'YOUR_CLIENT_ID',
|
||||
'clientSecret' => 'YOUR_CLIENT_SECRET',
|
||||
'redirectUri' => 'https://yourdomain.com/api/auth/auth.php?oidc=callback'
|
||||
],
|
||||
'loginOptions' => [
|
||||
'loginOptions' => [
|
||||
'disableFormLogin' => false,
|
||||
'disableBasicAuth' => false,
|
||||
'disableOIDCLogin' => false
|
||||
],
|
||||
'globalOtpauthUrl' => ""
|
||||
'globalOtpauthUrl' => "",
|
||||
'enableWebDAV' => false,
|
||||
'sharedMaxUploadSize' => min(50 * 1024 * 1024, self::parseSize(TOTAL_UPLOAD_SIZE))
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user