]>
git.p6c8.net - jirafeau_mojo42.git/blob - install.php
2739bc8ab7a103202927321a04bed920c40bc1e5
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
33 function jirafeau_quoted($str)
35 return QUOTE
. str_replace(QUOTE
, "\'", $str) . QUOTE
;
38 function jirafeau_export_cfg($cfg)
40 $content = '<?php' . NL
;
41 $content .= '/* ' . t('This file was generated by the install process. ' .
42 'You can edit it. Please see config.original.php to understand the ' .
43 'configuration items.') . ' */' . NL
;
44 $content .= '$cfg = ' . var_export($cfg, true) . ';';
46 $fileWrite = file_put_contents(JIRAFEAU_CFG
, $content);
48 if (false === $fileWrite) {
49 jirafeau_fatal_error(t('Can not write local configuration file'));
53 function jirafeau_mkdir($path)
55 return !(!file_exists($path) && !@mkdir
($path, 0755));
59 * Returns true whether the path is writable or we manage to make it
60 * so, which essentially is the same thing.
61 * @param $path is the file or directory to be tested.
62 * @return true if $path is writable.
64 function jirafeau_is_writable($path)
66 /* "@" gets rid of error messages. */
67 return is_writable($path) || @chmod
($path, 0777);
70 function jirafeau_check_var_dir($path)
72 $mkdir_str1 = t('The following directory could not be created') . ':';
73 $mkdir_str2 = t('You should create this directory manually.');
74 $write_str1 = t('The following directory is not writable') . ':';
75 $write_str2 = t('You should give the write permission to the web server on ' .
77 $solution_str = t('Here is a solution') . ':';
79 if (!jirafeau_mkdir($path) ||
!jirafeau_is_writable($path)) {
80 return array('has_error' => true,
81 'why' => $mkdir_str1 . '<br /><code>' .
82 $path . '</code><br />' . $solution_str .
83 '<br />' . $mkdir_str2);
86 foreach (array('files', 'links', 'async', 'alias') as $subdir) {
87 $subpath = $path.$subdir;
89 if (!jirafeau_mkdir($subpath) ||
!jirafeau_is_writable($subpath)) {
90 return array('has_error' => true,
91 'why' => $mkdir_str1 . '<br /><code>' .
92 $subpath . '</code><br />' . $solution_str .
93 '<br />' . $mkdir_str2);
97 return array('has_error' => false, 'why' => '');
100 function jirafeau_add_ending_slash($path)
102 return $path . ((substr($path, -1) == '/') ?
'' : '/');
109 // Is the installation process done already?
110 // Then there is nothing to do here → redirect to the main page.
111 if ($cfg['installation_done'] === true) {
112 header('Location: index.php');
117 * Prepare installation process
120 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
122 // does the local configuration file exist?
123 if (!file_exists(JIRAFEAU_CFG
)) {
124 // show an error if it is not possible to create the file
125 if (!@touch
(JIRAFEAU_CFG
)) {
126 jirafeau_fatal_error(
127 t('The local configuration file could not be created. Create a ' .
128 '<code>lib/config.local.php</code> file and give the write ' .
129 'permission to the web server (preferred solution), or give the ' .
130 'write permission to the web server on the <code>lib</code> ' .
136 // is the local configuration writable?
137 if (!is_writable(JIRAFEAU_CFG
) && !@chmod
(JIRAFEAU_CFG
, '0666')) {
138 jirafeau_fatal_error(
139 t('The local configuration is not writable by the web server. ' .
140 'Give the write permission to the web server on the ' .
141 '<code>lib/config.local.php</code> file.')
146 * Run trough each installation step
149 if (isset($_POST['step']) && isset($_POST['next'])) {
150 switch ($_POST['step']) {
152 $cfg['lang'] = $_POST['lang'];
153 jirafeau_export_cfg($cfg);
157 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
158 jirafeau_export_cfg($cfg);
162 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
163 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
164 jirafeau_export_cfg($cfg);
168 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
169 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
170 jirafeau_export_cfg($cfg);
176 if (isset($_POST['next'])) {
177 $current = $_POST['step'] +
1;
178 } elseif (isset($_POST['previous'])) {
179 $current = $_POST['step'] - 1;
180 } elseif (isset($_POST['retry'])) {
181 $current = $_POST['step'];
187 ?
><h2
><?php
printf(t('Installation of Jirafeau') . ' - ' . t('step') .
188 ' %d ' . t('out of') . ' %d', 1, 4);
189 ?
></h2
> <div id
= "install"> <form method
="post"> <input type
=
190 "hidden" name
= "jirafeau" value
=
191 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
192 "step" value
= "1" /><fieldset
> <legend
><?php
echo t('Language');
193 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
195 t('Jirafeau is internationalised. Choose a specific langage or ' .
196 'choose Automatic (langage is provided by user\'s browser).');
197 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_lang"
198 ><?php
echo t('Choose the default language') . ':';
201 <select name
= "lang" id
= "select_lang">
202 <?php
foreach ($languages_list as $key => $item) {
203 echo '<option value="'.$key.'"'.($key ==
204 $cfg['lang'] ?
' selected="selected"'
205 : '').'>'.$item.'</option>'.NL
;
212 <td
class = "nav next"><input type
= "submit" name
= "next" value
=
213 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
214 </fieldset
> </form
> </div
> <?php
218 ?
><h2
><?php
printf(t('Installation of Jirafeau') . ' - ' . t('step') .
219 ' %d ' . t('out of') . ' %d', 2, 4);
220 ?
></h2
> <div id
= "install"> <form method
="post"> <input type
=
221 "hidden" name
= "jirafeau" value
=
222 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
223 "step" value
= "2" /><fieldset
> <legend
><?php
224 echo t('Administration password');
225 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
227 t('Jirafeau has an administration interface (through admin.php). ' .
228 'You can set a password to access the interface or leave it empty ' .
229 'to disable the interface.');
230 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_password"
231 ><?php
echo t('Administration password') . ':';
233 <td
class = "field"><input type
= "password" name
= "admin_password"
234 id
= "admin_password" size
= "40" /></td
>
238 <td
class = "nav next">
239 <input type
= "submit"
240 class = "navleft" name
= "previous" value
= "<?php
241 echo t('Previous step'); ?>" />
242 <input type
= "submit" name
= "next" value
=
243 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
244 </fieldset
> </form
> </div
> <?php
248 ?
><h2
><?php
printf(t('Installation of Jirafeau') . ' - ' . t('step') .
249 ' %d ' . t('out of') . ' %d', 3, 4);
250 ?
></h2
> <div id
= "install"> <form method
="post"> <input type
=
251 "hidden" name
= "jirafeau" value
=
252 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
254 "3" /><fieldset
> <legend
><?php
echo t('Information');
255 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
257 t('The base address of Jirafeau is the first part of the URL, until ' .
258 '(and including) the last slash. For example: ' .
259 '"http://www.example.com/". Do not forget the trailing slash!');
260 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_web_root"
261 ><?php
echo t('Base address') . ':';
263 <td
class = "field"><input type
= "text" name
= "web_root"
264 id
= "input_web_root" value
= "<?php
265 echo(empty($cfg['web_root']) ?
266 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
267 '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
268 ?>" size
= "40" /></td
>
269 </tr
> <tr
> <td
class = "info" colspan
= "2"><?php
270 echo t('The data directory is where your files and information about' .
271 ' your files will be stored. You should put it outside your web ' .
272 'site, or at least restrict the access to this directory. Do not ' .
273 'forget the trailing slash!');
274 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_var_root"
275 ><?php
echo t('Data directory') . ':';
277 <td
class = "field"><input type
= "text" name
= "var_root"
278 id
= "input_var_root" value
= "<?php
279 if (empty($cfg['var_root'])) {
280 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
281 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
282 $len_alphanum = strlen($alphanum);
284 for ($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
285 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
287 echo JIRAFEAU_ROOT . $var . '/';
289 echo $cfg['var_root'];
291 ?>" size
= "40" /></td
>
292 </tr
> <tr
> <td colspan
= "2"><input type
= "submit"
293 class = "navleft" name
= "previous" value
= "<?php
294 echo t('Previous step'); ?>" />
295 <input type
= "submit" class = "navright" name
= "next" value
= "
296 <?php echo t('Next step'); ?>" />
297 </td
> </tr
> </table
> </fieldset
>
302 ?
><h2
><?php
printf(t('Installation of Jirafeau') . ' - ' . t('step') .
303 ' %d ' . t('out of') . ' %d', 4, 4);
304 ?
></h2
> <div id
= "install"> <form method
="post"> <input type
=
305 "hidden" name
= "jirafeau" value
=
306 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
308 "4" /><fieldset
> <legend
><?php
echo t('Finalisation');
309 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
311 t('Jirafeau is setting the website according to the configuration ' .
313 ?
></td
> </tr
> <tr
> <td
class = "nav previous"><input type
=
314 "submit" name
= "previous" value
=
317 echo t('Previous step');
318 ?>" /></td
> <td
></td
> </tr
>
319 </table
> </fieldset
> </form
> </div
>
321 $err = jirafeau_check_var_dir($cfg['var_root']);
322 if ($err['has_error']) {
323 echo '<div class="error"><p>'.$err['why'].'<br />'.NL
; ?
><form method
="post"> <input type
= "hidden" name
= "jirafeau" value
=
324 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
325 "step" value
= "4" /><input type
= "submit" name
=
327 "<?php echo t('Retry this step'); ?>" /></form
>
328 <?php
echo '</p></div>';
330 $cfg['installation_done'] = true;
331 jirafeau_export_cfg($cfg);
332 echo '<div class="message"><p>' .
333 t('Jirafeau is now fully operational') . ':' .
334 '<br /><a href="' . $cfg['web_root'] . '">' .
335 $cfg['web_root'].'</a></p></div>';
340 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
patrick-canterino.de