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 // load and initialize the core system
13 require_once(DOKU_INC
.'inc/init.php');
15 // check for error reporting override or set error reporting to sane values
16 if (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE
); }
17 else { error_reporting(DOKU_E_LEVEL
); }
20 require_once(DOKU_INC
.'inc/lang/en/lang.php');
21 if(isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) {
22 $LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']);
24 if(empty($LC)) $LC = 'en';
25 if($LC && $LC != 'en' ) {
26 require_once(DOKU_INC
.'inc/lang/'.$LC.'/lang.php');
29 // initialise variables ...
32 $dokuwiki_hash = array(
33 '2005-09-22' => 'e33223e957b0b0a130d0520db08f8fb7',
34 '2006-03-05' => '51295727f79ab9af309a2fd9e0b61acc',
35 '2006-03-09' => '51295727f79ab9af309a2fd9e0b61acc',
36 '2006-11-06' => 'b3a8af76845977c2000d85d6990dd72b',
37 '2007-05-24' => 'd80f2740c84c4a6a791fd3c7a353536f',
38 '2007-06-26' => 'b3ca19c7a654823144119980be73cd77',
39 '2008-05-04' => '1e5c42eac3219d9e21927c39e3240aad',
40 '2009-02-14' => 'ec8c04210732a14fdfce0f7f6eead865',
41 '2009-12-25' => '993c4b2b385643efe5abf8e7010e11f4',
42 '2010-11-07' => '7921d48195f4db21b8ead6d9bea801b8',
43 '2011-05-25' => '4241865472edb6fa14a1227721008072',
44 '2011-11-10' => 'b46ff19a7587966ac4df61cbab1b8b31',
45 '2012-01-25' => '72c083c73608fc43c586901fd5dabb74',
46 '2012-09-10' => 'eb0b3fc90056fbc12bac6f49f7764df3',
47 '2013-05-10' => '7b62b75245f57f122d3e0f8ed7989623',
48 '2013-12-08' => '263c76af309fbf083867c18a34ff5214',
49 '2014-05-05' => '263c76af309fbf083867c18a34ff5214',
50 '2015-08-10' => '263c76af309fbf083867c18a34ff5214',
51 '2016-06-26' => 'fd3abb6d89853dacb032907e619fbd73',
52 '2017-02-19' => 'e4f2f5a34c9dbcd96a5ecc8f2df25bd9'
57 header('Content-Type: text/html; charset=utf-8');
60 <html lang
="<?php echo $LC?>" dir
="<?php echo $lang['direction']?>">
62 <meta charset
="utf-8" />
63 <title
><?php
echo $lang['i_installer']?
></title
>
64 <style type
="text/css">
65 body
{ width
: 90%
; margin
: 0 auto
; font
: 84% Verdana
, Helvetica
, Arial
, sans
-serif
; }
68 code
{ font
-size
: 110%
; color
: #800000; }
69 fieldset
{ border
: none
}
70 label
{ display
: block
; margin
-top
: 0.5em
; }
71 select
.text
, input
.text
{ width
: 30em
; margin
: 0 0.5em
; }
72 a
{text
-decoration
: none
}
74 <script type
="text/javascript">
76 var cb
= document
.getElementById('acl');
77 var fs
= document
.getElementById('acldep');
78 if(!cb ||
!fs
) return;
80 fs
.style
.display
= '';
82 fs
.style
.display
= 'none';
85 window
.onload
= function(){
87 var cb
= document
.getElementById('acl');
88 if(cb
) cb
.onchange
= acltoggle
;
93 <h1 style
="float:left">
94 <img src
="lib/exe/fetch.php?media=wiki:dokuwiki-128.png"
95 style
="vertical-align: middle;" alt
="" height
="64" width
="64" />
96 <?php
echo $lang['i_installer']?
>
98 <div style
="float:right; margin: 1em;">
103 <div style
="float: right; width: 34%;">
105 if(file_exists(DOKU_INC
.'inc/lang/'.$LC.'/install.html')){
106 include(DOKU_INC
.'inc/lang/'.$LC.'/install.html');
108 print "<div lang=\"en\" dir=\"ltr\">\n";
109 include(DOKU_INC
.'inc/lang/en/install.html');
113 <a style
="background: transparent url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png) left top no-repeat;
114 display: block; width:380px; height:73px; border:none; clear:both;"
116 href
="http://www.dokuwiki.org/security#web_access_security"></a
>
119 <div style
="float: left; width: 58%;">
121 if(! (check_functions() && check_permissions()) ){
122 echo '<p>'.$lang['i_problems'].'</p>';
125 }elseif(!check_configs()){
126 echo '<p>'.$lang['i_modified'].'</p>';
128 }elseif(check_data($_REQUEST['d'])){
129 // check_data has sanitized all input parameters
130 if(!store_data($_REQUEST['d'])){
131 echo '<p>'.$lang['i_failure'].'</p>';
134 echo '<p>'.$lang['i_success'].'</p>';
138 print_form($_REQUEST['d']);
144 <div style
="clear: both">
145 <a href
="http://dokuwiki.org/"><img src
="lib/tpl/dokuwiki/images/button-dw.png" alt
="driven by DokuWiki" /></a
>
146 <a href
="http://php.net"><img src
="lib/tpl/dokuwiki/images/button-php.gif" alt
="powered by PHP" /></a
>
153 * Print the input form
155 * @param array $d submitted entry 'd' of request data
157 function print_form($d){
161 include(DOKU_CONF
.'license.php');
163 if(!is_array($d)) $d = array();
164 $d = array_map('hsc',$d);
166 if(!isset($d['acl'])) $d['acl']=1;
167 if(!isset($d['pop'])) $d['pop']=1;
170 <form action
="" method
="post">
171 <input type
="hidden" name
="l" value
="<?php echo $LC ?>" />
173 <label
for="title"><?php
echo $lang['i_wikiname']?
>
174 <input type
="text" name
="d[title]" id
="title" value
="<?php echo $d['title'] ?>" style
="width: 20em;" />
177 <fieldset style
="margin-top: 1em;">
179 <input type
="checkbox" name
="d[acl]" id
="acl" <?php
echo(($d['acl'] ?
' checked="checked"' : ''));?
> />
180 <?php
echo $lang['i_enableacl']?
></label
>
182 <fieldset id
="acldep">
183 <label
for="superuser"><?php
echo $lang['i_superuser']?
></label
>
184 <input
class="text" type
="text" name
="d[superuser]" id
="superuser" value
="<?php echo $d['superuser'] ?>" />
186 <label
for="fullname"><?php
echo $lang['fullname']?
></label
>
187 <input
class="text" type
="text" name
="d[fullname]" id
="fullname" value
="<?php echo $d['fullname'] ?>" />
189 <label
for="email"><?php
echo $lang['email']?
></label
>
190 <input
class="text" type
="text" name
="d[email]" id
="email" value
="<?php echo $d['email'] ?>" />
192 <label
for="password"><?php
echo $lang['pass']?
></label
>
193 <input
class="text" type
="password" name
="d[password]" id
="password" />
195 <label
for="confirm"><?php
echo $lang['passchk']?
></label
>
196 <input
class="text" type
="password" name
="d[confirm]" id
="confirm" />
198 <label
for="policy"><?php
echo $lang['i_policy']?
></label
>
199 <select
class="text" name
="d[policy]" id
="policy">
200 <option value
="0" <?php
echo ($d['policy'] == 0)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol0']?
></option
>
201 <option value
="1" <?php
echo ($d['policy'] == 1)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol1']?
></option
>
202 <option value
="2" <?php
echo ($d['policy'] == 2)?
'selected="selected"':'' ?
>><?php
echo $lang['i_pol2']?
></option
>
205 <label
for="allowreg">
206 <input type
="checkbox" name
="d[allowreg]" id
="allowreg" <?php
echo(($d['allowreg'] ?
' checked="checked"' : ''));?
> />
207 <?php
echo $lang['i_allowreg']?
>
213 <p
><?php
echo $lang['i_license']?
></p
>
215 array_push($license,array('name' => $lang['i_license_none'], 'url'=>''));
216 if(empty($d['license'])) $d['license'] = 'cc-by-sa';
217 foreach($license as $key => $lic){
218 echo '<label for="lic_'.$key.'">';
219 echo '<input type="radio" name="d[license]" value="'.hsc($key).'" id="lic_'.$key.'"'.
220 (($d['license'] === $key)?
' checked="checked"':'').'>';
221 echo hsc($lic['name']);
222 if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>';
229 <p
><?php
echo $lang['i_pop_field']?
></p
>
231 <input type
="checkbox" name
="d[pop]" id
="pop" <?php
echo(($d['pop'] ?
' checked="checked"' : ''));?
> />
232 <?php
echo $lang['i_pop_label']?
> <a href
="http://www.dokuwiki.org/popularity" target
="_blank"><sup
>[?
]</sup
></a
>
237 <fieldset id
="process">
238 <button type
="submit" name
="submit"><?php
echo $lang['btn_save']?
></button
>
244 function print_retry() {
248 <form action
="" method
="get">
250 <input type
="hidden" name
="l" value
="<?php echo $LC ?>" />
251 <button type
="submit"><?php
echo $lang['i_retry'];?
></button
>
258 * Check validity of data
260 * @author Andreas Gohr
265 function check_data(&$d){
266 static $form_default = array(
276 'license' => 'cc-by-sa'
281 if(!is_array($d)) $d = array();
282 foreach($d as $k => $v) {
289 //autolowercase the username
290 $d['superuser'] = isset($d['superuser']) ?
strtolower($d['superuser']) : "";
294 if(isset($_REQUEST['submit'])) {
298 if(empty($d['title'])){
299 $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
302 if(isset($d['acl'])){
303 if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){
304 $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
307 if(empty($d['password'])){
308 $error[] = sprintf($lang['i_badval'],$lang['pass']);
311 elseif(!isset($d['confirm']) ||
$d['confirm'] != $d['password']){
312 $error[] = sprintf($lang['i_badval'],$lang['passchk']);
315 if(empty($d['fullname']) ||
strstr($d['fullname'],':')){
316 $error[] = sprintf($lang['i_badval'],$lang['fullname']);
319 if(empty($d['email']) ||
strstr($d['email'],':') ||
!strstr($d['email'],'@')){
320 $error[] = sprintf($lang['i_badval'],$lang['email']);
325 $d = array_merge($form_default, $d);
330 * Writes the data to the config files
332 * @author Chris Smith <chris@jalakai.co.uk>
337 function store_data($d){
340 $d['policy'] = (int) $d['policy'];
347 * Dokuwiki's Main Configuration File - Local Settings
348 * Auto-generated by install script
353 // add any config options set by a previous installer
354 $preset = __DIR__
.'/install.conf';
355 if(file_exists($preset)){
356 $output .= "# preset config options\n";
357 $output .= file_get_contents($preset);
359 $output .= "# options selected in installer\n";
363 $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
364 $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
365 $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n";
367 $output .= '$conf[\'useacl\'] = 1'.";\n";
368 $output .= "\$conf['superuser'] = '@admin';\n";
371 $output .= '$conf[\'disableactions\'] = \'register\''.";\n";
373 $ok = $ok && fileWrite(DOKU_LOCAL
.'local.php',$output);
377 $phash = new PassHash();
378 $pass = $phash->hash_smd5($d['password']);
380 // create users.auth.php
381 // --- user:SMD5password:Real Name:email:groups,comma,seperated
382 $output = join(":",array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user'));
383 $output = @file_get_contents
(DOKU_CONF
.'users.auth.php.dist')."\n$output\n";
384 $ok = $ok && fileWrite(DOKU_LOCAL
.'users.auth.php', $output);
386 // create acl.auth.php
390 # Don't modify the lines above
392 # Access Control Lists
394 # Auto-generated by install script
398 if($d['policy'] == 2){
399 $output .= "* @ALL 0\n";
400 $output .= "* @user 8\n";
401 }elseif($d['policy'] == 1){
402 $output .= "* @ALL 1\n";
403 $output .= "* @user 8\n";
405 $output .= "* @ALL 8\n";
407 $ok = $ok && fileWrite(DOKU_LOCAL
.'acl.auth.php', $output);
410 // enable popularity submission
412 @touch
(DOKU_INC
.'data/cache/autosubmit.txt');
415 // disable auth plugins til needed
419 * Local plugin enable/disable settings
421 * Auto-generated by install script
425 \$plugins['authad'] = 0;
426 \$plugins['authldap'] = 0;
427 \$plugins['authmysql'] = 0;
428 \$plugins['authpgsql'] = 0;
431 $ok = $ok && fileWrite(DOKU_LOCAL
.'plugins.local.php', $output);
437 * Write the given content to a file
439 * @author Chris Smith <chris@jalakai.co.uk>
441 * @param string $filename
442 * @param string $data
445 function fileWrite($filename, $data) {
449 if (($fp = @fopen
($filename, 'wb')) === false) {
450 $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
451 $error[] = sprintf($lang['i_writeerr'],$filename);
455 if (!empty($data)) { fwrite($fp, $data); }
462 * check installation dependent local config files and tests for a known
463 * unmodified main config file
465 * @author Chris Smith <chris@jalakai.co.uk>
469 function check_configs(){
472 global $dokuwiki_hash;
476 $config_files = array(
477 'local' => DOKU_LOCAL
.'local.php',
478 'users' => DOKU_LOCAL
.'users.auth.php',
479 'auth' => DOKU_LOCAL
.'acl.auth.php'
482 // main dokuwiki config file (conf/dokuwiki.php) must not have been modified
483 $installation_hash = md5(preg_replace("/(\015\012)|(\015)/","\012",
484 @file_get_contents
(DOKU_CONF
.'dokuwiki.php')));
485 if (!in_array($installation_hash, $dokuwiki_hash)) {
486 $error[] = sprintf($lang['i_badhash'],$installation_hash);
490 // configs shouldn't exist
491 foreach ($config_files as $file) {
492 if (file_exists($file) && filesize($file)) {
493 $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
494 $error[] = sprintf($lang['i_confexists'],$file);
503 * Check other installation dir/file permission requirements
505 * @author Chris Smith <chris@jalakai.co.uk>
509 function check_permissions(){
514 'conf' => DOKU_LOCAL
,
515 'data' => DOKU_INC
.'data',
516 'pages' => DOKU_INC
.'data/pages',
517 'attic' => DOKU_INC
.'data/attic',
518 'media' => DOKU_INC
.'data/media',
519 'media_attic' => DOKU_INC
.'data/media_attic',
520 'media_meta' => DOKU_INC
.'data/media_meta',
521 'meta' => DOKU_INC
.'data/meta',
522 'cache' => DOKU_INC
.'data/cache',
523 'locks' => DOKU_INC
.'data/locks',
524 'index' => DOKU_INC
.'data/index',
525 'tmp' => DOKU_INC
.'data/tmp'
529 foreach($dirs as $dir){
530 if(!file_exists("$dir/.") ||
!is_writable($dir)){
531 $dir = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
532 $error[] = sprintf($lang['i_permfail'],$dir);
540 * Check the availability of functions used in DokuWiki and the PHP version
542 * @author Andreas Gohr <andi@splitbrain.org>
546 function check_functions(){
551 if(version_compare(phpversion(),'5.6.0','<')){
552 $error[] = sprintf($lang['i_phpver'],phpversion(),'5.6.0');
556 if(ini_get('mbstring.func_overload') != 0){
557 $error[] = $lang['i_mbfuncoverload'];
561 $funcs = explode(' ','addslashes call_user_func chmod copy fgets '.
562 'file file_exists fseek flush filesize ftell fopen '.
563 'glob header ignore_user_abort ini_get mail mkdir '.
564 'ob_start opendir parse_ini_file readfile realpath '.
565 'rename rmdir serialize session_start unlink usleep '.
566 'preg_replace file_get_contents htmlspecialchars_decode '.
567 'spl_autoload_register stream_select fsockopen pack');
569 if (!function_exists('mb_substr')) {
570 $funcs[] = 'utf8_encode';
571 $funcs[] = 'utf8_decode';
574 foreach($funcs as $func){
575 if(!function_exists($func)){
576 $error[] = sprintf($lang['i_funcna'],$func);
584 * Print language selection
586 * @author Andreas Gohr <andi@splitbrain.org>
592 $dir = DOKU_INC
.'inc/lang';
597 while (($file = readdir($dh)) !== false) {
598 if(preg_match('/^[\._]/',$file)) continue;
599 if(is_dir($dir.'/'.$file) && file_exists($dir.'/'.$file.'/lang.php')){
606 echo '<form action="">';
607 echo $lang['i_chooselang'];
608 echo ': <select name="l" onchange="submit()">';
609 foreach($langs as $l){
610 $sel = ($l == $LC) ?
'selected="selected"' : '';
611 echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
614 echo '<button type="submit">'.$lang['btn_update'].'</button>';
619 * Print global error array
621 * @author Andreas Gohr <andi@splitbrain.org>
623 function print_errors(){
627 foreach ($error as $err){
628 echo "<li>$err</li>";