]> git.ipfire.org Git - thirdparty/sarg.git/blob - getconf.c
Fixed a regression in the usertab file not accepting IPv6 addresses any more.
[thirdparty/sarg.git] / getconf.c
1 /*
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
3 * 1998, 2010
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
5 *
6 * SARG donations:
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
23 *
24 */
25
26 #include "include/conf.h"
27 #include "include/defs.h"
28
29 extern numlist hours, weekdays;
30
31 static int is_param(const char *param,const char *buf)
32 {
33 int plen;
34
35 plen=strlen(param);
36 if (strncmp(buf,param,plen) != 0) return(0);
37 buf+=plen;
38 if ((unsigned char)*buf>' ') return(0);
39 return(1);
40 }
41
42 static int getparam_string(const char *param,char *buf,char *value,int value_size)
43 {
44 int plen;
45
46 plen=strlen(param);
47 if (strncmp(buf,param,plen) != 0) return(0);
48 buf+=plen;
49 if ((unsigned char)*buf>' ') return(0);
50 while (*buf && (unsigned char)*buf<=' ') buf++;
51
52 if (strlen(buf)>=value_size) {
53 printf("SARG: Maybe you have a broken record or garbage in %s parameter.\n",param);
54 exit(1);
55 }
56 strcpy(value,buf);
57 fixnone(value);
58 return(1);
59 }
60
61 static int getparam_quoted(const char *param,char *buf,char *value,int value_size)
62 {
63 int plen;
64 int i;
65
66 plen=strlen(param);
67 if (strncmp(buf,param,plen) != 0) return(0);
68 buf+=plen;
69 if ((unsigned char)*buf>' ') return(0);
70 while (*buf && (unsigned char)*buf<=' ') buf++;
71
72 if (*buf != '\"') {
73 printf("SARG: %s %s.\n",text[139],param);
74 exit(1);
75 }
76 buf++;
77
78 value_size--;
79 for (i=0 ; i<value_size && *buf && *buf!='\"' ; i++) {
80 value[i]=*buf++;
81 }
82 value[i]='\0';
83
84 if (*buf != '\"') {
85 printf("SARG: Missing double quote after parameter %s or value is more than %d bytes long.\n",param,value_size);
86 exit(1);
87 }
88 fixnone(value);
89 return(1);
90 }
91
92 static int getparam_2words(const char *param,char *buf,char *word1,int word1_size,char *word2,int word2_size)
93 {
94 int plen;
95 int i;
96
97 plen=strlen(param);
98 if (strncmp(buf,param,plen) != 0) return(0);
99 buf+=plen;
100 if ((unsigned char)*buf>' ') return(0);
101 while (*buf && (unsigned char)*buf<=' ') buf++;
102
103 for (i=0 ; i<word1_size && *buf && (unsigned char)*buf>' ' ; i++)
104 word1[i]=*buf++;
105 if (i>=word1_size) {
106 printf("SARG: The first word of parameter %s is more than %d bytes long.\n",param,word1_size-1);
107 exit(1);
108 }
109 if (*buf!=' ') {
110 printf("SARG: Missing second word for parameter %s.\n",param);
111 exit(1);
112 }
113 word1[i]=0;
114
115 while (*buf && (unsigned char)*buf<=' ') buf++;
116
117 for (i=0 ; i<word2_size && *buf && (unsigned char)*buf>' ' ; i++)
118 word2[i]=*buf++;
119 if (i>=word2_size) {
120 printf("SARG: The second word of parameter %s is more than %d bytes long.\n",param,word2_size-1);
121 exit(1);
122 }
123 word2[i]=0;
124
125 fixnone(word1);
126 fixnone(word2);
127 return(1);
128 }
129
130 static int getparam_int(const char *param,char *buf,int *value)
131 {
132 int plen;
133 int next;
134
135 plen=strlen(param);
136 if (strncmp(buf,param,plen) != 0) return(0);
137 buf+=plen;
138 if ((unsigned char)*buf>' ') return(0);
139 while (*buf && (unsigned char)*buf<=' ') buf++;
140
141 next=0;
142 if (sscanf(buf,"%d%n",value,&next) != 1 || (unsigned char)buf[next] > ' ') {
143 printf("SARG: Maybe you have a broken record or garbage in %s parameter.\n",param);
144 exit(1);
145 }
146 return(1);
147 }
148
149 static int getparam_bool(const char *param,char *buf,int *value)
150 {
151 int plen;
152 char *str;
153 int i;
154
155 plen=strlen(param);
156 if (strncmp(buf,param,plen) != 0) return(0);
157 buf+=plen;
158 if ((unsigned char)*buf>' ') return(0);
159 while (*buf && (unsigned char)*buf<=' ') buf++;
160
161 *value=0;
162 str=text[144];
163 if (str == NULL || *str == '\0') str="yes";
164 for ( ; *str ; str+=i) {
165 for (i=0 ; str[i] && str[i]!=',' ; i++);
166 if (strncasecmp(str,buf,i)==0) {
167 *value=1;
168 break;
169 }
170 if (str[i]==',') i++;
171 }
172 return(1);
173 }
174
175 static void parmtest(char *buf)
176 {
177 char wbuf[50];
178 struct getwordstruct gwarea;
179
180 while (*buf && (unsigned char)*buf<=' ') buf++;
181
182 if(*buf == '#' || *buf == '\0')
183 return;
184
185 if(debugz)
186 printf("SARG: TAG: %s\n",buf);
187
188 if (getparam_string("background_color",buf,BgColor,sizeof(BgColor))>0) return;
189
190 if (getparam_string("text_color",buf,TxColor,sizeof(TxColor))>0) return;
191
192 if (getparam_string("text_bgcolor",buf,TxBgColor,sizeof(TxBgColor))>0) return;
193
194 if (getparam_string("title_color",buf,TiColor,sizeof(TiColor))>0) return;
195
196 if (getparam_string("logo_image",buf,LogoImage,sizeof(LogoImage))>0) return;
197
198 if (getparam_quoted("logo_text",buf,LogoText,sizeof(LogoText))>0) return;
199
200 if (getparam_string("logo_text_color",buf,LogoTextColor,sizeof(LogoTextColor))>0) return;
201
202 if (getparam_string("background_image",buf,BgImage,sizeof(BgImage))>0) return;
203
204 if (getparam_bool("show_sarg_info",buf,&ShowSargInfo)>0) return;
205
206 if (getparam_bool("show_sarg_logo",buf,&ShowSargLogo)>0) return;
207
208 if (getparam_string("font_face",buf,FontFace,sizeof(FontFace))>0) return;
209
210 if (getparam_string("header_color",buf,HeaderColor,sizeof(HeaderColor))>0) return;
211
212 if (getparam_string("header_bgcolor",buf,HeaderBgColor,sizeof(HeaderBgColor))>0) return;
213
214 if (getparam_string("font_size",buf,FontSize,sizeof(FontSize))>0) return;
215
216 if (getparam_string("header_font_size",buf,HeaderFontSize,sizeof(HeaderFontSize))>0) return;
217
218 if (getparam_string("title_font_size",buf,TitleFontSize,sizeof(TitleFontSize))>0) return;
219
220 if (getparam_2words("image_size",buf,Width,sizeof(Width),Height,sizeof(Height))>0) return;
221
222 if (getparam_quoted("title",buf,Title,sizeof(Title))>0) return;
223
224 if (getparam_bool("resolve_ip",buf,&Ip2Name)>0) return;
225
226 if (getparam_bool("user_ip",buf,&UserIp)>0) return;
227
228 if (getparam_string("max_elapsed",buf,MaxElapsed,sizeof(MaxElapsed))>0) return;
229
230 if (is_param("date_format",buf)) {
231 getword_start(&gwarea,buf);
232 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
233 printf("SARG: Maybe you have a broken record or garbage in date_format parameter.\n");
234 exit(1);
235 }
236 strncpy(DateFormat,gwarea.current,1);
237 fixnone(DateFormat);
238 return;
239 }
240
241 if (is_param("hours",buf)) {
242 if( getnumlist( buf, &hours, 24, 24 ) ) {
243 fprintf( stderr, "Error: Invalid syntax in hours tag!\n" );
244 exit( 1 );
245 }
246 }
247
248 if (is_param("weekdays",buf)) {
249 if( getnumlist( buf, &weekdays, 7, 7 ) ) {
250 fprintf( stderr, "Error: Invalid syntax in weekdays tag!\n" );
251 exit( 1 );
252 }
253 }
254
255 if (getparam_2words("topuser_sort_field",buf,TopuserSortField,sizeof(TopuserSortField),TopuserSortOrder,sizeof(TopuserSortOrder))>0) return;
256
257 if (getparam_2words("user_sort_field",buf,UserSortField,sizeof(UserSortField),UserSortOrder,sizeof(UserSortOrder))>0) return;
258
259 if (is_param("access_log",buf)>0) {
260 if (AccessLogFromCmdLine==0) {
261 if (NAccessLog>=MAXLOGS) {
262 fprintf(stderr,"SARG: Too many log files.\n");
263 exit(1);
264 }
265 getparam_string("access_log",buf,AccessLog[NAccessLog],MAXLEN);
266 NAccessLog++;
267 }
268 return;
269 }
270
271 if (getparam_string("useragent_log",buf,UserAgentLog,sizeof(UserAgentLog))>0) return;
272
273 if (getparam_string("exclude_hosts",buf,ExcludeHosts,sizeof(ExcludeHosts))>0) return;
274
275 if (getparam_string("exclude_codes",buf,ExcludeCodes,sizeof(ExcludeCodes))>0) return;
276
277 if (getparam_string("exclude_users",buf,ExcludeUsers,sizeof(ExcludeUsers))>0) return;
278
279 if (getparam_string("password",buf,PasswdFile,sizeof(PasswdFile))>0) return;
280
281 if (getparam_string("temporary_dir",buf,TempDir,sizeof(TempDir))>0) return;
282
283 if (getparam_string("report_type",buf,ReportType,sizeof(ReportType))>0) return;
284
285 if (getparam_string("output_dir",buf,OutputDir,sizeof(OutputDir))>0) return;
286
287 if (getparam_string("output_email",buf,OutputEmail,sizeof(OutputEmail))>0) return;
288
289 if (getparam_2words("per_user_limit",buf,PerUserLimitFile,sizeof(PerUserLimitFile),wbuf,sizeof(wbuf))>0) {
290 PerUserLimit=atoi(wbuf);
291 return;
292 }
293
294 if (getparam_int("lastlog",buf,&LastLog)>0) return;
295
296 if (getparam_bool("remove_temp_files",buf,&RemoveTempFiles)>0) return;
297
298 if (getparam_string("replace_index",buf,ReplaceIndex,sizeof(ReplaceIndex))>0) return;
299
300 if (getparam_string("index_tree",buf,IndexTree,sizeof(IndexTree))>0) return;
301
302 if (getparam_string("index",buf,Index,sizeof(Index))>0) return;
303
304 if (getparam_bool("overwrite_report",buf,&OverwriteReport)>0) return;
305
306 if (getparam_string("records_without_userid",buf,RecordsWithoutUser,sizeof(RecordsWithoutUser))>0) return;
307
308 if (getparam_bool("use_comma",buf,&UseComma)>0) return;
309
310 if (getparam_string("mail_utility",buf,MailUtility,sizeof(MailUtility))>0) return;
311
312 if (getparam_string("topsites_num",buf,TopSitesNum,sizeof(TopSitesNum))>0) return;
313
314 if (getparam_int("topuser_num",buf,&TopUsersNum)>0) return;
315
316 if (getparam_string("usertab",buf,UserTabFile,sizeof(UserTabFile))>0) return;
317
318 if (getparam_string("index_sort_order",buf,IndexSortOrder,sizeof(IndexSortOrder))>0) return;
319
320 if (getparam_2words("topsites_sort_order",buf,TopsitesSortField,sizeof(TopsitesSortField),TopsitesSortType,sizeof(TopsitesSortType))>0) return;
321
322 if (getparam_bool("long_url",buf,&LongUrl)>0) return;
323
324 if (getparam_string("language",buf,language,sizeof(language))>0) return;
325
326 if (getparam_string("dansguardian_conf",buf,DansGuardianConf,sizeof(DansGuardianConf))>0) return;
327
328 if (getparam_string("squidguard_conf",buf,SquidGuardConf,sizeof(SquidGuardConf))>0) return;
329
330 if (getparam_string("date_time_by",buf,datetimeby,sizeof(datetimeby))>0) return;
331
332 if (getparam_string("charset",buf,CharSet,sizeof(CharSet))>0) {
333 ccharset(CharSet);
334 return;
335 }
336
337 if (getparam_quoted("user_invalid_char",buf,UserInvalidChar,sizeof(UserInvalidChar))>0) return;
338
339 if (getparam_quoted("include_users",buf,IncludeUsers+1,sizeof(IncludeUsers)-2)>0) {
340 IncludeUsers[0]=':';
341 strcat(IncludeUsers,":");
342 return;
343 }
344
345 if (getparam_quoted("exclude_string",buf,ExcludeString,sizeof(ExcludeString))>0) return;
346
347 if (getparam_bool("privacy",buf,&Privacy)>0) return;
348
349 if (getparam_quoted("privacy_string",buf,PrivacyString,sizeof(PrivacyString))>0) return;
350
351 if (getparam_string("privacy_string_color",buf,PrivacyStringColor,sizeof(PrivacyStringColor))>0) return;
352
353 if (getparam_bool("show_successful_message",buf,&SuccessfulMsg)>0) return;
354
355 if (getparam_bool("show_read_statistics",buf,&ShowReadStatistics)>0) return;
356
357 if (getparam_string("topuser_fields",buf,TopUserFields,sizeof(TopUserFields))>0) return;
358
359 if (getparam_bool("bytes_in_sites_users_report",buf,&BytesInSitesUsersReport)>0) return;
360
361 if (getparam_string("user_report_fields",buf,UserReportFields,sizeof(UserReportFields))>0) return;
362
363 if (getparam_string("datafile",buf,DataFile,sizeof(DataFile))>0) return;
364
365 if (getparam_quoted("datafile_delimiter",buf,DataFileDelimiter,sizeof(DataFileDelimiter))>0) return;
366
367 if (getparam_string("datafile_fields",buf,DataFileFields,sizeof(DataFileFields))>0) return;
368
369 if (getparam_string("datafile_url",buf,DataFileUrl,sizeof(DataFileUrl))>0) return;
370
371 if (getparam_string("parsed_output_log",buf,ParsedOutputLog,sizeof(ParsedOutputLog))>0) return;
372
373 if (getparam_string("parsed_output_log_compress",buf,ParsedOutputLogCompress,sizeof(ParsedOutputLogCompress))>0) return;
374
375 if (getparam_string("displayed_values",buf,DisplayedValues,sizeof(DisplayedValues))>0) return;
376
377 if (getparam_int("authfail_report_limit",buf,&AuthfailReportLimit)>0) return;
378
379 if (getparam_int("denied_report_limit",buf,&DeniedReportLimit)>0) return;
380
381 if (getparam_int("siteusers_report_limit",buf,&SiteUsersReportLimit)>0) return;
382
383 if (getparam_int("dansguardian_report_limit",buf,&DansGuardianReportLimit)>0) return;
384
385 if (getparam_int("squidguard_report_limit",buf,&SquidGuardReportLimit)>0) return;
386
387 if (getparam_int("user_report_limit",buf,&UserReportLimit)>0) return;
388
389 if (getparam_int("download_report_limit",buf,&DownloadReportLimit)>0) return;
390
391 if (getparam_string("www_document_root",buf,wwwDocumentRoot,sizeof(wwwDocumentRoot))>0) return;
392
393 if (getparam_string("block_it",buf,BlockIt,sizeof(BlockIt))>0) return;
394
395 if (getparam_string("external_css_file",buf,ExternalCSSFile,sizeof(ExternalCSSFile))>0) return;
396
397 if (getparam_bool("user_authentication",buf,&UserAuthentication)>0) return;
398
399 if (getparam_string("AuthUserFile",buf,AuthUserFile,sizeof(AuthUserFile))>0) return;
400
401 if (getparam_string("AuthName",buf,AuthName,sizeof(AuthName))>0) return;
402
403 if (getparam_string("AuthType",buf,AuthType,sizeof(AuthType))>0) return;
404
405 if (getparam_string("Require",buf,Require,sizeof(Require))>0) return;
406
407 if (is_param("download_suffix",buf)) {
408 char warea[MAXLEN];
409
410 getparam_quoted("download_suffix",buf,warea,sizeof(warea));
411 set_download_suffix(warea);
412 return;
413 }
414
415 if (getparam_bool("graphs",buf,&Graphs)>0) return;
416
417 if (getparam_string("graph_days_bytes_bar_color",buf,GraphDaysBytesBarColor,sizeof(GraphDaysBytesBarColor))>0) return;
418
419 if (getparam_string("squidguard_log_format",buf,SquidGuardLogFormat,sizeof(SquidGuardLogFormat))>0) return;
420
421 if (getparam_bool("squidguard_ignore_date",buf,&SquidguardIgnoreDate)>0) return;
422
423 if (getparam_bool("dansguardian_ignore_date",buf,&DansguardianIgnoreDate)>0) return;
424
425 if (getparam_string("ulimit",buf,Ulimit,sizeof(Ulimit))>0) return;
426
427 if (getparam_string("ntlm_user_format",buf,NtlmUserFormat,sizeof(NtlmUserFormat))>0) return;
428
429 if (getparam_string("realtime_types",buf,RealtimeTypes,sizeof(RealtimeTypes))>0) return;
430
431 if (getparam_string("realtime_unauthenticated_records",buf,RealtimeUnauthRec,sizeof(RealtimeUnauthRec))>0) return;
432
433 if (getparam_int("realtime_refresh_time",buf,&realtime_refresh)>0) return;
434
435 if (getparam_int("realtime_access_log_lines",buf,&realtime_access_log_lines)>0) return;
436
437 if (getparam_string("LDAPHost",buf,LDAPHost,sizeof(LDAPHost))>0) return;
438
439 if (getparam_int("LDAPPort",buf,&LDAPPort)>0) return;
440
441 if (getparam_int("LDAPProtocolVersion",buf,&LDAPProtocolVersion)>0) return;
442
443 if (getparam_string("LDAPBindDN",buf,LDAPBindDN,sizeof(LDAPBindDN))>0) return;
444
445 if (getparam_string("LDAPBindPW",buf,LDAPBindPW,sizeof(LDAPBindPW))>0) return;
446
447 if (getparam_string("LDAPBaseSearch",buf,LDAPBaseSearch,sizeof(LDAPBaseSearch))>0) return;
448
449 if (getparam_string("LDAPFilterSearch",buf,LDAPFilterSearch,sizeof(LDAPFilterSearch))>0) return;
450
451 if (getparam_string("LDAPTargetAttr",buf,LDAPTargetAttr,sizeof(LDAPTargetAttr))>0) return;
452
453 if(strstr(buf,"squid24") != 0) {
454 squid24++;
455 return;
456 }
457
458 if(strstr(buf,"byte_cost") != 0) {
459 getword_start(&gwarea,buf);
460 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
461 printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
462 exit(1);
463 }
464 cost=atol(gwarea.current);
465 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
466 printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
467 exit(1);
468 }
469 nocost=my_atoll(gwarea.current);
470 return;
471 }
472
473 printf("SARG: %s %s\n",text[140],buf);
474 }
475
476 void getconf(void)
477 {
478
479 FILE *fp_in;
480 char buf[MAXLEN];
481
482 if(debug)
483 debuga("Loading configuration from: %s",ConfigFile);
484
485 if ((fp_in = fopen(ConfigFile, "r")) == NULL) {
486 fprintf(stderr, "SARG: (getconf) Cannot open file: %s\n",ConfigFile);
487 exit(1);
488 }
489
490 while (fgets(buf, sizeof(buf), fp_in) != NULL) {
491 fixendofline(buf);
492
493 if(debugm)
494 printf("SYSCONFDIR %s\n",buf);
495
496 parmtest(buf);
497
498 }
499
500 fclose(fp_in);
501 language_load(language);
502 return;
503 }