]> git.p6c8.net - jirafeau_mojo42.git/blob - install.php
Translated using Weblate (Arabic)
[jirafeau_mojo42.git] / install.php
1 <?php
2 /*
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>
6 *
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.
11 *
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.
16 *
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/>.
19 */
20 define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
21
22 define('JIRAFEAU_CFG', JIRAFEAU_ROOT . 'lib/config.local.php');
23 define('JIRAFEAU_VAR_RAND_LENGTH', 15);
24
25 require(JIRAFEAU_ROOT . 'lib/settings.php');
26 require(JIRAFEAU_ROOT . 'lib/functions.php');
27 require(JIRAFEAU_ROOT . 'lib/lang.php');
28
29 /**
30 * Prepend used functions
31 **/
32
33 function jirafeau_quoted($str)
34 {
35 return QUOTE . str_replace(QUOTE, "\'", $str) . QUOTE;
36 }
37
38 function jirafeau_export_cfg($cfg)
39 {
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) . ';';
45
46 $fileWrite = file_put_contents(JIRAFEAU_CFG, $content);
47
48 if (false === $fileWrite) {
49 jirafeau_fatal_error(t('Can not write local configuration file'));
50 }
51 }
52
53 function jirafeau_mkdir($path)
54 {
55 return !(!file_exists($path) && !@mkdir($path, 0755));
56 }
57
58 /**
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.
63 */
64 function jirafeau_is_writable($path)
65 {
66 /* "@" gets rid of error messages. */
67 return is_writable($path) || @chmod($path, 0777);
68 }
69
70 function jirafeau_check_var_dir($path)
71 {
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 ' .
76 'this directory.');
77 $solution_str = t('Here is a solution') . ':';
78
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);
84 }
85
86 foreach (array('files', 'links', 'async') as $subdir) {
87 $subpath = $path.$subdir;
88
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);
94 }
95 }
96
97 return array('has_error' => false, 'why' => '');
98 }
99
100 function jirafeau_add_ending_slash($path)
101 {
102 return $path . ((substr($path, -1) == '/') ? '' : '/');
103 }
104
105 /**
106 * Check installation
107 **/
108
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');
113 exit;
114 }
115
116 /**
117 * Prepare installation process
118 **/
119
120 require(JIRAFEAU_ROOT . 'lib/template/header.php');
121
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> ' .
131 'directory.')
132 );
133 }
134 }
135
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.')
142 );
143 }
144
145 /**
146 * Run trough each installation step
147 **/
148
149 if (isset($_POST['step']) && isset($_POST['next'])) {
150 switch ($_POST['step']) {
151 case 1:
152 $cfg['lang'] = $_POST['lang'];
153 jirafeau_export_cfg($cfg);
154 break;
155
156 case 2:
157 if (strlen($_POST['admin_password'])) {
158 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
159 } else {
160 $cfg['admin_password'] = '';
161 }
162 jirafeau_export_cfg($cfg);
163 break;
164
165 case 3:
166 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
167 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
168 jirafeau_export_cfg($cfg);
169 break;
170
171 case 4:
172 $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
173 $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
174 jirafeau_export_cfg($cfg);
175 break;
176 }
177 }
178
179 $current = 1;
180 if (isset($_POST['next'])) {
181 $current = $_POST['step'] + 1;
182 } elseif (isset($_POST['previous'])) {
183 $current = $_POST['step'] - 1;
184 } elseif (isset($_POST['retry'])) {
185 $current = $_POST['step'];
186 }
187
188 switch ($current) {
189 case 1:
190 default:
191 ?><h2><?php printf(t('Installation of Jirafeau') . ' - ' . t('step') .
192 ' %d ' . t('out of') . ' %d', 1, 4);
193 ?></h2> <div id = "install"> <form method="post"> <input type =
194 "hidden" name = "jirafeau" value =
195 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
196 "step" value = "1" /><fieldset> <legend><?php echo t('Language');
197 ?></legend> <table> <tr> <td class = "info" colspan =
198 "2"><?php echo
199 t('Jirafeau is internationalised. Choose a specific langage or ' .
200 'choose Automatic (langage is provided by user\'s browser).');
201 ?></td> </tr> <tr> <td class = "label"><label for = "select_lang"
202 ><?php echo t('Choose the default language') . ':';
203 ?></label></td>
204 <td class = "field">
205 <select name = "lang" id = "select_lang">
206 <?php foreach ($languages_list as $key => $item) {
207 echo '<option value="'.$key.'"'.($key ==
208 $cfg['lang'] ? ' selected="selected"'
209 : '').'>'.$item.'</option>'.NL;
210 }
211 ?></select>
212 </td>
213 </tr>
214 <tr class = "nav">
215 <td></td>
216 <td class = "nav next"><input type = "submit" name = "next" value =
217 "<?php echo t('Next step'); ?>" /></td> </tr> </table>
218 </fieldset> </form> </div> <?php
219 break;
220
221 case 2:
222 ?><h2><?php printf(t('Installation of Jirafeau') . ' - ' . t('step') .
223 ' %d ' . t('out of') . ' %d', 2, 4);
224 ?></h2> <div id = "install"> <form method="post"> <input type =
225 "hidden" name = "jirafeau" value =
226 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
227 "step" value = "2" /><fieldset> <legend><?php
228 echo t('Administration password');
229 ?></legend> <table> <tr> <td class = "info" colspan =
230 "2"><?php echo
231 t('Jirafeau has an administration interface (through admin.php). ' .
232 'You can set a password to access the interface or leave it empty ' .
233 'to disable the interface.');
234 ?></td> </tr> <tr> <td class = "label"><label for = "select_password"
235 ><?php echo t('Administration password') . ':';
236 ?></label></td>
237 <td class = "field"><input type = "password" name = "admin_password"
238 id = "admin_password" size = "40" /></td>
239 </tr>
240 <tr class = "nav">
241 <td></td>
242 <td class = "nav next">
243 <input type = "submit"
244 class = "navleft" name = "previous" value = "<?php
245 echo t('Previous step'); ?>" />
246 <input type = "submit" name = "next" value =
247 "<?php echo t('Next step'); ?>" /></td> </tr> </table>
248 </fieldset> </form> </div> <?php
249 break;
250
251 case 3:
252 ?><h2><?php printf(t('Installation of Jirafeau') . ' - ' . t('step') .
253 ' %d ' . t('out of') . ' %d', 3, 4);
254 ?></h2> <div id = "install"> <form method="post"> <input type =
255 "hidden" name = "jirafeau" value =
256 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
257 "step" value =
258 "3" /><fieldset> <legend><?php echo t('Information');
259 ?></legend> <table> <tr> <td class = "info" colspan =
260 "2"><?php echo
261 t('The base address of Jirafeau is the first part of the URL, until ' .
262 '(and including) the last slash. For example: ' .
263 '"http://www.example.com/". Do not forget the trailing slash!');
264 ?></td> </tr> <tr> <td class = "label"><label for = "input_web_root"
265 ><?php echo t('Base address') . ':';
266 ?></label></td>
267 <td class = "field"><input type = "text" name = "web_root"
268 id = "input_web_root" value = "<?php
269 echo(empty($cfg['web_root']) ?
270 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
271 '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
272 ?>" size = "40" /></td>
273 </tr> <tr> <td class = "info" colspan = "2"><?php
274 echo t('The data directory is where your files and information about' .
275 ' your files will be stored. You should put it outside your web ' .
276 'site, or at least restrict the access to this directory. Do not ' .
277 'forget the trailing slash!');
278 ?></td> </tr> <tr> <td class = "label"><label for = "input_var_root"
279 ><?php echo t('Data directory') . ':';
280 ?></label></td>
281 <td class = "field"><input type = "text" name = "var_root"
282 id = "input_var_root" value = "<?php
283 if (empty($cfg['var_root'])) {
284 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
285 'abcdefghijklmnopqrstuvwxyz' . '0123456789';
286 $len_alphanum = strlen($alphanum);
287 $var = 'var-';
288 for ($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
289 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
290 }
291 echo JIRAFEAU_ROOT . $var . '/';
292 } else {
293 echo $cfg['var_root'];
294 }
295 ?>" size = "40" /></td>
296 </tr> <tr> <td colspan = "2"><input type = "submit"
297 class = "navleft" name = "previous" value = "<?php
298 echo t('Previous step'); ?>" />
299 <input type = "submit" class = "navright" name = "next" value = "
300 <?php echo t('Next step'); ?>" />
301 </td> </tr> </table> </fieldset>
302 </form> </div> <?php
303 break;
304
305 case 4:
306 ?><h2><?php printf(t('Installation of Jirafeau') . ' - ' . t('step') .
307 ' %d ' . t('out of') . ' %d', 4, 4);
308 ?></h2> <div id = "install"> <form method="post"> <input type =
309 "hidden" name = "jirafeau" value =
310 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
311 "step" value =
312 "4" /><fieldset> <legend><?php echo t('Finalisation');
313 ?></legend> <table> <tr> <td class = "info" colspan =
314 "2"><?php echo
315 t('Jirafeau is setting the website according to the configuration ' .
316 'you provided.');
317 ?></td> </tr> <tr> <td class = "nav previous"><input type =
318 "submit" name = "previous" value =
319 "
320 <?php
321 echo t('Previous step');
322 ?>" /></td> <td></td> </tr>
323 </table> </fieldset> </form> </div>
324 <?php
325 $err = jirafeau_check_var_dir($cfg['var_root']);
326 if ($err['has_error']) {
327 echo '<div class="error"><p>'.$err['why'].'<br />'.NL; ?><form method="post"> <input type = "hidden" name = "jirafeau" value =
328 "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
329 "step" value = "4" /><input type = "submit" name =
330 "retry" value =
331 "<?php echo t('Retry this step'); ?>" /></form>
332 <?php echo '</p></div>';
333 } else {
334 $cfg['installation_done'] = true;
335 jirafeau_export_cfg($cfg);
336 echo '<div class="message"><p>' .
337 t('Jirafeau is now fully operational') . ':' .
338 '<br /><a href="./">' .
339 $cfg['web_root'].'</a></p></div>';
340 }
341 break;
342 }
343
344 require(JIRAFEAU_ROOT . 'lib/template/footer.php');

patrick-canterino.de