xref: /dokuwiki/install.php (revision 267bbbca31c7b508d47a961a99012cb9c725e1f4)
15cfb8815Schris<?php
2ac251797SAndreas Gohr/*><div style="width:60%; margin: auto; background-color: #fcc;
3ac251797SAndreas Gohr                border: 1px solid #faa; padding: 0.5em 1em;">
4ac251797SAndreas Gohr    <h1 style="font-size: 120%">No PHP Support</h1>
5ac251797SAndreas Gohr
6ac251797SAndreas Gohr    It seems this server has no PHP support enabled. You will need to
7ac251797SAndreas Gohr    enable PHP before you can install and run DokuWiki. Contact your hosting
8ac251797SAndreas Gohr    provider if you're unsure what this means.
9ac251797SAndreas Gohr
10ac251797SAndreas Gohr</div>*/
115cfb8815Schris/**
125cfb8815Schris * Dokuwiki installation assistance
135cfb8815Schris *
145cfb8815Schris * @author      Chris Smith <chris@jalakai.co.uk>
155cfb8815Schris */
165cfb8815Schris
17d0a27cb0SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
185cfb8815Schrisif(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
195cfb8815Schrisif(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC.'conf/');
205cfb8815Schris
2102bca5d4SYousong Zhou// load and initialize the core system
2202bca5d4SYousong Zhourequire_once(DOKU_INC.'inc/init.php');
233791b589SAndreas Gohr
243545b2e0Schris// check for error reporting override or set error reporting to sane values
253545b2e0Schrisif (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE); }
263545b2e0Schriselse { error_reporting(DOKU_E_LEVEL); }
273545b2e0Schris
2847248316SAndreas Gohr// language strings
2947248316SAndreas Gohrrequire_once(DOKU_INC.'inc/lang/en/lang.php');
304b530faaSTom N Harrisif(isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) {
3147248316SAndreas Gohr    $LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']);
324b530faaSTom N Harris}
334b530faaSTom N Harrisif(empty($LC)) $LC = 'en';
3447248316SAndreas Gohrif($LC && $LC != 'en' ) {
3547248316SAndreas Gohr    require_once(DOKU_INC.'inc/lang/'.$LC.'/lang.php');
3647248316SAndreas Gohr}
3747248316SAndreas Gohr
3847248316SAndreas Gohr// initialise variables ...
3947248316SAndreas Gohr$error = array();
4047248316SAndreas Gohr
4147248316SAndreas Gohr// begin output
4247248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8');
4347248316SAndreas Gohr?>
44c8839c22SAnika Henke<!DOCTYPE html>
45c8839c22SAnika Henke<html lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>">
4647248316SAndreas Gohr<head>
47c8839c22SAnika Henke    <meta charset="utf-8" />
484208c142SAndreas Gohr    <title><?php echo $lang['i_installer']?></title>
4959305168SPhy    <style>
5047248316SAndreas Gohr        body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; }
5147248316SAndreas Gohr        img { border: none }
5247248316SAndreas Gohr        br.cl { clear:both; }
5370a6aa16Schris        code { font-size: 110%; color: #800000; }
5447248316SAndreas Gohr        fieldset { border: none }
559c70688aSchris        label { display: block; margin-top: 0.5em; }
568af2e4bbSAndreas Gohr        select.text, input.text { width: 30em; margin: 0 0.5em; }
5706361442SAndreas Gohr        a {text-decoration: none}
5847248316SAndreas Gohr    </style>
5959305168SPhy    <script>
6047248316SAndreas Gohr        function acltoggle(){
6147248316SAndreas Gohr            var cb = document.getElementById('acl');
6247248316SAndreas Gohr            var fs = document.getElementById('acldep');
6347248316SAndreas Gohr            if(!cb || !fs) return;
6447248316SAndreas Gohr            if(cb.checked){
6547248316SAndreas Gohr                fs.style.display = '';
6647248316SAndreas Gohr            }else{
6747248316SAndreas Gohr                fs.style.display = 'none';
6847248316SAndreas Gohr            }
6947248316SAndreas Gohr        }
7047248316SAndreas Gohr        window.onload = function(){
7147248316SAndreas Gohr            acltoggle();
7247248316SAndreas Gohr            var cb = document.getElementById('acl');
7347248316SAndreas Gohr            if(cb) cb.onchange = acltoggle;
7447248316SAndreas Gohr        };
7547248316SAndreas Gohr    </script>
7647248316SAndreas Gohr</head>
7747248316SAndreas Gohr<body style="">
7847248316SAndreas Gohr    <h1 style="float:left">
79c5270434SAndreas Gohr        <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png"
80c5270434SAndreas Gohr             style="vertical-align: middle;" alt="" height="64" width="64" />
8147248316SAndreas Gohr        <?php echo $lang['i_installer']?>
8247248316SAndreas Gohr    </h1>
8347248316SAndreas Gohr    <div style="float:right; margin: 1em;">
8447248316SAndreas Gohr        <?php langsel()?>
8547248316SAndreas Gohr    </div>
8647248316SAndreas Gohr    <br class="cl" />
8747248316SAndreas Gohr
8847248316SAndreas Gohr    <div style="float: right; width: 34%;">
8947248316SAndreas Gohr        <?php
9079e79377SAndreas Gohr            if(file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){
9147248316SAndreas Gohr                include(DOKU_INC.'inc/lang/'.$LC.'/install.html');
9247248316SAndreas Gohr            }else{
93ca64d724Schris                print "<div lang=\"en\" dir=\"ltr\">\n";
9447248316SAndreas Gohr                include(DOKU_INC.'inc/lang/en/install.html');
95ca64d724Schris                print "</div>\n";
9647248316SAndreas Gohr            }
9747248316SAndreas Gohr        ?>
9864159a61SAndreas Gohr        <a style="
9964159a61SAndreas Gohr                background: transparent
10064159a61SAndreas Gohr                url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png)
10164159a61SAndreas Gohr                left top no-repeat;
102c8b43921SAndreas Gohr                display: block; width:380px; height:73px; border:none; clear:both;"
103c8b43921SAndreas Gohr           target="_blank"
104c8b43921SAndreas Gohr           href="http://www.dokuwiki.org/security#web_access_security"></a>
10547248316SAndreas Gohr    </div>
10647248316SAndreas Gohr
10747248316SAndreas Gohr    <div style="float: left; width: 58%;">
10847248316SAndreas Gohr        <?php
1097ac1baa0SL. Ivanovich Harrison            try {
11047248316SAndreas Gohr                if(! (check_functions() && check_permissions()) ){
11147248316SAndreas Gohr                    echo '<p>'.$lang['i_problems'].'</p>';
11247248316SAndreas Gohr                    print_errors();
11370a6aa16Schris                    print_retry();
11447248316SAndreas Gohr                }elseif(!check_configs()){
11547248316SAndreas Gohr                    echo '<p>'.$lang['i_modified'].'</p>';
11647248316SAndreas Gohr                    print_errors();
1174b530faaSTom N Harris                }elseif(check_data($_REQUEST['d'])){
1184b530faaSTom N Harris                    // check_data has sanitized all input parameters
1194b530faaSTom N Harris                    if(!store_data($_REQUEST['d'])){
12047248316SAndreas Gohr                        echo '<p>'.$lang['i_failure'].'</p>';
12147248316SAndreas Gohr                        print_errors();
12247248316SAndreas Gohr                    }else{
12347248316SAndreas Gohr                        echo '<p>'.$lang['i_success'].'</p>';
12447248316SAndreas Gohr                    }
12547248316SAndreas Gohr                }else{
1264b530faaSTom N Harris                    print_errors();
12747248316SAndreas Gohr                    print_form($_REQUEST['d']);
12847248316SAndreas Gohr                }
1297ac1baa0SL. Ivanovich Harrison            } catch (Exception $e) {
1307ac1baa0SL. Ivanovich Harrison                echo 'Caught exception: ',  $e->getMessage(), "\n";
1317ac1baa0SL. Ivanovich Harrison            }
13247248316SAndreas Gohr        ?>
13347248316SAndreas Gohr    </div>
13447248316SAndreas Gohr
135c8b43921SAndreas Gohr
13647248316SAndreas Gohr<div style="clear: both">
137654436fbSAnika Henke  <a href="http://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki" /></a>
13859752844SAnders Sandblad  <a href="http://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP" /></a>
13947248316SAndreas Gohr</div>
14047248316SAndreas Gohr</body>
14147248316SAndreas Gohr</html>
14247248316SAndreas Gohr<?php
14347248316SAndreas Gohr
14447248316SAndreas Gohr/**
14547248316SAndreas Gohr * Print the input form
146253d4b48SGerrit Uitslag *
147253d4b48SGerrit Uitslag * @param array $d submitted entry 'd' of request data
14847248316SAndreas Gohr */
14947248316SAndreas Gohrfunction print_form($d){
15047248316SAndreas Gohr    global $lang;
15147248316SAndreas Gohr    global $LC;
15247248316SAndreas Gohr
15306361442SAndreas Gohr    include(DOKU_CONF.'license.php');
15406361442SAndreas Gohr
15547248316SAndreas Gohr    if(!is_array($d)) $d = array();
15665cc1598SPhy    $d = array_map('hsc',$d);
15747248316SAndreas Gohr
15847248316SAndreas Gohr    if(!isset($d['acl'])) $d['acl']=1;
1593a0852d9SAndreas Gohr    if(!isset($d['pop'])) $d['pop']=1;
16047248316SAndreas Gohr
16147248316SAndreas Gohr    ?>
16247248316SAndreas Gohr    <form action="" method="post">
16347248316SAndreas Gohr    <input type="hidden" name="l" value="<?php echo $LC ?>" />
16447248316SAndreas Gohr    <fieldset>
16547248316SAndreas Gohr        <label for="title"><?php echo $lang['i_wikiname']?>
16647248316SAndreas Gohr        <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" />
16747248316SAndreas Gohr        </label>
16847248316SAndreas Gohr
16947248316SAndreas Gohr        <fieldset style="margin-top: 1em;">
17047248316SAndreas Gohr            <label for="acl">
17147248316SAndreas Gohr            <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : ''));?> />
17247248316SAndreas Gohr            <?php echo $lang['i_enableacl']?></label>
17347248316SAndreas Gohr
17447248316SAndreas Gohr            <fieldset id="acldep">
17547248316SAndreas Gohr                <label for="superuser"><?php echo $lang['i_superuser']?></label>
17664159a61SAndreas Gohr                <input class="text" type="text" name="d[superuser]" id="superuser"
17764159a61SAndreas Gohr                       value="<?php echo $d['superuser'] ?>" />
17847248316SAndreas Gohr
17947248316SAndreas Gohr                <label for="fullname"><?php echo $lang['fullname']?></label>
18064159a61SAndreas Gohr                <input class="text" type="text" name="d[fullname]" id="fullname"
18164159a61SAndreas Gohr                       value="<?php echo $d['fullname'] ?>" />
18247248316SAndreas Gohr
18347248316SAndreas Gohr                <label for="email"><?php echo $lang['email']?></label>
18447248316SAndreas Gohr                <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" />
18547248316SAndreas Gohr
18647248316SAndreas Gohr                <label for="password"><?php echo $lang['pass']?></label>
18747248316SAndreas Gohr                <input class="text" type="password" name="d[password]" id="password" />
18847248316SAndreas Gohr
18947248316SAndreas Gohr                <label for="confirm"><?php echo $lang['passchk']?></label>
19047248316SAndreas Gohr                <input class="text" type="password" name="d[confirm]" id="confirm" />
1918af2e4bbSAndreas Gohr
1928af2e4bbSAndreas Gohr                <label for="policy"><?php echo $lang['i_policy']?></label>
1938af2e4bbSAndreas Gohr                <select class="text" name="d[policy]" id="policy">
19464159a61SAndreas Gohr                    <option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php
19564159a61SAndreas Gohr                        echo $lang['i_pol0']?></option>
19664159a61SAndreas Gohr                    <option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php
19764159a61SAndreas Gohr                        echo $lang['i_pol1']?></option>
19864159a61SAndreas Gohr                    <option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php
19964159a61SAndreas Gohr                        echo $lang['i_pol2']?></option>
2008af2e4bbSAndreas Gohr                </select>
20106361442SAndreas Gohr
202ab9346edSAnika Henke                <label for="allowreg">
20364159a61SAndreas Gohr                    <input type="checkbox" name="d[allowreg]" id="allowreg" <?php
20464159a61SAndreas Gohr                        echo(($d['allowreg'] ? ' checked="checked"' : ''));?> />
205ab9346edSAnika Henke                    <?php echo $lang['i_allowreg']?>
20674850f29SAnika Henke                </label>
20747248316SAndreas Gohr            </fieldset>
20847248316SAndreas Gohr        </fieldset>
20947248316SAndreas Gohr
21006361442SAndreas Gohr        <fieldset>
21106361442SAndreas Gohr            <p><?php echo $lang['i_license']?></p>
21206361442SAndreas Gohr            <?php
213b1730bd2STom N Harris            array_push($license,array('name' => $lang['i_license_none'], 'url'=>''));
214ed856534STom N Harris            if(empty($d['license'])) $d['license'] = 'cc-by-sa';
21506361442SAndreas Gohr            foreach($license as $key => $lic){
21606361442SAndreas Gohr                echo '<label for="lic_'.$key.'">';
21765cc1598SPhy                echo '<input type="radio" name="d[license]" value="'.hsc($key).'" id="lic_'.$key.'"'.
218b1730bd2STom N Harris                     (($d['license'] === $key)?' checked="checked"':'').'>';
21965cc1598SPhy                echo hsc($lic['name']);
22006361442SAndreas Gohr                if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>';
22106361442SAndreas Gohr                echo '</label>';
22206361442SAndreas Gohr            }
22306361442SAndreas Gohr            ?>
22406361442SAndreas Gohr        </fieldset>
22506361442SAndreas Gohr
2263a0852d9SAndreas Gohr        <fieldset>
2273a0852d9SAndreas Gohr            <p><?php echo $lang['i_pop_field']?></p>
2283a0852d9SAndreas Gohr            <label for="pop">
22964159a61SAndreas Gohr                <input type="checkbox" name="d[pop]" id="pop" <?php
23064159a61SAndreas Gohr                    echo(($d['pop'] ? ' checked="checked"' : ''));?> />
23164159a61SAndreas Gohr                <?php echo $lang['i_pop_label']?>
23264159a61SAndreas Gohr                <a href="http://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a>
2333a0852d9SAndreas Gohr            </label>
2343a0852d9SAndreas Gohr        </fieldset>
2353a0852d9SAndreas Gohr
23647248316SAndreas Gohr    </fieldset>
23747248316SAndreas Gohr    <fieldset id="process">
238ae614416SAnika Henke        <button type="submit" name="submit"><?php echo $lang['btn_save']?></button>
23947248316SAndreas Gohr    </fieldset>
24047248316SAndreas Gohr    </form>
24147248316SAndreas Gohr    <?php
24247248316SAndreas Gohr}
24347248316SAndreas Gohr
24470a6aa16Schrisfunction print_retry() {
24570a6aa16Schris    global $lang;
2469ad6da3dSAndreas Gohr    global $LC;
24770a6aa16Schris    ?>
24870a6aa16Schris    <form action="" method="get">
24970a6aa16Schris      <fieldset>
2509ad6da3dSAndreas Gohr        <input type="hidden" name="l" value="<?php echo $LC ?>" />
251ae614416SAnika Henke        <button type="submit"><?php echo $lang['i_retry'];?></button>
25270a6aa16Schris      </fieldset>
25370a6aa16Schris    </form>
25470a6aa16Schris    <?php
25570a6aa16Schris}
25670a6aa16Schris
25747248316SAndreas Gohr/**
25847248316SAndreas Gohr * Check validity of data
25947248316SAndreas Gohr *
26047248316SAndreas Gohr * @author Andreas Gohr
261253d4b48SGerrit Uitslag *
262253d4b48SGerrit Uitslag * @param array $d
263253d4b48SGerrit Uitslag * @return bool ok?
26447248316SAndreas Gohr */
265e2386079SAndreas Gohrfunction check_data(&$d){
2664b530faaSTom N Harris    static $form_default = array(
2674b530faaSTom N Harris        'title'     => '',
268ed856534STom N Harris        'acl'       => '1',
2694b530faaSTom N Harris        'superuser' => '',
2704b530faaSTom N Harris        'fullname'  => '',
2714b530faaSTom N Harris        'email'     => '',
2724b530faaSTom N Harris        'password'  => '',
2734b530faaSTom N Harris        'confirm'   => '',
2744b530faaSTom N Harris        'policy'    => '0',
275ab9346edSAnika Henke        'allowreg'  => '0',
2764b530faaSTom N Harris        'license'   => 'cc-by-sa'
2774b530faaSTom N Harris    );
27847248316SAndreas Gohr    global $lang;
27947248316SAndreas Gohr    global $error;
28047248316SAndreas Gohr
2814b530faaSTom N Harris    if(!is_array($d)) $d = array();
2824b530faaSTom N Harris    foreach($d as $k => $v) {
2834b530faaSTom N Harris        if(is_array($v))
2844b530faaSTom N Harris            unset($d[$k]);
2854b530faaSTom N Harris        else
2864b530faaSTom N Harris            $d[$k] = (string)$v;
2874b530faaSTom N Harris    }
288e2386079SAndreas Gohr
2894b530faaSTom N Harris    //autolowercase the username
2904b530faaSTom N Harris    $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : "";
2914b530faaSTom N Harris
2924b530faaSTom N Harris    $ok = false;
2934b530faaSTom N Harris
2944b530faaSTom N Harris    if(isset($_REQUEST['submit'])) {
29547248316SAndreas Gohr        $ok = true;
29647248316SAndreas Gohr
29747248316SAndreas Gohr        // check input
29847248316SAndreas Gohr        if(empty($d['title'])){
29947248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
30047248316SAndreas Gohr            $ok      = false;
30147248316SAndreas Gohr        }
3024b530faaSTom N Harris        if(isset($d['acl'])){
303d60813a2SGina Haeussge            if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){
30447248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
30547248316SAndreas Gohr                $ok      = false;
30647248316SAndreas Gohr            }
30747248316SAndreas Gohr            if(empty($d['password'])){
30847248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['pass']);
30947248316SAndreas Gohr                $ok      = false;
31047248316SAndreas Gohr            }
3114b530faaSTom N Harris            elseif(!isset($d['confirm']) || $d['confirm'] != $d['password']){
31247248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['passchk']);
31347248316SAndreas Gohr                $ok      = false;
31447248316SAndreas Gohr            }
31547248316SAndreas Gohr            if(empty($d['fullname']) || strstr($d['fullname'],':')){
31647248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['fullname']);
31747248316SAndreas Gohr                $ok      = false;
31847248316SAndreas Gohr            }
319e2386079SAndreas Gohr            if(empty($d['email']) || strstr($d['email'],':') || !strstr($d['email'],'@')){
32047248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['email']);
32147248316SAndreas Gohr                $ok      = false;
32247248316SAndreas Gohr            }
323b9ab8e4fSPhy        }else{
324b9ab8e4fSPhy            // Since default = 1, browser won't send acl=0 when user untick acl
325b9ab8e4fSPhy            $d['acl'] = '0';
32647248316SAndreas Gohr        }
3274b530faaSTom N Harris    }
3284b530faaSTom N Harris    $d = array_merge($form_default, $d);
32947248316SAndreas Gohr    return $ok;
33047248316SAndreas Gohr}
33147248316SAndreas Gohr
33247248316SAndreas Gohr/**
33347248316SAndreas Gohr * Writes the data to the config files
33447248316SAndreas Gohr *
33547248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
336253d4b48SGerrit Uitslag *
337253d4b48SGerrit Uitslag * @param array $d
338253d4b48SGerrit Uitslag * @return bool
33947248316SAndreas Gohr */
34047248316SAndreas Gohrfunction store_data($d){
3410036aa89SAndreas Gohr    global $LC;
34247248316SAndreas Gohr    $ok = true;
3438af2e4bbSAndreas Gohr    $d['policy'] = (int) $d['policy'];
34447248316SAndreas Gohr
34547248316SAndreas Gohr    // create local.php
34624650a19SAndreas Gohr    $now    = gmdate('r');
34747248316SAndreas Gohr    $output = <<<EOT
34847248316SAndreas Gohr<?php
34947248316SAndreas Gohr/**
35047248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings
35147248316SAndreas Gohr * Auto-generated by install script
35247248316SAndreas Gohr * Date: $now
35347248316SAndreas Gohr */
35447248316SAndreas Gohr
35547248316SAndreas GohrEOT;
3562613efa1SAndreas Gohr    // add any config options set by a previous installer
3572613efa1SAndreas Gohr    $preset = __DIR__.'/install.conf';
3582613efa1SAndreas Gohr    if(file_exists($preset)){
3592613efa1SAndreas Gohr        $output .= "# preset config options\n";
3602613efa1SAndreas Gohr        $output .= file_get_contents($preset);
3612613efa1SAndreas Gohr        $output .= "\n\n";
3622613efa1SAndreas Gohr        $output .= "# options selected in installer\n";
3632613efa1SAndreas Gohr        @unlink($preset);
3642613efa1SAndreas Gohr    }
3652613efa1SAndreas Gohr
36647248316SAndreas Gohr    $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
3670036aa89SAndreas Gohr    $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
36806361442SAndreas Gohr    $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n";
36947248316SAndreas Gohr    if($d['acl']){
37047248316SAndreas Gohr        $output .= '$conf[\'useacl\'] = 1'.";\n";
371523d7ea6Schris        $output .= "\$conf['superuser'] = '@admin';\n";
37247248316SAndreas Gohr    }
373ab9346edSAnika Henke    if(!$d['allowreg']){
37443c137edSAnika Henke        $output .= '$conf[\'disableactions\'] = \'register\''.";\n";
375d2ea6dc1SAnika Henke    }
37647248316SAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output);
37747248316SAndreas Gohr
37847248316SAndreas Gohr    if ($d['acl']) {
3793791b589SAndreas Gohr        // hash the password
380c3cc6e05SAndreas Gohr        $phash = new \dokuwiki\PassHash();
381*267bbbcaSms101        $pass = $phash->hash_bcrypt($d['password']);
3823791b589SAndreas Gohr
38347248316SAndreas Gohr        // create users.auth.php
384a672ef75SPhy        $output = <<<EOT
385a672ef75SPhy# users.auth.php
386a672ef75SPhy# <?php exit()?>
387a672ef75SPhy# Don't modify the lines above
388a672ef75SPhy#
389a672ef75SPhy# Userfile
390a672ef75SPhy#
391a672ef75SPhy# Auto-generated by install script
392a672ef75SPhy# Date: $now
393a672ef75SPhy#
394a672ef75SPhy# Format:
395a672ef75SPhy# login:passwordhash:Real Name:email:groups,comma,separated
396a672ef75SPhy
397a672ef75SPhyEOT;
3983791b589SAndreas Gohr        // --- user:SMD5password:Real Name:email:groups,comma,seperated
399a672ef75SPhy        $output = $output."\n".join(":",array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user'))."\n";
40047248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output);
40147248316SAndreas Gohr
40247248316SAndreas Gohr        // create acl.auth.php
4038af2e4bbSAndreas Gohr        $output = <<<EOT
4048af2e4bbSAndreas Gohr# acl.auth.php
4058af2e4bbSAndreas Gohr# <?php exit()?>
4068af2e4bbSAndreas Gohr# Don't modify the lines above
4078af2e4bbSAndreas Gohr#
4088af2e4bbSAndreas Gohr# Access Control Lists
4098af2e4bbSAndreas Gohr#
4108af2e4bbSAndreas Gohr# Auto-generated by install script
4118af2e4bbSAndreas Gohr# Date: $now
4128af2e4bbSAndreas Gohr
4138af2e4bbSAndreas GohrEOT;
4148af2e4bbSAndreas Gohr        if($d['policy'] == 2){
4158af2e4bbSAndreas Gohr            $output .=  "*               @ALL          0\n";
416d2ea6dc1SAnika Henke            $output .=  "*               @user         8\n";
4179c70688aSchris        }elseif($d['policy'] == 1){
4188af2e4bbSAndreas Gohr            $output .=  "*               @ALL          1\n";
419d2ea6dc1SAnika Henke            $output .=  "*               @user         8\n";
4208af2e4bbSAndreas Gohr        }else{
4218af2e4bbSAndreas Gohr            $output .=  "*               @ALL          8\n";
4228af2e4bbSAndreas Gohr        }
42347248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output);
42447248316SAndreas Gohr    }
4253a0852d9SAndreas Gohr
4263a0852d9SAndreas Gohr    // enable popularity submission
4273a0852d9SAndreas Gohr    if($d['pop']){
4283a0852d9SAndreas Gohr        @touch(DOKU_INC.'data/cache/autosubmit.txt');
4293a0852d9SAndreas Gohr    }
4303a0852d9SAndreas Gohr
431c70d6ceeSAndreas Gohr    // disable auth plugins til needed
432c70d6ceeSAndreas Gohr    $output = <<<EOT
433c70d6ceeSAndreas Gohr<?php
434c70d6ceeSAndreas Gohr/*
435c70d6ceeSAndreas Gohr * Local plugin enable/disable settings
436c70d6ceeSAndreas Gohr *
437c70d6ceeSAndreas Gohr * Auto-generated by install script
438c70d6ceeSAndreas Gohr * Date: $now
439c70d6ceeSAndreas Gohr */
440c70d6ceeSAndreas Gohr
441c70d6ceeSAndreas Gohr\$plugins['authad']    = 0;
442c70d6ceeSAndreas Gohr\$plugins['authldap']  = 0;
443c70d6ceeSAndreas Gohr\$plugins['authmysql'] = 0;
444c70d6ceeSAndreas Gohr\$plugins['authpgsql'] = 0;
445c70d6ceeSAndreas Gohr
446c70d6ceeSAndreas GohrEOT;
447c70d6ceeSAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL.'plugins.local.php', $output);
448c70d6ceeSAndreas Gohr
44947248316SAndreas Gohr    return $ok;
45047248316SAndreas Gohr}
45147248316SAndreas Gohr
45247248316SAndreas Gohr/**
45347248316SAndreas Gohr * Write the given content to a file
45447248316SAndreas Gohr *
45547248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
456253d4b48SGerrit Uitslag *
457253d4b48SGerrit Uitslag * @param string $filename
458253d4b48SGerrit Uitslag * @param string $data
459253d4b48SGerrit Uitslag * @return bool
46047248316SAndreas Gohr */
46147248316SAndreas Gohrfunction fileWrite($filename, $data) {
46247248316SAndreas Gohr    global $error;
46347248316SAndreas Gohr    global $lang;
46447248316SAndreas Gohr
46547248316SAndreas Gohr    if (($fp = @fopen($filename, 'wb')) === false) {
46647248316SAndreas Gohr        $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
46747248316SAndreas Gohr        $error[]  = sprintf($lang['i_writeerr'],$filename);
46847248316SAndreas Gohr        return false;
46947248316SAndreas Gohr    }
47047248316SAndreas Gohr
47147248316SAndreas Gohr    if (!empty($data)) { fwrite($fp, $data);  }
47247248316SAndreas Gohr    fclose($fp);
47347248316SAndreas Gohr    return true;
47447248316SAndreas Gohr}
47547248316SAndreas Gohr
47647248316SAndreas Gohr
47747248316SAndreas Gohr/**
47847248316SAndreas Gohr * check installation dependent local config files and tests for a known
47947248316SAndreas Gohr * unmodified main config file
48047248316SAndreas Gohr *
48147248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
482253d4b48SGerrit Uitslag *
483253d4b48SGerrit Uitslag * @return bool
48447248316SAndreas Gohr */
48547248316SAndreas Gohrfunction check_configs(){
48647248316SAndreas Gohr    global $error;
48747248316SAndreas Gohr    global $lang;
48847248316SAndreas Gohr
48947248316SAndreas Gohr    $ok = true;
49047248316SAndreas Gohr
4915cfb8815Schris    $config_files = array(
4925cfb8815Schris        'local' => DOKU_LOCAL.'local.php',
4935cfb8815Schris        'users' => DOKU_LOCAL.'users.auth.php',
4945cfb8815Schris        'auth'  => DOKU_LOCAL.'acl.auth.php'
4955cfb8815Schris    );
4965cfb8815Schris
49747248316SAndreas Gohr    // configs shouldn't exist
49847248316SAndreas Gohr    foreach ($config_files as $file) {
49979e79377SAndreas Gohr        if (file_exists($file) && filesize($file)) {
50047248316SAndreas Gohr            $file    = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
50147248316SAndreas Gohr            $error[] = sprintf($lang['i_confexists'],$file);
50247248316SAndreas Gohr            $ok      = false;
50347248316SAndreas Gohr        }
50447248316SAndreas Gohr    }
50547248316SAndreas Gohr    return $ok;
50647248316SAndreas Gohr}
50747248316SAndreas Gohr
50847248316SAndreas Gohr
50947248316SAndreas Gohr/**
51047248316SAndreas Gohr * Check other installation dir/file permission requirements
51147248316SAndreas Gohr *
51247248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
513253d4b48SGerrit Uitslag *
514253d4b48SGerrit Uitslag * @return bool
51547248316SAndreas Gohr */
51647248316SAndreas Gohrfunction check_permissions(){
51747248316SAndreas Gohr    global $error;
51847248316SAndreas Gohr    global $lang;
51947248316SAndreas Gohr
52047248316SAndreas Gohr    $dirs = array(
52147248316SAndreas Gohr        'conf'        => DOKU_LOCAL,
52247248316SAndreas Gohr        'data'        => DOKU_INC.'data',
52347248316SAndreas Gohr        'pages'       => DOKU_INC.'data/pages',
52447248316SAndreas Gohr        'attic'       => DOKU_INC.'data/attic',
52547248316SAndreas Gohr        'media'       => DOKU_INC.'data/media',
52649b78edaSAndreas Gohr        'media_attic' => DOKU_INC.'data/media_attic',
52749b78edaSAndreas Gohr        'media_meta'  => DOKU_INC.'data/media_meta',
52847248316SAndreas Gohr        'meta'        => DOKU_INC.'data/meta',
52947248316SAndreas Gohr        'cache'       => DOKU_INC.'data/cache',
53047248316SAndreas Gohr        'locks'       => DOKU_INC.'data/locks',
5319711045aSAndreas Gohr        'index'       => DOKU_INC.'data/index',
532de33a58fSMichael Klier        'tmp'         => DOKU_INC.'data/tmp'
53347248316SAndreas Gohr    );
53447248316SAndreas Gohr
53547248316SAndreas Gohr    $ok = true;
53647248316SAndreas Gohr    foreach($dirs as $dir){
53779e79377SAndreas Gohr        if(!file_exists("$dir/.") || !is_writable($dir)){
53870a6aa16Schris            $dir     = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
53947248316SAndreas Gohr            $error[] = sprintf($lang['i_permfail'],$dir);
54047248316SAndreas Gohr            $ok      = false;
54147248316SAndreas Gohr        }
54247248316SAndreas Gohr    }
54347248316SAndreas Gohr    return $ok;
54447248316SAndreas Gohr}
54547248316SAndreas Gohr
54647248316SAndreas Gohr/**
5473afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version
54847248316SAndreas Gohr *
54947248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
550253d4b48SGerrit Uitslag *
551253d4b48SGerrit Uitslag * @return bool
55247248316SAndreas Gohr */
55347248316SAndreas Gohrfunction check_functions(){
55447248316SAndreas Gohr    global $error;
55547248316SAndreas Gohr    global $lang;
5563afe5d1cSAndreas Gohr    $ok = true;
5573afe5d1cSAndreas Gohr
5583476bb81SAndreas Gohr    if(version_compare(phpversion(),'5.6.0','<')){
5593476bb81SAndreas Gohr        $error[] = sprintf($lang['i_phpver'],phpversion(),'5.6.0');
5603afe5d1cSAndreas Gohr        $ok = false;
5613afe5d1cSAndreas Gohr    }
5623afe5d1cSAndreas Gohr
5637f413440SAndreas Gohr    if(ini_get('mbstring.func_overload') != 0){
5647f413440SAndreas Gohr        $error[] = $lang['i_mbfuncoverload'];
5657f413440SAndreas Gohr        $ok = false;
5667f413440SAndreas Gohr    }
5677f413440SAndreas Gohr
568387250efSPhy    try {
569387250efSPhy        random_bytes(1);
570387250efSPhy    } catch (\Exception $th) {
571387250efSPhy        // If an appropriate source of randomness cannot be found, an Exception will be thrown by PHP 7+
572387250efSPhy        // this exception is also thrown by paragonie/random_compat for PHP 5.6 support
573387250efSPhy        $error[] = $lang['i_urandom'];
574387250efSPhy        $ok = false;
575387250efSPhy    }
576387250efSPhy
577387250efSPhy    if(ini_get('mbstring.func_overload') != 0){
578387250efSPhy        $error[] = $lang['i_mbfuncoverload'];
579387250efSPhy        $ok = false;
580387250efSPhy    }
581387250efSPhy
5823009a773SAndreas Gohr    $funcs = explode(' ','addslashes call_user_func chmod copy fgets '.
58347248316SAndreas Gohr                         'file file_exists fseek flush filesize ftell fopen '.
5843f6872b1SMyron Turner                         'glob header ignore_user_abort ini_get mkdir '.
58547248316SAndreas Gohr                         'ob_start opendir parse_ini_file readfile realpath '.
586bab4a8bdSAndreas Gohr                         'rename rmdir serialize session_start unlink usleep '.
587d1d99bb9SAndreas Gohr                         'preg_replace file_get_contents htmlspecialchars_decode '.
588ab38a322Slupo49                         'spl_autoload_register stream_select fsockopen pack');
58947248316SAndreas Gohr
59070a6aa16Schris    if (!function_exists('mb_substr')) {
59170a6aa16Schris        $funcs[] = 'utf8_encode';
59270a6aa16Schris        $funcs[] = 'utf8_decode';
59370a6aa16Schris    }
59470a6aa16Schris
5953f6872b1SMyron Turner    if(!function_exists('mail')){
5963f6872b1SMyron Turner        if(strpos(ini_get('disable_functions'),'mail') !== false) {
5973f6872b1SMyron Turner            $disabled = $lang['i_disabled'];
5983f6872b1SMyron Turner        }
5993f6872b1SMyron Turner        else {
6003f6872b1SMyron Turner            $disabled = "";
6013f6872b1SMyron Turner        }
6023f6872b1SMyron Turner        $error[] = sprintf($lang['i_funcnmail'],$disabled);
6033f6872b1SMyron Turner    }
6043f6872b1SMyron Turner
60547248316SAndreas Gohr    foreach($funcs as $func){
60647248316SAndreas Gohr        if(!function_exists($func)){
60747248316SAndreas Gohr            $error[] = sprintf($lang['i_funcna'],$func);
60847248316SAndreas Gohr            $ok = false;
60947248316SAndreas Gohr        }
61047248316SAndreas Gohr    }
61147248316SAndreas Gohr    return $ok;
61247248316SAndreas Gohr}
61347248316SAndreas Gohr
61447248316SAndreas Gohr/**
61547248316SAndreas Gohr * Print language selection
61647248316SAndreas Gohr *
61747248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
61847248316SAndreas Gohr */
61947248316SAndreas Gohrfunction langsel(){
62047248316SAndreas Gohr    global $lang;
62147248316SAndreas Gohr    global $LC;
62247248316SAndreas Gohr
62347248316SAndreas Gohr    $dir = DOKU_INC.'inc/lang';
62447248316SAndreas Gohr    $dh  = opendir($dir);
62547248316SAndreas Gohr    if(!$dh) return;
62647248316SAndreas Gohr
62747248316SAndreas Gohr    $langs = array();
62847248316SAndreas Gohr    while (($file = readdir($dh)) !== false) {
62947248316SAndreas Gohr        if(preg_match('/^[\._]/',$file)) continue;
63079e79377SAndreas Gohr        if(is_dir($dir.'/'.$file) && file_exists($dir.'/'.$file.'/lang.php')){
63147248316SAndreas Gohr            $langs[] = $file;
63247248316SAndreas Gohr        }
63347248316SAndreas Gohr    }
63447248316SAndreas Gohr    closedir($dh);
63547248316SAndreas Gohr    sort($langs);
63647248316SAndreas Gohr
63747248316SAndreas Gohr    echo '<form action="">';
63847248316SAndreas Gohr    echo $lang['i_chooselang'];
63947248316SAndreas Gohr    echo ': <select name="l" onchange="submit()">';
64047248316SAndreas Gohr    foreach($langs as $l){
64147248316SAndreas Gohr        $sel = ($l == $LC) ? 'selected="selected"' : '';
64247248316SAndreas Gohr        echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
64347248316SAndreas Gohr    }
64447248316SAndreas Gohr    echo '</select> ';
645ae614416SAnika Henke    echo '<button type="submit">'.$lang['btn_update'].'</button>';
64647248316SAndreas Gohr    echo '</form>';
64747248316SAndreas Gohr}
64847248316SAndreas Gohr
64947248316SAndreas Gohr/**
650c66972f2SAdrian Lang * Print global error array
65147248316SAndreas Gohr *
65247248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
65347248316SAndreas Gohr */
65447248316SAndreas Gohrfunction print_errors(){
65547248316SAndreas Gohr    global $error;
6564b530faaSTom N Harris    if(!empty($error)) {
65747248316SAndreas Gohr        echo '<ul>';
65847248316SAndreas Gohr        foreach ($error as $err){
65947248316SAndreas Gohr            echo "<li>$err</li>";
66047248316SAndreas Gohr        }
66147248316SAndreas Gohr        echo '</ul>';
66247248316SAndreas Gohr    }
6634b530faaSTom N Harris}
664