mirror of https://github.com/dnomd343/ClearDNS
dnomd343
2 years ago
21 changed files with 190 additions and 170 deletions
@ -1,83 +0,0 @@ |
|||
#ifndef _COMMON_H_ |
|||
#define _COMMON_H_ |
|||
|
|||
//#include <stdlib.h>
|
|||
//
|
|||
//typedef u_int8_t uint8_t;
|
|||
//typedef u_int16_t uint16_t;
|
|||
//typedef u_int32_t uint32_t;
|
|||
//typedef u_int64_t uint64_t;
|
|||
|
|||
#include <stdint.h> |
|||
|
|||
#define VERSION "1.3.0-dev" |
|||
|
|||
#define TRUE 1 |
|||
#define FALSE 0 |
|||
|
|||
#define DNS_PORT 53 |
|||
#define ADGUARD_PORT 80 |
|||
#define DIVERTER_PORT 5353 |
|||
#define DOMESTIC_PORT 4053 |
|||
#define FOREIGN_PORT 6053 |
|||
|
|||
#define DIVERTER_TIMEOUT 6 |
|||
|
|||
#define ADGUARD_USER "admin" |
|||
#define ADGUARD_PASSWD "adguard" |
|||
|
|||
#define DNSPROXY_BIN "dnsproxy" |
|||
#define OVERTURE_BIN "overture" |
|||
#define ADGUARD_BIN "AdGuardHome" |
|||
|
|||
#define WORK_DIR "/etc/cleardns/" |
|||
#define EXPOSE_DIR "/cleardns/" |
|||
#define ASSETS_DIR "/cleardns/assets/" |
|||
#define ADGUARD_DIR "/cleardns/adguard/" |
|||
|
|||
#define ASSET_TTL "ttl.txt" |
|||
#define ASSET_HOSTS "hosts.txt" |
|||
#define ASSET_GFW_LIST "gfwlist.txt" |
|||
#define ASSET_CHINA_IP "china-ip.txt" |
|||
#define ASSET_CHINA_LIST "chinalist.txt" |
|||
|
|||
//extern char **adguard_command;
|
|||
//extern char **overture_command;
|
|||
//extern char **domestic_dnsproxy_command;
|
|||
//extern char **foreign_dnsproxy_command;
|
|||
|
|||
//void load_start_command(char *adguard_workdir, char *overture_config, char *upstream_config, int is_debug);
|
|||
|
|||
char* show_bool(uint8_t value); |
|||
char* read_file(const char *file); |
|||
void save_file(const char *file, const char *content); |
|||
void string_list_debug(char *describe, char **string_list); |
|||
void uint32_list_debug(char *describe, uint32_t **uint32_list); |
|||
|
|||
uint8_t check_port(uint16_t port); |
|||
uint16_t gen_rand_num(uint16_t limit); |
|||
char* uint32_to_string(uint32_t number); |
|||
|
|||
void save_string_list(const char *file, char **string_list); |
|||
|
|||
char* gen_bcrypt(const char *data); |
|||
int run_command(const char *command); |
|||
void create_folder(const char *folder); |
|||
|
|||
char* string_init(const char *str); |
|||
char* string_join(const char *base, const char *add); |
|||
|
|||
#include "cJSON.h" |
|||
|
|||
char* to_json(const char *config_file); |
|||
cJSON* json_field_get(cJSON *entry, const char *field); |
|||
void json_field_replace(cJSON *entry, const char *field, cJSON *content); |
|||
|
|||
uint8_t json_bool_value(char *key, cJSON *json); |
|||
uint32_t** json_uint32_list_value(char *key, cJSON *json, uint32_t **uint32_list); |
|||
char** json_string_list_value(char *key, cJSON *json, char **string_list); |
|||
char* json_string_value(char* key, cJSON *json); |
|||
int json_int_value(char *key, cJSON *json); |
|||
uint8_t is_json_suffix(const char *file_name); |
|||
|
|||
#endif |
@ -0,0 +1,48 @@ |
|||
#ifndef _COMMON_H_ |
|||
#define _COMMON_H_ |
|||
|
|||
#define VERSION "1.3.0-dev" |
|||
|
|||
#define TRUE 1 |
|||
#define FALSE 0 |
|||
|
|||
#define DNS_PORT 53 |
|||
#define ADGUARD_PORT 80 |
|||
#define DIVERTER_PORT 5353 |
|||
#define DOMESTIC_PORT 4053 |
|||
#define FOREIGN_PORT 6053 |
|||
|
|||
#define DIVERTER_TIMEOUT 6 |
|||
|
|||
#define ADGUARD_USER "admin" |
|||
#define ADGUARD_PASSWD "adguard" |
|||
|
|||
#define DNSPROXY_BIN "dnsproxy" |
|||
#define OVERTURE_BIN "overture" |
|||
#define ADGUARD_BIN "AdGuardHome" |
|||
|
|||
#define WORK_DIR "/etc/cleardns/" |
|||
#define EXPOSE_DIR "/cleardns/" |
|||
#define ASSETS_DIR "/cleardns/assets/" |
|||
#define ADGUARD_DIR "/cleardns/adguard/" |
|||
|
|||
#define ASSET_TTL "ttl.txt" |
|||
#define ASSET_HOSTS "hosts.txt" |
|||
#define ASSET_GFW_LIST "gfwlist.txt" |
|||
#define ASSET_CHINA_IP "china-ip.txt" |
|||
#define ASSET_CHINA_LIST "chinalist.txt" |
|||
|
|||
#include <stdint.h> |
|||
|
|||
char* show_bool(uint8_t value); |
|||
void string_list_debug(char *describe, char **string_list); |
|||
void uint32_list_debug(char *describe, uint32_t **uint32_list); |
|||
|
|||
uint8_t check_port(uint16_t port); |
|||
uint16_t gen_rand_num(uint16_t limit); |
|||
char* uint32_to_string(uint32_t number); |
|||
|
|||
char* string_init(const char *str); |
|||
char* string_join(const char *base, const char *add); |
|||
|
|||
#endif |
@ -0,0 +1,18 @@ |
|||
#ifndef _JSON_H_ |
|||
#define _JSON_H_ |
|||
|
|||
#include <stdint.h> |
|||
#include "cJSON.h" |
|||
|
|||
char* to_json(const char *config_file); |
|||
cJSON* json_field_get(cJSON *entry, const char *field); |
|||
void json_field_replace(cJSON *entry, const char *field, cJSON *content); |
|||
|
|||
uint8_t json_bool_value(char *key, cJSON *json); |
|||
uint32_t** json_uint32_list_value(char *key, cJSON *json, uint32_t **uint32_list); |
|||
char** json_string_list_value(char *key, cJSON *json, char **string_list); |
|||
char* json_string_value(char* key, cJSON *json); |
|||
int json_int_value(char *key, cJSON *json); |
|||
uint8_t is_json_suffix(const char *file_name); |
|||
|
|||
#endif |
@ -0,0 +1,10 @@ |
|||
#ifndef _SYSTEM_H_ |
|||
#define _SYSTEM_H_ |
|||
|
|||
char* read_file(const char *file); |
|||
int run_command(const char *command); |
|||
void create_folder(const char *folder); |
|||
void save_file(const char *file, const char *content); |
|||
void save_string_list(const char *file, char **string_list); |
|||
|
|||
#endif |
@ -1,4 +1,4 @@ |
|||
cmake_minimum_required(VERSION 2.8.12) |
|||
|
|||
add_library(applet adguard.c dnsproxy.c overture.c) |
|||
target_link_libraries(applet utils) |
|||
target_link_libraries(applet bcrypt utils) |
|||
|
@ -0,0 +1,19 @@ |
|||
#include <stdlib.h> |
|||
#include "bcrypt.h" |
|||
#include "logger.h" |
|||
|
|||
char* bcrypt_cal(const char *data) { |
|||
char salt[BCRYPT_HASHSIZE]; |
|||
log_debug("BCrypt data -> `%s`", data); |
|||
if (bcrypt_gensalt(10, salt)) { |
|||
log_fatal("BCrypt generate salt error"); |
|||
} |
|||
log_debug("BCrypt salt -> `%s`", salt); |
|||
|
|||
char *hash = (char *)malloc(BCRYPT_HASHSIZE); |
|||
if (bcrypt_hashpw(data, salt, hash)) { |
|||
log_fatal("BCrypt generate hash error"); |
|||
} |
|||
log_debug("BCrypt hash -> `%s`", hash); |
|||
return hash; |
|||
} |
@ -0,0 +1,3 @@ |
|||
cmake_minimum_required(VERSION 2.8.12) |
|||
|
|||
add_library(common common.c json.c system.c structure.c) |
@ -0,0 +1,57 @@ |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
#include <sys/time.h> |
|||
#include "common.h" |
|||
#include "logger.h" |
|||
#include "structure.h" |
|||
#include "bcrypt.h" |
|||
|
|||
char* show_bool(uint8_t value) { // return `true` or `false`
|
|||
if (value) { |
|||
return "true"; |
|||
} else { |
|||
return "false"; |
|||
} |
|||
} |
|||
|
|||
char* string_init(const char *str) { // new string
|
|||
return strcpy((char *)malloc(strlen(str) + 1), str); |
|||
} |
|||
|
|||
char* string_join(const char *base, const char *add) { // combine string
|
|||
char *ret = (char *)malloc(strlen(base) + strlen(add) + 1); |
|||
return strcat(strcpy(ret, base), add); |
|||
} |
|||
|
|||
void string_list_debug(char *describe, char **string_list) { |
|||
char *string_ret = string_list_dump(string_list); |
|||
log_debug("%s -> %s", describe, string_ret); |
|||
free(string_ret); |
|||
} |
|||
|
|||
void uint32_list_debug(char *describe, uint32_t **uint32_list) { |
|||
char *string_ret = uint32_list_dump(uint32_list); |
|||
log_debug("%s -> %s", describe, string_ret); |
|||
free(string_ret); |
|||
} |
|||
|
|||
uint8_t check_port(uint16_t port) { |
|||
if (port > 0 && port <= 65535) { // 1 ~ 65535
|
|||
return TRUE; |
|||
} |
|||
return FALSE; |
|||
} |
|||
|
|||
char* uint32_to_string(uint32_t number) { |
|||
char to_str[11]; // 32-bits (MAX_LEN -> 4294967296 -> 10-bytes)
|
|||
sprintf(to_str, "%u", number); |
|||
return string_init(to_str); |
|||
} |
|||
|
|||
uint16_t gen_rand_num(uint16_t limit) { // 0 ~ (limit - 1)
|
|||
struct timeval tv; |
|||
gettimeofday(&tv, NULL); |
|||
srand(tv.tv_usec); |
|||
return rand() % limit; // NOLINT
|
|||
} |
@ -1,8 +1,8 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <stdlib.h> |
|||
#include "structure.h" |
|||
#include "common.h" |
|||
#include "structure.h" |
|||
|
|||
uint32_t* uint32_init(uint32_t number) { // new uint32 (by malloc)
|
|||
uint32_t *data = (uint32_t *)malloc(sizeof(uint32_t)); |
@ -1,3 +1,3 @@ |
|||
cmake_minimum_required(VERSION 2.8.12) |
|||
|
|||
add_library(utils cJSON.c json.c logger.c process.c structure.c) |
|||
add_library(utils cJSON.c logger.c process.c) |
|||
|
Loading…
Reference in new issue