~ubuntu-branches/ubuntu/natty/sarg/natty

« back to all changes in this revision

Viewing changes to topsites.c

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-01-11 15:07:10 UTC
  • mfrom: (1.1.8 upstream) (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100111150710-mgvjhyjs13mrg0tb
Tags: 2.2.6-1
* New upstream release
  - Fixes issues in getword loop detection (Closes: #522284)
  - Removed patches integrated upstream
  - Fixes usertab parsing for IPv6 address (Closes: #504749)
  - Fixes typo in dansguardian_log.c (Closes: #540438)
  - Fixes error parsing squidGuard logs (Closes: #486895)

* debian/sarg-reports.conf
  - Fixed typo (Closes: #517356)

* debian/control
  - Added Build-Dep options on libgd2-xpm-dev (Closes: #540121)
  - Added Dependency on ${misc:Depends}
  - Added dependency on dpatch
  - Bumped Standard-Version to 3.8.3

* debian/compat
  - Upgraded debhelper compatibility to level 6

* debian/rules
  - Removed unnecessary upgrade of autoconf files
  - Added dpatch rules
  - Fixed configuration options and paths

* debian/patches/01_makefile-install-path
  - Fixed build-time installation paths

* debian/patches/02_config-file-references
  - Fixed references to configuration files

* debian/squid.conf
  - Sinced with upstream changes

* debian/{postrm,preinst,sarg.conf,sarg-reports,rules,dirs,sarg-reports.conf}
  - Moved configuration files to /etc/sarg and data directory to /var/lib/sarg
    (Closes: #553554, #502273)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * AUTHOR: Pedro Lineu Orso                         pedro.orso@gmail.com
3
 
 *                                                            1998, 2008
 
3
 *                                                            1998, 2009
4
4
 * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
5
5
 *
6
6
 * SARG donations:
24
24
 */
25
25
 
26
26
#include "include/conf.h"
 
27
#include "include/defs.h"
27
28
 
28
 
void topsites()
 
29
void topsites(void)
29
30
{
30
31
 
31
32
   FILE *fp_in, *fp_ou;
32
 
      
 
33
 
33
34
   char url[MAXLEN];
34
35
   char ourl[MAXLEN];
35
36
   char nacc[20];
36
37
   char nbytes[20];
37
38
   char ntime[20];
38
 
   char ntemp[20];
 
39
   char ntemp[255];
39
40
   char ttnacc[20];
40
41
   char ttnbytes[20];
41
42
   char ttntime[20];
54
55
   long long int tntime=0;
55
56
   long long int twork1=0, twork2=0, twork3=0;
56
57
   int regs=0;
 
58
   int cstatus;
57
59
 
58
60
   if(strcmp(Privacy,"yes") == 0)
59
61
      return;
74
76
      exit(1);
75
77
   }
76
78
 
77
 
   fgets(period,sizeof(period),fp_in);
 
79
   if (!fgets(period,sizeof(period),fp_in)) {
 
80
      fprintf(stderr,"SARG: (topuser) read error in %s\n",per);
 
81
      exit(1);
 
82
   }
78
83
   fclose(fp_in);
79
84
 
80
 
   sprintf(csort,"sort -k 4,4 -o '%s' '%s'",general2,general);
81
 
   system(csort);
 
85
   sprintf(csort,"sort -k 4,4 -o \"%s\" \"%s\"",general2,general);
 
86
   cstatus=system(csort);
 
87
   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
 
88
      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
 
89
      fprintf(stderr, "SARG: sort command: %s\n",csort);
 
90
      exit(1);
 
91
   }
82
92
 
83
93
   if((fp_in=fopen(general2,"r"))==NULL) {
84
94
     fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],general2);
 
95
     fprintf(stderr, "SARG: sort command: %s\n",csort);
85
96
     exit(1);
86
97
   }
87
98
 
91
102
   }
92
103
 
93
104
   while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
94
 
      getword(url,sizeof(url),buf,' ');
 
105
      if (getword(url,sizeof(url),buf,' ')<0) {
 
106
         printf("SARG: Maybe you have an invalid user in your %s file of the topsites.\n",general2);
 
107
         exit(1);
 
108
      }
95
109
      if(strcmp(url,"TOTAL") == 0) {
96
 
         getword(ttnacc,sizeof(ttnacc),buf,' ');
97
 
         getword(ttnbytes,sizeof(ttnbytes),buf,' ');
98
 
         getword(ttntime,sizeof(ttntime),buf,' ');
 
110
         if (getword(ttnacc,sizeof(ttnacc),buf,' ')<0) {
 
111
            printf("SARG: Maybe you have an invalid total number of access in your %s file of the topsites.\n",general2);
 
112
            exit(1);
 
113
         }
 
114
         if (getword(ttnbytes,sizeof(ttnbytes),buf,' ')<0) {
 
115
            printf("SARG: Maybe you have an invalid total number of bytes in your %s file of the topsites.\n",general2);
 
116
            exit(1);
 
117
         }
 
118
         if (getword(ttntime,sizeof(ttntime),buf,' ')<0) {
 
119
            printf("SARG: Maybe you have an invalid total time in your %s file of the topsites.\n",general2);
 
120
            exit(1);
 
121
         }
99
122
         continue;
100
123
      }
101
 
      getword(nacc,sizeof(nacc),buf,' ');
102
 
      getword(nbytes,sizeof(nbytes),buf,' ');
103
 
      getword(url,sizeof(url),buf,' ');
104
 
      getword(ntemp,sizeof(ntemp),buf,' ');
105
 
      getword(ntemp,sizeof(ntemp),buf,' ');
106
 
      getword(ntemp,sizeof(ntemp),buf,' ');
107
 
      getword(ntime,sizeof(ntime),buf,' ');
 
124
      if (getword(nacc,sizeof(nacc),buf,' ')<0) {
 
125
         printf("SARG: Maybe you have an invalid number of access in your %s file of the topsites.\n",general2);
 
126
         exit(1);
 
127
      }
 
128
      if (getword(nbytes,sizeof(nbytes),buf,' ')<0) {
 
129
         printf("SARG: Maybe you have an invalid number of bytes in your %s file of the topsites.\n",general2);
 
130
         exit(1);
 
131
      }
 
132
      if (getword(url,sizeof(url),buf,' ')<0) {
 
133
         printf("SARG: Maybe you have an invalid url in your %s file of the topsites.\n",general2);
 
134
         exit(1);
 
135
      }
 
136
      if (getword(ntemp,sizeof(ntemp),buf,' ')<0) {
 
137
         printf("SARG: Maybe you have a broken record or garbage in column 5 in your %s file of the topsites.\n",general2);
 
138
         exit(1);
 
139
      }
 
140
      if (getword(ntemp,sizeof(ntemp),buf,' ')<0) {
 
141
         printf("SARG: Maybe you have a broken record or garbage in column 6 in your %s file of the topsites.\n",general2);
 
142
         exit(1);
 
143
      }
 
144
      if (getword(ntemp,sizeof(ntemp),buf,' ')<0) {
 
145
         printf("SARG: Maybe you have a broken record or garbage in column 7 in your %s file of the topsites.\n",general2);
 
146
         exit(1);
 
147
      }
 
148
      if (getword(ntime,sizeof(ntime),buf,' ')<0) {
 
149
         printf("SARG: Maybe you have a broken record or garbage in column 8 in your %s file of the topsites.\n",general2);
 
150
         exit(1);
 
151
      }
108
152
 
109
153
      if(!regs) {
110
154
         strcpy(ourl,url);
115
159
         my_lltoa(tnacc,val1,15);
116
160
         my_lltoa(tnbytes,val2,15);
117
161
         my_lltoa(tntime,val3,15);
118
 
         sprintf(buf,"%s %s %s %s\n",val1,val2,val3,ourl);
119
 
         fputs(buf, fp_ou);
 
162
         fprintf(fp_ou,"%s %s %s %s\n",val1,val2,val3,ourl);
120
163
         strcpy(ourl,url);
121
164
         tnacc=0;
122
165
         tnbytes=0;
131
174
   my_lltoa(tnacc,val1,15);
132
175
   my_lltoa(tnbytes,val2,15);
133
176
   my_lltoa(tntime,val3,15);
134
 
   sprintf(buf,"%s %s %s %s\n",val1,val2,val3,ourl);
135
 
   fputs(buf, fp_ou);
 
177
   fprintf(fp_ou,"%s %s %s %s\n",val1,val2,val3,ourl);
136
178
 
137
179
   fclose(fp_in);
138
180
   fclose(fp_ou);
150
192
   if(strcmp(TopsitesSortType,"d") == 0)
151
193
      strcpy(sortt,"-r");
152
194
 
153
 
   sprintf(csort,"sort %s -k %s -o '%s' '%s'",sortt,sortf,sites,general3);
154
 
   system(csort);
 
195
   sprintf(csort,"sort %s -k %s -o \"%s\" \"%s\"",sortt,sortf,sites,general3);
 
196
   cstatus=system(csort);
 
197
   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
 
198
      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
 
199
      fprintf(stderr, "SARG: sort command: %s\n",csort);
 
200
      exit(1);
 
201
   }
 
202
   if((fp_in=fopen(sites,"r"))==NULL) {
 
203
      fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],sites);
 
204
      fprintf(stderr, "SARG: sort command: %s\n",csort);
 
205
      exit(1);
 
206
   }
155
207
 
156
208
   unlink(general2);
157
209
   unlink(general3);
158
210
 
159
 
   if((fp_in=fopen(sites,"r"))==NULL) {
160
 
     fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],sites);
161
 
     exit(1);
162
 
   }
163
 
 
164
211
   if((fp_ou=fopen(report,"w"))==NULL) {
165
212
     fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],report);
166
213
     exit(1);
171
218
   fprintf(fp_ou, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
172
219
   css(fp_ou);
173
220
   fputs("</head>\n",fp_ou);
174
 
   fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
175
 
   if(strlen(LogoImage) > 0) fprintf(fp_ou, "<center><table cellpadding=\"0\" cellspacing=\"0\">\n<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n<tr><td height=\"5\"></td></tr>\n</table>\n",LogoImage,Width,Height,LogoText);
 
221
   fprintf(fp_ou,"<body bgcolor=\"%s\" text=\"%s\" background=\"%s\">\n",BgColor,TxColor,BgImage);
 
222
   write_logo_image(fp_ou);
176
223
 
177
224
   if(strcmp(IndexTree,"date") == 0)
178
225
      show_sarg(fp_ou,"../../..");
179
226
   else
180
227
      show_sarg(fp_ou, "..");
181
228
 
182
 
   fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
183
 
   sprintf(url,"<tr><th class=\"title\">%s</th></tr>\n",Title);
184
 
   fputs(url,fp_ou);
185
 
 
186
 
   sprintf(url,"<tr><td class=\"header3\">%s: %s</td></tr>\n",text[89],period);
187
 
   fputs(url,fp_ou);
188
 
   sprintf(url,"<tr><th class=\"header3\">%s %s %s</th></tr>\n",text[83],TopSitesNum,text[84]);
189
 
   fputs(url,fp_ou);
190
 
   fputs("</table></center>\n",fp_ou);
191
 
 
192
 
   fputs("<center><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
 
229
   fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
 
230
   fprintf(fp_ou,"<tr><th class=\"title\">%s</th></tr>\n",Title);
 
231
 
 
232
   fprintf(fp_ou,"<tr><td class=\"header3\">%s: %s</td></tr>\n",text[89],period);
 
233
   fprintf(fp_ou,"<tr><th class=\"header3\">%s %s %s</th></tr>\n",text[83],TopSitesNum,text[84]);
 
234
   fputs("</table></div>\n",fp_ou);
 
235
 
 
236
   fputs("<div align=\"center\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
193
237
   fputs("<tr><td></td></tr>\n",fp_ou);
194
 
   sprintf(url,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th> \
 
238
   fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th> \
195
239
                <th class=\"header\">%s</th><th class=\"header\">%s</th> \
196
240
                <th class=\"header\">%s</th></tr>\n", \
197
241
                text[100],text[91],text[92],text[93],text[99]);
198
 
   fputs(url,fp_ou);
199
242
 
200
243
   regs=1;
201
244
   ntopsites = 0;
203
246
   while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
204
247
      if(regs>atoi(TopSitesNum))
205
248
         break;
206
 
      getword(nacc,sizeof(nacc),buf,' ');
 
249
      if (getword(nacc,sizeof(nacc),buf,' ')<0) {
 
250
         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sites);
 
251
         exit(1);
 
252
      }
207
253
      if (atoi(nacc) == 0) continue;
208
 
 
209
 
      getword(nbytes,sizeof(nbytes),buf,' ');
210
 
      getword(ntime,sizeof(ntime),buf,' ');
211
 
      getword(url,sizeof(url),buf,' ');
 
254
      if (getword(nbytes,sizeof(nbytes),buf,' ')<0 ||
 
255
          getword(ntime,sizeof(ntime),buf,' ')<0 || getword(url,sizeof(url),buf,' ')<0) {
 
256
         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sites);
 
257
         exit(1);
 
258
      }
212
259
 
213
260
      twork1=my_atoll(nacc);
214
261
      twork2=my_atoll(nbytes);
215
262
      twork3=my_atoll(ntime);
216
263
 
217
 
      sprintf(wwork1,"%s",fixnum(twork1,1));
218
 
      sprintf(wwork2,"%s",fixnum(twork2,1));
219
 
      sprintf(wwork3,"%s",fixtime(twork3,1));
 
264
      strcpy(wwork1,fixnum(twork1,1));
 
265
      strcpy(wwork2,fixnum(twork2,1));
 
266
      strcpy(wwork3,fixtime(twork3));
220
267
 
221
268
      if(strlen(BlockIt) > 0)
222
269
         sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"../images/sarg-squidguard-block.png\" border=\"0\"></a>&nbsp;",wwwDocumentRoot,BlockIt,url);
223
270
      else BlockImage[0]='\0';
224
271
 
225
272
 
226
 
      sprintf(ourl,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\"><font class=\"link\">%s</font></td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",regs,BlockImage,url,url,wwork1,wwork2,wwork3);
227
 
      fputs(ourl,fp_ou);
 
273
      fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\"><font class=\"link\">%s</font></a></td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",regs,BlockImage,url,url,wwork1,wwork2,wwork3);
228
274
      regs++;
229
275
   }
230
276
 
231
277
 
232
 
   fputs("</table></center>\n",fp_ou);
 
278
   fputs("</table>\n</div>\n",fp_ou);
233
279
 
234
280
   show_info(fp_ou);
235
281
 
236
282
   fputs("</body>\n</html>\n",fp_ou);
237
 
   
 
283
 
238
284
   fclose(fp_in);
239
285
   fclose(fp_ou);
240
286