mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
Merge branch 'development' of https://github.com/rushilwiz/SkoolOs into development
Merge Merge Merge
This commit is contained in:
commit
1b8c7b1307
1
.profile
Normal file
1
.profile
Normal file
|
@ -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': []}
|
58
BackgroundService/bgservice.py
Normal file
58
BackgroundService/bgservice.py
Normal file
|
@ -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()
|
65
BackgroundService/event_processor.py
Normal file
65
BackgroundService/event_processor.py
Normal file
|
@ -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()
|
19
BackgroundService/test.py
Normal file
19
BackgroundService/test.py
Normal file
|
@ -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
|
|
@ -14,7 +14,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<div class="d-flex align-items-center justify-content-center" style="height: 100vh">
|
||||
|
||||
<a href="https://ion.tjhsst.edu/oauth/authorize/?response_type=code&client_id=QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F&scope=read&state=O9QWIinWimSA8Kehr8vxUZHZ0SNPpL" title="Ion" class="border border-dark p-3 btn btn-lg mx-auto" style="box-shadow: 5px 10px;">
|
||||
<img src="https://ion.tjhsst.edu/static/img/favicon.png">
|
||||
Sign in with Ion
|
||||
</a>
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user