Project

General

Profile

Download (16.3 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
require("guiconfig.inc");
33

    
34
$pconfig['hostname'] = $config['system']['hostname'];
35
$pconfig['domain'] = $config['system']['domain'];
36
list($pconfig['dns1'],$pconfig['dns2'],$pconfig['dns3'],$pconfig['dns4']) = $config['system']['dnsserver'];
37

    
38

    
39
$pconfig['dns1gwint'] = $config['system']['dns1gwint'];
40
$pconfig['dns2gwint'] = $config['system']['dns2gwint'];
41
$pconfig['dns3gwint'] = $config['system']['dns3gwint'];
42
$pconfig['dns4gwint'] = $config['system']['dns4gwint'];
43

    
44
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
45
$pconfig['webguiproto'] = $config['system']['webgui']['protocol'];
46
if (!$pconfig['webguiproto'])
47
	$pconfig['webguiproto'] = "http";
48
$pconfig['webguiport'] = $config['system']['webgui']['port'];
49
$pconfig['timezone'] = $config['system']['timezone'];
50
$pconfig['timeupdateinterval'] = $config['system']['time-update-interval'];
51
$pconfig['timeservers'] = $config['system']['timeservers'];
52
$pconfig['theme'] = $config['system']['theme'];
53

    
54
if (!isset($pconfig['timeupdateinterval']))
55
	$pconfig['timeupdateinterval'] = 300;
56
if (!$pconfig['timezone'])
57
	$pconfig['timezone'] = "Etc/UTC";
58
if (!$pconfig['timeservers'])
59
	$pconfig['timeservers'] = "pool.ntp.org";
60

    
61
$changedesc = "System: ";
62
$changecount = 0;
63

    
64
function is_timezone($elt) {
65
	return !preg_match("/\/$/", $elt);
66
}
67

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

    
79
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
80
$timezonelist = array_filter($timezonelist, 'is_timezone');
81
sort($timezonelist);
82

    
83
if ($_POST) {
84

    
85
	$changecount++;
86
	
87
	unset($input_errors);
88
	$pconfig = $_POST;
89

    
90
	/* input validation */
91
	$reqdfields = split(" ", "hostname domain");
92
	$reqdfieldsn = split(",", "Hostname,Domain");
93

    
94
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
95

    
96
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
97
		$input_errors[] = "The hostname may only contain the characters a-z, 0-9 and '-'.";
98
	}
99
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
100
		$input_errors[] = "The domain may only contain the characters a-z, 0-9, '-' and '.'.";
101
	}
102
	if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) {
103
		$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS server.";
104
	}
105
	if (($_POST['dns3'] && !is_ipaddr($_POST['dns3'])) || ($_POST['dns4'] && !is_ipaddr($_POST['dns4']))) {
106
		$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS server.";
107
	}	
108
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
109
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
110
		$input_errors[] = "A valid TCP/IP port must be specified for the webConfigurator port.";
111
	}
112
	if (($_POST['password']) && ($_POST['password'] != $_POST['password2'])) {
113
		$input_errors[] = "The passwords do not match.";
114
	}
115

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

    
126
	if (!$input_errors) {
127
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
128
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
129

    
130
		if (update_if_changed("webgui protocol", $config['system']['webgui']['protocol'], $_POST['webguiproto']))
131
			$restart_webgui = true;
132
		if (update_if_changed("webgui port", $config['system']['webgui']['port'], $_POST['webguiport']))
133
			$restart_webgui = true;
134

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

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

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

    
153
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
154

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

    
158
		if ($_POST['password']) {
159
			$config['system']['password'] = crypt($_POST['password']);
160
			update_changedesc("password changed via webConfigurator");
161
			sync_webgui_passwords();
162
		}
163

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

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

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

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

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

    
208
		config_unlock();
209

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

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

    
219
?>
220

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