Advertisement
Guest User

Untitled

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