9a56ab25 |
1 | #include "cll1-0.6.2.h"\r |
2 | #include "ipstruct.h"\r |
3 | #define STRLEN 512\r |
4 | \r |
5 | extern int row_odd_even;\r |
6 | extern int use_jquery_popups;\r |
7 | extern struct IP *ips, *ip, *sharedip;\r |
8 | extern struct Group *groups, *group;\r |
9 | extern struct Keyword *keyword, *defaultkeyword, *keywords;\r |
10 | extern const int highest_priority;\r |
11 | extern const char *version;\r |
12 | extern const char *stats_html_signature;\r |
13 | extern char *jquery_url;\r |
14 | extern int keywordcount;\r |
15 | extern long long int line;\r |
16 | extern int dry_run;\r |
17 | extern int qos_proxy;\r |
18 | extern char *title;\r |
19 | extern char *log_url;\r |
20 | extern int found_lmsid;\r |
21 | extern char *lms_url;\r |
22 | extern char *log_dir;\r |
ca6f7e80 |
23 | extern char *ip6prefix;\r |
9a56ab25 |
24 | \r |
25 | const char *tr_odd_even(void);\r |
26 | /* implemented in prometheus.c, shared with parselogs.c */\r |
27 | \r |
28 | void append_log(struct IP *self) /*using global variables*/\r |
29 | {\r |
30 | char *d, *str;\r |
31 | FILE *f; \r |
32 | \r |
33 | date(d); /* this is typical cll1.h macro - prints current date */ \r |
0995c4ad |
34 | string(str, STRLEN); \r |
35 | sprintf(str, "%s/%s.log", log_dir, self->name);\r |
36 | \r |
37 | /*-----------------------------------------------------------------*/\r |
38 | printf("Writing traffic log %s ...\n", str);\r |
39 | /*-----------------------------------------------------------------*/\r |
40 | f = fopen(str, "a");\r |
9a56ab25 |
41 | if(f > 0)\r |
42 | {\r |
0995c4ad |
43 | fprintf(f, "%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s",\r |
44 | time(NULL), self->name, self->traffic, self->direct, self->proxy,\r |
45 | self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/\r |
9a56ab25 |
46 | fclose(f);\r |
47 | }\r |
48 | else\r |
49 | {\r |
50 | perror(str);\r |
51 | }\r |
52 | }\r |
53 | \r |
54 | void write_htmlandlogs(char *html, char *d, int total, int just_preview)\r |
55 | {\r |
56 | int i;\r |
57 | char *str;\r |
0db8e993 |
58 | FILE *f=fopen(html, "w");\r |
9a56ab25 |
59 | \r |
60 | string(str,STRLEN); \r |
61 | if(f > 0)\r |
62 | {\r |
63 | int count=1;\r |
64 | i=0;\r |
65 | \r |
9a56ab25 |
66 | if(use_jquery_popups)\r |
67 | {\r |
68 | fprintf(f,"<script type=\"text/javascript\" src=\"%s\"></script>\n", jquery_url);\r |
69 | }\r |
70 | fputs("<table class=\"decorated last\">\n\\r |
71 | <caption>Bandwidth classes</caption>\n\\r |
72 | <thead><tr>\n\\r |
73 | <th style=\"text-align: right\">#</th>\n\\r |
74 | <th style=\"text-align: right\">group</th>\n\\r |
75 | <th style=\"text-align: right\">IPs</th>\n\\r |
76 | <th style=\"text-align: right\">requested</th>\n",f);\r |
77 | fprintf(f,"<th colspan=\"%d\">data limits</th>\n", keywordcount);\r |
78 | fputs("</tr></thead><tbody>\n",f);\r |
79 | \r |
80 | row_odd_even = 0;\r |
81 | for_each(group, groups) \r |
82 | { \r |
83 | #ifdef DEBUG\r |
84 | printf("%d kb/s group: %d bandwidth requested: %d kb/s\n",group->min,group->count,group->desired);\r |
85 | #endif\r |
86 | fprintf(f, "%s<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d kb/s</td>",\r |
87 | tr_odd_even(), count, group->min);\r |
88 | fprintf(f, "<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d kb/s</td>",\r |
89 | group->count, group->desired);\r |
90 | \r |
91 | for_each(keyword, keywords) if(keyword->ip_count)\r |
92 | {\r |
ca6f7e80 |
93 | fprintf(f, "<td style=\"text-align: right\"><span style=\"color:#%s\">%d MB</span></td>",\r |
94 | keyword->html_color, group->min*keyword->data_limit);\r |
9a56ab25 |
95 | } \r |
96 | i += group->desired; \r |
97 | total += group->count;\r |
98 | count++; \r |
99 | }\r |
100 | #ifdef DEBUG\r |
101 | printf("Total groups: %d Total bandwidth requested: %d kb/s\nAGGREGATION: 1/%d\n",\r |
102 | count, i, i/line);\r |
103 | #endif\r |
104 | fprintf(f,"</tr></tbody>\n\\r |
105 | <thead><tr>\n\\r |
106 | <th colspan=\"2\" style=\"text-align: left\">Line %Ld kb/s</td>",line);\r |
107 | fprintf(f,"<th style=\"text-align: right\">%d</td><th style=\"text-align: right\">%d kb/s</td>",total,i);\r |
108 | \r |
109 | for_each(keyword, keywords) if(keyword->ip_count)\r |
110 | {\r |
111 | fprintf(f,"<th style=\"text-align: right\">%d IPs</th>",keyword->ip_count);\r |
112 | }\r |
113 | fprintf(f,"</tr><tr><th colspan=\"4\">Aggregation 1/%d</th>\n", (int)(0.5+i/line));\r |
114 | fprintf(f,"<th colspan=\"%d\">%d traffic classes</th></tr>\n", keywordcount, total);\r |
115 | \r |
116 | fputs("</thead></table>\n",f);\r |
117 | }\r |
118 | else\r |
119 | {\r |
120 | perror(html);\r |
121 | }\r |
122 | \r |
123 | i=0;\r |
124 | if(f > 0)\r |
125 | {\r |
b1a5c883 |
126 | unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum = 0;\r |
127 | int active_classes = 0;\r |
128 | int colspan = 12;\r |
129 | struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums = NULL;\r |
130 | int limit_count = 0, prio_count = 0;\r |
131 | int popup_button = 0;\r |
132 | /* IPv6 vs. IPv4 stats */\r |
133 | unsigned long long pkts4 =0, pkts6 = 0, bytes4 = 0, bytes6 = 0;\r |
134 | int count4 = 0, count6 = 0;\r |
135 | double perc6;\r |
9a56ab25 |
136 | \r |
137 | if(qos_proxy)\r |
138 | {\r |
139 | colspan++;\r |
140 | }\r |
141 | \r |
142 | fprintf(f,"<p><table class=\"decorated last\">\n<caption>%s",title);\r |
143 | fprintf(f," (%s)</caption>\n", d);\r |
144 | fputs("<thead><tr>\n<th colspan=\"3\"> </th>\n",f);\r |
145 | fputs("<th style=\"text-align: right\">credit</th>\n\\r |
146 | <th style=\"text-align: right\">FUP</th>\n\\r |
147 | <th style=\"text-align: right\">total</th>\n\\r |
148 | <th style=\"text-align: right\">down</th>\n",f);\r |
149 | if(qos_proxy)\r |
150 | {\r |
151 | fputs("<th style=\"text-align: right\">proxy</th>\n",f);\r |
152 | }\r |
153 | fputs("<th style=\"text-align: right\">up</th>\n\\r |
154 | <th style=\"text-align: right\">min</th>\n\\r |
155 | <th style=\"text-align: right\">max</th>\n\\r |
156 | <th style=\"text-align: right\">limit</th>\n\\r |
157 | <th> </th>\n\\r |
158 | </tr><tr>\n\\r |
159 | <th style=\"text-align: right\">#</th>\n\\r |
160 | <th>hostname [+sharing]</th>\n\\r |
161 | <th style=\"text-align: right\">LMS</th>\n\\r |
162 | <th style=\"text-align: right\">MB</th>\n\\r |
163 | <th style=\"text-align: right\">MB</th>\n\\r |
164 | <th style=\"text-align: right\">MB</th>\n\\r |
165 | <th style=\"text-align: right\">MB</th>\n\\r |
166 | <th style=\"text-align: right\">MB</th>\n\\r |
167 | <th style=\"text-align: right\">kb/s</th>\n\\r |
168 | <th style=\"text-align: right\">kb/s</th>\n\\r |
169 | <th style=\"text-align: right\">kb/s</th>\n\\r |
170 | <th>prio</th>\n\\r |
171 | </tr></thead><tbody>\n",f); \r |
172 | \r |
173 | row_odd_even = 0;\r |
174 | for_each(ip,ips) if(!use_jquery_popups || !ip->sharing)\r |
175 | {\r |
176 | char *f1="", *f2="";\r |
177 | i++;\r |
178 | \r |
179 | if(ip->max < ip->desired) \r |
ca6f7e80 |
180 | {\r |
181 | f1 = "<span style=\"color:red\">";\r |
9a56ab25 |
182 | f2 = "</span>"; \r |
183 | limit_count++; \r |
ca6f7e80 |
184 | }\r |
185 | else if(ip->prio > highest_priority+1)\r |
186 | {\r |
187 | f1 = "<span style=\"color:brown\">";\r |
188 | f2 = "</span>";\r |
9a56ab25 |
189 | prio_count++; \r |
190 | } \r |
191 | \r |
192 | #ifdef DEBUG\r |
193 | printf("%03d. %-22s %10Lu (%d/%d)\n",i ,ip->name, ip->traffic, ip->min, ip->max); \r |
194 | #endif\r |
195 | /* hostnames -------------------------------------- */\r |
196 | fprintf(f,"%s<td style=\"text-align: right\"><a name=\"%s\"></a>%d</td><td><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n", \r |
197 | tr_odd_even(), ip->name, i, log_url, ip->name, ip->name);\r |
198 | \r |
199 | if(use_jquery_popups)\r |
200 | {\r |
ca6f7e80 |
201 | fprintf(f, "<span id=\"sharing_%d\" style=\"display:none\">",i);\r |
9a56ab25 |
202 | popup_button=0;\r |
ca6f7e80 |
203 | \r |
0b9c3c19 |
204 | for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r |
9a56ab25 |
205 | {\r |
ca6f7e80 |
206 | fprintf(f, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n", \r |
207 | log_url, sharedip->name, sharedip->name);\r |
9a56ab25 |
208 | popup_button++;\r |
209 | }\r |
ca6f7e80 |
210 | \r |
0b9c3c19 |
211 | for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r |
f64d5431 |
212 | {\r |
ca6f7e80 |
213 | fprintf(f, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s/64</a>\n", \r |
214 | log_url, sharedip->addr, sharedip->addr);\r |
f64d5431 |
215 | popup_button++;\r |
216 | }\r |
ca6f7e80 |
217 | \r |
9a56ab25 |
218 | fputs("</span>\n",f);\r |
219 | if(popup_button)\r |
220 | {\r |
ca6f7e80 |
221 | fprintf(f, "<span>[<a class=\"blue\" href=\"#\" onClick=\"$(this).parent().hide();$(\'#sharing_%d\').show();$(\'#download_%d\').show();$(\'#upload_%d\').show();return(false);\" style=\"cursor: pointer;\">+%d</a>]</span>",\r |
222 | i, i, i, popup_button);\r |
9a56ab25 |
223 | }\r |
224 | }\r |
225 | fputs("</td>\n",f);\r |
226 | /* ----------------------------------------------- */\r |
227 | \r |
228 | if(found_lmsid)\r |
229 | {\r |
230 | fputs("<td style=\"text-align: right\">",f);\r |
231 | if(ip->lmsid > 0)\r |
232 | {\r |
233 | fprintf(f,"<a class=\"blue\" target=\"_blank\" href=\"%s%d\">%04d</a>\n", lms_url, ip->lmsid, ip->lmsid);\r |
234 | }\r |
235 | else if(ip->lmsid == 0)\r |
236 | {\r |
237 | fputs("-------",f);\r |
238 | }\r |
239 | fputs("</td>\n",f);\r |
240 | }\r |
241 | fprintf(f,"<td style=\"text-align: right\">%Lu</td>\n", ip->credit);\r |
242 | fprintf(f,"<td style=\"text-align: right\"><span style=\"color:#%s\">%Lu</span></td>",\r |
e48d46c9 |
243 | ip->keyword->html_color, ip->realquota);\r |
9a56ab25 |
244 | fprintf(f,"<td style=\"text-align: right\">%s%Lu%s", f1, ip->traffic, f2);\r |
245 | \r |
246 | /* download --------------------------------------- */\r |
247 | fprintf(f,"</td><td style=\"text-align: right\">%Lu", ip->direct);\r |
248 | if(use_jquery_popups)\r |
249 | {\r |
ca6f7e80 |
250 | fprintf(f,"<span id=\"download_%d\" style=\"display:none\">", i);\r |
0b9c3c19 |
251 | for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r |
f64d5431 |
252 | {\r |
253 | fprintf(f,"<br />%Lu", sharedip->direct);\r |
254 | }\r |
0b9c3c19 |
255 | for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r |
9a56ab25 |
256 | {\r |
257 | fprintf(f,"<br />%Lu", sharedip->direct);\r |
258 | }\r |
259 | fputs("</span>\n",f);\r |
260 | }\r |
261 | fputs("</td>\n",f);\r |
262 | /* ----------------------------------------------- */\r |
263 | \r |
264 | if(qos_proxy)\r |
265 | {\r |
266 | fprintf(f,"<td style=\"text-align: right\">%Lu</td>\n", ip->proxy);\r |
267 | }\r |
268 | /* upload ---------------------------------------- */\r |
269 | fprintf(f,"<td style=\"text-align: right\">%Lu", ip->upload);\r |
270 | if(use_jquery_popups)\r |
271 | {\r |
ca6f7e80 |
272 | fprintf(f,"<span id=\"upload_%d\" style=\"display:none\">", i);\r |
0b9c3c19 |
273 | for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r |
f64d5431 |
274 | {\r |
275 | fprintf(f,"<br />%Lu", sharedip->upload);\r |
276 | }\r |
0b9c3c19 |
277 | for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r |
9a56ab25 |
278 | {\r |
279 | fprintf(f,"<br />%Lu", sharedip->upload);\r |
280 | }\r |
281 | fputs("</span>\n",f);\r |
282 | }\r |
283 | fputs("</td>\n",f);\r |
284 | /* ----------------------------------------------- */\r |
285 | \r |
b1a5c883 |
286 | fprintf(f, "<td style=\"text-align: right\">%d</td>\n\\r |
9a56ab25 |
287 | <td style=\"text-align: right\">%d</td>\n\\r |
288 | <td style=\"text-align: right\">%s%d%s</td>\n\\r |
289 | <td>%s%d%s</td></tr>\n",\r |
b1a5c883 |
290 | ip->min, ip->desired, \r |
291 | f1, ip->max, f2, \r |
292 | f1, ip->prio, f2);\r |
9a56ab25 |
293 | \r |
294 | total_traffic+=ip->traffic;\r |
295 | total_direct+=ip->direct;\r |
296 | total_proxy+=ip->proxy;\r |
297 | total_upload+=ip->upload;\r |
298 | if(ip->traffic>0)\r |
299 | {\r |
300 | active_classes++;\r |
301 | tmp_sum+=ip->traffic;\r |
302 | create(sum,Sum);\r |
303 | sum->l=tmp_sum;\r |
304 | sum->i=active_classes;\r |
305 | insert(sum,sums,order_by,i);\r |
306 | }\r |
307 | \r |
308 | if(!just_preview)\r |
309 | {\r |
310 | append_log(ip);\r |
311 | for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing))\r |
312 | {\r |
313 | append_log(sharedip);\r |
314 | }\r |
315 | }\r |
316 | }\r |
317 | fprintf(f,"</tbody><thead><tr>\n\\r |
318 | <th colspan=\"%d\" style=\"text-align: left\">%d CLASSES</th>", colspan-7, i);\r |
b1a5c883 |
319 | fprintf(f, "<th style=\"text-align: right\">%Lu</th><th style=\"text-align: right\">%Lu</th>\n", \r |
320 | total_traffic, total_direct);\r |
9a56ab25 |
321 | if(qos_proxy)\r |
322 | {\r |
b1a5c883 |
323 | fprintf(f," <th style=\"text-align: right\">%Lu</th>\n", total_proxy);\r |
9a56ab25 |
324 | }\r |
b1a5c883 |
325 | fprintf(f, "<th style=\"text-align: right\">%Lu</th>", total_upload);\r |
326 | fprintf(f, "<th colspan=\"4\"><span style=\"color:red\">LIMIT %dx</span> <span style=\"color:brown\">LOW-PRIO %dx</span></th></tr>\n</thead></table>\n",\r |
327 | limit_count, prio_count);\r |
9a56ab25 |
328 | \r |
ca6f7e80 |
329 | if(ip6prefix)\r |
330 | {\r |
b1a5c883 |
331 | \r |
ca6f7e80 |
332 | for_each(ip, ips)\r |
333 | { \r |
334 | if(ip->v6)\r |
335 | {\r |
336 | bytes6 += ip->traffic;\r |
337 | pkts6 += ip->pktsdown+ip->pktsup;\r |
b1a5c883 |
338 | count6++;\r |
ca6f7e80 |
339 | }\r |
340 | else\r |
341 | {\r |
342 | bytes4 += ip->traffic;\r |
343 | pkts4 += ip->pktsdown+ip->pktsup;\r |
b1a5c883 |
344 | count4++;\r |
ca6f7e80 |
345 | }\r |
346 | }\r |
b1a5c883 |
347 | perc6=(double)(100*bytes6)/(bytes4+bytes6);\r |
ca6f7e80 |
348 | \r |
349 | fputs("<p><table class=\"decorated last\"><caption>IP protocols usage</caption>\n",f);\r |
b1a5c883 |
350 | fprintf(f, "%s<td>Total %d IPv4 (addreses)</td><td style=\"text-align: right\">%Lu MB (%.2f %%)</td><td style=\"text-align: right\">%Lu packets (%.2f %%)</td></tr>\n",\r |
351 | tr_odd_even(), count4, bytes4, (double)(100*bytes4)/(bytes4+bytes6), pkts4, (float)(100*pkts4)/(pkts4+pkts6));\r |
352 | fprintf(f, "%s<td>Total %d IPv6 (/64 ranges)</td><td style=\"text-align: right\">%Lu MB (%.2f %%)</td><td style=\"text-align: right\">%Lu packets (%.2f %%)</td></tr>\n",\r |
353 | tr_odd_even(), count6, bytes6, perc6, pkts6, (float)(100*pkts6)/(pkts4+pkts6));\r |
354 | fputs("</table></p>\n", f);\r |
ca6f7e80 |
355 | }\r |
356 | \r |
9a56ab25 |
357 | row_odd_even = 0;\r |
358 | if(active_classes>10)\r |
359 | {\r |
360 | int top20_count=0,top20_perc1=0;\r |
361 | long long top20_perc2=0;\r |
362 | unsigned long long top20_sum=0l;\r |
363 | \r |
364 | fputs("<a name=\"erp\"></a><p><table class=\"decorated last\"><caption>Enterprise Resource Planning (ERP)</caption>\n",f);\r |
365 | fputs("<thead><tr>\n\\r |
366 | <th>Analytic category</th>\n\\r |
367 | <th colspan=\"2\" style=\"text-align: center\">Active Classes</th>\n\\r |
368 | <th colspan=\"2\" style=\"text-align: center\">Data transfers</th>\n\\r |
369 | </tr></thead><tbody>\n",f);\r |
370 | \r |
b1a5c883 |
371 | if_exists(sum,sums,sum->l >= total_traffic/4)\r |
9a56ab25 |
372 | {\r |
373 | fprintf(f,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());\r |
374 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
375 | <td style=\"text-align: right\">%d %%</td>\n\\r |
376 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
377 | <td style=\"text-align: right\">%Ld %%</td></tr>\n",\r |
378 | sum->i, (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic);\r |
379 | }\r |
380 | \r |
b1a5c883 |
381 | if_exists(sum,sums,sum->i == 10)\r |
9a56ab25 |
382 | {\r |
383 | fprintf(f,"%s<td>Top 10 downloaders</td>\n", tr_odd_even());\r |
384 | fprintf(f,"<td style=\"text-align: right\"><strong>10</strong></td>\n\\r |
385 | <td style=\"text-align: right\">%d %%</td>\n\\r |
386 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
387 | <td style=\"text-align: right\">%Ld %%</td></tr>\n",\r |
388 | (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic);\r |
389 | }\r |
390 | \r |
b1a5c883 |
391 | if_exists(sum,sums,sum->l >= total_traffic/2)\r |
9a56ab25 |
392 | {\r |
393 | fprintf(f,"%s<td>Top 50%% of traffic</td>\n", tr_odd_even());\r |
394 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
395 | <td style=\"text-align: right\">%d %%</td>\n\\r |
396 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
397 | <td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",\r |
398 | sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r |
399 | }\r |
400 | \r |
b1a5c883 |
401 | if_exists(sum,sums,sum->l >= 4*total_traffic/5)\r |
9a56ab25 |
402 | {\r |
403 | fprintf(f,"%s<td>Top 80%% of traffic</td>\n", tr_odd_even());\r |
404 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
405 | <td style=\"text-align: right\">%d %%</td>\n\\r |
406 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
407 | <td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",\r |
408 | sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r |
409 | }\r |
410 | \r |
b1a5c883 |
411 | if_exists(sum,sums,sum->i >= (active_classes+1)/5)\r |
9a56ab25 |
412 | {\r |
413 | fprintf(f,"%s<td>Top 20%% downloaders</td>\n", tr_odd_even());\r |
414 | top20_count=sum->i;\r |
415 | top20_perc1=(100*sum->i+50)/active_classes;\r |
416 | top20_sum=sum->l;\r |
417 | top20_perc2=(100*sum->l+50)/total_traffic;\r |
418 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
419 | <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r |
420 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
421 | <td style=\"text-align: right\">%Ld %%</td></tr>\n",\r |
422 | top20_count,top20_perc1,top20_sum,top20_perc2);\r |
423 | }\r |
424 | \r |
b1a5c883 |
425 | if_exists(sum,sums,sum->i >= (active_classes+1)/4)\r |
9a56ab25 |
426 | {\r |
427 | fprintf(f,"%s<td>Top 25%% downloaders</td>\n", tr_odd_even());\r |
428 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
429 | <td style=\"text-align: right\">%d %%</td>\n\\r |
430 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
431 | <td style=\"text-align: right\">%Ld %%</td></tr>\n",\r |
432 | sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r |
433 | }\r |
434 | \r |
435 | if_exists(sum,sums,sum->i>=(active_classes+1)/2)\r |
436 | {\r |
437 | fprintf(f,"%s<td>Top 50%% downloaders</td>\n", tr_odd_even());\r |
438 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
439 | <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r |
440 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
441 | <td style=\"text-align: right\">%Ld %%</td></tr>\n",\r |
442 | sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r |
443 | }\r |
444 | \r |
b1a5c883 |
445 | if_exists(sum,sums,sum->i >= 4*(active_classes+1)/5)\r |
9a56ab25 |
446 | {\r |
447 | fprintf(f,"%s<td>Top 80%% downloaders</td>\n", tr_odd_even());\r |
448 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
449 | <td style=\"text-align: right\">%d %%</td>\n\\r |
450 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
451 | <td style=\"text-align: right\">%Ld %%</td></tr></tbody>\n",\r |
452 | sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r |
453 | }\r |
454 | \r |
455 | fprintf(f,"<thead><tr><th><a class=\"blue\" target=\"_blank\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url);\r |
456 | fprintf(f,"<th style=\"text-align: right\">%d</th>\n\\r |
457 | <th style=\"text-align: right\">100 %%</th>\n\\r |
458 | <th style=\"text-align: right\">%Lu MB</th>\n\\r |
459 | <th style=\"text-align: right\">100 %%</th></tr>\n",active_classes,total_traffic);\r |
b1a5c883 |
460 | fputs("</thead></table></p>\n", f);\r |
9a56ab25 |
461 | \r |
462 | /* write basic ERP data to log directory */\r |
463 | if(!just_preview)\r |
464 | {\r |
465 | FILE *iplog;\r |
466 | sprintf(str,"%s/ERP.log",log_dir);\r |
467 | iplog=fopen(str,"a");\r |
468 | if(iplog)\r |
469 | {\r |
b1a5c883 |
470 | fprintf(iplog, "%ld\t%d\t%d %%\t%Lu M\t%Ld %%\tACTIVE %d\tTRAFFIC %Lu M\tCLASSES %d\tFUP-LIMIT %d\tLOW-PRIO %d\tIPv6 %Lu\t%.2f %%\t%s",\r |
471 | time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, \r |
472 | active_classes, total_traffic, i, limit_count, prio_count,\r |
473 | bytes6, perc6, d); /* d = date*/\r |
9a56ab25 |
474 | fclose(iplog);\r |
475 | }\r |
476 | else\r |
477 | {\r |
478 | perror(str);\r |
479 | }\r |
480 | }\r |
481 | }\r |
482 | \r |
483 | fprintf(f, stats_html_signature, version);\r |
484 | fclose(f);\r |
485 | }\r |
486 | } |