Project

General

Profile

Download (12.2 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php 
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	services_dnsmasq_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7
	Copyright (C) 2003-2004 Bob Zoller <bob@kludgebox.com> and Manuel Kasper <mk@neon1.net>.
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 1d333258 Scott Ullrich
/*
32
	pfSense_MODULE:	dnsforwarder
33
*/
34 5b237745 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-services-dnsforwarder-edithost
37
##|*NAME=Services: DNS Forwarder: Edit host page
38
##|*DESCR=Allow access to the 'Services: DNS Forwarder: Edit host' page.
39
##|*MATCH=services_dnsmasq_edit.php*
40
##|-PRIV
41
42 4504a769 Ermal Lu?i
function hostcmp($a, $b) {
43
	return strcasecmp($a['host'], $b['host']);
44
}
45
46 0d64af59 Ermal Lu?i
function hosts_sort() {
47
        global $g, $config;
48
49
        if (!is_array($config['dnsmasq']['hosts']))
50
                return;
51
52
        usort($config['dnsmasq']['hosts'], "hostcmp");
53
}
54 6b07c15a Matthew Grooms
55 5b237745 Scott Ullrich
require("guiconfig.inc");
56
57 4d6ba181 Scott Ullrich
if (!is_array($config['dnsmasq']['hosts'])) 
58 5b237745 Scott Ullrich
	$config['dnsmasq']['hosts'] = array();
59 4d6ba181 Scott Ullrich
60 5b237745 Scott Ullrich
$a_hosts = &$config['dnsmasq']['hosts'];
61
62 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
63
	$id = $_GET['id'];
64
if (isset($_POST['id']) && is_numericint($_POST['id']))
65 5b237745 Scott Ullrich
	$id = $_POST['id'];
66
67
if (isset($id) && $a_hosts[$id]) {
68
	$pconfig['host'] = $a_hosts[$id]['host'];
69
	$pconfig['domain'] = $a_hosts[$id]['domain'];
70
	$pconfig['ip'] = $a_hosts[$id]['ip'];
71
	$pconfig['descr'] = $a_hosts[$id]['descr'];
72 5a2a8349 Lorenz Schori
	$pconfig['aliases'] = $a_hosts[$id]['aliases'];
73 5b237745 Scott Ullrich
}
74
75
if ($_POST) {
76
77
	unset($input_errors);
78
	$pconfig = $_POST;
79
80
	/* input validation */
81
	$reqdfields = explode(" ", "domain ip");
82 065bc89a Rafael Lucas
	$reqdfieldsn = array(gettext("Domain"),gettext("IP address"));
83 5b237745 Scott Ullrich
	
84 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
85 5b237745 Scott Ullrich
	
86 4d6ba181 Scott Ullrich
	if (($_POST['host'] && !is_hostname($_POST['host']))) 
87 065bc89a Rafael Lucas
		$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
88 4d6ba181 Scott Ullrich
89
	if (($_POST['domain'] && !is_domain($_POST['domain']))) 
90 065bc89a Rafael Lucas
		$input_errors[] = gettext("A valid domain must be specified.");
91 4d6ba181 Scott Ullrich
		
92
	if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) 
93 065bc89a Rafael Lucas
		$input_errors[] = gettext("A valid IP address must be specified.");
94 5b237745 Scott Ullrich
95 5a2a8349 Lorenz Schori
	/* collect aliases */
96
	$aliases = array();
97
	foreach ($_POST as $key => $value) {
98
		$entry = '';
99
		if (!substr_compare('aliashost', $key, 0, 9)) {
100
			$entry = substr($key, 9);
101
			$field = 'host';
102
		}
103
		elseif (!substr_compare('aliasdomain', $key, 0, 11)) {
104
			$entry = substr($key, 11);
105
			$field = 'domain';
106
		}
107
		elseif (!substr_compare('aliasdescription', $key, 0, 16)) {
108
			$entry = substr($key, 16);
109
			$field = 'description';
110
		}
111
		if (ctype_digit($entry)) {
112
			$aliases[$entry][$field] = $value;
113
		}
114
	}
115
	$pconfig['aliases']['item'] = $aliases;
116
117
	/* validate aliases */
118
	foreach ($aliases as $idx => $alias) {
119
		$aliasreqdfields = array('aliasdomain' . $idx);
120
		$aliasreqdfieldsn = array(gettext("Alias Domain"));
121
122
		var_dump(array('fields' => $aliasreqdfields, 'names' => $aliasreqdfieldsn, 'alias' => $alias));
123 1e9b4611 Renato Botelho
		do_input_validation($_POST, $aliasreqdfields, $aliasreqdfieldsn, $input_errors);
124 5a2a8349 Lorenz Schori
		if (($alias['host'] && !is_hostname($alias['host']))) {
125
			$input_errors[] = gettext("Hostnames in alias list can only contain the characters A-Z, 0-9 and '-'.");
126
		}
127
		if (($alias['domain'] && !is_domain($alias['domain']))) {
128
			$input_errors[] = gettext("A valid domain must be specified in alias list.");
129
		}
130
	}
131
132 5b237745 Scott Ullrich
	/* check for overlaps */
133
	foreach ($a_hosts as $hostent) {
134
		if (isset($id) && ($a_hosts[$id]) && ($a_hosts[$id] === $hostent))
135
			continue;
136
137 424be584 jim-p
		if (($hostent['host'] == $_POST['host']) && ($hostent['domain'] == $_POST['domain'])
138
			&& ((is_ipaddrv4($hostent['ip']) && is_ipaddrv4($_POST['ip'])) || (is_ipaddrv6($hostent['ip']) && is_ipaddrv6($_POST['ip'])))) {
139 065bc89a Rafael Lucas
			$input_errors[] = gettext("This host/domain already exists.");
140 5b237745 Scott Ullrich
			break;
141
		}
142
	}
143
144
	if (!$input_errors) {
145
		$hostent = array();
146
		$hostent['host'] = $_POST['host'];
147
		$hostent['domain'] = $_POST['domain'];
148
		$hostent['ip'] = $_POST['ip'];
149
		$hostent['descr'] = $_POST['descr'];
150 5a2a8349 Lorenz Schori
		$hostent['aliases']['item'] = $aliases;
151 5b237745 Scott Ullrich
152
		if (isset($id) && $a_hosts[$id])
153
			$a_hosts[$id] = $hostent;
154
		else
155
			$a_hosts[] = $hostent;
156 0e3aa71c Erik Fonnesbeck
		hosts_sort();
157 5b237745 Scott Ullrich
		
158 a368a026 Ermal Lu?i
		mark_subsystem_dirty('hosts');
159 5b237745 Scott Ullrich
		
160
		write_config();
161
		
162
		header("Location: services_dnsmasq.php");
163
		exit;
164
	}
165
}
166 b63695db Scott Ullrich
167 065bc89a Rafael Lucas
$pgtitle = array(gettext("Services"),gettext("DNS forwarder"),gettext("Edit host"));
168 b32dd0a6 jim-p
$shortcut_section = "resolver";
169 b63695db Scott Ullrich
include("head.inc");
170
171 5b237745 Scott Ullrich
?>
172
173 5a2a8349 Lorenz Schori
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
174 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
175 5a2a8349 Lorenz Schori
176
<script type="text/javascript" src="/javascript/row_helper.js">
177
</script>
178
179
<script type="text/javascript">
180 7bd5b320 Colin Fleming
//<![CDATA[
181 5a2a8349 Lorenz Schori
	rowname[0] = "aliashost";
182
	rowtype[0] = "textbox";
183
	rowsize[0] = "20";
184
	rowname[1] = "aliasdomain";
185
	rowtype[1] = "textbox";
186
	rowsize[1] = "20";
187
	rowname[2] = "aliasdescription";
188
	rowtype[2] = "textbox";
189
	rowsize[2] = "20";
190 7bd5b320 Colin Fleming
//]]>
191 5a2a8349 Lorenz Schori
</script>
192
193 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
194 4d6ba181 Scott Ullrich
        <form action="services_dnsmasq_edit.php" method="post" name="iform" id="iform">
195 7bd5b320 Colin Fleming
        <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="dns edit">
196 e22987a4 Scott Ullrich
				<tr>
197 065bc89a Rafael Lucas
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit DNS Forwarder entry");?></td>
198 e22987a4 Scott Ullrich
				</tr>	
199 5b237745 Scott Ullrich
                <tr>
200 065bc89a Rafael Lucas
                  <td width="22%" valign="top" class="vncell"><?=gettext("Host");?></td>
201 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
202 7bd5b320 Colin Fleming
                    <input name="host" type="text" class="formfld" id="host" size="40" value="<?=htmlspecialchars($pconfig['host']);?>" />
203 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("Name of the host, without".
204
                   " domain part"); ?><br />
205 463def4b Carlos Eduardo Ramos
                   <?=gettext("e.g."); ?> <em><?=gettext("myhost"); ?></em></span></td>
206 5b237745 Scott Ullrich
                </tr>
207
				<tr>
208 065bc89a Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Domain");?></td>
209 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
210 7bd5b320 Colin Fleming
                    <input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>" />
211 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("Domain of the host"); ?><br />
212 463def4b Carlos Eduardo Ramos
                   <?=gettext("e.g."); ?> <em><?=gettext("example.com"); ?></em></span></td>
213 5b237745 Scott Ullrich
                </tr>
214
				<tr>
215 065bc89a Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("IP address");?></td>
216 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
217 7bd5b320 Colin Fleming
                    <input name="ip" type="text" class="formfld" id="ip" size="40" value="<?=htmlspecialchars($pconfig['ip']);?>" />
218 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("IP address of the host"); ?><br />
219 4af6167d jim-p
                   <?=gettext("e.g."); ?> <em>192.168.100.100</em> <?=gettext("or"); ?> <em>fd00:abcd::1</em></span></td>
220 5b237745 Scott Ullrich
                </tr>
221
				<tr>
222 065bc89a Rafael Lucas
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
223 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
224 7bd5b320 Colin Fleming
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
225 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here".
226 065bc89a Rafael Lucas
                   " for your reference (not parsed).");?></span></td>
227 5b237745 Scott Ullrich
                </tr>
228 5a2a8349 Lorenz Schori
				<tr>
229 85d1b51b Lorenz Schori
                  <td width="22%" valign="top" class="vncell"><div id="addressnetworkport"><?=gettext("Aliases"); ?></div></td>
230
                  <td width="78%" class="vtable">
231 7bd5b320 Colin Fleming
                    <table id="maintable" summary="aliases">
232 85d1b51b Lorenz Schori
                      <tbody>
233
                        <tr>
234
                          <td colspan="4">
235
                            <div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">
236
                              <?=gettext("Enter additional names for this host."); ?>
237
                            </div>
238
                          </td>
239
                        </tr>
240
                        <tr>
241
                          <td><div id="onecolumn"><?=gettext("Host");?></div></td>
242
                          <td><div id="twocolumn"><?=gettext("Domain");?></div></td>
243
                          <td><div id="threecolumn"><?=gettext("Description");?></div></td>
244
                        </tr>
245
                        <?php
246
                          $counter = 0;
247
                          if($pconfig['aliases']['item']):
248
                            foreach($pconfig['aliases']['item'] as $item):
249
                              $host = $item['host'];
250
                              $domain = $item['domain'];
251
                              $description = $item['description'];
252
                        ?>
253
                        <tr>
254
                          <td>
255
                            <input autocomplete="off" name="aliashost<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliashost<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($host);?>" />
256
                          </td>
257
                          <td>
258
                            <input autocomplete="off" name="aliasdomain<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliasdomain<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($domain);?>" />
259
                          </td>
260
                          <td>
261
                            <input name="aliasdescription<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliasdescription<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($description);?>" />
262
                          </td>
263
                          <td>
264
                            <a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="" title="<?=gettext("remove this entry"); ?>" /></a>
265
                          </td>
266
                        </tr>
267
                        <?php
268
                              $counter++;
269
                            endforeach;
270
                          endif;
271
                        ?>
272
                      </tbody>
273
                    </table>
274
                    <a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
275
                      <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
276
                    </a>
277
                    <script type="text/javascript">
278 7bd5b320 Colin Fleming
                    //<![CDATA[
279 85d1b51b Lorenz Schori
                      field_counter_js = 3;
280
                      rows = 1;
281
                      totalrows = <?php echo $counter; ?>;
282
                      loaded = <?php echo $counter; ?>;
283 7bd5b320 Colin Fleming
                    //]]>
284 85d1b51b Lorenz Schori
                    </script>
285
                  </td>
286
                </tr>
287 5b237745 Scott Ullrich
                <tr>
288
                  <td width="22%" valign="top">&nbsp;</td>
289
                  <td width="78%"> 
290 7bd5b320 Colin Fleming
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> <input class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
291 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_hosts[$id]): ?>
292 7bd5b320 Colin Fleming
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
293 5b237745 Scott Ullrich
                    <?php endif; ?>
294
                  </td>
295
                </tr>
296 4d6ba181 Scott Ullrich
        </table>
297 5b237745 Scott Ullrich
</form>
298
<?php include("fend.inc"); ?>
299
</body>
300
</html>