Project

General

Profile

Download (8.79 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	vpn_ipsec.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5

    
6
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
7
	All rights reserved.
8

    
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11

    
12
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14

    
15
	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

    
19
	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
$wancfg = &$config['interfaces']['wan'];
38

    
39
$pconfig['enable'] = isset($config['ipsec']['enable']);
40
$pconfig['ipcomp'] = isset($config['ipsec']['ipcomp']);
41

    
42
if ($_POST) {
43

    
44
	if ($_POST['apply']) {
45
		$retval = 0;
46
		$retval = vpn_ipsec_configure();
47
		$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

    
55
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
56
		$config['ipsec']['ipcomp'] = $_POST['ipcomp'] ? true : false;
57
		
58
		write_config();
59

    
60
		$retval = 0;
61
		config_lock();
62
		$retval = vpn_ipsec_configure();
63
		config_unlock();
64
		/* reload the filter in the background */
65
		filter_configure();
66

    
67
		$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
		unset($a_ipsec[$_GET['id']]);
78
		filter_configure();
79
		write_config();
80
		header("Location: vpn_ipsec.php");
81
		exit;
82
	}
83
}
84

    
85
$pgtitle = array("VPN","IPsec");
86
include("head.inc");
87

    
88
?>
89

    
90

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

    
174
						echo $if . "<br>" . $ipsecent['remote-gateway'];
175
					?>
176
                  <?=$spane;?></td>
177
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
178
				    <?=$ipsecent['p1']['mode'];?>
179
                  <?=$spane;?></td>
180
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
181
				    <?=$p1_ealgos[$ipsecent['p1']['encryption-algorithm']];?>
182
                  <?=$spane;?></td>
183
                  <td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
184
				    <?=$p1_halgos[$ipsecent['p1']['hash-algorithm']];?>
185
                  <?=$spane;?></td>
186
                  <td class="listbg" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?><font color="#FFFFFF">
187
                    <?=htmlspecialchars($ipsecent['descr']);?>&nbsp;
188
                  <?=$spane;?></td>
189
                  <td valign="middle" nowrap class="list">
190
			<table border="0" cellspacing="0" cellpadding="1">
191
			     <tr>
192
				<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>
193
                    		<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>
194
			     </tr>
195
			     <tr>
196
				<td></td>
197
				<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>
198
			     </tr>
199
			</table>
200
		  </td>
201
		</tr>
202
			  <?php $i++; endforeach; ?>
203
                <tr>
204
                  <td class="list" colspan="6"></td>
205
		  <td class="list">
206
			<table border="0" cellspacing="0" cellpadding="1">
207
			     <tr>
208
				<td width="17"></td>
209
				<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>
210
			     </tr>
211
			</table>
212
		  <td>
213
                </tr>
214
		<tr>
215
		    <td colspan="4">
216
		      <p><span class="vexpl"><span class="red"><strong>Note:<br>
217
                      </strong></span>You can check your IPsec status at <a href="diag_ipsec_sad.php">Status:IPsec</a>.</span></p>
218
		  </td>
219
		</tr>
220
              </table>
221
	      </div>
222
  	  </td>
223
	</tr>
224
</table>
225
</form>
226
<?php include("fend.inc"); ?>
227
</body>
228
</html>
(164-164/189)