-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (48 loc) · 1.62 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"bytes"
"fmt"
"net/http"
"os/exec"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
var function string = r.URL.Query().Get("function")
var project string = r.URL.Query().Get("project")
var runner string = r.URL.Query().Get("runner")
var user string = r.URL.Query().Get("user")
var redirect string = r.URL.Query().Get("redirect")
var method string = r.URL.Query().Get("method")
if (function == "stdin") {
var out bytes.Buffer
cmd := exec.Command("crconsole", "-u", user, "-i", "/tmp/" + user + ".priv", "-p", project, "-r", runner, "stdin", "-f", "/tmp/stdin_" + user + "_stdin.tmp")
cmd.Stdout = &out
cmd.Stderr = &out
cmd.Run()
fmt.Fprintln(w, out.String())
} else if (function == "get") {
var out bytes.Buffer
cmd := exec.Command("crconsole", "-u", user, "-i", "/tmp/" + user + ".priv", "-p", project, "-r", runner, "get", "-m", method)
cmd.Stdout = &out
cmd.Stderr = &out
cmd.Run()
fmt.Fprintln(w, out.String())
} else if (function == "run") {
var out bytes.Buffer
cmd := exec.Command("crconsole", "-u", user, "-i", "/tmp/" + user + ".priv", "-p", project, "-r", runner, "run", "-x", redirect)
cmd.Stdout = &out
cmd.Stderr = &out
cmd.Run()
fmt.Fprintln(w, out.String())
} else {
var out bytes.Buffer
cmd := exec.Command("crconsole", "-u", user, "-i", "/tmp/" + user + ".priv", "-p", project, "-r", runner, function)
cmd.Stdout = &out
cmd.Stderr = &out
cmd.Run()
fmt.Fprintln(w, out.String())
}
})
http.ListenAndServe("127.0.0.1:5634", nil)
fmt.Println("Running and serving on :5634")
}