Project

General

Profile

Download (13.3 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 04ad7c7c Scott Ullrich
<?php
3 62d01225 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5
	system.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7 04ad7c7c Scott Ullrich
8 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10 04ad7c7c Scott Ullrich
11 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13 04ad7c7c Scott Ullrich
14 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16 04ad7c7c Scott Ullrich
17 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20 04ad7c7c Scott Ullrich
21 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
33
require("guiconfig.inc");
34
35
$pconfig['hostname'] = $config['system']['hostname'];
36
$pconfig['domain'] = $config['system']['domain'];
37
list($pconfig['dns1'],$pconfig['dns2']) = $config['system']['dnsserver'];
38 0d8a219e Scott Ullrich
39 5b237745 Scott Ullrich
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
40
$pconfig['username'] = $config['system']['username'];
41
if (!$pconfig['username'])
42
	$pconfig['username'] = "admin";
43
$pconfig['webguiproto'] = $config['system']['webgui']['protocol'];
44
if (!$pconfig['webguiproto'])
45
	$pconfig['webguiproto'] = "http";
46
$pconfig['webguiport'] = $config['system']['webgui']['port'];
47
$pconfig['timezone'] = $config['system']['timezone'];
48
$pconfig['timeupdateinterval'] = $config['system']['time-update-interval'];
49
$pconfig['timeservers'] = $config['system']['timeservers'];
50
51
if (!isset($pconfig['timeupdateinterval']))
52
	$pconfig['timeupdateinterval'] = 300;
53
if (!$pconfig['timezone'])
54
	$pconfig['timezone'] = "Etc/UTC";
55
if (!$pconfig['timeservers'])
56
	$pconfig['timeservers'] = "pool.ntp.org";
57 04ad7c7c Scott Ullrich
58 417c6042 Bill Marquette
$changedesc = "System: ";
59 62d01225 Bill Marquette
$changecount = 0;
60 417c6042 Bill Marquette
61 5b237745 Scott Ullrich
function is_timezone($elt) {
62
	return !preg_match("/\/$/", $elt);
63
}
64
65
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
66
$timezonelist = array_filter($timezonelist, 'is_timezone');
67
sort($timezonelist);
68
69
if ($_POST) {
70
71 c668c964 Scott Ullrich
	$changecount++;
72
73 5b237745 Scott Ullrich
	unset($input_errors);
74
	$pconfig = $_POST;
75
76
	/* input validation */
77
	$reqdfields = split(" ", "hostname domain username");
78
	$reqdfieldsn = split(",", "Hostname,Domain,Username");
79 04ad7c7c Scott Ullrich
80 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
81 04ad7c7c Scott Ullrich
82 5b237745 Scott Ullrich
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
83
		$input_errors[] = "The hostname may only contain the characters a-z, 0-9 and '-'.";
84
	}
85
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
86
		$input_errors[] = "The domain may only contain the characters a-z, 0-9, '-' and '.'.";
87
	}
88
	if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) {
89
		$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS server.";
90
	}
91
	if ($_POST['username'] && !preg_match("/^[a-zA-Z0-9]*$/", $_POST['username'])) {
92
		$input_errors[] = "The username may only contain the characters a-z, A-Z and 0-9.";
93
	}
94 04ad7c7c Scott Ullrich
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
95 5b237745 Scott Ullrich
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
96
		$input_errors[] = "A valid TCP/IP port must be specified for the webGUI port.";
97
	}
98
	if (($_POST['password']) && ($_POST['password'] != $_POST['password2'])) {
99
		$input_errors[] = "The passwords do not match.";
100
	}
101 04ad7c7c Scott Ullrich
102 5b237745 Scott Ullrich
	$t = (int)$_POST['timeupdateinterval'];
103
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
104
		$input_errors[] = "The time update interval must be either 0 (disabled) or between 6 and 1440.";
105
	}
106
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
107
		if (!is_domain($ts)) {
108
			$input_errors[] = "A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.";
109
		}
110
	}
111
112
	if (!$input_errors) {
113 9eab73da Bill Marquette
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
114
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
115
		update_if_changed("username", $config['system']['username'], $_POST['username']);
116 79f8694f Bill Marquette
117 9eab73da Bill Marquette
		if (update_if_changed("webgui protocol", $config['system']['webgui']['protocol'], $pconfig['webguiproto'])  || update_if_changed("webgui port", $config['system']['webgui']['port'], $pconfig['webguiport']))
118 37d160c2 Bill Marquette
			$restart_webgui = true;
119
120 9eab73da Bill Marquette
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
121
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
122
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
123 04ad7c7c Scott Ullrich
124 4fbf63aa Bill Marquette
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
125 5b237745 Scott Ullrich
		unset($config['system']['dnsserver']);
126
		if ($_POST['dns1'])
127
			$config['system']['dnsserver'][] = $_POST['dns1'];
128
		if ($_POST['dns2'])
129
			$config['system']['dnsserver'][] = $_POST['dns2'];
130 04ad7c7c Scott Ullrich
131 07bd3f83 Scott Ullrich
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
132 0d8a219e Scott Ullrich
		
133
		unset($config['system']['dnsallowoverride']);
134 5b237745 Scott Ullrich
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
135 04ad7c7c Scott Ullrich
136 5b237745 Scott Ullrich
		if ($_POST['password']) {
137
			$config['system']['password'] = crypt($_POST['password']);
138 04ad7c7c Scott Ullrich
			$fd = popen("/usr/sbin/pw usermod -n root -H 0", "w");
139
			$salt = md5(time());
140
			$crypted_pw = crypt($_POST['password'],$salt);
141
			fwrite($fd, $crypted_pw);
142
			pclose($fd);
143 62d01225 Bill Marquette
			update_changedesc("password changed");
144 5b237745 Scott Ullrich
		}
145 04ad7c7c Scott Ullrich
146 62d01225 Bill Marquette
		if ($changecount > 0)
147
			write_config($changedesc);
148 04ad7c7c Scott Ullrich
149 390c2739 Bill Marquette
		// restart webgui if proto or port changed
150 4fbf63aa Bill Marquette
		if ($restart_webgui) {
151 390c2739 Bill Marquette
			global $_SERVER;
152 8e8f7ff7 Bill Marquette
			system_webgui_start();
153 ce62fee7 Bill Marquette
			if ($pconfig['webguiport'])
154
				header("Location: {$pconfig['webguiproto']}://{$_SERVER['SERVER_NAME']}:{$pconfig['webguiport']}/system.php");
155
			else
156
				header("Location: {$pconfig['webguiproto']}://{$_SERVER['SERVER_NAME']}/system.php");
157 390c2739 Bill Marquette
		}
158 04ad7c7c Scott Ullrich
159 5b237745 Scott Ullrich
		$retval = 0;
160
		if (!file_exists($d_sysrebootreqd_path)) {
161
			config_lock();
162
			$retval = system_hostname_configure();
163
			$retval |= system_hosts_generate();
164
			$retval |= system_resolvconf_generate();
165
			$retval |= system_password_configure();
166
			$retval |= services_dnsmasq_configure();
167
			$retval |= system_timezone_configure();
168
 			$retval |= system_ntp_configure();
169 04ad7c7c Scott Ullrich
170 07bd3f83 Scott Ullrich
 			if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
171
 				$retval |= interfaces_wan_configure();
172 04ad7c7c Scott Ullrich
173 5b237745 Scott Ullrich
			config_unlock();
174
		}
175 04ad7c7c Scott Ullrich
176 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
177
	}
178
}
179 4df96eff Scott Ullrich
180
$pgtitle = "System: General Setup";
181
include("head.inc");
182
183 5b237745 Scott Ullrich
?>
184 4df96eff Scott Ullrich
185 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
186
<?php include("fbegin.inc"); ?>
187 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
188 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
189
<?php if ($savemsg) print_info_box($savemsg); ?>
190
<form action="system.php" method="post">
191
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
192 04ad7c7c Scott Ullrich
                <tr>
193 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Hostname</td>
194 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <input name="hostname" type="text" class="formfld" id="hostname" size="40" value="<?=htmlspecialchars($pconfig['hostname']);?>">
195
                    <br> <span class="vexpl">name of the firewall host, without
196 5b237745 Scott Ullrich
                    domain part<br>
197
                    e.g. <em>firewall</em></span></td>
198
                </tr>
199 04ad7c7c Scott Ullrich
                <tr>
200 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Domain</td>
201 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
202 5b237745 Scott Ullrich
                    <br> <span class="vexpl">e.g. <em>mycorp.com</em> </span></td>
203
                </tr>
204 04ad7c7c Scott Ullrich
                <tr>
205 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">DNS servers</td>
206 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <p>
207 5b237745 Scott Ullrich
                      <input name="dns1" type="text" class="formfld" id="dns1" size="20" value="<?=htmlspecialchars($pconfig['dns1']);?>">
208
                      <br>
209
                      <input name="dns2" type="text" class="formfld" id="dns22" size="20" value="<?=htmlspecialchars($pconfig['dns2']);?>">
210
                      <br>
211 04ad7c7c Scott Ullrich
                      <span class="vexpl">IP addresses; these are also used for
212 5b237745 Scott Ullrich
                      the DHCP service, DNS forwarder and for PPTP VPN clients<br>
213
                      <br>
214 07bd3f83 Scott Ullrich
                      <input name="dnsallowoverride" type="checkbox" id="dnsallowoverride" value="yes" <?php if ($pconfig['dnsallowoverride']) echo "checked"; ?>>
215 04ad7c7c Scott Ullrich
                      <strong>Allow DNS server list to be overridden by DHCP/PPP
216 5b237745 Scott Ullrich
                      on WAN</strong><br>
217 841dd38a Scott Ullrich
                      If this option is set, pfSense will use DNS servers assigned
218 04ad7c7c Scott Ullrich
                      by a DHCP/PPP server on WAN for its own purposes (including
219
                      the DNS forwarder). They will not be assigned to DHCP and
220 5b237745 Scott Ullrich
                      PPTP VPN clients, though.</span></p></td>
221
                </tr>
222 04ad7c7c Scott Ullrich
                <tr>
223 5b237745 Scott Ullrich
                  <td valign="top" class="vncell">Username</td>
224
                  <td class="vtable"> <input name="username" type="text" class="formfld" id="username" size="20" value="<?=$pconfig['username'];?>">
225
                    <br>
226 04ad7c7c Scott Ullrich
                     <span class="vexpl">If you want
227
                    to change the username for accessing the webGUI, enter it
228 5b237745 Scott Ullrich
                    here.</span></td>
229
                </tr>
230 04ad7c7c Scott Ullrich
                <tr>
231 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Password</td>
232 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <input name="password" type="password" class="formfld" id="password" size="20">
233
                    <br> <input name="password2" type="password" class="formfld" id="password2" size="20">
234
                    &nbsp;(confirmation) <br> <span class="vexpl">If you want
235
                    to change the password for accessing the webGUI, enter it
236 5b237745 Scott Ullrich
                    here twice.</span></td>
237
                </tr>
238 04ad7c7c Scott Ullrich
                <tr>
239 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">webGUI protocol</td>
240 2ecd3a0d Colin Smith
                  <td width="78%" class="vtable"> <input name="webguiproto" type="radio" value="http" <?php if ($pconfig['webguiproto'] == "http") echo "checked"; ?>>
241
                    HTTP &nbsp;&nbsp;&nbsp; <input type="radio" name="webguiproto" value="https" <?php if ($pconfig['webguiproto'] == "https") echo "checked"; ?>>
242 5b237745 Scott Ullrich
                    HTTPS</td>
243
                </tr>
244 04ad7c7c Scott Ullrich
                <tr>
245 5b237745 Scott Ullrich
                  <td valign="top" class="vncell">webGUI port</td>
246 63c2f169 Colin Smith
                  <td class="vtable"> <input name="webguiport" type="text" class="formfld" id="webguiport" "size="5" value="<?=htmlspecialchars($pconfig['webguiport']);?>">
247 5b237745 Scott Ullrich
                    <br>
248 04ad7c7c Scott Ullrich
                    <span class="vexpl">Enter a custom port number for the webGUI
249
                    above if you want to override the default (80 for HTTP, 443
250 63c2f169 Colin Smith
                    for HTTPS). Changes will take effect immediately after save.</span></td>
251 5b237745 Scott Ullrich
                </tr>
252 04ad7c7c Scott Ullrich
                <tr>
253 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Time zone</td>
254
                  <td width="78%" class="vtable"> <select name="timezone" id="timezone">
255
                      <?php foreach ($timezonelist as $value): ?>
256 04ad7c7c Scott Ullrich
                      <option value="<?=htmlspecialchars($value);?>" <?php if ($value == $pconfig['timezone']) echo "selected"; ?>>
257 5b237745 Scott Ullrich
                      <?=htmlspecialchars($value);?>
258
                      </option>
259
                      <?php endforeach; ?>
260 04ad7c7c Scott Ullrich
                    </select> <br> <span class="vexpl">Select the location closest
261 5b237745 Scott Ullrich
                    to you</span></td>
262
                </tr>
263 04ad7c7c Scott Ullrich
                <tr>
264 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Time update interval</td>
265 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <input name="timeupdateinterval" type="text" class="formfld" id="timeupdateinterval" size="4" value="<?=htmlspecialchars($pconfig['timeupdateinterval']);?>">
266
                    <br> <span class="vexpl">Minutes between network time sync.;
267 5b237745 Scott Ullrich
                    300 recommended, or 0 to disable </span></td>
268
                </tr>
269 04ad7c7c Scott Ullrich
                <tr>
270 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">NTP time server</td>
271 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <input name="timeservers" type="text" class="formfld" id="timeservers" size="40" value="<?=htmlspecialchars($pconfig['timeservers']);?>">
272
                    <br> <span class="vexpl">Use a space to separate multiple
273
                    hosts (only one required). Remember to set up at least one
274 5b237745 Scott Ullrich
                    DNS server if you enter a host name here!</span></td>
275
                </tr>
276 04ad7c7c Scott Ullrich
                <tr>
277 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
278 04ad7c7c Scott Ullrich
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
279 5b237745 Scott Ullrich
                  </td>
280
                </tr>
281
              </table>
282
</form>
283
<?php include("fend.inc"); ?>
284
</body>
285
</html>