Project

General

Profile

Download (13.8 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
$pconfig['pppoe_subnet'] = $pppoecfg['pppoe_subnet'];
49

    
50
if ($_POST) {
51

    
52
	unset($input_errors);
53
	$pconfig = $_POST;
54

    
55
	/* input validation */
56
	if ($_POST['mode'] == "server") {
57
		$reqdfields = explode(" ", "localip remoteip");
58
		$reqdfieldsn = explode(",", "Server address,Remote start address");
59
		
60
		if ($_POST['radiusenable']) {
61
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
62
			$reqdfieldsn = array_merge($reqdfieldsn, 
63
				explode(",", "RADIUS server address,RADIUS shared secret"));
64
		}
65
		
66
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
67
		
68
		if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) {
69
			$input_errors[] = "A valid server address must be specified.";
70
		}
71
		if (($_POST['subnet'] && !is_ipaddr($_POST['remoteip']))) {
72
			$input_errors[] = "A valid remote start address must be specified.";
73
		}
74
		if (($_POST['radiusserver'] && !is_ipaddr($_POST['radiusserver']))) {
75
			$input_errors[] = "A valid RADIUS server address must be specified.";
76
		}
77
		
78
		if (!$input_errors) {	
79
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $g['pppoe_subnet']);
80
			$subnet_start = ip2long($_POST['remoteip']);
81
			$subnet_end = ip2long($_POST['remoteip']) + $g['pppoe_subnet'] - 1;
82
						
83
			if ((ip2long($_POST['localip']) >= $subnet_start) && 
84
			    (ip2long($_POST['localip']) <= $subnet_end)) {
85
				$input_errors[] = "The specified server address lies in the remote subnet.";	
86
			}
87
			if ($_POST['localip'] == $config['interfaces']['lan']['ipaddr']) {
88
				$input_errors[] = "The specified server address is equal to the LAN interface address.";	
89
			}
90
		}
91
	} else {
92
		/* turning pppoe off, lets dump any custom rules */
93
		$rules = &$config['filter']['rule'];
94
		for($x=0; $x<count($rules); $x++) {
95
			if($rules[$x]['interface'] == "pppoe") { 
96
				unset($rules[$x]);
97
			}
98
		}
99
		unset($config['pppoe']);
100
		write_config();		
101
	}
102
	
103
	if (!$input_errors) {
104
		$pppoecfg['remoteip'] = $_POST['remoteip'];
105
		$pppoecfg['localip'] = $_POST['localip'];
106
		$pppoecfg['mode'] = $_POST['mode'];
107
		$pppoecfg['interface'] = $_POST['interface'];
108
		$pppoecfg['n_pppoe_units'] = $_POST['n_pppoe_units'];	
109
		$pppoecfg['pppoe_subnet'] = $_POST['pppoe_subnet'];
110
		$pppoecfg['radius']['server'] = $_POST['radiusserver'];
111
		$pppoecfg['radius']['secret'] = $_POST['radiussecret'];
112

    
113
		if($_POST['radiusenable'] == "yes")
114
			$pppoecfg['radius']['enable'] = true;
115
		else
116
			unset($pppoecfg['radius']['enable']);
117
			
118
		if($_POST['radacct_enable'] == "yes")
119
			$pppoecfg['radius']['accounting'] = true;
120
		else
121
			unset($pppoecfg['radius']['accounting']);
122

    
123
		if($_POST['radiusissueips'] == "yes") {
124
			$pppoecfg['radius']['radiusissueips'] = true;
125
		} else
126
			unset($pppoecfg['radius']['radiusissueips']);
127

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

    
140
$pgtitle = "Services: PPPoE";
141
include("head.inc");
142

    
143
?>
144

    
145
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
146
<?php include("fbegin.inc"); ?>
147
<p class="pgtitle"><?=$pgtitle?></p>
148
<script language="JavaScript">
149
<!--
150
function get_radio_value(obj)
151
{
152
	for (i = 0; i < obj.length; i++) {
153
		if (obj[i].checked)
154
			return obj[i].value;
155
	}
156
	return null;
157
}
158

    
159
function enable_change(enable_over) {
160
	if ((get_radio_value(document.iform.mode) == "server") || enable_over) {
161
		document.iform.remoteip.disabled = 0;
162
		document.iform.localip.disabled = 0;
163
		document.iform.radiusenable.disabled = 0;
164
		document.iform.radiusissueips.disabled = 0;
165
		document.iform.interface.disabled = 0;
166
		document.iform.n_pppoe_units.disabled = 0;		
167
		document.iform.pppoe_subnet.disabled = 0;		
168
		if (document.iform.radiusenable.checked || enable_over) {
169
			document.iform.radacct_enable.disabled = 0;
170
			document.iform.radiusserver.disabled = 0;
171
			document.iform.radiussecret.disabled = 0;
172
			document.iform.radiusissueips.disabled = 0;
173
		} else {
174
			document.iform.radacct_enable.disabled = 1;
175
			document.iform.radiusserver.disabled = 1;
176
			document.iform.radiussecret.disabled = 1;
177
			document.iform.radiusissueips.disabled = 1;
178
		}
179
	} else {
180
		document.iform.interface.disabled = 1;
181
		document.iform.n_pppoe_units.disabled = 1;		
182
		document.iform.pppoe_subnet.disabled = 1;		
183
		document.iform.remoteip.disabled = 1;
184
		document.iform.localip.disabled = 1;
185
		document.iform.radiusenable.disabled = 1;
186
		document.iform.radacct_enable.disabled = 1;
187
		document.iform.radiusserver.disabled = 1;
188
		document.iform.radiussecret.disabled = 1;
189
		document.iform.radiusissueips.disabled = 1;
190
	}
191
}
192
//-->
193
</script>
194
<form action="vpn_pppoe.php" method="post" name="iform" id="iform">
195
<?php if ($input_errors) print_input_errors($input_errors); ?>
196
<?php if ($savemsg) print_info_box($savemsg); ?>
197
<table width="100%" border="0" cellpadding="0" cellspacing="0">
198
  <tr><td class="tabnavtbl">
199
<?php
200
	$tab_array = array();
201
	$tab_array[0] = array("Configuration", true, "vpn_pppoe.php");
202
	$tab_array[1] = array("Users", false, "vpn_pppoe_users.php");
203
	display_top_tabs($tab_array);
204
?>  
205
  </td></tr>
206
  <tr> 
207
    <td>
208
	<div id="mainarea">
209
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
210
                <tr> 
211
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
212
                  <td width="78%" class="vtable"> 
213
                    <input name="mode" type="radio" onclick="enable_change(false)" value="off"
214
				  	<?php if (($pconfig['mode'] != "server") && ($pconfig['mode'] != "redir")) echo "checked";?>>
215
                    Off</td>
216
		</tr>
217
                <tr> 
218
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
219
                  <td width="78%" class="vtable">
220
		    <input type="radio" name="mode" value="server" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "server") echo "checked"; ?>>
221
                    Enable PPPoE server</td>
222
		</tr>
223

    
224
                <tr> 
225
                  <td width="22%" valign="top" class="vncell"><b>Interface</b></td>
226
                  <td width="78%" valign="top" class="vtable">
227

    
228
			<select name="interface" class="formfld" id="interface">
229
			  <?php
230
				$interfaces = array('lan' => 'LAN', 'wan' => 'WAN');
231
				for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
232
				      if (isset($config['interfaces']['opt' . $i]['enable']))
233
					      $interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
234
				}
235
				foreach ($interfaces as $iface => $ifacename):
236
			  ?>
237
			  <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
238
			  <?=htmlspecialchars($ifacename);?>
239
			  </option>
240
			  <?php endforeach; ?>
241
			</select> <br>			
242
                      
243
		  </td>
244
                </tr>
245
                <tr> 
246
                  <td width="22%" valign="top" class="vncellreq">Subnet netmask</td>
247
                  <td width="78%" class="vtable">
248
		    <select id="pppoe_subnet" name="pppoe_subnet">
249
		    <?php
250
		     for($x=0; $x<33; $x++) {
251
			if($x == $pconfig['pppoe_subnet'])
252
				$SELECTED = " SELECTED";
253
			else
254
				$SELECTED = "";
255
			echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";			
256
		     }
257
		    ?>
258
		    </select>
259
		    <br>Hint: 24 is 255.255.255.0
260
                  </td>
261
		</tr>
262
                <tr> 
263
                  <td width="22%" valign="top" class="vncellreq">Number of PPPoE users</td>
264
                  <td width="78%" class="vtable">
265
		    <select id="n_pppoe_units" name="n_pppoe_units">
266
		    <?php
267
		     for($x=0; $x<255; $x++) {
268
			if($x == $pconfig['n_pppoe_units'])
269
				$SELECTED = " SELECTED";
270
			else
271
				$SELECTED = "";
272
			echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";			
273
		     }
274
		    ?>
275
		    </select>
276
		    <br>Hint: 10 is ten PPPoE clients
277
                  </td>
278
		</tr>
279
                <tr> 
280
                  <td width="22%" valign="top" class="vncellreq">Server address</td>
281
                  <td width="78%" class="vtable"> 
282
                    <?=$mandfldhtml;?><input name="localip" type="text" class="formfld" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>"> 
283
                    <br>
284
                    Enter the IP address the PPPoE server should use on its side 
285
                    for all clients.</td>
286
                </tr>
287
                <tr> 
288
                  <td width="22%" valign="top" class="vncellreq">Remote address range</td>
289
                  <td width="78%" class="vtable"> 
290
                    <?=$mandfldhtml;?><input name="remoteip" type="text" class="formfld" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>">
291
                    <br>
292
                    Specify the starting address for the client IP address subnet.<br>
293
                    </td>
294
                </tr>
295

    
296
                <tr> 
297
                  <td width="22%" valign="top" class="vncell">RADIUS</td>
298
                  <td width="78%" class="vtable"> 
299
                      <input name="radiusenable" type="checkbox" id="radiusenable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radiusenable']) echo "checked"; ?>>
300
                      <strong>Use a RADIUS server for authentication<br>
301
                      </strong>When set, all users will be authenticated using 
302
                      the RADIUS server specified below. The local user database 
303
                      will not be used.<br>
304
                      <br>
305
                      <input name="radacct_enable" type="checkbox" id="radacct_enable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radacct_enable']) echo "checked"; ?>>
306
                      <strong>Enable RADIUS accounting <br>
307
                      </strong>Sends accounting packets to the RADIUS server.</td>
308
                </tr>
309
                <tr> 
310
                  <td width="22%" valign="top" class="vncell">RADIUS server </td>
311
                  <td width="78%" class="vtable">
312
                      <input name="radiusserver" type="text" class="formfld" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>">
313
                      <br>
314
                      Enter the IP address of the RADIUS server.</td>
315
                </tr>
316
                <tr> 
317
                  <td width="22%" valign="top" class="vncell">RADIUS shared secret</td>
318
                  <td width="78%" valign="top" class="vtable">
319
                      <input name="radiussecret" type="password" class="formfld" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>">
320
                      <br>
321
                      Enter the shared secret that will be used to authenticate 
322
                      to the RADIUS server.</td>
323
                </tr>
324
                <tr> 
325
                  <td width="22%" valign="top" class="vncell">RADIUS issued IPs</td>
326
                  <td width="78%" valign="top" class="vtable">
327
                      <input name="radiusissueips" value="yes" type="checkbox" class="formfld" id="radiusissueips"<?php if($pconfig['radiusissueips']) echo " CHECKED"; ?>>
328
                      <br>Issue IP Addresses via RADIUS server.
329
                      
330
                  </td>
331
                </tr>		
332
                <tr> 
333
                  <td height="16" colspan="2" valign="top"></td>
334
                </tr>
335
                <tr> 
336
                  <td width="22%" valign="top">&nbsp;</td>
337
                  <td width="78%"> 
338
                    <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)"> 
339
                  </td>
340
                </tr>
341
                <tr> 
342
                  <td width="22%" valign="top">&nbsp;</td>
343
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
344
                    </strong></span>Don't forget to add a firewall rule to permit 
345
                    traffic from PPPoE clients!</span></td>
346
                </tr>
347
              </table>
348
	   </div>
349
	 </td>
350
	</tr>
351
</table>
352
</form>
353
<script language="JavaScript">
354
<!--
355
enable_change(false);
356
//-->
357
</script>
358
<?php include("fend.inc"); ?>
359
</body>
360
</html>
(169-169/176)