From e9851c0566893b852e4cc4b23222b36a707de9ec Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Tue, 16 Jun 2020 14:12:33 -0400 Subject: [PATCH 1/3] wow raffu thanks for deleting it --- CLI/skoolos.py | 144 ------------------------------------------------- 1 file changed, 144 deletions(-) delete mode 100644 CLI/skoolos.py diff --git a/CLI/skoolos.py b/CLI/skoolos.py deleted file mode 100644 index 9477806..0000000 --- a/CLI/skoolos.py +++ /dev/null @@ -1,144 +0,0 @@ -import sys -from urllib.parse import urlparse -import requests -from requests_oauthlib import OAuth2Session -from selenium import webdriver -import os.path -import time -import http.server -import socketserver -from threading import Thread -from werkzeug.urls import url_decode -import pprint -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' -redirect_uri = 'http://localhost:8000/callback/' -token_url = 'https://ion.tjhsst.edu/oauth/token/' -scope = ["read"] - - -def main(): - print("") - print("░██████╗██╗░░██╗░█████╗░░█████╗░██╗░░░░░  ░█████╗░░██████╗") - print("██╔════╝██║░██╔╝██╔══██╗██╔══██╗██║░░░░░  ██╔══██╗██╔════╝") - print("╚█████╗░█████═╝░██║░░██║██║░░██║██║░░░░░  ██║░░██║╚█████╗░") - print("░╚═══██╗██╔═██╗░██║░░██║██║░░██║██║░░░░░  ██║░░██║░╚═══██╗") - print("██████╔╝██║░╚██╗╚█████╔╝╚█████╔╝███████╗  ╚█████╔╝██████╔╝") - print("╚═════╝░╚═╝░░╚═╝░╚════╝░░╚════╝░╚══════╝  ░╚════╝░╚═════╝░") - print("") - - if not os.path.exists(".profile"): - input("Welcome to SkoolOS. Press any key to create an account") - authenticate() - else: - file = open('key.key', 'rb') - key = file.read() # The key will be type bytes - file.close() - f = Fernet(key) - file = open('.profile', 'rb') - p = file.read() # The key will be type bytes - file.close() - - - # while True: - # pass - -def authenticate(): - oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope) - authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/") - - cdir = os.getcwd() - #Linux: chromdriver-linux - #Macos: chromdriver-mac - #Windows: chromdriver.exe - if('CLI' in os.getcwd()): - path = os.path.join(os.getcwd(), '../','chromedriver-mac') - else: - path = os.path.join(os.getcwd(), 'chromedriver-mac') - - browser = webdriver.Chrome(path) - web_dir = os.path.join(os.path.dirname(__file__), 'oauth') - print(web_dir) - os.chdir(web_dir) - if os.path.exists("index.html"): - os.remove("index.html") - - template = open("template.html", "r") - index = open("index.html", "w") - for line in template: - index.write(line.replace('AUTH_URL', authorization_url)) - template.close() - index.close() - - server = Thread(target=create_server) - server.daemon = True - server.start() - - 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) - - url = browser.current_url - gets = url_decode(url.replace("http://localhost:8000/callback/?", "")) - code = gets.get("code") - if state == gets.get("state"): - state = gets.get("state") - print("states good") - browser.quit() - - #print(code) - print(state) - - payload = {'grant_type': 'authorization_code', 'code': code, 'redirect_uri': redirect_uri, 'client_id': client_id, - 'client_secret': client_secret, 'csrfmiddlewaretoken': state} - token = requests.post("https://ion.tjhsst.edu/oauth/token/", data=payload).json() - #print(token) - headers = {'Authorization': f"Bearer {token['access_token']}"} - - # And finally get the user's profile! - profile = requests.get("https://ion.tjhsst.edu/api/profile", headers=headers).json() - - pprint.pprint(profile) - username = profile['ion_username'] - email = profile['tj_email'] - first_name = profile['first_name'] - last_name = profile['last_name'] - - os.chdir(cdir) - # key = Fernet.generate_key() - # file = open('key.key', 'wb') - # file.write(key) # The key is type bytes still - # file.close() - # p = str(profile).encode() - # f = Fernet(key) - # encrypted = f.encrypt(p) - - # profileFile = open(".profile", "wb") - # #profileFile.write(profile.text()) - # profileFile.write(encrypted) - # profileFile.close() - - sys.exit - - -def create_server(): - port = 8000 - handler = http.server.SimpleHTTPRequestHandler - httpd = socketserver.TCPServer(("", port), handler) - print("serving at port:" + str(port)) - httpd.serve_forever() - -if __name__ == "__main__": - main() From 5120b5b9b392192810e4b4b20e2bb6bed669c33b Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Tue, 16 Jun 2020 14:14:12 -0400 Subject: [PATCH 2/3] moved --- skoolos.py => CLI/skoolos.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename skoolos.py => CLI/skoolos.py (100%) diff --git a/skoolos.py b/CLI/skoolos.py similarity index 100% rename from skoolos.py rename to CLI/skoolos.py From cbd3ddb4e756a0f20a218e5e12e9c0474f8ec793 Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Tue, 16 Jun 2020 14:16:03 -0400 Subject: [PATCH 3/3] moved chromedrivers and fixed usages --- CLI/skoolos.py | 4 ++-- .../chromedriver-linux | Bin chromedriver-mac => chromedriver/chromedriver-mac | Bin chromedriver.exe => chromedriver/chromedriver.exe | Bin 4 files changed, 2 insertions(+), 2 deletions(-) rename chromedriver-linux => chromedriver/chromedriver-linux (100%) rename chromedriver-mac => chromedriver/chromedriver-mac (100%) rename chromedriver.exe => chromedriver/chromedriver.exe (100%) diff --git a/CLI/skoolos.py b/CLI/skoolos.py index f335dfe..881cce4 100644 --- a/CLI/skoolos.py +++ b/CLI/skoolos.py @@ -315,9 +315,9 @@ def authenticate(): #Macos: chromdriver-mac #Windows: chromdriver.exe if('CLI' in os.getcwd()): - path = os.path.join(os.getcwd(), '../','chromedriver-mac') + path = os.path.join(os.getcwd(), '../','chromedriver/chromedriver-mac') else: - path = os.path.join(os.getcwd(), 'chromedriver-mac') + path = os.path.join(os.getcwd(), 'chromedriver/chromedriver-mac') browser = webdriver.Chrome(path) diff --git a/chromedriver-linux b/chromedriver/chromedriver-linux similarity index 100% rename from chromedriver-linux rename to chromedriver/chromedriver-linux diff --git a/chromedriver-mac b/chromedriver/chromedriver-mac similarity index 100% rename from chromedriver-mac rename to chromedriver/chromedriver-mac diff --git a/chromedriver.exe b/chromedriver/chromedriver.exe similarity index 100% rename from chromedriver.exe rename to chromedriver/chromedriver.exe