static int Password_GetConfig(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { int ret = 0, lid = -1, i = 0; UINT32 priority = 100; RG_AUTH_T authCfg; char username[RG_USER_MAX][DEF_AUTH_INFO_LEN] = {{0}, {0}, {0}}; memset(&authCfg, 0, sizeof(RG_AUTH_T)); if (GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, RG_MSG_CFG_AUTH_GET, VOS_MSG_PRI_NORMAL, &authCfg, sizeof(RG_AUTH_T), &authCfg, sizeof(RG_AUTH_T), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "send RG_MSG_CFG_AUTH_GET message fail"); return ret; } lid = GetLoginIndex(r); WEB_LOG(LOG_LEVEL_NORMAL, "GetLoginIndex:%d, State:%d", lid, g_login_data[lid].login_state); memset(username, 0, sizeof(username)); if(-1 != lid) { if(WEB_LOGIN_USER == g_login_data[lid].login_state) priority = 2; else if(WEB_LOGIN_SUPERUSER == g_login_data[lid].login_state) priority = 1; else if(WEB_LOGIN_BACKGROUND == g_login_data[lid].login_state) priority = 0; for (i = 0; i < RG_USER_MAX; i++) { if (authCfg.user[i].enable && (priority == authCfg.user[i].priority)) { memcpy(username[0], authCfg.user[i].username, DEF_AUTH_INFO_LEN - 1); ret += ngx_webs_write(r, b, T("old_password = \"%s\";\n"), authCfg.user[i].passwd); ret += ngx_webs_write(r, b, T("user_pri = %d;\n"), authCfg.user[i].priority); } if ((WEB_LOGIN_BACKGROUND == g_login_data[lid].login_state) && authCfg.user[i].enable && (1 == authCfg.user[i].priority)) { memcpy(username[1], authCfg.user[i].username, DEF_AUTH_INFO_LEN - 1); } } } ret += ngx_webs_write(r, b, T("username = [\"%s\", \"%s\"];\n"), username[0], username[1]); ret += ngx_webs_write(r, b, T("isillegalPasswd = %d\n"), isillegalPasswd); isillegalPasswd = -1; return ret; }
int web_GetQosMappingProfile(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { int ret = 0; AP_WEB_MAP_PROFILE_T rateCfg; AP_WIFI_MAP_PROFILE_T *pCfg; UINT32 i = 0; memset(&rateCfg, 0, sizeof(rateCfg)); rateCfg.profile_param.get_type = PROFILE_GET_ALL_SPEC; if ( GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, AP_MSG_GET_PROFILE_QOSMAP_CFG, VOS_MSG_PRI_NORMAL, &rateCfg, sizeof(rateCfg), &rateCfg, sizeof(rateCfg), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "get qos mapping config fail"); return ret; } ret += ngx_webs_write(r, b, T("qosmap_list = [\n")); for (i = 0; i < rateCfg.profile_param.profile_num; i++) { pCfg = &rateCfg.web_map_profile[i]; if (i > 0) { ret += ngx_webs_write(r, b, T(",\n")); } ret += ngx_webs_write(r, b, T("\t{\n")); ret += ngx_webs_write(r, b, T("\t\"index\": %d,\n"), pCfg->map_profile.profile_id); ret += ngx_webs_write(r, b, T("\t\"name\": \"%s\"\n"), pCfg->map_profile.profile_name); ret += ngx_webs_write(r, b, T("\t}")); } ret += ngx_webs_write(r, b, T("\n];\n")); return ret; }
int web_GetFilterIdProfile(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { int ret = 0; UMM_FILTER_ID_PROFILE_T filteridCfg; UMM_WIFI_FILTER_ID_PROFILE_T *pCfg; UINT32 i = 0; memset(&filteridCfg, 0, sizeof(filteridCfg)); filteridCfg.profile_param.get_type = PROFILE_GET_ALL_SPEC; if ( GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, UMM_MSG_CFG_PROFILE_FILTERID_GET, VOS_MSG_PRI_NORMAL, &filteridCfg, sizeof(filteridCfg), &filteridCfg, sizeof(filteridCfg), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "get filter id config 0x%x fail", UMM_MSG_CFG_PROFILE_FILTERID_GET); return ret; } ret += ngx_webs_write(r, b, T("qosfilterid_list = [\n")); for (i = 0; i < filteridCfg.profile_param.profile_num; i++) { pCfg = &filteridCfg.filter_id_profile[i]; if (i > 0) { ret += ngx_webs_write(r, b, T(",\n")); } ret += ngx_webs_write(r, b, T("\t{\n")); ret += ngx_webs_write(r, b, T("\t\"index\": %d,\n"), pCfg->filterId_profile.profile_id); ret += ngx_webs_write(r, b, T("\t\"name\": \"%s\"\n"), pCfg->filterId_profile.profile_name); ret += ngx_webs_write(r, b, T("\t}")); } ret += ngx_webs_write(r, b, T("\n];\n")); return ret; }
// constructor (takes json data) tweet::tweet(const char *json_data) { Json::Value root; Json::Reader reader; if(json_data == NULL || !reader.parse(json_data, root)) { ERROR_LOG << "failed to decode tweet JSON!\n" << reader.getFormattedErrorMessages() << json_data << "\n\n"; return; } else { if(root["warning"].get("code", "").asString() == "FALLING_BEHIND") { ERROR_LOG << "lagging behind twitter (" << root["warning"].get("percent_full", 0).asInt() << ")\n"; WEB_LOG("Uh-oh", "Looks like the application is having a hard time keeping up with all the tweets.", "warning"); m_id = -1; } else { m_id = root.get("id", 0).asInt64(); m_text = filter(root.get("text", "").asString()); m_sentiment = 0; // is this json straight from twitter? (ie does it have the created_at field?) if(root.get("created_at", "").asString().length() > 0) { m_lang = root["user"].get("lang", "").asString(); m_followers = root["user"].get("followers_count", 0).asInt(); m_retweets = root.get("retweet_count", 0).asInt(); m_is_retweet = !root["retweeted_status"].empty(); if(m_is_retweet) { m_original_id = root["retweeted_status"].get("id", 0).asInt64(); } else { m_original_id = 0; } } else // internal json { m_lang = root.get("language", "").asString(); m_followers = root.get("followers", 0).asInt(); m_retweets = root.get("retweets", 0).asInt(); m_weight = root.get("weight", 0).asInt(); m_conservative = root.get("conservative", 0).asDouble(); m_liberal = root.get("liberal", 0).asDouble(); m_is_retweet = root.get("is_retweet", false).asBool(); m_original_id = root.get("original_id", 0).asInt64(); } } } }
static int Remote_GetConfig(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { int ret = 0, i = 0, count = 0; RG_MANAGE_REMOTE_WEB_T remote; char ip[16] = "", mask[16] = ""; char buf[192] = {0}; memset(&remote,0,sizeof(RG_MANAGE_REMOTE_WEB_T)); if(GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, RG_MSG_CFG_REMOTE_WEB_GET, VOS_MSG_PRI_NORMAL, &remote, sizeof(RG_MANAGE_REMOTE_WEB_T), &remote, sizeof(RG_MANAGE_REMOTE_WEB_T), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "Remote get syc message fail\r\n"); return 0; } ret += ngx_webs_write(r, b, T("remote_enable = %d;\n"), remote.enable); if(remote.protocol == 0) ret += ngx_webs_write(r, b, T("wanindex = %d;\n"), (remote.wanIndex&0xFFFF)/2); else ret += ngx_webs_write(r, b, T("wanindex = %d;\n"), ((remote.wanIndex>>16)&0xFFFF)/2); ret += ngx_webs_write(r, b, T("protocol = %d;\n"), remote.protocol); ret += ngx_webs_write(r, b, T("portid = %d;\n"), remote.port); ret += ngx_webs_write(r, b, T("username = \"%s\";\n"),web_translate_value(remote.userName, buf, DEF_AUTH_INFO_LEN)); ret += ngx_webs_write(r, b, T("password = \"%s\";\n"), WEB_PASSWORD_MASK); for(i = 0; i < 32; i++) { if(0 != remote.allowDevice[i].remoteIp) count++; } WEB_LOG(LOG_LEVEL_NORMAL, "Remote ip count is %d", count); for(i = 0; i < count; i++) { VOS_Host2Str(remote.allowDevice[i].remoteIp, ip); VOS_Host2Str(remote.allowDevice[i].remoteMask, mask); ret += ngx_webs_write(r, b, "iplist[%d] = {\n", i); ret += ngx_webs_write(r, b, "\"ip\":\"%s\",\"mask\":\"%s\"\n }\n", ip, mask); } return ret; }
static int qosfilterid_write(ngx_http_request_t *r, ngx_buf_t *b, UMM_WIFI_FILTER_ID_PROFILE_T *pCfg) { int ret = 0; UINT32 j = 0; WEB_LOG(LOG_LEVEL_NORMAL, "qosfilterid_write start num[%d]...", pCfg->ItemNum); if(pCfg->ItemNum>MAX_FILTERID_RULE) { WEB_LOG(LOG_LEVEL_NORMAL, "qosfilterid_write start num[%d]...", pCfg->ItemNum); return -1; } ret += ngx_webs_write(r, b, T("{\n")); ret += ngx_webs_write(r, b, T("\t\"profile_id\": %d,\n"), pCfg->filterId_profile.profile_id); ret += ngx_webs_write(r, b, T("\t\"profile_name\": \"%s\",\n"), pCfg->filterId_profile.profile_name); ret += ngx_webs_write(r, b, T("\t\"profile_ref_mask\": %d,\n"), pCfg->profile_ref_mask); ret += ngx_webs_write(r, b, T("\t\"item_num\": %d,\n"), pCfg->ItemNum); ret += ngx_webs_write(r, b, T("\t\"filteridrule_list\": [\n")); for (j = 0; j < pCfg->ItemNum; j++) { WEB_LOG(LOG_LEVEL_NORMAL, "qosfilterid_write filteridrule_list index[%d]...", j); if (j > 0) { ret += ngx_webs_write(r, b, T(",\n")); } ret += ngx_webs_write(r, b, T("\t\t{\n")); ret += ngx_webs_write(r, b, T("\t\t\"filterid_value\": \"%s\",\n"), pCfg->filterId_rule[j].filterId); ret += ngx_webs_write(r, b, T("\t\t\"filterid_vlan\": \"%d\",\n"), pCfg->filterId_rule[j].vlanId); ret += ngx_webs_write(r, b, T("\t\t\"filterid_in_type\": %d,\n"), pCfg->filterId_rule[j].IngressRateType); ret += ngx_webs_write(r, b, T("\t\t\"filterid_in_rate\": %u,\n"), pCfg->filterId_rule[j].IngressRate/ 1000); ret += ngx_webs_write(r, b, T("\t\t\"filterid_out_type\": %d,\n"), pCfg->filterId_rule[j].EgressRateType); ret += ngx_webs_write(r, b, T("\t\t\"filterid_out_rate\": %u\n"), pCfg->filterId_rule[j].EgressRate/ 1000); ret += ngx_webs_write(r, b, T("\t\t}")); } ret += ngx_webs_write(r, b, T("\n\t]\n")); ret += ngx_webs_write(r, b, T("\t}")); WEB_LOG(LOG_LEVEL_NORMAL, "qosfilterid_write stop"); return ret; }
static int NTP_GetConfig(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { int ret = 0; RG_NTP_CFG_T ntpcfg; FILE *fp = NULL; char cur_time[32] = {0}, tmp[128] = {0}; char *ptr; memset(&ntpcfg, 0, sizeof(RG_NTP_CFG_T)); if(GOS_OK != VOS_SendSyncMsg(PON_APPLID_MEC, RG_MSG_CFG_NTP_GET, VOS_MSG_PRI_NORMAL, &ntpcfg, sizeof(RG_NTP_CFG_T), &ntpcfg, sizeof(RG_NTP_CFG_T), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "LAN send syc message fail"); return ret; } ret += ngx_webs_write(r, b, T("ntp_enable=%d;\n"), ntpcfg.enable); ret += ngx_webs_write(r, b, T("time_Zone=%d;\n"), ntpcfg.timeZone); ret += ngx_webs_write(r, b, T("ntpwanIndex=%d;\n"), ntpcfg.wanIndex); ret += ngx_webs_write(r, b, T("syncInterval=%d;\n"), ntpcfg.syncInterval); ret += ngx_webs_write(r, b, T("server1=\"%s\";\n"), web_translate_value(ntpcfg.server1, tmp, sizeof(ntpcfg.server1))); ret += ngx_webs_write(r, b, T("server2=\"%s\";\n"), web_translate_value(ntpcfg.server2, tmp, sizeof(ntpcfg.server1))); ret += ngx_webs_write(r, b, T("server3=\"%s\";\n"), web_translate_value(ntpcfg.server3, tmp, sizeof(ntpcfg.server1))); ret += ngx_webs_write(r, b, T("server4=\"%s\";\n"), web_translate_value(ntpcfg.server4, tmp, sizeof(ntpcfg.server1))); system("date > /tmp/curtime"); if(NULL != (fp = fopen("/tmp/curtime", "r+"))) { if(fgets(cur_time, sizeof(cur_time) - 1, fp)) { if(NULL != (ptr = strchr(cur_time, '\r'))) *ptr = 0; if(NULL != (ptr = strchr(cur_time, '\n'))) *ptr = 0; ret += ngx_webs_write(r, b, T("cur_time=\"%s\";\n"), cur_time); } fclose(fp); unlink("/tmp/curtime"); } return ret; }
static int qosmap_Form(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { char *page = NULL, *pData = NULL; AP_WEB_MAP_PROFILE_T mapCfg; AP_WIFI_MAP_PROFILE_T *pCfg; GOS_ERROR_CODE ret; CHAR buf[32]; int i = 0, j = 0; memset(&mapCfg, 0, sizeof(mapCfg)); pCfg = &mapCfg.web_map_profile[0]; page = ngx_asp_get_var(r, T("XWebPageName"), T("qos_mapping")); pData = ngx_asp_get_var(r, T("qosmap_action"), T("")); mapCfg.profile_param.set_type = atoi(pData); pData = ngx_asp_get_var(r, T("qosmap_index"), T("")); pCfg->map_profile.profile_id = atoi(pData); WEB_LOG(LOG_LEVEL_NORMAL, "set qos mapping, act=%d, idx=%d", mapCfg.profile_param.set_type, pCfg->map_profile.profile_id); pData = ngx_asp_get_var(r, T("profile_name"), T("")); strncpy(pCfg->map_profile.profile_name, pData, PROFILE_NAME_LEN_MAX); pData = ngx_asp_get_var(r, T("w2l_type"), T("")); pCfg->map_spec.w2l_type = atoi(pData); for (i = 0; i < 4; i++) { if (PBIT == pCfg->map_spec.w2l_type) { sprintf(buf, "w2l_pbit%d", i); } else { sprintf(buf, "w2l_dscp%d", i); } pData = ngx_asp_get_var(r, buf, T("")); pCfg->map_spec.w2l_map[i] = atoi(pData); } pData = ngx_asp_get_var(r, T("l2w_type"), T("")); pCfg->map_spec.l2w_type = atoi(pData); for (i = 0; i < 8; i++) { sprintf(buf, "l2w_wmm%d", i); pData = ngx_asp_get_var(r, buf, T("")); if (PBIT == pCfg->map_spec.l2w_type) { pCfg->map_spec.l2w_map[i] = atoi(pData); } else { for (j = 0; j < 8; j++) { pCfg->map_spec.l2w_map[(i<<3)+j] = atoi(pData); } } } if (GOS_OK != VOS_SendSyncMsg(PON_APPLID_MEC, AP_MSG_SET_PROFILE_QOSMAP_CFG, VOS_MSG_PRI_NORMAL, &mapCfg, sizeof(mapCfg), &ret, sizeof(ret), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "qos mapping send set syc message fail"); } FormDone(r, b, page); return 0; }
int qos_GetConfig(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { int ret=0; RG_QOS_IPV4_CFG_T qosCfg; int i=0; char buf[64]; memset(&qosCfg, 0, sizeof(qosCfg)); if ( GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, RG_MSG_CFG_QOS_IPV4_GET, VOS_MSG_PRI_NORMAL, &qosCfg, sizeof(qosCfg), &qosCfg, sizeof(qosCfg), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "qos get qos config fail\r\n"); //we need queue number even fail, because custom can need view it. ret += ngx_webs_write(r, b, T("queue_num = %d;\r\n"), RG_QOS_QUEUE_NUM); return ret; } //enable ret+=ngx_webs_write(r, b, T("enable=%d;\r\n"),qosCfg.enable); //us_rate ret+=ngx_webs_write(r, b, T("usrate=%d;\r\n"),qosCfg.us_rate); //count ret+=ngx_webs_write(r, b, T("count=%d;\r\n"),qosCfg.count); //rules[RG_QOS_RULE_MAX]; ret+=ngx_webs_write(r, b, T("rules_max=%d;\r\n"), RG_QOS_RULE_MAX); ret += ngx_webs_write(r, b, T("rules = new Array();\r\n")); for(i=0; i<qosCfg.count; i++) { ret += ngx_webs_write(r, b, T("rules[%d] = {\r\n"), i); //clsType //ret += ngx_webs_write(r, b, T("clsType:%d,\r\n"), qosCfg.rules[i].clsType); //cls ret += ngx_webs_write(r, b, T("cls_proto:%d,\r\n"), qosCfg.rules[i].cls.proto); ret += ngx_webs_write(r, b, T("cls_srcIp:\"%s\",\r\n"), VOS_Host2Str(qosCfg.rules[i].cls.srcIp, buf)); ret += ngx_webs_write(r, b, T("cls_srcMask:\"%s\",\r\n"), VOS_Host2Str(qosCfg.rules[i].cls.srcMask, buf)); ret += ngx_webs_write(r, b, T("cls_dstIp:\"%s\",\r\n"), VOS_Host2Str(qosCfg.rules[i].cls.dstIp, buf)); ret += ngx_webs_write(r, b, T("cls_dstMask:\"%s\",\r\n"), VOS_Host2Str(qosCfg.rules[i].cls.dstMask, buf)); ret += ngx_webs_write(r, b, T("cls_srcPort:%d,\r\n"), qosCfg.rules[i].cls.srcPort); ret += ngx_webs_write(r, b, T("cls_srcPortMax:%d,\r\n"), qosCfg.rules[i].cls.srcPortMax); ret += ngx_webs_write(r, b, T("cls_dstPort:%d,\r\n"), qosCfg.rules[i].cls.dstPort); ret += ngx_webs_write(r, b, T("cls_dstPortMax:%d,\r\n"), qosCfg.rules[i].cls.dstPortMax); //dscp; ret += ngx_webs_write(r, b, T("cls_dscp:%d,\r\n"), qosCfg.rules[i].cls.dscp); //pbit; ret += ngx_webs_write(r, b, T("cls_pbit:%d,\r\n"), qosCfg.rules[i].cls.pbit); //action //order; //ret += ngx_webs_write(r, b, T("action_order:%d,\r\n"), qosCfg.rules[i].action.order, buf); //queue; ret += ngx_webs_write(r, b, T("action_queue:%d,\r\n"), qosCfg.rules[i].action.queue); //dscp; ret += ngx_webs_write(r, b, T("action_dscp:%d,\r\n"), qosCfg.rules[i].action.dscp); //pbit; ret += ngx_webs_write(r, b, T("action_pbit:%d\r\n"), qosCfg.rules[i].action.pbit); ret += ngx_webs_write(r, b, T("};\r\n")); } ret += ngx_webs_write(r, b, T("\r\n")); //queue[RG_QOS_QUEUE_NUM]; ret += ngx_webs_write(r, b, T("queue_num = %d;\r\n"), RG_QOS_QUEUE_NUM); for(i=0; i<RG_QOS_QUEUE_NUM; i++) { ret += ngx_webs_write(r, b, T("queue[%d] = {\r\n"), i); //priority; // priority of this queue: 0 - 7 ret += ngx_webs_write(r, b, T("queue_priority:%d,\r\n"), qosCfg.queue[i].priority); //weight; // weight of this queue: 1 - 63 ret += ngx_webs_write(r, b, T("queue_weight:%d,\r\n"), qosCfg.queue[i].weight); //rate; // shaping of this queue: 64 kbps ret += ngx_webs_write(r, b, T("queue_rate:%d,\r\n"), qosCfg.queue[i].rate); //enable; ret += ngx_webs_write(r, b, T("queue_enable:%d,\r\n"), qosCfg.queue[i].enable); //mode; ret += ngx_webs_write(r, b, T("queue_mode:%d\r\n"), qosCfg.queue[i].mode); ret += ngx_webs_write(r, b, T("};\r\n")); } return ret; }
int qosmap_GetConfig(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { int ret = 0; AP_WEB_MAP_PROFILE_T mapCfg; AP_WIFI_MAP_PROFILE_T *pCfg; INT32 unused_idx = -1; INT32 i = 0; memset(&mapCfg, 0, sizeof(mapCfg)); mapCfg.profile_param.get_type = PROFILE_GET_ALL_SPEC; if ( GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, AP_MSG_GET_PROFILE_QOSMAP_CFG, VOS_MSG_PRI_NORMAL, &mapCfg, sizeof(mapCfg), &mapCfg, sizeof(mapCfg), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "get qos mapping config fail"); return ret; } ret += ngx_webs_write(r, b, T("qosmap_list = [\n\t")); for (i = 0; i < (INT32)mapCfg.profile_param.profile_num; i++) { pCfg = &mapCfg.web_map_profile[i]; if (unused_idx < 0 && (INT32)pCfg->map_profile.profile_id != i) { unused_idx = i; } if (i > 0) { ret += ngx_webs_write(r, b, T(",\n\t")); } ret += qosmap_write(r, b, pCfg); } ret += ngx_webs_write(r, b, T("\n];\n")); if (unused_idx < 0) { unused_idx = (INT32)mapCfg.profile_param.profile_num; if (unused_idx >= PROFILE_NUM_MAX) { return ret; } } WEB_LOG(LOG_LEVEL_NORMAL, "get unused qos mapping, idx = %d", unused_idx); memset(&mapCfg, 0, sizeof(mapCfg)); mapCfg.profile_param.get_type = PROFILE_GET_ONE_SPEC; pCfg = &mapCfg.web_map_profile[0]; pCfg->map_profile.profile_id = unused_idx; pCfg->map_spec.get_default = 1; if ( GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, AP_MSG_GET_PROFILE_QOSMAP_CFG, VOS_MSG_PRI_NORMAL, &mapCfg, sizeof(mapCfg), &mapCfg, sizeof(mapCfg), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "get qos mapping config fail"); return ret; } ret += ngx_webs_write(r, b, T("unused_qosmap = ")); ret += qosmap_write(r, b, pCfg); ret += ngx_webs_write(r, b, T(";\n")); return ret; }
static int qos_XForm(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { char *page = NULL; RG_QOS_IPV4_CFG_T qosCfg0; RG_QOS_IPV4_CFG_T qosCfg1; BOOL isChanged = FALSE; GOS_ERROR_CODE ret; char * pbuf = NULL; char var_str[64]; int i=0, j=0; UINT32 qos_op=0; memset(&qosCfg0, 0, sizeof(qosCfg0)); memset(&qosCfg1, 0, sizeof(qosCfg1)); page = ngx_asp_get_var(r, T("XWebPageName"), T("qos")); if(NULL == page) { WEB_LOG(LOG_LEVEL_NORMAL, "Qos invalid request!"); return 0; } if(GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, RG_MSG_CFG_QOS_IPV4_GET, VOS_MSG_PRI_NORMAL, &qosCfg0, sizeof(qosCfg0), &qosCfg0, sizeof(qosCfg0), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "QOS Form send Get syc message fail"); FormDone(r, b, page); return 0; } //from qos.html //rules pbuf = ngx_asp_get_var(r, T("qos_op"), NULL); if(pbuf != NULL) { qos_op = atoi(pbuf); } //qos enable if(qos_op == 0) { //enable qosCfg1.enable = (BOOL)atoi(ngx_asp_get_var(r, T("qos_en"), NULL)); if(qosCfg0.enable != qosCfg1.enable) { qosCfg0.enable = qosCfg1.enable; isChanged = TRUE; } } //add rule if(qos_op == 1) { //first get rule index pbuf = ngx_asp_get_var(r, T("rule_index"), NULL); if(pbuf != NULL) { //here i is rule array index i = atoi(pbuf)-1; } //check valid if(qosCfg0.count+1 <= RG_QOS_RULE_MAX && i >= 0) { if(i >= qosCfg0.count) { i=qosCfg0.count; } } else { FormDone(r, b, page); return 0; } //RG_QOS_IPV4_RULE_T //clsType qosCfg1.rules[i].clsType = RG_QOS_CLS_5TUPLE; //cls //enable, always true in web, this is for tr069 qosCfg1.rules[i].cls.enable = TRUE; //proto pbuf = ngx_asp_get_var(r, T("cls_proto"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].cls.proto = atoi(pbuf); } //srcIp pbuf = ngx_asp_get_var(r, T("cls_srcIp"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].cls.srcIp = VOS_Str2Host(pbuf); } //srcMask pbuf = ngx_asp_get_var(r, T("cls_srcMask"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].cls.srcMask = VOS_Str2Host(pbuf); } //srcPort pbuf = ngx_asp_get_var(r, T("cls_srcPort"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].cls.srcPort = atoi(pbuf); } //srcPortMax; pbuf = ngx_asp_get_var(r, T("cls_srcPortMax"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].cls.srcPortMax = atoi(pbuf); } //dstIp pbuf = ngx_asp_get_var(r, T("cls_dstIp"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].cls.dstIp = VOS_Str2Host(pbuf); } //dstMask pbuf = ngx_asp_get_var(r, T("cls_dstMask"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].cls.dstMask = VOS_Str2Host(pbuf); } //dstPort pbuf = ngx_asp_get_var(r, T("cls_dstPort"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].cls.dstPort = atoi(pbuf); } //dstPortMax; pbuf = ngx_asp_get_var(r, T("cls_dstPortMax"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].cls.dstPortMax = atoi(pbuf); } //pbit //need to be design //dscp //need to be design //RG_QOS_IPV4_ACTION_T action //UINT32 order; //unused yet //int pbit; pbuf = ngx_asp_get_var(r, T("action_pbit"), NULL); if(pbuf == NULL) { qosCfg1.rules[i].action.pbit = -1; //disable } else { pbuf = ngx_asp_get_var(r, T("action_pbitVal"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].action.pbit = atoi(pbuf); } } //int dscp; pbuf = ngx_asp_get_var(r, T("action_dscp"), NULL); if(pbuf == NULL) { qosCfg1.rules[i].action.dscp = -1; //disable } else { pbuf = ngx_asp_get_var(r, T("action_dscpVal"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].action.dscp = atoi(pbuf); } } //UINT32 queue; pbuf = ngx_asp_get_var(r, T("action_queue"), NULL); if(pbuf != NULL) { qosCfg1.rules[i].action.queue = atoi(pbuf); } //do add rule //move behands back qosCfg0.count++; for(j=qosCfg0.count-1; j>i; j--) { qosCfg0.rules[j] = qosCfg0.rules[j-1]; } memcpy(&qosCfg0.rules[i], &qosCfg1.rules[i], sizeof(RG_QOS_IPV4_RULE_T)); isChanged = TRUE; } //del rule if(qos_op == 2) { pbuf = ngx_asp_get_var(r, T("rule_index"), NULL); if(pbuf != NULL) { //here i is rule array index i = atoi(pbuf)-1; } //del rule if(qosCfg0.count > 0 && i < qosCfg0.count && i >= 0) { //move behands forward for(j=i+1; j<qosCfg0.count; j++) { qosCfg0.rules[j-1] = qosCfg0.rules[j]; } qosCfg0.count--; isChanged = TRUE; } else { FormDone(r, b, page); return 0; } } //from qos_queue.html //config queue if(qos_op == 3) { for(i=0; i<RG_QOS_QUEUE_NUM; i++) { //enable sprintf(var_str, "queue%d_%s", i+1, "enable"); pbuf = ngx_asp_get_var(r, T(var_str), NULL); if(pbuf != NULL) { qosCfg1.queue[i].enable = TRUE; } else { qosCfg1.queue[i].enable = FALSE; } //mode sprintf(var_str, "queue%d_%s", i+1, "mode"); pbuf = ngx_asp_get_var(r, T(var_str), NULL); if(pbuf != NULL) { switch(atoi(pbuf)) { case 0: qosCfg1.queue[i].mode = RG_QOS_QUEUE_PRIO; break; case 1: qosCfg1.queue[i].mode = RG_QOS_QUEUE_WRR; break; case 2: qosCfg1.queue[i].mode = RG_QOS_QUEUE_PRIO_WRR; break; case 3: qosCfg1.queue[i].mode = RG_QOS_QUEUE_CAR; break; default: qosCfg1.queue[i].mode = RG_QOS_QUEUE_PRIO; break; } } //priority sprintf(var_str, "queue%d_%s", i+1, "priority"); pbuf = ngx_asp_get_var(r, T(var_str), NULL); if(pbuf != NULL) { qosCfg1.queue[i].priority = atoi(pbuf); } //weight sprintf(var_str, "queue%d_%s", i+1, "weight"); pbuf = ngx_asp_get_var(r, T(var_str), NULL); if(pbuf != NULL) { qosCfg1.queue[i].weight = atoi(pbuf); } //rate sprintf(var_str, "queue%d_%s", i+1, "rate"); pbuf = ngx_asp_get_var(r, T(var_str), NULL); if(pbuf != NULL) { qosCfg1.queue[i].rate = atoi(pbuf); } //check if changed. if(memcmp(&qosCfg0.queue[i], &qosCfg1.queue[i], sizeof(qosCfg0.queue[i])) != 0) { memcpy(&qosCfg0.queue[i], &qosCfg1.queue[i], sizeof(qosCfg0.queue[i])); isChanged = TRUE; } } } //check if changed if(isChanged) { if(GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, RG_MSG_CFG_QOS_IPV4_SET, VOS_MSG_PRI_NORMAL, &qosCfg0, sizeof(qosCfg0), &ret, sizeof(ret), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "QOS send SET syc message fail\r\n"); } if(GOS_OK != ret) { WEB_LOG(LOG_LEVEL_NORMAL, "QOS set mib data failed.\r\n"); } } FormDone(r, b, page); return 0; }
static int NTP_Form(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { char *page = NULL; char *webvalue = NULL; RG_NTP_CFG_T ntpcfg; GOS_ERROR_CODE setAck; int changed = 0, ret = 0; page = ngx_asp_get_var(r, T("XWebPageName"), T("ntp")); memset(&ntpcfg, 0, sizeof(RG_NTP_CFG_T)); if(GOS_OK != VOS_SendSyncMsg(PON_APPLID_MEC, RG_MSG_CFG_NTP_GET, VOS_MSG_PRI_NORMAL, &ntpcfg, sizeof(RG_NTP_CFG_T), &ntpcfg, sizeof(RG_NTP_CFG_T), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "LAN send syc message fail"); return ret; } webvalue = ngx_asp_get_var(r, T("ntp_enable"), T("")); if(webvalue) { if(ntpcfg.enable != (BOOL)atoi(webvalue)) { ntpcfg.enable = (BOOL)atoi(webvalue); changed = 1; } } webvalue = ngx_asp_get_var(r, T("ntpwanIndex"), T("")); if(webvalue) { if(ntpcfg.wanIndex != atoi(webvalue)) { ntpcfg.wanIndex = atoi(webvalue); changed = 1; } } //server1 webvalue = ngx_asp_get_var(r, T("ntp_server1"), T("")); if(strcmp(ntpcfg.server1, webvalue)) { if(!strcmp(webvalue, "Other")) { webvalue = ngx_asp_get_var(r, T("new_server1"), T("")); } strcpy(ntpcfg.server1, webvalue); if (!strcmp(ntpcfg.server1, "None")) { ntpcfg.server1[0] = 0; } changed = 1; } //server2 webvalue = ngx_asp_get_var(r, T("ntp_server2"), T("")); if(strcmp(ntpcfg.server2, webvalue)) { if(!strcmp(webvalue, "Other")) { webvalue = ngx_asp_get_var(r, T("new_server2"), T("")); } strcpy(ntpcfg.server2, webvalue); if (!strcmp(ntpcfg.server2, "None")) { ntpcfg.server2[0] = 0; } changed = 1; } //server3 webvalue = ngx_asp_get_var(r, T("ntp_server3"), T("")); if(strcmp(ntpcfg.server3, webvalue)) { if(!strcmp(webvalue, "Other")) { webvalue = ngx_asp_get_var(r, T("new_server3"), T("")); } strcpy(ntpcfg.server3, webvalue); if (!strcmp(ntpcfg.server3, "None")) { ntpcfg.server3[0] = 0; } changed = 1; } //server4 webvalue = ngx_asp_get_var(r, T("ntp_server4"), T("")); if(strcmp(ntpcfg.server4, webvalue)) { if(!strcmp(webvalue, "Other")) { webvalue = ngx_asp_get_var(r, T("new_server4"), T("")); } strcpy(ntpcfg.server4, webvalue); if (!strcmp(ntpcfg.server4, "None")) { ntpcfg.server4[0] = 0; } changed = 1; } webvalue = ngx_asp_get_var(r, T("time_Zone"), T("")); if(ntpcfg.timeZone != atoi(webvalue)) { ntpcfg.timeZone = atoi(webvalue); changed = 1; } webvalue = ngx_asp_get_var(r, T("syncInterval"), T("")); if(ntpcfg.syncInterval != atoi(webvalue)) { ntpcfg.syncInterval = atoi(webvalue); changed = 1; } WEB_LOG(LOG_LEVEL_NORMAL, "server1:%s, server2:%s, timezone:%d, changed is %d\n", ntpcfg.server1, ntpcfg.server2, ntpcfg.timeZone, changed); if( 1 == changed) { if(GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, RG_MSG_CFG_NTP_SET, VOS_MSG_PRI_NORMAL, &ntpcfg, sizeof(RG_NTP_CFG_T), &setAck, sizeof(GOS_ERROR_CODE), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "ntp send syc message fail"); } } FormDone(r, b, page); return 0; }
/*============================================================================== * - T_web_server_start() * * - http server task */ void T_web_server_start () { int sockfd; // Socket file descriptor int nsockfd; // New Socket file descriptor int num; socklen_t sin_size; // to store struct size char revbuf[LENGTH]; struct sockaddr_in addr_local; struct sockaddr_in addr_remote; /* Get the Socket file descriptor */ if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1 ) { serial_printf ("ERROR: Cannot obtain Socket Despcritor.\n"); return ; } else { WEB_LOG ("OK: Obtain Socket Despcritor sucessfully.\n"); } /* Fill the local socket address struct */ addr_local.sin_family = AF_INET; // Protocol Family addr_local.sin_port = htons(PORT); // Port number addr_local.sin_addr.s_addr = INADDR_ANY; // AutoFill local address memset(&(addr_local.sin_zero), 0, 8); // Flush the rest of struct /* Blind a special Port */ if( bind(sockfd, (struct sockaddr*)&addr_local, sizeof(struct sockaddr)) == -1 ) { serial_printf ("ERROR: Cannot bind Port %d\n.",PORT); return ; } else { WEB_LOG ("OK: Bind the Port %d sucessfully.\n",PORT); } /* Listen remote connect/calling */ if(listen(sockfd,BACKLOG) == -1) { serial_printf ("ERROR: Cannot listen Port %d\n.", PORT); return ; } else { WEB_LOG ("OK: Listening the Port %d sucessfully.\n", PORT); } while(1) { sin_size = sizeof(struct sockaddr_in); /* Wait a connection, and obtain a new socket file despriptor for single connection */ if ((nsockfd = accept(sockfd, (struct sockaddr *)&addr_remote, &sin_size)) == -1) { serial_printf ("ERROR: Obtain new Socket Despcritor error\n"); continue; } else { WEB_LOG ("OK: Server has got connect from %s\n", inet_ntoa(addr_remote.sin_addr)); } num = recv(nsockfd, revbuf, LENGTH, 0); revbuf[num] = '\0'; WEB_LOG (revbuf); /* Child process */ // if(!fork()) { WEB_LOG ("OK: Http web is servering.\n"); if(revbuf[5]==' ') { send(nsockfd, reply, sizeof(reply), 0); send(nsockfd, html, sizeof(html), 0); } else if(revbuf[5]=='1') { send(nsockfd, httpgif, sizeof(httpgif), 0); send(nsockfd, bmp, sizeof(bmp), 0); } else { char file_name[PATH_LEN_MAX] = {WEB_PATH}; char file_context[1024]; char send_context[2048]; int i = 5; int fd; int read_byte; int send_byte; #if 0 int f_len, h_len = strlen(HOME_HTML); #endif while (!isspace(revbuf[i++])) ; revbuf[--i] = '\0'; strncat (file_name, revbuf + 5, PATH_LEN_MAX - strlen(file_name) - 1); file_name[PATH_LEN_MAX - 1] = '\0'; #if 0 f_len = strlen (file_name); if ((f_len > h_len) && (strcmp (file_name + f_len - h_len, HOME_HTML) == 0)) { strcpy (file_name, WEB_PATH HOME_HTML); } #endif fd = yaffs_open(file_name, O_RDONLY, 0); if ( fd == -1) { serial_printf("ERROR: Cannot open file %s", file_name); } if ( (strcmp (strchr (file_name, '.'), ".html") == 0) || /* *.html */ (strcmp (strchr (file_name, '.'), ".jpg") == 0)) { /* *.jpg */ read_byte = yaffs_read(fd, file_context, 1024); while (read_byte > 0) { send(nsockfd, file_context, read_byte, 0); read_byte = yaffs_read(fd, file_context, 1024); } } else { /* !.html */ send(nsockfd, html_start, sizeof(html_start), 0); read_byte = yaffs_read(fd, file_context+1, 1023); file_context[0] = '|'; read_byte++; while (read_byte > 1) { send_byte = 0; for (i = 0; i < read_byte; i++) { if (file_context[i] == '\n') { send_context[send_byte++] = '<'; send_context[send_byte++] = 'B'; send_context[send_byte++] = 'R'; send_context[send_byte++] = '>'; send_context[send_byte++] = '|'; } else if (file_context[i] == '<'){ send_context[send_byte++] = '&'; send_context[send_byte++] = 'l'; send_context[send_byte++] = 't'; } else if (file_context[i] == '&'){ send_context[send_byte++] = '&'; send_context[send_byte++] = 'a'; send_context[send_byte++] = 'm'; send_context[send_byte++] = 'p'; } else if (file_context[i] == '"'){ send_context[send_byte++] = '&'; send_context[send_byte++] = 'q'; send_context[send_byte++] = 'u'; send_context[send_byte++] = 'o'; send_context[send_byte++] = 't'; }else { send_context[send_byte++] = file_context[i]; } } send(nsockfd, send_context, send_byte, 0); read_byte = yaffs_read(fd, file_context, 1024); } send(nsockfd, html_end, sizeof(html_end), 0); } /* !*.html */ yaffs_close(fd); } } close(nsockfd); // while(waitpid(-1, NULL, WNOHANG) > 0); } }
static int Remote_XForm(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { GOS_ERROR_CODE ret = 0; char *page = NULL, *value = NULL; BOOL enabled = FALSE, changed = 0; RG_MANAGE_REMOTE_WEB_T remote; int i = 0, n = 0, index = 0; char buf[512] = {0}; char *mainvar[32], *subvar[3]; memset(&remote,0,sizeof(RG_MANAGE_REMOTE_WEB_T)); page = ngx_asp_get_var(r, T("XWebPageName"), T("rmtweb")); if(NULL == page) { WEB_LOG(LOG_LEVEL_NORMAL, "Invalid request!"); return 0; } if(GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, RG_MSG_CFG_REMOTE_WEB_GET, VOS_MSG_PRI_NORMAL, &remote, sizeof(RG_MANAGE_REMOTE_WEB_T), &remote, sizeof(RG_MANAGE_REMOTE_WEB_T), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "remote GET syc message fail\r\n"); return 0; } value = ngx_asp_get_var(r, T("rmt_state"), NULL); if (value) { enabled = (BOOL)atoi(value); if (remote.enable != enabled) { changed = 1; remote.enable = enabled; } } value = ngx_asp_get_var(r, T("wan_list"), NULL); if (value) { if (remote.wanIndex != atoi(value)) { changed = 1; remote.wanIndex = atoi(value); index = remote.wanIndex; } } value = ngx_asp_get_var(r, T("username"), NULL); if (value) { if (strcmp(remote.userName, value)) { changed = 1; memset(remote.userName, 0, sizeof(remote.userName) - 1); memcpy(remote.userName, value, sizeof(remote.userName) - 1); } } value = ngx_asp_get_var(r, T("password1"), NULL); if (value) { if (strcmp(WEB_PASSWORD_MASK, value)) { changed = 1; memset(remote.passwd, 0, sizeof(remote.passwd) - 1); memcpy(remote.passwd, value, sizeof(remote.passwd) - 1); } } value = ngx_asp_get_var(r, T("protocol_list"), NULL); if (value) { if (remote.protocol != atoi(value)) { changed = 1; remote.protocol = atoi(value); if(remote.protocol == 0) remote.wanIndex = ID_2_MASK(index) & 0xFFFF; else remote.wanIndex = ID_2_MASK(index+16) & 0xFFFF0000; } } value = ngx_asp_get_var(r, T("port"), NULL); if (value) { if (remote.port != atoi(value)) { changed = 1; remote.port = atoi(value); } } value = ngx_asp_get_var(r, T("iplist_value"), NULL); if(value) { sprintf(buf, "%s", value); WEB_LOG(LOG_LEVEL_NORMAL, "Remote ip list value is %s", buf); n = str_split(buf, "~", mainvar, 32); WEB_LOG(LOG_LEVEL_NORMAL, "Remote ip list count is %d", n); for(i = 0; i < 32; i++) { memset(&remote.allowDevice[i], 0, sizeof(RG_DEVICE_LIST_T) - 1); } for (i = 0; i < n; i++) { int m; UINT32 ip = 0; m = str_split(mainvar[i], "|", subvar, 2); if(2 != m ) { WEB_LOG(LOG_LEVEL_NORMAL, "GET multi_addrpool table value fail"); goto quit; } ip = VOS_Str2Host(subvar[0]); if(ip != remote.allowDevice[i].remoteIp) { remote.allowDevice[i].remoteIp = ip; changed = 1; } ip = VOS_Str2Host(subvar[1]); if(ip != remote.allowDevice[i].remoteMask) { remote.allowDevice[i].remoteMask = ip; changed = 1; } } } else { if(0 != remote.allowDevice[0].remoteIp) { for(i = 0; i < 32; i++) { memset(&remote.allowDevice[i], 0, sizeof(RG_DEVICE_LIST_T) - 1); } changed = 1; } } WEB_LOG(LOG_LEVEL_NORMAL, "Set remote enable:%d,wanindex:%d,username:%s,password:%s,protocol:%d,port:%d", remote.enable, remote.wanIndex, remote .userName, remote.passwd,remote.protocol,remote.port); if(changed == 1) { if(GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, RG_MSG_CFG_REMOTE_WEB_SET, VOS_MSG_PRI_NORMAL, &remote,sizeof(RG_MANAGE_REMOTE_WEB_T), &ret, sizeof(GOS_ERROR_CODE), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "Send syc message to set remote fail\r\n"); return 0; } if(GOS_OK != ret) { WEB_LOG(LOG_LEVEL_NORMAL, "Set remote mib data failed.\r\n"); return 0; } } quit: FormDone(r, b, page); return 0; }
int qosfilterid_GetConfig(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { int ret = 0; UMM_FILTER_ID_PROFILE_T filterIdCfg; UMM_WIFI_FILTER_ID_PROFILE_T *pCfg; INT32 add_idx = -1; INT32 i = 0; memset(&filterIdCfg, 0, sizeof(filterIdCfg)); filterIdCfg.profile_param.get_type = PROFILE_GET_ALL_SPEC; if ( GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, UMM_MSG_CFG_PROFILE_FILTERID_GET, VOS_MSG_PRI_NORMAL, &filterIdCfg, sizeof(filterIdCfg), &filterIdCfg, sizeof(filterIdCfg), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "get filter id config fail"); return ret; } WEB_LOG(LOG_LEVEL_NORMAL, "get filter id config success"); ret += ngx_webs_write(r, b, T("qosfilterid_list = [\n\t")); for (i = 0; i < (INT32)filterIdCfg.profile_param.profile_num; i++) { WEB_LOG(LOG_LEVEL_NORMAL, "get filter id[%d]", i); pCfg = &filterIdCfg.filter_id_profile[i]; if (add_idx < 0 && (INT32)pCfg->filterId_profile.profile_id != i) { add_idx = i; } if (i > 0) { ret += ngx_webs_write(r, b, T(",\n\t")); } ret += qosfilterid_write(r, b, pCfg); } ret += ngx_webs_write(r, b, T("\n];\n")); if (add_idx < 0) { add_idx = (INT32)filterIdCfg.profile_param.profile_num; if (add_idx >= PROFILE_NUM_MAX) { return ret; } } WEB_LOG(LOG_LEVEL_NORMAL, "get unused filter id, idx = %d", add_idx); memset(&filterIdCfg, 0, sizeof(filterIdCfg)); filterIdCfg.profile_param.get_type = PROFILE_GET_ONE_SPEC; pCfg = &filterIdCfg.filter_id_profile[0]; pCfg->filterId_profile.profile_id = add_idx; pCfg->get_default = 1; if ( GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, UMM_MSG_CFG_PROFILE_FILTERID_GET, VOS_MSG_PRI_NORMAL, &filterIdCfg, sizeof(filterIdCfg), &filterIdCfg, sizeof(filterIdCfg), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "get filter id config fail"); return ret; } ret += ngx_webs_write(r, b, T("add_qosfilterid = ")); ret += qosfilterid_write(r, b, pCfg); ret += ngx_webs_write(r, b, T(";\n")); return ret; }
int qosrate_GetConfig(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { int ret = 0; AP_WEB_RATELIMIT_PROFILE_T rateCfg; AP_WIFI_RATELIMIT_PROFILE_T *pCfg; INT32 add_idx = -1; INT32 i = 0; memset(&rateCfg, 0, sizeof(rateCfg)); rateCfg.profile_param.get_type = PROFILE_GET_ALL_SPEC; if ( GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, AP_MSG_GET_PROFILE_RATELIMIT_CFG, VOS_MSG_PRI_NORMAL, &rateCfg, sizeof(rateCfg), &rateCfg, sizeof(rateCfg), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "get rate limit config fail"); return ret; } ret += ngx_webs_write(r, b, T("qosrate_list = [\n\t")); for (i = 0; i < (INT32)rateCfg.profile_param.profile_num; i++) { pCfg = &rateCfg.web_ratelimit_profile[i]; if (add_idx < 0 && (INT32)pCfg->ratelimit_profile.profile_id != i) { add_idx = i; } if (i > 0) { ret += ngx_webs_write(r, b, T(",\n\t")); } ret += qosrate_write(r, b, pCfg); } ret += ngx_webs_write(r, b, T("\n];\n")); if (add_idx < 0) { add_idx = (INT32)rateCfg.profile_param.profile_num; if (add_idx >= PROFILE_NUM_MAX) { return ret; } } WEB_LOG(LOG_LEVEL_NORMAL, "get unused qos rate, idx = %d", add_idx); memset(&rateCfg, 0, sizeof(rateCfg)); rateCfg.profile_param.get_type = PROFILE_GET_ONE_SPEC; pCfg = &rateCfg.web_ratelimit_profile[0]; pCfg->ratelimit_profile.profile_id = add_idx; pCfg->ratelimit_spec.get_default = 1; if ( GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, AP_MSG_GET_PROFILE_RATELIMIT_CFG, VOS_MSG_PRI_NORMAL, &rateCfg, sizeof(rateCfg), &rateCfg, sizeof(rateCfg), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "get rate limit config fail"); return ret; } ret += ngx_webs_write(r, b, T("add_qosrate = ")); ret += qosrate_write(r, b, pCfg); ret += ngx_webs_write(r, b, T(";\n")); return ret; }
static int qosrate_Form(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { char *page = NULL, *pData = NULL; AP_WEB_RATELIMIT_PROFILE_T rateCfg; AP_WIFI_RATELIMIT_PROFILE_T *pCfg; GOS_ERROR_CODE ret; CHAR buf[32]; int i = 0; memset(&rateCfg, 0, sizeof(rateCfg)); pCfg = &rateCfg.web_ratelimit_profile[0]; page = ngx_asp_get_var(r, T("XWebPageName"), T("qos_rate")); pData = ngx_asp_get_var(r, T("qosrate_action"), T("")); rateCfg.profile_param.set_type = atoi(pData); pData = ngx_asp_get_var(r, T("qosrate_index"), T("")); pCfg->ratelimit_profile.profile_id = atoi(pData); WEB_LOG(LOG_LEVEL_NORMAL, "set qos rate limit, act=%d, idx=%d", rateCfg.profile_param.set_type, pCfg->ratelimit_profile.profile_id); pData = ngx_asp_get_var(r, T("profile_name"), T("")); strncpy(pCfg->ratelimit_profile.profile_name, pData, PROFILE_NAME_LEN_MAX); pData = ngx_asp_get_var(r, T("ssid_in_type"), T("")); pCfg->ratelimit_spec.incoming_type = atoi(pData); pData = ngx_asp_get_var(r, T("ssid_in_rate"), T("")); pCfg->ratelimit_spec.incoming_rate = atoi(pData) * 1000; pData = ngx_asp_get_var(r, T("ssid_out_type"), T("")); pCfg->ratelimit_spec.outgoing_type = atoi(pData); pData = ngx_asp_get_var(r, T("ssid_out_rate"), T("")); pCfg->ratelimit_spec.outgoing_rate = atoi(pData) * 1000; for (i = 0; i < RATELIMIT_STA_NUM_PERVAP; i++) { sprintf(buf, "sta%d_mac", i); pData = ngx_asp_get_var(r, buf, T("")); if (!strcmp(pData, "")) { break; } mac_strtoint(pData, pCfg->ratelimit_spec.sta_qos_list[i].sta_mac); sprintf(buf, "sta%d_in_type", i); pData = ngx_asp_get_var(r, buf, T("")); pCfg->ratelimit_spec.sta_qos_list[i].incoming_type = atoi(pData); sprintf(buf, "sta%d_in_rate", i); pData = ngx_asp_get_var(r, buf, T("")); pCfg->ratelimit_spec.sta_qos_list[i].incoming_rate = atoi(pData) * 1000; sprintf(buf, "sta%d_out_type", i); pData = ngx_asp_get_var(r, buf, T("")); pCfg->ratelimit_spec.sta_qos_list[i].outgoing_type = atoi(pData); sprintf(buf, "sta%d_out_rate", i); pData = ngx_asp_get_var(r, buf, T("")); pCfg->ratelimit_spec.sta_qos_list[i].outgoing_rate = atoi(pData) * 1000; pCfg->ratelimit_spec.sta_num++; } if (GOS_OK != VOS_SendSyncMsg(PON_APPLID_MEC, AP_MSG_SET_PROFILE_RATELIMIT_CFG, VOS_MSG_PRI_NORMAL, &rateCfg, sizeof(rateCfg), &ret, sizeof(ret), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "qos rate limit send set syc message fail"); } FormDone(r, b, page); return 0; }
static int qosfilterid_Form(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { char *page = NULL, *pData = NULL; UMM_FILTER_ID_PROFILE_T filteridCfg; UMM_WIFI_FILTER_ID_PROFILE_T *pCfg; GOS_ERROR_CODE ret; CHAR buf[32]; int i = 0; memset(&filteridCfg, 0, sizeof(filteridCfg)); pCfg = &filteridCfg.filter_id_profile[0]; page = ngx_asp_get_var(r, T("XWebPageName"), T("qos_filterid")); pData = ngx_asp_get_var(r, T("qosfilterid_action"), T("")); if (!strcmp(pData, "")) { WEB_LOG(LOG_LEVEL_NORMAL, "can't get qosfilterid_action"); return -1; } filteridCfg.profile_param.set_type = atoi(pData); pData = ngx_asp_get_var(r, T("qosfilterid_index"), T("")); if (!strcmp(pData, "")) { WEB_LOG(LOG_LEVEL_NORMAL, "can't get qosfilterid_index"); return -1; } pCfg->filterId_profile.profile_id = atoi(pData); WEB_LOG(LOG_LEVEL_NORMAL, "set qos filter id, act=%d, idx=%d", filteridCfg.profile_param.set_type, pCfg->filterId_profile.profile_id); pData = ngx_asp_get_var(r, T("profile_name"), T("")); if (!strcmp(pData, "")) { WEB_LOG(LOG_LEVEL_NORMAL, "use default profile_name 'groupid%d'", pCfg->filterId_profile.profile_id); sprintf(pCfg->filterId_profile.profile_name, "groupid%d", pCfg->filterId_profile.profile_id); } else { strncpy(pCfg->filterId_profile.profile_name, pData, PROFILE_NAME_LEN_MAX); } for (i = 0; i < RATELIMIT_STA_NUM_PERVAP; i++) { sprintf(buf, "filterid%d_value", i); pData = ngx_asp_get_var(r, buf, T("")); if (!strcmp(pData, "")) { WEB_LOG(LOG_LEVEL_NORMAL, "can't get filter rule[%d]",i); break; } strncpy(pCfg->filterId_rule[i].filterId, pData, PROFILE_NAME_LEN_MAX); WEB_LOG(LOG_LEVEL_NORMAL, "qos filter rule[%d] groupidvalue=%s",i, pCfg->filterId_rule[i].filterId); sprintf(buf, "filterid%d_vlan", i); pData = ngx_asp_get_var(r, buf, T("")); pCfg->filterId_rule[i].vlanId = atoi(pData); WEB_LOG(LOG_LEVEL_NORMAL, "qos filter rule[%d] vlanid=%d",i, pCfg->filterId_rule[i].vlanId); sprintf(buf, "filterid%d_in_type", i); pData = ngx_asp_get_var(r, buf, T("")); pCfg->filterId_rule[i].IngressRateType= atoi(pData); WEB_LOG(LOG_LEVEL_NORMAL, "qos filter rule[%d] IngressRateType=%d",i, pCfg->filterId_rule[i].IngressRateType); sprintf(buf, "filterid%d_in_rate", i); pData = ngx_asp_get_var(r, buf, T("")); pCfg->filterId_rule[i].IngressRate= atoi(pData) * 1000; WEB_LOG(LOG_LEVEL_NORMAL, "qos filter rule[%d] IngressRate=%d",i, pCfg->filterId_rule[i].IngressRate); sprintf(buf, "filterid%d_out_type", i); pData = ngx_asp_get_var(r, buf, T("")); pCfg->filterId_rule[i].EgressRateType= atoi(pData); WEB_LOG(LOG_LEVEL_NORMAL, "qos filter rule[%d] EgressRateType=%d",i, pCfg->filterId_rule[i].EgressRateType); sprintf(buf, "filterid%d_out_rate", i); pData = ngx_asp_get_var(r, buf, T("")); pCfg->filterId_rule[i].EgressRate= atoi(pData) * 1000; WEB_LOG(LOG_LEVEL_NORMAL, "qos filter rule[%d] EgressRate=%d",i, pCfg->filterId_rule[i].EgressRate); pCfg->ItemNum++; } WEB_LOG(LOG_LEVEL_NORMAL, "qos filter ItemNum[%d] ",i, pCfg->ItemNum); pCfg->inUse = TRUE; if (GOS_OK != VOS_SendSyncMsg(PON_APPLID_MEC, UMM_MSG_CFG_PROFILE_FILTERID_SET, VOS_MSG_PRI_NORMAL, &filteridCfg, sizeof(filteridCfg), &ret, sizeof(ret), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "qos filter id send set syc message fail"); } FormDone(r, b, page); return 0; }
static int Password_XForm(ngx_http_request_t *r, ngx_buf_t *b, int argc, char **argv) { GOS_ERROR_CODE ret = 0, i = 0; char *page = NULL, *value = NULL, *pass0 = NULL, *pass1 = NULL, *pass2 = NULL; RG_AUTH_T authCfg; char username[DEF_AUTH_INFO_LEN] = {0}; BOOL legalUser = FALSE; BOOL legalPass = FALSE; memset(&authCfg, 0, sizeof(RG_AUTH_T)); isillegalPasswd = 1; page = ngx_asp_get_var(r, T("XWebPageName"), T("password")); if(NULL == page) { WEB_LOG(LOG_LEVEL_NORMAL, "Invalid request for password.html!"); return 0; } memset(&authCfg, 0, sizeof(RG_AUTH_T)); if (GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, RG_MSG_CFG_AUTH_GET, VOS_MSG_PRI_NORMAL, &authCfg, sizeof(RG_AUTH_T), &authCfg, sizeof(RG_AUTH_T), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "send RG_MSG_CFG_AUTH_GET message fail"); return ret; } value = ngx_asp_get_var(r, T("username"), NULL); if (value && strcmp(value, "")) { strncpy(username, value, sizeof(username) - 1); for (i = 0; i < RG_USER_MAX; i++) { if (!strcmp(username, authCfg.user[i].username)) { pass0 = ngx_asp_get_var(r, T("password0"), NULL); if (pass0 && strcmp(pass0, "") && !strcmp(pass0, authCfg.user[i].passwd)) { legalUser = TRUE; break; } } } } if (FALSE == legalUser) { WEB_LOG(LOG_LEVEL_NORMAL, "password web configuration illegal"); FormDone(r, b, page); return 0; } else { pass1 = ngx_asp_get_var(r, T("password1"), NULL); pass2 = ngx_asp_get_var(r, T("password2"), NULL); if (pass1 && strcmp(pass1, "") && pass2 && strcmp(pass2, "") && !strcmp(pass1, pass2)) { if (FALSE == islegalPassword(authCfg.user[i].priority, authCfg.user[i].username, pass1)) { legalPass = FALSE; } else { legalPass = TRUE; memset(authCfg.user[i].passwd, 0, sizeof(authCfg.user[i].passwd) - 1); memcpy(authCfg.user[i].passwd, pass1, sizeof(authCfg.user[i].passwd) - 1); } } else { legalPass = FALSE; } } if (FALSE == legalPass) { WEB_LOG(LOG_LEVEL_NORMAL, "password web configuration illegal"); FormDone(r, b, page); return 0; } if(GOS_OK != VOS_SendSyncMsg(PON_APPLID_RTC, RG_MSG_CFG_AUTH_SET, VOS_MSG_PRI_NORMAL, &authCfg, sizeof(RG_AUTH_T), &ret, sizeof(GOS_ERROR_CODE), 2000)) { WEB_LOG(LOG_LEVEL_NORMAL, "Send syc message to set password fail\r\n"); return 0; } else { UINT32 cip; int lid; char ipbuf[32] = ""; lid = GetLoginIndex(r); cip = webs_get_client_ip(r); VOS_Net2Str(cip, ipbuf); VOS_E8C_Log(LOG_E8C_INFO_6, "[User] %s at %s change password successfully!", g_login_data[lid].username, ipbuf); } if(GOS_OK != ret) { WEB_LOG(LOG_LEVEL_NORMAL, "Set password mib data failed.\r\n"); return 0; } isillegalPasswd = 0; page = "login";//jump to login page after set password sucessful FormDone(r, b, page); return 0; }