Project

General

Profile

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