2012-02-13 16:53:02 -08:00
|
|
|
{$I M_OPS.PAS}
|
|
|
|
|
|
|
|
Unit MIS_Client_Telnet;
|
|
|
|
|
|
|
|
Interface
|
|
|
|
|
|
|
|
Uses
|
|
|
|
{$IFDEF UNIX}
|
|
|
|
Unix,
|
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF WIN32}
|
|
|
|
Windows,
|
|
|
|
{$ENDIF}
|
|
|
|
m_Strings,
|
|
|
|
m_Socket_Class,
|
|
|
|
MIS_Common,
|
|
|
|
MIS_NodeData,
|
|
|
|
MIS_Server;
|
|
|
|
|
|
|
|
Function CreateTelnet (Owner: TServerManager; Config: RecConfig; ND: TNodeData; CliSock: TSocketClass) : TServerClient;
|
|
|
|
{ must match server create or there will be access violations }
|
|
|
|
|
|
|
|
Type
|
|
|
|
TTelnetServer = Class(TServerClient)
|
|
|
|
ND : TNodeData;
|
|
|
|
Constructor Create (Owner: TServerManager; ND: TNodeData; CliSock: TSocketClass);
|
|
|
|
Procedure Execute; Override;
|
|
|
|
Destructor Destroy; Override;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Implementation
|
|
|
|
|
|
|
|
Function CreateTelnet (Owner: TServerManager; Config: RecConfig; ND: TNodeData; CliSock: TSocketClass) : TServerClient;
|
|
|
|
Begin
|
|
|
|
Result := TTelnetServer.Create(Owner, ND, CliSock);
|
|
|
|
End;
|
|
|
|
|
|
|
|
Constructor TTelnetServer.Create (Owner: TServerManager; ND: TNodeData; CliSock: TSocketClass);
|
|
|
|
Begin
|
|
|
|
Inherited Create(Owner, CliSock);
|
|
|
|
|
|
|
|
Self.ND := ND;
|
|
|
|
End;
|
|
|
|
|
2012-02-17 23:54:53 -08:00
|
|
|
{$IFDEF WINDOWS}
|
2012-02-13 16:53:02 -08:00
|
|
|
Procedure TTelnetServer.Execute;
|
|
|
|
Var
|
|
|
|
Cmd : String;
|
|
|
|
SI : TStartupInfo;
|
|
|
|
PI : TProcessInformation;
|
|
|
|
Num : LongInt;
|
|
|
|
NI : TNodeInfoRec;
|
|
|
|
PassHandle : LongInt;
|
|
|
|
Begin
|
|
|
|
If Not DuplicateHandle (
|
|
|
|
GetCurrentProcess,
|
|
|
|
Client.FSocketHandle,
|
|
|
|
GetCurrentProcess,
|
|
|
|
@PassHandle,
|
|
|
|
0,
|
|
|
|
TRUE,
|
|
|
|
DUPLICATE_SAME_ACCESS) Then Exit;
|
|
|
|
|
|
|
|
Num := ND.GetFreeNode;
|
|
|
|
Cmd := 'mystic.exe -n' + strI2S(Num) + ' -TID' + strI2S(PassHandle) + ' -IP' + Client.FPeerIP + ' -HOST' + Client.FPeerName + #0;
|
|
|
|
|
|
|
|
FillChar(NI, SizeOf(NI), 0);
|
|
|
|
|
|
|
|
NI.Num := Num;
|
|
|
|
NI.Busy := True;
|
|
|
|
NI.IP := Client.FPeerIP;
|
|
|
|
NI.User := 'Unknown';
|
|
|
|
NI.Action := 'Logging In';
|
|
|
|
|
2012-02-17 23:47:18 -08:00
|
|
|
ND.SetNodeInfo(Num, NI);
|
2012-02-13 16:53:02 -08:00
|
|
|
|
|
|
|
FillChar(SI, SizeOf(SI), 0);
|
|
|
|
FillChar(PI, SizeOf(PI), 0);
|
|
|
|
|
|
|
|
SI.dwFlags := STARTF_USESHOWWINDOW;
|
|
|
|
SI.wShowWindow := SW_SHOWMINNOACTIVE;
|
|
|
|
|
|
|
|
If CreateProcess(NIL, PChar(@Cmd[1]),
|
|
|
|
NIL, NIL, True, create_new_console + normal_priority_class, NIL, NIL, SI, PI) Then
|
|
|
|
WaitForSingleObject (PI.hProcess, INFINITE);
|
|
|
|
|
|
|
|
NI.Busy := False;
|
|
|
|
NI.IP := '';
|
|
|
|
NI.User := '';
|
|
|
|
NI.Action := '';
|
|
|
|
|
|
|
|
ND.SetNodeInfo(Num, NI);
|
|
|
|
End;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF UNIX}
|
|
|
|
Procedure TTelnetServer.Execute;
|
|
|
|
Var
|
|
|
|
Cmd : String;
|
|
|
|
Num : LongInt;
|
|
|
|
NI : TNodeInfoRec;
|
|
|
|
Begin
|
|
|
|
Num := ND.GetFreeNode;
|
2012-02-17 23:47:18 -08:00
|
|
|
Cmd := './mystic -n' + strI2S(Num) + ' -IP' + Client.FPeerIP + ' -HOST' + Client.FPeerName;
|
2012-02-13 16:53:02 -08:00
|
|
|
|
|
|
|
FillChar(NI, SizeOf(NI), 0);
|
|
|
|
|
|
|
|
NI.Num := Num;
|
|
|
|
NI.Busy := True;
|
|
|
|
NI.IP := Client.FPeerIP;
|
|
|
|
NI.User := 'Unknown';
|
|
|
|
NI.Action := 'Logging In';
|
|
|
|
|
2012-02-17 23:47:18 -08:00
|
|
|
ND.SetNodeInfo(Num, NI);
|
|
|
|
|
|
|
|
// setup and execute Cmd as defined above, setting up STDIO handles
|
|
|
|
|
|
|
|
fpSystem(Cmd); // placeholder for above
|
2012-02-13 16:53:02 -08:00
|
|
|
|
2012-02-17 23:47:18 -08:00
|
|
|
// redirection of STDIO psuedocode loop here
|
2012-02-17 23:54:53 -08:00
|
|
|
// NOTE client class already escapes telnet protocol, no need for that!
|
2012-02-17 23:47:18 -08:00
|
|
|
//
|
|
|
|
// while processGoing do begin
|
2012-02-17 23:54:53 -08:00
|
|
|
// case waitEvent(Input, output, close, wait INFINITY)
|
|
|
|
// input : push input to STDIO handle?
|
2012-02-17 23:47:18 -08:00
|
|
|
// output : push output to client class
|
2012-02-17 23:49:57 -08:00
|
|
|
// close : break;
|
2012-02-17 23:47:18 -08:00
|
|
|
// end
|
2012-02-13 16:53:02 -08:00
|
|
|
|
|
|
|
NI.Busy := False;
|
|
|
|
NI.IP := '';
|
|
|
|
NI.User := '';
|
|
|
|
NI.Action := '';
|
|
|
|
|
|
|
|
ND.SetNodeInfo(Num, NI);
|
|
|
|
End;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
Destructor TTelnetServer.Destroy;
|
|
|
|
Begin
|
|
|
|
Inherited Destroy;
|
|
|
|
End;
|
|
|
|
|
2012-02-17 23:49:57 -08:00
|
|
|
End.
|