Project

General

Profile

Download (2.81 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php-cgi -f
2
<?php
3
/*
4
 * rc.initial.password
5
 *
6
 * part of pfSense (https://www.pfsense.org)
7
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
8
 * All rights reserved.
9
 *
10
 * originally part of m0n0wall (http://m0n0.ch/wall)
11
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
 * All rights reserved.
13
 *
14
 * Licensed under the Apache License, Version 2.0 (the "License");
15
 * you may not use this file except in compliance with the License.
16
 * You may obtain a copy of the License at
17
 *
18
 * http://www.apache.org/licenses/LICENSE-2.0
19
 *
20
 * Unless required by applicable law or agreed to in writing, software
21
 * distributed under the License is distributed on an "AS IS" BASIS,
22
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
 * See the License for the specific language governing permissions and
24
 * limitations under the License.
25
 */
26

    
27
	/* parse the configuration and include all functions used below */
28

    
29
	require_once("config.inc");
30
	require_once("auth.inc");
31
	require_once("functions.inc");
32
	require_once("shaper.inc");
33

    
34
	$fp = fopen('php://stdin', 'r');
35

    
36
	echo "\n" . gettext('
37
The webConfigurator admin password and privileges will be reset to the default (which is "' . strtolower($g['product_name']) . '").') . "\n" .
38
	gettext('Do you want to proceed [y|n]?') . " ";
39

    
40
	if (strcasecmp(chop(fgets($fp)), "y") == 0) {
41
		if (isset($config['system']['webgui']['authmode']) &&
42
		    $config['system']['webgui']['authmode'] != "Local Database") {
43
			echo "\n" . gettext('
44
The User manager authentication server is set to "' . $config['system']['webgui']['authmode'] . '".') . "\n" .
45
			gettext('Do you want to set it back to Local Database [y|n]?') . " ";
46
			if (strcasecmp(chop(fgets($fp)), "y") == 0) {
47
				$config['system']['webgui']['authmode'] = "Local Database";
48
			}
49
		}
50
		$admin_user =& getUserEntryByUID(0);
51
		if (!$admin_user) {
52
			echo "Failed to locate the admin user account! Attempting to restore access.\n";
53
			$admin_user = array();
54
			$admin_user['uid'] = 0;
55
			if (!is_array($config['system']['user'])) {
56
				$config['system']['user'] = array();
57
			}
58
			$config['system']['user'][] = $admin_user;
59
		}
60

    
61
		$admin_user['name'] = "admin";
62
		$admin_user['scope'] = "system";
63
		$admin_user['priv'] = array("user-shell-access");
64

    
65
		if (isset($admin_user['disabled'])) {
66
			unset($admin_user['disabled']);
67
		}
68

    
69
		local_user_set_password($admin_user, strtolower($g['product_name']));
70
		local_user_set($admin_user);
71
		write_config(gettext("password changed from console menu"));
72

    
73
		echo "\n" . gettext('
74
The password for the webConfigurator has been reset and
75
the default username has been set to "admin".') . "\n" .
76
		gettext('
77
Remember to set the password to something else than
78
the default as soon as you have logged into the webConfigurator.') . "\n" .
79
		gettext("Press ENTER to continue.");
80

    
81
		fgets($fp);
82
	}
83
?>
(40-40/78)