added command line arguments

This commit is contained in:
2019-05-06 12:55:01 +02:00
parent 1754dd8385
commit 1c752847d9
2 changed files with 92 additions and 151 deletions

View File

@ -4,50 +4,62 @@
#include "API.h"
#include "Logger.h"
int main() {
API api;
Logger logger;
int main(int argc, char *argv[]) {
if(argc > 1){
std::string firstarg(argv[1]);
if (firstarg == "-h" || firstarg == "--help"){
std::cout << "help page: " << std::endl << "[-h] [--help] print this help page" << std::endl << "[-v] [--version] print the software version" <<std::endl << "[no argument] normal ip check and refresh" << std::endl;
}else if(firstarg == "-v" || firstarg == "--version"){
std::cout << "Version 1.0" << std::endl;
}else{
std::cout << "wrong arguments! -h for help" << std::endl;
}
} else{
API api;
Logger logger;
std::string ip = api.request("https://api.ipify.org");
std::string ip = api.request("https://api.ipify.org");
if (ip == "") {
//no internet connection
logger.logToLogfile("[WARNING] no internet connection");
std::cout << "[WARNING] no internet connection" << std::endl;
if (ip == "") {
//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 << "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 << "ip changed! -- from :" << oldip << "to: " << ip << std::endl;
std::string oldip = logger.readip();
//dynu api key: 88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg
if (oldip == ip) {
std::cout << "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 << "ip changed! -- from :" << oldip << "to: " << ip << std::endl;
static std::string domainid = "8506047"; //id of the dynu domain
//dynu api key: 88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg
Hashmap<std::string, std::string> args;
args.add("name", "luki.dynu.net");
args.add("ipv4Address", ip);
static std::string domainid = "8506047"; //id of the dynu domain
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: 88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg");
Hashmap<std::string, std::string> args;
args.add("name", "luki.dynu.net");
args.add("ipv4Address", ip);
std::string dynurepl = api.request("https://api.dynu.com/v2/dns/" + domainid, true, args, headers);
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: 88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg");
std::cout << "[ DEBUG ] api reply:: " << dynurepl << std::endl;
std::string dynurepl = api.request("https://api.dynu.com/v2/dns/" + domainid, true, args, headers);
if (dynurepl != "{\"statusCode\":200}") {
logger.logToLogfile(" [ERROR] failed to write ip to dynu api!");
std::cout << "[ DEBUG ] api reply:: " << dynurepl << std::endl;
if (dynurepl != "{\"statusCode\":200}") {
logger.logToLogfile(" [ERROR] failed to write ip to dynu api!");
}
logger.safeip(ip);
}
logger.safeip(ip);
}
}