Project

General

Profile

Download (11.9 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	vpn_pppoe.php
5
	part of pfSense
6
	
7
	Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
8
	All rights reserved.
9
	
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
	
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
	
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
	
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

    
32
require("guiconfig.inc");
33

    
34
if (!is_array($config['pppoe']['radius'])) {
35
	$config['pppoe']['radius'] = array();
36
}
37
$pppoecfg = &$config['pppoe'];
38

    
39
$pconfig['remoteip'] = $pppoecfg['remoteip'];
40
$pconfig['localip'] = $pppoecfg['localip'];
41
$pconfig['mode'] = $pppoecfg['mode'];
42
$pconfig['interface'] = $pppoecfg['interface'];
43
$pconfig['wins'] = $pppoecfg['wins'];
44
$pconfig['req128'] = isset($pppoecfg['req128']);
45
$pconfig['radiusenable'] = isset($pppoecfg['radius']['enable']);
46
$pconfig['radacct_enable'] = isset($pppoecfg['radius']['accounting']);
47
$pconfig['radiusserver'] = $pppoecfg['radius']['server'];
48
$pconfig['radiussecret'] = $pppoecfg['radius']['secret'];
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['n_pppoe_units'] - 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
	}
92
	
93
	if (!$input_errors) {
94
		$pppoecfg['remoteip'] = $_POST['remoteip'];
95
		$pppoecfg['localip'] = $_POST['localip'];
96
		$pppoecfg['mode'] = $_POST['mode'];
97
		$pppoecfg['wins'] = $_POST['wins'];
98
		$pppoecfg['interface'] = $_POST['interface'];
99
		$pppoecfg['req128'] = $_POST['req128'] ? true : false;
100
		$pppoecfg['radius']['enable'] = $_POST['radiusenable'] ? true : false;
101
		$pppoecfg['radius']['accounting'] = $_POST['radacct_enable'] ? true : false;
102
		$pppoecfg['radius']['server'] = $_POST['radiusserver'];
103
		$pppoecfg['radius']['secret'] = $_POST['radiussecret'];
104

    
105
		write_config();
106
		
107
		$retval = 0;
108
		
109
		config_lock();
110
		$retval = vpn_pppoe_configure();
111
		config_unlock();
112
		
113
		$savemsg = get_std_save_message($retval);
114
	}
115
}
116

    
117
$pgtitle = "VPN: PPPoE";
118
include("head.inc");
119

    
120
?>
121

    
122
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
123
<?php include("fbegin.inc"); ?>
124
<p class="pgtitle"><?=$pgtitle?></p>
125
<script language="JavaScript">
126
<!--
127
function get_radio_value(obj)
128
{
129
	for (i = 0; i < obj.length; i++) {
130
		if (obj[i].checked)
131
			return obj[i].value;
132
	}
133
	return null;
134
}
135

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

    
196
                <tr> 
197
                  <td width="22%" valign="top" class="vncell"><b>Interface</b></td>
198
                  <td width="78%" valign="top" class="vtable">
199

    
200
			<select name="interface" class="formfld" id="interface">
201
			  <?php
202
				$interfaces = array('lan' => 'LAN', 'wan' => 'WAN');
203
				for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
204
				      if (isset($config['interfaces']['opt' . $i]['enable']))
205
					      $interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
206
				}
207
				foreach ($interfaces as $iface => $ifacename):
208
			  ?>
209
			  <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
210
			  <?=htmlspecialchars($ifacename);?>
211
			  </option>
212
			  <?php endforeach; ?>
213
			</select> <br>			
214
                      
215
		  </td>
216
                </tr>
217

    
218
                <tr> 
219
                  <td width="22%" valign="top" class="vncellreq">Max. concurrent connections</td>
220
                  <td width="78%" class="vtable"> 
221
                    <?=$g['n_pppoe_units'];?>
222
                  </td>
223
		</tr>
224

    
225
                <tr> 
226
                  <td width="22%" valign="top" class="vncellreq">Server address</td>
227
                  <td width="78%" class="vtable"> 
228
                    <?=$mandfldhtml;?><input name="localip" type="text" class="formfld" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>"> 
229
                    <br>
230
                    Enter the IP address the PPPoE server should use on its side 
231
                    for all clients.</td>
232
                </tr>
233

    
234
                <tr> 
235
                  <td width="22%" valign="top" class="vncellreq">Remote address range</td>
236
                  <td width="78%" class="vtable"> 
237
                    <?=$mandfldhtml;?><input name="remoteip" type="text" class="formfld" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>">
238
                    / 
239
                    <?=$g['pppoe_subnet'];?>
240
                    <br>
241
                    Specify the starting address for the client IP address subnet.<br>
242
                    The PPPoE server will assign 
243
                    <?=$g['n_pppoe_units'];?>
244
                    addresses, starting at the address entered above, to clients.</td>
245
                </tr>
246

    
247
                <tr> 
248
                  <td width="22%" valign="top" class="vncell">RADIUS</td>
249
                  <td width="78%" class="vtable"> 
250
                      <input name="radiusenable" type="checkbox" id="radiusenable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radiusenable']) echo "checked"; ?>>
251
                      <strong>Use a RADIUS server for authentication<br>
252
                      </strong>When set, all users will be authenticated using 
253
                      the RADIUS server specified below. The local user database 
254
                      will not be used.<br>
255
                      <br>
256
                      <input name="radacct_enable" type="checkbox" id="radacct_enable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radacct_enable']) echo "checked"; ?>>
257
                      <strong>Enable RADIUS accounting <br>
258
                      </strong>Sends accounting packets to the RADIUS server.</td>
259
                </tr>
260
                <tr> 
261
                  <td width="22%" valign="top" class="vncell">RADIUS server </td>
262
                  <td width="78%" class="vtable">
263
                      <input name="radiusserver" type="text" class="formfld" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>">
264
                      <br>
265
                      Enter the IP address of the RADIUS server.</td>
266
                </tr>
267
                <tr> 
268
                  <td width="22%" valign="top" class="vncell">RADIUS shared secret</td>
269
                  <td width="78%" valign="top" class="vtable">
270
                      <input name="radiussecret" type="password" class="formfld" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>">
271
                      <br>
272
                      Enter the shared secret that will be used to authenticate 
273
                      to the RADIUS server.</td>
274
                </tr>
275
		
276

    
277

    
278
                <tr> 
279
                  <td height="16" colspan="2" valign="top"></td>
280
                </tr>
281

    
282
                <tr> 
283
                  <td width="22%" valign="top">&nbsp;</td>
284
                  <td width="78%"> 
285
                    <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)"> 
286
                  </td>
287
                </tr>
288
                <tr> 
289
                  <td width="22%" valign="top">&nbsp;</td>
290
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
291
                    </strong></span>don't forget to add a firewall rule to permit 
292
                    traffic from PPPoE clients!</span></td>
293
                </tr>
294
              </table>
295
	   </div>
296
	 </td>
297
	</tr>
298
</table>
299
</form>
300
<script language="JavaScript">
301
<!--
302
enable_change(false);
303
//-->
304
</script>
305
<?php include("fend.inc"); ?>
306
</body>
307
</html>
(130-130/137)