Project

General

Profile

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