Source viewer

By BrAndo on Jul 11, 2008

This dialog is used to view a page source

usefull for making a simple socket, you can search the page using regex or wildcards.

not much to explain pretty self explanatory

/*
By BrAndo| [swiftirc/quakenet]
Note: You can either put the full link under 'Host:' or seperate it your self.
*/
dialog -l source {
  title "Source viewer or whatever you want to call it idk what it is really"
  size -1 -1 357 205
  option dbu
  combo 1, 4 3 160 10, drop
  text "Host:", 3, 4 15 17 8
  edit "", 4, 4 24 160 10, autohs
  text "Page:", 5, 4 34 17 8
  edit "", 6, 4 43 160 10, autohs
  edit "0", 8, 112 65 12 10, disable limit 1 center
  text "times", 9, 126 66 16 8
  button "&View Page", 10, 4 90 45 12
  button "&Save URL", 11, 60 90 45 12
  button "&Remove URL", 12, 115 90 45 12
  text "HTTP Version:", 13, 4 55 37 8
  edit "HTTP/1.0", 14, 45 54 35 10
  check "Show Headers", 15, 4 65 48 10
  check "Show lines longer than", 16, 4 77 65 10
  text "Status:", 2, 4 106 19 8
  edit "", 18, 4 116 160 10, read autohs right
  text "View line:", 19, 4 129 25 8
  edit "", 20, 4 139 160 11, read autohs
  button "&Clipboard Line", 21, 4 154 45 12
  check "Strip HTML", 22, 55 155 45 10
  text "Line number:", 23, 4 172 35 8
  text "", 24, 47 172 35 8
  text "Line length:", 25, 4 187 33 8
  text "", 26, 47 187 35 8
  text "Total lines:", 27, 60 106 30 8, right
  text "", 28, 94 106 69 8
  list 29, 166 2 190 190, size
  edit "", 30, 215 193 140 10, autohs
  button "&Find in Page", 31, 167 193 34 10
  text "Search Type:", 32, 109 154 36 8
  radio "Normal", 33, 109 165 53 10
  radio "Wildcard", 34, 109 177 50 10
  radio "Regex", 35, 109 189 41 10
  button ">", 36, 203 193 10 10
  icon 37, 30 104 10 9, source\ready.png, 0
  edit "", 39, 69 77 23 10, disable center
  text "in own window", 40, 94 78 38 8
  check "SSL", 38, 134 54 21 10
  button "", 41, 153 19 10 4
  button "", 42, 153 38 10 4
  check "Evaluate text", 7, 69 65 43 10
  text "Port:", 17, 85 55 15 8
  edit "80", 43, 104 54 23 10
}
menu status,menubar {
  Source View:{ source }
}
on *:start:{ hmake source | hload source source\source.dat }
on *:exit:{ hsave source source\source.dat }
alias source { 
  var %sw = $iif(-?* iswm $1,$1,-m)
  if (!$isdir(source)) {
    if ($show) echo 7 -gta This is your first time running this script. Please wait while the icons are downloaded.
    mkdir source
    hmake source
    tokenize 32 img231.imageshack.us/img231/6527/completeoc8.png img241.imageshack.us/img241/9589/connectingbb4.png $&
      img187.imageshack.us/img187/4764/errorwg6.png img170.imageshack.us/img170/6811/readywg0.png
    dload $*
    .timerdl 0 0 if (!$sock(dload.*,0)) dialog %sw source source
  }
  else dialog %sw source source 
}
alias -l dload {
  noop $regex($1,/(complete|connecting|error|ready)/i)
  var %host = $gettok($1,1,47), %page = / $+ $gettok($1,2-,47)
  sockopen dload. $+ $regml(1) %host 80
  sockmark dload. $+ $regml(1) %host %page
}
alias -l wind {
  if (!$window(@longlines)) window -bk0 @longlines
  did -a source 29 <Long line>
  echo @longlines $chr(2) $+ Line Number: $1 $chr(149) Line Length: $len($2-)
  echo @longlines $2-
}
alias -l html { return $regsubex($1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }
on *:sockopen:dload.*:{
  tokenize 32 $sock($sockname).mark
  sockwrite -n $sockname GET $2 HTTP/1.0
  sockwrite $sockname Host: $1 $+ $str($crlf,2)
}
on *:sockread:dload.*:{
  tokenize 32 $sock($sockname).mark
  if ($0 == 2) {
    var %a = 1
    while (%a) {
      if ($regex(%a,/Content-Length: (\d+)/i)) sockmark $sockname $1- $regml(1)
      sockread %a
    }
  }
  var %fn = source\ $+ $gettok($sockname,2,46) $+ .png
  while ($sockbr) {
    sockread &a
    bwrite %fn -1 -1 &a
  }
  if ($file(%fn).size >= $3) sockclose $sockname
}
on *:dialog:source:init:*:{
  .timerdl off
  var %a = 1
  while ($hfind(source,fav*,%a,w)) {
    did -a $dname 1 $remove($hget(source,$v1),$chr(32))
    inc %a
  }
  did -a $dname 4 $hget(source,host)
  did -a $dname 6 $hget(source,page)
  did -c $dname 15,17,33
}
on *:dialog:source:close:*:{ unset %match* }
on *:dialog:source:sclick:10:{
  if ($did(4)) {
    if ($did(16).state && $did(39) !isnum) {
      var %n = 1
      goto err
    }
    if ($did(6)) var %host = $did(4), %page = $did(6)
    else var %host = $gettok($did(4),1,47), %page = / $+ $gettok($did(4),2-,47)
    var %port = $gettok(%host,2,58), %host = $regsubex(%host,/^https?:\/\//i,)
    if (https* iswm $did(4)) did -c $dname 38
    did -r source 28,29
    did -ra $dname 4 %host
    did -ra $dname 6 %page
    tokenize 149 $+(host %host,•,page %page,•,lines 0•headers 0)
    hadd source $*
    sockclose source
    if ($did(16).state) close -@ @longlines
    if ($did(8) == $null) did -a $dname 8 0
    if ($did(14) == $null) did -a $dname 14 HTTP/1.0
    var %e = $iif($did(8).enabled,$did(8),0) + 1, %host = $(%host,%e), %page = $(%page,%e), %ssl = $did(38).state
    if (%ssl && $sslready) {
      did -ra $dname 43 $iif(%port,$v1,443)
      sockopen -e source %host $did(43)
    }
    elseif (%ssl) goto err
    else {
      did -ra $dname 43 $iif(%port,$v1,80)
      sockopen source %host $did(43)    
    }
    sockmark source %host %page
    did -ra source 18 Connecting to site...
    did -g source 37 source\connecting.png
  }
  else {
    :err
    did -ra source 18 $iif(%n,Specify a line length.,$iif(%ssl,You do not have SSL support.,Invalid URL.))
  }
}
on *:sockopen:source:{
  if ($sockerr) {
    did -ra source 18 Socket Error (connecting to site): $v1
    did -g source 37 source\error.png
    sockclose $sockname 
  }
  else {
    did -ra source 18 Connection Successful...
    tokenize 32 $sock($sockname).mark
    sockwrite -nt $sockname GET $2 $did(source,14)
    sockwrite -t $sockname Host: $1 $+ $str($crlf,2)
    if (!$did(source,15).state) sockmark $sockname 0
  }
}
on *:sockread:source:{
  if ($sockerr) {
    did -ra source 18 Socket Error (reading buffer): $v1
    did -g source 37 source\error.png
    sockclose $sockname
  }
  else {
    did -ra source 18 Reading buffer...
    if (!$did(source,15).state && !$sock($sockname).mark) {
      var %a = 1
      while (%a) {
        sockread %a
        hinc source headers
        hinc source lines
      }
      sockmark $sockname 1
    }
    var %a
    sockread %a
    hinc source lines
    if (%a != $null) {
      if ($did(source,16).state && $len(%a) >= $did(source,39)) wind $hget(source,lines) %a
      else did -a source 29 %a
    }
  }
}
on *:sockclose:source:{
  did -ra source 18 Bytes sent: $bytes($sock($sockname).sent,b) Bytes received: $bytes($sock($sockname).rcvd,b)
  did -ra source 28 $bytes($hget(source,lines),b) $str($chr(160),3) $iif(!$did(source,15).state,$chr(40) $+ Headers: $hget(source,headers) $+ $chr(41))
  did -g source 37 source\Complete.png
}
on *:dialog:source:sclick:*:{
  if ($did == 1) {
    did -ra $dname 4 $gettok($did(1),1,47)
    did -ra $dname 6 / $+ $gettok($did(1),2-,47)
  }
  elseif ($did == 7) did $iif($did(7).state,-e,-b) $dname 8
  elseif ($did == 11) {
    if ($did(4)) {
      if ($did(6)) var %host = $regsubex($did(4),/^https?:\/\//i,), %page = $did(6)
      else var %host = $gettok($did(4),1,47), %page = / $+ $gettok($did(4),2-,47)
      %host = $regsubex(%host,/^https?:\/\//i,)
      did -ra $dname 4 %host
      did -ra $dname 6 %page
      var %a = 1
      while ($hfind(source,fav*,%a,w)) {
        if ($hget(source,$v1) == $did(4) $did(6)) goto err
        inc %a
      }
      hadd source fav $+ %a %host %page
      did -ra $dname 18 Saved URL.
      did -ac $dname 1 %host $+ %page
    }
    else {
      :err
      did -ra $dname 18 $iif($did(4),URL is already saved.,Invalid URL.)
    }
  }
  elseif ($did == 12) {
    var %a = 1
    while ($hfind(source,fav*,%a,w)) {
      if ($remove($hget(source,$v1),$chr(32)) == $did(1)) break
      inc %a
    }
    if ($hfind(source,fav*,%a,w)) {
      did -d $dname 1 $did(1).sel
      did -ra $dname 18 URL removed.
      hdel source $v1
    }
    else did -ra $dname 18 URL not saved.
  }
  elseif ($did == 16) {
    if ($did(16).state) did -e $dname 39
    else did -b $dname 39  
  }
  elseif ($did == 21 && $did(20) != $null) clipboard $did(20)
  elseif ($did == 22) { 
    var %i = $iif($did(29).seltext,$v1,$did(20))
    goto html
  }
  elseif ($did == 29 && $did(29).seltext) {
    did -ra $dname 24 $did(29).sel
    var %i = $v1
    :html
    %i = $iif($did(22).state,$html(%i),$remove(%i,$chr(9)))
    did -ra $dname 26 $len(%i)
    did -ra $dname 20 %i
  }
  elseif ($did == 31 && $did(30) != $null) {
    did -ra $dname 18 Searching...
    unset %match*
    var %a = 1, %b = 0
    while (%a <= $did(29).lines) {
      var %m
      if ($did(33).state && $did(30) isin $did(29,%a)) { %m = 1 }
      elseif ($did(34).state && $did(30) iswm $did(29,%a)) { %m = 1 }
      elseif ($did(35).state && $regex($did(29,%a),$did(30))) { %m = 1 }
      if (%m) {
        inc %b
        %match [ $+ [ %b ] ] = %a
      }
      inc %a
    }
    if (%b) {
      did -c $dname 29 %match1
      %a = $remove($did(29).seltext,$chr(9))
      if ($did(22).state) %a = $html(%a)
      did -ra $dname 20 %a
      did -ra $dname 24 $did(29).sel
      did -ra $dname 26 $len(%a)
    }
    did -ra $dname 18 Found %b lines. $iif(%b,Viewing line 1 of %b)
  }
  elseif ($did == 36 && $var(match*,0)) {
    var %a = 1
    while (%match [ $+ [ %a ] ]) {
      if ($v1 == $did(29).sel) break
      inc %a
    }
    inc %a
    %a = $iif(%match [ $+ [ %a ] ],%a,1)
    did -ra $dname 18 $regsubex($did(18),/\d+ of/i,%a of)
    did -c $dname 29 %match [ $+ [ %a ] ]
    %a = $did(29).seltext
    if ($did(22).state) %a = $html(%a)
    did -ra $dname 20 %a
    did -ra $dname 24 $did(29).sel
    did -ra $dname 26 $len(%a)
  } 
  elseif ($did == 41) did -r $dname 4
  elseif ($did == 42) did -r $dname 6
}

Comments

Sign in to comment.
BrAndo   -  Oct 30, 2008

i really dont want to look into it, as i made this so long ago. my guess is that the imageshack hosting of the icons has updated and the urls have changed. just take the commands (/did -g) and the item (icon) out of the code

 Respond  
MorbidAngel   -  Oct 30, 2008

(12:39:37) This is your first time running this script. Please wait while the icons are downloaded.

  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'
  • /dialog: 'source' error loading icon 'source\ready.png'

and it goes and goes... Anyone know why?

 Respond  
guest598594   -  Jul 11, 2008

You should upload a screen.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.