Merge branch 'master' into GUI
This commit is contained in:
commit
2762605ca4
@ -1,49 +1,95 @@
|
|||||||
image: luki42/dynuiprefresher_build:latest
|
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- cmake
|
- cmake
|
||||||
- build
|
- build
|
||||||
- build_package
|
- post
|
||||||
- test
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- build/
|
|
||||||
- src/
|
|
||||||
- inc/
|
|
||||||
- tests/
|
|
||||||
- postinst
|
|
||||||
|
|
||||||
|
# Unix Build
|
||||||
cmake:
|
cmake:
|
||||||
stage: cmake
|
stage: cmake
|
||||||
|
image: luki42/dynuiprefresher_build:latest
|
||||||
script:
|
script:
|
||||||
- cmake -S . -B build
|
- cmake -S . -B build
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- build/
|
||||||
|
- inc/
|
||||||
|
- postinst
|
||||||
|
|
||||||
build:
|
build:
|
||||||
stage: build
|
stage: build
|
||||||
|
image: luki42/dynuiprefresher_build:latest
|
||||||
script:
|
script:
|
||||||
- cd build
|
- cd build
|
||||||
- make
|
- make dynuiprefresher
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- "build/bin/*"
|
- build/
|
||||||
|
- inc/
|
||||||
|
- postinst
|
||||||
|
dependencies:
|
||||||
|
- cmake
|
||||||
|
|
||||||
|
|
||||||
build_package:
|
build_package:
|
||||||
stage: build_package
|
stage: post
|
||||||
|
image: luki42/dynuiprefresher_build:latest
|
||||||
script:
|
script:
|
||||||
- cd build
|
- cd build
|
||||||
- make package
|
- make package
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- "build/packages/*"
|
- build/
|
||||||
|
- inc/
|
||||||
|
- postinst
|
||||||
|
dependencies:
|
||||||
|
- build
|
||||||
|
|
||||||
test:
|
test:
|
||||||
stage: test
|
stage: post
|
||||||
|
image: luki42/dynuiprefresher_build:latest
|
||||||
script:
|
script:
|
||||||
- cd build
|
- cd build
|
||||||
- make test
|
- make build-test
|
||||||
- make build-xml
|
|
||||||
artifacts:
|
artifacts:
|
||||||
reports:
|
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 dynuiprefresher
|
||||||
|
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
|
143
CMakeLists.txt
143
CMakeLists.txt
@ -9,8 +9,8 @@
|
|||||||
# for test build gtest needs to be installed.
|
# for test build gtest needs to be installed.
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
project(iprefresher DESCRIPTION "Dynu ip refresher")
|
project(dynuiprefresher DESCRIPTION "Dynu ip refresher" LANGUAGES)
|
||||||
SET(PROJECT_VERSION 1.3.3)
|
SET(PROJECT_VERSION 1.3.4)
|
||||||
|
|
||||||
# CONFIGURATION
|
# CONFIGURATION
|
||||||
SET(CMAKE_BUILD_TYPE Release) # manually SET build type (Release / Debug)
|
SET(CMAKE_BUILD_TYPE Release) # manually SET build type (Release / Debug)
|
||||||
@ -20,11 +20,12 @@ 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(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
|
option(TESTS "Build Tests" ON) # additional dependencies for GTEST - to build tests
|
||||||
option(GUI "Build GUI elements" ON) # additional dependencies to QT libraries needed
|
option(GUI "Build GUI elements" ON) # additional dependencies to QT libraries needed
|
||||||
set(WinBuild false)
|
option(WinBuild "cross compile for Windows Platform" OFF)
|
||||||
|
|
||||||
# helper variables
|
# helper variables
|
||||||
SET(CMAKE_CXX_STANDARD 17)
|
SET(CMAKE_CXX_STANDARD 17)
|
||||||
string(TIMESTAMP TIMESTAMP_NOW "%d.%m.%Y")
|
string(TIMESTAMP TIMESTAMP_NOW "%d.%m.%Y")
|
||||||
|
SET(Application_Name "dynuiprefresher")
|
||||||
|
|
||||||
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||||
@ -32,6 +33,7 @@ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
|||||||
|
|
||||||
# setup winbuild compilers
|
# setup winbuild compilers
|
||||||
if (${WinBuild})
|
if (${WinBuild})
|
||||||
|
message(STATUS "setup Mingw Toolchain for cross compile.")
|
||||||
set(LIBSUFFIX .dll)
|
set(LIBSUFFIX .dll)
|
||||||
set(SUFFIX .exe)
|
set(SUFFIX .exe)
|
||||||
|
|
||||||
@ -41,9 +43,9 @@ if (${WinBuild})
|
|||||||
#set(TOOLCHAIN_PREFIX i686-w64-mingw32)
|
#set(TOOLCHAIN_PREFIX i686-w64-mingw32)
|
||||||
|
|
||||||
# cross compilers to use for C and C++
|
# cross compilers to use for C and C++
|
||||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
set(CMAKE_C_COMPILER /usr/bin/${TOOLCHAIN_PREFIX}-gcc)
|
||||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
set(CMAKE_CXX_COMPILER /usr/bin/${TOOLCHAIN_PREFIX}-g++)
|
||||||
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
|
set(CMAKE_RC_COMPILER /usr/bin/${TOOLCHAIN_PREFIX}-windres)
|
||||||
|
|
||||||
# target environment on the build host system
|
# target environment on the build host system
|
||||||
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
|
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
|
||||||
@ -65,18 +67,31 @@ if (${WinBuild})
|
|||||||
# or set(CMAKE_CXX_STANDARD_LIBRARIES -lcurl -lpthread -static-libgcc -static-libstdc++ -lcrypto -lssl -lws2_32 -static -DCURL_STATICLIB)
|
# or set(CMAKE_CXX_STANDARD_LIBRARIES -lcurl -lpthread -static-libgcc -static-libstdc++ -lcrypto -lssl -lws2_32 -static -DCURL_STATICLIB)
|
||||||
# or add_definitions(-DCURL_STATICLIB)
|
# or add_definitions(-DCURL_STATICLIB)
|
||||||
|
|
||||||
# windows config path is same as executable
|
# windows config path is in %appdata% folder of user
|
||||||
set(CONFIG_PATH "./iprefresher.cfg")
|
set(CONFIG_PATH "std::string(std::getenv(\"USERPROFILE\")) + \"\\\\AppData\\\\Roaming\\\\DynuIPrefresher\\\\\"")
|
||||||
|
# temp file is also stored in appdata folder
|
||||||
|
set(TempFilePath "std::string(std::getenv(\"USERPROFILE\")) + \"\\\\AppData\\\\Roaming\\\\DynuIPrefresher\\\\\"")
|
||||||
else ()
|
else ()
|
||||||
|
message(STATUS "using nativ gcc toolchain.")
|
||||||
set(LIBSUFFIX .so)
|
set(LIBSUFFIX .so)
|
||||||
set(SUFFIX "")
|
set(SUFFIX "")
|
||||||
|
|
||||||
# set /etc/ config path
|
# set linux config path
|
||||||
set(CONFIG_PATH "/etc/iprefresher.cfg")
|
set(CONFIG_PATH "\"/etc/\"")
|
||||||
|
# set path of temp file
|
||||||
|
set(TempFilePath "\"/var/tmp/\"")
|
||||||
endif ()
|
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
|
# config libs
|
||||||
|
message("")
|
||||||
message(STATUS "Config of Libraries")
|
message(STATUS "Config of Libraries")
|
||||||
# libcurl
|
# libcurl
|
||||||
if (${WinBuild})
|
if (${WinBuild})
|
||||||
@ -89,7 +104,7 @@ if (${WinBuild})
|
|||||||
message(STATUS "Using CURL lib(s): ${CURL_LIBRARIES}")
|
message(STATUS "Using CURL lib(s): ${CURL_LIBRARIES}")
|
||||||
message(STATUS "")
|
message(STATUS "")
|
||||||
|
|
||||||
include_directories(${CURL_INCLUDE_DIRS} inc)
|
include_directories(${CURL_INCLUDE_DIRS})
|
||||||
|
|
||||||
# configure libconfig
|
# configure libconfig
|
||||||
FIND_PATH(LIBCONFIG++_INCLUDE_DIRS libconfig.h++ /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/include/) # search for libconfig include headers
|
FIND_PATH(LIBCONFIG++_INCLUDE_DIRS libconfig.h++ /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/include/) # search for libconfig include headers
|
||||||
@ -98,11 +113,11 @@ if (${WinBuild})
|
|||||||
message(STATUS "Using LIBCONFIG++ include dir(s): ${LIBCONFIG++_INCLUDE_DIRS}")
|
message(STATUS "Using LIBCONFIG++ include dir(s): ${LIBCONFIG++_INCLUDE_DIRS}")
|
||||||
message(STATUS "Using LIBCONFIG++ lib(s): ${LIBCONFIG++_LIBRARIES}")
|
message(STATUS "Using LIBCONFIG++ lib(s): ${LIBCONFIG++_LIBRARIES}")
|
||||||
|
|
||||||
include_directories(${LIBCONFIG++_INCLUDE_DIRS} inc)
|
|
||||||
|
|
||||||
if (${GUI})
|
if (${GUI})
|
||||||
set(CMAKE_PREFIX_PATH "/usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib/cmake")
|
set(CMAKE_PREFIX_PATH "/usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib/cmake")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
include_directories(${LIBCONFIG++_INCLUDE_DIRS})
|
||||||
else ()
|
else ()
|
||||||
find_package(CURL REQUIRED)
|
find_package(CURL REQUIRED)
|
||||||
if (CURL_INCLUDE_DIRS AND CURL_LIBRARIES)
|
if (CURL_INCLUDE_DIRS AND CURL_LIBRARIES)
|
||||||
@ -112,7 +127,7 @@ else ()
|
|||||||
else ()
|
else ()
|
||||||
message(FATAL_ERROR "Could not find CURL")
|
message(FATAL_ERROR "Could not find CURL")
|
||||||
endif ()
|
endif ()
|
||||||
include_directories(${CURL_INCLUDE_DIR} inc)
|
include_directories(${CURL_INCLUDE_DIR})
|
||||||
|
|
||||||
message("")
|
message("")
|
||||||
# libconfig
|
# libconfig
|
||||||
@ -134,6 +149,7 @@ else ()
|
|||||||
include_directories(${LIBCONFIG_INCLUDE_DIRS})
|
include_directories(${LIBCONFIG_INCLUDE_DIRS})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
|
||||||
if (${GUI})
|
if (${GUI})
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
@ -143,14 +159,16 @@ if (${GUI})
|
|||||||
find_package(Qt5Sql REQUIRED)
|
find_package(Qt5Sql REQUIRED)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
include_directories(inc)
|
||||||
|
|
||||||
message("")
|
message("")
|
||||||
|
|
||||||
#read sample config
|
#read sample config
|
||||||
FILE(READ ${CMAKE_SOURCE_DIR}/config/iprefresher.cfg SAMPLECONFIG)
|
FILE(READ ${CMAKE_SOURCE_DIR}/config/dynuiprefresher.cfg SAMPLECONFIG)
|
||||||
#add version header
|
#add StaticData header
|
||||||
FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h
|
FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/StaticData.h
|
||||||
"/**
|
"/**
|
||||||
* Version header to store Version, Config dir and a Sample config
|
* StaticData header to store Version, Config dir and a Sample config
|
||||||
* Do not edit this file manually, it is generated by the cmake script!
|
* Do not edit this file manually, it is generated by the cmake script!
|
||||||
*
|
*
|
||||||
* @author Lukas Heiligenbrunner
|
* @author Lukas Heiligenbrunner
|
||||||
@ -161,9 +179,11 @@ FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Version {
|
namespace StaticData {
|
||||||
const std::string VERSION = \"${PROJECT_VERSION}\";
|
const std::string VERSION = \"${PROJECT_VERSION}\";
|
||||||
const std::string ConfigDir = \"${CONFIG_PATH}\";
|
const std::string TempFilePath = ${TempFilePath};
|
||||||
|
const std::string ConfigDir = ${CONFIG_PATH};
|
||||||
|
const std::string ConfName = \"${Application_Name}.cfg\";
|
||||||
const std::string SAMPLECONFIG = R\"(${SAMPLECONFIG})\";
|
const std::string SAMPLECONFIG = R\"(${SAMPLECONFIG})\";
|
||||||
}"
|
}"
|
||||||
)
|
)
|
||||||
@ -174,7 +194,7 @@ add_library(api ${LIB_METHOD}
|
|||||||
src/api/DynuAPI.cpp
|
src/api/DynuAPI.cpp
|
||||||
src/api/IPAPI.cpp)
|
src/api/IPAPI.cpp)
|
||||||
|
|
||||||
add_library(dynuiprefresher ${LIB_METHOD}
|
add_library(libdynuiprefresher ${LIB_METHOD}
|
||||||
src/IPRefresher.cpp
|
src/IPRefresher.cpp
|
||||||
src/Config.cpp
|
src/Config.cpp
|
||||||
src/IpHelper.cpp
|
src/IpHelper.cpp
|
||||||
@ -182,10 +202,10 @@ add_library(dynuiprefresher ${LIB_METHOD}
|
|||||||
src/Logger.cpp
|
src/Logger.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(iprefresher src/main.cpp)
|
add_executable(${Application_Name} src/main.cpp)
|
||||||
|
|
||||||
# LINK generated LIBS #
|
# LINK generated LIBS #
|
||||||
target_link_libraries(iprefresher dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
|
target_link_libraries(${Application_Name} libdynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
|
||||||
|
|
||||||
if (${GUI})
|
if (${GUI})
|
||||||
set(QT5_LIBRARIES Qt5::Widgets Qt5::PrintSupport Qt5::Sql)
|
set(QT5_LIBRARIES Qt5::Widgets Qt5::PrintSupport Qt5::Sql)
|
||||||
@ -220,9 +240,9 @@ IF (NOT ${WinBuild})
|
|||||||
# INSTALL to Linux SYSTEM #
|
# INSTALL to Linux SYSTEM #
|
||||||
|
|
||||||
# install binaries
|
# install binaries
|
||||||
install(TARGETS iprefresher DESTINATION usr/bin)
|
install(TARGETS ${Application_Name} DESTINATION usr/bin)
|
||||||
# install systemd service and enable it
|
# 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)
|
||||||
|
|
||||||
if (${GUI})
|
if (${GUI})
|
||||||
# install binaries
|
# install binaries
|
||||||
@ -232,8 +252,8 @@ ELSE ()
|
|||||||
# INSTALL to Windows SYSTEM #
|
# INSTALL to Windows SYSTEM #
|
||||||
|
|
||||||
# install binary to current folder
|
# install binary to current folder
|
||||||
set_target_properties(iprefresher PROPERTIES SUFFIX ".exe")
|
set_target_properties(${Application_Name} PROPERTIES SUFFIX ".exe")
|
||||||
install(TARGETS iprefresher DESTINATION .)
|
install(TARGETS ${Application_Name} DESTINATION .)
|
||||||
|
|
||||||
# install .dll dependencies
|
# install .dll dependencies
|
||||||
# todo check if files exist...
|
# todo check if files exist...
|
||||||
@ -301,8 +321,10 @@ if (${PACKAGING})
|
|||||||
if [ ! -f ${CONFIG_PATH} ]; then
|
if [ ! -f ${CONFIG_PATH} ]; then
|
||||||
cat > ${CONFIG_PATH} <<- EOM
|
cat > ${CONFIG_PATH} <<- EOM
|
||||||
${SAMPLECONFIG}EOM
|
${SAMPLECONFIG}EOM
|
||||||
fi\n"
|
fi
|
||||||
)
|
|
||||||
|
systemctl enable ${Application_Name}.service
|
||||||
|
systemctl start ${Application_Name}.service")
|
||||||
|
|
||||||
|
|
||||||
SET(CPACK_DEB_COMPONENT_INSTALL 1)
|
SET(CPACK_DEB_COMPONENT_INSTALL 1)
|
||||||
@ -371,8 +393,8 @@ fi\n"
|
|||||||
|
|
||||||
add_custom_target(build-packages
|
add_custom_target(build-packages
|
||||||
"${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target package
|
"${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target package
|
||||||
DEPENDS ${PROJECT_NAME}
|
DEPENDS ${Application_Name}
|
||||||
COMMENT "Packing ${PROJECT_NAME}")
|
COMMENT "Packing ${Application_Name}")
|
||||||
message("")
|
message("")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
@ -403,39 +425,40 @@ endif (BUILD_DOC)
|
|||||||
|
|
||||||
# Test Cases
|
# Test Cases
|
||||||
if (TESTS)
|
if (TESTS)
|
||||||
include(GoogleTest)
|
# include(GoogleTest)
|
||||||
|
message(STATUS "Configuring GTEST")
|
||||||
|
find_package(GTest)
|
||||||
|
if (GTEST_FOUND)
|
||||||
|
|
||||||
mark_as_advanced(
|
mark_as_advanced(
|
||||||
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
|
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
|
||||||
gmock_build_tests gtest_build_samples gtest_build_tests
|
gmock_build_tests gtest_build_samples gtest_build_tests
|
||||||
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
|
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
|
||||||
)
|
)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
macro(package_add_test TESTNAME)
|
macro(package_add_test TESTNAME)
|
||||||
# create an exectuable in which the tests will be stored
|
# create an exectuable in which the tests will be stored
|
||||||
add_executable(${TESTNAME} ${ARGN})
|
add_executable(${TESTNAME} ${ARGN})
|
||||||
# link the Google test infrastructure, mocking library, and a default main fuction to
|
# 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
|
# see https://cmake.org/cmake/help/v3.10/module/GoogleTest.html for more options to pass to it
|
||||||
gtest_discover_tests(${TESTNAME}
|
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)
|
|
||||||
endmacro()
|
|
||||||
|
|
||||||
package_add_test(test1 tests/UnitTest.cpp ${SOURCE})
|
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
|
add_custom_target(build-test
|
||||||
"${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target test
|
DEPENDS ${PROJECT_NAME}
|
||||||
DEPENDS ${PROJECT_NAME}
|
COMMENT "Testing ${PROJECT_NAME}")
|
||||||
COMMENT "Packing ${PROJECT_NAME}")
|
|
||||||
|
|
||||||
add_custom_target(build-xml
|
package_add_test(test1 tests/UnitTest.cpp ${SOURCE})
|
||||||
"bin/test1" --gtest_output="xml:report.xml"
|
|
||||||
DEPENDS ${PROJECT_NAME}
|
else ()
|
||||||
COMMENT "Packing ${PROJECT_NAME}")
|
message(STATUS "GTEST environment not found!")
|
||||||
|
endif ()
|
||||||
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).
|
But you can still compile the code my your own (see build section).
|
||||||
|
|
||||||
## Configuration
|
## 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.
|
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:
|
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
|
## Build
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Version.h"
|
#include "StaticData.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <libconfig.h++>
|
#include <libconfig.h++>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
std::string Config::dynuapikey;
|
std::string Config::dynuapikey;
|
||||||
std::string Config::domainid; //id of the dynu domain
|
std::string Config::domainid; //id of the dynu domain
|
||||||
@ -19,15 +20,41 @@ bool Config::telegramSupport;
|
|||||||
bool Config::readConfig() {
|
bool Config::readConfig() {
|
||||||
libconfig::Config cfg;
|
libconfig::Config cfg;
|
||||||
try {
|
try {
|
||||||
cfg.readFile(Version::ConfigDir.c_str());
|
cfg.readFile(std::string(StaticData::ConfigDir + StaticData::ConfName).c_str());
|
||||||
}
|
}
|
||||||
catch (const libconfig::FileIOException &fioex) {
|
catch (const libconfig::FileIOException &fioex) {
|
||||||
std::cout << "I/O error while reading config file." << std::endl << "creating new config file!" << std::endl;
|
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(StaticData::ConfigDir.c_str(), &info) != 0) {
|
||||||
|
Logger::warning("The config folder doesn't exist. Trying to create it.");
|
||||||
|
|
||||||
|
// mkdir command is different defined for windows
|
||||||
|
#ifdef __unix
|
||||||
|
int check = mkdir(StaticData::ConfigDir.c_str(), 777);
|
||||||
|
#else
|
||||||
|
int check = mkdir(StaticData::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;
|
std::ofstream myfile;
|
||||||
myfile.open(Version::ConfigDir);
|
myfile.open(StaticData::ConfigDir + StaticData::ConfName);
|
||||||
if (myfile.is_open()) {
|
if (myfile.is_open()) {
|
||||||
myfile << Version::SAMPLECONFIG;
|
myfile << StaticData::SAMPLECONFIG;
|
||||||
myfile.close();
|
myfile.close();
|
||||||
} else {
|
} else {
|
||||||
Logger::error("error creating file");
|
Logger::error("error creating file");
|
||||||
@ -73,7 +100,7 @@ bool Config::validateConfig() {
|
|||||||
libconfig::Config cfg;
|
libconfig::Config cfg;
|
||||||
try {
|
try {
|
||||||
Logger::message("reading config file");
|
Logger::message("reading config file");
|
||||||
cfg.readFile(Version::ConfigDir.c_str());
|
cfg.readFile(StaticData::ConfigDir.c_str());
|
||||||
}
|
}
|
||||||
catch (const libconfig::FileIOException &fioex) {
|
catch (const libconfig::FileIOException &fioex) {
|
||||||
Logger::warning("config file doesn't exist or permission denied!");
|
Logger::warning("config file doesn't exist or permission denied!");
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#include "FileLogger.h"
|
#include "FileLogger.h"
|
||||||
#include "IpHelper.h"
|
#include "IpHelper.h"
|
||||||
|
#include "StaticData.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void FileLogger::safeip(std::string ip) {
|
void FileLogger::safeip(std::string ip) {
|
||||||
std::ofstream out;
|
std::ofstream out;
|
||||||
out.open("ip.txt", std::ios::out);
|
out.open(StaticData::TempFilePath + "temp-dynuiprefresher.txt", std::ios::out);
|
||||||
|
|
||||||
out << ip;
|
out << ip;
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ void FileLogger::safeip(std::string ip) {
|
|||||||
|
|
||||||
std::string FileLogger::readip() {
|
std::string FileLogger::readip() {
|
||||||
std::ifstream in;
|
std::ifstream in;
|
||||||
in.open("ip.txt", std::ios::in);
|
in.open(StaticData::TempFilePath + "temp-dynuiprefresher.txt", std::ios::in);
|
||||||
|
|
||||||
std::string ip;
|
std::string ip;
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "api/DynuAPI.h"
|
#include "api/DynuAPI.h"
|
||||||
#include "api/TelegramAPI.h"
|
#include "api/TelegramAPI.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Version.h"
|
#include "StaticData.h"
|
||||||
#include "IpHelper.h"
|
#include "IpHelper.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@ -59,15 +59,18 @@ bool IPRefresher::checkIPAdress(bool force) {
|
|||||||
|
|
||||||
void IPRefresher::startUpService(int interval) {
|
void IPRefresher::startUpService(int interval) {
|
||||||
Logger::message("startup of service");
|
Logger::message("startup of service");
|
||||||
Logger::message("Version: " + Version::VERSION);
|
Logger::message("Version: " + StaticData::VERSION);
|
||||||
if (Config::readConfig()) {
|
if (Config::readConfig()) {
|
||||||
while (true) {
|
while (true) {
|
||||||
Logger::message("starting check");
|
Logger::message("starting check");
|
||||||
checkIPAdress(false);
|
if (Config::readConfig()) {
|
||||||
|
checkIPAdress(false);
|
||||||
|
} else {
|
||||||
|
std::cout << "incorrect credentials!" << std::endl;
|
||||||
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(interval * 1000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(interval * 1000));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::cout << "incorrect credentials!" << std::endl;
|
std::cout << "incorrect credentials!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include "IpHelper.h"
|
#include "IpHelper.h"
|
||||||
|
|
||||||
#include <climits>
|
|
||||||
|
|
||||||
bool IpHelper::isIpValid(std::string ip) {
|
bool IpHelper::isIpValid(std::string ip) {
|
||||||
return (ip.find('.') != ULONG_MAX);
|
return (ip.find('.') != SIZE_MAX);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#include "api/TelegramAPI.h"
|
#include "api/TelegramAPI.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
#include <climits>
|
|
||||||
|
|
||||||
int TelegramAPI::sendMessage(const std::string &text) {
|
int TelegramAPI::sendMessage(const std::string &text) {
|
||||||
Hashmap<std::string, std::string> args;
|
Hashmap<std::string, std::string> args;
|
||||||
args.add("chat_id", chatid);
|
args.add("chat_id", chatid);
|
||||||
@ -12,8 +10,8 @@ int TelegramAPI::sendMessage(const std::string &text) {
|
|||||||
|
|
||||||
std::string reply = request("https://api.telegram.org/bot" + apikey + "/sendmessage", false, args, headers);
|
std::string reply = request("https://api.telegram.org/bot" + apikey + "/sendmessage", false, args, headers);
|
||||||
|
|
||||||
if (reply.find("\"error_code\"") != ULONG_MAX) {
|
if (reply.find("\"error_code\"") != SIZE_MAX) {
|
||||||
Logger::error("failed to refresh the ip (Dynu API)");
|
Logger::error("failed to send the Telegram Message");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "Version.h"
|
#include "StaticData.h"
|
||||||
#include "IPRefresher.h"
|
#include "IPRefresher.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
@ -19,7 +19,7 @@ int main(int argc, char *argv[]) {
|
|||||||
<< "[-ip] [--currentip] get current global ip" << std::endl
|
<< "[-ip] [--currentip] get current global ip" << 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 " << Version::VERSION << std::endl;
|
std::cout << "Version " << StaticData::VERSION << std::endl;
|
||||||
} else if (firstarg == "-f" || firstarg == "--force") {
|
} else if (firstarg == "-f" || firstarg == "--force") {
|
||||||
if (Config::readConfig()) {
|
if (Config::readConfig()) {
|
||||||
IPRefresher::checkIPAdress(true);
|
IPRefresher::checkIPAdress(true);
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include <FileLogger.h>
|
#include <FileLogger.h>
|
||||||
#include <api/IPAPI.h>
|
#include <api/IPAPI.h>
|
||||||
#include <climits>
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,7 +20,7 @@ TEST(ReadIp, testzeroIpIfNotExists) {
|
|||||||
TEST(IPAPI, testIpAPIcheckIPSyntax) {
|
TEST(IPAPI, testIpAPIcheckIPSyntax) {
|
||||||
IPAPI ipapi;
|
IPAPI ipapi;
|
||||||
std::string ip = ipapi.getGlobalIp();
|
std::string ip = ipapi.getGlobalIp();
|
||||||
if (ip.find('.') == ULONG_MAX) {
|
if (ip.find('.') == SIZE_MAX) {
|
||||||
// error when ip doesn't contain a .
|
// error when ip doesn't contain a .
|
||||||
ASSERT_TRUE(false);
|
ASSERT_TRUE(false);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user