1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
pragma Singleton
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import qs.Common
Singleton {
id: root
readonly property bool available: DMSNetworkService.vpnAvailable
property var plugins: []
property var allExtensions: []
property bool importing: false
property string importError: ""
property var editConfig: null
property bool configLoading: false
property bool pluginsLoading: false
signal importComplete(string uuid, string name)
signal configLoaded(var config)
signal configUpdated
signal vpnDeleted(string uuid)
Component.onCompleted: {
if (available) {
fetchPlugins();
}
}
Connections {
target: DMSNetworkService
function onVpnAvailableChanged() {
if (DMSNetworkService.vpnAvailable && plugins.length === 0) {
fetchPlugins();
}
}
}
function fetchPlugins() {
if (!available || pluginsLoading)
return;
pluginsLoading = true;
DMSService.sendRequest("network.vpn.plugins", null, response => {
pluginsLoading = false;
if (response.error) {
console.warn("VPNService: Failed to fetch plugins:", response.error);
return;
}
if (!response.result)
return;
plugins = response.result;
const extSet = new Set();
for (const plugin of response.result) {
for (const ext of plugin.fileExtensions || []) {
extSet.add(ext);
}
}
allExtensions = Array.from(extSet);
});
}
function importVpn(filePath, name = "") {
if (!available || importing)
return;
importing = true;
importError = "";
const params = {
file: filePath
};
if (name)
params.name = name;
DMSService.sendRequest("network.vpn.import", params, response => {
importing = false;
if (response.error) {
importError = response.error;
ToastService.showError(I18n.tr("Failed to import VPN"), response.error);
return;
}
if (!response.result)
return;
if (response.result.success) {
ToastService.showInfo(I18n.tr("VPN imported: %1").arg(response.result.name || ""));
DMSNetworkService.refreshVpnProfiles();
importComplete(response.result.uuid || "", response.result.name || "");
return;
}
importError = response.result.error || "Import failed";
ToastService.showError(I18n.tr("Failed to import VPN"), importError);
});
}
function getConfig(uuidOrName) {
if (!available)
return;
configLoading = true;
editConfig = null;
DMSService.sendRequest("network.vpn.getConfig", {
uuid: uuidOrName
}, response => {
configLoading = false;
if (response.error) {
ToastService.showError(I18n.tr("Failed to load VPN config"), response.error);
return;
}
if (response.result) {
editConfig = response.result;
configLoaded(response.result);
}
});
}
function updateConfig(uuid, updates) {
if (!available)
return;
const params = {
uuid: uuid
};
if (updates.name !== undefined)
params.name = updates.name;
if (updates.autoconnect !== undefined)
params.autoconnect = updates.autoconnect;
if (updates.data !== undefined)
params.data = updates.data;
DMSService.sendRequest("network.vpn.updateConfig", params, response => {
if (response.error) {
ToastService.showError(I18n.tr("Failed to update VPN"), response.error);
return;
}
ToastService.showInfo(I18n.tr("VPN configuration updated"));
DMSNetworkService.refreshVpnProfiles();
getConfig(uuid);
configUpdated();
});
}
function deleteVpn(uuidOrName) {
if (!available)
return;
DMSService.sendRequest("network.vpn.delete", {
uuid: uuidOrName
}, response => {
if (response.error) {
ToastService.showError(I18n.tr("Failed to delete VPN"), response.error);
return;
}
ToastService.showInfo(I18n.tr("VPN deleted"));
DMSNetworkService.refreshVpnProfiles();
vpnDeleted(uuidOrName);
});
}
function getFileFilter() {
if (allExtensions.length === 0) {
return ["*.ovpn", "*.conf"];
}
return allExtensions.map(e => "*" + e);
}
function getExtensionsForPlugin(serviceType) {
const plugin = plugins.find(p => p.serviceType === serviceType);
if (!plugin)
return ["*.conf"];
return (plugin.fileExtensions || [".conf"]).map(e => "*" + e);
}
function getPluginName(serviceType) {
if (!serviceType)
return "VPN";
const plugin = plugins.find(p => p.serviceType === serviceType);
if (plugin)
return plugin.name;
const svc = serviceType.toLowerCase();
if (svc.includes("openvpn"))
return "OpenVPN";
if (svc.includes("wireguard"))
return "WireGuard";
if (svc.includes("openconnect"))
return "OpenConnect";
if (svc.includes("fortissl") || svc.includes("forti"))
return "Fortinet";
if (svc.includes("strongswan"))
return "IPsec (strongSwan)";
if (svc.includes("libreswan"))
return "IPsec (Libreswan)";
if (svc.includes("l2tp"))
return "L2TP/IPsec";
if (svc.includes("pptp"))
return "PPTP";
if (svc.includes("vpnc"))
return "Cisco (vpnc)";
if (svc.includes("sstp"))
return "SSTP";
const parts = serviceType.split('.');
return parts[parts.length - 1] || "VPN";
}
function getVpnTypeFromProfile(profile) {
if (!profile)
return "VPN";
if (profile.type === "wireguard")
return "WireGuard";
return getPluginName(profile.serviceType);
}
}
|