| 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 |
424be584
|
jim-p
|
if (($hostent['host'] == $_POST['host']) && ($hostent['domain'] == $_POST['domain'])
|
| 99 |
|
|
&& ((is_ipaddrv4($hostent['ip']) && is_ipaddrv4($_POST['ip'])) || (is_ipaddrv6($hostent['ip']) && is_ipaddrv6($_POST['ip'])))) {
|
| 100 |
065bc89a
|
Rafael Lucas
|
$input_errors[] = gettext("This host/domain already exists.");
|
| 101 |
5b237745
|
Scott Ullrich
|
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 |
|
|
if (isset($id) && $a_hosts[$id])
|
| 113 |
|
|
$a_hosts[$id] = $hostent;
|
| 114 |
|
|
else
|
| 115 |
|
|
$a_hosts[] = $hostent;
|
| 116 |
0e3aa71c
|
Erik Fonnesbeck
|
hosts_sort();
|
| 117 |
5b237745
|
Scott Ullrich
|
|
| 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 |
065bc89a
|
Rafael Lucas
|
$pgtitle = array(gettext("Services"),gettext("DNS forwarder"),gettext("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 |
065bc89a
|
Rafael Lucas
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit DNS Forwarder entry");?></td>
|
| 139 |
e22987a4
|
Scott Ullrich
|
</tr>
|
| 140 |
5b237745
|
Scott Ullrich
|
<tr>
|
| 141 |
065bc89a
|
Rafael Lucas
|
<td width="22%" valign="top" class="vncell"><?=gettext("Host");?></td>
|
| 142 |
5b237745
|
Scott Ullrich
|
<td width="78%" class="vtable">
|
| 143 |
|
|
<input name="host" type="text" class="formfld" id="host" size="40" value="<?=htmlspecialchars($pconfig['host']);?>">
|
| 144 |
065bc89a
|
Rafael Lucas
|
<br> <span class="vexpl"><?=gettext("Name of the host, without".
|
| 145 |
463def4b
|
Carlos Eduardo Ramos
|
" domain part"); ?><br>
|
| 146 |
|
|
<?=gettext("e.g."); ?> <em><?=gettext("myhost"); ?></em></span></td>
|
| 147 |
5b237745
|
Scott Ullrich
|
</tr>
|
| 148 |
|
|
<tr>
|
| 149 |
065bc89a
|
Rafael Lucas
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Domain");?></td>
|
| 150 |
5b237745
|
Scott Ullrich
|
<td width="78%" class="vtable">
|
| 151 |
|
|
<input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
|
| 152 |
463def4b
|
Carlos Eduardo Ramos
|
<br> <span class="vexpl"><?=gettext("Domain of the host"); ?><br>
|
| 153 |
|
|
<?=gettext("e.g."); ?> <em><?=gettext("example.com"); ?></em></span></td>
|
| 154 |
5b237745
|
Scott Ullrich
|
</tr>
|
| 155 |
|
|
<tr>
|
| 156 |
065bc89a
|
Rafael Lucas
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("IP address");?></td>
|
| 157 |
5b237745
|
Scott Ullrich
|
<td width="78%" class="vtable">
|
| 158 |
|
|
<input name="ip" type="text" class="formfld" id="ip" size="40" value="<?=htmlspecialchars($pconfig['ip']);?>">
|
| 159 |
463def4b
|
Carlos Eduardo Ramos
|
<br> <span class="vexpl"><?=gettext("IP address of the host"); ?><br>
|
| 160 |
|
|
<?=gettext("e.g."); ?> <em>192.168.100.100</em></span></td>
|
| 161 |
5b237745
|
Scott Ullrich
|
</tr>
|
| 162 |
|
|
<tr>
|
| 163 |
065bc89a
|
Rafael Lucas
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
|
| 164 |
5b237745
|
Scott Ullrich
|
<td width="78%" class="vtable">
|
| 165 |
|
|
<input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
|
| 166 |
065bc89a
|
Rafael Lucas
|
<br> <span class="vexpl"><?=gettext("You may enter a description here".
|
| 167 |
|
|
" for your reference (not parsed).");?></span></td>
|
| 168 |
5b237745
|
Scott Ullrich
|
</tr>
|
| 169 |
|
|
<tr>
|
| 170 |
|
|
<td width="22%" valign="top"> </td>
|
| 171 |
|
|
<td width="78%">
|
| 172 |
065bc89a
|
Rafael Lucas
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>"> <input class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()">
|
| 173 |
5b237745
|
Scott Ullrich
|
<?php if (isset($id) && $a_hosts[$id]): ?>
|
| 174 |
225a2f0b
|
Scott Ullrich
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
|
| 175 |
5b237745
|
Scott Ullrich
|
<?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>
|