1 | 1 | | package web |
2 | 2 | | |
3 | 3 | | import ( |
4 | | - | "goc2/internal/app/api" |
5 | 4 | | "encoding/json" |
6 | 5 | | "fmt" |
| 6 | + | "goc2/internal/app/api" |
7 | 7 | | "log" |
8 | 8 | | "net/http" |
9 | 9 | | |
| skipped 17 lines |
27 | 27 | | router := httprouter.New() |
28 | 28 | | |
29 | 29 | | //Main Entry |
30 | | - | router.POST("/api/scan", apiScan) |
| 30 | + | router.POST("/api/cmd/update", apiCmdUpdate) |
| 31 | + | router.POST("/api/cmd/update/output", apiCmdUpdateOut) |
| 32 | + | router.POST("/api/cmd/new", apiCmdNew) |
31 | 33 | | |
32 | 34 | | //Main Entry |
33 | 35 | | router.GET("/api/test", apiTest) |
| skipped 4 lines |
38 | 40 | | |
39 | 41 | | //commands Endpoints |
40 | 42 | | router.GET("/api/cmds/:name", apiCmds) |
| 43 | + | router.GET("/api/cmd/output/:id", apiCmdsOut) |
41 | 44 | | router.GET("/cmds/", redirect) |
42 | 45 | | |
43 | 46 | | fmt.Printf("Starting server at port 8005\n") |
| skipped 7 lines |
51 | 54 | | http.Redirect(w, r, "/", 301) |
52 | 55 | | } |
53 | 56 | | |
54 | | - | func apiScan(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { |
55 | | - | w.Header().Set("Content-Type", "application/json") |
| 57 | + | func apiCmdUpdate(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { |
| 58 | + | w.Header().Set("Content-Type", "application/x-www-form-urlencoded") |
| 59 | + | if err := r.ParseForm(); err != nil { |
| 60 | + | fmt.Fprintf(w, "ParseForm() err: %v", err) |
| 61 | + | return |
| 62 | + | } |
| 63 | + | |
| 64 | + | ID := r.FormValue("id") |
| 65 | + | OUTPUT := r.FormValue("output") |
| 66 | + | fmt.Println(ID) |
| 67 | + | fmt.Println(OUTPUT) |
| 68 | + | |
| 69 | + | jsond := map[string]interface{}{ |
| 70 | + | "status": "Command Updated", |
| 71 | + | } |
| 72 | + | |
| 73 | + | jsondata, err := json.Marshal(jsond) |
| 74 | + | if err != nil { |
| 75 | + | log.Fatalln(err) |
| 76 | + | } |
| 77 | + | fmt.Fprintf(w, string(jsondata)) |
| 78 | + | api.UpdateCMDStatus(ID, OUTPUT) |
| 79 | + | } |
| 80 | + | |
| 81 | + | func apiCmdUpdateOut(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { |
| 82 | + | w.Header().Set("Content-Type", "application/x-www-form-urlencoded") |
| 83 | + | if err := r.ParseForm(); err != nil { |
| 84 | + | fmt.Fprintf(w, "ParseForm() err: %v", err) |
| 85 | + | return |
| 86 | + | } |
| 87 | + | |
| 88 | + | ID := r.FormValue("id") |
| 89 | + | fmt.Println(ID) |
| 90 | + | |
| 91 | + | jsond := map[string]interface{}{ |
| 92 | + | "status": "Command Updated", |
| 93 | + | } |
| 94 | + | |
| 95 | + | jsondata, err := json.Marshal(jsond) |
| 96 | + | if err != nil { |
| 97 | + | log.Fatalln(err) |
| 98 | + | } |
| 99 | + | fmt.Fprintf(w, string(jsondata)) |
| 100 | + | api.UpdateCMDStatusOut(ID) |
| 101 | + | } |
| 102 | + | |
| 103 | + | func apiCmdNew(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { |
| 104 | + | w.Header().Set("Content-Type", "application/x-www-form-urlencoded") |
56 | 105 | | if err := r.ParseForm(); err != nil { |
57 | 106 | | fmt.Fprintf(w, "ParseForm() err: %v", err) |
58 | 107 | | return |
59 | 108 | | } |
60 | 109 | | |
61 | | - | //domains := r.FormValue("domains") |
62 | | - | //git := r.FormValue("git") |
63 | | - | //email := r.FormValue("email") |
64 | | - | //scanner := r.FormValue("scanner") |
| 110 | + | CMD := r.FormValue("cmd") |
| 111 | + | fmt.Println(CMD) |
65 | 112 | | |
66 | 113 | | jsond := map[string]interface{}{ |
67 | | - | "status": "Scan Started", |
| 114 | + | "status": "Command Updated", |
68 | 115 | | } |
69 | 116 | | |
70 | 117 | | jsondata, err := json.Marshal(jsond) |
| skipped 1 lines |
72 | 119 | | log.Fatalln(err) |
73 | 120 | | } |
74 | 121 | | fmt.Fprintf(w, string(jsondata)) |
75 | | - | //go api.WebScan(domains, git, email, scanner) |
| 122 | + | api.NewCMD(CMD) |
76 | 123 | | } |
77 | 124 | | |
78 | 125 | | func apiAgents(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { |
| skipped 3 lines |
82 | 129 | | fmt.Fprintf(w, "%s", string(d)) |
83 | 130 | | } |
84 | 131 | | |
85 | | - | |
86 | 132 | | func apiCmds(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { |
87 | 133 | | w.Header().Set("Content-Type", "application/json") |
88 | 134 | | d := api.GetCommands(ps.ByName("name")) |
| 135 | + | |
| 136 | + | fmt.Fprintf(w, "%s", string(d)) |
| 137 | + | } |
| 138 | + | |
| 139 | + | func apiCmdsOut(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { |
| 140 | + | w.Header().Set("Content-Type", "application/json") |
| 141 | + | d := api.GetCommandsOut(ps.ByName("id")) |
89 | 142 | | |
90 | 143 | | fmt.Fprintf(w, "%s", string(d)) |
91 | 144 | | } |
| skipped 13 lines |