Project

General

Profile

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