Project

General

Profile

Download (14 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 c98d28e1 Seth Mos
	$direct_networks_list = explode(" ", get_direct_networks_list());
125
	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
		config_lock();
202
		$retval = system_hostname_configure();
203
		$retval |= system_hosts_generate();
204
		$retval |= system_resolvconf_generate();
205
		$retval |= services_dnsmasq_configure();
206
		$retval |= system_timezone_configure();
207
		$retval |= system_ntp_configure();
208
209 69e5a8be Ermal Luçi
		/* XXX: ermal -- What is this supposed to do?! */
210 3cfdba5f Scott Ullrich
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
211 69e5a8be Ermal Luçi
			$retval |= interface_configure();
212 3cfdba5f Scott Ullrich
213 e7d967d8 Scott Ullrich
		// Reload the filter - plugins might need to be run.
214
		filter_configure();
215
		
216 3cfdba5f Scott Ullrich
		config_unlock();
217 04ad7c7c Scott Ullrich
218 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
219
	}
220
}
221 4df96eff Scott Ullrich
222 d88c6a9f Scott Ullrich
$pgtitle = array("System","General Setup");
223 4df96eff Scott Ullrich
include("head.inc");
224
225 5b237745 Scott Ullrich
?>
226 4df96eff Scott Ullrich
227 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
228 f0f7a3eb Scott Ullrich
<?php
229 77446beb Matthew Grooms
	include("fbegin.inc");
230
	if ($input_errors)
231
		print_input_errors($input_errors);
232
	if ($savemsg)
233
		print_info_box($savemsg);
234 f0f7a3eb Scott Ullrich
?>
235 77446beb Matthew Grooms
	<form action="system.php" method="post">
236
		<table width="100%" border="0" cellpadding="6" cellspacing="0">
237
			<tr>
238
				<td colspan="2" valign="top" class="listtopic">System</td>
239
			</tr>
240
			<tr>
241
				<td width="22%" valign="top" class="vncellreq">Hostname</td>
242
				<td width="78%" class="vtable"> <input name="hostname" type="text" class="formfld unknown" id="hostname" size="40" value="<?=htmlspecialchars($pconfig['hostname']);?>">
243
					<br/>
244
					<span class="vexpl">
245
						name of the firewall host, without domain part
246
						<br>
247
						e.g. <em>firewall</em>
248
					</span>
249
				</td>
250
			</tr>
251
			<tr>
252
				<td width="22%" valign="top" class="vncellreq">Domain</td>
253
				<td width="78%" class="vtable"> <input name="domain" type="text" class="formfld unknown" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
254
					<br/>
255
					<span class="vexpl">
256
						e.g. <em>mycorp.com</em>
257
					</span>
258
				</td>
259
			</tr>
260
			<tr>
261
				<td width="22%" valign="top" class="vncell">DNS servers</td>
262
				<td width="78%" class="vtable">
263
					<p>
264
						<table>
265
							<tr>
266
								<td><b>DNS Server</b></td>
267
								<?php if ($multiwan): ?>
268
								<td><b>Use gateway</b></td>
269
								<?php endif; ?>
270
							</tr>
271
							<?php
272
								for ($dnscounter=1; $dnscounter<5; $dnscounter++):
273
									$fldname="dns{$dnscounter}gwint";
274
							?>
275
							<tr>
276
								<td>
277
									<input name="dns<?php echo $dnscounter;?>" type="text" class="formfld unknown" id="dns<?php echo $dnscounter;?>" size="20" value="<?php echo $pconfig['dns'.$dnscounter];?>">
278
								</td>
279
								<td>
280 a077b479 Ermal Luçi
<?php if ($multiwan): ?>
281 3537ac27 Seth Mos
									<select name='<?=$fldname;?>'>
282 77446beb Matthew Grooms
										<?php
283 7922db8a Seth Mos
											$interface = "none";
284 3537ac27 Seth Mos
											$dnsgw = "dns{$dnscounter}gwint";
285
											if($pconfig[$dnsgw] == $interface) {
286
												$selected = "selected";
287 7922db8a Seth Mos
											} else {
288 77446beb Matthew Grooms
												$selected = "";
289 7922db8a Seth Mos
											}
290 3537ac27 Seth Mos
											echo "<option value='$interface' $selected>". ucwords($interface) ."</option>\n";
291 7922db8a Seth Mos
											foreach($interfaces as $interface) {
292
												if(interface_has_gateway($interface)) {
293 3537ac27 Seth Mos
													if($pconfig[$dnsgw] == $interface) {
294
														$selected = "selected";
295 7922db8a Seth Mos
													} else {
296
														$selected = "";
297
													}
298 3537ac27 Seth Mos
													echo "<option value='$interface' $selected>". ucwords($interface) ."</option>\n";
299 7922db8a Seth Mos
												}
300
											}
301 77446beb Matthew Grooms
										?>
302
									</select>
303 a077b479 Ermal Luçi
<?php endif; ?>
304 77446beb Matthew Grooms
								</td>
305
							</tr>
306
							<?php endfor; ?>
307
						</table>
308
						<br>
309
						<span class="vexpl">
310
							IP addresses; these are also used for the DHCP
311
							service, DNS forwarder and for PPTP VPN clients.
312
							<br/>
313
							<?php if($multiwan): ?>
314
							<br/>
315
							In addition, select the gateway for each DNS server.
316
							You should have a unique DNS server per gateway.
317
							<br/>
318
							<?php endif; ?>
319
							<br/>
320
							<input name="dnsallowoverride" type="checkbox" id="dnsallowoverride" value="yes" <?php if ($pconfig['dnsallowoverride']) echo "checked"; ?>>
321
							<strong>
322
								Allow DNS server list to be overridden by DHCP/PPP
323
								on WAN
324
							</strong>
325
							<br/>
326
							If this option is set, <?=$g['product_name'];?> will
327
							use DNS servers assigned by a DHCP/PPP server on WAN
328
							for its own purposes (including the DNS forwarder).
329
							However, they will not be assigned to DHCP and PPTP
330
							VPN	clients.
331
						</span>
332
					</p>
333
				</td>
334
			</tr>
335
			<tr>
336
				<td width="22%" valign="top" class="vncell">Time zone</td>
337
				<td width="78%" class="vtable">
338
					<select name="timezone" id="timezone">
339
						<?php foreach ($timezonelist as $value): ?>
340
						<option value="<?=htmlspecialchars($value);?>" <?php if ($value == $pconfig['timezone']) echo "selected"; ?>>
341
							<?=htmlspecialchars($value);?>
342
						</option>
343
						<?php endforeach; ?>
344 f0f7a3eb Scott Ullrich
					</select>
345 77446beb Matthew Grooms
					<br/>
346
					<span class="vexpl">
347
						Select the location closest to you
348
					</span>
349
				</td>
350
			</tr>
351
<!--
352
			<tr>
353
				<td width="22%" valign="top" class="vncell">Time update interval</td>
354
				<td width="78%" class="vtable">
355
					<input name="timeupdateinterval" type="text" class="formfld unknown" id="timeupdateinterval" size="4" value="<?=htmlspecialchars($pconfig['timeupdateinterval']);?>">
356
					<br/>
357
					<span class="vexpl">
358
						Minutes between network time sync. 300 recommended,
359
						or 0 to disable
360
					</span>
361
				</td>
362
			</tr>
363
-->
364
			<tr>
365
				<td width="22%" valign="top" class="vncell">NTP time server</td>
366
				<td width="78%" class="vtable">
367
					<input name="timeservers" type="text" class="formfld unknown" id="timeservers" size="40" value="<?=htmlspecialchars($pconfig['timeservers']);?>">
368
					<br/>
369
					<span class="vexpl">
370
						Use a space to separate multiple hosts (only one
371
						required). Remember to set up at least one DNS server
372
						if you enter a host name here!
373
					</span>
374
				</td>
375
			</tr>
376
			<tr>
377
				<td colspan="2" class="list" height="12">&nbsp;</td>
378
			</tr>
379
			<tr>
380
				<td colspan="2" valign="top" class="listtopic">Theme</td>
381
			</tr>
382
			<tr>
383
				<td width="22%" valign="top" class="vncell">&nbsp;</td>
384
				<td width="78%" class="vtable">
385
					<select name="theme">
386
						<?php
387
							$files = return_dir_as_array("/usr/local/www/themes/");
388
							foreach($files as $f):
389
								if ((substr($f, 0, 1) == "_") && !isset($config['system']['developer']))
390
									continue;
391
								if ($f == "CVS")
392
									continue;
393
								$curtheme = "pfsense";
394
								if ($config['theme'])
395
									$curtheme = $config['theme'];
396
								$selected = "";
397
								if($f == $curtheme)
398
									$selected = " SELECTED";
399
						?>
400
						<option <?=$selected;?>><?=$f;?></option>
401
						<?php endforeach; ?>
402
					</select>
403
					<strong>
404
						This will change the look and feel of
405
						<?=$g['product_name'];?>.
406
					</strong>
407
				</td>
408
			</tr>
409 306f082a Scott Ullrich
			<tr>
410
				<td colspan="2" class="list" height="12">&nbsp;</td>
411
			</tr>			
412 77446beb Matthew Grooms
			<tr>
413
				<td width="22%" valign="top">&nbsp;</td>
414
				<td width="78%">
415
					<input name="Submit" type="submit" class="formbtn" value="Save">
416 f0f7a3eb Scott Ullrich
				</td>
417 77446beb Matthew Grooms
			</tr>
418
		</table>
419
	</form>
420 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
421 2f3f316c Scott Ullrich
</body>
422
</html>