Project

General

Profile

Download (13.1 KB) Statistics
| Branch: | Tag: | Revision:
1 3818935a Scott Ullrich
<?php
2
/*
3
	vpn_pppoe.php
4
	part of pfSense
5
	
6
	Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
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['pppoe']['radius'])) {
34
	$config['pppoe']['radius'] = array();
35
}
36
$pppoecfg = &$config['pppoe'];
37
38
$pconfig['remoteip'] = $pppoecfg['remoteip'];
39
$pconfig['localip'] = $pppoecfg['localip'];
40
$pconfig['mode'] = $pppoecfg['mode'];
41 83773ab0 Scott Ullrich
$pconfig['interface'] = $pppoecfg['interface'];
42 3818935a Scott Ullrich
$pconfig['radiusenable'] = isset($pppoecfg['radius']['enable']);
43
$pconfig['radacct_enable'] = isset($pppoecfg['radius']['accounting']);
44
$pconfig['radiusserver'] = $pppoecfg['radius']['server'];
45
$pconfig['radiussecret'] = $pppoecfg['radius']['secret'];
46 4b128721 Scott Ullrich
$pconfig['radiusissueips'] = isset($pppoecfg['radius']['radiusissueips']);
47 a429d105 Scott Ullrich
$pconfig['n_pppoe_units'] = $pppoecfg['n_pppoe_units'];
48 3818935a Scott Ullrich
49
if ($_POST) {
50
51
	unset($input_errors);
52
	$pconfig = $_POST;
53
54
	/* input validation */
55
	if ($_POST['mode'] == "server") {
56
		$reqdfields = explode(" ", "localip remoteip");
57
		$reqdfieldsn = explode(",", "Server address,Remote start address");
58
		
59
		if ($_POST['radiusenable']) {
60
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
61
			$reqdfieldsn = array_merge($reqdfieldsn, 
62
				explode(",", "RADIUS server address,RADIUS shared secret"));
63
		}
64
		
65
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
66
		
67
		if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) {
68
			$input_errors[] = "A valid server address must be specified.";
69
		}
70
		if (($_POST['subnet'] && !is_ipaddr($_POST['remoteip']))) {
71
			$input_errors[] = "A valid remote start address must be specified.";
72
		}
73
		if (($_POST['radiusserver'] && !is_ipaddr($_POST['radiusserver']))) {
74
			$input_errors[] = "A valid RADIUS server address must be specified.";
75
		}
76
		
77
		if (!$input_errors) {	
78
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $g['pppoe_subnet']);
79
			$subnet_start = ip2long($_POST['remoteip']);
80
			$subnet_end = ip2long($_POST['remoteip']) + $g['n_pppoe_units'] - 1;
81
						
82
			if ((ip2long($_POST['localip']) >= $subnet_start) && 
83
			    (ip2long($_POST['localip']) <= $subnet_end)) {
84
				$input_errors[] = "The specified server address lies in the remote subnet.";	
85
			}
86
			if ($_POST['localip'] == $config['interfaces']['lan']['ipaddr']) {
87
				$input_errors[] = "The specified server address is equal to the LAN interface address.";	
88
			}
89
		}
90 e09def9e Scott Ullrich
	} else {
91
		/* turning pppoe off, lets dump any custom rules */
92
		$rules = &$config['filter']['rule'];
93
		for($x=0; $x<count($rules); $x++) {
94
			if($rules[$x]['interface'] == "pppoe") { 
95
				unset($rules[$x]);
96
			}
97
		}
98 7446b407 Scott Ullrich
		unset($config['pppoe']);
99 e09def9e Scott Ullrich
		write_config();		
100 3818935a Scott Ullrich
	}
101 3e73f3a8 Scott Ullrich
	
102 3818935a Scott Ullrich
	if (!$input_errors) {
103
		$pppoecfg['remoteip'] = $_POST['remoteip'];
104
		$pppoecfg['localip'] = $_POST['localip'];
105
		$pppoecfg['mode'] = $_POST['mode'];
106 83773ab0 Scott Ullrich
		$pppoecfg['interface'] = $_POST['interface'];
107 a429d105 Scott Ullrich
		$pppoecfg['n_pppoe_units'] = $_POST['n_pppoe_units'];	
108 33eaec88 Scott Ullrich
109 3818935a Scott Ullrich
		$pppoecfg['radius']['server'] = $_POST['radiusserver'];
110
		$pppoecfg['radius']['secret'] = $_POST['radiussecret'];
111 83773ab0 Scott Ullrich
112 33eaec88 Scott Ullrich
		if($_POST['radiusenable'] == "yes")
113
			$pppoecfg['radius']['enable'] = true;
114
		else
115
			unset($pppoecfg['radius']['enable']);
116
			
117
		if($_POST['radacct_enable'] == "yes")
118
			$pppoecfg['radius']['accounting'] = true;
119
		else
120
			unset($pppoecfg['radius']['accounting']);
121
122 4b128721 Scott Ullrich
		if($_POST['radiusissueips'] == "yes") {
123 5dfdc1fb Scott Ullrich
			$pppoecfg['radius']['radiusissueips'] = true;
124 4b128721 Scott Ullrich
		} else
125 5dfdc1fb Scott Ullrich
			unset($pppoecfg['radius']['radiusissueips']);
126
127 3818935a Scott Ullrich
		write_config();
128
		
129
		$retval = 0;
130
		
131
		config_lock();
132 88964924 Scott Ullrich
		$retval = vpn_setup();
133 3818935a Scott Ullrich
		config_unlock();
134
		
135
		$savemsg = get_std_save_message($retval);
136
	}
137
}
138
139 bffce1dc Scott Ullrich
$pgtitle = "VPN: PPPoE";
140 3818935a Scott Ullrich
include("head.inc");
141
142
?>
143
144
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
145
<?php include("fbegin.inc"); ?>
146
<p class="pgtitle"><?=$pgtitle?></p>
147
<script language="JavaScript">
148
<!--
149
function get_radio_value(obj)
150
{
151
	for (i = 0; i < obj.length; i++) {
152
		if (obj[i].checked)
153
			return obj[i].value;
154
	}
155
	return null;
156
}
157
158
function enable_change(enable_over) {
159
	if ((get_radio_value(document.iform.mode) == "server") || enable_over) {
160
		document.iform.remoteip.disabled = 0;
161
		document.iform.localip.disabled = 0;
162
		document.iform.radiusenable.disabled = 0;
163 4b128721 Scott Ullrich
		document.iform.radiusissueips.disabled = 0;
164 5287f0e6 Scott Ullrich
		document.iform.interface.disabled = 0;
165
		document.iform.n_pppoe_units.disabled = 0;		
166 3818935a Scott Ullrich
		if (document.iform.radiusenable.checked || enable_over) {
167
			document.iform.radacct_enable.disabled = 0;
168
			document.iform.radiusserver.disabled = 0;
169
			document.iform.radiussecret.disabled = 0;
170 4b128721 Scott Ullrich
			document.iform.radiusissueips.disabled = 0;
171 3818935a Scott Ullrich
		} else {
172
			document.iform.radacct_enable.disabled = 1;
173
			document.iform.radiusserver.disabled = 1;
174
			document.iform.radiussecret.disabled = 1;
175 4b128721 Scott Ullrich
			document.iform.radiusissueips.disabled = 1;
176 3818935a Scott Ullrich
		}
177
	} else {
178 5287f0e6 Scott Ullrich
		document.iform.interface.disabled = 1;
179
		document.iform.n_pppoe_units.disabled = 1;		
180 3818935a Scott Ullrich
		document.iform.remoteip.disabled = 1;
181
		document.iform.localip.disabled = 1;
182
		document.iform.radiusenable.disabled = 1;
183
		document.iform.radacct_enable.disabled = 1;
184
		document.iform.radiusserver.disabled = 1;
185
		document.iform.radiussecret.disabled = 1;
186 4b128721 Scott Ullrich
		document.iform.radiusissueips.disabled = 1;
187 3818935a Scott Ullrich
	}
188
}
189
//-->
190
</script>
191
<form action="vpn_pppoe.php" method="post" name="iform" id="iform">
192
<?php if ($input_errors) print_input_errors($input_errors); ?>
193
<?php if ($savemsg) print_info_box($savemsg); ?>
194
<table width="100%" border="0" cellpadding="0" cellspacing="0">
195
  <tr><td class="tabnavtbl">
196
<?php
197
	$tab_array = array();
198
	$tab_array[0] = array("Configuration", true, "vpn_pppoe.php");
199
	$tab_array[1] = array("Users", false, "vpn_pppoe_users.php");
200
	display_top_tabs($tab_array);
201
?>  
202
  </td></tr>
203
  <tr> 
204
    <td>
205 3e73f3a8 Scott Ullrich
	<div id="mainarea">
206 3818935a Scott Ullrich
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
207
                <tr> 
208
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
209
                  <td width="78%" class="vtable"> 
210
                    <input name="mode" type="radio" onclick="enable_change(false)" value="off"
211
				  	<?php if (($pconfig['mode'] != "server") && ($pconfig['mode'] != "redir")) echo "checked";?>>
212
                    Off</td>
213 3e73f3a8 Scott Ullrich
		</tr>
214 3818935a Scott Ullrich
                <tr> 
215
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
216
                  <td width="78%" class="vtable">
217 3e73f3a8 Scott Ullrich
		    <input type="radio" name="mode" value="server" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "server") echo "checked"; ?>>
218 3818935a Scott Ullrich
                    Enable PPPoE server</td>
219 3e73f3a8 Scott Ullrich
		</tr>
220
221 64391455 Scott Ullrich
                <tr> 
222
                  <td width="22%" valign="top" class="vncell"><b>Interface</b></td>
223
                  <td width="78%" valign="top" class="vtable">
224
225
			<select name="interface" class="formfld" id="interface">
226
			  <?php
227
				$interfaces = array('lan' => 'LAN', 'wan' => 'WAN');
228
				for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
229
				      if (isset($config['interfaces']['opt' . $i]['enable']))
230
					      $interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
231
				}
232
				foreach ($interfaces as $iface => $ifacename):
233
			  ?>
234
			  <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
235
			  <?=htmlspecialchars($ifacename);?>
236
			  </option>
237
			  <?php endforeach; ?>
238
			</select> <br>			
239
                      
240
		  </td>
241
                </tr>
242 3818935a Scott Ullrich
                <tr> 
243 c0503ad3 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Subnet netmask</td>
244 a429d105 Scott Ullrich
                  <td width="78%" class="vtable">
245 50667263 Scott Ullrich
		    <select id="n_pppoe_units" name="n_pppoe_units">
246 a429d105 Scott Ullrich
		    <?php
247
		     for($x=0; $x<33; $x++) {
248
			if($x == $pconfig['n_pppoe_units'])
249
				$SELECTED = " SELECTED";
250
			else
251
				$SELECTED = "";
252 50667263 Scott Ullrich
			echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";			
253 a429d105 Scott Ullrich
		     }
254
		    ?>
255
		    </select>
256 c0503ad3 Scott Ullrich
		    <br>Hint: 24 is 255.255.255.0
257 3818935a Scott Ullrich
                  </td>
258 3e73f3a8 Scott Ullrich
		</tr>
259 3818935a Scott Ullrich
                <tr> 
260
                  <td width="22%" valign="top" class="vncellreq">Server address</td>
261
                  <td width="78%" class="vtable"> 
262
                    <?=$mandfldhtml;?><input name="localip" type="text" class="formfld" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>"> 
263
                    <br>
264
                    Enter the IP address the PPPoE server should use on its side 
265
                    for all clients.</td>
266
                </tr>
267
                <tr> 
268 3e73f3a8 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Remote address range</td>
269 3818935a Scott Ullrich
                  <td width="78%" class="vtable"> 
270
                    <?=$mandfldhtml;?><input name="remoteip" type="text" class="formfld" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>">
271
                    <br>
272
                    Specify the starting address for the client IP address subnet.<br>
273 aa58165b Scott Ullrich
                    </td>
274 3818935a Scott Ullrich
                </tr>
275 3e73f3a8 Scott Ullrich
276 3818935a Scott Ullrich
                <tr> 
277
                  <td width="22%" valign="top" class="vncell">RADIUS</td>
278
                  <td width="78%" class="vtable"> 
279
                      <input name="radiusenable" type="checkbox" id="radiusenable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radiusenable']) echo "checked"; ?>>
280
                      <strong>Use a RADIUS server for authentication<br>
281
                      </strong>When set, all users will be authenticated using 
282
                      the RADIUS server specified below. The local user database 
283
                      will not be used.<br>
284
                      <br>
285
                      <input name="radacct_enable" type="checkbox" id="radacct_enable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radacct_enable']) echo "checked"; ?>>
286
                      <strong>Enable RADIUS accounting <br>
287
                      </strong>Sends accounting packets to the RADIUS server.</td>
288
                </tr>
289
                <tr> 
290
                  <td width="22%" valign="top" class="vncell">RADIUS server </td>
291
                  <td width="78%" class="vtable">
292
                      <input name="radiusserver" type="text" class="formfld" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>">
293
                      <br>
294
                      Enter the IP address of the RADIUS server.</td>
295
                </tr>
296
                <tr> 
297
                  <td width="22%" valign="top" class="vncell">RADIUS shared secret</td>
298
                  <td width="78%" valign="top" class="vtable">
299
                      <input name="radiussecret" type="password" class="formfld" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>">
300
                      <br>
301
                      Enter the shared secret that will be used to authenticate 
302
                      to the RADIUS server.</td>
303
                </tr>
304 5dfdc1fb Scott Ullrich
                <tr> 
305
                  <td width="22%" valign="top" class="vncell">RADIUS issued IP's</td>
306
                  <td width="78%" valign="top" class="vtable">
307 4b128721 Scott Ullrich
                      <input name="radiusissueips" value="yes" type="checkbox" class="formfld" id="radiusissueips"<?php if($pconfig['radiusissueips']) echo " CHECKED"; ?>>
308 5dfdc1fb Scott Ullrich
                      <br>Issue IP Addresses via RADIUS server.
309
                      
310
                  </td>
311
                </tr>		
312 3818935a Scott Ullrich
                <tr> 
313
                  <td height="16" colspan="2" valign="top"></td>
314
                </tr>
315
                <tr> 
316
                  <td width="22%" valign="top">&nbsp;</td>
317
                  <td width="78%"> 
318
                    <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)"> 
319
                  </td>
320
                </tr>
321
                <tr> 
322
                  <td width="22%" valign="top">&nbsp;</td>
323
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
324
                    </strong></span>don't forget to add a firewall rule to permit 
325
                    traffic from PPPoE clients!</span></td>
326
                </tr>
327
              </table>
328 3e73f3a8 Scott Ullrich
	   </div>
329
	 </td>
330 3818935a Scott Ullrich
	</tr>
331
</table>
332
</form>
333
<script language="JavaScript">
334
<!--
335
enable_change(false);
336
//-->
337
</script>
338
<?php include("fend.inc"); ?>
339
</body>
340
</html>