From 64f362c6f77d176cb6b3839207e8457b07a05471 Mon Sep 17 00:00:00 2001 From: Markus Date: Thu, 22 Aug 2019 12:14:43 +0200 Subject: [PATCH] removed test_dir --- g++/accountManager.cpp | 210 --------- g++/accountManager.h | 32 -- g++/main.cpp | 14 - g++/pageManager.cpp | 347 -------------- g++/pageManager.h | 55 --- g++/parameterManager.cpp | 973 --------------------------------------- g++/parameterManager.h | 92 ---- g++/programManager.cpp | 723 ----------------------------- g++/programManager.h | 61 --- 9 files changed, 2507 deletions(-) delete mode 100644 g++/accountManager.cpp delete mode 100644 g++/accountManager.h delete mode 100644 g++/main.cpp delete mode 100644 g++/pageManager.cpp delete mode 100644 g++/pageManager.h delete mode 100644 g++/parameterManager.cpp delete mode 100644 g++/parameterManager.h delete mode 100644 g++/programManager.cpp delete mode 100644 g++/programManager.h diff --git a/g++/accountManager.cpp b/g++/accountManager.cpp deleted file mode 100644 index f8555b1..0000000 --- a/g++/accountManager.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include "accountManager.h" - -AccountManager::AccountManager(std::string pathToFile, std::string pathToAccountNumberFile) - : pathToAccountNumberFile(pathToAccountNumberFile) -{ - std::ifstream ifs(pathToFile); - if(!ifs.is_open()) { - if(writeDefault(pathToFile) != 0) - exit(12); - ifs.open(pathToFile); - if(!ifs.is_open()) { - std::cout << " => Error: Konnte Account File nicht öffnen" << std::endl; - exit(13); - } - } - - - std::string line; - while (std::getline(ifs, line)) { - if(line.length() > 0 && line[0] == '#') - continue; - Account account; - size_t Delimeter = line.find("/"); - - if(Delimeter == std::string::npos) { - account.Email = line; - account.Password = line; - } else { - account.Email = std::string(line).erase(Delimeter, line.length() - Delimeter); - account.Password = line.erase(0, Delimeter + 1); - } - if(account.Email == "" || account.Password == "") - continue; - else - accounts.push_back(account); - } - - ifs.close(); - -} - -Account AccountManager::getNextAccount() -{ - if(accounts.size() == 0) { - std::cout << " => Error: Keine Accounts vorhanden." << std::endl; - exit(36); - } - size_t accountNumber = getLastAccountNumber(); - accountNumber++; - - if( accountNumber >= accounts.size() ) - accountNumber=0; - if(setLastAccountNumber(accountNumber) != 0) - exit(45); - - return accounts.at(accountNumber); -} - -int AccountManager::writeDefault(std::string path) -{ - std::ofstream ofs(path); - if(!ofs.is_open()) { - perror((std::string(" => Error: Konnte Account Datei nicht öffnen: ") + path).c_str()); - return -1; - } - std::cout << " => Erstelle Datei mit Accounts unter: " << path << "..." < Error: Konnte Account Number Datei nicht erstellen"); - exit(34); - } - } - - std::string content( (std::istreambuf_iterator(fStream) ), (std::istreambuf_iterator() ) ); - return static_cast( atoi(content.c_str()) ); -} - -int AccountManager::setLastAccountNumber(size_t number) -{ - std::ofstream ofs; - ofs.open(pathToAccountNumberFile, std::ios::trunc); - if(!ofs.is_open()) { - std::cout << " => Error: Account Number Datei ist nicht geöffnet." << std::endl; - return 110; - } - //fStream.clear(); - ofs << number << std::endl; - return 0; -} - -bool AccountManager::isDirExist(const std::string& path) -{ - struct stat info; - if (stat(path.c_str(), &info) != 0) { - return false; - } - return (info.st_mode & S_IFDIR) != 0; -} - -bool AccountManager::createDir(std::string path, std::string atLinux) -{ - return system(std::string("mkdir " + atLinux + "'" + path +"'").c_str()); // -p if is linux -} diff --git a/g++/accountManager.h b/g++/accountManager.h deleted file mode 100644 index 390b6d5..0000000 --- a/g++/accountManager.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef ACCOUNTMANAGER_H -#define ACCOUNTMANAGER_H - -#include -#include -#include -#include - -struct Account { - std::string Email, Password; -}; - - -class AccountManager -{ -public: - AccountManager(std::string pathToFile, std::string pathToAccountNumberFile); - Account getNextAccount(); - - int writeDefault(std::string path); - size_t getLastAccountNumber(); - int setLastAccountNumber(size_t number); - - bool isDirExist(const std::string& path); - bool createDir(std::string path, std::string atLinux = "-p "); - -private: - std::vector accounts; - std::string pathToAccountNumberFile; -}; - -#endif // ACCOUNTMANAGER_H diff --git a/g++/main.cpp b/g++/main.cpp deleted file mode 100644 index 7e6a6ac..0000000 --- a/g++/main.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "programManager.h" -#include "parameterManager.h" - - -int main(int argc, char *argv[]) -{ - ProgramManager mainProgram; - Settings settings; - int res = manageParameter(settings, argc, argv); - if(res != 0) - return (res == -1) ? 0 : res; - - return mainProgram.start(&settings); -} diff --git a/g++/pageManager.cpp b/g++/pageManager.cpp deleted file mode 100644 index 1cc478a..0000000 --- a/g++/pageManager.cpp +++ /dev/null @@ -1,347 +0,0 @@ -#include "pageManager.h" - -PageManager::PageManager(std::string sock5Proxy, std::string cookieFilePath) - : sock5Proxy(sock5Proxy), cookieFilePath(cookieFilePath) -{ - curl_global_init(CURL_GLOBAL_ALL); -} - -PageManager::~PageManager() -{ - curl_global_cleanup(); -} - -void PageManager::setProxy(std::string ip, int port) -{ - this->sock5Proxy = "socks5://" + ip + ":" + std::to_string(port); -} - -void PageManager::setCookieFilePath(std::string path) -{ - this->cookieFilePath = path; -} - -void PageManager::setDebugMode(bool status) -{ - this->debugMode = status; -} - -size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) -{ - //Function für CURL - static_cast(userp)->append(static_cast(contents),size * nmemb); - return size * nmemb; -} - -Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::string data, bool generateCookieFile) -{ - CURL *curl; - CURLcode res; - std::string readBuffer; - char *url; - std::string returnUrl; - - std::cout << ( "\33[2K\rLade: '" + Url + "'..." ) << std::flush; - - curl = curl_easy_init(); - if(!curl) { - perror("\33[2K\r => Error: Curl easy init failed"); - return Reply("-1"); - } - - //Settings - curl_easy_setopt(curl, CURLOPT_URL, Url.c_str()); //Url für Curl - curl_easy_setopt(curl, CURLOPT_PROXY, sock5Proxy.c_str() ); //Sock5Proxy für Curl - 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_WRITEDATA, &readBuffer); //Legt die Variable readbuffer fest - curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0"); - if(useCookies) - curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieFilePath.c_str()); - if(data != "") - curl_easy_setopt (curl, CURLOPT_POSTFIELDS, data.c_str()); - if(generateCookieFile) - curl_easy_setopt (curl, CURLOPT_COOKIEJAR, cookieFilePath.c_str()); - - int maxTimeout = 10; - for (int timeout = 1; timeout <= maxTimeout; ++timeout) { - /* Perform the request, res will get the return code */ - res = curl_easy_perform(curl); - std::cout << "\33[2K\r" << std::flush; - - if(res != CURLE_OK) { - if(timeout == maxTimeout) { - perror((std::string("\33[2K\r => Error: curl_easy_perform() failed: ") + curl_easy_strerror(res)).c_str()); - return Reply("-1"); - } else { - std::cout << std::string( "\33[2K\r => Warning: Versuch " + std::to_string(timeout) + " von " + std::to_string(maxTimeout) + ": curl_easy_perform() failed: " + curl_easy_strerror(res) )<< std::flush; - sleep(1); - } - } else { - break; - } - - } - - //Get Url - res = curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); - if( res != CURLE_OK || !url ) { - perror((std::string("\33[2K\r => Error: curl_easy_getinfo failed: ") + curl_easy_strerror(res)).c_str()); - return Reply("-1"); - } else - returnUrl=url; - - - /* always cleanup */ /* Mach den Griff zu, schreib die Kekse! */ - curl_easy_cleanup(curl); - - return Reply(readBuffer, returnUrl); -} - -int PageManager::login(Account account) -{ - if(debugMode) - std::cout << " > Melde mit neuem Account an: Email: " << account.Email << " Passowort: " << account.Password << std::endl; - - std::string html = getServerRequest("https://s.to/login", false, std::string("email=" + account.Email + "&password=" + account.Password), true ).html; - if(html == "" ) - return 0; - else if (html.find("Das Feld Email muss eine gültige E-Mail-Adresse enthalten.") != std::string::npos) - std::cout << " => Error: Login failed: Das Feld Email muss eine gültige E-Mail-Adresse enthalten." << std::endl - << " Email: '" << account.Email << "' Passwort: '" << account.Password << "'" << std::endl; - else if (html.find("Das Passwort ist nicht korrekt") != std::string::npos) - std::cout << " => Error: Login failed: Das Passwort ist nicht korrekt." << std::endl - << " Email: '" << account.Email << "' Passwort: '" << account.Password << "'" << std::endl; - else if (html.find("Ein Account mit dieser E-Mail Adresse wurde nicht gefunden.") != std::string::npos) - std::cout << " => Error: Login failed: Ein Account mit dieser E-Mail Adresse wurde nicht gefunden." << std::endl - << " Email: '" << account.Email << "' Passwort: '" << account.Password << "'" << std::endl; - else if(html == "-1") - return -1; - else - std::cout << " => Error: Login failed: Keine Weiterleitung bei Login." << std::endl - << " Email: '" << account.Email << "' Passwort: '" << account.Password << "'" << std::endl; - return -1; -} - -std::string PageManager::getUrlAfterRedirect(std::string Url) -{ - return getServerRequest(Url, true).url; -} - -std::string PageManager::checkName(std::string Name) -{ - std::string name = replace(Name, " ", "-"); - - std::string html = getServerRequest("https://s.to/serie/stream/" + name).html; - if(html.find("Die gewünschte Serie wurde nicht gefunden oder ist im Moment deaktiviert.") != std::string::npos) { - std::cout << "\33[2K\r => Error: Die gewünschte Serie wurde nicht gefunden oder ist im Moment deaktiviert: " << Name << std::endl; - return "-1"; - } else if (html.find("404 - Seite nicht gefunden") != std::string::npos) { - std::cout << "\33[2K\r => Error: Ungültiger Name: " << Name << std::endl; - return "-1"; - } else if (html == "-1") { - return "-1"; - } - else { - std::cout << "\33[2K\r > Name: " << name << std::endl; - return name; - } -} - -std::string PageManager::getLinks(std::string HTML) -{ - size_t pos = HTML.find("
    "); - if(pos == std::string::npos) { - std::cout << " => Error: Konnte Position von \"" << "
      " << " nicht finden" < Error: Konnte Position von \"" << "