Project

General

Profile

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

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

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

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

    
16
	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

    
20
	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

    
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
$pconfig['theme'] = $config['system']['theme'];
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
if($pconfig['timezone'] <> $_POST['timezone']) {
66
	/* restart firewall log dumper helper */
67
	require_once("functions.inc");
68
	$pid = `ps awwwux | grep -v "grep" | grep "tcpdump -v -l -n -e -ttt -i pflog0"  | awk '{ print $2 }'`;
69
	if($pid) {
70
		mwexec("kill $pid");
71
		usleep(1000);
72
	}		
73
	filter_pflog_start();
74
}
75

    
76
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
77
$timezonelist = array_filter($timezonelist, 'is_timezone');
78
sort($timezonelist);
79

    
80
if ($_POST) {
81

    
82
	$changecount++;
83

    
84
	unset($input_errors);
85
	$pconfig = $_POST;
86

    
87
	/* input validation */
88
	$reqdfields = split(" ", "hostname domain username");
89
	$reqdfieldsn = split(",", "Hostname,Domain,Username");
90

    
91
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
92

    
93
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
94
		$input_errors[] = "The hostname may only contain the characters a-z, 0-9 and '-'.";
95
	}
96
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
97
		$input_errors[] = "The domain may only contain the characters a-z, 0-9, '-' and '.'.";
98
	}
99
	if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) {
100
		$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS server.";
101
	}
102
	if ($_POST['username'] && !preg_match("/^[a-zA-Z0-9]*$/", $_POST['username'])) {
103
		$input_errors[] = "The username may only contain the characters a-z, A-Z and 0-9.";
104
	}
105
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
106
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
107
		$input_errors[] = "A valid TCP/IP port must be specified for the webGUI port.";
108
	}
109
	if (($_POST['password']) && ($_POST['password'] != $_POST['password2'])) {
110
		$input_errors[] = "The passwords do not match.";
111
	}
112

    
113
	$t = (int)$_POST['timeupdateinterval'];
114
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
115
		$input_errors[] = "The time update interval must be either 0 (disabled) or between 6 and 1440.";
116
	}
117
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
118
		if (!is_domain($ts)) {
119
			$input_errors[] = "A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.";
120
		}
121
	}
122

    
123
	if (!$input_errors) {
124
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
125
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
126
		update_if_changed("username", $config['system']['username'], $_POST['username']);
127

    
128
		if (update_if_changed("webgui protocol", $config['system']['webgui']['protocol'], $_POST['webguiproto']))
129
			$restart_webgui = true;
130
		if (update_if_changed("webgui port", $config['system']['webgui']['port'], $_POST['webguiport']))
131
			$restart_webgui = true;
132

    
133
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
134
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
135
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
136

    
137
		/* pfSense themes */
138
		update_if_changed("System Theme", $config['theme'], $_POST['theme']);
139

    
140
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
141
		unset($config['system']['dnsserver']);
142
		if ($_POST['dns1'])
143
			$config['system']['dnsserver'][] = $_POST['dns1'];
144
		if ($_POST['dns2'])
145
			$config['system']['dnsserver'][] = $_POST['dns2'];
146

    
147
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
148

    
149
		unset($config['system']['dnsallowoverride']);
150
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
151
                if ($_POST['password']) {
152
                        $config['system']['password'] = crypt($_POST['password']);
153
			update_changedesc("password changed via webConfigurator");
154
			sync_webgui_passwords();
155
                }
156

    
157
		if ($changecount > 0)
158
			write_config($changedesc);
159

    
160
		if ($restart_webgui) {
161
			global $_SERVER;
162
			list($host) = explode(":", $_SERVER['HTTP_HOST']);
163
			if ($config['system']['webgui']['port']) {
164
				$url="{$config['system']['webgui']['protocol']}://{$host}:{$config['system']['webgui']['port']}/system.php";
165
			} else {
166
				$url = "{$config['system']['webgui']['protocol']}://{$host}/system.php";
167
			}
168
		}
169

    
170
		$retval = 0;
171
		config_lock();
172
		$retval = system_hostname_configure();
173
		$retval |= system_hosts_generate();
174
		$retval |= system_resolvconf_generate();
175
		$retval |= system_password_configure();
176
		$retval |= services_dnsmasq_configure();
177
		$retval |= system_timezone_configure();
178
		$retval |= system_ntp_configure();
179

    
180
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
181
			$retval |= interfaces_wan_configure();
182

    
183
		config_unlock();
184

    
185
		// Reload filter -- plugins might need to run
186
		filter_configure();
187

    
188
		$savemsg = get_std_save_message($retval);
189
		if ($restart_webgui)
190
			$savemsg .= "<br />One moment...redirecting to {$url} in 10 seconds.";
191
	}
192
}
193

    
194
$pgtitle = "System: General Setup";
195
include("head.inc");
196

    
197
?>
198

    
199
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
200
<?php include("fbegin.inc"); ?>
201
<p class="pgtitle"><?=$pgtitle?></p>
202
<?php if ($input_errors) print_input_errors($input_errors); ?>
203
<?php if ($savemsg) print_info_box($savemsg); ?>
204
<form action="system.php" method="post">
205
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
206
                <tr>
207
                  <td width="22%" valign="top" class="vncellreq">Hostname</td>
208
                  <td width="78%" class="vtable"> <input name="hostname" type="text" class="formfld" id="hostname" size="40" value="<?=htmlspecialchars($pconfig['hostname']);?>">
209
                    <br> <span class="vexpl">name of the firewall host, without
210
                    domain part<br>
211
                    e.g. <em>firewall</em></span></td>
212
                </tr>
213
                <tr>
214
                  <td width="22%" valign="top" class="vncellreq">Domain</td>
215
                  <td width="78%" class="vtable"> <input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
216
                    <br> <span class="vexpl">e.g. <em>mycorp.com</em> </span></td>
217
                </tr>
218
                <tr>
219
                  <td width="22%" valign="top" class="vncell">DNS servers</td>
220
                  <td width="78%" class="vtable"> <p>
221
                      <input name="dns1" type="text" class="formfld" id="dns1" size="20" value="<?=htmlspecialchars($pconfig['dns1']);?>">
222
                      <br>
223
                      <input name="dns2" type="text" class="formfld" id="dns22" size="20" value="<?=htmlspecialchars($pconfig['dns2']);?>">
224
                      <br>
225
                      <span class="vexpl">IP addresses; these are also used for
226
                      the DHCP service, DNS forwarder and for PPTP VPN clients<br>
227
                      <br>
228
                      <input name="dnsallowoverride" type="checkbox" id="dnsallowoverride" value="yes" <?php if ($pconfig['dnsallowoverride']) echo "checked"; ?>>
229
                      <strong>Allow DNS server list to be overridden by DHCP/PPP
230
                      on WAN</strong><br>
231
                      If this option is set, <?=$g['product_name']?> will use DNS servers assigned
232
                      by a DHCP/PPP server on WAN for its own purposes (including
233
                      the DNS forwarder). They will not be assigned to DHCP and
234
                      PPTP VPN clients, though.</span></p></td>
235
                </tr>
236
                <tr>
237
                  <td valign="top" class="vncell">Username</td>
238
                  <td class="vtable"> <input name="username" type="text" class="formfld" id="username" size="20" value="<?=$pconfig['username'];?>">
239
                    <br>
240
                     <span class="vexpl">If you want
241
                    to change the username for accessing the webGUI, enter it
242
                    here.</span></td>
243
                </tr>
244
                <tr>
245
                  <td width="22%" valign="top" class="vncell">Password</td>
246
                  <td width="78%" class="vtable"> <input name="password" type="password" class="formfld" id="password" size="20">
247
                    <br> <input name="password2" type="password" class="formfld" id="password2" size="20">
248
                    &nbsp;(confirmation) <br> <span class="vexpl">If you want
249
                    to change the password for accessing the webGUI, enter it
250
                    here twice.</span></td>
251
                </tr>
252
                <tr>
253
                  <td width="22%" valign="top" class="vncell">webGUI protocol</td>
254
                  <td width="78%" class="vtable"> <input name="webguiproto" type="radio" value="http" <?php if ($pconfig['webguiproto'] == "http") echo "checked"; ?>>
255
                    HTTP &nbsp;&nbsp;&nbsp; <input type="radio" name="webguiproto" value="https" <?php if ($pconfig['webguiproto'] == "https") echo "checked"; ?>>
256
                    HTTPS</td>
257
                </tr>
258
                <tr>
259
                  <td valign="top" class="vncell">webGUI port</td>
260
                  <td class="vtable"> <input name="webguiport" type="text" class="formfld" id="webguiport" "size="5" value="<?=htmlspecialchars($config['system']['webgui']['port']);?>">
261
                    <br>
262
                    <span class="vexpl">Enter a custom port number for the webGUI
263
                    above if you want to override the default (80 for HTTP, 443
264
                    for HTTPS). Changes will take effect immediately after save.</span></td>
265
                </tr>
266
                <tr>
267
                  <td width="22%" valign="top" class="vncell">Time zone</td>
268
                  <td width="78%" class="vtable"> <select name="timezone" id="timezone">
269
                      <?php foreach ($timezonelist as $value): ?>
270
                      <option value="<?=htmlspecialchars($value);?>" <?php if ($value == $pconfig['timezone']) echo "selected"; ?>>
271
                      <?=htmlspecialchars($value);?>
272
                      </option>
273
                      <?php endforeach; ?>
274
                    </select> <br> <span class="vexpl">Select the location closest
275
                    to you</span></td>
276
                </tr>
277
                <!--
278
                <tr>
279
                  <td width="22%" valign="top" class="vncell">Time update interval</td>
280
                  <td width="78%" class="vtable"> <input name="timeupdateinterval" type="text" class="formfld" id="timeupdateinterval" size="4" value="<?=htmlspecialchars($pconfig['timeupdateinterval']);?>">
281
                    <br> <span class="vexpl">Minutes between network time sync.;
282
                    300 recommended, or 0 to disable </span></td>
283
                </tr>
284
                -->
285
                <tr>
286
                  <td width="22%" valign="top" class="vncell">NTP time server</td>
287
                  <td width="78%" class="vtable"> <input name="timeservers" type="text" class="formfld" id="timeservers" size="40" value="<?=htmlspecialchars($pconfig['timeservers']);?>">
288
                    <br> <span class="vexpl">Use a space to separate multiple
289
                    hosts (only one required). Remember to set up at least one
290
                    DNS server if you enter a host name here!</span></td>
291
                </tr>
292
				<tr>
293
					<td colspan="2" class="list" height="12">&nbsp;</td>
294
				</tr>
295
				<tr>
296
					<td colspan="2" valign="top" class="listtopic">Theme</td>
297
				</tr>
298
				<tr>
299
				<td width="22%" valign="top" class="vncell">&nbsp;</td>
300
				<td width="78%" class="vtable">
301
				    <select name="theme">
302
<?php
303
				$files = return_dir_as_array("/usr/local/www/themes/");
304
				foreach($files as $f) {
305
					if ( (substr($f, 0, 1) == "_") && !isset($config['system']['developer']) ) continue;
306
					if($f == "CVS") continue;
307
					$selected = "";
308
					if($f == $config['theme'])
309
						$selected = " SELECTED";
310
					if($config['theme'] == "" and $f == "pfsense")
311
						$selceted = " SELECTED";
312
					echo "\t\t\t\t\t"."<option{$selected}>{$f}</option>\n";
313
				}
314
?>
315
					</select>
316
					<strong>This will change the look and feel of <?=$g['product_name']?></strong>
317
				</td>
318
				</tr>
319
				<tr>
320
                  <td width="22%" valign="top">&nbsp;</td>
321
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
322
                  </td>
323
                </tr>
324
              </table>
325
</form>
326
<?php include("fend.inc"); ?>
327
<?php
328
	// restart webgui if proto or port changed
329
	if ($restart_webgui) {
330
		echo "<meta http-equiv=\"refresh\" content=\"10;url={$url}\">";
331
	}
332
?>
333
</body>
334
</html>
335
<?php
336
if ($restart_webgui) {
337
	touch("/tmp/restart_webgui");
338
}
339
?>
(138-138/175)