mirror of
https://github.com/luscis/openlan.git
synced 2025-10-07 01:22:51 +08:00
clone from danieldin95
This commit is contained in:
44
pkg/api/openvpn.go
Executable file
44
pkg/api/openvpn.go
Executable file
@@ -0,0 +1,44 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/luscis/openlan/pkg/cache"
|
||||
"github.com/luscis/openlan/pkg/schema"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type VPNClient struct {
|
||||
}
|
||||
|
||||
func (h VPNClient) Router(router *mux.Router) {
|
||||
router.HandleFunc("/api/vpn/client", h.List).Methods("GET")
|
||||
router.HandleFunc("/api/vpn/client/{id}", h.List).Methods("GET")
|
||||
}
|
||||
|
||||
func (h VPNClient) List(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
name := vars["id"]
|
||||
|
||||
clients := make([]schema.VPNClient, 0, 1024)
|
||||
if name == "" {
|
||||
for n := range cache.Network.List() {
|
||||
if n == nil {
|
||||
break
|
||||
}
|
||||
for client := range cache.VPNClient.List(n.Name) {
|
||||
if client == nil {
|
||||
break
|
||||
}
|
||||
clients = append(clients, *client)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for client := range cache.VPNClient.List(name) {
|
||||
if client == nil {
|
||||
break
|
||||
}
|
||||
clients = append(clients, *client)
|
||||
}
|
||||
}
|
||||
ResponseJson(w, clients)
|
||||
}
|
Reference in New Issue
Block a user