防篡改php文件校验程序
2015-11-27 11:02
661 查看
<?php /** * 校验线上源文件是否和本地的一致 * User: Administrator * Date: 2015/11/26 * Time: 9:30 */ include_once 'functions.php'; class SrcVerifier { var $md5_files = array(); var $total = 0; public function scan($dir, $prefix_len, $excepts=array()) { if ( $handle = opendir($dir) ) { while ( ($file = readdir($handle)) !== false ) { if ( $file != ".." && $file != "." && $file != ".svn" && $file!=".buildpath" && $file!=".htaccess" && $file!=".idea" && $file!=".project" && $file!=".settings") { $real_location = $dir . "/" . $file; $relative_location = substr($real_location, $prefix_len); if ( is_dir($real_location) ) { echo "[dir] - $relative_location [end]\n"; //$files[$file] = scandir($file_location); if(!in_array($relative_location, $excepts)) { $this->scan($real_location, $prefix_len, $excepts); } }else { $this->md5_files[$relative_location] = md5_file($real_location); echo "[file] - $relative_location , ".$this->md5_files[$relative_location]." \n"; $this->total++; } } } closedir($handle); } } public function list_file($dir, $except_dirs = array()) { $list = scandir($dir); // 得到该文件下的所有文件和文件夹 foreach ($list as $file) {//遍历 $file_location = $dir . "/" . $file;//生成路径 if (is_dir($file_location) && $file != "." && $file != ".." && $file != ".svn") { //判断是不是文件夹 echo "[dir] - $file_location \n"; $this->list_file($file_location); //继续遍历 } elseif (is_file($file_location)) { echo "[file] - $file_location \n"; $this->total++; } } } public function total_files(){ return $this->total; } } $root_path = 'd:/projects/php/test'; $start_time = microtime_float(); //step_1,扫描校验本地源文件,生成文件路径与其md5值之间的映射文件 $verifier = new SrcVerifier(); $verifier->scan($root_path, strlen($root_path), array('/data/files','/temp')); file_put_contents('md5_files.php', '<?php return '.var_export($verifier->md5_files,true));//校验结果写入本地文件 //统计数据 $scan_local_time = microtime_float() - $start_time; echo "scan files: ".$verifier->total_files()."\n"; echo "total cost: {$scan_local_time} secs.\n"; //step_2,遍历刚取下的源文件,并和本地的线上源文件进行md5校验,如果存在不一致的,则写入日志 //step_3,输出校验结果
相关文章推荐
- 转载:PHP,MySQL的安装与配置
- laravel homestead
- PHP 服务器变量$_SERVER 服务器环境变量 $_ENV
- YII2 Gii 服务器上不能访问
- php时间设置为本地
- php +mysql 添加 删除 修改 insert into delete update
- PHP实用函数 过滤数据
- PHP脚本和JAVA连接mysql数据库
- php中curl_multi的应用
- Curl批量打开网址的PHP类,curl_multi_init
- 在PHP代码中经常能看到一些类似PG(), EG()之类的函数,他们都是PHP中定义的宏,这系列宏主要的作用是解决线程安全所写的全局变量包裹宏, 如$PHP_SRC/main/php_globals.
- ftp上传工具类
- php中cookie和session
- Phpcms V9当前栏目及所有二级栏目下内容调用标签
- doubang中tinyRTP传输逻辑
- PHP生成唯一订单号
- php return
- CURL PHP
- PHP通过反射动态加载第三方类和获得类源码的实例
- PHP编程中的__clone()方法使用详解