From ead0d836ae6e0dfab5f754058b0baac630520384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Al=D0=B5x=D0=B0nder=20Lysik=D0=BEv?= <alexander.lysikov@demlabs.net> Date: Mon, 1 Jun 2020 22:57:48 +0500 Subject: [PATCH] added geoip_init() --- modules/net/dap_chain_net_bugreport.c | 1 + modules/net/dap_chain_node_cli.c | 8 ++--- modules/net/include/dap_chain_node_cli_cmd.h | 6 ++-- modules/net/srv/dap_chain_net_srv_geoip.c | 37 ++++++++++++++++---- modules/net/srv/dap_chain_net_srv_geoip.h | 4 +++ 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/modules/net/dap_chain_net_bugreport.c b/modules/net/dap_chain_net_bugreport.c index 9d466d317a..63b00ba2db 100644 --- a/modules/net/dap_chain_net_bugreport.c +++ b/modules/net/dap_chain_net_bugreport.c @@ -78,6 +78,7 @@ static int bugreport_write_to_file(byte_t *a_request_byte, size_t a_request_size static void bugreport_http_proc(struct dap_http_simple *a_http_simple, void * a_arg) { // data:text/html,<form action=http://192.168.100.92:8079/bugreport/ method=post><input name=a></form> + // data:text/html,<form action=http://cdb.klvn.io/bugreport/ method=post><input name=a></form> log_it(L_DEBUG, "bugreport_http_proc request"); http_status_code_t * return_code = (http_status_code_t*) a_arg; //if(dap_strcmp(cl_st->http->url_path, BUGREPORT_URL) == 0 ) diff --git a/modules/net/dap_chain_node_cli.c b/modules/net/dap_chain_node_cli.c index 82e0eba706..7e000f75d5 100644 --- a/modules/net/dap_chain_node_cli.c +++ b/modules/net/dap_chain_node_cli.c @@ -957,11 +957,11 @@ int dap_chain_node_cli_init(dap_config_t * g_config) dap_chain_node_cli_cmd_item_create ("exit", com_exit, NULL, "Stop application and exit", "exit\n" ); -#ifndef _WIN32 +//#ifndef _WIN32 // News - //dap_chain_node_cli_cmd_item_create("news", com_news, NULL, "Add News for VPN clients. Language code is a text code like \"en\", \"ru\", \"fr\"", - // "news [-text <news text> | -file <filename with news>] -lang <language code> \n"); -#endif + dap_chain_node_cli_cmd_item_create("news", com_news, NULL, "Add News for VPN clients. Language code is a text code like \"en\", \"ru\", \"fr\"", + "news [-text <news text> | -file <filename with news>] -lang <language code> \n"); +//#endif // create thread for waiting of clients pthread_t l_thread_id; diff --git a/modules/net/include/dap_chain_node_cli_cmd.h b/modules/net/include/dap_chain_node_cli_cmd.h index ed35ce7a41..dc5f569568 100644 --- a/modules/net/include/dap_chain_node_cli_cmd.h +++ b/modules/net/include/dap_chain_node_cli_cmd.h @@ -133,10 +133,10 @@ int com_stats(int argc, char ** argv, void *arg_func, char **str_reply); int com_exit(int argc, char ** argv, void *arg_func, char **str_reply); -#ifndef _WIN32 +//#ifndef _WIN32 // Add News for VPN clients -//int com_news(int a_argc, char ** a_argv, void *a_arg_func, char **a_str_reply); -#endif +int com_news(int a_argc, char ** a_argv, void *a_arg_func, char **a_str_reply); +//#endif // vpn_client command int com_vpn_client(int a_argc, char ** a_argv, void *arg_func, char **a_str_reply); diff --git a/modules/net/srv/dap_chain_net_srv_geoip.c b/modules/net/srv/dap_chain_net_srv_geoip.c index a0f1a31b0b..ff7aea1c4f 100644 --- a/modules/net/srv/dap_chain_net_srv_geoip.c +++ b/modules/net/srv/dap_chain_net_srv_geoip.c @@ -37,6 +37,9 @@ #define LOG_TAG "chain_net_srv_geoip" #define LOCALE_DEFAULT "en" + +static char *s_geoip_db_file_path = NULL; // share/geoip/GeoLite2-City.mmdb + /** * @brief m_request_response * @param a_response @@ -168,18 +171,18 @@ geoip_info_t *chain_net_geoip_get_ip_info_by_local_db(const char *a_ip_str, cons { // https://geoip.maxmind.com/geoip/v2.1/city/178.7.88.55 // https://maxmind.github.io/libmaxminddb/ - char *l_file_db_name = dap_strdup_printf("%s/share/geoip/GeoLite2-City.mmdb", g_sys_dir_path); - if(!dap_file_test(l_file_db_name)) { - DAP_DELETE(l_file_db_name); + //char *l_file_db_name = dap_strdup_printf("%s/share/geoip/GeoLite2-City.mmdb", g_sys_dir_path); + if(!dap_file_test(s_geoip_db_file_path)) { + //DAP_DELETE(l_file_db_name); return NULL ; } MMDB_s mmdb; - int l_status = MMDB_open(l_file_db_name, MMDB_MODE_MMAP, &mmdb); + int l_status = MMDB_open(s_geoip_db_file_path, MMDB_MODE_MMAP, &mmdb); if(MMDB_SUCCESS != l_status) { - log_it(L_WARNING, "geoip file %s opened with errcode=%d", l_file_db_name, l_status); + log_it(L_WARNING, "geoip file %s opened with errcode=%d", s_geoip_db_file_path, l_status); return NULL ; } - DAP_DELETE(l_file_db_name); + //DAP_DELETE(l_file_db_name); geoip_info_t *l_ret = DAP_NEW_Z(geoip_info_t); @@ -252,3 +255,25 @@ geoip_info_t *chain_net_geoip_get_ip_info(const char *a_ip_str) return chain_net_geoip_get_ip_info_by_local_db(a_ip_str, "en"); //return chain_net_geoip_get_ip_info_by_web(a_ip_str); } + + +int chain_net_geoip_init(dap_config_t *a_config) +{ + s_geoip_db_file_path = dap_strdup_printf("%s/%s", g_sys_dir_path, + dap_config_get_item_str(g_config, "resources", "geoip_db_path")); + if(!dap_file_test(s_geoip_db_file_path)) { + log_it(L_ERROR, "No exists geoip db file %s", s_geoip_db_file_path); + DAP_DELETE(s_geoip_db_file_path); + s_geoip_db_file_path = NULL; + return -1; + } + MMDB_s mmdb; + int l_status = MMDB_open(s_geoip_db_file_path, MMDB_MODE_MMAP, &mmdb); + if(MMDB_SUCCESS != l_status) { + log_it(L_WARNING, "geoip file %s opened with errcode=%d", s_geoip_db_file_path, l_status); + DAP_DELETE(s_geoip_db_file_path); + s_geoip_db_file_path = NULL; + return -2; + } + return 0; +} diff --git a/modules/net/srv/dap_chain_net_srv_geoip.h b/modules/net/srv/dap_chain_net_srv_geoip.h index 714dbc62f2..1f8ecd5be3 100644 --- a/modules/net/srv/dap_chain_net_srv_geoip.h +++ b/modules/net/srv/dap_chain_net_srv_geoip.h @@ -22,6 +22,8 @@ along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ +#include "dap_config.h" + typedef struct geoip_info { char ip_str[20]; @@ -35,3 +37,5 @@ typedef struct geoip_info { } geoip_info_t; geoip_info_t *chain_net_geoip_get_ip_info(const char *a_ip_str); + +int chain_net_geoip_init(dap_config_t *a_config); -- GitLab