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
13 changed files with 205 additions and 395 deletions

View File

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

View File

@ -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,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(GUI "Build GUI elements" ON) # additional dependencies to QT libraries needed option(WinBuild "cross compile for Windows Platform" OFF)
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,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)
@ -41,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})
@ -66,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})
@ -99,10 +109,6 @@ 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)
@ -134,19 +140,10 @@ 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/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
"/** "/**
@ -163,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})\";
}" }"
) )
@ -174,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
@ -182,47 +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})
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 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...
@ -262,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)
@ -315,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 ()
@ -347,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 ()

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). 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

View File

@ -9,25 +9,22 @@
#pragma once #pragma once
namespace IPRefresher { class 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
*/ */
bool checkIPAdress(bool force); void 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
*/ */
void startUpService(int interval = 300); explicit IPRefresher(bool loop);
} };

View File

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

View File

@ -11,9 +11,7 @@
#include <thread> #include <thread>
#include <Logger.h> #include <Logger.h>
using namespace IPRefresher; void IPRefresher::checkIPAdress(bool force) {
bool IPRefresher::checkIPAdress(bool force) {
FileLogger logger; FileLogger logger;
IPAPI ipapi; IPAPI ipapi;
@ -22,17 +20,14 @@ bool 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);
@ -48,26 +43,26 @@ bool 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;
} }
} }
} }
void IPRefresher::startUpService(int interval) { IPRefresher::IPRefresher(bool loop) {
Logger::message("startup of service"); if (loop) {
Logger::message("Version: " + Version::VERSION); Logger::message("startup of service");
if (Config::readConfig()) { Logger::message("Version: " + Version::VERSION);
while (true) { while (true) {
Logger::message("starting check"); Logger::message("starting check");
checkIPAdress(false); if (Config::readConfig()) {
std::this_thread::sleep_for(std::chrono::milliseconds(interval * 1000)); checkIPAdress(false);
} else {
std::cout << "incorrect credentials!" << std::endl;
}
std::this_thread::sleep_for(std::chrono::milliseconds(300000));
} }
} else {
std::cout << "incorrect credentials!" << std::endl;
} }
} }

View File

@ -1,84 +0,0 @@
#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.");
});
}

View File

@ -1,50 +0,0 @@
/**
* 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);
};

View File

@ -1,103 +0,0 @@
<?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>

View File

@ -21,14 +21,15 @@ 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()) {
IPRefresher::checkIPAdress(true); ipr.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::startUpService(true); IPRefresher(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");
@ -43,9 +44,10 @@ 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()) {
IPRefresher::checkIPAdress(false); ipr.checkIPAdress(false);
} else { } else {
std::cout << "incorrect credentials!" << std::endl; std::cout << "incorrect credentials!" << std::endl;
} }

View File

@ -1,14 +0,0 @@
#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();
}