]>
git.ipfire.org Git - thirdparty/sarg.git/blob - squidguard_log.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_in
= NULL
, *fp_ou
= NULL
, *fp_guard
= NULL
;
32 char guard_in
[MAXLEN
];
33 char guard_ou
[MAXLEN
];
35 char year
[10], mon
[10], day
[10], hour
[15];
41 char leks
[5], sep
[2], res
[MAXLEN
];
45 if(strlen(SquidGuardConf
) < 1)
52 if(strcmp(df
,"e") == 0) {
53 strncpy(day
,periodo
,2);
54 strncpy(mon
,periodo
+2,3);
55 strncpy(year
,periodo
+5,4);
57 sprintf(warea
,"%s%s%s",year
,mon
,day
);
59 strncpy(day
,periodo
+10,2);
60 strncpy(mon
,periodo
+12,3);
61 strncpy(year
,periodo
+15,4);
63 sprintf(warea
,"%s%s%s",year
,mon
,day
);
66 strncpy(day
,periodo
+7,2);
67 strncpy(mon
,periodo
+4,3);
68 strncpy(year
,periodo
,4);
70 sprintf(warea
,"%s%s%s",year
,mon
,day
);
72 strncpy(day
,periodo
+17,2);
73 strncpy(mon
,periodo
+14,3);
74 strncpy(year
,periodo
+10,4);
76 sprintf(warea
,"%s%s%s",year
,mon
,day
);
80 sprintf(guard_in
,"%s/squidguard.unsort",tmp
);
81 sprintf(guard_ou
,"%s/squidguard.log",tmp
);
83 if(access(SquidGuardConf
, R_OK
) != 0) {
84 sprintf(msg
,"Cannot open squidGuard config file: %s",SquidGuardConf
);
89 if((fp_guard
=fopen(SquidGuardConf
,"r"))==NULL
) {
90 fprintf(stderr
, "SARG: (squidguard) %s: %s\n",text
[8],SquidGuardConf
);
94 if((fp_ou
=fopen(guard_in
,"a"))==NULL
) {
95 fprintf(stderr
, "SARG: (squidguard) %s: %s\n",text
[8],guard_in
);
99 while(fgets(buf
,sizeof(buf
),fp_guard
)!=NULL
) {
100 if(strstr(buf
,"\n") != 0)
101 buf
[strlen(buf
)-1]='\0';
102 if(strstr(buf
,"logdir ") != 0) {
103 getword(logdir
,buf
,' ');
104 getword(logdir
,buf
,' ');
106 if((str
=(char *) strstr(buf
, "log")) != (char *) NULL
) {
110 for (x
=0; x
<=strlen(str
); x
++) {
111 if (str
[x
] != ' ' && str
[x
] != '\t') {
117 sprintf(wentp
,"%s/%s",logdir
,str2
);
122 getword(urly
,buf
,' ');
123 getword(href
,buf
,' ');
124 sprintf(msg
,"%s squidGuard %s: %s",urly
,buf
,wentp
);
128 if((fp_in
=fopen(wentp
,"r"))==NULL
) {
129 fprintf(stderr
, "SARG: (squidguard) %s: %s\n",text
[8],wentp
);
133 while(fgets(buf
,sizeof(buf
),fp_in
) != NULL
) {
135 if(strlen(SquidGuardLogFormat
) > 0) {
136 strcpy(bufbsf
,SquidGuardLogFormat
);
138 getword(leks
,bufbsf
,'#');
139 while(strcmp(leks
,"end") != 0) {
140 getword(leks
,bufbsf
,'#');
141 getword(sep
,bufbsf
,'#');
142 if(strcmp(leks
,"end") != 0) {
143 getword(res
,buf
,sep
[0]);
144 if(strcmp(leks
,"year") == 0)
146 else if(strcmp(leks
,"year") == 0)
148 else if(strcmp(leks
,"mon") == 0)
150 else if(strcmp(leks
,"day") == 0)
152 else if(strcmp(leks
,"hour") == 0)
154 else if(strcmp(leks
,"list") == 0)
156 else if(strcmp(leks
,"ip") == 0)
158 else if(strcmp(leks
,"user") == 0)
160 else if(strcmp(leks
,"url") == 0)
166 sprintf(warea
,"%s%s%s",year
,mon
,day
);
167 sprintf(wdata
,"%s%s%s",year
,mon
,day
);
170 if(idata
>= dfrom
&& idata
<= duntil
) {
171 if(strcmp(user
,"-") == 0) {
175 sprintf(tmp6
,"%s %s%s%s %s %s %s %s\n",user
,year
,mon
,day
,hour
,ip
,url
,list
);
186 sprintf(tmp6
,"sort -k 1,1 -k 2,2 -k 4,4 '%s' -o '%s'",guard_in
, guard_ou
);