2012-02-13 16:53:02 -08:00
|
|
|
Unit MIS_Client_NNTP;
|
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
{$I M_OPS.PAS}
|
|
|
|
|
|
|
|
// RFC 977
|
2012-02-13 16:53:02 -08:00
|
|
|
|
|
|
|
Interface
|
|
|
|
|
|
|
|
Uses
|
|
|
|
SysUtils,
|
|
|
|
m_Strings,
|
|
|
|
m_FileIO,
|
|
|
|
m_Socket_Class,
|
|
|
|
m_DateTime,
|
|
|
|
MIS_Server,
|
|
|
|
MIS_NodeData,
|
|
|
|
MIS_Common;
|
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
Function CreateNNTP (Owner: TServerManager; Config: RecConfig; ND: TNodeData; CliSock: TSocketClass) : TServerClient;
|
2012-02-13 16:53:02 -08:00
|
|
|
|
|
|
|
Type
|
|
|
|
TNNTPServer = Class(TServerClient)
|
|
|
|
Server : TServerManager;
|
2012-02-27 09:52:54 -08:00
|
|
|
UserName : String[30];
|
|
|
|
Password : String[15];
|
2012-02-13 16:53:02 -08:00
|
|
|
LoggedIn : Boolean;
|
|
|
|
Cmd : String;
|
|
|
|
Data : String;
|
|
|
|
User : RecUser;
|
|
|
|
UserPos : LongInt;
|
|
|
|
|
|
|
|
Constructor Create (Owner: TServerManager; CliSock: TSocketClass);
|
|
|
|
Procedure Execute; Override;
|
|
|
|
Destructor Destroy; Override;
|
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
Procedure ClientWriteLine (Str: String);
|
|
|
|
|
2012-02-13 16:53:02 -08:00
|
|
|
Procedure ResetSession;
|
|
|
|
|
|
|
|
Procedure cmd_AUTHINFO;
|
2012-02-27 09:52:54 -08:00
|
|
|
Procedure cmd_GROUP;
|
|
|
|
Procedure cmd_LIST;
|
2012-02-13 16:53:02 -08:00
|
|
|
End;
|
|
|
|
|
|
|
|
Implementation
|
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
Uses
|
|
|
|
bbs_MsgBase_ABS,
|
|
|
|
bbs_MsgBase_JAM,
|
|
|
|
bbs_MsgBase_Squish;
|
2012-02-13 16:53:02 -08:00
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
Const
|
|
|
|
FileReadBuffer = 2048;
|
2012-02-13 16:53:02 -08:00
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
re_Greeting = '200 Mystic BBS NNTP server ready';
|
|
|
|
re_Goodbye = '205 Goodbye';
|
|
|
|
re_ListFollows = '215 List of newsgroups follows';
|
2012-02-13 16:53:02 -08:00
|
|
|
re_AuthOK = '281 Authentication accepted';
|
|
|
|
re_AuthBad = '381 Authentication rejected';
|
|
|
|
re_AuthPass = '381 Password required';
|
|
|
|
re_AuthSync = '482 Bad Authentication sequence';
|
|
|
|
re_Unknown = '500 Unknown command';
|
|
|
|
re_UnknownOption = '501 Unknown option';
|
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
Function CreateNNTP (Owner: TServerManager; Config: RecConfig; ND: TNodeData; CliSock: TSocketClass) : TServerClient;
|
2012-02-13 16:53:02 -08:00
|
|
|
Begin
|
|
|
|
Result := TNNTPServer.Create(Owner, CliSock);
|
|
|
|
End;
|
|
|
|
|
|
|
|
Constructor TNNTPServer.Create (Owner: TServerManager; CliSock: TSocketClass);
|
|
|
|
Begin
|
|
|
|
Inherited Create(Owner, CliSock);
|
|
|
|
|
|
|
|
Server := Owner;
|
|
|
|
End;
|
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
Procedure TNNTPServer.ClientWriteLine (Str: String);
|
|
|
|
Begin
|
|
|
|
Server.Server.Status('S:' + Str);
|
|
|
|
Client.WriteLine(Str);
|
|
|
|
End;
|
|
|
|
|
2012-02-13 16:53:02 -08:00
|
|
|
Procedure TNNTPServer.ResetSession;
|
|
|
|
Begin
|
|
|
|
LoggedIn := False;
|
|
|
|
UserName := '';
|
|
|
|
Password := '';
|
|
|
|
UserPos := -1;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Procedure TNNTPServer.cmd_AUTHINFO;
|
|
|
|
Var
|
|
|
|
NewCmd : String;
|
|
|
|
NewData : String;
|
|
|
|
Begin
|
|
|
|
NewCmd := strWordGet(1, Data, ' ');
|
|
|
|
NewData := Copy(Data, Pos(' ', Data) + 1, 255);
|
|
|
|
|
|
|
|
If NewCmd = 'USER' Then Begin
|
|
|
|
If SearchForUser(NewData, User, UserPos) Then Begin
|
2012-02-27 09:52:54 -08:00
|
|
|
ClientWriteLine(re_AuthPass);
|
2012-02-13 16:53:02 -08:00
|
|
|
UserName := NewData;
|
|
|
|
End Else
|
2012-02-27 09:52:54 -08:00
|
|
|
ClientWriteLine(re_AuthBad);
|
2012-02-13 16:53:02 -08:00
|
|
|
End Else
|
|
|
|
If NewCmd = 'PASS' Then Begin
|
|
|
|
If UserPos = -1 Then
|
2012-02-27 09:52:54 -08:00
|
|
|
ClientWriteLine(re_AuthSync)
|
2012-02-13 16:53:02 -08:00
|
|
|
Else
|
|
|
|
If strUpper(NewData) = User.Password Then Begin
|
2012-02-27 09:52:54 -08:00
|
|
|
ClientWriteLine(re_AuthOK);
|
2012-02-13 16:53:02 -08:00
|
|
|
LoggedIn := True;
|
|
|
|
End Else
|
2012-02-27 09:52:54 -08:00
|
|
|
ClientWriteLine(re_AuthBad);
|
2012-02-13 16:53:02 -08:00
|
|
|
End Else
|
2012-02-27 09:52:54 -08:00
|
|
|
ClientWriteLine(re_UnknownOption);
|
|
|
|
|
|
|
|
If LoggedIn Then
|
|
|
|
Server.Server.Status('Logged in as ' + UserName);
|
|
|
|
End;
|
|
|
|
|
|
|
|
Procedure TNNTPServer.cmd_GROUP;
|
|
|
|
Begin
|
|
|
|
// 211 number_of_estimated_articles first_msg last_msg newsname
|
|
|
|
// 411 nosuchnewsgroup
|
|
|
|
// this selects the "current" base
|
|
|
|
End;
|
|
|
|
|
|
|
|
Procedure TNNTPServer.cmd_LIST;
|
|
|
|
Var
|
|
|
|
MBaseFile : TBufFile;
|
|
|
|
TempBase : RecMessageBase;
|
|
|
|
MsgBase : PMsgBaseABS;
|
|
|
|
LowMessage : LongInt = 0;
|
|
|
|
HighMessage : LongInt = 0;
|
|
|
|
PostAbility : Char;
|
|
|
|
Begin
|
|
|
|
ClientWriteLine(re_ListFollows);
|
|
|
|
|
|
|
|
MBaseFile := TBufFile.Create(FileReadBuffer);
|
|
|
|
|
|
|
|
If MBaseFile.Open(bbsConfig.DataPath + 'mbases.dat', fmOpen, fmRWDN, SizeOf(RecMessageBase)) Then Begin
|
|
|
|
MBaseFile.Read(TempBase);
|
|
|
|
|
|
|
|
While Not MBaseFile.EOF Do Begin
|
|
|
|
MBaseFile.Read(TempBase);
|
|
|
|
|
|
|
|
If TempBase.NewsName = '' Then Continue;
|
|
|
|
|
|
|
|
If CheckAccess(User, True, TempBase.ListACS) Then Begin
|
|
|
|
LowMessage := 0;
|
|
|
|
HighMessage := 0;
|
|
|
|
|
|
|
|
Case CheckAccess(User, True, TempBase.PostACS) of
|
|
|
|
False : PostAbility := 'n';
|
|
|
|
True : PostAbility := 'y';
|
|
|
|
End;
|
|
|
|
|
|
|
|
Case TempBase.BaseType of
|
|
|
|
0 : MsgBase := New(PMsgBaseJAM, Init);
|
|
|
|
1 : MsgBase := New(PMsgBaseSquish, Init);
|
|
|
|
End;
|
|
|
|
|
|
|
|
MsgBase^.SetMsgPath (TempBase.Path + TempBase.FileName);
|
|
|
|
|
|
|
|
If MsgBase^.OpenMsgBase Then Begin
|
|
|
|
LowMessage := 1;
|
|
|
|
HighMessage := MsgBase^.GetHighActiveMsgNum;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Dispose (MsgBase, Done);
|
|
|
|
|
|
|
|
ClientWriteLine (TempBase.NewsName + ' ' + strI2S(LowMessage) + ' ' + strI2S(HighMessage) + ' ' + PostAbility);
|
|
|
|
End;
|
|
|
|
End;
|
|
|
|
End;
|
|
|
|
|
|
|
|
MBaseFile.Free;
|
|
|
|
|
|
|
|
ClientWriteLine('.');
|
2012-02-13 16:53:02 -08:00
|
|
|
End;
|
|
|
|
|
|
|
|
Procedure TNNTPServer.Execute;
|
|
|
|
Var
|
|
|
|
Str : String;
|
|
|
|
Begin
|
|
|
|
ResetSession;
|
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
ClientWriteLine(re_Greeting);
|
2012-02-13 16:53:02 -08:00
|
|
|
|
|
|
|
Repeat
|
2012-02-27 09:52:54 -08:00
|
|
|
If Client.WaitForData(bbsConfig.inetNNTPTimeout * 1000) = 0 Then Break;
|
2012-02-13 16:53:02 -08:00
|
|
|
|
|
|
|
If Terminated Then Exit;
|
|
|
|
|
|
|
|
If Client.ReadLine(Str) = -1 Then Exit;
|
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
Server.Server.Status('C:' + Str);
|
2012-02-13 16:53:02 -08:00
|
|
|
|
|
|
|
Cmd := strUpper(strWordGet(1, Str, ' '));
|
|
|
|
|
|
|
|
If Pos(' ', Str) > 0 Then
|
|
|
|
Data := strStripB(Copy(Str, Pos(' ', Str) + 1, Length(Str)), ' ')
|
|
|
|
Else
|
|
|
|
Data := '';
|
|
|
|
|
|
|
|
If Cmd = 'AUTHINFO' Then cmd_AUTHINFO Else
|
2012-02-27 09:52:54 -08:00
|
|
|
If Cmd = 'GROUP' Then cmd_GROUP Else
|
|
|
|
If Cmd = 'LIST' Then cmd_LIST Else
|
|
|
|
If Cmd = 'QUIT' Then Break Else
|
|
|
|
ClientWriteLine(re_Unknown);
|
2012-02-13 16:53:02 -08:00
|
|
|
Until Terminated;
|
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
If Not Terminated Then ClientWriteLine(re_Goodbye);
|
2012-02-13 16:53:02 -08:00
|
|
|
End;
|
|
|
|
|
|
|
|
Destructor TNNTPServer.Destroy;
|
|
|
|
Begin
|
|
|
|
Inherited Destroy;
|
|
|
|
End;
|
|
|
|
|
2012-02-27 09:52:54 -08:00
|
|
|
End.
|