shuusei24124:指定ポートへのアクセスを1週間Ban(idea by antiDOM)

diff --dos -wurN 24123/constants.pas 24124/constants.pas
--- 24123/constants.pas	Wed Feb 05 20:44:54 2003
+++ 24124/constants.pas	Sun Feb 09 14:02:58 2003
@@ -43,6 +43,7 @@
  max_announcement             = 63;
  // sockets
  MAX_LISTEN_SOCKET            = 7; // maximum listen sockets
+ MAX_LISTEN_TRAPSOCKET        = 7; // maximum listen trapsockets
  DEF_LISTEN_PORT              = 8888; //3456; // default port for listening
  DEF_LISTEN_PORTS             = '3456 8888';
  RECV_BUF_SIZE_MIN            = 128;
diff --dos -wurN 24123/handler.pas 24124/handler.pas
--- 24123/handler.pas	Sun Feb 09 03:13:46 2003
+++ 24124/handler.pas	Sun Feb 09 15:23:48 2003
@@ -1064,6 +1064,16 @@
    LoginError(GetLangT(LNG_INVALIDSOFTWARE));
    exit;
  end;
+ tmp_pos:=12262;
+ for i:=0 to MAX_LISTEN_TRAPSOCKET do
+ begin
+   if trap_port[i]=0 then continue;
+   if TCPSocket_GetLocalSin(local.socket).sin_port
+     <>TCPSocket_GetLocalSin(trap_socket[i]).sin_port then continue;
+   LoginError('不正なポートにアクセスしようとしています');
+   BanUser(tempnick,servername_t,7*86400,'不正なポートへのアクセス ID:'+tempnick,true);
+   exit;
+ end;
  tmp_pos:=192;
  local.SoftwareId:=GetSoftware(hlist.Strings[3]);
  ResetOnlineRec(rec);
diff --dos -wurN 24123/japanese.lng 24124/japanese.lng
--- 24123/japanese.lng	Tue Jan 28 01:32:24 2003
+++ 24124/japanese.lng	Sun Feb 09 15:59:58 2003
@@ -329,7 +329,7 @@
 BLIST_EXPIRES=期限
 BLIST_REASON=理由
 BLIST_LASTATTEMPT=最終試行時刻
-BLIST_USING=使用ソフト
+BLIST_USING=使用ID|IP
 BLIST_TRIES=試行回数
 BBTN_REFRESH=更新
 BBTN_BAN=Ban
diff --dos -wurN 24123/mainform.pas 24124/mainform.pas
--- 24123/mainform.pas	Sun Feb 09 03:17:46 2003
+++ 24124/mainform.pas	Sun Feb 09 14:28:18 2003
@@ -738,6 +738,11 @@
   server_port[i]:=0;
   server_socket[i]:=INVALID_SOCKET;
  end;
+ for i:=0 to MAX_LISTEN_TRAPSOCKET do
+ begin
+  trap_port[i]:=0;
+  trap_socket[i]:=INVALID_SOCKET;
+ end;
  napigator_socket:=INVALID_SOCKET;
  dagsta_socket:=INVALID_SOCKET;
  stats_socket:=INVALID_SOCKET;
@@ -1420,6 +1425,11 @@
   fakeext:=ini.ReadString('Other2','FakeExt','.zip.avi .zip.mpg');
   StrHash_Reset(fakeext_list);
   SplitString(AnsiLowerCase(fakeext),fakeext_list);
+  enable_trapport:=ini.ReadBool('Other2','EnableTrapPort',false);
+  str:=ini.ReadString('Other2','TrapPort','8888 8875 7743');
+  SplitString(str,list);
+  for i:=0 to list.Count-1 do
+    trap_port[i]:=StrToIntDef(list.Strings[i],0);
   // set up console
   LogStartup('mainform::loadconfig: setting up console user');
   cons_channels:=TMyList.Create;
@@ -1474,6 +1484,7 @@
  ini: TIniFile;
  i: Integer;
  list: TMyStringList;
+ str: String;
  procedure PutInt64(section,value: String; val: Int64);
  begin
    ini.WriteString(section,value,IntToStr(val));
@@ -1853,6 +1864,7 @@
   ini.WriteBool('Other2','AutoBanINCOMPLETE',autoban_incomplete);
   ini.WriteBool('Other2','DisableFakeExt',disable_fakeext);
   ini.WriteString('Other2','FakeExt',fakeext);
+  ini.WriteBool('Other2','EnableTrapPort',enable_trapport);
   finally
   ini.Free;
  end;
diff --dos -wurN 24123/settings.dfm 24124/settings.dfm
--- 24123/settings.dfm	Sun Feb 09 03:17:22 2003
+++ 24124/settings.dfm	Sun Feb 09 16:20:18 2003
@@ -1922,7 +1922,7 @@
           Width = 156
           Height = 20
           Style = csDropDownList
-          ItemHeight = 0
+          ItemHeight = 12
           TabOrder = 9
         end
       end
@@ -2435,7 +2435,7 @@
           Width = 111
           Height = 20
           Style = csDropDownList
-          ItemHeight = 0
+          ItemHeight = 12
           TabOrder = 1
         end
         object Edit_cons_autojoin1: TEdit
@@ -5494,7 +5494,7 @@
           Width = 156
           Height = 20
           Style = csDropDownList
-          ItemHeight = 0
+          ItemHeight = 12
           TabOrder = 9
         end
       end
@@ -5656,21 +5656,21 @@
         BevelOuter = bvNone
         object Label153: TLabel
           Left = 8
-          Top = 8
+          Top = 0
           Width = 333
           Height = 12
           Caption = 'DOM対策 : 共有数/サイズの少ない人の検索/参照/DLをブロック'
         end
         object Label154: TLabel
           Left = 8
-          Top = 120
+          Top = 104
           Width = 332
           Height = 12
           Caption = '投網/連Q対策 : 3分間あたりのDL要求・//WantQueue回数を制限'
         end
         object gb_searchblock: TGroupBox
           Left = 8
-          Top = 24
+          Top = 16
           Width = 169
           Height = 81
           Caption = ' 検索ブロック '
@@ -5736,7 +5736,7 @@
         end
         object gb_domblock: TGroupBox
           Left = 184
-          Top = 24
+          Top = 16
           Width = 169
           Height = 81
           Caption = ' 参照/キューブロック '
@@ -5802,7 +5802,7 @@
         end
         object gb_dlfloodblock: TGroupBox
           Left = 8
-          Top = 136
+          Top = 120
           Width = 169
           Height = 65
           Caption = ' DL数制限 (0=無制限) '
@@ -5857,7 +5857,7 @@
         end
         object gb_wqfloodblock: TGroupBox
           Left = 184
-          Top = 136
+          Top = 120
           Width = 169
           Height = 65
           Caption = '//WantQueue制限 (0=無制限) '
@@ -5912,7 +5912,7 @@
         end
         object cb_nocount_text: TCheckBox
           Left = 8
-          Top = 208
+          Top = 240
           Width = 225
           Height = 17
           Caption = 'テキストファイルは共有数にかぞえない'
@@ -5920,15 +5920,15 @@
         end
         object cb_autoban_incomplete: TCheckBox
           Left = 8
-          Top = 224
-          Width = 241
+          Top = 208
+          Width = 233
           Height = 17
           Caption = 'INCOMPLETEファイルの共有を無効にする'
           TabOrder = 5
         end
         object cb_disable_fakeext: TCheckBox
           Left = 8
-          Top = 240
+          Top = 192
           Width = 225
           Height = 17
           Caption = '拡張子偽装ファイルの共有を無効にする'
@@ -5936,12 +5936,30 @@
           OnClick = cb_disable_fakeextClick
         end
         object edit_fakeext: TEdit
-          Left = 240
-          Top = 238
-          Width = 113
+          Left = 248
+          Top = 190
+          Width = 105
           Height = 20
           TabOrder = 7
           Text = '.zip.avi .zip.mpg'
+          Visible = False
+        end
+        object cb_enable_trapport: TCheckBox
+          Left = 8
+          Top = 224
+          Width = 209
+          Height = 17
+          Caption = '指定ポートへのアクセスを1週間Ban'
+          TabOrder = 8
+          OnClick = cb_enable_trapportClick
+        end
+        object edit_trapport: TEdit
+          Left = 248
+          Top = 222
+          Width = 105
+          Height = 20
+          TabOrder = 9
+          Text = '8888 8875 7743'
           Visible = False
         end
       end
diff --dos -wurN 24123/settings.pas 24124/settings.pas
--- 24123/settings.pas	Sun Feb 09 02:53:00 2003
+++ 24124/settings.pas	Sun Feb 09 14:22:46 2003
@@ -571,6 +571,8 @@
     cb_autoban_incomplete: TCheckBox;
     cb_disable_fakeext: TCheckBox;
     edit_fakeext: TEdit;
+    cb_enable_trapport: TCheckBox;
+    edit_trapport: TEdit;
     procedure Panel3Resize(Sender: TObject);
     procedure headerPaint(Sender: TObject);
     procedure SetTopText(str: String);
@@ -647,6 +649,7 @@
     procedure rd_wqfloodblock_blockClick(Sender: TObject);
     procedure rd_wqfloodblock_leechClick(Sender: TObject);
     procedure cb_disable_fakeextClick(Sender: TObject);
+    procedure cb_enable_trapportClick(Sender: TObject);
   private
     { Private declarations }
     procedure SetBanItems(control: TComboBox);
@@ -1426,6 +1429,10 @@
 end;
 
 procedure TSlavaNapSettings.sh_other2Show(Sender: TObject);
+var
+  i: Integer;
+  str: String;
+  ini: TIniFile;
 begin
  SetTopText('その他の設定2');
  SetChange(true);
@@ -1471,6 +1478,13 @@
  cb_disable_fakeext.Checked:=disable_fakeext;
  edit_fakeext.Visible:=cb_disable_fakeext.Checked;
  edit_fakeext.Text:=fakeext;
+ cb_enable_trapport.Checked:=enable_trapport;
+ ini:=TIniFile.Create(Applicationdir+'config');
+ try
+   edit_trapport.Text:=ini.ReadString('Other2','TrapPort','8888 8875 7743');
+  finally
+   ini.Free;
+ end;
 end;
 
 procedure TSlavaNapSettings.sh_reportShow(Sender: TObject);
@@ -1999,6 +2013,13 @@
    autoban_incomplete:=cb_autoban_incomplete.Checked;
    disable_fakeext:=cb_disable_fakeext.Checked;
    fakeext:=edit_fakeext.Text;
+   enable_trapport:=cb_enable_trapport.Checked;
+   ini:=TIniFile.Create(Applicationdir+'config');
+   try
+     ini.WriteString('Other2','TrapPort',edit_trapport.Text);
+    finally
+     ini.Free;
+   end;
   except
  end;
  btn_restoreClick(nil);
@@ -2416,6 +2437,11 @@
 procedure TSlavaNapSettings.cb_disable_fakeextClick(Sender: TObject);
 begin
   edit_fakeext.Visible:=cb_disable_fakeext.Checked;
+end;
+
+procedure TSlavaNapSettings.cb_enable_trapportClick(Sender: TObject);
+begin
+  edit_trapport.Visible:=cb_enable_trapport.Checked;
 end;
 
 end.
diff --dos -wurN 24123/thread.pas 24124/thread.pas
--- 24123/thread.pas	Sun Feb 09 03:13:38 2003
+++ 24124/thread.pas	Sun Feb 09 16:45:06 2003
@@ -197,6 +197,14 @@
    server_socket[i]:=INVALID_SOCKET;
    dec(sockets_count);
   end;
+  for i:=0 to MAX_LISTEN_TRAPSOCKET do
+  if trap_socket[i]<>INVALID_SOCKET then
+  begin
+   synsock.shutdown(trap_socket[i],SD_BOTH);
+   synsock.closesocket(trap_socket[i]);
+   trap_socket[i]:=INVALID_SOCKET;
+   dec(sockets_count);
+  end;
  DebugLog('ShutDown - 5',true);
   if old_report_socket<>INVALID_SOCKET then
   begin
@@ -760,6 +768,26 @@
    on E:Exception do
     DebugLog('Exception in TMainThread::CreateSockets (pos='+IntToStr(tmp_pos)+') : '+E.Message);
   end;
+ tmp_pos:=12262;
+ if enable_trapport then
+ for i:=0 to MAX_LISTEN_TRAPSOCKET do
+  if trap_port[i]<>0 then
+  try
+    trap_socket[i]:=synsock.socket(PF_INET,integer(SOCK_STREAM),IPPROTO_TCP);
+    inc(sockets_count);
+    if not Listen(trap_socket[i],trap_port[i]) then
+     if trap_socket[i]<>INVALID_SOCKET then
+     begin
+      synsock.shutdown(trap_socket[i],SD_BOTH);
+      synsock.closesocket(trap_socket[i]);
+      trap_socket[i]:=INVALID_SOCKET;
+      dec(sockets_count);
+     end;
+    Synchronize(SyncLog);
+   except
+   on E:Exception do
+    DebugLog('Exception in TMainThread::CreateSockets (pos='+IntToStr(tmp_pos)+') : '+E.Message);
+  end;
   if old_report_enabled then
   try
    tmp_pos:=1519;
@@ -882,6 +910,14 @@
      while TCPSocket_CanRead(server_socket[i],0,last_error) do
      begin
       Accept(server_socket[i]);
+      {$I checksync.pas}
+     end;
+  if enable_trapport then
+  for i:=0 to MAX_LISTEN_TRAPSOCKET do
+   if trap_socket[i]<>INVALID_SOCKET then
+     while TCPSocket_CanRead(trap_socket[i],0,last_error) do
+     begin
+      Accept(trap_socket[i]);
       {$I checksync.pas}
      end;
    except
diff --dos -wurN 24123/vars.pas 24124/vars.pas
--- 24123/vars.pas	Sun Feb 09 02:52:22 2003
+++ 24124/vars.pas	Sun Feb 09 12:58:22 2003
@@ -314,6 +314,9 @@
  disable_fakeext: Boolean;
  fakeext: String;
  fakeext_list: TStringHash;
+ enable_trapport: Boolean;
+ trap_socket: Array[0..MAX_LISTEN_TRAPSOCKET] of HSocket;
+ trap_port: Array[0..MAX_LISTEN_TRAPSOCKET] of Integer;
 implementation
 
 procedure CheckWindows;