Project

General

Profile

Download (13 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
foreach($config['interfaces'] as $int) 
88
	if($int['gateway']) 
89
		$multiwan = true;
90

    
91
$ints = get_interface_list();
92

    
93
if ($_POST) {
94

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

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

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

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

    
123
	$t = (int)$_POST['timeupdateinterval'];
124
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
125
		$input_errors[] = "The time update interval must be either 0 (disabled) or between 6 and 1440.";
126
	}
127
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
128
		if (!is_domain($ts)) {
129
			$input_errors[] = "A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.";
130
		}
131
	}
132

    
133
	if (!$input_errors) {
134
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
135
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
136

    
137
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
138
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
139
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
140

    
141
		/* pfSense themes */
142
		update_if_changed("System Theme", $config['theme'], $_POST['theme']);
143

    
144
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
145
		unset($config['system']['dnsserver']);
146
		if ($_POST['dns1'])
147
			$config['system']['dnsserver'][] = $_POST['dns1'];
148
		if ($_POST['dns2'])
149
			$config['system']['dnsserver'][] = $_POST['dns2'];
150
		if ($_POST['dns3'])
151
			$config['system']['dnsserver'][] = $_POST['dns3'];
152
		if ($_POST['dns4'])
153
			$config['system']['dnsserver'][] = $_POST['dns4'];
154

    
155
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
156

    
157
		unset($config['system']['dnsallowoverride']);
158
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
159

    
160
		/* which interface should the dns servers resolve through? */
161
		if($_POST['dns1gwint']) 
162
			$config['system']['dns1gwint'] = $pconfig['dns1gwint'];
163
		else 
164
			unset($config['system']['dns1gwint']);
165
		if($_POST['dns2gwint']) 
166
			$config['system']['dns2gwint'] = $pconfig['dns2gwint'];
167
		else
168
			unset($config['system']['dns2gwint']);
169
		if($_POST['dns3gwint']) 
170
			$config['system']['dns1gwint'] = $pconfig['dns3gwint'];
171
		else 
172
			unset($config['system']['dns3gwint']);
173
		if($_POST['dns4gwint']) 
174
			$config['system']['dns4gwint'] = $pconfig['dns4gwint'];
175
		else
176
			unset($config['system']['dns4gwint']);
177

    
178
		if ($changecount > 0)
179
			write_config($changedesc);
180

    
181
		$retval = 0;
182
		config_lock();
183
		$retval = system_hostname_configure();
184
		$retval |= system_hosts_generate();
185
		$retval |= system_resolvconf_generate();
186
		$retval |= services_dnsmasq_configure();
187
		$retval |= system_timezone_configure();
188
		$retval |= system_ntp_configure();
189

    
190
		/* XXX: ermal -- What is this supposed to do?! */
191
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
192
			$retval |= interface_configure();
193

    
194
		// Reload the filter - plugins might need to be run.
195
		filter_configure();
196
		
197
		config_unlock();
198

    
199
		$savemsg = get_std_save_message($retval);
200
	}
201
}
202

    
203
$pgtitle = array("System","General Setup");
204
include("head.inc");
205

    
206
?>
207

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