2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
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.
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.
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.
26 #include "include/conf.h"
27 #include "include/defs.h"
29 extern numlist hours
, weekdays
;
31 static int is_param(const char *param
,const char *buf
)
36 if (strncmp(buf
,param
,plen
) != 0) return(0);
38 if ((unsigned char)*buf
>' ') return(0);
42 static int getparam_string(const char *param
,char *buf
,char *value
,int value_size
)
47 if (strncmp(buf
,param
,plen
) != 0) return(0);
49 if ((unsigned char)*buf
>' ') return(0);
50 while (*buf
&& (unsigned char)*buf
<=' ') buf
++;
52 if (strlen(buf
)>=value_size
) {
53 printf("SARG: Maybe you have a broken record or garbage in %s parameter.\n",param
);
61 static int getparam_quoted(const char *param
,char *buf
,char *value
,int value_size
)
67 if (strncmp(buf
,param
,plen
) != 0) return(0);
69 if ((unsigned char)*buf
>' ') return(0);
70 while (*buf
&& (unsigned char)*buf
<=' ') buf
++;
73 printf("SARG: %s %s.\n",text
[139],param
);
79 for (i
=0 ; i
<value_size
&& *buf
&& *buf
!='\"' ; i
++) {
85 printf("SARG: Missing double quote after parameter %s or value is more than %d bytes long.\n",param
,value_size
);
92 static int getparam_2words(const char *param
,char *buf
,char *word1
,int word1_size
,char *word2
,int word2_size
)
98 if (strncmp(buf
,param
,plen
) != 0) return(0);
100 if ((unsigned char)*buf
>' ') return(0);
101 while (*buf
&& (unsigned char)*buf
<=' ') buf
++;
103 for (i
=0 ; i
<word1_size
&& *buf
&& (unsigned char)*buf
>' ' ; i
++)
106 printf("SARG: The first word of parameter %s is more than %d bytes long.\n",param
,word1_size
-1);
110 printf("SARG: Missing second word for parameter %s.\n",param
);
115 while (*buf
&& (unsigned char)*buf
<=' ') buf
++;
117 for (i
=0 ; i
<word2_size
&& *buf
&& (unsigned char)*buf
>' ' ; i
++)
120 printf("SARG: The second word of parameter %s is more than %d bytes long.\n",param
,word2_size
-1);
130 static int getparam_int(const char *param
,char *buf
,int *value
)
136 if (strncmp(buf
,param
,plen
) != 0) return(0);
138 if ((unsigned char)*buf
>' ') return(0);
139 while (*buf
&& (unsigned char)*buf
<=' ') buf
++;
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
);
149 static int getparam_bool(const char *param
,char *buf
,int *value
)
153 const char *bool_str
="yes,true,on,1";
156 if (strncmp(buf
,param
,plen
) != 0) return(0);
158 if ((unsigned char)*buf
>' ') return(0);
159 while (*buf
&& (unsigned char)*buf
<=' ') buf
++;
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) {
168 if (bool_str
[i
]==',') i
++;
173 static void parmtest(char *buf
)
176 struct getwordstruct gwarea
;
178 while (*buf
&& (unsigned char)*buf
<=' ') buf
++;
180 if(*buf
== '#' || *buf
== '\0')
184 printf("SARG: TAG: %s\n",buf
);
186 if (getparam_string("background_color",buf
,BgColor
,sizeof(BgColor
))>0) return;
188 if (getparam_string("text_color",buf
,TxColor
,sizeof(TxColor
))>0) return;
190 if (getparam_string("text_bgcolor",buf
,TxBgColor
,sizeof(TxBgColor
))>0) return;
192 if (getparam_string("title_color",buf
,TiColor
,sizeof(TiColor
))>0) return;
194 if (getparam_string("logo_image",buf
,LogoImage
,sizeof(LogoImage
))>0) return;
196 if (getparam_quoted("logo_text",buf
,LogoText
,sizeof(LogoText
))>0) return;
198 if (getparam_string("logo_text_color",buf
,LogoTextColor
,sizeof(LogoTextColor
))>0) return;
200 if (getparam_string("background_image",buf
,BgImage
,sizeof(BgImage
))>0) return;
202 if (getparam_bool("show_sarg_info",buf
,&ShowSargInfo
)>0) return;
204 if (getparam_bool("show_sarg_logo",buf
,&ShowSargLogo
)>0) return;
206 if (getparam_string("font_face",buf
,FontFace
,sizeof(FontFace
))>0) return;
208 if (getparam_string("header_color",buf
,HeaderColor
,sizeof(HeaderColor
))>0) return;
210 if (getparam_string("header_bgcolor",buf
,HeaderBgColor
,sizeof(HeaderBgColor
))>0) return;
212 if (getparam_string("font_size",buf
,FontSize
,sizeof(FontSize
))>0) return;
214 if (getparam_string("header_font_size",buf
,HeaderFontSize
,sizeof(HeaderFontSize
))>0) return;
216 if (getparam_string("title_font_size",buf
,TitleFontSize
,sizeof(TitleFontSize
))>0) return;
218 if (getparam_2words("image_size",buf
,Width
,sizeof(Width
),Height
,sizeof(Height
))>0) return;
220 if (getparam_quoted("title",buf
,Title
,sizeof(Title
))>0) return;
222 if (getparam_bool("resolve_ip",buf
,&Ip2Name
)>0) return;
224 if (getparam_bool("user_ip",buf
,&UserIp
)>0) return;
226 if (getparam_string("max_elapsed",buf
,MaxElapsed
,sizeof(MaxElapsed
))>0) return;
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");
234 strncpy(DateFormat
,gwarea
.current
,1);
239 if (is_param("hours",buf
)) {
240 if( getnumlist( buf
, &hours
, 24, 24 ) ) {
241 fprintf( stderr
, "Error: Invalid syntax in hours tag!\n" );
246 if (is_param("weekdays",buf
)) {
247 if( getnumlist( buf
, &weekdays
, 7, 7 ) ) {
248 fprintf( stderr
, "Error: Invalid syntax in weekdays tag!\n" );
253 if (getparam_2words("topuser_sort_field",buf
,TopuserSortField
,sizeof(TopuserSortField
),TopuserSortOrder
,sizeof(TopuserSortOrder
))>0) return;
255 if (getparam_2words("user_sort_field",buf
,UserSortField
,sizeof(UserSortField
),UserSortOrder
,sizeof(UserSortOrder
))>0) return;
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");
263 getparam_string("access_log",buf
,AccessLog
[NAccessLog
],MAXLEN
);
269 if (getparam_string("useragent_log",buf
,UserAgentLog
,sizeof(UserAgentLog
))>0) return;
271 if (getparam_string("exclude_hosts",buf
,ExcludeHosts
,sizeof(ExcludeHosts
))>0) return;
273 if (getparam_string("exclude_codes",buf
,ExcludeCodes
,sizeof(ExcludeCodes
))>0) return;
275 if (getparam_string("exclude_users",buf
,ExcludeUsers
,sizeof(ExcludeUsers
))>0) return;
277 if (getparam_string("password",buf
,PasswdFile
,sizeof(PasswdFile
))>0) return;
279 if (getparam_string("temporary_dir",buf
,TempDir
,sizeof(TempDir
))>0) return;
281 if (getparam_string("report_type",buf
,ReportType
,sizeof(ReportType
))>0) return;
283 if (getparam_string("output_dir",buf
,OutputDir
,sizeof(OutputDir
))>0) return;
285 if (getparam_string("output_email",buf
,OutputEmail
,sizeof(OutputEmail
))>0) return;
287 if (getparam_2words("per_user_limit",buf
,PerUserLimitFile
,sizeof(PerUserLimitFile
),wbuf
,sizeof(wbuf
))>0) {
288 PerUserLimit
=atoi(wbuf
);
292 if (getparam_int("lastlog",buf
,&LastLog
)>0) return;
294 if (getparam_bool("remove_temp_files",buf
,&RemoveTempFiles
)>0) return;
296 if (getparam_string("replace_index",buf
,ReplaceIndex
,sizeof(ReplaceIndex
))>0) return;
298 if (getparam_string("index_tree",buf
,IndexTree
,sizeof(IndexTree
))>0) return;
300 if (getparam_string("index",buf
,Index
,sizeof(Index
))>0) return;
302 if (getparam_bool("overwrite_report",buf
,&OverwriteReport
)>0) return;
304 if (getparam_string("records_without_userid",buf
,RecordsWithoutUser
,sizeof(RecordsWithoutUser
))>0) return;
306 if (getparam_bool("use_comma",buf
,&UseComma
)>0) return;
308 if (getparam_string("mail_utility",buf
,MailUtility
,sizeof(MailUtility
))>0) return;
310 if (getparam_string("topsites_num",buf
,TopSitesNum
,sizeof(TopSitesNum
))>0) return;
312 if (getparam_int("topuser_num",buf
,&TopUsersNum
)>0) return;
314 if (getparam_string("usertab",buf
,UserTabFile
,sizeof(UserTabFile
))>0) return;
316 if (getparam_string("index_sort_order",buf
,IndexSortOrder
,sizeof(IndexSortOrder
))>0) return;
318 if (getparam_2words("topsites_sort_order",buf
,TopsitesSortField
,sizeof(TopsitesSortField
),TopsitesSortType
,sizeof(TopsitesSortType
))>0) return;
320 if (getparam_bool("long_url",buf
,&LongUrl
)>0) return;
322 if (getparam_string("language",buf
,language
,sizeof(language
))>0) return;
324 if (getparam_string("dansguardian_conf",buf
,DansGuardianConf
,sizeof(DansGuardianConf
))>0) return;
326 if (getparam_string("squidguard_conf",buf
,SquidGuardConf
,sizeof(SquidGuardConf
))>0) return;
328 if (getparam_string("date_time_by",buf
,datetimeby
,sizeof(datetimeby
))>0) return;
330 if (getparam_string("charset",buf
,CharSet
,sizeof(CharSet
))>0) {
335 if (getparam_quoted("user_invalid_char",buf
,UserInvalidChar
,sizeof(UserInvalidChar
))>0) return;
337 if (getparam_quoted("include_users",buf
,IncludeUsers
+1,sizeof(IncludeUsers
)-2)>0) {
339 strcat(IncludeUsers
,":");
343 if (getparam_quoted("exclude_string",buf
,ExcludeString
,sizeof(ExcludeString
))>0) return;
345 if (getparam_bool("privacy",buf
,&Privacy
)>0) return;
347 if (getparam_quoted("privacy_string",buf
,PrivacyString
,sizeof(PrivacyString
))>0) return;
349 if (getparam_string("privacy_string_color",buf
,PrivacyStringColor
,sizeof(PrivacyStringColor
))>0) return;
351 if (getparam_bool("show_successful_message",buf
,&SuccessfulMsg
)>0) return;
353 if (getparam_bool("show_read_statistics",buf
,&ShowReadStatistics
)>0) return;
355 if (getparam_string("topuser_fields",buf
,TopUserFields
,sizeof(TopUserFields
))>0) return;
357 if (getparam_bool("bytes_in_sites_users_report",buf
,&BytesInSitesUsersReport
)>0) return;
359 if (getparam_string("user_report_fields",buf
,UserReportFields
,sizeof(UserReportFields
))>0) return;
361 if (getparam_string("datafile",buf
,DataFile
,sizeof(DataFile
))>0) return;
363 if (getparam_quoted("datafile_delimiter",buf
,DataFileDelimiter
,sizeof(DataFileDelimiter
))>0) return;
365 if (getparam_string("datafile_fields",buf
,DataFileFields
,sizeof(DataFileFields
))>0) return;
367 if (getparam_string("datafile_url",buf
,DataFileUrl
,sizeof(DataFileUrl
))>0) return;
369 if (getparam_string("parsed_output_log",buf
,ParsedOutputLog
,sizeof(ParsedOutputLog
))>0) return;
371 if (getparam_string("parsed_output_log_compress",buf
,ParsedOutputLogCompress
,sizeof(ParsedOutputLogCompress
))>0) return;
373 if (getparam_string("displayed_values",buf
,DisplayedValues
,sizeof(DisplayedValues
))>0) return;
375 if (getparam_int("authfail_report_limit",buf
,&AuthfailReportLimit
)>0) return;
377 if (getparam_int("denied_report_limit",buf
,&DeniedReportLimit
)>0) return;
379 if (getparam_int("siteusers_report_limit",buf
,&SiteUsersReportLimit
)>0) return;
381 if (getparam_int("dansguardian_report_limit",buf
,&DansGuardianReportLimit
)>0) return;
383 if (getparam_int("squidguard_report_limit",buf
,&SquidGuardReportLimit
)>0) return;
385 if (getparam_int("user_report_limit",buf
,&UserReportLimit
)>0) return;
387 if (getparam_int("download_report_limit",buf
,&DownloadReportLimit
)>0) return;
389 if (getparam_string("www_document_root",buf
,wwwDocumentRoot
,sizeof(wwwDocumentRoot
))>0) return;
391 if (getparam_string("block_it",buf
,BlockIt
,sizeof(BlockIt
))>0) return;
393 if (getparam_string("external_css_file",buf
,ExternalCSSFile
,sizeof(ExternalCSSFile
))>0) return;
395 if (getparam_bool("user_authentication",buf
,&UserAuthentication
)>0) return;
397 if (getparam_string("AuthUserFile",buf
,AuthUserFile
,sizeof(AuthUserFile
))>0) return;
399 if (getparam_string("AuthName",buf
,AuthName
,sizeof(AuthName
))>0) return;
401 if (getparam_string("AuthType",buf
,AuthType
,sizeof(AuthType
))>0) return;
403 if (getparam_string("Require",buf
,Require
,sizeof(Require
))>0) return;
405 if (is_param("download_suffix",buf
)) {
408 getparam_quoted("download_suffix",buf
,warea
,sizeof(warea
));
409 set_download_suffix(warea
);
413 if (getparam_bool("graphs",buf
,&Graphs
)>0) return;
415 if (getparam_string("graph_days_bytes_bar_color",buf
,GraphDaysBytesBarColor
,sizeof(GraphDaysBytesBarColor
))>0) return;
417 if (getparam_string("squidguard_log_format",buf
,SquidGuardLogFormat
,sizeof(SquidGuardLogFormat
))>0) return;
419 if (getparam_bool("squidguard_ignore_date",buf
,&SquidguardIgnoreDate
)>0) return;
421 if (getparam_bool("dansguardian_ignore_date",buf
,&DansguardianIgnoreDate
)>0) return;
423 if (getparam_string("ulimit",buf
,Ulimit
,sizeof(Ulimit
))>0) return;
425 if (getparam_string("ntlm_user_format",buf
,NtlmUserFormat
,sizeof(NtlmUserFormat
))>0) return;
427 if (getparam_string("realtime_types",buf
,RealtimeTypes
,sizeof(RealtimeTypes
))>0) return;
429 if (getparam_string("realtime_unauthenticated_records",buf
,RealtimeUnauthRec
,sizeof(RealtimeUnauthRec
))>0) return;
431 if (getparam_int("realtime_refresh_time",buf
,&realtime_refresh
)>0) return;
433 if (getparam_int("realtime_access_log_lines",buf
,&realtime_access_log_lines
)>0) return;
435 if(strstr(buf
,"squid24") != 0) {
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");
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");
451 nocost
=my_atoll(gwarea
.current
);
455 printf("SARG: %s %s\n",text
[140],buf
);
465 debuga("Loading configuration from: %s",ConfigFile
);
467 if ((fp_in
= fopen(ConfigFile
, "r")) == NULL
) {
468 fprintf(stderr
, "SARG: (getconf) Cannot open file: %s\n",ConfigFile
);
472 while (fgets(buf
, sizeof(buf
), fp_in
) != NULL
) {
476 printf("SYSCONFDIR %s\n",buf
);
483 language_load(language
);