Project

General

Profile

Download (11.8 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

    
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
		write_config();
113
		
114
		$retval = 0;
115
		
116
		config_lock();
117
		$retval = vpn_pppoe_configure();
118
		config_unlock();
119
		
120
		$savemsg = get_std_save_message($retval);
121
	}
122
}
123

    
124
$pgtitle = "VPN: PPPoE";
125
include("head.inc");
126

    
127
?>
128

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

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

    
199
                <tr> 
200
                  <td width="22%" valign="top" class="vncell"><b>Interface</b></td>
201
                  <td width="78%" valign="top" class="vtable">
202

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

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