Projet

Général

Profil

Télécharger (7,29 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_dhcp_relay.php @ 7e736f38

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
	All rights reserved.
8

    
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11

    
12
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14

    
15
	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

    
19
	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
/*
31
	pfSense_MODULE:	dhcprelay
32
*/
33

    
34
##|+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
require("guiconfig.inc");
42

    
43
$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
$pconfig['server'] = $config['dhcrelay']['server'];
49
$pconfig['agentoption'] = isset($config['dhcrelay']['agentoption']);
50

    
51
$iflist = get_configured_interface_with_descr();
52

    
53
/*   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
if (is_array($config['dhcpd'])) {
59
	foreach($config['dhcpd'] as $dhcp) 
60
		if (isset($dhcp['enable'])) 
61
			$dhcpd_enabled = true;
62
}
63

    
64
if ($_POST) {
65

    
66
	unset($input_errors);
67
	$pconfig = $_POST;
68

    
69
	/* input validation */
70
	if ($_POST['enable']) {
71
		$reqdfields = explode(" ", "server interface");
72
		$reqdfieldsn = array(gettext("Destination Server"), gettext("Interface"));
73

    
74
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
75

    
76
		if ($_POST['server']) {
77
			$checksrv = explode(",", $_POST['server']);
78
			foreach ($checksrv as $srv) {
79
				if (!is_ipaddr($srv))
80
					$input_errors[] = gettext("A valid Destination Server IP address must be specified.");
81
			}
82
		}
83
	}
84

    
85
	if (!$input_errors) {
86
		$config['dhcrelay']['enable'] = $_POST['enable'] ? true : false;
87
		$config['dhcrelay']['interface'] = implode(",", $_POST['interface']);
88
		$config['dhcrelay']['agentoption'] = $_POST['agentoption'] ? true : false;
89
		$config['dhcrelay']['server'] = $_POST['server'];
90

    
91
		write_config();
92

    
93
		$retval = 0;
94
		$retval = services_dhcrelay_configure();
95
		$savemsg = get_std_save_message($retval);
96

    
97
	}
98
}
99

    
100
$pgtitle = array(gettext("Services"),gettext("DHCP Relay"));
101
$shortcut_section = "dhcp";
102
include("head.inc");
103

    
104
?>
105

    
106
<script language="JavaScript">
107
<!--
108
function enable_change(enable_over) {
109
	if (document.iform.enable.checked || enable_over) {
110
		document.iform.server.disabled = 0;
111
		document.iform.interface.disabled = 0;
112
		document.iform.agentoption.disabled = 0;
113
	} else {
114
		document.iform.server.disabled = 1;
115
		document.iform.interface.disabled = 1;
116
		document.iform.agentoption.disabled = 1;
117
	}
118
}
119
//-->
120
</script>
121

    
122

    
123
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
124
<?php include("fbegin.inc"); ?>
125
<form action="services_dhcp_relay.php" method="post" name="iform" id="iform">
126
<?php if ($input_errors) print_input_errors($input_errors); ?>
127
<?php if ($savemsg) print_info_box($savemsg); ?>
128

    
129
<table width="100%" border="0" cellpadding="0" cellspacing="0">
130
  <tr>
131
    <td>
132
	<div id="mainarea">
133
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
134
		<tr>
135
<?php 
136
	if ($dhcpd_enabled) {
137
		echo "<td>DHCP Server is currently enabled. Cannot enable the DHCP Relay service while the DHCP Server is enabled on any interface.";
138
			echo "</td></tr></table></div></td></tr></table></body>";
139
			echo "</html>";
140
			include("fend.inc"); 
141
			exit;
142
		}
143
?>
144

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