]>
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>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 define ('JIRAFEAU_ROOT', dirname (__FILE__
) . '/');
21 define ('QUOTE', "'");
23 define ('JIRAFEAU_CFG', JIRAFEAU_ROOT
.'lib/config.local.php');
24 define ('JIRAFEAU_VAR_RAND_LENGTH', 15);
26 require (JIRAFEAU_ROOT
. 'lib/lang.php');
27 require (JIRAFEAU_ROOT
. 'lib/config.php');
30 jirafeau_quoted ($str)
32 return QUOTE
. str_replace (QUOTE
, "\'", $str) . QUOTE
;
36 jirafeau_export_cfg ($cfg)
38 $handle = fopen (JIRAFEAU_CFG
, 'w');
39 fwrite ($handle, '<?php' . NL
);
42 t ('This file was generated by the install process. ' .
43 'You can edit it. Please see config.php to understand the ' .
44 'configuration items.') . ' */' . NL
);
45 foreach ($cfg as $key => $item)
47 fwrite ($handle, '$cfg[' . jirafeau_quoted ($key) . '] = ');
49 fwrite ($handle, ($item ?
'true' : 'false'));
50 else if (is_string ($item))
51 fwrite ($handle, jirafeau_quoted ($item));
53 fwrite ($handle, 'null');
54 fwrite ($handle, ';'.NL
);
56 /* No newline at the end of the file to be able to send headers. */
57 fwrite ($handle, '?>');
62 jirafeau_mkdir ($path)
64 if (!file_exists ($path) && !@mkdir
($path, 0755))
70 * Returns true whether the path is writable or we manage to make it
71 * so, which essentially is the same thing.
72 * @param $path is the file or directory to be tested.
73 * @return true if $path is writable.
76 jirafeau_is_writable ($path)
78 /* "@" gets rid of error messages. */
79 return is_writable ($path) || @chmod
($path, 0777);
83 jirafeau_check_var_dir ($path)
85 $mkdir_str1 = t('The following directory could not be created') . ':';
86 $mkdir_str2 = t('You should create this directory by hand.');
87 $write_str1 = t('The following directory is not writable') . ':';
88 $write_str2 = t('You should give the write right to the web server on ' .
90 $solution_str = t('Here is a solution') . ':';
92 if (!jirafeau_mkdir ($path) ||
!jirafeau_is_writable ($path))
93 return array ('has_error' => true,
94 'why' => $mkdir_str1 . '<br /><code>' .
95 $path . '</code><br />' . $solution_str .
96 '<br />' . $mkdir_str2);
98 foreach (array ('files', 'links') as $subdir)
100 $subpath = $path.$subdir;
102 if (!jirafeau_mkdir ($subpath) ||
!jirafeau_is_writable ($subpath))
103 return array ('has_error' => true,
104 'why' => $mkdir_str1 . '<br /><code>' .
105 $subpath . '</code><br />' . $solution_str .
106 '<br />' . $mkdir_str2);
109 return array ('has_error' => false, 'why' => '');
113 jirafeau_add_ending_slash ($path)
115 return $path . ((substr ($path, -1) == '/') ?
'' : '/');
118 if (!file_exists (JIRAFEAU_CFG
))
120 /* We try to create an empty one. */
121 if (!@touch
(JIRAFEAU_CFG
))
123 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
124 echo '<div class="error"><p>' .
125 t('The local configuration file could not be created. Create a ' .
126 '<code>lib/config.local.php</code> file and give the write ' .
127 'right to the web server (preferred solution), or give the ' .
128 'write right to the web server on the <code>lib</code> ' .
131 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
136 if (!is_writable (JIRAFEAU_CFG
) && !@chmod
(JIRAFEAU_CFG
, '0666'))
138 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
139 echo '<div class="error"><p>' .
140 t('The local configuration is not writable by the web server. ' .
141 'Give the write right to the web server on the ' .
142 '<code>lib/config.local.php</code> file.') .
144 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
148 if (isset ($_POST['step']) && isset ($_POST['next']))
150 switch ($_POST['step'])
153 $cfg['lang'] = $_POST['lang'];
154 jirafeau_export_cfg ($cfg);
158 $cfg['admin_password'] = $_POST['admin_password'];
159 jirafeau_export_cfg ($cfg);
163 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
164 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
165 jirafeau_export_cfg ($cfg);
169 $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
170 $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
171 jirafeau_export_cfg ($cfg);
179 require (JIRAFEAU_ROOT
. 'lib/settings.php');
180 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
183 if (isset ($_POST['next']))
184 $current = $_POST['step'] +
1;
185 else if (isset ($_POST['previous']))
186 $current = $_POST['step'] - 1;
187 else if (isset ($_POST['retry']))
188 $current = $_POST['step'];
194 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
195 ' %d ' . t('out of') . ' %d', 1, 4);
196 ?
></h2
> <div id
= "install"> <form action
=
197 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
198 "hidden" name
= "jirafeau" value
=
199 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
200 "step" value
= "1" /><fieldset
> <legend
><?php
echo t('Language');
201 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
204 ('Jirafeau is internationalised. Choose a specific langage or ' .
205 'choose Automatic (langage is provided by user\'s browser).');
206 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_lang"
207 ><?php
echo t('Choose the default language') . ':';
210 <select name
= "lang" id
= "select_lang">
211 <?php
foreach ($languages_list as $key => $item)
213 echo '<option value="'.$key.'"'.($key ==
214 $cfg['lang'] ?
' selected="selected"'
215 : '').'>'.$item.'</option>'.NL
;
222 <td
class = "nav next"><input type
= "submit" name
= "next" value
=
223 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
224 </fieldset
> </form
> </div
> <?php
228 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
229 ' %d ' . t('out of') . ' %d', 2, 4);
230 ?
></h2
> <div id
= "install"> <form action
=
231 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
232 "hidden" name
= "jirafeau" value
=
233 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
234 "step" value
= "2" /><fieldset
> <legend
><?php
235 echo t('Administration password');
236 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
239 ('Jirafeau has an administration interface (through admin.php). ' .
240 'You can set a password to access the intercace or let it be empty ' .
241 'to disable the interface.');
242 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "select_password"
243 ><?php
echo t('Administration password') . ':';
245 <td
class = "field"><input type
= "password" name
= "admin_password"
246 id
= "admin_password" size
= "40" /></td
>
250 <td
class = "nav next">
251 <input type
= "submit"
252 class = "navleft" name
= "previous" value
= "<?php
253 echo t('Previous step'); ?>" />
254 <input type
= "submit" name
= "next" value
=
255 "<?php echo t('Next step'); ?>" /></td
> </tr
> </table
>
256 </fieldset
> </form
> </div
> <?php
260 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
261 ' %d ' . t('out of') . ' %d', 3, 4);
262 ?
></h2
> <div id
= "install"> <form action
=
263 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
264 "hidden" name
= "jirafeau" value
=
265 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
267 "3" /><fieldset
> <legend
><?php
echo t('Information');
268 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
271 ('The base address of Jirafeau is the first part of the URL, until ' .
272 '(and including) the last slash. For example: ' .
273 '"http://www.example.com/". Do not forget the ending slash!');
274 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_web_root"
275 ><?php
echo t('Base address') . ':';
277 <td
class = "field"><input type
= "text" name
= "web_root"
278 id
= "input_web_root" value
= "<?php
279 echo (empty($cfg['web_root']) ?
280 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
281 '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
282 ?>" size
= "40" /></td
>
283 </tr
> <tr
> <td
class = "info" colspan
= "2"><?php
284 echo t('The data directory is where your files and information about' .
285 ' your files will be stored. You should put it outside your web ' .
286 'site, or at least restrict the access of this directory. Do not ' .
287 'forget the ending slash!');
288 ?
></td
> </tr
> <tr
> <td
class = "label"><label
for = "input_var_root"
289 ><?php
echo t('Data directory') . ':';
291 <td
class = "field"><input type
= "text" name
= "var_root"
292 id
= "input_var_root" value
= "<?php
293 if(empty($cfg['var_root'])) {
294 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
295 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
296 $len_alphanum = strlen($alphanum);
298 for($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
299 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
301 echo JIRAFEAU_ROOT . $var . '/';
304 echo $cfg['var_root'];
305 ?>" size
= "40" /></td
>
306 </tr
> <tr
> <td colspan
= "2"><input type
= "submit"
307 class = "navleft" name
= "previous" value
= "<?php
308 echo t('Previous step'); ?>" />
309 <input type
= "submit" class = "navright" name
= "next" value
= "
310 <?php echo t('Next step'); ?>" />
311 </td
> </tr
> </table
> </fieldset
>
316 ?
><h2
><?php
printf (t('Installation of Jirafeau') . ' - ' . t('step') .
317 ' %d ' . t('out of') . ' %d', 4, 4);
318 ?
></h2
> <div id
= "install"> <form action
=
319 "<?php echo basename(__FILE__); ?>" method
= "post"> <input type
=
320 "hidden" name
= "jirafeau" value
=
321 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
323 "4" /><fieldset
> <legend
><?php
echo t('Finalisation');
324 ?
></legend
> <table
> <tr
> <td
class = "info" colspan
=
326 t ('Jirafeau is setting the website according to the configuration ' .
328 ?
></td
> </tr
> <tr
> <td
class = "nav previous"><input type
=
329 "submit" name
= "previous" value
=
332 echo t('Previous step');
333 ?>" /></td
> <td
></td
> </tr
>
334 </table
> </fieldset
> </form
> </div
>
336 $err = jirafeau_check_var_dir ($cfg['var_root']);
337 if ($err['has_error'])
339 echo '<div class="error"><p>'.$err['why'].'<br />'.NL
;
340 ?
><form action
= "<?php echo basename(__FILE__); ?>" method
=
341 "post"> <input type
= "hidden" name
= "jirafeau" value
=
342 "<?php echo JIRAFEAU_VERSION; ?>" /><input type
= "hidden" name
=
343 "step" value
= "3" /><input type
= "submit" name
=
345 "<?php echo t('Retry this step'); ?>" /></form
>
346 <?php
echo '</p></div>';
350 echo '<div class="message"><p>' .
351 t('Jirafeau is now fully operational') . ':' .
352 '<br /><a href="' . $cfg['web_root'] . '">' .
353 $cfg['web_root'].'</a></p></div>';
358 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
patrick-canterino.de