xref: /dokuwiki/install.php (revision 4b530faa88b9afb8467805a9dde8204b9b0bd9fa)
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
123791b589SAndreas Gohrrequire_once(DOKU_INC.'inc/PassHash.class.php');
133791b589SAndreas Gohr
143545b2e0Schris// check for error reporting override or set error reporting to sane values
153545b2e0Schrisif (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE); }
163545b2e0Schriselse { error_reporting(DOKU_E_LEVEL); }
173545b2e0Schris
1847248316SAndreas Gohr// kill magic quotes
1947248316SAndreas Gohrif (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) {
2047248316SAndreas Gohr    if (!empty($_GET))    remove_magic_quotes($_GET);
2147248316SAndreas Gohr    if (!empty($_POST))   remove_magic_quotes($_POST);
2247248316SAndreas Gohr    if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE);
2347248316SAndreas Gohr    if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST);
2447248316SAndreas Gohr    @ini_set('magic_quotes_gpc', 0);
2547248316SAndreas Gohr    define('MAGIC_QUOTES_STRIPPED',1);
2647248316SAndreas Gohr}
2747248316SAndreas Gohr@set_magic_quotes_runtime(0);
2847248316SAndreas Gohr@ini_set('magic_quotes_sybase',0);
295cfb8815Schris
3047248316SAndreas Gohr// language strings
3147248316SAndreas Gohrrequire_once(DOKU_INC.'inc/lang/en/lang.php');
32*4b530faaSTom N Harrisif(isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) {
3347248316SAndreas Gohr    $LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']);
34*4b530faaSTom N Harris}
35*4b530faaSTom N Harrisif(empty($LC)) $LC = 'en';
3647248316SAndreas Gohrif($LC && $LC != 'en' ) {
3747248316SAndreas Gohr    require_once(DOKU_INC.'inc/lang/'.$LC.'/lang.php');
3847248316SAndreas Gohr}
3947248316SAndreas Gohr
4047248316SAndreas Gohr// initialise variables ...
4147248316SAndreas Gohr$error = array();
4247248316SAndreas Gohr
4347248316SAndreas Gohr$dokuwiki_hash = array(
4447248316SAndreas Gohr    '2005-09-22'   => 'e33223e957b0b0a130d0520db08f8fb7',
4547248316SAndreas Gohr    '2006-03-05'   => '51295727f79ab9af309a2fd9e0b61acc',
4647248316SAndreas Gohr    '2006-03-09'   => '51295727f79ab9af309a2fd9e0b61acc',
474dde32ddSAndreas Gohr    '2006-11-06'   => 'b3a8af76845977c2000d85d6990dd72b',
48e7f137b2SAndreas Gohr    '2007-05-24'   => 'd80f2740c84c4a6a791fd3c7a353536f',
4983666c1bSAndreas Gohr    '2007-06-26'   => 'b3ca19c7a654823144119980be73cd77',
50dd6510bdSAndreas Gohr    '2008-05-04'   => '1e5c42eac3219d9e21927c39e3240aad',
51b4353e51SAndreas Gohr    '2009-02-14'   => 'ec8c04210732a14fdfce0f7f6eead865',
5285d9abfcSAndreas Gohr    '2009-12-25'   => '993c4b2b385643efe5abf8e7010e11f4',
53c991623aSAdrian Lang    '2010-11-07'   => '7921d48195f4db21b8ead6d9bea801b8',
545ff12737SAdrian Lang    '2011-05-25'   => '4241865472edb6fa14a1227721008072',
55a5a71ecfSAdrian Lang    '2011-11-10'   => 'b46ff19a7587966ac4df61cbab1b8b31',
565371328cSAndreas Gohr    '2012-01-25'   => '72c083c73608fc43c586901fd5dabb74',
573791b589SAndreas Gohr    'devel'        => 'eb0b3fc90056fbc12bac6f49f7764df3'
5847248316SAndreas Gohr);
5947248316SAndreas Gohr
6047248316SAndreas Gohr
6147248316SAndreas Gohr// begin output
6247248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8');
6347248316SAndreas Gohr?>
6447248316SAndreas Gohr<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
6547248316SAndreas Gohr "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6647248316SAndreas Gohr<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $LC?>"
6747248316SAndreas Gohr lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>">
6847248316SAndreas Gohr<head>
6947248316SAndreas Gohr    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
704208c142SAndreas Gohr    <title><?php echo $lang['i_installer']?></title>
7147248316SAndreas Gohr    <style type="text/css">
7247248316SAndreas Gohr        body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; }
7347248316SAndreas Gohr        img { border: none }
7447248316SAndreas Gohr        br.cl { clear:both; }
7570a6aa16Schris        code { font-size: 110%; color: #800000; }
7647248316SAndreas Gohr        fieldset { border: none }
779c70688aSchris        label { display: block; margin-top: 0.5em; }
788af2e4bbSAndreas Gohr        select.text, input.text { width: 30em; margin: 0 0.5em; }
7906361442SAndreas Gohr        a {text-decoration: none}
8047248316SAndreas Gohr    </style>
8147248316SAndreas Gohr    <script type="text/javascript" language="javascript">
8247248316SAndreas Gohr        function acltoggle(){
8347248316SAndreas Gohr            var cb = document.getElementById('acl');
8447248316SAndreas Gohr            var fs = document.getElementById('acldep');
8547248316SAndreas Gohr            if(!cb || !fs) return;
8647248316SAndreas Gohr            if(cb.checked){
8747248316SAndreas Gohr                fs.style.display = '';
8847248316SAndreas Gohr            }else{
8947248316SAndreas Gohr                fs.style.display = 'none';
9047248316SAndreas Gohr            }
9147248316SAndreas Gohr        }
9247248316SAndreas Gohr        window.onload = function(){
9347248316SAndreas Gohr            acltoggle();
9447248316SAndreas Gohr            var cb = document.getElementById('acl');
9547248316SAndreas Gohr            if(cb) cb.onchange = acltoggle;
9647248316SAndreas Gohr        };
9747248316SAndreas Gohr    </script>
9847248316SAndreas Gohr</head>
9947248316SAndreas Gohr<body style="">
10047248316SAndreas Gohr    <h1 style="float:left">
1012e79fc15SAnika Henke        <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png&w=64"
10247248316SAndreas Gohr             style="vertical-align: middle;" alt="" />
10347248316SAndreas Gohr        <?php echo $lang['i_installer']?>
10447248316SAndreas Gohr    </h1>
10547248316SAndreas Gohr    <div style="float:right; margin: 1em;">
10647248316SAndreas Gohr        <?php langsel()?>
10747248316SAndreas Gohr    </div>
10847248316SAndreas Gohr    <br class="cl" />
10947248316SAndreas Gohr
11047248316SAndreas Gohr    <div style="float: right; width: 34%;">
11147248316SAndreas Gohr        <?php
11247248316SAndreas Gohr            if(@file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){
11347248316SAndreas Gohr                include(DOKU_INC.'inc/lang/'.$LC.'/install.html');
11447248316SAndreas Gohr            }else{
115ca64d724Schris                print "<div lang=\"en\" dir=\"ltr\">\n";
11647248316SAndreas Gohr                include(DOKU_INC.'inc/lang/en/install.html');
117ca64d724Schris                print "</div>\n";
11847248316SAndreas Gohr            }
11947248316SAndreas Gohr        ?>
120c8b43921SAndreas Gohr        <a style="background: transparent url(data/security.png) left top no-repeat;
121c8b43921SAndreas Gohr                  display: block; width:380px; height:73px; border:none; clear:both;"
122c8b43921SAndreas Gohr           target="_blank"
123c8b43921SAndreas Gohr           href="http://www.dokuwiki.org/security#web_access_security"></a>
12447248316SAndreas Gohr    </div>
12547248316SAndreas Gohr
12647248316SAndreas Gohr    <div style="float: left; width: 58%;">
12747248316SAndreas Gohr        <?php
12847248316SAndreas Gohr            if(! (check_functions() && check_permissions()) ){
12947248316SAndreas Gohr                echo '<p>'.$lang['i_problems'].'</p>';
13047248316SAndreas Gohr                print_errors();
13170a6aa16Schris                print_retry();
13247248316SAndreas Gohr            }elseif(!check_configs()){
13347248316SAndreas Gohr                echo '<p>'.$lang['i_modified'].'</p>';
13447248316SAndreas Gohr                print_errors();
135*4b530faaSTom N Harris            }elseif(check_data($_REQUEST['d'])){
136*4b530faaSTom N Harris                // check_data has sanitized all input parameters
137*4b530faaSTom N Harris                if(!store_data($_REQUEST['d'])){
13847248316SAndreas Gohr                    echo '<p>'.$lang['i_failure'].'</p>';
13947248316SAndreas Gohr                    print_errors();
14047248316SAndreas Gohr                }else{
14147248316SAndreas Gohr                    echo '<p>'.$lang['i_success'].'</p>';
14247248316SAndreas Gohr                }
14347248316SAndreas Gohr            }else{
144*4b530faaSTom N Harris                print_errors();
14547248316SAndreas Gohr                print_form($_REQUEST['d']);
14647248316SAndreas Gohr            }
14747248316SAndreas Gohr        ?>
14847248316SAndreas Gohr    </div>
14947248316SAndreas Gohr
150c8b43921SAndreas Gohr
15147248316SAndreas Gohr<div style="clear: both">
152f46c9e83SAnika Henke  <a href="http://dokuwiki.org/"><img src="lib/tpl/default/images/button-dw.png" alt="driven by DokuWiki" /></a>
15347248316SAndreas Gohr  <a href="http://www.php.net"><img src="lib/tpl/default/images/button-php.gif" alt="powered by PHP" /></a>
15447248316SAndreas Gohr</div>
15547248316SAndreas Gohr</body>
15647248316SAndreas Gohr</html>
15747248316SAndreas Gohr<?php
15847248316SAndreas Gohr
15947248316SAndreas Gohr/**
16047248316SAndreas Gohr * Print the input form
16147248316SAndreas Gohr */
16247248316SAndreas Gohrfunction print_form($d){
16347248316SAndreas Gohr    global $lang;
16447248316SAndreas Gohr    global $LC;
16547248316SAndreas Gohr
16606361442SAndreas Gohr    include(DOKU_CONF.'license.php');
16706361442SAndreas Gohr
16847248316SAndreas Gohr    if(!is_array($d)) $d = array();
16947248316SAndreas Gohr    $d = array_map('htmlspecialchars',$d);
17047248316SAndreas Gohr
17147248316SAndreas Gohr    if(!isset($d['acl'])) $d['acl']=1;
17247248316SAndreas Gohr
17347248316SAndreas Gohr    ?>
17447248316SAndreas Gohr    <form action="" method="post">
17547248316SAndreas Gohr    <input type="hidden" name="l" value="<?php echo $LC ?>" />
17647248316SAndreas Gohr    <fieldset>
17747248316SAndreas Gohr        <label for="title"><?php echo $lang['i_wikiname']?>
17847248316SAndreas Gohr        <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" />
17947248316SAndreas Gohr        </label>
18047248316SAndreas Gohr
18147248316SAndreas Gohr        <fieldset style="margin-top: 1em;">
18247248316SAndreas Gohr            <label for="acl">
18347248316SAndreas Gohr            <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? 'checked="checked"' : ''));?> />
18447248316SAndreas Gohr            <?php echo $lang['i_enableacl']?></label>
18547248316SAndreas Gohr
18647248316SAndreas Gohr            <fieldset id="acldep">
18747248316SAndreas Gohr                <label for="superuser"><?php echo $lang['i_superuser']?></label>
18847248316SAndreas Gohr                <input class="text" type="text" name="d[superuser]" id="superuser" value="<?php echo $d['superuser'] ?>" />
18947248316SAndreas Gohr
19047248316SAndreas Gohr                <label for="fullname"><?php echo $lang['fullname']?></label>
19147248316SAndreas Gohr                <input class="text" type="text" name="d[fullname]" id="fullname" value="<?php echo $d['fullname'] ?>" />
19247248316SAndreas Gohr
19347248316SAndreas Gohr                <label for="email"><?php echo $lang['email']?></label>
19447248316SAndreas Gohr                <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" />
19547248316SAndreas Gohr
19647248316SAndreas Gohr                <label for="password"><?php echo $lang['pass']?></label>
19747248316SAndreas Gohr                <input class="text" type="password" name="d[password]" id="password" />
19847248316SAndreas Gohr
19947248316SAndreas Gohr                <label for="confirm"><?php echo $lang['passchk']?></label>
20047248316SAndreas Gohr                <input class="text" type="password" name="d[confirm]" id="confirm" />
2018af2e4bbSAndreas Gohr
2028af2e4bbSAndreas Gohr                <label for="policy"><?php echo $lang['i_policy']?></label>
2038af2e4bbSAndreas Gohr                <select class="text" name="d[policy]" id="policy">
2048af2e4bbSAndreas Gohr                    <option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php echo $lang['i_pol0']?></option>
2058af2e4bbSAndreas Gohr                    <option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php echo $lang['i_pol1']?></option>
2068af2e4bbSAndreas Gohr                    <option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php echo $lang['i_pol2']?></option>
2078af2e4bbSAndreas Gohr                </select>
20806361442SAndreas Gohr
20947248316SAndreas Gohr            </fieldset>
21047248316SAndreas Gohr        </fieldset>
21147248316SAndreas Gohr
21206361442SAndreas Gohr        <fieldset>
21306361442SAndreas Gohr            <p><?php echo $lang['i_license']?></p>
21406361442SAndreas Gohr            <?php
21506361442SAndreas Gohr            array_unshift($license,array('name' => 'None', 'url'=>''));
21606361442SAndreas Gohr            if(!isset($d['license'])) $d['license'] = 'cc-by-sa';
21706361442SAndreas Gohr            foreach($license as $key => $lic){
21806361442SAndreas Gohr                echo '<label for="lic_'.$key.'">';
21906361442SAndreas Gohr                echo '<input type="radio" name="d[license]" value="'.htmlspecialchars($key).'" id="lic_'.$key.'"'.
22006361442SAndreas Gohr                     (($d['license'] == $key)?'checked="checked"':'').'>';
22106361442SAndreas Gohr                echo htmlspecialchars($lic['name']);
22206361442SAndreas Gohr                if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>';
22306361442SAndreas Gohr                echo '</label>';
22406361442SAndreas Gohr            }
22506361442SAndreas Gohr            ?>
22606361442SAndreas Gohr        </fieldset>
22706361442SAndreas Gohr
22847248316SAndreas Gohr    </fieldset>
22947248316SAndreas Gohr    <fieldset id="process">
23047248316SAndreas Gohr        <input class="button" type="submit" name="submit" value="<?php echo $lang['btn_save']?>" />
23147248316SAndreas Gohr    </fieldset>
23247248316SAndreas Gohr    </form>
23347248316SAndreas Gohr    <?php
23447248316SAndreas Gohr}
23547248316SAndreas Gohr
23670a6aa16Schrisfunction print_retry() {
23770a6aa16Schris    global $lang;
2389ad6da3dSAndreas Gohr    global $LC;
23970a6aa16Schris    ?>
24070a6aa16Schris    <form action="" method="get">
24170a6aa16Schris      <fieldset>
2429ad6da3dSAndreas Gohr        <input type="hidden" name="l" value="<?php echo $LC ?>" />
24370a6aa16Schris        <input class="button" type="submit" value="<?php echo $lang['i_retry'];?>" />
24470a6aa16Schris      </fieldset>
24570a6aa16Schris    </form>
24670a6aa16Schris    <?php
24770a6aa16Schris}
24870a6aa16Schris
24947248316SAndreas Gohr/**
25047248316SAndreas Gohr * Check validity of data
25147248316SAndreas Gohr *
25247248316SAndreas Gohr * @author Andreas Gohr
25347248316SAndreas Gohr */
254e2386079SAndreas Gohrfunction check_data(&$d){
255*4b530faaSTom N Harris    static $form_default = array(
256*4b530faaSTom N Harris        'title'     => '',
257*4b530faaSTom N Harris        'acl'       => '0',
258*4b530faaSTom N Harris        'superuser' => '',
259*4b530faaSTom N Harris        'fullname'  => '',
260*4b530faaSTom N Harris        'email'     => '',
261*4b530faaSTom N Harris        'password'  => '',
262*4b530faaSTom N Harris        'confirm'   => '',
263*4b530faaSTom N Harris        'policy'    => '0',
264*4b530faaSTom N Harris        'license'   => 'cc-by-sa'
265*4b530faaSTom N Harris    );
26647248316SAndreas Gohr    global $lang;
26747248316SAndreas Gohr    global $error;
26847248316SAndreas Gohr
269*4b530faaSTom N Harris    if(!is_array($d)) $d = array();
270*4b530faaSTom N Harris    foreach($d as $k => $v) {
271*4b530faaSTom N Harris        if(is_array($v))
272*4b530faaSTom N Harris            unset($d[$k]);
273*4b530faaSTom N Harris        else
274*4b530faaSTom N Harris            $d[$k] = (string)$v;
275*4b530faaSTom N Harris    }
276e2386079SAndreas Gohr
277*4b530faaSTom N Harris    //autolowercase the username
278*4b530faaSTom N Harris    $d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : "";
279*4b530faaSTom N Harris
280*4b530faaSTom N Harris    $ok = false;
281*4b530faaSTom N Harris
282*4b530faaSTom N Harris    if(isset($_REQUEST['submit'])) {
28347248316SAndreas Gohr        $ok = true;
28447248316SAndreas Gohr
28547248316SAndreas Gohr        // check input
28647248316SAndreas Gohr        if(empty($d['title'])){
28747248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
28847248316SAndreas Gohr            $ok      = false;
28947248316SAndreas Gohr        }
290*4b530faaSTom N Harris        if(isset($d['acl'])){
291d60813a2SGina Haeussge            if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){
29247248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
29347248316SAndreas Gohr                $ok      = false;
29447248316SAndreas Gohr            }
29547248316SAndreas Gohr            if(empty($d['password'])){
29647248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['pass']);
29747248316SAndreas Gohr                $ok      = false;
29847248316SAndreas Gohr            }
299*4b530faaSTom N Harris            elseif(!isset($d['confirm']) || $d['confirm'] != $d['password']){
30047248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['passchk']);
30147248316SAndreas Gohr                $ok      = false;
30247248316SAndreas Gohr            }
30347248316SAndreas Gohr            if(empty($d['fullname']) || strstr($d['fullname'],':')){
30447248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['fullname']);
30547248316SAndreas Gohr                $ok      = false;
30647248316SAndreas Gohr            }
307e2386079SAndreas Gohr            if(empty($d['email']) || strstr($d['email'],':') || !strstr($d['email'],'@')){
30847248316SAndreas Gohr                $error[] = sprintf($lang['i_badval'],$lang['email']);
30947248316SAndreas Gohr                $ok      = false;
31047248316SAndreas Gohr            }
31147248316SAndreas Gohr        }
312*4b530faaSTom N Harris    }
313*4b530faaSTom N Harris    $d = array_merge($form_default, $d);
31447248316SAndreas Gohr    return $ok;
31547248316SAndreas Gohr}
31647248316SAndreas Gohr
31747248316SAndreas Gohr/**
31847248316SAndreas Gohr * Writes the data to the config files
31947248316SAndreas Gohr *
32047248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
32147248316SAndreas Gohr */
32247248316SAndreas Gohrfunction store_data($d){
3230036aa89SAndreas Gohr    global $LC;
32447248316SAndreas Gohr    $ok = true;
3258af2e4bbSAndreas Gohr    $d['policy'] = (int) $d['policy'];
32647248316SAndreas Gohr
32747248316SAndreas Gohr    // create local.php
32824650a19SAndreas Gohr    $now    = gmdate('r');
32947248316SAndreas Gohr    $output = <<<EOT
33047248316SAndreas Gohr<?php
33147248316SAndreas Gohr/**
33247248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings
33347248316SAndreas Gohr * Auto-generated by install script
33447248316SAndreas Gohr * Date: $now
33547248316SAndreas Gohr */
33647248316SAndreas Gohr
33747248316SAndreas GohrEOT;
33847248316SAndreas Gohr    $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
3390036aa89SAndreas Gohr    $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
34006361442SAndreas Gohr    $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n";
34147248316SAndreas Gohr    if($d['acl']){
34247248316SAndreas Gohr        $output .= '$conf[\'useacl\'] = 1'.";\n";
343523d7ea6Schris        $output .= "\$conf['superuser'] = '@admin';\n";
34447248316SAndreas Gohr    }
34547248316SAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output);
34647248316SAndreas Gohr
34747248316SAndreas Gohr    if ($d['acl']) {
3483791b589SAndreas Gohr        // hash the password
3493791b589SAndreas Gohr        $phash = new PassHash();
3503791b589SAndreas Gohr        $pass = $phash->hash_smd5($d['password']);
3513791b589SAndreas Gohr
35247248316SAndreas Gohr        // create users.auth.php
3533791b589SAndreas Gohr        // --- user:SMD5password:Real Name:email:groups,comma,seperated
3543791b589SAndreas Gohr        $output = join(":",array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user'));
35547248316SAndreas Gohr        $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n";
35647248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output);
35747248316SAndreas Gohr
35847248316SAndreas Gohr        // create acl.auth.php
3598af2e4bbSAndreas Gohr        $output = <<<EOT
3608af2e4bbSAndreas Gohr# acl.auth.php
3618af2e4bbSAndreas Gohr# <?php exit()?>
3628af2e4bbSAndreas Gohr# Don't modify the lines above
3638af2e4bbSAndreas Gohr#
3648af2e4bbSAndreas Gohr# Access Control Lists
3658af2e4bbSAndreas Gohr#
3668af2e4bbSAndreas Gohr# Auto-generated by install script
3678af2e4bbSAndreas Gohr# Date: $now
3688af2e4bbSAndreas Gohr
3698af2e4bbSAndreas GohrEOT;
3708af2e4bbSAndreas Gohr        if($d['policy'] == 2){
3718af2e4bbSAndreas Gohr            $output .=  "*               @ALL          0\n";
3725c4260faSAndreas Gohr            $output .=  "*               @user         8\n";
3739c70688aSchris        }elseif($d['policy'] == 1){
3748af2e4bbSAndreas Gohr            $output .=  "*               @ALL          1\n";
3755c4260faSAndreas Gohr            $output .=  "*               @user         8\n";
3768af2e4bbSAndreas Gohr        }else{
3778af2e4bbSAndreas Gohr            $output .=  "*               @ALL          8\n";
3788af2e4bbSAndreas Gohr        }
37947248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output);
38047248316SAndreas Gohr    }
38147248316SAndreas Gohr    return $ok;
38247248316SAndreas Gohr}
38347248316SAndreas Gohr
38447248316SAndreas Gohr/**
38547248316SAndreas Gohr * Write the given content to a file
38647248316SAndreas Gohr *
38747248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
38847248316SAndreas Gohr */
38947248316SAndreas Gohrfunction fileWrite($filename, $data) {
39047248316SAndreas Gohr    global $error;
39147248316SAndreas Gohr    global $lang;
39247248316SAndreas Gohr
39347248316SAndreas Gohr    if (($fp = @fopen($filename, 'wb')) === false) {
39447248316SAndreas Gohr        $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
39547248316SAndreas Gohr        $error[]  = sprintf($lang['i_writeerr'],$filename);
39647248316SAndreas Gohr        return false;
39747248316SAndreas Gohr    }
39847248316SAndreas Gohr
39947248316SAndreas Gohr    if (!empty($data)) { fwrite($fp, $data);  }
40047248316SAndreas Gohr    fclose($fp);
40147248316SAndreas Gohr    return true;
40247248316SAndreas Gohr}
40347248316SAndreas Gohr
40447248316SAndreas Gohr
40547248316SAndreas Gohr/**
40647248316SAndreas Gohr * check installation dependent local config files and tests for a known
40747248316SAndreas Gohr * unmodified main config file
40847248316SAndreas Gohr *
40947248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
41047248316SAndreas Gohr */
41147248316SAndreas Gohrfunction check_configs(){
41247248316SAndreas Gohr    global $error;
41347248316SAndreas Gohr    global $lang;
41447248316SAndreas Gohr    global $dokuwiki_hash;
41547248316SAndreas Gohr
41647248316SAndreas Gohr    $ok = true;
41747248316SAndreas Gohr
4185cfb8815Schris    $config_files = array(
4195cfb8815Schris        'local' => DOKU_LOCAL.'local.php',
4205cfb8815Schris        'users' => DOKU_LOCAL.'users.auth.php',
4215cfb8815Schris        'auth'  => DOKU_LOCAL.'acl.auth.php'
4225cfb8815Schris    );
4235cfb8815Schris
4245cfb8815Schris    // main dokuwiki config file (conf/dokuwiki.php) must not have been modified
425aa248fb5SAndreas Gohr    $installation_hash = md5(preg_replace("/(\015\012)|(\015)/","\012",
426aa248fb5SAndreas Gohr                             @file_get_contents(DOKU_CONF.'dokuwiki.php')));
4275cfb8815Schris    if (!in_array($installation_hash, $dokuwiki_hash)) {
42847248316SAndreas Gohr        $error[] = sprintf($lang['i_badhash'],$installation_hash);
42947248316SAndreas Gohr        $ok = false;
4305cfb8815Schris    }
4315cfb8815Schris
43247248316SAndreas Gohr    // configs shouldn't exist
43347248316SAndreas Gohr    foreach ($config_files as $file) {
43447248316SAndreas Gohr        if (@file_exists($file)) {
43547248316SAndreas Gohr            $file    = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
43647248316SAndreas Gohr            $error[] = sprintf($lang['i_confexists'],$file);
43747248316SAndreas Gohr            $ok      = false;
43847248316SAndreas Gohr        }
43947248316SAndreas Gohr    }
44047248316SAndreas Gohr    return $ok;
44147248316SAndreas Gohr}
44247248316SAndreas Gohr
44347248316SAndreas Gohr
44447248316SAndreas Gohr/**
44547248316SAndreas Gohr * Check other installation dir/file permission requirements
44647248316SAndreas Gohr *
44747248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
44847248316SAndreas Gohr */
44947248316SAndreas Gohrfunction check_permissions(){
45047248316SAndreas Gohr    global $error;
45147248316SAndreas Gohr    global $lang;
45247248316SAndreas Gohr
45347248316SAndreas Gohr    $dirs = array(
45447248316SAndreas Gohr        'conf'        => DOKU_LOCAL,
45547248316SAndreas Gohr        'data'        => DOKU_INC.'data',
45647248316SAndreas Gohr        'pages'       => DOKU_INC.'data/pages',
45747248316SAndreas Gohr        'attic'       => DOKU_INC.'data/attic',
45847248316SAndreas Gohr        'media'       => DOKU_INC.'data/media',
45949b78edaSAndreas Gohr        'media_attic' => DOKU_INC.'data/media_attic',
46049b78edaSAndreas Gohr        'media_meta'  => DOKU_INC.'data/media_meta',
46147248316SAndreas Gohr        'meta'        => DOKU_INC.'data/meta',
46247248316SAndreas Gohr        'cache'       => DOKU_INC.'data/cache',
46347248316SAndreas Gohr        'locks'       => DOKU_INC.'data/locks',
4649711045aSAndreas Gohr        'index'       => DOKU_INC.'data/index',
465de33a58fSMichael Klier        'tmp'         => DOKU_INC.'data/tmp'
46647248316SAndreas Gohr    );
46747248316SAndreas Gohr
46847248316SAndreas Gohr    $ok = true;
46947248316SAndreas Gohr    foreach($dirs as $dir){
47047248316SAndreas Gohr        if(!@file_exists("$dir/.") || !@is_writable($dir)){
47170a6aa16Schris            $dir     = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
47247248316SAndreas Gohr            $error[] = sprintf($lang['i_permfail'],$dir);
47347248316SAndreas Gohr            $ok      = false;
47447248316SAndreas Gohr        }
47547248316SAndreas Gohr    }
47647248316SAndreas Gohr    return $ok;
47747248316SAndreas Gohr}
47847248316SAndreas Gohr
47947248316SAndreas Gohr/**
4803afe5d1cSAndreas Gohr * Check the availability of functions used in DokuWiki and the PHP version
48147248316SAndreas Gohr *
48247248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
48347248316SAndreas Gohr */
48447248316SAndreas Gohrfunction check_functions(){
48547248316SAndreas Gohr    global $error;
48647248316SAndreas Gohr    global $lang;
4873afe5d1cSAndreas Gohr    $ok = true;
4883afe5d1cSAndreas Gohr
489ab91da89SAndreas Gohr    if(version_compare(phpversion(),'5.1.2','<')){
490ab91da89SAndreas Gohr        $error[] = sprintf($lang['i_phpver'],phpversion(),'5.1.2');
4913afe5d1cSAndreas Gohr        $ok = false;
4923afe5d1cSAndreas Gohr    }
4933afe5d1cSAndreas Gohr
49447248316SAndreas Gohr    $funcs = explode(' ','addslashes basename call_user_func chmod copy fgets '.
49547248316SAndreas Gohr                         'file file_exists fseek flush filesize ftell fopen '.
49647248316SAndreas Gohr                         'glob header ignore_user_abort ini_get mail mkdir '.
49747248316SAndreas Gohr                         'ob_start opendir parse_ini_file readfile realpath '.
498bab4a8bdSAndreas Gohr                         'rename rmdir serialize session_start unlink usleep '.
499d1d99bb9SAndreas Gohr                         'preg_replace file_get_contents htmlspecialchars_decode '.
500f774b92aSAndreas Gohr                         'spl_autoload_register stream_select fsockopen');
50147248316SAndreas Gohr
50270a6aa16Schris    if (!function_exists('mb_substr')) {
50370a6aa16Schris        $funcs[] = 'utf8_encode';
50470a6aa16Schris        $funcs[] = 'utf8_decode';
50570a6aa16Schris    }
50670a6aa16Schris
50747248316SAndreas Gohr    foreach($funcs as $func){
50847248316SAndreas Gohr        if(!function_exists($func)){
50947248316SAndreas Gohr            $error[] = sprintf($lang['i_funcna'],$func);
51047248316SAndreas Gohr            $ok = false;
51147248316SAndreas Gohr        }
51247248316SAndreas Gohr    }
51347248316SAndreas Gohr    return $ok;
51447248316SAndreas Gohr}
51547248316SAndreas Gohr
51647248316SAndreas Gohr/**
51747248316SAndreas Gohr * Print language selection
51847248316SAndreas Gohr *
51947248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
52047248316SAndreas Gohr */
52147248316SAndreas Gohrfunction langsel(){
52247248316SAndreas Gohr    global $lang;
52347248316SAndreas Gohr    global $LC;
52447248316SAndreas Gohr
52547248316SAndreas Gohr    $dir = DOKU_INC.'inc/lang';
52647248316SAndreas Gohr    $dh  = opendir($dir);
52747248316SAndreas Gohr    if(!$dh) return;
52847248316SAndreas Gohr
52947248316SAndreas Gohr    $langs = array();
53047248316SAndreas Gohr    while (($file = readdir($dh)) !== false) {
53147248316SAndreas Gohr        if(preg_match('/^[\._]/',$file)) continue;
53247248316SAndreas Gohr        if(is_dir($dir.'/'.$file) && @file_exists($dir.'/'.$file.'/lang.php')){
53347248316SAndreas Gohr            $langs[] = $file;
53447248316SAndreas Gohr        }
53547248316SAndreas Gohr    }
53647248316SAndreas Gohr    closedir($dh);
53747248316SAndreas Gohr    sort($langs);
53847248316SAndreas Gohr
53947248316SAndreas Gohr    echo '<form action="">';
54047248316SAndreas Gohr    echo $lang['i_chooselang'];
54147248316SAndreas Gohr    echo ': <select name="l" onchange="submit()">';
54247248316SAndreas Gohr    foreach($langs as $l){
54347248316SAndreas Gohr        $sel = ($l == $LC) ? 'selected="selected"' : '';
54447248316SAndreas Gohr        echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
54547248316SAndreas Gohr    }
54647248316SAndreas Gohr    echo '</select> ';
54747248316SAndreas Gohr    echo '<input type="submit" value="'.$lang['btn_update'].'" />';
54847248316SAndreas Gohr    echo '</form>';
54947248316SAndreas Gohr}
55047248316SAndreas Gohr
55147248316SAndreas Gohr/**
552c66972f2SAdrian Lang * Print global error array
55347248316SAndreas Gohr *
55447248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
55547248316SAndreas Gohr */
55647248316SAndreas Gohrfunction print_errors(){
55747248316SAndreas Gohr    global $error;
558*4b530faaSTom N Harris    if(!empty($error)) {
55947248316SAndreas Gohr        echo '<ul>';
56047248316SAndreas Gohr        foreach ($error as $err){
56147248316SAndreas Gohr            echo "<li>$err</li>";
56247248316SAndreas Gohr        }
56347248316SAndreas Gohr        echo '</ul>';
56447248316SAndreas Gohr    }
565*4b530faaSTom N Harris}
5665cfb8815Schris
5675cfb8815Schris/**
5685cfb8815Schris * remove magic quotes recursivly
5695cfb8815Schris *
5705cfb8815Schris * @author Andreas Gohr <andi@splitbrain.org>
5715cfb8815Schris */
5725cfb8815Schrisfunction remove_magic_quotes(&$array) {
5735cfb8815Schris    foreach (array_keys($array) as $key) {
5745cfb8815Schris        if (is_array($array[$key])) {
5755cfb8815Schris            remove_magic_quotes($array[$key]);
5765cfb8815Schris        }else {
5775cfb8815Schris            $array[$key] = stripslashes($array[$key]);
5785cfb8815Schris        }
5795cfb8815Schris    }
5805cfb8815Schris}
5815cfb8815Schris
582