MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
General Public License for more details.\r
\r
- You should have received a copy of the GNU General Public License
- along with Prometheus Qos; if not, write to the Free Software
+ You should have received a copy of the GNU General Public License\r
+ along with Prometheus Qos; if not, write to the Free Software\r
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA \r
\r
- GNU General Public License is located in file COPYING */
+ GNU General Public License is located in file COPYING */\r
\r
#define STRLEN 256\r
#define FIRSTGROUPID 1024\r
return NULL;\r
}\r
\r
-struct IpLog
-{
- char *name;
- long traffic;
- list(IpLog);
-} *iplog,*iplogs;
-
-void parse_ip_log(int argc, char **argv)
-{
- char *month,*year,*str,*name,*ptr,*ptr2;
- long traffic,traffic_month,total=0;
+struct IpLog\r
+{\r
+ char *name;\r
+ long traffic;\r
+ list(IpLog);\r
+} *iplog,*iplogs;\r
+\r
+void parse_ip_log(int argc, char **argv) \r
+{\r
+ char *month,*year,*str,*name,*ptr,*ptr2;\r
+ long traffic,traffic_month,total=0;\r
int col,col2,y_ok,m_ok,accept_month,i=1,any_month=0;\r
- char mstr[4],ystr[5];
- FILE *f;
-
- string(str,STRLEN);
-
+ char mstr[4],ystr[5];\r
+ FILE *f;\r
+ \r
+ string(str,STRLEN);\r
+\r
if(argv[1][1]=='l') /* -l */\r
{\r
- if(argc<4)
- {
- puts("Missing parameter(s)!\nUsage: prometheus -l Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)");
- exit(-1);
- }
- else
- {
- month=argv[2];
- if(eq(month,"Year")) any_month=1;
- year=argv[3];
+ if(argc<4)\r
+ {\r
+ puts("Missing parameter(s)!\nUsage: prometheus -l Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)");\r
+ exit(-1);\r
+ }\r
+ else\r
+ {\r
+ month=argv[2];\r
+ if(eq(month,"Year")) any_month=1;\r
+ year=argv[3];\r
}\r
}\r
else\r
}\r
}\r
printf("Analysing traffic for %s %s ...\n",month,year);\r
-
- sprintf(str,"%s %s/*.log",ls,log_dir);
- shell(str);
- input(str,STRLEN)
- {
- ptr=strrchr(str,'\n');
- if(ptr) *ptr='\0';
- printf("Parsing %s ...",str);
- accept_month=0;
- traffic_month=0;
- parse(str)
- {
- y_ok=m_ok=0;
- valid_columns(ptr,_,'\t',col) switch(col)
- {
- case 2: name=ptr;break;
- case 3: traffic=atol(ptr);break;
- case 7: valid_columns(ptr2,ptr,' ',col2) switch(col2)
- {
- case 2: if(any_month || eq(ptr2,month)) m_ok=1; break;
- case 5: if(eq(ptr2,year)) y_ok=1; break;
- }
- }
- if(y_ok && m_ok)
- {
- traffic_month+=traffic;
- accept_month=1;
- }
- }
- done;
- if(accept_month)
- {
- create(iplog,IpLog);
- iplog->name=name;
- iplog->traffic=traffic_month;
- insert(iplog,iplogs,desc_order_by,traffic);
- printf(" %ld MB\n",iplog->traffic);
- }
- else
- puts(" no records.");
- }
- sprintf(str,"%s/%s-%s.html",html_log_dir,year,month);
- printf("Writing %s ...",str);
- f=fopen(str,"w");
- if(f)
- {
- fprintf(f,"<table border><tr><th colspan=\"4\">Data transfers - %s %s</th></tr>\n ",month,year);
- every(iplog,iplogs)
- if(iplog->traffic)
- {
- fprintf(f,"<tr><td align=\"right\">%d</td><th>%s</td><td align=\"right\">%ld MB</td><th align=\"right\">%ld GB</th></tr>\n",i++,iplog->name,iplog->traffic,iplog->traffic>>10);
- total+=iplog->traffic>>10;
- }
- fprintf(f,"<tr><th colspan=\"3\" align=\"left\">Total:</th><th align=\"right\">%ld GB</th></tr>\n",total);
- fputs("</table>\n",f);
- fclose(f);
- puts(" done.");
- }
-}
+\r
+ sprintf(str,"%s %s/*.log",ls,log_dir);\r
+ shell(str);\r
+ input(str,STRLEN)\r
+ {\r
+ ptr=strrchr(str,'\n');\r
+ if(ptr) *ptr='\0';\r
+ printf("Parsing %s ...",str);\r
+ accept_month=0;\r
+ traffic_month=0;\r
+ parse(str)\r
+ {\r
+ y_ok=m_ok=0; \r
+ valid_columns(ptr,_,'\t',col) switch(col)\r
+ {\r
+ case 2: name=ptr;break;\r
+ case 3: traffic=atol(ptr);break;\r
+ case 7: valid_columns(ptr2,ptr,' ',col2) switch(col2)\r
+ {\r
+ case 2: if(any_month || eq(ptr2,month)) m_ok=1; break;\r
+ case 5: if(eq(ptr2,year)) y_ok=1; break;\r
+ }\r
+ }\r
+ if(y_ok && m_ok) \r
+ {\r
+ traffic_month+=traffic;\r
+ accept_month=1;\r
+ }\r
+ }\r
+ done;\r
+ if(accept_month)\r
+ {\r
+ create(iplog,IpLog);\r
+ iplog->name=name;\r
+ iplog->traffic=traffic_month;\r
+ insert(iplog,iplogs,desc_order_by,traffic);\r
+ printf(" %ld MB\n",iplog->traffic);\r
+ }\r
+ else\r
+ puts(" no records.");\r
+ }\r
+ sprintf(str,"%s/%s-%s.html",html_log_dir,year,month);\r
+ printf("Writing %s ...",str);\r
+ f=fopen(str,"w");\r
+ if(f)\r
+ {\r
+ fprintf(f,"<table border><tr><th colspan=\"4\">Data transfers - %s %s</th></tr>\n ",month,year);\r
+ every(iplog,iplogs)\r
+ if(iplog->traffic)\r
+ {\r
+ fprintf(f,"<tr><td align=\"right\">%d</td><th>%s</td><td align=\"right\">%ld MB</td><th align=\"right\">%ld GB</th></tr>\n",i++,iplog->name,iplog->traffic,iplog->traffic>>10);\r
+ total+=iplog->traffic>>10;\r
+ }\r
+ fprintf(f,"<tr><th colspan=\"3\" align=\"left\">Total:</th><th align=\"right\">%ld GB</th></tr>\n",total);\r
+ fputs("</table>\n",f);\r
+ fclose(f);\r
+ puts(" done.");\r
+ }\r
+}\r
\r
\r
/*-----------------------------------------------------------------*/\r
argument("-9") { just_flush=9; }\r
argument("-p") { just_preview=1; }\r
argument("-n") { nodelay=1; }\r
- argument("-l") { parse_ip_log(argc,argv); exit(0); }\r
- argument("-m") { parse_ip_log(argc,argv); exit(0); }\r
- argument("-y") { parse_ip_log(argc,argv); exit(0); }\r
+ argument("-l") { just_preview=666; }\r
+ argument("-m") { just_preview=666; }\r
+ argument("-y") { just_preview=666; }\r
argument("-?") { help(); exit(0); }\r
argument("--help") { help(); exit(0); }\r
argument("-v") { exit(0); } \r
printf("Parsing configuration file %s ...\n", config);\r
/*-----------------------------------------------------------------*/\r
get_config(config);\r
+ \r
+ if(just_preview == 666)\r
+ {\r
+ parse_ip_log(argc,argv); \r
+ exit(0); \r
+ }\r
\r
if(althosts) hosts=althosts;\r
\r
fputs("<td colspan=\"4\"></td></th>\n</table>\n",f);\r
\r
if(active_classes>10)\r
- {
- fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"5\">Enterprise Research and Planning (ERP)</th></tr>\n",f);
- fputs("<tr><td>Analytic category</td>\n",f);
- fputs("<td colspan=\"2\" align=\"center\">Active Classes</td><td colspan=\"2\" align=\"center\">Data transfers</td></tr>\n",f);
-
- find(sum,sums,sum->l>=total/4)
- {
- fprintf(f,"<tr><td>Top 25%% of traffic</td>\n");
- fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);
- }
-
- find(sum,sums,sum->i==10)
- {
- fprintf(f,"<tr><td>Top 10 downloaders</td>\n");
- fprintf(f,"<th align=\"right\">10</th><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);
- }
-
- find(sum,sums,sum->l>=total/2)
- {
- fprintf(f,"<tr><td>Top 50%% of traffic</td>\n");
- fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><th align=\"right\">%Ld %%</th></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);
- }
-
- find(sum,sums,sum->l>=4*total/5)
- {
- fprintf(f,"<tr><td>Top 80%% of traffic</td>\n");
- fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><th align=\"right\">%Ld %%</th></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);
- }
-
- find (sum,sums,sum->i>=(active_classes+1)/5)
- {
- fprintf(f,"<tr><td>Top 20%% downloaders</td>\n");
- fprintf(f,"<td align=\"right\">%d</td><th align=\"right\">%d %%</th><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);
- }
-
- find(sum,sums,sum->i>=(active_classes+1)/4)
- {
- fprintf(f,"<tr><td>Top 25%% downloaders</td>\n");
- fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);
- }
-
- find(sum,sums,sum->i>=(active_classes+1)/2)
- {
- fprintf(f,"<tr><td>Top 50%% downloaders</td>\n");
- fprintf(f,"<td align=\"right\">%d</td><th align=\"right\">%d %%</th><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);
- }
-
- find(sum,sums,sum->i>=4*(active_classes+1)/5)
- {
- fprintf(f,"<tr><td>Top 80%% downloaders</td>\n");
- fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);
- }
-
- fprintf(f,"<tr><td>All users, all traffic</td>\n");
- fprintf(f,"<th align=\"right\">%d</th><th align=\"right\">100 %%</th><th align=\"right\">%Lu M</th><th align=\"right\">100 %%</th></tr>\n",active_classes,total);
- fputs("</table>\n",f);
- }
+ {\r
+ fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"5\">Enterprise Research and Planning (ERP)</th></tr>\n",f);\r
+ fputs("<tr><td>Analytic category</td>\n",f);\r
+ fputs("<td colspan=\"2\" align=\"center\">Active Classes</td><td colspan=\"2\" align=\"center\">Data transfers</td></tr>\n",f);\r
+\r
+ find(sum,sums,sum->l>=total/4)\r
+ {\r
+ fprintf(f,"<tr><td>Top 25%% of traffic</td>\n");\r
+ fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+ }\r
+ \r
+ find(sum,sums,sum->i==10)\r
+ {\r
+ fprintf(f,"<tr><td>Top 10 downloaders</td>\n");\r
+ fprintf(f,"<th align=\"right\">10</th><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+ }\r
+\r
+ find(sum,sums,sum->l>=total/2)\r
+ {\r
+ fprintf(f,"<tr><td>Top 50%% of traffic</td>\n");\r
+ fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><th align=\"right\">%Ld %%</th></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+ }\r
+\r
+ find(sum,sums,sum->l>=4*total/5)\r
+ {\r
+ fprintf(f,"<tr><td>Top 80%% of traffic</td>\n");\r
+ fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><th align=\"right\">%Ld %%</th></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+ }\r
+\r
+ find (sum,sums,sum->i>=(active_classes+1)/5)\r
+ {\r
+ fprintf(f,"<tr><td>Top 20%% downloaders</td>\n");\r
+ fprintf(f,"<td align=\"right\">%d</td><th align=\"right\">%d %%</th><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+ }\r
+\r
+ find(sum,sums,sum->i>=(active_classes+1)/4)\r
+ {\r
+ fprintf(f,"<tr><td>Top 25%% downloaders</td>\n");\r
+ fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+ }\r
+\r
+ find(sum,sums,sum->i>=(active_classes+1)/2)\r
+ {\r
+ fprintf(f,"<tr><td>Top 50%% downloaders</td>\n");\r
+ fprintf(f,"<td align=\"right\">%d</td><th align=\"right\">%d %%</th><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+ }\r
+\r
+ find(sum,sums,sum->i>=4*(active_classes+1)/5)\r
+ {\r
+ fprintf(f,"<tr><td>Top 80%% downloaders</td>\n");\r
+ fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+ }\r
+\r
+ fprintf(f,"<tr><td>All users, all traffic</td>\n");\r
+ fprintf(f,"<th align=\"right\">%d</th><th align=\"right\">100 %%</th><th align=\"right\">%Lu M</th><th align=\"right\">100 %%</th></tr>\n",active_classes,total);\r
+ fputs("</table>\n",f);\r
+ }\r
fprintf(f,"<small>Statistics generated by Prometheus QoS version %s<br>GPL+Copyright(C)2005-2008 Michael Polak, <a href=\"http://www.arachne.cz/\">Arachne Labs</a></small>\n",version);\r
fclose(f);\r
}\r
\r
if(qos_proxy)\r
{\r
- sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j MARK --set-mark 3",chain_postrouting,proxy_ip,proxy_port,lan);\r
+ sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j %s%d",chain_postrouting,proxy_ip,proxy_port,lan,mark_iptables,3);\r
save_line(str);\r
sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j ACCEPT",chain_postrouting,proxy_ip,proxy_port,lan);\r
save_line(str);\r
}\r
- sprintf(str,"-A %s -o %s -j MARK --set-mark 3",chain_postrouting,lan);\r
+ sprintf(str,"-A %s -o %s -j %s%d",chain_postrouting,lan,mark_iptables,3);\r
save_line(str);\r
sprintf(str,"-A %s -o %s -j ACCEPT",chain_postrouting,lan);\r
save_line(str);\r
\r
/* -------------------------------------------------------- mark upload */\r
- sprintf(str,"-A %s -o %s -j MARK --set-mark 3",chain_forward,wan);\r
+ sprintf(str,"-A %s -o %s -j %s%d",chain_forward,wan,mark_iptables,3);\r
save_line(str);\r
sprintf(str,"-A %s -o %s -j ACCEPT",chain_forward,wan);\r
save_line(str);\r