diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 75 |
1 files changed, 4 insertions, 71 deletions
| @@ -1,86 +1,19 @@ | |||
| 1 | package main | 1 | package main |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | ||
| 5 | "io" | ||
| 6 | "net/http" | 4 | "net/http" |
| 7 | "net/http/cookiejar" | ||
| 8 | "strings" | ||
| 9 | |||
| 10 | "golang.org/x/net/publicsuffix" | ||
| 11 | ) | 5 | ) |
| 12 | 6 | ||
| 13 | var base_link string | 7 | var base_link string |
| 14 | var token string | 8 | var token string |
| 9 | var client http.Client | ||
| 15 | 10 | ||
| 16 | func main() { | 11 | func main() { |
| 17 | |||
| 18 | jar, _ := cookiejar.New(&cookiejar.Options{ | ||
| 19 | PublicSuffixList: publicsuffix.List, | ||
| 20 | }) | ||
| 21 | |||
| 22 | client := http.Client{ | ||
| 23 | CheckRedirect: func(req *http.Request, via []*http.Request) error { | ||
| 24 | fmt.Println("Redirected to:", req.URL) | ||
| 25 | fmt.Println(req.Cookies()) | ||
| 26 | return nil | ||
| 27 | }, | ||
| 28 | Jar: jar, | ||
| 29 | } | ||
| 30 | |||
| 31 | initialize() | 12 | initialize() |
| 32 | 13 | ||
| 33 | // select_course() | 14 | // select_course() |
| 15 | course_code := 7329 | ||
| 16 | launch_aplus(course_code) | ||
| 34 | 17 | ||
| 35 | aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, 7329, token) // 7329 always works | 18 | // enter_code() |
| 36 | aplus := get_aplus(token, aplus_link, client) | ||
| 37 | fmt.Println(aplus) | ||
| 38 | resp, err := client.Get(aplus) | ||
| 39 | |||
| 40 | if err != nil { | ||
| 41 | fmt.Println("Error while performing GET request to aplus auth link.") | ||
| 42 | } | ||
| 43 | |||
| 44 | defer resp.Body.Close() | ||
| 45 | body, _ := io.ReadAll(resp.Body) | ||
| 46 | |||
| 47 | form_str := get_form_from_request_body(body) | ||
| 48 | fmt.Println(form_str) | ||
| 49 | |||
| 50 | form_values := parse_form(form_str) | ||
| 51 | |||
| 52 | fmt.Println("Form Values:") | ||
| 53 | for key, values := range form_values { | ||
| 54 | fmt.Printf("%s: %s\n", key, values) | ||
| 55 | } | ||
| 56 | |||
| 57 | //req, _ := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values) | ||
| 58 | req, _ := http.NewRequest(http.MethodPost, "https://floridapoly.aplusattendance.com/canvas", strings.NewReader(form_values.Encode())) | ||
| 59 | req.Header.Set("Content-Type", "application/x-www-form-urlencoded") | ||
| 60 | req.Header.Set("Access-Control-Allow-Origin", "*") | ||
| 61 | req.Header.Set("Access-Control-Allow-Credentials", "true") | ||
| 62 | req.Header.Set("Access-Control-Allow-Headers", "Content-Type,access-control-allow-origin, access-control-allow-headers,access-control-allow-credentials") | ||
| 63 | |||
| 64 | resp, err = client.Do(req) | ||
| 65 | |||
| 66 | if err != nil { | ||
| 67 | fmt.Println("Error posting form to Aplus Attendance.") | ||
| 68 | } | ||
| 69 | |||
| 70 | body, err = io.ReadAll(resp.Body) | ||
| 71 | |||
| 72 | if err != nil { | ||
| 73 | fmt.Println("Error reading body of post form response from aplus attendance.") | ||
| 74 | } | ||
| 75 | |||
| 76 | fmt.Println(string(body)) | ||
| 77 | //fmt.Println(resp) | ||
| 78 | fmt.Println(resp.Header) | ||
| 79 | fmt.Println(resp.Cookies()) | ||
| 80 | // we need to submit the above post request correctly in order to submit this request. | ||
| 81 | //resp, _ = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&doStudentAuth=truee") | ||
| 82 | //body, _ = io.ReadAll(resp.Body) | ||
| 83 | |||
| 84 | //fmt.Println(string(body)) | ||
| 85 | //fmt.Println(req) | ||
| 86 | } | 19 | } |
