* new class for IP utils
* method to check telegram support out of config * getters in Config.cpp * lots of reformatings and cdoc
This commit is contained in:
77
inc/Config.h
77
inc/Config.h
@ -6,22 +6,17 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* A static class to manage the configuration file, read/write parameters to it.
|
||||
*/
|
||||
class Config {
|
||||
public:
|
||||
static std::string dynuapikey;
|
||||
|
||||
static std::string domainid; //id of the dynu domain
|
||||
static std::string domainname;
|
||||
|
||||
static std::string telegramApiKey;
|
||||
static std::string chatId;
|
||||
|
||||
/**
|
||||
* read configuration out of config file
|
||||
*
|
||||
* @return success of config read
|
||||
*/
|
||||
static bool readCredentials();
|
||||
* read configuration out of config file
|
||||
*
|
||||
* @return success of config read
|
||||
*/
|
||||
static bool readConfig();
|
||||
|
||||
/**
|
||||
* validate config file
|
||||
@ -30,5 +25,61 @@ public:
|
||||
*/
|
||||
static bool validateConfig();
|
||||
|
||||
/**
|
||||
* check if telegram credentials in config are set
|
||||
* @return is supported?
|
||||
*/
|
||||
static bool isTelegramSupported();
|
||||
|
||||
/** Getters **/
|
||||
|
||||
/**
|
||||
* encapsulated getter for DynuApiKey
|
||||
* @return api key
|
||||
*/
|
||||
static const std::string &getDynuapikey();
|
||||
|
||||
/**
|
||||
* encapsulated getter for DomainId
|
||||
* @return DomainId
|
||||
*/
|
||||
static const std::string &getDomainid();
|
||||
|
||||
/**
|
||||
* encapsulated getter for Domainname
|
||||
* @return Domainname
|
||||
*/
|
||||
static const std::string &getDomainname();
|
||||
|
||||
/**
|
||||
* encapsulated getter for TelegramApiKey
|
||||
* @return TelegramApiKey
|
||||
*/
|
||||
static const std::string &getTelegramApiKey();
|
||||
|
||||
/**
|
||||
* encapsulated getter for ChatId
|
||||
* @return ChatId
|
||||
*/
|
||||
static const std::string &getChatId();
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* private constructor --> don't allow instance of this class
|
||||
*/
|
||||
Config();
|
||||
|
||||
/**
|
||||
* helper variable for managing telegram Support
|
||||
*/
|
||||
static bool telegramSupport;
|
||||
|
||||
static std::string dynuapikey;
|
||||
|
||||
static std::string domainid; //id of the dynu domain
|
||||
static std::string domainname;
|
||||
|
||||
static std::string telegramApiKey;
|
||||
static std::string chatId;
|
||||
};
|
@ -14,7 +14,7 @@ public:
|
||||
/**
|
||||
* default constructor
|
||||
*/
|
||||
IPRefresher();
|
||||
IPRefresher() = default;
|
||||
|
||||
/**
|
||||
* start the service in loop mode
|
||||
|
22
inc/IpHelper.h
Normal file
22
inc/IpHelper.h
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by lukas on 07.05.20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* General helper class for IP actions
|
||||
*/
|
||||
class IpHelper {
|
||||
public:
|
||||
/**
|
||||
* check if ip is valid
|
||||
* @param ip ip address to test
|
||||
* @return validity
|
||||
*/
|
||||
static bool isIpValid(std::string ip);
|
||||
|
||||
private:
|
||||
};
|
@ -25,7 +25,10 @@ public:
|
||||
* @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);
|
||||
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);
|
||||
|
@ -6,14 +6,14 @@
|
||||
|
||||
#include "API.h"
|
||||
|
||||
class DynuAPI : API{
|
||||
class DynuAPI : API {
|
||||
public:
|
||||
/**
|
||||
* refresh the ip of domain on Dynu server
|
||||
* @param ip new ip
|
||||
* @return request status
|
||||
*/
|
||||
int refreshIp(std::string ip);
|
||||
bool refreshIp(std::string ip);
|
||||
|
||||
/**
|
||||
* init Telegram api with apikey and chatid
|
||||
@ -21,7 +21,8 @@ public:
|
||||
* @param domainId ID of domain received by Dynu
|
||||
* @param domainName domainname to refresh
|
||||
*/
|
||||
void init(const std::string& dynuApiKey, const std::string& domainId, const std::string& domainName);
|
||||
void init(const std::string &dynuApiKey, const std::string &domainId, const std::string &domainName);
|
||||
|
||||
private:
|
||||
std::string dynuapikey; // Dynu API key
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
class IPAPI : API{
|
||||
class IPAPI : API {
|
||||
public:
|
||||
/**
|
||||
* get global ip of current internet connection
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
* send telegram Message to predefined destination
|
||||
* @param text message
|
||||
*/
|
||||
int sendMessage(const std::string& text);
|
||||
int sendMessage(const std::string &text);
|
||||
|
||||
/**
|
||||
* init Telegram api with apikey and chatid
|
||||
|
Reference in New Issue
Block a user