Project

General

Profile

Download (8.83 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 24e53389 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 6de5d673 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 d88c6a9f Scott Ullrich
$pgtitle = array("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
<form action="vpn_ipsec.php" method="post">
98
<?php if ($savemsg) print_info_box($savemsg); ?>
99
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
100 b8a4d945 Scott Ullrich
<?php if ($pconfig['enable'])
101
			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>
102 5b237745 Scott Ullrich
<?php endif; ?>
103
<table width="100%" border="0" cellpadding="0" cellspacing="0">
104 e2411886 Scott Ullrich
  <tr><td class="tabnavtbl">
105 323d040b Scott Ullrich
<?php
106
	$tab_array = array();
107
	$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
108
	$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
109
	$tab_array[2] = array("Pre-shared keys", false, "vpn_ipsec_keys.php");
110
	$tab_array[3] = array("CAs", false, "vpn_ipsec_ca.php");
111
	display_top_tabs($tab_array);
112 574a2b47 Scott Ullrich
?>
113 5b237745 Scott Ullrich
  </td></tr>
114 574a2b47 Scott Ullrich
  <tr>
115 0f10aee4 Bill Marquette
    <td>
116
	<div id="mainarea">
117
        <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
118 574a2b47 Scott Ullrich
                <tr>
119 e2411886 Scott Ullrich
                  <td class="vtable">
120
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked";?>>
121
                      <strong>Enable IPsec</strong></td>
122
                </tr>
123 574a2b47 Scott Ullrich
                <tr>
124
                  <td> <input name="submit" type="submit" class="formbtn" value="Save">
125 5b237745 Scott Ullrich
                  </td>
126
                </tr>
127 0f10aee4 Bill Marquette
        </table>
128
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
129 5b237745 Scott Ullrich
                <tr>
130
                  <td nowrap class="listhdrr">Local net<br>
131
                    Remote net</td>
132
                  <td class="listhdrr">Interface<br>Remote gw</td>
133
                  <td class="listhdrr">P1 mode</td>
134
                  <td class="listhdrr">P1 Enc. Algo</td>
135
                  <td class="listhdrr">P1 Hash Algo</td>
136
                  <td class="listhdr">Description</td>
137 d415d821 Seth Mos
                  <td class="list" >
138
			<table border="0" cellspacing="0" cellpadding="1">
139
			     <tr>
140
				<td width="17" heigth="17"></td>
141
				<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>
142
			     </tr>
143
			</table>
144 127bd0ce Seth Mos
		  </td>
145 d415d821 Seth Mos
		</tr>
146 5b237745 Scott Ullrich
                <?php $i = 0; foreach ($a_ipsec as $ipsecent):
147
					if (isset($ipsecent['disabled'])) {
148
						$spans = "<span class=\"gray\">";
149
						$spane = "</span>";
150
					} else {
151
						$spans = $spane = "";
152
					}
153
				?>
154
                <tr valign="top">
155 574a2b47 Scott Ullrich
                  <td nowrap class="listlr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
156 5b237745 Scott Ullrich
                    <?php	if ($ipsecent['local-subnet']['network'])
157
								echo strtoupper($ipsecent['local-subnet']['network']);
158
							else
159
								echo $ipsecent['local-subnet']['address'];
160
					?>
161
                    <br>
162
                    <?=$ipsecent['remote-subnet'];?>
163
                  <?=$spane;?></td>
164 c62799be Scott Ullrich
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
165 5b237745 Scott Ullrich
				  <?php if ($ipsecent['interface']) {
166 3e321df2 Ermal Luçi
							$iflabels = get_configured_interface_with_descr();
167 87e72a58 Scott Ullrich
                 	        $carpips = find_number_of_needed_carp_interfaces();
168 210b0258 Scott Ullrich
                         	    for($j=0; $j<$carpips; $j++) {
169
                       				$carpip = find_interface_ip("carp" . $j);
170 b7aa32c0 Scott Ullrich
                      	 			$iflabels['carp' . $j] = "CARP{$j} ({$carpip})"; 
171 87e72a58 Scott Ullrich
                     		    }
172
							$if = htmlspecialchars($iflabels[$ipsecent['interface']]);
173 5b237745 Scott Ullrich
						} else
174
							$if = "WAN";
175 574a2b47 Scott Ullrich
176 5b237745 Scott Ullrich
						echo $if . "<br>" . $ipsecent['remote-gateway'];
177
					?>
178
                  <?=$spane;?></td>
179 c62799be Scott Ullrich
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
180 5b237745 Scott Ullrich
				    <?=$ipsecent['p1']['mode'];?>
181
                  <?=$spane;?></td>
182 c62799be Scott Ullrich
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
183 5b237745 Scott Ullrich
				    <?=$p1_ealgos[$ipsecent['p1']['encryption-algorithm']];?>
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_halgos[$ipsecent['p1']['hash-algorithm']];?>
187
                  <?=$spane;?></td>
188 c62799be Scott Ullrich
                  <td class="listbg" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?><font color="#FFFFFF">
189 e2411886 Scott Ullrich
                    <?=htmlspecialchars($ipsecent['descr']);?>&nbsp;
190 5b237745 Scott Ullrich
                  <?=$spane;?></td>
191 d415d821 Seth Mos
                  <td valign="middle" nowrap class="list">
192
			<table border="0" cellspacing="0" cellpadding="1">
193
			     <tr>
194
				<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>
195
                    		<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>
196
			     </tr>
197
			     <tr>
198
				<td></td>
199
				<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>
200
			     </tr>
201
			</table>
202
		  </td>
203
		</tr>
204 e2411886 Scott Ullrich
			  <?php $i++; endforeach; ?>
205 574a2b47 Scott Ullrich
                <tr>
206 5b237745 Scott Ullrich
                  <td class="list" colspan="6"></td>
207 d415d821 Seth Mos
		  <td class="list">
208
			<table border="0" cellspacing="0" cellpadding="1">
209
			     <tr>
210
				<td width="17"></td>
211
				<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>
212
			     </tr>
213
			</table>
214
		  <td>
215
                </tr>
216 518887aa Seth Mos
		<tr>
217 d415d821 Seth Mos
		    <td colspan="4">
218 c55a8ab9 Holger Bauer
		      <p><span class="vexpl"><span class="red"><strong>Note:<br>
219 69e108df Chris Buechler
                      </strong></span>You can check your IPsec status at <a href="diag_ipsec_sad.php">Status:IPsec</a>.</span></p>
220 c55a8ab9 Holger Bauer
		  </td>
221 1256bba5 Seth Mos
		</tr>
222 5b237745 Scott Ullrich
              </table>
223 0f10aee4 Bill Marquette
	      </div>
224
  	  </td>
225 5b237745 Scott Ullrich
	</tr>
226
</table>
227
</form>
228
<?php include("fend.inc"); ?>
229 323d040b Scott Ullrich
</body>
230
</html>