1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-28 23:42:51 -05:00

vpn: just try and import all types on errors

This commit is contained in:
bbedward
2025-12-13 10:02:57 -05:00
parent 31b67164c7
commit a1bcb7ea30

View File

@@ -880,29 +880,24 @@ func (b *NetworkManagerBackend) ImportVPN(filePath string, name string) (*VPNImp
} }
func (b *NetworkManagerBackend) importVPNWithNmcli(filePath string, name string) (*VPNImportResult, error) { func (b *NetworkManagerBackend) importVPNWithNmcli(filePath string, name string) (*VPNImportResult, error) {
args := []string{"connection", "import", "type", "openvpn", "file", filePath} vpnTypes := []string{"openvpn", "wireguard", "vpnc", "pptp", "l2tp", "openconnect", "strongswan"}
cmd := exec.Command("nmcli", args...)
output, err := cmd.CombinedOutput() var output []byte
var err error
for _, vpnType := range vpnTypes {
args := []string{"connection", "import", "type", vpnType, "file", filePath}
cmd := exec.Command("nmcli", args...)
output, err = cmd.CombinedOutput()
if err == nil {
break
}
}
if err != nil { if err != nil {
outputStr := string(output) return &VPNImportResult{
if strings.Contains(outputStr, "vpnc") || strings.Contains(outputStr, "unknown connection type") { Success: false,
for _, vpnType := range []string{"vpnc", "pptp", "l2tp", "openconnect", "strongswan", "wireguard"} { Error: fmt.Sprintf("import failed: %s", strings.TrimSpace(string(output))),
args = []string{"connection", "import", "type", vpnType, "file", filePath} }, nil
cmd = exec.Command("nmcli", args...)
output, err = cmd.CombinedOutput()
if err == nil {
break
}
}
}
if err != nil {
return &VPNImportResult{
Success: false,
Error: fmt.Sprintf("import failed: %s", strings.TrimSpace(string(output))),
}, nil
}
} }
outputStr := string(output) outputStr := string(output)