Project

General

Profile

Download (13.3 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
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
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
38
$pconfig['username'] = $config['system']['username'];
39
if (!$pconfig['username'])
40
	$pconfig['username'] = "admin";
41
$pconfig['webguiproto'] = $config['system']['webgui']['protocol'];
42
if (!$pconfig['webguiproto'])
43
	$pconfig['webguiproto'] = "http";
44
$pconfig['webguiport'] = $config['system']['webgui']['port'];
45
$pconfig['timezone'] = $config['system']['timezone'];
46
$pconfig['timeupdateinterval'] = $config['system']['time-update-interval'];
47
$pconfig['timeservers'] = $config['system']['timeservers'];
48

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

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

    
60
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
61
$timezonelist = array_filter($timezonelist, 'is_timezone');
62
sort($timezonelist);
63

    
64
if ($_POST) {
65

    
66
	unset($input_errors);
67
	$pconfig = $_POST;
68

    
69
	/* input validation */
70
	$reqdfields = split(" ", "hostname domain username");
71
	$reqdfieldsn = split(",", "Hostname,Domain,Username");
72

    
73
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
74

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

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

    
105
	if (!$input_errors) {
106
		$config['system']['hostname'] = strtolower($_POST['hostname']);
107
		$config['system']['domain'] = strtolower($_POST['domain']);
108
		$oldwebguiproto = $config['system']['webgui']['protocol'];
109
		$config['system']['username'] = $_POST['username'];
110
		$config['system']['webgui']['protocol'] = $pconfig['webguiproto'];
111
		$oldwebguiport = $config['system']['webgui']['port'];
112
		$config['system']['webgui']['port'] = $pconfig['webguiport'];
113
		$config['system']['timezone'] = $_POST['timezone'];
114
		$config['system']['timeservers'] = strtolower($_POST['timeservers']);
115
		$config['system']['time-update-interval'] = $_POST['timeupdateinterval'];
116

    
117
		unset($config['system']['dnsserver']);
118
		if ($_POST['dns1'])
119
			$config['system']['dnsserver'][] = $_POST['dns1'];
120
		if ($_POST['dns2'])
121
			$config['system']['dnsserver'][] = $_POST['dns2'];
122

    
123
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
124
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
125

    
126
		if ($_POST['password']) {
127
			$config['system']['password'] = crypt($_POST['password']);
128
			$fd = popen("/usr/sbin/pw usermod -n root -H 0", "w");
129
			$salt = md5(time());
130
			$crypted_pw = crypt($_POST['password'],$salt);
131
			fwrite($fd, $crypted_pw);
132
			pclose($fd);
133
		}
134

    
135
		write_config();
136

    
137
		// restart webgui if proto or port changed
138
		if (($oldwebguiproto != $config['system']['webgui']['protocol']) ||
139
			($oldwebguiport != $config['system']['webgui']['port'])) {
140
			global $_SERVER;
141
			system_webgui_start();
142
			if ($pconfig['webguiport'])
143
				header("Location: {$pconfig['webguiproto']}://{$_SERVER['SERVER_NAME']}:{$pconfig['webguiport']}/system.php");
144
			else
145
				header("Location: {$pconfig['webguiproto']}://{$_SERVER['SERVER_NAME']}/system.php");
146
		}
147

    
148
		$retval = 0;
149
		if (!file_exists($d_sysrebootreqd_path)) {
150
			config_lock();
151
			$retval = system_hostname_configure();
152
			$retval |= system_hosts_generate();
153
			$retval |= system_resolvconf_generate();
154
			$retval |= system_password_configure();
155
			$retval |= services_dnsmasq_configure();
156
			$retval |= system_timezone_configure();
157
 			$retval |= system_ntp_configure();
158

    
159
 			if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
160
 				$retval |= interfaces_wan_configure();
161

    
162
			config_unlock();
163
		}
164

    
165
		$savemsg = get_std_save_message($retval);
166
	}
167
}
168
?>
169
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
170
<html>
171
<head>
172
<title><?=gentitle("System: General setup");?></title>
173
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
174
<link href="gui.css" rel="stylesheet" type="text/css">
175
</head>
176

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