]> git.ipfire.org Git - thirdparty/sarg.git/blame - getconf.c
LDAP usertab feature added
[thirdparty/sarg.git] / getconf.c
CommitLineData
25697a35 1/*
c37945ed 2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
e3af0ae9 3 * 1998, 2009
94ff9470 4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
25697a35
GS
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"
5f3cfd1d 27#include "include/defs.h"
25697a35
GS
28
29extern numlist hours, weekdays;
30
4af2f8ff
FM
31static 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}
25697a35 49
4af2f8ff 50static int getparam_quoted(const char *param,char *buf,char *value,int value_size)
25697a35 51{
4af2f8ff
FM
52 int plen;
53 int i;
25697a35 54
4af2f8ff
FM
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++;
25697a35 60
4af2f8ff 61 if (*buf != '\"') {
f29e90f8 62 printf("SARG: %s %s.\n",text[139],param);
4af2f8ff
FM
63 exit(1);
64 }
65 buf++;
25697a35 66
4af2f8ff
FM
67 value_size--;
68 for (i=0 ; i<value_size && *buf && *buf!='\"' ; i++) {
69 value[i]=*buf++;
70 }
71 value[i]='\0';
25697a35 72
4af2f8ff
FM
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}
25697a35 80
4af2f8ff
FM
81static 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;
25697a35 103
4af2f8ff 104 while (*buf && (unsigned char)*buf<=' ') buf++;
25697a35 105
4af2f8ff
FM
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;
25697a35 113
4af2f8ff
FM
114 fixnone(word1);
115 fixnone(word2);
116 return(1);
117}
25697a35 118
4af2f8ff
FM
119static 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}
25697a35 137
4af2f8ff
FM
138static void parmtest(char *buf)
139{
140 char wbuf[50];
25697a35 141
4af2f8ff 142 while (*buf && (unsigned char)*buf<=' ') buf++;
25697a35 143
4af2f8ff
FM
144 if(*buf == '#' || *buf == '\0')
145 return;
25697a35 146
4af2f8ff
FM
147 if(debugz)
148 printf("SARG: TAG: %s\n",buf);
25697a35 149
4af2f8ff 150 if (getparam_string("background_color",buf,BgColor,sizeof(BgColor))>0) return;
25697a35 151
4af2f8ff 152 if (getparam_string("text_color",buf,TxColor,sizeof(TxColor))>0) return;
25697a35 153
4af2f8ff 154 if (getparam_string("text_bgcolor",buf,TxBgColor,sizeof(TxBgColor))>0) return;
25697a35 155
4af2f8ff 156 if (getparam_string("title_color",buf,TiColor,sizeof(TiColor))>0) return;
25697a35 157
4af2f8ff 158 if (getparam_string("logo_image",buf,LogoImage,sizeof(LogoImage))>0) return;
25697a35 159
4af2f8ff 160 if (getparam_quoted("logo_text",buf,LogoText,sizeof(LogoText))>0) return;
25697a35 161
4af2f8ff 162 if (getparam_string("logo_text_color",buf,LogoTextColor,sizeof(LogoTextColor))>0) return;
25697a35 163
4af2f8ff 164 if (getparam_string("background_image",buf,BgImage,sizeof(BgImage))>0) return;
25697a35 165
4af2f8ff 166 if (getparam_string("show_sarg_info",buf,ShowSargInfo,sizeof(ShowSargInfo))>0) return;
25697a35 167
4af2f8ff 168 if (getparam_string("show_sarg_logo",buf,ShowSargLogo,sizeof(ShowSargLogo))>0) return;
25697a35 169
4af2f8ff 170 if (getparam_string("font_face",buf,FontFace,sizeof(FontFace))>0) return;
25697a35 171
4af2f8ff 172 if (getparam_string("header_color",buf,HeaderColor,sizeof(HeaderColor))>0) return;
25697a35 173
4af2f8ff 174 if (getparam_string("header_bgcolor",buf,HeaderBgColor,sizeof(HeaderBgColor))>0) return;
25697a35 175
4af2f8ff 176 if (getparam_string("font_size",buf,FontSize,sizeof(FontSize))>0) return;
25697a35 177
4af2f8ff 178 if (getparam_string("header_font_size",buf,HeaderFontSize,sizeof(HeaderFontSize))>0) return;
25697a35 179
4af2f8ff 180 if (getparam_string("title_font_size",buf,TitleFontSize,sizeof(TitleFontSize))>0) return;
25697a35 181
4af2f8ff 182 if (getparam_2words("image_size",buf,Width,sizeof(Width),Height,sizeof(Height))>0) return;
25697a35 183
4af2f8ff 184 if (getparam_quoted("title",buf,Title,sizeof(Title))>0) return;
25697a35 185
4af2f8ff 186 if (getparam_string("resolve_ip",buf,Ip2Name,sizeof(Ip2Name))>0) return;
25697a35 187
4af2f8ff
FM
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;
25697a35 191
4af2f8ff
FM
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);
25697a35 196 }
4af2f8ff
FM
197 strncpy(DateFormat,buf,1);
198 fixnone(DateFormat);
199 return;
200 }
25697a35 201
4af2f8ff
FM
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 );
25697a35 206 }
4af2f8ff 207 }
25697a35 208
4af2f8ff
FM
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 );
25697a35 213 }
4af2f8ff 214 }
25697a35 215
4af2f8ff 216 if (getparam_2words("topuser_sort_field",buf,TopuserSortField,sizeof(TopuserSortField),TopuserSortOrder,sizeof(TopuserSortOrder))>0) return;
25697a35 217
4af2f8ff 218 if (getparam_2words("user_sort_field",buf,UserSortField,sizeof(UserSortField),UserSortOrder,sizeof(UserSortOrder))>0) return;
25697a35 219
4af2f8ff 220 if (getparam_string("access_log",buf,AccessLog,sizeof(AccessLog))>0) return;
25697a35 221
4af2f8ff 222 if (getparam_string("useragent_log",buf,UserAgentLog,sizeof(UserAgentLog))>0) return;
25697a35 223
4af2f8ff 224 if (getparam_string("exclude_hosts",buf,ExcludeHosts,sizeof(ExcludeHosts))>0) return;
25697a35 225
4af2f8ff 226 if (getparam_string("exclude_codes",buf,ExcludeCodes,sizeof(ExcludeCodes))>0) return;
25697a35 227
4af2f8ff 228 if (getparam_string("exclude_users",buf,ExcludeUsers,sizeof(ExcludeUsers))>0) return;
25697a35 229
4af2f8ff 230 if (getparam_string("password",buf,PasswdFile,sizeof(PasswdFile))>0) return;
25697a35 231
4af2f8ff 232 if (getparam_string("temporary_dir",buf,TempDir,sizeof(TempDir))>0) return;
25697a35 233
4af2f8ff 234 if (getparam_string("report_type",buf,ReportType,sizeof(ReportType))>0) return;
25697a35 235
4af2f8ff 236 if (getparam_string("output_dir",buf,OutputDir,sizeof(OutputDir))>0) return;
25697a35 237
4af2f8ff 238 if (getparam_string("output_email",buf,OutputEmail,sizeof(OutputEmail))>0) return;
25697a35 239
4af2f8ff 240 if (getparam_2words("per_user_limit",buf,PerUserLimitFile,sizeof(PerUserLimitFile),PerUserLimit,sizeof(PerUserLimit))>0) return;
25697a35 241
4af2f8ff 242 if (getparam_string("lastlog",buf,LastLog,sizeof(LastLog))>0) return;
25697a35 243
4af2f8ff 244 if (getparam_string("remove_temp_files",buf,RemoveTempFiles,sizeof(RemoveTempFiles))>0) return;
25697a35 245
4af2f8ff 246 if (getparam_string("replace_index",buf,ReplaceIndex,sizeof(ReplaceIndex))>0) return;
25697a35 247
4af2f8ff 248 if (getparam_string("index_tree",buf,IndexTree,sizeof(IndexTree))>0) return;
25697a35 249
4af2f8ff 250 if (getparam_string("index",buf,Index,sizeof(Index))>0) return;
25697a35 251
4af2f8ff 252 if (getparam_string("overwrite_report",buf,OverwriteReport,sizeof(OverwriteReport))>0) return;
25697a35 253
4af2f8ff 254 if (getparam_string("records_without_userid",buf,RecordsWithoutUser,sizeof(RecordsWithoutUser))>0) return;
25697a35 255
4af2f8ff 256 if (getparam_string("use_comma",buf,UseComma,sizeof(UseComma))>0) return;
25697a35 257
4af2f8ff 258 if (getparam_string("mail_utility",buf,MailUtility,sizeof(MailUtility))>0) return;
25697a35 259
4af2f8ff 260 if (getparam_string("topsites_num",buf,TopSitesNum,sizeof(TopSitesNum))>0) return;
25697a35 261
fb7c5f27 262 if (getparam_int("topuser_num",buf,&TopUsersNum)>0) return;
25697a35 263
4af2f8ff 264 if (getparam_string("usertab",buf,UserTabFile,sizeof(UserTabFile))>0) return;
25697a35 265
4af2f8ff 266 if (getparam_string("index_sort_order",buf,IndexSortOrder,sizeof(IndexSortOrder))>0) return;
25697a35 267
4af2f8ff 268 if (getparam_2words("topsites_sort_order",buf,TopsitesSortField,sizeof(TopsitesSortField),TopsitesSortType,sizeof(TopsitesSortType))>0) return;
25697a35 269
4af2f8ff 270 if (getparam_string("long_url",buf,LongUrl,sizeof(LongUrl))>0) return;
25697a35 271
4af2f8ff 272 if (getparam_string("language",buf,language,sizeof(language))>0) return;
d6e703cc 273
4af2f8ff 274 if (getparam_string("dansguardian_conf",buf,DansGuardianConf,sizeof(DansGuardianConf))>0) return;
25697a35 275
4af2f8ff 276 if (getparam_string("squidguard_conf",buf,SquidGuardConf,sizeof(SquidGuardConf))>0) return;
25697a35 277
4af2f8ff 278 if (getparam_string("date_time_by",buf,datetimeby,sizeof(datetimeby))>0) return;
25697a35 279
4af2f8ff
FM
280 if (getparam_string("charset",buf,CharSet,sizeof(CharSet))>0) {
281 ccharset(CharSet);
282 return;
283 }
25697a35 284
4af2f8ff 285 if (getparam_quoted("user_invalid_char",buf,UserInvalidChar,sizeof(UserInvalidChar))>0) return;
25697a35 286
4af2f8ff
FM
287 if (getparam_quoted("include_users",buf,IncludeUsers+1,sizeof(IncludeUsers)-2)>0) {
288 IncludeUsers[0]=':';
289 strcat(IncludeUsers,":");
290 return;
291 }
491b862f 292
4af2f8ff 293 if (getparam_quoted("exclude_string",buf,ExcludeString,sizeof(ExcludeString))>0) return;
25697a35 294
4af2f8ff 295 if (getparam_string("privacy",buf,Privacy,sizeof(Privacy))>0) return;
25697a35 296
4af2f8ff 297 if (getparam_quoted("privacy_string",buf,ExcludeString,sizeof(ExcludeString))>0) return;
25697a35 298
4af2f8ff 299 if (getparam_string("privacy_string_color",buf,PrivacyStringColor,sizeof(PrivacyStringColor))>0) return;
25697a35 300
4af2f8ff 301 if (getparam_string("show_successful_message",buf,SuccessfulMsg,sizeof(SuccessfulMsg))>0) return;
25697a35 302
4af2f8ff 303 if (getparam_string("show_read_statistics",buf,ShowReadStatistics,sizeof(ShowReadStatistics))>0) return;
25697a35 304
4af2f8ff 305 if (getparam_string("topuser_fields",buf,TopUserFields,sizeof(TopUserFields))>0) return;
25697a35 306
4af2f8ff 307 if (getparam_string("bytes_in_sites_users_report",buf,BytesInSitesUsersReport,sizeof(BytesInSitesUsersReport))>0) return;
25697a35 308
4af2f8ff 309 if (getparam_string("user_report_fields",buf,UserReportFields,sizeof(UserReportFields))>0) return;
25697a35 310
4af2f8ff 311 if (getparam_string("bytes_in_sites_users_report",buf,BytesInSitesUsersReport,sizeof(BytesInSitesUsersReport))>0) return;
94ff9470 312
4af2f8ff 313 if (getparam_string("datafile",buf,DataFile,sizeof(DataFile))>0) return;
25697a35 314
4af2f8ff 315 if (getparam_quoted("datafile_delimiter",buf,DataFileDelimiter,sizeof(DataFileDelimiter))>0) return;
25697a35 316
4af2f8ff 317 if (getparam_string("datafile_fields",buf,DataFileFields,sizeof(DataFileFields))>0) return;
25697a35 318
4af2f8ff 319 if (getparam_string("datafile_url",buf,DataFileUrl,sizeof(DataFileUrl))>0) return;
25697a35 320
4af2f8ff 321 if (getparam_string("parsed_output_log",buf,ParsedOutputLog,sizeof(ParsedOutputLog))>0) return;
25697a35 322
4af2f8ff 323 if (getparam_string("parsed_output_log_compress",buf,ParsedOutputLogCompress,sizeof(ParsedOutputLogCompress))>0) return;
25697a35 324
4af2f8ff 325 if (getparam_string("displayed_values",buf,DisplayedValues,sizeof(DisplayedValues))>0) return;
25697a35 326
4af2f8ff 327 if (getparam_int("authfail_report_limit",buf,&AuthfailReportLimit)>0) return;
25697a35 328
4af2f8ff 329 if (getparam_int("denied_report_limit",buf,&DeniedReportLimit)>0) return;
25697a35 330
4af2f8ff 331 if (getparam_int("siteusers_report_limit",buf,&SiteUsersReportLimit)>0) return;
25697a35 332
4af2f8ff 333 if (getparam_int("dansguardian_report_limit",buf,&DansGuardianReportLimit)>0) return;
25697a35 334
4af2f8ff 335 if (getparam_int("squidguard_report_limit",buf,&SquidGuardReportLimit)>0) return;
25697a35 336
4af2f8ff 337 if (getparam_int("user_report_limit",buf,&UserReportLimit)>0) return;
491b862f 338
4af2f8ff 339 if (getparam_int("download_report_limit",buf,&DownloadReportLimit)>0) return;
491b862f 340
4af2f8ff 341 if (getparam_string("www_document_root",buf,wwwDocumentRoot,sizeof(wwwDocumentRoot))>0) return;
25697a35 342
4af2f8ff 343 if (getparam_string("block_it",buf,BlockIt,sizeof(BlockIt))>0) return;
491b862f 344
4af2f8ff 345 if (getparam_string("external_css_file",buf,ExternalCSSFile,sizeof(ExternalCSSFile))>0) return;
491b862f 346
4af2f8ff 347 if (getparam_string("user_authentication",buf,UserAuthentication,sizeof(UserAuthentication))>0) return;
491b862f 348
4af2f8ff 349 if (getparam_string("AuthUserFile",buf,AuthUserFile,sizeof(AuthUserFile))>0) return;
491b862f 350
4af2f8ff 351 if (getparam_string("AuthName",buf,AuthName,sizeof(AuthName))>0) return;
491b862f 352
4af2f8ff
FM
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;
d6e703cc 358
4af2f8ff
FM
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
e3af0ae9
PO
381 if (getparam_string("LDAPHost",buf,LDAPHost,sizeof(LDAPHost))>0) return;
382
383 if (getparam_string("LDAPPort",buf,LDAPPort,sizeof(LDAPPort))>0) return;
384
385 if (getparam_string("LDAPProtocolVersion",buf,LDAPProtocolVersion,sizeof(LDAPProtocolVersion))>0) return;
386
387 if (getparam_string("LDAPBindDN",buf,LDAPBindDN,sizeof(LDAPBindDN))>0) return;
388
389 if (getparam_string("LDAPBindPW",buf,LDAPBindPW,sizeof(LDAPBindPW))>0) return;
390
391 if (getparam_string("LDAPBaseSearch",buf,LDAPBaseSearch,sizeof(LDAPBaseSearch))>0) return;
392
393 if (getparam_string("LDAPFilterSearch",buf,LDAPFilterSearch,sizeof(LDAPFilterSearch))>0) return;
394
395 if (getparam_string("LDAPTargetAttr",buf,LDAPTargetAttr,sizeof(LDAPTargetAttr))>0) return;
396
4af2f8ff
FM
397 if(strstr(buf,"squid24") != 0) {
398 squid24++;
399 return;
400 }
401
402 if(strstr(buf,"byte_cost") != 0) {
403 if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
404 printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
405 exit(1);
406 }
407 cost=atol(buf);
408 if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
409 printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
410 exit(1);
491b862f 411 }
4af2f8ff
FM
412 nocost=my_atoll(buf);
413 return;
414 }
415
f29e90f8 416 printf("SARG: %s %s\n",text[140],buf);
d6e703cc
FM
417}
418
32e71fa4 419void getconf(void)
d6e703cc
FM
420{
421
422 FILE *fp_in;
423 char buf[MAXLEN];
424
d2fe0c32
FM
425 if(debug)
426 debuga("Loading configuration from: %s",ConfigFile);
d6e703cc
FM
427
428 if ((fp_in = fopen(ConfigFile, "r")) == NULL) {
429 fprintf(stderr, "SARG: (getconf) Cannot open file: %s\n",ConfigFile);
430 exit(1);
431 }
432
4af2f8ff
FM
433 while (fgets(buf, sizeof(buf), fp_in) != NULL) {
434 fixendofline(buf);
d6e703cc
FM
435
436 if(debugm)
3103300b 437 printf("SYSCONFDIR %s\n",buf);
d6e703cc 438
d6e703cc
FM
439 parmtest(buf);
440
441 }
442
443 fclose(fp_in);
444 language_load(language);
445 return;
25697a35 446}