15cfb8815Schris<?php 2db581254Sjpedryc 3ac251797SAndreas Gohr/*><div style="width:60%; margin: auto; background-color: #fcc; 4ac251797SAndreas Gohr border: 1px solid #faa; padding: 0.5em 1em;"> 5ac251797SAndreas Gohr <h1 style="font-size: 120%">No PHP Support</h1> 6ac251797SAndreas Gohr 7ac251797SAndreas Gohr It seems this server has no PHP support enabled. You will need to 8ac251797SAndreas Gohr enable PHP before you can install and run DokuWiki. Contact your hosting 9ac251797SAndreas Gohr provider if you're unsure what this means. 10ac251797SAndreas Gohr 11ac251797SAndreas Gohr</div>*/ 125cfb8815Schris/** 135cfb8815Schris * Dokuwiki installation assistance 145cfb8815Schris * 155cfb8815Schris * @author Chris Smith <chris@jalakai.co.uk> 165cfb8815Schris */ 175cfb8815Schris 18d0a27cb0SAndreas Gohrif (!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/'); 195cfb8815Schrisif (!defined('DOKU_CONF')) define('DOKU_CONF', DOKU_INC . 'conf/'); 205cfb8815Schrisif (!defined('DOKU_LOCAL')) define('DOKU_LOCAL', DOKU_INC . 'conf/'); 215cfb8815Schris 2202bca5d4SYousong Zhou// load and initialize the core system 2302bca5d4SYousong Zhourequire_once(DOKU_INC . 'inc/init.php'); 24*2cb06bbdSjpedrycrequire_once(DOKU_INC . 'inc/pageutils.php'); 253791b589SAndreas Gohr 263545b2e0Schris// check for error reporting override or set error reporting to sane values 27db581254Sjpedrycif (!defined('DOKU_E_LEVEL')) { 28db581254Sjpedryc error_reporting(E_ALL ^ E_NOTICE); 29db581254Sjpedryc} else { 30db581254Sjpedryc error_reporting(DOKU_E_LEVEL); 31db581254Sjpedryc} 323545b2e0Schris 3347248316SAndreas Gohr// language strings 3447248316SAndreas Gohrrequire_once(DOKU_INC . 'inc/lang/en/lang.php'); 354b530faaSTom N Harrisif (isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) { 3647248316SAndreas Gohr $LC = preg_replace('/[^a-z\-]+/', '', $_REQUEST['l']); 374b530faaSTom N Harris} 384b530faaSTom N Harrisif (empty($LC)) $LC = 'en'; 3947248316SAndreas Gohrif ($LC && $LC != 'en') { 4047248316SAndreas Gohr require_once(DOKU_INC . 'inc/lang/' . $LC . '/lang.php'); 4147248316SAndreas Gohr} 4247248316SAndreas Gohr 4347248316SAndreas Gohr// initialise variables ... 4447248316SAndreas Gohr$error = array(); 4547248316SAndreas Gohr 4647248316SAndreas Gohr// begin output 4747248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8'); 4847248316SAndreas Gohr?> 49c8839c22SAnika Henke<!DOCTYPE html> 50c8839c22SAnika Henke<html lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>"> 5147248316SAndreas Gohr<head> 52c8839c22SAnika Henke <meta charset="utf-8" /> 534208c142SAndreas Gohr <title><?php echo $lang['i_installer']?></title> 5459305168SPhy <style> 5547248316SAndreas Gohr body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; } 5647248316SAndreas Gohr img { border: none } 5747248316SAndreas Gohr br.cl { clear:both; } 5870a6aa16Schris code { font-size: 110%; color: #800000; } 5947248316SAndreas Gohr fieldset { border: none } 609c70688aSchris label { display: block; margin-top: 0.5em; } 618af2e4bbSAndreas Gohr select.text, input.text { width: 30em; margin: 0 0.5em; } 6206361442SAndreas Gohr a {text-decoration: none} 6347248316SAndreas Gohr </style> 6459305168SPhy <script> 6547248316SAndreas Gohr function acltoggle(){ 6647248316SAndreas Gohr var cb = document.getElementById('acl'); 6747248316SAndreas Gohr var fs = document.getElementById('acldep'); 6847248316SAndreas Gohr if(!cb || !fs) return; 6947248316SAndreas Gohr if(cb.checked){ 7047248316SAndreas Gohr fs.style.display = ''; 7147248316SAndreas Gohr }else{ 7247248316SAndreas Gohr fs.style.display = 'none'; 7347248316SAndreas Gohr } 7447248316SAndreas Gohr } 7547248316SAndreas Gohr window.onload = function(){ 7647248316SAndreas Gohr acltoggle(); 7747248316SAndreas Gohr var cb = document.getElementById('acl'); 7847248316SAndreas Gohr if(cb) cb.onchange = acltoggle; 7947248316SAndreas Gohr }; 8047248316SAndreas Gohr </script> 8147248316SAndreas Gohr</head> 8247248316SAndreas Gohr<body style=""> 8347248316SAndreas Gohr <h1 style="float:left"> 84c5270434SAndreas Gohr <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png" 85c5270434SAndreas Gohr style="vertical-align: middle;" alt="" height="64" width="64" /> 8647248316SAndreas Gohr <?php echo $lang['i_installer']?> 8747248316SAndreas Gohr </h1> 8847248316SAndreas Gohr <div style="float:right; margin: 1em;"> 8947248316SAndreas Gohr <?php langsel()?> 9047248316SAndreas Gohr </div> 9147248316SAndreas Gohr <br class="cl" /> 9247248316SAndreas Gohr 9347248316SAndreas Gohr <div style="float: right; width: 34%;"> 9447248316SAndreas Gohr <?php 9579e79377SAndreas Gohr if (file_exists(DOKU_INC . 'inc/lang/' . $LC . '/install.html')) { 9647248316SAndreas Gohr include(DOKU_INC . 'inc/lang/' . $LC . '/install.html'); 9747248316SAndreas Gohr } else { 98ca64d724Schris print "<div lang=\"en\" dir=\"ltr\">\n"; 9947248316SAndreas Gohr include(DOKU_INC . 'inc/lang/en/install.html'); 100ca64d724Schris print "</div>\n"; 10147248316SAndreas Gohr } 10247248316SAndreas Gohr ?> 10364159a61SAndreas Gohr <a style=" 10464159a61SAndreas Gohr background: transparent 10564159a61SAndreas Gohr url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png) 10664159a61SAndreas Gohr left top no-repeat; 107c8b43921SAndreas Gohr display: block; width:380px; height:73px; border:none; clear:both;" 108c8b43921SAndreas Gohr target="_blank" 109c8b43921SAndreas Gohr href="http://www.dokuwiki.org/security#web_access_security"></a> 11047248316SAndreas Gohr </div> 11147248316SAndreas Gohr 11247248316SAndreas Gohr <div style="float: left; width: 58%;"> 11347248316SAndreas Gohr <?php 1147ac1baa0SL. Ivanovich Harrison try { 11547248316SAndreas Gohr if (! (check_functions() && check_permissions())) { 11647248316SAndreas Gohr echo '<p>' . $lang['i_problems'] . '</p>'; 11747248316SAndreas Gohr print_errors(); 11870a6aa16Schris print_retry(); 11947248316SAndreas Gohr } elseif (!check_configs()) { 12047248316SAndreas Gohr echo '<p>' . $lang['i_modified'] . '</p>'; 12147248316SAndreas Gohr print_errors(); 1224b530faaSTom N Harris } elseif (check_data($_REQUEST['d'])) { 1234b530faaSTom N Harris // check_data has sanitized all input parameters 1244b530faaSTom N Harris if (!store_data($_REQUEST['d'])) { 12547248316SAndreas Gohr echo '<p>' . $lang['i_failure'] . '</p>'; 12647248316SAndreas Gohr print_errors(); 12747248316SAndreas Gohr } else { 12847248316SAndreas Gohr echo '<p>' . $lang['i_success'] . '</p>'; 12947248316SAndreas Gohr } 13047248316SAndreas Gohr } else { 1314b530faaSTom N Harris print_errors(); 13247248316SAndreas Gohr print_form($_REQUEST['d']); 13347248316SAndreas Gohr } 1347ac1baa0SL. Ivanovich Harrison } catch (Exception $e) { 1357ac1baa0SL. Ivanovich Harrison echo 'Caught exception: ', $e->getMessage(), "\n"; 1367ac1baa0SL. Ivanovich Harrison } 13747248316SAndreas Gohr ?> 13847248316SAndreas Gohr </div> 13947248316SAndreas Gohr 140c8b43921SAndreas Gohr 14147248316SAndreas Gohr<div style="clear: both"> 142654436fbSAnika Henke <a href="http://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki" /></a> 14359752844SAnders Sandblad <a href="http://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP" /></a> 14447248316SAndreas Gohr</div> 14547248316SAndreas Gohr</body> 14647248316SAndreas Gohr</html> 14747248316SAndreas Gohr<?php 14847248316SAndreas Gohr 14947248316SAndreas Gohr/** 15047248316SAndreas Gohr * Print the input form 151253d4b48SGerrit Uitslag * 152253d4b48SGerrit Uitslag * @param array $d submitted entry 'd' of request data 15347248316SAndreas Gohr */ 154db581254Sjpedrycfunction print_form($d) 155db581254Sjpedryc{ 15647248316SAndreas Gohr global $lang; 15747248316SAndreas Gohr global $LC; 15847248316SAndreas Gohr 15906361442SAndreas Gohr include(DOKU_CONF . 'license.php'); 16006361442SAndreas Gohr 16147248316SAndreas Gohr if (!is_array($d)) $d = array(); 16265cc1598SPhy $d = array_map('hsc', $d); 16347248316SAndreas Gohr 16447248316SAndreas Gohr if (!isset($d['acl'])) $d['acl'] = 1; 1653a0852d9SAndreas Gohr if (!isset($d['pop'])) $d['pop'] = 1; 16647248316SAndreas Gohr 16747248316SAndreas Gohr ?> 16847248316SAndreas Gohr <form action="" method="post"> 16947248316SAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>" /> 17047248316SAndreas Gohr <fieldset> 17147248316SAndreas Gohr <label for="title"><?php echo $lang['i_wikiname']?> 17247248316SAndreas Gohr <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" /> 17347248316SAndreas Gohr </label> 17447248316SAndreas Gohr 17547248316SAndreas Gohr <fieldset style="margin-top: 1em;"> 17647248316SAndreas Gohr <label for="acl"> 17747248316SAndreas Gohr <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : ''));?> /> 17847248316SAndreas Gohr <?php echo $lang['i_enableacl']?></label> 17947248316SAndreas Gohr 18047248316SAndreas Gohr <fieldset id="acldep"> 18147248316SAndreas Gohr <label for="superuser"><?php echo $lang['i_superuser']?></label> 18264159a61SAndreas Gohr <input class="text" type="text" name="d[superuser]" id="superuser" 18364159a61SAndreas Gohr value="<?php echo $d['superuser'] ?>" /> 18447248316SAndreas Gohr 18547248316SAndreas Gohr <label for="fullname"><?php echo $lang['fullname']?></label> 18664159a61SAndreas Gohr <input class="text" type="text" name="d[fullname]" id="fullname" 18764159a61SAndreas Gohr 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"> 20064159a61SAndreas Gohr <option value="0" <?php echo ($d['policy'] == 0) ? 'selected="selected"' : '' ?>><?php 20164159a61SAndreas Gohr echo $lang['i_pol0']?></option> 20264159a61SAndreas Gohr <option value="1" <?php echo ($d['policy'] == 1) ? 'selected="selected"' : '' ?>><?php 20364159a61SAndreas Gohr echo $lang['i_pol1']?></option> 20464159a61SAndreas Gohr <option value="2" <?php echo ($d['policy'] == 2) ? 'selected="selected"' : '' ?>><?php 20564159a61SAndreas Gohr echo $lang['i_pol2']?></option> 2068af2e4bbSAndreas Gohr </select> 20706361442SAndreas Gohr 208ab9346edSAnika Henke <label for="allowreg"> 20964159a61SAndreas Gohr <input type="checkbox" name="d[allowreg]" id="allowreg" <?php 21064159a61SAndreas Gohr echo(($d['allowreg'] ? ' checked="checked"' : ''));?> /> 211ab9346edSAnika Henke <?php echo $lang['i_allowreg']?> 21274850f29SAnika Henke </label> 21347248316SAndreas Gohr </fieldset> 21447248316SAndreas Gohr </fieldset> 21547248316SAndreas Gohr 21606361442SAndreas Gohr <fieldset> 21706361442SAndreas Gohr <p><?php echo $lang['i_license']?></p> 21806361442SAndreas Gohr <?php 219b1730bd2STom N Harris array_push($license, array('name' => $lang['i_license_none'], 'url' => '')); 220ed856534STom N Harris if (empty($d['license'])) $d['license'] = 'cc-by-sa'; 22106361442SAndreas Gohr foreach ($license as $key => $lic) { 22206361442SAndreas Gohr echo '<label for="lic_' . $key . '">'; 22365cc1598SPhy echo '<input type="radio" name="d[license]" value="' . hsc($key) . '" id="lic_' . $key . '"' . 224b1730bd2STom N Harris (($d['license'] === $key) ? ' checked="checked"' : '') . '>'; 22565cc1598SPhy echo hsc($lic['name']); 22606361442SAndreas Gohr if ($lic['url']) echo ' <a href="' . $lic['url'] . '" target="_blank"><sup>[?]</sup></a>'; 22706361442SAndreas Gohr echo '</label>'; 22806361442SAndreas Gohr } 22906361442SAndreas Gohr ?> 23006361442SAndreas Gohr </fieldset> 23106361442SAndreas Gohr 2323a0852d9SAndreas Gohr <fieldset> 2333a0852d9SAndreas Gohr <p><?php echo $lang['i_pop_field']?></p> 2343a0852d9SAndreas Gohr <label for="pop"> 23564159a61SAndreas Gohr <input type="checkbox" name="d[pop]" id="pop" <?php 23664159a61SAndreas Gohr echo(($d['pop'] ? ' checked="checked"' : ''));?> /> 23764159a61SAndreas Gohr <?php echo $lang['i_pop_label']?> 23864159a61SAndreas Gohr <a href="http://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a> 2393a0852d9SAndreas Gohr </label> 2403a0852d9SAndreas Gohr </fieldset> 2413a0852d9SAndreas Gohr 24247248316SAndreas Gohr </fieldset> 24347248316SAndreas Gohr <fieldset id="process"> 244ae614416SAnika Henke <button type="submit" name="submit"><?php echo $lang['btn_save']?></button> 24547248316SAndreas Gohr </fieldset> 24647248316SAndreas Gohr </form> 24747248316SAndreas Gohr <?php 24847248316SAndreas Gohr} 24947248316SAndreas Gohr 250db581254Sjpedrycfunction print_retry() 251db581254Sjpedryc{ 25270a6aa16Schris global $lang; 2539ad6da3dSAndreas Gohr global $LC; 25470a6aa16Schris ?> 25570a6aa16Schris <form action="" method="get"> 25670a6aa16Schris <fieldset> 2579ad6da3dSAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>" /> 258ae614416SAnika Henke <button type="submit"><?php echo $lang['i_retry'];?></button> 25970a6aa16Schris </fieldset> 26070a6aa16Schris </form> 26170a6aa16Schris <?php 26270a6aa16Schris} 26370a6aa16Schris 26447248316SAndreas Gohr/** 26547248316SAndreas Gohr * Check validity of data 26647248316SAndreas Gohr * 26747248316SAndreas Gohr * @author Andreas Gohr 268253d4b48SGerrit Uitslag * 269253d4b48SGerrit Uitslag * @param array $d 270253d4b48SGerrit Uitslag * @return bool ok? 27147248316SAndreas Gohr */ 272db581254Sjpedrycfunction check_data(&$d) 273db581254Sjpedryc{ 2744b530faaSTom N Harris static $form_default = array( 2754b530faaSTom N Harris 'title' => '', 276ed856534STom N Harris 'acl' => '1', 2774b530faaSTom N Harris 'superuser' => '', 2784b530faaSTom N Harris 'fullname' => '', 2794b530faaSTom N Harris 'email' => '', 2804b530faaSTom N Harris 'password' => '', 2814b530faaSTom N Harris 'confirm' => '', 2824b530faaSTom N Harris 'policy' => '0', 283ab9346edSAnika Henke 'allowreg' => '0', 2844b530faaSTom N Harris 'license' => 'cc-by-sa' 2854b530faaSTom N Harris ); 28647248316SAndreas Gohr global $lang; 28747248316SAndreas Gohr global $error; 28847248316SAndreas Gohr 2894b530faaSTom N Harris if (!is_array($d)) $d = array(); 2904b530faaSTom N Harris foreach ($d as $k => $v) { 2914b530faaSTom N Harris if (is_array($v)) 2924b530faaSTom N Harris unset($d[$k]); 293db581254Sjpedryc else $d[$k] = (string)$v; 2944b530faaSTom N Harris } 295e2386079SAndreas Gohr 2964b530faaSTom N Harris //autolowercase the username 2974b530faaSTom N Harris $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : ""; 2984b530faaSTom N Harris 2994b530faaSTom N Harris $ok = false; 3004b530faaSTom N Harris 3014b530faaSTom N Harris if (isset($_REQUEST['submit'])) { 30247248316SAndreas Gohr $ok = true; 30347248316SAndreas Gohr 30447248316SAndreas Gohr // check input 30547248316SAndreas Gohr if (empty($d['title'])) { 30647248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['i_wikiname']); 30747248316SAndreas Gohr $ok = false; 30847248316SAndreas Gohr } 3094b530faaSTom N Harris if (isset($d['acl'])) { 310*2cb06bbdSjpedryc if (empty($d['superuser']) || ($d['superuser'] !== cleanID($d['superuser']))) { 31147248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['i_superuser']); 31247248316SAndreas Gohr $ok = false; 31347248316SAndreas Gohr } 31447248316SAndreas Gohr if (empty($d['password'])) { 31547248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['pass']); 31647248316SAndreas Gohr $ok = false; 317db581254Sjpedryc } elseif (!isset($d['confirm']) || $d['confirm'] != $d['password']) { 31847248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['passchk']); 31947248316SAndreas Gohr $ok = false; 32047248316SAndreas Gohr } 32147248316SAndreas Gohr if (empty($d['fullname']) || strstr($d['fullname'], ':')) { 32247248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['fullname']); 32347248316SAndreas Gohr $ok = false; 32447248316SAndreas Gohr } 325e2386079SAndreas Gohr if (empty($d['email']) || strstr($d['email'], ':') || !strstr($d['email'], '@')) { 32647248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['email']); 32747248316SAndreas Gohr $ok = false; 32847248316SAndreas Gohr } 329b9ab8e4fSPhy } else { 330b9ab8e4fSPhy // Since default = 1, browser won't send acl=0 when user untick acl 331b9ab8e4fSPhy $d['acl'] = '0'; 33247248316SAndreas Gohr } 3334b530faaSTom N Harris } 3344b530faaSTom N Harris $d = array_merge($form_default, $d); 33547248316SAndreas Gohr return $ok; 33647248316SAndreas Gohr} 33747248316SAndreas Gohr 33847248316SAndreas Gohr/** 33947248316SAndreas Gohr * Writes the data to the config files 34047248316SAndreas Gohr * 34147248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 342253d4b48SGerrit Uitslag * 343253d4b48SGerrit Uitslag * @param array $d 344253d4b48SGerrit Uitslag * @return bool 34547248316SAndreas Gohr */ 346db581254Sjpedrycfunction store_data($d) 347db581254Sjpedryc{ 3480036aa89SAndreas Gohr global $LC; 34947248316SAndreas Gohr $ok = true; 3508af2e4bbSAndreas Gohr $d['policy'] = (int) $d['policy']; 35147248316SAndreas Gohr 35247248316SAndreas Gohr // create local.php 35324650a19SAndreas Gohr $now = gmdate('r'); 35447248316SAndreas Gohr $output = <<<EOT 35547248316SAndreas Gohr<?php 35647248316SAndreas Gohr/** 35747248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings 35847248316SAndreas Gohr * Auto-generated by install script 35947248316SAndreas Gohr * Date: $now 36047248316SAndreas Gohr */ 36147248316SAndreas Gohr 36247248316SAndreas GohrEOT; 3632613efa1SAndreas Gohr // add any config options set by a previous installer 3642613efa1SAndreas Gohr $preset = __DIR__ . '/install.conf'; 3652613efa1SAndreas Gohr if (file_exists($preset)) { 3662613efa1SAndreas Gohr $output .= "# preset config options\n"; 3672613efa1SAndreas Gohr $output .= file_get_contents($preset); 3682613efa1SAndreas Gohr $output .= "\n\n"; 3692613efa1SAndreas Gohr $output .= "# options selected in installer\n"; 3702613efa1SAndreas Gohr @unlink($preset); 3712613efa1SAndreas Gohr } 3722613efa1SAndreas Gohr 37347248316SAndreas Gohr $output .= '$conf[\'title\'] = \'' . addslashes($d['title']) . "';\n"; 3740036aa89SAndreas Gohr $output .= '$conf[\'lang\'] = \'' . addslashes($LC) . "';\n"; 37506361442SAndreas Gohr $output .= '$conf[\'license\'] = \'' . addslashes($d['license']) . "';\n"; 37647248316SAndreas Gohr if ($d['acl']) { 37747248316SAndreas Gohr $output .= '$conf[\'useacl\'] = 1' . ";\n"; 378523d7ea6Schris $output .= "\$conf['superuser'] = '@admin';\n"; 37947248316SAndreas Gohr } 380ab9346edSAnika Henke if (!$d['allowreg']) { 38143c137edSAnika Henke $output .= '$conf[\'disableactions\'] = \'register\'' . ";\n"; 382d2ea6dc1SAnika Henke } 38347248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'local.php', $output); 38447248316SAndreas Gohr 38547248316SAndreas Gohr if ($d['acl']) { 3863791b589SAndreas Gohr // hash the password 387c3cc6e05SAndreas Gohr $phash = new \dokuwiki\PassHash(); 388267bbbcaSms101 $pass = $phash->hash_bcrypt($d['password']); 3893791b589SAndreas Gohr 39047248316SAndreas Gohr // create users.auth.php 391a672ef75SPhy $output = <<<EOT 392a672ef75SPhy# users.auth.php 393a672ef75SPhy# <?php exit()?> 394a672ef75SPhy# Don't modify the lines above 395a672ef75SPhy# 396a672ef75SPhy# Userfile 397a672ef75SPhy# 398a672ef75SPhy# Auto-generated by install script 399a672ef75SPhy# Date: $now 400a672ef75SPhy# 401a672ef75SPhy# Format: 402a672ef75SPhy# login:passwordhash:Real Name:email:groups,comma,separated 403a672ef75SPhy 404a672ef75SPhyEOT; 405722372bdSms101 // --- user:bcryptpasswordhash:Real Name:email:groups,comma,seperated 406a672ef75SPhy $output = $output . "\n" . join(":", array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user')) . "\n"; 40747248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'users.auth.php', $output); 40847248316SAndreas Gohr 40947248316SAndreas Gohr // create acl.auth.php 4108af2e4bbSAndreas Gohr $output = <<<EOT 4118af2e4bbSAndreas Gohr# acl.auth.php 4128af2e4bbSAndreas Gohr# <?php exit()?> 4138af2e4bbSAndreas Gohr# Don't modify the lines above 4148af2e4bbSAndreas Gohr# 4158af2e4bbSAndreas Gohr# Access Control Lists 4168af2e4bbSAndreas Gohr# 4178af2e4bbSAndreas Gohr# Auto-generated by install script 4188af2e4bbSAndreas Gohr# Date: $now 4198af2e4bbSAndreas Gohr 4208af2e4bbSAndreas GohrEOT; 4218af2e4bbSAndreas Gohr if ($d['policy'] == 2) { 4228af2e4bbSAndreas Gohr $output .= "* @ALL 0\n"; 423d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4249c70688aSchris } elseif ($d['policy'] == 1) { 4258af2e4bbSAndreas Gohr $output .= "* @ALL 1\n"; 426d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4278af2e4bbSAndreas Gohr } else { 4288af2e4bbSAndreas Gohr $output .= "* @ALL 8\n"; 4298af2e4bbSAndreas Gohr } 43047248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'acl.auth.php', $output); 43147248316SAndreas Gohr } 4323a0852d9SAndreas Gohr 4333a0852d9SAndreas Gohr // enable popularity submission 434ee4f28e3SDamien Regad if (isset($d['pop']) && $d['pop']) { 4353a0852d9SAndreas Gohr @touch(DOKU_INC . 'data/cache/autosubmit.txt'); 4363a0852d9SAndreas Gohr } 4373a0852d9SAndreas Gohr 438c70d6ceeSAndreas Gohr // disable auth plugins til needed 439c70d6ceeSAndreas Gohr $output = <<<EOT 440c70d6ceeSAndreas Gohr<?php 441c70d6ceeSAndreas Gohr/* 442c70d6ceeSAndreas Gohr * Local plugin enable/disable settings 443c70d6ceeSAndreas Gohr * 444c70d6ceeSAndreas Gohr * Auto-generated by install script 445c70d6ceeSAndreas Gohr * Date: $now 446c70d6ceeSAndreas Gohr */ 447c70d6ceeSAndreas Gohr 448c70d6ceeSAndreas Gohr\$plugins['authad'] = 0; 449c70d6ceeSAndreas Gohr\$plugins['authldap'] = 0; 450c70d6ceeSAndreas Gohr\$plugins['authmysql'] = 0; 451c70d6ceeSAndreas Gohr\$plugins['authpgsql'] = 0; 452c70d6ceeSAndreas Gohr 453c70d6ceeSAndreas GohrEOT; 454c70d6ceeSAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'plugins.local.php', $output); 455c70d6ceeSAndreas Gohr 45647248316SAndreas Gohr return $ok; 45747248316SAndreas Gohr} 45847248316SAndreas Gohr 45947248316SAndreas Gohr/** 46047248316SAndreas Gohr * Write the given content to a file 46147248316SAndreas Gohr * 46247248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 463253d4b48SGerrit Uitslag * 464253d4b48SGerrit Uitslag * @param string $filename 465253d4b48SGerrit Uitslag * @param string $data 466253d4b48SGerrit Uitslag * @return bool 46747248316SAndreas Gohr */ 468db581254Sjpedrycfunction fileWrite($filename, $data) 469db581254Sjpedryc{ 47047248316SAndreas Gohr global $error; 47147248316SAndreas Gohr global $lang; 47247248316SAndreas Gohr 47347248316SAndreas Gohr if (($fp = @fopen($filename, 'wb')) === false) { 47447248316SAndreas Gohr $filename = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $filename); 47547248316SAndreas Gohr $error[] = sprintf($lang['i_writeerr'], $filename); 47647248316SAndreas Gohr return false; 47747248316SAndreas Gohr } 47847248316SAndreas Gohr 479db581254Sjpedryc if (!empty($data)) { 480db581254Sjpedryc fwrite($fp, $data); 481db581254Sjpedryc } 48247248316SAndreas Gohr fclose($fp); 48347248316SAndreas Gohr return true; 48447248316SAndreas Gohr} 48547248316SAndreas Gohr 48647248316SAndreas Gohr 48747248316SAndreas Gohr/** 48847248316SAndreas Gohr * check installation dependent local config files and tests for a known 48947248316SAndreas Gohr * unmodified main config file 49047248316SAndreas Gohr * 49147248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 492253d4b48SGerrit Uitslag * 493253d4b48SGerrit Uitslag * @return bool 49447248316SAndreas Gohr */ 495db581254Sjpedrycfunction check_configs() 496db581254Sjpedryc{ 49747248316SAndreas Gohr global $error; 49847248316SAndreas Gohr global $lang; 49947248316SAndreas Gohr 50047248316SAndreas Gohr $ok = true; 50147248316SAndreas Gohr 5025cfb8815Schris $config_files = array( 5035cfb8815Schris 'local' => DOKU_LOCAL . 'local.php', 5045cfb8815Schris 'users' => DOKU_LOCAL . 'users.auth.php', 5055cfb8815Schris 'auth' => DOKU_LOCAL . 'acl.auth.php' 5065cfb8815Schris ); 5075cfb8815Schris 50847248316SAndreas Gohr // configs shouldn't exist 50947248316SAndreas Gohr foreach ($config_files as $file) { 51079e79377SAndreas Gohr if (file_exists($file) && filesize($file)) { 51147248316SAndreas Gohr $file = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $file); 51247248316SAndreas Gohr $error[] = sprintf($lang['i_confexists'], $file); 51347248316SAndreas Gohr $ok = false; 51447248316SAndreas Gohr } 51547248316SAndreas Gohr } 51647248316SAndreas Gohr return $ok; 51747248316SAndreas Gohr} 51847248316SAndreas Gohr 51947248316SAndreas Gohr 52047248316SAndreas Gohr/** 52147248316SAndreas Gohr * Check other installation dir/file permission requirements 52247248316SAndreas Gohr * 52347248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 524253d4b48SGerrit Uitslag * 525253d4b48SGerrit Uitslag * @return bool 52647248316SAndreas Gohr */ 527db581254Sjpedrycfunction check_permissions() 528db581254Sjpedryc{ 52947248316SAndreas Gohr global $error; 53047248316SAndreas Gohr global $lang; 53147248316SAndreas Gohr 53247248316SAndreas Gohr $dirs = array( 53347248316SAndreas Gohr 'conf' => DOKU_LOCAL, 53447248316SAndreas Gohr 'data' => DOKU_INC . 'data', 53547248316SAndreas Gohr 'pages' => DOKU_INC . 'data/pages', 53647248316SAndreas Gohr 'attic' => DOKU_INC . 'data/attic', 53747248316SAndreas Gohr 'media' => DOKU_INC . 'data/media', 53849b78edaSAndreas Gohr 'media_attic' => DOKU_INC . 'data/media_attic', 53949b78edaSAndreas Gohr 'media_meta' => DOKU_INC . 'data/media_meta', 54047248316SAndreas Gohr 'meta' => DOKU_INC . 'data/meta', 54147248316SAndreas Gohr 'cache' => DOKU_INC . 'data/cache', 54247248316SAndreas Gohr 'locks' => DOKU_INC . 'data/locks', 5439711045aSAndreas Gohr 'index' => DOKU_INC . 'data/index', 544de33a58fSMichael Klier 'tmp' => DOKU_INC . 'data/tmp' 54547248316SAndreas Gohr ); 54647248316SAndreas Gohr 54747248316SAndreas Gohr $ok = true; 54847248316SAndreas Gohr foreach ($dirs as $dir) { 54979e79377SAndreas Gohr if (!file_exists("$dir/.") || !is_writable($dir)) { 55070a6aa16Schris $dir = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}', $dir); 55147248316SAndreas Gohr $error[] = sprintf($lang['i_permfail'], $dir); 55247248316SAndreas Gohr $ok = false; 55347248316SAndreas Gohr } 55447248316SAndreas Gohr } 55547248316SAndreas Gohr return $ok; 55647248316SAndreas Gohr} 55747248316SAndreas Gohr 55847248316SAndreas Gohr/** 5593afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version 56047248316SAndreas Gohr * 56147248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 562253d4b48SGerrit Uitslag * 563253d4b48SGerrit Uitslag * @return bool 56447248316SAndreas Gohr */ 565db581254Sjpedrycfunction check_functions() 566db581254Sjpedryc{ 56747248316SAndreas Gohr global $error; 56847248316SAndreas Gohr global $lang; 5693afe5d1cSAndreas Gohr $ok = true; 5703afe5d1cSAndreas Gohr 5713476bb81SAndreas Gohr if (version_compare(phpversion(), '5.6.0', '<')) { 5723476bb81SAndreas Gohr $error[] = sprintf($lang['i_phpver'], phpversion(), '5.6.0'); 5733afe5d1cSAndreas Gohr $ok = false; 5743afe5d1cSAndreas Gohr } 5753afe5d1cSAndreas Gohr 5767f413440SAndreas Gohr if (ini_get('mbstring.func_overload') != 0) { 5777f413440SAndreas Gohr $error[] = $lang['i_mbfuncoverload']; 5787f413440SAndreas Gohr $ok = false; 5797f413440SAndreas Gohr } 5807f413440SAndreas Gohr 581387250efSPhy try { 582387250efSPhy random_bytes(1); 583387250efSPhy } catch (\Exception $th) { 584387250efSPhy // If an appropriate source of randomness cannot be found, an Exception will be thrown by PHP 7+ 585387250efSPhy $error[] = $lang['i_urandom']; 586387250efSPhy $ok = false; 587387250efSPhy } 588387250efSPhy 589387250efSPhy if (ini_get('mbstring.func_overload') != 0) { 590387250efSPhy $error[] = $lang['i_mbfuncoverload']; 591387250efSPhy $ok = false; 592387250efSPhy } 593387250efSPhy 5943009a773SAndreas Gohr $funcs = explode(' ', 'addslashes call_user_func chmod copy fgets ' . 59547248316SAndreas Gohr 'file file_exists fseek flush filesize ftell fopen ' . 5963f6872b1SMyron Turner 'glob header ignore_user_abort ini_get mkdir ' . 59747248316SAndreas Gohr 'ob_start opendir parse_ini_file readfile realpath ' . 598bab4a8bdSAndreas Gohr 'rename rmdir serialize session_start unlink usleep ' . 599d1d99bb9SAndreas Gohr 'preg_replace file_get_contents htmlspecialchars_decode ' . 600670dc13dSAndreas Gohr 'spl_autoload_register stream_select fsockopen pack xml_parser_create'); 60147248316SAndreas Gohr 60270a6aa16Schris if (!function_exists('mb_substr')) { 60370a6aa16Schris $funcs[] = 'utf8_encode'; 60470a6aa16Schris $funcs[] = 'utf8_decode'; 60570a6aa16Schris } 60670a6aa16Schris 6073f6872b1SMyron Turner if (!function_exists('mail')) { 6083f6872b1SMyron Turner if (strpos(ini_get('disable_functions'), 'mail') !== false) { 6093f6872b1SMyron Turner $disabled = $lang['i_disabled']; 610db581254Sjpedryc } else { 6113f6872b1SMyron Turner $disabled = ""; 6123f6872b1SMyron Turner } 6133f6872b1SMyron Turner $error[] = sprintf($lang['i_funcnmail'], $disabled); 6143f6872b1SMyron Turner } 6153f6872b1SMyron Turner 61647248316SAndreas Gohr foreach ($funcs as $func) { 61747248316SAndreas Gohr if (!function_exists($func)) { 61847248316SAndreas Gohr $error[] = sprintf($lang['i_funcna'], $func); 61947248316SAndreas Gohr $ok = false; 62047248316SAndreas Gohr } 62147248316SAndreas Gohr } 62247248316SAndreas Gohr return $ok; 62347248316SAndreas Gohr} 62447248316SAndreas Gohr 62547248316SAndreas Gohr/** 62647248316SAndreas Gohr * Print language selection 62747248316SAndreas Gohr * 62847248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 62947248316SAndreas Gohr */ 630db581254Sjpedrycfunction langsel() 631db581254Sjpedryc{ 63247248316SAndreas Gohr global $lang; 63347248316SAndreas Gohr global $LC; 63447248316SAndreas Gohr 63547248316SAndreas Gohr $dir = DOKU_INC . 'inc/lang'; 63647248316SAndreas Gohr $dh = opendir($dir); 63747248316SAndreas Gohr if (!$dh) return; 63847248316SAndreas Gohr 63947248316SAndreas Gohr $langs = array(); 64047248316SAndreas Gohr while (($file = readdir($dh)) !== false) { 64147248316SAndreas Gohr if (preg_match('/^[\._]/', $file)) continue; 64279e79377SAndreas Gohr if (is_dir($dir . '/' . $file) && file_exists($dir . '/' . $file . '/lang.php')) { 64347248316SAndreas Gohr $langs[] = $file; 64447248316SAndreas Gohr } 64547248316SAndreas Gohr } 64647248316SAndreas Gohr closedir($dh); 64747248316SAndreas Gohr sort($langs); 64847248316SAndreas Gohr 64947248316SAndreas Gohr echo '<form action="">'; 65047248316SAndreas Gohr echo $lang['i_chooselang']; 65147248316SAndreas Gohr echo ': <select name="l" onchange="submit()">'; 65247248316SAndreas Gohr foreach ($langs as $l) { 65347248316SAndreas Gohr $sel = ($l == $LC) ? 'selected="selected"' : ''; 65447248316SAndreas Gohr echo '<option value="' . $l . '" ' . $sel . '>' . $l . '</option>'; 65547248316SAndreas Gohr } 65647248316SAndreas Gohr echo '</select> '; 657ae614416SAnika Henke echo '<button type="submit">' . $lang['btn_update'] . '</button>'; 65847248316SAndreas Gohr echo '</form>'; 65947248316SAndreas Gohr} 66047248316SAndreas Gohr 66147248316SAndreas Gohr/** 662c66972f2SAdrian Lang * Print global error array 66347248316SAndreas Gohr * 66447248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 66547248316SAndreas Gohr */ 666db581254Sjpedrycfunction print_errors() 667db581254Sjpedryc{ 66847248316SAndreas Gohr global $error; 6694b530faaSTom N Harris if (!empty($error)) { 67047248316SAndreas Gohr echo '<ul>'; 67147248316SAndreas Gohr foreach ($error as $err) { 67247248316SAndreas Gohr echo "<li>$err</li>"; 67347248316SAndreas Gohr } 67447248316SAndreas Gohr echo '</ul>'; 67547248316SAndreas Gohr } 6764b530faaSTom N Harris} 677