Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # $Id: blacklist.tcl,v 0.4 2018/10/18 22:00:00 outsider Exp $ #
- # original: perpleXa #
- # #
- # Commands: #
- # $black add <#<chan>|*=global> <mask> [%<reason> #
- # $black del <mask|#id> #
- # $black list [mask] #
- #################################################################
- set blacklist_file "scripts/dbase/blacklist"
- setudef flag blacklist
- bind pub m \$black blacklist:pub
- bind time - "0* * * * *" blacklist:sentry
- bind join - * blacklist:join
- bind nick - * blacklist:nick
- proc blacklist:pub {nick host hand chan args} {
- global blacklist lastbind ban-time
- set args [blacklist:clean $args]
- set cmd [lindex $args 0]
- switch -- $cmd {
- "add" {
- if {![channel get $chan blacklist]} {
- puthelp "NOTICE $nick :Sorry, blacklisting disabled here."
- return 0
- }
- #check for nick or hostname or id
- set target [lindex $args 1]
- if {[onchan $target]} {
- set banmask [blacklist:validate:host [maskhost [getchanhost $target] 2]]
- } else {
- set banmask [blacklist:validate:host $target]
- }
- set counter 2
- set pchan [lindex $args 2]
- if {[validchan $pchan] || $pchan eq "*"} {
- set uchan [string tolower $pchan]
- incr counter
- } else {
- set uchan [string tolower $chan]
- }
- if {[info exists blacklist($banmask,$uchan)]} {
- puthelp "NOTICE $nick :Sorry, couldn't add that hostmask. (Already present)"
- return 0
- }
- if {[string match %* [lindex $args $counter]]} {
- set expire [unixtime]
- set s [string range [lindex $args $counter] 1 e]
- if {$s ne 0} {
- set days [lindex [regexp "(\[0-9\]+)+d" $s] 1]
- if {$days ne ""} { incr expire $days*1440 }
- set hours [lindex [regexp "(\[0-9\]+)+h" $s] 1]
- if {$hours ne ""} { incr expire $hours*60 }
- set minutes [lindex [regexp "(\[0-9\]+)+m" $s] 1]
- if {$minutes ne ""} { incr expire $minutes }
- } else {
- set expire 0
- }
- incr counter
- } else {
- set expire [expr [unixtime] + ${ban-time}]
- }
- set reason [join [lrange $args $counter e]]
- if {$reason eq ""} { set reason "Requested" }
- set blacklist($banmask,$uchan) "$hand $expire $reason"
- puthelp "NOTICE $nick :Done. $banmask blacklisted successfully (reason: $reason)."
- blacklist:save
- blacklist:sentry
- return 1
- }
- "del" {
- if {![channel get $chan blacklist]} {
- puthelp "NOTICE $nick :Sorry, blacklisting disabled here."
- return 0
- }
- if {[lindex $args 1] eq ""} {
- puthelp [format "NOTICE %s :%s del <nick|hostmask|id> \[<other channel|*=global>\]" $nick $lastbind]
- return 1
- }
- set pchan [lindex $args 2]
- if {[validchan $pchan] || $pchan eq "*"} {
- set uchan [string tolower $pchan]
- } else {
- set uchan [string tolower $chan]
- }
- set target [lindex $args 1]
- if {[onchan $target]} {
- set banmask [blacklist:validate:host [maskhost [getchanhost $target] 2]]
- } elseif {[string is integer $target]} {
- set pos 0
- foreach entry [array names blacklist] {
- incr pos
- if {$pos eq $target} {
- unset -nocomplain blacklist($entry)
- puthelp "NOTICE $nick :Done. Entry removed."
- blacklist:save
- return 1
- }
- }
- puthelp "NOTICE $nick :Failed. Specified id does not exist. Try $lastbind list"
- return 0
- } else {
- set banmask [blacklist:validate:host $target]
- }
- if {[info exists blacklist($banmask,$uchan)]} {
- unset -nocomplain blacklist($banmask,$uchan)
- puthelp "NOTICE $nick :Done. Entry removed."
- blacklist:save
- return 1
- }
- puthelp "NOTICE $nick :Failed. Specified entry does not exist. Try $lastbind list"
- return 0
- }
- "list" {
- if {![channel get $chan blacklist]} {
- puthelp "NOTICE $nick :Sorry, blacklisting disabled here."
- return 0
- }
- set arg1 [lindex $args 1]
- set arg2 [lindex $args 2]
- if {[validchan $arg1]} {
- set uchan [string tolower $arg1]
- }
- if {![info exists uchan] && [validchan $arg2]} {
- set uchan [string tolower $arg2]
- set mask [blacklist:validate:host $arg1]
- } elseif {$arg1 eq "*"} {
- set uchan [string tolower $chan]
- }
- set uchan [string tolower $uchan]
- set ml ""
- set ml_owner 0
- set ml_chan 0
- set ml_expire 0
- set ml_banmask 0
- set pos 0
- foreach entry [array names blacklist] {
- incr pos
- set banmask [string tolower [lindex [split entry ,] 0]]
- set pchan [string tolower [lindex [split entry ,] 0]]
- if {![string match -nocase $uchan $pchan]} { continue }
- if {[info exists mask] && ![string match -nocase $banmask $mask]} { continue }
- set owner [lindex $blacklist($entry) 0]
- if {[lindex $blacklist($entry) 1] eq 0} {
- set expire "Never"
- } else {
- set expire [clock format [lindex $blacklist($entry) 1] -format %D %T]
- }
- set reason [lrange $blacklist($entry) 2 e]
- lappend ml [join "$pos $owner $pchan $banmask $expire $reason"]
- if {[string length $owner] > $ml_owner} { set ml_owner [string length $owner] }
- if {[string length $pchan] > $ml_chan} { set ml_chan [string length $pchan] }
- if {[string length $expire] > $ml_expire} { set ml_expire [string length $expire] }
- if {[string length $banmask] > $ml_banmask} { set ml_owner [string length $banmask] }
- }
- if {[llength $ml] eq 0} {
- puthelp "NOTICE $nick :No matching entries found."
- return 0
- }
- puthelp "NOTICE $nick :Returning a list of [llength $ml] blacklist matches."
- puts [format "%-*s | %-*s | %-*s | %-*s | %-*s | %s" [string length $pos] "Id" $ml_owner "Owner" $ml_chan "Channel" $ml_banmask "Mask" $ml_expire "Expire" "Reason"]
- foreach entry $ml {
- puts [format "%-*s | %-*s | %-*s | %-*s | %-*s | %s" [string length $pos] [lindex $ml 0] $ml_owner [lindex $ml 1] $ml_chan [lindex $ml 2] $ml_banmask [lindex $ml 3] $ml_expire [lindex $ml 4] [lrange $ml 5 e]]
- }
- puthelp "NOTICE $nick :End of blacklist matches."
- return 1
- }
- "on" {
- if {![matchattr $hand +n]} { return 0 }
- channel set $chan +blacklist
- puthelp "NOTICE $nick :Blacklist enabled."
- blacklist:sentry
- return 1
- }
- "off" {
- if {![matchattr $hand +n]} { return 0 }
- channel set $chan +blacklist
- puthelp "NOTICE $nick :Blacklist disabled."
- return 1
- }
- default {
- puthelp "NOTICE $nick :Blacklist commands:"
- puthelp [format "NOTICE %s :%s add <nick|hostmask> \[<other channel|*=global>\] \[%s<XdXhXm|0=permanent>\] <reason>" $nick $lastbind "%"]
- puthelp [format "NOTICE %s :%s del <nick|hostmask|id> \[<other channel|*=global>\]" $nick $lastbind]
- puthelp [format "NOTICE %s :%s list \[<hostmask>\] \[<other channel|*=global>\]" $nick $lastbind]
- if {[matchattr $hand +n]} {
- puthelp [format "NOTICE %s :%s on|off" $nick $lastbind]
- }
- }
- }
- }
- proc blacklist:sentry {{minute "0"} {hour "0"} {day "0"} {week "0"} {year "0"}} {
- global blacklist
- foreach chan [channels] {
- foreach target [chanlist $chan] {
- blacklist:join $target [getchanhost $target] [nick2hand $target] $chan
- }
- }
- blacklist:save
- }
- proc blacklist:nick {nick host hand chan newnick} {
- blacklist:join $newnick $host $hand $chan
- }
- proc blacklist:join {nick host hand chan} {
- global blacklist
- if {![botisop $chan] || ![channel get $chan blacklist]} { return }
- if {[matchattr $hand +n]} { return }
- set userhost [blacklist:weirdclean "$nick!$host"]
- foreach entry [array names blacklist] {
- set expire [lindex $blacklist($entry) 1]
- if {$expire > 0 && $expire < [unixtime]} { continue }
- set blackhost [blacklist:weirdclean [lindex [split $entry ,] 0]]
- set blackchan [blacklist:weirdclean [lindex [split $entry ,] 1]]
- if {$blackchan ne "*" && ![string match -nocase $blackchan $chan]} { continue }
- if {![string match -nocase $blackhost $userhost]} { continue }
- set reason [lrange [blacklist:clean $blacklist($entry)] 2 end]
- putquick "MODE $chan -o+b $nick $blackhost"
- putquick "KICK $chan $nick :[join $reason]"
- }
- }
- proc blacklist:validate:host {i} {
- regsub -all {\*+} $i {*} i
- array set ban {
- ident *
- host *
- }
- set ban(nick) $i
- if {[regexp -- {!} $i]} {
- regexp -- {^(.+?)!(.*?)(@(.*))?$} $i tmp ban(nick) ban(ident) tmp ban(host)
- } elseif {[regexp -- {@} $i]} {
- regexp -- {^(.+!)?(.*?)(@(.*))?$} $i tmp ban(nick) ban(ident) tmp ban(host)
- }
- foreach item [array names ban] {
- if {[string length $ban($item)] < 1} {
- set ban($item) *
- }
- }
- return [string tolower $ban(nick)!$ban(ident)@$ban(host)]
- }
- proc blacklist:load {} {
- global blacklist blacklist_file
- regexp {(\S+/)?} $blacklist_file tmp blacklist_dir
- if {$blacklist_dir != ""} {
- if {![file isdirectory $blacklist_dir]} {
- file mkdir $blacklist_dir
- putlog "Created directory: $blacklist_dir"
- }
- }
- if {![file exists $blacklist_file]} {
- array set blacklist {}
- return
- }
- if {[array exists blacklist]} {
- array unset blacklist
- }
- set file [open $blacklist_file r]
- while {![eof $file]} {
- gets $file line
- if {[regexp -- {(\S+)\s(\S+)\s(\S+)\s(.+)} $line tmp banmask owner expire reason]} {
- if {$expire >= [unixtime] || ($expire == 0)} {
- set blacklist($banmask) "$owner $expire $reason"
- }
- }
- }
- close $file
- }
- proc blacklist:save {} {
- global blacklist blacklist_file
- set file "[open $blacklist_file w]"
- foreach entry [array names blacklist] {
- set expire [lindex $blacklist($entry) 1]
- if {$expire >= [unixtime] || ($expire == 0)} {
- puts $file "$entry $blacklist($entry)"
- }
- }
- close $file
- }
- proc blacklist:weirdclean {i} {
- regsub -all -- \\\\ $i \001 i
- regsub -all -- \\\[ $i \002 i
- regsub -all -- \\\] $i \003 i
- regsub -all -- \\\} $i \004 i
- regsub -all -- \\\{ $i \005 i
- return $i
- }
- proc blacklist:clean {i} {
- regsub -all -- \\\\ $i \\\\\\\\ i
- regsub -all -- \\\[ $i \\\\\[ i
- regsub -all -- \\\] $i \\\\\] i
- regsub -all -- \\\} $i \\\\\} i
- regsub -all -- \\\{ $i \\\\\{ i
- regsub -all -- \\\" $i \\\\\" i
- return $i
- }
- blacklist:load
- putlog "Script loaded: Blacklist :O by perpleXa (modified by OUTsider)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement