mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
finalized checker.py
This commit is contained in:
parent
76db4476d2
commit
04ce324566
|
@ -2,6 +2,7 @@ import time
|
|||
import sys
|
||||
import os
|
||||
import pyinotify
|
||||
import checker
|
||||
|
||||
|
||||
class EventHandler(pyinotify.ProcessEvent):
|
||||
|
@ -77,18 +78,24 @@ class EventHandler(pyinotify.ProcessEvent):
|
|||
|
||||
NOTIFIER = None
|
||||
STDOUT = sys.stdout
|
||||
DIR = None
|
||||
START_TIME = None
|
||||
|
||||
|
||||
def watch_dir(watched_dir="/tmp", logdir="/tmp/skooloslogs"):
|
||||
global DIR
|
||||
global START_TIME
|
||||
global NOTIFIER
|
||||
DIR = watched_dir
|
||||
if not os.path.exists(logdir):
|
||||
os.makedirs(logdir)
|
||||
logfile = open(
|
||||
logdir + "/skoolos_" +
|
||||
time.strftime("%m%d%Y-%H%M%S", time.localtime()), 'w')
|
||||
sys.stdout = logfile
|
||||
START_TIME = time.time()
|
||||
print("Start time: " +
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime()) + "\n\n")
|
||||
global NOTIFIER
|
||||
wm = pyinotify.WatchManager()
|
||||
mask = pyinotify.IN_CREATE | pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE | \
|
||||
pyinotify.IN_MOVED_TO | pyinotify.IN_MOVED_FROM | pyinotify.IN_OPEN
|
||||
|
@ -99,7 +106,17 @@ def watch_dir(watched_dir="/tmp", logdir="/tmp/skooloslogs"):
|
|||
|
||||
def stop_watching():
|
||||
NOTIFIER.stop()
|
||||
now = time.time()
|
||||
print("End time: " +
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime()))
|
||||
print("\nTotal work time: " +
|
||||
time.strftime("%H:%M:%S", time.gmtime(now - START_TIME)))
|
||||
suspicious_files = checker.file_check(DIR)
|
||||
if suspicious_files != []:
|
||||
print(
|
||||
"\n\n--------------------------------------------------\n\n\n" +
|
||||
"WARNING: One or more file did not have file extensions that are acceptable.\n"
|
||||
+ "The paths to these files are listed below:\n")
|
||||
print(*suspicious_files, sep='\n')
|
||||
sys.stdout = STDOUT
|
||||
print("Done watching.\n")
|
||||
|
|
|
@ -1,9 +1,80 @@
|
|||
import os
|
||||
from glob import glob
|
||||
|
||||
file_whitelist = [
|
||||
# text and document files
|
||||
".doc",
|
||||
".docx",
|
||||
".odt",
|
||||
".pdf",
|
||||
".rtf",
|
||||
".tex",
|
||||
".txt",
|
||||
".wpd",
|
||||
# video files
|
||||
".3g2",
|
||||
".3gp",
|
||||
".avi",
|
||||
".flv",
|
||||
".h264",
|
||||
".m4v",
|
||||
".mkv",
|
||||
".mov",
|
||||
".mp4",
|
||||
".mpg",
|
||||
".mpeg",
|
||||
".rm",
|
||||
".swf",
|
||||
".vob",
|
||||
".wmv",
|
||||
# spreadsheet files
|
||||
".ods",
|
||||
".xls",
|
||||
".xlsm",
|
||||
".xlsx",
|
||||
".csv",
|
||||
# programming files
|
||||
".c",
|
||||
".class",
|
||||
".cpp",
|
||||
".cs",
|
||||
".go",
|
||||
".h",
|
||||
".java",
|
||||
".pl",
|
||||
".sh",
|
||||
".swift",
|
||||
".vb",
|
||||
# presentation files
|
||||
".key",
|
||||
".odp",
|
||||
".pps",
|
||||
".ppt",
|
||||
".pptx",
|
||||
# image files
|
||||
".ai",
|
||||
".bmp",
|
||||
".gif",
|
||||
".ico",
|
||||
".jpeg",
|
||||
".jpg",
|
||||
".png",
|
||||
".ps",
|
||||
".psd",
|
||||
".svg",
|
||||
".tif",
|
||||
".tiff",
|
||||
]
|
||||
|
||||
|
||||
def shell_check():
|
||||
bash_history = [line.strip() for line in open(os.path.expanduser("~/.bash_history"), 'r')]
|
||||
zsh_history = [line.strip() for line in open(os.path.expanduser("~/.histfile"), 'r')]
|
||||
bash_history = [
|
||||
line.strip()
|
||||
for line in open(os.path.expanduser("~/.bash_history"), 'r')
|
||||
]
|
||||
zsh_history = [
|
||||
line.strip() for line in open(os.path.expanduser("~/.histfile"), 'r')
|
||||
]
|
||||
report = "Suspicios commands found:\n"
|
||||
for i in bash_history + zsh_history:
|
||||
if "git" in i:
|
||||
|
@ -13,5 +84,17 @@ def shell_check():
|
|||
return "Nothing suspicious found in bash or zsh history."
|
||||
|
||||
|
||||
def file_check(dir_):
|
||||
def verify_file(file_):
|
||||
for ext in file_whitelist:
|
||||
if file_[len(file_) - len(ext):] == ext:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def file_check(dir_):
|
||||
files = glob(dir_ + "/**/*", recursive=True)
|
||||
suspicious_files = []
|
||||
for file_ in files:
|
||||
if not verify_file(file_):
|
||||
suspicious_files.append(file_)
|
||||
return suspicious_files
|
||||
|
|
Loading…
Reference in New Issue
Block a user