17 Commits
GUI ... v1.3.4

Author SHA1 Message Date
ce4a3a830e release version v1.3.4 2020-05-21 14:18:29 +02:00
af4a9c8350 Merge pull request #20 from Lukas-Heiligenbrunner/servicebinarypackagesamename
Servicebinarypackagesamename
2020-05-21 14:16:35 +02:00
86fd995923 some minor renamings
edited README.md
2020-05-21 14:09:17 +02:00
12ff16dc8e renamed service-binarayname and config file name to dynuiprefresher 2020-05-21 11:52:55 +02:00
ea648d5946 added usage info to readme 2020-05-21 11:38:39 +02:00
8c0c888472 Merge pull request #19 from Lukas-Heiligenbrunner/configfilewriteable
Configfilewriteable
2020-05-21 11:28:49 +02:00
fed6d251be Merge branch 'master' into configfilewriteable 2020-05-21 11:28:33 +02:00
ca47949a38 check if config folder exists if not create it
right appdata folder for windows hosts
seperate config path and config name in cmake header
2020-05-21 11:26:15 +02:00
8199fc2c1e correct build of test targets
correct upload of report.xml
2020-05-20 19:37:39 +02:00
998f3ea5e8 right xml export of unit test cases for test target 2020-05-20 19:25:37 +02:00
d8c3d4ffb8 correct build of gtests in one target with xml output 2020-05-19 23:57:16 +02:00
ede1afcce3 correct build dependencies for unit test 2020-05-19 21:50:43 +02:00
1239ae015a right ci camke dependencies for win and unix build 2020-05-19 21:29:36 +02:00
5271a25cbc use artifacts instead of cache 2020-05-19 21:13:53 +02:00
fb65ef98fa new gitlab ci for windows build
cmake- check if gtest is installed on build system
validate compiler after setting of compiler paths
2020-05-19 20:58:18 +02:00
da53941cba enable and start iprefresher service automatically after package installation (#18)
- dont terminate service if config not valid.
2020-05-19 16:35:57 +02:00
a356bca964 install config in other folder win 2020-05-18 19:46:19 +02:00
7 changed files with 184 additions and 80 deletions

View File

@ -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

View File

@ -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 ()

View File

@ -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

View File

@ -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();

View File

@ -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));
}
}
}