Ford

Website Advisor for eggdrop

Jun 5th, 2012
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 5.52 KB | None | 0 0
  1. ##############################################################################################
  2. ##  ##     advisor.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help      ##  ##
  3. ##############################################################################################
  4. ## To use this script you must set channel flag +advisor (ie .chanset #chan +advisor)       ##
  5. ##############################################################################################
  6. ##############################################################################################
  7. ##  ##                             Start Setup.                                         ##  ##
  8. ##############################################################################################
  9. namespace eval advisor {
  10. ## Edit safelogo to change the logo for sites that return a value of safe               ##  ##
  11.   variable safelogo "\017\00300,03\002Safe\017"
  12. ## Edit safetext to change the text shown when a site returns a value of safe           ##  ##
  13.   variable safetext "No problems found with\017"
  14. ## Edit warninglogo to change the logo for sites that return a warning                  ##  ##
  15.   variable warninglogo "\017\00301,08\002Caution\017"
  16. ## Edit warningtext to change the text shown when a site returns a warning              ##  ##
  17.   variable warningtext "Found potential suspicious behavior on\017"
  18. ## Edit dangerlogo to change the logo shown when a site returns danger                  ##  ##
  19.   variable dangerlogo "\017\00300,04\002Danger\017"
  20. ## Edit dangertext to change the text shown when a site returns danger                  ##  ##
  21.   variable dangertext "Found potential security risks with\017"
  22. ## showsafe, showwarning & showdanger can be turned on or off by changing the value.    ##  ##
  23. ## Use lowercase letters only for this setting.                                         ##  ##
  24.   variable showsafe "on"
  25.   variable showwarning "on"
  26.   variable showdanger "on"
  27. ## Edit sitecolor to change the color that the sitename will be displayed in            ##  ##
  28.   variable sitecolor "\017\002"
  29. ##############################################################################################
  30. ##  ##                           End Setup.                                              ## ##
  31. ##############################################################################################
  32.   setudef flag advisor
  33.   bind pubm -|- "*" advisor::main
  34. }
  35. proc advisor::main {nick host hand chan text} {
  36.   if {[lsearch -exact [channel info $chan] +advisor] != -1} {
  37.     set text [strip $text]
  38.     if {[regexp {(www\.|http\x3A\x2F\x2F)([^\s]+)} $text]} {
  39.       set counter 1
  40.       set text [regexp -all -inline {(www\.|http\x3A\x2F\x2F)([^\s]+)} $text]
  41.       foreach i $text {
  42.         if {$counter == 3} {
  43.           resolve $nick $host $hand $chan $i
  44.           set counter 0
  45.         }
  46.         incr counter
  47.       }
  48.     }
  49.   }
  50. }
  51. proc advisor::check {nick host hand chan site} {
  52.   set advisorsite "www.siteadvisor.com"
  53.   set advisorurl "/sites/${site}"
  54.   if {[catch {set advisorsock [socket -async $advisorsite 80]} sockerr]} {
  55.     putserv "PRIVMSG $chan :$advisorsite $advisorurl $sockerr error"
  56.     return 0
  57.   } else {
  58.     puts $advisorsock "GET $advisorurl HTTP/1.0"
  59.     puts $advisorsock "Host: $advisorsite"
  60.     puts $advisorsock "User-Agent: Opera 9.6"
  61.     puts $advisorsock ""
  62.     flush $advisorsock
  63.     while {![eof $advisorsock]} {
  64.       set advisorvar " [gets $advisorsock] "
  65.       if {[string match "*class=\"siteGreen\"*" $advisorvar] && $advisor::showsafe == "on"} {
  66.         putserv "PRIVMSG $chan : $advisor::safelogo $advisor::safetext ${advisor::sitecolor}${site} $advisor::safelogo"
  67.       } elseif {[string match "*class=\"siteYellow\"*" $advisorvar] && $advisor::showwarning == "on"} {
  68.         putserv "PRIVMSG $chan : $advisor::warninglogo $advisor::warningtext ${advisor::sitecolor}${site} $advisor::warninglogo"
  69.       } elseif {[string match "*class=\"siteRed\"*" $advisorvar] && $advisor::showdanger == "on"} {
  70.         putserv "PRIVMSG $chan : $advisor::dangerlogo $advisor::dangertext ${advisor::sitecolor}${site} $advisor::dangerlogo"
  71.       }
  72.     }
  73.   }
  74. }
  75. proc advisor::resolve {nick host hand chan site} {
  76.   set resolveurl "/"
  77.   regexp {([^\/]*)} [string map {\xf ""} $site] match resolvesite
  78.   regexp {(\/.*)} [string map {\xf ""} $site] match resolveurl
  79.   if {[catch {set resolvesock [socket -async $resolvesite 80]} sockerr]} {
  80.     return 0
  81.   } else {
  82.     puts $resolvesock "GET $resolveurl HTTP/1.0"
  83.     puts $resolvesock "Host: $resolvesite"
  84.     puts $resolvesock "User-Agent: Opera 9.6"
  85.     puts $resolvesock ""
  86.     flush $resolvesock
  87.     while {![eof $resolvesock]} {
  88.       set resolvevar " [gets $resolvesock] "
  89.       if {[regexp -nocase {http\/1\.[0-9]\s([0-9]{3})} $resolvevar match code]} {
  90.         if {$code != "301"} {
  91.           check $nick $host $hand $chan $resolvesite
  92.           break
  93.           return 0
  94.         }
  95.       } elseif {[regexp -nocase {Location:\s(.*)} $resolvevar match redirect]} {
  96.         regexp {:\/\/([^\/]*)} $redirect match resolvesite
  97.         check $nick $host $hand $chan $resolvesite
  98.         break
  99.         return 0
  100.       } elseif {[regexp {<html} $resolvevar]} {
  101.         check $nick $host $hand $chan $resolvesite
  102.         break
  103.         return 0
  104.       }
  105.     }
  106.   }
  107. }
  108. proc advisor::strip {text} {
  109.   regsub -all -- {\017|\015|\031|\002|\037|\026|\003(\d{1,2})?(,\d{1,2})?} $text "" text
  110.     return $text
  111. }
  112. putlog "\002*Loaded* \002\00300,02Web Site Advisor\002\003 \002by Ford_Lawnmower irc.GeekShed.net #Script-Help"
Advertisement
Add Comment
Please, Sign In to add comment