Project

General

Profile

Download (17.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	Copyright (C) 2008 Ermal Lu?i
5
	All rights reserved.
6

    
7
	Redistribution and use in source and binary forms, with or without
8
	modification, are permitted provided that the following conditions are met:
9

    
10
	1. Redistributions of source code must retain the above copyright notice,
11
	   this list of conditions and the following disclaimer.
12

    
13
	2. Redistributions in binary form must reproduce the above copyright
14
	   notice, this list of conditions and the following disclaimer in the
15
	   documentation and/or other materials provided with the distribution.
16

    
17
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
	POSSIBILITY OF SUCH DAMAGE.
27
*/
28
/*
29
	pfSense_BUILDER_BINARIES:	/bin/rm
30
	pfSense_MODULE:	dyndns
31
*/
32

    
33
##|+PRIV
34
##|*IDENT=page-services-dynamicdnsclient
35
##|*NAME=Services: Dynamic DNS client page
36
##|*DESCR=Allow access to the 'Services: Dynamic DNS client' page.
37
##|*MATCH=services_dyndns_edit.php*
38
##|-PRIV
39

    
40
/* returns true if $uname is a valid DynDNS username */
41
function is_dyndns_username($uname) {
42
        if (!is_string($uname))
43
                return false;
44
        
45
        if (preg_match("/[^a-z0-9\-.@_:]/i", $uname))
46
                return false;
47
        else
48
                return true;
49
}
50

    
51
require("guiconfig.inc");
52

    
53
if (!is_array($config['dyndnses']['dyndns'])) {
54
	$config['dyndnses']['dyndns'] = array();
55
}
56

    
57
$a_dyndns = &$config['dyndnses']['dyndns'];
58

    
59
$id = $_GET['id'];
60
if (isset($_POST['id']))
61
	$id = $_POST['id'];
62

    
63
if (isset($id) && isset($a_dyndns[$id])) {
64
	$pconfig['username'] = $a_dyndns[$id]['username'];
65
	$pconfig['password'] = $a_dyndns[$id]['password'];
66
	$pconfig['host'] = $a_dyndns[$id]['host'];
67
	$pconfig['mx'] = $a_dyndns[$id]['mx'];
68
	$pconfig['type'] = $a_dyndns[$id]['type'];
69
	$pconfig['enable'] = !isset($a_dyndns[$id]['enable']);
70
	$pconfig['interface'] = $a_dyndns[$id]['interface'];
71
	$pconfig['wildcard'] = isset($a_dyndns[$id]['wildcard']);
72
	$pconfig['zoneid'] = $a_dyndns[$id]['zoneid'];
73
	$pconfig['ttl'] = isset($a_dyndns[$id]['ttl']);
74
	$pconfig['updateurl'] = $a_dyndns[$id]['updateurl'];
75
	$pconfig['resultmatch'] = $a_dyndns[$id]['resultmatch'];
76
	$pconfig['requestif'] = $a_dyndns[$id]['requestif'];
77
	$pconfig['descr'] = $a_dyndns[$id]['descr'];
78
}
79

    
80
if ($_POST) {
81

    
82
	unset($input_errors);
83
	$pconfig = $_POST;
84
	
85
	if(($pconfig['type'] == "freedns" || $pconfig['type'] == "namecheap") && $_POST['username'] == "")
86
		$_POST['username'] = "none"; 
87

    
88
	/* input validation */
89
	$reqdfields = array();
90
	$reqdfieldsn = array();
91
	$reqdfields = array("type");
92
	$reqdfieldsn = array(gettext("Service type"));
93
	if ($pconfig['type'] != "custom") {
94
		$reqdfields[] = "host";
95
		$reqdfieldsn[] = gettext("Hostname");
96
		$reqdfields[] = "password";
97
		$reqdfieldsn[] = gettext("Password");
98
 		$reqdfields[] = "username";
99
 		$reqdfieldsn[] = gettext("Username");
100
	}else{
101
		$reqdfields[] = "updateurl";
102
		$reqdfieldsn[] = gettext("Update URL");
103
 	}
104

    
105
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
106

    
107
	if (($_POST['mx'] && !is_domain($_POST['mx']))) 
108
		$input_errors[] = gettext("The MX contains invalid characters.");
109
	if ((in_array("username", $reqdfields) && $_POST['username'] && !is_dyndns_username($_POST['username'])) || ((in_array("username", $reqdfields)) && ($_POST['username'] == ""))) 
110
 		$input_errors[] = gettext("The username contains invalid characters.");
111

    
112
	if (!$input_errors) {
113
		$dyndns = array();
114
		$dyndns['type'] = $_POST['type'];
115
		$dyndns['username'] = $_POST['username'];
116
		$dyndns['password'] = $_POST['password'];
117
		$dyndns['host'] = $_POST['host'];
118
		$dyndns['mx'] = $_POST['mx'];
119
		$dyndns['wildcard'] = $_POST['wildcard'] ? true : false;
120
		$dyndns['enable'] = $_POST['enable'] ? false : true;
121
		$dyndns['interface'] = $_POST['interface'];
122
		$dyndns['zoneid'] = $_POST['zoneid'];
123
		$dyndns['ttl'] = $_POST['ttl'];
124
		$dyndns['updateurl'] = $_POST['updateurl'];
125
		// Trim hard-to-type but sometimes returned characters
126
		$dyndns['resultmatch'] = trim($_POST['resultmatch'], "\t\n\r");
127
		$dyndns['type'] == "custom" ? $dyndns['requestif'] = $_POST['requestif'] : $dyndns['requestif'] = $_POST['interface'];
128
		$dyndns['descr'] = $_POST['descr'];
129
		$dyndns['force'] = isset($_POST['force']);
130
		
131
		if($dyndns['username'] == "none")
132
			$dyndns['username'] = "";
133

    
134
		if (isset($id) && $a_dyndns[$id])
135
			$a_dyndns[$id] = $dyndns;
136
		else {
137
 			$a_dyndns[] = $dyndns;
138
			$id = count($a_dyndns) - 1;
139
		}
140

    
141
		$dyndns['id'] = $id;
142
		//Probably overkill, but its better to be safe
143
		for($i = 0; $i < count($a_dyndns); $i++) {
144
			$a_dyndns[$i]['id'] = $i;
145
		}
146

    
147
		write_config();
148

    
149
		services_dyndns_configure_client($dyndns);
150

    
151
		header("Location: services_dyndns.php");
152
		exit;
153
	}
154
}
155

    
156
$pgtitle = array(gettext("Services"),gettext("Dynamic DNS client"));
157
include("head.inc");
158

    
159
?>
160

    
161
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
162
<?php include("fbegin.inc"); ?>
163
<?php if ($input_errors) print_input_errors($input_errors); ?>
164
<?php if ($savemsg) print_info_box($savemsg); ?>
165
<script type="text/javascript">
166
function _onTypeChange(type){ 
167
	switch(type) {
168
		case "custom":
169
			document.getElementById("_resulttr").style.display = '';
170
			document.getElementById("_urltr").style.display = '';
171
			document.getElementById("_requestiftr").style.display = '';
172
			document.getElementById("_hostnametr").style.display = 'none';
173
			document.getElementById("_mxtr").style.display = 'none';
174
			document.getElementById("_wildcardtr").style.display = 'none';
175
			document.getElementById("r53_zoneid").style.display='none';
176
			document.getElementById("r53_ttl").style.display='none';
177
			break;
178
		case "route53":
179
			document.getElementById("_resulttr").style.display = 'none';
180
			document.getElementById("_urltr").style.display = 'none';
181
			document.getElementById("_requestiftr").style.display = 'none';
182
			document.getElementById("_hostnametr").style.display = '';
183
			document.getElementById("_mxtr").style.display = '';
184
			document.getElementById("_wildcardtr").style.display = '';
185
			document.getElementById("r53_zoneid").style.display='';
186
			document.getElementById("r53_ttl").style.display='';
187
			break;
188
		default:
189
			document.getElementById("_resulttr").style.display = 'none';
190
			document.getElementById("_urltr").style.display = 'none';
191
			document.getElementById("_requestiftr").style.display = 'none';
192
			document.getElementById("_hostnametr").style.display = '';
193
			document.getElementById("_mxtr").style.display = '';
194
			document.getElementById("_wildcardtr").style.display = '';
195
			document.getElementById("r53_zoneid").style.display='none';
196
			document.getElementById("r53_ttl").style.display='none';
197
	}
198
}
199
</script>
200
<form action="services_dyndns_edit.php" method="post" name="iform" id="iform">
201
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
202
                <tr>
203
                  <td colspan="2" valign="top" class="optsect_t">
204
				  <table border="0" cellspacing="0" cellpadding="0" width="100%">
205
				  <tr><td class="optsect_s"><strong><?=gettext("Dynamic DNS client");?></strong></td></tr>
206
				  </table>
207
				  </td>
208
                </tr>
209
                <tr>
210
                  <td width="22%" valign="top" class="vncell"><?=gettext("Disable");?></td>
211
				  <td width="78%" class="vtable">
212
				    <input name="enable" type="checkbox" id="enable" value="<?=gettext("yes");?>" <?php if ($pconfig['enable']) echo "checked"; ?>>
213
				  </td>
214
                </tr>
215
                <tr>
216
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Service type");?></td>
217
                  <td width="78%" class="vtable">
218
			<select name="type" class="formselect" id="type" onchange="_onTypeChange(this.options[this.selectedIndex].value);">
219
                      <?php
220
						$types = explode(",", "DNS-O-Matic, DynDNS (dynamic),DynDNS (static),DynDNS (custom),DHS,DyNS,easyDNS,No-IP,ODS.org,ZoneEdit,Loopia,freeDNS, DNSexit, OpenDNS, Namecheap, HE.net, HE.net Tunnelbroker, SelfHost, Route 53, Custom");
221
						$vals = explode(" ", "dnsomatic dyndns dyndns-static dyndns-custom dhs dyns easydns noip ods zoneedit loopia freedns dnsexit opendns namecheap he-net he-net-tunnelbroker selfhost route53 custom");
222
						$j = 0; for ($j = 0; $j < count($vals); $j++): ?>
223
                      <option value="<?=$vals[$j];?>" <?php if ($vals[$j] == $pconfig['type']) echo "selected";?>>
224
                      <?=htmlspecialchars($types[$j]);?>
225
                      </option>
226
                      <?php endfor; ?>
227
                    </select></td>
228
				</tr>
229
				<tr>
230
				   <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface to monitor");?></td>  
231
				   <td width="78%" class="vtable">
232
				   <select name="interface" class="formselect" id="interface">
233
				<?php
234
					$iflist = get_configured_interface_with_descr();					
235
				   	foreach ($iflist as $if => $ifdesc) {
236
						echo "<option value=\"{$if}\"";
237
						if ($pconfig['interface'] == $if)
238
							echo "selected";
239
						echo ">{$ifdesc}</option>\n";
240
					}
241
					$grouplist = return_gateway_groups_array();
242
				   	foreach ($grouplist as $name => $group) {
243
						echo "<option value=\"{$name}\"";
244
						if ($pconfig['interface'] == $name)
245
							echo "selected";
246
						echo ">GW Group {$name}</option>\n";
247
					}
248
				?>
249
					</select>
250
					</td>
251
					</td>
252
				</tr>	
253
				<tr id="_requestiftr">
254
				   <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface to send update from");?></td>  
255
				   <td width="78%" class="vtable">
256
				   <select name="requestif" class="formselect" id="requestif">
257
				   <?php $iflist = get_configured_interface_with_descr();
258
				   		foreach ($iflist as $if => $ifdesc):?>
259
							<option value="<?=$if;?>" <?php if ($pconfig['requestif'] == $if) echo "selected";?>><?=$ifdesc;?></option>
260
					<?php endforeach; ?>
261
					</select>
262
					<br/><?= gettext("Note: This is almost always the same as the Interface to Monitor.");?>
263
					</td>
264
					</td>
265
				</tr>
266
                <tr id="_hostnametr">
267
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Hostname");?></td>
268
                  <td width="78%" class="vtable">
269
                    <input name="host" type="text" class="formfld unknown" id="host" size="30" value="<?=htmlspecialchars($pconfig['host']);?>">
270
                    <br>
271
				    <span class="vexpl">
272
				    <span class="red"><strong><?=gettext("Note:");?><br></strong>
273
				    </span>
274
					<?=gettext("Enter the complete host/domain name.  example:  myhost.dyndns.org");?><br/>
275
					<?=gettext("For he.net tunnelbroker, enter your tunnel ID");?>
276
				    </span>
277
		          </td>
278
				</tr>
279
                <tr id="_mxtr">
280
                  <td width="22%" valign="top" class="vncell"><?=gettext("MX"); ?></td>
281
                  <td width="78%" class="vtable">
282
                    <input name="mx" type="text" class="formfld unknown" id="mx" size="30" value="<?=htmlspecialchars($pconfig['mx']);?>">
283
                    <br>
284
					<?=gettext("Note: With DynDNS service you can only use a hostname, not an IP address.");?>
285
					<br>
286
                    <?=gettext("Set this option only if you need a special MX record. Not".
287
                   " all services support this.");?></td>
288
				</tr>
289
                <tr id="_wildcardtr">
290
                  <td width="22%" valign="top" class="vncell"><?=gettext("Wildcards"); ?></td>
291
                  <td width="78%" class="vtable">
292
                    <input name="wildcard" type="checkbox" id="wildcard" value="yes" <?php if ($pconfig['wildcard']) echo "checked"; ?>>
293
                    <?=gettext("Enable ");?><?=gettext("Wildcard"); ?></td>
294
				</tr>
295
                <tr id="_usernametr">
296
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Username");?></td>
297
                  <td width="78%" class="vtable">
298
                    <input name="username" type="text" class="formfld user" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>">
299
                    <br/><?= gettext("Username is required for all types except Namecheap, FreeDNS and Custom Entries.");?>
300
		    <br/><?= gettext("Route 53: Enter your Access Key ID.");?>
301
		    <br/><?= gettext("For Custom Entries, Username and Password represent HTTP Authentication username and passwords.");?>
302
                  </td>
303
                </tr>
304
                <tr>
305
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Password");?></td>
306
                  <td width="78%" class="vtable">
307
                    <input name="password" type="password" class="formfld pwd" id="password" size="20" value="<?=htmlspecialchars($pconfig['password']);?>">
308
                    <br/>
309
                    <?=gettext("FreeDNS (freedns.afraid.org): Enter your \"Authentication Token\" provided by FreeDNS.");?>
310
		    <br/><?= gettext("Route 53: Enter your Secret Access Key.");?>
311
                  </td>
312
                </tr>
313

    
314
                <tr id="r53_zoneid" style="display:none">
315
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Zone ID");?></td>
316
                  <td width="78%" class="vtable">
317
                    <input name="zoneid" type="text" class="formfld user" id="zoneid" size="20" value="<?=htmlspecialchars($pconfig['zoneid']);?>">
318
                    <br/><?= gettext("Enter Zone ID that you received when you created your domain in Route 53.");?>
319
                  </td>
320
                </tr>
321
                <tr id="_urltr">
322
                  <td width="22%" valign="top" class="vncell"><?=gettext("Update URL");?></td>
323
                  <td width="78%" class="vtable">
324
                    <input name="updateurl" type="text" class="formfld unknown" id="updateurl" size="60" value="<?=htmlspecialchars($pconfig['updateurl']);?>">
325
                    <br/><?= gettext("This is the only field required by for Custom Dynamic DNS, and is only used by Custom Entries.");?>
326
			<br/>
327
			<?= gettext("If you need the new IP to be included in the request, put %IP% in its place.");?>
328
                  </td>
329
                </tr>
330
		<tr id="_resulttr">
331
                  <td width="22%" valign="top" class="vncell"><?=gettext("Result Match");?></td>
332
                  <td width="78%" class="vtable">
333
                    <textarea name="resultmatch" class="formpre" id="resultmatch" cols="65" rows="7"><?=htmlspecialchars($pconfig['resultmatch']);?></textarea>
334
                    <br/><?= gettext("This field is only used by Custom Dynamic DNS Entries.");?>
335
			<br/>
336
			<?= gettext("This field should be identical to what your DDNS Provider will return if the update succeeds, leave it blank to disable checking of returned results.");?>
337
			<br/>
338
			<?= gettext("If you need the new IP to be included in the request, put %IP% in its place.");?>
339
			<br/>
340
			<?= gettext("If you need to include multiple possible values, sperate them with a |.  If your provider includes a |, escape it with \\|");?>
341
			<br/>
342
			<?= gettext("Tabs (\\t), newlines (\\n) and carriage returns (\\r) at the beginning or end of the returned results are removed before comparison.");?>
343
                  </td>
344
                </tr>
345
                <tr>
346

    
347
                <tr id="r53_ttl" style="display:none">
348
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("TTL");?></td>
349
                  <td width="78%" class="vtable">
350
                    <input name="ttl" type="text" class="formfld user" id="ttl" size="20" value="<?=htmlspecialchars($pconfig['ttl']);?>">
351
                    <br/><?= gettext("Choose TTL for your dns record.");?>
352
                  </td>
353
                </tr>
354
                <tr>
355

    
356

    
357
                <tr>
358
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
359
                  <td width="78%" class="vtable">
360
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>">
361
                  </td>
362
                </tr>
363
                <tr>
364
                  <td width="22%" valign="top">&nbsp;</td>
365
                  <td width="78%">
366
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onClick="enable_change(true)">
367
					<a href="services_dyndns.php"><input name="cancel" type="button" class="formbtn" value="<?=gettext("Cancel");?>"></a>
368
					<?php if (isset($id) && $a_dyndns[$id]): ?>
369
						<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
370
						<input name="force" type="submit" class="formbtn" value="<?=gettext("Save & Force Update");?>" onClick="enable_change(true)">
371
					<?php endif; ?>
372
                  </td>
373
                </tr>
374
                <tr>
375
                  <td width="22%" valign="top">&nbsp;</td>
376
                  <td width="78%"><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
377
                    </strong></span><?php printf(gettext("You must configure a DNS server in %sSystem:
378
                    General setup%s or allow the DNS server list to be overridden
379
                    by DHCP/PPP on WAN for dynamic DNS updates to work."),'<a href="system.php">','</a>');?></span></td>
380
                </tr>
381
              </table>
382
</form>
383
<?php include("fend.inc"); ?>
384

    
385
<script type="text/javascript">
386
_onTypeChange("<?php echo $pconfig['type']; ?>");
387
</script>
388

    
389
</body>
390
</html>
(158-158/249)