Project

General

Profile

Download (5.67 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * vpn_iwg.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2013-2016 Electric Sheep Fencing
7
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
8
 * All rights reserved.
9
 *
10
 * originally based on m0n0wall (http://m0n0.ch/wall)
11
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
 * All rights reserved.
13
 *
14
 * Licensed under the Apache License, Version 2.0 (the "License");
15
 * you may not use this file except in compliance with the License.
16
 * You may obtain a copy of the License at
17
 *
18
 * http://www.apache.org/licenses/LICENSE-2.0
19
 *
20
 * Unless required by applicable law or agreed to in writing, software
21
 * distributed under the License is distributed on an "AS IS" BASIS,
22
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
 * See the License for the specific language governing permissions and
24
 * limitations under the License.
25
 */
26

    
27
##|+PRIV
28
##|*IDENT=page-vpn-wg
29
##|*NAME=VPN: WireGuard
30
##|*DESCR=Allow access to the 'VPN: WireGuard' page.
31
##|*MATCH=vpn_wg.php*
32
##|-PRIV
33

    
34
require_once("guiconfig.inc");
35
require_once("functions.inc");
36
require_once("wg.inc");
37

    
38
init_config_arr(array('wireguard', 'tunnel'));
39
$tunnels = &$config['wireguard']['tunnel'];
40

    
41
$pgtitle = array(gettext("VPN"), gettext("WireGuard"), gettext("Tunnels"));
42
$pglinks = array("", "@self", "@self");
43
$shortcut_section = "wireguard";
44

    
45
include("head.inc");
46

    
47
// Delete a tunnel?
48
if (array_key_exists('delidx', $_POST)) {
49
	deleteTunnel($_POST['delidx']);
50
	header("Location: vpn_wg.php");
51
}
52
?>
53

    
54
<form name="mainform" method="post">
55
<?php
56
	if (count($tunnels) == 0):
57
		print_info_box(gettext('No WireGuard tunnels have been configured. Click the "Add tunnel" button below to create one.'), 'warning', false);
58
	else:
59
?>
60
	<div class="panel panel-default">
61
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('WireGuard Tunnels')?></h2></div>
62
		<div class="panel-body table-responsive">
63
			<table class="table table-striped table-hover">
64
				<thead>
65
					<tr>
66
						<th class="peer-entries"></th>
67
						<th><?=gettext("Name")?></th>
68
						<th><?=gettext("Description")?></th>
69
						<th><?=gettext("Address")?></th>
70
						<th><?=gettext("Port")?></th>
71
						<th><?=gettext("# Peers")?></th>
72
						<th><?=gettext("Actions")?></th>
73
					</tr>
74
				</thead>
75
				<tbody>
76
<?php
77

    
78
		$i = 0;
79
		foreach ($tunnels as $tunnel):
80
			$entryStatus = ($tunnel['enabled'] == 'yes') ? 'enabled':'disabled';
81
			if (!$tunnel['peers'] || !is_array($tunnel['peers'])) {
82
				$tunnel['peers'] = array();
83
			}
84
			if (!$tunnel['peers']['wgpeer'] || !is_array($tunnel['peers']['wgpeer'])) {
85
				$tunnel['peers']['wgpeer'] = array();
86
			}
87
?>
88
					<tr id="fr<?=$i?>" id="frd<?=$i?>" class="<?= $entryStatus ?>">
89
						<td class="peer-entries"><?=gettext('Interface')?></td>
90
						<td><?=$tunnel['name']?></td>
91
						<td><?=$tunnel['descr']?></td>
92
						<td><?=$tunnel['interface']['address']?></td>
93
						<td><?=$tunnel['interface']['listenport']?></td>
94
						<td><?=count($tunnel['peers']['wgpeer'])?></td>
95

    
96
						<td style="cursor: pointer;">
97
							<a class="fa fa-pencil" href="vpn_wg_edit.php?index=<?=$i?>" title="<?=gettext("Edit tunnel"); ?>"></a>
98
							<a class="fa fa-trash text-danger" id="Xdel_<?=$i?>" title="<?=gettext('Delete tunnel'); ?>"></a>
99
						</td>
100
					</tr>
101

    
102
					<tr class="peer-entries" style="background-color:#ccf2ff;"> <!-- Move to pfSense.css -->
103
						<td>Peers</td>
104
<?php
105
			if (count($tunnel['peers']['wgpeer']) > 0):
106
?>
107
						<td colspan="6">
108
							<table class="table table-hover" style="background-color:#ccf2ff;"> <!-- Move to pfSense.css -->
109
								<thead>
110
									<tr>
111
										<th>Description</th>
112
										<th>Endpoint</th>
113
										<th>Allowed IPs</th>
114
										<th>Public key</th>
115
									</tr>
116
								</thead>
117
								<tbody>
118

    
119
<?php
120
				foreach ($tunnel['peers']['wgpeer'] as $peer):
121
?>
122
									<tr>
123
										<td><?=$peer['descr']?></td>
124
										<td><?=$peer['endpoint']?>:<?=$peer['port']?></td>
125
										<td><?=$peer['allowedips']?></td>
126
										<td><?=$peer['publickey']?></td>
127
									</tr>
128
<?php
129
				endforeach;
130
?>
131
								</tbody>
132
							</table>
133
						</td>
134
<?php
135
			else:
136
				print('<td colspan="6">' . gettext("No peers have been configured") . '</td>');
137
			endif;
138
?>
139
					</tr>
140
<?php
141
			$i++;
142
		endforeach;	 // $tunnelsa
143
?>
144
				</tbody>
145
			</table>
146
		</div>
147
	</div>
148

    
149

    
150
<?php
151
		$section = new Form_Section('Firewall keys');
152
		$section->addClass('fwkeys');
153

    
154
		$section->addInput(new Form_Input(
155
			'pubkey',
156
			'Public key',
157
			'',
158
			''
159
		))->setReadonly();
160

    
161
		$section->addInput(new Form_Input(
162
			'privkey',
163
			'Private key',
164
			'',
165
			''
166
		))->setReadonly();
167

    
168
		print($section);
169
	endif;
170
?>
171

    
172
	<nav class="action-buttons">
173
		<a href="#" class="btn btn-info btn-sm" id="showpeers">
174
			<i class="fa fa-info icon-embed-btn"></i>
175
			<?=gettext("Show peers")?>
176
		</a>
177

    
178
		<a href="vpn_wg_edit.php?index=<?=nextFreeWGInterfaceName();?>" class="btn btn-success btn-sm">
179
			<i class="fa fa-plus icon-embed-btn"></i>
180
			<?=gettext("Add Tunnel")?>
181
		</a>
182
	</nav>
183
</form>
184

    
185
<!-- Simple form that is submitted on tunnel delete -->
186
<form name="delform" id="delform" method="post">
187
	<input id="delidx" name="delidx" type="hidden" />
188
</form>
189

    
190
<script type="text/javascript">
191
//<![CDATA[
192

    
193
events.push(function() {
194
	var peershidden = true;
195
	var keyshidden = true;
196

    
197
	hideClass('peer-entries', peershidden);
198
	hideClass('fwkeys', keyshidden);
199

    
200
	// Toggle peer visibility
201
	$('#showpeers').click(function () {
202
		peershidden = !peershidden;
203
		hideClass('peer-entries', peershidden);
204
	})
205

    
206
	// Delete tunnel
207
	$('[id^=Xdel_]').click(function (event) {
208
		var idx = event.target.id.split('_')[1];
209
		$('#delidx').val(idx);  // Set the id of the tunnel
210
		$('#delform').submit(); // Submit the form
211
	});
212
});
213
//]]>
214
</script>
215

    
216
<?php
217
include("foot.inc");
(228-228/231)