Project

General

Profile

Download (3.31 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-2013 BSD Perimeter
8
 * Copyright (c) 2013-2016 Electric Sheep Fencing
9
 * Copyright (c) 2014-2025 Rubicon Communications, LLC (Netgate)
10
 * All rights reserved.
11
 *
12
 * originally part of m0n0wall (http://m0n0.ch/wall)
13
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
14
 * All rights reserved.
15
 *
16
 * Licensed under the Apache License, Version 2.0 (the "License");
17
 * you may not use this file except in compliance with the License.
18
 * You may obtain a copy of the License at
19
 *
20
 * http://www.apache.org/licenses/LICENSE-2.0
21
 *
22
 * Unless required by applicable law or agreed to in writing, software
23
 * distributed under the License is distributed on an "AS IS" BASIS,
24
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
 * See the License for the specific language governing permissions and
26
 * limitations under the License.
27
 */
28

    
29
/* parse the configuration and include all functions used below */
30

    
31
require_once("config.inc");
32
require_once("auth.inc");
33
require_once("functions.inc");
34
require_once("shaper.inc");
35

    
36
$fp = fopen('php://stdin', 'r');
37

    
38
echo "\n";
39
echo gettext('The authentication configuration and privileges for the "admin" account will be reset to the default.');
40
echo "\n";
41
echo gettext('Proceed?') . " (y|n): ";
42

    
43
if (strcasecmp(chop(fgets($fp)), "y") == 0) {
44
	/* Check authentication mode */
45
	$authmode = config_get_path('system/webgui/authmode', 'Local Database');
46
	if ($authmode != 'Local Database') {
47
		echo "\n";
48
		echo sprintf(gettext('The User manager authentication server is set to: %s.'), $authmode);
49
		echo "\n";
50
		echo gettext('Revert setting to Local Database [y|n]?') . " ";
51
		if (strcasecmp(chop(fgets($fp)), "y") == 0) {
52
			config_set_path('system/webgui/authmode', 'Local Database');
53
		}
54
	}
55

    
56
	/* Check for missing/deleted admin account */
57
	$user_item_config = getUserEntryByUID(0);
58
	$admin_user = &$user_item_config['item'];
59
	if (!$admin_user) {
60
		echo gettext('Cannot locate the "admin" account in the User Manager!');
61
		echo "\n";
62
		echo gettext('Attempting to restore the account.');
63
		echo "\n";
64
		$admin_user = ['uid' => 0];
65
		config_set_path('system/user/', $admin_user);
66
		$user_item_config = getUserEntryByUID(0);
67
		$admin_user = &$user_item_config['item'];
68
	}
69

    
70
	/* Reset admin account name, scope, and privileges */
71
	$admin_user['name'] = 'admin';
72
	$admin_user['scope'] = 'system';
73
	$admin_user['priv'] = ['user-shell-access'];
74

    
75
	/* Re-enable disabled admin account */
76
	if (isset($admin_user['disabled'])) {
77
		unset($admin_user['disabled']);
78
	}
79

    
80
	/* Remove account expiration */
81
	if (isset($admin_user['expires'])) {
82
		unset($admin_user['expires']);
83
	}
84

    
85
	/* Store settings. */
86
	if (isset($user_item_config['idx'])) {
87
		config_set_path("system/user/{$user_item_config['idx']}", $admin_user);
88
	}
89
	local_user_set($admin_user);
90
	write_config(gettext("Reset admin account from console"));
91

    
92
	echo "\n";
93
	echo gettext('The default administrator account in the User Manager ("admin") has been reset.');
94
	echo "\n";
95
	echo gettext("The password must now be set to a new value.");
96
	echo "\n";
97

    
98
	/* Close before password reset */
99
	fclose($fp);
100
	/* Include the password change script directly as it already handles this step. */
101
	include('/usr/local/bin/usermgrpasswd');
102
} else {
103
	fclose($fp);
104
}
105
echo "\n";
106
?>
(41-41/84)