mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-09 15:00:21 -04:00
Merge branch 'development' of github.com:Rushilwiz/SkoolOS into development
This commit is contained in:
commit
7a05627a98
|
@ -569,7 +569,7 @@ class Teacher:
|
|||
'due_date': str(due),
|
||||
'owner':self.id
|
||||
}
|
||||
postDB(self.username, self.password, ass, 'http://127.0.0.1:8000/api/assignments/')
|
||||
print(postDB(self.username, self.password, ass, 'http://127.0.0.1:8000/api/assignments/'))
|
||||
course['assignments'].append(oname)
|
||||
|
||||
cinfo = {
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
Start time: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Opened file
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/bgservice/run.py
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Created file
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/bgservice.run.html
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Opened file
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/bgservice.run.html
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
wrote bgservice.run.html
|
||||
Event: Wrote to a file
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/bgservice.run.html
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Opened file
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/bgservice/__pycache__/test.cpython-38.pyc
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Opened file
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/bgservice/test.py
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Created file
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/bgservice/__pycache__/test.cpython-38.pyc.139630150929712
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Opened file
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/bgservice/__pycache__/test.cpython-38.pyc.139630150929712
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Wrote to a file
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/bgservice/__pycache__/test.cpython-38.pyc.139630150929712
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Moved a file out
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/bgservice/__pycache__/test.cpython-38.pyc.139630150929712
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Moved a file in
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/bgservice/__pycache__/test.cpython-38.pyc
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Created file
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/SkoolOS/logs/skoolos_06162020-221848
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
||||
Event: Opened file
|
||||
Event Path: /home/nkenschaft/Sysadmin/skoolos/SkoolOS/logs/skoolos_06162020-221848
|
||||
Timestamp: Tuesday, June 16, 2020 22:18:48
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
416690
SkoolOS/logs/skooloslog
Normal file
416690
SkoolOS/logs/skooloslog
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -25,7 +25,7 @@ class AssignmentSerializer(serializers.HyperlinkedModelSerializer):
|
|||
class Meta:
|
||||
model = Assignment
|
||||
# fields = ['url','name', 'due_date', 'path' , "Class","teacher",'owner']
|
||||
fields = ['name', 'due_date', 'path' ,"teacher",'owner']
|
||||
fields = ['name', 'due_date', 'path' ,'teacher','owner']
|
||||
|
||||
class ClassSerializer(serializers.ModelSerializer):
|
||||
# assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -7,10 +7,184 @@ import time
|
|||
import sys
|
||||
import os
|
||||
import pyinotify
|
||||
from . import checker
|
||||
from pathlib import Path
|
||||
from glob import glob
|
||||
|
||||
|
||||
NOTIFIER = None
|
||||
STDOUT = sys.stdout
|
||||
DIR = None
|
||||
START_TIME = None
|
||||
|
||||
|
||||
def watch_dir(watched_dir=str(Path.home()), log_dir="SkoolOS/logs"):
|
||||
"""
|
||||
Watches the specified directory for changes and outputs it in
|
||||
human readable format to a log file in the specified log directory.
|
||||
param watched_dir: directory to watch for changes
|
||||
param log_dir: directory to store log files
|
||||
return: none
|
||||
"""
|
||||
global DIR
|
||||
global START_TIME
|
||||
global NOTIFIER
|
||||
DIR = watched_dir
|
||||
if not os.path.exists(log_dir):
|
||||
os.makedirs(log_dir)
|
||||
logfile_ = log_dir + "/skooloslog"
|
||||
if os.path.isfile(logfile_):
|
||||
os.remove(logfile_)
|
||||
logfile = open(logfile_, 'w')
|
||||
START_TIME = time.time()
|
||||
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
|
||||
NOTIFIER = pyinotify.ThreadedNotifier(wm, EventHandler())
|
||||
NOTIFIER.start()
|
||||
sys.stdout = open("/dev/null", 'w')
|
||||
wm.add_watch(watched_dir, mask, rec=True)
|
||||
time.sleep(1)
|
||||
sys.stdout = logfile
|
||||
print("Start time: " +
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime()) + "\n")
|
||||
|
||||
|
||||
def stop_watching():
|
||||
"""
|
||||
Stops the watch started by watch_dir()
|
||||
return: none
|
||||
"""
|
||||
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)))
|
||||
print("\n" + shell_check())
|
||||
suspicious_files = 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
|
||||
|
||||
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():
|
||||
"""
|
||||
Check .bash_history and .histfile for git commands that could interfere with SkoolOS
|
||||
return: results of the 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')
|
||||
]
|
||||
suspicious_commands = []
|
||||
for i in bash_history + zsh_history:
|
||||
if "git" in i:
|
||||
suspicious_commands.append(i)
|
||||
if suspicious_commands:
|
||||
return str(
|
||||
len(suspicious_commands)
|
||||
) + " suspicious commands found:\n" + "\n".join(suspicious_commands)
|
||||
return "Nothing suspicious found in bash or zsh history."
|
||||
|
||||
|
||||
def verify_file(file_):
|
||||
"""
|
||||
Check if the file name has an extension in the list of whitelisted file exentsions
|
||||
param file_: path to file
|
||||
return: whether or not the file's extension is whitelisted
|
||||
"""
|
||||
for ext in file_whitelist:
|
||||
if len(file_) > len(ext):
|
||||
if file_[len(file_) - len(ext):] == ext:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def file_check(dir_):
|
||||
"""
|
||||
Checks specified dir_ for non-whitelisted files using verify_file()
|
||||
param dir_: directory to check
|
||||
return: list of suspicious files
|
||||
"""
|
||||
files = glob(dir_ + "/**/*", recursive=True)
|
||||
suspicious_files = []
|
||||
for file_ in files:
|
||||
if not verify_file(file_):
|
||||
suspicious_files.append(file_)
|
||||
return suspicious_files
|
||||
|
||||
class EventHandler(pyinotify.ProcessEvent):
|
||||
"""
|
||||
Custom event handler for watching a SkoolOS work directory
|
||||
|
@ -113,63 +287,3 @@ class EventHandler(pyinotify.ProcessEvent):
|
|||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime())
|
||||
)
|
||||
print(description)
|
||||
|
||||
|
||||
NOTIFIER = None
|
||||
STDOUT = sys.stdout
|
||||
DIR = None
|
||||
START_TIME = None
|
||||
|
||||
|
||||
def watch_dir(watched_dir=str(Path.home()), log_dir="SkoolOS/logs"):
|
||||
"""
|
||||
Watches the specified directory for changes and outputs it in
|
||||
human readable format to a log file in the specified log directory.
|
||||
param watched_dir: directory to watch for changes
|
||||
param log_dir: directory to store log files
|
||||
return: none
|
||||
"""
|
||||
global DIR
|
||||
global START_TIME
|
||||
global NOTIFIER
|
||||
DIR = watched_dir
|
||||
if not os.path.exists(log_dir):
|
||||
os.makedirs(log_dir)
|
||||
logfile_ = log_dir + "/skooloslog"
|
||||
if os.path.isfile(logfile_):
|
||||
os.remove(logfile_)
|
||||
logfile = open(logfile_, 'w')
|
||||
START_TIME = time.time()
|
||||
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
|
||||
NOTIFIER = pyinotify.ThreadedNotifier(wm, EventHandler())
|
||||
NOTIFIER.start()
|
||||
sys.stdout = open("/dev/null", 'w')
|
||||
wm.add_watch(watched_dir, mask, rec=True)
|
||||
time.sleep(1)
|
||||
sys.stdout = logfile
|
||||
print("Start time: " +
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime()) + "\n")
|
||||
|
||||
|
||||
def stop_watching():
|
||||
"""
|
||||
Stops the watch started by watch_dir()
|
||||
return: none
|
||||
"""
|
||||
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)))
|
||||
print("\n" + checker.shell_check())
|
||||
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
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
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():
|
||||
"""
|
||||
Check .bash_history and .histfile for git commands that could interfere with SkoolOS
|
||||
return: results of the 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')
|
||||
]
|
||||
suspicious_commands = []
|
||||
for i in bash_history + zsh_history:
|
||||
if "git" in i:
|
||||
suspicious_commands.append(i)
|
||||
if suspicious_commands:
|
||||
return str(
|
||||
len(suspicious_commands)
|
||||
) + " suspicious commands found:\n" + "\n".join(suspicious_commands)
|
||||
return "Nothing suspicious found in bash or zsh history."
|
||||
|
||||
|
||||
def verify_file(file_):
|
||||
"""
|
||||
Check if the file name has an extension in the list of whitelisted file exentsions
|
||||
param file_: path to file
|
||||
return: whether or not the file's extension is whitelisted
|
||||
"""
|
||||
for ext in file_whitelist:
|
||||
if len(file_) > len(ext):
|
||||
if file_[len(file_) - len(ext):] == ext:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def file_check(dir_):
|
||||
"""
|
||||
Checks specified dir_ for non-whitelisted files using verify_file()
|
||||
param dir_: directory to check
|
||||
return: list of suspicious files
|
||||
"""
|
||||
files = glob(dir_ + "/**/*", recursive=True)
|
||||
suspicious_files = []
|
||||
for file_ in files:
|
||||
if not verify_file(file_):
|
||||
suspicious_files.append(file_)
|
||||
return suspicious_files
|
|
@ -1 +1 @@
|
|||
Subproject commit b80d7ed56b7d649a74be4e7f906d26e7be43702d
|
||||
Subproject commit d9cbcc1e6dd8907bf856f30b4565018e48934abf
|
31
skoolos.py
31
skoolos.py
|
@ -18,7 +18,7 @@ import datetime
|
|||
import os
|
||||
import argparse
|
||||
import webbrowser
|
||||
#from bgservice import bgservice as bg
|
||||
from bgservice import bgservice as bg
|
||||
import atexit
|
||||
|
||||
client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6'
|
||||
|
@ -88,11 +88,9 @@ def main():
|
|||
USER = data['username']
|
||||
print(data['username'])
|
||||
if data['is_student']:
|
||||
# empty_logs()
|
||||
# bg.watch_dir()
|
||||
# atexit.register(stop_bg_service)
|
||||
studentCLI(USER, PWD)
|
||||
|
||||
atexit.register(stop_bg_service)
|
||||
else:
|
||||
teacherCLI(USER, PWD)
|
||||
|
||||
|
@ -100,21 +98,16 @@ def main():
|
|||
#################################################################################################### STUDENT METHODS
|
||||
|
||||
def stop_bg_service():
|
||||
#bg.stop_watching()
|
||||
cur_path = os.path.dirname(__file__)
|
||||
#newpath = os.path.relpath('bgservice/SkoolOS/logs')
|
||||
|
||||
# def empty_logs():
|
||||
# logs_folder = os.path.dirname(__file__) + 'bgservice/SkoolOS/logs/'
|
||||
# for filename in os.listdir(logs_folder):
|
||||
# file_path = os.path.join(folder, filename)
|
||||
# try:
|
||||
# if os.path.isfile(file_path) or os.path.islink(file_path):
|
||||
# os.unlink(file_path)
|
||||
# elif os.path.isdir(file_path):
|
||||
# shutil.rmtree(file_path)
|
||||
# except Exception as e:
|
||||
# print('Failed to delete %s. Reason: %s' % (file_path, e))
|
||||
print("good")
|
||||
bg.stop_watching()
|
||||
print('also')
|
||||
cur_path = os.path.dirname('') # Change to definite SkoolOS dir
|
||||
print('yes')
|
||||
newpath = os.path.relpath('bgservice/SkoolOS/logs/')
|
||||
logText = ""
|
||||
with open(newpath + '/skooloslog', 'r') as logfile:
|
||||
logfile.read()
|
||||
print (logText)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user