Project

General

Profile

Download (6.04 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

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

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

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

    
91
		if (isset($id) && $a_hosts[$id])
92
			$a_hosts[$id] = $hostent;
93
		else
94
			$a_hosts[] = $hostent;
95
		
96
		touch($d_hostsdirty_path);
97
		
98
		write_config();
99
		
100
		header("Location: services_dnsmasq.php");
101
		exit;
102
	}
103
}
104
?>
105
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
106
<html>
107
<head>
108
<title><?=gentitle("Services: DNS forwarder: Edit host");?></title>
109
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
110
<link href="gui.css" rel="stylesheet" type="text/css">
111
</head>
112

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