Path: blob/master/src/infrastructure/ssh/PhabricatorSSHWorkflow.php
12241 views
<?php12abstract class PhabricatorSSHWorkflow3extends PhutilArgumentWorkflow {45// NOTE: We are explicitly extending "PhutilArgumentWorkflow", not6// "PhabricatorManagementWorkflow". We want to avoid inheriting "getViewer()"7// and other methods which assume workflows are administrative commands8// like `bin/storage`.910private $sshUser;11private $iochannel;12private $errorChannel;13private $isClusterRequest;14private $originalArguments;15private $requestIdentifier;1617public function isExecutable() {18return false;19}2021public function setErrorChannel(PhutilChannel $error_channel) {22$this->errorChannel = $error_channel;23return $this;24}2526public function getErrorChannel() {27return $this->errorChannel;28}2930public function setSSHUser(PhabricatorUser $ssh_user) {31$this->sshUser = $ssh_user;32return $this;33}3435public function getSSHUser() {36return $this->sshUser;37}3839public function setIOChannel(PhutilChannel $channel) {40$this->iochannel = $channel;41return $this;42}4344public function getIOChannel() {45return $this->iochannel;46}4748public function readAllInput() {49$channel = $this->getIOChannel();50while ($channel->update()) {51PhutilChannel::waitForAny(array($channel));52if (!$channel->isOpenForReading()) {53break;54}55}56return $channel->read();57}5859public function writeIO($data) {60$this->getIOChannel()->write($data);61return $this;62}6364public function writeErrorIO($data) {65$this->getErrorChannel()->write($data);66return $this;67}6869protected function newPassthruCommand() {70return id(new PhabricatorSSHPassthruCommand())71->setErrorChannel($this->getErrorChannel());72}7374public function setIsClusterRequest($is_cluster_request) {75$this->isClusterRequest = $is_cluster_request;76return $this;77}7879public function getIsClusterRequest() {80return $this->isClusterRequest;81}8283public function setOriginalArguments(array $original_arguments) {84$this->originalArguments = $original_arguments;85return $this;86}8788public function getOriginalArguments() {89return $this->originalArguments;90}9192public function setRequestIdentifier($request_identifier) {93$this->requestIdentifier = $request_identifier;94return $this;95}9697public function getRequestIdentifier() {98return $this->requestIdentifier;99}100101public function getSSHRemoteAddress() {102$ssh_client = getenv('SSH_CLIENT');103if (!strlen($ssh_client)) {104return null;105}106107// TODO: When commands are proxied, the original remote address should108// also be proxied.109110// This has the format "<ip> <remote-port> <local-port>". Grab the IP.111$remote_address = head(explode(' ', $ssh_client));112113try {114$address = PhutilIPAddress::newAddress($remote_address);115} catch (Exception $ex) {116return null;117}118119return $address->getAddress();120}121122}123124125