Project

General

Profile

Download (12.9 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
	}
91
	
92
	if (!$input_errors) {
93
		$pppoecfg['remoteip'] = $_POST['remoteip'];
94
		$pppoecfg['localip'] = $_POST['localip'];
95
		$pppoecfg['mode'] = $_POST['mode'];
96
		$pppoecfg['interface'] = $_POST['interface'];
97
		$pppoecfg['n_pppoe_units'] = $_POST['n_pppoe_units'];	
98

    
99
		$pppoecfg['radius']['server'] = $_POST['radiusserver'];
100
		$pppoecfg['radius']['secret'] = $_POST['radiussecret'];
101

    
102
		if($_POST['radiusenable'] == "yes")
103
			$pppoecfg['radius']['enable'] = true;
104
		else
105
			unset($pppoecfg['radius']['enable']);
106
			
107
		if($_POST['radacct_enable'] == "yes")
108
			$pppoecfg['radius']['accounting'] = true;
109
		else
110
			unset($pppoecfg['radius']['accounting']);
111

    
112
		if($_POST['radiusissueips'] == "yes") {
113
			$pppoecfg['radius']['radiusissueips'] = true;
114
		} else
115
			unset($pppoecfg['radius']['radiusissueips']);
116

    
117
		write_config();
118
		
119
		$retval = 0;
120
		
121
		config_lock();
122
		$retval = vpn_pppoe_configure();
123
		config_unlock();
124
		
125
		$savemsg = get_std_save_message($retval);
126
	}
127
}
128

    
129
$pgtitle = "VPN: PPPoE";
130
include("head.inc");
131

    
132
?>
133

    
134
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
135
<?php include("fbegin.inc"); ?>
136
<p class="pgtitle"><?=$pgtitle?></p>
137
<script language="JavaScript">
138
<!--
139
function get_radio_value(obj)
140
{
141
	for (i = 0; i < obj.length; i++) {
142
		if (obj[i].checked)
143
			return obj[i].value;
144
	}
145
	return null;
146
}
147

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

    
211
                <tr> 
212
                  <td width="22%" valign="top" class="vncell"><b>Interface</b></td>
213
                  <td width="78%" valign="top" class="vtable">
214

    
215
			<select name="interface" class="formfld" id="interface">
216
			  <?php
217
				$interfaces = array('lan' => 'LAN', 'wan' => 'WAN');
218
				for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
219
				      if (isset($config['interfaces']['opt' . $i]['enable']))
220
					      $interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
221
				}
222
				foreach ($interfaces as $iface => $ifacename):
223
			  ?>
224
			  <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
225
			  <?=htmlspecialchars($ifacename);?>
226
			  </option>
227
			  <?php endforeach; ?>
228
			</select> <br>			
229
                      
230
		  </td>
231
                </tr>
232
                <tr> 
233
                  <td width="22%" valign="top" class="vncellreq">Subnet netmask</td>
234
                  <td width="78%" class="vtable">
235
		    <select id="n_pppoe_units" name="n_pppoe_units">
236
		    <?php
237
		     for($x=0; $x<33; $x++) {
238
			if($x == $pconfig['n_pppoe_units'])
239
				$SELECTED = " SELECTED";
240
			else
241
				$SELECTED = "";
242
			echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";			
243
		     }
244
		    ?>
245
		    </select>
246
		    <br>Hint: 24 is 255.255.255.0
247
                  </td>
248
		</tr>
249
                <tr> 
250
                  <td width="22%" valign="top" class="vncellreq">Server address</td>
251
                  <td width="78%" class="vtable"> 
252
                    <?=$mandfldhtml;?><input name="localip" type="text" class="formfld" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>"> 
253
                    <br>
254
                    Enter the IP address the PPPoE server should use on its side 
255
                    for all clients.</td>
256
                </tr>
257
                <tr> 
258
                  <td width="22%" valign="top" class="vncellreq">Remote address range</td>
259
                  <td width="78%" class="vtable"> 
260
                    <?=$mandfldhtml;?><input name="remoteip" type="text" class="formfld" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>">
261
                    <br>
262
                    Specify the starting address for the client IP address subnet.<br>
263
                    </td>
264
                </tr>
265

    
266
                <tr> 
267
                  <td width="22%" valign="top" class="vncell">RADIUS</td>
268
                  <td width="78%" class="vtable"> 
269
                      <input name="radiusenable" type="checkbox" id="radiusenable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radiusenable']) echo "checked"; ?>>
270
                      <strong>Use a RADIUS server for authentication<br>
271
                      </strong>When set, all users will be authenticated using 
272
                      the RADIUS server specified below. The local user database 
273
                      will not be used.<br>
274
                      <br>
275
                      <input name="radacct_enable" type="checkbox" id="radacct_enable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radacct_enable']) echo "checked"; ?>>
276
                      <strong>Enable RADIUS accounting <br>
277
                      </strong>Sends accounting packets to the RADIUS server.</td>
278
                </tr>
279
                <tr> 
280
                  <td width="22%" valign="top" class="vncell">RADIUS server </td>
281
                  <td width="78%" class="vtable">
282
                      <input name="radiusserver" type="text" class="formfld" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>">
283
                      <br>
284
                      Enter the IP address of the RADIUS server.</td>
285
                </tr>
286
                <tr> 
287
                  <td width="22%" valign="top" class="vncell">RADIUS shared secret</td>
288
                  <td width="78%" valign="top" class="vtable">
289
                      <input name="radiussecret" type="password" class="formfld" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>">
290
                      <br>
291
                      Enter the shared secret that will be used to authenticate 
292
                      to the RADIUS server.</td>
293
                </tr>
294
                <tr> 
295
                  <td width="22%" valign="top" class="vncell">RADIUS issued IP's</td>
296
                  <td width="78%" valign="top" class="vtable">
297
                      <input name="radiusissueips" value="yes" type="checkbox" class="formfld" id="radiusissueips"<?php if($pconfig['radiusissueips']) echo " CHECKED"; ?>>
298
                      <br>Issue IP Addresses via RADIUS server.
299
                      
300
                  </td>
301
                </tr>		
302
                <tr> 
303
                  <td height="16" colspan="2" valign="top"></td>
304
                </tr>
305
                <tr> 
306
                  <td width="22%" valign="top">&nbsp;</td>
307
                  <td width="78%"> 
308
                    <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)"> 
309
                  </td>
310
                </tr>
311
                <tr> 
312
                  <td width="22%" valign="top">&nbsp;</td>
313
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
314
                    </strong></span>don't forget to add a firewall rule to permit 
315
                    traffic from PPPoE clients!</span></td>
316
                </tr>
317
              </table>
318
	   </div>
319
	 </td>
320
	</tr>
321
</table>
322
</form>
323
<script language="JavaScript">
324
<!--
325
enable_change(false);
326
//-->
327
</script>
328
<?php include("fend.inc"); ?>
329
</body>
330
</html>
(148-148/155)