]> git.p6c8.net - jirafeau_mojo42.git/blob - install.php
Added translation using Weblate (Tamil)
[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', 'alias') 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 $cfg['admin_password'] = hash('sha256', $_POST['admin_password']);
158 jirafeau_export_cfg($cfg);
159 break;
160
161 case 3:
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);
165 break;
166
167 case 4:
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);
171 break;
172 }
173 }
174
175 $current = 1;
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'];
182 }
183
184 switch ($current) {
185 case 1:
186 default:
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 =
194 "2"><?php echo
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') . ':';
199 ?></label></td>
200 <td class = "field">
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;
206 }
207 ?></select>
208 </td>
209 </tr>
210 <tr class = "nav">
211 <td></td>
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
215 break;
216
217 case 2:
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 =
226 "2"><?php echo
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') . ':';
232 ?></label></td>
233 <td class = "field"><input type = "password" name = "admin_password"
234 id = "admin_password" size = "40" /></td>
235 </tr>
236 <tr class = "nav">
237 <td></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
245 break;
246
247 case 3:
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 =
253 "step" value =
254 "3" /><fieldset> <legend><?php echo t('Information');
255 ?></legend> <table> <tr> <td class = "info" colspan =
256 "2"><?php echo
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') . ':';
262 ?></label></td>
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') . ':';
276 ?></label></td>
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);
283 $var = 'var-';
284 for ($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
285 $var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
286 }
287 echo JIRAFEAU_ROOT . $var . '/';
288 } else {
289 echo $cfg['var_root'];
290 }
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>
298 </form> </div> <?php
299 break;
300
301 case 4:
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 =
307 "step" value =
308 "4" /><fieldset> <legend><?php echo t('Finalisation');
309 ?></legend> <table> <tr> <td class = "info" colspan =
310 "2"><?php echo
311 t('Jirafeau is setting the website according to the configuration ' .
312 'you provided.');
313 ?></td> </tr> <tr> <td class = "nav previous"><input type =
314 "submit" name = "previous" value =
315 "
316 <?php
317 echo t('Previous step');
318 ?>" /></td> <td></td> </tr>
319 </table> </fieldset> </form> </div>
320 <?php
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 =
326 "retry" value =
327 "<?php echo t('Retry this step'); ?>" /></form>
328 <?php echo '</p></div>';
329 } else {
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>';
336 }
337 break;
338 }
339
340 require(JIRAFEAU_ROOT . 'lib/template/footer.php');

patrick-canterino.de