[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/upgrade/upd-2.0.13-to-2.0.14/ -> index.php (source)

   1  <?php
   2  
   3  class upgrade_2014 {  
   4      
   5      var $usedFiles = array( 'mainfile.php' );
   6      
   7  	function isApplied() {
   8          return ( $this->check_0523patch() && $this->check_auth_db() );
   9      }
  10  
  11  	function apply() {
  12          if ( $this->apply_0523patch() ) {
  13              return $this->apply_auth_db();
  14          }
  15          return false; 
  16      }
  17  
  18  	function check_0523patch() {
  19          $lines = file( '../mainfile.php' );
  20          foreach ( $lines as $line ) {
  21              if ( strpos( $line, "\$_REQUEST[\$bad_global]" ) !== false ) {
  22                  // Patch found: do not apply again
  23                  return true;
  24              }
  25          }
  26          return false;
  27      }
  28  
  29  	function apply_0523patch() {
  30  $patchCode = "
  31      foreach ( array('GLOBALS', '_SESSION', 'HTTP_SESSION_VARS', '_GET', 'HTTP_GET_VARS', '_POST', 'HTTP_POST_VARS', '_COOKIE', 'HTTP_COOKIE_VARS', '_REQUEST', '_SERVER', 'HTTP_SERVER_VARS', '_ENV', 'HTTP_ENV_VARS', '_FILES', 'HTTP_POST_FILES', 'xoopsDB', 'xoopsUser', 'xoopsUserId', 'xoopsUserGroups', 'xoopsUserIsAdmin', 'xoopsConfig', 'xoopsOption', 'xoopsModule', 'xoopsModuleConfig', 'xoopsRequestUri') as \$bad_global ) {
  32          if ( isset( \$_REQUEST[\$bad_global] ) ) {
  33              header( 'Location: '.XOOPS_URL.'/' );
  34              exit();
  35          }
  36      }
  37  ";
  38  $manual = "<h2>" . _MANUAL_INSTRUCTIONS . "</h2>\n<p>" . sprintf( _COPY_RED_LINES, "mainfile.php" ) . "</p>
  39  <pre style='border:1px solid black;width:650px;overflow:auto'><span style='color:#ff0000;font-weight:bold'>$patchCode</span>
  40      if (!isset(\$xoopsOption['nocommon']) && XOOPS_ROOT_PATH != '') {
  41          include XOOPS_ROOT_PATH.\"/include/common.php\";
  42      }
  43  </pre>";
  44          $lines = file( '../mainfile.php' );
  45      
  46          $insert = -1;
  47          $matchProtector = '/modules/protector/include/precheck.inc.php';
  48          $matchDefault = "\$xoopsOption['nocommon']";
  49      
  50          foreach ( $lines as $k => $line ) {
  51              if ( strpos( $line, "\$_REQUEST[\$bad_global]" ) !== false ) {
  52                  // Patch found: do not apply again
  53                  $insert = -2;
  54                  break;
  55              }
  56              if ( strpos( $line, $matchProtector ) || strpos( $line, $matchDefault ) ) {
  57                  $insert = $k;
  58                  break;
  59              }
  60          }
  61          if ( $insert == -1 ) {
  62              printf( _FAILED_PATCH . "<br />", "mainfile.php" );
  63              echo $manual;
  64              return false;
  65          } elseif ( $insert != -2 ) {
  66              if ( !is_writable( '../mainfile.php' ) ) {
  67                  echo 'mainfile.php is read-only. Please allow the server to write to this file, or apply the patch manually';
  68                  echo $manual;
  69                  return false;
  70              } else {
  71                  $fp = fopen( '../mainfile.php', 'wt' );
  72                  if ( !$fp ) {
  73                      echo 'Error opening mainfile.php, please apply the patch manually.';
  74                      echo $manual;
  75                      return false;
  76                  } else {
  77                      $newline = defined( PHP_EOL ) ? PHP_EOL : ( strpos( php_uname(), 'Windows') ? "\r\n" : "\n" );
  78                      $prepend = implode( '', array_slice( $lines, 0, $insert ) );
  79                      $append = implode( '', array_slice( $lines, $insert ) );
  80                      
  81                      $content = $prepend . $patchCode . $append;
  82                      $content = str_replace( array( "\r\n", "\n" ), $newline, $content );
  83                      
  84                      fwrite( $fp,  $content );
  85                      fclose( $fp );
  86                      echo "Patch successfully applied";
  87                  }
  88              }
  89          }
  90          return true;
  91      }
  92  
  93  	function check_auth_db() {
  94          $db = $GLOBALS['xoopsDB'];
  95          $value = getDbValue( $db, 'config', 'conf_id',
  96              "`conf_name` = 'ldap_provisionning' AND `conf_catid` = " . XOOPS_CONF_AUTH
  97          );
  98          return (bool)$value;
  99      }
 100      
 101  	function query( $sql ) {
 102          $db = $GLOBALS['xoopsDB'];
 103          if ( ! ( $ret = $db->queryF( $sql ) ) ) {
 104              echo $db->error();
 105          }
 106      }        
 107  
 108  	function apply_auth_db() {
 109          $db = $GLOBALS['xoopsDB'];
 110          
 111          $cat = getDbValue( $db, 'configcategory', 'confcat_id', "`confcat_name` ='_MD_AM_AUTHENTICATION'" );
 112          if ( $cat !== false && $cat != XOOPS_CONF_AUTH ) {
 113              // 2.2 downgrade bug: LDAP cat is here but has a catid of 0
 114              $db->queryF( "DELETE FROM " . $db->prefix( 'configcategory' ) . " WHERE `confcat_name` ='_MD_AM_AUTHENTICATION' " );
 115              $db->queryF( "DELETE FROM " . $db->prefix( 'config' ) . " WHERE `conf_modid`=0 AND `conf_catid` = $cat" );
 116          }
 117          // Insert config category ( always XOOPS_CONF_AUTH = 7 )
 118             $db->queryF(" INSERT INTO " . $db->prefix("configcategory") . " (confcat_id,confcat_name) VALUES (7,'_MD_AM_AUTHENTICATION')");
 119          // Insert config values
 120          $table = $db->prefix( 'config' );
 121          $data = array(
 122              'auth_method'            => "'_MD_AM_AUTHMETHOD', 'xoops', '_MD_AM_AUTHMETHODDESC', 'select', 'text', 1",
 123              'ldap_port'                => "'_MD_AM_LDAP_PORT', '389', '_MD_AM_LDAP_PORT', 'textbox', 'int', 2 ",
 124              'ldap_server'            => "'_MD_AM_LDAP_SERVER', 'your directory server', '_MD_AM_LDAP_SERVER_DESC', 'textbox', 'text', 3 ",
 125                 'ldap_manager_dn'        => "'_MD_AM_LDAP_MANAGER_DN', 'manager_dn', '_MD_AM_LDAP_MANAGER_DN_DESC', 'textbox', 'text', 5",
 126                 'ldap_manager_pass'        => "'_MD_AM_LDAP_MANAGER_PASS', 'manager_pass', '_MD_AM_LDAP_MANAGER_PASS_DESC', 'textbox', 'text', 6",
 127                 'ldap_version'            => "'_MD_AM_LDAP_VERSION', '3', '_MD_AM_LDAP_VERSION_DESC', 'textbox', 'text', 7",
 128                 'ldap_users_bypass'        => "'_MD_AM_LDAP_USERS_BYPASS', '".serialize(array('admin'))."', '_MD_AM_LDAP_USERS_BYPASS_DESC', 'textarea', 'array', 8",
 129                 'ldap_loginname_asdn'    => "'_MD_AM_LDAP_LOGINNAME_ASDN', 'uid_asdn', '_MD_AM_LDAP_LOGINNAME_ASDN_D', 'yesno', 'int', 9",
 130                 'ldap_loginldap_attr'    => "'_MD_AM_LDAP_LOGINLDAP_ATTR', 'uid', '_MD_AM_LDAP_LOGINLDAP_ATTR_D', 'textbox', 'text', 10",
 131                 'ldap_filter_person'    => "'_MD_AM_LDAP_FILTER_PERSON', '', '_MD_AM_LDAP_FILTER_PERSON_DESC', 'textbox', 'text', 11",
 132                 'ldap_domain_name'        => "'_MD_AM_LDAP_DOMAIN_NAME', 'mydomain', '_MD_AM_LDAP_DOMAIN_NAME_DESC', 'textbox', 'text', 12",
 133                 'ldap_provisionning'    => "'_MD_AM_LDAP_PROVIS', '0', '_MD_AM_LDAP_PROVIS_DESC', 'yesno', 'int', 13",
 134                 'ldap_provisionning_group'    => "'_MD_AM_LDAP_PROVIS_GROUP', 'a:1:{i:0;s:1:\"2\";}', '_MD_AM_LDAP_PROVIS_GROUP_DSC', 'group_multi', 'array', 14",
 135                 'ldap_mail_attr'        => "'_MD_AM_LDAP_MAIL_ATTR', 'mail', '_MD_AM_LDAP_MAIL_ATTR_DESC', 'textbox', 'text', 15",
 136                 'ldap_givenname_attr'    => "'_MD_AM_LDAP_GIVENNAME_ATTR', 'givenname', '_MD_AM_LDAP_GIVENNAME_ATTR_DSC', 'textbox', 'text', 16",
 137                 'ldap_surname_attr'        => "'_MD_AM_LDAP_SURNAME_ATTR', 'sn', '_MD_AM_LDAP_SURNAME_ATTR_DESC', 'textbox', 'text', 17",
 138          );
 139          foreach ( $data as $name => $values ) {
 140              if ( !getDbValue( $db, 'config', 'conf_id', "`conf_modid`=0 AND `conf_catid`=7 AND `conf_name`='$name'" ) ) {
 141                  $this->query(
 142                      "INSERT INTO `$table` (conf_modid,conf_catid,conf_name,conf_title,conf_value,conf_desc,conf_formtype,conf_valuetype,conf_order) " .
 143                      "VALUES ( 0,7,'$name',$values)"
 144                  );
 145              }
 146          }
 147          // Insert auth_method config options
 148          $id = getDbValue( $db, 'config', 'conf_id', "`conf_modid`=0 AND `conf_catid`=7 AND `conf_name`='auth_method'" );
 149          $table = $db->prefix( 'configoption' );
 150          $data = array(
 151              '_MD_AM_AUTH_CONFOPTION_XOOPS' => 'xoops',
 152              '_MD_AM_AUTH_CONFOPTION_LDAP' => 'ldap',
 153              '_MD_AM_AUTH_CONFOPTION_AD' => 'ad',
 154          );
 155          $this->query( "DELETE FROM `$table` WHERE `conf_id`=$id" );
 156          foreach ( $data as $name => $value ) {
 157              $this->query( "INSERT INTO `$table` (confop_name, confop_value, conf_id) VALUES ('$name', '$value', $id)" );
 158          }
 159          return true;
 160      }
 161  }
 162  
 163  $upg = new upgrade_2014();
 164  return $upg;
 165  
 166  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics