Project

General

Profile

« Previous | Next » 

Revision db784b1a

Added by Steve Beaver over 4 years ago

#5186 Added keepalive units, clarified Address text, added incremented port placeholder, minor validation changes

View differences:

src/etc/inc/web/wg.inc
24 24

  
25 25
$wgbinpath = '/usr/local/bin/wg';
26 26

  
27
// Return the next available wWreguard port
28
function next_wg_port() {
29
	global $config;
30

  
31
	init_config_arr(array('wireguard', 'tunnel'));
32
	$tunnels = &$config['wireguard']['tunnel'];
33

  
34
	$found = true;
35
	for ($idx=51820; $idx<65535 && $found; $idx++) {
36

  
37
		// Check to see if the port is already in use
38
		$found = false;
39
		foreach ($tunnels as $tunnel) {
40
			if ($tunnel['interface']['listenport'] == $idx) {
41
				$found = true;
42
			}
43
		}
44

  
45
		// If not, it can be used
46
		if (!$found) {
47
			return $idx;
48
		}
49
	}
50

  
51
	return 51820;
52
}
53

  
27 54
// Validate the user's input and return error messages if not acceptable
28 55
function wg_validate_post($pconfig) {
29 56
	$input_errors = array();
......
75 102

  
76 103
	// Check remote port
77 104
	$rport = $peer['port'];
78
	if (!empty($rport) && ($rport > 65535 || $rport < 512 )) {
105
	if (!empty($rport){
106
		$input_errors[] = "Peer " . $idx . gettext(": A port must be specified";
107
	} else  if ($rport > 65535 || $rport < 512 )) {
79 108
		$input_errors[] = "Peer " . $idx . gettext(": Invalid remote port. (") . $rport . ")";
80 109
	}
81 110

  
src/usr/local/www/vpn_wg_edit.php
61 61
	}
62 62
} else if ($_POST['action'] == 'genkeys') { // Process ajax call requesting new key pair
63 63
	print(genKeyPair(true));
64
	// Debug:
65
	// print(json_encode(array('pubkey' => 'myPublicKeyThingyXXXXXXXXXXXXXXXXXX==', 'privkey' => 'myPrivateKeyThingyYYYYYYYYYYYYYYYYYY==')));
66 64
	exit;
67 65
} else {
68
	if (isset($index) && $tunnels[$index]) {
69
		$pconfig = &$tunnels[$index];
66
	if (isset($index)) {
67
		if ($tunnels[$index]) {
68
			$pconfig = &$tunnels[$index];
69
		}
70 70
	}
71 71
}
72 72

  
......
113 113
	'*Address',
114 114
	'text',
115 115
	$pconfig['interface']['address']
116
))->setHelp('Comma separated list of interface Addresses.');
116
))->setHelp('Comma separated list of addresses assigned to interface.');
117 117

  
118 118

  
119 119
$section->addInput(new Form_Input(
120 120
	'listenport',
121 121
	'*Listen port',
122 122
	'text',
123
	$pconfig['interface']['listenport']
123
	$tunnels[$index],
124
	['placeholder' => next_wg_port()]
124 125
))->setHelp('Port to listen on.');
125 126

  
126 127
$group = new Form_Group('*Interface keys');
......
202 203

  
203 204
	$group->add(new Form_Input(
204 205
		'persistentkeepalive' . $peer_num,
205
		'Keepalive',
206
		'Keepalive (seconds)',
206 207
		'PDF_pcos_get_number(p, doc, path)',
207 208
		$peer['persistentkeepalive']
208 209
	))->setHelp($ka_help)->setWidth(1);
......
219 220

  
220 221
	$group2->add(new Form_Input(
221 222
		'publickeyp' . $peer_num,
222
		'Public key',
223
		'*Public key',
223 224
		'text',
224 225
		$peer['publickey']
225 226
	))->setHelp($dnshost_help)->setWidth(4);

Also available in: Unified diff