xref: /dokuwiki/install.php (revision 36a1a8807f1cc9849e89e04d2778992e17a2d738)
15cfb8815Schris<?php
2db581254Sjpedryc
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');
242cb06bbdSjpedrycrequire_once(DOKU_INC . 'inc/pageutils.php');
253791b589SAndreas Gohr
263545b2e0Schris// check for error reporting override or set error reporting to sane values
27db581254Sjpedrycif (!defined('DOKU_E_LEVEL')) {
28db581254Sjpedryc    error_reporting(E_ALL ^ E_NOTICE);
29db581254Sjpedryc} else {
30db581254Sjpedryc    error_reporting(DOKU_E_LEVEL);
31db581254Sjpedryc}
323545b2e0Schris
3347248316SAndreas Gohr// language strings
3447248316SAndreas Gohrrequire_once(DOKU_INC . 'inc/lang/en/lang.php');
354b530faaSTom N Harrisif (isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) {
3647248316SAndreas Gohr    $LC = preg_replace('/[^a-z\-]+/', '', $_REQUEST['l']);
374b530faaSTom N Harris}
384b530faaSTom N Harrisif (empty($LC)) $LC = 'en';
3947248316SAndreas Gohrif ($LC && $LC != 'en') {
4047248316SAndreas Gohr    require_once(DOKU_INC . 'inc/lang/' . $LC . '/lang.php');
4147248316SAndreas Gohr}
4247248316SAndreas Gohr
4347248316SAndreas Gohr// initialise variables ...
4447248316SAndreas Gohr$error = array();
4547248316SAndreas Gohr
4647248316SAndreas Gohr// begin output
4747248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8');
4847248316SAndreas Gohr?>
49c8839c22SAnika Henke<!DOCTYPE html>
50c8839c22SAnika Henke<html lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>">
5147248316SAndreas Gohr<head>
52c8839c22SAnika Henke    <meta charset="utf-8" />
534208c142SAndreas Gohr    <title><?php echo $lang['i_installer']?></title>
5459305168SPhy    <style>
5547248316SAndreas Gohr        body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; }
5647248316SAndreas Gohr        img { border: none }
5747248316SAndreas Gohr        br.cl { clear:both; }
5870a6aa16Schris        code { font-size: 110%; color: #800000; }
5947248316SAndreas Gohr        fieldset { border: none }
609c70688aSchris        label { display: block; margin-top: 0.5em; }
618af2e4bbSAndreas Gohr        select.text, input.text { width: 30em; margin: 0 0.5em; }
6206361442SAndreas Gohr        a {text-decoration: none}
6347248316SAndreas Gohr    </style>
6459305168SPhy    <script>
6547248316SAndreas Gohr        function acltoggle(){
6647248316SAndreas Gohr            var cb = document.getElementById('acl');
6747248316SAndreas Gohr            var fs = document.getElementById('acldep');
6847248316SAndreas Gohr            if(!cb || !fs) return;
6947248316SAndreas Gohr            if(cb.checked){
7047248316SAndreas Gohr                fs.style.display = '';
7147248316SAndreas Gohr            }else{
7247248316SAndreas Gohr                fs.style.display = 'none';
7347248316SAndreas Gohr            }
7447248316SAndreas Gohr        }
7547248316SAndreas Gohr        window.onload = function(){
7647248316SAndreas Gohr            acltoggle();
7747248316SAndreas Gohr            var cb = document.getElementById('acl');
7847248316SAndreas Gohr            if(cb) cb.onchange = acltoggle;
7947248316SAndreas Gohr        };
8047248316SAndreas Gohr    </script>
8147248316SAndreas Gohr</head>
8247248316SAndreas Gohr<body style="">
8347248316SAndreas Gohr    <h1 style="float:left">
84c5270434SAndreas Gohr        <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png"
85c5270434SAndreas Gohr             style="vertical-align: middle;" alt="" height="64" width="64" />
8647248316SAndreas Gohr        <?php echo $lang['i_installer']?>
8747248316SAndreas Gohr    </h1>
8847248316SAndreas Gohr    <div style="float:right; margin: 1em;">
8947248316SAndreas Gohr        <?php langsel()?>
9047248316SAndreas Gohr    </div>
9147248316SAndreas Gohr    <br class="cl" />
9247248316SAndreas Gohr
9347248316SAndreas Gohr    <div style="float: right; width: 34%;">
9447248316SAndreas Gohr        <?php
9579e79377SAndreas Gohr        if (file_exists(DOKU_INC . 'inc/lang/' . $LC . '/install.html')) {
9647248316SAndreas Gohr            include(DOKU_INC . 'inc/lang/' . $LC . '/install.html');
9747248316SAndreas Gohr        } else {
98ca64d724Schris            print "<div lang=\"en\" dir=\"ltr\">\n";
9947248316SAndreas Gohr            include(DOKU_INC . 'inc/lang/en/install.html');
100ca64d724Schris            print "</div>\n";
10147248316SAndreas Gohr        }
10247248316SAndreas Gohr        ?>
10364159a61SAndreas Gohr        <a style="
10464159a61SAndreas Gohr                background: transparent
10564159a61SAndreas Gohr                url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png)
10664159a61SAndreas Gohr                left top no-repeat;
107c8b43921SAndreas Gohr                display: block; width:380px; height:73px; border:none; clear:both;"
108c8b43921SAndreas Gohr           target="_blank"
109c8b43921SAndreas Gohr           href="http://www.dokuwiki.org/security#web_access_security"></a>
11047248316SAndreas Gohr    </div>
11147248316SAndreas Gohr
11247248316SAndreas Gohr    <div style="float: left; width: 58%;">
11347248316SAndreas Gohr        <?php
1147ac1baa0SL. Ivanovich Harrison        try {
11547248316SAndreas Gohr            if (! (check_functions() && check_permissions())) {
11647248316SAndreas Gohr                echo '<p>' . $lang['i_problems'] . '</p>';
11747248316SAndreas Gohr                print_errors();
11870a6aa16Schris                print_retry();
11947248316SAndreas Gohr            } elseif (!check_configs()) {
12047248316SAndreas Gohr                echo '<p>' . $lang['i_modified'] . '</p>';
12147248316SAndreas Gohr                print_errors();
1224b530faaSTom N Harris            } elseif (check_data($_REQUEST['d'])) {
1234b530faaSTom N Harris                // check_data has sanitized all input parameters
1244b530faaSTom N Harris                if (!store_data($_REQUEST['d'])) {
12547248316SAndreas Gohr                    echo '<p>' . $lang['i_failure'] . '</p>';
12647248316SAndreas Gohr                    print_errors();
12747248316SAndreas Gohr                } else {
12847248316SAndreas Gohr                    echo '<p>' . $lang['i_success'] . '</p>';
12947248316SAndreas Gohr                }
13047248316SAndreas Gohr            } else {
1314b530faaSTom N Harris                print_errors();
13247248316SAndreas Gohr                print_form($_REQUEST['d']);
13347248316SAndreas Gohr            }
1347ac1baa0SL. Ivanovich Harrison        } catch (Exception $e) {
1357ac1baa0SL. Ivanovich Harrison            echo 'Caught exception: ',  $e->getMessage(), "\n";
1367ac1baa0SL. Ivanovich Harrison        }
13747248316SAndreas Gohr        ?>
13847248316SAndreas Gohr    </div>
13947248316SAndreas Gohr
140c8b43921SAndreas Gohr
14147248316SAndreas Gohr<div style="clear: both">
142654436fbSAnika Henke  <a href="http://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki" /></a>
14359752844SAnders Sandblad  <a href="http://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP" /></a>
14447248316SAndreas Gohr</div>
14547248316SAndreas Gohr</body>
14647248316SAndreas Gohr</html>
14747248316SAndreas Gohr<?php
14847248316SAndreas Gohr
14947248316SAndreas Gohr/**
15047248316SAndreas Gohr * Print the input form
151253d4b48SGerrit Uitslag *
152253d4b48SGerrit Uitslag * @param array $d submitted entry 'd' of request data
15347248316SAndreas Gohr */
154db581254Sjpedrycfunction print_form($d)
155db581254Sjpedryc{
15647248316SAndreas Gohr    global $lang;
15747248316SAndreas Gohr    global $LC;
15847248316SAndreas Gohr
15906361442SAndreas Gohr    include(DOKU_CONF . 'license.php');
16006361442SAndreas Gohr
16147248316SAndreas Gohr    if (!is_array($d)) $d = array();
16265cc1598SPhy    $d = array_map('hsc', $d);
16347248316SAndreas Gohr
16447248316SAndreas Gohr    if (!isset($d['acl'])) $d['acl'] = 1;
1653a0852d9SAndreas Gohr    if (!isset($d['pop'])) $d['pop'] = 1;
16647248316SAndreas Gohr
16747248316SAndreas Gohr    ?>
16847248316SAndreas Gohr    <form action="" method="post">
16947248316SAndreas Gohr    <input type="hidden" name="l" value="<?php echo $LC ?>" />
17047248316SAndreas Gohr    <fieldset>
17147248316SAndreas Gohr        <label for="title"><?php echo $lang['i_wikiname']?>
17247248316SAndreas Gohr        <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" />
17347248316SAndreas Gohr        </label>
17447248316SAndreas Gohr
17547248316SAndreas Gohr        <fieldset style="margin-top: 1em;">
17647248316SAndreas Gohr            <label for="acl">
17747248316SAndreas Gohr            <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : ''));?> />
17847248316SAndreas Gohr            <?php echo $lang['i_enableacl']?></label>
17947248316SAndreas Gohr
18047248316SAndreas Gohr            <fieldset id="acldep">
18147248316SAndreas Gohr                <label for="superuser"><?php echo $lang['i_superuser']?></label>
18264159a61SAndreas Gohr                <input class="text" type="text" name="d[superuser]" id="superuser"
18364159a61SAndreas Gohr                       value="<?php echo $d['superuser'] ?>" />
18447248316SAndreas Gohr
18547248316SAndreas Gohr                <label for="fullname"><?php echo $lang['fullname']?></label>
18664159a61SAndreas Gohr                <input class="text" type="text" name="d[fullname]" id="fullname"
18764159a61SAndreas Gohr                       value="<?php echo $d['fullname'] ?>" />
18847248316SAndreas Gohr
18947248316SAndreas Gohr                <label for="email"><?php echo $lang['email']?></label>
19047248316SAndreas Gohr                <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" />
19147248316SAndreas Gohr
19247248316SAndreas Gohr                <label for="password"><?php echo $lang['pass']?></label>
19347248316SAndreas Gohr                <input class="text" type="password" name="d[password]" id="password" />
19447248316SAndreas Gohr
19547248316SAndreas Gohr                <label for="confirm"><?php echo $lang['passchk']?></label>
19647248316SAndreas Gohr                <input class="text" type="password" name="d[confirm]" id="confirm" />
1978af2e4bbSAndreas Gohr
1988af2e4bbSAndreas Gohr                <label for="policy"><?php echo $lang['i_policy']?></label>
1998af2e4bbSAndreas Gohr                <select class="text" name="d[policy]" id="policy">
20064159a61SAndreas Gohr                    <option value="0" <?php echo ($d['policy'] == 0) ? 'selected="selected"' : '' ?>><?php
20164159a61SAndreas Gohr                        echo $lang['i_pol0']?></option>
20264159a61SAndreas Gohr                    <option value="1" <?php echo ($d['policy'] == 1) ? 'selected="selected"' : '' ?>><?php
20364159a61SAndreas Gohr                        echo $lang['i_pol1']?></option>
20464159a61SAndreas Gohr                    <option value="2" <?php echo ($d['policy'] == 2) ? 'selected="selected"' : '' ?>><?php
20564159a61SAndreas Gohr                        echo $lang['i_pol2']?></option>
2068af2e4bbSAndreas Gohr                </select>
20706361442SAndreas Gohr
208ab9346edSAnika Henke                <label for="allowreg">
20964159a61SAndreas Gohr                    <input type="checkbox" name="d[allowreg]" id="allowreg" <?php
21064159a61SAndreas Gohr                        echo(($d['allowreg'] ? ' checked="checked"' : ''));?> />
211ab9346edSAnika Henke                    <?php echo $lang['i_allowreg']?>
21274850f29SAnika Henke                </label>
21347248316SAndreas Gohr            </fieldset>
21447248316SAndreas Gohr        </fieldset>
21547248316SAndreas Gohr
21606361442SAndreas Gohr        <fieldset>
21706361442SAndreas Gohr            <p><?php echo $lang['i_license']?></p>
21806361442SAndreas Gohr            <?php
219b1730bd2STom N Harris            array_push($license, array('name' => $lang['i_license_none'], 'url' => ''));
220ed856534STom N Harris            if (empty($d['license'])) $d['license'] = 'cc-by-sa';
22106361442SAndreas Gohr            foreach ($license as $key => $lic) {
22206361442SAndreas Gohr                echo '<label for="lic_' . $key . '">';
22365cc1598SPhy                echo '<input type="radio" name="d[license]" value="' . hsc($key) . '" id="lic_' . $key . '"' .
224b1730bd2STom N Harris                     (($d['license'] === $key) ? ' checked="checked"' : '') . '>';
22565cc1598SPhy                echo hsc($lic['name']);
22606361442SAndreas Gohr                if ($lic['url']) echo ' <a href="' . $lic['url'] . '" target="_blank"><sup>[?]</sup></a>';
22706361442SAndreas Gohr                echo '</label>';
22806361442SAndreas Gohr            }
22906361442SAndreas Gohr            ?>
23006361442SAndreas Gohr        </fieldset>
23106361442SAndreas Gohr
2323a0852d9SAndreas Gohr        <fieldset>
2333a0852d9SAndreas Gohr            <p><?php echo $lang['i_pop_field']?></p>
2343a0852d9SAndreas Gohr            <label for="pop">
23564159a61SAndreas Gohr                <input type="checkbox" name="d[pop]" id="pop" <?php
23664159a61SAndreas Gohr                    echo(($d['pop'] ? ' checked="checked"' : ''));?> />
23764159a61SAndreas Gohr                <?php echo $lang['i_pop_label']?>
23864159a61SAndreas Gohr                <a href="http://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a>
2393a0852d9SAndreas Gohr            </label>
2403a0852d9SAndreas Gohr        </fieldset>
2413a0852d9SAndreas Gohr
24247248316SAndreas Gohr    </fieldset>
24347248316SAndreas Gohr    <fieldset id="process">
244ae614416SAnika Henke        <button type="submit" name="submit"><?php echo $lang['btn_save']?></button>
24547248316SAndreas Gohr    </fieldset>
24647248316SAndreas Gohr    </form>
24747248316SAndreas Gohr    <?php
24847248316SAndreas Gohr}
24947248316SAndreas Gohr
250db581254Sjpedrycfunction print_retry()
251db581254Sjpedryc{
25270a6aa16Schris    global $lang;
2539ad6da3dSAndreas Gohr    global $LC;
25470a6aa16Schris    ?>
25570a6aa16Schris    <form action="" method="get">
25670a6aa16Schris      <fieldset>
2579ad6da3dSAndreas Gohr        <input type="hidden" name="l" value="<?php echo $LC ?>" />
258ae614416SAnika Henke        <button type="submit"><?php echo $lang['i_retry'];?></button>
25970a6aa16Schris      </fieldset>
26070a6aa16Schris    </form>
26170a6aa16Schris    <?php
26270a6aa16Schris}
26370a6aa16Schris
26447248316SAndreas Gohr/**
26547248316SAndreas Gohr * Check validity of data
26647248316SAndreas Gohr *
26747248316SAndreas Gohr * @author Andreas Gohr
268253d4b48SGerrit Uitslag *
269253d4b48SGerrit Uitslag * @param array $d
270253d4b48SGerrit Uitslag * @return bool ok?
27147248316SAndreas Gohr */
272db581254Sjpedrycfunction check_data(&$d)
273db581254Sjpedryc{
2744b530faaSTom N Harris    static $form_default = array(
2754b530faaSTom N Harris        'title'     => '',
276ed856534STom N Harris        'acl'       => '1',
2774b530faaSTom N Harris        'superuser' => '',
2784b530faaSTom N Harris        'fullname'  => '',
2794b530faaSTom N Harris        'email'     => '',
2804b530faaSTom N Harris        'password'  => '',
2814b530faaSTom N Harris        'confirm'   => '',
2824b530faaSTom N Harris        'policy'    => '0',
283ab9346edSAnika Henke        'allowreg'  => '0',
2844b530faaSTom N Harris        'license'   => 'cc-by-sa'
2854b530faaSTom N Harris    );
28647248316SAndreas Gohr    global $lang;
28747248316SAndreas Gohr    global $error;
28847248316SAndreas Gohr
2894b530faaSTom N Harris    if (!is_array($d)) $d = array();
2904b530faaSTom N Harris    foreach ($d as $k => $v) {
2914b530faaSTom N Harris        if (is_array($v))
2924b530faaSTom N Harris            unset($d[$k]);
293db581254Sjpedryc        else $d[$k] = (string)$v;
2944b530faaSTom N Harris    }
295e2386079SAndreas Gohr
2964b530faaSTom N Harris    //autolowercase the username
2974b530faaSTom N Harris    $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : "";
2984b530faaSTom N Harris
2994b530faaSTom N Harris    $ok = false;
3004b530faaSTom N Harris
3014b530faaSTom N Harris    if (isset($_REQUEST['submit'])) {
30247248316SAndreas Gohr        $ok = true;
30347248316SAndreas Gohr
30447248316SAndreas Gohr        // check input
30547248316SAndreas Gohr        if (empty($d['title'])) {
30647248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'], $lang['i_wikiname']);
30747248316SAndreas Gohr            $ok      = false;
30847248316SAndreas Gohr        }
3094b530faaSTom N Harris        if (isset($d['acl'])) {
3102cb06bbdSjpedryc            if (empty($d['superuser']) || ($d['superuser'] !== cleanID($d['superuser']))) {
31147248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'], $lang['i_superuser']);
31247248316SAndreas Gohr                $ok      = false;
31347248316SAndreas Gohr            }
31447248316SAndreas Gohr            if (empty($d['password'])) {
31547248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'], $lang['pass']);
31647248316SAndreas Gohr                $ok      = false;
317db581254Sjpedryc            } elseif (!isset($d['confirm']) || $d['confirm'] != $d['password']) {
31847248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'], $lang['passchk']);
31947248316SAndreas Gohr                $ok      = false;
32047248316SAndreas Gohr            }
32147248316SAndreas Gohr            if (empty($d['fullname']) || strstr($d['fullname'], ':')) {
32247248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'], $lang['fullname']);
32347248316SAndreas Gohr                $ok      = false;
32447248316SAndreas Gohr            }
325e2386079SAndreas Gohr            if (empty($d['email']) || strstr($d['email'], ':') || !strstr($d['email'], '@')) {
32647248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'], $lang['email']);
32747248316SAndreas Gohr                $ok      = false;
32847248316SAndreas Gohr            }
329b9ab8e4fSPhy        } else {
330b9ab8e4fSPhy            // Since default = 1, browser won't send acl=0 when user untick acl
331b9ab8e4fSPhy            $d['acl'] = '0';
33247248316SAndreas Gohr        }
3334b530faaSTom N Harris    }
3344b530faaSTom N Harris    $d = array_merge($form_default, $d);
33547248316SAndreas Gohr    return $ok;
33647248316SAndreas Gohr}
33747248316SAndreas Gohr
33847248316SAndreas Gohr/**
33947248316SAndreas Gohr * Writes the data to the config files
34047248316SAndreas Gohr *
34147248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
342253d4b48SGerrit Uitslag *
343253d4b48SGerrit Uitslag * @param array $d
344253d4b48SGerrit Uitslag * @return bool
34547248316SAndreas Gohr */
346db581254Sjpedrycfunction store_data($d)
347db581254Sjpedryc{
3480036aa89SAndreas Gohr    global $LC;
34947248316SAndreas Gohr    $ok = true;
3508af2e4bbSAndreas Gohr    $d['policy'] = (int) $d['policy'];
35147248316SAndreas Gohr
35247248316SAndreas Gohr    // create local.php
35324650a19SAndreas Gohr    $now    = gmdate('r');
35447248316SAndreas Gohr    $output = <<<EOT
35547248316SAndreas Gohr<?php
35647248316SAndreas Gohr/**
35747248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings
35847248316SAndreas Gohr * Auto-generated by install script
35947248316SAndreas Gohr * Date: $now
36047248316SAndreas Gohr */
36147248316SAndreas Gohr
36247248316SAndreas GohrEOT;
3632613efa1SAndreas Gohr    // add any config options set by a previous installer
3642613efa1SAndreas Gohr    $preset = __DIR__ . '/install.conf';
3652613efa1SAndreas Gohr    if (file_exists($preset)) {
3662613efa1SAndreas Gohr        $output .= "# preset config options\n";
3672613efa1SAndreas Gohr        $output .= file_get_contents($preset);
3682613efa1SAndreas Gohr        $output .= "\n\n";
3692613efa1SAndreas Gohr        $output .= "# options selected in installer\n";
3702613efa1SAndreas Gohr        @unlink($preset);
3712613efa1SAndreas Gohr    }
3722613efa1SAndreas Gohr
37347248316SAndreas Gohr    $output .= '$conf[\'title\'] = \'' . addslashes($d['title']) . "';\n";
3740036aa89SAndreas Gohr    $output .= '$conf[\'lang\'] = \'' . addslashes($LC) . "';\n";
37506361442SAndreas Gohr    $output .= '$conf[\'license\'] = \'' . addslashes($d['license']) . "';\n";
37647248316SAndreas Gohr    if ($d['acl']) {
37747248316SAndreas Gohr        $output .= '$conf[\'useacl\'] = 1' . ";\n";
378523d7ea6Schris        $output .= "\$conf['superuser'] = '@admin';\n";
37947248316SAndreas Gohr    }
380ab9346edSAnika Henke    if (!$d['allowreg']) {
38143c137edSAnika Henke        $output .= '$conf[\'disableactions\'] = \'register\'' . ";\n";
382d2ea6dc1SAnika Henke    }
38347248316SAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL . 'local.php', $output);
38447248316SAndreas Gohr
38547248316SAndreas Gohr    if ($d['acl']) {
3863791b589SAndreas Gohr        // hash the password
387c3cc6e05SAndreas Gohr        $phash = new \dokuwiki\PassHash();
388267bbbcaSms101        $pass = $phash->hash_bcrypt($d['password']);
3893791b589SAndreas Gohr
39047248316SAndreas Gohr        // create users.auth.php
391a672ef75SPhy        $output = <<<EOT
392a672ef75SPhy# users.auth.php
393a672ef75SPhy# <?php exit()?>
394a672ef75SPhy# Don't modify the lines above
395a672ef75SPhy#
396a672ef75SPhy# Userfile
397a672ef75SPhy#
398a672ef75SPhy# Auto-generated by install script
399a672ef75SPhy# Date: $now
400a672ef75SPhy#
401a672ef75SPhy# Format:
402a672ef75SPhy# login:passwordhash:Real Name:email:groups,comma,separated
403a672ef75SPhy
404a672ef75SPhyEOT;
405722372bdSms101        // --- user:bcryptpasswordhash:Real Name:email:groups,comma,seperated
406*36a1a880SAndreas Gohr        $output = $output . "\n" . join(':', [
407*36a1a880SAndreas Gohr                $d['superuser'],
408*36a1a880SAndreas Gohr                $pass,
409*36a1a880SAndreas Gohr                $d['fullname'],
410*36a1a880SAndreas Gohr                $d['email'],
411*36a1a880SAndreas Gohr                'admin,user',
412*36a1a880SAndreas Gohr            ]) . "\n";
41347248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL . 'users.auth.php', $output);
41447248316SAndreas Gohr
41547248316SAndreas Gohr        // create acl.auth.php
4168af2e4bbSAndreas Gohr        $output = <<<EOT
4178af2e4bbSAndreas Gohr# acl.auth.php
4188af2e4bbSAndreas Gohr# <?php exit()?>
4198af2e4bbSAndreas Gohr# Don't modify the lines above
4208af2e4bbSAndreas Gohr#
4218af2e4bbSAndreas Gohr# Access Control Lists
4228af2e4bbSAndreas Gohr#
4238af2e4bbSAndreas Gohr# Auto-generated by install script
4248af2e4bbSAndreas Gohr# Date: $now
4258af2e4bbSAndreas Gohr
4268af2e4bbSAndreas GohrEOT;
4278af2e4bbSAndreas Gohr        if ($d['policy'] == 2) {
4288af2e4bbSAndreas Gohr            $output .=  "*               @ALL          0\n";
429d2ea6dc1SAnika Henke            $output .=  "*               @user         8\n";
4309c70688aSchris        } elseif ($d['policy'] == 1) {
4318af2e4bbSAndreas Gohr            $output .=  "*               @ALL          1\n";
432d2ea6dc1SAnika Henke            $output .=  "*               @user         8\n";
4338af2e4bbSAndreas Gohr        } else {
4348af2e4bbSAndreas Gohr            $output .=  "*               @ALL          8\n";
4358af2e4bbSAndreas Gohr        }
43647248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL . 'acl.auth.php', $output);
43747248316SAndreas Gohr    }
4383a0852d9SAndreas Gohr
4393a0852d9SAndreas Gohr    // enable popularity submission
440ee4f28e3SDamien Regad    if (isset($d['pop']) && $d['pop']) {
4413a0852d9SAndreas Gohr        @touch(DOKU_INC . 'data/cache/autosubmit.txt');
4423a0852d9SAndreas Gohr    }
4433a0852d9SAndreas Gohr
444c70d6ceeSAndreas Gohr    // disable auth plugins til needed
445c70d6ceeSAndreas Gohr    $output = <<<EOT
446c70d6ceeSAndreas Gohr<?php
447c70d6ceeSAndreas Gohr/*
448c70d6ceeSAndreas Gohr * Local plugin enable/disable settings
449c70d6ceeSAndreas Gohr *
450c70d6ceeSAndreas Gohr * Auto-generated by install script
451c70d6ceeSAndreas Gohr * Date: $now
452c70d6ceeSAndreas Gohr */
453c70d6ceeSAndreas Gohr
454c70d6ceeSAndreas Gohr\$plugins['authad']    = 0;
455c70d6ceeSAndreas Gohr\$plugins['authldap']  = 0;
456c70d6ceeSAndreas Gohr\$plugins['authmysql'] = 0;
457c70d6ceeSAndreas Gohr\$plugins['authpgsql'] = 0;
458c70d6ceeSAndreas Gohr
459c70d6ceeSAndreas GohrEOT;
460c70d6ceeSAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL . 'plugins.local.php', $output);
461c70d6ceeSAndreas Gohr
46247248316SAndreas Gohr    return $ok;
46347248316SAndreas Gohr}
46447248316SAndreas Gohr
46547248316SAndreas Gohr/**
46647248316SAndreas Gohr * Write the given content to a file
46747248316SAndreas Gohr *
46847248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
469253d4b48SGerrit Uitslag *
470253d4b48SGerrit Uitslag * @param string $filename
471253d4b48SGerrit Uitslag * @param string $data
472253d4b48SGerrit Uitslag * @return bool
47347248316SAndreas Gohr */
474db581254Sjpedrycfunction fileWrite($filename, $data)
475db581254Sjpedryc{
47647248316SAndreas Gohr    global $error;
47747248316SAndreas Gohr    global $lang;
47847248316SAndreas Gohr
47947248316SAndreas Gohr    if (($fp = @fopen($filename, 'wb')) === false) {
48047248316SAndreas Gohr        $filename = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $filename);
48147248316SAndreas Gohr        $error[]  = sprintf($lang['i_writeerr'], $filename);
48247248316SAndreas Gohr        return false;
48347248316SAndreas Gohr    }
48447248316SAndreas Gohr
485db581254Sjpedryc    if (!empty($data)) {
486db581254Sjpedryc        fwrite($fp, $data);
487db581254Sjpedryc    }
48847248316SAndreas Gohr    fclose($fp);
48947248316SAndreas Gohr    return true;
49047248316SAndreas Gohr}
49147248316SAndreas Gohr
49247248316SAndreas Gohr
49347248316SAndreas Gohr/**
49447248316SAndreas Gohr * check installation dependent local config files and tests for a known
49547248316SAndreas Gohr * unmodified main config file
49647248316SAndreas Gohr *
49747248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
498253d4b48SGerrit Uitslag *
499253d4b48SGerrit Uitslag * @return bool
50047248316SAndreas Gohr */
501db581254Sjpedrycfunction check_configs()
502db581254Sjpedryc{
50347248316SAndreas Gohr    global $error;
50447248316SAndreas Gohr    global $lang;
50547248316SAndreas Gohr
50647248316SAndreas Gohr    $ok = true;
50747248316SAndreas Gohr
5085cfb8815Schris    $config_files = array(
5095cfb8815Schris        'local' => DOKU_LOCAL . 'local.php',
5105cfb8815Schris        'users' => DOKU_LOCAL . 'users.auth.php',
5115cfb8815Schris        'auth'  => DOKU_LOCAL . 'acl.auth.php'
5125cfb8815Schris    );
5135cfb8815Schris
51447248316SAndreas Gohr    // configs shouldn't exist
51547248316SAndreas Gohr    foreach ($config_files as $file) {
51679e79377SAndreas Gohr        if (file_exists($file) && filesize($file)) {
51747248316SAndreas Gohr            $file    = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $file);
51847248316SAndreas Gohr            $error[] = sprintf($lang['i_confexists'], $file);
51947248316SAndreas Gohr            $ok      = false;
52047248316SAndreas Gohr        }
52147248316SAndreas Gohr    }
52247248316SAndreas Gohr    return $ok;
52347248316SAndreas Gohr}
52447248316SAndreas Gohr
52547248316SAndreas Gohr
52647248316SAndreas Gohr/**
52747248316SAndreas Gohr * Check other installation dir/file permission requirements
52847248316SAndreas Gohr *
52947248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
530253d4b48SGerrit Uitslag *
531253d4b48SGerrit Uitslag * @return bool
53247248316SAndreas Gohr */
533db581254Sjpedrycfunction check_permissions()
534db581254Sjpedryc{
53547248316SAndreas Gohr    global $error;
53647248316SAndreas Gohr    global $lang;
53747248316SAndreas Gohr
53847248316SAndreas Gohr    $dirs = array(
53947248316SAndreas Gohr        'conf'        => DOKU_LOCAL,
54047248316SAndreas Gohr        'data'        => DOKU_INC . 'data',
54147248316SAndreas Gohr        'pages'       => DOKU_INC . 'data/pages',
54247248316SAndreas Gohr        'attic'       => DOKU_INC . 'data/attic',
54347248316SAndreas Gohr        'media'       => DOKU_INC . 'data/media',
54449b78edaSAndreas Gohr        'media_attic' => DOKU_INC . 'data/media_attic',
54549b78edaSAndreas Gohr        'media_meta'  => DOKU_INC . 'data/media_meta',
54647248316SAndreas Gohr        'meta'        => DOKU_INC . 'data/meta',
54747248316SAndreas Gohr        'cache'       => DOKU_INC . 'data/cache',
54847248316SAndreas Gohr        'locks'       => DOKU_INC . 'data/locks',
5499711045aSAndreas Gohr        'index'       => DOKU_INC . 'data/index',
550de33a58fSMichael Klier        'tmp'         => DOKU_INC . 'data/tmp'
55147248316SAndreas Gohr    );
55247248316SAndreas Gohr
55347248316SAndreas Gohr    $ok = true;
55447248316SAndreas Gohr    foreach ($dirs as $dir) {
55579e79377SAndreas Gohr        if (!file_exists("$dir/.") || !is_writable($dir)) {
55670a6aa16Schris            $dir     = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}', $dir);
55747248316SAndreas Gohr            $error[] = sprintf($lang['i_permfail'], $dir);
55847248316SAndreas Gohr            $ok      = false;
55947248316SAndreas Gohr        }
56047248316SAndreas Gohr    }
56147248316SAndreas Gohr    return $ok;
56247248316SAndreas Gohr}
56347248316SAndreas Gohr
56447248316SAndreas Gohr/**
5653afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version
56647248316SAndreas Gohr *
56747248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
568253d4b48SGerrit Uitslag *
569253d4b48SGerrit Uitslag * @return bool
57047248316SAndreas Gohr */
571db581254Sjpedrycfunction check_functions()
572db581254Sjpedryc{
57347248316SAndreas Gohr    global $error;
57447248316SAndreas Gohr    global $lang;
5753afe5d1cSAndreas Gohr    $ok = true;
5763afe5d1cSAndreas Gohr
5773476bb81SAndreas Gohr    if (version_compare(phpversion(), '5.6.0', '<')) {
5783476bb81SAndreas Gohr        $error[] = sprintf($lang['i_phpver'], phpversion(), '5.6.0');
5793afe5d1cSAndreas Gohr        $ok = false;
5803afe5d1cSAndreas Gohr    }
5813afe5d1cSAndreas Gohr
5827f413440SAndreas Gohr    if (ini_get('mbstring.func_overload') != 0) {
5837f413440SAndreas Gohr        $error[] = $lang['i_mbfuncoverload'];
5847f413440SAndreas Gohr        $ok = false;
5857f413440SAndreas Gohr    }
5867f413440SAndreas Gohr
587387250efSPhy    try {
588387250efSPhy        random_bytes(1);
589387250efSPhy    } catch (\Exception $th) {
590387250efSPhy        // If an appropriate source of randomness cannot be found, an Exception will be thrown by PHP 7+
591387250efSPhy        $error[] = $lang['i_urandom'];
592387250efSPhy        $ok = false;
593387250efSPhy    }
594387250efSPhy
595387250efSPhy    if (ini_get('mbstring.func_overload') != 0) {
596387250efSPhy        $error[] = $lang['i_mbfuncoverload'];
597387250efSPhy        $ok = false;
598387250efSPhy    }
599387250efSPhy
6003009a773SAndreas Gohr    $funcs = explode(' ', 'addslashes call_user_func chmod copy fgets ' .
60147248316SAndreas Gohr                         'file file_exists fseek flush filesize ftell fopen ' .
6023f6872b1SMyron Turner                         'glob header ignore_user_abort ini_get mkdir ' .
60347248316SAndreas Gohr                         'ob_start opendir parse_ini_file readfile realpath ' .
604bab4a8bdSAndreas Gohr                         'rename rmdir serialize session_start unlink usleep ' .
605d1d99bb9SAndreas Gohr                         'preg_replace file_get_contents htmlspecialchars_decode ' .
606670dc13dSAndreas Gohr                         'spl_autoload_register stream_select fsockopen pack xml_parser_create');
60747248316SAndreas Gohr
60870a6aa16Schris    if (!function_exists('mb_substr')) {
60970a6aa16Schris        $funcs[] = 'utf8_encode';
61070a6aa16Schris        $funcs[] = 'utf8_decode';
61170a6aa16Schris    }
61270a6aa16Schris
6133f6872b1SMyron Turner    if (!function_exists('mail')) {
6143f6872b1SMyron Turner        if (strpos(ini_get('disable_functions'), 'mail') !== false) {
6153f6872b1SMyron Turner            $disabled = $lang['i_disabled'];
616db581254Sjpedryc        } else {
6173f6872b1SMyron Turner            $disabled = "";
6183f6872b1SMyron Turner        }
6193f6872b1SMyron Turner        $error[] = sprintf($lang['i_funcnmail'], $disabled);
6203f6872b1SMyron Turner    }
6213f6872b1SMyron Turner
62247248316SAndreas Gohr    foreach ($funcs as $func) {
62347248316SAndreas Gohr        if (!function_exists($func)) {
62447248316SAndreas Gohr            $error[] = sprintf($lang['i_funcna'], $func);
62547248316SAndreas Gohr            $ok = false;
62647248316SAndreas Gohr        }
62747248316SAndreas Gohr    }
62847248316SAndreas Gohr    return $ok;
62947248316SAndreas Gohr}
63047248316SAndreas Gohr
63147248316SAndreas Gohr/**
63247248316SAndreas Gohr * Print language selection
63347248316SAndreas Gohr *
63447248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
63547248316SAndreas Gohr */
636db581254Sjpedrycfunction langsel()
637db581254Sjpedryc{
63847248316SAndreas Gohr    global $lang;
63947248316SAndreas Gohr    global $LC;
64047248316SAndreas Gohr
64147248316SAndreas Gohr    $dir = DOKU_INC . 'inc/lang';
64247248316SAndreas Gohr    $dh  = opendir($dir);
64347248316SAndreas Gohr    if (!$dh) return;
64447248316SAndreas Gohr
64547248316SAndreas Gohr    $langs = array();
64647248316SAndreas Gohr    while (($file = readdir($dh)) !== false) {
64747248316SAndreas Gohr        if (preg_match('/^[\._]/', $file)) continue;
64879e79377SAndreas Gohr        if (is_dir($dir . '/' . $file) && file_exists($dir . '/' . $file . '/lang.php')) {
64947248316SAndreas Gohr            $langs[] = $file;
65047248316SAndreas Gohr        }
65147248316SAndreas Gohr    }
65247248316SAndreas Gohr    closedir($dh);
65347248316SAndreas Gohr    sort($langs);
65447248316SAndreas Gohr
65547248316SAndreas Gohr    echo '<form action="">';
65647248316SAndreas Gohr    echo $lang['i_chooselang'];
65747248316SAndreas Gohr    echo ': <select name="l" onchange="submit()">';
65847248316SAndreas Gohr    foreach ($langs as $l) {
65947248316SAndreas Gohr        $sel = ($l == $LC) ? 'selected="selected"' : '';
66047248316SAndreas Gohr        echo '<option value="' . $l . '" ' . $sel . '>' . $l . '</option>';
66147248316SAndreas Gohr    }
66247248316SAndreas Gohr    echo '</select> ';
663ae614416SAnika Henke    echo '<button type="submit">' . $lang['btn_update'] . '</button>';
66447248316SAndreas Gohr    echo '</form>';
66547248316SAndreas Gohr}
66647248316SAndreas Gohr
66747248316SAndreas Gohr/**
668c66972f2SAdrian Lang * Print global error array
66947248316SAndreas Gohr *
67047248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
67147248316SAndreas Gohr */
672db581254Sjpedrycfunction print_errors()
673db581254Sjpedryc{
67447248316SAndreas Gohr    global $error;
6754b530faaSTom N Harris    if (!empty($error)) {
67647248316SAndreas Gohr        echo '<ul>';
67747248316SAndreas Gohr        foreach ($error as $err) {
67847248316SAndreas Gohr            echo "<li>$err</li>";
67947248316SAndreas Gohr        }
68047248316SAndreas Gohr        echo '</ul>';
68147248316SAndreas Gohr    }
6824b530faaSTom N Harris}
683