Project

General

Profile

Download (17.3 KB) Statistics
| Branch: | Tag: | Revision:
1 f1f60c92 Ermal Luçi
<?php
2
/* $Id$ */
3
/*
4 7a5fe50d Phil Davis
	Copyright (C) 2008 Ermal Luçi
5 f1f60c92 Ermal Luçi
	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 1d333258 Scott Ullrich
/*
29
	pfSense_BUILDER_BINARIES:	/bin/rm
30
	pfSense_MODULE:	dyndns
31
*/
32 f1f60c92 Ermal Luçi
33 6b07c15a Matthew Grooms
##|+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 ee2db55f Ermal Lu?i
/* 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 f1f60c92 Ermal Luçi
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 acdfc164 Ermal Luçi
	$pconfig['enable'] = !isset($a_dyndns[$id]['enable']);
70 f1f60c92 Ermal Luçi
	$pconfig['interface'] = $a_dyndns[$id]['interface'];
71
	$pconfig['wildcard'] = isset($a_dyndns[$id]['wildcard']);
72 cd132e86 Edson Brandi
	$pconfig['zoneid'] = $a_dyndns[$id]['zoneid'];
73
	$pconfig['ttl'] = isset($a_dyndns[$id]['ttl']);
74 37f3e704 Matt Corallo
	$pconfig['updateurl'] = $a_dyndns[$id]['updateurl'];
75
	$pconfig['resultmatch'] = $a_dyndns[$id]['resultmatch'];
76
	$pconfig['requestif'] = $a_dyndns[$id]['requestif'];
77 f1f60c92 Ermal Luçi
	$pconfig['descr'] = $a_dyndns[$id]['descr'];
78
}
79
80
if ($_POST) {
81
82
	unset($input_errors);
83
	$pconfig = $_POST;
84 d9cc4b24 gnhb
	
85 0030036f gnhb
	if(($pconfig['type'] == "freedns" || $pconfig['type'] == "namecheap") && $_POST['username'] == "")
86
		$_POST['username'] = "none"; 
87 f1f60c92 Ermal Luçi
88
	/* input validation */
89
	$reqdfields = array();
90
	$reqdfieldsn = array();
91 37f3e704 Matt Corallo
	$reqdfields = array("type");
92
	$reqdfieldsn = array(gettext("Service type"));
93
	if ($pconfig['type'] != "custom") {
94
		$reqdfields[] = "host";
95
		$reqdfieldsn[] = gettext("Hostname");
96
		$reqdfields[] = "password";
97
		$reqdfieldsn[] = gettext("Password");
98
 		$reqdfields[] = "username";
99
 		$reqdfieldsn[] = gettext("Username");
100
	}else{
101
		$reqdfields[] = "updateurl";
102
		$reqdfieldsn[] = gettext("Update URL");
103
 	}
104 f1f60c92 Ermal Luçi
105
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
106
107
	if (($_POST['mx'] && !is_domain($_POST['mx']))) 
108 2b2a7984 Rafael Lucas
		$input_errors[] = gettext("The MX contains invalid characters.");
109 37f3e704 Matt Corallo
	if ((in_array("username", $reqdfields) && $_POST['username'] && !is_dyndns_username($_POST['username'])) || ((in_array("username", $reqdfields)) && ($_POST['username'] == ""))) 
110
 		$input_errors[] = gettext("The username contains invalid characters.");
111 f1f60c92 Ermal Luçi
112
	if (!$input_errors) {
113
		$dyndns = array();
114
		$dyndns['type'] = $_POST['type'];
115
		$dyndns['username'] = $_POST['username'];
116
		$dyndns['password'] = $_POST['password'];
117
		$dyndns['host'] = $_POST['host'];
118
		$dyndns['mx'] = $_POST['mx'];
119
		$dyndns['wildcard'] = $_POST['wildcard'] ? true : false;
120 d348160e Renato Botelho
		/* In this place enable means disabled */
121
		if ($_POST['enable'])
122
			unset($dyndns['enable']);
123
		else
124
			$dyndns['enable'] = true;
125 f1f60c92 Ermal Luçi
		$dyndns['interface'] = $_POST['interface'];
126 cd132e86 Edson Brandi
		$dyndns['zoneid'] = $_POST['zoneid'];
127
		$dyndns['ttl'] = $_POST['ttl'];
128 37f3e704 Matt Corallo
		$dyndns['updateurl'] = $_POST['updateurl'];
129
		// Trim hard-to-type but sometimes returned characters
130
		$dyndns['resultmatch'] = trim($_POST['resultmatch'], "\t\n\r");
131
		$dyndns['type'] == "custom" ? $dyndns['requestif'] = $_POST['requestif'] : $dyndns['requestif'] = $_POST['interface'];
132 f1f60c92 Ermal Luçi
		$dyndns['descr'] = $_POST['descr'];
133 f3b2b2a4 Yehuda Katz
		$dyndns['force'] = isset($_POST['force']);
134 0030036f gnhb
		
135
		if($dyndns['username'] == "none")
136
			$dyndns['username'] = "";
137 f1f60c92 Ermal Luçi
138
		if (isset($id) && $a_dyndns[$id])
139
			$a_dyndns[$id] = $dyndns;
140 37f3e704 Matt Corallo
		else {
141
 			$a_dyndns[] = $dyndns;
142
			$id = count($a_dyndns) - 1;
143
		}
144
145
		$dyndns['id'] = $id;
146
		//Probably overkill, but its better to be safe
147
		for($i = 0; $i < count($a_dyndns); $i++) {
148
			$a_dyndns[$i]['id'] = $i;
149
		}
150 f1f60c92 Ermal Luçi
151
		write_config();
152
153 f3b2b2a4 Yehuda Katz
		services_dyndns_configure_client($dyndns);
154 9c38bcea sullrich
155 07cdb9a2 Ermal Luçi
		header("Location: services_dyndns.php");
156
		exit;
157 f1f60c92 Ermal Luçi
	}
158
}
159
160 2b2a7984 Rafael Lucas
$pgtitle = array(gettext("Services"),gettext("Dynamic DNS client"));
161 f1f60c92 Ermal Luçi
include("head.inc");
162
163
?>
164
165
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
166
<?php include("fbegin.inc"); ?>
167
<?php if ($input_errors) print_input_errors($input_errors); ?>
168
<?php if ($savemsg) print_info_box($savemsg); ?>
169 37f3e704 Matt Corallo
<script type="text/javascript">
170
function _onTypeChange(type){ 
171
	switch(type) {
172
		case "custom":
173
			document.getElementById("_resulttr").style.display = '';
174
			document.getElementById("_urltr").style.display = '';
175
			document.getElementById("_requestiftr").style.display = '';
176
			document.getElementById("_hostnametr").style.display = 'none';
177
			document.getElementById("_mxtr").style.display = 'none';
178
			document.getElementById("_wildcardtr").style.display = 'none';
179
			document.getElementById("r53_zoneid").style.display='none';
180
			document.getElementById("r53_ttl").style.display='none';
181
			break;
182
		case "route53":
183
			document.getElementById("_resulttr").style.display = 'none';
184
			document.getElementById("_urltr").style.display = 'none';
185
			document.getElementById("_requestiftr").style.display = 'none';
186
			document.getElementById("_hostnametr").style.display = '';
187
			document.getElementById("_mxtr").style.display = '';
188
			document.getElementById("_wildcardtr").style.display = '';
189
			document.getElementById("r53_zoneid").style.display='';
190
			document.getElementById("r53_ttl").style.display='';
191
			break;
192
		default:
193
			document.getElementById("_resulttr").style.display = 'none';
194
			document.getElementById("_urltr").style.display = 'none';
195
			document.getElementById("_requestiftr").style.display = 'none';
196
			document.getElementById("_hostnametr").style.display = '';
197
			document.getElementById("_mxtr").style.display = '';
198
			document.getElementById("_wildcardtr").style.display = '';
199
			document.getElementById("r53_zoneid").style.display='none';
200
			document.getElementById("r53_ttl").style.display='none';
201
	}
202
}
203
</script>
204 f1f60c92 Ermal Luçi
<form action="services_dyndns_edit.php" method="post" name="iform" id="iform">
205
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
206
                <tr>
207
                  <td colspan="2" valign="top" class="optsect_t">
208
				  <table border="0" cellspacing="0" cellpadding="0" width="100%">
209 2b2a7984 Rafael Lucas
				  <tr><td class="optsect_s"><strong><?=gettext("Dynamic DNS client");?></strong></td></tr>
210 f1f60c92 Ermal Luçi
				  </table>
211
				  </td>
212
                </tr>
213
                <tr>
214 2b2a7984 Rafael Lucas
                  <td width="22%" valign="top" class="vncell"><?=gettext("Disable");?></td>
215 f1f60c92 Ermal Luçi
				  <td width="78%" class="vtable">
216 2b2a7984 Rafael Lucas
				    <input name="enable" type="checkbox" id="enable" value="<?=gettext("yes");?>" <?php if ($pconfig['enable']) echo "checked"; ?>>
217 f1f60c92 Ermal Luçi
				  </td>
218
                </tr>
219
                <tr>
220 2b2a7984 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Service type");?></td>
221 f1f60c92 Ermal Luçi
                  <td width="78%" class="vtable">
222 37f3e704 Matt Corallo
			<select name="type" class="formselect" id="type" onchange="_onTypeChange(this.options[this.selectedIndex].value);">
223 f1f60c92 Ermal Luçi
                      <?php
224 7a5fe50d Phil Davis
						$types = explode(",", DYNDNS_PROVIDER_DESCRIPTIONS);
225
						$vals = explode(" ", DYNDNS_PROVIDER_VALUES);
226 f1f60c92 Ermal Luçi
						$j = 0; for ($j = 0; $j < count($vals); $j++): ?>
227
                      <option value="<?=$vals[$j];?>" <?php if ($vals[$j] == $pconfig['type']) echo "selected";?>>
228
                      <?=htmlspecialchars($types[$j]);?>
229
                      </option>
230
                      <?php endfor; ?>
231
                    </select></td>
232
				</tr>
233
				<tr>
234 2b2a7984 Rafael Lucas
				   <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface to monitor");?></td>  
235 f1f60c92 Ermal Luçi
				   <td width="78%" class="vtable">
236
				   <select name="interface" class="formselect" id="interface">
237 3e1eec58 smos
				<?php
238
					$iflist = get_configured_interface_with_descr();					
239
				   	foreach ($iflist as $if => $ifdesc) {
240
						echo "<option value=\"{$if}\"";
241
						if ($pconfig['interface'] == $if)
242
							echo "selected";
243
						echo ">{$ifdesc}</option>\n";
244
					}
245
					$grouplist = return_gateway_groups_array();
246
				   	foreach ($grouplist as $name => $group) {
247
						echo "<option value=\"{$name}\"";
248
						if ($pconfig['interface'] == $name)
249
							echo "selected";
250
						echo ">GW Group {$name}</option>\n";
251
					}
252
				?>
253 f1f60c92 Ermal Luçi
					</select>
254
					</td>
255
					</td>
256
				</tr>	
257 37f3e704 Matt Corallo
				<tr id="_requestiftr">
258
				   <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface to send update from");?></td>  
259
				   <td width="78%" class="vtable">
260
				   <select name="requestif" class="formselect" id="requestif">
261
				   <?php $iflist = get_configured_interface_with_descr();
262
				   		foreach ($iflist as $if => $ifdesc):?>
263
							<option value="<?=$if;?>" <?php if ($pconfig['requestif'] == $if) echo "selected";?>><?=$ifdesc;?></option>
264
					<?php endforeach; ?>
265
					</select>
266
					<br/><?= gettext("Note: This is almost always the same as the Interface to Monitor.");?>
267
					</td>
268
					</td>
269
				</tr>
270
                <tr id="_hostnametr">
271 2b2a7984 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Hostname");?></td>
272 f1f60c92 Ermal Luçi
                  <td width="78%" class="vtable">
273
                    <input name="host" type="text" class="formfld unknown" id="host" size="30" value="<?=htmlspecialchars($pconfig['host']);?>">
274
                    <br>
275
				    <span class="vexpl">
276 16457bdd Renato Botelho
				    <span class="red"><strong><?=gettext("Note:");?><br></strong>
277 f1f60c92 Ermal Luçi
				    </span>
278 38a481ad jim-p
					<?=gettext("Enter the complete host/domain name.  example:  myhost.dyndns.org");?><br/>
279
					<?=gettext("For he.net tunnelbroker, enter your tunnel ID");?>
280 f1f60c92 Ermal Luçi
				    </span>
281
		          </td>
282
				</tr>
283 37f3e704 Matt Corallo
                <tr id="_mxtr">
284 50bfcec0 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncell"><?=gettext("MX"); ?></td>
285 f1f60c92 Ermal Luçi
                  <td width="78%" class="vtable">
286
                    <input name="mx" type="text" class="formfld unknown" id="mx" size="30" value="<?=htmlspecialchars($pconfig['mx']);?>">
287
                    <br>
288 2b2a7984 Rafael Lucas
					<?=gettext("Note: With DynDNS service you can only use a hostname, not an IP address.");?>
289 f1f60c92 Ermal Luçi
					<br>
290 2b2a7984 Rafael Lucas
                    <?=gettext("Set this option only if you need a special MX record. Not".
291
                   " all services support this.");?></td>
292 f1f60c92 Ermal Luçi
				</tr>
293 37f3e704 Matt Corallo
                <tr id="_wildcardtr">
294 50bfcec0 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncell"><?=gettext("Wildcards"); ?></td>
295 f1f60c92 Ermal Luçi
                  <td width="78%" class="vtable">
296
                    <input name="wildcard" type="checkbox" id="wildcard" value="yes" <?php if ($pconfig['wildcard']) echo "checked"; ?>>
297 50bfcec0 Carlos Eduardo Ramos
                    <?=gettext("Enable ");?><?=gettext("Wildcard"); ?></td>
298 f1f60c92 Ermal Luçi
				</tr>
299 37f3e704 Matt Corallo
                <tr id="_usernametr">
300 2b2a7984 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Username");?></td>
301 f1f60c92 Ermal Luçi
                  <td width="78%" class="vtable">
302
                    <input name="username" type="text" class="formfld user" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>">
303 37f3e704 Matt Corallo
                    <br/><?= gettext("Username is required for all types except Namecheap, FreeDNS and Custom Entries.");?>
304 cd132e86 Edson Brandi
		    <br/><?= gettext("Route 53: Enter your Access Key ID.");?>
305 37f3e704 Matt Corallo
		    <br/><?= gettext("For Custom Entries, Username and Password represent HTTP Authentication username and passwords.");?>
306 f1f60c92 Ermal Luçi
                  </td>
307
                </tr>
308
                <tr>
309 2b2a7984 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Password");?></td>
310 f1f60c92 Ermal Luçi
                  <td width="78%" class="vtable">
311
                    <input name="password" type="password" class="formfld pwd" id="password" size="20" value="<?=htmlspecialchars($pconfig['password']);?>">
312 d9cc4b24 gnhb
                    <br/>
313
                    <?=gettext("FreeDNS (freedns.afraid.org): Enter your \"Authentication Token\" provided by FreeDNS.");?>
314 cd132e86 Edson Brandi
		    <br/><?= gettext("Route 53: Enter your Secret Access Key.");?>
315
                  </td>
316
                </tr>
317
318
                <tr id="r53_zoneid" style="display:none">
319
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Zone ID");?></td>
320
                  <td width="78%" class="vtable">
321
                    <input name="zoneid" type="text" class="formfld user" id="zoneid" size="20" value="<?=htmlspecialchars($pconfig['zoneid']);?>">
322
                    <br/><?= gettext("Enter Zone ID that you received when you created your domain in Route 53.");?>
323 f1f60c92 Ermal Luçi
                  </td>
324
                </tr>
325 37f3e704 Matt Corallo
                <tr id="_urltr">
326
                  <td width="22%" valign="top" class="vncell"><?=gettext("Update URL");?></td>
327
                  <td width="78%" class="vtable">
328
                    <input name="updateurl" type="text" class="formfld unknown" id="updateurl" size="60" value="<?=htmlspecialchars($pconfig['updateurl']);?>">
329
                    <br/><?= gettext("This is the only field required by for Custom Dynamic DNS, and is only used by Custom Entries.");?>
330
			<br/>
331
			<?= gettext("If you need the new IP to be included in the request, put %IP% in its place.");?>
332
                  </td>
333
                </tr>
334
		<tr id="_resulttr">
335
                  <td width="22%" valign="top" class="vncell"><?=gettext("Result Match");?></td>
336
                  <td width="78%" class="vtable">
337
                    <textarea name="resultmatch" class="formpre" id="resultmatch" cols="65" rows="7"><?=htmlspecialchars($pconfig['resultmatch']);?></textarea>
338
                    <br/><?= gettext("This field is only used by Custom Dynamic DNS Entries.");?>
339
			<br/>
340
			<?= 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.");?>
341
			<br/>
342
			<?= gettext("If you need the new IP to be included in the request, put %IP% in its place.");?>
343
			<br/>
344
			<?= gettext("If you need to include multiple possible values, sperate them with a |.  If your provider includes a |, escape it with \\|");?>
345
			<br/>
346
			<?= gettext("Tabs (\\t), newlines (\\n) and carriage returns (\\r) at the beginning or end of the returned results are removed before comparison.");?>
347
                  </td>
348
                </tr>
349 cd132e86 Edson Brandi
                <tr>
350
351
                <tr id="r53_ttl" style="display:none">
352
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("TTL");?></td>
353
                  <td width="78%" class="vtable">
354
                    <input name="ttl" type="text" class="formfld user" id="ttl" size="20" value="<?=htmlspecialchars($pconfig['ttl']);?>">
355
                    <br/><?= gettext("Choose TTL for your dns record.");?>
356
                  </td>
357
                </tr>
358
                <tr>
359
360
361 f1f60c92 Ermal Luçi
                <tr>
362 2b2a7984 Rafael Lucas
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
363 f1f60c92 Ermal Luçi
                  <td width="78%" class="vtable">
364
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>">
365
                  </td>
366
                </tr>
367
                <tr>
368
                  <td width="22%" valign="top">&nbsp;</td>
369
                  <td width="78%">
370 2b2a7984 Rafael Lucas
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onClick="enable_change(true)">
371
					<a href="services_dyndns.php"><input name="cancel" type="button" class="formbtn" value="<?=gettext("Cancel");?>"></a>
372 f1f60c92 Ermal Luçi
					<?php if (isset($id) && $a_dyndns[$id]): ?>
373 225a2f0b Scott Ullrich
						<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
374 f3b2b2a4 Yehuda Katz
						<input name="force" type="submit" class="formbtn" value="<?=gettext("Save & Force Update");?>" onClick="enable_change(true)">
375 f1f60c92 Ermal Luçi
					<?php endif; ?>
376
                  </td>
377
                </tr>
378
                <tr>
379
                  <td width="22%" valign="top">&nbsp;</td>
380 16457bdd Renato Botelho
                  <td width="78%"><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
381 2b2a7984 Rafael Lucas
                    </strong></span><?php printf(gettext("You must configure a DNS server in %sSystem:
382
                    General setup%s or allow the DNS server list to be overridden
383
                    by DHCP/PPP on WAN for dynamic DNS updates to work."),'<a href="system.php">','</a>');?></span></td>
384 f1f60c92 Ermal Luçi
                </tr>
385
              </table>
386
</form>
387 9e9b596f Ermal Luçi
<?php include("fend.inc"); ?>
388 cd132e86 Edson Brandi
389
<script type="text/javascript">
390 37f3e704 Matt Corallo
_onTypeChange("<?php echo $pconfig['type']; ?>");
391 cd132e86 Edson Brandi
</script>
392
393 f1f60c92 Ermal Luçi
</body>
394
</html>