Project

General

Profile

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