lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /************************************************************************ |
| 2 | * °æÈ¨ËùÓÐ (C)2010, ÉîÛÚÊÐÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£ |
| 3 | * |
| 4 | * ÎļþÃû³Æ£º zte_web_mgmt.c |
| 5 | * Îļþ±êʶ£º |
| 6 | * ÄÚÈÝÕªÒª£º |
| 7 | * ÆäËü˵Ã÷£º |
| 8 | * µ±Ç°°æ±¾£º V0.1 |
| 9 | * ×÷ Õߣº zyt |
| 10 | * Íê³ÉÈÕÆÚ£º 2010-11-06 |
| 11 | * |
| 12 | * Ð޸ļǼ1£º |
| 13 | * ÐÞ¸ÄÄÚÈÝ£º³õʼ°æ±¾ |
| 14 | |
| 15 | |
| 16 | * ECµ¥ºÅ:EC616000235556 ¿ª·¢¹ÊÕÏ |
| 17 | * ¹ÊÕÏÖ÷Ìâ:¿ª»ú¸üÐÂʧ°ÜºóÁ¢¼´ÖØÆô£¬ÖØÆôºóÈÔÏÔʾ¸üÐÂʧ°ÜÎÊÌâ / Ôö¼Ówebui fota´¦Àílog |
| 18 | * ÐÞ¸Äʱ¼ä:20140715 |
| 19 | ************************************************************************/ |
| 20 | #include <sys/time.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <string.h> |
| 23 | #include <pthread.h> |
| 24 | #include <dirent.h> |
| 25 | #include <stdlib.h> |
| 26 | |
| 27 | #include <signal.h> |
| 28 | #include <errno.h> |
| 29 | #include <unistd.h> |
| 30 | #include <sys/stat.h> |
| 31 | #include <sys/ipc.h> |
| 32 | #include <sys/msg.h> |
| 33 | |
| 34 | #include <openssl/aes.h> |
| 35 | |
| 36 | #include "zte_web_interface.h" |
| 37 | #include "zte_web_get_fw_para.h" |
| 38 | #include "zte_web_mgmt_wifi.h" |
| 39 | #include "fota_common.h" |
| 40 | #include "nv_api.h" |
| 41 | #include "libkey.h" |
| 42 | |
| 43 | /**************************************************************************** |
| 44 | * È«¾Ö±äÁ¿¶¨ÒåÇø |
| 45 | ****************************************************************************/ |
| 46 | /* password check result*/ |
| 47 | typedef enum _psw_check_result_type_t { |
| 48 | PSW_EMPTY = 0, |
| 49 | PSW_OK = 1, |
| 50 | PSW_TOO_LONG = 2, |
| 51 | PSW_TIME_OUT = 3, |
| 52 | PSW_OTHER = 4 |
| 53 | } psw_check_result_type_t; |
| 54 | |
| 55 | typedef enum { |
| 56 | PIN_MANAGE_DISABLE = 0, |
| 57 | PIN_MANAGE_ENABLE, |
| 58 | PIN_MANAGE_MODIFY |
| 59 | } emPIN_MANAGE_ACTION; |
| 60 | |
| 61 | typedef struct UNLOCK_PARA { |
| 62 | char unlock_code[20]; |
| 63 | } UNLOCK_PARA_ST; |
| 64 | |
| 65 | //quick setting |
| 66 | typedef void (*funcWPType)(webs_t); |
| 67 | |
| 68 | pthread_mutex_t g_login_timemark_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 69 | #define TIME_SEM_KEY_1 0x0A2B |
| 70 | #define TIME_SEM_KEY_2 0x3A4B |
| 71 | |
| 72 | //bsim |
| 73 | typedef struct |
| 74 | { |
| 75 | unsigned int pubKeyRsaE[32]; |
| 76 | unsigned int pubKeyRsaN[32]; |
| 77 | unsigned int secureFlag; |
| 78 | unsigned int pubKeyHash[4]; |
| 79 | unsigned int secureDevId[3]; |
| 80 | }T_ZDrvEfuse_Secure; |
| 81 | |
| 82 | #define EFUSE_IOC_MAGIC 'E' |
| 83 | #define EFUSE_GET_DATA _IOWR(EFUSE_IOC_MAGIC, 1, char *) |
| 84 | #define PPPOE_CODE_LEN 32 //webui limit 30 |
| 85 | |
| 86 | static unsigned char web_aes_key[16] = {0}; |
| 87 | |
| 88 | #define APNCONFIG_NUM_MAX 10 |
| 89 | //bsim end |
| 90 | |
| 91 | /**************************************************************************** |
| 92 | * staticº¯ÊýÉùÃ÷Çø |
| 93 | ****************************************************************************/ |
| 94 | void deal_quick_setup_apn_ex(webs_t wp); |
| 95 | void deal_quick_setup_wifi_basic(webs_t wp); |
| 96 | void deal_quick_setup_wifi_security(webs_t wp); |
| 97 | int zte_mgmt_handle_account(webs_t wp); |
| 98 | void zte_setLastLoginTime(); |
| 99 | int zte_checkLoginTime(); |
| 100 | void zte_reduct_login_times(); |
| 101 | psw_check_result_type_t zte_password_check(webs_t wp, char* psw); |
| 102 | static void wait_verify(char *wait_name, char *wait_value); |
| 103 | static void zte_mgmt_enable_pin(webs_t wp, char_t *old_pin); |
| 104 | static void zte_mgmt_modify_pin(webs_t wp, char_t *old_pin, char_t *new_pin); |
| 105 | void deal_quick_setup_wifi_basic(webs_t wp); |
| 106 | void deal_quick_setup_wifi_security(webs_t wp); |
| 107 | static void deal_quick_setup_wps(webs_t wp); |
| 108 | static char *split_str_by_sep(char *src, char *sep, char *dst, int len); |
| 109 | static void set_apn_to_cfg(APN_PROFILE *apn_profile, IPV6_APN_PROFILE *ipv6_apn_profile); |
| 110 | #ifdef WEBS_SECURITY |
| 111 | static void js_aes_wifi_encode(void); |
| 112 | #endif |
| 113 | |
| 114 | /* ¿ìËÙÉèÖà */ |
| 115 | const funcWPType G_ZQUICK_SET[MAX_QUICK_SET_NUM] = { |
| 116 | deal_quick_setup_apn_ex, |
| 117 | deal_quick_setup_wifi_basic, |
| 118 | deal_quick_setup_wifi_security, |
| 119 | zte_mgmt_handle_account, |
| 120 | quick_dhcp_set |
| 121 | }; |
| 122 | |
| 123 | /****************************************************** |
| 124 | * Function: void zte_mgmt_login(webs_t wp) |
| 125 | * Description: deal with the login goform |
| 126 | * Input: HTTP page info |
| 127 | * Output: |
| 128 | * Return: none |
| 129 | * Others: |
| 130 | * Modify Date Version Author Modification |
| 131 | * 2010/11/26 V1.0 zyt create |
| 132 | *******************************************************/ |
| 133 | void zte_mgmt_login(webs_t wp) |
| 134 | { |
| 135 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User login!\n")); |
| 136 | char_t *psw = NULL; |
| 137 | char_t *user = NULL; |
| 138 | char_t *save_flag = NULL; |
| 139 | char_t *ip_address = NULL; |
| 140 | |
| 141 | int user_name_len = 0; |
| 142 | char_t *pUser = NULL; |
| 143 | char user_name[CONFIG_DEFAULT_LENGTH] = {0}; |
| 144 | int zte_password_len = 0; |
| 145 | char_t *zte_password = NULL; |
| 146 | char zte_psw_admin[CONFIG_DEFAULT_LENGTH] = {0}; |
| 147 | psw_check_result_type_t psw_cheak_result = PSW_EMPTY; |
| 148 | char buf[CONFIG_DEFAULT_LENGTH] = {0}; |
| 149 | |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 150 | slog(MISC_PRINT, SLOG_DEBUG,"[login] mgmt_login enter====\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 151 | if (NULL == wp) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 152 | slog(MISC_PRINT, SLOG_ERR,"[login] mgmt_login: wp is null.");/*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 153 | zte_write_result_to_web(wp, LOGIN_FAIL); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | psw = websGetVar(wp, T("password"), T("")); |
| 158 | user = websGetVar(wp, T("username"), NULL); |
| 159 | |
| 160 | if ('\0' == (*psw)) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 161 | slog(MISC_PRINT, SLOG_ERR,"[login] mgmt_login: psw is empty.");/*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 162 | zte_write_result_to_web(wp, LOGIN_FAIL); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | if (user != NULL) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 167 | slog(MISC_PRINT, SLOG_DEBUG," mgmt_login user = %s\n", user); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 168 | pUser = (char *)zte_base64_decode((const unsigned char *)user, strlen(user), (unsigned int*)&user_name_len); |
| 169 | if (NULL == pUser) { |
| 170 | zte_write_result_to_web(wp, LOGIN_FAIL); |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | //strncpy(user_name, pUser, user_name_len); |
| 175 | if(user_name_len < sizeof(user_name)) |
| 176 | snprintf(user_name,user_name_len+1,"%s",pUser); |
| 177 | else |
| 178 | snprintf(user_name,sizeof(user_name),"%s",pUser); |
| 179 | free(pUser); |
| 180 | |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 181 | slog(MISC_PRINT, SLOG_DEBUG," mgmt_login user_name = %s\n", user_name); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 182 | sc_cfg_get("admin_user", buf, sizeof(buf)); |
| 183 | if (0 != strcmp(user_name, buf)) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 184 | slog(MISC_PRINT, SLOG_ERR," mgmt_login user_name fail \n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 185 | zte_write_result_to_web(wp, LOGIN_USER_NAME_NOT_EXSIT); |
| 186 | return; |
| 187 | } |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 188 | slog(MISC_PRINT, SLOG_DEBUG," mgmt_login uername correct \n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 189 | } |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 190 | slog(MISC_PRINT, SLOG_DEBUG,"[login] login1 -> password_encode:%s.\n", psw); /*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 191 | #ifdef WEBS_SECURITY |
| 192 | zte_password = js_aes_decode(psw, strlen(psw), (unsigned int*)&zte_password_len); |
| 193 | #else |
| 194 | zte_password = (char *)zte_base64_decode((const unsigned char *)psw, strlen(psw), (unsigned int*)&zte_password_len); |
| 195 | #endif |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 196 | slog(MISC_PRINT, SLOG_DEBUG,"[login] login2 -> password:%s.\n", zte_password); /*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 197 | |
| 198 | if (NULL == zte_password) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 199 | slog(MISC_PRINT, SLOG_ERR,"[login] mgmt_login: psw is empty.\n");/*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 200 | zte_write_result_to_web(wp, LOGIN_FAIL); |
| 201 | return; |
| 202 | } |
| 203 | //zte_password will long than zte_password_len, then strncpy zte_password_len data to zte_psw_admin |
| 204 | if(zte_password_len < sizeof(zte_psw_admin)) |
| 205 | snprintf(zte_psw_admin,zte_password_len+1,"%s",zte_password); |
| 206 | else |
| 207 | snprintf(zte_psw_admin,sizeof(zte_psw_admin),"%s",zte_password); |
| 208 | //strncpy(zte_psw_admin, zte_password, zte_password_len); |
| 209 | free(zte_password); |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 210 | slog(MISC_PRINT, SLOG_DEBUG,"[login] login3 -> psw_admin:%s.\n", zte_psw_admin); /*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 211 | psw_cheak_result = zte_password_check(wp, zte_psw_admin); |
| 212 | |
| 213 | if (psw_cheak_result != PSW_OK) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 214 | slog(MISC_PRINT, SLOG_ERR,"[login] mgmt_login psw_cheak_result != PSW_OK\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 215 | zte_write_result_to_web(wp, LOGIN_FAIL); |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | //get request ip addr |
| 220 | ip_address = websGetRequestIpaddr(wp); |
| 221 | #if 0 // kw 3 |
| 222 | if (NULL == ip_address) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 223 | slog(MISC_PRINT, SLOG_ERR,"[login] mgmt_login: ip_address is null.\n");/*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 224 | zte_write_result_to_web(wp, LOGIN_FAIL); |
| 225 | return; |
| 226 | } |
| 227 | #endif |
| 228 | //memset(&buf, 0, sizeof(buf)); |
| 229 | //sc_cfg_get("admin_Password", buf, sizeof(buf)); |
| 230 | //if (0 == strcmp(zte_psw_admin, buf)) { |
| 231 | if (0 == web_check_pwd(zte_psw_admin)) { |
| 232 | save_flag = websGetVar(wp, T("save_login"), T("")); |
| 233 | if (('\0' != (*save_flag)) && (IFSTREQUAL("1", save_flag))) { |
| 234 | sc_cfg_set("psw_save", zte_psw_admin); |
| 235 | } |
| 236 | } else { |
| 237 | zte_reduct_login_times(); |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 238 | slog(MISC_PRINT, SLOG_ERR,"[login] mgmt_login: error pass.");/*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 239 | zte_write_result_to_web(wp, LOGIN_BAD_PASSWORD); |
| 240 | security_log(MODULE_ID_WEB_CGI,"web login err pwd ip=%s",ip_address); |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | if (zte_mgmt_login_timemark_set()) { |
| 245 | char id[COOKIE_SESSION_SIZE+1] = {0}; |
| 246 | int ret = web_make_salt_base64(id, sizeof(id)); |
| 247 | if(ret == 0) |
| 248 | { |
| 249 | slog(MISC_PRINT, SLOG_ERR,"[login] web_get_cookie_id fail\n"); |
| 250 | zte_write_result_to_web(wp, LOGIN_FAIL); |
| 251 | return; |
| 252 | } |
| 253 | (void)zte_web_write(NV_USER_IP_ADDR, ip_address); |
| 254 | (void)zte_web_write(NV_LOGINFO, "ok"); |
| 255 | (void)zte_web_write("save_login", save_flag); |
| 256 | (void)zte_web_write("psw_fail_num_str", LOGIN_FAIL_TIMES); |
| 257 | (void)zte_web_write(NV_COOKIE_ID, id); |
| 258 | #ifdef WEBS_SECURITY |
| 259 | js_aes_wifi_encode(); |
| 260 | #endif |
| 261 | //zte_write_result_to_web(wp, LOGIN_SUCCESS); |
| 262 | websWrite(wp, T("HTTP/1.1 200 OK\n")); |
| 263 | websWrite(wp, T("Server: %s\r\n"), WEBS_NAME); |
| 264 | #ifdef WEBINSPECT_FIX |
| 265 | websWrite(wp, T("X-Frame-Options: SAMEORIGIN\n")); |
| 266 | #endif |
| 267 | websWrite(wp, T("Pragma: no-cache\n")); |
| 268 | websWrite(wp, T("Cache-control: no-cache\n")); |
| 269 | websWrite(wp, T("Content-Type: text/html\n")); |
| 270 | #ifdef WEBS_SECURITY |
| 271 | websWrite(wp, T("Expires: 0\n")); |
| 272 | if (websSSLIsOpen()) |
| 273 | websWrite(wp, T("Set-Cookie: id=%s; secure; HttpOnly; SameSite=Lax;\n"),id); |
| 274 | else |
| 275 | websWrite(wp, T("Set-Cookie: id=%s; HttpOnly; SameSite=Lax;\n"),id); |
| 276 | #endif |
| 277 | websWrite(wp, T("\n")); |
| 278 | if (wp->flags & WEBS_XML_CLIENT_REQUEST) { |
| 279 | zte_rest_result_write(wp, LOGIN_SUCCESS); |
| 280 | } else { |
| 281 | websWrite(wp, T("{\"result\":\"%s\"}"), LOGIN_SUCCESS); |
| 282 | } |
| 283 | security_log(MODULE_ID_WEB_CGI,"web login suc ip=%s",ip_address); |
| 284 | return; |
| 285 | } else { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 286 | slog(MISC_PRINT, SLOG_ERR,"[login] mgmt_login_timemark_set fail\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 287 | zte_write_result_to_web(wp, LOGIN_FAIL); |
| 288 | return; |
| 289 | } |
| 290 | } |
| 291 | /****************************************************** |
| 292 | * Function: int zte_mgmt_login_timemark_set() |
| 293 | * Description: save the setting operate time |
| 294 | * Input: |
| 295 | * Output: |
| 296 | * Return: none |
| 297 | * Others: |
| 298 | * Modify Date Version Author Modification |
| 299 | *******************************************************/ |
| 300 | int zte_mgmt_login_timemark_set() |
| 301 | { |
| 302 | char_t login_timemark[NV_ITEM_STRING_LEN_64] = {0}; |
| 303 | long timemark = 0; |
| 304 | int sem_id = -1; |
| 305 | |
| 306 | int rc = TRUE; |
| 307 | |
| 308 | sem_id = get_sem(TIME_SEM_KEY_2); |
| 309 | if (sem_id != -1) { |
| 310 | sem_p(sem_id); |
| 311 | } |
| 312 | |
| 313 | timemark = time(0); |
| 314 | sprintf(login_timemark, "%ld", timemark); |
| 315 | if(ZTE_NVIO_DONE != zte_web_write(NV_USER_LOGIN_TIMEMARK, login_timemark)) |
| 316 | { |
| 317 | rc = FALSE; // kw 3 |
| 318 | } |
| 319 | |
| 320 | if (sem_id != -1) { |
| 321 | sem_v(sem_id); |
| 322 | } |
| 323 | |
| 324 | return rc; |
| 325 | } |
| 326 | void zte_mgmt_login_timeout_check() |
| 327 | { |
| 328 | char_t user_login_timemark[NV_ITEM_STRING_LEN_64] = {0}; |
| 329 | char_t login_info[NV_ITEM_STRING_LEN_20] = {0}; |
| 330 | |
| 331 | long time_now = 0; |
| 332 | int sem_id = -1; |
| 333 | long luser_login_timemark = 0; |
| 334 | |
| 335 | zte_web_read(NV_LOGINFO, login_info); |
| 336 | |
| 337 | if (0 == strcmp(login_info, "ok")) { |
| 338 | zte_web_read(NV_USER_LOGIN_TIMEMARK, user_login_timemark); |
| 339 | luser_login_timemark = atol(user_login_timemark); |
| 340 | if(luser_login_timemark < 0 || luser_login_timemark > LONG_MAX-1){ |
| 341 | luser_login_timemark = LONG_MAX; |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 342 | slog(MISC_PRINT, SLOG_DEBUG, "mgmt_login_timemark_check: user_login_timemark is out of range [0, LONG_MAX)."); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | sem_id = get_sem(TIME_SEM_KEY_2); |
| 346 | if (sem_id != -1) { |
| 347 | sem_p(sem_id); |
| 348 | } |
| 349 | //timemark_check = time(0) - luser_login_timemark; |
| 350 | time_now = time(0); |
| 351 | if (sem_id != -1) { |
| 352 | sem_v(sem_id); |
| 353 | } |
| 354 | |
| 355 | if ((time_now - luser_login_timemark) > LOGIN_TIMEOUT) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 356 | slog(MISC_PRINT, SLOG_DEBUG, "mgmt_login_timemark_check: the login is timeout ."); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 357 | (void)zte_web_write(NV_USER_IP_ADDR, ""); |
| 358 | (void)zte_web_write(NV_LOGINFO, "timeout"); |
| 359 | (void)zte_web_write(NV_COOKIE_ID, ""); |
| 360 | (void)zte_web_write(NV_WEB_TOKEN, ""); |
| 361 | (void)zte_web_write(NV_USER_LOGIN_TIMEMARK, "0"); |
| 362 | security_log(MODULE_ID_WEB_CGI,"web logout timeout"); |
| 363 | return; |
| 364 | } |
| 365 | #ifdef WEBS_SECURITY |
| 366 | static long time_update_token = 0; |
| 367 | if ((time_now - time_update_token) > COOKIE_TOKEN_TIMEOUT) { |
| 368 | time_update_token = time_now; |
| 369 | (void)zte_web_write(NV_WEB_TOKEN, ""); |
| 370 | } |
| 371 | #endif |
| 372 | } |
| 373 | |
| 374 | } |
| 375 | /****************************************************** |
| 376 | * Function: void zte_mgmt_logout(webs_t wp) |
| 377 | * Description: deal with the logout goform |
| 378 | * Input: HTTP page info |
| 379 | * Output: |
| 380 | * Return: none |
| 381 | * Others: |
| 382 | * Modify Date Version Author Modification |
| 383 | * 2010/11/26 V1.0 zyt create |
| 384 | *******************************************************/ |
| 385 | void zte_mgmt_logout(webs_t wp) |
| 386 | { |
| 387 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User logout!\n")); |
| 388 | |
| 389 | if (NULL == wp) { |
| 390 | zte_write_result_to_web(wp, FAILURE); |
| 391 | return; |
| 392 | } |
| 393 | |
| 394 | sc_cfg_set(NV_USER_IP_ADDR, ""); |
| 395 | sc_cfg_set(NV_LOGINFO, ""); |
| 396 | sc_cfg_set(NV_COOKIE_ID, ""); |
| 397 | sc_cfg_set(NV_WEB_TOKEN, ""); |
| 398 | zte_write_result_to_web(wp, SUCCESS); |
| 399 | security_log(MODULE_ID_WEB_CGI,"web logout"); |
| 400 | } |
| 401 | |
| 402 | /****************************************************** |
| 403 | * Function: void zte_mgmt_set_language(webs_t wp) |
| 404 | * Description: deal with the set language goform |
| 405 | * Input: HTTP page info |
| 406 | * Output: |
| 407 | * Return: none |
| 408 | * Others: |
| 409 | * Modify Date Version Author Modification |
| 410 | * 2010/11/26 V1.0 zyt create |
| 411 | *2012/09/14 liuyingnan modification |
| 412 | *******************************************************/ |
| 413 | void zte_mgmt_set_language(webs_t wp) |
| 414 | { |
| 415 | char_t* language = websGetVar(wp, T("Language"), T("en")); |
| 416 | |
| 417 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User set language!\n")); |
| 418 | |
| 419 | sc_cfg_set(NV_LANGUAGE, language); |
| 420 | |
| 421 | //sc_cfg_save(); |
| 422 | if ('\0' == (*language)) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 423 | slog(MISC_PRINT, SLOG_ERR, "mgmt_set_language: web para:[language] is empty string.\n"); /*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 424 | zte_write_result_to_web(wp, FAILURE); |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | |
| 429 | zte_write_result_to_web(wp, SUCCESS); |
| 430 | return; |
| 431 | |
| 432 | |
| 433 | } |
| 434 | |
| 435 | |
| 436 | /****************************************************** |
| 437 | * Function: void zte_mgmt_set_devicemode(webs_t wp) |
| 438 | * Description: user/develop mode switch |
| 439 | * Input: HTTP page info(debug_enable = 1 develop mode) |
| 440 | * Output: |
| 441 | * Return: none |
| 442 | * Others: |
| 443 | * Modify Date Version Author Modification |
| 444 | * Feb 27, 2014 V1.0 jhy create |
| 445 | *******************************************************/ |
| 446 | void zte_mgmt_set_devicemode(webs_t wp) |
| 447 | { |
| 448 | char_t* debug_enable = websGetVar(wp, T("debug_enable"), T("")); |
| 449 | char_t* auth = websGetVar(wp, T("auth"), T("")); |
| 450 | |
| 451 | char strCfgGetItem[16] = {0}; |
| 452 | nv_get_item(NV_RO, "usb_modetype", strCfgGetItem, sizeof(strCfgGetItem)); |
| 453 | |
| 454 | slog(MISC_PRINT, SLOG_NORMAL,"[goahead]debug_enable->%s current->%s\n", debug_enable, strCfgGetItem); |
| 455 | if((strcmp(strCfgGetItem,"user")== 0)&&(atoi(debug_enable) != 0)) |
| 456 | { |
| 457 | /* if(verify_device_key(auth,strlen(auth),SEED,strlen(SEED)) != 1) |
| 458 | { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 459 | slog(MISC_PRINT, SLOG_ERR, "mgmt_set_devicemode: auth %s fail.\n",auth); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 460 | zte_write_result_to_web(wp, "set_devicemode fail:auth fail!"); |
| 461 | return; |
| 462 | }*/ |
| 463 | } |
| 464 | |
| 465 | if ('\0' == (*debug_enable)) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 466 | slog(MISC_PRINT, SLOG_ERR, "mgmt_set_devicemode: web para:[debug_enable] is empty string.\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 467 | zte_write_result_to_web(wp, "set_devicemode fail:parameter debug_enable is empty!"); |
| 468 | return; |
| 469 | } |
| 470 | |
| 471 | if (atoi(debug_enable) < 0 || atoi(debug_enable) > 3) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 472 | slog(MISC_PRINT, SLOG_ERR, "mgmt_set_devicemode: web para:[debug_enable] is illegal string.\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 473 | zte_write_result_to_web(wp, "set_devicemode fail:parameter debug_enable is illegal!"); |
| 474 | return; |
| 475 | } |
| 476 | char ss[20] = {0}; |
| 477 | unsigned char bootmode[] = {0x54,0x4D}; |
| 478 | switch (atoi(debug_enable)) { |
| 479 | case 0: |
| 480 | slog(MISC_PRINT, SLOG_NORMAL,"[goahead]debug_enable->user\n"); |
| 481 | nv_set_item(NV_RO, "usb_modetype", "user", 1); |
| 482 | bootmode[1] =0x00; |
| 483 | amt_set_bootmode(bootmode); |
| 484 | break; |
| 485 | case 1: |
| 486 | slog(MISC_PRINT, SLOG_NORMAL,"[goahead]debug_enable->debug\n"); |
| 487 | nv_set_item(NV_RO, "usb_modetype", "debug", 1); |
| 488 | bootmode[1] =0x01; |
| 489 | amt_set_bootmode(bootmode); |
| 490 | break; |
| 491 | case 2: |
| 492 | slog(MISC_PRINT, SLOG_NORMAL,"[goahead]debug_enable->factory\n"); |
| 493 | nv_set_item(NV_RO, "usb_modetype", "factory", 1); |
| 494 | bootmode[1] =0x02; |
| 495 | amt_set_bootmode(bootmode); |
| 496 | break; |
| 497 | case 3: |
| 498 | slog(MISC_PRINT, SLOG_NORMAL,"[goahead]debug_enable->amt\n"); |
| 499 | //nv_set_item(NV_RO, "usb_modetype", "amt", 1); |
| 500 | amt_set_bootmode(bootmode); |
| 501 | break; |
| 502 | default: |
| 503 | slog(MISC_PRINT, SLOG_NORMAL,"[goahead]error!\n"); |
| 504 | zte_write_result_to_web(wp, "set_devicemode fail:parameter debug_enable is illegal!"); |
| 505 | return;; |
| 506 | } |
| 507 | nv_commit(NV_RO);////default_parameter_roÖеÄNV±£´æ±ØÐëÓÃnv_commit²»ÄÜÓÃsc_cfg_save |
| 508 | zte_write_result_to_web(wp, "set_devicemode successfully!"); |
| 509 | |
| 510 | } |
| 511 | |
| 512 | /****************************************************** |
| 513 | * Function: void zte_mgmt_restore(webs_t wp) |
| 514 | * Description: deal with the restore goform |
| 515 | * Input: HTTP page info |
| 516 | * Output: |
| 517 | * Return: none |
| 518 | * Others: |
| 519 | * Modify Date Version Author Modification |
| 520 | * 2010/11/26 V1.0 zyt create |
| 521 | *******************************************************/ |
| 522 | void zte_mgmt_restore(webs_t wp) |
| 523 | { |
| 524 | slog(MISC_PRINT, SLOG_NORMAL,"webui reset send message to blc\n"); |
| 525 | ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_RESET_REQUEST, 0, NULL, 0); |
| 526 | system("sleep 2");//WH:delete? |
| 527 | zte_write_result_to_web(wp, SUCCESS); |
| 528 | } |
| 529 | |
| 530 | |
| 531 | /****************************************************** |
| 532 | * Function: void zte_mgmt_poweroff(webs_t wp) |
| 533 | * Description: deal with the poweroff goform |
| 534 | * Input: HTTP page info |
| 535 | * Output: |
| 536 | * Return: none |
| 537 | * Others: |
| 538 | * Modify Date Version Author Modification |
| 539 | * 2015/5/26 V1.0 lsl create |
| 540 | *******************************************************/ |
| 541 | void zte_mgmt_poweroff(webs_t wp) |
| 542 | { |
| 543 | zte_write_result_to_web(wp, SUCCESS); |
| 544 | slog(MISC_PRINT, SLOG_NORMAL,"webui poweroff send message to blc\n"); |
| 545 | ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_POWEROFF_REQUEST, 0, NULL, 0); |
| 546 | } |
| 547 | |
| 548 | /****************************************************** |
| 549 | * Function: void zte_mgmt_control_power_on_speed(webs_t wp) |
| 550 | * Description: deal with the power_on_speed goform |
| 551 | * Input: HTTP page info |
| 552 | * Output: |
| 553 | * Return: none |
| 554 | * Others: |
| 555 | * Modify Date Version Author Modification |
| 556 | * 2015/5/26 V1.0 lsl create |
| 557 | *******************************************************/ |
| 558 | void zte_mgmt_control_power_on_speed(webs_t wp) |
| 559 | { |
| 560 | char_t* mgmt_quicken_power_on = websGetVar(wp, T("mgmt_quicken_power_on"), T("")); |
| 561 | |
| 562 | if ('\0' == (*mgmt_quicken_power_on)) { |
| 563 | zte_write_result_to_web(wp, FAILURE); |
| 564 | return; |
| 565 | } else if (strcmp(mgmt_quicken_power_on, "0") != 0 && strcmp(mgmt_quicken_power_on, "1") != 0) { |
| 566 | zte_write_result_to_web(wp, FAILURE); |
| 567 | return; |
| 568 | } |
| 569 | |
| 570 | sc_cfg_set("mgmt_quicken_power_on", mgmt_quicken_power_on); |
| 571 | |
| 572 | zte_write_result_to_web(wp, SUCCESS); |
| 573 | } |
| 574 | |
| 575 | /****************************************************** |
| 576 | * Function: void zte_goform_mgmt_reboot_process(webs_t wp) |
| 577 | * Description: deal with the restore goform |
| 578 | * Input: HTTP page info |
| 579 | * Output: |
| 580 | * Return: none |
| 581 | * Others: |
| 582 | * Modify Date Version Author Modification |
| 583 | * 2010/11/26 V1.0 zyt create |
| 584 | *******************************************************/ |
| 585 | void zte_goform_mgmt_reboot_process(webs_t wp) |
| 586 | { |
| 587 | MSG_BUF stMsg = {0}; |
| 588 | SINT32 iMsgSize = sizeof(MSG_BUF) - sizeof(SINT32); |
| 589 | char buf[NV_ITEM_STRING_LEN_20] = {0}; |
| 590 | |
| 591 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User reboot!\n")); |
| 592 | ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_RESTART_REQUEST, 0, NULL, 0); |
| 593 | } |
| 594 | |
| 595 | |
| 596 | void zte_goform_mgmt_syslog_process(webs_t wp) |
| 597 | { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 598 | slog(MISC_PRINT, SLOG_DEBUG, "goform_mgmt_syslog_process coming\n"); /*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 599 | char_t *syslog_mode = NULL; |
| 600 | /* get value from web page */ |
| 601 | syslog_mode = websGetVar(wp, T("syslog_mode"), T("all")); |
| 602 | |
| 603 | char_t *syslog_flag = NULL; |
| 604 | /* get value from web page */ |
| 605 | syslog_flag = websGetVar(wp, T("syslog_flag"), T("close")); |
| 606 | |
| 607 | if (strcmp(syslog_flag, "close") == 0) { |
| 608 | sc_cfg_set("debug_level", "0"); |
| 609 | zte_write_result_to_web(wp, SUCCESS); |
| 610 | } else if (strcmp(syslog_flag, "delete") == 0) { |
| 611 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User delete syslog!\n")); |
| 612 | slog(MISC_PRINT, SLOG_DEBUG, "delete syslog====\n"); /*lint !e26*/ |
| 613 | //system("cat /dev/null > /var/log/webshow_messages"); |
| 614 | system("cat /dev/null > /usr/netlog/misc.log"); |
| 615 | system("cat /dev/null > /etc_ro/web/webshow_messages"); |
| 616 | |
| 617 | zte_write_result_to_web(wp, SUCCESS); |
| 618 | } else { |
| 619 | //sc_cfg_set("debug_level","7");/*added by jhy */ |
| 620 | if (0 == strcmp("ufi", syslog_mode)) { |
| 621 | slog(MISC_PRINT, SLOG_DEBUG, "syslog_mode=====%s\n", syslog_mode); /*lint !e26*/ |
| 622 | system("mkdir -p /etc_ro/web"); |
| 623 | system("log.sh UFI"); |
| 624 | sc_cfg_set("syslog_mode", "ufi"); |
| 625 | }/*added by jhy */ |
| 626 | else if (0 == strcmp("wan_connect", syslog_mode)) { |
| 627 | slog(MISC_PRINT, SLOG_DEBUG, "syslog_mode=====%s\n", syslog_mode); /*lint !e26*/ |
| 628 | system("log.sh wan_connect info"); |
| 629 | sc_cfg_set("syslog_mode", "wan_connect"); |
| 630 | } else if (0 == strcmp("voip", syslog_mode)) { |
| 631 | slog(MISC_PRINT, SLOG_DEBUG, "syslog_mode=====%s\n", syslog_mode); /*lint !e26*/ |
| 632 | system("log.sh voip info"); |
| 633 | sc_cfg_set("syslog_mode", "voip"); |
| 634 | } else if (0 == strcmp("sms", syslog_mode)) { |
| 635 | slog(MISC_PRINT, SLOG_DEBUG, "syslog_mode=====%s\n", syslog_mode); /*lint !e26*/ |
| 636 | system("log.sh sms info"); |
| 637 | sc_cfg_set("syslog_mode", "sms"); |
| 638 | } else if (0 == strcmp("tr069", syslog_mode)) { |
| 639 | slog(MISC_PRINT, SLOG_DEBUG, "syslog_mode=====%s\n", syslog_mode); /*lint !e26*/ |
| 640 | system("log.sh tr069 info"); |
| 641 | sc_cfg_set("syslog_mode", "tr069"); |
| 642 | } else if (0 == strcmp("dlna", syslog_mode)) { |
| 643 | slog(MISC_PRINT, SLOG_DEBUG, "syslog_mode=====%s\n", syslog_mode); /*lint !e26*/ |
| 644 | system("log.sh dlna info"); |
| 645 | sc_cfg_set("syslog_mode", "dlna"); |
| 646 | } else if (0 == strcmp("wlan", syslog_mode)) { |
| 647 | slog(MISC_PRINT, SLOG_DEBUG, "syslog_mode=====%s\n", syslog_mode); /*lint !e26*/ |
| 648 | system("log.sh wlan info"); |
| 649 | sc_cfg_set("syslog_mode", "wlan"); |
| 650 | } else if (0 == strcmp("router", syslog_mode)) { |
| 651 | slog(MISC_PRINT, SLOG_DEBUG, "syslog_mode=====%s\n", syslog_mode); /*lint !e26*/ |
| 652 | system("log.sh router info"); |
| 653 | sc_cfg_set("syslog_mode", "router"); |
| 654 | } else { |
| 655 | slog(MISC_PRINT, SLOG_DEBUG, "syslog_mode=====%s\n", syslog_mode); /*lint !e26*/ |
| 656 | system("log.sh all info"); |
| 657 | sc_cfg_set("syslog_mode", "all"); |
| 658 | } |
| 659 | |
| 660 | zte_write_result_to_web(wp, SUCCESS); |
| 661 | } |
| 662 | |
| 663 | } |
| 664 | |
| 665 | |
| 666 | /****************************************************** |
| 667 | * Function: void zte_mgmt_change_password(webs_t wp) |
| 668 | * Description: deal with the user account modify goform |
| 669 | * Input: HTTP page info |
| 670 | * Output: |
| 671 | * Return: none |
| 672 | * Others: |
| 673 | * Modify Date Version Author Modification |
| 674 | * 2010/11/26 V1.0 zyt create |
| 675 | *******************************************************/ |
| 676 | void zte_mgmt_change_password(webs_t wp) |
| 677 | { |
| 678 | char_t *old_pass = NULL; |
| 679 | char_t *new_pass = NULL; |
| 680 | char_t *current_psw = NULL; |
| 681 | char_t *new_psw = NULL; |
| 682 | int current_psw_len = 0; |
| 683 | int new_psw_len = 0; |
| 684 | char new_psw_admin[CONFIG_DEFAULT_LENGTH] = {0}; |
| 685 | char old_psw_admin[CONFIG_DEFAULT_LENGTH] = {0}; |
| 686 | //char admin_psw_buf[CONFIG_DEFAULT_LENGTH] = {0}; |
| 687 | |
| 688 | old_pass = websGetVar(wp, T("oldPassword"), T("")); |
| 689 | new_pass = websGetVar(wp, T("newPassword"), T("")); |
| 690 | |
| 691 | if (0 == strlen(old_pass) || 0 == strlen(new_pass)) { |
| 692 | zte_write_result_to_web(wp, FAILURE); |
| 693 | return; |
| 694 | } |
| 695 | |
| 696 | slog(MISC_PRINT, SLOG_DEBUG, "user_modify:new_psw_encode:%s\n", new_pass); /*lint !e26*/ |
| 697 | #ifdef WEBS_SECURITY |
| 698 | current_psw = js_aes_decode(old_pass, strlen(old_pass), (unsigned int *)¤t_psw_len); |
| 699 | new_psw = js_aes_decode(new_pass, strlen(new_pass), (unsigned int *)&new_psw_len); |
| 700 | #else |
| 701 | current_psw = (char*)zte_base64_decode((const unsigned char *)old_pass, strlen(old_pass), (unsigned int *)¤t_psw_len); |
| 702 | new_psw = (char*)zte_base64_decode((const unsigned char *)new_pass, strlen(new_pass), (unsigned int *)&new_psw_len); |
| 703 | #endif |
| 704 | |
| 705 | if (NULL == current_psw || NULL == new_psw) { |
| 706 | slog(MISC_PRINT, SLOG_ERR, "current_psw or new_psw is NULL\n"); /*lint !e26*/ |
| 707 | zte_write_result_to_web(wp, FAILURE); |
| 708 | free(current_psw); |
| 709 | free(new_psw); |
| 710 | return; |
| 711 | } |
| 712 | slog(MISC_PRINT, SLOG_DEBUG, "user_modify:new_psw:%s\n", new_psw); /*lint !e26*/ |
| 713 | slog(MISC_PRINT, SLOG_DEBUG, "user_modify:new_psw_len:%d\n", new_psw_len); /*lint !e26*/ |
| 714 | if(current_psw_len < sizeof(old_psw_admin)) |
| 715 | snprintf(old_psw_admin,current_psw_len+1,"%s",current_psw); |
| 716 | else |
| 717 | snprintf(old_psw_admin,sizeof(old_psw_admin),"%s",current_psw); |
| 718 | //strncpy(old_psw_admin, current_psw, CONFIG_DEFAULT_LENGTH-1); |
| 719 | if(new_psw_len < sizeof(new_psw_admin)) |
| 720 | snprintf(new_psw_admin,new_psw_len+1,"%s",new_psw); |
| 721 | else |
| 722 | snprintf(new_psw_admin,sizeof(new_psw_admin),"%s",new_psw); |
| 723 | //strncpy(new_psw_admin, new_psw, CONFIG_DEFAULT_LENGTH-1); |
| 724 | free(current_psw); |
| 725 | free(new_psw); |
| 726 | slog(MISC_PRINT, SLOG_DEBUG, "user_modify:new_psw_admin:%s\n", new_psw_admin); /*lint !e26*/ |
| 727 | |
| 728 | if (LOGIN_PSW_MIN_LEN > new_psw_len || LOGIN_PSW_MAX_LEN < new_psw_len) { |
| 729 | slog(MISC_PRINT, SLOG_ERR, "new_psw_len is too long\n"); /*lint !e26*/ |
| 730 | sc_cfg_set("data_safe", "failed"); |
| 731 | zte_write_result_to_web(wp, FAILURE); |
| 732 | return; |
| 733 | } |
| 734 | if (DATA_NO_SAFE == zte_Safe_noSpecialChar(old_psw_admin) |
| 735 | || DATA_NO_SAFE == zte_Safe_noSpecialChar(new_psw_admin)) { |
| 736 | slog(MISC_PRINT, SLOG_ERR, "Get Data is no Safe:old_pass:%s,new_pass:%s\n", old_psw_admin, new_psw_admin); /*lint !e26*/ |
| 737 | sc_cfg_set("data_safe", "failed"); |
| 738 | zte_write_result_to_web(wp, FAILURE); |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | //sc_cfg_get("admin_Password", admin_psw_buf, sizeof(admin_psw_buf)); |
| 743 | //if (0 != strcmp(old_psw_admin, admin_psw_buf)) { |
| 744 | if (0 != web_check_pwd(old_psw_admin)) { |
| 745 | #ifdef WEBS_SECURITY |
| 746 | sc_cfg_set(NV_USER_IP_ADDR, ""); |
| 747 | sc_cfg_set(NV_LOGINFO, ""); |
| 748 | sc_cfg_set(NV_COOKIE_ID, ""); |
| 749 | sc_cfg_set(NV_WEB_TOKEN, ""); |
| 750 | security_log(MODULE_ID_WEB_CGI,"web changepwd fail logout"); |
| 751 | #endif |
| 752 | zte_write_result_to_web(wp, FAILURE); |
| 753 | return; |
| 754 | } |
| 755 | |
| 756 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User change passwd!\n")); |
| 757 | |
| 758 | //sc_cfg_set("admin_Password", new_psw_admin); |
| 759 | web_set_pwd(new_psw_admin); |
| 760 | //sc_cfg_set("user_save", ""); |
| 761 | sc_cfg_set("psw_save", ""); |
| 762 | sc_cfg_set("save_login", ""); |
| 763 | sc_cfg_set("psw_changed", "1");/*³õʼÃÜÂëÐ޸ıêʶ*/ |
| 764 | /* |
| 765 | char cmd[82] = {0}; |
| 766 | sprintf(cmd, "mksmbpasswd.sh \'%s\'", new_psw_admin); |
| 767 | system(cmd); |
| 768 | system("killall smbd"); |
| 769 | system("killall nmbd"); |
| 770 | system("smbd -D"); |
| 771 | system("nmbd -D"); |
| 772 | */ |
| 773 | zte_write_result_to_web(wp, SUCCESS); |
| 774 | } |
| 775 | |
| 776 | int zte_mgmt_check_password(webs_t wp) |
| 777 | { |
| 778 | char_t *tmp_old_psw = NULL; |
| 779 | char_t *old_psw = NULL; |
| 780 | int old_psw_len = 0; |
| 781 | char old_psw_admin[CONFIG_DEFAULT_LENGTH] = {0}; |
| 782 | //char admin_psw_buf[CONFIG_DEFAULT_LENGTH] = {0}; |
| 783 | |
| 784 | tmp_old_psw = websGetVar(wp, T("oldPassword"), NULL); |
| 785 | if (NULL != tmp_old_psw) { |
| 786 | old_psw = (char*)zte_base64_decode((const unsigned char *)tmp_old_psw, strlen(tmp_old_psw), (unsigned int *)&old_psw_len); |
| 787 | if (NULL == old_psw) { |
| 788 | slog(MISC_PRINT, SLOG_DEBUG, "current_psw or new_psw is NULL\n"); /*lint !e26*/ |
| 789 | return -1; |
| 790 | } |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 791 | slog(MISC_PRINT, SLOG_NORMAL,"mgmt_check_password old_psw:%s!\n", old_psw); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 792 | if(old_psw_len < sizeof(old_psw_admin)) |
| 793 | snprintf(old_psw_admin,old_psw_len+1,"%s",old_psw); |
| 794 | else |
| 795 | snprintf(old_psw_admin,sizeof(old_psw_admin),"%s",old_psw); |
| 796 | //strncpy(old_psw_admin, old_psw, CONFIG_DEFAULT_LENGTH-1); |
| 797 | free(old_psw); |
| 798 | |
| 799 | if (DATA_NO_SAFE == zte_Safe_noSpecialChar(old_psw_admin)) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 800 | slog(MISC_PRINT, SLOG_ERR,"mgmt_check_password old_psw_admin Get Data is no Safe!\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 801 | sc_cfg_set("data_safe", "failed"); |
| 802 | return -1; |
| 803 | } |
| 804 | |
| 805 | //sc_cfg_get("admin_Password", admin_psw_buf, sizeof(admin_psw_buf)); |
| 806 | //if (0 != strcmp(old_psw_admin, admin_psw_buf)) { |
| 807 | if (0 != web_check_pwd(old_psw_admin)) { |
| 808 | #ifdef WEBS_SECURITY |
| 809 | sc_cfg_set(NV_USER_IP_ADDR, ""); |
| 810 | sc_cfg_set(NV_LOGINFO, ""); |
| 811 | sc_cfg_set(NV_COOKIE_ID, ""); |
| 812 | sc_cfg_set(NV_WEB_TOKEN, ""); |
| 813 | security_log(MODULE_ID_WEB_CGI,"web checkpwd fail logout"); |
| 814 | #endif |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 815 | slog(MISC_PRINT, SLOG_ERR,"mgmt_check_password admin_Password fail!\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 816 | return -1; |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | int zte_mgmt_handle_account(webs_t wp) |
| 824 | { |
| 825 | char_t *tmp_new_user = NULL; |
| 826 | char_t *tmp_new_psw = NULL; |
| 827 | char_t *new_user = NULL; |
| 828 | char_t *new_psw = NULL; |
| 829 | int new_psw_len = 0; |
| 830 | int new_user_len = 0; |
| 831 | char new_user_admin[CONFIG_DEFAULT_LENGTH] = {0}; |
| 832 | char new_psw_admin[CONFIG_DEFAULT_LENGTH] = {0}; |
| 833 | |
| 834 | tmp_new_psw = websGetVar(wp, T("newPassword"), NULL); |
| 835 | tmp_new_user = websGetVar(wp, T("newUserName"), NULL); |
| 836 | |
| 837 | if (NULL == tmp_new_psw || NULL == tmp_new_user) { |
| 838 | return -1; |
| 839 | } |
| 840 | |
| 841 | new_psw = (char*)zte_base64_decode((const unsigned char *)tmp_new_psw, strlen(tmp_new_psw), (unsigned int *)&new_psw_len); |
| 842 | if (NULL == new_psw) { |
| 843 | slog(MISC_PRINT, SLOG_ERR, "new_psw is NULL\n"); /*lint !e26*/ |
| 844 | return -1; |
| 845 | } |
| 846 | new_user = (char*)zte_base64_decode((const unsigned char *)tmp_new_user, strlen(tmp_new_user), (unsigned int *)&new_user_len); |
| 847 | |
| 848 | if (NULL == new_user) { |
| 849 | free(new_psw); |
| 850 | slog(MISC_PRINT, SLOG_ERR, "new_user is NULL\n"); /*lint !e26*/ |
| 851 | return -1; |
| 852 | } |
| 853 | |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 854 | slog(MISC_PRINT, SLOG_DEBUG,"mgmt_handle_account new_psw:%s!\n", new_psw); |
| 855 | slog(MISC_PRINT, SLOG_DEBUG,"mgmt_handle_account new_user:%s!\n", new_user); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 856 | if(new_psw_len < sizeof(new_psw_admin)) |
| 857 | snprintf(new_psw_admin,new_psw_len+1,"%s",new_psw); |
| 858 | else |
| 859 | snprintf(new_psw_admin,sizeof(new_psw_admin),"%s",new_psw); |
| 860 | //strncpy(new_psw_admin, new_psw, CONFIG_DEFAULT_LENGTH-1); |
| 861 | if(new_user_len < sizeof(new_user_admin)) |
| 862 | snprintf(new_user_admin,new_user_len+1,"%s",new_psw); |
| 863 | else |
| 864 | snprintf(new_user_admin,sizeof(new_user_admin),"%s",new_psw); |
| 865 | //strncpy(new_user_admin, new_user, CONFIG_DEFAULT_LENGTH-1); |
| 866 | free(new_psw); |
| 867 | free(new_user); |
| 868 | |
| 869 | if (LOGIN_PSW_MIN_LEN > new_psw_len || LOGIN_PSW_MAX_LEN < new_psw_len) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 870 | slog(MISC_PRINT, SLOG_ERR,"mgmt_handle_account new_psw_len is too long!\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 871 | sc_cfg_set("data_safe", "failed"); |
| 872 | return -1; |
| 873 | } |
| 874 | |
| 875 | if (LOGIN_PSW_MIN_LEN > new_user_len || LOGIN_PSW_MAX_LEN < new_user_len) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 876 | slog(MISC_PRINT, SLOG_ERR,"mgmt_handle_account new_user_len is too long!\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 877 | sc_cfg_set("data_safe", "failed"); |
| 878 | return -1; |
| 879 | } |
| 880 | |
| 881 | if (DATA_NO_SAFE == zte_Safe_noSpecialChar(new_psw_admin) |
| 882 | || DATA_NO_SAFE == zte_Safe_noSpecialChar(new_user_admin)) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 883 | slog(MISC_PRINT, SLOG_ERR,"mgmt_handle_account Get Data is no Safe!\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 884 | sc_cfg_set("data_safe", "failed"); |
| 885 | return -1; |
| 886 | } |
| 887 | |
| 888 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User change account!\n")); |
| 889 | |
| 890 | sc_cfg_set("admin_user", new_user_admin); |
| 891 | //sc_cfg_set("admin_Password", new_psw_admin); |
| 892 | web_set_pwd(new_psw_admin); |
| 893 | //sc_cfg_set("user_save", ""); |
| 894 | sc_cfg_set("psw_save", ""); |
| 895 | sc_cfg_set("save_login", ""); |
| 896 | //sc_cfg_save(); |
| 897 | /* |
| 898 | char cmd[82] = {0}; |
| 899 | sprintf(cmd, "mksmbpasswd.sh \'%s\'", new_psw_admin); |
| 900 | system(cmd); |
| 901 | system("killall smbd"); |
| 902 | system("killall nmbd"); |
| 903 | system("smbd -D"); |
| 904 | system("nmbd -D"); |
| 905 | */ |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 906 | slog(MISC_PRINT, SLOG_DEBUG,"mgmt_handle_account success!\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | void zte_mgmt_change_account(webs_t wp) |
| 911 | { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 912 | slog(MISC_PRINT, SLOG_NORMAL,"mgmt_change_account ====================!\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 913 | |
| 914 | if (0 != zte_mgmt_check_password(wp)) { |
| 915 | zte_write_result_to_web(wp, FAILURE); |
| 916 | return; |
| 917 | } |
| 918 | |
| 919 | if (0 != zte_mgmt_handle_account(wp)) { |
| 920 | zte_write_result_to_web(wp, FAILURE); |
| 921 | return; |
| 922 | } |
| 923 | |
| 924 | zte_write_result_to_web(wp, SUCCESS); |
| 925 | } |
| 926 | |
| 927 | |
| 928 | /****************************************************** |
| 929 | * Function: void zte_mgmt_pin_input(webs_t wp) |
| 930 | * Description: deal with the pin code input goform |
| 931 | * Input: HTTP page info |
| 932 | * Output: |
| 933 | * Return: none |
| 934 | * Others: |
| 935 | * Modify Date Version Author Modification |
| 936 | * 2010/11/26 V1.0 zyt create |
| 937 | *******************************************************/ |
| 938 | void zte_mgmt_pin_input(webs_t wp) |
| 939 | { |
| 940 | char *pPinCode = NULL; |
| 941 | UINT32 length = 0; |
| 942 | T_zAt_CpinPukSet para = {0}; |
| 943 | UINT32 ret = 0; |
| 944 | char modem_main_state[NV_ITEM_STRING_LEN_50] = {0}; |
| 945 | |
| 946 | pPinCode = websGetVar(wp, T("PinNumber"), T("")); |
| 947 | length = strlen(pPinCode); |
| 948 | if (0 == length || length >= sizeof(para.pin)) { |
| 949 | zte_write_result_to_web(wp, FAILURE); |
| 950 | return; |
| 951 | } |
| 952 | |
| 953 | strncpy(para.pin, pPinCode,sizeof(para.pin)-1); |
| 954 | sc_cfg_set(NV_PIN_PUK_PROCESS, "begin"); |
| 955 | ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_VERIFY_PIN_REQ, sizeof(T_zAt_CpinPukSet), (UCHAR *)¶, 0); |
| 956 | if (0 != ret) { |
| 957 | sc_cfg_set(NV_PIN_PUK_PROCESS, ""); |
| 958 | zte_write_result_to_web(wp, FAILURE); |
| 959 | return; |
| 960 | } |
| 961 | |
| 962 | wait_verify(NV_PIN_PUK_PROCESS, "end"); |
| 963 | |
| 964 | (void)sleep(1); |
| 965 | (void)zte_web_read(NV_MODEM_MAIN_STATE, modem_main_state); |
| 966 | |
| 967 | if (0 != strcmp(modem_main_state, "modem_waitpin")) { |
| 968 | zte_write_result_to_web(wp, SUCCESS); |
| 969 | } else { |
| 970 | zte_write_result_to_web(wp, FAILURE); |
| 971 | } |
| 972 | } |
| 973 | /****************************************************** |
| 974 | * Function: void zte_mgmt_puk_input(webs_t wp) |
| 975 | * Description: deal with the puk code input goform |
| 976 | * Input: HTTP page info |
| 977 | * Output: |
| 978 | * Return: none |
| 979 | * Others: |
| 980 | * Modify Date Version Author Modification |
| 981 | * 2010/11/26 V1.0 zyt create |
| 982 | *******************************************************/ |
| 983 | void zte_mgmt_puk_input(webs_t wp) |
| 984 | { |
| 985 | char *pPukCode = NULL; |
| 986 | char *pNewPin = NULL; |
| 987 | int length = 0; |
| 988 | int ret = 0; |
| 989 | T_zAt_CpinPukSet para = {0}; |
| 990 | CHAR modem_main_state[NV_ITEM_STRING_LEN_50] = {0}; |
| 991 | |
| 992 | pPukCode = websGetVar(wp, T("PUKNumber"), T("")); |
| 993 | pNewPin = websGetVar(wp, T("PinNumber"), T("")); |
| 994 | |
| 995 | length = strlen(pPukCode); |
| 996 | if (0 == length || length >= sizeof(para.pin)) { |
| 997 | zte_write_result_to_web(wp, FAILURE); |
| 998 | return; |
| 999 | } |
| 1000 | |
| 1001 | length = strlen(pNewPin); |
| 1002 | if (0 == length || length >= sizeof(para.newpin)) { |
| 1003 | zte_write_result_to_web(wp, FAILURE); |
| 1004 | return; |
| 1005 | } |
| 1006 | |
| 1007 | strncpy(para.pin, pPukCode,sizeof(para.pin)-1); |
| 1008 | strncpy(para.newpin, pNewPin,sizeof(para.newpin)-1); |
| 1009 | sc_cfg_set(NV_PIN_PUK_PROCESS, "begin"); |
| 1010 | ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_VERIFY_PUK_REQ, sizeof(T_zAt_CpinPukSet), (UCHAR *)¶, 0); |
| 1011 | if (0 != ret) { |
| 1012 | sc_cfg_set(NV_PIN_PUK_PROCESS, ""); |
| 1013 | zte_write_result_to_web(wp, FAILURE); |
| 1014 | return; |
| 1015 | } |
| 1016 | |
| 1017 | wait_verify(NV_PIN_PUK_PROCESS, "end"); |
| 1018 | |
| 1019 | (void)sleep(1); |
| 1020 | (void)zte_web_read("pinset_result", modem_main_state); |
| 1021 | |
| 1022 | if (0 != strcmp(modem_main_state, "fail")) { |
| 1023 | zte_write_result_to_web(wp, SUCCESS); |
| 1024 | } else { |
| 1025 | zte_write_result_to_web(wp, FAILURE); |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | void zte_mgmt_auto_pin(webs_t wp) |
| 1030 | { |
| 1031 | char *pPinEable = NULL; |
| 1032 | char *pPinCode = NULL; |
| 1033 | int length = 0; |
| 1034 | |
| 1035 | pPinEable = websGetVar(wp, T("auto_simpin"), T("")); |
| 1036 | pPinCode = websGetVar(wp, T("auto_simpin_code"), T("")); |
| 1037 | |
| 1038 | length = strlen(pPinCode); |
| 1039 | if (0 == length || length > 8) { |
| 1040 | zte_write_result_to_web(wp, FAILURE); |
| 1041 | return; |
| 1042 | } |
| 1043 | |
| 1044 | length = strlen(pPinEable); |
| 1045 | if (1 != length) { |
| 1046 | zte_write_result_to_web(wp, FAILURE); |
| 1047 | return; |
| 1048 | } |
| 1049 | |
| 1050 | sc_cfg_set("auto_simpin", pPinEable); |
| 1051 | sc_cfg_set("auto_simpin_code", pPinCode); |
| 1052 | zte_write_result_to_web(wp, SUCCESS); |
| 1053 | |
| 1054 | } |
| 1055 | /****************************************************** |
| 1056 | * Function: void zte_mgmt_unlock_network(webs_t wp) |
| 1057 | * Description: deal with the unlock code input goform |
| 1058 | * Input: HTTP page info |
| 1059 | * Output: |
| 1060 | * Return: none |
| 1061 | * Others: |
| 1062 | * Modify Date Version Author Modification |
| 1063 | * 2010/11/26 V1.0 zyt create |
| 1064 | *******************************************************/ |
| 1065 | void zte_mgmt_unlock_network(webs_t wp) |
| 1066 | { |
| 1067 | char *unlock_code = NULL; |
| 1068 | UNLOCK_PARA_ST para; |
| 1069 | int length = 0; |
| 1070 | int ret = 0; |
| 1071 | |
| 1072 | memset(¶, 0, sizeof(UNLOCK_PARA_ST)); |
| 1073 | |
| 1074 | unlock_code = websGetVar(wp, T("unlock_network_code"), T("")); |
| 1075 | slog(MISC_PRINT, SLOG_DEBUG, "unlock_code=%s", unlock_code); /*lint !e26*/ |
| 1076 | length = strlen(unlock_code); |
| 1077 | if (0 == length || length >= sizeof(para.unlock_code)) { |
| 1078 | zte_write_result_to_web(wp, FAILURE); |
| 1079 | return; |
| 1080 | } |
| 1081 | |
| 1082 | strncpy(para.unlock_code, unlock_code,sizeof(para.unlock_code)-1); |
| 1083 | ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_UNLOCK_REQ, sizeof(UNLOCK_PARA_ST), (UCHAR *)¶, 0); |
| 1084 | if (0 != ret) { |
| 1085 | zte_write_result_to_web(wp, FAILURE); |
| 1086 | return; |
| 1087 | } |
| 1088 | |
| 1089 | wait_verify("unlock_at_wait", "0"); |
| 1090 | zte_write_result_to_web(wp, SUCCESS); |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | /*PINÂë½ûÓÃ*/ |
| 1095 | void zte_mgmt_disable_pin(webs_t wp) |
| 1096 | { |
| 1097 | char *pOldPin = NULL; |
| 1098 | T_zAt_PinManage para = {0}; |
| 1099 | int length = 0; |
| 1100 | int ret = 0; |
| 1101 | char pin_manage_result[NV_ITEM_STRING_LEN_5] = {0}; |
| 1102 | |
| 1103 | pOldPin = websGetVar(wp, T("OldPinNumber"), T("")); |
| 1104 | length = strlen(pOldPin); |
| 1105 | if (0 == length || length >= sizeof(para.oldPin)) { |
| 1106 | zte_write_result_to_web(wp, FAILURE); |
| 1107 | return; |
| 1108 | } |
| 1109 | strncpy(para.oldPin, pOldPin,sizeof(para.oldPin)-1); |
| 1110 | para.action = PIN_MANAGE_DISABLE; |
| 1111 | |
| 1112 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User disable pin!\n")); |
| 1113 | |
| 1114 | (void)zte_web_write("pin_manage_process", "begin"); |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1115 | slog(MISC_PRINT, SLOG_NORMAL, "goform_mgmt_pin_mgmt_process send message: ZUFI_MODULE_ID_AT_MAIN, MSG_CMD_WEB_REQ_PIN_MANAGE"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1116 | ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_PIN_MANAGE_REQ, sizeof(T_zAt_PinManage), (UCHAR *)¶, 0); |
| 1117 | if (0 != ret) { |
| 1118 | sc_cfg_set("pin_manage_process", ""); |
| 1119 | zte_write_result_to_web(wp, FAILURE); |
| 1120 | return; |
| 1121 | } |
| 1122 | |
| 1123 | /*ÉèÖõȴýpinÂë¹ÜÀí¶¯×÷AT´¦Àí½áÊø*/ |
| 1124 | wait_verify("pin_manage_process", "end"); |
| 1125 | |
| 1126 | (void)zte_web_read("pin_manage_result", pin_manage_result); |
| 1127 | (void)zte_web_write("pin_manage_result", ""); |
| 1128 | |
| 1129 | if (0 == strcmp(pin_manage_result, "0")) { |
| 1130 | zte_write_result_to_web(wp, SUCCESS); |
| 1131 | } else { |
| 1132 | zte_write_result_to_web(wp, FAILURE); |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | /*PINÂëÆôÓûòÐÞ¸Ä*/ |
| 1137 | void zte_mgmt_pin_enable_or_modify(webs_t wp) |
| 1138 | { |
| 1139 | CHAR *pOldPin = NULL; |
| 1140 | CHAR *pNewPin = NULL; |
| 1141 | |
| 1142 | if (NULL == wp) { |
| 1143 | zte_write_result_to_web(wp, FAILURE); |
| 1144 | return; |
| 1145 | } |
| 1146 | |
| 1147 | pOldPin = websGetVar(wp, T("OldPinNumber"), T("")); |
| 1148 | pNewPin = websGetVar(wp, T("NewPinNumber"), T("")); |
| 1149 | |
| 1150 | slog(MISC_PRINT, SLOG_DEBUG, "web para:[OldPinNumber] is [%s].", pOldPin); |
| 1151 | slog(MISC_PRINT, SLOG_DEBUG, "web para:[NewPinNumber] is [%s].", pNewPin); |
| 1152 | |
| 1153 | if ('\0' == (*pOldPin)) { |
| 1154 | zte_write_result_to_web(wp, FAILURE); |
| 1155 | return; |
| 1156 | } |
| 1157 | |
| 1158 | if (0 == strcmp(pNewPin, "")) { |
| 1159 | zte_mgmt_enable_pin(wp, pOldPin); |
| 1160 | } else { |
| 1161 | zte_mgmt_modify_pin(wp, pOldPin, pNewPin); |
| 1162 | } |
| 1163 | |
| 1164 | |
| 1165 | } |
| 1166 | static void zte_mgmt_enable_pin(webs_t wp, CHAR *pOldPin) |
| 1167 | { |
| 1168 | T_zAt_PinManage para = {0}; |
| 1169 | int ret = 0; |
| 1170 | char pin_manage_result[NV_ITEM_STRING_LEN_5] = {0}; |
| 1171 | |
| 1172 | |
| 1173 | if ((NULL == wp) || (NULL == pOldPin)) { |
| 1174 | zte_write_result_to_web(wp, FAILURE); |
| 1175 | return; |
| 1176 | } |
| 1177 | |
| 1178 | strncpy(para.oldPin, pOldPin,sizeof(para.oldPin)-1); |
| 1179 | para.action = PIN_MANAGE_ENABLE; |
| 1180 | if ('\0' == (*pOldPin)) { |
| 1181 | zte_write_result_to_web(wp, FAILURE); |
| 1182 | return; |
| 1183 | } |
| 1184 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User enable pin!\n")); |
| 1185 | |
| 1186 | (void)zte_web_write("pin_manage_process", "begin"); |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1187 | slog(MISC_PRINT, SLOG_NORMAL, "mgmt_enable_pin send message : ZUFI_MODULE_ID_AT_MAIN, MSG_CMD_WEB_REQ_PIN_MANAGE."); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1188 | ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_PIN_MANAGE_REQ, sizeof(T_zAt_PinManage), (UCHAR *)¶, 0); |
| 1189 | if (0 != ret) { |
| 1190 | sc_cfg_set("pin_manage_process", ""); |
| 1191 | zte_write_result_to_web(wp, FAILURE); |
| 1192 | return; |
| 1193 | } |
| 1194 | |
| 1195 | /*ÉèÖõȴýpinÂë¹ÜÀí¶¯×÷AT´¦Àí½áÊø*/ |
| 1196 | wait_verify("pin_manage_process", "end"); |
| 1197 | |
| 1198 | (void)zte_web_read("pin_manage_result", pin_manage_result); |
| 1199 | (void)zte_web_write("pin_manage_result", ""); |
| 1200 | |
| 1201 | if (0 == strcmp(pin_manage_result, "0")) { |
| 1202 | zte_write_result_to_web(wp, SUCCESS); |
| 1203 | } else { |
| 1204 | zte_write_result_to_web(wp, FAILURE); |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | /********************************************************************** |
| 1209 | * Function: zte_mgmt_modify_pin |
| 1210 | * Description: to modify pin |
| 1211 | * Input: wp: the web para;old_pin: old pin number; new_pin:new pin number |
| 1212 | * Output: |
| 1213 | * Return: |
| 1214 | * Others: |
| 1215 | * Modify Date Version Author Modification |
| 1216 | * ----------------------------------------------- |
| 1217 | * 2011/11/16 V1.0 chenyi first version |
| 1218 | **********************************************************************/ |
| 1219 | |
| 1220 | static void zte_mgmt_modify_pin(webs_t wp, CHAR *pOldPin, CHAR *pNewPin) |
| 1221 | { |
| 1222 | int length = 0; |
| 1223 | int ret = 0; |
| 1224 | T_zAt_PinManage para = {0}; |
| 1225 | char pin_manage_result[NV_ITEM_STRING_LEN_5] = {0}; |
| 1226 | |
| 1227 | if ((NULL == wp) || (NULL == pOldPin) || (NULL == pNewPin)) { |
| 1228 | zte_write_result_to_web(wp, FAILURE); |
| 1229 | return; |
| 1230 | } |
| 1231 | |
| 1232 | if (('\0' == (*pOldPin)) || ('\0' == (*pNewPin))) { |
| 1233 | zte_write_result_to_web(wp, FAILURE); |
| 1234 | return; |
| 1235 | } |
| 1236 | length = strlen(pNewPin); |
| 1237 | if (0 == length || length >= sizeof(para.newPin)) { |
| 1238 | zte_write_result_to_web(wp, FAILURE); |
| 1239 | return; |
| 1240 | } |
| 1241 | |
| 1242 | |
| 1243 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User modify pin!\n")); |
| 1244 | |
| 1245 | para.action = PIN_MANAGE_MODIFY; |
| 1246 | strncpy(para.oldPin, pOldPin,sizeof(para.oldPin)-1); |
| 1247 | strncpy(para.newPin, pNewPin,sizeof(para.newPin)-1); |
| 1248 | (void)zte_web_write("pin_manage_process", "begin"); |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1249 | slog(MISC_PRINT, SLOG_NORMAL, "mgmt_modify_pin send message : ZUFI_MODULE_ID_AT_MAIN, MSG_CMD_WEB_REQ_PIN_MANAGE."); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1250 | ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_PIN_MANAGE_REQ, sizeof(T_zAt_PinManage), (UCHAR *)¶, 0); |
| 1251 | if (0 != ret) { |
| 1252 | sc_cfg_set("pin_manage_process", ""); |
| 1253 | zte_write_result_to_web(wp, FAILURE); |
| 1254 | return; |
| 1255 | } |
| 1256 | |
| 1257 | /*ÉèÖõȴýpinÂë¹ÜÀí¶¯×÷AT´¦Àí½áÊø*/ |
| 1258 | wait_verify("pin_manage_process", "end"); |
| 1259 | |
| 1260 | |
| 1261 | (void)zte_web_read("pin_manage_result", pin_manage_result); |
| 1262 | (void)zte_web_write("pin_manage_result", ""); |
| 1263 | |
| 1264 | if (0 == strcmp(pin_manage_result, "0")) { |
| 1265 | zte_write_result_to_web(wp, SUCCESS); |
| 1266 | } else { |
| 1267 | zte_write_result_to_web(wp, FAILURE); |
| 1268 | } |
| 1269 | } |
| 1270 | /****************************************************** |
| 1271 | * Function: void zte_quick_setup(webs_t wp) |
| 1272 | * Description: deal with the quick setup goform |
| 1273 | * Input: HTTP page info |
| 1274 | * Output: |
| 1275 | * Return: none |
| 1276 | * Others: |
| 1277 | * Modify Date Version Author Modification |
| 1278 | * 2010/11/26 V1.0 zyt create |
| 1279 | *******************************************************/ |
| 1280 | void zte_quick_setup(webs_t wp) |
| 1281 | { |
| 1282 | int iFunc = 0; |
| 1283 | |
| 1284 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User quick setup!\n")); |
| 1285 | |
| 1286 | for (iFunc = 0; iFunc < MAX_QUICK_SET_NUM; iFunc++) { |
| 1287 | if (G_ZQUICK_SET[iFunc] != NULL) { |
| 1288 | G_ZQUICK_SET[iFunc](wp); |
| 1289 | } |
| 1290 | } |
| 1291 | zte_write_result_to_web(wp, SUCCESS); |
| 1292 | } |
| 1293 | |
| 1294 | int save_data_to_file(char *file_path, unsigned char *data, int len) |
| 1295 | { |
| 1296 | int file_fd = -1; |
| 1297 | int ret = -1; |
| 1298 | |
| 1299 | |
| 1300 | if (NULL == file_path || NULL == data) { |
| 1301 | slog(MISC_PRINT, SLOG_ERR,"Input para is invalid, null point!"); |
| 1302 | return -1; |
| 1303 | } |
| 1304 | |
| 1305 | // O_TRUNC:½«Îļþ³¤¶È½Ø¶ÏΪ0£¬×öΪÐÂÎļþдÈë |
| 1306 | file_fd = open(file_path, O_RDWR | O_CREAT | O_TRUNC | O_SYNC, 777); |
| 1307 | if (file_fd < 0) { |
| 1308 | slog(MISC_PRINT, SLOG_ERR,"Open file fail, error:%s, file path:%s", strerror(errno), file_path); |
| 1309 | return -1; |
| 1310 | } |
| 1311 | |
| 1312 | ret = write(file_fd, (void *)data, len); |
| 1313 | if (ret != len) { |
| 1314 | slog(MISC_PRINT, SLOG_ERR,"Write data to file fail, error:%s, file path:%s", strerror(errno), file_path); |
| 1315 | goto error; |
| 1316 | } |
| 1317 | |
| 1318 | ret = fsync(file_fd); |
| 1319 | if (ret < 0) { |
| 1320 | slog(MISC_PRINT, SLOG_ERR,"Sync Failed:%s, file path:%s", strerror(errno), file_path); |
| 1321 | goto error; |
| 1322 | } |
| 1323 | |
| 1324 | |
| 1325 | ret = 0; |
| 1326 | goto end; |
| 1327 | |
| 1328 | error: |
| 1329 | ret = -1; |
| 1330 | |
| 1331 | end: |
| 1332 | close(file_fd); |
| 1333 | |
| 1334 | file_fd = -1; |
| 1335 | |
| 1336 | return ret; |
| 1337 | |
| 1338 | } |
| 1339 | |
| 1340 | /****************************************************** |
| 1341 | * Function: void zte_goform_mgmt_sntp_process(webs_t wp) |
| 1342 | * Description: deal with the sntp |
| 1343 | * Input: HTTP page info |
| 1344 | * Output: |
| 1345 | * Return: none |
| 1346 | * Others: |
| 1347 | * Modify Date Version Author Modification |
| 1348 | * 2011/04/13 V1.0 mengyuan create |
| 1349 | *******************************************************/ |
| 1350 | void zte_goform_mgmt_sntp_process(webs_t wp) |
| 1351 | { |
| 1352 | MSG_BUF msg; |
| 1353 | int lTgtMsgID = 0; |
| 1354 | char *mode = NULL; |
| 1355 | char *sntp_server0 = NULL; |
| 1356 | char *sntp_server1 = NULL; |
| 1357 | char *sntp_server2 = NULL; |
| 1358 | char *sntp_timezone = NULL; |
| 1359 | int result = 0; |
| 1360 | LONG msgSize = sizeof(MSG_BUF) - sizeof(LONG); |
| 1361 | char *ntp_server = NULL; |
| 1362 | int sem_id = 0; |
| 1363 | char state[NV_ITEM_STRING_LEN_20] = {0}; |
| 1364 | char sntp_timezone_tmp[NV_ITEM_STRING_LEN_64] = {0}; |
| 1365 | //char cmd[100] = {0}; |
| 1366 | |
| 1367 | memset(&msg, 1, sizeof(MSG_BUF)); |
| 1368 | mode = websGetVar(wp, T("manualsettime"), T("")); |
| 1369 | sc_cfg_set("sntp_time_set_mode", mode); |
| 1370 | |
| 1371 | sntp_server0 = websGetVar(wp, T("sntp_server1_ip"), T("")); |
| 1372 | sntp_server1 = websGetVar(wp, T("sntp_server2_ip"), T("")); |
| 1373 | sntp_server2 = websGetVar(wp, T("sntp_server3_ip"), T("")); |
| 1374 | sc_cfg_set("sntp_server0", sntp_server0); |
| 1375 | sc_cfg_set("sntp_server1", sntp_server1); |
| 1376 | sc_cfg_set("sntp_server2", sntp_server2); |
| 1377 | |
| 1378 | |
| 1379 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User set sntp time!\n")); |
| 1380 | |
| 1381 | if (strcmp(sntp_server0, "Other") == 0) { |
| 1382 | sc_cfg_set("sntp_other_server0", websGetVar(wp, T("sntp_other_server0"), T(""))); |
| 1383 | } |
| 1384 | if (strcmp(sntp_server1, "Other") == 0) { |
| 1385 | sc_cfg_set("sntp_other_server1", websGetVar(wp, T("sntp_other_server1"), T(""))); |
| 1386 | } |
| 1387 | if (strcmp(sntp_server2, "Other") == 0) { |
| 1388 | sc_cfg_set("sntp_other_server2", websGetVar(wp, T("sntp_other_server2"), T(""))); |
| 1389 | } |
| 1390 | sc_cfg_set("sntp_timezone_index", websGetVar(wp, T("sntp_timezone_index"), T(""))); |
| 1391 | //sc_cfg_set("sntp_timezone", websGetVar(wp, T("timezone"), T(""))); |
| 1392 | sc_cfg_set("sntp_dst_enable", websGetVar(wp, T("DaylightEnabled"), T(""))); |
| 1393 | |
| 1394 | sc_cfg_set("manual_time_year", websGetVar(wp, T("time_year"), T(""))); |
| 1395 | sc_cfg_set("manual_time_month", websGetVar(wp, T("time_month"), T(""))); |
| 1396 | sc_cfg_set("manual_time_day", websGetVar(wp, T("time_day"), T(""))); |
| 1397 | sc_cfg_set("manual_time_hour", websGetVar(wp, T("time_hour"), T(""))); |
| 1398 | sc_cfg_set("manual_time_minute", websGetVar(wp, T("time_minute"), T(""))); |
| 1399 | sc_cfg_set("manual_time_second", websGetVar(wp, T("time_second"), T(""))); |
| 1400 | //ÉèÖÃÊ±Çø |
| 1401 | sntp_timezone = websGetVar(wp, T("timezone"), T("")); |
| 1402 | sc_cfg_set("sntp_timezone", sntp_timezone); |
| 1403 | |
| 1404 | //memset(cmd, 0, 100); |
| 1405 | //sprintf(cmd, "echo \"%s\" > /etc_rw/TZ", sntp_timezone); |
| 1406 | //system(cmd); |
| 1407 | snprintf(sntp_timezone_tmp,sizeof(sntp_timezone_tmp),"%s\n",sntp_timezone); |
| 1408 | save_data_to_file("/etc_rw/TZ",sntp_timezone_tmp,strlen(sntp_timezone_tmp)); |
| 1409 | |
| 1410 | if (strcmp(mode, "manual") == 0) { |
| 1411 | sem_id = get_sem(TIME_SEM_KEY_1); |
| 1412 | if (sem_id != -1) { |
| 1413 | sem_p(sem_id); |
| 1414 | slog(MISC_PRINT, SLOG_DEBUG,"[MANUAL] manual_set_time, sem_p, sem_id = %d\r\n", sem_id); |
| 1415 | } |
| 1416 | |
| 1417 | result = manual_set_time(); |
| 1418 | |
| 1419 | if (sem_id != -1) { |
| 1420 | sem_v(sem_id); |
| 1421 | slog(MISC_PRINT, SLOG_DEBUG,"[MANUAL] manual_set_time, sem_v, sem_id = %d\r\n", sem_id); |
| 1422 | } |
| 1423 | |
| 1424 | sc_cfg_set("sntp_year", websGetVar(wp, T("time_year"), T(""))); |
| 1425 | sc_cfg_set("sntp_month", websGetVar(wp, T("time_month"), T(""))); |
| 1426 | sc_cfg_set("sntp_day", websGetVar(wp, T("time_day"), T(""))); |
| 1427 | sc_cfg_set("sntp_hour", websGetVar(wp, T("time_hour"), T(""))); |
| 1428 | sc_cfg_set("sntp_minute", websGetVar(wp, T("time_minute"), T(""))); |
| 1429 | sc_cfg_set("sntp_second", websGetVar(wp, T("time_second"), T(""))); |
| 1430 | sc_cfg_set("sntp_process_result", "success"); |
| 1431 | if (result < 0) { |
| 1432 | zte_write_result_to_web(wp, FAILURE); |
| 1433 | } else { |
| 1434 | if (!zte_mgmt_login_timemark_set()) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1435 | slog(MISC_PRINT, SLOG_ERR, "[ERROR]goform_whitelist_check -> timemark set error .\n"); /*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1436 | } |
| 1437 | zte_write_result_to_web(wp, SUCCESS); |
| 1438 | } |
| 1439 | } else if (strcmp(mode, "auto") == 0) { |
| 1440 | sc_cfg_get("sntp_process_state", state, sizeof(state)); |
| 1441 | if (strcmp(state, "over") != 0) { |
| 1442 | zte_write_result_to_web(wp, PROCESSING); |
| 1443 | slog(MISC_PRINT, SLOG_DEBUG,"[SNTP] already runing return \n"); |
| 1444 | return; |
| 1445 | } |
| 1446 | sc_cfg_set("sntp_process_state", "idle"); |
| 1447 | //sc_cfg_set("systime_mode", "auto"); |
| 1448 | //sc_cfg_set("sntp_cmd_from", "WEBUI"); |
| 1449 | sc_cfg_set("sntp_process_result", ""); |
| 1450 | ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_SNTP, MSG_CMD_SNTP_START, 0, NULL, 0); |
| 1451 | zte_write_result_to_web(wp, SUCCESS); |
| 1452 | } else { |
| 1453 | sem_id = get_sem(TIME_SEM_KEY_1); |
| 1454 | if (sem_id != -1) { |
| 1455 | sem_p(sem_id); |
| 1456 | slog(MISC_PRINT, SLOG_DEBUG,"[MANUAL] manual_set_time, sem_p, sem_id = %d\r\n", sem_id); |
| 1457 | } |
| 1458 | |
| 1459 | result = manual_set_time(); |
| 1460 | |
| 1461 | if (sem_id != -1) { |
| 1462 | sem_v(sem_id); |
| 1463 | slog(MISC_PRINT, SLOG_DEBUG,"[MANUAL] manual_set_time, sem_v, sem_id = %d\r\n", sem_id); |
| 1464 | } |
| 1465 | |
| 1466 | sc_cfg_set("sntp_year", websGetVar(wp, T("time_year"), T(""))); |
| 1467 | sc_cfg_set("sntp_month", websGetVar(wp, T("time_month"), T(""))); |
| 1468 | sc_cfg_set("sntp_day", websGetVar(wp, T("time_day"), T(""))); |
| 1469 | sc_cfg_set("sntp_hour", websGetVar(wp, T("time_hour"), T(""))); |
| 1470 | sc_cfg_set("sntp_minute", websGetVar(wp, T("time_minute"), T(""))); |
| 1471 | sc_cfg_set("sntp_second", websGetVar(wp, T("time_second"), T(""))); |
| 1472 | |
| 1473 | if (result < 0) { |
| 1474 | zte_write_result_to_web(wp, FAILURE); |
| 1475 | } else { |
| 1476 | if (!zte_mgmt_login_timemark_set()) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1477 | slog(MISC_PRINT, SLOG_ERR, "[ERROR]goform_whitelist_check -> timemark set error .\n"); /*lint !e26*/ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1478 | } |
| 1479 | zte_write_result_to_web(wp, SUCCESS); |
| 1480 | } |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | static void wait_verify(char *wait_name, char *wait_value) |
| 1485 | { |
| 1486 | int i = 0; |
| 1487 | char buf[NV_ITEM_STRING_LEN_200] = {0}; |
| 1488 | |
| 1489 | if (NULL == wait_name || NULL == wait_value) { |
| 1490 | return; |
| 1491 | } |
| 1492 | |
| 1493 | for (i = 0; i < 10; i++) { |
| 1494 | sleep(2); |
| 1495 | sc_cfg_get(wait_name, buf, sizeof(buf)); |
| 1496 | if (0 == strcmp(wait_value, buf)) { |
| 1497 | break; |
| 1498 | } |
| 1499 | } |
| 1500 | return; |
| 1501 | } |
| 1502 | |
| 1503 | |
| 1504 | void deal_quick_setup_wifi_basic(webs_t wp) |
| 1505 | { |
| 1506 | deal_quick_setup_wifi_basic_mgmt(wp); |
| 1507 | } |
| 1508 | static int deal_quick_setup_auto_apn_set() |
| 1509 | { |
| 1510 | APN_PROFILE newProfile = { 0 }; |
| 1511 | char ppp_status[NV_ITEM_STRING_LEN_50] = {0}; |
| 1512 | |
| 1513 | get_autoapn_profile(&newProfile); |
| 1514 | set_apn_to_cfg(&newProfile, NULL); |
| 1515 | sc_cfg_set("ipv6_wan_apn", newProfile.apn_name); |
| 1516 | |
| 1517 | sc_cfg_get("ppp_status", ppp_status, sizeof(ppp_status)); |
| 1518 | if (0 == strcmp("ppp_disconnected", ppp_status) || 0 == strcmp("ppp_ready", ppp_status)) { |
| 1519 | ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_APN_SET_REQ, 0, NULL, 0); |
| 1520 | } |
| 1521 | return 0; |
| 1522 | } |
| 1523 | static void set_apn_to_cfg(APN_PROFILE *apn_profile, IPV6_APN_PROFILE *ipv6_apn_profile) |
| 1524 | { |
| 1525 | if (apn_profile != NULL) { |
| 1526 | sc_cfg_set("m_profile_name", apn_profile->profile_name); |
| 1527 | sc_cfg_set("wan_apn", apn_profile->apn_name); |
| 1528 | sc_cfg_set("apn_select", apn_profile->apn_select); |
| 1529 | sc_cfg_set("wan_dial", apn_profile->dial_num); |
| 1530 | sc_cfg_set("ppp_auth_mode", apn_profile->ppp_auth_mode); |
| 1531 | sc_cfg_set("ppp_username", apn_profile->ppp_username); |
| 1532 | sc_cfg_set("ppp_passtmp", apn_profile->ppp_passwd); |
| 1533 | sc_cfg_set("pdp_type", apn_profile->pdp_type); |
| 1534 | sc_cfg_set("ipv6_pdp_type", apn_profile->pdp_type); |
| 1535 | sc_cfg_set("pdp_select", apn_profile->pdp_select); |
| 1536 | sc_cfg_set("pdp_addr", apn_profile->pdp_addr); |
| 1537 | apn_encrypt_code(); |
| 1538 | } |
| 1539 | |
| 1540 | if (ipv6_apn_profile != NULL) { |
| 1541 | sc_cfg_set("m_profile_name", ipv6_apn_profile->profile_name); |
| 1542 | sc_cfg_set("ipv6_wan_apn", ipv6_apn_profile->apn_name); |
| 1543 | sc_cfg_set("apn_select", ipv6_apn_profile->apn_select); |
| 1544 | sc_cfg_set("wan_dial", ipv6_apn_profile->dial_num); |
| 1545 | sc_cfg_set(NV_IPV6_PPP_AUTH_MODE, ipv6_apn_profile->ppp_auth_mode); |
| 1546 | sc_cfg_set("ipv6_ppp_username", ipv6_apn_profile->ppp_username); |
| 1547 | sc_cfg_set("ipv6_ppp_passtmp", ipv6_apn_profile->ppp_passwd); |
| 1548 | sc_cfg_set("pdp_type", ipv6_apn_profile->pdp_type); |
| 1549 | sc_cfg_set("ipv6_pdp_type", ipv6_apn_profile->pdp_type); |
| 1550 | sc_cfg_set("pdp_select", ipv6_apn_profile->pdp_select); |
| 1551 | sc_cfg_set("pdp_addr", ipv6_apn_profile->pdp_addr); |
| 1552 | ipv6apn_encrypt_code(); |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | |
| 1557 | static void deal_quick_setup_manual_apn_set(webs_t wp) |
| 1558 | { |
| 1559 | IPV6_APN_PROFILE newIpv6Profile = { 0 }; |
| 1560 | APN_PROFILE newProfile = { 0 }; |
| 1561 | int index_apn = atoi(websGetVar(wp, "index", T(""))); |
| 1562 | char *pdp_type = websGetVar(wp, "pdp_type", T("")); |
| 1563 | char *apn_name = websGetVar(wp, "wan_apn", T("")); |
| 1564 | char *ipv6_wan_apn = websGetVar(wp, "ipv6_wan_apn", T("")); |
| 1565 | char ppp_status[NV_ITEM_STRING_LEN_50] = {0}; |
| 1566 | char *ppp_auth_mode = websGetVar(wp, "ppp_auth_mode", T("")); |
| 1567 | char *ppp_username = websGetVar(wp, "ppp_username", T("")); |
| 1568 | char *ppp_passwd = websGetVar(wp, "ppp_passtmp", T("")); |
| 1569 | char *ipv6_pdp_auth_mode = websGetVar(wp, NV_IPV6_PPP_AUTH_MODE, T("")); |
| 1570 | char *ipv6_ppp_username = websGetVar(wp, "ipv6_ppp_username", T("")); |
| 1571 | char *ipv6_ppp_passwd = websGetVar(wp, "ipv6_ppp_passtmp", T("")); |
| 1572 | |
| 1573 | slog(MISC_PRINT, SLOG_NORMAL,"[goahead] deal_quick_setup_manual_apn_set wan_apn %s. %s.\n", apn_name,ppp_username); |
| 1574 | |
| 1575 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User manual apn set!\n")); |
| 1576 | if (0 == strcmp(pdp_type, "IPv6")) { |
| 1577 | get_ipv6apn_profile_by_index(index_apn, &newIpv6Profile); |
| 1578 | strncpy(newIpv6Profile.apn_name, ipv6_wan_apn,sizeof(newIpv6Profile.apn_name)-1); |
| 1579 | strncpy(newIpv6Profile.ppp_auth_mode, ipv6_pdp_auth_mode,sizeof(newIpv6Profile.ppp_auth_mode)-1); |
| 1580 | strncpy(newIpv6Profile.ppp_username, ipv6_ppp_username,sizeof(newIpv6Profile.ppp_username)-1); |
| 1581 | strncpy(newIpv6Profile.ppp_passwd, ipv6_ppp_passwd,sizeof(newIpv6Profile.ppp_passwd)-1); |
| 1582 | set_ipv6_apn_profile_by_index(index_apn, &newIpv6Profile); |
| 1583 | set_ipv6_apn_prof_aes_by_index(index_apn, &newIpv6Profile); |
| 1584 | |
| 1585 | set_apn_to_cfg(NULL, &newIpv6Profile); |
| 1586 | } else if (0 == strcmp(pdp_type, "IPv4v6")) { |
| 1587 | get_ipv4v6apn_profile_by_index(index_apn, &newProfile, &newIpv6Profile); |
| 1588 | strncpy(newProfile.apn_name, apn_name,sizeof(newProfile.apn_name)-1); |
| 1589 | strncpy(newProfile.ppp_auth_mode, ppp_auth_mode,sizeof(newProfile.ppp_auth_mode)-1); |
| 1590 | strncpy(newProfile.ppp_username, ppp_username,sizeof(newProfile.ppp_username)-1); |
| 1591 | strncpy(newProfile.ppp_passwd, ppp_passwd,sizeof(newProfile.ppp_passwd)-1); |
| 1592 | |
| 1593 | strncpy(newIpv6Profile.apn_name, ipv6_wan_apn,sizeof(newIpv6Profile.apn_name)-1); |
| 1594 | strncpy(newIpv6Profile.ppp_auth_mode, ipv6_pdp_auth_mode,sizeof(newIpv6Profile.ppp_auth_mode)-1); |
| 1595 | strncpy(newIpv6Profile.ppp_username, ipv6_ppp_username,sizeof(newIpv6Profile.ppp_username)-1); |
| 1596 | strncpy(newIpv6Profile.ppp_passwd, ipv6_ppp_passwd,sizeof(newIpv6Profile.ppp_passwd)-1); |
| 1597 | set_ipv4v6_apn_profile_by_index(index_apn, &newProfile, &newIpv6Profile); |
| 1598 | set_ipv4v6_apn_prof_aes_by_index(index_apn, &newProfile, &newIpv6Profile); |
| 1599 | |
| 1600 | set_apn_to_cfg(&newProfile, &newIpv6Profile); |
| 1601 | } else { |
| 1602 | get_apn_profile_by_index(index_apn, &newProfile); |
| 1603 | strncpy(newProfile.apn_name, apn_name,sizeof(newProfile.apn_name)-1); |
| 1604 | strncpy(newProfile.ppp_auth_mode, ppp_auth_mode,sizeof(newProfile.ppp_auth_mode)-1); |
| 1605 | strncpy(newProfile.ppp_username, ppp_username,sizeof(newProfile.ppp_username)-1); |
| 1606 | strncpy(newProfile.ppp_passwd, ppp_passwd,sizeof(newProfile.ppp_passwd)-1); |
| 1607 | set_apn_profile_by_index(index_apn, &newProfile); |
| 1608 | set_apn_prof_aes_by_index(index_apn, &newProfile); |
| 1609 | |
| 1610 | set_apn_to_cfg(&newProfile, NULL); |
| 1611 | } |
| 1612 | |
| 1613 | sc_cfg_get("ppp_status", ppp_status, sizeof(ppp_status)); |
| 1614 | if (0 == strcmp("ppp_disconnected", ppp_status) || 0 == strcmp("ppp_ready", ppp_status)) { |
| 1615 | ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_APN_SET_REQ, 0, NULL, 0); |
| 1616 | } |
| 1617 | } |
| 1618 | |
| 1619 | void deal_quick_setup_apn_ex(webs_t wp) |
| 1620 | { |
| 1621 | if (strcmp(ZTE_WEB_ACT_MANUAL, websGetVar(wp, "apn_mode", T(""))) == 0) { |
| 1622 | zte_web_write("apn_mode", ZTE_WEB_ACT_MANUAL); |
| 1623 | deal_quick_setup_manual_apn_set(wp); |
| 1624 | } else { |
| 1625 | zte_web_write("apn_mode", ZTE_WEB_ACT_AUTO); |
| 1626 | deal_quick_setup_auto_apn_set(); // cov low, deal_quick_setup_auto_apn_set does not need parameter |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | void deal_quick_setup_wifi_security(webs_t wp) |
| 1631 | { |
| 1632 | deal_quick_setup_wifi_security_mgmt(wp); |
| 1633 | } |
| 1634 | |
| 1635 | static void deal_quick_setup_wps(webs_t wp) |
| 1636 | { |
| 1637 | deal_quick_setup_wps_mgmt(wp); |
| 1638 | } |
| 1639 | /****************************************************** |
| 1640 | * Function: void get_apn_profile_by_index(int index, APN_PROFILE *profile) |
| 1641 | * Description: get a apn profile by index from config |
| 1642 | * Input: index:the index of apn profile which to get |
| 1643 | * Output: profile:the result of apn profile config after splited |
| 1644 | * Return: none |
| 1645 | * Others: |
| 1646 | * Modify Date Version Author Modification |
| 1647 | * 2010/11/26 V1.0 zyt create |
| 1648 | *******************************************************/ |
| 1649 | void get_apn_profile_by_index(int index, APN_PROFILE *profile) |
| 1650 | { |
| 1651 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 1652 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 1653 | char *pos_begin = NULL; |
| 1654 | |
| 1655 | if (NULL == profile) { |
| 1656 | return; |
| 1657 | } |
| 1658 | //È¡Ã÷ÎÄAPN_configtmp,Õâʱ²»ÓÃÈ¡ÃÜÎÄ |
| 1659 | sprintf(cfg_name, "APN_configtmp%d", index); |
| 1660 | |
| 1661 | sc_cfg_get(cfg_name, cfg_value, sizeof(cfg_value)); |
| 1662 | pos_begin = cfg_value; |
| 1663 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->profile_name, PROFILE_MEMBER_LEN); |
| 1664 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->apn_name, PROFILE_APN_LEN); |
| 1665 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->apn_select, PROFILE_MEMBER_LEN); |
| 1666 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->dial_num, PROFILE_MEMBER_LEN); |
| 1667 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_auth_mode, PROFILE_MEMBER_LEN); |
| 1668 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_username, PROFILE_APN_LEN); |
| 1669 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_passwd, PROFILE_APN_LEN); |
| 1670 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_type, PROFILE_MEMBER_LEN); |
| 1671 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_select, PROFILE_MEMBER_LEN); |
| 1672 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_addr, PROFILE_MEMBER_LEN); |
| 1673 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->dns_mode, PROFILE_MEMBER_LEN); |
| 1674 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->prefer_dns_manual, PROFILE_MEMBER_LEN); |
| 1675 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->standby_dns_manual, PROFILE_MEMBER_LEN); |
| 1676 | return; |
| 1677 | } |
| 1678 | |
| 1679 | void get_ipv6apn_profile_by_index(int index, IPV6_APN_PROFILE *profile) |
| 1680 | { |
| 1681 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 1682 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 1683 | char *pos_begin = NULL; |
| 1684 | |
| 1685 | if (NULL == profile) { |
| 1686 | return; |
| 1687 | } |
| 1688 | |
| 1689 | sprintf(cfg_name, "ipv6_APN_configtmp%d", index); |
| 1690 | |
| 1691 | sc_cfg_get(cfg_name, cfg_value, sizeof(cfg_value)); |
| 1692 | slog(MISC_PRINT, SLOG_DEBUG, "get_ipv6apn_profile_by_index cfg_value=%s", cfg_value); /*lint !e26*/ |
| 1693 | |
| 1694 | pos_begin = cfg_value; |
| 1695 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->profile_name, PROFILE_MEMBER_LEN); |
| 1696 | slog(MISC_PRINT, SLOG_DEBUG, "========= profile->profile_name=%s=======", profile->profile_name); /*lint !e26*/ |
| 1697 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->apn_name, PROFILE_APN_LEN); |
| 1698 | slog(MISC_PRINT, SLOG_DEBUG, "=========profile->apn_name=%s=======", profile->apn_name); /*lint !e26*/ |
| 1699 | |
| 1700 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->apn_select, PROFILE_MEMBER_LEN); |
| 1701 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->dial_num, PROFILE_MEMBER_LEN); |
| 1702 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_auth_mode, PROFILE_MEMBER_LEN); |
| 1703 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_username, PROFILE_APN_LEN); |
| 1704 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_passwd, PROFILE_APN_LEN); |
| 1705 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_type, PROFILE_MEMBER_LEN); |
| 1706 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_select, PROFILE_MEMBER_LEN); |
| 1707 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_addr, PROFILE_MEMBER_LEN); |
| 1708 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->dns_mode, PROFILE_MEMBER_LEN); |
| 1709 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->prefer_dns_manual, PROFILE_MEMBER_LEN); |
| 1710 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->standby_dns_manual, PROFILE_MEMBER_LEN); |
| 1711 | return; |
| 1712 | } |
| 1713 | |
| 1714 | |
| 1715 | void get_ipv4v6apn_profile_by_index(int index, APN_PROFILE *profile, IPV6_APN_PROFILE *ipv6profile) |
| 1716 | { |
| 1717 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 1718 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 1719 | char *pos_begin = NULL; |
| 1720 | |
| 1721 | char ipv6_cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 1722 | char ipv6_cfg_value[APNCONFIG_MEMORY] = {0}; |
| 1723 | char *ipv6_pos_begin = NULL; |
| 1724 | |
| 1725 | |
| 1726 | if (NULL == profile) { |
| 1727 | return; |
| 1728 | } |
| 1729 | if (NULL == ipv6profile) { |
| 1730 | return; |
| 1731 | } |
| 1732 | |
| 1733 | sprintf(cfg_name, "APN_configtmp%d", index); |
| 1734 | sc_cfg_get(cfg_name, cfg_value, sizeof(cfg_value)); |
| 1735 | pos_begin = cfg_value; |
| 1736 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->profile_name, PROFILE_MEMBER_LEN); |
| 1737 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->apn_name, PROFILE_APN_LEN); |
| 1738 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->apn_select, PROFILE_MEMBER_LEN); |
| 1739 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->dial_num, PROFILE_MEMBER_LEN); |
| 1740 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_auth_mode, PROFILE_MEMBER_LEN); |
| 1741 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_username, PROFILE_APN_LEN); |
| 1742 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_passwd, PROFILE_APN_LEN); |
| 1743 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_type, PROFILE_MEMBER_LEN); |
| 1744 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_select, PROFILE_MEMBER_LEN); |
| 1745 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_addr, PROFILE_MEMBER_LEN); |
| 1746 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->dns_mode, PROFILE_MEMBER_LEN); |
| 1747 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->prefer_dns_manual, PROFILE_MEMBER_LEN); |
| 1748 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->standby_dns_manual, PROFILE_MEMBER_LEN); |
| 1749 | |
| 1750 | |
| 1751 | sprintf(ipv6_cfg_name, "ipv6_APN_configtmp%d", index); |
| 1752 | sc_cfg_get(ipv6_cfg_name, ipv6_cfg_value, sizeof(ipv6_cfg_value)); |
| 1753 | ipv6_pos_begin = ipv6_cfg_value; |
| 1754 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->profile_name, PROFILE_MEMBER_LEN); |
| 1755 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->apn_name, PROFILE_APN_LEN); |
| 1756 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->apn_select, PROFILE_MEMBER_LEN); |
| 1757 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->dial_num, PROFILE_MEMBER_LEN); |
| 1758 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->ppp_auth_mode, PROFILE_MEMBER_LEN); |
| 1759 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->ppp_username, PROFILE_APN_LEN); |
| 1760 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->ppp_passwd, PROFILE_APN_LEN); |
| 1761 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->pdp_type, PROFILE_MEMBER_LEN); |
| 1762 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->pdp_select, PROFILE_MEMBER_LEN); |
| 1763 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->pdp_addr, PROFILE_MEMBER_LEN); |
| 1764 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->dns_mode, PROFILE_MEMBER_LEN); |
| 1765 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->prefer_dns_manual, PROFILE_MEMBER_LEN); |
| 1766 | ipv6_pos_begin = split_str_by_sep(ipv6_pos_begin, "($)", ipv6profile->standby_dns_manual, PROFILE_MEMBER_LEN); |
| 1767 | |
| 1768 | |
| 1769 | return; |
| 1770 | } |
| 1771 | |
| 1772 | |
| 1773 | |
| 1774 | void get_autoapn_profile(APN_PROFILE *profile) |
| 1775 | { |
| 1776 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 1777 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 1778 | char *pos_begin = NULL; |
| 1779 | char buf[NV_ITEM_STRING_LEN_20] = {0}; |
| 1780 | |
| 1781 | int auto_apn_index = 0; |
| 1782 | slog(MISC_PRINT, SLOG_DEBUG, "get_autoapn_profile\n"); /*lint !e26*/ |
| 1783 | |
| 1784 | sc_cfg_get("auto_apn_index", buf, sizeof(buf)); |
| 1785 | auto_apn_index = atoi(buf); |
| 1786 | slog(MISC_PRINT, SLOG_DEBUG, "auto_apn_index=%d\n", auto_apn_index); /*lint !e26*/ |
| 1787 | if (NULL == profile) { |
| 1788 | return; |
| 1789 | } |
| 1790 | |
| 1791 | if (0 != auto_apn_index) { |
| 1792 | sprintf(cfg_name, "apn_auto_config%d", auto_apn_index); |
| 1793 | } else { |
| 1794 | sprintf(cfg_name, "apn_auto_config"); |
| 1795 | } |
| 1796 | slog(MISC_PRINT, SLOG_DEBUG, "cfg_name=%s\n", cfg_name); /*lint !e26*/ |
| 1797 | |
| 1798 | sc_cfg_get(cfg_name, cfg_value, sizeof(cfg_value)); |
| 1799 | pos_begin = cfg_value; |
| 1800 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->profile_name, PROFILE_MEMBER_LEN); |
| 1801 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->apn_name, PROFILE_APN_LEN); |
| 1802 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->apn_select, PROFILE_MEMBER_LEN); |
| 1803 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->dial_num, PROFILE_MEMBER_LEN); |
| 1804 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_auth_mode, PROFILE_MEMBER_LEN); |
| 1805 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_username, PROFILE_APN_LEN); |
| 1806 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->ppp_passwd, PROFILE_APN_LEN); |
| 1807 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_type, PROFILE_MEMBER_LEN); |
| 1808 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_select, PROFILE_MEMBER_LEN); |
| 1809 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->pdp_addr, PROFILE_MEMBER_LEN); |
| 1810 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->dns_mode, PROFILE_MEMBER_LEN); |
| 1811 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->prefer_dns_manual, PROFILE_MEMBER_LEN); |
| 1812 | pos_begin = split_str_by_sep(pos_begin, "($)", profile->standby_dns_manual, PROFILE_MEMBER_LEN); |
| 1813 | return; |
| 1814 | } |
| 1815 | |
| 1816 | /****************************************************** |
| 1817 | * Function: void set_apn_profile_by_index(int index, APN_PROFILE *profile) |
| 1818 | * Description: set a apn profile into config by index |
| 1819 | * Input: index:the index of apn profile which to set |
| 1820 | * profile:the struct of apn profile. |
| 1821 | * Output: |
| 1822 | * Return: none |
| 1823 | * Others: |
| 1824 | * Modify Date Version Author Modification |
| 1825 | * 2010/11/26 V1.0 zyt create |
| 1826 | *******************************************************/ |
| 1827 | void set_apn_profile_by_index(int index, APN_PROFILE *profile) |
| 1828 | { |
| 1829 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 1830 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 1831 | |
| 1832 | if (NULL == profile) { |
| 1833 | return; |
| 1834 | } |
| 1835 | |
| 1836 | sprintf(cfg_name, "APN_configtmp%d", index); |
| 1837 | if (0 == strcmp(profile->pdp_type, "IPv6")) { |
| 1838 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 1839 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 1840 | profile->profile_name, |
| 1841 | "", |
| 1842 | "", |
| 1843 | "", |
| 1844 | "", |
| 1845 | "", |
| 1846 | "", |
| 1847 | "", |
| 1848 | "", |
| 1849 | "", |
| 1850 | "", |
| 1851 | "", |
| 1852 | ""); |
| 1853 | } else { |
| 1854 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 1855 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 1856 | profile->profile_name, |
| 1857 | profile->apn_name, |
| 1858 | profile->apn_select, |
| 1859 | profile->dial_num, |
| 1860 | profile->ppp_auth_mode, |
| 1861 | profile->ppp_username, |
| 1862 | profile->ppp_passwd, |
| 1863 | profile->pdp_type, |
| 1864 | profile->pdp_select, |
| 1865 | profile->pdp_addr, |
| 1866 | profile->dns_mode, |
| 1867 | profile->prefer_dns_manual, |
| 1868 | profile->standby_dns_manual); |
| 1869 | } |
| 1870 | sc_cfg_set(cfg_name, cfg_value); |
| 1871 | |
| 1872 | return; |
| 1873 | } |
| 1874 | |
| 1875 | void set_ipv6_apn_profile_by_index(int index, IPV6_APN_PROFILE *profile) |
| 1876 | { |
| 1877 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 1878 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 1879 | |
| 1880 | if (NULL == profile) { |
| 1881 | return; |
| 1882 | } |
| 1883 | |
| 1884 | sprintf(cfg_name, "ipv6_APN_configtmp%d", index); |
| 1885 | if (0 == strcmp(profile->pdp_type, "IP")) { |
| 1886 | slog(MISC_PRINT, SLOG_DEBUG, "pdp_type=IP cpsnprintf "); /*lint !e26*/ |
| 1887 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 1888 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 1889 | profile->profile_name, |
| 1890 | "", |
| 1891 | "", |
| 1892 | "", |
| 1893 | "", |
| 1894 | "", |
| 1895 | "", |
| 1896 | "", |
| 1897 | "", |
| 1898 | "", |
| 1899 | "", |
| 1900 | "", |
| 1901 | ""); |
| 1902 | } else { |
| 1903 | slog(MISC_PRINT, SLOG_DEBUG, "pdp_type=else cpsnprintf "); /*lint !e26*/ |
| 1904 | slog(MISC_PRINT, SLOG_DEBUG, "profile->profile_name=%s ", profile->profile_name); /*lint !e26*/ |
| 1905 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 1906 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 1907 | profile->profile_name, |
| 1908 | profile->apn_name, |
| 1909 | profile->apn_select, |
| 1910 | profile->dial_num, |
| 1911 | profile->ppp_auth_mode, |
| 1912 | profile->ppp_username, |
| 1913 | profile->ppp_passwd, |
| 1914 | profile->pdp_type, |
| 1915 | profile->pdp_select, |
| 1916 | profile->pdp_addr, |
| 1917 | profile->dns_mode, |
| 1918 | profile->prefer_dns_manual, |
| 1919 | profile->standby_dns_manual); |
| 1920 | } |
| 1921 | slog(MISC_PRINT, SLOG_DEBUG, "cfg_value=%s", cfg_value); /*lint !e26*/ |
| 1922 | sc_cfg_set(cfg_name, cfg_value); |
| 1923 | |
| 1924 | return; |
| 1925 | } |
| 1926 | |
| 1927 | void set_ipv4v6_apn_profile_by_index(int index, APN_PROFILE *profile, IPV6_APN_PROFILE *ipv6profile) |
| 1928 | { |
| 1929 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 1930 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 1931 | |
| 1932 | if (NULL == profile) { |
| 1933 | return; |
| 1934 | } |
| 1935 | |
| 1936 | sprintf(cfg_name, "APN_configtmp%d", index); |
| 1937 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 1938 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 1939 | profile->profile_name, |
| 1940 | profile->apn_name, |
| 1941 | profile->apn_select, |
| 1942 | profile->dial_num, |
| 1943 | profile->ppp_auth_mode, |
| 1944 | profile->ppp_username, |
| 1945 | profile->ppp_passwd, |
| 1946 | profile->pdp_type, |
| 1947 | profile->pdp_select, |
| 1948 | profile->pdp_addr, |
| 1949 | profile->dns_mode, |
| 1950 | profile->prefer_dns_manual, |
| 1951 | profile->standby_dns_manual); |
| 1952 | |
| 1953 | sc_cfg_set(cfg_name, cfg_value); |
| 1954 | |
| 1955 | memset(cfg_name, 0, sizeof(cfg_name)); |
| 1956 | memset(cfg_value, 0, sizeof(cfg_value)); |
| 1957 | sprintf(cfg_name, "ipv6_APN_configtmp%d", index); |
| 1958 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 1959 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 1960 | ipv6profile->profile_name, |
| 1961 | ipv6profile->apn_name, |
| 1962 | ipv6profile->apn_select, |
| 1963 | ipv6profile->dial_num, |
| 1964 | ipv6profile->ppp_auth_mode, |
| 1965 | ipv6profile->ppp_username, |
| 1966 | ipv6profile->ppp_passwd, |
| 1967 | ipv6profile->pdp_type, |
| 1968 | ipv6profile->pdp_select, |
| 1969 | ipv6profile->pdp_addr, |
| 1970 | ipv6profile->dns_mode, |
| 1971 | ipv6profile->prefer_dns_manual, |
| 1972 | ipv6profile->standby_dns_manual); |
| 1973 | |
| 1974 | sc_cfg_set(cfg_name, cfg_value); |
| 1975 | |
| 1976 | return; |
| 1977 | } |
| 1978 | |
| 1979 | static char *split_str_by_sep(char *src, char *sep, char *dst, int len) |
| 1980 | { |
| 1981 | char *pos_begin = NULL; |
| 1982 | char *pos_end = NULL; |
| 1983 | |
| 1984 | if (NULL == src || NULL == sep || NULL == dst || 0 == len) { |
| 1985 | return NULL; |
| 1986 | } |
| 1987 | |
| 1988 | pos_begin = src; |
| 1989 | pos_end = strstr(pos_begin, sep); |
| 1990 | |
| 1991 | if (NULL == pos_end) { |
| 1992 | return NULL; |
| 1993 | } |
| 1994 | |
| 1995 | if (len <= (pos_end - pos_begin)) { |
| 1996 | return NULL; |
| 1997 | } |
| 1998 | |
| 1999 | strncpy(dst, pos_begin, pos_end - pos_begin); |
| 2000 | pos_end += strlen(sep); |
| 2001 | return pos_end; |
| 2002 | } |
| 2003 | |
| 2004 | void zte_mgmt_set_login_timemark() |
| 2005 | { |
| 2006 | char login_timemark[NV_ITEM_STRING_LEN_20] = {0}; |
| 2007 | long now_timemark = time(0); |
| 2008 | |
| 2009 | sprintf(login_timemark, "%ld", now_timemark); |
| 2010 | zte_web_write(NV_USER_LOGIN_TIMEMARK, login_timemark); |
| 2011 | slog(MISC_PRINT, SLOG_NORMAL,"[SNTP] [manual] timemark, user_login_timemark=%ld\n", now_timemark); |
| 2012 | } |
| 2013 | |
| 2014 | int manual_set_time() |
| 2015 | { |
| 2016 | struct timeval tp; |
| 2017 | time_t nowtime; |
| 2018 | time_t SynBeforeTime = 0; |
| 2019 | int ltime = 0, mtime = 0, ntime = 0; |
| 2020 | char SynSystemTotal[16] = {0}; |
| 2021 | char SynPppTotal[16] = {0}; |
| 2022 | char SynSecond[16] = {0}; |
| 2023 | int year = 0, month = 0, day = 0; |
| 2024 | int hour = 0, minute = 0, second = 0; |
| 2025 | int days = 0; |
| 2026 | int LeapYear = 0; |
| 2027 | int CommonYear = 0; |
| 2028 | int YearTotal = 0; |
| 2029 | int count; |
| 2030 | int flag = 0; |
| 2031 | int i; |
| 2032 | int ret = 0; |
| 2033 | char buf[NV_ITEM_STRING_LEN_10] = {0}; |
| 2034 | char ppp_status[NV_ITEM_STRING_LEN_50] = {0}; |
| 2035 | struct tm timeToSet = {0}; |
| 2036 | int dataLen = 0; |
| 2037 | sc_cfg_get("manual_time_year", buf, sizeof(buf)); |
| 2038 | year = atoi(buf); |
| 2039 | if(year < 1970 || year > 2100)//for kw |
| 2040 | { |
| 2041 | return -1; |
| 2042 | } |
| 2043 | |
| 2044 | memset(&buf, 0, sizeof(buf)); |
| 2045 | sc_cfg_get("manual_time_month", buf, sizeof(buf)); |
| 2046 | month = atoi(buf); |
| 2047 | if(month<1 || month>12) |
| 2048 | { |
| 2049 | month = 1; |
| 2050 | } |
| 2051 | |
| 2052 | memset(&buf, 0, sizeof(buf)); |
| 2053 | sc_cfg_get("manual_time_day", buf, sizeof(buf)); |
| 2054 | day = atoi(buf); |
| 2055 | if(day<1 || day>31) |
| 2056 | { |
| 2057 | day = 1; |
| 2058 | } |
| 2059 | |
| 2060 | memset(&buf, 0, sizeof(buf)); |
| 2061 | sc_cfg_get("manual_time_hour", buf, sizeof(buf)); |
| 2062 | hour = atoi(buf); |
| 2063 | if(hour<0 || hour>24) |
| 2064 | { |
| 2065 | hour = 0; |
| 2066 | } |
| 2067 | |
| 2068 | memset(&buf, 0, sizeof(buf)); |
| 2069 | sc_cfg_get("manual_time_minute", buf, sizeof(buf)); |
| 2070 | minute = atoi(buf); |
| 2071 | if(minute<0 || minute>60) |
| 2072 | { |
| 2073 | minute = 0; |
| 2074 | } |
| 2075 | |
| 2076 | memset(&buf, 0, sizeof(buf)); |
| 2077 | sc_cfg_get("manual_time_second", buf, sizeof(buf)); |
| 2078 | second = atoi(buf); |
| 2079 | if(second<0 || second>60) |
| 2080 | { |
| 2081 | second = 0; |
| 2082 | } |
| 2083 | |
| 2084 | YearTotal = year - 1970; |
| 2085 | for (count = 0; count < YearTotal; count++) { |
| 2086 | i = 1971 + count; |
| 2087 | if (i % 4 == 0 && i % 100 != 0) { |
| 2088 | if (YearTotal == count + 1) { |
| 2089 | CommonYear++; |
| 2090 | } else { |
| 2091 | LeapYear++; |
| 2092 | } |
| 2093 | continue; |
| 2094 | } else if (i % 400 == 0) { |
| 2095 | if (YearTotal == count + 1) { |
| 2096 | CommonYear++; |
| 2097 | } else { |
| 2098 | LeapYear++; |
| 2099 | } |
| 2100 | continue; |
| 2101 | } else { |
| 2102 | CommonYear++; |
| 2103 | } |
| 2104 | } |
| 2105 | |
| 2106 | /****************flag==1±íʾµ±ÄêΪÈòÄê*************************/ |
| 2107 | if (year % 4 == 0 && year % 100 != 0) { |
| 2108 | flag = 1; |
| 2109 | } else if (year % 400 == 0) { |
| 2110 | flag = 1; |
| 2111 | } else { |
| 2112 | flag = 0; |
| 2113 | } |
| 2114 | |
| 2115 | switch (month - 1) { |
| 2116 | case 0: |
| 2117 | days = day; |
| 2118 | break; |
| 2119 | case 1: |
| 2120 | days = 31 + day; |
| 2121 | break; |
| 2122 | case 2: |
| 2123 | days = 31 + 28 + day; |
| 2124 | break; |
| 2125 | case 3: |
| 2126 | days = 31 + 28 + 31 + day; |
| 2127 | break; |
| 2128 | case 4: |
| 2129 | days = 31 + 28 + 31 + 30 + day; |
| 2130 | break; |
| 2131 | case 5: |
| 2132 | days = 31 + 28 + 31 + 30 + 31 + day; |
| 2133 | break; |
| 2134 | case 6: |
| 2135 | days = 31 + 28 + 31 + 30 + 31 + 30 + day; |
| 2136 | break; |
| 2137 | case 7: |
| 2138 | days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + day; |
| 2139 | break; |
| 2140 | case 8: |
| 2141 | days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day; |
| 2142 | break; |
| 2143 | case 9: |
| 2144 | days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day; |
| 2145 | break; |
| 2146 | case 10: |
| 2147 | days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day; |
| 2148 | break; |
| 2149 | case 11: |
| 2150 | days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day; |
| 2151 | break; |
| 2152 | } |
| 2153 | if ((month - 1) >= 2 && 1 == flag) { |
| 2154 | days++; |
| 2155 | } |
| 2156 | |
| 2157 | |
| 2158 | nowtime = COMMONYEARSEC * CommonYear + LEAPYEARSEC * LeapYear + (days - 1) * DAYSEC + hour * 3600 + minute * 60 + second; |
| 2159 | tp.tv_usec = 0; |
| 2160 | tp.tv_sec = nowtime; |
| 2161 | |
| 2162 | time(&SynBeforeTime); |
| 2163 | slog(MISC_PRINT, SLOG_DEBUG, "Now time is %d", SynBeforeTime); /*lint !e26*/ |
| 2164 | |
| 2165 | sc_cfg_get("syn_after_time", SynSecond, sizeof(SynSecond)); |
| 2166 | sscanf(SynSecond, "%d", <ime); |
| 2167 | if(ltime < 0 || ltime > INT_MAX-1) // kw 3 |
| 2168 | { |
| 2169 | ltime = 0; |
| 2170 | } |
| 2171 | |
| 2172 | sc_cfg_get("syn_system_total", SynSystemTotal, sizeof(SynSystemTotal)); |
| 2173 | |
| 2174 | sscanf(SynSystemTotal, "%d", &mtime); |
| 2175 | if(mtime < 0 || mtime > INT_MAX-1) // kw 3 |
| 2176 | { |
| 2177 | mtime = 0; |
| 2178 | } |
| 2179 | |
| 2180 | if (0 != mtime) { |
| 2181 | mtime += (SynBeforeTime - ltime); |
| 2182 | } else { |
| 2183 | mtime = (SynBeforeTime - JAN_2000); |
| 2184 | } |
| 2185 | sprintf(SynSystemTotal, "%d", mtime); |
| 2186 | sc_cfg_set("syn_system_total", SynSystemTotal); |
| 2187 | |
| 2188 | sc_cfg_get("ppp_status", ppp_status, sizeof(ppp_status)); |
| 2189 | if ((0 == strcmp(ppp_status, "ppp_connected")) || (0 == strcmp(ppp_status, "ipv6_connected")) || (0 == strcmp(ppp_status, "ipv4_ipv6_connected"))) { |
| 2190 | sc_cfg_get("syn_ppp_total", SynPppTotal, sizeof(SynPppTotal)); |
| 2191 | |
| 2192 | sscanf(SynPppTotal, "%d", &mtime); |
| 2193 | if(mtime < 0 || mtime > INT_MAX-1) // kw 3 |
| 2194 | { |
| 2195 | mtime = 0; |
| 2196 | } |
| 2197 | if (0 != mtime) { |
| 2198 | mtime += (SynBeforeTime - ltime); |
| 2199 | } else { |
| 2200 | memset(&SynSecond, 0, sizeof(SynSecond)); |
| 2201 | sc_cfg_get("ppp_start_time", SynSecond, sizeof(SynSecond)); |
| 2202 | |
| 2203 | sscanf(SynSecond, "%d", &ntime); |
| 2204 | if(ntime < 0 || ntime > INT_MAX-1) // kw 3 |
| 2205 | { |
| 2206 | ntime = 0; |
| 2207 | } |
| 2208 | |
| 2209 | mtime = SynBeforeTime - ntime; |
| 2210 | } |
| 2211 | sprintf(SynPppTotal, "%d", mtime); |
| 2212 | sc_cfg_set("syn_ppp_total", SynPppTotal); |
| 2213 | sc_cfg_set("syn_order_flag", "ppp_on"); |
| 2214 | } else { |
| 2215 | sc_cfg_set("syn_order_flag", "ppp_off"); |
| 2216 | sc_cfg_set("syn_ppp_total", "0"); |
| 2217 | } |
| 2218 | |
| 2219 | timeToSet.tm_year = year-1900; |
| 2220 | timeToSet.tm_mon = month-1; |
| 2221 | timeToSet.tm_mday = day; |
| 2222 | timeToSet.tm_hour = hour; |
| 2223 | timeToSet.tm_min = minute; |
| 2224 | timeToSet.tm_sec = second; |
| 2225 | dataLen = sizeof(struct tm); |
| 2226 | slog(MISC_PRINT, SLOG_DEBUG, "SetTime:year:%d, mon:%d, day:%d, hour:%d, min:%d, sec:%d \n", |
| 2227 | timeToSet.tm_year, timeToSet.tm_mon, timeToSet.tm_mday, |
| 2228 | timeToSet.tm_hour, timeToSet.tm_min, timeToSet.tm_sec ); |
| 2229 | ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_SNTP, MSG_CMD_SNTP_SET_TIME, |
| 2230 | dataLen, &timeToSet, 0); |
| 2231 | if (0 != ret) { |
| 2232 | slog(MISC_PRINT, SLOG_ERR, "send MSG_CMD_SNTP_SET_TIME to sntp fail!"); |
| 2233 | } |
| 2234 | |
| 2235 | ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_SYCTIME_SET_REQ, 0, NULL, 0); |
| 2236 | if (0 != ret) { |
| 2237 | slog(MISC_PRINT, SLOG_ERR, "sync time to cp fail!"); |
| 2238 | } |
| 2239 | |
| 2240 | memset(&buf, 0, sizeof(buf)); |
| 2241 | sc_cfg_get("outdate_delete", buf, sizeof(buf)); |
| 2242 | if (0 == strcmp(buf, "1")) { |
| 2243 | ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_SMS, MSG_CMD_SMS_OUTDATE_CHECK, 0, NULL, 0); |
| 2244 | } |
| 2245 | |
| 2246 | sprintf(SynSecond, "%d", (int)(time((time_t *)NULL))); |
| 2247 | sc_cfg_set("syn_after_time", SynSecond); |
| 2248 | //sc_cfg_set("systime_mode", "manual"); |
| 2249 | sc_cfg_set("need_clear_traffic_data", "yes"); |
| 2250 | zte_mgmt_set_login_timemark(); |
| 2251 | return 0; |
| 2252 | } |
| 2253 | char * timei2s(int itime) |
| 2254 | { |
| 2255 | static char buf[64]; |
| 2256 | int hours, min, sec; |
| 2257 | memset(buf, 0, 64); |
| 2258 | |
| 2259 | hours = itime / 3600; |
| 2260 | min = (itime / 60) % 60; |
| 2261 | sec = itime % 60; |
| 2262 | |
| 2263 | sprintf(buf, "%d:%02d:%02d", hours, min, sec); |
| 2264 | return buf ; |
| 2265 | } |
| 2266 | void timeen2ch(char *time) |
| 2267 | { |
| 2268 | char timetmp[128] = {0}; |
| 2269 | char year[5] = {0}; |
| 2270 | char month[4] = {0}; |
| 2271 | char day[3] = {0}; |
| 2272 | char weekday[4] = {0}; |
| 2273 | char nowtime[16] = {0}; |
| 2274 | char hour[4] = {0}; |
| 2275 | char second[4] = {0}; |
| 2276 | char minute[4] = {0}; |
| 2277 | //int imonth; |
| 2278 | char imonth[4] = {0}; |
| 2279 | strncpy(timetmp, time,sizeof(timetmp)-1); |
| 2280 | char *loc = timetmp; |
| 2281 | char *tmp = NULL; |
| 2282 | memset(time, 0, 128); |
| 2283 | char str_buf[10] = {0}; |
| 2284 | int temp; |
| 2285 | int month_temp; |
| 2286 | |
| 2287 | while (*loc == ' ') { |
| 2288 | loc++; |
| 2289 | } |
| 2290 | tmp = strtok(loc, " "); |
| 2291 | if(tmp == NULL) return; |
| 2292 | strncpy(weekday, tmp, sizeof(weekday)-1); |
| 2293 | tmp = strtok(NULL, " "); |
| 2294 | if(tmp == NULL) return; |
| 2295 | strncpy(month, tmp, sizeof(month)-1); |
| 2296 | tmp = strtok(NULL, " "); |
| 2297 | if(tmp == NULL) return; |
| 2298 | strncpy(day, tmp, sizeof(day)-1); |
| 2299 | slog(MISC_PRINT, SLOG_DEBUG, "strlen(tmp)=%d", strlen(tmp)); /*lint !e26*/ |
| 2300 | if (strlen(tmp) == 1) { |
| 2301 | temp = atoi(tmp); |
| 2302 | slog(MISC_PRINT, SLOG_DEBUG, "====temp=%d", temp); /*lint !e26*/ |
| 2303 | if(temp < 10 && temp > 0) |
| 2304 | snprintf(day,sizeof(day), "0%d", temp); |
| 2305 | slog(MISC_PRINT, SLOG_DEBUG, "====day=%s", day); /*lint !e26*/ |
| 2306 | } else { |
| 2307 | strncpy(day, tmp,sizeof(day)-1); |
| 2308 | } |
| 2309 | tmp = strtok(NULL, " "); |
| 2310 | if(tmp == NULL) return; |
| 2311 | strncpy(nowtime, tmp, sizeof(nowtime)-1); |
| 2312 | tmp = strtok(NULL, " "); |
| 2313 | if(tmp == NULL) return; |
| 2314 | strncpy(year, tmp, sizeof(year)-1); |
| 2315 | if (0 == strcmp("Jan", month)) { |
| 2316 | strncpy(imonth, "01", sizeof(imonth)-1); |
| 2317 | } else if (0 == strcmp("Feb", month)) { |
| 2318 | strncpy(imonth, "02", sizeof(imonth)-1); |
| 2319 | } else if (0 == strcmp("Mar", month)) { |
| 2320 | strncpy(imonth, "03", sizeof(imonth)-1); |
| 2321 | } else if (0 == strcmp("Apr", month)) { |
| 2322 | strncpy(imonth, "04", sizeof(imonth)-1); |
| 2323 | } else if (0 == strcmp("May", month)) { |
| 2324 | strncpy(imonth, "05", sizeof(imonth)-1); |
| 2325 | } else if (0 == strcmp("Jun", month)) { |
| 2326 | strncpy(imonth, "06", sizeof(imonth)-1); |
| 2327 | } else if (0 == strcmp("Jul", month)) { |
| 2328 | strncpy(imonth, "07", sizeof(imonth)-1); |
| 2329 | } else if (0 == strcmp("Aug", month)) { |
| 2330 | strncpy(imonth, "08", sizeof(imonth)-1); |
| 2331 | } else if (0 == strcmp("Sep", month)) { |
| 2332 | strncpy(imonth, "09", sizeof(imonth)-1); |
| 2333 | } else if (0 == strcmp("Oct", month)) { |
| 2334 | strncpy(imonth, "10", sizeof(imonth)-1); |
| 2335 | } else if (0 == strcmp("Nov", month)) { |
| 2336 | strncpy(imonth, "11", sizeof(imonth)-1); |
| 2337 | } else if (0 == strcmp("Dec", month)) { |
| 2338 | strncpy(imonth, "12", sizeof(imonth)-1); |
| 2339 | } |
| 2340 | sprintf(time, "%s-%s-%s %s", year, imonth, day, nowtime); |
| 2341 | slog(MISC_PRINT, SLOG_DEBUG, "====nowtime=%s", nowtime); /*lint !e26*/ |
| 2342 | |
| 2343 | |
| 2344 | tmp = strtok(nowtime, ":"); |
| 2345 | if(tmp == NULL) return; |
| 2346 | strncpy(hour, tmp,sizeof(hour)-1); |
| 2347 | slog(MISC_PRINT, SLOG_DEBUG, "====hour=%s", hour); /*lint !e26*/ |
| 2348 | tmp = strtok(NULL, ":"); |
| 2349 | if(tmp == NULL) return; |
| 2350 | strncpy(minute, tmp,sizeof(minute)-1); |
| 2351 | slog(MISC_PRINT, SLOG_DEBUG, "====minute=%s", minute); /*lint !e26*/ |
| 2352 | tmp = strtok(NULL, ":"); |
| 2353 | if(tmp == NULL) return; |
| 2354 | strncpy(second, tmp,sizeof(second)-1); |
| 2355 | slog(MISC_PRINT, SLOG_DEBUG, "====second=%s", second); /*lint !e26*/ |
| 2356 | sc_cfg_set("sntp_hour", hour); |
| 2357 | sc_cfg_set("sntp_minute", minute); |
| 2358 | sc_cfg_set("sntp_second", second); |
| 2359 | |
| 2360 | sc_cfg_set("sntp_year", year); |
| 2361 | sc_cfg_set("sntp_month", imonth); |
| 2362 | sc_cfg_set("sntp_day", day); |
| 2363 | } |
| 2364 | void datastatic(char *rec, char *send, char *onlinetime, char *runtime, char *localtime) |
| 2365 | { |
| 2366 | char Receive_Amount[20] = {0}; |
| 2367 | char Transmit_Amount[20] = {0}; |
| 2368 | char syn_system_total[20] = {0}; |
| 2369 | char syn_after_time[20] = {0}; |
| 2370 | char syn_ppp_total[20] = {0}; |
| 2371 | char ppp_start_time[20] = {0}; |
| 2372 | char timestr[128] = {0}; |
| 2373 | int mtime; |
| 2374 | int ltime; |
| 2375 | int ntime; |
| 2376 | int otime; |
| 2377 | time_t timenow; |
| 2378 | char ppp_status[NV_ITEM_STRING_LEN_50] = {0}; |
| 2379 | char buf[NV_ITEM_STRING_LEN_20] = {0}; |
| 2380 | |
| 2381 | sc_cfg_get("syn_system_total", syn_system_total, sizeof(syn_system_total)); |
| 2382 | |
| 2383 | sscanf(syn_system_total, "%d", <ime); |
| 2384 | if(ltime < 0 || ltime > INT_MAX-1) // kw 3 |
| 2385 | { |
| 2386 | ltime = 0; |
| 2387 | } |
| 2388 | sc_cfg_get("syn_after_time", syn_after_time, sizeof(syn_after_time)); |
| 2389 | |
| 2390 | sscanf(syn_after_time, "%d", &ntime); |
| 2391 | if(ntime < 0 || ntime > INT_MAX-1) // kw 3 |
| 2392 | { |
| 2393 | ntime = 0; |
| 2394 | } |
| 2395 | sc_cfg_get("ppp_start_time", ppp_start_time, sizeof(ppp_start_time)); |
| 2396 | |
| 2397 | sscanf(ppp_start_time, "%d", &otime); |
| 2398 | if(otime < 0 || otime > INT_MAX-1) // kw 3 |
| 2399 | { |
| 2400 | otime = 0; |
| 2401 | } |
| 2402 | |
| 2403 | sc_cfg_get("ppp_status", ppp_status, sizeof(ppp_status)); |
| 2404 | if ((0 != strcmp(ppp_status, "ppp_connected")) && (0 != strcmp(ppp_status, "ipv6_connected")) && (0 != strcmp(ppp_status, "ipv4_ipv6_connected"))) { |
| 2405 | sc_cfg_set("syn_ppp_total", "0"); |
| 2406 | } |
| 2407 | |
| 2408 | sc_cfg_get("syn_ppp_total", syn_ppp_total, sizeof(syn_ppp_total)); |
| 2409 | |
| 2410 | sscanf(syn_ppp_total, "%d", &mtime); |
| 2411 | if(mtime < 0 || mtime > INT_MAX-1) // kw 3 |
| 2412 | { |
| 2413 | mtime = 0; |
| 2414 | } |
| 2415 | |
| 2416 | time(&timenow); |
| 2417 | if (ntime == 0) { |
| 2418 | strncpy(onlinetime, timei2s(timenow - otime), 63); |
| 2419 | strncpy(runtime, timei2s(timenow - JAN_2000), 63); |
| 2420 | } else { |
| 2421 | sc_cfg_get("syn_order_flag", buf, sizeof(buf)); |
| 2422 | if (0 == strcmp(buf, "ppp_on")) { |
| 2423 | strncpy(onlinetime, timei2s(timenow - ntime + mtime), 63); |
| 2424 | } else { |
| 2425 | strncpy(onlinetime, timei2s(timenow - otime), 63); |
| 2426 | } |
| 2427 | strncpy(runtime, timei2s(timenow - ntime + ltime), 63); |
| 2428 | } |
| 2429 | slog(MISC_PRINT, SLOG_DEBUG, "----runtime=%s", runtime); /*lint !e26*/ |
| 2430 | strncpy(timestr, ctime(&timenow),sizeof(timestr)-1); |
| 2431 | slog(MISC_PRINT, SLOG_DEBUG, "----timestr=%s", timestr); /*lint !e26*/ |
| 2432 | timeen2ch(timestr); |
| 2433 | strncpy(localtime, timestr,sizeof(localtime)-1); |
| 2434 | slog(MISC_PRINT, SLOG_DEBUG, "----localtime=%s", localtime); /*lint !e26*/ |
| 2435 | |
| 2436 | } |
| 2437 | |
| 2438 | void zte_goform_sntp_getdatastatic_process(webs_t wp) |
| 2439 | { |
| 2440 | char receive[30], send[30], onlinetime[64], runtime[64], localtime[128]; |
| 2441 | |
| 2442 | memset(receive, 0, 30); |
| 2443 | memset(send, 0, 30); |
| 2444 | memset(onlinetime, 0, 64); |
| 2445 | memset(runtime, 0, 64); |
| 2446 | memset(localtime, 0, 128); |
| 2447 | |
| 2448 | datastatic(receive, send, onlinetime, runtime, localtime); |
| 2449 | |
| 2450 | websWrite(wp, T("{\"receive\":\"%s\",\"send\":\"%s\",\"onlinetime\":\"%s\",\"runtime\":\"%s\",\"localtime\":\"%s\"}"), receive, send, onlinetime, runtime, localtime); |
| 2451 | } |
| 2452 | |
| 2453 | |
| 2454 | typedef struct LOG_FILES { |
| 2455 | char filename[64]; |
| 2456 | } LOG_FILES; |
| 2457 | |
| 2458 | int start_diaglog() |
| 2459 | { |
| 2460 | int ret = 0; |
| 2461 | slog(MISC_PRINT, SLOG_NORMAL, "start_diaglog"); /*lint !e26*/ |
| 2462 | system("/sbin/diaglog &"); |
| 2463 | return ret; |
| 2464 | } |
| 2465 | |
| 2466 | int stop_diaglog() |
| 2467 | { |
| 2468 | int ret = 0; |
| 2469 | slog(MISC_PRINT, SLOG_NORMAL, "get killall SIGINT"); /*lint !e26*/ |
| 2470 | system("killall -9 diaglog");//SIGINT=2 |
| 2471 | return ret; |
| 2472 | } |
| 2473 | #if 0 |
| 2474 | int del_diaglog(char *fllename) |
| 2475 | { |
| 2476 | slog(MISC_PRINT, SLOG_NORMAL, "del log name=%s", fllename); /*lint !e26*/ |
| 2477 | int ret = 0; |
| 2478 | char cmd[128]; |
| 2479 | sprintf(cmd, "rm %s", fllename); |
| 2480 | system(cmd); |
| 2481 | return ret; |
| 2482 | } |
| 2483 | #endif |
| 2484 | |
| 2485 | int getDiaglogFile(LOG_FILES *files, int n_files) |
| 2486 | { |
| 2487 | char ext[] = ".dlf"; |
| 2488 | int i = 0; |
| 2489 | |
| 2490 | DIR *dp; |
| 2491 | struct dirent *entry; |
| 2492 | |
| 2493 | dp = opendir(DIAGLOG_DATA_PATH); |
| 2494 | if (dp == NULL) { |
| 2495 | slog(MISC_PRINT, SLOG_ERR, "dp==NULL"); |
| 2496 | return 0; |
| 2497 | } |
| 2498 | |
| 2499 | i = 0; |
| 2500 | while ((entry = readdir(dp)) != NULL && (i < n_files)) { |
| 2501 | { |
| 2502 | int len = strlen(entry->d_name); |
| 2503 | if ((len > strlen(ext)) && !strcmp(entry->d_name + len - strlen(ext), ext)) { //*.dlf *.zm |
| 2504 | strncpy(files[i].filename, entry->d_name, sizeof(files[i].filename)-1); |
| 2505 | slog(MISC_PRINT, SLOG_DEBUG, "entry->d_name=%s", entry->d_name); |
| 2506 | i++; |
| 2507 | } |
| 2508 | } |
| 2509 | } |
| 2510 | closedir(dp); |
| 2511 | |
| 2512 | return i; |
| 2513 | |
| 2514 | } |
| 2515 | |
| 2516 | |
| 2517 | void getdialog_url(int eid, webs_t wp, int argc, char_t **argv) |
| 2518 | { |
| 2519 | char filename[128] = {0}; |
| 2520 | LOG_FILES files[10]; |
| 2521 | int n, i; |
| 2522 | char *p = filename; |
| 2523 | n = getDiaglogFile(files, 10); |
| 2524 | i = 0; |
| 2525 | if (n > 0) { |
| 2526 | while (i < n) { |
| 2527 | slog(MISC_PRINT, SLOG_DEBUG, "i=%d", i); /*lint !e26*/ |
| 2528 | strcpy(p, files[i].filename); |
| 2529 | p += strlen(files[i].filename); |
| 2530 | *p = ';'; |
| 2531 | p++; |
| 2532 | slog(MISC_PRINT, SLOG_DEBUG, "filename=%s", files[i].filename); /*lint !e26*/ |
| 2533 | i++; |
| 2534 | } |
| 2535 | websWrite(wp, T(filename)); |
| 2536 | } else { |
| 2537 | websWrite(wp, T("")); |
| 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | /****************************************************** |
| 2542 | * Function: zte_fota_get_upgrade_result |
| 2543 | * Description: get fota upgrade result |
| 2544 | * Input: http request info |
| 2545 | * Output: |
| 2546 | * Return: |
| 2547 | * Others: |
| 2548 | * Modify Date Version Author Modification |
| 2549 | * 2013/03/14 V1.0 chenyi create |
| 2550 | *******************************************************/ |
| 2551 | void zte_fota_get_upgrade_result(webs_t wp) |
| 2552 | { |
| 2553 | zte_topsw_state_e_type nv_result = ZTE_NVIO_MAX; |
| 2554 | |
| 2555 | char nv_upgrade_result[NV_ITEM_STRING_LEN_50] = {0}; |
| 2556 | |
| 2557 | nv_result = zte_web_read(NV_FOTA_UPGRADE_RESULT, nv_upgrade_result); |
| 2558 | if (ZTE_NVIO_DONE != nv_result) { |
| 2559 | slog(MISC_PRINT, SLOG_ERR,"read nv [%s] fail.\n", NV_FOTA_UPGRADE_RESULT); |
| 2560 | } |
| 2561 | |
| 2562 | web_feedback_header(wp); |
| 2563 | (void)websWrite(wp, T("{\"%s\":\"%s\"}"), FOTA_UPGRADE_RESULT, nv_upgrade_result); |
| 2564 | |
| 2565 | if ((0 == strcmp("success", nv_upgrade_result)) || (0 == strcmp("fail", nv_upgrade_result))) { |
| 2566 | (void)zte_web_write(NV_FOTA_UPGRADE_RESULT, ""); //reset |
| 2567 | |
| 2568 | // ÖØÖÃNVºó±£´æ¸ÃNV²ÎÊý£¬±ÜÃâÒò¿ìËÙÖØÆô£¬NVÐÂֵδ±£´æµ¼Öµĸüнá¹ûÖØ¸´Éϱ¨ÎÊÌâ |
| 2569 | //sc_cfg_save(); |
| 2570 | slog(MISC_PRINT, SLOG_ERR,"reset nv [%s]. nv_upgrade_result:%s\n", NV_FOTA_UPGRADE_RESULT, nv_upgrade_result); |
| 2571 | } |
| 2572 | } |
| 2573 | |
| 2574 | #if 0 |
| 2575 | /****************************************************** |
| 2576 | * Function: zte_fota_get_dp_pack_info |
| 2577 | * Description: get fota dp info |
| 2578 | * Input: http request info |
| 2579 | * Output: |
| 2580 | * Return: |
| 2581 | * Others: |
| 2582 | * Modify Date Version Author Modification |
| 2583 | * 2013/01/06 V1.0 chenyi create |
| 2584 | *******************************************************/ |
| 2585 | void zte_fota_get_dp_pack_info(webs_t wp) |
| 2586 | { |
| 2587 | char dp_total_size[NV_ITEM_STRING_LEN_50] = {0}; |
| 2588 | char dp_download_size[NV_ITEM_STRING_LEN_50] = {0}; |
| 2589 | |
| 2590 | //get dp pack info |
| 2591 | (void)zte_web_read(NV_FOTA_PKG_TOTAL_SIZE, dp_total_size); |
| 2592 | (void)zte_web_read(NV_FOTA_PKG_DL_SIZE, dp_download_size); |
| 2593 | |
| 2594 | web_feedback_header(wp); |
| 2595 | (void)websWrite(wp, T("{\"%s\":\"%s\",\"%s\":\"%s\"}"), \ |
| 2596 | NV_FOTA_PKG_TOTAL_SIZE, dp_total_size, NV_FOTA_PKG_DL_SIZE, dp_download_size); |
| 2597 | } |
| 2598 | #endif |
| 2599 | /********************************************************************** |
| 2600 | * Function: zte_fota_update |
| 2601 | * Description: send msg to fota update module |
| 2602 | * Input: wp:the web para; |
| 2603 | * Output: |
| 2604 | * Return: |
| 2605 | * Others: add from uFi |
| 2606 | * Modify Date Version Author Modification |
| 2607 | * ----------------------------------------------- |
| 2608 | * |
| 2609 | **********************************************************************/ |
| 2610 | int zte_fota_SendMsg2DM(int cmd) |
| 2611 | { |
| 2612 | slog(MISC_PRINT, SLOG_NORMAL,"goahead send cmd=%d to fota\n", cmd); |
| 2613 | return ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_DM_WEBUI_AT, cmd, 0, NULL, 0); |
| 2614 | } |
| 2615 | |
| 2616 | void zte_fota_update(webs_t wp) |
| 2617 | { |
| 2618 | slog(MISC_PRINT, SLOG_NORMAL, T("UFIx User check new version!\n")); |
| 2619 | char *update_action = NULL; |
| 2620 | zte_topsw_state_e_type nv_result = ZTE_NVIO_MAX; |
| 2621 | char new_version_state[NV_ITEM_STRING_LEN_150] = {0}; |
| 2622 | BOOL new_state_version_check = FALSE; |
| 2623 | int iDlPara = -1; |
| 2624 | |
| 2625 | if (NULL == wp) { |
| 2626 | return; |
| 2627 | } |
| 2628 | |
| 2629 | update_action = websGetVar(wp, T("select_op"), T("")); |
| 2630 | slog(MISC_PRINT, SLOG_DEBUG,"websGetVar FOTA upgrade action[%s].\n", update_action); |
| 2631 | |
| 2632 | if ('\0' == *update_action) { |
| 2633 | zte_write_result_to_web(wp, FAILURE); |
| 2634 | return; |
| 2635 | } |
| 2636 | |
| 2637 | |
| 2638 | //ÓëdeviceUiµÄ»¥³â±£»¤´¦Àí |
| 2639 | zte_web_read(NV_FOTA_NEW_VERSION_STATE, new_version_state); |
| 2640 | |
| 2641 | if ((0 == strcmp(update_action, FOTA_ACTION_CONFIRM_DOWNLOAD)) || (0 == strcmp(update_action, FOTA_ACTION_CANCEL_DOWNLOAD))) { |
| 2642 | if ((0 == strcmp(new_version_state, HAS_OPTIONAL)) || (0 == strcmp(new_version_state, HAS_CRITICAL))) { |
| 2643 | new_state_version_check = TRUE; |
| 2644 | } |
| 2645 | if (!new_state_version_check) { |
| 2646 | zte_write_result_to_web(wp, FAILURE); |
| 2647 | return; |
| 2648 | } |
| 2649 | } |
| 2650 | |
| 2651 | if (0 == strcmp(update_action, FOTA_ACTION_CONFIRM_DOWNLOAD)) { |
| 2652 | zte_web_write(NV_FOTA_UPGRADE_SELECTOR, "accept"); |
| 2653 | //zte_web_write(NV_FOTA_NEED_USER_CONFIRM,"0"); |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2654 | slog(MISC_PRINT, SLOG_DEBUG,"web :fota_update. update_action = FOTA_ACTION_CONFIRM_DOWNLOAD, set NV_FOTA_UPGRADE_SELECTOR accept!\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2655 | //zte_fota_SendMsg2DM(MSG_CMD_FOTA_WEBUI_START_DOWNLOAD); |
| 2656 | //ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_DM_WEBUI_AT,MSG_CMD_FOTA_WEBUI_START_DOWNLOAD, 2, "1", 0); |
| 2657 | iDlPara = 1; |
| 2658 | ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_DM_WEBUI_AT, MSG_CMD_FOTADL_REQ, sizeof(iDlPara), (UCHAR *)(&iDlPara), 0); |
| 2659 | } else if (0 == strcmp(update_action, FOTA_ACTION_CANCEL_DOWNLOAD)) { |
| 2660 | (void)zte_web_write(NV_FOTA_UPGRADE_SELECTOR, "cancel"); |
| 2661 | zte_web_write(NV_FOTA_NEW_VERSION_STATE, IDLE); |
| 2662 | zte_web_write(NV_FOTA_CURR_UPGRADE_STATE, IDLE); |
| 2663 | |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2664 | slog(MISC_PRINT, SLOG_DEBUG,"web :fota_update. update_action = FOTA_ACTION_CANCEL_DOWNLOAD, set NV_FOTA_UPGRADE_SELECTOR cancel!\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2665 | zte_write_result_to_web(wp, SUCCESS); |
| 2666 | return; //no need to send msg to ota module |
| 2667 | } else if (0 == strcmp(update_action, "check")) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2668 | slog(MISC_PRINT, SLOG_DEBUG,"goahead :fota_update. begin to check!!\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2669 | zte_fota_SendMsg2DM(MSG_CMD_FOTA_WEBUI_START_FOTA); |
| 2670 | } |
| 2671 | |
| 2672 | zte_write_result_to_web(wp, SUCCESS); |
| 2673 | } |
| 2674 | |
| 2675 | /********************************************************************** |
| 2676 | * Function: zte_fota_settings |
| 2677 | * Description: to set fota settings |
| 2678 | * Input: wp:the web para;dm_nextpollingtime;dm_pollingcycle;pollingswitch; |
| 2679 | * Output: |
| 2680 | * Return: |
| 2681 | * Others: add from uFi |
| 2682 | * Modify Date Version Author Modification |
| 2683 | * ----------------------------------------------- |
| 2684 | * |
| 2685 | **********************************************************************/ |
| 2686 | void zte_fota_settings(webs_t wp) |
| 2687 | { |
| 2688 | char_t *updateMode = NULL; |
| 2689 | char_t *allowRoamingUpdate = NULL; |
| 2690 | zte_topsw_state_e_type status = ZTE_NVIO_MAX; |
| 2691 | |
| 2692 | if (NULL == wp) { |
| 2693 | return; |
| 2694 | } |
| 2695 | |
| 2696 | updateMode = websGetVar(wp, T("UpgMode"), T("")); |
| 2697 | allowRoamingUpdate = websGetVar(wp, T("UpgRoamPermission"), T("")); |
| 2698 | |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2699 | slog(MISC_PRINT, SLOG_DEBUG,"fota_settings web para:[updateMode] is [%s].\n", updateMode); |
| 2700 | slog(MISC_PRINT, SLOG_DEBUG,"fota_settings web para:[allowRoamingUpdate] is [%s].\n", allowRoamingUpdate); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2701 | |
| 2702 | if ('\0' == (*updateMode)) { |
| 2703 | zte_write_result_to_web(wp, FAILURE); |
| 2704 | return; |
| 2705 | } |
| 2706 | |
| 2707 | status = zte_web_write("fota_allowRoamingUpdate", allowRoamingUpdate); |
| 2708 | if (ZTE_NVIO_DONE != status) { |
| 2709 | zte_write_result_to_web(wp, FAILURE); |
| 2710 | return; |
| 2711 | } |
| 2712 | |
| 2713 | |
| 2714 | status = zte_web_write("fota_updateMode", updateMode); |
| 2715 | if (ZTE_NVIO_DONE != status) { |
| 2716 | zte_write_result_to_web(wp, FAILURE); |
| 2717 | return; |
| 2718 | } |
| 2719 | zte_fota_SendMsg2DM(MSG_CMD_FOTA_WEBUI_CHANGE_PARAMETER); |
| 2720 | zte_write_result_to_web(wp, SUCCESS); |
| 2721 | } |
| 2722 | |
| 2723 | #if 0 |
| 2724 | |
| 2725 | /********************************************************************** |
| 2726 | * Function: zte_get_fota_settings |
| 2727 | * Description: to get fota settings |
| 2728 | * Input: wp:the web para; |
| 2729 | * Output: |
| 2730 | * Return: |
| 2731 | * Others: add from uFi |
| 2732 | * Modify Date Version Author Modification |
| 2733 | * ----------------------------------------------- |
| 2734 | * |
| 2735 | **********************************************************************/ |
| 2736 | void zte_get_fota_settings(webs_t wp) |
| 2737 | { |
| 2738 | zte_topsw_state_e_type status = ZTE_NVIO_MAX; |
| 2739 | |
| 2740 | char_t updateMode[NV_ITEM_STRING_LEN_20] = {0}; |
| 2741 | char_t updateIntervalDay[NV_ITEM_STRING_LEN_20] = {0}; |
| 2742 | char_t allowRoamingUpdate[NV_ITEM_STRING_LEN_20] = {0}; |
| 2743 | |
| 2744 | status = zte_web_read("fota_allowRoamingUpdate", allowRoamingUpdate); |
| 2745 | if (ZTE_NVIO_DONE != status) { |
| 2746 | zte_write_result_to_web(wp, FAILURE); |
| 2747 | return; |
| 2748 | } |
| 2749 | |
| 2750 | status = zte_web_read("fota_updateIntervalDay", updateIntervalDay); |
| 2751 | if (ZTE_NVIO_DONE != status) { |
| 2752 | zte_write_result_to_web(wp, FAILURE); |
| 2753 | return; |
| 2754 | } |
| 2755 | |
| 2756 | status = zte_web_read("fota_updateMode", updateMode); |
| 2757 | if (ZTE_NVIO_DONE != status) { |
| 2758 | zte_write_result_to_web(wp, FAILURE); |
| 2759 | return; |
| 2760 | } |
| 2761 | |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2762 | WEBLOG("get_fota_settings:[updateMode] is [%s].\n", updateMode); |
| 2763 | WEBLOG("get_fota_settings:[updateIntervalDay] is [%s].\n", updateIntervalDay); |
| 2764 | WEBLOG("get_fota_settings:[allowRoamingUpdate] is [%s].\n", allowRoamingUpdate); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2765 | |
| 2766 | web_feedback_header(wp); |
| 2767 | zte_rest_cmd_write_head(wp); |
| 2768 | |
| 2769 | if ('\0' != *updateMode) |
| 2770 | zte_rest_cmd_write(wp, "UpgMode", updateMode, 1); |
| 2771 | else |
| 2772 | zte_rest_cmd_write(wp, "UpgMode", "0", 1); |
| 2773 | |
| 2774 | if ('\0' != *updateIntervalDay) |
| 2775 | zte_rest_cmd_write(wp, "UpgIntervalDay", updateIntervalDay, 1); |
| 2776 | else |
| 2777 | zte_rest_cmd_write(wp, "UpgIntervalDay", "1", 1); |
| 2778 | |
| 2779 | if ('\0' != *allowRoamingUpdate) |
| 2780 | zte_rest_cmd_write(wp, "UpgRoamPermission", allowRoamingUpdate, 0); |
| 2781 | else |
| 2782 | zte_rest_cmd_write(wp, "UpgRoamPermission", "0", 0); |
| 2783 | |
| 2784 | zte_rest_cmd_write_foot(wp); |
| 2785 | } |
| 2786 | |
| 2787 | |
| 2788 | /****************************************************** |
| 2789 | * Function: zte_fota_get_update_info |
| 2790 | * Description: get fota update info |
| 2791 | * Input: http request info |
| 2792 | * Output: |
| 2793 | * Return: |
| 2794 | * Others: |
| 2795 | * Modify Date Version Author Modification |
| 2796 | * 2013/01/06 V1.0 chenyi create |
| 2797 | *******************************************************/ |
| 2798 | void zte_fota_get_update_info(webs_t wp) |
| 2799 | { |
| 2800 | char version[NV_ITEM_STRING_LEN_64 + 1] = {0}; |
| 2801 | |
| 2802 | (void)zte_web_read(NV_FOTA_VERSION, version); |
| 2803 | |
| 2804 | web_feedback_header(wp); |
| 2805 | (void)websWrite(wp, T("{\"%s\":\"%s\"}"), FOTA_UPDATE_VERSION, version); |
| 2806 | } |
| 2807 | #endif |
| 2808 | |
| 2809 | void zte_wan_lock_frequency_process(webs_t wp) |
| 2810 | { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2811 | slog(MISC_PRINT, SLOG_NORMAL, "wan_lock_frequency_process coming"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2812 | CHAR *actionlte = NULL; |
| 2813 | CHAR *uarfcnlte = NULL; |
| 2814 | CHAR *cellParaIdlte = NULL; |
| 2815 | |
| 2816 | /* get value from web page */ |
| 2817 | actionlte = websGetVar(wp, T("actionlte"), T("")); |
| 2818 | uarfcnlte = websGetVar(wp, T("uarfcnlte"), T("")); |
| 2819 | cellParaIdlte = websGetVar(wp, T("cellParaIdlte"), T("")); |
| 2820 | |
| 2821 | sc_cfg_set("actionlte", actionlte); |
| 2822 | sc_cfg_set("uarfcnlte", uarfcnlte); |
| 2823 | sc_cfg_set("cellParaIdlte", cellParaIdlte); |
| 2824 | ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_CELL_LOCK_REQ, 0, NULL, 0); |
| 2825 | zte_write_result_to_web(wp, SUCCESS); |
| 2826 | } |
| 2827 | |
| 2828 | void zte_setLastLoginTime() |
| 2829 | { |
| 2830 | int curr_time = 0; |
| 2831 | char login_time[LOGIN_RECORD_TIME] = {0}; |
| 2832 | curr_time = zte_web_getCurrentTime(); |
| 2833 | sprintf(login_time, "%d", curr_time); |
| 2834 | (void)zte_web_write(NV_LAST_LOGIN_TIME, login_time); |
| 2835 | } |
| 2836 | |
| 2837 | int zte_checkLoginTime() |
| 2838 | { |
| 2839 | char last_record_time[LOGIN_RECORD_TIME] = {0}; |
| 2840 | int last_record_time_num = 0; |
| 2841 | int curr_record_time_num = 0; |
| 2842 | int lock_time = 0; |
| 2843 | zte_web_read(NV_LAST_LOGIN_TIME, last_record_time); |
| 2844 | last_record_time_num = atoi(last_record_time); |
| 2845 | if(last_record_time_num < 0 || last_record_time_num > INT_MAX-1) // kw 3 |
| 2846 | { |
| 2847 | last_record_time_num = 0; |
| 2848 | } |
| 2849 | |
| 2850 | curr_record_time_num = zte_web_getCurrentTime(); |
| 2851 | lock_time = curr_record_time_num - last_record_time_num; |
| 2852 | if (lock_time < LOGIN_FAIL_LOCK_TIME) { |
| 2853 | return -1; |
| 2854 | } else { |
| 2855 | return 1; |
| 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | void zte_reduct_login_times() |
| 2860 | { |
| 2861 | char psw_fail_num_str[12] = {0}; |
| 2862 | int login_times = 0; |
| 2863 | zte_web_read("psw_fail_num_str", psw_fail_num_str); |
| 2864 | login_times = atoi(psw_fail_num_str); |
| 2865 | if(login_times < 0 || login_times > INT_MAX-1) // kw 3 |
| 2866 | { |
| 2867 | login_times = 0; |
| 2868 | } |
| 2869 | |
| 2870 | login_times--; |
| 2871 | sprintf(psw_fail_num_str, "%d", login_times); |
| 2872 | (void)zte_web_write("psw_fail_num_str", psw_fail_num_str); |
| 2873 | } |
| 2874 | /****************************************************** |
| 2875 | * Function: void zte_password_check(webs_t wp) |
| 2876 | * Description: password check when login |
| 2877 | * Input: HTTP page info |
| 2878 | * Output: |
| 2879 | * Return: none |
| 2880 | * Others: |
| 2881 | * Modify Date Version Author Modification |
| 2882 | * |
| 2883 | *******************************************************/ |
| 2884 | psw_check_result_type_t zte_password_check(webs_t wp, char* psw) |
| 2885 | { |
| 2886 | int psw_len = 0; |
| 2887 | int psw_fail_num = 0; |
| 2888 | char psw_fail_num_str[10] = {0}; |
| 2889 | int check_lock = 0; |
| 2890 | |
| 2891 | if (NULL == psw) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2892 | slog(MISC_PRINT, SLOG_DEBUG, "mgmt_login: psw is empty."); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2893 | return PSW_EMPTY; |
| 2894 | } |
| 2895 | |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2896 | slog(MISC_PRINT, SLOG_DEBUG, "mgmt_login:psw:%s", psw); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2897 | //don't foget add the nv psw_fail_num_str |
| 2898 | zte_web_read("psw_fail_num_str", psw_fail_num_str); |
| 2899 | psw_fail_num = atoi(psw_fail_num_str); |
| 2900 | psw_len = strlen(psw); |
| 2901 | |
| 2902 | if (0 == psw_len) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2903 | slog(MISC_PRINT, SLOG_ERR, "mgmt_login: psw is empty."); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2904 | return PSW_EMPTY; |
| 2905 | } |
| 2906 | |
| 2907 | if (psw_fail_num <= 0) { |
| 2908 | check_lock = zte_checkLoginTime(); // check the current time if it is time out |
| 2909 | if (check_lock < 0) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2910 | slog(MISC_PRINT, SLOG_ERR, "mgmt_login: psw number use out."); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2911 | return PSW_TIME_OUT; |
| 2912 | // } else if (check_lock > 0) { // kw 3 |
| 2913 | }else{ |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2914 | slog(MISC_PRINT, SLOG_DEBUG, "mgmt_login: login time out, can login."); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2915 | (void)zte_web_write("psw_fail_num_str", LOGIN_FAIL_TIMES); |
| 2916 | } |
| 2917 | } |
| 2918 | zte_setLastLoginTime(); //record current time to nv |
| 2919 | if (LOGIN_PSW_MIN_LEN > psw_len || LOGIN_PSW_MAX_LEN < psw_len) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2920 | slog(MISC_PRINT, SLOG_ERR, "mgmt_login: psw is too long."); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2921 | return PSW_TOO_LONG; |
| 2922 | } else { |
| 2923 | return PSW_OK; |
| 2924 | } |
| 2925 | } |
| 2926 | |
| 2927 | void zte_get_ddns_status(webs_t wp) |
| 2928 | { |
| 2929 | char * line = NULL; |
| 2930 | size_t len = 0; |
| 2931 | int lsize = 0; //klocwork |
| 2932 | char path_conf[100] = {0}; |
| 2933 | char path_file[500] = {0}; |
| 2934 | sc_cfg_get("path_conf", path_conf, sizeof(path_conf)); |
| 2935 | sprintf(path_file, "%s/inadyn.status", path_conf); |
| 2936 | FILE *proc_file = fopen(path_file, "r"); |
| 2937 | |
| 2938 | if (proc_file == NULL) { |
| 2939 | //websWrite(wp, T("4")); |
| 2940 | websWrite(wp, T("{\"%s\":\"%s\"}"), "getddns_status", "4"); |
| 2941 | return; |
| 2942 | } |
| 2943 | if ((lsize = getline(&line, &len, proc_file)) != -1 && line) { |
| 2944 | if (strstr(line, "RC_IP_INVALID_REMOTE_ADDR")) { |
| 2945 | //websWrite(wp, T("2")); |
| 2946 | websWrite(wp, T("{\"%s\":\"%s\"}"), "getddns_status", "2"); |
| 2947 | } else if (strstr(line, "RC_DYNDNS_RSP_NOTOK")) { |
| 2948 | //websWrite(wp, T("1")); |
| 2949 | websWrite(wp, T("{\"%s\":\"%s\"}"), "getddns_status", "1"); |
| 2950 | } else if (strstr(line, "RC_OK")) { |
| 2951 | //websWrite(wp, T("0")); |
| 2952 | websWrite(wp, T("{\"%s\":\"%s\"}"), "getddns_status", "0"); |
| 2953 | } else if (strstr(line, "RC_REGISTERING")) { |
| 2954 | //websWrite(wp, T("3")); |
| 2955 | websWrite(wp, T("{\"%s\":\"%s\"}"), "getddns_status", "3"); |
| 2956 | } else { |
| 2957 | //websWrite(wp, T("5")); |
| 2958 | websWrite(wp, T("{\"%s\":\"%s\"}"), "getddns_status", "5"); |
| 2959 | } |
| 2960 | } else { |
| 2961 | //websWrite(wp, T("-1")); |
| 2962 | websWrite(wp, T("{\"%s\":\"%s\"}"), "getddns_status", "-1"); |
| 2963 | } |
| 2964 | if (line) { |
| 2965 | free(line); |
| 2966 | } |
| 2967 | fclose(proc_file); |
| 2968 | return; |
| 2969 | |
| 2970 | } |
| 2971 | |
| 2972 | void zte_goform_set_work_type(webs_t wp) |
| 2973 | { |
| 2974 | char_t *work_type = NULL; |
| 2975 | work_type = websGetVar(wp, T("work_type"), T("")); |
| 2976 | |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2977 | slog(MISC_PRINT, SLOG_DEBUG,"[zyl]goform_set_work_type:work_type->%s\n", work_type); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2978 | |
| 2979 | if (work_type == NULL) { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2980 | slog(MISC_PRINT, SLOG_ERR,"[zyl]goform_set_work_type:empty!\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2981 | zte_write_result_to_web(wp, FAILURE); |
| 2982 | return; |
| 2983 | } |
| 2984 | if ((strncmp(work_type, "0", 1) == 0) || (strncmp(work_type, "1", 1) == 0)) { |
| 2985 | char LanEnable[5] = {0}; |
| 2986 | (void)zte_web_read("LanEnable", LanEnable); |
| 2987 | if (strncmp(LanEnable, work_type, 1) == 0) { |
| 2988 | return zte_write_result_to_web(wp, SUCCESS); |
| 2989 | } |
| 2990 | (void)zte_web_write("LanEnable", work_type); |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2991 | slog(MISC_PRINT, SLOG_DEBUG,"[zyl]goform_set_work_type:work_type->%s\n", work_type); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2992 | ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_RESTART_REQUEST, 0, NULL, 0); |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2993 | slog(MISC_PRINT, SLOG_NORMAL,"[zyl]goform_set_work_type:device reboot now\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2994 | zte_write_result_to_web(wp, SUCCESS); |
| 2995 | return; |
| 2996 | } else { |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 2997 | slog(MISC_PRINT, SLOG_ERR,"[zyl]goform_set_work_type:work_type->%s error!\n", work_type); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2998 | zte_write_result_to_web(wp, FAILURE); |
| 2999 | return; |
| 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | /****************************************************** |
| 3004 | * Function: void zte_goform_set_sample(webs_t wp) |
| 3005 | * Description: example function |
| 3006 | * Input: HTTP page info |
| 3007 | * Output: |
| 3008 | * Return: none |
| 3009 | * Others: |
| 3010 | * Modify Date Version Author Modification |
| 3011 | * |
| 3012 | *******************************************************/ |
| 3013 | void zte_goform_set_sample(webs_t wp) |
| 3014 | { |
| 3015 | //´ÓWEBÇëÇóÖлñÈ¡²ÎÊý,ûÓвÎÊýÔò²»ÐèÒªÕâÒ»²½ |
| 3016 | |
| 3017 | // ÉèÖÃNV»ò·¢ÏûÏ¢¸øÏàӦģ¿é |
| 3018 | //ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_PDP_ACT_REQ, 0, NULL, 0); |
| 3019 | |
| 3020 | //·µ»ØJSON ¸ñʽ½á¹û£¬Èç¹ûÐèÒª²éѯÉèÖýá¹ûÔòÐèÒªwebuiͨ¹ý»ñÈ¡ppp_statusÕâ¸öNVÖµÀ´»ñÈ¡ |
| 3021 | zte_write_result_to_web(wp, SUCCESS); |
| 3022 | return; |
| 3023 | } |
| 3024 | |
| 3025 | //bsim |
| 3026 | static int bs_string2bytes(const char* pSrc, unsigned char* pDst, int nSrcLength) |
| 3027 | { |
| 3028 | int i=0; |
| 3029 | |
| 3030 | //УÑé²ÎÊý |
| 3031 | if(pSrc == NULL || pDst == NULL || nSrcLength < 0) |
| 3032 | { |
| 3033 | return -1; |
| 3034 | } |
| 3035 | |
| 3036 | for(i = 0; i < nSrcLength; i += 2) |
| 3037 | { |
| 3038 | // Êä³ö¸ß4λ |
| 3039 | if(*pSrc >= '0' && *pSrc <= '9') |
| 3040 | { |
| 3041 | *pDst = (*pSrc - '0') << 4; |
| 3042 | } |
| 3043 | else |
| 3044 | { |
| 3045 | *pDst = ((toupper(*pSrc) - 'A') + 10) << 4; |
| 3046 | } |
| 3047 | |
| 3048 | pSrc++; |
| 3049 | |
| 3050 | // Êä³öµÍ4λ |
| 3051 | if(*pSrc >= '0' && *pSrc <= '9') |
| 3052 | { |
| 3053 | *pDst |= *pSrc - '0'; |
| 3054 | } |
| 3055 | else |
| 3056 | { |
| 3057 | *pDst |= (toupper(*pSrc) - 'A') + 10; |
| 3058 | } |
| 3059 | |
| 3060 | pSrc++; |
| 3061 | pDst++; |
| 3062 | } |
| 3063 | |
| 3064 | // ·µ»ØÄ¿±êÊý¾Ý³¤¶È |
| 3065 | return nSrcLength / 2; |
| 3066 | } |
| 3067 | |
| 3068 | static int bs_bytes2string(const unsigned char* pSrc, char* pDst, int nSrcLength) |
| 3069 | { |
| 3070 | const char tab[]="0123456789ABCDEF"; // 0x0-0xfµÄ×Ö·û²éÕÒ±í |
| 3071 | int i = 0; |
| 3072 | |
| 3073 | //УÑé²ÎÊý |
| 3074 | if(pSrc == NULL || pDst == NULL || nSrcLength < 0) |
| 3075 | { |
| 3076 | return -1; |
| 3077 | } |
| 3078 | |
| 3079 | for(i=0; i<nSrcLength; i++) |
| 3080 | { |
| 3081 | *pDst++ = tab[*pSrc >> 4]; // Êä³öµÍ4λ |
| 3082 | *pDst++ = tab[*pSrc & 0x0f]; // Êä³ö¸ß4λ |
| 3083 | pSrc++; |
| 3084 | } |
| 3085 | |
| 3086 | // ·µ»ØÄ¿±ê×Ö·û´®³¤¶È |
| 3087 | return nSrcLength * 2; |
| 3088 | } |
| 3089 | |
| 3090 | static int bs_aes_init_key(unsigned char *aes_key, int k_len) |
| 3091 | { |
| 3092 | int efuse_fd = -1; |
| 3093 | T_ZDrvEfuse_Secure efuse = {0}; |
| 3094 | |
| 3095 | memset(&efuse, 0, sizeof(efuse)); |
| 3096 | efuse_fd = open("/dev/efuse", O_RDWR); |
| 3097 | if (efuse_fd < 0) { |
| 3098 | printf("wifi_aes_init_key efuse open errno=%d\n", errno); |
| 3099 | return 0; |
| 3100 | } |
| 3101 | if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuse) != 0) { |
| 3102 | printf("wifi_aes_init_key efuse ioctl errno=%d\n", errno); |
| 3103 | close(efuse_fd); |
| 3104 | return 0; |
| 3105 | } |
| 3106 | close(efuse_fd); |
| 3107 | memcpy(aes_key, efuse.pubKeyHash, k_len); |
| 3108 | |
| 3109 | return 1; |
| 3110 | } |
| 3111 | |
| 3112 | static int bs_aes_encrypt(char* in, int len, char* out, unsigned char* key, int key_len) |
| 3113 | { |
| 3114 | if (!in || !out || !key || len <=0 || (len%AES_BLOCK_SIZE)!=0 || (key_len!=16 && key_len!=24 && key_len!=32)) { |
| 3115 | printf("bs_aes_encrypt err in=%p out=%p key=%p len=%d key_len=%d\n",in,key,out,len,key_len); |
| 3116 | return 0; |
| 3117 | } |
| 3118 | |
| 3119 | AES_KEY aes = {0}; //cov h |
| 3120 | if (AES_set_encrypt_key(key, key_len*8, &aes) < 0) { |
| 3121 | printf("bs_aes_encrypt AES_set_encrypt_key err\n"); |
| 3122 | return 0; |
| 3123 | } |
| 3124 | |
| 3125 | int en_len = 0; |
| 3126 | while (en_len < len) { |
| 3127 | AES_encrypt((unsigned char*)in, (unsigned char*)out, &aes); |
| 3128 | in += AES_BLOCK_SIZE; |
| 3129 | out += AES_BLOCK_SIZE; |
| 3130 | en_len += AES_BLOCK_SIZE; |
| 3131 | } |
| 3132 | |
| 3133 | return 1; |
| 3134 | } |
| 3135 | |
| 3136 | static int bs_aes_decrypt(char* in, int len, char* out, char* key, int key_len) |
| 3137 | { |
| 3138 | if (!in || !out || !key || len <=0 || (len%AES_BLOCK_SIZE)!=0 || (key_len!=16 && key_len!=24 && key_len!=32)) { |
| 3139 | printf("bs_aes_decrypt err in=%p out=%p key=%p len=%d key_len=%d\n",in,key,out,len,key_len); |
| 3140 | return 0; |
| 3141 | } |
| 3142 | |
| 3143 | AES_KEY aes = {0}; //cov h |
| 3144 | if (AES_set_decrypt_key((unsigned char*)key, key_len*8, &aes) < 0) { |
| 3145 | printf("bs_aes_decrypt AES_set_decrypt_key err\n"); |
| 3146 | return 0; |
| 3147 | } |
| 3148 | |
| 3149 | int en_len = 0; |
| 3150 | while (en_len < len) { |
| 3151 | AES_decrypt((unsigned char*)in, (unsigned char*)out, &aes); |
| 3152 | in += AES_BLOCK_SIZE; |
| 3153 | out += AES_BLOCK_SIZE; |
| 3154 | en_len += AES_BLOCK_SIZE; |
| 3155 | } |
| 3156 | |
| 3157 | return 1; |
| 3158 | } |
| 3159 | |
| 3160 | static int bs_aes_cbc_encrypt(char* in, int len, char* out, unsigned char* key, int key_len) |
| 3161 | { |
| 3162 | if (!in || !out || !key || len <=0 || (len%AES_BLOCK_SIZE)!=0 || (key_len!=16 && key_len!=24 && key_len!=32)) { |
| 3163 | printf("bs_aes_encrypt err in=%p out=%p key=%p len=%d key_len=%d\n",in,key,out,len,key_len); |
| 3164 | return 0; |
| 3165 | } |
| 3166 | |
| 3167 | AES_KEY aes = {0}; //cov h |
| 3168 | if (AES_set_encrypt_key(key, key_len*8, &aes) < 0) { |
| 3169 | printf("bs_aes_encrypt AES_set_encrypt_key err\n"); |
| 3170 | return 0; |
| 3171 | } |
| 3172 | |
| 3173 | unsigned char iv[AES_BLOCK_SIZE] = {0}; |
| 3174 | memcpy(iv, key, AES_BLOCK_SIZE); |
| 3175 | |
| 3176 | AES_cbc_encrypt((unsigned char*)in, (unsigned char*)out, len, |
| 3177 | &aes, iv, AES_ENCRYPT); |
| 3178 | |
| 3179 | |
| 3180 | return 1; |
| 3181 | } |
| 3182 | |
| 3183 | static int bs_aes_cbc_decrypt(char* in, int len, char* out, char* key, int key_len) |
| 3184 | { |
| 3185 | if (!in || !out || !key || len <=0 || (len%AES_BLOCK_SIZE)!=0 || (key_len!=16 && key_len!=24 && key_len!=32)) { |
| 3186 | printf("bs_aes_decrypt err in=%p out=%p key=%p len=%d key_len=%d\n",in,key,out,len,key_len); |
| 3187 | return 0; |
| 3188 | } |
| 3189 | |
| 3190 | AES_KEY aes = {0}; //cov h |
| 3191 | if (AES_set_decrypt_key((unsigned char*)key, key_len*8, &aes) < 0) { |
| 3192 | printf("bs_aes_decrypt AES_set_decrypt_key err\n"); |
| 3193 | return 0; |
| 3194 | } |
| 3195 | |
| 3196 | unsigned char iv[AES_BLOCK_SIZE] = {0}; |
| 3197 | memcpy(iv, key, AES_BLOCK_SIZE); |
| 3198 | |
| 3199 | AES_cbc_encrypt((unsigned char*)in, (unsigned char*)out, len, |
| 3200 | &aes, iv, AES_DECRYPT); |
| 3201 | |
| 3202 | return 1; |
| 3203 | } |
| 3204 | |
| 3205 | |
| 3206 | static int apn_profile_encrypt_code(char *w_code, int len, char *b_aes, char *s_aes) |
| 3207 | { |
| 3208 | bs_aes_encrypt(w_code, len, b_aes, web_aes_key, sizeof(web_aes_key)); |
| 3209 | bs_bytes2string(b_aes, s_aes, len); |
| 3210 | |
| 3211 | printf("encrypt apn_profile w_code=%s, s_aes=%s\n", w_code, s_aes); |
| 3212 | |
| 3213 | return 1; |
| 3214 | } |
| 3215 | |
| 3216 | void set_apn_prof_aes_by_index(int index, APN_PROFILE *profile) |
| 3217 | { |
| 3218 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 3219 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 3220 | |
| 3221 | if (NULL == profile) { |
| 3222 | return; |
| 3223 | } |
| 3224 | |
| 3225 | sprintf(cfg_name, "APN_config%d", index); |
| 3226 | if (0 == strcmp(profile->pdp_type, "IPv6")) { |
| 3227 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 3228 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 3229 | profile->profile_name, |
| 3230 | "", |
| 3231 | "", |
| 3232 | "", |
| 3233 | "", |
| 3234 | "", |
| 3235 | "", |
| 3236 | "", |
| 3237 | "", |
| 3238 | "", |
| 3239 | "", |
| 3240 | "", |
| 3241 | ""); |
| 3242 | } else { |
| 3243 | char ppp_aes[PROFILE_APN_AES_LEN] = {0}; |
| 3244 | char ppp_aes_b[PROFILE_APN_LEN - 1] = {0}; |
| 3245 | apn_profile_encrypt_code(profile->ppp_passwd, PROFILE_APN_LEN - 1 , ppp_aes_b, ppp_aes); |
| 3246 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 3247 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 3248 | profile->profile_name, |
| 3249 | profile->apn_name, |
| 3250 | profile->apn_select, |
| 3251 | profile->dial_num, |
| 3252 | profile->ppp_auth_mode, |
| 3253 | profile->ppp_username, |
| 3254 | ppp_aes,//profile->ppp_passwd, |
| 3255 | profile->pdp_type, |
| 3256 | profile->pdp_select, |
| 3257 | profile->pdp_addr, |
| 3258 | profile->dns_mode, |
| 3259 | profile->prefer_dns_manual, |
| 3260 | profile->standby_dns_manual); |
| 3261 | } |
| 3262 | sc_cfg_set(cfg_name, cfg_value); |
| 3263 | |
| 3264 | return; |
| 3265 | } |
| 3266 | |
| 3267 | void set_ipv6_apn_prof_aes_by_index(int index, IPV6_APN_PROFILE *profile) |
| 3268 | { |
| 3269 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 3270 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 3271 | |
| 3272 | if (NULL == profile) { |
| 3273 | return; |
| 3274 | } |
| 3275 | |
| 3276 | sprintf(cfg_name, "ipv6_APN_config%d", index); |
| 3277 | if (0 == strcmp(profile->pdp_type, "IP")) { |
| 3278 | slog(MISC_PRINT, SLOG_DEBUG, "pdp_type=IP cpsnprintf "); /*lint !e26*/ |
| 3279 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 3280 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 3281 | profile->profile_name, |
| 3282 | "", |
| 3283 | "", |
| 3284 | "", |
| 3285 | "", |
| 3286 | "", |
| 3287 | "", |
| 3288 | "", |
| 3289 | "", |
| 3290 | "", |
| 3291 | "", |
| 3292 | "", |
| 3293 | ""); |
| 3294 | } else { |
| 3295 | char ppp_aes[PROFILE_APN_AES_LEN] = {0}; |
| 3296 | char ppp_aes_b[PROFILE_APN_LEN - 1] = {0}; |
| 3297 | apn_profile_encrypt_code(profile->ppp_passwd, PROFILE_APN_LEN - 1 , ppp_aes_b, ppp_aes); |
| 3298 | slog(MISC_PRINT, SLOG_DEBUG, "pdp_type=else cpsnprintf "); /*lint !e26*/ |
| 3299 | slog(MISC_PRINT, SLOG_DEBUG, "profile->profile_name=%s ", profile->profile_name); /*lint !e26*/ |
| 3300 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 3301 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 3302 | profile->profile_name, |
| 3303 | profile->apn_name, |
| 3304 | profile->apn_select, |
| 3305 | profile->dial_num, |
| 3306 | profile->ppp_auth_mode, |
| 3307 | profile->ppp_username, |
| 3308 | ppp_aes,//profile->ppp_passwd, |
| 3309 | profile->pdp_type, |
| 3310 | profile->pdp_select, |
| 3311 | profile->pdp_addr, |
| 3312 | profile->dns_mode, |
| 3313 | profile->prefer_dns_manual, |
| 3314 | profile->standby_dns_manual); |
| 3315 | } |
| 3316 | slog(MISC_PRINT, SLOG_DEBUG, "cfg_value=%s", cfg_value); /*lint !e26*/ |
| 3317 | sc_cfg_set(cfg_name, cfg_value); |
| 3318 | |
| 3319 | return; |
| 3320 | } |
| 3321 | |
| 3322 | void set_ipv4v6_apn_prof_aes_by_index(int index, APN_PROFILE *profile, IPV6_APN_PROFILE *ipv6profile) |
| 3323 | { |
| 3324 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 3325 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 3326 | char ppp_aes[PROFILE_APN_AES_LEN] = {0}; |
| 3327 | char ppp_aes_b[PROFILE_APN_LEN - 1] = {0}; |
| 3328 | |
| 3329 | if (NULL == profile) { |
| 3330 | return; |
| 3331 | } |
| 3332 | |
| 3333 | sprintf(cfg_name, "APN_config%d", index); |
| 3334 | apn_profile_encrypt_code(profile->ppp_passwd, PROFILE_APN_LEN - 1 , ppp_aes_b, ppp_aes); |
| 3335 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 3336 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 3337 | profile->profile_name, |
| 3338 | profile->apn_name, |
| 3339 | profile->apn_select, |
| 3340 | profile->dial_num, |
| 3341 | profile->ppp_auth_mode, |
| 3342 | profile->ppp_username, |
| 3343 | ppp_aes,//profile->ppp_passwd, |
| 3344 | profile->pdp_type, |
| 3345 | profile->pdp_select, |
| 3346 | profile->pdp_addr, |
| 3347 | profile->dns_mode, |
| 3348 | profile->prefer_dns_manual, |
| 3349 | profile->standby_dns_manual); |
| 3350 | sc_cfg_set(cfg_name, cfg_value); |
| 3351 | |
| 3352 | memset(cfg_name, 0, sizeof(cfg_name)); |
| 3353 | memset(cfg_value, 0, sizeof(cfg_value)); |
| 3354 | memset(ppp_aes, 0, sizeof(ppp_aes)); |
| 3355 | memset(ppp_aes_b, 0, sizeof(ppp_aes_b)); |
| 3356 | sprintf(cfg_name, "ipv6_APN_config%d", index); |
| 3357 | apn_profile_encrypt_code(ipv6profile->ppp_passwd, PROFILE_APN_LEN - 1 , ppp_aes_b, ppp_aes); |
| 3358 | snprintf(cfg_value, APNCONFIG_MEMORY, |
| 3359 | "%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)%s($)", |
| 3360 | ipv6profile->profile_name, |
| 3361 | ipv6profile->apn_name, |
| 3362 | ipv6profile->apn_select, |
| 3363 | ipv6profile->dial_num, |
| 3364 | ipv6profile->ppp_auth_mode, |
| 3365 | ipv6profile->ppp_username, |
| 3366 | ppp_aes,//ipv6profile->ppp_passwd, |
| 3367 | ipv6profile->pdp_type, |
| 3368 | ipv6profile->pdp_select, |
| 3369 | ipv6profile->pdp_addr, |
| 3370 | ipv6profile->dns_mode, |
| 3371 | ipv6profile->prefer_dns_manual, |
| 3372 | ipv6profile->standby_dns_manual); |
| 3373 | sc_cfg_set(cfg_name, cfg_value); |
| 3374 | |
| 3375 | return; |
| 3376 | } |
| 3377 | |
| 3378 | //APN_config0~n |
| 3379 | static void apn_decode_profile_by_index(int index) |
| 3380 | { |
| 3381 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 3382 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 3383 | char ppp_aes[PROFILE_APN_AES_LEN] = {0}; |
| 3384 | char b_aes[PROFILE_APN_LEN] = {0}; |
| 3385 | //char ppp_s[PROFILE_APN_LEN] = {0}; |
| 3386 | char *pos_begin = NULL; |
| 3387 | APN_PROFILE profile = {0}; |
| 3388 | |
| 3389 | sprintf(cfg_name, "APN_config%d", index); |
| 3390 | sc_cfg_get(cfg_name, cfg_value, sizeof(cfg_value)); |
| 3391 | if (strlen(cfg_value) == 0) |
| 3392 | return; |
| 3393 | pos_begin = cfg_value; |
| 3394 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.profile_name, PROFILE_MEMBER_LEN); |
| 3395 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.apn_name, PROFILE_APN_LEN); |
| 3396 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.apn_select, PROFILE_MEMBER_LEN); |
| 3397 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.dial_num, PROFILE_MEMBER_LEN); |
| 3398 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.ppp_auth_mode, PROFILE_MEMBER_LEN); |
| 3399 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.ppp_username, PROFILE_APN_LEN); |
| 3400 | pos_begin = split_str_by_sep(pos_begin, "($)", ppp_aes, PROFILE_APN_AES_LEN); |
| 3401 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.pdp_type, PROFILE_MEMBER_LEN); |
| 3402 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.pdp_select, PROFILE_MEMBER_LEN); |
| 3403 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.pdp_addr, PROFILE_MEMBER_LEN); |
| 3404 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.dns_mode, PROFILE_MEMBER_LEN); |
| 3405 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.prefer_dns_manual, PROFILE_MEMBER_LEN); |
| 3406 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.standby_dns_manual, PROFILE_MEMBER_LEN); |
| 3407 | |
| 3408 | if (strlen(ppp_aes) == (PROFILE_APN_AES_LEN - 1)) { |
| 3409 | bs_string2bytes(ppp_aes, b_aes, PROFILE_APN_AES_LEN - 1); |
| 3410 | bs_aes_decrypt(b_aes, PROFILE_APN_LEN - 1, profile.ppp_passwd, web_aes_key, sizeof(web_aes_key)); |
| 3411 | // printf("decrypt ppp_tmp[%d]=%s\n", index, profile.ppp_passwd); |
| 3412 | } else if (strlen(ppp_aes) > 0){ |
| 3413 | //fotaÉý¼¶À´µÄÃ÷ÎÄ |
| 3414 | strncpy(profile.ppp_passwd, ppp_aes,sizeof(profile.ppp_passwd)-1); |
| 3415 | set_apn_prof_aes_by_index(index, &profile); |
| 3416 | // printf("decrypt fota ppp_tmp[%d]=%s\n", index, profile.ppp_passwd); |
| 3417 | } |
| 3418 | |
| 3419 | set_apn_profile_by_index(index, &profile); |
| 3420 | |
| 3421 | return; |
| 3422 | } |
| 3423 | |
| 3424 | static void ipv6apn_decode_profile_by_index(int index) |
| 3425 | { |
| 3426 | char cfg_name[PROFILE_MEMBER_LEN] = {0}; |
| 3427 | char cfg_value[APNCONFIG_MEMORY] = {0}; |
| 3428 | char ppp_aes[PROFILE_APN_AES_LEN] = {0}; |
| 3429 | char b_aes[PROFILE_APN_LEN] = {0}; |
| 3430 | char *pos_begin = NULL; |
| 3431 | IPV6_APN_PROFILE profile = {0}; |
| 3432 | |
| 3433 | |
| 3434 | sprintf(cfg_name, "ipv6_APN_config%d", index); |
| 3435 | sc_cfg_get(cfg_name, cfg_value, sizeof(cfg_value)); |
| 3436 | if (strlen(cfg_value) == 0) |
| 3437 | return; |
| 3438 | pos_begin = cfg_value; |
| 3439 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.profile_name, PROFILE_MEMBER_LEN); |
| 3440 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.apn_name, PROFILE_APN_LEN); |
| 3441 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.apn_select, PROFILE_MEMBER_LEN); |
| 3442 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.dial_num, PROFILE_MEMBER_LEN); |
| 3443 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.ppp_auth_mode, PROFILE_MEMBER_LEN); |
| 3444 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.ppp_username, PROFILE_APN_LEN); |
| 3445 | pos_begin = split_str_by_sep(pos_begin, "($)", ppp_aes, PROFILE_APN_AES_LEN); |
| 3446 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.pdp_type, PROFILE_MEMBER_LEN); |
| 3447 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.pdp_select, PROFILE_MEMBER_LEN); |
| 3448 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.pdp_addr, PROFILE_MEMBER_LEN); |
| 3449 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.dns_mode, PROFILE_MEMBER_LEN); |
| 3450 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.prefer_dns_manual, PROFILE_MEMBER_LEN); |
| 3451 | pos_begin = split_str_by_sep(pos_begin, "($)", profile.standby_dns_manual, PROFILE_MEMBER_LEN); |
| 3452 | |
| 3453 | if (strlen(ppp_aes) == (PROFILE_APN_AES_LEN - 1)) { |
| 3454 | bs_string2bytes(ppp_aes, b_aes, PROFILE_APN_AES_LEN - 1); |
| 3455 | bs_aes_decrypt(b_aes, PROFILE_APN_LEN - 1, profile.ppp_passwd, web_aes_key, sizeof(web_aes_key)); |
| 3456 | // printf("decrypt ppp_v6tmp[%d]=%s\n", index, profile.ppp_passwd); |
| 3457 | } else if (strlen(ppp_aes) > 0){ |
| 3458 | //fotaÉý¼¶À´µÄÃ÷ÎÄ |
| 3459 | strncpy(profile.ppp_passwd, ppp_aes,sizeof(profile.ppp_passwd)-1); |
| 3460 | set_ipv6_apn_prof_aes_by_index(index, &profile); |
| 3461 | // printf("decrypt fota ppp_v6tmp[%d]=%s\n", index, profile.ppp_passwd); |
| 3462 | } |
| 3463 | set_ipv6_apn_profile_by_index(index, &profile); |
| 3464 | |
| 3465 | return; |
| 3466 | } |
| 3467 | |
| 3468 | static int apn_profile_decrypt_code(void) |
| 3469 | { |
| 3470 | int index = 0;//APN_config0ÊÇDefault,¿É²»´¦Àí? |
| 3471 | |
| 3472 | for (index = 0; index < APNCONFIG_NUM_MAX; index++) { |
| 3473 | apn_decode_profile_by_index(index); |
| 3474 | ipv6apn_decode_profile_by_index(index); |
| 3475 | } |
| 3476 | |
| 3477 | return 1; |
| 3478 | } |
| 3479 | |
| 3480 | int apn_encrypt_code(void) |
| 3481 | { |
| 3482 | char w_code[PROFILE_APN_LEN] = {0}; |
| 3483 | char b_aes[PROFILE_APN_LEN] = {0}; |
| 3484 | char s_aes[PROFILE_APN_AES_LEN] = {0}; |
| 3485 | |
| 3486 | sc_cfg_get("ppp_passtmp", w_code, sizeof(w_code)); |
| 3487 | bs_aes_encrypt(w_code, PROFILE_APN_LEN - 1, b_aes, web_aes_key, sizeof(web_aes_key)); |
| 3488 | bs_bytes2string(b_aes, s_aes, PROFILE_APN_LEN - 1); |
| 3489 | sc_cfg_set("ppp_passwd", s_aes); |
| 3490 | printf("apn_encrypt_code w_code=%s, s_aes=%s\n", w_code, s_aes); |
| 3491 | |
| 3492 | return 1; |
| 3493 | } |
| 3494 | |
| 3495 | int ipv6apn_encrypt_code(void) |
| 3496 | { |
| 3497 | char w_code[PROFILE_APN_LEN] = {0}; |
| 3498 | char b_aes[PROFILE_APN_LEN] = {0}; |
| 3499 | char s_aes[PROFILE_APN_AES_LEN] = {0}; |
| 3500 | |
| 3501 | sc_cfg_get("ipv6_ppp_passtmp", w_code, sizeof(w_code)); |
| 3502 | bs_aes_encrypt(w_code, PROFILE_APN_LEN - 1, b_aes, web_aes_key, sizeof(web_aes_key)); |
| 3503 | bs_bytes2string(b_aes, s_aes, PROFILE_APN_LEN - 1); |
| 3504 | sc_cfg_set("ipv6_ppp_passwd", s_aes); |
| 3505 | printf("ipv6apn_encrypt_code w_code=%s, s_aes=%s\n", w_code, s_aes); |
| 3506 | |
| 3507 | return 1; |
| 3508 | } |
| 3509 | #if 0 |
| 3510 | //2±íʾfota´ÓÀϰ汾ÍùÉÏÉý¼¶£¬ppp_password´æµÄÊÇÃ÷ÎÄÃÜÂ룬а汾ÊÇÃÜÎÄ |
| 3511 | static int apn_decrypt_code(void) |
| 3512 | { |
| 3513 | char w_code[PROFILE_APN_LEN]= {0}; |
| 3514 | char b_aes[PROFILE_APN_LEN] = {0}; |
| 3515 | char s_aes[PROFILE_APN_AES_LEN] = {0}; |
| 3516 | int flag = 0; |
| 3517 | |
| 3518 | sc_cfg_get("ppp_passwd", s_aes, sizeof(s_aes)); |
| 3519 | if (strlen(s_aes) == (PROFILE_APN_AES_LEN - 1)) { |
| 3520 | bs_string2bytes(s_aes, b_aes, PROFILE_APN_AES_LEN - 1); |
| 3521 | bs_aes_decrypt(b_aes, PROFILE_APN_LEN - 1, w_code, web_aes_key, sizeof(web_aes_key)); |
| 3522 | sc_cfg_set("ppp_passtmp", w_code); |
| 3523 | printf("apn_decrypt_code w_code=%s, s_aes=%s\n", w_code, s_aes); |
| 3524 | } else if (strlen(s_aes) > 0){ |
| 3525 | sc_cfg_set("ppp_passtmp", s_aes); |
| 3526 | return 2; |
| 3527 | } |
| 3528 | |
| 3529 | return 1; |
| 3530 | } |
| 3531 | |
| 3532 | static int ipv6apn_decrypt_code(void) |
| 3533 | { |
| 3534 | char w_code[PROFILE_APN_LEN]= {0}; |
| 3535 | char b_aes[PROFILE_APN_LEN] = {0}; |
| 3536 | char s_aes[PROFILE_APN_AES_LEN] = {0}; |
| 3537 | int flag = 0; |
| 3538 | |
| 3539 | sc_cfg_get("ipv6_ppp_passwd", s_aes, sizeof(s_aes)); |
| 3540 | if (strlen(s_aes) == (PROFILE_APN_AES_LEN - 1)) { |
| 3541 | bs_string2bytes(s_aes, b_aes, PROFILE_APN_AES_LEN - 1); |
| 3542 | bs_aes_decrypt(b_aes, PROFILE_APN_LEN - 1, w_code, web_aes_key, sizeof(web_aes_key)); |
| 3543 | sc_cfg_set("ipv6_ppp_passtmp", w_code); |
| 3544 | printf("apn_decrypt_code w_code=%s, s_aes=%s\n", w_code, s_aes); |
| 3545 | } else if (strlen(s_aes) > 0){ |
| 3546 | sc_cfg_set("ipv6_ppp_passtmp", s_aes); |
| 3547 | return 2; |
| 3548 | } |
| 3549 | |
| 3550 | return 1; |
| 3551 | } |
| 3552 | #endif |
| 3553 | #ifdef WEBS_SECURITY |
| 3554 | static void js_aes_wifi_encode(void) |
| 3555 | { |
| 3556 | char js_aes_key[24 + 1]={0}; |
| 3557 | char imei_buf[15 + 1] = {0}; |
| 3558 | char rnum_buf[9 + 1] = {0}; |
| 3559 | |
| 3560 | char wificode[WIFI_PSW_DEFAULT_LENGTH] = {0}; |
| 3561 | char b_aes[WIFI_PSW_DEFAULT_LENGTH] = {0}; |
| 3562 | char *basestr = NULL; |
| 3563 | |
| 3564 | sc_cfg_get("imei", imei_buf, sizeof(imei_buf)); |
| 3565 | sc_cfg_get("rnum_js", rnum_buf, sizeof(rnum_buf)); |
| 3566 | snprintf(js_aes_key, sizeof(js_aes_key), "%s%sFFFFFFFFFFFFFFF", rnum_buf, imei_buf); |
| 3567 | |
| 3568 | sc_cfg_get("WPAPSK1", wificode, sizeof(wificode)); |
| 3569 | bs_aes_cbc_encrypt(wificode, sizeof(wificode)-1, b_aes, js_aes_key, sizeof(js_aes_key)-1); |
| 3570 | basestr = zte_base64_encode(b_aes, sizeof(b_aes)-1); |
| 3571 | if (NULL == basestr) { |
| 3572 | slog(MISC_PRINT, SLOG_ERR, "basestr is NULL.\n");/*lint !e26*/ |
| 3573 | return; |
| 3574 | } |
| 3575 | (void)zte_web_write("WPAPSK1_enaes", basestr); |
| 3576 | free(basestr); |
| 3577 | basestr = NULL; |
| 3578 | |
| 3579 | memset(wificode, 0, sizeof(wificode)); |
| 3580 | sc_cfg_get("m_WPAPSK1", wificode, sizeof(wificode)); |
| 3581 | bs_aes_cbc_encrypt(wificode, sizeof(wificode)-1, b_aes, js_aes_key, sizeof(js_aes_key)-1); |
| 3582 | basestr = zte_base64_encode(b_aes, sizeof(b_aes)-1); |
| 3583 | if (NULL == basestr) { |
| 3584 | slog(MISC_PRINT, SLOG_ERR, "basestr-m is NULL.\n");/*lint !e26*/ |
| 3585 | return; |
| 3586 | } |
| 3587 | (void)zte_web_write("m_WPAPSK1_enaes", basestr); |
| 3588 | free(basestr); |
| 3589 | basestr = NULL; |
| 3590 | |
| 3591 | } |
| 3592 | |
| 3593 | |
| 3594 | static void js_aes_rand(void) |
| 3595 | { |
| 3596 | char rstr[10] = {0}; |
| 3597 | unsigned int rnum = 0; |
| 3598 | |
| 3599 | srand( (unsigned)time( NULL ) ); |
| 3600 | rnum = rand(); |
| 3601 | rnum %= 1000000000; |
| 3602 | |
| 3603 | snprintf((char *)rstr, sizeof(rstr), "%09ld", rnum); |
| 3604 | sc_cfg_set("rnum_js", rstr); |
| 3605 | } |
| 3606 | //cbc |
| 3607 | char *js_aes_decode(char *src, size_t len, size_t *out_len) |
| 3608 | { |
| 3609 | unsigned char *aes_password = NULL; |
| 3610 | size_t aes_len = 0; |
| 3611 | |
| 3612 | char *out = NULL; |
| 3613 | |
| 3614 | char js_aes_key[24 + 1]={0}; |
| 3615 | char imei_buf[15 + 1] = {0}; |
| 3616 | char rnum_buf[9 + 1] = {0}; |
| 3617 | |
| 3618 | aes_password = (char *)zte_base64_decode((const unsigned char *)src, len, (unsigned int*)&aes_len); |
| 3619 | if (aes_password == NULL) |
| 3620 | return NULL; |
| 3621 | |
| 3622 | |
| 3623 | out = malloc(aes_len + 1); |
| 3624 | if (out == NULL) { |
| 3625 | free(aes_password); |
| 3626 | return NULL; |
| 3627 | } |
| 3628 | memset(out, 0, aes_len + 1); |
| 3629 | |
| 3630 | sc_cfg_get("imei", imei_buf, sizeof(imei_buf)); |
| 3631 | sc_cfg_get("rnum_js", rnum_buf, sizeof(rnum_buf)); |
| 3632 | snprintf(js_aes_key, sizeof(js_aes_key), "%s%sFFFFFFFFFFFFFFF", rnum_buf, imei_buf); |
| 3633 | |
| 3634 | bs_aes_cbc_decrypt(aes_password, aes_len, out, js_aes_key, sizeof(js_aes_key)-1); |
| 3635 | //printf("decrypt js_aes_decode[%d]=%s\n", aes_len, out); |
| 3636 | |
| 3637 | free(aes_password); |
| 3638 | |
| 3639 | if (strlen(out) > aes_len) { |
| 3640 | free(out); |
| 3641 | return NULL; |
| 3642 | } |
| 3643 | |
| 3644 | *out_len = strlen(out); |
| 3645 | |
| 3646 | return out; |
| 3647 | } |
| 3648 | #endif |
| 3649 | int web_aes_init(void) |
| 3650 | { |
| 3651 | bs_aes_init_key(web_aes_key, sizeof(web_aes_key)); |
| 3652 | apn_profile_decrypt_code(); |
| 3653 | #ifdef WEBS_SECURITY |
| 3654 | js_aes_rand(); |
| 3655 | #endif |
| 3656 | return 1; |
| 3657 | } |
| 3658 | |