Project

General

Profile

Download (12.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	vpn_ipsec.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5

    
6
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
7
	Copyright (C) 2008 Shrew Soft Inc
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

    
32
require("guiconfig.inc");
33

    
34
if (!is_array($config['ipsec']['phase1']))
35
	$config['ipsec']['phase1'] = array();
36

    
37
if (!is_array($config['ipsec']['phase2']))
38
	$config['ipsec']['phase2'] = array();
39

    
40
$a_phase1 = &$config['ipsec']['phase1'];
41
$a_phase2 = &$config['ipsec']['phase2'];
42

    
43
$wancfg = &$config['interfaces']['wan'];
44

    
45
$pconfig['enable'] = isset($config['ipsec']['enable']);
46

    
47
if ($_POST) {
48

    
49
	if ($_POST['apply']) {
50
		$retval = 0;
51
		$retval = vpn_ipsec_configure();
52
		$savemsg = get_std_save_message($retval);
53
		if ($retval == 0) {
54
			if (file_exists($d_ipsecconfdirty_path))
55
				unlink($d_ipsecconfdirty_path);
56
		}
57
	} else if ($_POST['submit']) {
58
		$pconfig = $_POST;
59

    
60
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
61
		
62
		write_config();
63

    
64
		$retval = 0;
65
		config_lock();
66
		$retval = vpn_ipsec_configure();
67
		config_unlock();
68
		/* reload the filter in the background */
69
		filter_configure();
70

    
71
		$savemsg = get_std_save_message($retval);
72
		if ($retval == 0) {
73
			if (file_exists($d_ipsecconfdirty_path))
74
				unlink($d_ipsecconfdirty_path);
75
		}
76
	}
77
}
78

    
79
if ($_GET['act'] == "delph1")
80
{
81
	if ($a_phase1[$_GET['p1index']]) {
82
		/* remove static route if interface is not WAN */
83
		if ($a_phase1[$_GET['p1index']]['interface'] <> "wan") {
84
			mwexec("/sbin/route delete -host {$$a_phase1[$_GET['p1index']]['remote-gateway']}");
85
		}
86

    
87
		/* remove all phase2 entries that match the ikeid */
88
		$ikeid = $a_phase1[$_GET['p1index']]['ikeid'];
89
		$p2index = 0;
90
		foreach ($a_phase2 as $ph2tmp) {
91
			if ($ph2tmp['ikeid'] == $ikeid) {
92
				/* remove the phase2 entry */
93
				unset($a_phase2[$p2index]);
94
				continue;
95
			}
96
			/* only skip if we remove an entry */
97
			$p2index++;
98
		}
99

    
100
		/* remove the phase1 entry */
101
		unset($a_phase1[$_GET['p1index']]);
102
		filter_configure();
103
		write_config();
104
		header("Location: vpn_ipsec.php");
105
		exit;
106
	}
107
}
108

    
109
if ($_GET['act'] == "delph2")
110
{
111
	if ($a_phase2[$_GET['p2index']]) {
112
		/* remove the phase2 entry */
113
		unset($a_phase2[$_GET['p2index']]);
114
		filter_configure();
115
		write_config();
116
		header("Location: vpn_ipsec.php");
117
		exit;
118
	}
119
}
120

    
121
$pgtitle = array("VPN","IPsec");
122
include("head.inc");
123

    
124
?>
125

    
126

    
127
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
128
<?php include("fbegin.inc"); ?>
129
<form action="vpn_ipsec.php" method="post">
130
<?php
131
	if ($savemsg)
132
		print_info_box($savemsg);
133
	if ($pconfig['enable'] && file_exists($d_ipsecconfdirty_path))
134
		print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes in order for them to take effect.");
135
?>
136
<table width="100%" border="0" cellpadding="0" cellspacing="0">
137
	<tr>
138
		<td class="tabnavtbl">
139
			<?php
140
				$tab_array = array();
141
				$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
142
//				$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
143
				$tab_array[2] = array("CAs", false, "vpn_ipsec_ca.php");
144
				display_top_tabs($tab_array);
145
			?>
146
		</td>
147
	</tr>
148
	<tr>
149
		<td>
150
			<div id="mainarea">
151
				<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
152
					<tr>
153
						<td class="vtable">
154
							<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked";?>>
155
							<strong>Enable IPsec</strong>
156
						</td>
157
					</tr>
158
					<tr>
159
						<td>
160
							<input name="submit" type="submit" class="formbtn" value="Save">
161
						</td>
162
					</tr>
163
				</table>
164
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
165
					<tr>
166
						<td class="listhdrr">Interface<br>Remote gw</td>
167
						<td class="listhdrr">P1 mode</td>
168
						<td class="listhdrr">P1 Enc. Algo</td>
169
						<td class="listhdrr">P1 Hash Algo</td>
170
						<td class="listhdr">Description</td>
171
						<td class="list" >
172
							<table border="0" cellspacing="0" cellpadding="o">
173
								<tr>
174
									<td width="17" heigth="17"></td>
175
									<td>
176
										<a href="vpn_ipsec_phase1.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add phase1 entry" width="17" height="17" border="0"></a>
177
									</td>
178
								</tr>
179
							</table>
180
						</td>
181
					</tr>
182
					<?php
183
						$i = 0;
184
						foreach ($a_phase1 as $ph1ent) {
185
							if (isset( $ph1ent['disabled'])) {
186
								$spans = "<span class=\"gray\">";
187
								$spane = "</span>";
188
							}
189
							else
190
								$spans = $spane = "";
191
					?>
192
					<tr valign="top">
193
						<td class="listlr" ondblclick="document.location='vpn_ipsec_phase1.php?id=<?=$i;?>'">
194
							<?=$spans;?>
195
							<?php
196
								if ($ph1ent['interface']) {
197
									$iflabels = get_configured_interface_with_descr();
198
									$carpips = find_number_of_needed_carp_interfaces();
199
									for( $j=0; $j<$carpips; $j++ ) {
200
										$carpip = find_interface_ip("carp" . $j);
201
										$iflabels['carp' . $j] = "CARP{$j} ({$carpip})"; 
202
									}
203
									$if = htmlspecialchars($iflabels[$ph1ent['interface']]);
204
								}
205
								else
206
									$if = "WAN";
207

    
208
								echo $if . "<br>" . $ph1ent['remote-gateway'];
209
							?>
210
							<?=$spane;?>
211
						</td>
212
						<td class="listr" ondblclick="document.location='vpn_ipsec_phase1.php?id=<?=$i;?>'">
213
							<?=$spans;?>
214
							<?=$ph1ent['mode'];?>
215
							<?=$spane;?>
216
						</td>
217
						<td class="listr" ondblclick="document.location='vpn_ipsec_phase1.php?id=<?=$i;?>'">
218
							<?=$spans;?>
219
							<?=$p1_ealgos[$ph1ent['encryption-algorithm']['name']]['name'];?>
220
							<?php
221
								if ($ph1ent['encryption-algorithm']['keylen']) {
222
									if ($ph1ent['encryption-algorithm']['keylen']=="auto")
223
										echo " (auto)";
224
									else
225
										echo " ({$ph1ent['encryption-algorithm']['keylen']} bits)";
226
								}
227
							?>
228
							<?=$spane;?>
229
						</td>
230
						<td class="listr" ondblclick="document.location='vpn_ipsec_phase1.php?id=<?=$i;?>'">
231
							<?=$spans;?>
232
							<?=$p1_halgos[$ph1ent['hash-algorithm']];?>
233
							<?=$spane;?>
234
						</td>
235
						<td class="listtopic" ondblclick="document.location='vpn_ipsec_phase1.php?id=<?=$i;?>'">
236
							<?=$spans;?>
237
								<font color="#FFFFFF">
238
									<?=htmlspecialchars($ph1ent['descr']);?>&nbsp;
239
								</font>
240
							<?=$spane;?>
241
						</td>
242
						<td valign="middle" nowrap class="list">
243
							<table border="0" cellspacing="0" cellpadding="1">
244
								<tr>
245
									<td>
246
										<a href="vpn_ipsec_phase1.php?p1index=<?=$i;?>">
247
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit phase1 entry" width="17" height="17" border="0">
248
										</a>
249
									</td>
250
									<td>
251
										<a href="vpn_ipsec.php?act=delph1&p1index=<?=$i;?>" onclick="return confirm('Do you really want to delete this phase1 and all associated phase2 entries?')">
252
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete phase1 entry" width="17" height="17" border="0">
253
										</a>
254
									</td>
255
								</tr>
256
								<tr>
257
									<td>
258
									</td>
259
									<td>
260
										<a href="vpn_ipsec_phase1.php?dup=<?=$i;?>">
261
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="copy phase1 entry" width="17" height="17" border="0">
262
										</a>
263
									</td>
264
								</tr>
265
							</table>
266
						</td>
267
					</tr>
268
					<tr>
269
						<td class="listbg" colspan="5">
270
							<table width="100%" height="100%"border="0" cellspacing="0" cellpadding="0">
271
								<tr>
272
									<td class="listhdrr">Local Network</td>
273
									<td class="listhdrr">Remote Network</td>
274
									<td class="listhdrr">P2 Protocol</td>
275
									<td class="listhdrr">P2 Transforms</td>
276
									<td class="listhdrr">P2 Auth Methods</td>
277
									<td class ="list">
278
										<a href="vpn_ipsec_phase2.php?ikeid=<?=$ph1ent['ikeid'];?>">
279
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add phase2 entry" width="17" height="17" border="0">
280
										</a>
281
									</td>
282
								</tr>
283
								<?php
284
									$j = 0;
285
									foreach ($a_phase2 as $ph2ent) {
286
										if ($ph2ent['ikeid'] != $ph1ent['ikeid']) {
287
											$j++;
288
											continue;
289
										}
290

    
291
										if (isset( $ph2ent['disabled']) || isset($ph1ent['disabled'])) {
292
											$spans = "<span class=\"gray\">";
293
											$spane = "</span>";
294
										}
295
										else
296
											$spans = $spane = "";
297
								?>
298
								<tr valign="top">
299
									<td nowrap class="listr" ondblclick="document.location='vpn_ipsec_phase2.php?id=<?=$i;?>'">
300
										<?=$spans;?>
301
										<?php echo ipsec_idinfo_to_text($ph2ent['localid']); ?>
302
										<?=$spane;?>
303
									</td>
304
									<td nowrap class="listr" ondblclick="document.location='vpn_ipsec_phase2.php?id=<?=$i;?>'">
305
										<?=$spans;?>
306
										<?php echo ipsec_idinfo_to_text($ph2ent['remoteid']); ?>
307
										<?=$spane;?>
308
									</td>
309
									<td nowrap class="listr" ondblclick="document.location='vpn_ipsec_phase2.php?id=<?=$i;?>'">
310
										<?=$spans;?>
311
										<?php echo $p2_protos[$ph2ent['protocol']];	?>
312
										<?=$spane;?>
313
									</td>
314
									<td nowrap class="listr" ondblclick="document.location='vpn_ipsec_phase2.php?id=<?=$i;?>'">
315
										<?=$spans;?>
316
										<?php
317
											$k = 0;
318
											foreach ($ph2ent['encryption-algorithm-option'] as $ph2ea) {
319
												if ($k++)
320
													echo ", ";
321
												echo $p2_ealgos[$ph2ea['name']]['name'];
322
												if ($ph2ea['keylen']) {
323
													if ($ph2ea['keylen']=="auto")
324
														echo " (auto)";
325
													else
326
														echo " ({$ph2ea['keylen']} bits)";
327
												}
328
											}
329
										?>
330
										<?=$spane;?>
331
									</td>
332
									<td nowrap class="listr" ondblclick="document.location='vpn_ipsec_phase2.php?id=<?=$i;?>'">
333
										<?=$spans;?>
334
										<?php
335
											$k = 0;
336
											foreach ($ph2ent['hash-algorithm-option'] as $ph2ha) {
337
												if ($k++)
338
													echo ", ";
339
												echo $p2_halgos[$ph2ha];
340
											}
341
										?>
342
										<?=$spane;?>
343
									</td>
344
									<td nowrap class="list">
345
										<a href="vpn_ipsec_phase2.php?p2index=<?=$j;?>">
346
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit phase2 entry" width="17" height="17" border="0">
347
										</a>
348
										<a href="vpn_ipsec.php?act=delph2&p2index=<?=$j;?>" onclick="return confirm('Do you really want to delete this phase2 entry?')">
349
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete phase2 entry" width="17" height="17" border="0">
350
										</a>
351
									</td>
352
								</tr>
353
								<?php
354
										$j++;
355
									}
356
								?>
357
							</table>
358
						</td>
359
					</tr>
360
					<?php
361
							$i++;
362
						}
363
					?>
364
					<tr>
365
						<td class="list" colspan="5"></td>
366
						<td class="list">
367
							<table border="0" cellspacing="0" cellpadding="1">
368
								<tr>
369
									<td width="17"></td>
370
									<td>
371
										<a href="vpn_ipsec_phase1.php">
372
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add phase1 entry" width="17" height="17" border="0">
373
										</a>
374
									</td>
375
								</tr>
376
							</table>
377
						<td>
378
					</tr>
379
					<tr>
380
						<td colspan="4">
381
							<p>
382
								<span class="vexpl">
383
									<span class="red">
384
										<strong>Note:<br></strong>
385
									</span>
386
									You can check your IPsec status at <a href="diag_ipsec.php">Status:IPsec</a>.
387
								</span>
388
							</p>
389
						</td>
390
					</tr>
391
				</table>
392
			</div>
393
		</td>
394
	</tr>
395
</table>
396
</form>
397
<?php include("fend.inc"); ?>
398
</body>
399
</html>
(170-170/197)