Projet

Général

Profil

Télécharger (18,7 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_dyndns_edit.php @ 9ec8e1f2

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

    
82
if ($_POST) {
83

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

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

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

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

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

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

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

    
153
		if (isset($id) && $a_dyndns[$id])
154
			$a_dyndns[$id] = $dyndns;
155
		else {
156
 			$a_dyndns[] = $dyndns;
157
			$id = count($a_dyndns) - 1;
158
		}
159

    
160
		$dyndns['id'] = $id;
161
		//Probably overkill, but its better to be safe
162
		for($i = 0; $i < count($a_dyndns); $i++) {
163
			$a_dyndns[$i]['id'] = $i;
164
		}
165

    
166
		write_config();
167

    
168
		services_dyndns_configure_client($dyndns);
169

    
170
		header("Location: services_dyndns.php");
171
		exit;
172
	}
173
}
174

    
175
$pgtitle = array(gettext("Services"),gettext("Dynamic DNS client"));
176
include("head.inc");
177

    
178
?>
179

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

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

    
389
                <tr id="r53_ttl" style="display:none">
390
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("TTL");?></td>
391
                  <td width="78%" class="vtable">
392
                    <input name="ttl" type="text" class="formfld user" id="ttl" size="20" value="<?=htmlspecialchars($pconfig['ttl']);?>">
393
                    <br/><?= gettext("Choose TTL for your dns record.");?>
394
                  </td>
395
                </tr>
396
                <tr>
397

    
398

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

    
427
<script type="text/javascript">
428
_onTypeChange("<?php echo $pconfig['type']; ?>");
429
</script>
430

    
431
</body>
432
</html>
(158-158/246)