Advertisement
Guest User

Untitled

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