Project

General

Profile

Download (7.48 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	services_dhcp_relay.php
4

    
5
	Copyright (C) 2003-2004 Justin Ellison <justin@techadvise.com>.
6
	Copyright (C) 2010 	Ermal Luçi
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
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
	pfSense_MODULE:	dhcprelay
33
*/
34

    
35
##|+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
require("guiconfig.inc");
43
require_once("filter.inc");
44

    
45
$pconfig['enable'] = isset($config['dhcrelay']['enable']);
46
if (empty($config['dhcrelay']['interface']))
47
	$pconfig['interface'] = array();
48
else
49
	$pconfig['interface'] = explode(",", $config['dhcrelay']['interface']);
50
$pconfig['server'] = $config['dhcrelay']['server'];
51
$pconfig['agentoption'] = isset($config['dhcrelay']['agentoption']);
52

    
53
$iflist = get_configured_interface_with_descr();
54

    
55
/*   set the enabled flag which will tell us if DHCP server is enabled
56
 *   on any interface.   We will use this to disable dhcp-relay since
57
 *   the two are not compatible with each other.
58
 */
59
$dhcpd_enabled = false;
60
if (is_array($config['dhcpd'])) {
61
	foreach($config['dhcpd'] as $dhcpif => $dhcp) {
62
		if (isset($dhcp['enable']) && isset($config['interfaces'][$dhcpif]['enable'])) {
63
			$dhcpd_enabled = true;
64
			break;
65
		}
66
	}
67
}
68

    
69
if ($_POST) {
70

    
71
	unset($input_errors);
72
	$pconfig = $_POST;
73

    
74
	/* input validation */
75
	if ($_POST['enable']) {
76
		$reqdfields = explode(" ", "server interface");
77
		$reqdfieldsn = array(gettext("Destination Server"), gettext("Interface"));
78

    
79
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
80

    
81
		if ($_POST['server']) {
82
			$checksrv = explode(",", $_POST['server']);
83
			foreach ($checksrv as $srv) {
84
				if (!is_ipaddr($srv))
85
					$input_errors[] = gettext("A valid Destination Server IP address must be specified.");
86
			}
87
		}
88
	}
89

    
90
	if (!$input_errors) {
91
		$config['dhcrelay']['enable'] = $_POST['enable'] ? true : false;
92
		$config['dhcrelay']['interface'] = implode(",", $_POST['interface']);
93
		$config['dhcrelay']['agentoption'] = $_POST['agentoption'] ? true : false;
94
		$config['dhcrelay']['server'] = $_POST['server'];
95

    
96
		write_config();
97

    
98
		$retval = 0;
99
		$retval = services_dhcrelay_configure();
100
		$savemsg = get_std_save_message($retval);
101
		filter_configure();
102

    
103
	}
104
}
105

    
106
$closehead = false;
107
$pgtitle = array(gettext("Services"),gettext("DHCP Relay"));
108
$shortcut_section = "dhcp";
109
include("head.inc");
110

    
111
?>
112

    
113
<script type="text/javascript">
114
//<![CDATA[
115
function enable_change(enable_over) {
116
	if (document.iform.enable.checked || enable_over) {
117
		document.iform.server.disabled = 0;
118
		document.iform.interface.disabled = 0;
119
		document.iform.agentoption.disabled = 0;
120
	} else {
121
		document.iform.server.disabled = 1;
122
		document.iform.interface.disabled = 1;
123
		document.iform.agentoption.disabled = 1;
124
	}
125
}
126
//]]>
127
</script>
128
</head>
129

    
130
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
131
<?php include("fbegin.inc"); ?>
132
<form action="services_dhcp_relay.php" method="post" name="iform" id="iform">
133
<?php if ($input_errors) print_input_errors($input_errors); ?>
134
<?php if ($savemsg) print_info_box($savemsg); ?>
135

    
136
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="dhcp relay">
137
  <tr>
138
    <td>
139
	<div id="mainarea">
140
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
141
		<tr>
142
<?php
143
	if ($dhcpd_enabled) {
144
		echo "<td>DHCP Server is currently enabled. Cannot enable the DHCP Relay service while the DHCP Server is enabled on any interface.";
145
			echo "</td></tr></table></div></td></tr></table></form>";
146
			include("fend.inc"); 
147
			echo "</body></html>";
148
			exit;
149
		}
150
?>
151

    
152
			<td colspan="2" valign="top" class="listtopic"><?=gettext("DHCP Relay configuration"); ?></td>
153
		</tr>
154
		<tr>
155
                        <td width="22%" valign="top" class="vncellreq">Enable</td>
156
                        <td width="78%" class="vtable">
157
			<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked=\"checked\""; ?> onclick="enable_change(false)" />
158
                          <strong><?php printf(gettext("Enable DHCP relay on interface"));?></strong>
159
			</td>
160
		</tr>
161
		<tr>
162
                        <td width="22%" valign="top" class="vncellreq">Interface(s)</td>
163
                        <td width="78%" class="vtable">
164
				<select id="interface" name="interface[]" multiple="multiple" class="formselect" size="3">
165
			<?php
166
                                foreach ($iflist as $ifent => $ifdesc) {
167
					if (!is_ipaddr(get_interface_ip($ifent)))
168
						continue;
169
					echo "<option value=\"{$ifent}\"";
170
					if (in_array($ifent, $pconfig['interface']))
171
						echo " selected=\"selected\"";
172
					echo ">{$ifdesc}</option>\n";
173
				}
174
			?>
175
                                </select>
176
				<br />Interfaces without an IP address will not be shown.
177
			</td>
178
		</tr>
179
		<tr>
180
	              <td width="22%" valign="top" class="vtable">&nbsp;</td>
181
                      <td width="78%" class="vtable">
182
<input name="agentoption" type="checkbox" value="yes" <?php if ($pconfig['agentoption']) echo "checked=\"checked\""; ?> />
183
                      <strong><?=gettext("Append circuit ID and agent ID to requests"); ?></strong><br />
184
                      <?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>
185
		</tr>
186
		<tr>
187
                        <td width="22%" valign="top" class="vncellreq"><?=gettext("Destination server");?></td>
188
                        <td width="78%" class="vtable">
189
                          <input name="server" type="text" class="formfld unknown" id="server" size="20" value="<?=htmlspecialchars($pconfig['server']);?>" />
190
                          <br />
191
			  <?=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.");?>
192
                        </td>
193
		</tr>
194
		<tr>
195
                        <td width="22%" valign="top">&nbsp;</td>
196
                        <td width="78%">
197
                          <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)" />
198
                        </td>
199
		</tr>
200
	</table>
201
	</div>
202
    </td>
203
  </tr>
204
</table>
205
</form>
206
<script type="text/javascript">
207
//<![CDATA[
208
enable_change(false);
209
//]]>
210
</script>
211
<?php include("fend.inc"); ?>
212
</body>
213
</html>
(147-147/251)