2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
26 #include "include/conf.h"
28 void getdata(char *, FILE *);
29 void datashow(char *);
36 char ouser
[MAXLEN
]="";
40 realtime(int argc
, char *argv
[])
50 char template1
[255]="/var/tmp/sargtpl1.XXXXXX";
51 char template2
[255]="/var/tmp/sargtpl2.XXXXXX";
56 fd1
= mkstemp(template1
);
57 fd2
= mkstemp(template2
);
59 if((fd1
== -1 ) || ((tmp
= fdopen (fd1
, "w+" )) == NULL
) ) { /* failure, bail out */
60 fprintf(stderr
, "SARG: (realtime) mkstemp error - %s\n",strerror(errno
));
64 sprintf(cmd
,"tail -%d %s",realtime_access_log_lines
,AccessLog
);
66 while(fgets(buf
,sizeof(buf
),fp
) != NULL
)
71 sprintf(cmd
,"sort -k 4,4 -k 5,5 -o %s %s",template2
,template1
);
77 void getdata(char *rec
, FILE *ftmp
)
82 getword3(dat
,rec
,' ');
83 getword3(warea
,rec
,' ');
84 while(strcmp(warea
,"") == 0 && strlen(rec
) > 0)
85 getword3(warea
,rec
,' ');
87 getword3(warea
,rec
,' ');
88 getword3(warea
,rec
,' ');
89 getword3(typ
,rec
,' ');
90 if(strncmp(typ
,"CONNECT",7) == 0) {
91 getword3(url
,rec
,' ');
92 getword3(user
,rec
,' ');
94 getword3(url
,rec
,'/');
95 getword3(url
,rec
,'/');
96 getword3(url
,rec
,'/');
97 getword3(user
,rec
,' ');
98 getword3(user
,rec
,' ');
101 if(strncmp(user
,"-",1) == 0 && strcmp(RealtimeUnauthRec
,"ignore") == 0)
106 if(strncmp(DateFormat
,"u",1) == 0)
107 strftime(tbuf
, 127, "%Y-%m-%d %H:%M", t
);
108 else if(strncmp(DateFormat
,"e",1) == 0)
109 strftime(tbuf
, 127, "%d-%m-%Y %H:%M", t
);
111 sprintf(warea
,"%s %s %s %s %s\n",tbuf
,ip
,user
,url
,typ
);
115 void datashow(char *tmp
)
120 if((fin
=fopen(tmp
,"r"))==NULL
) {
121 fprintf(stderr
, "SARG: (realtime) open error %s - %s\n",tmp
,strerror(errno
));
127 while(fgets(buf
, MAXLEN
, fin
)) {
128 buf
[strlen(buf
)-1]='\0';
129 getword3(dat
,buf
,' ');
130 getword3(tim
,buf
,' ');
131 getword3(ip
,buf
,' ');
132 getword3(user
,buf
,' ');
133 if(strlen(dat
) < 3 || strlen(user
) < 1) continue;
134 getword3(url
,buf
,' ');
135 getword3(typ
,buf
,' ');
136 if(strstr(RealtimeTypes
,typ
) == 0)
139 if(strcmp(ouser
,user
) == 0 && strcmp(ourl
,url
) == 0)
142 printf("<tr><td class=\"data\">%s %s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data2\"><a href=\"http://%s\">%s</td></tr>\n",dat
,tim
,ip
,user
,typ
,url
,url
);
147 puts("</table>\n</html>\n");
156 puts("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"");
157 puts(" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
161 printf(" <meta http-equiv=refresh content=\"%d\" url=\"sarg-php/sarg-realtime.php\"; charset=\"%s\">\n",realtime_refresh
,CharSet
);
163 printf(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet
);
166 printf(buf
,"<body style=\"font-family:%s;font-size:%s;background-color:%s;background-image:url(%s)\">\n",FontFace
,TitleFontSize
,BgColor
,BgImage
);
167 puts("<center><table cellpadding=\"1\" cellspacing=\"1\">\n");
168 printf("<tr><th class=\"title2\" colspan=\"10\">SARG %s</th></tr>\n",text
[134]);
169 printf("<tr><th class=\"text\" colspan=\"10\">%s: %d s</th></tr>\n",text
[136],realtime_refresh
);
170 printf("<tr><th class=\"header3\">%s</th><th class=\"header3\">%s</th><th class=\"header3\">%s</th><th class=\"header3\">%s</th><th class=\"header\">%s</th></tr>\n",text
[110],text
[111],text
[98],text
[135],text
[91]);