]> git.p6c8.net - jirafeau_project.git/blob - install.php
README: Deny access to var on Apache using "Require all denied"
[jirafeau_project.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 Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20 define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
21
22 define('JIRAFEAU_CFG', JIRAFEAU_ROOT . 'lib/config.local.php');
23 define('JIRAFEAU_VAR_RAND_LENGTH', 15);
24
25 require(JIRAFEAU_ROOT . 'lib/settings.php');
26 require(JIRAFEAU_ROOT . 'lib/functions.php');
27 require(JIRAFEAU_ROOT . 'lib/lang.php');
28
29 /**
30 * Check installation
31 **/
32
33 // Is the installation process done already?
34 // Then there is nothing to do here → redirect to the main page.
35 if ($cfg['installation_done'] === true) {
36 header('Location: index.php');
37 exit;
38 }
39
40 /**
41 * Prepare installation process
42 **/
43
44 require(JIRAFEAU_ROOT . 'lib/template/header.php');
45
46 // does the local configuration file exist?
47 if (!file_exists(JIRAFEAU_CFG)) {
48 // show an error if it is not possible to create the file
49 if (!@touch(JIRAFEAU_CFG)) {
50 jirafeau_fatal_error(t('CONF_SOLUTION'));
51 }
52 }
53
54 // is the local configuration writable?
55 if (!is_writable(JIRAFEAU_CFG) && !@chmod(JIRAFEAU_CFG, '0666')) {
56 jirafeau_fatal_error(t('CONF_SOLUTION_2'));
57 }
58
59 /**
60 * Run trough each installation step
61 **/
62
63 if (isset($_POST['step']) && isset($_POST['next'])) {
64 switch ($_POST['step']) {
65 case 1:
66 if (strlen($_POST['admin_password'])) {
67 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
68 } else {
69 $cfg['admin_password'] = '';
70 }
71 jirafeau_export_cfg($cfg);
72 break;
73
74 case 2:
75 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
76 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
77 jirafeau_export_cfg($cfg);
78 break;
79
80 case 3:
81 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
82 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
83 jirafeau_export_cfg($cfg);
84 break;
85 }
86 }
87
88 $current = 1;
89 if (isset($_POST['next'])) {
90 $current = $_POST['step'] + 1;
91 } elseif (isset($_POST['previous'])) {
92 $current = $_POST['step'] - 1;
93 } elseif (isset($_POST['retry'])) {
94 $current = $_POST['step'];
95 }
96
97 switch ($current) {
98 case 1:
99 default:
100 ?><h2><?php printf(t('JI_INSTALL') . ' - ' . t('STEP') .
101 ' %d ' . t('OUT_OF') . ' %d', 1, 3);
102 ?></h2> <div id = "install"> <form method="post"> <input type =
103 "hidden" name = "jirafeau" value =
104 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
105 "step" value = "1" /><fieldset> <legend><?php
106 echo t('ADMIN_PSW');
107 ?></legend> <table> <tr> <td class = "info" colspan =
108 "2"><?php echo t('ADMIN_INTERFACE_INFO');
109 ?></td> </tr> <tr> <td class = "label"><label for = "select_password"
110 ><?php echo t('ADMIN_PSW') . ':';
111 ?></label></td>
112 <td class = "field"><input type = "password" name = "admin_password"
113 id = "admin_password" size = "40" autocomplete = "new-password"/></td>
114 </tr>
115 <tr class = "nav">
116 <td></td>
117 <td class = "nav next">
118 <input type = "submit"
119 class = "navleft" name = "previous" value = "<?php
120 echo t('PREV_STEP'); ?>" />
121 <input type = "submit" name = "next" value =
122 "<?php echo t('NEXT_STEP'); ?>" /></td> </tr> </table>
123 </fieldset> </form> </div> <?php
124 break;
125
126 case 2:
127 ?><h2><?php printf(t('JI_INSTALL') . ' - ' . t('STEP') .
128 ' %d ' . t('OUT_OF') . ' %d', 2, 3);
129 ?></h2> <div id = "install"> <form method="post"> <input type =
130 "hidden" name = "jirafeau" value =
131 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
132 "step" value =
133 "2" /><fieldset> <legend><?php echo t('INFO');
134 ?></legend> <table> <tr> <td class = "info" colspan =
135 "2"><?php echo t('BASE_ADDR_INFO');
136 ?></td> </tr> <tr> <td class = "label"><label for = "input_web_root"
137 ><?php echo t('BASE_ADDR') . ':';
138 ?></label></td>
139 <td class = "field"><input type = "text" name = "web_root"
140 id = "input_web_root" value = "<?php
141 echo(empty($cfg['web_root']) ? jirafeau_default_web_root() : $cfg['web_root']);
142 ?>" size = "40" /></td>
143 </tr> <tr> <td class = "info" colspan = "2"><?php
144 echo t('DATA_DIR_EXPLAINATION');
145 ?></td> </tr> <tr> <td class = "label"><label for = "input_var_root"
146 ><?php echo t('DATA_DIR') . ':';
147 ?></label></td>
148 <td class = "field"><input type = "text" name = "var_root"
149 id = "input_var_root" value = "<?php
150 if (empty($cfg['var_root'])) {
151 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
152 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
153 $len_alphanum = strlen($alphanum);
154 $var = 'var-';
155 for ($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
156 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
157 }
158 echo JIRAFEAU_ROOT . $var . '/';
159 } else {
160 echo $cfg['var_root'];
161 }
162 ?>" size = "40" /></td>
163 </tr> <tr> <td colspan = "2"><input type = "submit"
164 class = "navleft" name = "previous" value = "<?php
165 echo t('PREV_STEP'); ?>" />
166 <input type = "submit" class = "navright" name = "next" value =
167 "<?php echo t('NEXT_STEP'); ?>" />
168 </td> </tr> </table> </fieldset>
169 </form> </div> <?php
170 break;
171
172 case 3:
173 ?><h2><?php printf(t('JI_INSTALL') . ' - ' . t('STEP') .
174 ' %d ' . t('OUT_OF') . ' %d', 3, 3);
175 ?></h2> <div id = "install"> <form method="post"> <input type =
176 "hidden" name = "jirafeau" value =
177 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
178 "step" value =
179 "3" /><fieldset> <legend><?php echo t('FINALIZATION');
180 ?></legend> <table> <tr> <td class = "info" colspan =
181 "2"><?php echo t('SETTING_UP');
182 ?></td> </tr> <tr> <td class = "nav previous"><input type =
183 "submit" name = "previous" value = " <?php echo t('PREV_STEP');
184 ?>" /></td> <td></td> </tr>
185 </table> </fieldset> </form> </div>
186 <?php
187 $err = jirafeau_check_var_dir($cfg['var_root']);
188 if ($err['has_error']) {
189 echo '<div class="error"><p>'.$err['why'].'<br />'.NL; ?><form method="post"> <input type = "hidden" name = "jirafeau" value =
190 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
191 "step" value = "3" /><input type = "submit" name =
192 "retry" value =
193 "<?php echo t('RETRY_STEP'); ?>" /></form>
194 <?php echo '</p></div>';
195 } else {
196 $cfg['installation_done'] = true;
197 jirafeau_export_cfg($cfg);
198 echo '<div class="message"><p>' .
199 t('JI_FONCTIONAL') . ':' .
200 '<br /><a href="./">' .
201 $cfg['web_root'].'</a></p></div>';
202 }
203 break;
204 }
205
206 require(JIRAFEAU_ROOT . 'lib/template/footer.php');

patrick-canterino.de