xref: /dokuwiki/install.php (revision db5812548dce8c3d33de113cdc1d22a1dc818420)
15cfb8815Schris<?php
2*db581254Sjpedryc
3ac251797SAndreas Gohr/*><div style="width:60%; margin: auto; background-color: #fcc;
4ac251797SAndreas Gohr                border: 1px solid #faa; padding: 0.5em 1em;">
5ac251797SAndreas Gohr    <h1 style="font-size: 120%">No PHP Support</h1>
6ac251797SAndreas Gohr
7ac251797SAndreas Gohr    It seems this server has no PHP support enabled. You will need to
8ac251797SAndreas Gohr    enable PHP before you can install and run DokuWiki. Contact your hosting
9ac251797SAndreas Gohr    provider if you're unsure what this means.
10ac251797SAndreas Gohr
11ac251797SAndreas Gohr</div>*/
125cfb8815Schris/**
135cfb8815Schris * Dokuwiki installation assistance
145cfb8815Schris *
155cfb8815Schris * @author      Chris Smith <chris@jalakai.co.uk>
165cfb8815Schris */
175cfb8815Schris
18d0a27cb0SAndreas Gohrif (!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/');
195cfb8815Schrisif (!defined('DOKU_CONF')) define('DOKU_CONF', DOKU_INC . 'conf/');
205cfb8815Schrisif (!defined('DOKU_LOCAL')) define('DOKU_LOCAL', DOKU_INC . 'conf/');
215cfb8815Schris
2202bca5d4SYousong Zhou// load and initialize the core system
2302bca5d4SYousong Zhourequire_once(DOKU_INC . 'inc/init.php');
243791b589SAndreas Gohr
253545b2e0Schris// check for error reporting override or set error reporting to sane values
26*db581254Sjpedrycif (!defined('DOKU_E_LEVEL')) {
27*db581254Sjpedryc    error_reporting(E_ALL ^ E_NOTICE);
28*db581254Sjpedryc} else {
29*db581254Sjpedryc    error_reporting(DOKU_E_LEVEL);
30*db581254Sjpedryc}
313545b2e0Schris
3247248316SAndreas Gohr// language strings
3347248316SAndreas Gohrrequire_once(DOKU_INC . 'inc/lang/en/lang.php');
344b530faaSTom N Harrisif (isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) {
3547248316SAndreas Gohr    $LC = preg_replace('/[^a-z\-]+/', '', $_REQUEST['l']);
364b530faaSTom N Harris}
374b530faaSTom N Harrisif (empty($LC)) $LC = 'en';
3847248316SAndreas Gohrif ($LC && $LC != 'en') {
3947248316SAndreas Gohr    require_once(DOKU_INC . 'inc/lang/' . $LC . '/lang.php');
4047248316SAndreas Gohr}
4147248316SAndreas Gohr
4247248316SAndreas Gohr// initialise variables ...
4347248316SAndreas Gohr$error = array();
4447248316SAndreas Gohr
4547248316SAndreas Gohr// begin output
4647248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8');
4747248316SAndreas Gohr?>
48c8839c22SAnika Henke<!DOCTYPE html>
49c8839c22SAnika Henke<html lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>">
5047248316SAndreas Gohr<head>
51c8839c22SAnika Henke    <meta charset="utf-8" />
524208c142SAndreas Gohr    <title><?php echo $lang['i_installer']?></title>
5359305168SPhy    <style>
5447248316SAndreas Gohr        body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; }
5547248316SAndreas Gohr        img { border: none }
5647248316SAndreas Gohr        br.cl { clear:both; }
5770a6aa16Schris        code { font-size: 110%; color: #800000; }
5847248316SAndreas Gohr        fieldset { border: none }
599c70688aSchris        label { display: block; margin-top: 0.5em; }
608af2e4bbSAndreas Gohr        select.text, input.text { width: 30em; margin: 0 0.5em; }
6106361442SAndreas Gohr        a {text-decoration: none}
6247248316SAndreas Gohr    </style>
6359305168SPhy    <script>
6447248316SAndreas Gohr        function acltoggle(){
6547248316SAndreas Gohr            var cb = document.getElementById('acl');
6647248316SAndreas Gohr            var fs = document.getElementById('acldep');
6747248316SAndreas Gohr            if(!cb || !fs) return;
6847248316SAndreas Gohr            if(cb.checked){
6947248316SAndreas Gohr                fs.style.display = '';
7047248316SAndreas Gohr            }else{
7147248316SAndreas Gohr                fs.style.display = 'none';
7247248316SAndreas Gohr            }
7347248316SAndreas Gohr        }
7447248316SAndreas Gohr        window.onload = function(){
7547248316SAndreas Gohr            acltoggle();
7647248316SAndreas Gohr            var cb = document.getElementById('acl');
7747248316SAndreas Gohr            if(cb) cb.onchange = acltoggle;
7847248316SAndreas Gohr        };
7947248316SAndreas Gohr    </script>
8047248316SAndreas Gohr</head>
8147248316SAndreas Gohr<body style="">
8247248316SAndreas Gohr    <h1 style="float:left">
83c5270434SAndreas Gohr        <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png"
84c5270434SAndreas Gohr             style="vertical-align: middle;" alt="" height="64" width="64" />
8547248316SAndreas Gohr        <?php echo $lang['i_installer']?>
8647248316SAndreas Gohr    </h1>
8747248316SAndreas Gohr    <div style="float:right; margin: 1em;">
8847248316SAndreas Gohr        <?php langsel()?>
8947248316SAndreas Gohr    </div>
9047248316SAndreas Gohr    <br class="cl" />
9147248316SAndreas Gohr
9247248316SAndreas Gohr    <div style="float: right; width: 34%;">
9347248316SAndreas Gohr        <?php
9479e79377SAndreas Gohr        if (file_exists(DOKU_INC . 'inc/lang/' . $LC . '/install.html')) {
9547248316SAndreas Gohr            include(DOKU_INC . 'inc/lang/' . $LC . '/install.html');
9647248316SAndreas Gohr        } else {
97ca64d724Schris            print "<div lang=\"en\" dir=\"ltr\">\n";
9847248316SAndreas Gohr            include(DOKU_INC . 'inc/lang/en/install.html');
99ca64d724Schris            print "</div>\n";
10047248316SAndreas Gohr        }
10147248316SAndreas Gohr        ?>
10264159a61SAndreas Gohr        <a style="
10364159a61SAndreas Gohr                background: transparent
10464159a61SAndreas Gohr                url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png)
10564159a61SAndreas Gohr                left top no-repeat;
106c8b43921SAndreas Gohr                display: block; width:380px; height:73px; border:none; clear:both;"
107c8b43921SAndreas Gohr           target="_blank"
108c8b43921SAndreas Gohr           href="http://www.dokuwiki.org/security#web_access_security"></a>
10947248316SAndreas Gohr    </div>
11047248316SAndreas Gohr
11147248316SAndreas Gohr    <div style="float: left; width: 58%;">
11247248316SAndreas Gohr        <?php
1137ac1baa0SL. Ivanovich Harrison        try {
11447248316SAndreas Gohr            if (! (check_functions() && check_permissions())) {
11547248316SAndreas Gohr                echo '<p>' . $lang['i_problems'] . '</p>';
11647248316SAndreas Gohr                print_errors();
11770a6aa16Schris                print_retry();
11847248316SAndreas Gohr            } elseif (!check_configs()) {
11947248316SAndreas Gohr                echo '<p>' . $lang['i_modified'] . '</p>';
12047248316SAndreas Gohr                print_errors();
1214b530faaSTom N Harris            } elseif (check_data($_REQUEST['d'])) {
1224b530faaSTom N Harris                // check_data has sanitized all input parameters
1234b530faaSTom N Harris                if (!store_data($_REQUEST['d'])) {
12447248316SAndreas Gohr                    echo '<p>' . $lang['i_failure'] . '</p>';
12547248316SAndreas Gohr                    print_errors();
12647248316SAndreas Gohr                } else {
12747248316SAndreas Gohr                    echo '<p>' . $lang['i_success'] . '</p>';
12847248316SAndreas Gohr                }
12947248316SAndreas Gohr            } else {
1304b530faaSTom N Harris                print_errors();
13147248316SAndreas Gohr                print_form($_REQUEST['d']);
13247248316SAndreas Gohr            }
1337ac1baa0SL. Ivanovich Harrison        } catch (Exception $e) {
1347ac1baa0SL. Ivanovich Harrison            echo 'Caught exception: ',  $e->getMessage(), "\n";
1357ac1baa0SL. Ivanovich Harrison        }
13647248316SAndreas Gohr        ?>
13747248316SAndreas Gohr    </div>
13847248316SAndreas Gohr
139c8b43921SAndreas Gohr
14047248316SAndreas Gohr<div style="clear: both">
141654436fbSAnika Henke  <a href="http://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki" /></a>
14259752844SAnders Sandblad  <a href="http://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP" /></a>
14347248316SAndreas Gohr</div>
14447248316SAndreas Gohr</body>
14547248316SAndreas Gohr</html>
14647248316SAndreas Gohr<?php
14747248316SAndreas Gohr
14847248316SAndreas Gohr/**
14947248316SAndreas Gohr * Print the input form
150253d4b48SGerrit Uitslag *
151253d4b48SGerrit Uitslag * @param array $d submitted entry 'd' of request data
15247248316SAndreas Gohr */
153*db581254Sjpedrycfunction print_form($d)
154*db581254Sjpedryc{
15547248316SAndreas Gohr    global $lang;
15647248316SAndreas Gohr    global $LC;
15747248316SAndreas Gohr
15806361442SAndreas Gohr    include(DOKU_CONF . 'license.php');
15906361442SAndreas Gohr
16047248316SAndreas Gohr    if (!is_array($d)) $d = array();
16165cc1598SPhy    $d = array_map('hsc', $d);
16247248316SAndreas Gohr
16347248316SAndreas Gohr    if (!isset($d['acl'])) $d['acl'] = 1;
1643a0852d9SAndreas Gohr    if (!isset($d['pop'])) $d['pop'] = 1;
16547248316SAndreas Gohr
16647248316SAndreas Gohr    ?>
16747248316SAndreas Gohr    <form action="" method="post">
16847248316SAndreas Gohr    <input type="hidden" name="l" value="<?php echo $LC ?>" />
16947248316SAndreas Gohr    <fieldset>
17047248316SAndreas Gohr        <label for="title"><?php echo $lang['i_wikiname']?>
17147248316SAndreas Gohr        <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" />
17247248316SAndreas Gohr        </label>
17347248316SAndreas Gohr
17447248316SAndreas Gohr        <fieldset style="margin-top: 1em;">
17547248316SAndreas Gohr            <label for="acl">
17647248316SAndreas Gohr            <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : ''));?> />
17747248316SAndreas Gohr            <?php echo $lang['i_enableacl']?></label>
17847248316SAndreas Gohr
17947248316SAndreas Gohr            <fieldset id="acldep">
18047248316SAndreas Gohr                <label for="superuser"><?php echo $lang['i_superuser']?></label>
18164159a61SAndreas Gohr                <input class="text" type="text" name="d[superuser]" id="superuser"
18264159a61SAndreas Gohr                       value="<?php echo $d['superuser'] ?>" />
18347248316SAndreas Gohr
18447248316SAndreas Gohr                <label for="fullname"><?php echo $lang['fullname']?></label>
18564159a61SAndreas Gohr                <input class="text" type="text" name="d[fullname]" id="fullname"
18664159a61SAndreas Gohr                       value="<?php echo $d['fullname'] ?>" />
18747248316SAndreas Gohr
18847248316SAndreas Gohr                <label for="email"><?php echo $lang['email']?></label>
18947248316SAndreas Gohr                <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" />
19047248316SAndreas Gohr
19147248316SAndreas Gohr                <label for="password"><?php echo $lang['pass']?></label>
19247248316SAndreas Gohr                <input class="text" type="password" name="d[password]" id="password" />
19347248316SAndreas Gohr
19447248316SAndreas Gohr                <label for="confirm"><?php echo $lang['passchk']?></label>
19547248316SAndreas Gohr                <input class="text" type="password" name="d[confirm]" id="confirm" />
1968af2e4bbSAndreas Gohr
1978af2e4bbSAndreas Gohr                <label for="policy"><?php echo $lang['i_policy']?></label>
1988af2e4bbSAndreas Gohr                <select class="text" name="d[policy]" id="policy">
19964159a61SAndreas Gohr                    <option value="0" <?php echo ($d['policy'] == 0) ? 'selected="selected"' : '' ?>><?php
20064159a61SAndreas Gohr                        echo $lang['i_pol0']?></option>
20164159a61SAndreas Gohr                    <option value="1" <?php echo ($d['policy'] == 1) ? 'selected="selected"' : '' ?>><?php
20264159a61SAndreas Gohr                        echo $lang['i_pol1']?></option>
20364159a61SAndreas Gohr                    <option value="2" <?php echo ($d['policy'] == 2) ? 'selected="selected"' : '' ?>><?php
20464159a61SAndreas Gohr                        echo $lang['i_pol2']?></option>
2058af2e4bbSAndreas Gohr                </select>
20606361442SAndreas Gohr
207ab9346edSAnika Henke                <label for="allowreg">
20864159a61SAndreas Gohr                    <input type="checkbox" name="d[allowreg]" id="allowreg" <?php
20964159a61SAndreas Gohr                        echo(($d['allowreg'] ? ' checked="checked"' : ''));?> />
210ab9346edSAnika Henke                    <?php echo $lang['i_allowreg']?>
21174850f29SAnika Henke                </label>
21247248316SAndreas Gohr            </fieldset>
21347248316SAndreas Gohr        </fieldset>
21447248316SAndreas Gohr
21506361442SAndreas Gohr        <fieldset>
21606361442SAndreas Gohr            <p><?php echo $lang['i_license']?></p>
21706361442SAndreas Gohr            <?php
218b1730bd2STom N Harris            array_push($license, array('name' => $lang['i_license_none'], 'url' => ''));
219ed856534STom N Harris            if (empty($d['license'])) $d['license'] = 'cc-by-sa';
22006361442SAndreas Gohr            foreach ($license as $key => $lic) {
22106361442SAndreas Gohr                echo '<label for="lic_' . $key . '">';
22265cc1598SPhy                echo '<input type="radio" name="d[license]" value="' . hsc($key) . '" id="lic_' . $key . '"' .
223b1730bd2STom N Harris                     (($d['license'] === $key) ? ' checked="checked"' : '') . '>';
22465cc1598SPhy                echo hsc($lic['name']);
22506361442SAndreas Gohr                if ($lic['url']) echo ' <a href="' . $lic['url'] . '" target="_blank"><sup>[?]</sup></a>';
22606361442SAndreas Gohr                echo '</label>';
22706361442SAndreas Gohr            }
22806361442SAndreas Gohr            ?>
22906361442SAndreas Gohr        </fieldset>
23006361442SAndreas Gohr
2313a0852d9SAndreas Gohr        <fieldset>
2323a0852d9SAndreas Gohr            <p><?php echo $lang['i_pop_field']?></p>
2333a0852d9SAndreas Gohr            <label for="pop">
23464159a61SAndreas Gohr                <input type="checkbox" name="d[pop]" id="pop" <?php
23564159a61SAndreas Gohr                    echo(($d['pop'] ? ' checked="checked"' : ''));?> />
23664159a61SAndreas Gohr                <?php echo $lang['i_pop_label']?>
23764159a61SAndreas Gohr                <a href="http://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a>
2383a0852d9SAndreas Gohr            </label>
2393a0852d9SAndreas Gohr        </fieldset>
2403a0852d9SAndreas Gohr
24147248316SAndreas Gohr    </fieldset>
24247248316SAndreas Gohr    <fieldset id="process">
243ae614416SAnika Henke        <button type="submit" name="submit"><?php echo $lang['btn_save']?></button>
24447248316SAndreas Gohr    </fieldset>
24547248316SAndreas Gohr    </form>
24647248316SAndreas Gohr    <?php
24747248316SAndreas Gohr}
24847248316SAndreas Gohr
249*db581254Sjpedrycfunction print_retry()
250*db581254Sjpedryc{
25170a6aa16Schris    global $lang;
2529ad6da3dSAndreas Gohr    global $LC;
25370a6aa16Schris    ?>
25470a6aa16Schris    <form action="" method="get">
25570a6aa16Schris      <fieldset>
2569ad6da3dSAndreas Gohr        <input type="hidden" name="l" value="<?php echo $LC ?>" />
257ae614416SAnika Henke        <button type="submit"><?php echo $lang['i_retry'];?></button>
25870a6aa16Schris      </fieldset>
25970a6aa16Schris    </form>
26070a6aa16Schris    <?php
26170a6aa16Schris}
26270a6aa16Schris
26347248316SAndreas Gohr/**
26447248316SAndreas Gohr * Check validity of data
26547248316SAndreas Gohr *
26647248316SAndreas Gohr * @author Andreas Gohr
267253d4b48SGerrit Uitslag *
268253d4b48SGerrit Uitslag * @param array $d
269253d4b48SGerrit Uitslag * @return bool ok?
27047248316SAndreas Gohr */
271*db581254Sjpedrycfunction check_data(&$d)
272*db581254Sjpedryc{
2734b530faaSTom N Harris    static $form_default = array(
2744b530faaSTom N Harris        'title'     => '',
275ed856534STom N Harris        'acl'       => '1',
2764b530faaSTom N Harris        'superuser' => '',
2774b530faaSTom N Harris        'fullname'  => '',
2784b530faaSTom N Harris        'email'     => '',
2794b530faaSTom N Harris        'password'  => '',
2804b530faaSTom N Harris        'confirm'   => '',
2814b530faaSTom N Harris        'policy'    => '0',
282ab9346edSAnika Henke        'allowreg'  => '0',
2834b530faaSTom N Harris        'license'   => 'cc-by-sa'
2844b530faaSTom N Harris    );
28547248316SAndreas Gohr    global $lang;
28647248316SAndreas Gohr    global $error;
28747248316SAndreas Gohr
2884b530faaSTom N Harris    if (!is_array($d)) $d = array();
2894b530faaSTom N Harris    foreach ($d as $k => $v) {
2904b530faaSTom N Harris        if (is_array($v))
2914b530faaSTom N Harris            unset($d[$k]);
292*db581254Sjpedryc        else $d[$k] = (string)$v;
2934b530faaSTom N Harris    }
294e2386079SAndreas Gohr
2954b530faaSTom N Harris    //autolowercase the username
2964b530faaSTom N Harris    $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : "";
2974b530faaSTom N Harris
2984b530faaSTom N Harris    $ok = false;
2994b530faaSTom N Harris
3004b530faaSTom N Harris    if (isset($_REQUEST['submit'])) {
30147248316SAndreas Gohr        $ok = true;
30247248316SAndreas Gohr
30347248316SAndreas Gohr        // check input
30447248316SAndreas Gohr        if (empty($d['title'])) {
30547248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'], $lang['i_wikiname']);
30647248316SAndreas Gohr            $ok      = false;
30747248316SAndreas Gohr        }
3084b530faaSTom N Harris        if (isset($d['acl'])) {
309d60813a2SGina Haeussge            if (!preg_match('/^[a-z0-9_]+$/', $d['superuser'])) {
31047248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'], $lang['i_superuser']);
31147248316SAndreas Gohr                $ok      = false;
31247248316SAndreas Gohr            }
31347248316SAndreas Gohr            if (empty($d['password'])) {
31447248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'], $lang['pass']);
31547248316SAndreas Gohr                $ok      = false;
316*db581254Sjpedryc            } elseif (!isset($d['confirm']) || $d['confirm'] != $d['password']) {
31747248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'], $lang['passchk']);
31847248316SAndreas Gohr                $ok      = false;
31947248316SAndreas Gohr            }
32047248316SAndreas Gohr            if (empty($d['fullname']) || strstr($d['fullname'], ':')) {
32147248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'], $lang['fullname']);
32247248316SAndreas Gohr                $ok      = false;
32347248316SAndreas Gohr            }
324e2386079SAndreas Gohr            if (empty($d['email']) || strstr($d['email'], ':') || !strstr($d['email'], '@')) {
32547248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'], $lang['email']);
32647248316SAndreas Gohr                $ok      = false;
32747248316SAndreas Gohr            }
328b9ab8e4fSPhy        } else {
329b9ab8e4fSPhy            // Since default = 1, browser won't send acl=0 when user untick acl
330b9ab8e4fSPhy            $d['acl'] = '0';
33147248316SAndreas Gohr        }
3324b530faaSTom N Harris    }
3334b530faaSTom N Harris    $d = array_merge($form_default, $d);
33447248316SAndreas Gohr    return $ok;
33547248316SAndreas Gohr}
33647248316SAndreas Gohr
33747248316SAndreas Gohr/**
33847248316SAndreas Gohr * Writes the data to the config files
33947248316SAndreas Gohr *
34047248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
341253d4b48SGerrit Uitslag *
342253d4b48SGerrit Uitslag * @param array $d
343253d4b48SGerrit Uitslag * @return bool
34447248316SAndreas Gohr */
345*db581254Sjpedrycfunction store_data($d)
346*db581254Sjpedryc{
3470036aa89SAndreas Gohr    global $LC;
34847248316SAndreas Gohr    $ok = true;
3498af2e4bbSAndreas Gohr    $d['policy'] = (int) $d['policy'];
35047248316SAndreas Gohr
35147248316SAndreas Gohr    // create local.php
35224650a19SAndreas Gohr    $now    = gmdate('r');
35347248316SAndreas Gohr    $output = <<<EOT
35447248316SAndreas Gohr<?php
35547248316SAndreas Gohr/**
35647248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings
35747248316SAndreas Gohr * Auto-generated by install script
35847248316SAndreas Gohr * Date: $now
35947248316SAndreas Gohr */
36047248316SAndreas Gohr
36147248316SAndreas GohrEOT;
3622613efa1SAndreas Gohr    // add any config options set by a previous installer
3632613efa1SAndreas Gohr    $preset = __DIR__ . '/install.conf';
3642613efa1SAndreas Gohr    if (file_exists($preset)) {
3652613efa1SAndreas Gohr        $output .= "# preset config options\n";
3662613efa1SAndreas Gohr        $output .= file_get_contents($preset);
3672613efa1SAndreas Gohr        $output .= "\n\n";
3682613efa1SAndreas Gohr        $output .= "# options selected in installer\n";
3692613efa1SAndreas Gohr        @unlink($preset);
3702613efa1SAndreas Gohr    }
3712613efa1SAndreas Gohr
37247248316SAndreas Gohr    $output .= '$conf[\'title\'] = \'' . addslashes($d['title']) . "';\n";
3730036aa89SAndreas Gohr    $output .= '$conf[\'lang\'] = \'' . addslashes($LC) . "';\n";
37406361442SAndreas Gohr    $output .= '$conf[\'license\'] = \'' . addslashes($d['license']) . "';\n";
37547248316SAndreas Gohr    if ($d['acl']) {
37647248316SAndreas Gohr        $output .= '$conf[\'useacl\'] = 1' . ";\n";
377523d7ea6Schris        $output .= "\$conf['superuser'] = '@admin';\n";
37847248316SAndreas Gohr    }
379ab9346edSAnika Henke    if (!$d['allowreg']) {
38043c137edSAnika Henke        $output .= '$conf[\'disableactions\'] = \'register\'' . ";\n";
381d2ea6dc1SAnika Henke    }
38247248316SAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL . 'local.php', $output);
38347248316SAndreas Gohr
38447248316SAndreas Gohr    if ($d['acl']) {
3853791b589SAndreas Gohr        // hash the password
386c3cc6e05SAndreas Gohr        $phash = new \dokuwiki\PassHash();
387267bbbcaSms101        $pass = $phash->hash_bcrypt($d['password']);
3883791b589SAndreas Gohr
38947248316SAndreas Gohr        // create users.auth.php
390a672ef75SPhy        $output = <<<EOT
391a672ef75SPhy# users.auth.php
392a672ef75SPhy# <?php exit()?>
393a672ef75SPhy# Don't modify the lines above
394a672ef75SPhy#
395a672ef75SPhy# Userfile
396a672ef75SPhy#
397a672ef75SPhy# Auto-generated by install script
398a672ef75SPhy# Date: $now
399a672ef75SPhy#
400a672ef75SPhy# Format:
401a672ef75SPhy# login:passwordhash:Real Name:email:groups,comma,separated
402a672ef75SPhy
403a672ef75SPhyEOT;
404722372bdSms101        // --- user:bcryptpasswordhash:Real Name:email:groups,comma,seperated
405a672ef75SPhy        $output = $output . "\n" . join(":", array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user')) . "\n";
40647248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL . 'users.auth.php', $output);
40747248316SAndreas Gohr
40847248316SAndreas Gohr        // create acl.auth.php
4098af2e4bbSAndreas Gohr        $output = <<<EOT
4108af2e4bbSAndreas Gohr# acl.auth.php
4118af2e4bbSAndreas Gohr# <?php exit()?>
4128af2e4bbSAndreas Gohr# Don't modify the lines above
4138af2e4bbSAndreas Gohr#
4148af2e4bbSAndreas Gohr# Access Control Lists
4158af2e4bbSAndreas Gohr#
4168af2e4bbSAndreas Gohr# Auto-generated by install script
4178af2e4bbSAndreas Gohr# Date: $now
4188af2e4bbSAndreas Gohr
4198af2e4bbSAndreas GohrEOT;
4208af2e4bbSAndreas Gohr        if ($d['policy'] == 2) {
4218af2e4bbSAndreas Gohr            $output .=  "*               @ALL          0\n";
422d2ea6dc1SAnika Henke            $output .=  "*               @user         8\n";
4239c70688aSchris        } elseif ($d['policy'] == 1) {
4248af2e4bbSAndreas Gohr            $output .=  "*               @ALL          1\n";
425d2ea6dc1SAnika Henke            $output .=  "*               @user         8\n";
4268af2e4bbSAndreas Gohr        } else {
4278af2e4bbSAndreas Gohr            $output .=  "*               @ALL          8\n";
4288af2e4bbSAndreas Gohr        }
42947248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL . 'acl.auth.php', $output);
43047248316SAndreas Gohr    }
4313a0852d9SAndreas Gohr
4323a0852d9SAndreas Gohr    // enable popularity submission
433ee4f28e3SDamien Regad    if (isset($d['pop']) && $d['pop']) {
4343a0852d9SAndreas Gohr        @touch(DOKU_INC . 'data/cache/autosubmit.txt');
4353a0852d9SAndreas Gohr    }
4363a0852d9SAndreas Gohr
437c70d6ceeSAndreas Gohr    // disable auth plugins til needed
438c70d6ceeSAndreas Gohr    $output = <<<EOT
439c70d6ceeSAndreas Gohr<?php
440c70d6ceeSAndreas Gohr/*
441c70d6ceeSAndreas Gohr * Local plugin enable/disable settings
442c70d6ceeSAndreas Gohr *
443c70d6ceeSAndreas Gohr * Auto-generated by install script
444c70d6ceeSAndreas Gohr * Date: $now
445c70d6ceeSAndreas Gohr */
446c70d6ceeSAndreas Gohr
447c70d6ceeSAndreas Gohr\$plugins['authad']    = 0;
448c70d6ceeSAndreas Gohr\$plugins['authldap']  = 0;
449c70d6ceeSAndreas Gohr\$plugins['authmysql'] = 0;
450c70d6ceeSAndreas Gohr\$plugins['authpgsql'] = 0;
451c70d6ceeSAndreas Gohr
452c70d6ceeSAndreas GohrEOT;
453c70d6ceeSAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL . 'plugins.local.php', $output);
454c70d6ceeSAndreas Gohr
45547248316SAndreas Gohr    return $ok;
45647248316SAndreas Gohr}
45747248316SAndreas Gohr
45847248316SAndreas Gohr/**
45947248316SAndreas Gohr * Write the given content to a file
46047248316SAndreas Gohr *
46147248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
462253d4b48SGerrit Uitslag *
463253d4b48SGerrit Uitslag * @param string $filename
464253d4b48SGerrit Uitslag * @param string $data
465253d4b48SGerrit Uitslag * @return bool
46647248316SAndreas Gohr */
467*db581254Sjpedrycfunction fileWrite($filename, $data)
468*db581254Sjpedryc{
46947248316SAndreas Gohr    global $error;
47047248316SAndreas Gohr    global $lang;
47147248316SAndreas Gohr
47247248316SAndreas Gohr    if (($fp = @fopen($filename, 'wb')) === false) {
47347248316SAndreas Gohr        $filename = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $filename);
47447248316SAndreas Gohr        $error[]  = sprintf($lang['i_writeerr'], $filename);
47547248316SAndreas Gohr        return false;
47647248316SAndreas Gohr    }
47747248316SAndreas Gohr
478*db581254Sjpedryc    if (!empty($data)) {
479*db581254Sjpedryc        fwrite($fp, $data);
480*db581254Sjpedryc    }
48147248316SAndreas Gohr    fclose($fp);
48247248316SAndreas Gohr    return true;
48347248316SAndreas Gohr}
48447248316SAndreas Gohr
48547248316SAndreas Gohr
48647248316SAndreas Gohr/**
48747248316SAndreas Gohr * check installation dependent local config files and tests for a known
48847248316SAndreas Gohr * unmodified main config file
48947248316SAndreas Gohr *
49047248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
491253d4b48SGerrit Uitslag *
492253d4b48SGerrit Uitslag * @return bool
49347248316SAndreas Gohr */
494*db581254Sjpedrycfunction check_configs()
495*db581254Sjpedryc{
49647248316SAndreas Gohr    global $error;
49747248316SAndreas Gohr    global $lang;
49847248316SAndreas Gohr
49947248316SAndreas Gohr    $ok = true;
50047248316SAndreas Gohr
5015cfb8815Schris    $config_files = array(
5025cfb8815Schris        'local' => DOKU_LOCAL . 'local.php',
5035cfb8815Schris        'users' => DOKU_LOCAL . 'users.auth.php',
5045cfb8815Schris        'auth'  => DOKU_LOCAL . 'acl.auth.php'
5055cfb8815Schris    );
5065cfb8815Schris
50747248316SAndreas Gohr    // configs shouldn't exist
50847248316SAndreas Gohr    foreach ($config_files as $file) {
50979e79377SAndreas Gohr        if (file_exists($file) && filesize($file)) {
51047248316SAndreas Gohr            $file    = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $file);
51147248316SAndreas Gohr            $error[] = sprintf($lang['i_confexists'], $file);
51247248316SAndreas Gohr            $ok      = false;
51347248316SAndreas Gohr        }
51447248316SAndreas Gohr    }
51547248316SAndreas Gohr    return $ok;
51647248316SAndreas Gohr}
51747248316SAndreas Gohr
51847248316SAndreas Gohr
51947248316SAndreas Gohr/**
52047248316SAndreas Gohr * Check other installation dir/file permission requirements
52147248316SAndreas Gohr *
52247248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
523253d4b48SGerrit Uitslag *
524253d4b48SGerrit Uitslag * @return bool
52547248316SAndreas Gohr */
526*db581254Sjpedrycfunction check_permissions()
527*db581254Sjpedryc{
52847248316SAndreas Gohr    global $error;
52947248316SAndreas Gohr    global $lang;
53047248316SAndreas Gohr
53147248316SAndreas Gohr    $dirs = array(
53247248316SAndreas Gohr        'conf'        => DOKU_LOCAL,
53347248316SAndreas Gohr        'data'        => DOKU_INC . 'data',
53447248316SAndreas Gohr        'pages'       => DOKU_INC . 'data/pages',
53547248316SAndreas Gohr        'attic'       => DOKU_INC . 'data/attic',
53647248316SAndreas Gohr        'media'       => DOKU_INC . 'data/media',
53749b78edaSAndreas Gohr        'media_attic' => DOKU_INC . 'data/media_attic',
53849b78edaSAndreas Gohr        'media_meta'  => DOKU_INC . 'data/media_meta',
53947248316SAndreas Gohr        'meta'        => DOKU_INC . 'data/meta',
54047248316SAndreas Gohr        'cache'       => DOKU_INC . 'data/cache',
54147248316SAndreas Gohr        'locks'       => DOKU_INC . 'data/locks',
5429711045aSAndreas Gohr        'index'       => DOKU_INC . 'data/index',
543de33a58fSMichael Klier        'tmp'         => DOKU_INC . 'data/tmp'
54447248316SAndreas Gohr    );
54547248316SAndreas Gohr
54647248316SAndreas Gohr    $ok = true;
54747248316SAndreas Gohr    foreach ($dirs as $dir) {
54879e79377SAndreas Gohr        if (!file_exists("$dir/.") || !is_writable($dir)) {
54970a6aa16Schris            $dir     = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}', $dir);
55047248316SAndreas Gohr            $error[] = sprintf($lang['i_permfail'], $dir);
55147248316SAndreas Gohr            $ok      = false;
55247248316SAndreas Gohr        }
55347248316SAndreas Gohr    }
55447248316SAndreas Gohr    return $ok;
55547248316SAndreas Gohr}
55647248316SAndreas Gohr
55747248316SAndreas Gohr/**
5583afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version
55947248316SAndreas Gohr *
56047248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
561253d4b48SGerrit Uitslag *
562253d4b48SGerrit Uitslag * @return bool
56347248316SAndreas Gohr */
564*db581254Sjpedrycfunction check_functions()
565*db581254Sjpedryc{
56647248316SAndreas Gohr    global $error;
56747248316SAndreas Gohr    global $lang;
5683afe5d1cSAndreas Gohr    $ok = true;
5693afe5d1cSAndreas Gohr
5703476bb81SAndreas Gohr    if (version_compare(phpversion(), '5.6.0', '<')) {
5713476bb81SAndreas Gohr        $error[] = sprintf($lang['i_phpver'], phpversion(), '5.6.0');
5723afe5d1cSAndreas Gohr        $ok = false;
5733afe5d1cSAndreas Gohr    }
5743afe5d1cSAndreas Gohr
5757f413440SAndreas Gohr    if (ini_get('mbstring.func_overload') != 0) {
5767f413440SAndreas Gohr        $error[] = $lang['i_mbfuncoverload'];
5777f413440SAndreas Gohr        $ok = false;
5787f413440SAndreas Gohr    }
5797f413440SAndreas Gohr
580387250efSPhy    try {
581387250efSPhy        random_bytes(1);
582387250efSPhy    } catch (\Exception $th) {
583387250efSPhy        // If an appropriate source of randomness cannot be found, an Exception will be thrown by PHP 7+
584387250efSPhy        $error[] = $lang['i_urandom'];
585387250efSPhy        $ok = false;
586387250efSPhy    }
587387250efSPhy
588387250efSPhy    if (ini_get('mbstring.func_overload') != 0) {
589387250efSPhy        $error[] = $lang['i_mbfuncoverload'];
590387250efSPhy        $ok = false;
591387250efSPhy    }
592387250efSPhy
5933009a773SAndreas Gohr    $funcs = explode(' ', 'addslashes call_user_func chmod copy fgets ' .
59447248316SAndreas Gohr                         'file file_exists fseek flush filesize ftell fopen ' .
5953f6872b1SMyron Turner                         'glob header ignore_user_abort ini_get mkdir ' .
59647248316SAndreas Gohr                         'ob_start opendir parse_ini_file readfile realpath ' .
597bab4a8bdSAndreas Gohr                         'rename rmdir serialize session_start unlink usleep ' .
598d1d99bb9SAndreas Gohr                         'preg_replace file_get_contents htmlspecialchars_decode ' .
599670dc13dSAndreas Gohr                         'spl_autoload_register stream_select fsockopen pack xml_parser_create');
60047248316SAndreas Gohr
60170a6aa16Schris    if (!function_exists('mb_substr')) {
60270a6aa16Schris        $funcs[] = 'utf8_encode';
60370a6aa16Schris        $funcs[] = 'utf8_decode';
60470a6aa16Schris    }
60570a6aa16Schris
6063f6872b1SMyron Turner    if (!function_exists('mail')) {
6073f6872b1SMyron Turner        if (strpos(ini_get('disable_functions'), 'mail') !== false) {
6083f6872b1SMyron Turner            $disabled = $lang['i_disabled'];
609*db581254Sjpedryc        } else {
6103f6872b1SMyron Turner            $disabled = "";
6113f6872b1SMyron Turner        }
6123f6872b1SMyron Turner        $error[] = sprintf($lang['i_funcnmail'], $disabled);
6133f6872b1SMyron Turner    }
6143f6872b1SMyron Turner
61547248316SAndreas Gohr    foreach ($funcs as $func) {
61647248316SAndreas Gohr        if (!function_exists($func)) {
61747248316SAndreas Gohr            $error[] = sprintf($lang['i_funcna'], $func);
61847248316SAndreas Gohr            $ok = false;
61947248316SAndreas Gohr        }
62047248316SAndreas Gohr    }
62147248316SAndreas Gohr    return $ok;
62247248316SAndreas Gohr}
62347248316SAndreas Gohr
62447248316SAndreas Gohr/**
62547248316SAndreas Gohr * Print language selection
62647248316SAndreas Gohr *
62747248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
62847248316SAndreas Gohr */
629*db581254Sjpedrycfunction langsel()
630*db581254Sjpedryc{
63147248316SAndreas Gohr    global $lang;
63247248316SAndreas Gohr    global $LC;
63347248316SAndreas Gohr
63447248316SAndreas Gohr    $dir = DOKU_INC . 'inc/lang';
63547248316SAndreas Gohr    $dh  = opendir($dir);
63647248316SAndreas Gohr    if (!$dh) return;
63747248316SAndreas Gohr
63847248316SAndreas Gohr    $langs = array();
63947248316SAndreas Gohr    while (($file = readdir($dh)) !== false) {
64047248316SAndreas Gohr        if (preg_match('/^[\._]/', $file)) continue;
64179e79377SAndreas Gohr        if (is_dir($dir . '/' . $file) && file_exists($dir . '/' . $file . '/lang.php')) {
64247248316SAndreas Gohr            $langs[] = $file;
64347248316SAndreas Gohr        }
64447248316SAndreas Gohr    }
64547248316SAndreas Gohr    closedir($dh);
64647248316SAndreas Gohr    sort($langs);
64747248316SAndreas Gohr
64847248316SAndreas Gohr    echo '<form action="">';
64947248316SAndreas Gohr    echo $lang['i_chooselang'];
65047248316SAndreas Gohr    echo ': <select name="l" onchange="submit()">';
65147248316SAndreas Gohr    foreach ($langs as $l) {
65247248316SAndreas Gohr        $sel = ($l == $LC) ? 'selected="selected"' : '';
65347248316SAndreas Gohr        echo '<option value="' . $l . '" ' . $sel . '>' . $l . '</option>';
65447248316SAndreas Gohr    }
65547248316SAndreas Gohr    echo '</select> ';
656ae614416SAnika Henke    echo '<button type="submit">' . $lang['btn_update'] . '</button>';
65747248316SAndreas Gohr    echo '</form>';
65847248316SAndreas Gohr}
65947248316SAndreas Gohr
66047248316SAndreas Gohr/**
661c66972f2SAdrian Lang * Print global error array
66247248316SAndreas Gohr *
66347248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
66447248316SAndreas Gohr */
665*db581254Sjpedrycfunction print_errors()
666*db581254Sjpedryc{
66747248316SAndreas Gohr    global $error;
6684b530faaSTom N Harris    if (!empty($error)) {
66947248316SAndreas Gohr        echo '<ul>';
67047248316SAndreas Gohr        foreach ($error as $err) {
67147248316SAndreas Gohr            echo "<li>$err</li>";
67247248316SAndreas Gohr        }
67347248316SAndreas Gohr        echo '</ul>';
67447248316SAndreas Gohr    }
6754b530faaSTom N Harris}
676