Project

General

Profile

Download (16.1 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

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

    
52
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
53
$pconfig['webguiproto'] = $config['system']['webgui']['protocol'];
54
if (!$pconfig['webguiproto'])
55
	$pconfig['webguiproto'] = "http";
56
$pconfig['webguiport'] = $config['system']['webgui']['port'];
57
$pconfig['timezone'] = $config['system']['timezone'];
58
$pconfig['timeupdateinterval'] = $config['system']['time-update-interval'];
59
$pconfig['timeservers'] = $config['system']['timeservers'];
60
$pconfig['theme'] = $config['system']['theme'];
61

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

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

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

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

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

    
91
if ($_POST) {
92

    
93
	$changecount++;
94
	
95
	unset($input_errors);
96
	$pconfig = $_POST;
97

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

    
102
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
103

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

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

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

    
135
		if (update_if_changed("webgui protocol", $config['system']['webgui']['protocol'], $_POST['webguiproto']))
136
			$restart_webgui = true;
137
		if (update_if_changed("webgui port", $config['system']['webgui']['port'], $_POST['webguiport']))
138
			$restart_webgui = true;
139

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

    
144
		/* pfSense themes */
145
		update_if_changed("System Theme", $config['theme'], $_POST['theme']);
146

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

    
158
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
159

    
160
		unset($config['system']['dnsallowoverride']);
161
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
162

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

    
181
		if ($changecount > 0)
182
			write_config($changedesc);
183

    
184
		if ($restart_webgui) {
185
			global $_SERVER;
186
			list($host) = explode(":", $_SERVER['HTTP_HOST']);
187
			if ($config['system']['webgui']['port']) {
188
				$url="{$config['system']['webgui']['protocol']}://{$host}:{$config['system']['webgui']['port']}/system.php";
189
			} else {
190
				$url = "{$config['system']['webgui']['protocol']}://{$host}/system.php";
191
			}
192
		}
193

    
194
		$retval = 0;
195
		config_lock();
196
		$retval = system_hostname_configure();
197
		$retval |= system_hosts_generate();
198
		$retval |= system_resolvconf_generate();
199
		$retval |= services_dnsmasq_configure();
200
		$retval |= system_timezone_configure();
201
		$retval |= system_ntp_configure();
202

    
203
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
204
			$retval |= interfaces_wan_configure();
205

    
206
		config_unlock();
207

    
208
		$savemsg = get_std_save_message($retval);
209
		if ($restart_webgui)
210
			$savemsg .= "<br />One moment...redirecting to {$url} in 10 seconds.";
211
	}
212
}
213

    
214
$pgtitle = array("System","General Setup");
215
include("head.inc");
216

    
217
?>
218

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