├── .DS_Store
├── .project
├── .pydevproject
├── .settings
└── org.eclipse.core.resources.prefs
├── ReadMe.txt
└── src
├── Main.py
├── __init__.py
└── com
├── __init__.py
├── __init__.pyc
└── wyyw
├── __init__.py
├── __init__.pyc
└── iGuard
├── File
├── FileDev.py
├── FileDev.pyc
├── __init__.py
└── __init__.pyc
├── Util
├── UtilTool.py
├── UtilTool.pyc
├── __init__.py
└── __init__.pyc
├── __init__.py
├── __init__.pyc
├── config
├── Config.py
├── Config.pyc
├── __init__.py
└── __init__.pyc
├── core
├── Core.py
├── Core.pyc
├── __init__.py
└── __init__.pyc
└── polling
├── __init__.py
├── __init__.pyc
├── polling.py
└── polling.pyc
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/.DS_Store
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | iGuardForPython
4 |
5 |
6 |
7 |
8 |
9 | org.python.pydev.PyDevBuilder
10 |
11 |
12 |
13 |
14 |
15 | org.python.pydev.pythonNature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.pydevproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | /${PROJECT_DIR_NAME}/src
5 |
6 | python 2.7
7 | Default
8 |
9 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/Main.py=utf-8
3 | encoding//src/com/wyyw/iGuard/config/Config.py=utf-8
4 | encoding//src/com/wyyw/iGuard/core/Core.py=utf-8
5 |
--------------------------------------------------------------------------------
/ReadMe.txt:
--------------------------------------------------------------------------------
1 | 防篡改Py版_V1.0
2 | 依赖模块
3 | wheel
4 | watchdog
5 | 如果没有安装请执行
6 | [>]pip install wheel
7 | [>]pip install watchdog
8 |
9 |
10 | 支持事件触发和时间轮训两种机制
11 | 具体配置详见Config.py
12 | 针对文件/文件夹所有的修改,增加,删除均会进行防篡改处理
13 | 针对修改的文件,新增的文件会做备份处理方便后期查看和调取
14 |
15 |
16 | =========================================
17 | 2020-4-16
18 | 解决两个问题
19 | 1.删除不需要模块引用
20 | 可以不用引用wheel模块了
21 | 2.window 终端打印中文乱码
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/Main.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding=utf-8 -*-
3 | #获取配置文件参数
4 | import thread
5 | import time
6 |
7 | from com.wyyw.iGuard.config.Config import Config
8 | from com.wyyw.iGuard.core.Core import start_watch
9 | from com.wyyw.iGuard.polling.polling import runpolling
10 |
11 |
12 | class Main:
13 | def init(self):
14 | pass
15 | def menu(self):
16 |
17 | print u'1.替代发布'
18 | print u'2.检测目标程序'
19 | print u'3.运行防篡改工具'
20 | str = input(u"请输入菜单编号:")
21 | print str
22 |
23 | def watch(self):
24 | # 事件驱动机制
25 | start_watch(Config.FOLDERPATH,None)
26 | def pollingThread(self):
27 | # 轮询机制
28 | runpolling()
29 | if __name__ == '__main__':
30 | print u"监控文件 : ",Config.FOLDERPATH
31 | main = Main()
32 | try:
33 | print u"启动轮询机制"
34 | thread.start_new_thread(main.pollingThread, ())
35 | print u"启动事件驱动"
36 | thread.start_new_thread(main.watch,())
37 | # 增加线程阻塞
38 | while 1:
39 | time.sleep(0.1)
40 | except Exception ,ex:
41 | print ex.message
42 | pass
43 |
44 |
--------------------------------------------------------------------------------
/src/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/__init__.py
--------------------------------------------------------------------------------
/src/com/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/__init__.py
--------------------------------------------------------------------------------
/src/com/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/__init__.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/__init__.py
--------------------------------------------------------------------------------
/src/com/wyyw/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/__init__.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/File/FileDev.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-*- coding: UTF-8 -*-
3 | '''
4 |
5 | @author: wyyw
6 | '''
7 |
8 |
9 | import hashlib
10 | import os
11 | import shutil
12 |
13 | from com.wyyw.iGuard.Util.UtilTool import UtilTool
14 | from com.wyyw.iGuard.config.Config import Config
15 |
16 |
17 |
18 | class FileDev:
19 | def isExists(self,path):
20 | try:
21 | if(os.path.exists(path)):
22 | return True
23 | else:
24 | return False
25 | except Exception,e:
26 | print e.message
27 | return False
28 | pass
29 | def isFile(self,path):
30 | try:
31 | if(self.isExists(path)):
32 | if(os.path.isfile(path)):
33 | return True
34 | else:
35 | return False
36 | except:
37 | pass
38 | def CalcSha1(self,filepath):
39 | try:
40 | with open(filepath,'rb') as f:
41 | sha1obj = hashlib.sha1()
42 | sha1obj.update(f.read())
43 | hash = sha1obj.hexdigest()
44 | print(hash)
45 | return hash
46 | except:
47 | pass
48 | def CalcMD5(self,filepath):
49 | try:
50 | with open(filepath,'rb') as f:
51 | md5obj = hashlib.md5()
52 | md5obj.update(f.read())
53 | hash = md5obj.hexdigest()
54 | # print(hash)
55 | return hash
56 | except:
57 | pass
58 | def getBigFileMD5(self,filepath):
59 | try:
60 | if self.isFile(filepath):
61 | md5obj = hashlib.md5()
62 | maxbuf = 8192
63 | f = open(filepath,'rb')
64 | while True:
65 | buf = f.read(maxbuf)
66 | if not buf:
67 | break
68 | md5obj.update(buf)
69 | f.close()
70 | hash = md5obj.hexdigest()
71 | return str(hash).upper()
72 | return None
73 | except:
74 | pass
75 | def getFileMD5(self,filepath):
76 | try:
77 | if self.isFile(filepath):
78 | f = open(filepath,'rb')
79 | md5obj = hashlib.md5()
80 | md5obj.update(f.read())
81 | hash = md5obj.hexdigest()
82 | f.close()
83 | return str(hash).upper()
84 | return None
85 | except:
86 | pass
87 |
88 | def removeDir(self,filePath):
89 | try:
90 | shutil.rmtree(filePath)
91 | except:
92 | pass
93 |
94 | def removeFile(self,filePath):
95 | fileDev = FileDev()
96 | utilTool = UtilTool()
97 | try:
98 | pathF = filePath.replace(Config.FOLDERPATH,fileDev.getBackUpF())
99 |
100 | fileDev.mkdirsF(pathF)
101 | endstr = str(utilTool.getTimes())+str(utilTool.getRandom(10000))
102 | pathF = pathF+str(endstr)
103 | # print pathF
104 | fileDev.copyFile(filePath,pathF)
105 | os.remove(filePath)
106 |
107 | floder = os.path.dirname(filePath)
108 | #if not self.isExists(floder):
109 |
110 |
111 |
112 | except Exception ,e:
113 | print e.message
114 | pass
115 | def copyFile(self,filepath,filetopath):
116 | try:
117 | # print 'filepath ',filepath
118 | # print 'filetopath',filetopath
119 |
120 | floder = os.path.dirname(filetopath)
121 | # 判断文件夹是否存在 若不存在就创建一个
122 | if not self.isExists(floder):
123 | os.makedirs(floder)
124 | shutil.copy(filepath, filetopath)
125 | except Exception ,e:
126 | print e.message
127 | pass
128 | def copyFileTree(self,filepath,filetopath):
129 | try:
130 | shutil.copytree(filepath, filetopath)
131 | except Exception ,e:
132 | print e.message
133 | pass
134 | #获取要备份的文件夹 并且以年月日命名
135 | def getBackUpF(self):
136 | fileDev = FileDev()
137 | utilTool = UtilTool()
138 | backupF = Config.BACKUPFOLDERPATH+'/'+utilTool.getData('%Y%m%d')
139 | return backupF
140 | def mkdirsF(self,filePath):
141 | fileDev = FileDev()
142 | # 根据路径获取文件夹路径
143 | paths = os.path.dirname(filePath)
144 | if not fileDev.isExists(paths):
145 | os.makedirs(paths)
146 |
147 | # 迭代文件夹
148 | def iterationFolder(self,filePath):
149 | afiles = []
150 | for root, dirs , files in os.walk(filePath):
151 | for f in files:
152 | afiles.append(root + "/" + f)
153 | return afiles
154 |
155 | # 迭代所有的文件夹(不包含文件名)
156 | def iterationFolderF(self,filepath):
157 | floderList = []
158 | pathDir = os.listdir(filepath)
159 | for allDir in pathDir:
160 | path = filepath+"/"+allDir
161 | if not self.isFile(path):
162 | floderList.append(path)
163 | self.iterationFolderF(path)
164 | return floderList
165 | if __name__ == '__main__':
166 | fileDev = FileDev()
167 | fileDev.eachFile('D:\\Soft\\norsebak')
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/File/FileDev.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/File/FileDev.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/File/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/File/__init__.py
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/File/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/File/__init__.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/Util/UtilTool.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-*- coding: UTF-8 -*-
3 | '''
4 | Created on 2017年1月10日
5 |
6 | @author: developer
7 | '''
8 |
9 |
10 | '''
11 | %y 两位数的年份表示(00-99)
12 | %Y 四位数的年份表示(000-9999)
13 | %m 月份(01-12)
14 | %d 月内中的一天(0-31)
15 | %H 24小时制小时数(0-23)
16 | %I 12小时制小时数(01-12)
17 | %M 分钟数(00=59)
18 | %S 秒(00-59)
19 |
20 | %a 本地简化星期名称
21 | %A 本地完整星期名称
22 | %b 本地简化的月份名称
23 | %B 本地完整的月份名称
24 | %c 本地相应的日期表示和时间表示
25 | %j 年内的一天(001-366)
26 | %p 本地A.M.或P.M.的等价符
27 | %U 一年中的星期数(00-53)星期天为星期的开始
28 | %w 星期(0-6),星期天为星期的开始
29 | %W 一年中的星期数(00-53)星期一为星期的开始
30 | %x 本地相应的日期表示
31 | %X 本地相应的时间表示
32 | %Z 当前时区的名称
33 | %% %号本身
34 | '''
35 |
36 | import random
37 | import time
38 |
39 |
40 | from com.wyyw.iGuard.config.Config import Config
41 |
42 |
43 | class UtilTool:
44 | #获取日期
45 | #localformat 格式化字符串
46 | def getData(self,localformat):
47 | times = time.strftime(localformat,time.localtime(time.time()))
48 | return times
49 | def getRandom(self,nums):
50 | return random.randint(0,nums)
51 | def getTimes(self):
52 | return time.time()
53 | if __name__ == '__main__':
54 | util = UtilTool()
55 | print util.getRandom(100000)
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/Util/UtilTool.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/Util/UtilTool.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/Util/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/Util/__init__.py
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/Util/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/Util/__init__.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/__init__.py
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/__init__.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/config/Config.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding=utf-8 -*-
3 | #获取配置文件参数
4 |
5 | class Config:
6 | #被文件夹路径 (后期期望添加多个文件夹按照|分隔) 也就是要保护网站的根目录
7 | FOLDERPATH= "D:\\RDPback"
8 | #受保护文件夹路径 (当文件被篡改,从该文件夹中获取文件将其替换)
9 | SECFOLDERPATH= "D:\\RDP"
10 | #样本文件夹 将所有的变更的文件进行备份
11 | BACKUPFOLDERPATH="D:\\backup"
12 | #日志文件路径 (系统运行日志存放路径)
13 | LOGPATH= "D://log"
14 | #日志打印级别 从高到低依次是: SEVERE->WARNING->INFO->CONFIG->FINE->FINER->FINESET
15 | LOGLEVEL = "INFO"
16 | #备份文件夹路径(当发现新增,修改操作时,将文件保存到此目录提供样本)
17 | BACKUPPATH="D://log"
18 | #格式化日期 ( 我也不知道干啥的,先留着吧,说不定以后会用的上)
19 | FORMATDATE="%Y%m%d"
20 | #轮询时间 (每间隔时间N,将轮询文件夹,防止事件抓取不准确,单位 毫秒 s)
21 | POOLTIMES= 0.1
22 | # smtp 服务器
23 | SMTP = "smtp.163.com"
24 | # SMTP服务器端口
25 | SMTPPORT = 25
26 | # 发送邮件的邮箱
27 | MAIL_FROM_ADDRES = ""
28 | # 接收邮件的邮箱
29 | MAIL_TO_ADDRESSES = ""
30 | # 邮箱密码
31 | MAIL_PASSWORD = ""
32 |
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/config/Config.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/config/Config.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/config/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/config/__init__.py
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/config/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/config/__init__.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/core/Core.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding=utf-8 -*-
3 | #获取配置文件参数
4 |
5 | '''
6 | Created on 2017年1月4日
7 | 网站防篡改核心类
8 | @author: wyyw
9 | '''
10 |
11 |
12 | import os, sys, time, subprocess
13 | import shutil
14 |
15 | from com.wyyw.iGuard.File.FileDev import FileDev
16 | from com.wyyw.iGuard.config.Config import Config
17 | from watchdog.events import FileSystemEventHandler
18 | from watchdog.observers import Observer
19 |
20 |
21 | class MyFileSystemEventHander(FileSystemEventHandler):
22 |
23 |
24 | fileDev = FileDev()
25 | '''
26 | event.is_directory
27 | 该事件是否由一个目录触发
28 |
29 | event.src_path
30 | 触发该事件的文件或目录路径
31 |
32 | event.event_type
33 | 事件类型,为moved、deleted、created或modified的其中之一
34 |
35 | event.key
36 | 返回元组(event_type, src_path, is_directory)
37 | '''
38 |
39 |
40 | def __init__(self, fn):
41 | super(MyFileSystemEventHander, self).__init__()
42 | self.restart = fn
43 | # 时间处理集合
44 | def on_any_event(self, event):
45 | pass
46 | # print "any_event"
47 | # print event.src_path
48 | # 新增事件
49 | def on_created(self, event):
50 | try:
51 | fileDev = FileDev()
52 | filePath = event.src_path
53 | print "---------------"
54 | print "createrd"
55 | print event.src_path
56 | srcpath = iunion(event.src_path)
57 | # 如果是文件夹创建
58 | if event.is_directory:
59 | print "文件夹事件"
60 | pathX = srcpath.replace(Config.FOLDERPATH,Config.SECFOLDERPATH)
61 | if fileDev.isExists(pathX):
62 | print "发现文件夹,但未处理"
63 | pass
64 | else:
65 | print "删除文件夹"
66 | fileDev.removeDir(filePath)
67 | pass
68 | else : # 如果是文件 需要判断源目录是否存在 如果存在 判断hash值 判断是否相等 如果相等不处理 否则删除掉
69 |
70 | pathX = srcpath.replace(Config.FOLDERPATH,Config.SECFOLDERPATH)
71 | pathX = iunion(pathX)
72 | if fileDev.isExists(pathX):
73 | if fileDev.CalcMD5(pathX) == fileDev.CalcMD5(srcpath):
74 | #print "两个值相等"
75 | pass
76 | else:
77 | fileDev.removeFile(srcpath)
78 | #os.remove(srcpath)
79 | pass
80 | else:
81 | fileDev.removeFile(srcpath)
82 | #os.remove(srcpath)
83 | except:
84 | pass
85 | # 删除文件操作
86 | def on_deleted(self, event):
87 | fileDev = FileDev()
88 | print "---------------"
89 | print "delete"
90 | print event.src_path
91 | srcpath = event.src_path
92 | print event.is_directory
93 | if not fileDev.isFile(srcpath):
94 | pathF = srcpath.replace(Config.FOLDERPATH,Config.SECFOLDERPATH)
95 | print '-----------pathF ',pathF
96 | if fileDev.isExists(pathF):
97 | fileDev.copyFile(pathF, srcpath)
98 | else:
99 | print "不存在的文件夹 ,不做处理"
100 | else:
101 | pathX = event.src_path.replace(Config.FOLDERPATH,Config.SECFOLDERPATH)
102 | if fileDev.isExists(pathX):
103 | print pathX
104 | fileDev.copyFile(pathX, event.src_path)
105 | else:
106 | pass
107 | # 文件修改操作
108 | def on_modified(self, event):
109 | try:
110 | fileDev = FileDev()
111 | print "---------------"
112 | print "modified"
113 | print event.src_path
114 |
115 | # 判断是否为文件夹触发
116 | if event.is_directory:
117 | pass
118 | else:
119 | pathX = event.src_path.replace(Config.FOLDERPATH,Config.SECFOLDERPATH)
120 | if fileDev.isExists(pathX):
121 | if fileDev.CalcMD5(pathX) == fileDev.CalcMD5(event.src_path):
122 | #print "两个值相等"
123 | pass
124 | else:
125 | fileDev.removeFile(event.src_path)
126 | #os.remove(event.src_path)
127 | pass
128 | else:
129 | os.remove(event.src_path)
130 | pass
131 | except:
132 | pass
133 | # 移动文件操作
134 | def on_moved(self, event):
135 | fileDev = FileDev()
136 | print "---------------"
137 | print "moved"
138 | print event.src_path
139 | print event.dest_path
140 | srcpath = event.src_path
141 | destpath = event.dest_path
142 | if event.is_directory:
143 | print "文件夹事件"
144 | pathX = destpath.replace(Config.FOLDERPATH,Config.SECFOLDERPATH)
145 | if fileDev.isExists(pathX):
146 | print "发现文件夹,但未处理"
147 | pass
148 | else:
149 | print "删除文件夹"
150 | fileDev.removeDir(destpath)
151 | pass
152 |
153 | pathF = srcpath.replace(Config.FOLDERPATH,Config.SECFOLDERPATH)
154 | print '-----------pathF ',pathF
155 | if fileDev.isExists(pathF):
156 | fileDev.copyFileTree(pathF, srcpath)
157 | else:
158 | print "不存在的文件夹 ,不做处理"
159 | pass
160 |
161 |
162 | else:
163 | pathX = event.src_path.replace(Config.FOLDERPATH,Config.SECFOLDERPATH)
164 | print pathX
165 | if fileDev.isExists(pathX):
166 | fileDev.copyFile(pathX, event.src_path)
167 | #shutil.copy(pathX, event.src_path)
168 | else:
169 | fileDev.removeFile(event.src_path)
170 | pass
171 |
172 | def iunion(str):
173 | print '--------------------',str
174 | return str
175 | pass
176 |
177 | def start_watch(path, callback):
178 | observer = Observer()
179 | observer.schedule(MyFileSystemEventHander(""), path, recursive=True)
180 | observer.start()
181 | try:
182 | while True:
183 | time.sleep(0.5)
184 | except KeyboardInterrupt:
185 | observer.stop()
186 | observer.join()
187 | if __name__ == '__main__':
188 | start_watch("D:\\Soft\\norsebak", None)
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/core/Core.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/core/Core.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/core/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/core/__init__.py
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/core/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/core/__init__.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/polling/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/polling/__init__.py
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/polling/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/polling/__init__.pyc
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/polling/polling.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-*- coding: UTF-8 -*-
3 | '''
4 | Created on 2017-1-10
5 |
6 | @author: wyyw
7 | '''
8 | import time
9 |
10 | from setuptools.unicode_utils import filesys_decode
11 |
12 | from com.wyyw.iGuard import polling
13 | from com.wyyw.iGuard.File.FileDev import FileDev
14 | from com.wyyw.iGuard.config.Config import Config
15 |
16 |
17 | class pollingFloder:
18 | # 正向比较
19 | # 从源目录的文件与目标目录的文件进行比较
20 | def poolFloder(self):
21 | fileDev = FileDev()
22 | filelist = fileDev.iterationFolder(Config.SECFOLDERPATH)
23 | for srcpath in filelist:
24 | # pathX 目标文件夹
25 | pathX = srcpath.replace(Config.SECFOLDERPATH,Config.FOLDERPATH)
26 |
27 | if fileDev.isExists(pathX):
28 | if fileDev.CalcMD5(pathX) == fileDev.CalcMD5(srcpath):
29 | #print "两个值相等"
30 | pass
31 | else:
32 | fileDev.removeFile(pathX)
33 | fileDev.copyFile(srcpath, pathX)
34 | pass
35 | else:
36 | fileDev.copyFile(srcpath, pathX)
37 | #fileDev.removeFile(srcpath)
38 | pass
39 | def poolingFloderreverse(self):
40 | # 逆向对比 从目标文件夹到源文件夹进行对比
41 | fileDev = FileDev()
42 | #目标文件夹
43 | filelist = fileDev.iterationFolder(Config.FOLDERPATH)
44 | for srcpath in filelist:
45 | # pathX 目标文件夹
46 | pathX = srcpath.replace(Config.FOLDERPATH,Config.SECFOLDERPATH)
47 | # 如果在源文件夹中找不到 那么意味着这是一个篡改文件
48 | if not fileDev.isExists(pathX):
49 | fileDev.removeFile(srcpath)
50 |
51 |
52 | else:
53 | if fileDev.CalcMD5(pathX) == fileDev.CalcMD5(srcpath):
54 | #print "两个值相等"
55 | pass
56 | else:
57 | fileDev.removeFile(srcpath)
58 | fileDev.copyFile(pathX, srcpath)
59 | pass
60 |
61 | # 删除多余的文件夹
62 | def removeFloder(self):
63 | # 逆向对比 从目标文件夹到源文件夹进行对比
64 | fileDev = FileDev()
65 | #目标文件夹
66 | filelist = fileDev.iterationFolderF(Config.FOLDERPATH)
67 | for srcpath in filelist:
68 | # pathX 目标文件夹
69 | pathX = srcpath.replace(Config.FOLDERPATH,Config.SECFOLDERPATH)
70 | # 如果在源文件夹中找不到 那么意味着这是一个篡改文件
71 | if not fileDev.isExists(pathX):
72 | fileDev.removeDir(srcpath)
73 | else:
74 | pass
75 |
76 | def getFloder(self):
77 | pass
78 |
79 | def runing():
80 | print u"轮询开始"
81 |
82 | pollingfloder = pollingFloder()
83 | print u"准备正向对比内容"
84 |
85 | pollingfloder.poolFloder()
86 | print u"正向对比结束"
87 | print u"准备逆向对比"
88 | pollingfloder.poolingFloderreverse()
89 | print u"逆向对比结束"
90 | print u"准备轮询文件夹"
91 | pollingfloder.removeFloder()
92 | print u"文件夹轮询结束"
93 | print u"轮询结束"
94 |
95 | def runpolling():
96 | while 1:
97 | runing()
98 | time.sleep(Config.POOLTIMES)
99 |
100 | if __name__ == '__main__':
101 | runpolling()
102 | # pollingfloder = pollingFloder()
103 | # pollingfloder.poolFloder()
104 | # pollingfloder.poolingFloderreverse()
105 | # pollingfloder.removeFloder()
106 |
107 |
108 |
--------------------------------------------------------------------------------
/src/com/wyyw/iGuard/polling/polling.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naozibuhao/iGuardForPython/c52a931fe70e3e5b12259eb069feaa804ba5ebc8/src/com/wyyw/iGuard/polling/polling.pyc
--------------------------------------------------------------------------------