]>
git.p6c8.net - jirafeau_mojo42.git/blob - docker/docker_config.php
6a03b7360aebd63308c0ac8ea49cde3f85e612f1
3 * Jirafeau, your web file repository
4 * Copyright (C) 2020 Jérôme Jutteau <jerome@jutteau.fr>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 define('JIRAFEAU_ROOT', '/www/');
20 define('JIRAFEAU_CFG', JIRAFEAU_ROOT
. 'lib/config.local.php');
22 require(JIRAFEAU_ROOT
. 'lib/settings.php');
23 require(JIRAFEAU_ROOT
. 'lib/functions.php');
24 require(JIRAFEAU_ROOT
. 'lib/lang.php');
26 function env_2_cfg_string(&$cfg, $config_name, $default = null)
28 $env_name = strtoupper($config_name);
29 $r = getenv($env_name);
31 if (is_null($default)) {
37 echo("setting $config_name to '$r'\n");
38 $cfg[$config_name] = $r;
42 function env_2_cfg_bool(&$cfg, $config_name, $default = null)
44 $env_name = strtoupper($config_name);
45 $r = getenv($env_name);
47 if (is_null($default)) {
53 $r = ($r == "1") ?
true : false;
55 echo("setting $config_name to " . ($r ?
"true" : "false") . "\n");
56 $cfg[$config_name] = $r;
60 function env_2_cfg_int(&$cfg, $config_name, $default = null)
62 $env_name = strtoupper($config_name);
63 $r = getenv($env_name);
65 if (is_null($default)) {
73 echo("setting $config_name to $r\n");
74 $cfg[$config_name] = $r;
78 function env_2_cfg_string_array(&$cfg, $config_name)
80 $env_name = strtoupper($config_name);
81 $r = getenv($env_name);
85 $r = explode(",", $r);
87 echo("setting $config_name array with $c value(s)n\n");
88 $cfg[$config_name] = $r;
92 function setup_admin_password(&$cfg)
94 if (strlen($cfg['admin_password']) > 0) {
97 echo("setting up admin password\n");
98 $p = getenv('ADMIN_PASSWORD');
100 $p = jirafeau_gen_random(20);
101 echo("auto-generated admin password: $p\n");
103 $cfg['admin_password'] = hash('sha256', $p);
107 function set_rights($path)
109 $uid = getenv('USER_ID');
110 if ($uid === false) {
113 $gid = getenv('GROUP_ID');
114 if ($gid === false) {
117 if (!chown($path, $uid)) {
118 echo("setting up user $uid for $path: failed\n");
121 if (!chgrp($path, $gid)) {
122 echo("setting up group $gid for $path: failed\n");
125 if (!chmod($path, 0770)) {
126 echo("setting up permissions $path: failed\n");
132 function setup_var_folder(&$cfg)
134 env_2_cfg_string($cfg, 'var_root', '/data/');
135 $var_root = $cfg['var_root'];
136 if (!is_dir($var_root)) {
137 mkdir($var_root, 0770, true);
139 $err = jirafeau_check_var_dir($var_root);
140 if ($err['has_error']) {
141 echo("error: cannot create $var_root folder\n");
144 return set_rights($var_root) &&
145 set_rights($var_root . 'async') &&
146 set_rights($var_root . 'files') &&
147 set_rights($var_root . 'links');
150 function setup_webroot(&$cfg)
152 if (!env_2_cfg_string($cfg, 'web_root')) {
153 echo("warning: you may want to have set WEB_ROOT to your website URL (like 'jirafeau.mydomain.tld/')\n");
157 function run_setup(&$cfg)
159 $setup_ok = setup_admin_password($cfg) &&
160 setup_var_folder($cfg);
162 env_2_cfg_string($cfg, 'file_hash');
163 env_2_cfg_bool($cfg, 'preview');
164 env_2_cfg_bool($cfg, 'title');
165 env_2_cfg_string($cfg, 'organisation');
166 env_2_cfg_string($cfg, 'contactperson');
167 env_2_cfg_string($cfg, 'style');
168 env_2_cfg_string($cfg, 'availability_default');
169 env_2_cfg_bool($cfg, 'one_time_download');
170 env_2_cfg_bool($cfg, 'enable_crypt');
171 env_2_cfg_bool($cfg, 'debug');
172 env_2_cfg_int($cfg, 'maximal_upload_size');
173 env_2_cfg_string_array($cfg, 'upload_password');
174 env_2_cfg_string_array($cfg, 'upload_ip');
175 env_2_cfg_string_array($cfg, 'upload_ip_nopassword');
176 env_2_cfg_string_array($cfg, 'proxy_ip');
177 env_2_cfg_bool($cfg, 'store_uploader_ip');
180 $cfg['installation_done'] = true;
181 jirafeau_export_cfg($cfg);
182 echo("You can now connect to your Jirafeau instance\n");
185 echo("Some Jirafeau options failed");
patrick-canterino.de