|
|
|
@ -0,0 +1,949 @@
|
|
|
|
|
#include "first.h"
|
|
|
|
|
|
|
|
|
|
#include "base.h"
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "plugin.h"
|
|
|
|
|
#include "log.h"
|
|
|
|
|
#include "response.h"
|
|
|
|
|
#include "connections.h"
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include "http_header.h"
|
|
|
|
|
#include "json.h"
|
|
|
|
|
#include "../../../../Common/config_manager.h"
|
|
|
|
|
# include"mod_webm.h"
|
|
|
|
|
#include "web_interface_def.h"
|
|
|
|
|
#include "web_interface_stuc.h"
|
|
|
|
|
#include "web_interface.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
输入1:待结构化数据
|
|
|
|
|
返回: json字符串
|
|
|
|
|
**/
|
|
|
|
|
char * interface_send_server(interface_ss *data_in){
|
|
|
|
|
cJSON * json;
|
|
|
|
|
json = cJSON_CreateObject(); //创建对象
|
|
|
|
|
if(NULL == json) {goto end;}
|
|
|
|
|
cJSON_AddNumberToObject(json, "config_type", data_in->config_type);
|
|
|
|
|
cJSON_AddStringToObject(json, "ifname", data_in->ifname);
|
|
|
|
|
//char* szOut = (char*)(sizeof(char));
|
|
|
|
|
char *out_string = cJSON_PrintUnformatted(json);
|
|
|
|
|
if(out_string == NULL) {goto end;}
|
|
|
|
|
int len = strlen(out_string);
|
|
|
|
|
char* szOut = (char*)malloc(sizeof(char)*len);
|
|
|
|
|
strcpy(szOut,out_string);
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return szOut;
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
输入1:json字符串
|
|
|
|
|
输入2:结构化数据
|
|
|
|
|
返回: 成功-失败
|
|
|
|
|
**/
|
|
|
|
|
int interface_get_server(char *data_in,interface_sg *data_out){
|
|
|
|
|
cJSON *json;
|
|
|
|
|
|
|
|
|
|
//interface_sg *data_struct;
|
|
|
|
|
//data_struct = (interface_sg*)malloc(sizeof(interface_sg ));
|
|
|
|
|
json = cJSON_Parse(data_in);
|
|
|
|
|
|
|
|
|
|
if(!json){goto end;}
|
|
|
|
|
//char * operate = cJSON_GetObjectItem(json, "operate")->valuestring;
|
|
|
|
|
cJSON *json_data = cJSON_GetObjectItem(json, "resultCode");
|
|
|
|
|
if(json_data == NULL){data_out->resultCode ="";}
|
|
|
|
|
else{data_out->resultCode = json_data->valuestring;}
|
|
|
|
|
json_data = cJSON_GetObjectItem(json, "message");
|
|
|
|
|
if(json_data == NULL){data_out->message ="";}
|
|
|
|
|
else{data_out->message =json_data ->valuestring;}
|
|
|
|
|
if(strcmp(data_out->resultCode , "0")) {goto end;} //返回0,直接跳出
|
|
|
|
|
|
|
|
|
|
cJSON * Array = cJSON_GetObjectItem(json, "data"); //从root中获得jsonarray
|
|
|
|
|
if(Array == NULL){goto end;}
|
|
|
|
|
int size = cJSON_GetArraySize(Array ); //读取数组大小
|
|
|
|
|
|
|
|
|
|
data_out->_datalen = size; //指定数组大小
|
|
|
|
|
|
|
|
|
|
// data_out->data = (interface_data*)malloc(sizeof(interface_data)*size); //给interface_data分配空间
|
|
|
|
|
|
|
|
|
|
//printf("adress:%p\n", data_struct->data);
|
|
|
|
|
// strcpy(ins.ifname,"kob");
|
|
|
|
|
//printf("size:%d\n",size);
|
|
|
|
|
for(int i=0;i<size;i++){
|
|
|
|
|
cJSON *ArrayItem = cJSON_GetArrayItem(Array,i); //分别读取数组中每一个object对象。
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "ifname");
|
|
|
|
|
if(json_data == NULL){goto end;}
|
|
|
|
|
data_out->data[i].ifname = json_data->valuestring;
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "ipenable");
|
|
|
|
|
if(json_data == NULL){goto end;}
|
|
|
|
|
data_out->data[i].ipenable = json_data->valuestring;
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "v4protocol");
|
|
|
|
|
if(json_data == NULL){goto end;}
|
|
|
|
|
data_out->data[i].v4protocol = json_data->valuestring;
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "v6protocol");
|
|
|
|
|
if(json_data == NULL){goto end;}
|
|
|
|
|
data_out->data[i].v6protocol = json_data->valuestring;
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "role");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].role = ""; }
|
|
|
|
|
else{data_out->data[i].role = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "maxspeed");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].maxspeed = ""; }
|
|
|
|
|
else{data_out->data[i].maxspeed = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "state");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].state = ""; }
|
|
|
|
|
else{data_out->data[i].state = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "hwaddr");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].hwaddr=""; }
|
|
|
|
|
else{data_out->data[i].hwaddr = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
cJSON *statistics_data = cJSON_GetObjectItem(ArrayItem, "statistics");
|
|
|
|
|
if(statistics_data == NULL){
|
|
|
|
|
data_out->data[i].rcv_packets = "";
|
|
|
|
|
data_out->data[i].rcv_bytes = "";
|
|
|
|
|
data_out->data[i].snd_packets = "";
|
|
|
|
|
data_out->data[i].snd_bytes = "";
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
json_data = cJSON_GetObjectItem(statistics_data, "rcv_packets");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].rcv_packets = "";;}
|
|
|
|
|
else{data_out->data[i].rcv_packets = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(statistics_data, "rcv_bytes");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].rcv_bytes = "";;}
|
|
|
|
|
else{data_out->data[i].rcv_bytes = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(statistics_data, "snd_packets");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].snd_packets = "";;}
|
|
|
|
|
else{data_out->data[i].snd_packets = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(statistics_data, "snd_bytes");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].snd_bytes = "";;}
|
|
|
|
|
else{data_out->data[i].snd_bytes = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *ipv4array = cJSON_GetObjectItem(ArrayItem, "ipv4");
|
|
|
|
|
cJSON *ipv4data = cJSON_GetArrayItem(ipv4array,0); //去除数组
|
|
|
|
|
if(ipv4data == NULL){
|
|
|
|
|
data_out->data[i].ipv4_ipaddr = "";
|
|
|
|
|
data_out->data[i].ipv4_prefixlen = "";
|
|
|
|
|
} //跳过
|
|
|
|
|
else{
|
|
|
|
|
json_data = cJSON_GetObjectItem(ipv4data, "addr");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].ipv4_ipaddr = "";;}
|
|
|
|
|
else{data_out->data[i].ipv4_ipaddr = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ipv4data, "prefixlen");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].ipv4_prefixlen = "";;}
|
|
|
|
|
else{data_out->data[i].ipv4_prefixlen = json_data->valuestring;}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//cJSON *ipv6data = cJSON_GetObjectItem(ArrayItem, "ipv6");
|
|
|
|
|
cJSON * ipv6Array = cJSON_GetObjectItem(ArrayItem, "ipv6"); //从root中获得jsonarray
|
|
|
|
|
if(ipv6Array == NULL){
|
|
|
|
|
data_out->data[i]._arripv6 = 0; //ipv6数组不存在
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
int ipv6_size = cJSON_GetArraySize(ipv6Array); //读取数组大小
|
|
|
|
|
data_out->data[i]._arripv6 = ipv6_size;
|
|
|
|
|
for(int j=0;j<ipv6_size;j++){
|
|
|
|
|
cJSON *ArrayItem = cJSON_GetArrayItem(ipv6Array,j); //分别读取数组中每一个object对象。
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "addr");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].ipv6_data[j].ipv6_ipaddr = "";}
|
|
|
|
|
else {data_out->data[i].ipv6_data[j].ipv6_ipaddr = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "prefixlen");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].ipv6_data[j].ipv6_prefixlen ="";}
|
|
|
|
|
else{data_out->data[i].ipv6_data[j].ipv6_prefixlen = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(data_out->data[i]._arripv6 == 0){ //初始为空,防止野指针
|
|
|
|
|
data_out->data[i].ipv6_data[0].ipv6_ipaddr = "";
|
|
|
|
|
data_out->data[i].ipv6_data[0].ipv6_prefixlen ="";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//printf("adress:%p\n",data_struct);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
end:
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int temp_interface_get_server(char *data_in,interface_sg *data_out){
|
|
|
|
|
cJSON *json;
|
|
|
|
|
|
|
|
|
|
//interface_sg *data_struct;
|
|
|
|
|
//data_struct = (interface_sg*)malloc(sizeof(interface_sg ));
|
|
|
|
|
json = cJSON_Parse(data_in);
|
|
|
|
|
|
|
|
|
|
if(!json){ goto end;}
|
|
|
|
|
//char * operate = cJSON_GetObjectItem(json, "operate")->valuestring;
|
|
|
|
|
cJSON *json_data = cJSON_GetObjectItem(json, "resultCode");
|
|
|
|
|
if(json_data == NULL){data_out->resultCode ="";}
|
|
|
|
|
else{data_out->resultCode = json_data->valuestring;}
|
|
|
|
|
json_data = cJSON_GetObjectItem(json, "message");
|
|
|
|
|
if(json_data == NULL){data_out->message ="";}
|
|
|
|
|
else{data_out->message =json_data ->valuestring;}
|
|
|
|
|
if(strcmp(data_out->resultCode , "0")) {goto end;} //返回0,直接跳出
|
|
|
|
|
|
|
|
|
|
cJSON * ArrayItem = cJSON_GetObjectItem(json, "data"); //从root中获得jsonarray
|
|
|
|
|
if(ArrayItem == NULL){goto end;}
|
|
|
|
|
//cJSON *ArrayItem = cJSON_GetArrayItem(Array,i); //分别读取数组中每一个object对象。
|
|
|
|
|
int i=0;
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "ifname");
|
|
|
|
|
if(json_data == NULL){goto end;}
|
|
|
|
|
data_out->data[i].ifname = json_data->valuestring;
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "ipenable");
|
|
|
|
|
if(json_data == NULL){goto end;}
|
|
|
|
|
data_out->data[i].ipenable = json_data->valuestring;
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "v4protocol");
|
|
|
|
|
if(json_data == NULL){goto end;}
|
|
|
|
|
data_out->data[i].v4protocol = json_data->valuestring;
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "v6protocol");
|
|
|
|
|
if(json_data == NULL){goto end;}
|
|
|
|
|
data_out->data[i].v6protocol = json_data->valuestring;
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "role");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].role = ""; }
|
|
|
|
|
else{data_out->data[i].role = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "maxspeed");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].maxspeed = ""; }
|
|
|
|
|
else{data_out->data[i].maxspeed = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "state");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].state = ""; }
|
|
|
|
|
else{data_out->data[i].state = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "hwaddr");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].hwaddr=""; }
|
|
|
|
|
else{data_out->data[i].hwaddr = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
cJSON *statistics_data = cJSON_GetObjectItem(ArrayItem, "statistics");
|
|
|
|
|
if(statistics_data == NULL){
|
|
|
|
|
data_out->data[i].rcv_packets = "";
|
|
|
|
|
data_out->data[i].rcv_bytes = "";
|
|
|
|
|
data_out->data[i].snd_packets = "";
|
|
|
|
|
data_out->data[i].snd_bytes = "";
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
json_data = cJSON_GetObjectItem(statistics_data, "rcv_packets");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].rcv_packets = "";;}
|
|
|
|
|
else{data_out->data[i].rcv_packets = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(statistics_data, "rcv_bytes");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].rcv_bytes = "";;}
|
|
|
|
|
else{data_out->data[i].rcv_bytes = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(statistics_data, "snd_packets");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].snd_packets = "";;}
|
|
|
|
|
else{data_out->data[i].snd_packets = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(statistics_data, "snd_bytes");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].snd_bytes = "";;}
|
|
|
|
|
else{data_out->data[i].snd_bytes = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *ipv4array = cJSON_GetObjectItem(ArrayItem, "ipv4");
|
|
|
|
|
cJSON *ipv4data = cJSON_GetArrayItem(ipv4array,0); //去除数组
|
|
|
|
|
if(ipv4data == NULL){
|
|
|
|
|
data_out->data[i].ipv4_ipaddr = "";
|
|
|
|
|
data_out->data[i].ipv4_prefixlen = "";
|
|
|
|
|
} //跳过
|
|
|
|
|
else{
|
|
|
|
|
json_data = cJSON_GetObjectItem(ipv4data, "addr");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].ipv4_ipaddr = "";;}
|
|
|
|
|
else{data_out->data[i].ipv4_ipaddr = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ipv4data, "prefixlen");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].ipv4_prefixlen = "";;}
|
|
|
|
|
else{data_out->data[i].ipv4_prefixlen = json_data->valuestring;}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//cJSON *ipv6data = cJSON_GetObjectItem(ArrayItem, "ipv6");
|
|
|
|
|
cJSON * ipv6Array = cJSON_GetObjectItem(ArrayItem, "ipv6"); //从root中获得jsonarray
|
|
|
|
|
if(ipv6Array == NULL){
|
|
|
|
|
data_out->data[i]._arripv6 = 0; //ipv6数组不存在
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
int ipv6_size = cJSON_GetArraySize(ipv6Array); //读取数组大小
|
|
|
|
|
data_out->data[i]._arripv6 = ipv6_size;
|
|
|
|
|
for(int j=0;j<ipv6_size;j++){
|
|
|
|
|
cJSON *ArrayItem = cJSON_GetArrayItem(ipv6Array,j); //分别读取数组中每一个object对象。
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "addr");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].ipv6_data[j].ipv6_ipaddr = "";}
|
|
|
|
|
else {data_out->data[i].ipv6_data[j].ipv6_ipaddr = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "prefixlen");
|
|
|
|
|
if(json_data == NULL){data_out->data[i].ipv6_data[j].ipv6_prefixlen ="";}
|
|
|
|
|
else{data_out->data[i].ipv6_data[j].ipv6_prefixlen = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(data_out->data[i]._arripv6 == 0){ //初始为空,防止野指针
|
|
|
|
|
data_out->data[i].ipv6_data[0].ipv6_ipaddr = "";
|
|
|
|
|
data_out->data[i].ipv6_data[0].ipv6_prefixlen ="";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//printf("adress:%p\n",data_struct);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
end:
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
输入1:json字符串
|
|
|
|
|
输入2:结构化数据
|
|
|
|
|
返回: 成功-失败
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
int interface_get_web(char *data_in,interface_wg *data_out){
|
|
|
|
|
cJSON *json;
|
|
|
|
|
|
|
|
|
|
json = cJSON_Parse(data_in);
|
|
|
|
|
if(!json){ goto end;}
|
|
|
|
|
//char * operate = cJSON_GetObjectItem(json, "operate")->valuestring;
|
|
|
|
|
cJSON * json_data = cJSON_GetObjectItem(json, "type");
|
|
|
|
|
if(json_data == NULL){data_out->type ="";}
|
|
|
|
|
else{data_out->type = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(json, "data");
|
|
|
|
|
if(json_data == NULL){
|
|
|
|
|
data_out->page_num ="";
|
|
|
|
|
data_out->page_count ="";
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
cJSON * item = cJSON_GetObjectItem(json, "data");
|
|
|
|
|
json_data = cJSON_GetObjectItem(item, "page_num");
|
|
|
|
|
if(json_data == NULL){data_out->page_num ="";}
|
|
|
|
|
else{data_out->page_num = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(item, "page_count");
|
|
|
|
|
if(json_data == NULL){data_out->page_count ="";}
|
|
|
|
|
else{data_out->page_count = json_data->valuestring;}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//发送数据到WEB
|
|
|
|
|
char *interface_send_web(interface_ws *data_in){
|
|
|
|
|
cJSON * json;
|
|
|
|
|
json = cJSON_CreateObject(); //创建对象
|
|
|
|
|
if(NULL == json) {goto end;}
|
|
|
|
|
cJSON_AddStringToObject(json, "retcode", data_in->retcode);
|
|
|
|
|
cJSON_AddStringToObject(json, "message", data_in->message);
|
|
|
|
|
cJSON_AddStringToObject(json, "pages", data_in->pages);
|
|
|
|
|
|
|
|
|
|
cJSON *JsonArray = cJSON_CreateArray(); //创建数组
|
|
|
|
|
for(int i=0;i < data_in->_datalen;i++){
|
|
|
|
|
cJSON *ArrayItem = cJSON_CreateObject(); //创建一个对象将对象
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "interface_type", data_in->data[i].interface_type);
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "interface_name",data_in->data[i].interface_name );
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "mac", data_in->data[i].mac);
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "rate",data_in->data[i].rate );
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "input_flow", data_in->data[i].input_flow);
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "output_flow",data_in->data[i].output_flow );
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "status", data_in->data[i].status);
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "vlan_flag", data_in->data[i].vlan_flag);
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "attr", data_in->data[i].attr);
|
|
|
|
|
cJSON *vlanArray = cJSON_CreateArray(); //创建数组
|
|
|
|
|
for(int j=0;j<data_in->data[i]._arrlen;j++){
|
|
|
|
|
int vid = data_in->data[i].vlan_id[j];
|
|
|
|
|
cJSON_AddItemToArray(vlanArray, cJSON_CreateNumber(vid));
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(ArrayItem, "vlan_id", vlanArray); //将jason数组添加到ArrayItem对象中
|
|
|
|
|
cJSON_AddItemToArray(JsonArray, ArrayItem);//将该对象依次添加到数组里
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(json, "data", JsonArray); //将jason数组添加到root对象中
|
|
|
|
|
|
|
|
|
|
char * out_string = cJSON_PrintUnformatted(json);
|
|
|
|
|
if(out_string == NULL) {cJSON_Delete(json);goto end;}
|
|
|
|
|
int out_len = strlen(out_string);
|
|
|
|
|
char* szOut = (char*)malloc(sizeof(char)*out_len);
|
|
|
|
|
strcpy(szOut,out_string);
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return szOut;
|
|
|
|
|
end:
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *interface_vlan_send_server(interface_vlan_ss * data_in){
|
|
|
|
|
cJSON * json;
|
|
|
|
|
json = cJSON_CreateObject(); //创建对象
|
|
|
|
|
if(NULL == json) {goto end;}
|
|
|
|
|
cJSON_AddStringToObject(json, "operate", data_in->operate);
|
|
|
|
|
cJSON *JsonArray = cJSON_CreateArray(); //创建数组
|
|
|
|
|
cJSON *ArrayItem = cJSON_CreateObject(); //创建一个对象
|
|
|
|
|
if(NULL == ArrayItem) {goto end;}
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "if_name", data_in->if_name);
|
|
|
|
|
cJSON_AddItemToArray(JsonArray, ArrayItem);//将该对象依次添加到数组里
|
|
|
|
|
cJSON_AddItemToObject(json, "get_ifvlan", JsonArray); //将jason数组添加到root对象中
|
|
|
|
|
|
|
|
|
|
//char* szOut = (char*)(sizeof(char));
|
|
|
|
|
char *out_string = cJSON_PrintUnformatted(json);
|
|
|
|
|
if(out_string == NULL) {goto end;}
|
|
|
|
|
int len = strlen(out_string);
|
|
|
|
|
char* szOut = (char*)malloc(sizeof(char)*len);
|
|
|
|
|
strcpy(szOut,out_string);
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return szOut;
|
|
|
|
|
end:
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//VLAN数据解析
|
|
|
|
|
int interface_vlan_get_server(char *data_in, interface_vlan_sg *data_out){
|
|
|
|
|
cJSON *json;
|
|
|
|
|
|
|
|
|
|
json = cJSON_Parse(data_in);
|
|
|
|
|
if(!json){goto end;}
|
|
|
|
|
cJSON * Array = cJSON_GetObjectItem(json, "if_vlan"); //从json中获得jsonarray
|
|
|
|
|
if(Array == NULL){goto end;}//初始话出错
|
|
|
|
|
int size = cJSON_GetArraySize( Array ); //读取数组大小
|
|
|
|
|
if(size == 0){
|
|
|
|
|
data_out->data[0].if_name = "";
|
|
|
|
|
data_out->data[0].if_attr ="";
|
|
|
|
|
data_out->data[0]._vlan_flag = "0";
|
|
|
|
|
data_out->data[0]._arrlen = 0;
|
|
|
|
|
} //数组为空,赋空值
|
|
|
|
|
else{
|
|
|
|
|
data_out->_datalen = size; //数据个数
|
|
|
|
|
for(int i = 0;i< size;i++){
|
|
|
|
|
cJSON *ArrayItem = cJSON_GetArrayItem(Array,i);
|
|
|
|
|
cJSON * json_data = cJSON_GetObjectItem(ArrayItem, "if_name");
|
|
|
|
|
if(json_data == NULL){goto end;} //关键值丢失出错
|
|
|
|
|
data_out->data[i].if_name = json_data->valuestring;
|
|
|
|
|
|
|
|
|
|
json_data = cJSON_GetObjectItem(ArrayItem, "if_attr");
|
|
|
|
|
if(json_data == NULL){goto end; }
|
|
|
|
|
data_out->data[i].if_attr = json_data->valuestring;
|
|
|
|
|
|
|
|
|
|
cJSON *Array_vid = cJSON_GetObjectItem(ArrayItem, "vid");
|
|
|
|
|
if(Array_vid == NULL){ data_out->data[i]._vlan_flag = "0"; } //vlan数组不存在,标志为0,未开启。
|
|
|
|
|
else{
|
|
|
|
|
int size_arr = cJSON_GetArraySize(Array_vid ); //读取数组大小
|
|
|
|
|
data_out->data[i]._arrlen = size_arr;
|
|
|
|
|
if(size_arr == 0){data_out->data[i]._vlan_flag = "0";} //vlan数组为空,标志为0,未开启。
|
|
|
|
|
else{
|
|
|
|
|
data_out->data[i]._vlan_flag = "1"; //不为空,开启VLAN
|
|
|
|
|
for(int j =0;j<size_arr;j++){
|
|
|
|
|
json_data = cJSON_GetArrayItem(Array_vid,j);
|
|
|
|
|
data_out->data[i].vlan_id[j] = json_data->valueint; //取数
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
end:
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
char * interface_vlan_send_web(interface_vlan_ws *data_in){
|
|
|
|
|
cJSON * json;
|
|
|
|
|
json = cJSON_CreateObject(); //创建对象
|
|
|
|
|
if(NULL == json) {goto end;}
|
|
|
|
|
cJSON_AddStringToObject(json, "retcode", data_in->retcode);
|
|
|
|
|
cJSON_AddStringToObject(json, "message", data_in->message);
|
|
|
|
|
cJSON * page_json = cJSON_CreateObject(); //创建对象
|
|
|
|
|
cJSON_AddStringToObject(page_json, "total", data_in->total);
|
|
|
|
|
cJSON_AddStringToObject(page_json, "page_num", data_in->page_num);
|
|
|
|
|
cJSON_AddStringToObject(page_json, "page_count", data_in->page_count);
|
|
|
|
|
cJSON_AddItemToObject(json, "pages", page_json);
|
|
|
|
|
|
|
|
|
|
cJSON *JsonArray = cJSON_CreateArray(); //创建数组
|
|
|
|
|
for(int i=0;i < data_in->_datalen;i++){
|
|
|
|
|
cJSON *ArrayItem = cJSON_CreateObject(); //创建一个对象将对象
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "vlan_id", data_in->data[i].vlan_id);
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "ipv4",data_in->data[i].ipv4);
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "ipv6", data_in->data[i].ipv6);
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "submask_ipv4",data_in->data[i].submask_ipv4 );
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "submask_ipv6", data_in->data[i].submask_ipv6);
|
|
|
|
|
|
|
|
|
|
cJSON_AddItemToArray(JsonArray, ArrayItem);//将该对象依次添加到数组里
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(json, "data", JsonArray); //将jason数组添加到root对象中
|
|
|
|
|
|
|
|
|
|
char * out_string = cJSON_PrintUnformatted(json);
|
|
|
|
|
if(out_string == NULL) {goto end;}
|
|
|
|
|
int out_len = strlen(out_string);
|
|
|
|
|
char* szOut = (char*)malloc(sizeof(char)*out_len);
|
|
|
|
|
strcpy(szOut,out_string);
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return szOut;
|
|
|
|
|
end:
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
//配置IP
|
|
|
|
|
char * interface_conip_send_web(interface_conip_ws *data_in){
|
|
|
|
|
cJSON * json;
|
|
|
|
|
json = cJSON_CreateObject(); //创建对象
|
|
|
|
|
if(NULL == json) {goto end;}
|
|
|
|
|
cJSON_AddStringToObject(json, "retcode", data_in->retcode);
|
|
|
|
|
cJSON_AddStringToObject(json, "message", data_in->message);
|
|
|
|
|
cJSON * page_json = cJSON_CreateObject(); //创建对象
|
|
|
|
|
cJSON_AddStringToObject(page_json, "total", data_in->total);
|
|
|
|
|
cJSON_AddStringToObject(page_json, "page_num", data_in->page_num);
|
|
|
|
|
cJSON_AddStringToObject(page_json, "page_count", data_in->page_count);
|
|
|
|
|
cJSON_AddItemToObject(json, "pages", page_json);
|
|
|
|
|
|
|
|
|
|
// printf("len:%d\n",data_in->_datalen);
|
|
|
|
|
cJSON *JsonArray = cJSON_CreateArray(); //创建数组
|
|
|
|
|
for(int i=0;i < data_in->_datalen;i++){
|
|
|
|
|
cJSON *ArrayItem = cJSON_CreateObject(); //创建一个对象将对象
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "interface_type", data_in->data[i].interface_type);
|
|
|
|
|
cJSON_AddStringToObject(ArrayItem, "ifname",data_in->data[i].ifname );
|
|
|
|
|
cJSON *iptypeArray = cJSON_CreateArray(); //创建数组
|
|
|
|
|
for(int j=0;j<data_in->data[i]._coniplen;j++){
|
|
|
|
|
cJSON *Arrayconip = cJSON_CreateObject(); //创建一个对象将对象
|
|
|
|
|
cJSON_AddNumberToObject(Arrayconip, "family", data_in->data[i].condata[j].family);
|
|
|
|
|
cJSON_AddStringToObject(Arrayconip, "ipaddr",data_in->data[i].condata[j].ipaddr);
|
|
|
|
|
cJSON_AddStringToObject(Arrayconip, "prefixlen",data_in->data[i].condata[j].prefixlen);
|
|
|
|
|
//printf("prefixlen:%s\n",data_in->data[i].condata[j].prefixlen);
|
|
|
|
|
cJSON_AddItemToArray(iptypeArray, Arrayconip);//将该对象依次添加到数组里
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(ArrayItem, "ip_type", iptypeArray); //将数组添加到ArrayItem对象中
|
|
|
|
|
cJSON_AddItemToArray(JsonArray, ArrayItem);//将该对象依次添加到数组里
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(json, "data", JsonArray); //将jason数组添加到root对象中
|
|
|
|
|
|
|
|
|
|
char * out_string = cJSON_PrintUnformatted(json);
|
|
|
|
|
if(out_string == NULL) {goto end;}
|
|
|
|
|
int out_len = strlen(out_string);
|
|
|
|
|
char* szOut = (char*)malloc(sizeof(char)*out_len);
|
|
|
|
|
strcpy(szOut,out_string);
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return szOut;
|
|
|
|
|
end:
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询可配置IP的接口
|
|
|
|
|
char * interface_conipenable_send_web(interface_conipenable_ws *data_in){
|
|
|
|
|
cJSON * json;
|
|
|
|
|
json = cJSON_CreateObject(); //创建对象
|
|
|
|
|
if(NULL == json) {goto end;}
|
|
|
|
|
cJSON_AddStringToObject(json, "retcode", data_in->retcode);
|
|
|
|
|
cJSON_AddStringToObject(json, "message", data_in->message);
|
|
|
|
|
cJSON_AddStringToObject(json, "pages", "");
|
|
|
|
|
cJSON *JsonArray = cJSON_CreateArray(); //创建数组
|
|
|
|
|
for(int i=0;i < data_in->_datalen;i++){
|
|
|
|
|
char * name = data_in->data[i];
|
|
|
|
|
cJSON_AddItemToArray(JsonArray, cJSON_CreateString(name));
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(json, "data", JsonArray); //将jason数组添加到root对象中
|
|
|
|
|
|
|
|
|
|
char * out_string = cJSON_PrintUnformatted(json);
|
|
|
|
|
if(out_string == NULL) {goto end;}
|
|
|
|
|
int out_len = strlen(out_string);
|
|
|
|
|
char* szOut = (char*)malloc(sizeof(char)*out_len);
|
|
|
|
|
strcpy(szOut,out_string);
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return szOut;
|
|
|
|
|
end:
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询接口信息
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char * interface_process(server *srv,char * data_in,void *point){
|
|
|
|
|
//处理web请求
|
|
|
|
|
//从WEB端解析数据
|
|
|
|
|
char *mess_str = NULL;
|
|
|
|
|
int mess_len = 0;
|
|
|
|
|
mod_webm_plugin_data *p_d = point;
|
|
|
|
|
int flag =1;
|
|
|
|
|
|
|
|
|
|
interface_wg data_web;
|
|
|
|
|
flag = interface_get_web(data_in,&data_web); //
|
|
|
|
|
if(flag == 1){log_error_write(srv, __FILE__, __LINE__, "s", "WEB Parsing data error-interface"); return NULL;}
|
|
|
|
|
|
|
|
|
|
interface_ss server_send_data;
|
|
|
|
|
server_send_data.config_type = 5; //获取接口所有数据
|
|
|
|
|
server_send_data.ifname = "";
|
|
|
|
|
char * json_data = interface_send_server(&server_send_data);//向服务端发送请求
|
|
|
|
|
if( json_data ==NULL){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER Serialized data error-interface");return NULL; }
|
|
|
|
|
if (p_d && p_d->web_cfg_exec)
|
|
|
|
|
{
|
|
|
|
|
flag = p_d->web_cfg_exec(CM_CONFIG_GET_ALL, IPCONFIG_V4, json_data, strlen(json_data), &mess_str, &mess_len); //获取所有物理口
|
|
|
|
|
if(flag != 0){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER send data error-interface"); return NULL;}
|
|
|
|
|
}
|
|
|
|
|
else {log_error_write(srv, __FILE__, __LINE__, "s", "CFG lod error-interface");return NULL;}
|
|
|
|
|
free( json_data);
|
|
|
|
|
|
|
|
|
|
interface_sg server_get_data ; //定义获取到的SERVER端数据结构
|
|
|
|
|
flag = interface_get_server(mess_str,&server_get_data);//从服务端解析数据
|
|
|
|
|
if(flag){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER Parsing data error-interface");return NULL; }
|
|
|
|
|
|
|
|
|
|
interface_ws websend_data; //定义发送WEB端的数据结构
|
|
|
|
|
websend_data.retcode=server_get_data.resultCode;
|
|
|
|
|
websend_data.message=server_get_data.message;
|
|
|
|
|
websend_data.pages="";
|
|
|
|
|
int index = 0; //发送端数据结构索引
|
|
|
|
|
for(int i=0;i<server_get_data._datalen;i++){
|
|
|
|
|
char * rol = server_get_data.data[i].role;
|
|
|
|
|
if ( strcmp(rol ,"lan" ) && strcmp(rol ,"wan" ) ){continue;} //筛选LAN,wan
|
|
|
|
|
websend_data.data[index].interface_type = server_get_data.data[i].role;
|
|
|
|
|
websend_data.data[index].interface_name = server_get_data.data[i].ifname;
|
|
|
|
|
websend_data.data[index].mac = server_get_data.data[i].hwaddr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char temp[20];
|
|
|
|
|
char *bytes = server_get_data.data[i].rcv_bytes;
|
|
|
|
|
//char *packets = server_get_data.data[i].rcv_packets;
|
|
|
|
|
double flow =atoi(bytes);
|
|
|
|
|
if(flow>1024 && flow<=1048576) {sprintf(temp, "%.2fk", (flow/1024));}
|
|
|
|
|
else if(flow>1048576 && flow<=1048576000) {sprintf(temp, "%.2fM", (flow/1048576));}
|
|
|
|
|
else if(flow>1048576000 ) {sprintf(temp, "%.2fG", (flow/1048576000));}
|
|
|
|
|
strcpy(websend_data.data[index].input_flow,temp);
|
|
|
|
|
//strcat( websend_data.data[index].input_flow, packets); //包个数
|
|
|
|
|
|
|
|
|
|
char *sndbytes = server_get_data.data[i].snd_bytes;
|
|
|
|
|
//char *sndpackets = server_get_data.data[i].snd_packets;
|
|
|
|
|
flow =atoi(sndbytes);
|
|
|
|
|
if(flow>1024 && flow<=1048576) {sprintf(temp, "%.2fk", (flow/1024));}
|
|
|
|
|
else if(flow>1048576 && flow<=1048576000) {sprintf(temp, "%.2fM", (flow/1048576));}
|
|
|
|
|
else if(flow>1048576000 ) {sprintf(temp, "%.2fG", (flow/1048576000));}
|
|
|
|
|
strcpy(websend_data.data[index].output_flow,temp);
|
|
|
|
|
//strcat( websend_data.data[index].output_flow, sndpackets); //包个数
|
|
|
|
|
|
|
|
|
|
websend_data.data[index].status = server_get_data.data[i].state;
|
|
|
|
|
websend_data.data[index].rate = server_get_data.data[i].maxspeed;
|
|
|
|
|
|
|
|
|
|
//查询VALN请求
|
|
|
|
|
interface_vlan_ss svlan_send_data; //定义vlan 服务发送数据
|
|
|
|
|
svlan_send_data.operate = "get"; //单个获取
|
|
|
|
|
svlan_send_data.if_name =server_get_data.data[i].ifname;
|
|
|
|
|
char * ss_data = interface_vlan_send_server(&svlan_send_data);//向服务端发送请求
|
|
|
|
|
if(ss_data==NULL){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER Serialized data error-interface"); return NULL;}
|
|
|
|
|
if (p_d && p_d->web_cfg_exec){
|
|
|
|
|
flag = p_d->web_cfg_exec(CM_CONFIG_GET, VLAN_CONFIG, ss_data, strlen(ss_data), &mess_str, &mess_len); //获取对应接口VLAN信息
|
|
|
|
|
if(flag != 0){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER send data error-interface"); return NULL;}
|
|
|
|
|
}
|
|
|
|
|
else {log_error_write(srv, __FILE__, __LINE__, "s", "CFG load error");return NULL;}
|
|
|
|
|
free(ss_data);
|
|
|
|
|
|
|
|
|
|
interface_vlan_sg svlan_get_data; //定义VLAN数据解析的结构体
|
|
|
|
|
flag = interface_vlan_get_server(mess_str,& svlan_get_data);//从VLAN服务端解析数据
|
|
|
|
|
if(flag != 0){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER parsing data error-interface");return NULL;}
|
|
|
|
|
websend_data.data[index].vlan_flag = svlan_get_data.data[0]._vlan_flag; //每次取一条
|
|
|
|
|
websend_data.data[index]._arrlen = svlan_get_data.data[0]._arrlen;
|
|
|
|
|
websend_data.data[index].attr = svlan_get_data.data[0].if_attr;
|
|
|
|
|
for(int j=0;j<svlan_get_data.data[0]._arrlen;j++){
|
|
|
|
|
websend_data.data[index].vlan_id[j] = svlan_get_data.data[0].vlan_id[j];
|
|
|
|
|
}
|
|
|
|
|
index++;
|
|
|
|
|
websend_data._datalen = index;
|
|
|
|
|
}
|
|
|
|
|
char* wout = interface_send_web( &websend_data); //向WEB端发送数据
|
|
|
|
|
return wout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询VLAN配置的接口
|
|
|
|
|
char * interface_vlan_process(server *srv,char * data_in,void *point){
|
|
|
|
|
//处理web请求
|
|
|
|
|
//从WEB端解析数据
|
|
|
|
|
int flag;
|
|
|
|
|
char *mess_str = NULL;
|
|
|
|
|
int mess_len = 0;
|
|
|
|
|
mod_webm_plugin_data *p_d = point;
|
|
|
|
|
|
|
|
|
|
interface_wg data_web;
|
|
|
|
|
flag = interface_get_web(data_in,&data_web); //
|
|
|
|
|
if(flag == 1){log_error_write(srv, __FILE__, __LINE__, "s", "WEB数据解析出错-VLAN"); return NULL;}
|
|
|
|
|
|
|
|
|
|
char * page_num_str = data_web.page_num;
|
|
|
|
|
char * page_count_str = data_web.page_count;
|
|
|
|
|
if(!strcmp(page_num_str,"")||!strcmp(page_count_str ,"") ){log_error_write(srv, __FILE__, __LINE__, "s", "页码为空出错-VLAN");return NULL;} //该页面,必须有页码返回值。
|
|
|
|
|
|
|
|
|
|
//向vlan服务端发送请求
|
|
|
|
|
//printf("发送请求VLAN服务端数据: \n");
|
|
|
|
|
interface_vlan_ss vlan_getdata;
|
|
|
|
|
vlan_getdata.operate = "getall"; //getall
|
|
|
|
|
vlan_getdata.if_name = "";
|
|
|
|
|
char * vlanget = interface_vlan_send_server(&vlan_getdata);//向服务端发送请求
|
|
|
|
|
if(vlanget == NULL){log_error_write(srv, __FILE__, __LINE__, "s", "server数据打包出错-VLAN"); return NULL; }
|
|
|
|
|
if (p_d && p_d->web_cfg_exec){
|
|
|
|
|
flag = p_d->web_cfg_exec(CM_CONFIG_GET_ALL, VLAN_CONFIG, vlanget, strlen(vlanget), &mess_str, &mess_len); //获取所有配置VLAN接口
|
|
|
|
|
if(flag != 0){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER端发送数据出错-VLAN"); return NULL;}
|
|
|
|
|
}
|
|
|
|
|
else {log_error_write(srv, __FILE__, __LINE__, "s", "配置函数加载出错-VLAN");return NULL;}
|
|
|
|
|
//printf("生成vlan_get_json:\n%s\n",vlanget);
|
|
|
|
|
free(vlanget);
|
|
|
|
|
//解析vlan返回数据。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface_vlan_sg vlandata;
|
|
|
|
|
flag = interface_vlan_get_server(mess_str,&vlandata);//从VLAN服务端解析数据
|
|
|
|
|
if(flag == 1){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER数据解析出错-VLAN");return NULL;}
|
|
|
|
|
int index =0;
|
|
|
|
|
int vid_vector[VLAN_COUNT]={-1}; //存放VLAN数量
|
|
|
|
|
for(int i = 0; i<vlandata. _datalen; i++){
|
|
|
|
|
for(int j=0;j<vlandata.data[i]._arrlen;j++){
|
|
|
|
|
int id = vlandata.data[i].vlan_id[j];
|
|
|
|
|
int flag = 0;
|
|
|
|
|
for (int k = 0; k<index;k++)
|
|
|
|
|
{
|
|
|
|
|
if (vid_vector[k] == id){ flag = 1;break;}
|
|
|
|
|
}
|
|
|
|
|
if( flag == 0){
|
|
|
|
|
vid_vector[index++] = id;
|
|
|
|
|
//printf("%d\n",id );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int page_num =atoi(page_num_str);
|
|
|
|
|
int page_count =atoi(page_count_str);
|
|
|
|
|
//printf("page_num:%d\npage_count:%d\n",page_num ,page_count );
|
|
|
|
|
int page_index = (page_num-1) *page_count ; //计算页码
|
|
|
|
|
|
|
|
|
|
interface_vlan_ws websend_vlan_data; // 定义发送给web Vlan数据结构
|
|
|
|
|
websend_vlan_data.retcode="0";
|
|
|
|
|
websend_vlan_data.message="成功";
|
|
|
|
|
char total_str[11] ; //总条数转换成字符串。
|
|
|
|
|
sprintf(total_str, "%d",index);
|
|
|
|
|
websend_vlan_data.total = total_str;
|
|
|
|
|
websend_vlan_data.page_num =page_num_str;
|
|
|
|
|
websend_vlan_data.page_count =page_count_str;
|
|
|
|
|
int k =0;
|
|
|
|
|
char name[page_count][20] ;
|
|
|
|
|
for( ; k < page_count; k++,page_index++) {
|
|
|
|
|
if(page_index>=index) break;
|
|
|
|
|
int id = vid_vector[page_index] ;
|
|
|
|
|
//printf("page:%d\n", id );
|
|
|
|
|
sprintf(name[k], "br-vl%d", id); //利用vlan id拼接成一个key,用来取接口信息。
|
|
|
|
|
//printf("%s\n", name);
|
|
|
|
|
//printf("发送服务端数据: \n");
|
|
|
|
|
interface_ss server_send_data; // 发送数据结构
|
|
|
|
|
server_send_data.config_type = 4; //获取接口
|
|
|
|
|
server_send_data.ifname = name[k];
|
|
|
|
|
char * json_data = interface_send_server(&server_send_data);//向服务端发送请求
|
|
|
|
|
if( json_data ==NULL){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER数据打包出错-VLAN");return NULL; }
|
|
|
|
|
if (p_d && p_d->web_cfg_exec){
|
|
|
|
|
flag = p_d->web_cfg_exec(CM_CONFIG_GET, IPCONFIG_V4, json_data, strlen(json_data), &mess_str, &mess_len); //获取对应VLAN接口信息。
|
|
|
|
|
if(flag != 0){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER端发送数据出错-VLAN"); return NULL;}
|
|
|
|
|
}
|
|
|
|
|
else {log_error_write(srv, __FILE__, __LINE__, "s", "配置函数加载出错-VLAN");return NULL;}
|
|
|
|
|
//printf("生成json:\n%s\n", json_data);
|
|
|
|
|
free( json_data);
|
|
|
|
|
//服务端数据解析
|
|
|
|
|
//printf("解析服务断数据: \n");
|
|
|
|
|
//log_error_write(srv, __FILE__, __LINE__, "s", mess_str);///////////////////////
|
|
|
|
|
interface_sg server_get_data ; //定义获取到的SERVER端数据结构
|
|
|
|
|
flag = temp_interface_get_server(mess_str,&server_get_data);//从服务端解析数据
|
|
|
|
|
if(flag !=0 ){log_error_write(srv, __FILE__, __LINE__, "d", flag);return NULL; }
|
|
|
|
|
websend_vlan_data.data[k].vlan_id = name[k];
|
|
|
|
|
websend_vlan_data.data[k].ipv4 = server_get_data.data[0].ipv4_ipaddr;
|
|
|
|
|
websend_vlan_data.data[k].submask_ipv4 = server_get_data.data[0].ipv4_prefixlen;
|
|
|
|
|
websend_vlan_data.data[k].ipv6 = server_get_data.data[0].ipv6_data[0].ipv6_ipaddr;
|
|
|
|
|
websend_vlan_data.data[k].submask_ipv6 = server_get_data.data[0].ipv6_data[0].ipv6_prefixlen;
|
|
|
|
|
//printf("解析完成: \n");
|
|
|
|
|
}
|
|
|
|
|
websend_vlan_data._datalen = k;
|
|
|
|
|
char * wout = interface_vlan_send_web(&websend_vlan_data);
|
|
|
|
|
|
|
|
|
|
return wout;
|
|
|
|
|
}
|
|
|
|
|
//查询已经配置IP的接口
|
|
|
|
|
char * interface_conip_process(server *srv,char * data_in,void *point){
|
|
|
|
|
//处理web请求
|
|
|
|
|
//从WEB端解析数据
|
|
|
|
|
int flag;
|
|
|
|
|
char *mess_str = NULL;
|
|
|
|
|
int mess_len = 0;
|
|
|
|
|
mod_webm_plugin_data *p_d = point;
|
|
|
|
|
|
|
|
|
|
//printf("解析WEB数据: \n");
|
|
|
|
|
interface_wg data_web;
|
|
|
|
|
flag = interface_get_web(data_in,&data_web); //
|
|
|
|
|
if(flag == 1){log_error_write(srv, __FILE__, __LINE__, "s", "WEB解析数据出错-CONIP"); return NULL;}
|
|
|
|
|
|
|
|
|
|
char * page_num_str = data_web.page_num;
|
|
|
|
|
char * page_count_str = data_web.page_count;
|
|
|
|
|
if(!strcmp(page_num_str,"")||!strcmp(page_count_str ,"")){log_error_write(srv, __FILE__, __LINE__, "s", "页码数为空-CONIP");return NULL;} //该页面,必须有页码返回值。
|
|
|
|
|
|
|
|
|
|
//向interface服务端发送请求
|
|
|
|
|
//printf("发送请求interface服务端数据: \n");
|
|
|
|
|
interface_ss server_send_data;
|
|
|
|
|
server_send_data.config_type = 5; //获取接口所有数据
|
|
|
|
|
server_send_data.ifname = "";
|
|
|
|
|
char * json_data = interface_send_server(&server_send_data);//向服务端发送请求
|
|
|
|
|
if( json_data ==NULL){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER端打包数据出错-CONIP");return NULL; }
|
|
|
|
|
if (p_d && p_d->web_cfg_exec){
|
|
|
|
|
flag = p_d->web_cfg_exec(CM_CONFIG_GET_ALL, IPCONFIG_V4, json_data, strlen(json_data), &mess_str, &mess_len); //获取所有配置VLAN接口
|
|
|
|
|
if(flag != 0){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER端发送数据出错-CONIP"); return NULL;}
|
|
|
|
|
}
|
|
|
|
|
else {log_error_write(srv, __FILE__, __LINE__, "s", "配置函数加载出错-CONIP");return NULL;}
|
|
|
|
|
free( json_data);
|
|
|
|
|
|
|
|
|
|
//printf("解析服务断数据: \n");
|
|
|
|
|
interface_sg server_get_data ; //定义获取到的SERVER端数据结构
|
|
|
|
|
flag = interface_get_server(mess_str,&server_get_data);//从服务端解析数据
|
|
|
|
|
if(flag){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER端解析数据出错-CONIP");return NULL; }
|
|
|
|
|
|
|
|
|
|
interface_conip_ws websend_conip_data; // 定义发送 到WEB数据结构
|
|
|
|
|
|
|
|
|
|
websend_conip_data.retcode =server_get_data.resultCode;
|
|
|
|
|
websend_conip_data.message =server_get_data.message;
|
|
|
|
|
|
|
|
|
|
int page_num =atoi(page_num_str);
|
|
|
|
|
int page_count =atoi(page_count_str);
|
|
|
|
|
|
|
|
|
|
int page_index = (page_num-1) *page_count ; //计算页码
|
|
|
|
|
int index =0; //
|
|
|
|
|
int k=0; //
|
|
|
|
|
for(int i=0;i<server_get_data._datalen;i++){
|
|
|
|
|
char * ipenable = server_get_data.data[i].ipenable;
|
|
|
|
|
|
|
|
|
|
if ( strcmp(ipenable ,"true" )){continue;} //筛选ipenable
|
|
|
|
|
char * v4protocol = server_get_data.data[i].v4protocol;
|
|
|
|
|
char * v6protocol = server_get_data.data[i].v6protocol;
|
|
|
|
|
if ( strcmp(v4protocol ,"static" ) || strcmp(v6protocol ,"static" )){continue;} //筛选出static
|
|
|
|
|
if( !strcmp(server_get_data.data[i].ipv4_ipaddr ,"" ) && !strcmp( server_get_data.data[i].ipv6_data[0].ipv6_ipaddr,"" ) ){continue;}
|
|
|
|
|
//ipv4,ipv6至少一个已经配置
|
|
|
|
|
if(index>=page_index && index<(page_index +page_count)){ //筛选出指定页面
|
|
|
|
|
websend_conip_data.data[k].interface_type = server_get_data.data[i].role;
|
|
|
|
|
websend_conip_data.data[k].ifname = server_get_data.data[i].ifname;
|
|
|
|
|
int coniplen =0;
|
|
|
|
|
if(!strcmp(v4protocol ,"static" ) ){
|
|
|
|
|
websend_conip_data.data[k].condata[coniplen].family = 2; //ipv4
|
|
|
|
|
websend_conip_data.data[k].condata[coniplen].ipaddr = server_get_data.data[i].ipv4_ipaddr;
|
|
|
|
|
websend_conip_data.data[k].condata[coniplen].prefixlen = server_get_data.data[i].ipv4_prefixlen;
|
|
|
|
|
coniplen++;
|
|
|
|
|
}
|
|
|
|
|
if(!strcmp(v6protocol ,"static" ) ){
|
|
|
|
|
websend_conip_data.data[k].condata[coniplen].family = 10; //ipv6
|
|
|
|
|
websend_conip_data.data[k].condata[coniplen].ipaddr = server_get_data.data[i].ipv6_data[0].ipv6_ipaddr;
|
|
|
|
|
websend_conip_data.data[k].condata[coniplen].prefixlen = server_get_data.data[i].ipv6_data[0].ipv6_prefixlen;
|
|
|
|
|
coniplen++;
|
|
|
|
|
}
|
|
|
|
|
websend_conip_data.data[k]._coniplen =coniplen;
|
|
|
|
|
k++;
|
|
|
|
|
}
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
char total_str[11] ; //总条数转换成字符串。
|
|
|
|
|
sprintf(total_str, "%d", index);
|
|
|
|
|
websend_conip_data._datalen =k;
|
|
|
|
|
websend_conip_data.page_num =page_num_str;
|
|
|
|
|
websend_conip_data.page_count=page_count_str;
|
|
|
|
|
websend_conip_data.total = total_str;
|
|
|
|
|
char * wout = interface_conip_send_web(&websend_conip_data);
|
|
|
|
|
return wout;
|
|
|
|
|
}
|
|
|
|
|
//查询能配置IP的接口
|
|
|
|
|
char * interface_conipenable_process(server *srv,char * data_in,void *point){
|
|
|
|
|
//处理web请求
|
|
|
|
|
//从WEB端解析数据
|
|
|
|
|
int flag;
|
|
|
|
|
char *mess_str = NULL;
|
|
|
|
|
int mess_len = 0;
|
|
|
|
|
mod_webm_plugin_data *p_d = point;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//printf("解析WEB数据: \n");
|
|
|
|
|
interface_wg data_web;
|
|
|
|
|
flag = interface_get_web(data_in,&data_web); //
|
|
|
|
|
if(flag == 1){log_error_write(srv, __FILE__, __LINE__, "s", "WEB解析数据出错-ENIP"); return NULL;}
|
|
|
|
|
|
|
|
|
|
//向interface服务端发送请求
|
|
|
|
|
//printf("发送请求interface服务端数据: \n");
|
|
|
|
|
interface_ss server_send_data;
|
|
|
|
|
server_send_data.config_type = 5; //获取接口所有数据
|
|
|
|
|
server_send_data.ifname = "";
|
|
|
|
|
char * json_data = interface_send_server(&server_send_data);//向服务端发送请求
|
|
|
|
|
if( json_data ==NULL){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER端打包数据出错-ENIP");return NULL; }
|
|
|
|
|
if (p_d && p_d->web_cfg_exec){
|
|
|
|
|
flag = p_d->web_cfg_exec(CM_CONFIG_GET_ALL, IPCONFIG_V4, json_data, strlen(json_data), &mess_str, &mess_len); //获取所有配置VLAN接口
|
|
|
|
|
if(flag != 0){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER端发送数据出错-ENIP"); return NULL;}
|
|
|
|
|
}
|
|
|
|
|
else {log_error_write(srv, __FILE__, __LINE__, "s", "配置函数加载出错-ENIP");return NULL;}
|
|
|
|
|
//printf("生成json:\n%s\n", json_data);
|
|
|
|
|
free( json_data);
|
|
|
|
|
|
|
|
|
|
//服务端数据解析
|
|
|
|
|
|
|
|
|
|
interface_sg server_get_data ; //定义获取到的SERVER端数据结构
|
|
|
|
|
flag = interface_get_server(mess_str,&server_get_data);//从服务端解析数据
|
|
|
|
|
if(flag){log_error_write(srv, __FILE__, __LINE__, "s", "SERVER端解析数据出错-ENIP");return NULL; }
|
|
|
|
|
|
|
|
|
|
interface_conipenable_ws websend_conipen_data; // 定义发送 到WEB数据结构
|
|
|
|
|
websend_conipen_data.retcode =server_get_data.resultCode;
|
|
|
|
|
websend_conipen_data.message =server_get_data.message;
|
|
|
|
|
int index = 0;
|
|
|
|
|
for(int i=0;i<server_get_data._datalen;i++){
|
|
|
|
|
char * ipenable = server_get_data.data[i].ipenable;
|
|
|
|
|
if ( strcmp(ipenable ,"true" )){continue;} //筛选ipenable
|
|
|
|
|
char * v4protocol = server_get_data.data[i].v4protocol;
|
|
|
|
|
char * v6protocol = server_get_data.data[i].v6protocol;
|
|
|
|
|
if ( strcmp(v4protocol ,"static" ) || strcmp(v6protocol ,"static" )){continue;} //筛选出都不是static接口
|
|
|
|
|
if( strcmp(server_get_data.data[i].ipv4_ipaddr ,"" ) || strcmp( server_get_data.data[i].ipv6_data[0].ipv6_ipaddr,"" ) ){continue;}
|
|
|
|
|
//筛选出ipv4,ipv6都没配置的接口。
|
|
|
|
|
websend_conipen_data.data[index] = server_get_data.data[i].ifname;
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
websend_conipen_data._datalen =index;
|
|
|
|
|
char * wout = interface_conipenable_send_web(&websend_conipen_data);
|
|
|
|
|
return wout;
|
|
|
|
|
}
|
|
|
|
|
//失败返回json
|
|
|
|
|
char * interface_failure(void){
|
|
|
|
|
fail_message fai;
|
|
|
|
|
fai.retcode ="1";
|
|
|
|
|
fai.message ="操作失败";
|
|
|
|
|
cJSON * json;
|
|
|
|
|
json = cJSON_CreateObject(); //创建对象
|
|
|
|
|
cJSON_AddStringToObject(json, "retcode", fai.retcode);
|
|
|
|
|
cJSON_AddStringToObject(json, "message",fai.message);
|
|
|
|
|
char *out_string = cJSON_PrintUnformatted(json);
|
|
|
|
|
int len = strlen(out_string);
|
|
|
|
|
char* szOut = (char*)malloc(sizeof(char)*len);
|
|
|
|
|
strcpy(szOut,out_string);
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
return szOut;
|
|
|
|
|
}
|