]>
git.p6c8.net - jirafeau.git/blob - install.php
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', "'");
23 define ('JIRAFEAU_CFG', JIRAFEAU_ROOT
.'lib/config.local.php');
24 define ('JIRAFEAU_VAR_RAND_LENGTH', 15);
26 require (JIRAFEAU_ROOT
. 'lib/settings.php');
27 require (JIRAFEAU_ROOT
. 'lib/functions.php');
28 require (JIRAFEAU_ROOT
. 'lib/lang.php');
31 * Prepend used functions
35 jirafeau_quoted ($str)
37 return QUOTE
. str_replace (QUOTE
, "\'", $str) . QUOTE
;
41 jirafeau_export_cfg ($cfg)
43 $handle = fopen (JIRAFEAU_CFG
, 'w');
44 fwrite ($handle, '<?php' . NL
);
47 t ('This file was generated by the install process. ' .
48 'You can edit it. Please see config.original.php to understand the ' .
49 'configuration items.') . ' */' . NL
);
50 foreach ($cfg as $key => $item)
52 fwrite ($handle, '$cfg[' . jirafeau_quoted ($key) . '] = ');
54 fwrite ($handle, ($item ?
'true' : 'false'));
55 else if (is_string ($item))
56 fwrite ($handle, jirafeau_quoted ($item));
57 else if (is_int ($item))
58 fwrite ($handle, $item);
59 else if (is_array ($item))
60 fwrite ($handle, str_replace(array("\n", "\r"), "",
61 var_export ($item, true)));
63 fwrite ($handle, 'null');
64 fwrite ($handle, ';'.NL
);
66 /* No newline at the end of the file to be able to send headers. */
67 fwrite ($handle, '?>');
72 jirafeau_mkdir ($path)
74 return !(!file_exists ($path) && !@mkdir
($path, 0755));
78 * Returns true whether the path is writable or we manage to make it
79 * so, which essentially is the same thing.
80 * @param $path is the file or directory to be tested.
81 * @return true if $path is writable.
84 jirafeau_is_writable ($path)
86 /* "@" gets rid of error messages. */
87 return is_writable ($path) || @chmod
($path, 0777);
91 jirafeau_check_var_dir ($path)
93 $mkdir_str1 = t('The following directory could not be created') . ':';
94 $mkdir_str2 = t('You should create this directory manually.');
95 $write_str1 = t('The following directory is not writable') . ':';
96 $write_str2 = t('You should give the write permission to the web server on ' .
98 $solution_str = t('Here is a solution') . ':';
100 if (!jirafeau_mkdir ($path) ||
!jirafeau_is_writable ($path))
101 return array ('has_error' => true,
102 'why' => $mkdir_str1 . '<br /><code>' .
103 $path . '</code><br />' . $solution_str .
104 '<br />' . $mkdir_str2);
106 foreach (array ('files', 'links', 'async', 'alias') as $subdir)
108 $subpath = $path.$subdir;
110 if (!jirafeau_mkdir ($subpath) ||
!jirafeau_is_writable ($subpath))
111 return array ('has_error' => true,
112 'why' => $mkdir_str1 . '<br /><code>' .
113 $subpath . '</code><br />' . $solution_str .
114 '<br />' . $mkdir_str2);
117 return array ('has_error' => false, 'why' => '');
121 jirafeau_add_ending_slash ($path)
123 return $path . ((substr ($path, -1) == '/') ?
'' : '/');
127 jirafeau_fatal_error($errorText)
129 echo '<div class="error"><h2>Error</h2><p>' . $errorText . '</p></div>';
130 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
138 // Is the installation process done already?
139 // Then there is nothing to do here → redirect to the main page.
140 if ($cfg['installation_done'] === true)
142 header('Location: index.php');
147 * Prepare installation process
150 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
152 // does the local configuration file exist?
153 if (!file_exists (JIRAFEAU_CFG
))
155 // show an error if it is not possible to create the file
156 if (!@touch
(JIRAFEAU_CFG
))
158 jirafeau_fatal_error(
159 t('The local configuration file could not be created. Create a ' .
160 '<code>lib/config.local.php</code> file and give the write ' .
161 'permission to the web server (preferred solution), or give the ' .
162 'write permission to the web server on the <code>lib</code> ' .
168 // is the local configuration writable?
169 if (!is_writable (JIRAFEAU_CFG
) && !@chmod
(JIRAFEAU_CFG
, '0666'))
171 jirafeau_fatal_error(
172 t('The local configuration is not writable by the web server. ' .
173 'Give the write permission to the web server on the ' .
174 '<code>lib/config.local.php</code> file.')
179 * Run trough each installation step
182 if (isset ($_POST['step']) && isset ($_POST['next']))
184 switch ($_POST['step'])
187 $cfg['lang'] = $_POST['lang'];
188 jirafeau_export_cfg ($cfg);
192 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
193 jirafeau_export_cfg ($cfg);
197 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
198 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
199 jirafeau_export_cfg ($cfg);
203 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
204 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
205 jirafeau_export_cfg ($cfg);
212 if (isset ($_POST['next']))
213 $current = $_POST['step'] +
1;
214 else if (isset ($_POST['previous']))
215 $current = $_POST['step'] - 1;
216 else if (isset ($_POST['retry']))
217 $current = $_POST['step'];
223 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
224 ' %d ' . t('out of') . ' %d', 1, 4);
225 ?
></h2
> <div id
= "install"> <form action
=
226 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
227 "hidden" name
= "jirafeau" value
=
228 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
229 "step" value
= "1" /><fieldset
> <legend
><?php
echo t('Language');
230 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
233 ('Jirafeau is internationalised. Choose a specific langage or ' .
234 'choose Automatic (langage is provided by user\'s browser).');
235 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_lang"
236 ><?php
echo t('Choose the default language') . ':';
239 <select name
= "lang" id
= "select_lang">
240 <?php
foreach ($languages_list as $key => $item)
242 echo '<option value="'.$key.'"'.($key ==
243 $cfg['lang'] ?
' selected="selected"'
244 : '').'>'.$item.'</option>'.NL
;
251 <td
class = "nav next"><input type
= "submit" name
= "next" value
=
252 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
253 </fieldset
> </form
> </div
> <?php
257 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
258 ' %d ' . t('out of') . ' %d', 2, 4);
259 ?
></h2
> <div id
= "install"> <form action
=
260 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
261 "hidden" name
= "jirafeau" value
=
262 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
263 "step" value
= "2" /><fieldset
> <legend
><?php
264 echo t('Administration password');
265 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
268 ('Jirafeau has an administration interface (through admin.php). ' .
269 'You can set a password to access the interface or leave it empty ' .
270 'to disable the interface.');
271 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_password"
272 ><?php
echo t('Administration password') . ':';
274 <td
class = "field"><input type
= "password" name
= "admin_password"
275 id
= "admin_password" size
= "40" /></td
>
279 <td
class = "nav next">
280 <input type
= "submit"
281 class = "navleft" name
= "previous" value
= "<?php
282 echo t('Previous step'); ?>" />
283 <input type
= "submit" name
= "next" value
=
284 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
285 </fieldset
> </form
> </div
> <?php
289 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
290 ' %d ' . t('out of') . ' %d', 3, 4);
291 ?
></h2
> <div id
= "install"> <form action
=
292 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
293 "hidden" name
= "jirafeau" value
=
294 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
296 "3" /><fieldset
> <legend
><?php
echo t('Information');
297 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
300 ('The base address of Jirafeau is the first part of the URL, until ' .
301 '(and including) the last slash. For example: ' .
302 '"http://www.example.com/". Do not forget the trailing slash!');
303 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_web_root"
304 ><?php
echo t('Base address') . ':';
306 <td
class = "field"><input type
= "text" name
= "web_root"
307 id
= "input_web_root" value
= "<?php
308 echo (empty($cfg['web_root']) ?
309 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
310 '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
311 ?>" size
= "40" /></td
>
312 </tr
> <tr
> <td
class = "info" colspan
= "2"><?php
313 echo t('The data directory is where your files and information about' .
314 ' your files will be stored. You should put it outside your web ' .
315 'site, or at least restrict the access to this directory. Do not ' .
316 'forget the trailing slash!');
317 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_var_root"
318 ><?php
echo t('Data directory') . ':';
320 <td
class = "field"><input type
= "text" name
= "var_root"
321 id
= "input_var_root" value
= "<?php
322 if(empty($cfg['var_root'])) {
323 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
324 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
325 $len_alphanum = strlen($alphanum);
327 for($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
328 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
330 echo JIRAFEAU_ROOT . $var . '/';
333 echo $cfg['var_root'];
334 ?>" size
= "40" /></td
>
335 </tr
> <tr
> <td colspan
= "2"><input type
= "submit"
336 class = "navleft" name
= "previous" value
= "<?php
337 echo t('Previous step'); ?>" />
338 <input type
= "submit" class = "navright" name
= "next" value
= "
339 <?php echo t('Next step'); ?>" />
340 </td
> </tr
> </table
> </fieldset
>
345 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
346 ' %d ' . t('out of') . ' %d', 4, 4);
347 ?
></h2
> <div id
= "install"> <form action
=
348 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
349 "hidden" name
= "jirafeau" value
=
350 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
352 "4" /><fieldset
> <legend
><?php
echo t('Finalisation');
353 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
355 t ('Jirafeau is setting the website according to the configuration ' .
357 ?
></td
> </tr
> <tr
> <td
class = "nav previous"><input type
=
358 "submit" name
= "previous" value
=
361 echo t('Previous step');
362 ?>" /></td
> <td
></td
> </tr
>
363 </table
> </fieldset
> </form
> </div
>
365 $err = jirafeau_check_var_dir ($cfg['var_root']);
366 if ($err['has_error'])
368 echo '<div class="error"><p>'.$err['why'].'<br />'.NL
;
369 ?
><form action
= "<?php echo basename(__FILE__); ?>" method
=
370 "post"> <input type
= "hidden" name
= "jirafeau" value
=
371 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
372 "step" value
= "4" /><input type
= "submit" name
=
374 "<?php echo t('Retry this step'); ?>" /></form
>
375 <?php
echo '</p></div>';
379 $cfg['installation_done'] = true;
380 jirafeau_export_cfg ($cfg);
381 echo '<div class="message"><p>' .
382 t('Jirafeau is now fully operational') . ':' .
383 '<br /><a href="' . $cfg['web_root'] . '">' .
384 $cfg['web_root'].'</a></p></div>';
389 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
patrick-canterino.de