aplus/main.go

87 lines
2.3 KiB
Go
Raw Normal View History

2023-10-27 19:02:38 -04:00
package main
import (
"fmt"
"io"
"net/http"
"net/http/cookiejar"
"strings"
"golang.org/x/net/publicsuffix"
2023-10-27 19:02:38 -04:00
)
var base_link string
var token string
2023-10-27 19:02:38 -04:00
func main() {
jar, _ := cookiejar.New(&cookiejar.Options{
PublicSuffixList: publicsuffix.List,
})
client := http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
fmt.Println("Redirected to:", req.URL)
fmt.Println(req.Cookies())
return nil
},
Jar: jar,
}
2023-10-27 19:02:38 -04:00
initialize()
2023-11-04 01:55:30 -04:00
// select_course()
2023-10-30 17:58:38 -04:00
2023-10-27 19:02:38 -04:00
aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, 7329, token) // 7329 always works
2023-11-04 01:55:30 -04:00
aplus := get_aplus(token, aplus_link, client)
2023-10-27 19:02:38 -04:00
fmt.Println(aplus)
resp, err := client.Get(aplus)
2023-10-27 19:02:38 -04:00
if err != nil {
2023-11-04 01:55:30 -04:00
fmt.Println("Error while performing GET request to aplus auth link.")
2023-10-27 19:02:38 -04:00
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
2023-10-30 17:58:38 -04:00
2023-11-04 01:55:30 -04:00
form_str := get_form_from_request_body(body)
fmt.Println(form_str)
2023-10-30 17:58:38 -04:00
2023-11-04 01:55:30 -04:00
form_values := parse_form(form_str)
2023-10-31 02:06:01 -04:00
fmt.Println("Form Values:")
for key, values := range form_values {
fmt.Printf("%s: %s\n", key, values)
}
2023-10-31 02:30:30 -04:00
//req, _ := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)
req, _ := http.NewRequest(http.MethodPost, "https://floridapoly.aplusattendance.com/canvas", strings.NewReader(form_values.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Access-Control-Allow-Origin", "*")
req.Header.Set("Access-Control-Allow-Credentials", "true")
req.Header.Set("Access-Control-Allow-Headers", "Content-Type,access-control-allow-origin, access-control-allow-headers,access-control-allow-credentials")
resp, err = client.Do(req)
2023-10-30 17:58:38 -04:00
2023-11-04 01:55:30 -04:00
if err != nil {
fmt.Println("Error posting form to Aplus Attendance.")
2023-10-30 17:58:38 -04:00
}
body, err = io.ReadAll(resp.Body)
2023-10-30 17:58:38 -04:00
if err != nil {
2023-11-04 01:55:30 -04:00
fmt.Println("Error reading body of post form response from aplus attendance.")
2023-10-30 17:58:38 -04:00
}
2023-11-04 01:55:30 -04:00
fmt.Println(string(body))
//fmt.Println(resp)
fmt.Println(resp.Header)
fmt.Println(resp.Cookies())
2023-11-04 01:55:30 -04:00
// we need to submit the above post request correctly in order to submit this request.
//resp, _ = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&doStudentAuth=truee")
//body, _ = io.ReadAll(resp.Body)
2023-10-30 17:58:38 -04:00
2023-11-04 01:55:30 -04:00
//fmt.Println(string(body))
//fmt.Println(req)
}