[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_handlers/ -> e107_class.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |     ©Steve Dunstan 2001-2002
   7  |     http://e107.org
   8  |     jalist@e107.org
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $Source: /cvsroot/e107/e107_0.7/e107_handlers/e107_class.php,v $
  14  |     $Revision: 1.59 $
  15  |     $Date: 2007/02/14 22:15:46 $
  16  |     $Author: e107steved $
  17  +----------------------------------------------------------------------------+
  18  */
  19  
  20  if (!defined('e107_INIT')) { exit; }
  21  
  22  /**
  23   * Core e107 class
  24   *
  25   */
  26  class e107{
  27  
  28      var $server_path;
  29      var $e107_dirs;
  30      var $http_path;
  31      var $https_path;
  32      var $base_path;
  33      var $file_path;
  34      var $relative_base_path;
  35      var $_ip_cache;
  36      var $_host_name_cache;
  37      /**
  38       * e107 class constructor
  39       *
  40       * @param array $e107_paths
  41       * @param string $e107_root_path
  42       * @return e107
  43       */
  44  	function e107($e107_paths, $e107_root_path){
  45          $this->e107_dirs = $e107_paths;
  46          $this->set_paths();
  47          $this->file_path = $this->fix_windows_paths($e107_root_path)."/";
  48      }
  49  
  50  	function set_base_path()
  51      {
  52          global $pref;
  53          $this->base_path = ($pref['ssl_enabled']==1 ?  $this->https_path : $this->http_path);
  54      }
  55  
  56  	function set_paths(){
  57          global $DOWNLOADS_DIRECTORY, $ADMIN_DIRECTORY, $IMAGES_DIRECTORY, $THEMES_DIRECTORY, $PLUGINS_DIRECTORY,
  58          $FILES_DIRECTORY, $HANDLERS_DIRECTORY, $LANGUAGES_DIRECTORY, $HELP_DIRECTORY;
  59          $path = ""; $i = 0;
  60          while (!file_exists("{$path}class2.php")) {
  61              $path .= "../";
  62              $i++;
  63          }
  64          if($_SERVER['PHP_SELF'] == "") { $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME']; }
  65  
  66          $http_path = dirname($_SERVER['PHP_SELF']);
  67          $http_path = explode("/", $http_path);
  68          $http_path = array_reverse($http_path);
  69          $j = 0;
  70          while ($j < $i) {
  71              unset($http_path[$j]);
  72              $j++;
  73          }
  74          $http_path = array_reverse($http_path);
  75          $this->server_path = implode("/", $http_path)."/";
  76          $this->server_path = $this->fix_windows_paths($this->server_path);
  77  
  78          if ($this->server_path == "//") {
  79              $this->server_path = "/";
  80          }
  81          $this->relative_base_path = $path;
  82          $this->http_path = "http://{$_SERVER['HTTP_HOST']}{$this->server_path}";
  83          $this->https_path = "https://{$_SERVER['HTTP_HOST']}{$this->server_path}";
  84          $this->file_path = $path;
  85  
  86          if(!defined("e_HTTP") || !defined("e_ADMIN") )
  87          {
  88              define("e_HTTP", $this->server_path);
  89              define("e_BASE", $this->relative_base_path);
  90              define("e_ADMIN", e_BASE.$ADMIN_DIRECTORY);
  91              define("e_IMAGE", e_BASE.$IMAGES_DIRECTORY);
  92              define("e_THEME", e_BASE.$THEMES_DIRECTORY);
  93              define("e_PLUGIN", e_BASE.$PLUGINS_DIRECTORY);
  94              define("e_FILE", e_BASE.$FILES_DIRECTORY);
  95              define("e_HANDLER", e_BASE.$HANDLERS_DIRECTORY);
  96              define("e_LANGUAGEDIR", e_BASE.$LANGUAGES_DIRECTORY);
  97  
  98              define("e_ADMIN_ABS", e_HTTP.$ADMIN_DIRECTORY);
  99              define("e_IMAGE_ABS", e_HTTP.$IMAGES_DIRECTORY);
 100              define("e_THEME_ABS", e_HTTP.$THEMES_DIRECTORY);
 101              define("e_PLUGIN_ABS", e_HTTP.$PLUGINS_DIRECTORY);
 102              define("e_FILE_ABS", e_HTTP.$FILES_DIRECTORY);
 103              define("e_HANDLER_ABS", e_HTTP.$HANDLERS_DIRECTORY);
 104              define("e_LANGUAGEDIR_ABS", e_HTTP.$LANGUAGES_DIRECTORY);
 105  
 106              define("e_DOCS", e_BASE.$HELP_DIRECTORY);
 107              define("e_DOCROOT", $_SERVER['DOCUMENT_ROOT']."/");
 108  
 109              define("e_DOCS_ABS", e_HTTP.$HELP_DIRECTORY);
 110  
 111              if ($DOWNLOADS_DIRECTORY{0} == "/") {
 112                  define("e_DOWNLOAD", $DOWNLOADS_DIRECTORY);
 113              } else {
 114                  define("e_DOWNLOAD", e_BASE.$DOWNLOADS_DIRECTORY);
 115              }
 116          }
 117      }
 118  
 119  	function fix_windows_paths($path) {
 120          $fixed_path = str_replace(array('\\\\', '\\'), array('/', '/'), $path);
 121          $fixed_path = (substr($fixed_path, 1, 2) == ":/" ? substr($fixed_path, 2) : $fixed_path);
 122          return $fixed_path;
 123      }
 124  
 125      /**
 126       * Check if current user is banned
 127       *
 128       */
 129  	function ban() {
 130          global $sql, $e107, $tp, $pref;
 131          $ban_count = $sql->db_Count("banlist");
 132          if($ban_count)
 133          {
 134              $ip = $this->getip();
 135              $tmp = explode(".",$ip);
 136              $wildcard =  $tmp[0].".".$tmp[1].".".$tmp[2].".*";
 137              $wildcard2 = $tmp[0].".".$tmp[1].".*.*";
 138  
 139              if(varsettrue($pref['enable_rdns']))
 140              {
 141                  $tmp = $e107->get_host_name(getenv('REMOTE_ADDR'));
 142                  preg_match("/[\w]+\.[\w]+$/si", $tmp, $match);
 143                  $bhost = (isset($match[0]) ? " OR banlist_ip='".$tp -> toDB($match[0], true)."'" : "");
 144              }
 145              else
 146              {
 147                  $bhost = "";
 148              }
 149  
 150              if ($ip != '127.0.0.1')
 151              {
 152                  if ($sql->db_Select("banlist", "*", "banlist_ip='".$tp -> toDB($_SERVER['REMOTE_ADDR'], true)."' OR banlist_ip='".USEREMAIL."' OR banlist_ip='{$ip}' OR banlist_ip='{$wildcard}' OR banlist_ip='{$wildcard2}' {$bhost}"))
 153                  {
 154                    header("HTTP/1.1 403 Forbidden", true);
 155                      // enter a message here if you want some text displayed to banned users ...
 156                      exit();
 157                  }
 158              }
 159          }
 160      }
 161  
 162      /**
 163       * Get the current user's IP address
 164       *
 165       * @return string
 166       */
 167  	function getip() {
 168          if(!$this->_ip_cache){
 169              if (getenv('HTTP_X_FORWARDED_FOR')) {
 170                  $ip=$_SERVER['REMOTE_ADDR'];
 171                  if (preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", getenv('HTTP_X_FORWARDED_FOR'), $ip3)) {
 172                  $ip2 = array('#^0\..*#', 
 173                      '#^127\..*#',                             // Local loopbacks
 174                      '#^192\.168\..*#',                         // RFC1918 - Private Network
 175                      '#^172\.(?:1[6789]|2\d|3[01])\..*#',     // RFC1918 - Private network
 176                      '#^10\..*#',                             // RFC1918 - Private Network
 177                      '#^169\.254\..*#',                         // RFC3330 - Link-local, auto-DHCP 
 178                      '#^2(?:2[456789]|[345][0-9])\..*#'        // Single check for Class D and Class E
 179                      );
 180                      $ip = preg_replace($ip2, $ip, $ip3[1]);
 181                  }
 182              } else {
 183                  $ip = $_SERVER['REMOTE_ADDR'];
 184              }
 185              if ($ip == "") {
 186                  $ip = "x.x.x.x";
 187              }
 188              $this->_ip_cache = $ip;
 189          }
 190          return $this->_ip_cache;
 191      }
 192  
 193  	function get_host_name($ip_address) {
 194          if(!$this->_host_name_cache[$ip_address]) {
 195              $this->_host_name_cache[$ip_address] = gethostbyaddr($ip_address);
 196          }
 197          return $this->_host_name_cache[$ip_address];
 198      }
 199  
 200      /**
 201       * Get the current memory usage of the code
 202       *
 203       * @return string memory usage
 204       */
 205  	function get_memory_usage(){
 206          if(function_exists("memory_get_usage")){
 207              $memusage = memory_get_usage();
 208              $memunit = 'b';
 209              if ($memusage > 1048576){
 210                  $memusage = $memusage / 1024;
 211                  $memunit = 'kb';
 212              }
 213              if ($memusage > 1048576){
 214                  $memusage = $memusage / 1024;
 215                  $memunit = 'mb';
 216              }
 217              if ($memusage > 1048576){
 218                  $memusage = $memusage / 1024;
 219                  $memunit = 'gb';
 220              }
 221              return (number_format($memusage, 0).$memunit);
 222          } else {
 223              return ('Unknown');
 224          }
 225      }
 226  
 227  }
 228  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7