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 @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;
172 <form action
="" method
="post">
173 <input type
="hidden" name
="l" value
="<?php echo $LC ?>" />
175 <label
for="title"><?php
echo $lang['i_wikiname']?
>
176 <input type
="text" name
="d[title]" id
="title" value
="<?php echo $d['title'] ?>" style
="width: 20em;" />
179 <fieldset style
="margin-top: 1em;">
181 <input type
="checkbox" name
="d[acl]" id
="acl" <?php
echo(($d['acl'] ?
' checked="checked"' : ''));?
> />
182 <?php
echo $lang['i_enableacl']?
></label
>
184 <fieldset id
="acldep">
185 <label
for="superuser"><?php
echo $lang['i_superuser']?
></label
>
186 <input
class="text" type
="text" name
="d[superuser]" id
="superuser" value
="<?php echo $d['superuser'] ?>" />
188 <label
for="fullname"><?php
echo $lang['fullname']?
></label
>
189 <input
class="text" type
="text" name
="d[fullname]" id
="fullname" value
="<?php echo $d['fullname'] ?>" />
191 <label
for="email"><?php
echo $lang['email']?
></label
>
192 <input
class="text" type
="text" name
="d[email]" id
="email" value
="<?php echo $d['email'] ?>" />
194 <label
for="password"><?php
echo $lang['pass']?
></label
>
195 <input
class="text" type
="password" name
="d[password]" id
="password" />
197 <label
for="confirm"><?php
echo $lang['passchk']?
></label
>
198 <input
class="text" type
="password" name
="d[confirm]" id
="confirm" />
200 <label
for="policy"><?php
echo $lang['i_policy']?
></label
>
201 <select
class="text" name
="d[policy]" id
="policy">
202 <option value
="0" <?php
echo ($d['policy'] == 0)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol0']?
></option
>
203 <option value
="1" <?php
echo ($d['policy'] == 1)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol1']?
></option
>
204 <option value
="2" <?php
echo ($d['policy'] == 2)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol2']?
></option
>
211 <p
><?php
echo $lang['i_license']?
></p
>
213 array_unshift($license,array('name' => 'None', 'url'=>''));
214 if(empty($d['license'])) $d['license'] = 'cc-by-sa';
215 foreach($license as $key => $lic){
216 echo '<label for="lic_'.$key.'">';
217 echo '<input type="radio" name="d[license]" value="'.htmlspecialchars($key).'" id="lic_'.$key.'"'.
218 (($d['license'] == $key)?
' checked="checked"':'').'>';
219 echo htmlspecialchars($lic['name']);
220 if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>';
227 <fieldset id
="process">
228 <input
class="button" type
="submit" name
="submit" value
="<?php echo $lang['btn_save']?>" />
234 function print_retry() {
238 <form action
="" method
="get">
240 <input type
="hidden" name
="l" value
="<?php echo $LC ?>" />
241 <input
class="button" type
="submit" value
="<?php echo $lang['i_retry'];?>" />
248 * Check validity of data
250 * @author Andreas Gohr
252 function check_data(&$d){
253 static $form_default = array(
262 'license' => 'cc-by-sa'
267 if(!is_array($d)) $d = array();
268 foreach($d as $k => $v) {
275 //autolowercase the username
276 $d['superuser'] = isset($d['superuser']) ?
strtolower($d['superuser']) : "";
280 if(isset($_REQUEST['submit'])) {
284 if(empty($d['title'])){
285 $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
288 if(isset($d['acl'])){
289 if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){
290 $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
293 if(empty($d['password'])){
294 $error[] = sprintf($lang['i_badval'],$lang['pass']);
297 elseif(!isset($d['confirm']) ||
$d['confirm'] != $d['password']){
298 $error[] = sprintf($lang['i_badval'],$lang['passchk']);
301 if(empty($d['fullname']) ||
strstr($d['fullname'],':')){
302 $error[] = sprintf($lang['i_badval'],$lang['fullname']);
305 if(empty($d['email']) ||
strstr($d['email'],':') ||
!strstr($d['email'],'@')){
306 $error[] = sprintf($lang['i_badval'],$lang['email']);
311 $d = array_merge($form_default, $d);
316 * Writes the data to the config files
318 * @author Chris Smith <chris@jalakai.co.uk>
320 function store_data($d){
323 $d['policy'] = (int) $d['policy'];
330 * Dokuwiki's Main Configuration File - Local Settings
331 * Auto-generated by install script
336 $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
337 $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
338 $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n";
340 $output .= '$conf[\'useacl\'] = 1'.";\n";
341 $output .= "\$conf['superuser'] = '@admin';\n";
343 $ok = $ok && fileWrite(DOKU_LOCAL
.'local.php',$output);
347 $phash = new PassHash();
348 $pass = $phash->hash_smd5($d['password']);
350 // create users.auth.php
351 // --- user:SMD5password:Real Name:email:groups,comma,seperated
352 $output = join(":",array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user'));
353 $output = @file_get_contents
(DOKU_CONF
.'users.auth.php.dist')."\n$output\n";
354 $ok = $ok && fileWrite(DOKU_LOCAL
.'users.auth.php', $output);
356 // create acl.auth.php
360 # Don't modify the lines above
362 # Access Control Lists
364 # Auto-generated by install script
368 if($d['policy'] == 2){
369 $output .= "* @ALL 0\n";
370 $output .= "* @user 8\n";
371 }elseif($d['policy'] == 1){
372 $output .= "* @ALL 1\n";
373 $output .= "* @user 8\n";
375 $output .= "* @ALL 8\n";
377 $ok = $ok && fileWrite(DOKU_LOCAL
.'acl.auth.php', $output);
383 * Write the given content to a file
385 * @author Chris Smith <chris@jalakai.co.uk>
387 function fileWrite($filename, $data) {
391 if (($fp = @fopen
($filename, 'wb')) === false) {
392 $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
393 $error[] = sprintf($lang['i_writeerr'],$filename);
397 if (!empty($data)) { fwrite($fp, $data); }
404 * check installation dependent local config files and tests for a known
405 * unmodified main config file
407 * @author Chris Smith <chris@jalakai.co.uk>
409 function check_configs(){
412 global $dokuwiki_hash;
416 $config_files = array(
417 'local' => DOKU_LOCAL
.'local.php',
418 'users' => DOKU_LOCAL
.'users.auth.php',
419 'auth' => DOKU_LOCAL
.'acl.auth.php'
422 // main dokuwiki config file (conf/dokuwiki.php) must not have been modified
423 $installation_hash = md5(preg_replace("/(\015\012)|(\015)/","\012",
424 @file_get_contents
(DOKU_CONF
.'dokuwiki.php')));
425 if (!in_array($installation_hash, $dokuwiki_hash)) {
426 $error[] = sprintf($lang['i_badhash'],$installation_hash);
430 // configs shouldn't exist
431 foreach ($config_files as $file) {
432 if (@file_exists
($file) && filesize($file)) {
433 $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
434 $error[] = sprintf($lang['i_confexists'],$file);
443 * Check other installation dir/file permission requirements
445 * @author Chris Smith <chris@jalakai.co.uk>
447 function check_permissions(){
452 'conf' => DOKU_LOCAL
,
453 'data' => DOKU_INC
.'data',
454 'pages' => DOKU_INC
.'data/pages',
455 'attic' => DOKU_INC
.'data/attic',
456 'media' => DOKU_INC
.'data/media',
457 'media_attic' => DOKU_INC
.'data/media_attic',
458 'media_meta' => DOKU_INC
.'data/media_meta',
459 'meta' => DOKU_INC
.'data/meta',
460 'cache' => DOKU_INC
.'data/cache',
461 'locks' => DOKU_INC
.'data/locks',
462 'index' => DOKU_INC
.'data/index',
463 'tmp' => DOKU_INC
.'data/tmp'
467 foreach($dirs as $dir){
468 if(!@file_exists
("$dir/.") ||
!@is_writable
($dir)){
469 $dir = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
470 $error[] = sprintf($lang['i_permfail'],$dir);
478 * Check the availability of functions used in DokuWiki and the PHP version
480 * @author Andreas Gohr <andi@splitbrain.org>
482 function check_functions(){
487 if(version_compare(phpversion(),'5.1.2','<')){
488 $error[] = sprintf($lang['i_phpver'],phpversion(),'5.1.2');
492 $funcs = explode(' ','addslashes call_user_func chmod copy fgets '.
493 'file file_exists fseek flush filesize ftell fopen '.
494 'glob header ignore_user_abort ini_get mail mkdir '.
495 'ob_start opendir parse_ini_file readfile realpath '.
496 'rename rmdir serialize session_start unlink usleep '.
497 'preg_replace file_get_contents htmlspecialchars_decode '.
498 'spl_autoload_register stream_select fsockopen');
500 if (!function_exists('mb_substr')) {
501 $funcs[] = 'utf8_encode';
502 $funcs[] = 'utf8_decode';
505 foreach($funcs as $func){
506 if(!function_exists($func)){
507 $error[] = sprintf($lang['i_funcna'],$func);
515 * Print language selection
517 * @author Andreas Gohr <andi@splitbrain.org>
523 $dir = DOKU_INC
.'inc/lang';
528 while (($file = readdir($dh)) !== false) {
529 if(preg_match('/^[\._]/',$file)) continue;
530 if(is_dir($dir.'/'.$file) && @file_exists
($dir.'/'.$file.'/lang.php')){
537 echo '<form action="">';
538 echo $lang['i_chooselang'];
539 echo ': <select name="l" onchange="submit()">';
540 foreach($langs as $l){
541 $sel = ($l == $LC) ?
'selected="selected"' : '';
542 echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
545 echo '<input type="submit" value="'.$lang['btn_update'].'" />';
550 * Print global error array
552 * @author Andreas Gohr <andi@splitbrain.org>
554 function print_errors(){
558 foreach ($error as $err){
559 echo "<li>$err</li>";
566 * remove magic quotes recursivly
568 * @author Andreas Gohr <andi@splitbrain.org>
570 function remove_magic_quotes(&$array) {
571 foreach (array_keys($array) as $key) {
572 if (is_array($array[$key])) {
573 remove_magic_quotes($array[$key]);
575 $array[$key] = stripslashes($array[$key]);