mirror of
https://github.com/luscis/openlan.git
synced 2025-09-27 04:46:02 +08:00
55 lines
1.2 KiB
Go
Executable File
55 lines
1.2 KiB
Go
Executable File
package v5
|
|
|
|
import (
|
|
"github.com/luscis/openlan/cmd/api"
|
|
"github.com/luscis/openlan/pkg/schema"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
type VPNClient struct {
|
|
Cmd
|
|
}
|
|
|
|
func (u VPNClient) Url(prefix, name string) string {
|
|
if name == "" {
|
|
return prefix + "/api/vpn/client"
|
|
} else {
|
|
return prefix + "/api/vpn/client/" + name
|
|
}
|
|
}
|
|
|
|
func (u VPNClient) Tmpl() string {
|
|
return `# total {{ len . }}
|
|
{{ps -8 "alive"}} {{ps -16 "address"}} {{ ps -13 "device" }} {{ps -15 "name"}} {{ps -22 "remote"}} {{ ps -6 "state"}}
|
|
{{- range . }}
|
|
{{pt .AliveTime | ps -8}} {{ps -16 .Address}} {{ ps -13 .Device }} {{ps -15 .Name}} {{ps -22 .Remote}} {{ ps -6 .State}}
|
|
{{- end }}
|
|
`
|
|
}
|
|
|
|
func (u VPNClient) List(c *cli.Context) error {
|
|
url := u.Url(c.String("url"), c.String("network"))
|
|
clt := u.NewHttp(c.String("token"))
|
|
var items []schema.VPNClient
|
|
if err := clt.GetJSON(url, &items); err != nil {
|
|
return err
|
|
}
|
|
return u.Out(items, c.String("format"), u.Tmpl())
|
|
}
|
|
|
|
func (u VPNClient) Commands(app *api.App) {
|
|
app.Command(&cli.Command{
|
|
Name: "client",
|
|
Aliases: []string{"cl"},
|
|
Usage: "Connected client by OpenVPN",
|
|
Subcommands: []*cli.Command{
|
|
{
|
|
Name: "list",
|
|
Usage: "Display all clients",
|
|
Aliases: []string{"ls"},
|
|
Action: u.List,
|
|
},
|
|
},
|
|
})
|
|
}
|