15cfb8815Schris<?php 25cfb8815Schris/** 35cfb8815Schris * Dokuwiki installation assistance 45cfb8815Schris * 55cfb8815Schris * @author Chris Smith <chris@jalakai.co.uk> 65cfb8815Schris */ 75cfb8815Schris 8d0a27cb0SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/'); 95cfb8815Schrisif(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/'); 105cfb8815Schrisif(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC.'conf/'); 115cfb8815Schris 1202bca5d4SYousong Zhou// load and initialize the core system 1302bca5d4SYousong Zhourequire_once(DOKU_INC.'inc/init.php'); 143791b589SAndreas Gohr 153545b2e0Schris// check for error reporting override or set error reporting to sane values 163545b2e0Schrisif (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE); } 173545b2e0Schriselse { error_reporting(DOKU_E_LEVEL); } 183545b2e0Schris 1947248316SAndreas Gohr// language strings 2047248316SAndreas Gohrrequire_once(DOKU_INC.'inc/lang/en/lang.php'); 214b530faaSTom N Harrisif(isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) { 2247248316SAndreas Gohr $LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']); 234b530faaSTom N Harris} 244b530faaSTom N Harrisif(empty($LC)) $LC = 'en'; 2547248316SAndreas Gohrif($LC && $LC != 'en' ) { 2647248316SAndreas Gohr require_once(DOKU_INC.'inc/lang/'.$LC.'/lang.php'); 2747248316SAndreas Gohr} 2847248316SAndreas Gohr 2947248316SAndreas Gohr// initialise variables ... 3047248316SAndreas Gohr$error = array(); 3147248316SAndreas Gohr 3247248316SAndreas Gohr$dokuwiki_hash = array( 3347248316SAndreas Gohr '2005-09-22' => 'e33223e957b0b0a130d0520db08f8fb7', 3447248316SAndreas Gohr '2006-03-05' => '51295727f79ab9af309a2fd9e0b61acc', 3547248316SAndreas Gohr '2006-03-09' => '51295727f79ab9af309a2fd9e0b61acc', 364dde32ddSAndreas Gohr '2006-11-06' => 'b3a8af76845977c2000d85d6990dd72b', 37e7f137b2SAndreas Gohr '2007-05-24' => 'd80f2740c84c4a6a791fd3c7a353536f', 3883666c1bSAndreas Gohr '2007-06-26' => 'b3ca19c7a654823144119980be73cd77', 39dd6510bdSAndreas Gohr '2008-05-04' => '1e5c42eac3219d9e21927c39e3240aad', 40b4353e51SAndreas Gohr '2009-02-14' => 'ec8c04210732a14fdfce0f7f6eead865', 4185d9abfcSAndreas Gohr '2009-12-25' => '993c4b2b385643efe5abf8e7010e11f4', 42c991623aSAdrian Lang '2010-11-07' => '7921d48195f4db21b8ead6d9bea801b8', 435ff12737SAdrian Lang '2011-05-25' => '4241865472edb6fa14a1227721008072', 44a5a71ecfSAdrian Lang '2011-11-10' => 'b46ff19a7587966ac4df61cbab1b8b31', 455371328cSAndreas Gohr '2012-01-25' => '72c083c73608fc43c586901fd5dabb74', 46c70d6ceeSAndreas Gohr '2012-09-10' => 'eb0b3fc90056fbc12bac6f49f7764df3', 472a5a1456SGuy Brand '2013-05-10' => '7b62b75245f57f122d3e0f8ed7989623', 488c4759c9SGuy Brand '2013-12-08' => '263c76af309fbf083867c18a34ff5214', 4975930869SGuy Brand '2014-05-05' => '263c76af309fbf083867c18a34ff5214', 50c8574e7dSGuy Brand '2015-08-10' => '263c76af309fbf083867c18a34ff5214', 512f7c97b3SGuy Brand '2016-06-26' => 'fd3abb6d89853dacb032907e619fbd73', 522f7c97b3SGuy Brand '2017-02-19' => 'e4f2f5a34c9dbcd96a5ecc8f2df25bd9' 5347248316SAndreas Gohr); 5447248316SAndreas Gohr 5547248316SAndreas Gohr 5647248316SAndreas Gohr// begin output 5747248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8'); 5847248316SAndreas Gohr?> 59c8839c22SAnika Henke<!DOCTYPE html> 60c8839c22SAnika Henke<html lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>"> 6147248316SAndreas Gohr<head> 62c8839c22SAnika Henke <meta charset="utf-8" /> 634208c142SAndreas Gohr <title><?php echo $lang['i_installer']?></title> 6447248316SAndreas Gohr <style type="text/css"> 6547248316SAndreas Gohr body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; } 6647248316SAndreas Gohr img { border: none } 6747248316SAndreas Gohr br.cl { clear:both; } 6870a6aa16Schris code { font-size: 110%; color: #800000; } 6947248316SAndreas Gohr fieldset { border: none } 709c70688aSchris label { display: block; margin-top: 0.5em; } 718af2e4bbSAndreas Gohr select.text, input.text { width: 30em; margin: 0 0.5em; } 7206361442SAndreas Gohr a {text-decoration: none} 7347248316SAndreas Gohr </style> 74e260f93bSAnika Henke <script type="text/javascript"> 7547248316SAndreas Gohr function acltoggle(){ 7647248316SAndreas Gohr var cb = document.getElementById('acl'); 7747248316SAndreas Gohr var fs = document.getElementById('acldep'); 7847248316SAndreas Gohr if(!cb || !fs) return; 7947248316SAndreas Gohr if(cb.checked){ 8047248316SAndreas Gohr fs.style.display = ''; 8147248316SAndreas Gohr }else{ 8247248316SAndreas Gohr fs.style.display = 'none'; 8347248316SAndreas Gohr } 8447248316SAndreas Gohr } 8547248316SAndreas Gohr window.onload = function(){ 8647248316SAndreas Gohr acltoggle(); 8747248316SAndreas Gohr var cb = document.getElementById('acl'); 8847248316SAndreas Gohr if(cb) cb.onchange = acltoggle; 8947248316SAndreas Gohr }; 9047248316SAndreas Gohr </script> 9147248316SAndreas Gohr</head> 9247248316SAndreas Gohr<body style=""> 9347248316SAndreas Gohr <h1 style="float:left"> 94c5270434SAndreas Gohr <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png" 95c5270434SAndreas Gohr style="vertical-align: middle;" alt="" height="64" width="64" /> 9647248316SAndreas Gohr <?php echo $lang['i_installer']?> 9747248316SAndreas Gohr </h1> 9847248316SAndreas Gohr <div style="float:right; margin: 1em;"> 9947248316SAndreas Gohr <?php langsel()?> 10047248316SAndreas Gohr </div> 10147248316SAndreas Gohr <br class="cl" /> 10247248316SAndreas Gohr 10347248316SAndreas Gohr <div style="float: right; width: 34%;"> 10447248316SAndreas Gohr <?php 10579e79377SAndreas Gohr if(file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){ 10647248316SAndreas Gohr include(DOKU_INC.'inc/lang/'.$LC.'/install.html'); 10747248316SAndreas Gohr }else{ 108ca64d724Schris print "<div lang=\"en\" dir=\"ltr\">\n"; 10947248316SAndreas Gohr include(DOKU_INC.'inc/lang/en/install.html'); 110ca64d724Schris print "</div>\n"; 11147248316SAndreas Gohr } 11247248316SAndreas Gohr ?> 113*3cd83762SDeathCamel57 <a style="background: transparent url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png) left top no-repeat; 114c8b43921SAndreas Gohr display: block; width:380px; height:73px; border:none; clear:both;" 115c8b43921SAndreas Gohr target="_blank" 116c8b43921SAndreas Gohr href="http://www.dokuwiki.org/security#web_access_security"></a> 11747248316SAndreas Gohr </div> 11847248316SAndreas Gohr 11947248316SAndreas Gohr <div style="float: left; width: 58%;"> 12047248316SAndreas Gohr <?php 12147248316SAndreas Gohr if(! (check_functions() && check_permissions()) ){ 12247248316SAndreas Gohr echo '<p>'.$lang['i_problems'].'</p>'; 12347248316SAndreas Gohr print_errors(); 12470a6aa16Schris print_retry(); 12547248316SAndreas Gohr }elseif(!check_configs()){ 12647248316SAndreas Gohr echo '<p>'.$lang['i_modified'].'</p>'; 12747248316SAndreas Gohr print_errors(); 1284b530faaSTom N Harris }elseif(check_data($_REQUEST['d'])){ 1294b530faaSTom N Harris // check_data has sanitized all input parameters 1304b530faaSTom N Harris if(!store_data($_REQUEST['d'])){ 13147248316SAndreas Gohr echo '<p>'.$lang['i_failure'].'</p>'; 13247248316SAndreas Gohr print_errors(); 13347248316SAndreas Gohr }else{ 13447248316SAndreas Gohr echo '<p>'.$lang['i_success'].'</p>'; 13547248316SAndreas Gohr } 13647248316SAndreas Gohr }else{ 1374b530faaSTom N Harris print_errors(); 13847248316SAndreas Gohr print_form($_REQUEST['d']); 13947248316SAndreas Gohr } 14047248316SAndreas Gohr ?> 14147248316SAndreas Gohr </div> 14247248316SAndreas Gohr 143c8b43921SAndreas Gohr 14447248316SAndreas Gohr<div style="clear: both"> 145654436fbSAnika Henke <a href="http://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki" /></a> 14659752844SAnders Sandblad <a href="http://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP" /></a> 14747248316SAndreas Gohr</div> 14847248316SAndreas Gohr</body> 14947248316SAndreas Gohr</html> 15047248316SAndreas Gohr<?php 15147248316SAndreas Gohr 15247248316SAndreas Gohr/** 15347248316SAndreas Gohr * Print the input form 154253d4b48SGerrit Uitslag * 155253d4b48SGerrit Uitslag * @param array $d submitted entry 'd' of request data 15647248316SAndreas Gohr */ 15747248316SAndreas Gohrfunction print_form($d){ 15847248316SAndreas Gohr global $lang; 15947248316SAndreas Gohr global $LC; 16047248316SAndreas Gohr 16106361442SAndreas Gohr include(DOKU_CONF.'license.php'); 16206361442SAndreas Gohr 16347248316SAndreas Gohr if(!is_array($d)) $d = array(); 16465cc1598SPhy $d = array_map('hsc',$d); 16547248316SAndreas Gohr 16647248316SAndreas Gohr if(!isset($d['acl'])) $d['acl']=1; 1673a0852d9SAndreas Gohr if(!isset($d['pop'])) $d['pop']=1; 16847248316SAndreas Gohr 16947248316SAndreas Gohr ?> 17047248316SAndreas Gohr <form action="" method="post"> 17147248316SAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>" /> 17247248316SAndreas Gohr <fieldset> 17347248316SAndreas Gohr <label for="title"><?php echo $lang['i_wikiname']?> 17447248316SAndreas Gohr <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" /> 17547248316SAndreas Gohr </label> 17647248316SAndreas Gohr 17747248316SAndreas Gohr <fieldset style="margin-top: 1em;"> 17847248316SAndreas Gohr <label for="acl"> 17947248316SAndreas Gohr <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : ''));?> /> 18047248316SAndreas Gohr <?php echo $lang['i_enableacl']?></label> 18147248316SAndreas Gohr 18247248316SAndreas Gohr <fieldset id="acldep"> 18347248316SAndreas Gohr <label for="superuser"><?php echo $lang['i_superuser']?></label> 18447248316SAndreas Gohr <input class="text" type="text" name="d[superuser]" id="superuser" value="<?php echo $d['superuser'] ?>" /> 18547248316SAndreas Gohr 18647248316SAndreas Gohr <label for="fullname"><?php echo $lang['fullname']?></label> 18747248316SAndreas Gohr <input class="text" type="text" name="d[fullname]" id="fullname" value="<?php echo $d['fullname'] ?>" /> 18847248316SAndreas Gohr 18947248316SAndreas Gohr <label for="email"><?php echo $lang['email']?></label> 19047248316SAndreas Gohr <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" /> 19147248316SAndreas Gohr 19247248316SAndreas Gohr <label for="password"><?php echo $lang['pass']?></label> 19347248316SAndreas Gohr <input class="text" type="password" name="d[password]" id="password" /> 19447248316SAndreas Gohr 19547248316SAndreas Gohr <label for="confirm"><?php echo $lang['passchk']?></label> 19647248316SAndreas Gohr <input class="text" type="password" name="d[confirm]" id="confirm" /> 1978af2e4bbSAndreas Gohr 1988af2e4bbSAndreas Gohr <label for="policy"><?php echo $lang['i_policy']?></label> 1998af2e4bbSAndreas Gohr <select class="text" name="d[policy]" id="policy"> 2008af2e4bbSAndreas Gohr <option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php echo $lang['i_pol0']?></option> 2018af2e4bbSAndreas Gohr <option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php echo $lang['i_pol1']?></option> 2028af2e4bbSAndreas Gohr <option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php echo $lang['i_pol2']?></option> 2038af2e4bbSAndreas Gohr </select> 20406361442SAndreas Gohr 205ab9346edSAnika Henke <label for="allowreg"> 206ab9346edSAnika Henke <input type="checkbox" name="d[allowreg]" id="allowreg" <?php echo(($d['allowreg'] ? ' checked="checked"' : ''));?> /> 207ab9346edSAnika Henke <?php echo $lang['i_allowreg']?> 20874850f29SAnika Henke </label> 20947248316SAndreas Gohr </fieldset> 21047248316SAndreas Gohr </fieldset> 21147248316SAndreas Gohr 21206361442SAndreas Gohr <fieldset> 21306361442SAndreas Gohr <p><?php echo $lang['i_license']?></p> 21406361442SAndreas Gohr <?php 215b1730bd2STom N Harris array_push($license,array('name' => $lang['i_license_none'], 'url'=>'')); 216ed856534STom N Harris if(empty($d['license'])) $d['license'] = 'cc-by-sa'; 21706361442SAndreas Gohr foreach($license as $key => $lic){ 21806361442SAndreas Gohr echo '<label for="lic_'.$key.'">'; 21965cc1598SPhy echo '<input type="radio" name="d[license]" value="'.hsc($key).'" id="lic_'.$key.'"'. 220b1730bd2STom N Harris (($d['license'] === $key)?' checked="checked"':'').'>'; 22165cc1598SPhy echo hsc($lic['name']); 22206361442SAndreas Gohr if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>'; 22306361442SAndreas Gohr echo '</label>'; 22406361442SAndreas Gohr } 22506361442SAndreas Gohr ?> 22606361442SAndreas Gohr </fieldset> 22706361442SAndreas Gohr 2283a0852d9SAndreas Gohr <fieldset> 2293a0852d9SAndreas Gohr <p><?php echo $lang['i_pop_field']?></p> 2303a0852d9SAndreas Gohr <label for="pop"> 2313a0852d9SAndreas Gohr <input type="checkbox" name="d[pop]" id="pop" <?php echo(($d['pop'] ? ' checked="checked"' : ''));?> /> 232e93f702bSAndreas Gohr <?php echo $lang['i_pop_label']?> <a href="http://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a> 2333a0852d9SAndreas Gohr </label> 2343a0852d9SAndreas Gohr </fieldset> 2353a0852d9SAndreas Gohr 23647248316SAndreas Gohr </fieldset> 23747248316SAndreas Gohr <fieldset id="process"> 238ae614416SAnika Henke <button type="submit" name="submit"><?php echo $lang['btn_save']?></button> 23947248316SAndreas Gohr </fieldset> 24047248316SAndreas Gohr </form> 24147248316SAndreas Gohr <?php 24247248316SAndreas Gohr} 24347248316SAndreas Gohr 24470a6aa16Schrisfunction print_retry() { 24570a6aa16Schris global $lang; 2469ad6da3dSAndreas Gohr global $LC; 24770a6aa16Schris ?> 24870a6aa16Schris <form action="" method="get"> 24970a6aa16Schris <fieldset> 2509ad6da3dSAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>" /> 251ae614416SAnika Henke <button type="submit"><?php echo $lang['i_retry'];?></button> 25270a6aa16Schris </fieldset> 25370a6aa16Schris </form> 25470a6aa16Schris <?php 25570a6aa16Schris} 25670a6aa16Schris 25747248316SAndreas Gohr/** 25847248316SAndreas Gohr * Check validity of data 25947248316SAndreas Gohr * 26047248316SAndreas Gohr * @author Andreas Gohr 261253d4b48SGerrit Uitslag * 262253d4b48SGerrit Uitslag * @param array $d 263253d4b48SGerrit Uitslag * @return bool ok? 26447248316SAndreas Gohr */ 265e2386079SAndreas Gohrfunction check_data(&$d){ 2664b530faaSTom N Harris static $form_default = array( 2674b530faaSTom N Harris 'title' => '', 268ed856534STom N Harris 'acl' => '1', 2694b530faaSTom N Harris 'superuser' => '', 2704b530faaSTom N Harris 'fullname' => '', 2714b530faaSTom N Harris 'email' => '', 2724b530faaSTom N Harris 'password' => '', 2734b530faaSTom N Harris 'confirm' => '', 2744b530faaSTom N Harris 'policy' => '0', 275ab9346edSAnika Henke 'allowreg' => '0', 2764b530faaSTom N Harris 'license' => 'cc-by-sa' 2774b530faaSTom N Harris ); 27847248316SAndreas Gohr global $lang; 27947248316SAndreas Gohr global $error; 28047248316SAndreas Gohr 2814b530faaSTom N Harris if(!is_array($d)) $d = array(); 2824b530faaSTom N Harris foreach($d as $k => $v) { 2834b530faaSTom N Harris if(is_array($v)) 2844b530faaSTom N Harris unset($d[$k]); 2854b530faaSTom N Harris else 2864b530faaSTom N Harris $d[$k] = (string)$v; 2874b530faaSTom N Harris } 288e2386079SAndreas Gohr 2894b530faaSTom N Harris //autolowercase the username 2904b530faaSTom N Harris $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : ""; 2914b530faaSTom N Harris 2924b530faaSTom N Harris $ok = false; 2934b530faaSTom N Harris 2944b530faaSTom N Harris if(isset($_REQUEST['submit'])) { 29547248316SAndreas Gohr $ok = true; 29647248316SAndreas Gohr 29747248316SAndreas Gohr // check input 29847248316SAndreas Gohr if(empty($d['title'])){ 29947248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']); 30047248316SAndreas Gohr $ok = false; 30147248316SAndreas Gohr } 3024b530faaSTom N Harris if(isset($d['acl'])){ 303d60813a2SGina Haeussge if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){ 30447248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['i_superuser']); 30547248316SAndreas Gohr $ok = false; 30647248316SAndreas Gohr } 30747248316SAndreas Gohr if(empty($d['password'])){ 30847248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['pass']); 30947248316SAndreas Gohr $ok = false; 31047248316SAndreas Gohr } 3114b530faaSTom N Harris elseif(!isset($d['confirm']) || $d['confirm'] != $d['password']){ 31247248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['passchk']); 31347248316SAndreas Gohr $ok = false; 31447248316SAndreas Gohr } 31547248316SAndreas Gohr if(empty($d['fullname']) || strstr($d['fullname'],':')){ 31647248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['fullname']); 31747248316SAndreas Gohr $ok = false; 31847248316SAndreas Gohr } 319e2386079SAndreas Gohr if(empty($d['email']) || strstr($d['email'],':') || !strstr($d['email'],'@')){ 32047248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['email']); 32147248316SAndreas Gohr $ok = false; 32247248316SAndreas Gohr } 32347248316SAndreas Gohr } 3244b530faaSTom N Harris } 3254b530faaSTom N Harris $d = array_merge($form_default, $d); 32647248316SAndreas Gohr return $ok; 32747248316SAndreas Gohr} 32847248316SAndreas Gohr 32947248316SAndreas Gohr/** 33047248316SAndreas Gohr * Writes the data to the config files 33147248316SAndreas Gohr * 33247248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 333253d4b48SGerrit Uitslag * 334253d4b48SGerrit Uitslag * @param array $d 335253d4b48SGerrit Uitslag * @return bool 33647248316SAndreas Gohr */ 33747248316SAndreas Gohrfunction store_data($d){ 3380036aa89SAndreas Gohr global $LC; 33947248316SAndreas Gohr $ok = true; 3408af2e4bbSAndreas Gohr $d['policy'] = (int) $d['policy']; 34147248316SAndreas Gohr 34247248316SAndreas Gohr // create local.php 34324650a19SAndreas Gohr $now = gmdate('r'); 34447248316SAndreas Gohr $output = <<<EOT 34547248316SAndreas Gohr<?php 34647248316SAndreas Gohr/** 34747248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings 34847248316SAndreas Gohr * Auto-generated by install script 34947248316SAndreas Gohr * Date: $now 35047248316SAndreas Gohr */ 35147248316SAndreas Gohr 35247248316SAndreas GohrEOT; 3532613efa1SAndreas Gohr // add any config options set by a previous installer 3542613efa1SAndreas Gohr $preset = __DIR__.'/install.conf'; 3552613efa1SAndreas Gohr if(file_exists($preset)){ 3562613efa1SAndreas Gohr $output .= "# preset config options\n"; 3572613efa1SAndreas Gohr $output .= file_get_contents($preset); 3582613efa1SAndreas Gohr $output .= "\n\n"; 3592613efa1SAndreas Gohr $output .= "# options selected in installer\n"; 3602613efa1SAndreas Gohr @unlink($preset); 3612613efa1SAndreas Gohr } 3622613efa1SAndreas Gohr 36347248316SAndreas Gohr $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n"; 3640036aa89SAndreas Gohr $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n"; 36506361442SAndreas Gohr $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n"; 36647248316SAndreas Gohr if($d['acl']){ 36747248316SAndreas Gohr $output .= '$conf[\'useacl\'] = 1'.";\n"; 368523d7ea6Schris $output .= "\$conf['superuser'] = '@admin';\n"; 36947248316SAndreas Gohr } 370ab9346edSAnika Henke if(!$d['allowreg']){ 37143c137edSAnika Henke $output .= '$conf[\'disableactions\'] = \'register\''.";\n"; 372d2ea6dc1SAnika Henke } 37347248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output); 37447248316SAndreas Gohr 37547248316SAndreas Gohr if ($d['acl']) { 3763791b589SAndreas Gohr // hash the password 3773791b589SAndreas Gohr $phash = new PassHash(); 3783791b589SAndreas Gohr $pass = $phash->hash_smd5($d['password']); 3793791b589SAndreas Gohr 38047248316SAndreas Gohr // create users.auth.php 3813791b589SAndreas Gohr // --- user:SMD5password:Real Name:email:groups,comma,seperated 382d2ea6dc1SAnika Henke $output = join(":",array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user')); 38347248316SAndreas Gohr $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n"; 38447248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output); 38547248316SAndreas Gohr 38647248316SAndreas Gohr // create acl.auth.php 3878af2e4bbSAndreas Gohr $output = <<<EOT 3888af2e4bbSAndreas Gohr# acl.auth.php 3898af2e4bbSAndreas Gohr# <?php exit()?> 3908af2e4bbSAndreas Gohr# Don't modify the lines above 3918af2e4bbSAndreas Gohr# 3928af2e4bbSAndreas Gohr# Access Control Lists 3938af2e4bbSAndreas Gohr# 3948af2e4bbSAndreas Gohr# Auto-generated by install script 3958af2e4bbSAndreas Gohr# Date: $now 3968af2e4bbSAndreas Gohr 3978af2e4bbSAndreas GohrEOT; 3988af2e4bbSAndreas Gohr if($d['policy'] == 2){ 3998af2e4bbSAndreas Gohr $output .= "* @ALL 0\n"; 400d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4019c70688aSchris }elseif($d['policy'] == 1){ 4028af2e4bbSAndreas Gohr $output .= "* @ALL 1\n"; 403d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4048af2e4bbSAndreas Gohr }else{ 4058af2e4bbSAndreas Gohr $output .= "* @ALL 8\n"; 4068af2e4bbSAndreas Gohr } 40747248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output); 40847248316SAndreas Gohr } 4093a0852d9SAndreas Gohr 4103a0852d9SAndreas Gohr // enable popularity submission 4113a0852d9SAndreas Gohr if($d['pop']){ 4123a0852d9SAndreas Gohr @touch(DOKU_INC.'data/cache/autosubmit.txt'); 4133a0852d9SAndreas Gohr } 4143a0852d9SAndreas Gohr 415c70d6ceeSAndreas Gohr // disable auth plugins til needed 416c70d6ceeSAndreas Gohr $output = <<<EOT 417c70d6ceeSAndreas Gohr<?php 418c70d6ceeSAndreas Gohr/* 419c70d6ceeSAndreas Gohr * Local plugin enable/disable settings 420c70d6ceeSAndreas Gohr * 421c70d6ceeSAndreas Gohr * Auto-generated by install script 422c70d6ceeSAndreas Gohr * Date: $now 423c70d6ceeSAndreas Gohr */ 424c70d6ceeSAndreas Gohr 425c70d6ceeSAndreas Gohr\$plugins['authad'] = 0; 426c70d6ceeSAndreas Gohr\$plugins['authldap'] = 0; 427c70d6ceeSAndreas Gohr\$plugins['authmysql'] = 0; 428c70d6ceeSAndreas Gohr\$plugins['authpgsql'] = 0; 429c70d6ceeSAndreas Gohr 430c70d6ceeSAndreas GohrEOT; 431c70d6ceeSAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL.'plugins.local.php', $output); 432c70d6ceeSAndreas Gohr 43347248316SAndreas Gohr return $ok; 43447248316SAndreas Gohr} 43547248316SAndreas Gohr 43647248316SAndreas Gohr/** 43747248316SAndreas Gohr * Write the given content to a file 43847248316SAndreas Gohr * 43947248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 440253d4b48SGerrit Uitslag * 441253d4b48SGerrit Uitslag * @param string $filename 442253d4b48SGerrit Uitslag * @param string $data 443253d4b48SGerrit Uitslag * @return bool 44447248316SAndreas Gohr */ 44547248316SAndreas Gohrfunction fileWrite($filename, $data) { 44647248316SAndreas Gohr global $error; 44747248316SAndreas Gohr global $lang; 44847248316SAndreas Gohr 44947248316SAndreas Gohr if (($fp = @fopen($filename, 'wb')) === false) { 45047248316SAndreas Gohr $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename); 45147248316SAndreas Gohr $error[] = sprintf($lang['i_writeerr'],$filename); 45247248316SAndreas Gohr return false; 45347248316SAndreas Gohr } 45447248316SAndreas Gohr 45547248316SAndreas Gohr if (!empty($data)) { fwrite($fp, $data); } 45647248316SAndreas Gohr fclose($fp); 45747248316SAndreas Gohr return true; 45847248316SAndreas Gohr} 45947248316SAndreas Gohr 46047248316SAndreas Gohr 46147248316SAndreas Gohr/** 46247248316SAndreas Gohr * check installation dependent local config files and tests for a known 46347248316SAndreas Gohr * unmodified main config file 46447248316SAndreas Gohr * 46547248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 466253d4b48SGerrit Uitslag * 467253d4b48SGerrit Uitslag * @return bool 46847248316SAndreas Gohr */ 46947248316SAndreas Gohrfunction check_configs(){ 47047248316SAndreas Gohr global $error; 47147248316SAndreas Gohr global $lang; 47247248316SAndreas Gohr global $dokuwiki_hash; 47347248316SAndreas Gohr 47447248316SAndreas Gohr $ok = true; 47547248316SAndreas Gohr 4765cfb8815Schris $config_files = array( 4775cfb8815Schris 'local' => DOKU_LOCAL.'local.php', 4785cfb8815Schris 'users' => DOKU_LOCAL.'users.auth.php', 4795cfb8815Schris 'auth' => DOKU_LOCAL.'acl.auth.php' 4805cfb8815Schris ); 4815cfb8815Schris 4825cfb8815Schris // main dokuwiki config file (conf/dokuwiki.php) must not have been modified 483aa248fb5SAndreas Gohr $installation_hash = md5(preg_replace("/(\015\012)|(\015)/","\012", 484aa248fb5SAndreas Gohr @file_get_contents(DOKU_CONF.'dokuwiki.php'))); 4855cfb8815Schris if (!in_array($installation_hash, $dokuwiki_hash)) { 48647248316SAndreas Gohr $error[] = sprintf($lang['i_badhash'],$installation_hash); 48747248316SAndreas Gohr $ok = false; 4885cfb8815Schris } 4895cfb8815Schris 49047248316SAndreas Gohr // configs shouldn't exist 49147248316SAndreas Gohr foreach ($config_files as $file) { 49279e79377SAndreas Gohr if (file_exists($file) && filesize($file)) { 49347248316SAndreas Gohr $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file); 49447248316SAndreas Gohr $error[] = sprintf($lang['i_confexists'],$file); 49547248316SAndreas Gohr $ok = false; 49647248316SAndreas Gohr } 49747248316SAndreas Gohr } 49847248316SAndreas Gohr return $ok; 49947248316SAndreas Gohr} 50047248316SAndreas Gohr 50147248316SAndreas Gohr 50247248316SAndreas Gohr/** 50347248316SAndreas Gohr * Check other installation dir/file permission requirements 50447248316SAndreas Gohr * 50547248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 506253d4b48SGerrit Uitslag * 507253d4b48SGerrit Uitslag * @return bool 50847248316SAndreas Gohr */ 50947248316SAndreas Gohrfunction check_permissions(){ 51047248316SAndreas Gohr global $error; 51147248316SAndreas Gohr global $lang; 51247248316SAndreas Gohr 51347248316SAndreas Gohr $dirs = array( 51447248316SAndreas Gohr 'conf' => DOKU_LOCAL, 51547248316SAndreas Gohr 'data' => DOKU_INC.'data', 51647248316SAndreas Gohr 'pages' => DOKU_INC.'data/pages', 51747248316SAndreas Gohr 'attic' => DOKU_INC.'data/attic', 51847248316SAndreas Gohr 'media' => DOKU_INC.'data/media', 51949b78edaSAndreas Gohr 'media_attic' => DOKU_INC.'data/media_attic', 52049b78edaSAndreas Gohr 'media_meta' => DOKU_INC.'data/media_meta', 52147248316SAndreas Gohr 'meta' => DOKU_INC.'data/meta', 52247248316SAndreas Gohr 'cache' => DOKU_INC.'data/cache', 52347248316SAndreas Gohr 'locks' => DOKU_INC.'data/locks', 5249711045aSAndreas Gohr 'index' => DOKU_INC.'data/index', 525de33a58fSMichael Klier 'tmp' => DOKU_INC.'data/tmp' 52647248316SAndreas Gohr ); 52747248316SAndreas Gohr 52847248316SAndreas Gohr $ok = true; 52947248316SAndreas Gohr foreach($dirs as $dir){ 53079e79377SAndreas Gohr if(!file_exists("$dir/.") || !is_writable($dir)){ 53170a6aa16Schris $dir = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir); 53247248316SAndreas Gohr $error[] = sprintf($lang['i_permfail'],$dir); 53347248316SAndreas Gohr $ok = false; 53447248316SAndreas Gohr } 53547248316SAndreas Gohr } 53647248316SAndreas Gohr return $ok; 53747248316SAndreas Gohr} 53847248316SAndreas Gohr 53947248316SAndreas Gohr/** 5403afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version 54147248316SAndreas Gohr * 54247248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 543253d4b48SGerrit Uitslag * 544253d4b48SGerrit Uitslag * @return bool 54547248316SAndreas Gohr */ 54647248316SAndreas Gohrfunction check_functions(){ 54747248316SAndreas Gohr global $error; 54847248316SAndreas Gohr global $lang; 5493afe5d1cSAndreas Gohr $ok = true; 5503afe5d1cSAndreas Gohr 5513476bb81SAndreas Gohr if(version_compare(phpversion(),'5.6.0','<')){ 5523476bb81SAndreas Gohr $error[] = sprintf($lang['i_phpver'],phpversion(),'5.6.0'); 5533afe5d1cSAndreas Gohr $ok = false; 5543afe5d1cSAndreas Gohr } 5553afe5d1cSAndreas Gohr 5567f413440SAndreas Gohr if(ini_get('mbstring.func_overload') != 0){ 5577f413440SAndreas Gohr $error[] = $lang['i_mbfuncoverload']; 5587f413440SAndreas Gohr $ok = false; 5597f413440SAndreas Gohr } 5607f413440SAndreas Gohr 5613009a773SAndreas Gohr $funcs = explode(' ','addslashes call_user_func chmod copy fgets '. 56247248316SAndreas Gohr 'file file_exists fseek flush filesize ftell fopen '. 56347248316SAndreas Gohr 'glob header ignore_user_abort ini_get mail mkdir '. 56447248316SAndreas Gohr 'ob_start opendir parse_ini_file readfile realpath '. 565bab4a8bdSAndreas Gohr 'rename rmdir serialize session_start unlink usleep '. 566d1d99bb9SAndreas Gohr 'preg_replace file_get_contents htmlspecialchars_decode '. 567ab38a322Slupo49 'spl_autoload_register stream_select fsockopen pack'); 56847248316SAndreas Gohr 56970a6aa16Schris if (!function_exists('mb_substr')) { 57070a6aa16Schris $funcs[] = 'utf8_encode'; 57170a6aa16Schris $funcs[] = 'utf8_decode'; 57270a6aa16Schris } 57370a6aa16Schris 57447248316SAndreas Gohr foreach($funcs as $func){ 57547248316SAndreas Gohr if(!function_exists($func)){ 57647248316SAndreas Gohr $error[] = sprintf($lang['i_funcna'],$func); 57747248316SAndreas Gohr $ok = false; 57847248316SAndreas Gohr } 57947248316SAndreas Gohr } 58047248316SAndreas Gohr return $ok; 58147248316SAndreas Gohr} 58247248316SAndreas Gohr 58347248316SAndreas Gohr/** 58447248316SAndreas Gohr * Print language selection 58547248316SAndreas Gohr * 58647248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 58747248316SAndreas Gohr */ 58847248316SAndreas Gohrfunction langsel(){ 58947248316SAndreas Gohr global $lang; 59047248316SAndreas Gohr global $LC; 59147248316SAndreas Gohr 59247248316SAndreas Gohr $dir = DOKU_INC.'inc/lang'; 59347248316SAndreas Gohr $dh = opendir($dir); 59447248316SAndreas Gohr if(!$dh) return; 59547248316SAndreas Gohr 59647248316SAndreas Gohr $langs = array(); 59747248316SAndreas Gohr while (($file = readdir($dh)) !== false) { 59847248316SAndreas Gohr if(preg_match('/^[\._]/',$file)) continue; 59979e79377SAndreas Gohr if(is_dir($dir.'/'.$file) && file_exists($dir.'/'.$file.'/lang.php')){ 60047248316SAndreas Gohr $langs[] = $file; 60147248316SAndreas Gohr } 60247248316SAndreas Gohr } 60347248316SAndreas Gohr closedir($dh); 60447248316SAndreas Gohr sort($langs); 60547248316SAndreas Gohr 60647248316SAndreas Gohr echo '<form action="">'; 60747248316SAndreas Gohr echo $lang['i_chooselang']; 60847248316SAndreas Gohr echo ': <select name="l" onchange="submit()">'; 60947248316SAndreas Gohr foreach($langs as $l){ 61047248316SAndreas Gohr $sel = ($l == $LC) ? 'selected="selected"' : ''; 61147248316SAndreas Gohr echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>'; 61247248316SAndreas Gohr } 61347248316SAndreas Gohr echo '</select> '; 614ae614416SAnika Henke echo '<button type="submit">'.$lang['btn_update'].'</button>'; 61547248316SAndreas Gohr echo '</form>'; 61647248316SAndreas Gohr} 61747248316SAndreas Gohr 61847248316SAndreas Gohr/** 619c66972f2SAdrian Lang * Print global error array 62047248316SAndreas Gohr * 62147248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 62247248316SAndreas Gohr */ 62347248316SAndreas Gohrfunction print_errors(){ 62447248316SAndreas Gohr global $error; 6254b530faaSTom N Harris if(!empty($error)) { 62647248316SAndreas Gohr echo '<ul>'; 62747248316SAndreas Gohr foreach ($error as $err){ 62847248316SAndreas Gohr echo "<li>$err</li>"; 62947248316SAndreas Gohr } 63047248316SAndreas Gohr echo '</ul>'; 63147248316SAndreas Gohr } 6324b530faaSTom N Harris} 633