Merge branch 'master' into cross-compilation
This commit is contained in:
		| @@ -4,9 +4,9 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "Hashmap.h" | ||||
|  | ||||
| #include <string> | ||||
| #include "Hashmap.h" | ||||
|  | ||||
| class API { | ||||
| public: | ||||
|   | ||||
| @@ -4,9 +4,10 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include <string> | ||||
| #include "API.h" | ||||
|  | ||||
| #include <string> | ||||
|  | ||||
| class IPAPI : API{ | ||||
| public: | ||||
|     /** | ||||
|   | ||||
| @@ -4,9 +4,9 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "API.h" | ||||
|  | ||||
| #include <string> | ||||
| #include "API.h" | ||||
|  | ||||
| class TelegramAPI : API { | ||||
| public: | ||||
|   | ||||
| @@ -2,14 +2,14 @@ | ||||
| // Created by lukas on 11.02.20. | ||||
| // | ||||
|  | ||||
| #include <Config.h> | ||||
| #include <Logger.h> | ||||
| #include "Config.h" | ||||
| #include "Logger.h" | ||||
| #include "Version.h" | ||||
|  | ||||
| #include <iostream> | ||||
| #include <cstring> | ||||
| #include <fstream> | ||||
| #include <libconfig.h++> | ||||
| #include <Version.h> | ||||
|  | ||||
| std::string Config::dynuapikey; | ||||
| std::string Config::domainid; //id of the dynu domain | ||||
|   | ||||
| @@ -2,10 +2,11 @@ | ||||
| // Created by lukas on 05.05.19. | ||||
| // | ||||
|  | ||||
| #include "FileLogger.h" | ||||
|  | ||||
| #include <fstream> | ||||
| #include <iostream> | ||||
|  | ||||
| #include "FileLogger.h" | ||||
| #include <climits> | ||||
|  | ||||
| void FileLogger::safeip(std::string ip) { | ||||
|     std::ofstream out; | ||||
| @@ -24,5 +25,9 @@ std::string FileLogger::readip() { | ||||
|  | ||||
|     in >> ip; | ||||
|  | ||||
|     // when received ip has no : return 0.0.0.0 | ||||
|     if (ip.find(':') == ULONG_MAX) | ||||
|         return "0.0.0.0"; | ||||
|     else | ||||
|         return ip; | ||||
| } | ||||
|   | ||||
| @@ -2,20 +2,19 @@ | ||||
| // Created by lukas on 02.08.19. | ||||
| // | ||||
|  | ||||
| #include "IPRefresher.h" | ||||
| #include "FileLogger.h" | ||||
| #include "api/IPAPI.h" | ||||
| #include "api/DynuAPI.h" | ||||
| #include "api/TelegramAPI.h" | ||||
| #include "Config.h" | ||||
| #include "Version.h" | ||||
|  | ||||
| #include <string> | ||||
|  | ||||
| #include <FileLogger.h> | ||||
| #include <api/IPAPI.h> | ||||
| #include <api/DynuAPI.h> | ||||
| #include <api/TelegramAPI.h> | ||||
|  | ||||
| #include <chrono> | ||||
| #include <thread> | ||||
| #include <Logger.h> | ||||
|  | ||||
| #include <IPRefresher.h> | ||||
| #include <Config.h> | ||||
| #include <Version.h> | ||||
| #include <climits> | ||||
|  | ||||
| void IPRefresher::checkIPAdress(bool force) { | ||||
|     FileLogger logger; | ||||
| @@ -26,6 +25,9 @@ void IPRefresher::checkIPAdress(bool force) { | ||||
|     if (ip.empty()) { | ||||
|         //no internet connection (or other error) | ||||
|         Logger::warning("no internet connection"); | ||||
|     } else if (ip.find(':') == ULONG_MAX) { | ||||
|         // error when ip doesn't contain a : | ||||
|         Logger::warning("an error occured when getting the global ip"); | ||||
|     } else { | ||||
|         std::string oldip = logger.readip(); | ||||
|  | ||||
|   | ||||
| @@ -2,11 +2,11 @@ | ||||
| // Created by lukas on 26.10.19. | ||||
| // | ||||
|  | ||||
| #include "Logger.h" | ||||
|  | ||||
| #include <sstream> | ||||
| #include <iostream> | ||||
|  | ||||
| #include "Logger.h" | ||||
|  | ||||
| void Logger::debug(const std::string message) { | ||||
|     log(message, Logger::Debug); | ||||
| } | ||||
|   | ||||
| @@ -7,7 +7,6 @@ | ||||
| #include <sstream> | ||||
| #include <curl/curl.h> | ||||
|  | ||||
|  | ||||
| std::string API::request(std::string myurl) { | ||||
|     Hashmap<std::string, std::string> map; | ||||
|     std::vector<std::string> str; | ||||
|   | ||||
| @@ -3,8 +3,9 @@ | ||||
| // | ||||
|  | ||||
| #include "api/TelegramAPI.h" | ||||
| #include "Logger.h" | ||||
|  | ||||
| #include <Logger.h> | ||||
| #include <climits> | ||||
|  | ||||
| int TelegramAPI::sendMessage(const std::string& text) { | ||||
|     Hashmap<std::string, std::string> args; | ||||
| @@ -15,8 +16,7 @@ int TelegramAPI::sendMessage(const std::string& text) { | ||||
|  | ||||
|     std::string reply = request("https://api.telegram.org/bot" + apikey + "/sendmessage", false, args, headers); | ||||
|  | ||||
|     unsigned long ulongmax = -1; | ||||
|     if (reply.find("\"error_code\"") != ulongmax) { | ||||
|     if (reply.find("\"error_code\"") != ULONG_MAX) { | ||||
|         Logger::error("failed to refresh the ip (Dynu API)"); | ||||
|         return -1; | ||||
|     } | ||||
|   | ||||
							
								
								
									
										14
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/main.cpp
									
									
									
									
									
								
							| @@ -2,12 +2,14 @@ | ||||
| // Created by lukas on 18.06.19. | ||||
| // | ||||
|  | ||||
| #include <Version.h> | ||||
| #include <IPRefresher.h> | ||||
| #include <Logger.h> | ||||
| #include <Config.h> | ||||
| #include "Version.h" | ||||
| #include "IPRefresher.h" | ||||
| #include "Logger.h" | ||||
| #include "Config.h" | ||||
| #include "api/IPAPI.h" | ||||
|  | ||||
| #include <iostream> | ||||
|  | ||||
| /** | ||||
|  * application entry point | ||||
|  */ | ||||
| @@ -20,6 +22,7 @@ int main(int argc, char *argv[]) { | ||||
|                       << "[-f] [--force] force refresh of ip" << std::endl | ||||
|                       << "[-l] [--loop] infinite loop to refresh ip every five minutes" << std::endl | ||||
|                       << "[-c] [--checkconfig] validate configuration" << std::endl | ||||
|                       << "[-ip] [--currentip] get current global ip" << std::endl | ||||
|                       << "[no argument] normal ip check and refresh" << std::endl; | ||||
|         } else if (firstarg == "-v" || firstarg == "--version") { | ||||
|             std::cout << "Version " << Version::VERSION << std::endl; | ||||
| @@ -40,6 +43,9 @@ int main(int argc, char *argv[]) { | ||||
|                 Logger::warning("There are errors in config file!"); | ||||
|                 return -1; | ||||
|             } | ||||
|         } else if (firstarg == "-ip" || firstarg == "--currentip") { | ||||
|             IPAPI ipapi; | ||||
|             std::cout << "Current global IP: " << ipapi.getGlobalIp() << std::endl; | ||||
|         } else { | ||||
|             Logger::message("wrong arguments!  -h for help"); | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user