20 Commits
1.1 ... v1.2

Author SHA1 Message Date
cc8c2b0497 added package dependency of libcurl 2019-10-26 11:49:10 +02:00
8eae88edfe removed install check of systemd 2019-10-26 11:38:24 +02:00
0d00ab10cf added package build info in readme 2019-10-26 11:03:11 +02:00
8e7c01c5ed edited readme 2019-10-26 11:00:57 +02:00
eadbfe90fd improved cmake file output dirs and package install dirs 2019-10-26 10:57:32 +02:00
6a3f1dc7a5 included windows build 2019-10-25 12:24:19 +02:00
eecbc755ce temp commit 2019-10-24 22:00:58 +02:00
133b21e1bd updated build targets 2019-10-24 16:11:35 +02:00
eeaf67906f cleanup cmakelist 2019-10-23 22:05:10 +02:00
5012cc517e check for deb build tools
improved check of rpm
2019-10-23 21:55:45 +02:00
314795d70d right install service with package
check if rpm build is possible
2019-10-23 21:47:54 +02:00
d91a52c6ba created systemd service 2019-10-23 13:18:43 +02:00
436051d641 updated version info to 1.2 2019-10-23 09:32:33 +02:00
b68982345d * option to force a refresh
* option to run in loop every 5 minutes
* pack into deb, rpm ant targz archive
2019-10-23 09:24:35 +02:00
f325c3a371 outsourced main method of ip refresh and added some doc 2019-08-02 22:44:42 +02:00
700d7912df manual build type set 2019-08-01 22:31:58 +02:00
52cc5f204b added c++ doc and replaced ifndef with pragma once 2019-08-01 21:19:02 +02:00
904cd2e96a cleanup in cmake file (added libraries)
code reformats
2019-08-01 20:18:39 +02:00
c5b5029cb1 added const variables in class headers 2019-06-18 11:42:26 +02:00
07ce161155 added seperate class for ip request and dynu request 2019-06-18 11:23:24 +02:00
20 changed files with 450 additions and 207 deletions

2
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

View File

@ -1,28 +1,140 @@
cmake_minimum_required(VERSION 3.7) cmake_minimum_required(VERSION 3.13)
project(iprefresher) project(iprefresher VERSION 1.2.0 DESCRIPTION "Dynu ip refresher")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE Release) # manually set build type (Release / Debug)
set(libmethod STATIC) #SHARED / STATIC
set(WinBuild false)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
#set up toolchain
if (${WinBuild})
set(LIBSUFFIX .dll)
set(SUFFIX .exe)
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
#set(TOOLCHAIN_PREFIX i686-w64-mingw32)
# cross compilers to use for C and C++
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw /usr/lib/gcc/${TOOLCHAIN_PREFIX}/8.3.0)
# modify default behavior of FIND_XXX() commands to
# search for headers/libs in the target environment and
# search for programs in the build host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# set(CMAKE_CXX_STANDARD_LIBRARIES -lcurl -lpthread -static-libgcc -static-libstdc++ -lcrypto -lssl -lws2_32 -std=c++11 -static -DCURL_STATICLIB)
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lcurl -lpthread -lstdc++ -lwsock32 -lws2_32 ${CMAKE_CSS_STANDARD_LIBRARIES}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -Wl,-Bstatic,--whole-archive -Wl,--no-whole-archive")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
# set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
add_definitions(-DCURL_STATICLIB)
else ()
set(LIBSUFFIX .so)
set(SUFFIX "")
endif ()
set(CMAKE_CXX_STANDARD 11)
find_package(CURL REQUIRED) find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR}) if (CURL_FOUND)
message(STATUS "Found CURL version: ${CURL_VERSION_STRING}")
message(STATUS "Using CURL include dir(s): ${CURL_INCLUDE_DIRS}")
message(STATUS "Using CURL lib(s): ${CURL_LIBRARIES}")
# include_directories(${CURL_INCLUDE_DIRS})
else ()
message(FATAL_ERROR "Could not find CURLLL")
endif ()
include_directories(${CURL_INCLUDE_DIR} inc)
add_library(api ${libmethod}
src/api/API.cpp
src/api/TelegramAPI.cpp
src/api/DynuAPI.cpp
src/api/IPAPI.cpp
)
add_library(logger ${libmethod}
src/Logger.cpp
)
set(SOURCE set(SOURCE
src/main.cpp src/main.cpp
src/IPRefresher.cpp inc/IPRefresher.h)
src/api/API.h add_executable(iprefresher ${SOURCE})
src/api/API.cpp
src/api/Hashmap.h # LINK generated LIBS #
target_link_libraries(iprefresher api logger ${CURL_LIBRARIES})
src/Logger.cpp # INSTALL to SYSTEM #
src/Logger.h install(TARGETS iprefresher DESTINATION bin)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/iprefresher.service DESTINATION /lib/systemd/system)
src/api/TelegramAPI.cpp
src/api/TelegramAPI.h
)
add_executable(iprefresher ${SOURCE}) IF (UNIX)
target_link_libraries(iprefresher ${CURL_LIBRARIES}) SET(CPACK_DEB_COMPONENT_INSTALL 1)
SET(CPACK_OUTPUT_FILE_PREFIX packages)
install (TARGETS iprefresher DESTINATION bin) FIND_PROGRAM(RPMBUILD_EXECUTABLE rpmbuild)
FIND_PROGRAM(DEB_EXECUTABLE dpkg)
SET(CPACK_GENERATOR "TGZ;TBZ2")
#check if rpm build is possible
if (NOT ${RPMBUILD_EXECUTABLE} STREQUAL "RPMBUILD_EXECUTABLE-NOTFOUND")
message(STATUS "found rpm build executeable --> able to build rpm")
set(CPACK_GENERATOR "${CPACK_GENERATOR};RPM")
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/lib/systemd/system" "/usr/lib/systemd") # --> needed to not override existing folders
else (NOT ${RPMBUILD_EXECUTABLE} STREQUAL "RPMBUILD_EXECUTABLE-NOTFOUND")
message(STATUS "not found rpm build tools --> not building rpm")
endif (NOT ${RPMBUILD_EXECUTABLE} STREQUAL "RPMBUILD_EXECUTABLE-NOTFOUND")
#check if deb build is possible
if (NOT ${DEB_EXECUTABLE} STREQUAL "DEB_EXECUTABLE-NOTFOUND")
message(STATUS "found deb build tools --> able to build deb")
set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB")
else (NOT ${DEB_EXECUTABLE} STREQUAL "DEB_EXECUTABLE-NOTFOUND")
message(STATUS "not found deb build tools --> not building deb")
endif (NOT ${DEB_EXECUTABLE} STREQUAL "DEB_EXECUTABLE-NOTFOUND")
SET(CPACK_CMAKE_GENERATOR "Unix Makefiles")
SET(CPACK_SOURCE_GENERATOR "TGZ;TBZ2")
SET(CPACK_PACKAGE_DESCRIPTION "IPrefresher to refresh Dynu ip address and notify user via Telegram")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "IPrefresher to refresh Dynu ip address and notify user via Telegram")
SET(CPACK_PACKAGE_VENDOR "Lukas Heilgienbrunner")
SET(CPACK_PACKAGE_VERSION_MAJOR "1")
SET(CPACK_PACKAGE_VERSION_MINOR "2")
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
SET(CPACK_PACKAGE_CONTACT "Lukas Heiligenbrunner <ultimategameingcookie@gmail.com>")
SET(CPACK_PACKAGE_SECTION "games")
set(CPACK_PACKAGE_DEPENDS "libcurl (>= 7.0.0-1)")
INCLUDE(CPack)
add_custom_target(build-linux-packages
"${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target package
DEPENDS ${PROJECT_NAME}
COMMENT "Installing ${PROJECT_NAME}")
ENDIF (UNIX)

View File

@ -2,84 +2,44 @@
## Build ## Build
## Basic Build ## Basic Build
Download source files ### Download source files
`git clone https://github.com/Lukas-Heiligenbrunner/DynuIPRefresher.git` `git clone https://github.com/Lukas-Heiligenbrunner/DynuIPRefresher.git`
### install build dependencies
`libcurl`
`libcurl-devel`
Debian:
`apt install libcurl4-openssl-dev`
Fedora:
`dnf install libcurl-devel`
#### dependencies for package build
`dpkg` --> debian/ubuntu package
`rpmbuild` --> Fedora/RedHat/CentOS package
### cmake project
cd into downloaded files and Generate makefiles: cd into downloaded files and Generate makefiles:
`cmake .` `cmake -S . -B build`
compile project ### compile project
`make` `make`
install it to the system [root] install it to the system
`make install` `make install`
### Build a Debian package [root] or create Linux packages
Download source files
`git clone https://github.com/Lukas-Heiligenbrunner/DynuIPRefresher.git` `make package`
rename Project folder to lower case:
`mv DynuIPRefresher iprefresher-1.0`
`cd iprefresher-1.0`
remove .idea folder because it´s useless in this case:
`rm -Rf .idea`
pack source in a tar.gz archive
`tar -zcvf iprefresher-1.0.tar.gz *`
create debian/ folder and create example config files
`dh_make -f iprefresher-1.0.tar.gz`
recently packed archive is useless now, delete it
`rm iprefresher-1.0.tar.gz`
move to debian/ folder:
`cd debian`
remove useless files:
`rm *.ex *.EX README.Debian README.source `
edit control file
`rm control`
`nano control`
```
Source: iprefresher
Section: net
Priority: optional
Maintainer: Lukas Heiligenbrunner <lukas@unknown>
Build-Depends: debhelper (>= 10)
Standards-Version: 4.1.2
Package: iprefresher
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: a dynu.net ip refresher written in c++
a dynu.net ip refresher written in c++
```
return to main folder
`cd ..`
buld .deb package
`dpkg-buildpackage -us -uc `
### Windows cross build ### Windows cross build
TODO! TODO!

17
inc/IPRefresher.h Normal file
View File

@ -0,0 +1,17 @@
//
// Created by lukas on 02.08.19.
//
#pragma once
class IPRefresher {
public:
/**
* refresh ip address on Dynu server
*/
void checkIPAdress(bool force);
IPRefresher();
IPRefresher(bool loop);
};

27
inc/Logger.h Normal file
View File

@ -0,0 +1,27 @@
//
// Created by lukas on 05.05.19.
//
#pragma once
#include <string>
class Logger {
public:
/**
* log messages to logfile
* @param text message
*/
void logToLogfile(std::string text);
/**
* safe ip to temp file
* @param ip ip address to save
*/
void safeip(std::string ip);
/**
* read ip from file
* @return read ip
*/
std::string readip();
};

32
inc/api/API.h Normal file
View File

@ -0,0 +1,32 @@
//
// Created by lukas on 06.04.19.
//
#pragma once
#include <string>
#include "Hashmap.h"
class API {
public:
/**
* Simple API get request
* @param myurl api url
* @return return string of server
*/
std::string request(std::string myurl);
/**
* complex request with post/get and header information support
* @param myurl base request url
* @param post boolean (false=get)
* @param map post/get fields
* @param headers header fields
* @return return string of server
*/
std::string request(std::string myurl, bool post, Hashmap<std::string, std::string> &map, std::vector<std::string> &headers);
private:
static size_t write_data(void *buffer, size_t size, size_t buffersize, FILE *stream);
};

23
inc/api/DynuAPI.h Normal file
View File

@ -0,0 +1,23 @@
//
// Created by lukas on 18.06.19.
//
#pragma once
#include "API.h"
class DynuAPI : API{
public:
/**
* refresh the ip of domain on Dynu server
* @param ip new ip
* @return request status
*/
int refreshIp(std::string ip);
private:
const std::string dynuapikey = "88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg";
const std::string domainid = "8506047"; //id of the dynu domain
const std::string domainname = "luki.dynu.net";
};

View File

@ -2,8 +2,7 @@
// Created by lukas on 07.04.19. // Created by lukas on 07.04.19.
// //
#ifndef QT5PROJECT_HASHMAP_H #pragma once
#define QT5PROJECT_HASHMAP_H
#include <iostream> #include <iostream>
@ -12,12 +11,31 @@
template<class keytype, class valuetype> template<class keytype, class valuetype>
class Hashmap { class Hashmap {
public: public:
/**
* add key-value pair to hashmap
* @param key keyvalue
* @param value valuevalue
*/
void add(keytype key, keytype value); void add(keytype key, keytype value);
/**
* get key of specific position
* @param position int position
* @return responding key object
*/
keytype getKey(int position); keytype getKey(int position);
/**
* get value of specific position
* @param position int position
* @return responding value object
*/
valuetype getValue(int position); valuetype getValue(int position);
/**
* get size of Hashmap
* @return size of Hashmap
*/
int size(); int size();
private: private:
@ -43,8 +61,5 @@ valuetype Hashmap<keytype, valuetype>::getValue(int position) {
template<class keytype, class valuetype> template<class keytype, class valuetype>
int Hashmap<keytype, valuetype>::size() { int Hashmap<keytype, valuetype>::size() {
return (int)(keys.size()); return (int) (keys.size());
} }
#endif //QT5PROJECT_HASHMAP_H

17
inc/api/IPAPI.h Normal file
View File

@ -0,0 +1,17 @@
//
// Created by lukas on 18.06.19.
//
#pragma once
#include <string>
#include "API.h"
class IPAPI : API{
public:
/**
* get global ip of current internet connection
* @return global ip
*/
std::string getGlobalIp();
};

29
inc/api/TelegramAPI.h Normal file
View File

@ -0,0 +1,29 @@
//
// Created by lukas on 08.05.19.
//
#pragma once
#include <string>
#include "API.h"
class TelegramAPI : API {
public:
/**
* send telegram Message to predefined destination
* @param text message
*/
void sendMessage(std::string text);
/**
* init Telegram api with apikey and chatid
* @param apikey recieved API key
* @param chatid chatid where bot should post into
*/
void init(std::string apikey, std::string chatid);
private:
std::string apikey;
std::string chatid;
};

12
iprefresher.service Normal file
View File

@ -0,0 +1,12 @@
[Unit]
Description=IP Refresher
After=network.target
[Service]
ExecStart=iprefresher -l
WorkingDirectory=/root
StandardOutput=inherit
StandardError=inherit
Restart=always
User=root
[Install]
WantedBy=multi-user.target

62
src/IPRefresher.cpp Normal file
View File

@ -0,0 +1,62 @@
//
// Created by lukas on 02.08.19.
//
#include <string>
#include <Logger.h>
#include <api/IPAPI.h>
#include <api/DynuAPI.h>
#include <api/TelegramAPI.h>
#include <chrono>
#include <thread>
#include "IPRefresher.h"
void IPRefresher::checkIPAdress(bool force) {
Logger logger;
IPAPI ipapi;
std::string ip = ipapi.getGlobalIp();
if (ip.empty()) {
//no internet connection
logger.logToLogfile("[WARNING] no internet connection");
std::cout << "[WARNING] no internet connection" << std::endl;
} else {
std::string oldip = logger.readip();
if (oldip == ip && !force) {
std::cout << "[INFO] no change -- ip: " << ip << std::endl;
logger.logToLogfile(" [INFO] no change -- ip: " + ip);
} else {
logger.logToLogfile(" [INFO] ip changed! -- from :" + oldip + "to: " + ip);
std::cout << "[INFO] ip changed! -- from :" << oldip << "to: " << ip << std::endl;
DynuAPI dynu;
if (dynu.refreshIp(ip)) {
TelegramAPI tele;
tele.init("717213769:AAHan1nSXhUsxLJAN1Dv8Oc0z8wqwDdYPn4","618154204");
tele.sendMessage(oldip + " moved to " + ip);
} else {
//error
logger.logToLogfile(" [ERROR] failed to write ip to dynu api!");
}
logger.safeip(ip);
}
}
}
IPRefresher::IPRefresher() {
}
IPRefresher::IPRefresher(bool loop) {
while(true){
std::this_thread::sleep_for(std::chrono::milliseconds(300000));
checkIPAdress(false);
}
}

View File

@ -1,20 +0,0 @@
//
// Created by lukas on 05.05.19.
//
#ifndef IPREFRESHER_LOGGER_H
#define IPREFRESHER_LOGGER_H
class Logger {
public:
void logToLogfile(std::string text);
void safeip(std::string ip);
std::string readip();
};
#endif //IPREFRESHER_LOGGER_H

View File

@ -2,8 +2,8 @@
// Created by lukas on 06.04.19. // Created by lukas on 06.04.19.
// //
#include "API.h" #include "api/API.h"
#include "Hashmap.h" #include "api/Hashmap.h"
#include <string> #include <string>
#include <iostream> #include <iostream>
@ -26,7 +26,7 @@ API::request(std::string myurl, bool post, Hashmap<std::string, std::string> &ma
struct curl_slist *list = nullptr; struct curl_slist *list = nullptr;
for (int j = 0; j < headers.size(); ++j) { for (int j = 0; j < headers.size(); ++j) {
list = curl_slist_append(list, headers.at((unsigned long)(j)).c_str()); list = curl_slist_append(list, headers.at((unsigned long) (j)).c_str());
} }
std::string readString; std::string readString;

View File

@ -1,23 +0,0 @@
//
// Created by lukas on 06.04.19.
//
#ifndef IPREFRESHER_API_H
#define IPREFRESHER_API_H
#include <string>
#include "Hashmap.h"
class API {
public:
std::string request(std::string myurl);
std::string request(std::string myurl, bool post, Hashmap<std::string, std::string> &map, std::vector<std::string> &headers);
private:
static size_t write_data(void *buffer, size_t size, size_t buffersize, FILE *stream);
};
#endif //IPREFRESHER_API_H

27
src/api/DynuAPI.cpp Normal file
View File

@ -0,0 +1,27 @@
//
// Created by lukas on 18.06.19.
//
#include "api/DynuAPI.h"
int DynuAPI::refreshIp(std:: string ip) {
Hashmap<std::string, std::string> args;
args.add("name", domainname);
args.add("ipv4Address", ip);
std::vector<std::string> headers;
headers.push_back("accept: application/json");
headers.push_back("User-Agent: Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)");
headers.push_back("API-Key: " + dynuapikey);
std::string dynurepl = request("https://api.dynu.com/v2/dns/" + domainid, true, args, headers);
// std::cout << "[DEBUG] api reply:: " << dynurepl << std::endl;
if (dynurepl != "{\"statusCode\":200}") {
return -1;
} else {
return 1;
}
}

9
src/api/IPAPI.cpp Normal file
View File

@ -0,0 +1,9 @@
//
// Created by lukas on 18.06.19.
//
#include "api/IPAPI.h"
std::string IPAPI::getGlobalIp() {
return request("https://api.ipify.org");
}

View File

@ -2,7 +2,7 @@
// Created by lukas on 08.05.19. // Created by lukas on 08.05.19.
// //
#include "TelegramAPI.h" #include "api/TelegramAPI.h"
void TelegramAPI::sendMessage(std::string text) { void TelegramAPI::sendMessage(std::string text) {
Hashmap<std::string, std::string> args; Hashmap<std::string, std::string> args;
@ -12,5 +12,10 @@ void TelegramAPI::sendMessage(std::string text) {
std::vector<std::string> headers; std::vector<std::string> headers;
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);
std::cout << "[DEBUG] " << reply << std::endl; // std::cout << "[DEBUG] " << reply << std::endl;
}
void TelegramAPI::init(std::string apikey, std::string chatid) {
this->apikey = apikey;
this->chatid = chatid;
} }

View File

@ -1,22 +0,0 @@
//
// Created by lukas on 08.05.19.
//
#ifndef IPREFRESHER_TELEGRAMAPI_H
#define IPREFRESHER_TELEGRAMAPI_H
#include <string>
#include "API.h"
class TelegramAPI : API {
public:
void sendMessage(std::string text);
private:
std::string apikey = "717213769:AAHan1nSXhUsxLJAN1Dv8Oc0z8wqwDdYPn4";
std::string chatid = "618154204";
};
#endif //IPREFRESHER_TELEGRAMAPI_H

View File

@ -1,10 +1,5 @@
#include <iostream> #include <iostream>
#include <ctime> #include <IPRefresher.h>
#include <unordered_map>
#include "api/API.h"
#include "Logger.h"
#include "api/TelegramAPI.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -13,60 +8,24 @@ int main(int argc, char *argv[]) {
if (firstarg == "-h" || firstarg == "--help") { if (firstarg == "-h" || firstarg == "--help") {
std::cout << "help page: " << std::endl << "[-h] [--help] print this help page" << std::endl std::cout << "help page: " << std::endl << "[-h] [--help] print this help page" << std::endl
<< "[-v] [--version] print the software version" << std::endl << "[-v] [--version] print the software version" << std::endl
<< "[-f] [--force] force refresh of ip" << std::endl
<< "[-l] [--loop] infinite loop to refresh ip every five minutes" << 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 1.0" << std::endl; std::cout << "Version 1.2" << std::endl;
} else if (firstarg == "-f" || firstarg == "--force") {
IPRefresher ipr;
ipr.checkIPAdress(true);
} else if (firstarg == "-l" || firstarg == "--loop") {
IPRefresher ipr(true);
ipr.checkIPAdress(false);
} else { } else {
std::cout << "wrong arguments! -h for help" << std::endl; std::cout << "wrong arguments! -h for help" << std::endl;
} }
} else { } else {
API api; IPRefresher ipr;
Logger logger; ipr.checkIPAdress(false);
std::string ip = api.request("https://api.ipify.org");
if (ip.empty()) {
//no internet connection
logger.logToLogfile("[WARNING] no internet connection");
std::cout << "[WARNING] no internet connection" << std::endl;
} else {
std::string oldip = logger.readip();
if (oldip == ip) {
std::cout << "[INFO] no change -- ip: " << ip << std::endl;
logger.logToLogfile(" [INFO] no change -- ip: " + ip);
} else {
logger.logToLogfile(" [INFO] ip changed! -- from :" + oldip + "to: " + ip);
std::cout << "[INFO] ip changed! -- from :" << oldip << "to: " << ip << std::endl;
static std::string dynuapikey = "88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg";
static std::string domainid = "8506047"; //id of the dynu domain
static std::string domainname = "luki.dynu.net";
Hashmap<std::string, std::string> args;
args.add("name", domainname);
args.add("ipv4Address", ip);
std::vector<std::string> headers;
headers.push_back("accept: application/json");
headers.push_back("User-Agent: Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)");
headers.push_back("API-Key: " + dynuapikey);
std::string dynurepl = api.request("https://api.dynu.com/v2/dns/" + domainid, true, args, headers);
std::cout << "[DEBUG] api reply:: " << dynurepl << std::endl;
if (dynurepl != "{\"statusCode\":200}") {
logger.logToLogfile(" [ERROR] failed to write ip to dynu api!");
} else {
TelegramAPI tele;
tele.sendMessage(oldip + " moved to " + ip);
}
logger.safeip(ip);
}
}
} }
return 0; return 0;