blob: b69600262b10d10c2a0508369d7100746e8ebfd0 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/**
2 * @file zte_web_util.c
3 * @brief goform mesage processing
4 *
5 * Copyright (C) 2017 Sanechips Technology Co., Ltd.
6 * @author Hong Wu <wu.hong@sanechips.com.cn>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14
15/*******************************************************************************
16 * Include header files *
17 ******************************************************************************/
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <sys/ioctl.h>
22#include <arpa/inet.h>
23#include <net/if.h>
24#include <net/route.h>
25#ifdef CONFIG_DEFAULTS_KERNEL_2_6_21
26#include <linux/types.h>
27#include <linux/socket.h>
28#endif
29#include <string.h>
30#include <dirent.h>
31#include "webs.h"
32//#include "linux/autoconf.h"
33#include <sys/time.h>
34#include <signal.h>
35#include "zte_web_interface.h"
36#include "zte_web_get_fw_para.h"
37
38/*******************************************************************************
39 * Macro definitions *
40 ******************************************************************************/
41
42#define MAX_MOBILE_KEY_WORD_SIZE 20 /*¹Ø¼ü×Ö³¤¶ÈÔݶ¨20*/
43#define MAX_PAGE_PATH_SIZE 128
44//#define MAX_GOFORM_TABLE_SIZE 256
45
46/*******************************************************************************
47 * Local function declarations *
48 ******************************************************************************/
49static int getSysUptime(int eid, webs_t wp, int argc, char_t **argv);
50static int zte_goform_whitelist_check(webs_t wp);
51static int zte_goform_blacklist_check(webs_t wp);
52/*******************************************************************************
53 * Local variable definitions *
54 ******************************************************************************/
55/****Define the HEADER and FOOTER of web page****/
56static const char * const zte_web_page_header =
57 "<head>"
58 "<title>-</title>"
59 "</head>"
60 "<body bgcolor=white>"
61 "<p>"
62 "<font size=3 face=arial>"
63 "<p>"
64 "<font size=2 face=arial>"
65 ;
66
67static const char * const zte_web_page_footer =
68 "<p>"
69 "<p>"
70 "<font face=arial></b></font><br>"
71 "<script> "
72 " timer = setTimeout('location.replace(\"%s\")', 100) "
73 "</script> "
74 "<p>"
75 "</body>"
76 ;
77
78static const char * const zte_web_page_top =
79 "<p>"
80 "<p>"
81 "<font face=arial></b></font><br>"
82 "<script> "
83 " timer = setTimeout('top.location.replace(\"%s\")', 100) "
84 "</script> "
85 "<p>"
86 "</body>"
87 ;
88//multi_dataΪ¿Õ£¬ÇÒÒѵǽ²ÅÄÜ»ñÈ¡µ½,¸ÃÁÐ±í²»¿ÉËæÒâÔö¼Ó¾¡Á¿ÓÃNV
89static web_goform_type web_goform_get_cmd_table[] = {
90 /********** ¹²Í¬ ***********/
91 //{CMD_GET_DEVICE_MODE, zte_get_device_mode},//debug_enable
92 //{CMD_GET_POWERON_TIME, zte_get_poweron_time},//¿ª»úʱ¼ä
93 //{CMD_GET_LAN_DEV_INFO, zte_get_lan_dev_info},//»ñÈ¡ÄÚÍøÐÅÏ¢
94 {CMD_GET_USER_MAC_ADDR, zte_lan_user_mac_get},
95 {CMD_CONNECTION_MODE, zte_get_connection_mode},
96 /********** PBM module ***********/
97 {CMD_PBM_DATA_INFO, zte_get_pbm_data},
98 {CMD_PBM_DATA_TOTAL, zte_get_pbm_data_total},
99 {CMD_PBM_CAPACITY_INFO, zte_get_pbm_parameter_info},
100 /********** sms module ***********/
101 {CMD_SMS_PAGE_DATA, zte_get_sms_data},
102 {CMD_SMS_DATA_TOTAL, zte_get_sms_data_total},
103 {CMD_SMS_PARAMETER_INFO, zte_get_sms_parameter_info},
104 {CMD_SMS_STATUS_INFO, zte_get_sms_cmd_status_info},
105 {CMD_SMS_CAPACITY_INFO, zte_get_sms_capacity_info},
106 {CMD_SMS_STATUS_RPT_DATA, zte_get_sms_status_rpt_data},
107 {CMD_SMS_UNREAD_COUNT, zte_get_sms_unread_count},
108 {CMD_BROADCAST_DATA, zte_get_boradcast_data},
109 /********** wifi module ***********/
110 {CMD_WIFI_STATION_LIST, zte_wlan_get_station_list},
111 {CMD_WIFI_WPS_AP_PIN, zte_wlan_get_wps_pin},
112 {CMD_WIFI_WPS_AP_DEF_PIN, zte_wlan_get_wps_defpin},
113 /********** net module ***********/
114 {CMD_HOSTNAME_LIST, zte_get_hostnamelist},
115 {CMD_CURRENT_STATICADDR_LIST, zte_get_current_static_addr_list},
116 {CMD_LAN_STATION_LIST, zte_get_lan_station_list},
117 {CMD_CHILDREN_DEVICE_LIST, zte_get_children_device_list},
118 {CMD_WHITE_SITE_LIST, zte_get_white_site_list},
119 /********** DDNS ***********/
120 //{CMD_GETDDNS_STATUS, zte_get_ddns_status},
121 /********** USSD ***********/
122 {CMD_USSD_DATA_INFO, zte_get_ussd_data_info},
123 /********** FOTA ***********/
124 {FOTA_UPGRADE_RESULT, zte_fota_get_upgrade_result}, //¶ÁÈ¡ºóÐèÒªÌØÊâ´¦Àí £¬ËùÒÔ²»ÄܸijÉÖ±½Ó¶ÁNV
125
126 /********** httpshare ***********/
127 {CMD_HTTPSHARE_GETCARD_VAULE, zte_httpShare_getcard_value},
128 {CMD_HTTPSHARE_GETCARD_NMEA, zte_httpShare_getcard_name},
129 {CMD_HTTPSHARE_AUTH_GET, zte_httpShare_auth_get},
130};
131
132
133/*******************************************************************************
134* Global variable definitions *
135******************************************************************************/
136//extern web_goform_type web_goform_set_cmd_table[MAX_GOFORM_TABLE_SIZE];
137web_goform_type web_goform_set_cmd_table[] = {
138 /********** management module ***********/
139 {GOFORM_MGMT_SET_WEB_LANGUAGE, zte_mgmt_set_language}, //webuiÓïÑÔÏÔʾÉèÖÃ
140#ifndef WEBS_SECURITY
141 {GOFORM_MGMT_SET_DEVICEMODE, zte_mgmt_set_devicemode}, //¹¤×÷ģʽ
142#endif
143 {GOFORM_MGMT_LOGIN_IP, zte_mgmt_login}, //怫
144 {GOFORM_MGMT_LOGOUT_IP, zte_mgmt_logout}, //µÇ³ö
145 {GOFORM_MGMT_CHANGE_PASSWORD, zte_mgmt_change_password}, //ÃÜÂëÐÞ¸Ä
146 {GOFORM_MGMT_CHANGE_ACCOUNT, zte_mgmt_change_account}, //Õ˺ÅÐÞ¸Ä
147 {GOFORM_MGMT_QUICK_SETUP, zte_quick_setup}, //¿ìËÙÉèÖÃ
148 {GOFORM_MGMT_RESTORE_FACTORY_SETTINGS, zte_mgmt_restore}, //»Ö¸´³ö³¡ÉèÖÃ
149 {GOFORM_MGMT_REBOOT, zte_goform_mgmt_reboot_process}, //REBOOT
150 {GOFORM_MGMT_POWEROFF, zte_mgmt_poweroff}, //poweroff
151 {GOFORM_MGMT_POWER_ON_SPEED, zte_mgmt_control_power_on_speed}, //¿ìËÙ¿ª¹Ø»úÉèÖÃ
152 //{GOFORM_MGMT_SET_EXTERNAL_NV, zte_goform_set_external_nv},
153 {GOFORM_MGMT_SNTP, zte_goform_mgmt_sntp_process}, //SNTPÉèÖÃ
154 {GOFORM_SNTP_GETDATASTATIC, zte_goform_sntp_getdatastatic_process}, //´¥·¢serverУ׼ʱ¼ä
155 //{GOFORM_MGMT_SYSLOG, zte_goform_mgmt_syslog_process}, //ϵͳLOG
156
157 /********** wan module start***********/
158 {GOFORM_WAN_SET_NETWORK, zte_wan_set_network}, //ÊÖ¶¯ËÑÍø×¢²á
159 {GOFORM_WAN_SET_CONNECTION_MODE, zte_wan_set_connection_mode}, //ÉèÖò¦ºÅģʽ
160 {GOFORM_WAN_CONNECT_NETWORK, zte_wan_connect_network}, //PDP ²¦ºÅÇëÇó
161 {GOFORM_WAN_DISCONNECT_NETWORK, zte_wan_disconnect_network}, //PDP ²¦ºÅ¶Ï¿ªÇëÇó
162 {GOFORM_WAN_SET_BEARER_PREFERENCE, zte_wan_network_select}, //ÉèÖÃÕÒÍø·½Ê½MSG_CMD_NET_SELECT_REQ
163 {GOFORM_WAN_SCAN_NETWORK, zte_wan_scan_network}, //ÊÖ¶¯ËÑÍø
164 {GOFORM_WAN_UNLOCK_NETWORK, zte_mgmt_unlock_network}, //½âËøÍøÂç
165 //{GOFORM_WAN_LOCK_FREQUENCY, zte_wan_lock_frequency_process}, //LTEÏÂËø»ò½âËøÆµÇëÇó£¬ATÔÝδ´¦Àí
166 /********** apn module ***********/
167 {GOFORM_WAN_APN_PROC_EX, zte_form_multi_apn_proc_ex}, //APNÉèÖÃ
168 /********** pin,puk module ***********/
169 {GOFORM_MGMT_ENTER_PIN, zte_mgmt_pin_input}, //ÑéÖ¤PINÂëÊäÈë
170 {GOFORM_MGMT_DISABLE_PIN, zte_mgmt_disable_pin}, //¹Ø±ÕPIN
171 {GOFORM_MGMT_ENABLE_PIN, zte_mgmt_pin_enable_or_modify}, //¿ªÆô»òÐÞ¸ÄPIN
172 {GOFORM_MGMT_ENTER_PUK, zte_mgmt_puk_input}, //PUK
173 {GOFORM_MGMT_AUTO_PIN, zte_mgmt_auto_pin}, //×Ô¶¯PIN
174 /********** statistics module ***********/
175 {GOFORM_WAN_DATA_LIMIT_SETTING, zte_wan_data_limit_setting}, //Á÷Á¿¹ÜÀíÉèÖÃ
176 {GOFORM_WAN_DATA_FLOW_CALIBRATION_MANUAL, zte_wan_data_flow_calibration_manual},//ÊÖ¶¯Ð£×¼Á÷Á¿
177 {GOFORM_WAN_RESET_DATA_COUNTER, zte_wan_data_statistics_clear_process}, //Çå³ýÁ÷Á¿ÐÅÏ¢
178 /********** ussd module ***********/
179 {GOFORM_USSD_PROCESS, zte_goform_ussd_process}, //USSDÉèÖÃ
180 /********** wan module end***********/
181
182 /********** wifi module ***********/
183 {GOFORM_WLAN_SET, zte_wlan_basic_set}, //WIFI »ù´¡ÉèÖÃ
184 {GOFORM_WLAN_MAC_FILTER, zte_wlan_mac_filter_set}, //ÉèÖÃmac¹ýÂ˹¦ÄÜ
185 {GOFORM_WLAN_WPS_SET, zte_wlan_wps_mode_set}, //WPS
186 {GOFORM_WLAN_SSID1_SET, zte_wlan_web_ssid1_set}, //SSID1
187 {GOFORM_WLAN_SSID2_SET, zte_wlan_ssid2_set}, //SSID2
188 {GOFORM_WLAN_WIFI_SLEEP_SET, zte_wlan_sleep_set}, //ÐÝÃß
189 {GOFORM_WLAN_SET_TSW, zte_wlan_set_tsw}, //¶¨Ê±ÐÝÃß»½ÐÑ
190 {GOFORM_WLAN_WIFI_COVERAGE_SET, zte_wlan_coverage_set}, //¸²¸Ç·¶Î§
191 {GOFORM_WLAN_WIFI_STA_CONTROL, zte_wlan_station_set}, //wifi station
192 {GOFORM_WLAN_WIFI_SPOT_PROFILE_UPDATE, zte_wlan_station_spot_profile_update}, //wifi station
193 {GOFORM_WLAN_SET_STA_CON, zte_wlan_station_connect}, //wifi station
194 {GOFORM_WLAN_SET_STA_DISCON, zte_wlan_station_disconnect}, //wifi station
195 {GOFORM_WLAN_SET_STA_REFRESH, zte_wlan_station_refresh}, //wifi station
196
197 /********** router module ***********/
198 {GOFORM_ROUTER_DEL_IP_PORT_FILETER, zte_fw_ipport_filter_del},
199 {GOFORM_ROUTER_ADD_IP_PORT_FILETER_V4V6, zte_fw_ipport_filter_add}, /*for v4 and v6*/
200 {GOFORM_ROUTER_DEL_IP_PORT_FILETER_V4V6, zte_fw_ipport_filter_del_v4_v6}, /*for v4 and v6*/
201 {GOFORM_ROUTER_ADD_PORT_FORWARE, zte_fw_port_forward_add},
202 {GOFORM_ROUTER_DEL_PORT_FORWARE, zte_fw_port_forward_del},
203 {GOFORM_ROUTER_ADD_PORT_MAP, zte_fw_port_map_add},
204 {GOFORM_ROUTER_DEL_PORT_MAP, zte_fw_port_map_del},
205 {GOFORM_ROUTER_BASIC_SETTING, zte_fw_basic_setting},
206 {GOFORM_ROUTER_FORWARD_SETTING, zte_fw_forward_setting},
207 {GOFORM_ROUTER_SYSTEM_SECURITY, zte_fw_sys_security_setting},
208 {GOFORM_ROUTER_DHCP_SETTING, zte_dhcp_set},
209 {GOFORM_ROUTER_STATIC_DHCP_SETTING, zte_static_dhcp_set},
210 {GOFORM_ROUTER_UPNP_SETTING, zte_fw_upnp_set}, //CPEÈÚºÏÔÚ·ÓÉÉèÖÃÖÐ
211 {GOFORM_ROUTER_DMZ_SETTING, zte_fw_dmz},
212 {GOFORM_ROUTER_EDIT_HOSTNAME, zte_edit_hostname},
213 {GOFORM_URL_FILTER_DELETE, zte_goform_url_filter_delete_process}, //URL ¹ýÂË
214 {GOFORM_URL_FILTER_ADD, zte_goform_url_filter_add_process},
215 {GOFORM_BIND_STATIC_ADDRESS_SET, zte_set_bind_static_address},
216 {GOFORM_BIND_STATIC_ADDRESS_ADD, zte_bind_static_address_add},
217 {GOFORM_BIND_STATIC_ADDRESS_DEL, zte_bind_static_address_del},
218 {GOFORM_ADD_CHILDREN_DEVICE, zte_add_children_device}, //¼Ò³¤¿ØÖÆ
219 {GOFORM_DEL_CHILDREN_DEVICE, zte_del_children_device},
220 {GOFORM_ADD_WHITE_SITE, zte_add_white_site},
221 {GOFORM_REMOVE_WHITE_SITE, zte_remove_white_site},
222 {GOFORM_PARENT_CONTROL_SET, zte_parent_control_set},
223 //{GOFORM_DDNS, zte_goform_ddns},
224 //{GOFORM_DNS_MODE_SET, zte_dns_mode_set}, //ÉèÖÃÊÖ¶¯DNS mode
225 //{GOFORM_DNS_SERVER_SET, zte_dns_server_set}, //ÉèÖÃÊÖ¶¯DNS server
226 /********** wan pppoe ***********/
227 {GOFORM_SET_OPERATION_MODE, zte_goform_set_operation_mode}, //RJ45ģʽÇл»ÉèÖÃ
228 {GOFORM_SET_WAN_GATEWAYMODE_PPPOE, zte_goform_set_wan_gatewaymode_PPPOE},
229 {GOFORM_SET_WAN_GATEWAYMODE_DHCP, zte_goform_set_wan_gatewaymode_DHCP},
230 {GOFORM_SET_WAN_GATEWAYMODE_STATIC, zte_goform_set_wan_gatewaymode_STATIC},
231 {GOFORM_SET_WAN_GATEWAYMODE_AUTO, zte_goform_set_wan_gatewaymode_AUTO},
232
233 /********** httpShare module ***********/
234 {GOFORM_HTTPSHARE_ENTERFOLD, zte_httpShare_enterFold}, //get SD's filelist
235 {GOFORM_HTTPSHARE_NEW, zte_httpShare_new}, //creat a new folder
236 {GOFORM_HTTPSHARE_DEL, zte_httpShare_del}, //delete file or folder
237 {GOFORM_HTTPSHARE_AUTH_SET, zte_httpShare_auth_set}, //httpshare setting
238 {GOFORM_HTTPSHARE_MODE_SET, zte_httpShare_modeset}, //set SD card's mode:usb mode or httpshare mode
239 {GOFORM_HTTPSHARE_FILE_RENAME, zte_httpShare_rename}, //rename the file
240 {GOFORM_HTTPSHARE_CHECK_FILE, zte_httpShare_check_file}, //check file exists
241
242 /********** PBM module ***********/
243 {GOFORM_PBM_CONTACT_ADD, zte_goform_pbm_contact_add_process},
244 {GOFORM_PBM_CONTACT_DEL, zte_goform_pbm_contact_del_process},
245
246 /********** sms module ***********/
247 {GOFORM_SMS_SET_MSG_CENTER, zte_sms_set_message_center},
248 {GOFORM_SMS_DELETE_SMS, zte_sms_delete_msg_process},
249 {GOFORM_SMS_DELETE_SMS_ALL, zte_goform_sms_alldel_msg_process},
250 {GOFORM_SMS_MOVE_TO_SIM, zte_sms_move_to_sim_msg_process},
251 {GOFORM_SMS_SAVE_SMS, zte_sms_save_msg_process},
252 {GOFORM_SMS_SEND_SMS, zte_sms_send_msg_process},
253 {GOFORM_SMS_SET_MSG_READ, zte_sms_view_msg_process},
254
255 /********** fota module ***********/
256 {GOFORM_SET_FOTAAUTOUPDATE, zte_fota_update}, //Óû§Ñ¡ÔñÊÇ·ñ½øÐÐÉý¼¶ºÍÉý¼¶ÖÐÈ¡Ïû
257 {GOFORM_SET_FOTASETTINGS, zte_fota_settings}, //×Ô¶¯¼ì²â
258
259 /********** ping test ***********/
260 //{GOFORM_PING_DIAGNOSTICS_START, zte_ping_diagnostics_start}, // ping°ü¼ì²â¹¦ÄÜ¿ªÆô
261 //{GOFORM_PING_DIAGNOSTICS_STOP, zte_ping_diagnostics_stop}, // ping°ü¼ì²â¹¦ÄܹرÕ
262
263 /********** ¿Í»§¶þ´Î¿ª·¢½Ó¿ÚÇëÔÚÏÂÃæÌí¼Ó ***********/
264 {GOFORM_SET_SAMPLE, zte_goform_set_sample}, //¿Í»§¶þ´Î¿ª·¢½Ó¿ÚʾÀý
265};
266
267/*******************************************************************************
268 * Local function implementations *
269 ******************************************************************************/
270
271//WH://»ñȡϵͳ×î½üÒ»´ÎÉϵçºó³ÖÐøÔËÐÐʱ¼ä
272static int getSysUptime(int eid, webs_t wp, int argc, char_t **argv)
273{
274 struct tm *utime;
275 time_t usecs;
276
277 char syn_system_total[20] = {0};
278 char syn_after_time[20] = {0};
279 int ltime = 0;
280 int ntime = 0;
281
282 sc_cfg_get("syn_system_total", syn_system_total, sizeof(syn_system_total));
283
284 sscanf(syn_system_total, "%d", &ltime);
285 if(ltime < 0 || ltime > INT_MAX-1) // kw 3
286 {
287 ltime = 0;
288 }
289 ltime += JAN_2000;
290
291 sc_cfg_get("syn_after_time", syn_after_time, sizeof(syn_after_time));
292
293 sscanf(syn_after_time, "%d", &ntime);
294 if(ntime < 0 || ntime > INT_MAX-1) // kw 3
295 {
296 ntime = 0;
297 }
298 time(&usecs);
299 if (ntime == 0) {
300 utime = localtime(&usecs);
301 } else {
302 time_t use;
303 use = (time_t)(usecs - ntime + ltime);
304 utime = localtime(&use);
305 }
306 if(utime == NULL)
307 return -1;
308 if (utime->tm_yday > 0) {
309 return websWrite(wp, T("%d day%s, %d hour%s, %d min%s, %d sec%s"),
310 utime->tm_yday, (utime->tm_yday == 1) ? "" : "s",
311 utime->tm_hour, ((utime->tm_hour == 1) || (utime->tm_hour == 0)) ? "" : "s",
312 utime->tm_min, ((utime->tm_min == 1) || (utime->tm_min == 0)) ? "" : "s",
313 utime->tm_sec, ((utime->tm_sec == 1) || (utime->tm_sec == 0)) ? "" : "s");
314 } else if (utime->tm_hour > 0) {
315 return websWrite(wp, T("%d hour%s, %d min%s, %d sec%s"),
316 utime->tm_hour, (utime->tm_hour == 1) ? "" : "s",
317 utime->tm_min, ((utime->tm_min == 1) || (utime->tm_min == 0)) ? "" : "s",
318 utime->tm_sec, ((utime->tm_sec == 1) || (utime->tm_sec == 0)) ? "" : "s");
319 } else if (utime->tm_min > 0) {
320 return websWrite(wp, T("%d min%s, %d sec%s"),
321 utime->tm_min, (utime->tm_min == 1) ? "" : "s",
322 utime->tm_sec, ((utime->tm_sec == 1) || (utime->tm_sec == 0)) ? "" : "s");
323 } else {
324 return websWrite(wp, T("%d sec%s"),
325 utime->tm_sec, ((utime->tm_sec == 1) || (utime->tm_sec == 0)) ? "" : "s");
326 }
327
328}
329
330static int zte_goform_whitelist_check(webs_t wp)
331{
332
333 char login_info[NV_ITEM_STRING_LEN_20] = {0};
334 char_t nv_ipaddr[40] = {0};
335 //zte_topsw_state_e_type status = ZTE_NVIO_MAX;
336 char_t *ip_address = NULL;
337
338 int result = FALSE;
339
340 zte_web_read(NV_LOGINFO, login_info);
341
342 //get request ip addr
343 ip_address = websGetRequestIpaddr(wp);
344#if 0 // kw 3 NVARIANT_CONDITION.UNREACH
345 if (NULL == ip_address) {
xf.libdd93d52023-05-12 07:10:14 -0700346 slog(MISC_PRINT, SLOG_ERR, "goform_whitelist_check: ip_address is null.\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700347 return FALSE;
348 }
349#endif
350 (void)zte_web_read(NV_USER_IP_ADDR, nv_ipaddr);
351 if ((0 == strncmp(login_info, "ok", sizeof(login_info))) && (0 == strncmp(ip_address, nv_ipaddr, sizeof(nv_ipaddr)))) {
352 result = TRUE; //to update the timemark
353 }
354 if (result == TRUE) {
355 if (!zte_mgmt_login_timemark_set()) {
xf.libdd93d52023-05-12 07:10:14 -0700356 slog(MISC_PRINT, SLOG_ERR, "[ERROR]goform_whitelist_check -> timemark set error .\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700357 }
358 }
359
360 return result;
361}
362
363/******************************************************
364* Function: zte_goform_blacklist_check
365* Description:goform entry for handling set cmd
366* Input: HTTP Request Info
367* Output:
368* Return:
369* Others:
370* Modify Date Version Author Modification
371* 2013/01/21 V1.0 Liuyingnan create
372*******************************************************/
373static int zte_goform_blacklist_check(webs_t wp)
374{
375 //char login_info[NV_ITEM_STRING_LEN_20] = {0};
376 char_t *zte_goform_id = NULL;
377 //zte_web_read(NV_LOGINFO, login_info);
378
379 zte_goform_id = websGetVar(wp, T("goformId"), T(""));
380 if (zte_goform_id == NULL) {
xf.libdd93d52023-05-12 07:10:14 -0700381 slog(MISC_PRINT, SLOG_ERR, "goform_whitelist_check: goform_id is null.\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700382 return -1;
383 }
384
385 if ((0 == strncmp(GOFORM_MGMT_SET_WEB_LANGUAGE, zte_goform_id, strlen(GOFORM_MGMT_SET_WEB_LANGUAGE)))
386 || (0 == strncmp(GOFORM_MGMT_LOGIN_IP, zte_goform_id, strlen(GOFORM_MGMT_LOGIN_IP)))
387 || (0 == strncmp(GOFORM_MGMT_ENTER_PIN, zte_goform_id, strlen(GOFORM_MGMT_ENTER_PIN)))
388 || (0 == strncmp(GOFORM_MGMT_ENTER_PUK, zte_goform_id, strlen(GOFORM_MGMT_ENTER_PUK)))
389 || (0 == strncmp(GOFORM_HTTPSHARE_CHECK_FILE, zte_goform_id, strlen(GOFORM_HTTPSHARE_CHECK_FILE)))
390 || (0 == strncmp(GOFORM_HTTPSHARE_ENTERFOLD, zte_goform_id, strlen(GOFORM_HTTPSHARE_ENTERFOLD)))
391 || (0 == strncmp(GOFORM_HTTPSHARE_FILE_RENAME, zte_goform_id, strlen(GOFORM_HTTPSHARE_FILE_RENAME)))
392 || (0 == strncmp(GOFORM_HTTPSHARE_NEW, zte_goform_id, strlen(GOFORM_HTTPSHARE_NEW)))
393 || (0 == strncmp(GOFORM_HTTPSHARE_DEL, zte_goform_id, strlen(GOFORM_HTTPSHARE_DEL)))
394#ifndef WEBS_SECURITY
395 || (0 == strncmp(GOFORM_MGMT_LOGOUT_IP, zte_goform_id, strlen(GOFORM_MGMT_LOGOUT_IP)))
396 || (0 == strncmp(GOFORM_MGMT_SET_DEVICEMODE, zte_goform_id, strlen(GOFORM_MGMT_SET_DEVICEMODE)))
397 || (0 == strncmp(GOFORM_MGMT_REBOOT, zte_goform_id, strlen(GOFORM_MGMT_REBOOT)))
398#endif
399 ) {
xf.libdd93d52023-05-12 07:10:14 -0700400 slog(MISC_PRINT, SLOG_DEBUG, "goform_whitelist_check: goform_id:[%s] is OK.\n", zte_goform_id); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700401 return 1;
402 } else {
xf.libdd93d52023-05-12 07:10:14 -0700403 slog(MISC_PRINT, SLOG_ERR, "goform_whitelist_check: goform_id:[%s] is black.\n", zte_goform_id); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700404 return -1;
405 }
406
407}
408
409static int isMobileReq(webs_t wp)
410{
411 int iMobileKW = 0;
412 const char MOBILE_KEYWORD[][MAX_MOBILE_KEY_WORD_SIZE] = {"Mobile", "mobile", "MOBILE"};
413
414 if (wp->userAgent == NULL) {
415 return 0;
416 }
417 for (iMobileKW = 0; iMobileKW < sizeof(MOBILE_KEYWORD) / MAX_MOBILE_KEY_WORD_SIZE; iMobileKW++) {
418 if (strstr(wp->userAgent, MOBILE_KEYWORD[iMobileKW]) != NULL) {
419 return 1;
420 }
421 }
422 return 0;
423}
424static int isPageExist(char *page)
425{
426 char *defaultDir = websGetDefaultDir();
427 char *fullPagePath = NULL;
428 int fullPathSize = 0;
429 int hasPageExist = 0;
430
431 if (defaultDir == NULL || page == NULL) {
432 return 0;
433 }
434 fullPathSize = strlen(defaultDir) + strlen(page) + 2;
435 fmtAlloc(&fullPagePath, fullPathSize, T("%s/%s"), defaultDir, page);
436 hasPageExist = (access(fullPagePath, F_OK) == 0);
437 bfreeSafe(B_L, fullPagePath);
438 return hasPageExist;
439}
440
441int is_print_str(char *str, int len)
442{
443 int i = 0;
444 if (str == NULL || len <= 0 || strlen(str) < len) {
445 return 0;
446 }
447 for (i = 0; i < len; i++) {
448 if (!isprint(str[i])) {
449 return 0;
450 }
451 if(str[i] == '%' && (i+2) < len && isxdigit(str[i+1]) && isxdigit(str[i+2]))
452 {
453 if(str[i+1] < '2' || str[i+1] > '7' ||(str[i+1] == '7' && (str[i+2] == 'f' || str[i+2] == 'F')))
454 {
455 return 0;
456 }
457 }
458 }
459 return 1;
460}
461
462/*******************************************************************************
463 * Global function implementations *
464 ******************************************************************************/
465
466/******************************************************
467* Function: void zte_web_init()
468* Description: the entry of zte code in goahead
469* Input:
470* Output:
471* Return:
472* Others:
473* Modify Date Version Author Modification
474* 2010/8/5 V1.0 LiuWei create
475* 2010/11/4 V1.1 ZYT modify
476*******************************************************/
477void zte_web_init()
478{
479 sc_cfg_set(NV_LOGINFO, "");
480 websFormDefine(T("proc_get"), zte_goform_get_cmd_process);
481 websFormDefine(T("proc_post"), zte_goform_set_cmd_process);
482 zte_init_login_psw_time(); //WH:³õʼ»¯×î´óµÇ½´ÎÊý
483}
484
485/*
486 * description: parse va and do system
487 */
488#if 0
489int doSystem(char_t *fmt, ...)
490{
491 va_list vargs;
492 char_t *cmd = NULL;
493 int rc = 0;
494
495 va_start(vargs, fmt);/*lint !e530*/
496 if (fmtValloc(&cmd, WEBS_BUFSIZE, fmt, vargs) >= WEBS_BUFSIZE) {
497 trace(0, T("doSystem: lost data, buffer overflow\n"));
498 }
499 va_end(vargs);
500
501 if (cmd) {
502 trace(0, T("%s\n"), cmd);
503 rc = system(cmd);
504 bfree(B_L, cmd);
505 }
506 return rc;
507}
508#endif
509/******************************************************
510* Function: void zte_webs_feedback_top(webs_t wp, char *fileName)
511* Description: feed back web page at top location
512* Input:
513* Output:
514* Return:
515* Others:
516* Modify Date Version Author Modification
517* 2010/9/10 V1.0 LiuWei create
518* 2010/11/15 V1.1 zyt modify
519*******************************************************/
520void zte_webs_feedback_top(webs_t i_wp, char *i_pageName)
521{
522 char dest_page[64] = {0};
523 char language[64] = {0};
524
525 if (NULL == i_pageName) {
xf.libdd93d52023-05-12 07:10:14 -0700526 slog(MISC_PRINT, SLOG_ERR, "webs_feedback_top para null.\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700527 return;
528 }
529
530 sc_cfg_get(NV_LANGUAGE, language, sizeof(language));
531 websWrite(i_wp, T("HTTP/1.1 200 OK\n"));
532 websWrite(i_wp, T("Pragma: no-cache\n"));
533 websWrite(i_wp, T("Cache-control: no-cache\n"));
534 websWrite(i_wp, T("Connection: Close\n"));
535 websWrite(i_wp, T("Content-Type: text/html\n"));
536 websWrite(i_wp, T("Set-Cookie: mLangage=%s;"" path=/;"" Expires=Mon, 1 Jan 2050 00:00:00 GMT\n"), language);
537 websWrite(i_wp, T("\n"));
538 websWrite(i_wp, T("<html>\n"));
539 websWrite(i_wp, T(zte_web_page_header));
540 websWrite(i_wp, T(zte_web_page_top), i_pageName);
541 websWrite(i_wp, T("</html>"));
542}
543
544
545
546/******************************************************
547* Function: zte_goform_get_cmd_process()
548* Description:goform entry from web pages to get fw para, call the related functions according to the cmd
549* Input: HTTP Request Info
550* Output:
551* Return:
552* Others:
553* Modify Date Version Author Modification
554* 2012/08/08 V1.0 liuyingnan create
555*******************************************************/
556void zte_goform_get_cmd_process(webs_t wp, char *path, char *query)
557{
558 char_t *cmd = NULL;
559 char_t *multi_data = NULL;
560 char login_info[NV_ITEM_STRING_LEN_20] = {0};
561 UINT32 ticks = 0;
562 int goform_index = 0;
563 int max_goform_index = (int)(sizeof(web_goform_get_cmd_table) / sizeof(web_goform_type));
564
565 zte_get_login_status_value(wp, login_info);
566
567 cmd = websGetVar(wp, T("cmd"), T(""));
568 multi_data = websGetVar(wp, T("multi_data"), T(""));
569
xf.libdd93d52023-05-12 07:10:14 -0700570 slog(MISC_PRINT, SLOG_DEBUG, "[goahead] goform_get_cmd_process multi_data = %s, cmd = %s\n", multi_data, cmd);
lh9ed821d2023-04-07 01:36:19 -0700571
572 zte_mgmt_login_timeout_check();
573
574 if (0 == strcmp(cmd, "")) {
575 websDone(wp, 0);
576 return;
577 }
578#ifdef WEBINSPECT_FIX
579 if (query && (strstr(query, "%3d%2f")
580 || strstr(query, "%3c%2f")
581 || strstr(query, "=/")
582 || strstr(query, "</")
583 || strstr(query, "%27")
584 || strstr(query, "'")
585#ifdef WEBS_SECURITY
586 || strstr(query, "%2f")
587 || strstr(query, "/")
588 || strstr(query, "%5c")
589 || strstr(query, "\\")
590 || strstr(query, "%3c")
591 || strstr(query, "<")
592 || strstr(query, "%3e")
593 || strstr(query, ">")
594 || strstr(query, "%28")
595 || strstr(query, "(")
596 || strstr(query, "%29")
597 || strstr(query, ")")
598 || strstr(query, "%25")
599#endif
600 )) {
601 //slog(MISC_PRINT, SLOG_ERR,"[goahead]e qry:%s\n",query);
602 slog(MISC_PRINT, SLOG_ERR,"[goahead]e 1\n");
603 websDone(wp, 0);
604 return;
605 }
606 if (strstr(cmd, "=/") || strstr(cmd, "</")
607#ifdef WEBS_SECURITY
608 || strstr(cmd, "/") || strstr(cmd, "\\") || strstr(cmd, "<") || strstr(cmd, ">")
609#endif
610 || strstr(cmd, "'")) {
611 //slog(MISC_PRINT, SLOG_ERR,"[goahead]e cmd:%s\n",cmd);
612 slog(MISC_PRINT, SLOG_ERR,"[goahead]e 2\n");
613 websDone(wp, 0);
614 return;
615 }
616#ifdef WEBS_SECURITY
617 char token[COOKIE_SESSION_SIZE+1] = {0};
618 char cook_id[COOKIE_SESSION_SIZE+1] = {0};
619 (void)zte_web_read(NV_COOKIE_ID, cook_id);
620 (void)zte_web_read(NV_WEB_TOKEN, token);
621 if (strlen(cook_id) && wp->cookie && strlen(wp->cookie) > strlen(token)
622 && (strstr(wp->cookie, token) == NULL)) {
623 //slog(MISC_PRINT, SLOG_ERR,"[goahead]e cmd:%s\n",cmd);
624 //slog(MISC_PRINT, SLOG_ERR,"[goahead]e token:%s\n",token);
625 //slog(MISC_PRINT, SLOG_ERR,"[goahead]e cookie:%s\n",wp->cookie);
626 slog(MISC_PRINT, SLOG_ERR,"[goahead]e 3\n");
627 websDone(wp, 0);
628 sc_cfg_set(NV_WEB_TOKEN, "");
629 return;
630 }
631 if(query && !is_print_str(query,strlen(query)))
632 {
633 slog(MISC_PRINT, SLOG_ERR,"[goahead]g print_str\n");
634 websDone(wp, 0);
635 return;
636 }
637#endif
638#endif
639 if ((0 == strcmp("ok", login_info)) || (0 == strcmp(GOFORM_HTTPSHARE_GETCARD_VAULE, cmd))) {
640 if (0 == strcmp(multi_data, "")) {
641 for (goform_index = 0; goform_index < max_goform_index; goform_index++) {
642 if (0 == strcmp(web_goform_get_cmd_table[goform_index].goform_id, cmd)) {
643 (*(web_goform_get_cmd_table[goform_index].proc_func))(wp);
644 websDone(wp, 200);
645 return;
646 }
647 }
648 zte_web_get_para_xml(wp, (char_t *)cmd);
649 } else {
650 zte_get_request_process_xml(wp, cmd);
651 }
652 } else {
653 if (0 == strcmp(multi_data, "")) {
654 zte_web_get_para_nologin(wp, (char_t *)cmd);
655 } else {
656 zte_get_request_process_nologin(wp, (char_t *)cmd);
657 }
658 }
659 websDone(wp, 0);
660 return;
661
662}
663
664/******************************************************
665* Function: zte_goform_set_cmd_process()
666* Description:goform entry from web pages to set firmware para
667* Input: HTTP Request Info
668* Output:
669* Return:
670* Others:
671* Modify Date Version Author Modification
672* 2012/08/08 V1.0 liuyingnan create
673*******************************************************/
674
675void zte_goform_set_cmd_process(webs_t wp, char *path, char *query)
676{
677 char_t *zte_goform_id = NULL;
678 int goform_index = 0;
679 int max_goform_index = (int)(sizeof(web_goform_set_cmd_table) / sizeof(web_goform_type));
680 int blacklist_result = 0;
681 char login_info[NV_ITEM_STRING_LEN_20] = {0};
682
683 zte_get_login_status_value(wp, login_info);
684 zte_goform_id = websGetVar(wp, T("goformId"), T(""));
685
xf.libdd93d52023-05-12 07:10:14 -0700686 slog(MISC_PRINT, SLOG_DEBUG,"[goahead] goform_set_cmd_process goform_id = %s,login_info=%s!\n", zte_goform_id, login_info);
lh9ed821d2023-04-07 01:36:19 -0700687#ifdef WEBINSPECT_FIX
688 if (query && (strstr(query, ")(")
689/* || strstr(query, "%26%26")
690 || strstr(query, "&&")
691 || strstr(query, "%7C%7C")
692 || strstr(query, "||")
693 || strstr(query, "%3B")
694 || strstr(query, ";")*/
695 )) {
696 //slog(MISC_PRINT, SLOG_ERR,"[goahead]e sqry:%s\n",query);
697 slog(MISC_PRINT, SLOG_ERR,"[goahead]e 4\n");
698 websDone(wp, 0);
699 return;
700 }
701#ifdef WEBS_SECURITY
702 if (!(wp->flags & WEBS_POST_REQUEST)||(query && (strstr(query, "%2f")
703 || strstr(query, "/")
704 || strstr(query, "%5c")
705 || strstr(query, "\\")
706 || strstr(query, "%3c")
707 || strstr(query, "<")
708 || strstr(query, "%3e")
709 || strstr(query, ">")
710 || strstr(query, "%27")
711 || strstr(query, "'")
712 || strstr(query, "%28")
713 || strstr(query, "(")
714 || strstr(query, "%29")
715 || strstr(query, ")")
716 || strstr(query, "%25")
717 ))) {
718 //slog(MISC_PRINT, SLOG_ERR,"[goahead]e qry:%s\n",query);
719 slog(MISC_PRINT, SLOG_ERR,"[goahead]e 5\n");
720 websDone(wp, 0);
721 return;
722 }
723 char token[COOKIE_SESSION_SIZE+1] = {0};
724 char cook_id[COOKIE_SESSION_SIZE+1] = {0};
725 (void)zte_web_read(NV_COOKIE_ID, cook_id);
726 (void)zte_web_read(NV_WEB_TOKEN, token);
727 if (strlen(cook_id) && wp->cookie && strlen(wp->cookie) > strlen(token)
728 && (strstr(wp->cookie, token) == NULL)) {
729 //slog(MISC_PRINT, SLOG_ERR,"[goahead]e goform:%s\n",zte_goform_id);
730 //slog(MISC_PRINT, SLOG_ERR,"[goahead]e token:%s\n",token);
731 //slog(MISC_PRINT, SLOG_ERR,"[goahead]e cookie:%s\n",wp->cookie);
732 slog(MISC_PRINT, SLOG_ERR,"[goahead]e 6\n");
733 websDone(wp, 0);
734 sc_cfg_set(NV_WEB_TOKEN, "");
735 return;
736 }
737 if(query && !is_print_str(query,strlen(query)))
738 {
739 slog(MISC_PRINT, SLOG_ERR,"[goahead]s print_str\n");
740 zte_write_result_to_web(wp, FAILURE);
741 websDone(wp, 200);
742 return;
743 }
744#endif
745#endif
746
747 if (0 != strcmp("ok", login_info)) {
748 blacklist_result = zte_goform_blacklist_check(wp);
749 if (blacklist_result < 0) {
xf.libdd93d52023-05-12 07:10:14 -0700750 slog(MISC_PRINT, SLOG_ERR,"[ERROR]goform_blacklist_check -> black goform id:[%s].\n", zte_goform_id);
lh9ed821d2023-04-07 01:36:19 -0700751 zte_write_result_to_web(wp, FAILURE);
752 websDone(wp, 200);
753 return;
754 }
755 }
756
757 zte_mgmt_login_timemark_set();
758
759 for (goform_index = 0; goform_index < max_goform_index; goform_index++) {
760 if (0 == strcmp(web_goform_set_cmd_table[goform_index].goform_id, zte_goform_id)) {
761 (void)zte_goform_whitelist_check(wp);//not to check the return value, only A has logged in,then update the timemark
762 (*(web_goform_set_cmd_table[goform_index].proc_func))(wp);
763 break;
764 }
765 }
766
767 if (goform_index == max_goform_index) {
xf.libdd93d52023-05-12 07:10:14 -0700768 slog(MISC_PRINT, SLOG_ERR,"[ERROR]goform_set_cmd_process -> unknown goform id:[%s].\n", zte_goform_id);
lh9ed821d2023-04-07 01:36:19 -0700769 zte_write_result_to_web(wp, FAILURE);
770 }
771
772 websDone(wp, 200);
773 return;
774}
775
776zte_topsw_state_e_type zte_nvconfig_read(char *item, char *data, int dataLen)
777{
778 if (NULL == item || NULL == data) {
779 slog(MISC_PRINT, SLOG_ERR, "input is NULL."); /*lint !e26*/
780 return ZTE_NVIO_FAIL;
781 }
782
783 if (dataLen > NV_ITEM_VALUE_MAX_LEN) {
784 slog(MISC_PRINT, SLOG_ERR, "data of [%s] too long.", item); /*lint !e26*/
785 return ZTE_NVIO_FAIL;
786 }
787 // kw 3
788 if(0 == sc_cfg_get(item, data, dataLen))
789 {
790 return ZTE_NVIO_DONE;
791 }
792
793 return ZTE_NVIO_FAIL;
794}
795
796zte_topsw_state_e_type zte_nvconfig_write(char *item, char *data, int dataLen)
797{
798 if (NULL == item || NULL == data) {
799 slog(MISC_PRINT, SLOG_ERR, "input is NULL."); /*lint !e26*/
800 return ZTE_NVIO_FAIL;
801 }
802
803 if ((strlen(data) + 1) > NV_ITEM_VALUE_MAX_LEN || dataLen > NV_ITEM_VALUE_MAX_LEN) {
804 slog(MISC_PRINT, SLOG_ERR, "value is too long, name=%s.", item); /*lint !e26*/
805 return ZTE_NVIO_FAIL;
806 }
807
808 if(0 == sc_cfg_set(item, data))
809 {
810 return ZTE_NVIO_DONE;
811 }
812
813 return ZTE_NVIO_FAIL;
814}
815
816void zte_init_login_psw_time(void)
817{
818 (void)zte_web_write("psw_fail_num_str", LOGIN_FAIL_TIMES);
819}
820
821void zte_goform_set_external_nv(webs_t wp)
822{
823 char_t *nv_name = NULL;
824 char_t *nv_value = NULL;
825 nv_name = websGetVar(wp, T("external_nv_name"), T(""));
826 nv_value = websGetVar(wp, T("external_nv_value"), T(""));
827
828 if (nv_value == NULL || nv_name == NULL) {
829 zte_write_result_to_web(wp, FAILURE);
830 return;
831 }
832
833 if (0 != strncmp(nv_name, "external", 8)) {
834 zte_write_result_to_web(wp, FAILURE);
835 return;
836 }
837
838 sc_cfg_set(nv_name, nv_value);
839 zte_write_result_to_web(wp, SUCCESS);
840}
841
842/**************************************************************************
843* º¯ÊýÃû³Æ: zte_web_get_login_page
844* ¹¦ÄÜÃèÊö: ×ÔÊÊÓ¦ÖÕ¶Ëä¯ÀÀÆ÷
845* ²ÎÊý˵Ã÷: (IN)
846* (OUT)
847* ·µ »Ø Öµ:
848* ÆäËü˵Ã÷:
849**************************************************************************/
850const char* zte_web_get_login_page(webs_t wp)
851{
852 if (isMobileReq(wp) && isPageExist(ZTE_WEB_MOBILE_PAGE_LOGIN_NAME)) {
853 return ZTE_WEB_MOBILE_PAGE_LOGIN_NAME;
854 } else {
855 return ZTE_WEB_PAGE_LOGIN_NAME;
856 }
857}
858
859
860