unit Unit2;

interface

uses
  SysUtils, Classes, HTTPApp, StrUtils, HTTPProd, DSProd, OleServer,
  ASGSQLite3, DB;

type
  TWebModule2 = class(TWebModule)
    DataSetPageProducer1: TDataSetPageProducer;
    PageProducer2: TPageProducer;
    DataSetPageProducer2: TDataSetPageProducer;
    PageProducer1: TPageProducer;
    ASQLite3DB1: TASQLite3DB;
    ASQLite3Table1: TASQLite3Table;
    ASQLite3Query1: TASQLite3Query;
    PageProducer3: TPageProducer;
    ASQLite3Table2: TASQLite3Table;
    ASQLite3Table3: TASQLite3Table;
    Log: TASQLite3Table;
    ASQLite3DB2: TASQLite3DB;
    ASQLite3Query2: TASQLite3Query;
    stopitems: TPageProducer;
    procedure WebModuleCreate(Sender: TObject);
    procedure WebModuleDestroy(Sender: TObject);
    procedure WebModuleBeforeDispatch(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    procedure WebModule2indexAction(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    procedure WebModuleAfterDispatch(Sender: TObject; Request: TWebRequest;
      Response: TWebResponse; var Handled: Boolean);
    procedure PageProducer2HTMLTag(Sender: TObject; Tag: TTag;
      const TagString: String; TagParams: TStrings;
      var ReplaceText: String);
    procedure WebModule2RegistAction(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    procedure DataSetPageProducer1HTMLTag(Sender: TObject; Tag: TTag;
      const TagString: String; TagParams: TStrings;
      var ReplaceText: String);
    procedure WebModule2UsrdelAction(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    procedure PageProducer1HTMLTag(Sender: TObject; Tag: TTag;
      const TagString: String; TagParams: TStrings;
      var ReplaceText: String);
    procedure PageProducer3HTMLTag(Sender: TObject; Tag: TTag;
      const TagString: String; TagParams: TStrings;
      var ReplaceText: String);
    procedure WebModule2admdelAction(Sender: TObject; Request: TWebRequest;
      Response: TWebResponse; var Handled: Boolean);
    procedure WebModule2errorAction(Sender: TObject; Request: TWebRequest;
      Response: TWebResponse; var Handled: Boolean);                                                                        
    procedure WebModule2viewAction(Sender: TObject; Request: TWebRequest;
      Response: TWebResponse; var Handled: Boolean);
    procedure WebModule2startAction(Sender: TObject; Request: TWebRequest;
      Response: TWebResponse; var Handled: Boolean);
    procedure stopitemsHTMLTag(Sender: TObject; Tag: TTag;
      const TagString: String; TagParams: TStrings;
      var ReplaceText: String);
    procedure WebModule2stopAction(Sender: TObject; Request: TWebRequest;
      Response: TWebResponse; var Handled: Boolean);
    procedure WebModule2adminAction(Sender: TObject; Request: TWebRequest;
      Response: TWebResponse; var Handled: Boolean);
  private
    { Private declarations }
    head, body, foot, page: string;
    pos: integer;
    htmlw: Boolean;
    html: TStringList;
    admin_pass: string;
    r_name: string;
    home: string;
    page_def: integer;
    maxn, maxs, maxv, maxw: integer;
    maxline: integer;
    w_regist: Int64;
    autolink, tag: Boolean;
    mudai: string;
    re_color: string;
    no_hosts, no_words: TStringList;
    l_count: integer;
    admin_log: Boolean;
    loginlist: TStringList;
    function LinkContent(path: string): string;
    function footer(path: string): string;
    function contentstring(dataset: TDataSetPageProducer): string;
    procedure createview;
  public
    { Public declarations }
  end;

const
    GAIBU: Boolean = true;

var
  WebModule2: TWebModule2;

implementation

uses WebReq, DateUtils;

{$R *.DFM}

procedure TWebModule2.WebModuleCreate(Sender: TObject);
begin
//ここで初期化するとデバッグモードと設置段階とで挙動が異なるので好ましくない
//ローカル変数以外宣言してはいけない
//* <body>タグ */
        body := '<body bgcolor="#ddf2ed" text="#444444" link="#0000AA">';
//* 一ページあたりの表示記事数 */
        page_def := 10;

        l_count:=5;
        pos:=-1;
//* 文字数制限（名前、題名、本文）全角だとこの半分です */
        maxn  := 40;
        maxs  := 40;
        maxv  := 1500;

        maxw:=160;
//* 本文の改行数制限 */
        maxline := 25;
//* 同一ホストからの連続投稿を制限
//  --> 秒数を記述するとその時間以上を経過しないと連続投稿できない*/
        w_regist := 5;
//* 文中で自動リンクするかどうか（yes=1 no=0）*/
        autolink := true;
//* HTMLタグを有効にするか（yes=1 no=0)*/
        tag := true;
//* タイトル無しで投稿された場合 */
        mudai := '(無題)';
//* ＞がついた時の色 */
        re_color := '#225588';


        htmlw:=true;
//* 外部書き込み禁止にする?(する=1,しない=0) */
//define("GAIBU", 0);

        admin_log:=false;
        no_hosts:=TStringList.Create;
        no_words:=TStringList.Create;
        loginlist:=TStringList.Create;
        loginlist.CommaText:='/admin2,/admdel,/stop';
        html:=TStringList.Create;
end;

procedure TWebModule2.WebModuleDestroy(Sender: TObject);
begin
        no_hosts.Free;
        no_words.Free;
        loginlist.Free;
        html.Free;
end;

procedure TWebModule2.WebModuleBeforeDispatch(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  i: integer;
  s, t: string;
begin
  with ASQLite3Query1 do
  begin
        ExecSQL;
        SQL.Clear;
        SQL.Add('CREATE TABLE if not exists pass(week integer, pass text);');
        ExecSQL;
        ASQLite3Table3.Active:=true;
  if ASQLite3Table3.IsEmpty = true then
  begin
    for i:=1 to 7 do
    begin
        ASQLite3Table3.AppendRecord([i,'full']);
    end;
  end;
        SQL.Clear;
        SQL.Add('CREATE TABLE if not exists setting(home text, title1 text, title2 text,');
        SQL.Add(' no_word text, no_host text);');
        ExecSQL;
        SQL.Clear;
        SQL.Add('SELECT home, title1, "no_host" FROM setting;');
        Active:=true;
        t:='http://'+Request.Host+Request.InternalScriptName+'/';
  if IsEmpty = true then
  begin
    if Request.InternalPathInfo <> '/start' then
    begin
        Response.Content:='<form method="POST" action="'+t+'start">home : '+t+
          '<br>title1 : <input type=text name="title1" value="P-BBS" /><br>title2 : <textarea name="title2" col=5 row=10>'+
          '<font size=5 face=Verdana color=gray><b>P-BBS</b></font></textarea><br><input type=submit value="決定" /></form>';
        Handled:=true;
        Exit;
    end;
        s:='';
  end else
  begin
        home:=FieldByName('home').AsString;
        s:=FieldByName('title1').AsString;
        no_hosts.CommaText:=Fields[2].AsString;
  end;
        Active:=false;
  end;
        ASQLite3Table1.Active:=true;
        head:='<html><head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=Shift_JIS"><title>'+s+'</title></head>';
        foot:='[ <a href='+home+'>ホーム</a> ] [ <a href='+home+'admin>管理</a> ]'+
          '<br><br><small><!-- P-BBS v1.232 -->- <a href="http://php.s3.to" target="_top">P-BBS</a> -</small></body></html>';
  if loginlist.IndexOf(Request.InternalPathInfo) = -1 then
  begin

    if Request.CookieFields.Values['admin_pass'] <> '' then
    begin
      if admin_log = true then
      begin
                ASQLite3Query2.ExecSQL;
                Log.Active:=true;
                Log.AppendRecord(['LogOut',DateTimeToStr(Now)]);
                Log.Active:=false;
      end;
      with Response.Cookies.Add do
      begin
        Name:='admin_pass';
        Value:='';
//        Secure:=true;
      end;
    end;

  end else
        if t = home then
  begin
    if ASQLite3Table3.Lookup('week',DayOfWeek(Now),'pass') <> Request.CookieFields.Values['admin_pass'] then
    begin
        Response.Content:='ログインしてください';
        Handled:=true;
    end;
  end else
  begin
        Response.Content:='不正アクセス setting テーブルのhomeカラムを見直してください';
        handled:=true;
  end;
  for i:=0 to no_hosts.Count-1 do
  begin
    if AnsiContainsText(t,no_hosts[i]) = true then
    begin
        Response.StatusCode:=204;
        Handled:=true;
        break;
    end;
  end;
end;

procedure TWebModule2.WebModule2indexAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
        pos:=StrToIntDef(Request.Query,-1);
  if (htmlw = true)and(pos = -1) then
  begin
    if FileExists('index.html') = false then
    begin
        html.Text:=PageProducer2.Content;
        html.SaveToFile('index.html');
    end else
    begin
        html.LoadFromFile('index.html');
    end;
        Response.Content:=html.Text;
  end else
  begin
        r_name:=Request.CookieFields.Values['name'];
        Response.Content:=PageProducer2.Content;
  end;
end;

procedure TWebModule2.WebModuleAfterDispatch(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
        ASQLite3Table1.Active:=false;
        ASQLite3Table3.Active:=false;
end;

procedure TWebModule2.PageProducer2HTMLTag(Sender: TObject; Tag: TTag;
  const TagString: String; TagParams: TStrings; var ReplaceText: String);
begin
  if TagString = 'page_def' then
  begin
        ReplaceText:=IntToStr(page_def);
  end;
  if TagString = 'home' then
  begin
        ReplaceText:=home;
  end;
  if TagString = 'main' then
  begin
        ReplaceText:=contentstring(DataSetPageProducer2);
  end;
  if TagString = 'title2' then
  begin
    with ASQLite3Query1 do
    begin
        Active:=false;
        SQL.Clear;
        SQL.Add('SELECT title2 FROM setting;');
        Active:=true;
        ReplaceText:=FieldByName('title2').AsString;
    end;
  end;
  if TagString = 'r_name' then
  begin
        ReplaceText:=r_name;
  end;
  if TagString = 'foot' then
  begin
        ReplaceText:=footer('');
  end;
end;

procedure TWebModule2.WebModule2RegistAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  i: integer;
  s: string;
  l_name, pass, sub, com: string;
  x: TDateTime;
  y: Int64;
  procedure linecount;
  var
    j: integer;
    t: WideString;
    temp: TStringList;
  begin
        temp:=TStringList.Create;
    try
        temp.Text:=com;
      if temp.Count > maxline then
      begin
                s:=s+'行数が長すぎます<br>';
      end else
      begin
                com:='';
        for j:=0 to temp.Count-1 do
        begin
                t:=temp[j];
          while Length(t) > maxw do
          begin
                com:=com+'<br>'+Copy(t,1,maxw);
                Delete(t,1,maxw);
          end;
                com:=com+'<br>'+t;
        end;
      end;
    finally
        temp.Free;
    end;
  end;
  procedure cookie;
  begin
    with Response.Cookies.Add do
    begin
        Name:='name';
        Value:=Request.Authorization;
    if Value = '' then
    begin
        Value:=Request.ContentFields.Values['name'];
    end;
        Expires:=Now+20;
    end;
  end;
begin
        s:='';
  if Request.Method <> 'POST' then
  begin
        s:=s+'不正な投稿をしないでください<br>';
  end;
  if (GAIBU = false)and(AnsiContainsStr('http://'+Request.Host+Request.InternalScriptName+Request.InternalPathInfo,home) = false) then
  begin
        s:=s+'外部から書き込みできません<br>';
  end;
        l_name:=Request.ContentFields.Values['name'];
        sub:=Request.ContentFields.Values['sub'];
        com:=Request.ContentFields.Values['com'];
        pass:=Request.ContentFields.Values['password'];
  if l_name = '' then
  begin
        l_name:='no name';
  end else
        if Length(name) > maxn then
  begin
        s:=s+'名前が長すぎます<br>';
  end;
  if sub = '' then
  begin
        sub:=mudai;
  end else
        if Length(sub) > maxs then
  begin
        s:=s+'タイトルが長すぎます<br>';
  end;
  if com = '' then
  begin
        s:=s+'本文が書き込まれていません<br>';
  end else
        if Length(com) > maxv then
  begin
        s:=s+'本文が長すぎます<br>';
  end;
  with ASQLite3Query1 do
  begin
        Active:=false;
        SQL.Clear;
        SQL.Add('SELECT "no_word" FROM setting;');
        Active:=true;
        no_words.CommaText:=Fields[0].AsString;
  end;
  for i:=0 to no_words.Count-1 do
  begin
    if (AnsiContainsText(com,no_words[i]) = true)or(AnsiContainsText(sub,no_words[i]) = true)or
      (AnsiContainsText(l_name,no_words[i]) = true) then
    begin
        s:=s+'使用できない言葉が含まれています<br>';
    end;
  end;
        ASQLite3Table1.Last;
        x:=Now;
        y:=SecondsBetween(x,ASQLite3Table1.FieldByName('date').AsFloat);
  if (ASQLite3Table1.FieldByName('com').AsString = com)and
    (ASQLite3Table1.FieldByName('name').AsString = name) then
  begin
        Response.SendRedirect(home);
        Exit;
  end;
  if y < w_regist then
  begin
        s:=s+'混み合っています　残り'+IntToStr(w_regist-y)+'秒<br>';
  end;
        linecount;
        cookie;
  if s <> '' then
  begin
        Response.Content:=head+s+'ブラウザの戻るで移動してください。</body></html>';
  end else
  begin
    if Request.ContentFields.Values['property'] = 'view' then
    begin
        createview;
      with ASQLite3Table2 do
      begin
        TableName:='view';
        Active:=true;
      if IsEmpty = true then
      begin
                i:=1;
      end else
      begin
                i:=FieldByName('no').AsInteger+1;
      end;
        AppendRecord([pass,i,Now,l_name,sub,com]);
        Active:=false;
      end;
        Response.Content:='<table border=1><tr><td>名前</td><td>'+l_name+'</td></tr><tr><td>タイトル</td><td>'+
          sub+'</td></tr><tr><td>コメント</td><td>'+com+'</td></tr></table><form method=post action='+home+
          'view?'+IntToStr(i)+'><input type=submit value="決定">書き直す場合はブラウザの戻る';
        Exit;
    end;
    with ASQLite3Table1 do
    begin
        Last;
    if RecordCount = 0 then
    begin
        i:=0
    end else
    begin
        i:=FieldByName('no').AsInteger+1;
    end;
        AppendRecord([pass,i,Now,l_name,sub,com]);
    end;
        pos:=-1;
    if htmlw = true then
    begin
        html.Text:=PageProducer2.Content;
        html.SaveToFile('index.html');
    end;
        Response.SendRedirect(home);
  end;
end;

procedure TWebModule2.DataSetPageProducer1HTMLTag(Sender: TObject;
  Tag: TTag; const TagString: String; TagParams: TStrings;
  var ReplaceText: String);
begin
  if TagString = 'home' then
  begin
        ReplaceText:=home;
  end else
        if TagString = 'now' then
  begin
        ReplaceText:=DateTimeToStr(ASQLite3Table1.FieldByName('date').AsFloat);
  end else
  begin
        ReplaceText:=ASQLite3Table1.FieldByName(TagString).AsString;
  end;
end;

procedure TWebModule2.WebModule2UsrdelAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  s, t: string;
  no, pwd: string;
begin
        no:=Request.ContentFields.Values['no'];
        pwd:=Request.ContentFields.Values['pwd'];
  if (no = '')or(pwd = '') then
  begin
        t:='削除noまたは削除キーが入力もれです';
  end;
  if ASQLite3Table1.Locate('no',no,[]) = false then
  begin
        t:='該当記事が見当たりません';
  end else
  begin
        s:=ASQLite3Table1.FieldByName('pwd').AsString;
    if s = '' then
    begin
        t:='該当記事には削除キーが設定されていません)';
    end else
        if s <> pwd then
    begin
        t:='削除キーが違います';
    end else
    begin
        ASQLite3Table1.Delete;
    end;
  end;
  if t = '' then
  begin
        Response.SendRedirect(home);
  end else
  begin
        Response.Content:=head+t+'</body></html>';
  end;
end;

procedure TWebModule2.PageProducer1HTMLTag(Sender: TObject; Tag: TTag;
  const TagString: String; TagParams: TStrings; var ReplaceText: String);
begin
  if TagString = 'home' then
  begin
        ReplaceText:=home;
  end;
  if TagString = 'main' then
  begin
        ReplaceText:=contentstring(DataSetPageProducer1);
  end;
  if TagString = 'footer' then
  begin
        ReplaceText:=footer('admin2');
  end;
  if TagString = 'pos' then
  begin
        ReplaceText:=IntToStr(pos);
  end;
end;

procedure TWebModule2.PageProducer3HTMLTag(Sender: TObject; Tag: TTag;
  const TagString: String; TagParams: TStrings; var ReplaceText: String);
begin
  if TagString = 'home' then
  begin
        ReplaceText:=home;
  end;
end;

procedure TWebModule2.WebModule2admdelAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  i, j: integer;
  s: string;
begin
  if (admin_pass <> '')and(Request.CookieFields.Values['admin_pass'] = admin_pass) then
  begin
    for i:=0 to Request.ContentFields.Count-1 do
    begin
        s:=Request.ContentFields.Values[Request.ContentFields.Names[i]];
      if ASQLite3Table1.Locate('no',StrToInt(s),[]) = true then
      begin
                ASQLite3Table1.Delete;
      end;
    end;
    if htmlw = true then
    begin
        j:=pos;
        pos:=-1;
        html.Text:=PageProducer2.Content;
        html.SaveToFile('index.html');
        pos:=j;
    end;
  end;
        Response.SendRedirect(home+'admin2?'+Request.Query);
end;

function TWebModule2.LinkContent(path: string): string;
var
  i, j: integer;
begin
        result:='';
  if pos > l_count div 2 then
  begin
        j:=-(l_count div 2);
  end else
  begin
        j:=-pos;
  end;
  for i:=0 to l_count-1 do
  begin
    if ASQLite3Table1.RecordCount < (pos+i+j)*page_def then
    begin
        break;
    end;
    if i+j = 0 then
    begin
        result:=result+'　'+IntToStr(pos)+'　';
    end else
    begin
        result:=result+Format('　<a href="'+home+path+'?%d">%d</a>　',[pos+i+j,pos+i+j]);
    end;
  end;
end;

procedure TWebModule2.WebModule2errorAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
        Response.SendRedirect(home);
end;

function TWebModule2.footer(path: string): string;
var
  s, t, u: string;
  i: integer;
begin
  if pos <= -1 then
  begin
        s:='<hr size=1>最新%d件の記事を表示<br><center>Pages:[<b>';
        page:='<<'+LinkContent(path)+'>>]　最新<br></center>';
        result:=Format(s,[page_def])+page+foot;
  end else
  begin
    if pos = 0 then
    begin
        t:='?0';
        u:='?'+IntToStr(pos+1);
    end else
    begin
        i:=ASQLite3Table1.RecordCount div page_def;
        t:='?'+IntToStr(pos-1);
      if pos = i then
      begin
                u:='?'+IntToStr(i);
      end else
      begin
                u:='?'+IntToStr(pos+1);
      end;
    end;
        page:='<a href="'+home+path+t+'"><<</a>'+LinkContent(path)+
          '<a href="'+home+path+u+'">>></a>]　<a href="'+home+path+'">最新</a></b></center>';
        s:='<hr size=1>%d　件中<br> %d 番目から %d 番目の記事を表示<br><center>Page:[<b>';
        result:=Format(s,[ASQLite3Table1.RecordCount,pos*page_def,(pos+1)*page_def-1])+page+foot;
  end;
end;

procedure TWebModule2.WebModule2viewAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  i: integer;
  p, n, d, s, c: string;
begin
        i:=StrToIntDef(Request.Query,0);
  if i > 0 then
  begin
        createview;
    with ASQLite3Table2 do
    begin
        TableName:='view';
        Active:=true;
    if Locate('no',i,[]) = true then
    begin
        p:=FieldByName('pass').AsString;
        n:=FieldByName('name').AsString;
        d:=FieldByName('date').AsString;
        s:=FieldByName('sub').AsString;
        c:=FieldByName('com').AsString;
      with ASQLite3Table1 do
      begin
      if Eof and Bof then
      begin
                i:=0;
      end else
      begin
                Last;
                i:=FieldByName('no').AsInteger+1;
      end;
        AppendRecord([p,i,d,n,s,c]);
      end;
        Delete;
        pos:=-1;
      if htmlw = true then
      begin
                html.Text:=PageProducer2.Content;
                html.SaveToFile('index.html');
      end;
    end;
        Active:=false;
    end;
  end;
        Response.SendRedirect(home);
end;

function TWebModule2.contentstring(dataset: TDataSetPageProducer): string;
var
  i: integer;
begin
  with ASQLite3Table1 do
  begin
  if (pos < -1)or((pos+1)*page_def > RecordCount) then
  begin
    if pos < -1 then
    begin
        pos:=0;
    end else
    begin
        pos:=RecordCount div page_def;
    end;
  end;
  if pos = -1 then
  begin
    if RecordCount > page_def then
    begin
        RecNo:=RecordCount-page_def+1;
    end else
    begin
        First;
    end;
  end else
  begin
        RecNo:=pos*page_def+1;
  end;
        i:=0;
  while (Eof = false)and(i < page_def) do
  begin
        result:=dataset.Content+result;
        Next;
        inc(i);
  end;
  end;
end;

procedure TWebModule2.WebModule2startAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  h, t1, t2, c1, c2: string;
  x: Boolean;
begin
        h:='http://'+Request.Host+Request.InternalScriptName+'/';
        t1:=Request.ContentFields.Values['title1'];
        t2:=Request.ContentFields.Values['title2'];
        c1:='死ね,馬鹿,novapublic';
        c2:='kantei.go.jp,anonymizer.com,pt$,ph$,my$,th$,rr.com';
  with ASQLite3Table2 do
  begin
        TableName:='setting';
        Active:=true;
        x:=IsEmpty;
    if x = true then
    begin
        AppendRecord([h,t1,t2,c1,c2]);
    end;
        Active:=false;
  end;
  if x = true then
  begin
        Response.SendRedirect(h);
  end else
  begin
        Response.Content:='error';
  end;
end;

procedure TWebModule2.createview;
begin
  with ASQLite3Query1 do
  begin
        SQL.Clear;
        SQL.Add('CREATE TABLE if not exists view(pass text, no integer, date real, name text, sub text, com text);');
        ExecSQL;
  end;
end;

procedure TWebModule2.stopitemsHTMLTag(Sender: TObject; Tag: TTag;
  const TagString: String; TagParams: TStrings; var ReplaceText: String);
begin
  if TagString = 'home' then
  begin
        ReplaceText:=home;
  end;
  if TagString = 'no_word' then
  begin
    with ASQLite3Query1 do
    begin
        Active:=false;
        SQL.Clear;
        SQL.Add('SELECT "no_word" FROM setting;');
        Active:=true;
        no_words.CommaText:=Fields[0].AsString;
    end;
        ReplaceText:=no_words.Text;
  end;
  if TagString = 'no_host' then
  begin
        ReplaceText:=no_hosts.Text;
  end;
end;

procedure TWebModule2.WebModule2stopAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  i: integer;
begin
  if Request.MethodType = mtPost then
  begin
        no_words.Text:=Request.ContentFields.Values['word'];
        no_hosts.Text:=Request.ContentFields.Values['host'];
    for i:=0 to no_words.Count-1 do
    begin
        no_words[i]:=Trim(no_words[i]);
    end;
    for i:=0 to no_hosts.Count-1 do
    begin
        no_hosts[i]:=Trim(no_hosts[i]);
    end;
    with ASQLite3Table2 do
    begin
        TableName:='setting';
        Active:=true;
        Edit;
        Fields[3].AsString:=no_words.CommaText;
        Fields[4].AsString:=no_hosts.CommaText;
        Post;
        Active:=false;
    end;
        Response.SendRedirect(home+'admin2');
  end else
  begin
        Response.Content:=stopitems.Content;
  end;
end;

procedure TWebModule2.WebModule2adminAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  pwd: string;
begin
  if Request.MethodType = mtPost then
  begin
    if (Request.ContentFields.IndexOfName('apass') = -1)or(Request.MethodType <> mtPost) then
    begin
        pwd:=Request.CookieFields.Values['admin_pass'];
    end else
    begin
        pwd:=Request.ContentFields.Values['apass'];
    end;
    if (admin_log = true)and(Request.ContentFields.Values['apass'] <> '') then
    begin
        ASQLite3Query2.ExecSQL;
        Log.Active:=true;
        Log.AppendRecord(['LogIn',DateTimeToStr(Now)]);
        Log.Active:=false;
    end;
    with Response.Cookies.Add do
    begin
        Name:='admin_pass';
        Value:=pwd;
//        Secure:=true;
    end;
        pos:=StrToIntDef(Request.Query,-1);
        Response.SendRedirect(home+'admin2');
  end else
  begin
        Response.Content:=PageProducer3.Content;
  end;
end;

initialization
  if WebRequestHandler <> nil then
    WebRequestHandler.WebModuleClass := TWebModule2;

end.
