Skip to content
Snippets Groups Projects
Commit ead0d836 authored by alexander.lysikov's avatar alexander.lysikov
Browse files

added geoip_init()

parent 602a9ab5
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
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 )
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
}
......@@ -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);
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