]> git.ipfire.org Git - thirdparty/sarg.git/blob - getconf.c
Don't translate the boolean flags from sarg.conf
[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 int i;
153 const char *bool_str="yes,true,on,1";
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 for ( ; *bool_str ; bool_str+=i) {
163 for (i=0 ; bool_str[i] && bool_str[i]!=',' ; i++);
164 if (strncasecmp(bool_str,buf,i)==0) {
165 *value=1;
166 break;
167 }
168 if (bool_str[i]==',') i++;
169 }
170 return(1);
171 }
172
173 static void parmtest(char *buf)
174 {
175 char wbuf[50];
176 struct getwordstruct gwarea;
177
178 while (*buf && (unsigned char)*buf<=' ') buf++;
179
180 if(*buf == '#' || *buf == '\0')
181 return;
182
183 if(debugz)
184 printf("SARG: TAG: %s\n",buf);
185
186 if (getparam_string("background_color",buf,BgColor,sizeof(BgColor))>0) return;
187
188 if (getparam_string("text_color",buf,TxColor,sizeof(TxColor))>0) return;
189
190 if (getparam_string("text_bgcolor",buf,TxBgColor,sizeof(TxBgColor))>0) return;
191
192 if (getparam_string("title_color",buf,TiColor,sizeof(TiColor))>0) return;
193
194 if (getparam_string("logo_image",buf,LogoImage,sizeof(LogoImage))>0) return;
195
196 if (getparam_quoted("logo_text",buf,LogoText,sizeof(LogoText))>0) return;
197
198 if (getparam_string("logo_text_color",buf,LogoTextColor,sizeof(LogoTextColor))>0) return;
199
200 if (getparam_string("background_image",buf,BgImage,sizeof(BgImage))>0) return;
201
202 if (getparam_bool("show_sarg_info",buf,&ShowSargInfo)>0) return;
203
204 if (getparam_bool("show_sarg_logo",buf,&ShowSargLogo)>0) return;
205
206 if (getparam_string("font_face",buf,FontFace,sizeof(FontFace))>0) return;
207
208 if (getparam_string("header_color",buf,HeaderColor,sizeof(HeaderColor))>0) return;
209
210 if (getparam_string("header_bgcolor",buf,HeaderBgColor,sizeof(HeaderBgColor))>0) return;
211
212 if (getparam_string("font_size",buf,FontSize,sizeof(FontSize))>0) return;
213
214 if (getparam_string("header_font_size",buf,HeaderFontSize,sizeof(HeaderFontSize))>0) return;
215
216 if (getparam_string("title_font_size",buf,TitleFontSize,sizeof(TitleFontSize))>0) return;
217
218 if (getparam_2words("image_size",buf,Width,sizeof(Width),Height,sizeof(Height))>0) return;
219
220 if (getparam_quoted("title",buf,Title,sizeof(Title))>0) return;
221
222 if (getparam_bool("resolve_ip",buf,&Ip2Name)>0) return;
223
224 if (getparam_bool("user_ip",buf,&UserIp)>0) return;
225
226 if (getparam_string("max_elapsed",buf,MaxElapsed,sizeof(MaxElapsed))>0) return;
227
228 if (is_param("date_format",buf)) {
229 getword_start(&gwarea,buf);
230 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
231 printf("SARG: Maybe you have a broken record or garbage in date_format parameter.\n");
232 exit(1);
233 }
234 strncpy(DateFormat,gwarea.current,1);
235 fixnone(DateFormat);
236 return;
237 }
238
239 if (is_param("hours",buf)) {
240 if( getnumlist( buf, &hours, 24, 24 ) ) {
241 fprintf( stderr, "Error: Invalid syntax in hours tag!\n" );
242 exit( 1 );
243 }
244 }
245
246 if (is_param("weekdays",buf)) {
247 if( getnumlist( buf, &weekdays, 7, 7 ) ) {
248 fprintf( stderr, "Error: Invalid syntax in weekdays tag!\n" );
249 exit( 1 );
250 }
251 }
252
253 if (getparam_2words("topuser_sort_field",buf,TopuserSortField,sizeof(TopuserSortField),TopuserSortOrder,sizeof(TopuserSortOrder))>0) return;
254
255 if (getparam_2words("user_sort_field",buf,UserSortField,sizeof(UserSortField),UserSortOrder,sizeof(UserSortOrder))>0) return;
256
257 if (is_param("access_log",buf)>0) {
258 if (AccessLogFromCmdLine==0) {
259 if (NAccessLog>=MAXLOGS) {
260 fprintf(stderr,"SARG: Too many log files.\n");
261 exit(1);
262 }
263 getparam_string("access_log",buf,AccessLog[NAccessLog],MAXLEN);
264 NAccessLog++;
265 }
266 return;
267 }
268
269 if (getparam_string("useragent_log",buf,UserAgentLog,sizeof(UserAgentLog))>0) return;
270
271 if (getparam_string("exclude_hosts",buf,ExcludeHosts,sizeof(ExcludeHosts))>0) return;
272
273 if (getparam_string("exclude_codes",buf,ExcludeCodes,sizeof(ExcludeCodes))>0) return;
274
275 if (getparam_string("exclude_users",buf,ExcludeUsers,sizeof(ExcludeUsers))>0) return;
276
277 if (getparam_string("password",buf,PasswdFile,sizeof(PasswdFile))>0) return;
278
279 if (getparam_string("temporary_dir",buf,TempDir,sizeof(TempDir))>0) return;
280
281 if (getparam_string("report_type",buf,ReportType,sizeof(ReportType))>0) return;
282
283 if (getparam_string("output_dir",buf,OutputDir,sizeof(OutputDir))>0) return;
284
285 if (getparam_string("output_email",buf,OutputEmail,sizeof(OutputEmail))>0) return;
286
287 if (getparam_2words("per_user_limit",buf,PerUserLimitFile,sizeof(PerUserLimitFile),wbuf,sizeof(wbuf))>0) {
288 PerUserLimit=atoi(wbuf);
289 return;
290 }
291
292 if (getparam_int("lastlog",buf,&LastLog)>0) return;
293
294 if (getparam_bool("remove_temp_files",buf,&RemoveTempFiles)>0) return;
295
296 if (getparam_string("replace_index",buf,ReplaceIndex,sizeof(ReplaceIndex))>0) return;
297
298 if (getparam_string("index_tree",buf,IndexTree,sizeof(IndexTree))>0) return;
299
300 if (getparam_string("index",buf,Index,sizeof(Index))>0) return;
301
302 if (getparam_bool("overwrite_report",buf,&OverwriteReport)>0) return;
303
304 if (getparam_string("records_without_userid",buf,RecordsWithoutUser,sizeof(RecordsWithoutUser))>0) return;
305
306 if (getparam_bool("use_comma",buf,&UseComma)>0) return;
307
308 if (getparam_string("mail_utility",buf,MailUtility,sizeof(MailUtility))>0) return;
309
310 if (getparam_string("topsites_num",buf,TopSitesNum,sizeof(TopSitesNum))>0) return;
311
312 if (getparam_int("topuser_num",buf,&TopUsersNum)>0) return;
313
314 if (getparam_string("usertab",buf,UserTabFile,sizeof(UserTabFile))>0) return;
315
316 if (getparam_string("index_sort_order",buf,IndexSortOrder,sizeof(IndexSortOrder))>0) return;
317
318 if (getparam_2words("topsites_sort_order",buf,TopsitesSortField,sizeof(TopsitesSortField),TopsitesSortType,sizeof(TopsitesSortType))>0) return;
319
320 if (getparam_bool("long_url",buf,&LongUrl)>0) return;
321
322 if (getparam_string("language",buf,language,sizeof(language))>0) return;
323
324 if (getparam_string("dansguardian_conf",buf,DansGuardianConf,sizeof(DansGuardianConf))>0) return;
325
326 if (getparam_string("squidguard_conf",buf,SquidGuardConf,sizeof(SquidGuardConf))>0) return;
327
328 if (getparam_string("date_time_by",buf,datetimeby,sizeof(datetimeby))>0) return;
329
330 if (getparam_string("charset",buf,CharSet,sizeof(CharSet))>0) {
331 ccharset(CharSet);
332 return;
333 }
334
335 if (getparam_quoted("user_invalid_char",buf,UserInvalidChar,sizeof(UserInvalidChar))>0) return;
336
337 if (getparam_quoted("include_users",buf,IncludeUsers+1,sizeof(IncludeUsers)-2)>0) {
338 IncludeUsers[0]=':';
339 strcat(IncludeUsers,":");
340 return;
341 }
342
343 if (getparam_quoted("exclude_string",buf,ExcludeString,sizeof(ExcludeString))>0) return;
344
345 if (getparam_bool("privacy",buf,&Privacy)>0) return;
346
347 if (getparam_quoted("privacy_string",buf,PrivacyString,sizeof(PrivacyString))>0) return;
348
349 if (getparam_string("privacy_string_color",buf,PrivacyStringColor,sizeof(PrivacyStringColor))>0) return;
350
351 if (getparam_bool("show_successful_message",buf,&SuccessfulMsg)>0) return;
352
353 if (getparam_bool("show_read_statistics",buf,&ShowReadStatistics)>0) return;
354
355 if (getparam_string("topuser_fields",buf,TopUserFields,sizeof(TopUserFields))>0) return;
356
357 if (getparam_bool("bytes_in_sites_users_report",buf,&BytesInSitesUsersReport)>0) return;
358
359 if (getparam_string("user_report_fields",buf,UserReportFields,sizeof(UserReportFields))>0) return;
360
361 if (getparam_string("datafile",buf,DataFile,sizeof(DataFile))>0) return;
362
363 if (getparam_quoted("datafile_delimiter",buf,DataFileDelimiter,sizeof(DataFileDelimiter))>0) return;
364
365 if (getparam_string("datafile_fields",buf,DataFileFields,sizeof(DataFileFields))>0) return;
366
367 if (getparam_string("datafile_url",buf,DataFileUrl,sizeof(DataFileUrl))>0) return;
368
369 if (getparam_string("parsed_output_log",buf,ParsedOutputLog,sizeof(ParsedOutputLog))>0) return;
370
371 if (getparam_string("parsed_output_log_compress",buf,ParsedOutputLogCompress,sizeof(ParsedOutputLogCompress))>0) return;
372
373 if (getparam_string("displayed_values",buf,DisplayedValues,sizeof(DisplayedValues))>0) return;
374
375 if (getparam_int("authfail_report_limit",buf,&AuthfailReportLimit)>0) return;
376
377 if (getparam_int("denied_report_limit",buf,&DeniedReportLimit)>0) return;
378
379 if (getparam_int("siteusers_report_limit",buf,&SiteUsersReportLimit)>0) return;
380
381 if (getparam_int("dansguardian_report_limit",buf,&DansGuardianReportLimit)>0) return;
382
383 if (getparam_int("squidguard_report_limit",buf,&SquidGuardReportLimit)>0) return;
384
385 if (getparam_int("user_report_limit",buf,&UserReportLimit)>0) return;
386
387 if (getparam_int("download_report_limit",buf,&DownloadReportLimit)>0) return;
388
389 if (getparam_string("www_document_root",buf,wwwDocumentRoot,sizeof(wwwDocumentRoot))>0) return;
390
391 if (getparam_string("block_it",buf,BlockIt,sizeof(BlockIt))>0) return;
392
393 if (getparam_string("external_css_file",buf,ExternalCSSFile,sizeof(ExternalCSSFile))>0) return;
394
395 if (getparam_bool("user_authentication",buf,&UserAuthentication)>0) return;
396
397 if (getparam_string("AuthUserFile",buf,AuthUserFile,sizeof(AuthUserFile))>0) return;
398
399 if (getparam_string("AuthName",buf,AuthName,sizeof(AuthName))>0) return;
400
401 if (getparam_string("AuthType",buf,AuthType,sizeof(AuthType))>0) return;
402
403 if (getparam_string("Require",buf,Require,sizeof(Require))>0) return;
404
405 if (is_param("download_suffix",buf)) {
406 char warea[MAXLEN];
407
408 getparam_quoted("download_suffix",buf,warea,sizeof(warea));
409 set_download_suffix(warea);
410 return;
411 }
412
413 if (getparam_bool("graphs",buf,&Graphs)>0) return;
414
415 if (getparam_string("graph_days_bytes_bar_color",buf,GraphDaysBytesBarColor,sizeof(GraphDaysBytesBarColor))>0) return;
416
417 if (getparam_string("squidguard_log_format",buf,SquidGuardLogFormat,sizeof(SquidGuardLogFormat))>0) return;
418
419 if (getparam_bool("squidguard_ignore_date",buf,&SquidguardIgnoreDate)>0) return;
420
421 if (getparam_bool("dansguardian_ignore_date",buf,&DansguardianIgnoreDate)>0) return;
422
423 if (getparam_string("ulimit",buf,Ulimit,sizeof(Ulimit))>0) return;
424
425 if (getparam_string("ntlm_user_format",buf,NtlmUserFormat,sizeof(NtlmUserFormat))>0) return;
426
427 if (getparam_string("realtime_types",buf,RealtimeTypes,sizeof(RealtimeTypes))>0) return;
428
429 if (getparam_string("realtime_unauthenticated_records",buf,RealtimeUnauthRec,sizeof(RealtimeUnauthRec))>0) return;
430
431 if (getparam_int("realtime_refresh_time",buf,&realtime_refresh)>0) return;
432
433 if (getparam_int("realtime_access_log_lines",buf,&realtime_access_log_lines)>0) return;
434
435 if(strstr(buf,"squid24") != 0) {
436 squid24++;
437 return;
438 }
439
440 if(strstr(buf,"byte_cost") != 0) {
441 getword_start(&gwarea,buf);
442 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
443 printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
444 exit(1);
445 }
446 cost=atol(gwarea.current);
447 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
448 printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
449 exit(1);
450 }
451 nocost=my_atoll(gwarea.current);
452 return;
453 }
454
455 printf("SARG: %s %s\n",text[140],buf);
456 }
457
458 void getconf(void)
459 {
460
461 FILE *fp_in;
462 char buf[MAXLEN];
463
464 if(debug)
465 debuga("Loading configuration from: %s",ConfigFile);
466
467 if ((fp_in = fopen(ConfigFile, "r")) == NULL) {
468 fprintf(stderr, "SARG: (getconf) Cannot open file: %s\n",ConfigFile);
469 exit(1);
470 }
471
472 while (fgets(buf, sizeof(buf), fp_in) != NULL) {
473 fixendofline(buf);
474
475 if(debugm)
476 printf("SYSCONFDIR %s\n",buf);
477
478 parmtest(buf);
479
480 }
481
482 fclose(fp_in);
483 language_load(language);
484 return;
485 }