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