summaryrefslogtreecommitdiff
path: root/pkg/backend/webapi.go
blob: e3918c50f6e625e7a62a9434a8fb6eeecb6b3fc0 (plain)
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
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)
}