program lms_cgi; {$mode objfpc}{$H+} uses Interfaces, Classes, SysUtils, inifiles, httpDefs, fpweb, custweb, custcgi, lnetbase, tcpClient, tcpthreadhelper, extTypes, eventlog; Type { TMyCGIHandler } TMyCGIHandler = Class(TCgiHandler) Private fAnswer: string; fMode: byte; fCode: DWORD; fParam: QWORD; fValues: TStrings; fData: TStream; function answerReady(Sender: TMainThread; const mode: byte; const Code:DWORD; const QValue: QWORD; const Answer: string; const Values: TStrings; const iValues: TParamArray; const Data: TStream): boolean; Public Procedure HandleRequest(ARequest : Trequest; AResponse : TResponse); override; procedure log(ALevel: TLogLevel; Sender: TObject; msg: string); end; { TMyCGIApp } TMyCGIApp = Class(TCustomCGIApplication) private flogFolder: string; fHost: string; fPort: integer; flogger: TEventLog; procedure LoadConfig; Protected function InitializeWebHandler: TWebHandler; override; public constructor CreateWithLogger(AOwner: TComponent); destructor Destroy; override; property Host: string read fHost; property Port: integer read fPort; property LogFolder: string read fLogFolder; property Logger: TEventLog read flogger; end; const aTypes: array[0..3] of string=('"UNKNOWN"','"REQUEST"','"ANSWER"','"ERROR"'); function TMyCGIHandler.answerReady(Sender: TMainThread; const mode: byte; const Code: DWORD; const QValue: QWORD; const Answer: string; const Values: TStrings; const iValues: TParamArray; const Data: TStream ): boolean; begin fAnswer:=Answer; fMode:=mode; fCode:=code; fParam:=QValue; if assigned(Values) then begin fValues:=TStringList.Create; fValues.assign(Values); end; if assigned(Data) then begin fData := TMemoryStream.Create; Data.seek(0,soFromBeginning); fData.CopyFrom(Data,Data.Size); end; Sender.Terminate; end; procedure TMyCGIHandler.HandleRequest(ARequest: Trequest; AResponse: TResponse); var clt: TClientMainThread; i: integer; k,v: string; allfields: TStrings; begin {$IFDEF DEBUG} log(mtDebug,self,'Command '+ARequest.Command); log(mtDebug,self,'RemoteAddr '+ARequest.RemoteAddr); log(mtDebug,self,'RemoteAddress '+ARequest.RemoteAddress); log(mtDebug,self,'CommandLine '+ARequest.CommandLine); log(mtDebug,self,'ContentRange '+ARequest.ContentRange); log(mtDebug,self,'HeaderLine '+ARequest.HeaderLine); log(mtDebug,self,'QueryString '+ARequest.QueryString); log(mtDebug,self,'Authorization '+ARequest.Authorization); log(mtDebug,self,'Connection '+ARequest.Connection); log(mtDebug,self,'WWWAuthenticate '+ARequest.WWWAuthenticate); log(mtDebug,self,'Content '+ARequest.Content); log(mtDebug,self,'ContentType '+ARequest.ContentType); log(mtDebug,self,'From '+ARequest.From); log(mtDebug,self,'UserAgent '+ARequest.UserAgent); log(mtDebug,self,'URI '+ARequest.URI); log(mtDebug,self,'URL '+ARequest.URL); log(mtDebug,self,'ContentEncoding '+ARequest.ContentEncoding); log(mtDebug,self,'ContentLanguage '+ARequest.ContentLanguage); log(mtDebug,self,'Query '+ARequest.Query); log(mtDebug,self,'Location '+ARequest.Location); log(mtDebug,self,'Method '+ARequest.Method); log(mtDebug,self,'PathInfo '+ARequest.PathInfo); log(mtDebug,self,'Referer '+ARequest.Referer); LogStrings(mtInfo, @log,self,'QueryFields',Arequest.QueryFields); LogStrings(mtInfo, @log,self,'ContentFields',Arequest.ContentFields); LogStrings(mtInfo, @log,self,'CookieFields',Arequest.CookieFields); LogStrings(mtInfo, @log,self,'CustomHeaders',Arequest.CustomHeaders); {$ENDIF} if ARequest.QueryFields.Values['action']='cgi-test' then begin AResponse.ContentType := 'text/html'; AResponse.Contents.add('