Project

General

Profile

Feature #129 ยป 0001-cname-support-for-dnsmasq.patch

znerol znerol, 11/04/2009 11:46 AM

View differences:

etc/inc/services.inc
634 634
			}
635 635
		}
636 636

  
637
		if (isset($config['dnsmasq']['aliases']) && is_array($config['dnsmasq']['aliases'])) {
638
			foreach($config['dnsmasq']['aliases'] as $override) {
639
			        $args .= ' --cname=' . $override['alias'] . ',' . $override['host'];
640
			}
641
		}
637 642
		/* suppose that dnsmasq handles our domain and don't send
638 643
		requests for our local domain to upstream servers */
639 644
		//if (!empty($config['system']['domain'])) {
usr/local/www/services_dnsmasq.php
53 53

  
54 54

  
55 55
$a_hosts 	   = &$config['dnsmasq']['hosts'];
56
$a_aliases 	   = &$config['dnsmasq']['aliases'];
56 57
$a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
57 58

  
58 59
if ($_POST) {
......
73 74
	filter_configure();
74 75

  
75 76
	if ($retval == 0)
76
		clear_subsystem_dirty('hosts');
77
    clear_subsystem_dirty('hosts');
77 78
}
78 79

  
79 80
if ($_GET['act'] == "del") {
......
86 87
                       exit;
87 88
               }
88 89
       }
90
       elseif ($_GET['type'] == 'alias') {
91
               if ($a_aliases[$_GET['id']]) {
92
                       unset($a_aliases[$_GET['id']]);
93
                       write_config();
94
			mark_subsystem_dirty('hosts');
95
                       header("Location: services_dnsmasq.php");
96
                       exit;
97
               }
98
       }
89 99
       elseif ($_GET['type'] == 'doverride') {
90 100
               if ($a_domainOverrides[$_GET['id']]) {
91 101
                       unset($a_domainOverrides[$_GET['id']]);
......
220 230
                    </table>
221 231
		   </td>
222 232
	</table>
233
       &nbsp;<br>
234
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
235
	       <tr><td>&nbsp;</td></tr>
236
               <tr>
237
                 <td><p>Below you can define CNAME records for the hosts you entered in the previous table.</p></td>
238
               </tr>
239
        </table>
240
	&nbsp;<br>
241
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
242
                <tr>
243
                  <td width="30%" class="listhdrr">Alias</td>
244
                  <td width="30%" class="listhdrr">Target Host</td>
245
                  <td width="30%" class="listhdr">Description</td>
246
                  <td width="10%" class="list">
247
                    <table border="0" cellspacing="0" cellpadding="1">
248
                      <tr>
249
			<td width="17"></td>
250
                        <td valign="middle"><a href="services_dnsmasq_alias_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
251
                      </tr>
252
                    </table>
253
		  </td>
254
		</tr>
255
			  <?php $i = 0; foreach ($a_aliases as $aliasent): ?>
256
                <tr>
257
                  <td class="listlr" ondblclick="document.location='services_dnsmasq_alias_edit.php?id=<?=$i;?>';">
258
                    <?=strtolower($aliasent['alias']);?>&nbsp;
259
                  </td>
260
                  <td class="listr" ondblclick="document.location='services_dnsmasq_alias_edit.php?id=<?=$i;?>';">
261
                    <?=strtolower($aliasent['host']);?>&nbsp;
262
                  </td>
263
                  <td class="listbg" ondblclick="document.location='services_dnsmasq_alias_edit.php?id=<?=$i;?>';">
264
                    <?=htmlspecialchars($aliasent['descr']);?>&nbsp;
265
                  </td>
266
                  <td valign="middle" nowrap class="list">
267
                    <table border="0" cellspacing="0" cellpadding="1">
268
                      <tr>
269
                        <td valign="middle"><a href="services_dnsmasq_alias_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
270
                        <td><a href="services_dnsmasq.php?type=alias&act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this alias?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
271
		      </tr>
272
                   </table>
273
                </tr>
274
		<?php $i++; endforeach; ?>
275
                <tr>
276
                  <td class="list" colspan="4"></td>
277
                  <td class="list">
278
                    <table border="0" cellspacing="0" cellpadding="1">
279
                      <tr>
280
			<td width="17"></td>
281
                        <td valign="middle"><a href="services_dnsmasq_alias_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
282
                      </tr>
283
                    </table>
284
		   </td>
285
	</table>
286
	&nbsp;<br>
223 287
<!-- update to enable domain overrides -->
224 288
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
225 289
	       <tr><td>&nbsp;</td></tr>
usr/local/www/services_dnsmasq_alias_edit.php
1
<?php 
2
/* $Id$ */
3
/*
4
	services_dnsmasq_alias_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-editalias
37
##|*NAME=Services: DNS Forwarder: Edit alias page
38
##|*DESCR=Allow access to the 'Services: DNS Forwarder: Edit alias' page.
39
##|*MATCH=services_dnsmasq_edit.php*
40
##|-PRIV
41

  
42
function aliascmp($a, $b) {
43
	return strcasecmp($a['alias'], $b['alias']);
44
}
45

  
46
function aliases_sort() {
47
        global $g, $config;
48

  
49
        if (!is_array($config['dnsmasq']['aliases']))
50
                return;
51

  
52
        usort($config['dnsmasq']['aliases'], "aliascmp");
53
}
54

  
55
require("guiconfig.inc");
56

  
57
if (!is_array($config['dnsmasq']['aliases'])) 
58
	$config['dnsmasq']['aliases'] = array();
59

  
60
aliases_sort();
61
$a_aliases = &$config['dnsmasq']['aliases'];
62

  
63
$id = $_GET['id'];
64
if (isset($_POST['id']))
65
	$id = $_POST['id'];
66

  
67
if (isset($id) && $a_aliases[$id]) {
68
	$pconfig['alias'] = $a_aliases[$id]['alias'];
69
	$pconfig['host'] = $a_aliases[$id]['host'];
70
	$pconfig['descr'] = $a_aliases[$id]['descr'];
71
}
72

  
73
if ($_POST) {
74

  
75
	unset($input_errors);
76
	$pconfig = $_POST;
77

  
78
	/* input validation */
79
	$reqdfields = explode(" ", "alias,host");
80
	$reqdfieldsn = explode(",", "Alias,Host");
81
	
82
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
83
	
84
	if ($_POST['alias'] && !is_hostname($_POST['alias']) && !is_domain($_POST['alias']))
85
		$input_errors[] = "A valid alias must be specified.";
86

  
87
	if ($_POST['host'] && !is_hostname($_POST['host'])) 
88
		$input_errors[] = "A valid host must be specified.";
89
		
90
	if (!$input_errors) {
91
		$aliasent = array();
92
		$aliasent['alias'] = $_POST['alias'];
93
		$aliasent['host'] = $_POST['host'];
94
		$aliasent['descr'] = $_POST['descr'];
95

  
96
		aliases_sort();
97
		if (isset($id) && $a_aliases[$id])
98
			$a_aliases[$id] = $aliasent;
99
		else
100
			$a_aliases[] = $aliasent;
101
		
102
		mark_subsystem_dirty('hosts');
103
		
104
		write_config();
105
		
106
		header("Location: services_dnsmasq.php");
107
		exit;
108
	}
109
}
110

  
111
$pgtitle = array("Services","DNS forwarder","Edit alias");
112
include("head.inc");
113

  
114
?>
115

  
116
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
117
<?php include("fbegin.inc"); ?>
118
<?php if ($input_errors) print_input_errors($input_errors); ?>
119
        <form action="services_dnsmasq_edit.php" method="post" name="iform" id="iform">
120
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
121
				<tr>
122
					<td colspan="2" valign="top" class="listtopic">Edit DNS Alias entry</td>
123
				</tr>	
124
                <tr>
125
                  <td width="22%" valign="top" class="vncell">Alias</td>
126
                  <td width="78%" class="vtable"> 
127
                    <input name="alias" type="text" class="formfld" id="alias" size="40" value="<?=htmlspecialchars($pconfig['alias']);?>">
128
                    <br> <span class="vexpl">Name of the alias<br>
129
                    e.g. <em>myalias</em></span></td>
130
                </tr>
131
				<tr>
132
                  <td width="22%" valign="top" class="vncellreq">Host</td>
133
                  <td width="78%" class="vtable"> 
134
                    <input name="host" type="text" class="formfld" id="host" size="40" value="<?=htmlspecialchars($pconfig['host']);?>">
135
                    <br> <span class="vexpl">Target host<br>
136
                    e.g. <em>blah.com</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_aliases[$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>
    (1-1/1)