]>
git.p6c8.net - jirafeau_mojo42.git/blob - install.php
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);
56 fwrite ($handle, 'null');
57 fwrite ($handle, ';'.NL
);
59 /* No newline at the end of the file to be able to send headers. */
60 fwrite ($handle, '?>');
65 jirafeau_mkdir ($path)
67 if (!file_exists ($path) && !@mkdir
($path, 0755))
73 * Returns true whether the path is writable or we manage to make it
74 * so, which essentially is the same thing.
75 * @param $path is the file or directory to be tested.
76 * @return true if $path is writable.
79 jirafeau_is_writable ($path)
81 /* "@" gets rid of error messages. */
82 return is_writable ($path) || @chmod
($path, 0777);
86 jirafeau_check_var_dir ($path)
88 $mkdir_str1 = t('The following directory could not be created') . ':';
89 $mkdir_str2 = t('You should create this directory by hand.');
90 $write_str1 = t('The following directory is not writable') . ':';
91 $write_str2 = t('You should give the write right to the web server on ' .
93 $solution_str = t('Here is a solution') . ':';
95 if (!jirafeau_mkdir ($path) ||
!jirafeau_is_writable ($path))
96 return array ('has_error' => true,
97 'why' => $mkdir_str1 . '<br /><code>' .
98 $path . '</code><br />' . $solution_str .
99 '<br />' . $mkdir_str2);
101 foreach (array ('files', 'links', 'async', 'block') as $subdir)
103 $subpath = $path.$subdir;
105 if (!jirafeau_mkdir ($subpath) ||
!jirafeau_is_writable ($subpath))
106 return array ('has_error' => true,
107 'why' => $mkdir_str1 . '<br /><code>' .
108 $subpath . '</code><br />' . $solution_str .
109 '<br />' . $mkdir_str2);
112 return array ('has_error' => false, 'why' => '');
116 jirafeau_add_ending_slash ($path)
118 return $path . ((substr ($path, -1) == '/') ?
'' : '/');
121 if ($cfg['installation_done'] === true)
123 header('Location: index.php');
127 if (!file_exists (JIRAFEAU_CFG
))
129 /* We try to create an empty one. */
130 if (!@touch
(JIRAFEAU_CFG
))
132 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
133 echo '<div class="error"><p>' .
134 t('The local configuration file could not be created. Create a ' .
135 '<code>lib/config.local.php</code> file and give the write ' .
136 'right to the web server (preferred solution), or give the ' .
137 'write right to the web server on the <code>lib</code> ' .
140 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
145 if (!is_writable (JIRAFEAU_CFG
) && !@chmod
(JIRAFEAU_CFG
, '0666'))
147 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
148 echo '<div class="error"><p>' .
149 t('The local configuration is not writable by the web server. ' .
150 'Give the write right to the web server on the ' .
151 '<code>lib/config.local.php</code> file.') .
153 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
157 if (isset ($_POST['step']) && isset ($_POST['next']))
159 switch ($_POST['step'])
162 $cfg['lang'] = $_POST['lang'];
163 jirafeau_export_cfg ($cfg);
167 $cfg['admin_password'] = $_POST['admin_password'];
168 jirafeau_export_cfg ($cfg);
172 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
173 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
174 $cfg['installation_done'] = true;
175 jirafeau_export_cfg ($cfg);
179 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
180 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
181 jirafeau_export_cfg ($cfg);
189 require (JIRAFEAU_ROOT
. 'lib/settings.php');
190 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
193 if (isset ($_POST['next']))
194 $current = $_POST['step'] +
1;
195 else if (isset ($_POST['previous']))
196 $current = $_POST['step'] - 1;
197 else if (isset ($_POST['retry']))
198 $current = $_POST['step'];
204 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
205 ' %d ' . t('out of') . ' %d', 1, 4);
206 ?
></h2
> <div id
= "install"> <form action
=
207 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
208 "hidden" name
= "jirafeau" value
=
209 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
210 "step" value
= "1" /><fieldset
> <legend
><?php
echo t('Language');
211 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
214 ('Jirafeau is internationalised. Choose a specific langage or ' .
215 'choose Automatic (langage is provided by user\'s browser).');
216 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_lang"
217 ><?php
echo t('Choose the default language') . ':';
220 <select name
= "lang" id
= "select_lang">
221 <?php
foreach ($languages_list as $key => $item)
223 echo '<option value="'.$key.'"'.($key ==
224 $cfg['lang'] ?
' selected="selected"'
225 : '').'>'.$item.'</option>'.NL
;
232 <td
class = "nav next"><input type
= "submit" name
= "next" value
=
233 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
234 </fieldset
> </form
> </div
> <?php
238 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
239 ' %d ' . t('out of') . ' %d', 2, 4);
240 ?
></h2
> <div id
= "install"> <form action
=
241 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
242 "hidden" name
= "jirafeau" value
=
243 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
244 "step" value
= "2" /><fieldset
> <legend
><?php
245 echo t('Administration password');
246 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
249 ('Jirafeau has an administration interface (through admin.php). ' .
250 'You can set a password to access the intercace or let it be empty ' .
251 'to disable the interface.');
252 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_password"
253 ><?php
echo t('Administration password') . ':';
255 <td
class = "field"><input type
= "password" name
= "admin_password"
256 id
= "admin_password" size
= "40" /></td
>
260 <td
class = "nav next">
261 <input type
= "submit"
262 class = "navleft" name
= "previous" value
= "<?php
263 echo t('Previous step'); ?>" />
264 <input type
= "submit" name
= "next" value
=
265 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
266 </fieldset
> </form
> </div
> <?php
270 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
271 ' %d ' . t('out of') . ' %d', 3, 4);
272 ?
></h2
> <div id
= "install"> <form action
=
273 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
274 "hidden" name
= "jirafeau" value
=
275 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
277 "3" /><fieldset
> <legend
><?php
echo t('Information');
278 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
281 ('The base address of Jirafeau is the first part of the URL, until ' .
282 '(and including) the last slash. For example: ' .
283 '"http://www.example.com/". Do not forget the ending slash!');
284 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_web_root"
285 ><?php
echo t('Base address') . ':';
287 <td
class = "field"><input type
= "text" name
= "web_root"
288 id
= "input_web_root" value
= "<?php
289 echo (empty($cfg['web_root']) ?
290 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
291 '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
292 ?>" size
= "40" /></td
>
293 </tr
> <tr
> <td
class = "info" colspan
= "2"><?php
294 echo t('The data directory is where your files and information about' .
295 ' your files will be stored. You should put it outside your web ' .
296 'site, or at least restrict the access of this directory. Do not ' .
297 'forget the ending slash!');
298 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_var_root"
299 ><?php
echo t('Data directory') . ':';
301 <td
class = "field"><input type
= "text" name
= "var_root"
302 id
= "input_var_root" value
= "<?php
303 if(empty($cfg['var_root'])) {
304 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
305 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
306 $len_alphanum = strlen($alphanum);
308 for($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
309 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
311 echo JIRAFEAU_ROOT . $var . '/';
314 echo $cfg['var_root'];
315 ?>" size
= "40" /></td
>
316 </tr
> <tr
> <td colspan
= "2"><input type
= "submit"
317 class = "navleft" name
= "previous" value
= "<?php
318 echo t('Previous step'); ?>" />
319 <input type
= "submit" class = "navright" name
= "next" value
= "
320 <?php echo t('Next step'); ?>" />
321 </td
> </tr
> </table
> </fieldset
>
326 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
327 ' %d ' . t('out of') . ' %d', 4, 4);
328 ?
></h2
> <div id
= "install"> <form action
=
329 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
330 "hidden" name
= "jirafeau" value
=
331 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
333 "4" /><fieldset
> <legend
><?php
echo t('Finalisation');
334 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
336 t ('Jirafeau is setting the website according to the configuration ' .
338 ?
></td
> </tr
> <tr
> <td
class = "nav previous"><input type
=
339 "submit" name
= "previous" value
=
342 echo t('Previous step');
343 ?>" /></td
> <td
></td
> </tr
>
344 </table
> </fieldset
> </form
> </div
>
346 $err = jirafeau_check_var_dir ($cfg['var_root']);
347 if ($err['has_error'])
349 echo '<div class="error"><p>'.$err['why'].'<br />'.NL
;
350 ?
><form action
= "<?php echo basename(__FILE__); ?>" method
=
351 "post"> <input type
= "hidden" name
= "jirafeau" value
=
352 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
353 "step" value
= "4" /><input type
= "submit" name
=
355 "<?php echo t('Retry this step'); ?>" /></form
>
356 <?php
echo '</p></div>';
360 echo '<div class="message"><p>' .
361 t('Jirafeau is now fully operational') . ':' .
362 '<br /><a href="' . $cfg['web_root'] . '">' .
363 $cfg['web_root'].'</a></p></div>';
368 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
patrick-canterino.de