2020-05-05 17:25:23 +00:00
|
|
|
#include "Version.h"
|
|
|
|
#include "IPRefresher.h"
|
|
|
|
#include "Logger.h"
|
|
|
|
#include "Config.h"
|
|
|
|
#include "api/IPAPI.h"
|
2019-05-05 13:38:48 +00:00
|
|
|
|
2020-04-30 17:37:11 +00:00
|
|
|
/**
|
|
|
|
* application entry point
|
|
|
|
*/
|
2019-05-06 10:55:01 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
2019-05-06 16:49:38 +00:00
|
|
|
if (argc > 1) {
|
2019-05-06 10:55:01 +00:00
|
|
|
std::string firstarg(argv[1]);
|
2019-05-06 16:49:38 +00:00
|
|
|
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
|
2019-10-23 07:24:35 +00:00
|
|
|
<< "[-f] [--force] force refresh of ip" << std::endl
|
|
|
|
<< "[-l] [--loop] infinite loop to refresh ip every five minutes" << std::endl
|
2020-05-01 13:33:20 +00:00
|
|
|
<< "[-c] [--checkconfig] validate configuration" << std::endl
|
2020-05-05 13:32:07 +00:00
|
|
|
<< "[-ip] [--currentip] get current global ip" << std::endl
|
2019-05-06 16:49:38 +00:00
|
|
|
<< "[no argument] normal ip check and refresh" << std::endl;
|
|
|
|
} else if (firstarg == "-v" || firstarg == "--version") {
|
2019-10-27 12:41:40 +00:00
|
|
|
std::cout << "Version " << Version::VERSION << std::endl;
|
2019-10-23 07:24:35 +00:00
|
|
|
} else if (firstarg == "-f" || firstarg == "--force") {
|
|
|
|
IPRefresher ipr;
|
2020-05-07 12:54:40 +00:00
|
|
|
if (Config::readConfig()) {
|
2020-04-30 09:30:41 +00:00
|
|
|
ipr.checkIPAdress(true);
|
|
|
|
} else {
|
|
|
|
std::cout << "incorrect credentials!" << std::endl;
|
|
|
|
}
|
|
|
|
|
2019-10-23 07:24:35 +00:00
|
|
|
} else if (firstarg == "-l" || firstarg == "--loop") {
|
2020-02-11 16:22:14 +00:00
|
|
|
IPRefresher(true);
|
2020-05-01 13:33:20 +00:00
|
|
|
} else if (firstarg == "-c" || firstarg == "--checkconfig") {
|
|
|
|
if (Config::validateConfig()) {
|
|
|
|
Logger::message("Config file is OK");
|
|
|
|
} else {
|
2020-05-07 12:54:40 +00:00
|
|
|
Logger::error("There are errors in config file!");
|
2020-05-01 13:33:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2020-05-05 13:32:07 +00:00
|
|
|
} else if (firstarg == "-ip" || firstarg == "--currentip") {
|
|
|
|
IPAPI ipapi;
|
|
|
|
std::cout << "Current global IP: " << ipapi.getGlobalIp() << std::endl;
|
2019-05-06 16:49:38 +00:00
|
|
|
} else {
|
2019-10-26 12:41:43 +00:00
|
|
|
Logger::message("wrong arguments! -h for help");
|
2019-05-06 10:55:01 +00:00
|
|
|
}
|
2019-05-06 16:49:38 +00:00
|
|
|
} else {
|
2019-08-02 20:44:42 +00:00
|
|
|
IPRefresher ipr;
|
2019-10-26 12:41:43 +00:00
|
|
|
Logger::message("starting check");
|
2020-05-07 12:54:40 +00:00
|
|
|
if (Config::readConfig()) {
|
2020-04-30 09:30:41 +00:00
|
|
|
ipr.checkIPAdress(false);
|
|
|
|
} else {
|
|
|
|
std::cout << "incorrect credentials!" << std::endl;
|
|
|
|
}
|
2019-05-05 16:50:10 +00:00
|
|
|
}
|
2019-05-05 13:38:48 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|