mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
vpn: aggregate all import errors
- we are dumb about importing by just trying to import everythting - that caused errors to not be represented correctly - just aggregate them all and present them in toast details - Better would be to detect the type of file being imported, but this is better than nothing
This commit is contained in:
@@ -3,6 +3,7 @@ package network
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -925,25 +926,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) {
|
||||||
vpnTypes := []string{"openvpn", "wireguard", "vpnc", "pptp", "l2tp", "openconnect", "strongswan"}
|
vpnTypes := []string{"openvpn", "wireguard", "vpnc", "pptp", "l2tp", "openconnect", "strongswan"}
|
||||||
|
|
||||||
var output []byte
|
var allErrors []error
|
||||||
var err error
|
var outputStr string
|
||||||
for _, vpnType := range vpnTypes {
|
for _, vpnType := range vpnTypes {
|
||||||
args := []string{"connection", "import", "type", vpnType, "file", filePath}
|
cmd := exec.Command("nmcli", "connection", "import", "type", vpnType, "file", filePath)
|
||||||
cmd := exec.Command("nmcli", args...)
|
output, err := cmd.CombinedOutput()
|
||||||
output, err = cmd.CombinedOutput()
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
outputStr = string(output)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
allErrors = append(allErrors, fmt.Errorf("%s: %s", vpnType, strings.TrimSpace(string(output))))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if len(allErrors) == len(vpnTypes) {
|
||||||
return &VPNImportResult{
|
return &VPNImportResult{
|
||||||
Success: false,
|
Success: false,
|
||||||
Error: fmt.Sprintf("import failed: %s", strings.TrimSpace(string(output))),
|
Error: errors.Join(allErrors...).Error(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
outputStr := string(output)
|
|
||||||
var connUUID, connName string
|
var connUUID, connName string
|
||||||
|
|
||||||
lines := strings.Split(outputStr, "\n")
|
lines := strings.Split(outputStr, "\n")
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
importError = response.result.error || "Import failed";
|
importError = response.result.error || "Import failed";
|
||||||
ToastService.showError(importError);
|
ToastService.showError(I18n.tr("Failed to import VPN"), importError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user