Merge pull request #13 from Rushilwiz/development

Development
This commit is contained in:
Rushil Umaretiya 2020-06-16 13:46:49 -04:00 committed by GitHub
commit a1537106db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 9 deletions

View File

@ -18,7 +18,10 @@ if(outputs['init']):
#already ccrerrated account through website, has to login #already ccrerrated account through website, has to login
def update(): def update():
#get data from database """
Gets data from the database
:return:
"""
return return
def yesorno(question): def yesorno(question):
@ -35,6 +38,10 @@ def yesorno(question):
return False return False
def login(): def login():
"""
Login to the website with a username and password
:return: user information json if successful, None otherwise
"""
#enter username #enter username
#enter password #enter password
questions = [ questions = [
@ -66,6 +73,11 @@ def login():
#did not create account through website, has to signup/login #did not create account through website, has to signup/login
def signup(): def signup():
"""
Used to create an account for the service.
Called if the user does not have an existing account and must create one.
:return: the new user account
"""
questions = [ questions = [
{ {
'type': 'input', 'type': 'input',
@ -114,6 +126,10 @@ def signup():
return user return user
def relogin(): def relogin():
"""
Login to an already verified user account
:return:
"""
questions = [ questions = [
{ {
'type': 'list', 'type': 'list',
@ -128,12 +144,21 @@ def relogin():
def setup(user): def setup(user):
#Read classes/assignenments and setup directory: #Read classes/assignenments and setup directory:
#SkoolOS/Math/Week1 #SkoolOS/Math/Week1
"""
Reads classes and assignments of/for the user and properly sets of their work directory
:param user:
:return:
"""
for c in user["classes"]: for c in user["classes"]:
os.makedirs(c) os.makedirs(c)
for a in user["classes"][c]: for a in user["classes"][c]:
os.makedirs(c + "/" + a) os.makedirs(c + "/" + a)
def start(): def start():
"""
Prompts the user for whether or not they have an account and allows them to login/signup depending on their response
:return:
"""
if(os.path.exists(".login.txt") == False): if(os.path.exists(".login.txt") == False):
b = yesorno("Do you have a SkoolOS account?(y/N)") b = yesorno("Do you have a SkoolOS account?(y/N)")
if(b): if(b):

View File

@ -5,7 +5,7 @@ import secrets
class Student(models.Model): class Student(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE) user = models.OneToOneField(User, blank=True, on_delete=models.CASCADE)
ion_user = models.CharField(max_length=100, primary_key=True) ion_user = models.CharField(max_length=100, primary_key=True)
grade = models.IntegerField(default=0, blank=True) grade = models.IntegerField(default=0, blank=True)
git=models.CharField(default="", max_length=100, blank=True) git=models.CharField(default="", max_length=100, blank=True)
@ -20,8 +20,9 @@ class Student(models.Model):
def __str__(self): def __str__(self):
return f"{self.user.username}'s Profile" return f"{self.user.username}'s Profile"
class Assignment(models.Model): class Assignment(models.Model):
owner = models.ForeignKey('auth.User', related_name='aowner', on_delete=models.CASCADE) owner = models.ForeignKey(User, null=True, blank=True, related_name='aowner', on_delete=models.CASCADE)
name=models.CharField(max_length=100, primary_key=True) name=models.CharField(max_length=100, primary_key=True)
due_date=models.DateTimeField() due_date=models.DateTimeField()
@ -33,8 +34,9 @@ class Assignment(models.Model):
def __str__(self): def __str__(self):
return '%s' % (self.name) return '%s' % (self.name)
class Class(models.Model): class Class(models.Model):
owner = models.ForeignKey('auth.User', related_name='cowner', on_delete=models.CASCADE) owner = models.ForeignKey(User, null=True, blank=True, related_name='cowner', on_delete=models.CASCADE)
teacher = models.CharField(max_length=100) teacher = models.CharField(max_length=100)
name = models.CharField(primary_key=True, max_length=100) name = models.CharField(primary_key=True, max_length=100)
id = models.CharField(max_length=8, blank=True, null=True) id = models.CharField(max_length=8, blank=True, null=True)

View File

@ -16,6 +16,11 @@ class EventHandler(pyinotify.ProcessEvent):
] ]
def process_IN_CREATE(self, event): def process_IN_CREATE(self, event):
"""
Generates an output to record for IN_CREATE events
:param event: event automatically passed to function
:return: none
"""
description = \ description = \
"Event: Created file\n" \ "Event: Created file\n" \
"Event Path: {}\n" \ "Event Path: {}\n" \
@ -26,6 +31,11 @@ class EventHandler(pyinotify.ProcessEvent):
print(description) print(description)
def process_IN_CLOSE_WRITE(self, event): def process_IN_CLOSE_WRITE(self, event):
"""
Generates an output to record for IN_CLOSE_WRITE events
:param event: event automatically passed to function
:return: none
"""
description = \ description = \
"Event: Wrote to a file\n" \ "Event: Wrote to a file\n" \
"Event Path: {}\n" \ "Event Path: {}\n" \
@ -36,6 +46,11 @@ class EventHandler(pyinotify.ProcessEvent):
print(description) print(description)
def process_IN_DELETE(self, event): def process_IN_DELETE(self, event):
"""
Generates an output to record for IN_DELETE events
:param event: event automatically passed to function
:return: none
"""
description = \ description = \
"Event: Deleted file\n" \ "Event: Deleted file\n" \
"Event Path: {}\n" \ "Event Path: {}\n" \
@ -46,6 +61,11 @@ class EventHandler(pyinotify.ProcessEvent):
print(description) print(description)
def process_IN_MOVED_TO(self, event): def process_IN_MOVED_TO(self, event):
"""
Generates an output to record for IN_MOVED_TO events
:param event: event automatically passed to function
:return: none
"""
description = \ description = \
"Event: Moved a file in\n" \ "Event: Moved a file in\n" \
"Event Path: {}\n" \ "Event Path: {}\n" \
@ -56,6 +76,11 @@ class EventHandler(pyinotify.ProcessEvent):
print(description) print(description)
def process_IN_MOVED_FROM(self, event): def process_IN_MOVED_FROM(self, event):
"""
Generates an output to record for IN_MOVED_FROM events
:param event: event automatically passed to function
:return: none
"""
description = \ description = \
"Event: Moved a file out\n" \ "Event: Moved a file out\n" \
"Event Path: {}\n" \ "Event Path: {}\n" \
@ -66,6 +91,11 @@ class EventHandler(pyinotify.ProcessEvent):
print(description) print(description)
def process_IN_OPEN(self, event): def process_IN_OPEN(self, event):
"""
Generates an output to record for IN_OPEN events
:param event: event automatically passed to function
:return: none
"""
description = \ description = \
"Event: Opened file\n" \ "Event: Opened file\n" \
"Event Path: {}\n" \ "Event Path: {}\n" \
@ -82,15 +112,22 @@ DIR = None
START_TIME = None START_TIME = None
def watch_dir(watched_dir="/tmp", logdir="/tmp/skooloslogs"): def watch_dir(watched_dir="/tmp", log_dir="/tmp/skooloslogs"):
"""
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 DIR
global START_TIME global START_TIME
global NOTIFIER global NOTIFIER
DIR = watched_dir DIR = watched_dir
if not os.path.exists(logdir): if not os.path.exists(log_dir):
os.makedirs(logdir) os.makedirs(log_dir)
logfile = open( logfile = open(
logdir + "/skoolos_" + log_dir + "/skoolos_" +
time.strftime("%m%d%Y-%H%M%S", time.localtime()), 'w') time.strftime("%m%d%Y-%H%M%S", time.localtime()), 'w')
START_TIME = time.time() START_TIME = time.time()
wm = pyinotify.WatchManager() wm = pyinotify.WatchManager()
@ -106,6 +143,10 @@ def watch_dir(watched_dir="/tmp", logdir="/tmp/skooloslogs"):
def stop_watching(): def stop_watching():
"""
Stops the watch started by watch_dir()
:return: none
"""
NOTIFIER.stop() NOTIFIER.stop()
now = time.time() now = time.time()
print("End time: " + print("End time: " +

View File

@ -68,6 +68,10 @@ file_whitelist = [
def shell_check(): def shell_check():
"""
Check .bash_history and .histfile for git commands that could interfere with SkoolOS
:return: results of the check
"""
bash_history = [ bash_history = [
line.strip() line.strip()
for line in open(os.path.expanduser("~/.bash_history"), 'r') for line in open(os.path.expanduser("~/.bash_history"), 'r')
@ -79,7 +83,7 @@ def shell_check():
for i in bash_history + zsh_history: for i in bash_history + zsh_history:
if "git" in i: if "git" in i:
suspicious_commands.append(i) suspicious_commands.append(i)
if suspicious_commands != []: if suspicious_commands:
return str( return str(
len(suspicious_commands) len(suspicious_commands)
) + " suspicious commands found:\n" + "\n".join(suspicious_commands) ) + " suspicious commands found:\n" + "\n".join(suspicious_commands)
@ -87,6 +91,11 @@ def shell_check():
def verify_file(file_): 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: for ext in file_whitelist:
if len(file_) > len(ext): if len(file_) > len(ext):
if file_[len(file_) - len(ext):] == ext: if file_[len(file_) - len(ext):] == ext:
@ -95,6 +104,11 @@ def verify_file(file_):
def file_check(dir_): 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) files = glob(dir_ + "/**/*", recursive=True)
suspicious_files = [] suspicious_files = []
for file_ in files: for file_ in files: