Advertisement
Oasiz

Oasiz IRCX API v2 Auth

Nov 16th, 2012
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 4.40 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;;;;;;; Oasiz IRCX Authentication ;;;;;;;;;
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4.  
  5. ;; VERSION  1.0.9
  6. ;; AUTHOR   Rob Hildyard
  7. ;; DATE     15.11.15
  8. ;; SITE     www.oasiz.com
  9. ;; DATA     chat.oasiz.net/chat_api_key
  10.  
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12.  
  13. ;; Callback codes - allows developers to "hook" into this script by adding an api_callback alias
  14.  
  15. ;; 1 = Loading API data
  16. ;; 2 = Successful API authcode load
  17. ;; 3 = API challenge response
  18. ;; 6 = API Data/Input error
  19. ;; 7 = API Authentication Error
  20. ;; 8 = IRCX Authentication fail
  21.  
  22. ;; API Auth Encryption
  23.  
  24. ;hmacsha1 by Ford_Lawnmower irc.GeekShed.net #Script-Help
  25. ;Syntax hmacsha1 key message or $hmacsha1(key,message)
  26. alias hmacsha1 {
  27.   var %key $1, %data $2
  28.   bset -c &key 1 $regsubex(%key,/(.)/g, $asc(\1) $chr(32))
  29.   bset -c &data 1 $regsubex(%data,/(.)/g, $asc(\1) $chr(32))
  30.   if ($bvar(&key,0) > 64) bset -c &key 1 $hex2chr($sha1(&key,1))
  31.   bset -c &ipad 1 $xorall($str($+(54,$chr(32)),64),$bvar(&key,1-))
  32.   bset -c &opad 1 $xorall($str($+(92,$chr(32)),64),$bvar(&key,1-))
  33.   bcopy &ipad $calc($bvar(&ipad,0) + 1) &data 1 -1
  34.   bset -c &ipad 1 $hex2chr($sha1(&ipad,1))
  35.   bcopy &opad $calc($bvar(&opad,0) + 1) &ipad 1 -1
  36.   bset -c &return 1 $hex2chr($sha1(&opad,1))
  37.   noop $encode(&return, mb)
  38.   $iif($isid,return,$iif(#,say,echo -a)) $bvar(&return, 1-).text
  39. }
  40.  
  41. alias -l hex2chr { return $regsubex($1-,/(.{2})/g, $base(\t,16,10) $chr(32)) }
  42.  
  43. alias -l xorall {
  44.   var %p $1, %k $2, %end $iif($regex($1,/([\d]{1,})/g) > $regex($2,/([\d]{1,})/g),$v1,$v2)
  45.   return $regsubex($str(.,%end),/(.)/g,$+($xor($iif($gettok(%p,\n,32),$v1,0),$iif($gettok(%k,\n,32),$v1,0)),$chr(32)))
  46. }
  47.  
  48. alias access_token {
  49.   ;; Returns valid access token in JSON format
  50.   ;; Use md5 because certain characters fail in URLs
  51.   set %_oa.api_time $ctime
  52.   var %json $chr(123) $+ "timestamp": $+ %_oa.api_time $+ $chr(125)
  53.   return $md5($hmacsha1(%_oa.api_pass,%json))
  54. }
  55.  
  56. ;; Set API Data
  57.  
  58. alias api {
  59.   if ( $1 == add ) {
  60.     ;; /API ADD <API_KEY> <API_PASSWORD>
  61.     if ($len($2) != 36 || $len($3) != 32) { $callback(6, API Data/Input error) | return }
  62.     set %_oa.api_key $2
  63.     set %_oa.api_pass $3
  64.     $callback(1, Oasiz API data set. Aquiring IRCX AUTH data..)
  65.   }
  66.   $api_call(1)
  67. }
  68.  
  69. ;; IRCx AUTH
  70.  
  71. alias is_oasiz {
  72.   if (96.47.35.* iswm $server) return $true
  73.   return $false
  74. }
  75.  
  76. alias api_call {
  77.   if ( $1 === 1 ) {
  78.     set %_oa.api_call ircx_authcode
  79.   }
  80.   else {
  81.     set %_oa.api_query $2
  82.     set %_oa.api_call ircx_challenge
  83.   }
  84.   sockopen oasiz $+ $rand(000,999) www.oasiz.com 80
  85. }
  86.  
  87. on ^*:logon:*: {
  88.   if (!$is_oasiz) return
  89.   if (%_oa.api_pass === $null) { $callback(6, API Data/Input error) | halt }
  90.   .raw MODE ISIRCX
  91.   .halt
  92. }
  93.  
  94. raw auth:*: {
  95.   if (!$is_oasiz) return
  96.   if ($2 === S) {
  97.     if ($3 === OK) {
  98.       .raw -q AUTH GateKeeperPassport S : $+ %_oa.authcode
  99.     }
  100.     else {
  101.       set %_oa.challengeType 1
  102.       $api_call(2, $remove($3,OASSP000000))
  103.     }
  104.   }
  105.   .halt
  106. }
  107.  
  108. raw 800:*:{
  109.   if ($2 === 0) && ($is_oasiz) {
  110.     .raw -q AUTH GateKeeperPassport I :OASSP000000X1A
  111.     .halt
  112.   }
  113. }
  114.  
  115. alias auth_fail {
  116.   .disconnect
  117.   $callback(8, $1)
  118. }
  119.  
  120. raw 910:*:{
  121.   ;; Authentication failed
  122.   $auth_fail(910)
  123.   .halt
  124. }
  125.  
  126. raw 911:*:{
  127.   ;; Authentication suspended for this IP
  128.   $auth_fail(911)
  129.   .halt
  130. }
  131.  
  132. on *:sockopen:oasiz*: {
  133.   sockwrite -n $sockname GET /api?api_key= $+ %_oa.api_key $+ &access_token= $+ $access_token() $+ &timestamp= $+ %_oa.api_time $+ &api_call= $+ %_oa.api_call $+ &query= $+ %_oa.api_query HTTP/1.1 $+ $crlf $+ host: www.oasiz.com $+ $crlf $+ Connection: close $str($crlf,2)
  134. }
  135.  
  136. alias callback {
  137.   if ($isalias(oasiz.api.callback)) {
  138.     ;; We have a callback script. Lets use it
  139.     $oasiz.api.callback($1, $2-)
  140.   }
  141.   else {
  142.     ;; No callback alias detected, echo data.
  143.     echo -s $2-
  144.   }
  145. }
  146.  
  147. on *:sockread:oasiz*: {
  148.   if ($sockerr > 0) return
  149.   var %z | sockread %z
  150.   while ($sockbr > 0) {
  151.     tokenize 32 %z
  152.     if ($regex($1-,/challenge": "(.*)"/)) { set %_oa.challengeCode $regml(1) | $iif(%_oa.challengeType == 1,.RAW -q AUTH GateKeeperPassport S :OASSP000000 $+ $regml(1),) | $callback(3, $regml(1)) | return }
  153.     if ($regex($1-,/authcode": "(.*)"/)) { set %_oa.authcode $regml(1) | $callback(2, $regml(1)) | return }
  154.     if ($regex($1-,/"message": "(.*)"/)) { $callback(7, $regml(1)) | return }
  155.     return
  156.   }
  157.   sockread %z
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement