Source for file Blacklist.class.php

Documentation is available at Blacklist.class.php

  1. <?php
  2. /**
  3.  * Class Blacklist checks if the user is allowed to be in the chat and inserts the user to the blacklist
  4.  *
  5.  * LICENSE: CREATIVE COMMONS PUBLIC LICENSE  "Namensnennung — Nicht-kommerziell 2.0"
  6.  *
  7.  * @copyright  2009 <SEDesign />
  8.  * @license    http://creativecommons.org/licenses/by-nc/2.0/de/
  9.  * @version    $3.0.6$
  10.  * @link       http://www.sedesign.de/de_produkte_chat-v3.html
  11.  * @since      File available since Alpha 1.0
  12.  */
  13.  
  14. class Blacklist extends EtChatConfig
  15. {
  16.     /**
  17.     * DB-Connection Obj
  18.     * @var ConnectDB 
  19.     */
  20.     private $dbObj;
  21.     
  22.     /**
  23.     * User IP Key
  24.     * @var String 
  25.     */
  26.     public $user_param_all;
  27.     
  28.     /**
  29.     * Time until the user is banned
  30.     * @var String 
  31.     */
  32.     public $user_bann_time;
  33.     
  34.     /**
  35.     * Constructor
  36.     *
  37.     * @param  ConnectDB $dbObj, Obj with the db connection handler
  38.     * @return void 
  39.     */
  40.     public function __construct ($dbObj)
  41.     
  42.         // call parent Constructor from class EtChatConfig
  43.         parent::__construct();
  44.         
  45.         $this->dbObj = $dbObj;
  46.         
  47.         $this->user_param_all = $_SERVER['REMOTE_ADDR']."@".@gethostbyaddr($_SERVER['REMOTE_ADDR'])."@".@getenv('HTTP_X_FORWARDED_FOR');
  48.     }
  49.     
  50.     /**
  51.     * UserInBlacklist,  checks if the curent user IP in zhe Blacklist or has the user browser an actual "black cookie"
  52.     *
  53.     * @uses ConnectDB::sqlGet()
  54.     * @return bool 
  55.     */
  56.     public function userInBlacklist(){    
  57.  
  58.         //look first for a "black cookie". If is set, compare it with the actual datasets in the etchat_blacklist tab
  59.         if(isset($_COOKIE['cookie_etchat_blacklist_ip']&& isset($_COOKIE['cookie_etchat_blacklist_until']))
  60.             $blacklist_c=$this->dbObj->sqlGet("SELECT etchat_blacklist_time FROM {$this->_prefix}etchat_blacklist WHERE etchat_blacklist_ip = '".addslashes($_COOKIE['cookie_etchat_blacklist_ip'])."' and etchat_blacklist_time = ".(int)$_COOKIE['cookie_etchat_blacklist_until']." and etchat_blacklist_time > ".date('U'));
  61.         
  62.         // just compare by IP 
  63.         //echo "SELECT etchat_blacklist_time FROM {$this->_prefix}etchat_blacklist WHERE etchat_blacklist_ip = '".$this->user_param_all."' and etchat_blacklist_time > ".date('U');
  64.         $blacklist=$this->dbObj->sqlGet("SELECT etchat_blacklist_time FROM {$this->_prefix}etchat_blacklist WHERE etchat_blacklist_ip = '".$this->user_param_all."' and etchat_blacklist_time > ".date('U'));
  65.         
  66.         if (is_array($blacklist)) $this->user_bann_time = $blacklist[0][0];
  67.         if (is_array($blacklist_c)) $this->user_bann_time = $blacklist_c[0][0];
  68.         
  69.         // if the user is banned, destroy the session and return true
  70.         if (is_array($blacklist|| is_array($blacklist_c)) return true;
  71.         else return false;
  72.     }
  73.     
  74.     /**
  75.     * AllowedToAndSetCookie, return true if done
  76.     *
  77.     * @uses ConnectDB::sqlGet()    
  78.     * @uses ConnectDB::sqlSet()    
  79.     * @return bool
  80.     */
  81.     public function allowedToAndSetCookie(){
  82.         $rechte_zum_sperren=$this->dbObj->sqlGet("select etchat_userprivilegien FROM {$this->_prefix}etchat_user where etchat_user_id = ".$_SESSION['etchat_'.$this->_prefix.'user_id']);
  83.         if ($rechte_zum_sperren[0][0]!="admin" && $rechte_zum_sperren[0][0]!="mod"){
  84.             $this->dbObj->sqlSet("DELETE FROM {$this->_prefix}etchat_useronline WHERE etchat_onlineuser_fid = ".$_SESSION['etchat_'.$this->_prefix.'user_id']);
  85.             setcookie("cookie_etchat_blacklist_until"$this->user_bann_time$this->user_bann_time"/")
  86.             setcookie("cookie_etchat_blacklist_ip"$this->user_param_all$this->user_bann_time"/");
  87.             return true;
  88.         }
  89.         else return false;
  90.     }    
  91.     
  92.     /**
  93.     * insertUser into the blacklist table
  94.     *
  95.     * @param  int $userID
  96.     * @param  int $time, Unix time
  97.     * @uses ConnectDB::sqlGet()    
  98.     * @uses ConnectDB::sqlSet()    
  99.     * @return bool
  100.     */
  101.     public function insertUser($userID,$time){
  102.         $rechte_zum_sperren=$this->dbObj->sqlGet("select etchat_userprivilegien FROM {$this->_prefix}etchat_user where etchat_user_id = ".$userID);
  103.         if ($rechte_zum_sperren[0][0]!="admin" && $rechte_zum_sperren[0][0]!="mod"){
  104.             $ip=$this->dbObj->sqlGet("SELECT etchat_onlineip FROM {$this->_prefix}etchat_useronline WHERE etchat_onlineuser_fid = ".$userID);
  105.             $time_to_hold = date("U")+$time; 
  106.             $this->dbObj->sqlSet("INSERT INTO {$this->_prefix}etchat_blacklist (etchat_blacklist_ip, etchat_blacklist_userid, etchat_blacklist_time) VALUES ('".$ip[0][0]."', ".$userID.", ".$time_to_hold.")");
  107.             return true;
  108.         }
  109.         else return false;
  110.     }    
  111.     
  112.     /**
  113.     * killUserSession, if the user is in blacklist
  114.     *
  115.     * @return void
  116.     */
  117.     public function killUserSession(){    
  118.         @session_unset();
  119.         @session_destroy();
  120.     }

Documentation generated on Tue, 22 Dec 2009 09:42:45 +0100 by phpDocumentor 1.4.1