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>*/ 110f2c316aSAndreas Gohr 120f2c316aSAndreas 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> 51ff84abadSGerrit Uitslag body { 52ff84abadSGerrit Uitslag width: 90%; 53ff84abadSGerrit Uitslag margin: 0 auto; 54ff84abadSGerrit Uitslag font: 84% Verdana, Helvetica, Arial, sans-serif; 55ff84abadSGerrit Uitslag } 56ff84abadSGerrit Uitslag 57ff84abadSGerrit Uitslag img { 58ff84abadSGerrit Uitslag border: none 59ff84abadSGerrit Uitslag } 60ff84abadSGerrit Uitslag 61ff84abadSGerrit Uitslag br.cl { 62ff84abadSGerrit Uitslag clear: both; 63ff84abadSGerrit Uitslag } 64ff84abadSGerrit Uitslag 65ff84abadSGerrit Uitslag code { 66ff84abadSGerrit Uitslag font-size: 110%; 67ff84abadSGerrit Uitslag color: #800000; 68ff84abadSGerrit Uitslag } 69ff84abadSGerrit Uitslag 70ff84abadSGerrit Uitslag fieldset { 71ff84abadSGerrit Uitslag border: none 72ff84abadSGerrit Uitslag } 73ff84abadSGerrit Uitslag 74ff84abadSGerrit Uitslag label { 75ff84abadSGerrit Uitslag display: block; 76ff84abadSGerrit Uitslag margin-top: 0.5em; 77ff84abadSGerrit Uitslag } 78ff84abadSGerrit Uitslag 79ff84abadSGerrit Uitslag select.text, input.text { 80ff84abadSGerrit Uitslag width: 30em; 81ff84abadSGerrit Uitslag margin: 0 0.5em; 82ff84abadSGerrit Uitslag } 83ff84abadSGerrit Uitslag 84ff84abadSGerrit Uitslag a { 85ff84abadSGerrit Uitslag text-decoration: none 86ff84abadSGerrit Uitslag } 8747248316SAndreas Gohr </style> 8859305168SPhy <script> 8947248316SAndreas Gohr function acltoggle() { 9047248316SAndreas Gohr var cb = document.getElementById('acl'); 9147248316SAndreas Gohr var fs = document.getElementById('acldep'); 9247248316SAndreas Gohr if (!cb || !fs) return; 9347248316SAndreas Gohr if (cb.checked) { 9447248316SAndreas Gohr fs.style.display = ''; 9547248316SAndreas Gohr } else { 9647248316SAndreas Gohr fs.style.display = 'none'; 9747248316SAndreas Gohr } 9847248316SAndreas Gohr } 99ff84abadSGerrit Uitslag 10047248316SAndreas Gohr window.onload = function () { 10147248316SAndreas Gohr acltoggle(); 10247248316SAndreas Gohr var cb = document.getElementById('acl'); 10347248316SAndreas Gohr if (cb) cb.onchange = acltoggle; 10447248316SAndreas Gohr }; 10547248316SAndreas Gohr </script> 10647248316SAndreas Gohr </head> 10747248316SAndreas Gohr <body style=""> 10847248316SAndreas Gohr <h1 style="float:left"> 109c5270434SAndreas Gohr <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png" 110c5270434SAndreas Gohr style="vertical-align: middle;" alt="" height="64" width="64"/> 11147248316SAndreas Gohr <?php echo $lang['i_installer'] ?> 11247248316SAndreas Gohr </h1> 11347248316SAndreas Gohr <div style="float:right; margin: 1em;"> 11447248316SAndreas Gohr <?php langsel() ?> 11547248316SAndreas Gohr </div> 11647248316SAndreas Gohr <br class="cl"/> 11747248316SAndreas Gohr 11847248316SAndreas Gohr <div style="float: right; width: 34%;"> 11947248316SAndreas Gohr <?php 12079e79377SAndreas Gohr if (file_exists(DOKU_INC . 'inc/lang/' . $LC . '/install.html')) { 12147248316SAndreas Gohr include(DOKU_INC . 'inc/lang/' . $LC . '/install.html'); 12247248316SAndreas Gohr } else { 123*26dfc232SAndreas Gohr echo "<div lang=\"en\" dir=\"ltr\">\n"; 12447248316SAndreas Gohr include(DOKU_INC . 'inc/lang/en/install.html'); 125*26dfc232SAndreas Gohr echo "</div>\n"; 12647248316SAndreas Gohr } 12747248316SAndreas Gohr ?> 12864159a61SAndreas Gohr <a style=" 12964159a61SAndreas Gohr background: transparent 13064159a61SAndreas Gohr url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png) 13164159a61SAndreas Gohr left top no-repeat; 132c8b43921SAndreas Gohr display: block; width:380px; height:73px; border:none; clear:both;" 133c8b43921SAndreas Gohr target="_blank" 134220897aeSGerrit Uitslag href="https://www.dokuwiki.org/security#web_access_security"></a> 13547248316SAndreas Gohr </div> 13647248316SAndreas Gohr 13747248316SAndreas Gohr <div style="float: left; width: 58%;"> 13847248316SAndreas Gohr <?php 1397ac1baa0SL. Ivanovich Harrison try { 14047248316SAndreas Gohr if (!(check_functions() && check_permissions())) { 14147248316SAndreas Gohr echo '<p>' . $lang['i_problems'] . '</p>'; 14247248316SAndreas Gohr print_errors(); 14370a6aa16Schris print_retry(); 14447248316SAndreas Gohr } elseif (!check_configs()) { 14547248316SAndreas Gohr echo '<p>' . $lang['i_modified'] . '</p>'; 14647248316SAndreas Gohr print_errors(); 1474b530faaSTom N Harris } elseif (check_data($_REQUEST['d'])) { 1484b530faaSTom N Harris // check_data has sanitized all input parameters 1494b530faaSTom N Harris if (!store_data($_REQUEST['d'])) { 15047248316SAndreas Gohr echo '<p>' . $lang['i_failure'] . '</p>'; 15147248316SAndreas Gohr print_errors(); 15247248316SAndreas Gohr } else { 15347248316SAndreas Gohr echo '<p>' . $lang['i_success'] . '</p>'; 15447248316SAndreas Gohr } 15547248316SAndreas Gohr } else { 1564b530faaSTom N Harris print_errors(); 15747248316SAndreas Gohr print_form($_REQUEST['d']); 15847248316SAndreas Gohr } 1597ac1baa0SL. Ivanovich Harrison } catch (Exception $e) { 1607ac1baa0SL. Ivanovich Harrison echo 'Caught exception: ', $e->getMessage(), "\n"; 1617ac1baa0SL. Ivanovich Harrison } 16247248316SAndreas Gohr ?> 16347248316SAndreas Gohr </div> 16447248316SAndreas Gohr 165c8b43921SAndreas Gohr 16647248316SAndreas Gohr <div style="clear: both"> 167220897aeSGerrit Uitslag <a href="https://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki"/></a> 168220897aeSGerrit Uitslag <a href="https://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP"/></a> 16947248316SAndreas Gohr </div> 17047248316SAndreas Gohr </body> 17147248316SAndreas Gohr </html> 17247248316SAndreas Gohr<?php 17347248316SAndreas Gohr 17447248316SAndreas Gohr/** 17547248316SAndreas Gohr * Print the input form 176253d4b48SGerrit Uitslag * 177253d4b48SGerrit Uitslag * @param array $d submitted entry 'd' of request data 17847248316SAndreas Gohr */ 179db581254Sjpedrycfunction print_form($d) 180db581254Sjpedryc{ 18147248316SAndreas Gohr global $lang; 18247248316SAndreas Gohr global $LC; 18347248316SAndreas Gohr 18406361442SAndreas Gohr include(DOKU_CONF . 'license.php'); 18506361442SAndreas Gohr 186b1f206e1SAndreas Gohr if (!is_array($d)) $d = []; 18765cc1598SPhy $d = array_map('hsc', $d); 18847248316SAndreas Gohr 18947248316SAndreas Gohr if (!isset($d['acl'])) $d['acl'] = 1; 1903a0852d9SAndreas Gohr if (!isset($d['pop'])) $d['pop'] = 1; 19147248316SAndreas Gohr 19247248316SAndreas Gohr ?> 19347248316SAndreas Gohr <form action="" method="post"> 19447248316SAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>"/> 19547248316SAndreas Gohr <fieldset> 19647248316SAndreas Gohr <label for="title"><?php echo $lang['i_wikiname'] ?> 19747248316SAndreas Gohr <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;"/> 19847248316SAndreas Gohr </label> 19947248316SAndreas Gohr 20047248316SAndreas Gohr <fieldset style="margin-top: 1em;"> 20147248316SAndreas Gohr <label for="acl"> 202ff84abadSGerrit Uitslag <input type="checkbox" name="d[acl]" 203ff84abadSGerrit Uitslag id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : '')); ?> /> 20447248316SAndreas Gohr <?php echo $lang['i_enableacl'] ?></label> 20547248316SAndreas Gohr 20647248316SAndreas Gohr <fieldset id="acldep"> 20747248316SAndreas Gohr <label for="superuser"><?php echo $lang['i_superuser'] ?></label> 20864159a61SAndreas Gohr <input class="text" type="text" name="d[superuser]" id="superuser" 20964159a61SAndreas Gohr value="<?php echo $d['superuser'] ?>"/> 21047248316SAndreas Gohr 21147248316SAndreas Gohr <label for="fullname"><?php echo $lang['fullname'] ?></label> 21264159a61SAndreas Gohr <input class="text" type="text" name="d[fullname]" id="fullname" 21364159a61SAndreas Gohr value="<?php echo $d['fullname'] ?>"/> 21447248316SAndreas Gohr 21547248316SAndreas Gohr <label for="email"><?php echo $lang['email'] ?></label> 21647248316SAndreas Gohr <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>"/> 21747248316SAndreas Gohr 21847248316SAndreas Gohr <label for="password"><?php echo $lang['pass'] ?></label> 21947248316SAndreas Gohr <input class="text" type="password" name="d[password]" id="password"/> 22047248316SAndreas Gohr 22147248316SAndreas Gohr <label for="confirm"><?php echo $lang['passchk'] ?></label> 22247248316SAndreas Gohr <input class="text" type="password" name="d[confirm]" id="confirm"/> 2238af2e4bbSAndreas Gohr 2248af2e4bbSAndreas Gohr <label for="policy"><?php echo $lang['i_policy'] ?></label> 2258af2e4bbSAndreas Gohr <select class="text" name="d[policy]" id="policy"> 22664159a61SAndreas Gohr <option value="0" <?php echo ($d['policy'] == 0) ? 'selected="selected"' : '' ?>><?php 22764159a61SAndreas Gohr echo $lang['i_pol0'] ?></option> 22864159a61SAndreas Gohr <option value="1" <?php echo ($d['policy'] == 1) ? 'selected="selected"' : '' ?>><?php 22964159a61SAndreas Gohr echo $lang['i_pol1'] ?></option> 23064159a61SAndreas Gohr <option value="2" <?php echo ($d['policy'] == 2) ? 'selected="selected"' : '' ?>><?php 23164159a61SAndreas Gohr echo $lang['i_pol2'] ?></option> 2328af2e4bbSAndreas Gohr </select> 23306361442SAndreas Gohr 234ab9346edSAnika Henke <label for="allowreg"> 23564159a61SAndreas Gohr <input type="checkbox" name="d[allowreg]" id="allowreg" <?php 23664159a61SAndreas Gohr echo(($d['allowreg'] ? ' checked="checked"' : '')); ?> /> 237ab9346edSAnika Henke <?php echo $lang['i_allowreg'] ?> 23874850f29SAnika Henke </label> 23947248316SAndreas Gohr </fieldset> 24047248316SAndreas Gohr </fieldset> 24147248316SAndreas Gohr 24206361442SAndreas Gohr <fieldset> 24306361442SAndreas Gohr <p><?php echo $lang['i_license'] ?></p> 24406361442SAndreas Gohr <?php 245b1f206e1SAndreas Gohr $license[] = ['name' => $lang['i_license_none'], 'url' => '']; 246ed856534STom N Harris if (empty($d['license'])) $d['license'] = 'cc-by-sa'; 24706361442SAndreas Gohr foreach ($license as $key => $lic) { 24806361442SAndreas Gohr echo '<label for="lic_' . $key . '">'; 24965cc1598SPhy echo '<input type="radio" name="d[license]" value="' . hsc($key) . '" id="lic_' . $key . '"' . 250b1730bd2STom N Harris (($d['license'] === $key) ? ' checked="checked"' : '') . '>'; 25165cc1598SPhy echo hsc($lic['name']); 25206361442SAndreas Gohr if ($lic['url']) echo ' <a href="' . $lic['url'] . '" target="_blank"><sup>[?]</sup></a>'; 25306361442SAndreas Gohr echo '</label>'; 25406361442SAndreas Gohr } 25506361442SAndreas Gohr ?> 25606361442SAndreas Gohr </fieldset> 25706361442SAndreas Gohr 2583a0852d9SAndreas Gohr <fieldset> 2593a0852d9SAndreas Gohr <p><?php echo $lang['i_pop_field'] ?></p> 2603a0852d9SAndreas Gohr <label for="pop"> 26164159a61SAndreas Gohr <input type="checkbox" name="d[pop]" id="pop" <?php 26264159a61SAndreas Gohr echo(($d['pop'] ? ' checked="checked"' : '')); ?> /> 26364159a61SAndreas Gohr <?php echo $lang['i_pop_label'] ?> 264220897aeSGerrit Uitslag <a href="https://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a> 2653a0852d9SAndreas Gohr </label> 2663a0852d9SAndreas Gohr </fieldset> 2673a0852d9SAndreas Gohr 26847248316SAndreas Gohr </fieldset> 26947248316SAndreas Gohr <fieldset id="process"> 270ae614416SAnika Henke <button type="submit" name="submit"><?php echo $lang['btn_save'] ?></button> 27147248316SAndreas Gohr </fieldset> 27247248316SAndreas Gohr </form> 27347248316SAndreas Gohr <?php 27447248316SAndreas Gohr} 27547248316SAndreas Gohr 276db581254Sjpedrycfunction print_retry() 277db581254Sjpedryc{ 27870a6aa16Schris global $lang; 2799ad6da3dSAndreas Gohr global $LC; 28070a6aa16Schris ?> 28170a6aa16Schris <form action="" method="get"> 28270a6aa16Schris <fieldset> 2839ad6da3dSAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>"/> 284ae614416SAnika Henke <button type="submit"><?php echo $lang['i_retry']; ?></button> 28570a6aa16Schris </fieldset> 28670a6aa16Schris </form> 28770a6aa16Schris <?php 28870a6aa16Schris} 28970a6aa16Schris 29047248316SAndreas Gohr/** 29147248316SAndreas Gohr * Check validity of data 29247248316SAndreas Gohr * 293253d4b48SGerrit Uitslag * @param array $d 294253d4b48SGerrit Uitslag * @return bool ok? 295ff84abadSGerrit Uitslag * @author Andreas Gohr 296ff84abadSGerrit Uitslag * 29747248316SAndreas Gohr */ 298db581254Sjpedrycfunction check_data(&$d) 299db581254Sjpedryc{ 300b1f206e1SAndreas Gohr static $form_default = [ 3014b530faaSTom N Harris 'title' => '', 302ed856534STom N Harris 'acl' => '1', 3034b530faaSTom N Harris 'superuser' => '', 3044b530faaSTom N Harris 'fullname' => '', 3054b530faaSTom N Harris 'email' => '', 3064b530faaSTom N Harris 'password' => '', 3074b530faaSTom N Harris 'confirm' => '', 3084b530faaSTom N Harris 'policy' => '0', 309ab9346edSAnika Henke 'allowreg' => '0', 3104b530faaSTom N Harris 'license' => 'cc-by-sa' 311b1f206e1SAndreas Gohr ]; 31247248316SAndreas Gohr global $lang; 31347248316SAndreas Gohr global $error; 31447248316SAndreas Gohr 315b1f206e1SAndreas Gohr if (!is_array($d)) $d = []; 3164b530faaSTom N Harris foreach ($d as $k => $v) { 3174b530faaSTom N Harris if (is_array($v)) 3184b530faaSTom N Harris unset($d[$k]); 319db581254Sjpedryc else $d[$k] = (string)$v; 3204b530faaSTom N Harris } 321e2386079SAndreas Gohr 3224b530faaSTom N Harris //autolowercase the username 3234b530faaSTom N Harris $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : ""; 3244b530faaSTom N Harris 3254b530faaSTom N Harris $ok = false; 3264b530faaSTom N Harris 3274b530faaSTom N Harris if (isset($_REQUEST['submit'])) { 32847248316SAndreas Gohr $ok = true; 32947248316SAndreas Gohr 33047248316SAndreas Gohr // check input 33147248316SAndreas Gohr if (empty($d['title'])) { 33247248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['i_wikiname']); 33347248316SAndreas Gohr $ok = false; 33447248316SAndreas Gohr } 3354b530faaSTom N Harris if (isset($d['acl'])) { 3362cb06bbdSjpedryc if (empty($d['superuser']) || ($d['superuser'] !== cleanID($d['superuser']))) { 33747248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['i_superuser']); 33847248316SAndreas Gohr $ok = false; 33947248316SAndreas Gohr } 34047248316SAndreas Gohr if (empty($d['password'])) { 34147248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['pass']); 34247248316SAndreas Gohr $ok = false; 343db581254Sjpedryc } elseif (!isset($d['confirm']) || $d['confirm'] != $d['password']) { 34447248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['passchk']); 34547248316SAndreas Gohr $ok = false; 34647248316SAndreas Gohr } 34747248316SAndreas Gohr if (empty($d['fullname']) || strstr($d['fullname'], ':')) { 34847248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['fullname']); 34947248316SAndreas Gohr $ok = false; 35047248316SAndreas Gohr } 351e2386079SAndreas Gohr if (empty($d['email']) || strstr($d['email'], ':') || !strstr($d['email'], '@')) { 35247248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['email']); 35347248316SAndreas Gohr $ok = false; 35447248316SAndreas Gohr } 355b9ab8e4fSPhy } else { 356b9ab8e4fSPhy // Since default = 1, browser won't send acl=0 when user untick acl 357b9ab8e4fSPhy $d['acl'] = '0'; 35847248316SAndreas Gohr } 3594b530faaSTom N Harris } 3604b530faaSTom N Harris $d = array_merge($form_default, $d); 36147248316SAndreas Gohr return $ok; 36247248316SAndreas Gohr} 36347248316SAndreas Gohr 36447248316SAndreas Gohr/** 36547248316SAndreas Gohr * Writes the data to the config files 36647248316SAndreas Gohr * 367253d4b48SGerrit Uitslag * @param array $d 368253d4b48SGerrit Uitslag * @return bool 369ff84abadSGerrit Uitslag * @throws Exception 370ff84abadSGerrit Uitslag * 371ff84abadSGerrit Uitslag * @author Chris Smith <chris@jalakai.co.uk> 37247248316SAndreas Gohr */ 373db581254Sjpedrycfunction store_data($d) 374db581254Sjpedryc{ 3750036aa89SAndreas Gohr global $LC; 37647248316SAndreas Gohr $ok = true; 3778af2e4bbSAndreas Gohr $d['policy'] = (int)$d['policy']; 37847248316SAndreas Gohr 37947248316SAndreas Gohr // create local.php 38024650a19SAndreas Gohr $now = gmdate('r'); 38147248316SAndreas Gohr $output = <<<EOT 38247248316SAndreas Gohr<?php 38347248316SAndreas Gohr/** 38447248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings 38547248316SAndreas Gohr * Auto-generated by install script 38647248316SAndreas Gohr * Date: $now 38747248316SAndreas Gohr */ 38847248316SAndreas Gohr 38947248316SAndreas GohrEOT; 3902613efa1SAndreas Gohr // add any config options set by a previous installer 3912613efa1SAndreas Gohr $preset = __DIR__ . '/install.conf'; 3922613efa1SAndreas Gohr if (file_exists($preset)) { 3932613efa1SAndreas Gohr $output .= "# preset config options\n"; 3942613efa1SAndreas Gohr $output .= file_get_contents($preset); 3952613efa1SAndreas Gohr $output .= "\n\n"; 3962613efa1SAndreas Gohr $output .= "# options selected in installer\n"; 3972613efa1SAndreas Gohr @unlink($preset); 3982613efa1SAndreas Gohr } 3992613efa1SAndreas Gohr 40047248316SAndreas Gohr $output .= '$conf[\'title\'] = \'' . addslashes($d['title']) . "';\n"; 4010036aa89SAndreas Gohr $output .= '$conf[\'lang\'] = \'' . addslashes($LC) . "';\n"; 40206361442SAndreas Gohr $output .= '$conf[\'license\'] = \'' . addslashes($d['license']) . "';\n"; 40347248316SAndreas Gohr if ($d['acl']) { 40447248316SAndreas Gohr $output .= '$conf[\'useacl\'] = 1' . ";\n"; 405523d7ea6Schris $output .= "\$conf['superuser'] = '@admin';\n"; 40647248316SAndreas Gohr } 407ab9346edSAnika Henke if (!$d['allowreg']) { 40843c137edSAnika Henke $output .= '$conf[\'disableactions\'] = \'register\'' . ";\n"; 409d2ea6dc1SAnika Henke } 41047248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'local.php', $output); 41147248316SAndreas Gohr 41247248316SAndreas Gohr if ($d['acl']) { 4133791b589SAndreas Gohr // hash the password 414b1f206e1SAndreas Gohr $phash = new PassHash(); 415267bbbcaSms101 $pass = $phash->hash_bcrypt($d['password']); 4163791b589SAndreas Gohr 41747248316SAndreas Gohr // create users.auth.php 418a672ef75SPhy $output = <<<EOT 419a672ef75SPhy# users.auth.php 420a672ef75SPhy# <?php exit()?> 421a672ef75SPhy# Don't modify the lines above 422a672ef75SPhy# 423a672ef75SPhy# Userfile 424a672ef75SPhy# 425a672ef75SPhy# Auto-generated by install script 426a672ef75SPhy# Date: $now 427a672ef75SPhy# 428a672ef75SPhy# Format: 429a672ef75SPhy# login:passwordhash:Real Name:email:groups,comma,separated 430a672ef75SPhy 431a672ef75SPhyEOT; 432722372bdSms101 // --- user:bcryptpasswordhash:Real Name:email:groups,comma,seperated 433b1f206e1SAndreas Gohr $output = $output . "\n" . implode(':', [ 43436a1a880SAndreas Gohr $d['superuser'], 43536a1a880SAndreas Gohr $pass, 43636a1a880SAndreas Gohr $d['fullname'], 43736a1a880SAndreas Gohr $d['email'], 43836a1a880SAndreas Gohr 'admin,user', 43936a1a880SAndreas Gohr ]) . "\n"; 44047248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'users.auth.php', $output); 44147248316SAndreas Gohr 44247248316SAndreas Gohr // create acl.auth.php 4438af2e4bbSAndreas Gohr $output = <<<EOT 4448af2e4bbSAndreas Gohr# acl.auth.php 4458af2e4bbSAndreas Gohr# <?php exit()?> 4468af2e4bbSAndreas Gohr# Don't modify the lines above 4478af2e4bbSAndreas Gohr# 4488af2e4bbSAndreas Gohr# Access Control Lists 4498af2e4bbSAndreas Gohr# 4508af2e4bbSAndreas Gohr# Auto-generated by install script 4518af2e4bbSAndreas Gohr# Date: $now 4528af2e4bbSAndreas Gohr 4538af2e4bbSAndreas GohrEOT; 4548af2e4bbSAndreas Gohr if ($d['policy'] == 2) { 4558af2e4bbSAndreas Gohr $output .= "* @ALL 0\n"; 456d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4579c70688aSchris } elseif ($d['policy'] == 1) { 4588af2e4bbSAndreas Gohr $output .= "* @ALL 1\n"; 459d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4608af2e4bbSAndreas Gohr } else { 4618af2e4bbSAndreas Gohr $output .= "* @ALL 8\n"; 4628af2e4bbSAndreas Gohr } 46347248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'acl.auth.php', $output); 46447248316SAndreas Gohr } 4653a0852d9SAndreas Gohr 4663a0852d9SAndreas Gohr // enable popularity submission 467ee4f28e3SDamien Regad if (isset($d['pop']) && $d['pop']) { 4683a0852d9SAndreas Gohr @touch(DOKU_INC . 'data/cache/autosubmit.txt'); 4693a0852d9SAndreas Gohr } 4703a0852d9SAndreas Gohr 471c70d6ceeSAndreas Gohr // disable auth plugins til needed 472c70d6ceeSAndreas Gohr $output = <<<EOT 473c70d6ceeSAndreas Gohr<?php 474c70d6ceeSAndreas Gohr/* 475c70d6ceeSAndreas Gohr * Local plugin enable/disable settings 476c70d6ceeSAndreas Gohr * 477c70d6ceeSAndreas Gohr * Auto-generated by install script 478c70d6ceeSAndreas Gohr * Date: $now 479c70d6ceeSAndreas Gohr */ 480c70d6ceeSAndreas Gohr 481c70d6ceeSAndreas Gohr\$plugins['authad'] = 0; 482c70d6ceeSAndreas Gohr\$plugins['authldap'] = 0; 483c70d6ceeSAndreas Gohr\$plugins['authmysql'] = 0; 484c70d6ceeSAndreas Gohr\$plugins['authpgsql'] = 0; 485c70d6ceeSAndreas Gohr 486c70d6ceeSAndreas GohrEOT; 487c70d6ceeSAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'plugins.local.php', $output); 488c70d6ceeSAndreas Gohr 48947248316SAndreas Gohr return $ok; 49047248316SAndreas Gohr} 49147248316SAndreas Gohr 49247248316SAndreas Gohr/** 49347248316SAndreas Gohr * Write the given content to a file 49447248316SAndreas Gohr * 495253d4b48SGerrit Uitslag * @param string $filename 496253d4b48SGerrit Uitslag * @param string $data 497253d4b48SGerrit Uitslag * @return bool 498ff84abadSGerrit Uitslag * 499ff84abadSGerrit Uitslag * @author Chris Smith <chris@jalakai.co.uk> 50047248316SAndreas Gohr */ 501db581254Sjpedrycfunction fileWrite($filename, $data) 502db581254Sjpedryc{ 50347248316SAndreas Gohr global $error; 50447248316SAndreas Gohr global $lang; 50547248316SAndreas Gohr 50647248316SAndreas Gohr if (($fp = @fopen($filename, 'wb')) === false) { 50747248316SAndreas Gohr $filename = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $filename); 50847248316SAndreas Gohr $error[] = sprintf($lang['i_writeerr'], $filename); 50947248316SAndreas Gohr return false; 51047248316SAndreas Gohr } 51147248316SAndreas Gohr 512db581254Sjpedryc if (!empty($data)) { 513db581254Sjpedryc fwrite($fp, $data); 514db581254Sjpedryc } 51547248316SAndreas Gohr fclose($fp); 51647248316SAndreas Gohr return true; 51747248316SAndreas Gohr} 51847248316SAndreas Gohr 51947248316SAndreas Gohr 52047248316SAndreas Gohr/** 52147248316SAndreas Gohr * check installation dependent local config files and tests for a known 52247248316SAndreas Gohr * unmodified main config file 52347248316SAndreas Gohr * 524253d4b48SGerrit Uitslag * @return bool 525ff84abadSGerrit Uitslag * 526ff84abadSGerrit Uitslag * @author Chris Smith <chris@jalakai.co.uk> 52747248316SAndreas Gohr */ 528db581254Sjpedrycfunction check_configs() 529db581254Sjpedryc{ 53047248316SAndreas Gohr global $error; 53147248316SAndreas Gohr global $lang; 53247248316SAndreas Gohr 53347248316SAndreas Gohr $ok = true; 53447248316SAndreas Gohr 535b1f206e1SAndreas Gohr $config_files = [ 5365cfb8815Schris 'local' => DOKU_LOCAL . 'local.php', 5375cfb8815Schris 'users' => DOKU_LOCAL . 'users.auth.php', 5385cfb8815Schris 'auth' => DOKU_LOCAL . 'acl.auth.php' 539b1f206e1SAndreas Gohr ]; 5405cfb8815Schris 54147248316SAndreas Gohr // configs shouldn't exist 54247248316SAndreas Gohr foreach ($config_files as $file) { 54379e79377SAndreas Gohr if (file_exists($file) && filesize($file)) { 54447248316SAndreas Gohr $file = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $file); 54547248316SAndreas Gohr $error[] = sprintf($lang['i_confexists'], $file); 54647248316SAndreas Gohr $ok = false; 54747248316SAndreas Gohr } 54847248316SAndreas Gohr } 54947248316SAndreas Gohr return $ok; 55047248316SAndreas Gohr} 55147248316SAndreas Gohr 55247248316SAndreas Gohr 55347248316SAndreas Gohr/** 55447248316SAndreas Gohr * Check other installation dir/file permission requirements 55547248316SAndreas Gohr * 556253d4b48SGerrit Uitslag * @return bool 557ff84abadSGerrit Uitslag * 558ff84abadSGerrit Uitslag * @author Chris Smith <chris@jalakai.co.uk> 55947248316SAndreas Gohr */ 560db581254Sjpedrycfunction check_permissions() 561db581254Sjpedryc{ 56247248316SAndreas Gohr global $error; 56347248316SAndreas Gohr global $lang; 56447248316SAndreas Gohr 565b1f206e1SAndreas Gohr $dirs = [ 56647248316SAndreas Gohr 'conf' => DOKU_LOCAL, 56747248316SAndreas Gohr 'data' => DOKU_INC . 'data', 56847248316SAndreas Gohr 'pages' => DOKU_INC . 'data/pages', 56947248316SAndreas Gohr 'attic' => DOKU_INC . 'data/attic', 57047248316SAndreas Gohr 'media' => DOKU_INC . 'data/media', 57149b78edaSAndreas Gohr 'media_attic' => DOKU_INC . 'data/media_attic', 57249b78edaSAndreas Gohr 'media_meta' => DOKU_INC . 'data/media_meta', 57347248316SAndreas Gohr 'meta' => DOKU_INC . 'data/meta', 57447248316SAndreas Gohr 'cache' => DOKU_INC . 'data/cache', 57547248316SAndreas Gohr 'locks' => DOKU_INC . 'data/locks', 5769711045aSAndreas Gohr 'index' => DOKU_INC . 'data/index', 577de33a58fSMichael Klier 'tmp' => DOKU_INC . 'data/tmp' 578b1f206e1SAndreas Gohr ]; 57947248316SAndreas Gohr 58047248316SAndreas Gohr $ok = true; 58147248316SAndreas Gohr foreach ($dirs as $dir) { 58279e79377SAndreas Gohr if (!file_exists("$dir/.") || !is_writable($dir)) { 58370a6aa16Schris $dir = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}', $dir); 58447248316SAndreas Gohr $error[] = sprintf($lang['i_permfail'], $dir); 58547248316SAndreas Gohr $ok = false; 58647248316SAndreas Gohr } 58747248316SAndreas Gohr } 58847248316SAndreas Gohr return $ok; 58947248316SAndreas Gohr} 59047248316SAndreas Gohr 59147248316SAndreas Gohr/** 5923afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version 59347248316SAndreas Gohr * 594253d4b48SGerrit Uitslag * @return bool 595ff84abadSGerrit Uitslag * 596ff84abadSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 59747248316SAndreas Gohr */ 598db581254Sjpedrycfunction check_functions() 599db581254Sjpedryc{ 60047248316SAndreas Gohr global $error; 60147248316SAndreas Gohr global $lang; 6023afe5d1cSAndreas Gohr $ok = true; 6033afe5d1cSAndreas Gohr 604c49393f5SAndreas Gohr if (version_compare(phpversion(), '7.4.0', '<')) { 605c49393f5SAndreas Gohr $error[] = sprintf($lang['i_phpver'], phpversion(), '7.4.0'); 6063afe5d1cSAndreas Gohr $ok = false; 6073afe5d1cSAndreas Gohr } 6083afe5d1cSAndreas Gohr 6097f413440SAndreas Gohr if (ini_get('mbstring.func_overload') != 0) { 6107f413440SAndreas Gohr $error[] = $lang['i_mbfuncoverload']; 6117f413440SAndreas Gohr $ok = false; 6127f413440SAndreas Gohr } 6137f413440SAndreas Gohr 614387250efSPhy try { 615387250efSPhy random_bytes(1); 616ff84abadSGerrit Uitslag } catch (Exception $th) { 617387250efSPhy // If an appropriate source of randomness cannot be found, an Exception will be thrown by PHP 7+ 618387250efSPhy $error[] = $lang['i_urandom']; 619387250efSPhy $ok = false; 620387250efSPhy } 621387250efSPhy 622387250efSPhy if (ini_get('mbstring.func_overload') != 0) { 623387250efSPhy $error[] = $lang['i_mbfuncoverload']; 624387250efSPhy $ok = false; 625387250efSPhy } 626387250efSPhy 6273009a773SAndreas Gohr $funcs = explode(' ', 'addslashes call_user_func chmod copy fgets ' . 62847248316SAndreas Gohr 'file file_exists fseek flush filesize ftell fopen ' . 6293f6872b1SMyron Turner 'glob header ignore_user_abort ini_get mkdir ' . 63047248316SAndreas Gohr 'ob_start opendir parse_ini_file readfile realpath ' . 631bab4a8bdSAndreas Gohr 'rename rmdir serialize session_start unlink usleep ' . 632d1d99bb9SAndreas Gohr 'preg_replace file_get_contents htmlspecialchars_decode ' . 633670dc13dSAndreas Gohr 'spl_autoload_register stream_select fsockopen pack xml_parser_create'); 63447248316SAndreas Gohr 63570a6aa16Schris if (!function_exists('mb_substr')) { 63670a6aa16Schris $funcs[] = 'utf8_encode'; 63770a6aa16Schris $funcs[] = 'utf8_decode'; 63870a6aa16Schris } 63970a6aa16Schris 6403f6872b1SMyron Turner if (!function_exists('mail')) { 6413f6872b1SMyron Turner if (strpos(ini_get('disable_functions'), 'mail') !== false) { 6423f6872b1SMyron Turner $disabled = $lang['i_disabled']; 643db581254Sjpedryc } else { 6443f6872b1SMyron Turner $disabled = ""; 6453f6872b1SMyron Turner } 6463f6872b1SMyron Turner $error[] = sprintf($lang['i_funcnmail'], $disabled); 6473f6872b1SMyron Turner } 6483f6872b1SMyron Turner 64947248316SAndreas Gohr foreach ($funcs as $func) { 65047248316SAndreas Gohr if (!function_exists($func)) { 65147248316SAndreas Gohr $error[] = sprintf($lang['i_funcna'], $func); 65247248316SAndreas Gohr $ok = false; 65347248316SAndreas Gohr } 65447248316SAndreas Gohr } 65547248316SAndreas Gohr return $ok; 65647248316SAndreas Gohr} 65747248316SAndreas Gohr 65847248316SAndreas Gohr/** 65947248316SAndreas Gohr * Print language selection 66047248316SAndreas Gohr * 66147248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 66247248316SAndreas Gohr */ 663db581254Sjpedrycfunction langsel() 664db581254Sjpedryc{ 66547248316SAndreas Gohr global $lang; 66647248316SAndreas Gohr global $LC; 66747248316SAndreas Gohr 66847248316SAndreas Gohr $dir = DOKU_INC . 'inc/lang'; 66947248316SAndreas Gohr $dh = opendir($dir); 67047248316SAndreas Gohr if (!$dh) return; 67147248316SAndreas Gohr 672b1f206e1SAndreas Gohr $langs = []; 67347248316SAndreas Gohr while (($file = readdir($dh)) !== false) { 674220897aeSGerrit Uitslag if (preg_match('/^[._]/', $file)) continue; 67579e79377SAndreas Gohr if (is_dir($dir . '/' . $file) && file_exists($dir . '/' . $file . '/lang.php')) { 67647248316SAndreas Gohr $langs[] = $file; 67747248316SAndreas Gohr } 67847248316SAndreas Gohr } 67947248316SAndreas Gohr closedir($dh); 68047248316SAndreas Gohr sort($langs); 68147248316SAndreas Gohr 68247248316SAndreas Gohr echo '<form action="">'; 68347248316SAndreas Gohr echo $lang['i_chooselang']; 68447248316SAndreas Gohr echo ': <select name="l" onchange="submit()">'; 68547248316SAndreas Gohr foreach ($langs as $l) { 68647248316SAndreas Gohr $sel = ($l == $LC) ? 'selected="selected"' : ''; 68747248316SAndreas Gohr echo '<option value="' . $l . '" ' . $sel . '>' . $l . '</option>'; 68847248316SAndreas Gohr } 68947248316SAndreas Gohr echo '</select> '; 690ae614416SAnika Henke echo '<button type="submit">' . $lang['btn_update'] . '</button>'; 69147248316SAndreas Gohr echo '</form>'; 69247248316SAndreas Gohr} 69347248316SAndreas Gohr 69447248316SAndreas Gohr/** 695c66972f2SAdrian Lang * Print global error array 69647248316SAndreas Gohr * 69747248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 69847248316SAndreas Gohr */ 699db581254Sjpedrycfunction print_errors() 700db581254Sjpedryc{ 70147248316SAndreas Gohr global $error; 7024b530faaSTom N Harris if (!empty($error)) { 70347248316SAndreas Gohr echo '<ul>'; 70447248316SAndreas Gohr foreach ($error as $err) { 70547248316SAndreas Gohr echo "<li>$err</li>"; 70647248316SAndreas Gohr } 70747248316SAndreas Gohr echo '</ul>'; 70847248316SAndreas Gohr } 7094b530faaSTom N Harris} 710