Skip to content
Snippets Groups Projects
Commit d2977324 authored by dmitriy.gerasimov's avatar dmitriy.gerasimov
Browse files

Merge branch 'feature-3600' into 'master'

added geoip_init()

See merge request !88
parents 602a9ab5 ead0d836
No related branches found
No related tags found
1 merge request!88added geoip_init()
...@@ -78,6 +78,7 @@ static int bugreport_write_to_file(byte_t *a_request_byte, size_t a_request_size ...@@ -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) 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://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"); log_it(L_DEBUG, "bugreport_http_proc request");
http_status_code_t * return_code = (http_status_code_t*) a_arg; http_status_code_t * return_code = (http_status_code_t*) a_arg;
//if(dap_strcmp(cl_st->http->url_path, BUGREPORT_URL) == 0 ) //if(dap_strcmp(cl_st->http->url_path, BUGREPORT_URL) == 0 )
......
...@@ -957,11 +957,11 @@ int dap_chain_node_cli_init(dap_config_t * g_config) ...@@ -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", dap_chain_node_cli_cmd_item_create ("exit", com_exit, NULL, "Stop application and exit",
"exit\n" ); "exit\n" );
#ifndef _WIN32 //#ifndef _WIN32
// News // 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\"", 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"); "news [-text <news text> | -file <filename with news>] -lang <language code> \n");
#endif //#endif
// create thread for waiting of clients // create thread for waiting of clients
pthread_t l_thread_id; pthread_t l_thread_id;
......
...@@ -133,10 +133,10 @@ int com_stats(int argc, char ** argv, void *arg_func, char **str_reply); ...@@ -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); int com_exit(int argc, char ** argv, void *arg_func, char **str_reply);
#ifndef _WIN32 //#ifndef _WIN32
// Add News for VPN clients // Add News for VPN clients
//int com_news(int a_argc, char ** a_argv, void *a_arg_func, char **a_str_reply); int com_news(int a_argc, char ** a_argv, void *a_arg_func, char **a_str_reply);
#endif //#endif
// vpn_client command // vpn_client command
int com_vpn_client(int a_argc, char ** a_argv, void *arg_func, char **a_str_reply); int com_vpn_client(int a_argc, char ** a_argv, void *arg_func, char **a_str_reply);
......
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
#define LOG_TAG "chain_net_srv_geoip" #define LOG_TAG "chain_net_srv_geoip"
#define LOCALE_DEFAULT "en" #define LOCALE_DEFAULT "en"
static char *s_geoip_db_file_path = NULL; // share/geoip/GeoLite2-City.mmdb
/** /**
* @brief m_request_response * @brief m_request_response
* @param a_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 ...@@ -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://geoip.maxmind.com/geoip/v2.1/city/178.7.88.55
// https://maxmind.github.io/libmaxminddb/ // https://maxmind.github.io/libmaxminddb/
char *l_file_db_name = dap_strdup_printf("%s/share/geoip/GeoLite2-City.mmdb", g_sys_dir_path); //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)) { if(!dap_file_test(s_geoip_db_file_path)) {
DAP_DELETE(l_file_db_name); //DAP_DELETE(l_file_db_name);
return NULL ; return NULL ;
} }
MMDB_s mmdb; 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) { 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 ; 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); 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) ...@@ -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_local_db(a_ip_str, "en");
//return chain_net_geoip_get_ip_info_by_web(a_ip_str); //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;
}
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "dap_config.h"
typedef struct geoip_info { typedef struct geoip_info {
char ip_str[20]; char ip_str[20];
...@@ -35,3 +37,5 @@ typedef struct geoip_info { ...@@ -35,3 +37,5 @@ typedef struct geoip_info {
} geoip_info_t; } geoip_info_t;
geoip_info_t *chain_net_geoip_get_ip_info(const char *a_ip_str); geoip_info_t *chain_net_geoip_get_ip_info(const char *a_ip_str);
int chain_net_geoip_init(dap_config_t *a_config);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment