27
27
#include "tandem.h"
28
28
#include "modules.h"
30
extern Tcl_Interp *interp;
31
extern tcl_timer_t *timer,
33
extern struct dcc_t *dcc;
34
extern int dcc_total, backgrd, parties, make_userfile,
35
do_restart, remote_boots, max_dcc;
36
extern char botnetnick[];
37
extern party_t *party;
38
extern tand_t *tandbot;
42
extern unsigned long otraffic_irc, otraffic_irc_today, itraffic_irc, itraffic_irc_today, otraffic_bn, otraffic_bn_today, itraffic_bn, itraffic_bn_today, otraffic_dcc, otraffic_dcc_today, itraffic_dcc, itraffic_dcc_today, otraffic_trans, otraffic_trans_today, itraffic_trans, itraffic_trans_today, otraffic_unknown, otraffic_unknown_today, itraffic_unknown, itraffic_unknown_today;
45
static struct portmap *root = NULL;
30
extern Tcl_Interp *interp;
31
extern tcl_timer_t *timer, *utimer;
32
extern struct dcc_t *dcc;
33
extern char botnetnick[];
34
extern int dcc_total, backgrd, parties, make_userfile, do_restart, max_dcc,
36
extern party_t *party;
37
extern tand_t *tandbot;
39
extern unsigned long otraffic_irc, otraffic_irc_today, itraffic_irc,
40
itraffic_irc_today, otraffic_bn, otraffic_bn_today,
41
itraffic_bn, itraffic_bn_today, otraffic_dcc,
42
otraffic_dcc_today, itraffic_dcc, itraffic_dcc_today,
43
otraffic_trans, otraffic_trans_today, itraffic_trans,
44
itraffic_trans_today, otraffic_unknown, itraffic_unknown,
45
otraffic_unknown_today, itraffic_unknown_today;
46
static struct portmap *root = NULL;
48
49
int expmem_tcldcc(void)
261
268
module_entry *me;
263
270
BADARGS(2, 4, " idx ?channel? ?console-modes?");
264
272
i = findidx(atoi(argv[1]));
265
273
if (i < 0 || dcc[i].type != &DCC_CHAT) {
266
274
Tcl_AppendResult(irp, "invalid idx", NULL);
267
275
return TCL_ERROR;
270
279
for (arg = 2; arg < argc; arg++) {
271
280
if (argv[arg][0] && ((strchr(CHANMETA, argv[arg][0]) != NULL) ||
272
(argv[arg][0] == '*'))) {
281
(argv[arg][0] == '*'))) {
273
282
if ((argv[arg][0] != '*') && (!findchan_by_dname(argv[arg]))) {
274
/* If we dont find the channel, and it starts with a +... assume it
275
* should be the console flags to set.
277
if (argv[arg][0]=='+')
283
/* If we dont find the channel, and it starts with a +, assume it
284
* should be the console flags to set. */
285
if (argv[arg][0] == '+')
278
286
goto do_console_flags;
279
Tcl_AppendResult(irp, "invalid channel", NULL);
287
Tcl_AppendResult(irp, "invalid channel", NULL);
282
290
strncpyz(dcc[i].u.chat->con_chan, argv[arg], 81);
284
292
if ((argv[arg][0] != '+') && (argv[arg][0] != '-'))
285
dcc[i].u.chat->con_flags = 0;
293
dcc[i].u.chat->con_flags = 0;
287
295
for (j = 0; j < strlen(argv[arg]); j++) {
288
if (argv[arg][j] == '+')
290
else if (argv[arg][j] == '-')
296
if (argv[arg][j] == '+')
298
else if (argv[arg][j] == '-')
298
dcc[i].u.chat->con_flags |= logmodes(s);
300
dcc[i].u.chat->con_flags &= ~logmodes(s);
306
dcc[i].u.chat->con_flags |= logmodes(s);
308
dcc[i].u.chat->con_flags &= ~logmodes(s);
474
488
BADARGS(2, 3, " idx ?reason?");
475
490
idx = findidx(atoi(argv[1]));
477
492
Tcl_AppendResult(irp, "invalid idx", NULL);
478
493
return TCL_ERROR;
480
/* Don't kill terminal socket */
481
if ((dcc[idx].sock == STDOUT) && !backgrd)
496
if ((dcc[idx].sock == STDOUT) && !backgrd) /* Don't kill terminal socket */
483
/* Make sure 'whom' info is updated for other bots */
484
if (dcc[idx].type->flags & DCT_CHAT) {
500
if (dcc[idx].type->flags & DCT_CHAT) { /* Make sure 'whom' info is updated */
485
501
chanout_but(idx, dcc[idx].u.chat->channel, "*** %s has left the %s%s%s\n",
486
dcc[idx].nick, dcc[idx].u.chat ? "channel" : "partyline",
487
argc == 3 ? ": " : "", argc == 3 ? argv[2] : "");
502
dcc[idx].nick, dcc[idx].u.chat ? "channel" : "partyline",
503
argc == 3 ? ": " : "", argc == 3 ? argv[2] : "");
488
504
botnet_send_part_idx(idx, argc == 3 ? argv[2] : "");
489
505
if ((dcc[idx].u.chat->channel >= 0) &&
490
(dcc[idx].u.chat->channel < GLOBAL_CHANS))
506
(dcc[idx].u.chat->channel < GLOBAL_CHANS))
491
507
check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
492
dcc[idx].u.chat->channel);
508
dcc[idx].u.chat->channel);
493
509
check_tcl_chof(dcc[idx].nick, dcc[idx].sock);
494
/* Notice is sent to the party line, the script can add a reason. */
496
511
killsock(dcc[idx].sock);
623
/* list of { nick bot host flag idletime awaymsg [channel]}
625
644
static int tcl_whom STDVAR
627
char c[2], idle[11], work[20], *list[7], *p;
647
char c[2], idle[11], work[20], *p;
648
EGG_CONST char *list[7];
630
650
BADARGS(2, 2, " chan");
631
652
if (argv[1][0] == '*')
634
655
if ((argv[1][0] < '0') || (argv[1][0] > '9')) {
635
656
Tcl_SetVar(interp, "chan", argv[1], 0);
636
657
if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) != TCL_OK) ||
637
!interp->result[0]) {
638
Tcl_AppendResult(irp, "channel name is invalid", NULL);
658
!interp->result[0]) {
659
Tcl_AppendResult(irp, "channel name is invalid", NULL);
641
662
chan = atoi(interp->result);
643
664
chan = atoi(argv[1]);
644
665
if ((chan < 0) || (chan > 199999)) {
645
Tcl_AppendResult(irp, "channel out of range; must be 0 thru 199999",
666
Tcl_AppendResult(irp, "channel out of range; must be 0 through 199999",
647
668
return TCL_ERROR;
650
671
for (i = 0; i < dcc_total; i++)
651
672
if (dcc[i].type == &DCC_CHAT) {
652
673
if (dcc[i].u.chat->channel == chan || chan == -1) {
655
egg_snprintf(idle, sizeof idle, "%lu", (now - dcc[i].timeval) / 60);
656
list[0] = dcc[i].nick;
657
list[1] = botnetnick;
658
list[2] = dcc[i].host;
661
list[5] = dcc[i].u.chat->away ? dcc[i].u.chat->away : "";
663
egg_snprintf(work, sizeof work, "%d", dcc[i].u.chat->channel);
666
p = Tcl_Merge((chan == -1) ? 7 : 6, list);
667
Tcl_AppendElement(irp, p);
668
Tcl_Free((char *) p);
676
egg_snprintf(idle, sizeof idle, "%lu", (now - dcc[i].timeval) / 60);
677
list[0] = dcc[i].nick;
678
list[1] = botnetnick;
679
list[2] = dcc[i].host;
682
list[5] = dcc[i].u.chat->away ? dcc[i].u.chat->away : "";
684
egg_snprintf(work, sizeof work, "%d", dcc[i].u.chat->channel);
687
p = Tcl_Merge((chan == -1) ? 7 : 6, list);
688
Tcl_AppendElement(irp, p);
689
Tcl_Free((char *) p);
671
692
for (i = 0; i < parties; i++) {
1035
1071
/* IRC traffic */
1036
1072
sprintf(buf, "irc %ld %ld %ld %ld", itraffic_irc_today, itraffic_irc +
1037
itraffic_irc_today, otraffic_irc_today, otraffic_irc + otraffic_irc_today);
1038
Tcl_AppendElement(irp, buf);
1073
itraffic_irc_today, otraffic_irc_today,
1074
otraffic_irc + otraffic_irc_today);
1075
Tcl_AppendElement(irp, buf);
1040
1077
/* Botnet traffic */
1041
1078
sprintf(buf, "botnet %ld %ld %ld %ld", itraffic_bn_today, itraffic_bn +
1042
itraffic_bn_today, otraffic_bn_today, otraffic_bn + otraffic_bn_today);
1079
itraffic_bn_today, otraffic_bn_today,
1080
otraffic_bn + otraffic_bn_today);
1043
1081
Tcl_AppendElement(irp, buf);
1045
1083
/* Partyline */
1046
sprintf(buf, "partyline %ld %ld %ld %ld", itraffic_dcc_today, itraffic_dcc +
1047
itraffic_dcc_today, otraffic_dcc_today, otraffic_dcc + otraffic_dcc_today);
1084
sprintf(buf, "partyline %ld %ld %ld %ld", itraffic_dcc_today, itraffic_dcc +
1085
itraffic_dcc_today, otraffic_dcc_today,
1086
otraffic_dcc + otraffic_dcc_today);
1048
1087
Tcl_AppendElement(irp, buf);
1051
sprintf(buf, "transfer %ld %ld %ld %ld", itraffic_trans_today, itraffic_trans +
1052
itraffic_trans_today, otraffic_trans_today, otraffic_trans + otraffic_trans_today);
1090
sprintf(buf, "transfer %ld %ld %ld %ld", itraffic_trans_today,
1091
itraffic_trans + itraffic_trans_today, otraffic_trans_today,
1092
otraffic_trans + otraffic_trans_today);
1053
1093
Tcl_AppendElement(irp, buf);
1055
1095
/* Misc traffic */
1056
sprintf(buf, "misc %ld %ld %ld %ld", itraffic_unknown_today, itraffic_unknown +
1057
itraffic_unknown_today, otraffic_unknown_today, otraffic_unknown +
1058
otraffic_unknown_today);
1096
sprintf(buf, "misc %ld %ld %ld %ld", itraffic_unknown_today,
1097
itraffic_unknown + itraffic_unknown_today, otraffic_unknown_today,
1098
otraffic_unknown + otraffic_unknown_today);
1059
1099
Tcl_AppendElement(irp, buf);
1062
in_total_today = itraffic_irc_today + itraffic_bn_today + itraffic_dcc_today +
1063
itraffic_trans_today + itraffic_unknown_today,
1064
in_total = in_total_today + itraffic_irc + itraffic_bn + itraffic_dcc +
1065
itraffic_trans + itraffic_unknown;
1066
out_total_today = otraffic_irc_today + otraffic_bn_today + otraffic_dcc_today +
1067
itraffic_trans_today + otraffic_unknown_today,
1102
in_total_today = itraffic_irc_today + itraffic_bn_today +
1103
itraffic_dcc_today + itraffic_trans_today +
1104
itraffic_unknown_today;
1105
in_total = in_total_today + itraffic_irc + itraffic_bn + itraffic_dcc +
1106
itraffic_trans + itraffic_unknown;
1107
out_total_today = otraffic_irc_today + otraffic_bn_today +
1108
otraffic_dcc_today + itraffic_trans_today +
1109
otraffic_unknown_today;
1068
1110
out_total = out_total_today + otraffic_irc + otraffic_bn + otraffic_dcc +
1069
otraffic_trans + otraffic_unknown;
1070
sprintf(buf, "total %ld %ld %ld %ld", in_total_today, in_total, out_total_today, out_total);
1111
otraffic_trans + otraffic_unknown;
1112
sprintf(buf, "total %ld %ld %ld %ld", in_total_today, in_total,
1113
out_total_today, out_total);
1071
1114
Tcl_AppendElement(irp, buf);
1075
tcl_cmds tcldcc_cmds[] =
1077
{"putdcc", tcl_putdcc},
1078
{"putdccraw", tcl_putdccraw},
1079
{"putidx", tcl_putdcc},
1080
{"dccsimul", tcl_dccsimul},
1081
{"dccbroadcast", tcl_dccbroadcast},
1082
{"hand2idx", tcl_hand2idx},
1083
{"getchan", tcl_getchan},
1084
{"setchan", tcl_setchan},
1085
{"dccputchan", tcl_dccputchan},
1086
{"console", tcl_console},
1087
{"strip", tcl_strip},
1090
{"control", tcl_control},
1091
{"valididx", tcl_valididx},
1092
{"killdcc", tcl_killdcc},
1093
{"putbot", tcl_putbot},
1094
{"putallbots", tcl_putallbots},
1095
{"idx2hand", tcl_idx2hand},
1097
{"botlist", tcl_botlist},
1098
{"dcclist", tcl_dcclist},
1100
{"dccused", tcl_dccused},
1101
{"getdccidle", tcl_getdccidle},
1102
{"getdccaway", tcl_getdccaway},
1103
{"setdccaway", tcl_setdccaway},
1104
{"islinked", tcl_islinked},
1106
{"unlink", tcl_unlink},
1107
{"connect", tcl_connect},
1108
{"listen", tcl_listen},
1110
{"rehash", tcl_rehash},
1111
{"restart", tcl_restart},
1112
{"traffic", tcl_traffic},
1118
tcl_cmds tcldcc_cmds[] = {
1119
{"putdcc", tcl_putdcc},
1120
{"putdccraw", tcl_putdccraw},
1121
{"putidx", tcl_putdcc},
1122
{"dccsimul", tcl_dccsimul},
1123
{"dccbroadcast", tcl_dccbroadcast},
1124
{"hand2idx", tcl_hand2idx},
1125
{"getchan", tcl_getchan},
1126
{"setchan", tcl_setchan},
1127
{"dccputchan", tcl_dccputchan},
1128
{"console", tcl_console},
1129
{"strip", tcl_strip},
1132
{"control", tcl_control},
1133
{"valididx", tcl_valididx},
1134
{"killdcc", tcl_killdcc},
1135
{"putbot", tcl_putbot},
1136
{"putallbots", tcl_putallbots},
1137
{"idx2hand", tcl_idx2hand},
1139
{"botlist", tcl_botlist},
1140
{"dcclist", tcl_dcclist},
1142
{"dccused", tcl_dccused},
1143
{"getdccidle", tcl_getdccidle},
1144
{"getdccaway", tcl_getdccaway},
1145
{"setdccaway", tcl_setdccaway},
1146
{"islinked", tcl_islinked},
1148
{"unlink", tcl_unlink},
1149
{"connect", tcl_connect},
1150
{"listen", tcl_listen},
1152
{"rehash", tcl_rehash},
1153
{"restart", tcl_restart},
1154
{"traffic", tcl_traffic},