2023-10-27 19:02:38 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
2023-11-12 15:05:16 -05:00
|
|
|
"net/http/cookiejar"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"golang.org/x/net/publicsuffix"
|
2023-10-27 19:02:38 -04:00
|
|
|
)
|
|
|
|
|
2023-11-07 00:21:48 -05:00
|
|
|
var base_link string
|
|
|
|
var token string
|
|
|
|
|
2023-10-27 19:02:38 -04:00
|
|
|
func main() {
|
2023-11-12 15:05:16 -05:00
|
|
|
|
|
|
|
jar, _ := cookiejar.New(&cookiejar.Options{
|
|
|
|
PublicSuffixList: publicsuffix.List,
|
|
|
|
})
|
|
|
|
|
2023-10-30 01:00:50 -04:00
|
|
|
client := http.Client{
|
|
|
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
|
|
|
fmt.Println("Redirected to:", req.URL)
|
2023-11-12 15:05:16 -05:00
|
|
|
fmt.Println(req.Cookies())
|
2023-10-30 01:00:50 -04:00
|
|
|
return nil
|
|
|
|
},
|
2023-11-12 15:05:16 -05:00
|
|
|
Jar: jar,
|
2023-10-30 01:00:50 -04:00
|
|
|
}
|
2023-10-27 19:02:38 -04:00
|
|
|
|
2023-11-07 00:21:48 -05: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)
|
2023-10-30 01:00:50 -04:00
|
|
|
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()
|
2023-11-07 00:21:48 -05:00
|
|
|
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
|
|
|
|
2023-11-12 15:05:16 -05: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
|
|
|
}
|
|
|
|
|
2023-11-12 15:05:16 -05: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))
|
2023-11-12 15:05:16 -05:00
|
|
|
//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.
|
2023-11-12 15:05:16 -05:00
|
|
|
//resp, _ = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&doStudentAuth=truee")
|
2023-11-07 00:21:48 -05:00
|
|
|
//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)
|
|
|
|
}
|