24 error_reporting(E_ALL);
25 if ((php_sapi_name() !=
'cli')) trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
27 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
28 if (empty($SYSTEM_ROOT)) {
29 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
30 echo
'Usage: '.basename(__FILE__).
" SYSTEM_ROOT [NEW_PASSWORD]\n\n";
31 echo
" If NEW_PASSWORD is not provided, it will be reset to 'root'\n";
35 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
36 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
37 echo
'Usage: '.basename(__FILE__).
" SYSTEM_ROOT [NEW_PASSWORD]\n\n";
38 echo
" If NEW_PASSWORD is not provided, it will be reset to 'root'\n";
42 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
45 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
47 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
48 echo
"ERROR: Failed login in as root user\n";
53 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($root_user->id,
'attributes')) trigger_error(
"Couldn't get lock\n", E_USER_ERROR);
55 $current_run_level = $GLOBALS[
'SQ_SYSTEM']->getRunLevel();
56 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($current_run_level - SQ_SECURITY_PASSWORD_VALIDATION);
58 $password = array_get_index($argv, 2,
'root');
59 if (!$root_user->setAttrValue(
'password', $password)) trigger_error(
"Couldn't set password\n", E_USER_ERROR);
60 if (!$root_user->saveAttributes()) trigger_error(
"Couldn't save attributes \n", E_USER_ERROR);
62 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
64 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($root_user->id,
'attributes');
66 echo
'Root User Password now reset to "'.$password.
'", please login and change.',
"\n";