BT.Ban.tcl 44 KB

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