Project

General

Profile

Download (12.8 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
		if (($oldwebguiproto != $config['system']['webgui']['protocol']) ||
138
			($oldwebguiport != $config['system']['webgui']['port']))
139
			touch($d_sysrebootreqd_path);
140

    
141
		$retval = 0;
142
		if (!file_exists($d_sysrebootreqd_path)) {
143
			config_lock();
144
			$retval = system_hostname_configure();
145
			$retval |= system_hosts_generate();
146
			$retval |= system_resolvconf_generate();
147
			$retval |= system_password_configure();
148
			$retval |= services_dnsmasq_configure();
149
			$retval |= system_timezone_configure();
150
 			$retval |= system_ntp_configure();
151

    
152
 			if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
153
 				$retval |= interfaces_wan_configure();
154

    
155
			config_unlock();
156
		}
157

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

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