Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
b5b352f83d | |||
3b32f60190 | |||
0eea7095e0 | |||
ab772aac55 | |||
c25996a925 |
@ -1,95 +1,49 @@
|
|||||||
|
image: luki42/dynuiprefresher_build:latest
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- cmake
|
- cmake
|
||||||
- build
|
- build
|
||||||
- post
|
- build_package
|
||||||
|
- 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 iprefresher
|
- make
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- build/
|
- "build/bin/*"
|
||||||
- inc/
|
|
||||||
- postinst
|
|
||||||
dependencies:
|
|
||||||
- cmake
|
|
||||||
|
|
||||||
|
|
||||||
build_package:
|
build_package:
|
||||||
stage: post
|
stage: build_package
|
||||||
image: luki42/dynuiprefresher_build:latest
|
|
||||||
script:
|
script:
|
||||||
- cd build
|
- cd build
|
||||||
- make package
|
- make package
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- build/
|
- "build/packages/*"
|
||||||
- inc/
|
|
||||||
- postinst
|
|
||||||
dependencies:
|
|
||||||
- build
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
stage: post
|
stage: test
|
||||||
image: luki42/dynuiprefresher_build:latest
|
|
||||||
script:
|
script:
|
||||||
- cd build
|
- cd build
|
||||||
- make build-test
|
- make test
|
||||||
|
- make build-xml
|
||||||
artifacts:
|
artifacts:
|
||||||
reports:
|
reports:
|
||||||
junit: build/*.xml
|
junit: build/report.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
|
|
151
CMakeLists.txt
151
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(dynuiprefresher DESCRIPTION "Dynu ip refresher" LANGUAGES)
|
project(iprefresher DESCRIPTION "Dynu ip refresher")
|
||||||
SET(PROJECT_VERSION 1.3.4)
|
SET(PROJECT_VERSION 1.3.3)
|
||||||
|
|
||||||
# CONFIGURATION
|
# CONFIGURATION
|
||||||
SET(CMAKE_BUILD_TYPE Release) # manually SET build type (Release / Debug)
|
SET(CMAKE_BUILD_TYPE Release) # manually SET build type (Release / Debug)
|
||||||
@ -19,12 +19,12 @@ SET(LIB_METHOD STATIC) #SHARED / STATIC
|
|||||||
option(BUILD_DOC "Build documentation" ON) # additional dependency for Doxygen
|
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(WinBuild "cross compile for Windows Platform" OFF)
|
option(GUI "Build GUI elements" ON) # additional dependencies to QT libraries needed
|
||||||
|
set(WinBuild false)
|
||||||
|
|
||||||
# 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,7 +32,6 @@ 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)
|
||||||
|
|
||||||
@ -42,9 +41,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 /usr/bin/${TOOLCHAIN_PREFIX}-gcc)
|
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
||||||
set(CMAKE_CXX_COMPILER /usr/bin/${TOOLCHAIN_PREFIX}-g++)
|
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
||||||
set(CMAKE_RC_COMPILER /usr/bin/${TOOLCHAIN_PREFIX}-windres)
|
set(CMAKE_RC_COMPILER ${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})
|
||||||
@ -67,26 +66,17 @@ if (${WinBuild})
|
|||||||
# or add_definitions(-DCURL_STATICLIB)
|
# or add_definitions(-DCURL_STATICLIB)
|
||||||
|
|
||||||
# windows config path is same as executable
|
# windows config path is same as executable
|
||||||
set(CONFIG_PATH "std::string(std::getenv(\"USERPROFILE\")) + \"\\\\AppData\\\\Roaming\\\\DynuIPrefresher\\\\\"")
|
set(CONFIG_PATH "./iprefresher.cfg")
|
||||||
else ()
|
else ()
|
||||||
message(STATUS "using nativ gcc toolchain.")
|
|
||||||
set(LIBSUFFIX .so)
|
set(LIBSUFFIX .so)
|
||||||
set(SUFFIX "")
|
set(SUFFIX "")
|
||||||
|
|
||||||
# set /etc/ config path
|
# set /etc/ config path
|
||||||
set(CONFIG_PATH "\"/etc/\"")
|
set(CONFIG_PATH "/etc/iprefresher.cfg")
|
||||||
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})
|
||||||
@ -109,6 +99,10 @@ if (${WinBuild})
|
|||||||
message(STATUS "Using LIBCONFIG++ lib(s): ${LIBCONFIG++_LIBRARIES}")
|
message(STATUS "Using LIBCONFIG++ lib(s): ${LIBCONFIG++_LIBRARIES}")
|
||||||
|
|
||||||
include_directories(${LIBCONFIG++_INCLUDE_DIRS} inc)
|
include_directories(${LIBCONFIG++_INCLUDE_DIRS} inc)
|
||||||
|
|
||||||
|
if (${GUI})
|
||||||
|
set(CMAKE_PREFIX_PATH "/usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib/cmake")
|
||||||
|
endif ()
|
||||||
else ()
|
else ()
|
||||||
find_package(CURL REQUIRED)
|
find_package(CURL REQUIRED)
|
||||||
if (CURL_INCLUDE_DIRS AND CURL_LIBRARIES)
|
if (CURL_INCLUDE_DIRS AND CURL_LIBRARIES)
|
||||||
@ -140,10 +134,19 @@ else ()
|
|||||||
include_directories(${LIBCONFIG_INCLUDE_DIRS})
|
include_directories(${LIBCONFIG_INCLUDE_DIRS})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (${GUI})
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
find_package(Qt5Widgets REQUIRED)
|
||||||
|
find_package(Qt5PrintSupport REQUIRED)
|
||||||
|
find_package(Qt5Sql REQUIRED)
|
||||||
|
endif ()
|
||||||
|
|
||||||
message("")
|
message("")
|
||||||
|
|
||||||
#read sample config
|
#read sample config
|
||||||
FILE(READ ${CMAKE_SOURCE_DIR}/config/dynuiprefresher.cfg SAMPLECONFIG)
|
FILE(READ ${CMAKE_SOURCE_DIR}/config/iprefresher.cfg SAMPLECONFIG)
|
||||||
#add version header
|
#add version header
|
||||||
FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h
|
FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h
|
||||||
"/**
|
"/**
|
||||||
@ -160,8 +163,7 @@ FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h
|
|||||||
|
|
||||||
namespace Version {
|
namespace Version {
|
||||||
const std::string VERSION = \"${PROJECT_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})\";
|
const std::string SAMPLECONFIG = R\"(${SAMPLECONFIG})\";
|
||||||
}"
|
}"
|
||||||
)
|
)
|
||||||
@ -172,7 +174,7 @@ add_library(api ${LIB_METHOD}
|
|||||||
src/api/DynuAPI.cpp
|
src/api/DynuAPI.cpp
|
||||||
src/api/IPAPI.cpp)
|
src/api/IPAPI.cpp)
|
||||||
|
|
||||||
add_library(libdynuiprefresher ${LIB_METHOD}
|
add_library(dynuiprefresher ${LIB_METHOD}
|
||||||
src/IPRefresher.cpp
|
src/IPRefresher.cpp
|
||||||
src/Config.cpp
|
src/Config.cpp
|
||||||
src/IpHelper.cpp
|
src/IpHelper.cpp
|
||||||
@ -180,25 +182,47 @@ add_library(libdynuiprefresher ${LIB_METHOD}
|
|||||||
src/Logger.cpp
|
src/Logger.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(${Application_Name} src/main.cpp)
|
add_executable(iprefresher src/main.cpp)
|
||||||
|
|
||||||
# LINK generated LIBS #
|
# LINK generated LIBS #
|
||||||
target_link_libraries(${Application_Name} libdynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
|
target_link_libraries(iprefresher dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
|
||||||
|
|
||||||
|
if (${GUI})
|
||||||
|
set(QT5_LIBRARIES Qt5::Widgets Qt5::PrintSupport Qt5::Sql)
|
||||||
|
|
||||||
|
set(UI_SOURCES
|
||||||
|
src/gui/mainwindow.ui
|
||||||
|
)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Generate necessary headers from .ui files. (qmake lets `uic` do this job.)
|
||||||
|
# hint from [Cross-platform Qt5 project using cmake](http://stackoverflow.com/questions/21174586/cross-platform-qt5-project-using-cmake)
|
||||||
|
#
|
||||||
|
qt5_wrap_ui(UI_GENERATED_HEADERS ${UI_SOURCES})
|
||||||
|
|
||||||
|
add_executable(iprefresher-gui
|
||||||
|
src/maingui.cpp
|
||||||
|
src/gui/MainWindow.cpp
|
||||||
|
src/gui/MainWindow.h ${UI_GENERATED_HEADERS})
|
||||||
|
|
||||||
|
# LINK generated LIBS #
|
||||||
|
target_link_libraries(iprefresher-gui -lpthread dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES} ${QT5_LIBRARIES})
|
||||||
|
endif ()
|
||||||
|
|
||||||
# setting install targets
|
# setting install targets
|
||||||
IF (NOT ${WinBuild})
|
IF (NOT ${WinBuild})
|
||||||
# INSTALL to Linux SYSTEM #
|
# INSTALL to Linux SYSTEM #
|
||||||
|
|
||||||
# install binaries
|
# install binaries
|
||||||
install(TARGETS ${Application_Name} DESTINATION usr/bin)
|
install(TARGETS iprefresher DESTINATION usr/bin)
|
||||||
# install systemd service and enable it
|
# install systemd service and enable it
|
||||||
install(FILES service/${Application_Name}.service DESTINATION lib/systemd/system)
|
install(FILES service/iprefresher.service DESTINATION lib/systemd/system)
|
||||||
ELSE ()
|
ELSE ()
|
||||||
# INSTALL to Windows SYSTEM #
|
# INSTALL to Windows SYSTEM #
|
||||||
|
|
||||||
# install binary to current folder
|
# install binary to current folder
|
||||||
set_target_properties(${Application_Name} PROPERTIES SUFFIX ".exe")
|
set_target_properties(iprefresher PROPERTIES SUFFIX ".exe")
|
||||||
install(TARGETS ${Application_Name} DESTINATION .)
|
install(TARGETS iprefresher DESTINATION .)
|
||||||
|
|
||||||
# install .dll dependencies
|
# install .dll dependencies
|
||||||
# todo check if files exist...
|
# todo check if files exist...
|
||||||
@ -238,10 +262,8 @@ 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
|
fi\n"
|
||||||
|
)
|
||||||
systemctl enable ${Application_Name}.service
|
|
||||||
systemctl start ${Application_Name}.service")
|
|
||||||
|
|
||||||
|
|
||||||
SET(CPACK_DEB_COMPONENT_INSTALL 1)
|
SET(CPACK_DEB_COMPONENT_INSTALL 1)
|
||||||
@ -293,8 +315,8 @@ systemctl start ${Application_Name}.service")
|
|||||||
|
|
||||||
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 ${Application_Name}
|
DEPENDS ${PROJECT_NAME}
|
||||||
COMMENT "Packing ${Application_Name}")
|
COMMENT "Packing ${PROJECT_NAME}")
|
||||||
message("")
|
message("")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
@ -325,40 +347,39 @@ 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 libdynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
|
target_link_libraries(${TESTNAME} gtest gtest_main -lpthread -lm dynuiprefresher 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()
|
||||||
|
|
||||||
add_custom_command(TARGET build-test
|
package_add_test(test1 tests/UnitTest.cpp ${SOURCE})
|
||||||
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
|
||||||
DEPENDS ${PROJECT_NAME}
|
"${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target test
|
||||||
COMMENT "Testing ${PROJECT_NAME}")
|
DEPENDS ${PROJECT_NAME}
|
||||||
|
COMMENT "Packing ${PROJECT_NAME}")
|
||||||
|
|
||||||
package_add_test(test1 tests/UnitTest.cpp ${SOURCE})
|
add_custom_target(build-xml
|
||||||
|
"bin/test1" --gtest_output="xml:report.xml"
|
||||||
else ()
|
DEPENDS ${PROJECT_NAME}
|
||||||
message(STATUS "GTEST environment not found!")
|
COMMENT "Packing ${PROJECT_NAME}")
|
||||||
endif ()
|
|
||||||
ENDIF ()
|
ENDIF ()
|
20
README.md
20
README.md
@ -9,27 +9,11 @@ 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/dynuiprefresher.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/iprefresher.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 dynuiprefresher.service` and `systemctl start dynuiprefresher.service`
|
`systemctl enable iprefresher.service` and `systemctl start iprefresher.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
|
||||||
|
@ -9,22 +9,25 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class IPRefresher {
|
namespace IPRefresher {
|
||||||
public:
|
/**
|
||||||
|
* Status return-codes for startUpService
|
||||||
|
*/
|
||||||
|
namespace Status_Code {
|
||||||
|
const int SUCCESS = 1;
|
||||||
|
const int ERROR = -1;
|
||||||
|
const int ERROR_NO_INTERNET = -2;
|
||||||
|
const int NOREFRESH = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* refresh ip address on Dynu server
|
* refresh ip address on Dynu server
|
||||||
*/
|
*/
|
||||||
void checkIPAdress(bool force);
|
bool checkIPAdress(bool force);
|
||||||
|
|
||||||
/**
|
|
||||||
* default constructor
|
|
||||||
*/
|
|
||||||
IPRefresher() = default;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* start the service in loop mode
|
* start the service in loop mode
|
||||||
* every 5 minutes the ip is checked an refreshed (needed for .service)
|
* every 5 minutes the ip is checked an refreshed (needed for .service)
|
||||||
* @param loop true->loopmode on
|
|
||||||
*/
|
*/
|
||||||
explicit IPRefresher(bool loop);
|
void startUpService(int interval = 300);
|
||||||
};
|
}
|
@ -6,7 +6,6 @@
|
|||||||
#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
|
||||||
@ -20,38 +19,13 @@ bool Config::telegramSupport;
|
|||||||
bool Config::readConfig() {
|
bool Config::readConfig() {
|
||||||
libconfig::Config cfg;
|
libconfig::Config cfg;
|
||||||
try {
|
try {
|
||||||
cfg.readFile(std::string(Version::ConfigDir + Version::ConfName).c_str());
|
cfg.readFile(Version::ConfigDir.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(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;
|
std::ofstream myfile;
|
||||||
myfile.open(Version::ConfigDir + Version::ConfName);
|
myfile.open(Version::ConfigDir);
|
||||||
if (myfile.is_open()) {
|
if (myfile.is_open()) {
|
||||||
myfile << Version::SAMPLECONFIG;
|
myfile << Version::SAMPLECONFIG;
|
||||||
myfile.close();
|
myfile.close();
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <Logger.h>
|
#include <Logger.h>
|
||||||
|
|
||||||
void IPRefresher::checkIPAdress(bool force) {
|
using namespace IPRefresher;
|
||||||
|
|
||||||
|
bool IPRefresher::checkIPAdress(bool force) {
|
||||||
FileLogger logger;
|
FileLogger logger;
|
||||||
|
|
||||||
IPAPI ipapi;
|
IPAPI ipapi;
|
||||||
@ -20,14 +22,17 @@ void IPRefresher::checkIPAdress(bool force) {
|
|||||||
if (ip.empty()) {
|
if (ip.empty()) {
|
||||||
//no internet connection (or other error)
|
//no internet connection (or other error)
|
||||||
Logger::warning("no internet connection");
|
Logger::warning("no internet connection");
|
||||||
|
return Status_Code::ERROR_NO_INTERNET;
|
||||||
} else if (!IpHelper::isIpValid(ip)) {
|
} else if (!IpHelper::isIpValid(ip)) {
|
||||||
// error when ip doesn't contain a :
|
// error when ip doesn't contain a :
|
||||||
Logger::warning("an error occured when getting the global ip");
|
Logger::warning("an error occured when getting the global ip");
|
||||||
|
return Status_Code::ERROR;
|
||||||
} else {
|
} else {
|
||||||
std::string oldip = logger.readip();
|
std::string oldip = logger.readip();
|
||||||
|
|
||||||
if (oldip == ip && !force) {
|
if (oldip == ip && !force) {
|
||||||
Logger::message("no change -- ip: " + ip);
|
Logger::message("no change -- ip: " + ip);
|
||||||
|
return Status_Code::NOREFRESH;
|
||||||
} else {
|
} else {
|
||||||
Logger::message("ip changed! -- from :" + oldip + "to: " + ip);
|
Logger::message("ip changed! -- from :" + oldip + "to: " + ip);
|
||||||
|
|
||||||
@ -43,26 +48,26 @@ void IPRefresher::checkIPAdress(bool force) {
|
|||||||
} else if (!result) {
|
} else if (!result) {
|
||||||
//error
|
//error
|
||||||
Logger::error("failed to write ip to dynu api!");
|
Logger::error("failed to write ip to dynu api!");
|
||||||
|
return Status_Code::ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.safeip(ip);
|
logger.safeip(ip);
|
||||||
|
return result ? Status_Code::SUCCESS : Status_Code::ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IPRefresher::IPRefresher(bool loop) {
|
void IPRefresher::startUpService(int interval) {
|
||||||
if (loop) {
|
Logger::message("startup of service");
|
||||||
Logger::message("startup of service");
|
Logger::message("Version: " + Version::VERSION);
|
||||||
Logger::message("Version: " + Version::VERSION);
|
if (Config::readConfig()) {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
Logger::message("starting check");
|
Logger::message("starting check");
|
||||||
if (Config::readConfig()) {
|
checkIPAdress(false);
|
||||||
checkIPAdress(false);
|
std::this_thread::sleep_for(std::chrono::milliseconds(interval * 1000));
|
||||||
} else {
|
|
||||||
std::cout << "incorrect credentials!" << std::endl;
|
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(300000));
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
std::cout << "incorrect credentials!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
84
src/gui/MainWindow.cpp
Normal file
84
src/gui/MainWindow.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
#include "MainWindow.h"
|
||||||
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
|
#include "api/IPAPI.h"
|
||||||
|
#include "IPRefresher.h"
|
||||||
|
#include "Config.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
MainWindow::MainWindow() : QMainWindow(), ui(new Ui::MainWindow) {
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
// needs to be defined with new -- would be termintated after this constructor.
|
||||||
|
new std::thread([this]() {
|
||||||
|
IPAPI ipapi;
|
||||||
|
std::string ip = ipapi.getGlobalIp();
|
||||||
|
Logger::message("Current global IP: " + ip);
|
||||||
|
std::string msg = "Your current global IP: " + ip;
|
||||||
|
this->ui->labelCurrentIP->setText(msg.c_str());
|
||||||
|
});
|
||||||
|
|
||||||
|
// set config info label and initial check if config is valid
|
||||||
|
ui->labelConfig->setText(Config::validateConfig() ? "Config is: OK" : "Config is: NOT OK");
|
||||||
|
|
||||||
|
connect(ui->buttonCheckConfig, SIGNAL(clicked()), this, SLOT(checkConfigBtn()));
|
||||||
|
connect(ui->buttonRefreshIP, SIGNAL(clicked()), this, SLOT(refreshIPBtn()));
|
||||||
|
|
||||||
|
connect(this, SIGNAL(appendLogField(QString)), ui->textLog, SLOT(appendPlainText(QString)));
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow() {
|
||||||
|
// todo check if disconnects are really necessary
|
||||||
|
disconnect(ui->buttonCheckConfig);
|
||||||
|
disconnect(ui->buttonRefreshIP);
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::checkConfigBtn() {
|
||||||
|
Logger::message("checking config!");
|
||||||
|
appendLogField("checking config!");
|
||||||
|
|
||||||
|
if (Config::validateConfig()) {
|
||||||
|
Logger::message("Config file is OK");
|
||||||
|
appendLogField("Config file is OK");
|
||||||
|
ui->labelConfig->setText("Config is: OK");
|
||||||
|
} else {
|
||||||
|
Logger::error("There are errors in config file!");
|
||||||
|
appendLogField("There are errors in config file!");
|
||||||
|
}
|
||||||
|
appendLogField("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::refreshIPBtn() {
|
||||||
|
Logger::message("start refreshing Dynu IP.");
|
||||||
|
appendLogField("");
|
||||||
|
appendLogField("start refreshing Dynu IP.");
|
||||||
|
new std::thread([this]() {
|
||||||
|
if (Config::readConfig()) {
|
||||||
|
int code = IPRefresher::checkIPAdress(false);
|
||||||
|
switch (code) {
|
||||||
|
case IPRefresher::Status_Code::SUCCESS:
|
||||||
|
appendLogField("successfully refreshed IP!");
|
||||||
|
break;
|
||||||
|
case IPRefresher::Status_Code::NOREFRESH:
|
||||||
|
appendLogField("IP is already correct.");
|
||||||
|
break;
|
||||||
|
case IPRefresher::Status_Code::ERROR_NO_INTERNET:
|
||||||
|
appendLogField("Error: No Internet connection");
|
||||||
|
break;
|
||||||
|
case IPRefresher::Status_Code::ERROR:
|
||||||
|
appendLogField("An error occured while refreshing.");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
appendLogField("An unknown error code occured");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::cout << "incorrect credentials!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::message("Finished refreshing Dynu IP.");
|
||||||
|
this->appendLogField("Finished refreshing Dynu IP.");
|
||||||
|
});
|
||||||
|
}
|
50
src/gui/MainWindow.h
Normal file
50
src/gui/MainWindow.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* Main GUI controller - User IO handlings
|
||||||
|
*
|
||||||
|
* @author Lukas Heiligenbrunner
|
||||||
|
* @date 09.05.2020
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QtWidgets/QMainWindow>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class MainWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
class MainWindow : public QMainWindow {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* constructor with basic initializations
|
||||||
|
*/
|
||||||
|
explicit MainWindow();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* destruct all gui elements
|
||||||
|
*/
|
||||||
|
~MainWindow();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::MainWindow *ui;
|
||||||
|
private slots:
|
||||||
|
/**
|
||||||
|
* executed click handler for config button
|
||||||
|
*/
|
||||||
|
void checkConfigBtn();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* executed click handler for refresh btn
|
||||||
|
*/
|
||||||
|
void refreshIPBtn();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/**
|
||||||
|
* append a String line to the Log field
|
||||||
|
*
|
||||||
|
* @param QString string to be appended
|
||||||
|
*/
|
||||||
|
void appendLogField(QString);
|
||||||
|
};
|
103
src/gui/mainwindow.ui
Normal file
103
src/gui/mainwindow.ui
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>823</width>
|
||||||
|
<height>618</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MainWindow</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<widget class="QPushButton" name="buttonRefreshIP">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>290</x>
|
||||||
|
<y>300</y>
|
||||||
|
<width>91</width>
|
||||||
|
<height>33</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Refresh IP</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="labelCurrentIP">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>40</x>
|
||||||
|
<y>60</y>
|
||||||
|
<width>301</width>
|
||||||
|
<height>17</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Your current global IP:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPlainTextEdit" name="textLog">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>40</x>
|
||||||
|
<y>410</y>
|
||||||
|
<width>691</width>
|
||||||
|
<height>191</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="cursor" stdset="0">
|
||||||
|
<cursorShape>IBeamCursor</cursorShape>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>40</x>
|
||||||
|
<y>380</y>
|
||||||
|
<width>64</width>
|
||||||
|
<height>17</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Log:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPushButton" name="buttonCheckConfig">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>270</x>
|
||||||
|
<y>140</y>
|
||||||
|
<width>91</width>
|
||||||
|
<height>33</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Check Config</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="labelConfig">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>270</x>
|
||||||
|
<y>180</y>
|
||||||
|
<width>141</width>
|
||||||
|
<height>17</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Config is: undefined</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@ -21,15 +21,14 @@ int main(int argc, char *argv[]) {
|
|||||||
} else if (firstarg == "-v" || firstarg == "--version") {
|
} else if (firstarg == "-v" || firstarg == "--version") {
|
||||||
std::cout << "Version " << Version::VERSION << std::endl;
|
std::cout << "Version " << Version::VERSION << std::endl;
|
||||||
} else if (firstarg == "-f" || firstarg == "--force") {
|
} else if (firstarg == "-f" || firstarg == "--force") {
|
||||||
IPRefresher ipr;
|
|
||||||
if (Config::readConfig()) {
|
if (Config::readConfig()) {
|
||||||
ipr.checkIPAdress(true);
|
IPRefresher::checkIPAdress(true);
|
||||||
} else {
|
} else {
|
||||||
std::cout << "incorrect credentials!" << std::endl;
|
std::cout << "incorrect credentials!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (firstarg == "-l" || firstarg == "--loop") {
|
} else if (firstarg == "-l" || firstarg == "--loop") {
|
||||||
IPRefresher(true);
|
IPRefresher::startUpService(true);
|
||||||
} else if (firstarg == "-c" || firstarg == "--checkconfig") {
|
} else if (firstarg == "-c" || firstarg == "--checkconfig") {
|
||||||
if (Config::validateConfig()) {
|
if (Config::validateConfig()) {
|
||||||
Logger::message("Config file is OK");
|
Logger::message("Config file is OK");
|
||||||
@ -44,10 +43,9 @@ int main(int argc, char *argv[]) {
|
|||||||
Logger::message("wrong arguments! -h for help");
|
Logger::message("wrong arguments! -h for help");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IPRefresher ipr;
|
|
||||||
Logger::message("starting check");
|
Logger::message("starting check");
|
||||||
if (Config::readConfig()) {
|
if (Config::readConfig()) {
|
||||||
ipr.checkIPAdress(false);
|
IPRefresher::checkIPAdress(false);
|
||||||
} else {
|
} else {
|
||||||
std::cout << "incorrect credentials!" << std::endl;
|
std::cout << "incorrect credentials!" << std::endl;
|
||||||
}
|
}
|
||||||
|
14
src/maingui.cpp
Normal file
14
src/maingui.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <QApplication>
|
||||||
|
#include "gui/MainWindow.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* application entry point
|
||||||
|
*/
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
MainWindow w;
|
||||||
|
w.setWindowTitle("startUpService");
|
||||||
|
w.show();
|
||||||
|
|
||||||
|
return QApplication::exec();
|
||||||
|
}
|
Reference in New Issue
Block a user