Projet

Général

Profil

Télécharger (20 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_dyndns_edit.php @ de29dadc

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
if (is_numericint($_GET['id']))
60
	$id = $_GET['id'];
61
if (isset($_POST['id']) && is_numericint($_POST['id']))
62
	$id = $_POST['id'];
63

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

    
84
if ($_POST) {
85

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

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

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

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

    
118
		if (!is_domain($host_to_check))
119
			$input_errors[] = gettext("The Hostname contains invalid characters.");
120

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

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

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

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

    
170
		write_config();
171

    
172
		services_dyndns_configure_client($dyndns);
173

    
174
		header("Location: services_dyndns.php");
175
		exit;
176
	}
177
}
178

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

    
182
?>
183

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

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

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

    
412

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

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

    
447
</body>
448
</html>
(160-160/256)