1 |
de3fa7a6
|
Scott Ullrich
|
<?php
|
2 |
5b237745
|
Scott Ullrich
|
/*
|
3 |
f64e8f99
|
Ermal
|
services_dhcp_relay.php
|
4 |
de3fa7a6
|
Scott Ullrich
|
|
5 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Justin Ellison <justin@techadvise.com>.
|
6 |
1d7ba683
|
ayvis
|
Copyright (C) 2010 Ermal Luçi
|
7 |
ce77a9c4
|
Phil Davis
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
8 |
5b237745
|
Scott Ullrich
|
All rights reserved.
|
9 |
de3fa7a6
|
Scott Ullrich
|
|
10 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
11 |
|
|
modification, are permitted provided that the following conditions are met:
|
12 |
de3fa7a6
|
Scott Ullrich
|
|
13 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
this list of conditions and the following disclaimer.
|
15 |
de3fa7a6
|
Scott Ullrich
|
|
16 |
5b237745
|
Scott Ullrich
|
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 |
de3fa7a6
|
Scott Ullrich
|
|
20 |
5b237745
|
Scott Ullrich
|
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 |
1d333258
|
Scott Ullrich
|
/*
|
32 |
|
|
pfSense_MODULE: dhcprelay
|
33 |
|
|
*/
|
34 |
5b237745
|
Scott Ullrich
|
|
35 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
36 |
|
|
##|*IDENT=page-services-dhcprelay
|
37 |
|
|
##|*NAME=Services: DHCP Relay page
|
38 |
|
|
##|*DESCR=Allow access to the 'Services: DHCP Relay' page.
|
39 |
|
|
##|*MATCH=services_dhcp_relay.php*
|
40 |
|
|
##|-PRIV
|
41 |
|
|
|
42 |
5b237745
|
Scott Ullrich
|
require("guiconfig.inc");
|
43 |
|
|
|
44 |
2f06cc3f
|
Ermal
|
$pconfig['enable'] = isset($config['dhcrelay']['enable']);
|
45 |
|
|
if (empty($config['dhcrelay']['interface']))
|
46 |
|
|
$pconfig['interface'] = array();
|
47 |
|
|
else
|
48 |
|
|
$pconfig['interface'] = explode(",", $config['dhcrelay']['interface']);
|
49 |
5b237745
|
Scott Ullrich
|
$pconfig['server'] = $config['dhcrelay']['server'];
|
50 |
|
|
$pconfig['agentoption'] = isset($config['dhcrelay']['agentoption']);
|
51 |
|
|
|
52 |
2f06cc3f
|
Ermal
|
$iflist = get_configured_interface_with_descr();
|
53 |
5b237745
|
Scott Ullrich
|
|
54 |
48c6ab80
|
Scott Ullrich
|
/* set the enabled flag which will tell us if DHCP server is enabled
|
55 |
|
|
* on any interface. We will use this to disable dhcp-relay since
|
56 |
|
|
* the two are not compatible with each other.
|
57 |
|
|
*/
|
58 |
|
|
$dhcpd_enabled = false;
|
59 |
b9ed163d
|
Ermal Luçi
|
if (is_array($config['dhcpd'])) {
|
60 |
e94692c0
|
Renato Botelho
|
foreach($config['dhcpd'] as $dhcpif => $dhcp) {
|
61 |
|
|
if (isset($dhcp['enable']) && isset($config['interfaces'][$dhcpif]['enable'])) {
|
62 |
b9ed163d
|
Ermal Luçi
|
$dhcpd_enabled = true;
|
63 |
e94692c0
|
Renato Botelho
|
break;
|
64 |
|
|
}
|
65 |
|
|
}
|
66 |
3d7b7757
|
Chris Buechler
|
}
|
67 |
5b237745
|
Scott Ullrich
|
|
68 |
|
|
if ($_POST) {
|
69 |
|
|
|
70 |
|
|
unset($input_errors);
|
71 |
|
|
$pconfig = $_POST;
|
72 |
|
|
|
73 |
|
|
/* input validation */
|
74 |
|
|
if ($_POST['enable']) {
|
75 |
2f06cc3f
|
Ermal
|
$reqdfields = explode(" ", "server interface");
|
76 |
|
|
$reqdfieldsn = array(gettext("Destination Server"), gettext("Interface"));
|
77 |
de3fa7a6
|
Scott Ullrich
|
|
78 |
1e9b4611
|
Renato Botelho
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
79 |
de3fa7a6
|
Scott Ullrich
|
|
80 |
2f06cc3f
|
Ermal
|
if ($_POST['server']) {
|
81 |
|
|
$checksrv = explode(",", $_POST['server']);
|
82 |
|
|
foreach ($checksrv as $srv) {
|
83 |
|
|
if (!is_ipaddr($srv))
|
84 |
45c8402f
|
Chris Buechler
|
$input_errors[] = gettext("A valid Destination Server IP address must be specified.");
|
85 |
de3fa7a6
|
Scott Ullrich
|
}
|
86 |
5b237745
|
Scott Ullrich
|
}
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
if (!$input_errors) {
|
90 |
2f06cc3f
|
Ermal
|
$config['dhcrelay']['enable'] = $_POST['enable'] ? true : false;
|
91 |
|
|
$config['dhcrelay']['interface'] = implode(",", $_POST['interface']);
|
92 |
5b237745
|
Scott Ullrich
|
$config['dhcrelay']['agentoption'] = $_POST['agentoption'] ? true : false;
|
93 |
|
|
$config['dhcrelay']['server'] = $_POST['server'];
|
94 |
de3fa7a6
|
Scott Ullrich
|
|
95 |
5b237745
|
Scott Ullrich
|
write_config();
|
96 |
de3fa7a6
|
Scott Ullrich
|
|
97 |
5b237745
|
Scott Ullrich
|
$retval = 0;
|
98 |
3851094f
|
Scott Ullrich
|
$retval = services_dhcrelay_configure();
|
99 |
5b237745
|
Scott Ullrich
|
$savemsg = get_std_save_message($retval);
|
100 |
de3fa7a6
|
Scott Ullrich
|
|
101 |
5b237745
|
Scott Ullrich
|
}
|
102 |
|
|
}
|
103 |
|
|
|
104 |
d2b3e9dc
|
Colin Fleming
|
$closehead = false;
|
105 |
7fd3b523
|
Rafael Lucas
|
$pgtitle = array(gettext("Services"),gettext("DHCP Relay"));
|
106 |
b32dd0a6
|
jim-p
|
$shortcut_section = "dhcp";
|
107 |
4df96eff
|
Scott Ullrich
|
include("head.inc");
|
108 |
|
|
|
109 |
5b237745
|
Scott Ullrich
|
?>
|
110 |
4df96eff
|
Scott Ullrich
|
|
111 |
91f026b0
|
ayvis
|
<script type="text/javascript">
|
112 |
d2b3e9dc
|
Colin Fleming
|
//<![CDATA[
|
113 |
471877bf
|
Scott Ullrich
|
function enable_change(enable_over) {
|
114 |
|
|
if (document.iform.enable.checked || enable_over) {
|
115 |
|
|
document.iform.server.disabled = 0;
|
116 |
2f06cc3f
|
Ermal
|
document.iform.interface.disabled = 0;
|
117 |
471877bf
|
Scott Ullrich
|
document.iform.agentoption.disabled = 0;
|
118 |
|
|
} else {
|
119 |
|
|
document.iform.server.disabled = 1;
|
120 |
2f06cc3f
|
Ermal
|
document.iform.interface.disabled = 1;
|
121 |
471877bf
|
Scott Ullrich
|
document.iform.agentoption.disabled = 1;
|
122 |
|
|
}
|
123 |
5b237745
|
Scott Ullrich
|
}
|
124 |
d2b3e9dc
|
Colin Fleming
|
//]]>
|
125 |
5b237745
|
Scott Ullrich
|
</script>
|
126 |
d2b3e9dc
|
Colin Fleming
|
</head>
|
127 |
5b237745
|
Scott Ullrich
|
|
128 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
129 |
|
|
<?php include("fbegin.inc"); ?>
|
130 |
|
|
<form action="services_dhcp_relay.php" method="post" name="iform" id="iform">
|
131 |
|
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
132 |
|
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
133 |
48c6ab80
|
Scott Ullrich
|
|
134 |
d2b3e9dc
|
Colin Fleming
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="dhcp relay">
|
135 |
de3fa7a6
|
Scott Ullrich
|
<tr>
|
136 |
d732f186
|
Bill Marquette
|
<td>
|
137 |
|
|
<div id="mainarea">
|
138 |
d2b3e9dc
|
Colin Fleming
|
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
|
139 |
7eb2ebbe
|
Scott Ullrich
|
<tr>
|
140 |
d2b3e9dc
|
Colin Fleming
|
<?php
|
141 |
7eb2ebbe
|
Scott Ullrich
|
if ($dhcpd_enabled) {
|
142 |
45c8402f
|
Chris Buechler
|
echo "<td>DHCP Server is currently enabled. Cannot enable the DHCP Relay service while the DHCP Server is enabled on any interface.";
|
143 |
905bafa1
|
Colin Fleming
|
echo "</td></tr></table></div></td></tr></table></form>";
|
144 |
7eb2ebbe
|
Scott Ullrich
|
include("fend.inc");
|
145 |
905bafa1
|
Colin Fleming
|
echo "</body></html>";
|
146 |
7eb2ebbe
|
Scott Ullrich
|
exit;
|
147 |
|
|
}
|
148 |
2f06cc3f
|
Ermal
|
?>
|
149 |
7eb2ebbe
|
Scott Ullrich
|
|
150 |
2f06cc3f
|
Ermal
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("DHCP Relay configuration"); ?></td>
|
151 |
|
|
</tr>
|
152 |
|
|
<tr>
|
153 |
|
|
<td width="22%" valign="top" class="vncellreq">Enable</td>
|
154 |
|
|
<td width="78%" class="vtable">
|
155 |
d2b3e9dc
|
Colin Fleming
|
<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked=\"checked\""; ?> onclick="enable_change(false)" />
|
156 |
2f06cc3f
|
Ermal
|
<strong><?php printf(gettext("Enable DHCP relay on interface"));?></strong>
|
157 |
|
|
</td>
|
158 |
|
|
</tr>
|
159 |
|
|
<tr>
|
160 |
|
|
<td width="22%" valign="top" class="vncellreq">Interface(s)</td>
|
161 |
5b237745
|
Scott Ullrich
|
<td width="78%" class="vtable">
|
162 |
d2b3e9dc
|
Colin Fleming
|
<select id="interface" name="interface[]" multiple="multiple" class="formselect" size="3">
|
163 |
2f06cc3f
|
Ermal
|
<?php
|
164 |
|
|
foreach ($iflist as $ifent => $ifdesc) {
|
165 |
|
|
if (!is_ipaddr(get_interface_ip($ifent)))
|
166 |
|
|
continue;
|
167 |
d2b3e9dc
|
Colin Fleming
|
echo "<option value=\"{$ifent}\"";
|
168 |
2f06cc3f
|
Ermal
|
if (in_array($ifent, $pconfig['interface']))
|
169 |
d2b3e9dc
|
Colin Fleming
|
echo " selected=\"selected\"";
|
170 |
2f06cc3f
|
Ermal
|
echo ">{$ifdesc}</option>\n";
|
171 |
|
|
}
|
172 |
|
|
?>
|
173 |
|
|
</select>
|
174 |
45c8402f
|
Chris Buechler
|
<br />Interfaces without an IP address will not be shown.
|
175 |
2f06cc3f
|
Ermal
|
</td>
|
176 |
|
|
</tr>
|
177 |
|
|
<tr>
|
178 |
5b237745
|
Scott Ullrich
|
<td width="22%" valign="top" class="vtable"> </td>
|
179 |
|
|
<td width="78%" class="vtable">
|
180 |
d2b3e9dc
|
Colin Fleming
|
<input name="agentoption" type="checkbox" value="yes" <?php if ($pconfig['agentoption']) echo "checked=\"checked\""; ?> />
|
181 |
1d7ba683
|
ayvis
|
<strong><?=gettext("Append circuit ID and agent ID to requests"); ?></strong><br />
|
182 |
bff079e8
|
Carlos Eduardo Ramos
|
<?php printf(gettext("If this is checked, the DHCP relay will append the circuit ID (%s interface number) and the agent ID to the DHCP request."), $g['product_name']); ?></td>
|
183 |
2f06cc3f
|
Ermal
|
</tr>
|
184 |
|
|
<tr>
|
185 |
b145863a
|
Chris Buechler
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination server");?></td>
|
186 |
de3fa7a6
|
Scott Ullrich
|
<td width="78%" class="vtable">
|
187 |
d2b3e9dc
|
Colin Fleming
|
<input name="server" type="text" class="formfld unknown" id="server" size="20" value="<?=htmlspecialchars($pconfig['server']);?>" />
|
188 |
1d7ba683
|
ayvis
|
<br />
|
189 |
0f680478
|
jim-p
|
<?=gettext("This is the IP address of the server to which DHCP requests are relayed. You can enter multiple server IP addresses, separated by commas.");?>
|
190 |
5b237745
|
Scott Ullrich
|
</td>
|
191 |
2f06cc3f
|
Ermal
|
</tr>
|
192 |
|
|
<tr>
|
193 |
5b237745
|
Scott Ullrich
|
<td width="22%" valign="top"> </td>
|
194 |
de3fa7a6
|
Scott Ullrich
|
<td width="78%">
|
195 |
d2b3e9dc
|
Colin Fleming
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)" />
|
196 |
5b237745
|
Scott Ullrich
|
</td>
|
197 |
2f06cc3f
|
Ermal
|
</tr>
|
198 |
|
|
</table>
|
199 |
d732f186
|
Bill Marquette
|
</div>
|
200 |
5b237745
|
Scott Ullrich
|
</td>
|
201 |
|
|
</tr>
|
202 |
|
|
</table>
|
203 |
|
|
</form>
|
204 |
91f026b0
|
ayvis
|
<script type="text/javascript">
|
205 |
d2b3e9dc
|
Colin Fleming
|
//<![CDATA[
|
206 |
471877bf
|
Scott Ullrich
|
enable_change(false);
|
207 |
d2b3e9dc
|
Colin Fleming
|
//]]>
|
208 |
5b237745
|
Scott Ullrich
|
</script>
|
209 |
|
|
<?php include("fend.inc"); ?>
|
210 |
|
|
</body>
|
211 |
|
|
</html>
|