|
|
@@ -22,6 +22,7 @@
|
|
|
#include "led.h"
|
|
|
#include "broadcast.h"
|
|
|
#include "radius.h"
|
|
|
+#include "elog.h"
|
|
|
|
|
|
#define TOTAL_COUNT 60
|
|
|
#define FN_MAX 30
|
|
|
@@ -55,6 +56,16 @@ enum {
|
|
|
FILE_SENSOR_INFO,
|
|
|
};
|
|
|
|
|
|
+#if 1
|
|
|
+ #define LOGE log_e
|
|
|
+ #define LOGW log_w
|
|
|
+ #define LOGD log_d
|
|
|
+#else
|
|
|
+ #define LOGD printf
|
|
|
+ #define LOGW printf
|
|
|
+ #define LOGE printf
|
|
|
+#endif
|
|
|
+
|
|
|
|
|
|
typedef void (*http_fn_t)(void *arg);
|
|
|
typedef struct mg_tls_opts mg_tls_t;
|
|
|
@@ -569,7 +580,7 @@ static void *web_thread(void *arg)
|
|
|
return NULL;
|
|
|
}
|
|
|
//get user info message
|
|
|
-#if 0
|
|
|
+#if 1
|
|
|
INIT_LIST_HEAD(&_g_User_list.list);
|
|
|
|
|
|
//get current db user infoinfomation
|
|
|
@@ -668,8 +679,219 @@ static void loginFunc(void* conn)
|
|
|
bool LoginFlag = false;
|
|
|
|
|
|
// 查询用户信息
|
|
|
- UserInfo User_list;
|
|
|
- INIT_LIST_HEAD(&User_list.list);
|
|
|
+ UserInfo User_list;
|
|
|
+ INIT_LIST_HEAD(&User_list.list);
|
|
|
+ //UserInfo *_UserInfoTemp;
|
|
|
+ //uint8_t db_mememer_flag = 0;
|
|
|
+ // list_for_each_entry(_UserInfoTemp, &_g_User_list.list, list)
|
|
|
+ // {
|
|
|
+ // if (strcmp(_UserInfoTemp->userName,_newUserLogin->user_name)==0 && strcmp(_UserInfoTemp->userPW,_newUserLogin->user_password)==0)
|
|
|
+ // {
|
|
|
+ // LoginFlag=true;
|
|
|
+ // //_GlobalUserInfoNew = *_UserInfoTemp;
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //check is or not database member
|
|
|
+ UserInfo user={0};
|
|
|
+ int ret = dev_get_sigle_user_info(__globalDeviceManage.db,&user,_newUserLogin->user_name,_newUserLogin->user_password);
|
|
|
+ if(ret)
|
|
|
+ {
|
|
|
+ //database is not menber you need auth
|
|
|
+ if(__globalDeviceManage._globalDevInfo.misc.radius)
|
|
|
+ {
|
|
|
+ char temp[256] = {0};
|
|
|
+ sprintf(temp,"radlogin -f /etc/radiusclient/radiusclient.conf -u %s -p %s",_newUserLogin->user_name,_newUserLogin->user_password);
|
|
|
+ ret = system(temp);
|
|
|
+ if(ret)
|
|
|
+ {
|
|
|
+ if(__globalDeviceManage._globalDevInfo.ldap.ldap)
|
|
|
+ {
|
|
|
+ memset(temp,0,sizeof(temp));
|
|
|
+ sprintf(temp,"ldapwhoami -x -D \"%s\" -H ldap://%s -w %s",_newUserLogin->user_name,__globalDeviceManage._globalDevInfo.ldap.ldip_server,_newUserLogin->user_password);
|
|
|
+ ret = system(temp);
|
|
|
+ if(ret)
|
|
|
+ {
|
|
|
+ //delete
|
|
|
+ UserInfo *node;
|
|
|
+ UserInfo *next;
|
|
|
+ printf("delate a user!!!\n");
|
|
|
+
|
|
|
+ list_for_each_entry_safe(node, next, &_g_User_list.list, list)
|
|
|
+ {
|
|
|
+ if(strcmp(node->userName,_newUserLogin->user_name) == 0 && strcmp(node->userPW,_newUserLogin->user_password) == 0)
|
|
|
+ {
|
|
|
+ list_del(&node->list);
|
|
|
+ free(node);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LoginFlag = false;
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ UserInfo *_UserInfoTemp = NULL;
|
|
|
+ uint8_t ldap_find_flag = 0;
|
|
|
+ list_for_each_entry(_UserInfoTemp, &_g_User_list.list, list)
|
|
|
+ {
|
|
|
+ if (strcmp(_UserInfoTemp->userName,_newUserLogin->user_name)==0 && strcmp(_UserInfoTemp->userPW,_newUserLogin->user_password)==0)
|
|
|
+ {
|
|
|
+ ldap_find_flag = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(ldap_find_flag != 1)
|
|
|
+ {
|
|
|
+ //create a user;
|
|
|
+ _UserInfoTemp = (UserInfo *)malloc(sizeof(UserInfo));
|
|
|
+ memset(_UserInfoTemp,0,sizeof(UserInfo));
|
|
|
+ _UserInfoTemp->product_id = __globalDeviceManage._globalDevInfo.product.id;
|
|
|
+ _UserInfoTemp->roleID = 1;
|
|
|
+ memcpy(_UserInfoTemp->nickName,"ldap auth",strlen("ldap auth"));
|
|
|
+ memcpy(_UserInfoTemp->userName,_newUserLogin->user_name,strlen(_newUserLogin->user_name));
|
|
|
+ memcpy(_UserInfoTemp->userPW,_newUserLogin->user_password,strlen(_newUserLogin->user_password));
|
|
|
+ list_add_tail(&_UserInfoTemp->list, &_g_User_list.list);
|
|
|
+ }
|
|
|
+ LoginFlag = true;
|
|
|
+ _GlobalUserInfoNew = *_UserInfoTemp;
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ UserInfo *node;
|
|
|
+ UserInfo *next;
|
|
|
+ printf("delate a user!!!\n");
|
|
|
+
|
|
|
+ list_for_each_entry_safe(node, next, &_g_User_list.list, list)
|
|
|
+ {
|
|
|
+ if(strcmp(node->userName,_newUserLogin->user_name) == 0 && strcmp(node->userPW,_newUserLogin->user_password) == 0)
|
|
|
+ {
|
|
|
+ list_del(&node->list);
|
|
|
+ free(node);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LoginFlag = false;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ UserInfo *_UserInfoTemp = NULL;
|
|
|
+ uint8_t radius_find_flag = 0;
|
|
|
+ list_for_each_entry(_UserInfoTemp, &_g_User_list.list, list)
|
|
|
+ {
|
|
|
+ if (strcmp(_UserInfoTemp->userName,_newUserLogin->user_name)==0 && strcmp(_UserInfoTemp->userPW,_newUserLogin->user_password)==0)
|
|
|
+ {
|
|
|
+ radius_find_flag = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(radius_find_flag != 1)
|
|
|
+ {
|
|
|
+ //create a user;
|
|
|
+ _UserInfoTemp = (UserInfo *)malloc(sizeof(UserInfo));
|
|
|
+ memset(_UserInfoTemp,0,sizeof(UserInfo));
|
|
|
+ _UserInfoTemp->product_id = __globalDeviceManage._globalDevInfo.product.id;
|
|
|
+ _UserInfoTemp->roleID = 1;
|
|
|
+ memcpy(_UserInfoTemp->nickName,"radius auth",strlen("radius auth"));
|
|
|
+ memcpy(_UserInfoTemp->userName,_newUserLogin->user_name,strlen(_newUserLogin->user_name));
|
|
|
+ memcpy(_UserInfoTemp->userPW,_newUserLogin->user_password,strlen(_newUserLogin->user_password));
|
|
|
+ list_add_tail(&_UserInfoTemp->list, &_g_User_list.list);
|
|
|
+ }
|
|
|
+ LoginFlag = true;
|
|
|
+ _GlobalUserInfoNew = *_UserInfoTemp;
|
|
|
+ }
|
|
|
+ }else if(__globalDeviceManage._globalDevInfo.ldap.ldap)
|
|
|
+ {
|
|
|
+ char temp[256] = {0};
|
|
|
+ memset(temp,0,sizeof(temp));
|
|
|
+ sprintf(temp,"ldapwhoami -x -D \"%s\" -H ldap://%s -w %s",_newUserLogin->user_name,__globalDeviceManage._globalDevInfo.ldap.ldip_server,_newUserLogin->user_password);
|
|
|
+ ret = system(temp);
|
|
|
+ if(ret)
|
|
|
+ {
|
|
|
+ //delete
|
|
|
+ UserInfo *node;
|
|
|
+ UserInfo *next;
|
|
|
+ printf("delete a user!!!\n");
|
|
|
+ list_for_each_entry_safe(node, next, &_g_User_list.list, list)
|
|
|
+ {
|
|
|
+ if(strcmp(node->userName,_newUserLogin->user_name) == 0 && strcmp(node->userPW,_newUserLogin->user_password) == 0)
|
|
|
+ {
|
|
|
+ list_del(&node->list);
|
|
|
+ free(node);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LoginFlag = false;
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ UserInfo *_UserInfoTemp = NULL;
|
|
|
+ uint8_t ldap_find_flag = 0;
|
|
|
+ list_for_each_entry(_UserInfoTemp, &_g_User_list.list, list)
|
|
|
+ {
|
|
|
+ if (strcmp(_UserInfoTemp->userName,_newUserLogin->user_name)==0 && strcmp(_UserInfoTemp->userPW,_newUserLogin->user_password)==0)
|
|
|
+ {
|
|
|
+ ldap_find_flag = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(ldap_find_flag != 1)
|
|
|
+ {
|
|
|
+ //create a user;
|
|
|
+ _UserInfoTemp = (UserInfo *)malloc(sizeof(UserInfo));
|
|
|
+ memset(_UserInfoTemp,0,sizeof(UserInfo));
|
|
|
+ _UserInfoTemp->product_id = __globalDeviceManage._globalDevInfo.product.id;
|
|
|
+ _UserInfoTemp->roleID = 1;
|
|
|
+ memcpy(_UserInfoTemp->nickName,"ldap auth",strlen("ldap auth"));
|
|
|
+ memcpy(_UserInfoTemp->userName,_newUserLogin->user_name,strlen(_newUserLogin->user_name));
|
|
|
+ memcpy(_UserInfoTemp->userPW,_newUserLogin->user_password,strlen(_newUserLogin->user_password));
|
|
|
+ list_add_tail(&_UserInfoTemp->list, &_g_User_list.list);
|
|
|
+ }
|
|
|
+ LoginFlag = true;
|
|
|
+ _GlobalUserInfoNew = *_UserInfoTemp;
|
|
|
+ }
|
|
|
+
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ UserInfo *node;
|
|
|
+ UserInfo *next;
|
|
|
+ printf("delete a user!!!\n");
|
|
|
+ list_for_each_entry_safe(node, next, &_g_User_list.list, list)
|
|
|
+ {
|
|
|
+ if(strcmp(node->userName,_newUserLogin->user_name) == 0 && strcmp(node->userPW,_newUserLogin->user_password) == 0)
|
|
|
+ {
|
|
|
+ list_del(&node->list);
|
|
|
+ free(node);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LoginFlag = false;
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ //database user
|
|
|
+ UserInfo *_UserInfoTemp;
|
|
|
+ uint8_t db_find_flag = 0;
|
|
|
+ list_for_each_entry(_UserInfoTemp, &_g_User_list.list, list)
|
|
|
+ {
|
|
|
+ if (strcmp(_UserInfoTemp->userName,_newUserLogin->user_name)==0 && strcmp(_UserInfoTemp->userPW,_newUserLogin->user_password)==0)
|
|
|
+ {
|
|
|
+ db_find_flag = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(db_find_flag != 1)
|
|
|
+ {
|
|
|
+ //create a user;
|
|
|
+ _UserInfoTemp = (UserInfo *)malloc(sizeof(UserInfo));
|
|
|
+ memcpy(_UserInfoTemp,&user,sizeof(UserInfo));
|
|
|
+ list_add_tail(&_UserInfoTemp->list, &_g_User_list.list);
|
|
|
+ }
|
|
|
+ LoginFlag = true;
|
|
|
+ _GlobalUserInfoNew = *_UserInfoTemp;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
#if 0
|
|
|
UserInfo *_UserInfoTemp;
|
|
|
list_for_each_entry(_UserInfoTemp, &_g_User_list.list, list)
|
|
|
@@ -700,28 +922,64 @@ static void loginFunc(void* conn)
|
|
|
ret = system(temp);
|
|
|
if(ret)
|
|
|
{
|
|
|
- memset(temp,0,sizeof(temp));
|
|
|
- sprintf(temp,"ldapwhoami -x -D \"%s\" -H ldap://%s -w %s",_newUserLogin->user_name,__globalDeviceManage._globalDevInfo.ldap.ldip_server,_newUserLogin->user_password);
|
|
|
- ret = system(temp);
|
|
|
- if(ret)
|
|
|
+ printf("ldap = %d \n",__globalDeviceManage._globalDevInfo.ldap.ldap);
|
|
|
+ if( __globalDeviceManage._globalDevInfo.ldap.ldap)
|
|
|
{
|
|
|
- // delete current
|
|
|
- UserInfo * temp;
|
|
|
- list_for_each_entry(temp, &_g_User_list.list, list)
|
|
|
+ memset(temp,0,sizeof(temp));
|
|
|
+ sprintf(temp,"ldapwhoami -x -D \"%s\" -H ldap://%s -w %s",_newUserLogin->user_name,__globalDeviceManage._globalDevInfo.ldap.ldip_server,_newUserLogin->user_password);
|
|
|
+ ret = system(temp);
|
|
|
+ if(ret)
|
|
|
{
|
|
|
- if(temp == _UserInfoTemp)
|
|
|
+ // delete current
|
|
|
+ UserInfo * temp;
|
|
|
+ printf("delate a user!!!\n");
|
|
|
+ list_for_each_entry(temp, &_g_User_list.list, list)
|
|
|
{
|
|
|
- list_del(&temp->list);
|
|
|
- free(temp);
|
|
|
- _UserInfoTemp = NULL;
|
|
|
- LoginFlag = false;
|
|
|
+ if(temp == NULL)
|
|
|
+ {
|
|
|
+ LoginFlag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(temp == _UserInfoTemp)
|
|
|
+ {
|
|
|
+ list_del(&temp->list);
|
|
|
+ free(temp);
|
|
|
+ _UserInfoTemp = NULL;
|
|
|
+ LoginFlag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- }else
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ _GlobalUserInfoNew = *_UserInfoTemp;
|
|
|
+ }
|
|
|
+ } else
|
|
|
{
|
|
|
- _GlobalUserInfoNew = *_UserInfoTemp;
|
|
|
- }
|
|
|
+ LOGW("delete walllll\n");
|
|
|
+ UserInfo * temp;
|
|
|
+ list_for_each_entry(temp, &_g_User_list.list, list)
|
|
|
+ {
|
|
|
+
|
|
|
+ if(temp == NULL)
|
|
|
+ {
|
|
|
+ LoginFlag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(temp == _UserInfoTemp)
|
|
|
+ {
|
|
|
+
|
|
|
+ list_del(&temp->list);
|
|
|
+ free(temp);
|
|
|
+
|
|
|
+ _UserInfoTemp = NULL;
|
|
|
+ LoginFlag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}else
|
|
|
{
|
|
|
_GlobalUserInfoNew = *_UserInfoTemp;
|
|
|
@@ -800,12 +1058,19 @@ static void loginFunc(void* conn)
|
|
|
UserInfo * temp;
|
|
|
list_for_each_entry(temp, &_g_User_list.list, list)
|
|
|
{
|
|
|
+ if(temp == NULL)
|
|
|
+ {
|
|
|
+ LoginFlag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
if(temp == _UserInfoTemp)
|
|
|
{
|
|
|
list_del(&temp->list);
|
|
|
free(temp);
|
|
|
_UserInfoTemp = NULL;
|
|
|
LoginFlag = false;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
}else
|
|
|
@@ -893,6 +1158,7 @@ static void loginFunc(void* conn)
|
|
|
|
|
|
// }else
|
|
|
// {
|
|
|
+#if 0
|
|
|
if (0 == dev_get_user_info(__globalDeviceManage.db, &User_list))
|
|
|
{
|
|
|
UserInfo *_UserInfoTemp = NULL;
|
|
|
@@ -909,7 +1175,7 @@ static void loginFunc(void* conn)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+#endif
|
|
|
// }
|
|
|
// UserInfo *_UserInfoTemp = NULL;
|
|
|
// list_for_each_entry(_UserInfoTemp, &User_list.list, list)
|
|
|
@@ -1027,10 +1293,12 @@ static void getUserRouters(void* conn)
|
|
|
|
|
|
// 根据token获取用户及用户权限
|
|
|
int nRoleID=3;
|
|
|
-#if 0
|
|
|
+#if 1
|
|
|
UserInfo *_UserInfoTemp= NULL;
|
|
|
list_for_each_entry(_UserInfoTemp, &_g_User_list.list, list)
|
|
|
{
|
|
|
+ if(_UserInfoTemp == NULL)
|
|
|
+ break;
|
|
|
char *nName = getUserNamebyToken(g_token);
|
|
|
if (_UserInfoTemp && nName && strcmp(nName,_UserInfoTemp->userName)==0)
|
|
|
{
|
|
|
@@ -1038,7 +1306,7 @@ static void getUserRouters(void* conn)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-#endif
|
|
|
+#else
|
|
|
|
|
|
if (0 == dev_get_user_info(__globalDeviceManage.db, &User_list) )
|
|
|
{
|
|
|
@@ -1048,6 +1316,7 @@ static void getUserRouters(void* conn)
|
|
|
nRoleID = GetRoleIDByUserName(nName,&User_list);
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
SetMenuAuthority(nRoleID);
|
|
|
|