Project

General

Profile

Download (9.68 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
29 6b07c15a Matthew Grooms
##|+PRIV
30
##|*IDENT=page-services-dynamicdnsclient
31
##|*NAME=Services: Dynamic DNS client page
32
##|*DESCR=Allow access to the 'Services: Dynamic DNS client' page.
33
##|*MATCH=services_dyndns_edit.php*
34
##|-PRIV
35
36
37 ee2db55f Ermal Lu?i
/* returns true if $uname is a valid DynDNS username */
38
function is_dyndns_username($uname) {
39
        if (!is_string($uname))
40
                return false;
41
        
42
        if (preg_match("/[^a-z0-9\-.@_:]/i", $uname))
43
                return false;
44
        else
45
                return true;
46
}
47
48 f1f60c92 Ermal Luçi
require("guiconfig.inc");
49
50
if (!is_array($config['dyndnses']['dyndns'])) {
51
	$config['dyndnses']['dyndns'] = array();
52
}
53
54
$a_dyndns = &$config['dyndnses']['dyndns'];
55
56
$id = $_GET['id'];
57
if (isset($_POST['id']))
58
	$id = $_POST['id'];
59
60
if (isset($id) && isset($a_dyndns[$id])) {
61
	$pconfig['username'] = $a_dyndns[$id]['username'];
62
	$pconfig['password'] = $a_dyndns[$id]['password'];
63
	$pconfig['host'] = $a_dyndns[$id]['host'];
64
	$pconfig['mx'] = $a_dyndns[$id]['mx'];
65
	$pconfig['type'] = $a_dyndns[$id]['type'];
66 acdfc164 Ermal Luçi
	$pconfig['enable'] = !isset($a_dyndns[$id]['enable']);
67 f1f60c92 Ermal Luçi
	$pconfig['interface'] = $a_dyndns[$id]['interface'];
68
	$pconfig['wildcard'] = isset($a_dyndns[$id]['wildcard']);
69
	$pconfig['descr'] = $a_dyndns[$id]['descr'];
70
}
71
72
if ($_POST) {
73
74
	unset($input_errors);
75
	$pconfig = $_POST;
76
77
	/* input validation */
78
	$reqdfields = array();
79
	$reqdfieldsn = array();
80
	$reqdfields = array_merge($reqdfields, explode(" ", "host username password type"));
81
	$reqdfieldsn = array_merge($reqdfieldsn, explode(",", "Hostname,Username,Password,Service type"));
82
83
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
84
85
	if (($_POST['mx'] && !is_domain($_POST['mx']))) 
86
		$input_errors[] = "The MX contains invalid characters.";
87
	if (($_POST['username'] && !is_dyndns_username($_POST['username'])) || $_POST['username'] == "") 
88
		$input_errors[] = "The username contains invalid characters.";
89
90
	if (!$input_errors) {
91
		$dyndns = array();
92
		$dyndns['type'] = $_POST['type'];
93
		$dyndns['username'] = $_POST['username'];
94
		$dyndns['password'] = $_POST['password'];
95
		$dyndns['host'] = $_POST['host'];
96
		$dyndns['mx'] = $_POST['mx'];
97
		$dyndns['wildcard'] = $_POST['wildcard'] ? true : false;
98
		$dyndns['enable'] = $_POST['enable'] ? false : true;
99
		$dyndns['interface'] = $_POST['interface'];
100
		$dyndns['descr'] = $_POST['descr'];
101
102
		if (isset($id) && $a_dyndns[$id])
103
			$a_dyndns[$id] = $dyndns;
104
		else
105
			$a_dyndns[] = $dyndns;
106
107
		write_config();
108
109
110
		/* XXX: Make this with a touch file */
111
		$retval = 0;
112
113 91e55d73 Ermal Luçi
		conf_mount_rw();
114
		mwexec("rm {$g['conf_path']}/dyndns_{$dyndns['interface']}{$dyndns['type']}.cache");
115
		conf_mount_ro();
116
117 789af363 Ermal Luçi
		$retval = services_dyndns_configure_client($dyndns);
118
119 07cdb9a2 Ermal Luçi
		header("Location: services_dyndns.php");
120
		exit;
121 f1f60c92 Ermal Luçi
	}
122
}
123
124
$pgtitle = array("Services","Dynamic DNS client");
125
include("head.inc");
126
127
?>
128
129
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
130
<?php include("fbegin.inc"); ?>
131
<?php if ($input_errors) print_input_errors($input_errors); ?>
132
<?php if ($savemsg) print_info_box($savemsg); ?>
133
<form action="services_dyndns_edit.php" method="post" name="iform" id="iform">
134
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
135
                <tr>
136
                  <td colspan="2" valign="top" class="optsect_t">
137
				  <table border="0" cellspacing="0" cellpadding="0" width="100%">
138
				  <tr><td class="optsect_s"><strong>Dynamic DNS client</strong></td></tr>
139
				  </table>
140
				  </td>
141
                </tr>
142
                <tr>
143
                  <td width="22%" valign="top" class="vncellreq">Disable</td>
144
				  <td width="78%" class="vtable">
145 acdfc164 Ermal Luçi
				    <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?>>
146 f1f60c92 Ermal Luçi
				  </td>
147
                </tr>
148
                <tr>
149
                  <td width="22%" valign="top" class="vncellreq">Service type</td>
150
                  <td width="78%" class="vtable">
151
			<select name="type" class="formselect" id="type">
152
                      <?php
153 7d9dca1c Ermal Luçi
						$types = explode(",", "DNS-O-Matic, DynDNS (dynamic),DynDNS (static),DynDNS (custom),DHS,DyNS,easyDNS,No-IP,ODS.org,ZoneEdit,Loopia,freeDNS, DNSexit, OpenDNS");
154
						$vals = explode(" ", "dnsomatic dyndns dyndns-static dyndns-custom dhs dyns easydns noip ods zoneedit loopia freedns dnsexit opendns");
155 f1f60c92 Ermal Luçi
						$j = 0; for ($j = 0; $j < count($vals); $j++): ?>
156
                      <option value="<?=$vals[$j];?>" <?php if ($vals[$j] == $pconfig['type']) echo "selected";?>>
157
                      <?=htmlspecialchars($types[$j]);?>
158
                      </option>
159
                      <?php endfor; ?>
160
                    </select></td>
161
				</tr>
162
				<tr>
163
				   <td width="22%" valign="top" class="vncellreq">Interface to monitor</td>  
164
				   <td width="78%" class="vtable">
165
				   <select name="interface" class="formselect" id="interface">
166
				   <?php $iflist = get_configured_interface_with_descr();
167
				   		foreach ($iflist as $if => $ifdesc):?>
168
							<option value="<?=$if;?>" <?php if ($pconfig['interface'] == $if) echo "selected";?>><?=$ifdesc;?></option>
169
					<?php endforeach; ?>
170
					</select>
171
					</td>
172
					</td>
173
				</tr>	
174
                <tr>
175
                  <td width="22%" valign="top" class="vncellreq">Hostname/Interface</td>
176
                  <td width="78%" class="vtable">
177
                    <input name="host" type="text" class="formfld unknown" id="host" size="30" value="<?=htmlspecialchars($pconfig['host']);?>">
178
                    <br>
179
				    <span class="vexpl">
180
				    <span class="red"><strong>Note:<br></strong>
181
				    </span>
182
					Enter the complete host/domain name.  example:  myhost.dyndns.org
183
				    </span>
184
		          </td>
185
				</tr>
186
                <tr>
187
                  <td width="22%" valign="top" class="vncell">MX</td>
188
                  <td width="78%" class="vtable">
189
                    <input name="mx" type="text" class="formfld unknown" id="mx" size="30" value="<?=htmlspecialchars($pconfig['mx']);?>">
190
                    <br>
191
					Note: With DynDNS service you can only use a hostname, not an IP address.
192
					<br>
193
                    Set this option only if you need a special MX record. Not
194
                    all services support this.</td>
195
				</tr>
196
                <tr>
197
                  <td width="22%" valign="top" class="vncellreq">Wildcards</td>
198
                  <td width="78%" class="vtable">
199
                    <input name="wildcard" type="checkbox" id="wildcard" value="yes" <?php if ($pconfig['wildcard']) echo "checked"; ?>>
200
                    Enable Wildcard</td>
201
				</tr>
202
                <tr>
203
                  <td width="22%" valign="top" class="vncellreq">Username</td>
204
                  <td width="78%" class="vtable">
205
                    <input name="username" type="text" class="formfld user" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>">
206
                  </td>
207
                </tr>
208
                <tr>
209
                  <td width="22%" valign="top" class="vncellreq">Password</td>
210
                  <td width="78%" class="vtable">
211
                    <input name="password" type="password" class="formfld pwd" id="password" size="20" value="<?=htmlspecialchars($pconfig['password']);?>">
212
                  </td>
213
                </tr>
214
                <tr>
215
                  <td width="22%" valign="top" class="vncellreq">Description</td>
216
                  <td width="78%" class="vtable">
217
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>">
218
                  </td>
219
                </tr>
220
                <tr>
221
                  <td width="22%" valign="top">&nbsp;</td>
222
                  <td width="78%">
223
                    <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)">
224
					<a href="services_dyndns.php"><input name="cancel" type="button" class="formbtn" value="Cancel"></a>
225
					<?php if (isset($id) && $a_dyndns[$id]): ?>
226
						<input name="id" type="hidden" value="<?=$id;?>">
227
					<?php endif; ?>
228
                  </td>
229
                </tr>
230
                <tr>
231
                  <td width="22%" valign="top">&nbsp;</td>
232
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
233
                    </strong></span>You must configure a DNS server in <a href="system.php">System:
234
                    General setup</a> or allow the DNS server list to be overridden
235
                    by DHCP/PPP on WAN for dynamic DNS updates to work.</span></td>
236
                </tr>
237
              </table>
238
</form>
239 9e9b596f Ermal Luçi
<?php include("fend.inc"); ?>
240 f1f60c92 Ermal Luçi
</body>
241
</html>