]>
git.p6c8.net - jirafeau_project.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');
29 function jirafeau_export_cfg($cfg)
31 $content = '<?php' . NL
;
32 $content .= '/* This file was generated by the install process. ' .
33 'You can edit it. Please see config.original.php to understand the ' .
34 'configuration items. */' . NL
;
35 $content .= '$cfg = ' . var_export($cfg, true) . ';';
37 $fileWrite = file_put_contents(JIRAFEAU_CFG
, $content);
39 if (false === $fileWrite) {
40 jirafeau_fatal_error(t('Can not write local configuration file'));
44 function jirafeau_mkdir($path)
46 return !(!file_exists($path) && !@mkdir
($path, 0755));
50 * Returns true whether the path is writable or we manage to make it
51 * so, which essentially is the same thing.
52 * @param $path is the file or directory to be tested.
53 * @return true if $path is writable.
55 function jirafeau_is_writable($path)
57 /* "@" gets rid of error messages. */
58 return is_writable($path) || @chmod
($path, 0777);
61 function jirafeau_check_var_dir($path)
63 $mkdir_str1 = t('CANNOT_CREATE_DIR') . ':';
64 $mkdir_str2 = t('MANUAL_CREATE');
65 $write_str1 = t('DIR_NOT_W') . ':';
66 $write_str2 = t('You should give the write permission to the web server on ' .
68 $solution_str = t('HERE_SOLUTION') . ':';
70 if (!jirafeau_mkdir($path) ||
!jirafeau_is_writable($path)) {
71 return array('has_error' => true,
72 'why' => $mkdir_str1 . '<br /><code>' .
73 $path . '</code><br />' . $solution_str .
74 '<br />' . $mkdir_str2);
77 foreach (array('files', 'links', 'async') as $subdir) {
78 $subpath = $path.$subdir;
80 if (!jirafeau_mkdir($subpath) ||
!jirafeau_is_writable($subpath)) {
81 return array('has_error' => true,
82 'why' => $mkdir_str1 . '<br /><code>' .
83 $subpath . '</code><br />' . $solution_str .
84 '<br />' . $mkdir_str2);
88 return array('has_error' => false, 'why' => '');
91 function jirafeau_add_ending_slash($path)
93 return $path . ((substr($path, -1) == '/') ?
'' : '/');
100 // Is the installation process done already?
101 // Then there is nothing to do here → redirect to the main page.
102 if ($cfg['installation_done'] === true) {
103 header('Location: index.php');
108 * Prepare installation process
111 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
113 // does the local configuration file exist?
114 if (!file_exists(JIRAFEAU_CFG
)) {
115 // show an error if it is not possible to create the file
116 if (!@touch
(JIRAFEAU_CFG
)) {
117 jirafeau_fatal_error(
118 t('The local configuration file could not be created. Create a ' .
119 '<code>lib/config.local.php</code> file and give the write ' .
120 'permission to the web server (preferred solution), or give the ' .
121 'write permission to the web server on the <code>lib</code> ' .
127 // is the local configuration writable?
128 if (!is_writable(JIRAFEAU_CFG
) && !@chmod
(JIRAFEAU_CFG
, '0666')) {
129 jirafeau_fatal_error(
130 t('The local configuration is not writable by the web server. ' .
131 'Give the write permission to the web server on the ' .
132 '<code>lib/config.local.php</code> file.')
137 * Run trough each installation step
140 if (isset($_POST['step']) && isset($_POST['next'])) {
141 switch ($_POST['step']) {
143 if (strlen($_POST['admin_password'])) {
144 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
146 $cfg['admin_password'] = '';
148 jirafeau_export_cfg($cfg);
152 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
153 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
154 jirafeau_export_cfg($cfg);
158 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
159 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
160 jirafeau_export_cfg($cfg);
166 if (isset($_POST['next'])) {
167 $current = $_POST['step'] +
1;
168 } elseif (isset($_POST['previous'])) {
169 $current = $_POST['step'] - 1;
170 } elseif (isset($_POST['retry'])) {
171 $current = $_POST['step'];
177 ?
><h2
><?php
printf(t('JI_INSTALL') . ' - ' . t('STEP') .
178 ' %d ' . t('OUT_OF') . ' %d', 1, 3);
179 ?
></h2
> <div id
= "install"> <form method
="post"> <input type
=
180 "hidden" name
= "jirafeau" value
=
181 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
182 "step" value
= "1" /><fieldset
> <legend
><?php
184 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
185 "2"><?php
echo t('ADMIN_INTERFACE_INFO');
186 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_password"
187 ><?php
echo t('ADMIN_PSW') . ':';
189 <td
class = "field"><input type
= "password" name
= "admin_password"
190 id
= "admin_password" size
= "40" /></td
>
194 <td
class = "nav next">
195 <input type
= "submit"
196 class = "navleft" name
= "previous" value
= "<?php
197 echo t('PREV_STEP'); ?>" />
198 <input type
= "submit" name
= "next" value
=
199 "<?php echo t('NEXT_STEP'); ?>" /></td
> </tr
> </table
>
200 </fieldset
> </form
> </div
> <?php
204 ?
><h2
><?php
printf(t('JI_INSTALL') . ' - ' . t('STEP') .
205 ' %d ' . t('OUT_OF') . ' %d', 2, 3);
206 ?
></h2
> <div id
= "install"> <form method
="post"> <input type
=
207 "hidden" name
= "jirafeau" value
=
208 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
210 "2" /><fieldset
> <legend
><?php
echo t('INFO');
211 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
212 "2"><?php
echo t('BASE_ADDR_INFO');
213 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_web_root"
214 ><?php
echo t('BASE_ADDR') . ':';
216 <td
class = "field"><input type
= "text" name
= "web_root"
217 id
= "input_web_root" value
= "<?php
218 echo(empty($cfg['web_root']) ?
219 $_SERVER['HTTP_HOST'] . str_replace(
222 $_SERVER['REQUEST_URI']
223 ) : $cfg['web_root']);
224 ?>" size
= "40" /></td
>
225 </tr
> <tr
> <td
class = "info" colspan
= "2"><?php
226 echo t('DATA_DIR_EXPLAINATION');
227 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_var_root"
228 ><?php
echo t('DATA_DIR') . ':';
230 <td
class = "field"><input type
= "text" name
= "var_root"
231 id
= "input_var_root" value
= "<?php
232 if (empty($cfg['var_root'])) {
233 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
234 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
235 $len_alphanum = strlen($alphanum);
237 for ($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
238 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
240 echo JIRAFEAU_ROOT . $var . '/';
242 echo $cfg['var_root'];
244 ?>" size
= "40" /></td
>
245 </tr
> <tr
> <td colspan
= "2"><input type
= "submit"
246 class = "navleft" name
= "previous" value
= "<?php
247 echo t('PREV_STEP'); ?>" />
248 <input type
= "submit" class = "navright" name
= "next" value
=
249 "<?php echo t('NEXT_STEP'); ?>" />
250 </td
> </tr
> </table
> </fieldset
>
255 ?
><h2
><?php
printf(t('JI_INSTALL') . ' - ' . t('STEP') .
256 ' %d ' . t('OUT_OF') . ' %d', 3, 3);
257 ?
></h2
> <div id
= "install"> <form method
="post"> <input type
=
258 "hidden" name
= "jirafeau" value
=
259 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
261 "3" /><fieldset
> <legend
><?php
echo t('FINALIZATION');
262 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
263 "2"><?php
echo t('SETTING_UP');
264 ?
></td
> </tr
> <tr
> <td
class = "nav previous"><input type
=
265 "submit" name
= "previous" value
= " <?php echo t('PREV_STEP');
266 ?>" /></td
> <td
></td
> </tr
>
267 </table
> </fieldset
> </form
> </div
>
269 $err = jirafeau_check_var_dir($cfg['var_root']);
270 if ($err['has_error']) {
271 echo '<div class="error"><p>'.$err['why'].'<br />'.NL
; ?
><form method
="post"> <input type
= "hidden" name
= "jirafeau" value
=
272 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
273 "step" value
= "3" /><input type
= "submit" name
=
275 "<?php echo t('RETRY_STEP'); ?>" /></form
>
276 <?php
echo '</p></div>';
278 $cfg['installation_done'] = true;
279 jirafeau_export_cfg($cfg);
280 echo '<div class="message"><p>' .
281 t('JI_FONCTIONAL') . ':' .
282 '<br /><a href="./">' .
283 $cfg['web_root'].'</a></p></div>';
288 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
patrick-canterino.de