tglogo.png

Downloading File

Filename: Kirby's PasteBin Uploader/Downloader
alias pastebin dialog $iif($dialog(pastebin),-v,-m) pastebin pastebin
 
alias -l ab2word { var %x PasteBin\languages.txt, %y PasteBin\abbreviations.txt | noop $read(%y,w,$1) | return $iif($read(%x,$readn),$v1) }
alias -l between { noop $regex($1,/\Q $+ $2 $+ \E(.*?)\Q $+ $3 $+ \E/gi) | return $regml($4) }
alias -l hex { return $regsubex($1-,/([^\d\w])/gi,$+(%,$base($asc(\1),10,16))) }
alias -l pwrite { var %x $1 | tokenize 124 $2- | write $+(PasteBin\,%x) $* }
alias -l uber { return $replace($regsubex($regsubex($1,/&#(x?([a-f\d]*));/gi,$chr($iif($left(\1,1) == x,$base(\2,16,10),\2))),/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null),&lt;,<,&gt;,>,&quot;,",&amp;,&) }
alias -l word2ab { var %x PasteBin\languages.txt, %y PasteBin\abbreviations.txt | noop $read(%x,w,$1) | return $iif($read(%y,$readn),$v1) }
 
menu * {
  PasteBin Uploader/Downloader : pastebin
}
 
dialog pastebin {
  title "Pastebin Uploader / Downloader"
  size -1 -1 454 375
  option dbu
  box "Upload:", 1, 5 2 232 84
  text "Name:", 2, 14 11 16 8
  edit "", 3, 33 10 67 10, autohs limit 24 center
  text "Private sub-domain:", 4, 109 11 49 8
  edit "", 5, 160 10 68 10, autohs limit 50 center
  text "Syntax highlighting:", 6, 26 25 48 8
  combo 7, 81 24 75 62, sort size drop
  check "Private Paste?", 8, 171 24 45 10
  button "Browse file...", 9, 11 51 42 12
  edit "", 10, 61 52 170 10, autohs center
  text "How long should your post be retained?", 11, 19 39 96 8
  radio "a day", 12, 126 38 24 10
  radio "a month", 13, 157 38 30 10
  radio "forever", 14, 195 38 28 10
  button "Preview!", 15, 53 68 50 12
  button "Upload!", 16, 135 68 50 12
  box "Download:", 17, 237 2 213 37
  text "Pastebin URL:", 18, 244 10 34 8
  edit "", 19, 280 9 106 10, autohs center
  check "Load to remotes?", 20, 393 9 52 10
  button "Preview", 21, 273 22 50 12
  button "Download!", 22, 362 22 50 12
  edit "", 23, 5 90 443 261, multi return hsbar vsbar
  box "Information:", 24, 237 36 213 50
  text "", 25, 243 43 201 39
  button "Close Dialog", 26, 38 356 60 14
  button "Clear Screen", 27, 142 356 60 14
  button "Copy to Clipboard", 28, 248 356 60 14
  button "Go to line...", 29, 353 356 60 14
  link "", 30, 256 49 188 7
}
 
on *:dialog:PasteBin:*:*: {
  if ($devent == init) {
    $iif(!$isdir(PasteBin),mkdir PasteBin)
    if (!$isfile(PasteBin\abbreviations.txt)) || (!$isfile(PasteBin\languages.txt)) {
      $iif($input(Please wait while 72 languages and their abbreviations are being downloaded.,io,Please wait... :-D),dialog -x PasteBin PasteBin)
      hadd -m PasteBin Ticks $ticks | hadd -m PasteBin Version Load
      sockopen pastebin pastebin.com 80
    }
    $iif($dialog(PasteBin),did -a PasteBin 25 $+(Status: Ready!,$crlf,Credits: PasteBin Software developed by Paul Dixon))
    if ($isfile(PasteBin\languages.txt)) {
      loadbuf -o PasteBin 7 Pastebin\languages.txt
      did -c PasteBin 7 47 | did -c PasteBin 13 | did -b PasteBin 5,15-16,21-22
    }
    hadd -m PasteBin Expiry m
  }
  if ($devent == sclick) {
    if ($did == 8) { did $iif($did(8).state,-e,-b) PasteBin 5 }
    if ($did == 9) {
      if ($sfile(*.txt,Choose a file to upload)) {
        var %x 1, %y $did(23).lines, %z $qt($v1)
        while (%x <= %y) {
          if ($did(23,%x)) {
            $iif($input(It appears that text exists in the box. Are you sure you want to continue?,yi,Warning!),did -r PasteBin 23,halt)
            break
          }
          inc %x
        }
        loadbuf -o PasteBin 23 %z
        did -ra PasteBin 10 %z | did -e PasteBin 16 | did -c PasteBin 10 1 | did -cf PasteBin 23 1
      }
    }
    if ($did isnum 12-14) {
      hadd -m PasteBin Expiry $mid($gettok($did($did),$numtok($did($did),32),32),1,1)
      did -a PasteBin 25 $+(Status: Ready!,$crlf,Post Expiry ~ $did($did),:,$chr(32),Good for $iif($did == 12,IRC or IM conversations,$iif($did == 13,email conversations / temporary data,$iif($did == 14,long term archival of useful snippets))))
    }
    if ($did == 15) {
      var %x 1, %y $did(23).lines, %z $qt($did(10))
      while (%x <= %y) {
        if ($did(23,%x)) {
          $iif($input(It appears that text exists in the box. Are you sure you want to continue?,yi,Warning!),did -r PasteBin 23,halt)
          break
        }
        inc %x
      }
      loadbuf -o PasteBin 23 %z
      did -ra PasteBin 10 %z | did -r PasteBin 30 | did -e PasteBin 16 | did -c PasteBin 10 1 | did -cf PasteBin 23 1
    }
    if ($did == 16) {
      savebuf -o PasteBin 23 Pastebin\pb.tmp
      hadd -m PasteBin Ticks $ticks | hadd -m PasteBin Version Upload
      hadd -m PasteBin Tags $+(parent_id=&format=,$word2ab($did(PasteBin,7)),&paste=Send&poster=,$did(PasteBin,3),&expiry=,$hget(PasteBin,Expiry),&code2=)
      sockopen pastebin $+($regsubex($iif(!$did(5).enabled,$null,$iif($did(5) == .,$null,$iif($did(5),$v1,$null))),(^\.(.+)\.$|^(.+)\.$|^\.(.+)$|^(.+)$),$+(\2,.)),pastebin.com) 80
      did -a PasteBin 25 Status: Submitting data towards $+($regsubex($iif(!$did(5).enabled,$null,$iif($did(5) == .,$null,$iif($did(5),$v1,$null))),(^\.(.+)\.$|^(.+)\.$|^\.(.+)$|^(.+)$),$+(\2,.)),pastebin.com) ...
      did -b PasteBin 16,23 | did -r PasteBin 30
    }
    if ($did == 20) { $iif($regex($did(19),^http:\/\/((.*)\.)?(pastebin)\.com\/(\w+)),did $iif($did(20).state,-b,-e) PasteBin 21) }
    if ($did isnum 21-22) {
      var %x 1, %y $did(23).lines
      while (%x <= %y) {
        if ($did(23,%x)) {
          $iif($input(It appears that text exists in the box. Are you sure you want to continue?,yi,Warning!),did -r PasteBin 23,halt)
          break
        }
        inc %x
      }
      noop $regex($did(19),http:\/\/((.*)\.)?(pastebin|pastebin)\.com\/(.*))
      $iif($regml(4),$iif(!$isdir($+(PasteBin\,$regml(2))),mkdir $+(Pastebin\,$regml(2))))
      $iif($did == 22,$iif($isfile($+(PasteBin\,$iif($regml(4),$+($regml(2),\)),$iif($regml(4),$v1,$regml(2)),.txt)),$iif(!$input(The file $qt($iif($regml(4),$v1,$regml(2))) in directory $qt($iif($regml(4),$+(PasteBin\,$regml(2)),PasteBin)) already exists. If you continue the file will be overwritten. Are you sure you want to continue?,yi,Warning!),halt,.remove $+(PasteBin\,$iif($regml(4),$+($regml(2),\)),$iif($regml(4),$v1,$regml(2)),.txt))))
      noop $regex($did(19),http:\/\/((.*)\.)?(pastebin|pastebin)\.com\/(.*))
      hadd -m PasteBin Ticks $ticks | hadd -m PasteBin Version Download | hadd -m PasteBin Method $iif($did == 21,Preview,Download)
      sockopen pastebin pastebin.com 80 | sockmark pastebin $iif($regml(4),$regml(2) $v1,$regml(2))
      did -b PasteBin 15-16,19-23 | did -a PasteBin 25 Status: Connecting to $did(19) ... | did -r PasteBin 30
    }
    if ($did == 26) { dialog -x PasteBin PasteBin }
    if ($did == 27) { did -r PasteBin 3,5,10,19,23 | did -b PasteBin 15-16,21-22 | did -u Pastebin 8,12-14,20 | did -c PasteBin 7 47 | did -c PasteBin 13 | did -a PasteBin 25 $+(Status: Cleared screen!) }
    if ($did == 28) {
      if ($did(23).seltext) {
        did -a PasteBin 25 $+(Status: Copied selected text to clipboard!,$crlf,Size: $bytes($len($v1),b) bytes,$crlf,Number of lines: $iif($count($v1,$crlf),$v1,1))
        clipboard $v1 | halt
      }
      clipboard $null
      var %x 1, %y $did(23).lines
      while (%x <= %y) {
        var %z $calc(%z + ($len($did(23,%x)) + 2))
        clipboard -an $did(23,%x)
        inc %x
      }
      did -a PasteBin 25 $+(Status: Copied all text to clipboard!,$crlf,Size: $bytes(%z,b) bytes,$crlf,Number of lines: $did(23).lines)
    }
    if ($did == 29) {
      var %x $input(Enter a line number $iif($did(23).lines == 1,$null,from 1 to $did(23).lines) to go to...,ei,Go To Line)
      did -cf PasteBin 23 $iif($abs(%x) isnum 1- $did(23).lines,$v1,$iif($abs(%x) > $did(23).lines,$v2,$iif(!$abs(%x),1)))
    }
    if ($did == 30) { clipboard $did(30) }
  }
  if ($devent == rclick) && ($did == 30) { clipboard $did(30) }
  if ($devent == dclick) && ($did == 30) { run $did(30) }
  if ($devent == edit) {
    if ($did == 3) && ($regex($did(3),/[^\w\-]/ig)) { did -ra PasteBin 3 $regsubex($did(3),/([^\w\-])/ig,$null) }
    if ($did == 5) {
      if ($regex($did(5),/[^\w\-\.]/ig)) || ($regex($did(5),/\.{2}/)) { did -ra PasteBin 5 $regsubex($regsubex($did(5),/[^\w\-\.]/ig,$null),/\.{2}/g,.) }
    }
    if ($did == 10) { did $iif($isfile($qt($did(10))),-e,-b) PasteBin 15 }
    if ($did == 19) { did $iif($regex($did(19),^http:\/\/((.*)\.)?(pastebin)\.com\/(\w+)),-e,-b) PasteBin 21-22 }
    if ($did == 23) {
      did $iif($did(23),-e,-b) PasteBin 16
      did -a PasteBin 25 $+(Status: Ready!,$crlf,Note: To highlight particular lines,$chr(44),$chr(32),prefix each line with @@)
    }
  }
  if ($devent == close) { hfree PasteBin | unset %pb }
}
 
on *:sockopen:pastebin: {
  if ($hget(PasteBin,Version) == Download) || ($hget(PasteBin,Version) == Load) {
    tokenize 32 $sock(pastebin).mark
    sockwrite -n $sockname GET $+(/,$iif(!$1,$null,$iif(!$2,$1,$2))) HTTP/1.1
    sockwrite -n $sockname Host: $+($iif(!$1,$null,$iif($2,$+($1,.))),pastebin.com)
    sockwrite -n $sockname $crlf
  }
  elseif ($hget(PasteBin,Version) == Upload) {
    var %x 1, %y $did(PasteBin,23).lines
    while (%x <= %y) {
      var %z $calc(%z + $len($hex($did(PasteBin,23,%x))))
      inc %x
    }
    sockwrite -n $sockname POST /pastebin.php HTTP/1.1
    sockwrite -n $sockname Host: $+($regsubex($iif(!$did(Pastebin,5).enabled,$null,$iif($did(PasteBin,5) == .,$null,$iif($did(PasteBin,5),$v1,$null))),(^\.(.+)\.$|^(.+)\.$|^\.(.+)$|^(.+)$),$+(\2,.)),pastebin.com)
    sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
    sockwrite -n $sockname Content-length: $calc($len($hget(PasteBin,Tags)) + %z + (3 * %y))
    sockwrite $sockname $crlf
    sockwrite $sockname $hget(PasteBin,Tags)
    hinc -m PasteBin Buffer
  }
}
 
on *:sockwrite:pastebin: {
  if ($hget(PasteBin,Version) == Upload) && ($hget(PasteBin,Buffer) <= $did(PasteBin,23).lines) {
    sockwrite $sockname $+($hex($did(PasteBin,23,$hget(PasteBin,Buffer))),%,0A)
    hinc -m PasteBin Buffer
  }
}
 
on *:sockread:pastebin: {
  tokenize 32 $sock(pastebin).mark
  sockread %pb
  if (!$1) {
    if ($regex(%pb,<select name="format">)) && ($hget(PasteBin,Version) == Load) {
      var %x $regsubex($between(%pb,$+($str(-,28),</option>),</select>,1),/<option value="(.*?)">(.*?)</option>/g,$+(\1,$chr(124))), %y $regsubex($between(%pb,$+($str(-,28),</option>),</select>,1),/<option value="(.*?)">(.*?)</option>/g,$+(\2,$chr(124)))
      pwrite abbreviations.txt %x | pwrite languages.txt %y
      sockclose pastebin
      dialog -m PasteBin PasteBin
      did -a PasteBin 25 $+(Status: Downloaded text files,$crlf,Total estimated time: $calc(($ticks - $hget(PasteBin,Ticks))/1000) seconds)
    }
    elseif ($regex(%pb,Location:(.*))) && ($hget(PasteBin,Version) == Upload) {
      sockclose pastebin
      did -a PasteBin 25 $+(Status: File uploaded,$crlf,Link:,$crlf,Size: $bytes($file(PasteBin\pb.tmp),b) bytes,$crlf,Number of lines: $did(PasteBin,23).lines,$crlf,Total estimated time: $calc(($ticks - $hget(PasteBin,Ticks))/1000) seconds)
      did -a PasteBin 30 $regml(1) | did -e PasteBin 16,23 | did -cf Pastebin 23 1
      .remove PasteBin\pb.tmp
    }
  }
  elseif ($1) {
    if ($regex(%pb,<title>(.*)\s+pastebin\s+-)) { hadd -m PasteBin Type $regml(1) | did -a PasteBin 25 Status: Buffering $did(PasteBin,19) ... }
    if ($regex(%pb,<h1>(.*)<br/><a href="#")) { hadd -m PasteBin Info $uber($regml(1)) }
    if ($regex(%pb,<div class="de[\d]">(.*)</div>)) || ($regex(%pb,<li class="li[\d]"><div class="de[\d]">(.*)</div>)) {
      hadd -m PasteBin Directory $qt($+(PasteBin\,$iif($2,$+($1,\)),$iif(!$2,$1,$2),$iif(!$2,$+($iif($hget(PasteBin,Type),$+($chr(32),$+($chr(40),$v1,$chr(41)))),$iif($did(PasteBin,20).state,.mrc,.txt)),$iif($did(PasteBin,20).state,.mrc,.txt))))
      var %x $uber($regml(1))
      $iif($hget(PasteBin,Method) == Download,write $hget(PasteBin,Directory) $+($replace(%x,&nbsp;,$iif($count(%x,&nbsp;) != $numtok(%x,32),$chr(32))),$crlf))
      did -a PasteBin 23 $+($replace(%x,&nbsp;,$iif($count(%x,&nbsp;) != $numtok(%x,32),$chr(160))),$crlf)
    }
    if ($regex(%pb,</h1><ul><li>(.*)</li>)) || ($regex(%pb,(.*)<P>)) {
      sockclose pastebin
      did -a PasteBin 25 $+(Status: Ready!,$crlf,Error: Could not download $qt($+(http://,$iif($2,$1),pastebin.com/,$iif($2,$v1,$1))) - $regml(1))
      did -e PasteBin 16,19-23 | did -f PasteBin 23
    }
    if ($regex(%pb,<select name="format">)) {
      sockclose pastebin
      did -e PasteBin 16,19-23 | did -i PasteBin 23 1 | did -d PasteBin 23 1 | did -d PasteBin 23 $did(PasteBin,23).lines
      did -a PasteBin 25 $+(Status: $iif($hget(PasteBin,Method) == Download,$iif($did(PasteBin,20).state,Loaded script $+($chr(35),$script(0),:),Downloaded to:) $hget(PasteBin,Directory),Now previewing),$crlf,Link:,$crlf,PasteBin Type: $iif($hget(PasteBin,Type),$v1,None),$crlf,PasteBin Info: $hget(PasteBin,Info),$crlf,Total estimated time: $calc(($ticks - $hget(PasteBin,Ticks))/1000) seconds)
      did -a PasteBin 30 $did(PasteBin,19) | did -c PasteBin 19 1 | did -cf Pastebin 23 1
      $iif($did(PasteBin,20).state,.load -rs $qt($+($mircdir,$noqt($hget(PasteBin,Directory)))))
    }
  }
}

Related Files

by Akishoot
by Vulcan

Please note that on our website we use cookies necessary for the functioning of our website, cookies that optimize the performance. To learn more about our cookies, how we use them and their benefits, please read our Cookie Policy.
I Understand