]>
git.p6c8.net - jirafeau_project.git/blob - install.php
2d7afd986d008fdf268b17b5c8b35ef7244026c5
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 ('JIRAFEAU_CFG', JIRAFEAU_ROOT
. 'lib/config.local.php');
23 define ('JIRAFEAU_VAR_RAND_LENGTH', 15);
25 require (JIRAFEAU_ROOT
. 'lib/settings.php');
26 require (JIRAFEAU_ROOT
. 'lib/functions.php');
27 require (JIRAFEAU_ROOT
. 'lib/lang.php');
30 * Prepend used functions
34 jirafeau_quoted ($str)
36 return QUOTE
. str_replace (QUOTE
, "\'", $str) . QUOTE
;
40 jirafeau_export_cfg ($cfg)
42 $content = '<?php' . NL
;
43 $content .= '/* ' . 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 $content .= '$cfg = ' . var_export($cfg, true) . ';';
48 $fileWrite = file_put_contents(JIRAFEAU_CFG
, $content);
50 if (false === $fileWrite) {
51 jirafeau_fatal_error(t('Can not write local configuration file'));
56 jirafeau_mkdir ($path)
58 return !(!file_exists ($path) && !@mkdir
($path, 0755));
62 * Returns true whether the path is writable or we manage to make it
63 * so, which essentially is the same thing.
64 * @param $path is the file or directory to be tested.
65 * @return true if $path is writable.
68 jirafeau_is_writable ($path)
70 /* "@" gets rid of error messages. */
71 return is_writable ($path) || @chmod
($path, 0777);
75 jirafeau_check_var_dir ($path)
77 $mkdir_str1 = t('The following directory could not be created') . ':';
78 $mkdir_str2 = t('You should create this directory manually.');
79 $write_str1 = t('The following directory is not writable') . ':';
80 $write_str2 = t('You should give the write permission to the web server on ' .
82 $solution_str = t('Here is a solution') . ':';
84 if (!jirafeau_mkdir ($path) ||
!jirafeau_is_writable ($path))
85 return array ('has_error' => true,
86 'why' => $mkdir_str1 . '<br /><code>' .
87 $path . '</code><br />' . $solution_str .
88 '<br />' . $mkdir_str2);
90 foreach (array ('files', 'links', 'async', 'alias') as $subdir)
92 $subpath = $path.$subdir;
94 if (!jirafeau_mkdir ($subpath) ||
!jirafeau_is_writable ($subpath))
95 return array ('has_error' => true,
96 'why' => $mkdir_str1 . '<br /><code>' .
97 $subpath . '</code><br />' . $solution_str .
98 '<br />' . $mkdir_str2);
101 return array ('has_error' => false, 'why' => '');
105 jirafeau_add_ending_slash ($path)
107 return $path . ((substr ($path, -1) == '/') ?
'' : '/');
111 jirafeau_fatal_error($errorText)
113 echo '<div class="error"><h2>Error</h2><p>' . $errorText . '</p></div>';
114 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
122 // Is the installation process done already?
123 // Then there is nothing to do here → redirect to the main page.
124 if ($cfg['installation_done'] === true)
126 header('Location: index.php');
131 * Prepare installation process
134 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
136 // does the local configuration file exist?
137 if (!file_exists (JIRAFEAU_CFG
))
139 // show an error if it is not possible to create the file
140 if (!@touch
(JIRAFEAU_CFG
))
142 jirafeau_fatal_error(
143 t('The local configuration file could not be created. Create a ' .
144 '<code>lib/config.local.php</code> file and give the write ' .
145 'permission to the web server (preferred solution), or give the ' .
146 'write permission to the web server on the <code>lib</code> ' .
152 // is the local configuration writable?
153 if (!is_writable (JIRAFEAU_CFG
) && !@chmod
(JIRAFEAU_CFG
, '0666'))
155 jirafeau_fatal_error(
156 t('The local configuration is not writable by the web server. ' .
157 'Give the write permission to the web server on the ' .
158 '<code>lib/config.local.php</code> file.')
163 * Run trough each installation step
166 if (isset ($_POST['step']) && isset ($_POST['next']))
168 switch ($_POST['step'])
171 $cfg['lang'] = $_POST['lang'];
172 jirafeau_export_cfg ($cfg);
176 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
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);
187 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
188 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
189 jirafeau_export_cfg ($cfg);
196 if (isset ($_POST['next']))
197 $current = $_POST['step'] +
1;
198 else if (isset ($_POST['previous']))
199 $current = $_POST['step'] - 1;
200 else if (isset ($_POST['retry']))
201 $current = $_POST['step'];
207 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
208 ' %d ' . t('out of') . ' %d', 1, 4);
209 ?
></h2
> <div id
= "install"> <form action
=
210 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
211 "hidden" name
= "jirafeau" value
=
212 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
213 "step" value
= "1" /><fieldset
> <legend
><?php
echo t('Language');
214 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
217 ('Jirafeau is internationalised. Choose a specific langage or ' .
218 'choose Automatic (langage is provided by user\'s browser).');
219 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_lang"
220 ><?php
echo t('Choose the default language') . ':';
223 <select name
= "lang" id
= "select_lang">
224 <?php
foreach ($languages_list as $key => $item)
226 echo '<option value="'.$key.'"'.($key ==
227 $cfg['lang'] ?
' selected="selected"'
228 : '').'>'.$item.'</option>'.NL
;
235 <td
class = "nav next"><input type
= "submit" name
= "next" value
=
236 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
237 </fieldset
> </form
> </div
> <?php
241 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
242 ' %d ' . t('out of') . ' %d', 2, 4);
243 ?
></h2
> <div id
= "install"> <form action
=
244 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
245 "hidden" name
= "jirafeau" value
=
246 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
247 "step" value
= "2" /><fieldset
> <legend
><?php
248 echo t('Administration password');
249 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
252 ('Jirafeau has an administration interface (through admin.php). ' .
253 'You can set a password to access the interface or leave it empty ' .
254 'to disable the interface.');
255 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_password"
256 ><?php
echo t('Administration password') . ':';
258 <td
class = "field"><input type
= "password" name
= "admin_password"
259 id
= "admin_password" size
= "40" /></td
>
263 <td
class = "nav next">
264 <input type
= "submit"
265 class = "navleft" name
= "previous" value
= "<?php
266 echo t('Previous step'); ?>" />
267 <input type
= "submit" name
= "next" value
=
268 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
269 </fieldset
> </form
> </div
> <?php
273 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
274 ' %d ' . t('out of') . ' %d', 3, 4);
275 ?
></h2
> <div id
= "install"> <form action
=
276 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
277 "hidden" name
= "jirafeau" value
=
278 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
280 "3" /><fieldset
> <legend
><?php
echo t('Information');
281 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
284 ('The base address of Jirafeau is the first part of the URL, until ' .
285 '(and including) the last slash. For example: ' .
286 '"http://www.example.com/". Do not forget the trailing slash!');
287 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_web_root"
288 ><?php
echo t('Base address') . ':';
290 <td
class = "field"><input type
= "text" name
= "web_root"
291 id
= "input_web_root" value
= "<?php
292 echo (empty($cfg['web_root']) ?
293 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
294 '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
295 ?>" size
= "40" /></td
>
296 </tr
> <tr
> <td
class = "info" colspan
= "2"><?php
297 echo t('The data directory is where your files and information about' .
298 ' your files will be stored. You should put it outside your web ' .
299 'site, or at least restrict the access to this directory. Do not ' .
300 'forget the trailing slash!');
301 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_var_root"
302 ><?php
echo t('Data directory') . ':';
304 <td
class = "field"><input type
= "text" name
= "var_root"
305 id
= "input_var_root" value
= "<?php
306 if(empty($cfg['var_root'])) {
307 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
308 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
309 $len_alphanum = strlen($alphanum);
311 for($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
312 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
314 echo JIRAFEAU_ROOT . $var . '/';
317 echo $cfg['var_root'];
318 ?>" size
= "40" /></td
>
319 </tr
> <tr
> <td colspan
= "2"><input type
= "submit"
320 class = "navleft" name
= "previous" value
= "<?php
321 echo t('Previous step'); ?>" />
322 <input type
= "submit" class = "navright" name
= "next" value
= "
323 <?php echo t('Next step'); ?>" />
324 </td
> </tr
> </table
> </fieldset
>
329 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
330 ' %d ' . t('out of') . ' %d', 4, 4);
331 ?
></h2
> <div id
= "install"> <form action
=
332 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
333 "hidden" name
= "jirafeau" value
=
334 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
336 "4" /><fieldset
> <legend
><?php
echo t('Finalisation');
337 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
339 t ('Jirafeau is setting the website according to the configuration ' .
341 ?
></td
> </tr
> <tr
> <td
class = "nav previous"><input type
=
342 "submit" name
= "previous" value
=
345 echo t('Previous step');
346 ?>" /></td
> <td
></td
> </tr
>
347 </table
> </fieldset
> </form
> </div
>
349 $err = jirafeau_check_var_dir ($cfg['var_root']);
350 if ($err['has_error'])
352 echo '<div class="error"><p>'.$err['why'].'<br />'.NL
;
353 ?
><form action
= "<?php echo basename(__FILE__); ?>" method
=
354 "post"> <input type
= "hidden" name
= "jirafeau" value
=
355 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
356 "step" value
= "4" /><input type
= "submit" name
=
358 "<?php echo t('Retry this step'); ?>" /></form
>
359 <?php
echo '</p></div>';
363 $cfg['installation_done'] = true;
364 jirafeau_export_cfg ($cfg);
365 echo '<div class="message"><p>' .
366 t('Jirafeau is now fully operational') . ':' .
367 '<br /><a href="' . $cfg['web_root'] . '">' .
368 $cfg['web_root'].'</a></p></div>';
373 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
patrick-canterino.de