Remove product literal strings in "pht()", part 18
[phabricator.git] / src / infrastructure / ssh / PhabricatorSSHWorkflow.php
blobf7739f13327cd229764ffafd98d8306b0b306b6c
1 <?php
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
9 // like `bin/storage`.
11 private $sshUser;
12 private $iochannel;
13 private $errorChannel;
14 private $isClusterRequest;
15 private $originalArguments;
16 private $requestIdentifier;
18 public function isExecutable() {
19 return false;
22 public function setErrorChannel(PhutilChannel $error_channel) {
23 $this->errorChannel = $error_channel;
24 return $this;
27 public function getErrorChannel() {
28 return $this->errorChannel;
31 public function setSSHUser(PhabricatorUser $ssh_user) {
32 $this->sshUser = $ssh_user;
33 return $this;
36 public function getSSHUser() {
37 return $this->sshUser;
40 public function setIOChannel(PhutilChannel $channel) {
41 $this->iochannel = $channel;
42 return $this;
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()) {
54 break;
57 return $channel->read();
60 public function writeIO($data) {
61 $this->getIOChannel()->write($data);
62 return $this;
65 public function writeErrorIO($data) {
66 $this->getErrorChannel()->write($data);
67 return $this;
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;
77 return $this;
80 public function getIsClusterRequest() {
81 return $this->isClusterRequest;
84 public function setOriginalArguments(array $original_arguments) {
85 $this->originalArguments = $original_arguments;
86 return $this;
89 public function getOriginalArguments() {
90 return $this->originalArguments;
93 public function setRequestIdentifier($request_identifier) {
94 $this->requestIdentifier = $request_identifier;
95 return $this;
98 public function getRequestIdentifier() {
99 return $this->requestIdentifier;
102 public function getSSHRemoteAddress() {
103 $ssh_client = getenv('SSH_CLIENT');
104 if (!strlen($ssh_client)) {
105 return null;
108 // TODO: When commands are proxied, the original remote address should
109 // also be proxied.
111 // This has the format "<ip> <remote-port> <local-port>". Grab the IP.
112 $remote_address = head(explode(' ', $ssh_client));
114 try {
115 $address = PhutilIPAddress::newAddress($remote_address);
116 } catch (Exception $ex) {
117 return null;
120 return $address->getAddress();