]> git.p6c8.net - jirafeau.git/blob - install.php
[BUGFIX] avoid running admin cli if installation not finished
[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 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(
51 t('The local configuration file could not be created. Create a ' .
52 '<code>lib/config.local.php</code> file and give the write ' .
53 'permission to the web server (preferred solution), or give the ' .
54 'write permission to the web server on the <code>lib</code> ' .
55 'directory.')
56 );
57 }
58 }
59
60 // is the local configuration writable?
61 if (!is_writable(JIRAFEAU_CFG) && !@chmod(JIRAFEAU_CFG, '0666')) {
62 jirafeau_fatal_error(
63 t('The local configuration is not writable by the web server. ' .
64 'Give the write permission to the web server on the ' .
65 '<code>lib/config.local.php</code> file.')
66 );
67 }
68
69 /**
70 * Run trough each installation step
71 **/
72
73 if (isset($_POST['step']) && isset($_POST['next'])) {
74 switch ($_POST['step']) {
75 case 1:
76 if (strlen($_POST['admin_password'])) {
77 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
78 } else {
79 $cfg['admin_password'] = '';
80 }
81 jirafeau_export_cfg($cfg);
82 break;
83
84 case 2:
85 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
86 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
87 jirafeau_export_cfg($cfg);
88 break;
89
90 case 3:
91 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
92 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
93 jirafeau_export_cfg($cfg);
94 break;
95 }
96 }
97
98 $current = 1;
99 if (isset($_POST['next'])) {
100 $current = $_POST['step'] + 1;
101 } elseif (isset($_POST['previous'])) {
102 $current = $_POST['step'] - 1;
103 } elseif (isset($_POST['retry'])) {
104 $current = $_POST['step'];
105 }
106
107 switch ($current) {
108 case 1:
109 default:
110 ?><h2><?php printf(t('JI_INSTALL') . ' - ' . t('STEP') .
111 ' %d ' . t('OUT_OF') . ' %d', 1, 3);
112 ?></h2> <div id = "install"> <form method="post"> <input type =
113 "hidden" name = "jirafeau" value =
114 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
115 "step" value = "1" /><fieldset> <legend><?php
116 echo t('ADMIN_PSW');
117 ?></legend> <table> <tr> <td class = "info" colspan =
118 "2"><?php echo t('ADMIN_INTERFACE_INFO');
119 ?></td> </tr> <tr> <td class = "label"><label for = "select_password"
120 ><?php echo t('ADMIN_PSW') . ':';
121 ?></label></td>
122 <td class = "field"><input type = "password" name = "admin_password"
123 id = "admin_password" size = "40" /></td>
124 </tr>
125 <tr class = "nav">
126 <td></td>
127 <td class = "nav next">
128 <input type = "submit"
129 class = "navleft" name = "previous" value = "<?php
130 echo t('PREV_STEP'); ?>" />
131 <input type = "submit" name = "next" value =
132 "<?php echo t('NEXT_STEP'); ?>" /></td> </tr> </table>
133 </fieldset> </form> </div> <?php
134 break;
135
136 case 2:
137 ?><h2><?php printf(t('JI_INSTALL') . ' - ' . t('STEP') .
138 ' %d ' . t('OUT_OF') . ' %d', 2, 3);
139 ?></h2> <div id = "install"> <form method="post"> <input type =
140 "hidden" name = "jirafeau" value =
141 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
142 "step" value =
143 "2" /><fieldset> <legend><?php echo t('INFO');
144 ?></legend> <table> <tr> <td class = "info" colspan =
145 "2"><?php echo t('BASE_ADDR_INFO');
146 ?></td> </tr> <tr> <td class = "label"><label for = "input_web_root"
147 ><?php echo t('BASE_ADDR') . ':';
148 ?></label></td>
149 <td class = "field"><input type = "text" name = "web_root"
150 id = "input_web_root" value = "<?php
151 echo(empty($cfg['web_root']) ?
152 $_SERVER['HTTP_HOST'] . str_replace(
153 basename(__FILE__),
154 '',
155 $_SERVER['REQUEST_URI']
156 ) : $cfg['web_root']);
157 ?>" size = "40" /></td>
158 </tr> <tr> <td class = "info" colspan = "2"><?php
159 echo t('DATA_DIR_EXPLAINATION');
160 ?></td> </tr> <tr> <td class = "label"><label for = "input_var_root"
161 ><?php echo t('DATA_DIR') . ':';
162 ?></label></td>
163 <td class = "field"><input type = "text" name = "var_root"
164 id = "input_var_root" value = "<?php
165 if (empty($cfg['var_root'])) {
166 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
167 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
168 $len_alphanum = strlen($alphanum);
169 $var = 'var-';
170 for ($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
171 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
172 }
173 echo JIRAFEAU_ROOT . $var . '/';
174 } else {
175 echo $cfg['var_root'];
176 }
177 ?>" size = "40" /></td>
178 </tr> <tr> <td colspan = "2"><input type = "submit"
179 class = "navleft" name = "previous" value = "<?php
180 echo t('PREV_STEP'); ?>" />
181 <input type = "submit" class = "navright" name = "next" value =
182 "<?php echo t('NEXT_STEP'); ?>" />
183 </td> </tr> </table> </fieldset>
184 </form> </div> <?php
185 break;
186
187 case 3:
188 ?><h2><?php printf(t('JI_INSTALL') . ' - ' . t('STEP') .
189 ' %d ' . t('OUT_OF') . ' %d', 3, 3);
190 ?></h2> <div id = "install"> <form method="post"> <input type =
191 "hidden" name = "jirafeau" value =
192 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
193 "step" value =
194 "3" /><fieldset> <legend><?php echo t('FINALIZATION');
195 ?></legend> <table> <tr> <td class = "info" colspan =
196 "2"><?php echo t('SETTING_UP');
197 ?></td> </tr> <tr> <td class = "nav previous"><input type =
198 "submit" name = "previous" value = " <?php echo t('PREV_STEP');
199 ?>" /></td> <td></td> </tr>
200 </table> </fieldset> </form> </div>
201 <?php
202 $err = jirafeau_check_var_dir($cfg['var_root']);
203 if ($err['has_error']) {
204 echo '<div class="error"><p>'.$err['why'].'<br />'.NL; ?><form method="post"> <input type = "hidden" name = "jirafeau" value =
205 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
206 "step" value = "3" /><input type = "submit" name =
207 "retry" value =
208 "<?php echo t('RETRY_STEP'); ?>" /></form>
209 <?php echo '</p></div>';
210 } else {
211 $cfg['installation_done'] = true;
212 jirafeau_export_cfg($cfg);
213 echo '<div class="message"><p>' .
214 t('JI_FONCTIONAL') . ':' .
215 '<br /><a href="./">' .
216 $cfg['web_root'].'</a></p></div>';
217 }
218 break;
219 }
220
221 require(JIRAFEAU_ROOT . 'lib/template/footer.php');

patrick-canterino.de