Project

General

Profile

Download (13.9 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 d03efa9c Scott Ullrich
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5
	services_dyndns.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7 d03efa9c Scott Ullrich
8 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10 d03efa9c Scott Ullrich
11 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13 d03efa9c Scott Ullrich
14 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16 d03efa9c Scott Ullrich
17 5b237745 Scott Ullrich
	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 d03efa9c Scott Ullrich
21 5b237745 Scott Ullrich
	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 07bd3f83 Scott Ullrich
if (!is_array($config['dnsupdate'])) {
36
	$config['dnsupdate'] = array();
37
}
38
39 5b237745 Scott Ullrich
$pconfig['username'] = $config['dyndns']['username'];
40
$pconfig['password'] = $config['dyndns']['password'];
41
$pconfig['host'] = $config['dyndns']['host'];
42
$pconfig['mx'] = $config['dyndns']['mx'];
43
$pconfig['type'] = $config['dyndns']['type'];
44
$pconfig['enable'] = isset($config['dyndns']['enable']);
45
$pconfig['wildcard'] = isset($config['dyndns']['wildcard']);
46
47 07bd3f83 Scott Ullrich
$pconfig['dnsupdate_enable'] = isset($config['dnsupdate']['enable']);
48
$pconfig['dnsupdate_host'] = $config['dnsupdate']['host'];
49
$pconfig['dnsupdate_ttl'] = $config['dnsupdate']['ttl'];
50
if (!$pconfig['dnsupdate_ttl'])
51
	$pconfig['dnsupdate_ttl'] = 60;
52
$pconfig['dnsupdate_keydata'] = $config['dnsupdate']['keydata'];
53
$pconfig['dnsupdate_keyname'] = $config['dnsupdate']['keyname'];
54
$pconfig['dnsupdate_keytype'] = $config['dnsupdate']['keytype'];
55
if (!$pconfig['dnsupdate_keytype'])
56
	$pconfig['dnsupdate_keytype'] = "zone";
57
$pconfig['dnsupdate_usetcp'] = isset($config['dnsupdate']['usetcp']);
58
59 5b237745 Scott Ullrich
if ($_POST) {
60
61
	unset($input_errors);
62
	$pconfig = $_POST;
63
64
	/* input validation */
65 07bd3f83 Scott Ullrich
	$reqdfields = array();
66
	$reqdfieldsn = array();
67 5b237745 Scott Ullrich
	if ($_POST['enable']) {
68 07bd3f83 Scott Ullrich
		$reqdfields = array_merge($reqdfields, explode(" ", "host username password type"));
69
		$reqdfieldsn = array_merge($reqdfieldsn, explode(",", "Hostname,Username,Password,Service type"));
70 5b237745 Scott Ullrich
	}
71 07bd3f83 Scott Ullrich
	if ($_POST['dnsupdate_enable']) {
72
		$reqdfields = array_merge($reqdfields, explode(" ", "dnsupdate_host dnsupdate_ttl dnsupdate_keyname dnsupdate_keydata"));
73
		$reqdfieldsn = array_merge($reqdfieldsn, explode(",", "Hostname,TTL,Key name,Key"));
74
	}
75
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
76 d03efa9c Scott Ullrich
77 5b237745 Scott Ullrich
	if (($_POST['host'] && !is_domain($_POST['host']))) {
78
		$input_errors[] = "The host name contains invalid characters.";
79
	}
80
	if (($_POST['mx'] && !is_domain($_POST['mx']))) {
81
		$input_errors[] = "The MX contains invalid characters.";
82
	}
83
	if (($_POST['username'] && !is_dyndns_username($_POST['username']))) {
84
		$input_errors[] = "The username contains invalid characters.";
85
	}
86 d03efa9c Scott Ullrich
87 07bd3f83 Scott Ullrich
	if (($_POST['dnsupdate_host'] && !is_domain($_POST['dnsupdate_host']))) {
88
		$input_errors[] = "The DNS update host name contains invalid characters.";
89
	}
90
	if (($_POST['dnsupdate_ttl'] && !is_numericint($_POST['dnsupdate_ttl']))) {
91
		$input_errors[] = "The DNS update TTL must be an integer.";
92
	}
93
	if (($_POST['dnsupdate_keyname'] && !is_domain($_POST['dnsupdate_keyname']))) {
94
		$input_errors[] = "The DNS update key name contains invalid characters.";
95
	}
96 5b237745 Scott Ullrich
97
	if (!$input_errors) {
98 d03efa9c Scott Ullrich
		$config['dyndns']['type'] = $_POST['type'];
99 5b237745 Scott Ullrich
		$config['dyndns']['username'] = $_POST['username'];
100
		$config['dyndns']['password'] = $_POST['password'];
101
		$config['dyndns']['host'] = $_POST['host'];
102
		$config['dyndns']['mx'] = $_POST['mx'];
103
		$config['dyndns']['wildcard'] = $_POST['wildcard'] ? true : false;
104
		$config['dyndns']['enable'] = $_POST['enable'] ? true : false;
105 d03efa9c Scott Ullrich
106 07bd3f83 Scott Ullrich
		$config['dnsupdate']['enable'] = $_POST['dnsupdate_enable'] ? true : false;
107
		$config['dnsupdate']['host'] = $_POST['dnsupdate_host'];
108
		$config['dnsupdate']['ttl'] = $_POST['dnsupdate_ttl'];
109
		$config['dnsupdate']['keyname'] = $_POST['dnsupdate_keyname'];
110
		$config['dnsupdate']['keytype'] = $_POST['dnsupdate_keytype'];
111
		$config['dnsupdate']['keydata'] = $_POST['dnsupdate_keydata'];
112
		$config['dnsupdate']['usetcp'] = $_POST['dnsupdate_usetcp'] ? true : false;
113 d03efa9c Scott Ullrich
114 5b237745 Scott Ullrich
		write_config();
115 d03efa9c Scott Ullrich
116 5b237745 Scott Ullrich
		$retval = 0;
117 3851094f Scott Ullrich
118
		/* nuke the cache file */
119
		config_lock();
120
		services_dyndns_reset();
121
		$retval = services_dyndns_configure();
122
		$retval |= services_dnsupdate_process();
123
		config_unlock();
124 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
125
	}
126
}
127 4df96eff Scott Ullrich
128
$pgtitle = "Services: Dynamic DNS client";
129
include("head.inc");
130
131 5b237745 Scott Ullrich
?>
132 4df96eff Scott Ullrich
133 5b237745 Scott Ullrich
<script language="JavaScript">
134
<!--
135
function enable_change(enable_change) {
136 07bd3f83 Scott Ullrich
	var endis;
137 d03efa9c Scott Ullrich
138 07bd3f83 Scott Ullrich
	endis = !(document.iform.enable.checked || enable_change);
139
	document.iform.host.disabled = endis;
140
	document.iform.mx.disabled = endis;
141
	document.iform.type.disabled = endis;
142
	document.iform.wildcard.disabled = endis;
143
	document.iform.username.disabled = endis;
144
	document.iform.password.disabled = endis;
145 d03efa9c Scott Ullrich
146 07bd3f83 Scott Ullrich
	endis = !(document.iform.dnsupdate_enable.checked || enable_change);
147
	document.iform.dnsupdate_host.disabled = endis;
148
	document.iform.dnsupdate_ttl.disabled = endis;
149
	document.iform.dnsupdate_keyname.disabled = endis;
150
	document.iform.dnsupdate_keytype[0].disabled = endis;
151
	document.iform.dnsupdate_keytype[1].disabled = endis;
152
	document.iform.dnsupdate_keytype[2].disabled = endis;
153
	document.iform.dnsupdate_keydata.disabled = endis;
154
	document.iform.dnsupdate_usetcp.disabled = endis;
155 5b237745 Scott Ullrich
}
156
//-->
157
</script>
158
159
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
160
<?php include("fbegin.inc"); ?>
161 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
162 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
163
<?php if ($savemsg) print_info_box($savemsg); ?>
164
            <form action="services_dyndns.php" method="post" name="iform" id="iform">
165
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
166 d03efa9c Scott Ullrich
                <tr>
167 07bd3f83 Scott Ullrich
                  <td colspan="2" valign="top" class="optsect_t">
168
				  <table border="0" cellspacing="0" cellpadding="0" width="100%">
169
				  <tr><td class="optsect_s"><strong>Dynamic DNS client</strong></td>
170
				  <td align="right" class="optsect_s"><input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)"> <strong>Enable</strong></td></tr>
171
				  </table></td>
172
                </tr>
173 d03efa9c Scott Ullrich
                <tr>
174 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Service type</td>
175
                  <td width="78%" class="vtable">
176
<select name="type" class="formfld" id="type">
177 ae187f34 Scott Ullrich
                      <?php #$types = explode(",", "DynDNS,DHS,ODS,DyNS,HN.ORG,GNUDip,DynDNS (static),DynDNS (custom),easyDNS,EZ-IP,TZO");
178
					        #$vals = explode(" ", "dyndns dhs ods dyns hn gnudip dyndns-static dyndns-custom easydns ezip tzo");
179
							$types = explode(",", "DynDNS (dynamic),DynDNS (static),DynDNS (custom),DHS,DyNS,HN.ORG,easyDNS,No-IP,ODS.org");
180
							$vals = explode(" ", "dyndns dyndns-static dyndns-custom dhs dyns hn easydns noip ods");
181 5b237745 Scott Ullrich
					  $j = 0; for ($j = 0; $j < count($vals); $j++): ?>
182 d03efa9c Scott Ullrich
                      <option value="<?=$vals[$j];?>" <?php if ($vals[$j] == $pconfig['type']) echo "selected";?>>
183 5b237745 Scott Ullrich
                      <?=htmlspecialchars($types[$j]);?>
184
                      </option>
185
                      <?php endfor; ?>
186
                    </select></td>
187
				</tr>
188 d03efa9c Scott Ullrich
                <tr>
189 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Hostname</td>
190 d03efa9c Scott Ullrich
                  <td width="78%" class="vtable">
191
                    <input name="host" type="text" class="formfld" id="host" size="30" value="<?=htmlspecialchars($pconfig['host']);?>">
192 39363e03 Scott Ullrich
		    <br>
193
		    <span class="vexpl">
194
		    <span class="red"><strong>Note:<br></strong>
195
		    </span>
196
			Enter the complete host/domain name.  example:  myhost.dyndns.org
197
		    </span>		    
198 5b237745 Scott Ullrich
                  </td>
199 39363e03 Scott Ullrich
		</tr>
200 d03efa9c Scott Ullrich
                <tr>
201 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">MX</td>
202 d03efa9c Scott Ullrich
                  <td width="78%" class="vtable">
203
                    <input name="mx" type="text" class="formfld" id="mx" size="30" value="<?=htmlspecialchars($pconfig['mx']);?>">
204 5b237745 Scott Ullrich
                    <br>
205 d03efa9c Scott Ullrich
                    Set this option only if you need a special MX record. Not
206 5b237745 Scott Ullrich
                    all services support this.</td>
207
				</tr>
208 d03efa9c Scott Ullrich
                <tr>
209 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Wildcards</td>
210 d03efa9c Scott Ullrich
                  <td width="78%" class="vtable">
211 07bd3f83 Scott Ullrich
                    <input name="wildcard" type="checkbox" id="wildcard" value="yes" <?php if ($pconfig['wildcard']) echo "checked"; ?>>
212 5b237745 Scott Ullrich
                    Enable Wildcard</td>
213
				</tr>
214 d03efa9c Scott Ullrich
                <tr>
215 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Username</td>
216 d03efa9c Scott Ullrich
                  <td width="78%" class="vtable">
217
                    <input name="username" type="text" class="formfld" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>">
218 5b237745 Scott Ullrich
                  </td>
219
                </tr>
220 d03efa9c Scott Ullrich
                <tr>
221 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Password</td>
222 d03efa9c Scott Ullrich
                  <td width="78%" class="vtable">
223
                    <input name="password" type="password" class="formfld" id="password" size="20" value="<?=htmlspecialchars($pconfig['password']);?>">
224 5b237745 Scott Ullrich
                  </td>
225
                </tr>
226 c0c2f422 Scott Ullrich
                <tr>
227
                  <td width="22%" valign="top">&nbsp;</td>
228
                  <td width="78%">
229
                    <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)">
230
                  </td>		
231 d03efa9c Scott Ullrich
                <tr>
232
                  <td colspan="2" class="list" height="12">&nbsp;</td>
233 c0c2f422 Scott Ullrich
                </tr>		
234 07bd3f83 Scott Ullrich
                </tr>
235 d03efa9c Scott Ullrich
                <tr>
236 07bd3f83 Scott Ullrich
                  <td colspan="2" valign="top" class="optsect_t">
237
				  <table border="0" cellspacing="0" cellpadding="0" width="100%">
238 183f3086 Bill Marquette
				  <tr><td class="optsect_s"><strong>RFC 2136 Dynamic DNS updates</strong></td>
239 07bd3f83 Scott Ullrich
				  <td align="right" class="optsect_s"><input name="dnsupdate_enable" type="checkbox" value="yes" <?php if ($pconfig['dnsupdate_enable']) echo "checked"; ?> onClick="enable_change(false)"> <strong>Enable</strong></td></tr>
240
				  </table></td>
241
                </tr>
242 d03efa9c Scott Ullrich
                <tr>
243 07bd3f83 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Hostname</td>
244 d03efa9c Scott Ullrich
                  <td width="78%" class="vtable">
245
                    <input name="dnsupdate_host" type="text" class="formfld" id="dnsupdate_host" size="30" value="<?=htmlspecialchars($pconfig['dnsupdate_host']);?>">
246 07bd3f83 Scott Ullrich
                  </td>
247
				</tr>
248
                <tr>
249
                  <td valign="top" class="vncellreq">TTL</td>
250
                  <td class="vtable">
251 d03efa9c Scott Ullrich
                    <input name="dnsupdate_ttl" type="text" class="formfld" id="dnsupdate_ttl" size="6" value="<?=htmlspecialchars($pconfig['dnsupdate_ttl']);?>">
252 07bd3f83 Scott Ullrich
                  seconds</td>
253
                </tr>
254
                <tr>
255
                  <td valign="top" class="vncellreq">Key name</td>
256
                  <td class="vtable">
257
                    <input name="dnsupdate_keyname" type="text" class="formfld" id="dnsupdate_keyname" size="30" value="<?=htmlspecialchars($pconfig['dnsupdate_keyname']);?>">
258 d03efa9c Scott Ullrich
                    <br>
259 07bd3f83 Scott Ullrich
                    This must match the setting on the DNS server.</td>
260
                </tr>
261
                <tr>
262
                  <td valign="top" class="vncellreq">Key type </td>
263
                  <td class="vtable">
264
				  <input name="dnsupdate_keytype" type="radio" value="zone" <?php if ($pconfig['dnsupdate_keytype'] == "zone") echo "checked"; ?>> Zone &nbsp;
265
                  <input name="dnsupdate_keytype" type="radio" value="host" <?php if ($pconfig['dnsupdate_keytype'] == "host") echo "checked"; ?>> Host &nbsp;
266
                  <input name="dnsupdate_keytype" type="radio" value="user" <?php if ($pconfig['dnsupdate_keytype'] == "user") echo "checked"; ?>> User
267
				</tr>
268
                <tr>
269
                  <td valign="top" class="vncellreq">Key</td>
270
                  <td class="vtable">
271
                    <input name="dnsupdate_keydata" type="text" class="formfld" id="dnsupdate_keydata" size="70" value="<?=htmlspecialchars($pconfig['dnsupdate_keydata']);?>">
272 d03efa9c Scott Ullrich
                    <br>
273 07bd3f83 Scott Ullrich
                    Paste an HMAC-MD5 key here.</td>
274
                </tr>
275 d03efa9c Scott Ullrich
                <tr>
276 07bd3f83 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
277 d03efa9c Scott Ullrich
                  <td width="78%" class="vtable">
278 07bd3f83 Scott Ullrich
                    <input name="dnsupdate_usetcp" type="checkbox" id="dnsupdate_usetcp" value="yes" <?php if ($pconfig['dnsupdate_usetcp']) echo "checked"; ?>>
279
                    <strong>Use TCP instead of UDP</strong></td>
280
				</tr>
281 d03efa9c Scott Ullrich
                <tr>
282 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
283 d03efa9c Scott Ullrich
                  <td width="78%">
284
                    <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)">
285 5b237745 Scott Ullrich
                  </td>
286
                </tr>
287 d03efa9c Scott Ullrich
                <tr>
288 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
289
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
290 d03efa9c Scott Ullrich
                    </strong></span>You must configure a DNS server in <a href="system.php">System:
291
                    General setup</a> or allow the DNS server list to be overridden
292 07bd3f83 Scott Ullrich
                    by DHCP/PPP on WAN for dynamic DNS updates to work.</span></td>
293 5b237745 Scott Ullrich
                </tr>
294
              </table>
295
</form>
296
<script language="JavaScript">
297
<!--
298
enable_change(false);
299
//-->
300
</script>
301
<?php include("fend.inc"); ?>
302
</body>
303
</html>