Project

General

Profile

Download (8.99 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 3851094f Scott Ullrich
		$retval = vpn_ipsec_configure();
47 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
48
		if ($retval == 0) {
49
			if (file_exists($d_ipsecconfdirty_path))
50
				unlink($d_ipsecconfdirty_path);
51
		}
52
	} else if ($_POST['submit']) {
53
		$pconfig = $_POST;
54 574a2b47 Scott Ullrich
55 5b237745 Scott Ullrich
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
56 91f1378c Scott Ullrich
		$config['ipsec']['ipcomp'] = $_POST['ipcomp'] ? true : false;
57
		
58 5b237745 Scott Ullrich
		write_config();
59 574a2b47 Scott Ullrich
60 5b237745 Scott Ullrich
		$retval = 0;
61 3851094f Scott Ullrich
		config_lock();
62 1a93a8ab Scott Ullrich
		$retval = vpn_ipsec_configure();
63 3851094f Scott Ullrich
		config_unlock();
64
		/* reload the filter in the background */
65 574a2b47 Scott Ullrich
		filter_configure();
66 3851094f Scott Ullrich
67 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
68
		if ($retval == 0) {
69
			if (file_exists($d_ipsecconfdirty_path))
70
				unlink($d_ipsecconfdirty_path);
71
		}
72
	}
73
}
74
75
if ($_GET['act'] == "del") {
76
	if ($a_ipsec[$_GET['id']]) {
77 9528a92d Seth Mos
		/* remove static route if interface is not WAN */
78
		if($a_ipsec[$_GET['id']]['interface'] <> "wan") {
79
			mwexec("/sbin/route delete -host {$$a_ipsec[$_GET['id']]['remote-gateway']}");
80
		}
81 5b237745 Scott Ullrich
		unset($a_ipsec[$_GET['id']]);
82 3fdb04a6 Scott Ullrich
		filter_configure();
83 5b237745 Scott Ullrich
		write_config();
84
		header("Location: vpn_ipsec.php");
85
		exit;
86
	}
87
}
88 4df96eff Scott Ullrich
89 b128368a Bill Marquette
$pgtitle = "VPN: IPsec";
90 4df96eff Scott Ullrich
include("head.inc");
91
92 5b237745 Scott Ullrich
?>
93 4df96eff Scott Ullrich
94 422f27c0 Scott Ullrich
95
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
96 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
97 b128368a Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
98 5b237745 Scott Ullrich
<form action="vpn_ipsec.php" method="post">
99
<?php if ($savemsg) print_info_box($savemsg); ?>
100
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
101 bf93840d Scott Ullrich
<?php if ($pconfig['enable'])
102
		print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
103 5b237745 Scott Ullrich
<?php endif; ?>
104
<table width="100%" border="0" cellpadding="0" cellspacing="0">
105 e2411886 Scott Ullrich
  <tr><td class="tabnavtbl">
106 323d040b Scott Ullrich
<?php
107
	$tab_array = array();
108
	$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
109
	$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
110
	$tab_array[2] = array("Pre-shared keys", false, "vpn_ipsec_keys.php");
111
	$tab_array[3] = array("CAs", false, "vpn_ipsec_ca.php");
112
	display_top_tabs($tab_array);
113 574a2b47 Scott Ullrich
?>
114 5b237745 Scott Ullrich
  </td></tr>
115 574a2b47 Scott Ullrich
  <tr>
116 0f10aee4 Bill Marquette
    <td>
117
	<div id="mainarea">
118
        <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
119 574a2b47 Scott Ullrich
                <tr>
120 e2411886 Scott Ullrich
                  <td class="vtable">
121
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked";?>>
122
                      <strong>Enable IPsec</strong></td>
123
                </tr>
124 574a2b47 Scott Ullrich
                <tr>
125
                  <td> <input name="submit" type="submit" class="formbtn" value="Save">
126 5b237745 Scott Ullrich
                  </td>
127
                </tr>
128 0f10aee4 Bill Marquette
        </table>
129
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
130 5b237745 Scott Ullrich
                <tr>
131
                  <td nowrap class="listhdrr">Local net<br>
132
                    Remote net</td>
133
                  <td class="listhdrr">Interface<br>Remote gw</td>
134
                  <td class="listhdrr">P1 mode</td>
135
                  <td class="listhdrr">P1 Enc. Algo</td>
136
                  <td class="listhdrr">P1 Hash Algo</td>
137
                  <td class="listhdr">Description</td>
138 05c90549 Seth Mos
                  <td class="list" >
139
			<table border="0" cellspacing="0" cellpadding="1">
140
			     <tr>
141
				<td width="17" heigth="17"></td>
142
				<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>
143
			     </tr>
144
			</table>
145 d16448ea Seth Mos
		  </td>
146 05c90549 Seth Mos
		</tr>
147 5b237745 Scott Ullrich
                <?php $i = 0; foreach ($a_ipsec as $ipsecent):
148
					if (isset($ipsecent['disabled'])) {
149
						$spans = "<span class=\"gray\">";
150
						$spane = "</span>";
151
					} else {
152
						$spans = $spane = "";
153
					}
154
				?>
155
                <tr valign="top">
156 574a2b47 Scott Ullrich
                  <td nowrap class="listlr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
157 5b237745 Scott Ullrich
                    <?php	if ($ipsecent['local-subnet']['network'])
158
								echo strtoupper($ipsecent['local-subnet']['network']);
159
							else
160
								echo $ipsecent['local-subnet']['address'];
161
					?>
162
                    <br>
163
                    <?=$ipsecent['remote-subnet'];?>
164
                  <?=$spane;?></td>
165 c62799be Scott Ullrich
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
166 5b237745 Scott Ullrich
				  <?php if ($ipsecent['interface']) {
167
							$iflabels = array('lan' => 'LAN', 'wan' => 'WAN');
168 87e72a58 Scott Ullrich
                 	        $carpips = find_number_of_needed_carp_interfaces();
169 210b0258 Scott Ullrich
                         	    for($j=0; $j<$carpips; $j++) {
170
                       				$carpip = find_interface_ip("carp" . $j);
171 b7aa32c0 Scott Ullrich
                      	 			$iflabels['carp' . $j] = "CARP{$j} ({$carpip})"; 
172 87e72a58 Scott Ullrich
                     		    }
173
							for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
174 5b237745 Scott Ullrich
								$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
175 87e72a58 Scott Ullrich
							$if = htmlspecialchars($iflabels[$ipsecent['interface']]);
176 5b237745 Scott Ullrich
						} else
177
							$if = "WAN";
178 574a2b47 Scott Ullrich
179 5b237745 Scott Ullrich
						echo $if . "<br>" . $ipsecent['remote-gateway'];
180
					?>
181
                  <?=$spane;?></td>
182 c62799be Scott Ullrich
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
183 5b237745 Scott Ullrich
				    <?=$ipsecent['p1']['mode'];?>
184
                  <?=$spane;?></td>
185 c62799be Scott Ullrich
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
186 5b237745 Scott Ullrich
				    <?=$p1_ealgos[$ipsecent['p1']['encryption-algorithm']];?>
187
                  <?=$spane;?></td>
188 c62799be Scott Ullrich
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
189 5b237745 Scott Ullrich
				    <?=$p1_halgos[$ipsecent['p1']['hash-algorithm']];?>
190
                  <?=$spane;?></td>
191 c62799be Scott Ullrich
                  <td class="listbg" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?><font color="#FFFFFF">
192 e2411886 Scott Ullrich
                    <?=htmlspecialchars($ipsecent['descr']);?>&nbsp;
193 5b237745 Scott Ullrich
                  <?=$spane;?></td>
194 05c90549 Seth Mos
                  <td valign="middle" nowrap class="list">
195
			<table border="0" cellspacing="0" cellpadding="1">
196
			     <tr>
197
				<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>
198
                    		<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>
199
			     </tr>
200
			     <tr>
201
				<td></td>
202
				<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>
203
			     </tr>
204
			</table>
205
		  </td>
206
		</tr>
207 e2411886 Scott Ullrich
			  <?php $i++; endforeach; ?>
208 574a2b47 Scott Ullrich
                <tr>
209 5b237745 Scott Ullrich
                  <td class="list" colspan="6"></td>
210 05c90549 Seth Mos
		  <td class="list">
211
			<table border="0" cellspacing="0" cellpadding="1">
212
			     <tr>
213
				<td width="17"></td>
214
				<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>
215
			     </tr>
216
			</table>
217
		  <td>
218
                </tr>
219
		    <td colspan="4">
220 c55a8ab9 Holger Bauer
		      <p><span class="vexpl"><span class="red"><strong>Note:<br>
221 5c99e8ef Chris Buechler
                      </strong></span>You can check your IPsec status at <a href="diag_ipsec_sad.php">Status:IPsec</a>.</span></p>
222 c55a8ab9 Holger Bauer
		  </td>
223 8912e405 Seth Mos
		</tr>
224 5b237745 Scott Ullrich
              </table>
225 0f10aee4 Bill Marquette
	      </div>
226
  	  </td>
227 5b237745 Scott Ullrich
	</tr>
228
</table>
229
</form>
230
<?php include("fend.inc"); ?>
231 323d040b Scott Ullrich
</body>
232
</html>