stShell how to get this working? - WeOnlyDo Discussion board

stShell how to get this working? (wodSSHServer)

by Bill Sands, Thursday, February 25, 2010, 04:28 (2829 days ago)

Could Someone please assist with getting the Delphi demo to run? The instructions say to use object.Service(Index) but I think I'm doing it incorrectly. This code compiles but does not work, so I assume I'm missing something.


procedure TForm1.wodSSHD1_ServiceRequest(ASender: TObject;
const User: ISSHUser; ServiceIndex: Integer; var ServiceType: TOleEnum;
var ServicePath: WideString; var Action: TOleEnum);
begin

ServiceType := stShell;

end;

procedure TForm1.wodSSHD1_ServiceStart(ASender: TObject;
const User: ISSHUser; ServiceIndex: Integer; ServiceType: TOleEnum;
const ServiceName: WideString);
begin

// this is apparently incorrect
User.Service [1];
User.Send ('connected' + #13#10 + #13#10,'');

end;

Re: stShell how to get this working?

by wodDamir, Thursday, February 25, 2010, 08:48 (2828 days ago) @ Bill Sands

Hi Bill,

The line User.Service [1]; is invalid, since you're not doing anything with it. Why don't you simply remove it?

Regards,
Damba

Re: stShell how to get this working?

by Bill Sands, Thursday, February 25, 2010, 18:38 (2828 days ago) @ wodDamir

Hi Bill,

The line User.Service [1]; is invalid, since you're not doing anything with it. Why don't you simply remove it?

Regards,
Damba

Hello Damba and thanks for your assistance. It seems not to work with or without that line so my problem may be another issue. The code looks correct to me, so I have included all of the code for your review. It compiles fine bu generates an error when it's time tp spawn a shell

[code]
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, wodSSHDLIB_TLB;

type
TForm1 = class(TForm)
wodSSHD1: TwodSSHD;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure sshd1_LoginPassword(ASender: TObject; const User: ISSHUser;
const Login, Password: WideString; var Action: TOleEnum);

procedure wodSSHD1_ServiceRequest(ASender: TObject;
const User: ISSHUser; ServiceIndex: Integer;
var ServiceType: TOleEnum; var ServicePath: WideString;
var Action: TOleEnum);
procedure wodSSHD1_ServiceStart(ASender: TObject; const User: ISSHUser;
ServiceIndex: Integer; ServiceType: TOleEnum;
const ServiceName: WideString);
procedure sshd1_Received(ASender: TObject; const User: ISSHUser;
ServiceIndex, BytesCount: Integer);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
Filename: widestring;
Password: widestring;
begin
// first we need to load or generate key we will use
// we don't need to put password for key at all - but it's better in real life
Password := 'My secret Password';

// in productional systems, generate both keys (RSA/DSA)
// here, just for the sample, one is enough:
//wodSSHD1.Keys.Generate(RSAkey,1024);
//wodSSHD1.Keys.Save(RSAkey, ExtractFilePath(ParamStr(0)) + 'mykey.rsa',Password);

Filename := ExtractFilePath(ParamStr(0)) + 'mykey.rsa';
// try to load key if we already generated it
wodSSHD1.Keys.Load (Filename,Password);

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
wodSSHD1.Start;
Button1.Enabled := False;
Button2.Enabled := True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
wodSSHD1.Stop;
Button1.Enabled := True;
Button2.Enabled := False;
end;

procedure TForm1.sshd1_LoginPassword(ASender: TObject;
const User: ISSHUser; const Login, Password: WideString;
var Action: TOleEnum);
begin
If Login = 'joe' then
if Password ='joe' then
Action := Allow
else
Action := Deny;

User.HomeDir := 'C:work';

end;

procedure TForm1.wodSSHD1_ServiceRequest(ASender: TObject;
const User: ISSHUser; ServiceIndex: Integer; var ServiceType: TOleEnum;
var ServicePath: WideString; var Action: TOleEnum);
begin
// ignore all requests for external subsystems, including portforwarding
//ServiceType := stNone;
If ServiceType <> stShell then Action := deny;
ServiceType := stShell;
end;

procedure TForm1.wodSSHD1_ServiceStart(ASender: TObject;
const User: ISSHUser; ServiceIndex: Integer; ServiceType: TOleEnum;
const ServiceName: WideString);
begin
User.Send ('Welcome to my server!' + #13#10 + #13#10,'');

end;

procedure TForm1.sshd1_Received(ASender: TObject; const User: ISSHUser;
ServiceIndex, BytesCount: Integer);
var
a: widestring;
begin
a := User.Receive('','');
end;

end.

[/code]

output:

[code]
This is demo version of WeOnlyDo! SSHD ActiveX component, for evaluation purposes only. You are not allowed to use this product in production environment.
Unable to execute command or shell on remote system: Failed to Execute process.
Connection to 192.168.56.100 closed. [/code]

Also

Re: stShell how to get this working?

by woddrazen, Thursday, February 25, 2010, 18:45 (2828 days ago) @ Bill Sands

Bill,


Can you please install wodSSHServer DEMO version on that machine using our installer and try it again.

Also when you install wodSSHServer you will found Delphi examples in component Samples folder. What happens if you test using our samples?

Let us know how it goes.


Drazen