Project

General

Profile

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