|
|
@@ -21,6 +21,7 @@
|
|
|
#include "time.h"
|
|
|
#include "cJSON.h"
|
|
|
#include "json_handle.h"
|
|
|
+#include "mbedtls/md5.h"
|
|
|
|
|
|
static char* g_product_t_ac_type_str[3] = {
|
|
|
"L1",
|
|
|
@@ -156,6 +157,260 @@ static int ws_send(mg_conn_t *c, void *data, int len, int isbin)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+static void send_user_info(web_handle_t *h, mg_conn_t *c)
|
|
|
+{
|
|
|
+ pkt_hdr_t *hdr=NULL;
|
|
|
+ hdr = (pkt_hdr_t*)h->buf;
|
|
|
+ wb_send_user_t *data1 = (wb_send_user_t *)(&hdr->data);
|
|
|
+ memset(data1,0,sizeof(wb_send_user_t));
|
|
|
+ paras_data_t* para=paras_get();
|
|
|
+
|
|
|
+
|
|
|
+ user_data_t *data = ¶->user;
|
|
|
+
|
|
|
+ data1->count = data->user_count;
|
|
|
+
|
|
|
+
|
|
|
+ for(int i = 0; i < data->user_count;i++)
|
|
|
+ {
|
|
|
+ data1->users[i].roul_id = data->config[i].role_id;
|
|
|
+ strcpy(data1->users[i].user,data->config[i].user_name);
|
|
|
+ strcpy(data1->users[i].date,data->config[i].date);
|
|
|
+ strcpy(data1->users[i].time,data->config[i].time);
|
|
|
+ }
|
|
|
+
|
|
|
+ hdr->magic = PKT_MAGIC;
|
|
|
+ hdr->addr = 0;
|
|
|
+ hdr->type = NEW_PKT_TYPE_USER;
|
|
|
+ hdr->nack = 0;
|
|
|
+ hdr->subtype = 0;
|
|
|
+ hdr->dlen = data1->count * sizeof(user_t) + sizeof(data1->count);
|
|
|
+
|
|
|
+ uint32_t xlen = hdr->dlen + sizeof(pkt_hdr_t);
|
|
|
+ ws_send(c, h->buf, xlen, 1);
|
|
|
+}
|
|
|
+
|
|
|
+static void send_add_user_func(web_handle_t *h, mg_conn_t *c,wed_set_t *ctrl)
|
|
|
+{
|
|
|
+ char date[32]={0};
|
|
|
+ char time_s[32] = {0};
|
|
|
+ unsigned char digest[16]={0};
|
|
|
+ char output[33] = {0};
|
|
|
+ mbedtls_md5_context ctx={0};
|
|
|
+ uint8_t flag = USER_SUCCESS;
|
|
|
+
|
|
|
+ web_user_add_t * user_add = (web_user_add_t *)&(ctrl->user_add);
|
|
|
+ pkt_hdr_t *hdr=(pkt_hdr_t*)(h->buf);
|
|
|
+
|
|
|
+ paras_data_t* para=paras_get();
|
|
|
+
|
|
|
+ printf("hdr = %x\n",(uint32_t)hdr);
|
|
|
+ time_t t=time(NULL);
|
|
|
+ struct tm *tm=localtime(&t);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ hdr->magic = PKT_MAGIC;
|
|
|
+ hdr->addr = 0;
|
|
|
+ hdr->type = NEW_PKT_TYPE_USER;
|
|
|
+ hdr->nack = 0;
|
|
|
+ hdr->subtype = NEW_SUB_PKT_TYPE_USER_ADD;
|
|
|
+ hdr->dlen = 1;
|
|
|
+
|
|
|
+ sprintf(date,"%04d%/%02d/%02d",(tm->tm_year+1900), tm->tm_mon+1, tm->tm_mday);
|
|
|
+ sprintf(time_s,"%02d%:%02d:%02d",tm->tm_hour, tm->tm_min, tm->tm_sec);
|
|
|
+
|
|
|
+ for(int i = 0; i < para->user.user_count;i++)
|
|
|
+ {
|
|
|
+ if(strcmp(user_add->user,para->user.config[i].user_name) == 0)
|
|
|
+ {
|
|
|
+ flag = USER_EXIST; //user_add exist
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(flag == 0)
|
|
|
+ {
|
|
|
+ if(para->user.user_count >= 10)
|
|
|
+ {
|
|
|
+ flag = USER_OVER_TEN;
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ para->user.user_count++;
|
|
|
+ strcpy(para->user.config[para->user.user_count-1].user_name,user_add->user);
|
|
|
+ para->user.config[para->user.user_count-1].role_id = user_add->permition;
|
|
|
+ strcpy(para->user.config[para->user.user_count-1].date,date);
|
|
|
+ strcpy(para->user.config[para->user.user_count-1].time,time_s);
|
|
|
+ mbedtls_md5_init(&ctx);
|
|
|
+ mbedtls_md5_starts(&ctx);
|
|
|
+ mbedtls_md5_update(&ctx, user_add->password, strlen(user_add->password));
|
|
|
+ mbedtls_md5_finish(&ctx, digest);
|
|
|
+ mbedtls_md5_free(&ctx);
|
|
|
+ for (int k = 0; k < 16; k++) {
|
|
|
+ sprintf(&output[k * 2], "%02x", digest[k]);
|
|
|
+ }
|
|
|
+ output[33] = '\0';
|
|
|
+ strcpy(para->user.config[para->user.user_count-1].password_md5,output);
|
|
|
+ paras_user_save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ uint8_t *data = (uint8_t *)(&hdr->data);
|
|
|
+
|
|
|
+ *data = flag;
|
|
|
+ uint32_t xlen = sizeof(uint8_t) + sizeof(pkt_hdr_t);
|
|
|
+ ws_send(c, h->buf, xlen, 1);
|
|
|
+
|
|
|
+ //printf("send len = %d\n",xlen);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+static void send_user_delete_func(web_handle_t *h, mg_conn_t *c,wed_set_t *ctrl)
|
|
|
+{
|
|
|
+ web_user_delete_t * user_delete = &ctrl->user_delete;
|
|
|
+ pkt_hdr_t *hdr=NULL;
|
|
|
+ hdr = (pkt_hdr_t*)h->buf;
|
|
|
+ uint8_t flag = USER_DELETE_SUCCESS;
|
|
|
+
|
|
|
+ paras_data_t* para=paras_get();
|
|
|
+ user_data_t back_user = {0};
|
|
|
+ int j = 0;
|
|
|
+
|
|
|
+ for(int i = 0;i < para->user.user_count;i++)
|
|
|
+ {
|
|
|
+ if(strcmp(para->user.config[i].user_name,user_delete->user) == 0)
|
|
|
+ {
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ back_user.config[j++] = para->user.config[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ back_user.user_count = j;
|
|
|
+ //memset(¶->user,0,sizeof(para->user));
|
|
|
+ para->user = back_user;
|
|
|
+ paras_user_save();
|
|
|
+
|
|
|
+ uint8_t *data = (uint8_t *)(&hdr->data);
|
|
|
+ hdr->magic = PKT_MAGIC;
|
|
|
+ hdr->addr = 0;
|
|
|
+ hdr->type = NEW_PKT_TYPE_USER;
|
|
|
+ hdr->nack = 0;
|
|
|
+ hdr->subtype = NEW_SUB_PKT_TYPE_USER_DELETE;
|
|
|
+ hdr->dlen = 1;
|
|
|
+ *data = flag;
|
|
|
+ uint32_t xlen = sizeof(uint8_t) + sizeof(pkt_hdr_t);
|
|
|
+ ws_send(c, h->buf, xlen, 1);
|
|
|
+}
|
|
|
+
|
|
|
+static void send_user_update_func(web_handle_t *h, mg_conn_t *c,wed_set_t *ctrl)
|
|
|
+{
|
|
|
+ web_user_update_t *user_update = &ctrl->user_update;
|
|
|
+ pkt_hdr_t *hdr=NULL;
|
|
|
+ hdr = (pkt_hdr_t*)h->buf;
|
|
|
+ uint8_t flag = USER_DELETE_SUCCESS;
|
|
|
+ paras_data_t* para=paras_get();
|
|
|
+
|
|
|
+ unsigned char digest[16]={0};
|
|
|
+ char output[33] = {0};
|
|
|
+ mbedtls_md5_context ctx={0};
|
|
|
+ for(int i = 0; i < para->user.user_count;i++)
|
|
|
+ {
|
|
|
+ if(strcmp(user_update->user,para->user.config[i].user_name) == 0)
|
|
|
+ {
|
|
|
+ mbedtls_md5_init(&ctx);
|
|
|
+ mbedtls_md5_starts(&ctx);
|
|
|
+ mbedtls_md5_update(&ctx, user_update->old_password, strlen(user_update->old_password));
|
|
|
+ mbedtls_md5_finish(&ctx, digest);
|
|
|
+ mbedtls_md5_free(&ctx);
|
|
|
+ for (int k = 0; k < 16; k++) {
|
|
|
+ sprintf(&output[k * 2], "%02x", digest[k]);
|
|
|
+ }
|
|
|
+ output[33] = '\0';
|
|
|
+ if(strcmp(output,para->user.config[i].password_md5) == 0)
|
|
|
+ {
|
|
|
+ mbedtls_md5_init(&ctx);
|
|
|
+ mbedtls_md5_starts(&ctx);
|
|
|
+ mbedtls_md5_update(&ctx, user_update->new_password, strlen(user_update->new_password));
|
|
|
+ mbedtls_md5_finish(&ctx, digest);
|
|
|
+ mbedtls_md5_free(&ctx);
|
|
|
+ for (int k = 0; k < 16; k++) {
|
|
|
+ sprintf(&output[k * 2], "%02x", digest[k]);
|
|
|
+ }
|
|
|
+ output[33] = '\0';
|
|
|
+ strcpy(para->user.config[i].password_md5,output);
|
|
|
+ paras_user_save();
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ flag = USER_UPDATE_PASSERR;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ uint8_t *data = (uint8_t *)(&hdr->data);
|
|
|
+ hdr->magic = PKT_MAGIC;
|
|
|
+ hdr->addr = 0;
|
|
|
+ hdr->type = NEW_PKT_TYPE_USER;
|
|
|
+ hdr->nack = 0;
|
|
|
+ hdr->subtype = NEW_SUB_PKT_TYPE_USER_UPDATE;
|
|
|
+ hdr->dlen = 1;
|
|
|
+ *data = flag;
|
|
|
+ uint32_t xlen = sizeof(uint8_t) + sizeof(pkt_hdr_t);
|
|
|
+ ws_send(c, h->buf, xlen, 1);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+static void send_login_func(web_handle_t *h, mg_conn_t *c,wed_set_t *ctrl)
|
|
|
+{
|
|
|
+ pkt_hdr_t *hdr=NULL;
|
|
|
+ hdr = (pkt_hdr_t*)h->buf;
|
|
|
+ uint8_t flag = 0;
|
|
|
+ uint8_t *data = (uint8_t *)(&hdr->data);
|
|
|
+
|
|
|
+ paras_data_t* para=paras_get();
|
|
|
+
|
|
|
+ unsigned char digest[16]={0};
|
|
|
+ char output[33] = {0};
|
|
|
+ mbedtls_md5_context ctx={0};
|
|
|
+
|
|
|
+ for(int i = 0; i < para->user.user_count;i++)
|
|
|
+ {
|
|
|
+ if(strcmp(ctrl->login.user,para->user.config[i].user_name) == 0)
|
|
|
+ {
|
|
|
+ mbedtls_md5_init(&ctx);
|
|
|
+ mbedtls_md5_starts(&ctx);
|
|
|
+ mbedtls_md5_update(&ctx, (const unsigned char *)ctrl->login.password, strlen(ctrl->login.password));
|
|
|
+ mbedtls_md5_finish(&ctx, digest);
|
|
|
+ mbedtls_md5_free(&ctx);
|
|
|
+
|
|
|
+ for (int k = 0; k < 16; k++) {
|
|
|
+ sprintf(&output[k * 2], "%02x", digest[k]);
|
|
|
+ }
|
|
|
+ output[33] = '\0';
|
|
|
+ if(strcmp(output,para->user.config[i].password_md5) == 0)
|
|
|
+ {
|
|
|
+ flag = 1;
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ flag = 2;
|
|
|
+ }
|
|
|
+ //printf("user=%s output: %s\n",ctrl->login.user,output);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ hdr->magic = PKT_MAGIC;
|
|
|
+ hdr->addr = 0;
|
|
|
+ hdr->type = MEW_PKT_TYPE_LOGIN;
|
|
|
+ hdr->nack = 0;
|
|
|
+ hdr->subtype = 0;
|
|
|
+ hdr->dlen = 1;
|
|
|
+
|
|
|
+ *data = flag;
|
|
|
+ uint32_t xlen = sizeof(uint8_t) + sizeof(pkt_hdr_t);
|
|
|
+ ws_send(c, h->buf, xlen, 1);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
static void send_sys(web_handle_t *h, mg_conn_t *c)
|
|
|
{
|
|
|
@@ -838,6 +1093,41 @@ static int ws_handle_new(web_handle_t *h, pkt_hdr_t *hdr, mg_conn_t *c)
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
+ case MEW_PKT_TYPE_LOGIN:
|
|
|
+ {
|
|
|
+ send_login_func(h,c,ctrl);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case NEW_PKT_TYPE_USER:
|
|
|
+ {
|
|
|
+ if(hdr->dlen == 0)
|
|
|
+ {
|
|
|
+ send_user_info(h,c);
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ switch(hdr->subtype)
|
|
|
+ {
|
|
|
+ case NEW_SUB_PKT_TYPE_USER_ADD:
|
|
|
+ {
|
|
|
+ send_add_user_func(h,c,ctrl);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case NEW_SUB_PKT_TYPE_USER_UPDATE:
|
|
|
+ {
|
|
|
+ send_user_update_func(h,c,ctrl);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case NEW_SUB_PKT_TYPE_USER_DELETE:
|
|
|
+ {
|
|
|
+ send_user_delete_func(h,c,ctrl);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -940,6 +1230,10 @@ static void overChannelStatusMonitoring(void* conn)
|
|
|
if(p_handle->product->type == PDU_AC_I3O1_H || p_handle->product->type == PDU_AC_I3O1)
|
|
|
{
|
|
|
ph=pch->info.pse.ph-1;
|
|
|
+ uint8_t wanning = 0;
|
|
|
+ uint32_t ph_all_wanning = *(uint32_t*) (&pch->info.alarm);
|
|
|
+ wanning = (ph_all_wanning >> (ph*8)) & 0XFF; //get phse wanning
|
|
|
+ wanning_type_t wan = *(wanning_type_t *)(&wanning);
|
|
|
sprintf(ack_str,CHANNEL_SINGLE_RES_TYPE,pch->info.name,req.pro_ch_id,pch->power[ph].voltage,
|
|
|
pch->power[ph].current,pch->power[ph].power,
|
|
|
pch->power[ph].app_power,pch->power[ph].freq,
|
|
|
@@ -947,8 +1241,9 @@ static void overChannelStatusMonitoring(void* conn)
|
|
|
pch->thr.v_upper,pch->thr.v_lower,
|
|
|
pch->thr.c_upper,pch->thr.p_upper,
|
|
|
pch->thr.w_upper,
|
|
|
- pch->info.open_delay,pch->info.close_delay,
|
|
|
- pch->info.status,g_product_t_ac_type_str[ph]);
|
|
|
+ pch->info.open_delay,pch->info.close_delay,pch->info.status,
|
|
|
+ wan.v_upper,wan.v_lower,wan.c_upper,wan.p_upper,wan.w_upper,
|
|
|
+ g_product_t_ac_type_str[ph]);
|
|
|
}else
|
|
|
{
|
|
|
sprintf(ack_str,CHANNEL_SINGLE_RES_TYPE,pch->info.name,req.pro_ch_id,pch->power[0].voltage,
|
|
|
@@ -959,7 +1254,11 @@ static void overChannelStatusMonitoring(void* conn)
|
|
|
pch->thr.c_upper,pch->thr.p_upper,
|
|
|
pch->thr.w_upper,
|
|
|
pch->info.open_delay,pch->info.close_delay,
|
|
|
- pch->info.status,"");
|
|
|
+ pch->info.status,
|
|
|
+ pch->info.alarm.l1_v_upper,
|
|
|
+ pch->info.alarm.l1_v_lower,pch->info.alarm.l1_c_upper,
|
|
|
+ pch->info.alarm.l1_p_upper,pch->info.alarm.l1_w_upper,
|
|
|
+ "");
|
|
|
}
|
|
|
}
|
|
|
}else if(strcmp(req.type,"chnWanInfo")==0)
|
|
|
@@ -1163,17 +1462,6 @@ static void sensorStatusMonitoring(void* conn)
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
static int webSetCallback(void)
|
|
|
{
|
|
|
httpAddCallback("/pdu/channelStatusMonitoring", overChannelStatusMonitoring);
|