]> git.p6c8.net - jirafeau_mojo42.git/blob - install.php
[DOC] Fix feature list of 3.0.0
[jirafeau_mojo42.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 * Prepend used functions
31 **/
32
33 function jirafeau_quoted($str)
34 {
35 return QUOTE . str_replace(QUOTE, "\'", $str) . QUOTE;
36 }
37
38 function jirafeau_export_cfg($cfg)
39 {
40 $content = '<?php' . NL;
41 $content .= '/* ' . t('This file was generated by the install process. ' .
42 'You can edit it. Please see config.original.php to understand the ' .
43 'configuration items.') . ' */' . NL;
44 $content .= '$cfg = ' . var_export($cfg, true) . ';';
45
46 $fileWrite = file_put_contents(JIRAFEAU_CFG, $content);
47
48 if (false === $fileWrite) {
49 jirafeau_fatal_error(t('Can not write local configuration file'));
50 }
51 }
52
53 function jirafeau_mkdir($path)
54 {
55 return !(!file_exists($path) && !@mkdir($path, 0755));
56 }
57
58 /**
59 * Returns true whether the path is writable or we manage to make it
60 * so, which essentially is the same thing.
61 * @param $path is the file or directory to be tested.
62 * @return true if $path is writable.
63 */
64 function jirafeau_is_writable($path)
65 {
66 /* "@" gets rid of error messages. */
67 return is_writable($path) || @chmod($path, 0777);
68 }
69
70 function jirafeau_check_var_dir($path)
71 {
72 $mkdir_str1 = t('The following directory could not be created') . ':';
73 $mkdir_str2 = t('You should create this directory manually.');
74 $write_str1 = t('The following directory is not writable') . ':';
75 $write_str2 = t('You should give the write permission to the web server on ' .
76 'this directory.');
77 $solution_str = t('Here is a solution') . ':';
78
79 if (!jirafeau_mkdir($path) || !jirafeau_is_writable($path)) {
80 return array('has_error' => true,
81 'why' => $mkdir_str1 . '<br /><code>' .
82 $path . '</code><br />' . $solution_str .
83 '<br />' . $mkdir_str2);
84 }
85
86 foreach (array('files', 'links', 'async', 'alias') as $subdir) {
87 $subpath = $path.$subdir;
88
89 if (!jirafeau_mkdir($subpath) || !jirafeau_is_writable($subpath)) {
90 return array('has_error' => true,
91 'why' => $mkdir_str1 . '<br /><code>' .
92 $subpath . '</code><br />' . $solution_str .
93 '<br />' . $mkdir_str2);
94 }
95 }
96
97 return array('has_error' => false, 'why' => '');
98 }
99
100 function jirafeau_add_ending_slash($path)
101 {
102 return $path . ((substr($path, -1) == '/') ? '' : '/');
103 }
104
105 function jirafeau_fatal_error($errorText)
106 {
107 echo '<div class="error"><h2>Error</h2><p>' . $errorText . '</p></div>';
108 require(JIRAFEAU_ROOT . 'lib/template/footer.php');
109 exit;
110 }
111
112 /**
113 * Check installation
114 **/
115
116 // Is the installation process done already?
117 // Then there is nothing to do here → redirect to the main page.
118 if ($cfg['installation_done'] === true) {
119 header('Location: index.php');
120 exit;
121 }
122
123 /**
124 * Prepare installation process
125 **/
126
127 require(JIRAFEAU_ROOT . 'lib/template/header.php');
128
129 // does the local configuration file exist?
130 if (!file_exists(JIRAFEAU_CFG)) {
131 // show an error if it is not possible to create the file
132 if (!@touch(JIRAFEAU_CFG)) {
133 jirafeau_fatal_error(
134 t('The local configuration file could not be created. Create a ' .
135 '<code>lib/config.local.php</code> file and give the write ' .
136 'permission to the web server (preferred solution), or give the ' .
137 'write permission to the web server on the <code>lib</code> ' .
138 'directory.')
139 );
140 }
141 }
142
143 // is the local configuration writable?
144 if (!is_writable(JIRAFEAU_CFG) && !@chmod(JIRAFEAU_CFG, '0666')) {
145 jirafeau_fatal_error(
146 t('The local configuration is not writable by the web server. ' .
147 'Give the write permission to the web server on the ' .
148 '<code>lib/config.local.php</code> file.')
149 );
150 }
151
152 /**
153 * Run trough each installation step
154 **/
155
156 if (isset($_POST['step']) && isset($_POST['next'])) {
157 switch ($_POST['step']) {
158 case 1:
159 $cfg['lang'] = $_POST['lang'];
160 jirafeau_export_cfg($cfg);
161 break;
162
163 case 2:
164 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
165 jirafeau_export_cfg($cfg);
166 break;
167
168 case 3:
169 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
170 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
171 jirafeau_export_cfg($cfg);
172 break;
173
174 case 4:
175 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
176 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
177 jirafeau_export_cfg($cfg);
178 break;
179 }
180 }
181
182 $current = 1;
183 if (isset($_POST['next'])) {
184 $current = $_POST['step'] + 1;
185 } elseif (isset($_POST['previous'])) {
186 $current = $_POST['step'] - 1;
187 } elseif (isset($_POST['retry'])) {
188 $current = $_POST['step'];
189 }
190
191 switch ($current) {
192 case 1:
193 default:
194 ?><h2><?php printf(t('Installation of Jirafeau') . ' - ' . t('step') .
195 ' %d ' . t('out of') . ' %d', 1, 4);
196 ?></h2> <div id = "install"> <form method="post"> <input type =
197 "hidden" name = "jirafeau" value =
198 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
199 "step" value = "1" /><fieldset> <legend><?php echo t('Language');
200 ?></legend> <table> <tr> <td class = "info" colspan =
201 "2"><?php echo
202 t('Jirafeau is internationalised. Choose a specific langage or ' .
203 'choose Automatic (langage is provided by user\'s browser).');
204 ?></td> </tr> <tr> <td class = "label"><label for = "select_lang"
205 ><?php echo t('Choose the default language') . ':';
206 ?></label></td>
207 <td class = "field">
208 <select name = "lang" id = "select_lang">
209 <?php foreach ($languages_list as $key => $item) {
210 echo '<option value="'.$key.'"'.($key ==
211 $cfg['lang'] ? ' selected="selected"'
212 : '').'>'.$item.'</option>'.NL;
213 }
214 ?></select>
215 </td>
216 </tr>
217 <tr class = "nav">
218 <td></td>
219 <td class = "nav next"><input type = "submit" name = "next" value =
220 "<?php echo t('Next step'); ?>" /></td> </tr> </table>
221 </fieldset> </form> </div> <?php
222 break;
223
224 case 2:
225 ?><h2><?php printf(t('Installation of Jirafeau') . ' - ' . t('step') .
226 ' %d ' . t('out of') . ' %d', 2, 4);
227 ?></h2> <div id = "install"> <form method="post"> <input type =
228 "hidden" name = "jirafeau" value =
229 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
230 "step" value = "2" /><fieldset> <legend><?php
231 echo t('Administration password');
232 ?></legend> <table> <tr> <td class = "info" colspan =
233 "2"><?php echo
234 t('Jirafeau has an administration interface (through admin.php). ' .
235 'You can set a password to access the interface or leave it empty ' .
236 'to disable the interface.');
237 ?></td> </tr> <tr> <td class = "label"><label for = "select_password"
238 ><?php echo t('Administration password') . ':';
239 ?></label></td>
240 <td class = "field"><input type = "password" name = "admin_password"
241 id = "admin_password" size = "40" /></td>
242 </tr>
243 <tr class = "nav">
244 <td></td>
245 <td class = "nav next">
246 <input type = "submit"
247 class = "navleft" name = "previous" value = "<?php
248 echo t('Previous step'); ?>" />
249 <input type = "submit" name = "next" value =
250 "<?php echo t('Next step'); ?>" /></td> </tr> </table>
251 </fieldset> </form> </div> <?php
252 break;
253
254 case 3:
255 ?><h2><?php printf(t('Installation of Jirafeau') . ' - ' . t('step') .
256 ' %d ' . t('out of') . ' %d', 3, 4);
257 ?></h2> <div id = "install"> <form method="post"> <input type =
258 "hidden" name = "jirafeau" value =
259 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
260 "step" value =
261 "3" /><fieldset> <legend><?php echo t('Information');
262 ?></legend> <table> <tr> <td class = "info" colspan =
263 "2"><?php echo
264 t('The base address of Jirafeau is the first part of the URL, until ' .
265 '(and including) the last slash. For example: ' .
266 '"http://www.example.com/". Do not forget the trailing slash!');
267 ?></td> </tr> <tr> <td class = "label"><label for = "input_web_root"
268 ><?php echo t('Base address') . ':';
269 ?></label></td>
270 <td class = "field"><input type = "text" name = "web_root"
271 id = "input_web_root" value = "<?php
272 echo(empty($cfg['web_root']) ?
273 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
274 '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
275 ?>" size = "40" /></td>
276 </tr> <tr> <td class = "info" colspan = "2"><?php
277 echo t('The data directory is where your files and information about' .
278 ' your files will be stored. You should put it outside your web ' .
279 'site, or at least restrict the access to this directory. Do not ' .
280 'forget the trailing slash!');
281 ?></td> </tr> <tr> <td class = "label"><label for = "input_var_root"
282 ><?php echo t('Data directory') . ':';
283 ?></label></td>
284 <td class = "field"><input type = "text" name = "var_root"
285 id = "input_var_root" value = "<?php
286 if (empty($cfg['var_root'])) {
287 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
288 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
289 $len_alphanum = strlen($alphanum);
290 $var = 'var-';
291 for ($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
292 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
293 }
294 echo JIRAFEAU_ROOT . $var . '/';
295 } else {
296 echo $cfg['var_root'];
297 }
298 ?>" size = "40" /></td>
299 </tr> <tr> <td colspan = "2"><input type = "submit"
300 class = "navleft" name = "previous" value = "<?php
301 echo t('Previous step'); ?>" />
302 <input type = "submit" class = "navright" name = "next" value = "
303 <?php echo t('Next step'); ?>" />
304 </td> </tr> </table> </fieldset>
305 </form> </div> <?php
306 break;
307
308 case 4:
309 ?><h2><?php printf(t('Installation of Jirafeau') . ' - ' . t('step') .
310 ' %d ' . t('out of') . ' %d', 4, 4);
311 ?></h2> <div id = "install"> <form method="post"> <input type =
312 "hidden" name = "jirafeau" value =
313 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
314 "step" value =
315 "4" /><fieldset> <legend><?php echo t('Finalisation');
316 ?></legend> <table> <tr> <td class = "info" colspan =
317 "2"><?php echo
318 t('Jirafeau is setting the website according to the configuration ' .
319 'you provided.');
320 ?></td> </tr> <tr> <td class = "nav previous"><input type =
321 "submit" name = "previous" value =
322 "
323 <?php
324 echo t('Previous step');
325 ?>" /></td> <td></td> </tr>
326 </table> </fieldset> </form> </div>
327 <?php
328 $err = jirafeau_check_var_dir($cfg['var_root']);
329 if ($err['has_error']) {
330 echo '<div class="error"><p>'.$err['why'].'<br />'.NL; ?><form method="post"> <input type = "hidden" name = "jirafeau" value =
331 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
332 "step" value = "4" /><input type = "submit" name =
333 "retry" value =
334 "<?php echo t('Retry this step'); ?>" /></form>
335 <?php echo '</p></div>';
336 } else {
337 $cfg['installation_done'] = true;
338 jirafeau_export_cfg($cfg);
339 echo '<div class="message"><p>' .
340 t('Jirafeau is now fully operational') . ':' .
341 '<br /><a href="' . $cfg['web_root'] . '">' .
342 $cfg['web_root'].'</a></p></div>';
343 }
344 break;
345 }
346
347 require(JIRAFEAU_ROOT . 'lib/template/footer.php');

patrick-canterino.de