-
Notifications
You must be signed in to change notification settings - Fork 7
/
gseen.c
330 lines (304 loc) · 8.8 KB
/
gseen.c
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
* Copyright (C) 2000,2001 Florian Sander
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define MAKING_GSEEN
#define MODULE_NAME "gseen"
#define MODULE_VERSION "1.2.0"
#define MODULE_NUMVERSION 10200
#include "../module.h"
#include "../irc.mod/irc.h"
#include "../server.mod/server.h"
#include "../channels.mod/channels.h"
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h> /* for time_t */
#undef global
static Function *global = NULL, *irc_funcs = NULL, *server_funcs = NULL, *channels_funcs = NULL;
#ifndef EGG_IS_MIN_VER
#define EGG_IS_MIN_VER(ver) ((ver) <= 10400)
#endif
#ifndef EGG_IS_MAX_VER
#define EGG_IS_MAX_VER(ver) ((ver) >= 10400)
#endif
#ifndef Context
#define Context context
#endif
#ifndef findchan_by_dname
#define findchan_by_dname findchan
#endif
#include "gseen.h"
#include "seenlang.h"
static struct slang_header *coreslangs = NULL;
static gseenres *results = NULL;
static seenreq *requests = NULL;
static ignoredword *ignoredwords = NULL;
static char *bnsnick = NULL;
static char *bnschan = NULL;
static char *seen_reply = NULL;
static char *temp_wildmatch_host;
static int numresults = 0;
static double glob_presearch, glob_aftersearch;
int numseens, glob_total_queries;
double glob_total_searchtime;
static char gseenfile[121] = "gseen.dat";
static char no_pub[121];
static char quiet_seen[121];
static char quiet_ai_seen[121];
static char no_log[121];
static char ignore_words[1024];
static char default_slang[21] = "eng";
static int gseen_numversion = MODULE_NUMVERSION;
static int save_seens = 60;
static int save_seens_temp = 1;
static int expire_seens = 60;
static int maxseen_thr = 0;
static int maxseen_time = 0;
static int seenflood_thr = 0;
static time_t seenflood_time = 0;
static int use_handles = 0;
static int tell_seens = 1;
static int botnet_seen = 1;
int fuzzy_search = 1; // search for the same user under a differnt nick
static int wildcard_search = 1;// allow wildcard seaching? ("*!*@*.isp.de")
static int max_matches = 500; // break if there are more than X matches
static int hide_secret_chans = 1; // #chan (+secret) => [secret]
static int seen_nick_len = 9;
#include "global_vars.c"
#define SLANG_NOTYPES 1
#define SLANG_NOFACTS 1
#define SLANG_NOGETALL 1
#define SLANG_NOVALIDATE 1
#include "slang.c"
#include "slang_gseen_commands.c"
#include "generic_binary_tree.c"
#include "seentree.c"
#include "datahandling.c"
#include "sensors.c"
#include "do_seen.c"
#include "gseencmds.c"
#include "ai.c"
#include "misc.c"
#include "tclcmds.c"
static int gseen_expmem()
{
int size = 0;
size += seentree_expmem();
size += expmem_seenresults();
size += expmem_seenreq();
size += expmem_ignoredwords();
size += slang_expmem(coreslangs);
size += slang_glob_expmem();
size += slang_chanlang_expmem(chanlangs);
if (bnsnick)
size += strlen(bnsnick) + 1;
if (bnschan)
size += strlen(bnschan) + 1;
if (seen_reply) {
size += strlen(seen_reply) + 1;
}
return size;
}
static void free_gseen()
{
seentree_free();
slang_free(coreslangs);
slang_chanlang_free(chanlangs);
if (seen_reply)
nfree(seen_reply);
return;
}
/* a report on the module status */
static void gseen_report(int idx, int details)
{
int size = 0;
Context;
if (details) {
size = gseen_expmem();
dprintf(idx, " using %d bytes\n", size);
}
}
static void gseen_minutely ()
{
if (save_seens_temp >= save_seens) {
write_seens();
save_seens_temp = 1;
} else
save_seens_temp++;
}
static void gseen_daily ()
{
Context;
purge_seens();
}
static tcl_strings my_tcl_strings[] =
{
{"gseenfile", gseenfile, 121, 0},
{"ai-seen-ignore", ignore_words, 1024, 0},
{"no-pub-seens", no_pub, 121, 0},
{"quiet-seens", quiet_seen, 121, 0},
{"quiet-ai-seens", quiet_ai_seen, 121, 0},
{"no-log", no_log, 121, 0},
{"no-seendata", no_log, 121, 0},
{"default-slang", default_slang, 20, 0},
{0, 0, 0, 0}
};
static tcl_ints my_tcl_ints[] =
{
{"save-seens", &save_seens, 0},
{"expire-seens", &expire_seens, 0},
{"use-handles", &use_handles, 0},
{"tell-seens", &tell_seens, 0},
{"botnet-seens", &botnet_seen, 0},
{"max-matches", &max_matches, 0},
{"fuzzy-search", &fuzzy_search, 0},
{"wildcard-search", &wildcard_search, 0},
{"hide-secret-chans", &hide_secret_chans, 0},
{"seen-nick-len", &seen_nick_len, 0},
{0, 0, 0}
};
static tcl_coups my_tcl_coups[] =
{
{"max-seens", &maxseen_thr, &maxseen_time},
{0, 0, 0},
};
static char *gseen_close()
{
Context;
write_seens();
slang_glob_free();
free_gseen();
free_seenreq();
free_seenresults();
free_ignoredwords();
if (bnsnick)
nfree(bnsnick);
if (bnschan)
nfree(bnschan);
rem_tcl_strings(my_tcl_strings);
rem_tcl_ints(my_tcl_ints);
rem_tcl_coups(my_tcl_coups);
rem_tcl_commands(mytcls);
rem_tcl_commands(gseentcls);
rem_tcl_commands(seendebugtcls);
rem_tcl_commands(gseentcls);
rem_builtins(H_dcc, mydcc);
rem_builtins(H_join, seen_join);
rem_builtins(H_kick, seen_kick);
rem_builtins(H_nick, seen_nick);
rem_builtins(H_part, seen_part);
rem_builtins(H_sign, seen_sign);
rem_builtins(H_splt, seen_splt);
rem_builtins(H_rejn, seen_rejn);
rem_builtins(H_pub, seen_pub);
rem_builtins(H_msg, seen_msg);
rem_builtins(H_bot, seen_bot);
del_hook(HOOK_MINUTELY, (Function) gseen_minutely);
del_hook(HOOK_DAILY, (Function) gseen_daily);
module_undepend(MODULE_NAME);
return NULL;
}
char *gseen_start();
static Function gseen_table[] =
{
(Function) gseen_start,
(Function) gseen_close,
(Function) gseen_expmem,
(Function) gseen_report,
/* 4 - 7 */
(Function) findseens,
(Function) free_seenresults,
(Function) gseen_duration,
(Function) & glob_seendat,
(Function) & numresults,
(Function) & fuzzy_search,
(Function) & numseens,
(Function) & glob_total_queries,
(Function) & glob_total_searchtime,
(Function) & gseen_numversion,
};
char *gseen_start(Function * global_funcs)
{
global = global_funcs;
Context;
module_register(MODULE_NAME, gseen_table, 1, 2);
if (!(irc_funcs = module_depend(MODULE_NAME, "irc", 1, 0)))
return "You need the irc module to use the gseen module.";
if (!(server_funcs = module_depend(MODULE_NAME, "server", 1, 0)))
return "You need the server module to use the gseen module.";
if (!(channels_funcs = module_depend(MODULE_NAME, "channels", 1, 0)))
return "You need the channels module to use the gseen module.";
if (!module_depend(MODULE_NAME, "eggdrop", 108, 0)) {
if (!module_depend(MODULE_NAME, "eggdrop", 107, 0)) {
if (!module_depend(MODULE_NAME, "eggdrop", 106, 0)) {
if (!module_depend(MODULE_NAME, "eggdrop", 105, 0)) {
if (!module_depend(MODULE_NAME, "eggdrop", 104, 0)) {
module_undepend(MODULE_NAME);
return "This module requires eggdrop1.4.0 or later";
}
}
}
}
}
chanlangs = NULL;
coreslangs = NULL;
slang_glob_init();
results = NULL;
requests = NULL;
ignoredwords = NULL;
bnsnick = NULL;
bnschan = NULL;
seen_reply = NULL;
numresults = 0;
numseens = 0;
glob_total_queries = 0;
glob_total_searchtime = 0.0;
ignore_words[0] = 0;
no_pub[0] = 0;
quiet_seen[0] = 0;
no_log[0] = 0;
seentree_init();
add_tcl_strings(my_tcl_strings);
add_tcl_ints(my_tcl_ints);
add_tcl_coups(my_tcl_coups);
add_tcl_commands(mytcls);
add_tcl_commands(seendebugtcls);
add_tcl_commands(gseentcls);
add_builtins(H_dcc, mydcc);
add_builtins(H_join, seen_join);
add_builtins(H_kick, seen_kick);
add_builtins(H_nick, seen_nick);
add_builtins(H_part, seen_part);
add_builtins(H_sign, seen_sign);
add_builtins(H_sign, seen_sign);
add_builtins(H_splt, seen_splt);
add_builtins(H_rejn, seen_rejn);
add_builtins(H_pub, seen_pub);
add_builtins(H_msg, seen_msg);
add_builtins(H_bot, seen_bot);
read_seens();
add_hook(HOOK_MINUTELY, (Function) gseen_minutely);
add_hook(HOOK_DAILY, (Function) gseen_daily);
#if EGG_IS_MIN_VER(10503)
initudef(1, "noseendata", 1);
initudef(1, "quietseens", 1);
initudef(1, "quietaiseens", 1);
initudef(1, "nopubseens", 1);
#endif
glob_slang_cmd_list = slang_commands_list_add(glob_slang_cmd_list, slang_text_gseen_command_table);
putlog(LOG_MISC, "*", "gseen.mod v%s loaded.", MODULE_VERSION);
return NULL;
}