improved check of incorrect config
This commit is contained in:
		@@ -23,7 +23,7 @@ void IPRefresher::checkIPAdress(bool force) {
 | 
			
		||||
    std::string ip = ipapi.getGlobalIp();
 | 
			
		||||
 | 
			
		||||
    if (ip.empty()) {
 | 
			
		||||
        //no internet connection
 | 
			
		||||
        //no internet connection (or other error)
 | 
			
		||||
        logger.logToLogfile("[WARNING] no internet connection");
 | 
			
		||||
        Logger::warning("no internet connection");
 | 
			
		||||
    } else {
 | 
			
		||||
@@ -37,7 +37,7 @@ void IPRefresher::checkIPAdress(bool force) {
 | 
			
		||||
            Logger::message("ip changed! -- from :" + oldip + "to: " + ip);
 | 
			
		||||
 | 
			
		||||
            DynuAPI dynu;
 | 
			
		||||
            dynu.init(Credentials::dynuapikey,Credentials::domainid,Credentials::domainname);
 | 
			
		||||
            dynu.init(Credentials::dynuapikey, Credentials::domainid, Credentials::domainname);
 | 
			
		||||
 | 
			
		||||
            if (dynu.refreshIp(ip)) {
 | 
			
		||||
                TelegramAPI tele;
 | 
			
		||||
@@ -55,14 +55,18 @@ void IPRefresher::checkIPAdress(bool force) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IPRefresher::IPRefresher() {
 | 
			
		||||
 | 
			
		||||
    // default constructor
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IPRefresher::IPRefresher(bool loop) {
 | 
			
		||||
    Logger::message("startup of service");
 | 
			
		||||
    while (loop) {
 | 
			
		||||
        Logger::message("starting check");
 | 
			
		||||
        checkIPAdress(false);
 | 
			
		||||
        std::this_thread::sleep_for(std::chrono::milliseconds(300000));
 | 
			
		||||
    if (Credentials::readCredentials()) {
 | 
			
		||||
        Logger::message("startup of service");
 | 
			
		||||
        while (loop) {
 | 
			
		||||
            Logger::message("starting check");
 | 
			
		||||
            checkIPAdress(false);
 | 
			
		||||
            std::this_thread::sleep_for(std::chrono::milliseconds(300000));
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        std::cout << "incorrect credentials!" << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/main.cpp
									
									
									
									
									
								
							@@ -5,10 +5,6 @@
 | 
			
		||||
#include <Credentials.h>
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[]) {
 | 
			
		||||
    if (!Credentials::readCredentials()) {
 | 
			
		||||
        std::cout << "incorrect credentials!" << std::endl;
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    if (argc > 1) {
 | 
			
		||||
        std::string firstarg(argv[1]);
 | 
			
		||||
        if (firstarg == "-h" || firstarg == "--help") {
 | 
			
		||||
@@ -21,7 +17,12 @@ int main(int argc, char *argv[]) {
 | 
			
		||||
            std::cout << "Version " << Version::VERSION << std::endl;
 | 
			
		||||
        } else if (firstarg == "-f" || firstarg == "--force") {
 | 
			
		||||
            IPRefresher ipr;
 | 
			
		||||
            ipr.checkIPAdress(true);
 | 
			
		||||
            if (Credentials::readCredentials()) {
 | 
			
		||||
                ipr.checkIPAdress(true);
 | 
			
		||||
            } else {
 | 
			
		||||
                std::cout << "incorrect credentials!" << std::endl;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        } else if (firstarg == "-l" || firstarg == "--loop") {
 | 
			
		||||
            IPRefresher(true);
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -30,7 +31,12 @@ int main(int argc, char *argv[]) {
 | 
			
		||||
    } else {
 | 
			
		||||
        IPRefresher ipr;
 | 
			
		||||
        Logger::message("starting check");
 | 
			
		||||
        ipr.checkIPAdress(false);
 | 
			
		||||
        if (Credentials::readCredentials()) {
 | 
			
		||||
            ipr.checkIPAdress(false);
 | 
			
		||||
        } else {
 | 
			
		||||
            std::cout << "incorrect credentials!" << std::endl;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user