v6.1.1: fix cloudflare in download img

This commit is contained in:
M4RKUS28 2023-09-24 19:10:13 +02:00
parent ea246e18d0
commit 8872282941
3 changed files with 84 additions and 8 deletions

View File

@ -150,7 +150,7 @@ Reply PageManager::getServerRequest(std::string protocol, std::string Url, bool
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); //follows redirection curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); //follows redirection
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); // Funktion zum Speichern des outputs in einem string curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); // Funktion zum Speichern des outputs in einem string
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); //Legt die Variable readbuffer fest curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); //Legt die Variable readbuffer fest
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"); curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT);
/*"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0" */ /*"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0" */
if(useCookies) if(useCookies)
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieFilePath.c_str()); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieFilePath.c_str());
@ -205,6 +205,7 @@ Reply PageManager::getServerRequest(std::string protocol, std::string Url, bool
res = curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); res = curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
if( res != CURLE_OK || !url ) { if( res != CURLE_OK || !url ) {
perror((std::string("\33[2K\r => Error: curl_easy_getinfo failed: ") + curl_easy_strerror(res)).c_str()); perror((std::string("\33[2K\r => Error: curl_easy_getinfo failed: ") + curl_easy_strerror(res)).c_str());
curl_easy_cleanup(curl);
return Reply("-1"); return Reply("-1");
} else } else
returnUrl=url; returnUrl=url;
@ -248,8 +249,15 @@ Reply PageManager::getServerRequest(std::string protocol, std::string Url, bool
} }




int PageManager::downLoadToFile(std::string filePath, std::string url) int PageManager::downLoadToFile(std::string filePath, std::string url, int rek_num)
{ {
if(rek_num > 15) {
if(debugMode)
std::cout << " -> EXIT(): downLoadToFile Out of trys..." << std::endl;
exit(0);
}


CURL *curl_handle; CURL *curl_handle;
FILE *pagefile; FILE *pagefile;
CURLcode res; CURLcode res;
@ -290,11 +298,28 @@ int PageManager::downLoadToFile(std::string filePath, std::string url)
/* send all data to this function */ /* send all data to this function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);


//Sock5Proxy für Curl //Settings
if(sock5Proxy != "") if(sock5Proxy != "") {

curl_easy_setopt(curl_handle, CURLOPT_PROXY, sock5Proxy.c_str() ); //Sock5Proxy für Curl curl_easy_setopt(curl_handle, CURLOPT_PROXY, sock5Proxy.c_str() ); //Sock5Proxy für Curl
if(debugMode) if(debugMode)
std::cout << "\33[2K\r => INFO: Proxy:'" << sock5Proxy << "'" << std::endl; std::cout << "\33[2K\r => INFO: Proxy for download:'" << sock5Proxy << "'" << std::endl;

if(cloudflare_protec) {
if(debugMode)
std::cout << "\33[2K\r => INFO: Proxy username for cloudflare :'" << torAnmeldeNamen << ":passwd" << "'" << std::endl;
CURLcode setoptResult = curl_easy_setopt(curl_handle, CURLOPT_PROXYUSERPWD, (torAnmeldeNamen + ":passwd").c_str());
if (setoptResult != CURLE_OK) {
std::cerr << "Setting CURLOPT_URL failed: " << curl_easy_strerror(setoptResult) << std::endl;
}
}

} else {
if(debugMode)
std::cout << "\33[2K\r => INFO: Es wird kein Proxy verwendet: ADDR of PM:" << this << " -> prox: " << sock5Proxy << std::endl;
}




//User Agent //User Agent
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"); curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0");
@ -305,6 +330,10 @@ int PageManager::downLoadToFile(std::string filePath, std::string url)
//Error 404, for example => not found //Error 404, for example => not found
curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, true); curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, true);


//Against cloudflare!
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L); //follows redirection
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, USER_AGENT);

int maxTimeOut = 5; int maxTimeOut = 5;
bool failed = false; bool failed = false;
for (int timeout = 1; timeout <= maxTimeOut; ++timeout) { for (int timeout = 1; timeout <= maxTimeOut; ++timeout) {
@ -319,6 +348,7 @@ int PageManager::downLoadToFile(std::string filePath, std::string url)
sleep(1); sleep(1);
} }
} else { } else {

//Sonst ( wenns functioniert) schleife verlassen //Sonst ( wenns functioniert) schleife verlassen
break; break;
} }
@ -330,6 +360,48 @@ int PageManager::downLoadToFile(std::string filePath, std::string url)
return 4; return 4;
} }



char *url_after;
//Get Url
res = curl_easy_getinfo(curl_handle, CURLINFO_EFFECTIVE_URL, &url_after);
if( res != CURLE_OK || !curl_handle ) {
perror((std::string("\33[2K\r => Error: curl_easy_getinfo failed: ") + curl_easy_strerror(res)).c_str());
curl_easy_cleanup(curl_handle);
return 12;
} else if(url_after){

if(std::string(url_after).find("/_ray/pow") != std::string::npos) {
std::cout << " \33[2K\r => CLOUD FLARE PROTECTION (Try " << rek_num << "/15)..." << std::flush;
usleep(400000);

if(this->debugMode && std::string(url_after) != "ifconfig.me/ip") {
std::string out_ip = this->getServerRequest("https://", "ifconfig.me/ip").html;

if(out_ip.find("<html>") == std::string::npos && [](const std::string& str) { return std::count(str.begin(), str.end(), '.'); }(out_ip) == 3)
std::cout << "\33[2K\r -> Current IP: " << out_ip << std::endl;
else
std::cout << "\33[2K\r -> Current IP: " << "Unknown: " << std::endl;

}
cloudflare_protec = true;
generateNewTorAnmeldeNamen(torAnmeldeNamen);

return this->downLoadToFile(filePath, url, rek_num + 1);

// std::cout << "/_ray/pow:\n" << readBuffer << std::endl;
// this->writeToFile( std::vector<std::string>{"./output.text"}, readBuffer );

// QWebEngineView view;
// view.load(QUrl("https://qt-project.org/"));
// view.resize(1024, 750);
// view.show();

// qApp->exec();
}

}


/* cleanup curl stuff */ /* cleanup curl stuff */
curl_easy_cleanup(curl_handle); curl_easy_cleanup(curl_handle);



View File

@ -24,6 +24,10 @@
#include <mutex> #include <mutex>





#define USER_AGENT "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"


struct Reply { struct Reply {
Reply() {} Reply() {}
Reply(std::string value_both) : html(value_both), url(value_both) {} Reply(std::string value_both) : html(value_both), url(value_both) {}
@ -56,7 +60,7 @@ public:
void get_terminal_size(int& width); void get_terminal_size(int& width);


Reply getServerRequest(std::string protocol, std::string Url, bool useCookies = false, std::string data = "", bool generateCookieFile = false, bool UrlAfterRedirectOnlyNeeded = false, std::string cookieFilePath = "", int rek_num = 0); Reply getServerRequest(std::string protocol, std::string Url, bool useCookies = false, std::string data = "", bool generateCookieFile = false, bool UrlAfterRedirectOnlyNeeded = false, std::string cookieFilePath = "", int rek_num = 0);
int downLoadToFile(std::string filePath, std::string url); int downLoadToFile(std::string filePath, std::string url, int rek_num = 0);


int login(PAGE page, Account account, std::string cookieFilePath); int login(PAGE page, Account account, std::string cookieFilePath);
Reply getUrlAfterRedirect(std::string p, std::string Url, std::string cookieFilePath); Reply getUrlAfterRedirect(std::string p, std::string Url, std::string cookieFilePath);

View File

@ -25,7 +25,7 @@


#define UpdaterCloudUrlWithPath "https://cloud.obermui.de/s/tXz7SWdaPJ7TacZ/download?path=%2F&files=" #define UpdaterCloudUrlWithPath "https://cloud.obermui.de/s/tXz7SWdaPJ7TacZ/download?path=%2F&files="
#define SecondUpdaterCloudUrlWithPath "https://snew4.obermui.de/download?path=%2F&files=" #define SecondUpdaterCloudUrlWithPath "https://snew4.obermui.de/download?path=%2F&files="
#define VERSION "6.1.0" #define VERSION "6.1.1"
#define DEFAULT_FILE_VERSION "2.5" #define DEFAULT_FILE_VERSION "2.5"


//default, anime, normal, //default, anime, normal,