| 1 | /* Modified by: xChaos, 20121011 */\r |
| 2 | \r |
| 3 | #include "cll1-0.6.2.h"\r |
| 4 | #include "ipstruct.h"\r |
| 5 | \r |
| 6 | extern struct IP *ips, *ip;\r |
| 7 | \r |
| 8 | void write_json_traffic(char *json)\r |
| 9 | {\r |
| 10 | FILE *f=fopen(json, "w");\r |
| 11 | if(f > 0)\r |
| 12 | {\r |
| 13 | int jsoncount=0;\r |
| 14 | fprintf(f, "{\n");\r |
| 15 | \r |
| 16 | for_each(ip, ips)\r |
| 17 | {\r |
| 18 | if( ip->lmsid > 0 \r |
| 19 | and (ip->traffic or ip->direct or ip->proxy or ip->upload))\r |
| 20 | {\r |
| 21 | if(jsoncount)\r |
| 22 | {\r |
| 23 | fprintf(f, ",\n");\r |
| 24 | }\r |
| 25 | fprintf(f, \r |
| 26 | " \"%s\":{ \"lms\": %d, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \\r |
| 27 | \"proxy\":%Lu, \"up\":%Lu, \"min\":%d, \"max\":%d, \"limit\":%d, \\r |
| 28 | \"pktsup\":%Lu, \"pktsdown\":%Lu, \"realquota\":%Lu, \"credit\":%Lu, \"dailyquota\":%ld }",\r |
| 29 | ip->name, ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, \r |
| 30 | ip->upload, ip->min, ip->desired, ip->max, ip->pktsup, ip->pktsdown,\r |
| 31 | ip->realquota, ip->credit, (ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20)));\r |
| 32 | jsoncount++;\r |
| 33 | }\r |
| 34 | }\r |
| 35 | fprintf(f, "}\n");\r |
| 36 | fclose(f);\r |
| 37 | puts("done.");\r |
| 38 | }\r |
| 39 | else\r |
| 40 | {\r |
| 41 | perror(json);\r |
| 42 | }\r |
| 43 | } |