Skip to content
Snippets Groups Projects
Commit 928fef57 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Support bulk client/address filtering

Ctrl-A in the Failed Logins dialog now selects-all rather than copy-all (just
use Ctrl-A, then Ctrl-C to copy all).
parent 749a4a96
No related branches found
No related tags found
No related merge requests found
Pipeline #5027 passed
......@@ -91,6 +91,7 @@ void __fastcall TClientForm::FilterIpMenuItemClick(TObject *Sender)
char str[256];
char fname[MAX_PATH + 1];
int res;
bool repeat = false;
TListItem* ListItem;
TItemStates State;
static uint duration = MainForm->global.login_attempt.filter_duration;
......@@ -106,36 +107,44 @@ void __fastcall TClientForm::FilterIpMenuItemClick(TObject *Sender)
AnsiString username = ListItem->SubItems->Strings[1];
AnsiString ip_addr = ListItem->SubItems->Strings[2];
AnsiString hostname = ListItem->SubItems->Strings[3];
Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
wsprintf(str,"Disallow future connections from %s?", ip_addr);
CodeInputForm->Caption = str;
CodeInputForm->Label->Caption = "Address Filter Duration";
CodeInputForm->Edit->Visible = true;
CodeInputForm->Edit->Text = duration ? duration_to_vstr(duration, str, sizeof str) : "Infinite";
CodeInputForm->Edit->Hint = "'Infinite' or number of Seconds/Minutes/Hours/Days/Weeks/Years";
CodeInputForm->Edit->ShowHint = true;
CodeInputForm->CheckBox->Visible = true;
CodeInputForm->CheckBox->Caption = "Silent Filter";
CodeInputForm->CheckBox->Checked = silent;
CodeInputForm->CheckBox->Hint = "No messages logged when blocking this client";
CodeInputForm->CheckBox->ShowHint = true;
res = CodeInputForm->ShowModal();
duration = parse_duration(CodeInputForm->Edit->Text.c_str());
silent = CodeInputForm->CheckBox->Checked;
if(res != mrOk) {
if(!repeat) {
Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
wsprintf(str,"Disallow future connections from %s?", ip_addr);
CodeInputForm->Caption = str;
CodeInputForm->Label->Caption = "Address Filter Duration";
CodeInputForm->Edit->Visible = true;
CodeInputForm->Edit->Text = duration ? duration_to_vstr(duration, str, sizeof str) : "Infinite";
CodeInputForm->Edit->Hint = "'Infinite' or number of Seconds/Minutes/Hours/Days/Weeks/Years";
CodeInputForm->Edit->ShowHint = true;
CodeInputForm->RightCheckBox->Visible = true;
CodeInputForm->RightCheckBox->Caption = "Silent Filter";
CodeInputForm->RightCheckBox->Checked = silent;
CodeInputForm->RightCheckBox->Hint = "No messages logged when blocking this client";
CodeInputForm->RightCheckBox->ShowHint = true;
if(ListView->SelCount > 1) {
CodeInputForm->LeftCheckBox->Visible = true;
CodeInputForm->LeftCheckBox->Caption = "All Selected";
CodeInputForm->LeftCheckBox->Hint = "Filter all selected clients";
CodeInputForm->LeftCheckBox->ShowHint = true;
}
res = CodeInputForm->ShowModal();
duration = parse_duration(CodeInputForm->Edit->Text.c_str());
silent = CodeInputForm->RightCheckBox->Checked;
repeat = CodeInputForm->LeftCheckBox->Checked;
if(res != mrOk) {
delete CodeInputForm;
break;
}
CodeInputForm->Label->Caption = "Reason";
CodeInputForm->Edit->Text = reason;
CodeInputForm->Edit->Hint = "The cause or rationale for the filter";
CodeInputForm->RightCheckBox->Visible = false;
res = CodeInputForm->ShowModal();
SAFECOPY(reason, CodeInputForm->Edit->Text.c_str());
delete CodeInputForm;
break;
if(res != mrOk)
break;
}
CodeInputForm->Label->Caption = "Reason";
CodeInputForm->Edit->Text = reason;
CodeInputForm->Edit->Hint = "The cause or rationale for the filter";
CodeInputForm->CheckBox->Visible = false;
res = CodeInputForm->ShowModal();
SAFECOPY(reason, CodeInputForm->Edit->Text.c_str());
delete CodeInputForm;
if(res != mrOk)
break;
filter_ip(&MainForm->cfg,prot.c_str()
,reason
,hostname.c_str()
......
object CodeInputForm: TCodeInputForm
Left = 569
Top = 374
Left = 1601
Top = 417
BorderStyle = bsDialog
Caption = 'Parameter Required'
ClientHeight = 78
......@@ -71,16 +71,22 @@ object CodeInputForm: TCodeInputForm
TabOrder = 3
Visible = False
end
object CheckBox: TCheckBox
Left = 169
object RightCheckBox: TCheckBox
Left = 140
Top = 44
Width = 74
Width = 107
Height = 17
Alignment = taLeftJustify
BiDiMode = bdLeftToRight
Caption = 'CheckBox'
ParentBiDiMode = False
Caption = 'RightCheckBox'
TabOrder = 4
Visible = False
end
object LeftCheckBox: TCheckBox
Left = 20
Top = 44
Width = 97
Height = 17
Caption = 'LeftCheckBox'
TabOrder = 5
Visible = False
end
end
......@@ -43,7 +43,8 @@ __published:
TLabel *Label;
TComboBox *ComboBox;
TEdit *Edit;
TCheckBox *CheckBox;
TCheckBox *RightCheckBox;
TCheckBox *LeftCheckBox;
void __fastcall FormShow(TObject *Sender);
private:
public:
......
......@@ -157,21 +157,22 @@ static AnsiString ListItemString(TListItem* item)
//---------------------------------------------------------------------------
void __fastcall TLoginAttemptsForm::CopyPopupClick(TObject *Sender)
{
if(ListView->Selected==NULL)
return;
Clipboard()->SetTextBuf(ListItemString(ListView->Selected).c_str());
AnsiString buf;
TItemStates State;
State << isSelected;
TListItem* ListItem = ListView->Selected;
while(ListItem != NULL) {
buf += ListItemString(ListItem);
ListItem = ListView->GetNextItem(ListItem, sdAll, State);
}
Clipboard()->SetTextBuf(buf.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TLoginAttemptsForm::CopyAllPopupClick(TObject *Sender)
void __fastcall TLoginAttemptsForm::SelectAllPopupClick(TObject *Sender)
{
AnsiString buf;
int i;
for(i=0;i<ListView->Items->Count;i++)
buf += ListItemString(ListView->Items->Item[i]);
Clipboard()->SetTextBuf(buf.c_str());
ListView->SelectAll();
}
//---------------------------------------------------------------------------
......@@ -189,6 +190,7 @@ void __fastcall TLoginAttemptsForm::FilterIpMenuItemClick(TObject *Sender)
char str[256];
char fname[MAX_PATH + 1];
int res;
bool repeat = false;
TListItem* ListItem;
TItemStates State;
static uint duration = MainForm->global.login_attempt.filter_duration;
......@@ -205,26 +207,34 @@ void __fastcall TLoginAttemptsForm::FilterIpMenuItemClick(TObject *Sender)
AnsiString ip_addr = ListItem->SubItems->Strings[1];
AnsiString prot = ListItem->SubItems->Strings[2];
AnsiString username = ListItem->SubItems->Strings[3];
Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
wsprintf(str,"Disallow future connections from %s?", ip_addr);
CodeInputForm->Caption = str;
CodeInputForm->Label->Caption = "Address Filter Duration";
CodeInputForm->Edit->Visible = true;
CodeInputForm->Edit->Text = duration ? duration_to_vstr(duration, str, sizeof str) : "Infinite";
CodeInputForm->Edit->Hint = "'Infinite' or number of Seconds/Minutes/Hours/Days/Weeks/Years";
CodeInputForm->Edit->ShowHint = true;
CodeInputForm->CheckBox->Visible = true;
CodeInputForm->CheckBox->Caption = "Silent Filter";
CodeInputForm->CheckBox->Checked = silent;
CodeInputForm->CheckBox->Hint = "No messages logged when blocking this client";
CodeInputForm->CheckBox->ShowHint = true;
res = CodeInputForm->ShowModal();
duration = parse_duration(CodeInputForm->Edit->Text.c_str());
silent = CodeInputForm->CheckBox->Checked;
delete CodeInputForm;
if(res != mrOk)
break;
if(!repeat) {
Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
wsprintf(str,"Disallow future connections from %s?", ip_addr);
CodeInputForm->Caption = str;
CodeInputForm->Label->Caption = "Address Filter Duration";
CodeInputForm->Edit->Visible = true;
CodeInputForm->Edit->Text = duration ? duration_to_vstr(duration, str, sizeof str) : "Infinite";
CodeInputForm->Edit->Hint = "'Infinite' or number of Seconds/Minutes/Hours/Days/Weeks/Years";
CodeInputForm->Edit->ShowHint = true;
CodeInputForm->RightCheckBox->Visible = true;
CodeInputForm->RightCheckBox->Caption = "Silent Filter";
CodeInputForm->RightCheckBox->Checked = silent;
CodeInputForm->RightCheckBox->Hint = "No messages logged when blocking this client";
CodeInputForm->RightCheckBox->ShowHint = true;
if(ListView->SelCount > 1) {
CodeInputForm->LeftCheckBox->Visible = true;
CodeInputForm->LeftCheckBox->Caption = "All Selected";
CodeInputForm->LeftCheckBox->Hint = "Filter all selected addresses";
CodeInputForm->LeftCheckBox->ShowHint = true;
}
res = CodeInputForm->ShowModal();
duration = parse_duration(CodeInputForm->Edit->Text.c_str());
silent = CodeInputForm->RightCheckBox->Checked;
repeat = CodeInputForm->LeftCheckBox->Checked;
delete CodeInputForm;
if(res != mrOk)
break;
}
char* hostname = NULL;
addr.s_addr=inet_addr(ip_addr.c_str());
......
object LoginAttemptsForm: TLoginAttemptsForm
Left = 729
Top = 203
Left = 1802
Top = 407
Width = 496
Height = 793
BorderIcons = [biSystemMenu, biMaximize]
......@@ -17,19 +17,21 @@ object LoginAttemptsForm: TLoginAttemptsForm
OnClose = FormClose
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
TextHeight = 15
object ListView: TListView
Left = 0
Top = 0
Width = 480
Height = 755
Height = 754
Align = alClient
Columns = <
item
Caption = 'Unique Attempts'
Width = 58
end
item
Caption = 'Duplicate Attempts'
Width = 58
end
item
AutoSize = True
......@@ -68,10 +70,10 @@ object LoginAttemptsForm: TLoginAttemptsForm
ShortCut = 16451
OnClick = CopyPopupClick
end
object CopyAllPopup: TMenuItem
Caption = 'Copy All'
object SelectAllPopup: TMenuItem
Caption = 'Select All'
ShortCut = 16449
OnClick = CopyAllPopupClick
OnClick = SelectAllPopupClick
end
object RefreshPopup: TMenuItem
Caption = 'Refresh'
......
......@@ -16,7 +16,7 @@ __published: // IDE-managed Components
TListView *ListView;
TPopupMenu *PopupMenu;
TMenuItem *CopyPopup;
TMenuItem *CopyAllPopup;
TMenuItem *SelectAllPopup;
TMenuItem *RefreshPopup;
TMenuItem *FilterIpMenuItem;
TMenuItem *ResolveHostnameMenuItem;
......@@ -28,7 +28,7 @@ __published: // IDE-managed Components
void __fastcall ListViewCompare(TObject *Sender, TListItem *Item1,
TListItem *Item2, int Data, int &Compare);
void __fastcall CopyPopupClick(TObject *Sender);
void __fastcall CopyAllPopupClick(TObject *Sender);
void __fastcall SelectAllPopupClick(TObject *Sender);
void __fastcall RefreshPopupClick(TObject *Sender);
void __fastcall FilterIpMenuItemClick(TObject *Sender);
void __fastcall ResolveHostnameMenuItemClick(TObject *Sender);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment