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