1<?php 2/** 3 * Dokuwiki installation assistance 4 * 5 * @author Chris Smith <chris@jalakai.co.uk> 6 */ 7 8if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__)).'/'); 9if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/'); 10if(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC.'conf/'); 11 12// check for error reporting override or set error reporting to sane values 13if (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE); } 14else { error_reporting(DOKU_E_LEVEL); } 15 16// kill magic quotes 17if (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); 24} 25@set_magic_quotes_runtime(0); 26@ini_set('magic_quotes_sybase',0); 27 28// language strings 29require_once(DOKU_INC.'inc/lang/en/lang.php'); 30$LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']); 31if(!$LC) $LC = 'en'; 32if($LC && $LC != 'en' ) { 33 require_once(DOKU_INC.'inc/lang/'.$LC.'/lang.php'); 34} 35 36// initialise variables ... 37$error = array(); 38 39$dokuwiki_hash = array( 40 '2005-09-22' => 'e33223e957b0b0a130d0520db08f8fb7', 41 '2006-03-05' => '51295727f79ab9af309a2fd9e0b61acc', 42 '2006-03-09' => '51295727f79ab9af309a2fd9e0b61acc', 43 'devel' => '732131839d559198b985e183eefe9a63', 44); 45 46 47 48// begin output 49header('Content-Type: text/html; charset=utf-8'); 50?> 51<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 52 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 53<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $LC?>" 54 lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>"> 55<head> 56 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 57 <title>DokuWiki Installer</title> 58 <style type="text/css"> 59 body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; } 60 img { border: none } 61 br.cl { clear:both; } 62 code { font-size: 110%; color: #008000; } 63 fieldset { border: none } 64 label { display: block;} 65 select.text, input.text { width: 30em; margin: 0 0.5em; } 66 </style> 67 <script type="text/javascript" language="javascript"> 68 function acltoggle(){ 69 var cb = document.getElementById('acl'); 70 var fs = document.getElementById('acldep'); 71 if(!cb || !fs) return; 72 if(cb.checked){ 73 fs.style.display = ''; 74 }else{ 75 fs.style.display = 'none'; 76 } 77 } 78 window.onload = function(){ 79 acltoggle(); 80 var cb = document.getElementById('acl'); 81 if(cb) cb.onchange = acltoggle; 82 }; 83 </script> 84</head> 85<body style=""> 86 <h1 style="float:left"> 87 <img src="http://wiki.splitbrain.org/_media/wiki:dokuwiki-64.png" 88 style="vertical-align: middle;" alt="" /> 89 <?php echo $lang['i_installer']?> 90 </h1> 91 <div style="float:right; margin: 1em;"> 92 <?php langsel()?> 93 </div> 94 <br class="cl" /> 95 96 <div style="float: right; width: 34%;"> 97 <?php 98 if(@file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){ 99 include(DOKU_INC.'inc/lang/'.$LC.'/install.html'); 100 }else{ 101 include(DOKU_INC.'inc/lang/en/install.html'); 102 } 103 ?> 104 </div> 105 106 <div style="float: left; width: 58%;"> 107 <?php 108 if(! (check_functions() && check_permissions()) ){ 109 echo '<p>'.$lang['i_problems'].'</p>'; 110 print_errors(); 111 }elseif(!check_configs()){ 112 echo '<p>'.$lang['i_modified'].'</p>'; 113 print_errors(); 114 }elseif($_REQUEST['submit']){ 115 if(!check_data($_REQUEST['d'])){ 116 print_errors(); 117 print_form($_REQUEST['d']); 118 }elseif(!store_data($_REQUEST['d'])){ 119 echo '<p>'.$lang['i_failure'].'</p>'; 120 print_errors(); 121 }else{ 122 echo '<p>'.$lang['i_success'].'</p>'; 123 } 124 }else{ 125 print_form($_REQUEST['d']); 126 } 127 ?> 128 </div> 129 130<div style="clear: both"> 131 <a href="http://wiki.splitbrain.org/wiki:dokuwiki"><img src="lib/tpl/default/images/button-dw.png" alt="driven by DokuWiki" /></a> 132 <a href="http://www.php.net"><img src="lib/tpl/default/images/button-php.gif" alt="powered by PHP" /></a> 133</div> 134</body> 135</html> 136<?php 137 138/** 139 * Print the input form 140 */ 141function print_form($d){ 142 global $lang; 143 global $LC; 144 145 if(!is_array($d)) $d = array(); 146 $d = array_map('htmlspecialchars',$d); 147 148 if(!isset($d['acl'])) $d['acl']=1; 149 150 ?> 151 <form action="" method="post"> 152 <input type="hidden" name="l" value="<?php echo $LC ?>" /> 153 <fieldset> 154 <label for="title"><?php echo $lang['i_wikiname']?> 155 <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" /> 156 </label> 157 158 <fieldset style="margin-top: 1em;"> 159 <label for="acl"> 160 <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? 'checked="checked"' : ''));?> /> 161 <?php echo $lang['i_enableacl']?></label> 162 163 <fieldset id="acldep"> 164 <label for="superuser"><?php echo $lang['i_superuser']?></label> 165 <input class="text" type="text" name="d[superuser]" id="superuser" value="<?php echo $d['superuser'] ?>" /> 166 167 <label for="fullname"><?php echo $lang['fullname']?></label> 168 <input class="text" type="text" name="d[fullname]" id="fullname" value="<?php echo $d['fullname'] ?>" /> 169 170 <label for="email"><?php echo $lang['email']?></label> 171 <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" /> 172 173 <label for="password"><?php echo $lang['pass']?></label> 174 <input class="text" type="password" name="d[password]" id="password" /> 175 176 <label for="confirm"><?php echo $lang['passchk']?></label> 177 <input class="text" type="password" name="d[confirm]" id="confirm" /> 178 179 <label for="policy"><?php echo $lang['i_policy']?></label> 180 <select class="text" name="d[policy]" id="policy"> 181 <option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php echo $lang['i_pol0']?></option> 182 <option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php echo $lang['i_pol1']?></option> 183 <option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php echo $lang['i_pol2']?></option> 184 </select> 185 </fieldset> 186 </fieldset> 187 188 </fieldset> 189 <fieldset id="process"> 190 <input class="button" type="submit" name="submit" value="<?php echo $lang['btn_save']?>" /> 191 </fieldset> 192 </form> 193 <?php 194} 195 196/** 197 * Check validity of data 198 * 199 * @author Andreas Gohr 200 */ 201function check_data($d){ 202 global $lang; 203 global $error; 204 205 $ok = true; 206 207 // check input 208 if(empty($d['title'])){ 209 $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']); 210 $ok = false; 211 } 212 if($d['acl']){ 213 if(!preg_match('/^[a-z1-9_]+$/',$d['superuser'])){ 214 $error[] = sprintf($lang['i_badval'],$lang['i_superuser']); 215 $ok = false; 216 } 217 if(empty($d['password'])){ 218 $error[] = sprintf($lang['i_badval'],$lang['pass']); 219 $ok = false; 220 } 221 if($d['confirm'] != $d['password']){ 222 $error[] = sprintf($lang['i_badval'],$lang['passchk']); 223 $ok = false; 224 } 225 if(empty($d['fullname']) || strstr($d['fullname'],':')){ 226 $error[] = sprintf($lang['i_badval'],$lang['fullname']); 227 $ok = false; 228 } 229 if(empty($d['email']) || strstr($d['fullname'],':')){ 230 $error[] = sprintf($lang['i_badval'],$lang['email']); 231 $ok = false; 232 } 233 } 234 return $ok; 235} 236 237/** 238 * Writes the data to the config files 239 * 240 * @author Chris Smith <chris@jalakai.co.uk> 241 */ 242function store_data($d){ 243 global $LC; 244 $ok = true; 245 $d['policy'] = (int) $d['policy']; 246 247 // create changes.log 248 if (!@file_exists(DOKU_INC.'data/changes.log')){ 249 $ok = $ok && fileWrite(DOKU_INC.'data/changes.log',''); 250 } 251 252 // create local.php 253 $now = date('r'); 254 $output = <<<EOT 255<?php 256/** 257 * Dokuwiki's Main Configuration File - Local Settings 258 * Auto-generated by install script 259 * Date: $now 260 */ 261 262EOT; 263 $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n"; 264 $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n"; 265 if($d['acl']){ 266 $output .= '$conf[\'useacl\'] = 1'.";\n"; 267 $output .= '$conf[\'superuser\'] = \''.$d['superuser']."';\n"; 268 } 269 $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output); 270 271 272 if ($d['acl']) { 273 // create users.auth.php 274 // --- user:MD5password:Real Name:email:groups,comma,seperated 275 $output = join(":",array($d['superuser'], md5($d['password']), $d['fullname'], $d['email'], 'users')); 276 $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n"; 277 $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output); 278 279 // create acl.auth.php 280 $output = <<<EOT 281# acl.auth.php 282# <?php exit()?> 283# Don't modify the lines above 284# 285# Access Control Lists 286# 287# Auto-generated by install script 288# Date: $now 289 290EOT; 291 if($d['policy'] == 2){ 292 $output .= "* @ALL 0\n"; 293 $output .= "* @users 8\n"; 294 }elseif($d['policy'] == 2){ 295 $output .= "* @ALL 1\n"; 296 $output .= "* @users 8\n"; 297 }else{ 298 $output .= "* @ALL 8\n"; 299 } 300 301 $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output); 302 } 303 return $ok; 304} 305 306/** 307 * Write the given content to a file 308 * 309 * @author Chris Smith <chris@jalakai.co.uk> 310 */ 311function fileWrite($filename, $data) { 312 global $error; 313 global $lang; 314 315 if (($fp = @fopen($filename, 'wb')) === false) { 316 $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename); 317 $error[] = sprintf($lang['i_writeerr'],$filename); 318 return false; 319 } 320 321 if (!empty($data)) { fwrite($fp, $data); } 322 fclose($fp); 323 return true; 324} 325 326 327/** 328 * check installation dependent local config files and tests for a known 329 * unmodified main config file 330 * 331 * @author Chris Smith <chris@jalakai.co.uk> 332 */ 333function check_configs(){ 334 global $error; 335 global $lang; 336 global $dokuwiki_hash; 337 338 $ok = true; 339 340 $config_files = array( 341 'local' => DOKU_LOCAL.'local.php', 342 'users' => DOKU_LOCAL.'users.auth.php', 343 'auth' => DOKU_LOCAL.'acl.auth.php' 344 ); 345 346 347 // main dokuwiki config file (conf/dokuwiki.php) must not have been modified 348 $installation_hash = md5(@file_get_contents(DOKU_CONF.'dokuwiki.php')); 349 if (!in_array($installation_hash, $dokuwiki_hash)) { 350 $error[] = sprintf($lang['i_badhash'],$installation_hash); 351 $ok = false; 352 } 353 354 // configs shouldn't exist 355 foreach ($config_files as $file) { 356 if (@file_exists($file)) { 357 $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file); 358 $error[] = sprintf($lang['i_confexists'],$file); 359 $ok = false; 360 } 361 } 362 return $ok; 363} 364 365 366/** 367 * Check other installation dir/file permission requirements 368 * 369 * @author Chris Smith <chris@jalakai.co.uk> 370 */ 371function check_permissions(){ 372 global $error; 373 global $lang; 374 375 $dirs = array( 376 'conf' => DOKU_LOCAL, 377 'data' => DOKU_INC.'data', 378 'pages' => DOKU_INC.'data/pages', 379 'attic' => DOKU_INC.'data/attic', 380 'media' => DOKU_INC.'data/media', 381 'meta' => DOKU_INC.'data/meta', 382 'cache' => DOKU_INC.'data/cache', 383 'locks' => DOKU_INC.'data/locks', 384 ); 385 386 $ok = true; 387 foreach($dirs as $dir){ 388 if(!@file_exists("$dir/.") || !@is_writable($dir)){ 389 $dir = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $dir); 390 $error[] = sprintf($lang['i_permfail'],$dir); 391 $ok = false; 392 } 393 } 394 return $ok; 395} 396 397/** 398 * Check the availability of functions used in DokuWiki 399 * 400 * @author Andreas Gohr <andi@splitbrain.org> 401 */ 402function check_functions(){ 403 global $error; 404 global $lang; 405 $funcs = explode(' ','addslashes basename call_user_func chmod copy fgets '. 406 'file file_exists fseek flush filesize ftell fopen '. 407 'glob header ignore_user_abort ini_get mail mkdir '. 408 'ob_start opendir parse_ini_file readfile realpath '. 409 'rename rmdir serialize session_start unlink usleep'); 410 411 $ok = true; 412 foreach($funcs as $func){ 413 if(!function_exists($func)){ 414 $error[] = sprintf($lang['i_funcna'],$func); 415 $ok = false; 416 } 417 } 418 return $ok; 419} 420 421/** 422 * Print language selection 423 * 424 * @author Andreas Gohr <andi@splitbrain.org> 425 */ 426function langsel(){ 427 global $lang; 428 global $LC; 429 430 $dir = DOKU_INC.'inc/lang'; 431 $dh = opendir($dir); 432 if(!$dh) return; 433 434 $langs = array(); 435 while (($file = readdir($dh)) !== false) { 436 if(preg_match('/^[\._]/',$file)) continue; 437 if(is_dir($dir.'/'.$file) && @file_exists($dir.'/'.$file.'/lang.php')){ 438 $langs[] = $file; 439 } 440 } 441 closedir($dh); 442 sort($langs); 443 444 445 echo '<form action="">'; 446 echo $lang['i_chooselang']; 447 echo ': <select name="l" onchange="submit()">'; 448 foreach($langs as $l){ 449 $sel = ($l == $LC) ? 'selected="selected"' : ''; 450 echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>'; 451 } 452 echo '</select>'; 453 echo '<input type="submit" value="'.$lang['btn_update'].'" />'; 454 echo '</form>'; 455} 456 457/** 458 * Print gloabl error array 459 * 460 * @author Andreas Gohr <andi@splitbrain.org> 461 */ 462function print_errors(){ 463 global $error; 464 echo '<ul>'; 465 foreach ($error as $err){ 466 echo "<li>$err</li>"; 467 } 468 echo '</ul>'; 469} 470 471/** 472 * remove magic quotes recursivly 473 * 474 * @author Andreas Gohr <andi@splitbrain.org> 475 */ 476function remove_magic_quotes(&$array) { 477 foreach (array_keys($array) as $key) { 478 if (is_array($array[$key])) { 479 remove_magic_quotes($array[$key]); 480 }else { 481 $array[$key] = stripslashes($array[$key]); 482 } 483 } 484} 485 486