]>
Commit | Line | Data |
---|---|---|
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 | ||
28 | int squidguard_log() | |
29 | { | |
30 | ||
31 | FILE *fp_in = NULL, *fp_ou = NULL, *fp_guard = NULL; | |
32 | char guard_in[MAXLEN]; | |
33 | char guard_ou[MAXLEN]; | |
34 | char logdir[MAXLEN]; | |
35 | char year[10], mon[10], day[10], hour[15]; | |
36 | char list[MAXLEN]; | |
37 | char user[MAXLEN]; | |
38 | char ip[30]; | |
39 | char wdata[127]; | |
40 | char bufbsf[255]; | |
41 | char leks[5], sep[2], res[MAXLEN]; | |
42 | int idata=0; | |
43 | int x, y; | |
44 | ||
45 | if(strlen(SquidGuardConf) < 1) | |
46 | return; | |
47 | ||
48 | bzero(day, 3); | |
49 | bzero(mon, 4); | |
50 | bzero(year, 5); | |
51 | ||
52 | if(strcmp(df,"e") == 0) { | |
53 | strncpy(day,periodo,2); | |
54 | strncpy(mon,periodo+2,3); | |
55 | strncpy(year,periodo+5,4); | |
56 | conv_month(mon); | |
57 | sprintf(warea,"%s%s%s",year,mon,day); | |
58 | dfrom=atoi(warea); | |
59 | strncpy(day,periodo+10,2); | |
60 | strncpy(mon,periodo+12,3); | |
61 | strncpy(year,periodo+15,4); | |
62 | conv_month(mon); | |
63 | sprintf(warea,"%s%s%s",year,mon,day); | |
64 | duntil=atoi(warea); | |
65 | } else { | |
66 | strncpy(day,periodo+7,2); | |
67 | strncpy(mon,periodo+4,3); | |
68 | strncpy(year,periodo,4); | |
69 | conv_month(mon); | |
70 | sprintf(warea,"%s%s%s",year,mon,day); | |
71 | dfrom=atoi(warea); | |
72 | strncpy(day,periodo+17,2); | |
73 | strncpy(mon,periodo+14,3); | |
74 | strncpy(year,periodo+10,4); | |
75 | conv_month(mon); | |
76 | sprintf(warea,"%s%s%s",year,mon,day); | |
77 | duntil=atoi(warea); | |
78 | } | |
79 | ||
80 | sprintf(guard_in,"%s/squidguard.unsort",tmp); | |
81 | sprintf(guard_ou,"%s/squidguard.log",tmp); | |
82 | ||
83 | if(access(SquidGuardConf, R_OK) != 0) { | |
84 | sprintf(msg,"Cannot open squidGuard config file: %s",SquidGuardConf); | |
85 | debuga(msg); | |
86 | exit(1); | |
87 | } | |
88 | ||
89 | if((fp_guard=fopen(SquidGuardConf,"r"))==NULL) { | |
90 | fprintf(stderr, "SARG: (squidguard) %s: %s\n",text[8],SquidGuardConf); | |
91 | exit(1); | |
92 | } | |
93 | ||
94 | if((fp_ou=fopen(guard_in,"a"))==NULL) { | |
95 | fprintf(stderr, "SARG: (squidguard) %s: %s\n",text[8],guard_in); | |
96 | exit(1); | |
97 | } | |
98 | ||
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,' '); | |
105 | } | |
106 | if((str=(char *) strstr(buf, "log")) != (char *) NULL ) { | |
107 | str=str+3; | |
108 | str2[0]='\0'; | |
109 | y=0; | |
110 | for (x=0; x<=strlen(str); x++) { | |
111 | if (str[x] != ' ' && str[x] != '\t') { | |
112 | str2[y] = str[x]; | |
113 | y++; | |
114 | } | |
115 | } | |
116 | ||
117 | sprintf(wentp,"%s/%s",logdir,str2); | |
118 | ||
119 | if(debug) { | |
120 | strcpy(buf,text[7]); | |
121 | ||
122 | getword(urly,buf,' '); | |
123 | getword(href,buf,' '); | |
124 | sprintf(msg,"%s squidGuard %s: %s",urly,buf,wentp); | |
125 | debuga(msg); | |
126 | } | |
127 | ||
128 | if((fp_in=fopen(wentp,"r"))==NULL) { | |
129 | fprintf(stderr, "SARG: (squidguard) %s: %s\n",text[8],wentp); | |
130 | exit(1); | |
131 | } | |
132 | ||
133 | while(fgets(buf,sizeof(buf),fp_in) != NULL) { | |
134 | ||
135 | if(strlen(SquidGuardLogFormat) > 0) { | |
136 | strcpy(bufbsf,SquidGuardLogFormat); | |
137 | leks[0]='\0'; | |
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) | |
145 | strcpy(year,res); | |
146 | else if(strcmp(leks,"year") == 0) | |
147 | strcpy(year,res); | |
148 | else if(strcmp(leks,"mon") == 0) | |
149 | strcpy(mon,res); | |
150 | else if(strcmp(leks,"day") == 0) | |
151 | strcpy(day,res); | |
152 | else if(strcmp(leks,"hour") == 0) | |
153 | strcpy(hour,res); | |
154 | else if(strcmp(leks,"list") == 0) | |
155 | strcpy(list,res); | |
156 | else if(strcmp(leks,"ip") == 0) | |
157 | strcpy(ip,res); | |
158 | else if(strcmp(leks,"user") == 0) | |
159 | strcpy(user,res); | |
160 | else if(strcmp(leks,"url") == 0) | |
161 | strcpy(url,res); | |
162 | } | |
163 | } | |
164 | } | |
165 | ||
166 | sprintf(warea,"%s%s%s",year,mon,day); | |
167 | sprintf(wdata,"%s%s%s",year,mon,day); | |
168 | idata = atoi(wdata); | |
169 | ||
170 | if(idata >= dfrom && idata <= duntil) { | |
171 | if(strcmp(user,"-") == 0) { | |
172 | strcpy(user,ip); | |
173 | bzero(ip, 30); | |
174 | } | |
175 | sprintf(tmp6,"%s %s%s%s %s %s %s %s\n",user,year,mon,day,hour,ip,url,list); | |
176 | fputs(tmp6, fp_ou); | |
177 | squidguard_count++; | |
178 | } | |
179 | } | |
180 | fclose(fp_in); | |
181 | } | |
182 | } | |
183 | ||
184 | fclose(fp_guard); | |
185 | fclose(fp_ou); | |
94ff9470 | 186 | sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 '%s' -o '%s'",guard_in, guard_ou); |
25697a35 GS |
187 | system(tmp6); |
188 | unlink(guard_in); | |
189 | return; | |
190 | } |