Skip to content
Snippets Groups Projects
Commit cb211b47 authored by rswindell's avatar rswindell
Browse files

Added copy/refresh support.

parent da141f4c
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,7 @@
#include "sbbs.h"
#include <vcl.h>
#include <vcl/Clipbrd.hpp>
#pragma hdrstop
#include "LoginAttemptsFormUnit.h"
......@@ -53,7 +54,7 @@ __fastcall TLoginAttemptsForm::TLoginAttemptsForm(TComponent* Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TLoginAttemptsForm::FormShow(TObject *Sender)
void __fastcall TLoginAttemptsForm::FillListView(TObject *Sender)
{
char str[128];
TListItem* Item;
......@@ -61,8 +62,6 @@ void __fastcall TLoginAttemptsForm::FormShow(TObject *Sender)
struct tm tm;
login_attempt_t* attempt;
ColumnToSort=0;
SortBackwards=false;
Screen->Cursor=crAppStart;
listLock(&login_attempt_list);
......@@ -71,12 +70,12 @@ void __fastcall TLoginAttemptsForm::FormShow(TObject *Sender)
ListView->Items->BeginUpdate();
for(node=listFirstNode(&login_attempt_list); node!=NULL; node=listNextNode(node)) {
for(node=login_attempt_list.first; node!=NULL; node=node->next) {
attempt=(login_attempt_t*)node->data;
if(attempt==NULL)
continue;
Item=ListView->Items->Add();
Item->Caption=AnsiString(attempt->count);
Item->Caption=AnsiString(attempt->count-attempt->dupes);
Item->Data=(void*)attempt->time;
Item->SubItems->Add(attempt->dupes);
Item->SubItems->Add(inet_ntoa(attempt->addr));
......@@ -88,11 +87,20 @@ void __fastcall TLoginAttemptsForm::FormShow(TObject *Sender)
,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
Item->SubItems->Add(str);
}
ListView->AlphaSort();
ListView->Items->EndUpdate();
listUnlock(&login_attempt_list);
Screen->Cursor=crDefault;
}
//---------------------------------------------------------------------------
void __fastcall TLoginAttemptsForm::FormShow(TObject *Sender)
{
ColumnToSort=0;
SortBackwards=true;
FillListView(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TLoginAttemptsForm::FormClose(TObject *Sender,
TCloseAction &Action)
......@@ -122,9 +130,13 @@ void __fastcall TLoginAttemptsForm::ListViewCompare(TObject *Sender,
if(ColumnToSort==6) { /* Date */
num1=(ulong)Item1->Data;
num2=(ulong)Item2->Data;
} else {
} else if(ColumnToSort==0) {
num1=Item1->Caption.ToIntDef(0);
num2=Item2->Caption.ToIntDef(0);
} else {
int ix = ColumnToSort - 1;
num1=Item1->SubItems->Strings[ix].ToIntDef(0);
num2=Item2->SubItems->Strings[ix].ToIntDef(0);
}
if(SortBackwards)
Compare=(num2-num1);
......@@ -142,3 +154,43 @@ void __fastcall TLoginAttemptsForm::ListViewCompare(TObject *Sender,
}
//---------------------------------------------------------------------------
static AnsiString ListItemString(TListItem* item)
{
AnsiString str = item->Caption;
int i;
for(i=0;i<item->SubItems->Count;i++)
str += "\t" + item->SubItems->Strings[i];
return str + "\r\n";
}
//---------------------------------------------------------------------------
void __fastcall TLoginAttemptsForm::CopyPopupClick(TObject *Sender)
{
if(ListView->Selected==NULL)
return;
Clipboard()->SetTextBuf(ListItemString(ListView->Selected).c_str());
}
//---------------------------------------------------------------------------
void __fastcall TLoginAttemptsForm::CopyAllPopupClick(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());
}
//---------------------------------------------------------------------------
void __fastcall TLoginAttemptsForm::RefreshPopupClick(TObject *Sender)
{
ListView->Items->BeginUpdate();
ListView->Items->Clear();
ListView->Items->EndUpdate();
FillListView(Sender);
}
//---------------------------------------------------------------------------
object LoginAttemptsForm: TLoginAttemptsForm
Left = 522
Top = 454
Left = 729
Top = 203
Width = 496
Height = 793
BorderIcons = [biSystemMenu, biMaximize]
Caption = 'Failed Login Attempts'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
......@@ -10,6 +11,7 @@ object LoginAttemptsForm: TLoginAttemptsForm
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = False
Position = poDefault
OnClose = FormClose
......@@ -24,7 +26,7 @@ object LoginAttemptsForm: TLoginAttemptsForm
Align = alClient
Columns = <
item
Caption = 'Count'
Caption = 'Unique'
end
item
Caption = 'Dupes'
......@@ -49,9 +51,29 @@ object LoginAttemptsForm: TLoginAttemptsForm
AutoSize = True
Caption = 'Time'
end>
PopupMenu = PopupMenu
TabOrder = 0
ViewStyle = vsReport
OnColumnClick = ListViewColumnClick
OnCompare = ListViewCompare
end
object PopupMenu: TPopupMenu
Left = 168
Top = 184
object CopyPopup: TMenuItem
Caption = 'Copy'
ShortCut = 16451
OnClick = CopyPopupClick
end
object CopyAllPopup: TMenuItem
Caption = 'Copy All'
ShortCut = 16449
OnClick = CopyAllPopupClick
end
object RefreshPopup: TMenuItem
Caption = 'Refresh'
ShortCut = 116
OnClick = RefreshPopupClick
end
end
end
......@@ -8,18 +8,27 @@
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <Menus.hpp>
//---------------------------------------------------------------------------
class TLoginAttemptsForm : public TForm
{
__published: // IDE-managed Components
TListView *ListView;
TPopupMenu *PopupMenu;
TMenuItem *CopyPopup;
TMenuItem *CopyAllPopup;
TMenuItem *RefreshPopup;
void __fastcall FormShow(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall ListViewColumnClick(TObject *Sender,
TListColumn *Column);
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 RefreshPopupClick(TObject *Sender);
private: // User declarations
void __fastcall FillListView(TObject *Sender);
public: // User declarations
__fastcall TLoginAttemptsForm(TComponent* Owner);
int ColumnToSort;
......
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