xref: /dokuwiki/install.php (revision d1d99bb9528b5a7ca62b74e60314288602cbd5a0)
15cfb8815Schris<?php
25cfb8815Schris/**
35cfb8815Schris * Dokuwiki installation assistance
45cfb8815Schris *
55cfb8815Schris * @author      Chris Smith <chris@jalakai.co.uk>
65cfb8815Schris */
75cfb8815Schris
8d0a27cb0SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
95cfb8815Schrisif(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
105cfb8815Schrisif(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC.'conf/');
115cfb8815Schris
123545b2e0Schris// check for error reporting override or set error reporting to sane values
133545b2e0Schrisif (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE); }
143545b2e0Schriselse { error_reporting(DOKU_E_LEVEL); }
153545b2e0Schris
1647248316SAndreas Gohr// kill magic quotes
1747248316SAndreas Gohrif (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) {
1847248316SAndreas Gohr    if (!empty($_GET))    remove_magic_quotes($_GET);
1947248316SAndreas Gohr    if (!empty($_POST))   remove_magic_quotes($_POST);
2047248316SAndreas Gohr    if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE);
2147248316SAndreas Gohr    if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST);
2247248316SAndreas Gohr    @ini_set('magic_quotes_gpc', 0);
2347248316SAndreas Gohr    define('MAGIC_QUOTES_STRIPPED',1);
2447248316SAndreas Gohr}
2547248316SAndreas Gohr@set_magic_quotes_runtime(0);
2647248316SAndreas Gohr@ini_set('magic_quotes_sybase',0);
275cfb8815Schris
2847248316SAndreas Gohr// language strings
2947248316SAndreas Gohrrequire_once(DOKU_INC.'inc/lang/en/lang.php');
3047248316SAndreas Gohr$LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']);
3147248316SAndreas Gohrif(!$LC) $LC = 'en';
3247248316SAndreas Gohrif($LC && $LC != 'en' ) {
3347248316SAndreas Gohr    require_once(DOKU_INC.'inc/lang/'.$LC.'/lang.php');
3447248316SAndreas Gohr}
3547248316SAndreas Gohr
3647248316SAndreas Gohr// initialise variables ...
3747248316SAndreas Gohr$error = array();
3847248316SAndreas Gohr
3947248316SAndreas Gohr$dokuwiki_hash = array(
4047248316SAndreas Gohr    '2005-09-22'   => 'e33223e957b0b0a130d0520db08f8fb7',
4147248316SAndreas Gohr    '2006-03-05'   => '51295727f79ab9af309a2fd9e0b61acc',
4247248316SAndreas Gohr    '2006-03-09'   => '51295727f79ab9af309a2fd9e0b61acc',
434dde32ddSAndreas Gohr    '2006-11-06'   => 'b3a8af76845977c2000d85d6990dd72b',
44e7f137b2SAndreas Gohr    '2007-05-24'   => 'd80f2740c84c4a6a791fd3c7a353536f',
4583666c1bSAndreas Gohr    '2007-06-26'   => 'b3ca19c7a654823144119980be73cd77',
46dd6510bdSAndreas Gohr    '2008-05-04'   => '1e5c42eac3219d9e21927c39e3240aad',
47b4353e51SAndreas Gohr    '2009-02-14'   => 'ec8c04210732a14fdfce0f7f6eead865',
4885d9abfcSAndreas Gohr    '2009-12-25'   => '993c4b2b385643efe5abf8e7010e11f4',
49eb97dcb8SAndreas Gohr    '2010-11-07'   => '7921d48195f4db21b8ead6d9bea801b8'
5047248316SAndreas Gohr);
5147248316SAndreas Gohr
5247248316SAndreas Gohr
5347248316SAndreas Gohr
5447248316SAndreas Gohr// begin output
5547248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8');
5647248316SAndreas Gohr?>
5747248316SAndreas Gohr<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5847248316SAndreas Gohr "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5947248316SAndreas Gohr<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $LC?>"
6047248316SAndreas Gohr lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>">
6147248316SAndreas Gohr<head>
6247248316SAndreas Gohr    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
634208c142SAndreas Gohr    <title><?php echo $lang['i_installer']?></title>
6447248316SAndreas Gohr    <style type="text/css">
6547248316SAndreas Gohr        body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; }
6647248316SAndreas Gohr        img { border: none }
6747248316SAndreas Gohr        br.cl { clear:both; }
6870a6aa16Schris        code { font-size: 110%; color: #800000; }
6947248316SAndreas Gohr        fieldset { border: none }
709c70688aSchris        label { display: block; margin-top: 0.5em; }
718af2e4bbSAndreas Gohr        select.text, input.text { width: 30em; margin: 0 0.5em; }
7206361442SAndreas Gohr        a {text-decoration: none}
7347248316SAndreas Gohr    </style>
7447248316SAndreas Gohr    <script type="text/javascript" language="javascript">
7547248316SAndreas Gohr        function acltoggle(){
7647248316SAndreas Gohr            var cb = document.getElementById('acl');
7747248316SAndreas Gohr            var fs = document.getElementById('acldep');
7847248316SAndreas Gohr            if(!cb || !fs) return;
7947248316SAndreas Gohr            if(cb.checked){
8047248316SAndreas Gohr                fs.style.display = '';
8147248316SAndreas Gohr            }else{
8247248316SAndreas Gohr                fs.style.display = 'none';
8347248316SAndreas Gohr            }
8447248316SAndreas Gohr        }
8547248316SAndreas Gohr        window.onload = function(){
8647248316SAndreas Gohr            acltoggle();
8747248316SAndreas Gohr            var cb = document.getElementById('acl');
8847248316SAndreas Gohr            if(cb) cb.onchange = acltoggle;
8947248316SAndreas Gohr        };
9047248316SAndreas Gohr    </script>
9147248316SAndreas Gohr</head>
9247248316SAndreas Gohr<body style="">
9347248316SAndreas Gohr    <h1 style="float:left">
942e79fc15SAnika Henke        <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png&w=64"
9547248316SAndreas Gohr             style="vertical-align: middle;" alt="" />
9647248316SAndreas Gohr        <?php echo $lang['i_installer']?>
9747248316SAndreas Gohr    </h1>
9847248316SAndreas Gohr    <div style="float:right; margin: 1em;">
9947248316SAndreas Gohr        <?php langsel()?>
10047248316SAndreas Gohr    </div>
10147248316SAndreas Gohr    <br class="cl" />
10247248316SAndreas Gohr
10347248316SAndreas Gohr    <div style="float: right; width: 34%;">
10447248316SAndreas Gohr        <?php
10547248316SAndreas Gohr            if(@file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){
10647248316SAndreas Gohr                include(DOKU_INC.'inc/lang/'.$LC.'/install.html');
10747248316SAndreas Gohr            }else{
108ca64d724Schris                print "<div lang=\"en\" dir=\"ltr\">\n";
10947248316SAndreas Gohr                include(DOKU_INC.'inc/lang/en/install.html');
110ca64d724Schris                print "</div>\n";
11147248316SAndreas Gohr            }
11247248316SAndreas Gohr        ?>
113c8b43921SAndreas Gohr        <a style="background: transparent url(data/security.png) left top no-repeat;
114c8b43921SAndreas Gohr                  display: block; width:380px; height:73px; border:none; clear:both;"
115c8b43921SAndreas Gohr           target="_blank"
116c8b43921SAndreas Gohr           href="http://www.dokuwiki.org/security#web_access_security"></a>
11747248316SAndreas Gohr    </div>
11847248316SAndreas Gohr
11947248316SAndreas Gohr    <div style="float: left; width: 58%;">
12047248316SAndreas Gohr        <?php
12147248316SAndreas Gohr            if(! (check_functions() && check_permissions()) ){
12247248316SAndreas Gohr                echo '<p>'.$lang['i_problems'].'</p>';
12347248316SAndreas Gohr                print_errors();
12470a6aa16Schris                print_retry();
12547248316SAndreas Gohr            }elseif(!check_configs()){
12647248316SAndreas Gohr                echo '<p>'.$lang['i_modified'].'</p>';
12747248316SAndreas Gohr                print_errors();
12847248316SAndreas Gohr            }elseif($_REQUEST['submit']){
12947248316SAndreas Gohr                if(!check_data($_REQUEST['d'])){
13047248316SAndreas Gohr                    print_errors();
13147248316SAndreas Gohr                    print_form($_REQUEST['d']);
13247248316SAndreas Gohr                }elseif(!store_data($_REQUEST['d'])){
13347248316SAndreas Gohr                    echo '<p>'.$lang['i_failure'].'</p>';
13447248316SAndreas Gohr                    print_errors();
13547248316SAndreas Gohr                }else{
13647248316SAndreas Gohr                    echo '<p>'.$lang['i_success'].'</p>';
13747248316SAndreas Gohr                }
13847248316SAndreas Gohr            }else{
13947248316SAndreas Gohr                print_form($_REQUEST['d']);
14047248316SAndreas Gohr            }
14147248316SAndreas Gohr        ?>
14247248316SAndreas Gohr    </div>
14347248316SAndreas Gohr
144c8b43921SAndreas Gohr
14547248316SAndreas Gohr<div style="clear: both">
146f46c9e83SAnika Henke  <a href="http://dokuwiki.org/"><img src="lib/tpl/default/images/button-dw.png" alt="driven by DokuWiki" /></a>
14747248316SAndreas Gohr  <a href="http://www.php.net"><img src="lib/tpl/default/images/button-php.gif" alt="powered by PHP" /></a>
14847248316SAndreas Gohr</div>
14947248316SAndreas Gohr</body>
15047248316SAndreas Gohr</html>
15147248316SAndreas Gohr<?php
15247248316SAndreas Gohr
15347248316SAndreas Gohr/**
15447248316SAndreas Gohr * Print the input form
15547248316SAndreas Gohr */
15647248316SAndreas Gohrfunction print_form($d){
15747248316SAndreas Gohr    global $lang;
15847248316SAndreas Gohr    global $LC;
15947248316SAndreas Gohr
16006361442SAndreas Gohr    include(DOKU_CONF.'license.php');
16106361442SAndreas Gohr
16247248316SAndreas Gohr    if(!is_array($d)) $d = array();
16347248316SAndreas Gohr    $d = array_map('htmlspecialchars',$d);
16447248316SAndreas Gohr
16547248316SAndreas Gohr    if(!isset($d['acl'])) $d['acl']=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>
18247248316SAndreas Gohr                <input class="text" type="text" name="d[superuser]" id="superuser" value="<?php echo $d['superuser'] ?>" />
18347248316SAndreas Gohr
18447248316SAndreas Gohr                <label for="fullname"><?php echo $lang['fullname']?></label>
18547248316SAndreas Gohr                <input class="text" type="text" name="d[fullname]" id="fullname" value="<?php echo $d['fullname'] ?>" />
18647248316SAndreas Gohr
18747248316SAndreas Gohr                <label for="email"><?php echo $lang['email']?></label>
18847248316SAndreas Gohr                <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" />
18947248316SAndreas Gohr
19047248316SAndreas Gohr                <label for="password"><?php echo $lang['pass']?></label>
19147248316SAndreas Gohr                <input class="text" type="password" name="d[password]" id="password" />
19247248316SAndreas Gohr
19347248316SAndreas Gohr                <label for="confirm"><?php echo $lang['passchk']?></label>
19447248316SAndreas Gohr                <input class="text" type="password" name="d[confirm]" id="confirm" />
1958af2e4bbSAndreas Gohr
1968af2e4bbSAndreas Gohr                <label for="policy"><?php echo $lang['i_policy']?></label>
1978af2e4bbSAndreas Gohr                <select class="text" name="d[policy]" id="policy">
1988af2e4bbSAndreas Gohr                    <option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php echo $lang['i_pol0']?></option>
1998af2e4bbSAndreas Gohr                    <option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php echo $lang['i_pol1']?></option>
2008af2e4bbSAndreas Gohr                    <option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php echo $lang['i_pol2']?></option>
2018af2e4bbSAndreas Gohr                </select>
20206361442SAndreas Gohr
20347248316SAndreas Gohr            </fieldset>
20447248316SAndreas Gohr        </fieldset>
20547248316SAndreas Gohr
20606361442SAndreas Gohr        <fieldset>
20706361442SAndreas Gohr            <p><?php echo $lang['i_license']?></p>
20806361442SAndreas Gohr            <?php
20906361442SAndreas Gohr            array_unshift($license,array('name' => 'None', 'url'=>''));
21006361442SAndreas Gohr            if(!isset($d['license'])) $d['license'] = 'cc-by-sa';
21106361442SAndreas Gohr            foreach($license as $key => $lic){
21206361442SAndreas Gohr                echo '<label for="lic_'.$key.'">';
21306361442SAndreas Gohr                echo '<input type="radio" name="d[license]" value="'.htmlspecialchars($key).'" id="lic_'.$key.'"'.
21406361442SAndreas Gohr                     (($d['license'] == $key)?'checked="checked"':'').'>';
21506361442SAndreas Gohr                echo htmlspecialchars($lic['name']);
21606361442SAndreas Gohr                if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>';
21706361442SAndreas Gohr                echo '</label>';
21806361442SAndreas Gohr            }
21906361442SAndreas Gohr            ?>
22006361442SAndreas Gohr        </fieldset>
22106361442SAndreas Gohr
22247248316SAndreas Gohr    </fieldset>
22347248316SAndreas Gohr    <fieldset id="process">
22447248316SAndreas Gohr        <input class="button" type="submit" name="submit" value="<?php echo $lang['btn_save']?>" />
22547248316SAndreas Gohr    </fieldset>
22647248316SAndreas Gohr    </form>
22747248316SAndreas Gohr    <?php
22847248316SAndreas Gohr}
22947248316SAndreas Gohr
23070a6aa16Schrisfunction print_retry() {
23170a6aa16Schris    global $lang;
2329ad6da3dSAndreas Gohr    global $LC;
23370a6aa16Schris    ?>
23470a6aa16Schris    <form action="" method="get">
23570a6aa16Schris      <fieldset>
2369ad6da3dSAndreas Gohr        <input type="hidden" name="l" value="<?php echo $LC ?>" />
23770a6aa16Schris        <input class="button" type="submit" value="<?php echo $lang['i_retry'];?>" />
23870a6aa16Schris      </fieldset>
23970a6aa16Schris    </form>
24070a6aa16Schris    <?php
24170a6aa16Schris}
24270a6aa16Schris
24347248316SAndreas Gohr/**
24447248316SAndreas Gohr * Check validity of data
24547248316SAndreas Gohr *
24647248316SAndreas Gohr * @author Andreas Gohr
24747248316SAndreas Gohr */
248e2386079SAndreas Gohrfunction check_data(&$d){
24947248316SAndreas Gohr    global $lang;
25047248316SAndreas Gohr    global $error;
25147248316SAndreas Gohr
252e2386079SAndreas Gohr    //autolowercase the username
253e2386079SAndreas Gohr    $d['superuser'] = strtolower($d['superuser']);
254e2386079SAndreas Gohr
25547248316SAndreas Gohr    $ok = true;
25647248316SAndreas Gohr
25747248316SAndreas Gohr    // check input
25847248316SAndreas Gohr    if(empty($d['title'])){
25947248316SAndreas Gohr        $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
26047248316SAndreas Gohr        $ok      = false;
26147248316SAndreas Gohr    }
26247248316SAndreas Gohr    if($d['acl']){
263d60813a2SGina Haeussge        if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){
26447248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
26547248316SAndreas Gohr            $ok      = false;
26647248316SAndreas Gohr        }
26747248316SAndreas Gohr        if(empty($d['password'])){
26847248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['pass']);
26947248316SAndreas Gohr            $ok      = false;
27047248316SAndreas Gohr        }
27147248316SAndreas Gohr        if($d['confirm'] != $d['password']){
27247248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['passchk']);
27347248316SAndreas Gohr            $ok      = false;
27447248316SAndreas Gohr        }
27547248316SAndreas Gohr        if(empty($d['fullname']) || strstr($d['fullname'],':')){
27647248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['fullname']);
27747248316SAndreas Gohr            $ok      = false;
27847248316SAndreas Gohr        }
279e2386079SAndreas Gohr        if(empty($d['email']) || strstr($d['email'],':') || !strstr($d['email'],'@')){
28047248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['email']);
28147248316SAndreas Gohr            $ok      = false;
28247248316SAndreas Gohr        }
28347248316SAndreas Gohr    }
28447248316SAndreas Gohr    return $ok;
28547248316SAndreas Gohr}
28647248316SAndreas Gohr
28747248316SAndreas Gohr/**
28847248316SAndreas Gohr * Writes the data to the config files
28947248316SAndreas Gohr *
29047248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
29147248316SAndreas Gohr */
29247248316SAndreas Gohrfunction store_data($d){
2930036aa89SAndreas Gohr    global $LC;
29447248316SAndreas Gohr    $ok = true;
2958af2e4bbSAndreas Gohr    $d['policy'] = (int) $d['policy'];
29647248316SAndreas Gohr
29747248316SAndreas Gohr    // create local.php
29824650a19SAndreas Gohr    $now    = gmdate('r');
29947248316SAndreas Gohr    $output = <<<EOT
30047248316SAndreas Gohr<?php
30147248316SAndreas Gohr/**
30247248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings
30347248316SAndreas Gohr * Auto-generated by install script
30447248316SAndreas Gohr * Date: $now
30547248316SAndreas Gohr */
30647248316SAndreas Gohr
30747248316SAndreas GohrEOT;
30847248316SAndreas Gohr    $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
3090036aa89SAndreas Gohr    $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
31006361442SAndreas Gohr    $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n";
31147248316SAndreas Gohr    if($d['acl']){
31247248316SAndreas Gohr        $output .= '$conf[\'useacl\'] = 1'.";\n";
313523d7ea6Schris        $output .= "\$conf['superuser'] = '@admin';\n";
31447248316SAndreas Gohr    }
31547248316SAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output);
31647248316SAndreas Gohr
31747248316SAndreas Gohr    if ($d['acl']) {
31847248316SAndreas Gohr        // create users.auth.php
31947248316SAndreas Gohr        // --- user:MD5password:Real Name:email:groups,comma,seperated
320f6e0e340SAndreas Gohr        $output = join(":",array($d['superuser'], md5($d['password']), $d['fullname'], $d['email'], 'admin,user'));
32147248316SAndreas Gohr        $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n";
32247248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output);
32347248316SAndreas Gohr
32447248316SAndreas Gohr        // create acl.auth.php
3258af2e4bbSAndreas Gohr        $output = <<<EOT
3268af2e4bbSAndreas Gohr# acl.auth.php
3278af2e4bbSAndreas Gohr# <?php exit()?>
3288af2e4bbSAndreas Gohr# Don't modify the lines above
3298af2e4bbSAndreas Gohr#
3308af2e4bbSAndreas Gohr# Access Control Lists
3318af2e4bbSAndreas Gohr#
3328af2e4bbSAndreas Gohr# Auto-generated by install script
3338af2e4bbSAndreas Gohr# Date: $now
3348af2e4bbSAndreas Gohr
3358af2e4bbSAndreas GohrEOT;
3368af2e4bbSAndreas Gohr        if($d['policy'] == 2){
3378af2e4bbSAndreas Gohr            $output .=  "*               @ALL          0\n";
3385c4260faSAndreas Gohr            $output .=  "*               @user         8\n";
3399c70688aSchris        }elseif($d['policy'] == 1){
3408af2e4bbSAndreas Gohr            $output .=  "*               @ALL          1\n";
3415c4260faSAndreas Gohr            $output .=  "*               @user         8\n";
3428af2e4bbSAndreas Gohr        }else{
3438af2e4bbSAndreas Gohr            $output .=  "*               @ALL          8\n";
3448af2e4bbSAndreas Gohr        }
34547248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output);
34647248316SAndreas Gohr    }
34747248316SAndreas Gohr    return $ok;
34847248316SAndreas Gohr}
34947248316SAndreas Gohr
35047248316SAndreas Gohr/**
35147248316SAndreas Gohr * Write the given content to a file
35247248316SAndreas Gohr *
35347248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
35447248316SAndreas Gohr */
35547248316SAndreas Gohrfunction fileWrite($filename, $data) {
35647248316SAndreas Gohr    global $error;
35747248316SAndreas Gohr    global $lang;
35847248316SAndreas Gohr
35947248316SAndreas Gohr    if (($fp = @fopen($filename, 'wb')) === false) {
36047248316SAndreas Gohr        $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
36147248316SAndreas Gohr        $error[]  = sprintf($lang['i_writeerr'],$filename);
36247248316SAndreas Gohr        return false;
36347248316SAndreas Gohr    }
36447248316SAndreas Gohr
36547248316SAndreas Gohr    if (!empty($data)) { fwrite($fp, $data);  }
36647248316SAndreas Gohr    fclose($fp);
36747248316SAndreas Gohr    return true;
36847248316SAndreas Gohr}
36947248316SAndreas Gohr
37047248316SAndreas Gohr
37147248316SAndreas Gohr/**
37247248316SAndreas Gohr * check installation dependent local config files and tests for a known
37347248316SAndreas Gohr * unmodified main config file
37447248316SAndreas Gohr *
37547248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
37647248316SAndreas Gohr */
37747248316SAndreas Gohrfunction check_configs(){
37847248316SAndreas Gohr    global $error;
37947248316SAndreas Gohr    global $lang;
38047248316SAndreas Gohr    global $dokuwiki_hash;
38147248316SAndreas Gohr
38247248316SAndreas Gohr    $ok = true;
38347248316SAndreas Gohr
3845cfb8815Schris    $config_files = array(
3855cfb8815Schris        'local' => DOKU_LOCAL.'local.php',
3865cfb8815Schris        'users' => DOKU_LOCAL.'users.auth.php',
3875cfb8815Schris        'auth'  => DOKU_LOCAL.'acl.auth.php'
3885cfb8815Schris    );
3895cfb8815Schris
3905cfb8815Schris    // main dokuwiki config file (conf/dokuwiki.php) must not have been modified
391aa248fb5SAndreas Gohr    $installation_hash = md5(preg_replace("/(\015\012)|(\015)/","\012",
392aa248fb5SAndreas Gohr                             @file_get_contents(DOKU_CONF.'dokuwiki.php')));
3935cfb8815Schris    if (!in_array($installation_hash, $dokuwiki_hash)) {
39447248316SAndreas Gohr        $error[] = sprintf($lang['i_badhash'],$installation_hash);
39547248316SAndreas Gohr        $ok = false;
3965cfb8815Schris    }
3975cfb8815Schris
39847248316SAndreas Gohr    // configs shouldn't exist
39947248316SAndreas Gohr    foreach ($config_files as $file) {
40047248316SAndreas Gohr        if (@file_exists($file)) {
40147248316SAndreas Gohr            $file    = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
40247248316SAndreas Gohr            $error[] = sprintf($lang['i_confexists'],$file);
40347248316SAndreas Gohr            $ok      = false;
40447248316SAndreas Gohr        }
40547248316SAndreas Gohr    }
40647248316SAndreas Gohr    return $ok;
40747248316SAndreas Gohr}
40847248316SAndreas Gohr
40947248316SAndreas Gohr
41047248316SAndreas Gohr/**
41147248316SAndreas Gohr * Check other installation dir/file permission requirements
41247248316SAndreas Gohr *
41347248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
41447248316SAndreas Gohr */
41547248316SAndreas Gohrfunction check_permissions(){
41647248316SAndreas Gohr    global $error;
41747248316SAndreas Gohr    global $lang;
41847248316SAndreas Gohr
41947248316SAndreas Gohr    $dirs = array(
42047248316SAndreas Gohr        'conf'      => DOKU_LOCAL,
42147248316SAndreas Gohr        'data'      => DOKU_INC.'data',
42247248316SAndreas Gohr        'pages'     => DOKU_INC.'data/pages',
42347248316SAndreas Gohr        'attic'     => DOKU_INC.'data/attic',
42447248316SAndreas Gohr        'media'     => DOKU_INC.'data/media',
42547248316SAndreas Gohr        'meta'      => DOKU_INC.'data/meta',
42647248316SAndreas Gohr        'cache'     => DOKU_INC.'data/cache',
42747248316SAndreas Gohr        'locks'     => DOKU_INC.'data/locks',
4289711045aSAndreas Gohr        'index'     => DOKU_INC.'data/index',
429de33a58fSMichael Klier        'tmp'       => DOKU_INC.'data/tmp'
43047248316SAndreas Gohr    );
43147248316SAndreas Gohr
43247248316SAndreas Gohr    $ok = true;
43347248316SAndreas Gohr    foreach($dirs as $dir){
43447248316SAndreas Gohr        if(!@file_exists("$dir/.") || !@is_writable($dir)){
43570a6aa16Schris            $dir     = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
43647248316SAndreas Gohr            $error[] = sprintf($lang['i_permfail'],$dir);
43747248316SAndreas Gohr            $ok      = false;
43847248316SAndreas Gohr        }
43947248316SAndreas Gohr    }
44047248316SAndreas Gohr    return $ok;
44147248316SAndreas Gohr}
44247248316SAndreas Gohr
44347248316SAndreas Gohr/**
4443afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version
44547248316SAndreas Gohr *
44647248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
44747248316SAndreas Gohr */
44847248316SAndreas Gohrfunction check_functions(){
44947248316SAndreas Gohr    global $error;
45047248316SAndreas Gohr    global $lang;
4513afe5d1cSAndreas Gohr    $ok = true;
4523afe5d1cSAndreas Gohr
453ab91da89SAndreas Gohr    if(version_compare(phpversion(),'5.1.2','<')){
454ab91da89SAndreas Gohr        $error[] = sprintf($lang['i_phpver'],phpversion(),'5.1.2');
4553afe5d1cSAndreas Gohr        $ok = false;
4563afe5d1cSAndreas Gohr    }
4573afe5d1cSAndreas Gohr
45847248316SAndreas Gohr    $funcs = explode(' ','addslashes basename call_user_func chmod copy fgets '.
45947248316SAndreas Gohr                         'file file_exists fseek flush filesize ftell fopen '.
46047248316SAndreas Gohr                         'glob header ignore_user_abort ini_get mail mkdir '.
46147248316SAndreas Gohr                         'ob_start opendir parse_ini_file readfile realpath '.
462bab4a8bdSAndreas Gohr                         'rename rmdir serialize session_start unlink usleep '.
463*d1d99bb9SAndreas Gohr                         'preg_replace file_get_contents htmlspecialchars_decode '.
464*d1d99bb9SAndreas Gohr                         'spl_autoload_register');
46547248316SAndreas Gohr
46670a6aa16Schris    if (!function_exists('mb_substr')) {
46770a6aa16Schris        $funcs[] = 'utf8_encode';
46870a6aa16Schris        $funcs[] = 'utf8_decode';
46970a6aa16Schris    }
47070a6aa16Schris
47147248316SAndreas Gohr    foreach($funcs as $func){
47247248316SAndreas Gohr        if(!function_exists($func)){
47347248316SAndreas Gohr            $error[] = sprintf($lang['i_funcna'],$func);
47447248316SAndreas Gohr            $ok = false;
47547248316SAndreas Gohr        }
47647248316SAndreas Gohr    }
47747248316SAndreas Gohr    return $ok;
47847248316SAndreas Gohr}
47947248316SAndreas Gohr
48047248316SAndreas Gohr/**
48147248316SAndreas Gohr * Print language selection
48247248316SAndreas Gohr *
48347248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
48447248316SAndreas Gohr */
48547248316SAndreas Gohrfunction langsel(){
48647248316SAndreas Gohr    global $lang;
48747248316SAndreas Gohr    global $LC;
48847248316SAndreas Gohr
48947248316SAndreas Gohr    $dir = DOKU_INC.'inc/lang';
49047248316SAndreas Gohr    $dh  = opendir($dir);
49147248316SAndreas Gohr    if(!$dh) return;
49247248316SAndreas Gohr
49347248316SAndreas Gohr    $langs = array();
49447248316SAndreas Gohr    while (($file = readdir($dh)) !== false) {
49547248316SAndreas Gohr        if(preg_match('/^[\._]/',$file)) continue;
49647248316SAndreas Gohr        if(is_dir($dir.'/'.$file) && @file_exists($dir.'/'.$file.'/lang.php')){
49747248316SAndreas Gohr            $langs[] = $file;
49847248316SAndreas Gohr        }
49947248316SAndreas Gohr    }
50047248316SAndreas Gohr    closedir($dh);
50147248316SAndreas Gohr    sort($langs);
50247248316SAndreas Gohr
50347248316SAndreas Gohr    echo '<form action="">';
50447248316SAndreas Gohr    echo $lang['i_chooselang'];
50547248316SAndreas Gohr    echo ': <select name="l" onchange="submit()">';
50647248316SAndreas Gohr    foreach($langs as $l){
50747248316SAndreas Gohr        $sel = ($l == $LC) ? 'selected="selected"' : '';
50847248316SAndreas Gohr        echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
50947248316SAndreas Gohr    }
51047248316SAndreas Gohr    echo '</select> ';
51147248316SAndreas Gohr    echo '<input type="submit" value="'.$lang['btn_update'].'" />';
51247248316SAndreas Gohr    echo '</form>';
51347248316SAndreas Gohr}
51447248316SAndreas Gohr
51547248316SAndreas Gohr/**
516c66972f2SAdrian Lang * Print global error array
51747248316SAndreas Gohr *
51847248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
51947248316SAndreas Gohr */
52047248316SAndreas Gohrfunction print_errors(){
52147248316SAndreas Gohr    global $error;
52247248316SAndreas Gohr    echo '<ul>';
52347248316SAndreas Gohr    foreach ($error as $err){
52447248316SAndreas Gohr        echo "<li>$err</li>";
52547248316SAndreas Gohr    }
52647248316SAndreas Gohr    echo '</ul>';
52747248316SAndreas Gohr}
5285cfb8815Schris
5295cfb8815Schris/**
5305cfb8815Schris * remove magic quotes recursivly
5315cfb8815Schris *
5325cfb8815Schris * @author Andreas Gohr <andi@splitbrain.org>
5335cfb8815Schris */
5345cfb8815Schrisfunction remove_magic_quotes(&$array) {
5355cfb8815Schris    foreach (array_keys($array) as $key) {
5365cfb8815Schris        if (is_array($array[$key])) {
5375cfb8815Schris            remove_magic_quotes($array[$key]);
5385cfb8815Schris        }else {
5395cfb8815Schris            $array[$key] = stripslashes($array[$key]);
5405cfb8815Schris        }
5415cfb8815Schris    }
5425cfb8815Schris}
5435cfb8815Schris
544