Browse Source

feat: more options for overture

dev
dnomd343 2 years ago
parent
commit
eae715ee1b
  1. 4
      include/overture.h
  2. 71
      src/cleardns.c
  3. 2
      src/dnsproxy.c
  4. 28
      src/overture.c

4
include/overture.h

@ -5,9 +5,13 @@
typedef struct { typedef struct {
int port; int port;
int debug;
int timeout; int timeout;
char *ttl_file;
char *host_file;
int foreign_port; int foreign_port;
int domestic_port; int domestic_port;
int **reject_type;
char *foreign_ip_file; char *foreign_ip_file;
char *domestic_ip_file; char *domestic_ip_file;
char *foreign_domain_file; char *foreign_domain_file;

71
src/cleardns.c

@ -35,61 +35,48 @@ int main(int argc, char *argv[]) { // ClearDNS server
LOG_LEVEL = LOG_DEBUG; LOG_LEVEL = LOG_DEBUG;
log_info("ClearDNS server start (%s)", VERSION); log_info("ClearDNS server start (%s)", VERSION);
// int **temp = int_list_init();
// temp = int_list_append(temp, 1232);
// temp = int_list_append(temp, 2342);
// temp = int_list_append(temp, 3435);
// temp = int_list_append(temp, 456);
// temp = int_list_append(temp, 567);
//
// char *str = int_list_dump(temp);
// log_info("`%s`", str);
// char **temp = string_list_init();
// temp = string_list_append(temp, "1");
// temp = string_list_append(temp, "");
// temp = string_list_append(temp, "3");
// char *str = string_list_dump(temp); // dnsproxy *domestic = dnsproxy_init(DOMESTIC_PORT);
// log_info("`%s`", str); //
// dnsproxy_add_bootstrap(domestic, "1.1.1.1");
// dnsproxy_add_bootstrap(domestic, "8.8.8.8");
//
// dnsproxy_add_primary(domestic, "223.5.5.5");
// dnsproxy_add_primary(domestic, "tls://dns.pub");
//
// dnsproxy_add_fallback(domestic, "tls://223.6.6.6");
// dnsproxy_add_fallback(domestic, "tls://120.53.53.53");
// return 0; // domestic->verify = FALSE;
// domestic->parallel = FALSE;
// domestic->optimistic = TRUE;
// domestic->debug = TRUE;
// domestic->cache = 0;
dnsproxy *domestic = dnsproxy_init(DOMESTIC_PORT); // process *p = dnsproxy_load("Domestic", domestic, "domestic.json");
// log_info("cmd -> %s", string_list_dump(p->cmd));
// log_info("env -> %s", string_list_dump(p->env));
// log_info("cwd -> %s", p->cwd);
dnsproxy_add_bootstrap(domestic, "1.1.1.1");
dnsproxy_add_bootstrap(domestic, "8.8.8.8");
dnsproxy_add_primary(domestic, "223.5.5.5"); overture *diverter = overture_init(DIVERTER_PORT);
dnsproxy_add_primary(domestic, "tls://dns.pub");
dnsproxy_add_fallback(domestic, "tls://223.6.6.6"); diverter->timeout = 8;
dnsproxy_add_fallback(domestic, "tls://120.53.53.53"); diverter->domestic_ip_file = "china-ip.txt";
diverter->domestic_domain_file = "chinalist.txt";
diverter->foreign_domain_file = "gfwlist.txt";
domestic->verify = FALSE; diverter->debug = TRUE;
domestic->parallel = FALSE; diverter->ttl_file = "domain_ttl.txt";
domestic->optimistic = TRUE; diverter->host_file = "hosts.txt";
// domestic->debug = TRUE; diverter->reject_type = int_list_append(diverter->reject_type, 255);
domestic->cache = 0;
process *p = dnsproxy_load("Domestic", domestic, "domestic.json"); process *p = overture_load(diverter, "overture.json");
log_info("cmd -> %s", string_list_dump(p->cmd)); log_info("cmd -> %s", string_list_dump(p->cmd));
log_info("env -> %s", string_list_dump(p->env)); log_info("env -> %s", string_list_dump(p->env));
log_info("cwd -> %s", p->cwd); log_info("cwd -> %s", p->cwd);
// overture *diverter = overture_init(DIVERTER_PORT);
//
// diverter->timeout = 8;
// diverter->domestic_ip_file = "china-ip.txt";
// diverter->domestic_domain_file = "chinalist.txt";
// diverter->foreign_domain_file = "gfwlist.txt";
//
// process *p = overture_load(diverter, "overture.json");
// log_info("cmd -> %s", string_list_dump(p->cmd));
// log_info("env -> %s", string_list_dump(p->env));
// log_info("cwd -> %s", p->cwd);
// int debug_mode = 0; // int debug_mode = 0;
// fprintf(stderr, "[ClearDNS] Server start.\n"); // fprintf(stderr, "[ClearDNS] Server start.\n");
// for (char **p = argv; p < argv + argc; ++p) { // for (char **p = argv; p < argv + argc; ++p) {

2
src/dnsproxy.c

@ -70,7 +70,7 @@ process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) {
p->cmd = string_list_append(string_list_init(), DNSPROXY_BIN); p->cmd = string_list_append(string_list_init(), DNSPROXY_BIN);
p->cmd = string_list_append(p->cmd, option); p->cmd = string_list_append(p->cmd, option);
if (info->debug) { if (info->debug) {
p->cmd = string_list_append(p->cmd, "--verbose"); // dnsproxy into debug mode p->cmd = string_list_append(p->cmd, "--verbose"); // dnsproxy enable debug mode
} }
p->env = string_list_init(); p->env = string_list_init();
p->cwd = WORK_DIR; p->cwd = WORK_DIR;

28
src/overture.c

@ -13,9 +13,13 @@ char* overture_gen_config(overture *info);
overture* overture_init(int port) { // init overture options overture* overture_init(int port) { // init overture options
overture *info = (overture*)malloc(sizeof(overture)); overture *info = (overture*)malloc(sizeof(overture));
info->port = port; info->port = port;
info->debug = FALSE;
info->timeout = 6; // default timeout -> 6s info->timeout = 6; // default timeout -> 6s
info->ttl_file = NULL;
info->host_file = NULL;
info->foreign_port = FOREIGN_PORT; info->foreign_port = FOREIGN_PORT;
info->domestic_port = DOMESTIC_PORT; info->domestic_port = DOMESTIC_PORT;
info->reject_type = int_list_init();
info->foreign_ip_file = "/dev/null"; info->foreign_ip_file = "/dev/null";
info->domestic_ip_file = "/dev/null"; info->domestic_ip_file = "/dev/null";
info->foreign_domain_file = "/dev/null"; info->foreign_domain_file = "/dev/null";
@ -24,14 +28,20 @@ overture* overture_init(int port) { // init overture options
} }
void overture_dump(overture *info) { // show overture info in debug log void overture_dump(overture *info) { // show overture info in debug log
char *reject_type = int_list_dump(info->reject_type);
log_debug("Overture port -> %d", info->port); log_debug("Overture port -> %d", info->port);
log_debug("Overture debug -> %s", show_bool(info->debug));
log_debug("Overture timeout -> %d", info->timeout); log_debug("Overture timeout -> %d", info->timeout);
log_debug("Overture ttl file -> %s", info->ttl_file);
log_debug("Overture host file -> %s", info->host_file);
log_debug("Overture foreign port -> %d", info->foreign_port); log_debug("Overture foreign port -> %d", info->foreign_port);
log_debug("Overture domestic port -> %d", info->domestic_port); log_debug("Overture domestic port -> %d", info->domestic_port);
log_debug("Overture reject type -> %s", reject_type);
log_debug("Overture foreign ip file -> %s", info->foreign_ip_file); log_debug("Overture foreign ip file -> %s", info->foreign_ip_file);
log_debug("Overture domestic ip file -> %s", info->domestic_ip_file); log_debug("Overture domestic ip file -> %s", info->domestic_ip_file);
log_debug("Overture foreign domain file -> %s", info->foreign_domain_file); log_debug("Overture foreign domain file -> %s", info->foreign_domain_file);
log_debug("Overture domestic domain file -> %s", info->domestic_domain_file); log_debug("Overture domestic domain file -> %s", info->domestic_domain_file);
free(reject_type);
} }
process* overture_load(overture *info, const char *file) { process* overture_load(overture *info, const char *file) {
@ -46,6 +56,9 @@ process* overture_load(overture *info, const char *file) {
p->cmd = string_list_append(string_list_init(), OVERTURE_BIN); p->cmd = string_list_append(string_list_init(), OVERTURE_BIN);
p->cmd = string_list_append(p->cmd, "-c"); p->cmd = string_list_append(p->cmd, "-c");
p->cmd = string_list_append(p->cmd, file); p->cmd = string_list_append(p->cmd, file);
if (info->debug) {
p->cmd = string_list_append(p->cmd, "-v"); // overture enable debug mode
}
p->env = string_list_init(); p->env = string_list_init();
p->cwd = WORK_DIR; p->cwd = WORK_DIR;
return p; return p;
@ -97,9 +110,24 @@ char* overture_gen_config(overture *info) { // generate json configure from over
cJSON_AddItemToObject(config, "domainFile", domain_file); cJSON_AddItemToObject(config, "domainFile", domain_file);
cJSON *host_file = cJSON_CreateObject(); cJSON *host_file = cJSON_CreateObject();
if (info->host_file != NULL) {
cJSON_AddStringToObject(host_file, "hostsFile", info->host_file);
}
cJSON_AddStringToObject(host_file, "finder", "full-map"); cJSON_AddStringToObject(host_file, "finder", "full-map");
cJSON_AddItemToObject(config, "hostsFile", host_file); cJSON_AddItemToObject(config, "hostsFile", host_file);
if (info->ttl_file != NULL) {
cJSON_AddStringToObject(config, "domainTTLFile", info->ttl_file);
}
if (int_list_len(info->reject_type)) {
cJSON *reject_type = cJSON_CreateArray();
for (int **rr_num = info->reject_type; *rr_num != NULL; ++rr_num) {
cJSON_AddItemToArray(reject_type, cJSON_CreateNumber(**rr_num));
}
cJSON_AddItemToObject(config, "rejectQType", reject_type);
}
char *config_str = cJSON_Print(config); char *config_str = cJSON_Print(config);
cJSON_Delete(config); // free json object cJSON_Delete(config); // free json object
free(domestic_port); free(domestic_port);

Loading…
Cancel
Save