summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md12
-rw-r--r--aplus.go28
-rw-r--r--canvas.go17
-rw-r--r--main.go75
4 files changed, 60 insertions, 72 deletions
diff --git a/README.md b/README.md
index f08a35e..5735615 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,13 @@
1# aplus 1# aplus
2 2
3aplus cli \ No newline at end of file 3aplus cli
4
5# Usage
6
7# Launch interactive prompt
8aplus
9
10# Enter code immediately
11aplus -c <code>
12aplus --code <code>
13
diff --git a/aplus.go b/aplus.go
index ae5e054..3f3640b 100644
--- a/aplus.go
+++ b/aplus.go
@@ -75,3 +75,31 @@ func extract_attribute(input string, attribute string) string {
75 75
76 return input[start : start+end] 76 return input[start : start+end]
77} 77}
78
79func launch_aplus(course_code int) {
80 aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, course_code, token) // 7329 always works
81 aplus := get_aplus(token, aplus_link, client)
82
83 resp, err := client.Get(aplus)
84
85 if err != nil {
86 fmt.Println("Error while performing GET request to aplus auth link.")
87 }
88
89 defer resp.Body.Close()
90 body, _ := io.ReadAll(resp.Body)
91
92 form_str := get_form_from_request_body(body)
93
94 form_values := parse_form(form_str)
95
96 resp, _ = client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)
97
98 body, err = io.ReadAll(resp.Body)
99
100 if err != nil {
101 fmt.Println("Error reading body of post form response from aplus attendance.")
102 }
103
104 fmt.Println(string(body))
105}
diff --git a/canvas.go b/canvas.go
index 33c7f6b..3aa8050 100644
--- a/canvas.go
+++ b/canvas.go
@@ -5,18 +5,35 @@ import (
5 "fmt" 5 "fmt"
6 "io" 6 "io"
7 "net/http" 7 "net/http"
8 "net/http/cookiejar"
8 "os" 9 "os"
10
11 "golang.org/x/net/publicsuffix"
9) 12)
10 13
11func initialize() { 14func initialize() {
12 base_link = "https://floridapolytechnic.instructure.com/api/v1" 15 base_link = "https://floridapolytechnic.instructure.com/api/v1"
13 token = os.Getenv("CANVAS_API_KEY") 16 token = os.Getenv("CANVAS_API_KEY")
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 }
14} 30}
15 31
16func get_courses(token string, link string, client http.Client) []CanvasCourse { 32func get_courses(token string, link string, client http.Client) []CanvasCourse {
17 resp, err := client.Get(link) 33 resp, err := client.Get(link)
18 if err != nil { 34 if err != nil {
19 fmt.Println("Error performing GET request to get courses.") 35 fmt.Println("Error performing GET request to get courses.")
36 return nil
20 } 37 }
21 defer resp.Body.Close() 38 defer resp.Body.Close()
22 body, _ := io.ReadAll(resp.Body) 39 body, _ := io.ReadAll(resp.Body)
diff --git a/main.go b/main.go
index 473b027..8f669e1 100644
--- a/main.go
+++ b/main.go
@@ -1,86 +1,19 @@
1package main 1package main
2 2
3import ( 3import (
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
13var base_link string 7var base_link string
14var token string 8var token string
9var client http.Client
15 10
16func main() { 11func 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&amp;doStudentAuth=truee")
82 //body, _ = io.ReadAll(resp.Body)
83
84 //fmt.Println(string(body))
85 //fmt.Println(req)
86} 19}