📄 sbindysshserveriohandler9.pas
字号:
end;
function TElIdSSHClientServerIOHandler.GetForceCompression: boolean;
begin
Result := FSSHServer.ForceCompression;
end;
function TElIdSSHClientServerIOHandler.GetKexAlgorithm: TSSHKexAlgorithm;
begin
Result := FSSHServer.KexAlgorithm;
end;
function TElIdSSHClientServerIOHandler.GetKexAlgorithms(
Index: TSSHKexAlgorithm): boolean;
begin
Result := FSSHServer.KexAlgorithms[Index];
end;
function TElIdSSHClientServerIOHandler.GetKeyStorage: TElSSHCustomKeyStorage;
begin
Result := FSSHServer.KeyStorage;
end;
function TElIdSSHClientServerIOHandler.GetMacAlgorithmCS: TSSHMacAlgorithm;
begin
Result := FSSHServer.MacAlgorithmClientToServer;
end;
function TElIdSSHClientServerIOHandler.GetMACAlgorithms(
Index: TSSHMacAlgorithm): boolean;
begin
Result := FSSHServer.MacAlgorithms[Index];
end;
function TElIdSSHClientServerIOHandler.GetMacAlgorithmSC: TSSHMacAlgorithm;
begin
Result := FSSHServer.MacAlgorithmServerToClient;
end;
function TElIdSSHClientServerIOHandler.GetPublicKeyAlgorithm: TSSHPublicKeyAlgorithm;
begin
Result := FSSHServer.PublicKeyAlgorithm;
end;
function TElIdSSHClientServerIOHandler.GetPublicKeyAlgorithms(
Index: TSSHPublicKeyAlgorithm): boolean;
begin
Result := FSSHServer.PublicKeyAlgorithms[Index];
end;
function TElIdSSHClientServerIOHandler.GetSoftwareName: string;
begin
Result := FSSHServer.SoftwareName;
end;
procedure TElIdSSHClientServerIOHandler.SetAuthenticationTypes(
const Value: integer);
begin
FSSHServer.AuthenticationTypes := Value;
end;
procedure TElIdSSHClientServerIOHandler.SetCloseIfNoActiveTunnels(
const Value: boolean);
begin
FSSHServer.CloseIfNoActiveTunnels := Value;
end;
procedure TElIdSSHClientServerIOHandler.SetCompressionAlgorithms(
Index: TSSHCompressionAlgorithm; const Value: boolean);
begin
FSSHServer.CompressionAlgorithms[Index] := Value;
end;
procedure TElIdSSHClientServerIOHandler.SetCompressionLevel(
const Value: integer);
begin
FSSHServer.CompressionLevel := Value;
end;
procedure TElIdSSHClientServerIOHandler.SetEncryptionAlgorithms(
Index: TSSHEncryptionAlgorithm; const Value: boolean);
begin
FSSHServer.EncryptionAlgorithms[Index] := Value;
end;
procedure TElIdSSHClientServerIOHandler.SetForceCompression(
const Value: boolean);
begin
FSSHServer.ForceCompression := Value;
end;
procedure TElIdSSHClientServerIOHandler.SetKexAlgorithms(
Index: TSSHKexAlgorithm; const Value: boolean);
begin
FSSHServer.KexAlgorithms[Index] := Value;
end;
procedure TElIdSSHClientServerIOHandler.SetKeyStorage(
const Value: TElSSHCustomKeyStorage);
begin
FSSHServer.KeyStorage := Value;
end;
procedure TElIdSSHClientServerIOHandler.SetMACAlgorithms(
Index: TSSHMacAlgorithm; const Value: boolean);
begin
FSSHServer.MacAlgorithms[Index] := Value;
end;
procedure TElIdSSHClientServerIOHandler.SetPublicKeyAlgorithms(
Index: TSSHPublicKeyAlgorithm; const Value: boolean);
begin
FSSHServer.PublicKeyAlgorithms[Index] := Value;
end;
procedure TElIdSSHClientServerIOHandler.SetSoftwareName(
const Value: string);
begin
FSSHServer.SoftwareName := Value;
end;
function TElIdSSHClientServerIOHandler.GetConnectionCount: integer;
begin
Result := FConnections.Count;
end;
procedure TElIdSSHClientServerIOHandler.DoCloseConnection(Sender: TObject);
begin
if FActive then
Close;
if Assigned(FOnCloseConnection) then
FOnCloseConnection(Sender);
end;
function TElIdSSHClientServerIOHandler.GetOnOpenConnection: TSSHOpenConnectionEvent;
begin
Result := FSSHServer.OnOpenConnection;
end;
procedure TElIdSSHClientServerIOHandler.SetOnOpenConnection(
const Value: TSSHOpenConnectionEvent);
begin
FSSHServer.OnOpenConnection := Value;
end;
{ TElIdSSHConnectionIOHandler }
constructor TElIdSSHConnectionIOHandler.Create;
begin
inherited ;
FErrorOccured := false;
FActive := false;
FSSHServer := nil;
FTunnelConnection := nil;
FInputBuffer := TIdManagedBuffer.Create;
end;
procedure TElIdSSHConnectionIOHandler.Close;
begin
if Assigned(FTunnelConnection) and FActive then
begin
FActive := false;
FTunnelConnection.Close;
FTunnelConnection := nil;
end;
inherited;
end;
function TElIdSSHConnectionIOHandler.Connected: boolean;
begin
Result := FActive;
end;
destructor TElIdSSHConnectionIOHandler.Destroy;
begin
Close;
FreeAndNil(FInputBuffer);
inherited;
end;
procedure TElIdSSHConnectionIOHandler.DoOnClose(Sender: TObject;
CloseType: TSSHCloseType);
begin
FActive := false;
FTunnelConnection := nil;
end;
procedure TElIdSSHConnectionIOHandler.DoOnData(Sender: TObject;
Buffer: pointer; Size: Integer);
begin
if Size > 0 then
begin
FInputBuffer.Seek(0, soFromEnd);
FInputBuffer.Write(Buffer^, Size);
end;
end;
procedure TElIdSSHConnectionIOHandler.DoOnError(Sender: TObject;
ErrorCode: integer);
begin
FErrorOccured := true;
end;
procedure TElIdSSHConnectionIOHandler.SetConnection(
ATunnelConnection: TElSSHTunnelConnection; ASSHServer : TElSSHServer);
begin
if (FTunnelConnection = nil) and Assigned(ATunnelConnection)
and Assigned(ASSHServer)
then
begin
FTunnelConnection := ATunnelConnection;
FTunnelConnection.OnData := DoOnData;
FTunnelConnection.OnError := DoOnError;
FTunnelConnection.OnClose := DoOnClose;
FSSHServer := ASSHServer;
FSSHServer.FreeNotification(Self);
FActive := true;
end;
end;
function TElIdSSHConnectionIOHandler.Readable(AMSec: Integer): boolean;
function CheckIsReadable(AMSec: Integer): Boolean;
begin
Result := false;
if (not Assigned(FTunnelConnection)) or (not Active) then
Exit;
Result := FInputBuffer.Size > 0;
if not Result then
begin
if AMSec = IdTimeoutDefault then AMSec := ID_Default_TIdAntiFreezeBase_IdleTimeOut;
if AMSec = IdTimeoutInfinite then
begin
repeat
TIdAntiFreezeBase.Sleep(ID_Default_TIdAntiFreezeBase_IdleTimeOut);
if (not Assigned(FTunnelConnection)) or (not Active) then
Exit;
//raise EIdConnClosedGracefully.Create(SConnectionClosed);
FSSHServer.DataAvailable;
Result := FInputBuffer.Size > 0;
TIdAntiFreezeBase.DoProcess(Result = False);
until Result;
end
else
begin
TIdAntiFreezeBase.Sleep(AMSec);
FSSHServer.DataAvailable;
Result := FInputBuffer.Size > 0;
TIdAntiFreezeBase.DoProcess(Result = False);
end;
end;
end;
begin
if TIdAntiFreezeBase.ShouldUse then begin
if AMSec = IdTimeoutInfinite then begin
repeat
Result := CheckIsReadable(GAntiFreeze.IdleTimeOut);
until Result;
Exit;
end else if AMSec > GAntiFreeze.IdleTimeOut then begin
Result := CheckIsReadable(AMSec - GAntiFreeze.IdleTimeOut);
if Result then begin
Exit;
end else begin
AMSec := GAntiFreeze.IdleTimeOut;
end;
end;
end;
Result := CheckIsReadable(AMSec);
end;
procedure TElIdSSHConnectionIOHandler.Notification(AComponent: TComponent;
AOperation: TOperation);
begin
inherited;
if (AComponent = FSSHServer) and (AOperation = opRemove) then
begin
FSSHServer := nil;
FTunnelConnection := nil;
FActive := false;
end;
end;
function TElIdSSHClientServerIOHandler.Recv(var ABuf;
ALen: integer): integer;
begin
Result := 0;
end;
function TElIdSSHClientServerIOHandler.Send(var ABuf;
ALen: integer): integer;
begin
Result := 0;
end;
{ TElIdSSHConnection }
constructor TElIdSSHConnection.Create(AOwner : TComponent);
begin
inherited;
FTunnelConnection := nil;
FSSHServer := nil;
FDestPort := 0;
FSrcPort := 0;
FDestHost := '';
FSrcHost := '';
FScreenNumber := 0;
FCommand := '';
FAuthenticationProtocol := '';
FSubsystem := '';
FTerminalInfo := nil;
FEnvironment := nil;
end;
function TElIdSSHConnection.GetData: pointer;
begin
if Assigned(FTunnelConnection) then
Result := FTunnelConnection.Data
else
Result := nil;
end;
function TElIdSSHConnection.GetExitMessage: string;
begin
if Assigned(FTunnelConnection) then
Result := FTunnelConnection.ExitMessage
else
Result := '';
end;
function TElIdSSHConnection.GetExitSignal: string;
begin
if Assigned(FTunnelConnection) then
Result := FTunnelConnection.ExitSignal
else
Result := '';
end;
function TElIdSSHConnection.GetExitStatus: integer;
begin
if Assigned(FTunnelConnection) then
Result := FTunnelConnection.ExitStatus
else
Result := 0;
end;
function TElIdSSHConnection.GetTunnelType: TSSHTunnelType;
begin
if FTunnelConnection.Tunnel is TElShellSSHTunnel then
Result := ttShell
else if FTunnelConnection.Tunnel is TElCommandSSHTunnel then
Result := ttCommand
else if FTunnelConnection.Tunnel is TElLocalPortForwardSSHTunnel then
Result := ttLocalPortToRemoteAddress
else if FTunnelConnection.Tunnel is TElRemotePortForwardSSHTunnel then
Result := ttRemotePortToLocalAddress
else if FTunnelConnection.Tunnel is TElX11ForwardSSHTunnel then
Result := ttX11
else if FTunnelConnection.Tunnel is TElSubsystemSSHTunnel then
Result := ttSubsystem
else if FTunnelConnection.Tunnel is TElAuthenticationAgentSSHTunnel then
Result := ttAuthenticationAgent
else
Result := ttSubsystem;
end;
procedure TElIdSSHConnection.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (AComponent = FSSHServer) and (Operation = opRemove) then
begin
FSSHServer := nil;
FTunnelConnection := nil;
end;
end;
procedure TElIdSSHConnection.SetConnection(ATunnelConnection :
TElSSHTunnelConnection; ASSHServer : TElSSHServer);
begin
if Assigned(ATunnelConnection) and Assigned(ASSHServer)
then
begin
ASSHServer.FreeNotification(Self);
FTunnelConnection := ATunnelConnection;
FSSHServer := ASSHServer;
if Assigned(FIOHandler) then
TElIdSSHConnectionIOHandler(FIOHandler).SetConnection(
FTunnelConnection, FSSHServer);
end;
end;
procedure TElIdSSHConnection.SetData(const Value: pointer);
begin
if Assigned(FTunnelConnection) then
FTunnelConnection.Data := Value;
end;
function TElIdSSHConnectionIOHandler.Recv(var ABuf;
ALen: integer): integer;
begin
Result := Min(ALen, FInputBuffer.Size);
if Result > 0 then
begin
FInputBuffer.Position := 0;
FInputBuffer.Read(ABuf, Result);
FInputBuffer.Remove(Result);
end;
end;
function TElIdSSHConnectionIOHandler.Send(var ABuf;
ALen: integer): integer;
begin
if Assigned(FTunnelConnection) and FActive and (ALen > 0) then
FTunnelConnection.SendData(@ABuf, ALen);
Result := ALen;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -