]>
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>
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 method
="post"> <input type
=
210 "hidden" name
= "jirafeau" value
=
211 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
212 "step" value
= "1" /><fieldset
> <legend
><?php
echo t('Language');
213 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
216 ('Jirafeau is internationalised. Choose a specific langage or ' .
217 'choose Automatic (langage is provided by user\'s browser).');
218 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_lang"
219 ><?php
echo t('Choose the default language') . ':';
222 <select name
= "lang" id
= "select_lang">
223 <?php
foreach ($languages_list as $key => $item)
225 echo '<option value="'.$key.'"'.($key ==
226 $cfg['lang'] ?
' selected="selected"'
227 : '').'>'.$item.'</option>'.NL
;
234 <td
class = "nav next"><input type
= "submit" name
= "next" value
=
235 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
236 </fieldset
> </form
> </div
> <?php
240 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
241 ' %d ' . t('out of') . ' %d', 2, 4);
242 ?
></h2
> <div id
= "install"> <form method
="post"> <input type
=
243 "hidden" name
= "jirafeau" value
=
244 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
245 "step" value
= "2" /><fieldset
> <legend
><?php
246 echo t('Administration password');
247 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
250 ('Jirafeau has an administration interface (through admin.php). ' .
251 'You can set a password to access the interface or leave it empty ' .
252 'to disable the interface.');
253 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_password"
254 ><?php
echo t('Administration password') . ':';
256 <td
class = "field"><input type
= "password" name
= "admin_password"
257 id
= "admin_password" size
= "40" /></td
>
261 <td
class = "nav next">
262 <input type
= "submit"
263 class = "navleft" name
= "previous" value
= "<?php
264 echo t('Previous step'); ?>" />
265 <input type
= "submit" name
= "next" value
=
266 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
267 </fieldset
> </form
> </div
> <?php
271 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
272 ' %d ' . t('out of') . ' %d', 3, 4);
273 ?
></h2
> <div id
= "install"> <form 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 trailing 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 to this directory. Do not ' .
297 'forget the trailing 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 method
="post"> <input type
=
329 "hidden" name
= "jirafeau" value
=
330 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
332 "4" /><fieldset
> <legend
><?php
echo t('Finalisation');
333 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
335 t ('Jirafeau is setting the website according to the configuration ' .
337 ?
></td
> </tr
> <tr
> <td
class = "nav previous"><input type
=
338 "submit" name
= "previous" value
=
341 echo t('Previous step');
342 ?>" /></td
> <td
></td
> </tr
>
343 </table
> </fieldset
> </form
> </div
>
345 $err = jirafeau_check_var_dir ($cfg['var_root']);
346 if ($err['has_error'])
348 echo '<div class="error"><p>'.$err['why'].'<br />'.NL
;
349 ?
><form method
="post"> <input type
= "hidden" name
= "jirafeau" value
=
350 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
351 "step" value
= "4" /><input type
= "submit" name
=
353 "<?php echo t('Retry this step'); ?>" /></form
>
354 <?php
echo '</p></div>';
358 $cfg['installation_done'] = true;
359 jirafeau_export_cfg ($cfg);
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