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