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

Support removing login attempt entries

Include the time-span of the login attempts in the reason string.
parent 516a01a6
No related branches found
No related tags found
No related merge requests found
Pipeline #5051 passed
...@@ -59,12 +59,14 @@ void __fastcall TLoginAttemptsForm::FillListView(TObject *Sender) ...@@ -59,12 +59,14 @@ void __fastcall TLoginAttemptsForm::FillListView(TObject *Sender)
ListView->Items->BeginUpdate(); ListView->Items->BeginUpdate();
for(node=login_attempt_list.first; node!=NULL; node=node->next) { for(node=login_attempt_list.first; node!=NULL; node=node->next) {
attempt=(login_attempt_t*)node->data; if(node->data == NULL)
if(attempt==NULL)
continue; continue;
if((attempt = (login_attempt_t*)malloc(sizeof(*attempt))) == NULL)
continue;
*attempt = *(login_attempt_t*)node->data;
Item=ListView->Items->Add(); Item=ListView->Items->Add();
Item->Caption=AnsiString(attempt->count-attempt->dupes); Item->Caption=AnsiString(attempt->count-attempt->dupes);
Item->Data=(void*)attempt->time; Item->Data=(void*)attempt;
Item->SubItems->Add(attempt->dupes); Item->SubItems->Add(attempt->dupes);
if(inet_addrtop(&attempt->addr, str, sizeof(str))==NULL) if(inet_addrtop(&attempt->addr, str, sizeof(str))==NULL)
strcpy(str, "<invalid address>"); strcpy(str, "<invalid address>");
...@@ -118,8 +120,8 @@ void __fastcall TLoginAttemptsForm::ListViewCompare(TObject *Sender, ...@@ -118,8 +120,8 @@ void __fastcall TLoginAttemptsForm::ListViewCompare(TObject *Sender,
if (ColumnToSort < 2 || ColumnToSort == 6) { if (ColumnToSort < 2 || ColumnToSort == 6) {
int num1, num2; int num1, num2;
if(ColumnToSort==6) { /* Date */ if(ColumnToSort==6) { /* Date */
num1=(ulong)Item1->Data; num1 = ((login_attempt_t*)Item1->Data)->time;
num2=(ulong)Item2->Data; num2 = ((login_attempt_t*)Item2->Data)->time;
} else if(ColumnToSort==0) { } else if(ColumnToSort==0) {
num1=Item1->Caption.ToIntDef(0); num1=Item1->Caption.ToIntDef(0);
num2=Item2->Caption.ToIntDef(0); num2=Item2->Caption.ToIntDef(0);
...@@ -199,14 +201,15 @@ void __fastcall TLoginAttemptsForm::FilterIpMenuItemClick(TObject *Sender) ...@@ -199,14 +201,15 @@ void __fastcall TLoginAttemptsForm::FilterIpMenuItemClick(TObject *Sender)
ListItem=ListView->Selected; ListItem=ListView->Selected;
State << isSelected; State << isSelected;
Screen->Cursor=crHourGlass;
ListView->Items->BeginUpdate();
while(ListItem!=NULL) { while(ListItem!=NULL) {
struct in_addr addr; struct in_addr addr;
HOSTENT* h; HOSTENT* h;
AnsiString ip_addr = ListItem->SubItems->Strings[1]; AnsiString ip_addr = ListItem->SubItems->Strings[1];
AnsiString prot = ListItem->SubItems->Strings[2];
AnsiString username = ListItem->SubItems->Strings[3];
if(!repeat) { if(!repeat) {
Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm); Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
wsprintf(str,"Disallow future connections from %s?", ip_addr); wsprintf(str,"Disallow future connections from %s?", ip_addr);
...@@ -235,22 +238,30 @@ void __fastcall TLoginAttemptsForm::FilterIpMenuItemClick(TObject *Sender) ...@@ -235,22 +238,30 @@ void __fastcall TLoginAttemptsForm::FilterIpMenuItemClick(TObject *Sender)
if(res != mrOk) if(res != mrOk)
break; break;
} }
login_attempt_t* attempt = (login_attempt_t*)ListItem->Data;
if(attempt != NULL) {
char* hostname = NULL; char* hostname = NULL;
addr.s_addr=inet_addr(ip_addr.c_str()); addr.s_addr=inet_addr(ip_addr.c_str());
Screen->Cursor=crHourGlass;
h=gethostbyaddr((char *)&addr,sizeof(addr),AF_INET); h=gethostbyaddr((char *)&addr,sizeof(addr),AF_INET);
Screen->Cursor=crDefault;
if(h!=NULL) if(h!=NULL)
hostname = h->h_name; hostname = h->h_name;
filter_ip(&MainForm->cfg, prot.c_str(), (AnsiString(ListItem->Caption) + " " STR_FAILED_LOGIN_ATTEMPTS).c_str(), hostname char tmp[128];
,ip_addr.c_str(), username.c_str() AnsiString reason = ListItem->Caption + AnsiString(" " STR_FAILED_LOGIN_ATTEMPTS " in ");
reason += duration_estimate_to_str(attempt->time - attempt->first, tmp, sizeof tmp, 1, 1);
if(filter_ip(&MainForm->cfg, attempt->prot, reason.c_str(), hostname
,ip_addr.c_str(), attempt->user
,trashcan_fname(&MainForm->cfg, silent ? "ip-silent" : "ip", fname, sizeof fname) ,trashcan_fname(&MainForm->cfg, silent ? "ip-silent" : "ip", fname, sizeof fname)
,duration); ,duration)) {
loginSuccess(&login_attempt_list, &attempt->addr);
ListItem->Delete();
}
}
if(ListView->Selected == NULL) if(ListView->Selected == NULL)
break; break;
ListItem=ListView->GetNextItem(ListItem,sdAll,State); ListItem=ListView->GetNextItem(ListItem,sdAll,State);
} }
ListView->Items->EndUpdate();
Screen->Cursor=crDefault;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -298,3 +309,33 @@ void __fastcall TLoginAttemptsForm::ClearListMenuItemClick(TObject *Sender) ...@@ -298,3 +309,33 @@ void __fastcall TLoginAttemptsForm::ClearListMenuItemClick(TObject *Sender)
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void __fastcall TLoginAttemptsForm::ListViewDeletion(TObject *Sender,
TListItem *Item)
{
free(Item->Data);
}
//---------------------------------------------------------------------------
void __fastcall TLoginAttemptsForm::Remove1Click(TObject *Sender)
{
TItemStates State;
TListItem* ListItem = ListView->Selected;
State << isSelected;
Screen->Cursor=crHourGlass;
ListView->Items->BeginUpdate();
while (ListItem != NULL) {
login_attempt_t* attempt = (login_attempt_t*)ListItem->Data;
if(attempt != NULL) {
loginSuccess(&login_attempt_list, &attempt->addr);
ListItem->Delete();
}
ListItem=ListView->GetNextItem(ListItem, sdAll, State);
}
ListView->Items->EndUpdate();
Screen->Cursor=crDefault;
}
//---------------------------------------------------------------------------
...@@ -61,6 +61,7 @@ object LoginAttemptsForm: TLoginAttemptsForm ...@@ -61,6 +61,7 @@ object LoginAttemptsForm: TLoginAttemptsForm
ViewStyle = vsReport ViewStyle = vsReport
OnColumnClick = ListViewColumnClick OnColumnClick = ListViewColumnClick
OnCompare = ListViewCompare OnCompare = ListViewCompare
OnDeletion = ListViewDeletion
end end
object PopupMenu: TPopupMenu object PopupMenu: TPopupMenu
Left = 168 Left = 168
...@@ -92,5 +93,10 @@ object LoginAttemptsForm: TLoginAttemptsForm ...@@ -92,5 +93,10 @@ object LoginAttemptsForm: TLoginAttemptsForm
Caption = 'Clear List' Caption = 'Clear List'
OnClick = ClearListMenuItemClick OnClick = ClearListMenuItemClick
end end
object Remove1: TMenuItem
Caption = 'Remove'
ShortCut = 46
OnClick = Remove1Click
end
end end
end end
...@@ -21,6 +21,7 @@ __published: // IDE-managed Components ...@@ -21,6 +21,7 @@ __published: // IDE-managed Components
TMenuItem *FilterIpMenuItem; TMenuItem *FilterIpMenuItem;
TMenuItem *ResolveHostnameMenuItem; TMenuItem *ResolveHostnameMenuItem;
TMenuItem *ClearListMenuItem; TMenuItem *ClearListMenuItem;
TMenuItem *Remove1;
void __fastcall FormShow(TObject *Sender); void __fastcall FormShow(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action); void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall ListViewColumnClick(TObject *Sender, void __fastcall ListViewColumnClick(TObject *Sender,
...@@ -33,6 +34,8 @@ __published: // IDE-managed Components ...@@ -33,6 +34,8 @@ __published: // IDE-managed Components
void __fastcall FilterIpMenuItemClick(TObject *Sender); void __fastcall FilterIpMenuItemClick(TObject *Sender);
void __fastcall ResolveHostnameMenuItemClick(TObject *Sender); void __fastcall ResolveHostnameMenuItemClick(TObject *Sender);
void __fastcall ClearListMenuItemClick(TObject *Sender); void __fastcall ClearListMenuItemClick(TObject *Sender);
void __fastcall ListViewDeletion(TObject *Sender, TListItem *Item);
void __fastcall Remove1Click(TObject *Sender);
private: // User declarations private: // User declarations
void __fastcall FillListView(TObject *Sender); void __fastcall FillListView(TObject *Sender);
public: // User declarations public: // User declarations
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment