################################################################################
#  
#  TCL scripts by Ofloo all rights reserved.
# 
#  HomePage: http://ofloo.net/
#  CVS: http://cvs.ofloo.net/
#  Email: support[at]ofloo.net
#  
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#   
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#   
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#  
#  ChangeLog:
#   - 11/02/2005: Fix close fd
################################################################################

namespace eval proxyban {
  
  ###################################
  # Main settings change to your
  # preference.
  ###################################

  variable banport "1080,1081,3380,3381" ;# Most commen port list
  variable bantime "0" ;# Permanent ban.
  variable bantext "Proxys are not allowed." ;# Ban msg when bot kicks user
#  variable warnmsg "Scanning for proxys plz ignore the warning on your firewall." ;# notify the user.
  
  ###################################
  # Do not edit below
  ###################################

  variable version "1.1"

  ###################################
  # Join bind
  ###################################

  proc scan_join {nick host hand chan} {
    variable banport
#    putserv "NOTICE $nick :$warnmsg"
    set hostname [lindex [split $host \x40] end]
    foreach {x} [split $banport \x2c] {
      if {![catch {socket -async $hostname $x} s]} {
        fileevent $s writable [list [namespace current]::check_sock $s $host $chan]
      }
    }
  }

  ###################################
  # fileevent callback
  ###################################

  proc check_sock {s host chan} {
    variable bantime; variable bantext
    if {[string equal {} [fconfigure $s -error]]} {
      newchanban $chan [maskhost $host] $::botnick $bantext $bantime
    }
    close $s
  }

  bind join - * [namespace current]::scan_join
  
################################################################################
  putlog "\002ProxyCheck.tcl\002 version \002$version\002 by \002SmasHinG\002 is loaded."

}
