Project

General

Profile

Download (13.5 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
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
39
$pconfig['username'] = $config['system']['username'];
40
if (!$pconfig['username'])
41
	$pconfig['username'] = "admin";
42
$pconfig['webguiproto'] = $config['system']['webgui']['protocol'];
43
if (!$pconfig['webguiproto'])
44
	$pconfig['webguiproto'] = "http";
45
$pconfig['webguiport'] = $config['system']['webgui']['port'];
46
$pconfig['timezone'] = $config['system']['timezone'];
47
$pconfig['timeupdateinterval'] = $config['system']['time-update-interval'];
48
$pconfig['timeservers'] = $config['system']['timeservers'];
49
50
if (!isset($pconfig['timeupdateinterval']))
51
	$pconfig['timeupdateinterval'] = 300;
52
if (!$pconfig['timezone'])
53
	$pconfig['timezone'] = "Etc/UTC";
54
if (!$pconfig['timeservers'])
55
	$pconfig['timeservers'] = "pool.ntp.org";
56 04ad7c7c Scott Ullrich
57 417c6042 Bill Marquette
$changedesc = "System: ";
58 62d01225 Bill Marquette
$changecount = 0;
59 417c6042 Bill Marquette
60 5b237745 Scott Ullrich
function is_timezone($elt) {
61
	return !preg_match("/\/$/", $elt);
62
}
63
64
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
65
$timezonelist = array_filter($timezonelist, 'is_timezone');
66
sort($timezonelist);
67
68
if ($_POST) {
69
70
	unset($input_errors);
71
	$pconfig = $_POST;
72
73
	/* input validation */
74
	$reqdfields = split(" ", "hostname domain username");
75
	$reqdfieldsn = split(",", "Hostname,Domain,Username");
76 04ad7c7c Scott Ullrich
77 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
78 04ad7c7c Scott Ullrich
79 5b237745 Scott Ullrich
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
80
		$input_errors[] = "The hostname may only contain the characters a-z, 0-9 and '-'.";
81
	}
82
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
83
		$input_errors[] = "The domain may only contain the characters a-z, 0-9, '-' and '.'.";
84
	}
85
	if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) {
86
		$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS server.";
87
	}
88
	if ($_POST['username'] && !preg_match("/^[a-zA-Z0-9]*$/", $_POST['username'])) {
89
		$input_errors[] = "The username may only contain the characters a-z, A-Z and 0-9.";
90
	}
91 04ad7c7c Scott Ullrich
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
92 5b237745 Scott Ullrich
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
93
		$input_errors[] = "A valid TCP/IP port must be specified for the webGUI port.";
94
	}
95
	if (($_POST['password']) && ($_POST['password'] != $_POST['password2'])) {
96
		$input_errors[] = "The passwords do not match.";
97
	}
98 04ad7c7c Scott Ullrich
99 5b237745 Scott Ullrich
	$t = (int)$_POST['timeupdateinterval'];
100
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
101
		$input_errors[] = "The time update interval must be either 0 (disabled) or between 6 and 1440.";
102
	}
103
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
104
		if (!is_domain($ts)) {
105
			$input_errors[] = "A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.";
106
		}
107
	}
108
109
	if (!$input_errors) {
110 79f8694f Bill Marquette
		update_if_changed("hostname", &$config['system']['hostname'], strtolower($_POST['hostname']));
111
		update_if_changed("domain", &$config['system']['domain'], strtolower($_POST['domain']));
112
		update_if_changed("username", &$config['system']['username'], $_POST['username']);
113
114
		$restart_webgui = update_if_changed("webgui protocol", &$config['system']['webgui']['protocol'], $pconfig['webguiproto']);
115
		$restart_webgui = update_if_changed("webgui port", &$config['system']['webgui']['port'], $pconfig['webguiport']);
116
		update_if_changed("timezone", &$config['system']['timezone'], $_POST['timezone']);
117
		update_if_changed("NTP servers", &$config['system']['timeservers'], strtolower($_POST['timeservers']));
118
		update_if_changed("NTP update interval", &$config['system']['time-update-interval'], $_POST['timeupdateinterval']);
119 04ad7c7c Scott Ullrich
120 4fbf63aa Bill Marquette
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
121 5b237745 Scott Ullrich
		unset($config['system']['dnsserver']);
122
		if ($_POST['dns1'])
123
			$config['system']['dnsserver'][] = $_POST['dns1'];
124
		if ($_POST['dns2'])
125
			$config['system']['dnsserver'][] = $_POST['dns2'];
126 04ad7c7c Scott Ullrich
127 07bd3f83 Scott Ullrich
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
128 5b237745 Scott Ullrich
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
129 04ad7c7c Scott Ullrich
130 5b237745 Scott Ullrich
		if ($_POST['password']) {
131
			$config['system']['password'] = crypt($_POST['password']);
132 04ad7c7c Scott Ullrich
			$fd = popen("/usr/sbin/pw usermod -n root -H 0", "w");
133
			$salt = md5(time());
134
			$crypted_pw = crypt($_POST['password'],$salt);
135
			fwrite($fd, $crypted_pw);
136
			pclose($fd);
137 62d01225 Bill Marquette
			update_changedesc("password changed");
138 5b237745 Scott Ullrich
		}
139 04ad7c7c Scott Ullrich
140 62d01225 Bill Marquette
		if ($changecount > 0)
141
			write_config($changedesc);
142 04ad7c7c Scott Ullrich
143 390c2739 Bill Marquette
		// restart webgui if proto or port changed
144 4fbf63aa Bill Marquette
		if ($restart_webgui) {
145 390c2739 Bill Marquette
			global $_SERVER;
146 8e8f7ff7 Bill Marquette
			system_webgui_start();
147 ce62fee7 Bill Marquette
			if ($pconfig['webguiport'])
148
				header("Location: {$pconfig['webguiproto']}://{$_SERVER['SERVER_NAME']}:{$pconfig['webguiport']}/system.php");
149
			else
150
				header("Location: {$pconfig['webguiproto']}://{$_SERVER['SERVER_NAME']}/system.php");
151 390c2739 Bill Marquette
		}
152 04ad7c7c Scott Ullrich
153 5b237745 Scott Ullrich
		$retval = 0;
154
		if (!file_exists($d_sysrebootreqd_path)) {
155
			config_lock();
156
			$retval = system_hostname_configure();
157
			$retval |= system_hosts_generate();
158
			$retval |= system_resolvconf_generate();
159
			$retval |= system_password_configure();
160
			$retval |= services_dnsmasq_configure();
161
			$retval |= system_timezone_configure();
162
 			$retval |= system_ntp_configure();
163 04ad7c7c Scott Ullrich
164 07bd3f83 Scott Ullrich
 			if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
165
 				$retval |= interfaces_wan_configure();
166 04ad7c7c Scott Ullrich
167 5b237745 Scott Ullrich
			config_unlock();
168
		}
169 04ad7c7c Scott Ullrich
170 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
171
	}
172
}
173
?>
174
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
175
<html>
176
<head>
177
<title><?=gentitle("System: General setup");?></title>
178
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
179
<link href="gui.css" rel="stylesheet" type="text/css">
180
</head>
181
182
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
183
<?php include("fbegin.inc"); ?>
184
      <p class="pgtitle">System: General setup</p>
185
<?php if ($input_errors) print_input_errors($input_errors); ?>
186
<?php if ($savemsg) print_info_box($savemsg); ?>
187
<form action="system.php" method="post">
188
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
189 04ad7c7c Scott Ullrich
                <tr>
190 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Hostname</td>
191 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <input name="hostname" type="text" class="formfld" id="hostname" size="40" value="<?=htmlspecialchars($pconfig['hostname']);?>">
192
                    <br> <span class="vexpl">name of the firewall host, without
193 5b237745 Scott Ullrich
                    domain part<br>
194
                    e.g. <em>firewall</em></span></td>
195
                </tr>
196 04ad7c7c Scott Ullrich
                <tr>
197 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Domain</td>
198 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
199 5b237745 Scott Ullrich
                    <br> <span class="vexpl">e.g. <em>mycorp.com</em> </span></td>
200
                </tr>
201 04ad7c7c Scott Ullrich
                <tr>
202 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">DNS servers</td>
203 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <p>
204 5b237745 Scott Ullrich
                      <input name="dns1" type="text" class="formfld" id="dns1" size="20" value="<?=htmlspecialchars($pconfig['dns1']);?>">
205
                      <br>
206
                      <input name="dns2" type="text" class="formfld" id="dns22" size="20" value="<?=htmlspecialchars($pconfig['dns2']);?>">
207
                      <br>
208 04ad7c7c Scott Ullrich
                      <span class="vexpl">IP addresses; these are also used for
209 5b237745 Scott Ullrich
                      the DHCP service, DNS forwarder and for PPTP VPN clients<br>
210
                      <br>
211 07bd3f83 Scott Ullrich
                      <input name="dnsallowoverride" type="checkbox" id="dnsallowoverride" value="yes" <?php if ($pconfig['dnsallowoverride']) echo "checked"; ?>>
212 04ad7c7c Scott Ullrich
                      <strong>Allow DNS server list to be overridden by DHCP/PPP
213 5b237745 Scott Ullrich
                      on WAN</strong><br>
214 841dd38a Scott Ullrich
                      If this option is set, pfSense will use DNS servers assigned
215 04ad7c7c Scott Ullrich
                      by a DHCP/PPP server on WAN for its own purposes (including
216
                      the DNS forwarder). They will not be assigned to DHCP and
217 5b237745 Scott Ullrich
                      PPTP VPN clients, though.</span></p></td>
218
                </tr>
219 04ad7c7c Scott Ullrich
                <tr>
220 5b237745 Scott Ullrich
                  <td valign="top" class="vncell">Username</td>
221
                  <td class="vtable"> <input name="username" type="text" class="formfld" id="username" size="20" value="<?=$pconfig['username'];?>">
222
                    <br>
223 04ad7c7c Scott Ullrich
                     <span class="vexpl">If you want
224
                    to change the username for accessing the webGUI, enter it
225 5b237745 Scott Ullrich
                    here.</span></td>
226
                </tr>
227 04ad7c7c Scott Ullrich
                <tr>
228 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Password</td>
229 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <input name="password" type="password" class="formfld" id="password" size="20">
230
                    <br> <input name="password2" type="password" class="formfld" id="password2" size="20">
231
                    &nbsp;(confirmation) <br> <span class="vexpl">If you want
232
                    to change the password for accessing the webGUI, enter it
233 5b237745 Scott Ullrich
                    here twice.</span></td>
234
                </tr>
235 04ad7c7c Scott Ullrich
                <tr>
236 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">webGUI protocol</td>
237 2ecd3a0d Colin Smith
                  <td width="78%" class="vtable"> <input name="webguiproto" type="radio" value="http" <?php if ($pconfig['webguiproto'] == "http") echo "checked"; ?>>
238
                    HTTP &nbsp;&nbsp;&nbsp; <input type="radio" name="webguiproto" value="https" <?php if ($pconfig['webguiproto'] == "https") echo "checked"; ?>>
239 5b237745 Scott Ullrich
                    HTTPS</td>
240
                </tr>
241 04ad7c7c Scott Ullrich
                <tr>
242 5b237745 Scott Ullrich
                  <td valign="top" class="vncell">webGUI port</td>
243 ce62fee7 Bill Marquette
                  <td class="vtable"> <input name="webguiport" type="text" class="formfld" id="webguiport" onchange="'webGUI port changes will take effect immediately after clicking save') "size="5" value="<?=htmlspecialchars($pconfig['webguiport']);?>">
244 5b237745 Scott Ullrich
                    <br>
245 04ad7c7c Scott Ullrich
                    <span class="vexpl">Enter a custom port number for the webGUI
246
                    above if you want to override the default (80 for HTTP, 443
247 5b237745 Scott Ullrich
                    for HTTPS).</span></td>
248
                </tr>
249 04ad7c7c Scott Ullrich
                <tr>
250 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Time zone</td>
251
                  <td width="78%" class="vtable"> <select name="timezone" id="timezone">
252
                      <?php foreach ($timezonelist as $value): ?>
253 04ad7c7c Scott Ullrich
                      <option value="<?=htmlspecialchars($value);?>" <?php if ($value == $pconfig['timezone']) echo "selected"; ?>>
254 5b237745 Scott Ullrich
                      <?=htmlspecialchars($value);?>
255
                      </option>
256
                      <?php endforeach; ?>
257 04ad7c7c Scott Ullrich
                    </select> <br> <span class="vexpl">Select the location closest
258 5b237745 Scott Ullrich
                    to you</span></td>
259
                </tr>
260 04ad7c7c Scott Ullrich
                <tr>
261 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Time update interval</td>
262 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <input name="timeupdateinterval" type="text" class="formfld" id="timeupdateinterval" size="4" value="<?=htmlspecialchars($pconfig['timeupdateinterval']);?>">
263
                    <br> <span class="vexpl">Minutes between network time sync.;
264 5b237745 Scott Ullrich
                    300 recommended, or 0 to disable </span></td>
265
                </tr>
266 04ad7c7c Scott Ullrich
                <tr>
267 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">NTP time server</td>
268 04ad7c7c Scott Ullrich
                  <td width="78%" class="vtable"> <input name="timeservers" type="text" class="formfld" id="timeservers" size="40" value="<?=htmlspecialchars($pconfig['timeservers']);?>">
269
                    <br> <span class="vexpl">Use a space to separate multiple
270
                    hosts (only one required). Remember to set up at least one
271 5b237745 Scott Ullrich
                    DNS server if you enter a host name here!</span></td>
272
                </tr>
273 04ad7c7c Scott Ullrich
                <tr>
274 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
275 04ad7c7c Scott Ullrich
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
276 5b237745 Scott Ullrich
                  </td>
277
                </tr>
278
              </table>
279
</form>
280
<?php include("fend.inc"); ?>
281
</body>
282
</html>