From 74d25f0ac374ca2be83fe48c3238ce6857814f9d Mon Sep 17 00:00:00 2001 From: Pengwius Date: Wed, 13 Jan 2021 23:39:08 +0100 Subject: [PATCH] Getting permissions value --- app/API/dashboard.py | 38 ++++++++++++++++++++++++++++++++++++++ app/login.py | 7 ++++--- app/views.py | 14 ++++++++++++++ files/js/dashboard.js | 22 ++++++++++++++++++++++ files/js/login.js | 3 +++ templates/content.html | 2 ++ wulkanowy/urls.py | 3 ++- 7 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 app/API/dashboard.py create mode 100644 files/js/dashboard.js diff --git a/app/API/dashboard.py b/app/API/dashboard.py new file mode 100644 index 0000000..29a54e3 --- /dev/null +++ b/app/API/dashboard.py @@ -0,0 +1,38 @@ +import json +import requests +import re +from bs4 import BeautifulSoup + +def get_dashboard(register_id, register_r, s, diary_url, symbol): + cookies = s + if diary_url != 'http://cufs.fakelog.cf/': + cookies.update({ + "biezacyRokSzkolny": f"{register_r['data'][0]['DziennikRokSzkolny']}", + "idBiezacyDziennik": f"{register_r['data'][0]['IdDziennik']}", + "idBiezacyDziennikPrzedszkole": f"{register_r['data'][0]['IdPrzedszkoleDziennik']}", + "idBiezacyDziennikWychowankowie": f"{register_r['data'][0]['IdWychowankowieDziennik']}", + "idBiezacyUczen": f"{register_r['data'][0]['IdUczen']}" + }) + diary_url = 'http://uonetplus.vulcan.net.pl/' + else: + cookies.update({ + "biezacyRokSzkolny": f"{register_r['data'][0]['DziennikRokSzkolny']}", + "idBiezacyDziennik": f"{register_r['data'][0]['IdDziennik']}", + "idBiezacyDziennikPrzedszkole": f"{register_r['data'][0]['IdPrzedszkoleDziennik']}", + "idBiezacyUczen": f"{register_r['data'][0]['IdUczen']}" + }) + diary_url = 'http://uonetplus.fakelog.cf/' + + headers = { + 'Accept-Encoding': 'gzip, deflate', + 'Accept': '*/*', + 'Connection': 'keep-alive', + "User-Agent": "Wulkanowy-web :)" + } + + index = requests.get(f'{diary_url}{symbol}/Start.mvc/Index', headers=headers, cookies=cookies) + permissionsValue = re.search("permissions: '(.)*'", index.text) + permissionsValue = permissionsValue.group() + print(permissionsValue) + + return {"dupa": "dupa"} \ No newline at end of file diff --git a/app/login.py b/app/login.py index ca6ef60..8e72465 100644 --- a/app/login.py +++ b/app/login.py @@ -44,11 +44,11 @@ def send(url, data, fail, diary_url, symbol, s): if diary_url == 'http://cufs.fakelog.cf/': oun = 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458' - cookies = get_cookies(symbol, oun, s) + cookies = get_cookies(symbol, oun, s, diary_url) return cookies -def get_cookies(symbol, oun, s): +def get_cookies(symbol, oun, s, diary_url): register_r = s.post(oun+'/UczenDziennik.mvc/Get') register_id = register_r.json()['data'][0]['Okresy'][0]['Id'] @@ -76,7 +76,8 @@ def get_cookies(symbol, oun, s): 'date': str(date), 'school_year': school_year, 'symbol': symbol, - 's': s.cookies.get_dict() + 's': s.cookies.get_dict(), + 'diary_url': diary_url } return data \ No newline at end of file diff --git a/app/views.py b/app/views.py index a23207d..8a8f786 100644 --- a/app/views.py +++ b/app/views.py @@ -16,6 +16,7 @@ from .API.messages import get_received_messages, get_sent_messages, get_deleted_ from .API.homeworks import get_homeworks from .API.mobile_access import get_registered_devices, register_device from .API.school_data import get_school_data +from .API.dashboard import get_dashboard #views def default_view(request, *args, **kwargs): @@ -205,5 +206,18 @@ def school_data(request, *args, **kwargs): s = data['data']['s'] school_data = get_school_data(register_id, register_r, oun, s) return JsonResponse(school_data) + else: + return redirect('../') + +def dashboard(request, *args, **kwargs): + if request.session.has_key('is_logged'): + data = json.loads(request.body) + register_id = data['data']['register_id'] + register_r = data['data']['register_r'] + s = data['data']['s'] + diary_url = data['data']['diary_url'] + symbol = data['data']['symbol'] + dashboard = get_dashboard(register_id, register_r, s, diary_url, symbol) + return JsonResponse(dashboard) else: return redirect('../') \ No newline at end of file diff --git a/files/js/dashboard.js b/files/js/dashboard.js new file mode 100644 index 0000000..e571451 --- /dev/null +++ b/files/js/dashboard.js @@ -0,0 +1,22 @@ +const start_ = document.querySelector('#dashboard_'); + +const getDashboard = () => { + document.querySelector('#content').innerHTML = 'Dashboard'; + cookies_data = sessionStorage.getItem('cookies_data'); + csrfcookie_ = sessionStorage.getItem('csrfcookie'); + fetch(url = '../api/dashboard', { + method: 'POST', + mode: 'cors', + headers: { + 'Content-Type': 'application/json', + 'X-CSRFToken': csrfcookie_ + }, + body: cookies_data + }).then(response => response.json()).then(data => { + console.log(data); + }) + +} + +window.addEventListener('load', getDashboard); +start_.addEventListener('click', getDashboard); \ No newline at end of file diff --git a/files/js/login.js b/files/js/login.js index 61a0176..8e89fd0 100644 --- a/files/js/login.js +++ b/files/js/login.js @@ -9,10 +9,12 @@ const login = () => { switch(diary){ case 'Fakelog': var diaryUrl = 'http://cufs.fakelog.cf/'; + sessionStorage.setItem('diary_url', 'http://cufs.fakelog.cf/'); break; case 'Vulcan UONET+': var diaryUrl = 'https://cufs.vulcan.net.pl/'; + sessionStorage.setItem('diary_url', 'https://cufs.vulcan.net.pl/'); break; } data = { @@ -35,6 +37,7 @@ const login = () => { sessionStorage.setItem('cookies_data', JSON.stringify(data)); sessionStorage.setItem('csrfcookie', csrfcookie()); sessionStorage.setItem('email', document.querySelector('#id_loginName').value); + sessionStorage.setItem('symbol', document.querySelector('#id_Symbol').value); window.location.href = "/content/"; } else{ diff --git a/templates/content.html b/templates/content.html index 05d5401..7032fae 100644 --- a/templates/content.html +++ b/templates/content.html @@ -7,6 +7,7 @@ + @@ -45,6 +46,7 @@ John Doe +
  • dashboardStart
  • filter_6Oceny
  • event_notePlan Lekcji
  • eventSprawdziany
  • diff --git a/wulkanowy/urls.py b/wulkanowy/urls.py index e1d0796..2887b15 100644 --- a/wulkanowy/urls.py +++ b/wulkanowy/urls.py @@ -17,7 +17,7 @@ from django.urls import path from django.contrib.staticfiles.urls import staticfiles_urlpatterns from app.views import default_view, content_view -from app.views import login, grades, timetable, exams, homeworks, attendance, notes, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, school_data +from app.views import login, grades, timetable, exams, homeworks, attendance, notes, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, school_data, dashboard urlpatterns = [ #views @@ -32,6 +32,7 @@ urlpatterns = [ path('api/attendance', attendance, name='attendance'), path('api/notes', notes, name='notes'), path('api/school_data', school_data, name='school_data'), + path('api/dashboard', dashboard, name='dashboard'), #MOBILE ACCESS path('api/mobile/registered', registered_devices, name='registered_devices'), path('api/mobile/register', register_device_, name='register_device'),