legend Posted November 15, 2017 Share Posted November 15, 2017 Has anybody had luck making private posts to pastebin using this UDF? using the flag 1 or 2 won't make it private Link to comment Share on other sites More sharing options...
legend Posted November 16, 2017 Author Share Posted November 16, 2017 anyone had luck making a private paste with this udf :)? Link to comment Share on other sites More sharing options...
TheDcoder Posted November 16, 2017 Share Posted November 16, 2017 Are you supplying your user account's API key to the UDF? EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
legend Posted November 16, 2017 Author Share Posted November 16, 2017 50 minutes ago, TheDcoder said: Are you supplying your user account's API key to the UDF? yes, the post is being posted on pastebin, but it's public, I can't get it to be private Link to comment Share on other sites More sharing options...
Simpel Posted November 17, 2017 Share Posted November 17, 2017 (edited) IIRC your post will be pasted public if your APIUserKey is invalid. I had the same problem. Just create your apiuserkey only once (in your lifetime). Do not create it new every time you want something to post or starting your script. My problem then was there wasn’t enough time between creating and using the apiuserkey. And Pastebin support wrote to me there is no need to create the apiuserkey again and again. I show you my working script. But some things are special. First I use it with a proxy. Second my credentials are in an ini. Third I start this script with a shortcut from inside SciTE. So I pass the content (part of the script which is highlighted or the whole au3) to post via $cmdline. Fourth I use some specialties for naming my post, so don’t care hhlokwor(). Fifth this code has grown through years and my coding skills got better. But I didn’t refurbish this code so it’s a bit dirty. Number six german and english comments are mixed. Hope you will understand it anyway. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Icons\PasteBin.ico #AutoIt3Wrapper_Res_Comment=Schickt SciTE-Snippets zu Pastebin. #AutoIt3Wrapper_Res_Description=Schickt SciTE-Snippets zu Pastebin. #AutoIt3Wrapper_Res_Fileversion=1.0.0.21 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Res_LegalCopyright=Simpel #AutoIt3Wrapper_Res_Language=1031 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "WinHttp.au3" #include <Date.au3> #include <File.au3> #include <Crypt.au3> #region - Credentials Local $sInput ; Proxy server Global $sProxy = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "Proxy", "") If $sProxy ="" Then MsgBox(0, 'Fehler', "Kein Proxy in der INI gefunden.") Exit EndIf ; Proxy user Global $sUserName = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "ProxyUser", "") If $sUserName = "" Then $sInput = InputBox("Fehler", "Bitte den Proxy-Username eingeben:") IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "ProxyUser", _Encrypt($sInput)) $sUserName = $sInput Else $sUserName = _Decrypt($sUserName) EndIf ; Proxy password Global $sPassword = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "ProxyPass", "") If $sPassword = "" Then $sInput = InputBox("Fehler", "Bitte das Proxy-Passwort eingeben:") IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "ProxyPass", _Encrypt($sInput)) $sPassword = $sInput Else $sPassword = _Decrypt($sPassword) EndIf ; PasteBin API-Dev-Key Global $vAPIDevKey = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbApiDevKey", "") If $vAPIDevKey = "" Then $sInput = InputBox("Fehler", "Bitte den PasteBin Developer Key eingeben:") IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbApiDevKey", _Encrypt($sInput)) $vAPIDevKey = $sInput Else $vAPIDevKey = _Decrypt($vAPIDevKey) EndIf #endregion - Credentials ; Connect Pastebin Global $vOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240", $WINHTTP_ACCESS_TYPE_NAMED_PROXY, $sProxy) Global $vConnect = _WinHttpConnect($vOpen, "https://pastebin.com") Global $vRequest = _WinHttpSimpleSendRequest_ProxyAuth($vConnect) Local $sRead = _WinHttpSimpleReadData($vRequest) Local $sProxyTrigger = StringInStr($sRead, "<title>Pastebin.com") If $sProxyTrigger > 0 Then ConsoleWrite("+Proxy-Trigger: OK" & @CRLF) Else ConsoleWrite("!Proxy-Trigger: FAILED" & @CRLF) EndIf ; API-User-Key Global $vAPIUserKey = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbApiUserKey", "") If $vAPIUserKey = "" Then $vAPIUserKey = _CreateAPIUserKey() Else $vAPIUserKey = _Decrypt($vAPIUserKey) EndIf ; API-User-Key testen Local $sDetails Local $bApiUserKey = False While $bApiUserKey = False $sDetails = _UserDetails() ; Testen, ob API_User_Key gilt If StringInStr($sDetails, "Bad API request, invalid api_user_key") Then _CreateAPIUserKey() Else Local $aDetails = StringRegExp($sDetails, "<user_name>YOUR-USERNAME-HERE</user_name>", 3) ; YOUR USERNAME HERE ############################################################## If @error Then MsgBox(0, 'Fehler', "Kann keine User-Details auslesen. Programm wird beendet." & @CRLF & @CRLF & "Pastebin-Meldung ist:" & @CRLF & $sDetails) ClipPut($sDetails) Exit Else $bApiUserKey = True ConsoleWrite("+API-User-Key ist gueltig." & @CRLF) EndIf EndIf WEnd ; Create name of paste Global $sTime = _Date_Time_GetLocalTime() $sTime = _Date_Time_SystemTimeToDateTimeStr($sTime,1) $sTime = _TimeShort($sTime) Global $cPasteCode Global $iPasteLen Global $sNameExt = "" If $cmdline[0] = 0 Then MsgBox(0, "Fehler", "Keine Daten zum Pasten.") Exit ElseIf $cmdline[0] = 1 Then $open = FileOpen($cmdline[1], 0) $cPasteCode = FileRead($open) $iPasteLen = @extended $cPasteCode = _URIEncode($cPasteCode) $sNameExt = "F" ; Full FileClose($open) ElseIf $cmdline[2] <> "" Then Local $iTrennung = StringInStr($cmdlineraw, '" "') Local $sPureCmdline = StringTrimLeft($cmdlineraw, $iTrennung + 2) ; Schneidet an " " ab, da dann noch Leerstelle plus Anführungszeichen bleiben, müssen die auch noch weg $sPureCmdline = StringTrimRight($sPureCmdline, 1) ; da sind am Ende noch " plus vermutlich @CRLF über $iPasteLen = StringLen($sPureCmdline) $cPasteCode = _URIEncode($sPureCmdline) $sNameExt = "P" ; Part Else $open = FileOpen($cmdline[1], 0) $cPasteCode = FileRead($open) $iPasteLen = @extended $cPasteCode = _URIEncode($cPasteCode) $sNameExt = "F" ; Full FileClose($open) EndIf Local $szDrive, $szDir, $szFName, $szExt Global $aFileName = _PathSplit($cmdline[1], $szDrive, $szDir, $szFName, $szExt) Global $cPasteName = $aFileName[3] & " (" & $sTime & ") " & $sNameExt & "_" & $iPasteLen & " " & _HHLOKWOR() ConsoleWrite("+PasteName: " & $cPasteName & @CRLF) Global $cPasteFormat = "autoit" ; applescript, autoit, bash, dos, css, email, html4strict, html5, ini, php, qbasic, swift, xml, text Global $cPublicity = "2" ; 0 = Public, 1 = Unlisted, 2 = Private (only allowed in combination with api_user_key, as you have to be logged into your account to access the paste) Global $cPasteExpireDate = "N" ; N = Never, 10M = 10 Minutes, 1H = 1 Hour, 1D = 1 Day, 1W = 1 Week, 2W = 2 Weeks, 1M = 1 Month ; Create paste Local $sPaste = _CreatePaste($cPasteCode, $cPasteName, $cPasteFormat, $cPublicity, $cPasteExpireDate) ConsoleWrite("+PasteURL: " & $sPaste & @CRLF) IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Pastes", $sPaste, $cPasteName) Sleep(200) ; Prove paste If StringInStr($sPaste, "https://pastebin.com/") Then $sLastPaste = (_ListUserPastes()) If @error Then MsgBox(0, 'Fehler', "Kann die Liste der Pastes nicht abrufen.") Exit EndIf $aLastPasteUrl = StringRegExp($sLastPaste, "<paste_url>(.*?)</paste_url>", 3) If @error Then MsgBox(0, 'Fehler', "Kann keine URLs auslesen.") Exit EndIf $sLastPasteUrl = $aLastPasteUrl[0] If $sPaste = $sLastPasteUrl Then MsgBox(0, 'Erfolg', "Der letzte Transfer zu PasteBin war erfolgreich.", 2) Else MsgBox(48, 'Fehler', "Der letzte Transfer zu PasteBin ist evtl. im SPAM hängen geblieben.") EndIf Else MsgBox(48, 'Fehler', "Meldung: " & $sPaste) EndIf _WinHttpCloseHandle($vRequest) _WinHttpCloseHandle($vConnect) _WinHttpCloseHandle($vOpen) ConsoleWrite(@CRLF) Exit #Region Func Func _Encrypt($sData, $sPassword = @UserName) _Crypt_Startup() ; Start the Crypt library. Local $sReturn = _Crypt_EncryptData($sData, $sPassword, $CALG_AES_256) _Crypt_Shutdown() ; Shutdown the Crypt library. Return $sReturn EndFunc Func _Decrypt($sData, $sPassword = @UserName) _Crypt_Startup() ; Start the Crypt library. Local $sReturn = BinaryToString(_Crypt_DecryptData($sData, $sPassword, $CALG_AES_256)) _Crypt_Shutdown() ; Shutdown the Crypt library. Return $sReturn EndFunc Func _HHLOKWOR() Local $sPC = IniRead(@ScriptDir & "\HHLOKWOR.ini","Client", @ComputerName, @ComputerName) Return $sPC EndFunc Func _TimeShort($sTimeShort) Local $sDateKurz = StringTrimRight(_DateTimeFormat( $sTimeShort, 2), 4) ; z.B. 31.12. Local $sTimeKurz = _DateTimeFormat( $sTimeShort, 4) ; z.B. 23:56 Local $sTimeShortReturn = $sDateKurz & " " & $sTimeKurz ; z.B. 31.12. 23:56 Return $sTimeShortReturn EndFunc Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "") Local $nChar $sData = "" For $i = 1 To $aData[0] $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "%20" ; I change it from + to %20 Case Else $sData &= "%" & Hex($nChar, 2) EndSwitch Next Return $sData EndFunc ;==>_URIEncode Func _WinHttpSimpleSendRequest_ProxyAuth($hConnect, $sType = Default, $sPath = Default, $sReferrer = Default, $sDta = Default, $sHeader = Default) ; by trancexx Local $hRequest = _WinHttpSimpleSendSSLRequest($hConnect, $sType, $sPath, $sReferrer, $sDta, $sHeader) ; Specify the reguest If $hRequest Then Local $iStatusCode = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_STATUS_CODE) ; Query status code If $iStatusCode = $HTTP_STATUS_PROXY_AUTH_REQ Then ; Check status code Local $iSupportedSchemes, $iFirstScheme, $iAuthTarget ; Query Authorization scheme If _WinHttpQueryAuthSchemes($hRequest, $iSupportedSchemes, $iFirstScheme, $iAuthTarget) Then _WinHttpSetCredentials($hRequest, $iAuthTarget, $iFirstScheme, $sUserName, $sPassword) ; Set passed credentials _WinHttpSendRequest($hRequest) ; Send request again now _WinHttpReceiveResponse($hRequest) ; And wait for the response again EndIf EndIf EndIf Return $hRequest EndFunc #Region Parts of UDF Pastebin.au3 by mrflibblehat Func _CreatePaste($vPasteCode, $vPasteName, $vPasteFormat, $vPublicity, $vPasteExpireDate) 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) ;~ ConsoleWrite("PasteData: " & $sData & @CRLF) Local $vRequest = _WinHttpSimpleSSLRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") If @error Then ConsoleWrite("Error - Create Paste: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf If StringInStr($vRequest, "Bad API request") Then ConsoleWrite("Error - Create Paste: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf Return SetError(0, 0, $vRequest) EndFunc Func _CreateAPIUserKey() ; username Local $vUsername = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbUser", "") If $vUsername = "" Then $sInput = InputBox("Fehler", "Bitte den PasteBin Username eingeben:") IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbUser", _Encrypt($sInput)) $vUsername = $sInput Else $vUsername = _Decrypt($vUsername) EndIf ; password Local $vPassword = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbPass", "") If $vPassword = "" Then $sInput = InputBox("Fehler", "Bitte das PasteBin Passwort eingeben:") IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbPass", _Encrypt($sInput)) $vPassword = $sInput Else $vPassword = _Decrypt($vPassword) EndIf $vPassword = _URIEncode($vPassword) ; create api_dev_key Local $sData = ("api_dev_key=" & $vAPIDevKey & "&api_user_name=" & $vUsername & "&api_user_password=" & $vPassword) $vAPIUserKey = _WinHttpSimpleSSLRequest($vConnect, "POST", "/api/api_login.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") If @error Then ConsoleWrite("!Error - Create API-UserKey :" & $vAPIUserKey & @CRLF) Return SetError(3, 0, $vAPIUserKey) EndIf If StringInStr($vAPIUserKey, "Bad API request") Then ConsoleWrite("!Error - Create API-UserKey :" & $vAPIUserKey & @CRLF) Return SetError(3, 0, $vAPIUserKey) EndIf IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbApiUserKey", _Encrypt($vAPIUserKey)) ConsoleWrite("!Neuer API-User-Key erstellt: " & $vAPIUserKey & " - 3 Sekunden Wartezeit." & @CRLF) Sleep(3000) Return SetError(0, 0, $vAPIUserKey) EndFunc Func _ListUserPastes($vAPIResultsLimit = 1) Local $sData = ("api_option=list&api_user_key=" & $vAPIUserKey &"&api_dev_key=" & $vAPIDevKey & "&api_results_limit=" & $vAPIResultsLimit) Local $vRequest = _WinHttpSimpleSSLRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") If @error Then ConsoleWrite("Error - List UserPastes: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf If StringInStr($vRequest, "Bad API request") Then ConsoleWrite("Error - ListUserPastes: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf If StringInStr($vRequest, "Bad API request, invalid api_user_key") Then Return SetError(4, 0, 0) EndIf Return SetError(0, 0, $vRequest) EndFunc Func _UserDetails() Local $sData = ("api_option=userdetails&api_user_key=" & $vAPIUserKey &"&api_dev_key=" & $vAPIDevKey) Local $vRequest = _WinHttpSimpleSSLRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") If @error Then ConsoleWrite("Error - UserDetails: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf If StringInStr($vRequest, "Bad API request") Then ConsoleWrite("Error - UserDetails: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf If StringInStr($vRequest, "Bad API request, invalid api_user_key") Then Return SetError(4, 0, 0) EndIf Return SetError(0, 0, $vRequest) EndFunc #EndRegion #EndRegion Edited November 17, 2017 by Simpel typo SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
legend Posted November 17, 2017 Author Share Posted November 17, 2017 (edited) 2 hours ago, Simpel said: IIRC your post will be pasted public if your APIUserKey is invalid. I had the same problem. Just create your apiuserkey only once (in your lifetime). Do not create it new every time you want something to post or starting your script. My problem then was there wasn’t enough time between creating and using the apiuserkey. And Pastebin support wrote to me there is no need to create the apiuserkey again and again. I show you my working script. But some things are special. First I use it with a proxy. Second my credentials are in an ini. Third I start this script with a shortcut from inside SciTE. So I pass the content (part of the script which is highlighted or the whole au3) to post via $cmdline. Fourth I use some specialties for naming my post, so don’t care hhlokwor(). Fifth this code has grown through years and my coding skills got better. But I didn’t refurbish this code so it’s a bit dirty. Number six german and english comments are mixed. Hope you will understand it anyway. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Icons\PasteBin.ico #AutoIt3Wrapper_Res_Comment=Schickt SciTE-Snippets zu Pastebin. #AutoIt3Wrapper_Res_Description=Schickt SciTE-Snippets zu Pastebin. #AutoIt3Wrapper_Res_Fileversion=1.0.0.21 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Res_LegalCopyright=Simpel #AutoIt3Wrapper_Res_Language=1031 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "WinHttp.au3" #include <Date.au3> #include <File.au3> #include <Crypt.au3> #region - Credentials Local $sInput ; Proxy server Global $sProxy = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "Proxy", "") If $sProxy ="" Then MsgBox(0, 'Fehler', "Kein Proxy in der INI gefunden.") Exit EndIf ; Proxy user Global $sUserName = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "ProxyUser", "") If $sUserName = "" Then $sInput = InputBox("Fehler", "Bitte den Proxy-Username eingeben:") IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "ProxyUser", _Encrypt($sInput)) $sUserName = $sInput Else $sUserName = _Decrypt($sUserName) EndIf ; Proxy password Global $sPassword = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "ProxyPass", "") If $sPassword = "" Then $sInput = InputBox("Fehler", "Bitte das Proxy-Passwort eingeben:") IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "ProxyPass", _Encrypt($sInput)) $sPassword = $sInput Else $sPassword = _Decrypt($sPassword) EndIf ; PasteBin API-Dev-Key Global $vAPIDevKey = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbApiDevKey", "") If $vAPIDevKey = "" Then $sInput = InputBox("Fehler", "Bitte den PasteBin Developer Key eingeben:") IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbApiDevKey", _Encrypt($sInput)) $vAPIDevKey = $sInput Else $vAPIDevKey = _Decrypt($vAPIDevKey) EndIf #endregion - Credentials ; Connect Pastebin Global $vOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240", $WINHTTP_ACCESS_TYPE_NAMED_PROXY, $sProxy) Global $vConnect = _WinHttpConnect($vOpen, "https://pastebin.com") Global $vRequest = _WinHttpSimpleSendRequest_ProxyAuth($vConnect) Local $sRead = _WinHttpSimpleReadData($vRequest) Local $sProxyTrigger = StringInStr($sRead, "<title>Pastebin.com") If $sProxyTrigger > 0 Then ConsoleWrite("+Proxy-Trigger: OK" & @CRLF) Else ConsoleWrite("!Proxy-Trigger: FAILED" & @CRLF) EndIf ; API-User-Key Global $vAPIUserKey = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbApiUserKey", "") If $vAPIUserKey = "" Then $vAPIUserKey = _CreateAPIUserKey() Else $vAPIUserKey = _Decrypt($vAPIUserKey) EndIf ; API-User-Key testen Local $sDetails Local $bApiUserKey = False While $bApiUserKey = False $sDetails = _UserDetails() ; Testen, ob API_User_Key gilt If StringInStr($sDetails, "Bad API request, invalid api_user_key") Then _CreateAPIUserKey() Else Local $aDetails = StringRegExp($sDetails, "<user_name>YOUR-USERNAME-HERE</user_name>", 3) ; YOUR USERNAME HERE ############################################################## If @error Then MsgBox(0, 'Fehler', "Kann keine User-Details auslesen. Programm wird beendet." & @CRLF & @CRLF & "Pastebin-Meldung ist:" & @CRLF & $sDetails) ClipPut($sDetails) Exit Else $bApiUserKey = True ConsoleWrite("+API-User-Key ist gueltig." & @CRLF) EndIf EndIf WEnd ; Create name of paste Global $sTime = _Date_Time_GetLocalTime() $sTime = _Date_Time_SystemTimeToDateTimeStr($sTime,1) $sTime = _TimeShort($sTime) Global $cPasteCode Global $iPasteLen Global $sNameExt = "" If $cmdline[0] = 0 Then MsgBox(0, "Fehler", "Keine Daten zum Pasten.") Exit ElseIf $cmdline[0] = 1 Then $open = FileOpen($cmdline[1], 0) $cPasteCode = FileRead($open) $iPasteLen = @extended $cPasteCode = _URIEncode($cPasteCode) $sNameExt = "F" ; Full FileClose($open) ElseIf $cmdline[2] <> "" Then Local $iTrennung = StringInStr($cmdlineraw, '" "') Local $sPureCmdline = StringTrimLeft($cmdlineraw, $iTrennung + 2) ; Schneidet an " " ab, da dann noch Leerstelle plus Anführungszeichen bleiben, müssen die auch noch weg $sPureCmdline = StringTrimRight($sPureCmdline, 1) ; da sind am Ende noch " plus vermutlich @CRLF über $iPasteLen = StringLen($sPureCmdline) $cPasteCode = _URIEncode($sPureCmdline) $sNameExt = "P" ; Part Else $open = FileOpen($cmdline[1], 0) $cPasteCode = FileRead($open) $iPasteLen = @extended $cPasteCode = _URIEncode($cPasteCode) $sNameExt = "F" ; Full FileClose($open) EndIf Local $szDrive, $szDir, $szFName, $szExt Global $aFileName = _PathSplit($cmdline[1], $szDrive, $szDir, $szFName, $szExt) Global $cPasteName = $aFileName[3] & " (" & $sTime & ") " & $sNameExt & "_" & $iPasteLen & " " & _HHLOKWOR() ConsoleWrite("+PasteName: " & $cPasteName & @CRLF) Global $cPasteFormat = "autoit" ; applescript, autoit, bash, dos, css, email, html4strict, html5, ini, php, qbasic, swift, xml, text Global $cPublicity = "2" ; 0 = Public, 1 = Unlisted, 2 = Private (only allowed in combination with api_user_key, as you have to be logged into your account to access the paste) Global $cPasteExpireDate = "N" ; N = Never, 10M = 10 Minutes, 1H = 1 Hour, 1D = 1 Day, 1W = 1 Week, 2W = 2 Weeks, 1M = 1 Month ; Create paste Local $sPaste = _CreatePaste($cPasteCode, $cPasteName, $cPasteFormat, $cPublicity, $cPasteExpireDate) ConsoleWrite("+PasteURL: " & $sPaste & @CRLF) IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Pastes", $sPaste, $cPasteName) Sleep(200) ; Prove paste If StringInStr($sPaste, "https://pastebin.com/") Then $sLastPaste = (_ListUserPastes()) If @error Then MsgBox(0, 'Fehler', "Kann die Liste der Pastes nicht abrufen.") Exit EndIf $aLastPasteUrl = StringRegExp($sLastPaste, "<paste_url>(.*?)</paste_url>", 3) If @error Then MsgBox(0, 'Fehler', "Kann keine URLs auslesen.") Exit EndIf $sLastPasteUrl = $aLastPasteUrl[0] If $sPaste = $sLastPasteUrl Then MsgBox(0, 'Erfolg', "Der letzte Transfer zu PasteBin war erfolgreich.", 2) Else MsgBox(48, 'Fehler', "Der letzte Transfer zu PasteBin ist evtl. im SPAM hängen geblieben.") EndIf Else MsgBox(48, 'Fehler', "Meldung: " & $sPaste) EndIf _WinHttpCloseHandle($vRequest) _WinHttpCloseHandle($vConnect) _WinHttpCloseHandle($vOpen) ConsoleWrite(@CRLF) Exit #Region Func Func _Encrypt($sData, $sPassword = @UserName) _Crypt_Startup() ; Start the Crypt library. Local $sReturn = _Crypt_EncryptData($sData, $sPassword, $CALG_AES_256) _Crypt_Shutdown() ; Shutdown the Crypt library. Return $sReturn EndFunc Func _Decrypt($sData, $sPassword = @UserName) _Crypt_Startup() ; Start the Crypt library. Local $sReturn = BinaryToString(_Crypt_DecryptData($sData, $sPassword, $CALG_AES_256)) _Crypt_Shutdown() ; Shutdown the Crypt library. Return $sReturn EndFunc Func _HHLOKWOR() Local $sPC = IniRead(@ScriptDir & "\HHLOKWOR.ini","Client", @ComputerName, @ComputerName) Return $sPC EndFunc Func _TimeShort($sTimeShort) Local $sDateKurz = StringTrimRight(_DateTimeFormat( $sTimeShort, 2), 4) ; z.B. 31.12. Local $sTimeKurz = _DateTimeFormat( $sTimeShort, 4) ; z.B. 23:56 Local $sTimeShortReturn = $sDateKurz & " " & $sTimeKurz ; z.B. 31.12. 23:56 Return $sTimeShortReturn EndFunc Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "") Local $nChar $sData = "" For $i = 1 To $aData[0] $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "%20" ; I change it from + to %20 Case Else $sData &= "%" & Hex($nChar, 2) EndSwitch Next Return $sData EndFunc ;==>_URIEncode Func _WinHttpSimpleSendRequest_ProxyAuth($hConnect, $sType = Default, $sPath = Default, $sReferrer = Default, $sDta = Default, $sHeader = Default) ; by trancexx Local $hRequest = _WinHttpSimpleSendSSLRequest($hConnect, $sType, $sPath, $sReferrer, $sDta, $sHeader) ; Specify the reguest If $hRequest Then Local $iStatusCode = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_STATUS_CODE) ; Query status code If $iStatusCode = $HTTP_STATUS_PROXY_AUTH_REQ Then ; Check status code Local $iSupportedSchemes, $iFirstScheme, $iAuthTarget ; Query Authorization scheme If _WinHttpQueryAuthSchemes($hRequest, $iSupportedSchemes, $iFirstScheme, $iAuthTarget) Then _WinHttpSetCredentials($hRequest, $iAuthTarget, $iFirstScheme, $sUserName, $sPassword) ; Set passed credentials _WinHttpSendRequest($hRequest) ; Send request again now _WinHttpReceiveResponse($hRequest) ; And wait for the response again EndIf EndIf EndIf Return $hRequest EndFunc #Region Parts of UDF Pastebin.au3 by mrflibblehat Func _CreatePaste($vPasteCode, $vPasteName, $vPasteFormat, $vPublicity, $vPasteExpireDate) 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) ;~ ConsoleWrite("PasteData: " & $sData & @CRLF) Local $vRequest = _WinHttpSimpleSSLRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") If @error Then ConsoleWrite("Error - Create Paste: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf If StringInStr($vRequest, "Bad API request") Then ConsoleWrite("Error - Create Paste: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf Return SetError(0, 0, $vRequest) EndFunc Func _CreateAPIUserKey() ; username Local $vUsername = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbUser", "") If $vUsername = "" Then $sInput = InputBox("Fehler", "Bitte den PasteBin Username eingeben:") IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbUser", _Encrypt($sInput)) $vUsername = $sInput Else $vUsername = _Decrypt($vUsername) EndIf ; password Local $vPassword = IniRead("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbPass", "") If $vPassword = "" Then $sInput = InputBox("Fehler", "Bitte das PasteBin Passwort eingeben:") IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbPass", _Encrypt($sInput)) $vPassword = $sInput Else $vPassword = _Decrypt($vPassword) EndIf $vPassword = _URIEncode($vPassword) ; create api_dev_key Local $sData = ("api_dev_key=" & $vAPIDevKey & "&api_user_name=" & $vUsername & "&api_user_password=" & $vPassword) $vAPIUserKey = _WinHttpSimpleSSLRequest($vConnect, "POST", "/api/api_login.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") If @error Then ConsoleWrite("!Error - Create API-UserKey :" & $vAPIUserKey & @CRLF) Return SetError(3, 0, $vAPIUserKey) EndIf If StringInStr($vAPIUserKey, "Bad API request") Then ConsoleWrite("!Error - Create API-UserKey :" & $vAPIUserKey & @CRLF) Return SetError(3, 0, $vAPIUserKey) EndIf IniWrite("H:\_Conrad lokal\Downloads\AutoIt3\_COX\inis\PasteBin.ini", "Credentials", "PbApiUserKey", _Encrypt($vAPIUserKey)) ConsoleWrite("!Neuer API-User-Key erstellt: " & $vAPIUserKey & " - 3 Sekunden Wartezeit." & @CRLF) Sleep(3000) Return SetError(0, 0, $vAPIUserKey) EndFunc Func _ListUserPastes($vAPIResultsLimit = 1) Local $sData = ("api_option=list&api_user_key=" & $vAPIUserKey &"&api_dev_key=" & $vAPIDevKey & "&api_results_limit=" & $vAPIResultsLimit) Local $vRequest = _WinHttpSimpleSSLRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") If @error Then ConsoleWrite("Error - List UserPastes: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf If StringInStr($vRequest, "Bad API request") Then ConsoleWrite("Error - ListUserPastes: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf If StringInStr($vRequest, "Bad API request, invalid api_user_key") Then Return SetError(4, 0, 0) EndIf Return SetError(0, 0, $vRequest) EndFunc Func _UserDetails() Local $sData = ("api_option=userdetails&api_user_key=" & $vAPIUserKey &"&api_dev_key=" & $vAPIDevKey) Local $vRequest = _WinHttpSimpleSSLRequest($vConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded") If @error Then ConsoleWrite("Error - UserDetails: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf If StringInStr($vRequest, "Bad API request") Then ConsoleWrite("Error - UserDetails: " & $vRequest & @CRLF) Return SetError(3, 0, $vRequest) EndIf If StringInStr($vRequest, "Bad API request, invalid api_user_key") Then Return SetError(4, 0, 0) EndIf Return SetError(0, 0, $vRequest) EndFunc #EndRegion #EndRegion Thanks a lot for your answer, yet i'm a little unsure of how i'd get it to work with the udf Edited November 17, 2017 by legend Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now