15cfb8815Schris<?php 2ac251797SAndreas Gohr/*><div style="width:60%; margin: auto; background-color: #fcc; 3ac251797SAndreas Gohr border: 1px solid #faa; padding: 0.5em 1em;"> 4ac251797SAndreas Gohr <h1 style="font-size: 120%">No PHP Support</h1> 5ac251797SAndreas Gohr 6ac251797SAndreas Gohr It seems this server has no PHP support enabled. You will need to 7ac251797SAndreas Gohr enable PHP before you can install and run DokuWiki. Contact your hosting 8ac251797SAndreas Gohr provider if you're unsure what this means. 9ac251797SAndreas Gohr 10ac251797SAndreas Gohr</div>*/ 11*0f2c316aSAndreas Gohr 12*0f2c316aSAndreas Gohruse dokuwiki\PassHash; 135cfb8815Schris 14b1f206e1SAndreas Gohrif (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/'); 155cfb8815Schrisif (!defined('DOKU_CONF')) define('DOKU_CONF', DOKU_INC . 'conf/'); 165cfb8815Schrisif (!defined('DOKU_LOCAL')) define('DOKU_LOCAL', DOKU_INC . 'conf/'); 175cfb8815Schris 1802bca5d4SYousong Zhou// load and initialize the core system 1902bca5d4SYousong Zhourequire_once(DOKU_INC . 'inc/init.php'); 202cb06bbdSjpedrycrequire_once(DOKU_INC . 'inc/pageutils.php'); 213791b589SAndreas Gohr 223545b2e0Schris// check for error reporting override or set error reporting to sane values 23db581254Sjpedrycif (!defined('DOKU_E_LEVEL')) { 24db581254Sjpedryc error_reporting(E_ALL ^ E_NOTICE); 25db581254Sjpedryc} else { 26db581254Sjpedryc error_reporting(DOKU_E_LEVEL); 27db581254Sjpedryc} 283545b2e0Schris 2947248316SAndreas Gohr// language strings 3047248316SAndreas Gohrrequire_once(DOKU_INC . 'inc/lang/en/lang.php'); 314b530faaSTom N Harrisif (isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) { 3247248316SAndreas Gohr $LC = preg_replace('/[^a-z\-]+/', '', $_REQUEST['l']); 334b530faaSTom N Harris} 344b530faaSTom N Harrisif (empty($LC)) $LC = 'en'; 3547248316SAndreas Gohrif ($LC && $LC != 'en') { 3647248316SAndreas Gohr require_once(DOKU_INC . 'inc/lang/' . $LC . '/lang.php'); 3747248316SAndreas Gohr} 3847248316SAndreas Gohr 3947248316SAndreas Gohr// initialise variables ... 40b1f206e1SAndreas Gohr$error = []; 4147248316SAndreas Gohr 4247248316SAndreas Gohr// begin output 4347248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8'); 4447248316SAndreas Gohr?> 45c8839c22SAnika Henke<!DOCTYPE html> 46c8839c22SAnika Henke<html lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>"> 4747248316SAndreas Gohr<head> 48c8839c22SAnika Henke <meta charset="utf-8" /> 494208c142SAndreas Gohr <title><?php echo $lang['i_installer']?></title> 5059305168SPhy <style> 5147248316SAndreas Gohr body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; } 5247248316SAndreas Gohr img { border: none } 5347248316SAndreas Gohr br.cl { clear:both; } 5470a6aa16Schris code { font-size: 110%; color: #800000; } 5547248316SAndreas Gohr fieldset { border: none } 569c70688aSchris label { display: block; margin-top: 0.5em; } 578af2e4bbSAndreas Gohr select.text, input.text { width: 30em; margin: 0 0.5em; } 5806361442SAndreas Gohr a {text-decoration: none} 5947248316SAndreas Gohr </style> 6059305168SPhy <script> 6147248316SAndreas Gohr function acltoggle(){ 6247248316SAndreas Gohr var cb = document.getElementById('acl'); 6347248316SAndreas Gohr var fs = document.getElementById('acldep'); 6447248316SAndreas Gohr if(!cb || !fs) return; 6547248316SAndreas Gohr if(cb.checked){ 6647248316SAndreas Gohr fs.style.display = ''; 6747248316SAndreas Gohr }else{ 6847248316SAndreas Gohr fs.style.display = 'none'; 6947248316SAndreas Gohr } 7047248316SAndreas Gohr } 7147248316SAndreas Gohr window.onload = function(){ 7247248316SAndreas Gohr acltoggle(); 7347248316SAndreas Gohr var cb = document.getElementById('acl'); 7447248316SAndreas Gohr if(cb) cb.onchange = acltoggle; 7547248316SAndreas Gohr }; 7647248316SAndreas Gohr </script> 7747248316SAndreas Gohr</head> 7847248316SAndreas Gohr<body style=""> 7947248316SAndreas Gohr <h1 style="float:left"> 80c5270434SAndreas Gohr <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png" 81c5270434SAndreas Gohr style="vertical-align: middle;" alt="" height="64" width="64" /> 8247248316SAndreas Gohr <?php echo $lang['i_installer']?> 8347248316SAndreas Gohr </h1> 8447248316SAndreas Gohr <div style="float:right; margin: 1em;"> 8547248316SAndreas Gohr <?php langsel()?> 8647248316SAndreas Gohr </div> 8747248316SAndreas Gohr <br class="cl" /> 8847248316SAndreas Gohr 8947248316SAndreas Gohr <div style="float: right; width: 34%;"> 9047248316SAndreas Gohr <?php 9179e79377SAndreas Gohr if (file_exists(DOKU_INC . 'inc/lang/' . $LC . '/install.html')) { 9247248316SAndreas Gohr include(DOKU_INC . 'inc/lang/' . $LC . '/install.html'); 9347248316SAndreas Gohr } else { 94ca64d724Schris print "<div lang=\"en\" dir=\"ltr\">\n"; 9547248316SAndreas Gohr include(DOKU_INC . 'inc/lang/en/install.html'); 96ca64d724Schris print "</div>\n"; 9747248316SAndreas Gohr } 9847248316SAndreas Gohr ?> 9964159a61SAndreas Gohr <a style=" 10064159a61SAndreas Gohr background: transparent 10164159a61SAndreas Gohr url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png) 10264159a61SAndreas Gohr left top no-repeat; 103c8b43921SAndreas Gohr display: block; width:380px; height:73px; border:none; clear:both;" 104c8b43921SAndreas Gohr target="_blank" 105c8b43921SAndreas Gohr href="http://www.dokuwiki.org/security#web_access_security"></a> 10647248316SAndreas Gohr </div> 10747248316SAndreas Gohr 10847248316SAndreas Gohr <div style="float: left; width: 58%;"> 10947248316SAndreas Gohr <?php 1107ac1baa0SL. Ivanovich Harrison try { 11147248316SAndreas Gohr if (! (check_functions() && check_permissions())) { 11247248316SAndreas Gohr echo '<p>' . $lang['i_problems'] . '</p>'; 11347248316SAndreas Gohr print_errors(); 11470a6aa16Schris print_retry(); 11547248316SAndreas Gohr } elseif (!check_configs()) { 11647248316SAndreas Gohr echo '<p>' . $lang['i_modified'] . '</p>'; 11747248316SAndreas Gohr print_errors(); 1184b530faaSTom N Harris } elseif (check_data($_REQUEST['d'])) { 1194b530faaSTom N Harris // check_data has sanitized all input parameters 1204b530faaSTom N Harris if (!store_data($_REQUEST['d'])) { 12147248316SAndreas Gohr echo '<p>' . $lang['i_failure'] . '</p>'; 12247248316SAndreas Gohr print_errors(); 12347248316SAndreas Gohr } else { 12447248316SAndreas Gohr echo '<p>' . $lang['i_success'] . '</p>'; 12547248316SAndreas Gohr } 12647248316SAndreas Gohr } else { 1274b530faaSTom N Harris print_errors(); 12847248316SAndreas Gohr print_form($_REQUEST['d']); 12947248316SAndreas Gohr } 1307ac1baa0SL. Ivanovich Harrison } catch (Exception $e) { 1317ac1baa0SL. Ivanovich Harrison echo 'Caught exception: ', $e->getMessage(), "\n"; 1327ac1baa0SL. Ivanovich Harrison } 13347248316SAndreas Gohr ?> 13447248316SAndreas Gohr </div> 13547248316SAndreas Gohr 136c8b43921SAndreas Gohr 13747248316SAndreas Gohr<div style="clear: both"> 138654436fbSAnika Henke <a href="http://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki" /></a> 13959752844SAnders Sandblad <a href="http://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP" /></a> 14047248316SAndreas Gohr</div> 14147248316SAndreas Gohr</body> 14247248316SAndreas Gohr</html> 14347248316SAndreas Gohr<?php 14447248316SAndreas Gohr 14547248316SAndreas Gohr/** 14647248316SAndreas Gohr * Print the input form 147253d4b48SGerrit Uitslag * 148253d4b48SGerrit Uitslag * @param array $d submitted entry 'd' of request data 14947248316SAndreas Gohr */ 150db581254Sjpedrycfunction print_form($d) 151db581254Sjpedryc{ 15247248316SAndreas Gohr global $lang; 15347248316SAndreas Gohr global $LC; 15447248316SAndreas Gohr 15506361442SAndreas Gohr include(DOKU_CONF . 'license.php'); 15606361442SAndreas Gohr 157b1f206e1SAndreas Gohr if (!is_array($d)) $d = []; 15865cc1598SPhy $d = array_map('hsc', $d); 15947248316SAndreas Gohr 16047248316SAndreas Gohr if (!isset($d['acl'])) $d['acl'] = 1; 1613a0852d9SAndreas Gohr if (!isset($d['pop'])) $d['pop'] = 1; 16247248316SAndreas Gohr 16347248316SAndreas Gohr ?> 16447248316SAndreas Gohr <form action="" method="post"> 16547248316SAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>" /> 16647248316SAndreas Gohr <fieldset> 16747248316SAndreas Gohr <label for="title"><?php echo $lang['i_wikiname']?> 16847248316SAndreas Gohr <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" /> 16947248316SAndreas Gohr </label> 17047248316SAndreas Gohr 17147248316SAndreas Gohr <fieldset style="margin-top: 1em;"> 17247248316SAndreas Gohr <label for="acl"> 17347248316SAndreas Gohr <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : ''));?> /> 17447248316SAndreas Gohr <?php echo $lang['i_enableacl']?></label> 17547248316SAndreas Gohr 17647248316SAndreas Gohr <fieldset id="acldep"> 17747248316SAndreas Gohr <label for="superuser"><?php echo $lang['i_superuser']?></label> 17864159a61SAndreas Gohr <input class="text" type="text" name="d[superuser]" id="superuser" 17964159a61SAndreas Gohr value="<?php echo $d['superuser'] ?>" /> 18047248316SAndreas Gohr 18147248316SAndreas Gohr <label for="fullname"><?php echo $lang['fullname']?></label> 18264159a61SAndreas Gohr <input class="text" type="text" name="d[fullname]" id="fullname" 18364159a61SAndreas Gohr value="<?php echo $d['fullname'] ?>" /> 18447248316SAndreas Gohr 18547248316SAndreas Gohr <label for="email"><?php echo $lang['email']?></label> 18647248316SAndreas Gohr <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" /> 18747248316SAndreas Gohr 18847248316SAndreas Gohr <label for="password"><?php echo $lang['pass']?></label> 18947248316SAndreas Gohr <input class="text" type="password" name="d[password]" id="password" /> 19047248316SAndreas Gohr 19147248316SAndreas Gohr <label for="confirm"><?php echo $lang['passchk']?></label> 19247248316SAndreas Gohr <input class="text" type="password" name="d[confirm]" id="confirm" /> 1938af2e4bbSAndreas Gohr 1948af2e4bbSAndreas Gohr <label for="policy"><?php echo $lang['i_policy']?></label> 1958af2e4bbSAndreas Gohr <select class="text" name="d[policy]" id="policy"> 19664159a61SAndreas Gohr <option value="0" <?php echo ($d['policy'] == 0) ? 'selected="selected"' : '' ?>><?php 19764159a61SAndreas Gohr echo $lang['i_pol0']?></option> 19864159a61SAndreas Gohr <option value="1" <?php echo ($d['policy'] == 1) ? 'selected="selected"' : '' ?>><?php 19964159a61SAndreas Gohr echo $lang['i_pol1']?></option> 20064159a61SAndreas Gohr <option value="2" <?php echo ($d['policy'] == 2) ? 'selected="selected"' : '' ?>><?php 20164159a61SAndreas Gohr echo $lang['i_pol2']?></option> 2028af2e4bbSAndreas Gohr </select> 20306361442SAndreas Gohr 204ab9346edSAnika Henke <label for="allowreg"> 20564159a61SAndreas Gohr <input type="checkbox" name="d[allowreg]" id="allowreg" <?php 20664159a61SAndreas Gohr echo(($d['allowreg'] ? ' checked="checked"' : ''));?> /> 207ab9346edSAnika Henke <?php echo $lang['i_allowreg']?> 20874850f29SAnika Henke </label> 20947248316SAndreas Gohr </fieldset> 21047248316SAndreas Gohr </fieldset> 21147248316SAndreas Gohr 21206361442SAndreas Gohr <fieldset> 21306361442SAndreas Gohr <p><?php echo $lang['i_license']?></p> 21406361442SAndreas Gohr <?php 215b1f206e1SAndreas Gohr $license[] = ['name' => $lang['i_license_none'], 'url' => '']; 216ed856534STom N Harris if (empty($d['license'])) $d['license'] = 'cc-by-sa'; 21706361442SAndreas Gohr foreach ($license as $key => $lic) { 21806361442SAndreas Gohr echo '<label for="lic_' . $key . '">'; 21965cc1598SPhy echo '<input type="radio" name="d[license]" value="' . hsc($key) . '" id="lic_' . $key . '"' . 220b1730bd2STom N Harris (($d['license'] === $key) ? ' checked="checked"' : '') . '>'; 22165cc1598SPhy echo hsc($lic['name']); 22206361442SAndreas Gohr if ($lic['url']) echo ' <a href="' . $lic['url'] . '" target="_blank"><sup>[?]</sup></a>'; 22306361442SAndreas Gohr echo '</label>'; 22406361442SAndreas Gohr } 22506361442SAndreas Gohr ?> 22606361442SAndreas Gohr </fieldset> 22706361442SAndreas Gohr 2283a0852d9SAndreas Gohr <fieldset> 2293a0852d9SAndreas Gohr <p><?php echo $lang['i_pop_field']?></p> 2303a0852d9SAndreas Gohr <label for="pop"> 23164159a61SAndreas Gohr <input type="checkbox" name="d[pop]" id="pop" <?php 23264159a61SAndreas Gohr echo(($d['pop'] ? ' checked="checked"' : ''));?> /> 23364159a61SAndreas Gohr <?php echo $lang['i_pop_label']?> 23464159a61SAndreas Gohr <a href="http://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a> 2353a0852d9SAndreas Gohr </label> 2363a0852d9SAndreas Gohr </fieldset> 2373a0852d9SAndreas Gohr 23847248316SAndreas Gohr </fieldset> 23947248316SAndreas Gohr <fieldset id="process"> 240ae614416SAnika Henke <button type="submit" name="submit"><?php echo $lang['btn_save']?></button> 24147248316SAndreas Gohr </fieldset> 24247248316SAndreas Gohr </form> 24347248316SAndreas Gohr <?php 24447248316SAndreas Gohr} 24547248316SAndreas Gohr 246db581254Sjpedrycfunction print_retry() 247db581254Sjpedryc{ 24870a6aa16Schris global $lang; 2499ad6da3dSAndreas Gohr global $LC; 25070a6aa16Schris ?> 25170a6aa16Schris <form action="" method="get"> 25270a6aa16Schris <fieldset> 2539ad6da3dSAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>" /> 254ae614416SAnika Henke <button type="submit"><?php echo $lang['i_retry'];?></button> 25570a6aa16Schris </fieldset> 25670a6aa16Schris </form> 25770a6aa16Schris <?php 25870a6aa16Schris} 25970a6aa16Schris 26047248316SAndreas Gohr/** 26147248316SAndreas Gohr * Check validity of data 26247248316SAndreas Gohr * 26347248316SAndreas Gohr * @author Andreas Gohr 264253d4b48SGerrit Uitslag * 265253d4b48SGerrit Uitslag * @param array $d 266253d4b48SGerrit Uitslag * @return bool ok? 26747248316SAndreas Gohr */ 268db581254Sjpedrycfunction check_data(&$d) 269db581254Sjpedryc{ 270b1f206e1SAndreas Gohr static $form_default = [ 2714b530faaSTom N Harris 'title' => '', 272ed856534STom N Harris 'acl' => '1', 2734b530faaSTom N Harris 'superuser' => '', 2744b530faaSTom N Harris 'fullname' => '', 2754b530faaSTom N Harris 'email' => '', 2764b530faaSTom N Harris 'password' => '', 2774b530faaSTom N Harris 'confirm' => '', 2784b530faaSTom N Harris 'policy' => '0', 279ab9346edSAnika Henke 'allowreg' => '0', 2804b530faaSTom N Harris 'license' => 'cc-by-sa' 281b1f206e1SAndreas Gohr ]; 28247248316SAndreas Gohr global $lang; 28347248316SAndreas Gohr global $error; 28447248316SAndreas Gohr 285b1f206e1SAndreas Gohr if (!is_array($d)) $d = []; 2864b530faaSTom N Harris foreach ($d as $k => $v) { 2874b530faaSTom N Harris if (is_array($v)) 2884b530faaSTom N Harris unset($d[$k]); 289db581254Sjpedryc else $d[$k] = (string)$v; 2904b530faaSTom N Harris } 291e2386079SAndreas Gohr 2924b530faaSTom N Harris //autolowercase the username 2934b530faaSTom N Harris $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : ""; 2944b530faaSTom N Harris 2954b530faaSTom N Harris $ok = false; 2964b530faaSTom N Harris 2974b530faaSTom N Harris if (isset($_REQUEST['submit'])) { 29847248316SAndreas Gohr $ok = true; 29947248316SAndreas Gohr 30047248316SAndreas Gohr // check input 30147248316SAndreas Gohr if (empty($d['title'])) { 30247248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['i_wikiname']); 30347248316SAndreas Gohr $ok = false; 30447248316SAndreas Gohr } 3054b530faaSTom N Harris if (isset($d['acl'])) { 3062cb06bbdSjpedryc if (empty($d['superuser']) || ($d['superuser'] !== cleanID($d['superuser']))) { 30747248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['i_superuser']); 30847248316SAndreas Gohr $ok = false; 30947248316SAndreas Gohr } 31047248316SAndreas Gohr if (empty($d['password'])) { 31147248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['pass']); 31247248316SAndreas Gohr $ok = false; 313db581254Sjpedryc } elseif (!isset($d['confirm']) || $d['confirm'] != $d['password']) { 31447248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['passchk']); 31547248316SAndreas Gohr $ok = false; 31647248316SAndreas Gohr } 31747248316SAndreas Gohr if (empty($d['fullname']) || strstr($d['fullname'], ':')) { 31847248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['fullname']); 31947248316SAndreas Gohr $ok = false; 32047248316SAndreas Gohr } 321e2386079SAndreas Gohr if (empty($d['email']) || strstr($d['email'], ':') || !strstr($d['email'], '@')) { 32247248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['email']); 32347248316SAndreas Gohr $ok = false; 32447248316SAndreas Gohr } 325b9ab8e4fSPhy } else { 326b9ab8e4fSPhy // Since default = 1, browser won't send acl=0 when user untick acl 327b9ab8e4fSPhy $d['acl'] = '0'; 32847248316SAndreas Gohr } 3294b530faaSTom N Harris } 3304b530faaSTom N Harris $d = array_merge($form_default, $d); 33147248316SAndreas Gohr return $ok; 33247248316SAndreas Gohr} 33347248316SAndreas Gohr 33447248316SAndreas Gohr/** 33547248316SAndreas Gohr * Writes the data to the config files 33647248316SAndreas Gohr * 33747248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 338253d4b48SGerrit Uitslag * 339253d4b48SGerrit Uitslag * @param array $d 340253d4b48SGerrit Uitslag * @return bool 34147248316SAndreas Gohr */ 342db581254Sjpedrycfunction store_data($d) 343db581254Sjpedryc{ 3440036aa89SAndreas Gohr global $LC; 34547248316SAndreas Gohr $ok = true; 3468af2e4bbSAndreas Gohr $d['policy'] = (int) $d['policy']; 34747248316SAndreas Gohr 34847248316SAndreas Gohr // create local.php 34924650a19SAndreas Gohr $now = gmdate('r'); 35047248316SAndreas Gohr $output = <<<EOT 35147248316SAndreas Gohr<?php 35247248316SAndreas Gohr/** 35347248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings 35447248316SAndreas Gohr * Auto-generated by install script 35547248316SAndreas Gohr * Date: $now 35647248316SAndreas Gohr */ 35747248316SAndreas Gohr 35847248316SAndreas GohrEOT; 3592613efa1SAndreas Gohr // add any config options set by a previous installer 3602613efa1SAndreas Gohr $preset = __DIR__ . '/install.conf'; 3612613efa1SAndreas Gohr if (file_exists($preset)) { 3622613efa1SAndreas Gohr $output .= "# preset config options\n"; 3632613efa1SAndreas Gohr $output .= file_get_contents($preset); 3642613efa1SAndreas Gohr $output .= "\n\n"; 3652613efa1SAndreas Gohr $output .= "# options selected in installer\n"; 3662613efa1SAndreas Gohr @unlink($preset); 3672613efa1SAndreas Gohr } 3682613efa1SAndreas Gohr 36947248316SAndreas Gohr $output .= '$conf[\'title\'] = \'' . addslashes($d['title']) . "';\n"; 3700036aa89SAndreas Gohr $output .= '$conf[\'lang\'] = \'' . addslashes($LC) . "';\n"; 37106361442SAndreas Gohr $output .= '$conf[\'license\'] = \'' . addslashes($d['license']) . "';\n"; 37247248316SAndreas Gohr if ($d['acl']) { 37347248316SAndreas Gohr $output .= '$conf[\'useacl\'] = 1' . ";\n"; 374523d7ea6Schris $output .= "\$conf['superuser'] = '@admin';\n"; 37547248316SAndreas Gohr } 376ab9346edSAnika Henke if (!$d['allowreg']) { 37743c137edSAnika Henke $output .= '$conf[\'disableactions\'] = \'register\'' . ";\n"; 378d2ea6dc1SAnika Henke } 37947248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'local.php', $output); 38047248316SAndreas Gohr 38147248316SAndreas Gohr if ($d['acl']) { 3823791b589SAndreas Gohr // hash the password 383b1f206e1SAndreas Gohr $phash = new PassHash(); 384267bbbcaSms101 $pass = $phash->hash_bcrypt($d['password']); 3853791b589SAndreas Gohr 38647248316SAndreas Gohr // create users.auth.php 387a672ef75SPhy $output = <<<EOT 388a672ef75SPhy# users.auth.php 389a672ef75SPhy# <?php exit()?> 390a672ef75SPhy# Don't modify the lines above 391a672ef75SPhy# 392a672ef75SPhy# Userfile 393a672ef75SPhy# 394a672ef75SPhy# Auto-generated by install script 395a672ef75SPhy# Date: $now 396a672ef75SPhy# 397a672ef75SPhy# Format: 398a672ef75SPhy# login:passwordhash:Real Name:email:groups,comma,separated 399a672ef75SPhy 400a672ef75SPhyEOT; 401722372bdSms101 // --- user:bcryptpasswordhash:Real Name:email:groups,comma,seperated 402b1f206e1SAndreas Gohr $output = $output . "\n" . implode(':', [ 40336a1a880SAndreas Gohr $d['superuser'], 40436a1a880SAndreas Gohr $pass, 40536a1a880SAndreas Gohr $d['fullname'], 40636a1a880SAndreas Gohr $d['email'], 40736a1a880SAndreas Gohr 'admin,user', 40836a1a880SAndreas Gohr ]) . "\n"; 40947248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'users.auth.php', $output); 41047248316SAndreas Gohr 41147248316SAndreas Gohr // create acl.auth.php 4128af2e4bbSAndreas Gohr $output = <<<EOT 4138af2e4bbSAndreas Gohr# acl.auth.php 4148af2e4bbSAndreas Gohr# <?php exit()?> 4158af2e4bbSAndreas Gohr# Don't modify the lines above 4168af2e4bbSAndreas Gohr# 4178af2e4bbSAndreas Gohr# Access Control Lists 4188af2e4bbSAndreas Gohr# 4198af2e4bbSAndreas Gohr# Auto-generated by install script 4208af2e4bbSAndreas Gohr# Date: $now 4218af2e4bbSAndreas Gohr 4228af2e4bbSAndreas GohrEOT; 4238af2e4bbSAndreas Gohr if ($d['policy'] == 2) { 4248af2e4bbSAndreas Gohr $output .= "* @ALL 0\n"; 425d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4269c70688aSchris } elseif ($d['policy'] == 1) { 4278af2e4bbSAndreas Gohr $output .= "* @ALL 1\n"; 428d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4298af2e4bbSAndreas Gohr } else { 4308af2e4bbSAndreas Gohr $output .= "* @ALL 8\n"; 4318af2e4bbSAndreas Gohr } 43247248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'acl.auth.php', $output); 43347248316SAndreas Gohr } 4343a0852d9SAndreas Gohr 4353a0852d9SAndreas Gohr // enable popularity submission 436ee4f28e3SDamien Regad if (isset($d['pop']) && $d['pop']) { 4373a0852d9SAndreas Gohr @touch(DOKU_INC . 'data/cache/autosubmit.txt'); 4383a0852d9SAndreas Gohr } 4393a0852d9SAndreas Gohr 440c70d6ceeSAndreas Gohr // disable auth plugins til needed 441c70d6ceeSAndreas Gohr $output = <<<EOT 442c70d6ceeSAndreas Gohr<?php 443c70d6ceeSAndreas Gohr/* 444c70d6ceeSAndreas Gohr * Local plugin enable/disable settings 445c70d6ceeSAndreas Gohr * 446c70d6ceeSAndreas Gohr * Auto-generated by install script 447c70d6ceeSAndreas Gohr * Date: $now 448c70d6ceeSAndreas Gohr */ 449c70d6ceeSAndreas Gohr 450c70d6ceeSAndreas Gohr\$plugins['authad'] = 0; 451c70d6ceeSAndreas Gohr\$plugins['authldap'] = 0; 452c70d6ceeSAndreas Gohr\$plugins['authmysql'] = 0; 453c70d6ceeSAndreas Gohr\$plugins['authpgsql'] = 0; 454c70d6ceeSAndreas Gohr 455c70d6ceeSAndreas GohrEOT; 456c70d6ceeSAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'plugins.local.php', $output); 457c70d6ceeSAndreas Gohr 45847248316SAndreas Gohr return $ok; 45947248316SAndreas Gohr} 46047248316SAndreas Gohr 46147248316SAndreas Gohr/** 46247248316SAndreas Gohr * Write the given content to a file 46347248316SAndreas Gohr * 46447248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 465253d4b48SGerrit Uitslag * 466253d4b48SGerrit Uitslag * @param string $filename 467253d4b48SGerrit Uitslag * @param string $data 468253d4b48SGerrit Uitslag * @return bool 46947248316SAndreas Gohr */ 470db581254Sjpedrycfunction fileWrite($filename, $data) 471db581254Sjpedryc{ 47247248316SAndreas Gohr global $error; 47347248316SAndreas Gohr global $lang; 47447248316SAndreas Gohr 47547248316SAndreas Gohr if (($fp = @fopen($filename, 'wb')) === false) { 47647248316SAndreas Gohr $filename = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $filename); 47747248316SAndreas Gohr $error[] = sprintf($lang['i_writeerr'], $filename); 47847248316SAndreas Gohr return false; 47947248316SAndreas Gohr } 48047248316SAndreas Gohr 481db581254Sjpedryc if (!empty($data)) { 482db581254Sjpedryc fwrite($fp, $data); 483db581254Sjpedryc } 48447248316SAndreas Gohr fclose($fp); 48547248316SAndreas Gohr return true; 48647248316SAndreas Gohr} 48747248316SAndreas Gohr 48847248316SAndreas Gohr 48947248316SAndreas Gohr/** 49047248316SAndreas Gohr * check installation dependent local config files and tests for a known 49147248316SAndreas Gohr * unmodified main config file 49247248316SAndreas Gohr * 49347248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 494253d4b48SGerrit Uitslag * 495253d4b48SGerrit Uitslag * @return bool 49647248316SAndreas Gohr */ 497db581254Sjpedrycfunction check_configs() 498db581254Sjpedryc{ 49947248316SAndreas Gohr global $error; 50047248316SAndreas Gohr global $lang; 50147248316SAndreas Gohr 50247248316SAndreas Gohr $ok = true; 50347248316SAndreas Gohr 504b1f206e1SAndreas Gohr $config_files = [ 5055cfb8815Schris 'local' => DOKU_LOCAL . 'local.php', 5065cfb8815Schris 'users' => DOKU_LOCAL . 'users.auth.php', 5075cfb8815Schris 'auth' => DOKU_LOCAL . 'acl.auth.php' 508b1f206e1SAndreas Gohr ]; 5095cfb8815Schris 51047248316SAndreas Gohr // configs shouldn't exist 51147248316SAndreas Gohr foreach ($config_files as $file) { 51279e79377SAndreas Gohr if (file_exists($file) && filesize($file)) { 51347248316SAndreas Gohr $file = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $file); 51447248316SAndreas Gohr $error[] = sprintf($lang['i_confexists'], $file); 51547248316SAndreas Gohr $ok = false; 51647248316SAndreas Gohr } 51747248316SAndreas Gohr } 51847248316SAndreas Gohr return $ok; 51947248316SAndreas Gohr} 52047248316SAndreas Gohr 52147248316SAndreas Gohr 52247248316SAndreas Gohr/** 52347248316SAndreas Gohr * Check other installation dir/file permission requirements 52447248316SAndreas Gohr * 52547248316SAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 526253d4b48SGerrit Uitslag * 527253d4b48SGerrit Uitslag * @return bool 52847248316SAndreas Gohr */ 529db581254Sjpedrycfunction check_permissions() 530db581254Sjpedryc{ 53147248316SAndreas Gohr global $error; 53247248316SAndreas Gohr global $lang; 53347248316SAndreas Gohr 534b1f206e1SAndreas Gohr $dirs = [ 53547248316SAndreas Gohr 'conf' => DOKU_LOCAL, 53647248316SAndreas Gohr 'data' => DOKU_INC . 'data', 53747248316SAndreas Gohr 'pages' => DOKU_INC . 'data/pages', 53847248316SAndreas Gohr 'attic' => DOKU_INC . 'data/attic', 53947248316SAndreas Gohr 'media' => DOKU_INC . 'data/media', 54049b78edaSAndreas Gohr 'media_attic' => DOKU_INC . 'data/media_attic', 54149b78edaSAndreas Gohr 'media_meta' => DOKU_INC . 'data/media_meta', 54247248316SAndreas Gohr 'meta' => DOKU_INC . 'data/meta', 54347248316SAndreas Gohr 'cache' => DOKU_INC . 'data/cache', 54447248316SAndreas Gohr 'locks' => DOKU_INC . 'data/locks', 5459711045aSAndreas Gohr 'index' => DOKU_INC . 'data/index', 546de33a58fSMichael Klier 'tmp' => DOKU_INC . 'data/tmp' 547b1f206e1SAndreas Gohr ]; 54847248316SAndreas Gohr 54947248316SAndreas Gohr $ok = true; 55047248316SAndreas Gohr foreach ($dirs as $dir) { 55179e79377SAndreas Gohr if (!file_exists("$dir/.") || !is_writable($dir)) { 55270a6aa16Schris $dir = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}', $dir); 55347248316SAndreas Gohr $error[] = sprintf($lang['i_permfail'], $dir); 55447248316SAndreas Gohr $ok = false; 55547248316SAndreas Gohr } 55647248316SAndreas Gohr } 55747248316SAndreas Gohr return $ok; 55847248316SAndreas Gohr} 55947248316SAndreas Gohr 56047248316SAndreas Gohr/** 5613afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version 56247248316SAndreas Gohr * 56347248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 564253d4b48SGerrit Uitslag * 565253d4b48SGerrit Uitslag * @return bool 56647248316SAndreas Gohr */ 567db581254Sjpedrycfunction check_functions() 568db581254Sjpedryc{ 56947248316SAndreas Gohr global $error; 57047248316SAndreas Gohr global $lang; 5713afe5d1cSAndreas Gohr $ok = true; 5723afe5d1cSAndreas Gohr 573c49393f5SAndreas Gohr if (version_compare(phpversion(), '7.4.0', '<')) { 574c49393f5SAndreas Gohr $error[] = sprintf($lang['i_phpver'], phpversion(), '7.4.0'); 5753afe5d1cSAndreas Gohr $ok = false; 5763afe5d1cSAndreas Gohr } 5773afe5d1cSAndreas Gohr 5787f413440SAndreas Gohr if (ini_get('mbstring.func_overload') != 0) { 5797f413440SAndreas Gohr $error[] = $lang['i_mbfuncoverload']; 5807f413440SAndreas Gohr $ok = false; 5817f413440SAndreas Gohr } 5827f413440SAndreas Gohr 583387250efSPhy try { 584387250efSPhy random_bytes(1); 585387250efSPhy } catch (\Exception $th) { 586387250efSPhy // If an appropriate source of randomness cannot be found, an Exception will be thrown by PHP 7+ 587387250efSPhy $error[] = $lang['i_urandom']; 588387250efSPhy $ok = false; 589387250efSPhy } 590387250efSPhy 591387250efSPhy if (ini_get('mbstring.func_overload') != 0) { 592387250efSPhy $error[] = $lang['i_mbfuncoverload']; 593387250efSPhy $ok = false; 594387250efSPhy } 595387250efSPhy 5963009a773SAndreas Gohr $funcs = explode(' ', 'addslashes call_user_func chmod copy fgets ' . 59747248316SAndreas Gohr 'file file_exists fseek flush filesize ftell fopen ' . 5983f6872b1SMyron Turner 'glob header ignore_user_abort ini_get mkdir ' . 59947248316SAndreas Gohr 'ob_start opendir parse_ini_file readfile realpath ' . 600bab4a8bdSAndreas Gohr 'rename rmdir serialize session_start unlink usleep ' . 601d1d99bb9SAndreas Gohr 'preg_replace file_get_contents htmlspecialchars_decode ' . 602670dc13dSAndreas Gohr 'spl_autoload_register stream_select fsockopen pack xml_parser_create'); 60347248316SAndreas Gohr 60470a6aa16Schris if (!function_exists('mb_substr')) { 60570a6aa16Schris $funcs[] = 'utf8_encode'; 60670a6aa16Schris $funcs[] = 'utf8_decode'; 60770a6aa16Schris } 60870a6aa16Schris 6093f6872b1SMyron Turner if (!function_exists('mail')) { 6103f6872b1SMyron Turner if (strpos(ini_get('disable_functions'), 'mail') !== false) { 6113f6872b1SMyron Turner $disabled = $lang['i_disabled']; 612db581254Sjpedryc } else { 6133f6872b1SMyron Turner $disabled = ""; 6143f6872b1SMyron Turner } 6153f6872b1SMyron Turner $error[] = sprintf($lang['i_funcnmail'], $disabled); 6163f6872b1SMyron Turner } 6173f6872b1SMyron Turner 61847248316SAndreas Gohr foreach ($funcs as $func) { 61947248316SAndreas Gohr if (!function_exists($func)) { 62047248316SAndreas Gohr $error[] = sprintf($lang['i_funcna'], $func); 62147248316SAndreas Gohr $ok = false; 62247248316SAndreas Gohr } 62347248316SAndreas Gohr } 62447248316SAndreas Gohr return $ok; 62547248316SAndreas Gohr} 62647248316SAndreas Gohr 62747248316SAndreas Gohr/** 62847248316SAndreas Gohr * Print language selection 62947248316SAndreas Gohr * 63047248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 63147248316SAndreas Gohr */ 632db581254Sjpedrycfunction langsel() 633db581254Sjpedryc{ 63447248316SAndreas Gohr global $lang; 63547248316SAndreas Gohr global $LC; 63647248316SAndreas Gohr 63747248316SAndreas Gohr $dir = DOKU_INC . 'inc/lang'; 63847248316SAndreas Gohr $dh = opendir($dir); 63947248316SAndreas Gohr if (!$dh) return; 64047248316SAndreas Gohr 641b1f206e1SAndreas Gohr $langs = []; 64247248316SAndreas Gohr while (($file = readdir($dh)) !== false) { 64347248316SAndreas Gohr if (preg_match('/^[\._]/', $file)) continue; 64479e79377SAndreas Gohr if (is_dir($dir . '/' . $file) && file_exists($dir . '/' . $file . '/lang.php')) { 64547248316SAndreas Gohr $langs[] = $file; 64647248316SAndreas Gohr } 64747248316SAndreas Gohr } 64847248316SAndreas Gohr closedir($dh); 64947248316SAndreas Gohr sort($langs); 65047248316SAndreas Gohr 65147248316SAndreas Gohr echo '<form action="">'; 65247248316SAndreas Gohr echo $lang['i_chooselang']; 65347248316SAndreas Gohr echo ': <select name="l" onchange="submit()">'; 65447248316SAndreas Gohr foreach ($langs as $l) { 65547248316SAndreas Gohr $sel = ($l == $LC) ? 'selected="selected"' : ''; 65647248316SAndreas Gohr echo '<option value="' . $l . '" ' . $sel . '>' . $l . '</option>'; 65747248316SAndreas Gohr } 65847248316SAndreas Gohr echo '</select> '; 659ae614416SAnika Henke echo '<button type="submit">' . $lang['btn_update'] . '</button>'; 66047248316SAndreas Gohr echo '</form>'; 66147248316SAndreas Gohr} 66247248316SAndreas Gohr 66347248316SAndreas Gohr/** 664c66972f2SAdrian Lang * Print global error array 66547248316SAndreas Gohr * 66647248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 66747248316SAndreas Gohr */ 668db581254Sjpedrycfunction print_errors() 669db581254Sjpedryc{ 67047248316SAndreas Gohr global $error; 6714b530faaSTom N Harris if (!empty($error)) { 67247248316SAndreas Gohr echo '<ul>'; 67347248316SAndreas Gohr foreach ($error as $err) { 67447248316SAndreas Gohr echo "<li>$err</li>"; 67547248316SAndreas Gohr } 67647248316SAndreas Gohr echo '</ul>'; 67747248316SAndreas Gohr } 6784b530faaSTom N Harris} 679