2012-02-13 16:53:02 -08:00
|
|
|
{$I M_OPS.PAS}
|
|
|
|
|
|
|
|
Unit MIS_Client_Telnet;
|
|
|
|
|
|
|
|
Interface
|
|
|
|
|
|
|
|
Uses
|
|
|
|
{$IFDEF UNIX}
|
|
|
|
Unix,
|
2012-03-07 23:33:48 -08:00
|
|
|
Classes,
|
|
|
|
Process,
|
|
|
|
SysUtils,
|
2012-03-10 00:49:11 -08:00
|
|
|
m_FileIO,
|
2012-02-13 16:53:02 -08:00
|
|
|
{$ENDIF}
|
2012-02-18 00:09:14 -08:00
|
|
|
{$IFDEF WINDOWS}
|
2012-02-13 16:53:02 -08:00
|
|
|
Windows,
|
|
|
|
{$ENDIF}
|
2012-08-11 11:58:58 -07:00
|
|
|
m_io_Base,
|
|
|
|
m_io_Sockets,
|
2012-02-13 16:53:02 -08:00
|
|
|
m_Strings,
|
|
|
|
MIS_Common,
|
|
|
|
MIS_NodeData,
|
|
|
|
MIS_Server;
|
|
|
|
|
2012-08-11 11:58:58 -07:00
|
|
|
Function CreateTelnet (Owner: TServerManager; Config: RecConfig; ND: TNodeData; CliSock: TIOSocket) : TServerClient;
|
2012-02-13 16:53:02 -08:00
|
|
|
{ must match server create or there will be access violations }
|
|
|
|
|
|
|
|
Type
|
|
|
|
TTelnetServer = Class(TServerClient)
|
2012-06-18 05:59:19 -07:00
|
|
|
ND : TNodeData;
|
|
|
|
Snooping : Boolean;
|
2012-08-11 11:58:58 -07:00
|
|
|
Constructor Create (Owner: TServerManager; ND: TNodeData; CliSock: TIOSocket);
|
2012-02-13 16:53:02 -08:00
|
|
|
Procedure Execute; Override;
|
|
|
|
Destructor Destroy; Override;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Implementation
|
|
|
|
|
2012-08-11 11:58:58 -07:00
|
|
|
Function CreateTelnet (Owner: TServerManager; Config: RecConfig; ND: TNodeData; CliSock: TIOSocket) : TServerClient;
|
2012-02-13 16:53:02 -08:00
|
|
|
Begin
|
|
|
|
Result := TTelnetServer.Create(Owner, ND, CliSock);
|
|
|
|
End;
|
|
|
|
|
2012-08-11 11:58:58 -07:00
|
|
|
Constructor TTelnetServer.Create (Owner: TServerManager; ND: TNodeData; CliSock: TIOSocket);
|
2012-02-13 16:53:02 -08:00
|
|
|
Begin
|
|
|
|
Inherited Create(Owner, CliSock);
|
|
|
|
|
2012-06-18 05:59:19 -07:00
|
|
|
Self.ND := ND;
|
|
|
|
Snooping := False;
|
2012-02-13 16:53:02 -08:00
|
|
|
End;
|
|
|
|
|
2012-02-17 23:54:53 -08:00
|
|
|
{$IFDEF WINDOWS}
|
2012-02-13 16:53:02 -08:00
|
|
|
Procedure TTelnetServer.Execute;
|
|
|
|
Var
|
2012-03-07 23:33:48 -08:00
|
|
|
Cmd : String;
|
|
|
|
SI : TStartupInfo;
|
|
|
|
PI : TProcessInformation;
|
|
|
|
Num : LongInt;
|
|
|
|
NI : TNodeInfoRec;
|
2012-02-13 16:53:02 -08:00
|
|
|
PassHandle : LongInt;
|
|
|
|
Begin
|
2012-03-07 23:33:48 -08:00
|
|
|
If Not DuplicateHandle (
|
|
|
|
GetCurrentProcess,
|
|
|
|
Client.FSocketHandle,
|
|
|
|
GetCurrentProcess,
|
|
|
|
@PassHandle,
|
|
|
|
0,
|
|
|
|
TRUE,
|
|
|
|
DUPLICATE_SAME_ACCESS) Then Exit;
|
2012-02-13 16:53:02 -08:00
|
|
|
|
|
|
|
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]),
|
2012-03-07 23:33:48 -08:00
|
|
|
NIL, NIL, True, Create_New_Console + Normal_Priority_Class, NIL, NIL, SI, PI) Then
|
2012-02-13 16:53:02 -08:00
|
|
|
WaitForSingleObject (PI.hProcess, INFINITE);
|
|
|
|
|
|
|
|
NI.Busy := False;
|
|
|
|
NI.IP := '';
|
|
|
|
NI.User := '';
|
|
|
|
NI.Action := '';
|
|
|
|
|
|
|
|
ND.SetNodeInfo(Num, NI);
|
|
|
|
End;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF UNIX}
|
|
|
|
Procedure TTelnetServer.Execute;
|
2012-03-07 23:33:48 -08:00
|
|
|
Const
|
|
|
|
BufferSize = 4096;
|
2012-02-13 16:53:02 -08:00
|
|
|
Var
|
2012-03-07 23:33:48 -08:00
|
|
|
Cmd : String;
|
|
|
|
Num : LongInt;
|
|
|
|
NI : TNodeInfoRec;
|
|
|
|
Proc : TProcess;
|
|
|
|
Buffer : Array[1..BufferSize] of Char;
|
|
|
|
bRead : LongInt;
|
|
|
|
bWrite : LongInt;
|
2012-02-13 16:53:02 -08:00
|
|
|
Begin
|
2012-06-30 18:22:09 -07:00
|
|
|
Client.FTelnetServer := True;
|
|
|
|
|
2012-03-07 23:33:48 -08:00
|
|
|
Proc := TProcess.Create(Nil);
|
|
|
|
Num := ND.GetFreeNode;
|
|
|
|
|
|
|
|
Proc.CommandLine := 'mystic -n' + strI2S(Num) + ' -IP' + Client.FPeerIP + ' -HOST' + Client.FPeerName;
|
|
|
|
Proc.Options := [poUsePipes];
|
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);
|
|
|
|
|
2012-03-07 23:33:48 -08:00
|
|
|
Proc.Execute;
|
2012-02-17 23:47:18 -08:00
|
|
|
|
2012-03-07 23:33:48 -08:00
|
|
|
While Proc.Running Do Begin
|
|
|
|
If Proc.Output.NumBytesAvailable > 0 Then Begin
|
|
|
|
While Proc.Output.NumBytesAvailable > 0 Do Begin
|
|
|
|
bRead := Proc.Output.Read(Buffer, BufferSize);
|
|
|
|
Client.WriteBuf (Buffer, bRead);
|
2012-06-18 05:59:19 -07:00
|
|
|
|
|
|
|
If Snooping Then
|
|
|
|
Term.ProcessBuf(Buffer[1], bRead);
|
2012-03-07 23:33:48 -08:00
|
|
|
End;
|
|
|
|
End Else
|
|
|
|
If Client.DataWaiting Then Begin
|
|
|
|
bWrite := Client.ReadBuf(Buffer, BufferSize);
|
2012-02-13 16:53:02 -08:00
|
|
|
|
2012-03-07 23:33:48 -08:00
|
|
|
If bWrite < 0 Then Break;
|
|
|
|
|
2012-06-18 05:59:19 -07:00
|
|
|
If bWrite > 0 Then Begin
|
2012-03-07 23:33:48 -08:00
|
|
|
Proc.Input.Write(Buffer, bWrite);
|
2012-06-18 05:59:19 -07:00
|
|
|
End;
|
2012-03-07 23:33:48 -08:00
|
|
|
End Else
|
2012-03-10 00:49:11 -08:00
|
|
|
Sleep(10);
|
2012-03-07 23:33:48 -08:00
|
|
|
End;
|
2012-02-13 16:53:02 -08:00
|
|
|
|
2012-03-07 23:33:48 -08:00
|
|
|
Proc.Free;
|
2012-02-18 00:09:14 -08:00
|
|
|
|
2012-06-30 18:22:09 -07:00
|
|
|
FileMode := 66;
|
|
|
|
|
2012-03-10 00:49:11 -08:00
|
|
|
FileErase (bbsConfig.DataPath + 'chat' + strI2S(NI.Num) + '.dat');
|
|
|
|
|
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-03-10 00:49:11 -08:00
|
|
|
End.
|