]> git.ipfire.org Git - thirdparty/sarg.git/blob - getconf.c
Fixed e-mail report (may also fix bug #2153024).
[thirdparty/sarg.git] / getconf.c
1 /*
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
3 * 1998, 2008
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 getparam_string(const char *param,char *buf,char *value,int value_size)
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 while (*buf && (unsigned char)*buf<=' ') buf++;
40
41 if (strlen(buf)>=value_size) {
42 printf("SARG: Maybe you have a broken record or garbage in %s parameter.\n",param);
43 exit(1);
44 }
45 strcpy(value,buf);
46 fixnone(value);
47 return(1);
48 }
49
50 static int getparam_quoted(const char *param,char *buf,char *value,int value_size)
51 {
52 int plen;
53 int i;
54
55 plen=strlen(param);
56 if (strncmp(buf,param,plen) != 0) return(0);
57 buf+=plen;
58 if ((unsigned char)*buf>' ') return(0);
59 while (*buf && (unsigned char)*buf<=' ') buf++;
60
61 if (*buf != '\"') {
62 printf("SARG: Missing double quote after parameter %s.\n",param);
63 exit(1);
64 }
65 buf++;
66
67 value_size--;
68 for (i=0 ; i<value_size && *buf && *buf!='\"' ; i++) {
69 value[i]=*buf++;
70 }
71 value[i]='\0';
72
73 if (*buf != '\"') {
74 printf("SARG: Missing double quote after parameter %s or value is more than %d bytes long.\n",param,value_size);
75 exit(1);
76 }
77 fixnone(value);
78 return(1);
79 }
80
81 static int getparam_2words(const char *param,char *buf,char *word1,int word1_size,char *word2,int word2_size)
82 {
83 int plen;
84 int i;
85
86 plen=strlen(param);
87 if (strncmp(buf,param,plen) != 0) return(0);
88 buf+=plen;
89 if ((unsigned char)*buf>' ') return(0);
90 while (*buf && (unsigned char)*buf<=' ') buf++;
91
92 for (i=0 ; i<word1_size && *buf && (unsigned char)*buf>' ' ; i++)
93 word1[i]=*buf++;
94 if (i>=word1_size) {
95 printf("SARG: The first word of parameter %s is more than %d bytes long.\n",param,word1_size-1);
96 exit(1);
97 }
98 if (*buf!=' ') {
99 printf("SARG: Missing second word for parameter %s.\n",param);
100 exit(1);
101 }
102 word1[i]=0;
103
104 while (*buf && (unsigned char)*buf<=' ') buf++;
105
106 for (i=0 ; i<word2_size && *buf && (unsigned char)*buf>' ' ; i++)
107 word2[i]=*buf++;
108 if (i>=word2_size) {
109 printf("SARG: The second word of parameter %s is more than %d bytes long.\n",param,word2_size-1);
110 exit(1);
111 }
112 word2[i]=0;
113
114 fixnone(word1);
115 fixnone(word2);
116 return(1);
117 }
118
119 static int getparam_int(const char *param,char *buf,int *value)
120 {
121 int plen;
122 int next;
123
124 plen=strlen(param);
125 if (strncmp(buf,param,plen) != 0) return(0);
126 buf+=plen;
127 if ((unsigned char)*buf>' ') return(0);
128 while (*buf && (unsigned char)*buf<=' ') buf++;
129
130 next=0;
131 if (sscanf(buf,"%d%n",value,&next) != 1 || (unsigned char)buf[next] > ' ') {
132 printf("SARG: Maybe you have a broken record or garbage in %s parameter.\n",param);
133 exit(1);
134 }
135 return(1);
136 }
137
138 static void parmtest(char *buf)
139 {
140 char wbuf[50];
141
142 while (*buf && (unsigned char)*buf<=' ') buf++;
143
144 if(*buf == '#' || *buf == '\0')
145 return;
146
147 if(debugz)
148 printf("SARG: TAG: %s\n",buf);
149
150 if (getparam_string("background_color",buf,BgColor,sizeof(BgColor))>0) return;
151
152 if (getparam_string("text_color",buf,TxColor,sizeof(TxColor))>0) return;
153
154 if (getparam_string("text_bgcolor",buf,TxBgColor,sizeof(TxBgColor))>0) return;
155
156 if (getparam_string("title_color",buf,TiColor,sizeof(TiColor))>0) return;
157
158 if (getparam_string("logo_image",buf,LogoImage,sizeof(LogoImage))>0) return;
159
160 if (getparam_quoted("logo_text",buf,LogoText,sizeof(LogoText))>0) return;
161
162 if (getparam_string("logo_text_color",buf,LogoTextColor,sizeof(LogoTextColor))>0) return;
163
164 if (getparam_string("background_image",buf,BgImage,sizeof(BgImage))>0) return;
165
166 if (getparam_string("show_sarg_info",buf,ShowSargInfo,sizeof(ShowSargInfo))>0) return;
167
168 if (getparam_string("show_sarg_logo",buf,ShowSargLogo,sizeof(ShowSargLogo))>0) return;
169
170 if (getparam_string("font_face",buf,FontFace,sizeof(FontFace))>0) return;
171
172 if (getparam_string("header_color",buf,HeaderColor,sizeof(HeaderColor))>0) return;
173
174 if (getparam_string("header_bgcolor",buf,HeaderBgColor,sizeof(HeaderBgColor))>0) return;
175
176 if (getparam_string("font_size",buf,FontSize,sizeof(FontSize))>0) return;
177
178 if (getparam_string("header_font_size",buf,HeaderFontSize,sizeof(HeaderFontSize))>0) return;
179
180 if (getparam_string("title_font_size",buf,TitleFontSize,sizeof(TitleFontSize))>0) return;
181
182 if (getparam_2words("image_size",buf,Width,sizeof(Width),Height,sizeof(Height))>0) return;
183
184 if (getparam_quoted("title",buf,Title,sizeof(Title))>0) return;
185
186 if (getparam_string("resolve_ip",buf,Ip2Name,sizeof(Ip2Name))>0) return;
187
188 if (getparam_string("user_ip",buf,UserIp,sizeof(UserIp))>0) return;
189
190 if (getparam_string("max_elapsed",buf,MaxElapsed,sizeof(MaxElapsed))>0) return;
191
192 if(strstr(buf,"date_format") != 0) {
193 if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
194 printf("SARG: Maybe you have a broken record or garbage in date_format parameter.\n");
195 exit(1);
196 }
197 strncpy(DateFormat,buf,1);
198 fixnone(DateFormat);
199 return;
200 }
201
202 if( strstr( buf, "hours" ) != 0 ) {
203 if( getnumlist( buf, &hours, 24, 24 ) ) {
204 fprintf( stderr, "Error: Invalid syntax in hours tag!\n" );
205 exit( 1 );
206 }
207 }
208
209 if( strstr( buf, "weekdays" ) != 0 ) {
210 if( getnumlist( buf, &weekdays, 7, 7 ) ) {
211 fprintf( stderr, "Error: Invalid syntax in weekdays tag!\n" );
212 exit( 1 );
213 }
214 }
215
216 if (getparam_2words("topuser_sort_field",buf,TopuserSortField,sizeof(TopuserSortField),TopuserSortOrder,sizeof(TopuserSortOrder))>0) return;
217
218 if (getparam_2words("user_sort_field",buf,UserSortField,sizeof(UserSortField),UserSortOrder,sizeof(UserSortOrder))>0) return;
219
220 if (getparam_string("access_log",buf,AccessLog,sizeof(AccessLog))>0) return;
221
222 if (getparam_string("useragent_log",buf,UserAgentLog,sizeof(UserAgentLog))>0) return;
223
224 if (getparam_string("exclude_hosts",buf,ExcludeHosts,sizeof(ExcludeHosts))>0) return;
225
226 if (getparam_string("exclude_codes",buf,ExcludeCodes,sizeof(ExcludeCodes))>0) return;
227
228 if (getparam_string("exclude_users",buf,ExcludeUsers,sizeof(ExcludeUsers))>0) return;
229
230 if (getparam_string("password",buf,PasswdFile,sizeof(PasswdFile))>0) return;
231
232 if (getparam_string("temporary_dir",buf,TempDir,sizeof(TempDir))>0) return;
233
234 if (getparam_string("report_type",buf,ReportType,sizeof(ReportType))>0) return;
235
236 if (getparam_string("output_dir",buf,OutputDir,sizeof(OutputDir))>0) return;
237
238 if (getparam_string("output_email",buf,OutputEmail,sizeof(OutputEmail))>0) return;
239
240 if (getparam_2words("per_user_limit",buf,PerUserLimitFile,sizeof(PerUserLimitFile),PerUserLimit,sizeof(PerUserLimit))>0) return;
241
242 if (getparam_string("lastlog",buf,LastLog,sizeof(LastLog))>0) return;
243
244 if (getparam_string("remove_temp_files",buf,RemoveTempFiles,sizeof(RemoveTempFiles))>0) return;
245
246 if (getparam_string("replace_index",buf,ReplaceIndex,sizeof(ReplaceIndex))>0) return;
247
248 if (getparam_string("index_tree",buf,IndexTree,sizeof(IndexTree))>0) return;
249
250 if (getparam_string("index",buf,Index,sizeof(Index))>0) return;
251
252 if (getparam_string("overwrite_report",buf,OverwriteReport,sizeof(OverwriteReport))>0) return;
253
254 if (getparam_string("records_without_userid",buf,RecordsWithoutUser,sizeof(RecordsWithoutUser))>0) return;
255
256 if (getparam_string("use_comma",buf,UseComma,sizeof(UseComma))>0) return;
257
258 if (getparam_string("mail_utility",buf,MailUtility,sizeof(MailUtility))>0) return;
259
260 if (getparam_string("topsites_num",buf,TopSitesNum,sizeof(TopSitesNum))>0) return;
261
262 if (getparam_int("topuser_num",buf,&TopUsersNum)>0) return;
263
264 if (getparam_string("usertab",buf,UserTabFile,sizeof(UserTabFile))>0) return;
265
266 if (getparam_string("index_sort_order",buf,IndexSortOrder,sizeof(IndexSortOrder))>0) return;
267
268 if (getparam_2words("topsites_sort_order",buf,TopsitesSortField,sizeof(TopsitesSortField),TopsitesSortType,sizeof(TopsitesSortType))>0) return;
269
270 if (getparam_string("long_url",buf,LongUrl,sizeof(LongUrl))>0) return;
271
272 if (getparam_string("language",buf,language,sizeof(language))>0) return;
273
274 if (getparam_string("dansguardian_conf",buf,DansGuardianConf,sizeof(DansGuardianConf))>0) return;
275
276 if (getparam_string("squidguard_conf",buf,SquidGuardConf,sizeof(SquidGuardConf))>0) return;
277
278 if (getparam_string("date_time_by",buf,datetimeby,sizeof(datetimeby))>0) return;
279
280 if (getparam_string("charset",buf,CharSet,sizeof(CharSet))>0) {
281 ccharset(CharSet);
282 return;
283 }
284
285 if (getparam_quoted("user_invalid_char",buf,UserInvalidChar,sizeof(UserInvalidChar))>0) return;
286
287 if (getparam_quoted("include_users",buf,IncludeUsers+1,sizeof(IncludeUsers)-2)>0) {
288 IncludeUsers[0]=':';
289 strcat(IncludeUsers,":");
290 return;
291 }
292
293 if (getparam_quoted("exclude_string",buf,ExcludeString,sizeof(ExcludeString))>0) return;
294
295 if (getparam_string("privacy",buf,Privacy,sizeof(Privacy))>0) return;
296
297 if (getparam_quoted("privacy_string",buf,ExcludeString,sizeof(ExcludeString))>0) return;
298
299 if (getparam_string("privacy_string_color",buf,PrivacyStringColor,sizeof(PrivacyStringColor))>0) return;
300
301 if (getparam_string("show_successful_message",buf,SuccessfulMsg,sizeof(SuccessfulMsg))>0) return;
302
303 if (getparam_string("show_read_statistics",buf,ShowReadStatistics,sizeof(ShowReadStatistics))>0) return;
304
305 if (getparam_string("topuser_fields",buf,TopUserFields,sizeof(TopUserFields))>0) return;
306
307 if (getparam_string("bytes_in_sites_users_report",buf,BytesInSitesUsersReport,sizeof(BytesInSitesUsersReport))>0) return;
308
309 if (getparam_string("user_report_fields",buf,UserReportFields,sizeof(UserReportFields))>0) return;
310
311 if (getparam_string("bytes_in_sites_users_report",buf,BytesInSitesUsersReport,sizeof(BytesInSitesUsersReport))>0) return;
312
313 if (getparam_string("datafile",buf,DataFile,sizeof(DataFile))>0) return;
314
315 if (getparam_quoted("datafile_delimiter",buf,DataFileDelimiter,sizeof(DataFileDelimiter))>0) return;
316
317 if (getparam_string("datafile_fields",buf,DataFileFields,sizeof(DataFileFields))>0) return;
318
319 if (getparam_string("datafile_url",buf,DataFileUrl,sizeof(DataFileUrl))>0) return;
320
321 if (getparam_string("parsed_output_log",buf,ParsedOutputLog,sizeof(ParsedOutputLog))>0) return;
322
323 if (getparam_string("parsed_output_log_compress",buf,ParsedOutputLogCompress,sizeof(ParsedOutputLogCompress))>0) return;
324
325 if (getparam_string("displayed_values",buf,DisplayedValues,sizeof(DisplayedValues))>0) return;
326
327 if (getparam_int("authfail_report_limit",buf,&AuthfailReportLimit)>0) return;
328
329 if (getparam_int("denied_report_limit",buf,&DeniedReportLimit)>0) return;
330
331 if (getparam_int("siteusers_report_limit",buf,&SiteUsersReportLimit)>0) return;
332
333 if (getparam_int("dansguardian_report_limit",buf,&DansGuardianReportLimit)>0) return;
334
335 if (getparam_int("squidguard_report_limit",buf,&SquidGuardReportLimit)>0) return;
336
337 if (getparam_int("user_report_limit",buf,&UserReportLimit)>0) return;
338
339 if (getparam_int("download_report_limit",buf,&DownloadReportLimit)>0) return;
340
341 if (getparam_string("www_document_root",buf,wwwDocumentRoot,sizeof(wwwDocumentRoot))>0) return;
342
343 if (getparam_string("block_it",buf,BlockIt,sizeof(BlockIt))>0) return;
344
345 if (getparam_string("external_css_file",buf,ExternalCSSFile,sizeof(ExternalCSSFile))>0) return;
346
347 if (getparam_string("user_authentication",buf,UserAuthentication,sizeof(UserAuthentication))>0) return;
348
349 if (getparam_string("AuthUserFile",buf,AuthUserFile,sizeof(AuthUserFile))>0) return;
350
351 if (getparam_string("AuthName",buf,AuthName,sizeof(AuthName))>0) return;
352
353 if (getparam_string("AuthType",buf,AuthType,sizeof(AuthType))>0) return;
354
355 if (getparam_string("Require",buf,Require,sizeof(Require))>0) return;
356
357 if (getparam_quoted("download_suffix",buf,DownloadSuffix,sizeof(DownloadSuffix))>0) return;
358
359 if (getparam_string("graphs",buf,Graphs,sizeof(Graphs))>0) return;
360
361 if (getparam_string("graph_days_bytes_bar_color",buf,GraphDaysBytesBarColor,sizeof(GraphDaysBytesBarColor))>0) return;
362
363 if (getparam_string("squidguard_log_format",buf,SquidGuardLogFormat,sizeof(SquidGuardLogFormat))>0) return;
364
365 if (getparam_string("squidguard_ignore_date",buf,SquidguardIgnoreDate,sizeof(SquidguardIgnoreDate))>0) return;
366
367 if (getparam_string("dansguardian_ignore_date",buf,DansguardianIgnoreDate,sizeof(DansguardianIgnoreDate))>0) return;
368
369 if (getparam_string("ulimit",buf,Ulimit,sizeof(Ulimit))>0) return;
370
371 if (getparam_string("ntlm_user_format",buf,NtlmUserFormat,sizeof(NtlmUserFormat))>0) return;
372
373 if (getparam_string("realtime_types",buf,RealtimeTypes,sizeof(RealtimeTypes))>0) return;
374
375 if (getparam_string("realtime_unauthenticated_records",buf,RealtimeUnauthRec,sizeof(RealtimeUnauthRec))>0) return;
376
377 if (getparam_int("realtime_refresh_time",buf,&realtime_refresh)>0) return;
378
379 if (getparam_int("realtime_access_log_lines",buf,&realtime_access_log_lines)>0) return;
380
381 if(strstr(buf,"squid24") != 0) {
382 squid24++;
383 return;
384 }
385
386 if(strstr(buf,"byte_cost") != 0) {
387 if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
388 printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
389 exit(1);
390 }
391 cost=atol(buf);
392 if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
393 printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
394 exit(1);
395 }
396 nocost=my_atoll(buf);
397 return;
398 }
399
400 printf("SARG: Unknown option %s\n",buf);
401 }
402
403 void getconf(void)
404 {
405
406 FILE *fp_in;
407 char buf[MAXLEN];
408
409 if(debug)
410 debuga("Loading configuration from: %s",ConfigFile);
411
412 if ((fp_in = fopen(ConfigFile, "r")) == NULL) {
413 fprintf(stderr, "SARG: (getconf) Cannot open file: %s\n",ConfigFile);
414 exit(1);
415 }
416
417 while (fgets(buf, sizeof(buf), fp_in) != NULL) {
418 fixendofline(buf);
419
420 if(debugm)
421 printf("SYSCONFDIR %s",buf);
422
423 parmtest(buf);
424
425 }
426
427 fclose(fp_in);
428 language_load(language);
429 return;
430 }