[ PHPXref.com ] [ Generated: Sun Jul 20 17:18:56 2008 ] [ DokuWiki 2007-06-26b ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

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


[ Powered by PHPXref - Served by Debian GNU/Linux ]