Project

General

Profile

Download (20.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services_dyndns_edit.php
5

    
6
	Copyright (C) 2008 Ermal Luçi
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
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_BUILDER_BINARIES:	/bin/rm
33
	pfSense_MODULE:	dyndns
34
*/
35

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

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

    
54
require("guiconfig.inc");
55

    
56
if (!is_array($config['dyndnses']['dyndns'])) {
57
	$config['dyndnses']['dyndns'] = array();
58
}
59

    
60
$a_dyndns = &$config['dyndnses']['dyndns'];
61

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

    
67
if (isset($id) && isset($a_dyndns[$id])) {
68
	$pconfig['username'] = $a_dyndns[$id]['username'];
69
	$pconfig['password'] = $a_dyndns[$id]['password'];
70
	$pconfig['host'] = $a_dyndns[$id]['host'];
71
	$pconfig['mx'] = $a_dyndns[$id]['mx'];
72
	$pconfig['type'] = $a_dyndns[$id]['type'];
73
	$pconfig['enable'] = !isset($a_dyndns[$id]['enable']);
74
	$pconfig['interface'] = $a_dyndns[$id]['interface'];
75
	$pconfig['wildcard'] = isset($a_dyndns[$id]['wildcard']);
76
	$pconfig['verboselog'] = isset($a_dyndns[$id]['verboselog']);
77
	$pconfig['curl_ipresolve_v4'] = isset($a_dyndns[$id]['curl_ipresolve_v4']);
78
	$pconfig['curl_ssl_verifypeer'] = isset($a_dyndns[$id]['curl_ssl_verifypeer']);
79
	$pconfig['zoneid'] = $a_dyndns[$id]['zoneid'];
80
	$pconfig['ttl'] = $a_dyndns[$id]['ttl'];
81
	$pconfig['updateurl'] = $a_dyndns[$id]['updateurl'];
82
	$pconfig['resultmatch'] = $a_dyndns[$id]['resultmatch'];
83
	$pconfig['requestif'] = $a_dyndns[$id]['requestif'];
84
	$pconfig['descr'] = $a_dyndns[$id]['descr'];
85
}
86

    
87
if ($_POST) {
88

    
89
	unset($input_errors);
90
	$pconfig = $_POST;
91
	
92
	if(($pconfig['type'] == "freedns" || $pconfig['type'] == "namecheap") && $_POST['username'] == "")
93
		$_POST['username'] = "none"; 
94

    
95
	/* input validation */
96
	$reqdfields = array();
97
	$reqdfieldsn = array();
98
	$reqdfields = array("type");
99
	$reqdfieldsn = array(gettext("Service type"));
100
	if ($pconfig['type'] != "custom" && $pconfig['type'] != "custom-v6") {
101
		$reqdfields[] = "host";
102
		$reqdfieldsn[] = gettext("Hostname");
103
		$reqdfields[] = "passwordfld";
104
		$reqdfieldsn[] = gettext("Password");
105
 		$reqdfields[] = "username";
106
 		$reqdfieldsn[] = gettext("Username");
107
	}else{
108
		$reqdfields[] = "updateurl";
109
		$reqdfieldsn[] = gettext("Update URL");
110
 	}
111

    
112
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
113

    
114
	if (isset($_POST['host']) && in_array("host", $reqdfields)) {
115
		/* Namecheap can have a @. in hostname */
116
		if ($pconfig['type'] == "namecheap" && substr($_POST['host'], 0, 2) == '@.')
117
			$host_to_check = substr($_POST['host'], 2);
118
		else
119
			$host_to_check = $_POST['host'];
120

    
121
		if ($pconfig['type'] != "custom" && $pconfig['type'] != "custom-v6")
122
			if (!is_domain($host_to_check))
123
				$input_errors[] = gettext("The hostname contains invalid characters.");
124

    
125
		unset($host_to_check);
126
	}
127
	if (($_POST['mx'] && !is_domain($_POST['mx']))) 
128
		$input_errors[] = gettext("The MX contains invalid characters.");
129
	if ((in_array("username", $reqdfields) && $_POST['username'] && !is_dyndns_username($_POST['username'])) || ((in_array("username", $reqdfields)) && ($_POST['username'] == ""))) 
130
 		$input_errors[] = gettext("The username contains invalid characters.");
131

    
132
	if (!$input_errors) {
133
		$dyndns = array();
134
		$dyndns['type'] = $_POST['type'];
135
		$dyndns['username'] = $_POST['username'];
136
		$dyndns['password'] = $_POST['passwordfld'];
137
		$dyndns['host'] = $_POST['host'];
138
		$dyndns['mx'] = $_POST['mx'];
139
		$dyndns['wildcard'] = $_POST['wildcard'] ? true : false;
140
		$dyndns['verboselog'] = $_POST['verboselog'] ? true : false;
141
		$dyndns['curl_ipresolve_v4'] = $_POST['curl_ipresolve_v4'] ? true : false;
142
		$dyndns['curl_ssl_verifypeer'] = $_POST['curl_ssl_verifypeer'] ? true : false;
143
		/* In this place enable means disabled */
144
		if ($_POST['enable'])
145
			unset($dyndns['enable']);
146
		else
147
			$dyndns['enable'] = true;
148
		$dyndns['interface'] = $_POST['interface'];
149
		$dyndns['zoneid'] = $_POST['zoneid'];
150
		$dyndns['ttl'] = $_POST['ttl'];
151
		$dyndns['updateurl'] = $_POST['updateurl'];
152
		// Trim hard-to-type but sometimes returned characters
153
		$dyndns['resultmatch'] = trim($_POST['resultmatch'], "\t\n\r");
154
		($dyndns['type'] == "custom" || $dyndns['type'] == "custom-v6") ? $dyndns['requestif'] = $_POST['requestif'] : $dyndns['requestif'] = $_POST['interface'];
155
		$dyndns['descr'] = $_POST['descr'];
156
		$dyndns['force'] = isset($_POST['force']);
157
		
158
		if($dyndns['username'] == "none")
159
			$dyndns['username'] = "";
160

    
161
		if (isset($id) && $a_dyndns[$id])
162
			$a_dyndns[$id] = $dyndns;
163
		else {
164
 			$a_dyndns[] = $dyndns;
165
			$id = count($a_dyndns) - 1;
166
		}
167

    
168
		$dyndns['id'] = $id;
169
		//Probably overkill, but its better to be safe
170
		for($i = 0; $i < count($a_dyndns); $i++) {
171
			$a_dyndns[$i]['id'] = $i;
172
		}
173

    
174
		write_config();
175

    
176
		services_dyndns_configure_client($dyndns);
177

    
178
		header("Location: services_dyndns.php");
179
		exit;
180
	}
181
}
182

    
183
$pgtitle = array(gettext("Services"),gettext("Dynamic DNS client"));
184
include("head.inc");
185

    
186
?>
187

    
188
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
189
<?php include("fbegin.inc"); ?>
190
<?php if ($input_errors) print_input_errors($input_errors); ?>
191
<?php if ($savemsg) print_info_box($savemsg); ?>
192
<script type="text/javascript">
193
//<![CDATA[
194
function _onTypeChange(type){ 
195
	switch(type) {
196
		case "custom":
197
		case "custom-v6":
198
			document.getElementById("_resulttr").style.display = '';
199
			document.getElementById("_urltr").style.display = '';
200
			document.getElementById("_requestiftr").style.display = '';
201
			document.getElementById("_curloptions").style.display = '';
202
			document.getElementById("_hostnametr").style.display = 'none';
203
			document.getElementById("_mxtr").style.display = 'none';
204
			document.getElementById("_wildcardtr").style.display = 'none';
205
			document.getElementById("r53_zoneid").style.display='none';
206
			document.getElementById("r53_ttl").style.display='none';
207
			break;
208
		case "dnsimple":
209
		case "route53":
210
			document.getElementById("_resulttr").style.display = 'none';
211
			document.getElementById("_urltr").style.display = 'none';
212
			document.getElementById("_requestiftr").style.display = 'none';
213
			document.getElementById("_curloptions").style.display = 'none';
214
			document.getElementById("_hostnametr").style.display = '';
215
			document.getElementById("_mxtr").style.display = '';
216
			document.getElementById("_wildcardtr").style.display = '';
217
			document.getElementById("r53_zoneid").style.display='';
218
			document.getElementById("r53_ttl").style.display='';
219
			break;
220
		default:
221
			document.getElementById("_resulttr").style.display = 'none';
222
			document.getElementById("_urltr").style.display = 'none';
223
			document.getElementById("_requestiftr").style.display = 'none';
224
			document.getElementById("_curloptions").style.display = 'none';
225
			document.getElementById("_hostnametr").style.display = '';
226
			document.getElementById("_mxtr").style.display = '';
227
			document.getElementById("_wildcardtr").style.display = '';
228
			document.getElementById("r53_zoneid").style.display='none';
229
			document.getElementById("r53_ttl").style.display='none';
230
	}
231
}
232
//]]>
233
</script>
234
<form action="services_dyndns_edit.php" method="post" name="iform" id="iform">
235
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="dynamic dns edit">
236
                <tr>
237
                  <td colspan="2" valign="top" class="optsect_t">
238
				  <table border="0" cellspacing="0" cellpadding="0" width="100%" summary="title">
239
				  <tr><td class="optsect_s"><strong><?=gettext("Dynamic DNS client");?></strong></td></tr>
240
				  </table>
241
				  </td>
242
                </tr>
243
                <tr>
244
                  <td width="22%" valign="top" class="vncell"><?=gettext("Disable");?></td>
245
				  <td width="78%" class="vtable">
246
				    <input name="enable" type="checkbox" id="enable" value="<?=gettext("yes");?>" <?php if ($pconfig['enable']) echo "checked=\"checked\""; ?> />
247
				  </td>
248
                </tr>
249
                <tr>
250
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Service type");?></td>
251
                  <td width="78%" class="vtable">
252
			<select name="type" class="formselect" id="type" onchange="_onTypeChange(this.options[this.selectedIndex].value);">
253
                      <?php
254
						$types = explode(",", DYNDNS_PROVIDER_DESCRIPTIONS);
255
						$vals = explode(" ", DYNDNS_PROVIDER_VALUES);
256
						$j = 0; for ($j = 0; $j < count($vals); $j++): ?>
257
                      <option value="<?=$vals[$j];?>" <?php if ($vals[$j] == $pconfig['type']) echo "selected=\"selected\"";?>>
258
                      <?=htmlspecialchars($types[$j]);?>
259
                      </option>
260
                      <?php endfor; ?>
261
                    </select></td>
262
				</tr>
263
				<tr>
264
				   <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface to monitor");?></td>  
265
				   <td width="78%" class="vtable">
266
				   <select name="interface" class="formselect" id="interface">
267
				<?php
268
					$iflist = get_configured_interface_with_descr();					
269
				   	foreach ($iflist as $if => $ifdesc) {
270
						echo "<option value=\"{$if}\"";
271
						if ($pconfig['interface'] == $if)
272
							echo "selected=\"selected\"";
273
						echo ">{$ifdesc}</option>\n";
274
					}
275
					unset($iflist);
276
					$grouplist = return_gateway_groups_array();
277
				   	foreach ($grouplist as $name => $group) {
278
						echo "<option value=\"{$name}\"";
279
						if ($pconfig['interface'] == $name)
280
							echo "selected=\"selected\"";
281
						echo ">GW Group {$name}</option>\n";
282
					}
283
					unset($grouplist);
284
				?>
285
					</select>
286
					</td>
287
				</tr>	
288
				<tr id="_requestiftr">
289
					<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface to send update from");?></td>  
290
					<td width="78%" class="vtable">
291
					<select name="requestif" class="formselect" id="requestif">
292
				<?php
293
					$iflist = get_configured_interface_with_descr();					
294
					foreach ($iflist as $if => $ifdesc) {
295
						echo "<option value=\"{$if}\"";
296
						if ($pconfig['requestif'] == $if)
297
							echo "selected=\"selected\"";
298
						echo ">{$ifdesc}</option>\n";
299
					}
300
					unset($iflist);
301
					$grouplist = return_gateway_groups_array();
302
					foreach ($grouplist as $name => $group) {
303
						echo "<option value=\"{$name}\"";
304
						if ($pconfig['requestif'] == $name)
305
							echo "selected=\"selected\"";
306
						echo ">GW Group {$name}</option>\n";
307
					}
308
					unset($grouplist);
309
				?>
310
					</select>
311
					<br /><?= gettext("Note: This is almost always the same as the Interface to Monitor.");?>
312
					</td>
313
				</tr>
314
                <tr id="_hostnametr">
315
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Hostname");?></td>
316
                  <td width="78%" class="vtable">
317
                    <input name="host" type="text" class="formfld unknown" id="host" size="30" value="<?=htmlspecialchars($pconfig['host']);?>" />
318
                    <br />
319
				    <span class="vexpl">
320
				    <span class="red"><strong><?=gettext("Note:");?><br /></strong>
321
				    </span>
322
					<?=gettext("Enter the complete host/domain name.  example:  myhost.dyndns.org");?><br />
323
					<?=gettext("he.net tunnelbroker: Enter your tunnel ID");?><br />
324
					<?=gettext("GleSYS: Enter your record ID");?><br />
325
					<?= gettext("DNSimple: Enter only the domain name.");?>
326
				    </span>
327
		          </td>
328
				</tr>
329
                <tr id="_mxtr">
330
                  <td width="22%" valign="top" class="vncell"><?=gettext("MX"); ?></td>
331
                  <td width="78%" class="vtable">
332
                    <input name="mx" type="text" class="formfld unknown" id="mx" size="30" value="<?=htmlspecialchars($pconfig['mx']);?>" />
333
                    <br />
334
					<?=gettext("Note: With DynDNS service you can only use a hostname, not an IP address.");?>
335
					<br />
336
                    <?=gettext("Set this option only if you need a special MX record. Not".
337
                   " all services support this.");?></td>
338
				</tr>
339
                <tr id="_wildcardtr">
340
                  <td width="22%" valign="top" class="vncell"><?=gettext("Wildcards"); ?></td>
341
                  <td width="78%" class="vtable">
342
                    <input name="wildcard" type="checkbox" id="wildcard" value="yes" <?php if ($pconfig['wildcard']) echo "checked=\"checked\""; ?> />
343
                    <?=gettext("Enable ");?><?=gettext("Wildcard"); ?></td>
344
				</tr>
345
                <tr id="_verboselogtr">
346
                  <td width="22%" valign="top" class="vncell"><?=gettext("Verbose logging"); ?></td>
347
                  <td width="78%" class="vtable">
348
                    <input name="verboselog" type="checkbox" id="verboselog" value="yes" <?php if ($pconfig['verboselog']) echo "checked=\"checked\""; ?> />
349
                    <?=gettext("Enable ");?><?=gettext("verbose logging"); ?></td>
350
				</tr>
351
				<tr id="_curloptions">
352
                  <td width="22%" valign="top" class="vncell"><?=gettext("CURL options"); ?></td>
353
                  <td width="78%" class="vtable">
354
                    <input name="curl_ipresolve_v4" type="checkbox" id="curl_ipresolve_v4" value="yes" <?php if ($pconfig['curl_ipresolve_v4']) echo "checked=\"checked\""; ?> />
355
                    <?=gettext("Force IPv4 resolving"); ?><br />
356
					<input name="curl_ssl_verifypeer" type="checkbox" id="curl_ssl_verifypeer" value="yes" <?php if ($pconfig['curl_ssl_verifypeer']) echo "checked=\"checked\""; ?> />
357
                    <?=gettext("Verify SSL peer"); ?>
358
				  </td>
359
				</tr>
360
                <tr id="_usernametr">
361
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Username");?></td>
362
                  <td width="78%" class="vtable">
363
                    <input name="username" type="text" class="formfld user" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>" />
364
                    <br /><?= gettext("Username is required for all types except Namecheap, FreeDNS and Custom Entries.");?>
365
                    <br /><?= gettext("Route 53: Enter your Access Key ID.");?>
366
                    <br /><?= gettext("GleSYS: Enter your API user.");?>
367
                    <br /><?= gettext("For Custom Entries, Username and Password represent HTTP Authentication username and passwords.");?>
368
                  </td>
369
                </tr>
370
                <tr>
371
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Password");?></td>
372
                  <td width="78%" class="vtable">
373
                    <input name="passwordfld" type="password" class="formfld pwd" id="passwordfld" size="20" value="<?=htmlspecialchars($pconfig['password']);?>" />
374
                    <br />
375
                    <?=gettext("FreeDNS (freedns.afraid.org): Enter your \"Authentication Token\" provided by FreeDNS.");?>
376
                    <br /><?= gettext("Route 53: Enter your Secret Access Key.");?>
377
                    <br /><?= gettext("GleSYS: Enter your API key.");?>
378
                    <br /><?= gettext("DNSimple: Enter your API token.");?>
379
                  </td>
380
                </tr>
381

    
382
                <tr id="r53_zoneid" style="display:none">
383
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Zone ID");?></td>
384
                  <td width="78%" class="vtable">
385
                    <input name="zoneid" type="text" class="formfld user" id="zoneid" size="20" value="<?=htmlspecialchars($pconfig['zoneid']);?>" />
386
                    <br /><?= gettext("Enter Zone ID that you received when you created your domain in Route 53.");?>
387
                    <br /><?= gettext("DNSimple: Enter the Record ID of record to update.");?>
388
                  </td>
389
                </tr>
390
                <tr id="_urltr">
391
                  <td width="22%" valign="top" class="vncell"><?=gettext("Update URL");?></td>
392
                  <td width="78%" class="vtable">
393
                    <input name="updateurl" type="text" class="formfld unknown" id="updateurl" size="60" value="<?=htmlspecialchars($pconfig['updateurl']);?>" />
394
                    <br /><?= gettext("This is the only field required by for Custom Dynamic DNS, and is only used by Custom Entries.");?>
395
			<br />
396
			<?= gettext("If you need the new IP to be included in the request, put %IP% in its place.");?>
397
                  </td>
398
                </tr>
399
		<tr id="_resulttr">
400
                  <td width="22%" valign="top" class="vncell"><?=gettext("Result Match");?></td>
401
                  <td width="78%" class="vtable">
402
                    <textarea name="resultmatch" class="formpre" id="resultmatch" cols="65" rows="7"><?=htmlspecialchars($pconfig['resultmatch']);?></textarea>
403
                    <br /><?= gettext("This field is only used by Custom Dynamic DNS Entries.");?>
404
			<br />
405
			<?= 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.");?>
406
			<br />
407
			<?= gettext("If you need the new IP to be included in the request, put %IP% in its place.");?>
408
			<br />
409
			<?= gettext("If you need to include multiple possible values, separate them with a |.  If your provider includes a |, escape it with \\|");?>
410
			<br />
411
			<?= gettext("Tabs (\\t), newlines (\\n) and carriage returns (\\r) at the beginning or end of the returned results are removed before comparison.");?>
412
                  </td>
413
                </tr>
414

    
415
                <tr id="r53_ttl" style="display:none">
416
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("TTL");?></td>
417
                  <td width="78%" class="vtable">
418
                    <input name="ttl" type="text" class="formfld user" id="ttl" size="20" value="<?=htmlspecialchars($pconfig['ttl']);?>" />
419
                    <br /><?= gettext("Choose TTL for your dns record.");?>
420
                  </td>
421
                </tr>
422

    
423

    
424
                <tr>
425
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
426
                  <td width="78%" class="vtable">
427
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>" />
428
                  </td>
429
                </tr>
430
                <tr>
431
                  <td width="22%" valign="top">&nbsp;</td>
432
                  <td width="78%">
433
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)" />
434
					<a href="services_dyndns.php"><input name="cancel" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
435
					<?php if (isset($id) && $a_dyndns[$id]): ?>
436
						<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
437
						<input name="force" type="submit" class="formbtn" value="<?=gettext("Save & Force Update");?>" onclick="enable_change(true)" />
438
					<?php endif; ?>
439
                  </td>
440
                </tr>
441
                <tr>
442
                  <td width="22%" valign="top">&nbsp;</td>
443
                  <td width="78%"><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br />
444
                    </strong></span><?php printf(gettext("You must configure a DNS server in %sSystem:
445
                    General setup%s or allow the DNS server list to be overridden
446
                    by DHCP/PPP on WAN for dynamic DNS updates to work."),'<a href="system.php">','</a>');?></span></td>
447
                </tr>
448
              </table>
449
</form>
450
<?php include("fend.inc"); ?>
451

    
452
<script type="text/javascript">
453
//<![CDATA[
454
_onTypeChange("<?php echo $pconfig['type']; ?>");
455
//]]>
456
</script>
457

    
458
</body>
459
</html>
(160-160/256)