parent
42df8b3ed7
commit
c20427b71b
|
@ -41,6 +41,7 @@
|
|||
|
||||
server.modules = (
|
||||
"mod_portal",
|
||||
"mod_usermagnet",
|
||||
# "mod_webm",
|
||||
# "mod_access",
|
||||
# "mod_alias",
|
||||
|
|
|
@ -414,6 +414,11 @@ mod_portal_la_SOURCES = mod_portal.c json.c user_hashtable.c user_auth.c
|
|||
mod_portal_la_LDFLAGS = -module -export-dynamic -avoid-version -L../../../../Platform/build/debug/
|
||||
mod_portal_la_LIBADD = $(common_libadd) -ldatabase-$(host_cpu)
|
||||
|
||||
lib_LTLIBRARIES += mod_usermagnet.la
|
||||
mod_usermagnet_la_SOURCES = mod_usermagnet.c json.c user_hashtable.c user_auth.c
|
||||
mod_usermagnet_la_LDFLAGS = -module -export-dynamic -avoid-version -L../../../../Platform/build/debug/
|
||||
mod_usermagnet_la_LIBADD = $(common_libadd) -ldatabase-$(host_cpu)
|
||||
|
||||
hdr = server.h base64.h buffer.h burl.h network.h log.h http_kv.h keyvalue.h \
|
||||
response.h request.h fastcgi.h chunk.h \
|
||||
first.h settings.h http_chunk.h \
|
||||
|
|
|
@ -583,6 +583,14 @@ mod_userdir_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
|
|||
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
|
||||
$(AM_CFLAGS) $(CFLAGS) $(mod_userdir_la_LDFLAGS) $(LDFLAGS) -o \
|
||||
$@
|
||||
mod_usermagnet_la_DEPENDENCIES = $(am__DEPENDENCIES_2)
|
||||
am_mod_usermagnet_la_OBJECTS = mod_usermagnet.lo json.lo \
|
||||
user_hashtable.lo user_auth.lo
|
||||
mod_usermagnet_la_OBJECTS = $(am_mod_usermagnet_la_OBJECTS)
|
||||
mod_usermagnet_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
|
||||
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
|
||||
$(AM_CFLAGS) $(CFLAGS) $(mod_usermagnet_la_LDFLAGS) $(LDFLAGS) \
|
||||
-o $@
|
||||
mod_usertrack_la_DEPENDENCIES = $(am__DEPENDENCIES_2)
|
||||
am_mod_usertrack_la_OBJECTS = mod_usertrack.lo
|
||||
mod_usertrack_la_OBJECTS = $(am_mod_usertrack_la_OBJECTS)
|
||||
|
@ -925,9 +933,9 @@ SOURCES = $(liblightcomp_la_SOURCES) $(mod_access_la_SOURCES) \
|
|||
$(mod_staticfile_la_SOURCES) $(mod_status_la_SOURCES) \
|
||||
$(mod_trigger_b4_dl_la_SOURCES) \
|
||||
$(mod_uploadprogress_la_SOURCES) $(mod_userdir_la_SOURCES) \
|
||||
$(mod_usertrack_la_SOURCES) $(mod_vhostdb_la_SOURCES) \
|
||||
$(mod_vhostdb_dbi_la_SOURCES) $(mod_vhostdb_ldap_la_SOURCES) \
|
||||
$(mod_vhostdb_mysql_la_SOURCES) \
|
||||
$(mod_usermagnet_la_SOURCES) $(mod_usertrack_la_SOURCES) \
|
||||
$(mod_vhostdb_la_SOURCES) $(mod_vhostdb_dbi_la_SOURCES) \
|
||||
$(mod_vhostdb_ldap_la_SOURCES) $(mod_vhostdb_mysql_la_SOURCES) \
|
||||
$(mod_vhostdb_pgsql_la_SOURCES) $(mod_webdav_la_SOURCES) \
|
||||
$(mod_webm_la_SOURCES) $(mod_wstunnel_la_SOURCES) \
|
||||
$(lighttpd_SOURCES) $(lighttpd_angel_SOURCES) \
|
||||
|
@ -960,7 +968,8 @@ DIST_SOURCES = $(am__liblightcomp_la_SOURCES_DIST) \
|
|||
$(mod_staticfile_la_SOURCES) $(mod_status_la_SOURCES) \
|
||||
$(am__mod_trigger_b4_dl_la_SOURCES_DIST) \
|
||||
$(mod_uploadprogress_la_SOURCES) $(mod_userdir_la_SOURCES) \
|
||||
$(mod_usertrack_la_SOURCES) $(mod_vhostdb_la_SOURCES) \
|
||||
$(mod_usermagnet_la_SOURCES) $(mod_usertrack_la_SOURCES) \
|
||||
$(mod_vhostdb_la_SOURCES) \
|
||||
$(am__mod_vhostdb_dbi_la_SOURCES_DIST) \
|
||||
$(am__mod_vhostdb_ldap_la_SOURCES_DIST) \
|
||||
$(am__mod_vhostdb_mysql_la_SOURCES_DIST) \
|
||||
|
@ -1246,7 +1255,7 @@ lib_LTLIBRARIES = $(am__append_1) mod_flv_streaming.la $(am__append_3) \
|
|||
$(am__append_14) $(am__append_15) mod_rewrite.la \
|
||||
mod_redirect.la mod_status.la mod_accesslog.la \
|
||||
mod_uploadprogress.la mod_wstunnel.la mod_webm.la \
|
||||
mod_portal.la
|
||||
mod_portal.la mod_usermagnet.la
|
||||
@NO_RDYNAMIC_FALSE@common_ldflags = -avoid-version
|
||||
|
||||
# if the linker doesn't allow referencing symbols of the binary
|
||||
|
@ -1422,6 +1431,9 @@ mod_webm_la_LIBADD = $(common_libadd)
|
|||
mod_portal_la_SOURCES = mod_portal.c json.c user_hashtable.c user_auth.c
|
||||
mod_portal_la_LDFLAGS = -module -export-dynamic -avoid-version -L../../../../Platform/build/debug/
|
||||
mod_portal_la_LIBADD = $(common_libadd) -ldatabase-$(host_cpu)
|
||||
mod_usermagnet_la_SOURCES = mod_usermagnet.c json.c user_hashtable.c user_auth.c
|
||||
mod_usermagnet_la_LDFLAGS = -module -export-dynamic -avoid-version -L../../../../Platform/build/debug/
|
||||
mod_usermagnet_la_LIBADD = $(common_libadd) -ldatabase-$(host_cpu)
|
||||
hdr = server.h base64.h buffer.h burl.h network.h log.h http_kv.h keyvalue.h \
|
||||
response.h request.h fastcgi.h chunk.h \
|
||||
first.h settings.h http_chunk.h \
|
||||
|
@ -1706,6 +1718,9 @@ mod_uploadprogress.la: $(mod_uploadprogress_la_OBJECTS) $(mod_uploadprogress_la_
|
|||
mod_userdir.la: $(mod_userdir_la_OBJECTS) $(mod_userdir_la_DEPENDENCIES) $(EXTRA_mod_userdir_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(mod_userdir_la_LINK) -rpath $(libdir) $(mod_userdir_la_OBJECTS) $(mod_userdir_la_LIBADD) $(LIBS)
|
||||
|
||||
mod_usermagnet.la: $(mod_usermagnet_la_OBJECTS) $(mod_usermagnet_la_DEPENDENCIES) $(EXTRA_mod_usermagnet_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(mod_usermagnet_la_LINK) -rpath $(libdir) $(mod_usermagnet_la_OBJECTS) $(mod_usermagnet_la_LIBADD) $(LIBS)
|
||||
|
||||
mod_usertrack.la: $(mod_usertrack_la_OBJECTS) $(mod_usertrack_la_DEPENDENCIES) $(EXTRA_mod_usertrack_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(mod_usertrack_la_LINK) -rpath $(libdir) $(mod_usertrack_la_OBJECTS) $(mod_usertrack_la_LIBADD) $(LIBS)
|
||||
|
||||
|
@ -2046,6 +2061,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mod_trigger_b4_dl.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mod_uploadprogress.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mod_userdir.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mod_usermagnet.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mod_usertrack.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mod_vhostdb.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mod_vhostdb_dbi_la-mod_vhostdb_dbi.Plo@am__quote@
|
||||
|
|
|
@ -0,0 +1,520 @@
|
|||
#include "first.h"
|
||||
#include "base_decls.h"
|
||||
#include "json.h"
|
||||
#include "user_hashtable.h"
|
||||
#include "base.h"
|
||||
#include "plugin.h"
|
||||
#include "http_auth.h"
|
||||
#include "http_header.h"
|
||||
#include "log.h"
|
||||
#include "dlfcn.h"
|
||||
#include "connections.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include "user_auth.h"
|
||||
#include "arpa/inet.h"
|
||||
#include "unistd.h"
|
||||
#include "stddef.h"
|
||||
#include "/usr/include/x86_64-linux-gnu/sys/socket.h"
|
||||
|
||||
#define DEL_MAX_NUM (100)
|
||||
#define DEL_MAX_SIZE (24)
|
||||
|
||||
/*函数指针*/
|
||||
typedef void (*mod_usermagnet_cfg_exec_sync)(int page_num, int count, char *user_name, cJSON *array);
|
||||
|
||||
typedef struct {
|
||||
PLUGIN_DATA;
|
||||
void *cfgm_lib;
|
||||
mod_usermagnet_cfg_exec_sync usermagnet_cfg_exec;
|
||||
} mod_usermagnet_plugin_data;
|
||||
|
||||
|
||||
INIT_FUNC(mod_usermagnet_init) {
|
||||
mod_usermagnet_plugin_data *p;
|
||||
|
||||
p = calloc(1, sizeof(*p));
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/*认证模块释放*/
|
||||
FREE_FUNC(mod_usermagnet_free) {
|
||||
mod_usermagnet_plugin_data *p = p_d;
|
||||
srv = srv;
|
||||
if (!p) return HANDLER_GO_ON;
|
||||
|
||||
//dlclose(p->cfgm_lib);
|
||||
free(p);
|
||||
|
||||
return HANDLER_GO_ON;
|
||||
}
|
||||
|
||||
/*查询在线用户信息
|
||||
查询条件 1、用户IP 唯一性
|
||||
2、用户名 一个用户名对应多个IP
|
||||
3、NULL 查询所有在线用户信息
|
||||
*/
|
||||
static handler_t get_onlineuser_info(server *srv, connection *con, void* p_d)
|
||||
{
|
||||
p_d = p_d;
|
||||
cJSON *cjson,*userip, *username, *Page_Num, *Count;
|
||||
cJSON *pJsonArry;
|
||||
USER_INFO *user_info;
|
||||
uint32_t clientip;
|
||||
char *ip = NULL;
|
||||
char *name = NULL;
|
||||
char *result_str = NULL;
|
||||
int page_num = 0;
|
||||
int count = 0;
|
||||
char str[INET_ADDRSTRLEN];
|
||||
|
||||
user_info = (USER_INFO *)malloc(sizeof(USER_INFO));
|
||||
|
||||
if(NULL == user_info)
|
||||
{
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
|
||||
/*get payload*/
|
||||
handler_t result = connection_handle_read_post_state(srv, con);
|
||||
log_error_write(srv, __FILE__, __LINE__, "sd","test", result);
|
||||
|
||||
if (result != HANDLER_GO_ON)
|
||||
{
|
||||
return result ;
|
||||
}
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
|
||||
buffer *b = buffer_init();
|
||||
chunkqueue *dst_cq = con->request_content_queue;
|
||||
chunk *c = dst_cq->first;
|
||||
if (NULL == c)
|
||||
{
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
while(c != NULL)
|
||||
{
|
||||
buffer_append_string(b, c->mem->ptr + c->offset);
|
||||
c = c->next;
|
||||
}
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "sb","test",b);
|
||||
|
||||
/*JSON字符串到JSON格式 */
|
||||
cjson = cJSON_Parse(b->ptr);
|
||||
if(!cjson)
|
||||
{
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
/*get userip */
|
||||
userip = cJSON_GetObjectItem(cjson , "user_ip");
|
||||
if(userip)
|
||||
{
|
||||
ip = userip->valuestring;
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss", "test", ip);
|
||||
}
|
||||
|
||||
/*get username*/
|
||||
username = cJSON_GetObjectItem(cjson , "user_name");
|
||||
if(username)
|
||||
{
|
||||
name = username->valuestring;
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss", "test", name);
|
||||
}
|
||||
|
||||
/*get page_num*/
|
||||
Page_Num = cJSON_GetObjectItem(cjson, "page_num");
|
||||
if(Page_Num)
|
||||
{
|
||||
page_num = Page_Num->valueint;
|
||||
log_error_write(srv, __FILE__, __LINE__, "sd", "test", page_num);
|
||||
}
|
||||
|
||||
/*get count*/
|
||||
Count = cJSON_GetObjectItem(cjson, "count");
|
||||
if(Count)
|
||||
{
|
||||
count = Count->valueint;
|
||||
log_error_write(srv, __FILE__, __LINE__, "sd", "test", count);
|
||||
}
|
||||
|
||||
/*如果用户IP存在 通过用户IP查询在线用户信息*/
|
||||
if(ip != NULL)
|
||||
{
|
||||
cJSON *data, *res;
|
||||
|
||||
/*点分十进制转化十进制*/
|
||||
inet_pton(AF_INET, ip, &clientip);
|
||||
log_error_write(srv, __FILE__, __LINE__, "sd", "test", clientip);
|
||||
|
||||
/*通过用户IP地址查找用户信息*/
|
||||
user_info = ufind_user_by_ippage(page_num, count, clientip);
|
||||
if(user_info == NULL) /*无符合条件的用户信息*/
|
||||
{
|
||||
/*创建json对象*/
|
||||
res = cJSON_CreateObject();
|
||||
if(!res) return HANDLER_ERROR;
|
||||
|
||||
cJSON_AddNumberToObject(res, "resultcode", 0);
|
||||
cJSON_AddStringToObject(res, "message", "查询成功");
|
||||
cJSON_AddStringToObject(res, "data", "");
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
}
|
||||
else
|
||||
{
|
||||
/*创建json对象*/
|
||||
data = cJSON_CreateObject();
|
||||
if(!data)
|
||||
{
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
memset(str, 0, INET_ADDRSTRLEN);
|
||||
inet_ntop(AF_INET,&user_info->auth_user.user_ip, str, sizeof(str));
|
||||
|
||||
cJSON_AddStringToObject(data, "user_ip", str);
|
||||
cJSON_AddStringToObject(data, "user_name", user_info->auth_user.user_name);
|
||||
cJSON_AddNumberToObject(data, "user_id", user_info->auth_user.user_id);
|
||||
cJSON_AddNumberToObject(data, "group_id", user_info->auth_user.group_id);
|
||||
cJSON_AddNumberToObject(data, "message_num", user_info->auth_user.message_num);
|
||||
cJSON_AddNumberToObject(data, "byte_num", user_info->auth_user.byte_num);
|
||||
cJSON_AddNumberToObject(data, "online_time", user_info->auth_user.online_time);
|
||||
|
||||
/*创建json对象*/
|
||||
res = cJSON_CreateObject();
|
||||
if(!res)
|
||||
{
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
cJSON_AddNumberToObject(res, "resultcode", 0);
|
||||
cJSON_AddStringToObject(res, "message", "查询成功");
|
||||
cJSON_AddItemToObject(res, "data", data);
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
}
|
||||
|
||||
/*json对象转换为json字符串*/
|
||||
result_str = cJSON_Print(res);
|
||||
buffer *result_info = buffer_init();
|
||||
result_info = buffer_init_string(result_str);
|
||||
chunkqueue_append_buffer(con->write_queue, result_info);
|
||||
buffer_free(result_info);
|
||||
con->http_status = 200;
|
||||
con->file_finished = 1;
|
||||
cJSON_Delete(res);
|
||||
|
||||
return HANDLER_FINISHED;
|
||||
}
|
||||
else
|
||||
{
|
||||
cJSON *res;
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss", "test", username->valuestring);
|
||||
ufind_user_by_name(page_num, count, username->valuestring, &pJsonArry);
|
||||
|
||||
/*计算数组长度 如果为0 说明没有在线用户信息*/
|
||||
int iCount = cJSON_GetArraySize(pJsonArry);
|
||||
log_error_write(srv, __FILE__, __LINE__, "sd", "test", iCount);
|
||||
|
||||
if(iCount == 0)
|
||||
{
|
||||
/*创建json对象*/
|
||||
res = cJSON_CreateObject();
|
||||
if(!res) return HANDLER_ERROR;
|
||||
|
||||
cJSON_AddNumberToObject(res, "resultcode", 0);
|
||||
cJSON_AddStringToObject(res, "message", "查询成功");
|
||||
cJSON_AddStringToObject(res, "data", "");
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
}
|
||||
else
|
||||
{
|
||||
/*创建json对象*/
|
||||
res = cJSON_CreateObject();
|
||||
if(!res)
|
||||
{
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
cJSON_AddNumberToObject(res, "resultcode", 0);
|
||||
cJSON_AddStringToObject(res, "message", "查询成功");
|
||||
cJSON_AddItemToObject(res, "data", pJsonArry);
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
}
|
||||
|
||||
/*json对象转换为json字符串*/
|
||||
result_str = cJSON_Print(res);
|
||||
buffer *result_info = buffer_init();
|
||||
result_info = buffer_init_string(result_str);
|
||||
chunkqueue_append_buffer(con->write_queue, result_info);
|
||||
buffer_free(result_info);
|
||||
con->http_status = 200;
|
||||
con->file_finished = 1;
|
||||
cJSON_Delete(res);
|
||||
}
|
||||
|
||||
return HANDLER_FINISHED;
|
||||
}
|
||||
|
||||
|
||||
/*在线用户(单个、批量)下线*/
|
||||
/*iuput格式:
|
||||
{
|
||||
"data": [
|
||||
{"user_ip":"192.168.1.1", "user_port": 1010},
|
||||
{"user_ip":"192.168.1.2", "user_port": 1010},
|
||||
{"user_ip":"192.168.1.3", "user_port": 1010}
|
||||
]
|
||||
}
|
||||
*/
|
||||
/*删除所有在线用户*/
|
||||
/*iuput格式:
|
||||
{
|
||||
"data":"all",
|
||||
}
|
||||
*/
|
||||
static handler_t user_offline(server *srv, connection *con, void* p_d)
|
||||
{
|
||||
p_d = p_d;
|
||||
cJSON *cjson, *useripArry, *userip,*res;
|
||||
cJSON *DelArry =NULL;
|
||||
cJSON *Delsub;
|
||||
uint32_t clientip;
|
||||
int iCount;
|
||||
char *result_str = NULL;
|
||||
USER_INFO *user_info;
|
||||
int del_num = 0;
|
||||
char str[INET_ADDRSTRLEN];
|
||||
char del[DEL_MAX_NUM][DEL_MAX_SIZE] = {0};
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
|
||||
/*get payload*/
|
||||
handler_t result = connection_handle_read_post_state(srv, con);
|
||||
log_error_write(srv, __FILE__, __LINE__, "sd","test", result);
|
||||
|
||||
if (result != HANDLER_GO_ON)
|
||||
{
|
||||
return result ;
|
||||
}
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
|
||||
buffer *b = buffer_init();
|
||||
chunkqueue *dst_cq = con->request_content_queue;
|
||||
chunk *c = dst_cq->first;
|
||||
if (NULL == c)
|
||||
{
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
while(c != NULL)
|
||||
{
|
||||
buffer_append_string(b, c->mem->ptr + c->offset);
|
||||
c = c->next;
|
||||
}
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "sb","test",b);
|
||||
|
||||
/*JSON字符串到JSON格式 */
|
||||
cjson = cJSON_Parse(b->ptr);
|
||||
if(!cjson)
|
||||
{
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
/*get data解析数组 */
|
||||
useripArry = cJSON_GetObjectItem(cjson , "data");
|
||||
if(!useripArry)
|
||||
{
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
/*获取数组长度*/
|
||||
iCount = cJSON_GetArraySize(useripArry);
|
||||
log_error_write(srv, __FILE__, __LINE__, "sd","test", iCount);
|
||||
|
||||
|
||||
for(int i = 0; i < iCount; i++)
|
||||
{
|
||||
cJSON *pArrayItem = cJSON_GetArrayItem(useripArry, i);
|
||||
if(pArrayItem)
|
||||
{
|
||||
/*用户IP地址*/
|
||||
userip = cJSON_GetObjectItem(pArrayItem, "user_ip");
|
||||
log_error_write(srv, __FILE__, __LINE__, "sd","test", i);
|
||||
if(userip)
|
||||
{
|
||||
/*点分十进制转为十进制*/
|
||||
inet_pton(AF_INET, userip->valuestring, &clientip);
|
||||
log_error_write(srv, __FILE__, __LINE__, "sds","test", clientip, userip->valuestring);
|
||||
|
||||
user_info = ufind_user(clientip);
|
||||
|
||||
if(NULL != user_info)
|
||||
{
|
||||
/*根据用户IP删除用户信息*/
|
||||
udelete_user(clientip);
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
|
||||
memset(str, 0, INET_ADDRSTRLEN);
|
||||
inet_ntop(AF_INET, &clientip, str, sizeof(str));
|
||||
log_error_write(srv, __FILE__, __LINE__, "ssd","test" , str, del_num);
|
||||
strncpy(del[del_num], str, 24);
|
||||
log_error_write(srv, __FILE__, __LINE__, "ssd","test" , del[del_num], del_num);
|
||||
del_num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DelArry = cJSON_CreateArray(); /*创建数组*/
|
||||
|
||||
if(del_num == 0)
|
||||
{
|
||||
/*创建json对象*/
|
||||
res = cJSON_CreateObject();
|
||||
if(!res)
|
||||
{
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
cJSON_AddNumberToObject(res, "resultcode", 0);
|
||||
cJSON_AddStringToObject(res, "message", "删除成功");
|
||||
cJSON_AddStringToObject(res, "data", "");
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < del_num; i++)
|
||||
{
|
||||
char ipAddr[INET_ADDRSTRLEN];
|
||||
memset(ipAddr, 0, INET_ADDRSTRLEN);
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "sd","test", i);
|
||||
|
||||
cJSON_AddItemToArray(DelArry, Delsub = cJSON_CreateObject()); /* 给创建的数组增加对象*/
|
||||
|
||||
strncpy(ipAddr, del[i], INET_ADDRSTRLEN);
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss","test", ipAddr);
|
||||
cJSON_AddStringToObject(Delsub, "user_ip", ipAddr);
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
}
|
||||
|
||||
/*创建json对象*/
|
||||
res = cJSON_CreateObject();
|
||||
if(!res)
|
||||
{
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
cJSON_AddNumberToObject(res, "resultcode", 0);
|
||||
cJSON_AddStringToObject(res, "message", "删除成功");
|
||||
cJSON_AddItemToObject(res, "data", DelArry);
|
||||
}
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
|
||||
/*json对象转换为json字符串*/
|
||||
result_str = cJSON_Print(res);
|
||||
buffer *result_info = buffer_init();
|
||||
result_info = buffer_init_string(result_str);
|
||||
chunkqueue_append_buffer(con->write_queue, result_info);
|
||||
buffer_free(result_info);
|
||||
con->http_status = 200;
|
||||
con->file_finished = 1;
|
||||
cJSON_Delete(res);
|
||||
|
||||
return HANDLER_FINISHED;
|
||||
}
|
||||
|
||||
|
||||
/*根据传输过来的url分情况执行*/
|
||||
static handler_t mod_usermagnet_uri_handler(server *srv, connection *con, void* p_d)
|
||||
{
|
||||
/*case 1 根据不同条件查询用户信息
|
||||
case 2 -选择用户下线*/
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","mod_usermagnet_uri_handler");
|
||||
|
||||
handler_t t = HANDLER_GO_ON;
|
||||
p_d = p_d;
|
||||
if (con->request.http_method == HTTP_METHOD_GET)
|
||||
{
|
||||
return HANDLER_GO_ON;
|
||||
}
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
|
||||
if (con->state == CON_STATE_READ_POST) {
|
||||
chunkqueue *cq = con->request_content_queue;
|
||||
if (cq->bytes_in != (off_t)con->request.content_length) {
|
||||
handler_t r = connection_handle_read_post_state(srv, con);
|
||||
if (r != HANDLER_GO_ON) return r;
|
||||
}
|
||||
}
|
||||
else if (0 == con->request.content_length)
|
||||
{
|
||||
return HANDLER_GO_ON;
|
||||
}
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
|
||||
/*url 与"/user-get"匹配,根据条件查询用户信息*/
|
||||
if (0 == strcmp(con->uri.path->ptr, "/user-get"))
|
||||
{
|
||||
t = get_onlineuser_info(srv, con, p_d);
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
}
|
||||
else if (0 == strcmp(con->uri.path->ptr, "/user-offline"))
|
||||
{
|
||||
t = user_offline(srv, con, p_d);
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
|
||||
}
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s","test");
|
||||
con->http_status = 200;
|
||||
con->file_finished = 1;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
SETDEFAULTS_FUNC(mod_usermagnet_set_defaults)
|
||||
{
|
||||
mod_usermagnet_plugin_data *p = p_d;
|
||||
p = p;//解决编译告警;
|
||||
//srv = srv;//解决编译告警;
|
||||
|
||||
init_svr_ptr(srv);
|
||||
|
||||
return HANDLER_GO_ON;
|
||||
}
|
||||
|
||||
|
||||
int mod_usermagnet_plugin_init(plugin *p);
|
||||
int mod_usermagnet_plugin_init(plugin *p) {
|
||||
p->version = LIGHTTPD_VERSION_ID;
|
||||
p->name = buffer_init_string("usermagnet");
|
||||
p->init = mod_usermagnet_init;
|
||||
p->set_defaults = mod_usermagnet_set_defaults;
|
||||
p->handle_uri_clean = mod_usermagnet_uri_handler;
|
||||
p->cleanup = mod_usermagnet_free;
|
||||
p->data = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
#define UDESIZE (63)
|
||||
#define UPWDSIZE (63)
|
||||
|
||||
static server* b_svr = NULL;
|
||||
void * g_auth_hdbc = NULL; //用户认证连接句柄
|
||||
|
||||
typedef struct user_auth
|
||||
|
@ -487,6 +488,7 @@ void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
|||
/* 连接数据库 */
|
||||
if(NULL == g_auth_hdbc)
|
||||
{
|
||||
//log_error_write(b_svr, __FILE__, __LINE__, "s","test");
|
||||
g_auth_hdbc = connect_database(20);
|
||||
}
|
||||
|
||||
|
@ -496,6 +498,7 @@ void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
|||
bool ret_getconfig = get_config_data(g_auth_hdbc, config_data);
|
||||
if (!ret_getconfig)
|
||||
{
|
||||
//log_error_write(b_svr, __FILE__, __LINE__, "s","test");
|
||||
auth_result->ret = AUTH_FAIL_LACKINFO;
|
||||
return;
|
||||
}
|
||||
|
@ -689,4 +692,11 @@ void reset_online_by_groupid(int *group_ids)
|
|||
g_user_auth_ret_table[i].online_num = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void binit_svr_ptr(void *srv)
|
||||
{
|
||||
if(srv) {
|
||||
b_svr = (server*)srv;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
#include <time.h>
|
||||
|
||||
struct server;
|
||||
typedef struct server server;
|
||||
|
||||
typedef enum {
|
||||
AUTH_SUCCESS = 0,
|
||||
AUTH_FAIL_PASSWD = 1,
|
||||
|
@ -64,4 +67,6 @@ void reset_online_by_userid(int *user_ids, int num);
|
|||
/* 用户在线节点重置-按用户组id */
|
||||
void reset_online_by_groupid(int *group_ids);
|
||||
|
||||
void binit_svr_ptr(void *srv);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue