]>
git.p6c8.net - jirafeau_project.git/blob - docker/docker_config.php
976f36644b5d7feea15ba1227aa2de154e224e8b
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 setup_admin_password(&$cfg)
96 if (strlen($cfg['admin_password']) > 0) {
99 echo("setting up admin password\n");
100 $p = getenv('ADMIN_PASSWORD');
102 $p = jirafeau_gen_random(20);
103 echo("auto-generated admin password: $p\n");
105 $cfg['admin_password'] = hash('sha256', $p);
109 function set_rights($path)
111 $uid = getenv('USER_ID');
112 if ($uid === false) {
115 $gid = getenv('GROUP_ID');
116 if ($gid === false) {
119 if (!chown($path, $uid)) {
120 echo("setting up user $uid for $path: failed\n");
123 if (!chgrp($path, $gid)) {
124 echo("setting up group $gid for $path: failed\n");
127 if (!chmod($path, 0770)) {
128 echo("setting up permissions $path: failed\n");
134 function setup_var_folder(&$cfg)
136 env_2_cfg_string($cfg, 'var_root', '/data/');
137 $var_root = $cfg['var_root'];
138 if (!is_dir($var_root)) {
139 mkdir($var_root, 0770, true);
141 $err = jirafeau_check_var_dir($var_root);
142 if ($err['has_error']) {
143 echo("error: cannot create $var_root folder\n");
146 return set_rights($var_root) &&
147 set_rights($var_root . 'async') &&
148 set_rights($var_root . 'files') &&
149 set_rights($var_root . 'links');
152 function setup_webroot(&$cfg)
154 if (!env_2_cfg_string($cfg, 'web_root')) {
155 echo("warning: you may want to have set WEB_ROOT to your website URL (like 'jirafeau.mydomain.tld/')\n");
159 function run_setup(&$cfg)
161 $setup_ok = setup_admin_password($cfg) &&
162 setup_var_folder($cfg);
164 env_2_cfg_string($cfg, 'file_hash');
165 env_2_cfg_bool($cfg, 'preview');
166 env_2_cfg_string($cfg, 'title', false);
167 env_2_cfg_string($cfg, 'organisation');
168 env_2_cfg_string($cfg, 'contactperson');
169 env_2_cfg_string($cfg, 'style');
170 env_2_cfg_string($cfg, 'availability_default');
171 env_2_cfg_string($cfg, 'dark_style');
172 env_2_cfg_bool($cfg, 'one_time_download');
173 env_2_cfg_bool($cfg, 'enable_crypt');
174 env_2_cfg_bool($cfg, 'debug');
175 env_2_cfg_int($cfg, 'maximal_upload_size');
176 env_2_cfg_string_array($cfg, 'upload_password');
177 env_2_cfg_string_array($cfg, 'upload_ip');
178 env_2_cfg_string_array($cfg, 'admin_ip');
179 env_2_cfg_string_array($cfg, 'upload_ip_nopassword');
180 env_2_cfg_string_array($cfg, 'proxy_ip');
181 env_2_cfg_bool($cfg, 'store_uploader_ip');
182 env_2_cfg_string($cfg, 'download_password_requirement');
183 env_2_cfg_int($cfg, 'download_password_gen_len');
184 env_2_cfg_string($cfg, 'download_password_gen_chars');
185 env_2_cfg_string($cfg, 'download_password_policy');
186 env_2_cfg_string($cfg, 'download_password_policy_regex');
189 $cfg['installation_done'] = true;
190 jirafeau_export_cfg($cfg);
191 echo("You can now connect to your Jirafeau instance\n");
194 echo("Some Jirafeau options failed");
patrick-canterino.de