View file system/inc/include/ip._mass.php

File size: 5.14Kb
<?php
/*
=============================================
 Движок:  SHCMS Engine
=============================================
 Official website: http://shcms.ru
=============================================
 Данный код защищен авторскими правами
=============================================
*/

/*
------------------------
Массивы с настройками
------------------------
*/
$shcms_engine = array();
$set=array(); 

    date_default_timezone_set('Europe/Moscow');
    $time_date = time() + $sdvigclock * 3600;
    $mon = date("m", $time_date);
	
if (substr($mon, 0, 1) == 0) {
    $mon = str_replace("0", "", $mon);
	}
    $day = date("d", $time_date);
if (substr($day, 0, 1) == 0) {
    $day = str_replace("0", "", $day);
	}


    $ip=false;
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])  
                                           && $_SERVER['HTTP_X_FORWARDED_FOR']!='127.0.0.1' 
										   && ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$",$_SERVER['HTTP_X_FORWARDED_FOR'])){
    $ip2['xff']=$_SERVER['HTTP_X_FORWARDED_FOR'];
    $ipa[] = $_SERVER['HTTP_X_FORWARDED_FOR'];}
if(isset($_SERVER['HTTP_CLIENT_IP']) 
                                    && $_SERVER['HTTP_CLIENT_IP']!='127.0.0.1' 
									&& ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$",$_SERVER['HTTP_CLIENT_IP'])){
    $ip2['cl']=$_SERVER['HTTP_CLIENT_IP'];
    $ipa[] = $_SERVER['HTTP_CLIENT_IP'];}
if(isset($_SERVER['REMOTE_ADDR']) 
                                 && ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$",$_SERVER['REMOTE_ADDR'])){
    $ip2['add']=$_SERVER['REMOTE_ADDR'];
    $ipa[] = $_SERVER['REMOTE_ADDR'];}

    $ip=$ipa[0];

    $iplong =ip2long($ip);

if (isset($_SERVER['HTTP_USER_AGENT'])){
    $ua=$_SERVER['HTTP_USER_AGENT'];
    $ua=strtok($ua, '/');
    $ua=strtok($ua, '(');
    $ua=eregi_replace('[^a-z_\./ 0-9\-]', null, $ua);

if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) && ereg('Opera',$ua)){
    $ua_om=$_SERVER['HTTP_X_OPERAMINI_PHONE_UA'];
    $ua_om=strtok($ua_om, '/');
    $ua_om=strtok($ua_om, '(');
    $ua_om=eregi_replace('[^a-z_\. 0-9\-]', null, $ua_om);
    $ua='Opera Mini ('.$ua_om.')';}}else $ua='Нет данных';


    $id = isset ($_REQUEST['id']) ? abs(intval($_REQUEST['id'])) : false;
    $page = isset ($_REQUEST['page']) && $_REQUEST['page'] > 0 ? intval($_REQUEST['page']) : 1;
    $start = isset ($_GET['start']) ? abs(intval($_GET['start'])) : 0;
    $act = isset ($_GET['act']) ? trim($_GET['act']) : '';
    $secure_pass = isset($_GET['secure_pass']) ? trim($_GET['secure_pass']) : '';
    $do = isset ($_GET['do']) ? trim($_GET['do']) : '';
    $agn = htmlentities(substr($_SERVER['HTTP_USER_AGENT'], 0, 100), ENT_QUOTES);





class shcms_ip_ {
    public $ip;
    public $flood_chk = 1; 
    public $flood_interval = '120';   
    public $flood_limit = '50';    
    public $flood_file = "SHCMS_Cache.tmp";  
    private $requests;    

    function __construct() {
        $this->ip = ip2long($this->getip());
        if ($this->flood_chk) {
            $this->requests = $this->reqcount();}
        }

        /*
        -------------------------
        Получаем реальный адрес IP
        -------------------------
        */
    private function getip() {
        if (isset ($_SERVER['HTTP_X_FORWARDED_FOR']) && $this->ip_valid($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
        }elseif ($_SERVER['REMOTE_ADDR']) {
            return $_SERVER['REMOTE_ADDR'];
        }else {
            die('Unknown IP');
        }}
        /*
        ---------------------------------------
        Счетчик числа обращений с данного IP
        ---------------------------------------
        */
    private function reqcount() {
        global $rootpath;
        $tmp = array();
        $requests = 1;
        if (!file_exists('system/tmp/'. $this->flood_file))
        $in = fopen('system/tmp/'. $this->flood_file, "w+");
        else
        $in = fopen('system/tmp/'. $this->flood_file, "r+");
    
        $now = time();
        while ($block = fread($in, 8)) {
        $arr = unpack("Lip/Ltime", $block);
		
        if (($now - $arr['time']) > $this->flood_interval) {
        continue;}
		
        if ($arr['ip'] == $this->ip) {
        $requests++;}
        $tmp[] = $arr;
		}
		
        fseek($in, 0);
        ftruncate($in, 0);
        for ($i = 0; $i < count($tmp); $i++) {
        fwrite($in, pack('LL', $tmp[$i]['ip'], $tmp[$i]['time']));
		}
        fwrite($in, pack('LL', $this->ip, $now));
        fclose($in);
        return $requests;
        }

	/*
	--------------------
	Валидация IP адреса
	--------------------
	*/
    function ip_valid($ip = '') {
        $d = explode('.', $ip);
        for ($x = 0; $x < 4; $x++)
        if (!is_numeric($d[$x]) || ($d[$x] < 0) || ($d[$x] > 255))
        return false;
        return $ip;}
}
$shcms_ip_ = new shcms_ip_();
$vi_shcms = $shcms_ip_->ip;
$ipp = long2ip($ipl);
unset ($shcms_ip_);


?>