Project

General

Profile

Download (6.76 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/* $Id$ */
3
/*
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
/*
32
	pfSense_MODULE:	dnsforwarder
33
*/
34

    
35
##|+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
function hostcmp($a, $b) {
43
	return strcasecmp($a['host'], $b['host']);
44
}
45

    
46
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

    
55
require("guiconfig.inc");
56

    
57
if (!is_array($config['dnsmasq']['hosts'])) 
58
	$config['dnsmasq']['hosts'] = array();
59

    
60
$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
	$reqdfieldsn = array(gettext("Domain"),gettext("IP address"));
81
	
82
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
83
	
84
	if (($_POST['host'] && !is_hostname($_POST['host']))) 
85
		$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
86

    
87
	if (($_POST['domain'] && !is_domain($_POST['domain']))) 
88
		$input_errors[] = gettext("A valid domain must be specified.");
89
		
90
	if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) 
91
		$input_errors[] = gettext("A valid IP address must be specified.");
92

    
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
			$input_errors[] = gettext("This host/domain already exists.");
100
			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
		hosts_sort();
116
		
117
		mark_subsystem_dirty('hosts');
118
		
119
		write_config();
120
		
121
		header("Location: services_dnsmasq.php");
122
		exit;
123
	}
124
}
125

    
126
$pgtitle = array(gettext("Services"),gettext("DNS forwarder"),gettext("Edit host"));
127
include("head.inc");
128

    
129
?>
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
        <form action="services_dnsmasq_edit.php" method="post" name="iform" id="iform">
135
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
136
				<tr>
137
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit DNS Forwarder entry");?></td>
138
				</tr>	
139
                <tr>
140
                  <td width="22%" valign="top" class="vncell"><?=gettext("Host");?></td>
141
                  <td width="78%" class="vtable"> 
142
                    <input name="host" type="text" class="formfld" id="host" size="40" value="<?=htmlspecialchars($pconfig['host']);?>">
143
                    <br> <span class="vexpl"><?=gettext("Name of the host, without".
144
                   " domain part"); ?><br>
145
                   <?=gettext("e.g."); ?> <em><?=gettext("myhost"); ?></em></span></td>
146
                </tr>
147
				<tr>
148
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Domain");?></td>
149
                  <td width="78%" class="vtable"> 
150
                    <input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
151
                    <br> <span class="vexpl"><?=gettext("Domain of the host"); ?><br>
152
                   <?=gettext("e.g."); ?> <em><?=gettext("example.com"); ?></em></span></td>
153
                </tr>
154
				<tr>
155
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("IP address");?></td>
156
                  <td width="78%" class="vtable"> 
157
                    <input name="ip" type="text" class="formfld" id="ip" size="40" value="<?=htmlspecialchars($pconfig['ip']);?>">
158
                    <br> <span class="vexpl"><?=gettext("IP address of the host"); ?><br>
159
                   <?=gettext("e.g."); ?> <em>192.168.100.100</em></span></td>
160
                </tr>
161
				<tr>
162
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
163
                  <td width="78%" class="vtable"> 
164
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
165
                    <br> <span class="vexpl"><?=gettext("You may enter a description here".
166
                   " for your reference (not parsed).");?></span></td>
167
                </tr>
168
                <tr>
169
                  <td width="22%" valign="top">&nbsp;</td>
170
                  <td width="78%"> 
171
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>"> <input class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()">
172
                    <?php if (isset($id) && $a_hosts[$id]): ?>
173
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
174
                    <?php endif; ?>
175
                  </td>
176
                </tr>
177
        </table>
178
</form>
179
<?php include("fend.inc"); ?>
180
</body>
181
</html>
(140-140/222)