source: documentation/trunk/packages/dokuwiki-2011-05-25a/install.php@ 25038

Last change on this file since 25038 was 25027, checked in by jmt12, 12 years ago

Adding the packages directory, and within it a configured version of dokuwiki all ready to run

File size: 17.1 KB
Line 
1<?php
2/**
3 * Dokuwiki installation assistance
4 *
5 * @author Chris Smith <[email protected]>
6 */
7
8if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
9if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
10if(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC.'conf/');
11
12// check for error reporting override or set error reporting to sane values
13if (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE); }
14else { error_reporting(DOKU_E_LEVEL); }
15
16// kill magic quotes
17if (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) {
18 if (!empty($_GET)) remove_magic_quotes($_GET);
19 if (!empty($_POST)) remove_magic_quotes($_POST);
20 if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE);
21 if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST);
22 @ini_set('magic_quotes_gpc', 0);
23 define('MAGIC_QUOTES_STRIPPED',1);
24}
25@set_magic_quotes_runtime(0);
26@ini_set('magic_quotes_sybase',0);
27
28// language strings
29require_once(DOKU_INC.'inc/lang/en/lang.php');
30$LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']);
31if(!$LC) $LC = 'en';
32if($LC && $LC != 'en' ) {
33 require_once(DOKU_INC.'inc/lang/'.$LC.'/lang.php');
34}
35
36// initialise variables ...
37$error = array();
38
39$dokuwiki_hash = array(
40 '2005-09-22' => 'e33223e957b0b0a130d0520db08f8fb7',
41 '2006-03-05' => '51295727f79ab9af309a2fd9e0b61acc',
42 '2006-03-09' => '51295727f79ab9af309a2fd9e0b61acc',
43 '2006-11-06' => 'b3a8af76845977c2000d85d6990dd72b',
44 '2007-05-24' => 'd80f2740c84c4a6a791fd3c7a353536f',
45 '2007-06-26' => 'b3ca19c7a654823144119980be73cd77',
46 '2008-05-04' => '1e5c42eac3219d9e21927c39e3240aad',
47 '2009-02-14' => 'ec8c04210732a14fdfce0f7f6eead865',
48 '2009-12-25' => '993c4b2b385643efe5abf8e7010e11f4',
49 '2010-11-07' => '7921d48195f4db21b8ead6d9bea801b8',
50 '2011-05-25' => '4241865472edb6fa14a1227721008072',
51);
52
53
54
55// begin output
56header('Content-Type: text/html; charset=utf-8');
57?>
58<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
59 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
60<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $LC?>"
61 lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>">
62<head>
63 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
64 <title><?php echo $lang['i_installer']?></title>
65 <style type="text/css">
66 body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; }
67 img { border: none }
68 br.cl { clear:both; }
69 code { font-size: 110%; color: #800000; }
70 fieldset { border: none }
71 label { display: block; margin-top: 0.5em; }
72 select.text, input.text { width: 30em; margin: 0 0.5em; }
73 a {text-decoration: none}
74 </style>
75 <script type="text/javascript" language="javascript">
76 function acltoggle(){
77 var cb = document.getElementById('acl');
78 var fs = document.getElementById('acldep');
79 if(!cb || !fs) return;
80 if(cb.checked){
81 fs.style.display = '';
82 }else{
83 fs.style.display = 'none';
84 }
85 }
86 window.onload = function(){
87 acltoggle();
88 var cb = document.getElementById('acl');
89 if(cb) cb.onchange = acltoggle;
90 };
91 </script>
92</head>
93<body style="">
94 <h1 style="float:left">
95 <img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png&w=64"
96 style="vertical-align: middle;" alt="" />
97 <?php echo $lang['i_installer']?>
98 </h1>
99 <div style="float:right; margin: 1em;">
100 <?php langsel()?>
101 </div>
102 <br class="cl" />
103
104 <div style="float: right; width: 34%;">
105 <?php
106 if(@file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){
107 include(DOKU_INC.'inc/lang/'.$LC.'/install.html');
108 }else{
109 print "<div lang=\"en\" dir=\"ltr\">\n";
110 include(DOKU_INC.'inc/lang/en/install.html');
111 print "</div>\n";
112 }
113 ?>
114 <a style="background: transparent url(data/security.png) left top no-repeat;
115 display: block; width:380px; height:73px; border:none; clear:both;"
116 target="_blank"
117 href="http://www.dokuwiki.org/security#web_access_security"></a>
118 </div>
119
120 <div style="float: left; width: 58%;">
121 <?php
122 if(! (check_functions() && check_permissions()) ){
123 echo '<p>'.$lang['i_problems'].'</p>';
124 print_errors();
125 print_retry();
126 }elseif(!check_configs()){
127 echo '<p>'.$lang['i_modified'].'</p>';
128 print_errors();
129 }elseif($_REQUEST['submit']){
130 if(!check_data($_REQUEST['d'])){
131 print_errors();
132 print_form($_REQUEST['d']);
133 }elseif(!store_data($_REQUEST['d'])){
134 echo '<p>'.$lang['i_failure'].'</p>';
135 print_errors();
136 }else{
137 echo '<p>'.$lang['i_success'].'</p>';
138 }
139 }else{
140 print_form($_REQUEST['d']);
141 }
142 ?>
143 </div>
144
145
146<div style="clear: both">
147 <a href="http://dokuwiki.org/"><img src="lib/tpl/default/images/button-dw.png" alt="driven by DokuWiki" /></a>
148 <a href="http://www.php.net"><img src="lib/tpl/default/images/button-php.gif" alt="powered by PHP" /></a>
149</div>
150</body>
151</html>
152<?php
153
154/**
155 * Print the input form
156 */
157function print_form($d){
158 global $lang;
159 global $LC;
160
161 include(DOKU_CONF.'license.php');
162
163 if(!is_array($d)) $d = array();
164 $d = array_map('htmlspecialchars',$d);
165
166 if(!isset($d['acl'])) $d['acl']=1;
167
168 ?>
169 <form action="" method="post">
170 <input type="hidden" name="l" value="<?php echo $LC ?>" />
171 <fieldset>
172 <label for="title"><?php echo $lang['i_wikiname']?>
173 <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" />
174 </label>
175
176 <fieldset style="margin-top: 1em;">
177 <label for="acl">
178 <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? 'checked="checked"' : ''));?> />
179 <?php echo $lang['i_enableacl']?></label>
180
181 <fieldset id="acldep">
182 <label for="superuser"><?php echo $lang['i_superuser']?></label>
183 <input class="text" type="text" name="d[superuser]" id="superuser" value="<?php echo $d['superuser'] ?>" />
184
185 <label for="fullname"><?php echo $lang['fullname']?></label>
186 <input class="text" type="text" name="d[fullname]" id="fullname" value="<?php echo $d['fullname'] ?>" />
187
188 <label for="email"><?php echo $lang['email']?></label>
189 <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" />
190
191 <label for="password"><?php echo $lang['pass']?></label>
192 <input class="text" type="password" name="d[password]" id="password" />
193
194 <label for="confirm"><?php echo $lang['passchk']?></label>
195 <input class="text" type="password" name="d[confirm]" id="confirm" />
196
197 <label for="policy"><?php echo $lang['i_policy']?></label>
198 <select class="text" name="d[policy]" id="policy">
199 <option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php echo $lang['i_pol0']?></option>
200 <option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php echo $lang['i_pol1']?></option>
201 <option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php echo $lang['i_pol2']?></option>
202 </select>
203
204 </fieldset>
205 </fieldset>
206
207 <fieldset>
208 <p><?php echo $lang['i_license']?></p>
209 <?php
210 array_unshift($license,array('name' => 'None', 'url'=>''));
211 if(!isset($d['license'])) $d['license'] = 'cc-by-sa';
212 foreach($license as $key => $lic){
213 echo '<label for="lic_'.$key.'">';
214 echo '<input type="radio" name="d[license]" value="'.htmlspecialchars($key).'" id="lic_'.$key.'"'.
215 (($d['license'] == $key)?'checked="checked"':'').'>';
216 echo htmlspecialchars($lic['name']);
217 if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>';
218 echo '</label>';
219 }
220 ?>
221 </fieldset>
222
223 </fieldset>
224 <fieldset id="process">
225 <input class="button" type="submit" name="submit" value="<?php echo $lang['btn_save']?>" />
226 </fieldset>
227 </form>
228 <?php
229}
230
231function print_retry() {
232 global $lang;
233 global $LC;
234 ?>
235 <form action="" method="get">
236 <fieldset>
237 <input type="hidden" name="l" value="<?php echo $LC ?>" />
238 <input class="button" type="submit" value="<?php echo $lang['i_retry'];?>" />
239 </fieldset>
240 </form>
241 <?php
242}
243
244/**
245 * Check validity of data
246 *
247 * @author Andreas Gohr
248 */
249function check_data(&$d){
250 global $lang;
251 global $error;
252
253 //autolowercase the username
254 $d['superuser'] = strtolower($d['superuser']);
255
256 $ok = true;
257
258 // check input
259 if(empty($d['title'])){
260 $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
261 $ok = false;
262 }
263 if($d['acl']){
264 if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){
265 $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
266 $ok = false;
267 }
268 if(empty($d['password'])){
269 $error[] = sprintf($lang['i_badval'],$lang['pass']);
270 $ok = false;
271 }
272 if($d['confirm'] != $d['password']){
273 $error[] = sprintf($lang['i_badval'],$lang['passchk']);
274 $ok = false;
275 }
276 if(empty($d['fullname']) || strstr($d['fullname'],':')){
277 $error[] = sprintf($lang['i_badval'],$lang['fullname']);
278 $ok = false;
279 }
280 if(empty($d['email']) || strstr($d['email'],':') || !strstr($d['email'],'@')){
281 $error[] = sprintf($lang['i_badval'],$lang['email']);
282 $ok = false;
283 }
284 }
285 return $ok;
286}
287
288/**
289 * Writes the data to the config files
290 *
291 * @author Chris Smith <[email protected]>
292 */
293function store_data($d){
294 global $LC;
295 $ok = true;
296 $d['policy'] = (int) $d['policy'];
297
298 // create local.php
299 $now = gmdate('r');
300 $output = <<<EOT
301<?php
302/**
303 * Dokuwiki's Main Configuration File - Local Settings
304 * Auto-generated by install script
305 * Date: $now
306 */
307
308EOT;
309 $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
310 $output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
311 $output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n";
312 if($d['acl']){
313 $output .= '$conf[\'useacl\'] = 1'.";\n";
314 $output .= "\$conf['superuser'] = '@admin';\n";
315 }
316 $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output);
317
318 if ($d['acl']) {
319 // create users.auth.php
320 // --- user:MD5password:Real Name:email:groups,comma,seperated
321 $output = join(":",array($d['superuser'], md5($d['password']), $d['fullname'], $d['email'], 'admin,user'));
322 $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n";
323 $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output);
324
325 // create acl.auth.php
326 $output = <<<EOT
327# acl.auth.php
328# <?php exit()?>
329# Don't modify the lines above
330#
331# Access Control Lists
332#
333# Auto-generated by install script
334# Date: $now
335
336EOT;
337 if($d['policy'] == 2){
338 $output .= "* @ALL 0\n";
339 $output .= "* @user 8\n";
340 }elseif($d['policy'] == 1){
341 $output .= "* @ALL 1\n";
342 $output .= "* @user 8\n";
343 }else{
344 $output .= "* @ALL 8\n";
345 }
346 $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output);
347 }
348 return $ok;
349}
350
351/**
352 * Write the given content to a file
353 *
354 * @author Chris Smith <[email protected]>
355 */
356function fileWrite($filename, $data) {
357 global $error;
358 global $lang;
359
360 if (($fp = @fopen($filename, 'wb')) === false) {
361 $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
362 $error[] = sprintf($lang['i_writeerr'],$filename);
363 return false;
364 }
365
366 if (!empty($data)) { fwrite($fp, $data); }
367 fclose($fp);
368 return true;
369}
370
371
372/**
373 * check installation dependent local config files and tests for a known
374 * unmodified main config file
375 *
376 * @author Chris Smith <[email protected]>
377 */
378function check_configs(){
379 global $error;
380 global $lang;
381 global $dokuwiki_hash;
382
383 $ok = true;
384
385 $config_files = array(
386 'local' => DOKU_LOCAL.'local.php',
387 'users' => DOKU_LOCAL.'users.auth.php',
388 'auth' => DOKU_LOCAL.'acl.auth.php'
389 );
390
391 // main dokuwiki config file (conf/dokuwiki.php) must not have been modified
392 $installation_hash = md5(preg_replace("/(\015\012)|(\015)/","\012",
393 @file_get_contents(DOKU_CONF.'dokuwiki.php')));
394 if (!in_array($installation_hash, $dokuwiki_hash)) {
395 $error[] = sprintf($lang['i_badhash'],$installation_hash);
396 $ok = false;
397 }
398
399 // configs shouldn't exist
400 foreach ($config_files as $file) {
401 if (@file_exists($file)) {
402 $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
403 $error[] = sprintf($lang['i_confexists'],$file);
404 $ok = false;
405 }
406 }
407 return $ok;
408}
409
410
411/**
412 * Check other installation dir/file permission requirements
413 *
414 * @author Chris Smith <[email protected]>
415 */
416function check_permissions(){
417 global $error;
418 global $lang;
419
420 $dirs = array(
421 'conf' => DOKU_LOCAL,
422 'data' => DOKU_INC.'data',
423 'pages' => DOKU_INC.'data/pages',
424 'attic' => DOKU_INC.'data/attic',
425 'media' => DOKU_INC.'data/media',
426 'meta' => DOKU_INC.'data/meta',
427 'cache' => DOKU_INC.'data/cache',
428 'locks' => DOKU_INC.'data/locks',
429 'index' => DOKU_INC.'data/index',
430 'tmp' => DOKU_INC.'data/tmp'
431 );
432
433 $ok = true;
434 foreach($dirs as $dir){
435 if(!@file_exists("$dir/.") || !@is_writable($dir)){
436 $dir = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
437 $error[] = sprintf($lang['i_permfail'],$dir);
438 $ok = false;
439 }
440 }
441 return $ok;
442}
443
444/**
445 * Check the availability of functions used in DokuWiki and the PHP version
446 *
447 * @author Andreas Gohr <[email protected]>
448 */
449function check_functions(){
450 global $error;
451 global $lang;
452 $ok = true;
453
454 if(version_compare(phpversion(),'5.1.2','<')){
455 $error[] = sprintf($lang['i_phpver'],phpversion(),'5.1.2');
456 $ok = false;
457 }
458
459 $funcs = explode(' ','addslashes basename call_user_func chmod copy fgets '.
460 'file file_exists fseek flush filesize ftell fopen '.
461 'glob header ignore_user_abort ini_get mail mkdir '.
462 'ob_start opendir parse_ini_file readfile realpath '.
463 'rename rmdir serialize session_start unlink usleep '.
464 'preg_replace file_get_contents htmlspecialchars_decode '.
465 'spl_autoload_register');
466
467 if (!function_exists('mb_substr')) {
468 $funcs[] = 'utf8_encode';
469 $funcs[] = 'utf8_decode';
470 }
471
472 foreach($funcs as $func){
473 if(!function_exists($func)){
474 $error[] = sprintf($lang['i_funcna'],$func);
475 $ok = false;
476 }
477 }
478 return $ok;
479}
480
481/**
482 * Print language selection
483 *
484 * @author Andreas Gohr <[email protected]>
485 */
486function langsel(){
487 global $lang;
488 global $LC;
489
490 $dir = DOKU_INC.'inc/lang';
491 $dh = opendir($dir);
492 if(!$dh) return;
493
494 $langs = array();
495 while (($file = readdir($dh)) !== false) {
496 if(preg_match('/^[\._]/',$file)) continue;
497 if(is_dir($dir.'/'.$file) && @file_exists($dir.'/'.$file.'/lang.php')){
498 $langs[] = $file;
499 }
500 }
501 closedir($dh);
502 sort($langs);
503
504 echo '<form action="">';
505 echo $lang['i_chooselang'];
506 echo ': <select name="l" onchange="submit()">';
507 foreach($langs as $l){
508 $sel = ($l == $LC) ? 'selected="selected"' : '';
509 echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
510 }
511 echo '</select> ';
512 echo '<input type="submit" value="'.$lang['btn_update'].'" />';
513 echo '</form>';
514}
515
516/**
517 * Print global error array
518 *
519 * @author Andreas Gohr <[email protected]>
520 */
521function print_errors(){
522 global $error;
523 echo '<ul>';
524 foreach ($error as $err){
525 echo "<li>$err</li>";
526 }
527 echo '</ul>';
528}
529
530/**
531 * remove magic quotes recursivly
532 *
533 * @author Andreas Gohr <[email protected]>
534 */
535function remove_magic_quotes(&$array) {
536 foreach (array_keys($array) as $key) {
537 if (is_array($array[$key])) {
538 remove_magic_quotes($array[$key]);
539 }else {
540 $array[$key] = stripslashes($array[$key]);
541 }
542 }
543}
544
Note: See TracBrowser for help on using the repository browser.