Project

General

Profile

Download (13.5 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['webguiproto'] = $config['system']['webgui']['protocol'];
40
if (!$pconfig['webguiproto'])
41
	$pconfig['webguiproto'] = "http";
42
$pconfig['webguiport'] = $config['system']['webgui']['port'];
43
$pconfig['timezone'] = $config['system']['timezone'];
44
$pconfig['timeupdateinterval'] = $config['system']['time-update-interval'];
45
$pconfig['timeservers'] = $config['system']['timeservers'];
46
$pconfig['theme'] = $config['system']['theme'];
47

    
48
if (!isset($pconfig['timeupdateinterval']))
49
	$pconfig['timeupdateinterval'] = 300;
50
if (!$pconfig['timezone'])
51
	$pconfig['timezone'] = "Etc/UTC";
52
if (!$pconfig['timeservers'])
53
	$pconfig['timeservers'] = "pool.ntp.org";
54

    
55
$changedesc = "System: ";
56
$changecount = 0;
57

    
58
function is_timezone($elt) {
59
	return !preg_match("/\/$/", $elt);
60
}
61

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

    
73
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
74
$timezonelist = array_filter($timezonelist, 'is_timezone');
75
sort($timezonelist);
76

    
77
if ($_POST) {
78

    
79
	$changecount++;
80

    
81
	unset($input_errors);
82
	$pconfig = $_POST;
83

    
84
	/* input validation */
85
	$reqdfields = split(" ", "hostname domain");
86
	$reqdfieldsn = split(",", "Hostname,Domain");
87

    
88
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
89

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

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

    
117
	if (!$input_errors) {
118
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
119
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
120

    
121
		if (update_if_changed("webgui protocol", $config['system']['webgui']['protocol'], $_POST['webguiproto']))
122
			$restart_webgui = true;
123
		if (update_if_changed("webgui port", $config['system']['webgui']['port'], $_POST['webguiport']))
124
			$restart_webgui = true;
125

    
126
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
127
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
128
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
129

    
130
		/* pfSense themes */
131
		update_if_changed("System Theme", $config['theme'], $_POST['theme']);
132

    
133
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
134
		unset($config['system']['dnsserver']);
135
		if ($_POST['dns1'])
136
			$config['system']['dnsserver'][] = $_POST['dns1'];
137
		if ($_POST['dns2'])
138
			$config['system']['dnsserver'][] = $_POST['dns2'];
139

    
140
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
141

    
142
		unset($config['system']['dnsallowoverride']);
143
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
144
                if ($_POST['password']) {
145
                        $config['system']['password'] = crypt($_POST['password']);
146
			update_changedesc("password changed via webConfigurator");
147
			sync_webgui_passwords();
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
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
174
			$retval |= interfaces_wan_configure();
175

    
176
		config_unlock();
177

    
178
		$savemsg = get_std_save_message($retval);
179
		if ($restart_webgui)
180
			$savemsg .= "<br />One moment...redirecting to {$url} in 10 seconds.";
181
	}
182
}
183

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

    
187
?>
188

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