From: Jerome Jutteau Date: Sat, 2 Jan 2021 23:18:20 +0000 (+0100) Subject: [FEATURE] more option docker options X-Git-Tag: 4.4.0~11 X-Git-Url: https://git.p6c8.net/jirafeau.git/commitdiff_plain/50ba95ede58b3113d46ab7af40d922afe3d79755 [FEATURE] more option docker options closes #247 also: - warn user about web_root configuration in docker - no need to rewrite default options in docker - option name is the same as Jirafeau but in CAPSLOCK Signed-off-by: Jerome Jutteau --- diff --git a/docker/README.md b/docker/README.md index c8a6f55..4fef8f5 100644 --- a/docker/README.md +++ b/docker/README.md @@ -37,6 +37,21 @@ Available options: - `WEB_ROOT`: setup a specific domain to point at when generating links (e.g. 'jirafeau.mydomain.com/'). - `VAR_ROOT`: setup a specific path where to place files. default: '/data'. - `FILE_HASH`: can be set to `md5` (default), `partial_md5` or `random`. +- `PREVIEW`: set to 1 or 0 to enable or disable preview. +- `TITLE`: set Jirafeau instance title. +- `ORGANISATION`: set organisation (in ToS). +- `CONTACTPERSON`: set contact person (in ToS). +- `STYLE`: apply a specific style. +- `AVAILABILITY_DEFAULT`: setup which availability shows by default. +- `ONE_TIME_DOWNLOAD`: set to 1 or 0 to enable or disable one time downloads. +- `ENABLE_CRYPT`: set to 1 or 0 to enable or disable server side encryption. +- `DEBUG`: set to 1 or 0 to enable or disable debug mode. +- `MAXIMAL_UPLOAD_SIZE`: maximal file size allowed (expressed in MB). +- `UPLOAD_PASSWORD`: set one or more passwords to access Jirafeau (separated by comma). +- `UPLOAD_IP`: set one or more ip allowed to upload files (separated by comma). +- `UPLOAD_IP_NO_PASSWORD`: set one or more ip allowed to upload files without password (separated by comma). +- `PROXY_IP`: set one or more proxy ip (separated by comma). +- `STORE_UPLOADER_IP`: set to 1 or 0 to enable or disable keeping sender's IP with the _link_ file. ## Few notes diff --git a/docker/docker_config.php b/docker/docker_config.php index aa57772..6a03b73 100644 --- a/docker/docker_config.php +++ b/docker/docker_config.php @@ -23,8 +23,9 @@ require(JIRAFEAU_ROOT . 'lib/settings.php'); require(JIRAFEAU_ROOT . 'lib/functions.php'); require(JIRAFEAU_ROOT . 'lib/lang.php'); -function env_2_cfg_string(&$cfg, $config_name, $env_name, $default = null) +function env_2_cfg_string(&$cfg, $config_name, $default = null) { + $env_name = strtoupper($config_name); $r = getenv($env_name); if ($r === false) { if (is_null($default)) { @@ -38,6 +39,56 @@ function env_2_cfg_string(&$cfg, $config_name, $env_name, $default = null) return true; } +function env_2_cfg_bool(&$cfg, $config_name, $default = null) +{ + $env_name = strtoupper($config_name); + $r = getenv($env_name); + if ($r === false) { + if (is_null($default)) { + return false; + } else { + $r = $default; + } + } else { + $r = ($r == "1") ? true : false; + } + echo("setting $config_name to " . ($r ? "true" : "false") . "\n"); + $cfg[$config_name] = $r; + return true; +} + +function env_2_cfg_int(&$cfg, $config_name, $default = null) +{ + $env_name = strtoupper($config_name); + $r = getenv($env_name); + if ($r === false) { + if (is_null($default)) { + return false; + } else { + $r = $default; + } + } else { + $r = intval($r); + } + echo("setting $config_name to $r\n"); + $cfg[$config_name] = $r; + return true; +} + +function env_2_cfg_string_array(&$cfg, $config_name) +{ + $env_name = strtoupper($config_name); + $r = getenv($env_name); + if ($r === false) { + return; + } + $r = explode(",", $r); + $c = count($r); + echo("setting $config_name array with $c value(s)n\n"); + $cfg[$config_name] = $r; + return true; +} + function setup_admin_password(&$cfg) { if (strlen($cfg['admin_password']) > 0) { @@ -80,7 +131,7 @@ function set_rights($path) function setup_var_folder(&$cfg) { - env_2_cfg_string($cfg, 'var_root', 'VAR_ROOT', '/data/'); + env_2_cfg_string($cfg, 'var_root', '/data/'); $var_root = $cfg['var_root']; if (!is_dir($var_root)) { mkdir($var_root, 0770, true); @@ -96,18 +147,44 @@ function setup_var_folder(&$cfg) set_rights($var_root . 'links'); } -// TODO: lots of other options to implement -$setup_ok = setup_admin_password($cfg) && - setup_var_folder($cfg); -env_2_cfg_string($cfg, 'web_root', 'WEB_ROOT', ''); -env_2_cfg_string($cfg, 'file_hash', 'FILE_HASH', 'md5'); +function setup_webroot(&$cfg) +{ + if (!env_2_cfg_string($cfg, 'web_root')) { + echo("warning: you may want to have set WEB_ROOT to your website URL (like 'jirafeau.mydomain.tld/')\n"); + } +} + +function run_setup(&$cfg) +{ + $setup_ok = setup_admin_password($cfg) && + setup_var_folder($cfg); + setup_webroot($cfg); + env_2_cfg_string($cfg, 'file_hash'); + env_2_cfg_bool($cfg, 'preview'); + env_2_cfg_bool($cfg, 'title'); + env_2_cfg_string($cfg, 'organisation'); + env_2_cfg_string($cfg, 'contactperson'); + env_2_cfg_string($cfg, 'style'); + env_2_cfg_string($cfg, 'availability_default'); + env_2_cfg_bool($cfg, 'one_time_download'); + env_2_cfg_bool($cfg, 'enable_crypt'); + env_2_cfg_bool($cfg, 'debug'); + env_2_cfg_int($cfg, 'maximal_upload_size'); + env_2_cfg_string_array($cfg, 'upload_password'); + env_2_cfg_string_array($cfg, 'upload_ip'); + env_2_cfg_string_array($cfg, 'upload_ip_nopassword'); + env_2_cfg_string_array($cfg, 'proxy_ip'); + env_2_cfg_bool($cfg, 'store_uploader_ip'); -if ($setup_ok) { - $cfg['installation_done'] = true; - jirafeau_export_cfg($cfg); - echo("You can now connect to your Jirafeau instance\n"); - exit(0); -} else { - echo("Some Jirafeau options failed"); - exit(1); + if ($setup_ok) { + $cfg['installation_done'] = true; + jirafeau_export_cfg($cfg); + echo("You can now connect to your Jirafeau instance\n"); + exit(0); + } else { + echo("Some Jirafeau options failed"); + exit(1); + } } + +run_setup($cfg);