BT.noproxy.tcl 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ########################### NoProxy TCL #############################
  6. #########################################################################
  7. ## ##
  8. ## BlackTools : http://blacktools.tclscripts.net ##
  9. ## Bugs report : http://www.tclscripts.net/ ##
  10. ## GitHub page : https://github.com/tclscripts/BlackToolS-TCL ##
  11. ## Online Help : irc://irc.undernet.org/tcl-help ##
  12. ## #TCL-HELP / UnderNet ##
  13. ## You can ask in english or romanian ##
  14. ## ##
  15. #########################################################################
  16. ###
  17. proc noproxy:protect {nick host hand chan} {
  18. global black
  19. if {![validchan $chan]} { return }
  20. if {[setting:get $chan noproxy]} {
  21. if {[matchattr $hand $black(exceptflags) $chan]} { return }
  22. set bl_protect [blacktools:protect $nick $chan]
  23. if {$bl_protect == "1"} { return }
  24. if {![botisop $chan] && ![setting:get $chan xonly]} { return }
  25. set uhost [lindex [split $host @] 1]
  26. set is_except 0
  27. foreach ex $black(noproxy:excepts) {
  28. if {[string match -nocase $ex $uhost]} {
  29. set is_except 1
  30. }
  31. }
  32. if {$is_except == 1} {return}
  33. set check_proxy [blacktools:noproxy_data $uhost]
  34. if {$check_proxy == 0} {return}
  35. set isp [lindex $check_proxy 0]
  36. set proxy_status [lindex $check_proxy 1]
  37. if {$proxy_status == "false"} {return}
  38. blacktools:banner:2 $nick "noproxy" $chan $chan $host "0" [list $isp]
  39. if {[link:status $chan] == "1"} {
  40. foreach c [link:chan:get $chan] {
  41. blacktools:banner:2 $nick "noproxy" $c $c $host "1" [list $isp]
  42. }
  43. blacktools:link_ban2 [link:get] 0
  44. } else { who:chan $chan }
  45. }
  46. }
  47. ###
  48. proc blacktools:noproxy_data {host} {
  49. global black
  50. if {![info exists black(http_ok)]} {
  51. if {[catch {package require http} no_http] != 0} {
  52. source $black(backdir)/BlackTools/Addons/http.tcl
  53. package require http
  54. set black(http_ok) 1
  55. } else {
  56. set black(http_ok) 1
  57. }
  58. }
  59. set link "http://ip-api.com/json/${host}?fields=proxy,status,isp"
  60. set ipq [::http::config -useragent "lynx"]
  61. set ipq [::http::geturl "$link" -timeout 10000]
  62. set check_it [catch {set ipq [::http::geturl $link -timeout 3000]} error]
  63. if {$check_it == "1"} { return 0 }
  64. set data [::http::data $ipq]
  65. ::http::cleanup $ipq
  66. regexp -nocase {\"status\":\"(.+)\"} $data -> status
  67. regsub -all {\",(.*)} $status "" status
  68. if {$status != "success"} {
  69. return 0
  70. }
  71. set proxy_status "false"
  72. set isp ""
  73. regexp {"proxy":(.+)\}} $data -> proxy_status
  74. regsub {,(.*)} $proxy_status "" proxy_status
  75. regexp {"isp":\"(.+)\"} $data -> isp
  76. regsub {\",(.*)} $isp "" isp
  77. return [list $isp $proxy_status]
  78. }
  79. ##############
  80. #########################################################################
  81. ## END ##
  82. #########################################################################