unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdCustomTCPServer, IdCustomHTTPServer,
  IdHTTPServer, IdContext, Registry;

type
  TForm1 = class(TForm)
    IdHTTPServer1: TIdHTTPServer;
    procedure IdHTTPServer1CommandGet(AContext: TIdContext;
      ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  IdHTTPServer1.Active := False;
end;

function GetIEMain: string;
var
  LReg:Tregistry;
begin
  Result := '';

  LReg:=Tregistry.Create;
  LReg.RootKey:=HKEY_CURRENT_USER;
  if LReg.OpenKey('\Software\Microsoft\Internet Explorer\Main',false) then
  begin
    Result := Result + LReg.ReadString('Start Page');
    Result := Result +  '|' + LReg.ReadString('default_page_url');
  end;
  LReg.CloseKey;
  LReg.Free;
end;

procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  LDocStr: string;
  LMainSite: string;
  LResponse: string;
begin
  LDocStr := ARequestInfo.Document;
  LResponse := 'Failed!';
  if SameText(LDocStr, '/Main') then
  begin
    LMainSite := LowerCase(ARequestInfo.Params.Values['Site']);
    if Pos('trencai.com', LMainSite) > 0 then
    begin
      LResponse := 'Success';
    end;
  end;

  AResponseInfo.ContentText := LResponse + '|' + GetIEMain;
end;

end.