]>
git.p6c8.net - jirafeau_project.git/blob - docker/docker_config.php
3 * Jirafeau, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
5 * Copyright (C) 2015 Jerome Jutteau <jerome@jutteau.fr>
6 * Copyright (C) 2024 Jirafeau project <https://gitlab.com/jirafeau> (see AUTHORS.md)
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 define('JIRAFEAU_ROOT', '/www/');
22 define('JIRAFEAU_CFG', JIRAFEAU_ROOT
. 'lib/config.local.php');
24 require(JIRAFEAU_ROOT
. 'lib/settings.php');
25 require(JIRAFEAU_ROOT
. 'lib/functions.php');
26 require(JIRAFEAU_ROOT
. 'lib/lang.php');
28 function env_2_cfg_string(&$cfg, $config_name, $default = null)
30 $env_name = strtoupper($config_name);
31 $r = getenv($env_name);
33 if (is_null($default)) {
39 echo("setting $config_name to '$r'\n");
40 $cfg[$config_name] = $r;
44 function env_2_cfg_bool(&$cfg, $config_name, $default = null)
46 $env_name = strtoupper($config_name);
47 $r = getenv($env_name);
49 if (is_null($default)) {
55 $r = ($r == "1") ?
true : false;
57 echo("setting $config_name to " . ($r ?
"true" : "false") . "\n");
58 $cfg[$config_name] = $r;
62 function env_2_cfg_int(&$cfg, $config_name, $default = null)
64 $env_name = strtoupper($config_name);
65 $r = getenv($env_name);
67 if (is_null($default)) {
75 echo("setting $config_name to $r\n");
76 $cfg[$config_name] = $r;
80 function env_2_cfg_string_array(&$cfg, $config_name)
82 $env_name = strtoupper($config_name);
83 $r = getenv($env_name);
87 $r = explode(",", $r);
89 echo("setting $config_name array with $c value(s)n\n");
90 $cfg[$config_name] = $r;
94 function env_2_cfg_string_array_key_value(&$cfg, $config_name)
96 $env_name = strtoupper($config_name);
97 $env_string = getenv($env_name);
98 if ($env_string === false) {
101 $result = json_decode($env_string, true);
102 if (json_last_error() === JSON_ERROR_NONE
) {
105 echo ("setting $config_name array with $c value(s)n\n");
107 echo ("ERROR - invalid json for environment key $config_name \n");
110 $cfg[$config_name] = $result;
116 function setup_admin_password(&$cfg)
118 if (strlen($cfg['admin_password']) > 0) {
121 echo("setting up admin password\n");
122 $p = getenv('ADMIN_PASSWORD');
124 $p = jirafeau_gen_random(20);
125 echo("auto-generated admin password: $p\n");
127 $cfg['admin_password'] = hash('sha256', $p);
131 function set_rights($path)
133 $uid = getenv('USER_ID');
134 if ($uid === false) {
137 $gid = getenv('GROUP_ID');
138 if ($gid === false) {
141 if (!chown($path, $uid)) {
142 echo("setting up user $uid for $path: failed\n");
145 if (!chgrp($path, $gid)) {
146 echo("setting up group $gid for $path: failed\n");
149 if (!chmod($path, 0770)) {
150 echo("setting up permissions $path: failed\n");
156 function setup_var_folder(&$cfg)
158 env_2_cfg_string($cfg, 'var_root', '/data/');
159 $var_root = $cfg['var_root'];
160 if (!is_dir($var_root)) {
161 mkdir($var_root, 0770, true);
163 $err = jirafeau_check_var_dir($var_root);
164 if ($err['has_error']) {
165 echo("error: cannot create $var_root folder\n");
168 return set_rights($var_root) &&
169 set_rights($var_root . 'async') &&
170 set_rights($var_root . 'files') &&
171 set_rights($var_root . 'links');
174 function setup_webroot(&$cfg)
176 if (!env_2_cfg_string($cfg, 'web_root')) {
177 echo("warning: you may want to have set WEB_ROOT to your website URL (like 'jirafeau.mydomain.tld/')\n");
181 function run_setup(&$cfg)
183 $setup_ok = setup_admin_password($cfg) &&
184 setup_var_folder($cfg);
186 env_2_cfg_string($cfg, 'file_hash');
187 env_2_cfg_bool($cfg, 'preview');
188 env_2_cfg_string($cfg, 'title', false);
189 env_2_cfg_string($cfg, 'organisation');
190 env_2_cfg_string($cfg, 'lang');
191 env_2_cfg_string($cfg, 'contactperson');
192 env_2_cfg_string($cfg, 'style');
193 env_2_cfg_string($cfg, 'availability_default');
194 env_2_cfg_string($cfg, 'dark_style');
195 env_2_cfg_bool($cfg, 'one_time_download');
196 env_2_cfg_bool($cfg, 'one_time_download_preselected');
197 env_2_cfg_bool($cfg, 'enable_crypt');
198 env_2_cfg_bool($cfg, 'debug');
199 env_2_cfg_int($cfg, 'maximal_upload_size');
200 env_2_cfg_string_array($cfg, 'upload_password');
201 env_2_cfg_string_array($cfg, 'upload_ip');
202 env_2_cfg_string_array($cfg, 'admin_ip');
203 env_2_cfg_string_array($cfg, 'upload_ip_nopassword');
204 env_2_cfg_string_array($cfg, 'proxy_ip');
205 // this is a key value based value
206 env_2_cfg_string_array_key_value($cfg, 'availabilities');
207 env_2_cfg_bool($cfg, 'store_uploader_ip');
208 env_2_cfg_string($cfg, 'download_password_requirement');
209 env_2_cfg_int($cfg, 'download_password_gen_len');
210 env_2_cfg_string($cfg, 'download_password_gen_chars');
211 env_2_cfg_string($cfg, 'download_password_policy');
212 env_2_cfg_string($cfg, 'download_password_policy_regex');
215 $cfg['installation_done'] = true;
216 jirafeau_export_cfg($cfg);
217 echo("You can now connect to your Jirafeau instance\n");
220 echo("Some Jirafeau options failed");
patrick-canterino.de