Search the Community
Showing results for tags 'pastebin; udf;'.
-
Hi All, Please see code attached for my first UDF Attempt, I needed some functions for pastebin so decided to clean them up a bit and share with you guys. You need to add your Pastebin Developer Key to the top of the UDF for functionality. Hope someone finds these useful. You will need the WinHttp.au3 UDF to make this work. https://code.google.com/p/autoit-winhttp/downloads/list #Include-Once #include <WinHttp.au3> ; #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, "<paste_key>(.*?)</paste_key>", 3) $vPasteDate = StringRegExp($vRequest, "<paste_date>(.*?)</paste_date>", 3) $vPasteTitle = StringRegExp($vRequest, "<paste_title>(.*?)</paste_title>", 3) $vPasteSize = StringRegExp($vRequest, "<paste_size>(.*?)</paste_size>", 3) $vPasteExpiry = StringRegExp($vRequest, "<paste_expire_date>(.*?)</paste_expire_date>", 3) $vPastePrivate = StringRegExp($vRequest, "<paste_private>(.*?)</paste_private>", 3) $vPasteFormatL = StringRegExp($vRequest, "<paste_format_long>(.*?)</paste_format_long>", 3) $vPasteFormatS = StringRegExp($vRequest, "<paste_format_short>(.*?)</paste_format_short>", 3) $vPasteURL = StringRegExp($vRequest, "<paste_url>(.*?)</paste_url>", 3) $vPasteHits = StringRegExp($vRequest, "<paste_hits>(.*?)</paste_hits>", 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 Example #Include <Pastebin.au3> #include <Array.au3> _PB_Open() ;~ Create A New Paste And Return URL To Console $vPaste = _CreatePaste("This is a test paste", "Title of Test Paste") ConsoleWrite("Created Paste: " & $vPaste & @CRLF) ;~ Get Trending Pastes And Show in _ArrayDisplay $vTrends = _ListTrendingPastes() _ArrayDisplay($vTrends) ;~ Print Paste To Console $RawPaste = _GetRawPaste("http://pastebin.com/8sTHzAD7") ConsoleWrite("Raw Paste: " & $RawPaste) _PB_Close()