Ferreteria/v0.6/clade/IO/Aspect/Connx/run/Starter/Remote/SSH2/@removed
Jump to navigation
Jump to search
|
Removed Code
|
2026-04-03
Commented out yesterday:
#
// ++ ACTION ++ //
// 2026-04-02 This is old, and probably not very rescuable.
public function DoCommand(CLineIface &$oCmd) : OpCmdIface {
#$oCmd->QORunner()->SetIt($this);
#$this->Open(); // make sure connection is open (sets RNative())
$oSess = ($this->SessionClass())::FromCommand($oCmd);
$oHints = $oCmd->Hints();
#$sEndHint = $oHints->GetItNz('eos',NULL);
#$useEmpty = ($sEndHint === 'empty'); // TODO 2026-03-24: I think this needs to go away
$oOpCmd = $this->OOpCmd();
$oOpCmd->Clear();
$oProcLecture = $this->StreamFromCommmand($oCmd);
$oProcLecture->UseEoS(!$useEmpty);
$this->LectureStream($oProcLecture);
$ok = is_object($oProcLecture);
$oOpCmd->SetOkay($ok);
if ($ok) {
$oCanals = CanalsClass::FromVoid();
$qoCmdListen = $oCmd->QOListener(); // stream to receive data
if ($qoCmdListen->HasIt()) {
$oCodeListen = $qoCmdListen->GetIt();
$oCanalRecv = ConveyClass::FromPair($oProcLecture,$oCodeListen);
$oCanals->AddIt($oCanalRecv);
} else {
stream_set_blocking($rRecv, TRUE); // wait for entire output when reading
$oItWent = $oLecture->PullBytes();
#echo '** OUTCOME: '.CRLF.$oItWent->VIEW_AsBlock();
}
$this->OCanals($oCanals); // make the Canals object publicly available
$oOpConvey = NULL;
}
#$this->Shut(); // done with connection for now
return $oOpCmd;
}
protected function StreamFromCommmand(CLineIface $oCmd) : ?StrmExecIface {
$rExec = $this->RNative(); // This is the ssh2 session/process resource (not a stream).
$rRecv = ssh2_exec($rExec, $oCmd->AsString());
if (is_resource($rRecv)) {
$oStream = StrmExecClass::FromNative($rRecv,'exec');
#$doWait = $oCmd->DoWait();
#$doWait = TRUE; // 2026-03-03 for now, to replicate old behavior -- but this line should go away
$doWait = $oCmd->HasIt();
stream_set_blocking($rRecv, $doWait);
} else {
$oStream = NULL;
}
return $oStream;
}
// -- ACTION -- //
// ++ LIFECYCLE ++ //
// With ssh, we open (start) a connection (Session), and *then* send commands.
// This part creates a Session object for the connection... I think? Session object returned in the Op object?
protected function ActualOpen() : OpOpenIface {
$oAct = $this->OpOpen();
}
protected function ActualShut() : OpShutIface {
$rConn = $this->RNative();
$ok = TRUE; //ssh2_disconnect($rConn);
$oAct = $this->OpShut();
$oAct->SetOkay($ok);
echo 'CLOSED ssh connection'.CRLF;
return $oAct;
}
// -- LIFECYCLE -- //
2026-03-24
#
// 2026-02-09 moved here from Native/File/Generic
// 2026-03-03 I *think* this is kinda the wrong way.
public function PushBytes(string $s) : OpDataIface {
$ok = fwrite($this->QNative()->GetIt(),$s); // try to send it
// 2026-01-17 fwrite() supposedly works on non-file streams too.
$oOp = $this->OOpData();
$oOp->SetOkay($ok);
return $oOp;
}
2026-01-09
Commented out yesterday:
#
// 2026-01-08 Does anything use this anymore?
public function RunProcess(CmdLineIface $oCmd) : ProcIface {
$oCmdFull = $this->WrapCommand($oCmd);
return parent::RunProcess($oCmdFull);
}
// -- ACTION -- //
// ++ FIGURING ++ //
// 2026-01-08 ACTUALLY NO -- just use ssh2_exec() or ssh2_connect(), hey?
protected function WrapCommand(CmdLineIface $oCmd) : CmdLineIface {
// [+STANDARD CODE]: get connection specs
$oCred = $this->OCred();
$oSock = $this->OSock();
$oHost = $oSock->OHost();
$sUser = $oCred->QSUser()->GetIt();
$sHost = $oHost->QSAddr()->GetIt();
$onPort = $oHost->QIPort();
// [-STANDARD CODE]
$oCmdPfx = $oCmd->SpawnBlank();
$oCmdPfx->AddString('ssh');
if ($onPort->HasIt()) {
$nPort = $onPort->GetIt();
#$sPort = ' -p '.$nPort;
$oCmdPfx->AddArray(['-p',$nPort]);
}
$oCmdPfx->AddString("$sUser@$sHost");
$oCmd->EmbedWithin($oCmdPfx);
return $oCmd;
}
2026-01-08
Commented out yesterday:
#
// 2026-01-07 old API v2
public function DoCommand(string|array $saCmd, StreamIface $oResps) : CommOpIface {
$sCmdFull = $this->WrapCommand($saCmd);
return parent::DoCommand($sCmdFull,$oResps);
}
#
// 2026-01-07 old API
// 2025-03-29 FUTURE: maybe this should always return an array -- but that's harder to debug.
protected function WrapCommand(string|array $saCmd) : string {
// [+STANDARD CODE]: get connection specs
$oCred = $this->OCred();
$oSock = $this->OSock();
$oHost = $oSock->OHost();
$sUser = $oCred->QSUser()->GetIt();
$sHost = $oHost->QSAddr()->GetIt();
$onPort = $oHost->QIPort();
// [-STANDARD CODE]
if ($onPort->HasIt()) {
$nPort = $onPort->GetIt();
$sPort = ' -p '.$nPort;
} else {
$sPort = '';
}
$sCmdSafe = escapeshellarg($saCmd);
$sCmdFull = "ssh$sPort $sUser@$sHost $sCmdSafe";
return $sCmdFull;
}
#
// 2026-01-07 old API
public function RunProcess(string|array $saCmd) : ProcIface {
$sCmdFull = $this->WrapCommand($saCmd);
return parent::RunProcess($sCmdFull);
}
#
// 2025-12-28 old API v1
public function DoCommand(string|array $saCmd, StreamIface $oResps, ?CommOpIface $oAct=NULL) : CommOpIface {
$sCmdFull = $this->WrapCommand($saCmd);
$oAct = parent::DoCommand($sCmdFull,$oResps,$oAct);
return $oAct;
}
2025-12-04
Commented out from DoCommand() earlier:
#
$oAct = $this->NewAction();
$oCreds = $this->Creds();
$sHost = $oCreds->QHost()->GetIt();
$sUser = $oCreds->QUser()->GetIt();
$sPort = $oCreds->QPort()->GetStrNz('',' -p ');
$sCmdSafe = escapeshellarg($sCmd);
$sCmdFull = "ssh$sPort $sUser@$sHost $sCmdSafe";
2025-06-03
#
// 2025-05-28 old
public function __construct(private CredsIface $oCreds) {
$oCreds->QPort()->SetDefault(22); // SSH default port
}
public function Creds() : CredsIface { return $this->oCreds; }
2024-12-03
It looks like this was moved to ../Opener.php:
#
private int $nOpens = 0;
public function Open() : ActionIface {
$nOpens = $this->nOpens++;
if ($nOpens == 0) {
$oAct = $this->ActualOpen();
} else {
$oAct = new ActionIface();
$oAct->SetNoOp();
}
return $oAct;
}
public function Shut() : ActionIface {
$nOpens = --$this->nOpens;
if ($nOpens == 0) {
$oAct = $this->ActualShut();
} else {
$oAct = new ActionIface();
$oAct->SetNoOp();
}
return $oAct;
}
2024-11-27
This never worked anyway -- gives a "Segmentation fault (core dumped)" error -- but that's ok, because ssh2_auth_agent() was the one I wanted to use anyway. I only tried this when that wasn't working (which turned out to be because you have to explicitly add keys to the SSH Agent).
This was in Open(), in place of the ssh2_auth_agent() call:
#
$ok = ssh2_auth_pubkey_file($rSSH,$sUser,'/home/woozle/.ssh/id_ed25519.pub','/home/woozle/.ssh/id_ed25519');