#Include-Once #include ; #INDEX# ========================================================================================= ; Title .........: Pastebin UDF ; AutoIt Version : 3.3.8++ ; Language ..... : English ; Description ...: Functions for use with Pastebin.com API ; Author(s) .....: mrflibblehat (danielcarroll@gmail.com) ; ================================================================================================= ; #GLOBALS# ===================================================================================== Global Const $vPasteBin = "pastebin.com" ;~ PasteBin Website Global Const $vAPIDevKey = "" ;~ Obtain The Developer Key From Pastebin Global $vOpen = 0, $vConnect = 0 ; =============================================================================================== ; #CURRENT# ======================================================================================= ;_PB_Open ;_PB_Close ;_CreatePaste ;_DeletePaste ;_CreateAPIUserKey ;_ListUserPastes ;_ListTrendingPastes ;_UserDetails ;_GetRawPaste ; ================================================================================================= ; #FUNCTION# ==================================================================================================================== ; Name...........: _PB_Open ; Description ...: Create Session and Connection Handle ; Syntax.........: _PB_Open ; Return values .: Failure - Returns 0 and Sets @Error: ; |@error = 1 - Error Opening WinHTTP Handle ; |@error = 2 - Error Opening WinHTTPConnect Handle ; Author ........: mrflibblehat (danielcarroll@gmail.com) ; =============================================================================================================================== Func _PB_Open() $vOpen = _WinHttpOpen() if (@error) then Return SetError(1, 0, "Error Opening WinHTTP Handle") $vConnect = _WinHttpConnect($vOpen, $vPasteBin) if (@error) then Return SetError(2, 0, "Error Opening WinHTTPConnect Handle") EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _PB_Close ; Description ...: Close Session and Connection Handle ; Syntax.........: _PB_Close ; Author ........: mrflibblehat (danielcarroll@gmail.com) ; =============================================================================================================================== Func _PB_Close() _WinHttpCloseHandle($vConnect) _WinHttpCloseHandle($vOpen) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _CreatePaste ; Description ...: Creates a new paste and returns pastebin link ; Syntax.........: _CreatePaste($vPasteCode, $vPasteName[, $vPasteFormat = "text"[, $vPublicity = 1[, $vPasteExpireDate = "N" [, $vAPIUserKey = ""]]]] ) ; Parameters ....: $vPasteCode - Put Paste Code Here ; $vPasteName - Name of Your Paste ; $vPasteFormat - Set Syntax Highlighting Format (autoit, php, c, c++, vb, html etc) ; $vPublicity - Set The Publicity of Your Paste (0 = Public, 1 = Private, 2 = Unlisted) ; $vPasteExpireDate - Set The Paste Expiry Date (N = Never, 10M = 10 Minutes, 1D = 1 Day, 1W = 1 Week etc) ; $vAPIUserKey - To Paste as a User, Only if You Have Created an API User Key (See _CreateAPIUserKey) ; Return values .: Success - Returns Pastebin Paste Link ; Author ........: mrflibblehat (danielcarroll@gmail.com) ; =============================================================================================================================== Func _CreatePaste($vPasteCode, $vPasteName, $vPasteFormat = "text", $vPublicity = 1, $vPasteExpireDate = "N", $vAPIUserKey = "") 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) Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") if (@error) then Return SetError(3, 0, "Unable To Send Request") Return SetError(0, 0, $vRequest) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _CreateAPIUserKey ; Description ...: Creates an API User Key ; Syntax.........: _CreateAPIUserKey($vUsername, $vPassword) ; Parameters ....: $vUsername - Pastebin Username ; $vPassword - Pastebin Password ; Return values .: Success - Returns Pastebin API User Key ; Author ........: mrflibblehat (danielcarroll@gmail.com) ; =============================================================================================================================== Func _CreateAPIUserKey($vUsername, $vPassword) Local $sData = ("api_dev_key=" & $vAPIDevKey & "&api_user_name=" & $vUsername & "&api_user_password=" & $vPassword) Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") if (@error) then Return SetError(3, 0, "Unable To Send Request") Return SetError(0, 0, $vRequest) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _ListUserPastes ; Description ...: List Pastes by Given API User Key ; Syntax.........: _CreateAPIUserKey($vAPIUserKey[, $vAPIResultsLimit = 50]) ; Parameters ....: $vAPIUserKey - Pastebin API User Key ; $vAPIResultsLimit - Limit Results Displayed ; Return values .: Success - Returns List of Pastebin Pastes ; Author ........: mrflibblehat (danielcarroll@gmail.com) ; =============================================================================================================================== Func _ListUserPastes($vAPIUserKey, $vAPIResultsLimit = 50) Local $sData = ("api_option=list&api_user_key=" & $vAPIUserKey &"&api_dev_key=" & $vAPIDevKey & "&api_results_limit=" & $vAPIResultsLimit) Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") if (@error) then Return SetError(3, 0, "Unable To Send Request") Return SetError(0, 0, $vRequest) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _ListTrendingPastes ; Description ...: Creates an API User Key ; Syntax.........: _ListTrendingPastes() ; Parameters ....: ; Return values .: Success - Returns a 0 based array showing top trends ; Author ........: mrflibblehat (danielcarroll@gmail.com) ; =============================================================================================================================== Func _ListTrendingPastes() Local $vDataArr[18][10] Local $sData = ("api_option=trends&api_dev_key=" & $vAPIDevKey) Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") if (@error) then Return SetError(3, 0, "Unable To Send Request") $vPasteKey = StringRegExp($vRequest, "(.*?)", 3) $vPasteDate = StringRegExp($vRequest, "(.*?)", 3) $vPasteTitle = StringRegExp($vRequest, "(.*?)", 3) $vPasteSize = StringRegExp($vRequest, "(.*?)", 3) $vPasteExpiry = StringRegExp($vRequest, "(.*?)", 3) $vPastePrivate = StringRegExp($vRequest, "(.*?)", 3) $vPasteFormatL = StringRegExp($vRequest, "(.*?)", 3) $vPasteFormatS = StringRegExp($vRequest, "(.*?)", 3) $vPasteURL = StringRegExp($vRequest, "(.*?)", 3) $vPasteHits = StringRegExp($vRequest, "(.*?)", 3) For $i = 0 to 17 $vDataArr[$i][0] = $vPasteKey[$i] ;~ Paste Key $vDataArr[$i][1] = $vPasteDate[$i] ;~ Paste Date $vDataArr[$i][2] = $vPasteTitle[$i] ;~ Paste Title $vDataArr[$i][3] = $vPasteSize[$i] ;~ Paste Size (KB) $vDataArr[$i][4] = $vPasteExpiry[$i] ;~ Paste Expiry Time $vDataArr[$i][5] = $vPastePrivate[$i] ;~ Paste Publicity $vDataArr[$i][6] = $vPasteFormatL[$i] ;~ Paste Format Long $vDataArr[$i][7] = $vPasteFormatS[$i] ;~ Paste Formate Short $vDataArr[$i][8] = $vPasteURL[$i] ;~ Paste URL $vDataArr[$i][9] = $vPasteHits[$i] ;~ Paste Hits Next Return SetError(0, 0, $vDataArr) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _DeletePaste ; Description ...: Delete a Given Users Paste ; Syntax.........: _DeletePaste($vAPIUserKey, $vPasteKey) ; Parameters ....: $vAPIUserKey - Pastebin API User Key ; $vPasteKey - Paste Key, Obtained From _ListUserPastes Function ; Return values .: Success - Deletes Paste Returns "Paste Removed" ; Author ........: mrflibblehat (danielcarroll@gmail.com) ; =============================================================================================================================== Func _DeletePaste($vAPIUserKey, $vPasteKey) Local $sData = ("api_option=delete&api_user_key=" & $vAPIUserKey & "&api_dev_key=" & $vAPIDevKey & "&api_paste_key=" & $vPasteKey) Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") if (@error) then Return SetError(3, 0, "Unable To Send Request") Return SetError(0, 0, $vRequest) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _UserDetails ; Description ...: Delete a Given Users Paste ; Syntax.........: _UserDetails($vAPIUserKey) ; Parameters ....: $vAPIUserKey - Pastebin API User Key ; Return values .: Success - Returns User Details ; Author ........: mrflibblehat (danielcarroll@gmail.com) ; =============================================================================================================================== Func _UserDetails($vAPIUserKey) Local $sData = ("api_option=userdetails&api_user_key=" & $vAPIUserKey & "&api_dev_key=" & $vAPIDevKey) Local $vRequest = _WinHttpSimpleRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") if (@error) then Return SetError(3, 0, "Unable To Send Request") Return SetError(0, 0, $vRequest) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetRawPaste ; Description ...: Delete a Given Users Paste ; Syntax.........: _GetRawPaste($vPasteUrl) ; Parameters ....: $vPasteUrl - Pastebin URL ; Return values .: Success - Returns Paste ; Author ........: mrflibblehat (danielcarroll@gmail.com) ; =============================================================================================================================== Func _GetRawPaste($vPasteUrl) $vPasteKey = StringRegExp($vPasteUrl, "pastebin.com/(\H+)", 3) if (@error) then Return SetError(3, 0, "Unable To Read URL") Local $vRequest = _WinHttpSimpleRequest($vConnect, "GET", "/raw.php?i=" & $vPasteKey[0]) if (@error) then Return SetError(3, 0, "Unable To Connect To URL") Return SetError(0, 0, $vRequest) EndFunc