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