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:
|
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 iprefresher
|
||||||
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 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
|
115
CMakeLists.txt
115
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)
|
||||||
@ -19,11 +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
|
||||||
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)
|
||||||
@ -31,6 +32,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)
|
||||||
|
|
||||||
@ -40,9 +42,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,17 +67,26 @@ 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 "./iprefresher.cfg")
|
set(CONFIG_PATH "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 /etc/ config path
|
||||||
set(CONFIG_PATH "/etc/iprefresher.cfg")
|
set(CONFIG_PATH "\"/etc/\"")
|
||||||
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})
|
||||||
@ -132,7 +143,7 @@ endif ()
|
|||||||
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 version header
|
||||||
FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h
|
FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h
|
||||||
"/**
|
"/**
|
||||||
@ -149,7 +160,8 @@ 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})\";
|
||||||
}"
|
}"
|
||||||
)
|
)
|
||||||
@ -160,7 +172,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
|
||||||
@ -168,25 +180,25 @@ 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})
|
||||||
|
|
||||||
# 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 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)
|
||||||
ELSE ()
|
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...
|
||||||
@ -226,8 +238,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)
|
||||||
@ -279,8 +293,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 ()
|
||||||
|
|
||||||
@ -311,39 +325,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
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#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,13 +20,38 @@ 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(Version::ConfigDir + Version::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(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);
|
myfile.open(Version::ConfigDir + Version::ConfName);
|
||||||
if (myfile.is_open()) {
|
if (myfile.is_open()) {
|
||||||
myfile << Version::SAMPLECONFIG;
|
myfile << Version::SAMPLECONFIG;
|
||||||
myfile.close();
|
myfile.close();
|
||||||
|
@ -54,14 +54,15 @@ IPRefresher::IPRefresher(bool loop) {
|
|||||||
if (loop) {
|
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(300000));
|
} else {
|
||||||
|
std::cout << "incorrect credentials!" << std::endl;
|
||||||
}
|
}
|
||||||
} else {
|
std::this_thread::sleep_for(std::chrono::milliseconds(300000));
|
||||||
std::cout << "incorrect credentials!" << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user