Project

General

Profile

Download (12.7 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
		}
129
		
130
		write_config();
131
		
132
		if (($oldwebguiproto != $config['system']['webgui']['protocol']) ||
133
			($oldwebguiport != $config['system']['webgui']['port']))
134
			touch($d_sysrebootreqd_path);
135
		
136
		$retval = 0;
137
		if (!file_exists($d_sysrebootreqd_path)) {
138
			config_lock();
139
			$retval = system_hostname_configure();
140
			$retval |= system_hosts_generate();
141
			$retval |= system_resolvconf_generate();
142
			$retval |= system_password_configure();
143
			$retval |= services_dnsmasq_configure();
144
			$retval |= system_timezone_configure();
145
 			$retval |= system_ntp_configure();
146
 			
147
 			if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
148
 				$retval |= interfaces_wan_configure();
149
 			
150
			config_unlock();
151
		}
152
		
153
		$savemsg = get_std_save_message($retval);
154
	}
155
}
156
?>
157
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
158
<html>
159
<head>
160
<title><?=gentitle("System: General setup");?></title>
161
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
162
<link href="gui.css" rel="stylesheet" type="text/css">
163
</head>
164

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