Project

General

Profile

Download (3.02 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-2021 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" . gettext('
39
The webConfigurator admin password and privileges will be reset to the default (which is "' . strtolower($g['product_name']) . '").') . "\n" .
40
	gettext('Do you want to proceed [y|n]?') . " ";
41

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

    
64
		$admin_user['name'] = "admin";
65
		$admin_user['scope'] = "system";
66
		$admin_user['priv'] = array("user-shell-access");
67

    
68
		if (isset($admin_user['disabled'])) {
69
			unset($admin_user['disabled']);
70
		}
71

    
72
		if (isset($admin_user['expires'])) {
73
			unset($admin_user['expires']);
74
		}
75

    
76
		local_user_set_password($admin_user, strtolower($g['product_name']));
77
		local_user_set($admin_user);
78
		write_config(gettext("password changed from console menu"));
79

    
80
		echo "\n" . gettext('
81
The password for the webConfigurator has been reset and
82
the default username has been set to "admin".') . "\n" .
83
		gettext('
84
Remember to set the password to something else than
85
the default as soon as you have logged into the webConfigurator.') . "\n" .
86
		gettext("Press ENTER to continue.");
87

    
88
		fgets($fp);
89
	}
90
?>
(40-40/82)