Skip to content

Commit 6ca6854

Browse files
rcmcdonald91vajonamallcontributors[bot]
authored
Devel (#111)
* back merge main onto devel (#94) * Update main to latest (#77) * Updated pkg-plist * Makefile fix * Experimenting with wireguard service * Update README.md Co-authored-by: vajonam <152501+vajonam@users.noreply.github.com> Co-authored-by: Manojav Sridhar <manojav@manojav.com> * docs: add theonemcdonald as a contributor (#84) * docs: update README.md [skip ci] * docs: create .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> * Update README.md * Update README.md * Update .all-contributorsrc * Update .all-contributorsrc * Update README.md * Update README.md * Update Makefile * Cleanup * Cleanup * Clean upload of v0.1.2 * Create FUNDING.yml * Add files via upload Co-authored-by: vajonam <152501+vajonam@users.noreply.github.com> Co-authored-by: Manojav Sridhar <manojav@manojav.com> Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> * Clean ups * Syntax * Updated README * Improve input error clarity * Syntax * More syntax * Fix missing address, allowedip fields after tunnel or peer input errors * Reorganized peer post validation * Reorder all input errors to be consistent with UI order * Fix input being flushed on peer validation error * Fix * Test * Fix #98 * Also Fix #98 * v0.1.3 will be reserved for the next PR with Netgate * Further fixes #98 * More fixes for #98... * Removed exit() while working on #98 * Refactor wg_generate_tunnel_address_popover_link for readability * Working on guiconfig cleaning * Should fix #99 * Fix variable #99 * Fix re-saving unchanged tunnel or peer * Fix broke status icon * Back out some boiler plate code * Relocate pf reload trigger on tunnel sync * Test * Fixes some php errors on newer PHP versions * this has to be absolute apparently * Can't redeclare this * wg_clamp_key and wg_is_key_clamped functions * wg_gen_publickey now detects if a privkey was clamped or not * fix wg_gen_keypair to correctly consume new gen_publickey * Bump net/wireguard-kmod to 0.0.20210606 * Fix some logic in new functioons * syntax * Clamp private keys on UI * Don't block unclamped private keys in the UI * Validate pre-shared key * Missed a call that needs tweaking * Slight cleanup * Candidate 0.1.3 build for Netgate PR * Small bump * Tweak subsystem names * Testing * Add some comments to .conf files for the curious * Add some useful debug bits to .conf files * Testing extra services restart on apply * We are now going to restart extra services (currently dpinger and unbound) on config apply (in addition to service restart) * Bump v0.1.2_5 * Enable data-sortable on relevant tables * Missed a table * Peers should become unassigned when their tunnel is deleted * allowedips needs to be an array even when empty * Implement package apply conf on tunnels_edit.php * Tweaks to form post handling * Syntax * Private and PSKs are now hidden by default * Syntax * sortable tables doesn't play nicely with popovers, will revisit in the future * Slight UI tweaks * syntax * Improve sync logic * Test * Testing * Implement conf file downloads from UI * Fixed incorrect tunnel name variable * Bump 0.1.2_6 * Testing * fix plist * Add timestamp to conf download * Typo * " Co-authored-by: vajonam <152501+vajonam@users.noreply.github.com> Co-authored-by: Manojav Sridhar <manojav@manojav.com> Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
1 parent 2a9b08f commit 6ca6854

File tree

5 files changed

+57
-15
lines changed

5 files changed

+57
-15
lines changed

net/pfSense-pkg-WireGuard/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
PORTNAME= pfSense-pkg-WireGuard
2-
PORTVERSION= 0.1.2
3-
PORTREVISION= 6
2+
PORTVERSION= 0.1.3
43
CATEGORIES= net
54
MASTER_SITES= # empty
65
DISTFILES= # empty

net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg.inc

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ function wg_delete_tunnel($tunnel_name) {
228228

229229
// Sync with configuration backend
230230
write_config("[{$wgg['pkg_name']}] Tunnel {$tunnel['name']} deleted.");
231+
232+
// Mark any peers as unassigned
233+
wg_tunnel_unassign_peers($tunnel['name']);
231234

232235
// We've got meaningful changes...
233236
$changes = true;
@@ -243,6 +246,32 @@ function wg_delete_tunnel($tunnel_name) {
243246

244247
}
245248

249+
function wg_tunnel_unassign_peers($tunnel_name) {
250+
global $wgg;
251+
252+
wg_globals();
253+
254+
if (isset($wgg['peers']) && is_array($wgg['peers'])) {
255+
256+
$peers = $wgg['peers'];
257+
258+
foreach ($peers as $peer_idx => $peer) {
259+
260+
if ($peer['tun'] == $tunnel_name) {
261+
262+
$wgg['peers'][$peer_idx]['tun'] = 'unassigned';
263+
264+
}
265+
266+
}
267+
268+
// Sync with configuration backend
269+
write_config("[{$wgg['pkg_name']}] Tunnel {$tunnel_name} peers unassigned.");
270+
271+
}
272+
273+
}
274+
246275
/*
247276
* This transforms a raw peer post consisting of repeatables
248277
*/
@@ -1018,11 +1047,17 @@ function wg_download_tunnel($tunnel_name, $failure_redirect) {
10181047
// Make sure conf files are current
10191048
wg_resync();
10201049

1050+
$now = new DateTimeImmutable();
1051+
1052+
$stamp = $now->format('YmdHis');
1053+
10211054
$conf_path = "{$wgg['conf_path']}/{$tunnel_name}.conf";
10221055

1056+
$name = "tunnel-{$tunnel_name}-{$stamp}.conf";
1057+
10231058
if (file_exists($conf_path)) {
10241059

1025-
send_user_download('file', $conf_path);
1060+
send_user_download('file', $conf_path, $name);
10261061

10271062
}
10281063

net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_api.inc

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,15 @@ function wg_status_json($pretty = false) {
130130
function wg_get_peer_id($public_key, $tunnel_name) {
131131
global $wgg;
132132

133-
foreach ($wgg['peers'] as $peer_id => $peer){
133+
if (isset($wgg['peers']) && is_array($wgg['peers'])) {
134134

135-
if ($public_key == $peer['publickey'] && $tunnel_name = $peer['tun']) {
135+
foreach ($wgg['peers'] as $peer_id => $peer){
136136

137-
return $peer_id;
137+
if ($public_key == $peer['publickey'] && $tunnel_name = $peer['tun']) {
138+
139+
return $peer_id;
140+
141+
}
138142

139143
}
140144

@@ -732,15 +736,19 @@ function wg_get_tunnel_peers($tunnel_name) {
732736

733737
if (isset($wgg['tunnels'][$tun_idx])) {
734738

735-
// Look through array of peers for matching tunnel name
736-
foreach ($wgg['peers'] as $peer_idx => $peer) {
739+
if (isset($wgg['peers']) && is_array($wgg['peers'])) {
737740

738-
if ($peer['tun'] == $tunnel_name) {
741+
// Look through array of peers for matching tunnel name
742+
foreach ($wgg['peers'] as $peer_idx => $peer) {
739743

740-
// We need the array index for future manipulations
741-
$peer['index'] = $peer_idx;
744+
if ($peer['tun'] == $tunnel_name) {
742745

743-
$a_ret[] = $peer;
746+
// We need the array index for future manipulations
747+
$peer['index'] = $peer_idx;
748+
749+
$a_ret[] = $peer;
750+
751+
}
744752

745753
}
746754

net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_tunnels.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
default:
100100

101101
// Shouldn't be here, so bail out.
102-
header("Location: /wg/vpn_wg_tunnels.php");
102+
header('Location: /wg/vpn_wg_tunnels.php');
103103

104104
break;
105105

@@ -198,7 +198,7 @@
198198
<a class="fa fa-pencil" title="<?=gettext('Edit Tunnel')?>" href="<?="vpn_wg_tunnels_edit.php?tun={$tunnel['name']}"?>"></a>
199199
<a class="fa fa-download" title="<?=gettext('Download Configuration')?>" href="<?="?act=download&tun={$tunnel['name']}"?>" usepost></a>
200200
<?=wg_generate_toggle_icon_link($tunnel, 'Click to toggle enabled/disabled status', "?act=toggle&tun={$tunnel['name']}")?>
201-
<a class="fa fa-trash text-danger" title="<?=gettext('Delete Yunnel')?>" href="<?="?act=delete&tun={$tunnel['name']}"?>" usepost></a>
201+
<a class="fa fa-trash text-danger" title="<?=gettext('Delete Tunnel')?>" href="<?="?act=delete&tun={$tunnel['name']}"?>" usepost></a>
202202
</td>
203203
</tr>
204204

net/pfSense-pkg-WireGuard/pkg-plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ pkg/wireguard/wg_install.inc
88
pkg/wireguard/wg_service.inc
99
pkg/wireguard/wg_validate.inc
1010
www/shortcuts/pkg_wireguard.inc
11+
www/wg/js/WireGuardHelpers.js
1112
www/wg/status_wireguard.php
1213
www/wg/vpn_wg_peers.php
1314
www/wg/vpn_wg_peers_edit.php
1415
www/wg/vpn_wg_settings.php
1516
www/wg/vpn_wg_tunnels.php
1617
www/wg/vpn_wg_tunnels_edit.php
17-
www/wg/js/WireGuardHelpers.js
1818
/etc/inc/priv/wireguard.priv.inc
1919
%%DATADIR%%/info.xml
2020
@dir /etc/inc/priv

0 commit comments

Comments
 (0)