mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-03 20:20:18 -04:00
Merge branch 'development' of https://github.com/Rushilwiz/SkoolOS into development
This commit is contained in:
commit
9e50b60b62
|
@ -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
|
@ -10,6 +10,7 @@ class Student(models.Model):
|
|||
grade = models.IntegerField(default=0, blank=True)
|
||||
log = models.TextField(default="", blank=True)
|
||||
git=models.CharField(default="", max_length=100, blank=True)
|
||||
log = models.TextField(default="", blank=True)
|
||||
repo=models.URLField(default="", blank=True)
|
||||
classes=models.CharField(max_length=100, default="", blank=True)
|
||||
added_to=models.CharField(max_length=100, default="", blank=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
|
|
@ -17,8 +17,8 @@ Enter the valid SkoolOS username and password. Congratialations, you have succes
|
|||
1. CLI as a teacher:
|
||||
============
|
||||
|
||||
Start the CLI and select your username. For instance, teacher 'eharris1'::
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
python skoolos.py
|
||||
? Select User: (Use arrow keys)
|
||||
1) 2022rkhondak
|
||||
|
@ -140,13 +140,88 @@ work at ANY TIME. Simply go to the 'Students' directory and select the student's
|
|||
eharris1/Students/English12_eharris1/2022rkhondak
|
||||
eharris1/Students/English12_eharris1/2023rumareti
|
||||
|
||||
:
|
||||
? Select option: (Use arrow keys)
|
||||
1) Request Student
|
||||
OR
|
||||
|
||||
? Add Students): 1) Add individual student
|
||||
Student name: 2022rkhondak
|
||||
|
||||
Accessing an existing class
|
||||
=====================
|
||||
|
||||
Once you have created a class, you can then view and modify certain fields. (Open opening a class, any students who have accepted the request will be automatically
|
||||
added you the class.)
|
||||
|
||||
? Select class: (Use arrow keys)
|
||||
Art12_eharris1
|
||||
Civ_eharris1
|
||||
❯ English12_eharris1
|
||||
History12_eharris1
|
||||
Random_eharris1
|
||||
Truck_eharris1
|
||||
Make New Class
|
||||
Exit SkoolOS
|
||||
|
||||
Class: English12_eharris1
|
||||
? Select option: (Use arrow keys)
|
||||
❯ 1) Request Student
|
||||
2) Add assignment
|
||||
❯ 3) View student information
|
||||
3) View student information
|
||||
4) Exit
|
||||
|
||||
Requesting Students
|
||||
-------
|
||||
|
||||
Select 'Request Student'. You will then be prompted to add students. If you have a list of students, enter the relative path of a text file with the student usernames.
|
||||
The file must be a .txt file and have one student username per line. If you add an individual student, simply enter their ion username.
|
||||
one username per line.
|
||||
|
||||
Class: English12_eharris1
|
||||
? Select option: (Use arrow keys)
|
||||
❯ 1) Request Student
|
||||
2) Add assignment
|
||||
3) View student information
|
||||
4) Exit
|
||||
|
||||
? Add list of students (input path): (Use arrow keys)
|
||||
❯ 1) Add individual student
|
||||
2) Add list of students through path
|
||||
3) Exit
|
||||
|
||||
? Select option: 1) Request Student
|
||||
? Add list of students (input path): 1) Add individual student
|
||||
? Student Name: 2022rkhondak
|
||||
|
||||
OR
|
||||
|
||||
? Add Students): 2) Add list of students through path
|
||||
File must be .txt and have 1 student username per line
|
||||
Relative Path: students.txt
|
||||
|
||||
Adding Assignments
|
||||
-------
|
||||
|
||||
To add an assignment, you must first make a subdirectory for that assignment in the given class. You must then add a file wihin that subdirectory. For Example:
|
||||
For teacher eharris1 and class English11_eharris1, valid assignment folder would look like:
|
||||
|
||||
eharris1/English11_eharris1/Assignment1/instructions.txt
|
||||
|
||||
Then, select an assignment from the given options. Then enter a due date in the correct format: YYYY-MM-DD HH:MM. The assignment will then be coppied to every student
|
||||
who has confirmed the class.
|
||||
|
||||
Class: Truck_eharris1
|
||||
GET:200
|
||||
? Select option: (Use arrow keys)
|
||||
1) Request Student
|
||||
❯ 2) Add assignment
|
||||
3) View student information
|
||||
4) Exit
|
||||
|
||||
? Select new assignment: (Use arrow keys)
|
||||
❯ Assignment1
|
||||
|
||||
? Select new assignment: Assignment1
|
||||
Enter due date (Example: 2020-08-11 16:58): 2020-08-11 16:58
|
||||
|
||||
Students in class:
|
||||
2022rkhondak
|
||||
Requsted Students:
|
||||
|
|
|
@ -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