BT.SecureMode.tcl 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ########################### SECUREMODE TCL ##########################
  6. #########################################################################
  7. ## ##
  8. ## BlackTools : http://blacktools.tclscripts.net ##
  9. ## Bugs report : http://www.tclscripts.net/ ##
  10. ## Online Help : irc://irc.undernet.org/tcl-help ##
  11. ## #TCL-HELP / UnderNet ##
  12. ## You can ask in english or romanian ##
  13. ## ##
  14. #########################################################################
  15. proc securemode:findexcept {chan host} {
  16. global black
  17. set found_it 0
  18. set file [open $black(add_file) "r"]
  19. set w [read -nonewline $file]
  20. close $file
  21. set data [split $w "\n"]
  22. foreach line $data {
  23. set read_chan [lindex [split $line] 0]
  24. set enc_chan [encoding convertfrom utf-8 $read_chan]
  25. if {[string equal -nocase $enc_chan $chan]} {
  26. set read_type [lindex [split $line] 1]
  27. if {[string equal -nocase $read_type "SECUREMODE-EXCEPT"]} {
  28. set read_host [lindex [split $line] 3]
  29. set real_read_host [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $read_host]
  30. if {[string match -nocase $host $real_read_host] || [string match -nocase $real_read_host $host]} {
  31. set found_it 1
  32. }
  33. }
  34. }
  35. }
  36. return $found_it
  37. }
  38. proc securemode:module {nick host hand chan arg} {
  39. global black lastbind
  40. set type 0
  41. set chan1 "$chan"
  42. set why [lindex [split $arg] 0]
  43. set except [join [lrange [split $arg] 1 end]]
  44. set number [lindex [split $arg] 1]
  45. if {[regexp {^[&#]} $why] && [matchattr $hand nmo|M $why]} {
  46. set chan "$why"
  47. set why [lindex [split $arg] 1]
  48. set except [join [lrange [split $arg] 2 end]]
  49. set number [lindex [split $arg] 2]
  50. }
  51. set return [blacktools:mychar $lastbind $hand]
  52. if {$return == "0"} {
  53. return
  54. }
  55. prot:module:process $nick $host $hand $chan $chan1 $why $except $type $number "securemode"
  56. }
  57. proc securemode:kickremove {nick host hand chan kicked reason} {
  58. global black
  59. set host [getchanhost $kicked $chan]
  60. if {[setting:get $chan securemode]} {
  61. set chanmode [getchanmode $chan]
  62. if {[string match -nocase "*D*" $chanmode] && [string match -nocase "*m*" $chanmode]} {
  63. if {[info exists black(secure:$chan:allowlist)]} {
  64. if {[lsearch -exact [string tolower $black(secure:$chan:allowlist)] [string tolower $host]] > -1} {
  65. set position [lsearch -exact [string tolower $black(secure:$chan:allowlist)] [string tolower $host]]
  66. set black(secure:$chan:allowlist) [lreplace $black(secure:$chan:allowlist) $position $position]
  67. }
  68. if {[info exists black(secure:$chan:list)]} {
  69. if {[lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $kicked]] > -1} {
  70. set position [lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $kicked]]
  71. set black(secure:$chan:list) [lreplace $black(secure:$chan:list) $position $position]
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }
  78. proc secured:allowlist:reset {minute hour day month year} {
  79. global black
  80. foreach chan [channels] {
  81. if {[validchan $chan]} {
  82. if {[info exists black(secure:$chan:allowlist)]} {
  83. unset black(secure:$chan:allowlist)
  84. }
  85. }
  86. }
  87. }
  88. proc securemode:timer {} {
  89. global black botnick
  90. set channels ""
  91. set secure_act 0
  92. foreach chan [channels] {
  93. if {[setting:get $chan securemode]} {
  94. lappend channels $chan
  95. if {[onchan $botnick $chan]} {
  96. set chanmode [getchanmode $chan]
  97. if {[string match -nocase "*D*" $chanmode] && [string match -nocase "*m*" $chanmode]} {
  98. set secure_act 1
  99. }
  100. }
  101. }
  102. }
  103. if {$channels == ""} {
  104. return
  105. }
  106. if {$secure_act == "1"} {
  107. securemode:act $channels 0
  108. }
  109. utimer 30 [list securemode:timer]
  110. }
  111. proc securemode:reply {nick host hand chan mod who} {
  112. global black
  113. if {[setting:get $chan securemode]} {
  114. set getlang [string tolower [setting:get $chan lang]]
  115. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  116. if {[string match "*+D*" $mod]} {
  117. set replace(%chan%) $chan
  118. putserv "PRIVMSG $chan :[string map [array get replace] $black(say.$getlang.securemode.10)]"
  119. }
  120. if {[string match "*-D*" $mod]} {
  121. set replace(%chan%) $chan
  122. putserv "PRIVMSG $chan :[string map [array get replace] $black(say.$getlang.securemode.11)]"
  123. }
  124. }
  125. }
  126. proc securemode:act {channels counter} {
  127. global black
  128. if {$channels == ""} {
  129. return
  130. }
  131. set chan [lindex $channels $counter]
  132. set cc [expr $counter + 1]
  133. if {$chan != ""} {
  134. securemode:raw $chan
  135. } else {
  136. return
  137. }
  138. utimer 5 [list securemode:act $channels $cc]
  139. }
  140. proc securemode:raw {chan} {
  141. global black
  142. putquick "NAMES -d $chan"
  143. set ::securechan $chan
  144. bind RAW - 355 get:nameslist
  145. bind RAW - 366 end:nameslist
  146. }
  147. proc get:nameslist {from keyword arguments} {
  148. global black
  149. set found_it 0
  150. set chan $::securechan
  151. set split_arg [split $arguments ":"]
  152. set names [lindex $split_arg 1]
  153. if {[info exists black(secure:$chan:list)]} {
  154. foreach entry $black(secure:$chan:list) {
  155. if {[lsearch -exact [string tolower [split $names]] [string tolower $entry]] < 0} {
  156. set position [lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $entry]]
  157. set black(secure:$chan:list) [lreplace $black(secure:$chan:list) $position $position]
  158. if {[info exists black(securecode:$entry:$chan)]} {
  159. unset black(securecode:$entry:$chan)
  160. }
  161. }
  162. }
  163. }
  164. if {[info exists black(secure:$chan:list)]} {
  165. if {[llength $black(secure:$chan:list)] == "0"} {
  166. unset black(secure:$chan:list)
  167. }
  168. }
  169. secure:gethost $names $chan 0
  170. }
  171. proc end:nameslist {from keyword arguments} {
  172. global black
  173. check:if:bind "get:nameslist" "355"
  174. check:if:bind "end:nameslist" "366"
  175. }
  176. proc secure:gethost {names chan counter} {
  177. global black
  178. set name [lindex [split $names] $counter]
  179. set cc [expr $counter + 1]
  180. if {$name != ""} {
  181. securemode:gethost:raw $name $chan
  182. } else {
  183. return
  184. }
  185. utimer 3 [list secure:gethost $names $chan $cc]
  186. }
  187. proc securemode:gethost:raw {name chan} {
  188. global black
  189. putserv "USERHOST :$name"
  190. set ::shchan $chan
  191. set ::shnick $name
  192. bind RAW - 302 get:securemode:host
  193. }
  194. proc get:securemode:host {from keyword arguments} {
  195. global black botnick
  196. set is_allowed 0
  197. set has_access 0
  198. set securemode_activ 0
  199. set hosts [lindex [split $arguments] 1]
  200. set hostname [lindex [split $hosts "="] 1]
  201. regsub {^[-+]} $hostname "" mask
  202. set nick $::shnick
  203. set except_mask "$nick!$mask"
  204. set chan $::shchan
  205. if {[setting:get $chan securemode]} {
  206. set chanmode [getchanmode $chan]
  207. if {[string match -nocase "*D*" $chanmode] && [string match -nocase "*m*" $chanmode]} {
  208. set securemode_activ 1
  209. }
  210. }
  211. if {$securemode_activ == "0"} {
  212. return
  213. }
  214. set replace(%botnick%) $botnick
  215. set replace(%chan%) $chan
  216. set lang [setting:get $chan lang]
  217. if {$lang == ""} { set lang [string tolower $black(default_lang)] }
  218. set getaccess [finduser $except_mask]
  219. if {[matchattr $getaccess $black(exceptflags) $chan]} {
  220. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  221. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  222. } else {
  223. putserv "MODE $chan +v $nick"
  224. }
  225. return
  226. }
  227. if {[securemode:findexcept $chan $except_mask] == "1"} {
  228. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  229. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  230. } else {
  231. putserv "MODE $chan +v $nick"
  232. }
  233. return
  234. }
  235. if {[info exists black(secure:$chan:allowlist)]} {
  236. if {[setting:get $chan strictsecured] == "" || [setting:get $chan strictsecured] == "0"} {
  237. if {[lsearch -exact [string tolower $black(secure:$chan:allowlist)] [string tolower $mask]] > -1} {
  238. set is_allowed 1
  239. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  240. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  241. } else {
  242. putserv "MODE $chan +v $nick"
  243. }
  244. }
  245. if {$is_allowed == "1"} {
  246. return
  247. }
  248. }
  249. }
  250. if {[info exists black(secure:$chan:list)]} {
  251. if {[lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $nick]] < 0} {
  252. set black(securecode:$nick:$chan) [string toupper [bot:setcode]]
  253. set replace(%msg.1%) $black(securecode:$nick:$chan)
  254. set message [string map [array get replace] $black(say.$lang.securemode.1)]
  255. putserv "PRIVMSG $nick :$message"
  256. lappend black(secure:$chan:list) $nick
  257. }
  258. } else {
  259. set black(securecode:$nick:$chan) [string toupper [bot:setcode]]
  260. set replace(%msg.1%) $black(securecode:$nick:$chan)
  261. set message [string map [array get replace] $black(say.$lang.securemode.1)]
  262. putserv "PRIVMSG $nick :$message"
  263. lappend black(secure:$chan:list) $nick
  264. }
  265. check:if:bind "get:securemode:host" "302"
  266. }
  267. ##############
  268. #########################################################################
  269. ## END ##
  270. #########################################################################