Project

General

Profile

Download (18 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['zoneid'] = $a_dyndns[$id]['zoneid'];
74
	$pconfig['ttl'] = $a_dyndns[$id]['ttl'];
75
	$pconfig['updateurl'] = $a_dyndns[$id]['updateurl'];
76
	$pconfig['resultmatch'] = $a_dyndns[$id]['resultmatch'];
77
	$pconfig['requestif'] = $a_dyndns[$id]['requestif'];
78
	$pconfig['descr'] = $a_dyndns[$id]['descr'];
79
}
80

    
81
if ($_POST) {
82

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

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

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

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

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

    
142
		if (isset($id) && $a_dyndns[$id])
143
			$a_dyndns[$id] = $dyndns;
144
		else {
145
 			$a_dyndns[] = $dyndns;
146
			$id = count($a_dyndns) - 1;
147
		}
148

    
149
		$dyndns['id'] = $id;
150
		//Probably overkill, but its better to be safe
151
		for($i = 0; $i < count($a_dyndns); $i++) {
152
			$a_dyndns[$i]['id'] = $i;
153
		}
154

    
155
		write_config();
156

    
157
		services_dyndns_configure_client($dyndns);
158

    
159
		header("Location: services_dyndns.php");
160
		exit;
161
	}
162
}
163

    
164
$pgtitle = array(gettext("Services"),gettext("Dynamic DNS client"));
165
include("head.inc");
166

    
167
?>
168

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

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

    
362
                <tr id="r53_ttl" style="display:none">
363
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("TTL");?></td>
364
                  <td width="78%" class="vtable">
365
                    <input name="ttl" type="text" class="formfld user" id="ttl" size="20" value="<?=htmlspecialchars($pconfig['ttl']);?>">
366
                    <br/><?= gettext("Choose TTL for your dns record.");?>
367
                  </td>
368
                </tr>
369
                <tr>
370

    
371

    
372
                <tr>
373
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
374
                  <td width="78%" class="vtable">
375
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>">
376
                  </td>
377
                </tr>
378
                <tr>
379
                  <td width="22%" valign="top">&nbsp;</td>
380
                  <td width="78%">
381
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onClick="enable_change(true)">
382
					<a href="services_dyndns.php"><input name="cancel" type="button" class="formbtn" value="<?=gettext("Cancel");?>"></a>
383
					<?php if (isset($id) && $a_dyndns[$id]): ?>
384
						<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
385
						<input name="force" type="submit" class="formbtn" value="<?=gettext("Save & Force Update");?>" onClick="enable_change(true)">
386
					<?php endif; ?>
387
                  </td>
388
                </tr>
389
                <tr>
390
                  <td width="22%" valign="top">&nbsp;</td>
391
                  <td width="78%"><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
392
                    </strong></span><?php printf(gettext("You must configure a DNS server in %sSystem:
393
                    General setup%s or allow the DNS server list to be overridden
394
                    by DHCP/PPP on WAN for dynamic DNS updates to work."),'<a href="system.php">','</a>');?></span></td>
395
                </tr>
396
              </table>
397
</form>
398
<?php include("fend.inc"); ?>
399

    
400
<script type="text/javascript">
401
_onTypeChange("<?php echo $pconfig['type']; ?>");
402
</script>
403

    
404
</body>
405
</html>
(158-158/246)