]>
git.ipfire.org Git - thirdparty/sarg.git/blob - dansguardian_log.c
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
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 int dansguardian_log()
31 FILE *fp_in
= NULL
, *fp_ou
= NULL
, *fp_guard
= NULL
;
32 char guard_in
[MAXLEN
];
33 char guard_ou
[MAXLEN
];
34 char loglocation
[MAXLEN
] = "/var/log/dansguardian/access.log";
35 char year
[10], mon
[10], day
[10];
37 char user
[MAXLEN
], code1
[255], code2
[255];
47 if(strcmp(df
,"e") == 0) {
48 strncpy(day
,period
,2);
49 strncpy(mon
,period
+2,3);
50 strncpy(year
,period
+5,4);
52 sprintf(warea
,"%s%s%s",year
,mon
,day
);
54 strncpy(day
,period
+10,2);
55 strncpy(mon
,period
+12,3);
56 strncpy(year
,period
+15,4);
58 sprintf(warea
,"%s%s%s",year
,mon
,day
);
61 strncpy(day
,period
+7,2);
62 strncpy(mon
,period
+4,3);
63 strncpy(year
,period
,4);
65 sprintf(warea
,"%s%s%s",year
,mon
,day
);
67 strncpy(day
,period
+17,2);
68 strncpy(mon
,period
+14,3);
69 strncpy(year
,period
+10,4);
71 sprintf(warea
,"%s%s%s",year
,mon
,day
);
75 sprintf(guard_in
,"%s/dansguardian.unsort",tmp
);
76 sprintf(guard_ou
,"%s/dansguardian.log",tmp
);
78 if(access(DansGuardianConf
, R_OK
) != 0) {
79 sprintf(msg
,"Cannot open DansGuardian config file: %s",DansGuardianConf
);
84 if((fp_guard
=fopen(DansGuardianConf
,"r"))==NULL
) {
85 fprintf(stderr
, "SARG: (dansguardian) %s: %s\n",text
[8],DansGuardianConf
);
89 if((fp_ou
=fopen(guard_in
,"a"))==NULL
) {
90 fprintf(stderr
, "SARG: (dansguardian) %s: %s\n",text
[8],guard_in
);
94 while(fgets(buf
,sizeof(buf
),fp_guard
)!=NULL
) {
95 if(strstr(buf
,"\n") != 0)
96 buf
[strlen(buf
)-1]='\0';
97 if(strncmp(buf
,"#",1) == 0)
99 if(strstr(buf
,"loglocation ") != 0) {
100 getword(loglocation
,buf
,'\'');
101 getword(loglocation
,buf
,'\'');
108 getword(urly
,buf
,' ');
109 getword(href
,buf
,' ');
110 sprintf(msg
,"%s DansGuardian %s: %s",urly
,buf
,loglocation
);
114 if((fp_in
=fopen(loglocation
,"r"))==NULL
) {
115 fprintf(stderr
, "SARG: (dansguardian) %s: %s\n",text
[8],loglocation
);
119 while(fgets(buf
,sizeof(buf
),fp_in
) != NULL
) {
120 if(strstr(buf
," *DENIED* ") == 0)
122 getword(year
,buf
,'.');
123 getword(mon
,buf
,'.');
124 getword(day
,buf
,' ');
125 getword(hour
,buf
,' ');
126 getword(user
,buf
,' ');
128 getword(url
,buf
,'/');
129 getword(url
,buf
,'/');
130 getword(url
,buf
,' ');
131 getword(code1
,buf
,' ');
132 getword(code1
,buf
,' ');
133 getword(code2
,buf
,' ');
134 sprintf(wdata
,"%s%02d%s",year
,atoi(mon
),day
);
137 if(strcmp(DansguardianIgnoreDate
,"on") == 0) {
138 if(idata
< dfrom
&& idata
> duntil
)
142 if (strcmp(user
,"-") == 0) {
146 sprintf(tmp6
,"%s %d %s %s %s %s %s\n",user
,idata
,hour
,ip
,url
,code1
,code2
);
148 dansguardian_count
++;
151 if(fp_in
) fclose(fp_in
);
152 if(fp_guard
) fclose(fp_guard
);
153 if(fp_ou
) fclose(fp_ou
);
156 sprintf(msg
,"%s: %s",text
[54],guard_ou
);
160 sprintf(tmp6
,"sort -k 1,1 -k 2,2 -k 4,4 '%s' -o '%s'",guard_in
, guard_ou
);