15cfb8815Schris<?php 2d4f83172SAndreas Gohr 3ac251797SAndreas Gohr/*><div style="width:60%; margin: auto; background-color: #fcc; 4ac251797SAndreas Gohr border: 1px solid #faa; padding: 0.5em 1em;"> 5ac251797SAndreas Gohr <h1 style="font-size: 120%">No PHP Support</h1> 6ac251797SAndreas Gohr 7ac251797SAndreas Gohr It seems this server has no PHP support enabled. You will need to 8ac251797SAndreas Gohr enable PHP before you can install and run DokuWiki. Contact your hosting 9ac251797SAndreas Gohr provider if you're unsure what this means. 10ac251797SAndreas Gohr 11ac251797SAndreas Gohr</div>*/ 120f2c316aSAndreas Gohr 130f2c316aSAndreas Gohruse dokuwiki\PassHash; 145cfb8815Schris 15b1f206e1SAndreas Gohrif (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/'); 165cfb8815Schrisif (!defined('DOKU_CONF')) define('DOKU_CONF', DOKU_INC . 'conf/'); 175cfb8815Schrisif (!defined('DOKU_LOCAL')) define('DOKU_LOCAL', DOKU_INC . 'conf/'); 185cfb8815Schris 1902bca5d4SYousong Zhou// load and initialize the core system 2002bca5d4SYousong Zhourequire_once(DOKU_INC . 'inc/init.php'); 212cb06bbdSjpedrycrequire_once(DOKU_INC . 'inc/pageutils.php'); 223791b589SAndreas Gohr 233545b2e0Schris// check for error reporting override or set error reporting to sane values 24db581254Sjpedrycif (!defined('DOKU_E_LEVEL')) { 25db581254Sjpedryc error_reporting(E_ALL ^ E_NOTICE); 26db581254Sjpedryc} else { 27db581254Sjpedryc error_reporting(DOKU_E_LEVEL); 28db581254Sjpedryc} 293545b2e0Schris 3047248316SAndreas Gohr// language strings 3147248316SAndreas Gohrrequire_once(DOKU_INC . 'inc/lang/en/lang.php'); 324b530faaSTom N Harrisif (isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) { 3347248316SAndreas Gohr $LC = preg_replace('/[^a-z\-]+/', '', $_REQUEST['l']); 344b530faaSTom N Harris} 354b530faaSTom N Harrisif (empty($LC)) $LC = 'en'; 3647248316SAndreas Gohrif ($LC && $LC != 'en') { 3747248316SAndreas Gohr require_once(DOKU_INC . 'inc/lang/' . $LC . '/lang.php'); 3847248316SAndreas Gohr} 3947248316SAndreas Gohr 4047248316SAndreas Gohr// initialise variables ... 41b1f206e1SAndreas Gohr$error = []; 4247248316SAndreas Gohr 4347248316SAndreas Gohr// begin output 4447248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8'); 4547248316SAndreas Gohr?> 46c8839c22SAnika Henke <!DOCTYPE html> 47c8839c22SAnika Henke <html lang="<?php echo $LC ?>" dir="<?php echo $lang['direction'] ?>"> 4847248316SAndreas Gohr <head> 49c8839c22SAnika Henke <meta charset="utf-8"/> 504208c142SAndreas Gohr <title><?php echo $lang['i_installer'] ?></title> 5159305168SPhy <style> 52ff84abadSGerrit Uitslag body { 53ff84abadSGerrit Uitslag width: 90%; 54ff84abadSGerrit Uitslag margin: 0 auto; 55ff84abadSGerrit Uitslag font: 84% Verdana, Helvetica, Arial, sans-serif; 56ff84abadSGerrit Uitslag } 57ff84abadSGerrit Uitslag 58ff84abadSGerrit Uitslag img { 59ff84abadSGerrit Uitslag border: none 60ff84abadSGerrit Uitslag } 61ff84abadSGerrit Uitslag 62ff84abadSGerrit Uitslag br.cl { 63ff84abadSGerrit Uitslag clear: both; 64ff84abadSGerrit Uitslag } 65ff84abadSGerrit Uitslag 66ff84abadSGerrit Uitslag code { 67ff84abadSGerrit Uitslag font-size: 110%; 68ff84abadSGerrit Uitslag color: #800000; 69ff84abadSGerrit Uitslag } 70ff84abadSGerrit Uitslag 71ff84abadSGerrit Uitslag fieldset { 72ff84abadSGerrit Uitslag border: none 73ff84abadSGerrit Uitslag } 74ff84abadSGerrit Uitslag 75ff84abadSGerrit Uitslag label { 76ff84abadSGerrit Uitslag display: block; 77ff84abadSGerrit Uitslag margin-top: 0.5em; 78ff84abadSGerrit Uitslag } 79ff84abadSGerrit Uitslag 80ff84abadSGerrit Uitslag select.text, input.text { 81ff84abadSGerrit Uitslag width: 30em; 82ff84abadSGerrit Uitslag margin: 0 0.5em; 83ff84abadSGerrit Uitslag } 84ff84abadSGerrit Uitslag 85ff84abadSGerrit Uitslag a { 86ff84abadSGerrit Uitslag text-decoration: none 87ff84abadSGerrit Uitslag } 8847248316SAndreas Gohr </style> 8959305168SPhy <script> 9047248316SAndreas Gohr function acltoggle() { 9147248316SAndreas Gohr var cb = document.getElementById('acl'); 9247248316SAndreas Gohr var fs = document.getElementById('acldep'); 9347248316SAndreas Gohr if (!cb || !fs) return; 9447248316SAndreas Gohr if (cb.checked) { 9547248316SAndreas Gohr fs.style.display = ''; 9647248316SAndreas Gohr } else { 9747248316SAndreas Gohr fs.style.display = 'none'; 9847248316SAndreas Gohr } 9947248316SAndreas Gohr } 100ff84abadSGerrit Uitslag 10147248316SAndreas Gohr window.onload = function () { 10247248316SAndreas Gohr acltoggle(); 10347248316SAndreas Gohr var cb = document.getElementById('acl'); 10447248316SAndreas Gohr if (cb) cb.onchange = acltoggle; 10547248316SAndreas Gohr }; 10647248316SAndreas Gohr </script> 10747248316SAndreas Gohr </head> 10847248316SAndreas Gohr <body style=""> 10947248316SAndreas Gohr <h1 style="float:left"> 110c5270434SAndreas Gohr <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png" 111c5270434SAndreas Gohr style="vertical-align: middle;" alt="" height="64" width="64"/> 11247248316SAndreas Gohr <?php echo $lang['i_installer'] ?> 11347248316SAndreas Gohr </h1> 11447248316SAndreas Gohr <div style="float:right; margin: 1em;"> 11547248316SAndreas Gohr <?php langsel() ?> 11647248316SAndreas Gohr </div> 11747248316SAndreas Gohr <br class="cl"/> 11847248316SAndreas Gohr 11947248316SAndreas Gohr <div style="float: right; width: 34%;"> 12047248316SAndreas Gohr <?php 12179e79377SAndreas Gohr if (file_exists(DOKU_INC . 'inc/lang/' . $LC . '/install.html')) { 12247248316SAndreas Gohr include(DOKU_INC . 'inc/lang/' . $LC . '/install.html'); 12347248316SAndreas Gohr } else { 12426dfc232SAndreas Gohr echo "<div lang=\"en\" dir=\"ltr\">\n"; 12547248316SAndreas Gohr include(DOKU_INC . 'inc/lang/en/install.html'); 12626dfc232SAndreas Gohr echo "</div>\n"; 12747248316SAndreas Gohr } 12847248316SAndreas Gohr ?> 12964159a61SAndreas Gohr <a style=" 13064159a61SAndreas Gohr background: transparent 13164159a61SAndreas Gohr url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png) 13264159a61SAndreas Gohr left top no-repeat; 133c8b43921SAndreas Gohr display: block; width:380px; height:73px; border:none; clear:both;" 134c8b43921SAndreas Gohr target="_blank" 135220897aeSGerrit Uitslag href="https://www.dokuwiki.org/security#web_access_security"></a> 13647248316SAndreas Gohr </div> 13747248316SAndreas Gohr 13847248316SAndreas Gohr <div style="float: left; width: 58%;"> 13947248316SAndreas Gohr <?php 1407ac1baa0SL. Ivanovich Harrison try { 14147248316SAndreas Gohr if (!(check_functions() && check_permissions())) { 14247248316SAndreas Gohr echo '<p>' . $lang['i_problems'] . '</p>'; 14347248316SAndreas Gohr print_errors(); 14470a6aa16Schris print_retry(); 14547248316SAndreas Gohr } elseif (!check_configs()) { 14647248316SAndreas Gohr echo '<p>' . $lang['i_modified'] . '</p>'; 14747248316SAndreas Gohr print_errors(); 1484b530faaSTom N Harris } elseif (check_data($_REQUEST['d'])) { 1494b530faaSTom N Harris // check_data has sanitized all input parameters 1504b530faaSTom N Harris if (!store_data($_REQUEST['d'])) { 15147248316SAndreas Gohr echo '<p>' . $lang['i_failure'] . '</p>'; 15247248316SAndreas Gohr print_errors(); 15347248316SAndreas Gohr } else { 15447248316SAndreas Gohr echo '<p>' . $lang['i_success'] . '</p>'; 15547248316SAndreas Gohr } 15647248316SAndreas Gohr } else { 1574b530faaSTom N Harris print_errors(); 15847248316SAndreas Gohr print_form($_REQUEST['d']); 15947248316SAndreas Gohr } 1607ac1baa0SL. Ivanovich Harrison } catch (Exception $e) { 1617ac1baa0SL. Ivanovich Harrison echo 'Caught exception: ', $e->getMessage(), "\n"; 1627ac1baa0SL. Ivanovich Harrison } 16347248316SAndreas Gohr ?> 16447248316SAndreas Gohr </div> 16547248316SAndreas Gohr 166c8b43921SAndreas Gohr 16747248316SAndreas Gohr <div style="clear: both"> 168220897aeSGerrit Uitslag <a href="https://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki"/></a> 169220897aeSGerrit Uitslag <a href="https://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP"/></a> 17047248316SAndreas Gohr </div> 17147248316SAndreas Gohr </body> 17247248316SAndreas Gohr </html> 17347248316SAndreas Gohr<?php 17447248316SAndreas Gohr 17547248316SAndreas Gohr/** 17647248316SAndreas Gohr * Print the input form 177253d4b48SGerrit Uitslag * 178253d4b48SGerrit Uitslag * @param array $d submitted entry 'd' of request data 17947248316SAndreas Gohr */ 180db581254Sjpedrycfunction print_form($d) 181db581254Sjpedryc{ 18247248316SAndreas Gohr global $lang; 18347248316SAndreas Gohr global $LC; 18447248316SAndreas Gohr 18506361442SAndreas Gohr include(DOKU_CONF . 'license.php'); 18606361442SAndreas Gohr 187b1f206e1SAndreas Gohr if (!is_array($d)) $d = []; 18865cc1598SPhy $d = array_map('hsc', $d); 18947248316SAndreas Gohr 19047248316SAndreas Gohr if (!isset($d['acl'])) $d['acl'] = 1; 1913a0852d9SAndreas Gohr if (!isset($d['pop'])) $d['pop'] = 1; 19247248316SAndreas Gohr 19347248316SAndreas Gohr ?> 19447248316SAndreas Gohr <form action="" method="post"> 19547248316SAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>"/> 19647248316SAndreas Gohr <fieldset> 19747248316SAndreas Gohr <label for="title"><?php echo $lang['i_wikiname'] ?> 19847248316SAndreas Gohr <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;"/> 19947248316SAndreas Gohr </label> 20047248316SAndreas Gohr 20147248316SAndreas Gohr <fieldset style="margin-top: 1em;"> 20247248316SAndreas Gohr <label for="acl"> 203ff84abadSGerrit Uitslag <input type="checkbox" name="d[acl]" 204ff84abadSGerrit Uitslag id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : '')); ?> /> 20547248316SAndreas Gohr <?php echo $lang['i_enableacl'] ?></label> 20647248316SAndreas Gohr 20747248316SAndreas Gohr <fieldset id="acldep"> 20847248316SAndreas Gohr <label for="superuser"><?php echo $lang['i_superuser'] ?></label> 20964159a61SAndreas Gohr <input class="text" type="text" name="d[superuser]" id="superuser" 21064159a61SAndreas Gohr value="<?php echo $d['superuser'] ?>"/> 21147248316SAndreas Gohr 21247248316SAndreas Gohr <label for="fullname"><?php echo $lang['fullname'] ?></label> 21364159a61SAndreas Gohr <input class="text" type="text" name="d[fullname]" id="fullname" 21464159a61SAndreas Gohr value="<?php echo $d['fullname'] ?>"/> 21547248316SAndreas Gohr 21647248316SAndreas Gohr <label for="email"><?php echo $lang['email'] ?></label> 21747248316SAndreas Gohr <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>"/> 21847248316SAndreas Gohr 21947248316SAndreas Gohr <label for="password"><?php echo $lang['pass'] ?></label> 22047248316SAndreas Gohr <input class="text" type="password" name="d[password]" id="password"/> 22147248316SAndreas Gohr 22247248316SAndreas Gohr <label for="confirm"><?php echo $lang['passchk'] ?></label> 22347248316SAndreas Gohr <input class="text" type="password" name="d[confirm]" id="confirm"/> 2248af2e4bbSAndreas Gohr 2258af2e4bbSAndreas Gohr <label for="policy"><?php echo $lang['i_policy'] ?></label> 2268af2e4bbSAndreas Gohr <select class="text" name="d[policy]" id="policy"> 22764159a61SAndreas Gohr <option value="0" <?php echo ($d['policy'] == 0) ? 'selected="selected"' : '' ?>><?php 22864159a61SAndreas Gohr echo $lang['i_pol0'] ?></option> 22964159a61SAndreas Gohr <option value="1" <?php echo ($d['policy'] == 1) ? 'selected="selected"' : '' ?>><?php 23064159a61SAndreas Gohr echo $lang['i_pol1'] ?></option> 23164159a61SAndreas Gohr <option value="2" <?php echo ($d['policy'] == 2) ? 'selected="selected"' : '' ?>><?php 23264159a61SAndreas Gohr echo $lang['i_pol2'] ?></option> 2338af2e4bbSAndreas Gohr </select> 23406361442SAndreas Gohr 235ab9346edSAnika Henke <label for="allowreg"> 23664159a61SAndreas Gohr <input type="checkbox" name="d[allowreg]" id="allowreg" <?php 23764159a61SAndreas Gohr echo(($d['allowreg'] ? ' checked="checked"' : '')); ?> /> 238ab9346edSAnika Henke <?php echo $lang['i_allowreg'] ?> 23974850f29SAnika Henke </label> 24047248316SAndreas Gohr </fieldset> 24147248316SAndreas Gohr </fieldset> 24247248316SAndreas Gohr 24306361442SAndreas Gohr <fieldset> 24406361442SAndreas Gohr <p><?php echo $lang['i_license'] ?></p> 24506361442SAndreas Gohr <?php 246b1f206e1SAndreas Gohr $license[] = ['name' => $lang['i_license_none'], 'url' => '']; 247ed856534STom N Harris if (empty($d['license'])) $d['license'] = 'cc-by-sa'; 24806361442SAndreas Gohr foreach ($license as $key => $lic) { 24906361442SAndreas Gohr echo '<label for="lic_' . $key . '">'; 25065cc1598SPhy echo '<input type="radio" name="d[license]" value="' . hsc($key) . '" id="lic_' . $key . '"' . 251b1730bd2STom N Harris (($d['license'] === $key) ? ' checked="checked"' : '') . '>'; 25265cc1598SPhy echo hsc($lic['name']); 25306361442SAndreas Gohr if ($lic['url']) echo ' <a href="' . $lic['url'] . '" target="_blank"><sup>[?]</sup></a>'; 25406361442SAndreas Gohr echo '</label>'; 25506361442SAndreas Gohr } 25606361442SAndreas Gohr ?> 25706361442SAndreas Gohr </fieldset> 25806361442SAndreas Gohr 2593a0852d9SAndreas Gohr <fieldset> 2603a0852d9SAndreas Gohr <p><?php echo $lang['i_pop_field'] ?></p> 2613a0852d9SAndreas Gohr <label for="pop"> 26264159a61SAndreas Gohr <input type="checkbox" name="d[pop]" id="pop" <?php 26364159a61SAndreas Gohr echo(($d['pop'] ? ' checked="checked"' : '')); ?> /> 26464159a61SAndreas Gohr <?php echo $lang['i_pop_label'] ?> 265220897aeSGerrit Uitslag <a href="https://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a> 2663a0852d9SAndreas Gohr </label> 2673a0852d9SAndreas Gohr </fieldset> 2683a0852d9SAndreas Gohr 26947248316SAndreas Gohr </fieldset> 27047248316SAndreas Gohr <fieldset id="process"> 271ae614416SAnika Henke <button type="submit" name="submit"><?php echo $lang['btn_save'] ?></button> 27247248316SAndreas Gohr </fieldset> 27347248316SAndreas Gohr </form> 27447248316SAndreas Gohr <?php 27547248316SAndreas Gohr} 27647248316SAndreas Gohr 277db581254Sjpedrycfunction print_retry() 278db581254Sjpedryc{ 27970a6aa16Schris global $lang; 2809ad6da3dSAndreas Gohr global $LC; 28170a6aa16Schris ?> 28270a6aa16Schris <form action="" method="get"> 28370a6aa16Schris <fieldset> 2849ad6da3dSAndreas Gohr <input type="hidden" name="l" value="<?php echo $LC ?>"/> 285ae614416SAnika Henke <button type="submit"><?php echo $lang['i_retry']; ?></button> 28670a6aa16Schris </fieldset> 28770a6aa16Schris </form> 28870a6aa16Schris <?php 28970a6aa16Schris} 29070a6aa16Schris 29147248316SAndreas Gohr/** 29247248316SAndreas Gohr * Check validity of data 29347248316SAndreas Gohr * 294253d4b48SGerrit Uitslag * @param array $d 295253d4b48SGerrit Uitslag * @return bool ok? 296ff84abadSGerrit Uitslag * @author Andreas Gohr 297ff84abadSGerrit Uitslag * 29847248316SAndreas Gohr */ 299db581254Sjpedrycfunction check_data(&$d) 300db581254Sjpedryc{ 301b1f206e1SAndreas Gohr static $form_default = [ 3024b530faaSTom N Harris 'title' => '', 303ed856534STom N Harris 'acl' => '1', 3044b530faaSTom N Harris 'superuser' => '', 3054b530faaSTom N Harris 'fullname' => '', 3064b530faaSTom N Harris 'email' => '', 3074b530faaSTom N Harris 'password' => '', 3084b530faaSTom N Harris 'confirm' => '', 3094b530faaSTom N Harris 'policy' => '0', 310ab9346edSAnika Henke 'allowreg' => '0', 3114b530faaSTom N Harris 'license' => 'cc-by-sa' 312b1f206e1SAndreas Gohr ]; 31347248316SAndreas Gohr global $lang; 31447248316SAndreas Gohr global $error; 31547248316SAndreas Gohr 316b1f206e1SAndreas Gohr if (!is_array($d)) $d = []; 3174b530faaSTom N Harris foreach ($d as $k => $v) { 3184b530faaSTom N Harris if (is_array($v)) 3194b530faaSTom N Harris unset($d[$k]); 320db581254Sjpedryc else $d[$k] = (string)$v; 3214b530faaSTom N Harris } 322e2386079SAndreas Gohr 3234b530faaSTom N Harris //autolowercase the username 3244b530faaSTom N Harris $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : ""; 3254b530faaSTom N Harris 3264b530faaSTom N Harris $ok = false; 3274b530faaSTom N Harris 3284b530faaSTom N Harris if (isset($_REQUEST['submit'])) { 32947248316SAndreas Gohr $ok = true; 33047248316SAndreas Gohr 33147248316SAndreas Gohr // check input 33247248316SAndreas Gohr if (empty($d['title'])) { 33347248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['i_wikiname']); 33447248316SAndreas Gohr $ok = false; 33547248316SAndreas Gohr } 3364b530faaSTom N Harris if (isset($d['acl'])) { 3372cb06bbdSjpedryc if (empty($d['superuser']) || ($d['superuser'] !== cleanID($d['superuser']))) { 33847248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['i_superuser']); 33947248316SAndreas Gohr $ok = false; 34047248316SAndreas Gohr } 34147248316SAndreas Gohr if (empty($d['password'])) { 34247248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['pass']); 34347248316SAndreas Gohr $ok = false; 344db581254Sjpedryc } elseif (!isset($d['confirm']) || $d['confirm'] != $d['password']) { 34547248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['passchk']); 34647248316SAndreas Gohr $ok = false; 34747248316SAndreas Gohr } 34847248316SAndreas Gohr if (empty($d['fullname']) || strstr($d['fullname'], ':')) { 34947248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['fullname']); 35047248316SAndreas Gohr $ok = false; 35147248316SAndreas Gohr } 352e2386079SAndreas Gohr if (empty($d['email']) || strstr($d['email'], ':') || !strstr($d['email'], '@')) { 35347248316SAndreas Gohr $error[] = sprintf($lang['i_badval'], $lang['email']); 35447248316SAndreas Gohr $ok = false; 35547248316SAndreas Gohr } 356b9ab8e4fSPhy } else { 357b9ab8e4fSPhy // Since default = 1, browser won't send acl=0 when user untick acl 358b9ab8e4fSPhy $d['acl'] = '0'; 35947248316SAndreas Gohr } 3604b530faaSTom N Harris } 3614b530faaSTom N Harris $d = array_merge($form_default, $d); 36247248316SAndreas Gohr return $ok; 36347248316SAndreas Gohr} 36447248316SAndreas Gohr 36547248316SAndreas Gohr/** 36647248316SAndreas Gohr * Writes the data to the config files 36747248316SAndreas Gohr * 368253d4b48SGerrit Uitslag * @param array $d 369253d4b48SGerrit Uitslag * @return bool 370ff84abadSGerrit Uitslag * @throws Exception 371ff84abadSGerrit Uitslag * 372ff84abadSGerrit Uitslag * @author Chris Smith <chris@jalakai.co.uk> 37347248316SAndreas Gohr */ 374db581254Sjpedrycfunction store_data($d) 375db581254Sjpedryc{ 3760036aa89SAndreas Gohr global $LC; 37747248316SAndreas Gohr $ok = true; 3788af2e4bbSAndreas Gohr $d['policy'] = (int)$d['policy']; 37947248316SAndreas Gohr 38047248316SAndreas Gohr // create local.php 381*234bbfafShauk92 $now = date('r'); 38247248316SAndreas Gohr $output = <<<EOT 38347248316SAndreas Gohr<?php 38447248316SAndreas Gohr/** 38547248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings 38647248316SAndreas Gohr * Auto-generated by install script 38747248316SAndreas Gohr * Date: $now 38847248316SAndreas Gohr */ 38947248316SAndreas Gohr 39047248316SAndreas GohrEOT; 3912613efa1SAndreas Gohr // add any config options set by a previous installer 3922613efa1SAndreas Gohr $preset = __DIR__ . '/install.conf'; 3932613efa1SAndreas Gohr if (file_exists($preset)) { 3942613efa1SAndreas Gohr $output .= "# preset config options\n"; 3952613efa1SAndreas Gohr $output .= file_get_contents($preset); 3962613efa1SAndreas Gohr $output .= "\n\n"; 3972613efa1SAndreas Gohr $output .= "# options selected in installer\n"; 3982613efa1SAndreas Gohr @unlink($preset); 3992613efa1SAndreas Gohr } 4002613efa1SAndreas Gohr 40147248316SAndreas Gohr $output .= '$conf[\'title\'] = \'' . addslashes($d['title']) . "';\n"; 4020036aa89SAndreas Gohr $output .= '$conf[\'lang\'] = \'' . addslashes($LC) . "';\n"; 40306361442SAndreas Gohr $output .= '$conf[\'license\'] = \'' . addslashes($d['license']) . "';\n"; 40447248316SAndreas Gohr if ($d['acl']) { 40547248316SAndreas Gohr $output .= '$conf[\'useacl\'] = 1' . ";\n"; 406523d7ea6Schris $output .= "\$conf['superuser'] = '@admin';\n"; 40747248316SAndreas Gohr } 408ab9346edSAnika Henke if (!$d['allowreg']) { 40943c137edSAnika Henke $output .= '$conf[\'disableactions\'] = \'register\'' . ";\n"; 410d2ea6dc1SAnika Henke } 41147248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'local.php', $output); 41247248316SAndreas Gohr 41347248316SAndreas Gohr if ($d['acl']) { 4143791b589SAndreas Gohr // hash the password 415b1f206e1SAndreas Gohr $phash = new PassHash(); 416267bbbcaSms101 $pass = $phash->hash_bcrypt($d['password']); 4173791b589SAndreas Gohr 41847248316SAndreas Gohr // create users.auth.php 419a672ef75SPhy $output = <<<EOT 420a672ef75SPhy# users.auth.php 421a672ef75SPhy# <?php exit()?> 422a672ef75SPhy# Don't modify the lines above 423a672ef75SPhy# 424a672ef75SPhy# Userfile 425a672ef75SPhy# 426a672ef75SPhy# Auto-generated by install script 427a672ef75SPhy# Date: $now 428a672ef75SPhy# 429a672ef75SPhy# Format: 430a672ef75SPhy# login:passwordhash:Real Name:email:groups,comma,separated 431a672ef75SPhy 432a672ef75SPhyEOT; 433722372bdSms101 // --- user:bcryptpasswordhash:Real Name:email:groups,comma,seperated 434b1f206e1SAndreas Gohr $output = $output . "\n" . implode(':', [ 43536a1a880SAndreas Gohr $d['superuser'], 43636a1a880SAndreas Gohr $pass, 43736a1a880SAndreas Gohr $d['fullname'], 43836a1a880SAndreas Gohr $d['email'], 43936a1a880SAndreas Gohr 'admin,user', 44036a1a880SAndreas Gohr ]) . "\n"; 44147248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'users.auth.php', $output); 44247248316SAndreas Gohr 44347248316SAndreas Gohr // create acl.auth.php 4448af2e4bbSAndreas Gohr $output = <<<EOT 4458af2e4bbSAndreas Gohr# acl.auth.php 4468af2e4bbSAndreas Gohr# <?php exit()?> 4478af2e4bbSAndreas Gohr# Don't modify the lines above 4488af2e4bbSAndreas Gohr# 4498af2e4bbSAndreas Gohr# Access Control Lists 4508af2e4bbSAndreas Gohr# 4518af2e4bbSAndreas Gohr# Auto-generated by install script 4528af2e4bbSAndreas Gohr# Date: $now 4538af2e4bbSAndreas Gohr 4548af2e4bbSAndreas GohrEOT; 4558af2e4bbSAndreas Gohr if ($d['policy'] == 2) { 4568af2e4bbSAndreas Gohr $output .= "* @ALL 0\n"; 457d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4589c70688aSchris } elseif ($d['policy'] == 1) { 4598af2e4bbSAndreas Gohr $output .= "* @ALL 1\n"; 460d2ea6dc1SAnika Henke $output .= "* @user 8\n"; 4618af2e4bbSAndreas Gohr } else { 4628af2e4bbSAndreas Gohr $output .= "* @ALL 8\n"; 4638af2e4bbSAndreas Gohr } 46447248316SAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'acl.auth.php', $output); 46547248316SAndreas Gohr } 4663a0852d9SAndreas Gohr 4673a0852d9SAndreas Gohr // enable popularity submission 468ee4f28e3SDamien Regad if (isset($d['pop']) && $d['pop']) { 4693a0852d9SAndreas Gohr @touch(DOKU_INC . 'data/cache/autosubmit.txt'); 4703a0852d9SAndreas Gohr } 4713a0852d9SAndreas Gohr 472c70d6ceeSAndreas Gohr // disable auth plugins til needed 473c70d6ceeSAndreas Gohr $output = <<<EOT 474c70d6ceeSAndreas Gohr<?php 475c70d6ceeSAndreas Gohr/* 476c70d6ceeSAndreas Gohr * Local plugin enable/disable settings 477c70d6ceeSAndreas Gohr * 478c70d6ceeSAndreas Gohr * Auto-generated by install script 479c70d6ceeSAndreas Gohr * Date: $now 480c70d6ceeSAndreas Gohr */ 481c70d6ceeSAndreas Gohr 482c70d6ceeSAndreas Gohr\$plugins['authad'] = 0; 483c70d6ceeSAndreas Gohr\$plugins['authldap'] = 0; 484c70d6ceeSAndreas Gohr\$plugins['authmysql'] = 0; 485c70d6ceeSAndreas Gohr\$plugins['authpgsql'] = 0; 486c70d6ceeSAndreas Gohr 487c70d6ceeSAndreas GohrEOT; 488c70d6ceeSAndreas Gohr $ok = $ok && fileWrite(DOKU_LOCAL . 'plugins.local.php', $output); 489c70d6ceeSAndreas Gohr 49047248316SAndreas Gohr return $ok; 49147248316SAndreas Gohr} 49247248316SAndreas Gohr 49347248316SAndreas Gohr/** 49447248316SAndreas Gohr * Write the given content to a file 49547248316SAndreas Gohr * 496253d4b48SGerrit Uitslag * @param string $filename 497253d4b48SGerrit Uitslag * @param string $data 498253d4b48SGerrit Uitslag * @return bool 499ff84abadSGerrit Uitslag * 500ff84abadSGerrit Uitslag * @author Chris Smith <chris@jalakai.co.uk> 50147248316SAndreas Gohr */ 502db581254Sjpedrycfunction fileWrite($filename, $data) 503db581254Sjpedryc{ 50447248316SAndreas Gohr global $error; 50547248316SAndreas Gohr global $lang; 50647248316SAndreas Gohr 50747248316SAndreas Gohr if (($fp = @fopen($filename, 'wb')) === false) { 50847248316SAndreas Gohr $filename = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $filename); 50947248316SAndreas Gohr $error[] = sprintf($lang['i_writeerr'], $filename); 51047248316SAndreas Gohr return false; 51147248316SAndreas Gohr } 51247248316SAndreas Gohr 513db581254Sjpedryc if (!empty($data)) { 514db581254Sjpedryc fwrite($fp, $data); 515db581254Sjpedryc } 51647248316SAndreas Gohr fclose($fp); 51747248316SAndreas Gohr return true; 51847248316SAndreas Gohr} 51947248316SAndreas Gohr 52047248316SAndreas Gohr 52147248316SAndreas Gohr/** 52247248316SAndreas Gohr * check installation dependent local config files and tests for a known 52347248316SAndreas Gohr * unmodified main config file 52447248316SAndreas Gohr * 525253d4b48SGerrit Uitslag * @return bool 526ff84abadSGerrit Uitslag * 527ff84abadSGerrit Uitslag * @author Chris Smith <chris@jalakai.co.uk> 52847248316SAndreas Gohr */ 529db581254Sjpedrycfunction check_configs() 530db581254Sjpedryc{ 53147248316SAndreas Gohr global $error; 53247248316SAndreas Gohr global $lang; 53347248316SAndreas Gohr 53447248316SAndreas Gohr $ok = true; 53547248316SAndreas Gohr 536b1f206e1SAndreas Gohr $config_files = [ 5375cfb8815Schris 'local' => DOKU_LOCAL . 'local.php', 5385cfb8815Schris 'users' => DOKU_LOCAL . 'users.auth.php', 5395cfb8815Schris 'auth' => DOKU_LOCAL . 'acl.auth.php' 540b1f206e1SAndreas Gohr ]; 5415cfb8815Schris 54247248316SAndreas Gohr // configs shouldn't exist 54347248316SAndreas Gohr foreach ($config_files as $file) { 54479e79377SAndreas Gohr if (file_exists($file) && filesize($file)) { 54547248316SAndreas Gohr $file = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $file); 54647248316SAndreas Gohr $error[] = sprintf($lang['i_confexists'], $file); 54747248316SAndreas Gohr $ok = false; 54847248316SAndreas Gohr } 54947248316SAndreas Gohr } 55047248316SAndreas Gohr return $ok; 55147248316SAndreas Gohr} 55247248316SAndreas Gohr 55347248316SAndreas Gohr 55447248316SAndreas Gohr/** 55547248316SAndreas Gohr * Check other installation dir/file permission requirements 55647248316SAndreas Gohr * 557253d4b48SGerrit Uitslag * @return bool 558ff84abadSGerrit Uitslag * 559ff84abadSGerrit Uitslag * @author Chris Smith <chris@jalakai.co.uk> 56047248316SAndreas Gohr */ 561db581254Sjpedrycfunction check_permissions() 562db581254Sjpedryc{ 56347248316SAndreas Gohr global $error; 56447248316SAndreas Gohr global $lang; 56547248316SAndreas Gohr 566b1f206e1SAndreas Gohr $dirs = [ 56747248316SAndreas Gohr 'conf' => DOKU_LOCAL, 56847248316SAndreas Gohr 'data' => DOKU_INC . 'data', 56947248316SAndreas Gohr 'pages' => DOKU_INC . 'data/pages', 57047248316SAndreas Gohr 'attic' => DOKU_INC . 'data/attic', 57147248316SAndreas Gohr 'media' => DOKU_INC . 'data/media', 57249b78edaSAndreas Gohr 'media_attic' => DOKU_INC . 'data/media_attic', 57349b78edaSAndreas Gohr 'media_meta' => DOKU_INC . 'data/media_meta', 57447248316SAndreas Gohr 'meta' => DOKU_INC . 'data/meta', 57547248316SAndreas Gohr 'cache' => DOKU_INC . 'data/cache', 57647248316SAndreas Gohr 'locks' => DOKU_INC . 'data/locks', 5779711045aSAndreas Gohr 'index' => DOKU_INC . 'data/index', 578de33a58fSMichael Klier 'tmp' => DOKU_INC . 'data/tmp' 579b1f206e1SAndreas Gohr ]; 58047248316SAndreas Gohr 58147248316SAndreas Gohr $ok = true; 58247248316SAndreas Gohr foreach ($dirs as $dir) { 58379e79377SAndreas Gohr if (!file_exists("$dir/.") || !is_writable($dir)) { 58470a6aa16Schris $dir = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}', $dir); 58547248316SAndreas Gohr $error[] = sprintf($lang['i_permfail'], $dir); 58647248316SAndreas Gohr $ok = false; 58747248316SAndreas Gohr } 58847248316SAndreas Gohr } 58947248316SAndreas Gohr return $ok; 59047248316SAndreas Gohr} 59147248316SAndreas Gohr 59247248316SAndreas Gohr/** 5933afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version 59447248316SAndreas Gohr * 595253d4b48SGerrit Uitslag * @return bool 596ff84abadSGerrit Uitslag * 597ff84abadSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 59847248316SAndreas Gohr */ 599db581254Sjpedrycfunction check_functions() 600db581254Sjpedryc{ 60147248316SAndreas Gohr global $error; 60247248316SAndreas Gohr global $lang; 6033afe5d1cSAndreas Gohr $ok = true; 6043afe5d1cSAndreas Gohr 605c49393f5SAndreas Gohr if (version_compare(phpversion(), '7.4.0', '<')) { 606c49393f5SAndreas Gohr $error[] = sprintf($lang['i_phpver'], phpversion(), '7.4.0'); 6073afe5d1cSAndreas Gohr $ok = false; 6083afe5d1cSAndreas Gohr } 6093afe5d1cSAndreas Gohr 6107f413440SAndreas Gohr if (ini_get('mbstring.func_overload') != 0) { 6117f413440SAndreas Gohr $error[] = $lang['i_mbfuncoverload']; 6127f413440SAndreas Gohr $ok = false; 6137f413440SAndreas Gohr } 6147f413440SAndreas Gohr 615387250efSPhy try { 616387250efSPhy random_bytes(1); 617ff84abadSGerrit Uitslag } catch (Exception $th) { 618387250efSPhy // If an appropriate source of randomness cannot be found, an Exception will be thrown by PHP 7+ 619387250efSPhy $error[] = $lang['i_urandom']; 620387250efSPhy $ok = false; 621387250efSPhy } 622387250efSPhy 623387250efSPhy if (ini_get('mbstring.func_overload') != 0) { 624387250efSPhy $error[] = $lang['i_mbfuncoverload']; 625387250efSPhy $ok = false; 626387250efSPhy } 627387250efSPhy 6283009a773SAndreas Gohr $funcs = explode(' ', 'addslashes call_user_func chmod copy fgets ' . 62947248316SAndreas Gohr 'file file_exists fseek flush filesize ftell fopen ' . 6303f6872b1SMyron Turner 'glob header ignore_user_abort ini_get mkdir ' . 63147248316SAndreas Gohr 'ob_start opendir parse_ini_file readfile realpath ' . 632bab4a8bdSAndreas Gohr 'rename rmdir serialize session_start unlink usleep ' . 633d1d99bb9SAndreas Gohr 'preg_replace file_get_contents htmlspecialchars_decode ' . 634670dc13dSAndreas Gohr 'spl_autoload_register stream_select fsockopen pack xml_parser_create'); 63547248316SAndreas Gohr 6363f6872b1SMyron Turner if (!function_exists('mail')) { 6373f6872b1SMyron Turner if (strpos(ini_get('disable_functions'), 'mail') !== false) { 6383f6872b1SMyron Turner $disabled = $lang['i_disabled']; 639db581254Sjpedryc } else { 6403f6872b1SMyron Turner $disabled = ""; 6413f6872b1SMyron Turner } 6423f6872b1SMyron Turner $error[] = sprintf($lang['i_funcnmail'], $disabled); 6433f6872b1SMyron Turner } 6443f6872b1SMyron Turner 64547248316SAndreas Gohr foreach ($funcs as $func) { 64647248316SAndreas Gohr if (!function_exists($func)) { 64747248316SAndreas Gohr $error[] = sprintf($lang['i_funcna'], $func); 64847248316SAndreas Gohr $ok = false; 64947248316SAndreas Gohr } 65047248316SAndreas Gohr } 65147248316SAndreas Gohr return $ok; 65247248316SAndreas Gohr} 65347248316SAndreas Gohr 65447248316SAndreas Gohr/** 65547248316SAndreas Gohr * Print language selection 65647248316SAndreas Gohr * 65747248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 65847248316SAndreas Gohr */ 659db581254Sjpedrycfunction langsel() 660db581254Sjpedryc{ 66147248316SAndreas Gohr global $lang; 66247248316SAndreas Gohr global $LC; 66347248316SAndreas Gohr 66447248316SAndreas Gohr $dir = DOKU_INC . 'inc/lang'; 66547248316SAndreas Gohr $dh = opendir($dir); 66647248316SAndreas Gohr if (!$dh) return; 66747248316SAndreas Gohr 668b1f206e1SAndreas Gohr $langs = []; 66947248316SAndreas Gohr while (($file = readdir($dh)) !== false) { 670220897aeSGerrit Uitslag if (preg_match('/^[._]/', $file)) continue; 67179e79377SAndreas Gohr if (is_dir($dir . '/' . $file) && file_exists($dir . '/' . $file . '/lang.php')) { 67247248316SAndreas Gohr $langs[] = $file; 67347248316SAndreas Gohr } 67447248316SAndreas Gohr } 67547248316SAndreas Gohr closedir($dh); 67647248316SAndreas Gohr sort($langs); 67747248316SAndreas Gohr 67847248316SAndreas Gohr echo '<form action="">'; 67947248316SAndreas Gohr echo $lang['i_chooselang']; 68047248316SAndreas Gohr echo ': <select name="l" onchange="submit()">'; 68147248316SAndreas Gohr foreach ($langs as $l) { 68247248316SAndreas Gohr $sel = ($l == $LC) ? 'selected="selected"' : ''; 68347248316SAndreas Gohr echo '<option value="' . $l . '" ' . $sel . '>' . $l . '</option>'; 68447248316SAndreas Gohr } 68547248316SAndreas Gohr echo '</select> '; 686ae614416SAnika Henke echo '<button type="submit">' . $lang['btn_update'] . '</button>'; 68747248316SAndreas Gohr echo '</form>'; 68847248316SAndreas Gohr} 68947248316SAndreas Gohr 69047248316SAndreas Gohr/** 691c66972f2SAdrian Lang * Print global error array 69247248316SAndreas Gohr * 69347248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 69447248316SAndreas Gohr */ 695db581254Sjpedrycfunction print_errors() 696db581254Sjpedryc{ 69747248316SAndreas Gohr global $error; 6984b530faaSTom N Harris if (!empty($error)) { 69947248316SAndreas Gohr echo '<ul>'; 70047248316SAndreas Gohr foreach ($error as $err) { 70147248316SAndreas Gohr echo "<li>$err</li>"; 70247248316SAndreas Gohr } 70347248316SAndreas Gohr echo '</ul>'; 70447248316SAndreas Gohr } 7054b530faaSTom N Harris} 706