Project

General

Profile

Download (19.1 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['verboselog'] = isset($a_dyndns[$id]['verboselog']);
73
	$pconfig['curl_ipresolve_v4'] = isset($a_dyndns[$id]['curl_ipresolve_v4']);
74
	$pconfig['curl_ssl_verifypeer'] = isset($a_dyndns[$id]['curl_ssl_verifypeer']);
75
	$pconfig['zoneid'] = $a_dyndns[$id]['zoneid'];
76
	$pconfig['ttl'] = $a_dyndns[$id]['ttl'];
77
	$pconfig['updateurl'] = $a_dyndns[$id]['updateurl'];
78
	$pconfig['resultmatch'] = $a_dyndns[$id]['resultmatch'];
79
	$pconfig['requestif'] = $a_dyndns[$id]['requestif'];
80
	$pconfig['descr'] = $a_dyndns[$id]['descr'];
81
}
82

    
83
if ($_POST) {
84

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

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

    
108
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
109

    
110
	if (($_POST['host'] && !is_domain($_POST['host'])))
111
		$input_errors[] = gettext("The Hostname contains invalid characters.");
112
	if (($_POST['mx'] && !is_domain($_POST['mx']))) 
113
		$input_errors[] = gettext("The MX contains invalid characters.");
114
	if ((in_array("username", $reqdfields) && $_POST['username'] && !is_dyndns_username($_POST['username'])) || ((in_array("username", $reqdfields)) && ($_POST['username'] == ""))) 
115
 		$input_errors[] = gettext("The username contains invalid characters.");
116

    
117
	if (!$input_errors) {
118
		$dyndns = array();
119
		$dyndns['type'] = $_POST['type'];
120
		$dyndns['username'] = $_POST['username'];
121
		$dyndns['password'] = $_POST['password'];
122
		$dyndns['host'] = $_POST['host'];
123
		$dyndns['mx'] = $_POST['mx'];
124
		$dyndns['wildcard'] = $_POST['wildcard'] ? true : false;
125
		$dyndns['verboselog'] = $_POST['verboselog'] ? true : false;
126
		$dyndns['curl_ipresolve_v4'] = $_POST['curl_ipresolve_v4'] ? true : false;
127
		$dyndns['curl_ssl_verifypeer'] = $_POST['curl_ssl_verifypeer'] ? true : false;
128
		/* In this place enable means disabled */
129
		if ($_POST['enable'])
130
			unset($dyndns['enable']);
131
		else
132
			$dyndns['enable'] = true;
133
		$dyndns['interface'] = $_POST['interface'];
134
		$dyndns['zoneid'] = $_POST['zoneid'];
135
		$dyndns['ttl'] = $_POST['ttl'];
136
		$dyndns['updateurl'] = $_POST['updateurl'];
137
		// Trim hard-to-type but sometimes returned characters
138
		$dyndns['resultmatch'] = trim($_POST['resultmatch'], "\t\n\r");
139
		($dyndns['type'] == "custom" || $dyndns['type'] == "custom-v6") ? $dyndns['requestif'] = $_POST['requestif'] : $dyndns['requestif'] = $_POST['interface'];
140
		$dyndns['descr'] = $_POST['descr'];
141
		$dyndns['force'] = isset($_POST['force']);
142
		
143
		if($dyndns['username'] == "none")
144
			$dyndns['username'] = "";
145

    
146
		if (isset($id) && $a_dyndns[$id])
147
			$a_dyndns[$id] = $dyndns;
148
		else {
149
 			$a_dyndns[] = $dyndns;
150
			$id = count($a_dyndns) - 1;
151
		}
152

    
153
		$dyndns['id'] = $id;
154
		//Probably overkill, but its better to be safe
155
		for($i = 0; $i < count($a_dyndns); $i++) {
156
			$a_dyndns[$i]['id'] = $i;
157
		}
158

    
159
		write_config();
160

    
161
		services_dyndns_configure_client($dyndns);
162

    
163
		header("Location: services_dyndns.php");
164
		exit;
165
	}
166
}
167

    
168
$pgtitle = array(gettext("Services"),gettext("Dynamic DNS client"));
169
include("head.inc");
170

    
171
?>
172

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

    
345
                <tr id="r53_zoneid" style="display:none">
346
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Zone ID");?></td>
347
                  <td width="78%" class="vtable">
348
                    <input name="zoneid" type="text" class="formfld user" id="zoneid" size="20" value="<?=htmlspecialchars($pconfig['zoneid']);?>">
349
                    <br/><?= gettext("Enter Zone ID that you received when you created your domain in Route 53.");?>
350
                  </td>
351
                </tr>
352
                <tr id="_urltr">
353
                  <td width="22%" valign="top" class="vncell"><?=gettext("Update URL");?></td>
354
                  <td width="78%" class="vtable">
355
                    <input name="updateurl" type="text" class="formfld unknown" id="updateurl" size="60" value="<?=htmlspecialchars($pconfig['updateurl']);?>">
356
                    <br/><?= gettext("This is the only field required by for Custom Dynamic DNS, and is only used by Custom Entries.");?>
357
			<br/>
358
			<?= gettext("If you need the new IP to be included in the request, put %IP% in its place.");?>
359
                  </td>
360
                </tr>
361
		<tr id="_resulttr">
362
                  <td width="22%" valign="top" class="vncell"><?=gettext("Result Match");?></td>
363
                  <td width="78%" class="vtable">
364
                    <textarea name="resultmatch" class="formpre" id="resultmatch" cols="65" rows="7"><?=htmlspecialchars($pconfig['resultmatch']);?></textarea>
365
                    <br/><?= gettext("This field is only used by Custom Dynamic DNS Entries.");?>
366
			<br/>
367
			<?= 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.");?>
368
			<br/>
369
			<?= gettext("If you need the new IP to be included in the request, put %IP% in its place.");?>
370
			<br/>
371
			<?= gettext("If you need to include multiple possible values, separate them with a |.  If your provider includes a |, escape it with \\|");?>
372
			<br/>
373
			<?= gettext("Tabs (\\t), newlines (\\n) and carriage returns (\\r) at the beginning or end of the returned results are removed before comparison.");?>
374
                  </td>
375
                </tr>
376
                <tr>
377

    
378
                <tr id="r53_ttl" style="display:none">
379
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("TTL");?></td>
380
                  <td width="78%" class="vtable">
381
                    <input name="ttl" type="text" class="formfld user" id="ttl" size="20" value="<?=htmlspecialchars($pconfig['ttl']);?>">
382
                    <br/><?= gettext("Choose TTL for your dns record.");?>
383
                  </td>
384
                </tr>
385
                <tr>
386

    
387

    
388
                <tr>
389
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
390
                  <td width="78%" class="vtable">
391
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>">
392
                  </td>
393
                </tr>
394
                <tr>
395
                  <td width="22%" valign="top">&nbsp;</td>
396
                  <td width="78%">
397
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onClick="enable_change(true)">
398
					<a href="services_dyndns.php"><input name="cancel" type="button" class="formbtn" value="<?=gettext("Cancel");?>"></a>
399
					<?php if (isset($id) && $a_dyndns[$id]): ?>
400
						<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
401
						<input name="force" type="submit" class="formbtn" value="<?=gettext("Save & Force Update");?>" onClick="enable_change(true)">
402
					<?php endif; ?>
403
                  </td>
404
                </tr>
405
                <tr>
406
                  <td width="22%" valign="top">&nbsp;</td>
407
                  <td width="78%"><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
408
                    </strong></span><?php printf(gettext("You must configure a DNS server in %sSystem:
409
                    General setup%s or allow the DNS server list to be overridden
410
                    by DHCP/PPP on WAN for dynamic DNS updates to work."),'<a href="system.php">','</a>');?></span></td>
411
                </tr>
412
              </table>
413
</form>
414
<?php include("fend.inc"); ?>
415

    
416
<script type="text/javascript">
417
_onTypeChange("<?php echo $pconfig['type']; ?>");
418
</script>
419

    
420
</body>
421
</html>
(158-158/246)