French language update
[dokuwiki/radio.git] / install.php
bloba9edbd44556d391c981e1b5f65ee3506c28497ae
1 <?php
2 /**
3 * Dokuwiki installation assistance
5 * @author Chris Smith <chris@jalakai.co.uk>
6 */
8 if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
9 if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
10 if(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC.'conf/');
12 // check for error reporting override or set error reporting to sane values
13 if (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE); }
14 else { error_reporting(DOKU_E_LEVEL); }
16 // kill magic quotes
17 if (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) {
18 if (!empty($_GET)) remove_magic_quotes($_GET);
19 if (!empty($_POST)) remove_magic_quotes($_POST);
20 if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE);
21 if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST);
22 @ini_set('magic_quotes_gpc', 0);
23 define('MAGIC_QUOTES_STRIPPED',1);
25 @set_magic_quotes_runtime(0);
26 @ini_set('magic_quotes_sybase',0);
28 // language strings
29 require_once(DOKU_INC.'inc/lang/en/lang.php');
30 $LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']);
31 if(!$LC) $LC = 'en';
32 if($LC && $LC != 'en' ) {
33 require_once(DOKU_INC.'inc/lang/'.$LC.'/lang.php');
36 // initialise variables ...
37 $error = array();
39 $dokuwiki_hash = array(
40 '2005-09-22' => 'e33223e957b0b0a130d0520db08f8fb7',
41 '2006-03-05' => '51295727f79ab9af309a2fd9e0b61acc',
42 '2006-03-09' => '51295727f79ab9af309a2fd9e0b61acc',
43 '2006-11-06' => 'b3a8af76845977c2000d85d6990dd72b',
44 '2007-05-24' => 'd80f2740c84c4a6a791fd3c7a353536f',
45 '2007-06-26' => 'b3ca19c7a654823144119980be73cd77',
46 '2008-05-04' => '1e5c42eac3219d9e21927c39e3240aad',
47 '2009-02-14' => 'ec8c04210732a14fdfce0f7f6eead865',
48 '2009-12-25' => '993c4b2b385643efe5abf8e7010e11f4',
53 // begin output
54 header('Content-Type: text/html; charset=utf-8');
56 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
57 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
58 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $LC?>"
59 lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>">
60 <head>
61 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
62 <title><?php echo $lang['i_installer']?></title>
63 <style type="text/css">
64 body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; }
65 img { border: none }
66 br.cl { clear:both; }
67 code { font-size: 110%; color: #800000; }
68 fieldset { border: none }
69 label { display: block; margin-top: 0.5em; }
70 select.text, input.text { width: 30em; margin: 0 0.5em; }
71 </style>
72 <script type="text/javascript" language="javascript">
73 function acltoggle(){
74 var cb = document.getElementById('acl');
75 var fs = document.getElementById('acldep');
76 if(!cb || !fs) return;
77 if(cb.checked){
78 fs.style.display = '';
79 }else{
80 fs.style.display = 'none';
83 window.onload = function(){
84 acltoggle();
85 var cb = document.getElementById('acl');
86 if(cb) cb.onchange = acltoggle;
88 </script>
89 </head>
90 <body style="">
91 <h1 style="float:left">
92 <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png&w=64"
93 style="vertical-align: middle;" alt="" />
94 <?php echo $lang['i_installer']?>
95 </h1>
96 <div style="float:right; margin: 1em;">
97 <?php langsel()?>
98 </div>
99 <br class="cl" />
101 <div style="float: right; width: 34%;">
102 <?php
103 if(@file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){
104 include(DOKU_INC.'inc/lang/'.$LC.'/install.html');
105 }else{
106 print "<div lang=\"en\" dir=\"ltr\">\n";
107 include(DOKU_INC.'inc/lang/en/install.html');
108 print "</div>\n";
111 </div>
113 <div style="float: left; width: 58%;">
114 <?php
115 if(! (check_functions() && check_permissions()) ){
116 echo '<p>'.$lang['i_problems'].'</p>';
117 print_errors();
118 print_retry();
119 }elseif(!check_configs()){
120 echo '<p>'.$lang['i_modified'].'</p>';
121 print_errors();
122 }elseif($_REQUEST['submit']){
123 if(!check_data($_REQUEST['d'])){
124 print_errors();
125 print_form($_REQUEST['d']);
126 }elseif(!store_data($_REQUEST['d'])){
127 echo '<p>'.$lang['i_failure'].'</p>';
128 print_errors();
129 }else{
130 echo '<p>'.$lang['i_success'].'</p>';
132 }else{
133 print_form($_REQUEST['d']);
136 </div>
138 <div style="clear: both">
139 <a href="http://dokuwiki.org/"><img src="lib/tpl/default/images/button-dw.png" alt="driven by DokuWiki" /></a>
140 <a href="http://www.php.net"><img src="lib/tpl/default/images/button-php.gif" alt="powered by PHP" /></a>
141 </div>
142 </body>
143 </html>
144 <?php
147 * Print the input form
149 function print_form($d){
150 global $lang;
151 global $LC;
153 if(!is_array($d)) $d = array();
154 $d = array_map('htmlspecialchars',$d);
156 if(!isset($d['acl'])) $d['acl']=1;
159 <form action="" method="post">
160 <input type="hidden" name="l" value="<?php echo $LC ?>" />
161 <fieldset>
162 <label for="title"><?php echo $lang['i_wikiname']?>
163 <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" />
164 </label>
166 <fieldset style="margin-top: 1em;">
167 <label for="acl">
168 <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? 'checked="checked"' : ''));?> />
169 <?php echo $lang['i_enableacl']?></label>
171 <fieldset id="acldep">
172 <label for="superuser"><?php echo $lang['i_superuser']?></label>
173 <input class="text" type="text" name="d[superuser]" id="superuser" value="<?php echo $d['superuser'] ?>" />
175 <label for="fullname"><?php echo $lang['fullname']?></label>
176 <input class="text" type="text" name="d[fullname]" id="fullname" value="<?php echo $d['fullname'] ?>" />
178 <label for="email"><?php echo $lang['email']?></label>
179 <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" />
181 <label for="password"><?php echo $lang['pass']?></label>
182 <input class="text" type="password" name="d[password]" id="password" />
184 <label for="confirm"><?php echo $lang['passchk']?></label>
185 <input class="text" type="password" name="d[confirm]" id="confirm" />
187 <label for="policy"><?php echo $lang['i_policy']?></label>
188 <select class="text" name="d[policy]" id="policy">
189 <option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php echo $lang['i_pol0']?></option>
190 <option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php echo $lang['i_pol1']?></option>
191 <option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php echo $lang['i_pol2']?></option>
192 </select>
193 </fieldset>
194 </fieldset>
196 </fieldset>
197 <fieldset id="process">
198 <input class="button" type="submit" name="submit" value="<?php echo $lang['btn_save']?>" />
199 </fieldset>
200 </form>
201 <?php
204 function print_retry() {
205 global $lang;
206 global $LC;
208 <form action="" method="get">
209 <fieldset>
210 <input type="hidden" name="l" value="<?php echo $LC ?>" />
211 <input class="button" type="submit" value="<?php echo $lang['i_retry'];?>" />
212 </fieldset>
213 </form>
214 <?php
218 * Check validity of data
220 * @author Andreas Gohr
222 function check_data(&$d){
223 global $lang;
224 global $error;
226 //autolowercase the username
227 $d['superuser'] = strtolower($d['superuser']);
229 $ok = true;
231 // check input
232 if(empty($d['title'])){
233 $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
234 $ok = false;
236 if($d['acl']){
237 if(!preg_match('/^[a-z1-9_]+$/',$d['superuser'])){
238 $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
239 $ok = false;
241 if(empty($d['password'])){
242 $error[] = sprintf($lang['i_badval'],$lang['pass']);
243 $ok = false;
245 if($d['confirm'] != $d['password']){
246 $error[] = sprintf($lang['i_badval'],$lang['passchk']);
247 $ok = false;
249 if(empty($d['fullname']) || strstr($d['fullname'],':')){
250 $error[] = sprintf($lang['i_badval'],$lang['fullname']);
251 $ok = false;
253 if(empty($d['email']) || strstr($d['email'],':') || !strstr($d['email'],'@')){
254 $error[] = sprintf($lang['i_badval'],$lang['email']);
255 $ok = false;
258 return $ok;
262 * Writes the data to the config files
264 * @author Chris Smith <chris@jalakai.co.uk>
266 function store_data($d){
267 global $LC;
268 $ok = true;
269 $d['policy'] = (int) $d['policy'];
271 // create local.php
272 $now = date('r');
273 $output = <<<EOT
274 <?php
276 * Dokuwiki's Main Configuration File - Local Settings
277 * Auto-generated by install script
278 * Date: $now
281 EOT;
282 $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
283 $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
284 if($d['acl']){
285 $output .= '$conf[\'useacl\'] = 1'.";\n";
286 $output .= "\$conf['superuser'] = '@admin';\n";
288 $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output);
290 if ($d['acl']) {
291 // create users.auth.php
292 // --- user:MD5password:Real Name:email:groups,comma,seperated
293 $output = join(":",array($d['superuser'], md5($d['password']), $d['fullname'], $d['email'], 'admin,user'));
294 $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n";
295 $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output);
297 // create acl.auth.php
298 $output = <<<EOT
299 # acl.auth.php
300 # <?php exit()?>
301 # Don't modify the lines above
303 # Access Control Lists
305 # Auto-generated by install script
306 # Date: $now
308 EOT;
309 if($d['policy'] == 2){
310 $output .= "* @ALL 0\n";
311 $output .= "* @user 8\n";
312 }elseif($d['policy'] == 1){
313 $output .= "* @ALL 1\n";
314 $output .= "* @user 8\n";
315 }else{
316 $output .= "* @ALL 8\n";
318 $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output);
320 return $ok;
324 * Write the given content to a file
326 * @author Chris Smith <chris@jalakai.co.uk>
328 function fileWrite($filename, $data) {
329 global $error;
330 global $lang;
332 if (($fp = @fopen($filename, 'wb')) === false) {
333 $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
334 $error[] = sprintf($lang['i_writeerr'],$filename);
335 return false;
338 if (!empty($data)) { fwrite($fp, $data); }
339 fclose($fp);
340 return true;
345 * check installation dependent local config files and tests for a known
346 * unmodified main config file
348 * @author Chris Smith <chris@jalakai.co.uk>
350 function check_configs(){
351 global $error;
352 global $lang;
353 global $dokuwiki_hash;
355 $ok = true;
357 $config_files = array(
358 'local' => DOKU_LOCAL.'local.php',
359 'users' => DOKU_LOCAL.'users.auth.php',
360 'auth' => DOKU_LOCAL.'acl.auth.php'
363 // main dokuwiki config file (conf/dokuwiki.php) must not have been modified
364 $installation_hash = md5(preg_replace("/(\015\012)|(\015)/","\012",
365 @file_get_contents(DOKU_CONF.'dokuwiki.php')));
366 if (!in_array($installation_hash, $dokuwiki_hash)) {
367 $error[] = sprintf($lang['i_badhash'],$installation_hash);
368 $ok = false;
371 // configs shouldn't exist
372 foreach ($config_files as $file) {
373 if (@file_exists($file)) {
374 $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
375 $error[] = sprintf($lang['i_confexists'],$file);
376 $ok = false;
379 return $ok;
384 * Check other installation dir/file permission requirements
386 * @author Chris Smith <chris@jalakai.co.uk>
388 function check_permissions(){
389 global $error;
390 global $lang;
392 $dirs = array(
393 'conf' => DOKU_LOCAL,
394 'data' => DOKU_INC.'data',
395 'pages' => DOKU_INC.'data/pages',
396 'attic' => DOKU_INC.'data/attic',
397 'media' => DOKU_INC.'data/media',
398 'meta' => DOKU_INC.'data/meta',
399 'cache' => DOKU_INC.'data/cache',
400 'locks' => DOKU_INC.'data/locks',
401 'index' => DOKU_INC.'data/index',
402 'tmp' => DOKU_INC.'data/tmp'
405 $ok = true;
406 foreach($dirs as $dir){
407 if(!@file_exists("$dir/.") || !@is_writable($dir)){
408 $dir = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
409 $error[] = sprintf($lang['i_permfail'],$dir);
410 $ok = false;
413 return $ok;
417 * Check the availability of functions used in DokuWiki and the PHP version
419 * @author Andreas Gohr <andi@splitbrain.org>
421 function check_functions(){
422 global $error;
423 global $lang;
424 $ok = true;
426 if(version_compare(phpversion(),'5.1.2','<')){
427 $error[] = sprintf($lang['i_phpver'],phpversion(),'5.1.2');
428 $ok = false;
431 $funcs = explode(' ','addslashes basename call_user_func chmod copy fgets '.
432 'file file_exists fseek flush filesize ftell fopen '.
433 'glob header ignore_user_abort ini_get mail mkdir '.
434 'ob_start opendir parse_ini_file readfile realpath '.
435 'rename rmdir serialize session_start unlink usleep '.
436 'preg_replace file_get_contents htmlspecialchars_decode');
438 if (!function_exists('mb_substr')) {
439 $funcs[] = 'utf8_encode';
440 $funcs[] = 'utf8_decode';
443 foreach($funcs as $func){
444 if(!function_exists($func)){
445 $error[] = sprintf($lang['i_funcna'],$func);
446 $ok = false;
449 return $ok;
453 * Print language selection
455 * @author Andreas Gohr <andi@splitbrain.org>
457 function langsel(){
458 global $lang;
459 global $LC;
461 $dir = DOKU_INC.'inc/lang';
462 $dh = opendir($dir);
463 if(!$dh) return;
465 $langs = array();
466 while (($file = readdir($dh)) !== false) {
467 if(preg_match('/^[\._]/',$file)) continue;
468 if(is_dir($dir.'/'.$file) && @file_exists($dir.'/'.$file.'/lang.php')){
469 $langs[] = $file;
472 closedir($dh);
473 sort($langs);
475 echo '<form action="">';
476 echo $lang['i_chooselang'];
477 echo ': <select name="l" onchange="submit()">';
478 foreach($langs as $l){
479 $sel = ($l == $LC) ? 'selected="selected"' : '';
480 echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
482 echo '</select> ';
483 echo '<input type="submit" value="'.$lang['btn_update'].'" />';
484 echo '</form>';
488 * Print global error array
490 * @author Andreas Gohr <andi@splitbrain.org>
492 function print_errors(){
493 global $error;
494 echo '<ul>';
495 foreach ($error as $err){
496 echo "<li>$err</li>";
498 echo '</ul>';
502 * remove magic quotes recursivly
504 * @author Andreas Gohr <andi@splitbrain.org>
506 function remove_magic_quotes(&$array) {
507 foreach (array_keys($array) as $key) {
508 if (is_array($array[$key])) {
509 remove_magic_quotes($array[$key]);
510 }else {
511 $array[$key] = stripslashes($array[$key]);