Project

General

Profile

Download (4.59 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
 * Redistribution and use in source and binary forms, with or without
15
 * modification, are permitted provided that the following conditions are met:
16
 *
17
 * 1. Redistributions of source code must retain the above copyright notice,
18
 *    this list of conditions and the following disclaimer.
19
 *
20
 * 2. Redistributions in binary form must reproduce the above copyright
21
 *    notice, this list of conditions and the following disclaimer in
22
 *    the documentation and/or other materials provided with the
23
 *    distribution.
24
 *
25
 * 3. All advertising materials mentioning features or use of this software
26
 *    must display the following acknowledgment:
27
 *    "This product includes software developed by the pfSense Project
28
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
29
 *
30
 * 4. The names "pfSense" and "pfSense Project" must not be used to
31
 *    endorse or promote products derived from this software without
32
 *    prior written permission. For written permission, please contact
33
 *    coreteam@pfsense.org.
34
 *
35
 * 5. Products derived from this software may not be called "pfSense"
36
 *    nor may "pfSense" appear in their names without prior written
37
 *    permission of the Electric Sheep Fencing, LLC.
38
 *
39
 * 6. Redistributions of any form whatsoever must retain the following
40
 *    acknowledgment:
41
 *
42
 * "This product includes software developed by the pfSense Project
43
 * for use in the pfSense software distribution (http://www.pfsense.org/).
44
 *
45
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
46
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
49
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
54
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
56
 * OF THE POSSIBILITY OF SUCH DAMAGE.
57
 */
58

    
59
	/* parse the configuration and include all functions used below */
60

    
61
	require_once("config.inc");
62
	require_once("auth.inc");
63
	require_once("functions.inc");
64
	require_once("shaper.inc");
65

    
66
	$fp = fopen('php://stdin', 'r');
67

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

    
72
	if (strcasecmp(chop(fgets($fp)), "y") == 0) {
73
		if (isset($config['system']['webgui']['authmode']) &&
74
		    $config['system']['webgui']['authmode'] != "Local Database") {
75
			echo "\n" . gettext('
76
The User manager authentication server is set to "' . $config['system']['webgui']['authmode'] . '".') . "\n" .
77
			gettext('Do you want to set it back to Local Database [y|n]?') . " ";
78
			if (strcasecmp(chop(fgets($fp)), "y") == 0) {
79
				$config['system']['webgui']['authmode'] = "Local Database";
80
			}
81
		}
82
		$admin_user =& getUserEntryByUID(0);
83
		if (!$admin_user) {
84
			echo "Failed to locate the admin user account! Attempting to restore access.\n";
85
			$admin_user = array();
86
			$admin_user['uid'] = 0;
87
			if (!is_array($config['system']['user'])) {
88
				$config['system']['user'] = array();
89
			}
90
			$config['system']['user'][] = $admin_user;
91
			$admin_user =& getUserEntryByUID(0);
92
		}
93

    
94
		$admin_user['name'] = "admin";
95
		$admin_user['scope'] = "system";
96
		$admin_user['priv'] = array("user-shell-access");
97

    
98
		if (isset($admin_user['disabled'])) {
99
			unset($admin_user['disabled']);
100
		}
101

    
102
		if (isset($admin_user['expires'])) {
103
			unset($admin_user['expires']);
104
		}
105

    
106
		local_user_set_password($admin_user, strtolower($g['product_name']));
107
		local_user_set($admin_user);
108
		write_config(gettext("password changed from console menu"));
109

    
110
		echo "\n" . gettext('
111
The password for the webConfigurator has been reset and
112
the default username has been set to "admin".') . "\n" .
113
		gettext('
114
Remember to set the password to something else than
115
the default as soon as you have logged into the webConfigurator.') . "\n" .
116
		gettext("Press ENTER to continue.");
117

    
118
		fgets($fp);
119
	}
120
?>
(51-51/95)