clone from danieldin95

This commit is contained in:
sicheng
2022-07-29 23:38:54 +08:00
commit ac4f79bbf4
1931 changed files with 568263 additions and 0 deletions

44
pkg/api/openvpn.go Executable file
View 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)
}