<?php /** EasySite FireWall 防火墙模块 13:25 2012/7/23 */ define('FW_ADMIN_KEY', '21232f297a57a5a743894a0e4a801fc3'); // 超级管理员密钥 define('FW_IP_RULE_FILE', APP_PATH.'Runtime/Conf/Config.Iprule.php'); $FW_DEFEND_IP_ON = false; // 开启IP规则过滤 $FW_DEFEND_IP_TP = 1; // 开设置IP过滤模式 0-IP黑名单过滤 1-IP白名单过滤 $FW_DEFEND_CC_ON = false; // 开启防恶意刷新 $FW_DEFEND_CC_TL = 5; // 每五次请求最小间隔时间/S if(isset($_GET['fwkey']) || isset($_COOKIE['es_admin_fwkey'])){ $fwkey = isset($_GET['fwkey']) ? trim($_GET['fwkey']) : (isset($_COOKIE['es_admin_fwkey']) ? $_COOKIE['es_admin_fwkey'] : ''); if($fwkey === FW_ADMIN_KEY) $FW_DEFEND_IP_ON = $FW_DEFEND_CC_ON = false; setcookie('es_admin_fwkey', $fwkey, time()+3600*24, SITE_PATH); } if(true === $FW_DEFEND_IP_ON){ $client_ip = get_client_ip2(); $MYFW_LIST = (include FW_IP_RULE_FILE); if(1 === $FW_DEFEND_IP_TP){ $allowed = false; $MYFW_LIST = parse_ip_list($MYFW_LIST['whitelist']); foreach($MYFW_LIST as $ip){ if(preg_match($ip, $client_ip)){ $allowed = true; break; } } if(!$allowed){ header('HTTP/1.1 403 Forbidden'); exit('HTTP/1.1 403 ES FireWall Forbidden : Not allowed IP'); } }else{ $MYFW_LIST = parse_ip_list($MYFW_LIST['blacklist']); foreach($MYFW_LIST as $ip){ if(preg_match($ip, $client_ip)){ header('HTTP/1.1 403 Forbidden'); exit('HTTP/1.1 403 ES FireWall Forbidden : Not allowed IP'); } } } unset($allowed, $client_ip, $MYFW_LIST); } if(true === $FW_DEFEND_CC_ON){ if(!session_id()) session_start(); $nowtime = $lasttime = $_SERVER['REQUEST_TIME']; if(isset($_SESSION['FireWall'])){ $lasttime = intval($_SESSION['FireWall']['lasttime']); $fwtimes = intval($_SESSION['FireWall']['fwtimes']) + (isset($_SERVER['HTTP_X_REQUESTED_WITH']) ? 0 : 1); $_SESSION['FireWall']['fwtimes'] = $fwtimes; if(($nowtime - $lasttime) < $FW_DEFEND_CC_TL){ if($fwtimes >= 5){ header('HTTP/1.1 403 Forbidden'); $_SESSION['FireWall']['lasttime'] = $nowtime; exit('HTTP/1.1 403 ES FireWall Forbidden : Not allowed CC'); } }else{ $_SESSION['FireWall']['fwtimes'] = 0; $_SESSION['FireWall']['lasttime'] = $nowtime; } }else{ $_SESSION['FireWall']['fwtimes'] = 1; $_SESSION['FireWall']['lasttime'] = $nowtime; } unset($nowtime, $lasttime, $fwtimes); } ?>
2. [PHP]代码
<?php /** * 获取客户端IP * @param void * @return String 客户端IP */ function get_client_ip2(){ if(getenv('HTTP_CLIENT_IP')){ $client_ip = getenv('HTTP_CLIENT_IP'); }elseif(getenv('HTTP_X_FORWARDED_FOR')){ $client_ip = getenv('HTTP_X_FORWARDED_FOR'); }elseif(getenv('REMOTE_ADDR')) { $client_ip = getenv('REMOTE_ADDR'); }else{ $client_ip = $HTTP_SERVER_VARS['REMOTE_ADDR']; } return $client_ip; } /** * 解析IP规则列表 * @param void * @return Array IP规则列表 */ function parse_ip_list($rules){ $arr = array(); foreach($rules as $rule){ if($rule['start_time'] > $_SERVER['REQUEST_TIME'] || $rule['end_time'] < $_SERVER['REQUEST_TIME']) continue; $ip = str_replace('.', '\.', $rule['ip']); if($start = strstr($ip, '-')){ $start = substr($ip, 0, - strlen(strrchr($ip, '.')) + 1); $pos = explode('-', trim(strrchr($ip, '.'), '.')); for($i=intval($pos[0]),$a=intval($pos[1])+1; $i < $a; $i++ ){ $arr[] = '#^'.$start.$i.'$#i'; } }elseif($start = strstr($ip, '[')){ $_ips = explode('|', substr($start, 1, -1)); $arr[] = '#^'.substr($ip, 0, - strlen($start)).'(('.implode(')|(',$_ips ).'))'.'$#i'; }elseif(strpos($ip, '*')){ $arr[] = '#^'.str_replace('*', '((25[0-5])|(2[0-4]\\d)|(1\\d{2})|(\\d{1,2}))', $ip).'$#i'; }else{ $arr[] = '#^'.$ip.'$#i'; } } return $arr; } ?>
以上就是EasySite FireWall 防火墙模块的内容,更多相关内容请关注PHP中文网(www.php.cn)!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

Dreamweaver Mac版
시각적 웹 개발 도구

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는
