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 12*02bca5d4SYousong Zhou// load and initialize the core system 13*02bca5d4SYousong 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// kill magic quotes 2047248316SAndreas Gohrif (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) { 2147248316SAndreas Gohr if (!empty($_GET)) remove_magic_quotes($_GET); 2247248316SAndreas Gohr if (!empty($_POST)) remove_magic_quotes($_POST); 2347248316SAndreas Gohr if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE); 2447248316SAndreas Gohr if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST); 2547248316SAndreas Gohr @ini_set('magic_quotes_gpc', 0); 2647248316SAndreas Gohr define('MAGIC_QUOTES_STRIPPED',1); 2747248316SAndreas Gohr} 2814266831SMichael Hamannif (function_exists('set_magic_quotes_runtime')) @set_magic_quotes_runtime(0); 2947248316SAndreas Gohr@ini_set('magic_quotes_sybase',0); 305cfb8815Schris 3147248316SAndreas Gohr// language strings 3247248316SAndreas Gohrrequire_once(DOKU_INC.'inc/lang/en/lang.php'); 334b530faaSTom N Harrisif(isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) { 3447248316SAndreas Gohr $LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']); 354b530faaSTom N Harris} 364b530faaSTom N Harrisif(empty($LC)) $LC = 'en'; 3747248316SAndreas Gohrif($LC && $LC != 'en' ) { 3847248316SAndreas Gohr require_once(DOKU_INC.'inc/lang/'.$LC.'/lang.php'); 3947248316SAndreas Gohr} 4047248316SAndreas Gohr 4147248316SAndreas Gohr// initialise variables ... 4247248316SAndreas Gohr$error = array(); 4347248316SAndreas Gohr 4447248316SAndreas Gohr$dokuwiki_hash = array( 4547248316SAndreas Gohr '2005-09-22' => 'e33223e957b0b0a130d0520db08f8fb7', 4647248316SAndreas Gohr '2006-03-05' => '51295727f79ab9af309a2fd9e0b61acc', 4747248316SAndreas Gohr '2006-03-09' => '51295727f79ab9af309a2fd9e0b61acc', 484dde32ddSAndreas Gohr '2006-11-06' => 'b3a8af76845977c2000d85d6990dd72b', 49e7f137b2SAndreas Gohr '2007-05-24' => 'd80f2740c84c4a6a791fd3c7a353536f', 5083666c1bSAndreas Gohr '2007-06-26' => 'b3ca19c7a654823144119980be73cd77', 51dd6510bdSAndreas Gohr '2008-05-04' => '1e5c42eac3219d9e21927c39e3240aad', 52b4353e51SAndreas Gohr '2009-02-14' => 'ec8c04210732a14fdfce0f7f6eead865', 5385d9abfcSAndreas Gohr '2009-12-25' => '993c4b2b385643efe5abf8e7010e11f4', 54c991623aSAdrian Lang '2010-11-07' => '7921d48195f4db21b8ead6d9bea801b8', 555ff12737SAdrian Lang '2011-05-25' => '4241865472edb6fa14a1227721008072', 56a5a71ecfSAdrian Lang '2011-11-10' => 'b46ff19a7587966ac4df61cbab1b8b31', 575371328cSAndreas Gohr '2012-01-25' => '72c083c73608fc43c586901fd5dabb74', 58c70d6ceeSAndreas Gohr '2012-09-10' => 'eb0b3fc90056fbc12bac6f49f7764df3', 592a5a1456SGuy Brand '2013-05-10' => '7b62b75245f57f122d3e0f8ed7989623', 608c4759c9SGuy Brand '2013-12-08' => '263c76af309fbf083867c18a34ff5214', 6175930869SGuy Brand '2014-05-05' => '263c76af309fbf083867c18a34ff5214', 62c8574e7dSGuy Brand '2015-08-10' => '263c76af309fbf083867c18a34ff5214', 632f7c97b3SGuy Brand '2016-06-26' => 'fd3abb6d89853dacb032907e619fbd73', 642f7c97b3SGuy Brand '2017-02-19' => 'e4f2f5a34c9dbcd96a5ecc8f2df25bd9' 6547248316SAndreas Gohr); 6647248316SAndreas Gohr 6747248316SAndreas Gohr 6847248316SAndreas Gohr// begin output 6947248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8'); 7047248316SAndreas Gohr?> 71c8839c22SAnika Henke<!DOCTYPE html> 72c8839c22SAnika Henke<html lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>"> 7347248316SAndreas Gohr<head> 74c8839c22SAnika Henke <meta charset="utf-8" /> 754208c142SAndreas Gohr <title><?php echo $lang['i_installer']?></title> 7647248316SAndreas Gohr <style type="text/css"> 7747248316SAndreas Gohr body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; } 7847248316SAndreas Gohr img { border: none } 7947248316SAndreas Gohr br.cl { clear:both; } 8070a6aa16Schris code { font-size: 110%; color: #800000; } 8147248316SAndreas Gohr fieldset { border: none } 829c70688aSchris label { display: block; margin-top: 0.5em; } 838af2e4bbSAndreas Gohr select.text, input.text { width: 30em; margin: 0 0.5em; } 8406361442SAndreas Gohr a {text-decoration: none} 8547248316SAndreas Gohr </style> 86e260f93bSAnika Henke <script type="text/javascript"> 8747248316SAndreas Gohr function acltoggle(){ 8847248316SAndreas Gohr var cb = document.getElementById('acl'); 8947248316SAndreas Gohr var fs = document.getElementById('acldep'); 9047248316SAndreas Gohr if(!cb || !fs) return; 9147248316SAndreas Gohr if(cb.checked){ 9247248316SAndreas Gohr fs.style.display = ''; 9347248316SAndreas Gohr }else{ 9447248316SAndreas Gohr fs.style.display = 'none'; 9547248316SAndreas Gohr } 9647248316SAndreas Gohr } 9747248316SAndreas Gohr window.onload = function(){ 9847248316SAndreas Gohr acltoggle(); 9947248316SAndreas Gohr var cb = document.getElementById('acl'); 10047248316SAndreas Gohr if(cb) cb.onchange = acltoggle; 10147248316SAndreas Gohr }; 10247248316SAndreas Gohr </script> 10347248316SAndreas Gohr</head> 10447248316SAndreas Gohr<body style=""> 10547248316SAndreas Gohr <h1 style="float:left"> 106c5270434SAndreas Gohr <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png" 107c5270434SAndreas Gohr style="vertical-align: middle;" alt="" height="64" width="64" /> 10847248316SAndreas Gohr <?php echo $lang['i_installer']?> 10947248316SAndreas Gohr </h1> 11047248316SAndreas Gohr <div style="float:right; margin: 1em;"> 11147248316SAndreas Gohr <?php langsel()?> 11247248316SAndreas Gohr </div> 11347248316SAndreas Gohr <br class="cl" /> 11447248316SAndreas Gohr 11547248316SAndreas Gohr <div style="float: right; width: 34%;"> 11647248316SAndreas Gohr <?php 11779e79377SAndreas Gohr if(file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){ 11847248316SAndreas Gohr include(DOKU_INC.'inc/lang/'.$LC.'/install.html'); 11947248316SAndreas Gohr }else{ 120ca64d724Schris print "<div lang=\"en\" dir=\"ltr\">\n"; 12147248316SAndreas Gohr include(DOKU_INC.'inc/lang/en/install.html'); 122ca64d724Schris print "</div>\n"; 12347248316SAndreas Gohr } 12447248316SAndreas Gohr ?> 125c8b43921SAndreas Gohr <a style="background: transparent url(data/security.png) left top no-repeat; 126c8b43921SAndreas Gohr display: block; width:380px; height:73px; border:none; clear:both;" 127c8b43921SAndreas Gohr target="_blank" 128c8b43921SAndreas Gohr href="http://www.dokuwiki.org/security#web_access_security"></a> 12947248316SAndreas Gohr </div> 13047248316SAndreas Gohr 13147248316SAndreas Gohr <div style="float: left; width: 58%;"> 13247248316SAndreas Gohr <?php 13347248316SAndreas Gohr if(! (check_functions() && check_permissions()) ){ 13447248316SAndreas Gohr echo '<p>'.$lang['i_problems'].'</p>'; 13547248316SAndreas Gohr print_errors(); 13670a6aa16Schris print_retry(); 13747248316SAndreas Gohr }elseif(!check_configs()){ 13847248316SAndreas Gohr echo '<p>'.$lang['i_modified'].'</p>'; 13947248316SAndreas Gohr print_errors(); 1404b530faaSTom N Harris }elseif(check_data($_REQUEST['d'])){ 1414b530faaSTom N Harris // check_data has sanitized all input parameters 1424b530faaSTom N Harris if(!store_data($_REQUEST['d'])){ 14347248316SAndreas Gohr echo '<p>'.$lang['i_failure'].'</p>'; 14447248316SAndreas Gohr print_errors(); 14547248316SAndreas Gohr }else{ 14647248316SAndreas Gohr echo '<p>'.$lang['i_success'].'</p>'; 14747248316SAndreas Gohr } 14847248316SAndreas Gohr }else{ 1494b530faaSTom N Harris print_errors(); 15047248316SAndreas Gohr print_form($_REQUEST['d']); 15147248316SAndreas Gohr } 15247248316SAndreas Gohr ?> 15347248316SAndreas Gohr </div> 15447248316SAndreas Gohr 155c8b43921SAndreas Gohr 15647248316SAndreas Gohr<div style="clear: both"> 157654436fbSAnika Henke <a href="http://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki" /></a> 15859752844SAnders Sandblad <a href="http://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP" /></a> 15947248316SAndreas Gohr</div> 16047248316SAndreas Gohr</body> 16147248316SAndreas Gohr</html> 16247248316SAndreas Gohr<?php 16347248316SAndreas Gohr 16447248316SAndreas Gohr/** 16547248316SAndreas Gohr * Print the input form 166253d4b48SGerrit Uitslag * 167253d4b48SGerrit Uitslag * @param array $d submitted entry 'd' of request data 16847248316SAndreas Gohr */ 16947248316SAndreas Gohrfunction print_form($d){ 17047248316SAndreas Gohr global $lang; 17147248316SAndreas Gohr global $LC; 17247248316SAndreas Gohr 17306361442SAndreas Gohr include(DOKU_CONF.'license.php'); 17406361442SAndreas Gohr 17547248316SAndreas Gohr if(!is_array($d)) $d = array(); 17647248316SAndreas Gohr $d = array_map('htmlspecialchars',$d); 17747248316SAndreas Gohr 17847248316SAndreas Gohr if(!isset($d['acl'])) $d['acl']=1; 1793a0852d9SAndreas Gohr if(!isset($d['pop'])) $d['pop']=1; 18047248316SAndreas Gohr 18147248316SAndreas Gohr ?> 18247248316SAndreas Gohr <form action="" method="post"> 18347248316SAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>" /> 18447248316SAndreas Gohr <fieldset> 18547248316SAndreas Gohr <label for="title"><?php echo $lang['i_wikiname']?> 18647248316SAndreas Gohr <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" /> 18747248316SAndreas Gohr </label> 18847248316SAndreas Gohr 18947248316SAndreas Gohr <fieldset style="margin-top: 1em;"> 19047248316SAndreas Gohr <label for="acl"> 19147248316SAndreas Gohr <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : ''));?> /> 19247248316SAndreas Gohr <?php echo $lang['i_enableacl']?></label> 19347248316SAndreas Gohr 19447248316SAndreas Gohr <fieldset id="acldep"> 19547248316SAndreas Gohr <label for="superuser"><?php echo $lang['i_superuser']?></label> 19647248316SAndreas Gohr <input class="text" type="text" name="d[superuser]" id="superuser" value="<?php echo $d['superuser'] ?>" /> 19747248316SAndreas Gohr 19847248316SAndreas Gohr <label for="fullname"><?php echo $lang['fullname']?></label> 19947248316SAndreas Gohr <input class="text" type="text" name="d[fullname]" id="fullname" value="<?php echo $d['fullname'] ?>" /> 20047248316SAndreas Gohr 20147248316SAndreas Gohr <label for="email"><?php echo $lang['email']?></label> 20247248316SAndreas Gohr <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" /> 20347248316SAndreas Gohr 20447248316SAndreas Gohr <label for="password"><?php echo $lang['pass']?></label> 20547248316SAndreas Gohr <input class="text" type="password" name="d[password]" id="password" /> 20647248316SAndreas Gohr 20747248316SAndreas Gohr <label for="confirm"><?php echo $lang['passchk']?></label> 20847248316SAndreas Gohr <input class="text" type="password" name="d[confirm]" id="confirm" /> 2098af2e4bbSAndreas Gohr 2108af2e4bbSAndreas Gohr <label for="policy"><?php echo $lang['i_policy']?></label> 2118af2e4bbSAndreas Gohr <select class="text" name="d[policy]" id="policy"> 2128af2e4bbSAndreas Gohr <option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php echo $lang['i_pol0']?></option> 2138af2e4bbSAndreas Gohr <option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php echo $lang['i_pol1']?></option> 2148af2e4bbSAndreas Gohr <option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php echo $lang['i_pol2']?></option> 2158af2e4bbSAndreas Gohr </select> 21606361442SAndreas Gohr 217ab9346edSAnika Henke <label for="allowreg"> 218ab9346edSAnika Henke <input type="checkbox" name="d[allowreg]" id="allowreg" <?php echo(($d['allowreg'] ? ' checked="checked"' : ''));?> /> 219ab9346edSAnika Henke <?php echo $lang['i_allowreg']?> 22074850f29SAnika Henke </label> 22147248316SAndreas Gohr </fieldset> 22247248316SAndreas Gohr </fieldset> 22347248316SAndreas Gohr 22406361442SAndreas Gohr <fieldset> 22506361442SAndreas Gohr <p><?php echo $lang['i_license']?></p> 22606361442SAndreas Gohr <?php 227b1730bd2STom N Harris array_push($license,array('name' => $lang['i_license_none'], 'url'=>'')); 228ed856534STom N Harris if(empty($d['license'])) $d['license'] = 'cc-by-sa'; 22906361442SAndreas Gohr foreach($license as $key => $lic){ 23006361442SAndreas Gohr echo '<label for="lic_'.$key.'">'; 23106361442SAndreas Gohr echo '<input type="radio" name="d[license]" value="'.htmlspecialchars($key).'" id="lic_'.$key.'"'. 232b1730bd2STom N Harris (($d['license'] === $key)?' checked="checked"':'').'>'; 23306361442SAndreas Gohr echo htmlspecialchars($lic['name']); 23406361442SAndreas Gohr if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>'; 23506361442SAndreas Gohr echo '</label>'; 23606361442SAndreas Gohr } 23706361442SAndreas Gohr ?> 23806361442SAndreas Gohr </fieldset> 23906361442SAndreas Gohr 2403a0852d9SAndreas Gohr <fieldset> 2413a0852d9SAndreas Gohr <p><?php echo $lang['i_pop_field']?></p> 2423a0852d9SAndreas Gohr <label for="pop"> 2433a0852d9SAndreas Gohr <input type="checkbox" name="d[pop]" id="pop" <?php echo(($d['pop'] ? ' checked="checked"' : ''));?> /> 244e93f702bSAndreas Gohr <?php echo $lang['i_pop_label']?> <a href="http://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a> 2453a0852d9SAndreas Gohr </label> 2463a0852d9SAndreas Gohr </fieldset> 2473a0852d9SAndreas Gohr 24847248316SAndreas Gohr </fieldset> 24947248316SAndreas Gohr <fieldset id="process"> 250ae614416SAnika Henke <button type="submit" name="submit"><?php echo $lang['btn_save']?></button> 25147248316SAndreas Gohr </fieldset> 25247248316SAndreas Gohr </form> 25347248316SAndreas Gohr <?php 25447248316SAndreas Gohr} 25547248316SAndreas Gohr 25670a6aa16Schrisfunction print_retry() { 25770a6aa16Schris global $lang; 2589ad6da3dSAndreas Gohr global $LC; 25970a6aa16Schris ?> 26070a6aa16Schris <form action="" method="get"> 26170a6aa16Schris <fieldset> 2629ad6da3dSAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>" /> 263ae614416SAnika Henke <button type="submit"><?php echo $lang['i_retry'];?></button> 26470a6aa16Schris </fieldset> 26570a6aa16Schris </form> 26670a6aa16Schris <?php 26770a6aa16Schris} 26870a6aa16Schris 26947248316SAndreas Gohr/** 27047248316SAndreas Gohr * Check validity of data 27147248316SAndreas Gohr * 27247248316SAndreas Gohr * @author Andreas Gohr 273253d4b48SGerrit Uitslag * 274253d4b48SGerrit Uitslag * @param array $d 275253d4b48SGerrit Uitslag * @return bool ok? 27647248316SAndreas Gohr */ 277e2386079SAndreas Gohrfunction check_data(&$d){ 2784b530faaSTom N Harris static $form_default = array( 2794b530faaSTom N Harris 'title' => '', 280ed856534STom N Harris 'acl' => '1', 2814b530faaSTom N Harris 'superuser' => '', 2824b530faaSTom N Harris 'fullname' => '', 2834b530faaSTom N Harris 'email' => '', 2844b530faaSTom N Harris 'password' => '', 2854b530faaSTom N Harris 'confirm' => '', 2864b530faaSTom N Harris 'policy' => '0', 287ab9346edSAnika Henke 'allowreg' => '0', 2884b530faaSTom N Harris 'license' => 'cc-by-sa' 2894b530faaSTom N Harris ); 29047248316SAndreas Gohr global $lang; 29147248316SAndreas Gohr global $error; 29247248316SAndreas Gohr 2934b530faaSTom N Harris if(!is_array($d)) $d = array(); 2944b530faaSTom N Harris foreach($d as $k => $v) { 2954b530faaSTom N Harris if(is_array($v)) 2964b530faaSTom N Harris unset($d[$k]); 2974b530faaSTom N Harris else 2984b530faaSTom N Harris $d[$k] = (string)$v; 2994b530faaSTom N Harris } 300e2386079SAndreas Gohr 3014b530faaSTom N Harris //autolowercase the username 3024b530faaSTom N Harris $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : ""; 3034b530faaSTom N Harris 3044b530faaSTom N Harris $ok = false; 3054b530faaSTom N Harris 3064b530faaSTom N Harris if(isset($_REQUEST['submit'])) { 30747248316SAndreas Gohr $ok = true; 30847248316SAndreas Gohr 30947248316SAndreas Gohr // check input 31047248316SAndreas Gohr if(empty($d['title'])){ 31147248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']); 31247248316SAndreas Gohr $ok = false; 31347248316SAndreas Gohr } 3144b530faaSTom N Harris if(isset($d['acl'])){ 315d60813a2SGina Haeussge if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){ 31647248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['i_superuser']); 31747248316SAndreas Gohr $ok = false; 31847248316SAndreas Gohr } 31947248316SAndreas Gohr if(empty($d['password'])){ 32047248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['pass']); 32147248316SAndreas Gohr $ok = false; 32247248316SAndreas Gohr } 3234b530faaSTom N Harris elseif(!isset($d['confirm']) || $d['confirm'] != $d['password']){ 32447248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['passchk']); 32547248316SAndreas Gohr $ok = false; 32647248316SAndreas Gohr } 32747248316SAndreas Gohr if(empty($d['fullname']) || strstr($d['fullname'],':')){ 32847248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['fullname']); 32947248316SAndreas Gohr $ok = false; 33047248316SAndreas Gohr } 331e2386079SAndreas Gohr if(empty($d['email']) || strstr($d['email'],':') || !strstr($d['email'],'@')){ 33247248316SAndreas Gohr $error[] = sprintf($lang['i_badval'],$lang['email']); 33347248316SAndreas Gohr $ok = false; 33447248316SAndreas Gohr } 33547248316SAndreas Gohr } 3364b530faaSTom N Harris } 3374b530faaSTom N Harris $d = array_merge($form_default, $d); 33847248316SAndreas Gohr return $ok; 33947248316SAndreas Gohr} 34047248316SAndreas Gohr 34147248316SAndreas Gohr/** 34247248316SAndreas Gohr * Writes the data to the config files 34347248316SAndreas Gohr * 34447248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 345253d4b48SGerrit Uitslag * 346253d4b48SGerrit Uitslag * @param array $d 347253d4b48SGerrit Uitslag * @return bool 34847248316SAndreas Gohr */ 34947248316SAndreas Gohrfunction store_data($d){ 3500036aa89SAndreas Gohr global $LC; 35147248316SAndreas Gohr $ok = true; 3528af2e4bbSAndreas Gohr $d['policy'] = (int) $d['policy']; 35347248316SAndreas Gohr 35447248316SAndreas Gohr // create local.php 35524650a19SAndreas Gohr $now = gmdate('r'); 35647248316SAndreas Gohr $output = <<<EOT 35747248316SAndreas Gohr<?php 35847248316SAndreas Gohr/** 35947248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings 36047248316SAndreas Gohr * Auto-generated by install script 36147248316SAndreas Gohr * Date: $now 36247248316SAndreas Gohr */ 36347248316SAndreas Gohr 36447248316SAndreas GohrEOT; 3652613efa1SAndreas Gohr // add any config options set by a previous installer 3662613efa1SAndreas Gohr $preset = __DIR__.'/install.conf'; 3672613efa1SAndreas Gohr if(file_exists($preset)){ 3682613efa1SAndreas Gohr $output .= "# preset config options\n"; 3692613efa1SAndreas Gohr $output .= file_get_contents($preset); 3702613efa1SAndreas Gohr $output .= "\n\n"; 3712613efa1SAndreas Gohr $output .= "# options selected in installer\n"; 3722613efa1SAndreas Gohr @unlink($preset); 3732613efa1SAndreas Gohr } 3742613efa1SAndreas Gohr 37547248316SAndreas Gohr $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n"; 3760036aa89SAndreas Gohr $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n"; 37706361442SAndreas Gohr $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n"; 37847248316SAndreas Gohr if($d['acl']){ 37947248316SAndreas Gohr $output .= '$conf[\'useacl\'] = 1'.";\n"; 380523d7ea6Schris $output .= "\$conf['superuser'] = '@admin';\n"; 38147248316SAndreas Gohr } 382ab9346edSAnika Henke if(!$d['allowreg']){ 38343c137edSAnika Henke $output .= '$conf[\'disableactions\'] = \'register\''.";\n"; 384d2ea6dc1SAnika Henke } 38547248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output); 38647248316SAndreas Gohr 38747248316SAndreas Gohr if ($d['acl']) { 3883791b589SAndreas Gohr // hash the password 3893791b589SAndreas Gohr $phash = new PassHash(); 3903791b589SAndreas Gohr $pass = $phash->hash_smd5($d['password']); 3913791b589SAndreas Gohr 39247248316SAndreas Gohr // create users.auth.php 3933791b589SAndreas Gohr // --- user:SMD5password:Real Name:email:groups,comma,seperated 394d2ea6dc1SAnika Henke $output = join(":",array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user')); 39547248316SAndreas Gohr $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n"; 39647248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output); 39747248316SAndreas Gohr 39847248316SAndreas Gohr // create acl.auth.php 3998af2e4bbSAndreas Gohr $output = <<<EOT 4008af2e4bbSAndreas Gohr# acl.auth.php 4018af2e4bbSAndreas Gohr# <?php exit()?> 4028af2e4bbSAndreas Gohr# Don't modify the lines above 4038af2e4bbSAndreas Gohr# 4048af2e4bbSAndreas Gohr# Access Control Lists 4058af2e4bbSAndreas Gohr# 4068af2e4bbSAndreas Gohr# Auto-generated by install script 4078af2e4bbSAndreas Gohr# Date: $now 4088af2e4bbSAndreas Gohr 4098af2e4bbSAndreas GohrEOT; 4108af2e4bbSAndreas Gohr if($d['policy'] == 2){ 4118af2e4bbSAndreas Gohr $output .= "* @ALL 0\n"; 412d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4139c70688aSchris }elseif($d['policy'] == 1){ 4148af2e4bbSAndreas Gohr $output .= "* @ALL 1\n"; 415d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4168af2e4bbSAndreas Gohr }else{ 4178af2e4bbSAndreas Gohr $output .= "* @ALL 8\n"; 4188af2e4bbSAndreas Gohr } 41947248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output); 42047248316SAndreas Gohr } 4213a0852d9SAndreas Gohr 4223a0852d9SAndreas Gohr // enable popularity submission 4233a0852d9SAndreas Gohr if($d['pop']){ 4243a0852d9SAndreas Gohr @touch(DOKU_INC.'data/cache/autosubmit.txt'); 4253a0852d9SAndreas Gohr } 4263a0852d9SAndreas Gohr 427c70d6ceeSAndreas Gohr // disable auth plugins til needed 428c70d6ceeSAndreas Gohr $output = <<<EOT 429c70d6ceeSAndreas Gohr<?php 430c70d6ceeSAndreas Gohr/* 431c70d6ceeSAndreas Gohr * Local plugin enable/disable settings 432c70d6ceeSAndreas Gohr * 433c70d6ceeSAndreas Gohr * Auto-generated by install script 434c70d6ceeSAndreas Gohr * Date: $now 435c70d6ceeSAndreas Gohr */ 436c70d6ceeSAndreas Gohr 437c70d6ceeSAndreas Gohr\$plugins['authad'] = 0; 438c70d6ceeSAndreas Gohr\$plugins['authldap'] = 0; 439c70d6ceeSAndreas Gohr\$plugins['authmysql'] = 0; 440c70d6ceeSAndreas Gohr\$plugins['authpgsql'] = 0; 441c70d6ceeSAndreas Gohr 442c70d6ceeSAndreas GohrEOT; 443c70d6ceeSAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL.'plugins.local.php', $output); 444c70d6ceeSAndreas Gohr 44547248316SAndreas Gohr return $ok; 44647248316SAndreas Gohr} 44747248316SAndreas Gohr 44847248316SAndreas Gohr/** 44947248316SAndreas Gohr * Write the given content to a file 45047248316SAndreas Gohr * 45147248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 452253d4b48SGerrit Uitslag * 453253d4b48SGerrit Uitslag * @param string $filename 454253d4b48SGerrit Uitslag * @param string $data 455253d4b48SGerrit Uitslag * @return bool 45647248316SAndreas Gohr */ 45747248316SAndreas Gohrfunction fileWrite($filename, $data) { 45847248316SAndreas Gohr global $error; 45947248316SAndreas Gohr global $lang; 46047248316SAndreas Gohr 46147248316SAndreas Gohr if (($fp = @fopen($filename, 'wb')) === false) { 46247248316SAndreas Gohr $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename); 46347248316SAndreas Gohr $error[] = sprintf($lang['i_writeerr'],$filename); 46447248316SAndreas Gohr return false; 46547248316SAndreas Gohr } 46647248316SAndreas Gohr 46747248316SAndreas Gohr if (!empty($data)) { fwrite($fp, $data); } 46847248316SAndreas Gohr fclose($fp); 46947248316SAndreas Gohr return true; 47047248316SAndreas Gohr} 47147248316SAndreas Gohr 47247248316SAndreas Gohr 47347248316SAndreas Gohr/** 47447248316SAndreas Gohr * check installation dependent local config files and tests for a known 47547248316SAndreas Gohr * unmodified main config file 47647248316SAndreas Gohr * 47747248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 478253d4b48SGerrit Uitslag * 479253d4b48SGerrit Uitslag * @return bool 48047248316SAndreas Gohr */ 48147248316SAndreas Gohrfunction check_configs(){ 48247248316SAndreas Gohr global $error; 48347248316SAndreas Gohr global $lang; 48447248316SAndreas Gohr global $dokuwiki_hash; 48547248316SAndreas Gohr 48647248316SAndreas Gohr $ok = true; 48747248316SAndreas Gohr 4885cfb8815Schris $config_files = array( 4895cfb8815Schris 'local' => DOKU_LOCAL.'local.php', 4905cfb8815Schris 'users' => DOKU_LOCAL.'users.auth.php', 4915cfb8815Schris 'auth' => DOKU_LOCAL.'acl.auth.php' 4925cfb8815Schris ); 4935cfb8815Schris 4945cfb8815Schris // main dokuwiki config file (conf/dokuwiki.php) must not have been modified 495aa248fb5SAndreas Gohr $installation_hash = md5(preg_replace("/(\015\012)|(\015)/","\012", 496aa248fb5SAndreas Gohr @file_get_contents(DOKU_CONF.'dokuwiki.php'))); 4975cfb8815Schris if (!in_array($installation_hash, $dokuwiki_hash)) { 49847248316SAndreas Gohr $error[] = sprintf($lang['i_badhash'],$installation_hash); 49947248316SAndreas Gohr $ok = false; 5005cfb8815Schris } 5015cfb8815Schris 50247248316SAndreas Gohr // configs shouldn't exist 50347248316SAndreas Gohr foreach ($config_files as $file) { 50479e79377SAndreas Gohr if (file_exists($file) && filesize($file)) { 50547248316SAndreas Gohr $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file); 50647248316SAndreas Gohr $error[] = sprintf($lang['i_confexists'],$file); 50747248316SAndreas Gohr $ok = false; 50847248316SAndreas Gohr } 50947248316SAndreas Gohr } 51047248316SAndreas Gohr return $ok; 51147248316SAndreas Gohr} 51247248316SAndreas Gohr 51347248316SAndreas Gohr 51447248316SAndreas Gohr/** 51547248316SAndreas Gohr * Check other installation dir/file permission requirements 51647248316SAndreas Gohr * 51747248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 518253d4b48SGerrit Uitslag * 519253d4b48SGerrit Uitslag * @return bool 52047248316SAndreas Gohr */ 52147248316SAndreas Gohrfunction check_permissions(){ 52247248316SAndreas Gohr global $error; 52347248316SAndreas Gohr global $lang; 52447248316SAndreas Gohr 52547248316SAndreas Gohr $dirs = array( 52647248316SAndreas Gohr 'conf' => DOKU_LOCAL, 52747248316SAndreas Gohr 'data' => DOKU_INC.'data', 52847248316SAndreas Gohr 'pages' => DOKU_INC.'data/pages', 52947248316SAndreas Gohr 'attic' => DOKU_INC.'data/attic', 53047248316SAndreas Gohr 'media' => DOKU_INC.'data/media', 53149b78edaSAndreas Gohr 'media_attic' => DOKU_INC.'data/media_attic', 53249b78edaSAndreas Gohr 'media_meta' => DOKU_INC.'data/media_meta', 53347248316SAndreas Gohr 'meta' => DOKU_INC.'data/meta', 53447248316SAndreas Gohr 'cache' => DOKU_INC.'data/cache', 53547248316SAndreas Gohr 'locks' => DOKU_INC.'data/locks', 5369711045aSAndreas Gohr 'index' => DOKU_INC.'data/index', 537de33a58fSMichael Klier 'tmp' => DOKU_INC.'data/tmp' 53847248316SAndreas Gohr ); 53947248316SAndreas Gohr 54047248316SAndreas Gohr $ok = true; 54147248316SAndreas Gohr foreach($dirs as $dir){ 54279e79377SAndreas Gohr if(!file_exists("$dir/.") || !is_writable($dir)){ 54370a6aa16Schris $dir = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir); 54447248316SAndreas Gohr $error[] = sprintf($lang['i_permfail'],$dir); 54547248316SAndreas Gohr $ok = false; 54647248316SAndreas Gohr } 54747248316SAndreas Gohr } 54847248316SAndreas Gohr return $ok; 54947248316SAndreas Gohr} 55047248316SAndreas Gohr 55147248316SAndreas Gohr/** 5523afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version 55347248316SAndreas Gohr * 55447248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 555253d4b48SGerrit Uitslag * 556253d4b48SGerrit Uitslag * @return bool 55747248316SAndreas Gohr */ 55847248316SAndreas Gohrfunction check_functions(){ 55947248316SAndreas Gohr global $error; 56047248316SAndreas Gohr global $lang; 5613afe5d1cSAndreas Gohr $ok = true; 5623afe5d1cSAndreas Gohr 563001d05edSAndreas Gohr if(version_compare(phpversion(),'5.3.3','<')){ 564001d05edSAndreas Gohr $error[] = sprintf($lang['i_phpver'],phpversion(),'5.3.3'); 5653afe5d1cSAndreas Gohr $ok = false; 5663afe5d1cSAndreas Gohr } 5673afe5d1cSAndreas Gohr 5687f413440SAndreas Gohr if(ini_get('mbstring.func_overload') != 0){ 5697f413440SAndreas Gohr $error[] = $lang['i_mbfuncoverload']; 5707f413440SAndreas Gohr $ok = false; 5717f413440SAndreas Gohr } 5727f413440SAndreas Gohr 5733009a773SAndreas Gohr $funcs = explode(' ','addslashes call_user_func chmod copy fgets '. 57447248316SAndreas Gohr 'file file_exists fseek flush filesize ftell fopen '. 57547248316SAndreas Gohr 'glob header ignore_user_abort ini_get mail mkdir '. 57647248316SAndreas Gohr 'ob_start opendir parse_ini_file readfile realpath '. 577bab4a8bdSAndreas Gohr 'rename rmdir serialize session_start unlink usleep '. 578d1d99bb9SAndreas Gohr 'preg_replace file_get_contents htmlspecialchars_decode '. 579ab38a322Slupo49 'spl_autoload_register stream_select fsockopen pack'); 58047248316SAndreas Gohr 58170a6aa16Schris if (!function_exists('mb_substr')) { 58270a6aa16Schris $funcs[] = 'utf8_encode'; 58370a6aa16Schris $funcs[] = 'utf8_decode'; 58470a6aa16Schris } 58570a6aa16Schris 58647248316SAndreas Gohr foreach($funcs as $func){ 58747248316SAndreas Gohr if(!function_exists($func)){ 58847248316SAndreas Gohr $error[] = sprintf($lang['i_funcna'],$func); 58947248316SAndreas Gohr $ok = false; 59047248316SAndreas Gohr } 59147248316SAndreas Gohr } 59247248316SAndreas Gohr return $ok; 59347248316SAndreas Gohr} 59447248316SAndreas Gohr 59547248316SAndreas Gohr/** 59647248316SAndreas Gohr * Print language selection 59747248316SAndreas Gohr * 59847248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 59947248316SAndreas Gohr */ 60047248316SAndreas Gohrfunction langsel(){ 60147248316SAndreas Gohr global $lang; 60247248316SAndreas Gohr global $LC; 60347248316SAndreas Gohr 60447248316SAndreas Gohr $dir = DOKU_INC.'inc/lang'; 60547248316SAndreas Gohr $dh = opendir($dir); 60647248316SAndreas Gohr if(!$dh) return; 60747248316SAndreas Gohr 60847248316SAndreas Gohr $langs = array(); 60947248316SAndreas Gohr while (($file = readdir($dh)) !== false) { 61047248316SAndreas Gohr if(preg_match('/^[\._]/',$file)) continue; 61179e79377SAndreas Gohr if(is_dir($dir.'/'.$file) && file_exists($dir.'/'.$file.'/lang.php')){ 61247248316SAndreas Gohr $langs[] = $file; 61347248316SAndreas Gohr } 61447248316SAndreas Gohr } 61547248316SAndreas Gohr closedir($dh); 61647248316SAndreas Gohr sort($langs); 61747248316SAndreas Gohr 61847248316SAndreas Gohr echo '<form action="">'; 61947248316SAndreas Gohr echo $lang['i_chooselang']; 62047248316SAndreas Gohr echo ': <select name="l" onchange="submit()">'; 62147248316SAndreas Gohr foreach($langs as $l){ 62247248316SAndreas Gohr $sel = ($l == $LC) ? 'selected="selected"' : ''; 62347248316SAndreas Gohr echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>'; 62447248316SAndreas Gohr } 62547248316SAndreas Gohr echo '</select> '; 626ae614416SAnika Henke echo '<button type="submit">'.$lang['btn_update'].'</button>'; 62747248316SAndreas Gohr echo '</form>'; 62847248316SAndreas Gohr} 62947248316SAndreas Gohr 63047248316SAndreas Gohr/** 631c66972f2SAdrian Lang * Print global error array 63247248316SAndreas Gohr * 63347248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 63447248316SAndreas Gohr */ 63547248316SAndreas Gohrfunction print_errors(){ 63647248316SAndreas Gohr global $error; 6374b530faaSTom N Harris if(!empty($error)) { 63847248316SAndreas Gohr echo '<ul>'; 63947248316SAndreas Gohr foreach ($error as $err){ 64047248316SAndreas Gohr echo "<li>$err</li>"; 64147248316SAndreas Gohr } 64247248316SAndreas Gohr echo '</ul>'; 64347248316SAndreas Gohr } 6444b530faaSTom N Harris} 645