Project

General

Profile

Download (13.5 KB) Statistics
| Branch: | Tag: | Revision:
1 04ad7c7c Scott Ullrich
<?php
2 62d01225 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	system.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 04ad7c7c Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 04ad7c7c Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 04ad7c7c Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 04ad7c7c Scott Ullrich
16 5b237745 Scott Ullrich
	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 04ad7c7c Scott Ullrich
20 5b237745 Scott Ullrich
	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']) = $config['system']['dnsserver'];
37 0d8a219e Scott Ullrich
38 5b237745 Scott Ullrich
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
39
$pconfig['webguiproto'] = $config['system']['webgui']['protocol'];
40
if (!$pconfig['webguiproto'])
41
	$pconfig['webguiproto'] = "http";
42
$pconfig['webguiport'] = $config['system']['webgui']['port'];
43
$pconfig['timezone'] = $config['system']['timezone'];
44
$pconfig['timeupdateinterval'] = $config['system']['time-update-interval'];
45
$pconfig['timeservers'] = $config['system']['timeservers'];
46 f0f7a3eb Scott Ullrich
$pconfig['theme'] = $config['system']['theme'];
47 5b237745 Scott Ullrich
48
if (!isset($pconfig['timeupdateinterval']))
49
	$pconfig['timeupdateinterval'] = 300;
50
if (!$pconfig['timezone'])
51
	$pconfig['timezone'] = "Etc/UTC";
52
if (!$pconfig['timeservers'])
53
	$pconfig['timeservers'] = "pool.ntp.org";
54 04ad7c7c Scott Ullrich
55 417c6042 Bill Marquette
$changedesc = "System: ";
56 62d01225 Bill Marquette
$changecount = 0;
57 417c6042 Bill Marquette
58 5b237745 Scott Ullrich
function is_timezone($elt) {
59
	return !preg_match("/\/$/", $elt);
60
}
61
62 aa1ab1da Scott Ullrich
if($pconfig['timezone'] <> $_POST['timezone']) {
63
	/* restart firewall log dumper helper */
64
	require_once("functions.inc");
65 87c20eb5 Bill Marquette
	$pid = `ps awwwux | grep -v "grep" | grep "tcpdump -v -l -n -e -ttt -i pflog0"  | awk '{ print $2 }'`;
66 aa1ab1da Scott Ullrich
	if($pid) {
67
		mwexec("kill $pid");
68
		usleep(1000);
69
	}		
70
	filter_pflog_start();
71
}
72
73 5b237745 Scott Ullrich
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
74
$timezonelist = array_filter($timezonelist, 'is_timezone');
75
sort($timezonelist);
76
77
if ($_POST) {
78
79 c668c964 Scott Ullrich
	$changecount++;
80
81 5b237745 Scott Ullrich
	unset($input_errors);
82
	$pconfig = $_POST;
83
84
	/* input validation */
85 ec5a5d65 Scott Dale
	$reqdfields = split(" ", "hostname domain");
86
	$reqdfieldsn = split(",", "Hostname,Domain");
87 04ad7c7c Scott Ullrich
88 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
89 04ad7c7c Scott Ullrich
90 5b237745 Scott Ullrich
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
91
		$input_errors[] = "The hostname may only contain the characters a-z, 0-9 and '-'.";
92
	}
93
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
94
		$input_errors[] = "The domain may only contain the characters a-z, 0-9, '-' and '.'.";
95
	}
96
	if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) {
97
		$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS server.";
98
	}
99 04ad7c7c Scott Ullrich
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
100 5b237745 Scott Ullrich
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
101 709cc6e0 Bill Marquette
		$input_errors[] = "A valid TCP/IP port must be specified for the webConfigurator port.";
102 5b237745 Scott Ullrich
	}
103
	if (($_POST['password']) && ($_POST['password'] != $_POST['password2'])) {
104
		$input_errors[] = "The passwords do not match.";
105
	}
106 04ad7c7c Scott Ullrich
107 5b237745 Scott Ullrich
	$t = (int)$_POST['timeupdateinterval'];
108
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
109
		$input_errors[] = "The time update interval must be either 0 (disabled) or between 6 and 1440.";
110
	}
111
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
112
		if (!is_domain($ts)) {
113
			$input_errors[] = "A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.";
114
		}
115
	}
116
117
	if (!$input_errors) {
118 9eab73da Bill Marquette
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
119
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
120 79f8694f Bill Marquette
121 a6b0fbf7 Bill Marquette
		if (update_if_changed("webgui protocol", $config['system']['webgui']['protocol'], $_POST['webguiproto']))
122
			$restart_webgui = true;
123
		if (update_if_changed("webgui port", $config['system']['webgui']['port'], $_POST['webguiport']))
124 37d160c2 Bill Marquette
			$restart_webgui = true;
125
126 9eab73da Bill Marquette
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
127
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
128
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
129 04ad7c7c Scott Ullrich
130 f0f7a3eb Scott Ullrich
		/* pfSense themes */
131 20b90e0a Scott Ullrich
		update_if_changed("System Theme", $config['theme'], $_POST['theme']);
132 f0f7a3eb Scott Ullrich
133 4fbf63aa Bill Marquette
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
134 5b237745 Scott Ullrich
		unset($config['system']['dnsserver']);
135
		if ($_POST['dns1'])
136
			$config['system']['dnsserver'][] = $_POST['dns1'];
137
		if ($_POST['dns2'])
138
			$config['system']['dnsserver'][] = $_POST['dns2'];
139 04ad7c7c Scott Ullrich
140 07bd3f83 Scott Ullrich
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
141 20b90e0a Scott Ullrich
142 0d8a219e Scott Ullrich
		unset($config['system']['dnsallowoverride']);
143 5b237745 Scott Ullrich
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
144 2715fc52 Scott Ullrich
                if ($_POST['password']) {
145
                        $config['system']['password'] = crypt($_POST['password']);
146 62d489e7 Scott Ullrich
			update_changedesc("password changed via webConfigurator");
147 20b90e0a Scott Ullrich
			sync_webgui_passwords();
148 2715fc52 Scott Ullrich
                }
149 04ad7c7c Scott Ullrich
150 62d01225 Bill Marquette
		if ($changecount > 0)
151
			write_config($changedesc);
152 04ad7c7c Scott Ullrich
153 6485deb5 Bill Marquette
		if ($restart_webgui) {
154
			global $_SERVER;
155 a6b0fbf7 Bill Marquette
			list($host) = explode(":", $_SERVER['HTTP_HOST']);
156
			if ($config['system']['webgui']['port']) {
157
				$url="{$config['system']['webgui']['protocol']}://{$host}:{$config['system']['webgui']['port']}/system.php";
158 6485deb5 Bill Marquette
			} else {
159 a6b0fbf7 Bill Marquette
				$url = "{$config['system']['webgui']['protocol']}://{$host}/system.php";
160 6485deb5 Bill Marquette
			}
161
		}
162
163 5b237745 Scott Ullrich
		$retval = 0;
164 3cfdba5f Scott Ullrich
		config_lock();
165
		$retval = system_hostname_configure();
166
		$retval |= system_hosts_generate();
167
		$retval |= system_resolvconf_generate();
168
		$retval |= system_password_configure();
169
		$retval |= services_dnsmasq_configure();
170
		$retval |= system_timezone_configure();
171
		$retval |= system_ntp_configure();
172
173
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
174
			$retval |= interfaces_wan_configure();
175
176
		config_unlock();
177 04ad7c7c Scott Ullrich
178 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
179 6485deb5 Bill Marquette
		if ($restart_webgui)
180 991f7f37 Scott Ullrich
			$savemsg .= "<br />One moment...redirecting to {$url} in 10 seconds.";
181 5b237745 Scott Ullrich
	}
182
}
183 4df96eff Scott Ullrich
184
$pgtitle = "System: General Setup";
185
include("head.inc");
186
187 5b237745 Scott Ullrich
?>
188 4df96eff Scott Ullrich
189 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
190
<?php include("fbegin.inc"); ?>
191 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
192 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
193
<?php if ($savemsg) print_info_box($savemsg); ?>
194
<form action="system.php" method="post">
195
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
196 04ad7c7c Scott Ullrich
                <tr>
197 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Hostname</td>
198 b5c78501 Seth Mos
                  <td width="78%" class="vtable"> <input name="hostname" type="text" class="formfld unknown" id="hostname" size="40" value="<?=htmlspecialchars($pconfig['hostname']);?>">
199 04ad7c7c Scott Ullrich
                    <br> <span class="vexpl">name of the firewall host, without
200 5b237745 Scott Ullrich
                    domain part<br>
201
                    e.g. <em>firewall</em></span></td>
202
                </tr>
203 04ad7c7c Scott Ullrich
                <tr>
204 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Domain</td>
205 b5c78501 Seth Mos
                  <td width="78%" class="vtable"> <input name="domain" type="text" class="formfld unknown" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
206 5b237745 Scott Ullrich
                    <br> <span class="vexpl">e.g. <em>mycorp.com</em> </span></td>
207
                </tr>
208 04ad7c7c Scott Ullrich
                <tr>
209 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">DNS servers</td>
210 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <p>
211 b5c78501 Seth Mos
                      <input name="dns1" type="text" class="formfld unknown" id="dns1" size="20" value="<?=htmlspecialchars($pconfig['dns1']);?>">
212 5b237745 Scott Ullrich
                      <br>
213 b5c78501 Seth Mos
                      <input name="dns2" type="text" class="formfld unknown" id="dns22" size="20" value="<?=htmlspecialchars($pconfig['dns2']);?>">
214 5b237745 Scott Ullrich
                      <br>
215 04ad7c7c Scott Ullrich
                      <span class="vexpl">IP addresses; these are also used for
216 5b237745 Scott Ullrich
                      the DHCP service, DNS forwarder and for PPTP VPN clients<br>
217
                      <br>
218 07bd3f83 Scott Ullrich
                      <input name="dnsallowoverride" type="checkbox" id="dnsallowoverride" value="yes" <?php if ($pconfig['dnsallowoverride']) echo "checked"; ?>>
219 04ad7c7c Scott Ullrich
                      <strong>Allow DNS server list to be overridden by DHCP/PPP
220 5b237745 Scott Ullrich
                      on WAN</strong><br>
221 841dd38a Scott Ullrich
                      If this option is set, pfSense will use DNS servers assigned
222 04ad7c7c Scott Ullrich
                      by a DHCP/PPP server on WAN for its own purposes (including
223
                      the DNS forwarder). They will not be assigned to DHCP and
224 5b237745 Scott Ullrich
                      PPTP VPN clients, though.</span></p></td>
225
                </tr>
226 04ad7c7c Scott Ullrich
                <tr>
227 709cc6e0 Bill Marquette
                  <td width="22%" valign="top" class="vncell">webConfigurator protocol</td>
228 2ecd3a0d Colin Smith
                  <td width="78%" class="vtable"> <input name="webguiproto" type="radio" value="http" <?php if ($pconfig['webguiproto'] == "http") echo "checked"; ?>>
229
                    HTTP &nbsp;&nbsp;&nbsp; <input type="radio" name="webguiproto" value="https" <?php if ($pconfig['webguiproto'] == "https") echo "checked"; ?>>
230 5b237745 Scott Ullrich
                    HTTPS</td>
231
                </tr>
232 04ad7c7c Scott Ullrich
                <tr>
233 709cc6e0 Bill Marquette
                  <td valign="top" class="vncell">webConfigurator port</td>
234 b5c78501 Seth Mos
                  <td class="vtable"> <input name="webguiport" type="text" class="formfld unknown" id="webguiport" "size="5" value="<?=htmlspecialchars($config['system']['webgui']['port']);?>">
235 5b237745 Scott Ullrich
                    <br>
236 709cc6e0 Bill Marquette
                    <span class="vexpl">Enter a custom port number for the webConfigurator
237 04ad7c7c Scott Ullrich
                    above if you want to override the default (80 for HTTP, 443
238 63c2f169 Colin Smith
                    for HTTPS). Changes will take effect immediately after save.</span></td>
239 5b237745 Scott Ullrich
                </tr>
240 04ad7c7c Scott Ullrich
                <tr>
241 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Time zone</td>
242
                  <td width="78%" class="vtable"> <select name="timezone" id="timezone">
243
                      <?php foreach ($timezonelist as $value): ?>
244 04ad7c7c Scott Ullrich
                      <option value="<?=htmlspecialchars($value);?>" <?php if ($value == $pconfig['timezone']) echo "selected"; ?>>
245 5b237745 Scott Ullrich
                      <?=htmlspecialchars($value);?>
246
                      </option>
247
                      <?php endforeach; ?>
248 04ad7c7c Scott Ullrich
                    </select> <br> <span class="vexpl">Select the location closest
249 5b237745 Scott Ullrich
                    to you</span></td>
250
                </tr>
251 20b90e0a Scott Ullrich
                <!--
252 04ad7c7c Scott Ullrich
                <tr>
253 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Time update interval</td>
254 b5c78501 Seth Mos
                  <td width="78%" class="vtable"> <input name="timeupdateinterval" type="text" class="formfld unknown" id="timeupdateinterval" size="4" value="<?=htmlspecialchars($pconfig['timeupdateinterval']);?>">
255 04ad7c7c Scott Ullrich
                    <br> <span class="vexpl">Minutes between network time sync.;
256 5b237745 Scott Ullrich
                    300 recommended, or 0 to disable </span></td>
257
                </tr>
258 20b90e0a Scott Ullrich
                -->
259 04ad7c7c Scott Ullrich
                <tr>
260 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">NTP time server</td>
261 b5c78501 Seth Mos
                  <td width="78%" class="vtable"> <input name="timeservers" type="text" class="formfld unknown" id="timeservers" size="40" value="<?=htmlspecialchars($pconfig['timeservers']);?>">
262 04ad7c7c Scott Ullrich
                    <br> <span class="vexpl">Use a space to separate multiple
263
                    hosts (only one required). Remember to set up at least one
264 5b237745 Scott Ullrich
                    DNS server if you enter a host name here!</span></td>
265
                </tr>
266 f0f7a3eb Scott Ullrich
				<tr>
267
					<td colspan="2" class="list" height="12">&nbsp;</td>
268 20b90e0a Scott Ullrich
				</tr>
269 f0f7a3eb Scott Ullrich
				<tr>
270
					<td colspan="2" valign="top" class="listtopic">Theme</td>
271
				</tr>
272
				<tr>
273
				<td width="22%" valign="top" class="vncell">&nbsp;</td>
274
				<td width="78%" class="vtable">
275
				    <select name="theme">
276
<?php
277
				$files = return_dir_as_array("/usr/local/www/themes/");
278
				foreach($files as $f) {
279
					if ( (substr($f, 0, 1) == "_") && !isset($config['system']['developer']) ) continue;
280
					if($f == "CVS") continue;
281
					$selected = "";
282
					if($f == $config['theme'])
283
						$selected = " SELECTED";
284
					if($config['theme'] == "" and $f == "pfsense")
285
						$selceted = " SELECTED";
286
					echo "\t\t\t\t\t"."<option{$selected}>{$f}</option>\n";
287
				}
288
?>
289
					</select>
290
					<strong>This will change the look and feel of pfSense</strong>
291
				</td>
292 20b90e0a Scott Ullrich
				</tr>
293 f0f7a3eb Scott Ullrich
				<tr>
294 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
295 04ad7c7c Scott Ullrich
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
296 5b237745 Scott Ullrich
                  </td>
297
                </tr>
298
              </table>
299
</form>
300
<?php include("fend.inc"); ?>
301 cfa6fa1a Scott Ullrich
<?php
302
	// restart webgui if proto or port changed
303
	if ($restart_webgui) {
304 991f7f37 Scott Ullrich
		echo "<meta http-equiv=\"refresh\" content=\"10;url={$url}\">";
305 cfa6fa1a Scott Ullrich
	}
306 2f3f316c Scott Ullrich
?>
307
</body>
308
</html>
309
<?php
310 70b5a4e1 Scott Ullrich
if ($restart_webgui) {
311
	touch("/tmp/restart_webgui");
312
}
313 b5c78501 Seth Mos
?>