3 * Dokuwiki installation assistance
5 * @author Chris Smith <chris@jalakai.co.uk>
8 if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__
).'/');
9 if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC
.'conf/');
10 if(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC
.'conf/');
12 require_once(DOKU_INC
.'inc/PassHash.class.php');
14 // check for error reporting override or set error reporting to sane values
15 if (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE
); }
16 else { error_reporting(DOKU_E_LEVEL
); }
19 if (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) {
20 if (!empty($_GET)) remove_magic_quotes($_GET);
21 if (!empty($_POST)) remove_magic_quotes($_POST);
22 if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE);
23 if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST);
24 @ini_set
('magic_quotes_gpc', 0);
25 define('MAGIC_QUOTES_STRIPPED',1);
27 if (function_exists('set_magic_quotes_runtime')) @set_magic_quotes_runtime
(0);
28 @ini_set
('magic_quotes_sybase',0);
31 require_once(DOKU_INC
.'inc/lang/en/lang.php');
32 if(isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) {
33 $LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']);
35 if(empty($LC)) $LC = 'en';
36 if($LC && $LC != 'en' ) {
37 require_once(DOKU_INC
.'inc/lang/'.$LC.'/lang.php');
40 // initialise variables ...
43 $dokuwiki_hash = array(
44 '2005-09-22' => 'e33223e957b0b0a130d0520db08f8fb7',
45 '2006-03-05' => '51295727f79ab9af309a2fd9e0b61acc',
46 '2006-03-09' => '51295727f79ab9af309a2fd9e0b61acc',
47 '2006-11-06' => 'b3a8af76845977c2000d85d6990dd72b',
48 '2007-05-24' => 'd80f2740c84c4a6a791fd3c7a353536f',
49 '2007-06-26' => 'b3ca19c7a654823144119980be73cd77',
50 '2008-05-04' => '1e5c42eac3219d9e21927c39e3240aad',
51 '2009-02-14' => 'ec8c04210732a14fdfce0f7f6eead865',
52 '2009-12-25' => '993c4b2b385643efe5abf8e7010e11f4',
53 '2010-11-07' => '7921d48195f4db21b8ead6d9bea801b8',
54 '2011-05-25' => '4241865472edb6fa14a1227721008072',
55 '2011-11-10' => 'b46ff19a7587966ac4df61cbab1b8b31',
56 '2012-01-25' => '72c083c73608fc43c586901fd5dabb74',
57 '2012-09-10' => 'eb0b3fc90056fbc12bac6f49f7764df3'
62 header('Content-Type: text/html; charset=utf-8');
65 <html lang
="<?php echo $LC?>" dir
="<?php echo $lang['direction']?>">
67 <meta charset
="utf-8" />
68 <title
><?php
echo $lang['i_installer']?
></title
>
69 <style type
="text/css">
70 body
{ width
: 90%
; margin
: 0 auto
; font
: 84% Verdana
, Helvetica
, Arial
, sans
-serif
; }
73 code
{ font
-size
: 110%
; color
: #800000; }
74 fieldset
{ border
: none
}
75 label
{ display
: block
; margin
-top
: 0.5em
; }
76 select
.text
, input
.text
{ width
: 30em
; margin
: 0 0.5em
; }
77 a
{text
-decoration
: none
}
79 <script type
="text/javascript">
81 var cb
= document
.getElementById('acl');
82 var fs
= document
.getElementById('acldep');
83 if(!cb ||
!fs
) return;
85 fs
.style
.display
= '';
87 fs
.style
.display
= 'none';
90 window
.onload
= function(){
92 var cb
= document
.getElementById('acl');
93 if(cb
) cb
.onchange
= acltoggle
;
98 <h1 style
="float:left">
99 <img src
="lib/exe/fetch.php?media=wiki:dokuwiki-128.png&w=64"
100 style
="vertical-align: middle;" alt
="" />
101 <?php
echo $lang['i_installer']?
>
103 <div style
="float:right; margin: 1em;">
108 <div style
="float: right; width: 34%;">
110 if(@file_exists
(DOKU_INC
.'inc/lang/'.$LC.'/install.html')){
111 include(DOKU_INC
.'inc/lang/'.$LC.'/install.html');
113 print "<div lang=\"en\" dir=\"ltr\">\n";
114 include(DOKU_INC
.'inc/lang/en/install.html');
118 <a style
="background: transparent url(data/security.png) left top no-repeat;
119 display: block; width:380px; height:73px; border:none; clear:both;"
121 href
="http://www.dokuwiki.org/security#web_access_security"></a
>
124 <div style
="float: left; width: 58%;">
126 if(! (check_functions() && check_permissions()) ){
127 echo '<p>'.$lang['i_problems'].'</p>';
130 }elseif(!check_configs()){
131 echo '<p>'.$lang['i_modified'].'</p>';
133 }elseif(check_data($_REQUEST['d'])){
134 // check_data has sanitized all input parameters
135 if(!store_data($_REQUEST['d'])){
136 echo '<p>'.$lang['i_failure'].'</p>';
139 echo '<p>'.$lang['i_success'].'</p>';
143 print_form($_REQUEST['d']);
149 <div style
="clear: both">
150 <a href
="http://dokuwiki.org/"><img src
="lib/tpl/default/images/button-dw.png" alt
="driven by DokuWiki" /></a
>
151 <a href
="http://www.php.net"><img src
="lib/tpl/default/images/button-php.gif" alt
="powered by PHP" /></a
>
158 * Print the input form
160 function print_form($d){
164 include(DOKU_CONF
.'license.php');
166 if(!is_array($d)) $d = array();
167 $d = array_map('htmlspecialchars',$d);
169 if(!isset($d['acl'])) $d['acl']=1;
170 if(!isset($d['pop'])) $d['pop']=1;
173 <form action
="" method
="post">
174 <input type
="hidden" name
="l" value
="<?php echo $LC ?>" />
176 <label
for="title"><?php
echo $lang['i_wikiname']?
>
177 <input type
="text" name
="d[title]" id
="title" value
="<?php echo $d['title'] ?>" style
="width: 20em;" />
180 <fieldset style
="margin-top: 1em;">
182 <input type
="checkbox" name
="d[acl]" id
="acl" <?php
echo(($d['acl'] ?
' checked="checked"' : ''));?
> />
183 <?php
echo $lang['i_enableacl']?
></label
>
185 <fieldset id
="acldep">
186 <label
for="superuser"><?php
echo $lang['i_superuser']?
></label
>
187 <input
class="text" type
="text" name
="d[superuser]" id
="superuser" value
="<?php echo $d['superuser'] ?>" />
189 <label
for="fullname"><?php
echo $lang['fullname']?
></label
>
190 <input
class="text" type
="text" name
="d[fullname]" id
="fullname" value
="<?php echo $d['fullname'] ?>" />
192 <label
for="email"><?php
echo $lang['email']?
></label
>
193 <input
class="text" type
="text" name
="d[email]" id
="email" value
="<?php echo $d['email'] ?>" />
195 <label
for="password"><?php
echo $lang['pass']?
></label
>
196 <input
class="text" type
="password" name
="d[password]" id
="password" />
198 <label
for="confirm"><?php
echo $lang['passchk']?
></label
>
199 <input
class="text" type
="password" name
="d[confirm]" id
="confirm" />
201 <label
for="policy"><?php
echo $lang['i_policy']?
></label
>
202 <select
class="text" name
="d[policy]" id
="policy">
203 <option value
="0" <?php
echo ($d['policy'] == 0)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol0']?
></option
>
204 <option value
="1" <?php
echo ($d['policy'] == 1)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol1']?
></option
>
205 <option value
="2" <?php
echo ($d['policy'] == 2)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol2']?
></option
>
212 <p
><?php
echo $lang['i_license']?
></p
>
214 array_push($license,array('name' => $lang['i_license_none'], 'url'=>''));
215 if(empty($d['license'])) $d['license'] = 'cc-by-sa';
216 foreach($license as $key => $lic){
217 echo '<label for="lic_'.$key.'">';
218 echo '<input type="radio" name="d[license]" value="'.htmlspecialchars($key).'" id="lic_'.$key.'"'.
219 (($d['license'] === $key)?
' checked="checked"':'').'>';
220 echo htmlspecialchars($lic['name']);
221 if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>';
228 <p
><?php
echo $lang['i_pop_field']?
></p
>
230 <input type
="checkbox" name
="d[pop]" id
="pop" <?php
echo(($d['pop'] ?
' checked="checked"' : ''));?
> />
231 <?php
echo $lang['i_pop_label']?
> <a href
="http://www.dokuwiki.org/popularity" target
="_blank"><sup
>[?
]</sup
></a
>
236 <fieldset id
="process">
237 <input
class="button" type
="submit" name
="submit" value
="<?php echo $lang['btn_save']?>" />
243 function print_retry() {
247 <form action
="" method
="get">
249 <input type
="hidden" name
="l" value
="<?php echo $LC ?>" />
250 <input
class="button" type
="submit" value
="<?php echo $lang['i_retry'];?>" />
257 * Check validity of data
259 * @author Andreas Gohr
261 function check_data(&$d){
262 static $form_default = array(
271 'license' => 'cc-by-sa'
276 if(!is_array($d)) $d = array();
277 foreach($d as $k => $v) {
284 //autolowercase the username
285 $d['superuser'] = isset($d['superuser']) ?
strtolower($d['superuser']) : "";
289 if(isset($_REQUEST['submit'])) {
293 if(empty($d['title'])){
294 $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
297 if(isset($d['acl'])){
298 if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){
299 $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
302 if(empty($d['password'])){
303 $error[] = sprintf($lang['i_badval'],$lang['pass']);
306 elseif(!isset($d['confirm']) ||
$d['confirm'] != $d['password']){
307 $error[] = sprintf($lang['i_badval'],$lang['passchk']);
310 if(empty($d['fullname']) ||
strstr($d['fullname'],':')){
311 $error[] = sprintf($lang['i_badval'],$lang['fullname']);
314 if(empty($d['email']) ||
strstr($d['email'],':') ||
!strstr($d['email'],'@')){
315 $error[] = sprintf($lang['i_badval'],$lang['email']);
320 $d = array_merge($form_default, $d);
325 * Writes the data to the config files
327 * @author Chris Smith <chris@jalakai.co.uk>
329 function store_data($d){
332 $d['policy'] = (int) $d['policy'];
339 * Dokuwiki's Main Configuration File - Local Settings
340 * Auto-generated by install script
345 $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
346 $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
347 $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n";
349 $output .= '$conf[\'useacl\'] = 1'.";\n";
350 $output .= "\$conf['superuser'] = '@admin';\n";
352 $ok = $ok && fileWrite(DOKU_LOCAL
.'local.php',$output);
356 $phash = new PassHash();
357 $pass = $phash->hash_smd5($d['password']);
359 // create users.auth.php
360 // --- user:SMD5password:Real Name:email:groups,comma,seperated
361 $output = join(":",array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user'));
362 $output = @file_get_contents
(DOKU_CONF
.'users.auth.php.dist')."\n$output\n";
363 $ok = $ok && fileWrite(DOKU_LOCAL
.'users.auth.php', $output);
365 // create acl.auth.php
369 # Don't modify the lines above
371 # Access Control Lists
373 # Auto-generated by install script
377 if($d['policy'] == 2){
378 $output .= "* @ALL 0\n";
379 $output .= "* @user 8\n";
380 }elseif($d['policy'] == 1){
381 $output .= "* @ALL 1\n";
382 $output .= "* @user 8\n";
384 $output .= "* @ALL 8\n";
386 $ok = $ok && fileWrite(DOKU_LOCAL
.'acl.auth.php', $output);
389 // enable popularity submission
391 @touch
(DOKU_INC
.'data/cache/autosubmit.txt');
398 * Write the given content to a file
400 * @author Chris Smith <chris@jalakai.co.uk>
402 function fileWrite($filename, $data) {
406 if (($fp = @fopen
($filename, 'wb')) === false) {
407 $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
408 $error[] = sprintf($lang['i_writeerr'],$filename);
412 if (!empty($data)) { fwrite($fp, $data); }
419 * check installation dependent local config files and tests for a known
420 * unmodified main config file
422 * @author Chris Smith <chris@jalakai.co.uk>
424 function check_configs(){
427 global $dokuwiki_hash;
431 $config_files = array(
432 'local' => DOKU_LOCAL
.'local.php',
433 'users' => DOKU_LOCAL
.'users.auth.php',
434 'auth' => DOKU_LOCAL
.'acl.auth.php'
437 // main dokuwiki config file (conf/dokuwiki.php) must not have been modified
438 $installation_hash = md5(preg_replace("/(\015\012)|(\015)/","\012",
439 @file_get_contents
(DOKU_CONF
.'dokuwiki.php')));
440 if (!in_array($installation_hash, $dokuwiki_hash)) {
441 $error[] = sprintf($lang['i_badhash'],$installation_hash);
445 // configs shouldn't exist
446 foreach ($config_files as $file) {
447 if (@file_exists
($file) && filesize($file)) {
448 $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
449 $error[] = sprintf($lang['i_confexists'],$file);
458 * Check other installation dir/file permission requirements
460 * @author Chris Smith <chris@jalakai.co.uk>
462 function check_permissions(){
467 'conf' => DOKU_LOCAL
,
468 'data' => DOKU_INC
.'data',
469 'pages' => DOKU_INC
.'data/pages',
470 'attic' => DOKU_INC
.'data/attic',
471 'media' => DOKU_INC
.'data/media',
472 'media_attic' => DOKU_INC
.'data/media_attic',
473 'media_meta' => DOKU_INC
.'data/media_meta',
474 'meta' => DOKU_INC
.'data/meta',
475 'cache' => DOKU_INC
.'data/cache',
476 'locks' => DOKU_INC
.'data/locks',
477 'index' => DOKU_INC
.'data/index',
478 'tmp' => DOKU_INC
.'data/tmp'
482 foreach($dirs as $dir){
483 if(!@file_exists
("$dir/.") ||
!@is_writable
($dir)){
484 $dir = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
485 $error[] = sprintf($lang['i_permfail'],$dir);
493 * Check the availability of functions used in DokuWiki and the PHP version
495 * @author Andreas Gohr <andi@splitbrain.org>
497 function check_functions(){
502 if(version_compare(phpversion(),'5.1.2','<')){
503 $error[] = sprintf($lang['i_phpver'],phpversion(),'5.1.2');
507 $funcs = explode(' ','addslashes call_user_func chmod copy fgets '.
508 'file file_exists fseek flush filesize ftell fopen '.
509 'glob header ignore_user_abort ini_get mail mkdir '.
510 'ob_start opendir parse_ini_file readfile realpath '.
511 'rename rmdir serialize session_start unlink usleep '.
512 'preg_replace file_get_contents htmlspecialchars_decode '.
513 'spl_autoload_register stream_select fsockopen');
515 if (!function_exists('mb_substr')) {
516 $funcs[] = 'utf8_encode';
517 $funcs[] = 'utf8_decode';
520 foreach($funcs as $func){
521 if(!function_exists($func)){
522 $error[] = sprintf($lang['i_funcna'],$func);
530 * Print language selection
532 * @author Andreas Gohr <andi@splitbrain.org>
538 $dir = DOKU_INC
.'inc/lang';
543 while (($file = readdir($dh)) !== false) {
544 if(preg_match('/^[\._]/',$file)) continue;
545 if(is_dir($dir.'/'.$file) && @file_exists
($dir.'/'.$file.'/lang.php')){
552 echo '<form action="">';
553 echo $lang['i_chooselang'];
554 echo ': <select name="l" onchange="submit()">';
555 foreach($langs as $l){
556 $sel = ($l == $LC) ?
'selected="selected"' : '';
557 echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
560 echo '<input type="submit" value="'.$lang['btn_update'].'" />';
565 * Print global error array
567 * @author Andreas Gohr <andi@splitbrain.org>
569 function print_errors(){
573 foreach ($error as $err){
574 echo "<li>$err</li>";
581 * remove magic quotes recursivly
583 * @author Andreas Gohr <andi@splitbrain.org>
585 function remove_magic_quotes(&$array) {
586 foreach (array_keys($array) as $key) {
587 if (is_array($array[$key])) {
588 remove_magic_quotes($array[$key]);
590 $array[$key] = stripslashes($array[$key]);