]> git.p6c8.net - jirafeau.git/blob - install.php
Jirafeau 4.6.1 is ready
[jirafeau.git] / install.php
1 <?php
2 /*
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)
7 *
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.
12 *
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.
17 *
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/>.
20 */
21 define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
22
23 define('JIRAFEAU_CFG', JIRAFEAU_ROOT . 'lib/config.local.php');
24 define('JIRAFEAU_VAR_RAND_LENGTH', 15);
25
26 require(JIRAFEAU_ROOT . 'lib/settings.php');
27 require(JIRAFEAU_ROOT . 'lib/functions.php');
28 require(JIRAFEAU_ROOT . 'lib/lang.php');
29
30 /**
31 * Check installation
32 **/
33
34 // Is the installation process done already?
35 // Then there is nothing to do here → redirect to the main page.
36 if ($cfg['installation_done'] === true) {
37 header('Location: index.php');
38 exit;
39 }
40
41 /**
42 * Prepare installation process
43 **/
44
45 require(JIRAFEAU_ROOT . 'lib/template/header.php');
46
47 // does the local configuration file exist?
48 if (!file_exists(JIRAFEAU_CFG)) {
49 // show an error if it is not possible to create the file
50 if (!@touch(JIRAFEAU_CFG)) {
51 jirafeau_fatal_error(t('CONF_SOLUTION'));
52 }
53 }
54
55 // is the local configuration writable?
56 if (!is_writable(JIRAFEAU_CFG) && !@chmod(JIRAFEAU_CFG, '0666')) {
57 jirafeau_fatal_error(t('CONF_SOLUTION_2'));
58 }
59
60 /**
61 * Run trough each installation step
62 **/
63
64 if (isset($_POST['step']) && isset($_POST['next'])) {
65 switch ($_POST['step']) {
66 case 1:
67 if (strlen($_POST['admin_password'])) {
68 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
69 } else {
70 $cfg['admin_password'] = '';
71 }
72 jirafeau_export_cfg($cfg);
73 break;
74
75 case 2:
76 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
77 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
78 jirafeau_export_cfg($cfg);
79 break;
80
81 case 3:
82 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
83 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
84 jirafeau_export_cfg($cfg);
85 break;
86 }
87 }
88
89 $current = 1;
90 if (isset($_POST['next'])) {
91 $current = $_POST['step'] + 1;
92 } elseif (isset($_POST['previous'])) {
93 $current = $_POST['step'] - 1;
94 } elseif (isset($_POST['retry'])) {
95 $current = $_POST['step'];
96 }
97
98 switch ($current) {
99 case 1:
100 default:
101 ?><h2><?php printf(t('JI_INSTALL') . ' - ' . t('STEP') .
102 ' %d ' . t('OUT_OF') . ' %d', 1, 3);
103 ?></h2> <div id = "install"> <form method="post"> <input type =
104 "hidden" name = "jirafeau" value =
105 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
106 "step" value = "1" /><fieldset> <legend><?php
107 echo t('ADMIN_PSW');
108 ?></legend> <table> <tr> <td class = "info" colspan =
109 "2"><?php echo t('ADMIN_INTERFACE_INFO');
110 ?></td> </tr> <tr> <td class = "label"><label for = "select_password"
111 ><?php echo t('ADMIN_PSW') . ':';
112 ?></label></td>
113 <td class = "field"><input type = "password" name = "admin_password"
114 id = "admin_password" size = "40" autocomplete = "new-password"/></td>
115 </tr>
116 <tr class = "nav">
117 <td></td>
118 <td class = "nav next">
119 <input type = "submit"
120 class = "navleft" name = "previous" value = "<?php
121 echo t('PREV_STEP'); ?>" />
122 <input type = "submit" name = "next" value =
123 "<?php echo t('NEXT_STEP'); ?>" /></td> </tr> </table>
124 </fieldset> </form> </div> <?php
125 break;
126
127 case 2:
128 ?><h2><?php printf(t('JI_INSTALL') . ' - ' . t('STEP') .
129 ' %d ' . t('OUT_OF') . ' %d', 2, 3);
130 ?></h2> <div id = "install"> <form method="post"> <input type =
131 "hidden" name = "jirafeau" value =
132 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
133 "step" value =
134 "2" /><fieldset> <legend><?php echo t('INFO');
135 ?></legend> <table> <tr> <td class = "info" colspan =
136 "2"><?php echo t('BASE_ADDR_INFO');
137 ?></td> </tr> <tr> <td class = "label"><label for = "input_web_root"
138 ><?php echo t('BASE_ADDR') . ':';
139 ?></label></td>
140 <td class = "field"><input type = "text" name = "web_root"
141 id = "input_web_root" value = "<?php
142 echo(empty($cfg['web_root']) ? jirafeau_default_web_root() : $cfg['web_root']);
143 ?>" size = "40" /></td>
144 </tr> <tr> <td class = "info" colspan = "2"><?php
145 echo t('DATA_DIR_EXPLAINATION');
146 ?></td> </tr> <tr> <td class = "label"><label for = "input_var_root"
147 ><?php echo t('DATA_DIR') . ':';
148 ?></label></td>
149 <td class = "field"><input type = "text" name = "var_root"
150 id = "input_var_root" value = "<?php
151 if (empty($cfg['var_root'])) {
152 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
153 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
154 $len_alphanum = strlen($alphanum);
155 $var = 'var-';
156 for ($i = 0; $i < JIRAFEAU_VAR_RAND_LENGTH; $i++) {
157 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
158 }
159 echo JIRAFEAU_ROOT . $var . '/';
160 } else {
161 echo $cfg['var_root'];
162 }
163 ?>" size = "40" /></td>
164 </tr> <tr> <td colspan = "2"><input type = "submit"
165 class = "navleft" name = "previous" value = "<?php
166 echo t('PREV_STEP'); ?>" />
167 <input type = "submit" class = "navright" name = "next" value =
168 "<?php echo t('NEXT_STEP'); ?>" />
169 </td> </tr> </table> </fieldset>
170 </form> </div> <?php
171 break;
172
173 case 3:
174 ?><h2><?php printf(t('JI_INSTALL') . ' - ' . t('STEP') .
175 ' %d ' . t('OUT_OF') . ' %d', 3, 3);
176 ?></h2> <div id = "install"> <form method="post"> <input type =
177 "hidden" name = "jirafeau" value =
178 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
179 "step" value =
180 "3" /><fieldset> <legend><?php echo t('FINALIZATION');
181 ?></legend> <table> <tr> <td class = "info" colspan =
182 "2"><?php echo t('SETTING_UP');
183 ?></td> </tr> <tr> <td class = "nav previous"><input type =
184 "submit" name = "previous" value = " <?php echo t('PREV_STEP');
185 ?>" /></td> <td></td> </tr>
186 </table> </fieldset> </form> </div>
187 <?php
188 $err = jirafeau_check_var_dir($cfg['var_root']);
189 if ($err['has_error']) {
190 echo '<div class="error"><p>'.$err['why'].'<br />'.NL; ?><form method="post"> <input type = "hidden" name = "jirafeau" value =
191 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
192 "step" value = "3" /><input type = "submit" name =
193 "retry" value =
194 "<?php echo t('RETRY_STEP'); ?>" /></form>
195 <?php echo '</p></div>';
196 } else {
197 $cfg['installation_done'] = true;
198 jirafeau_export_cfg($cfg);
199 echo '<div class="message"><p>' .
200 t('JI_FONCTIONAL') . ':' .
201 '<br /><a href="./">' .
202 $cfg['web_root'].'</a></p></div>';
203 }
204 break;
205 }
206
207 require(JIRAFEAU_ROOT . 'lib/template/footer.php');

patrick-canterino.de