Skip to content

Commit

Permalink
hotfix for bypassing cloudflare protection
Browse files Browse the repository at this point in the history
  • Loading branch information
Eruyome committed Dec 22, 2016
1 parent 83d11be commit 895a94f
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Run_Only_This.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ RunAsAdmin()
}

StartSplashScreen() {
SplashTextOn, , , Merging and starting Scripts...
SplashTextOn, , 20, PoE-TradeMacro, Merging and starting Scripts...
}
2 changes: 1 addition & 1 deletion Run_without_Admin_Elevation.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ CloseScript(Name)


StartSplashScreen() {
SplashTextOn, , , Merging and starting Scripts...
SplashTextOn, , 20, PoE-TradeMacro, Merging and starting Scripts...
}
6 changes: 6 additions & 0 deletions TradeUpdates.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
The following is a list of what has been updated, starting with 1.1.0

1.3.0
================================================================================================
Hotfix for poe.trade's CloudFlare DDOS protection.
This is only a temporary solution until a more user friendly one is implemented.
Just start the script and follow instructions.

1.2.12
================================================================================================
Changed default hotkey for "Show item age" to "ctrl + e" because "ctrl + a" is the default for "select all".
Expand Down
11 changes: 11 additions & 0 deletions cookie_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; Please follow the steps here https://github.com/PoE-TradeMacro/POE-TradeMacro/issues/149#issuecomment-268639184
; for both poe.trade and currency.poe.trade
; we're working on a more user friendly solution in the meantime (no additional user interaction for this)
; example: useragent= Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
; example: cfduid=d7692e1029dac3d9b856f1c04807adcaf1482386959
; example: cfclearance=aefd126b59e0332b0e2c5750427ab11418a002fb-1482386963-604800

useragent=
cfduid=
cfclearance=

23 changes: 22 additions & 1 deletion trade_data/TradeMacro.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,12 @@ TradeFunc_DoParseClipboard()

TradeFunc_DoPostRequest(payload, openSearchInBrowser = false)
{

UserAgent := TradeGlobals.Get("UserAgent")
cfduid := TradeGlobals.Get("cfduid")
cfClearance := TradeGlobals.Get("cfClearance")
;MsgBox % UserAgent "`n" cfduid "`n" cfClearance

ComObjError(0)
Encoding := "utf-8"
;Reference in making POST requests - http://stackoverflow.com/questions/158633/how-can-i-send-an-http-post-request-to-a-server-from-excel-using-vba
Expand All @@ -1033,13 +1039,14 @@ TradeFunc_DoPostRequest(payload, openSearchInBrowser = false)
HttpObj.SetRequestHeader("Cache-Control","max-age=0")
HttpObj.SetRequestHeader("Origin","http://poe.trade")
HttpObj.SetRequestHeader("Upgrade-Insecure-Requests","1")
HttpObj.SetRequestHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36")
HttpObj.SetRequestHeader("User-Agent", UserAgent)
HttpObj.SetRequestHeader("Content-type","application/x-www-form-urlencoded")
HttpObj.SetRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
HttpObj.SetRequestHeader("Referer","http://poe.trade/")
;HttpObj.SetRequestHeader("Accept-Encoding","gzip;q=0,deflate;q=0") ; disables compression
;HttpObj.SetRequestHeader("Accept-Encoding","gzip, deflate")
;HttpObj.SetRequestHeader("Accept-Language","en-US,en;q=0.8")
HttpObj.SetRequestHeader("Cookie","__cfduid=" cfduid "; cf_clearance=" cfClearance)
HttpObj.Send(payload)
HttpObj.WaitForResponse()
html := HttpObj.ResponseText
Expand All @@ -1066,6 +1073,10 @@ TradeFunc_DoPostRequest(payload, openSearchInBrowser = false)
; Get currency.poe.trade html
; Either at script start to parse the currency IDs or when searching to get currency listings
TradeFunc_DoCurrencyRequest(currencyName = "", openSearchInBrowser = false, init = false){
UserAgent := TradeGlobals.Get("UserAgent")
cfduid := TradeGlobals.Get("cfduid")
cfClearance := TradeGlobals.Get("cfClearance")

ComObjError(0)
Encoding := "utf-8"
HttpObj := ComObjCreate("WinHttp.WinHttpRequest.5.1")
Expand All @@ -1084,6 +1095,8 @@ TradeFunc_DoCurrencyRequest(currencyName = "", openSearchInBrowser = false, init
}

HttpObj.Open("GET",Url)
HttpObj.SetRequestHeader("User-Agent", UserAgent)
HttpObj.SetRequestHeader("Cookie","__cfduid=" cfduid "; cf_clearance=" cfClearance)
HttpObj.Send()
HttpObj.WaitForResponse()
html := HttpObj.ResponseText
Expand Down Expand Up @@ -3191,4 +3204,12 @@ ReadPoeNinjaCurrencyData:
ChaosEquivalents[val.currencyTypeName] := val.chaosEquivalent
}
ChaosEquivalents["Chaos Orb"] := 1
Return

CloseCookieWindow:
Gui, Cancel
Return

OpenCookieFile:
Run, %A_ScriptDir%\cookie_data.txt
Return
56 changes: 55 additions & 1 deletion trade_data/TradeMacroInit.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ TradeGlobals.Set("CorruptedModsData", TradeFunc_ReadCorruptions())
TradeGlobals.Set("CurrencyIDs", object := {})

; get currency ids from currency.poe.trade

TradeFunc_ReadCookieData()
TradeFunc_DoCurrencyRequest("", false, true)
If (TradeOpts.DownloadDataFiles and not TradeOpts.Debug) {
TradeFunc_DownloadDataFiles()
Expand Down Expand Up @@ -879,9 +881,61 @@ TradeFunc_DownloadDataFiles() {
FileDelete, %dir%\*.bak
}

TradeFunc_ReadCookieData() {
FileRead, cookieFile, %A_ScriptDir%\cookie_data.txt
Loop, parse, cookieFile, `n`r
{
RegExMatch(A_LoopField, "i)^,", match)
If (match) {
continue
}

RegExMatch(A_LoopField, "i)(.*)\s?=", key)
RegExMatch(A_LoopField, "i)=\s?(.*)", value)

If (InStr(key1, "useragent")) {
TradeGlobals.Set("UserAgent", Trim(value1))
}
Else If (InStr(key1, "cfduid")) {
TradeGlobals.Set("cfduid", Trim(value1))
}
Else If (InStr(key1, "cfclearance")) {
TradeGlobals.Set("cfClearance", Trim(value1))
}
}

If (StrLen(TradeGlobals.Get("UserAgent")) < 1) {
ErrorLevel := 1
}
If (StrLen(TradeGlobals.Get("cfduid")) < 1) {
ErrorLevel := 1
}
If (StrLen(TradeGlobals.Get("cfClearance")) < 1) {
ErrorLevel := 1
}

If (ErrorLevel) {
WinSet, AlwaysOnTop, Off, PoE-TradeMacro
Gui, CookieWindow:Add, Text, cRed, Reading Cookie data failed!
Gui, CookieWindow:Add, Text, , As a workaround for the recent poe.trade changes we need `nUserAgent and Cloudflare cookie information.
Gui, CookieWindow:Add, Text, , This is a temporary solution until we have a better fix.

Gui, CookieWindow:Add, Text, , Please provide this information and copy it to file <cookie_data.txt>. `nThen restart the script.
Gui, CookieWindow:Add, Link, cBlue, <a href="https://github.com/PoE-TradeMacro/POE-TradeMacro/issues/149#issuecomment-268639184">Step-by-Step Tutorial</a>
Gui, CookieWindow:Add, Text, , If the script still doesn't work after this, please repeat the steps to get the `nneccessary information.

Gui, CookieWindow:Add, Button, gCloseCookieWindow, Close
Gui, CookieWindow:Add, Button, gOpenCookieFile, Open cookie file
Gui, CookieWindow:Show, w400 xCenter yCenter, Notice
ControlFocus, Close, Notice
WinWaitClose, Notice
}

}

;----------------------- SplashScreens ---------------------------------------
TradeFunc_StartSplashScreen() {
SplashTextOn, , , Initializing PoE-TradeMacro...
SplashTextOn, , 20, PoE-TradeMacro, Initializing script...
}
TradeFunc_StopSplashScreen() {
SplashTextOff
Expand Down
2 changes: 1 addition & 1 deletion trade_data/Version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TradeReleaseVersion := "1.2.12"
TradeReleaseVersion := "1.3.0"
TradeAHKVersionRequired := "1.1.24.01"

0 comments on commit 895a94f

Please sign in to comment.