]>
git.p6c8.net - jirafeau.git/blob - install.php
d8e5fdfef6db07632340479f11f71c2e3bebc560
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/lang.php');
27 require (JIRAFEAU_ROOT
. 'lib/config.original.php');
30 jirafeau_quoted ($str)
32 return QUOTE
. str_replace (QUOTE
, "\'", $str) . QUOTE
;
36 jirafeau_export_cfg ($cfg)
38 $handle = fopen (JIRAFEAU_CFG
, 'w');
39 fwrite ($handle, '<?php' . NL
);
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)
47 fwrite ($handle, '$cfg[' . jirafeau_quoted ($key) . '] = ');
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);
55 fwrite ($handle, 'null');
56 fwrite ($handle, ';'.NL
);
58 /* No newline at the end of the file to be able to send headers. */
59 fwrite ($handle, '?>');
64 jirafeau_mkdir ($path)
66 if (!file_exists ($path) && !@mkdir
($path, 0755))
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.
78 jirafeau_is_writable ($path)
80 /* "@" gets rid of error messages. */
81 return is_writable ($path) || @chmod
($path, 0777);
85 jirafeau_check_var_dir ($path)
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 ' .
92 $solution_str = t('Here is a solution') . ':';
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);
100 foreach (array ('files', 'links', 'async', 'block') as $subdir)
102 $subpath = $path.$subdir;
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);
111 return array ('has_error' => false, 'why' => '');
115 jirafeau_add_ending_slash ($path)
117 return $path . ((substr ($path, -1) == '/') ?
'' : '/');
120 if (!file_exists (JIRAFEAU_CFG
))
122 /* We try to create an empty one. */
123 if (!@touch
(JIRAFEAU_CFG
))
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> ' .
133 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
138 if (!is_writable (JIRAFEAU_CFG
) && !@chmod
(JIRAFEAU_CFG
, '0666'))
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.') .
146 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
150 if (isset ($_POST['step']) && isset ($_POST['next']))
152 switch ($_POST['step'])
155 $cfg['lang'] = $_POST['lang'];
156 jirafeau_export_cfg ($cfg);
160 $cfg['admin_password'] = $_POST['admin_password'];
161 jirafeau_export_cfg ($cfg);
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);
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);
181 require (JIRAFEAU_ROOT
. 'lib/settings.php');
182 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
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'];
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
=
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') . ':';
212 <select name
= "lang" id
= "select_lang">
213 <?php
foreach ($languages_list as $key => $item)
215 echo '<option value="'.$key.'"'.($key ==
216 $cfg['lang'] ?
' selected="selected"'
217 : '').'>'.$item.'</option>'.NL
;
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
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
=
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') . ':';
247 <td
class = "field"><input type
= "password" name
= "admin_password"
248 id
= "admin_password" size
= "40" /></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
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
=
269 "3" /><fieldset
> <legend
><?php
echo t('Information');
270 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
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') . ':';
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') . ':';
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);
300 for($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
301 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
303 echo JIRAFEAU_ROOT . $var . '/';
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
>
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
=
325 "4" /><fieldset
> <legend
><?php
echo t('Finalisation');
326 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
328 t ('Jirafeau is setting the website according to the configuration ' .
330 ?
></td
> </tr
> <tr
> <td
class = "nav previous"><input type
=
331 "submit" name
= "previous" value
=
334 echo t('Previous step');
335 ?>" /></td
> <td
></td
> </tr
>
336 </table
> </fieldset
> </form
> </div
>
338 $err = jirafeau_check_var_dir ($cfg['var_root']);
339 if ($err['has_error'])
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
=
347 "<?php echo t('Retry this step'); ?>" /></form
>
348 <?php
echo '</p></div>';
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>';
360 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
patrick-canterino.de