Blacklist - Block access to channels

Gives admins the ability to add, delete, list blacklists on channels. Includes support for expiry and reasons.

Requirements

Software Version Details
sBNC (w/TCL module) 1.2 Developed and tested on 1.2-846.

Download

Install

  • Download
  • Unzip
  • Place blacklist.tcl in scripts/
    • Check if you are satisfied with the default configuration settings.
  • Add source scripts/blacklist.tcl to sbnc.tcl
  • Rehash TCL
  • Use

Usage

/sbnc blacklist add <*channel*> [duration in days, 0 for infinite] [reason]
/sbnc blacklist del <*channel*>
/sbnc blacklist list [*filter*]

Configuration

Variable Description Values
::blacklist_announce_add Announce adding of channels to blacklist. 0 = disabled (default)
1 = notify all admins
::blacklist_announce_del Announce deleting of channels from blacklist. 0 = disabled
1 = notify all admins
2 = only notify the admin who added the channel (default)
::blacklist_announce_expire Announce expiring channels in blacklist. 0 = disabled
1 = notify all admins
2 = only notify the admin who added the channel (default)
::blacklist_reason Blacklist reason if none specified. A string (default: “Blacklisted”)

Source

Note that this source will/should be the development version, i.e. all changes noted in the history section, will have been made in this section.

blacklist.tcl

#
# @name       Blacklist - Block access to channels
# @version    Build 3 (2007-05-19)
# @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
# @author     David Lorentsen <zyberdog@quakenet.org>
# @www        http://wiki.zyberdog.dk/sbnc/blacklist
#
 
 
# Announce adding of channels to blacklist.
# 0 = disabled (default)
# 1 = notify all admins
set ::blacklist_announce_add 0
 
# Announce deleting of channels from blacklist.
# 0 = disabled
# 1 = notify all admins
# 2 = only notify the admin who added the channel (default)
set ::blacklist_announce_del 2
 
# Announce expiring channels in blacklist.
# 0 = disabled
# 1 = notify all admins
# 2 = only notify the admin who added the channel (default)
set ::blacklist_announce_expire 2
 
# Blacklist reason if none specified.
set ::blacklist_reason "Blacklisted"
 
 
# Should not need to edit anything below this line.
 
internalbind command blacklist:commands
 
proc blacklist:commands {client parameters} {
	if {[string equal -nocase [lindex $parameters 0] "help"] && [getbncuser $client "admin"]} {
		bncaddcommand blacklist Admin "Manage channel blacklist" "Syntax: blacklist <add|del|list>\n        blacklist add <*channel*> \[duration in days, 0 for infinite\] \[reason\]\n        blacklist del <*channel*>\n        blacklist list \[*filter*\]"
	}
	if {[string equal -nocase [lindex $parameters 0] "blacklist"] && [getbncuser $client "admin"]} {
		haltoutput
		if {[llength $parameters] < 1} {
			bncreply "Syntax: blacklist <add|del|list|announce>"
		} else {
			switch [lindex $parameters 1] {
				"add" {
					blacklist:add [lindex $parameters 2] [lindex $parameters 3] [join [lrange $parameters 4 end]]
				}
				"rem" -
				"del" {
					blacklist:del [lindex $parameters 2]
				}
				"list" {
					blacklist:list [lindex $parameters 2]
				}
				default {
					bncreply "Syntax: blacklist <add|del|list>"
				}
			}
		}
	}	
}
 
proc blacklist:add {channel duration reason} {
	global ::blacklist_announce_add ::blacklist_reason
	if {[string equal $channel ""]} {
		bncreply "Error: requires a channel argument."
		bncreply "Example: blacklist add #foo*bar"
	} else {
		set blacklist [bncgetglobaltag blacklist]
		foreach item $blacklist {
			if {[string equal -nocase [lindex $item 0] $channel]} {
				bncreply "Error: '$channel' already in blacklist."
				return
			}
		}
		if {$duration == 0 || $duration == ""} {
			set expires 0
		} else {
			set expires [expr [clock seconds] + (86400 * $duration)]
		}
		if {$reason == ""} { 
			set reason $::blacklist_reason
		}
		lappend blacklist [list $channel $expires $reason [getctx]]
		bncsetglobaltag blacklist $blacklist
		bncreply "Done."
		if {[string equal $::blacklist_announce_add "1"]} {
			if {$expires == 0} {
				set dexpire "Never"
			} else {
				set dexpire [clock format $expires -format "%Y-%m-%d %T"]
			}
			putmainlog "Blacklist: \"[getctx]\" added \"$channel\" to expire \"$dexpire\" with reason: $reason"
		}
	}
}
 
proc blacklist:del {channel} {
	global ::blacklist_announce_del
	if {[string equal $channel ""]} {
		bncreply "Error: requires a channel argument."
		bncreply "Example: blacklist del #foo*bar"
	} else {
		set blacklist [bncgetglobaltag blacklist]
		set newlist [list]
		set found 0
		foreach item $blacklist {
			if {![string equal -nocase [lindex $item 0] $channel]} {
				lappend newlist $item
			} else {
				set found 1
				set reason [lindex $item 2]
				set orgctx [lindex $item 3]
			}
		}
		if {[string equal $found 1]} {
			bncsetglobaltag blacklist $newlist
			bncreply "Done."
			if {[string equal $::blacklist_announce_del "1"]} {
				putmainlog "Blacklist: \"[getctx]\" deleted \"$channel\" originally placed by \"$orgctx\" with reason: $reason"
			} elseif {[string equal $::blacklist_announce_del "2"] && ![string equal $orgctx [getctx]]} {
				set curctx [getctx]
				setctx $orgctx
				putlog "Blacklist: \"$curctx\" deleted \"$channel\" originally placed by you with reason: $reason"
				setctx $curctx
			}
		} else {
			bncreply "Error. Could not find \"$channel\" in the blacklist."
		}
	}
}
 
proc blacklist:list {filter} {
	set sblacklist [bncgetglobaltag blacklist]
	if {[llength $sblacklist] == 0 || [string equal $sblacklist ""]} {
		bncreply "No channels in the blacklist."
	} else {
		bncreply "Channel              Expires              Placed by     Reason"
		bncreply "-------------------------------------------------------------------------"
		if {[string equal $filter ""]} {
			foreach item $sblacklist {
				if {[lindex $item 1] == 0} {
					set expires "Never"
				} else { 
					if {[clock seconds] > [lindex $item 1]} {
						set expires "EXPIRES NEXT CLEANUP"
					} else {
						set expires [clock format [lindex $item 1] -format "%Y-%m-%d %T"]
					}
				}
				bncreply [format "%-20s %-20s %-13s %s" [lindex $item 0] $expires [lindex $item 3] [lindex $item 2]]
			}
		} else {
			foreach item $sblacklist {
				if {[string match -nocase $filter [lindex $item 0]]} {
					if {[lindex $item 1] == 0} {
						set expires "Never"
					} else {
						if {[clock seconds] > [lindex $item 1]} {
							set expires "EXPIRES NEXT CLEANUP"
						} else {
							set expires [clock format [lindex $item 1] -format "%Y-%m-%d %T"]
						}
					}
					bncreply [format "%-20s %-20s %-13s %s" [lindex $item 0] $expires [lindex $item 3] [lindex $item 2]]
				}
			}
		}
		bncreply "------------------------------ End of list ------------------------------"
	}
}
 
 
internalbind client blacklist:block
 
proc blacklist:block {client params} {
	global botnick
 
	set blacklist [bncgetglobaltag blacklist]
 
	# ignore server prefixes
	if {[string index [lindex $params 0] 0] == ":"} {
		set idx 1
	} else {
		set idx 0
	}
 
	set command [lindex $params $idx]
 
	if {![string equal -nocase $command "JOIN"]} {
		return
	}
 
	if {![getbncuser $client hasserver]} {
		return
	}
 
	set channels [split [lindex $params [expr $idx + 1]] ","]
 
	set blocked 0
	set result_channels [list]
 
	set i 0
	foreach channel $channels {
		set this_blocked 0
 
		foreach item $blacklist {
			if {[string match -nocase [lindex $item 0] $channel]} {
				set this_blocked 1
				set blocked 1
				# Changing the message sent if a user attempts to join a 
				# blacklisted channel can have severe consequences.
				# It *MUST* clearly state that it is due to the BOUNCER he/she 
				# is denied access, and NOT because of the IRC SERVER.
				putclient ":[getbncuser $client realserver] 480 $botnick $channel :Access to this channel has been restricted by your bouncer administrator. Reason: [lindex $item 2]"
				set result_channels [lreplace $result_channels $i $i]
			}
		}
 
		if {!$this_blocked} {
			lappend result_channels $channel
		}
 
		incr i
	}
 
	if {$blocked} {
		haltoutput
 
		if {[llength $result_channels] > 0} {
			putserv "JOIN [join $result_channels ","]"
		}
	}
}
 
 
internaltimer 3600 1 blacklist:expire
 
proc blacklist:expire {} {
	global ::blacklist_announce_expire
	set blacklist [bncgetglobaltag blacklist]
	set newlist [list]
	foreach item $blacklist {
		if {[lindex $item 1] == 0 || [clock seconds] < [lindex $item 1]} {
			lappend newlist $item
		} elseif {[string equal $::blacklist_announce_expire "1"]} {
			putmainlog "Blacklist: Expired block for \"[lindex $item 0]\". Placed by \"[lindex $item 3]\" with reason: [lindex $item 2]"
		} elseif {[string equal $::blacklist_announce_expire "2"]} {
			setctx [lindex $item 3]
			putlog "Blacklist: Expired block for \"[lindex $item 0]\". Placed by you with reason: [lindex $item 2]"
		}
	}
	bncsetglobaltag blacklist $newlist
}

History

Build 3 (2007-05-19)

  • Fixed blacklist reason handling when adding new channels.

Build 2 (2007-03-04)

  • Do not block admins from joining channels in the blacklist.

Build 1 (2006-11-25)

  • Initial release.
sbnc/blacklist.txt · Last modified: 2007/05/19 18:50 by zyberdog