Browse Source

feat: add VERBOSE option

dev
Dnomd343 2 years ago
parent
commit
73695dd7a1
  1. 59
      src/cleardns.c

59
src/cleardns.c

@ -15,17 +15,31 @@
#include "overture.h" #include "overture.h"
#include "structure.h" #include "structure.h"
char* init(int argc, char *argv[]) { // return config file struct {
char *config = string_init(CONFIG_FILE); char *config;
uint8_t debug;
uint8_t verbose;
} settings;
void init(int argc, char *argv[]) { // return config file
settings.config = string_init(CONFIG_FILE);
settings.debug = FALSE;
settings.verbose = FALSE;
if (getenv("CONFIG") != NULL) { if (getenv("CONFIG") != NULL) {
config = string_init(getenv("CONFIG")); free(settings.config);
settings.config = string_init(getenv("CONFIG"));
} }
if (getenv("DEBUG") != NULL && !strcmp(getenv("DEBUG"), "TRUE")) { if (getenv("DEBUG") != NULL && !strcmp(getenv("DEBUG"), "TRUE")) {
LOG_LEVEL = LOG_DEBUG; // enable debug mode settings.debug = TRUE;
}
if (getenv("VERBOSE") != NULL && !strcmp(getenv("VERBOSE"), "TRUE")) {
settings.verbose = TRUE;
} }
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
if (!strcmp(argv[i], "--debug")) { if (!strcmp(argv[i], "--debug")) {
LOG_LEVEL = LOG_DEBUG; // enable debug mode settings.debug = TRUE;
} }
if (!strcmp(argv[i], "--version")) { if (!strcmp(argv[i], "--version")) {
printf("ClearDNS version %s\n", VERSION); // show version printf("ClearDNS version %s\n", VERSION); // show version
@ -40,24 +54,23 @@ char* init(int argc, char *argv[]) { // return config file
log_error("Option `--config` missing value"); log_error("Option `--config` missing value");
exit(1); exit(1);
} }
free(config); free(settings.config);
config = string_init(argv[++i]); // use custom config file settings.config = string_init(argv[++i]); // use custom config file
} }
} }
log_debug("Config file -> %s", config); log_debug("Config file -> %s", settings.config);
return config;
} }
int main(int argc, char *argv[]) { // ClearDNS service void cleardns() { // cleardns service
char *config_file = init(argc, argv); if (settings.verbose || settings.debug) {
log_info("ClearDNS server start (%s)", VERSION); LOG_LEVEL = LOG_DEBUG; // enable debug log level
}
create_folder(EXPOSE_DIR); create_folder(EXPOSE_DIR);
create_folder(WORK_DIR); create_folder(WORK_DIR);
chdir(EXPOSE_DIR); chdir(EXPOSE_DIR);
load_config(settings.config); // configure parser
load_config(config_file); free(settings.config);
free(config_file); if (settings.debug) { // debug mode enabled
if (LOG_LEVEL == LOG_DEBUG) { // debug mode enabled
loader.diverter->debug = TRUE; loader.diverter->debug = TRUE;
loader.domestic->debug = TRUE; loader.domestic->debug = TRUE;
loader.foreign->debug = TRUE; loader.foreign->debug = TRUE;
@ -69,8 +82,8 @@ int main(int argc, char *argv[]) { // ClearDNS service
} }
} }
process_list_init();
log_info("Start loading process"); log_info("Start loading process");
process_list_init();
assets_load(loader.resource); assets_load(loader.resource);
process_list_append(dnsproxy_load("Domestic", loader.domestic, "domestic.json")); process_list_append(dnsproxy_load("Domestic", loader.domestic, "domestic.json"));
process_list_append(dnsproxy_load("Foreign", loader.foreign, "foreign.json")); process_list_append(dnsproxy_load("Foreign", loader.foreign, "foreign.json"));
@ -87,19 +100,25 @@ int main(int argc, char *argv[]) { // ClearDNS service
adguard_free(loader.filter); adguard_free(loader.filter);
} }
for (char **script = loader.script; *script != NULL; ++script) { // run custom script for (char **script = loader.script; *script != NULL; ++script) { // running custom script
log_info("Run custom script -> `%s`", *script); log_info("Run custom script -> `%s`", *script);
run_command(*script); run_command(*script);
} }
string_list_free(loader.script); string_list_free(loader.script);
process_list_run(); process_list_run(); // start all process
if (loader.crond != NULL) { // assets not disabled if (loader.crond != NULL) { // assets not disabled
pid_t my_pid = getpid(); pid_t my_pid = getpid();
log_info("ClearDNS PID -> %d", my_pid); log_info("ClearDNS PID -> %d", my_pid);
kill(my_pid, SIGALRM); // send alarm signal to itself kill(my_pid, SIGALRM); // send alarm signal to itself
crontab_free(loader.crond); crontab_free(loader.crond);
} }
process_list_daemon(); process_list_daemon(); // daemon all process
}
int main(int argc, char *argv[]) {
init(argc, argv);
log_info("ClearDNS server start (%s)", VERSION);
cleardns();
return 0; return 0;
} }

Loading…
Cancel
Save