From 0ac9c497ae26a753fc1a4c789a8d70845efc5480 Mon Sep 17 00:00:00 2001 From: Lukas-Heiligenbrunner Date: Tue, 11 Feb 2020 16:42:05 +0100 Subject: [PATCH] create Credentials class to specify all credentials there. --- inc/Credentials.h | 32 ++++++++++++++++++++++++++++++++ inc/api/DynuAPI.h | 17 ++++++++++++----- src/IPRefresher.cpp | 4 +++- src/api/DynuAPI.cpp | 6 ++++++ src/main.cpp | 2 ++ 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 inc/Credentials.h diff --git a/inc/Credentials.h b/inc/Credentials.h new file mode 100644 index 0000000..1e82694 --- /dev/null +++ b/inc/Credentials.h @@ -0,0 +1,32 @@ +// +// Created by lukas on 11.02.20. +// + +#pragma once + + +#include + +class Credentials { +public: + static const std::string dynuapikey; + + static const std::string domainid; //id of the dynu domain + static const std::string domainname; + + static const std::string telegramApiKey; + static const std::string chatId; + + static bool checkCredentialValidity(); +}; + +const std::string Credentials::dynuapikey = ""; +const std::string Credentials::domainid = ""; //id of the dynu domain +const std::string Credentials::domainname = ""; + +static const std::string Credentials::telegramApiKey = ""; +static const std::string Credentials::chatId = ""; + +bool Credentials::checkCredentialValidity() { + return !(dynuapikey.empty() || domainid.empty() || domainname.empty()); +} diff --git a/inc/api/DynuAPI.h b/inc/api/DynuAPI.h index ac2df2d..c78148d 100644 --- a/inc/api/DynuAPI.h +++ b/inc/api/DynuAPI.h @@ -4,7 +4,6 @@ #pragma once - #include "API.h" class DynuAPI : API{ @@ -15,9 +14,17 @@ public: * @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"; + /** + * init Telegram api with apikey and chatid + * @param dynuApiKey Dynu Api key + * @param domainId ID of domain received by Dynu + * @param domainName domainname to refresh + */ + void init(std::string dynuApiKey, std::string domainId, std::string domainName); +private: + std::string dynuapikey; + + std::string domainid; //id of the dynu domain + std::string domainname; }; diff --git a/src/IPRefresher.cpp b/src/IPRefresher.cpp index 088af45..2e2b32b 100644 --- a/src/IPRefresher.cpp +++ b/src/IPRefresher.cpp @@ -14,6 +14,7 @@ #include #include +#include void IPRefresher::checkIPAdress(bool force) { FileLogger logger; @@ -36,10 +37,11 @@ void IPRefresher::checkIPAdress(bool force) { Logger::message("ip changed! -- from :" + oldip + "to: " + ip); DynuAPI dynu; + dynu.init(Credentials::dynuapikey,Credentials::domainid,Credentials::domainname); if (dynu.refreshIp(ip)) { TelegramAPI tele; - tele.init("717213769:AAHan1nSXhUsxLJAN1Dv8Oc0z8wqwDdYPn4", "618154204"); + tele.init(Credentials::telegramApiKey, Credentials::chatId); tele.sendMessage(oldip + " moved to " + ip); } else { //error diff --git a/src/api/DynuAPI.cpp b/src/api/DynuAPI.cpp index b21a450..89c5aff 100644 --- a/src/api/DynuAPI.cpp +++ b/src/api/DynuAPI.cpp @@ -25,3 +25,9 @@ int DynuAPI::refreshIp(std:: string ip) { return 1; } } + +void DynuAPI::init(std::string dynuApiKey, std::string domainId, std::string domainName) { + this->dynuapikey=dynuApiKey; + this->domainid=domainId; + this->domainname=domainName; +} diff --git a/src/main.cpp b/src/main.cpp index d3a9577..2d3cd3e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,8 +2,10 @@ #include #include #include +#include int main(int argc, char *argv[]) { + if(!Credentials::checkCredentialValidity()) return -1; if (argc > 1) { std::string firstarg(argv[1]); if (firstarg == "-h" || firstarg == "--help") {