Skip to content

Commit 30e149f

Browse files
authored
Bump main to v0.0.4_2
* Sets the tunnel enabled button to readonly if interface is assigned * Fixed syntax error with changes to enabled checkbox * Fix some oo symantics * Another syntax fix * Fixes a css style issue with placeholder text on secrets when blurred * Another attempt to fix cosmetic issue with placeholder text * Adds a new function to check if any wg tunnels are assigned interfaces * Fixes a syntax error in is_wg_assigned() * Working on package cleanup settings * Fixed some syntax bugs * Fixed some syntax errors in vpn_wg_settings.php * Correctly change keep_extras preferring interface assignment, but defaulting to no on fresh installs. * Fixed syntax error in previous commit * Working on settings page * Third times a charm * Bump revision to v0.0.4_2
1 parent a651436 commit 30e149f

File tree

6 files changed

+110
-19
lines changed

6 files changed

+110
-19
lines changed

src/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# $FreeBSD$
22

33
PORTNAME= pfSense-pkg-WireGuard
4-
PORTVERSION= 0.0.5
5-
PORREVISION= 0
4+
PORTVERSION= 0.0.4
5+
PORREVISION= 2
66
CATEGORIES= net
77
MASTER_SITES= # empty
88
DISTFILES= # empty

src/files/usr/local/pkg/wireguard/wg_api.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function exec_wg_quick_action($tunnel, $action, $verbose = false) {
108108
$wg_ifname = $tunnel;
109109

110110
// Looks like we have a tunnel structure
111-
if (is_array($tunnel)) {
111+
if (is_array($tunnel) && isset($tunnel['name'])) {
112112

113113
$wg_ifname = $tunnel['name'];
114114

src/files/usr/local/pkg/wireguard/wg_globals.inc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,26 @@
2323

2424
global $wgg;
2525

26+
$pkg_name = "wireguard";
27+
2628
$wgg = array(
2729
'wg' => '/usr/local/bin/wg',
2830
'wg_quick' => '/usr/local/bin/wg-quick',
29-
'conf_path' => '/etc/wireguard',
3031
'ifconfig' => '/sbin/ifconfig',
3132
'kldstat' => '/sbin/kldstat',
3233
'pkg' => '/usr/sbin/pkg',
34+
35+
'conf_path' => '/etc/wireguard',
36+
3337
'if_prefix' => 'wg',
3438
'if_group' => 'WireGuard',
3539
'default_mtu' => 1420,
40+
3641
'script_path' => '/usr/local/etc',
3742
'earlyshellcmds' => array('/usr/local/etc/rc.bootstrap_wireguard', '/usr/local/etc/rc.reload_wireguard'),
3843
'pkg_scripts' => array('/usr/local/etc/rc.reload_wireguard'),
3944
'extra_scripts' => array('/usr/local/pkg/wireguard/etc/rc.bootstrap_wireguard'),
45+
4046
'verbose' => false
4147
);
4248

src/files/usr/local/pkg/wireguard/wg_validate.inc

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,31 +179,62 @@ function is_wg_tunnel_assigned($tunnel, $disabled = true) {
179179
$wg_ifname = $tunnel;
180180

181181
// Looks like we have a tunnel structure
182-
if (is_array($tunnel)) {
182+
if (is_array($tunnel) && isset($tunnel['name'])) {
183183

184184
$wg_ifname = $tunnel['name'];
185185

186186
}
187187

188188
$if_list = get_configured_interface_list_by_realif($disabled);
189189

190-
$if_assigned = array_key_exists($wg_ifname, $if_list);
190+
$is_assigned = array_key_exists($wg_ifname, $if_list);
191191

192-
return $if_assigned;
192+
return $is_assigned;
193193

194194
}
195195

196+
// Check if at least one tunnel is assigned
197+
function is_wg_assigned($disabled = true) {
198+
global $wgg;
199+
200+
// Assume that no tunnels are assigned
201+
$is_assigned = false;
202+
203+
$if_list = get_configured_interface_list_by_realif($disabled);
204+
205+
foreach ($if_list as $realif => $name) {
206+
207+
// We found one, no need to keep checking
208+
if (substr($realif, 0, strlen($wgg['if_prefix'])) == $wgg['if_prefix']) {
209+
210+
$is_assigned = true;
211+
212+
break;
213+
214+
}
215+
216+
}
217+
218+
return $is_assigned;
219+
220+
}
221+
196222
// Check if at least one tunnel is enabled
197223
function is_wg_enabled() {
198224
global $config;
199225

200226
init_config_arr(array('installedpackages', 'wireguard', 'tunnel'));
201227

202228
foreach ($config['installedpackages']['wireguard']['tunnel'] as $tunnel) {
229+
203230
if (empty($tunnel['enabled'])) {
231+
204232
continue;
233+
205234
}
235+
206236
return true;
237+
207238
}
208239

209240
return false;

src/files/usr/local/www/wg/vpn_wg_edit.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
// WireGuard includes
3636
require_once("/usr/local/pkg/wireguard/wg.inc");
3737

38-
init_config_arr(array('installedpackages', 'wireguard', 'tunnel'));
39-
$tunnels = &$config['installedpackages']['wireguard']['tunnel'];
40-
4138
init_config_arr(array('installedpackages', 'wireguard', 'config', 0));
4239
$wg_config = &$config['installedpackages']['wireguard']['config'][0];
4340

41+
init_config_arr(array('installedpackages', 'wireguard', 'tunnel'));
42+
$tunnels = &$config['installedpackages']['wireguard']['tunnel'];
43+
4444
if (is_numericint($_REQUEST['index'])) {
4545
$index = $_REQUEST['index'];
4646
}
@@ -143,13 +143,24 @@
143143
$index
144144
));
145145

146-
$section->addInput(new Form_Checkbox(
146+
$enabled_button = new Form_Checkbox(
147147
'enabled',
148148
'Tunnel Enabled',
149149
gettext('Enable'),
150150
$pconfig['enabled'] == 'yes'
151-
))->setHelp('<span class="text-danger">Note: </span>'
152-
. 'Tunnel must be enabled in order to be assigned to an interface');
151+
);
152+
153+
$enabled_button->setHelp('<span class="text-danger">Note: </span>Tunnel must be <b>enabled</b> in order to be assigned to an interface');
154+
155+
// Disable the tunnel enabled button if interface is assigned
156+
if (is_wg_tunnel_assigned($pconfig)) {
157+
158+
$enabled_button->setDisabled();
159+
$enabled_button->setHelp('<span class="text-danger">Note: </span>Tunnel cannot be <b>disabled</b> when assigned to an interface');
160+
161+
}
162+
163+
$section->addInput($enabled_button);
153164

154165
$section->addInput(new Form_Input(
155166
'descr',
@@ -431,10 +442,13 @@
431442
// Eliminate ghost lines in modal
432443
$('.form-group').css({"border-bottom-width" : "0"});
433444

445+
// Eliminates blurred placeholder text
446+
$('body').append('<style>::placeholder{color:revert;text-shadow:none;}</style>');
447+
434448
// Blurs secrets
435449
if (wg_config['blur_secrets'] == 'yes') {
436450

437-
var blur = {"color" : "transparent", "text-shadow" : "0 0 5px rgba(0,0,0,0.5)"};
451+
var blur = {"color" : "transparent", "text-shadow" : "0 0 5px rgba(0,0,0,0.5)"}
438452

439453
$("#privatekey").css(blur);
440454

src/files/usr/local/www/wg/vpn_wg_settings.php

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,32 @@
4646
$pconfig = $_POST;
4747

4848
$wg_config['keep_conf'] = $pconfig['keep_conf'];
49+
50+
$wg_config['keep_extras'] = $pconfig['keep_extras'];
4951

5052
$wg_config['blur_secrets'] = $pconfig['blur_secrets'];
5153

52-
write_config('[WireGuard] Save general settings');
54+
write_config('[WireGuard] Save WireGuard settings');
5355

54-
wg_resync();
56+
//wg_resync();
5557

5658
header("Location: /wg/vpn_wg_settings.php");
5759

5860
}
5961

6062
}
6163

64+
} else {
65+
66+
// Default to yes
67+
$pconfig['keep_conf'] = isset($wg_config['keep_conf']) ? $wg_config['keep_conf'] : 'yes';
68+
69+
// Default to no, unless there are interfaces already assigned
70+
$pconfig['keep_extras'] = isset($wg_config['keep_conf']) ? $wg_config['keep_extras'] : 'no';
71+
$pconfig['keep_extras'] = is_wg_assigned() ? 'yes' : $pconfig['keep_extras'];
72+
73+
$pconfig['blur_secrets'] = $wg_config['blur_secrets'];
74+
6275
}
6376

6477
$pgtitle = array(gettext("VPN"), gettext("WireGuard"), gettext("Settings"));
@@ -88,21 +101,48 @@
88101
'keep_conf',
89102
'Keep Configuration',
90103
gettext('Enable'),
91-
$wg_config['keep_conf']
104+
$pconfig['keep_conf'] == 'yes'
92105
))->setHelp('<span class="text-danger">Note: </span>'
93106
. 'With \'Keep Configurations\' enabled (default), all tunnel configurations and package settings will persist on install/de-install.'
94107
);
95108

109+
$keep_extras_btn = new Form_Checkbox(
110+
'keep_extras',
111+
'Keep Extra Scripts',
112+
gettext('Enable'),
113+
$pconfig['keep_extras'] == 'yes'
114+
);
115+
116+
// Check if any WireGuard tunnel is assigned to an interface
117+
if (is_wg_assigned()) {
118+
119+
// Prevent removal of extra scripts
120+
$keep_extras_btn->setDisabled();
121+
$keep_extras_btn->setHelp('<span class="text-danger">Note: </span>'
122+
. 'Extra scripts <b>cannot be removed</b> with any tunnels assigned to interfaces.');
123+
124+
} else {
125+
126+
$keep_extras_btn->setHelp('<span class="text-danger">Note: </span>'
127+
. 'With \'Keep Extra Scripts\' enabled, any extra scripts installed by the package will persist on install/de-install.');
128+
129+
}
130+
131+
$section->addInput($keep_extras_btn);
132+
133+
$form->add($section);
134+
135+
$section = new Form_Section("User Interface Settings");
136+
96137
$section->addInput(new Form_Checkbox(
97138
'blur_secrets',
98139
'Blur Secrets',
99140
gettext('Enable'),
100-
$wg_config['blur_secrets']
141+
$pconfig['blur_secrets'] == 'yes'
101142
))->setHelp('<span class="text-danger">Note: </span>'
102143
. 'With \'Blur Secrets\' enabled, all secrets (private and pre-shared keys) are blurred in the user interface.'
103144
);
104145

105-
106146
$form->add($section);
107147

108148
print($form);

0 commit comments

Comments
 (0)