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',
58 '2013-05-10' => '7b62b75245f57f122d3e0f8ed7989623',
59 '2013-12-08' => '263c76af309fbf083867c18a34ff5214',
60 '2014-05-05' => '263c76af309fbf083867c18a34ff5214',
61 '2015-08-10' => '263c76af309fbf083867c18a34ff5214'
66 header('Content-Type: text/html; charset=utf-8');
69 <html lang
="<?php echo $LC?>" dir
="<?php echo $lang['direction']?>">
71 <meta charset
="utf-8" />
72 <title
><?php
echo $lang['i_installer']?
></title
>
73 <style type
="text/css">
74 body
{ width
: 90%
; margin
: 0 auto
; font
: 84% Verdana
, Helvetica
, Arial
, sans
-serif
; }
77 code
{ font
-size
: 110%
; color
: #800000; }
78 fieldset
{ border
: none
}
79 label
{ display
: block
; margin
-top
: 0.5em
; }
80 select
.text
, input
.text
{ width
: 30em
; margin
: 0 0.5em
; }
81 a
{text
-decoration
: none
}
83 <script type
="text/javascript">
85 var cb
= document
.getElementById('acl');
86 var fs
= document
.getElementById('acldep');
87 if(!cb ||
!fs
) return;
89 fs
.style
.display
= '';
91 fs
.style
.display
= 'none';
94 window
.onload
= function(){
96 var cb
= document
.getElementById('acl');
97 if(cb
) cb
.onchange
= acltoggle
;
102 <h1 style
="float:left">
103 <img src
="lib/exe/fetch.php?media=wiki:dokuwiki-128.png"
104 style
="vertical-align: middle;" alt
="" height
="64" width
="64" />
105 <?php
echo $lang['i_installer']?
>
107 <div style
="float:right; margin: 1em;">
112 <div style
="float: right; width: 34%;">
114 if(file_exists(DOKU_INC
.'inc/lang/'.$LC.'/install.html')){
115 include(DOKU_INC
.'inc/lang/'.$LC.'/install.html');
117 print "<div lang=\"en\" dir=\"ltr\">\n";
118 include(DOKU_INC
.'inc/lang/en/install.html');
122 <a style
="background: transparent url(data/security.png) left top no-repeat;
123 display: block; width:380px; height:73px; border:none; clear:both;"
125 href
="http://www.dokuwiki.org/security#web_access_security"></a
>
128 <div style
="float: left; width: 58%;">
130 if(! (check_functions() && check_permissions()) ){
131 echo '<p>'.$lang['i_problems'].'</p>';
134 }elseif(!check_configs()){
135 echo '<p>'.$lang['i_modified'].'</p>';
137 }elseif(check_data($_REQUEST['d'])){
138 // check_data has sanitized all input parameters
139 if(!store_data($_REQUEST['d'])){
140 echo '<p>'.$lang['i_failure'].'</p>';
143 echo '<p>'.$lang['i_success'].'</p>';
147 print_form($_REQUEST['d']);
153 <div style
="clear: both">
154 <a href
="http://dokuwiki.org/"><img src
="lib/tpl/dokuwiki/images/button-dw.png" alt
="driven by DokuWiki" /></a
>
155 <a href
="http://www.php.net"><img src
="lib/tpl/dokuwiki/images/button-php.gif" alt
="powered by PHP" /></a
>
162 * Print the input form
164 * @param array $d submitted entry 'd' of request data
166 function print_form($d){
170 include(DOKU_CONF
.'license.php');
172 if(!is_array($d)) $d = array();
173 $d = array_map('htmlspecialchars',$d);
175 if(!isset($d['acl'])) $d['acl']=1;
176 if(!isset($d['pop'])) $d['pop']=1;
179 <form action
="" method
="post">
180 <input type
="hidden" name
="l" value
="<?php echo $LC ?>" />
182 <label
for="title"><?php
echo $lang['i_wikiname']?
>
183 <input type
="text" name
="d[title]" id
="title" value
="<?php echo $d['title'] ?>" style
="width: 20em;" />
186 <fieldset style
="margin-top: 1em;">
188 <input type
="checkbox" name
="d[acl]" id
="acl" <?php
echo(($d['acl'] ?
' checked="checked"' : ''));?
> />
189 <?php
echo $lang['i_enableacl']?
></label
>
191 <fieldset id
="acldep">
192 <label
for="superuser"><?php
echo $lang['i_superuser']?
></label
>
193 <input
class="text" type
="text" name
="d[superuser]" id
="superuser" value
="<?php echo $d['superuser'] ?>" />
195 <label
for="fullname"><?php
echo $lang['fullname']?
></label
>
196 <input
class="text" type
="text" name
="d[fullname]" id
="fullname" value
="<?php echo $d['fullname'] ?>" />
198 <label
for="email"><?php
echo $lang['email']?
></label
>
199 <input
class="text" type
="text" name
="d[email]" id
="email" value
="<?php echo $d['email'] ?>" />
201 <label
for="password"><?php
echo $lang['pass']?
></label
>
202 <input
class="text" type
="password" name
="d[password]" id
="password" />
204 <label
for="confirm"><?php
echo $lang['passchk']?
></label
>
205 <input
class="text" type
="password" name
="d[confirm]" id
="confirm" />
207 <label
for="policy"><?php
echo $lang['i_policy']?
></label
>
208 <select
class="text" name
="d[policy]" id
="policy">
209 <option value
="0" <?php
echo ($d['policy'] == 0)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol0']?
></option
>
210 <option value
="1" <?php
echo ($d['policy'] == 1)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol1']?
></option
>
211 <option value
="2" <?php
echo ($d['policy'] == 2)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol2']?
></option
>
214 <label
for="allowreg">
215 <input type
="checkbox" name
="d[allowreg]" id
="allowreg" <?php
echo(($d['allowreg'] ?
' checked="checked"' : ''));?
> />
216 <?php
echo $lang['i_allowreg']?
>
222 <p
><?php
echo $lang['i_license']?
></p
>
224 array_push($license,array('name' => $lang['i_license_none'], 'url'=>''));
225 if(empty($d['license'])) $d['license'] = 'cc-by-sa';
226 foreach($license as $key => $lic){
227 echo '<label for="lic_'.$key.'">';
228 echo '<input type="radio" name="d[license]" value="'.htmlspecialchars($key).'" id="lic_'.$key.'"'.
229 (($d['license'] === $key)?
' checked="checked"':'').'>';
230 echo htmlspecialchars($lic['name']);
231 if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>';
238 <p
><?php
echo $lang['i_pop_field']?
></p
>
240 <input type
="checkbox" name
="d[pop]" id
="pop" <?php
echo(($d['pop'] ?
' checked="checked"' : ''));?
> />
241 <?php
echo $lang['i_pop_label']?
> <a href
="http://www.dokuwiki.org/popularity" target
="_blank"><sup
>[?
]</sup
></a
>
246 <fieldset id
="process">
247 <button type
="submit" name
="submit"><?php
echo $lang['btn_save']?
></button
>
253 function print_retry() {
257 <form action
="" method
="get">
259 <input type
="hidden" name
="l" value
="<?php echo $LC ?>" />
260 <button type
="submit"><?php
echo $lang['i_retry'];?
></button
>
267 * Check validity of data
269 * @author Andreas Gohr
274 function check_data(&$d){
275 static $form_default = array(
285 'license' => 'cc-by-sa'
290 if(!is_array($d)) $d = array();
291 foreach($d as $k => $v) {
298 //autolowercase the username
299 $d['superuser'] = isset($d['superuser']) ?
strtolower($d['superuser']) : "";
303 if(isset($_REQUEST['submit'])) {
307 if(empty($d['title'])){
308 $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
311 if(isset($d['acl'])){
312 if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){
313 $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
316 if(empty($d['password'])){
317 $error[] = sprintf($lang['i_badval'],$lang['pass']);
320 elseif(!isset($d['confirm']) ||
$d['confirm'] != $d['password']){
321 $error[] = sprintf($lang['i_badval'],$lang['passchk']);
324 if(empty($d['fullname']) ||
strstr($d['fullname'],':')){
325 $error[] = sprintf($lang['i_badval'],$lang['fullname']);
328 if(empty($d['email']) ||
strstr($d['email'],':') ||
!strstr($d['email'],'@')){
329 $error[] = sprintf($lang['i_badval'],$lang['email']);
334 $d = array_merge($form_default, $d);
339 * Writes the data to the config files
341 * @author Chris Smith <chris@jalakai.co.uk>
346 function store_data($d){
349 $d['policy'] = (int) $d['policy'];
356 * Dokuwiki's Main Configuration File - Local Settings
357 * Auto-generated by install script
362 // add any config options set by a previous installer
363 $preset = __DIR__
.'/install.conf';
364 if(file_exists($preset)){
365 $output .= "# preset config options\n";
366 $output .= file_get_contents($preset);
368 $output .= "# options selected in installer\n";
372 $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
373 $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
374 $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n";
376 $output .= '$conf[\'useacl\'] = 1'.";\n";
377 $output .= "\$conf['superuser'] = '@admin';\n";
380 $output .= '$conf[\'disableactions\'] = \'register\''.";\n";
382 $ok = $ok && fileWrite(DOKU_LOCAL
.'local.php',$output);
386 $phash = new PassHash();
387 $pass = $phash->hash_smd5($d['password']);
389 // create users.auth.php
390 // --- user:SMD5password:Real Name:email:groups,comma,seperated
391 $output = join(":",array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user'));
392 $output = @file_get_contents
(DOKU_CONF
.'users.auth.php.dist')."\n$output\n";
393 $ok = $ok && fileWrite(DOKU_LOCAL
.'users.auth.php', $output);
395 // create acl.auth.php
399 # Don't modify the lines above
401 # Access Control Lists
403 # Auto-generated by install script
407 if($d['policy'] == 2){
408 $output .= "* @ALL 0\n";
409 $output .= "* @user 8\n";
410 }elseif($d['policy'] == 1){
411 $output .= "* @ALL 1\n";
412 $output .= "* @user 8\n";
414 $output .= "* @ALL 8\n";
416 $ok = $ok && fileWrite(DOKU_LOCAL
.'acl.auth.php', $output);
419 // enable popularity submission
421 @touch
(DOKU_INC
.'data/cache/autosubmit.txt');
424 // disable auth plugins til needed
428 * Local plugin enable/disable settings
430 * Auto-generated by install script
434 \$plugins['authad'] = 0;
435 \$plugins['authldap'] = 0;
436 \$plugins['authmysql'] = 0;
437 \$plugins['authpgsql'] = 0;
440 $ok = $ok && fileWrite(DOKU_LOCAL
.'plugins.local.php', $output);
446 * Write the given content to a file
448 * @author Chris Smith <chris@jalakai.co.uk>
450 * @param string $filename
451 * @param string $data
454 function fileWrite($filename, $data) {
458 if (($fp = @fopen
($filename, 'wb')) === false) {
459 $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
460 $error[] = sprintf($lang['i_writeerr'],$filename);
464 if (!empty($data)) { fwrite($fp, $data); }
471 * check installation dependent local config files and tests for a known
472 * unmodified main config file
474 * @author Chris Smith <chris@jalakai.co.uk>
478 function check_configs(){
481 global $dokuwiki_hash;
485 $config_files = array(
486 'local' => DOKU_LOCAL
.'local.php',
487 'users' => DOKU_LOCAL
.'users.auth.php',
488 'auth' => DOKU_LOCAL
.'acl.auth.php'
491 // main dokuwiki config file (conf/dokuwiki.php) must not have been modified
492 $installation_hash = md5(preg_replace("/(\015\012)|(\015)/","\012",
493 @file_get_contents
(DOKU_CONF
.'dokuwiki.php')));
494 if (!in_array($installation_hash, $dokuwiki_hash)) {
495 $error[] = sprintf($lang['i_badhash'],$installation_hash);
499 // configs shouldn't exist
500 foreach ($config_files as $file) {
501 if (file_exists($file) && filesize($file)) {
502 $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
503 $error[] = sprintf($lang['i_confexists'],$file);
512 * Check other installation dir/file permission requirements
514 * @author Chris Smith <chris@jalakai.co.uk>
518 function check_permissions(){
523 'conf' => DOKU_LOCAL
,
524 'data' => DOKU_INC
.'data',
525 'pages' => DOKU_INC
.'data/pages',
526 'attic' => DOKU_INC
.'data/attic',
527 'media' => DOKU_INC
.'data/media',
528 'media_attic' => DOKU_INC
.'data/media_attic',
529 'media_meta' => DOKU_INC
.'data/media_meta',
530 'meta' => DOKU_INC
.'data/meta',
531 'cache' => DOKU_INC
.'data/cache',
532 'locks' => DOKU_INC
.'data/locks',
533 'index' => DOKU_INC
.'data/index',
534 'tmp' => DOKU_INC
.'data/tmp'
538 foreach($dirs as $dir){
539 if(!file_exists("$dir/.") ||
!is_writable($dir)){
540 $dir = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
541 $error[] = sprintf($lang['i_permfail'],$dir);
549 * Check the availability of functions used in DokuWiki and the PHP version
551 * @author Andreas Gohr <andi@splitbrain.org>
555 function check_functions(){
560 if(version_compare(phpversion(),'5.3.3','<')){
561 $error[] = sprintf($lang['i_phpver'],phpversion(),'5.3.3');
565 if(ini_get('mbstring.func_overload') != 0){
566 $error[] = $lang['i_mbfuncoverload'];
570 $funcs = explode(' ','addslashes call_user_func chmod copy fgets '.
571 'file file_exists fseek flush filesize ftell fopen '.
572 'glob header ignore_user_abort ini_get mail mkdir '.
573 'ob_start opendir parse_ini_file readfile realpath '.
574 'rename rmdir serialize session_start unlink usleep '.
575 'preg_replace file_get_contents htmlspecialchars_decode '.
576 'spl_autoload_register stream_select fsockopen pack');
578 if (!function_exists('mb_substr')) {
579 $funcs[] = 'utf8_encode';
580 $funcs[] = 'utf8_decode';
583 foreach($funcs as $func){
584 if(!function_exists($func)){
585 $error[] = sprintf($lang['i_funcna'],$func);
593 * Print language selection
595 * @author Andreas Gohr <andi@splitbrain.org>
601 $dir = DOKU_INC
.'inc/lang';
606 while (($file = readdir($dh)) !== false) {
607 if(preg_match('/^[\._]/',$file)) continue;
608 if(is_dir($dir.'/'.$file) && file_exists($dir.'/'.$file.'/lang.php')){
615 echo '<form action="">';
616 echo $lang['i_chooselang'];
617 echo ': <select name="l" onchange="submit()">';
618 foreach($langs as $l){
619 $sel = ($l == $LC) ?
'selected="selected"' : '';
620 echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
623 echo '<button type="submit">'.$lang['btn_update'].'</button>';
628 * Print global error array
630 * @author Andreas Gohr <andi@splitbrain.org>
632 function print_errors(){
636 foreach ($error as $err){
637 echo "<li>$err</li>";
644 * remove magic quotes recursivly
646 * @author Andreas Gohr <andi@splitbrain.org>
648 * @param array $array
650 function remove_magic_quotes(&$array) {
651 foreach (array_keys($array) as $key) {
652 if (is_array($array[$key])) {
653 remove_magic_quotes($array[$key]);
655 $array[$key] = stripslashes($array[$key]);