]> git.ipfire.org Git - thirdparty/sarg.git/blame - index.c
Imported sarg 2.0.9
[thirdparty/sarg.git] / index.c
CommitLineData
25697a35 1/*
94ff9470 2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
25697a35 3 * 1998, 2005
94ff9470 4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
25697a35
GS
5 *
6 * SARG donations:
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
9 *
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.
14 *
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.
19 *
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.
23 *
24 */
25
26#include "include/conf.h"
27
28void geraindex()
29{
30
31 FILE *fp_ou, *fp_tmp, *tp_tmp2;
32 DIR *dirp;
33 struct dirent *direntp;
34 char html[MAXLEN];
35 char wdir[MAXLEN];
36 char wdir_tmp[MAXLEN];
37 char wdir_tmp2[MAXLEN];
38 char newname[512];
39 char month[4];
40 char period[80];
41 char data[80];
42 char tuser[20];
43 char tbytes[20];
44 char media[20];
45 char ftime[128];
46 char day[4], mon[4], year[6], hour[10];
47 char h[3], m[3], s[3];
48
49 if(LastLog[0] != '\0')
50 mklastlog(outdir,debug);
51
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\"");
56
57 if(strcmp(Index,"no") == 0) {
58 if(access(wdir, R_OK) == 0)
59 unlink(wdir);
60 return;
61 }
62
63 if(debug)
64 debuga(text[53]);
65
66 if((fp_ou=fopen(wdir,"w"))==NULL) {
67 fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir);
68 exit(1);
69 }
70
71 if((fp_tmp=fopen(wdir_tmp,"w"))==NULL) {
72 fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir_tmp);
73 exit(1);
74 }
75
76 dirp = opendir(outdir);
77 while ( (direntp = readdir( dirp )) != NULL ){
78 if(strstr(direntp->d_name,"-") == 0)
79 continue;
80
81 bzero(newname, 512);
82 strncat(newname,direntp->d_name,4);
83 strncpy(month,direntp->d_name+4,3);
84 month[3]='\0';
85 conv_month(month);
86 strcat(newname,month);
87 strncat(newname,direntp->d_name+7,2);
88
89 obtdate(outdir,direntp->d_name,data);
90 obtuser(outdir,direntp->d_name,tuser);
91 obttotal(outdir,direntp->d_name,tbytes,tuser,media);
92
93 strcpy(html,data);
94 getword(mon,html,' ');
95 getword(mon,html,' ');
96 getword(day,html,' ');
97 getword(hour,html,' ');
98 getword(year,html,' ');
99 getword(year,html,' ');
100 strcpy(html,hour);
101 getword(h,html,':');
102 getword(m,html,':');
103 strcpy(s,html);
104 buildymd(day,mon,year,ftime);
105
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,
107 newname);
108 fputs(html, fp_tmp);
109 }
110
111 fclose(fp_tmp);
112 (void)rewinddir( dirp );
113 (void)closedir( dirp );
114
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);
118 else
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);
121
122 system(html);
123
124 unlink(wdir_tmp);
125
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);
131 fputs(html,fp_ou);
132 fputs("</head>\n",fp_ou);
133 css(fp_ou);
134
135 sprintf(buf,"<body style=\"font-family:%s;font-size:%s;background-color:%s; \
136 background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage);
137 fputs(buf,fp_ou);
138
139 sprintf(buf,"<center><table cellpadding=\"0\" cellspacing=\"0\">\n");
140 fputs(buf,fp_ou);
94ff9470 141
25697a35 142 if(strlen(LogoImage) > 0) {
94ff9470
GS
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>&nbsp;%s</th></tr>\n",LogoImage,Width,Height,LogoText);
25697a35 145 fputs(html,fp_ou);
94ff9470
GS
146 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou);
147 fputs("</table>\n",fp_ou);
25697a35 148 }
94ff9470 149
25697a35
GS
150 show_sarg(fp_ou, ".");
151 sprintf(html,"<tr><th class=\"title\">%s</th></tr>\n",Title);
152 fputs(html,fp_ou);
153 fputs("</table></center>\n",fp_ou);
154
155 fputs("<center><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
156 fputs("<tr><td></td><td></td></tr>\n",fp_ou);
157
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]);
161 fputs(html,fp_ou);
162
163 if((fp_tmp=fopen(wdir_tmp2,"r"))==NULL) {
164 fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir_tmp2);
165 exit(1);
166 }
167
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,';');
175
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);
179 fputs(html,fp_ou);
180 }
181
182 strcpy(html,"</table></center>");
183 fputs(html,fp_ou);
184
185 zdate(ftime, DateFormat);
186
187 show_info(fp_ou);
188
189 strcpy(html,"</body>\n</html>\n");
190 fputs(html,fp_ou);
191
192 fclose(fp_ou);
193 fclose(fp_tmp);
194
195 unlink(wdir_tmp2);
196 return;
197}