Project

General

Profile

Feature #1258 » services_dyndns_edit.php.txt

Chris Goundry, 02/06/2011 02:23 PM

 
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
$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
	$pconfig['enable'] = !isset($a_dyndns[$id]['enable']);
70
	$pconfig['interface'] = $a_dyndns[$id]['interface'];
71
	$pconfig['wildcard'] = isset($a_dyndns[$id]['wildcard']);
72
	$pconfig['descr'] = $a_dyndns[$id]['descr'];
73
}
74

    
75
if ($_POST) {
76

    
77
	unset($input_errors);
78
	$pconfig = $_POST;
79

    
80
	/* input validation */
81
	$reqdfields = array();
82
	$reqdfieldsn = array();
83
	$reqdfields = array("host", "password", "type");
84
	$reqdfieldsn = array(gettext("Hostname"),gettext("Password"),gettext("Service type"));
85
	if ($pconfig['type'] != "namecheap") {
86
		$reqdfields[] = "username";
87
		$reqdfieldsn[] = gettext("Username");
88
	}
89

    
90
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
91

    
92
	if (($_POST['mx'] && !is_domain($_POST['mx']))) 
93
		$input_errors[] = gettext("The MX contains invalid characters.");
94
	if (($_POST['username'] && !is_dyndns_username($_POST['username'])) || (($pconfig['type'] != "namecheap") && ($_POST['username'] == ""))) 
95
		$input_errors[] = gettext("The username contains invalid characters.");
96

    
97
	if (!$input_errors) {
98
		$dyndns = array();
99
		$dyndns['type'] = $_POST['type'];
100
		$dyndns['username'] = $_POST['username'];
101
		$dyndns['password'] = $_POST['password'];
102
		$dyndns['host'] = $_POST['host'];
103
		$dyndns['mx'] = $_POST['mx'];
104
		$dyndns['wildcard'] = $_POST['wildcard'] ? true : false;
105
		$dyndns['enable'] = $_POST['enable'] ? false : true;
106
		$dyndns['interface'] = $_POST['interface'];
107
		$dyndns['descr'] = $_POST['descr'];
108

    
109
		if (isset($id) && $a_dyndns[$id])
110
			$a_dyndns[$id] = $dyndns;
111
		else
112
			$a_dyndns[] = $dyndns;
113

    
114
		write_config();
115

    
116
		$retval = 0;
117

    
118
		conf_mount_rw();
119

    
120
		unlink("{$g['conf_path']}/dyndns_{$dyndns['interface']}{$dyndns['type']}{$dyndns['host']}.cache");
121

    
122
		$retval = services_dyndns_configure_client($dyndns);
123

    
124
		conf_mount_ro();
125

    
126
		header("Location: services_dyndns.php");
127
		exit;
128
	}
129
}
130

    
131
$pgtitle = array(gettext("Services"),gettext("Dynamic DNS client"));
132
include("head.inc");
133

    
134
?>
135

    
136
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
137
<?php include("fbegin.inc"); ?>
138
<?php if ($input_errors) print_input_errors($input_errors); ?>
139
<?php if ($savemsg) print_info_box($savemsg); ?>
140
<form action="services_dyndns_edit.php" method="post" name="iform" id="iform">
141
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
142
                <tr>
143
                  <td colspan="2" valign="top" class="optsect_t">
144
				  <table border="0" cellspacing="0" cellpadding="0" width="100%">
145
				  <tr><td class="optsect_s"><strong><?=gettext("Dynamic DNS client");?></strong></td></tr>
146
				  </table>
147
				  </td>
148
                </tr>
149
                <tr>
150
                  <td width="22%" valign="top" class="vncell"><?=gettext("Disable");?></td>
151
				  <td width="78%" class="vtable">
152
				    <input name="enable" type="checkbox" id="enable" value="<?=gettext("yes");?>" <?php if ($pconfig['enable']) echo "checked"; ?>>
153
				  </td>
154
                </tr>
155
                <tr>
156
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Service type");?></td>
157
                  <td width="78%" class="vtable">
158
			<select name="type" class="formselect" id="type">
159
                      <?php
160
						$types = explode(",", "DNS-O-Matic, DynDNS (dynamic),DynDNS (static),DynDNS (custom),DHS,DyNS,easyDNS,No-IP,ODS.org,ZoneEdit,Loopia,DNSMadeEasy,freeDNS, DNSexit, OpenDNS, Namecheap");
161
						$vals = explode(" ", "dnsomatic dyndns dyndns-static dyndns-custom dhs dyns easydns noip ods zoneedit loopia dnsmadeeasy freedns dnsexit opendns namecheap");
162
						$j = 0; for ($j = 0; $j < count($vals); $j++): ?>
163
                      <option value="<?=$vals[$j];?>" <?php if ($vals[$j] == $pconfig['type']) echo "selected";?>>
164
                      <?=htmlspecialchars($types[$j]);?>
165
                      </option>
166
                      <?php endfor; ?>
167
                    </select></td>
168
				</tr>
169
				<tr>
170
				   <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface to monitor");?></td>  
171
				   <td width="78%" class="vtable">
172
				   <select name="interface" class="formselect" id="interface">
173
				   <?php $iflist = get_configured_interface_with_descr();
174
				   		foreach ($iflist as $if => $ifdesc):?>
175
							<option value="<?=$if;?>" <?php if ($pconfig['interface'] == $if) echo "selected";?>><?=$ifdesc;?></option>
176
					<?php endforeach; ?>
177
					</select>
178
					</td>
179
					</td>
180
				</tr>	
181
                <tr>
182
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Hostname");?></td>
183
                  <td width="78%" class="vtable">
184
                    <input name="host" type="text" class="formfld unknown" id="host" size="30" value="<?=htmlspecialchars($pconfig['host']);?>">
185
                    <br>
186
				    <span class="vexpl">
187
				    <span class="red"><strong><?=gettext("Note:");?><br></strong>
188
				    </span>
189
					<?=gettext("Enter the complete host/domain name.  example:  myhost.dyndns.org");?>
190
				    </span>
191
		          </td>
192
				</tr>
193
                <tr>
194
                  <td width="22%" valign="top" class="vncell"><?=gettext("MX"); ?></td>
195
                  <td width="78%" class="vtable">
196
                    <input name="mx" type="text" class="formfld unknown" id="mx" size="30" value="<?=htmlspecialchars($pconfig['mx']);?>">
197
                    <br>
198
					<?=gettext("Note: With DynDNS service you can only use a hostname, not an IP address.");?>
199
					<br>
200
                    <?=gettext("Set this option only if you need a special MX record. Not".
201
                   " all services support this.");?></td>
202
				</tr>
203
                <tr>
204
                  <td width="22%" valign="top" class="vncell"><?=gettext("Wildcards"); ?></td>
205
                  <td width="78%" class="vtable">
206
                    <input name="wildcard" type="checkbox" id="wildcard" value="yes" <?php if ($pconfig['wildcard']) echo "checked"; ?>>
207
                    <?=gettext("Enable ");?><?=gettext("Wildcard"); ?></td>
208
				</tr>
209
                <tr>
210
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Username");?></td>
211
                  <td width="78%" class="vtable">
212
                    <input name="username" type="text" class="formfld user" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>">
213
                    <br/><?= gettext("Username is required for all types except Namecheap and FreeDNS.");?>
214
                  </td>
215
                </tr>
216
                <tr>
217
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Password");?></td>
218
                  <td width="78%" class="vtable">
219
                    <input name="password" type="password" class="formfld pwd" id="password" size="20" value="<?=htmlspecialchars($pconfig['password']);?>">
220
                  </td>
221
                </tr>
222
                <tr>
223
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
224
                  <td width="78%" class="vtable">
225
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>">
226
                  </td>
227
                </tr>
228
                <tr>
229
                  <td width="22%" valign="top">&nbsp;</td>
230
                  <td width="78%">
231
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onClick="enable_change(true)">
232
					<a href="services_dyndns.php"><input name="cancel" type="button" class="formbtn" value="<?=gettext("Cancel");?>"></a>
233
					<?php if (isset($id) && $a_dyndns[$id]): ?>
234
						<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
235
					<?php endif; ?>
236
                  </td>
237
                </tr>
238
                <tr>
239
                  <td width="22%" valign="top">&nbsp;</td>
240
                  <td width="78%"><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
241
                    </strong></span><?php printf(gettext("You must configure a DNS server in %sSystem:
242
                    General setup%s or allow the DNS server list to be overridden
243
                    by DHCP/PPP on WAN for dynamic DNS updates to work."),'<a href="system.php">','</a>');?></span></td>
244
                </tr>
245
              </table>
246
</form>
247
<?php include("fend.inc"); ?>
248
</body>
249
</html>
(3-3/3)