BT.Ban.tcl 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. ## BlackTools - The Ultimate Channel Control Script ##
  2. ## One TCL. One smart Eggdrop ##
  3. ###########################################################################
  4. ############################# BAN TCL #################################
  5. ###########################################################################
  6. ## ##
  7. ## BlackTools : http://blacktools.tclscripts.net ##
  8. ## Bugs report : http://www.tclscripts.net/ ##
  9. ## GitHub page : https://github.com/tclscripts/BlackToolS-TCL ##
  10. ## Online Help : irc://irc.undernet.org/tcl-help ##
  11. ## #TCL-HELP / UnderNet ##
  12. ## You can ask in english or romanian ##
  13. ## ##
  14. ###########################################################################
  15. ###
  16. proc blacktools:banlist {chan} {
  17. global black
  18. set banlist [lsearch -all -inline $black(bans) "* [string tolower $chan] *"]
  19. return $banlist
  20. }
  21. ###
  22. proc blacktools:banlist:ban {chan} {
  23. global black
  24. set banlist [lsearch -all -inline $black(bans) "BAN * [string tolower $chan] *"]
  25. return $banlist
  26. }
  27. ###
  28. proc blacktools:banlist:regex {chan} {
  29. global black
  30. set banlist [lsearch -all -inline $black(bans) "REGEX * [string tolower $chan] *"]
  31. return $banlist
  32. }
  33. ###
  34. proc blacktools:gaglist {chan} {
  35. global black
  36. set banlist [lsearch -all -inline $black(bans) "GAG * [string tolower $chan] *"]
  37. return $banlist
  38. }
  39. ###
  40. proc blacktools:banlist:gl {} {
  41. global black
  42. set banlist [lsearch -all -inline $black(bans) "* GLOBAL *"]
  43. return $banlist
  44. }
  45. ###
  46. proc blacktools:banlist:all {} {
  47. global black
  48. set file [open $black(bans_file) r]
  49. set size [file size $black(bans_file)]
  50. set data [split [read $file $size] \n]
  51. close $file
  52. set banlist [lsearch -all -inline $data "*"]
  53. }
  54. ###
  55. proc blacktools:banlist:lastid {} {
  56. global black
  57. if {$black(bans) != ""} {
  58. foreach b $black(bans) {
  59. set id [lindex [split $b] 1]
  60. lappend ids $id
  61. }
  62. set sort [blacktools:quicksort [join $ids]]
  63. return [lindex $sort end]
  64. } else {return 0}
  65. }
  66. ###
  67. #https://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Tcl
  68. proc blacktools:quicksort {m} {
  69. if {[llength $m] <= 1} {
  70. return $m
  71. }
  72. set pivot [lindex $m 0]
  73. set less [set equal [set greater [list]]]
  74. foreach x $m {
  75. lappend [expr {$x < $pivot ? "less" : $x > $pivot ? "greater" : "equal"}] $x
  76. }
  77. return [concat [blacktools:quicksort $less] $equal [blacktools:quicksort $greater]]
  78. }
  79. ###
  80. proc blacktools:sticky {host chan} {
  81. global black
  82. set bancheck [lsearch -all -inline $black(bans) "* [string tolower $chan] $host *"]
  83. if {$bancheck != ""} {
  84. return [lindex [split $bancheck] 7]
  85. }
  86. return
  87. }
  88. ###
  89. proc blacktools:isgag {host chan} {
  90. global black
  91. set bancheck [lsearch -all -inline $black(bans) "GAG * [string tolower $chan] $host *"]
  92. if {$bancheck != ""} {
  93. set expire [lindex [split $bancheck] 5]
  94. set dif [expr $expire - [unixtime]]
  95. if {$dif > 0} {
  96. return 1
  97. } else {
  98. return 0
  99. }
  100. } else {
  101. return 0
  102. }
  103. }
  104. ###
  105. proc blacktools:isregex {host chan} {
  106. global black
  107. set bancheck [lsearch -all -inline $black(bans) "REGEX * [string tolower $chan] $host *"]
  108. if {$bancheck != ""} {
  109. set expire [lindex [split $bancheck] 5]
  110. set dif [expr $expire - [unixtime]]
  111. if {$dif > 0} {
  112. return 1
  113. } else {
  114. return 0
  115. }
  116. } else {
  117. return 0
  118. }
  119. }
  120. ###
  121. proc blacktools:isban {host chan} {
  122. global black
  123. set bancheck [lsearch -all -inline $black(bans) "BAN * [string tolower $chan] $host *"]
  124. if {$bancheck != ""} {
  125. return 1
  126. } else {
  127. return 0
  128. }
  129. }
  130. ###
  131. proc blacktools:addban:gl {nick host hand chan bantime type sticky global reason id} {
  132. global black
  133. set chan1 $chan
  134. set sec_bantime [expr $bantime * 60]
  135. set unixtime [unixtime]
  136. if {$bantime != "0"} {
  137. set bantime [expr $unixtime + $sec_bantime]
  138. }
  139. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  140. set temp "$black(bans_file).new.$timestamp"
  141. set file [open $black(bans_file) r]
  142. set size [file size $black(bans_file)]
  143. set data [split [read $file $size] \n]
  144. close $file
  145. set tempwrite [open $temp w]
  146. foreach line $data {
  147. if {$line != ""} {
  148. set read_chan [lindex [split $line] 2]
  149. set read_host [lindex [split $line] 3]
  150. if {$type != "REGEX"} {
  151. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  152. } else {set real_read_host $read_host}
  153. if {([string match -nocase $host $real_read_host] || [string match -nocase $real_read_host $host] || [string equal -nocase $real_read_host $host]) && [string equal -nocase $chan "GLOBAL"]} {
  154. continue
  155. } else {
  156. puts $tempwrite $line
  157. }
  158. }
  159. }
  160. close $tempwrite
  161. file rename -force $temp $black(bans_file)
  162. blacktools:ban:put $nick $host $hand $chan $bantime $type $sticky $global $reason $id
  163. }
  164. ###
  165. proc blacktools:delban {host chan global gag} {
  166. global black
  167. if {$global == "1"} {
  168. set chan "GLOBAL"
  169. } else {
  170. if {![validchan $chan]} {
  171. return
  172. }
  173. }
  174. if {$gag == "1"} {
  175. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  176. set temp "$black(bans_file).new.$timestamp"
  177. set tempwrite [open $temp w]
  178. set file [open $black(bans_file) r]
  179. set size [file size $black(bans_file)]
  180. set data [split [read $file $size] \n]
  181. close $file
  182. foreach line $data {
  183. if {$line != ""} {
  184. set read_type [lindex [split $line] 0]
  185. set read_chan [lindex [split $line] 2]
  186. set read_host [lindex [split $line] 3]
  187. if {[string match -nocase $host $read_host] && [string equal -nocase $chan $read_chan] && [string equal -nocase "GAG" $read_type]} {
  188. continue
  189. } else {
  190. puts $tempwrite $line
  191. }
  192. }
  193. }
  194. close $tempwrite
  195. file rename -force $temp $black(bans_file)
  196. set black(bans) [blacktools:banlist:all]
  197. return
  198. }
  199. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  200. set temp "$black(bans_file).new.$timestamp"
  201. set tempwrite [open $temp w]
  202. set file [open $black(bans_file) r]
  203. set size [file size $black(bans_file)]
  204. set data [split [read $file $size] \n]
  205. close $file
  206. foreach line $data {
  207. if {$line != ""} {
  208. set read_chan [lindex [split $line] 2]
  209. set read_host [lindex [split $line] 3]
  210. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  211. if {([string match -nocase $host $real_read_host] || [string match -nocase $real_read_host $host]) && [string equal -nocase $chan $read_chan]} {
  212. continue
  213. } else {
  214. puts $tempwrite $line
  215. }
  216. }
  217. }
  218. close $tempwrite
  219. file rename -force $temp $black(bans_file)
  220. set black(bans) [blacktools:banlist:all]
  221. }
  222. ###
  223. proc blacktools:addban {nick host hand chan chan1 bantime type sticky global reason notfound cmd type banned prv id} {
  224. global black botnick
  225. chanserv:ignore_remove
  226. set rcmd [lindex $cmd 0]
  227. set regex [lindex $cmd 1]
  228. set read_num 0
  229. set split_hand [split $hand ":"]
  230. set gethand [lindex $split_hand 0]
  231. set gettype [lindex $split_hand 1]
  232. if {$gettype == ""} {
  233. set hand [string map {":" ""} $hand]
  234. } else {
  235. set length_type [llength [split $gettype]]
  236. if {$length_type > 1} {
  237. set gettype [string map {" " "%"} $gettype]
  238. }
  239. set hand "$gethand:$gettype"
  240. }
  241. set sec_bantime [expr $bantime * 60]
  242. set unixtime [unixtime]
  243. set accdenied 0
  244. set xban 0
  245. set getcount [setting:get $chan kickcount]
  246. set show_reason $reason
  247. if {$bantime != "0"} {
  248. set bantime [expr $unixtime + $sec_bantime]
  249. }
  250. if {![string equal -nocase $gethand "BADCHAN"] && ![string equal -nocase $gethand "badident"] && ![string equal -nocase $gethand "badnick"] && ![string equal -nocase $gethand "antibadquitpart"] && ![string equal -nocase $gethand "antichanflood"] && ![string equal -nocase $gethand "antispam"] && ![string equal -nocase $gethand "badhost"] && ![string equal -nocase $gethand "inviteban"] && ![string equal -nocase $gethand "private"] && ![string equal -nocase $gethand "clonescan"] && ![string equal -nocase $gethand "noproxy"]} {
  251. set show_reason [blacktools:setreason $chan $reason $gethand $bantime $getcount "0" $id]
  252. }
  253. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  254. set temp "$black(bans_file).new.$timestamp"
  255. set file [open $black(bans_file) r]
  256. set size [file size $black(bans_file)]
  257. set data [split [read $file $size] \n]
  258. close $file
  259. set tempwrite [open $temp w]
  260. foreach line $data {
  261. if {$line != ""} {
  262. set read_chan [lindex [split $line] 2]
  263. set read_host [lindex [split $line] 3]
  264. if {$regex != "REGEX"} {
  265. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  266. } else {set real_read_host $read_host}
  267. if {([string match -nocase $host $real_read_host] || [string match -nocase $real_read_host $host] || [string equal -nocase $real_read_host $host]) && [string equal -nocase $chan $read_chan]} {
  268. set read_num [lindex [split $line] 1]
  269. set read_time [lindex [split $line] 5]
  270. set read_stick [lindex [split $line] 7]
  271. set bywho [lindex [split $line] 4]
  272. set split_bywho [split $bywho ":"]
  273. set level [lindex $split_bywho 1]
  274. if {![string equal -nocase $gethand "BADCHAN"] && ![string equal -nocase $gethand "badident"] && ![string equal -nocase $gethand "badnick"] && ![string equal -nocase $gethand "antibadquitpart"] && ![string equal -nocase $gethand "antichanflood"] && ![string equal -nocase $gethand "badrealname"] && ![string equal -nocase $gethand "antispam"] && ![string equal -nocase $gethand "badhost"] && ![string equal -nocase $gethand "inviteban"] && ![string equal -nocase $gethand "private"] && ![string equal -nocase $gethand "clonescan"] && ![string equal -nocase $gethand "noproxy"]} {
  275. set show_reason [blacktools:setreason $chan $reason $gethand $read_time $getcount "0" $id]
  276. }
  277. set check [blacktools:check:levelub $gethand $chan $level]
  278. if {$check == "-1"} {
  279. puts $tempwrite $line
  280. set accdenied 1
  281. continue
  282. }
  283. if {[matchattr $gethand -|O $chan] && ($read_time == "0")} {
  284. puts $tempwrite $line
  285. set accdenied 1
  286. continue
  287. }
  288. if {[matchattr $gethand -|OAS $chan] && ($read_stick == "1")} {
  289. puts $tempwrite $line
  290. set accdenied 1
  291. continue
  292. }
  293. continue
  294. } else {
  295. puts $tempwrite $line
  296. }
  297. }
  298. }
  299. close $tempwrite
  300. file rename -force $temp $black(bans_file)
  301. if {$read_num != "0"} {
  302. set id $read_num
  303. }
  304. if {$accdenied == "0"} {
  305. if {$rcmd == "b" && $type != "gl"} {
  306. if {$prv != "prv"} {
  307. set prv ""
  308. }
  309. if {$regex == "REGEX"} {
  310. blacktools:tell $nick $prv $hand $chan $chan1 b.12 $id
  311. } elseif {$regex != "REGEX" && [setting:get $chan xonly]} {
  312. blacktools:tell $nick $prv $hand $chan $chan1 b.14 $id
  313. } else {
  314. blacktools:tell $nick $prv $hand $chan $chan1 b.7 $id
  315. }
  316. }
  317. if {$notfound == "1"} {
  318. if {[setting:get $chan xonly]} {
  319. set xban 1
  320. set getxtime [setting:get $chan xbantime]
  321. set getxlevel [setting:get $chan xbanlevel]
  322. if {$getxtime == ""} {
  323. set getxtime $black(chanserv:bantime)
  324. }
  325. if {$getxlevel == ""} {
  326. set getxlevel $black(chanserv:banlevel)
  327. }
  328. }
  329. set show_reason [blacktools:rem_comment_ban $show_reason]
  330. if {[onchan $black(chanserv) $chan] && $xban == "1" && $regex != "REGEX"} {
  331. if {$rcmd == "stick"} {
  332. putquick "MODE $chan +b $host"
  333. }
  334. putquick "PRIVMSG $black(chanserv) :ban $chan $host $getxtime $getxlevel $show_reason"
  335. } else {
  336. if {$regex != "REGEX"} {
  337. putquick "MODE $chan +b $host"
  338. }
  339. }
  340. }
  341. blacktools:ban:put $nick $host $hand $chan $bantime $type $sticky $global $reason $id
  342. } else {
  343. blacktools:tell $nick $host $hand $chan $chan1 gl.nobanlevel "$host"
  344. }
  345. }
  346. ###
  347. proc blacktools:ban:put {nick host hand chan bantime type sticky global reason id} {
  348. global black
  349. set is_comment 0
  350. set file [open $black(bans_file) "a"]
  351. if {[lsearch -exact -nocase $reason "-comment"] > -1} {
  352. set is_comment 1
  353. set split_it [wsplit $reason "-comment"]
  354. set comment [concat [lindex $split_it 1]]
  355. set reason [concat [lindex $split_it 0]]
  356. } elseif {[lsearch -exact -nocase $reason "-com"] > -1} {
  357. set is_comment 1
  358. set split_it [wsplit $reason "-com"]
  359. set comment [concat [lindex $split_it 1]]
  360. set reason [concat [lindex $split_it 0]]
  361. } elseif {[lsearch -exact -nocase $reason "-c"] > -1} {
  362. set is_comment 1
  363. set split_it [wsplit $reason "-c"]
  364. set comment [concat [lindex $split_it 1]]
  365. set reason [concat [lindex $split_it 0]]
  366. }
  367. set created [unixtime]
  368. if {$is_comment == "1"} {
  369. if {$global == "1"} {
  370. puts $file "$type $id GLOBAL $host $hand $bantime $created $sticky $global $reason%C%$comment"
  371. } else {
  372. puts $file "$type $id [string tolower $chan] $host $hand $bantime $created $sticky $global $reason%C%$comment"
  373. }
  374. } else {
  375. if {$global == "1"} {
  376. puts $file "$type $id GLOBAL $host $hand $bantime $created $sticky $global $reason"
  377. } else {
  378. puts $file "$type $id [string tolower $chan] $host $hand $bantime $created $sticky $global $reason"
  379. }
  380. }
  381. close $file
  382. blacktools:ub:setlast $bantime
  383. set black(bans) [blacktools:banlist:all]
  384. }
  385. ###
  386. proc blacktools:autounban {} {
  387. global black
  388. chanserv:ignore_remove
  389. set found_expired 0
  390. foreach b $black(bans) {
  391. set read_time [lindex [split $b] 5]
  392. if {$read_time == "0"} { continue }
  393. if {[expr $read_time - [unixtime]] <= 0} {
  394. set read_host [lindex [split $b] 3]
  395. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  396. set read_type [lindex [split $b] 0]
  397. set read_chan [lindex [split $b] 2]
  398. set read_tr [lindex [split $b] 7]
  399. blacktools:auto:remove $real_read_host $read_chan
  400. set found_expired 1
  401. if {![validchan $read_chan]} {
  402. if {[string equal -nocase $read_chan "GLOBAL"]} {
  403. foreach chan [channels] {
  404. if {[ischanban $read_host $chan]} {
  405. if {[setting:get $chan xonly] && [onchan $black(chanserv)]} {
  406. putquick "PRIVMSG $black(chanserv) :unban $chan $read_host"
  407. } else {
  408. pushmode $chan -b $read_host
  409. }
  410. }
  411. }
  412. }
  413. continue
  414. } else { set chan $read_chan }
  415. if {[botisop $chan]} {
  416. set getlang [string tolower [setting:get $chan lang]]
  417. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  418. if {[ischanban $read_host $chan]} {
  419. if {[string equal -nocase $read_type "GAG"]} {
  420. foreach user [chanlist $chan] {
  421. set uhost "$user![getchanhost $user $chan]"
  422. if {[string match -nocase $real_read_host $uhost]} {
  423. set replace(%nick%) $user
  424. set replace(%chan%) $chan
  425. set text [black:color:set "" $black(say.$getlang.gag.5)]
  426. set reply [join $text]
  427. puthelp "PRIVMSG $chan :[string map [array get replace] $reply]"
  428. }
  429. }
  430. }
  431. pushmode $chan -b $read_host
  432. }
  433. }
  434. if {$read_tr == "2"} {
  435. troll:del $read_host $chan
  436. }
  437. if {[setting:get $chan xonly] && [onchan $black(chanserv)]} {
  438. putquick "PRIVMSG $black(chanserv) :unban $chan $read_host"
  439. }
  440. }
  441. }
  442. if {$found_expired == 1} {
  443. set black(bans) [blacktools:banlist:all]
  444. }
  445. set lastban [blacktools:getlastban]
  446. if {$lastban == "-1"} {
  447. if {[info exists black(lastban)]} {
  448. unset black(lastban)
  449. }
  450. return
  451. }
  452. set black(lastban) $lastban
  453. foreach tmr [utimers] {
  454. if {[string match "*blacktools:autounban*" [join [lindex $tmr 1]]]} {
  455. killutimer [lindex $tmr 2]
  456. }
  457. }
  458. utimer $black(lastban) [list blacktools:autounban]
  459. }
  460. ###
  461. proc blacktools:join:autoban {nick host vhost hand chan fullhost realname} {
  462. global black
  463. set hand [nick2hand $nick]
  464. set foundblacktools_ban 0
  465. set specified_bmask ""
  466. set rest_host [lindex [split $fullhost @] 0]
  467. if {$host == ""} {set fulldns $fullhost} else {set fulldns "$rest_host@$host"}
  468. chanserv:ignore_remove
  469. set getlang [string tolower [setting:get $chan lang]]
  470. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  471. set xban 0
  472. set getcount [setting:get $chan kickcount]
  473. if {![botisop $chan] && ![setting:get $chan xonly]} {
  474. return
  475. }
  476. if {[setting:get $chan xonly]} {
  477. set xban 1
  478. set getxtime [setting:get $chan xbantime]
  479. set getxlevel [setting:get $chan xbanlevel]
  480. if {$getxtime == ""} {
  481. set getxtime $black(chanserv:bantime)
  482. }
  483. if {$getxlevel == ""} {
  484. set getxlevel $black(chanserv:banlevel)
  485. }
  486. }
  487. set foundgl 0
  488. set getcount [setting:get $chan kickcount]
  489. if {[validuser $hand]} {
  490. if {[matchattr $hand $black(banflag)]} {
  491. set hosts [getuser $hand hosts]
  492. set cidr 0
  493. foreach h $hosts {
  494. if {[regexp {[/]} $h]} {
  495. set read_ip [lindex [split $h @] 1]
  496. set theip [lindex [split $fullhost @] 1]
  497. set cidr_ip [ipcidr $read_ip $theip]
  498. if {$cidr_ip == "1"} {
  499. set read_rest_ip [lindex [split $h @] 0]
  500. set read_theip [lindex [split $fullhost @] 0]
  501. if {[string match -nocase $read_rest_ip $read_theip] || [string match -nocase $read_theip $read_rest_ip]} {
  502. set cidr 1
  503. }
  504. }
  505. }
  506. }
  507. if {[string match -nocase $h $fullhost] || [string match -nocase $h $fulldns] || $cidr == "1"} {
  508. set check_except [blacktools:ban:chanexempt $fullhost $fulldns $chan]
  509. if {$check_except == "0"} {
  510. add:ban $h [join [getuser $hand XTRA BLACK_REASON]]
  511. }
  512. }
  513. }
  514. }
  515. set llength_banlist [llength $black(bans)]
  516. for {set i $llength_banlist} { $i >= 0 } { decr i } {
  517. set b [lindex $black(bans) $i]
  518. set cidr 0
  519. set type [lindex [split $b] 0]
  520. set read_chan [lindex [split $b] 2]
  521. set read_host [lindex [split $b] 3]
  522. if {[string equal -nocase $type "REGEX"] && [string equal -nocase $read_chan $chan]} {
  523. if {[regexp {[/]} $read_host]} {
  524. set a ""
  525. regexp {/(.*)} $read_host a
  526. if {$a != ""} {
  527. set split_a [split $a "/"]
  528. if {[regexp {[0-9]} [lindex $split_a 1]]} {
  529. set specified_bmask [lindex $split_a 1]
  530. } elseif {[regexp {[0-9]} [lindex $split_a 2]]} {
  531. set specified_bmask [lindex $split_a 2]
  532. }
  533. if {$specified_bmask != ""} {
  534. regsub "/$specified_bmask" $read_host "" read_host
  535. }
  536. }
  537. set rfullhost "$fullhost/$realname"
  538. set rfulldns "$fulldns/$realname"
  539. } else {
  540. set rfullhost "$fullhost"
  541. set rfulldns "$fulldns"
  542. }
  543. if {[regexp "$read_host" $rfullhost] || [regexp "$read_host" $rfulldns]} {
  544. if {[matchattr $hand $black(exceptflags) $chan]} {
  545. break
  546. }
  547. set check_except [blacktools:ban:chanexempt $fullhost $fulldns $chan]
  548. if {$check_except == "1"} {
  549. break
  550. }
  551. if {$specified_bmask != ""} {
  552. set mask [return_mask $specified_bmask $fullhost $nick]
  553. } else {
  554. set mask [return_mask [return_host_num "b" $chan $fullhost] $fullhost $nick]
  555. }
  556. set foundblacktools_ban 1
  557. set num [lindex [split $b] 1]
  558. set read_reason [join [lrange [split $b] 9 end]]
  559. set read_reason [blacktools:rem_comment $read_reason]
  560. set read_reason [encoding convertfrom utf-8 $read_reason]
  561. set expire [lindex [split $b] 5]
  562. set read_handle [split [lindex [split $b] 4] ":"]
  563. set gethand [lindex [split $read_handle] 0]
  564. set show_reason [blacktools:setreason $chan $read_reason $read_handle $expire $getcount "2" $num]
  565. if {$expire == "0"} {
  566. set show_reason [blacktools:bl:setreason $chan $read_reason $read_handle $expire $getcount "0" $num]
  567. if {[setting:get $chan showhandle]} {
  568. if {![string equal -nocase $gethand "BADCHAN"] && ![string equal -nocase $gethand "badident"] && ![string equal -nocase $gethand "badnick"] && ![string equal -nocase $gethand "antibadquitpart"] && ![string equal -nocase $gethand "antichanflood"] && ![string equal -nocase $gethand "badrealname"] && ![string equal -nocase $gethand "antispam"] && ![string equal -nocase $gethand "badhost"] && ![string equal -nocase $gethand "antipub"] && ![string equal -nocase $gethand "antijoinflood"] && ![string equal -nocase $gethand "antinotice"] && ![string equal -nocase $gethand "antictcp"] && ![string equal -nocase $gethand "antirepeat"] && ![string equal -nocase $gethand "antibold"] && ![string equal -nocase $gethand "anticolor"] && ![string equal -nocase $gethand "antiunderline"] && ![string equal -nocase $gethand "antilongtext"] && ![string equal -nocase $gethand "antibadword"] && ![string equal -nocase $gethand "anticaps"] && ![string equal -nocase $gethand "nickflood"] && ![string equal -nocase $gethand "inviteban"] && ![string equal -nocase $gethand "private"] && ![string equal -nocase $gethand "clonescan"] && ![string equal -nocase $gethand "repetitivechars"] && ![string equal -nocase $gethand "noproxy"]} {
  569. set show_reason "\[BT\] \[$gethand\] (REGEX) blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  570. } else {
  571. set show_reason "\[BT\] (REGEX) blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  572. }
  573. } else {
  574. set show_reason "\[BT\] (REGEX) blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  575. }
  576. }
  577. if {[onchan $black(chanserv) $chan] && $xban == "1"} {
  578. putquick "PRIVMSG $black(chanserv) :ban $chan $mask $getxtime $getxlevel $show_reason"
  579. } else {
  580. putquick "MODE $chan +b $mask"
  581. putquick "KICK $chan $nick :$show_reason"
  582. }
  583. break
  584. }
  585. }
  586. if {[string equal -nocase $type "BAN"] && ![string equal -nocase $read_chan "GLOBAL"] && [string equal -nocase $read_chan $chan]} {
  587. set read_host [lindex [split $b] 3]
  588. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  589. if {[regexp {[/]} $real_read_host]} {
  590. set read_ip [lindex [split $real_read_host @] 1]
  591. set theip [lindex [split $fullhost @] 1]
  592. set theip_dns [lindex [split $fulldns @] 1]
  593. set cidr_ip [ipcidr $read_ip $theip]
  594. set cidr_ip_dns [ipcidr $read_ip $theip_dns]
  595. if {$cidr_ip == "1" || $cidr_ip_dns == "1"} {
  596. set read_rest_ip [lindex [split $fullhost @] 0]
  597. set read_theip [lindex [split $real_read_host @] 0]
  598. if {[string match -nocase $read_rest_ip $read_theip] || [string match -nocase $read_theip $read_rest_ip]} {
  599. set cidr 1
  600. }
  601. }
  602. }
  603. if {([string match -nocase $fulldns $real_read_host] || [string match -nocase $real_read_host $fulldns]) || ([string match -nocase $fullhost $real_read_host] || [string match -nocase $real_read_host $fullhost]) || ($cidr == "1")} {
  604. set check_except [blacktools:ban:chanexempt $fullhost $fulldns $chan]
  605. if {$check_except == "1"} {
  606. break
  607. }
  608. set foundblacktools_ban 1
  609. set num [lindex [split $b] 1]
  610. set read_reason [join [lrange [split $b] 9 end]]
  611. set read_reason [encoding convertfrom utf-8 $read_reason]
  612. set expire [lindex [split $b] 5]
  613. set read_handle [split [lindex [split $b] 4] ":"]
  614. set gethand [lindex [split $read_handle] 0]
  615. set show_reason [blacktools:setreason $chan $read_reason $read_handle $expire $getcount "0" $num]
  616. if {$expire == "0"} {
  617. set show_reason [blacktools:bl:setreason $chan $read_reason $read_handle $expire $getcount "0" $num]
  618. if {[setting:get $chan showhandle]} {
  619. if {![string equal -nocase $gethand "BADCHAN"] && ![string equal -nocase $gethand "badident"] && ![string equal -nocase $gethand "badnick"] && ![string equal -nocase $gethand "antibadquitpart"] && ![string equal -nocase $gethand "antichanflood"] && ![string equal -nocase $gethand "badrealname"] && ![string equal -nocase $gethand "antispam"] && ![string equal -nocase $gethand "badhost"] && ![string equal -nocase $gethand "antipub"] && ![string equal -nocase $gethand "antijoinflood"] && ![string equal -nocase $gethand "antinotice"] && ![string equal -nocase $gethand "antictcp"] && ![string equal -nocase $gethand "antirepeat"] && ![string equal -nocase $gethand "antibold"] && ![string equal -nocase $gethand "anticolor"] && ![string equal -nocase $gethand "antiunderline"] && ![string equal -nocase $gethand "antilongtext"] && ![string equal -nocase $gethand "antibadword"] && ![string equal -nocase $gethand "anticaps"] && ![string equal -nocase $gethand "nickflood"] && ![string equal -nocase $gethand "inviteban"] && ![string equal -nocase $gethand "private"] && ![string equal -nocase $gethand "clonescan"] && ![string equal -nocase $gethand "repetitivechars"] && ![string equal -nocase $gethand "noproxy"]} {
  620. set show_reason "\[BT\] \[$gethand\] blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  621. } else {
  622. set show_reason "\[BT\] blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  623. }
  624. } else {
  625. set show_reason "\[BT\] blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  626. }
  627. }
  628. if {[onchan $black(chanserv) $chan] && $xban == "1"} {
  629. putquick "PRIVMSG $black(chanserv) :ban $chan $read_host $getxtime $getxlevel $show_reason"
  630. } else {
  631. putquick "MODE $chan +b $read_host"
  632. putquick "KICK $chan $nick :$show_reason"
  633. }
  634. break
  635. }
  636. }
  637. if {[string equal -nocase $read_chan "GLOBAL"]} {
  638. set cidr 0
  639. set read_host [lindex [split $b] 3]
  640. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  641. if {[string equal -nocase $type "REGEX"]} {
  642. if {[regexp {[/]} $read_host]} {
  643. set a ""
  644. regexp {/(.*)} $read_host a
  645. if {$a != ""} {
  646. set split_a [split $a "/"]
  647. if {[regexp {[0-9]} [lindex $split_a 1]]} {
  648. set specified_bmask [lindex $split_a 1]
  649. } elseif {[regexp {[0-9]} [lindex $split_a 2]]} {
  650. set specified_bmask [lindex $split_a 2]
  651. }
  652. if {$specified_bmask != ""} {
  653. regsub "/$specified_bmask" $read_host "" read_host
  654. }
  655. }
  656. set rfullhost "$fullhost/$realname"
  657. set rfulldns "$fulldns/$realname"
  658. } else {
  659. set rfullhost "$fullhost"
  660. set rfulldns "$fulldns"
  661. }
  662. if {[regexp "$read_host" $rfullhost] || [regexp "$read_host" $rfulldns]} {
  663. set check_except [blacktools:ban:exempt $fullhost]
  664. if {$check_except == "1"} {
  665. break
  666. }
  667. if {$specified_bmask != ""} {
  668. set mask [return_mask $specified_bmask $fullhost $nick]
  669. } else {
  670. set mask [return_mask $black(b:banmask) $fullhost $nick]
  671. }
  672. set foundblacktools_ban 1
  673. set num [lindex [split $b] 1]
  674. set read_reason [join [lrange [split $b] 9 end]]
  675. set read_reason [encoding convertfrom utf-8 $read_reason]
  676. set expire [lindex [split $b] 5]
  677. set read_handle [lindex [split $b] 4]
  678. set show_reason [blacktools:setreason $chan $read_reason $read_handle $expire "" "3" $num]
  679. if {$expire == "0"} {
  680. set show_reason [blacktools:bl:setreason $chan $read_reason $read_handle $expire $getcount "0" $num]
  681. if {[setting:get $chan showhandle]} {
  682. set show_reason "\[BT\] \[$read_handle\] (GLOBAL) (REGEX) blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  683. } else {
  684. set show_reason "\[BT\] (GLOBAL) (REGEX) blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  685. }
  686. }
  687. if {[onchan $black(chanserv) $chan] && $xban == "1"} {
  688. putquick "PRIVMSG $black(chanserv) :ban $chan $mask $getxtime $getxlevel $show_reason"
  689. } else {
  690. putquick "MODE $chan +b $mask"
  691. putquick "KICK $chan $nick :$show_reason"
  692. }
  693. break
  694. }
  695. }
  696. if {[regexp {[/]} $real_read_host]} {
  697. set read_ip [lindex [split $real_read_host @] 1]
  698. set theip [lindex [split $fullhost @] 1]
  699. set theip_dns [lindex [split $fulldns @] 1]
  700. set cidr_ip [ipcidr $read_ip $theip]
  701. set cidr_ip_dns [ipcidr $read_ip $theip_dns]
  702. if {$cidr_ip == "1" || $cidr_ip_dns == "1"} {
  703. set read_rest_ip [lindex [split $fullhost @] 0]
  704. set read_theip [lindex [split $real_read_host @] 0]
  705. if {[string match -nocase $read_rest_ip $read_theip] || [string match -nocase $read_theip $read_rest_ip]} {
  706. set cidr 1
  707. }
  708. }
  709. }
  710. if {([string match -nocase $fullhost $real_read_host] || [string match -nocase $real_read_host $fullhost]) || ($cidr == "1")} {
  711. set check_except [blacktools:ban:exempt $fullhost]
  712. if {$check_except == "1"} {
  713. break
  714. }
  715. set foundblacktools_ban 1
  716. set num [lindex [split $b] 1]
  717. set read_reason [join [lrange [split $b] 9 end]]
  718. set read_reason [encoding convertfrom utf-8 $read_reason]
  719. set expire [lindex [split $b] 5]
  720. set read_handle [lindex [split $b] 4]
  721. set show_reason [blacktools:setreason $chan $read_reason $read_handle $expire "" "1" $num]
  722. if {$expire == "0"} {
  723. set show_reason [blacktools:bl:setreason $chan $read_reason $read_handle $expire $getcount "0" $num]
  724. if {[setting:get $chan showhandle]} {
  725. set show_reason "\[BT\] \[$read_handle\] (GLOBAL) blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  726. } else {
  727. set show_reason "\[BT\] (GLOBAL) blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  728. }
  729. }
  730. if {[onchan $black(chanserv) $chan] && $xban == "1"} {
  731. putquick "PRIVMSG $black(chanserv) :ban $chan $read_host $getxtime $getxlevel $show_reason"
  732. } else {
  733. putquick "MODE $chan +b $read_host"
  734. putquick "KICK $chan $nick :$show_reason"
  735. }
  736. break
  737. }
  738. }
  739. if {[string equal -nocase $type "GAG"] && [string equal -nocase $read_chan $chan]} {
  740. set read_host [lindex [split $b] 3]
  741. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  742. if {([string match -nocase $fulldns $real_read_host] || [string match -nocase $real_read_host $fulldns]) || ([string match -nocase $fullhost $real_read_host] || [string match -nocase $real_read_host $fullhost])} {
  743. if {[ischanban $read_host $chan]} {
  744. continue
  745. }
  746. set expire [lindex [split $b] 5]
  747. set read_time [return_time $getlang [expr $expire - [unixtime]]]
  748. set replace(%minute%) $read_time
  749. set replace(%gag%) $nick
  750. pushmode $chan +b $read_host
  751. if {[isop $nick $chan]} {
  752. pushmode $chan -o $nick
  753. }
  754. if {[isvoice $nick $chan]} {
  755. pushmode $chan -v $nick
  756. }
  757. set text [black:color:set "" $black(say.$getlang.gag.1)]
  758. set reply [join $text]
  759. set reply [string map [array get replace] $reply]
  760. putquick "PRIVMSG $chan :$reply"
  761. break
  762. }
  763. }
  764. }
  765. if {$foundblacktools_ban == 0} {
  766. foreach ban [banlist] {
  767. if {[string match -nocase [string tolower [lindex $ban 0]] $host]} {
  768. set foundgl 1
  769. set reason [lindex [split $ban] 1]
  770. set expire [lindex [split $ban] 2]
  771. set reason [join [lindex [split $ban] 1]]
  772. set bywho [lindex [split $ban] 5]
  773. set show_reason [blacktools:setreason $chan $reason $bywho $expire "" "1" "0"]
  774. if {[onchan $black(chanserv) $chan] && $xban == "1"} {
  775. putquick "PRIVMSG $black(chanserv) :ban $chan [lindex $ban 0] $getxtime $getxlevel $show_reason"
  776. } else {
  777. putquick "MODE $chan +b [lindex $ban 0]"
  778. putquick "KICK $chan $nick :$show_reason"
  779. }
  780. break
  781. }
  782. }
  783. if {$foundgl == "0"} {
  784. foreach ban [banlist $chan] {
  785. if {[string match -nocase [string tolower [lindex $ban 0]] $host]} {
  786. set reason [lindex $ban 1]
  787. set expire [lindex $ban 2]
  788. set reason [join [split [lindex $ban 1]]]
  789. set bywho [split [lindex $ban 5]]
  790. set show_reason [blacktools:setreason $chan $reason $bywho $expire $getcount "0" "0"]
  791. if {[onchan $black(chanserv) $chan] && $xban == "1"} {
  792. putquick "PRIVMSG $black(chanserv) :ban $chan [lindex $ban 0] $getxtime $getxlevel $show_reason"
  793. } else {
  794. putquick "MODE $chan +b [lindex $ban 0]"
  795. putquick "KICK $chan $nick :$show_reason"
  796. }
  797. break
  798. }
  799. }
  800. }
  801. }
  802. }
  803. ###
  804. proc blacktools:auto:remove {host chan} {
  805. global black
  806. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  807. set temp "$black(bans_file).new.$timestamp"
  808. set tempwrite [open $temp w]
  809. set file [open $black(bans_file) r]
  810. set size [file size $black(bans_file)]
  811. set data [split [read $file $size] \n]
  812. close $file
  813. foreach line $data {
  814. set read_host [lindex [split $line] 3]
  815. set read_chan [lindex [split $line] 2]
  816. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  817. if {([string match -nocase $host $real_read_host] || [string equal -nocase $host $real_read_host]) && [string equal -nocase $read_chan $chan]} {
  818. continue
  819. } else {
  820. puts $tempwrite $line
  821. }
  822. }
  823. close $tempwrite
  824. file rename -force $temp $black(bans_file)
  825. }
  826. ###
  827. proc blacktools:join:ban {nick host hand chan} {
  828. global black
  829. if {[isbotnick $nick]} {
  830. foreach tmr [utimers] {
  831. if {[string match "*who:chan $chan*" [join [lindex $tmr 1]]]} {
  832. killutimer [lindex $tmr 2]
  833. }
  834. }
  835. utimer 5 [list who:chan $chan]
  836. foreach b [blacktools:banlist:ban $chan] {
  837. set read_host [lindex [split $b] 3]
  838. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  839. set sticky [lindex [split $b] 7]
  840. if {$sticky == "1"} {
  841. if {![ischanban $read_host $chan]} {
  842. utimer 5 [list pushmode $chan +b $read_host]
  843. }
  844. }
  845. }
  846. }
  847. }
  848. ###
  849. proc blacktools:auto:ban_act {nick uhost vhost chan realname} {
  850. global black botnick
  851. set rest_host [lindex [split $uhost @] 0]
  852. set found_ban 0
  853. set fulldns "$rest_host@$vhost"
  854. set specified_bmask ""
  855. if {$vhost == ""} { set fulldns $uhost}
  856. set xban 0
  857. set getcount [setting:get $chan kickcount]
  858. set getlang [string tolower [setting:get $chan lang]]
  859. chanserv:ignore_remove
  860. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  861. if {![botisop $chan] && ![setting:get $chan xonly]} {
  862. return
  863. }
  864. if {[setting:get $chan xonly]} {
  865. set xban 1
  866. set getxtime [setting:get $chan xbantime]
  867. set getxlevel [setting:get $chan xbanlevel]
  868. if {$getxtime == ""} {
  869. set getxtime $black(chanserv:bantime)
  870. }
  871. if {$getxlevel == ""} {
  872. set getxlevel $black(chanserv:banlevel)
  873. }
  874. }
  875. set handle [nick2hand $nick]
  876. if {$handle != "*"} {
  877. if {[validuser $handle]} {
  878. if {[matchattr $handle B]} {
  879. set hosts [getuser $handle hosts]
  880. set cidr 0
  881. foreach h $hosts {
  882. if {[regexp {[/]} $h]} {
  883. set read_ip [lindex [split $h @] 1]
  884. set theip [lindex [split $uhost @] 1]
  885. set cidr_ip [ipcidr $read_ip $theip]
  886. if {$cidr_ip == "1"} {
  887. set read_rest_ip [lindex [split $h @] 0]
  888. set read_theip [lindex [split $uhost @] 0]
  889. if {[string match -nocase $read_rest_ip $read_theip] || [string match -nocase $read_theip $read_rest_ip]} {
  890. set cidr 1
  891. }
  892. }
  893. }
  894. if {[string match -nocase $h $uhost] || [string match -nocase $h $fulldns] || $cidr == "1"} {
  895. set check_except [blacktools:ban:chanexempt $uhost $fulldns $chan]
  896. if {$check_except == "0"} {
  897. add:ban $h [join [getuser $handle XTRA BLACK_REASON]]
  898. set found_ban 1
  899. }
  900. }
  901. }
  902. }
  903. }
  904. }
  905. if {$found_ban == "1"} {
  906. return
  907. }
  908. set llength_banlist [llength $black(bans)]
  909. for {set i $llength_banlist} { $i >= 0 } { decr i } {
  910. set b [lindex $black(bans) $i]
  911. set cidr 0
  912. set type [lindex [split $b] 0]
  913. set read_chan [lindex [split $b] 2]
  914. if {[string equal -nocase $type "REGEX"] && [string equal -nocase $read_chan $chan]} {
  915. set read_host [lindex [split $b] 3]
  916. if {[regexp {[/]} $read_host]} {
  917. set a ""
  918. regexp {/(.*)} $read_host a
  919. if {$a != ""} {
  920. set split_a [split $a "/"]
  921. if {[regexp {[0-9]} [lindex $split_a 1]]} {
  922. set specified_bmask [lindex $split_a 1]
  923. } elseif {[regexp {[0-9]} [lindex $split_a 2]]} {
  924. set specified_bmask [lindex $split_a 2]
  925. }
  926. if {$specified_bmask != ""} {
  927. regsub "/$specified_bmask" $read_host "" read_host
  928. }
  929. }
  930. set rfullhost "$uhost/$realname"
  931. set rfulldns "$fulldns/$realname"
  932. } else {
  933. set rfullhost "$uhost"
  934. set rfulldns "$fulldns"
  935. }
  936. if {[regexp "$read_host" $rfullhost] || [regexp "$read_host" $rfulldns]} {
  937. if {[matchattr $handle $black(exceptflags) $chan]} {
  938. continue
  939. }
  940. set check_except [blacktools:ban:chanexempt $uhost $fulldns $chan]
  941. if {$check_except == "1"} {
  942. break
  943. }
  944. if {$specified_bmask != ""} {
  945. set mask [return_mask $specified_bmask $uhost $nick]
  946. } else {
  947. set mask [return_mask [return_host_num "b" $chan $uhost] $uhost $nick]
  948. }
  949. set num [lindex [split $b] 1]
  950. set read_reason [join [lrange [split $b] 9 end]]
  951. set read_reason [blacktools:rem_comment $read_reason]
  952. set read_reason [encoding convertfrom utf-8 $read_reason]
  953. set expire [lindex [split $b] 5]
  954. set read_handle [split [lindex [split $b] 4] ":"]
  955. set gethand [lindex [split $read_handle] 0]
  956. set show_reason [blacktools:setreason $chan $read_reason $read_handle $expire $getcount "2" $num]
  957. if {$expire == "0"} {
  958. set show_reason [blacktools:bl:setreason $chan $read_reason $read_handle $expire $getcount "0" $num]
  959. if {[setting:get $chan showhandle]} {
  960. if {![string equal -nocase $gethand "BADCHAN"] && ![string equal -nocase $gethand "badident"] && ![string equal -nocase $gethand "badnick"] && ![string equal -nocase $gethand "antibadquitpart"] && ![string equal -nocase $gethand "antichanflood"] && ![string equal -nocase $gethand "badrealname"] && ![string equal -nocase $gethand "antispam"] && ![string equal -nocase $gethand "badhost"] && ![string equal -nocase $gethand "antipub"] && ![string equal -nocase $gethand "antijoinflood"] && ![string equal -nocase $gethand "antinotice"] && ![string equal -nocase $gethand "antictcp"] && ![string equal -nocase $gethand "antirepeat"] && ![string equal -nocase $gethand "antibold"] && ![string equal -nocase $gethand "anticolor"] && ![string equal -nocase $gethand "antiunderline"] && ![string equal -nocase $gethand "antilongtext"] && ![string equal -nocase $gethand "antibadword"] && ![string equal -nocase $gethand "anticaps"] && ![string equal -nocase $gethand "nickflood"] && ![string equal -nocase $gethand "inviteban"] && ![string equal -nocase $gethand "private"] && ![string equal -nocase $gethand "clonescan"] && ![string equal -nocase $gethand "repetitivechars"] && ![string equal -nocase $gethand "noproxy"]} {
  961. set show_reason "\[BT\] \[$gethand\] (REGEX) blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  962. } else {
  963. set show_reason "\[BT\] (REGEX) blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  964. }
  965. } else {
  966. set show_reason "\[BT\] (REGEX) blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  967. }
  968. }
  969. if {[onchan $black(chanserv) $chan] && $xban == "1"} {
  970. putquick "PRIVMSG $black(chanserv) :ban $chan $mask $getxtime $getxlevel $show_reason"
  971. } else {
  972. putquick "MODE $chan +b $mask"
  973. putquick "KICK $chan $nick :$show_reason"
  974. }
  975. break
  976. }
  977. }
  978. if {[string equal -nocase $type "BAN"] && ![string equal -nocase $read_chan "GLOBAL"] && [string equal -nocase $read_chan $chan]} {
  979. set read_host [lindex [split $b] 3]
  980. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  981. if {[regexp {[/]} $real_read_host]} {
  982. set read_ip [lindex [split $real_read_host @] 1]
  983. set theip [lindex [split $uhost @] 1]
  984. set theip_dns [lindex [split $fulldns @] 1]
  985. set cidr_ip [ipcidr $read_ip $theip]
  986. set cidr_dns [ipcidr $read_ip $theip_dns]
  987. if {$cidr_ip == "1" || $cidr_dns == "1"} {
  988. set read_rest_ip [lindex [split $uhost @] 0]
  989. set read_theip [lindex [split $real_read_host @] 0]
  990. if {[string match -nocase $read_rest_ip $read_theip] || [string match -nocase $read_theip $read_rest_ip]} {
  991. set cidr 1
  992. }
  993. }
  994. }
  995. if {([string match -nocase $real_read_host $uhost] || [string match -nocase $uhost $real_read_host]) || ([string match -nocase $real_read_host $fulldns] || [string match -nocase $fulldns $real_read_host]) || ($cidr == "1")} {
  996. set check_except [blacktools:ban:chanexempt $uhost $fulldns $chan]
  997. if {$check_except == "1"} {
  998. break
  999. }
  1000. set num [lindex [split $b] 1]
  1001. set read_reason [join [lrange [split $b] 9 end]]
  1002. set read_reason [blacktools:rem_comment $read_reason]
  1003. set read_reason [encoding convertfrom utf-8 $read_reason]
  1004. set expire [lindex [split $b] 5]
  1005. set read_handle [split [lindex [split $b] 4] ":"]
  1006. set gethand [lindex [split $read_handle] 0]
  1007. set show_reason [blacktools:setreason $chan $read_reason $read_handle $expire $getcount "0" $num]
  1008. if {$expire == "0"} {
  1009. set show_reason [blacktools:bl:setreason $chan $read_reason $read_handle $expire $getcount "0" $num]
  1010. if {[setting:get $chan showhandle]} {
  1011. if {![string equal -nocase $gethand "BADCHAN"] && ![string equal -nocase $gethand "badident"] && ![string equal -nocase $gethand "badnick"] && ![string equal -nocase $gethand "antibadquitpart"] && ![string equal -nocase $gethand "antichanflood"] && ![string equal -nocase $gethand "badrealname"] && ![string equal -nocase $gethand "antispam"] && ![string equal -nocase $gethand "badhost"] && ![string equal -nocase $gethand "antipub"] && ![string equal -nocase $gethand "antijoinflood"] && ![string equal -nocase $gethand "antinotice"] && ![string equal -nocase $gethand "antictcp"] && ![string equal -nocase $gethand "antirepeat"] && ![string equal -nocase $gethand "antibold"] && ![string equal -nocase $gethand "anticolor"] && ![string equal -nocase $gethand "antiunderline"] && ![string equal -nocase $gethand "antilongtext"] && ![string equal -nocase $gethand "antibadword"] && ![string equal -nocase $gethand "anticaps"] && ![string equal -nocase $gethand "nickflood"] && ![string equal -nocase $gethand "inviteban"] && ![string equal -nocase $gethand "private"] && ![string equal -nocase $gethand "clonescan"] && ![string equal -nocase $gethand "repetitivechars"] && ![string equal -nocase $gethand "noproxy"]} {
  1012. set show_reason "\[BT\] \[$gethand\] blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  1013. } else {
  1014. set show_reason "\[BT\] blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  1015. }
  1016. } else {
  1017. set show_reason "\[BT\] blacklisted -- ($black(say.$getlang.gl.reason): $show_reason)"
  1018. }
  1019. }
  1020. if {[onchan $black(chanserv) $chan] && $xban == "1"} {
  1021. putquick "PRIVMSG $black(chanserv) :ban $chan $read_host $getxtime $getxlevel $show_reason"
  1022. } else {
  1023. putquick "MODE $chan +b $read_host"
  1024. putquick "KICK $chan $nick :$show_reason"
  1025. }
  1026. break
  1027. }
  1028. }
  1029. if {[string equal -nocase $read_chan "GLOBAL"]} {
  1030. set cidr 0
  1031. set read_host [lindex [split $b] 3]
  1032. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  1033. if {[string equal -nocase $type "REGEX"]} {
  1034. if {[regexp {[/]} $read_host]} {
  1035. set a ""
  1036. regexp {/(.*)} $read_host a
  1037. if {$a != ""} {
  1038. set split_a [split $a "/"]
  1039. if {[regexp {[0-9]} [lindex $split_a 1]]} {
  1040. set specified_bmask [lindex $split_a 1]
  1041. } elseif {[regexp {[0-9]} [lindex $split_a 2]]} {
  1042. set specified_bmask [lindex $split_a 2]
  1043. }
  1044. if {$specified_bmask != ""} {
  1045. regsub "/$specified_bmask" $read_host "" read_host
  1046. }
  1047. }
  1048. set rfullhost "$uhost/$realname"
  1049. set rfulldns "$fulldns/$realname"
  1050. } else {
  1051. set rfullhost "$uhost"
  1052. set rfulldns "$fulldns"
  1053. }
  1054. if {[regexp "$read_host" $rfullhost] || [regexp "$read_host" $rfulldns]} {
  1055. set check_except [blacktools:ban:exempt $uhost]
  1056. if {$check_except == "1"} {
  1057. break
  1058. }
  1059. if {$specified_bmask != ""} {
  1060. set mask [return_mask $specified_bmask $uhost $nick]
  1061. } else {
  1062. set mask [return_mask $black(b:banmask) $uhost $nick]
  1063. }
  1064. set num [lindex [split $b] 1]
  1065. set read_reason [join [lrange [split $b] 9 end]]
  1066. set read_reason [blacktools:rem_comment $read_reason]
  1067. set read_reason [encoding convertfrom utf-8 $read_reason]
  1068. set expire [lindex [split $b] 5]
  1069. set read_handle [lindex [split $b] 4]
  1070. set read_handle [lindex [split $b] 4]
  1071. set gethand [lindex [split $read_handle] 0]
  1072. set show_reason [blacktools:setreason $chan $read_reason $read_handle $expire "" "3" $num]
  1073. if {$expire == "0"} {
  1074. set show_reason [blacktools:bl:setreason $chan $read_reason $read_handle $expire $getcount "0" $num]
  1075. if {[setting:get $chan showhandle]} {
  1076. set show_reason "\[BT\] \[$gethand\] (GLOBAL) (REGEXP) blacklisted -- ($black(say.$getlang.gl.reason): $read_reason)"
  1077. } else {
  1078. set show_reason "\[BT\] (GLOBAL) (REGEXP) blacklisted -- ($black(say.$getlang.gl.reason): $read_reason)"
  1079. }
  1080. }
  1081. if {[onchan $black(chanserv) $chan] && $xban == "1"} {
  1082. putquick "PRIVMSG $black(chanserv) :ban $chan $mask $getxtime $getxlevel $show_reason"
  1083. } else {
  1084. putquick "MODE $chan +b $mask"
  1085. putquick "KICK $chan $nick :$show_reason"
  1086. }
  1087. break
  1088. }
  1089. }
  1090. if {[regexp {[/]} $real_read_host]} {
  1091. set read_ip [lindex [split $real_read_host @] 1]
  1092. set theip [lindex [split $uhost @] 1]
  1093. set theip_dns [lindex [split $fulldns @] 1]
  1094. set cidr_ip [ipcidr $read_ip $theip]
  1095. set cidr_dns [ipcidr $read_ip $theip_dns]
  1096. if {$cidr_ip == "1" || $cidr_dns == "1"} {
  1097. set read_rest_ip [lindex [split $uhost @] 0]
  1098. set read_theip [lindex [split $real_read_host @] 0]
  1099. if {[string match -nocase $read_rest_ip $read_theip] || [string match -nocase $read_theip $read_rest_ip]} {
  1100. set cidr 1
  1101. }
  1102. }
  1103. }
  1104. if {[string match -nocase $real_read_host $uhost] || [string match -nocase $uhost $real_read_host] || ($cidr == "1")} {
  1105. set check_except [blacktools:ban:exempt $uhost]
  1106. if {$check_except == "1"} {
  1107. break
  1108. }
  1109. set num [lindex [split $b] 1]
  1110. set read_reason [join [lrange [split $b] 9 end]]
  1111. set read_reason [blacktools:rem_comment $read_reason]
  1112. set read_reason [encoding convertfrom utf-8 $read_reason]
  1113. set expire [lindex [split $b] 5]
  1114. set read_handle [lindex [split $b] 4]
  1115. set read_handle [lindex [split $b] 4]
  1116. set gethand [lindex [split $read_handle] 0]
  1117. set show_reason [blacktools:setreason $chan $read_reason $read_handle $expire "" "1" $num]
  1118. if {$expire == "0"} {
  1119. set show_reason [blacktools:bl:setreason $chan $read_reason $read_handle $expire $getcount "0" $num]
  1120. if {[setting:get $chan showhandle]} {
  1121. set show_reason "\[BT\] \[$gethand\] (GLOBAL) blacklisted -- ($black(say.$getlang.gl.reason): $read_reason)"
  1122. } else {
  1123. set show_reason "\[BT\] (GLOBAL) blacklisted -- ($black(say.$getlang.gl.reason): $read_reason)"
  1124. }
  1125. }
  1126. if {[onchan $black(chanserv) $chan] && $xban == "1"} {
  1127. putquick "PRIVMSG $black(chanserv) :ban $chan $read_host $getxtime $getxlevel $show_reason"
  1128. } else {
  1129. putquick "MODE $chan +b $read_host"
  1130. putquick "KICK $chan $nick :$show_reason"
  1131. }
  1132. break
  1133. }
  1134. }
  1135. if {[string equal -nocase $type "GAG"] && [string equal -nocase $read_chan $chan]} {
  1136. set read_host [lindex [split $b] 3]
  1137. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  1138. if {[string match -nocase $real_read_host $uhost]} {
  1139. if {[ischanban $read_host $chan]} {
  1140. continue
  1141. }
  1142. set num [lindex [split $b] 1]
  1143. set expire [lindex [split $b] 5]
  1144. set read_time [return_time $getlang [expr $expire - [unixtime]]]
  1145. set replace(%minute%) $read_time
  1146. set replace(%gag%) $nick
  1147. if {[isop $nick $chan]} {
  1148. pushmode $chan -o $nick
  1149. }
  1150. if {[isvoice $nick $chan]} {
  1151. pushmode $chan -v $nick
  1152. }
  1153. pushmode $chan +b $read_host
  1154. set text [black:color:set "" $black(say.$getlang.gag.1)]
  1155. set reply [join $text]
  1156. puthelp "PRIVMSG $chan :[string map [array get replace] $reply]"
  1157. break
  1158. }
  1159. }
  1160. }
  1161. }
  1162. ###
  1163. proc blacktools:mode:ban {nick host hand chan mod who} {
  1164. global black
  1165. if {$mod == "-b"} {
  1166. foreach b [blacktools:banlist:ban $chan] {
  1167. set read_host [lindex [split $b] 3]
  1168. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  1169. if {[string match -nocase $real_read_host $who]} {
  1170. set sticky [lindex [split $b] 7]
  1171. if {$sticky == "1"} {
  1172. pushmode $chan +b $who
  1173. }
  1174. break
  1175. }
  1176. }
  1177. }
  1178. if {$mod == "+o"} {
  1179. if {[isbotnick $who]} {
  1180. foreach b [blacktools:banlist:ban $chan] {
  1181. set read_host [lindex [split $b] 3]
  1182. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  1183. set sticky [lindex [split $b] 7]
  1184. if {$sticky == "1"} {
  1185. if {![ischanban $read_host $chan]} {
  1186. pushmode $chan +b $read_host
  1187. }
  1188. }
  1189. }
  1190. mode:who:chan $chan
  1191. }
  1192. }
  1193. }
  1194. ###
  1195. proc blacktools:chnick:ban {nick host hand chan newnick} {
  1196. global botnick black
  1197. if {[validchan $chan]} {
  1198. set bhost "$newnick![getchanhost $newnick $chan]"
  1199. blacktools:auto:ban $newnick $bhost $chan ""
  1200. }
  1201. }