]>
git.p6c8.net - jirafeau_mojo42.git/blob - install.php
b96593e67bb4983d470fba8029470fccf0eac521
3 * Jirafeau, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
5 * Copyright (C) 2015 Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 define ('JIRAFEAU_ROOT', dirname (__FILE__
) . '/');
22 define ('QUOTE', "'");
24 define ('JIRAFEAU_CFG', JIRAFEAU_ROOT
.'lib/config.local.php');
25 define ('JIRAFEAU_VAR_RAND_LENGTH', 15);
27 require (JIRAFEAU_ROOT
. 'lib/config.original.php');
28 require (JIRAFEAU_ROOT
. 'lib/settings.php');
29 require (JIRAFEAU_ROOT
. 'lib/functions.php');
30 require (JIRAFEAU_ROOT
. 'lib/lang.php');
33 * Prepend used functions
37 jirafeau_quoted ($str)
39 return QUOTE
. str_replace (QUOTE
, "\'", $str) . QUOTE
;
43 jirafeau_export_cfg ($cfg)
45 $handle = fopen (JIRAFEAU_CFG
, 'w');
46 fwrite ($handle, '<?php' . NL
);
49 t ('This file was generated by the install process. ' .
50 'You can edit it. Please see config.original.php to understand the ' .
51 'configuration items.') . ' */' . NL
);
52 foreach ($cfg as $key => $item)
54 fwrite ($handle, '$cfg[' . jirafeau_quoted ($key) . '] = ');
56 fwrite ($handle, ($item ?
'true' : 'false'));
57 else if (is_string ($item))
58 fwrite ($handle, jirafeau_quoted ($item));
59 else if (is_int ($item))
60 fwrite ($handle, $item);
61 else if (is_array ($item))
62 fwrite ($handle, str_replace(array("\n", "\r"), "",
63 var_export ($item, true)));
65 fwrite ($handle, 'null');
66 fwrite ($handle, ';'.NL
);
68 /* No newline at the end of the file to be able to send headers. */
69 fwrite ($handle, '?>');
74 jirafeau_mkdir ($path)
76 return !(!file_exists ($path) && !@mkdir
($path, 0755));
80 * Returns true whether the path is writable or we manage to make it
81 * so, which essentially is the same thing.
82 * @param $path is the file or directory to be tested.
83 * @return true if $path is writable.
86 jirafeau_is_writable ($path)
88 /* "@" gets rid of error messages. */
89 return is_writable ($path) || @chmod
($path, 0777);
93 jirafeau_check_var_dir ($path)
95 $mkdir_str1 = t('The following directory could not be created') . ':';
96 $mkdir_str2 = t('You should create this directory manually.');
97 $write_str1 = t('The following directory is not writable') . ':';
98 $write_str2 = t('You should give the write permission to the web server on ' .
100 $solution_str = t('Here is a solution') . ':';
102 if (!jirafeau_mkdir ($path) ||
!jirafeau_is_writable ($path))
103 return array ('has_error' => true,
104 'why' => $mkdir_str1 . '<br /><code>' .
105 $path . '</code><br />' . $solution_str .
106 '<br />' . $mkdir_str2);
108 foreach (array ('files', 'links', 'async', 'alias') as $subdir)
110 $subpath = $path.$subdir;
112 if (!jirafeau_mkdir ($subpath) ||
!jirafeau_is_writable ($subpath))
113 return array ('has_error' => true,
114 'why' => $mkdir_str1 . '<br /><code>' .
115 $subpath . '</code><br />' . $solution_str .
116 '<br />' . $mkdir_str2);
119 return array ('has_error' => false, 'why' => '');
123 jirafeau_add_ending_slash ($path)
125 return $path . ((substr ($path, -1) == '/') ?
'' : '/');
129 jirafeau_fatal_error($errorText)
131 echo '<div class="error"><h2>Error</h2><p>' . $errorText . '</p></div>';
132 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
140 // Is the installation process done already?
141 // Then there is nothing to do here → redirect to the main page.
142 if ($cfg['installation_done'] === true)
144 header('Location: index.php');
149 * Prepare installation process
152 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
154 // does the local configuration file exist?
155 if (!file_exists (JIRAFEAU_CFG
))
157 // show an error if it is not possible to create the file
158 if (!@touch
(JIRAFEAU_CFG
))
160 jirafeau_fatal_error(
161 t('The local configuration file could not be created. Create a ' .
162 '<code>lib/config.local.php</code> file and give the write ' .
163 'permission to the web server (preferred solution), or give the ' .
164 'write permission to the web server on the <code>lib</code> ' .
170 // is the local configuration writable?
171 if (!is_writable (JIRAFEAU_CFG
) && !@chmod
(JIRAFEAU_CFG
, '0666'))
173 jirafeau_fatal_error(
174 t('The local configuration is not writable by the web server. ' .
175 'Give the write permission to the web server on the ' .
176 '<code>lib/config.local.php</code> file.')
181 * Run trough each installation step
184 if (isset ($_POST['step']) && isset ($_POST['next']))
186 switch ($_POST['step'])
189 $cfg['lang'] = $_POST['lang'];
190 jirafeau_export_cfg ($cfg);
194 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
195 jirafeau_export_cfg ($cfg);
199 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
200 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
201 jirafeau_export_cfg ($cfg);
205 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
206 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
207 jirafeau_export_cfg ($cfg);
214 if (isset ($_POST['next']))
215 $current = $_POST['step'] +
1;
216 else if (isset ($_POST['previous']))
217 $current = $_POST['step'] - 1;
218 else if (isset ($_POST['retry']))
219 $current = $_POST['step'];
225 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
226 ' %d ' . t('out of') . ' %d', 1, 4);
227 ?
></h2
> <div id
= "install"> <form action
=
228 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
229 "hidden" name
= "jirafeau" value
=
230 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
231 "step" value
= "1" /><fieldset
> <legend
><?php
echo t('Language');
232 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
235 ('Jirafeau is internationalised. Choose a specific langage or ' .
236 'choose Automatic (langage is provided by user\'s browser).');
237 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_lang"
238 ><?php
echo t('Choose the default language') . ':';
241 <select name
= "lang" id
= "select_lang">
242 <?php
foreach ($languages_list as $key => $item)
244 echo '<option value="'.$key.'"'.($key ==
245 $cfg['lang'] ?
' selected="selected"'
246 : '').'>'.$item.'</option>'.NL
;
253 <td
class = "nav next"><input type
= "submit" name
= "next" value
=
254 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
255 </fieldset
> </form
> </div
> <?php
259 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
260 ' %d ' . t('out of') . ' %d', 2, 4);
261 ?
></h2
> <div id
= "install"> <form action
=
262 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
263 "hidden" name
= "jirafeau" value
=
264 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
265 "step" value
= "2" /><fieldset
> <legend
><?php
266 echo t('Administration password');
267 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
270 ('Jirafeau has an administration interface (through admin.php). ' .
271 'You can set a password to access the interface or leave it empty ' .
272 'to disable the interface.');
273 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_password"
274 ><?php
echo t('Administration password') . ':';
276 <td
class = "field"><input type
= "password" name
= "admin_password"
277 id
= "admin_password" size
= "40" /></td
>
281 <td
class = "nav next">
282 <input type
= "submit"
283 class = "navleft" name
= "previous" value
= "<?php
284 echo t('Previous step'); ?>" />
285 <input type
= "submit" name
= "next" value
=
286 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
287 </fieldset
> </form
> </div
> <?php
291 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
292 ' %d ' . t('out of') . ' %d', 3, 4);
293 ?
></h2
> <div id
= "install"> <form action
=
294 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
295 "hidden" name
= "jirafeau" value
=
296 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
298 "3" /><fieldset
> <legend
><?php
echo t('Information');
299 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
302 ('The base address of Jirafeau is the first part of the URL, until ' .
303 '(and including) the last slash. For example: ' .
304 '"http://www.example.com/". Do not forget the trailing slash!');
305 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_web_root"
306 ><?php
echo t('Base address') . ':';
308 <td
class = "field"><input type
= "text" name
= "web_root"
309 id
= "input_web_root" value
= "<?php
310 echo (empty($cfg['web_root']) ?
311 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
312 '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
313 ?>" size
= "40" /></td
>
314 </tr
> <tr
> <td
class = "info" colspan
= "2"><?php
315 echo t('The data directory is where your files and information about' .
316 ' your files will be stored. You should put it outside your web ' .
317 'site, or at least restrict the access to this directory. Do not ' .
318 'forget the trailing slash!');
319 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_var_root"
320 ><?php
echo t('Data directory') . ':';
322 <td
class = "field"><input type
= "text" name
= "var_root"
323 id
= "input_var_root" value
= "<?php
324 if(empty($cfg['var_root'])) {
325 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
326 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
327 $len_alphanum = strlen($alphanum);
329 for($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
330 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
332 echo JIRAFEAU_ROOT . $var . '/';
335 echo $cfg['var_root'];
336 ?>" size
= "40" /></td
>
337 </tr
> <tr
> <td colspan
= "2"><input type
= "submit"
338 class = "navleft" name
= "previous" value
= "<?php
339 echo t('Previous step'); ?>" />
340 <input type
= "submit" class = "navright" name
= "next" value
= "
341 <?php echo t('Next step'); ?>" />
342 </td
> </tr
> </table
> </fieldset
>
347 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
348 ' %d ' . t('out of') . ' %d', 4, 4);
349 ?
></h2
> <div id
= "install"> <form action
=
350 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
351 "hidden" name
= "jirafeau" value
=
352 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
354 "4" /><fieldset
> <legend
><?php
echo t('Finalisation');
355 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
357 t ('Jirafeau is setting the website according to the configuration ' .
359 ?
></td
> </tr
> <tr
> <td
class = "nav previous"><input type
=
360 "submit" name
= "previous" value
=
363 echo t('Previous step');
364 ?>" /></td
> <td
></td
> </tr
>
365 </table
> </fieldset
> </form
> </div
>
367 $err = jirafeau_check_var_dir ($cfg['var_root']);
368 if ($err['has_error'])
370 echo '<div class="error"><p>'.$err['why'].'<br />'.NL
;
371 ?
><form action
= "<?php echo basename(__FILE__); ?>" method
=
372 "post"> <input type
= "hidden" name
= "jirafeau" value
=
373 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
374 "step" value
= "4" /><input type
= "submit" name
=
376 "<?php echo t('Retry this step'); ?>" /></form
>
377 <?php
echo '</p></div>';
381 $cfg['installation_done'] = true;
382 jirafeau_export_cfg ($cfg);
383 echo '<div class="message"><p>' .
384 t('Jirafeau is now fully operational') . ':' .
385 '<br /><a href="' . $cfg['web_root'] . '">' .
386 $cfg['web_root'].'</a></p></div>';
391 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
patrick-canterino.de