Project

General

Profile

Download (14.4 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
	pfSense_BUILDER_BINARIES:	/bin/kill	/usr/bin/tar
33
	pfSense_MODULE:	system
34
*/
35

    
36
##|+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
require("guiconfig.inc");
44
require_once("functions.inc");
45
require_once("filter.inc");
46
require_once("shaper.inc");
47

    
48
$pconfig['hostname'] = $config['system']['hostname'];
49
$pconfig['domain'] = $config['system']['domain'];
50
list($pconfig['dns1'],$pconfig['dns2'],$pconfig['dns3'],$pconfig['dns4']) = $config['system']['dnsserver'];
51

    
52
$pconfig['dns1gwint'] = $config['system']['dns1gwint'];
53
$pconfig['dns2gwint'] = $config['system']['dns2gwint'];
54
$pconfig['dns3gwint'] = $config['system']['dns3gwint'];
55
$pconfig['dns4gwint'] = $config['system']['dns4gwint'];
56

    
57
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
58
$pconfig['timezone'] = $config['system']['timezone'];
59
$pconfig['timeupdateinterval'] = $config['system']['time-update-interval'];
60
$pconfig['timeservers'] = $config['system']['timeservers'];
61
$pconfig['theme'] = $config['system']['theme'];
62

    
63
if (!isset($pconfig['timeupdateinterval']))
64
	$pconfig['timeupdateinterval'] = 300;
65
if (!$pconfig['timezone'])
66
	$pconfig['timezone'] = "Etc/UTC";
67
if (!$pconfig['timeservers'])
68
	$pconfig['timeservers'] = "pool.ntp.org";
69

    
70
$changedesc = "System: ";
71
$changecount = 0;
72

    
73
function is_timezone($elt) {
74
	return !preg_match("/\/$/", $elt);
75
}
76

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

    
88
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
89
$timezonelist = array_filter($timezonelist, 'is_timezone');
90
sort($timezonelist);
91

    
92
$multiwan = false;
93
$interfaces = get_configured_interface_list();
94
foreach($interfaces as $interface) {
95
	if(interface_has_gateway($interface)) {
96
		$multiwan = true;
97
	}
98
}
99

    
100
if ($_POST) {
101

    
102
	$changecount++;
103
	
104
	unset($input_errors);
105
	$pconfig = $_POST;
106

    
107
	/* input validation */
108
	$reqdfields = split(" ", "hostname domain");
109
	$reqdfieldsn = split(",", "Hostname,Domain");
110

    
111
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
112

    
113
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
114
		$input_errors[] = "The hostname may only contain the characters a-z, 0-9 and '-'.";
115
	}
116
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
117
		$input_errors[] = "The domain may only contain the characters a-z, 0-9, '-' and '.'.";
118
	}
119
	if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) {
120
		$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS server.";
121
	}
122
	if (($_POST['dns3'] && !is_ipaddr($_POST['dns3'])) || ($_POST['dns4'] && !is_ipaddr($_POST['dns4']))) {
123
		$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS server.";
124
	}	
125
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
126
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
127
		$input_errors[] = "A valid TCP/IP port must be specified for the webConfigurator port.";
128
	}
129

    
130
	$direct_networks_list = explode(" ", filter_get_direct_networks_list());
131
	for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
132
		$dnsitem = "dns{$dnscounter}";
133
		$dnsgwitem = "dns{$dnscounter}gwint";
134
		if ($_POST[$dnsgwitem]) {
135
			if(interface_has_gateway($_POST[$dnsgwitem])) {
136
				foreach($direct_networks_list as $direct_network) {
137
					if(ip_in_subnet($_POST[$dnsitem], $direct_network)) {
138
						$input_errors[] = "You can not assign a gateway to DNS '{$_POST[$dnsitem]}' server which is on a directly connected network.";
139
					}
140
				}
141
			}
142
		}
143
	}
144

    
145
	$t = (int)$_POST['timeupdateinterval'];
146
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
147
		$input_errors[] = "The time update interval must be either 0 (disabled) or between 6 and 1440.";
148
	}
149
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
150
		if (!is_domain($ts)) {
151
			$input_errors[] = "A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.";
152
		}
153
	}
154

    
155
	if (!$input_errors) {
156
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
157
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
158

    
159
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
160
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
161
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
162

    
163
		/* pfSense themes */
164
		update_if_changed("System Theme", $config['theme'], $_POST['theme']);
165

    
166
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
167
		unset($config['system']['dnsserver']);
168
		if ($_POST['dns1'])
169
			$config['system']['dnsserver'][] = $_POST['dns1'];
170
		if ($_POST['dns2'])
171
			$config['system']['dnsserver'][] = $_POST['dns2'];
172
		if ($_POST['dns3'])
173
			$config['system']['dnsserver'][] = $_POST['dns3'];
174
		if ($_POST['dns4'])
175
			$config['system']['dnsserver'][] = $_POST['dns4'];
176

    
177
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
178

    
179
		unset($config['system']['dnsallowoverride']);
180
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
181

    
182
		/* which interface should the dns servers resolve through? */
183
		if($_POST['dns1gwint']) 
184
			$config['system']['dns1gwint'] = $pconfig['dns1gwint'];
185
		else 
186
			unset($config['system']['dns1gwint']);
187

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

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

    
198
		if($_POST['dns4gwint']) 
199
			$config['system']['dns4gwint'] = $pconfig['dns4gwint'];
200
		else
201
			unset($config['system']['dns4gwint']);
202

    
203
		if ($changecount > 0)
204
			write_config($changedesc);
205

    
206
		$retval = 0;
207
		$retval = system_hostname_configure();
208
		$retval |= system_hosts_generate();
209
		$retval |= system_resolvconf_generate();
210
		$retval |= services_dnsmasq_configure();
211
		$retval |= system_timezone_configure();
212
		$retval |= system_ntp_configure();
213

    
214
		/* XXX: ermal -- What is this supposed to do?! */
215
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
216
			$retval |= interface_configure();
217

    
218
		// Reload the filter - plugins might need to be run.
219
		$retval |= filter_configure();
220
		
221
		$savemsg = get_std_save_message($retval);
222
	}
223
}
224

    
225
$pgtitle = array("System","General Setup");
226
include("head.inc");
227

    
228
?>
229

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