summaryrefslogtreecommitdiff
path: root/pkg/backend/webapi.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-06-23 19:12:08 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-08-11 20:59:52 +0200
commit0f8eab4e1157e83f39cd7298378bb5cc9ddb913a (patch)
treee5e4d80aad90ba1cb1f34b32723c220064753760 /pkg/backend/webapi.go
parent3e0764caa84a21a60f971ec3693429a9981c5921 (diff)
[feat] first simplistic implementation of a rest api
It lacks authentication, and I need to debug a segfault/abort when quitting. But kind of useful for demonstration purposes.
Diffstat (limited to 'pkg/backend/webapi.go')
-rw-r--r--pkg/backend/webapi.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/pkg/backend/webapi.go b/pkg/backend/webapi.go
new file mode 100644
index 0000000..e3918c5
--- /dev/null
+++ b/pkg/backend/webapi.go
@@ -0,0 +1,35 @@
+package backend
+
+import (
+ "fmt"
+ "log"
+ "net/http"
+)
+
+func webOn(w http.ResponseWriter, r *http.Request) {
+ log.Println("Web UI: on")
+ SwitchOn()
+}
+
+func webOff(w http.ResponseWriter, r *http.Request) {
+ log.Println("Web UI: off")
+ SwitchOff()
+}
+
+func webStatus(w http.ResponseWriter, r *http.Request) {
+ log.Println("Web UI: status")
+ fmt.Fprintf(w, ctx.Status.String())
+}
+
+func webQuit(w http.ResponseWriter, r *http.Request) {
+ log.Println("Web UI: quit")
+ Quit()
+}
+
+func enableWebAPI() {
+ http.HandleFunc("/vpn/start", webOn)
+ http.HandleFunc("/vpn/stop", webOff)
+ http.HandleFunc("/vpn/status", webStatus)
+ http.HandleFunc("/vpn/quit", webQuit)
+ http.ListenAndServe(":8080", nil)
+}