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['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
	$changecount++;
71

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

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

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

    
81
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
82
		$input_errors[] = "The hostname may only contain the characters a-z, 0-9 and '-'.";
83
	}
84
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
85
		$input_errors[] = "The domain may only contain the characters a-z, 0-9, '-' and '.'.";
86
	}
87
	if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) {
88
		$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS server.";
89
	}
90
	if ($_POST['username'] && !preg_match("/^[a-zA-Z0-9]*$/", $_POST['username'])) {
91
		$input_errors[] = "The username may only contain the characters a-z, A-Z and 0-9.";
92
	}
93
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
94
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
95
		$input_errors[] = "A valid TCP/IP port must be specified for the webGUI port.";
96
	}
97
	if (($_POST['password']) && ($_POST['password'] != $_POST['password2'])) {
98
		$input_errors[] = "The passwords do not match.";
99
	}
100

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

    
111
	if (!$input_errors) {
112
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
113
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
114
		update_if_changed("username", $config['system']['username'], $_POST['username']);
115

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

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

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

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

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

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

    
155
		$retval = 0;
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
		$savemsg = get_std_save_message($retval);
171
		if ($restart_webgui)
172
			$savemsg .= "<br />One moment...redirecting to {$url} in 10 seconds.";
173
	}
174
}
175

    
176
$pgtitle = "System: General Setup";
177
include("head.inc");
178

    
179
?>
180

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