Pastebin UDF


SUBMITTED BY: Guest

DATE: May 28, 2013, 8:27 a.m.

FORMAT: Text only

SIZE: 12.8 kB

HITS: 1917

  1. #Include-Once
  2. #include <WinHttp.au3>
  3. ; #INDEX# =========================================================================================
  4. ; Title .........: Pastebin UDF
  5. ; AutoIt Version : 3.3.8++
  6. ; Language ..... : English
  7. ; Description ...: Functions for use with Pastebin.com API
  8. ; Author(s) .....: mrflibblehat (danielcarroll@gmail.com)
  9. ; =================================================================================================
  10. ; #GLOBALS# =====================================================================================
  11. Global Const $vPasteBin = "pastebin.com" ;~ PasteBin Website
  12. Global Const $vAPIDevKey = "" ;~ Obtain The Developer Key From Pastebin
  13. Global $vOpen = 0, $vConnect = 0
  14. ; ===============================================================================================
  15. ; #CURRENT# =======================================================================================
  16. ;_PB_Open
  17. ;_PB_Close
  18. ;_CreatePaste
  19. ;_DeletePaste
  20. ;_CreateAPIUserKey
  21. ;_ListUserPastes
  22. ;_ListTrendingPastes
  23. ;_UserDetails
  24. ;_GetRawPaste
  25. ; =================================================================================================
  26. ; #FUNCTION# ====================================================================================================================
  27. ; Name...........: _PB_Open
  28. ; Description ...: Create Session and Connection Handle
  29. ; Syntax.........: _PB_Open
  30. ; Return values .: Failure - Returns 0 and Sets @Error:
  31. ; |@error = 1 - Error Opening WinHTTP Handle
  32. ; |@error = 2 - Error Opening WinHTTPConnect Handle
  33. ; Author ........: mrflibblehat (danielcarroll@gmail.com)
  34. ; ===============================================================================================================================
  35. Func _PB_Open()
  36. $vOpen = _WinHttpOpen()
  37. if (@error) then Return SetError(1, 0, "Error Opening WinHTTP Handle")
  38. $vConnect = _WinHttpConnect($vOpen, $vPasteBin)
  39. if (@error) then Return SetError(2, 0, "Error Opening WinHTTPConnect Handle")
  40. EndFunc
  41. ; #FUNCTION# ====================================================================================================================
  42. ; Name...........: _PB_Close
  43. ; Description ...: Close Session and Connection Handle
  44. ; Syntax.........: _PB_Close
  45. ; Author ........: mrflibblehat (danielcarroll@gmail.com)
  46. ; ===============================================================================================================================
  47. Func _PB_Close()
  48. _WinHttpCloseHandle($vConnect)
  49. _WinHttpCloseHandle($vOpen)
  50. EndFunc
  51. ; #FUNCTION# ====================================================================================================================
  52. ; Name...........: _CreatePaste
  53. ; Description ...: Creates a new paste and returns pastebin link
  54. ; Syntax.........: _CreatePaste($vPasteCode, $vPasteName[, $vPasteFormat = "text"[, $vPublicity = 1[, $vPasteExpireDate = "N" [, $vAPIUserKey = ""]]]] )
  55. ; Parameters ....: $vPasteCode - Put Paste Code Here
  56. ; $vPasteName - Name of Your Paste
  57. ; $vPasteFormat - Set Syntax Highlighting Format (autoit, php, c, c++, vb, html etc)
  58. ; $vPublicity - Set The Publicity of Your Paste (0 = Public, 1 = Private, 2 = Unlisted)
  59. ; $vPasteExpireDate - Set The Paste Expiry Date (N = Never, 10M = 10 Minutes, 1D = 1 Day, 1W = 1 Week etc)
  60. ; $vAPIUserKey - To Paste as a User, Only if You Have Created an API User Key (See _CreateAPIUserKey)
  61. ; Return values .: Success - Returns Pastebin Paste Link
  62. ; Author ........: mrflibblehat (danielcarroll@gmail.com)
  63. ; ===============================================================================================================================
  64. Func _CreatePaste($vPasteCode, $vPasteName, $vPasteFormat = "text", $vPublicity = 1, $vPasteExpireDate = "N", $vAPIUserKey = "")
  65. Local $sData = ("api_option=paste&api_user_key=" & $vAPIUserKey & "&api_paste_private=" & $vPublicity & "&api_paste_name=" & $vPasteName & "&api_paste_expire_date= " & $vPasteExpireDate & "&api_paste_format=" & $vPasteFormat & "&api_dev_key=" & $vAPIDevKey & "&api_paste_code=" & $vPasteCode)
  66. Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded")
  67. if (@error) then Return SetError(3, 0, "Unable To Send Request")
  68. Return SetError(0, 0, $vRequest)
  69. EndFunc
  70. ; #FUNCTION# ====================================================================================================================
  71. ; Name...........: _CreateAPIUserKey
  72. ; Description ...: Creates an API User Key
  73. ; Syntax.........: _CreateAPIUserKey($vUsername, $vPassword)
  74. ; Parameters ....: $vUsername - Pastebin Username
  75. ; $vPassword - Pastebin Password
  76. ; Return values .: Success - Returns Pastebin API User Key
  77. ; Author ........: mrflibblehat (danielcarroll@gmail.com)
  78. ; ===============================================================================================================================
  79. Func _CreateAPIUserKey($vUsername, $vPassword)
  80. Local $sData = ("api_dev_key=" & $vAPIDevKey & "&api_user_name=" & $vUsername & "&api_user_password=" & $vPassword)
  81. Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded")
  82. if (@error) then Return SetError(3, 0, "Unable To Send Request")
  83. Return SetError(0, 0, $vRequest)
  84. EndFunc
  85. ; #FUNCTION# ====================================================================================================================
  86. ; Name...........: _ListUserPastes
  87. ; Description ...: List Pastes by Given API User Key
  88. ; Syntax.........: _CreateAPIUserKey($vAPIUserKey[, $vAPIResultsLimit = 50])
  89. ; Parameters ....: $vAPIUserKey - Pastebin API User Key
  90. ; $vAPIResultsLimit - Limit Results Displayed
  91. ; Return values .: Success - Returns List of Pastebin Pastes
  92. ; Author ........: mrflibblehat (danielcarroll@gmail.com)
  93. ; ===============================================================================================================================
  94. Func _ListUserPastes($vAPIUserKey, $vAPIResultsLimit = 50)
  95. Local $sData = ("api_option=list&api_user_key=" & $vAPIUserKey &"&api_dev_key=" & $vAPIDevKey & "&api_results_limit=" & $vAPIResultsLimit)
  96. Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded")
  97. if (@error) then Return SetError(3, 0, "Unable To Send Request")
  98. Return SetError(0, 0, $vRequest)
  99. EndFunc
  100. ; #FUNCTION# ====================================================================================================================
  101. ; Name...........: _ListTrendingPastes
  102. ; Description ...: Creates an API User Key
  103. ; Syntax.........: _ListTrendingPastes()
  104. ; Parameters ....:
  105. ; Return values .: Success - Returns a 0 based array showing top trends
  106. ; Author ........: mrflibblehat (danielcarroll@gmail.com)
  107. ; ===============================================================================================================================
  108. Func _ListTrendingPastes()
  109. Local $vDataArr[18][10]
  110. Local $sData = ("api_option=trends&api_dev_key=" & $vAPIDevKey)
  111. Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded")
  112. if (@error) then Return SetError(3, 0, "Unable To Send Request")
  113. $vPasteKey = StringRegExp($vRequest, "<paste_key>(.*?)</paste_key>", 3)
  114. $vPasteDate = StringRegExp($vRequest, "<paste_date>(.*?)</paste_date>", 3)
  115. $vPasteTitle = StringRegExp($vRequest, "<paste_title>(.*?)</paste_title>", 3)
  116. $vPasteSize = StringRegExp($vRequest, "<paste_size>(.*?)</paste_size>", 3)
  117. $vPasteExpiry = StringRegExp($vRequest, "<paste_expire_date>(.*?)</paste_expire_date>", 3)
  118. $vPastePrivate = StringRegExp($vRequest, "<paste_private>(.*?)</paste_private>", 3)
  119. $vPasteFormatL = StringRegExp($vRequest, "<paste_format_long>(.*?)</paste_format_long>", 3)
  120. $vPasteFormatS = StringRegExp($vRequest, "<paste_format_short>(.*?)</paste_format_short>", 3)
  121. $vPasteURL = StringRegExp($vRequest, "<paste_url>(.*?)</paste_url>", 3)
  122. $vPasteHits = StringRegExp($vRequest, "<paste_hits>(.*?)</paste_hits>", 3)
  123. For $i = 0 to 17
  124. $vDataArr[$i][0] = $vPasteKey[$i] ;~ Paste Key
  125. $vDataArr[$i][1] = $vPasteDate[$i] ;~ Paste Date
  126. $vDataArr[$i][2] = $vPasteTitle[$i] ;~ Paste Title
  127. $vDataArr[$i][3] = $vPasteSize[$i] ;~ Paste Size (KB)
  128. $vDataArr[$i][4] = $vPasteExpiry[$i] ;~ Paste Expiry Time
  129. $vDataArr[$i][5] = $vPastePrivate[$i] ;~ Paste Publicity
  130. $vDataArr[$i][6] = $vPasteFormatL[$i] ;~ Paste Format Long
  131. $vDataArr[$i][7] = $vPasteFormatS[$i] ;~ Paste Formate Short
  132. $vDataArr[$i][8] = $vPasteURL[$i] ;~ Paste URL
  133. $vDataArr[$i][9] = $vPasteHits[$i] ;~ Paste Hits
  134. Next
  135. Return SetError(0, 0, $vDataArr)
  136. EndFunc
  137. ; #FUNCTION# ====================================================================================================================
  138. ; Name...........: _DeletePaste
  139. ; Description ...: Delete a Given Users Paste
  140. ; Syntax.........: _DeletePaste($vAPIUserKey, $vPasteKey)
  141. ; Parameters ....: $vAPIUserKey - Pastebin API User Key
  142. ; $vPasteKey - Paste Key, Obtained From _ListUserPastes Function
  143. ; Return values .: Success - Deletes Paste Returns "Paste Removed"
  144. ; Author ........: mrflibblehat (danielcarroll@gmail.com)
  145. ; ===============================================================================================================================
  146. Func _DeletePaste($vAPIUserKey, $vPasteKey)
  147. Local $sData = ("api_option=delete&api_user_key=" & $vAPIUserKey & "&api_dev_key=" & $vAPIDevKey & "&api_paste_key=" & $vPasteKey)
  148. Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded")
  149. if (@error) then Return SetError(3, 0, "Unable To Send Request")
  150. Return SetError(0, 0, $vRequest)
  151. EndFunc
  152. ; #FUNCTION# ====================================================================================================================
  153. ; Name...........: _UserDetails
  154. ; Description ...: Delete a Given Users Paste
  155. ; Syntax.........: _UserDetails($vAPIUserKey)
  156. ; Parameters ....: $vAPIUserKey - Pastebin API User Key
  157. ; Return values .: Success - Returns User Details
  158. ; Author ........: mrflibblehat (danielcarroll@gmail.com)
  159. ; ===============================================================================================================================
  160. Func _UserDetails($vAPIUserKey)
  161. Local $sData = ("api_option=userdetails&api_user_key=" & $vAPIUserKey & "&api_dev_key=" & $vAPIDevKey)
  162. Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded")
  163. if (@error) then Return SetError(3, 0, "Unable To Send Request")
  164. Return SetError(0, 0, $vRequest)
  165. EndFunc
  166. ; #FUNCTION# ====================================================================================================================
  167. ; Name...........: _GetRawPaste
  168. ; Description ...: Delete a Given Users Paste
  169. ; Syntax.........: _GetRawPaste($vPasteUrl)
  170. ; Parameters ....: $vPasteUrl - Pastebin URL
  171. ; Return values .: Success - Returns Paste
  172. ; Author ........: mrflibblehat (danielcarroll@gmail.com)
  173. ; ===============================================================================================================================
  174. Func _GetRawPaste($vPasteUrl)
  175. $vPasteKey = StringRegExp($vPasteUrl, "pastebin.com/(\H+)", 3)
  176. if (@error) then Return SetError(3, 0, "Unable To Read URL")
  177. Local $vRequest = _WinHttpSimpleRequest($vConnect, "GET", "/raw.php?i=" & $vPasteKey[0])
  178. if (@error) then Return SetError(3, 0, "Unable To Connect To URL")
  179. Return SetError(0, 0, $vRequest)
  180. EndFunc

comments powered by Disqus