Project

General

Profile

Download (13.6 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

    
39
$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

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

    
61
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
	$changecount++;
72

    
73
	unset($input_errors);
74
	$pconfig = $_POST;
75

    
76
	/* input validation */
77
	$reqdfields = split(" ", "hostname domain username");
78
	$reqdfieldsn = split(",", "Hostname,Domain,Username");
79

    
80
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
81

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

    
102
	$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
		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

    
117
		if (update_if_changed("webgui protocol", $config['system']['webgui']['protocol'], $_POST['webguiproto']))
118
			$restart_webgui = true;
119
		if (update_if_changed("webgui port", $config['system']['webgui']['port'], $_POST['webguiport']))
120
			$restart_webgui = true;
121

    
122
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
123
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
124
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
125

    
126
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
127
		unset($config['system']['dnsserver']);
128
		if ($_POST['dns1'])
129
			$config['system']['dnsserver'][] = $_POST['dns1'];
130
		if ($_POST['dns2'])
131
			$config['system']['dnsserver'][] = $_POST['dns2'];
132

    
133
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
134
		
135
		unset($config['system']['dnsallowoverride']);
136
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
137

    
138
		if ($_POST['password']) {
139
			conf_mount_rw();
140
			$config['system']['password'] = crypt($_POST['password']);
141
			$fd = popen("/usr/sbin/pw usermod -n root -H 0", "w");
142
			$salt = md5(time());
143
			$crypted_pw = crypt($_POST['password'],$salt);
144
			fwrite($fd, $crypted_pw);
145
			pclose($fd);
146
			update_changedesc("password changed via webConfigurator");
147
			conf_mount_ro();
148
		}
149

    
150
		if ($changecount > 0)
151
			write_config($changedesc);
152

    
153
		if ($restart_webgui) {
154
			global $_SERVER;
155
			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
			} else {
159
				$url = "{$config['system']['webgui']['protocol']}://{$host}/system.php";
160
			}
161
		}
162

    
163
		$retval = 0;
164
		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
		sync_webgui_passwords();
174

    
175
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
176
			$retval |= interfaces_wan_configure();
177

    
178
		config_unlock();
179

    
180
		$savemsg = get_std_save_message($retval);
181
		if ($restart_webgui)
182
			$savemsg .= "<br />One moment...redirecting to {$url}";
183
	}
184
}
185

    
186
$pgtitle = "System: General Setup";
187
include("head.inc");
188

    
189
?>
190

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

    
296
?>
297
</body>
298
</html>
299
<?php
300
if ($restart_webgui)
301
	system_webgui_start();
(116-116/146)