]>
git.ipfire.org Git - thirdparty/sarg.git/blob - index.c
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"
31 FILE *fp_ou
, *fp_tmp
, *tp_tmp2
;
33 struct dirent
*direntp
;
36 char wdir_tmp
[MAXLEN
];
37 char wdir_tmp2
[MAXLEN
];
46 char day
[4], mon
[4], year
[6], hour
[10];
47 char h
[3], m
[3], s
[3];
49 if(LastLog
[0] != '\0')
50 mklastlog(outdir
,debug
);
52 sprintf(wdir
,"%sindex.html",outdir
);
53 sprintf(wdir_tmp
,"%sindex.unsort",outdir
);
54 sprintf(wdir_tmp2
,"%sindex.sort",outdir
);
55 strcpy(hbc1
,"class=\"header\"");
57 if(strcmp(Index
,"no") == 0) {
58 if(access(wdir
, R_OK
) == 0)
66 if((fp_ou
=fopen(wdir
,"w"))==NULL
) {
67 fprintf(stderr
, "SARG: (index) %s: %s\n",text
[45],wdir
);
71 if((fp_tmp
=fopen(wdir_tmp
,"w"))==NULL
) {
72 fprintf(stderr
, "SARG: (index) %s: %s\n",text
[45],wdir_tmp
);
76 dirp
= opendir(outdir
);
77 while ( (direntp
= readdir( dirp
)) != NULL
){
78 if(strstr(direntp
->d_name
,"-") == 0)
82 strncat(newname
,direntp
->d_name
,4);
83 strncpy(month
,direntp
->d_name
+4,3);
86 strcat(newname
,month
);
87 strncat(newname
,direntp
->d_name
+7,2);
89 obtdate(outdir
,direntp
->d_name
,data
);
90 obtuser(outdir
,direntp
->d_name
,tuser
);
91 obttotal(outdir
,direntp
->d_name
,tbytes
,tuser
,media
);
94 getword(mon
,html
,' ');
95 getword(mon
,html
,' ');
96 getword(day
,html
,' ');
97 getword(hour
,html
,' ');
98 getword(year
,html
,' ');
99 getword(year
,html
,' ');
104 buildymd(day
,mon
,year
,ftime
);
106 sprintf(html
,"%s%s%s%s;%s;%s;%s;%s;%s;%s\n",ftime
, h
, m
, s
, direntp
->d_name
, data
, tuser
, tbytes
, media
,
112 (void)rewinddir( dirp
);
113 (void)closedir( dirp
);
115 if(strcmp(IndexSortOrder
,"A") == 0)
116 // sprintf(html,"sort -t';' -k 7,7 %s -o %s", wdir_tmp, wdir_tmp2);
117 sprintf(html
,"sort -t';' +6.5n +6.2M +6.0n '%s' -o '%s'", wdir_tmp
, wdir_tmp2
);
119 // sprintf(html,"sort -t';' -r -k 7,7 %s -o %s", wdir_tmp, wdir_tmp2);
120 sprintf(html
,"sort -t';' +6.5nr +6.2Mr +6.0nr '%s' -o '%s'", wdir_tmp
, wdir_tmp2
);
126 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou
);
127 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou
);
128 fputs("<html>\n",fp_ou
);
129 fputs("<head>\n",fp_ou
);
130 sprintf(html
," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet
);
132 fputs("</head>\n",fp_ou
);
135 sprintf(buf
,"<body style=\"font-family:%s;font-size:%s;background-color:%s; \
136 background-image:url(%s)\">\n",FontFace
,TitleFontSize
,BgColor
,BgImage
);
139 sprintf(buf
,"<center><table cellpadding=\"0\" cellspacing=\"0\">\n");
142 if(strlen(LogoImage
) > 0) {
143 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou
);
144 sprintf(html
,"<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s> %s</th></tr>\n",LogoImage
,Width
,Height
,LogoText
);
146 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou
);
147 fputs("</table>\n",fp_ou
);
150 show_sarg(fp_ou
, ".");
151 sprintf(html
,"<tr><th class=\"title\">%s</th></tr>\n",Title
);
153 fputs("</table></center>\n",fp_ou
);
155 fputs("<center><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou
);
156 fputs("<tr><td></td><td></td></tr>\n",fp_ou
);
158 sprintf(html
,"<tr><th %s>%s</th><th %s>%s</th><th %s>%s \
159 </th><th %s>%s</th><th %s>%s</th></tr>\n", \
160 hbc1
,text
[101],hbc1
,text
[102],hbc1
,text
[103],hbc1
,text
[93],hbc1
,text
[96]);
163 if((fp_tmp
=fopen(wdir_tmp2
,"r"))==NULL
) {
164 fprintf(stderr
, "SARG: (index) %s: %s\n",text
[45],wdir_tmp2
);
168 while(fgets(buf
,MAXLEN
,fp_tmp
)!=NULL
) {
169 getword(period
,buf
,';');
170 getword(period
,buf
,';');
171 getword(data
,buf
,';');
172 getword(tuser
,buf
,';');
173 getword(tbytes
,buf
,';');
174 getword(media
,buf
,';');
176 sprintf(html
,"<tr><td class=\"data2\"><a href='%s/%s'>%s</a></td><td class=\"data2\">%s</td> \
177 <td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n", \
178 period
,ReplaceIndex
,period
,data
,tuser
,tbytes
,media
);
182 strcpy(html
,"</table></center>");
185 zdate(ftime
, DateFormat
);
189 strcpy(html
,"</body>\n</html>\n");