package require http
namespace eval pchecker {
# isproxyip.com api key
variable pckey "apikey"
# gzline message
variable gmsg "Sorry, VPN are not allowed"
# List of IP not checked
variable whitelist {}
# List of blacklisted IP
variable blacklist {}
variable pcheckerwl "scripts/pcheckerwl.txt"
# To enable on a chan, think to do
# .chanset #chan +scanip
setudef flag scanip
bind join - * ::pchecker::whois
bind raw - 378 ::pchecker::ipcheck
bind pub - !add ::pchecker::ipadd
bind pub - !rem ::pchecker::iprem
proc whois {nick uhost handle chan} {
if {![channel get $chan scanip]} { return }
if {[isbotnick $nick]} { return }
putquick "WHOIS $nick"
}
proc ipadd {nick uhost handle chan text} {
if {[lsearch $::pchecker::whitelist $text] == -1} {
lappend ::pchecker::whitelist $text
}
::pchecker::l2file $::pchecker::whitelist $::pchecker::pcheckerwl
}
proc iprem {nick uhost handle chan text} {
set n [lsearch $::pchecker::whitelist $text]
if {$n != -1} {
set ::pchecker::whitelist [lreplace $::pchecker::whitelist $n $n]
::pchecker::l2file $::pchecker::whitelist $::pchecker::pcheckerwl
}
}
proc ipcheck {frm key text} {
set ip [lindex [split $text " "] end]
foreach w $::pchecker::whitelist {
if {[string match $w $text]} { return }
}
foreach b $::pchecker::blacklist {
if {[string match $w $text]} {
putquick "GLINE *@$ip +316d :$::pchecker::gmsg"
return
}
}
::pchecker::isvpn $ip
}
proc json2dict {JSONtext} {
string range [string trim [string trimleft [string map {\t {} \n {} \r {} , { } : { } \[ \{ \] \}} $JSONtext] {\uFEFF}]] 1 end-1
}
proc isvpn {ip} {
::http::config -useragent "lynx"
set pcheck [::http::geturl http://api.isproxyip.com/v1/check.php?key=$::pchecker::pckey&ip=${ip}&format=json]
set data [json2dict [::http::data $pcheck]]
if {[dict get $data status] eq "success"} {
set proxy [dict get $data proxy]
if {$proxy == 1 } {
lappend $::pchecker::blacklist $ip
putquick "GLINE *@$ip +316d :$::pchecker::gmsg"
}
}
::http::cleanup $pcheck
}
proc l2file {olist dfile} {
set fo [open $dfile w]
puts $fo [join $olist "\n"]
close $fo
}
proc f2list {dfile} {
set fi [open $dfile r]
set olist [split [read -nonewline $fi] "\n"]
close $fi
return $olist
}
set ::pchecker::whitelist [::pchecker::f2list $::pchecker::pcheckerwl]
}
It throws a Tcl error [::pchecker::ipcheck]: Illegal characters in URL path
CrazyCat said it's a regexp error for InspIRCD as I use it.
I set the .set errorInfo but I don't see much info.
But I figured out the regexp for InspIRCD and would be
proc ipcheck {frm key text} {
if {[string match *!*@* $frm] || ![string match -nocase "*client connecting*" $text]} { return }
if {![regexp -nocase { CONNECT: Client connecting on port (\d+) \(class (\S+)\): ([^!]+)!([^@]+)@(\S+) \(([0-9a-f.:]+)\) \[(.*)\]} $text -> port class nick ident host ip realname]} {
return 0; not a connect notice
}
How do I keep this regexp in the tcl script at the top to fix it?
And I think you don't really know how to use .set errorInfo (you must type that in PL just after the error occures to have detailed informations).
And using putlog to show what you get / set in another good way to debug script.
And I think you don't really know how to use .set errorInfo (you must type that in PL just after the error occures to have detailed informations).
And using putlog to show what you get / set in another good way to debug script.
CrazyCat, I did put the .set errorInfo in partyline but it didn't get so much info for the debug and yes, I don't have much idea about putlog.
I am still getting the error as I put the bind you gave me too, getting: Tcl error [::pchecker::ipcheck]: Illegal characters in URL path
However, the one script you helped me build works on InspIRCD, if you could please change the proxy scanner link from the site ip-api.com to isproxyip.com here with the API key.
No I won't.
There are several examples on the forum, I'm trying to help (an teach) here, I won't do scripts for persons who don't even try to script by themselve.
CrazyCat wrote:No I won't.
There are several examples on the forum, I'm trying to help (an teach) here, I won't do scripts for persons who don't even try to script by themselve.
Hello CrazyCat, okay here is what I tried, It used to work for InspIRCD but it does not seem to use the API and scan the IP now. I don't see any errors and it does not work anymore. I don't know what the bug is.