]> git.ipfire.org Git - thirdparty/sarg.git/blob - dansguardian_log.c
Mass commit of all the changes made between version 2.1 and 2.2.5. See ChangeLog...
[thirdparty/sarg.git] / dansguardian_log.c
1 /*
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
3 * 1998, 2008
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
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 dansguardian_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 loglocation[MAXLEN] = "/var/log/dansguardian/access.log";
35 char year[10], mon[10], day[10];
36 char hour[15];
37 char user[MAXLEN], code1[255], code2[255];
38 char ip[30];
39 char wdata[127];
40 int idata=0;
41 int x, y;
42
43 bzero(day, 3);
44 bzero(mon, 4);
45 bzero(year, 5);
46
47 if(strcmp(df,"e") == 0) {
48 strncpy(day,period,2);
49 strncpy(mon,period+2,3);
50 strncpy(year,period+5,4);
51 conv_month(mon);
52 sprintf(warea,"%s%s%s",year,mon,day);
53 dfrom=atoi(warea);
54 strncpy(day,period+10,2);
55 strncpy(mon,period+12,3);
56 strncpy(year,period+15,4);
57 conv_month(mon);
58 sprintf(warea,"%s%s%s",year,mon,day);
59 duntil=atoi(warea);
60 } else {
61 strncpy(day,period+7,2);
62 strncpy(mon,period+4,3);
63 strncpy(year,period,4);
64 conv_month(mon);
65 sprintf(warea,"%s%s%s",year,mon,day);
66 dfrom=atoi(warea);
67 strncpy(day,period+17,2);
68 strncpy(mon,period+14,3);
69 strncpy(year,period+10,4);
70 conv_month(mon);
71 sprintf(warea,"%s%s%s",year,mon,day);
72 duntil=atoi(warea);
73 }
74
75 sprintf(guard_in,"%s/dansguardian.unsort",tmp);
76 sprintf(guard_ou,"%s/dansguardian.log",tmp);
77
78 if(access(DansGuardianConf, R_OK) != 0) {
79 sprintf(msg,"Cannot open DansGuardian config file: %s",DansGuardianConf);
80 debuga(msg);
81 exit(1);
82 }
83
84 if((fp_guard=fopen(DansGuardianConf,"r"))==NULL) {
85 fprintf(stderr, "SARG: (dansguardian) %s: %s\n",text[8],DansGuardianConf);
86 exit(1);
87 }
88
89 if((fp_ou=fopen(guard_in,"a"))==NULL) {
90 fprintf(stderr, "SARG: (dansguardian) %s: %s\n",text[8],guard_in);
91 exit(1);
92 }
93
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)
98 continue;
99 if(strstr(buf,"loglocation ") != 0) {
100 getword(loglocation,buf,'\'');
101 getword(loglocation,buf,'\'');
102 break;
103 }
104 }
105
106 if(debug) {
107 strcpy(buf,text[7]);
108 getword(urly,buf,' ');
109 getword(href,buf,' ');
110 sprintf(msg,"%s DansGuardian %s: %s",urly,buf,loglocation);
111 debuga(msg);
112 }
113
114 if((fp_in=fopen(loglocation,"r"))==NULL) {
115 fprintf(stderr, "SARG: (dansguardian) %s: %s\n",text[8],loglocation);
116 exit(1);
117 }
118
119 while(fgets(buf,sizeof(buf),fp_in) != NULL) {
120 if(strstr(buf," *DENIED* ") == 0)
121 continue;
122 getword(year,buf,'.');
123 getword(mon,buf,'.');
124 getword(day,buf,' ');
125 getword(hour,buf,' ');
126 getword(user,buf,' ');
127 getword(ip,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);
135 idata = atoi(wdata);
136
137 if(strcmp(DansguardianIgnoreDate,"on") == 0) {
138 if(idata < dfrom && idata > duntil)
139 continue;
140 }
141
142 if (strcmp(user,"-") == 0) {
143 strcpy(user,ip);
144 bzero(ip, 30);
145 }
146 sprintf(tmp6,"%s %d %s %s %s %s %s\n",user,idata,hour,ip,url,code1,code2);
147 fputs(tmp6, fp_ou);
148 dansguardian_count++;
149 }
150
151 if(fp_in) fclose(fp_in);
152 if(fp_guard) fclose(fp_guard);
153 if(fp_ou) fclose(fp_ou);
154
155 if(debug) {
156 sprintf(msg,"%s: %s",text[54],guard_ou);
157 debuga(msg);
158 }
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 unlink(guard_in);
163 return;
164 }