xref: /dokuwiki/install.php (revision 9ad6da3da0ff12062aea8a11d11099e87c6acc3b)
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',
465faa223dSAndreas Gohr    'rc2007-03-31' => '1e5c42eac3219d9e21927c39e3240aad',
4747248316SAndreas Gohr);
4847248316SAndreas Gohr
4947248316SAndreas Gohr
5047248316SAndreas Gohr
5147248316SAndreas Gohr// begin output
5247248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8');
5347248316SAndreas Gohr?>
5447248316SAndreas Gohr<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5547248316SAndreas Gohr "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5647248316SAndreas Gohr<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $LC?>"
5747248316SAndreas Gohr lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>">
5847248316SAndreas Gohr<head>
5947248316SAndreas Gohr    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
604208c142SAndreas Gohr    <title><?php echo $lang['i_installer']?></title>
6147248316SAndreas Gohr    <style type="text/css">
6247248316SAndreas Gohr        body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; }
6347248316SAndreas Gohr        img { border: none }
6447248316SAndreas Gohr        br.cl { clear:both; }
6570a6aa16Schris        code { font-size: 110%; color: #800000; }
6647248316SAndreas Gohr        fieldset { border: none }
679c70688aSchris        label { display: block; margin-top: 0.5em; }
688af2e4bbSAndreas Gohr        select.text, input.text { width: 30em; margin: 0 0.5em; }
6947248316SAndreas Gohr    </style>
7047248316SAndreas Gohr    <script type="text/javascript" language="javascript">
7147248316SAndreas Gohr        function acltoggle(){
7247248316SAndreas Gohr            var cb = document.getElementById('acl');
7347248316SAndreas Gohr            var fs = document.getElementById('acldep');
7447248316SAndreas Gohr            if(!cb || !fs) return;
7547248316SAndreas Gohr            if(cb.checked){
7647248316SAndreas Gohr                fs.style.display = '';
7747248316SAndreas Gohr            }else{
7847248316SAndreas Gohr                fs.style.display = 'none';
7947248316SAndreas Gohr            }
8047248316SAndreas Gohr        }
8147248316SAndreas Gohr        window.onload = function(){
8247248316SAndreas Gohr            acltoggle();
8347248316SAndreas Gohr            var cb = document.getElementById('acl');
8447248316SAndreas Gohr            if(cb) cb.onchange = acltoggle;
8547248316SAndreas Gohr        };
8647248316SAndreas Gohr    </script>
8747248316SAndreas Gohr</head>
8847248316SAndreas Gohr<body style="">
8947248316SAndreas Gohr    <h1 style="float:left">
9047248316SAndreas Gohr        <img src="http://wiki.splitbrain.org/_media/wiki:dokuwiki-64.png"
9147248316SAndreas Gohr             style="vertical-align: middle;" alt="" />
9247248316SAndreas Gohr        <?php echo $lang['i_installer']?>
9347248316SAndreas Gohr    </h1>
9447248316SAndreas Gohr    <div style="float:right; margin: 1em;">
9547248316SAndreas Gohr        <?php langsel()?>
9647248316SAndreas Gohr    </div>
9747248316SAndreas Gohr    <br class="cl" />
9847248316SAndreas Gohr
9947248316SAndreas Gohr    <div style="float: right; width: 34%;">
10047248316SAndreas Gohr        <?php
10147248316SAndreas Gohr            if(@file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){
10247248316SAndreas Gohr                include(DOKU_INC.'inc/lang/'.$LC.'/install.html');
10347248316SAndreas Gohr            }else{
104ca64d724Schris                print "<div lang=\"en\" dir=\"ltr\">\n";
10547248316SAndreas Gohr                include(DOKU_INC.'inc/lang/en/install.html');
106ca64d724Schris                print "</div>\n";
10747248316SAndreas Gohr            }
10847248316SAndreas Gohr        ?>
10947248316SAndreas Gohr    </div>
11047248316SAndreas Gohr
11147248316SAndreas Gohr    <div style="float: left; width: 58%;">
11247248316SAndreas Gohr        <?php
11347248316SAndreas Gohr            if(! (check_functions() && check_permissions()) ){
11447248316SAndreas Gohr                echo '<p>'.$lang['i_problems'].'</p>';
11547248316SAndreas Gohr                print_errors();
11670a6aa16Schris                print_retry();
11747248316SAndreas Gohr            }elseif(!check_configs()){
11847248316SAndreas Gohr                echo '<p>'.$lang['i_modified'].'</p>';
11947248316SAndreas Gohr                print_errors();
12047248316SAndreas Gohr            }elseif($_REQUEST['submit']){
12147248316SAndreas Gohr                if(!check_data($_REQUEST['d'])){
12247248316SAndreas Gohr                    print_errors();
12347248316SAndreas Gohr                    print_form($_REQUEST['d']);
12447248316SAndreas Gohr                }elseif(!store_data($_REQUEST['d'])){
12547248316SAndreas Gohr                    echo '<p>'.$lang['i_failure'].'</p>';
12647248316SAndreas Gohr                    print_errors();
12747248316SAndreas Gohr                }else{
12847248316SAndreas Gohr                    echo '<p>'.$lang['i_success'].'</p>';
12947248316SAndreas Gohr                }
13047248316SAndreas Gohr            }else{
13147248316SAndreas Gohr                print_form($_REQUEST['d']);
13247248316SAndreas Gohr            }
13347248316SAndreas Gohr        ?>
13447248316SAndreas Gohr    </div>
13547248316SAndreas Gohr
13647248316SAndreas Gohr<div style="clear: both">
13747248316SAndreas Gohr  <a href="http://wiki.splitbrain.org/wiki:dokuwiki"><img src="lib/tpl/default/images/button-dw.png" alt="driven by DokuWiki" /></a>
13847248316SAndreas Gohr  <a href="http://www.php.net"><img src="lib/tpl/default/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
14647248316SAndreas Gohr */
14747248316SAndreas Gohrfunction print_form($d){
14847248316SAndreas Gohr    global $lang;
14947248316SAndreas Gohr    global $LC;
15047248316SAndreas Gohr
15147248316SAndreas Gohr    if(!is_array($d)) $d = array();
15247248316SAndreas Gohr    $d = array_map('htmlspecialchars',$d);
15347248316SAndreas Gohr
15447248316SAndreas Gohr    if(!isset($d['acl'])) $d['acl']=1;
15547248316SAndreas Gohr
15647248316SAndreas Gohr    ?>
15747248316SAndreas Gohr    <form action="" method="post">
15847248316SAndreas Gohr    <input type="hidden" name="l" value="<?php echo $LC ?>" />
15947248316SAndreas Gohr    <fieldset>
16047248316SAndreas Gohr        <label for="title"><?php echo $lang['i_wikiname']?>
16147248316SAndreas Gohr        <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" />
16247248316SAndreas Gohr        </label>
16347248316SAndreas Gohr
16447248316SAndreas Gohr        <fieldset style="margin-top: 1em;">
16547248316SAndreas Gohr            <label for="acl">
16647248316SAndreas Gohr            <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? 'checked="checked"' : ''));?> />
16747248316SAndreas Gohr            <?php echo $lang['i_enableacl']?></label>
16847248316SAndreas Gohr
16947248316SAndreas Gohr            <fieldset id="acldep">
17047248316SAndreas Gohr                <label for="superuser"><?php echo $lang['i_superuser']?></label>
17147248316SAndreas Gohr                <input class="text" type="text" name="d[superuser]" id="superuser" value="<?php echo $d['superuser'] ?>" />
17247248316SAndreas Gohr
17347248316SAndreas Gohr                <label for="fullname"><?php echo $lang['fullname']?></label>
17447248316SAndreas Gohr                <input class="text" type="text" name="d[fullname]" id="fullname" value="<?php echo $d['fullname'] ?>" />
17547248316SAndreas Gohr
17647248316SAndreas Gohr                <label for="email"><?php echo $lang['email']?></label>
17747248316SAndreas Gohr                <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" />
17847248316SAndreas Gohr
17947248316SAndreas Gohr                <label for="password"><?php echo $lang['pass']?></label>
18047248316SAndreas Gohr                <input class="text" type="password" name="d[password]" id="password" />
18147248316SAndreas Gohr
18247248316SAndreas Gohr                <label for="confirm"><?php echo $lang['passchk']?></label>
18347248316SAndreas Gohr                <input class="text" type="password" name="d[confirm]" id="confirm" />
1848af2e4bbSAndreas Gohr
1858af2e4bbSAndreas Gohr                <label for="policy"><?php echo $lang['i_policy']?></label>
1868af2e4bbSAndreas Gohr                <select class="text" name="d[policy]" id="policy">
1878af2e4bbSAndreas Gohr                    <option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php echo $lang['i_pol0']?></option>
1888af2e4bbSAndreas Gohr                    <option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php echo $lang['i_pol1']?></option>
1898af2e4bbSAndreas Gohr                    <option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php echo $lang['i_pol2']?></option>
1908af2e4bbSAndreas Gohr                </select>
19147248316SAndreas Gohr            </fieldset>
19247248316SAndreas Gohr        </fieldset>
19347248316SAndreas Gohr
19447248316SAndreas Gohr    </fieldset>
19547248316SAndreas Gohr    <fieldset id="process">
19647248316SAndreas Gohr        <input class="button" type="submit" name="submit" value="<?php echo $lang['btn_save']?>" />
19747248316SAndreas Gohr    </fieldset>
19847248316SAndreas Gohr    </form>
19947248316SAndreas Gohr    <?php
20047248316SAndreas Gohr}
20147248316SAndreas Gohr
20270a6aa16Schrisfunction print_retry() {
20370a6aa16Schris  global $lang;
204*9ad6da3dSAndreas Gohr  global $LC;
20570a6aa16Schris?>
20670a6aa16Schris    <form action="" method="get">
20770a6aa16Schris      <fieldset>
208*9ad6da3dSAndreas Gohr        <input type="hidden" name="l" value="<?php echo $LC ?>" />
20970a6aa16Schris        <input class="button" type="submit" value="<?php echo $lang['i_retry'];?>" />
21070a6aa16Schris      </fieldset>
21170a6aa16Schris    </form>
21270a6aa16Schris<?php
21370a6aa16Schris}
21470a6aa16Schris
21547248316SAndreas Gohr/**
21647248316SAndreas Gohr * Check validity of data
21747248316SAndreas Gohr *
21847248316SAndreas Gohr * @author Andreas Gohr
21947248316SAndreas Gohr */
220e2386079SAndreas Gohrfunction check_data(&$d){
22147248316SAndreas Gohr    global $lang;
22247248316SAndreas Gohr    global $error;
22347248316SAndreas Gohr
224e2386079SAndreas Gohr    //autolowercase the username
225e2386079SAndreas Gohr    $d['superuser'] = strtolower($d['superuser']);
226e2386079SAndreas Gohr
22747248316SAndreas Gohr    $ok = true;
22847248316SAndreas Gohr
22947248316SAndreas Gohr    // check input
23047248316SAndreas Gohr    if(empty($d['title'])){
23147248316SAndreas Gohr        $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
23247248316SAndreas Gohr        $ok      = false;
23347248316SAndreas Gohr    }
23447248316SAndreas Gohr    if($d['acl']){
23547248316SAndreas Gohr        if(!preg_match('/^[a-z1-9_]+$/',$d['superuser'])){
23647248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
23747248316SAndreas Gohr            $ok      = false;
23847248316SAndreas Gohr        }
23947248316SAndreas Gohr        if(empty($d['password'])){
24047248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['pass']);
24147248316SAndreas Gohr            $ok      = false;
24247248316SAndreas Gohr        }
24347248316SAndreas Gohr        if($d['confirm'] != $d['password']){
24447248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['passchk']);
24547248316SAndreas Gohr            $ok      = false;
24647248316SAndreas Gohr        }
24747248316SAndreas Gohr        if(empty($d['fullname']) || strstr($d['fullname'],':')){
24847248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['fullname']);
24947248316SAndreas Gohr            $ok      = false;
25047248316SAndreas Gohr        }
251e2386079SAndreas Gohr        if(empty($d['email']) || strstr($d['email'],':') || !strstr($d['email'],'@')){
25247248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['email']);
25347248316SAndreas Gohr            $ok      = false;
25447248316SAndreas Gohr        }
25547248316SAndreas Gohr    }
25647248316SAndreas Gohr    return $ok;
25747248316SAndreas Gohr}
25847248316SAndreas Gohr
25947248316SAndreas Gohr/**
26047248316SAndreas Gohr * Writes the data to the config files
26147248316SAndreas Gohr *
26247248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
26347248316SAndreas Gohr */
26447248316SAndreas Gohrfunction store_data($d){
2650036aa89SAndreas Gohr    global $LC;
26647248316SAndreas Gohr    $ok = true;
2678af2e4bbSAndreas Gohr    $d['policy'] = (int) $d['policy'];
26847248316SAndreas Gohr
26947248316SAndreas Gohr    // create local.php
27047248316SAndreas Gohr    $now    = date('r');
27147248316SAndreas Gohr    $output = <<<EOT
27247248316SAndreas Gohr<?php
27347248316SAndreas Gohr/**
27447248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings
27547248316SAndreas Gohr * Auto-generated by install script
27647248316SAndreas Gohr * Date: $now
27747248316SAndreas Gohr */
27847248316SAndreas Gohr
27947248316SAndreas GohrEOT;
28047248316SAndreas Gohr    $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
2810036aa89SAndreas Gohr    $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
28247248316SAndreas Gohr    if($d['acl']){
28347248316SAndreas Gohr        $output .= '$conf[\'useacl\'] = 1'.";\n";
284523d7ea6Schris        $output .= "\$conf['superuser'] = '@admin';\n";
28547248316SAndreas Gohr    }
28647248316SAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output);
28747248316SAndreas Gohr
28847248316SAndreas Gohr
28947248316SAndreas Gohr    if ($d['acl']) {
29047248316SAndreas Gohr        // create users.auth.php
29147248316SAndreas Gohr        // --- user:MD5password:Real Name:email:groups,comma,seperated
292f6e0e340SAndreas Gohr        $output = join(":",array($d['superuser'], md5($d['password']), $d['fullname'], $d['email'], 'admin,user'));
29347248316SAndreas Gohr        $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n";
29447248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output);
29547248316SAndreas Gohr
29647248316SAndreas Gohr        // create acl.auth.php
2978af2e4bbSAndreas Gohr        $output = <<<EOT
2988af2e4bbSAndreas Gohr# acl.auth.php
2998af2e4bbSAndreas Gohr# <?php exit()?>
3008af2e4bbSAndreas Gohr# Don't modify the lines above
3018af2e4bbSAndreas Gohr#
3028af2e4bbSAndreas Gohr# Access Control Lists
3038af2e4bbSAndreas Gohr#
3048af2e4bbSAndreas Gohr# Auto-generated by install script
3058af2e4bbSAndreas Gohr# Date: $now
3068af2e4bbSAndreas Gohr
3078af2e4bbSAndreas GohrEOT;
3088af2e4bbSAndreas Gohr        if($d['policy'] == 2){
3098af2e4bbSAndreas Gohr            $output .=  "*               @ALL          0\n";
3105c4260faSAndreas Gohr            $output .=  "*               @user         8\n";
3119c70688aSchris        }elseif($d['policy'] == 1){
3128af2e4bbSAndreas Gohr            $output .=  "*               @ALL          1\n";
3135c4260faSAndreas Gohr            $output .=  "*               @user         8\n";
3148af2e4bbSAndreas Gohr        }else{
3158af2e4bbSAndreas Gohr            $output .=  "*               @ALL          8\n";
3168af2e4bbSAndreas Gohr        }
31747248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output);
31847248316SAndreas Gohr    }
31947248316SAndreas Gohr    return $ok;
32047248316SAndreas Gohr}
32147248316SAndreas Gohr
32247248316SAndreas Gohr/**
32347248316SAndreas Gohr * Write the given content to a file
32447248316SAndreas Gohr *
32547248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
32647248316SAndreas Gohr */
32747248316SAndreas Gohrfunction fileWrite($filename, $data) {
32847248316SAndreas Gohr    global $error;
32947248316SAndreas Gohr    global $lang;
33047248316SAndreas Gohr
33147248316SAndreas Gohr    if (($fp = @fopen($filename, 'wb')) === false) {
33247248316SAndreas Gohr        $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
33347248316SAndreas Gohr        $error[]  = sprintf($lang['i_writeerr'],$filename);
33447248316SAndreas Gohr        return false;
33547248316SAndreas Gohr    }
33647248316SAndreas Gohr
33747248316SAndreas Gohr    if (!empty($data)) { fwrite($fp, $data);  }
33847248316SAndreas Gohr    fclose($fp);
33947248316SAndreas Gohr    return true;
34047248316SAndreas Gohr}
34147248316SAndreas Gohr
34247248316SAndreas Gohr
34347248316SAndreas Gohr/**
34447248316SAndreas Gohr * check installation dependent local config files and tests for a known
34547248316SAndreas Gohr * unmodified main config file
34647248316SAndreas Gohr *
34747248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
34847248316SAndreas Gohr */
34947248316SAndreas Gohrfunction check_configs(){
35047248316SAndreas Gohr    global $error;
35147248316SAndreas Gohr    global $lang;
35247248316SAndreas Gohr    global $dokuwiki_hash;
35347248316SAndreas Gohr
35447248316SAndreas Gohr    $ok = true;
35547248316SAndreas Gohr
3565cfb8815Schris    $config_files = array(
3575cfb8815Schris        'local' => DOKU_LOCAL.'local.php',
3585cfb8815Schris        'users' => DOKU_LOCAL.'users.auth.php',
3595cfb8815Schris        'auth'  => DOKU_LOCAL.'acl.auth.php'
3605cfb8815Schris    );
3615cfb8815Schris
3625cfb8815Schris
3635cfb8815Schris    // main dokuwiki config file (conf/dokuwiki.php) must not have been modified
364aa248fb5SAndreas Gohr    $installation_hash = md5(preg_replace("/(\015\012)|(\015)/","\012",
365aa248fb5SAndreas Gohr                             @file_get_contents(DOKU_CONF.'dokuwiki.php')));
3665cfb8815Schris    if (!in_array($installation_hash, $dokuwiki_hash)) {
36747248316SAndreas Gohr        $error[] = sprintf($lang['i_badhash'],$installation_hash);
36847248316SAndreas Gohr        $ok = false;
3695cfb8815Schris    }
3705cfb8815Schris
37147248316SAndreas Gohr    // configs shouldn't exist
37247248316SAndreas Gohr    foreach ($config_files as $file) {
37347248316SAndreas Gohr        if (@file_exists($file)) {
37447248316SAndreas Gohr            $file    = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
37547248316SAndreas Gohr            $error[] = sprintf($lang['i_confexists'],$file);
37647248316SAndreas Gohr            $ok      = false;
37747248316SAndreas Gohr        }
37847248316SAndreas Gohr    }
37947248316SAndreas Gohr    return $ok;
38047248316SAndreas Gohr}
38147248316SAndreas Gohr
38247248316SAndreas Gohr
38347248316SAndreas Gohr/**
38447248316SAndreas Gohr * Check other installation dir/file permission requirements
38547248316SAndreas Gohr *
38647248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
38747248316SAndreas Gohr */
38847248316SAndreas Gohrfunction check_permissions(){
38947248316SAndreas Gohr    global $error;
39047248316SAndreas Gohr    global $lang;
39147248316SAndreas Gohr
39247248316SAndreas Gohr    $dirs = array(
39347248316SAndreas Gohr        'conf'      => DOKU_LOCAL,
39447248316SAndreas Gohr        'data'      => DOKU_INC.'data',
39547248316SAndreas Gohr        'pages'     => DOKU_INC.'data/pages',
39647248316SAndreas Gohr        'attic'     => DOKU_INC.'data/attic',
39747248316SAndreas Gohr        'media'     => DOKU_INC.'data/media',
39847248316SAndreas Gohr        'meta'      => DOKU_INC.'data/meta',
39947248316SAndreas Gohr        'cache'     => DOKU_INC.'data/cache',
40047248316SAndreas Gohr        'locks'     => DOKU_INC.'data/locks',
4019711045aSAndreas Gohr        'index'     => DOKU_INC.'data/index',
402de33a58fSMichael Klier        'tmp'       => DOKU_INC.'data/tmp'
40347248316SAndreas Gohr    );
40447248316SAndreas Gohr
40547248316SAndreas Gohr    $ok = true;
40647248316SAndreas Gohr    foreach($dirs as $dir){
40747248316SAndreas Gohr        if(!@file_exists("$dir/.") || !@is_writable($dir)){
40870a6aa16Schris            $dir     = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
40947248316SAndreas Gohr            $error[] = sprintf($lang['i_permfail'],$dir);
41047248316SAndreas Gohr            $ok      = false;
41147248316SAndreas Gohr        }
41247248316SAndreas Gohr    }
41347248316SAndreas Gohr    return $ok;
41447248316SAndreas Gohr}
41547248316SAndreas Gohr
41647248316SAndreas Gohr/**
4173afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version
41847248316SAndreas Gohr *
41947248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
42047248316SAndreas Gohr */
42147248316SAndreas Gohrfunction check_functions(){
42247248316SAndreas Gohr    global $error;
42347248316SAndreas Gohr    global $lang;
4243afe5d1cSAndreas Gohr    $ok = true;
4253afe5d1cSAndreas Gohr
4263afe5d1cSAndreas Gohr    if(version_compare(phpversion(),'4.3.3','<')){
4273afe5d1cSAndreas Gohr        $error[] = sprintf($lang['i_phpver'],phpversion(),'4.3.3');
4283afe5d1cSAndreas Gohr        $ok = false;
4293afe5d1cSAndreas Gohr    }
4303afe5d1cSAndreas Gohr
43147248316SAndreas Gohr    $funcs = explode(' ','addslashes basename call_user_func chmod copy fgets '.
43247248316SAndreas Gohr                         'file file_exists fseek flush filesize ftell fopen '.
43347248316SAndreas Gohr                         'glob header ignore_user_abort ini_get mail mkdir '.
43447248316SAndreas Gohr                         'ob_start opendir parse_ini_file readfile realpath '.
435bab4a8bdSAndreas Gohr                         'rename rmdir serialize session_start unlink usleep '.
4367b407d6dSAndreas Gohr                         'preg_replace file_get_contents');
43747248316SAndreas Gohr
43870a6aa16Schris    if (!function_exists('mb_substr')) {
43970a6aa16Schris      $funcs[] = 'utf8_encode';
44070a6aa16Schris      $funcs[] = 'utf8_decode';
44170a6aa16Schris    }
44270a6aa16Schris
44347248316SAndreas Gohr    foreach($funcs as $func){
44447248316SAndreas Gohr        if(!function_exists($func)){
44547248316SAndreas Gohr            $error[] = sprintf($lang['i_funcna'],$func);
44647248316SAndreas Gohr            $ok = false;
44747248316SAndreas Gohr        }
44847248316SAndreas Gohr    }
44947248316SAndreas Gohr    return $ok;
45047248316SAndreas Gohr}
45147248316SAndreas Gohr
45247248316SAndreas Gohr/**
45347248316SAndreas Gohr * Print language selection
45447248316SAndreas Gohr *
45547248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
45647248316SAndreas Gohr */
45747248316SAndreas Gohrfunction langsel(){
45847248316SAndreas Gohr    global $lang;
45947248316SAndreas Gohr    global $LC;
46047248316SAndreas Gohr
46147248316SAndreas Gohr    $dir = DOKU_INC.'inc/lang';
46247248316SAndreas Gohr    $dh  = opendir($dir);
46347248316SAndreas Gohr    if(!$dh) return;
46447248316SAndreas Gohr
46547248316SAndreas Gohr    $langs = array();
46647248316SAndreas Gohr    while (($file = readdir($dh)) !== false) {
46747248316SAndreas Gohr        if(preg_match('/^[\._]/',$file)) continue;
46847248316SAndreas Gohr        if(is_dir($dir.'/'.$file) && @file_exists($dir.'/'.$file.'/lang.php')){
46947248316SAndreas Gohr            $langs[] = $file;
47047248316SAndreas Gohr        }
47147248316SAndreas Gohr    }
47247248316SAndreas Gohr    closedir($dh);
47347248316SAndreas Gohr    sort($langs);
47447248316SAndreas Gohr
47547248316SAndreas Gohr
47647248316SAndreas Gohr    echo '<form action="">';
47747248316SAndreas Gohr    echo $lang['i_chooselang'];
47847248316SAndreas Gohr    echo ': <select name="l" onchange="submit()">';
47947248316SAndreas Gohr    foreach($langs as $l){
48047248316SAndreas Gohr        $sel = ($l == $LC) ? 'selected="selected"' : '';
48147248316SAndreas Gohr        echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
48247248316SAndreas Gohr    }
48347248316SAndreas Gohr    echo '</select> ';
48447248316SAndreas Gohr    echo '<input type="submit" value="'.$lang['btn_update'].'" />';
48547248316SAndreas Gohr    echo '</form>';
48647248316SAndreas Gohr}
48747248316SAndreas Gohr
48847248316SAndreas Gohr/**
48947248316SAndreas Gohr * Print gloabl error array
49047248316SAndreas Gohr *
49147248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
49247248316SAndreas Gohr */
49347248316SAndreas Gohrfunction print_errors(){
49447248316SAndreas Gohr    global $error;
49547248316SAndreas Gohr    echo '<ul>';
49647248316SAndreas Gohr    foreach ($error as $err){
49747248316SAndreas Gohr        echo "<li>$err</li>";
49847248316SAndreas Gohr    }
49947248316SAndreas Gohr    echo '</ul>';
50047248316SAndreas Gohr}
5015cfb8815Schris
5025cfb8815Schris/**
5035cfb8815Schris * remove magic quotes recursivly
5045cfb8815Schris *
5055cfb8815Schris * @author Andreas Gohr <andi@splitbrain.org>
5065cfb8815Schris */
5075cfb8815Schrisfunction remove_magic_quotes(&$array) {
5085cfb8815Schris  foreach (array_keys($array) as $key) {
5095cfb8815Schris    if (is_array($array[$key])) {
5105cfb8815Schris      remove_magic_quotes($array[$key]);
5115cfb8815Schris    }else {
5125cfb8815Schris      $array[$key] = stripslashes($array[$key]);
5135cfb8815Schris    }
5145cfb8815Schris  }
5155cfb8815Schris}
5165cfb8815Schris
517