Project

General

Profile

Download (8.8 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5
	vpn_ipsec.php
6 cfc707f7 Scott Ullrich
	Copyright (C) 2004 Scott Ullrich
7
	All rights reserved.
8 f0fe3d30 Scott Ullrich
9 cfc707f7 Scott Ullrich
	originally part of m0n0wall (http://m0n0.ch/wall)
10 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12 3da9a135 Scott Ullrich
13 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 f0fe3d30 Scott Ullrich
16 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 f0fe3d30 Scott Ullrich
19 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22 f0fe3d30 Scott Ullrich
23 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34
35
require("guiconfig.inc");
36
37
if (!is_array($config['ipsec']['tunnel'])) {
38
	$config['ipsec']['tunnel'] = array();
39
}
40
$a_ipsec = &$config['ipsec']['tunnel'];
41
42
$pconfig['enable'] = isset($config['ipsec']['enable']);
43 dacc4f59 Scott Ullrich
$pconfig['preferredoldsa'] = isset($config['ipsec']['preferredoldsa']);
44 3da9a135 Scott Ullrich
$pconfig['ipcomp'] = isset($config['ipsec']['ipcomp']);
45 5b237745 Scott Ullrich
46
if ($_POST) {
47
48
	if ($_POST['apply']) {
49
		$retval = 0;
50
		if (!file_exists($d_sysrebootreqd_path))
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 f0fe3d30 Scott Ullrich
60 5b237745 Scott Ullrich
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
61 dacc4f59 Scott Ullrich
		$config['ipsec']['preferredoldsa'] = $_POST['preferredoldsa'] ? true : false;
62 3da9a135 Scott Ullrich
		$config['ipsec']['ipcomp'] = $_POST['ipcomp'] ? true : false;
63 3216d4ba Scott Ullrich
		if($_POST['interface'] <> "")
64
			$config['ipsec']['interface'] = $_POST['interface'];
65 f0fe3d30 Scott Ullrich
66 5b237745 Scott Ullrich
		write_config();
67 f0fe3d30 Scott Ullrich
68 5b237745 Scott Ullrich
		$retval = 0;
69
		if (!file_exists($d_sysrebootreqd_path)) {
70
			config_lock();
71
			$retval = vpn_ipsec_configure();
72
			config_unlock();
73
		}
74
		$savemsg = get_std_save_message($retval);
75
		if ($retval == 0) {
76
			if (file_exists($d_ipsecconfdirty_path))
77
				unlink($d_ipsecconfdirty_path);
78
		}
79
	}
80
}
81
82
if ($_GET['act'] == "del") {
83
	if ($a_ipsec[$_GET['id']]) {
84
		unset($a_ipsec[$_GET['id']]);
85
		write_config();
86
		touch($d_ipsecconfdirty_path);
87
		header("Location: vpn_ipsec.php");
88
		exit;
89
	}
90
}
91
?>
92
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
93
<html>
94
<head>
95
<title><?=gentitle("VPN: IPsec");?></title>
96
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
97
<link href="gui.css" rel="stylesheet" type="text/css">
98
</head>
99
100
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
101
<?php include("fbegin.inc"); ?>
102
<p class="pgtitle">VPN: IPsec</p>
103
<form action="vpn_ipsec.php" method="post">
104
<?php if ($savemsg) print_info_box($savemsg); ?>
105
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
106
<?php 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>
107
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
108
<?php endif; ?>
109
<table width="100%" border="0" cellpadding="0" cellspacing="0">
110
  <tr><td>
111
  <ul id="tabnav">
112
    <li class="tabact">Tunnels</li>
113
    <li class="tabinact"><a href="vpn_ipsec_mobile.php">Mobile clients</a></li>
114
    <li class="tabinact"><a href="vpn_ipsec_keys.php">Pre-shared keys</a></li>
115
  </ul>
116
  </td></tr>
117 f0fe3d30 Scott Ullrich
  <tr>
118 5b237745 Scott Ullrich
    <td class="tabcont">
119 bafc1e3f Scott Ullrich
		<table width="100%" border="0" cellpadding="6" cellspacing="0">
120 f0fe3d30 Scott Ullrich
                <tr>
121
                  <td class="vtable"><p><span class="vexpl"> </span>
122 5b237745 Scott Ullrich
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?>>
123
                      <strong>Enable IPsec<br>
124 dacc4f59 Scott Ullrich
                      </strong></p>
125
		  </td>
126
		  <td class="vtable"><p><span class="vexpl"> </span>
127
		      <input name="preferredoldsa" type="checkbox" id="preferredoldsa" value="yes" <?php if ($pconfig['preferredoldsa'] == "yes") echo "checked";?>>
128
		      <strong>Prefer newer SA's.<br>
129
		      </strong></p>
130
		  </td>
131 3da9a135 Scott Ullrich
		  <td class="vtable"><p><span class="vexpl"> </span>
132
		      <input name="ipcomp" type="checkbox" id="ipcomp" value="yes" <?php if ($pconfig['ipcomp'] == "yes") echo "checked";?>>
133
		      <strong>Enable VPN IP Compression<br>
134
		      </strong></p>
135
		  </td>
136 f7ad479f Scott Ullrich
	         </tr>
137 f0fe3d30 Scott Ullrich
                <tr>
138
                  <td> <input name="submit" type="submit" class="formbtn" value="Save">
139 5b237745 Scott Ullrich
                  </td>
140
                </tr>
141
              </table>
142
              &nbsp;<br>
143
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
144
                <tr>
145
                  <td nowrap class="listhdrr">Local net<br>
146
                    Remote net</td>
147
                  <td class="listhdrr">Interface<br>Remote gw</td>
148
                  <td class="listhdrr">P1 mode</td>
149
                  <td class="listhdrr">P1 Enc. Algo</td>
150
                  <td class="listhdrr">P1 Hash Algo</td>
151
                  <td class="listhdr">Description</td>
152
                  <td class="list"></td>
153
				</tr>
154
                <?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 5f9c0e68 Bill Marquette
                  <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 5f9c0e68 Bill Marquette
                  <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
							  for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
176
								$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
177
							  $if = htmlspecialchars($iflabels[$ipsecent['interface']]);
178
						} else
179
							$if = "WAN";
180 f0fe3d30 Scott Ullrich
181 5b237745 Scott Ullrich
						echo $if . "<br>" . $ipsecent['remote-gateway'];
182
					?>
183
                  <?=$spane;?></td>
184 5f9c0e68 Bill Marquette
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>';"><?=$spans;?>
185 5b237745 Scott Ullrich
				    <?=$ipsecent['p1']['mode'];?>
186
                  <?=$spane;?></td>
187 5f9c0e68 Bill Marquette
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>';"><?=$spans;?>
188 5b237745 Scott Ullrich
				    <?=$p1_ealgos[$ipsecent['p1']['encryption-algorithm']];?>
189
                  <?=$spane;?></td>
190 5f9c0e68 Bill Marquette
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>';"><?=$spans;?>
191 5b237745 Scott Ullrich
				    <?=$p1_halgos[$ipsecent['p1']['hash-algorithm']];?>
192
                  <?=$spane;?></td>
193 5f9c0e68 Bill Marquette
                  <td class="listbg" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>';"><?=$spans;?>
194 f0fe3d30 Scott Ullrich
                    <font color="#FFFFFF"><?=htmlspecialchars($ipsecent['descr']);?>&nbsp;
195 5b237745 Scott Ullrich
                  <?=$spane;?></td>
196 a339c26a Bill Marquette
                  <td valign="middle" nowrap class="list">
197
                    <table border="0" cellspacing="0" cellpadding="1">
198
                      <tr>
199
                        <td valign="middle"><a href="vpn_ipsec_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a></td>
200
                        <td valign="middle"><a href="vpn_ipsec.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this tunnel?')"><img src="x.gif" width="17" height="17" border="0"></a></td>
201
                      </tr>
202
                    </table>
203
                  </td>
204
		</tr>
205
		<?php $i++; endforeach; ?>
206 f0fe3d30 Scott Ullrich
                <tr>
207 5b237745 Scott Ullrich
                  <td class="list" colspan="6"></td>
208 a339c26a Bill Marquette
                  <td class="list">
209
                    <table border="0" cellspacing="0" cellpadding="1">
210
                      <tr>
211
                        <td valign="middle"><a href="vpn_ipsec_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
212
                      </tr>
213
                    </table>
214
                  </td>
215
		</tr>
216 5b237745 Scott Ullrich
              </table>
217 a339c26a Bill Marquette
	    </td>
218 5b237745 Scott Ullrich
	</tr>
219
</table>
220
</form>
221
<?php include("fend.inc"); ?>
222
</body>
223
</html>