diff --git a/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg.inc b/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg.inc index cd459bdb..b27912c3 100644 --- a/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg.inc +++ b/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg.inc @@ -48,7 +48,7 @@ function wg_toggle_tunnel($tunnel_name) { $input_errors = array(); - if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($tunnel_name)) { + if ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($tunnel_name)) { $enabled = ($tunnel['enabled'] == 'yes'); @@ -77,13 +77,13 @@ function wg_toggle_tunnel($tunnel_name) { $changes = true; // What tunnel would we need to sync to apply these changes? - $tun_to_sync = $tunnel['name']; + $tuns_to_sync[] = $tunnel['name']; } } - return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync); + return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync); } @@ -101,7 +101,7 @@ function wg_toggle_peer($peer_idx) { $input_errors = array(); - if (list($peer_idx, $peer, $is_new) = wg_peer_get_config($peer_idx)) { + if ([$peer_idx, $peer, $is_new] = wg_peer_get_config($peer_idx)) { $enabled = ($peer['enabled'] == 'yes'); @@ -126,7 +126,7 @@ function wg_toggle_peer($peer_idx) { $changes = true; // What tunnel would we need to sync to apply these changes? - $tun_to_sync = $peer['tun']; + $tuns_to_sync[] = $peer['tun']; } @@ -134,7 +134,7 @@ function wg_toggle_peer($peer_idx) { } - return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync); + return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync); } @@ -151,7 +151,7 @@ function wg_delete_peer($peer_idx) { $input_errors = array(); - if (list($peer_idx, $peer, $is_new) = wg_peer_get_config($peer_idx)) { + if ([$peer_idx, $peer, $is_new] = wg_peer_get_config($peer_idx)) { // Boilerplate... if (empty($input_errors)) { @@ -172,7 +172,7 @@ function wg_delete_peer($peer_idx) { $changes = true; // What tunnel would we need to sync to apply these changes? - $tun_to_sync = $peer['tun']; + $tuns_to_sync[] = $peer['tun']; } @@ -180,7 +180,7 @@ function wg_delete_peer($peer_idx) { } - return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync); + return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync); } @@ -197,7 +197,7 @@ function wg_delete_tunnel($tunnel_name) { $input_errors = array(); - if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($tunnel_name)) { + if ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($tunnel_name)) { // We can't delete assigned tunnels if (is_wg_tunnel_assigned($tunnel['name'])) { @@ -226,13 +226,13 @@ function wg_delete_tunnel($tunnel_name) { $changes = true; // What tunnel would we need to sync to apply these changes? - $tun_to_sync = $tunnel['name']; + $tuns_to_sync[] = $tunnel['name']; } } - return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync); + return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync); } @@ -241,15 +241,14 @@ function wg_tunnel_unassign_peers($tunnel_name) { wg_globals(); + // Assume there is no peers to unassign... $changes = false; - foreach (wg_tunnel_get_peers_config($tunnel_name) as $peer_config) { - - list($peer_idx, $peer, $is_new) = $peer_config; + foreach (wg_tunnel_get_peers_config($tunnel_name) as [$peer_idx, $peer, $is_new]) { $wgg['peers'][$peer_idx]['tun'] = 'unassigned'; - // We need to sync with backend + // We've got at least one, so we need to resync with the backend... $changes = true; } @@ -512,7 +511,7 @@ function wg_do_peer_post($post) { // Assume no changes will be made... $changes = false; - list($peer_idx, $pconfig, $is_new) = wg_peer_get_config($post['index'], true); + [$peer_idx, $pconfig, $is_new] = wg_peer_get_config($post['index'], true); // We need to save the "old config" to compare against later... $old_pconfig = $pconfig; @@ -565,10 +564,7 @@ function wg_do_peer_post($post) { $changes = ($pconfig != $old_pconfig) || $is_new; - $tun_to_sync = $tun; - - // We found it... - break; + $tuns_to_sync[] = $tun; } @@ -576,7 +572,7 @@ function wg_do_peer_post($post) { } - return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync, 'pconfig' => $pconfig); + return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync, 'pconfig' => $pconfig); } @@ -593,7 +589,7 @@ function wg_do_tunnel_post($post) { // Assume no changes will be made... $changes = false; - list($tun_idx, $pconfig, $is_new) = wg_tunnel_get_config($post['index'], true); + [$tun_idx, $pconfig, $is_new] = wg_tunnel_get_config($post['index'], true); // We need to save the "old config" to compare against later... $old_pconfig = $pconfig; @@ -632,11 +628,11 @@ function wg_do_tunnel_post($post) { $changes = ($pconfig != $old_pconfig); // What tunnel would we need to sync to apply these changes? - $tun_to_sync = $pconfig['name']; + $tuns_to_sync[] = $pconfig['name']; } - return array('input_errors' => $input_errors, 'changes' => $changes, 'tun_to_sync' => $tun_to_sync, 'pconfig' => $pconfig); + return array('input_errors' => $input_errors, 'changes' => $changes, 'tuns_to_sync' => $tuns_to_sync, 'pconfig' => $pconfig); } @@ -651,10 +647,11 @@ function wg_apply_list_get($list, $delete_after_get = true) { if (file_exists($listpath)) { - $toapplylist = unserialize(file_get_contents($listpath)); + $toapplylist = (array) unserialize(file_get_contents($listpath)); } + // Usually just want to delete the apply list after we read it... if ($delete_after_get) { unlink_if_exists($listpath); @@ -667,7 +664,7 @@ function wg_apply_list_get($list, $delete_after_get = true) { } -function wg_apply_list_add($entry, $list) { +function wg_apply_list_add($list, $entries) { global $wgg; $toapplylist = array(); @@ -676,17 +673,11 @@ function wg_apply_list_add($entry, $list) { $listpath = $wgg['applylist'][$list]; - if (file_exists($listpath)) { - - $toapplylist = unserialize(file_get_contents($listpath)); - - } - - if (!in_array($entry, $toapplylist)) { + // Get the current list without deleting it... + $toapplylist = wg_apply_list_get($list, false); - $toapplylist[] = $entry; - - } + // Need to type cast $entires to array and remove duplicates + $toapplylist = array_unique(array_merge($toapplylist, (array) $entries)); file_put_contents($listpath, serialize($toapplylist)); @@ -802,7 +793,7 @@ function wg_tunnel_sync_by_name($tunnel_name, $json = false) { $cmds = $errors = $tunnel = array(); // We've got a tunnel that we need to build... - if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($tunnel_name)) { + if ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($tunnel_name)) { // Determine desired state of the tunnel $state = (isset($tunnel['enabled']) && $tunnel['enabled'] == 'yes'); @@ -1094,10 +1085,7 @@ function wg_make_tunnel_conf_file($tunnel, $include_endpoint = false) { $txt .= "\n"; // Process peers section - foreach (wg_tunnel_get_peers_config($tunnel['name']) as $peer_config) { - - // Pull out relevant bits - list($peer_idx, $peer, $is_new) = $peer_config; + foreach (wg_tunnel_get_peers_config($tunnel['name']) as [$peer_idx, $peer, $is_new]) { if (isset($peer['enabled']) && $peer['enabled'] == 'yes') { diff --git a/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_api.inc b/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_api.inc index 4f79c295..5866b3d5 100644 --- a/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_api.inc +++ b/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_api.inc @@ -272,7 +272,7 @@ function wg_interface_update_addresses($if_name, &$cmds = null) { $res = true; if (wg_is_valid_tunnel($if_name, true) - && (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($if_name))) { + && ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($if_name))) { // Assigned tunnel interfaces are handled by pfSense and should be ignored here if (!is_wg_tunnel_assigned($tunnel['name'])) { @@ -993,18 +993,14 @@ function wg_tunnel_get_peers_config($tunnel_name) { $ret_peers = array(); - if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($tunnel_name)) { - - if (isset($wgg['peers']) && is_array($wgg['peers'])) { - - // Look through array of peers for matching tunnel name - foreach ($wgg['peers'] as $peer_idx => $peer) { + if (isset($wgg['peers']) && is_array($wgg['peers'])) { - if ($peer['tun'] == $tunnel['name']) { + // Look through array of peers for matching tunnel name + foreach ($wgg['peers'] as $peer_idx => $peer) { - $ret_peers[] = wg_peer_get_config($peer_idx, false); + if ($peer['tun'] == $tunnel_name) { - } + $ret_peers[] = wg_peer_get_config($peer_idx, false); } @@ -1049,7 +1045,7 @@ function wg_tunnel_get_peers_config_keys($tunnel_name) { // Pull out the public keys $keys = array_map(function($s) { - list($peer_idx, $peer, $is_new) = $s; + [$peer_idx, $peer, $is_new] = $s; return $peer['publickey']; diff --git a/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_guiconfig.inc b/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_guiconfig.inc index 08b71c3a..12d5d884 100644 --- a/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_guiconfig.inc +++ b/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_guiconfig.inc @@ -293,7 +293,7 @@ function wg_peer_status_class($peer = null) { $tunnel_state = true; // We want to visually disable peers if the tunnel is disabled... - if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($peer['tun'])) { + if ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($peer['tun'])) { $tunnel_state = ($tunnel['enabled'] == 'yes'); @@ -341,7 +341,7 @@ function wg_generate_tunnel_address_popover_link($tunnel_name) { $hsc = fn($s) => htmlspecialchars($s); - if (list($tun_idx, $tunnel, $is_new) = wg_tunnel_get_config_by_name($tunnel_name, false)) { + if ([$tun_idx, $tunnel, $is_new] = wg_tunnel_get_config_by_name($tunnel_name, false)) { $addresses = $tunnel['addresses']['row']; @@ -435,7 +435,7 @@ function wg_generate_peer_allowedips_popup_link($peer_idx) { $hsc= fn($s) => htmlspecialchars($s); - if (list($peer_idx, $peer, $is_new) = wg_peer_get_config($peer_idx, false)) { + if ([$peer_idx, $peer, $is_new] = wg_peer_get_config($peer_idx, false)) { $allowedips = $peer['allowedips']['row']; diff --git a/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_install.inc b/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_install.inc index 46fc1662..5568680e 100644 --- a/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_install.inc +++ b/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_install.inc @@ -124,7 +124,7 @@ function wg_upgrade_allowedips() { foreach ($peer['allowedips']['item'] as $a_index => $item) { - list($addr, $addr_mask) = explode('/', $item['addr']); + [$addr, $addr_mask] = explode('/', $item['addr']); $tmp_addrs['row'][$a_index]['address'] = $addr; @@ -231,7 +231,7 @@ function wg_upgrade_addresses() { foreach ($tunnel['addresses']['item'] as $a_index => $item) { - list($addr, $addr_mask) = explode('/', $item['addr']); + [$addr, $addr_mask] = explode('/', $item['addr']); $tmp_addrs['row'][$a_index]['address'] = $addr; diff --git a/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_validate.inc b/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_validate.inc index 5637892c..1dbd4322 100644 --- a/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_validate.inc +++ b/net/pfSense-pkg-WireGuard/files/usr/local/pkg/wireguard/wg_validate.inc @@ -170,10 +170,7 @@ function wg_validate_peer_post($pconfig, $posted_peer_idx) { } elseif (!empty($pconfig['tun'])) { - foreach (wg_tunnel_get_peers_config($pconfig['tun']) as $peer_config) { - - // Pull out relevant bits - list($peer_idx, $peer, $is_new) = $peer_config; + foreach (wg_tunnel_get_peers_config($pconfig['tun']) as [$peer_idx, $peer, $is_new]) { // We don't want duplicate public keys per tunnel, but re-saving is okay... if (($peer['publickey'] == $pconfig['publickey']) && ($peer_idx != $posted_peer_idx)) { diff --git a/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_peers.php b/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_peers.php index e136a5c1..b0e66795 100644 --- a/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_peers.php +++ b/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_peers.php @@ -103,7 +103,7 @@ mark_subsystem_dirty($wgg['subsystems']['wg']); // Add tunnel to the list to apply - wg_apply_list_add($res['tun_to_sync'], 'tunnels'); + wg_apply_list_add('tunnels', $res['tuns_to_sync']); } diff --git a/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_peers_edit.php b/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_peers_edit.php index 3c4fb7fc..de714cbe 100644 --- a/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_peers_edit.php +++ b/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_peers_edit.php @@ -74,7 +74,7 @@ mark_subsystem_dirty($wgg['subsystems']['wg']); // Add tunnel to the list to apply - wg_apply_list_add($res['tun_to_sync'], 'tunnels'); + wg_apply_list_add('tunnels', $res['tuns_to_sync']); } diff --git a/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_tunnels.php b/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_tunnels.php index 269256f5..134a4509 100644 --- a/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_tunnels.php +++ b/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_tunnels.php @@ -113,7 +113,7 @@ mark_subsystem_dirty($wgg['subsystems']['wg']); // Add tunnel to the list to apply - wg_apply_list_add($res['tun_to_sync'], 'tunnels'); + wg_apply_list_add('tunnels', $res['tuns_to_sync']); } diff --git a/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_tunnels_edit.php b/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_tunnels_edit.php index c0a5bbe9..dedea639 100644 --- a/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_tunnels_edit.php +++ b/net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_tunnels_edit.php @@ -100,7 +100,7 @@ mark_subsystem_dirty($wgg['subsystems']['wg']); // Add tunnel to the list to apply - wg_apply_list_add($res['tun_to_sync'], 'tunnels'); + wg_apply_list_add('tunnels', $res['tuns_to_sync']); } @@ -176,7 +176,7 @@ mark_subsystem_dirty($wgg['subsystems']['wg']); // Add tunnel to the list to apply - wg_apply_list_add($res['tun_to_sync'], 'tunnels'); + wg_apply_list_add('tunnels', $res['tuns_to_sync']); } @@ -467,9 +467,7 @@ ';" class="">