Netcraft addon — File Browser

Netcraftaddonv1.0 / Netcraftaddonv1.0 / netcraft.mrc

netcraft.mrc — 3.23 KB — Download this file

on *:LOAD:echo $color(info) -a *** netcraft addon loaded, type "/netcraft" to open dialog.
on *:UNLOAD:.timernetcraft off | sockclose netcraft
menu menubar,channel {
  netcraft:netcraft
}
alias netcraft dialog -hm netcraft netcraft
alias -l timeout {
  did -ra netcraft 2 $crlf Error: $crlf $crlf Connection timed out. 
  did -e netcraft 6
  sockclose netcraft
  unset %net.*
}
dialog netcraft {
  title "Netcraft"
  size -1 -1 163 82
  option dbu
  box "", 1, 3 1 156 78
  edit "", 2, 7 21 148 40, read multi vsbar center
  edit "", 3, 21 8 75 10, autohs
  text "Site:", 4, 8 10 13 8
  button "Go!", 6, 100 8 25 10
  button "Show", 7, 129 8 25 10
  text "Timeout:", 8, 8 66 20 8
  edit "10", 9, 31 64 17 10, limit 3
  text "(in seconds)", 10, 52 66 30 8
  button "Abort", 11, 90 64 30 10
  button "Close", 12, 124 64 30 10, ok
}
on *:DIALOG:netcraft:*:*:{
  if ($devent == init) { did -f netcraft 3 | did -b netcraft 7,11 }
  if ($devent == sclick) {
    if ($did == 6) && ($did(3)) {
      ; error check
      if ($remove($did(3),$chr(46)) isnum) {
        did -ra netcraft 2 $crlf Error: $crlf $crlf Invalid DNS, IP's are not allowed.
        did -b netcraft 7
        goto skip
      }
      ; connect and proceed
      did -ra netcraft 2 $crlf Retrieving information on: $crlf $crlf $did(3).text 
      did -b netcraft 6,7
      did -e netcraft 11
      set %net.host $gettok($remove($did(3),http://),1,58)
      sockopen netcraft uptime.netcraft.com 80
      .timernetcraft 1 $iif($did(9),$ifmatch,10) timeout
      :skip
      did -r netcraft 3
    }
    ; output to channel
    if ($did == 7) && ($active != Status Window) {
      var %x = 1, %y
      while (%x <= $did(2).lines) { %y = $addtok(%y,$did(2,%x),32) | inc %x }
      msg $active %y
    }
    if ($did == 11) && ($timer(netcraft)) {
      did -b netcraft 11
      .timernetcraft off
      sockclose netcraft
      did -ra netcraft 2 $crlf Lookup aborted for: $crlf $crlf %net.host
      unset %net.*
    }
  }
  if ($devent == close) { .timernetcraft off | sockclose netcraft }
}
on *:SOCKOPEN:netcraft:sockwrite -nt $sockname GET $+(/up/graph/?host=,%net.host)
on *:SOCKREAD:netcraft:{
  if ($sockerr) return
  :read
  var %temp
  sockread %temp
  if ($sockbr == 0) return
  ; gather only information we can use
  if (*!-- regular whatos text --* iswm %temp) %net.temp = true
  if (*!-- end of regular whatos text --* iswm %temp) unset %net.temp
  if (%net.temp) %net.out = $addtok(%net.out,%temp,32)
  goto read
}
on *:SOCKCLOSE:netcraft:{
  did -e netcraft 6
  if (%net.out) {
    ; strip html tags and other crap
    .echo -q $regsub(%net.out,/(<?[^<>]*>| $+ $chr(9) $+ |FAQ|&nbsp;|The site|is running)/g,$null,%net.out)
    ; fix line breaking
    var %x = 2, %y, %z
    while ($gettok(%net.out,%x,32)) {
      %z = $ifmatch
      if (%z == on) %y = $addtok(%y,$crlf on,32)
      else %y = $addtok(%y,%z,32)
      inc %x
    }
    ; output results
    did -ra netcraft 2 $crlf %net.host is running: $crlf %y
    did -e netcraft 7
    did -f netcraft 2 1
    did -b netcraft 11
  }
  else did -ra netcraft 2 $crlf Failed to retrieve information on: $crlf $crlf %net.host
  did -b netcraft 11
  .timernetcraft off
  unset %net.*
}