Project

General

Profile

Download (14.4 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
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
		/* pfSense themes */
127
		update_if_changed("System Theme", $config['theme'], $_POST['theme']);		
128

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

    
136
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
137
		
138
		unset($config['system']['dnsallowoverride']);
139
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
140
                if ($_POST['password']) {
141
                        $config['system']['password'] = crypt($_POST['password']);
142
			update_changedesc("password changed via webConfigurator");
143
			sync_webgui_passwords();			
144
                }
145

    
146
		if ($changecount > 0)
147
			write_config($changedesc);
148

    
149
		if ($restart_webgui) {
150
			global $_SERVER;
151
			list($host) = explode(":", $_SERVER['HTTP_HOST']);
152
			if ($config['system']['webgui']['port']) {
153
				$url="{$config['system']['webgui']['protocol']}://{$host}:{$config['system']['webgui']['port']}/system.php";
154
			} else {
155
				$url = "{$config['system']['webgui']['protocol']}://{$host}/system.php";
156
			}
157
		}
158

    
159
		$retval = 0;
160
		config_lock();
161
		$retval = system_hostname_configure();
162
		$retval |= system_hosts_generate();
163
		$retval |= system_resolvconf_generate();
164
		$retval |= system_password_configure();
165
		$retval |= services_dnsmasq_configure();
166
		$retval |= system_timezone_configure();
167
		$retval |= system_ntp_configure();
168

    
169
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
170
			$retval |= interfaces_wan_configure();
171

    
172
		config_unlock();
173

    
174
		$savemsg = get_std_save_message($retval);
175
		if ($restart_webgui)
176
			$savemsg .= "<br />One moment...redirecting to {$url} in 10 seconds.";
177
	}
178
}
179

    
180
$pgtitle = "System: General Setup";
181
include("head.inc");
182

    
183
?>
184

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