public static function fence($yl_cc) { $c_agentip = 0; (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['HTTP_CLIENT_IP'])) && ($c_agentip = 1); $timestamp = time(); $onlineip = mod_defend::get_ip(); $c_banedip = mod_file::read(PATH_DATA . '/log/banip.txt'); //被banip文件 if ($c_ipoffset = strpos($c_banedip . "\n", "\t" . $onlineip . "\n")) { $c_ltt = (int) substr($c_banedip, $c_ipoffset - 10, 10); // 获取屏蔽的时间 if ($timestamp - $c_ltt < 20) { if ($timestamp - $c_ltt > 5) { mod_file::write(PATH_DATA . '/log/banip.txt', str_replace($c_ltt . "\t" . $onlineip, $timestamp . "\t" . $onlineip, $c_banedip)); } exit("Turn off CC, Please refresh after 20 secs"); } else { mod_file::write(PATH_DATA . '/log/banip.txt', str_replace("\n" . $c_ltt . "\t" . $onlineip, '', $c_banedip)); } } $c_banip_a = explode("\n", $c_banedip); if ($c_agentip == 1 || $yl_cc == 2) { $c_time = 0; if ($c_fp = @fopen(PATH_DATA . '/data/log/ccip.txt', 'rb')) { flock($c_fp, LOCK_SH); $c_size = 27 * 500; fseek($c_fp, -$c_size, SEEK_END); while (!feof($c_fp)) { $c_value = explode("\t", fgets($c_fp, 29)); if ($timestamp - $c_value[0] < 10 && trim($c_value[1]) == $onlineip) { $c_time++; if ($c_time > 15) { break; } } } fclose($c_fp); } if ($c_time > 15) { array_push($c_banip_a, $timestamp . "\t" . $onlineip); $c_banip_a = array_slice($c_banip_a, -150); mod_file::write(PATH_DATA . '/log/banip.txt', implode("\n", $c_banip_a)); exit('Turn off CC'); } if (@filesize(PATH_DATA . '/log/ccip.txt') > 27 * 1000) { mod_file::rm(PATH_DATA . '/log/ccip.txt'); } mod_file::write(PATH_DATA . '/log/ccip.txt', $timestamp . "\t" . $onlineip . "\n", 'ab'); } if (false == self::post_verify()) { exit('undefined_action'); } }
public static function empty_some_cache($cache_name = '') { if (empty($cache_name)) { return false; } if ($dh = opendir(PATH_DATA . '/cache')) { while (false !== ($file = readdir())) { if (strpos($file, $cache_name) !== false) { $cache_content = serialize(array()); $file_path = PATH_DATA . '/cache/' . $file; mod_file::write($file_path, $cache_content); } } } }
/** * MySQL 日志 * * @param string $message * @param string $errno[optional] * @return void */ public static function mysql_log($message, $sql_info = '', $errno = 0) { $message = strtr($message, array($GLOBALS['database']['db_host'] => 'DB_HOST')); // mysql 日志记录 开始 $_postdata = !empty($_POST) ? $_POST : 'NO_POSTDATA'; $record_name = strtr(htmlspecialchars(defined('USERNAME') && USERNAME, ENT_QUOTES), array('|' => '|')); $record_URI = strtr(htmlspecialchars($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], ENT_QUOTES), array('|' => '|')); $timestamp = time(); $onlineip = mod_defend::get_ip(); $new_record = "<?die;?>|{$record_name}|{$record_URI}|{$sql_info}|{$errno}{$message}|{$timestamp}|{$onlineip}|{$_postdata}|\n"; /*$new_record="<?die;?>|$record_name|$record_URI|$msg|$sqlerror|$timestamp|$onlineip|$_postdata|\n";*/ $mysqllogfile = PATH_DATA . '/log/mysql_error.php'; mod_file::write($mysqllogfile, $new_record, 'ab'); }