init kretacli
This commit is contained in:
commit
96b8700a57
14 changed files with 1188 additions and 0 deletions
568
KretaCLI/Program.vb
Normal file
568
KretaCLI/Program.vb
Normal file
|
@ -0,0 +1,568 @@
|
|||
Imports System.IO
|
||||
Imports System.Net.Http
|
||||
Imports System.Reflection
|
||||
Imports System.Runtime.InteropServices
|
||||
Imports System.Security.Cryptography
|
||||
Imports System.Text
|
||||
Imports Newtonsoft.Json.Linq
|
||||
|
||||
Module Program
|
||||
Sub Main(args As String())
|
||||
Console.ForegroundColor = ConsoleColor.Red
|
||||
Console.WriteLine(
|
||||
"Figyelmeztetés: Ennek az programnak a használatával elfogadod, hogy bármi kárért én nem vállalok felelősséget.")
|
||||
Console.WriteLine(
|
||||
"Csak saját felhasználásra alkalmas ez a program. (3rd party unofficial Kréta frontend)" + vbCrLf)
|
||||
Console.ForegroundColor = ConsoleColor.Gray
|
||||
If args.Length > 0 AndAlso args(0) = "schools" Then
|
||||
If args.Length > 1 Then
|
||||
If args.Length > 2 Then
|
||||
Dim argums = ""
|
||||
For i = 1 To args.Length - 1
|
||||
If i = args.Length - 1 Then
|
||||
argums += args(i)
|
||||
Else
|
||||
argums += args(i) + " "
|
||||
End If
|
||||
Next
|
||||
GetSchools(argums).Wait()
|
||||
Else
|
||||
GetSchools(args(1)).Wait()
|
||||
End If
|
||||
|
||||
Else
|
||||
Console.WriteLine("Nincs elég paraméter! (schools <Iskola neve/azonosítója>)")
|
||||
End If
|
||||
ElseIf args.Length > 0 AndAlso args(0) = "auth" Then
|
||||
if not args.Length > 2 andalso not args(1) = "refresh" andalso not args(1) = "logout" Then
|
||||
Console.WriteLine("Nincs elég paraméter! (auth login <felhasználónév>@<iskola-azonosító>)")
|
||||
Console.WriteLine("Vagy (auth refresh) ha frissíteni akarod a bejelentkezésed")
|
||||
Console.WriteLine("Vagy ha kiszeretnél jelentkezni, (auth logout).")
|
||||
exit sub
|
||||
end if
|
||||
If args(1) = "login" Then
|
||||
if not args(2).Contains("@") then
|
||||
Console.WriteLine("Elfelejtetted a @-ot! (auth login <felhasználónév>@<iskola-azonosító>)")
|
||||
Else
|
||||
Dim split As String() = args(2).Split("@")
|
||||
Console.WriteLine("Add meg a jelszavad:")
|
||||
Dim password As String = readpassword()
|
||||
getBearer(split(0), password, split(1)).Wait()
|
||||
end if
|
||||
elseif args(1) = "refresh" Then
|
||||
AuthRefreshToken().wait()
|
||||
elseif args(1) = "logout" Then
|
||||
if not File.Exists(GetStartupPath() + "loginData.json") Then
|
||||
Console.WriteLine("Miért szeretnél kijelentkezni, ha nem is vagy bejelentkezve?")
|
||||
exit sub
|
||||
End If
|
||||
Console.WriteLine("FIGYELMEZTETÉS: Kijelentkezni készülsz, biztos vagy benne hogy folytatod?")
|
||||
Console.WriteLine("i(gen) / n(em) (y/n)")
|
||||
Dim answer As String = Console.ReadLine()
|
||||
if answer = "i" or answer = "igen" or answer = "y" or answer = "yes" Then
|
||||
Console.WriteLine("UTOLSÓ FIGYELMEZTETÉS: Még mindig ki szeretnél jelentkezni?")
|
||||
Console.WriteLine("Ha igen, akkor írd be az iskolád azonosítóját. (pl. klik06982123)")
|
||||
Dim answer2 As String = ReadPassword()
|
||||
dim logindata as string = GetStartupPath() + "loginData.json"
|
||||
dim jsonString as string = file.ReadAllText(logindata)
|
||||
dim jsonObject as JObject = JObject.Parse(jsonString)
|
||||
dim school as string = jsonObject("institute_code").ToString()
|
||||
if answer2.ToLower() = school.ToLower() Then
|
||||
revokeRefreshToken().Wait()
|
||||
File.Delete(logindata)
|
||||
Console.WriteLine("Sikeresen kijelentkeztél.")
|
||||
Else
|
||||
Console.WriteLine("Az iskolád azonosítója nem egyezik a bejelentkezett iskoládéval.")
|
||||
Console.WriteLine("Kijelentkezés megszakítva.")
|
||||
End If
|
||||
end if
|
||||
Else
|
||||
Console.WriteLine("Nincs elég paraméter! (auth login <felhasználónév>@<iskola-azonosító>)")
|
||||
Console.WriteLine("Vagy (auth refresh) ha frissíteni akarod a bejelentkezésed")
|
||||
Console.WriteLine("Vagy ha kiszeretnél jelentkezni, (auth logout).")
|
||||
End If
|
||||
elseif args.Length > 0 andalso args(0) = "help" Then
|
||||
Console.WriteLine("KRÉTA CLI " + Version)
|
||||
Console.WriteLine(vbcrlf)
|
||||
Console.Writeline("Parancsok:")
|
||||
Console.ForegroundColor = ConsoleColor.Yellow
|
||||
Console.Write("auth ")
|
||||
Console.ForegroundColor = ConsoleColor.Gray
|
||||
Console.Write("<felhasználónév>@<iskola-azonosító>")
|
||||
Console.WriteLine(vbtab + " - Bejelentkezés a fiókba (Token generálás)")
|
||||
Console.ForegroundColor = consolecolor.DarkCyan
|
||||
Console.Writeline(vbTab + "Példa: hatizsak@klik06982123")
|
||||
Console.WriteLine()
|
||||
Console.ForegroundColor = ConsoleColor.Yellow
|
||||
Console.Write("auth ")
|
||||
Console.ForegroundColor = ConsoleColor.Gray
|
||||
Console.Write("refresh")
|
||||
Console.WriteLine(vbtab + " - Token frissítése")
|
||||
Console.ForegroundColor = ConsoleColor.DarkCyan
|
||||
Console.WriteLine()
|
||||
Console.ForegroundColor = ConsoleColor.Yellow
|
||||
Console.Write("auth ")
|
||||
Console.ForegroundColor = ConsoleColor.Gray
|
||||
Console.Write("logout")
|
||||
Console.WriteLine(vbtab + " - Kijelentkezés")
|
||||
Console.WriteLine()
|
||||
Console.ForegroundColor = ConsoleColor.Yellow
|
||||
Console.Write("schools ")
|
||||
Console.ForegroundColor = ConsoleColor.Gray
|
||||
Console.Write("<Iskola neve/azonosítója>")
|
||||
Console.WriteLine(vbtab + " - Iskolák keresése")
|
||||
Console.ForegroundColor = ConsoleColor.DarkCyan
|
||||
Console.WriteLine(vbTab + "Példa: schools klik")
|
||||
Console.WriteLine()
|
||||
Console.ForegroundColor = ConsoleColor.Yellow
|
||||
Console.Write("adatlap ")
|
||||
Console.ForegroundColor = ConsoleColor.Gray
|
||||
Console.Write("<tanulo/gondviselo>")
|
||||
Console.WriteLine(vbtab + " - Adatlap lekérése")
|
||||
Console.WriteLine()
|
||||
Console.ForegroundColor = ConsoleColor.yellow
|
||||
Console.write("changelog")
|
||||
Console.ForegroundColor = ConsoleColor.Gray
|
||||
Console.WriteLine(vbtab + " - Verzióváltások")
|
||||
Console.WriteLine()
|
||||
Console.ForegroundColor = ConsoleColor.yellow
|
||||
Console.write("privacy")
|
||||
Console.ForegroundColor = ConsoleColor.Gray
|
||||
Console.WriteLine(vbtab + " - Adatvédelmi cucc (idk mi a neve)")
|
||||
Console.WriteLine()
|
||||
Elseif args.Length > 0 andalso args(0) = "adatlap" Then
|
||||
if args.Length > 1 Then
|
||||
if args(1) = "tanulo" Then
|
||||
TanuloiAdatlap().Wait()
|
||||
elseif args(1) = "gondviselo" Then
|
||||
Console.WriteLine("Ha tanulói fiókkal vagy ez nagy eséllyel nem fog menni." + vbcrlf)
|
||||
GondviseloiAdatlap().wait()
|
||||
Else
|
||||
Console.WriteLine("Ismeretlen paraméter! (adatlap <tanulo/gondviselo>)")
|
||||
End If
|
||||
Else
|
||||
Console.WriteLine("Nincs elég paraméter! (adatlap <tanulo/gondviselo>)")
|
||||
End If
|
||||
elseif args.Length > 0 andalso args(0) = "changelog" then
|
||||
Console.WriteLine(Readonlymodule.Changelog)
|
||||
elseif args.Length > 0 andalso args(0) = "privacy" Then
|
||||
Console.WriteLine(Readonlymodule.Privacy)
|
||||
Else
|
||||
Console.WriteLine("Ismeretlen parancs, kérlek használd a segítséget. (help)")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Function GetSchools(search As String) As Task
|
||||
Dim task As Task = Task.Run(
|
||||
Sub()
|
||||
dim path as string = GetStartupPath() + "schools.json"
|
||||
Dim lastWriteTime As DateTime = File.GetLastWriteTime(path)
|
||||
Dim timediff As TimeSpan = DateTime.Now.Subtract(lastWriteTime)
|
||||
If File.Exists(path) AndAlso timediff.TotalHours < 10 AndAlso Not timediff.TotalHours < 0 Then
|
||||
Dim schools As String = File.ReadAllText(path)
|
||||
Console.ForegroundColor = ConsoleColor.DarkGreen
|
||||
Console.WriteLine("Volt egy már cachelt változat, ami {0} órája volt letöltve.",
|
||||
timediff.TotalHours.ToString("0.0"))
|
||||
Console.ForegroundColor = ConsoleColor.Gray
|
||||
Dim sarray = ""
|
||||
Dim searchIndex As Integer = schools.ToLower.IndexOf(search.ToLower, StringComparison.Ordinal)
|
||||
If searchIndex = - 1 Then
|
||||
Console.WriteLine("Nincs találat, próbálj valami mást.")
|
||||
Else
|
||||
searchIndex = 0
|
||||
Dim jArray As JArray = JArray.Parse(schools)
|
||||
For Each jObject As JObject In jArray
|
||||
Dim nev As String = jObject("nev").ToString().ToLower()
|
||||
Dim azonosito As String = jObject("azonosito").ToString().ToLower()
|
||||
Dim found = False
|
||||
If nev.Contains(search.ToLower, StringComparison.CurrentCultureIgnoreCase) Then
|
||||
searchIndex += 1
|
||||
sarray += jObject.ToString
|
||||
found = True
|
||||
End If
|
||||
If found = False Then
|
||||
If azonosito.Contains(search.ToLower, StringComparison.CurrentCultureIgnoreCase) _
|
||||
Then
|
||||
searchIndex += 1
|
||||
sarray += jObject.ToString
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
If searchIndex = 1 Then
|
||||
Console.WriteLine(sarraygen(sarray))
|
||||
Else
|
||||
Dim arrays As String() = sarray.Split("}{").ToArray
|
||||
Dim number = 0
|
||||
For Each sarray In arrays
|
||||
number += 1
|
||||
Console.WriteLine(vbCrLf + "{0}. Találat", number.ToString)
|
||||
Console.WriteLine(sarraygen(sarray))
|
||||
Next
|
||||
Console.WriteLine(vbCrLf)
|
||||
Console.WriteLine("A parancs 1-nél több iskolát ({0}) talált.", number.ToString)
|
||||
Console.WriteLine("Ha lehet kicsit specifikusabban add meg a nevét!")
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
Dim client = New HttpClient()
|
||||
client.DefaultRequestHeaders.Add("api-version", "v1")
|
||||
Dim response As HttpResponseMessage =
|
||||
client.GetAsync("https://kretaglobalapi.e-kreta.hu/intezmenyek/kreta/publikus").Result
|
||||
If response.IsSuccessStatusCode Then
|
||||
Dim schools As String = response.Content.ReadAsStringAsync().Result
|
||||
File.Delete(path)
|
||||
File.WriteAllText(path, schools)
|
||||
Dim sarray = ""
|
||||
Dim searchIndex As Integer = schools.ToLower.IndexOf(search.ToLower,
|
||||
StringComparison.Ordinal)
|
||||
If searchIndex = - 1 Then
|
||||
Console.WriteLine("Nincs találat, próbálj valami mást.")
|
||||
Else
|
||||
searchIndex = 0
|
||||
Dim jArray As JArray = JArray.Parse(schools)
|
||||
For Each jObject As JObject In jArray
|
||||
Dim nev As String = jObject("nev").ToString().ToLower()
|
||||
Dim azonosito As String = jObject("azonosito").ToString().ToLower()
|
||||
Dim found = False
|
||||
If nev.Contains(search.ToLower, StringComparison.CurrentCultureIgnoreCase) Then
|
||||
searchIndex += 1
|
||||
sarray += jObject.ToString
|
||||
found = True
|
||||
End If
|
||||
If found = False Then
|
||||
If azonosito.Contains(search.ToLower, StringComparison.CurrentCultureIgnoreCase) _
|
||||
Then
|
||||
searchIndex += 1
|
||||
sarray += jObject.ToString
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
If searchIndex = 1 Then
|
||||
Console.WriteLine(sarraygen(sarray))
|
||||
Else
|
||||
Dim arrays As String() = sarray.Split("}{").ToArray
|
||||
Dim number = 0
|
||||
For Each sarray In arrays
|
||||
number += 1
|
||||
Console.WriteLine(vbCrLf + "{0}. Találat", number.ToString)
|
||||
Console.WriteLine(sarraygen(sarray.ToString()))
|
||||
Next
|
||||
Console.WriteLine(vbCrLf)
|
||||
Console.WriteLine("A parancs 1-nél több iskolát ({0}) talált.", number.ToString)
|
||||
Console.WriteLine("Ha lehet kicsit specifikusabban add meg a nevét!")
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
Console.WriteLine("Hiba, {0}", response.StatusCode)
|
||||
End If
|
||||
|
||||
End If
|
||||
End Sub)
|
||||
Return task
|
||||
End Function
|
||||
|
||||
Private Function SarrayGen(stringarray As String)
|
||||
Dim str As String = stringarray.Replace(" ", "").Replace(": ", ":")
|
||||
dim list
|
||||
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
|
||||
list = New List(Of String)(str.Split(New String() {vbCrLf}, StringSplitOptions.None))
|
||||
Else
|
||||
list = New List(Of String)(str.Split(New String() {vbLf}, StringSplitOptions.None))
|
||||
end if
|
||||
dim azonosito as string =
|
||||
list.Item(2).Replace("""azonosito"":""", "Azonosító: ").Replace(""",", "").Replace(vbCrLf, "").
|
||||
ToString
|
||||
dim nev as String =
|
||||
list.Item(3).Replace("""nev"":""", "Név: ").Replace(""",", "").Replace(vbCrLf, "").ToString
|
||||
If nev.Contains("\""") Then
|
||||
nev = nev.Replace("\""", "")
|
||||
End If
|
||||
dim link as String =
|
||||
list.Item(6).Replace("""kretaLink"":""", "Link: ").Replace(""",", "").Replace(vbCrLf, "").ToString
|
||||
Dim final As String = vbCrLf + azonosito + vbCrLf + nev + vbCrLf + link
|
||||
Return final
|
||||
End Function
|
||||
|
||||
Private Function GetNonce()
|
||||
Dim nonce = ""
|
||||
Dim client = New HttpClient()
|
||||
Dim response As HttpResponseMessage = client.GetAsync("https://idp.e-kreta.hu/nonce").Result
|
||||
If response.IsSuccessStatusCode Then
|
||||
nonce = response.Content.ReadAsStringAsync().Result
|
||||
Else
|
||||
Console.WriteLine("Hiba, {0}", response.StatusCode)
|
||||
End If
|
||||
Return nonce
|
||||
End Function
|
||||
|
||||
Private Function GetStartupPath() As String
|
||||
dim path as string = IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
|
||||
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) Then
|
||||
path = path + "\"
|
||||
Else
|
||||
path = path + "/"
|
||||
End if
|
||||
Return path
|
||||
End Function
|
||||
' megfogom ölni magam
|
||||
Private Function GetBearer(username As String, password As String, instituteCode As String) As Task
|
||||
Dim task As Task = Task.Run(
|
||||
Sub()
|
||||
Dim client = New HttpClient()
|
||||
Dim nonce As String = getNonce()
|
||||
Dim authpoolkey As String = GenAuthorizationPolicy(username, institutecode, nonce)
|
||||
Dim content = New FormUrlEncodedContent(New Dictionary(Of String, String) From {
|
||||
{"userName", username},
|
||||
{"password", password},
|
||||
{"institute_code", institutecode},
|
||||
{"grant_type", "password"},
|
||||
{"client_id", "kreta-ellenorzo-mobile-android"}
|
||||
})
|
||||
client.DefaultRequestHeaders.Add("X-Authorizationpolicy-Key", authpoolkey)
|
||||
client.DefaultRequestHeaders.Add("X-Authorizationpolicy-Version", "v2")
|
||||
client.DefaultRequestHeaders.Add("X-Authorizationpolicy-Nonce", nonce)
|
||||
Dim response As HttpResponseMessage =
|
||||
client.PostAsync("https://idp.e-kreta.hu/connect/token", content).Result
|
||||
If response.IsSuccessStatusCode Then
|
||||
Dim result As String = response.Content.ReadAsStringAsync.Result
|
||||
Console.WriteLine("Sikeres lekérés mentve.")
|
||||
Try
|
||||
Dim path As String = GetStartupPath() + "login.json"
|
||||
File.Delete(path)
|
||||
File.WriteAllText(path, result)
|
||||
path = GetStartupPath() + "loginData.json"
|
||||
File.Delete(path)
|
||||
Dim jObject As JObject = JObject.Parse(result)
|
||||
Dim token As String = jObject("access_token").ToString()
|
||||
Dim refreshToken As String = jObject("refresh_token").ToString()
|
||||
Dim json As String = "{""access_token"":""" + token + """," + vbCrLf + """refresh_token"":""" +
|
||||
refreshToken + """," + vbCrLf + """institute_code"":""" + instituteCode +
|
||||
"""}"
|
||||
File.WriteAllText(path, json)
|
||||
File.Delete(GetStartupPath() + "login.json")
|
||||
Catch ex As Exception
|
||||
Console.WriteLine("Hiba történt a mentés során.")
|
||||
Exit Try
|
||||
End Try
|
||||
Console.WriteLine("Adatok elmentve!")
|
||||
Else
|
||||
Console.WriteLine("Hiba, {0}", response.StatusCode)
|
||||
Console.WriteLine("{0}", response.Content.ReadAsStringAsync().Result)
|
||||
End If
|
||||
End Sub)
|
||||
Return task
|
||||
End Function
|
||||
|
||||
Private Function GenAuthorizationPolicy(username As String, institutecode As String, nonce As String)
|
||||
Const hmacKey = "baSsxOwlU1jM"
|
||||
Dim hmac = New HMACSHA512(Encoding.UTF8.GetBytes(hmacKey))
|
||||
Dim unenc As String = institutecode.ToUpper + nonce + username.ToUpper
|
||||
Dim enc As Byte() = hmac.ComputeHash(Encoding.UTF8.GetBytes(unenc))
|
||||
Dim base64 As String = Convert.ToBase64String(enc)
|
||||
Return base64
|
||||
End Function
|
||||
|
||||
private function TanuloiAdatlap() as task
|
||||
dim task as task = task.run(Sub()
|
||||
Dim lastWriteTime As DateTime = File.GetLastWriteTime(getstartuppath + "diakadatlap.json")
|
||||
Dim timediff As TimeSpan = DateTime.Now.Subtract(lastWriteTime)
|
||||
if _
|
||||
File.Exists(getstartuppath + "diakadatlap.json") AndAlso timediff.TotalHours < 10 AndAlso
|
||||
Not timediff.TotalHours < 0 Then
|
||||
Dim diakadatlap As String = File.ReadAllText(getstartuppath + "diakadatlap.json")
|
||||
Console.ForegroundColor = ConsoleColor.DarkGreen
|
||||
Console.WriteLine("Volt egy már cachelt változat, ami {0} órája volt letöltve.",
|
||||
timediff.TotalHours.ToString("0.0"))
|
||||
Console.ForegroundColor = ConsoleColor.Gray
|
||||
Console.WriteLine(diakadatlap)
|
||||
Else
|
||||
dim client = new HttpClient()
|
||||
dim apikey = "21ff6c25-d1da-4a68-a811-c881a6057463"
|
||||
client.DefaultRequestHeaders.Add("apiKey", apikey)
|
||||
dim path as string = GetStartupPath() + "loginData.json"
|
||||
dim token as string
|
||||
dim school as string
|
||||
if File.Exists(path) Then
|
||||
dim jsonString as string = file.ReadAllText(path)
|
||||
dim jsonObject as JObject = JObject.Parse(jsonString)
|
||||
token = jsonObject("access_token").ToString()
|
||||
school = jsonObject("institute_code").ToString()
|
||||
Else
|
||||
Console.WriteLine("Jelenleg nem vagy authentikálva / nem található a loginData.json fájl.")
|
||||
Console.WriteLine("Kérlek használd az auth parancsot.")
|
||||
exit sub
|
||||
End If
|
||||
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token)
|
||||
dim response as HttpResponseMessage =
|
||||
client.GetAsync("https://" + school + ".e-kreta.hu/ellenorzo/v3/sajat/TanuloAdatlap").Result
|
||||
if response.IsSuccessStatusCode Then
|
||||
dim savepath as string = getstartuppath + "diakadatlap.json"
|
||||
Dim result As String = response.Content.ReadAsStringAsync.Result
|
||||
File.Delete(savepath)
|
||||
File.WriteAllText(savepath, result)
|
||||
Console.WriteLine(result)
|
||||
Else
|
||||
Console.WriteLine("Hiba, {0}", response.StatusCode)
|
||||
Console.WriteLine("{0}", response.Content.ReadAsStringAsync().Result)
|
||||
End If
|
||||
End If
|
||||
end sub)
|
||||
return task
|
||||
End function
|
||||
|
||||
private function GondviseloiAdatlap() as task
|
||||
dim task as task = task.run(Sub()
|
||||
Dim lastWriteTime As DateTime = File.GetLastWriteTime(getstartuppath + "szuloadatlap.json")
|
||||
Dim timediff As TimeSpan = DateTime.Now.Subtract(lastWriteTime)
|
||||
if file.Exists(getstartuppath + "szuloadatlap.json") AndAlso timediff.TotalHours < 10 AndAlso
|
||||
Not timediff.TotalHours < 0 Then
|
||||
dim szuloadatlap as string = file.ReadAllText(getstartuppath + "szuloadatlap.json")
|
||||
Console.ForegroundColor = ConsoleColor.DarkGreen
|
||||
Console.WriteLine("Volt egy már cachelt változat, ami {0} órája volt letöltve.",
|
||||
timediff.TotalHours.ToString("0.0"))
|
||||
Console.ForegroundColor = ConsoleColor.Gray
|
||||
Console.WriteLine(szuloadatlap)
|
||||
Else
|
||||
dim client = new HttpClient()
|
||||
dim apikey = "21ff6c25-d1da-4a68-a811-c881a6057463"
|
||||
client.DefaultRequestHeaders.Add("apiKey", apikey)
|
||||
dim path as string = GetStartupPath() + "loginData.json"
|
||||
dim token as string
|
||||
dim school as string
|
||||
if File.Exists(path) Then
|
||||
dim jsonString as string = file.ReadAllText(path)
|
||||
dim jsonObject as JObject = JObject.Parse(jsonString)
|
||||
token = jsonObject("access_token").ToString()
|
||||
school = jsonObject("institute_code").ToString()
|
||||
Else
|
||||
Console.WriteLine("Jelenleg nem vagy authentikálva / nem található a loginData.json fájl.")
|
||||
Console.WriteLine("Kérlek használd az auth parancsot.")
|
||||
exit sub
|
||||
End If
|
||||
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token)
|
||||
dim response as HttpResponseMessage =
|
||||
client.GetAsync("https://" + school + ".e-kreta.hu/ellenorzo/v3/sajat/GondviseloAdatlap").Result
|
||||
if response.IsSuccessStatusCode Then
|
||||
dim savepath as string = getstartuppath + "szuloadatlap.json"
|
||||
Dim result As String = response.Content.ReadAsStringAsync.Result
|
||||
File.Delete(savepath)
|
||||
File.WriteAllText(savepath, result)
|
||||
Console.WriteLine(result)
|
||||
Else
|
||||
if response.StatusCode.ToString() = "Forbidden" Then
|
||||
Console.WriteLine("Használj inkább tanulói adatlapot! (adatlap tanulo)")
|
||||
End If
|
||||
Console.WriteLine("Hiba, {0}", response.StatusCode)
|
||||
Console.WriteLine("{0}", response.Content.ReadAsStringAsync().Result)
|
||||
End If
|
||||
End If
|
||||
end sub)
|
||||
return task
|
||||
End function
|
||||
|
||||
private function AuthRefreshToken() as task
|
||||
dim task as task = Task.run(
|
||||
Sub()
|
||||
dim client = new HttpClient()
|
||||
dim path as string = GetStartupPath() + "loginData.json"
|
||||
dim refreshtok as string
|
||||
dim institutecode as string
|
||||
if File.Exists(path) Then
|
||||
dim jsonString as string = file.ReadAllText(path)
|
||||
dim jsonObject as JObject = JObject.Parse(jsonString)
|
||||
refreshtok = jsonObject("refresh_token").ToString()
|
||||
institutecode = jsonObject("institute_code").ToString()
|
||||
Else
|
||||
Console.WriteLine("Nem voltál authentikálva / nem található a loginData.json fájl.")
|
||||
Console.WriteLine("Kérlek használd az auth parancsot.")
|
||||
exit sub
|
||||
End If
|
||||
Dim content = New FormUrlEncodedContent(New Dictionary(Of String, String) From {
|
||||
{"institute_code", institutecode},
|
||||
{"refresh_token", refreshtok},
|
||||
{"grant_type", "refresh_token"},
|
||||
{"client_id", "kreta-ellenorzo-mobile-android"}
|
||||
})
|
||||
dim response as HttpResponseMessage =
|
||||
client.PostAsync("https://idp.e-kreta.hu/connect/token", content).Result
|
||||
If response.IsSuccessStatusCode Then
|
||||
Dim result As String = response.Content.ReadAsStringAsync.Result
|
||||
Console.WriteLine("Sikeres lekérés mentve.")
|
||||
Try
|
||||
path = GetStartupPath() + "login.json"
|
||||
File.Delete(path)
|
||||
File.WriteAllText(path, result)
|
||||
path = GetStartupPath() + "loginData.json"
|
||||
File.Delete(path)
|
||||
Dim jObject As JObject = JObject.Parse(result)
|
||||
Dim token As String = jObject("access_token").ToString()
|
||||
Dim refreshToken As String = jObject("refresh_token").ToString()
|
||||
Dim json As String = "{""access_token"":""" + token + """," + vbCrLf + """refresh_token"":""" +
|
||||
refreshToken + """," + vbCrLf + """institute_code"":""" + instituteCode +
|
||||
"""}"
|
||||
File.WriteAllText(path, json)
|
||||
file.Delete(GetStartupPath() + "login.json")
|
||||
Catch ex As Exception
|
||||
Console.WriteLine("Hiba történt a mentés során.")
|
||||
Exit Try
|
||||
End Try
|
||||
Console.WriteLine("Adatok elmentve!")
|
||||
Else
|
||||
Console.WriteLine("Hiba, {0}", response.StatusCode)
|
||||
Console.WriteLine("{0}", response.Content.ReadAsStringAsync().Result)
|
||||
End If
|
||||
end sub)
|
||||
return task
|
||||
End function
|
||||
|
||||
private Function ReadPassword() As String
|
||||
Dim password As New System.Text.StringBuilder()
|
||||
While True
|
||||
Dim info As ConsoleKeyInfo = Console.ReadKey(True)
|
||||
If info.Key = ConsoleKey.Enter Then
|
||||
Console.WriteLine()
|
||||
Exit While
|
||||
ElseIf info.Key = ConsoleKey.Backspace Then
|
||||
If password.Length > 0 Then
|
||||
password.Remove(password.Length - 1, 1)
|
||||
Console.Write(vbBack)
|
||||
Console.Write(" ")
|
||||
Console.Write(vbBack)
|
||||
End If
|
||||
Else
|
||||
password.Append(info.KeyChar)
|
||||
Console.Write("*")
|
||||
End If
|
||||
End While
|
||||
Return password.ToString()
|
||||
End Function
|
||||
|
||||
private function RevokeRefreshToken() as Task
|
||||
dim task as task = task.run(
|
||||
Sub()
|
||||
dim client = new HttpClient()
|
||||
dim path as string = GetStartupPath() + "loginData.json"
|
||||
dim refreshtok as string
|
||||
if File.Exists(path) Then
|
||||
dim jsonString as string = file.ReadAllText(path)
|
||||
dim jsonObject as JObject = JObject.Parse(jsonString)
|
||||
refreshtok = jsonObject("refresh_token").ToString()
|
||||
Else
|
||||
exit sub
|
||||
End If
|
||||
Dim content = New FormUrlEncodedContent(New Dictionary(Of String, String) From {
|
||||
{"token", refreshtok},
|
||||
{"client_id", "kreta-ellenorzo-mobile-android"}
|
||||
})
|
||||
dim response as HttpResponseMessage =
|
||||
client.PostAsync("https://idp.e-kreta.hu/connect/revocation", content).Result
|
||||
If response.IsSuccessStatusCode Then
|
||||
Console.WriteLine("Refresh token érvénytelenítve.")
|
||||
Else
|
||||
Console.WriteLine("Hiba, {0}", response.StatusCode)
|
||||
Console.WriteLine("{0}", response.Content.ReadAsStringAsync().Result)
|
||||
End If
|
||||
end sub)
|
||||
return task
|
||||
End function
|
||||
End Module
|
Loading…
Add table
Add a link
Reference in a new issue