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

    
45
$pconfig['hostname'] = $config['system']['hostname'];
46
$pconfig['domain'] = $config['system']['domain'];
47
list($pconfig['dns1'],$pconfig['dns2'],$pconfig['dns3'],$pconfig['dns4']) = $config['system']['dnsserver'];
48

    
49
$pconfig['dns1gwint'] = $config['system']['dns1gwint'];
50
$pconfig['dns2gwint'] = $config['system']['dns2gwint'];
51
$pconfig['dns3gwint'] = $config['system']['dns3gwint'];
52
$pconfig['dns4gwint'] = $config['system']['dns4gwint'];
53

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

    
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

    
67
$changedesc = "System: ";
68
$changecount = 0;
69

    
70
function is_timezone($elt) {
71
	return !preg_match("/\/$/", $elt);
72
}
73

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

    
85
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
86
$timezonelist = array_filter($timezonelist, 'is_timezone');
87
sort($timezonelist);
88

    
89
$multiwan = false;
90
$interfaces = get_configured_interface_list();
91
foreach($interfaces as $interface) {
92
	if(interface_has_gateway($interface)) {
93
		$multiwan = true;
94
	}
95
}
96

    
97
if ($_POST) {
98

    
99
	$changecount++;
100
	
101
	unset($input_errors);
102
	$pconfig = $_POST;
103

    
104
	/* input validation */
105
	$reqdfields = split(" ", "hostname domain");
106
	$reqdfieldsn = split(",", "Hostname,Domain");
107

    
108
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
109

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

    
127
	$direct_networks_list = explode(" ", filter_get_direct_networks_list());
128
	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
	$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
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
154
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
155

    
156
		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

    
160
		/* pfSense themes */
161
		update_if_changed("System Theme", $config['theme'], $_POST['theme']);
162

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

    
174
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
175

    
176
		unset($config['system']['dnsallowoverride']);
177
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
178

    
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

    
185
		if($_POST['dns2gwint']) 
186
			$config['system']['dns2gwint'] = $pconfig['dns2gwint'];
187
		else
188
			unset($config['system']['dns2gwint']);
189

    
190
		if($_POST['dns3gwint']) 
191
			$config['system']['dns3gwint'] = $pconfig['dns3gwint'];
192
		else 
193
			unset($config['system']['dns3gwint']);
194

    
195
		if($_POST['dns4gwint']) 
196
			$config['system']['dns4gwint'] = $pconfig['dns4gwint'];
197
		else
198
			unset($config['system']['dns4gwint']);
199

    
200
		if ($changecount > 0)
201
			write_config($changedesc);
202

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

    
215
		// Reload the filter - plugins might need to be run.
216
		$retval |= filter_configure();
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 id="mainarea">
239
                                        <div class="tabcont">
240
			<table width="100%" border="0" cellpadding="6" cellspacing="0">
241
			<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
						e.g. <em>mycorp.com</em>
261
					</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
<?php if ($multiwan): ?>
285
									<select name='<?=$fldname;?>'>
286
										<?php
287
											$interface = "none";
288
											$dnsgw = "dns{$dnscounter}gwint";
289
											if($pconfig[$dnsgw] == $interface) {
290
												$selected = "selected";
291
											} else {
292
												$selected = "";
293
											}
294
											echo "<option value='$interface' $selected>". ucwords($interface) ."</option>\n";
295
											foreach($interfaces as $interface) {
296
												if(interface_has_gateway($interface)) {
297
													if($pconfig[$dnsgw] == $interface) {
298
														$selected = "selected";
299
													} else {
300
														$selected = "";
301
													}
302
													$friendly_interface = convert_friendly_interface_to_friendly_descr($interface);
303
													echo "<option value='$interface' $selected>". ucwords($friendly_interface) ."</option>\n";
304
												}
305
											}
306
										?>
307
									</select>
308
<?php endif; ?>
309
								</td>
310
							</tr>
311
							<?php endfor; ?>
312
						</table>
313
						<br>
314
						<span class="vexpl">
315
							IP addresses; these are also used for the DHCP
316
							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
					</select>
350
					<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
			<tr>
415
				<td colspan="2" class="list" height="12">&nbsp;</td>
416
			</tr>			
417
			<tr>
418
				<td width="22%" valign="top">&nbsp;</td>
419
				<td width="78%">
420
					<input name="Submit" type="submit" class="formbtn" value="Save">
421
				</td>
422
			</tr>
423
		</table>
424
		</div>
425
		</td></tr>
426
		</table>
427
	</form>
428
<?php include("fend.inc"); ?>
429
</body>
430
</html>
(168-168/217)