3 abstract class PhabricatorSSHWorkflow
4 extends PhutilArgumentWorkflow
{
6 // NOTE: We are explicitly extending "PhutilArgumentWorkflow", not
7 // "PhabricatorManagementWorkflow". We want to avoid inheriting "getViewer()"
8 // and other methods which assume workflows are administrative commands
13 private $errorChannel;
14 private $isClusterRequest;
15 private $originalArguments;
16 private $requestIdentifier;
18 public function isExecutable() {
22 public function setErrorChannel(PhutilChannel
$error_channel) {
23 $this->errorChannel
= $error_channel;
27 public function getErrorChannel() {
28 return $this->errorChannel
;
31 public function setSSHUser(PhabricatorUser
$ssh_user) {
32 $this->sshUser
= $ssh_user;
36 public function getSSHUser() {
37 return $this->sshUser
;
40 public function setIOChannel(PhutilChannel
$channel) {
41 $this->iochannel
= $channel;
45 public function getIOChannel() {
46 return $this->iochannel
;
49 public function readAllInput() {
50 $channel = $this->getIOChannel();
51 while ($channel->update()) {
52 PhutilChannel
::waitForAny(array($channel));
53 if (!$channel->isOpenForReading()) {
57 return $channel->read();
60 public function writeIO($data) {
61 $this->getIOChannel()->write($data);
65 public function writeErrorIO($data) {
66 $this->getErrorChannel()->write($data);
70 protected function newPassthruCommand() {
71 return id(new PhabricatorSSHPassthruCommand())
72 ->setErrorChannel($this->getErrorChannel());
75 public function setIsClusterRequest($is_cluster_request) {
76 $this->isClusterRequest
= $is_cluster_request;
80 public function getIsClusterRequest() {
81 return $this->isClusterRequest
;
84 public function setOriginalArguments(array $original_arguments) {
85 $this->originalArguments
= $original_arguments;
89 public function getOriginalArguments() {
90 return $this->originalArguments
;
93 public function setRequestIdentifier($request_identifier) {
94 $this->requestIdentifier
= $request_identifier;
98 public function getRequestIdentifier() {
99 return $this->requestIdentifier
;
102 public function getSSHRemoteAddress() {
103 $ssh_client = getenv('SSH_CLIENT');
104 if (!strlen($ssh_client)) {
108 // TODO: When commands are proxied, the original remote address should
111 // This has the format "<ip> <remote-port> <local-port>". Grab the IP.
112 $remote_address = head(explode(' ', $ssh_client));
115 $address = PhutilIPAddress
::newAddress($remote_address);
116 } catch (Exception
$ex) {
120 return $address->getAddress();