]>
git.p6c8.net - jirafeau_project.git/blob - install.php
df4f106490992fa72623da13a484f7399e40b9c0
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 $content = '<?php' . NL
;
44 $content .= '/* ' . t ('This file was generated by the install process. ' .
45 'You can edit it. Please see config.original.php to understand the ' .
46 'configuration items.') . ' */' . NL
;
47 $content .= '$cfg = ' . var_export($cfg, true) . ';';
49 $fileWrite = file_put_contents(JIRAFEAU_CFG
, $content);
51 if (false === $fileWrite) {
52 jirafeau_fatal_error(t('Can not write local configuration file'));
57 jirafeau_mkdir ($path)
59 return !(!file_exists ($path) && !@mkdir
($path, 0755));
63 * Returns true whether the path is writable or we manage to make it
64 * so, which essentially is the same thing.
65 * @param $path is the file or directory to be tested.
66 * @return true if $path is writable.
69 jirafeau_is_writable ($path)
71 /* "@" gets rid of error messages. */
72 return is_writable ($path) || @chmod
($path, 0777);
76 jirafeau_check_var_dir ($path)
78 $mkdir_str1 = t('The following directory could not be created') . ':';
79 $mkdir_str2 = t('You should create this directory manually.');
80 $write_str1 = t('The following directory is not writable') . ':';
81 $write_str2 = t('You should give the write permission to the web server on ' .
83 $solution_str = t('Here is a solution') . ':';
85 if (!jirafeau_mkdir ($path) ||
!jirafeau_is_writable ($path))
86 return array ('has_error' => true,
87 'why' => $mkdir_str1 . '<br /><code>' .
88 $path . '</code><br />' . $solution_str .
89 '<br />' . $mkdir_str2);
91 foreach (array ('files', 'links', 'async', 'alias') as $subdir)
93 $subpath = $path.$subdir;
95 if (!jirafeau_mkdir ($subpath) ||
!jirafeau_is_writable ($subpath))
96 return array ('has_error' => true,
97 'why' => $mkdir_str1 . '<br /><code>' .
98 $subpath . '</code><br />' . $solution_str .
99 '<br />' . $mkdir_str2);
102 return array ('has_error' => false, 'why' => '');
106 jirafeau_add_ending_slash ($path)
108 return $path . ((substr ($path, -1) == '/') ?
'' : '/');
112 jirafeau_fatal_error($errorText)
114 echo '<div class="error"><h2>Error</h2><p>' . $errorText . '</p></div>';
115 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
123 // Is the installation process done already?
124 // Then there is nothing to do here → redirect to the main page.
125 if ($cfg['installation_done'] === true)
127 header('Location: index.php');
132 * Prepare installation process
135 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
137 // does the local configuration file exist?
138 if (!file_exists (JIRAFEAU_CFG
))
140 // show an error if it is not possible to create the file
141 if (!@touch
(JIRAFEAU_CFG
))
143 jirafeau_fatal_error(
144 t('The local configuration file could not be created. Create a ' .
145 '<code>lib/config.local.php</code> file and give the write ' .
146 'permission to the web server (preferred solution), or give the ' .
147 'write permission to the web server on the <code>lib</code> ' .
153 // is the local configuration writable?
154 if (!is_writable (JIRAFEAU_CFG
) && !@chmod
(JIRAFEAU_CFG
, '0666'))
156 jirafeau_fatal_error(
157 t('The local configuration is not writable by the web server. ' .
158 'Give the write permission to the web server on the ' .
159 '<code>lib/config.local.php</code> file.')
164 * Run trough each installation step
167 if (isset ($_POST['step']) && isset ($_POST['next']))
169 switch ($_POST['step'])
172 $cfg['lang'] = $_POST['lang'];
173 jirafeau_export_cfg ($cfg);
177 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
178 jirafeau_export_cfg ($cfg);
182 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
183 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
184 jirafeau_export_cfg ($cfg);
188 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
189 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
190 jirafeau_export_cfg ($cfg);
197 if (isset ($_POST['next']))
198 $current = $_POST['step'] +
1;
199 else if (isset ($_POST['previous']))
200 $current = $_POST['step'] - 1;
201 else if (isset ($_POST['retry']))
202 $current = $_POST['step'];
208 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
209 ' %d ' . t('out of') . ' %d', 1, 4);
210 ?
></h2
> <div id
= "install"> <form action
=
211 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
212 "hidden" name
= "jirafeau" value
=
213 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
214 "step" value
= "1" /><fieldset
> <legend
><?php
echo t('Language');
215 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
218 ('Jirafeau is internationalised. Choose a specific langage or ' .
219 'choose Automatic (langage is provided by user\'s browser).');
220 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_lang"
221 ><?php
echo t('Choose the default language') . ':';
224 <select name
= "lang" id
= "select_lang">
225 <?php
foreach ($languages_list as $key => $item)
227 echo '<option value="'.$key.'"'.($key ==
228 $cfg['lang'] ?
' selected="selected"'
229 : '').'>'.$item.'</option>'.NL
;
236 <td
class = "nav next"><input type
= "submit" name
= "next" value
=
237 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
238 </fieldset
> </form
> </div
> <?php
242 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
243 ' %d ' . t('out of') . ' %d', 2, 4);
244 ?
></h2
> <div id
= "install"> <form action
=
245 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
246 "hidden" name
= "jirafeau" value
=
247 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
248 "step" value
= "2" /><fieldset
> <legend
><?php
249 echo t('Administration password');
250 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
253 ('Jirafeau has an administration interface (through admin.php). ' .
254 'You can set a password to access the interface or leave it empty ' .
255 'to disable the interface.');
256 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_password"
257 ><?php
echo t('Administration password') . ':';
259 <td
class = "field"><input type
= "password" name
= "admin_password"
260 id
= "admin_password" size
= "40" /></td
>
264 <td
class = "nav next">
265 <input type
= "submit"
266 class = "navleft" name
= "previous" value
= "<?php
267 echo t('Previous step'); ?>" />
268 <input type
= "submit" name
= "next" value
=
269 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
270 </fieldset
> </form
> </div
> <?php
274 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
275 ' %d ' . t('out of') . ' %d', 3, 4);
276 ?
></h2
> <div id
= "install"> <form action
=
277 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
278 "hidden" name
= "jirafeau" value
=
279 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
281 "3" /><fieldset
> <legend
><?php
echo t('Information');
282 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
285 ('The base address of Jirafeau is the first part of the URL, until ' .
286 '(and including) the last slash. For example: ' .
287 '"http://www.example.com/". Do not forget the trailing slash!');
288 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_web_root"
289 ><?php
echo t('Base address') . ':';
291 <td
class = "field"><input type
= "text" name
= "web_root"
292 id
= "input_web_root" value
= "<?php
293 echo (empty($cfg['web_root']) ?
294 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
295 '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
296 ?>" size
= "40" /></td
>
297 </tr
> <tr
> <td
class = "info" colspan
= "2"><?php
298 echo t('The data directory is where your files and information about' .
299 ' your files will be stored. You should put it outside your web ' .
300 'site, or at least restrict the access to this directory. Do not ' .
301 'forget the trailing slash!');
302 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_var_root"
303 ><?php
echo t('Data directory') . ':';
305 <td
class = "field"><input type
= "text" name
= "var_root"
306 id
= "input_var_root" value
= "<?php
307 if(empty($cfg['var_root'])) {
308 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
309 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
310 $len_alphanum = strlen($alphanum);
312 for($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
313 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
315 echo JIRAFEAU_ROOT . $var . '/';
318 echo $cfg['var_root'];
319 ?>" size
= "40" /></td
>
320 </tr
> <tr
> <td colspan
= "2"><input type
= "submit"
321 class = "navleft" name
= "previous" value
= "<?php
322 echo t('Previous step'); ?>" />
323 <input type
= "submit" class = "navright" name
= "next" value
= "
324 <?php echo t('Next step'); ?>" />
325 </td
> </tr
> </table
> </fieldset
>
330 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
331 ' %d ' . t('out of') . ' %d', 4, 4);
332 ?
></h2
> <div id
= "install"> <form action
=
333 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
334 "hidden" name
= "jirafeau" value
=
335 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
337 "4" /><fieldset
> <legend
><?php
echo t('Finalisation');
338 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
340 t ('Jirafeau is setting the website according to the configuration ' .
342 ?
></td
> </tr
> <tr
> <td
class = "nav previous"><input type
=
343 "submit" name
= "previous" value
=
346 echo t('Previous step');
347 ?>" /></td
> <td
></td
> </tr
>
348 </table
> </fieldset
> </form
> </div
>
350 $err = jirafeau_check_var_dir ($cfg['var_root']);
351 if ($err['has_error'])
353 echo '<div class="error"><p>'.$err['why'].'<br />'.NL
;
354 ?
><form action
= "<?php echo basename(__FILE__); ?>" method
=
355 "post"> <input type
= "hidden" name
= "jirafeau" value
=
356 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
357 "step" value
= "4" /><input type
= "submit" name
=
359 "<?php echo t('Retry this step'); ?>" /></form
>
360 <?php
echo '</p></div>';
364 $cfg['installation_done'] = true;
365 jirafeau_export_cfg ($cfg);
366 echo '<div class="message"><p>' .
367 t('Jirafeau is now fully operational') . ':' .
368 '<br /><a href="' . $cfg['web_root'] . '">' .
369 $cfg['web_root'].'</a></p></div>';
374 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
patrick-canterino.de