Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
ce4a3a830e | |||
af4a9c8350 | |||
86fd995923 | |||
12ff16dc8e | |||
ea648d5946 | |||
8c0c888472 | |||
fed6d251be | |||
ca47949a38 | |||
8199fc2c1e | |||
998f3ea5e8 | |||
d8c3d4ffb8 | |||
ede1afcce3 | |||
1239ae015a | |||
5271a25cbc | |||
fb65ef98fa | |||
da53941cba | |||
a356bca964 |
@ -1,49 +1,95 @@
|
||||
image: luki42/dynuiprefresher_build:latest
|
||||
|
||||
stages:
|
||||
- cmake
|
||||
- build
|
||||
- build_package
|
||||
- test
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- build/
|
||||
- src/
|
||||
- inc/
|
||||
- tests/
|
||||
- postinst
|
||||
- post
|
||||
|
||||
# Unix Build
|
||||
cmake:
|
||||
stage: cmake
|
||||
image: luki42/dynuiprefresher_build:latest
|
||||
script:
|
||||
- cmake -S . -B build
|
||||
artifacts:
|
||||
paths:
|
||||
- build/
|
||||
- inc/
|
||||
- postinst
|
||||
|
||||
build:
|
||||
stage: build
|
||||
image: luki42/dynuiprefresher_build:latest
|
||||
script:
|
||||
- cd build
|
||||
- make
|
||||
- make iprefresher
|
||||
artifacts:
|
||||
paths:
|
||||
- "build/bin/*"
|
||||
- build/
|
||||
- inc/
|
||||
- postinst
|
||||
dependencies:
|
||||
- cmake
|
||||
|
||||
|
||||
build_package:
|
||||
stage: build_package
|
||||
stage: post
|
||||
image: luki42/dynuiprefresher_build:latest
|
||||
script:
|
||||
- cd build
|
||||
- make package
|
||||
artifacts:
|
||||
paths:
|
||||
- "build/packages/*"
|
||||
- build/
|
||||
- inc/
|
||||
- postinst
|
||||
dependencies:
|
||||
- build
|
||||
|
||||
test:
|
||||
stage: test
|
||||
stage: post
|
||||
image: luki42/dynuiprefresher_build:latest
|
||||
script:
|
||||
- cd build
|
||||
- make test
|
||||
- make build-xml
|
||||
- make build-test
|
||||
artifacts:
|
||||
reports:
|
||||
junit: build/report.xml
|
||||
junit: build/*.xml
|
||||
dependencies:
|
||||
- build
|
||||
|
||||
# Windows Build
|
||||
cmake_win64:
|
||||
stage: cmake
|
||||
image: luki42/dynuiprefresher_build:windows
|
||||
script:
|
||||
- cmake -S . -B build -D WinBuild=ON
|
||||
artifacts:
|
||||
paths:
|
||||
- build/
|
||||
- inc/
|
||||
|
||||
build_win64:
|
||||
stage: build
|
||||
image: luki42/dynuiprefresher_build:windows
|
||||
script:
|
||||
- cd build
|
||||
- make iprefresher
|
||||
artifacts:
|
||||
paths:
|
||||
- build/
|
||||
- inc/
|
||||
dependencies:
|
||||
- cmake_win64
|
||||
|
||||
|
||||
build_package_win64:
|
||||
stage: post
|
||||
image: luki42/dynuiprefresher_build:windows
|
||||
script:
|
||||
- cd build
|
||||
- make package
|
||||
artifacts:
|
||||
paths:
|
||||
- build/
|
||||
- inc/
|
||||
dependencies:
|
||||
- build_win64
|
@ -9,8 +9,8 @@
|
||||
# for test build gtest needs to be installed.
|
||||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
project(iprefresher DESCRIPTION "Dynu ip refresher")
|
||||
SET(PROJECT_VERSION 1.3.3)
|
||||
project(dynuiprefresher DESCRIPTION "Dynu ip refresher" LANGUAGES)
|
||||
SET(PROJECT_VERSION 1.3.4)
|
||||
|
||||
# CONFIGURATION
|
||||
SET(CMAKE_BUILD_TYPE Release) # manually SET build type (Release / Debug)
|
||||
@ -19,11 +19,12 @@ SET(LIB_METHOD STATIC) #SHARED / STATIC
|
||||
option(BUILD_DOC "Build documentation" ON) # additional dependency for Doxygen
|
||||
option(PACKAGING "Allow Packaging to <exe>, <deb> or <rpm>" ON) # additional dependencies for RPMbuild,dpkg or NSIS
|
||||
option(TESTS "Build Tests" ON) # additional dependencies for GTEST - to build tests
|
||||
set(WinBuild false)
|
||||
option(WinBuild "cross compile for Windows Platform" OFF)
|
||||
|
||||
# helper variables
|
||||
SET(CMAKE_CXX_STANDARD 17)
|
||||
string(TIMESTAMP TIMESTAMP_NOW "%d.%m.%Y")
|
||||
SET(Application_Name "dynuiprefresher")
|
||||
|
||||
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
@ -31,6 +32,7 @@ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
# setup winbuild compilers
|
||||
if (${WinBuild})
|
||||
message(STATUS "setup Mingw Toolchain for cross compile.")
|
||||
set(LIBSUFFIX .dll)
|
||||
set(SUFFIX .exe)
|
||||
|
||||
@ -40,9 +42,9 @@ if (${WinBuild})
|
||||
#set(TOOLCHAIN_PREFIX i686-w64-mingw32)
|
||||
|
||||
# cross compilers to use for C and C++
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
||||
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
|
||||
set(CMAKE_C_COMPILER /usr/bin/${TOOLCHAIN_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER /usr/bin/${TOOLCHAIN_PREFIX}-g++)
|
||||
set(CMAKE_RC_COMPILER /usr/bin/${TOOLCHAIN_PREFIX}-windres)
|
||||
|
||||
# target environment on the build host system
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
|
||||
@ -65,17 +67,26 @@ if (${WinBuild})
|
||||
# or add_definitions(-DCURL_STATICLIB)
|
||||
|
||||
# windows config path is same as executable
|
||||
set(CONFIG_PATH "./iprefresher.cfg")
|
||||
set(CONFIG_PATH "std::string(std::getenv(\"USERPROFILE\")) + \"\\\\AppData\\\\Roaming\\\\DynuIPrefresher\\\\\"")
|
||||
else ()
|
||||
message(STATUS "using nativ gcc toolchain.")
|
||||
set(LIBSUFFIX .so)
|
||||
set(SUFFIX "")
|
||||
|
||||
# set /etc/ config path
|
||||
set(CONFIG_PATH "/etc/iprefresher.cfg")
|
||||
set(CONFIG_PATH "\"/etc/\"")
|
||||
endif ()
|
||||
|
||||
# test compiler settings and enable languages here
|
||||
message("")
|
||||
message(STATUS "Testing the C++ compiler!")
|
||||
enable_language(CXX)
|
||||
message("")
|
||||
message(STATUS "Testing the C compiler!")
|
||||
enable_language(C)
|
||||
|
||||
# config libs
|
||||
message("")
|
||||
message(STATUS "Config of Libraries")
|
||||
# libcurl
|
||||
if (${WinBuild})
|
||||
@ -132,7 +143,7 @@ endif ()
|
||||
message("")
|
||||
|
||||
#read sample config
|
||||
FILE(READ ${CMAKE_SOURCE_DIR}/config/iprefresher.cfg SAMPLECONFIG)
|
||||
FILE(READ ${CMAKE_SOURCE_DIR}/config/dynuiprefresher.cfg SAMPLECONFIG)
|
||||
#add version header
|
||||
FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h
|
||||
"/**
|
||||
@ -149,7 +160,8 @@ FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h
|
||||
|
||||
namespace Version {
|
||||
const std::string VERSION = \"${PROJECT_VERSION}\";
|
||||
const std::string ConfigDir = \"${CONFIG_PATH}\";
|
||||
const std::string ConfigDir = ${CONFIG_PATH};
|
||||
const std::string ConfName = \"${Application_Name}.cfg\";
|
||||
const std::string SAMPLECONFIG = R\"(${SAMPLECONFIG})\";
|
||||
}"
|
||||
)
|
||||
@ -160,7 +172,7 @@ add_library(api ${LIB_METHOD}
|
||||
src/api/DynuAPI.cpp
|
||||
src/api/IPAPI.cpp)
|
||||
|
||||
add_library(dynuiprefresher ${LIB_METHOD}
|
||||
add_library(libdynuiprefresher ${LIB_METHOD}
|
||||
src/IPRefresher.cpp
|
||||
src/Config.cpp
|
||||
src/IpHelper.cpp
|
||||
@ -168,25 +180,25 @@ add_library(dynuiprefresher ${LIB_METHOD}
|
||||
src/Logger.cpp
|
||||
)
|
||||
|
||||
add_executable(iprefresher src/main.cpp)
|
||||
add_executable(${Application_Name} src/main.cpp)
|
||||
|
||||
# LINK generated LIBS #
|
||||
target_link_libraries(iprefresher dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
|
||||
target_link_libraries(${Application_Name} libdynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
|
||||
|
||||
# setting install targets
|
||||
IF (NOT ${WinBuild})
|
||||
# INSTALL to Linux SYSTEM #
|
||||
|
||||
# install binaries
|
||||
install(TARGETS iprefresher DESTINATION usr/bin)
|
||||
install(TARGETS ${Application_Name} DESTINATION usr/bin)
|
||||
# install systemd service and enable it
|
||||
install(FILES service/iprefresher.service DESTINATION lib/systemd/system)
|
||||
install(FILES service/${Application_Name}.service DESTINATION lib/systemd/system)
|
||||
ELSE ()
|
||||
# INSTALL to Windows SYSTEM #
|
||||
|
||||
# install binary to current folder
|
||||
set_target_properties(iprefresher PROPERTIES SUFFIX ".exe")
|
||||
install(TARGETS iprefresher DESTINATION .)
|
||||
set_target_properties(${Application_Name} PROPERTIES SUFFIX ".exe")
|
||||
install(TARGETS ${Application_Name} DESTINATION .)
|
||||
|
||||
# install .dll dependencies
|
||||
# todo check if files exist...
|
||||
@ -226,8 +238,10 @@ if (${PACKAGING})
|
||||
if [ ! -f ${CONFIG_PATH} ]; then
|
||||
cat > ${CONFIG_PATH} <<- EOM
|
||||
${SAMPLECONFIG}EOM
|
||||
fi\n"
|
||||
)
|
||||
fi
|
||||
|
||||
systemctl enable ${Application_Name}.service
|
||||
systemctl start ${Application_Name}.service")
|
||||
|
||||
|
||||
SET(CPACK_DEB_COMPONENT_INSTALL 1)
|
||||
@ -279,8 +293,8 @@ fi\n"
|
||||
|
||||
add_custom_target(build-packages
|
||||
"${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target package
|
||||
DEPENDS ${PROJECT_NAME}
|
||||
COMMENT "Packing ${PROJECT_NAME}")
|
||||
DEPENDS ${Application_Name}
|
||||
COMMENT "Packing ${Application_Name}")
|
||||
message("")
|
||||
ENDIF ()
|
||||
|
||||
@ -311,7 +325,10 @@ endif (BUILD_DOC)
|
||||
|
||||
# Test Cases
|
||||
if (TESTS)
|
||||
include(GoogleTest)
|
||||
# include(GoogleTest)
|
||||
message(STATUS "Configuring GTEST")
|
||||
find_package(GTest)
|
||||
if (GTEST_FOUND)
|
||||
|
||||
mark_as_advanced(
|
||||
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
|
||||
@ -325,25 +342,23 @@ if (TESTS)
|
||||
# create an exectuable in which the tests will be stored
|
||||
add_executable(${TESTNAME} ${ARGN})
|
||||
# link the Google test infrastructure, mocking library, and a default main fuction to
|
||||
target_link_libraries(${TESTNAME} gtest gtest_main -lpthread -lm dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
|
||||
target_link_libraries(${TESTNAME} gtest gtest_main -lpthread -lm libdynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
|
||||
# see https://cmake.org/cmake/help/v3.10/module/GoogleTest.html for more options to pass to it
|
||||
gtest_discover_tests(${TESTNAME}
|
||||
WORKING_DIRECTORY ${PROJECT_DIR}
|
||||
EXTRA_ARGS --gtest_output=xml:report.xml -VV
|
||||
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
|
||||
)
|
||||
set_target_properties(${TESTNAME} PROPERTIES FOLDER tests)
|
||||
gtest_discover_tests(${TESTNAME})
|
||||
|
||||
add_custom_command(TARGET build-test
|
||||
POST_BUILD
|
||||
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target ${TESTNAME}
|
||||
COMMAND "bin/${TESTNAME}" --gtest_output=xml:${TESTNAME}-report.xml)
|
||||
endmacro()
|
||||
|
||||
add_custom_target(build-test
|
||||
DEPENDS ${PROJECT_NAME}
|
||||
COMMENT "Testing ${PROJECT_NAME}")
|
||||
|
||||
package_add_test(test1 tests/UnitTest.cpp ${SOURCE})
|
||||
|
||||
add_custom_target(build-test
|
||||
"${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target test
|
||||
DEPENDS ${PROJECT_NAME}
|
||||
COMMENT "Packing ${PROJECT_NAME}")
|
||||
|
||||
add_custom_target(build-xml
|
||||
"bin/test1" --gtest_output="xml:report.xml"
|
||||
DEPENDS ${PROJECT_NAME}
|
||||
COMMENT "Packing ${PROJECT_NAME}")
|
||||
else ()
|
||||
message(STATUS "GTEST environment not found!")
|
||||
endif ()
|
||||
ENDIF ()
|
20
README.md
20
README.md
@ -9,11 +9,27 @@ I'm providing executables for Debian/Ubuntu (.deb) and RHEL/Debian (.rpm).
|
||||
But you can still compile the code my your own (see build section).
|
||||
|
||||
## Configuration
|
||||
There is a configuration file `/etc/iprefresher.cfg` where you have to specify the DYNU API key (get it from their homepage), the domainid and your domain.
|
||||
There is a configuration file `/etc/dynuiprefresher.cfg` where you have to specify the DYNU API key (get it from their homepage), the domainid and your domain.
|
||||
Furthermore, you can optionally specify a Telegram API key and a Chat ID if you want to be notfied when your local ip changes.
|
||||
|
||||
To enable and start the service:
|
||||
`systemctl enable iprefresher.service` and `systemctl start iprefresher.service`
|
||||
`systemctl enable dynuiprefresher.service` and `systemctl start dynuiprefresher.service`
|
||||
|
||||
## Usage
|
||||
First of all configure the right keys in the `/etc/dynuiprefresher.cfg` or `%appdata%\DynuIpRefresher\dynuiprefresher.cfg` config file.
|
||||
|
||||
Afterwards use the following options:
|
||||
|
||||
```
|
||||
help page:
|
||||
[-h] [--help] print this help page
|
||||
[-v] [--version] print the software version
|
||||
[-f] [--force] force refresh of ip
|
||||
[-l] [--loop] infinite loop to refresh ip every five minutes
|
||||
[-c] [--checkconfig] validate configuration
|
||||
[-ip] [--currentip] get current global ip
|
||||
[no argument] normal ip check and refresh
|
||||
```
|
||||
|
||||
|
||||
## Build
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <libconfig.h++>
|
||||
#include <sys/stat.h>
|
||||
|
||||
std::string Config::dynuapikey;
|
||||
std::string Config::domainid; //id of the dynu domain
|
||||
@ -19,13 +20,38 @@ bool Config::telegramSupport;
|
||||
bool Config::readConfig() {
|
||||
libconfig::Config cfg;
|
||||
try {
|
||||
cfg.readFile(Version::ConfigDir.c_str());
|
||||
cfg.readFile(std::string(Version::ConfigDir + Version::ConfName).c_str());
|
||||
}
|
||||
catch (const libconfig::FileIOException &fioex) {
|
||||
std::cout << "I/O error while reading config file." << std::endl << "creating new config file!" << std::endl;
|
||||
|
||||
// check if config folder exists
|
||||
struct stat info{};
|
||||
|
||||
if (stat(Version::ConfigDir.c_str(), &info) != 0) {
|
||||
Logger::warning("The config folder doesn't exist. Trying to create it.");
|
||||
|
||||
#ifdef __unix
|
||||
int check = mkdir(Version::ConfigDir.c_str(), 777);
|
||||
#else
|
||||
int check = mkdir(Version::ConfigDir.c_str());
|
||||
#endif
|
||||
|
||||
// check if directory is created or not
|
||||
if (!check)
|
||||
Logger::message("config directory successfully created. ");
|
||||
else
|
||||
Logger::error("unable to create config directory.");
|
||||
|
||||
} else if (info.st_mode & S_IFDIR) {
|
||||
Logger::debug("config directory exists already");
|
||||
} else {
|
||||
Logger::error("A file exists with the same name as the config dir should be");
|
||||
}
|
||||
|
||||
|
||||
std::ofstream myfile;
|
||||
myfile.open(Version::ConfigDir);
|
||||
myfile.open(Version::ConfigDir + Version::ConfName);
|
||||
if (myfile.is_open()) {
|
||||
myfile << Version::SAMPLECONFIG;
|
||||
myfile.close();
|
||||
|
@ -54,14 +54,15 @@ IPRefresher::IPRefresher(bool loop) {
|
||||
if (loop) {
|
||||
Logger::message("startup of service");
|
||||
Logger::message("Version: " + Version::VERSION);
|
||||
if (Config::readConfig()) {
|
||||
|
||||
while (true) {
|
||||
Logger::message("starting check");
|
||||
if (Config::readConfig()) {
|
||||
checkIPAdress(false);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300000));
|
||||
}
|
||||
} else {
|
||||
std::cout << "incorrect credentials!" << std::endl;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user