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

patrick-canterino.de