Project

General

Profile

Download (7.55 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	vpn_ipsec.php
5
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11
	
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

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

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

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

    
34
require("guiconfig.inc");
35

    
36
if (!is_array($config['ipsec']['tunnel'])) {
37
	$config['ipsec']['tunnel'] = array();
38
}
39
$a_ipsec = &$config['ipsec']['tunnel'];
40
$wancfg = &$config['interfaces']['wan'];
41

    
42
$pconfig['enable'] = isset($config['ipsec']['enable']);
43
$pconfig['preferredoldsa'] = isset($config['ipsec']['preferredoldsa']);
44

    
45
if ($_POST) {
46

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

    
59
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
60
		$config['ipsec']['preferredoldsa'] = $_POST['preferredoldsa'] ? true : false;
61

    
62
		write_config();
63

    
64
		$retval = 0;
65
		if (!file_exists($d_sysrebootreqd_path)) {
66
			config_lock();
67
			$retval = vpn_ipsec_configure();
68
			config_unlock();
69
		}
70
		$savemsg = get_std_save_message($retval);
71
		if ($retval == 0) {
72
			if (file_exists($d_ipsecconfdirty_path))
73
				unlink($d_ipsecconfdirty_path);
74
		}
75
	}
76
}
77

    
78
if ($_GET['act'] == "del") {
79
	if ($a_ipsec[$_GET['id']]) {
80
		unset($a_ipsec[$_GET['id']]);
81
		write_config();
82
		touch($d_ipsecconfdirty_path);
83
		header("Location: vpn_ipsec.php");
84
		exit;
85
	}
86
}
87
?>
88
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
89
<html>
90
<head>
91
<title><?=gentitle("VPN: IPsec");?></title>
92
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
93
<link href="gui.css" rel="stylesheet" type="text/css">
94
</head>
95

    
96
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
97
<?php include("fbegin.inc"); ?>
98
<p class="pgtitle">VPN: IPsec</p>
99
<form action="vpn_ipsec.php" method="post">
100
<?php if ($savemsg) print_info_box($savemsg); ?>
101
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
102
<?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>
103
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
104
<?php endif; ?>
105
<table width="100%" border="0" cellpadding="0" cellspacing="0">
106
  <tr><td>
107
  <ul id="tabnav">
108
    <li class="tabact">Tunnels</li>
109
    <li class="tabinact"><a href="vpn_ipsec_mobile.php">Mobile clients</a></li>
110
    <li class="tabinact"><a href="vpn_ipsec_keys.php">Pre-shared keys</a></li>
111
  </ul>
112
  </td></tr>
113
  <tr>
114
    <td class="tabcont">
115
		<table width="100%" border="0" cellpadding="6" cellspacing="0">
116
                <tr>
117
                  <td class="vtable"><p><span class="vexpl"> </span>
118
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?>>
119
                      <strong>Enable IPsec<br>
120
                      </strong></p>
121
		  </td>
122
		  <td class="vtable"><p><span class="vexpl"> </span>
123
		      <input name="preferredoldsa" type="checkbox" id="preferredoldsa" value="yes" <?php if ($pconfig['preferredoldsa'] == "yes") echo "checked";?>>
124
		      <strong>Prefer newer SA's.<br>
125
		      </strong></p>
126
		  </td>
127
                </tr>
128
                <tr>
129
                  <td> <input name="submit" type="submit" class="formbtn" value="Save">
130
                  </td>
131
                </tr>
132
              </table>
133
              &nbsp;<br>
134
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
135
                <tr>
136
                  <td nowrap class="listhdrr">Local net<br>
137
                    Remote net</td>
138
                  <td class="listhdrr">Interface<br>Remote gw</td>
139
                  <td class="listhdrr">P1 mode</td>
140
                  <td class="listhdrr">P1 Enc. Algo</td>
141
                  <td class="listhdrr">P1 Hash Algo</td>
142
                  <td class="listhdr">Description</td>
143
                  <td class="list"></td>
144
				</tr>
145
                <?php $i = 0; foreach ($a_ipsec as $ipsecent):
146
					if (isset($ipsecent['disabled'])) {
147
						$spans = "<span class=\"gray\">";
148
						$spane = "</span>";
149
					} else {
150
						$spans = $spane = "";
151
					}
152
				?>
153
                <tr valign="top">
154
                  <td nowrap class="listlr"><?=$spans;?>
155
                    <?php	if ($ipsecent['local-subnet']['network'])
156
								echo strtoupper($ipsecent['local-subnet']['network']);
157
							else
158
								echo $ipsecent['local-subnet']['address'];
159
					?>
160
                    <br>
161
                    <?=$ipsecent['remote-subnet'];?>
162
                  <?=$spane;?></td>
163
                  <td class="listr"><?=$spans;?>
164
				  <?php if ($ipsecent['interface']) {
165
							$iflabels = array('lan' => 'LAN', 'wan' => 'WAN');
166
							  for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
167
								$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
168
							  $if = htmlspecialchars($iflabels[$ipsecent['interface']]);
169
						} else
170
							$if = "WAN";
171

    
172
						echo $if . "<br>" . $ipsecent['remote-gateway'];
173
					?>
174
                  <?=$spane;?></td>
175
                  <td class="listr"><?=$spans;?>
176
				    <?=$ipsecent['p1']['mode'];?>
177
                  <?=$spane;?></td>
178
                  <td class="listr"><?=$spans;?>
179
				    <?=$p1_ealgos[$ipsecent['p1']['encryption-algorithm']];?>
180
                  <?=$spane;?></td>
181
                  <td class="listr"><?=$spans;?>
182
				    <?=$p1_halgos[$ipsecent['p1']['hash-algorithm']];?>
183
                  <?=$spane;?></td>
184
                  <td class="listbg"><?=$spans;?>
185
                    <font color="#FFFFFF"><?=htmlspecialchars($ipsecent['descr']);?>&nbsp;
186
                  <?=$spane;?></td>
187
                  <td valign="middle" nowrap class="list"> <a href="vpn_ipsec_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a>
188
                    &nbsp;<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>
189
				</tr>
190
			  <?php $i++; endforeach; ?>
191
                <tr>
192
                  <td class="list" colspan="6"></td>
193
                  <td class="list"> <a href="vpn_ipsec_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
194
				</tr>
195
              </table>
196
			</td>
197
	</tr>
198
</table>
199
</form>
200
<?php include("fend.inc"); ?>
201
</body>
202
</html>
(87-87/99)