Project

General

Profile

Download (14 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	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

    
20
	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
##|+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
require("guiconfig.inc");
41

    
42
$pconfig['hostname'] = $config['system']['hostname'];
43
$pconfig['domain'] = $config['system']['domain'];
44
list($pconfig['dns1'],$pconfig['dns2'],$pconfig['dns3'],$pconfig['dns4']) = $config['system']['dnsserver'];
45

    
46
$pconfig['dns1gwint'] = $config['system']['dns1gwint'];
47
$pconfig['dns2gwint'] = $config['system']['dns2gwint'];
48
$pconfig['dns3gwint'] = $config['system']['dns3gwint'];
49
$pconfig['dns4gwint'] = $config['system']['dns4gwint'];
50

    
51
$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
$pconfig['theme'] = $config['system']['theme'];
56

    
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

    
64
$changedesc = "System: ";
65
$changecount = 0;
66

    
67
function is_timezone($elt) {
68
	return !preg_match("/\/$/", $elt);
69
}
70

    
71
if($pconfig['timezone'] <> $_POST['timezone']) {
72
	/* restart firewall log dumper helper */
73
	require_once("functions.inc");
74
	$pid = `ps awwwux | grep -v "grep" | grep "tcpdump -v -l -n -e -ttt -i pflog0"  | awk '{ print $2 }'`;
75
	if($pid) {
76
		mwexec("kill $pid");
77
		usleep(1000);
78
	}		
79
	filter_pflog_start();
80
}
81

    
82
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
83
$timezonelist = array_filter($timezonelist, 'is_timezone');
84
sort($timezonelist);
85

    
86
$multiwan = false;
87
$interfaces = get_configured_interface_list();
88
foreach($interfaces as $interface) {
89
	if(interface_has_gateway($interface)) {
90
		$multiwan = true;
91
	}
92
}
93

    
94
if ($_POST) {
95

    
96
	$changecount++;
97
	
98
	unset($input_errors);
99
	$pconfig = $_POST;
100

    
101
	/* input validation */
102
	$reqdfields = split(" ", "hostname domain");
103
	$reqdfieldsn = split(",", "Hostname,Domain");
104

    
105
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
106

    
107
	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
	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
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
120
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
121
		$input_errors[] = "A valid TCP/IP port must be specified for the webConfigurator port.";
122
	}
123

    
124
	$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
	$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
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
151
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
152

    
153
		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

    
157
		/* pfSense themes */
158
		update_if_changed("System Theme", $config['theme'], $_POST['theme']);
159

    
160
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
161
		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
		if ($_POST['dns3'])
167
			$config['system']['dnsserver'][] = $_POST['dns3'];
168
		if ($_POST['dns4'])
169
			$config['system']['dnsserver'][] = $_POST['dns4'];
170

    
171
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
172

    
173
		unset($config['system']['dnsallowoverride']);
174
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
175

    
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

    
182
		if($_POST['dns2gwint']) 
183
			$config['system']['dns2gwint'] = $pconfig['dns2gwint'];
184
		else
185
			unset($config['system']['dns2gwint']);
186

    
187
		if($_POST['dns3gwint']) 
188
			$config['system']['dns3gwint'] = $pconfig['dns3gwint'];
189
		else 
190
			unset($config['system']['dns3gwint']);
191

    
192
		if($_POST['dns4gwint']) 
193
			$config['system']['dns4gwint'] = $pconfig['dns4gwint'];
194
		else
195
			unset($config['system']['dns4gwint']);
196

    
197
		if ($changecount > 0)
198
			write_config($changedesc);
199

    
200
		$retval = 0;
201
		$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
		/* XXX: ermal -- What is this supposed to do?! */
209
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
210
			$retval |= interface_configure();
211

    
212
		// Reload the filter - plugins might need to be run.
213
		$retval |= filter_configure();
214
		
215
		$savemsg = get_std_save_message($retval);
216
	}
217
}
218

    
219
$pgtitle = array("System","General Setup");
220
include("head.inc");
221

    
222
?>
223

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