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

    
213
		// Reload the filter - plugins might need to be run.
214
		filter_configure();
215
		
216
		config_unlock();
217

    
218
		$savemsg = get_std_save_message($retval);
219
	}
220
}
221

    
222
$pgtitle = array("System","General Setup");
223
include("head.inc");
224

    
225
?>
226

    
227
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
228
<?php
229
	include("fbegin.inc");
230
	if ($input_errors)
231
		print_input_errors($input_errors);
232
	if ($savemsg)
233
		print_info_box($savemsg);
234
?>
235
	<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
									<select name='<?=$fldname;?>'>
281
										<?php
282
										if ($multiwan) {
283
											$interface = "none";
284
											$dnsgw = "dns{$dnscounter}gwint";
285
											if($pconfig[$dnsgw] == $interface) {
286
												$selected = "selected";
287
											} else {
288
												$selected = "";
289
											}
290
											echo "<option value='$interface' $selected>". ucwords($interface) ."</option>\n";
291
											foreach($interfaces as $interface) {
292
												if(interface_has_gateway($interface)) {
293
													if($pconfig[$dnsgw] == $interface) {
294
														$selected = "selected";
295
													} else {
296
														$selected = "";
297
													}
298
													echo "<option value='$interface' $selected>". ucwords($interface) ."</option>\n";
299
												}
300
											}
301
										}
302
										?>
303
									</select>
304
								</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
					</select>
345
					<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
			<tr>
410
				<td colspan="2" class="list" height="12">&nbsp;</td>
411
			</tr>			
412
			<tr>
413
				<td width="22%" valign="top">&nbsp;</td>
414
				<td width="78%">
415
					<input name="Submit" type="submit" class="formbtn" value="Save">
416
				</td>
417
			</tr>
418
		</table>
419
	</form>
420
<?php include("fend.inc"); ?>
421
</body>
422
</html>
(163-163/210)