blob: 804c65b54d28efa4d83bbf383cae308e70081de0 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001#include <stdio.h>
2#include <stdlib.h>
3#include <sys/ioctl.h>
4#include <arpa/inet.h>
5#include <net/if.h>
6#include <net/route.h>
7#include <string.h>
8#include <dirent.h>
9
10#include "zte_mainctrl.h"
11
12extern void str_vary_dit(char * str, char *result);
13#if 0
14/*
15 * substitution of getNthValue which dosen't destroy the original value
16 */
17static int static_getNthValueSafe(int index, char *value, char delimit, char *result, int len)
18{
19 int i = 0, result_len = 0;
20 char *begin, *end;
21
22 if (!value || !result || !len)
23 return -1;
24
25 begin = value;
26 end = strchr(begin, delimit);
27
28 while (i < index && end) {
29 begin = end + 1;
30 end = strchr(begin, delimit);
31 i++;
32 }
33
34 //no delimit
35 if (!end) {
36 if (i == index) {
37 end = begin + strlen(begin);
38 result_len = (len - 1) < (end - begin) ? (len - 1) : (end - begin);
39 } else
40 return -1;
41 } else
42 result_len = (len - 1) < (end - begin) ? (len - 1) : (end - begin);
43
44 memcpy(result, begin, result_len);
45 *(result + result_len) = '\0';
46
47 return 0;
48}
49
50/*change the value of the Nth macip list */
51/*the macip list format is:
52 [mac1]+[ip1];[mac2]+[ip2];....*/
53/*add by lyf 2012/5/21*/
54static int changeNthValue(int index, char *value, char delimit, char *result, char *web_list)
55{
56 int i = 0;
57 int front_len = 0;
58 int end_len = 0;
59 int edit_len = 0;
60 int total_len = 0;
61
62 char *begin, *end;
63 char tempchar[NV_MACIP_LIST_MAX_LEN] = {0};
64
65 if (!value || !result || !web_list)
66 return -1;
67
68 begin = value;
69 end = strchr(begin, delimit);
70
71 while (i < index && end) {
72 begin = end + 1;
73 end = strchr(begin, delimit);
74 i++;
75 }
76
77 //no delimit
78 if (!end) {
79 if (i == index) {
80 end = begin + strlen(begin) - 1;
81 front_len = begin - value;
82 strncpy(tempchar, value, front_len);
83 strncpy(tempchar + front_len, web_list, (strlen(web_list)));
84 total_len = front_len + strlen(web_list);
85 } else {
86 return -1;
87 }
88 } else {
89 front_len = begin - value;
90 edit_len = end - begin;
91 end_len = strlen(value) - front_len - edit_len;
92 strncpy(tempchar, value, front_len);
93 strncpy(tempchar + front_len, web_list, strlen(web_list));
94 strncpy(tempchar + front_len + strlen(web_list), value + front_len + edit_len, end_len);
95 total_len = front_len + strlen(web_list) + end_len;
96
97
98 }
99
100 memcpy(result, tempchar, total_len);
101 *(result + total_len) = '\0';
102
103 return 0;
104}
105
106/*delete the value of the Nth macip list*/
107/*the macip list format is:
108 [mac1]+[ip1];[mac2]+[ip2];....*/
109/*add by lyf 2012/5/21*/
110static int deleteNthValue(int index, char *value, char delimit)
111{
112 char *begin, *end;
113 int i = 0, j = 0;
114 int need_check_flag = 0;
115 char *buf = NULL;
116 int default_len = 0;
117
118 if (!value)
119 return -1;
120 buf = strdup(value);
121 begin = buf;
122 end = strchr(begin, delimit);
123 while (end) {
124 if (i == index) {
125 memset(begin, 0, end - begin);
126 if (index == 0)
127 need_check_flag = 1;
128 break;
129 }
130 begin = end;
131 end = strchr(begin + 1, delimit);
132 i++;
133 }
134
135 if (!end && index == i)
136 memset(begin, 0, strlen(begin));
137
138 if (need_check_flag) {
139 for (i = 0; i < strlen(value); i++) {
140 if (buf[i] == '\0')
141 continue;
142 if (buf[i] == ';')
143 buf[i] = '\0';
144 break;
145 }
146 }
147 default_len = strlen(value);
148 for (i = 0, j = 0; i < strlen(value); i++) {
149 if (buf[i] != '\0') {
150 value[j++] = buf[i];
151 }
152 }
153 for (i = j; i < default_len; i++)
154 value[i] = '\0';
155
156 free(buf);
157 return 0;
158}
159//·ÅÈëzte_router½ø³ÌʵÏÖ,opms_wan_modeÓ¦¸Ã¸ù¾Ýµ±Ç°µÄȱʡÍâÍø¿Ú£¬Ê¶±ð³öethwan_mode¡¢pswan_mode¡¢wifiwan_modeÆäÖеÄÒ»ÖÖ
160void zte_qos_list_run(void)
161{
162 char Qos_enable[CONFIG_DEFAULT_LENGTH] = {0};
163 char Qos_auto_control[CONFIG_DEFAULT_LENGTH] = {0};
164 char list[NV_QOS_LIST_MAX_LEN] = {0};
165 char rec[NV_QOS_LIST_MAX_LEN] = {0};
166 char opms_wan_mode[CONFIG_DEFAULT_LENGTH] = {0};
167 char wan_if[CONFIG_DEFAULT_LENGTH] = {0};
168 char lan_if_cable[CONFIG_DEFAULT_LENGTH] = {0};
169 char lan_if_wifi[CONFIG_DEFAULT_LENGTH] = {0};
170 char uplimit_total[CONFIG_DEFAULT_LENGTH] = {0};
171 char downlimit_total[CONFIG_DEFAULT_LENGTH] = {0};
172 int i = 0;
173 char ip_list[32] = {0};
174 char maxdownload[32] = {0};
175 char maxupload[32] = {0};
176 char tempchar[32] = {0};
177 cfg_get_item("Qos_enable", Qos_enable, sizeof(Qos_enable));
178 cfg_get_item("Qos_auto_control", Qos_auto_control, sizeof(Qos_auto_control));
179 cfg_get_item("opms_wan_mode", opms_wan_mode, sizeof(opms_wan_mode));
180 cfg_get_item("Qos_control_list", list, sizeof(list));
181 cfg_get_item("UpLimit_Total", uplimit_total, sizeof(uplimit_total));
182 cfg_get_item("DownLimit_Total", downlimit_total, sizeof(downlimit_total));
183
184 if (0 == strlen(opms_wan_mode)) {
185 return;
186 }
187
188 if (!strcmp(opms_wan_mode, "PPPOE")) {
189 strcpy(wan_if, "ppp0");
190 strcpy(lan_if_cable, "eth1");
191 strcpy(lan_if_wifi, "ath0");
192
193 }
194 if (!strcmp(opms_wan_mode, "PPP")) {
195 strcpy(wan_if, "usb0");
196 strcpy(lan_if_cable, "eth0");
197 strcpy(lan_if_wifi, "ath0");
198
199 }
200 if (!strcmp(opms_wan_mode, "DHCP") || !strcmp(opms_wan_mode, "STATIC")) {
201 strcpy(wan_if, "eth0");
202 strcpy(lan_if_cable, "eth1");
203 strcpy(lan_if_wifi, "ath0");
204
205 }
206 if (!strcmp(opms_wan_mode, "BRIDGE")) {
207 return;
208 }
209 /*clear the qdisc first before func return,important!(the qos state from enabled to disabled)*/
210 /*clear upload*/
211 ZTE_LOG(LOG_INFO, "delete the qdisc ################"); /*lint !e26*/
212 doSystem("tc qdisc del dev %s root", wan_if);
213 /*clear download*/
214 doSystem("tc qdisc del dev %s root", lan_if_cable);
215 doSystem("tc qdisc del dev %s root", lan_if_wifi);
216 /*flush the mangle table*/
217 doSystem("iptables -t mangle -F");
218 ZTE_LOG(LOG_INFO, "delete over qdisc::"); /*lint !e26*/
219
220 if (!strlen(Qos_enable)) {
221 return;
222 }
223 if (!atoi(Qos_enable)) {
224 return;
225 }
226 if (atoi(Qos_auto_control)) {
227 return;
228 }
229
230 if (0 == strlen(list)) {
231 return;
232 }
233 ZTE_LOG(LOG_INFO, "list= %s", list); /*lint !e26*/
234
235 /*mark data first for the upload limit(because of SNAT )*/
236 doSystem("iptables -t mangle -A PREROUTING -p tcp -m length --length :64 -j MARK --set-mark 256 ");
237 doSystem("iptables -t mangle -A PREROUTING -p tcp -m length --length :64 -j RETURN ");
238
239 while ((static_getNthValueSafe(i++, list, ';', rec, sizeof(rec)) != -1)) {
240 // get ip
241 if ((static_getNthValueSafe(0, rec, '+', ip_list, sizeof(ip_list)) == -1)) {
242 continue;
243 }
244 if (strlen(ip_list)) {
245 ZTE_LOG(LOG_INFO, "ip_list= %s", ip_list); /*lint !e26*/
246 sprintf(tempchar, "%d", i);
247 doSystem("iptables -t mangle -A PREROUTING -s %s -j MARK --set-mark %s ", ip_list, tempchar);
248 doSystem("iptables -t mangle -A PREROUTING -s %s -j RETURN ", ip_list);
249 memset(tempchar, 0, sizeof(tempchar));
250 }
251 memset(ip_list, 0, sizeof(ip_list));
252 memset(rec, 0, sizeof(rec));
253 }
254 /*upload&&download*/
255 doSystem("tc qdisc add dev %s root handle 1: htb", wan_if);
256 doSystem("tc qdisc add dev %s root handle 1: htb default 256", lan_if_cable);
257 doSystem("tc qdisc add dev %s root handle 1: htb default 256", lan_if_wifi);
258
259 doSystem("tc class add dev %s parent 1: classid 1:256 htb rate %skbit ceil %skbit prio 0 ", wan_if, uplimit_total, uplimit_total);
260 doSystem("tc class add dev %s parent 1: classid 1:256 htb rate %skbit ceil %skbit prio 0 ", lan_if_cable, downlimit_total, downlimit_total);
261 doSystem("tc class add dev %s parent 1: classid 1:256 htb rate %skbit ceil %skbit prio 0 ", lan_if_wifi, downlimit_total, downlimit_total);
262
263
264 doSystem("tc qdisc add dev %s parent 1:256 handle 256: sfq perturb 5 ", wan_if);
265 doSystem("tc qdisc add dev %s parent 1:256 handle 256: sfq perturb 5 ", lan_if_cable);
266 doSystem("tc qdisc add dev %s parent 1:256 handle 256: sfq perturb 5 ", lan_if_wifi);
267
268 doSystem("tc filter add dev %s parent 1:0 protocol ip prio 0 handle 256 fw classid 1:256", wan_if);
269
270 i = 0;
271 while ((static_getNthValueSafe(i++, list, ';', rec, sizeof(rec)) != -1)) {
272 // get ip
273 if ((static_getNthValueSafe(0, rec, '+', ip_list, sizeof(ip_list)) == -1)) {
274 continue;
275 }
276 // get maxdownload
277 if ((static_getNthValueSafe(1, rec, '+', maxdownload, sizeof(maxdownload)) == -1)) {
278 continue;
279 }
280 // get maxupload
281 if ((static_getNthValueSafe(2, rec, '+', maxupload, sizeof(maxupload)) == -1)) {
282 continue;
283 }
284 /*the max download and upload can be 0*/
285 if (strlen(ip_list)) {
286
287 sprintf(tempchar, "%d", i);
288 doSystem("tc class add dev %s parent 1: classid 1:%s htb rate %skbit ceil %skbit prio 1", wan_if, tempchar, maxupload, maxupload);
289 doSystem("tc class add dev %s parent 1: classid 1:%s htb rate %skbit ceil %skbit prio 1", lan_if_cable, tempchar, maxdownload, maxdownload);
290 doSystem("tc class add dev %s parent 1: classid 1:%s htb rate %skbit ceil %skbit prio 1", lan_if_wifi, tempchar, maxdownload, maxdownload);
291 doSystem("tc qdisc add dev %s parent 1:%s handle 1%s: sfq perturb 15", wan_if, tempchar, tempchar);
292 doSystem("tc qdisc add dev %s parent 1:%s handle 1%s: sfq perturb 15", lan_if_cable, tempchar, tempchar);
293 doSystem("tc qdisc add dev %s parent 1:%s handle 1%s: sfq perturb 15", lan_if_wifi, tempchar, tempchar);
294 doSystem("tc filter add dev %s protocol ip parent 1:0 handle %s fw classid 1:%s", wan_if, tempchar, tempchar);
295 doSystem("tc filter add dev %s parent 1:0 protocol ip u32 match ip dst %s flowid 1:%s", lan_if_cable, ip_list, tempchar);
296 doSystem("tc filter add dev %s parent 1:0 protocol ip u32 match ip dst %s flowid 1:%s", lan_if_wifi, ip_list, tempchar);
297 memset(tempchar, 0, sizeof(tempchar));
298 }
299 memset(rec, 0, sizeof(rec));
300 memset(ip_list, 0, sizeof(ip_list));
301 memset(maxdownload, 0, sizeof(maxdownload));
302 memset(maxupload, 0, sizeof(maxupload));
303
304 }
305 cfg_save();
306}
307
308
309/*add a Qos list to the Qos control list */
310/*the Qos list format is:
311 [ip]+[maxdownload]+[maxupload]+[comment];[ip]+[maxdownload]+[maxupload]+[comment];....*/
312/*add by lyf 2012/6/11*/
313void zte_goform_qoslist_add_process(char_t *web_ip, char_t *max_download, char_t *max_upload, char_t *web_comment)
314{
315
316
317 /* value of make qos list */
318 char qos_list[NV_QOS_LIST_MAX_LEN] = {0};
319 char list[NV_QOS_LIST_MAX_LEN] = {0};
320
321 if (!max_download || !web_ip || !max_upload)
322 return;
323 cfg_get_item("Qos_control_list", qos_list, sizeof(qos_list));
324 if (0 != strlen(qos_list)) {
325 snprintf(list, sizeof(list), "%s;%s+%s+%s+%s", qos_list, web_ip, max_download, max_upload, web_comment);
326 } else {
327 snprintf(list, sizeof(list), "%s+%s+%s+%s", web_ip, max_download, max_upload, web_comment);
328 }
329
330 cfg_set("Qos_control_list", list);
331
332 zte_qos_list_run();
333 cfg_save();
334
335}
336
337
338/*delete a Qos list from the list */
339/*the Qos list format is:
340 [ip]+[maxdownload]+[maxupload]+[comment];[ip]+[maxdownload]+[maxupload]+[comment];....*/
341/*add by lyf 2012/6/11*/
342void zte_goform_qoslist_del_process(char_t *index)/*lint !e129*/
343{
344 char qos_list[NV_QOS_LIST_MAX_LEN] = {0};
345 //int list_count=0;
346 int deleIndex = 0;
347
348 if (!index)
349 return;
350 /*the web index begin from 1,but the fun index begin from 0*/
351 deleIndex = atoi(index) - 1;
352 cfg_get_item("Qos_control_list", qos_list, sizeof(qos_list));
353 if (0 == strlen(qos_list)) {
354 return;
355 }
356
357 deleteNthValue(deleIndex, qos_list, ';');
358 cfg_set("Qos_control_list", qos_list);
359 zte_qos_list_run();
360 cfg_save();
361
362
363
364}
365
366
367
368/*edit a qos list of the list */
369/*the Qos list format is:
370 [ip]+[maxdownload]+[maxupload]+[comment];[ip]+[maxdownload]+[maxupload]+[comment];....*/
371/*add by lyf 2012/6/11*/
372void zte_goform_qoslist_edit_process(char_t *web_ip, char_t *maxdownload, char_t *maxupload, char_t *web_comment, char_t *index) /*lint !e129*/
373{
374 char qos_address[64] = {0};
375 char qos_list[NV_QOS_LIST_MAX_LEN] = {0};
376 char rec[NV_QOS_LIST_MAX_LEN] = {0};
377 int editIndex = 0;
378
379 if (!web_ip || !maxdownload || !maxupload || !index)
380 return;
381 /*the web index begin from 1,but the fun index begin from 0*/
382 editIndex = atoi(index) - 1;
383 cfg_get_item("Qos_control_list", qos_list, sizeof(qos_list));
384 if (0 == strlen(qos_list)) {
385 return;
386 }
387
388 sprintf(qos_address, "%s+%s+%s+%s", web_ip, maxdownload, maxupload, web_comment);
389 changeNthValue(editIndex, qos_list, ';', rec, qos_address);
390 cfg_set("Qos_control_list", rec);
391 zte_qos_list_run();
392 cfg_save();
393
394}
395
396
397/*QoS£¬ÔÝδʵÏÖÐèÇó£¬opms_wan_modeÓ¦¸Ã¸ù¾Ýµ±Ç°µÄȱʡÍâÍø¿Ú£¬Ê¶±ð³öethwan_mode¡¢pswan_mode¡¢wifiwan_modeÆäÖеÄÒ»ÖÖ*/
398void zte_goform_Qos(void)/*lint !e18*/
399{
400 char Qos_enable[CONFIG_DEFAULT_LENGTH] = {0};
401 char Qos_auto_control[CONFIG_DEFAULT_LENGTH] = {0};
402 char opms_wan_mode[CONFIG_DEFAULT_LENGTH] = {0};
403 char ack_enable[CONFIG_DEFAULT_LENGTH] = {0};
404
405 cfg_get_item("Qos_enable", Qos_enable, sizeof(Qos_enable));
406 cfg_get_item("Qos_auto_control", Qos_auto_control, sizeof(Qos_auto_control));
407 cfg_get_item("opms_wan_mode", opms_wan_mode, sizeof(opms_wan_mode));
408 cfg_get_item("Qos_control_list", ack_enable, sizeof(ack_enable));
409
410 if (!atoi(Qos_enable)) {
411 /*if the wanmode is ppp0,then to call the ack first shall scrip*/
412 if (atoi(ack_enable)) {
413 if (!strcmp(opms_wan_mode, "PPP")) {
414 ZTE_LOG(LOG_INFO, "ack first is running////////////"); /*lint !e26*/
415 doSystem("ack_first.sh");
416 }
417 cfg_save();
418 return ;/*lint !e533 !e110 */
419 }
420
421
422
423 doSystem("speed_limit_ini.sh");
424 cfg_save();
425 return ;/*lint !e533 !e110 */
426 }
427
428 if (!atoi(Qos_auto_control)) {
429 zte_qos_list_run();
430 } else {
431 ZTE_LOG(LOG_INFO, "QoS auto traffic control is starting!");/*lint !e26*/
432
433 doSystem("qos.sh");
434
435 }
436 cfg_save();
437}
438
439/******************************************************
440* Function: zte_static_route_list_ini_run()
441* Description: run the static route list after the device reboot
442 the static route list format is:
443 [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric];.....
444* Input:
445* Output:
446* Return:
447* Others:
448* 2012/5/21 created by Liu Yifei
449*******************************************************/
450void zte_static_route_list_ini_run(void)
451{
452 //char name[CONFIG_DEFAULT_LENGTH] = {0};
453 char des_ip[32] = {0};
454 char subnet_mask[32] = {0};
455 char gateway[32] = {0};
456 char static_routelist[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
457 char rec[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
458 char pirvate[3] = {0}; /*private button*/
459 char active[3] = {0}; /*active button*/
460 char metric[3] = {0};
461 int list_index = 0;
462 int active_flag = 0;
463
464 cfg_get_item("static_route_list", static_routelist, sizeof(static_routelist));
465 if (0 == strlen(static_routelist)) {
466 return;
467 }
468 while ((getNthValueSafe(list_index++, static_routelist, ';', rec, sizeof(rec)) != -1)) {
469 /*get private info*/
470 if ((getNthValueSafe(1, rec, '+', pirvate, sizeof(pirvate)) == -1)) {
471 continue;
472 }
473 /*get active info*/
474 if ((getNthValueSafe(2, rec, '+', active, sizeof(active)) == -1)) {
475 continue;
476 }
477 /*get des ip address*/
478 if ((getNthValueSafe(3, rec, '+', des_ip, sizeof(des_ip)) == -1)) {
479 continue;
480 }
481 /*get subnet mask*/
482 if ((getNthValueSafe(4, rec, '+', subnet_mask, sizeof(subnet_mask)) == -1)) {
483 continue;
484 }
485 /*get gateway*/
486 if ((getNthValueSafe(5, rec, '+', gateway, sizeof(gateway)) == -1)) {
487 continue;
488 }
489 /*get metric*/
490 if ((getNthValueSafe(6, rec, '+', metric, sizeof(metric)) == -1)) {
491 continue;
492 }
493 if ((0 != strlen(active)) && (0 != strlen(des_ip))
494 && (0 != strlen(subnet_mask)) && (0 != strlen(gateway))) {
495 if (active_flag = atoi(active)) {
496 if (!strcmp(subnet_mask, "255.255.255.255")) {
497 doSystem("route add -host %s gw %s metric %s", des_ip, gateway, metric);
498 } else {
499 doSystem("route add -net %s netmask %s gw %s metric %s", des_ip, subnet_mask, gateway, metric);
500 }
501 }
502 }
503
504
505 }
506
507 cfg_save();
508
509
510}
511
512/******************************************************
513* Function: zte_static_route_list_add()
514* Description: add a list to the static route list
515 the static route list format is:
516 [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric];.....
517* Input: static route info from the web
518* Output:
519* Return:
520* Others:
521* 2012/5/21 created by Liu Yifei
522*******************************************************/
523void zte_static_route_list_add(char *name, char *private, char *active, char *des_ip, char *subnet_mask, char *gateway, char *metric)
524{
525 char static_routelist[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
526 char list[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
527 int active_flag = 0;
528
529 if (!name || !des_ip || !subnet_mask || !gateway) { /*private,active,metric may equal to 0*/
530 return;
531 }
532 cfg_get_item("static_route_list", static_routelist, sizeof(static_routelist));
533
534 if (0 != strlen(static_routelist)) {
535 snprintf(list, sizeof(list), "%s;%s+%s+%s+%s+%s+%s+%s", static_routelist, name, private, active, des_ip, subnet_mask, gateway, metric);
536 } else {
537 snprintf(list, sizeof(list), "%s+%s+%s+%s+%s+%s+%s", name, private, active, des_ip, subnet_mask, gateway, metric);
538 }
539
540 cfg_set("static_route_list", list);
541 if (active_flag = atoi(active)) {
542 if (!strcmp(subnet_mask, "255.255.255.255")) {
543 doSystem("route add -host %s gw %s metric %s", des_ip, gateway, metric);
544 } else {
545 doSystem("route add -net %s netmask %s gw %s metric %s", des_ip, subnet_mask, gateway, metric);
546 }
547 }
548
549 cfg_save();
550}
551/******************************************************
552* Function: zte_static_route_list_run_one()
553* Description: run one list from the static route list
554 the static route list format is:
555 [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric]
556* Input:
557 list--the list to run
558 delimit -- delimitor
559* Output:
560* Return:
561* Others:
562* 2012/5/21 created by Liu Yifei
563*******************************************************/
564void zte_static_route_list_run_one(char *list, char delimit)
565{
566 char des_ip[32] = {0};
567 char subnet_mask[32] = {0};
568 char gateway[32] = {0};
569 char pirvate[3] = {0};
570 char active[3] = {0};
571 char metric[3] = {0};
572 int active_flag = 0;
573
574 if (!list) {
575 return;
576 }
577
578 /*get private info*/
579 if ((getNthValueSafe(1, list, delimit, pirvate, sizeof(pirvate)) == -1)) { /*the index begin from 1,ingore the name(index 0)*/
580 return;
581 }
582 /*get active info*/
583 if ((getNthValueSafe(2, list, delimit, active, sizeof(active)) == -1)) {
584 return;
585 }
586 /*get des ip address*/
587 if ((getNthValueSafe(3, list, delimit, des_ip, sizeof(des_ip)) == -1)) {
588 return;
589 }
590 /*get subnet mask*/
591 if ((getNthValueSafe(4, list, delimit, subnet_mask, sizeof(subnet_mask)) == -1)) {
592 return;
593 }
594 /*get gateway*/
595 if ((getNthValueSafe(5, list, delimit, gateway, sizeof(gateway)) == -1)) {
596 return;
597 }
598 /*get metric*/
599 if ((getNthValueSafe(6, list, delimit, metric, sizeof(metric)) == -1)) {
600 return;
601 }
602 if ((0 != strlen(active)) && (0 != strlen(des_ip))
603 && (0 != strlen(subnet_mask)) && (0 != strlen(gateway))) {
604 if (active_flag = atoi(active)) {
605 if (!strcmp(subnet_mask, "255.255.255.255")) {
606 doSystem("route add -host %s gw %s metric %s", des_ip, gateway, metric);
607 } else {
608 doSystem("route add -net %s netmask %s gw %s metric %s", des_ip, subnet_mask, gateway, metric);
609 }
610 }
611 }
612
613}
614/******************************************************
615* Function: zte_static_route_list_del_one()
616* Description: delete one list from the static route list
617 the static route list format is:
618 [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric]
619* Input:
620 list--the list to delete
621 delimit -- delimitor
622* Output:
623* Return:
624* Others:
625* 2012/5/21 created by Liu Yifei
626*******************************************************/
627void zte_static_route_list_del_one(char *list, char delimit)
628{
629 char des_ip[32] = {0};
630 char subnet_mask[32] = {0};
631 char gateway[32] = {0};
632 char pirvate[3] = {0};
633 char active[3] = {0};
634 char metric[3] = {0};
635 int active_flag = 0;
636
637 if (!list) {
638 return;
639 }
640
641 /*get private info*/
642 if ((getNthValueSafe(1, list, delimit, pirvate, sizeof(pirvate)) == -1)) { /*the index begin from 1,ingore the name(index 0)*/
643 return;
644 }
645 /*get active info*/
646 if ((getNthValueSafe(2, list, delimit, active, sizeof(active)) == -1)) {
647 return;
648 }
649 /*get des ip address*/
650 if ((getNthValueSafe(3, list, delimit, des_ip, sizeof(des_ip)) == -1)) {
651 return;
652 }
653 /*get subnet mask*/
654 if ((getNthValueSafe(4, list, delimit, subnet_mask, sizeof(subnet_mask)) == -1)) {
655 return;
656 }
657 /*get gateway*/
658 if ((getNthValueSafe(5, list, delimit, gateway, sizeof(gateway)) == -1)) {
659 return;
660 }
661 /*get metric*/
662 if ((getNthValueSafe(6, list, delimit, metric, sizeof(metric)) == -1)) {
663 return;
664 }
665 if ((0 != strlen(active)) && (0 != strlen(des_ip))
666 && (0 != strlen(subnet_mask)) && (0 != strlen(gateway))) {
667 if (active_flag = atoi(active)) {
668 if (!strcmp(subnet_mask, "255.255.255.255")) {
669 doSystem("route del -host %s gw %s metric %s", des_ip, gateway, metric);
670 } else {
671 doSystem("route del -net %s netmask %s gw %s metric %s", des_ip, subnet_mask, gateway, metric);
672 }
673 }
674 }
675
676}
677/******************************************************
678* Function: zte_static_route_list_del()
679* Description: delete a list from the static route list according to the delete index
680 the static route list format is:
681 [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric];.....
682* Input:
683 index--the index of deleted items
684 delimit -- delimitor
685* Output:
686* Return:
687* Others:
688* 2012/5/21 created by Liu Yifei
689*******************************************************/
690void zte_static_route_list_del(int index, char delimit)
691{
692 char static_routelist[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
693 char list[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};/*temp list*/
694 //int active_flag=0;
695 char *begin = NULL;
696 char *end = NULL;
697 char *buf = NULL;
698 int i = 0;
699 int j = 0;
700 int need_check_flag = 0;
701 int default_len = 0;
702
703 cfg_get_item("static_route_list", static_routelist, sizeof(static_routelist));
704 if (!strlen(static_routelist)) {
705 return;
706 }
707
708 buf = strdup(static_routelist);
709 begin = buf;
710 end = strchr(begin, delimit);
711 while (end) {
712 if (i == index) {
713 strncpy(list, begin, end - begin);
714 zte_static_route_list_del_one(list, '+');
715 memset(begin, 0, end - begin);
716 memset(list, 0, strlen(list));
717 if (index == 0)
718 need_check_flag = 1;
719 break;
720 }
721 begin = end;
722
723 end = strchr(begin + 1, delimit);
724 i++;
725 }
726 if (!end && index == i) {
727 strncpy(list, begin, strlen(begin));
728 zte_static_route_list_del_one(list, '+');
729 memset(list, 0, strlen(list)); /*set the temp list to 0*/
730 memset(begin, 0, strlen(begin));
731
732 }
733
734
735 if (need_check_flag) {
736 for (i = 0; i < strlen(static_routelist); i++) {
737 if (buf[i] == '\0') {
738 continue;
739 }
740 if (buf[i] == ';') {
741 buf[i] = '\0';
742 }
743 break;
744 }
745 }
746 default_len = strlen(static_routelist);
747 for (i = 0, j = 0; i < strlen(static_routelist); i++) {
748 if (buf[i] != '\0') {
749 static_routelist[j++] = buf[i];
750 }
751 }
752 for (i = j; i < default_len; i++)
753 static_routelist[i] = '\0';
754
755 cfg_set("static_route_list", static_routelist);
756 cfg_save();
757 free(buf);
758
759
760}
761/******************************************************
762* Function: zte_static_route_list_edit_one()
763* Description: edit a list from the static route list
764 the static route list format is:
765 [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric];.....
766* Input:
767 index--the index of deleted item
768 value--the static route list
769 delimit--delimitor
770 web_list--static route info from the web
771* Output:
772 result-- the edited static route list
773* Return:
774* Others:
775* 2012/5/21 created by Liu Yifei
776*******************************************************/
777int zte_static_route_list_edit_one(int index, char *value, char delimit, char *result, char *web_list)
778{
779 int i = 0;
780 int front_len = 0;
781 int end_len = 0;
782 int edit_len = 0;
783 int total_len = 0;
784 char *begin = NULL;
785 char *end = NULL;
786 char tempchar[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
787 char dosys_list[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
788
789 if (!value || !result || !web_list)
790 return -1;
791
792 begin = value;
793 end = strchr(begin, delimit);
794 while (i < index && end) {
795 begin = end + 1;
796 end = strchr(begin, delimit);
797 i++;
798 }
799
800 //no delimit
801 if (!end) {
802 if (i == index) {
803 end = begin + strlen(begin) - 1;
804 strncpy(dosys_list, begin, end - begin + 1);
805 printf(dosys_list);
806 zte_static_route_list_del_one(dosys_list, '+');
807 memset(dosys_list, 0, strlen(dosys_list));
808 front_len = begin - value;
809 strncpy(tempchar, value, front_len);
810 strncpy(tempchar + front_len, web_list, (strlen(web_list)));
811 zte_static_route_list_run_one(web_list, '+');
812 total_len = front_len + strlen(web_list);
813 } else {
814 return -1;
815 }
816 } else {
817 front_len = begin - value;
818 edit_len = end - begin;
819 end_len = strlen(value) - front_len - edit_len;
820 strncpy(dosys_list, begin, end - begin);
821 printf(dosys_list);
822 zte_static_route_list_del_one(dosys_list, '+');
823 memset(dosys_list, 0, strlen(dosys_list));
824 strncpy(tempchar, value, front_len);
825 strncpy(tempchar + front_len, web_list, strlen(web_list));
826 strncpy(tempchar + front_len + strlen(web_list), value + front_len + edit_len, end_len);
827 zte_static_route_list_run_one(web_list, '+');
828 total_len = front_len + strlen(web_list) + end_len;
829 }
830 memcpy(result, tempchar, total_len);
831 *(result + total_len) = '\0';
832
833 return 0;
834
835}
836/******************************************************
837* Function: zte_static_route_list_edit()
838* Description: edit a list from the static route list
839 call zte_static_route_list_edit_one() to process
840 the static route list format is:
841 [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric];.....
842* Input:
843 index--the index of deleted item
844 list info from the web
845* Output:
846* Return:
847* Others:
848* 2012/5/21 created by Liu Yifei
849*******************************************************/
850void zte_static_route_list_edit(char *index, char *web_name, char *web_private, char *web_active, char *web_des_ip, char *web_subnet_mask, char *web_gateway, char *web_metric)
851{
852 char staticroute_one_list[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
853 char static_route_list[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
854 char rec[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
855 int editIndex = 0;
856 if (!web_name || !web_des_ip || !web_subnet_mask || !web_gateway) { /*private,active,metric may equal to 0*/
857 return;
858 }
859 editIndex = atoi(index) - 1;
860 cfg_get_item("static_route_list", static_route_list, sizeof(static_route_list));
861 if (!strlen(static_route_list)) {
862 return;
863 }
864 sprintf(staticroute_one_list, "%s+%s+%s+%s+%s+%s+%s", web_name, web_private, web_active, web_des_ip, web_subnet_mask, web_gateway, web_metric);
865 zte_static_route_list_edit_one(editIndex, static_route_list, ';', rec, staticroute_one_list);
866 cfg_set("static_route_list", rec);
867 cfg_save();
868}
869#endif
870
871//add by gongxuanhui 03/13/2014
872static void zte_router_make_MTU_Rule(char *buf, int len, char *wan_name, char *mtu_value)
873{
874 snprintf(buf, len, "ifconfig %s mtu %s ", wan_name, mtu_value);
875}
876
877//add by gongxuanhui 03/13/2014
878void zte_router_MTU_set(void)
879{
880
881 char cmd[1024] = {0};
882 char mtu[128] = {0};
883 int mtu_int;
884
885 memset(cmd, 0, sizeof(cmd));
886
887 //zte_router_nvconfig_read("mtu");
888 //strcpy(mtu , g_router_nvconfig_buf);
889
890 cfg_get_item("mtu", mtu, sizeof(mtu));
891
892 if (0 == strcmp(mtu, "")) {
893 slog(NET_PRINT, SLOG_ERR, "Warning: mtu valu is null \n");
894 return;
895 }
896
897 if ((mtu_int = atoi(mtu)) < 1280 || mtu_int > 1500) {
898 slog(NET_PRINT, SLOG_ERR, "Warning: mtu value is illgality\n");
899 return;
900 }
901
902 zte_router_make_MTU_Rule(cmd, sizeof(cmd), defwan_rel, mtu);
903
904 system_cmd_ex(cmd);
905 //system_cmd_ex("firewall_init.sh");
906 return;
907}
908
909//1217
910void zte_unpn_set(void)
911{
912 char upnpEnabled[8] = {0};
913
914 cfg_get_item("upnpEnabled", upnpEnabled, sizeof(upnpEnabled));
915 slog(NET_PRINT, SLOG_NORMAL, "router : start to set upnp %s\n", upnpEnabled);
916 if(atoi(upnpEnabled))
917 system_cmd_ex("upnp.sh");
918}
919void zte_router_dhcp_set_process(void)
920{
921 slog(NET_PRINT, SLOG_NORMAL, "router : start to set dhcp \n");
922 system_cmd_ex("lan.sh");
923 //doSystem("killall fullshare");
924 //doSystem("killall smbd");
925 //doSystem("killall nmbd");
926 //doSystem("fullshare &");
927 //doSystem("smbd -D");
928 //doSystem("nmbd -D");
929 //doSystem("sh /mnt/jffs2/scripts/upnp.sh");
930}
931
932//add by gongxuanhui 03/13/2014
933void zte_router_mtu_set_process(void)
934{
935 //zte_router_MTU_set();
936 zte_router_init();
937}
938
939
940//set mac_ip_list when get msg from web_firewall 08/09/2015
941void zte_macip_list_run(void)
942{
943 char dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
944 char list[NV_MACIP_LIST_MAX_LEN] = {0};
945 char mac_address[32] = {0}; /*mac address */
946 char ip_address[32] = {0}; /*ip address */
947
948 int dhcp_server_enable = 0;
949 int i = 0;
950 char rec[NV_MACIP_LIST_MAX_LEN] = {0};
951 char cmd[1024] = {0};
952
953 cfg_get_item("dhcpEnabled", dhcp_enable, sizeof(dhcp_enable));
954 if (0 == strlen(dhcp_enable)) {
955 slog(NET_PRINT, SLOG_ERR, "Error: can't find \"dhcpEnabled\" in flash.\n"); /*lint !e26*/
956 return;
957 }
958 dhcp_server_enable = atoi(dhcp_enable);
959 /* if dhcp is disable, then return directly: 0 mean disable, 1 means enable */
960 if (0 == dhcp_server_enable) {
961 return;
962 }
963
964 cfg_get_item("mac_ip_list", list, sizeof(list));
965
966 /*kill udhcpd*/
967 system_cmd_ex("config-udhcpd.sh \"lan\" -k");
968 /*clear the static_lease list in udhcpd.conf file*/
969 system_cmd_ex("config-udhcpd.sh \"lan\" -S");
970 while ((getNthValueSafe(i++, list, ';', rec, sizeof(rec)) != -1)) {
971 // get mac
972 if ((getNthValueSafe(1, rec, '+', mac_address, sizeof(mac_address)) == -1)) {
973 continue;
974 }
975 // get ip
976 if ((getNthValueSafe(2, rec, '+', ip_address, sizeof(ip_address)) == -1)) {
977 continue;
978 }
979 if ((0 != strlen(mac_address))
980 && (0 != strlen(ip_address))) {
981 memset(cmd, 0, sizeof(cmd));
982 sprintf(cmd, "config-udhcpd.sh \"lan\" -S %s %s", mac_address, ip_address);
983 system_cmd_ex(cmd);
984 //system_cmd_ex("config-udhcpd.sh -S %s %s",mac_address,ip_address);
985 }
986
987
988 }
989
990 /*restart udhcpd*/
991 system_cmd_ex("config-udhcpd.sh \"lan\" -r");
992
993}
994
995void zte_bind_macip_list(void)
996{
997 char dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
998 char static_dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
999
1000 cfg_get_item("dhcpEnabled", dhcp_enable, sizeof(dhcp_enable));
1001 if (0 == strlen(dhcp_enable)) {
1002 slog(NET_PRINT, SLOG_ERR, "Error: can't find \"dhcpEnabled\" in flash.\n"); /*lint !e26*/
1003 return;
1004 }
1005 /* if dhcp is disable, then return directly: 0 mean disable, 1 means enable */
1006 if (0 == atoi(dhcp_enable)) {
1007 return;
1008 }
1009
1010 /*kill udhcpd*/
1011 system_cmd_ex("config-udhcpd.sh \"lan\" -k");
1012
1013 cfg_get_item("static_dhcp_enable", static_dhcp_enable, sizeof(static_dhcp_enable));
1014
1015 //static_dhcp_enable=0,¹Ø±ÕMAC-IP°ó¶¨¹¦ÄÜ£¬Çå¿Õudhcpd.confÎļþÖа󶨵ÄMAC-IP
1016 //static_dhcp_enable=1,¿ªÆôMAC-IP°ó¶¨¹¦ÄÜ£¬½«Ö®Ç°µÄMAC-IP°ó¶¨¹ØÏµÖØÐÂдÈëudhcpd.conf
1017 if (0 == atoi(static_dhcp_enable)) {
1018 /*clear the static_lease list in udhcpd.conf file*/
1019 system_cmd_ex("config-udhcpd.sh \"lan\" -S");
1020 } else
1021 system_cmd_ex("config-udhcpd.sh \"lan\" -E");
1022
1023 system_cmd_ex("config-udhcpd.sh \"lan\" -r");
1024
1025}
1026
1027void zte_bind_macip_list_add(struct static_macip_info *static_macip)
1028{
1029 char dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
1030 char static_dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
1031 char* mac_address = NULL; /*mac address to add*/
1032 char* ip_address = NULL; /*ip address to add */
1033 char cmd[200] = {0};
1034
1035 cfg_get_item("dhcpEnabled", dhcp_enable, sizeof(dhcp_enable));
1036 if (0 == strlen(dhcp_enable)) {
1037 slog(NET_PRINT, SLOG_ERR, "Error: can't find \"dhcpEnabled\" in flash.\n"); /*lint !e26*/
1038 return;
1039 }
1040 /* if dhcp is disable, then return directly: 0 mean disable, 1 means enable */
1041 if (0 == atoi(dhcp_enable)) {
1042 return;
1043 }
1044
1045 mac_address = static_macip->mac;
1046 ip_address = static_macip->ip;
1047
1048 /*kill udhcpd*/
1049 system_cmd_ex("config-udhcpd.sh \"lan\" -k");
1050
1051 cfg_get_item("static_dhcp_enable", static_dhcp_enable, sizeof(static_dhcp_enable));
1052
1053 //static_dhcp_enable=0,¹Ø±ÕMAC-IP°ó¶¨¹¦ÄÜ£¬Çå¿Õ°ó¶¨µÄMAC-IP
1054 if (1 == atoi(static_dhcp_enable)) {
1055 //Ôö¼ÓMAC-IP°ó¶¨¹æÔò
1056 if ((0 != strlen(mac_address)) && (0 != strlen(ip_address))) {
1057 sprintf(cmd, "config-udhcpd.sh \"lan\" -S %s %s", mac_address, ip_address);
1058 system_cmd_ex(cmd);
1059 }
1060 }
1061
1062 system_cmd_ex("config-udhcpd.sh \"lan\" -r");
1063
1064}
1065
1066void zte_bind_macip_list_del(char* mac)
1067{
1068 char dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
1069 char static_dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
1070 char cmd[200] = {0};
1071
1072 cfg_get_item("dhcpEnabled", dhcp_enable, sizeof(dhcp_enable));
1073 if (0 == strlen(dhcp_enable)) {
1074 slog(NET_PRINT, SLOG_ERR, "Error: can't find \"dhcpEnabled\" in flash.\n"); /*lint !e26*/
1075 return;
1076 }
1077 /* if dhcp is disable, then return directly: 0 mean disable, 1 means enable */
1078 if (0 == atoi(dhcp_enable)) {
1079 return;
1080 }
1081
1082 /*kill udhcpd*/
1083 system_cmd_ex("config-udhcpd.sh \"lan\" -k");
1084
1085 cfg_get_item("static_dhcp_enable", static_dhcp_enable, sizeof(static_dhcp_enable));
1086
1087 //static_dhcp_enable=0,¹Ø±ÕMAC-IP°ó¶¨¹¦ÄÜ£¬Çå¿Õ°ó¶¨µÄMAC-IP
1088 if (1 == atoi(static_dhcp_enable)) {
1089 //ɾ³ýMAC-IP°ó¶¨¹æÔò
1090 if (0 != strlen(mac)) {
1091 sprintf(cmd, "config-udhcpd.sh \"lan\" -D %s", mac);
1092 system_cmd_ex(cmd);
1093 }
1094 }
1095
1096 system_cmd_ex("config-udhcpd.sh \"lan\" -r");
1097
1098}
1099
1100
1101void get_mac_hostname_pro(struct mac_hostname_info *mac_hostname_)
1102{
1103 char *mac = NULL;
1104 char *hostname = NULL;
1105 char cmd[200] = {0};
1106 mac = mac_hostname_->mac;
1107 hostname = mac_hostname_->hostname;
1108 sprintf(cmd, "config-hostname.sh \"%s\" \"%s\"", mac, hostname);
1109 system_cmd_ex(cmd);
1110
1111}
1112
1113void children_device_add(struct mac_hostname_info *mac_hostname)
1114{
1115 char *mac = NULL;
1116 char *hostname = NULL;
1117 char cmd[200] = {0};
1118 mac = mac_hostname->mac;
1119 hostname = mac_hostname->hostname;
1120 slog(NET_PRINT, SLOG_NORMAL, "children_device_add:mac= %s, hostname = %s\n", mac, hostname);
1121 if ((0 != strlen(mac)) && (0 != strlen(hostname))) {
1122 sprintf(cmd, "config-parents.sh device \"%s\" \"%s\"", mac, hostname);
1123 system_cmd_ex(cmd);
1124 }
1125}
1126
1127void children_device_del(char * mac)
1128{
1129 char cmd[100] = {0};
1130 if (0 != strlen(mac)) {
1131 sprintf(cmd, "config-parents.sh device \"%s\"", mac);
1132 system_cmd_ex(cmd);
1133 }
1134}
1135
1136
1137void white_site_add(struct white_site_info * white_site)
1138{
1139 char *name = NULL;
1140 char *site = NULL;
1141 char cmd[600] = {0};
1142 name = white_site->name;
1143 site = white_site->site;
1144 slog(NET_PRINT, SLOG_NORMAL, "white_site_add:site= %s, name = %s\n", site, name);
1145 if (0 != strlen(site)) {
1146 sprintf(cmd, "config-parents.sh white_site -A \"%s\" \"%s\"", site, name);
1147 system_cmd_ex(cmd);
1148 }
1149
1150}
1151
1152
1153void white_site_remove(char * ids)
1154{
1155 char cmd[100] = {0};
1156 if (0 != strlen(ids)) {
1157 sprintf(cmd, "config-parents.sh white_site -D \"%s\"", ids);
1158 system_cmd_ex(cmd);
1159 }
1160}
1161
1162
1163void zte_children_start_nonet(void)
1164{
1165 char sys_cmd_bufer[500] = {0};
1166
1167 FILE *chilren_device_file = NULL;
1168 char line[200] = {0};
1169 char mac[18] = {0};
1170 char path_conf[50] = {0};
1171 char path_file[100] = {0};
1172 cfg_get_item("path_conf", path_conf, sizeof(path_conf));
1173 sprintf(path_file, "%s/children_device_file", path_conf);
1174
1175 /*flush filter chain*/
1176 sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_MAC_CHAIN, FMT_ECHO_IPTABLES_CMD);
1177 system_cmd_ex(sys_cmd_bufer);
1178 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1179 sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_WEB_CHAIN, FMT_ECHO_IPTABLES_CMD);
1180 system_cmd_ex(sys_cmd_bufer);
1181 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1182 sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_WEB_PHONE_CHAIN, FMT_ECHO_IPTABLES_CMD);
1183 system_cmd_ex(sys_cmd_bufer);
1184
1185
1186 chilren_device_file = fopen(path_file, "r");
1187 if (chilren_device_file == NULL) {
1188 fprintf(stderr, "can not open file children_device_file.");
1189 return;
1190 }
1191
1192 while (fgets(line, 200, chilren_device_file) != NULL) {
1193 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1194
1195 strncpy(mac, line, 17);
1196
1197 if (strcmp(mac, "") != 0) {
1198 sprintf(sys_cmd_bufer, "iptables -A %s -m mac --mac-source %s -j DROP", CLILDREN_MAC_CHAIN, mac);
1199 slog(NET_PRINT, SLOG_NORMAL, "%s \n", sys_cmd_bufer);
1200 system_cmd_ex(sys_cmd_bufer);
1201 }
1202
1203 memset(line, 0, sizeof(line));
1204 memset(mac, 0, sizeof(mac));
1205 }
1206 fclose(chilren_device_file);
1207}
1208
1209static void make_children_white_site_rule(char mac[])
1210{
1211 slog(NET_PRINT, SLOG_NORMAL, "make_children_white_site_rule start! \n");
1212 char sys_cmd_bufer[600] = {0};
1213 FILE *white_site_file = NULL;
1214 char url_hexstring[ZTE_ROUTER_URL_FILTER_LEN] = {0};
1215 char line[600] = {0};
1216 char site[600] = {0};//klocwork
1217 char temp_site[600] = {0};
1218
1219 unsigned int len = 0;
1220
1221 char path_conf[50] = {0};
1222 char path_file[100] = {0};
1223 cfg_get_item("path_conf", path_conf, sizeof(path_conf));
1224 sprintf(path_file, "%s/white_site_file", path_conf);
1225
1226 white_site_file = fopen(path_file, "r");
1227 if (white_site_file == NULL) {
1228 fprintf(stderr, "can not open file white_site_file.");
1229
1230 //PCÖÕ¶Ë:ĬÈϽ«macµØÖ·µÄ53¶Ë¿ÚµÄ°ü¶ªµô
1231 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1232 sprintf(sys_cmd_bufer, "iptables -A %s -m mac --mac-source %s -p udp --dport 53 -j DROP", CLILDREN_WEB_CHAIN, mac);
1233 system_cmd_ex(sys_cmd_bufer);
1234
1235 //ÊÖ»úÖÕ¶Ë:ĬÈϽ«macµØÖ·µÄ53¶Ë¿ÚµÄ°ü¶ªµô
1236 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1237 sprintf(sys_cmd_bufer, "iptables -A %s -m mac --mac-source %s -p udp --dport 53 -j DROP", CLILDREN_WEB_PHONE_CHAIN, mac);
1238 system_cmd_ex(sys_cmd_bufer);
1239
1240 return;
1241 }
1242
1243 while (fgets(line, 600, white_site_file) != NULL) {
1244 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1245 memset(url_hexstring, 0, sizeof(url_hexstring));
1246
1247 int i = 0;
1248 for (i = 0; i < 600; i++) {
1249 if (line[i] == ',') {
1250 len = i;
1251 break;
1252 }
1253 }
1254 strncpy(site, line, len);
1255
1256 if (strcmp(site, "") != 0) {
1257 //È¥³ý꿅Ⴁ̾µÄhttpÍ·²¿
1258 if (!strncasecmp(site, "http://", strlen("http://"))) {
1259 strncpy(site, site + strlen("http://"), sizeof(site)-1);
1260 }
1261 if (!strncasecmp(site, "https://", strlen("https://"))) {
1262 strncpy(site, site + strlen("https://"), sizeof(site)-1);
1263 }
1264 //È¥³ýÍøÖ·ºóÃæ.com/ºóµÄβ²¿
1265 int seq = 0;
1266 int len_site = 0;
1267 memset(temp_site, 0, sizeof(temp_site));
1268 strcpy(temp_site, site);
1269 for (seq = 0; seq < strlen(temp_site); seq++) {
1270 if (temp_site[seq] == '/') {
1271 len_site = seq;
1272 memset(site, 0, sizeof(site));
1273 strncpy(site, temp_site, len_site);
1274 break;
1275 }
1276 }
1277
1278
1279
1280 str_vary_dit(site, url_hexstring);
1281 slog(NET_PRINT, SLOG_NORMAL, "site=%s url_hexstring=%s\n", site, url_hexstring);
1282 snprintf(sys_cmd_bufer, sizeof(sys_cmd_bufer), "iptables -A %s -m mac --mac-source %s -m string --hex-string \"|%s|\" --algo kmp -j ACCEPT", \
1283 CLILDREN_WEB_CHAIN, mac, url_hexstring);//klocwork
1284 system_cmd_ex(sys_cmd_bufer);
1285
1286 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1287 snprintf(sys_cmd_bufer, sizeof(sys_cmd_bufer), "iptables -A %s -m mac --mac-source %s -m string --hex-string \"|%s|\" --algo kmp -j ACCEPT", \
1288 CLILDREN_WEB_PHONE_CHAIN, mac, url_hexstring);
1289 system_cmd_ex(sys_cmd_bufer);
1290
1291 }
1292
1293 memset(line, 0, sizeof(line));
1294 memset(site, 0, sizeof(site));
1295 len = 0;
1296 }
1297
1298 fclose(white_site_file);
1299
1300 //ĬÈϽ«macµØÖ·µÄ53¶Ë¿ÚµÄ°ü¶ªµô
1301 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1302 sprintf(sys_cmd_bufer, "iptables -A %s -m mac --mac-source %s -p udp --dport 53 -j DROP", CLILDREN_WEB_CHAIN, mac);
1303 system_cmd_ex(sys_cmd_bufer);
1304
1305 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1306 sprintf(sys_cmd_bufer, "iptables -A %s -m mac --mac-source %s -p udp --dport 53 -j DROP", CLILDREN_WEB_PHONE_CHAIN, mac);
1307 system_cmd_ex(sys_cmd_bufer);
1308
1309
1310}
1311
1312void zte_children_stop_nonet(void)
1313{
1314 char sys_cmd_bufer[500] = {0};
1315 FILE *chilren_device_file = NULL;
1316 char line[200] = {0};
1317 char mac[18] = {0};
1318
1319 char path_conf[50] = {0};
1320 char path_file[100] = {0};
1321 cfg_get_item("path_conf", path_conf, sizeof(path_conf));
1322 sprintf(path_file, "%s/children_device_file", path_conf);
1323
1324 system_cmd_ex("iptables -t filter -D INPUT -p udp --dport 53 -j ACCEPT");
1325 system_cmd_ex("iptables -t filter -D FORWARD -p udp --dport 53 -j ACCEPT");
1326
1327
1328
1329 /*flush filter chain*/
1330 sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_MAC_CHAIN, FMT_ECHO_IPTABLES_CMD);
1331 system_cmd_ex(sys_cmd_bufer);
1332 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1333 sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_WEB_CHAIN, FMT_ECHO_IPTABLES_CMD);
1334 system_cmd_ex(sys_cmd_bufer);
1335 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1336 sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_WEB_PHONE_CHAIN, FMT_ECHO_IPTABLES_CMD);
1337 system_cmd_ex(sys_cmd_bufer);
1338
1339 chilren_device_file = fopen(path_file, "r");
1340 if (chilren_device_file == NULL) {
1341 fprintf(stderr, "can not open file children_device_file.");
1342 return;
1343 }
1344
1345 while (fgets(line, 200, chilren_device_file) != NULL) {
1346 memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
1347
1348 strncpy(mac, line, 17);
1349
1350 if (strcmp(mac, "") != 0) {
1351 make_children_white_site_rule(mac);
1352 }
1353
1354 memset(line, 0, sizeof(line));
1355 memset(mac, 0, sizeof(mac));
1356 }
1357 fclose(chilren_device_file);
1358}
1359
1360/* DHCP_SETTING_REQ */
1361void zte_router_dhcp_setting_req_process(dhcp_setting_req *pdhcp_setting_req)
1362{
1363 (void)cfg_set("lan_ipaddr", pdhcp_setting_req->lan_ip);
1364 (void)cfg_set("lan_netmask", pdhcp_setting_req->lan_netmask);
1365 if (!pdhcp_setting_req->dhcp_enabled) {
1366 (void)cfg_set("dhcpEnabled", "0");
1367 } else {
1368 (void)cfg_set("dhcpEnabled", "1");
1369 (void)cfg_set("dhcpStart", pdhcp_setting_req->dhcp_start);
1370 (void)cfg_set("dhcpEnd", pdhcp_setting_req->dhcp_end);
1371 (void)cfg_set("dhcpDns", pdhcp_setting_req->dhcp_dns);
1372 (void)cfg_set("dhcpLease_hour", pdhcp_setting_req->dhcp_lease);
1373 }
1374
1375 system_cmd_ex("user-config-udhcpd.sh");
1376}
1377