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
def update():
#get data from database
"""
Gets data from the database
:return:
"""
return
def yesorno(question):
@ -35,6 +38,10 @@ def yesorno(question):
return False
def login():
"""
Login to the website with a username and password
:return: user information json if successful, None otherwise
"""
#enter username
#enter password
questions = [
@ -66,6 +73,11 @@ def login():
#did not create account through website, has to signup/login
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 = [
{
'type': 'input',
@ -114,6 +126,10 @@ def signup():
return user
def relogin():
"""
Login to an already verified user account
:return:
"""
questions = [
{
'type': 'list',
@ -128,12 +144,21 @@ def relogin():
def setup(user):
#Read classes/assignenments and setup directory:
#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"]:
os.makedirs(c)
for a in user["classes"][c]:
os.makedirs(c + "/" + a)
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):
b = yesorno("Do you have a SkoolOS account?(y/N)")
if(b):

View File

@ -5,7 +5,7 @@ import secrets
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)
grade = models.IntegerField(default=0, blank=True)
git=models.CharField(default="", max_length=100, blank=True)
@ -20,8 +20,9 @@ class Student(models.Model):
def __str__(self):
return f"{self.user.username}'s Profile"
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)
due_date=models.DateTimeField()
@ -33,8 +34,9 @@ class Assignment(models.Model):
def __str__(self):
return '%s' % (self.name)
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)
name = models.CharField(primary_key=True, max_length=100)
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):
"""
Generates an output to record for IN_CREATE events
:param event: event automatically passed to function
:return: none
"""
description = \
"Event: Created file\n" \
"Event Path: {}\n" \
@ -26,6 +31,11 @@ class EventHandler(pyinotify.ProcessEvent):
print(description)
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 = \
"Event: Wrote to a file\n" \
"Event Path: {}\n" \
@ -36,6 +46,11 @@ class EventHandler(pyinotify.ProcessEvent):
print(description)
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 = \
"Event: Deleted file\n" \
"Event Path: {}\n" \
@ -46,6 +61,11 @@ class EventHandler(pyinotify.ProcessEvent):
print(description)
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 = \
"Event: Moved a file in\n" \
"Event Path: {}\n" \
@ -56,6 +76,11 @@ class EventHandler(pyinotify.ProcessEvent):
print(description)
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 = \
"Event: Moved a file out\n" \
"Event Path: {}\n" \
@ -66,6 +91,11 @@ class EventHandler(pyinotify.ProcessEvent):
print(description)
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 = \
"Event: Opened file\n" \
"Event Path: {}\n" \
@ -82,15 +112,22 @@ DIR = 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 START_TIME
global NOTIFIER
DIR = watched_dir
if not os.path.exists(logdir):
os.makedirs(logdir)
if not os.path.exists(log_dir):
os.makedirs(log_dir)
logfile = open(
logdir + "/skoolos_" +
log_dir + "/skoolos_" +
time.strftime("%m%d%Y-%H%M%S", time.localtime()), 'w')
START_TIME = time.time()
wm = pyinotify.WatchManager()
@ -106,6 +143,10 @@ def watch_dir(watched_dir="/tmp", logdir="/tmp/skooloslogs"):
def stop_watching():
"""
Stops the watch started by watch_dir()
:return: none
"""
NOTIFIER.stop()
now = time.time()
print("End time: " +

View File

@ -68,6 +68,10 @@ file_whitelist = [
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')
@ -79,7 +83,7 @@ def shell_check():
for i in bash_history + zsh_history:
if "git" in i:
suspicious_commands.append(i)
if suspicious_commands != []:
if suspicious_commands:
return str(
len(suspicious_commands)
) + " suspicious commands found:\n" + "\n".join(suspicious_commands)
@ -87,6 +91,11 @@ def shell_check():
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:
@ -95,6 +104,11 @@ def verify_file(file_):
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: