* option to force a refresh

* option to run in loop every 5 minutes
* pack into deb, rpm ant targz archive
This commit is contained in:
lukas-heiligenbrunner 2019-10-23 09:24:35 +02:00
parent f325c3a371
commit b68982345d
4 changed files with 57 additions and 4 deletions

View File

@ -35,3 +35,29 @@ target_link_libraries(iprefresher api logger ${CURL_LIBRARIES} )
# INSTALL to SYSTEM #
install (TARGETS iprefresher DESTINATION bin)
SET(CPACK_DEB_COMPONENT_INSTALL 1)
IF (UNIX)
SET(CPACK_CMAKE_GENERATOR "Unix Makefiles")
SET(CPACK_SOURCE_GENERATOR "TGZ;TBZ2")
SET(CPACK_GENERATOR "TGZ;TBZ2;DEB;RPM")
SET(CPACK_PACKAGE_DESCRIPTION "IPrefresher to refresh Dynu ip address and notify user via Telegram")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "IPrefresher to refresh Dynu ip address and notify user via Telegram")
SET(CPACK_PACKAGE_VENDOR "Lukas Heilgienbrunner")
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "1")
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
SET(CPACK_PACKAGE_CONTACT "Lukas Heiligenbrunner <ultimategameingcookie@gmail.com>")
SET(CPACK_PACKAGE_SECTION "games")
INCLUDE(CPack)
ENDIF (UNIX)
add_custom_target(build-linux-packages
"${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target package
DEPENDS ${PROJECT_NAME}
COMMENT "Installing ${PROJECT_NAME}")

View File

@ -10,5 +10,8 @@ public:
/**
* refresh ip address on Dynu server
*/
void checkIPAdress();
void checkIPAdress(bool force);
IPRefresher();
IPRefresher(bool loop);
};

View File

@ -8,9 +8,13 @@
#include <api/IPAPI.h>
#include <api/DynuAPI.h>
#include <api/TelegramAPI.h>
#include <chrono>
#include <thread>
#include "IPRefresher.h"
void IPRefresher::checkIPAdress() {
void IPRefresher::checkIPAdress(bool force) {
Logger logger;
IPAPI ipapi;
@ -23,7 +27,7 @@ void IPRefresher::checkIPAdress() {
} else {
std::string oldip = logger.readip();
if (oldip == ip) {
if (oldip == ip && !force) {
std::cout << "[INFO] no change -- ip: " << ip << std::endl;
logger.logToLogfile(" [INFO] no change -- ip: " + ip);
} else {
@ -45,3 +49,14 @@ void IPRefresher::checkIPAdress() {
}
}
}
IPRefresher::IPRefresher() {
}
IPRefresher::IPRefresher(bool loop) {
while(true){
std::this_thread::sleep_for(std::chrono::milliseconds(300000));
checkIPAdress(false);
}
}

View File

@ -8,15 +8,24 @@ int main(int argc, char *argv[]) {
if (firstarg == "-h" || firstarg == "--help") {
std::cout << "help page: " << std::endl << "[-h] [--help] print this help page" << std::endl
<< "[-v] [--version] print the software version" << std::endl
<< "[-f] [--force] force refresh of ip" << std::endl
<< "[-l] [--loop] infinite loop to refresh ip every five minutes" << std::endl
<< "[no argument] normal ip check and refresh" << std::endl;
} else if (firstarg == "-v" || firstarg == "--version") {
std::cout << "Version 1.0" << std::endl;
} else if (firstarg == "-f" || firstarg == "--force") {
IPRefresher ipr;
ipr.checkIPAdress(true);
} else if (firstarg == "-l" || firstarg == "--loop") {
IPRefresher ipr(true);
ipr.checkIPAdress(false);
} else {
std::cout << "wrong arguments! -h for help" << std::endl;
}
} else {
IPRefresher ipr;
ipr.checkIPAdress();
ipr.checkIPAdress(false);
}
return 0;