Project

General

Profile

Download (9.2 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2
/*
3
	vpn_ipsec.php
4 e2411886 Scott Ullrich
	part of m0n0wall (http://m0n0.ch/wall)
5 574a2b47 Scott Ullrich
6 e2411886 Scott Ullrich
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
7 cfc707f7 Scott Ullrich
	All rights reserved.
8 574a2b47 Scott Ullrich
9 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11 574a2b47 Scott Ullrich
12 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14 574a2b47 Scott Ullrich
15 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18 574a2b47 Scott Ullrich
19 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
31
require("guiconfig.inc");
32
33
if (!is_array($config['ipsec']['tunnel'])) {
34
	$config['ipsec']['tunnel'] = array();
35
}
36
$a_ipsec = &$config['ipsec']['tunnel'];
37 e2411886 Scott Ullrich
$wancfg = &$config['interfaces']['wan'];
38 5b237745 Scott Ullrich
39
$pconfig['enable'] = isset($config['ipsec']['enable']);
40 91f1378c Scott Ullrich
$pconfig['ipcomp'] = isset($config['ipsec']['ipcomp']);
41 5b237745 Scott Ullrich
42
if ($_POST) {
43
44
	if ($_POST['apply']) {
45
		$retval = 0;
46 bf92bc79 Seth Mos
		$retval = vpn_ipsec_refresh_policies();
47 3851094f Scott Ullrich
		$retval = vpn_ipsec_configure();
48 bf92bc79 Seth Mos
		/* reload the filter in the background */
49
		filter_configure();
50 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
51
		if ($retval == 0) {
52
			if (file_exists($d_ipsecconfdirty_path))
53
				unlink($d_ipsecconfdirty_path);
54
		}
55
	} else if ($_POST['submit']) {
56
		$pconfig = $_POST;
57 574a2b47 Scott Ullrich
58 5b237745 Scott Ullrich
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
59 91f1378c Scott Ullrich
		$config['ipsec']['ipcomp'] = $_POST['ipcomp'] ? true : false;
60
		
61 5b237745 Scott Ullrich
		write_config();
62 574a2b47 Scott Ullrich
63 5b237745 Scott Ullrich
		$retval = 0;
64 3851094f Scott Ullrich
		config_lock();
65 bf92bc79 Seth Mos
		$retval = vpn_ipsec_refresh_policies();
66 1a93a8ab Scott Ullrich
		$retval = vpn_ipsec_configure();
67 3851094f Scott Ullrich
		config_unlock();
68
		/* reload the filter in the background */
69 574a2b47 Scott Ullrich
		filter_configure();
70 3851094f Scott Ullrich
71 5b237745 Scott Ullrich
		$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'] == "del") {
80
	if ($a_ipsec[$_GET['id']]) {
81 9528a92d Seth Mos
		/* remove static route if interface is not WAN */
82
		if($a_ipsec[$_GET['id']]['interface'] <> "wan") {
83 bf92bc79 Seth Mos
			$oldgw = resolve_retry($a_ipsec[$_GET['id']]['remote-gateway']);
84
			mwexec("/sbin/route delete -host {$oldgw}");
85 9528a92d Seth Mos
		}
86 5b237745 Scott Ullrich
		unset($a_ipsec[$_GET['id']]);
87 bf92bc79 Seth Mos
		vpn_ipsec_configure();
88 3fdb04a6 Scott Ullrich
		filter_configure();
89 5b237745 Scott Ullrich
		write_config();
90
		header("Location: vpn_ipsec.php");
91
		exit;
92
	}
93
}
94 4df96eff Scott Ullrich
95 b128368a Bill Marquette
$pgtitle = "VPN: IPsec";
96 4df96eff Scott Ullrich
include("head.inc");
97
98 5b237745 Scott Ullrich
?>
99 4df96eff Scott Ullrich
100 422f27c0 Scott Ullrich
101
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
102 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
103 b128368a Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
104 5b237745 Scott Ullrich
<form action="vpn_ipsec.php" method="post">
105
<?php if ($savemsg) print_info_box($savemsg); ?>
106
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
107 bf93840d Scott Ullrich
<?php if ($pconfig['enable'])
108 bf92bc79 Seth Mos
		print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes 
109
in order for them to take effect.");?><br>
110 5b237745 Scott Ullrich
<?php endif; ?>
111
<table width="100%" border="0" cellpadding="0" cellspacing="0">
112 e2411886 Scott Ullrich
  <tr><td class="tabnavtbl">
113 323d040b Scott Ullrich
<?php
114
	$tab_array = array();
115
	$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
116
	$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
117
	$tab_array[2] = array("Pre-shared keys", false, "vpn_ipsec_keys.php");
118
	$tab_array[3] = array("CAs", false, "vpn_ipsec_ca.php");
119
	display_top_tabs($tab_array);
120 574a2b47 Scott Ullrich
?>
121 5b237745 Scott Ullrich
  </td></tr>
122 574a2b47 Scott Ullrich
  <tr>
123 0f10aee4 Bill Marquette
    <td>
124
	<div id="mainarea">
125
        <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
126 574a2b47 Scott Ullrich
                <tr>
127 e2411886 Scott Ullrich
                  <td class="vtable">
128
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked";?>>
129
                      <strong>Enable IPsec</strong></td>
130
                </tr>
131 574a2b47 Scott Ullrich
                <tr>
132
                  <td> <input name="submit" type="submit" class="formbtn" value="Save">
133 5b237745 Scott Ullrich
                  </td>
134
                </tr>
135 0f10aee4 Bill Marquette
        </table>
136
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
137 5b237745 Scott Ullrich
                <tr>
138
                  <td nowrap class="listhdrr">Local net<br>
139
                    Remote net</td>
140
                  <td class="listhdrr">Interface<br>Remote gw</td>
141
                  <td class="listhdrr">P1 mode</td>
142
                  <td class="listhdrr">P1 Enc. Algo</td>
143
                  <td class="listhdrr">P1 Hash Algo</td>
144
                  <td class="listhdr">Description</td>
145 05c90549 Seth Mos
                  <td class="list" >
146
			<table border="0" cellspacing="0" cellpadding="1">
147
			     <tr>
148
				<td width="17" heigth="17"></td>
149
				<td><a href="vpn_ipsec_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add tunnel" width="17" height="17" border="0"></a></td>
150
			     </tr>
151
			</table>
152 d16448ea Seth Mos
		  </td>
153 05c90549 Seth Mos
		</tr>
154 5b237745 Scott Ullrich
                <?php $i = 0; foreach ($a_ipsec as $ipsecent):
155
					if (isset($ipsecent['disabled'])) {
156
						$spans = "<span class=\"gray\">";
157
						$spane = "</span>";
158
					} else {
159
						$spans = $spane = "";
160
					}
161
				?>
162
                <tr valign="top">
163 574a2b47 Scott Ullrich
                  <td nowrap class="listlr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
164 5b237745 Scott Ullrich
                    <?php	if ($ipsecent['local-subnet']['network'])
165
								echo strtoupper($ipsecent['local-subnet']['network']);
166
							else
167
								echo $ipsecent['local-subnet']['address'];
168
					?>
169
                    <br>
170
                    <?=$ipsecent['remote-subnet'];?>
171
                  <?=$spane;?></td>
172 c62799be Scott Ullrich
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
173 5b237745 Scott Ullrich
				  <?php if ($ipsecent['interface']) {
174
							$iflabels = array('lan' => 'LAN', 'wan' => 'WAN');
175 87e72a58 Scott Ullrich
                 	        $carpips = find_number_of_needed_carp_interfaces();
176 210b0258 Scott Ullrich
                         	    for($j=0; $j<$carpips; $j++) {
177
                       				$carpip = find_interface_ip("carp" . $j);
178 b7aa32c0 Scott Ullrich
                      	 			$iflabels['carp' . $j] = "CARP{$j} ({$carpip})"; 
179 87e72a58 Scott Ullrich
                     		    }
180
							for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
181 5b237745 Scott Ullrich
								$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
182 87e72a58 Scott Ullrich
							$if = htmlspecialchars($iflabels[$ipsecent['interface']]);
183 5b237745 Scott Ullrich
						} else
184
							$if = "WAN";
185 574a2b47 Scott Ullrich
186 5b237745 Scott Ullrich
						echo $if . "<br>" . $ipsecent['remote-gateway'];
187
					?>
188
                  <?=$spane;?></td>
189 c62799be Scott Ullrich
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
190 5b237745 Scott Ullrich
				    <?=$ipsecent['p1']['mode'];?>
191
                  <?=$spane;?></td>
192 c62799be Scott Ullrich
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
193 5b237745 Scott Ullrich
				    <?=$p1_ealgos[$ipsecent['p1']['encryption-algorithm']];?>
194
                  <?=$spane;?></td>
195 c62799be Scott Ullrich
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
196 5b237745 Scott Ullrich
				    <?=$p1_halgos[$ipsecent['p1']['hash-algorithm']];?>
197
                  <?=$spane;?></td>
198 c62799be Scott Ullrich
                  <td class="listbg" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?><font color="#FFFFFF">
199 e2411886 Scott Ullrich
                    <?=htmlspecialchars($ipsecent['descr']);?>&nbsp;
200 5b237745 Scott Ullrich
                  <?=$spane;?></td>
201 05c90549 Seth Mos
                  <td valign="middle" nowrap class="list">
202
			<table border="0" cellspacing="0" cellpadding="1">
203
			     <tr>
204
				<td><a href="vpn_ipsec_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit tunnel" width="17" height="17" border="0"></a></td>
205
                    		<td><a href="vpn_ipsec.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this tunnel?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete tunnel" width="17" height="17" border="0"></a></td>
206
			     </tr>
207
			     <tr>
208
				<td></td>
209
				<td><a href="vpn_ipsec_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add a new rule based on this one" width="17" height="17" border="0"></a></td>
210
			     </tr>
211
			</table>
212
		  </td>
213
		</tr>
214 e2411886 Scott Ullrich
			  <?php $i++; endforeach; ?>
215 574a2b47 Scott Ullrich
                <tr>
216 5b237745 Scott Ullrich
                  <td class="list" colspan="6"></td>
217 05c90549 Seth Mos
		  <td class="list">
218
			<table border="0" cellspacing="0" cellpadding="1">
219
			     <tr>
220
				<td width="17"></td>
221
				<td><a href="vpn_ipsec_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add tunnel" width="17" height="17" border="0"></a></td>
222
			     </tr>
223
			</table>
224
		  <td>
225
                </tr>
226
		    <td colspan="4">
227 c55a8ab9 Holger Bauer
		      <p><span class="vexpl"><span class="red"><strong>Note:<br>
228 5c99e8ef Chris Buechler
                      </strong></span>You can check your IPsec status at <a href="diag_ipsec_sad.php">Status:IPsec</a>.</span></p>
229 c55a8ab9 Holger Bauer
		  </td>
230 8912e405 Seth Mos
		</tr>
231 5b237745 Scott Ullrich
              </table>
232 0f10aee4 Bill Marquette
	      </div>
233
  	  </td>
234 5b237745 Scott Ullrich
	</tr>
235
</table>
236
</form>
237
<?php include("fend.inc"); ?>
238 323d040b Scott Ullrich
</body>
239
</html>