Project

General

Profile

Download (14.3 KB) Statistics
| Branch: | Tag: | Revision:
1 04ad7c7c Scott Ullrich
<?php
2 62d01225 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	system.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 04ad7c7c Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 04ad7c7c Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 04ad7c7c Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 04ad7c7c Scott Ullrich
16 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19 04ad7c7c Scott Ullrich
20 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32 6b07c15a Matthew Grooms
##|+PRIV
33
##|*IDENT=page-system-generalsetup
34
##|*NAME=System: General Setup page
35
##|*DESCR=Allow access to the 'System: General Setup' page.
36
##|*MATCH=system.php*
37
##|-PRIV
38
39
40 5b237745 Scott Ullrich
require("guiconfig.inc");
41
42
$pconfig['hostname'] = $config['system']['hostname'];
43
$pconfig['domain'] = $config['system']['domain'];
44 93e0800d Scott Ullrich
list($pconfig['dns1'],$pconfig['dns2'],$pconfig['dns3'],$pconfig['dns4']) = $config['system']['dnsserver'];
45 0d8a219e Scott Ullrich
46 e180a6e3 Scott Ullrich
$pconfig['dns1gwint'] = $config['system']['dns1gwint'];
47
$pconfig['dns2gwint'] = $config['system']['dns2gwint'];
48 93e0800d Scott Ullrich
$pconfig['dns3gwint'] = $config['system']['dns3gwint'];
49
$pconfig['dns4gwint'] = $config['system']['dns4gwint'];
50 e180a6e3 Scott Ullrich
51 5b237745 Scott Ullrich
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
52
$pconfig['timezone'] = $config['system']['timezone'];
53
$pconfig['timeupdateinterval'] = $config['system']['time-update-interval'];
54
$pconfig['timeservers'] = $config['system']['timeservers'];
55 f0f7a3eb Scott Ullrich
$pconfig['theme'] = $config['system']['theme'];
56 5b237745 Scott Ullrich
57
if (!isset($pconfig['timeupdateinterval']))
58
	$pconfig['timeupdateinterval'] = 300;
59
if (!$pconfig['timezone'])
60
	$pconfig['timezone'] = "Etc/UTC";
61
if (!$pconfig['timeservers'])
62
	$pconfig['timeservers'] = "pool.ntp.org";
63 04ad7c7c Scott Ullrich
64 417c6042 Bill Marquette
$changedesc = "System: ";
65 62d01225 Bill Marquette
$changecount = 0;
66 417c6042 Bill Marquette
67 5b237745 Scott Ullrich
function is_timezone($elt) {
68
	return !preg_match("/\/$/", $elt);
69
}
70
71 aa1ab1da Scott Ullrich
if($pconfig['timezone'] <> $_POST['timezone']) {
72
	/* restart firewall log dumper helper */
73
	require_once("functions.inc");
74 87c20eb5 Bill Marquette
	$pid = `ps awwwux | grep -v "grep" | grep "tcpdump -v -l -n -e -ttt -i pflog0"  | awk '{ print $2 }'`;
75 aa1ab1da Scott Ullrich
	if($pid) {
76
		mwexec("kill $pid");
77
		usleep(1000);
78
	}		
79
	filter_pflog_start();
80
}
81
82 5b237745 Scott Ullrich
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
83
$timezonelist = array_filter($timezonelist, 'is_timezone');
84
sort($timezonelist);
85
86 77446beb Matthew Grooms
$multiwan = false;
87 7922db8a Seth Mos
$interfaces = get_configured_interface_list();
88
foreach($interfaces as $interface) {
89
	if(interface_has_gateway($interface)) {
90 77446beb Matthew Grooms
		$multiwan = true;
91 7922db8a Seth Mos
	}
92
}
93 77446beb Matthew Grooms
94 5b237745 Scott Ullrich
if ($_POST) {
95
96 c668c964 Scott Ullrich
	$changecount++;
97 e180a6e3 Scott Ullrich
	
98 5b237745 Scott Ullrich
	unset($input_errors);
99
	$pconfig = $_POST;
100
101
	/* input validation */
102 ec5a5d65 Scott Dale
	$reqdfields = split(" ", "hostname domain");
103
	$reqdfieldsn = split(",", "Hostname,Domain");
104 04ad7c7c Scott Ullrich
105 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
106 04ad7c7c Scott Ullrich
107 5b237745 Scott Ullrich
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
108
		$input_errors[] = "The hostname may only contain the characters a-z, 0-9 and '-'.";
109
	}
110
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
111
		$input_errors[] = "The domain may only contain the characters a-z, 0-9, '-' and '.'.";
112
	}
113
	if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) {
114
		$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS server.";
115
	}
116 93e0800d Scott Ullrich
	if (($_POST['dns3'] && !is_ipaddr($_POST['dns3'])) || ($_POST['dns4'] && !is_ipaddr($_POST['dns4']))) {
117
		$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS server.";
118
	}	
119 04ad7c7c Scott Ullrich
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
120 5b237745 Scott Ullrich
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
121 709cc6e0 Bill Marquette
		$input_errors[] = "A valid TCP/IP port must be specified for the webConfigurator port.";
122 5b237745 Scott Ullrich
	}
123 04ad7c7c Scott Ullrich
124 985fc0fb Ermal Lu?i
	$direct_networks_list = explode(" ", filter_get_direct_networks_list());
125 c98d28e1 Seth Mos
	for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
126
		$dnsitem = "dns{$dnscounter}";
127
		$dnsgwitem = "dns{$dnscounter}gwint";
128
		if ($_POST[$dnsgwitem]) {
129
			if(interface_has_gateway($_POST[$dnsgwitem])) {
130
				foreach($direct_networks_list as $direct_network) {
131
					if(ip_in_subnet($_POST[$dnsitem], $direct_network)) {
132
						$input_errors[] = "You can not assign a gateway to DNS '{$_POST[$dnsitem]}' server which is on a directly connected network.";
133
					}
134
				}
135
			}
136
		}
137
	}
138
139 5b237745 Scott Ullrich
	$t = (int)$_POST['timeupdateinterval'];
140
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
141
		$input_errors[] = "The time update interval must be either 0 (disabled) or between 6 and 1440.";
142
	}
143
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
144
		if (!is_domain($ts)) {
145
			$input_errors[] = "A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.";
146
		}
147
	}
148
149
	if (!$input_errors) {
150 9eab73da Bill Marquette
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
151
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
152 79f8694f Bill Marquette
153 9eab73da Bill Marquette
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
154
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
155
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
156 04ad7c7c Scott Ullrich
157 f0f7a3eb Scott Ullrich
		/* pfSense themes */
158 20b90e0a Scott Ullrich
		update_if_changed("System Theme", $config['theme'], $_POST['theme']);
159 f0f7a3eb Scott Ullrich
160 4fbf63aa Bill Marquette
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
161 5b237745 Scott Ullrich
		unset($config['system']['dnsserver']);
162
		if ($_POST['dns1'])
163
			$config['system']['dnsserver'][] = $_POST['dns1'];
164
		if ($_POST['dns2'])
165
			$config['system']['dnsserver'][] = $_POST['dns2'];
166 93e0800d Scott Ullrich
		if ($_POST['dns3'])
167
			$config['system']['dnsserver'][] = $_POST['dns3'];
168
		if ($_POST['dns4'])
169
			$config['system']['dnsserver'][] = $_POST['dns4'];
170 04ad7c7c Scott Ullrich
171 07bd3f83 Scott Ullrich
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
172 20b90e0a Scott Ullrich
173 0d8a219e Scott Ullrich
		unset($config['system']['dnsallowoverride']);
174 5b237745 Scott Ullrich
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
175 e180a6e3 Scott Ullrich
176
		/* which interface should the dns servers resolve through? */
177
		if($_POST['dns1gwint']) 
178
			$config['system']['dns1gwint'] = $pconfig['dns1gwint'];
179
		else 
180
			unset($config['system']['dns1gwint']);
181 3537ac27 Seth Mos
182 e180a6e3 Scott Ullrich
		if($_POST['dns2gwint']) 
183
			$config['system']['dns2gwint'] = $pconfig['dns2gwint'];
184
		else
185
			unset($config['system']['dns2gwint']);
186 3537ac27 Seth Mos
187 93e0800d Scott Ullrich
		if($_POST['dns3gwint']) 
188 5aaf13c4 Seth Mos
			$config['system']['dns3gwint'] = $pconfig['dns3gwint'];
189 93e0800d Scott Ullrich
		else 
190
			unset($config['system']['dns3gwint']);
191 3537ac27 Seth Mos
192 93e0800d Scott Ullrich
		if($_POST['dns4gwint']) 
193
			$config['system']['dns4gwint'] = $pconfig['dns4gwint'];
194
		else
195
			unset($config['system']['dns4gwint']);
196 04ad7c7c Scott Ullrich
197 62d01225 Bill Marquette
		if ($changecount > 0)
198
			write_config($changedesc);
199 04ad7c7c Scott Ullrich
200 5b237745 Scott Ullrich
		$retval = 0;
201 3cfdba5f Scott Ullrich
		$retval = system_hostname_configure();
202
		$retval |= system_hosts_generate();
203
		$retval |= system_resolvconf_generate();
204
		$retval |= services_dnsmasq_configure();
205
		$retval |= system_timezone_configure();
206
		$retval |= system_ntp_configure();
207
208 69e5a8be Ermal Luçi
		/* XXX: ermal -- What is this supposed to do?! */
209 3cfdba5f Scott Ullrich
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
210 69e5a8be Ermal Luçi
			$retval |= interface_configure();
211 3cfdba5f Scott Ullrich
212 e7d967d8 Scott Ullrich
		// Reload the filter - plugins might need to be run.
213 0027de0a Ermal Lu?i
		$retval |= filter_configure();
214 e7d967d8 Scott Ullrich
		
215 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
216
	}
217
}
218 4df96eff Scott Ullrich
219 d88c6a9f Scott Ullrich
$pgtitle = array("System","General Setup");
220 4df96eff Scott Ullrich
include("head.inc");
221
222 5b237745 Scott Ullrich
?>
223 4df96eff Scott Ullrich
224 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
225 f0f7a3eb Scott Ullrich
<?php
226 77446beb Matthew Grooms
	include("fbegin.inc");
227
	if ($input_errors)
228
		print_input_errors($input_errors);
229
	if ($savemsg)
230
		print_info_box($savemsg);
231 f0f7a3eb Scott Ullrich
?>
232 77446beb Matthew Grooms
	<form action="system.php" method="post">
233
		<table width="100%" border="0" cellpadding="6" cellspacing="0">
234 27b07eda Ermal Lu?i
                        <tr>
235
                                <td id="mainarea">
236
                                        <div class="tabcont">
237
			<table width="100%" border="0" cellpadding="6" cellspacing="0">
238 77446beb Matthew Grooms
			<tr>
239
				<td colspan="2" valign="top" class="listtopic">System</td>
240
			</tr>
241
			<tr>
242
				<td width="22%" valign="top" class="vncellreq">Hostname</td>
243
				<td width="78%" class="vtable"> <input name="hostname" type="text" class="formfld unknown" id="hostname" size="40" value="<?=htmlspecialchars($pconfig['hostname']);?>">
244
					<br/>
245
					<span class="vexpl">
246
						name of the firewall host, without domain part
247
						<br>
248
						e.g. <em>firewall</em>
249
					</span>
250
				</td>
251
			</tr>
252
			<tr>
253
				<td width="22%" valign="top" class="vncellreq">Domain</td>
254
				<td width="78%" class="vtable"> <input name="domain" type="text" class="formfld unknown" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
255
					<br/>
256
					<span class="vexpl">
257 87f0be87 Chris Buechler
						e.g. <em>mycorp.com</em>
258 77446beb Matthew Grooms
					</span>
259
				</td>
260
			</tr>
261
			<tr>
262
				<td width="22%" valign="top" class="vncell">DNS servers</td>
263
				<td width="78%" class="vtable">
264
					<p>
265
						<table>
266
							<tr>
267
								<td><b>DNS Server</b></td>
268
								<?php if ($multiwan): ?>
269
								<td><b>Use gateway</b></td>
270
								<?php endif; ?>
271
							</tr>
272
							<?php
273
								for ($dnscounter=1; $dnscounter<5; $dnscounter++):
274
									$fldname="dns{$dnscounter}gwint";
275
							?>
276
							<tr>
277
								<td>
278
									<input name="dns<?php echo $dnscounter;?>" type="text" class="formfld unknown" id="dns<?php echo $dnscounter;?>" size="20" value="<?php echo $pconfig['dns'.$dnscounter];?>">
279
								</td>
280
								<td>
281 a077b479 Ermal Luçi
<?php if ($multiwan): ?>
282 3537ac27 Seth Mos
									<select name='<?=$fldname;?>'>
283 77446beb Matthew Grooms
										<?php
284 7922db8a Seth Mos
											$interface = "none";
285 3537ac27 Seth Mos
											$dnsgw = "dns{$dnscounter}gwint";
286
											if($pconfig[$dnsgw] == $interface) {
287
												$selected = "selected";
288 7922db8a Seth Mos
											} else {
289 77446beb Matthew Grooms
												$selected = "";
290 7922db8a Seth Mos
											}
291 3537ac27 Seth Mos
											echo "<option value='$interface' $selected>". ucwords($interface) ."</option>\n";
292 7922db8a Seth Mos
											foreach($interfaces as $interface) {
293
												if(interface_has_gateway($interface)) {
294 3537ac27 Seth Mos
													if($pconfig[$dnsgw] == $interface) {
295
														$selected = "selected";
296 7922db8a Seth Mos
													} else {
297
														$selected = "";
298
													}
299 8ac4df97 Scott Ullrich
													$friendly_interface = convert_friendly_interface_to_friendly_descr($interface);
300
													echo "<option value='$interface' $selected>". ucwords($friendly_interface) ."</option>\n";
301 7922db8a Seth Mos
												}
302
											}
303 77446beb Matthew Grooms
										?>
304
									</select>
305 a077b479 Ermal Luçi
<?php endif; ?>
306 77446beb Matthew Grooms
								</td>
307
							</tr>
308
							<?php endfor; ?>
309
						</table>
310
						<br>
311
						<span class="vexpl">
312 87f0be87 Chris Buechler
							IP addresses; these are also used for the DHCP
313 77446beb Matthew Grooms
							service, DNS forwarder and for PPTP VPN clients.
314
							<br/>
315
							<?php if($multiwan): ?>
316
							<br/>
317
							In addition, select the gateway for each DNS server.
318
							You should have a unique DNS server per gateway.
319
							<br/>
320
							<?php endif; ?>
321
							<br/>
322
							<input name="dnsallowoverride" type="checkbox" id="dnsallowoverride" value="yes" <?php if ($pconfig['dnsallowoverride']) echo "checked"; ?>>
323
							<strong>
324
								Allow DNS server list to be overridden by DHCP/PPP
325
								on WAN
326
							</strong>
327
							<br/>
328
							If this option is set, <?=$g['product_name'];?> will
329
							use DNS servers assigned by a DHCP/PPP server on WAN
330
							for its own purposes (including the DNS forwarder).
331
							However, they will not be assigned to DHCP and PPTP
332
							VPN	clients.
333
						</span>
334
					</p>
335
				</td>
336
			</tr>
337
			<tr>
338
				<td width="22%" valign="top" class="vncell">Time zone</td>
339
				<td width="78%" class="vtable">
340
					<select name="timezone" id="timezone">
341
						<?php foreach ($timezonelist as $value): ?>
342
						<option value="<?=htmlspecialchars($value);?>" <?php if ($value == $pconfig['timezone']) echo "selected"; ?>>
343
							<?=htmlspecialchars($value);?>
344
						</option>
345
						<?php endforeach; ?>
346 f0f7a3eb Scott Ullrich
					</select>
347 77446beb Matthew Grooms
					<br/>
348
					<span class="vexpl">
349
						Select the location closest to you
350
					</span>
351
				</td>
352
			</tr>
353
<!--
354
			<tr>
355
				<td width="22%" valign="top" class="vncell">Time update interval</td>
356
				<td width="78%" class="vtable">
357
					<input name="timeupdateinterval" type="text" class="formfld unknown" id="timeupdateinterval" size="4" value="<?=htmlspecialchars($pconfig['timeupdateinterval']);?>">
358
					<br/>
359
					<span class="vexpl">
360
						Minutes between network time sync. 300 recommended,
361
						or 0 to disable
362
					</span>
363
				</td>
364
			</tr>
365
-->
366
			<tr>
367
				<td width="22%" valign="top" class="vncell">NTP time server</td>
368
				<td width="78%" class="vtable">
369
					<input name="timeservers" type="text" class="formfld unknown" id="timeservers" size="40" value="<?=htmlspecialchars($pconfig['timeservers']);?>">
370
					<br/>
371
					<span class="vexpl">
372
						Use a space to separate multiple hosts (only one
373
						required). Remember to set up at least one DNS server
374
						if you enter a host name here!
375
					</span>
376
				</td>
377
			</tr>
378
			<tr>
379
				<td colspan="2" class="list" height="12">&nbsp;</td>
380
			</tr>
381
			<tr>
382
				<td colspan="2" valign="top" class="listtopic">Theme</td>
383
			</tr>
384
			<tr>
385
				<td width="22%" valign="top" class="vncell">&nbsp;</td>
386
				<td width="78%" class="vtable">
387
					<select name="theme">
388
						<?php
389
							$files = return_dir_as_array("/usr/local/www/themes/");
390
							foreach($files as $f):
391
								if ((substr($f, 0, 1) == "_") && !isset($config['system']['developer']))
392
									continue;
393
								if ($f == "CVS")
394
									continue;
395
								$curtheme = "pfsense";
396
								if ($config['theme'])
397
									$curtheme = $config['theme'];
398
								$selected = "";
399
								if($f == $curtheme)
400
									$selected = " SELECTED";
401
						?>
402
						<option <?=$selected;?>><?=$f;?></option>
403
						<?php endforeach; ?>
404
					</select>
405
					<strong>
406
						This will change the look and feel of
407
						<?=$g['product_name'];?>.
408
					</strong>
409
				</td>
410
			</tr>
411 306f082a Scott Ullrich
			<tr>
412
				<td colspan="2" class="list" height="12">&nbsp;</td>
413
			</tr>			
414 77446beb Matthew Grooms
			<tr>
415
				<td width="22%" valign="top">&nbsp;</td>
416
				<td width="78%">
417
					<input name="Submit" type="submit" class="formbtn" value="Save">
418 f0f7a3eb Scott Ullrich
				</td>
419 77446beb Matthew Grooms
			</tr>
420
		</table>
421 27b07eda Ermal Lu?i
		</div>
422
		</td></tr>
423
		</table>
424 77446beb Matthew Grooms
	</form>
425 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
426 2f3f316c Scott Ullrich
</body>
427
</html>