]> git.p6c8.net - jirafeau_mojo42.git/blob - install.php
8cae45c6f7d5034cacc92b124ad365cf0de6bba9
[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 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
20 define ('NL', "\n");
21 define ('QUOTE', "'");
22
23 define ('JIRAFEAU_CFG', JIRAFEAU_ROOT.'lib/config.local.php');
24 define ('JIRAFEAU_VAR_RAND_LENGTH', 15);
25
26 require (JIRAFEAU_ROOT . 'lib/functions.php');
27 require (JIRAFEAU_ROOT . 'lib/lang.php');
28 require (JIRAFEAU_ROOT . 'lib/config.original.php');
29
30 function
31 jirafeau_quoted ($str)
32 {
33 return QUOTE . str_replace (QUOTE, "\'", $str) . QUOTE;
34 }
35
36 function
37 jirafeau_export_cfg ($cfg)
38 {
39 $handle = fopen (JIRAFEAU_CFG, 'w');
40 fwrite ($handle, '<?php' . NL);
41 fwrite ($handle,
42 '/* ' .
43 t ('This file was generated by the install process. ' .
44 'You can edit it. Please see config.original.php to understand the ' .
45 'configuration items.') . ' */' . NL);
46 foreach ($cfg as $key => $item)
47 {
48 fwrite ($handle, '$cfg[' . jirafeau_quoted ($key) . '] = ');
49 if (is_bool ($item))
50 fwrite ($handle, ($item ? 'true' : 'false'));
51 else if (is_string ($item))
52 fwrite ($handle, jirafeau_quoted ($item));
53 else if (is_int ($item))
54 fwrite ($handle, $item);
55 else
56 fwrite ($handle, 'null');
57 fwrite ($handle, ';'.NL);
58 }
59 /* No newline at the end of the file to be able to send headers. */
60 fwrite ($handle, '?>');
61 fclose ($handle);
62 }
63
64 function
65 jirafeau_mkdir ($path)
66 {
67 if (!file_exists ($path) && !@mkdir ($path, 0755))
68 return false;
69 return true;
70 }
71
72 /**
73 * Returns true whether the path is writable or we manage to make it
74 * so, which essentially is the same thing.
75 * @param $path is the file or directory to be tested.
76 * @return true if $path is writable.
77 */
78 function
79 jirafeau_is_writable ($path)
80 {
81 /* "@" gets rid of error messages. */
82 return is_writable ($path) || @chmod ($path, 0777);
83 }
84
85 function
86 jirafeau_check_var_dir ($path)
87 {
88 $mkdir_str1 = t('The following directory could not be created') . ':';
89 $mkdir_str2 = t('You should create this directory by hand.');
90 $write_str1 = t('The following directory is not writable') . ':';
91 $write_str2 = t('You should give the write right to the web server on ' .
92 'this directory.');
93 $solution_str = t('Here is a solution') . ':';
94
95 if (!jirafeau_mkdir ($path) || !jirafeau_is_writable ($path))
96 return array ('has_error' => true,
97 'why' => $mkdir_str1 . '<br /><code>' .
98 $path . '</code><br />' . $solution_str .
99 '<br />' . $mkdir_str2);
100
101 foreach (array ('files', 'links', 'async', 'block') as $subdir)
102 {
103 $subpath = $path.$subdir;
104
105 if (!jirafeau_mkdir ($subpath) || !jirafeau_is_writable ($subpath))
106 return array ('has_error' => true,
107 'why' => $mkdir_str1 . '<br /><code>' .
108 $subpath . '</code><br />' . $solution_str .
109 '<br />' . $mkdir_str2);
110 }
111
112 return array ('has_error' => false, 'why' => '');
113 }
114
115 function
116 jirafeau_add_ending_slash ($path)
117 {
118 return $path . ((substr ($path, -1) == '/') ? '' : '/');
119 }
120
121 if (!file_exists (JIRAFEAU_CFG))
122 {
123 /* We try to create an empty one. */
124 if (!@touch (JIRAFEAU_CFG))
125 {
126 require (JIRAFEAU_ROOT . 'lib/template/header.php');
127 echo '<div class="error"><p>' .
128 t('The local configuration file could not be created. Create a ' .
129 '<code>lib/config.local.php</code> file and give the write ' .
130 'right to the web server (preferred solution), or give the ' .
131 'write right to the web server on the <code>lib</code> ' .
132 'directory.') .
133 '</p></div>';
134 require (JIRAFEAU_ROOT . 'lib/template/footer.php');
135 exit;
136 }
137 }
138 #else
139 #{
140 # header('Location: index.php');
141 # exit;
142 #}
143
144 if (!is_writable (JIRAFEAU_CFG) && !@chmod (JIRAFEAU_CFG, '0666'))
145 {
146 require (JIRAFEAU_ROOT . 'lib/template/header.php');
147 echo '<div class="error"><p>' .
148 t('The local configuration is not writable by the web server. ' .
149 'Give the write right to the web server on the ' .
150 '<code>lib/config.local.php</code> file.') .
151 '</p></div>';
152 require (JIRAFEAU_ROOT . 'lib/template/footer.php');
153 exit;
154 }
155
156 if (isset ($_POST['step']) && isset ($_POST['next']))
157 {
158 switch ($_POST['step'])
159 {
160 case 1:
161 $cfg['lang'] = $_POST['lang'];
162 jirafeau_export_cfg ($cfg);
163 break;
164
165 case 2:
166 $cfg['admin_password'] = $_POST['admin_password'];
167 jirafeau_export_cfg ($cfg);
168 break;
169
170 case 3:
171 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
172 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
173 jirafeau_export_cfg ($cfg);
174 break;
175
176 case 4:
177 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
178 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
179 jirafeau_export_cfg ($cfg);
180 break;
181
182 default: break;
183 }
184
185 }
186
187 require (JIRAFEAU_ROOT . 'lib/settings.php');
188 require (JIRAFEAU_ROOT . 'lib/template/header.php');
189
190 $current = 1;
191 if (isset ($_POST['next']))
192 $current = $_POST['step'] + 1;
193 else if (isset ($_POST['previous']))
194 $current = $_POST['step'] - 1;
195 else if (isset ($_POST['retry']))
196 $current = $_POST['step'];
197
198 switch ($current)
199 {
200 case 1:
201 default:
202 ?><h2><?php printf (t('Installation of Jirafeau') . ' - ' . t('step') .
203 ' %d ' . t('out of') . ' %d', 1, 4);
204 ?></h2> <div id = "install"> <form action =
205 "<?php echo basename(__FILE__); ?>" method = "post"> <input type =
206 "hidden" name = "jirafeau" value =
207 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
208 "step" value = "1" /><fieldset> <legend><?php echo t('Language');
209 ?></legend> <table> <tr> <td class = "info" colspan =
210 "2"><?php echo
211 t
212 ('Jirafeau is internationalised. Choose a specific langage or ' .
213 'choose Automatic (langage is provided by user\'s browser).');
214 ?></td> </tr> <tr> <td class = "label"><label for = "select_lang"
215 ><?php echo t('Choose the default language') . ':';
216 ?></label></td>
217 <td class = "field">
218 <select name = "lang" id = "select_lang">
219 <?php foreach ($languages_list as $key => $item)
220 {
221 echo '<option value="'.$key.'"'.($key ==
222 $cfg['lang'] ? ' selected="selected"'
223 : '').'>'.$item.'</option>'.NL;
224 }
225 ?></select>
226 </td>
227 </tr>
228 <tr class = "nav">
229 <td></td>
230 <td class = "nav next"><input type = "submit" name = "next" value =
231 "<?php echo t('Next step'); ?>" /></td> </tr> </table>
232 </fieldset> </form> </div> <?php
233 break;
234
235 case 2:
236 ?><h2><?php printf (t('Installation of Jirafeau') . ' - ' . t('step') .
237 ' %d ' . t('out of') . ' %d', 2, 4);
238 ?></h2> <div id = "install"> <form action =
239 "<?php echo basename(__FILE__); ?>" method = "post"> <input type =
240 "hidden" name = "jirafeau" value =
241 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
242 "step" value = "2" /><fieldset> <legend><?php
243 echo t('Administration password');
244 ?></legend> <table> <tr> <td class = "info" colspan =
245 "2"><?php echo
246 t
247 ('Jirafeau has an administration interface (through admin.php). ' .
248 'You can set a password to access the intercace or let it be empty ' .
249 'to disable the interface.');
250 ?></td> </tr> <tr> <td class = "label"><label for = "select_password"
251 ><?php echo t('Administration password') . ':';
252 ?></label></td>
253 <td class = "field"><input type = "password" name = "admin_password"
254 id = "admin_password" size = "40" /></td>
255 </tr>
256 <tr class = "nav">
257 <td></td>
258 <td class = "nav next">
259 <input type = "submit"
260 class = "navleft" name = "previous" value = "<?php
261 echo t('Previous step'); ?>" />
262 <input type = "submit" name = "next" value =
263 "<?php echo t('Next step'); ?>" /></td> </tr> </table>
264 </fieldset> </form> </div> <?php
265 break;
266
267 case 3:
268 ?><h2><?php printf (t('Installation of Jirafeau') . ' - ' . t('step') .
269 ' %d ' . t('out of') . ' %d', 3, 4);
270 ?></h2> <div id = "install"> <form action =
271 "<?php echo basename(__FILE__); ?>" method = "post"> <input type =
272 "hidden" name = "jirafeau" value =
273 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
274 "step" value =
275 "3" /><fieldset> <legend><?php echo t('Information');
276 ?></legend> <table> <tr> <td class = "info" colspan =
277 "2"><?php echo
278 t
279 ('The base address of Jirafeau is the first part of the URL, until ' .
280 '(and including) the last slash. For example: ' .
281 '"http://www.example.com/". Do not forget the ending slash!');
282 ?></td> </tr> <tr> <td class = "label"><label for = "input_web_root"
283 ><?php echo t('Base address') . ':';
284 ?></label></td>
285 <td class = "field"><input type = "text" name = "web_root"
286 id = "input_web_root" value = "<?php
287 echo (empty($cfg['web_root']) ?
288 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
289 '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
290 ?>" size = "40" /></td>
291 </tr> <tr> <td class = "info" colspan = "2"><?php
292 echo t('The data directory is where your files and information about' .
293 ' your files will be stored. You should put it outside your web ' .
294 'site, or at least restrict the access of this directory. Do not ' .
295 'forget the ending slash!');
296 ?></td> </tr> <tr> <td class = "label"><label for = "input_var_root"
297 ><?php echo t('Data directory') . ':';
298 ?></label></td>
299 <td class = "field"><input type = "text" name = "var_root"
300 id = "input_var_root" value = "<?php
301 if(empty($cfg['var_root'])) {
302 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
303 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
304 $len_alphanum = strlen($alphanum);
305 $var = 'var-';
306 for($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
307 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
308 }
309 echo JIRAFEAU_ROOT . $var . '/';
310 }
311 else
312 echo $cfg['var_root'];
313 ?>" size = "40" /></td>
314 </tr> <tr> <td colspan = "2"><input type = "submit"
315 class = "navleft" name = "previous" value = "<?php
316 echo t('Previous step'); ?>" />
317 <input type = "submit" class = "navright" name = "next" value = "
318 <?php echo t('Next step'); ?>" />
319 </td> </tr> </table> </fieldset>
320 </form> </div> <?php
321 break;
322
323 case 4:
324 ?><h2><?php printf (t('Installation of Jirafeau') . ' - ' . t('step') .
325 ' %d ' . t('out of') . ' %d', 4, 4);
326 ?></h2> <div id = "install"> <form action =
327 "<?php echo basename(__FILE__); ?>" method = "post"> <input type =
328 "hidden" name = "jirafeau" value =
329 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
330 "step" value =
331 "4" /><fieldset> <legend><?php echo t('Finalisation');
332 ?></legend> <table> <tr> <td class = "info" colspan =
333 "2"><?php echo
334 t ('Jirafeau is setting the website according to the configuration ' .
335 'you provided.');
336 ?></td> </tr> <tr> <td class = "nav previous"><input type =
337 "submit" name = "previous" value =
338 "
339 <?php
340 echo t('Previous step');
341 ?>" /></td> <td></td> </tr>
342 </table> </fieldset> </form> </div>
343 <?php
344 $err = jirafeau_check_var_dir ($cfg['var_root']);
345 if ($err['has_error'])
346 {
347 echo '<div class="error"><p>'.$err['why'].'<br />'.NL;
348 ?><form action = "<?php echo basename(__FILE__); ?>" method =
349 "post"> <input type = "hidden" name = "jirafeau" value =
350 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
351 "step" value = "4" /><input type = "submit" name =
352 "retry" value =
353 "<?php echo t('Retry this step'); ?>" /></form>
354 <?php echo '</p></div>';
355 }
356 else
357 {
358 echo '<div class="message"><p>' .
359 t('Jirafeau is now fully operational') . ':' .
360 '<br /><a href="' . $cfg['web_root'] . '">' .
361 $cfg['web_root'].'</a></p></div>';
362 }
363 break;
364 }
365
366 require (JIRAFEAU_ROOT . 'lib/template/footer.php');
367 ?>

patrick-canterino.de