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
|
##|+PRIV
|
33
|
##|*IDENT=page-services-dnsforwarder-edithost
|
34
|
##|*NAME=Services: DNS Forwarder: Edit host page
|
35
|
##|*DESCR=Allow access to the 'Services: DNS Forwarder: Edit host' page.
|
36
|
##|*MATCH=services_dnsmasq_edit.php*
|
37
|
##|-PRIV
|
38
|
|
39
|
|
40
|
require("guiconfig.inc");
|
41
|
|
42
|
if (!is_array($config['dnsmasq']['hosts']))
|
43
|
$config['dnsmasq']['hosts'] = array();
|
44
|
|
45
|
hosts_sort();
|
46
|
$a_hosts = &$config['dnsmasq']['hosts'];
|
47
|
|
48
|
$id = $_GET['id'];
|
49
|
if (isset($_POST['id']))
|
50
|
$id = $_POST['id'];
|
51
|
|
52
|
if (isset($id) && $a_hosts[$id]) {
|
53
|
$pconfig['host'] = $a_hosts[$id]['host'];
|
54
|
$pconfig['domain'] = $a_hosts[$id]['domain'];
|
55
|
$pconfig['ip'] = $a_hosts[$id]['ip'];
|
56
|
$pconfig['descr'] = $a_hosts[$id]['descr'];
|
57
|
}
|
58
|
|
59
|
if ($_POST) {
|
60
|
|
61
|
unset($input_errors);
|
62
|
$pconfig = $_POST;
|
63
|
|
64
|
/* input validation */
|
65
|
$reqdfields = explode(" ", "domain ip");
|
66
|
$reqdfieldsn = explode(",", "Domain,IP address");
|
67
|
|
68
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
69
|
|
70
|
if (($_POST['host'] && !is_hostname($_POST['host'])))
|
71
|
$input_errors[] = "A valid host must be specified.";
|
72
|
|
73
|
if (($_POST['domain'] && !is_domain($_POST['domain'])))
|
74
|
$input_errors[] = "A valid domain must be specified.";
|
75
|
|
76
|
if (($_POST['ip'] && !is_ipaddr($_POST['ip'])))
|
77
|
$input_errors[] = "A valid IP address must be specified.";
|
78
|
|
79
|
/* check for overlaps */
|
80
|
foreach ($a_hosts as $hostent) {
|
81
|
if (isset($id) && ($a_hosts[$id]) && ($a_hosts[$id] === $hostent))
|
82
|
continue;
|
83
|
|
84
|
if (($hostent['host'] == $_POST['host']) && ($hostent['domain'] == $_POST['domain'])) {
|
85
|
$input_errors[] = "This host/domain already exists.";
|
86
|
break;
|
87
|
}
|
88
|
}
|
89
|
|
90
|
if (!$input_errors) {
|
91
|
$hostent = array();
|
92
|
$hostent['host'] = $_POST['host'];
|
93
|
$hostent['domain'] = $_POST['domain'];
|
94
|
$hostent['ip'] = $_POST['ip'];
|
95
|
$hostent['descr'] = $_POST['descr'];
|
96
|
|
97
|
if (isset($id) && $a_hosts[$id])
|
98
|
$a_hosts[$id] = $hostent;
|
99
|
else
|
100
|
$a_hosts[] = $hostent;
|
101
|
|
102
|
touch($d_hostsdirty_path);
|
103
|
|
104
|
write_config();
|
105
|
|
106
|
header("Location: services_dnsmasq.php");
|
107
|
exit;
|
108
|
}
|
109
|
}
|
110
|
|
111
|
$pgtitle = array("Services","DNS forwarder","Edit host");
|
112
|
include("head.inc");
|
113
|
|
114
|
?>
|
115
|
|
116
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
117
|
<?php include("fbegin.inc"); ?>
|
118
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
119
|
<form action="services_dnsmasq_edit.php" method="post" name="iform" id="iform">
|
120
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
121
|
<tr>
|
122
|
<td colspan="2" valign="top" class="listtopic">Edit DNS Forwareder entry</td>
|
123
|
</tr>
|
124
|
<tr>
|
125
|
<td width="22%" valign="top" class="vncell">Host</td>
|
126
|
<td width="78%" class="vtable">
|
127
|
<input name="host" type="text" class="formfld" id="host" size="40" value="<?=htmlspecialchars($pconfig['host']);?>">
|
128
|
<br> <span class="vexpl">Name of the host, without
|
129
|
domain part<br>
|
130
|
e.g. <em>myhost</em></span></td>
|
131
|
</tr>
|
132
|
<tr>
|
133
|
<td width="22%" valign="top" class="vncellreq">Domain</td>
|
134
|
<td width="78%" class="vtable">
|
135
|
<input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
|
136
|
<br> <span class="vexpl">Domain of the host<br>
|
137
|
e.g. <em>blah.com</em></span></td>
|
138
|
</tr>
|
139
|
<tr>
|
140
|
<td width="22%" valign="top" class="vncellreq">IP address</td>
|
141
|
<td width="78%" class="vtable">
|
142
|
<input name="ip" type="text" class="formfld" id="ip" size="40" value="<?=htmlspecialchars($pconfig['ip']);?>">
|
143
|
<br> <span class="vexpl">IP address of the host<br>
|
144
|
e.g. <em>192.168.100.100</em></span></td>
|
145
|
</tr>
|
146
|
<tr>
|
147
|
<td width="22%" valign="top" class="vncell">Description</td>
|
148
|
<td width="78%" class="vtable">
|
149
|
<input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
|
150
|
<br> <span class="vexpl">You may enter a description here
|
151
|
for your reference (not parsed).</span></td>
|
152
|
</tr>
|
153
|
<tr>
|
154
|
<td width="22%" valign="top"> </td>
|
155
|
<td width="78%">
|
156
|
<input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
|
157
|
<?php if (isset($id) && $a_hosts[$id]): ?>
|
158
|
<input name="id" type="hidden" value="<?=$id;?>">
|
159
|
<?php endif; ?>
|
160
|
</td>
|
161
|
</tr>
|
162
|
</table>
|
163
|
</form>
|
164
|
<?php include("fend.inc"); ?>
|
165
|
</body>
|
166
|
</html>
|