]> git.p6c8.net - jirafeau_project.git/blob - install.php
Fix footer project name
[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
138 if (!is_writable (JIRAFEAU_CFG) && !@chmod (JIRAFEAU_CFG, '0666'))
139 {
140 require (JIRAFEAU_ROOT . 'lib/template/header.php');
141 echo '<div class="error"><p>' .
142 t('The local configuration is not writable by the web server. ' .
143 'Give the write right to the web server on the ' .
144 '<code>lib/config.local.php</code> file.') .
145 '</p></div>';
146 require (JIRAFEAU_ROOT . 'lib/template/footer.php');
147 exit;
148 }
149
150 if (isset ($_POST['step']) && isset ($_POST['next']))
151 {
152 switch ($_POST['step'])
153 {
154 case 1:
155 $cfg['lang'] = $_POST['lang'];
156 jirafeau_export_cfg ($cfg);
157 break;
158
159 case 2:
160 $cfg['admin_password'] = $_POST['admin_password'];
161 jirafeau_export_cfg ($cfg);
162 break;
163
164 case 3:
165 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
166 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
167 jirafeau_export_cfg ($cfg);
168 break;
169
170 case 4:
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 default: break;
177 }
178
179 }
180
181 require (JIRAFEAU_ROOT . 'lib/settings.php');
182 require (JIRAFEAU_ROOT . 'lib/template/header.php');
183
184 $current = 1;
185 if (isset ($_POST['next']))
186 $current = $_POST['step'] + 1;
187 else if (isset ($_POST['previous']))
188 $current = $_POST['step'] - 1;
189 else if (isset ($_POST['retry']))
190 $current = $_POST['step'];
191
192 switch ($current)
193 {
194 case 1:
195 default:
196 ?><h2><?php printf (t('Installation of Jirafeau') . ' - ' . t('step') .
197 ' %d ' . t('out of') . ' %d', 1, 4);
198 ?></h2> <div id = "install"> <form action =
199 "<?php echo basename(__FILE__); ?>" method = "post"> <input type =
200 "hidden" name = "jirafeau" value =
201 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
202 "step" value = "1" /><fieldset> <legend><?php echo t('Language');
203 ?></legend> <table> <tr> <td class = "info" colspan =
204 "2"><?php echo
205 t
206 ('Jirafeau is internationalised. Choose a specific langage or ' .
207 'choose Automatic (langage is provided by user\'s browser).');
208 ?></td> </tr> <tr> <td class = "label"><label for = "select_lang"
209 ><?php echo t('Choose the default language') . ':';
210 ?></label></td>
211 <td class = "field">
212 <select name = "lang" id = "select_lang">
213 <?php foreach ($languages_list as $key => $item)
214 {
215 echo '<option value="'.$key.'"'.($key ==
216 $cfg['lang'] ? ' selected="selected"'
217 : '').'>'.$item.'</option>'.NL;
218 }
219 ?></select>
220 </td>
221 </tr>
222 <tr class = "nav">
223 <td></td>
224 <td class = "nav next"><input type = "submit" name = "next" value =
225 "<?php echo t('Next step'); ?>" /></td> </tr> </table>
226 </fieldset> </form> </div> <?php
227 break;
228
229 case 2:
230 ?><h2><?php printf (t('Installation of Jirafeau') . ' - ' . t('step') .
231 ' %d ' . t('out of') . ' %d', 2, 4);
232 ?></h2> <div id = "install"> <form action =
233 "<?php echo basename(__FILE__); ?>" method = "post"> <input type =
234 "hidden" name = "jirafeau" value =
235 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
236 "step" value = "2" /><fieldset> <legend><?php
237 echo t('Administration password');
238 ?></legend> <table> <tr> <td class = "info" colspan =
239 "2"><?php echo
240 t
241 ('Jirafeau has an administration interface (through admin.php). ' .
242 'You can set a password to access the intercace or let it be empty ' .
243 'to disable the interface.');
244 ?></td> </tr> <tr> <td class = "label"><label for = "select_password"
245 ><?php echo t('Administration password') . ':';
246 ?></label></td>
247 <td class = "field"><input type = "password" name = "admin_password"
248 id = "admin_password" size = "40" /></td>
249 </tr>
250 <tr class = "nav">
251 <td></td>
252 <td class = "nav next">
253 <input type = "submit"
254 class = "navleft" name = "previous" value = "<?php
255 echo t('Previous step'); ?>" />
256 <input type = "submit" name = "next" value =
257 "<?php echo t('Next step'); ?>" /></td> </tr> </table>
258 </fieldset> </form> </div> <?php
259 break;
260
261 case 3:
262 ?><h2><?php printf (t('Installation of Jirafeau') . ' - ' . t('step') .
263 ' %d ' . t('out of') . ' %d', 3, 4);
264 ?></h2> <div id = "install"> <form action =
265 "<?php echo basename(__FILE__); ?>" method = "post"> <input type =
266 "hidden" name = "jirafeau" value =
267 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
268 "step" value =
269 "3" /><fieldset> <legend><?php echo t('Information');
270 ?></legend> <table> <tr> <td class = "info" colspan =
271 "2"><?php echo
272 t
273 ('The base address of Jirafeau is the first part of the URL, until ' .
274 '(and including) the last slash. For example: ' .
275 '"http://www.example.com/". Do not forget the ending slash!');
276 ?></td> </tr> <tr> <td class = "label"><label for = "input_web_root"
277 ><?php echo t('Base address') . ':';
278 ?></label></td>
279 <td class = "field"><input type = "text" name = "web_root"
280 id = "input_web_root" value = "<?php
281 echo (empty($cfg['web_root']) ?
282 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
283 '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
284 ?>" size = "40" /></td>
285 </tr> <tr> <td class = "info" colspan = "2"><?php
286 echo t('The data directory is where your files and information about' .
287 ' your files will be stored. You should put it outside your web ' .
288 'site, or at least restrict the access of this directory. Do not ' .
289 'forget the ending slash!');
290 ?></td> </tr> <tr> <td class = "label"><label for = "input_var_root"
291 ><?php echo t('Data directory') . ':';
292 ?></label></td>
293 <td class = "field"><input type = "text" name = "var_root"
294 id = "input_var_root" value = "<?php
295 if(empty($cfg['var_root'])) {
296 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
297 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
298 $len_alphanum = strlen($alphanum);
299 $var = 'var-';
300 for($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
301 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
302 }
303 echo JIRAFEAU_ROOT . $var . '/';
304 }
305 else
306 echo $cfg['var_root'];
307 ?>" size = "40" /></td>
308 </tr> <tr> <td colspan = "2"><input type = "submit"
309 class = "navleft" name = "previous" value = "<?php
310 echo t('Previous step'); ?>" />
311 <input type = "submit" class = "navright" name = "next" value = "
312 <?php echo t('Next step'); ?>" />
313 </td> </tr> </table> </fieldset>
314 </form> </div> <?php
315 break;
316
317 case 4:
318 ?><h2><?php printf (t('Installation of Jirafeau') . ' - ' . t('step') .
319 ' %d ' . t('out of') . ' %d', 4, 4);
320 ?></h2> <div id = "install"> <form action =
321 "<?php echo basename(__FILE__); ?>" method = "post"> <input type =
322 "hidden" name = "jirafeau" value =
323 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
324 "step" value =
325 "4" /><fieldset> <legend><?php echo t('Finalisation');
326 ?></legend> <table> <tr> <td class = "info" colspan =
327 "2"><?php echo
328 t ('Jirafeau is setting the website according to the configuration ' .
329 'you provided.');
330 ?></td> </tr> <tr> <td class = "nav previous"><input type =
331 "submit" name = "previous" value =
332 "
333 <?php
334 echo t('Previous step');
335 ?>" /></td> <td></td> </tr>
336 </table> </fieldset> </form> </div>
337 <?php
338 $err = jirafeau_check_var_dir ($cfg['var_root']);
339 if ($err['has_error'])
340 {
341 echo '<div class="error"><p>'.$err['why'].'<br />'.NL;
342 ?><form action = "<?php echo basename(__FILE__); ?>" method =
343 "post"> <input type = "hidden" name = "jirafeau" value =
344 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
345 "step" value = "4" /><input type = "submit" name =
346 "retry" value =
347 "<?php echo t('Retry this step'); ?>" /></form>
348 <?php echo '</p></div>';
349 }
350 else
351 {
352 echo '<div class="message"><p>' .
353 t('Jirafeau is now fully operational') . ':' .
354 '<br /><a href="' . $cfg['web_root'] . '">' .
355 $cfg['web_root'].'</a></p></div>';
356 }
357 break;
358 }
359
360 require (JIRAFEAU_ROOT . 'lib/template/footer.php');
361 ?>

patrick-canterino.de