Project

General

Profile

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

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

    
408
                <tr id="r53_ttl" style="display:none">
409
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("TTL");?></td>
410
                  <td width="78%" class="vtable">
411
                    <input name="ttl" type="text" class="formfld user" id="ttl" size="20" value="<?=htmlspecialchars($pconfig['ttl']);?>" />
412
                    <br /><?= gettext("Choose TTL for your dns record.");?>
413
                  </td>
414
                </tr>
415

    
416

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

    
445
<script type="text/javascript">
446
//<![CDATA[
447
_onTypeChange("<?php echo $pconfig['type']; ?>");
448
//]]>
449
</script>
450

    
451
</body>
452
</html>
(160-160/256)