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['radiusenable'] = isset($pppoecfg['radius']['enable']);
44
$pconfig['radacct_enable'] = isset($pppoecfg['radius']['accounting']);
45
$pconfig['radiusserver'] = $pppoecfg['radius']['server'];
46
$pconfig['radiussecret'] = $pppoecfg['radius']['secret'];
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
		$pppoecfg['radius']['enable'] = $_POST['radiusenable'] ? true : false;
99
		$pppoecfg['radius']['accounting'] = $_POST['radacct_enable'] ? true : false;
100
		$pppoecfg['radius']['server'] = $_POST['radiusserver'];
101
		$pppoecfg['radius']['secret'] = $_POST['radiussecret'];
102

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

    
115
$pgtitle = "VPN: PPPoE";
116
include("head.inc");
117

    
118
?>
119

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

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

    
190
                <tr> 
191
                  <td width="22%" valign="top" class="vncell"><b>Interface</b></td>
192
                  <td width="78%" valign="top" class="vtable">
193

    
194
			<select name="interface" class="formfld" id="interface">
195
			  <?php
196
				$interfaces = array('lan' => 'LAN', 'wan' => 'WAN');
197
				for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
198
				      if (isset($config['interfaces']['opt' . $i]['enable']))
199
					      $interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
200
				}
201
				foreach ($interfaces as $iface => $ifacename):
202
			  ?>
203
			  <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
204
			  <?=htmlspecialchars($ifacename);?>
205
			  </option>
206
			  <?php endforeach; ?>
207
			</select> <br>			
208
                      
209
		  </td>
210
                </tr>
211
                <tr> 
212
                  <td width="22%" valign="top" class="vncellreq">Subnet netmask</td>
213
                  <td width="78%" class="vtable">
214
		    <select id="n_pppoe_units" name="n_pppoe_units">
215
		    <?php
216
		     for($x=0; $x<33; $x++) {
217
			if($x == $pconfig['n_pppoe_units'])
218
				$SELECTED = " SELECTED";
219
			else
220
				$SELECTED = "";
221
			echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";			
222
		     }
223
		    ?>
224
		    </select>
225
		    <br>Hint: 24 is 255.255.255.0
226
                  </td>
227
		</tr>
228
                <tr> 
229
                  <td width="22%" valign="top" class="vncellreq">Server address</td>
230
                  <td width="78%" class="vtable"> 
231
                    <?=$mandfldhtml;?><input name="localip" type="text" class="formfld" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>"> 
232
                    <br>
233
                    Enter the IP address the PPPoE server should use on its side 
234
                    for all clients.</td>
235
                </tr>
236
                <tr> 
237
                  <td width="22%" valign="top" class="vncellreq">Remote address range</td>
238
                  <td width="78%" class="vtable"> 
239
                    <?=$mandfldhtml;?><input name="remoteip" type="text" class="formfld" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>">
240
                    / 
241
                    <?=$g['pppoe_subnet'];?>
242
                    <br>
243
                    Specify the starting address for the client IP address subnet.<br>
244
                    The PPPoE server will assign 
245
                    <?=$g['n_pppoe_units'];?>
246
                    addresses, starting at the address entered above, to clients.</td>
247
                </tr>
248

    
249
                <tr> 
250
                  <td width="22%" valign="top" class="vncell">RADIUS</td>
251
                  <td width="78%" class="vtable"> 
252
                      <input name="radiusenable" type="checkbox" id="radiusenable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radiusenable']) echo "checked"; ?>>
253
                      <strong>Use a RADIUS server for authentication<br>
254
                      </strong>When set, all users will be authenticated using 
255
                      the RADIUS server specified below. The local user database 
256
                      will not be used.<br>
257
                      <br>
258
                      <input name="radacct_enable" type="checkbox" id="radacct_enable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radacct_enable']) echo "checked"; ?>>
259
                      <strong>Enable RADIUS accounting <br>
260
                      </strong>Sends accounting packets to the RADIUS server.</td>
261
                </tr>
262
                <tr> 
263
                  <td width="22%" valign="top" class="vncell">RADIUS server </td>
264
                  <td width="78%" class="vtable">
265
                      <input name="radiusserver" type="text" class="formfld" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>">
266
                      <br>
267
                      Enter the IP address of the RADIUS server.</td>
268
                </tr>
269
                <tr> 
270
                  <td width="22%" valign="top" class="vncell">RADIUS shared secret</td>
271
                  <td width="78%" valign="top" class="vtable">
272
                      <input name="radiussecret" type="password" class="formfld" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>">
273
                      <br>
274
                      Enter the shared secret that will be used to authenticate 
275
                      to the RADIUS server.</td>
276
                </tr>
277
                <tr> 
278
                  <td height="16" colspan="2" valign="top"></td>
279
                </tr>
280
                <tr> 
281
                  <td width="22%" valign="top">&nbsp;</td>
282
                  <td width="78%"> 
283
                    <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)"> 
284
                  </td>
285
                </tr>
286
                <tr> 
287
                  <td width="22%" valign="top">&nbsp;</td>
288
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
289
                    </strong></span>don't forget to add a firewall rule to permit 
290
                    traffic from PPPoE clients!</span></td>
291
                </tr>
292
              </table>
293
	   </div>
294
	 </td>
295
	</tr>
296
</table>
297
</form>
298
<script language="JavaScript">
299
<!--
300
enable_change(false);
301
//-->
302
</script>
303
<?php include("fend.inc"); ?>
304
</body>
305
</html>
(137-137/144)