Project

General

Profile

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