forked from CyberShadow/MyWormNET
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLists.pas
More file actions
239 lines (214 loc) · 5.81 KB
/
Copy pathLists.pas
File metadata and controls
239 lines (214 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
unit Lists;
{-------------------------------------------------------------------------------
| White/banlists unit.
| (C) StepS - 2014
|-------------------------------------------------------------------------------
| FEATURES:
|
| - Hold the lists and provide interface for their usage
| - Get and update lists in files
-------------------------------------------------------------------------------}
{$IFDEF FPC}
{$mode DELPHI}
{$ENDIF}
interface
uses
Classes, DateUtils;
type
TListEntry = class(TObject)
private
SetAt: TDateTime;
Duration: Integer;
function HasExpired: Boolean;
public
Name, SetBy, Comment: string;
Permanent: Boolean;
Relatives: TStringList;
property Expired: Boolean read HasExpired;
end;
var
WhitePassauthThreadList: TThreadList;
WhiteNickThreadList: TThreadList;
WhiteIPThreadList: TThreadList;
IPBanThreadList: TThreadList;
NickBanThreadList: TThreadList;
procedure GetListFromFile(var ThreadList: TThreadList; FileName: string);
procedure UpdateListInFile(var ThreadList: TThreadList; FileName: string);
procedure RemoveListEntry(var ThreadList: TThreadList; Name: String);
function InList(var ThreadList: TThreadList; Name: String): Boolean;
function ValidateRelativity(var ThreadList: TThreadList; Name, Relative: String): Boolean;
function RelativeExists(var ThreadList: TThreadList; Relative: String): Boolean;
procedure FreeObjectsFromThreadList(var ThreadList: TThreadList);
function NewListEntry(Name, SetBy, Comment: string; Permanent: Boolean; SetAt: TDateTime; Duration: Integer): TListEntry;
implementation
uses
Types, SysUtils, Data, Base;
procedure GetListFromFile(var ThreadList: TThreadList; FileName: string);
var
Buf, Line: string;
ListEntry: TListEntry;
begin
FreeObjectsFromThreadList(ThreadList);
Buf:=GetTextFile(FileName);
while GetLine(Buf,Line) do
begin
Line:=Trim(Line);
if Line <> '' then
begin
if Pos(' ', Line) <> 0 then
begin
ListEntry:=NewListEntry(StringSection(Line, 0), ServerHost, 'Server-listed', true, Now, -1);
Line:=ContinuedSection(Line, 1)+',';
while Pos(',', Line) <> 0 do
begin
ListEntry.Relatives.Add(Trim(Copy(Line, 1, Pos(',',Line)-1)));
Delete(Line, 1, Pos(',',Line));
end;
ThreadList.Add(ListEntry);
end
else
ThreadList.Add(NewListEntry(StringSection(Line, 0), ServerHost, 'Server-listed', true, Now, -1));
end;
end;
end;
procedure UpdateListInFile(var ThreadList: TThreadList; FileName: string);
var
I: Integer;
F: text;
List: TList;
begin
{$I-}
List:=ThreadList.LockList;
ForceDirectoriesEx(FileName);
AssignFile(F, FileName);
Rewrite(F);
for I:=0 to List.Count-1 do
WriteLn(F, TListEntry(List[I]).Name);
CloseFile(F);
ThreadList.UnlockList;
{$I+}
end;
function InList(var ThreadList: TThreadList; Name: String): Boolean;
var
I: Integer;
List: TList;
begin
Result:=false;
List:=ThreadList.LockList;
for I:=0 to List.Count-1 do
if TextMatch(TListEntry(List[I]).Name, Name) then
begin
if not TListEntry(List[I]).Expired then
Result := true;
Break;
end;
ThreadList.UnlockList;
end;
function ValidateRelativity(var ThreadList: TThreadList; Name, Relative: String): Boolean;
var
I, J: Integer;
Found, Checked: Boolean;
ListEntry: TListEntry;
List: TList;
begin
Result:=true;
Found:=false;
Checked:=false;
List:=ThreadList.LockList;
for I := 0 to List.Count-1 do
begin
ListEntry:=TListEntry(List[I]);
if TextMatch(ListEntry.Name, Name) then
begin
Found:=true;
for J := 0 to ListEntry.Relatives.Count-1 do
if TextMatch(ListEntry.Relatives[J], Relative) then
begin
Checked:=true;
Break
end;
end;
end;
ThreadList.UnlockList;
if not Found or Checked then
Result:=true
else if Found and not Checked then
Result:=false;
end;
function RelativeExists(var ThreadList: TThreadList; Relative: String): Boolean;
var
I, J: Integer;
ListEntry: TListEntry;
List: TList;
begin
Result:=false;
List:=ThreadList.LockList;
for I := 0 to List.Count-1 do
begin
ListEntry:=TListEntry(List[I]);
for J := 0 to ListEntry.Relatives.Count-1 do
if TextMatch(ListEntry.Relatives[J], Relative) then
begin
Result:=true;
Break
end;
end;
ThreadList.UnlockList;
end;
procedure RemoveListEntry(var ThreadList: TThreadList; Name: String);
var
I: Integer;
List: TList;
begin
List:=ThreadList.LockList;
for I:=List.Count-1 downto 0 do
if TextMatch(TListEntry(List[I]).Name, Name) then
begin
List.Remove(List[I]);
TListEntry(List[I]).Free;
Break;
end;
ThreadList.UnlockList;
end;
function NewListEntry(Name, SetBy, Comment: string; Permanent: Boolean; SetAt: TDateTime; Duration: Integer): TListEntry;
begin
Result:=TListEntry.Create;
Result.Name:=Name;
Result.SetBy:=SetBy;
Result.Comment:=Comment;
Result.Permanent:=Permanent;
Result.SetAt:=SetAt;
Result.Duration:=Duration;
Result.Relatives:=TStringList.Create;
end;
procedure FreeObjectsFromThreadList(var ThreadList: TThreadList);
var
I: Integer;
List: TList;
begin
List:=ThreadList.LockList;
for I := 0 to List.Count-1 do
TObject(List[I]).Free;
List.Clear;
ThreadList.UnlockList;
end;
function TListEntry.HasExpired: Boolean;
begin
Result:=false;
if not Permanent then
if SecondsBetween(Now, SetAt) > Duration then
Result:=true;
end;
initialization
WhitePassauthThreadList:=TThreadList.Create;
WhiteNickThreadList:=TThreadList.Create;
WhiteIPThreadList:=TThreadList.Create;
IPBanThreadList:=TThreadList.Create;
NickBanThreadList:=TThreadList.Create;
finalization
WhitePassauthThreadList.Free;
WhiteNickThreadList.Free;
WhiteIPThreadList.Free;
IPBanThreadList.Free;
NickBanThreadList.Free;
end.