Project

General

Profile

Download (13.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
$pconfig['interface'] = $pppoecfg['interface'];
42
$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
$pconfig['radiusissueips'] = isset($pppoecfg['radius']['radiusissueips']);
47
$pconfig['n_pppoe_units'] = $pppoecfg['n_pppoe_units'];
48

    
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
	} 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
		unset($config['pppoe']);
99
		write_config();		
100
	}
101
	
102
	if (!$input_errors) {
103
		$pppoecfg['remoteip'] = $_POST['remoteip'];
104
		$pppoecfg['localip'] = $_POST['localip'];
105
		$pppoecfg['mode'] = $_POST['mode'];
106
		$pppoecfg['interface'] = $_POST['interface'];
107
		$pppoecfg['n_pppoe_units'] = $_POST['n_pppoe_units'];	
108

    
109
		$pppoecfg['radius']['server'] = $_POST['radiusserver'];
110
		$pppoecfg['radius']['secret'] = $_POST['radiussecret'];
111

    
112
		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
		if($_POST['radiusissueips'] == "yes") {
123
			$pppoecfg['radius']['radiusissueips'] = true;
124
		} else
125
			unset($pppoecfg['radius']['radiusissueips']);
126

    
127
		write_config();
128
		
129
		$retval = 0;
130
		
131
		config_lock();
132
		$retval = vpn_setup();
133
		config_unlock();
134
		
135
		$savemsg = get_std_save_message($retval);
136
	}
137
}
138

    
139
$pgtitle = "VPN: PPPoE";
140
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
		document.iform.radiusissueips.disabled = 0;
164
		document.iform.interface.disabled = 0;
165
		document.iform.n_pppoe_units.disabled = 0;		
166
		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
			document.iform.radiusissueips.disabled = 0;
171
		} else {
172
			document.iform.radacct_enable.disabled = 1;
173
			document.iform.radiusserver.disabled = 1;
174
			document.iform.radiussecret.disabled = 1;
175
			document.iform.radiusissueips.disabled = 1;
176
		}
177
	} else {
178
		document.iform.interface.disabled = 1;
179
		document.iform.n_pppoe_units.disabled = 1;		
180
		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
		document.iform.radiusissueips.disabled = 1;
187
	}
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
	<div id="mainarea">
206
              <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
		</tr>
214
                <tr> 
215
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
216
                  <td width="78%" class="vtable">
217
		    <input type="radio" name="mode" value="server" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "server") echo "checked"; ?>>
218
                    Enable PPPoE server</td>
219
		</tr>
220

    
221
                <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
                <tr> 
243
                  <td width="22%" valign="top" class="vncellreq">Subnet netmask</td>
244
                  <td width="78%" class="vtable">
245
		    <select id="n_pppoe_units" name="n_pppoe_units">
246
		    <?php
247
		     for($x=0; $x<33; $x++) {
248
			if($x == $pconfig['n_pppoe_units'])
249
				$SELECTED = " SELECTED";
250
			else
251
				$SELECTED = "";
252
			echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";			
253
		     }
254
		    ?>
255
		    </select>
256
		    <br>Hint: 24 is 255.255.255.0
257
                  </td>
258
		</tr>
259
                <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
                  <td width="22%" valign="top" class="vncellreq">Remote address range</td>
269
                  <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
                    </td>
274
                </tr>
275

    
276
                <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
                <tr> 
305
                  <td width="22%" valign="top" class="vncell">RADIUS issued IP's</td>
306
                  <td width="78%" valign="top" class="vtable">
307
                      <input name="radiusissueips" value="yes" type="checkbox" class="formfld" id="radiusissueips"<?php if($pconfig['radiusissueips']) echo " CHECKED"; ?>>
308
                      <br>Issue IP Addresses via RADIUS server.
309
                      
310
                  </td>
311
                </tr>		
312
                <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
	   </div>
329
	 </td>
330
	</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>
(157-157/164)