Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
reset_root_password.php
1 <?php
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);
26 
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";
32  exit();
33 }
34 
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";
39  exit();
40 }
41 
42 require_once $SYSTEM_ROOT.'/core/include/init.inc';
43 
44 // Get the root user
45 $root_user = &$GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
46 // log in as root :P
47 if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
48  echo "ERROR: Failed login in as root user\n";
49  exit();
50 }
51 
52 // try to lock the root user
53 if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($root_user->id, 'attributes')) trigger_error("Couldn't get lock\n", E_USER_ERROR);
54 
55 $current_run_level = $GLOBALS['SQ_SYSTEM']->getRunLevel();
56 $GLOBALS['SQ_SYSTEM']->setRunLevel($current_run_level - SQ_SECURITY_PASSWORD_VALIDATION);
57 
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);
61 
62 $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
63 
64 $GLOBALS['SQ_SYSTEM']->am->releaseLock($root_user->id, 'attributes');
65 
66 echo 'Root User Password now reset to "'.$password.'", please login and change.', "\n";
67 
68 ?>