improved check of incorrect config

This commit is contained in:
Lukas Heiligenbrunner 2020-04-30 11:30:41 +02:00
parent 04e64ad79c
commit 7cf8e965b0
3 changed files with 25 additions and 16 deletions

View File

@ -134,7 +134,6 @@ IF (UNIX)
ENDIF (UNIX) ENDIF (UNIX)
# check if Doxygen is installed # check if Doxygen is installed
if (BUILD_DOC) if (BUILD_DOC)
message(STATUS "config of DOxygen build") message(STATUS "config of DOxygen build")
find_package(Doxygen) find_package(Doxygen)

View File

@ -23,7 +23,7 @@ void IPRefresher::checkIPAdress(bool force) {
std::string ip = ipapi.getGlobalIp(); std::string ip = ipapi.getGlobalIp();
if (ip.empty()) { if (ip.empty()) {
//no internet connection //no internet connection (or other error)
logger.logToLogfile("[WARNING] no internet connection"); logger.logToLogfile("[WARNING] no internet connection");
Logger::warning("no internet connection"); Logger::warning("no internet connection");
} else { } else {
@ -37,7 +37,7 @@ void IPRefresher::checkIPAdress(bool force) {
Logger::message("ip changed! -- from :" + oldip + "to: " + ip); Logger::message("ip changed! -- from :" + oldip + "to: " + ip);
DynuAPI dynu; DynuAPI dynu;
dynu.init(Credentials::dynuapikey,Credentials::domainid,Credentials::domainname); dynu.init(Credentials::dynuapikey, Credentials::domainid, Credentials::domainname);
if (dynu.refreshIp(ip)) { if (dynu.refreshIp(ip)) {
TelegramAPI tele; TelegramAPI tele;
@ -55,14 +55,18 @@ void IPRefresher::checkIPAdress(bool force) {
} }
IPRefresher::IPRefresher() { IPRefresher::IPRefresher() {
// default constructor
} }
IPRefresher::IPRefresher(bool loop) { IPRefresher::IPRefresher(bool loop) {
Logger::message("startup of service"); if (Credentials::readCredentials()) {
while (loop) { Logger::message("startup of service");
Logger::message("starting check"); while (loop) {
checkIPAdress(false); Logger::message("starting check");
std::this_thread::sleep_for(std::chrono::milliseconds(300000)); checkIPAdress(false);
std::this_thread::sleep_for(std::chrono::milliseconds(300000));
}
} else {
std::cout << "incorrect credentials!" << std::endl;
} }
} }

View File

@ -5,10 +5,6 @@
#include <Credentials.h> #include <Credentials.h>
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (!Credentials::readCredentials()) {
std::cout << "incorrect credentials!" << std::endl;
return -1;
}
if (argc > 1) { if (argc > 1) {
std::string firstarg(argv[1]); std::string firstarg(argv[1]);
if (firstarg == "-h" || firstarg == "--help") { if (firstarg == "-h" || firstarg == "--help") {
@ -21,7 +17,12 @@ int main(int argc, char *argv[]) {
std::cout << "Version " << Version::VERSION << std::endl; std::cout << "Version " << Version::VERSION << std::endl;
} else if (firstarg == "-f" || firstarg == "--force") { } else if (firstarg == "-f" || firstarg == "--force") {
IPRefresher ipr; IPRefresher ipr;
ipr.checkIPAdress(true); if (Credentials::readCredentials()) {
ipr.checkIPAdress(true);
} else {
std::cout << "incorrect credentials!" << std::endl;
}
} else if (firstarg == "-l" || firstarg == "--loop") { } else if (firstarg == "-l" || firstarg == "--loop") {
IPRefresher(true); IPRefresher(true);
} else { } else {
@ -30,7 +31,12 @@ int main(int argc, char *argv[]) {
} else { } else {
IPRefresher ipr; IPRefresher ipr;
Logger::message("starting check"); Logger::message("starting check");
ipr.checkIPAdress(false); if (Credentials::readCredentials()) {
ipr.checkIPAdress(false);
} else {
std::cout << "incorrect credentials!" << std::endl;
}
} }
return 0; return 0;