Signed-off-by: Hadi <[email protected]>
This commit is contained in:
Hadi
2026-08-13 00:58:37 +02:00
commit 59b31e5ca3
103 changed files with 8577 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
package network
// VPNConnection is a saved VPN or WireGuard connection profile.
type VPNConnection struct {
Name string
Type string // "vpn" or "wireguard"
Active bool
Device string
}
// ListVPN returns every saved connection whose type is "vpn" or "wireguard".
func ListVPN() ([]VPNConnection, error) {
rows, err := runTerse("NAME,TYPE,ACTIVE,DEVICE", "connection", "show")
if err != nil {
return nil, err
}
vpns := make([]VPNConnection, 0)
for _, row := range rows {
typ := field(row, 1)
if typ != "vpn" && typ != "wireguard" {
continue
}
vpns = append(vpns, VPNConnection{
Name: field(row, 0),
Type: typ,
Active: field(row, 2) == "yes",
Device: field(row, 3),
})
}
return vpns, nil
}
// VPNUp activates a VPN/WireGuard connection by name.
func VPNUp(name string) error {
_, err := run("connection", "up", "id", name)
return err
}
// VPNDown deactivates a VPN/WireGuard connection by name.
func VPNDown(name string) error {
_, err := run("connection", "down", "id", name)
return err
}