Project

General

Profile

Download (13.4 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	system.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7

    
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16

    
17
	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

    
21
	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

    
57
$changedesc = "System: ";
58
$changecount = 0;
59

    
60
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

    
77
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
78

    
79
	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
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
92
			($_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

    
99
	$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
		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
		if (update_if_changed("webgui protocol", $config['system']['webgui']['protocol'], $pconfig['webguiproto'])  || update_if_changed("webgui port", $config['system']['webgui']['port'], $pconfig['webguiport']))
115
			$restart_webgui = true;
116

    
117
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
118
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
119
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
120

    
121
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
122
		unset($config['system']['dnsserver']);
123
		if ($_POST['dns1'])
124
			$config['system']['dnsserver'][] = $_POST['dns1'];
125
		if ($_POST['dns2'])
126
			$config['system']['dnsserver'][] = $_POST['dns2'];
127

    
128
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
129
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
130

    
131
		if ($_POST['password']) {
132
			$config['system']['password'] = crypt($_POST['password']);
133
			$fd = popen("/usr/sbin/pw usermod -n root -H 0", "w");
134
			$salt = md5(time());
135
			$crypted_pw = crypt($_POST['password'],$salt);
136
			fwrite($fd, $crypted_pw);
137
			pclose($fd);
138
			update_changedesc("password changed");
139
		}
140

    
141
		if ($changecount > 0)
142
			write_config($changedesc);
143

    
144
		// restart webgui if proto or port changed
145
		if ($restart_webgui) {
146
			global $_SERVER;
147
			system_webgui_start();
148
			if ($pconfig['webguiport'])
149
				header("Location: {$pconfig['webguiproto']}://{$_SERVER['SERVER_NAME']}:{$pconfig['webguiport']}/system.php");
150
			else
151
				header("Location: {$pconfig['webguiproto']}://{$_SERVER['SERVER_NAME']}/system.php");
152
		}
153

    
154
		$retval = 0;
155
		if (!file_exists($d_sysrebootreqd_path)) {
156
			config_lock();
157
			$retval = system_hostname_configure();
158
			$retval |= system_hosts_generate();
159
			$retval |= system_resolvconf_generate();
160
			$retval |= system_password_configure();
161
			$retval |= services_dnsmasq_configure();
162
			$retval |= system_timezone_configure();
163
 			$retval |= system_ntp_configure();
164

    
165
 			if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
166
 				$retval |= interfaces_wan_configure();
167

    
168
			config_unlock();
169
		}
170

    
171
		$savemsg = get_std_save_message($retval);
172
	}
173
}
174
?>
175
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
176
<html>
177
<head>
178
<title><?=gentitle("System: General setup");?></title>
179
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
180
<link href="gui.css" rel="stylesheet" type="text/css">
181
</head>
182

    
183
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
184
<?php include("fbegin.inc"); ?>
185
      <p class="pgtitle">System: General setup</p>
186
<?php if ($input_errors) print_input_errors($input_errors); ?>
187
<?php if ($savemsg) print_info_box($savemsg); ?>
188
<form action="system.php" method="post">
189
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
190
                <tr>
191
                  <td width="22%" valign="top" class="vncellreq">Hostname</td>
192
                  <td width="78%" class="vtable"> <input name="hostname" type="text" class="formfld" id="hostname" size="40" value="<?=htmlspecialchars($pconfig['hostname']);?>">
193
                    <br> <span class="vexpl">name of the firewall host, without
194
                    domain part<br>
195
                    e.g. <em>firewall</em></span></td>
196
                </tr>
197
                <tr>
198
                  <td width="22%" valign="top" class="vncellreq">Domain</td>
199
                  <td width="78%" class="vtable"> <input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
200
                    <br> <span class="vexpl">e.g. <em>mycorp.com</em> </span></td>
201
                </tr>
202
                <tr>
203
                  <td width="22%" valign="top" class="vncell">DNS servers</td>
204
                  <td width="78%" class="vtable"> <p>
205
                      <input name="dns1" type="text" class="formfld" id="dns1" size="20" value="<?=htmlspecialchars($pconfig['dns1']);?>">
206
                      <br>
207
                      <input name="dns2" type="text" class="formfld" id="dns22" size="20" value="<?=htmlspecialchars($pconfig['dns2']);?>">
208
                      <br>
209
                      <span class="vexpl">IP addresses; these are also used for
210
                      the DHCP service, DNS forwarder and for PPTP VPN clients<br>
211
                      <br>
212
                      <input name="dnsallowoverride" type="checkbox" id="dnsallowoverride" value="yes" <?php if ($pconfig['dnsallowoverride']) echo "checked"; ?>>
213
                      <strong>Allow DNS server list to be overridden by DHCP/PPP
214
                      on WAN</strong><br>
215
                      If this option is set, pfSense will use DNS servers assigned
216
                      by a DHCP/PPP server on WAN for its own purposes (including
217
                      the DNS forwarder). They will not be assigned to DHCP and
218
                      PPTP VPN clients, though.</span></p></td>
219
                </tr>
220
                <tr>
221
                  <td valign="top" class="vncell">Username</td>
222
                  <td class="vtable"> <input name="username" type="text" class="formfld" id="username" size="20" value="<?=$pconfig['username'];?>">
223
                    <br>
224
                     <span class="vexpl">If you want
225
                    to change the username for accessing the webGUI, enter it
226
                    here.</span></td>
227
                </tr>
228
                <tr>
229
                  <td width="22%" valign="top" class="vncell">Password</td>
230
                  <td width="78%" class="vtable"> <input name="password" type="password" class="formfld" id="password" size="20">
231
                    <br> <input name="password2" type="password" class="formfld" id="password2" size="20">
232
                    &nbsp;(confirmation) <br> <span class="vexpl">If you want
233
                    to change the password for accessing the webGUI, enter it
234
                    here twice.</span></td>
235
                </tr>
236
                <tr>
237
                  <td width="22%" valign="top" class="vncell">webGUI protocol</td>
238
                  <td width="78%" class="vtable"> <input name="webguiproto" type="radio" value="http" <?php if ($pconfig['webguiproto'] == "http") echo "checked"; ?>>
239
                    HTTP &nbsp;&nbsp;&nbsp; <input type="radio" name="webguiproto" value="https" <?php if ($pconfig['webguiproto'] == "https") echo "checked"; ?>>
240
                    HTTPS</td>
241
                </tr>
242
                <tr>
243
                  <td valign="top" class="vncell">webGUI port</td>
244
                  <td class="vtable"> <input name="webguiport" type="text" class="formfld" id="webguiport" "size="5" value="<?=htmlspecialchars($pconfig['webguiport']);?>">
245
                    <br>
246
                    <span class="vexpl">Enter a custom port number for the webGUI
247
                    above if you want to override the default (80 for HTTP, 443
248
                    for HTTPS). Changes will take effect immediately after save.</span></td>
249
                </tr>
250
                <tr>
251
                  <td width="22%" valign="top" class="vncell">Time zone</td>
252
                  <td width="78%" class="vtable"> <select name="timezone" id="timezone">
253
                      <?php foreach ($timezonelist as $value): ?>
254
                      <option value="<?=htmlspecialchars($value);?>" <?php if ($value == $pconfig['timezone']) echo "selected"; ?>>
255
                      <?=htmlspecialchars($value);?>
256
                      </option>
257
                      <?php endforeach; ?>
258
                    </select> <br> <span class="vexpl">Select the location closest
259
                    to you</span></td>
260
                </tr>
261
                <tr>
262
                  <td width="22%" valign="top" class="vncell">Time update interval</td>
263
                  <td width="78%" class="vtable"> <input name="timeupdateinterval" type="text" class="formfld" id="timeupdateinterval" size="4" value="<?=htmlspecialchars($pconfig['timeupdateinterval']);?>">
264
                    <br> <span class="vexpl">Minutes between network time sync.;
265
                    300 recommended, or 0 to disable </span></td>
266
                </tr>
267
                <tr>
268
                  <td width="22%" valign="top" class="vncell">NTP time server</td>
269
                  <td width="78%" class="vtable"> <input name="timeservers" type="text" class="formfld" id="timeservers" size="40" value="<?=htmlspecialchars($pconfig['timeservers']);?>">
270
                    <br> <span class="vexpl">Use a space to separate multiple
271
                    hosts (only one required). Remember to set up at least one
272
                    DNS server if you enter a host name here!</span></td>
273
                </tr>
274
                <tr>
275
                  <td width="22%" valign="top">&nbsp;</td>
276
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
277
                  </td>
278
                </tr>
279
              </table>
280
</form>
281
<?php include("fend.inc"); ?>
282
</body>
283
</html>
(91-91/112)