mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
views update
This commit is contained in:
parent
1ba3d791f3
commit
44c924002e
1
.profile
1
.profile
|
@ -1 +0,0 @@
|
||||||
{'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': []}
|
|
|
@ -1 +0,0 @@
|
||||||
{'id': 1000417, 'ion_username': '2023rumareti', 'sex': 'Male', 'title': None, 'display_name': 'Rushil Umaretiya', 'full_name': 'Rushil Umaretiya', 'short_name': 'Rushil', 'first_name': 'Rushil', 'middle_name': 'Haresh', 'last_name': 'Umaretiya', 'nickname': None, 'tj_email': '2023rumareti@tjhsst.edu', 'emails': ['rushilwiz@gmail.com', 'r@crucialnet.org'], 'grade': {'number': 9, 'name': 'freshman'}, 'graduation_year': 2023, 'user_type': 'student', 'phones': ['Mobile Phone: 7034570803'], 'websites': ['http://crucialnet.org'], 'counselor': {'id': 115, 'url': 'https://ion.tjhsst.edu/api/profile/115', 'user_type': 'counselor', 'username': 'kchamblin', 'full_name': 'Kerry Hamblin', 'first_name': 'Kerry', 'last_name': 'Hamblin'}, 'address': None, 'picture': 'https://ion.tjhsst.edu/api/profile/1000417/picture', 'is_eighth_admin': False, 'is_announcements_admin': False, 'is_teacher': False, 'is_student': True, 'absences': 1}
|
|
|
@ -14,10 +14,10 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="d-flex align-items-center justify-content-center" style="height: 100vh">
|
<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;">
|
<a href="https://ion.tjhsst.edu/oauth/authorize/?response_type=code&client_id=QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback%2F&scope=read&state=HqMEAtGHTvAVR63VJrwdrIawpSvXGk" 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">
|
<img src="https://ion.tjhsst.edu/static/img/favicon.png">
|
||||||
Sign in with Ion
|
Sign in with Ion
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -37,7 +37,14 @@ def main():
|
||||||
input("Welcome to SkoolOS. Press any key to create an account")
|
input("Welcome to SkoolOS. Press any key to create an account")
|
||||||
authenticate()
|
authenticate()
|
||||||
else:
|
else:
|
||||||
print(open(".profile", "r").read())
|
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:
|
# while True:
|
||||||
# pass
|
# pass
|
||||||
|
@ -50,9 +57,14 @@ def authenticate():
|
||||||
#Linux: chromdriver-linux
|
#Linux: chromdriver-linux
|
||||||
#Macos: chromdriver-mac
|
#Macos: chromdriver-mac
|
||||||
#Windows: chromdriver.exe
|
#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')
|
web_dir = os.path.join(os.path.dirname(__file__), 'oauth')
|
||||||
|
print(web_dir)
|
||||||
os.chdir(web_dir)
|
os.chdir(web_dir)
|
||||||
if os.path.exists("index.html"):
|
if os.path.exists("index.html"):
|
||||||
os.remove("index.html")
|
os.remove("index.html")
|
||||||
|
@ -86,13 +98,13 @@ def authenticate():
|
||||||
print("states good")
|
print("states good")
|
||||||
browser.quit()
|
browser.quit()
|
||||||
|
|
||||||
print(code)
|
#print(code)
|
||||||
print(state)
|
print(state)
|
||||||
|
|
||||||
payload = {'grant_type': 'authorization_code', 'code': code, 'redirect_uri': redirect_uri, 'client_id': client_id,
|
payload = {'grant_type': 'authorization_code', 'code': code, 'redirect_uri': redirect_uri, 'client_id': client_id,
|
||||||
'client_secret': client_secret, 'csrfmiddlewaretoken': state}
|
'client_secret': client_secret, 'csrfmiddlewaretoken': state}
|
||||||
token = requests.post("https://ion.tjhsst.edu/oauth/token/", data=payload).json()
|
token = requests.post("https://ion.tjhsst.edu/oauth/token/", data=payload).json()
|
||||||
print(token)
|
#print(token)
|
||||||
headers = {'Authorization': f"Bearer {token['access_token']}"}
|
headers = {'Authorization': f"Bearer {token['access_token']}"}
|
||||||
|
|
||||||
# And finally get the user's profile!
|
# And finally get the user's profile!
|
||||||
|
@ -105,14 +117,18 @@ def authenticate():
|
||||||
last_name = profile['last_name']
|
last_name = profile['last_name']
|
||||||
|
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
profileFile = open(".profile", "w")
|
# key = Fernet.generate_key()
|
||||||
#profileFile.write(profile.text())
|
# file = open('key.key', 'wb')
|
||||||
key = Fernet.generate_key()
|
# file.write(key) # The key is type bytes still
|
||||||
file = open('key.key', 'wb')
|
# file.close()
|
||||||
file.write(key) # The key is type bytes still
|
# p = str(profile).encode()
|
||||||
file.close()
|
# f = Fernet(key)
|
||||||
profileFile.write(str(profile))
|
# encrypted = f.encrypt(p)
|
||||||
profileFile.close()
|
|
||||||
|
# profileFile = open(".profile", "wb")
|
||||||
|
# #profileFile.write(profile.text())
|
||||||
|
# profileFile.write(encrypted)
|
||||||
|
# profileFile.close()
|
||||||
|
|
||||||
sys.exit
|
sys.exit
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-13 18:15
|
# Generated by Django 3.0.7 on 2020-06-14 19:59
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
@ -41,19 +41,15 @@ class Migration(migrations.Migration):
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Student',
|
name='Student',
|
||||||
fields=[
|
fields=[
|
||||||
('created', models.DateTimeField(auto_now_add=True)),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('first_name', models.CharField(max_length=100)),
|
|
||||||
('last_name', models.CharField(max_length=100)),
|
|
||||||
('student_id', models.IntegerField()),
|
('student_id', models.IntegerField()),
|
||||||
('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)),
|
|
||||||
('email', models.CharField(blank=True, default='', max_length=100)),
|
|
||||||
('grade', models.IntegerField()),
|
('grade', models.IntegerField()),
|
||||||
('git', models.CharField(max_length=100)),
|
('git', models.CharField(max_length=100)),
|
||||||
('repo', models.URLField(blank=True, default='')),
|
('repo', models.URLField(blank=True, default='')),
|
||||||
('classes', models.CharField(blank=True, default='', max_length=100)),
|
('classes', models.CharField(blank=True, default='', max_length=100)),
|
||||||
('added_to', models.CharField(blank=True, default='', max_length=100)),
|
('added_to', models.CharField(blank=True, default='', max_length=100)),
|
||||||
('completed', models.TextField(blank=True, default='')),
|
('completed', models.TextField(blank=True, default='')),
|
||||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='students', to=settings.AUTH_USER_MODEL)),
|
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
@ -67,7 +63,7 @@ class Migration(migrations.Migration):
|
||||||
('default_file', models.CharField(blank=True, default='', max_length=100)),
|
('default_file', models.CharField(blank=True, default='', max_length=100)),
|
||||||
('confirmed', models.TextField(blank=True, default='')),
|
('confirmed', models.TextField(blank=True, default='')),
|
||||||
('unconfirmed', models.TextField(blank=True, default='')),
|
('unconfirmed', models.TextField(blank=True, default='')),
|
||||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='classes', to=settings.AUTH_USER_MODEL)),
|
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
|
|
@ -10,7 +10,7 @@ class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ['id', 'username', 'students','teachers']
|
fields = ['id', 'username']
|
||||||
|
|
||||||
# class DefFilesSerializer(serializers.HyperlinkedModelSerializer):
|
# class DefFilesSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
# class Meta:
|
# class Meta:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-13 08:25
|
# Generated by Django 3.0.7 on 2020-06-14 19:59
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
6
Website/users/pwd.py
Normal file
6
Website/users/pwd.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
pwd = "heyyy"
|
||||||
|
path = os.getcwd()
|
||||||
|
p = os.path.join(path, '../../', 'pwd.txt')
|
||||||
|
open(p, 'w')
|
|
@ -16,6 +16,7 @@ from django.contrib.auth import login as auth_login
|
||||||
from django.contrib.auth import logout as auth_logout
|
from django.contrib.auth import logout as auth_logout
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
import os
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
# Thanks Django, what would I do without this comment
|
# Thanks Django, what would I do without this comment
|
||||||
|
|
144
skoolos.py
Normal file
144
skoolos.py
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
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.getcwd(), 'CLI', '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']
|
||||||
|
password = input("Enter SkoolOS password: ")
|
||||||
|
profile = {
|
||||||
|
'username':username,
|
||||||
|
'email':email,
|
||||||
|
'first_name':first_name,
|
||||||
|
'last_name':last_name,
|
||||||
|
'password':password,
|
||||||
|
}
|
||||||
|
os.chdir(cdir)
|
||||||
|
|
||||||
|
profileFile = open(".profile", "w")
|
||||||
|
#profileFile.write(profile.text())
|
||||||
|
profileFile.write(str(profile))
|
||||||
|
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()
|
Loading…
Reference in New Issue
Block a user