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