|
|
1.1 root 1: /* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */
2:
3: /* $Id: LoginAttemptsFormUnit.cpp,v 1.3 2011/09/14 04:25:01 rswindell Exp $ */
4:
5: /****************************************************************************
6: * @format.tab-size 4 (Plain Text/Source Code File Header) *
7: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
8: * *
9: * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
10: * *
11: * This program is free software; you can redistribute it and/or *
12: * modify it under the terms of the GNU General Public License *
13: * as published by the Free Software Foundation; either version 2 *
14: * of the License, or (at your option) any later version. *
15: * See the GNU General Public License for more details: gpl.txt or *
16: * http://www.fsf.org/copyleft/gpl.html *
17: * *
18: * Anonymous FTP access to the most recent released source is available at *
19: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
20: * *
21: * Anonymous CVS access to the development source and modification history *
22: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
23: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
24: * (just hit return, no password is necessary) *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
26: * *
27: * For Synchronet coding style and modification guidelines, see *
28: * http://www.synchro.net/source.html *
29: * *
30: * You are encouraged to submit any modifications (preferably in Unix diff *
31: * format) via e-mail to [email protected] *
32: * *
33: * Note: If this box doesn't appear square, then you need to fix your tabs. *
34: ****************************************************************************/
35: //---------------------------------------------------------------------------
36:
37: #include "sbbs.h"
38: #include <vcl.h>
39: #include <vcl/Clipbrd.hpp>
40: #pragma hdrstop
41:
42: #include "LoginAttemptsFormUnit.h"
43: #include "MainFormUnit.h"
44: #include "userdat.h"
45: //---------------------------------------------------------------------------
46: #pragma package(smart_init)
47: #pragma resource "*.dfm"
48: TLoginAttemptsForm *LoginAttemptsForm;
49: extern link_list_t login_attempt_list;
50:
51: //---------------------------------------------------------------------------
52: __fastcall TLoginAttemptsForm::TLoginAttemptsForm(TComponent* Owner)
53: : TForm(Owner)
54: {
55: }
56: //---------------------------------------------------------------------------
57: void __fastcall TLoginAttemptsForm::FillListView(TObject *Sender)
58: {
59: char str[128];
60: TListItem* Item;
61: list_node_t* node;
62: struct tm tm;
63: login_attempt_t* attempt;
64:
65: Screen->Cursor=crAppStart;
66:
67: listLock(&login_attempt_list);
68:
69: ListView->AllocBy=listCountNodes(&login_attempt_list);
70:
71: ListView->Items->BeginUpdate();
72:
73: for(node=login_attempt_list.first; node!=NULL; node=node->next) {
74: attempt=(login_attempt_t*)node->data;
75: if(attempt==NULL)
76: continue;
77: Item=ListView->Items->Add();
78: Item->Caption=AnsiString(attempt->count-attempt->dupes);
79: Item->Data=(void*)attempt->time;
80: Item->SubItems->Add(attempt->dupes);
81: Item->SubItems->Add(inet_ntoa(attempt->addr));
82: Item->SubItems->Add(attempt->prot);
83: Item->SubItems->Add(attempt->user);
84: Item->SubItems->Add(attempt->pass);
85: localtime_r(&attempt->time,&tm);
86: sprintf(str,"%u/%u %02u:%02u:%02u"
87: ,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
88: Item->SubItems->Add(str);
89: }
90: ListView->AlphaSort();
91: ListView->Items->EndUpdate();
92:
93: listUnlock(&login_attempt_list);
94: Screen->Cursor=crDefault;
95: }
96: //---------------------------------------------------------------------------
97: void __fastcall TLoginAttemptsForm::FormShow(TObject *Sender)
98: {
99: ColumnToSort=0;
100: SortBackwards=true;
101: FillListView(Sender);
102: }
103:
104: //---------------------------------------------------------------------------
105: void __fastcall TLoginAttemptsForm::FormClose(TObject *Sender,
106: TCloseAction &Action)
107: {
108: ListView->Items->BeginUpdate();
109: ListView->Items->Clear();
110: ListView->Items->EndUpdate();
111: }
112: //---------------------------------------------------------------------------
113: void __fastcall TLoginAttemptsForm::ListViewColumnClick(TObject *Sender,
114: TListColumn *Column)
115: {
116: if(Column->Index == ColumnToSort)
117: SortBackwards=!SortBackwards;
118: else
119: SortBackwards=false;
120: ColumnToSort = Column->Index;
121: ((TCustomListView *)Sender)->AlphaSort();
122: }
123: //---------------------------------------------------------------------------
124: void __fastcall TLoginAttemptsForm::ListViewCompare(TObject *Sender,
125: TListItem *Item1, TListItem *Item2, int Data, int &Compare)
126: {
127: /* Decimal compare */
128: if (ColumnToSort < 2 || ColumnToSort == 6) {
129: int num1, num2;
130: if(ColumnToSort==6) { /* Date */
131: num1=(ulong)Item1->Data;
132: num2=(ulong)Item2->Data;
133: } else if(ColumnToSort==0) {
134: num1=Item1->Caption.ToIntDef(0);
135: num2=Item2->Caption.ToIntDef(0);
136: } else {
137: int ix = ColumnToSort - 1;
138: num1=Item1->SubItems->Strings[ix].ToIntDef(0);
139: num2=Item2->SubItems->Strings[ix].ToIntDef(0);
140: }
141: if(SortBackwards)
142: Compare=(num2-num1);
143: else
144: Compare=(num1-num2);
145: } else {
146: int ix = ColumnToSort - 1;
147: if(SortBackwards)
148: Compare = CompareText(Item2->SubItems->Strings[ix]
149: ,Item1->SubItems->Strings[ix]);
150: else
151: Compare = CompareText(Item1->SubItems->Strings[ix]
152: ,Item2->SubItems->Strings[ix]);
153: }
154:
155: }
156: //---------------------------------------------------------------------------
157: static AnsiString ListItemString(TListItem* item)
158: {
159: AnsiString str = item->Caption;
160: int i;
161:
162: for(i=0;i<item->SubItems->Count;i++)
163: str += "\t" + item->SubItems->Strings[i];
164:
165: return str + "\r\n";
166: }
167: //---------------------------------------------------------------------------
168: void __fastcall TLoginAttemptsForm::CopyPopupClick(TObject *Sender)
169: {
170: if(ListView->Selected==NULL)
171: return;
172: Clipboard()->SetTextBuf(ListItemString(ListView->Selected).c_str());
173: }
174: //---------------------------------------------------------------------------
175:
176: void __fastcall TLoginAttemptsForm::CopyAllPopupClick(TObject *Sender)
177: {
178: AnsiString buf;
179: int i;
180:
181: for(i=0;i<ListView->Items->Count;i++)
182: buf += ListItemString(ListView->Items->Item[i]);
183:
184: Clipboard()->SetTextBuf(buf.c_str());
185: }
186: //---------------------------------------------------------------------------
187:
188: void __fastcall TLoginAttemptsForm::RefreshPopupClick(TObject *Sender)
189: {
190: ListView->Items->BeginUpdate();
191: ListView->Items->Clear();
192: ListView->Items->EndUpdate();
193: FillListView(Sender);
194: }
195: //---------------------------------------------------------------------------
196:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.