]>
git.p6c8.net - jirafeau.git/blob - install.php
f83faf085543b5e29ad9cedc77254375a8edd664
3 * Jirafeau, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
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.
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.
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/>.
19 define ('JIRAFEAU_ROOT', dirname (__FILE__
) . '/');
21 define ('QUOTE', "'");
23 define ('JIRAFEAU_CFG', JIRAFEAU_ROOT
.'lib/config.local.php');
24 define ('JIRAFEAU_VAR_RAND_LENGTH', 15);
26 require (JIRAFEAU_ROOT
. 'lib/functions.php');
27 require (JIRAFEAU_ROOT
. 'lib/lang.php');
28 require (JIRAFEAU_ROOT
. 'lib/config.original.php');
31 jirafeau_quoted ($str)
33 return QUOTE
. str_replace (QUOTE
, "\'", $str) . QUOTE
;
37 jirafeau_export_cfg ($cfg)
39 $handle = fopen (JIRAFEAU_CFG
, 'w');
40 fwrite ($handle, '<?php' . NL
);
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)
48 fwrite ($handle, '$cfg[' . jirafeau_quoted ($key) . '] = ');
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)));
59 fwrite ($handle, 'null');
60 fwrite ($handle, ';'.NL
);
62 /* No newline at the end of the file to be able to send headers. */
63 fwrite ($handle, '?>');
68 jirafeau_mkdir ($path)
70 if (!file_exists ($path) && !@mkdir
($path, 0755))
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.
82 jirafeau_is_writable ($path)
84 /* "@" gets rid of error messages. */
85 return is_writable ($path) || @chmod
($path, 0777);
89 jirafeau_check_var_dir ($path)
91 $mkdir_str1 = t('The following directory could not be created') . ':';
92 $mkdir_str2 = t('You should create this directory by hand.');
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 ' .
96 $solution_str = t('Here is a solution') . ':';
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);
104 foreach (array ('files', 'links', 'async') as $subdir)
106 $subpath = $path.$subdir;
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);
115 return array ('has_error' => false, 'why' => '');
119 jirafeau_add_ending_slash ($path)
121 return $path . ((substr ($path, -1) == '/') ?
'' : '/');
124 if ($cfg['installation_done'] === true)
126 header('Location: index.php');
130 if (!file_exists (JIRAFEAU_CFG
))
132 /* We try to create an empty one. */
133 if (!@touch
(JIRAFEAU_CFG
))
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 'right to the web server (preferred solution), or give the ' .
140 'write permission to the web server on the <code>lib</code> ' .
143 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
148 if (!is_writable (JIRAFEAU_CFG
) && !@chmod
(JIRAFEAU_CFG
, '0666'))
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.') .
156 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
160 if (isset ($_POST['step']) && isset ($_POST['next']))
162 switch ($_POST['step'])
165 $cfg['lang'] = $_POST['lang'];
166 jirafeau_export_cfg ($cfg);
170 $cfg['admin_password'] = $_POST['admin_password'];
171 jirafeau_export_cfg ($cfg);
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);
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);
191 require (JIRAFEAU_ROOT
. 'lib/settings.php');
192 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
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'];
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
=
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') . ':';
222 <select name
= "lang" id
= "select_lang">
223 <?php
foreach ($languages_list as $key => $item)
225 echo '<option value="'.$key.'"'.($key ==
226 $cfg['lang'] ?
' selected="selected"'
227 : '').'>'.$item.'</option>'.NL
;
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
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
=
251 ('Jirafeau has an administration interface (through admin.php). ' .
252 'You can set a password to access the intercace or let it be empty ' .
253 'to disable the interface.');
254 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_password"
255 ><?php
echo t('Administration password') . ':';
257 <td
class = "field"><input type
= "password" name
= "admin_password"
258 id
= "admin_password" size
= "40" /></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
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
=
279 "3" /><fieldset
> <legend
><?php
echo t('Information');
280 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
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 ending slash!');
286 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_web_root"
287 ><?php
echo t('Base address') . ':';
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 of this directory. Do not ' .
299 'forget the ending slash!');
300 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_var_root"
301 ><?php
echo t('Data directory') . ':';
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);
310 for($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
311 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
313 echo JIRAFEAU_ROOT . $var . '/';
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
>
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
=
335 "4" /><fieldset
> <legend
><?php
echo t('Finalisation');
336 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
338 t ('Jirafeau is setting the website according to the configuration ' .
340 ?
></td
> </tr
> <tr
> <td
class = "nav previous"><input type
=
341 "submit" name
= "previous" value
=
344 echo t('Previous step');
345 ?>" /></td
> <td
></td
> </tr
>
346 </table
> </fieldset
> </form
> </div
>
348 $err = jirafeau_check_var_dir ($cfg['var_root']);
349 if ($err['has_error'])
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
=
357 "<?php echo t('Retry this step'); ?>" /></form
>
358 <?php
echo '</p></div>';
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>';
372 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
patrick-canterino.de