diff --git a/.profile b/.profile new file mode 100644 index 0000000..df779be --- /dev/null +++ b/.profile @@ -0,0 +1 @@ +{'absences': 2, 'address': None, 'counselor': {'first_name': 'Sean', 'full_name': 'Sean Burke', 'id': 37, 'last_name': 'Burke', 'url': 'https://ion.tjhsst.edu/api/profile/37', 'user_type': 'counselor', 'username': 'SPBurke'}, 'display_name': 'Raffu Khondaker', 'emails': [], 'first_name': 'Raffu', 'full_name': 'Raffu Khondaker', 'grade': {'name': 'sophomore', 'number': 10}, 'graduation_year': 2022, 'id': 36508, 'ion_username': '2022rkhondak', 'is_announcements_admin': False, 'is_eighth_admin': False, 'is_student': True, 'is_teacher': False, 'last_name': 'Khondaker', 'middle_name': 'Al', 'nickname': '', 'phones': [], 'picture': 'https://ion.tjhsst.edu/api/profile/36508/picture', 'sex': 'Male', 'short_name': 'Raffu', 'title': None, 'tj_email': '2022rkhondak@tjhsst.edu', 'user_type': 'student', 'websites': []} \ No newline at end of file diff --git a/BackgroundService/bgservice.py b/BackgroundService/bgservice.py new file mode 100644 index 0000000..ed26c76 --- /dev/null +++ b/BackgroundService/bgservice.py @@ -0,0 +1,58 @@ +import os +import sys +import signal +import time +import event_processor + + +class SkoolOSDaemon: + """Constructor""" + def __init__(self, work_dir='/tmp'): + self.work_dir = work_dir + self.start_time = None + self.end_time = None + self.log_file = None + def __write_pid_file(self): + try: + dirName = "/tmp/skooloslogs" + # Create log Directory + os.mkdir(dirName) + except FileExistsError: + pass + pid = str(os.getpid()) + file_ = open('/tmp/skoolosdaemonpid', 'w') + file_.write(pid) + file_.close() + def readable_time(self, input_time): + return time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime(input_time)) + def start(self): + self.__write_pid_file() + self.start_time = time.time() + self.log_file = open('/tmp/skooloslogs/' + str(self.start_time), 'w') + self.log_file.write("Start time: \n" + self.readable_time(self.start_time) + "\n\n") + sys.stdout = self.log_file + event_processor.watch_dir(self.work_dir) + def stop(self): + event_processor.stop_watching() + self.end_time = time.time() + self.log_file.write("Stop time: \n" + self.readable_time(self.end_time)) + self.log_file.write("Total work time: " + + time.strftime("%H:%M:%S", time.gmtime(self.end_time - self.start_time))) + + + + +logger = None + +def Main(): + def signal_handler(signum, frame): + logger.stop() + signal.signal(signal.SIGINT, signal_handler) + # signal.signal(signal.SIGTERM, signal_handler) + global logger + logger = SkoolOSDaemon("/tmp") + logger.start() + + +if __name__ == "__main__": + Main() diff --git a/BackgroundService/event_processor.py b/BackgroundService/event_processor.py new file mode 100644 index 0000000..55c5e15 --- /dev/null +++ b/BackgroundService/event_processor.py @@ -0,0 +1,65 @@ +import time +import pyinotify + + +def readable_time(input_time): + return time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime(input_time)) + + +class EventProcessor(pyinotify.ProcessEvent): + _methods = ["IN_OPEN", + "IN_CREATE", + "IN_CLOSE_WRITE", + "IN_DELETE", + "IN_MOVED_TO", + "IN_MOVED_FROM", + ] + + +def __method_format(method): + return { + "IN_OPEN":"Opened a file", + "IN_CREATE":"Created a file", + "IN_CLOSE_WRITE":"Wrote to a file", + "IN_DELETE":"Deleted a file", + "IN_MOVED_TO":"Moved a file or directory in from elsewhere", + "IN_MOVED_FROM":"Moved a file or directory elsewhere", + }.get(method, "Unknown event") + + +def __process_generator(cls, method): + def _method_name(self, event): + description = "Event description: {}\n" \ + "Path name: {}\n" \ + "Event Name: {}\n" \ + "Timestamp: {}\n".format(__method_format(method), + event.pathname, + event.maskname, + readable_time(time.time()) + ) + if "IN_DELETE" in description: + description += "WARNING: Unexpected file deletion\n" + if "IN_MOVED_TO" in description: + description += "WARNING: Unexpected file add to work\n" + if "IN_MOVED_FROM" in description: + description += "WARNING: Unexpected file moved out of directory\n" + print(description) + _method_name.__name__ = "process_{}".format(method) + setattr(cls, _method_name.__name__, _method_name) + + +EVENT_NOTIFIER = None + + +def watch_dir(dir_to_watch): + global EVENT_NOTIFIER + for method in EventProcessor._methods: + __process_generator(EventProcessor, method) + watch_manager = pyinotify.WatchManager() + EVENT_NOTIFIER = pyinotify.ThreadedNotifier(watch_manager, EventProcessor()) + watch_manager.add_watch(dir_to_watch, pyinotify.ALL_EVENTS, rec=True) + EVENT_NOTIFIER.loop() + + +def stop_watching(): + EVENT_NOTIFIER.stop() diff --git a/BackgroundService/test.py b/BackgroundService/test.py new file mode 100644 index 0000000..b797228 --- /dev/null +++ b/BackgroundService/test.py @@ -0,0 +1,19 @@ +from bgservice import SkoolOSDaemon as sod +import threading + +logger = sod() + + +if __name__ == "__main__": + line=1 + print(line) + line+=1 + logger.start() + print(line) + line+=1 + input("Enter any key when you are done modifyng the /tmp/ directory") + print(line) + line+=1 + logger.stop() + print(line) + line+=1 diff --git a/CLI/oauth/index.html b/CLI/oauth/index.html index 3598c6d..cdce72e 100644 --- a/CLI/oauth/index.html +++ b/CLI/oauth/index.html @@ -14,8 +14,8 @@
- - + + Sign in with Ion
diff --git a/CLI/skoolos.py b/CLI/skoolos.py index e318c72..73c7e37 100644 --- a/CLI/skoolos.py +++ b/CLI/skoolos.py @@ -14,6 +14,7 @@ from PyInquirer import prompt, print_json import json import os import argparse +from cryptography.fernet import Fernet client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6' client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY' @@ -69,6 +70,11 @@ def authenticate(): browser.get("localhost:8000/") + while "http://localhost:8000/callback/?code" not in browser.current_url: + time.sleep(0.25) + + url = browser.current_url + gets = url_decode(url.replace("http://localhost:8000/callback/?", "")) while "http://localhost:8000/callback/?code" not in browser.current_url: time.sleep(0.25) @@ -101,6 +107,10 @@ def authenticate(): os.chdir(cdir) profileFile = open(".profile", "w") #profileFile.write(profile.text()) + key = Fernet.generate_key() + file = open('key.key', 'wb') + file.write(key) # The key is type bytes still + file.close() profileFile.write(str(profile)) profileFile.close() diff --git a/requirements.txt b/requirements.txt index 1110b47..9a6e972 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,6 +12,7 @@ oauthlib==3.1.0 prompt-toolkit==1.0.14 pyclipper==1.1.0.post3 Pygments==2.6.1 +pyinotify==0.9.6 PyInquirer==1.0.3 pyperclip==1.8.0 pytz==2020.1