Projet

Général

Profil

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

univnautes / usr / local / www / services_dyndns_edit.php @ 6b71ebb7

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 (($_POST['host'] && !is_domain($_POST['host'])))
110
		$input_errors[] = gettext("The Hostname contains invalid characters.");
111
	if (($_POST['mx'] && !is_domain($_POST['mx']))) 
112
		$input_errors[] = gettext("The MX contains invalid characters.");
113
	if ((in_array("username", $reqdfields) && $_POST['username'] && !is_dyndns_username($_POST['username'])) || ((in_array("username", $reqdfields)) && ($_POST['username'] == ""))) 
114
 		$input_errors[] = gettext("The username contains invalid characters.");
115

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

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

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

    
156
		write_config();
157

    
158
		services_dyndns_configure_client($dyndns);
159

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

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

    
168
?>
169

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

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

    
379
                <tr id="r53_ttl" style="display:none">
380
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("TTL");?></td>
381
                  <td width="78%" class="vtable">
382
                    <input name="ttl" type="text" class="formfld user" id="ttl" size="20" value="<?=htmlspecialchars($pconfig['ttl']);?>">
383
                    <br/><?= gettext("Choose TTL for your dns record.");?>
384
                  </td>
385
                </tr>
386
                <tr>
387

    
388

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

    
417
<script type="text/javascript">
418
_onTypeChange("<?php echo $pconfig['type']; ?>");
419
</script>
420

    
421
</body>
422
</html>
(158-158/246)