]> git.p6c8.net - jirafeau_project.git/blob - install.php
fix spelling mistakes
[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(
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" autocomplete = "new-password"/></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']) ? jirafeau_default_web_root() : $cfg['web_root']);
152 ?>" size = "40" /></td>
153 </tr> <tr> <td class = "info" colspan = "2"><?php
154 echo t('DATA_DIR_EXPLAINATION');
155 ?></td> </tr> <tr> <td class = "label"><label for = "input_var_root"
156 ><?php echo t('DATA_DIR') . ':';
157 ?></label></td>
158 <td class = "field"><input type = "text" name = "var_root"
159 id = "input_var_root" value = "<?php
160 if (empty($cfg['var_root'])) {
161 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
162 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
163 $len_alphanum = strlen($alphanum);
164 $var = 'var-';
165 for ($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
166 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
167 }
168 echo JIRAFEAU_ROOT . $var . '/';
169 } else {
170 echo $cfg['var_root'];
171 }
172 ?>" size = "40" /></td>
173 </tr> <tr> <td colspan = "2"><input type = "submit"
174 class = "navleft" name = "previous" value = "<?php
175 echo t('PREV_STEP'); ?>" />
176 <input type = "submit" class = "navright" name = "next" value =
177 "<?php echo t('NEXT_STEP'); ?>" />
178 </td> </tr> </table> </fieldset>
179 </form> </div> <?php
180 break;
181
182 case 3:
183 ?><h2><?php printf(t('JI_INSTALL') . ' - ' . t('STEP') .
184 ' %d ' . t('OUT_OF') . ' %d', 3, 3);
185 ?></h2> <div id = "install"> <form method="post"> <input type =
186 "hidden" name = "jirafeau" value =
187 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
188 "step" value =
189 "3" /><fieldset> <legend><?php echo t('FINALIZATION');
190 ?></legend> <table> <tr> <td class = "info" colspan =
191 "2"><?php echo t('SETTING_UP');
192 ?></td> </tr> <tr> <td class = "nav previous"><input type =
193 "submit" name = "previous" value = " <?php echo t('PREV_STEP');
194 ?>" /></td> <td></td> </tr>
195 </table> </fieldset> </form> </div>
196 <?php
197 $err = jirafeau_check_var_dir($cfg['var_root']);
198 if ($err['has_error']) {
199 echo '<div class="error"><p>'.$err['why'].'<br />'.NL; ?><form method="post"> <input type = "hidden" name = "jirafeau" value =
200 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
201 "step" value = "3" /><input type = "submit" name =
202 "retry" value =
203 "<?php echo t('RETRY_STEP'); ?>" /></form>
204 <?php echo '</p></div>';
205 } else {
206 $cfg['installation_done'] = true;
207 jirafeau_export_cfg($cfg);
208 echo '<div class="message"><p>' .
209 t('JI_FONCTIONAL') . ':' .
210 '<br /><a href="./">' .
211 $cfg['web_root'].'</a></p></div>';
212 }
213 break;
214 }
215
216 require(JIRAFEAU_ROOT . 'lib/template/footer.php');

patrick-canterino.de