| 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 |
| 23 | extern char *ip6prefix;\r |
| 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 |
| 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 |
| 41 | if(f > 0)\r |
| 42 | {\r |
| 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 |
| 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 |
| 58 | FILE *f=fopen(html, "w");\r |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 180 | {\r |
| 181 | f1 = "<span style=\"color:red\">";\r |
| 182 | f2 = "</span>"; \r |
| 183 | limit_count++; \r |
| 184 | }\r |
| 185 | else if(ip->prio > highest_priority+1)\r |
| 186 | {\r |
| 187 | f1 = "<span style=\"color:brown\">";\r |
| 188 | f2 = "</span>";\r |
| 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 |
| 201 | fprintf(f, "<span id=\"sharing_%d\" style=\"display:none\">",i);\r |
| 202 | popup_button=0;\r |
| 203 | \r |
| 204 | for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r |
| 205 | {\r |
| 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 |
| 208 | popup_button++;\r |
| 209 | }\r |
| 210 | \r |
| 211 | for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r |
| 212 | {\r |
| 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 |
| 215 | popup_button++;\r |
| 216 | }\r |
| 217 | \r |
| 218 | fputs("</span>\n",f);\r |
| 219 | if(popup_button)\r |
| 220 | {\r |
| 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 |
| 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 |
| 243 | ip->keyword->html_color, ip->realquota);\r |
| 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 |
| 250 | fprintf(f,"<span id=\"download_%d\" style=\"display:none\">", i);\r |
| 251 | for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r |
| 252 | {\r |
| 253 | fprintf(f,"<br />%Lu", sharedip->direct);\r |
| 254 | }\r |
| 255 | for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r |
| 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 |
| 272 | fprintf(f,"<span id=\"upload_%d\" style=\"display:none\">", i);\r |
| 273 | for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r |
| 274 | {\r |
| 275 | fprintf(f,"<br />%Lu", sharedip->upload);\r |
| 276 | }\r |
| 277 | for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r |
| 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 |
| 286 | fprintf(f, "<td style=\"text-align: right\">%d</td>\n\\r |
| 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 |
| 290 | ip->min, ip->desired, \r |
| 291 | f1, ip->max, f2, \r |
| 292 | f1, ip->prio, f2);\r |
| 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 |
| 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 |
| 321 | if(qos_proxy)\r |
| 322 | {\r |
| 323 | fprintf(f," <th style=\"text-align: right\">%Lu</th>\n", total_proxy);\r |
| 324 | }\r |
| 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 |
| 328 | \r |
| 329 | if(ip6prefix)\r |
| 330 | { \r |
| 331 | for_each(ip, ips)\r |
| 332 | { \r |
| 333 | if(ip->v6)\r |
| 334 | {\r |
| 335 | bytes6 += ip->upload + ip->direct;\r |
| 336 | pkts6 += ip->pktsdown + ip->pktsup;\r |
| 337 | count6++;\r |
| 338 | }\r |
| 339 | else\r |
| 340 | {\r |
| 341 | bytes4 += ip->upload + ip->direct;\r |
| 342 | pkts4 += ip->pktsdown + ip->pktsup;\r |
| 343 | count4++;\r |
| 344 | }\r |
| 345 | }\r |
| 346 | \r |
| 347 | perc6=(double)(bytes6)/(bytes4+bytes6)*100;\r |
| 348 | fputs("<p><table class=\"decorated last\"><caption>IP protocols usage</caption>\n",f);\r |
| 349 | 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 |
| 350 | tr_odd_even(), count4, bytes4, (double)(bytes4)/(bytes4+bytes6)*100, pkts4, (float)(100*pkts4)/(pkts4+pkts6));\r |
| 351 | 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 |
| 352 | tr_odd_even(), count6, bytes6, perc6, pkts6, (float)(100*pkts6)/(pkts4+pkts6));\r |
| 353 | fputs("</table></p>\n", f);\r |
| 354 | }\r |
| 355 | \r |
| 356 | row_odd_even = 0;\r |
| 357 | if(active_classes>10)\r |
| 358 | {\r |
| 359 | int top20_count=0,top20_perc1=0;\r |
| 360 | long long top20_perc2=0;\r |
| 361 | unsigned long long top20_sum=0l;\r |
| 362 | \r |
| 363 | fputs("<a name=\"erp\"></a><p><table class=\"decorated last\"><caption>Enterprise Resource Planning (ERP)</caption>\n",f);\r |
| 364 | fputs("<thead><tr>\n\\r |
| 365 | <th>Analytic category</th>\n\\r |
| 366 | <th colspan=\"2\" style=\"text-align: center\">Active Classes</th>\n\\r |
| 367 | <th colspan=\"2\" style=\"text-align: center\">Data transfers</th>\n\\r |
| 368 | </tr></thead><tbody>\n",f);\r |
| 369 | \r |
| 370 | if_exists(sum,sums,sum->l >= total_traffic/4)\r |
| 371 | {\r |
| 372 | fprintf(f,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());\r |
| 373 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
| 374 | <td style=\"text-align: right\">%d %%</td>\n\\r |
| 375 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
| 376 | <td style=\"text-align: right\">%Ld %%</td></tr>\n",\r |
| 377 | sum->i, (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic);\r |
| 378 | }\r |
| 379 | \r |
| 380 | if_exists(sum,sums,sum->i == 10)\r |
| 381 | {\r |
| 382 | fprintf(f,"%s<td>Top 10 downloaders</td>\n", tr_odd_even());\r |
| 383 | fprintf(f,"<td style=\"text-align: right\"><strong>10</strong></td>\n\\r |
| 384 | <td style=\"text-align: right\">%d %%</td>\n\\r |
| 385 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
| 386 | <td style=\"text-align: right\">%Ld %%</td></tr>\n",\r |
| 387 | (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic);\r |
| 388 | }\r |
| 389 | \r |
| 390 | if_exists(sum,sums,sum->l >= total_traffic/2)\r |
| 391 | {\r |
| 392 | fprintf(f,"%s<td>Top 50%% of traffic</td>\n", tr_odd_even());\r |
| 393 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
| 394 | <td style=\"text-align: right\">%d %%</td>\n\\r |
| 395 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
| 396 | <td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",\r |
| 397 | sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r |
| 398 | }\r |
| 399 | \r |
| 400 | if_exists(sum,sums,sum->l >= 4*total_traffic/5)\r |
| 401 | {\r |
| 402 | fprintf(f,"%s<td>Top 80%% of traffic</td>\n", tr_odd_even());\r |
| 403 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
| 404 | <td style=\"text-align: right\">%d %%</td>\n\\r |
| 405 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
| 406 | <td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",\r |
| 407 | sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r |
| 408 | }\r |
| 409 | \r |
| 410 | if_exists(sum,sums,sum->i >= (active_classes+1)/5)\r |
| 411 | {\r |
| 412 | fprintf(f,"%s<td>Top 20%% downloaders</td>\n", tr_odd_even());\r |
| 413 | top20_count=sum->i;\r |
| 414 | top20_perc1=(100*sum->i+50)/active_classes;\r |
| 415 | top20_sum=sum->l;\r |
| 416 | top20_perc2=(100*sum->l+50)/total_traffic;\r |
| 417 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
| 418 | <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r |
| 419 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
| 420 | <td style=\"text-align: right\">%Ld %%</td></tr>\n",\r |
| 421 | top20_count,top20_perc1,top20_sum,top20_perc2);\r |
| 422 | }\r |
| 423 | \r |
| 424 | if_exists(sum,sums,sum->i >= (active_classes+1)/4)\r |
| 425 | {\r |
| 426 | fprintf(f,"%s<td>Top 25%% downloaders</td>\n", tr_odd_even());\r |
| 427 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
| 428 | <td style=\"text-align: right\">%d %%</td>\n\\r |
| 429 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
| 430 | <td style=\"text-align: right\">%Ld %%</td></tr>\n",\r |
| 431 | sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r |
| 432 | }\r |
| 433 | \r |
| 434 | if_exists(sum,sums,sum->i>=(active_classes+1)/2)\r |
| 435 | {\r |
| 436 | fprintf(f,"%s<td>Top 50%% downloaders</td>\n", tr_odd_even());\r |
| 437 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
| 438 | <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r |
| 439 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
| 440 | <td style=\"text-align: right\">%Ld %%</td></tr>\n",\r |
| 441 | sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r |
| 442 | }\r |
| 443 | \r |
| 444 | if_exists(sum,sums,sum->i >= 4*(active_classes+1)/5)\r |
| 445 | {\r |
| 446 | fprintf(f,"%s<td>Top 80%% downloaders</td>\n", tr_odd_even());\r |
| 447 | fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r |
| 448 | <td style=\"text-align: right\">%d %%</td>\n\\r |
| 449 | <td style=\"text-align: right\">%Lu MB</td>\n\\r |
| 450 | <td style=\"text-align: right\">%Ld %%</td></tr></tbody>\n",\r |
| 451 | sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r |
| 452 | }\r |
| 453 | \r |
| 454 | fprintf(f,"<thead><tr><th><a class=\"blue\" target=\"_blank\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url);\r |
| 455 | fprintf(f,"<th style=\"text-align: right\">%d</th>\n\\r |
| 456 | <th style=\"text-align: right\">100 %%</th>\n\\r |
| 457 | <th style=\"text-align: right\">%Lu MB</th>\n\\r |
| 458 | <th style=\"text-align: right\">100 %%</th></tr>\n",active_classes,total_traffic);\r |
| 459 | fputs("</thead></table></p>\n", f);\r |
| 460 | \r |
| 461 | /* write basic ERP data to log directory */\r |
| 462 | if(!just_preview)\r |
| 463 | {\r |
| 464 | FILE *iplog;\r |
| 465 | sprintf(str,"%s/ERP.log",log_dir);\r |
| 466 | iplog=fopen(str,"a");\r |
| 467 | if(iplog)\r |
| 468 | {\r |
| 469 | 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 M\t%.2f %%\t%s",\r |
| 470 | time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, \r |
| 471 | active_classes, total_traffic, i, limit_count, prio_count,\r |
| 472 | bytes6, perc6, d); /* d = date*/\r |
| 473 | fclose(iplog);\r |
| 474 | }\r |
| 475 | else\r |
| 476 | {\r |
| 477 | perror(str);\r |
| 478 | }\r |
| 479 | }\r |
| 480 | }\r |
| 481 | \r |
| 482 | fprintf(f, stats_html_signature, version);\r |
| 483 | fclose(f);\r |
| 484 | }\r |
| 485 | } |