Changeset View
Changeset View
Standalone View
Standalone View
scripts/ssh/ssh-exec.php
| Show All 26 Lines | array( | ||||
| 'name' => 'ssh-command', | 'name' => 'ssh-command', | ||||
| 'param' => 'command', | 'param' => 'command', | ||||
| ), | ), | ||||
| )); | )); | ||||
| try { | try { | ||||
| $user_name = $args->getArg('phabricator-ssh-user'); | $user_name = $args->getArg('phabricator-ssh-user'); | ||||
| if (!strlen($user_name)) { | if (!strlen($user_name)) { | ||||
| throw new Exception("No username."); | throw new Exception('No username.'); | ||||
| } | } | ||||
| $user = id(new PhabricatorUser())->loadOneWhere( | $user = id(new PhabricatorUser())->loadOneWhere( | ||||
| 'userName = %s', | 'userName = %s', | ||||
| $user_name); | $user_name); | ||||
| if (!$user) { | if (!$user) { | ||||
| throw new Exception("Invalid username."); | throw new Exception('Invalid username.'); | ||||
| } | } | ||||
| $ssh_log->setData( | $ssh_log->setData( | ||||
| array( | array( | ||||
| 'u' => $user->getUsername(), | 'u' => $user->getUsername(), | ||||
| 'P' => $user->getPHID(), | 'P' => $user->getPHID(), | ||||
| )); | )); | ||||
| if (!$user->isUserActivated()) { | if (!$user->isUserActivated()) { | ||||
| throw new Exception(pht("Your account is not activated.")); | throw new Exception(pht('Your account is not activated.')); | ||||
| } | } | ||||
| if ($args->getArg('ssh-command')) { | if ($args->getArg('ssh-command')) { | ||||
| $original_command = $args->getArg('ssh-command'); | $original_command = $args->getArg('ssh-command'); | ||||
| } else { | } else { | ||||
| $original_command = getenv('SSH_ORIGINAL_COMMAND'); | $original_command = getenv('SSH_ORIGINAL_COMMAND'); | ||||
| } | } | ||||
| Show All 30 Lines | $ssh_log->setData( | ||||
| )); | )); | ||||
| $command = head($original_argv); | $command = head($original_argv); | ||||
| array_unshift($original_argv, 'phabricator-ssh-exec'); | array_unshift($original_argv, 'phabricator-ssh-exec'); | ||||
| $original_args = new PhutilArgumentParser($original_argv); | $original_args = new PhutilArgumentParser($original_argv); | ||||
| if (empty($workflow_names[$command])) { | if (empty($workflow_names[$command])) { | ||||
| throw new Exception("Invalid command."); | throw new Exception('Invalid command.'); | ||||
| } | } | ||||
| $workflow = $original_args->parseWorkflows($workflows); | $workflow = $original_args->parseWorkflows($workflows); | ||||
| $workflow->setUser($user); | $workflow->setUser($user); | ||||
| $sock_stdin = fopen('php://stdin', 'r'); | $sock_stdin = fopen('php://stdin', 'r'); | ||||
| if (!$sock_stdin) { | if (!$sock_stdin) { | ||||
| throw new Exception("Unable to open stdin."); | throw new Exception('Unable to open stdin.'); | ||||
| } | } | ||||
| $sock_stdout = fopen('php://stdout', 'w'); | $sock_stdout = fopen('php://stdout', 'w'); | ||||
| if (!$sock_stdout) { | if (!$sock_stdout) { | ||||
| throw new Exception("Unable to open stdout."); | throw new Exception('Unable to open stdout.'); | ||||
| } | } | ||||
| $sock_stderr = fopen('php://stderr', 'w'); | $sock_stderr = fopen('php://stderr', 'w'); | ||||
| if (!$sock_stderr) { | if (!$sock_stderr) { | ||||
| throw new Exception("Unable to open stderr."); | throw new Exception('Unable to open stderr.'); | ||||
| } | } | ||||
| $socket_channel = new PhutilSocketChannel( | $socket_channel = new PhutilSocketChannel( | ||||
| $sock_stdin, | $sock_stdin, | ||||
| $sock_stdout); | $sock_stdout); | ||||
| $error_channel = new PhutilSocketChannel(null, $sock_stderr); | $error_channel = new PhutilSocketChannel(null, $sock_stderr); | ||||
| $metrics_channel = new PhutilMetricsChannel($socket_channel); | $metrics_channel = new PhutilMetricsChannel($socket_channel); | ||||
| $workflow->setIOChannel($metrics_channel); | $workflow->setIOChannel($metrics_channel); | ||||
| Show All 34 Lines | |||||