]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
e99bf0c0 | 3 | * 1998, 2013 |
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 | |
085c1e1f FM |
30 | #define SET_LIST(list) list,sizeof(list)/sizeof(list[0]) |
31 | ||
25697a35 GS |
32 | extern numlist hours, weekdays; |
33 | ||
085c1e1f FM |
34 | struct param_list |
35 | { | |
9bd92830 FM |
36 | //! The name of the value of the parameter. |
37 | const char *name; | |
38 | //! The bit to set if the value is found. | |
39 | unsigned long int value; | |
40 | //! The value is invalid if any bit of this mask is set in the parameter. | |
41 | unsigned long int exclude; | |
085c1e1f FM |
42 | }; |
43 | ||
15d5372b FM |
44 | struct sort_list |
45 | { | |
9bd92830 FM |
46 | //! The name of the value of the parameter. |
47 | const char *name; | |
48 | //! The bit to set if the value is found. | |
49 | unsigned long int value; | |
15d5372b FM |
50 | }; |
51 | ||
e43854ef | 52 | static struct param_list report_type_values[]= |
085c1e1f | 53 | { |
9bd92830 FM |
54 | {"users_sites",REPORT_TYPE_USERS_SITES,0}, |
55 | {"topusers",REPORT_TYPE_TOPUSERS,0}, | |
56 | {"topsites",REPORT_TYPE_TOPSITES,0}, | |
57 | {"sites_users",REPORT_TYPE_SITES_USERS,0}, | |
58 | {"date_time",REPORT_TYPE_DATE_TIME,0}, | |
59 | {"denied",REPORT_TYPE_DENIED,0}, | |
60 | {"auth_failures",REPORT_TYPE_AUTH_FAILURES,0}, | |
61 | {"site_user_time_date",REPORT_TYPE_SITE_USER_TIME_DATE,0}, | |
62 | {"downloads",REPORT_TYPE_DOWNLOADS,0}, | |
085c1e1f FM |
63 | }; |
64 | ||
e43854ef | 65 | static struct param_list data_field_values[]= |
085c1e1f | 66 | { |
9bd92830 FM |
67 | {"user",DATA_FIELD_USER,0}, |
68 | {"date",DATA_FIELD_DATE,0}, | |
69 | {"time",DATA_FIELD_TIME,0}, | |
70 | {"url",DATA_FIELD_URL,0}, | |
71 | {"connect",DATA_FIELD_CONNECT,0}, | |
72 | {"bytes",DATA_FIELD_BYTES,0}, | |
73 | {"in_cache",DATA_FIELD_IN_CACHE,0}, | |
74 | {"out_cache",DATA_FIELD_OUT_CACHE,0}, | |
75 | {"elapsed",DATA_FIELD_ELAPSED,0}, | |
085c1e1f FM |
76 | }; |
77 | ||
e43854ef | 78 | static struct param_list topuserfields_values[]= |
085c1e1f | 79 | { |
9bd92830 FM |
80 | {"NUM",TOPUSERFIELDS_NUM,0}, |
81 | {"DATE_TIME",TOPUSERFIELDS_DATE_TIME,0}, | |
82 | {"USERID",TOPUSERFIELDS_USERID,0}, | |
83 | {"CONNECT",TOPUSERFIELDS_CONNECT,0}, | |
84 | {"BYTES",TOPUSERFIELDS_BYTES,0}, | |
85 | {"%BYTES",TOPUSERFIELDS_SETYB,0}, | |
86 | {"SETYB",TOPUSERFIELDS_SETYB,0}, | |
87 | {"IN-CACHE-OUT",TOPUSERFIELDS_IN_CACHE_OUT,0}, | |
88 | {"USED_TIME",TOPUSERFIELDS_USED_TIME,0}, | |
89 | {"MILISEC",TOPUSERFIELDS_MILISEC,0}, | |
90 | {"%TIME",TOPUSERFIELDS_PTIME,0}, | |
91 | {"TOTAL",TOPUSERFIELDS_TOTAL,0}, | |
92 | {"AVERAGE",TOPUSERFIELDS_AVERAGE,0}, | |
085c1e1f FM |
93 | }; |
94 | ||
e43854ef | 95 | static struct param_list userreportfields_values[]= |
085c1e1f | 96 | { |
9bd92830 FM |
97 | {"CONNECT",USERREPORTFIELDS_CONNECT,0}, |
98 | {"BYTES",USERREPORTFIELDS_BYTES,0}, | |
99 | {"%BYTES",USERREPORTFIELDS_SETYB,0}, | |
100 | {"SETYB",USERREPORTFIELDS_SETYB,0}, | |
101 | {"IN-CACHE-OUT",USERREPORTFIELDS_IN_CACHE_OUT,0}, | |
102 | {"USED_TIME",USERREPORTFIELDS_USED_TIME,0}, | |
103 | {"MILISEC",USERREPORTFIELDS_MILISEC,0}, | |
104 | {"%TIME",USERREPORTFIELDS_PTIME,0}, | |
105 | {"TOTAL",USERREPORTFIELDS_TOTAL,0}, | |
106 | {"AVERAGE",USERREPORTFIELDS_AVERAGE,0}, | |
085c1e1f FM |
107 | }; |
108 | ||
e43854ef | 109 | static struct param_list index_values[]= |
0349fa24 | 110 | { |
9bd92830 FM |
111 | {"yes",INDEX_YES,~INDEX_YES}, |
112 | {"no",INDEX_NO,~INDEX_NO}, | |
113 | {"only",INDEX_ONLY,~INDEX_ONLY}, | |
0349fa24 FM |
114 | }; |
115 | ||
e43854ef | 116 | static struct param_list index_tree_values[]= |
0349fa24 | 117 | { |
9bd92830 FM |
118 | {"date",INDEX_TREE_DATE,~INDEX_TREE_DATE}, |
119 | {"file",INDEX_TREE_FILE,~INDEX_TREE_FILE}, | |
0349fa24 FM |
120 | }; |
121 | ||
9aaa3361 FM |
122 | static struct param_list indexfields_values[]= |
123 | { | |
124 | {"DIRSIZE",INDEXFIELDS_DIRSIZE,0}, | |
125 | }; | |
126 | ||
e43854ef | 127 | static struct param_list ntml_userformat_values[]= |
f2ec8c75 | 128 | { |
9bd92830 FM |
129 | {"user",NTLMUSERFORMAT_USER,~NTLMUSERFORMAT_USER}, |
130 | {"domainname+username",NTLMUSERFORMAT_DOMAINUSER,~NTLMUSERFORMAT_DOMAINUSER}, | |
f2ec8c75 FM |
131 | }; |
132 | ||
e43854ef | 133 | static struct param_list recnouser_values[]= |
f2ec8c75 | 134 | { |
9bd92830 FM |
135 | {"ip",RECORDWITHOUTUSER_IP,~RECORDWITHOUTUSER_IP}, |
136 | {"ignore",RECORDWITHOUTUSER_IGNORE,~RECORDWITHOUTUSER_IGNORE}, | |
137 | {"everybody",RECORDWITHOUTUSER_EVERYBODY,~RECORDWITHOUTUSER_EVERYBODY}, | |
f2ec8c75 FM |
138 | }; |
139 | ||
e43854ef | 140 | static struct param_list datafileurl_values[]= |
f84a35a3 | 141 | { |
9bd92830 FM |
142 | {"ip",DATAFILEURL_IP,~DATAFILEURL_IP}, |
143 | {"name",DATAFILEURL_NAME,~DATAFILEURL_NAME}, | |
f84a35a3 FM |
144 | }; |
145 | ||
e43854ef FM |
146 | static struct param_list displayvalue_values[]= |
147 | { | |
9bd92830 FM |
148 | {"bytes",DISPLAY_BYTES,~DISPLAY_BYTES}, |
149 | {"abbreviation",DISPLAY_ABBREV,~DISPLAY_ABBREV}, | |
e43854ef FM |
150 | }; |
151 | ||
43cc1649 FM |
152 | static struct param_list datetime_values[]= |
153 | { | |
9bd92830 FM |
154 | {"elap",DATETIME_ELAP,0}, |
155 | {"bytes",DATETIME_BYTE,0}, | |
43cc1649 FM |
156 | }; |
157 | ||
71d78774 FM |
158 | static struct param_list realtime_unauth_values[]= |
159 | { | |
9bd92830 FM |
160 | {"show",REALTIME_UNAUTH_REC_SHOW,~REALTIME_UNAUTH_REC_SHOW}, |
161 | {"ignore",REALTIME_UNAUTH_REC_IGNORE,~REALTIME_UNAUTH_REC_IGNORE}, | |
71d78774 FM |
162 | }; |
163 | ||
15d5372b FM |
164 | struct sort_list topuser_sort[]= |
165 | { | |
9bd92830 FM |
166 | {"BYTES",TOPUSER_SORT_BYTES}, |
167 | {"USER",TOPUSER_SORT_USER}, | |
168 | {"CONNECT",TOPUSER_SORT_CONNECT}, | |
169 | {"TIME",TOPUSER_SORT_TIME}, | |
15d5372b FM |
170 | }; |
171 | ||
172 | struct sort_list topsite_sort[]= | |
173 | { | |
9bd92830 FM |
174 | {"BYTES",TOPSITE_SORT_BYTES}, |
175 | {"CONNECT",TOPSITE_SORT_CONNECT}, | |
176 | {"TIME",TOPSITE_SORT_TIME}, | |
7d82ea1a | 177 | {"USER",TOPSITE_SORT_USER}, |
15d5372b FM |
178 | }; |
179 | ||
180 | struct sort_list user_sort[]= | |
181 | { | |
9bd92830 FM |
182 | {"BYTES",USER_SORT_BYTES}, |
183 | {"SITE",USER_SORT_SITE}, | |
184 | {"CONNECT",USER_SORT_CONNECT}, | |
185 | {"TIME",USER_SORT_TIME}, | |
15d5372b FM |
186 | }; |
187 | ||
6e792ade | 188 | static int is_param(const char *param,const char *buf) |
0a4e18e1 | 189 | { |
9bd92830 | 190 | int plen; |
0a4e18e1 | 191 | |
9bd92830 FM |
192 | plen=strlen(param); |
193 | if (strncmp(buf,param,plen) != 0) return(0); | |
194 | buf+=plen; | |
195 | if ((unsigned char)*buf>' ') return(0); | |
196 | return(1); | |
0a4e18e1 FM |
197 | } |
198 | ||
4af2f8ff FM |
199 | static int getparam_string(const char *param,char *buf,char *value,int value_size) |
200 | { | |
9bd92830 FM |
201 | int plen; |
202 | ||
203 | plen=strlen(param); | |
204 | if (strncmp(buf,param,plen) != 0) return(0); | |
205 | buf+=plen; | |
206 | if ((unsigned char)*buf>' ') return(0); | |
207 | while (*buf && (unsigned char)*buf<=' ') buf++; | |
208 | ||
209 | if (strlen(buf)>=value_size) { | |
210 | debuga(_("The string value of parameter \"%s\" is too long\n"),param); | |
211 | exit(EXIT_FAILURE); | |
212 | } | |
213 | strcpy(value,buf); | |
214 | fixnone(value); | |
215 | return(1); | |
4af2f8ff | 216 | } |
25697a35 | 217 | |
4af2f8ff | 218 | static int getparam_quoted(const char *param,char *buf,char *value,int value_size) |
25697a35 | 219 | { |
9bd92830 FM |
220 | int plen; |
221 | int i; | |
222 | ||
223 | plen=strlen(param); | |
224 | if (strncmp(buf,param,plen) != 0) return(0); | |
225 | buf+=plen; | |
226 | if ((unsigned char)*buf>' ') return(0); | |
227 | while (*buf && (unsigned char)*buf<=' ') buf++; | |
228 | ||
229 | if (*buf != '\"') { | |
230 | debuga(_("Missing double quote after parameter \"%s\"\n"),param); | |
231 | exit(EXIT_FAILURE); | |
232 | } | |
233 | buf++; | |
234 | ||
235 | value_size--; | |
236 | for (i=0 ; i<value_size && *buf && *buf!='\"' ; i++) { | |
237 | value[i]=*buf++; | |
238 | } | |
239 | value[i]='\0'; | |
240 | ||
241 | if (*buf != '\"') { | |
242 | debuga(_("Missing double quote after parameter \"%s\" or value is more than %d bytes long\n"),param,value_size); | |
243 | exit(EXIT_FAILURE); | |
244 | } | |
245 | fixnone(value); | |
246 | return(1); | |
4af2f8ff | 247 | } |
25697a35 | 248 | |
4af2f8ff FM |
249 | static int getparam_2words(const char *param,char *buf,char *word1,int word1_size,char *word2,int word2_size) |
250 | { | |
9bd92830 FM |
251 | int plen; |
252 | int i; | |
253 | ||
254 | plen=strlen(param); | |
255 | if (strncmp(buf,param,plen) != 0) return(0); | |
256 | buf+=plen; | |
257 | if ((unsigned char)*buf>' ') return(0); | |
258 | while (*buf && (unsigned char)*buf<=' ') buf++; | |
259 | ||
260 | for (i=0 ; i<word1_size && *buf && (unsigned char)*buf>' ' ; i++) | |
261 | word1[i]=*buf++; | |
262 | if (i>=word1_size) { | |
263 | debuga(_("The first word of parameter \"%s\" is more than %d bytes long\n"),param,word1_size-1); | |
264 | exit(EXIT_FAILURE); | |
265 | } | |
266 | if (*buf!=' ') { | |
267 | debuga(_("Missing second word for parameter \"%s\"\n"),param); | |
268 | exit(EXIT_FAILURE); | |
269 | } | |
270 | word1[i]=0; | |
271 | ||
272 | while (*buf && (unsigned char)*buf<=' ') buf++; | |
273 | ||
274 | for (i=0 ; i<word2_size && *buf && (unsigned char)*buf>' ' ; i++) | |
275 | word2[i]=*buf++; | |
276 | if (i>=word2_size) { | |
277 | debuga(_("The second word of parameter \"%s\" is more than %d bytes long\n"),param,word2_size-1); | |
278 | exit(EXIT_FAILURE); | |
279 | } | |
280 | word2[i]=0; | |
281 | ||
282 | fixnone(word1); | |
283 | fixnone(word2); | |
284 | return(1); | |
4af2f8ff | 285 | } |
25697a35 | 286 | |
4af2f8ff FM |
287 | static int getparam_int(const char *param,char *buf,int *value) |
288 | { | |
9bd92830 FM |
289 | int plen; |
290 | int next; | |
291 | ||
292 | plen=strlen(param); | |
293 | if (strncmp(buf,param,plen) != 0) return(0); | |
294 | buf+=plen; | |
295 | if ((unsigned char)*buf>' ') return(0); | |
296 | while (*buf && (unsigned char)*buf<=' ') buf++; | |
297 | ||
298 | next=0; | |
299 | if (sscanf(buf,"%d%n",value,&next) != 1 || (unsigned char)buf[next] > ' ') { | |
300 | debuga(_("The integer value of parameter \"%s\" is invalid\n"),param); | |
301 | exit(EXIT_FAILURE); | |
302 | } | |
303 | return(1); | |
4af2f8ff | 304 | } |
25697a35 | 305 | |
06b39c87 | 306 | static int getparam_bool(const char *param,char *buf,bool *value) |
246c8489 | 307 | { |
9bd92830 FM |
308 | int plen; |
309 | int i; | |
310 | const char *bool_str="yes,true,on,1"; | |
311 | ||
312 | plen=strlen(param); | |
313 | if (strncmp(buf,param,plen) != 0) return(0); | |
314 | buf+=plen; | |
315 | if ((unsigned char)*buf>' ') return(0); | |
316 | while (*buf && (unsigned char)*buf<=' ') buf++; | |
317 | ||
318 | *value=false; | |
319 | for ( ; *bool_str ; bool_str+=i) { | |
320 | for (i=0 ; bool_str[i] && bool_str[i]!=',' ; i++); | |
321 | if (strncasecmp(bool_str,buf,i)==0) { | |
322 | *value=true; | |
323 | break; | |
324 | } | |
325 | if (bool_str[i]==',') i++; | |
326 | } | |
327 | return(1); | |
246c8489 FM |
328 | } |
329 | ||
085c1e1f FM |
330 | static int getparam_list(const char *param,struct param_list *options,int noptions,char *buf,unsigned long int *value) |
331 | { | |
9bd92830 FM |
332 | int plen; |
333 | char *str; | |
334 | int i; | |
335 | ||
336 | plen=strlen(param); | |
337 | if (strncmp(buf,param,plen) != 0) return(0); | |
338 | buf+=plen; | |
339 | if ((unsigned char)*buf>' ') return(0); | |
340 | while (*buf && (unsigned char)*buf<=' ') buf++; | |
341 | ||
342 | *value=0UL; | |
343 | while (*buf) { | |
344 | str=buf; | |
345 | while (*str && (unsigned char)*str>' ' && *str!=';') str++; | |
346 | if (*str) { | |
347 | *str++='\0'; | |
348 | while (*str && ((unsigned char)*str<=' ' || *str==';')) str++; | |
349 | } | |
350 | for (i=0 ; i<noptions && strcasecmp(buf,options[i].name) ; i++); | |
351 | if (i>=noptions) { | |
352 | debuga(_("Unknown value \"%s\" for parameter \"%s\"\n"),buf,param); | |
353 | exit(EXIT_FAILURE); | |
354 | } | |
355 | if ((*value & options[i].exclude)!=0) { | |
356 | debuga(_("Value \"%s\" conflicts with other selected values for parameter \"%s\"\n"),buf,param); | |
357 | exit(EXIT_FAILURE); | |
358 | } | |
359 | *value|=options[i].value; | |
360 | buf=str; | |
361 | } | |
362 | return(1); | |
085c1e1f FM |
363 | } |
364 | ||
15d5372b FM |
365 | static int getparam_sort(const char *param,struct sort_list *options,int noptions,char *buf,unsigned long int *value) |
366 | { | |
9bd92830 FM |
367 | int plen; |
368 | char *str, *order; | |
369 | int i; | |
370 | ||
371 | plen=strlen(param); | |
372 | if (strncmp(buf,param,plen) != 0) return(0); | |
373 | buf+=plen; | |
374 | if ((unsigned char)*buf>' ') return(0); | |
375 | while (*buf && (unsigned char)*buf<=' ') buf++; | |
376 | ||
377 | str=buf; | |
378 | order=NULL; | |
379 | while (*str && (unsigned char)*str>' ') str++; | |
380 | if (*str) { | |
381 | *str++='\0'; | |
382 | while (*str && (unsigned char)*str<=' ') str++; | |
383 | order=str; | |
384 | } | |
385 | for (i=0 ; i<noptions && strcasecmp(buf,options[i].name) ; i++); | |
386 | if (i>=noptions) { | |
387 | debuga(_("Unknown sort criterion \"%s\" for parameter \"%s\"\n"),buf,param); | |
388 | exit(EXIT_FAILURE); | |
389 | } | |
390 | *value=options[i].value; | |
391 | ||
392 | if (order) { | |
393 | str=order; | |
394 | while (*str && (unsigned char)*str>' ') str++; | |
395 | if (*str) { | |
396 | *str++='\0'; | |
397 | while (*str && (unsigned char)*str<=' ') str++; | |
398 | } | |
399 | if (strcasecmp(order,"reverse")==0 || strcasecmp(order,"D")==0) { | |
400 | *value|=SORT_REVERSE; | |
401 | } else if (strcasecmp(order,"normal")!=0 && strcasecmp(order,"A")!=0) { | |
402 | debuga(_("Unknown sort order \"%s\" for parameter \"%s\"\n"),order,param); | |
403 | exit(EXIT_FAILURE); | |
404 | } | |
405 | } | |
406 | ||
407 | buf=str; | |
408 | return(1); | |
15d5372b FM |
409 | } |
410 | ||
4af2f8ff FM |
411 | static void parmtest(char *buf) |
412 | { | |
9bd92830 FM |
413 | char wbuf[2048]; |
414 | struct getwordstruct gwarea; | |
25697a35 | 415 | |
9bd92830 | 416 | while (*buf && (unsigned char)*buf<=' ') buf++; |
25697a35 | 417 | |
9bd92830 FM |
418 | if(*buf == '#' || *buf == '\0') |
419 | return; | |
25697a35 | 420 | |
9bd92830 FM |
421 | if(debugz) |
422 | printf(_("SARG: TAG: %s\n"),buf); | |
25697a35 | 423 | |
9bd92830 | 424 | if (getparam_string("background_color",buf,BgColor,sizeof(BgColor))>0) return; |
25697a35 | 425 | |
9bd92830 | 426 | if (getparam_string("text_color",buf,TxColor,sizeof(TxColor))>0) return; |
25697a35 | 427 | |
9bd92830 | 428 | if (getparam_string("text_bgcolor",buf,TxBgColor,sizeof(TxBgColor))>0) return; |
25697a35 | 429 | |
9bd92830 | 430 | if (getparam_string("title_color",buf,TiColor,sizeof(TiColor))>0) return; |
25697a35 | 431 | |
9bd92830 | 432 | if (getparam_string("logo_image",buf,LogoImage,sizeof(LogoImage))>0) return; |
25697a35 | 433 | |
9bd92830 | 434 | if (getparam_quoted("logo_text",buf,LogoText,sizeof(LogoText))>0) return; |
25697a35 | 435 | |
9bd92830 | 436 | if (getparam_string("logo_text_color",buf,LogoTextColor,sizeof(LogoTextColor))>0) return; |
25697a35 | 437 | |
9bd92830 | 438 | if (getparam_string("background_image",buf,BgImage,sizeof(BgImage))>0) return; |
25697a35 | 439 | |
9bd92830 | 440 | if (getparam_bool("show_sarg_info",buf,&ShowSargInfo)>0) return; |
25697a35 | 441 | |
9bd92830 | 442 | if (getparam_bool("show_sarg_logo",buf,&ShowSargLogo)>0) return; |
25697a35 | 443 | |
9bd92830 | 444 | if (getparam_string("font_face",buf,FontFace,sizeof(FontFace))>0) return; |
25697a35 | 445 | |
9bd92830 | 446 | if (getparam_string("header_color",buf,HeaderColor,sizeof(HeaderColor))>0) return; |
25697a35 | 447 | |
9bd92830 | 448 | if (getparam_string("header_bgcolor",buf,HeaderBgColor,sizeof(HeaderBgColor))>0) return; |
25697a35 | 449 | |
9bd92830 | 450 | if (getparam_string("font_size",buf,FontSize,sizeof(FontSize))>0) return; |
25697a35 | 451 | |
9bd92830 | 452 | if (getparam_string("header_font_size",buf,HeaderFontSize,sizeof(HeaderFontSize))>0) return; |
25697a35 | 453 | |
9bd92830 | 454 | if (getparam_string("title_font_size",buf,TitleFontSize,sizeof(TitleFontSize))>0) return; |
25697a35 | 455 | |
9bd92830 | 456 | if (getparam_2words("image_size",buf,Width,sizeof(Width),Height,sizeof(Height))>0) return; |
25697a35 | 457 | |
9bd92830 | 458 | if (getparam_quoted("title",buf,Title,sizeof(Title))>0) return; |
25697a35 | 459 | |
51b166d4 FM |
460 | if (strncasecmp(buf,"resolve_ip",10)==0) { |
461 | if (ip2name_config(buf+10)>0) return; | |
462 | } | |
25697a35 | 463 | |
9bd92830 | 464 | if (getparam_bool("user_ip",buf,&UserIp)>0) return; |
4af2f8ff | 465 | |
9bd92830 | 466 | if (getparam_string("max_elapsed",buf,MaxElapsed,sizeof(MaxElapsed))>0) return; |
25697a35 | 467 | |
9bd92830 FM |
468 | if (is_param("date_format",buf)) { |
469 | getword_start(&gwarea,buf); | |
470 | if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) { | |
a968fba4 | 471 | debuga(_("Invalid value in the \"date_format\" parameter\n")); |
9bd92830 FM |
472 | exit(EXIT_FAILURE); |
473 | } | |
474 | strncpy(DateFormat,gwarea.current,1); | |
475 | fixnone(DateFormat); | |
476 | return; | |
477 | } | |
25697a35 | 478 | |
9bd92830 FM |
479 | if (is_param("hours",buf)) { |
480 | if( getnumlist( buf, &hours, 24, 24 ) ) { | |
481 | debuga(_("Error: Invalid syntax in hours tag!\n")); | |
482 | exit( 1 ); | |
483 | } | |
484 | return; | |
485 | } | |
25697a35 | 486 | |
9bd92830 FM |
487 | if (is_param("weekdays",buf)) { |
488 | if( getnumlist( buf, &weekdays, 7, 7 ) ) { | |
489 | debuga(_("Error: Invalid syntax in weekdays tag!\n")); | |
490 | exit( 1 ); | |
491 | } | |
492 | return; | |
493 | } | |
25697a35 | 494 | |
9bd92830 | 495 | if (getparam_sort("topuser_sort_field",SET_LIST(topuser_sort),buf,&TopuserSort)>0) return; |
25697a35 | 496 | |
9bd92830 | 497 | if (getparam_sort("user_sort_field",SET_LIST(user_sort),buf,&UserSort)>0) return; |
25697a35 | 498 | |
9bd92830 FM |
499 | if (is_param("access_log",buf)>0) { |
500 | if (AccessLogFromCmdLine==0) { | |
501 | if (NAccessLog>=MAXLOGS) { | |
502 | debuga(_("Too many log files in configuration file\n")); | |
503 | exit(EXIT_FAILURE); | |
504 | } | |
505 | getparam_string("access_log",buf,AccessLog[NAccessLog],MAX_LOG_FILELEN); | |
506 | NAccessLog++; | |
507 | } | |
508 | return; | |
509 | } | |
25697a35 | 510 | |
9bd92830 FM |
511 | if (is_param("redirector_log",buf)>0) { |
512 | if (RedirectorLogFromCmdLine==0) { | |
513 | if (NRedirectorLogs>=MAX_REDIRECTOR_LOGS) { | |
514 | debuga(_("Too many redirector log files in configuration file\n")); | |
515 | exit(EXIT_FAILURE); | |
516 | } | |
517 | getparam_string("redirector_log",buf,RedirectorLogs[NRedirectorLogs],MAX_REDIRECTOR_FILELEN); | |
518 | NRedirectorLogs++; | |
519 | } | |
520 | return; | |
521 | } | |
1f482a8d | 522 | |
9bd92830 | 523 | if (getparam_string("useragent_log",buf,UserAgentLog,sizeof(UserAgentLog))>0) return; |
25697a35 | 524 | |
9bd92830 | 525 | if (getparam_string("exclude_hosts",buf,ExcludeHosts,sizeof(ExcludeHosts))>0) return; |
25697a35 | 526 | |
9bd92830 | 527 | if (getparam_string("exclude_codes",buf,ExcludeCodes,sizeof(ExcludeCodes))>0) return; |
25697a35 | 528 | |
9bd92830 | 529 | if (getparam_string("exclude_users",buf,ExcludeUsers,sizeof(ExcludeUsers))>0) return; |
25697a35 | 530 | |
9bd92830 | 531 | if (getparam_string("password",buf,PasswdFile,sizeof(PasswdFile))>0) return; |
25697a35 | 532 | |
9bd92830 | 533 | if (getparam_string("temporary_dir",buf,TempDir,sizeof(TempDir))>0) return; |
25697a35 | 534 | |
9bd92830 | 535 | if (getparam_list("report_type",SET_LIST(report_type_values),buf,&ReportType)>0) return; |
25697a35 | 536 | |
9bd92830 | 537 | if (getparam_string("output_dir",buf,OutputDir,sizeof(OutputDir))>0) return; |
25697a35 | 538 | |
829a53c2 FM |
539 | if (getparam_bool("anonymous_output_files",buf,&AnonymousOutputFiles)>0) return; |
540 | ||
9bd92830 | 541 | if (getparam_string("output_email",buf,OutputEmail,sizeof(OutputEmail))>0) return; |
25697a35 | 542 | |
9bd92830 FM |
543 | if (getparam_2words("per_user_limit",buf,PerUserLimitFile,sizeof(PerUserLimitFile),wbuf,sizeof(wbuf))>0) { |
544 | PerUserLimit=atoi(wbuf); | |
545 | return; | |
546 | } | |
25697a35 | 547 | |
9bd92830 | 548 | if (getparam_int("lastlog",buf,&LastLog)>0) return; |
25697a35 | 549 | |
9bd92830 | 550 | if (getparam_bool("remove_temp_files",buf,&RemoveTempFiles)>0) return; |
25697a35 | 551 | |
9bd92830 | 552 | if (getparam_string("replace_index",buf,ReplaceIndex,sizeof(ReplaceIndex))>0) return; |
25697a35 | 553 | |
9bd92830 | 554 | if (getparam_list("index_tree",SET_LIST(index_tree_values),buf,&IndexTree)>0) return; |
25697a35 | 555 | |
9bd92830 | 556 | if (getparam_list("index",SET_LIST(index_values),buf,&Index)>0) return; |
25697a35 | 557 | |
9aaa3361 FM |
558 | if (getparam_list("index_fields",SET_LIST(indexfields_values),buf,&IndexFields)>0) return; |
559 | ||
9bd92830 | 560 | if (getparam_bool("overwrite_report",buf,&OverwriteReport)>0) return; |
25697a35 | 561 | |
9bd92830 | 562 | if (getparam_list("records_without_userid",SET_LIST(recnouser_values),buf,&RecordsWithoutUser)>0) return; |
25697a35 | 563 | |
9bd92830 | 564 | if (getparam_bool("use_comma",buf,&UseComma)>0) return; |
25697a35 | 565 | |
9bd92830 | 566 | if (getparam_string("mail_utility",buf,MailUtility,sizeof(MailUtility))>0) return; |
25697a35 | 567 | |
9bd92830 | 568 | if (getparam_int("topsites_num",buf,&TopSitesNum)>0) return; |
25697a35 | 569 | |
9bd92830 | 570 | if (getparam_int("topuser_num",buf,&TopUsersNum)>0) return; |
25697a35 | 571 | |
9bd92830 | 572 | if (getparam_string("usertab",buf,UserTabFile,sizeof(UserTabFile))>0) return; |
25697a35 | 573 | |
9bd92830 | 574 | if (getparam_string("index_sort_order",buf,IndexSortOrder,sizeof(IndexSortOrder))>0) return; |
25697a35 | 575 | |
9bd92830 | 576 | if (getparam_sort("topsites_sort_order",SET_LIST(topsite_sort),buf,&TopsitesSort)>0) return; |
25697a35 | 577 | |
9bd92830 | 578 | if (getparam_bool("long_url",buf,&LongUrl)>0) return; |
25697a35 | 579 | |
9bd92830 | 580 | if (getparam_string("dansguardian_conf",buf,DansGuardianConf,sizeof(DansGuardianConf))>0) return; |
25697a35 | 581 | |
9bd92830 | 582 | if (getparam_string("squidguard_conf",buf,SquidGuardConf,sizeof(SquidGuardConf))>0) return; |
25697a35 | 583 | |
9bd92830 | 584 | if (getparam_list("date_time_by",SET_LIST(datetime_values),buf,&datetimeby)>0) return; |
25697a35 | 585 | |
9bd92830 FM |
586 | if (getparam_string("charset",buf,CharSet,sizeof(CharSet))>0) { |
587 | ccharset(CharSet); | |
588 | return; | |
589 | } | |
25697a35 | 590 | |
9bd92830 | 591 | if (getparam_quoted("user_invalid_char",buf,UserInvalidChar,sizeof(UserInvalidChar))>0) return; |
25697a35 | 592 | |
9bd92830 FM |
593 | if (getparam_quoted("include_users",buf,IncludeUsers+1,sizeof(IncludeUsers)-2)>0) { |
594 | IncludeUsers[0]=':'; | |
595 | strcat(IncludeUsers,":"); | |
596 | return; | |
597 | } | |
491b862f | 598 | |
9bd92830 | 599 | if (getparam_quoted("exclude_string",buf,ExcludeString,sizeof(ExcludeString))>0) return; |
25697a35 | 600 | |
9bd92830 | 601 | if (getparam_bool("privacy",buf,&Privacy)>0) return; |
25697a35 | 602 | |
9bd92830 | 603 | if (getparam_quoted("privacy_string",buf,PrivacyString,sizeof(PrivacyString))>0) return; |
25697a35 | 604 | |
9bd92830 | 605 | if (getparam_string("privacy_string_color",buf,PrivacyStringColor,sizeof(PrivacyStringColor))>0) return; |
25697a35 | 606 | |
9bd92830 | 607 | if (getparam_bool("show_successful_message",buf,&SuccessfulMsg)>0) return; |
25697a35 | 608 | |
9bd92830 | 609 | if (getparam_bool("show_read_statistics",buf,&ShowReadStatistics)>0) return; |
25697a35 | 610 | |
9bd92830 | 611 | if (getparam_list("topuser_fields",SET_LIST(topuserfields_values),buf,&TopUserFields)>0) return; |
25697a35 | 612 | |
9bd92830 | 613 | if (getparam_bool("bytes_in_sites_users_report",buf,&BytesInSitesUsersReport)>0) return; |
25697a35 | 614 | |
9bd92830 | 615 | if (getparam_list("user_report_fields",SET_LIST(userreportfields_values),buf,&UserReportFields)>0) return; |
25697a35 | 616 | |
9bd92830 | 617 | if (getparam_string("datafile",buf,DataFile,sizeof(DataFile))>0) return; |
25697a35 | 618 | |
9bd92830 | 619 | if (getparam_quoted("datafile_delimiter",buf,DataFileDelimiter,sizeof(DataFileDelimiter))>0) return; |
25697a35 | 620 | |
9bd92830 | 621 | if (getparam_list("datafile_fields",SET_LIST(data_field_values),buf,&DataFileFields)>0) return; |
25697a35 | 622 | |
9bd92830 | 623 | if (getparam_list("datafile_url",SET_LIST(datafileurl_values),buf,&DataFileUrl)>0) return; |
25697a35 | 624 | |
9bd92830 | 625 | if (getparam_string("parsed_output_log",buf,ParsedOutputLog,sizeof(ParsedOutputLog))>0) return; |
25697a35 | 626 | |
9bd92830 | 627 | if (getparam_string("parsed_output_log_compress",buf,ParsedOutputLogCompress,sizeof(ParsedOutputLogCompress))>0) return; |
25697a35 | 628 | |
9bd92830 | 629 | if (getparam_list("displayed_values",SET_LIST(displayvalue_values),buf,&DisplayedValues)>0) return; |
25697a35 | 630 | |
9bd92830 | 631 | if (getparam_int("authfail_report_limit",buf,&AuthfailReportLimit)>0) return; |
25697a35 | 632 | |
9bd92830 | 633 | if (getparam_int("denied_report_limit",buf,&DeniedReportLimit)>0) return; |
25697a35 | 634 | |
9bd92830 | 635 | if (getparam_int("siteusers_report_limit",buf,&SiteUsersReportLimit)>0) return; |
25697a35 | 636 | |
9bd92830 | 637 | if (getparam_int("dansguardian_report_limit",buf,&DansGuardianReportLimit)>0) return; |
25697a35 | 638 | |
9bd92830 | 639 | if (getparam_int("squidguard_report_limit",buf,&SquidGuardReportLimit)>0) return; |
25697a35 | 640 | |
9bd92830 | 641 | if (getparam_int("user_report_limit",buf,&UserReportLimit)>0) return; |
491b862f | 642 | |
9bd92830 | 643 | if (getparam_int("download_report_limit",buf,&DownloadReportLimit)>0) return; |
491b862f | 644 | |
9bd92830 | 645 | if (getparam_string("www_document_root",buf,wwwDocumentRoot,sizeof(wwwDocumentRoot))>0) return; |
25697a35 | 646 | |
9bd92830 | 647 | if (getparam_string("block_it",buf,BlockIt,sizeof(BlockIt))>0) return; |
491b862f | 648 | |
9bd92830 | 649 | if (getparam_string("external_css_file",buf,ExternalCSSFile,sizeof(ExternalCSSFile))>0) return; |
491b862f | 650 | |
9bd92830 | 651 | if (getparam_bool("user_authentication",buf,&UserAuthentication)>0) return; |
491b862f | 652 | |
9bd92830 FM |
653 | if (getparam_string("AuthUserTemplateFile",buf,wbuf,sizeof(wbuf))>0) { |
654 | char dir[MAXLEN]; | |
491b862f | 655 | |
9bd92830 FM |
656 | if (is_absolute(wbuf)) { |
657 | if (strlen(wbuf)>=sizeof(AuthUserTemplateFile)) { | |
658 | debuga(_("Template file name is too long in parameter \"AuthUserTemplateFile\"\n")); | |
659 | exit(EXIT_FAILURE); | |
660 | } | |
a87d4d11 | 661 | safe_strcpy(AuthUserTemplateFile,wbuf,sizeof(AuthUserTemplateFile)); |
9bd92830 | 662 | } else { |
a87d4d11 | 663 | safe_strcpy(dir,ConfigFile,sizeof(dir)); |
9bd92830 FM |
664 | if (snprintf(AuthUserTemplateFile,sizeof(AuthUserTemplateFile),"%s/%s",dirname(dir),wbuf)>=sizeof(AuthUserTemplateFile)) { |
665 | debuga(_("Template file name is too long in parameter \"AuthUserTemplateFile\"\n")); | |
666 | exit(EXIT_FAILURE); | |
667 | } | |
668 | } | |
669 | return; | |
670 | } | |
4af2f8ff | 671 | |
9bd92830 FM |
672 | if (is_param("download_suffix",buf)) { |
673 | char warea[MAXLEN]; | |
6e792ade | 674 | |
9bd92830 FM |
675 | getparam_quoted("download_suffix",buf,warea,sizeof(warea)); |
676 | set_download_suffix(warea); | |
677 | return; | |
678 | } | |
d6e703cc | 679 | |
8ddc656a FM |
680 | if (getparam_bool("graphs",buf,&Graphs)>0) { |
681 | #ifndef HAVE_GD | |
682 | if (Graphs) | |
683 | debugaz(_("No graphs available as sarg was not compiled with libgd. Set \"graphs\" to \"no\" in %s to disable this warning\n"), | |
684 | ConfigFile); | |
685 | #endif | |
686 | return; | |
687 | } | |
4af2f8ff | 688 | |
9bd92830 | 689 | if (getparam_string("graph_days_bytes_bar_color",buf,GraphDaysBytesBarColor,sizeof(GraphDaysBytesBarColor))>0) return; |
4af2f8ff | 690 | |
9bd92830 FM |
691 | if (getparam_string("redirector_log_format",buf,RedirectorLogFormat,sizeof(RedirectorLogFormat))>0) return; |
692 | if (getparam_string("squidguard_log_format",buf,RedirectorLogFormat,sizeof(RedirectorLogFormat))>0) { | |
693 | debuga(_("squidguard_log_format is deprecated and has been replaced by redirector_log_format. Please update your configuration file.\n")); | |
694 | return; | |
695 | } | |
4af2f8ff | 696 | |
9bd92830 FM |
697 | if (getparam_bool("redirector_filter_out_date",buf,&RedirectorFilterOutDate)>0) return; |
698 | if (getparam_bool("redirector_ignore_date",buf,&RedirectorFilterOutDate)>0) { | |
699 | /* | |
700 | Due to an old bug in sarg before version 2.3, the option was having the opposite action than implied by the name. | |
701 | */ | |
702 | debuga(_("redirector_ignore_date is deprecated and has been replaced by redirector_filter_out_date that does the action implied by its name as opposed to redirector_ignore_date. Please update your configuration file.\n")); | |
703 | RedirectorFilterOutDate=!RedirectorFilterOutDate; | |
704 | return; | |
705 | } | |
706 | if (getparam_bool("squidguard_ignore_date",buf,&RedirectorFilterOutDate)>0) { | |
707 | debuga(_("squidguard_ignore_date is deprecated and has been replaced by redirector_filter_out_date that does the action implied by its name as opposed to squidguard_ignore_date. Please update your configuration file.\n")); | |
708 | RedirectorFilterOutDate=!RedirectorFilterOutDate; | |
709 | return; | |
710 | } | |
4af2f8ff | 711 | |
9bd92830 FM |
712 | if (getparam_bool("dansguardian_filter_out_date",buf,&DansguardianFilterOutDate)>0) return; |
713 | if (getparam_bool("dansguardian_ignore_date",buf,&DansguardianFilterOutDate)>0) { | |
714 | debuga(_("dansguardian_ignore_date is deprecated and has been replaced by dansguardian_filter_out_date that does the action implied by its name as opposed to dansguardian_ignore_date. Please update your configuration file.\n")); | |
715 | DansguardianFilterOutDate=!DansguardianFilterOutDate; | |
716 | return; | |
717 | } | |
4af2f8ff | 718 | |
9bd92830 | 719 | if (getparam_string("ulimit",buf,Ulimit,sizeof(Ulimit))>0) return; |
4af2f8ff | 720 | |
9bd92830 | 721 | if (getparam_list("ntlm_user_format",SET_LIST(ntml_userformat_values),buf,&NtlmUserFormat)>0) return; |
4af2f8ff | 722 | |
9bd92830 | 723 | if (getparam_string("realtime_types",buf,RealtimeTypes,sizeof(RealtimeTypes))>0) return; |
4af2f8ff | 724 | |
9bd92830 | 725 | if (getparam_list("realtime_unauthenticated_records",SET_LIST(realtime_unauth_values),buf,&RealtimeUnauthRec)>0) return; |
4af2f8ff | 726 | |
9bd92830 | 727 | if (getparam_int("realtime_refresh_time",buf,&realtime_refresh)>0) return; |
4af2f8ff | 728 | |
9bd92830 | 729 | if (getparam_int("realtime_access_log_lines",buf,&realtime_access_log_lines)>0) return; |
4af2f8ff | 730 | |
9bd92830 | 731 | if (getparam_string("LDAPHost",buf,LDAPHost,sizeof(LDAPHost))>0) return; |
e3af0ae9 | 732 | |
9bd92830 | 733 | if (getparam_int("LDAPPort",buf,&LDAPPort)>0) return; |
e3af0ae9 | 734 | |
9bd92830 | 735 | if (getparam_int("LDAPProtocolVersion",buf,&LDAPProtocolVersion)>0) return; |
e3af0ae9 | 736 | |
9bd92830 | 737 | if (getparam_string("LDAPBindDN",buf,LDAPBindDN,sizeof(LDAPBindDN))>0) return; |
e3af0ae9 | 738 | |
9bd92830 | 739 | if (getparam_string("LDAPBindPW",buf,LDAPBindPW,sizeof(LDAPBindPW))>0) return; |
e3af0ae9 | 740 | |
9bd92830 | 741 | if (getparam_string("LDAPBaseSearch",buf,LDAPBaseSearch,sizeof(LDAPBaseSearch))>0) return; |
e3af0ae9 | 742 | |
9bd92830 | 743 | if (getparam_string("LDAPFilterSearch",buf,LDAPFilterSearch,sizeof(LDAPFilterSearch))>0) return; |
e3af0ae9 | 744 | |
9bd92830 | 745 | if (getparam_string("LDAPTargetAttr",buf,LDAPTargetAttr,sizeof(LDAPTargetAttr))>0) return; |
e3af0ae9 | 746 | |
9bd92830 | 747 | if (getparam_string("graph_font",buf,GraphFont,sizeof(GraphFont))>0) return; |
3becf85c | 748 | |
9bd92830 | 749 | if (getparam_string("sorttable",buf,SortTableJs,sizeof(SortTableJs))>0) return; |
ea275279 | 750 | |
22715352 | 751 | if (getparam_string("hostalias",buf,HostAliasFile,sizeof(HostAliasFile))>0) return; |
11767c6a FM |
752 | |
753 | if (getparam_bool("keep_temp_log",buf,&KeepTempLog)>0) return; | |
22715352 | 754 | |
9bd92830 FM |
755 | if(strstr(buf,"squid24") != 0) { |
756 | squid24=true; | |
757 | return; | |
758 | } | |
4af2f8ff | 759 | |
9bd92830 FM |
760 | if(strstr(buf,"byte_cost") != 0) { |
761 | getword_start(&gwarea,buf); | |
762 | if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) { | |
763 | debuga(_("The \"byte_cost\" parameter of the configuration file is invalid\n")); | |
764 | exit(EXIT_FAILURE); | |
765 | } | |
766 | cost=atol(gwarea.current); | |
767 | if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) { | |
768 | debuga(_("The \"byte_cost\" parameter of the configuration file is invalid\n")); | |
769 | exit(EXIT_FAILURE); | |
770 | } | |
771 | nocost=my_atoll(gwarea.current); | |
772 | return; | |
773 | } | |
4af2f8ff | 774 | |
9bd92830 | 775 | printf(_("SARG: Unknown option %s\n"),buf); |
d6e703cc FM |
776 | } |
777 | ||
32e71fa4 | 778 | void getconf(void) |
d6e703cc | 779 | { |
9bd92830 FM |
780 | FILE *fp_in; |
781 | char buf[MAXLEN]; | |
d6e703cc | 782 | |
9bd92830 FM |
783 | if(debug) |
784 | debuga(_("Loading configuration from %s\n"),ConfigFile); | |
d6e703cc | 785 | |
9bd92830 | 786 | if ((fp_in = fopen(ConfigFile, "r")) == NULL) { |
4b06d570 | 787 | debugapos("getconf",_("Cannot open file \"%s\": %s\n"),ConfigFile,strerror(errno)); |
9bd92830 FM |
788 | exit(EXIT_FAILURE); |
789 | } | |
d6e703cc | 790 | |
9bd92830 FM |
791 | while (fgets(buf, sizeof(buf), fp_in) != NULL) { |
792 | fixendofline(buf); | |
d6e703cc | 793 | |
9bd92830 FM |
794 | if(debugm) |
795 | printf("SYSCONFDIR %s\n",buf); | |
d6e703cc | 796 | |
9bd92830 | 797 | parmtest(buf); |
d6e703cc | 798 | |
9bd92830 | 799 | } |
d6e703cc | 800 | |
9bd92830 FM |
801 | fclose(fp_in); |
802 | return; | |
25697a35 | 803 | } |