Code: Select all
# IP BAN for eggdrop
# raspi 2004
# bans users with non-resolvable IPs
# also checks global and channel banlist if that resolved host is banned
# requires: dns module
# report bugs to raspi@IRCNet/Freenode/Quakenet
# ver 0.6 (23.09.2004)
# see also: .help +exempt
# todo:
# - is some of those foreachses unnecessary?
# - run :init when .+chan is used
set opts(cmd) "ipban";
set opts(char) "!";
bind join -|- * ipban:checkhost
bind pub n|m "$opts(char)$opts(cmd)" ipban:pub
bind dcc -|- $opts(cmd) ipban:dcc
# -- public: --
# !ipban - shows status
# !ipban on - toggles it on
# !ipban off - toggles it off
# -- partyline: --
# .ipban - show list of channels and ipban status
# end of config
set opts(udef) "ipban_enabled"; # don't touch!
setudef str $opts(udef); # used by channel set/get
proc ipban:pub {nick uhost handle channel arg} {
global opts
set run 0
switch $arg {
"on" {
channel set $channel $opts(udef) "1"
set run 1
}
"off" {
channel set $channel $opts(udef) "0"
set run 1
}
default {
if {[channel get $channel $opts(udef)] == "1"} {
set ipbanstatus "on"
} else {
set ipbanstatus "off"
}
puthelp "PRIVMSG $channel :$opts(cmd) ($channel): $ipbanstatus"
if {$run == 1} {
putcmdlog "#$handle# $opts(cmd) $channel $arg"
}
}
}
}
proc ipban:checkhost {nick uhost handle channel} {
global opts
if {[botisop $channel] == 1 && [channel get $channel $opts(udef)] == "1"} {
set hosti [parsehost $uhost]
set regexip4 {^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$}
set regexip6 {^\d{1,4}(:\d{1,4}){7}$}
# does that host match IPv4 or IPv6
if {[regexp -- $regexip4 $hosti] || [regexp -- $regexip6 $hosti]} {
dnslookup $hosti resolve_ip $channel $hosti $nick
}
}
}
proc resolve_ip {ip host status chan hostip nick} {
global opts
if {!$status} {
set resolved "?"
} elseif {[regexp -nocase -- $ip $hostip]} {
set resolved $host
} else {
set resolved $ip
}
set ban_it 0
if {$ip == $host && $resolved == "?"} {
# ip wasn't resolved
set $ban_it 1
} else {
# ip resolved to host
puthelp "PRIVMSG $chan :$nick $ip -> $resolved"
# let's see if there's ban concerning that host in global bans
foreach banni [banlist] {
set b [parsehost [lindex $banni 0]]
if {[string match $b $resolved]} {
set ban_it 1
}
}
foreach banni [banlist $chan] {
set b [parsehost [lindex $banni 0]]
if {[string match $b $resolved]} {
set ban_it 1
}
}
# let's see if there's ban concerning that host in current channel
foreach banni [chanbans $chan] {
set b [parsehost [lindex $banni 0]]
if {[string match $b $resolved]} {
set ban_it 1
}
}
}
if {$ban_it == 1} {
# let's ban!
# last digit to "*"
regsub -all {\d+$} $ip "*" banhost
newchanban $chan "*!*@$banhost" "IP-BAN" " IP"
putkick $chan $nick "banned"
}
}
proc parsehost {uhost} {
set re "^(.+?)@(.*)$"
regexp -- $re $uhost -> identti hosti
return $hosti
}
proc ipban:dcc {handle idx txt} {
global opts
putcmdlog "#$handle# $opts(cmd)"
set output [listipchansstat]
putdcc $idx $output
}
proc listipchansstat {} {
global opts
set output "$opts(cmd): "
foreach channel [channels] {
if {[channel get $channel $opts(udef)] == "1"} {
set s "on"
} else {
set s "off"
}
append output "$channel: $s "
}
return $output
}
proc ipban:init {} {
global opts
# initialize all channels to off
foreach channel [channels] {
if {[channel get $channel $opts(udef)] == ""} {
channel set $channel $opts(udef) "0"
}
}
}
# initialize channels to OFF
ipban:init
putlog "\[x\] IP ban (pub:$opts(char)$opts(cmd) & partyline:.$opts(cmd)) by raspi loaded"
#putlog [listipchansstat]
2) Right now, I wanted to combine this TCL with another function which is to whois and check a user on JOIN on his/her "RealName" and "Identd".
So now the script will BAN the user on-join first when it detect that it was non-resolve IP and if it checked that the REALNAME and IDENTD is 6 letters, it will kick the user out.
Example of the user is:
Anyone able t help?Egghelp is ~pcvmgu@221.168.143.52 * fpcvmg