Skip to content

Commit 3f9f260

Browse files
rcmcdonald91vajonamallcontributors[bot]
authored
Devel (#120)
* 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 * " * Working on DNS race * Syntax * Working on DNS * Syntax * MVCd the settings page * Syntax * syntax * More DNS work * More DNS work * Playing with DNS bits * DNS testing * More DNS work * Working on DNS improvements * Resync pakage on post * DNS work * A bit more DNS work * DNS Testing * DNS work * Final DNS work * Some backend rewrites * Cleanups * Some more work * Tweaks * Fixed some variables * Fix variable * Work * Testing some refactoring * Fix some GUI stuff after refactor * Fixes from refactoring * Fix typo * Typo fix * Fix bug * Fix gui bug * This should be count() not max() * Working on bug * apply_list_add can now accept both single string or an array of strings * Support for marking multiple tunnels for resync (needed for moving peers between tunnels) * Fixed flipped params * Convert to [ ] for destructuring arrays 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 7791bb5 commit 3f9f260

File tree

9 files changed

+49
-70
lines changed

9 files changed

+49
-70
lines changed

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

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function wg_toggle_tunnel($tunnel_name) {
4848

4949
$input_errors = array();
5050

51-
if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($tunnel_name)) {
51+
if ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($tunnel_name)) {
5252

5353
$enabled = ($tunnel['enabled'] == 'yes');
5454

@@ -77,13 +77,13 @@ function wg_toggle_tunnel($tunnel_name) {
7777
$changes = true;
7878

7979
// What tunnel would we need to sync to apply these changes?
80-
$tun_to_sync = $tunnel['name'];
80+
$tuns_to_sync[] = $tunnel['name'];
8181

8282
}
8383

8484
}
8585

86-
return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync);
86+
return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync);
8787

8888
}
8989

@@ -101,7 +101,7 @@ function wg_toggle_peer($peer_idx) {
101101

102102
$input_errors = array();
103103

104-
if (list($peer_idx, $peer, $is_new) = wg_peer_get_config($peer_idx)) {
104+
if ([$peer_idx, $peer, $is_new] = wg_peer_get_config($peer_idx)) {
105105

106106
$enabled = ($peer['enabled'] == 'yes');
107107

@@ -126,15 +126,15 @@ function wg_toggle_peer($peer_idx) {
126126
$changes = true;
127127

128128
// What tunnel would we need to sync to apply these changes?
129-
$tun_to_sync = $peer['tun'];
129+
$tuns_to_sync[] = $peer['tun'];
130130

131131
}
132132

133133
}
134134

135135
}
136136

137-
return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync);
137+
return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync);
138138

139139
}
140140

@@ -151,7 +151,7 @@ function wg_delete_peer($peer_idx) {
151151

152152
$input_errors = array();
153153

154-
if (list($peer_idx, $peer, $is_new) = wg_peer_get_config($peer_idx)) {
154+
if ([$peer_idx, $peer, $is_new] = wg_peer_get_config($peer_idx)) {
155155

156156
// Boilerplate...
157157
if (empty($input_errors)) {
@@ -172,15 +172,15 @@ function wg_delete_peer($peer_idx) {
172172
$changes = true;
173173

174174
// What tunnel would we need to sync to apply these changes?
175-
$tun_to_sync = $peer['tun'];
175+
$tuns_to_sync[] = $peer['tun'];
176176

177177
}
178178

179179
}
180180

181181
}
182182

183-
return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync);
183+
return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync);
184184

185185
}
186186

@@ -197,7 +197,7 @@ function wg_delete_tunnel($tunnel_name) {
197197

198198
$input_errors = array();
199199

200-
if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($tunnel_name)) {
200+
if ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($tunnel_name)) {
201201

202202
// We can't delete assigned tunnels
203203
if (is_wg_tunnel_assigned($tunnel['name'])) {
@@ -226,13 +226,13 @@ function wg_delete_tunnel($tunnel_name) {
226226
$changes = true;
227227

228228
// What tunnel would we need to sync to apply these changes?
229-
$tun_to_sync = $tunnel['name'];
229+
$tuns_to_sync[] = $tunnel['name'];
230230

231231
}
232232

233233
}
234234

235-
return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync);
235+
return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync);
236236

237237
}
238238

@@ -241,15 +241,14 @@ function wg_tunnel_unassign_peers($tunnel_name) {
241241

242242
wg_globals();
243243

244+
// Assume there is no peers to unassign...
244245
$changes = false;
245246

246-
foreach (wg_tunnel_get_peers_config($tunnel_name) as $peer_config) {
247-
248-
list($peer_idx, $peer, $is_new) = $peer_config;
247+
foreach (wg_tunnel_get_peers_config($tunnel_name) as [$peer_idx, $peer, $is_new]) {
249248

250249
$wgg['peers'][$peer_idx]['tun'] = 'unassigned';
251250

252-
// We need to sync with backend
251+
// We've got at least one, so we need to resync with the backend...
253252
$changes = true;
254253

255254
}
@@ -512,7 +511,7 @@ function wg_do_peer_post($post) {
512511
// Assume no changes will be made...
513512
$changes = false;
514513

515-
list($peer_idx, $pconfig, $is_new) = wg_peer_get_config($post['index'], true);
514+
[$peer_idx, $pconfig, $is_new] = wg_peer_get_config($post['index'], true);
516515

517516
// We need to save the "old config" to compare against later...
518517
$old_pconfig = $pconfig;
@@ -565,18 +564,15 @@ function wg_do_peer_post($post) {
565564

566565
$changes = ($pconfig != $old_pconfig) || $is_new;
567566

568-
$tun_to_sync = $tun;
569-
570-
// We found it...
571-
break;
567+
$tuns_to_sync[] = $tun;
572568

573569
}
574570

575571
}
576572

577573
}
578574

579-
return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync, 'pconfig' => $pconfig);
575+
return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync, 'pconfig' => $pconfig);
580576

581577
}
582578

@@ -593,7 +589,7 @@ function wg_do_tunnel_post($post) {
593589
// Assume no changes will be made...
594590
$changes = false;
595591

596-
list($tun_idx, $pconfig, $is_new) = wg_tunnel_get_config($post['index'], true);
592+
[$tun_idx, $pconfig, $is_new] = wg_tunnel_get_config($post['index'], true);
597593

598594
// We need to save the "old config" to compare against later...
599595
$old_pconfig = $pconfig;
@@ -632,11 +628,11 @@ function wg_do_tunnel_post($post) {
632628
$changes = ($pconfig != $old_pconfig);
633629

634630
// What tunnel would we need to sync to apply these changes?
635-
$tun_to_sync = $pconfig['name'];
631+
$tuns_to_sync[] = $pconfig['name'];
636632

637633
}
638634

639-
return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync, 'pconfig' => $pconfig);
635+
return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync, 'pconfig' => $pconfig);
640636

641637
}
642638

@@ -651,10 +647,11 @@ function wg_apply_list_get($list, $delete_after_get = true) {
651647

652648
if (file_exists($listpath)) {
653649

654-
$toapplylist = unserialize(file_get_contents($listpath));
650+
$toapplylist = (array) unserialize(file_get_contents($listpath));
655651

656652
}
657653

654+
// Usually just want to delete the apply list after we read it...
658655
if ($delete_after_get) {
659656

660657
unlink_if_exists($listpath);
@@ -667,7 +664,7 @@ function wg_apply_list_get($list, $delete_after_get = true) {
667664

668665
}
669666

670-
function wg_apply_list_add($entry, $list) {
667+
function wg_apply_list_add($list, $entries) {
671668
global $wgg;
672669

673670
$toapplylist = array();
@@ -676,17 +673,11 @@ function wg_apply_list_add($entry, $list) {
676673

677674
$listpath = $wgg['applylist'][$list];
678675

679-
if (file_exists($listpath)) {
680-
681-
$toapplylist = unserialize(file_get_contents($listpath));
682-
683-
}
684-
685-
if (!in_array($entry, $toapplylist)) {
676+
// Get the current list without deleting it...
677+
$toapplylist = wg_apply_list_get($list, false);
686678

687-
$toapplylist[] = $entry;
688-
689-
}
679+
// Need to type cast $entires to array and remove duplicates
680+
$toapplylist = array_unique(array_merge($toapplylist, (array) $entries));
690681

691682
file_put_contents($listpath, serialize($toapplylist));
692683

@@ -802,7 +793,7 @@ function wg_tunnel_sync_by_name($tunnel_name, $json = false) {
802793
$cmds = $errors = $tunnel = array();
803794

804795
// We've got a tunnel that we need to build...
805-
if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($tunnel_name)) {
796+
if ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($tunnel_name)) {
806797

807798
// Determine desired state of the tunnel
808799
$state = (isset($tunnel['enabled']) && $tunnel['enabled'] == 'yes');
@@ -1094,10 +1085,7 @@ function wg_make_tunnel_conf_file($tunnel, $include_endpoint = false) {
10941085
$txt .= "\n";
10951086

10961087
// Process peers section
1097-
foreach (wg_tunnel_get_peers_config($tunnel['name']) as $peer_config) {
1098-
1099-
// Pull out relevant bits
1100-
list($peer_idx, $peer, $is_new) = $peer_config;
1088+
foreach (wg_tunnel_get_peers_config($tunnel['name']) as [$peer_idx, $peer, $is_new]) {
11011089

11021090
if (isset($peer['enabled']) && $peer['enabled'] == 'yes') {
11031091

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ function wg_interface_update_addresses($if_name, &$cmds = null) {
272272
$res = true;
273273

274274
if (wg_is_valid_tunnel($if_name, true)
275-
&& (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($if_name))) {
275+
&& ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($if_name))) {
276276

277277
// Assigned tunnel interfaces are handled by pfSense and should be ignored here
278278
if (!is_wg_tunnel_assigned($tunnel['name'])) {
@@ -993,18 +993,14 @@ function wg_tunnel_get_peers_config($tunnel_name) {
993993

994994
$ret_peers = array();
995995

996-
if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($tunnel_name)) {
997-
998-
if (isset($wgg['peers']) && is_array($wgg['peers'])) {
999-
1000-
// Look through array of peers for matching tunnel name
1001-
foreach ($wgg['peers'] as $peer_idx => $peer) {
996+
if (isset($wgg['peers']) && is_array($wgg['peers'])) {
1002997

1003-
if ($peer['tun'] == $tunnel['name']) {
998+
// Look through array of peers for matching tunnel name
999+
foreach ($wgg['peers'] as $peer_idx => $peer) {
10041000

1005-
$ret_peers[] = wg_peer_get_config($peer_idx, false);
1001+
if ($peer['tun'] == $tunnel_name) {
10061002

1007-
}
1003+
$ret_peers[] = wg_peer_get_config($peer_idx, false);
10081004

10091005
}
10101006

@@ -1049,7 +1045,7 @@ function wg_tunnel_get_peers_config_keys($tunnel_name) {
10491045
// Pull out the public keys
10501046
$keys = array_map(function($s) {
10511047

1052-
list($peer_idx, $peer, $is_new) = $s;
1048+
[$peer_idx, $peer, $is_new] = $s;
10531049

10541050
return $peer['publickey'];
10551051

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ function wg_peer_status_class($peer = null) {
293293
$tunnel_state = true;
294294

295295
// We want to visually disable peers if the tunnel is disabled...
296-
if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($peer['tun'])) {
296+
if ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($peer['tun'])) {
297297

298298
$tunnel_state = ($tunnel['enabled'] == 'yes');
299299

@@ -341,7 +341,7 @@ function wg_generate_tunnel_address_popover_link($tunnel_name) {
341341

342342
$hsc = fn($s) => htmlspecialchars($s);
343343

344-
if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($tunnel_name, false)) {
344+
if ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($tunnel_name, false)) {
345345

346346
$addresses = $tunnel['addresses']['row'];
347347

@@ -435,7 +435,7 @@ function wg_generate_peer_allowedips_popup_link($peer_idx) {
435435

436436
$hsc= fn($s) => htmlspecialchars($s);
437437

438-
if (list($peer_idx, $peer, $is_new) = wg_peer_get_config($peer_idx, false)) {
438+
if ([$peer_idx, $peer, $is_new] = wg_peer_get_config($peer_idx, false)) {
439439

440440
$allowedips = $peer['allowedips']['row'];
441441

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function wg_upgrade_allowedips() {
124124

125125
foreach ($peer['allowedips']['item'] as $a_index => $item) {
126126

127-
list($addr, $addr_mask) = explode('/', $item['addr']);
127+
[$addr, $addr_mask] = explode('/', $item['addr']);
128128

129129
$tmp_addrs['row'][$a_index]['address'] = $addr;
130130

@@ -231,7 +231,7 @@ function wg_upgrade_addresses() {
231231

232232
foreach ($tunnel['addresses']['item'] as $a_index => $item) {
233233

234-
list($addr, $addr_mask) = explode('/', $item['addr']);
234+
[$addr, $addr_mask] = explode('/', $item['addr']);
235235

236236
$tmp_addrs['row'][$a_index]['address'] = $addr;
237237

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,7 @@ function wg_validate_peer_post($pconfig, $posted_peer_idx) {
170170

171171
} elseif (!empty($pconfig['tun'])) {
172172

173-
foreach (wg_tunnel_get_peers_config($pconfig['tun']) as $peer_config) {
174-
175-
// Pull out relevant bits
176-
list($peer_idx, $peer, $is_new) = $peer_config;
173+
foreach (wg_tunnel_get_peers_config($pconfig['tun']) as [$peer_idx, $peer, $is_new]) {
177174

178175
// We don't want duplicate public keys per tunnel, but re-saving is okay...
179176
if (($peer['publickey'] == $pconfig['publickey']) && ($peer_idx != $posted_peer_idx)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
mark_subsystem_dirty($wgg['subsystems']['wg']);
104104

105105
// Add tunnel to the list to apply
106-
wg_apply_list_add($res['tun_to_sync'], 'tunnels');
106+
wg_apply_list_add('tunnels', $res['tuns_to_sync']);
107107

108108
}
109109

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
mark_subsystem_dirty($wgg['subsystems']['wg']);
7575

7676
// Add tunnel to the list to apply
77-
wg_apply_list_add($res['tun_to_sync'], 'tunnels');
77+
wg_apply_list_add('tunnels', $res['tuns_to_sync']);
7878

7979
}
8080

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
mark_subsystem_dirty($wgg['subsystems']['wg']);
114114

115115
// Add tunnel to the list to apply
116-
wg_apply_list_add($res['tun_to_sync'], 'tunnels');
116+
wg_apply_list_add('tunnels', $res['tuns_to_sync']);
117117

118118
}
119119

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
mark_subsystem_dirty($wgg['subsystems']['wg']);
101101

102102
// Add tunnel to the list to apply
103-
wg_apply_list_add($res['tun_to_sync'], 'tunnels');
103+
wg_apply_list_add('tunnels', $res['tuns_to_sync']);
104104

105105
}
106106

@@ -176,7 +176,7 @@
176176
mark_subsystem_dirty($wgg['subsystems']['wg']);
177177

178178
// Add tunnel to the list to apply
179-
wg_apply_list_add($res['tun_to_sync'], 'tunnels');
179+
wg_apply_list_add('tunnels', $res['tuns_to_sync']);
180180

181181
}
182182

@@ -467,9 +467,7 @@
467467
<?php
468468
if (!$is_new):
469469

470-
foreach (wg_tunnel_get_peers_config($pconfig['name']) as $peer_config):
471-
472-
list($peer_idx, $peer, $is_new) = $peer_config;
470+
foreach (wg_tunnel_get_peers_config($pconfig['name']) as [$peer_idx, $peer, $is_new]):
473471
?>
474472
<tr ondblclick="document.location='<?="vpn_wg_peers_edit.php?peer={$peer_idx}"?>';" class="<?=wg_peer_status_class($peer)?>">
475473
<td><?=htmlspecialchars($peer['descr'])?></td>

0 commit comments

Comments
 (0)