-
Notifications
You must be signed in to change notification settings - Fork 0
/
akira.tcl
3410 lines (3382 loc) · 127 KB
/
akira.tcl
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# $KYAULabs: akira.tcl,v 2.5.8 2021/11/30 00:30:48 kyau Exp $
#
# █████████▀█ █████████ █ ▀▀▀▀▀▀▀▀▀▀ █████████▀█ █████████▀█
# █████████ █ █████████ █ ██████████ █████████ █ █████████ █
# █████████▀█ █████████▀▄ ██████████ █████████▀▄ █████████▀█
# ───────────────────────── ██████████ ──────────────────bz!────
#
# ak!ra.tcl - botpack for hybrid(core)
# Copyright (C) 2021 KYAU Labs (https://kyaulabs.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
package provide akira 2.0
package require Tcl 8.6
package require hybridcore 1.8.0
package require http 2.9.0
package require htmlparse 1.2.2
package require md5 2.0.7
package require tls 1.7.11
# hybrid(core) overrides {{{
# hybrid(core: basic {{{
set bot-dir [pwd]
set bot-tcl [info script]
set network "ak!ra"
# }}}
# hybrid(core): logs {{{
set max-logs 20
set max-logsize 0
set quick-logs 0
set log-time 1
set timestamp-format {[%H:%M:%S]}
set keep-all-logs 0
set logfile-suffix ".%d%b%Y"
set switch-logfiles-at 100
set quiet-save 0
# }}}
# hybrid(core): console {{{
set console "mkcoblxs"
set userfile-perm 0600
# }}}
# hybrid(core): botnet/dcc/telnet {{{
set botport [set userport 2600]
set share-unlinks 1
set protect-telnet 0
set dcc-sanitycheck 0
set ident-timeout 0
set require-p 1
set open-telnets 0
set stealth-telnets 0
set use-telnet-banner 0
set connect-timeout 15
set dcc-flood-thr 3
set telnet-flood 5:60
set paranoid-telnet-flood 1
set resolve-timeout 7
# }}}
# hybrid(core): ssl {{{
set ssl-capath "/etc/ssl/certs/"
set ssl-cert-auth 0
#set ssl-verify-dcc 0
#set ssl-verify-bots 0
#set ssl-verify-clients 0
#set ssl-verify-servers 0
# }}}
# hybrid(core): more advanced settings {{{
set ignore-time [expr {1+ [rand 8]}][expr {1+ [rand 8]}]
set hourly-updates 00
#set owner "kyau"
#set notify-newusers "$owner"
set default-flags "h"
set whois-fields "created createdby chattrby lastleft lastlinked lastlogin"
set must-be-owner 1
set max-socks 200
set allow-dk-cmds 1
set dupwait-timeout 5
set strict-host 0
set cidr-support 0
# }}}
# hybrid(core): modules {{{
# hybrid(core): module: blowfish {{{
loadmodule blowfish
set blowfish-use-mode cbc
# }}}
# hybrid(core): module: dns {{{
loadmodule dns
#set dns-servers "8.8.8.8 8.8.4.4"
set dns-servers "1.1.1.1"
set dns-cache 86400
set dns-negcache 600
set dns-maxsends 4
set dns-retrydelay 3
# }}}
# hybrid(core): module: channels {{{
loadmodule channels
set force-expire 0
set share-greet 0
set use-info 1
set allow-ps 0
set default-flood-chan 0:0
set default-flood-deop 3:10
set default-flood-kick 3:10
set default-flood-join 5:60
set default-flood-ctcp 3:60
set default-flood-nick 5:60
set default-aop-delay 0:3
set default-idle-kick 0
set default-chanmode "nt"
set default-stopnethack-mode 6
set default-revenge-mode 0
set default-ban-type 18
set default-ban-time 1[expr {[rand 8] +1}][expr {1+ [rand 8]}]
set default-exempt-time 60
set default-invite-time 60
set default-chanset { -autoop -autovoice -bitch -cycle +dontkickops -dynamicbans -dynamicexempts -dynamicinvites +enforcebans -greet -inactive -nodesynch -protectfriends -protectosp -revenge +revengebot -secret -seen +shared -statuslog +userbans +userexempts +userinvites -protecthalfops -autohalfop -static }
# }}}
# hybrid(core): module: server {{{
loadmodule server
set net-type 0
set realname "hybrid(core) \[$network\]"
set default-port +6697
set msg-rate 2
set keep-nick 1
set quiet-reject 1
set lowercase-ctcp 1
set answer-ctcp 3
set flood-msg 5:60
set flood-ctcp 3:60
set server-cycle-wait 15
set server-timeout 20
set check-stoned 1
set serverror-quit 1
set max-queue-msg 300
set trigger-on-ignore 0
set exclusive-binds 0
set double-mode 1
set double-server 1
set double-help 1
set optimize-kicks 1
set stack-limit 4
# }}}
# hybrid(core): module: ctcp {{{
loadmodule ctcp
set ctcp-mode 0
# }}}
# hybrid(core): module: irc {{{
loadmodule irc
set bounce-bans 0
set bounce-exempts 0
set bounce-invites 0
set bounce-modes 0
set max-bans 100
set max-exempts 20
set max-invites 20
set max-modes 30
set learn-users 0
set wait-split 300
set wait-info 600
set mode-buf-length 200
set opchars "@"
set no-chanrec-info 0
# }}}
# hybrid(core): module: transfer {{{
loadmodule transfer
set max-dloads 3
set dcc-block 0
set copy-to-tmp 1
set xfer-timeout 30
# }}}
# hybrid(core): module: share {{{
loadmodule share
# }}}
# hybrid(core): module: compress {{{
loadmodule compress
set share-compressed 1
set compress-level 9
# }}}
# hybrid(core): module: notes {{{
loadmodule notes
set max-notes 5000
set note-life 60
set allow-fwd 0
set notify-users 1
set notify-onjoin 1
# }}}
# hybrid(core): module: console {{{
loadmodule "console"
set console-autosave 1
set force-channel 0
set info-party 0
# }}}
# }}}
# }}}
# ak!ra botpack {{{
namespace eval ::*akira {
# namespace variables
global botnet-nick nick ctcp-version infobot hub server userfile
variable author "kyau"
variable t9version "1.4.5(hc1.8.4)"
variable version "2.5.8+cbc"
variable hcversion "${ctcp-version}"
variable release_date "2021.11.26"
variable ishub 0
variable isinfo 0
variable blowcrypt_version "v3.7"
variable tmon_version "v1.0.4"
# ak!ra: config {{{
namespace eval config {
# ak!ra: config: general {{{
# users to notify when new users/bots are added
variable admins { "kyau" }
# botpack logfile
variable logfile "akira.log"
# botpack logging level (0=none, 1=invite+limit+key+unban, 2=1+ops)
variable loglevel 2
# key used for dcc/schat/telnet verification [encrypt key key]
variable securekey {*epkJSwvIT2Qe2tDPWyxWng==}
# determine modes-per-line from net-type
if {[info exists net-type]} {
switch -- ${net-type} {
0 { # EFnet
variable modes_per_line 4
}
default { # Other Networks
variable modes_per_line 3
}
}
}
# }}}
# ak!ra: config: botnet {{{
# botattr to be considered a local bot
variable control_flag "A"
# default botnet control (* is all)
variable control_default "*"
variable control $control_default
# display partyline users on dcc connection after motd
variable motd_userlist true
# key used for encrypted ops verification
variable bop_opkey {T4EWF7tZXkslyn/3ZEsTP5cHCLCxLYK7b}
# should bots request ops when other bots get ops
variable bop_modeop true
# should bots request ops when they link to the botnet
variable bop_linkop true
# perform op sync, checking that request came from someone with +o
variable bop_osync true
# automatically add hosts for bots with +o that request ops
variable bop_addhost false
# should bots accept invite requests from other bots to get into channels
variable bop_icheck true
# delay between requests bot=>bot, formula: rand() * bot_delay + 2
variable bot_delay 10
# maximum simultaneous bot requests to send out
variable bot_maxreq 2
# }}}
# ak!ra mod: config: anti-idle {{{
# bot anti-idle timer
variable ai_min 10
# }}}
# ak!ra mod: config: autoaway (partyline) {{{
# partyline - enable/disable the autoaway system
variable plaa_active true
# partyline - idle time to automatically set user away
variable plaa_idle 10
# }}}
# ak!ra mod: config: limit {{{
# grace period to automatically check the limit
variable alimit_timer 10
# limit to set above current user count
variable alimit_add 5
# limit plus/minus variation amount
variable alimit_var 2
# }}}
# ak!ra mod: config: blowcrypt {{{
# mode: normal/paranoid (talk unencrypted if no key/don't talk if no key)
variable bc_mode "normal"
# channel key list
variable bc_keys {
{#ak!ra {%$`N:k.k~JF7#v:6:_U<\L*Q@yC]m[6d}}
}
# }}}
}
# }}}
# ak!ra: help {{{
proc help { handle idx args } {
if { [llength [lindex $args 0]] == 0 } {
::*akira::cmdlog "help|${handle}"
putdcc $idx ""
putdcc $idx "\00301,01..\003 \00304,05█▓▒░\003\00305█████▀█ \003\00304,05█▓▒░\003\00305█████ █ \003\00300▀\003▀\00314▀▀▀▀▀▀\003▀\00300▀ \003\00304,05█▓▒░\003\00305█████▀█ \003\00304,05█▓▒░\003\00305█████▀█"
putdcc $idx "\00301,01..\003 \00304,05▓▒░\003\00305██████ █ \003\00304,05▓▒░\003\00305██████ █ \003\00304,05▓▒░\003\00305███████ \003\00304,05▓▒░\003\00305██████ █ \003\00304,05▓▒░\003\00305██████ █"
putdcc $idx "\00301,01..\003 \00304,05▒░\003\00305███████▀█ \003\00304,05▒░\003\00305███████▀▄ \003\00304,05▒░\003\00305████████ \003\00304,05▒░\003\00305███████▀▄ \003\00304,05▒░\003\00305███████▀█"
putdcc $idx "\00301,01.\003\00300─\003─\00314─────────────────────── \003\00304,05░\003\00305█████████ \003\00314──────────────────\003bz!\00314──\003─\00300─\003"
putdcc $idx ""
if {[ matchattr $handle n] } {
# owners
putdcc $idx "\00301,01.\003\00308(owner)\003 commands:"
putdcc $idx "\00301,01..\003 \00314+bot -bot +chan -chan +host -host +telnet -telnet\003"
putdcc $idx "\00301,01..\003 \00314+user -user\003"
putdcc $idx "\00301,01..\003 \00314backup botattr botnick botstat chaddr channels\003"
putdcc $idx "\00301,01..\003 \00314chpass chhandle dccstat die jump kill link rehash\003"
putdcc $idx "\00301,01..\003 \00314restart status telnet unlink\003"
putdcc $idx ""
putdcc $idx "\00301,01.\003\00308(owner)\003 net commands:"
putdcc $idx "\00301,01..\003 \00314act channels chankey chanset control die join jump\003"
putdcc $idx "\00301,01..\003 \00314part rehash save say\003"
putdcc $idx ""
}
if { [matchattr $handle m]} {
putdcc $idx "\00301,01.\003\00308(master)\003 commands:"
putdcc $idx "\00301,01..\003 \00314+ignore -ignore\003"
putdcc $idx "\00301,01..\003 \00314botinfo bots bottree chattr chhandle dolimit\003"
putdcc $idx "\00301,01..\003 \00314ignores match relay reload save servers trace\003"
putdcc $idx "\00301,01..\003 \00314traffic uptime userlist vcheck who whom\003"
putdcc $idx ""
putdcc $idx "\00301,01.\003\00308(master)\003 net commands:"
putdcc $idx "\00301,01..\003 \00314massdevoice masskick massop massopall massvoice\003"
putdcc $idx "\00301,01..\003 \00314takeover\003"
putdcc $idx ""
}
if { [matchattr $handle o] } {
# ops
putdcc $idx "\00301,01.\003\00308(op)\003 commands:"
putdcc $idx "\00301,01..\003 \00314+ban -ban +exempt -exempt +invite -invite\003"
putdcc $idx "\00301,01..\003 \00314bans exempts invites stick unstick op\003"
putdcc $idx ""
}
if { [matchattr $handle p] } {
# users
putdcc $idx "\00301,01.\003\00308(user)\003 commands:"
putdcc $idx "\00301,01..\003 \00314about away back chat info newpass page quit sv\003"
putdcc $idx "\00301,01..\003 \00314whoami version\003"
putdcc $idx ""
}
} {
*dcc:help $handle $idx $args
}
}
# }}}
# ak!ra: motd {{{
proc display_motd { idx } {
global botnick env server tcl_patchLevel tcl_platform uptime
variable ::*akira::config::motd_userlist
set chans {}
foreach chan [channels] {
if { ![botonchan $chan] } {
# bot can't join channel
lappend chans "\00305(${chan})\003"
} elseif { ![botisop $chan] } {
# bot has no ops in channel
lappend chans "\00314${chan}\003"
} {
# bot has ops in channel
lappend chans "\00310${chan}\003"
}
}
set up [clock seconds]
incr up -$uptime
set utime [string map {" years" "y" " weeks" "w" " days" "d" " hours" "h" " minutes" "m" " seconds" "s" " year" "y" " week" "w" " day" "d" " hour" "h" " minute" "m" " second" "s"} [duration $up]]
set fp [open "/etc/hostname" r]
set hostname [read $fp]
close $fp
putdcc $idx "\00300▀\003▀\00314▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█\003"
putdcc $idx "\00314█ \003\00310█▀█ █ ▄ ▀ █▀▄ █▀█ \003\00314█\003"
putdcc $idx "\00314█ \00311,10░\003 \00311,10░\003 \00311,10░\003 \00311,10░\003 \00310█ \003\00311,10░\003 \00311,10▒\003 \00311,10░\003 \00310█\003 \00314█\003"
putdcc $idx "\00314█ \00311,10▓\003 \00311█\003 \00311,10▓\003\00311▄▀\003 \00311,10▓\003 \00311█ █ █ \003\00311,10▓\003 \00314█\003"
putdcc $idx "\00314█ \00311█▀█ █ █ █ █▀▄ █▀█ \003\00314█ bz!\003"
putdcc $idx "\00314█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\003▄\00300▄\003"
putdcc $idx ""
putdcc $idx "\00301,01.\003bot: \00310[string tolower ${botnick}]\003 users: \00310[countusers]\003 server: \00310[string tolower ${server}]\003"
putdcc $idx "\00301,01.\003channels: $chans"
if { $motd_userlist == 1 } {
set pusers {}
set dccusers [whom 0]
set deli {}
if { [llength $dccusers] != 0 } {
foreach dccuser $dccusers {
set userhand [lindex $dccuser 0]
if { [matchattr $userhand n] } {
set userrank "\00304(owner)\003"
} elseif { [matchattr $userhand m] } {
set userrank "\00306(master)\003"
} elseif { [matchattr $userhand t] } {
set userrank "\00306(botmaster)\003"
} elseif { [matchattr $userhand o] } {
set userrank "(op)"
} {
set userrank "(user)"
}
lappend pusers "${deli}\002\00300${userhand}\002@[lindex $dccuser 1]\003 ${userrank}"
set deli ", "
}
putdcc $idx "\00301,01.\003partyline users: $pusers"
}
}
putdcc $idx ""
putdcc $idx "\00301,01.\003running: \00310${::*akira::hcversion}\003 \00314(tcl/$tcl_patchLevel)\003"
putdcc $idx "\00301,01.\003os: \00310[string tolower $tcl_platform(os)-$tcl_platform(osVersion)-$tcl_platform(machine)]\003"
putdcc $idx "\00301,01.\003hostname: \00310${hostname}\003"
putdcc $idx "\00301,01.\003uptime: \00310$utime\003"
putdcc $idx ""
}
# }}}
# ak!ra: default procs {{{
proc _botlog { frombot command text } {
global nicklen
if { ${::*akira::ishub} } {
set fromlen [expr {$nicklen + 2}]
if { [string match *:* $text] } {
set textlen [expr {$nicklen * 2 + 2}]
set tmp [split $text :]
set text1 "[lindex $tmp 0]:"
set text2 [join [lrange $tmp 1 end]]
putloglev 5 "*" [format "\[ak!ra\] %-${fromlen}s %-${textlen}s%s" "($frombot)" "$text1" "$text2"]
} {
putloglev 5 "*" [format "\[ak!ra\] %-${fromlen}s %s" "($frombot)" "$text"]
}
}
return 0 ;# TCL_OK
}
proc botlog { text } {
global botnet-nick
if { ${::*akira::ishub} } {
::*akira::_botlog ${botnet-nick} "akira_botlog" ${text}
} else {
putallbots "akira_botlog ${text}"
#putlog "\00312DEBUG:\003 akira_botlog ${text}"
}
return 0 ;# TCL_OK
}
proc control_islocal {} {
global botnick
variable ::*akira::config::control
if { $control == "*" } {
return 1 ;# TRUE
}
if { [lsearch $control [string tolower $botnick]] != -1 } {
return 1 ;# TRUE
}
return 0 ;# FALSE
}
proc countbots {} {
global botnick
variable ::*akira::config::control
set bot_count 0
if { $control == "*" } {
foreach bot [userlist b] {
if { [islinked $bot] || [string tolower $bot] == [string tolower $botnick] } {
set bot_count [expr {$bot_count+1}]
}
}
} {
foreach bot $control {
if { [islinked $bot] || [string tolower $bot] == [string tolower $botnick] } {
set bot_count [expr {$bot_count+1}]
}
}
}
return $bot_count ;# INT
}
proc cmdlog { text } {
if { [llength $text] == 0 } {
return 2 ;# TCL_RETURN
}
set text [split $text "|"]
set addtext {}
if { [llength $text] > 2 } {
set addtext "\00306[lindex $text 2]\003 "
}
putlog "\00307#[lindex $text 0]#\003 ${addtext}[lindex $text 1]"
return 0 ;# TCL_OK
}
proc enterpass { idx args } {
global botnick
#regsub -all "\377\[\373-\376\].|\377." $args "" args
#set args "[string range $args 0 14]"
if { "[join $args]" == "" } { return 0 }
putlog "encrypt: [join $args]"
putlog "thekey: [decrypt [join $args] ${::*akira::config::securekey}]"
if { "[join $args]" eq "[string trim [decrypt [join $args] [join ${::*akira::config::securekey}]]]" } {
::*akira::display_motd $idx
setchan $idx 1
return 1
}
putdcc $idx "\00304ACCESS DENIED!\003"
::*akira::output "secauth" "access denied \00304<[idx2hand $idx]@$botnick>\003"
if { [catch { idx2hand $idx } handle] } { set handle "unknown" }
if { [catch { idx2ip $idx } longip] } { set longip - }
if { [catch { idx2host $idx } host] } { foreach w [dcclist] { if { $idx == [lindex $w 0] } { set host [lindex $w 2] } } }
::*akira::botlog "login: !FAILED! ([join $args]): [list $handle] <+[set f [chattr $handle]]> $idx [list $host] ($longip)"
killdcc $idx
return 0 ;# TCL_OK
}
proc err { text } {
if { ${text} eq "" } {
return 2 ;# TCL_RETURN
}
putlog "\00304‼ ERROR:\003 ${text}"
return 0 ;# TCL_OK
}
proc errdcc { idx text } {
if { ${text} eq "" } {
return 2 ;# TCL_RETURN
}
putdcc $idx "\00304‼ ERROR:\003 ${text}"
return 0 ;# TCL_OK
}
proc iso8601 {} {
set x [clock milliseconds]
return [format "%s.%03dZ" [clock format [expr {$x / 1000}] -timezone :UTC -format {%Y-%m-%dT%H:%M:%S}] [expr {$x % 1000}]]
}
proc output { section text } {
if { ${section} eq "" || ${text} eq "" } {
warning "::*akira::output failure"
return 2 ;# TCL_RETURN
}
putlog "\00311≡\003 ${section}: \00314${text}\003"
return 0 ;# TCL_OK
}
proc outputdcc { idx section text } {
if { ${section} eq "" && ${text} eq "" } {
warning "::*akira::outputdcc failure"
return 2 ;# TCL_RETURN
} elseif { ${section} ne "" } {
set section [string cat $section ": "]
}
putdcc $idx "\00311≡\003 ${section}\00314${text}\003"
return 0 ;# TCL_OK
}
proc putcbot { nick msg } {
#putlog "\00312DEBUG:\003 putbot $nick $msg"
putbot $nick "$msg"
return 0 ;# TCL_OK
}
proc putcbots { command args } {
variable ::*akira::config::control
if { $control == "*" } {
#putlog "\00312DEBUG:\003 putallbot $command $args"
putallbots "${command} ${args}"
return 0 ;# TCL_OK
} {
foreach bot $control {
if { [islinked $bot] } {
#putlog "\00312DEBUG:\003 putbot $bot $command $args"
putbot $bot "${command} ${args}"
}
}
return 0 ;# TCL_OK
}
}
proc ::putchan { chan {section "ak!ra"} text } {
if { (${chan} eq "" && ${section} eq "" && ${text} eq "") || ![validchan $chan] } {
warning "putchan failure"
return 2 ;# TCL_RETURN
}
puthelp "PRIVMSG $chan :\00311≡\003 ${section}: \00314${text}\003"
return 0 ;# TCL_OK
}
proc randomize_bots {} {
return [::*akira::shuffle6 [bots]]
}
proc randomize_nicks { chan } {
return [::*akira::shuffle6 [chanlist $chan]]
}
proc secureinit { event } {
global botnet-nick botnick hub serveraddress
putquick "MODE $botnick +i-wxs"
if { ${::*akira::ishub} } {
::*akira::bot::server ${botnet-nick} "akira_server" $serveraddress
} {
if { [islinked $hub] } {
putbot $hub "akira_server $serveraddress"
}
}
::*akira::setutimer [rand 5] { ::*akira::secureme }
return 0 ;# TCL_OK
}
proc secureme {} {
global botnet-nick botname listen-addr botport userport
# make sure hub has its own user record
if { ${::*akira::ishub} } {
if { $botname eq ${botnet-nick} } {
::*akira::setutimer [rand 5] { ::*akira::secureme }
return 1 ;# TCL_ERROR
}
if { ![validuser ${botnet-nick}] } {
addbot ${botnet-nick} ${listen-addr} +$botport +$userport
setuser ${botnet-nick} HOSTS ${botname}
chattr ${botnet-nick} +bfop${::*akira::config::control_flag}
botattr ${botnet-nick} +h
putlog "\00309□\003 securehub: \00314added bot \002${botnet-nick}\002\003"
} {
if { ![matchattr ${botnet-nick} +bfop${::*akira::config::control_flag}] } {
chattr ${botnet-nick} +bfop${::*akira::config::control_flag}
putlog "\00309□\003 securehub: \00314chattr \002${botnet-nick}\002\003 \00306<+bfop${::*akira::config::control_flag}>\003"
}
if { ![matchattr ${botnet-nick} ||+h] } {
botattr ${botnet-nick} +h
putlog "\00309□\003 securehub: \00314botattr \002${botnet-nick}\002\003 \00306<+h>\003"
}
set hosts [getuser ${botnet-nick} HOSTS]
set hfound false
foreach host $hosts {
if { $botname eq $host } { set hfound true }
}
if { !$hfound } {
setuser ${botnet-nick} HOSTS ${botname}
putlog "\00309□\003 securehub: \00314addhost \002${botnet-nick}\002\003 \00306<$botname>\003"
}
}
}
return 0 ;# TCL_OK
}
proc settimer { minutes command } {
set command "[join $command]"
if { $minutes < 1 } { set minutes 1 }
foreach t [timers] { if { [lindex $t 1] eq $command } { killtimer [lindex $t 2] } }
timer $minutes [subst {$command}]
return 0 ;# TCL_OK
}
proc setutimer { seconds command } {
set command "[join $command]"
if { $seconds < 1 } { set seconds 1 }
foreach t [utimers] { if { [lindex $t 1] eq $command } { killutimer [lindex $t 2] } }
utimer $seconds [subst {$command}]
return 0 ;# TCL_OK
}
proc shuffle6 { list } {
set n [llength $list]
for { set i 1 } { $i < $n } { incr i } {
set j [expr { int( rand() * $n ) }]
set temp [lindex $list $i]
lset list $i [lindex $list $j]
lset list $j $temp
}
return $list
}
proc warning { text } {
if { ${text} eq "" } {
return 2 ;# TCL_RETURN
}
putlog "\00310! WARNING:\003 ${text}"
return 0 ;# TCL_OK
}
proc warningdcc { idx text } {
if { ${idx} eq "" && ${text} eq "" } {
return 2 ;# TCL_RETURN
}
putdcc $idx "\00310! WARNING:\003 ${text}"
return 0 ;# TCL_OK
}
proc xindex { xr xr1 } { return [join [lrange [split $xr] $xr1 $xr1]] }
proc xrange { xr xr1 xr2 } { return [join [lrange [split $xr] $xr1 $xr2]] }
proc xstrcmp { str1 str2 } {
if { [string compare [string tolower $str1] [string tolower $str2]] == 0 } {
return 1 ;# TCL_ERROR
} {
return 0 ;# TCL_OK
}
}
# }}}
# ak!ra: init {{{
# register the tls socket with http as https
http::register https 443 [list ::tls::socket -autoservername true]
set hubtxt {}
if { ${nick} == ${hub} } { set ::*akira::ishub 1;set hubtxt " \00310<hub mode>\003" }
if { ${nick} == ${infobot} } { set ::*akira::isinfo 1;set hubtxt " \00310<info bot>\003" }
::*akira::output "tribe9/akira.tcl" "v${::*akira::t9version}+${::*akira::version}\003 \00306<${::*akira::author}>${hubtxt}"
catch { setudef flag crypto }
catch { setudef flag limit }
catch { setudef flag secure }
catch { setudef flag youtube }
catch { setudef flag www }
if { ${::*akira::ishub} } {
# hub bot
logfile 5 * "${::*akira::config::logfile}"
::*akira::setutimer 10 { ::*akira::time::hubcheckstat }
if { [string length $server] > 0 } {
::*akira::setutimer 8 { ::*akira::bot::server ${botnet-nick} "akira_server" $serveraddress }
}
} {
# leaf bots
if { [islinked $hub] } {
::*akira::setutimer 8 {putbot $hub \"akira_server $serveraddress\"}
}
}
# mod versions
::*akira::output "blowcrypt.tcl" "${blowcrypt_version} \00306<poci/PPX>\003"
::*akira::output "tmon.tcl" "${tmon_version} \00306<stran9er>\003"
# general maintenance
if {![info exists passive]} { uplevel #0 {set passive 0} }
if {![info exists oldpassive]} { uplevel #0 {set oldpassive $passive} }
::*akira::setutimer 2 { ::*akira::bot::bop_clearneeds }
# port setup
if { !${::*akira::ishub} && ![matchattr ${botnet-nick} a] && ![matchattr ${botnet-nick} h] } {
set userport [expr {$userport + 1}]
listen +$userport users
} {
listen +$botport all
}
# if userfile doesn't exist, try to restore from backup
if { ![file exists $userfile] } { if { [file exists ${userfile}~bak] } { exec /bin/cp ${userfile}~bak $userfile } }
if { ![info exists main_config] } {
if { [userlist n] eq "" } { die "no main_config variable is set in main config, die..." }
warning "no main_config variable is set!"
}
if { !${::*akira::ishub} && ![matchattr ${botnet-nick} h] && ![matchattr ${botnet-nick} a] } {
unbind dcc - unlink *dcc:unlink
bind dcc n unlink ::*akira::dccunlink
proc dccunlink { args } { putallbots "noop \nbye" }
}
# load blowcrypt module
uplevel #0 { set bc_enabled 0 }
global bc_enabled
catch { load [file join [pwd] modules/dh1080.so] } dherr
if { [string length $dherr] > 0 } {
::*akira::err "$dherr"
::*akira::warning "blowcrypt: keyexchange is disabled"
} {
set bc_enabled 1
}
# load external files if they exist
set stcls {}
catch { set stcls [glob -types f "*-secure.tcl"] }
if { [llength $stcls] > 0 } {
foreach stcl $stcls {
if { [file exists $stcl] } {
hcsource $stcl
}
}
}
# }}}
# ak!ra: binds {{{
catch { unbind dcc lo|lo +ban *dcc:+ban }
catch { unbind dcc n|- +bot *dcc:+bot }
catch { unbind dcc o|o act *dcc:act }
catch { unbind dcc m|- bots *dcc:bots }
catch { unbind dcc -|- help *dcc:help }
catch { unbind dcc o|- msg *dcc:msg }
catch { unbind dcc o|o op *dcc:op }
catch { unbind dcc o|o say *dcc:say }
catch { unbind dcc o|- servers *dcc:servers }
catch { unbind dcc n|- status *dcc:status }
catch { unbind dcc -|- whom *dcc:whom }
catch { unbind msg -|- +host *msg:+host }
catch { unbind msg -|- +op *msg:+op }
catch { unbind ctcp -|- TIME *ctcp:TIME }
catch { unbind ctcp -|- CLIENTINFO *ctcp:CLIENTINFO }
catch { unbind ctcp -|- USERINFO *ctcp:USERINFO }
catch { unbind ctcp -|- VERSION *ctcp:VERSION }
catch { unbind ctcp -|- ERRMSG *ctcp:ERRMSG }
catch { unbind ctcp -|- PING *ctcp:PING }
catch { unbind ctcp -|- ECHO *ctcp:ECHO }
catch { unbind ctcp -|- FINGER *ctcp:FINGER }
# BOT - triggered by a message coming from another bot in the botnet
bind bot - akira_botlog ::*akira::_botlog
bind bot - akira_checkstat ::*akira::bot::checkstat
bind bot - akira_checkuser ::*akira::bot::checkuser
bind bot - akira_joinkey ::*akira::bot::bop_joinkey
bind bot - akira_needinvite ::*akira::bot::bop_botwantsin
bind bot - akira_needkey ::*akira::bot::bop_botwantsin
bind bot - akira_needlimit ::*akira::bot::bop_botwantsin
bind bot - akira_needop ::*akira::bot::bop_needop
bind bot - akira_needopack ::*akira::bot::bop_needopack
bind bot - akira_needunban ::*akira::bot::bop_botwantsin
bind bot - akira_net ::*akira::bot::botnet
bind bot - akira_netchans ::*akira::bot::netchans
bind bot - akira_onchans ::*akira::bot::onchans
bind bot - akira_opcheck ::*akira::bot::opcheck
bind bot - akira_opjoin ::*akira::bot::opjoin
bind bot - akira_reqop ::*akira::bot::bop_reqtimer
bind bot - akira_server ::*akira::bot::server
bind bot - akira_uname ::*akira::bot::uname
bind bot - akira_vcheck ::*akira::bot::extcheck
bind bot - akira_vcheck_ack ::*akira::bot::extcheckack
# CHOF (stackable) - triggered when a user disconnects from the bot
bind chof - * ::*akira::events::userdisc
# CHON (stackable) - triggered when someone enters the party-line (dcc or telnet)
bind chon - * ::*akira::events::chon
# CTCP (stackable) - triggered on incoming user/channel ctcp event
bind ctcp - action ::*akira::ctcp::ctcpreply
bind ctcp - chops ::*akira::ctcp::ctcpreply
bind ctcp - clientinfo ::*akira::ctcp::ctcpreply
bind ctcp - errmsg ::*akira::ctcp::ctcpreply
bind ctcp - echo ::*akira::ctcp::ctcpreply
bind ctcp - finger ::*akira::ctcp::ctcpreply
bind ctcp - help ::*akira::ctcp::ctcpreply
bind ctcp - invite ::*akira::ctcp::ctcpreply
bind ctcp - op ::*akira::ctcp::ctcpreply
bind ctcp - open ::*akira::ctcp::ctcpreply
bind ctcp - ops ::*akira::ctcp::ctcpreply
bind ctcp - page ::*akira::ctcp::ctcpreply
bind ctcp - ping ::*akira::ctcp::ctcpreply
bind ctcp - send ::*akira::ctcp::ctcpreply
bind ctcp - time ::*akira::ctcp::ctcpreply
bind ctcp - unban ::*akira::ctcp::ctcpreply
bind ctcp - uptime ::*akira::ctcp::ctcpreply
bind ctcp - userinfo ::*akira::ctcp::ctcpreply
bind ctcp - utc ::*akira::ctcp::ctcpreply
bind ctcp - ver ::*akira::ctcp::ctcpreply
bind ctcp - version ::*akira::ctcp::ctcpreply
bind ctcp - voice ::*akira::ctcp::ctcpreply
bind ctcp - whoami ::*akira::ctcp::ctcpreply
bind ctcp - xdcc ::*akira::ctcp::ctcpreply
# DCC - used for partyline commands
bind dcc lo|lo +ban ::*akira::dcc::+ban
bind dcc n|- +bot ::*akira::dcc::+bot
bind dcc n|- +user ::*akira::dcc::+user
bind dcc p|- about ::*akira::dcc::about
bind dcc n|- act *dcc::act
bind dcc -|- akira ::*akira::help
bind dcc m|- autoaway ::*akira::dcc::autoaway
bind dcc n|- botnick ::*akira::dcc::dccbotnick
bind dcc m|- botnet ::*akira::dcc::botnet
bind dcc m|- bots ::*akira::dcc::dccbots
bind dcc n|- botstat ::*akira::dcc::botstat
bind dcc n|- channels ::*akira::dcc::dccchannels
bind dcc m|m dolimit ::*akira::limit::dcc_dolimit
bind dcc -|- help ::*akira::help
bind dcc m|m hostcheck ::*akira::dcc::hostcheck
bind dcc n|- kill ::*akira::dcc::dcckill
bind dcc n|- msg *dcc::msg
bind dcc n|- net ::*akira::dcc::botnet
bind dcc -|- op ::*akira::dcc::op
bind dcc n|- say *dcc::say
bind dcc n|- servers ::*akira::dcc::serverlist
bind dcc n|- status ::*akira::dcc::status
bind dcc p|- sv ::*akira::dcc::about
bind dcc n|- uname ::*akira::dcc::uname
bind dcc m|m userlist ::*akira::dcc::dccuserlist
bind dcc m|- vcheck ::*akira::dcc::vcheck
bind dcc p|- version ::*akira::dcc::aversion
bind dcc m|m whom ::*akira::dcc::dccwhom
# DISC (stackable) - triggered when a bot disconnects from the botnet
bind disc - * ::*akira::events::botdisc
# EVNT (stackable) - triggered when an event happens {{{
# sighup - called on a kill -HUP <pid>
# sigterm - called on a kill -TERM <pid>
# sigill - called on a kill -ILL <pid>
# sigquit - called on a kill -QUIT <pid>
# save - called when the userfile is saved
# rehash - called just after a rehash
# prerehash - called just before a rehash
# prerestart - called just before a restart
# logfile - called when the logs are switched daily
# loaded - called when the bot is done loading
# userfile-loaded - called after userfile has been loaded
# connect-server - called just before we connect to an IRC server
# preinit-server - called immediately when we connect to the server
# init-server - called when we actually get on our IRC server
# disconnect-server - called when we disconnect from our IRC server
# fail-server - called when an IRC server fails to respond
# loadchannels - called when the bot loads the chanfile
# savechannels - called when the bot saves the chanfile
# reload - called when the bot issues a reload
# }}}
bind evnt - init-server ::*akira::secureinit
# FILT (stackable) - filter through bot user input (dcc/telnet)
bind filt - .chatt* ::*akira::filt::chattr
# JOIN (stackable) - triggered by someone joining the channel
bind join -|- * ::*akira::bot::bop_jointimer
bind join -|- * ::*akira::bot::secureopjoin
# LINK (stackable) - triggered when a bot links into the botnet
bind link - * ::*akira::events::botlink
# MODE (stackable) - triggered by channel/server mode changes
if { ${::*akira::config::bop_modeop} } { bind mode - * ::*akira::bot::bop_modeop }
bind mode - * ::*akira::bot::modeverify
bind mode - "* ?l" ::*akira::limit::check
# MSG - used for /msg commands
bind msg -|- +op ::*akira::msg::op
# NEED (stackable) - triggered when the bot needs: op, unban, invite, limit, or key
bind need - * ::*akira::bot::bop_reqop
# PART (stackable) - triggered by someone leaving the channel
bind part - * ::*akira::bot::bop_unsetneed
# RAW (stackable) - triggered on raw server output
bind raw - 352 ::*akira::bot::bop_who
bind raw - MODE ::*akira::bot::raw_modeverify
# TIME (stackable) - allows you to schedule procedure calls at certain times
bind time - "57 * * * *" ::*akira::time::keeplinked
bind time - "30 * * * *" ::*akira::time::checkstattimer
bind time - "* * * * *" ::*akira::time::dccidlekick
bind time - "42 * * * *" ::*akira::tmon::tmontimer
# ak!ra: binds: mods {{{
# mod - blowcrypt
bind pub -|- +OK ::*akira::blowcrypt::onencryptedtext
if { $bc_enabled } {
bind msg -|- +OK ::*akira::blowcrypt::onencryptedmsg
bind msg -|- !bckeydel ::*akira::blowcrypt::bckeydel
bind pub n|- %verify ::*akira::blowcrypt::test
bind nick -|- * ::*akira::blowcrypt::keyexnick
bind notc - "DH1080_INIT *" ::*akira::blowcrypt::onkeyexchangeinit
bind notc - "DH1080_FINISH *" ::*akira::blowcrypt::onkeyexchangefinish
}
# mod - crypto
if { ${::*akira::isinfo} } {
bind pub -|- !btc ::*akira::crypto::handlerbtc
bind pub -|- !eth ::*akira::crypto::handlereth
bind pub -|- !xbt ::*akira::crypto::handlerbtc
}
# mod - trace monitor
if { ${::*akira::ishub} } { bind bot - akira_trace ::*akira::tmon::botcmd }
# mod - www
if { ${::*akira::isinfo} } {
bind pubm -|- {*://*} ::*akira::www::handler
}
# mod - youtube
if { ${::*akira::isinfo} } {
bind pubm -|- "*youtube.*watch?v=*" ::*akira::youtube::handler
bind pubm -|- "*youtu.be/*" ::*akira::youtube::handler
}
# }}}
# }}}
# ak!ra: binds (bot) {{{
namespace eval bot {
proc bop_askbot { handle chan } {
global botnick
set stlchan [string tolower $chan]
if { [info exists ::*akira::bop_asktimer($handle:$stlchan)] } {
unset ::*akira::bop_asktimer($handle:$stlchan)
}
if { ![validchan $chan] || ![botonchan $chan] || ![botisop $chan] } { return 1 }
if { ![matchattr $handle b] || ![matchattr $handle o|o $chan] || [matchattr $handle d|d $chan] } { return 1 }
if { ![islinked $handle] } { return 1 }
::*akira::putcbot $handle "akira_needop $chan $botnick"
return 0 ;# TCL_OK
}
proc bop_botwantsin { frombot command args } {
set chan [lindex [join $args] 0]
if { ![validchan $chan] } { return 1 }
if { ![matchattr $frombot b] || ![matchattr $frombot fo|fo $chan] } { return 1 }
set fromhost [lindex [join $args] 2]
set command [lindex [split $command _] 1]
#putlog "\00312DEBUG:\003 bop_botwantsin $frombot $command $chan"
switch -exact -- $command {
"needkey" {
if { [string match *k* [lindex [split [getchanmode $chan]] 0]] } {
::*akira::putcbot $frombot "akira_joinkey $chan [lindex [split [getchanmode $chan]] 1]"
if { [set ::*akira::config::loglevel] >= 1 } {
::*akira::botlog "gave key: ${chan}: $frombot $fromhost <+[botattr $frombot]> [getuser $frombot BOTADDR]"
}
}
}
"needinvite" {
if { ![botisop $chan] } { return 1 }
set fromnick [lindex [join $args] 1]
if { [set ::*akira::config::bop_icheck] && $fromhost ne "" } {
if { ![info exists ::*akira::config::bop_who($fromnick)] } {
set ::*akira::config::bop_who($fromnick) "$chan $frombot $fromhost"
::*akira::setutimer 60 [split "::*akira::bot::bop_whounset $fromnick"]
}
putserv "WHO $fromnick"
} {
putserv "INVITE $fromnick $chan"
if { [set ::*akira::config::loglevel] >= 1 } {
if { $fromnick ne $frombot } {
::*akira::botlog "gave invite: ${chan}: $frombot $fromhost (${fromnick}) <+[botattr $frombot]> [getuser $frombot BOTADDR]"
} {
::*akira::botlog "gave invite: ${chan}: $frombot $fromhost <+[botattr $frombot]> [getuser $frombot BOTADDR]"
}
}
}
}
"needlimit" {
if { ![botisop $chan] } { return 1 }
putserv "MODE $chan +l [expr {[llength [chanlist $chan]] +1}]"
if { [set ::*akira::config::loglevel] >= 1 } {
::*akira::botlog "gave limit incr: ${chan}: $frombot $fromhost"
}
}
"needunban" {
if { ![botisop $chan] } { return 1 }
foreach ban [chanbans $chan] {
if { [string match [string tolower [lindex $ban 0]] [string tolower $fromhost]] } {
putserv "MODE $chan -b [lindex $ban 0]"
if { [set ::*akira::config::loglevel] >= 1 } {
::*akira::botlog "gave unban: ${chan}: $frombot $fromhost <+[botattr $frombot]> [getuser $frombot BOTADDR]"
}
}
}
}
}
return 0 ;# TCL_OK
}