Project

General

Profile

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