<?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文件校验程序的更多相关文章

  1. WebApi系列~安全校验中的防篡改和防复用

    回到目录 web api越来越火,因为它的跨平台,因为它的简单,因为它支持xml,json等流行的数据协议,我们在开发基于面向服务的API时,有个问题一直在困扰着我们,那就是数据的安全,请求的安全,一 ...

  2. 使用数字签名实现数据库记录防篡改(Java实现)

    本文大纲 一.提出问题 二.数字签名 三.实现步骤 四.参考代码 五.后记 六.参考资料 一.提出问题 最近在做一个项目,需要对一个现成的产品的数据库进行操作,增加额外的功能.为此,需要对该产品对数据 ...

  3. 网站如何防Session冒名顶替和cookie防篡改

    做网站难免要面对安全性的问题,诸如sql注入拉,cookie冒名拉,等等,sql注入算是老生常谈,翻翻旧账有不少优秀的帖子在说明这个问题,所以我们来说说Session冒名顶替的风险以及应对的办法. 首 ...

  4. WebAPI 用户认证防篡改实现HMAC(二)签名验证 AbsBaseAuthenticationAttribute--转

    public class ActionFilter : ActionFilterAttribute      {          public override void OnActionExecu ...

  5. UWP项目的包无法通过本地校验程序

    在UWP工程中,我们打出的包Appx需要通过本地的校验程序校验通过后才可以进行商店的提交.在校验程序汇报的不通过原因当中,除了显而易见的因为美术资源不规范.代码调用不合法API等原因之外,还有一些奇怪 ...

  6. Cookie防篡改机制

    一.为什么Cookie需要防篡改 为什么要做Cookie防篡改,一个重要原因是 Cookie中存储有判断当前登陆用户会话信息(Session)的会话票据-SessionID和一些用户信息. 当发起一个 ...

  7. HashTab---Windows资源管理器的文件属性窗口中添加了一个叫做”文件校验”的标签

    HashTab 是一个优秀的 Windows 外壳扩展程序,它在 Windows 资源管理器的文件属性窗口中添加了一个叫做”文件校验”的标签.该标签可以帮助你方便地计算文件的 MD5.SHA1 与 C ...

  8. javascript高级技巧篇(作用域安全、防篡改、惰性载入、节流、自定义事件,拖放)

    安全的类型检测 在任何值上调用Object原生的toString()方法,都会返回一个[object NativeConstructorName]格式字符串.每个类在内部都有一个[[Class]]属性 ...

  9. linux下文件校验的使用

    为解决官方发布的软件包被别人更改或者软件在传输过程中出现传输错误等问题,软件官方在提供软件包的同时,还提供一个保存MD5校验码的文件. Linux/unix中可以使用如下命令获得校验码和官方的校验码对 ...

随机推荐

  1. android开源项目---blog篇

    本文转载于:http://blog.csdn.net/likebamboo/article/details/19081241 主要介绍那些乐于分享并且有一些很不错的开源项目的个人和组织.Follow大 ...

  2. JQ插件jquery.fn.extend与jquery.extend

    jQuery为开发插件提拱了两个方法,分别是: JavaScript代码 jQuery.fn.extend(object); jQuery.extend(object); jQuery.extend( ...

  3. web-api-global-error-handling

    http://www.asp.net/web-api/overview/error-handling/web-api-global-error-handling http://www.cnblogs. ...

  4. I/O Completions port

    http://blogs.technet.com/b/winserverperformance/archive/2008/06/26/designing-applications-for-high-p ...

  5. C# 正则表达式类 Match类和Group类

    @"\b(\S+)://(\S+)\b"; //匹配URL的模式foreach (Match match in mc){ Console.WriteLine(match.Value ...

  6. python数据库连接池

    python数据库连接池 import psycopg2 import psycopg2.pool dbpool=psycopg2.pool.PersistentConnectionPool(1,1, ...

  7. jQuery Ajax请求提交 后台getParameter接收不到数据

    今天遇到的问题,总结一下 jQuery的$ajax({ contentType:"application/json",  //发送信息至服务器时内容编码类型. }) 这样的方式提交 ...

  8. form表单回车提交问题,JS监听回车事件

    我们有时候希望回车键敲在文本框(input element)里来提交表单(form),但有时候又不希望如此.比如搜索行为,希望输入完关键词之后直接按回车键立即提交表单,而有些复杂表单,可能要避免回车键 ...

  9. sqlite-dbeaver-heidisql

    http://www.sqlite.org/ http://www.sqliteexpert.com/ gui工具 这个网站的大部分信息在2015-10-9阅读完毕,下一步是阅读软件自带的帮助文档 将 ...

  10. linux安全

    http://drops.wooyun.org/ 最专业的安全知识分享平台 http://www.freebuf.com/ 关注黑客与极客 http://book.beifabook.com/prod ...