]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
1164c474 | 3 | * 1998, 2010 |
25697a35 GS |
4 | * |
5 | * SARG donations: | |
6 | * please look at http://sarg.sourceforge.net/donations.php | |
1164c474 FM |
7 | * Support: |
8 | * http://sourceforge.net/projects/sarg/forums/forum/363374 | |
25697a35 GS |
9 | * --------------------------------------------------------------------- |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
24 | * | |
25 | */ | |
26 | ||
27 | #include "include/conf.h" | |
5f3cfd1d | 28 | #include "include/defs.h" |
25697a35 | 29 | |
32e71fa4 | 30 | void dansguardian_report(void) |
25697a35 GS |
31 | { |
32 | ||
33 | FILE *fp_in = NULL, *fp_ou = NULL; | |
120d768c | 34 | |
25697a35 | 35 | char url[MAXLEN]; |
25697a35 | 36 | char dansguardian_in[MAXLEN]; |
25697a35 GS |
37 | char per[MAXLEN]; |
38 | char report[MAXLEN]; | |
d6e703cc | 39 | char period[100]; |
25697a35 GS |
40 | char ip[MAXLEN]; |
41 | char rule[255]; | |
42 | char oip[MAXLEN]; | |
43 | char user[MAXLEN]; | |
44 | char ouser[MAXLEN]; | |
45 | char date[15]; | |
46 | char date2[15]; | |
47 | char hour[15]; | |
25697a35 GS |
48 | char *str; |
49 | int z=0; | |
50 | int count=0; | |
9c7c6346 | 51 | struct getwordstruct gwarea; |
25697a35 GS |
52 | |
53 | ouser[0]='\0'; | |
54 | ||
55 | sprintf(dansguardian_in,"%s/dansguardian.log",tmp); | |
56 | if(!dansguardian_count) { | |
57 | unlink(dansguardian_in); | |
58 | return; | |
59 | } | |
60 | ||
d6e703cc | 61 | sprintf(per,"%s/sarg-period",dirname); |
25697a35 GS |
62 | sprintf(report,"%s/dansguardian.html",dirname); |
63 | ||
64 | if ((fp_in = fopen(per, "r")) == 0) { | |
65 | fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[45],per); | |
66 | exit(1); | |
67 | } | |
68 | ||
05b90947 FM |
69 | if (!fgets(period,sizeof(period),fp_in)) { |
70 | fprintf(stderr,"SARG: (dansguardian_report) read error in %s\n",per); | |
71 | exit(1); | |
72 | } | |
25697a35 GS |
73 | fclose(fp_in); |
74 | ||
936c9905 | 75 | if((fp_in=MY_FOPEN(dansguardian_in,"r"))==NULL) { |
25697a35 GS |
76 | fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],dansguardian_in); |
77 | exit(1); | |
78 | } | |
79 | ||
936c9905 | 80 | if((fp_ou=MY_FOPEN(report,"w"))==NULL) { |
25697a35 GS |
81 | fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],report); |
82 | exit(1); | |
83 | } | |
84 | ||
d6e703cc | 85 | fprintf(fp_ou, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet); |
25697a35 GS |
86 | css(fp_ou); |
87 | fputs("</head>\n",fp_ou); | |
d6e703cc FM |
88 | if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace); |
89 | fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage); | |
dfb337be FM |
90 | write_logo_image(fp_ou); |
91 | ||
0349fa24 | 92 | if(IndexTree == INDEX_TREE_DATE) |
491b862f GS |
93 | show_sarg(fp_ou, "../../.."); |
94 | else | |
95 | show_sarg(fp_ou,".."); | |
dfb337be | 96 | fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou); |
354c1a68 | 97 | fprintf(fp_ou,"<tr><th class=\"title\">%s</th></tr>\n",Title); |
25697a35 | 98 | |
b18ce4a0 FM |
99 | fprintf(fp_ou,"<tr><td class=\"header_l\">%s: %s</td></tr>\n",text[89],period); |
100 | fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",text[128]); | |
dfb337be | 101 | fputs("</table></div>\n",fp_ou); |
25697a35 | 102 | |
dfb337be | 103 | fputs("<div align=\"center\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou); |
25697a35 | 104 | fputs("<tr><td></td></tr>\n",fp_ou); |
b18ce4a0 | 105 | fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[98],text[111],text[110],text[91],text[129]); |
25697a35 GS |
106 | |
107 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
9c7c6346 FM |
108 | getword_start(&gwarea,buf); |
109 | if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,sizeof(date2),&gwarea,'\t')<0 || | |
110 | getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 || | |
111 | getword(url,sizeof(url),&gwarea,'\t')<0 || getword(rule,sizeof(rule),&gwarea,'\n')<0) { | |
4bcb77cf FM |
112 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in); |
113 | exit(1); | |
114 | } | |
25697a35 | 115 | |
246c8489 | 116 | if(UserIp) |
25697a35 GS |
117 | strcpy(user,ip); |
118 | ||
119 | bzero(date, 15); | |
120 | if(strncmp(df,"u",1) != 0) { | |
121 | strncpy(date,date2+6,2); | |
122 | strcat(date,"/"); | |
123 | strncat(date,date2+4,2); | |
124 | strcat(date,"/"); | |
125 | strncat(date,date2,4); | |
126 | } else { | |
127 | strncpy(date,date2+4,2); | |
128 | strcat(date,"/"); | |
129 | strncat(date,date2+6,2); | |
130 | strcat(date,"/"); | |
131 | strncat(date,date2,4); | |
132 | } | |
133 | ||
134 | if((str=(char *) strstr(user, "_")) != (char *) NULL ) { | |
135 | if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) | |
136 | fixip(user); | |
137 | } | |
138 | ||
246c8489 | 139 | if(Ip2Name) |
a1c55d8c | 140 | ip2name(ip,sizeof(ip)); |
25697a35 GS |
141 | |
142 | if(!z) { | |
143 | strcpy(ouser,user); | |
144 | strcpy(oip,ip); | |
145 | z++; | |
146 | } else { | |
147 | if(strcmp(ouser,user) == 0) | |
148 | user[0]='\0'; | |
149 | if(user[0] != '\0') | |
150 | strcpy(ouser,user); | |
120d768c | 151 | if(strcmp(oip,ip) == 0) |
25697a35 GS |
152 | ip[0]='\0'; |
153 | if(ip[0] != '\0') | |
154 | strcpy(oip,ip); | |
155 | } | |
156 | ||
965c4a6f | 157 | user_find(name, sizeof(name), user); |
25697a35 | 158 | |
48864d28 FM |
159 | if(dotinuser && strchr(name,'_')) { |
160 | subs(name,sizeof(name),"_","."); | |
94ff9470 GS |
161 | } |
162 | ||
25697a35 GS |
163 | if(DansGuardianReportLimit) { |
164 | if(strcmp(ouser2,name) == 0) { | |
165 | count++; | |
166 | } else { | |
167 | count=1; | |
168 | strcpy(ouser2,name); | |
169 | } | |
170 | if(count >= DansGuardianReportLimit) | |
171 | continue; | |
172 | } | |
173 | ||
354c1a68 | 174 | fprintf(fp_ou,"<tr><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s-%s</td><td class=\"data2\" nospaw><a href=\"http://%s\">%s</a></td><td class=\"data2\" nospaw>%s</td></tr>\n",name,ip,date,hour,url,url,rule); |
25697a35 GS |
175 | } |
176 | ||
177 | fputs("</table>\n",fp_ou); | |
178 | ||
179 | show_info(fp_ou); | |
120d768c | 180 | |
25697a35 GS |
181 | fputs("</body>\n</html>\n",fp_ou); |
182 | ||
183 | fclose(fp_in); | |
184 | fclose(fp_ou); | |
185 | ||
186 | unlink(dansguardian_in); | |
187 | ||
188 | return; | |
189 | } |