[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit
Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/app/goahead/interface5.0/net/Makefile b/ap/app/goahead/interface5.0/net/Makefile
new file mode 100755
index 0000000..a2a6e00
--- /dev/null
+++ b/ap/app/goahead/interface5.0/net/Makefile
@@ -0,0 +1,90 @@
+# /*****************************************************************************
+#* °æÈ¨ËùÓÐ (C)2015, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#*
+#* ÎļþÃû³Æ: Makefile
+#* Îļþ±êʶ: Makefile
+#* ÄÚÈÝÕªÒª: Makefile of ZTE applications
+#* ʹÓ÷½·¨: void
+#*
+#* ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+#* -----------------------------------------------------------------------------
+#* 2015/03/12 V1.0 Create ²ÜÈü ´´½¨
+#*
+# ******************************************************************************/
+
+#*******************************************************************************
+# include ZTE application makefile
+#*******************************************************************************
+include $(zte_app_mak)
+
+#*******************************************************************************
+# execute
+#*******************************************************************************
+#EXEC = libwebuinet.a
+
+#*******************************************************************************
+# objects
+#*******************************************************************************
+OBJS = zte_web_net_lan.o zte_web_net_other.o zte_web_net_wan.o
+
+SRC = zte_web_net_lan.c zte_web_net_other.c zte_web_net_wan.c
+
+#*******************************************************************************
+# include path
+#*******************************************************************************
+CFLAGS += -DCONFIG_CHINA_UNICOM -DWEBS -DUEMF -DOS="LINUX" -DLINUX \
+ -I. \
+ -I$(zte_lib_path)/libnvram \
+ -I$(zte_lib_path)/libezxml \
+ -I$(zte_lib_path)/libmxml \
+ -I../../../include \
+ -I$(zte_lib_path)/libsqlite \
+ -I$(zte_lib_path)/libsoft_timer \
+ -I../../../at_server \
+ -I../../../awps/include \
+ -I../../server \
+ -I.. \
+ -lsoftap \
+ -L$(zte_lib_path)/libsoftap \
+ -lpthread \
+ -lsoft_timer_sc \
+ -L$(zte_lib_path)/libsoft_timer
+
+ifeq ($(CONFIG_USE_WEBUI_SECURITY),yes)
+CFLAGS += -DWEBS_SECURITY
+endif
+#*******************************************************************************
+# macro definition
+#*******************************************************************************
+ifeq ($(CUSTOM_MODEL), MF29S2)
+CFLAGS += -DCUSTOM_VERSION_MF29S2_ZTE
+endif
+#CPPFLAGS += -D_MBB_OS_UCLINUX
+#*******************************************************************************
+# library
+#*******************************************************************************
+
+LDLIBS +=
+
+#*******************************************************************************
+# library path
+#*******************************************************************************
+LDLIBS +=
+
+#*******************************************************************************
+# targets
+#*******************************************************************************
+
+#$(error ===================================>)
+all: $(OBJS)
+ @echo "--------------------webui build-----------------------"
+#$(RANLIB) $@
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(INCLUDES) -c $< -Wl,--start-group $(LDLIBS) -Wl,--end-group
+
+#$(CC) $(LDFLAGS) $(CFLAGS) $(INCLUDES) -o $@ $< -Wl,--start-group $(LDLIBS) -Wl,--end-group
+
+
+clean:
+ -rm -f *.elf *.gdb *.o *.a
diff --git a/ap/app/goahead/interface5.0/net/zte_web_net_lan.c b/ap/app/goahead/interface5.0/net/zte_web_net_lan.c
new file mode 100644
index 0000000..7b82e59
--- /dev/null
+++ b/ap/app/goahead/interface5.0/net/zte_web_net_lan.c
@@ -0,0 +1,893 @@
+#include <stdlib.h>
+#include "zte_web_interface.h"
+#include "zte_web_net_lan.h"
+#include "zte_web_net_other.h"
+
+#include "message.h"
+#include "netotherapi.h"
+#include "mainctl_msg.h"
+
+#define WEB_DHCP_LEASE_TIME_DEFAULT 86400 /* 24*3600 */
+#define safe_free(x) do { if(x) {free(x); x=NULL;} } while(0)
+
+/*¶¨Òåsystemºê*/
+#define CMD_STR_LEN 256
+/*
+#define do_cmd(format, cmds...) ({ \
+ int __STATAS__; \
+ char __TEMP__[CMD_STR_LEN]; \
+ sprintf(__TEMP__, format, ##cmds); \
+ __STATAS__ = system(__TEMP__); \
+ __STATAS__; \
+})
+*/
+
+void zte_dhcpv6_state_set(webs_t wp)
+{
+ char_t *dhcpv6stateE = NULL;
+ char_t *dhcpv6statelessE = NULL;
+
+ dhcpv6stateE = websGetVar(wp, T("dhcpv6stateEnabled"), T(""));
+ dhcpv6statelessE = websGetVar(wp, T("dhcpv6statelessEnabled"), T(""));
+
+ slog(MISC_PRINT, SLOG_DEBUG, "dhcpv6stateE = %s\n", dhcpv6stateE);
+ slog(MISC_PRINT, SLOG_DEBUG, "dhcpv6statelessE = %s\n", dhcpv6statelessE);
+
+ if (!dhcpv6stateE || !strlen(dhcpv6stateE)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ if (!dhcpv6statelessE || !strlen(dhcpv6statelessE)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ if ((atoi(dhcpv6stateE) == 0) && (atoi(dhcpv6statelessE) == 0)) {
+ zte_web_write("dhcpv6stateEnabled", "0");
+ zte_web_write("dhcpv6statelessEnabled", "0");
+ } else if ((atoi(dhcpv6stateE) == 1) && (atoi(dhcpv6statelessE) == 0)) {
+ zte_web_write("dhcpv6stateEnabled", "1");
+ zte_web_write("dhcpv6statelessEnabled", "0");
+ } else if ((atoi(dhcpv6stateE) == 0) && (atoi(dhcpv6statelessE) == 1)) {
+ zte_web_write("dhcpv6stateEnabled", "0");
+ zte_web_write("dhcpv6statelessEnabled", "1");
+ } else {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+ zte_goform_mgmt_reboot_process(wp);
+}
+
+static void dhcp_setting_process(char *lanIp, char *lanNetmask, char *lanDhcpType,
+ char *dhcpStart, char *dhcpEnd, char *dhcpLease)
+{
+ dhcp_setting_req dhcp_setting = {0};
+
+ strncpy(dhcp_setting.lan_ip, lanIp,sizeof(dhcp_setting.lan_ip)-1);
+ strncpy(dhcp_setting.lan_netmask, lanNetmask,sizeof(dhcp_setting.lan_netmask)-1);
+ if (!strncmp(lanDhcpType, "DISABLE", strlen("DISABLE"))) {
+ dhcp_setting.dhcp_enabled = 0;
+ } else {
+ dhcp_setting.dhcp_enabled = 1;
+ strncpy(dhcp_setting.dhcp_start, dhcpStart,sizeof(dhcp_setting.dhcp_start)-1);
+ strncpy(dhcp_setting.dhcp_end, dhcpEnd,sizeof(dhcp_setting.dhcp_end)-1);
+ strncpy(dhcp_setting.dhcp_dns, lanIp,sizeof(dhcp_setting.dhcp_dns)-1);
+ strncpy(dhcp_setting.dhcp_lease, dhcpLease,sizeof(dhcp_setting.dhcp_lease)-1);
+ }
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, \
+ MSG_CMD_NET_DHCP_SETTING_REQ, sizeof(dhcp_setting), &dhcp_setting, 0);
+}
+
+//¿ìËÙDHCP²ÎÊýÉèÖÃ
+void quick_dhcp_set(webs_t wp)
+{
+ // data from form
+ char_t *lanIp = NULL;
+ char_t *lanNetmask = NULL;
+ char_t *lanDhcpType = NULL;
+ char_t *dhcpStart = NULL;
+ char_t *dhcpEnd = NULL;
+ char_t *dhcpDns = NULL;
+ char_t *dhcpLease = NULL;
+ char dhcp_temp[NVIO_DEFAULT_LEN] = {0};
+ int dhcp_lease_time = WEB_DHCP_LEASE_TIME_DEFAULT; /* default 24*3600 */
+
+ int dhcp_lease_hour = 24;
+
+ // get old data
+ int bLanNotChangeFlag = 0;
+ char lanIp_read[WEB_IP_ADDR_MAX_LEN] = {0};
+ char lanNetmask_read[WEB_IP_ADDR_MAX_LEN] = {0};
+ char dhcpType_read[NV_ITEM_VALUE_YES_NO_LEN] = {0};
+ char dhcpStart_read[WEB_IP_ADDR_MAX_LEN] = {0};
+ char dhcpEnd_read[WEB_IP_ADDR_MAX_LEN] = {0};
+ char dhcpDns_read[WEB_IP_ADDR_MAX_LEN] = {0};
+ char dhcpLeaseHour_read[NVIO_DEFAULT_LEN] = {0};
+
+ // wan info
+ //char wan_ip[NVIO_DEFAULT_LEN] = {0};
+
+ // Get the params from pages
+ lanIp = websGetVar(wp, T("lanIp"), T(""));
+ lanNetmask = websGetVar(wp, T("lanNetmask"), T(""));
+ lanDhcpType = websGetVar(wp, T("lanDhcpType"), T("SERVER"));
+ dhcpStart = websGetVar(wp, T("dhcpStart"), T(""));
+ dhcpEnd = websGetVar(wp, T("dhcpEnd"), T(""));
+ dhcpDns = websGetVar(wp, T("dhcpDns"), T(lanIp));
+ dhcpLease = websGetVar(wp, T("dhcpLease"), T("24"));
+#if 0 // kw 3
+ dhcp_lease_time = atoi(dhcpLease) * 3600;/* hours to seconds */
+#else
+ dhcp_lease_hour = atoi(dhcpLease);
+
+ if(dhcp_lease_hour < 0 || dhcp_lease_hour > INT_MAX-1)
+ {
+ dhcp_lease_hour = 24;
+ }
+
+ dhcp_lease_time = dhcp_lease_hour * 3600;
+
+#endif
+ sprintf(dhcp_temp, "%d", dhcp_lease_time);
+
+ //add by liuyingnan for server safe for xss attack start
+ if (DATA_NO_SAFE == zte_Safe_noSpecialChar(lanIp)
+ || DATA_NO_SAFE == zte_Safe_noSpecialChar(dhcpStart)
+ || DATA_NO_SAFE == zte_Safe_noSpecialChar(dhcpEnd)) {
+ sc_cfg_set("data_safe", "failed");
+ slog(MISC_PRINT, SLOG_ERR, "Get Data is no Safe:lanIp:%s\n", lanIp); /*lint !e26*/
+ //zte_write_result_to_web(wp,FAILURE);
+
+ return;
+ }
+ //add by liuyingnan for server safe for xss attack end
+
+ // read old data
+
+ (void)zte_web_read("lan_ipaddr", lanIp_read);
+ (void)zte_web_read("lan_netmask", lanNetmask_read);
+ (void)zte_web_read("dhcpEnabled", dhcpType_read);
+ (void)zte_web_read("dhcpStart", dhcpStart_read);
+ (void)zte_web_read("dhcpEnd", dhcpEnd_read);
+ (void)zte_web_read("dhcpDns", dhcpDns_read);
+ (void)zte_web_read("dhcpLease_hour", dhcpLeaseHour_read);
+
+ if (
+ (0 == strcmp(lanDhcpType, "SERVER"))
+ && (0 == strcmp(dhcpType_read, "1"))
+ ) {
+ if (!strcmp(lanIp, lanIp_read) &&
+ !strcmp(lanNetmask, lanNetmask_read) &&
+ !strcmp(dhcpStart, dhcpStart_read) &&
+ !strcmp(dhcpEnd, dhcpEnd_read) &&
+ !strcmp(dhcpDns, dhcpDns_read) &&
+ !strcmp(dhcpLease, dhcpLeaseHour_read)
+ ) {
+ bLanNotChangeFlag = 1;
+ }
+ } else if ((0 == strcmp(lanDhcpType, "DISABLE")) && (0 == strcmp(dhcpType_read, "0"))) {
+ if (!strcmp(lanIp, lanIp_read) && !strcmp(lanNetmask, lanNetmask_read)) {
+ bLanNotChangeFlag = 1;
+ }
+ }
+
+ if (1 == bLanNotChangeFlag) {
+ return;
+ }
+
+ /*
+ * check static ip address:
+ * lan and wan ip should not be the same except in bridge mode
+ */
+ if (!strncmp(lanDhcpType, "SERVER", strlen("SERVER"))) { /*lint !e530*/
+ if (0 == isIpValid(dhcpStart)) {
+ return;
+ }
+
+ if (0 == isIpValid(dhcpEnd)) {
+ return;
+ }
+ }
+
+ /* dhcpÅäÖ÷¢Ë͸øÖ÷¿Ø */
+ dhcp_setting_process(lanIp, lanNetmask, lanDhcpType, dhcpStart, dhcpEnd, dhcpLease);
+
+}
+
+//DHCP²ÎÊýÉèÖÃ
+void zte_dhcp_set(webs_t wp)
+{
+ slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User set dhcp!\n"));
+ // data from form
+ char_t *lanIp = NULL;
+ char_t *lanNetmask = NULL;
+ char_t *lanDhcpType = NULL;
+ char_t *dhcpStart = NULL;
+ char_t *dhcpEnd = NULL;
+ char_t *dhcpDns = NULL;
+ char_t *dhcpLease = NULL;
+ char dhcp_temp[NVIO_DEFAULT_LEN] = {0};
+ int dhcp_lease_time = WEB_DHCP_LEASE_TIME_DEFAULT; /* default 24*3600 */
+
+ int dhcp_lease_hour = 24;
+
+ // get old data
+ int bLanNotChangeFlag = 0;
+ char lanIp_read[WEB_IP_ADDR_MAX_LEN] = {0};
+ char lanNetmask_read[WEB_IP_ADDR_MAX_LEN] = {0};
+ char dhcpType_read[NV_ITEM_VALUE_YES_NO_LEN] = {0};
+ char dhcpStart_read[WEB_IP_ADDR_MAX_LEN] = {0};
+ char dhcpEnd_read[WEB_IP_ADDR_MAX_LEN] = {0};
+ char dhcpDns_read[WEB_IP_ADDR_MAX_LEN] = {0};
+ char dhcpLeaseHour_read[NVIO_DEFAULT_LEN] = {0};
+
+ // Get the params from pages
+ lanIp = websGetVar(wp, T("lanIp"), T(""));
+ lanNetmask = websGetVar(wp, T("lanNetmask"), T(""));
+ lanDhcpType = websGetVar(wp, T("lanDhcpType"), T("SERVER"));
+ dhcpStart = websGetVar(wp, T("dhcpStart"), T(""));
+ dhcpEnd = websGetVar(wp, T("dhcpEnd"), T(""));
+ dhcpDns = websGetVar(wp, T("dhcpDns"), T(lanIp));
+ dhcpLease = websGetVar(wp, T("dhcpLease"), T("24"));
+
+#if 0 // kw 3
+ dhcp_lease_time = atoi(dhcpLease) * 3600;/* hours to seconds */
+#else
+ dhcp_lease_hour = atoi(dhcpLease);
+
+ if(dhcp_lease_hour < 0 || dhcp_lease_hour > INT_MAX-1)
+ {
+ dhcp_lease_hour = 24;
+ }
+
+ dhcp_lease_time = dhcp_lease_hour * 3600;
+
+#endif
+
+
+ sprintf(dhcp_temp, "%d", dhcp_lease_time);
+ //add by liuyingnan for server safe for xss attack start
+ if (DATA_NO_SAFE == zte_Safe_noSpecialChar(lanIp)
+ || DATA_NO_SAFE == zte_Safe_noSpecialChar(dhcpStart)
+ || DATA_NO_SAFE == zte_Safe_noSpecialChar(dhcpEnd)) {
+ sc_cfg_set("data_safe", "failed");
+ slog(MISC_PRINT, SLOG_ERR, "Get Data is no Safe:lanIp:%s\n", lanIp); /*lint !e26*/
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+ //add by liuyingnan for server safe for xss attack end
+
+ // read old data
+
+ (void)zte_web_read("lan_ipaddr", lanIp_read);
+ (void)zte_web_read("lan_netmask", lanNetmask_read);
+ (void)zte_web_read("dhcpEnabled", dhcpType_read);
+ (void)zte_web_read("dhcpStart", dhcpStart_read);
+ (void)zte_web_read("dhcpEnd", dhcpEnd_read);
+ (void)zte_web_read("dhcpDns", dhcpDns_read);
+ (void)zte_web_read("dhcpLease_hour", dhcpLeaseHour_read);
+
+ if (
+ (0 == strcmp(lanDhcpType, "SERVER"))
+ && (0 == strcmp(dhcpType_read, "1"))
+ ) {
+ if (!strcmp(lanIp, lanIp_read) &&
+ !strcmp(lanNetmask, lanNetmask_read) &&
+ !strcmp(dhcpStart, dhcpStart_read) &&
+ !strcmp(dhcpEnd, dhcpEnd_read) &&
+ !strcmp(dhcpDns, dhcpDns_read) &&
+ !strcmp(dhcpLease, dhcpLeaseHour_read)
+ ) {
+ bLanNotChangeFlag = 1;
+ }
+ } else if ((0 == strcmp(lanDhcpType, "DISABLE")) && (0 == strcmp(dhcpType_read, "0"))) {
+ if (!strcmp(lanIp, lanIp_read) && !strcmp(lanNetmask, lanNetmask_read)) {
+ bLanNotChangeFlag = 1;
+ }
+ }
+
+ if (1 == bLanNotChangeFlag) {
+ zte_write_result_to_web(wp, SUCCESS);
+ return;
+ }
+
+ /*
+ * check static ip address:
+ * lan and wan ip should not be the same except in bridge mode
+ */
+ if (!strncmp(lanDhcpType, "SERVER", strlen("SERVER"))) { /*lint !e530*/
+ if (0 == isIpValid(dhcpStart)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ if (0 == isIpValid(dhcpEnd)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+ }
+
+ /* dhcpÅäÖ÷¢Ë͸øÖ÷¿Ø */
+ dhcp_setting_process(lanIp, lanNetmask, lanDhcpType, dhcpStart, dhcpEnd, dhcpLease);
+
+ zte_write_result_to_web(wp, SUCCESS);
+
+ zte_goform_mgmt_reboot_process(wp);
+}
+
+//ÉèÖÃDHCPµØÖ·³ØÖеľ²Ì¬IPÁбí
+void zte_static_dhcp_set(webs_t wp)
+{
+ char_t *mac_ip_list = NULL;
+ mac_ip_list = websGetVar(wp, T("mac_ip_list"), T(""));
+
+ slog(MISC_PRINT, SLOG_DEBUG, "add======mac_ip_list=%s\n", mac_ip_list);
+ if (!mac_ip_list)
+ return;
+ sc_cfg_set("mac_ip_list", mac_ip_list);
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_STATIC_DHCP, 0, NULL, 0);
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+void zte_set_bind_static_address(webs_t wp)
+{
+ char *bind_enable = NULL; /* 0: Disabled 1: Enabled */
+ bind_enable = websGetVar(wp, T("mac_ip_status"), T("0"));
+
+ switch (atoi(bind_enable)) {
+ case 0:
+ (void)zte_web_write("static_dhcp_enable", "0"); /* Disable */
+ break;
+ case 1:
+ (void)zte_web_write("static_dhcp_enable", "1"); /* Enable */
+ break;
+ default:
+ (void)zte_web_write("static_dhcp_enable", "0"); /* Disable */
+ break;
+ }
+
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_set_bind_static_address SEND MESSAGE TO MC START"); /*lint !e26*/
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_BIND_STATIC_ADDRESS, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_set_bind_static_address SEND MESSAGE TO MC END"); /*lint !e26*/
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+void zte_bind_static_address_add(webs_t wp)
+{
+ char *ip = NULL;
+ char *mac = NULL;
+ struct static_macip_info static_macip_info;
+
+ ip = websGetVar(wp, T("ip_address"), T(""));
+ mac = websGetVar(wp, T("mac_address"), T(""));
+
+ if (!ip || !strlen(ip)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+ if ((!mac) || (strlen(mac) != 17)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ strncpy(static_macip_info.mac, mac,sizeof(static_macip_info.mac)-1);
+ strncpy(static_macip_info.ip, ip,sizeof(static_macip_info.ip)-1);
+
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_bind_static_address_add SEND MESSAGE TO MC START"); /*lint !e26*/
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_BIND_STATIC_ADDRESS_ADD, sizeof(struct static_macip_info), (UCHAR *)&static_macip_info, 0);
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_bind_static_address_add SEND MESSAGE TO MC END"); /*lint !e26*/
+ Sleep(1);
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+void zte_bind_static_address_del(webs_t wp)
+{
+ char *mac = NULL;
+ mac = websGetVar(wp, T("mac_address"), T(""));
+
+ if ((!mac) || (strlen(mac) != 17)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_bind_static_address_del SEND MESSAGE TO MC START"); /*lint !e26*/
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_BIND_STATIC_ADDRESS_DEL, strlen(mac), (UCHAR *)mac, 0);
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_bind_static_address_del SEND MESSAGE TO MC END"); /*lint !e26*/
+ Sleep(1);
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+void zte_get_current_static_addr_list(webs_t wp)
+{
+ FILE *static_macip_file = NULL;
+ char line[100] = {0};
+ char mac_address[18] = {0};
+ char ip_address[50] = {0};
+
+ BOOL first = TRUE;
+
+ char path_conf[50] = {0};
+ char path_file[100] = {0};
+ sc_cfg_get("path_conf", path_conf, sizeof(path_conf));
+ sprintf(path_file, "%s/static_macip_file", path_conf);
+
+ web_feedback_header(wp);
+ zte_rest_cmd_write_head(wp);
+ (void)websWrite(wp, T("\"%s\":["), CMD_CURRENT_STATICADDR_LIST);
+ static_macip_file = fopen(path_file, "r");
+ if (static_macip_file == NULL) {
+ fprintf(stderr, "can not open file static_macip_file.");
+ goto out;
+ }
+
+ while (fgets(line, sizeof(line), static_macip_file) != NULL) {
+ if (first == FALSE) {
+ (void)websWrite(wp, T(","));
+ } else {
+ first = FALSE;
+ }
+ strncpy(mac_address, line, sizeof(mac_address)-1);
+ if(strlen(line) - 19 > 0 && strlen(line) - 19 < 50){
+ snprintf(ip_address,strlen(line)-18,"%s",line + 18);
+ }
+ //strncpy(ip_address, line + 18, strlen(line) - 19);
+ if (strncmp(mac_address, "", sizeof(mac_address)) != 0 && strncmp(ip_address, "", sizeof(ip_address)) != 0) {
+ (void)websWrite(wp, T("{\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":\"%s\"}"), HOSTANME, "", MAC, mac_address, ADDR, ip_address, DOMAIN, "");
+ }
+
+ memset(line, 0, sizeof(line));
+ memset(mac_address, 0, sizeof(mac_address));
+ memset(ip_address, 0, sizeof(ip_address));
+
+ }
+ fclose(static_macip_file);
+
+out:
+ (void)websWrite(wp, T("]"));
+ zte_rest_cmd_write_foot(wp);
+}
+
+/*ÔÚÒ³ÃæÉÏÏÔʾËùÓнÓÈëDHCP client µÄMACµØÖ·ºÍIPµØÖ·*/
+static int zte_dhcp_client_list(int eid, webs_t wp, int argc, char_t **argv)
+{
+ FILE *fp = NULL;/*lint !e63*/
+ typedef struct _DHCPOFFERINFO {
+ unsigned long expires;
+ unsigned long ip;
+ unsigned char mac[6];
+ unsigned char host_name[20];
+ unsigned char pad[2];
+ } DHCPOFFERINFO;
+ struct in_addr addr;/*lint !e1080 !e565 */
+ DHCPOFFERINFO addrlist;
+ int64_t written_at;/*lint !e522*/
+ int i = 0;
+ memset(&addrlist, 0, sizeof(addrlist));
+ // memset(&dclist,0,sizeof(DHCPCLIENTINFO)*MAX_DHCP_CLIENT_NUM);
+ system("killall -q -USR1 udhcpd");
+ fp = fopen("/var/udhcpd.leases", "r"); /*lint !e63*/
+
+ if (NULL == fp) {
+ slog(MISC_PRINT, SLOG_ERR, "can not open file/var/udhcpd.leases.");
+ return -1;
+ }
+ if (fread(&written_at, 1, sizeof(written_at), fp) != sizeof(written_at)) {
+ slog(MISC_PRINT, SLOG_DEBUG, "read the first part of udhcpd.leases fail!");
+ }
+
+ while (fread(&addrlist, 1, sizeof(addrlist), fp) == sizeof(addrlist)) {
+ addr.s_addr = addrlist.ip; /*lint !e115 !e1013 !e63 */
+ websWrite(wp, T("<tr><td align=\"center\" width=\"10%%\" class=\"head\">%d</td>"), i + 1);
+ websWrite(wp, T("<td align=\"center\" width=\"40%%\" class=\"tail\">%02X:%02X:%02X:%02X:%02X:%02X</td>"),
+ addrlist.mac[0], addrlist.mac[1], addrlist.mac[2], addrlist.mac[3], addrlist.mac[4], addrlist.mac[5]);
+ websWrite(wp, T("<td align=\"center\"width=\"40%%\" class=\"tail\">%s</td>"), inet_ntoa(addr));
+ websWrite(wp, T("</tr>"));
+ i++;
+ }
+ slog(MISC_PRINT, SLOG_DEBUG, "the number of dhcp client access is %d", i); /*lint !e26*/
+
+// if (NULL != fp) { // kw 3
+ fclose(fp);
+// }
+ return 0;
+}
+#ifdef WEB_ASP
+void init_router_web(void)
+{
+ websAspDefine(T("zte_dhcp_client_list"), zte_dhcp_client_list);
+}
+#endif
+//»ñÈ¡³ýwifi lan¿ÚÐÅÏ¢: Óëwifi·Ö¿ªµÄÔÒò£¬ÁÚ¾ÓÁбíºÍlease¶¼ÎÞ·¨Çø·ÖËÊÇwifi£¬Ö»ÓÐwifiоƬ֪µÀ
+void zte_get_lan_station_list(webs_t wp)
+{
+ struct pc_node *mypc_node;
+ DHCPOFFERADDR_LIST_t * list_head = NULL;
+ DHCPOFFERADDR_LIST_t * list_current = NULL;
+ char hostname[50] = {0};
+ char mac[18] = {0};
+ char mac_temp[18] = {0};
+ int result = 0;
+ int result1 = 0;
+ int i = 0;
+ BOOL first = TRUE;
+ struct list_head dhcp_info_list;
+ INIT_LIST_HEAD(&dhcp_info_list);
+
+ char eth_lan[NV_NAME_LEN] = {0};
+ char usb_lan[NV_NAME_LEN] = {0};
+ sc_cfg_get("ethlan", eth_lan, sizeof(eth_lan));
+ sc_cfg_get("usblan", usb_lan, sizeof(usb_lan));
+
+ web_feedback_header(wp);
+ (void)websWrite(wp, T("{\"%s\":["), CMD_LAN_STATION_LIST);
+
+ mypc_node = (struct pc_node*)malloc(sizeof(struct pc_node));
+ if (!mypc_node) {
+ slog(MISC_PRINT, SLOG_ERR, "malloc err");
+ (void)websWrite(wp, T("]}"));
+ return;
+ }
+
+ if (get_dev_list(mypc_node) < 0) {
+ (void)websWrite(wp, T("]}"));
+ safe_free(mypc_node);
+ return;
+ }
+ slog(MISC_PRINT, SLOG_DEBUG, "num: %d\n", mypc_node->num);
+
+ result1 = zte_get_mac_list_from_lease(&dhcp_info_list);
+
+ //if((-1 == result1) || (-2 == result1) || (-3 == result1) )
+ //{
+ // (void)websWrite(wp, T("]}"));
+ // safe_free(dhcp_info_list);
+ // return;
+ //}
+
+// if (0 == result) { // kw 3 result is 0
+ for (i = 0; i < mypc_node->num; i++) {
+ memset(mac, 0, sizeof(mac));
+ memset(hostname, 0, sizeof(hostname));
+ sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", \
+ mypc_node->info[i].mac_addr[0], mypc_node->info[i].mac_addr[1], \
+ mypc_node->info[i].mac_addr[2], mypc_node->info[i].mac_addr[3], \
+ mypc_node->info[i].mac_addr[4], mypc_node->info[i].mac_addr[5]);
+
+ if ((0 != strncmp(mypc_node->info[i].dev_name, eth_lan, strlen(eth_lan) - 1))\
+ && (0 != strncmp(mypc_node->info[i].dev_name, usb_lan, strlen(usb_lan) - 1)))
+ continue;
+
+ if (first == FALSE) {
+ (void)websWrite(wp, T(","));
+ } else {
+ first = FALSE;
+ }
+
+ list_for_each_entry(list_head, &dhcp_info_list, list) {
+ memset(mac_temp, 0, sizeof(mac_temp));
+ sprintf(mac_temp, "%02X:%02X:%02X:%02X:%02X:%02X", \
+ list_head->dhcp_info.mac[0], list_head->dhcp_info.mac[1], \
+ list_head->dhcp_info.mac[2], list_head->dhcp_info.mac[3], \
+ list_head->dhcp_info.mac[4], list_head->dhcp_info.mac[5]);
+
+ if (0 == strcmp(mac, mac_temp)) {
+ strcpy(hostname, list_head->dhcp_info.host_name);
+ break;
+ }
+ }
+
+ if (strlen(hostname)) {
+ (void)websWrite(wp, T("{\"%s\":\"%s\","), HOSTANME, hostname);
+ } else {
+ (void)websWrite(wp, T("{\"%s\":\"--\","), HOSTANME);
+ }
+ (void)websWrite(wp, T("\"%s\":\"%s\"}"), MAC_ADDR, mac);
+ }
+// }
+
+ free(mypc_node);
+
+ (void)websWrite(wp, T("]}"));
+#if 0
+ while (NULL != list_head) {
+ list_current = list_head;
+ list_head = list_head->next;
+ safe_free(list_current);
+ }
+#endif
+ free_dhcp_list(&dhcp_info_list);
+}
+
+void zte_add_children_device(webs_t wp)
+{
+ char *mac = NULL;
+ char mac_buf[18] = {0};
+ struct mac_hostname_info mac_hostname_info;
+ int result = 0;
+ struct list_head dhcp_info_list;
+ DHCPOFFERADDR_LIST_t * list_head = NULL;
+ DHCPOFFERADDR_LIST_t * list_current = NULL;
+ INIT_LIST_HEAD(&dhcp_info_list);
+ mac = websGetVar(wp, T("mac"), T(""));
+
+ if ((!mac) || (strlen(mac) != 17)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+ strncpy(mac_hostname_info.mac, mac,sizeof(mac_hostname_info.mac)-1);
+ memset(mac_hostname_info.hostname, 0, sizeof(mac_hostname_info.hostname));
+
+ //´Óudhcpd.leaseÎļþÖжÁÈ¡ÖÕ¶ËÉ豸ÐÅÏ¢
+ //ÕÒµ½macµØÖ·¶ÔÓ¦µÄhostname
+ result = zte_get_mac_list_from_lease(&dhcp_info_list);
+ if (result < 0) {
+ zte_write_result_to_web(wp, FAILURE);
+ free_dhcp_list(&dhcp_info_list);
+ return;
+ }
+
+ if (0 == result) {
+ list_for_each_entry(list_head, &dhcp_info_list, list) {
+ sprintf(mac_buf, "%02X:%02X:%02X:%02X:%02X:%02X", \
+ list_head->dhcp_info.mac[0], list_head->dhcp_info.mac[1], \
+ list_head->dhcp_info.mac[2], list_head->dhcp_info.mac[3], \
+ list_head->dhcp_info.mac[4], list_head->dhcp_info.mac[5]);
+
+ if (0 == strcmp(mac_hostname_info.mac, mac_buf)) {
+ strcpy(mac_hostname_info.hostname, list_head->dhcp_info.host_name);
+ break;
+ }
+ memset(mac_buf, 0, sizeof(mac_buf));
+ }
+ }
+
+ if (0 == strlen(mac_hostname_info.hostname)) {
+ sprintf(mac_hostname_info.hostname, "%s", "--");
+ }
+#if 0
+ while (NULL != list_head) {
+ list_current = list_head;
+ list_head = list_head->next;
+ safe_free(list_current);
+ }
+#endif
+ free_dhcp_list(&dhcp_info_list);
+
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_add_children_device SEND MESSAGE TO MC START"); /*lint !e26*/
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_ADD_CHILDREN_DEVICE, sizeof(struct mac_hostname_info), (UCHAR *)&mac_hostname_info, 0);
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_add_children_device SEND MESSAGE TO MC END"); /*lint !e26*/
+ Sleep(1);
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+void zte_del_children_device(webs_t wp)
+{
+ char *mac = NULL;
+ mac = websGetVar(wp, T("mac"), T(""));
+
+ if ((!mac) || (strlen(mac) != 17)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_del_children_device SEND MESSAGE TO MC START"); /*lint !e26*/
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_DEL_CHILDREN_DEVICE, strlen(mac), (UCHAR *)mac, 0);
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_del_children_device SEND MESSAGE TO MC END"); /*lint !e26*/
+ Sleep(1);
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+void zte_add_white_site(webs_t wp)
+{
+ char *name = NULL;
+ char *site = NULL;
+ struct white_site_info white_site;
+
+ name = websGetVar(wp, T("name"), T(""));
+ site = websGetVar(wp, T("site"), T(""));
+ slog(NET_PRINT, SLOG_DEBUG, "zte_add_white_site:name= %s, site = %s\n", name, site);
+ if (!name) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+ if (!site || !strlen(site)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ strncpy(white_site.name, name, sizeof(white_site.name)-1);
+ strncpy(white_site.site, site, sizeof(white_site.site)-1);
+
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_add_white_site SEND MESSAGE TO MC START"); /*lint !e26*/
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_ADD_WHITE_SITE, sizeof(struct white_site_info), (UCHAR *)&white_site, 0);
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_add_white_site SEND MESSAGE TO MC END"); /*lint !e26*/
+ Sleep(1);
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+void zte_remove_white_site(webs_t wp)
+{
+ char *ids = NULL;
+ ids = websGetVar(wp, T("ids"), T(""));
+
+ if (!ids || !strlen(ids)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_remove_white_site SEND MESSAGE TO MC START"); /*lint !e26*/
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_REMOVE_WHITE_SITE, strlen(ids), (UCHAR *)ids, 0);
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_remove_white_site SEND MESSAGE TO MC END"); /*lint !e26*/
+ Sleep(1);
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+void zte_get_children_device_list(webs_t wp)
+{
+ slog(NET_PRINT, SLOG_NORMAL, "zte_get_children_device_list start!\n");
+ FILE *chilren_device_file = NULL;
+ char line[200] = {0};
+ char mac[18] = {0};
+ char hostname[150] = {0};
+
+ BOOL first = TRUE;
+
+ char path_conf[50] = {0};
+ char path_file[100] = {0};
+ sc_cfg_get("path_conf", path_conf, sizeof(path_conf));
+ sprintf(path_file, "%s/children_device_file", path_conf);
+
+ web_feedback_header(wp);
+ zte_rest_cmd_write_head(wp);
+ (void)websWrite(wp, T("\"%s\":["), DEVICES);
+ chilren_device_file = fopen(path_file, "r");
+ if (chilren_device_file == NULL) {
+ slog(MISC_PRINT, SLOG_ERR, "can not open file children_device_file.");
+ goto out;
+ }
+
+ while (fgets(line, sizeof(line), chilren_device_file) != NULL) {
+ if (first == FALSE) {
+ (void)websWrite(wp, T(","));
+ } else {
+ first = FALSE;
+ }
+
+ strncpy(mac, line, sizeof(mac)-1);
+ if(strlen(line) - 19 > 0 && strlen(line) - 19 < 150)
+ snprintf(hostname,strlen(line) - 18,"%s",line + 18);
+ //strncpy(hostname, line + 18, strlen(line) - 19);
+
+ if (strncmp(mac, "", sizeof(mac)) != 0 && strncmp(hostname, "", sizeof(hostname)) != 0) {
+ (void)websWrite(wp, T("{\"%s\":\"%s\",\"%s\":\"%s\"}"), HOSTANME, hostname, MAC, mac);
+ }
+
+ memset(line, 0, sizeof(line));
+ memset(mac, 0, sizeof(mac));
+ memset(hostname, 0, sizeof(hostname));
+
+ }
+ fclose(chilren_device_file);
+
+out:
+ (void)websWrite(wp, T("]"));
+ zte_rest_cmd_write_foot(wp);
+}
+
+void zte_get_white_site_list(webs_t wp)
+{
+ slog(NET_PRINT, SLOG_ERR, "zte_get_white_site_list start!\n");
+ FILE *white_site_file = NULL;
+ char line[600] = {0};
+ unsigned int id = 1;
+ char name[150] = {0};
+ char site[400] = {0};
+ unsigned int len = 0;
+
+ BOOL first = TRUE;
+
+ char path_conf[50] = {0};
+ char path_file[100] = {0};
+ sc_cfg_get("path_conf", path_conf, sizeof(path_conf));
+ sprintf(path_file, "%s/white_site_file", path_conf);
+
+ web_feedback_header(wp);
+ zte_rest_cmd_write_head(wp);
+ (void)websWrite(wp, T("\"%s\":["), SITELIST);
+ white_site_file = fopen(path_file, "r");
+ if (white_site_file == NULL) {
+ slog(MISC_PRINT, SLOG_ERR, "can not open file white_site_file.");
+ goto out;
+ }
+
+ while (fgets(line, sizeof(line), white_site_file) != NULL) {
+ if (first == FALSE)
+ (void)websWrite(wp, T(","));
+ else
+ first = FALSE;
+
+ int i = 0;
+ for (i = 0; i < sizeof(line); i++) {
+ if (line[i] == ',') {
+ len = i;
+ break;
+ }
+ }
+ if(len < sizeof(site) && len > 0)
+ snprintf(site,len+1,"%s",line);
+ //strncpy(site, line, len);
+ //ÿÐж¼ÓÐÒ»¸ö'\n'
+ int name_len = strlen(line) - (len + 2);
+ if(len < 598 && name_len > 0 && name_len < 150)
+ snprintf(name,name_len+1,"%s",line + len + 1);
+ //strncpy(name, line + len + 1, name_len);
+ if (strcmp(site, "") != 0) {
+ (void)websWrite(wp, T("{\"%s\":\"%d\",\"%s\":\"%s\",\"%s\":\"%s\"}"), ID, id, NAME, name, SITE, site);
+ }
+
+ id = id + 1;
+ memset(line, 0, sizeof(line));
+ memset(name, 0, sizeof(name));
+ memset(site, 0, sizeof(site));
+ len = 0;
+
+ }
+
+ fclose(white_site_file);
+
+out:
+ (void)websWrite(wp, T("]"));
+ zte_rest_cmd_write_foot(wp);
+}
+
+//»ñÈ¡ÄÚÍøÐÅÏ¢
+void zte_get_lan_dev_info(webs_t wp)
+{
+ char_t *dev_name = NULL;
+ LAN_INFO_t lan_info;
+
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_get_lan_dev_info enter \n");
+ //ÏȽèÓÿª»úʱ¼ä°Ñ¿ò¼Ü´îºÃ, elseµÄÆ´½ÓÓÐÎÊÌ⣬ÔÝʱ²»Ìṩwebserver¸ø¿Í»§£¬
+ //´Ë¹¦ÄÜÓëstation_list/wifi_station_list¹¦ÄÜÓÐÖØµþ£¬ºóÐøÓÅ»¯³ÉͳһµÄ
+#if 1
+ unsigned long cur_time;
+
+ cur_time = time_sec();
+
+ web_feedback_header(wp);
+ zte_rest_cmd_write_head(wp);
+ zte_rest_cmd_write_int(wp, "poweron_time", cur_time, 0);
+ zte_rest_cmd_write_foot(wp);
+ slog(MISC_PRINT, SLOG_DEBUG,"zte_get_lan_dev_info cur_time:%lu \n", cur_time);
+#else
+ dev_name = websGetVar(wp, "dev_name", T(""));
+ printf(LOG_INFO, "zte_get_lan_dev_info dev:%s \n", dev_name);
+ if ('\0' == (*dev_name)) {
+ return;
+ }
+
+ if (get_laninfo_byname(dev_name, &lan_info) == -1)
+ return;
+
+ printf(LOG_INFO, "zte_get_lan_dev_info mac:%02x:%02x:%02x:%02x:%02x:%02x \n", lan_info.mac[0], lan_info.mac[1], lan_info.mac[2], lan_info.mac[3], lan_info.mac[4], lan_info.mac[5]);
+ printf(LOG_INFO, "zte_get_lan_dev_info ip:%lu, host:%s, dev:%s, remain:%d, last:%d \n", lan_info.ip, lan_info.host_name, lan_info.dev_name, lan_info.time_remain, lan_info.time_last);
+ web_feedback_header(wp);
+ zte_rest_cmd_write_head(wp);
+ zte_rest_cmd_write_int(wp, "mac", lan_info.mac, 1);
+ zte_rest_cmd_write_int(wp, "ip", lan_info.ip, 1);
+ zte_rest_cmd_write_int(wp, "host_name", lan_info.host_name, 1);
+ zte_rest_cmd_write_int(wp, "dev_name", lan_info.dev_name, 1);
+ zte_rest_cmd_write_int(wp, "time_remain", lan_info.time_remain, 1);
+ zte_rest_cmd_write_int(wp, "time_last", lan_info.time_last, 0);
+ zte_rest_cmd_write_foot(wp);
+#endif
+}
+
+
diff --git a/ap/app/goahead/interface5.0/net/zte_web_net_lan.h b/ap/app/goahead/interface5.0/net/zte_web_net_lan.h
new file mode 100644
index 0000000..95db708
--- /dev/null
+++ b/ap/app/goahead/interface5.0/net/zte_web_net_lan.h
@@ -0,0 +1,29 @@
+#ifndef ZTE_WEB_NET_LAN_H
+#define ZTE_WEB_NET_LAN_H
+#include "webs.h"
+
+extern void zte_dhcpv6_state_set(webs_t wp);
+extern void quick_dhcp_set(webs_t wp);
+extern void zte_dhcp_set(webs_t wp);
+extern void zte_static_dhcp_set(webs_t wp);
+
+extern void zte_set_bind_static_address(webs_t wp);
+extern void zte_bind_static_address_add(webs_t wp);
+extern void zte_bind_static_address_del(webs_t wp);
+extern void zte_get_current_static_addr_list(webs_t wp);
+
+extern void zte_get_lan_station_list(webs_t wp);
+
+extern void zte_add_children_device(webs_t wp);
+extern void zte_del_children_device(webs_t wp);
+
+extern void zte_add_white_site(webs_t wp);
+extern void zte_remove_white_site(webs_t wp);
+
+extern void zte_get_children_device_list(webs_t wp);
+extern void zte_get_white_site_list(webs_t wp);
+
+
+
+#endif
+
diff --git a/ap/app/goahead/interface5.0/net/zte_web_net_other.c b/ap/app/goahead/interface5.0/net/zte_web_net_other.c
new file mode 100755
index 0000000..de459aa
--- /dev/null
+++ b/ap/app/goahead/interface5.0/net/zte_web_net_other.c
@@ -0,0 +1,385 @@
+#include "zte_web_net_other.h"
+#include "../wifi/zte_web_lan_utils.h"
+#include "zte_web_mgmt.h"
+#include "wifi.h"
+
+#include <stdlib.h>
+//#include <linux/wireless.h>
+#include <sys/ioctl.h>
+#include "message.h"
+#include "softap_api.h"
+
+#define NV_MACIP_LIST_MAX_LEN 500
+
+#define safe_free(x) do { if(x) {free(x); x=NULL;} } while(0)
+
+//extern void zte_get_wifi_sta_list(RT_802_11_MAC_TABLE *staList);
+
+//¼ì²âijIPµØÖ·ÊÇ·ñΪÓû§¾²Ì¬ÉèÖõÄÖÕ¶ËIPµØÖ·
+BOOL zte_is_static_dhcp_ip(char *ipAddr)
+{
+ char list[NV_MACIP_LIST_MAX_LEN] = {0};
+
+ sc_cfg_get("mac_ip_list", list, sizeof(list));
+ if (strlen(list) == 0) {
+ return FALSE;
+ }
+
+ if (strstr(list, ipAddr) == NULL) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+//ÓÃÓÚ¼ì²âÊÇ·ñΪUSBµÄMACµØÖ·
+static BOOL zte_is_usb_mac(unsigned char mac[])
+{
+ /*
+ char mac0[3] = {0};
+ char mac1[3] = {0};
+ char mac2[3] = {0};
+
+ sprintf(mac0, "%02X", mac[0]);
+ sprintf(mac1, "%02X", mac[1]);
+ sprintf(mac2, "%02X", mac[2]);
+ */
+
+ BOOL ret = TRUE;
+ int i;
+ size_t read_len = 0;
+
+ FILE *usb_mac_file = NULL;
+ unsigned char usb_mac[7] = {0};
+
+ usb_mac_file = fopen("/var/usbmac", "r");
+ if (usb_mac_file != NULL) {
+ read_len = fread(usb_mac, sizeof(usb_mac[0]), 7, usb_mac_file);
+ if(read_len != 7)
+ {
+ slog(MISC_PRINT, SLOG_DEBUG, "read len :%d \n", read_len);
+ }
+ fclose(usb_mac_file);
+ }
+
+ //printf("zte_is_usb_mac stored usbmac %x %x %x %x %x %x\n",usb_mac[0],usb_mac[1],usb_mac[2],usb_mac[3],usb_mac[4],usb_mac[5]);
+ //printf("zte_is_usb_mac lease mac %x %x %x %x %x %x\n",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
+
+ for (i = 0; i < 6; i++) {
+
+ if (usb_mac[i] != mac[i]) {
+ ret = FALSE;
+ break;
+ }
+ }
+
+ /*
+ if (strcmp(mac0, "00") == 0 && strcmp(mac1, "A0") == 0 && strcmp(mac2, "C6") == 0)
+ {
+ fprintf(stderr, "current mac is from usb");
+ return TRUE;
+ }
+ */
+
+ return ret;
+}
+
+//MTU ÉèÖÃ
+void zte_mtu_set(webs_t wp)
+{
+ char_t *new_mtu = NULL;
+
+ new_mtu = websGetVar(wp, T("mtu"), T(""));
+
+ if ('\0' == (*new_mtu)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_mtu_set new_mtu= %s\n", new_mtu);
+
+ (void)zte_web_write("mtu", new_mtu);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_mtu_set MESSAGE TO MC START");
+ //zte_send_message(MODULE_ID_MAIN_CTRL, MSG_CMD_NET_MTU, 0, 0);
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_MTU, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_mtu_set MESSAGE TO MC END");
+
+ //sc_cfg_save();
+
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+//ÉèÖÃÊÖ¶¯DNS mode
+/*void zte_dns_mode_set(webs_t wp)
+{
+ char_t *pswan_dns_mode = NULL;
+ char_t *pswan_ipv6_dns_mode = NULL;
+
+ pswan_dns_mode = websGetVar(wp, T("pswan_dns_mode"), T(""));
+ pswan_ipv6_dns_mode = websGetVar(wp, T("pswan_ipv6_dns_mode"), T(""));
+
+ if ('\0' == (*pswan_dns_mode) && '\0' == (*pswan_ipv6_dns_mode))
+ {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ if (('\0' != (*pswan_dns_mode) && strcmp(pswan_dns_mode, "auto") && strcmp(pswan_dns_mode, "manual"))
+ || ('\0' != (*pswan_ipv6_dns_mode) && strcmp(pswan_ipv6_dns_mode, "auto") && strcmp(pswan_ipv6_dns_mode, "manual")))
+ {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ if ('\0' != (*pswan_dns_mode))
+ (void)zte_web_write("pswan_dns_mode", pswan_dns_mode);
+
+ if ('\0' != (*pswan_ipv6_dns_mode))
+ (void)zte_web_write("pswan_ipv6_dns_mode", pswan_ipv6_dns_mode);
+
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+*/
+//ÉèÖÃÊÖ¶¯DNS server --- ÔÝʱֻ֧³Öpswan¿Ú
+/*void zte_dns_server_set(webs_t wp)
+{
+ char_t *pswan_pridns = NULL;
+ char_t *pswan_secdns = NULL;
+ char_t *pswan_ipv6_pridns = NULL;
+ char_t *pswan_ipv6_secdns = NULL;
+
+ pswan_pridns = websGetVar(wp, T("pswan_pridns_manual"), T(""));
+ pswan_secdns = websGetVar(wp, T("pswan_secdns_manual"), T(""));
+ pswan_ipv6_pridns = websGetVar(wp, T("pswan_ipv6_pridns_manual"), T(""));
+ pswan_ipv6_secdns = websGetVar(wp, T("pswan_ipv6_secdns_manual"), T(""));
+
+ printf("zte_dns_server_set: %s - %s - %s - %s \n", pswan_pridns, pswan_secdns, pswan_ipv6_pridns, pswan_ipv6_secdns);
+
+ if ('\0' == (*pswan_pridns) && '\0' == (*pswan_secdns) && '\0' == (*pswan_ipv6_pridns) && '\0' == (*pswan_ipv6_secdns))
+ {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ //ÉèÖÃÁ˵ØÖ·£¬µ«ÊÇÊÇ´íÎóµÄ
+ if (('\0' != (*pswan_pridns) && !isIpValid(pswan_pridns))
+ || ('\0' != (*pswan_secdns) && !isIpValid(pswan_secdns))
+ || ('\0' != (*pswan_ipv6_pridns) && !isIpv6Valid(pswan_ipv6_pridns))
+ || ('\0' != (*pswan_ipv6_secdns) && !isIpv6Valid(pswan_ipv6_secdns)))
+ {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ if ('\0' != (*pswan_pridns))
+ (void)zte_web_write("pswan_pridns_manual", pswan_pridns);
+ if ('\0' != (*pswan_secdns))
+ (void)zte_web_write("pswan_secdns_manual", pswan_secdns);
+ if ('\0' != (*pswan_ipv6_pridns))
+ (void)zte_web_write("pswan_ipv6_pridns_manual", pswan_ipv6_pridns);
+ if ('\0' != (*pswan_ipv6_secdns))
+ (void)zte_web_write("pswan_ipv6_secdns_manual", pswan_ipv6_secdns);
+
+ //sc_cfg_save();
+
+ zte_write_result_to_web(wp, SUCCESS);
+}
+*/
+
+//±à¼²¢±£´æMACºÍ¶ÔÓ¦µÄÖ÷»úÃû
+void zte_edit_hostname(webs_t wp)
+{
+ char_t *mac = NULL;
+ char_t *hostname = NULL;
+ struct mac_hostname_info mac_hostname_info;
+
+ mac = websGetVar(wp, T("mac"), T(""));
+ hostname = websGetVar(wp, T("hostname"), T(""));
+
+ slog(NET_PRINT, SLOG_ERR, "zte_edit_hostname:mac= %s, hostname = %s\n£¬len=%d", mac, hostname, strlen(hostname));
+ if ((strcmp(hostname, "") == 0) || (strlen(mac) != 17)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ strncpy(mac_hostname_info.mac, mac,sizeof(mac_hostname_info.mac)-1);
+ strncpy(mac_hostname_info.hostname, hostname,sizeof(mac_hostname_info.hostname)-1);
+
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_edit_hostname MESSAGE TO MC START");
+ //zte_send_message(MODULE_ID_MAIN_CTRL, MSG_CMD_NET_GET_HOSTNAME, sizeof(struct mac_hostname_info), (UCHAR *)&mac_hostname_info);
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_GET_HOSTNAME, sizeof(struct mac_hostname_info), (UCHAR *)&mac_hostname_info, 0);
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_edit_hostname MESSAGE TO MC END");
+ Sleep(2);
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+//´ÓÎļþÖжÁÈ¡MACºÍ¶ÔÓ¦µÄÖ÷»úÃû²¢ÏÔʾÔÚwebui
+void zte_get_hostnamelist(webs_t wp)
+{
+ FILE *hostname_mac_file = NULL;
+ char line[200] = {0};
+ char line_mac[18] = {0};
+ char line_hostname[150] = {0};
+
+ BOOL first = TRUE;
+
+ char path_conf[50] = {0};
+ char path_file[100] = {0};
+ sc_cfg_get("path_conf", path_conf, sizeof(path_conf));
+ sprintf(path_file, "%s/hostname_mac_file", path_conf);
+
+ web_feedback_header(wp);
+ zte_rest_cmd_write_head(wp);
+ (void)websWrite(wp, T("\"%s\":["), DEVICES);
+ hostname_mac_file = fopen(path_file, "r");
+ if (hostname_mac_file == NULL) {
+ slog(MISC_PRINT, SLOG_ERR, "can not open file hostname_mac_file.");
+ goto out;
+ }
+
+ while (fgets(line, 200, hostname_mac_file) != NULL) {
+ if (first == FALSE) {
+ (void)websWrite(wp, T(","));
+ } else {
+ first = FALSE;
+ }
+ strncpy(line_mac, line, 17);
+ if((strlen(line) - 19) < 150)
+ snprintf(line_hostname,strlen(line) -18,"%s",line + 18);
+ //strncpy(line_hostname, line + 18, strlen(line) - 19);
+ if (strncmp(line_mac, "", sizeof(line_mac)) != 0 && strncmp(line_hostname, "", sizeof(line_hostname)) != 0) {
+ (void)websWrite(wp, T("{\"%s\":\"%s\",\"%s\":\"%s\"}"), HOSTANME, line_hostname, MAC, line_mac);
+ }
+
+ memset(line, 0, sizeof(line));
+ memset(line_mac, 0, sizeof(line_mac));
+ memset(line_hostname, 0, sizeof(line_hostname));
+
+ }
+ fclose(hostname_mac_file);
+
+out:
+ (void)websWrite(wp, T("]"));
+ zte_rest_cmd_write_foot(wp);
+}
+
+/* * check the existence of semicolon in str */
+int checkSemicolon(char *str)
+{
+ char *c = strchr(str, ';');
+ if (c)
+ return 1;
+ return 0;
+}
+
+void zte_goform_ddns(webs_t wp)
+{
+
+ char *ddns_provider, *ddns, *DDNS_Hash_Value, *ddns_acc, *ddns_pass, *DDNS_Enable, *DDNS_Mode;
+ //char empty_char = '\0';
+
+ DDNS_Enable = websGetVar(wp, T("DDNS_Enable"), T("1"));
+ DDNS_Mode = websGetVar(wp, T("DDNS_Mode"), T("manual"));
+ ddns_provider = websGetVar(wp, T("DDNSProvider"), T("none"));
+ ddns = websGetVar(wp, T("DDNS"), T(""));
+ DDNS_Hash_Value = websGetVar(wp, T("DDNS_Hash_Value"), T(""));
+ ddns_acc = websGetVar(wp, T("DDNSAccount"), T(""));
+ ddns_pass = websGetVar(wp, T("DDNSPassword"), T(""));
+
+ if (strcmp(DDNS_Enable, "0")) { //disable
+ if (!ddns_provider || !ddns || !ddns_acc || !ddns_pass) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+ if (!strcmp(T("none"), ddns_provider)) {
+ //ddns = ddns_acc = ddns_pass = DDNS_Hash_Value = T("");//&empty_char;//cov
+ } else {
+ if (!strlen(ddns) || !strlen(ddns_acc) || !strlen(ddns_pass)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+ }
+
+ if (checkSemicolon(ddns) || checkSemicolon(ddns_acc) || checkSemicolon(ddns_pass)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+ sc_cfg_set("DDNS_Mode", DDNS_Mode);
+ sc_cfg_set("DDNSProvider", ddns_provider);
+ if(!strcmp(T("none"), ddns_provider))// kw OVERWRITE_CONST_CHAR
+ {
+ sc_cfg_set("DDNS", "");
+ sc_cfg_set("DDNS_Hash_Value", "");
+ sc_cfg_set("DDNSAccount", "");
+ sc_cfg_set("DDNSPassword", "");
+ }
+ else
+ {
+ sc_cfg_set("DDNS", ddns);
+ sc_cfg_set("DDNS_Hash_Value", DDNS_Hash_Value);
+ sc_cfg_set("DDNSAccount", ddns_acc);
+ sc_cfg_set("DDNSPassword", ddns_pass);
+ }
+ }
+ sc_cfg_set("DDNS_Enable", DDNS_Enable);
+ //sc_cfg_save();
+
+ system("ddns.sh");
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+//parent control nv set
+void zte_parent_control_set(webs_t wp)
+{
+ char* time_limited = NULL;
+ char old_time_limited[512] = {0};
+ sc_cfg_get("time_limited", old_time_limited, sizeof(old_time_limited));
+ time_limited = websGetVar(wp, T("time_limited"), T(""));
+ slog(MISC_PRINT, SLOG_DEBUG,"[%s]time_limited=%s,old_time_limited=%s\n", __FUNCTION__, time_limited, old_time_limited);
+
+ //parent control time has no open/close button,so if time_limited is null,
+ //means close , if time_limited is not null, means set
+#if 0
+ if (time_limited == NULL || *time_limited == '\0') {
+ printf("zte_parent_control_set: invalid input para\n");/*lint !e26*/
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+#endif
+
+ if (strcmp(time_limited, old_time_limited) == 0) {
+ slog(MISC_PRINT, SLOG_NORMAL,"[%s]para not changed\n", __FUNCTION__); /*lint !e26*/
+ zte_write_result_to_web(wp, SUCCESS);
+ return;
+ } else {
+ sc_cfg_set("time_limited", time_limited);
+ if (strcmp(time_limited, "") == 0) {
+ slog(MISC_PRINT, SLOG_NORMAL,"[%s]send to parent control set : MSG_CMD_PARENT_CONTROL_CLOSE\n", __FUNCTION__);
+ //zte_send_message(MODULE_ID_PARENT_CONTROL_SET,MSG_CMD_PARENT_CONTROL_CLOSE,0,NULL);
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_PARENT_CONTROL_SET, MSG_CMD_PARENT_CONTROL_CLOSE, 0, NULL, 0);
+ } else {
+ slog(MISC_PRINT, SLOG_NORMAL,"[%s]send to parent control set : MSG_CMD_PARENT_CONTROL_SET\n", __FUNCTION__);
+ //zte_send_message(MODULE_ID_PARENT_CONTROL_SET,MSG_CMD_PARENT_CONTROL_SET,0,NULL);
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_PARENT_CONTROL_SET, MSG_CMD_PARENT_CONTROL_SET, 0, NULL, 0);
+ }
+ }
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+//¿ª»úʱ¼ä
+void zte_get_poweron_time(webs_t wp)
+{
+ unsigned long cur_time;
+
+ slog(MISC_PRINT, SLOG_NORMAL,"zte_get_poweron_time enter \n");
+
+ cur_time = time_sec();
+
+ web_feedback_header(wp);
+ zte_rest_cmd_write_head(wp);
+ zte_rest_cmd_write_int(wp, "poweron_time", cur_time, 0);
+ zte_rest_cmd_write_foot(wp);
+ slog(MISC_PRINT, SLOG_DEBUG,"zte_get_poweron_time cur_time:%lu \n", cur_time);
+}
+
diff --git a/ap/app/goahead/interface5.0/net/zte_web_net_other.h b/ap/app/goahead/interface5.0/net/zte_web_net_other.h
new file mode 100644
index 0000000..fce8ddd
--- /dev/null
+++ b/ap/app/goahead/interface5.0/net/zte_web_net_other.h
@@ -0,0 +1,47 @@
+#ifndef ZTE_WEB_NET_OTHER_H
+#define ZTE_WEB_NET_OTHER_H
+//#include "zte_web_lan_utils.h"
+//#include "zte_web_mgmt.h"
+//#include "zte_web_net_xfrm.h"
+#include <stdlib.h>
+#include "webs.h"
+#include "wifi.h"
+
+#ifndef BOOL
+
+#define BOOL unsigned char
+#endif
+
+
+//extern void zte_get_mac_list(webs_t wp);
+//extern void zte_get_mac_list_network(webs_t wp);
+
+/*zhangpeimin 20160427 begin
+typedef struct _DHCPOFFERADDR_LIST
+{
+ DHCPOFFERADDR dhcp_info;
+ struct _DHCPOFFERADDR_LIST *next;
+
+} DHCPOFFERADDR_LIST_t;
+zhangpeimin 20160427 end*/
+static BOOL zte_is_usb_mac(unsigned char mac[]);
+extern void zte_mtu_set(webs_t wp);
+extern void zte_dns_mode_set(webs_t wp);
+//extern void zte_dns_server_set(webs_t wp);
+extern void zte_ping_diagnostics_start(webs_t wp);
+extern void zte_ping_diagnostics_stop(webs_t wp);
+extern void zte_get_poweron_time(webs_t wp);
+extern void zte_get_lan_dev_info(webs_t wp);
+extern void zte_edit_hostname(webs_t wp);
+extern void zte_get_hostnamelist(webs_t wp);
+//int zte_get_mac_list_from_lease(DHCPOFFERADDR_LIST_t **dhcpInfo_list);
+BOOL zte_is_static_dhcp_ip(char *ipAddr);
+
+//һϼ¸¸öº¯ÊýĿǰ²»µ÷Ó㬺¯ÊýÌåΪ¿Õ
+//extern void zte_get_mac_list_ap2_network(webs_t wp,int sta_num_1);
+//extern void zte_reset_mac_list();
+extern void zte_goform_ddns(webs_t wp);
+
+
+
+#endif
diff --git a/ap/app/goahead/interface5.0/net/zte_web_net_wan.c b/ap/app/goahead/interface5.0/net/zte_web_net_wan.c
new file mode 100755
index 0000000..8cea5ac
--- /dev/null
+++ b/ap/app/goahead/interface5.0/net/zte_web_net_wan.c
@@ -0,0 +1,1813 @@
+#include "zte_web_interface.h"
+#include "zte_web_net_wan.h"
+#include "zte_web_get_fw_para.h"
+#include "message.h"
+
+#define IP_VERSION_V4 "ipv4"
+#define IP_VERSION_V6 "ipv6"
+
+//======================Global Constants=============================//
+static char wan_if_name[20] = {0}; /* default is ppp0 */
+
+//==============================Util================================//
+static int isMacValid(char *str)
+{
+ int i, len = strlen(str);
+ if (len != 17)
+ return 0;
+
+ for (i = 0; i < 5; i++) {
+ if ((!isxdigit(str[i * 3])) || (!isxdigit(str[i * 3 + 1])) || (str[i * 3 + 2] != ':'))
+ return 0;
+ }
+ return (isxdigit(str[15]) && isxdigit(str[16])) ? 1 : 0;
+}
+
+int isIpValid(char *str)
+{
+ struct in_addr addr; // for examination/*lint !e1080 !565 */
+ if ((! strcmp(T("any"), str)) || (! strcmp(T("any/0"), str)))
+ return 1;
+#ifdef WEBS_SECURITY
+ int len = strlen(str);
+ len--;
+ while(len > 0)
+ {
+ len--;
+ if(str[len] == '0' && str[len+1] >= '0')
+ {
+ if(len == 0 || (len > 1 && str[len-1] == '.'))
+ return 0;
+ }
+ }
+#endif
+ if (!(inet_aton(str, &addr))) {
+ slog(MISC_PRINT, SLOG_ERR, "isIpValid(): %s is not a valid IP address.\n", str); /*lint !e26*/
+ return 0;
+ }
+ return 1;
+}
+
+int isIpv6Valid(char *str)
+{
+ int ret = 0;
+ struct in6_addr ipv6_addr;
+
+ if ((! strcmp(T("any"), str)) || (! strcmp(T("any/0"), str)))
+ return 1;
+
+ ret = inet_pton(AF_INET6, str, &ipv6_addr);
+ if (ret < 1) {
+ slog(MISC_PRINT, SLOG_ERR,"isIpv6Valid: str inet_pton failed: %d \n", ret);
+ return 0;
+ }
+ return 1;
+}
+
+static int isNumOnly(char *str)
+{
+ int i, len = strlen(str);
+ for (i = 0; i < len; i++) {
+ if ((str[i] >= '0' && str[i] <= '9'))
+ continue;
+ return 0;
+ }
+ return 1;
+}
+
+static int isAllNumAndSlash(char *str)
+{
+ int i, len = strlen(str);
+ for (i = 0; i < len; i++) {
+ if ((str[i] >= '0' && str[i] <= '9') || str[i] == '.' || str[i] == '/')
+ continue;
+ return 0;
+ }
+ return 1;
+}
+
+static int isOnlyOneSlash(char *str)
+{
+ int i, count = 0;
+ int len = strlen(str);
+ for (i = 0; i < len; i++)
+ if (str[i] == '/')
+ count++;
+ return count <= 1 ? 1 : 0;
+}
+
+static int isIpNetmaskValid(char *s)
+{
+ char str[32]={0};
+ char *slash;
+ struct in_addr addr; // for examination/*lint !e1080*/
+
+ if (!s || !strlen(s)) {
+ return 0;
+ }
+
+ strncpy(str, s, sizeof(str)-1);
+
+ if ((!strcmp("any", str)) || (!strcmp("any/0", str)))
+ return 1;
+
+ if (!isAllNumAndSlash(str)) {
+ return 0;
+ }
+
+ if (!isOnlyOneSlash(str)) {
+ return 0;
+ }
+
+ slash = strchr(str, '/');
+ if (slash) {
+ int mask;
+
+ *slash = '\0';
+ slash++;
+ if (!strlen(slash)) {
+ return 0;
+ }
+
+ if (!isNumOnly(slash)) {
+ return 0;
+ }
+
+ mask = atoi(slash);
+ if (mask < 0 || mask > 32) {
+ return 0;
+ }
+ }
+
+ if (!(inet_aton(str, &addr))) {
+ slog(MISC_PRINT, SLOG_ERR, "isIpNetmaskValid(): %s is not a valid IP address.\n", str); /*lint !e26*/
+ return 0;
+ }
+ return 1;
+}
+
+static int getNums(char *value, char delimit)
+{
+
+ char *pos = value;
+
+ int count = 1;
+ if (!pos)
+ return 0;
+ while ((pos = strchr(pos, delimit))) {
+
+ pos = pos + 1;
+
+ count++;
+
+ }
+
+ return count;
+}
+
+static int getRuleNums(char *rules)
+{
+
+ return getNums(rules, ';');
+}
+
+
+
+/*
+ * argument: [IN] index -- the index array of deleted items(begin from 0)
+ * [IN] count -- deleted itmes count.
+ * [IN/OUT] value -- original string/return string
+ * [IN] delimit -- delimitor
+ */
+static int static_deleteNthValueMulti(int index[], int count, char *value, char delimit)
+{
+ char *begin, *end;
+ int i = 0, j = 0;
+ int need_check_flag = 0;
+ char *buf = strdup(value);
+
+ if(buf == NULL)
+ return 0;
+ *(buf+strlen(value)) = 0;
+ begin = buf;
+
+ end = strchr(begin, delimit);
+ while (end) {
+ if (i == index[j]) {
+ memset(begin, 0, end - begin);
+ if (index[j] == 0)
+ need_check_flag = 1;
+ j++;
+ if (j >= count)
+ break;
+ }
+ begin = end;
+
+ end = strchr(begin + 1, delimit);
+ i++;
+ }
+
+ if (!end && index[j] == i)
+ memset(begin, 0, strlen(begin));
+
+ if (need_check_flag) {
+ for (i = 0; i < strlen(value); i++) {
+ if (buf[i] == '\0')
+ continue;
+ if (buf[i] == ';')
+ buf[i] = '\0';
+ break;
+ }
+ }
+
+ for (i = 0, j = 0; i < strlen(value) && j < 1023; i++) {
+ if (buf[i] != '\0') {
+ value[j++] = buf[i];
+ }
+ }
+ value[j] = '\0';
+
+ free(buf);
+ return 0;
+}
+
+/*
+ * substitution of getNthValue which dosen't destroy the original value
+ */
+static int static_getNthValueSafe(int index, char *value, char delimit, char *result, int len)
+{
+ int i = 0, result_len = 0;
+ char *begin, *end;
+
+ if (!value || !result || !len)
+ return -1;
+
+ begin = value;
+ end = strchr(begin, delimit);
+
+ while (i < index && end) {
+ begin = end + 1;
+ end = strchr(begin, delimit);
+ i++;
+ }
+
+ //no delimit
+ if (!end) {
+ if (i == index) {
+ end = begin + strlen(begin);
+ result_len = (len - 1) < (end - begin) ? (len - 1) : (end - begin);
+ } else
+ return -1;
+ } else
+ result_len = (len - 1) < (end - begin) ? (len - 1) : (end - begin);
+
+ memcpy(result, begin, result_len);
+ *(result + result_len) = '\0';
+
+ return 0;
+}
+
+/*************************** firewallÏà¹Ø ***************************/
+
+/*IP¡¢PORTµÈ·À»ðǽµÄwebÒ³Ãæ»ù±¾ÅäÖÃ*/
+void zte_fw_basic_setting(webs_t wp)
+{
+ char *firewall_enable = NULL; /* 0: Disabled 1: Enabled */
+ char *default_policy = NULL; /* 0: Accepted 1: Dropped */
+
+ firewall_enable = websGetVar(wp, T("portFilterEnabled"), T("0"));
+ default_policy = websGetVar(wp, T("defaultFirewallPolicy"), T("0"));
+
+ switch (atoi(firewall_enable)) {
+ case 0:
+ (void)zte_web_write("IPPortFilterEnable", "0"); /* Disable */
+ slog(MISC_PRINT, SLOG_DEBUG, T("UFIx User disable port filtering!\n"));
+ break;
+ case 1:
+ (void)zte_web_write("IPPortFilterEnable", "1"); /* Enable */
+ slog(MISC_PRINT, SLOG_DEBUG, T("UFIx User enable port filtering!\n"));
+ break;
+ default:
+ (void)zte_web_write("IPPortFilterEnable", "0"); /* Accepted */
+ break;
+ }
+
+ switch (atoi(default_policy)) {
+ case 1:
+ (void)zte_web_write("DefaultFirewallPolicy", "1"); /* Dropped */
+ break;
+ case 0:
+ default:
+ (void)zte_web_write("DefaultFirewallPolicy", "0"); /* Accepted */
+ break;
+ }
+
+ //zte_iptables_basic_setting();
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_fw_basic_setting SEND MESSAGE TO MC START"); /*lint !e26*/
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_FILTER, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_fw_basic_setting SEND MESSAGE TO MC END"); /*lint !e26*/
+
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+/*¶Ë¿Úת·¢web»ù±¾ÅäÖÃ*/
+void zte_fw_forward_setting(webs_t wp)
+{
+ char *firewall_enable = NULL; /* 0: Disabled 1: Enabled */
+
+ firewall_enable = websGetVar(wp, T("PortForwardEnable"), T("0"));
+
+ switch (atoi(firewall_enable)) {
+ case 0:
+ (void)zte_web_write("PortForwardEnable", "0"); /* Disable */
+ slog(MISC_PRINT, SLOG_DEBUG, T("UFIx User disable port forward!\n"));
+ break;
+ case 1:
+ (void)zte_web_write("PortForwardEnable", "1"); /* Enable */
+ slog(MISC_PRINT, SLOG_DEBUG, T("UFIx User enable port forward!\n"));
+ break;
+ default:
+ (void)zte_web_write("PortForwardEnable", "0"); /* Accepted */
+ break;
+ }
+
+ //zte_iptables_basic_setting();
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_fw_forward_setting SEND MESSAGE TO MC START"); /*lint !e26*/
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_FORWARD, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_fw_forward_setting SEND MESSAGE TO MC END"); /*lint !e26*/
+
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+/*·À»ðǽÖÐÍâÍø¿Ú¶¨ÖƹæÔò£¬ÊôÓÚ·À»ðǽ·¶³ë*/
+void zte_fw_sys_security_setting(webs_t wp)
+{
+ char *rmE = NULL; /* 0: Disabled 1: Enabled */
+ char *wpfE = NULL; /* 0: Disabled 1: Enabled */
+
+ rmE = websGetVar(wp, T("RemoteManagement"), T("0"));
+ wpfE = websGetVar(wp, T("WANPingFilter"), T("0"));
+
+ switch (atoi(rmE)) {
+ case 0:
+ (void)zte_web_write("RemoteManagement", "0"); /* Disable */
+ break;
+ case 1:
+ (void)zte_web_write("RemoteManagement", "1"); /* Enable */
+ break;
+ default:
+ (void)zte_web_write("RemoteManagement", "0"); /* Accepted */
+ break;
+ }
+
+ switch (atoi(wpfE)) {
+ case 0:
+ (void)zte_web_write("WANPingFilter", "0"); /* Disable */
+ break;
+ case 1:
+ (void)zte_web_write("WANPingFilter", "1"); /* Enable */
+ break;
+ default:
+ (void)zte_web_write("WANPingFilter", "0"); /* Accepted */
+ break;
+ }
+
+ //zte_iptables_basic_setting();
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_FORWARD, 0, NULL, 0);
+
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+/*ɾ³ýÒ»Ìõ·À»ðǽ*/
+void zte_fw_ipport_filter_del(webs_t wp)
+{
+ /* value from web page */
+ int i = 0, j = 0;
+ char_t *delete_id = NULL;
+ int id = 0;
+ char_t *start = NULL;
+ char IPPortFilterRules_x[NV_ITEM_STRING_LEN_50] = {0};
+ char IPPortFilterRules[NV_ITEM_STRING_LEN_200] = {0};
+ int flag = 0;
+
+ delete_id = websGetVar(wp, "delete_id", "");
+
+ if (*delete_id == '\0') {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ //to delete the rules
+ for (start = delete_id; *delete_id != '\0';) {
+ if (*delete_id == ';') {
+ *delete_id = '\0';
+ id = atoi(start);
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ (void)snprintf(IPPortFilterRules_x, NV_ITEM_STRING_LEN_50, "IPPortFilterRules_%d", id);
+ (void)sc_cfg_set(IPPortFilterRules_x, "");
+
+ delete_id ++;/*lint !e52*/
+ start = delete_id;
+ } else {
+ delete_id ++;/*lint !e52*/
+ }
+ }
+
+ //organize the rule
+ for (i = 0; i <= 9; i++) {
+ flag = 0;
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ memset(IPPortFilterRules, 0, sizeof(IPPortFilterRules));
+
+ (void)snprintf(IPPortFilterRules_x, NV_ITEM_STRING_LEN_50, "IPPortFilterRules_%d", i);
+ sc_cfg_get(IPPortFilterRules_x, IPPortFilterRules, sizeof(IPPortFilterRules));
+ if (0 == strcmp(IPPortFilterRules, "")) {
+ for (j = (i + 1); j <= 9; j++) {
+ //reset
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ memset(IPPortFilterRules, 0, sizeof(IPPortFilterRules));
+
+ (void)snprintf(IPPortFilterRules_x, NV_ITEM_STRING_LEN_50, "IPPortFilterRules_%d", j);
+ sc_cfg_get(IPPortFilterRules_x, IPPortFilterRules, sizeof(IPPortFilterRules));
+ if (0 != strcmp(IPPortFilterRules, "")) {
+ sc_cfg_set(IPPortFilterRules_x, "");
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ (void)snprintf(IPPortFilterRules_x, NV_ITEM_STRING_LEN_50, "IPPortFilterRules_%d", i);
+ sc_cfg_set(IPPortFilterRules_x, IPPortFilterRules);
+ flag = 1;
+ break;
+ }
+ }
+
+ if (0 == flag) {
+ break;
+ }
+ }
+ }
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_FILTER, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_fw_ipport_filter_del SEND MESSAGE TO MC END");/*lint !e26*/ /*lint !e26*/
+
+ //sc_cfg_save();
+ //zte_response_json_for_test(wp,"zte_fw_ipport_filter_del","send message to mc");
+
+ zte_write_result_to_web(wp, SUCCESS);
+ return;
+}
+
+/*ɾ³ýÒ»Ìõ¶Ë¿Úת·¢¹æÔò*/
+void zte_fw_port_forward_del(webs_t wp)
+{
+ int i = 0, j = 0;
+ char_t *delete_id = NULL;
+ int id = 0;
+ char_t *start = NULL;
+ char PortForwardRules_x[NV_ITEM_STRING_LEN_50] = {0};
+ char PortForwardRules[NV_ITEM_STRING_LEN_200] = {0};
+ int flag = 0;
+
+ delete_id = websGetVar(wp, "delete_id", "");
+
+ if (*delete_id == '\0') {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+ //to delete the rules
+ for (start = delete_id; *delete_id != '\0';) {
+ if (*delete_id == ';') {
+ *delete_id = '\0';
+ id = atoi(start);
+ memset(PortForwardRules_x, 0, sizeof(PortForwardRules_x));
+ (void)snprintf(PortForwardRules_x, NV_ITEM_STRING_LEN_50, "PortForwardRules_%d", id);
+ slog(MISC_PRINT, SLOG_DEBUG, "port_forward delete NV:[%s]", PortForwardRules_x);
+ (void)sc_cfg_set(PortForwardRules_x, "");
+
+ delete_id ++;/*lint !e52*/
+ start = delete_id;
+ } else {
+ delete_id ++;/*lint !e52*/
+ }
+ }
+
+ //organize the rule
+ for (i = 0; i <= 9; i++) {
+ flag = 0;
+ memset(PortForwardRules_x, 0, sizeof(PortForwardRules_x));
+ memset(PortForwardRules, 0, sizeof(PortForwardRules));
+
+ (void)snprintf(PortForwardRules_x, NV_ITEM_STRING_LEN_50, "PortForwardRules_%d", i);
+ sc_cfg_get(PortForwardRules_x, PortForwardRules, sizeof(PortForwardRules));
+
+ if (0 == strcmp(PortForwardRules, "")) {
+ for (j = (i + 1); j <= 9; j++) {
+ //reset
+ memset(PortForwardRules_x, 0, sizeof(PortForwardRules_x));
+ memset(PortForwardRules, 0, sizeof(PortForwardRules));
+
+ (void)snprintf(PortForwardRules_x, NV_ITEM_STRING_LEN_50, "PortForwardRules_%d", j);
+ sc_cfg_get(PortForwardRules_x, PortForwardRules, sizeof(PortForwardRules));
+ if (0 != strcmp(PortForwardRules, "")) {
+ (void)sc_cfg_set(PortForwardRules_x, "");
+
+ memset(PortForwardRules_x, 0, sizeof(PortForwardRules_x));
+ (void)snprintf(PortForwardRules_x, NV_ITEM_STRING_LEN_50, "PortForwardRules_%d", i);
+ (void)sc_cfg_set(PortForwardRules_x, PortForwardRules);
+
+ flag = 1;
+ break;
+ }
+ }
+
+ if (0 == flag) {
+ break;
+ }
+ }
+ }
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_FORWARD, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_fw_port_forward_del SEND MESSAGE TO MC END"); /*lint !e26*/
+ //zte_response_json_for_test(wp,"zte_fw_port_forward_del","send message to mc");
+
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+ return;
+}
+
+/******************************************************
+* Function: zte_fw_port_map_check()
+* Description: check the add port map data
+* Input:
+* Output:
+* Return:
+* Others:
+* Modify Date Version Author Modification
+* 2014/08/18 V1.0 gebin create
+*******************************************************/
+static int zte_fw_port_map_check(webs_t wp, fw_port_map_type *fw_port_map)
+{
+ // we dont trust user input.....
+ if (!fw_port_map->spr) {//klocwork
+ return -1;
+ }
+ if (!fw_port_map->dpr) {
+ return -1;
+ }
+ /* user choose nothing but press "apply" only */
+ if (0 == strlen(fw_port_map->ip_address)
+ || 0 == strlen(fw_port_map->spr)
+ || 0 == strlen(fw_port_map->dpr)
+ || 0 == strlen(fw_port_map->comment)) {
+ zte_web_write("PortMapEnable", "1");
+ slog(MISC_PRINT, SLOG_DEBUG, "port_map some parameter null");
+ return -1;
+ }
+#ifdef WEBS_SECURITY
+ int i = 0;
+ int len = strlen(fw_port_map->comment);
+ for (i = 0; i < len; i++) {
+ if (strchr("`$&*\\[];:\'\"<>,",fw_port_map->comment[i]) || !isprint(fw_port_map->comment[i])) {
+ return -1;
+ }
+ }
+#endif
+#if 0 // kw 3 fw_port_map->ip_address has already checked
+ if (!strlen(fw_port_map->ip_address)) {
+ return -1;
+ }
+#endif
+ if (!isIpValid(fw_port_map->ip_address)) {
+ return -1;
+ }
+
+ if (!(fw_port_map->spr_int = atoi(fw_port_map->spr))) {
+ return -1;
+ }
+ if (fw_port_map->spr_int > 65000) {
+ return -1;
+ }
+
+ if (!(fw_port_map->dpr_int = atoi(fw_port_map->dpr))) {
+ return -1;
+ }
+ if (fw_port_map->dpr_int > 65000) {
+ return -1;
+ }
+
+ if (!strcmp(fw_port_map->protocol, "TCP"))
+ fw_port_map->proto = PROTO_TCP;
+ else if (!strcmp(fw_port_map->protocol, "UDP"))
+ fw_port_map->proto = PROTO_UDP;
+ else if (!strcmp(fw_port_map->protocol, "TCP&UDP"))
+ fw_port_map->proto = PROTO_TCP_UDP;
+ else {
+ return -1;
+ }
+ if (strlen(fw_port_map->comment) > 32) {
+ return -1;
+ }
+ /* i know you will try to break our box... ;) */
+ if (strchr(fw_port_map->comment, ';') || strchr(fw_port_map->comment, ',')) {
+ return -1;
+ }
+
+ return 1;
+}
+
+/*Ìí¼ÓÒ»Ìõ¶Ë¿ÚÓ³É乿Ôò*/
+void zte_fw_port_map_add(webs_t wp)
+{
+ slog(MISC_PRINT, SLOG_ERR, T("UFIx User added port map!\n"));
+ fw_port_map_type fw_port_map;
+ int check_result = 0;
+ int count = 0;
+ int flag = 0;
+ char PortMapRules[NV_FW_RULE_MAX_LEN] = {0};
+ char PortMapRules_x[NV_ITEM_STRING_LEN_50] = {0};
+ char *portmap_enable = NULL; /* 0: Disabled 1: Enabled */
+ char portmap_original[2] = {0}; /* 0: Disabled 1: Enabled */
+
+ slog(MISC_PRINT, SLOG_DEBUG, "enter zte_fw_port_map_add.\n");
+
+ //port_map setting
+ portmap_enable = websGetVar(wp, T("portMapEnabled"), T("0"));
+
+ //read original port_map setting
+ zte_web_read("PortMapEnable", portmap_original);
+ slog(MISC_PRINT, SLOG_DEBUG, "portmap_original: %s, portmap_enable: %s\n", portmap_original, portmap_enable);
+
+ switch (atoi(portmap_enable)) {
+ case 0:
+ (void)zte_web_write("PortMapEnable", "0"); /* Disable */
+ break;
+ case 1:
+ (void)zte_web_write("PortMapEnable", "1"); /* Enable */
+ break;
+ default:
+ (void)zte_web_write("PortMapEnable", "0"); /* Accepted */
+ break;
+ }
+
+ //portmap switch open/close, or keep close
+ if ((0 != strcmp(portmap_original, portmap_enable)) || (0 == strcmp(portmap_enable, "0"))) {
+ /* EC: 616000297057, ÔÒò: ÍøÂç²»Ö§³Ö¶Ë¿ÚÓ³Éä */
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_MAPPING, 0, NULL, 0);
+
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+ slog(MISC_PRINT, SLOG_NORMAL, "portmap switch open/close, or keep close\n");
+ return;
+ }
+
+ memset(&fw_port_map, 0, sizeof(fw_port_map_type));
+ fw_port_map.ip_address = websGetVar(wp, T("ip_address"), T(""));
+ fw_port_map.spr = websGetVar(wp, T("fromPort"), T(""));
+ fw_port_map.dpr = websGetVar(wp, T("toPort"), T(""));
+ fw_port_map.protocol = websGetVar(wp, T("protocol"), T(""));
+ fw_port_map.comment = websGetVar(wp, T("comment"), T(""));
+
+ /* user re-press port_map open apply button, should return SUCCESS*/
+ /* while user choose nothing but press "apply" only will be checked by js code*/
+ if (0 == strlen(fw_port_map.ip_address)
+ && 0 == strlen(fw_port_map.spr)
+ && 0 == strlen(fw_port_map.dpr)
+ && 0 == strlen(fw_port_map.comment)) {
+ zte_write_result_to_web(wp, SUCCESS);
+ slog(MISC_PRINT, SLOG_DEBUG, "portmap re-press open apply button\n");
+ return;
+ }
+
+ //add rules
+ check_result = zte_fw_port_map_check(wp, &fw_port_map);
+ if (check_result < 0) {
+ slog(MISC_PRINT, SLOG_ERR, "portmap add rule failure\n");
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ for (count = 0; count <= 9; count++) {
+ (void)snprintf(PortMapRules_x, NV_ITEM_STRING_LEN_50, "PortMapRules_%d", count);
+ memset(PortMapRules, 0, sizeof(PortMapRules));
+ zte_web_read(PortMapRules_x, PortMapRules);
+ if (0 == strcmp(PortMapRules, "")) {
+ memset(PortMapRules, 0, sizeof(PortMapRules));
+ (void)snprintf(PortMapRules, NV_ITEM_STRING_LEN_200, "%s,%d,%d,%d,%s",
+ fw_port_map.ip_address, fw_port_map.spr_int,
+ fw_port_map.dpr_int, fw_port_map.proto,
+ fw_port_map.comment);
+ (void)zte_web_write(PortMapRules_x, PortMapRules);
+ flag = 1;
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_fw_port_map_add %s: %s\n", PortMapRules_x, PortMapRules);
+ break;
+ }
+ }
+
+ if (0 == flag) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_MAPPING, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_fw_port_map_add MESSAGE TO MC END\n"); /*lint !e26*/
+
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+/*ɾ³ýÒ»Ìõ¶Ë¿ÚÓ³É乿Ôò*/
+void zte_fw_port_map_del(webs_t wp)
+{
+ int i = 0, j = 0;
+ char_t *delete_id = NULL;
+ int id = 0;
+ char_t *start = NULL;
+ char PortMapRules_x[NV_ITEM_STRING_LEN_50] = {0};
+ char PortMapRules[NV_ITEM_STRING_LEN_200] = {0};
+ int flag = 0;
+
+ delete_id = websGetVar(wp, "delete_id", "");
+ slog(MISC_PRINT, SLOG_DEBUG, "zte_fw_port_map_del delete_id: %s\n", delete_id);
+ if (*delete_id == '\0') {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ //to delete the rules
+ for (start = delete_id; *delete_id != '\0';) {
+ if (*delete_id == ';') {
+ *delete_id = '\0';
+ id = atoi(start);
+ memset(PortMapRules_x, 0, sizeof(PortMapRules_x));
+ (void)snprintf(PortMapRules_x, NV_ITEM_STRING_LEN_50, "PortMapRules_%d", id);
+ slog(MISC_PRINT, SLOG_DEBUG, "port_map delete NV: %s\n", PortMapRules_x);
+ (void)sc_cfg_set(PortMapRules_x, "");
+
+ delete_id++; /*lint !e52*/
+ start = delete_id;
+ } else {
+ delete_id ++;/*lint !e52*/
+ }
+ }
+
+ //organize the rule
+ for (i = 0; i <= 9; i++) {
+ flag = 0;
+ memset(PortMapRules_x, 0, sizeof(PortMapRules_x));
+ memset(PortMapRules, 0, sizeof(PortMapRules));
+
+ (void)snprintf(PortMapRules_x, NV_ITEM_STRING_LEN_50, "PortMapRules_%d", i);
+ sc_cfg_get(PortMapRules_x, PortMapRules, sizeof(PortMapRules));
+
+ if (0 == strcmp(PortMapRules, "")) {
+ for (j = (i + 1); j <= 9; j++) {
+ //reset
+ memset(PortMapRules_x, 0, sizeof(PortMapRules_x));
+ memset(PortMapRules, 0, sizeof(PortMapRules));
+
+ (void)snprintf(PortMapRules_x, NV_ITEM_STRING_LEN_50, "PortMapRules_%d", j);
+ sc_cfg_get(PortMapRules_x, PortMapRules, sizeof(PortMapRules));
+ if (0 != strcmp(PortMapRules, "")) {
+ (void)sc_cfg_set(PortMapRules_x, "");
+
+ memset(PortMapRules_x, 0, sizeof(PortMapRules_x));
+ (void)snprintf(PortMapRules_x, NV_ITEM_STRING_LEN_50, "PortMapRules_%d", i);
+ (void)sc_cfg_set(PortMapRules_x, PortMapRules);
+
+ flag = 1;
+ break;
+ }
+ }
+
+ if (0 == flag) {
+ break;
+ }
+ }
+ }
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_MAPPING, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_fw_port_map_del SEND MESSAGE TO MC END\n"); /*lint !e26*/
+
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+//¹©web»ñÈ¡¹æÔòÐÐÊý
+/*int zte_get_fw_rules_num(webs_t wp, char* ruleName)
+{
+ char rules[NV_FW_RULE_MAX_LEN]={0};
+
+ sc_cfg_get(ruleName, rules, sizeof(rules));
+ if(0 == strlen(rules))
+ {
+ websWrite(wp, T("0"));
+ return 0;
+ }
+
+ websWrite(wp, T("%d"), getRuleNums(rules));
+ return 0;
+}*/
+
+void zte_goform_url_filter_add_process(webs_t wp)
+{
+ slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User added url filter!\n"));
+ char urlfilters[1023] = {0};
+ char new_urlfilters[1024] = {0};
+ char *rule = websGetVar(wp, T("addURLFilter"), T(""));
+
+ memset(urlfilters, 0, 1023);
+ memset(new_urlfilters, 0, 1024);
+
+ if (!rule)
+ return;
+ if (strchr(rule, ';'))
+ return;
+
+ sc_cfg_get("websURLFilters", urlfilters, sizeof(urlfilters));
+ if (0 == strcmp(urlfilters, "")) {
+ sc_cfg_set("websURLFilters", rule);
+ } else {
+ snprintf(new_urlfilters,sizeof(new_urlfilters),"%s%s%s",urlfilters,";",rule);
+/* strcat(new_urlfilters, urlfilters);
+ strcat(new_urlfilters, ";");
+ if(strlen(new_urlfilters) + strlen(rule) < 1024)
+ strcat(new_urlfilters, rule);*/
+ sc_cfg_set("websURLFilters", new_urlfilters);
+ }
+
+ //zte_iptables_Webs_Filter_Run();
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_URL_FILTER, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_goform_url_filter_add_process MESSAGE TO MC END"); /*lint !e26*/
+
+ //sc_cfg_save();
+
+ zte_write_result_to_web(wp, SUCCESS);
+}
+//URL¹ýÂ˹æÔòɾ³ý
+void zte_goform_url_filter_delete_process(webs_t wp)
+{
+ int j = 0, rule_count = 0;
+ char_t name_buf[16] = {0};
+ char_t *value = NULL;
+ char_t *delete_id = NULL;
+ int *deleArray = NULL;
+ char rules[1024] = {0};
+ char_t *start = NULL;
+ int id = 0;
+
+ delete_id = websGetVar(wp, "url_filter_delete_id", NULL);
+
+ if (delete_id == NULL || *delete_id == '\0') {
+ slog(MISC_PRINT, SLOG_DEBUG, "delete_id is NULL."); /*lint !e26*/
+ zte_write_result_to_web(wp, FAILURE); /*lint !e26*/
+ return;
+ }
+ slog(MISC_PRINT, SLOG_DEBUG, "delete_id is [%s].", delete_id); /*lint !e26*/
+
+ //to delete the rules
+
+ sc_cfg_get("websURLFilters", rules, sizeof(rules));
+ if (0 == strlen(rules)) {
+ slog(MISC_PRINT, SLOG_ERR, "rules is NULL."); /*lint !e26*/
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+ rule_count = getRuleNums(rules);
+#if 0 // kw 3 INVARIANT_CONDITION.UNREACH
+ if (!rule_count) {
+ slog(MISC_PRINT, SLOG_ERR, "rule_count is NULL."); /*lint !e26*/
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+#endif
+ deleArray = (int *)malloc(rule_count * sizeof(int));
+ if (NULL == deleArray) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ for (start = delete_id; *delete_id != '\0';) {
+ if (*delete_id == ';') {
+ *delete_id = '\0';
+ id = atoi(start);
+ slog(MISC_PRINT, SLOG_DEBUG, "delete_id single is [%d].", id); /*lint !e26*/
+ deleArray[j++] = id; /*lint !e52*/
+ delete_id ++;
+ start = delete_id;
+ } else {
+ delete_id ++;/*lint !e52*/
+ }
+ }
+#if 0
+ for (i = 0, j = 0; i < rule_count; i++) {
+ snprintf(name_buf, 16, "DR%d", i);
+ value = websGetVar(wp, name_buf, NULL);
+ if (value) {
+ deleArray[j++] = i;
+ }
+ }
+#endif
+ if (!j) {
+ free(deleArray);
+
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ static_deleteNthValueMulti(deleArray, rule_count, rules, ';');
+ free(deleArray);
+ deleArray = NULL;
+
+ sc_cfg_set("websURLFilters", rules);
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_URL_FILTER, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_goform_url_filter_delete_process MESSAGE TO MC END"); /*lint !e26*/
+
+ //sc_cfg_save();
+
+ zte_write_result_to_web(wp, SUCCESS);
+ return;
+}
+
+//DMZ¹æÔòÌí¼Ó
+void zte_fw_dmz(webs_t wp)
+{
+ char *dmzE, *ip_address;
+
+ dmzE = websGetVar(wp, T("DMZEnabled"), T(""));
+ ip_address = websGetVar(wp, T("DMZIPAddress"), T(""));
+
+ // someone use malform page.....
+ if (!dmzE || !strlen(dmzE)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ if (atoi(dmzE) && !isIpValid(ip_address)) { // enable && invalid mac address
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ //zte_iptables_DMZ_Run();
+ if (atoi(dmzE) == 0) {
+ zte_web_write("DMZEnable", "0");// disable
+ slog(MISC_PRINT, SLOG_DEBUG, T("UFIx User disable port forward!\n"));
+ } else {
+ zte_web_write("DMZEnable", "1");// enable
+ slog(MISC_PRINT, SLOG_DEBUG, T("UFIx User enable port forward!\n"));
+ if (strlen(ip_address)) {
+ zte_web_write("DMZIPAddress", ip_address);
+ }
+ }
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_DMZ, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_fw_dmz SEND MESSAGE TO MC END"); /*lint !e26*/
+
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+static int zte_fw_ipport_filter_check(webs_t wp, fw_ipport_filter_type *fw_ipport_filter)
+{
+ char *ip_version = NULL;
+ ip_version = websGetVar(wp, T("ip_version"), T(""));
+
+ if (0 == strlen(fw_ipport_filter->mac_address)
+ && 0 == strlen(fw_ipport_filter->sip_1)
+ && 0 == strlen(fw_ipport_filter->dip_1)
+ && 0 == strlen(fw_ipport_filter->sprf)
+ && 0 == strlen(fw_ipport_filter->dprf)) {
+ slog(MISC_PRINT, SLOG_ERR, "zte_fw_ipport_filter_add -> No MAC/IP/Port input!"); /*lint !e26*/
+ return -1;
+ }
+
+ if (strlen(fw_ipport_filter->mac_address) > 0
+ && !isMacValid(fw_ipport_filter->mac_address)) {
+ slog(MISC_PRINT, SLOG_ERR, "Mac address is error."); /*lint !e26*/
+ return -1;
+ }
+
+ if (strlen(fw_ipport_filter->sip_1)) {
+ if (0 == strcmp(ip_version, IP_VERSION_V4)) {
+ if (!isIpNetmaskValid(fw_ipport_filter->sip_1)) {
+ slog(MISC_PRINT, SLOG_ERR, "zte_fw_ipport_filter_add -> src ip is invalid:[%s]", fw_ipport_filter->sip_1); /*lint !e26*/
+ return -1;
+ }
+ }
+ } else {
+ fw_ipport_filter->sip_1 = T("any/0");
+ slog(MISC_PRINT, SLOG_DEBUG, "liuyingnan check:[%s]", fw_ipport_filter->sip_1); /*lint !e26*/
+ }
+
+ if (strlen(fw_ipport_filter->dip_1)) {
+ if (0 == strcmp(ip_version, IP_VERSION_V4)) {
+ if (!isIpNetmaskValid(fw_ipport_filter->dip_1)) {
+ slog(MISC_PRINT, SLOG_ERR, "zte_fw_ipport_filter_add -> dest ip is invalid:[%s]", fw_ipport_filter->dip_1); /*lint !e26*/
+ return -1;
+ }
+ }
+ } else {
+ fw_ipport_filter->dip_1 = T("any/0");
+ slog(MISC_PRINT, SLOG_DEBUG, "liuyingnan check:[%s]", fw_ipport_filter->dip_1); /*lint !e26*/
+ }
+
+ fw_ipport_filter->sip_2 = fw_ipport_filter->dip_2 = "0";
+
+ if (!strcmp(fw_ipport_filter->protocol, T("TCP")))
+ fw_ipport_filter->proto = PROTO_TCP;
+ else if (!strcmp(fw_ipport_filter->protocol, T("UDP")))
+ fw_ipport_filter->proto = PROTO_UDP;
+ else if (!strcmp(fw_ipport_filter->protocol, T("None")))
+ fw_ipport_filter->proto = PROTO_NONE;
+ else if (!strcmp(fw_ipport_filter->protocol, T("ICMP")))
+ fw_ipport_filter->proto = PROTO_ICMP;
+ else if (!strcmp(fw_ipport_filter->protocol, T("TCP&UDP")))
+ fw_ipport_filter->proto = PROTO_TCP_UDP;
+ else {
+ slog(MISC_PRINT, SLOG_ERR, "protocol is invalid:[%s]", fw_ipport_filter->protocol); /*lint !e26*/
+ return -1;
+ }
+
+ /* port(1~65535) is valid only when the protocol is TCP or UDP */
+ if (!strlen(fw_ipport_filter->sprf)
+ || fw_ipport_filter->proto == PROTO_NONE
+ || fw_ipport_filter->proto == PROTO_ICMP) {
+ fw_ipport_filter->sprf_int = 0;
+ } else {
+ fw_ipport_filter->sprf_int = atoi(fw_ipport_filter->sprf);
+ if (fw_ipport_filter->sprf_int == 0 || fw_ipport_filter->sprf_int > 65535) {
+ slog(MISC_PRINT, SLOG_ERR, "sprf is invalid:[%s]", fw_ipport_filter->sprf); /*lint !e26*/
+ return -1;
+ }
+ }
+
+ if (!strlen(fw_ipport_filter->sprt)
+ || fw_ipport_filter->proto == PROTO_NONE
+ || fw_ipport_filter->proto == PROTO_ICMP) {
+ fw_ipport_filter->sprt_int = 0;
+ } else {
+ fw_ipport_filter->sprt_int = atoi(fw_ipport_filter->sprt);
+ if (fw_ipport_filter->sprt_int == 0 || fw_ipport_filter->sprt_int > 65535) {
+ slog(MISC_PRINT, SLOG_ERR, "sprt is invalid:[%s]", fw_ipport_filter->sprt); /*lint !e26*/
+ return -1;
+ }
+ }
+
+ if (!strlen(fw_ipport_filter->dprf)
+ || fw_ipport_filter->proto == PROTO_NONE
+ || fw_ipport_filter->proto == PROTO_ICMP) {
+ fw_ipport_filter->dprf_int = 0;
+ } else {
+ fw_ipport_filter->dprf_int = atoi(fw_ipport_filter->dprf);
+ if (fw_ipport_filter->dprf_int == 0 || fw_ipport_filter->dprf_int > 65535) {
+ slog(MISC_PRINT, SLOG_ERR, "dprf is invalid:[%s]", fw_ipport_filter->dprf); /*lint !e26*/
+ return -1;
+ }
+ }
+
+ if (!strlen(fw_ipport_filter->dprt)
+ || fw_ipport_filter->proto == PROTO_NONE
+ || fw_ipport_filter->proto == PROTO_ICMP) {
+ fw_ipport_filter->dprt_int = 0;
+ } else {
+ fw_ipport_filter->dprt_int = atoi(fw_ipport_filter->dprt);
+ if (fw_ipport_filter->dprt_int == 0 || fw_ipport_filter->dprt_int > 65535) {
+ slog(MISC_PRINT, SLOG_ERR, "dprt is invalid:[%s]", fw_ipport_filter->dprt); /*lint !e26*/
+ return -1;
+ }
+ }
+
+ if (0 == (strcmp(fw_ipport_filter->action_str, T("Accept")))) {
+ fw_ipport_filter->action = ACTION_ACCEPT;
+ } else if (0 == (strcmp(fw_ipport_filter->action_str, T("Drop")))) {
+ fw_ipport_filter->action = ACTION_DROP;
+ } else {
+ slog(MISC_PRINT, SLOG_ERR, "action is invalid:[%s]", fw_ipport_filter->action_str); /*lint !e26*/
+ return -1;
+ }
+
+ if (strlen(fw_ipport_filter->comment) > 32) {
+ slog(MISC_PRINT, SLOG_ERR, "comment is too long."); /*lint !e26*/
+ return -1;
+ }
+ // i know you will try to break our box... ;)
+ if (strchr(fw_ipport_filter->comment, ';') || strchr(fw_ipport_filter->comment, ',')) {
+ slog(MISC_PRINT, SLOG_ERR, "comment is invalid."); /*lint !e26*/
+ return -1;
+ }
+
+ return 1;
+}
+
+/*IPV4¶Ë¿Ú¹ýÂËÌí¼Ó*/
+static void zte_fw_ipport_filter_add_v4(webs_t wp)
+{
+ fw_ipport_filter_type fw_ipport_filter_v4;
+ char IPPortFilterRules[NV_FW_RULE_MAX_LEN] = {0};
+ char IPPortFilterRules_x[NV_ITEM_STRING_LEN_50] = {0};
+ int check_result = 0;
+ int count = 0;
+ int flag = 0;
+
+ memset(&fw_ipport_filter_v4, 0, sizeof(fw_ipport_filter_type));
+ fw_ipport_filter_v4.sip_1 = websGetVar(wp, T("sip_address"), T("any"));
+ fw_ipport_filter_v4.sip_2 = websGetVar(wp, T("sip_address2"), T("")); // TODO: not support now
+ fw_ipport_filter_v4.sprf = websGetVar(wp, T("sFromPort"), T("0"));
+ fw_ipport_filter_v4.sprt = websGetVar(wp, T("sToPort"), T(""));
+ fw_ipport_filter_v4.dip_1 = websGetVar(wp, T("dip_address"), T("any"));
+ fw_ipport_filter_v4.dip_2 = websGetVar(wp, T("dip_address2"), T("")); // TODO: not support now
+ fw_ipport_filter_v4.dprf = websGetVar(wp, T("dFromPort"), T("0"));
+ fw_ipport_filter_v4.dprt = websGetVar(wp, T("dToPort"), T(""));
+ fw_ipport_filter_v4.mac_address = websGetVar(wp, T("mac_address"), T(""));
+ fw_ipport_filter_v4.protocol = websGetVar(wp, T("protocol"), T("")); // None | TCP | UDP | ICMP | TCP&UDP
+ fw_ipport_filter_v4.action_str = websGetVar(wp, T("action"), T("")); // Drop | Accept
+ fw_ipport_filter_v4.comment = websGetVar(wp, T("comment"), T(""));
+
+ check_result = zte_fw_ipport_filter_check(wp, &fw_ipport_filter_v4);
+ if (check_result < 0) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ for (count = 0; count <= 9; count ++) {
+ (void)snprintf(IPPortFilterRules_x, NV_ITEM_STRING_LEN_50, "IPPortFilterRules_%d", count);
+ memset(IPPortFilterRules, 0, sizeof(IPPortFilterRules));
+ zte_web_read(IPPortFilterRules_x, IPPortFilterRules);
+ if (0 == strcmp(IPPortFilterRules, "")) {
+ memset(IPPortFilterRules, 0, sizeof(IPPortFilterRules));
+ (void)snprintf(IPPortFilterRules, NV_FW_RULE_MAX_LEN, "%s,%s,%d,%d,%s,%s,%d,%d,%d,%d,%s,%s",
+ fw_ipport_filter_v4.sip_1, fw_ipport_filter_v4.sip_2,
+ fw_ipport_filter_v4.sprf_int, fw_ipport_filter_v4.sprt_int,
+ fw_ipport_filter_v4.dip_1, fw_ipport_filter_v4.dip_2,
+ fw_ipport_filter_v4.dprf_int, fw_ipport_filter_v4.dprt_int,
+ fw_ipport_filter_v4.proto, fw_ipport_filter_v4.action,
+ fw_ipport_filter_v4.comment, fw_ipport_filter_v4.mac_address);
+ (void)zte_web_write(IPPortFilterRules_x, IPPortFilterRules);
+ flag = 1;
+ break;
+ }
+ }
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_FILTER, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_fw_ipport_filter_add_v4 SEND MESSAGE TO MC END"); /*lint !e26*/
+ //zte_response_json_for_test(wp,"zte_fw_ipport_filter_add","send message to mc");
+ //sc_cfg_save();
+
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+/*IPV6¶Ë¿Ú¹ýÂËÌí¼Ó*/
+static void zte_fw_ipport_filter_add_v6(webs_t wp)
+{
+ fw_ipport_filter_type fw_ipport_filter_v6;
+ char IPPortFilterRulesV6[NV_FW_RULE_MAX_LEN] = {0};
+ char IPPortFilterRulesV6_x[NV_ITEM_STRING_LEN_50] = {0};
+ int check_result = 0;
+ int count = 0;
+ int flag = 0;
+
+ memset(&fw_ipport_filter_v6, 0, sizeof(fw_ipport_filter_type));
+ fw_ipport_filter_v6.sip_1 = websGetVar(wp, T("sip_address"), T("any"));
+ fw_ipport_filter_v6.sip_2 = websGetVar(wp, T("sip_address2"), T("")); // TODO: not support now
+ fw_ipport_filter_v6.sprf = websGetVar(wp, T("sFromPort"), T("0"));
+ fw_ipport_filter_v6.sprt = websGetVar(wp, T("sToPort"), T(""));
+ fw_ipport_filter_v6.dip_1 = websGetVar(wp, T("dip_address"), T("any"));
+ fw_ipport_filter_v6.dip_2 = websGetVar(wp, T("dip_address2"), T("")); // TODO: not support now
+ fw_ipport_filter_v6.dprf = websGetVar(wp, T("dFromPort"), T("0"));
+ fw_ipport_filter_v6.dprt = websGetVar(wp, T("dToPort"), T(""));
+ fw_ipport_filter_v6.mac_address = websGetVar(wp, T("mac_address"), T(""));
+ fw_ipport_filter_v6.protocol = websGetVar(wp, T("protocol"), T("")); // None | TCP | UDP | ICMP | TCP&UDP
+ fw_ipport_filter_v6.action_str = websGetVar(wp, T("action"), T("")); // Drop | Accept
+ fw_ipport_filter_v6.comment = websGetVar(wp, T("comment"), T(""));
+
+ check_result = zte_fw_ipport_filter_check(wp, &fw_ipport_filter_v6);
+ if (check_result < 0) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ for (count = 0; count <= 9; count ++) {
+ (void)snprintf(IPPortFilterRulesV6_x, NV_ITEM_STRING_LEN_50, "IPPortFilterRulesv6_%d", count);
+ memset(IPPortFilterRulesV6, 0, sizeof(IPPortFilterRulesV6));
+ zte_web_read(IPPortFilterRulesV6_x, IPPortFilterRulesV6);
+ if (0 == strcmp(IPPortFilterRulesV6, "")) {
+ memset(IPPortFilterRulesV6, 0, sizeof(IPPortFilterRulesV6));
+ (void)snprintf(IPPortFilterRulesV6, NV_FW_RULE_MAX_LEN, "%s,%s,%d,%d,%s,%s,%d,%d,%d,%d,%s,%s",
+ fw_ipport_filter_v6.sip_1, fw_ipport_filter_v6.sip_2,
+ fw_ipport_filter_v6.sprf_int, fw_ipport_filter_v6.sprt_int,
+ fw_ipport_filter_v6.dip_1, fw_ipport_filter_v6.dip_2,
+ fw_ipport_filter_v6.dprf_int, fw_ipport_filter_v6.dprt_int,
+ fw_ipport_filter_v6.proto, fw_ipport_filter_v6.action,
+ fw_ipport_filter_v6.comment, fw_ipport_filter_v6.mac_address);
+ (void)zte_web_write(IPPortFilterRulesV6_x, IPPortFilterRulesV6);
+ flag = 1;
+ break;
+ }
+ }
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_FILTER, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_fw_ipport_filter_add_v6 MESSAGE TO MC END"); /*lint !e26*/
+
+ //zte_response_json_for_test(wp,"zte_fw_ipport_filter_add","send message to mc");
+
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+/*¶Ë¿Ú¹ýÂËÓÐЧÐÔ¼ì²é*/
+static int zte_fw_port_forward_check(webs_t wp, fw_port_forward_type *fw_port_forward)
+{
+ /* user choose nothing but press "apply" only */
+ if (0 == strlen(fw_port_forward->ip_address)
+ && 0 == strlen(fw_port_forward->prf)
+ && 0 == strlen(fw_port_forward->prt)
+ && 0 == strlen(fw_port_forward->comment)) {
+ zte_web_write("PortForwardEnable", "1");
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_FORWARD, 0, NULL, 0);
+ return -1;
+ }
+
+ if (!strlen(fw_port_forward->ip_address)) {
+ return -1;
+ }
+ if (!isIpValid(fw_port_forward->ip_address)) {
+ return -1;
+ }
+
+ // we dont trust user input.....
+ if (!fw_port_forward->prf || !strlen(fw_port_forward->prf)) {
+ return -1;
+ }
+ if (!(fw_port_forward->prf_int = atoi(fw_port_forward->prf))) {
+ return -1;
+ }
+ if (fw_port_forward->prf_int > 65535) {
+ return -1;
+ }
+
+ if (!fw_port_forward->prt) {
+ return -1;
+ }
+ if (strlen(fw_port_forward->prt)) {
+ if (!(fw_port_forward->prt_int = atoi(fw_port_forward->prt))) {
+ return -1;
+ }
+ if (fw_port_forward->prt_int < fw_port_forward->prf_int) {
+ return -1;
+ }
+ if (fw_port_forward->prt_int > 65535)
+ return -1;
+ } else {
+ fw_port_forward->prt_int = 0;
+ }
+
+ if (! strcmp(fw_port_forward->protocol, "TCP"))
+ fw_port_forward->proto = PROTO_TCP;
+ else if (!strcmp(fw_port_forward->protocol, "UDP"))
+ fw_port_forward->proto = PROTO_UDP;
+ else if (!strcmp(fw_port_forward->protocol, "TCP&UDP"))
+ fw_port_forward->proto = PROTO_TCP_UDP;
+ else {
+ return -1;
+ }
+ if (strlen(fw_port_forward->comment) > 32) {
+ return -1;
+ }
+ /* i know you will try to break our box... ;) */
+ if (strchr(fw_port_forward->comment, ';') || strchr(fw_port_forward->comment, ',')) {
+ return -1;
+ }
+
+ return 1;
+}
+
+/*Ìí¼ÓÒ»Ìõ·À»ðǽ*/
+void zte_fw_ipport_filter_add(webs_t wp)
+{
+ slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User added port filter!\n"));
+
+ char *ip_version = NULL;
+
+ ip_version = websGetVar(wp, T("ip_version"), T(""));
+
+ if (0 == strcmp(ip_version, IP_VERSION_V4)) {
+ zte_fw_ipport_filter_add_v4(wp);
+ } else if (0 == strcmp(ip_version, IP_VERSION_V6)) {
+ zte_fw_ipport_filter_add_v6(wp);
+ } else {
+ slog(MISC_PRINT, SLOG_ERR, "unknown ip_version:[%s]", ip_version); /*lint !e26*/
+ zte_write_result_to_web(wp, FAILURE);
+ }
+}
+
+/*Ìí¼ÓÒ»Ìõ¶Ë¿Úת·¢¹æÔò£¬½»ÓÉzte_routerͳһ´¦Àí*/
+void zte_fw_port_forward_add(webs_t wp)
+{
+ slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User added port forward!\n"));
+ fw_port_forward_type fw_port_forward;
+ int check_result = 0;
+ int count = 0;
+ int flag = 0;
+ char PortForwardRules[NV_FW_RULE_MAX_LEN] = {0};
+ char PortForwardRules_x[NV_ITEM_STRING_LEN_50] = {0};
+ memset(&fw_port_forward, 0, sizeof(fw_port_forward_type));
+ fw_port_forward.ip_address = websGetVar(wp, T("ipAddress"), T(""));
+ fw_port_forward.prf = websGetVar(wp, T("portStart"), T(""));
+ fw_port_forward.prt = websGetVar(wp, T("portEnd"), T(""));
+ fw_port_forward.protocol = websGetVar(wp, T("protocol"), T(""));
+ fw_port_forward.comment = websGetVar(wp, T("comment"), T(""));
+ //slog(MISC_PRINT,SLOG_DEBUG, "fw_port_forward.protocol:[%s]", fw_port_forward.protocol);
+
+ check_result = zte_fw_port_forward_check(wp, &fw_port_forward);
+ if (check_result < 0) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ //zte_web_write("PortForwardEnable", "1");
+ for (count = 0; count <= 9; count ++) {
+ (void)snprintf(PortForwardRules_x, NV_ITEM_STRING_LEN_50, "PortForwardRules_%d", count);
+ memset(PortForwardRules, 0, sizeof(PortForwardRules));
+ zte_web_read(PortForwardRules_x, PortForwardRules);
+ if (0 == strcmp(PortForwardRules, "")) {
+ memset(PortForwardRules, 0, sizeof(PortForwardRules));
+ (void)snprintf(PortForwardRules, NV_ITEM_STRING_LEN_200, "%s,%d,%d,%d,%s",
+ fw_port_forward.ip_address, fw_port_forward.prf_int,
+ fw_port_forward.prt_int, fw_port_forward.proto,
+ fw_port_forward.comment);
+ (void)zte_web_write(PortForwardRules_x, PortForwardRules);
+ flag = 1;
+ break;
+ }
+ }
+
+ if (0 == flag) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_FORWARD, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_fw_port_forward_add MESSAGE TO MC END"); /*lint !e26*/
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+/*ɾ³ýV4µÄ¶Ë¿ÚÁбí*/
+static void zte_fw_ipport_filter_del_v4(webs_t wp)
+{
+ int i = 0, j = 0;
+ char_t *delete_id = NULL;
+ int id = 0;
+ char_t *start = NULL;
+ char IPPortFilterRules_x[NV_ITEM_STRING_LEN_50] = {0};
+ char IPPortFilterRules[NV_FW_RULE_MAX_LEN] = {0};
+ int flag = 0;
+
+ delete_id = websGetVar(wp, "delete_id", "");
+ slog(MISC_PRINT, SLOG_DEBUG, "delete_id is [%s].", delete_id); /*lint !e26*/
+
+ if (*delete_id == '\0') {
+ return; // no delete the v4 rule
+ }
+
+ //to delete the rules
+ for (start = delete_id; *delete_id != '\0';) {
+ if (*delete_id == ';') {
+ *delete_id = '\0';
+ id = atoi(start);
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ (void)snprintf(IPPortFilterRules_x, sizeof(IPPortFilterRules_x) - 1, "IPPortFilterRules_%d", id);
+ (void)zte_web_write(IPPortFilterRules_x, "");
+
+ delete_id ++;/*lint !e52*/
+ start = delete_id;
+ } else {
+ delete_id ++;/*lint !e52*/
+ }
+ }
+
+ //organize the rule
+ for (i = 0; i <= 9; i++) {
+ flag = 0;
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ memset(IPPortFilterRules, 0, sizeof(IPPortFilterRules));
+
+ (void)snprintf(IPPortFilterRules_x, sizeof(IPPortFilterRules_x) - 1, "IPPortFilterRules_%d", i);
+ (void)zte_web_read(IPPortFilterRules_x, IPPortFilterRules);
+
+ if (0 == strcmp(IPPortFilterRules, "")) {
+ for (j = (i + 1); j <= 9; j++) {
+ //reset
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ memset(IPPortFilterRules, 0, sizeof(IPPortFilterRules));
+
+ (void)snprintf(IPPortFilterRules_x, sizeof(IPPortFilterRules_x) - 1, "IPPortFilterRules_%d", j);
+ (void)zte_web_read(IPPortFilterRules_x, IPPortFilterRules);
+ if (0 != strcmp(IPPortFilterRules, "")) {
+ (void)zte_web_write(IPPortFilterRules_x, "");
+
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ (void)snprintf(IPPortFilterRules_x, sizeof(IPPortFilterRules_x) - 1, "IPPortFilterRules_%d", i);
+ (void)zte_web_write(IPPortFilterRules_x, IPPortFilterRules);
+
+ flag = 1;
+ break;
+ }
+ }
+
+ if (0 == flag) {
+ break;
+ }
+ }
+ }
+}
+
+/*ɾ³ýV6µÄ¶Ë¿ÚÁбí*/
+static void zte_fw_ipport_filter_del_v6(webs_t wp)
+{
+ int i = 0, j = 0;
+ char_t *delete_id = NULL;
+ int id = 0;
+ char_t *start = NULL;
+ char IPPortFilterRules_x[NV_ITEM_STRING_LEN_50] = {0};
+ char IPPortFilterRules[NV_FW_RULE_MAX_LEN_V6] = {0};
+ int flag = 0;
+
+ delete_id = websGetVar(wp, "delete_id_v6", "");
+ slog(MISC_PRINT, SLOG_DEBUG, "delete_id is [%s].", delete_id); /*lint !e26*/
+
+ if (*delete_id == '\0') {
+ return; // no delete the v6 rule
+ }
+
+ //to delete the rules
+ for (start = delete_id; *delete_id != '\0';) {
+ if (*delete_id == ';') {
+ *delete_id = '\0';
+ id = atoi(start);
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ (void)snprintf(IPPortFilterRules_x, sizeof(IPPortFilterRules_x) - 1, "IPPortFilterRulesv6_%d", id);
+ (void)zte_web_write(IPPortFilterRules_x, "");
+
+ delete_id ++;/*lint !e52*/
+ start = delete_id;
+ } else {
+ delete_id ++;/*lint !e52*/
+ }
+ }
+
+ //organize the rule
+ for (i = 0; i <= 9; i++) {
+ flag = 0;
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ memset(IPPortFilterRules, 0, sizeof(IPPortFilterRules));
+
+ (void)snprintf(IPPortFilterRules_x, sizeof(IPPortFilterRules_x) - 1, "IPPortFilterRulesv6_%d", i);
+ (void)zte_web_read(IPPortFilterRules_x, IPPortFilterRules);
+
+ if (0 == strcmp(IPPortFilterRules, "")) {
+ for (j = (i + 1); j <= 9; j++) {
+ //reset
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ memset(IPPortFilterRules, 0, sizeof(IPPortFilterRules));
+
+ (void)snprintf(IPPortFilterRules_x, sizeof(IPPortFilterRules_x) - 1, "IPPortFilterRulesv6_%d", j);
+ (void)zte_web_read(IPPortFilterRules_x, IPPortFilterRules);
+ if (0 != strcmp(IPPortFilterRules, "")) {
+ (void)zte_web_write(IPPortFilterRules_x, "");
+
+ memset(IPPortFilterRules_x, 0, sizeof(IPPortFilterRules_x));
+ (void)snprintf(IPPortFilterRules_x, sizeof(IPPortFilterRules_x) - 1, "IPPortFilterRulesv6_%d", i);
+ (void)zte_web_write(IPPortFilterRules_x, IPPortFilterRules);
+
+ flag = 1;
+ break;
+ }
+ }
+
+ if (0 == flag) {
+ break;
+ }
+ }
+ }
+
+}
+
+/*ɾ³ýij¶Ë¿ÚÁбí*/
+void zte_fw_ipport_filter_del_v4_v6(webs_t wp)
+{
+ //delete the v4 rule and v6 rule
+ zte_fw_ipport_filter_del_v4(wp);
+ zte_fw_ipport_filter_del_v6(wp);
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_IPPORT_FILTER, 0, NULL, 0);
+
+ //response
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+/**********************************************************************
+¿ª¹ØupnpÒµÎñ
+**********************************************************************/
+void zte_fw_upnp_set(webs_t wp, char_t *path, char_t *query)
+{
+ char *upnp_set = NULL;
+#if 0
+ //wanghan start ÓÉÓÚȱʧ¶¯Ì¬¿âÍ·Îļþdlfcn.h£¬miniupnpdÔÝʱÎÞ·¨±àÒë¹ý£¬ÏÈ´ò×®±£Ö¤webui²»»á¿¨×¡
+ zte_write_result_to_web(wp, SUCCESS);
+ return;
+ //wanghan end
+#endif
+ //zte_topsw_state_e_type status = ZTE_NVIO_DONE;
+
+ upnp_set = websGetVar(wp, T("upnp_setting_option"), T("0"));
+
+ if (atoi(upnp_set) == 0) {
+ // disable
+ (void)zte_web_write("upnpEnabled", "0");
+ slog(MISC_PRINT, SLOG_DEBUG, T("UFIx User disable port forward!\n"));
+ } else {
+ // enable
+ (void)zte_web_write("upnpEnabled", "1");
+ slog(MISC_PRINT, SLOG_DEBUG, T("UFIx User enable port forward!\n"));
+ }
+
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_UPNP, 0, NULL, 0);
+ slog(MISC_PRINT, SLOG_NORMAL, "zte_fw_upnp_set MESSAGE TO MC END"); /*lint !e26*/
+ //sc_cfg_save();
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+/*************************** wan pppoe ***************************/
+void zte_goform_set_wan_gatewaymode_PPPOE(webs_t wp)
+{
+ char work_state[20] = {0};
+ char *actionLink = NULL;
+ char_t *pppoe_username = NULL;
+ char_t *pppoe_cc = NULL;
+ char_t *eth_dial_mode = NULL;
+
+ pppoe_username = websGetVar(wp, T("pppoe_username"), T(""));
+ pppoe_cc = websGetVar(wp, T("pppoe_cc"), T(""));
+ eth_dial_mode = websGetVar(wp, T("dial_mode"), T(""));
+ actionLink = websGetVar(wp, T("action_link"), T(""));
+ sc_cfg_set(NV_OPMS_WAN_MODE, "PPPOE");
+ sc_cfg_set("ethwan_mode", "pppoe");
+ zte_write_result_to_web(wp, SUCCESS);
+ sc_cfg_get("rj45_state", work_state, sizeof(work_state));
+
+ if (IFSTREQUAL(eth_dial_mode, "auto_dial")) {
+ sc_cfg_set("ethwan_dialmode", "auto");
+ if (0 == strcmp(work_state, "idle")) { //rj45ÒѲåÈë Ôò×Ô¶¯²¦ºÅ ·ñÔòʲô¶¼²»×ö
+ sc_cfg_set("pppoe_username", pppoe_username);
+ sc_cfg_set("pppoe_cc", pppoe_cc);
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ }
+ } else if (IFSTREQUAL(eth_dial_mode, "on_demand_dial")) {
+ sc_cfg_set("ethwan_dialmode", "ondemand");
+ if (0 == strcmp(work_state, "idle")) { //rj45ÒѲåÈë Ôò×Ô¶¯²¦ºÅ ·ñÔòʲô¶¼²»×ö
+ sc_cfg_set("pppoe_username", pppoe_username);
+ sc_cfg_set("pppoe_cc", pppoe_cc);
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ }
+ } else if (IFSTREQUAL(eth_dial_mode, "manual_dial")) { //Ö»ÓÐÔÚrj45ÒѾ²åÈëµÄÇé¿öϲÅÄܹ»ÉèÖÃÊÖ¶¯Ä£Ê½
+ sc_cfg_set("ethwan_dialmode", "manual");
+ if (!strcmp(actionLink, "connect")) {
+ sc_cfg_set("pppoe_username", pppoe_username);
+ sc_cfg_set("pppoe_cc", pppoe_cc);
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ } else {
+ netdev_disconnect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ }
+ }
+ //sc_cfg_save();
+}
+
+void zte_goform_set_wan_gatewaymode_DHCP(webs_t wp)
+{
+ char work_state[20] = {0};
+ char *actionLink = NULL;
+ char_t *eth_dial_mode = NULL;
+
+ actionLink = websGetVar(wp, T("action_link"), T(""));
+ eth_dial_mode = websGetVar(wp, T("dial_mode"), T(""));
+
+ sc_cfg_set(NV_OPMS_WAN_MODE, "DHCP");
+ sc_cfg_set("ethwan_mode", "dhcp");
+
+ zte_write_result_to_web(wp, SUCCESS);
+
+ sc_cfg_set("ethwan_dialmode", "auto");//dhcp Ò³ÃæÉÏûÓÐÊÖ¶¯ ÔÝʱĬÈÏΪ×Ô¶¯²¦ºÅ
+ sc_cfg_get("rj45_state", work_state, sizeof(work_state));
+
+ if (IFSTREQUAL(eth_dial_mode, "auto_dial")) {
+ sc_cfg_set("ethwan_dialmode", "auto");
+ if (0 == strcmp(work_state, "idle"))//rj45ÒѲåÈë Ôò×Ô¶¯²¦ºÅ ·ñÔòʲô¶¼²»×ö
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ } else if (IFSTREQUAL(eth_dial_mode, "on_demand_dial")) {
+ sc_cfg_set("ethwan_dialmode", "ondemand");
+ if (0 == strcmp(work_state, "idle"))//rj45ÒѲåÈë Ôò×Ô¶¯²¦ºÅ ·ñÔòʲô¶¼²»×ö
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ } else if (IFSTREQUAL(eth_dial_mode, "manual_dial")) { //Ö»ÓÐÔÚrj45ÒѾ²åÈëµÄÇé¿öϲÅÄܹ»ÉèÖÃÊÖ¶¯Ä£Ê½
+ sc_cfg_set("ethwan_dialmode", "manual");
+ if (!strcmp(actionLink, "connect")) {
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ } else {
+ netdev_disconnect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ }
+ }
+ //sc_cfg_save();
+}
+
+void zte_goform_set_wan_gatewaymode_STATIC(webs_t wp)
+{
+ char work_state[20] = {0};
+ char *actionLink = NULL;
+ char_t *eth_dial_mode = NULL;
+ char_t *static_wan_ipaddr = NULL;
+ char_t *static_wan_netmask = NULL;
+ char_t *static_wan_gateway = NULL;
+ char_t *static_wan_primary_dns = NULL;
+ char_t *static_wan_secondary_dns = NULL;
+
+ static_wan_ipaddr = websGetVar(wp, T("static_wan_ipaddr"), T(""));
+ static_wan_netmask = websGetVar(wp, T("static_wan_netmask"), T("0"));
+ static_wan_gateway = websGetVar(wp, T("static_wan_gateway"), T(""));
+ static_wan_primary_dns = websGetVar(wp, T("static_wan_primary_dns"), T(""));
+ static_wan_secondary_dns = websGetVar(wp, T("static_wan_secondary_dns"), T(""));
+ actionLink = websGetVar(wp, T("action_link"), T(""));
+ eth_dial_mode = websGetVar(wp, T("dial_mode"), T(""));
+
+ sc_cfg_set("ethwan_mode", "static");
+ sc_cfg_set(NV_OPMS_WAN_MODE, "STATIC");
+ zte_write_result_to_web(wp, SUCCESS);
+ sc_cfg_get("rj45_state", work_state, sizeof(work_state));
+
+ if (IFSTREQUAL(eth_dial_mode, "auto_dial")) {
+ sc_cfg_set("ethwan_dialmode", "auto");
+ if (0 == strcmp(work_state, "idle")) { //rj45ÒѲåÈë Ôò×Ô¶¯²¦ºÅ ·ñÔòʲô¶¼²»×ö
+ sc_cfg_set("static_wan_ipaddr", static_wan_ipaddr);
+ sc_cfg_set("static_wan_netmask", static_wan_netmask);
+ sc_cfg_set("static_wan_gateway", static_wan_gateway);
+ sc_cfg_set("static_wan_primary_dns", static_wan_primary_dns);
+ sc_cfg_set("static_wan_secondary_dns", static_wan_secondary_dns);
+ sc_cfg_set("static_ethwan_ip", static_wan_ipaddr);
+ sc_cfg_set("static_ethwan_nw", static_wan_netmask);
+ sc_cfg_set("static_ethwan_gw", static_wan_gateway);
+ sc_cfg_set("static_ethwan_pridns", static_wan_primary_dns);
+ sc_cfg_set("static_ethwan_secdns", static_wan_secondary_dns);
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ }
+ } else if (IFSTREQUAL(eth_dial_mode, "on_demand_dial")) {
+ sc_cfg_set("ethwan_dialmode", "ondemand");
+ if (0 == strcmp(work_state, "idle")) { //rj45ÒѲåÈë Ôò×Ô¶¯²¦ºÅ ·ñÔòʲô¶¼²»×ö
+ sc_cfg_set("static_wan_ipaddr", static_wan_ipaddr);
+ sc_cfg_set("static_wan_netmask", static_wan_netmask);
+ sc_cfg_set("static_wan_gateway", static_wan_gateway);
+ sc_cfg_set("static_wan_primary_dns", static_wan_primary_dns);
+ sc_cfg_set("static_wan_secondary_dns", static_wan_secondary_dns);
+ sc_cfg_set("static_ethwan_ip", static_wan_ipaddr);
+ sc_cfg_set("static_ethwan_nw", static_wan_netmask);
+ sc_cfg_set("static_ethwan_gw", static_wan_gateway);
+ sc_cfg_set("static_ethwan_pridns", static_wan_primary_dns);
+ sc_cfg_set("static_ethwan_secdns", static_wan_secondary_dns);
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ }
+ } else if (IFSTREQUAL(eth_dial_mode, "manual_dial")) { //Ö»ÓÐÔÚrj45ÒѾ²åÈëµÄÇé¿öϲÅÄܹ»ÉèÖÃÊÖ¶¯Ä£Ê½
+ sc_cfg_set("ethwan_dialmode", "manual");
+ if (!strcmp(actionLink, "connect")) {
+ sc_cfg_set("static_wan_ipaddr", static_wan_ipaddr);
+ sc_cfg_set("static_wan_netmask", static_wan_netmask);
+ sc_cfg_set("static_wan_gateway", static_wan_gateway);
+ sc_cfg_set("static_wan_primary_dns", static_wan_primary_dns);
+ sc_cfg_set("static_wan_secondary_dns", static_wan_secondary_dns);
+ sc_cfg_set("static_ethwan_ip", static_wan_ipaddr);
+ sc_cfg_set("static_ethwan_nw", static_wan_netmask);
+ sc_cfg_set("static_ethwan_gw", static_wan_gateway);
+ sc_cfg_set("static_ethwan_pridns", static_wan_primary_dns);
+ sc_cfg_set("static_ethwan_secdns", static_wan_secondary_dns);
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ } else {
+ netdev_disconnect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ }
+ }
+ //sc_cfg_save();
+}
+
+void zte_goform_set_wan_gatewaymode_AUTO(webs_t wp)
+{
+ char work_state[20] = {0};
+ char_t *pppoe_username = NULL;
+ char_t *pppoe_cc = NULL;
+ char_t *actionLink = NULL;
+ char_t *eth_dial_mode = NULL;
+
+ pppoe_username = websGetVar(wp, T("pppoe_username"), T(""));
+ pppoe_cc = websGetVar(wp, T("pppoe_cc"), T(""));
+ actionLink = websGetVar(wp, T("action_link"), T(""));
+ eth_dial_mode = websGetVar(wp, T("dial_mode"), T(""));
+
+ sc_cfg_set("ethwan_mode", "auto");
+ sc_cfg_set("ethwan_dialmode", "auto");
+ sc_cfg_set(NV_OPMS_WAN_MODE, "AUTO");
+
+ zte_write_result_to_web(wp, SUCCESS);
+
+ sc_cfg_get("rj45_state", work_state, sizeof(work_state));
+
+ if (IFSTREQUAL(eth_dial_mode, "auto_dial")) {
+ sc_cfg_set("ethwan_dialmode", "auto");
+ if (0 == strcmp(work_state, "idle")) { //rj45ÒѲåÈë Ôò×Ô¶¯²¦ºÅ ·ñÔòʲô¶¼²»×ö
+ sc_cfg_set("pppoe_username", pppoe_username);
+ sc_cfg_set("pppoe_cc", pppoe_cc);
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ }
+ } else if (IFSTREQUAL(eth_dial_mode, "on_demand_dial")) {
+ sc_cfg_set("ethwan_dialmode", "ondemand");
+ if (0 == strcmp(work_state, "idle")) { //rj45ÒѲåÈë Ôò×Ô¶¯²¦ºÅ ·ñÔòʲô¶¼²»×ö
+ sc_cfg_set("pppoe_username", pppoe_username);
+ sc_cfg_set("pppoe_cc", pppoe_cc);
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ }
+ } else if (IFSTREQUAL(eth_dial_mode, "manual_dial")) { //Ö»ÓÐÔÚrj45ÒѾ²åÈëµÄÇé¿öϲÅÄܹ»ÉèÖÃÊÖ¶¯Ä£Ê½
+ sc_cfg_set("ethwan_dialmode", "manual");
+ if (!strcmp(actionLink, "connect")) {
+ sc_cfg_set("pppoe_username", pppoe_username);
+ sc_cfg_set("pppoe_cc", pppoe_cc);
+ netdev_connect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ } else {
+ netdev_disconnect_internet(RJ45_WAN_DEV, MODULE_ID_WEB_CGI);
+ }
+ }
+ //sc_cfg_save();
+}
+
+void zte_goform_set_operation_mode(webs_t wp)
+{
+ char_t *mode = NULL;
+ char oldMode[128] = {0};
+ char buf[NV_ITEM_STRING_LEN_20] = {0};
+
+ sc_cfg_get(NV_BLC_WAN_MODE, oldMode, sizeof(oldMode));
+ mode = websGetVar(wp, T("opMode"), T("PPP"));
+ sc_cfg_set(NV_BLC_WAN_MODE, mode);
+
+ if (!strcmp(mode, oldMode)) {
+ zte_write_result_to_web(wp, FAILURE);
+ } else {
+ zte_write_result_to_web(wp, SUCCESS);
+ slog(MISC_PRINT, SLOG_NORMAL,"zte_goform_set_operation_mode: send MSG_CMD_RESTART_REQUEST\n");
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_RESTART_REQUEST, 0, NULL, 0);
+ }
+}
+
+
+//Æô¶¯pingÕï¶Ï
+void zte_ping_diagnostics_start(webs_t wp)
+{
+ char_t *diag_addr = NULL;
+ char_t *repetition_count = NULL;
+ char_t *time_out = NULL;
+ char_t *data_size = NULL;
+ char_t *diag_interface = NULL;
+
+ diag_addr = websGetVar(wp, T("ping_diag_addr"), T(""));
+ repetition_count = websGetVar(wp, T("ping_repetition_count"), T(""));
+ time_out = websGetVar(wp, T("ping_time_out"), T(""));
+ data_size = websGetVar(wp, T("ping_data_size"), T(""));
+ diag_interface = websGetVar(wp, T("ping_diag_interface"), T(""));
+
+ if ('\0' == (*diag_addr) || !isIpValid(diag_addr)) {
+ zte_write_result_to_web(wp, FAILURE);
+ return;
+ }
+ (void)zte_web_write("ping_diag_addr", diag_addr);
+
+ if ('\0' != (*repetition_count))
+ (void)zte_web_write("ping_repetition_count", repetition_count);
+
+ if ('\0' != (*time_out))
+ (void)zte_web_write("ping_time_out", time_out);
+
+ if ('\0' != (*data_size))
+ (void)zte_web_write("ping_data_size", data_size);
+
+ if ('\0' != (*diag_interface))
+ (void)zte_web_write("ping_diag_interface", diag_interface);
+
+ //sc_cfg_save();
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_PING_DIAGNOSTICS, 0, NULL, 0);
+
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+//¹Ø±ÕpingÕï¶Ï
+void zte_ping_diagnostics_stop(webs_t wp)
+{
+ system("killall ping");
+
+ zte_write_result_to_web(wp, SUCCESS);
+}
+
+
diff --git a/ap/app/goahead/interface5.0/net/zte_web_net_wan.h b/ap/app/goahead/interface5.0/net/zte_web_net_wan.h
new file mode 100644
index 0000000..bd7abb3
--- /dev/null
+++ b/ap/app/goahead/interface5.0/net/zte_web_net_wan.h
@@ -0,0 +1,205 @@
+#ifndef ZTE_WEB_NET_WAN_H
+#define ZTE_WEB_NET_WAN_H
+
+#include "webs.h"
+
+/********************************Constant************************/
+#define PROTO_UNKNOWN 0
+#define PROTO_TCP 1
+#define PROTO_UDP 2
+#define PROTO_TCP_UDP 3
+#define PROTO_ICMP 4
+#define PROTO_NONE 5
+
+#define RULE_MODE_DISABLE 0
+#define RULE_MODE_DROP 1
+#define RULE_MODE_ACCEPT 2
+
+#define ACTION_DROP 0
+#define ACTION_ACCEPT 1
+
+#define NV_FW_EACH_RULE_LEN 150
+#define NV_FW_RULE_MAX_LEN 300
+
+#define WEB_PORT_MAX 65535
+#define ZTE_FW_IP_ADDR_LEN 16
+#define ZTE_FW_MAC_ADDR_LEN 18
+#define ZTE_FW_PORT_LEN 6
+#define ZTE_FW_FLAG_LEN 2
+#define ZTE_FW_SHORT_COMMENT_LEN 16
+#define ZTE_FW_MAC_FILTER_MAX_LEN 500
+#define ZTE_FW_IP_ADDR_LEN_V6 45
+
+#define WEB_IP_ADDR_MAX_LEN 32
+#define WEB_IP_PORT_MAX_LEN 8
+#define WEB_MAC_ADDR_MAX_LEN 32
+#define WEB_RULE_COMMENT_LEN 32
+
+
+#define FMT_ECHO_IPTABLES_CMD " 1>/dev/null 2>&1"
+#define IPPORT_FILTER_CHAIN "macipport_filter"
+#define VPN_CHAIN "vpn_filter"
+#define PORT_FORWARD_CHAIN "port_forward"
+
+#define WEB_FILTER_CHAIN "web_filter"
+#define DMZ_CHAIN "DMZ"
+
+/* Same as the file "linux/netfilter_ipv4/ipt_webstr.h" */
+#define BLK_JAVA 0x01
+#define BLK_ACTIVE 0x02
+#define BLK_COOKIE 0x04
+#define BLK_PROXY 0x08
+
+typedef struct _fw_ipport_filter_type {
+ char_t *mac_address;
+ char_t *sip_1;
+ char_t *sip_2;
+ char_t *sprf;
+ char_t *sprt;
+ char_t *dip_1;
+ char_t *dip_2;
+ char_t *dprf;
+ char_t *dprt;
+ char_t *protocol;
+ char_t *action_str;
+ char_t *comment;
+ int sprf_int;
+ int sprt_int;
+ int dprf_int;
+ int dprt_int;
+ int proto;
+ int action;
+} fw_ipport_filter_type;
+
+typedef struct _fw_port_map_type {
+ char_t *ip_address;
+ char_t *spr;
+ char_t *dpr;
+ char_t *protocol;
+ char_t *comment;
+ int spr_int;
+ int dpr_int;
+ int proto;
+
+} fw_port_map_type;
+
+typedef struct _fw_port_forward_type {
+ char_t *pfe;
+ char_t *ip_address;
+ char_t *prf;
+ char_t *prt;
+ char_t *protocol;
+ char_t *comment;
+ int prf_int;
+ int prt_int;
+ int proto;
+
+} fw_port_forward_type;
+
+extern void zte_goform_url_filter_add_process(webs_t wp);
+extern void zte_goform_url_filter_delete_process(webs_t wp);
+
+extern void init_router_web(void);
+//static int zte_dhcp_client_list(int eid, webs_t wp, int argc, char_t **argv);
+
+//static void zte_fw_ipport_filter_del_v4(webs_t wp);
+//static void zte_fw_ipport_filter_del_v6(webs_t wp);
+
+extern void zte_fw_basic_setting(webs_t wp);
+extern void zte_fw_forward_setting(webs_t wp);
+extern void zte_fw_sys_security_setting(webs_t wp);
+extern void zte_fw_ipport_filter_add(webs_t wp);
+extern void zte_fw_ipport_filter_del(webs_t wp);
+extern void zte_fw_port_forward_del(webs_t wp);
+//static int zte_fw_port_map_check(webs_t wp, fw_port_map_type *fw_port_map);
+extern void zte_fw_port_map_add(webs_t wp);
+extern void zte_fw_port_map_del(webs_t wp);
+
+
+//extern int zte_get_fw_rules_num(webs_t wp, char* ruleName);
+extern void zte_fw_dmz(webs_t wp);
+extern void zte_make_filter_rules_v6(char *buf, int len, char *mac_address,
+ char *sip_1, char *sip_2, int sprf_int, int sprt_int,
+ char *dip_1, char *dip_2, int dprf_int, int dprt_int, int proto, int action);
+extern void zte_parse_mac_ip_port_filter_rules_v6(char* rules, char* mac_address);
+extern void zte_run_mac_ip_port_filter_rules_v6(void);
+extern void zte_run_all_filter_rules_v6(void);
+//static int changeNthValue(int index, char *value, char delimit, char *result, char *web_list);
+//static int deleteNthValue(int index, char *value, char delimit);
+//static int deleteNthValue(int index, char *value, char delimit);
+extern void zte_static_route_list_ini_run(void);
+extern void zte_static_route_list_add(char *name, char *private, char *active, char *des_ip, char *subnet_mask, char *gateway, char *metric);
+extern void zte_static_route_list_run_one(char *list, char delimit);
+extern void zte_static_route_list_del_one(char *list, char delimit);
+extern void zte_static_route_list_del(int index, char delimit);
+extern int zte_static_route_list_edit_one(int index, char *value, char delimit, char *result, char *web_list);
+extern void zte_static_route_list_edit(char *index, char *web_name, char *web_private, char *web_active, char *web_des_ip, char *web_subnet_mask, char *web_gateway, char *web_metric);
+extern void zte_fw_port_forward_add(webs_t wp);
+//static void zte_fw_ipport_filter_del_v6(webs_t wp);
+extern void zte_fw_ipport_filter_del_v4_v6(webs_t wp);
+//static void zte_goform_maciplist_add_process(char_t *web_mac_ip_list);
+
+extern void zte_fw_upnp_set(webs_t wp, char_t *path, char_t *query);
+extern void zte_qos_list_run(void);
+extern void zte_goform_qoslist_add_process(char_t *web_ip, char_t *max_download, char_t *max_upload, char_t *web_comment);
+extern void zte_goform_qoslist_del_process(char_t *index);/*lint !e129*/
+extern void zte_goform_qoslist_edit_process(char_t *web_ip, char_t *maxdownload, char_t *maxupload, char_t *web_comment, char_t *index); /*lint !e129*/
+
+//==============================ASP Functions================================//
+
+//static int showPortForwardRulesASP(int eid, webs_t wp, int argc, char_t **argv);/* PortForwardRules */
+//static int showIPPortFilterRulesASP(int eid, webs_t wp, int argc, char_t **argv); /* IPPortFilterRules */
+//static int getDMZEnableASP(int eid, webs_t wp, int argc, char_t **argv);
+//static int showDMZIPAddressASP(int eid, webs_t wp, int argc, char_t **argv);
+
+
+/* added by liuweipeng for ipv6 firwall 20120315 end */
+//==========================Functions to add rules===========================//
+//static void zte_fw_ipport_filter_add_v4(webs_t wp);
+//static void zte_fw_ipport_filter_add_v6(webs_t wp);
+//static int zte_fw_ipport_filter_check(webs_t wp, fw_ipport_filter_type *fw_ipport_filter);
+//static int zte_fw_port_forward_check(webs_t wp, fw_port_forward_type *fw_port_forward);
+//==========================Functions to clear iptables rules===========================//
+//static void zte_iptables_filter_flush(void);
+//static void zte_iptables_nat_flush(void);
+
+//======================Functions to make rules=============================//
+/* Mac/Ip/Port Filtering Web page */
+//static void zte_iptables_basic_setting(void);
+//static void zte_iptables_filter_run(void);
+//static void zte_iptables_make_filter_rule(char *buf, int len, char *mac_address,
+// char *sip_1, char *sip_2, int sprf_int, int sprt_int,
+// char *dip_1, char *dip_2, int dprf_int, int dprt_int, int proto, int action);
+/* Port Forwarding Web page */
+//static void zte_iptables_port_forward_run(void);
+//static void zte_iptables_make_port_forward_rule(char *buf, int len, char *wan_name,
+// char *ip_address, int proto, int prf_int, int prt_int);
+/* System Security Web page */
+/* Run all rules */
+
+//======================Util=============================//
+//static int static_deleteNthValueMulti(int index[], int count, char *value, char delimit);
+//static int static_getNthValueSafe(int index, char *value, char delimit, char *result, int len);/*lint !e402*/
+//static int getNums(char *value, char delimit);
+//static int getRuleNums(char *rules);
+//static int isMacValid(char *str);
+//static int isIpNetmaskValid(char *s);
+extern int isIpValid(char *str);
+//static int isNumOnly(char *str);
+//static int isAllNumAndSlash(char *str);
+//static int isOnlyOneSlash(char *str);
+/*lint +e402*/
+
+
+/*************************** wan pppoe ***************************/
+extern void zte_goform_set_wan_gatewaymode_PPPOE(webs_t wp);
+extern void zte_goform_set_wan_gatewaymode_STATIC(webs_t wp);
+extern void zte_goform_set_wan_gatewaymode_DHCP(webs_t wp);
+extern void zte_goform_set_wan_gatewaymode_AUTO(webs_t wp);
+extern void zte_goform_set_operation_mode(webs_t wp);
+
+
+#endif
+
+
+