Changeset View
Changeset View
Standalone View
Standalone View
scripts/ssh/ssh-exec.php
| #!/usr/bin/env php | #!/usr/bin/env php | ||||
| <?php | <?php | ||||
| $ssh_start_time = microtime(true); | $ssh_start_time = microtime(true); | ||||
| $root = dirname(dirname(dirname(__FILE__))); | $root = dirname(dirname(dirname(__FILE__))); | ||||
| require_once $root.'/scripts/__init_script__.php'; | require_once $root.'/scripts/__init_script__.php'; | ||||
| $ssh_log = PhabricatorSSHLog::getLog(); | $ssh_log = PhabricatorSSHLog::getLog(); | ||||
| $request_identifier = Filesystem::readRandomCharacters(12); | |||||
| $ssh_log->setData( | |||||
| array( | |||||
| 'Q' => $request_identifier, | |||||
| )); | |||||
| $args = new PhutilArgumentParser($argv); | $args = new PhutilArgumentParser($argv); | ||||
| $args->setTagline(pht('execute SSH requests')); | $args->setTagline(pht('execute SSH requests')); | ||||
| $args->setSynopsis(<<<EOSYNOPSIS | $args->setSynopsis(<<<EOSYNOPSIS | ||||
| **ssh-exec** --phabricator-ssh-user __user__ [--ssh-command __commmand__] | **ssh-exec** --phabricator-ssh-user __user__ [--ssh-command __commmand__] | ||||
| **ssh-exec** --phabricator-ssh-device __device__ [--ssh-command __commmand__] | **ssh-exec** --phabricator-ssh-device __device__ [--ssh-command __commmand__] | ||||
| Execute authenticated SSH requests. This script is normally invoked | Execute authenticated SSH requests. This script is normally invoked | ||||
| via SSHD, but can be invoked manually for testing. | via SSHD, but can be invoked manually for testing. | ||||
| ▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | try { | ||||
| if (empty($workflows[$command])) { | if (empty($workflows[$command])) { | ||||
| throw new Exception(pht('Invalid command.')); | throw new Exception(pht('Invalid command.')); | ||||
| } | } | ||||
| $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); | |||||
| $sock_stdin = fopen('php://stdin', 'r'); | $sock_stdin = fopen('php://stdin', 'r'); | ||||
| if (!$sock_stdin) { | if (!$sock_stdin) { | ||||
| throw new Exception(pht('Unable to open stdin.')); | throw new Exception(pht('Unable to open stdin.')); | ||||
| } | } | ||||
| $sock_stdout = fopen('php://stdout', 'w'); | $sock_stdout = fopen('php://stdout', 'w'); | ||||
| if (!$sock_stdout) { | if (!$sock_stdout) { | ||||
| ▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines | |||||