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