Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. # $Id: blacklist.tcl,v 0.3 2004/07/26 20:06:03 perpleXa Exp $ #
  2. # #
  3. # Commands: #
  4. # $blackadd <mask> <reason> #
  5. # $blackdel <mask|#id> #
  6. # $blacklist #
  7. #################################################################
  8.  
  9.  
  10. set blacklist_file "scripts/dbase/blacklist"
  11.  
  12.  
  13. bind PUB m !listbl blacklist:list
  14. bind PUB m !bl blacklist:add
  15. bind PUB m !unbl blacklist:del
  16. bind TIME -|- "0* * * * *" blacklist:sentry
  17. bind JOIN -|- * blacklist:join
  18.  
  19.  
  20. proc blacklist:list {nickname hostname handle channel arguments} {
  21. global blacklist
  22. set entrys 0
  23. puthelp "NOTICE $nickname :Blacklist entrys"
  24. puthelp "NOTICE $nickname :cuite62 Hostmask"
  25. foreach entry [array names blacklist] {
  26. incr entrys
  27. set owner [lindex $blacklist($entry) 0]
  28. while {[string length $owner] < 15} {
  29. set owner "$cuite62 "
  30. }
  31. if {[string length $entrys] < 2} {
  32. set target "$entrys "
  33. } else {
  34. set target $entrys
  35. }
  36. puthelp "NOTICE $nickname :#$target $owner $entry"
  37. }
  38. puthelp "NOTICE $nickname :fin de la liste."
  39. }
  40.  
  41.  
  42. proc blacklist:add {nickname hostname handle channel arguments} {
  43. global blacklist
  44. set arguments [blacklist:clean $arguments]
  45. set banmask [blacklist:validate:host [lindex $arguments 0]]
  46. if {([regexp -all -- {!} $banmask] > 1) || ([regexp -all -- {@} $banmask] > 1)} {
  47. puthelp "NOTICE $nickname :Sorry, couldn't add that hostmask."
  48. return
  49. }
  50. set owner $handle
  51. if {[regexp {^(\d{1,2}|[0-3][0-6][0-5])$} [lindex $arguments 1]]} {
  52. set expire [expr ([lindex $arguments 1] * 86400) + [unixtime]]
  53. set reason [join [lrange $arguments 2 end]]
  54. } else {
  55. set expire 0
  56. set reason [join [lrange $arguments 1 end]]
  57. }
  58. if {[llength $reason] >= 1} {
  59. if {![info exists blacklist($banmask)]} {
  60. set blacklist($banmask) "$owner $expire $reason"
  61. puthelp "NOTICE $nickname :Done. $banmask blacklisted successfully (reason: $reason)."
  62. blacklist:sentry
  63. } else {
  64. puthelp "NOTICE $nickname :Sorry, couldn't add that hostmask."
  65. }
  66. } else {
  67. puthelp "NOTICE $nickname :You forgot to type a blacklist reason."
  68. }
  69. }
  70.  
  71.  
  72. proc blacklist:del {nickname hostname handle channel arguments} {
  73. global blacklist
  74. set arguments [blacklist:clean $arguments]
  75. set banmask [lindex $arguments 0]
  76. set success 0
  77. if {[regexp {^#([0-9]+)$} $banmask tmp number]} {
  78. set item 0
  79. foreach entry [array names blacklist] {
  80. incr item
  81. if {$item == $number} {
  82. unset blacklist($entry)
  83. set success 1
  84. }
  85. }
  86. } else {
  87. if {[info exists blacklist($banmask)]} {
  88. unset blacklist($banmask)
  89. set success 1
  90. }
  91. }
  92. if {$success == 0} {
  93. puthelp "NOTICE $nickname :Couldn't delete the requested ban. Use \$blacklist to view them."
  94. } else {
  95. puthelp "NOTICE $nickname :Done."
  96. }
  97. }
  98.  
  99.  
  100. proc blacklist:sentry {{minute "0"} {hour "0"} {day "0"} {week "0"} {year "0"}} {
  101. global blacklist
  102. foreach channel [channels] {
  103. if {![botisop $channel]} {continue}
  104. foreach target [chanlist $channel] {
  105. set userhost [blacklist:weirdclean "$target![getchanhost $target]"]
  106. foreach entry [array names blacklist] {
  107. set expire [lindex $blacklist($entry) 1]
  108. if {$expire >= [unixtime] || ($expire == 0)} {
  109. set reason [lrange [blacklist:clean $blacklist($entry)] 2 end]
  110. set blackhost [blacklist:weirdclean $entry]
  111. if {[string match -nocase $blackhost $userhost]} {
  112. putquick "MODE $channel -o+b $target $entry"
  113. putquick "KICK $channel $target :[join $reason]"
  114. }
  115. } else {
  116. unset blacklist($entry)
  117. }
  118. }
  119. }
  120. }
  121. blacklist:save
  122. }
  123.  
  124.  
  125. proc blacklist:join {nickname hostname handle channel} {
  126. global blacklist
  127. if {![botisop $channel]} {return}
  128. set userhost [blacklist:weirdclean "$nickname![getchanhost $nickname]"]
  129. foreach entry [array names blacklist] {
  130. set reason [lrange [blacklist:clean $blacklist($entry)] 2 end]
  131. set blackhost [blacklist:weirdclean $entry]
  132. if {[string match -nocase $blackhost $userhost]} {
  133. putquick "MODE $channel -o+b $nickname $entry"
  134. putquick "KICK $channel $nickname :[join $reason]"
  135. }
  136. }
  137. }
  138.  
  139.  
  140. proc blacklist:validate:host {i} {
  141. regsub -all {\*+} $i {*} i
  142. array set ban {
  143. ident *
  144. host *
  145. }
  146. set ban(nick) $i
  147. if {[regexp -- {!} $i]} {
  148. regexp -- {^(.+?)!(.*?)(@(.*))?$} $i tmp ban(nick) ban(ident) tmp ban(host)
  149. } elseif {[regexp -- {@} $i]} {
  150. regexp -- {^(.+!)?(.*?)(@(.*))?$} $i tmp ban(nick) ban(ident) tmp ban(host)
  151. }
  152. foreach item [array names ban] {
  153. if {[string length $ban($item)] < 1} {
  154. set ban($item) *
  155. }
  156. }
  157. return $ban(nick)!$ban(ident)@$ban(host)
  158. }
  159.  
  160.  
  161. proc blacklist:load {} {
  162. global blacklist blacklist_file
  163. regexp {(\S+/)?} $blacklist_file tmp blacklist_dir
  164. if {$blacklist_dir != ""} {
  165. if {![file isdirectory $blacklist_dir]} {
  166. file mkdir $blacklist_dir
  167. putlog "Created directory: $blacklist_dir"
  168. }
  169. }
  170. if {![file exists $blacklist_file]} {
  171. array set blacklist {}
  172. return
  173. }
  174. if {[array exists blacklist]} {
  175. array unset blacklist
  176. }
  177. set file [open $blacklist_file r]
  178. while {![eof $file]} {
  179. gets $file line
  180. if {[regexp -- {(\S+)\s(\S+)\s(\S+)\s(.+)} $line tmp banmask owner expire reason]} {
  181. if {$expire >= [unixtime] || ($expire == 0)} {
  182. set blacklist($banmask) "$owner $expire $reason"
  183. }
  184. }
  185. }
  186. close $file
  187. }
  188.  
  189.  
  190. proc blacklist:save {} {
  191. global blacklist blacklist_file
  192. set file "[open $blacklist_file w]"
  193. foreach entry [array names blacklist] {
  194. puts $file "$entry $blacklist($entry)"
  195. }
  196. close $file
  197. }
  198.  
  199.  
  200. proc blacklist:weirdclean {i} {
  201. regsub -all -- \\\\ $i \001 i
  202. regsub -all -- \\\[ $i \002 i
  203. regsub -all -- \\\] $i \003 i
  204. regsub -all -- \\\} $i \004 i
  205. regsub -all -- \\\{ $i \005 i
  206. return $i
  207. }
  208.  
  209.  
  210. proc blacklist:clean {i} {
  211. regsub -all -- \\\\ $i \\\\\\\\ i
  212. regsub -all -- \\\[ $i \\\\\[ i
  213. regsub -all -- \\\] $i \\\\\] i
  214. regsub -all -- \\\} $i \\\\\} i
  215. regsub -all -- \\\{ $i \\\\\{ i
  216. regsub -all -- \\\" $i \\\\\" i
  217. return $i
  218. }
  219.  
  220.  
  221. blacklist:load
  222.  
  223. putlog "Script loaded: Blacklist :O by perpleXa"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement