Projet

Général

Profil

Télécharger (12,3 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_dnsmasq_edit.php @ 62424bdb

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
	pfSense_MODULE:	dnsforwarder
33
*/
34

    
35
##|+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
function hostcmp($a, $b) {
43
	return strcasecmp($a['host'], $b['host']);
44
}
45

    
46
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

    
55
require("guiconfig.inc");
56

    
57
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_dnsmasq.php');
58

    
59
if (!is_array($config['dnsmasq']['hosts'])) 
60
	$config['dnsmasq']['hosts'] = array();
61

    
62
$a_hosts = &$config['dnsmasq']['hosts'];
63

    
64
if (is_numericint($_GET['id']))
65
	$id = $_GET['id'];
66
if (isset($_POST['id']) && is_numericint($_POST['id']))
67
	$id = $_POST['id'];
68

    
69
if (isset($id) && $a_hosts[$id]) {
70
	$pconfig['host'] = $a_hosts[$id]['host'];
71
	$pconfig['domain'] = $a_hosts[$id]['domain'];
72
	$pconfig['ip'] = $a_hosts[$id]['ip'];
73
	$pconfig['descr'] = $a_hosts[$id]['descr'];
74
	$pconfig['aliases'] = $a_hosts[$id]['aliases'];
75
}
76

    
77
if ($_POST) {
78

    
79
	unset($input_errors);
80
	$pconfig = $_POST;
81

    
82
	/* input validation */
83
	$reqdfields = explode(" ", "domain ip");
84
	$reqdfieldsn = array(gettext("Domain"),gettext("IP address"));
85
	
86
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
87
	
88
	if (($_POST['host'] && !is_hostname($_POST['host']))) 
89
		$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
90

    
91
	if (($_POST['domain'] && !is_domain($_POST['domain']))) 
92
		$input_errors[] = gettext("A valid domain must be specified.");
93
		
94
	if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) 
95
		$input_errors[] = gettext("A valid IP address must be specified.");
96

    
97
	/* collect aliases */
98
	$aliases = array();
99
	foreach ($_POST as $key => $value) {
100
		$entry = '';
101
		if (!substr_compare('aliashost', $key, 0, 9)) {
102
			$entry = substr($key, 9);
103
			$field = 'host';
104
		}
105
		elseif (!substr_compare('aliasdomain', $key, 0, 11)) {
106
			$entry = substr($key, 11);
107
			$field = 'domain';
108
		}
109
		elseif (!substr_compare('aliasdescription', $key, 0, 16)) {
110
			$entry = substr($key, 16);
111
			$field = 'description';
112
		}
113
		if (ctype_digit($entry)) {
114
			$aliases[$entry][$field] = $value;
115
		}
116
	}
117
	$pconfig['aliases']['item'] = $aliases;
118

    
119
	/* validate aliases */
120
	foreach ($aliases as $idx => $alias) {
121
		$aliasreqdfields = array('aliasdomain' . $idx);
122
		$aliasreqdfieldsn = array(gettext("Alias Domain"));
123

    
124
		var_dump(array('fields' => $aliasreqdfields, 'names' => $aliasreqdfieldsn, 'alias' => $alias));
125
		do_input_validation($_POST, $aliasreqdfields, $aliasreqdfieldsn, $input_errors);
126
		if (($alias['host'] && !is_hostname($alias['host']))) {
127
			$input_errors[] = gettext("Hostnames in alias list can only contain the characters A-Z, 0-9 and '-'.");
128
		}
129
		if (($alias['domain'] && !is_domain($alias['domain']))) {
130
			$input_errors[] = gettext("A valid domain must be specified in alias list.");
131
		}
132
	}
133

    
134
	/* check for overlaps */
135
	foreach ($a_hosts as $hostent) {
136
		if (isset($id) && ($a_hosts[$id]) && ($a_hosts[$id] === $hostent))
137
			continue;
138

    
139
		if (($hostent['host'] == $_POST['host']) && ($hostent['domain'] == $_POST['domain'])
140
			&& ((is_ipaddrv4($hostent['ip']) && is_ipaddrv4($_POST['ip'])) || (is_ipaddrv6($hostent['ip']) && is_ipaddrv6($_POST['ip'])))) {
141
			$input_errors[] = gettext("This host/domain already exists.");
142
			break;
143
		}
144
	}
145

    
146
	if (!$input_errors) {
147
		$hostent = array();
148
		$hostent['host'] = $_POST['host'];
149
		$hostent['domain'] = $_POST['domain'];
150
		$hostent['ip'] = $_POST['ip'];
151
		$hostent['descr'] = $_POST['descr'];
152
		$hostent['aliases']['item'] = $aliases;
153

    
154
		if (isset($id) && $a_hosts[$id])
155
			$a_hosts[$id] = $hostent;
156
		else
157
			$a_hosts[] = $hostent;
158
		hosts_sort();
159
		
160
		mark_subsystem_dirty('hosts');
161
		
162
		write_config();
163
		
164
		header("Location: services_dnsmasq.php");
165
		exit;
166
	}
167
}
168

    
169
$pgtitle = array(gettext("Services"),gettext("DNS forwarder"),gettext("Edit host"));
170
$shortcut_section = "resolver";
171
include("head.inc");
172

    
173
?>
174

    
175
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
176
<?php include("fbegin.inc"); ?>
177

    
178
<script type="text/javascript" src="/javascript/row_helper.js">
179
</script>
180

    
181
<script type="text/javascript">
182
//<![CDATA[
183
	rowname[0] = "aliashost";
184
	rowtype[0] = "textbox";
185
	rowsize[0] = "20";
186
	rowname[1] = "aliasdomain";
187
	rowtype[1] = "textbox";
188
	rowsize[1] = "20";
189
	rowname[2] = "aliasdescription";
190
	rowtype[2] = "textbox";
191
	rowsize[2] = "20";
192
//]]>
193
</script>
194

    
195
<?php if ($input_errors) print_input_errors($input_errors); ?>
196
        <form action="services_dnsmasq_edit.php" method="post" name="iform" id="iform">
197
        <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="dns edit">
198
				<tr>
199
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit DNS Forwarder entry");?></td>
200
				</tr>	
201
                <tr>
202
                  <td width="22%" valign="top" class="vncell"><?=gettext("Host");?></td>
203
                  <td width="78%" class="vtable"> 
204
                    <input name="host" type="text" class="formfld" id="host" size="40" value="<?=htmlspecialchars($pconfig['host']);?>" />
205
                    <br /> <span class="vexpl"><?=gettext("Name of the host, without".
206
                   " domain part"); ?><br />
207
                   <?=gettext("e.g."); ?> <em><?=gettext("myhost"); ?></em></span></td>
208
                </tr>
209
				<tr>
210
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Domain");?></td>
211
                  <td width="78%" class="vtable"> 
212
                    <input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>" />
213
                    <br /> <span class="vexpl"><?=gettext("Domain of the host"); ?><br />
214
                   <?=gettext("e.g."); ?> <em><?=gettext("example.com"); ?></em></span></td>
215
                </tr>
216
				<tr>
217
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("IP address");?></td>
218
                  <td width="78%" class="vtable"> 
219
                    <input name="ip" type="text" class="formfld" id="ip" size="40" value="<?=htmlspecialchars($pconfig['ip']);?>" />
220
                    <br /> <span class="vexpl"><?=gettext("IP address of the host"); ?><br />
221
                   <?=gettext("e.g."); ?> <em>192.168.100.100</em> <?=gettext("or"); ?> <em>fd00:abcd::1</em></span></td>
222
                </tr>
223
				<tr>
224
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
225
                  <td width="78%" class="vtable"> 
226
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
227
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here".
228
                   " for your reference (not parsed).");?></span></td>
229
                </tr>
230
				<tr>
231
                  <td width="22%" valign="top" class="vncell"><div id="addressnetworkport"><?=gettext("Aliases"); ?></div></td>
232
                  <td width="78%" class="vtable">
233
                    <table id="maintable" summary="aliases">
234
                      <tbody>
235
                        <tr>
236
                          <td colspan="4">
237
                            <div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">
238
                              <?=gettext("Enter additional names for this host."); ?>
239
                            </div>
240
                          </td>
241
                        </tr>
242
                        <tr>
243
                          <td><div id="onecolumn"><?=gettext("Host");?></div></td>
244
                          <td><div id="twocolumn"><?=gettext("Domain");?></div></td>
245
                          <td><div id="threecolumn"><?=gettext("Description");?></div></td>
246
                        </tr>
247
                        <?php
248
                          $counter = 0;
249
                          if($pconfig['aliases']['item']):
250
                            foreach($pconfig['aliases']['item'] as $item):
251
                              $host = $item['host'];
252
                              $domain = $item['domain'];
253
                              $description = $item['description'];
254
                        ?>
255
                        <tr>
256
                          <td>
257
                            <input autocomplete="off" name="aliashost<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliashost<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($host);?>" />
258
                          </td>
259
                          <td>
260
                            <input autocomplete="off" name="aliasdomain<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliasdomain<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($domain);?>" />
261
                          </td>
262
                          <td>
263
                            <input name="aliasdescription<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliasdescription<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($description);?>" />
264
                          </td>
265
                          <td>
266
                            <a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="" title="<?=gettext("remove this entry"); ?>" /></a>
267
                          </td>
268
                        </tr>
269
                        <?php
270
                              $counter++;
271
                            endforeach;
272
                          endif;
273
                        ?>
274
                      </tbody>
275
                    </table>
276
                    <a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
277
                      <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
278
                    </a>
279
                    <script type="text/javascript">
280
                    //<![CDATA[
281
                      field_counter_js = 3;
282
                      rows = 1;
283
                      totalrows = <?php echo $counter; ?>;
284
                      loaded = <?php echo $counter; ?>;
285
                    //]]>
286
                    </script>
287
                  </td>
288
                </tr>
289
                <tr>
290
                  <td width="22%" valign="top">&nbsp;</td>
291
                  <td width="78%"> 
292
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
293
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
294
                    <?php if (isset($id) && $a_hosts[$id]): ?>
295
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
296
                    <?php endif; ?>
297
                  </td>
298
                </tr>
299
        </table>
300
</form>
301
<?php include("fend.inc"); ?>
302
</body>
303
</html>
(158-158/256)