15cfb8815Schris<?php 2db581254Sjpedryc 3*b1f206e1SAndreas Gohruse dokuwiki\PassHash; 4ac251797SAndreas Gohr/*><div style="width:60%; margin: auto; background-color: #fcc; 5ac251797SAndreas Gohr border: 1px solid #faa; padding: 0.5em 1em;"> 6ac251797SAndreas Gohr <h1 style="font-size: 120%">No PHP Support</h1> 7ac251797SAndreas Gohr 8ac251797SAndreas Gohr It seems this server has no PHP support enabled. You will need to 9ac251797SAndreas Gohr enable PHP before you can install and run DokuWiki. Contact your hosting 10ac251797SAndreas Gohr provider if you're unsure what this means. 11ac251797SAndreas Gohr 12ac251797SAndreas Gohr</div>*/ 135cfb8815Schris/** 145cfb8815Schris * Dokuwiki installation assistance 155cfb8815Schris * 165cfb8815Schris * @author Chris Smith <chris@jalakai.co.uk> 175cfb8815Schris */ 185cfb8815Schris 19*b1f206e1SAndreas Gohrif (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/'); 205cfb8815Schrisif (!defined('DOKU_CONF')) define('DOKU_CONF', DOKU_INC . 'conf/'); 215cfb8815Schrisif (!defined('DOKU_LOCAL')) define('DOKU_LOCAL', DOKU_INC . 'conf/'); 225cfb8815Schris 2302bca5d4SYousong Zhou// load and initialize the core system 2402bca5d4SYousong Zhourequire_once(DOKU_INC . 'inc/init.php'); 252cb06bbdSjpedrycrequire_once(DOKU_INC . 'inc/pageutils.php'); 263791b589SAndreas Gohr 273545b2e0Schris// check for error reporting override or set error reporting to sane values 28db581254Sjpedrycif (!defined('DOKU_E_LEVEL')) { 29db581254Sjpedryc error_reporting(E_ALL ^ E_NOTICE); 30db581254Sjpedryc} else { 31db581254Sjpedryc error_reporting(DOKU_E_LEVEL); 32db581254Sjpedryc} 333545b2e0Schris 3447248316SAndreas Gohr// language strings 3547248316SAndreas Gohrrequire_once(DOKU_INC . 'inc/lang/en/lang.php'); 364b530faaSTom N Harrisif (isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) { 3747248316SAndreas Gohr $LC = preg_replace('/[^a-z\-]+/', '', $_REQUEST['l']); 384b530faaSTom N Harris} 394b530faaSTom N Harrisif (empty($LC)) $LC = 'en'; 4047248316SAndreas Gohrif ($LC && $LC != 'en') { 4147248316SAndreas Gohr require_once(DOKU_INC . 'inc/lang/' . $LC . '/lang.php'); 4247248316SAndreas Gohr} 4347248316SAndreas Gohr 4447248316SAndreas Gohr// initialise variables ... 45*b1f206e1SAndreas Gohr$error = []; 4647248316SAndreas Gohr 4747248316SAndreas Gohr// begin output 4847248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8'); 4947248316SAndreas Gohr?> 50c8839c22SAnika Henke<!DOCTYPE html> 51c8839c22SAnika Henke<html lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>"> 5247248316SAndreas Gohr<head> 53c8839c22SAnika Henke <meta charset="utf-8" /> 544208c142SAndreas Gohr <title><?php echo $lang['i_installer']?></title> 5559305168SPhy <style> 5647248316SAndreas Gohr body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; } 5747248316SAndreas Gohr img { border: none } 5847248316SAndreas Gohr br.cl { clear:both; } 5970a6aa16Schris code { font-size: 110%; color: #800000; } 6047248316SAndreas Gohr fieldset { border: none } 619c70688aSchris label { display: block; margin-top: 0.5em; } 628af2e4bbSAndreas Gohr select.text, input.text { width: 30em; margin: 0 0.5em; } 6306361442SAndreas Gohr a {text-decoration: none} 6447248316SAndreas Gohr </style> 6559305168SPhy <script> 6647248316SAndreas Gohr function acltoggle(){ 6747248316SAndreas Gohr var cb = document.getElementById('acl'); 6847248316SAndreas Gohr var fs = document.getElementById('acldep'); 6947248316SAndreas Gohr if(!cb || !fs) return; 7047248316SAndreas Gohr if(cb.checked){ 7147248316SAndreas Gohr fs.style.display = ''; 7247248316SAndreas Gohr }else{ 7347248316SAndreas Gohr fs.style.display = 'none'; 7447248316SAndreas Gohr } 7547248316SAndreas Gohr } 7647248316SAndreas Gohr window.onload = function(){ 7747248316SAndreas Gohr acltoggle(); 7847248316SAndreas Gohr var cb = document.getElementById('acl'); 7947248316SAndreas Gohr if(cb) cb.onchange = acltoggle; 8047248316SAndreas Gohr }; 8147248316SAndreas Gohr </script> 8247248316SAndreas Gohr</head> 8347248316SAndreas Gohr<body style=""> 8447248316SAndreas Gohr <h1 style="float:left"> 85c5270434SAndreas Gohr <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png" 86c5270434SAndreas Gohr style="vertical-align: middle;" alt="" height="64" width="64" /> 8747248316SAndreas Gohr <?php echo $lang['i_installer']?> 8847248316SAndreas Gohr </h1> 8947248316SAndreas Gohr <div style="float:right; margin: 1em;"> 9047248316SAndreas Gohr <?php langsel()?> 9147248316SAndreas Gohr </div> 9247248316SAndreas Gohr <br class="cl" /> 9347248316SAndreas Gohr 9447248316SAndreas Gohr <div style="float: right; width: 34%;"> 9547248316SAndreas Gohr <?php 9679e79377SAndreas Gohr if (file_exists(DOKU_INC . 'inc/lang/' . $LC . '/install.html')) { 9747248316SAndreas Gohr include(DOKU_INC . 'inc/lang/' . $LC . '/install.html'); 9847248316SAndreas Gohr } else { 99ca64d724Schris print "<div lang=\"en\" dir=\"ltr\">\n"; 10047248316SAndreas Gohr include(DOKU_INC . 'inc/lang/en/install.html'); 101ca64d724Schris print "</div>\n"; 10247248316SAndreas Gohr } 10347248316SAndreas Gohr ?> 10464159a61SAndreas Gohr <a style=" 10564159a61SAndreas Gohr background: transparent 10664159a61SAndreas Gohr url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png) 10764159a61SAndreas Gohr left top no-repeat; 108c8b43921SAndreas Gohr display: block; width:380px; height:73px; border:none; clear:both;" 109c8b43921SAndreas Gohr target="_blank" 110c8b43921SAndreas Gohr href="http://www.dokuwiki.org/security#web_access_security"></a> 11147248316SAndreas Gohr </div> 11247248316SAndreas Gohr 11347248316SAndreas Gohr <div style="float: left; width: 58%;"> 11447248316SAndreas Gohr <?php 1157ac1baa0SL. Ivanovich Harrison try { 11647248316SAndreas Gohr if (! (check_functions() && check_permissions())) { 11747248316SAndreas Gohr echo '<p>' . $lang['i_problems'] . '</p>'; 11847248316SAndreas Gohr print_errors(); 11970a6aa16Schris print_retry(); 12047248316SAndreas Gohr } elseif (!check_configs()) { 12147248316SAndreas Gohr echo '<p>' . $lang['i_modified'] . '</p>'; 12247248316SAndreas Gohr print_errors(); 1234b530faaSTom N Harris } elseif (check_data($_REQUEST['d'])) { 1244b530faaSTom N Harris // check_data has sanitized all input parameters 1254b530faaSTom N Harris if (!store_data($_REQUEST['d'])) { 12647248316SAndreas Gohr echo '<p>' . $lang['i_failure'] . '</p>'; 12747248316SAndreas Gohr print_errors(); 12847248316SAndreas Gohr } else { 12947248316SAndreas Gohr echo '<p>' . $lang['i_success'] . '</p>'; 13047248316SAndreas Gohr } 13147248316SAndreas Gohr } else { 1324b530faaSTom N Harris print_errors(); 13347248316SAndreas Gohr print_form($_REQUEST['d']); 13447248316SAndreas Gohr } 1357ac1baa0SL. Ivanovich Harrison } catch (Exception $e) { 1367ac1baa0SL. Ivanovich Harrison echo 'Caught exception: ', $e->getMessage(), "\n"; 1377ac1baa0SL. Ivanovich Harrison } 13847248316SAndreas Gohr ?> 13947248316SAndreas Gohr </div> 14047248316SAndreas Gohr 141c8b43921SAndreas Gohr 14247248316SAndreas Gohr<div style="clear: both"> 143654436fbSAnika Henke <a href="http://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki" /></a> 14459752844SAnders Sandblad <a href="http://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP" /></a> 14547248316SAndreas Gohr</div> 14647248316SAndreas Gohr</body> 14747248316SAndreas Gohr</html> 14847248316SAndreas Gohr<?php 14947248316SAndreas Gohr 15047248316SAndreas Gohr/** 15147248316SAndreas Gohr * Print the input form 152253d4b48SGerrit Uitslag * 153253d4b48SGerrit Uitslag * @param array $d submitted entry 'd' of request data 15447248316SAndreas Gohr */ 155db581254Sjpedrycfunction print_form($d) 156db581254Sjpedryc{ 15747248316SAndreas Gohr global $lang; 15847248316SAndreas Gohr global $LC; 15947248316SAndreas Gohr 16006361442SAndreas Gohr include(DOKU_CONF . 'license.php'); 16106361442SAndreas Gohr 162*b1f206e1SAndreas Gohr if (!is_array($d)) $d = []; 16365cc1598SPhy $d = array_map('hsc', $d); 16447248316SAndreas Gohr 16547248316SAndreas Gohr if (!isset($d['acl'])) $d['acl'] = 1; 1663a0852d9SAndreas Gohr if (!isset($d['pop'])) $d['pop'] = 1; 16747248316SAndreas Gohr 16847248316SAndreas Gohr ?> 16947248316SAndreas Gohr <form action="" method="post"> 17047248316SAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>" /> 17147248316SAndreas Gohr <fieldset> 17247248316SAndreas Gohr <label for="title"><?php echo $lang['i_wikiname']?> 17347248316SAndreas Gohr <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" /> 17447248316SAndreas Gohr </label> 17547248316SAndreas Gohr 17647248316SAndreas Gohr <fieldset style="margin-top: 1em;"> 17747248316SAndreas Gohr <label for="acl"> 17847248316SAndreas Gohr <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : ''));?> /> 17947248316SAndreas Gohr <?php echo $lang['i_enableacl']?></label> 18047248316SAndreas Gohr 18147248316SAndreas Gohr <fieldset id="acldep"> 18247248316SAndreas Gohr <label for="superuser"><?php echo $lang['i_superuser']?></label> 18364159a61SAndreas Gohr <input class="text" type="text" name="d[superuser]" id="superuser" 18464159a61SAndreas Gohr value="<?php echo $d['superuser'] ?>" /> 18547248316SAndreas Gohr 18647248316SAndreas Gohr <label for="fullname"><?php echo $lang['fullname']?></label> 18764159a61SAndreas Gohr <input class="text" type="text" name="d[fullname]" id="fullname" 18864159a61SAndreas Gohr value="<?php echo $d['fullname'] ?>" /> 18947248316SAndreas Gohr 19047248316SAndreas Gohr <label for="email"><?php echo $lang['email']?></label> 19147248316SAndreas Gohr <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" /> 19247248316SAndreas Gohr 19347248316SAndreas Gohr <label for="password"><?php echo $lang['pass']?></label> 19447248316SAndreas Gohr <input class="text" type="password" name="d[password]" id="password" /> 19547248316SAndreas Gohr 19647248316SAndreas Gohr <label for="confirm"><?php echo $lang['passchk']?></label> 19747248316SAndreas Gohr <input class="text" type="password" name="d[confirm]" id="confirm" /> 1988af2e4bbSAndreas Gohr 1998af2e4bbSAndreas Gohr <label for="policy"><?php echo $lang['i_policy']?></label> 2008af2e4bbSAndreas Gohr <select class="text" name="d[policy]" id="policy"> 20164159a61SAndreas Gohr <option value="0" <?php echo ($d['policy'] == 0) ? 'selected="selected"' : '' ?>><?php 20264159a61SAndreas Gohr echo $lang['i_pol0']?></option> 20364159a61SAndreas Gohr <option value="1" <?php echo ($d['policy'] == 1) ? 'selected="selected"' : '' ?>><?php 20464159a61SAndreas Gohr echo $lang['i_pol1']?></option> 20564159a61SAndreas Gohr <option value="2" <?php echo ($d['policy'] == 2) ? 'selected="selected"' : '' ?>><?php 20664159a61SAndreas Gohr echo $lang['i_pol2']?></option> 2078af2e4bbSAndreas Gohr </select> 20806361442SAndreas Gohr 209ab9346edSAnika Henke <label for="allowreg"> 21064159a61SAndreas Gohr <input type="checkbox" name="d[allowreg]" id="allowreg" <?php 21164159a61SAndreas Gohr echo(($d['allowreg'] ? ' checked="checked"' : ''));?> /> 212ab9346edSAnika Henke <?php echo $lang['i_allowreg']?> 21374850f29SAnika Henke </label> 21447248316SAndreas Gohr </fieldset> 21547248316SAndreas Gohr </fieldset> 21647248316SAndreas Gohr 21706361442SAndreas Gohr <fieldset> 21806361442SAndreas Gohr <p><?php echo $lang['i_license']?></p> 21906361442SAndreas Gohr <?php 220*b1f206e1SAndreas Gohr $license[] = ['name' => $lang['i_license_none'], 'url' => '']; 221ed856534STom N Harris if (empty($d['license'])) $d['license'] = 'cc-by-sa'; 22206361442SAndreas Gohr foreach ($license as $key => $lic) { 22306361442SAndreas Gohr echo '<label for="lic_' . $key . '">'; 22465cc1598SPhy echo '<input type="radio" name="d[license]" value="' . hsc($key) . '" id="lic_' . $key . '"' . 225b1730bd2STom N Harris (($d['license'] === $key) ? ' checked="checked"' : '') . '>'; 22665cc1598SPhy echo hsc($lic['name']); 22706361442SAndreas Gohr if ($lic['url']) echo ' <a href="' . $lic['url'] . '" target="_blank"><sup>[?]</sup></a>'; 22806361442SAndreas Gohr echo '</label>'; 22906361442SAndreas Gohr } 23006361442SAndreas Gohr ?> 23106361442SAndreas Gohr </fieldset> 23206361442SAndreas Gohr 2333a0852d9SAndreas Gohr <fieldset> 2343a0852d9SAndreas Gohr <p><?php echo $lang['i_pop_field']?></p> 2353a0852d9SAndreas Gohr <label for="pop"> 23664159a61SAndreas Gohr <input type="checkbox" name="d[pop]" id="pop" <?php 23764159a61SAndreas Gohr echo(($d['pop'] ? ' checked="checked"' : ''));?> /> 23864159a61SAndreas Gohr <?php echo $lang['i_pop_label']?> 23964159a61SAndreas Gohr <a href="http://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a> 2403a0852d9SAndreas Gohr </label> 2413a0852d9SAndreas Gohr </fieldset> 2423a0852d9SAndreas Gohr 24347248316SAndreas Gohr </fieldset> 24447248316SAndreas Gohr <fieldset id="process"> 245ae614416SAnika Henke <button type="submit" name="submit"><?php echo $lang['btn_save']?></button> 24647248316SAndreas Gohr </fieldset> 24747248316SAndreas Gohr </form> 24847248316SAndreas Gohr <?php 24947248316SAndreas Gohr} 25047248316SAndreas Gohr 251db581254Sjpedrycfunction print_retry() 252db581254Sjpedryc{ 25370a6aa16Schris global $lang; 2549ad6da3dSAndreas Gohr global $LC; 25570a6aa16Schris ?> 25670a6aa16Schris <form action="" method="get"> 25770a6aa16Schris <fieldset> 2589ad6da3dSAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>" /> 259ae614416SAnika Henke <button type="submit"><?php echo $lang['i_retry'];?></button> 26070a6aa16Schris </fieldset> 26170a6aa16Schris </form> 26270a6aa16Schris <?php 26370a6aa16Schris} 26470a6aa16Schris 26547248316SAndreas Gohr/** 26647248316SAndreas Gohr * Check validity of data 26747248316SAndreas Gohr * 26847248316SAndreas Gohr * @author Andreas Gohr 269253d4b48SGerrit Uitslag * 270253d4b48SGerrit Uitslag * @param array $d 271253d4b48SGerrit Uitslag * @return bool ok? 27247248316SAndreas Gohr */ 273db581254Sjpedrycfunction check_data(&$d) 274db581254Sjpedryc{ 275*b1f206e1SAndreas Gohr static $form_default = [ 2764b530faaSTom N Harris 'title' => '', 277ed856534STom N Harris 'acl' => '1', 2784b530faaSTom N Harris 'superuser' => '', 2794b530faaSTom N Harris 'fullname' => '', 2804b530faaSTom N Harris 'email' => '', 2814b530faaSTom N Harris 'password' => '', 2824b530faaSTom N Harris 'confirm' => '', 2834b530faaSTom N Harris 'policy' => '0', 284ab9346edSAnika Henke 'allowreg' => '0', 2854b530faaSTom N Harris 'license' => 'cc-by-sa' 286*b1f206e1SAndreas Gohr ]; 28747248316SAndreas Gohr global $lang; 28847248316SAndreas Gohr global $error; 28947248316SAndreas Gohr 290*b1f206e1SAndreas Gohr if (!is_array($d)) $d = []; 2914b530faaSTom N Harris foreach ($d as $k => $v) { 2924b530faaSTom N Harris if (is_array($v)) 2934b530faaSTom N Harris unset($d[$k]); 294db581254Sjpedryc else $d[$k] = (string)$v; 2954b530faaSTom N Harris } 296e2386079SAndreas Gohr 2974b530faaSTom N Harris //autolowercase the username 2984b530faaSTom N Harris $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : ""; 2994b530faaSTom N Harris 3004b530faaSTom N Harris $ok = false; 3014b530faaSTom N Harris 3024b530faaSTom N Harris if (isset($_REQUEST['submit'])) { 30347248316SAndreas Gohr $ok = true; 30447248316SAndreas Gohr 30547248316SAndreas Gohr // check input 30647248316SAndreas Gohr if (empty($d['title'])) { 30747248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['i_wikiname']); 30847248316SAndreas Gohr $ok = false; 30947248316SAndreas Gohr } 3104b530faaSTom N Harris if (isset($d['acl'])) { 3112cb06bbdSjpedryc if (empty($d['superuser']) || ($d['superuser'] !== cleanID($d['superuser']))) { 31247248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['i_superuser']); 31347248316SAndreas Gohr $ok = false; 31447248316SAndreas Gohr } 31547248316SAndreas Gohr if (empty($d['password'])) { 31647248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['pass']); 31747248316SAndreas Gohr $ok = false; 318db581254Sjpedryc } elseif (!isset($d['confirm']) || $d['confirm'] != $d['password']) { 31947248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['passchk']); 32047248316SAndreas Gohr $ok = false; 32147248316SAndreas Gohr } 32247248316SAndreas Gohr if (empty($d['fullname']) || strstr($d['fullname'], ':')) { 32347248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['fullname']); 32447248316SAndreas Gohr $ok = false; 32547248316SAndreas Gohr } 326e2386079SAndreas Gohr if (empty($d['email']) || strstr($d['email'], ':') || !strstr($d['email'], '@')) { 32747248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['email']); 32847248316SAndreas Gohr $ok = false; 32947248316SAndreas Gohr } 330b9ab8e4fSPhy } else { 331b9ab8e4fSPhy // Since default = 1, browser won't send acl=0 when user untick acl 332b9ab8e4fSPhy $d['acl'] = '0'; 33347248316SAndreas Gohr } 3344b530faaSTom N Harris } 3354b530faaSTom N Harris $d = array_merge($form_default, $d); 33647248316SAndreas Gohr return $ok; 33747248316SAndreas Gohr} 33847248316SAndreas Gohr 33947248316SAndreas Gohr/** 34047248316SAndreas Gohr * Writes the data to the config files 34147248316SAndreas Gohr * 34247248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 343253d4b48SGerrit Uitslag * 344253d4b48SGerrit Uitslag * @param array $d 345253d4b48SGerrit Uitslag * @return bool 34647248316SAndreas Gohr */ 347db581254Sjpedrycfunction store_data($d) 348db581254Sjpedryc{ 3490036aa89SAndreas Gohr global $LC; 35047248316SAndreas Gohr $ok = true; 3518af2e4bbSAndreas Gohr $d['policy'] = (int) $d['policy']; 35247248316SAndreas Gohr 35347248316SAndreas Gohr // create local.php 35424650a19SAndreas Gohr $now = gmdate('r'); 35547248316SAndreas Gohr $output = <<<EOT 35647248316SAndreas Gohr<?php 35747248316SAndreas Gohr/** 35847248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings 35947248316SAndreas Gohr * Auto-generated by install script 36047248316SAndreas Gohr * Date: $now 36147248316SAndreas Gohr */ 36247248316SAndreas Gohr 36347248316SAndreas GohrEOT; 3642613efa1SAndreas Gohr // add any config options set by a previous installer 3652613efa1SAndreas Gohr $preset = __DIR__ . '/install.conf'; 3662613efa1SAndreas Gohr if (file_exists($preset)) { 3672613efa1SAndreas Gohr $output .= "# preset config options\n"; 3682613efa1SAndreas Gohr $output .= file_get_contents($preset); 3692613efa1SAndreas Gohr $output .= "\n\n"; 3702613efa1SAndreas Gohr $output .= "# options selected in installer\n"; 3712613efa1SAndreas Gohr @unlink($preset); 3722613efa1SAndreas Gohr } 3732613efa1SAndreas Gohr 37447248316SAndreas Gohr $output .= '$conf[\'title\'] = \'' . addslashes($d['title']) . "';\n"; 3750036aa89SAndreas Gohr $output .= '$conf[\'lang\'] = \'' . addslashes($LC) . "';\n"; 37606361442SAndreas Gohr $output .= '$conf[\'license\'] = \'' . addslashes($d['license']) . "';\n"; 37747248316SAndreas Gohr if ($d['acl']) { 37847248316SAndreas Gohr $output .= '$conf[\'useacl\'] = 1' . ";\n"; 379523d7ea6Schris $output .= "\$conf['superuser'] = '@admin';\n"; 38047248316SAndreas Gohr } 381ab9346edSAnika Henke if (!$d['allowreg']) { 38243c137edSAnika Henke $output .= '$conf[\'disableactions\'] = \'register\'' . ";\n"; 383d2ea6dc1SAnika Henke } 38447248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'local.php', $output); 38547248316SAndreas Gohr 38647248316SAndreas Gohr if ($d['acl']) { 3873791b589SAndreas Gohr // hash the password 388*b1f206e1SAndreas Gohr $phash = new PassHash(); 389267bbbcaSms101 $pass = $phash->hash_bcrypt($d['password']); 3903791b589SAndreas Gohr 39147248316SAndreas Gohr // create users.auth.php 392a672ef75SPhy $output = <<<EOT 393a672ef75SPhy# users.auth.php 394a672ef75SPhy# <?php exit()?> 395a672ef75SPhy# Don't modify the lines above 396a672ef75SPhy# 397a672ef75SPhy# Userfile 398a672ef75SPhy# 399a672ef75SPhy# Auto-generated by install script 400a672ef75SPhy# Date: $now 401a672ef75SPhy# 402a672ef75SPhy# Format: 403a672ef75SPhy# login:passwordhash:Real Name:email:groups,comma,separated 404a672ef75SPhy 405a672ef75SPhyEOT; 406722372bdSms101 // --- user:bcryptpasswordhash:Real Name:email:groups,comma,seperated 407*b1f206e1SAndreas Gohr $output = $output . "\n" . implode(':', [ 40836a1a880SAndreas Gohr $d['superuser'], 40936a1a880SAndreas Gohr $pass, 41036a1a880SAndreas Gohr $d['fullname'], 41136a1a880SAndreas Gohr $d['email'], 41236a1a880SAndreas Gohr 'admin,user', 41336a1a880SAndreas Gohr ]) . "\n"; 41447248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'users.auth.php', $output); 41547248316SAndreas Gohr 41647248316SAndreas Gohr // create acl.auth.php 4178af2e4bbSAndreas Gohr $output = <<<EOT 4188af2e4bbSAndreas Gohr# acl.auth.php 4198af2e4bbSAndreas Gohr# <?php exit()?> 4208af2e4bbSAndreas Gohr# Don't modify the lines above 4218af2e4bbSAndreas Gohr# 4228af2e4bbSAndreas Gohr# Access Control Lists 4238af2e4bbSAndreas Gohr# 4248af2e4bbSAndreas Gohr# Auto-generated by install script 4258af2e4bbSAndreas Gohr# Date: $now 4268af2e4bbSAndreas Gohr 4278af2e4bbSAndreas GohrEOT; 4288af2e4bbSAndreas Gohr if ($d['policy'] == 2) { 4298af2e4bbSAndreas Gohr $output .= "* @ALL 0\n"; 430d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4319c70688aSchris } elseif ($d['policy'] == 1) { 4328af2e4bbSAndreas Gohr $output .= "* @ALL 1\n"; 433d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4348af2e4bbSAndreas Gohr } else { 4358af2e4bbSAndreas Gohr $output .= "* @ALL 8\n"; 4368af2e4bbSAndreas Gohr } 43747248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'acl.auth.php', $output); 43847248316SAndreas Gohr } 4393a0852d9SAndreas Gohr 4403a0852d9SAndreas Gohr // enable popularity submission 441ee4f28e3SDamien Regad if (isset($d['pop']) && $d['pop']) { 4423a0852d9SAndreas Gohr @touch(DOKU_INC . 'data/cache/autosubmit.txt'); 4433a0852d9SAndreas Gohr } 4443a0852d9SAndreas Gohr 445c70d6ceeSAndreas Gohr // disable auth plugins til needed 446c70d6ceeSAndreas Gohr $output = <<<EOT 447c70d6ceeSAndreas Gohr<?php 448c70d6ceeSAndreas Gohr/* 449c70d6ceeSAndreas Gohr * Local plugin enable/disable settings 450c70d6ceeSAndreas Gohr * 451c70d6ceeSAndreas Gohr * Auto-generated by install script 452c70d6ceeSAndreas Gohr * Date: $now 453c70d6ceeSAndreas Gohr */ 454c70d6ceeSAndreas Gohr 455c70d6ceeSAndreas Gohr\$plugins['authad'] = 0; 456c70d6ceeSAndreas Gohr\$plugins['authldap'] = 0; 457c70d6ceeSAndreas Gohr\$plugins['authmysql'] = 0; 458c70d6ceeSAndreas Gohr\$plugins['authpgsql'] = 0; 459c70d6ceeSAndreas Gohr 460c70d6ceeSAndreas GohrEOT; 461c70d6ceeSAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'plugins.local.php', $output); 462c70d6ceeSAndreas Gohr 46347248316SAndreas Gohr return $ok; 46447248316SAndreas Gohr} 46547248316SAndreas Gohr 46647248316SAndreas Gohr/** 46747248316SAndreas Gohr * Write the given content to a file 46847248316SAndreas Gohr * 46947248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 470253d4b48SGerrit Uitslag * 471253d4b48SGerrit Uitslag * @param string $filename 472253d4b48SGerrit Uitslag * @param string $data 473253d4b48SGerrit Uitslag * @return bool 47447248316SAndreas Gohr */ 475db581254Sjpedrycfunction fileWrite($filename, $data) 476db581254Sjpedryc{ 47747248316SAndreas Gohr global $error; 47847248316SAndreas Gohr global $lang; 47947248316SAndreas Gohr 48047248316SAndreas Gohr if (($fp = @fopen($filename, 'wb')) === false) { 48147248316SAndreas Gohr $filename = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $filename); 48247248316SAndreas Gohr $error[] = sprintf($lang['i_writeerr'], $filename); 48347248316SAndreas Gohr return false; 48447248316SAndreas Gohr } 48547248316SAndreas Gohr 486db581254Sjpedryc if (!empty($data)) { 487db581254Sjpedryc fwrite($fp, $data); 488db581254Sjpedryc } 48947248316SAndreas Gohr fclose($fp); 49047248316SAndreas Gohr return true; 49147248316SAndreas Gohr} 49247248316SAndreas Gohr 49347248316SAndreas Gohr 49447248316SAndreas Gohr/** 49547248316SAndreas Gohr * check installation dependent local config files and tests for a known 49647248316SAndreas Gohr * unmodified main config file 49747248316SAndreas Gohr * 49847248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 499253d4b48SGerrit Uitslag * 500253d4b48SGerrit Uitslag * @return bool 50147248316SAndreas Gohr */ 502db581254Sjpedrycfunction check_configs() 503db581254Sjpedryc{ 50447248316SAndreas Gohr global $error; 50547248316SAndreas Gohr global $lang; 50647248316SAndreas Gohr 50747248316SAndreas Gohr $ok = true; 50847248316SAndreas Gohr 509*b1f206e1SAndreas Gohr $config_files = [ 5105cfb8815Schris 'local' => DOKU_LOCAL . 'local.php', 5115cfb8815Schris 'users' => DOKU_LOCAL . 'users.auth.php', 5125cfb8815Schris 'auth' => DOKU_LOCAL . 'acl.auth.php' 513*b1f206e1SAndreas Gohr ]; 5145cfb8815Schris 51547248316SAndreas Gohr // configs shouldn't exist 51647248316SAndreas Gohr foreach ($config_files as $file) { 51779e79377SAndreas Gohr if (file_exists($file) && filesize($file)) { 51847248316SAndreas Gohr $file = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $file); 51947248316SAndreas Gohr $error[] = sprintf($lang['i_confexists'], $file); 52047248316SAndreas Gohr $ok = false; 52147248316SAndreas Gohr } 52247248316SAndreas Gohr } 52347248316SAndreas Gohr return $ok; 52447248316SAndreas Gohr} 52547248316SAndreas Gohr 52647248316SAndreas Gohr 52747248316SAndreas Gohr/** 52847248316SAndreas Gohr * Check other installation dir/file permission requirements 52947248316SAndreas Gohr * 53047248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 531253d4b48SGerrit Uitslag * 532253d4b48SGerrit Uitslag * @return bool 53347248316SAndreas Gohr */ 534db581254Sjpedrycfunction check_permissions() 535db581254Sjpedryc{ 53647248316SAndreas Gohr global $error; 53747248316SAndreas Gohr global $lang; 53847248316SAndreas Gohr 539*b1f206e1SAndreas Gohr $dirs = [ 54047248316SAndreas Gohr 'conf' => DOKU_LOCAL, 54147248316SAndreas Gohr 'data' => DOKU_INC . 'data', 54247248316SAndreas Gohr 'pages' => DOKU_INC . 'data/pages', 54347248316SAndreas Gohr 'attic' => DOKU_INC . 'data/attic', 54447248316SAndreas Gohr 'media' => DOKU_INC . 'data/media', 54549b78edaSAndreas Gohr 'media_attic' => DOKU_INC . 'data/media_attic', 54649b78edaSAndreas Gohr 'media_meta' => DOKU_INC . 'data/media_meta', 54747248316SAndreas Gohr 'meta' => DOKU_INC . 'data/meta', 54847248316SAndreas Gohr 'cache' => DOKU_INC . 'data/cache', 54947248316SAndreas Gohr 'locks' => DOKU_INC . 'data/locks', 5509711045aSAndreas Gohr 'index' => DOKU_INC . 'data/index', 551de33a58fSMichael Klier 'tmp' => DOKU_INC . 'data/tmp' 552*b1f206e1SAndreas Gohr ]; 55347248316SAndreas Gohr 55447248316SAndreas Gohr $ok = true; 55547248316SAndreas Gohr foreach ($dirs as $dir) { 55679e79377SAndreas Gohr if (!file_exists("$dir/.") || !is_writable($dir)) { 55770a6aa16Schris $dir = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}', $dir); 55847248316SAndreas Gohr $error[] = sprintf($lang['i_permfail'], $dir); 55947248316SAndreas Gohr $ok = false; 56047248316SAndreas Gohr } 56147248316SAndreas Gohr } 56247248316SAndreas Gohr return $ok; 56347248316SAndreas Gohr} 56447248316SAndreas Gohr 56547248316SAndreas Gohr/** 5663afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version 56747248316SAndreas Gohr * 56847248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 569253d4b48SGerrit Uitslag * 570253d4b48SGerrit Uitslag * @return bool 57147248316SAndreas Gohr */ 572db581254Sjpedrycfunction check_functions() 573db581254Sjpedryc{ 57447248316SAndreas Gohr global $error; 57547248316SAndreas Gohr global $lang; 5763afe5d1cSAndreas Gohr $ok = true; 5773afe5d1cSAndreas Gohr 578c49393f5SAndreas Gohr if (version_compare(phpversion(), '7.4.0', '<')) { 579c49393f5SAndreas Gohr $error[] = sprintf($lang['i_phpver'], phpversion(), '7.4.0'); 5803afe5d1cSAndreas Gohr $ok = false; 5813afe5d1cSAndreas Gohr } 5823afe5d1cSAndreas Gohr 5837f413440SAndreas Gohr if (ini_get('mbstring.func_overload') != 0) { 5847f413440SAndreas Gohr $error[] = $lang['i_mbfuncoverload']; 5857f413440SAndreas Gohr $ok = false; 5867f413440SAndreas Gohr } 5877f413440SAndreas Gohr 588387250efSPhy try { 589387250efSPhy random_bytes(1); 590387250efSPhy } catch (\Exception $th) { 591387250efSPhy // If an appropriate source of randomness cannot be found, an Exception will be thrown by PHP 7+ 592387250efSPhy $error[] = $lang['i_urandom']; 593387250efSPhy $ok = false; 594387250efSPhy } 595387250efSPhy 596387250efSPhy if (ini_get('mbstring.func_overload') != 0) { 597387250efSPhy $error[] = $lang['i_mbfuncoverload']; 598387250efSPhy $ok = false; 599387250efSPhy } 600387250efSPhy 6013009a773SAndreas Gohr $funcs = explode(' ', 'addslashes call_user_func chmod copy fgets ' . 60247248316SAndreas Gohr 'file file_exists fseek flush filesize ftell fopen ' . 6033f6872b1SMyron Turner 'glob header ignore_user_abort ini_get mkdir ' . 60447248316SAndreas Gohr 'ob_start opendir parse_ini_file readfile realpath ' . 605bab4a8bdSAndreas Gohr 'rename rmdir serialize session_start unlink usleep ' . 606d1d99bb9SAndreas Gohr 'preg_replace file_get_contents htmlspecialchars_decode ' . 607670dc13dSAndreas Gohr 'spl_autoload_register stream_select fsockopen pack xml_parser_create'); 60847248316SAndreas Gohr 60970a6aa16Schris if (!function_exists('mb_substr')) { 61070a6aa16Schris $funcs[] = 'utf8_encode'; 61170a6aa16Schris $funcs[] = 'utf8_decode'; 61270a6aa16Schris } 61370a6aa16Schris 6143f6872b1SMyron Turner if (!function_exists('mail')) { 6153f6872b1SMyron Turner if (strpos(ini_get('disable_functions'), 'mail') !== false) { 6163f6872b1SMyron Turner $disabled = $lang['i_disabled']; 617db581254Sjpedryc } else { 6183f6872b1SMyron Turner $disabled = ""; 6193f6872b1SMyron Turner } 6203f6872b1SMyron Turner $error[] = sprintf($lang['i_funcnmail'], $disabled); 6213f6872b1SMyron Turner } 6223f6872b1SMyron Turner 62347248316SAndreas Gohr foreach ($funcs as $func) { 62447248316SAndreas Gohr if (!function_exists($func)) { 62547248316SAndreas Gohr $error[] = sprintf($lang['i_funcna'], $func); 62647248316SAndreas Gohr $ok = false; 62747248316SAndreas Gohr } 62847248316SAndreas Gohr } 62947248316SAndreas Gohr return $ok; 63047248316SAndreas Gohr} 63147248316SAndreas Gohr 63247248316SAndreas Gohr/** 63347248316SAndreas Gohr * Print language selection 63447248316SAndreas Gohr * 63547248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 63647248316SAndreas Gohr */ 637db581254Sjpedrycfunction langsel() 638db581254Sjpedryc{ 63947248316SAndreas Gohr global $lang; 64047248316SAndreas Gohr global $LC; 64147248316SAndreas Gohr 64247248316SAndreas Gohr $dir = DOKU_INC . 'inc/lang'; 64347248316SAndreas Gohr $dh = opendir($dir); 64447248316SAndreas Gohr if (!$dh) return; 64547248316SAndreas Gohr 646*b1f206e1SAndreas Gohr $langs = []; 64747248316SAndreas Gohr while (($file = readdir($dh)) !== false) { 64847248316SAndreas Gohr if (preg_match('/^[\._]/', $file)) continue; 64979e79377SAndreas Gohr if (is_dir($dir . '/' . $file) && file_exists($dir . '/' . $file . '/lang.php')) { 65047248316SAndreas Gohr $langs[] = $file; 65147248316SAndreas Gohr } 65247248316SAndreas Gohr } 65347248316SAndreas Gohr closedir($dh); 65447248316SAndreas Gohr sort($langs); 65547248316SAndreas Gohr 65647248316SAndreas Gohr echo '<form action="">'; 65747248316SAndreas Gohr echo $lang['i_chooselang']; 65847248316SAndreas Gohr echo ': <select name="l" onchange="submit()">'; 65947248316SAndreas Gohr foreach ($langs as $l) { 66047248316SAndreas Gohr $sel = ($l == $LC) ? 'selected="selected"' : ''; 66147248316SAndreas Gohr echo '<option value="' . $l . '" ' . $sel . '>' . $l . '</option>'; 66247248316SAndreas Gohr } 66347248316SAndreas Gohr echo '</select> '; 664ae614416SAnika Henke echo '<button type="submit">' . $lang['btn_update'] . '</button>'; 66547248316SAndreas Gohr echo '</form>'; 66647248316SAndreas Gohr} 66747248316SAndreas Gohr 66847248316SAndreas Gohr/** 669c66972f2SAdrian Lang * Print global error array 67047248316SAndreas Gohr * 67147248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 67247248316SAndreas Gohr */ 673db581254Sjpedrycfunction print_errors() 674db581254Sjpedryc{ 67547248316SAndreas Gohr global $error; 6764b530faaSTom N Harris if (!empty($error)) { 67747248316SAndreas Gohr echo '<ul>'; 67847248316SAndreas Gohr foreach ($error as $err) { 67947248316SAndreas Gohr echo "<li>$err</li>"; 68047248316SAndreas Gohr } 68147248316SAndreas Gohr echo '</ul>'; 68247248316SAndreas Gohr } 6834b530faaSTom N Harris} 684