summaryrefslogtreecommitdiff
path: root/helper/helper.go
diff options
context:
space:
mode:
Diffstat (limited to 'helper/helper.go')
-rw-r--r--helper/helper.go30
1 files changed, 27 insertions, 3 deletions
diff --git a/helper/helper.go b/helper/helper.go
index 04eafc7..4671868 100644
--- a/helper/helper.go
+++ b/helper/helper.go
@@ -74,11 +74,10 @@ func daemonize() {
func serveHTTP() {
openvpn := openvpnT{nil}
- firewall := firewallT{}
http.HandleFunc("/openvpn/start", openvpn.start)
http.HandleFunc("/openvpn/stop", openvpn.stop)
- http.HandleFunc("/firewall/start", firewall.start)
- http.HandleFunc("/firewall/stop", firewall.stop)
+ http.HandleFunc("/firewall/start", firewallStartHandler)
+ http.HandleFunc("/firewall/stop", firewallStopHandler)
log.Fatal(http.ListenAndServe(bindAddr, nil))
}
@@ -139,6 +138,31 @@ func (openvpn *openvpnT) kill() error {
return nil
}
+func firewallStartHandler(w http.ResponseWriter, r *http.Request) {
+ gateways, err := getArgs(r)
+ if err != nil {
+ log.Printf("An error has occurred processing gateways: %v", err)
+ w.Write([]byte(err.Error()))
+ return
+ }
+
+ err = firewallStart(gateways)
+ if err != nil {
+ log.Printf("Error starting firewall: %v", err)
+ w.Write([]byte(err.Error()))
+ }
+ log.Println("Start firewall: firewall started")
+}
+
+func firewallStopHandler(w http.ResponseWriter, r *http.Request) {
+ err := firewallStop()
+ if err != nil {
+ log.Printf("Error stoping firewall: %v", err)
+ w.Write([]byte(err.Error()))
+ }
+ log.Println("Stop firewall: firewall stopped")
+}
+
func getArgs(r *http.Request) ([]string, error) {
args := []string{}
decoder := json.NewDecoder(r.Body)