Skip to content

Commit 5b2762f

Browse files
committed
Adding WireGuard VPN support
1 parent 45c07f9 commit 5b2762f

File tree

5 files changed

+125
-9
lines changed

5 files changed

+125
-9
lines changed

main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ ipcMain.handle("app:on-key-add", (event, name, private, public) => {
6363
io.addKey(name, private, public);
6464
});
6565
//
66-
ipcMain.handle("app:on-vpn-add", (event, vpns, username, password, input1, input2, path, type) => {
67-
io.addVpn(vpns, username, password, input1, input2, path, type);
66+
ipcMain.handle("app:on-vpn-add", (event, vpns, input1, input2, input3, input4, input5, input6, path, type) => {
67+
io.addVpn(vpns, input1, input2, input3, input4, input5, input6, path, type);
6868
});
6969
//
7070
ipcMain.handle("app:on-ssh-add", (event, username, password, ip, key, path, type) => {

main/io.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,23 @@ exports.decryptFile = (keyFilePath, isBinary, passphrase, fileEncrypted) => {
101101
})
102102
};
103103

104-
exports.addVpn = (vpns, username, password, input1, input2, path, type) => {
104+
exports.addVpn = (vpns, input1, input2, input3, input4, input5, input6, path, type) => {
105105
let lastEncryptedMessage;
106106
var zipName = "config.zip"
107107
var zipLoc = tsDir
108108
var zipWrite = (zipLoc + "\\" + zipName);
109109
var nl = "\n"
110110
if (vpns == "ovpn") {
111111
var block = "[ovpn]"
112-
var com = username+block+password+block+input1+nl+input2
112+
var com = input1+block+input2+block+input3+nl+input4
113113
}
114114
if (vpns == "ipsec") {
115115
var block = "[ipsec]"
116-
var com = username+block+password+block+input1+block+input2
116+
var com = input1+block+input2+block+input3+block+input4
117+
}
118+
if (vpns == "wg") {
119+
var block = "[wg]"
120+
var com = input1+block+input2+block+input3+block+input4+block+input5+block+input6
117121
}
118122
var zip = new AdmZip();
119123
zip.addFile("config.txt", Buffer.from(com, "utf8"), "");

preload.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ contextBridge.exposeInMainWorld("api", {
2828
writeKey: (name, private, public) => {
2929
return ipcRenderer.invoke("app:on-key-add", name, private, public);
3030
},
31-
writeVpn: (vpns, username, password, input1, input2, path, type) => {
32-
return ipcRenderer.invoke("app:on-vpn-add", vpns, username, password, input1, input2, path, type);
31+
writeVpn: (vpns, input1, input2, input3, input4, input5, input6, path, type) => {
32+
return ipcRenderer.invoke("app:on-vpn-add", vpns, input1, input2, input3, input4, input5, input6, path, type);
3333
},
3434
writeSsh: (username, password, ip, key, path, type) => {
3535
return ipcRenderer.invoke("app:on-ssh-add", username, password, ip, key, path, type);

renderer/js/vpn.js

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,34 @@ $("#processing").removeAttr("style").hide();
1010

1111
$("#OpenVPN").removeAttr("style").hide();
1212
$("#IPSec").removeAttr("style").hide();
13+
$("#WireGuard").removeAttr("style").hide();
1314
$("#btn-gen-zip").removeAttr("style").hide();
1415

1516

1617
$(document).ready(function(){
1718
$('#vpnSelect').on('change', function() {
1819
if ( this.value == 'ovpn') {
1920
$("#IPSec").removeAttr("style").hide();
21+
$("#WireGuard").removeAttr("style").hide();
2022
$("#OpenVPN").show();
2123
$("#btn-gen-zip").show();
2224
console.log("OpenVPN selected")
2325
} else if( this.value == 'ipsec') {
2426
$("#OpenVPN").removeAttr("style").hide();
27+
$("#WireGuard").removeAttr("style").hide();
2528
$("#IPSec").show();
2629
$("#btn-gen-zip").show();
2730
console.log("IPSec selected")
31+
} else if( this.value == 'wg') {
32+
$("#OpenVPN").removeAttr("style").hide();
33+
$("#IPSec").removeAttr("style").hide();
34+
$("#WireGuard").show();
35+
$("#btn-gen-zip").show();
36+
console.log("WireGuard selected")
2837
} else {
2938
$("#OpenVPN").removeAttr("style").hide();
3039
$("#IPSec").removeAttr("style").hide();
40+
$("#WireGuard").removeAttr("style").hide();
3141
$("#btn-gen-zip").removeAttr("style").hide();
3242
console.log("Nothing selected")
3343
}
@@ -147,6 +157,10 @@ $("#btn-gen-zip").on("click", function (e) {
147157
encryptWithKey2(k);
148158
const element = document.createElement("a");
149159
element.focus();
160+
} else if ($("#vpnSelect").val() == "wg") {
161+
encryptWithKey4(k);
162+
const element = document.createElement("a");
163+
element.focus();
150164
} else {
151165
alert("VPN Type not found");
152166
return;
@@ -162,6 +176,10 @@ $("#btn-gen-zip").on("click", function (e) {
162176
encryptWithKey2(keyFile);
163177
const element = document.createElement("a");
164178
element.focus();
179+
} else if ($("#vpnSelect").val() == "wg") {
180+
encryptWithKey4(keyFile);
181+
const element = document.createElement("a");
182+
element.focus();
165183
} else {
166184
alert("VPN Type not found");
167185
return;
@@ -201,6 +219,42 @@ $("#btn-save-enc").on("click", function (e) {
201219
element.click();
202220
});
203221

222+
function encryptWithKey4(keyFile) {
223+
let vpns = $("#vpnSelect").val();
224+
console.log(vpns)
225+
let option1 = $("#wg-pubkey").val();
226+
//console.log(option1)
227+
let option2 = $("#wg-pvtkey").val();
228+
//console.log(option2)
229+
let option3 = $("#wg-ep-ip").val();
230+
//console.log(option3)
231+
let option4 = $("#wg-ep-p").val();
232+
//console.log(option4)
233+
let option5 = $("#wg-pskey").val();
234+
//console.log(option5)
235+
let option6 = $("#wg-l-ip").val();
236+
//console.log(option6)
237+
var validating = false;
238+
239+
if (!keyFile) {
240+
alert("Please select a public key from list or import from file");
241+
return;
242+
}
243+
console.log(keyFile);
244+
245+
const keyType = getKeyType(keyFile);
246+
if (keyType < 0) {
247+
alert(
248+
"Unknown key file format. Please use *.key for binary or *.asc for armored ASCII"
249+
);
250+
return;
251+
}
252+
253+
window.api
254+
.writeVpn(vpns, option1, option2, option3, option4, option5, option6, keyFile.path, keyType == 0)
255+
.catch(alert);
256+
}
257+
204258
function encryptWithKey3(keyFile) {
205259
let vpns = $("#vpnSelect").val();
206260
console.log(vpns)
@@ -212,6 +266,10 @@ function encryptWithKey3(keyFile) {
212266
//console.log(option3)
213267
let option4 = $("#ovpn-config").val();
214268
//console.log(option4)
269+
let option5 = "";
270+
//console.log(option5)
271+
let option6 = "";
272+
//console.log(option6)
215273
var validating = false;
216274

217275
if (!keyFile) {
@@ -240,7 +298,7 @@ function encryptWithKey3(keyFile) {
240298
}
241299

242300
window.api
243-
.writeVpn(vpns, option1, option2, option3, option4, keyFile.path, keyType == 0)
301+
.writeVpn(vpns, option1, option2, option3, option4, option5, option6, keyFile.path, keyType == 0)
244302
.catch(alert);
245303
}
246304

@@ -255,6 +313,10 @@ function encryptWithKey2(keyFile) {
255313
//console.log(option3)
256314
let option4 = $("#ipsec-ip").val();
257315
//console.log(option4)
316+
let option5 = "";
317+
//console.log(option5)
318+
let option6 = "";
319+
//console.log(option6)
258320
var validating = false;
259321

260322
if (!keyFile) {
@@ -313,7 +375,7 @@ function encryptWithKey2(keyFile) {
313375
}
314376

315377
window.api
316-
.writeVpn(vpns, option1, option2, option3, option4, keyFile.path, keyType == 0)
378+
.writeVpn(vpns, option1, option2, option3, option4, option5, option6, keyFile.path, keyType == 0)
317379
.catch(alert);
318380
}
319381

renderer/views/vpn.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ <h4>VPN Config Encryption:</h4>
3131
<option selected>VPN Type...</option>
3232
<option value="ovpn">OpenVPN</option>
3333
<option value="ipsec">IPSec</option>
34+
<option value="wg">WireGuard</option>
3435
</select>
3536
<hr>
3637
<div id="OpenVPN">
@@ -111,6 +112,55 @@ <h4>VPN Config Encryption:</h4>
111112
<button class="btn btn-primary btn-lg" id="btn-gen-zip">Generate & Save Config</button>
112113
</div> -->
113114
</div>
115+
<div id="WireGuard">
116+
<label for="wg-pubkey" class="form-label">Please enter your WireGuard Public Key: </label>
117+
<input class="form-control"
118+
type="text"
119+
name="full-name"
120+
id="wg-pubkey"
121+
placeholder="WireGuard Public Key"
122+
autofocus
123+
/><br />
124+
<label for="wg-pvtkey" class="form-label">Please enter your WireGuard Private Key: </label>
125+
<input class="form-control"
126+
type="text"
127+
name="full-name"
128+
id="wg-pvtkey"
129+
placeholder="WireGuard Private Key"
130+
autofocus
131+
/><br />
132+
<label for="wg-ep-ip" class="form-label">Please enter your WireGuard Endpoint IP: </label>
133+
<input class="form-control"
134+
type="text"
135+
name="full-name"
136+
id="wg-ep-ip"
137+
placeholder="WireGuard Endpoint IP"
138+
/><br />
139+
<label for="wg-ep-p" class="form-label">Please enter your WireGuard Endpoint Port: </label>
140+
<input class="form-control"
141+
type="text"
142+
name="full-name"
143+
id="wg-ep-p"
144+
placeholder="WireGuard Endpoint Port"
145+
/><br />
146+
<label for="wg-pskey" class="form-label">Please enter your WireGuard Pre Shared Key: </label>
147+
<input class="form-control"
148+
type="text"
149+
name="full-name"
150+
id="wg-pskey"
151+
placeholder="WireGuard Pre Shared Key"
152+
/><br />
153+
<label for="wg-l-ip" class="form-label">Please enter your WireGuard Local IP: </label>
154+
<input class="form-control"
155+
type="text"
156+
name="full-name"
157+
id="wg-l-ip"
158+
placeholder="WireGuard Local IP"
159+
/><br /><br />
160+
<!-- <div>
161+
<button class="btn btn-primary btn-lg" id="btn-gen-zip">Generate & Save Config</button>
162+
</div> -->
163+
</div>
114164
</div>
115165
<div class="col-lg-12 align-self-center text-center">
116166
<button class="btn btn-primary btn-lg" id="btn-gen-zip">Generate & Save Config</button>

0 commit comments

Comments
 (0)