Project

General

Profile

Download (20.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	Copyright (C) 2008 Ermal Luçi
5
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
6
	All rights reserved.
7

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

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

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

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

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

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

    
52
require("guiconfig.inc");
53

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

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

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

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

    
85
if ($_POST) {
86

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

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

    
110
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
111

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

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

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

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

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

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

    
172
		write_config();
173

    
174
		services_dyndns_configure_client($dyndns);
175

    
176
		header("Location: services_dyndns.php");
177
		exit;
178
	}
179
}
180

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

    
184
?>
185

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

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

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

    
414

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

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

    
449
</body>
450
</html>
(160-160/256)