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

patrick-canterino.de