* 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:
parent
f325c3a371
commit
b68982345d
@ -35,3 +35,29 @@ target_link_libraries(iprefresher api logger ${CURL_LIBRARIES} )
|
|||||||
|
|
||||||
# INSTALL to SYSTEM #
|
# INSTALL to SYSTEM #
|
||||||
install (TARGETS iprefresher DESTINATION bin)
|
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}")
|
||||||
|
|
||||||
|
@ -10,5 +10,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
* refresh ip address on Dynu server
|
* refresh ip address on Dynu server
|
||||||
*/
|
*/
|
||||||
void checkIPAdress();
|
void checkIPAdress(bool force);
|
||||||
|
|
||||||
|
IPRefresher();
|
||||||
|
IPRefresher(bool loop);
|
||||||
};
|
};
|
||||||
|
@ -8,9 +8,13 @@
|
|||||||
#include <api/IPAPI.h>
|
#include <api/IPAPI.h>
|
||||||
#include <api/DynuAPI.h>
|
#include <api/DynuAPI.h>
|
||||||
#include <api/TelegramAPI.h>
|
#include <api/TelegramAPI.h>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "IPRefresher.h"
|
#include "IPRefresher.h"
|
||||||
|
|
||||||
void IPRefresher::checkIPAdress() {
|
void IPRefresher::checkIPAdress(bool force) {
|
||||||
Logger logger;
|
Logger logger;
|
||||||
|
|
||||||
IPAPI ipapi;
|
IPAPI ipapi;
|
||||||
@ -23,7 +27,7 @@ void IPRefresher::checkIPAdress() {
|
|||||||
} else {
|
} else {
|
||||||
std::string oldip = logger.readip();
|
std::string oldip = logger.readip();
|
||||||
|
|
||||||
if (oldip == ip) {
|
if (oldip == ip && !force) {
|
||||||
std::cout << "[INFO] no change -- ip: " << ip << std::endl;
|
std::cout << "[INFO] no change -- ip: " << ip << std::endl;
|
||||||
logger.logToLogfile(" [INFO] no change -- ip: " + ip);
|
logger.logToLogfile(" [INFO] no change -- ip: " + ip);
|
||||||
} else {
|
} 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
11
src/main.cpp
11
src/main.cpp
@ -8,15 +8,24 @@ int main(int argc, char *argv[]) {
|
|||||||
if (firstarg == "-h" || firstarg == "--help") {
|
if (firstarg == "-h" || firstarg == "--help") {
|
||||||
std::cout << "help page: " << std::endl << "[-h] [--help] print this help page" << std::endl
|
std::cout << "help page: " << std::endl << "[-h] [--help] print this help page" << std::endl
|
||||||
<< "[-v] [--version] print the software version" << 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;
|
<< "[no argument] normal ip check and refresh" << std::endl;
|
||||||
} else if (firstarg == "-v" || firstarg == "--version") {
|
} else if (firstarg == "-v" || firstarg == "--version") {
|
||||||
std::cout << "Version 1.0" << std::endl;
|
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 {
|
} else {
|
||||||
std::cout << "wrong arguments! -h for help" << std::endl;
|
std::cout << "wrong arguments! -h for help" << std::endl;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IPRefresher ipr;
|
IPRefresher ipr;
|
||||||
ipr.checkIPAdress();
|
ipr.checkIPAdress(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user