From f7deb2420295ba04dbb5cfc5b1087b0c9b695bb4 Mon Sep 17 00:00:00 2001 From: PlashSpeed-Aiman Date: Thu, 23 Feb 2023 01:11:10 +0800 Subject: [PATCH] QoL improvents + added ability to look for results --- .gitignore | 7 +++ imaalum/imaalum.go | 23 +++++++-- main.go | 115 +++++++++++++++++++++++++++++---------------- 3 files changed, 100 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index df222d6..6ad22e3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,10 @@ /Financial.pdf /timetable.pdf /cs.html +gopher.png +PassGo.exe - Shortcut.lnk +PassGo.zip +hello +New Text Document.bat +.gitignore +result.html diff --git a/imaalum/imaalum.go b/imaalum/imaalum.go index da6c941..2fe27d8 100644 --- a/imaalum/imaalum.go +++ b/imaalum/imaalum.go @@ -7,6 +7,7 @@ import ( userstruct "PassGo/model/user" "encoding/base64" "encoding/json" + "fmt" "io" "log" "net/http" @@ -77,7 +78,7 @@ func Imaalum_login() ImaalumClient { } return MClient } -func GetGeneralExamTimeTable(ws *sync.WaitGroup, client ImaalumClient) { +func GetGeneralExamTimeTable(ws *sync.WaitGroup, client *ImaalumClient) { response, _ := client.client.Get("https://imaluum.iium.edu.my/MyAcademic/course_timetable") if response.StatusCode == 200 { bodyBytes, err := io.ReadAll(response.Body) @@ -95,8 +96,20 @@ func GetGeneralExamTimeTable(ws *sync.WaitGroup, client ImaalumClient) { client.client.Get("https://cas.iium.edu.my:8448/cas/logout?service=http://imaluum.iium.edu.my/") ws.Done() } -func GetConfimationSlip(ws *sync.WaitGroup, client ImaalumClient) { - response, _ := client.client.Get("https://imaluum.iium.edu.my/confirmationslip?ses=2021/2022&sem=1") +func GetConfimationSlip(ws *sync.WaitGroup, client *ImaalumClient) { + var session_val string = "" + fmt.Println("Session i.e 2021/2022") + _, err := fmt.Scan(&session_val) + if err != nil { + log.Fatal(err) + } + var semester_val string = "" + fmt.Println("Semester") + _, err = fmt.Scan(&semester_val) + if err != nil { + log.Fatal(err) + } + response, _ := client.client.Get(fmt.Sprintf("https://imaluum.iium.edu.my/confirmationslip?ses=%s&sem=%s",session_val,semester_val)) if response.StatusCode == 200 { bodyBytes, err := io.ReadAll(response.Body) if err != nil { @@ -112,7 +125,7 @@ func GetConfimationSlip(ws *sync.WaitGroup, client ImaalumClient) { client.client.Get("https://cas.iium.edu.my:8448/cas/logout?service=http://imaluum.iium.edu.my/") ws.Done() } -func GetFinance(ws *sync.WaitGroup, client ImaalumClient) { +func GetFinance(ws *sync.WaitGroup, client *ImaalumClient) { response, _ := client.client.Get("https://imaluum.iium.edu.my/MyFinancial") if response.StatusCode == 200 { bodyBytes, err := io.ReadAll(response.Body) @@ -122,7 +135,7 @@ func GetFinance(ws *sync.WaitGroup, client ImaalumClient) { } _ = os.WriteFile("Finance.pdf", bodyBytes, 0644) - dialog.XPlatMessageBox("Done", "Download Complete") + dialog.XPlatMessageBox("Done", "Finance.PDF Download Complete") } client.client.Get("https://cas.iium.edu.my:8448/cas/logout?service=http://imaluum.iium.edu.my/") diff --git a/main.go b/main.go index 611ac94..d94280e 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "io" "io/fs" "log" "net/http" @@ -20,7 +21,6 @@ import ( "os" "sync" "syscall" - "unsafe" "golang.org/x/term" ) @@ -35,34 +35,80 @@ AUTOMATE LOGIN TO IIUM-STUDENT WITH 2 EASY STEPS ***CREDENTIALS ARE SAVED IN YOUR PC*** `) ws := new(sync.WaitGroup) - fmt.Println("Select Function\n1.Store Creds\n2.Connect To Network\n3.Logout\n4.Login To iMaalum") + fmt.Println("Select Function\n1.Store Creds\n2.Connect To Network\n3.Logout\n4.Login To iMaalum\n5.Results") var user_input int = 0 _, err := fmt.Scan(&user_input) if err != nil { log.Fatal(err) } - switch user_input { - case 1: - store_pass() - case 2: - connect_network() - case 3: - logout_network() - case 4: - dialog.XPlatMessageBox("TEST", "TEST") - var client = imaalum.Imaalum_login() - ws.Add(3) - go imaalum.GetFinance(ws, client) - go imaalum.GetConfimationSlip(ws, client) - go imaalum.GetGeneralExamTimeTable(ws, client) - ws.Wait() - } + eval_choice(user_input,ws) + +} +func eval_choice(choice int,ws *sync.WaitGroup){ + switch choice { + case 1: + store_pass() + case 2: + connect_network() + case 3: + logout_network() + case 4: + dialog.XPlatMessageBox("TEST", "TEST") + var client = imaalum.Imaalum_login() + ws.Add(3) + go imaalum.GetFinance(ws, &client) + go imaalum.GetConfimationSlip(ws, &client) + go imaalum.GetGeneralExamTimeTable(ws, &client) + ws.Wait() + case 5: + checkResult() + } } -// func read_pass() { +func checkResult(){ + var UserStruct userstruct.User + file, err := os.ReadFile("indexxx.json") + if err != nil { + log.Fatal(err) + panic(err) + } + + var session_val string = "" + fmt.Println("Session i.e 2021/2022") + _, err = fmt.Scan(&session_val) + if err != nil { + log.Fatal(err) + } + var semester_val string = "" + fmt.Println("Semester") + _, err = fmt.Scan(&semester_val) + if err != nil { + log.Fatal(err) + } + json.Unmarshal(file, &UserStruct) + decodeUser, _ := base64.StdEncoding.DecodeString(UserStruct.User) + decodePass, _ := base64.StdEncoding.DecodeString(UserStruct.Password) + form_val := url.Values{ + "mat_no" : {string(decodeUser)}, + "pin_no" : {string(decodePass)}, + "sessi" : {session_val}, + "semester" : {semester_val}, + "login" :{"Login"}, + } + resp,err := http.PostForm("https://myapps.iium.edu.my/anrapps/viewResult.php", form_val) + if resp.StatusCode == 200 { + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + dialog.XPlatMessageBox("ERROR", err.Error()) + os.Exit(1) + } + + _ = os.WriteFile("result.html", bodyBytes, 0644) -// } + dialog.XPlatMessageBox("Done", "Download Complete") + } +} func store_pass() { userVal := "" @@ -89,6 +135,7 @@ func store_pass() { } } func logout_network() { + transCfg := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // ignore expired SSL certificates } @@ -96,16 +143,20 @@ func logout_network() { _, err := client.Get("https://captiveportalmahallahgombak.iium.edu.my/auth/logout.html") if err != nil { dialog.XPlatMessageBox("ERROR", "UNABLE TO LOGOUT (I GUESS)") + panic(err) } dialog.XPlatMessageBox("SUCCESS", "YOU ARE LOGGED OUT OF IIUM-STUDENT") } func connect_network() { + var UserStruct userstruct.User file, err := os.ReadFile("indexxx.json") if err != nil { log.Fatal(err) + panic(err) + } - var UserStruct userstruct.User + json.Unmarshal(file, &UserStruct) decodeUser, _ := base64.StdEncoding.DecodeString(UserStruct.User) decodePass, _ := base64.StdEncoding.DecodeString(UserStruct.Password) @@ -120,11 +171,13 @@ func connect_network() { TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // ignore expired SSL certificates } client := &http.Client{Transport: transCfg} - resp, err := client.PostForm("https://captiveportalmahallahgombak.iium.edu.my/cgi-bin/login", formVal) + resp, err := client.PostForm("https://captiveportalmahallahgombak.iium.edu.my/cgi-bin/login", formVal) + formVal = nil if err != nil { dialog.XPlatMessageBox("ERROR", err.Error()) log.Fatal(err) + panic(err) } var res map[string]interface{} @@ -135,21 +188,3 @@ func connect_network() { } // MessageBox of Win32 API. -func MessageBox(hwnd uintptr, caption, title string, flags uint) int { - ret, _, _ := syscall.NewLazyDLL("user32.dll").NewProc("MessageBoxW").Call( - uintptr(hwnd), - uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(caption))), - uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))), - uintptr(flags)) - - return int(ret) -} - -// MessageBoxPlain of Win32 API. -func MessageBoxPlain(title, caption string) int { - const ( - NULL = 0 - MB_OK = 0 - ) - return MessageBox(NULL, caption, title, MB_OK) -}