From fa08d6d8ebad889396003c034e67a1f0ada0d9be Mon Sep 17 00:00:00 2001 From: Pengwius Date: Fri, 15 Jan 2021 23:17:03 +0100 Subject: [PATCH 1/2] Getting recipients --- app/API/messages.py | 22 ++++++++++++++++++++++ app/views.py | 17 ++++++++++++++++- files/js/messages.js | 20 +++++++++++++++++++- templates/content.html | 2 +- wulkanowy/urls.py | 3 ++- 5 files changed, 60 insertions(+), 4 deletions(-) diff --git a/app/API/messages.py b/app/API/messages.py index 5d20017..beede5d 100644 --- a/app/API/messages.py +++ b/app/API/messages.py @@ -53,3 +53,25 @@ def get_deleted_messages(register_id, register_r, oun, s, date, school_year, sym deleted_messages = requests.get(f'https://uonetplus-uzytkownik.vulcan.net.pl/{symbol}/Wiadomosc.mvc/GetOutboxMessages?_dc={now}&dataOd=&dataDo=&page=1&start=0&limit=25', headers=headers, cookies=s) return deleted_messages.json() + +def get_recipients(register_id, register_r, oun, s, date, school_year, symbol): + headers = { + 'Accept-Encoding': 'gzip, deflate, br', + 'Accept': '*/*', + 'Connection': 'keep-alive', + "User-Agent": "Wulkanowy-web :)" + } + + if oun == 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458': + link = f'http://uonetplus-uzytkownik.fakelog.cf/{symbol}' + else: + link = f'https://uonetplus-uzytkownik.vulcan.net.pl/{symbol}' + + get_jednostki = requests.get(f'{link}/NowaWiadomosc.mvc/GetJednostkiUzytkownika', headers=headers, cookies=s) + id_jednostka = get_jednostki.json()['data'][0]['IdJednostkaSprawozdawcza'] + data = { + "paramsVo":{"IdJednostkaSprawozdawcza":id_jednostka, 'Rola': 2} + } + get_addressee = requests.post(f'{link}/Adresaci.mvc/GetAddressee', headers=headers, cookies=s, json=data) + + return get_addressee.json() \ No newline at end of file diff --git a/app/views.py b/app/views.py index 8a8f786..d364eab 100644 --- a/app/views.py +++ b/app/views.py @@ -12,7 +12,7 @@ from .API.exams import get_exams from .API.timetable import get_timetable from .API.notes import get_notes from .API.attendance import get_attendance -from .API.messages import get_received_messages, get_sent_messages, get_deleted_messages +from .API.messages import get_received_messages, get_sent_messages, get_deleted_messages, get_recipients from .API.homeworks import get_homeworks from .API.mobile_access import get_registered_devices, register_device from .API.school_data import get_school_data @@ -197,6 +197,21 @@ def deleted_messages(request, *args, **kwargs): else: return redirect('../') +def recipients(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'] + oun = data['data']['oun'] + s = data['data']['s'] + date = data['data']['date'] + school_year = data['data']['school_year'] + symbol = data['data']['symbol'] + recipients = get_recipients(register_id, register_r, oun, s, date, school_year, symbol) + return JsonResponse(recipients) + else: + return redirect('../') + def school_data(request, *args, **kwargs): if request.session.has_key('is_logged'): data = json.loads(request.body) diff --git a/files/js/messages.js b/files/js/messages.js index b9d371a..33f288c 100644 --- a/files/js/messages.js +++ b/files/js/messages.js @@ -1,7 +1,8 @@ const received_ = document.querySelector('#received_'); const sent_ = document.querySelector('#sent_'); const deleted_ = document.querySelector('#deleted_'); -const content = document.getElementById("content") +const content = document.getElementById("content"); +const send_ = document.querySelector('#send_') const getReceivedMessages = () => { content.innerHTML = "" @@ -156,7 +157,24 @@ const getDeletedMessages = () => { }) } +const sendMessage = () => { + cookies_data = sessionStorage.getItem('cookies_data'); + csrfcookie_ = sessionStorage.getItem('csrfcookie'); + fetch(url = '../api/messages/recipients', { + method: 'POST', + mode: 'cors', + headers: { + 'Content-Type': 'application/json', + 'X-CSRFToken': csrfcookie_ + }, + body: cookies_data + }).then(response => response.json()).then(data => { + console.log(data); + }) +} + received_.addEventListener('click', getReceivedMessages); sent_.addEventListener('click', getSentMessages); deleted_.addEventListener('click', getDeletedMessages); +send_.addEventListener('click', sendMessage); \ No newline at end of file diff --git a/templates/content.html b/templates/content.html index 3df8965..f70f838 100644 --- a/templates/content.html +++ b/templates/content.html @@ -59,7 +59,7 @@ diff --git a/wulkanowy/urls.py b/wulkanowy/urls.py index 2887b15..31d2001 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, dashboard +from app.views import login, grades, timetable, exams, homeworks, attendance, notes, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, school_data, dashboard, recipients urlpatterns = [ #views @@ -40,6 +40,7 @@ urlpatterns = [ path('api/messages/received', received_messages, name='received_messages'), path('api/messages/sent', sent_messages, name='sent_messages'), path('api/messages/deleted', deleted_messages, name='deleted_messages'), + path('api/messages/recipients', recipients, name='recipients'), ] urlpatterns += staticfiles_urlpatterns() \ No newline at end of file From c654711b4aa3cbdd0d018ef21105b5d2f2664925 Mon Sep 17 00:00:00 2001 From: Pengwius Date: Mon, 18 Jan 2021 13:01:18 +0100 Subject: [PATCH 2/2] Sending message --- app/API/messages.py | 83 +++++++++++++++++++++++++++++++++++++++++- app/views.py | 21 ++++++++++- files/js/messages.js | 55 +++++++++++++++++++++++++++- package-lock.json | 19 ++++++++++ package.json | 3 +- templates/content.html | 3 +- wulkanowy/urls.py | 3 +- 7 files changed, 178 insertions(+), 9 deletions(-) diff --git a/app/API/messages.py b/app/API/messages.py index beede5d..edeed9e 100644 --- a/app/API/messages.py +++ b/app/API/messages.py @@ -2,6 +2,7 @@ import requests import json import calendar import time +import re def get_received_messages(register_id, register_r, oun, s, date, school_year, symbol): headers = { @@ -74,4 +75,84 @@ def get_recipients(register_id, register_r, oun, s, date, school_year, symbol): } get_addressee = requests.post(f'{link}/Adresaci.mvc/GetAddressee', headers=headers, cookies=s, json=data) - return get_addressee.json() \ No newline at end of file + return {'addressee': get_addressee.json(), 'unitId': id_jednostka} + +def send_message(register_id, register_r, oun, s, date, school_year, symbol, send_data): + headers = { + 'Accept-Encoding': 'gzip, deflate, br', + 'Accet': '*/*', + 'Connection': 'keep-alive', + "User-Agent": "Wulkanowy-web :)", + 'Content-Type': 'application/json', + 'TE': "Trailers" + } + + if oun == 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458': + link = f'http://uonetplus-uzytkownik.fakelog.cf/{symbol}' + else: + link = f'https://uonetplus-uzytkownik.vulcan.net.pl/{symbol}' + + student_data = register_r['data'][0]['UczenNazwisko']+' '+register_r['data'][0]['UczenImie'] + + sess = requests.Session() + + sess.cookies.update(s) + sess.headers.update(headers) + + index = sess.get(link) + + antiForgeryToken = re.search("antiForgeryToken: '(.)*'", index.text) + antiForgeryToken = antiForgeryToken.group() + antiForgeryToken = antiForgeryToken.replace('antiForgeryToken: ', '').replace("'", "") + + appGuid = re.search("appGuid: '(.)*'", index.text) + appGuid = appGuid.group() + appGuid = appGuid.replace('appGuid: ', '').replace("'", "") + + sess.headers.update({ + 'X-V-RequestVerificationToken': antiForgeryToken, + 'X-V-AppGuid': appGuid + }) + + payload = { + "incomming": { + "Id": 0, + "Nieprzeczytane": 0, + "Przeczytane": 0, + "Nieprzeczytana": False, + "FolderWiadomosci": 0, + "WiadomoscPowitalna": False, + "Data": None, + "Tresc": send_data['content'], + "Temat": send_data['subject'], + "IdWiadomosci": 0, + "HasZalaczniki": False, + "Zalaczniki": "", + "Adresaci": [ + { + "Id": send_data['data']['Id'], + "IdReceiver": "", + "Name": send_data['data']['Name'], + "Role": send_data['data']['Role'], + "UnitId": send_data['data']['UnitId'], + "IdLogin": send_data['data']['IdLogin'], + "PushWiadomosc": False, + "Hash": send_data['data']['Hash'], + "Date": None, + "IsMarked": False + } + ], + "WyslijJako": student_data, + "WiadomoscAdresatLogin": "", + "IdWiadomoscAdresatLogin": None, + "RolaNadawcy": 0, + "NieprzeczytanePrzeczytane": "0/0", + "NadawcaNazwa": "Brak nadawcy", + "IdNadawca": 0, + "AdresaciNazwa": "Brak adresata" + } + } + + send = sess.post(f'{link}/NowaWiadomosc.mvc/InsertWiadomosc', data=json.dumps(payload)) + + return send.json() \ No newline at end of file diff --git a/app/views.py b/app/views.py index d364eab..048e133 100644 --- a/app/views.py +++ b/app/views.py @@ -12,7 +12,7 @@ from .API.exams import get_exams from .API.timetable import get_timetable from .API.notes import get_notes from .API.attendance import get_attendance -from .API.messages import get_received_messages, get_sent_messages, get_deleted_messages, get_recipients +from .API.messages import get_received_messages, get_sent_messages, get_deleted_messages, get_recipients, send_message from .API.homeworks import get_homeworks from .API.mobile_access import get_registered_devices, register_device from .API.school_data import get_school_data @@ -235,4 +235,21 @@ def dashboard(request, *args, **kwargs): dashboard = get_dashboard(register_id, register_r, s, diary_url, symbol) return JsonResponse(dashboard) else: - return redirect('../') \ No newline at end of file + return redirect('../') + +def send(request, *args, **kwargs): + if request.session.has_key('is_logged'): + data = json.loads(request.body) + cookies_data = json.loads(data['cookies_data']) + register_id = cookies_data['data']['register_id'] + register_r = cookies_data['data']['register_r'] + oun = cookies_data['data']['oun'] + s = cookies_data['data']['s'] + date = cookies_data['data']['date'] + school_year = cookies_data['data']['school_year'] + symbol = cookies_data['data']['symbol'] + send_data = {'data': data['data'], 'subject': data['subject'], 'content': data['content']} + send = send_message(register_id, register_r, oun, s, date, school_year, symbol, send_data) + return JsonResponse(send, safe=False) + else: + return redirect('../') diff --git a/files/js/messages.js b/files/js/messages.js index 33f288c..15a0876 100644 --- a/files/js/messages.js +++ b/files/js/messages.js @@ -3,6 +3,7 @@ const sent_ = document.querySelector('#sent_'); const deleted_ = document.querySelector('#deleted_'); const content = document.getElementById("content"); const send_ = document.querySelector('#send_') +var hash = require('object-hash'); const getReceivedMessages = () => { content.innerHTML = "" @@ -157,7 +158,7 @@ const getDeletedMessages = () => { }) } -const sendMessage = () => { +const getAddressee = () => { cookies_data = sessionStorage.getItem('cookies_data'); csrfcookie_ = sessionStorage.getItem('csrfcookie'); fetch(url = '../api/messages/recipients', { @@ -170,11 +171,61 @@ const sendMessage = () => { body: cookies_data }).then(response => response.json()).then(data => { console.log(data); + document.querySelector('#content').innerHTML = ` +
+
+ +
+
+ +
+
+ +
+ +
` + data.addressee.data.forEach((recipient) => { + const recipient_hash = `${hash.MD5(recipient)}` + document.querySelector('#recipients').insertAdjacentHTML('beforeend', ''); + sessionStorage.setItem(recipient_hash, JSON.stringify(recipient)); + const button_ = document.querySelector('#button'); + button_.addEventListener('click', sendMessage); + }) }) } +const sendMessage = () => { + const recipient_hash_ = document.querySelector('#recipients').value; + const subject_ = document.querySelector('#subject').value; + const content_ = document.querySelector('#message-content').value; + const recipient_ = JSON.parse(sessionStorage.getItem(recipient_hash_)); + if(subject_ != '' && content_ != ''){ + cookies_data = sessionStorage.getItem('cookies_data'); + csrfcookie_ = sessionStorage.getItem('csrfcookie'); + send_data = { + 'cookies_data': cookies_data, + 'data': recipient_, + 'subject': subject_, + 'content': content_ + } + fetch(url = '../api/messages/send', { + method: 'POST', + mode: 'cors', + headers: { + 'Content-Type': 'application/json', + 'X-CSRFToken': csrfcookie_ + }, + body: JSON.stringify(send_data) + }).then(response => response.json()).then(data => { + console.log(data) + }) + } + +} + received_.addEventListener('click', getReceivedMessages); sent_.addEventListener('click', getSentMessages); deleted_.addEventListener('click', getDeletedMessages); -send_.addEventListener('click', sendMessage); \ No newline at end of file +send_.addEventListener('click', getAddressee); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 608c2b7..a7bc067 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1939,6 +1939,11 @@ } } }, + "md5-jkmyers": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/md5-jkmyers/-/md5-jkmyers-0.0.1.tgz", + "integrity": "sha1-t9PfKAe5HV7H8zc7V/JNYLD6krs=" + }, "merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -2198,6 +2203,15 @@ "integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==", "dev": true }, + "reverse-md5": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/reverse-md5/-/reverse-md5-0.0.5.tgz", + "integrity": "sha512-nSzYU/we3UHObW0rHdf/680AxlAuaVH9fmV3l/1/fnyzbphPPpTFZ684g4wQ2Ru+2lCOdmu8rgWJTTmg/JoXfA==", + "requires": { + "md5-jkmyers": "^0.0.1", + "xtend": "^4.0.0" + } + }, "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -2480,6 +2494,11 @@ "isexe": "^2.0.0" } }, + "xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" + }, "yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index c54886c..b4ac24d 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ }, "homepage": "https://github.com/wulkanowy/wulkanowy-web#readme", "dependencies": { - "object-hash": "^2.1.1" + "object-hash": "^2.1.1", + "reverse-md5": "0.0.5" }, "devDependencies": { "@babel/core": "^7.12.10", diff --git a/templates/content.html b/templates/content.html index f70f838..d3a09b8 100644 --- a/templates/content.html +++ b/templates/content.html @@ -14,7 +14,7 @@ - + @@ -66,7 +66,6 @@ menu
-