xref: /dokuwiki/install.php (revision 7ac1baa0050d31cd1db1b1c90fb122d4f6da841b)
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>
4947248316SAndreas Gohr    <style type="text/css">
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>
59e260f93bSAnika Henke    <script type="text/javascript">
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        ?>
983cd83762SDeathCamel57        <a style="background: transparent url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png) left top no-repeat;
99c8b43921SAndreas Gohr                  display: block; width:380px; height:73px; border:none; clear:both;"
100c8b43921SAndreas Gohr           target="_blank"
101c8b43921SAndreas Gohr           href="http://www.dokuwiki.org/security#web_access_security"></a>
10247248316SAndreas Gohr    </div>
10347248316SAndreas Gohr
10447248316SAndreas Gohr    <div style="float: left; width: 58%;">
10547248316SAndreas Gohr        <?php
106*7ac1baa0SL. Ivanovich Harrison            try {
10747248316SAndreas Gohr                if(! (check_functions() && check_permissions()) ){
10847248316SAndreas Gohr                    echo '<p>'.$lang['i_problems'].'</p>';
10947248316SAndreas Gohr                    print_errors();
11070a6aa16Schris                    print_retry();
11147248316SAndreas Gohr                }elseif(!check_configs()){
11247248316SAndreas Gohr                    echo '<p>'.$lang['i_modified'].'</p>';
11347248316SAndreas Gohr                    print_errors();
1144b530faaSTom N Harris                }elseif(check_data($_REQUEST['d'])){
1154b530faaSTom N Harris                    // check_data has sanitized all input parameters
1164b530faaSTom N Harris                    if(!store_data($_REQUEST['d'])){
11747248316SAndreas Gohr                        echo '<p>'.$lang['i_failure'].'</p>';
11847248316SAndreas Gohr                        print_errors();
11947248316SAndreas Gohr                    }else{
12047248316SAndreas Gohr                        echo '<p>'.$lang['i_success'].'</p>';
12147248316SAndreas Gohr                    }
12247248316SAndreas Gohr                }else{
1234b530faaSTom N Harris                    print_errors();
12447248316SAndreas Gohr                    print_form($_REQUEST['d']);
12547248316SAndreas Gohr                }
126*7ac1baa0SL. Ivanovich Harrison            } catch (Exception $e) {
127*7ac1baa0SL. Ivanovich Harrison                echo 'Caught exception: ',  $e->getMessage(), "\n";
128*7ac1baa0SL. Ivanovich Harrison            }
12947248316SAndreas Gohr        ?>
13047248316SAndreas Gohr    </div>
13147248316SAndreas Gohr
132c8b43921SAndreas Gohr
13347248316SAndreas Gohr<div style="clear: both">
134654436fbSAnika Henke  <a href="http://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki" /></a>
13559752844SAnders Sandblad  <a href="http://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP" /></a>
13647248316SAndreas Gohr</div>
13747248316SAndreas Gohr</body>
13847248316SAndreas Gohr</html>
13947248316SAndreas Gohr<?php
14047248316SAndreas Gohr
14147248316SAndreas Gohr/**
14247248316SAndreas Gohr * Print the input form
143253d4b48SGerrit Uitslag *
144253d4b48SGerrit Uitslag * @param array $d submitted entry 'd' of request data
14547248316SAndreas Gohr */
14647248316SAndreas Gohrfunction print_form($d){
14747248316SAndreas Gohr    global $lang;
14847248316SAndreas Gohr    global $LC;
14947248316SAndreas Gohr
15006361442SAndreas Gohr    include(DOKU_CONF.'license.php');
15106361442SAndreas Gohr
15247248316SAndreas Gohr    if(!is_array($d)) $d = array();
15365cc1598SPhy    $d = array_map('hsc',$d);
15447248316SAndreas Gohr
15547248316SAndreas Gohr    if(!isset($d['acl'])) $d['acl']=1;
1563a0852d9SAndreas Gohr    if(!isset($d['pop'])) $d['pop']=1;
15747248316SAndreas Gohr
15847248316SAndreas Gohr    ?>
15947248316SAndreas Gohr    <form action="" method="post">
16047248316SAndreas Gohr    <input type="hidden" name="l" value="<?php echo $LC ?>" />
16147248316SAndreas Gohr    <fieldset>
16247248316SAndreas Gohr        <label for="title"><?php echo $lang['i_wikiname']?>
16347248316SAndreas Gohr        <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" />
16447248316SAndreas Gohr        </label>
16547248316SAndreas Gohr
16647248316SAndreas Gohr        <fieldset style="margin-top: 1em;">
16747248316SAndreas Gohr            <label for="acl">
16847248316SAndreas Gohr            <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : ''));?> />
16947248316SAndreas Gohr            <?php echo $lang['i_enableacl']?></label>
17047248316SAndreas Gohr
17147248316SAndreas Gohr            <fieldset id="acldep">
17247248316SAndreas Gohr                <label for="superuser"><?php echo $lang['i_superuser']?></label>
17347248316SAndreas Gohr                <input class="text" type="text" name="d[superuser]" id="superuser" value="<?php echo $d['superuser'] ?>" />
17447248316SAndreas Gohr
17547248316SAndreas Gohr                <label for="fullname"><?php echo $lang['fullname']?></label>
17647248316SAndreas Gohr                <input class="text" type="text" name="d[fullname]" id="fullname" value="<?php echo $d['fullname'] ?>" />
17747248316SAndreas Gohr
17847248316SAndreas Gohr                <label for="email"><?php echo $lang['email']?></label>
17947248316SAndreas Gohr                <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" />
18047248316SAndreas Gohr
18147248316SAndreas Gohr                <label for="password"><?php echo $lang['pass']?></label>
18247248316SAndreas Gohr                <input class="text" type="password" name="d[password]" id="password" />
18347248316SAndreas Gohr
18447248316SAndreas Gohr                <label for="confirm"><?php echo $lang['passchk']?></label>
18547248316SAndreas Gohr                <input class="text" type="password" name="d[confirm]" id="confirm" />
1868af2e4bbSAndreas Gohr
1878af2e4bbSAndreas Gohr                <label for="policy"><?php echo $lang['i_policy']?></label>
1888af2e4bbSAndreas Gohr                <select class="text" name="d[policy]" id="policy">
1898af2e4bbSAndreas Gohr                    <option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php echo $lang['i_pol0']?></option>
1908af2e4bbSAndreas Gohr                    <option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php echo $lang['i_pol1']?></option>
1918af2e4bbSAndreas Gohr                    <option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php echo $lang['i_pol2']?></option>
1928af2e4bbSAndreas Gohr                </select>
19306361442SAndreas Gohr
194ab9346edSAnika Henke                <label for="allowreg">
195ab9346edSAnika Henke                    <input type="checkbox" name="d[allowreg]" id="allowreg" <?php echo(($d['allowreg'] ? ' checked="checked"' : ''));?> />
196ab9346edSAnika Henke                    <?php echo $lang['i_allowreg']?>
19774850f29SAnika Henke                </label>
19847248316SAndreas Gohr            </fieldset>
19947248316SAndreas Gohr        </fieldset>
20047248316SAndreas Gohr
20106361442SAndreas Gohr        <fieldset>
20206361442SAndreas Gohr            <p><?php echo $lang['i_license']?></p>
20306361442SAndreas Gohr            <?php
204b1730bd2STom N Harris            array_push($license,array('name' => $lang['i_license_none'], 'url'=>''));
205ed856534STom N Harris            if(empty($d['license'])) $d['license'] = 'cc-by-sa';
20606361442SAndreas Gohr            foreach($license as $key => $lic){
20706361442SAndreas Gohr                echo '<label for="lic_'.$key.'">';
20865cc1598SPhy                echo '<input type="radio" name="d[license]" value="'.hsc($key).'" id="lic_'.$key.'"'.
209b1730bd2STom N Harris                     (($d['license'] === $key)?' checked="checked"':'').'>';
21065cc1598SPhy                echo hsc($lic['name']);
21106361442SAndreas Gohr                if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>';
21206361442SAndreas Gohr                echo '</label>';
21306361442SAndreas Gohr            }
21406361442SAndreas Gohr            ?>
21506361442SAndreas Gohr        </fieldset>
21606361442SAndreas Gohr
2173a0852d9SAndreas Gohr        <fieldset>
2183a0852d9SAndreas Gohr            <p><?php echo $lang['i_pop_field']?></p>
2193a0852d9SAndreas Gohr            <label for="pop">
2203a0852d9SAndreas Gohr                <input type="checkbox" name="d[pop]" id="pop" <?php echo(($d['pop'] ? ' checked="checked"' : ''));?> />
221e93f702bSAndreas Gohr                <?php echo $lang['i_pop_label']?> <a href="http://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a>
2223a0852d9SAndreas Gohr            </label>
2233a0852d9SAndreas Gohr        </fieldset>
2243a0852d9SAndreas Gohr
22547248316SAndreas Gohr    </fieldset>
22647248316SAndreas Gohr    <fieldset id="process">
227ae614416SAnika Henke        <button type="submit" name="submit"><?php echo $lang['btn_save']?></button>
22847248316SAndreas Gohr    </fieldset>
22947248316SAndreas Gohr    </form>
23047248316SAndreas Gohr    <?php
23147248316SAndreas Gohr}
23247248316SAndreas Gohr
23370a6aa16Schrisfunction print_retry() {
23470a6aa16Schris    global $lang;
2359ad6da3dSAndreas Gohr    global $LC;
23670a6aa16Schris    ?>
23770a6aa16Schris    <form action="" method="get">
23870a6aa16Schris      <fieldset>
2399ad6da3dSAndreas Gohr        <input type="hidden" name="l" value="<?php echo $LC ?>" />
240ae614416SAnika Henke        <button type="submit"><?php echo $lang['i_retry'];?></button>
24170a6aa16Schris      </fieldset>
24270a6aa16Schris    </form>
24370a6aa16Schris    <?php
24470a6aa16Schris}
24570a6aa16Schris
24647248316SAndreas Gohr/**
24747248316SAndreas Gohr * Check validity of data
24847248316SAndreas Gohr *
24947248316SAndreas Gohr * @author Andreas Gohr
250253d4b48SGerrit Uitslag *
251253d4b48SGerrit Uitslag * @param array $d
252253d4b48SGerrit Uitslag * @return bool ok?
25347248316SAndreas Gohr */
254e2386079SAndreas Gohrfunction check_data(&$d){
2554b530faaSTom N Harris    static $form_default = array(
2564b530faaSTom N Harris        'title'     => '',
257ed856534STom N Harris        'acl'       => '1',
2584b530faaSTom N Harris        'superuser' => '',
2594b530faaSTom N Harris        'fullname'  => '',
2604b530faaSTom N Harris        'email'     => '',
2614b530faaSTom N Harris        'password'  => '',
2624b530faaSTom N Harris        'confirm'   => '',
2634b530faaSTom N Harris        'policy'    => '0',
264ab9346edSAnika Henke        'allowreg'  => '0',
2654b530faaSTom N Harris        'license'   => 'cc-by-sa'
2664b530faaSTom N Harris    );
26747248316SAndreas Gohr    global $lang;
26847248316SAndreas Gohr    global $error;
26947248316SAndreas Gohr
2704b530faaSTom N Harris    if(!is_array($d)) $d = array();
2714b530faaSTom N Harris    foreach($d as $k => $v) {
2724b530faaSTom N Harris        if(is_array($v))
2734b530faaSTom N Harris            unset($d[$k]);
2744b530faaSTom N Harris        else
2754b530faaSTom N Harris            $d[$k] = (string)$v;
2764b530faaSTom N Harris    }
277e2386079SAndreas Gohr
2784b530faaSTom N Harris    //autolowercase the username
2794b530faaSTom N Harris    $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : "";
2804b530faaSTom N Harris
2814b530faaSTom N Harris    $ok = false;
2824b530faaSTom N Harris
2834b530faaSTom N Harris    if(isset($_REQUEST['submit'])) {
28447248316SAndreas Gohr        $ok = true;
28547248316SAndreas Gohr
28647248316SAndreas Gohr        // check input
28747248316SAndreas Gohr        if(empty($d['title'])){
28847248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
28947248316SAndreas Gohr            $ok      = false;
29047248316SAndreas Gohr        }
2914b530faaSTom N Harris        if(isset($d['acl'])){
292d60813a2SGina Haeussge            if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){
29347248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
29447248316SAndreas Gohr                $ok      = false;
29547248316SAndreas Gohr            }
29647248316SAndreas Gohr            if(empty($d['password'])){
29747248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['pass']);
29847248316SAndreas Gohr                $ok      = false;
29947248316SAndreas Gohr            }
3004b530faaSTom N Harris            elseif(!isset($d['confirm']) || $d['confirm'] != $d['password']){
30147248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['passchk']);
30247248316SAndreas Gohr                $ok      = false;
30347248316SAndreas Gohr            }
30447248316SAndreas Gohr            if(empty($d['fullname']) || strstr($d['fullname'],':')){
30547248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['fullname']);
30647248316SAndreas Gohr                $ok      = false;
30747248316SAndreas Gohr            }
308e2386079SAndreas Gohr            if(empty($d['email']) || strstr($d['email'],':') || !strstr($d['email'],'@')){
30947248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['email']);
31047248316SAndreas Gohr                $ok      = false;
31147248316SAndreas Gohr            }
31247248316SAndreas Gohr        }
3134b530faaSTom N Harris    }
3144b530faaSTom N Harris    $d = array_merge($form_default, $d);
31547248316SAndreas Gohr    return $ok;
31647248316SAndreas Gohr}
31747248316SAndreas Gohr
31847248316SAndreas Gohr/**
31947248316SAndreas Gohr * Writes the data to the config files
32047248316SAndreas Gohr *
32147248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
322253d4b48SGerrit Uitslag *
323253d4b48SGerrit Uitslag * @param array $d
324253d4b48SGerrit Uitslag * @return bool
32547248316SAndreas Gohr */
32647248316SAndreas Gohrfunction store_data($d){
3270036aa89SAndreas Gohr    global $LC;
32847248316SAndreas Gohr    $ok = true;
3298af2e4bbSAndreas Gohr    $d['policy'] = (int) $d['policy'];
33047248316SAndreas Gohr
33147248316SAndreas Gohr    // create local.php
33224650a19SAndreas Gohr    $now    = gmdate('r');
33347248316SAndreas Gohr    $output = <<<EOT
33447248316SAndreas Gohr<?php
33547248316SAndreas Gohr/**
33647248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings
33747248316SAndreas Gohr * Auto-generated by install script
33847248316SAndreas Gohr * Date: $now
33947248316SAndreas Gohr */
34047248316SAndreas Gohr
34147248316SAndreas GohrEOT;
3422613efa1SAndreas Gohr    // add any config options set by a previous installer
3432613efa1SAndreas Gohr    $preset = __DIR__.'/install.conf';
3442613efa1SAndreas Gohr    if(file_exists($preset)){
3452613efa1SAndreas Gohr        $output .= "# preset config options\n";
3462613efa1SAndreas Gohr        $output .= file_get_contents($preset);
3472613efa1SAndreas Gohr        $output .= "\n\n";
3482613efa1SAndreas Gohr        $output .= "# options selected in installer\n";
3492613efa1SAndreas Gohr        @unlink($preset);
3502613efa1SAndreas Gohr    }
3512613efa1SAndreas Gohr
35247248316SAndreas Gohr    $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
3530036aa89SAndreas Gohr    $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
35406361442SAndreas Gohr    $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n";
35547248316SAndreas Gohr    if($d['acl']){
35647248316SAndreas Gohr        $output .= '$conf[\'useacl\'] = 1'.";\n";
357523d7ea6Schris        $output .= "\$conf['superuser'] = '@admin';\n";
35847248316SAndreas Gohr    }
359ab9346edSAnika Henke    if(!$d['allowreg']){
36043c137edSAnika Henke        $output .= '$conf[\'disableactions\'] = \'register\''.";\n";
361d2ea6dc1SAnika Henke    }
36247248316SAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output);
36347248316SAndreas Gohr
36447248316SAndreas Gohr    if ($d['acl']) {
3653791b589SAndreas Gohr        // hash the password
3663791b589SAndreas Gohr        $phash = new PassHash();
3673791b589SAndreas Gohr        $pass = $phash->hash_smd5($d['password']);
3683791b589SAndreas Gohr
36947248316SAndreas Gohr        // create users.auth.php
3703791b589SAndreas Gohr        // --- user:SMD5password:Real Name:email:groups,comma,seperated
371d2ea6dc1SAnika Henke        $output = join(":",array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user'));
37247248316SAndreas Gohr        $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n";
37347248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output);
37447248316SAndreas Gohr
37547248316SAndreas Gohr        // create acl.auth.php
3768af2e4bbSAndreas Gohr        $output = <<<EOT
3778af2e4bbSAndreas Gohr# acl.auth.php
3788af2e4bbSAndreas Gohr# <?php exit()?>
3798af2e4bbSAndreas Gohr# Don't modify the lines above
3808af2e4bbSAndreas Gohr#
3818af2e4bbSAndreas Gohr# Access Control Lists
3828af2e4bbSAndreas Gohr#
3838af2e4bbSAndreas Gohr# Auto-generated by install script
3848af2e4bbSAndreas Gohr# Date: $now
3858af2e4bbSAndreas Gohr
3868af2e4bbSAndreas GohrEOT;
3878af2e4bbSAndreas Gohr        if($d['policy'] == 2){
3888af2e4bbSAndreas Gohr            $output .=  "*               @ALL          0\n";
389d2ea6dc1SAnika Henke            $output .=  "*               @user         8\n";
3909c70688aSchris        }elseif($d['policy'] == 1){
3918af2e4bbSAndreas Gohr            $output .=  "*               @ALL          1\n";
392d2ea6dc1SAnika Henke            $output .=  "*               @user         8\n";
3938af2e4bbSAndreas Gohr        }else{
3948af2e4bbSAndreas Gohr            $output .=  "*               @ALL          8\n";
3958af2e4bbSAndreas Gohr        }
39647248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output);
39747248316SAndreas Gohr    }
3983a0852d9SAndreas Gohr
3993a0852d9SAndreas Gohr    // enable popularity submission
4003a0852d9SAndreas Gohr    if($d['pop']){
4013a0852d9SAndreas Gohr        @touch(DOKU_INC.'data/cache/autosubmit.txt');
4023a0852d9SAndreas Gohr    }
4033a0852d9SAndreas Gohr
404c70d6ceeSAndreas Gohr    // disable auth plugins til needed
405c70d6ceeSAndreas Gohr    $output = <<<EOT
406c70d6ceeSAndreas Gohr<?php
407c70d6ceeSAndreas Gohr/*
408c70d6ceeSAndreas Gohr * Local plugin enable/disable settings
409c70d6ceeSAndreas Gohr *
410c70d6ceeSAndreas Gohr * Auto-generated by install script
411c70d6ceeSAndreas Gohr * Date: $now
412c70d6ceeSAndreas Gohr */
413c70d6ceeSAndreas Gohr
414c70d6ceeSAndreas Gohr\$plugins['authad']    = 0;
415c70d6ceeSAndreas Gohr\$plugins['authldap']  = 0;
416c70d6ceeSAndreas Gohr\$plugins['authmysql'] = 0;
417c70d6ceeSAndreas Gohr\$plugins['authpgsql'] = 0;
418c70d6ceeSAndreas Gohr
419c70d6ceeSAndreas GohrEOT;
420c70d6ceeSAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL.'plugins.local.php', $output);
421c70d6ceeSAndreas Gohr
42247248316SAndreas Gohr    return $ok;
42347248316SAndreas Gohr}
42447248316SAndreas Gohr
42547248316SAndreas Gohr/**
42647248316SAndreas Gohr * Write the given content to a file
42747248316SAndreas Gohr *
42847248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
429253d4b48SGerrit Uitslag *
430253d4b48SGerrit Uitslag * @param string $filename
431253d4b48SGerrit Uitslag * @param string $data
432253d4b48SGerrit Uitslag * @return bool
43347248316SAndreas Gohr */
43447248316SAndreas Gohrfunction fileWrite($filename, $data) {
43547248316SAndreas Gohr    global $error;
43647248316SAndreas Gohr    global $lang;
43747248316SAndreas Gohr
43847248316SAndreas Gohr    if (($fp = @fopen($filename, 'wb')) === false) {
43947248316SAndreas Gohr        $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
44047248316SAndreas Gohr        $error[]  = sprintf($lang['i_writeerr'],$filename);
44147248316SAndreas Gohr        return false;
44247248316SAndreas Gohr    }
44347248316SAndreas Gohr
44447248316SAndreas Gohr    if (!empty($data)) { fwrite($fp, $data);  }
44547248316SAndreas Gohr    fclose($fp);
44647248316SAndreas Gohr    return true;
44747248316SAndreas Gohr}
44847248316SAndreas Gohr
44947248316SAndreas Gohr
45047248316SAndreas Gohr/**
45147248316SAndreas Gohr * check installation dependent local config files and tests for a known
45247248316SAndreas Gohr * unmodified main config file
45347248316SAndreas Gohr *
45447248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
455253d4b48SGerrit Uitslag *
456253d4b48SGerrit Uitslag * @return bool
45747248316SAndreas Gohr */
45847248316SAndreas Gohrfunction check_configs(){
45947248316SAndreas Gohr    global $error;
46047248316SAndreas Gohr    global $lang;
46147248316SAndreas Gohr
46247248316SAndreas Gohr    $ok = true;
46347248316SAndreas Gohr
4645cfb8815Schris    $config_files = array(
4655cfb8815Schris        'local' => DOKU_LOCAL.'local.php',
4665cfb8815Schris        'users' => DOKU_LOCAL.'users.auth.php',
4675cfb8815Schris        'auth'  => DOKU_LOCAL.'acl.auth.php'
4685cfb8815Schris    );
4695cfb8815Schris
47047248316SAndreas Gohr    // configs shouldn't exist
47147248316SAndreas Gohr    foreach ($config_files as $file) {
47279e79377SAndreas Gohr        if (file_exists($file) && filesize($file)) {
47347248316SAndreas Gohr            $file    = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
47447248316SAndreas Gohr            $error[] = sprintf($lang['i_confexists'],$file);
47547248316SAndreas Gohr            $ok      = false;
47647248316SAndreas Gohr        }
47747248316SAndreas Gohr    }
47847248316SAndreas Gohr    return $ok;
47947248316SAndreas Gohr}
48047248316SAndreas Gohr
48147248316SAndreas Gohr
48247248316SAndreas Gohr/**
48347248316SAndreas Gohr * Check other installation dir/file permission requirements
48447248316SAndreas Gohr *
48547248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
486253d4b48SGerrit Uitslag *
487253d4b48SGerrit Uitslag * @return bool
48847248316SAndreas Gohr */
48947248316SAndreas Gohrfunction check_permissions(){
49047248316SAndreas Gohr    global $error;
49147248316SAndreas Gohr    global $lang;
49247248316SAndreas Gohr
49347248316SAndreas Gohr    $dirs = array(
49447248316SAndreas Gohr        'conf'        => DOKU_LOCAL,
49547248316SAndreas Gohr        'data'        => DOKU_INC.'data',
49647248316SAndreas Gohr        'pages'       => DOKU_INC.'data/pages',
49747248316SAndreas Gohr        'attic'       => DOKU_INC.'data/attic',
49847248316SAndreas Gohr        'media'       => DOKU_INC.'data/media',
49949b78edaSAndreas Gohr        'media_attic' => DOKU_INC.'data/media_attic',
50049b78edaSAndreas Gohr        'media_meta'  => DOKU_INC.'data/media_meta',
50147248316SAndreas Gohr        'meta'        => DOKU_INC.'data/meta',
50247248316SAndreas Gohr        'cache'       => DOKU_INC.'data/cache',
50347248316SAndreas Gohr        'locks'       => DOKU_INC.'data/locks',
5049711045aSAndreas Gohr        'index'       => DOKU_INC.'data/index',
505de33a58fSMichael Klier        'tmp'         => DOKU_INC.'data/tmp'
50647248316SAndreas Gohr    );
50747248316SAndreas Gohr
50847248316SAndreas Gohr    $ok = true;
50947248316SAndreas Gohr    foreach($dirs as $dir){
51079e79377SAndreas Gohr        if(!file_exists("$dir/.") || !is_writable($dir)){
51170a6aa16Schris            $dir     = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
51247248316SAndreas Gohr            $error[] = sprintf($lang['i_permfail'],$dir);
51347248316SAndreas Gohr            $ok      = false;
51447248316SAndreas Gohr        }
51547248316SAndreas Gohr    }
51647248316SAndreas Gohr    return $ok;
51747248316SAndreas Gohr}
51847248316SAndreas Gohr
51947248316SAndreas Gohr/**
5203afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version
52147248316SAndreas Gohr *
52247248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
523253d4b48SGerrit Uitslag *
524253d4b48SGerrit Uitslag * @return bool
52547248316SAndreas Gohr */
52647248316SAndreas Gohrfunction check_functions(){
52747248316SAndreas Gohr    global $error;
52847248316SAndreas Gohr    global $lang;
5293afe5d1cSAndreas Gohr    $ok = true;
5303afe5d1cSAndreas Gohr
5313476bb81SAndreas Gohr    if(version_compare(phpversion(),'5.6.0','<')){
5323476bb81SAndreas Gohr        $error[] = sprintf($lang['i_phpver'],phpversion(),'5.6.0');
5333afe5d1cSAndreas Gohr        $ok = false;
5343afe5d1cSAndreas Gohr    }
5353afe5d1cSAndreas Gohr
5367f413440SAndreas Gohr    if(ini_get('mbstring.func_overload') != 0){
5377f413440SAndreas Gohr        $error[] = $lang['i_mbfuncoverload'];
5387f413440SAndreas Gohr        $ok = false;
5397f413440SAndreas Gohr    }
5407f413440SAndreas Gohr
5413009a773SAndreas Gohr    $funcs = explode(' ','addslashes call_user_func chmod copy fgets '.
54247248316SAndreas Gohr                         'file file_exists fseek flush filesize ftell fopen '.
54347248316SAndreas Gohr                         'glob header ignore_user_abort ini_get mail mkdir '.
54447248316SAndreas Gohr                         'ob_start opendir parse_ini_file readfile realpath '.
545bab4a8bdSAndreas Gohr                         'rename rmdir serialize session_start unlink usleep '.
546d1d99bb9SAndreas Gohr                         'preg_replace file_get_contents htmlspecialchars_decode '.
547ab38a322Slupo49                         'spl_autoload_register stream_select fsockopen pack');
54847248316SAndreas Gohr
54970a6aa16Schris    if (!function_exists('mb_substr')) {
55070a6aa16Schris        $funcs[] = 'utf8_encode';
55170a6aa16Schris        $funcs[] = 'utf8_decode';
55270a6aa16Schris    }
55370a6aa16Schris
55447248316SAndreas Gohr    foreach($funcs as $func){
55547248316SAndreas Gohr        if(!function_exists($func)){
55647248316SAndreas Gohr            $error[] = sprintf($lang['i_funcna'],$func);
55747248316SAndreas Gohr            $ok = false;
55847248316SAndreas Gohr        }
55947248316SAndreas Gohr    }
56047248316SAndreas Gohr    return $ok;
56147248316SAndreas Gohr}
56247248316SAndreas Gohr
56347248316SAndreas Gohr/**
56447248316SAndreas Gohr * Print language selection
56547248316SAndreas Gohr *
56647248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
56747248316SAndreas Gohr */
56847248316SAndreas Gohrfunction langsel(){
56947248316SAndreas Gohr    global $lang;
57047248316SAndreas Gohr    global $LC;
57147248316SAndreas Gohr
57247248316SAndreas Gohr    $dir = DOKU_INC.'inc/lang';
57347248316SAndreas Gohr    $dh  = opendir($dir);
57447248316SAndreas Gohr    if(!$dh) return;
57547248316SAndreas Gohr
57647248316SAndreas Gohr    $langs = array();
57747248316SAndreas Gohr    while (($file = readdir($dh)) !== false) {
57847248316SAndreas Gohr        if(preg_match('/^[\._]/',$file)) continue;
57979e79377SAndreas Gohr        if(is_dir($dir.'/'.$file) && file_exists($dir.'/'.$file.'/lang.php')){
58047248316SAndreas Gohr            $langs[] = $file;
58147248316SAndreas Gohr        }
58247248316SAndreas Gohr    }
58347248316SAndreas Gohr    closedir($dh);
58447248316SAndreas Gohr    sort($langs);
58547248316SAndreas Gohr
58647248316SAndreas Gohr    echo '<form action="">';
58747248316SAndreas Gohr    echo $lang['i_chooselang'];
58847248316SAndreas Gohr    echo ': <select name="l" onchange="submit()">';
58947248316SAndreas Gohr    foreach($langs as $l){
59047248316SAndreas Gohr        $sel = ($l == $LC) ? 'selected="selected"' : '';
59147248316SAndreas Gohr        echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
59247248316SAndreas Gohr    }
59347248316SAndreas Gohr    echo '</select> ';
594ae614416SAnika Henke    echo '<button type="submit">'.$lang['btn_update'].'</button>';
59547248316SAndreas Gohr    echo '</form>';
59647248316SAndreas Gohr}
59747248316SAndreas Gohr
59847248316SAndreas Gohr/**
599c66972f2SAdrian Lang * Print global error array
60047248316SAndreas Gohr *
60147248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
60247248316SAndreas Gohr */
60347248316SAndreas Gohrfunction print_errors(){
60447248316SAndreas Gohr    global $error;
6054b530faaSTom N Harris    if(!empty($error)) {
60647248316SAndreas Gohr        echo '<ul>';
60747248316SAndreas Gohr        foreach ($error as $err){
60847248316SAndreas Gohr            echo "<li>$err</li>";
60947248316SAndreas Gohr        }
61047248316SAndreas Gohr        echo '</ul>';
61147248316SAndreas Gohr    }
6124b530faaSTom N Harris}
613