Project

General

Profile

Download (6.41 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
hosts_sort();
61
$a_hosts = &$config['dnsmasq']['hosts'];
62
63
$id = $_GET['id'];
64
if (isset($_POST['id']))
65
	$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
}
73
74
if ($_POST) {
75
76
	unset($input_errors);
77
	$pconfig = $_POST;
78
79
	/* input validation */
80
	$reqdfields = explode(" ", "domain ip");
81
	$reqdfieldsn = explode(",", "Domain,IP address");
82
	
83
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
84
	
85 4d6ba181 Scott Ullrich
	if (($_POST['host'] && !is_hostname($_POST['host']))) 
86 407f6220 Chris Buechler
		$input_errors[] = "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 5b237745 Scott Ullrich
		$input_errors[] = "A valid domain must be specified.";
90 4d6ba181 Scott Ullrich
		
91
	if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) 
92 5b237745 Scott Ullrich
		$input_errors[] = "A valid IP address must be specified.";
93
94
	/* check for overlaps */
95
	foreach ($a_hosts as $hostent) {
96
		if (isset($id) && ($a_hosts[$id]) && ($a_hosts[$id] === $hostent))
97
			continue;
98
99
		if (($hostent['host'] == $_POST['host']) && ($hostent['domain'] == $_POST['domain'])) {
100
			$input_errors[] = "This host/domain already exists.";
101
			break;
102
		}
103
	}
104
105
	if (!$input_errors) {
106
		$hostent = array();
107
		$hostent['host'] = $_POST['host'];
108
		$hostent['domain'] = $_POST['domain'];
109
		$hostent['ip'] = $_POST['ip'];
110
		$hostent['descr'] = $_POST['descr'];
111
112 0d64af59 Ermal Lu?i
		hosts_sort();
113 5b237745 Scott Ullrich
		if (isset($id) && $a_hosts[$id])
114
			$a_hosts[$id] = $hostent;
115
		else
116
			$a_hosts[] = $hostent;
117
		
118 a368a026 Ermal Lu?i
		mark_subsystem_dirty('hosts');
119 5b237745 Scott Ullrich
		
120
		write_config();
121
		
122
		header("Location: services_dnsmasq.php");
123
		exit;
124
	}
125
}
126 b63695db Scott Ullrich
127 d88c6a9f Scott Ullrich
$pgtitle = array("Services","DNS forwarder","Edit host");
128 b63695db Scott Ullrich
include("head.inc");
129
130 5b237745 Scott Ullrich
?>
131
132
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
133
<?php include("fbegin.inc"); ?>
134
<?php if ($input_errors) print_input_errors($input_errors); ?>
135 4d6ba181 Scott Ullrich
        <form action="services_dnsmasq_edit.php" method="post" name="iform" id="iform">
136
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
137 e22987a4 Scott Ullrich
				<tr>
138 341a01da Chris Buechler
					<td colspan="2" valign="top" class="listtopic">Edit DNS Forwarder entry</td>
139 e22987a4 Scott Ullrich
				</tr>	
140 5b237745 Scott Ullrich
                <tr>
141
                  <td width="22%" valign="top" class="vncell">Host</td>
142
                  <td width="78%" class="vtable"> 
143
                    <input name="host" type="text" class="formfld" id="host" size="40" value="<?=htmlspecialchars($pconfig['host']);?>">
144
                    <br> <span class="vexpl">Name of the host, without
145
                    domain part<br>
146
                    e.g. <em>myhost</em></span></td>
147
                </tr>
148
				<tr>
149
                  <td width="22%" valign="top" class="vncellreq">Domain</td>
150
                  <td width="78%" class="vtable"> 
151
                    <input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
152
                    <br> <span class="vexpl">Domain of the host<br>
153 341a01da Chris Buechler
                    e.g. <em>example.com</em></span></td>
154 5b237745 Scott Ullrich
                </tr>
155
				<tr>
156
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
157
                  <td width="78%" class="vtable"> 
158
                    <input name="ip" type="text" class="formfld" id="ip" size="40" value="<?=htmlspecialchars($pconfig['ip']);?>">
159
                    <br> <span class="vexpl">IP address of the host<br>
160
                    e.g. <em>192.168.100.100</em></span></td>
161
                </tr>
162
				<tr>
163
                  <td width="22%" valign="top" class="vncell">Description</td>
164
                  <td width="78%" class="vtable"> 
165
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
166
                    <br> <span class="vexpl">You may enter a description here
167
                    for your reference (not parsed).</span></td>
168
                </tr>
169
                <tr>
170
                  <td width="22%" valign="top">&nbsp;</td>
171
                  <td width="78%"> 
172 fc01e414 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
173 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_hosts[$id]): ?>
174
                    <input name="id" type="hidden" value="<?=$id;?>">
175
                    <?php endif; ?>
176
                  </td>
177
                </tr>
178 4d6ba181 Scott Ullrich
        </table>
179 5b237745 Scott Ullrich
</form>
180
<?php include("fend.inc"); ?>
181
</body>
182
</html>