Project

General

Profile

Download (5.82 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
3
/* $Id$ */
4
/*
5
	services_dnsmasq_edit.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7
	
8
	Copyright (C) 2003-2004 Bob Zoller <bob@kludgebox.com> and Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10
	
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
	
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
	
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
	
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32

    
33
require("guiconfig.inc");
34

    
35
if (!is_array($config['dnsmasq']['hosts'])) 
36
	$config['dnsmasq']['hosts'] = array();
37

    
38
hosts_sort();
39
$a_hosts = &$config['dnsmasq']['hosts'];
40

    
41
$id = $_GET['id'];
42
if (isset($_POST['id']))
43
	$id = $_POST['id'];
44

    
45
if (isset($id) && $a_hosts[$id]) {
46
	$pconfig['host'] = $a_hosts[$id]['host'];
47
	$pconfig['domain'] = $a_hosts[$id]['domain'];
48
	$pconfig['ip'] = $a_hosts[$id]['ip'];
49
	$pconfig['descr'] = $a_hosts[$id]['descr'];
50
}
51

    
52
if ($_POST) {
53

    
54
	unset($input_errors);
55
	$pconfig = $_POST;
56

    
57
	/* input validation */
58
	$reqdfields = explode(" ", "domain ip");
59
	$reqdfieldsn = explode(",", "Domain,IP address");
60
	
61
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
62
	
63
	if (($_POST['host'] && !is_hostname($_POST['host']))) 
64
		$input_errors[] = "A valid host must be specified.";
65

    
66
	if (($_POST['domain'] && !is_domain($_POST['domain']))) 
67
		$input_errors[] = "A valid domain must be specified.";
68
		
69
	if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) 
70
		$input_errors[] = "A valid IP address must be specified.";
71

    
72
	/* check for overlaps */
73
	foreach ($a_hosts as $hostent) {
74
		if (isset($id) && ($a_hosts[$id]) && ($a_hosts[$id] === $hostent))
75
			continue;
76

    
77
		if (($hostent['host'] == $_POST['host']) && ($hostent['domain'] == $_POST['domain'])) {
78
			$input_errors[] = "This host/domain already exists.";
79
			break;
80
		}
81
	}
82

    
83
	if (!$input_errors) {
84
		$hostent = array();
85
		$hostent['host'] = $_POST['host'];
86
		$hostent['domain'] = $_POST['domain'];
87
		$hostent['ip'] = $_POST['ip'];
88
		$hostent['descr'] = $_POST['descr'];
89

    
90
		if (isset($id) && $a_hosts[$id])
91
			$a_hosts[$id] = $hostent;
92
		else
93
			$a_hosts[] = $hostent;
94
		
95
		touch($d_hostsdirty_path);
96
		
97
		write_config();
98
		
99
		header("Location: services_dnsmasq.php");
100
		exit;
101
	}
102
}
103

    
104
$pgtitle = "Services: DNS forwarder: Edit host";
105
include("head.inc");
106

    
107
?>
108

    
109
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
110
<?php include("fbegin.inc"); ?>
111
<p class="pgtitle"><?=$pgtitle?></p>
112
<?php if ($input_errors) print_input_errors($input_errors); ?>
113
        <form action="services_dnsmasq_edit.php" method="post" name="iform" id="iform">
114
        <?display_topbar()?>
115
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
116
                <tr>
117
                  <td width="22%" valign="top" class="vncell">Host</td>
118
                  <td width="78%" class="vtable"> 
119
                    <input name="host" type="text" class="formfld" id="host" size="40" value="<?=htmlspecialchars($pconfig['host']);?>">
120
                    <br> <span class="vexpl">Name of the host, without
121
                    domain part<br>
122
                    e.g. <em>myhost</em></span></td>
123
                </tr>
124
				<tr>
125
                  <td width="22%" valign="top" class="vncellreq">Domain</td>
126
                  <td width="78%" class="vtable"> 
127
                    <input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
128
                    <br> <span class="vexpl">Domain of the host<br>
129
                    e.g. <em>blah.com</em></span></td>
130
                </tr>
131
				<tr>
132
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
133
                  <td width="78%" class="vtable"> 
134
                    <input name="ip" type="text" class="formfld" id="ip" size="40" value="<?=htmlspecialchars($pconfig['ip']);?>">
135
                    <br> <span class="vexpl">IP address of the host<br>
136
                    e.g. <em>192.168.100.100</em></span></td>
137
                </tr>
138
				<tr>
139
                  <td width="22%" valign="top" class="vncell">Description</td>
140
                  <td width="78%" class="vtable"> 
141
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
142
                    <br> <span class="vexpl">You may enter a description here
143
                    for your reference (not parsed).</span></td>
144
                </tr>
145
                <tr>
146
                  <td width="22%" valign="top">&nbsp;</td>
147
                  <td width="78%"> 
148
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
149
                    <?php if (isset($id) && $a_hosts[$id]): ?>
150
                    <input name="id" type="hidden" value="<?=$id;?>">
151
                    <?php endif; ?>
152
                  </td>
153
                </tr>
154
        </table>
155
</form>
156
<?php include("fend.inc"); ?>
157
</body>
158
</html>
(92-92/133)