Project

General

Profile

« Previous | Next » 

Revision 04ad7c7c

Added by Scott Ullrich over 20 years ago

Sync root password with admin password

View differences:

usr/local/www/system.php
1 1
#!/usr/local/bin/php
2
<?php 
2
<?php
3 3
/*
4 4
	system.php
5 5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
6

  
7 7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8 8
	All rights reserved.
9
	
9

  
10 10
	Redistribution and use in source and binary forms, with or without
11 11
	modification, are permitted provided that the following conditions are met:
12
	
12

  
13 13
	1. Redistributions of source code must retain the above copyright notice,
14 14
	   this list of conditions and the following disclaimer.
15
	
15

  
16 16
	2. Redistributions in binary form must reproduce the above copyright
17 17
	   notice, this list of conditions and the following disclaimer in the
18 18
	   documentation and/or other materials provided with the distribution.
19
	
19

  
20 20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21 21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22 22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
......
52 52
	$pconfig['timezone'] = "Etc/UTC";
53 53
if (!$pconfig['timeservers'])
54 54
	$pconfig['timeservers'] = "pool.ntp.org";
55
	
55

  
56 56
function is_timezone($elt) {
57 57
	return !preg_match("/\/$/", $elt);
58 58
}
......
69 69
	/* input validation */
70 70
	$reqdfields = split(" ", "hostname domain username");
71 71
	$reqdfieldsn = split(",", "Hostname,Domain,Username");
72
	
72

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

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

  
95 95
	$t = (int)$_POST['timeupdateinterval'];
96 96
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
97 97
		$input_errors[] = "The time update interval must be either 0 (disabled) or between 6 and 1440.";
......
113 113
		$config['system']['timezone'] = $_POST['timezone'];
114 114
		$config['system']['timeservers'] = strtolower($_POST['timeservers']);
115 115
		$config['system']['time-update-interval'] = $_POST['timeupdateinterval'];
116
		
116

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

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

  
126 126
		if ($_POST['password']) {
127 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);
128 133
		}
129
		
134

  
130 135
		write_config();
131
		
136

  
132 137
		if (($oldwebguiproto != $config['system']['webgui']['protocol']) ||
133 138
			($oldwebguiport != $config['system']['webgui']['port']))
134 139
			touch($d_sysrebootreqd_path);
135
		
140

  
136 141
		$retval = 0;
137 142
		if (!file_exists($d_sysrebootreqd_path)) {
138 143
			config_lock();
......
143 148
			$retval |= services_dnsmasq_configure();
144 149
			$retval |= system_timezone_configure();
145 150
 			$retval |= system_ntp_configure();
146
 			
151

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

  
150 155
			config_unlock();
151 156
		}
152
		
157

  
153 158
		$savemsg = get_std_save_message($retval);
154 159
	}
155 160
}
......
169 174
<?php if ($savemsg) print_info_box($savemsg); ?>
170 175
<form action="system.php" method="post">
171 176
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
172
                <tr> 
177
                <tr>
173 178
                  <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 
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
176 181
                    domain part<br>
177 182
                    e.g. <em>firewall</em></span></td>
178 183
                </tr>
179
                <tr> 
184
                <tr>
180 185
                  <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']);?>"> 
186
                  <td width="78%" class="vtable"> <input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
182 187
                    <br> <span class="vexpl">e.g. <em>mycorp.com</em> </span></td>
183 188
                </tr>
184
                <tr> 
189
                <tr>
185 190
                  <td width="22%" valign="top" class="vncell">DNS servers</td>
186
                  <td width="78%" class="vtable"> <p> 
191
                  <td width="78%" class="vtable"> <p>
187 192
                      <input name="dns1" type="text" class="formfld" id="dns1" size="20" value="<?=htmlspecialchars($pconfig['dns1']);?>">
188 193
                      <br>
189 194
                      <input name="dns2" type="text" class="formfld" id="dns22" size="20" value="<?=htmlspecialchars($pconfig['dns2']);?>">
190 195
                      <br>
191
                      <span class="vexpl">IP addresses; these are also used for 
196
                      <span class="vexpl">IP addresses; these are also used for
192 197
                      the DHCP service, DNS forwarder and for PPTP VPN clients<br>
193 198
                      <br>
194 199
                      <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 
200
                      <strong>Allow DNS server list to be overridden by DHCP/PPP
196 201
                      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 
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
200 205
                      PPTP VPN clients, though.</span></p></td>
201 206
                </tr>
202
                <tr> 
207
                <tr>
203 208
                  <td valign="top" class="vncell">Username</td>
204 209
                  <td class="vtable"> <input name="username" type="text" class="formfld" id="username" size="20" value="<?=$pconfig['username'];?>">
205 210
                    <br>
206
                     <span class="vexpl">If you want 
207
                    to change the username for accessing the webGUI, enter it 
211
                     <span class="vexpl">If you want
212
                    to change the username for accessing the webGUI, enter it
208 213
                    here.</span></td>
209 214
                </tr>
210
                <tr> 
215
                <tr>
211 216
                  <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 
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
216 221
                    here twice.</span></td>
217 222
                </tr>
218
                <tr> 
223
                <tr>
219 224
                  <td width="22%" valign="top" class="vncell">webGUI protocol</td>
220 225
                  <td width="78%" class="vtable"> <input name="webguiproto" type="radio" value="http" <?php if ($pconfig['webguiproto'] == "http") echo "checked"; ?>>
221 226
                    HTTP &nbsp;&nbsp;&nbsp; <input type="radio" name="webguiproto" value="https" <?php if ($pconfig['webguiproto'] == "https") echo "checked"; ?>>
222 227
                    HTTPS</td>
223 228
                </tr>
224
                <tr> 
229
                <tr>
225 230
                  <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']);?>"> 
231
                  <td class="vtable"> <input name="webguiport" type="text" class="formfld" id="webguiport" size="5" value="<?=htmlspecialchars($pconfig['webguiport']);?>">
227 232
                    <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 
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
230 235
                    for HTTPS).</span></td>
231 236
                </tr>
232
                <tr> 
237
                <tr>
233 238
                  <td width="22%" valign="top" class="vncell">Time zone</td>
234 239
                  <td width="78%" class="vtable"> <select name="timezone" id="timezone">
235 240
                      <?php foreach ($timezonelist as $value): ?>
236
                      <option value="<?=htmlspecialchars($value);?>" <?php if ($value == $pconfig['timezone']) echo "selected"; ?>> 
241
                      <option value="<?=htmlspecialchars($value);?>" <?php if ($value == $pconfig['timezone']) echo "selected"; ?>>
237 242
                      <?=htmlspecialchars($value);?>
238 243
                      </option>
239 244
                      <?php endforeach; ?>
240
                    </select> <br> <span class="vexpl">Select the location closest 
245
                    </select> <br> <span class="vexpl">Select the location closest
241 246
                    to you</span></td>
242 247
                </tr>
243
                <tr> 
248
                <tr>
244 249
                  <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.; 
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.;
247 252
                    300 recommended, or 0 to disable </span></td>
248 253
                </tr>
249
                <tr> 
254
                <tr>
250 255
                  <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 
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
254 259
                    DNS server if you enter a host name here!</span></td>
255 260
                </tr>
256
                <tr> 
261
                <tr>
257 262
                  <td width="22%" valign="top">&nbsp;</td>
258
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save"> 
263
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
259 264
                  </td>
260 265
                </tr>
261 266
              </table>

Also available in: Unified diff