[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/ -> install.php (source)

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


Generated: Thu Aug 28 01:30:02 2008 Cross-referenced by PHPXref 0.7