/** * Log in as a user * * ## OPTIONS * [<email>] * : Email address to log in as. * * [--password=<value>] * : Log in non-interactively with this password. Useful for automation. * * [--machine-token=<value>] * : Authenticate using an Auth0 token * * [--session=<value>] * : Authenticate using an existing session token * [--debug] * : dump call information when logging in. */ public function login($args, $assoc_args) { // Try to login using a machine token, if provided. if (isset($assoc_args['machine-token']) || empty($args) && isset($_SERVER['TERMINUS_MACHINE_TOKEN'])) { if (isset($assoc_args['machine-token'])) { $token = $assoc_args['machine-token']; } elseif (isset($_SERVER['TERMINUS_MACHINE_TOKEN'])) { $token = $_SERVER['TERMINUS_MACHINE_TOKEN']; } $this->auth->logInViaMachineToken($token); } elseif (isset($assoc_args['session'])) { $this->auth->logInViaSessionToken($assoc_args['session']); } else { // Otherwise, do a normal email/password-based login. if (empty($args)) { if (isset($_SERVER['TERMINUS_USER'])) { $email = $_SERVER['TERMINUS_USER']; } else { $email = Input::prompt(array('message' => 'Your email address?')); } } else { $email = $args[0]; } if (isset($assoc_args['password'])) { $password = $assoc_args['password']; } else { $password = Input::promptSecret(array('message' => 'Your dashboard password (input will not be shown)')); } $this->auth->logInViaUsernameAndPassword($email, $password); } $this->log()->debug(get_defined_vars()); Terminus::launchSelf('art', array('fist')); }
/** * Loads a single backup * * @params array $assoc_args Parameters and flags from the command line * @return bool Always true, else the function has thrown an exception */ private function loadBackup($assoc_args) { $assoc_args['to'] = '/tmp'; $assoc_args['element'] = 'database'; if (isset($assoc_args['database'])) { $database = $assoc_args['database']; } else { $database = escapeshellarg(Input::prompt(array('message' => 'Name of database to import to'))); } if (isset($assoc_args['username'])) { $username = $assoc_args['username']; } else { $username = escapeshellarg(Input::prompt(array('message' => 'Username'))); } if (isset($assoc_args['password'])) { $password = $assoc_args['password']; } else { $password = Input::promptSecret(array('message' => 'Your MySQL password (input will not be shown)')); } exec('mysql --version', $stdout, $exit); if ($exit != 0) { $this->failure('MySQL does not appear to be installed on your server.'); } $target = $this->getBackup($assoc_args); $target = '/tmp/' . Utils\getFilenameFromUrl($target); if (!file_exists($target)) { $this->failure('Cannot read database file {target}', compact('target')); } $this->log()->info('Unziping database'); exec("gunzip {$target}", $stdout, $exit); // trim the gz of the target $target = Utils\sqlFromZip($target); $target = escapeshellarg($target); exec(sprintf('mysql %s -u %s -p"%s" < %s', $database, $username, $password, $target), $stdout, $exit); if ($exit != 0) { $this->failure('Could not import database'); } $this->log()->info('{target} successfully imported to {db}', array('target' => $target, 'db' => $database)); return true; }