1<?php 2/*><div style="width:60%; margin: auto; background-color: #fcc; 3 border: 1px solid #faa; padding: 0.5em 1em;"> 4 <h1 style="font-size: 120%">No PHP Support</h1> 5 6 It seems this server has no PHP support enabled. You will need to 7 enable PHP before you can install and run DokuWiki. Contact your hosting 8 provider if you're unsure what this means. 9 10</div>*/ 11/** 12 * Dokuwiki installation assistance 13 * 14 * @author Chris Smith <chris@jalakai.co.uk> 15 */ 16 17if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/'); 18if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/'); 19if(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC.'conf/'); 20 21// load and initialize the core system 22require_once(DOKU_INC.'inc/init.php'); 23 24// check for error reporting override or set error reporting to sane values 25if (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE); } 26else { error_reporting(DOKU_E_LEVEL); } 27 28// language strings 29require_once(DOKU_INC.'inc/lang/en/lang.php'); 30if(isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) { 31 $LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']); 32} 33if(empty($LC)) $LC = 'en'; 34if($LC && $LC != 'en' ) { 35 require_once(DOKU_INC.'inc/lang/'.$LC.'/lang.php'); 36} 37 38// initialise variables ... 39$error = array(); 40 41// begin output 42header('Content-Type: text/html; charset=utf-8'); 43?> 44<!DOCTYPE html> 45<html lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>"> 46<head> 47 <meta charset="utf-8" /> 48 <title><?php echo $lang['i_installer']?></title> 49 <style type="text/css"> 50 body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; } 51 img { border: none } 52 br.cl { clear:both; } 53 code { font-size: 110%; color: #800000; } 54 fieldset { border: none } 55 label { display: block; margin-top: 0.5em; } 56 select.text, input.text { width: 30em; margin: 0 0.5em; } 57 a {text-decoration: none} 58 </style> 59 <script type="text/javascript"> 60 function acltoggle(){ 61 var cb = document.getElementById('acl'); 62 var fs = document.getElementById('acldep'); 63 if(!cb || !fs) return; 64 if(cb.checked){ 65 fs.style.display = ''; 66 }else{ 67 fs.style.display = 'none'; 68 } 69 } 70 window.onload = function(){ 71 acltoggle(); 72 var cb = document.getElementById('acl'); 73 if(cb) cb.onchange = acltoggle; 74 }; 75 </script> 76</head> 77<body style=""> 78 <h1 style="float:left"> 79 <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png" 80 style="vertical-align: middle;" alt="" height="64" width="64" /> 81 <?php echo $lang['i_installer']?> 82 </h1> 83 <div style="float:right; margin: 1em;"> 84 <?php langsel()?> 85 </div> 86 <br class="cl" /> 87 88 <div style="float: right; width: 34%;"> 89 <?php 90 if(file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){ 91 include(DOKU_INC.'inc/lang/'.$LC.'/install.html'); 92 }else{ 93 print "<div lang=\"en\" dir=\"ltr\">\n"; 94 include(DOKU_INC.'inc/lang/en/install.html'); 95 print "</div>\n"; 96 } 97 ?> 98 <a style=" 99 background: transparent 100 url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png) 101 left top no-repeat; 102 display: block; width:380px; height:73px; border:none; clear:both;" 103 target="_blank" 104 href="http://www.dokuwiki.org/security#web_access_security"></a> 105 </div> 106 107 <div style="float: left; width: 58%;"> 108 <?php 109 try { 110 if(! (check_functions() && check_permissions()) ){ 111 echo '<p>'.$lang['i_problems'].'</p>'; 112 print_errors(); 113 print_retry(); 114 }elseif(!check_configs()){ 115 echo '<p>'.$lang['i_modified'].'</p>'; 116 print_errors(); 117 }elseif(check_data($_REQUEST['d'])){ 118 // check_data has sanitized all input parameters 119 if(!store_data($_REQUEST['d'])){ 120 echo '<p>'.$lang['i_failure'].'</p>'; 121 print_errors(); 122 }else{ 123 echo '<p>'.$lang['i_success'].'</p>'; 124 } 125 }else{ 126 print_errors(); 127 print_form($_REQUEST['d']); 128 } 129 } catch (Exception $e) { 130 echo 'Caught exception: ', $e->getMessage(), "\n"; 131 } 132 ?> 133 </div> 134 135 136<div style="clear: both"> 137 <a href="http://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki" /></a> 138 <a href="http://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP" /></a> 139</div> 140</body> 141</html> 142<?php 143 144/** 145 * Print the input form 146 * 147 * @param array $d submitted entry 'd' of request data 148 */ 149function print_form($d){ 150 global $lang; 151 global $LC; 152 153 include(DOKU_CONF.'license.php'); 154 155 if(!is_array($d)) $d = array(); 156 $d = array_map('hsc',$d); 157 158 if(!isset($d['acl'])) $d['acl']=1; 159 if(!isset($d['pop'])) $d['pop']=1; 160 161 ?> 162 <form action="" method="post"> 163 <input type="hidden" name="l" value="<?php echo $LC ?>" /> 164 <fieldset> 165 <label for="title"><?php echo $lang['i_wikiname']?> 166 <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" /> 167 </label> 168 169 <fieldset style="margin-top: 1em;"> 170 <label for="acl"> 171 <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : ''));?> /> 172 <?php echo $lang['i_enableacl']?></label> 173 174 <fieldset id="acldep"> 175 <label for="superuser"><?php echo $lang['i_superuser']?></label> 176 <input class="text" type="text" name="d[superuser]" id="superuser" 177 value="<?php echo $d['superuser'] ?>" /> 178 179 <label for="fullname"><?php echo $lang['fullname']?></label> 180 <input class="text" type="text" name="d[fullname]" id="fullname" 181 value="<?php echo $d['fullname'] ?>" /> 182 183 <label for="email"><?php echo $lang['email']?></label> 184 <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" /> 185 186 <label for="password"><?php echo $lang['pass']?></label> 187 <input class="text" type="password" name="d[password]" id="password" /> 188 189 <label for="confirm"><?php echo $lang['passchk']?></label> 190 <input class="text" type="password" name="d[confirm]" id="confirm" /> 191 192 <label for="policy"><?php echo $lang['i_policy']?></label> 193 <select class="text" name="d[policy]" id="policy"> 194 <option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php 195 echo $lang['i_pol0']?></option> 196 <option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php 197 echo $lang['i_pol1']?></option> 198 <option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php 199 echo $lang['i_pol2']?></option> 200 </select> 201 202 <label for="allowreg"> 203 <input type="checkbox" name="d[allowreg]" id="allowreg" <?php 204 echo(($d['allowreg'] ? ' checked="checked"' : ''));?> /> 205 <?php echo $lang['i_allowreg']?> 206 </label> 207 </fieldset> 208 </fieldset> 209 210 <fieldset> 211 <p><?php echo $lang['i_license']?></p> 212 <?php 213 array_push($license,array('name' => $lang['i_license_none'], 'url'=>'')); 214 if(empty($d['license'])) $d['license'] = 'cc-by-sa'; 215 foreach($license as $key => $lic){ 216 echo '<label for="lic_'.$key.'">'; 217 echo '<input type="radio" name="d[license]" value="'.hsc($key).'" id="lic_'.$key.'"'. 218 (($d['license'] === $key)?' checked="checked"':'').'>'; 219 echo hsc($lic['name']); 220 if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>'; 221 echo '</label>'; 222 } 223 ?> 224 </fieldset> 225 226 <fieldset> 227 <p><?php echo $lang['i_pop_field']?></p> 228 <label for="pop"> 229 <input type="checkbox" name="d[pop]" id="pop" <?php 230 echo(($d['pop'] ? ' checked="checked"' : ''));?> /> 231 <?php echo $lang['i_pop_label']?> 232 <a href="http://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a> 233 </label> 234 </fieldset> 235 236 </fieldset> 237 <fieldset id="process"> 238 <button type="submit" name="submit"><?php echo $lang['btn_save']?></button> 239 </fieldset> 240 </form> 241 <?php 242} 243 244function print_retry() { 245 global $lang; 246 global $LC; 247 ?> 248 <form action="" method="get"> 249 <fieldset> 250 <input type="hidden" name="l" value="<?php echo $LC ?>" /> 251 <button type="submit"><?php echo $lang['i_retry'];?></button> 252 </fieldset> 253 </form> 254 <?php 255} 256 257/** 258 * Check validity of data 259 * 260 * @author Andreas Gohr 261 * 262 * @param array $d 263 * @return bool ok? 264 */ 265function check_data(&$d){ 266 static $form_default = array( 267 'title' => '', 268 'acl' => '1', 269 'superuser' => '', 270 'fullname' => '', 271 'email' => '', 272 'password' => '', 273 'confirm' => '', 274 'policy' => '0', 275 'allowreg' => '0', 276 'license' => 'cc-by-sa' 277 ); 278 global $lang; 279 global $error; 280 281 if(!is_array($d)) $d = array(); 282 foreach($d as $k => $v) { 283 if(is_array($v)) 284 unset($d[$k]); 285 else 286 $d[$k] = (string)$v; 287 } 288 289 //autolowercase the username 290 $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : ""; 291 292 $ok = false; 293 294 if(isset($_REQUEST['submit'])) { 295 $ok = true; 296 297 // check input 298 if(empty($d['title'])){ 299 $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']); 300 $ok = false; 301 } 302 if(isset($d['acl'])){ 303 if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){ 304 $error[] = sprintf($lang['i_badval'],$lang['i_superuser']); 305 $ok = false; 306 } 307 if(empty($d['password'])){ 308 $error[] = sprintf($lang['i_badval'],$lang['pass']); 309 $ok = false; 310 } 311 elseif(!isset($d['confirm']) || $d['confirm'] != $d['password']){ 312 $error[] = sprintf($lang['i_badval'],$lang['passchk']); 313 $ok = false; 314 } 315 if(empty($d['fullname']) || strstr($d['fullname'],':')){ 316 $error[] = sprintf($lang['i_badval'],$lang['fullname']); 317 $ok = false; 318 } 319 if(empty($d['email']) || strstr($d['email'],':') || !strstr($d['email'],'@')){ 320 $error[] = sprintf($lang['i_badval'],$lang['email']); 321 $ok = false; 322 } 323 }else{ 324 // Since default = 1, browser won't send acl=0 when user untick acl 325 $d['acl'] = '0'; 326 } 327 } 328 $d = array_merge($form_default, $d); 329 return $ok; 330} 331 332/** 333 * Writes the data to the config files 334 * 335 * @author Chris Smith <chris@jalakai.co.uk> 336 * 337 * @param array $d 338 * @return bool 339 */ 340function store_data($d){ 341 global $LC; 342 $ok = true; 343 $d['policy'] = (int) $d['policy']; 344 345 // create local.php 346 $now = gmdate('r'); 347 $output = <<<EOT 348<?php 349/** 350 * Dokuwiki's Main Configuration File - Local Settings 351 * Auto-generated by install script 352 * Date: $now 353 */ 354 355EOT; 356 // add any config options set by a previous installer 357 $preset = __DIR__.'/install.conf'; 358 if(file_exists($preset)){ 359 $output .= "# preset config options\n"; 360 $output .= file_get_contents($preset); 361 $output .= "\n\n"; 362 $output .= "# options selected in installer\n"; 363 @unlink($preset); 364 } 365 366 $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n"; 367 $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n"; 368 $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n"; 369 if($d['acl']){ 370 $output .= '$conf[\'useacl\'] = 1'.";\n"; 371 $output .= "\$conf['superuser'] = '@admin';\n"; 372 } 373 if(!$d['allowreg']){ 374 $output .= '$conf[\'disableactions\'] = \'register\''.";\n"; 375 } 376 $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output); 377 378 if ($d['acl']) { 379 // hash the password 380 $phash = new \dokuwiki\PassHash(); 381 $pass = $phash->hash_smd5($d['password']); 382 383 // create users.auth.php 384 // --- user:SMD5password:Real Name:email:groups,comma,seperated 385 $output = join(":",array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user')); 386 $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n"; 387 $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output); 388 389 // create acl.auth.php 390 $output = <<<EOT 391# acl.auth.php 392# <?php exit()?> 393# Don't modify the lines above 394# 395# Access Control Lists 396# 397# Auto-generated by install script 398# Date: $now 399 400EOT; 401 if($d['policy'] == 2){ 402 $output .= "* @ALL 0\n"; 403 $output .= "* @user 8\n"; 404 }elseif($d['policy'] == 1){ 405 $output .= "* @ALL 1\n"; 406 $output .= "* @user 8\n"; 407 }else{ 408 $output .= "* @ALL 8\n"; 409 } 410 $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output); 411 } 412 413 // enable popularity submission 414 if($d['pop']){ 415 @touch(DOKU_INC.'data/cache/autosubmit.txt'); 416 } 417 418 // disable auth plugins til needed 419 $output = <<<EOT 420<?php 421/* 422 * Local plugin enable/disable settings 423 * 424 * Auto-generated by install script 425 * Date: $now 426 */ 427 428\$plugins['authad'] = 0; 429\$plugins['authldap'] = 0; 430\$plugins['authmysql'] = 0; 431\$plugins['authpgsql'] = 0; 432 433EOT; 434 $ok = $ok && fileWrite(DOKU_LOCAL.'plugins.local.php', $output); 435 436 return $ok; 437} 438 439/** 440 * Write the given content to a file 441 * 442 * @author Chris Smith <chris@jalakai.co.uk> 443 * 444 * @param string $filename 445 * @param string $data 446 * @return bool 447 */ 448function fileWrite($filename, $data) { 449 global $error; 450 global $lang; 451 452 if (($fp = @fopen($filename, 'wb')) === false) { 453 $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename); 454 $error[] = sprintf($lang['i_writeerr'],$filename); 455 return false; 456 } 457 458 if (!empty($data)) { fwrite($fp, $data); } 459 fclose($fp); 460 return true; 461} 462 463 464/** 465 * check installation dependent local config files and tests for a known 466 * unmodified main config file 467 * 468 * @author Chris Smith <chris@jalakai.co.uk> 469 * 470 * @return bool 471 */ 472function check_configs(){ 473 global $error; 474 global $lang; 475 476 $ok = true; 477 478 $config_files = array( 479 'local' => DOKU_LOCAL.'local.php', 480 'users' => DOKU_LOCAL.'users.auth.php', 481 'auth' => DOKU_LOCAL.'acl.auth.php' 482 ); 483 484 // configs shouldn't exist 485 foreach ($config_files as $file) { 486 if (file_exists($file) && filesize($file)) { 487 $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file); 488 $error[] = sprintf($lang['i_confexists'],$file); 489 $ok = false; 490 } 491 } 492 return $ok; 493} 494 495 496/** 497 * Check other installation dir/file permission requirements 498 * 499 * @author Chris Smith <chris@jalakai.co.uk> 500 * 501 * @return bool 502 */ 503function check_permissions(){ 504 global $error; 505 global $lang; 506 507 $dirs = array( 508 'conf' => DOKU_LOCAL, 509 'data' => DOKU_INC.'data', 510 'pages' => DOKU_INC.'data/pages', 511 'attic' => DOKU_INC.'data/attic', 512 'media' => DOKU_INC.'data/media', 513 'media_attic' => DOKU_INC.'data/media_attic', 514 'media_meta' => DOKU_INC.'data/media_meta', 515 'meta' => DOKU_INC.'data/meta', 516 'cache' => DOKU_INC.'data/cache', 517 'locks' => DOKU_INC.'data/locks', 518 'index' => DOKU_INC.'data/index', 519 'tmp' => DOKU_INC.'data/tmp' 520 ); 521 522 $ok = true; 523 foreach($dirs as $dir){ 524 if(!file_exists("$dir/.") || !is_writable($dir)){ 525 $dir = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir); 526 $error[] = sprintf($lang['i_permfail'],$dir); 527 $ok = false; 528 } 529 } 530 return $ok; 531} 532 533/** 534 * Check the availability of functions used in DokuWiki and the PHP version 535 * 536 * @author Andreas Gohr <andi@splitbrain.org> 537 * 538 * @return bool 539 */ 540function check_functions(){ 541 global $error; 542 global $lang; 543 $ok = true; 544 545 if(version_compare(phpversion(),'5.6.0','<')){ 546 $error[] = sprintf($lang['i_phpver'],phpversion(),'5.6.0'); 547 $ok = false; 548 } 549 550 if(ini_get('mbstring.func_overload') != 0){ 551 $error[] = $lang['i_mbfuncoverload']; 552 $ok = false; 553 } 554 555 $funcs = explode(' ','addslashes call_user_func chmod copy fgets '. 556 'file file_exists fseek flush filesize ftell fopen '. 557 'glob header ignore_user_abort ini_get mail mkdir '. 558 'ob_start opendir parse_ini_file readfile realpath '. 559 'rename rmdir serialize session_start unlink usleep '. 560 'preg_replace file_get_contents htmlspecialchars_decode '. 561 'spl_autoload_register stream_select fsockopen pack'); 562 563 if (!function_exists('mb_substr')) { 564 $funcs[] = 'utf8_encode'; 565 $funcs[] = 'utf8_decode'; 566 } 567 568 foreach($funcs as $func){ 569 if(!function_exists($func)){ 570 $error[] = sprintf($lang['i_funcna'],$func); 571 $ok = false; 572 } 573 } 574 return $ok; 575} 576 577/** 578 * Print language selection 579 * 580 * @author Andreas Gohr <andi@splitbrain.org> 581 */ 582function langsel(){ 583 global $lang; 584 global $LC; 585 586 $dir = DOKU_INC.'inc/lang'; 587 $dh = opendir($dir); 588 if(!$dh) return; 589 590 $langs = array(); 591 while (($file = readdir($dh)) !== false) { 592 if(preg_match('/^[\._]/',$file)) continue; 593 if(is_dir($dir.'/'.$file) && file_exists($dir.'/'.$file.'/lang.php')){ 594 $langs[] = $file; 595 } 596 } 597 closedir($dh); 598 sort($langs); 599 600 echo '<form action="">'; 601 echo $lang['i_chooselang']; 602 echo ': <select name="l" onchange="submit()">'; 603 foreach($langs as $l){ 604 $sel = ($l == $LC) ? 'selected="selected"' : ''; 605 echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>'; 606 } 607 echo '</select> '; 608 echo '<button type="submit">'.$lang['btn_update'].'</button>'; 609 echo '</form>'; 610} 611 612/** 613 * Print global error array 614 * 615 * @author Andreas Gohr <andi@splitbrain.org> 616 */ 617function print_errors(){ 618 global $error; 619 if(!empty($error)) { 620 echo '<ul>'; 621 foreach ($error as $err){ 622 echo "<li>$err</li>"; 623 } 624 echo '</ul>'; 625 } 626} 627