|
@ -2,6 +2,7 @@ |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
#include <time.h> |
|
|
#include <time.h> |
|
|
#include <unistd.h> |
|
|
#include <unistd.h> |
|
|
|
|
|
#include <string.h> |
|
|
#include "loader.h" |
|
|
#include "loader.h" |
|
|
#include "logger.h" |
|
|
#include "logger.h" |
|
|
#include "constant.h" |
|
|
#include "constant.h" |
|
@ -11,11 +12,7 @@ |
|
|
#include "adguard.h" |
|
|
#include "adguard.h" |
|
|
#include "system.h" |
|
|
#include "system.h" |
|
|
#include "assets.h" |
|
|
#include "assets.h" |
|
|
|
|
|
#include "sundry.h" |
|
|
//#include <stdio.h>
|
|
|
|
|
|
//#include <string.h>
|
|
|
|
|
|
//#include "common.h"
|
|
|
|
|
|
//#include "process.h"
|
|
|
|
|
|
|
|
|
|
|
|
//char *init_script = "/usr/bin/load";
|
|
|
//char *init_script = "/usr/bin/load";
|
|
|
//char *custom_script = "/etc/cleardns/custom.sh";
|
|
|
//char *custom_script = "/etc/cleardns/custom.sh";
|
|
@ -24,48 +21,63 @@ |
|
|
//char *overture_config = "/etc/overture/config.yml";
|
|
|
//char *overture_config = "/etc/overture/config.yml";
|
|
|
//char *upstream_config = "/etc/cleardns/upstream.json";
|
|
|
//char *upstream_config = "/etc/cleardns/upstream.json";
|
|
|
|
|
|
|
|
|
//void show_command(char *title, char **command) {
|
|
|
#define HELP_MSG "\ |
|
|
// int num = 0;
|
|
|
ClearDNS usage \n\ |
|
|
// fprintf(stderr, "%s => \"", title);
|
|
|
--debug ...\n\ |
|
|
// while(command[num] != NULL) {
|
|
|
--config ...\n\ |
|
|
// fprintf(stderr, "%s", command[num++]);
|
|
|
--help ...\n\ |
|
|
// if (command[num] != NULL) {
|
|
|
" |
|
|
// fprintf(stderr, " ");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// fprintf(stderr, "\"\n");
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: load `--debug`, `--config ...`, `--version`
|
|
|
#define CONFIG_FILE "test.json" |
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { // ClearDNS server
|
|
|
// TODO: load `--debug`, `--config ...`, `--version`, `--help`
|
|
|
|
|
|
|
|
|
LOG_LEVEL = LOG_DEBUG; |
|
|
char* init(int argc, char *argv[]) { // return config file
|
|
|
log_info("ClearDNS server start (%s)", VERSION); |
|
|
char *config = string_init(CONFIG_FILE); |
|
|
|
|
|
for (int i = 0; i < argc; ++i) { |
|
|
|
|
|
if (!strcmp(argv[i], "--debug")) { |
|
|
|
|
|
LOG_LEVEL = LOG_DEBUG; // enable debug mode
|
|
|
|
|
|
} |
|
|
|
|
|
if (!strcmp(argv[i], "--version")) { |
|
|
|
|
|
printf("ClearDNS version %s\n", VERSION); // show version
|
|
|
|
|
|
exit(0); |
|
|
|
|
|
} |
|
|
|
|
|
if (!strcmp(argv[i], "--help")) { |
|
|
|
|
|
printf("\n%s\n", HELP_MSG); // show help message
|
|
|
|
|
|
exit(0); |
|
|
|
|
|
} |
|
|
|
|
|
if (!strcmp(argv[i], "--config")) { |
|
|
|
|
|
if (i + 1 == argc) { |
|
|
|
|
|
log_error("Option `--config` missing value"); |
|
|
|
|
|
exit(1); |
|
|
|
|
|
} |
|
|
|
|
|
free(config); |
|
|
|
|
|
config = string_init(argv[++i]); // use custom config file
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
log_debug("Config file -> %s", config); |
|
|
|
|
|
return config; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: load assets -> extract `/assets.tar.xz` -> ${ASSETS_DIR}*.txt
|
|
|
int main(int argc, char *argv[]) { // ClearDNS server
|
|
|
|
|
|
|
|
|
load_assets(); |
|
|
char *config_file = init(argc, argv); |
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOG_LEVEL = LOG_DEBUG; // TODO: dev only
|
|
|
|
|
|
log_info("ClearDNS server start (%s)", VERSION); |
|
|
|
|
|
|
|
|
load_config("test.json"); |
|
|
load_config(config_file); |
|
|
|
|
|
free(config_file); |
|
|
|
|
|
|
|
|
dnsproxy_load("Domestic", loader.domestic, "domestic.json"); |
|
|
dnsproxy_load("Domestic", loader.domestic, "domestic.json"); |
|
|
dnsproxy_load("Foreign", loader.foreign, "foreign.json"); |
|
|
dnsproxy_load("Foreign", loader.foreign, "foreign.json"); |
|
|
overture_load(loader.diverter, "overture.json"); |
|
|
overture_load(loader.diverter, "overture.json"); |
|
|
adguard_load(loader.filter, ADGUARD_DIR); |
|
|
adguard_load(loader.filter, ADGUARD_DIR); |
|
|
|
|
|
|
|
|
|
|
|
// TODO: running custom script
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// int debug_mode = 0;
|
|
|
|
|
|
// fprintf(stderr, "[ClearDNS] Server start.\n");
|
|
|
|
|
|
// for (char **p = argv; p < argv + argc; ++p) {
|
|
|
|
|
|
// if (!strcmp(*p, "--debug")) { // --debug option
|
|
|
|
|
|
// ++debug_mode;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// init_server(init_script, custom_script); // run init script and custom script
|
|
|
// init_server(init_script, custom_script); // run init script and custom script
|
|
|
//
|
|
|
//
|
|
|
// load_start_command(adguard_workdir, overture_config, upstream_config, debug_mode); // generate commands
|
|
|
// load_start_command(adguard_workdir, overture_config, upstream_config, debug_mode); // generate commands
|
|
|