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

« back to all changes in this revision

Viewing changes to dansguardian_log.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
 
int dansguardian_log()
 
29
void dansguardian_log(void)
29
30
{
30
31
 
31
32
   FILE *fp_in = NULL, *fp_ou = NULL, *fp_guard = NULL;
38
39
   char ip[30];
39
40
   char wdata[127];
40
41
   int  idata=0;
41
 
   int  x, y;
 
42
   int cstatus;
42
43
 
43
44
   bzero(day, 3);
44
45
   bzero(mon, 4);
76
77
   sprintf(guard_ou,"%s/dansguardian.log",tmp);
77
78
 
78
79
   if(access(DansGuardianConf, R_OK) != 0) {
79
 
      sprintf(msg,"Cannot open DansGuardian config file: %s",DansGuardianConf);
80
 
      debuga(msg);
 
80
      debuga("Cannot open DansGuardian config file: %s",DansGuardianConf);
81
81
      exit(1);
82
82
   }
83
83
 
86
86
      exit(1);
87
87
   }
88
88
 
89
 
   if((fp_ou=fopen(guard_in,"a"))==NULL) {
 
89
   if((fp_ou=MY_FOPEN(guard_in,"a"))==NULL) {
90
90
      fprintf(stderr, "SARG: (dansguardian) %s: %s\n",text[8],guard_in);
91
91
      exit(1);
92
92
   }
97
97
      if(strncmp(buf,"#",1) == 0)
98
98
         continue;
99
99
      if(strstr(buf,"loglocation ") != 0) {
100
 
         getword(loglocation,sizeof(loglocation),buf,'\'');
101
 
         getword(loglocation,sizeof(loglocation),buf,'\'');
 
100
         if (getword(loglocation,sizeof(loglocation),buf,'\'')<0 || getword(loglocation,sizeof(loglocation),buf,'\'')<0) {
 
101
            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",DansGuardianConf);
 
102
            exit(1);
 
103
         }
102
104
         break;
103
105
      }
104
106
   }
105
107
 
106
108
   if(debug) {
107
109
      strcpy(buf,text[7]);
108
 
      getword(urly,sizeof(urly),buf,' ');
109
 
      getword(href,sizeof(href),buf,' ');
110
 
      sprintf(msg,"%s DansGuardian %s: %s",urly,buf,loglocation);
111
 
      debuga(msg);
 
110
      if (getword(urly,sizeof(urly),buf,' ')<0 || getword(href,sizeof(href),buf,' ')<0) {
 
111
         printf("SARG: Maybe you have a broken record or garbage in your %s entry.\n",text[7]);
 
112
         exit(1);
 
113
      }
 
114
      debuga("%s DansGuardian %s: %s",urly,buf,loglocation);
112
115
   }
113
 
   
114
 
   if((fp_in=fopen(loglocation,"r"))==NULL) {
 
116
 
 
117
   if((fp_in=MY_FOPEN(loglocation,"r"))==NULL) {
115
118
      fprintf(stderr, "SARG: (dansguardian) %s: %s\n",text[8],loglocation);
116
119
      exit(1);
117
120
   }
118
 
 
 
121
 
119
122
   while(fgets(buf,sizeof(buf),fp_in) != NULL) {
120
123
      if(strstr(buf," *DENIED* ") == 0)
121
124
         continue;
122
 
      getword(year,sizeof(year),buf,'.');
123
 
      getword(mon,sizeof(year),buf,'.');
124
 
      getword(day,sizeof(day),buf,' ');
125
 
      getword(hour,sizeof(hour),buf,' ');
126
 
      getword(user,sizeof(user),buf,' ');
127
 
      getword(ip,sizeof(ip),buf,' ');
128
 
      getword(url,sizeof(url),buf,'/');
129
 
      getword(url,sizeof(url),buf,'/');
130
 
      getword(url,sizeof(url),buf,' ');
131
 
      getword(code1,sizeof(code1),buf,' ');
132
 
      getword(code1,sizeof(code1),buf,' ');
133
 
      getword(code2,sizeof(code2),buf,' ');
 
125
      if (getword(year,sizeof(year),buf,'.')<0 || getword(mon,sizeof(mon),buf,'.')<0 ||
 
126
          getword(day,sizeof(day),buf,' ')<0 || getword(hour,sizeof(hour),buf,' ')<0 ||
 
127
          getword(user,sizeof(user),buf,' ')<0 || getword(ip,sizeof(ip),buf,' ')<0 ||
 
128
          getword(url,sizeof(url),buf,'/')<0 || getword(url,sizeof(url),buf,'/')<0 ||
 
129
          getword(url,sizeof(url),buf,' ')<0 || getword(code1,sizeof(code1),buf,' ')<0 ||
 
130
          getword(code1,sizeof(code1),buf,' ')<0 || getword(code2,sizeof(code2),buf,' ')<0) {
 
131
         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",loglocation);
 
132
         exit(1);
 
133
      }
134
134
      sprintf(wdata,"%s%02d%s",year,atoi(mon),day);
135
135
      idata = atoi(wdata);
136
136
 
143
143
         strcpy(user,ip);
144
144
         bzero(ip, 30);
145
145
      }
146
 
      sprintf(tmp6,"%s %d %s %s %s %s %s\n",user,idata,hour,ip,url,code1,code2);
147
 
      fputs(tmp6, fp_ou);
 
146
      fprintf(fp_ou,"%s %d %s %s %s %s %s\n",user,idata,hour,ip,url,code1,code2);
148
147
      dansguardian_count++;
149
148
   }
150
149
 
152
151
   if(fp_guard) fclose(fp_guard);
153
152
   if(fp_ou) fclose(fp_ou);
154
153
 
155
 
   if(debug) {
156
 
      sprintf(msg,"%s: %s",text[54],guard_ou);
157
 
      debuga(msg);
 
154
   if(debug)
 
155
      debuga("%s: %s",text[54],guard_ou);
 
156
 
 
157
   sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 \"%s\" -o \"%s\"",guard_in, guard_ou);
 
158
   cstatus=system(tmp6);
 
159
   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
 
160
      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
 
161
      fprintf(stderr, "SARG: sort command: %s\n",tmp6);
 
162
      exit(1);
158
163
   }
159
 
 
160
 
   sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 '%s' -o '%s'",guard_in, guard_ou);
161
 
   system(tmp6);
162
164
   unlink(guard_in);
163
 
   return;
164
165
}