Changeset View
Changeset View
Standalone View
Standalone View
scripts/ssh/ssh-exec.php
| Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | if (!$device) { | ||||
| } | } | ||||
| } | } | ||||
| $workflows = id(new PhutilClassMapQuery()) | $workflows = id(new PhutilClassMapQuery()) | ||||
| ->setAncestorClass('PhabricatorSSHWorkflow') | ->setAncestorClass('PhabricatorSSHWorkflow') | ||||
| ->setUniqueMethod('getName') | ->setUniqueMethod('getName') | ||||
| ->execute(); | ->execute(); | ||||
| $command_list = array_keys($workflows); | |||||
| $command_list = implode(', ', $command_list); | |||||
| $error_lines = array(); | |||||
| $error_lines[] = pht('Welcome to Phabricator.'); | |||||
| $error_lines[] = pht( | |||||
| 'You are logged in as %s.', | |||||
| $user_name); | |||||
| if (!$original_argv) { | if (!$original_argv) { | ||||
| throw new Exception( | $error_lines[] = pht( | ||||
| pht( | 'You have not specified a command to run. This means you are requesting '. | ||||
| "Welcome to Phabricator.\n\n". | 'an interactive shell, but Phabricator does not provide interactive '. | ||||
| "You are logged in as %s.\n\n". | 'shells over SSH.'); | ||||
| "You haven't specified a command to run. This means you're requesting ". | $error_lines[] = pht( | ||||
| "an interactive shell, but Phabricator does not provide an ". | '(Usually, you should run a command like "git clone" or "hg push" '. | ||||
| "interactive shell over SSH.\n\n". | 'instead of connecting directly with SSH.)'); | ||||
| "Usually, you should run a command like `%s` or `%s` ". | $error_lines[] = pht( | ||||
| "rather than connecting directly with SSH.\n\n". | 'Supported commands are: %s.', | ||||
| "Supported commands are: %s.", | $command_list); | ||||
| $user_name, | |||||
| 'git clone', | $error_lines = implode("\n\n", $error_lines); | ||||
| 'hg push', | throw new PhutilArgumentUsageException($error_lines); | ||||
| implode(', ', array_keys($workflows)))); | |||||
| } | } | ||||
| $log_argv = implode(' ', $original_argv); | $log_argv = implode(' ', $original_argv); | ||||
| $log_argv = id(new PhutilUTF8StringTruncator()) | $log_argv = id(new PhutilUTF8StringTruncator()) | ||||
| ->setMaximumCodepoints(128) | ->setMaximumCodepoints(128) | ||||
| ->truncateString($log_argv); | ->truncateString($log_argv); | ||||
| $ssh_log->setData( | $ssh_log->setData( | ||||
| array( | array( | ||||
| 'C' => $original_argv[0], | 'C' => $original_argv[0], | ||||
| 'U' => $log_argv, | 'U' => $log_argv, | ||||
| )); | )); | ||||
| $command = head($original_argv); | $command = head($original_argv); | ||||
| $parseable_argv = $original_argv; | $parseable_argv = $original_argv; | ||||
| array_unshift($parseable_argv, 'phabricator-ssh-exec'); | array_unshift($parseable_argv, 'phabricator-ssh-exec'); | ||||
| $parsed_args = new PhutilArgumentParser($parseable_argv); | $parsed_args = new PhutilArgumentParser($parseable_argv); | ||||
| if (empty($workflows[$command])) { | if (empty($workflows[$command])) { | ||||
| throw new Exception(pht('Invalid command.')); | $error_lines[] = pht( | ||||
| 'You have specified the command "%s", but that command is not '. | |||||
| 'supported by Phabricator. As received by Phabricator, your entire '. | |||||
| 'argument list was:', | |||||
| $command); | |||||
| $error_lines[] = csprintf(' $ ssh ... -- %Ls', $parseable_argv); | |||||
| $error_lines[] = pht( | |||||
| 'Supported commands are: %s.', | |||||
| $command_list); | |||||
| $error_lines = implode("\n\n", $error_lines); | |||||
| throw new PhutilArgumentUsageException($error_lines); | |||||
| } | } | ||||
| $workflow = $parsed_args->parseWorkflows($workflows); | $workflow = $parsed_args->parseWorkflows($workflows); | ||||
| $workflow->setSSHUser($user); | $workflow->setSSHUser($user); | ||||
| $workflow->setOriginalArguments($original_argv); | $workflow->setOriginalArguments($original_argv); | ||||
| $workflow->setIsClusterRequest($is_cluster_request); | $workflow->setIsClusterRequest($is_cluster_request); | ||||
| $workflow->setRequestIdentifier($request_identifier); | $workflow->setRequestIdentifier($request_identifier); | ||||
| ▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines | |||||