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