From ea225dea0ef38368699c8ff74b5008e7848429cc Mon Sep 17 00:00:00 2001 From: Subho Date: Thu, 21 Sep 2023 13:14:51 +0530 Subject: [PATCH] networking: Add support for OpenVPN --- pkg/networkmanager/dialogs-common.jsx | 4 + pkg/networkmanager/interfaces.js | 26 ++- pkg/networkmanager/ip-settings.jsx | 2 +- pkg/networkmanager/network-interface.jsx | 26 ++- pkg/networkmanager/network-main.jsx | 1 + pkg/networkmanager/openvpn.jsx | 216 +++++++++++++++++++++++ test/run | 2 +- test/verify/check-networkmanager-openvpn | 185 +++++++++++++++++++ 8 files changed, 457 insertions(+), 5 deletions(-) create mode 100644 pkg/networkmanager/openvpn.jsx create mode 100755 test/verify/check-networkmanager-openvpn diff --git a/pkg/networkmanager/dialogs-common.jsx b/pkg/networkmanager/dialogs-common.jsx index 7bb0f4a85068..4743f0ceee3b 100644 --- a/pkg/networkmanager/dialogs-common.jsx +++ b/pkg/networkmanager/dialogs-common.jsx @@ -33,6 +33,7 @@ import { BondDialog, getGhostSettings as getBondGhostSettings } from './bond.jsx import { BridgeDialog, getGhostSettings as getBridgeGhostSettings } from './bridge.jsx'; import { BridgePortDialog } from './bridgeport.jsx'; import { IpSettingsDialog } from './ip-settings.jsx'; +import { OpenVPNDialog, getOpenVPNGhostSettings } from './openvpn.jsx'; import { TeamDialog, getGhostSettings as getTeamGhostSettings } from './team.jsx'; import { TeamPortDialog } from './teamport.jsx'; import { VlanDialog, getGhostSettings as getVlanGhostSettings } from './vlan.jsx'; @@ -203,6 +204,7 @@ export const NetworkAction = ({ buttonText, iface, connectionSettings, type }) = if (type == 'team') settings = getTeamGhostSettings({ newIfaceName }); if (type == 'bridge') settings = getBridgeGhostSettings({ newIfaceName }); if (type == 'wg') settings = getWireGuardGhostSettings({ newIfaceName }); + if (type == 'openvpn') settings = getOpenVPNGhostSettings({ newIfaceName }); } const properties = { connection: con, dev, settings }; @@ -234,6 +236,8 @@ export const NetworkAction = ({ buttonText, iface, connectionSettings, type }) = dlg = ; else if (type == 'wg') dlg = ; + else if (type == 'openvpn') + dlg = ; else if (type == 'mtu') dlg = ; else if (type == 'mac') diff --git a/pkg/networkmanager/interfaces.js b/pkg/networkmanager/interfaces.js index 181362ab8df5..f3e4002d36ad 100644 --- a/pkg/networkmanager/interfaces.js +++ b/pkg/networkmanager/interfaces.js @@ -596,6 +596,13 @@ export function NetworkManagerModel() { }; } + // As NM support many vpn plugins, single out openvpn with the service name o.fd.NM.openvpn + if (settings.vpn && settings.vpn['service-type'].v === "org.freedesktop.NetworkManager.openvpn") { + result.openvpn = { + data: settings.vpn.data.v + }; + } + return result; } @@ -733,8 +740,12 @@ export function NetworkManagerModel() { } }; })); - } else { + } else delete result.wireguard; + + if (settings.vpn) { + set("vpn", "service-type", "s", settings.vpn['service-type']); + set("vpn", "data", "a{ss}", settings.vpn.data); } return result; @@ -1005,7 +1016,8 @@ export function NetworkManagerModel() { props: { Connection: { conv: conv_Object(type_Connection) }, Ip4Config: { conv: conv_Object(type_Ipv4Config) }, - Ip6Config: { conv: conv_Object(type_Ipv6Config) } + Ip6Config: { conv: conv_Object(type_Ipv6Config) }, + Vpn: { def: false } // See below for "Group" }, @@ -1306,6 +1318,16 @@ export function NetworkManagerModel() { type_Settings); }; + self.list_active_connections = function() { + const result = []; + for (const path in objects) { + const obj = objects[path]; + if (priv(obj).type === type_ActiveConnection) + result.push(obj); + } + return result; + }; + /* Initialization. */ diff --git a/pkg/networkmanager/ip-settings.jsx b/pkg/networkmanager/ip-settings.jsx index b7f7b2fe8219..9eedd6a2ee16 100644 --- a/pkg/networkmanager/ip-settings.jsx +++ b/pkg/networkmanager/ip-settings.jsx @@ -174,7 +174,7 @@ export const IpSettingsDialog = ({ topic, connection, dev, settings }) => { aria-label={_("Select method")} onChange={(_, val) => setMethod(val)} value={method}> - {get_ip_method_choices(topic, dev.DeviceType).map(choice => )} + {get_ip_method_choices(topic, dev?.DeviceType).map(choice => )}