Compare commits

...

5 Commits

8 changed files with 29 additions and 51 deletions

View File

@ -1,95 +1,68 @@
stages:
- cmake
- build
- post
# Unix Build
cmake:
stage: cmake
image: luki42/dynuiprefresher_build:latest
script:
- cmake -S . -B build -D WinBuild=OFF -D GUI=OFF
artifacts:
paths:
- build/
- inc/
- postinst
build:
stage: build
image: luki42/dynuiprefresher_build:latest
script:
- cmake -S . -B build -D WinBuild=OFF -D GUI=OFF
- cd build
- make dynuiprefresher
artifacts:
paths:
- build/
- inc/
- postinst
dependencies:
- cmake
- build/bin/
build_package:
stage: post
image: luki42/dynuiprefresher_build:latest
script:
- cmake -S . -B build -D WinBuild=OFF -D GUI=OFF
- cd build
- make package
artifacts:
paths:
- build/
- inc/
- postinst
dependencies:
- build/packages/
needs:
- build
test:
stage: post
image: luki42/dynuiprefresher_build:latest
script:
- cmake -S . -B build -D WinBuild=OFF -D GUI=OFF
- cd build
- make build-test
artifacts:
reports:
junit: build/*.xml
dependencies:
needs:
- 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:
- cmake -S . -B build -D WinBuild=ON
- cd build
- make dynuiprefresher
artifacts:
paths:
- build/
- inc/
dependencies:
- cmake_win64
- build/bin/
build_package_win64:
stage: post
image: luki42/dynuiprefresher_build:windows
script:
- cmake -S . -B build -D WinBuild=ON
- cd build
- make package
artifacts:
paths:
- build/
- inc/
dependencies:
- build/packages/
needs:
- build_win64

View File

@ -341,7 +341,7 @@ ${SAMPLECONFIG}EOM
fi
systemctl enable ${Application_Name}.service
systemctl start ${Application_Name}.service")
systemctl restart ${Application_Name}.service")
SET(CPACK_DEB_COMPONENT_INSTALL 1)
@ -487,7 +487,7 @@ if (TESTS)
# create an exectuable in which the tests will be stored
add_executable(${TESTNAME} ${ARGN})
# link the Google test infrastructure, mocking library, and a default main fuction to
target_link_libraries(${TESTNAME} gtest gtest_main -lpthread -lm libdynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
target_link_libraries(${TESTNAME} gtest gtest_main -lpthread -lm api libdynuiprefresher ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
# see https://cmake.org/cmake/help/v3.10/module/GoogleTest.html for more options to pass to it
gtest_discover_tests(${TESTNAME})

View File

@ -16,7 +16,7 @@ public:
* @param ip ip address to test
* @return validity
*/
static bool isIpValid(std::string ip);
static bool isIpValid(const std::string& ip);
private:
};

View File

@ -2,7 +2,7 @@
Description=IP Refresher
After=network.target
[Service]
ExecStart=iprefresher -l
ExecStart=dynuiprefresher -l
WorkingDirectory=/root
StandardOutput=inherit
StandardError=inherit

View File

@ -23,8 +23,5 @@ std::string FileLogger::readip() {
in >> ip;
// when received ip has no . return 0.0.0.0
if (!IpHelper::isIpValid(ip))
return "0.0.0.0";
else
return ip;
return (IpHelper::isIpValid(ip) ? ip : "0.0.0.0");
}

View File

@ -1,5 +1,7 @@
#include <regex>
#include "IpHelper.h"
bool IpHelper::isIpValid(std::string ip) {
return (ip.find('.') != SIZE_MAX);
bool IpHelper::isIpValid(const std::string& ip) {
const std::regex rgx(R"(^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)");
return (std::regex_match(ip, rgx));
}

View File

@ -1,5 +1,11 @@
#include <IpHelper.h>
#include <Logger.h>
#include "api/IPAPI.h"
std::string IPAPI::getGlobalIp() {
return request("https://api.ipify.org");
const std::string ip = request("https://api.ipify.org");
if(!IpHelper::isIpValid(ip))
Logger::warning("no valid ip returned from ipapi");
return ip;
}

View File

@ -28,7 +28,7 @@ int main(int argc, char *argv[]) {
}
} else if (firstarg == "-l" || firstarg == "--loop") {
IPRefresher::startUpService(true);
IPRefresher::startUpService(600);
} else if (firstarg == "-c" || firstarg == "--checkconfig") {
if (Config::validateConfig()) {
Logger::message("Config file is OK");