Advertisement
ageisp0lis

[bitcoin] mIRC helper script for #bitcoin-otc

Oct 31st, 2011
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 13.79 KB | None | 0 0
  1. /*
  2. OTCgpg helper script for #bitcoin-otc
  3. By ageis & imsaguy
  4. 2011.11.01
  5.  
  6. to install, type /load -rs <script_filename.mrc>
  7.  
  8. new features:
  9. popup menus for channel & userlist
  10. settings/configuration
  11. two options for downloading OTP
  12. ASCII-encrypted passwords
  13. automatic verify on join
  14.  
  15. todo:
  16. gpg registration
  17. buy/sell system
  18. */
  19.  
  20. menu Nicklist {
  21.   OTCgpg
  22.   .Ident:msg %otcgpgbot ;;ident $1
  23.   .GPG info:msg %otcgpgbot ;;gpg info $1
  24.   .Get trust:msg %otcgpgbot ;;gettrust $1
  25.   .Rate
  26.   ..Rate:msg %otcgpgbot ;;rate $1 $$?="Enter a rating (-10 to 10):" $input("Would you like to leave a comment? (Type it below)",en)
  27.   ..Unrate:msg %otcgpgbot ;;unrate $1
  28.   ..Rated?:msg %otcgpgbot ;;rated $1
  29.   ..Get rating:msg %otcgpgbot ;;getrating $1
  30.   .Tell
  31.   ..Now:msg %otcgpgbot ;;tell $1 $$?="What's your message?"
  32.   ..Later:msg %otcgpgbot ;;later tell $1 $$?="What's your message?"
  33.   ..Offer guide:msg %otcgpgchan ;;tell $1 [guide]
  34.   ..GPG instructions:msg %otcgpgchan ;;tell $1 [gpg]
  35.   .WoT
  36.   ..Ratings received
  37.   ...All:{
  38.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ $1 $+ &sign=ANY&type=RECV
  39.     echo $color(info) -st * [OTCgpg] Looking up all ratings received for $1 . . .
  40.   }
  41.   ...Positive:{
  42.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ $1 $+ &sign=POS&type=RECV
  43.     echo $color(info) -st * [OTCgpg] Looking up all positive ratings received for $1 . . .    
  44.   }
  45.   ...Negative:{
  46.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ $1 $+ &sign=NEG&type=RECV
  47.     echo $color(info) -st * [OTCgpg] Looking up all negative ratings received for $1 . . .
  48.   }
  49.   ..Ratings sent
  50.   ...All:{
  51.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ $1 $+ &sign=ANY&type=SENT
  52.     echo $color(info) -st * [OTCgpg] Looking up all ratings sent by $1 . . .
  53.   }
  54.   ...Positive:{
  55.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ $1 $+ &sign=POS&type=SENT
  56.     echo $color(info) -st * [OTCgpg] Looking up all positive ratings sent by $1 . . .
  57.   }
  58.   ...Negative:{
  59.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ $1 $+ &sign=NEG&type=SENT
  60.     echo $color(info) -st * [OTCgpg] Looking up all negative ratings sent by $1 . . .
  61.   }  
  62. }
  63.  
  64. menu Channel {
  65.   OTCgpg
  66.   .Authenticate:/otcgpg_starteauth
  67.   .Ticker:msg %otcgpgbot ;;ticker
  68.   .Ident:msg %otcgpgbot ;;ident $$?="Enter username to identify:"
  69.   .MtGox Live:url -an http://mtgoxlive.com/orders
  70.   .OTC Order Book:url -an http://bitcoin-otc.com/vieworderbook.php
  71.   .Bitcoin
  72.   ..Stats:msg %otcgpgbot ;;bc,stats
  73.   ..Difficulty:msg %otcgpgbot ;;bc,diff
  74.   ..Change in difficulty:msg %otcgpgbot ;;bc,diffchange
  75.   ..Blocks:msg %otcgpgbot ;;bc,blocks
  76.   .Buy/Sell
  77.   ..Buy:msg %otcgpgchan ;;buy $$?="What are you buying?"
  78.   ..Sell:msg %otcgpgchan ;;sell $$?="What are you selling?"
  79.   ..Remove:msg %otcgpgchan ;;remove
  80.   ..Refresh:msg %otcgpgchan ;;refresh
  81.   ..View:msg %otcgpgchan ;;view $$?="Which order #?"
  82.   .WoT
  83.   ..Ratings received
  84.   ...All:{
  85.     var %otcuser $$?="Enter username:"
  86.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ %otcuser $+ &sign=ANY&type=RECV
  87.     echo $color(info) -st * [OTCgpg] Looking up all ratings received for %otcuser . . .
  88.   }
  89.   ...Positive:{
  90.     var %otcuser $$?="Enter username:"
  91.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ %otcuser $+ &sign=POS&type=RECV
  92.     echo $color(info) -st * [OTCgpg] Looking up all positive ratings received for %otcuser . . .    
  93.   }
  94.   ...Negative:{
  95.     var %otcuser $$?="Enter username:"
  96.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ %otcuser $+ &sign=NEG&type=RECV
  97.     echo $color(info) -st * [OTCgpg] Looking up all negative ratings received for %otcuser . . .
  98.   }
  99.   ..Ratings sent
  100.   ...All:{
  101.     var %otcuser $$?="Enter username:"
  102.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ %otcuser $+ &sign=ANY&type=SENT
  103.     echo $color(info) -st * [OTCgpg] Looking up all ratings sent by %otcuser . . .
  104.   }
  105.   ...Positive:{
  106.     var %otcuser $$?="Enter username:"
  107.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ %otcuser $+ &sign=POS&type=SENT
  108.     echo $color(info) -st * [OTCgpg] Looking up all positive ratings sent by %otcuser . . .
  109.   }
  110.   ...Negative:{
  111.     var %otcuser $$?="Enter username:"
  112.     url -an http://bitcoin-otc.com/viewratingdetail.php?nick= $+ %otcuser $+ &sign=NEG&type=SENT
  113.     echo $color(info) -st * [OTCgpg] Looking up all negative ratings sent by %otcuser . . .
  114.   }  
  115.   .Settings
  116.   ..Set verify on join
  117.   ...On:set %otcgpgauto true | echo $color(info) -st * [OTCgpg] GPG autoverify ON with %otcgpgbot for %otcgpguser in %otcgpgchan
  118.   ...Off:set %otcgpgauto false | echo %color(info) -st * [OTCgpg] GPG autoverify OFF with %otcgpgbot for %otcgpguser in %otcgpgchan
  119.   ..Set GPG bot name:{
  120.     set %otcgpgbot $input(What is the name of the GPG bot?,e,GPG bot name,gribble)
  121.     if (%otcgpgbot == $null) {
  122.       set %otcgpgbot gribble
  123.       echo $color(info) -st * [OTCgpg] Using default GPG bot name of gribble.
  124.     }
  125.   }
  126.   ..Set IRC channel:{
  127.     set %otcgpgchan $input(What is the name of the IRC channel?,e,GPG IRC channel,#bitcoin-otc)
  128.     if (%otcgpgchan == $null) {
  129.       set %otcgpgchan #bitcoin-otc
  130.       echo $color(info) -st * [OTCgpg] Using default IRC channel of #bitcoin-otc.
  131.     }
  132.   }
  133.   ..Set GPG username:{
  134.     set %otcgpguser $input(What is your %otcgpgchan username?,eo,Enter username:,$me)
  135.   }
  136.   ..GPG password
  137.   ...Set/store:{
  138.     set %otcgpgpass $cryptoid($input(What is your GPG password?,po,Enter password:),e
  139.     echo $color(info) -st * [OTCgpg] Your password will be remembered. To clear, type /unset $chr(37) $+ otcgpgpass
  140.   }
  141.   ...Clear:{
  142.     unset %otcgpgpass
  143.     echo $color(info) -st * [OTCgpg] Password cleared. You will be prompted for it in the future.
  144.   }
  145.  
  146.   ..Set GPG.exe location:/otcgpg_findgpg
  147.   ..Set download method
  148.   ...choose internal (default):{
  149.     set %otcgpgdl true
  150.     echo $color(info) -st * [OTCgpg] Using internal download method for encrypted OTPs.
  151.   }
  152.   ...choose wget:{
  153.     set %otcgpgdl false
  154.     if ($isfile(C:\Cygwin\bin\wget.exe)) {
  155.       set %otcgpgwgetpath "C:\cygwin\bin\wget.exe"
  156.       echo $color(info) -st * [OTCgpg] wget found at C:\cygwin\bin\
  157.     }
  158.     elseif ($isfile(C:\Program Files\GnuWin32\bin\wget.exe)) {
  159.       set %otcgpgwgetpath "C:\Program Files\GnuWin32\bin\wget.exe"
  160.       echo $color(info) -st * [OTCgpg] wget found at C:\Program Files\GnuWin32\bin\
  161.     }
  162.     elseif ($isfile(C:\Program Files (x86)\GnuWin32\bin\wget.exe)) {
  163.       set %otcgpgwgetpath "C:\Program Files (x86)\GnuWin32\bin\wget.exe"
  164.       echo $color(info) -st * [OTCgpg] wget found at C:\Program Files (x86)\GnuWin32\bin\
  165.     }
  166.     else {
  167.       set %otcgpgwgetpath $$?="Can't find wget.exe! Specify the path where it is located:"
  168.       if ($isfile(%otcgpgwgetpath)) {
  169.         set %otcgpgwgetpath $qt(%otcgpgwgetpath)
  170.       }
  171.       else {
  172.         set %otcgpgdl true
  173.         echo $color(info) -st * [OTCgpg] Failed to find wget.exe Reverting to internal download method. . .
  174.       }      
  175.     }
  176.   }
  177. }
  178.  
  179. on *:LOAD:{
  180.   unset %otcgpg*
  181.   set %otcgpgbot gribble
  182.   set %otcgpgchan #bitcoin-otc
  183.   set %otcgpgdl true
  184.  
  185.   /otcgpg_findgpg
  186.  
  187.   while (%otcgpguser == $null) set %otcgpguser $input(What is your %otcgpgchan username?,eo,Enter username:,$me)
  188.  
  189.   if ($input(Would you like to store your password?,yi,Configuration)) {
  190.     set %otcgpgpass $cryptoid($input(What is your GPG password?,po,Enter password:),e)
  191.   }
  192.   else {
  193.     unset %otcgpgpass
  194.   }
  195.  
  196.   if ($input(Would you like to automatically authenticate and verify to %otcgpgbot every time you join %otcgpgchan ?,yi,Configuration)) {
  197.     set %otcgpgauto true
  198.   }
  199.   else {
  200.     set %otcgpgauto false
  201.   }
  202.   echo $color(info) -st * [OTCgpg] The script is now configured and ready. Use /otcgpg_starteauth to ident to %otcgpgbot and gain voice in %otcgpgchan .
  203. }
  204.  
  205. on 1:JOIN:#: {
  206.   if ($nick == $me && %otcgpgauto == true && $chan == %otcgpgchan) {
  207.     echo $color(info) -st * [OTCgpg] Joined %otcgpgchan . Requesting authentication from %otcgpgbot . . .
  208.     msg %otcgpgbot ;;eauth %otcgpguser
  209.   }
  210. }
  211.  
  212. on *:SOCKOPEN:otcdl.*:{
  213.   hadd -m ticks $sockname $ticks
  214.   var %file = $nopath($gettok($sock($sockname).mark,3,32))
  215.   var %fullfile = $+(",$scriptdir,%file,")
  216.   var %sckr = sockwrite -n $sockname, %^ = $gettok($sock($sockname).mark,3,32)
  217.   echo $color(info) -st * [OTCgpg] Connecting to OTP host. . .
  218.   write -c %fullfile
  219.   %sckr GET $iif(left(%^,1) != $chr(47),$chr(47) $+ %^,%^) HTTP/1.0
  220.   %sckr HOST: $gettok($sock($sockname).mark,2,32)
  221.   %sckr ACCEPT: *.*
  222.   %sckr $crlf
  223. }
  224.  
  225. on *:SOCKREAD:otcdl.*:{
  226.   if ($sockerr) {
  227.     echo $color(info) -st * [OTCgpg] Error: $sock($sockname).wsmsg
  228.     return
  229.   }
  230.   var %a
  231.   :begin
  232.   if ($gettok($sock($sockname).mark,1,32) == head) {
  233.     sockread %a
  234.   }
  235.   else {
  236.     sockread &b
  237.   }
  238.   if ($sockbr) {
  239.     tokenize 32 $sock($sockname).mark
  240.     if ($1 == HEAD) {
  241.       if (%a) {
  242.         ; Catching the file size, avoiding the data header
  243.         if ($gettok(%a,1,32) == Content-Length:) { var %totsize = $gettok(%a,2,32) }
  244.       }
  245.       else {
  246.         ; When there are no vars, we now we have to start binary downloading
  247.         echo $color(info) -st * [OTCgpg] Downloading %totsize bytes. . .
  248.         sockmark $sockname GET $2- %totsize
  249.       }
  250.     }
  251.     elseif ($1 == GET) {
  252.       ; Downloading ...
  253.       var %file = $+(",$scriptdir,$nopath($3),"), %cursize = $file(%file).size
  254.       var %totsize = $gettok($sock($sockname).mark,4,32)
  255.       bwrite %file -1 &b
  256.     }
  257.     goto begin
  258.   }
  259. }
  260.  
  261. on *:SOCKCLOSE:otcdl.*:{
  262.   var %ticks = $calc(($ticks - $hget(ticks,$sockname)) /1000)
  263.   var %filename = $nopath($gettok($sock($sockname).mark,3,32))
  264.   echo $color(info) -st * [OTCgpg] File %filename downloaded in : %ticks seconds. Beginning decryption.
  265.   /otcgpg_decrypt %filename
  266. }
  267.  
  268. on *:TEXT:$(Request successful for user %otcgpguser $+ *):?:{
  269.   if ($nick == %otcgpgbot && %otcgpgdl == true) {
  270.     /otcgpg_download $wildtok($1-, http://*, 1, 32)
  271.   }
  272.   if ($nick == %otcgpgbot && %otcgpgdl == false) {
  273.     /otcgpg_wget $wildtok($1-, http://*, 1, 32)
  274.   }
  275. }
  276.  
  277. on *:TEXT:$(You are now authenticated for user %otcgpguser $+ *):?: {
  278.   if ($nick == %otcgpgbot) {
  279.     /msg %otcgpgbot ;;voiceme
  280.     echo $color(info) -st * [OTCgpg] Successfully authenticated to %otcgpgbot . .
  281.   }
  282. }
  283.  
  284. alias otcgpg_findgpg {
  285.   if ($isfile(C:\Program Files\GNU\GnuPG\gpg.exe)) {
  286.     set %otcgpgpath "C:\Program Files\GNU\GnuPG\gpg.exe"
  287.     echo $color(info) -st * [OTCgpg] GPG found at C:\Program Files\GNU\GnuPG\
  288.   }
  289.   elseif ($isfile(C:\Program Files\GNU\GnuPG\pub\gpg.exe)) {
  290.     set %otcgpgpath "C:\Program Files\GNU\GnuPG\pub\gpg.exe"
  291.     echo $color(info) -st * [OTCgpg] GPG found at C:\Program Files\GNU\GnuPG\pub\
  292.   }
  293.   elseif ($isfile(C:\Program Files (x86)\GNU\GnuPG\gpg.exe)) {
  294.     set %otcgpgpath "C:\Program Files (x86)\GNU\GnuPG\gpg.exe"
  295.     echo $color(info) -st * [OTCgpg] GPG found at C:\Program Files (x86)\GNU\GnuPG\
  296.   }
  297.   elseif ($isfile(C:\Program Files (x86)\GNU\GnuPG\pub\gpg.exe)) {
  298.     set %otcgpgpath "C:\Program Files (x86)\GNU\GnuPG\pub\gpg.exe"
  299.     echo $color(info) -st * [OTCgpg] GPG found at C:\Program Files (x86)\GNU\GnuPG\pub\
  300.   }
  301.   else {
  302.     set %otcgpgpath $qt($$?="Please specify the full path/location of gpg.exe:")
  303.   }
  304.  
  305.   if ($isfile(%otcgpgpath)) {
  306.     echo $color(info) -st * [OTCgpg] Using gpg.exe from %otcgpgpath .
  307.   }
  308.   else {
  309.     echo $color(info) -st * [OTCgpg] Unable to find GPG. Please try again, or re-load the script by typing /load -rs $script
  310.   }    
  311. }
  312.  
  313. alias otcgpg_decrypt {
  314.   var %in = $scriptdir $+ $1
  315.   var %out = $scriptdir $+ stdout.txt
  316.   if (%otcgpgpass == $null) {
  317.     var %cmd = -w cmd /C %otcgpgpath --yes --decrypt %in > %out
  318.     echo $color(info) -st * [OTCgpg] You will be prompted by GPG.exe for your password.
  319.   }
  320.   else {
  321.     var %cmd = -wnh cmd /C echo $cryptoid(%otcgpgpass,d) $+ $chr(124) %otcgpgpath --batch --yes --passphrase-fd 0 --decrypt %in > %out
  322.   }
  323.   xrun %cmd
  324.   .timer 1 10 /otcgpg_everify %out
  325. }
  326.  
  327. alias otcgpg_everify {
  328.   if ($isfile($1)) {
  329.     var %s = $read($1)
  330.     /msg %otcgpgbot ;;everify %s
  331.     .remove $1
  332.     if (%otcgpgdl == false) {
  333.       .remove $scriptdir $+ otcgpgkey.txt
  334.     }
  335.   }
  336.   else {
  337.     .timer 1 10 otcgpg_everify $1
  338.     echo $color(info) -st * [OTCgpg] Unable to decrypt the OTP. Incorrect password or there was an error downloading.
  339.   }
  340. }
  341.  
  342. alias otcgpg_download {
  343.   var %socket $+(otcdl,$chr(46),$nopath($1))
  344.   if (!$sock(%socket)) {
  345.     sockopen %socket $gettok($1,2,47) 80
  346.     sockmark %socket HEAD $gettok($1,2,47) $+($chr(47),$gettok($1,3,47),$chr(47),$gettok($1,4,47))
  347.     echo $color(info) -st * [OTCgpg] Beginning to retrieve OTP.
  348.   }
  349.   else {
  350.     echo $color(info) -st * [OTCgpg] Socket already in use.
  351.   }
  352. }
  353.  
  354. alias verify {
  355.   /msg %otcgpgbot ;;eauth %otcgpguser
  356. }
  357.  
  358. alias otcgpg_wget {
  359.   xrun -wnh cmd /C %otcgpgwgetpath -O $scriptdir $+ otcgpgkey.txt $1
  360.   otcgpg_decrypt otcgpgkey.txt
  361. }
  362.  
  363. alias xrun {
  364.   var %a = $ticks, %n = 5, %c = $1-, %b = false
  365.   if -* iswm $1 {
  366.     %c = $2-
  367.     if w isin $1 { %b = true }
  368.     if $regex($1,/((?<=r)[0-9]+|[hnx])/i) { %n = $replace($regml(1),h,0,n,2,x,3) }
  369.   }
  370.   .comopen %a WScript.Shell
  371.   if !$comerr { .comclose %a $com(%a,Run,3,bstr,%c,uint,%n,bool,%b) }
  372. }
  373.  
  374. alias cryptoid {
  375.   if ($2 == e) {
  376.     var %i = 1, %s = $replace($1-, $chr(32), $chr(1)), %r
  377.     while (%i <= $len($1-)) {
  378.       %r = $instok(%r, $base($calc($asc($mid(%s, %i, 1)) * %i), 10, 16), $calc($numtok(%r, 46) + 1), 46)    
  379.       inc %i
  380.     }
  381.     return %r
  382.   }
  383.   elseif ($2 == d) {
  384.     var %i = 1, %x = $numtok($1-, 46), %r
  385.     while (%i <= %x) {
  386.       %r = $+(%r, $chr($calc($base($gettok($1-, %i, 46), 16, 10) / %i)))
  387.       inc %i    
  388.     }
  389.     return $replace(%r, $chr(1), $chr(32))
  390.     else echo $color(info) -st [OTGgpg] Insufficient parameters.
  391.   }
  392. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement