1 rizwank 1.1 #!/usr/bin/perl
2 #------------------------------------------------------------------------------
3 # Free realtime web server logfile analyzer to show advanced web statistics.
4 # Works from command line or as a CGI. You must use this script as often as
5 # necessary from your scheduler to update your statistics and from command
6 # line or a browser to read report results.
7 # See AWStats documentation (in docs/ directory) for all setup instructions.
8 #------------------------------------------------------------------------------
9 # $Revision: 1.800 $ - $Author: eldy $ - $Date: 2005/01/22 16:34:38 $
10 require 5.005;
11
12 push @INC, ".";
13 push @INC, "./plugins";
14 push @INC, "../wwwroot/cgi-bin/plugins";
15 push @INC, "/home/rizwank/lib/perl/5.6.1";
16
17
18 #$|=1;
19 #use warnings; # Must be used in test mode only. This reduce a little process speed
20 #use diagnostics; # Must be used in test mode only. This reduce a lot of process speed
21 use strict;no strict "refs";
22 rizwank 1.1 use Time::Local; # use Time::Local 'timelocal_nocheck' is faster but not supported by all Time::Local modules
23 use Socket;
24
25
26 #------------------------------------------------------------------------------
27 # Defines
28 #------------------------------------------------------------------------------
29 use vars qw/ $REVISION $VERSION /;
30 $REVISION='$Revision: 1.800 $'; $REVISION =~ /\s(.*)\s/; $REVISION=$1;
31 $VERSION="6.3 (build $REVISION)";
32
33 # ----- Constants -----
34 use vars qw/
35 $DEBUGFORCED $NBOFLINESFORBENCHMARK $FRAMEWIDTH $NBOFLASTUPDATELOOKUPTOSAVE
36 $LIMITFLUSH $NEWDAYVISITTIMEOUT $VISITTIMEOUT $NOTSORTEDRECORDTOLERANCE
37 $WIDTHCOLICON $TOOLTIPON
38 $lastyearbeforeupdate
39 /;
40 $DEBUGFORCED=0; # Force debug level to log lesser level into debug.log file (Keep this value to 0)
41 $NBOFLINESFORBENCHMARK=8192; # Benchmark info are printing every NBOFLINESFORBENCHMARK lines (Must be a power of 2)
42 $FRAMEWIDTH=240; # Width of left frame when UseFramesWhenCGI is on
43 rizwank 1.1 $NBOFLASTUPDATELOOKUPTOSAVE=500; # Nb of records to save in DNS last update cache file
44 $LIMITFLUSH=5000; # Nb of records in data arrays after how we need to flush data on disk
45 $NEWDAYVISITTIMEOUT=764041; # Delay between 01-23:59:59 and 02-00:00:00
46 $VISITTIMEOUT=10000; # Lapse of time to consider a page load as a new visit. 10000 = 1 hour (Default = 10000)
47 $NOTSORTEDRECORDTOLERANCE=20000; # Lapse of time to accept a record if not in correct order. 20000 = 2 hour (Default = 20000)
48 $WIDTHCOLICON=32;
49 $TOOLTIPON=0; # Tooltips plugin loaded
50 # ----- Running variables -----
51 use vars qw/
52 $DIR $PROG $Extension
53 $Debug $ShowSteps
54 $DebugResetDone $DNSLookupAlreadyDone
55 $RunAsCli $UpdateFor $HeaderHTTPSent $HeaderHTMLSent
56 $LastLine $LastLineNumber $LastLineOffset $LastLineChecksum $LastUpdate
57 $lowerval
58 $PluginMode
59 $TotalUnique $TotalVisits $TotalHostsKnown $TotalHostsUnknown
60 $TotalPages $TotalHits $TotalBytes
61 $TotalNotViewedPages $TotalNotViewedHits $TotalNotViewedBytes
62 $TotalEntries $TotalExits $TotalBytesPages $TotalDifferentPages
63 $TotalKeyphrases $TotalKeywords $TotalDifferentKeyphrases $TotalDifferentKeywords
64 rizwank 1.1 $TotalSearchEnginesPages $TotalSearchEnginesHits $TotalRefererPages $TotalRefererHits $TotalDifferentSearchEngines $TotalDifferentReferer
65 $FrameName $Center $FileConfig $FileSuffix $Host $DayRequired $MonthRequired $YearRequired
66 $QueryString $SiteConfig $StaticLinks $PageCode $PageDir $PerlParsingFormat $UserAgent
67 $pos_vh $pos_host $pos_logname $pos_date $pos_tz $pos_method $pos_url $pos_code $pos_size
68 $pos_referer $pos_agent $pos_query $pos_gzipin $pos_gzipout $pos_compratio $pos_timetaken
69 $pos_cluster $pos_emails $pos_emailr $pos_hostr @pos_extra
70 /;
71 $DIR=$PROG=$Extension='';
72 $Debug = $ShowSteps = 0;
73 $DebugResetDone = $DNSLookupAlreadyDone = 0;
74 $RunAsCli = $UpdateFor = $HeaderHTTPSent = $HeaderHTMLSent = 0;
75 $LastLine = $LastLineNumber = $LastLineOffset = $LastLineChecksum = $LastUpdate = 0;
76 $lowerval = 0;
77 $PluginMode = '';
78 $TotalUnique = $TotalVisits = $TotalHostsKnown = $TotalHostsUnknown = 0;
79 $TotalPages = $TotalHits = $TotalBytes = 0;
80 $TotalNotViewedPages = $TotalNotViewedHits = $TotalNotViewedBytes = 0;
81 $TotalEntries = $TotalExits = $TotalBytesPages = $TotalDifferentPages = 0;
82 $TotalKeyphrases = $TotalKeywords = $TotalDifferentKeyphrases = $TotalDifferentKeywords = 0;
83 $TotalSearchEnginesPages = $TotalSearchEnginesHits = $TotalRefererPages = $TotalRefererHits = $TotalDifferentSearchEngines = $TotalDifferentReferer = 0;
84 ($FrameName, $Center, $FileConfig, $FileSuffix, $Host, $DayRequired, $MonthRequired, $YearRequired,
85 rizwank 1.1 $QueryString, $SiteConfig, $StaticLinks, $PageCode, $PageDir, $PerlParsingFormat, $UserAgent)=
86 ('','','','','','','','','','','','','','','');
87 $pos_vh = $pos_host = $pos_logname = $pos_date = $pos_tz = $pos_method = $pos_url = $pos_code = $pos_size = -1;
88 $pos_referer = $pos_agent = $pos_query = $pos_gzipin = $pos_gzipout = $pos_compratio = -1;
89 $pos_cluster = $pos_emails = $pos_emailr = $pos_hostr = -1;
90 @pos_extra=();
91 # ----- Plugins variable -----
92 use vars qw/ %PluginsLoaded $PluginDir $AtLeastOneSectionPlugin /;
93 %PluginsLoaded=();
94 $PluginDir='';
95 $AtLeastOneSectionPlugin=0;
96 # ----- Time vars -----
97 use vars qw/
98 $starttime
99 $nowtime $tomorrowtime
100 $nowweekofmonth $nowweekofyear $nowdaymod $nowsmallyear
101 $nowsec $nowmin $nowhour $nowday $nowmonth $nowyear $nowwday $nowyday $nowns
102 $StartSeconds $StartMicroseconds
103 /;
104 $StartSeconds=$StartMicroseconds=0;
105 # ----- Variables for config file reading -----
106 rizwank 1.1 use vars qw/
107 $FoundNotPageList
108 /;
109 $FoundNotPageList=0;
110 # ----- Config file variables -----
111 use vars qw/
112 $StaticExt
113 $DNSStaticCacheFile
114 $DNSLastUpdateCacheFile
115 $MiscTrackerUrl
116 $Lang
117 $MaxRowsInHTMLOutput
118 $MaxLengthOfShownURL
119 $MaxLengthOfStoredURL
120 $MaxLengthOfStoredUA
121 %BarPng
122 $BuildReportFormat
123 $BuildHistoryFormat
124 $ExtraTrackedRowsLimit
125 /;
126 $StaticExt='html';
127 rizwank 1.1 $DNSStaticCacheFile='dnscache.txt';
128 $DNSLastUpdateCacheFile='dnscachelastupdate.txt';
129 $MiscTrackerUrl='/js/awstats_misc_tracker.js';
130 $Lang='auto';
131 $MaxRowsInHTMLOutput=1000;
132 $MaxLengthOfShownURL=64;
133 $MaxLengthOfStoredURL=256; # Note: Apache LimitRequestLine is default to 8190
134 $MaxLengthOfStoredUA=256;
135 %BarPng=('vv'=>'vv.png','vu'=>'vu.png','hu'=>'hu.png','vp'=>'vp.png','hp'=>'hp.png',
136 'he'=>'he.png','hx'=>'hx.png','vh'=>'vh.png','hh'=>'hh.png','vk'=>'vk.png','hk'=>'hk.png');
137 $BuildReportFormat='html';
138 $BuildHistoryFormat='text';
139 $ExtraTrackedRowsLimit=500;
140 use vars qw/
141 $EnableLockForUpdate $DNSLookup $AllowAccessFromWebToAuthenticatedUsersOnly
142 $BarHeight $BarWidth $CreateDirDataIfNotExists $KeepBackupOfHistoricFiles
143 $NbOfLinesParsed $NbOfLinesDropped $NbOfLinesCorrupted $NbOfOldLines $NbOfNewLines
144 $NbOfLinesShowsteps $NewLinePhase $NbOfLinesForCorruptedLog $PurgeLogFile $ArchiveLogRecords
145 $ShowDropped $ShowCorrupted $ShowUnknownOrigin $ShowLinksToWhoIs
146 $ShowAuthenticatedUsers $ShowFileSizesStats $ShowScreenSizeStats $ShowSMTPErrorsStats
147 $ShowEMailSenders $ShowEMailReceivers $ShowWormsStats $ShowClusterStats
148 rizwank 1.1 $IncludeInternalLinksInOriginSection
149 $AuthenticatedUsersNotCaseSensitive
150 $Expires $UpdateStats $MigrateStats $URLNotCaseSensitive $URLWithQuery $URLReferrerWithQuery
151 $DecodeUA
152 /;
153 ($EnableLockForUpdate, $DNSLookup, $AllowAccessFromWebToAuthenticatedUsersOnly,
154 $BarHeight, $BarWidth, $CreateDirDataIfNotExists, $KeepBackupOfHistoricFiles,
155 $NbOfLinesParsed, $NbOfLinesDropped, $NbOfLinesCorrupted, $NbOfOldLines, $NbOfNewLines,
156 $NbOfLinesShowsteps, $NewLinePhase, $NbOfLinesForCorruptedLog, $PurgeLogFile, $ArchiveLogRecords,
157 $ShowDropped, $ShowCorrupted, $ShowUnknownOrigin, $ShowLinksToWhoIs,
158 $ShowAuthenticatedUsers, $ShowFileSizesStats, $ShowScreenSizeStats, $ShowSMTPErrorsStats,
159 $ShowEMailSenders, $ShowEMailReceivers, $ShowWormsStats, $ShowClusterStats,
160 $IncludeInternalLinksInOriginSection,
161 $AuthenticatedUsersNotCaseSensitive,
162 $Expires, $UpdateStats, $MigrateStats, $URLNotCaseSensitive, $URLWithQuery, $URLReferrerWithQuery,
163 $DecodeUA)=
164 (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
165 use vars qw/
166 $AllowToUpdateStatsFromBrowser $DetailedReportsOnNewWindows
167 $FirstDayOfWeek $KeyWordsNotSensitive $SaveDatabaseFilesWithPermissionsForEveryone
168 $WarningMessages $DebugMessages $ShowLinksOnUrl $UseFramesWhenCGI
169 rizwank 1.1 $ShowMenu $ShowMonthStats $ShowDaysOfMonthStats $ShowDaysOfWeekStats
170 $ShowHoursStats $ShowDomainsStats $ShowHostsStats
171 $ShowRobotsStats $ShowSessionsStats $ShowPagesStats $ShowFileTypesStats
172 $ShowOSStats $ShowBrowsersStats $ShowOriginStats
173 $ShowKeyphrasesStats $ShowKeywordsStats $ShowMiscStats $ShowHTTPErrorsStats
174 $AddDataArrayMonthStats $AddDataArrayShowDaysOfMonthStats $AddDataArrayShowDaysOfWeekStats $AddDataArrayShowHoursStats
175 /;
176 ($AllowToUpdateStatsFromBrowser, $DetailedReportsOnNewWindows,
177 $FirstDayOfWeek, $KeyWordsNotSensitive, $SaveDatabaseFilesWithPermissionsForEveryone,
178 $WarningMessages, $DebugMessages, $ShowLinksOnUrl, $UseFramesWhenCGI,
179 $ShowMenu, $ShowMonthStats, $ShowDaysOfMonthStats, $ShowDaysOfWeekStats,
180 $ShowHoursStats, $ShowDomainsStats, $ShowHostsStats,
181 $ShowRobotsStats, $ShowSessionsStats, $ShowPagesStats, $ShowFileTypesStats,
182 $ShowOSStats, $ShowBrowsersStats, $ShowOriginStats,
183 $ShowKeyphrasesStats, $ShowKeywordsStats, $ShowMiscStats, $ShowHTTPErrorsStats,
184 $AddDataArrayMonthStats, $AddDataArrayShowDaysOfMonthStats, $AddDataArrayShowDaysOfWeekStats, $AddDataArrayShowHoursStats
185 )=
186 (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
187 use vars qw/
188 $AllowFullYearView
189 $LevelForRobotsDetection $LevelForWormsDetection $LevelForBrowsersDetection $LevelForOSDetection $LevelForRefererAnalyze
190 rizwank 1.1 $LevelForFileTypesDetection $LevelForSearchEnginesDetection $LevelForKeywordsDetection
191 /;
192 ($AllowFullYearView,
193 $LevelForRobotsDetection, $LevelForWormsDetection, $LevelForBrowsersDetection, $LevelForOSDetection, $LevelForRefererAnalyze,
194 $LevelForFileTypesDetection, $LevelForSearchEnginesDetection, $LevelForKeywordsDetection)=
195 (2,2,0,2,2,2,2,2,2);
196 use vars qw/
197 $DirLock $DirCgi $DirConfig $DirData $DirIcons $DirLang $AWScript $ArchiveFileName
198 $AllowAccessFromWebToFollowingIPAddresses $HTMLHeadSection $HTMLEndSection $LinksToWhoIs $LinksToIPWhoIs
199 $LogFile $LogType $LogFormat $LogSeparator $Logo $LogoLink $StyleSheet $WrapperScript $SiteDomain
200 $UseHTTPSLinkForUrl $URLQuerySeparators $URLWithAnchor $ErrorMessages $ShowFlagLinks
201 /;
202 ($DirLock, $DirCgi, $DirConfig, $DirData, $DirIcons, $DirLang, $AWScript, $ArchiveFileName,
203 $AllowAccessFromWebToFollowingIPAddresses, $HTMLHeadSection, $HTMLEndSection, $LinksToWhoIs, $LinksToIPWhoIs,
204 $LogFile, $LogType, $LogFormat, $LogSeparator, $Logo, $LogoLink, $StyleSheet, $WrapperScript, $SiteDomain,
205 $UseHTTPSLinkForUrl, $URLQuerySeparators, $URLWithAnchor, $ErrorMessages, $ShowFlagLinks)=
206 ('','','','','','','','','','','','','','','','','','','','','','','','','','','');
207 use vars qw/
208 $color_Background $color_TableBG $color_TableBGRowTitle
209 $color_TableBGTitle $color_TableBorder $color_TableRowTitle $color_TableTitle
210 $color_text $color_textpercent $color_titletext $color_weekend $color_link $color_hover $color_other
211 rizwank 1.1 $color_h $color_k $color_p $color_e $color_x $color_s $color_u $color_v
212 /;
213 ($color_Background, $color_TableBG, $color_TableBGRowTitle,
214 $color_TableBGTitle, $color_TableBorder, $color_TableRowTitle, $color_TableTitle,
215 $color_text, $color_textpercent, $color_titletext, $color_weekend, $color_link, $color_hover, $color_other,
216 $color_h, $color_k, $color_p, $color_e, $color_x, $color_s, $color_u, $color_v)=
217 ('','','','','','','','','','','','','','','','','','','','','','');
218 # ---------- Init arrays --------
219 use vars qw/
220 @RobotsSearchIDOrder_list1 @RobotsSearchIDOrder_list2 @RobotsSearchIDOrder_listgen
221 @SearchEnginesSearchIDOrder_list1 @SearchEnginesSearchIDOrder_list2 @SearchEnginesSearchIDOrder_listgen
222 @BrowsersSearchIDOrder @OSSearchIDOrder @WordsToExtractSearchUrl @WordsToCleanSearchUrl
223 @WormsSearchIDOrder
224 @RobotsSearchIDOrder @SearchEnginesSearchIDOrder
225 @_from_p @_from_h
226 @_time_p @_time_h @_time_k @_time_nv_p @_time_nv_h @_time_nv_k
227 @DOWIndex @fieldlib @keylist
228 /;
229 @RobotsSearchIDOrder = @SearchEnginesSearchIDOrder = ();
230 @_from_p = @_from_h = ();
231 @_time_p = @_time_h = @_time_k = @_time_nv_p = @_time_nv_h = @_time_nv_k = ();
232 rizwank 1.1 @DOWIndex = @fieldlib = @keylist = ();
233 use vars qw/
234 @MiscListOrder %MiscListCalc
235 @OSFamily %BrowsersFamily @SessionsRange %SessionsAverage
236 %LangBrowserToLangAwstats %LangAWStatsToFlagAwstats
237 @HostAliases @AllowAccessFromWebToFollowingAuthenticatedUsers
238 @DefaultFile @SkipDNSLookupFor
239 @SkipHosts @SkipUserAgents @SkipFiles
240 @OnlyHosts @OnlyUserAgents @OnlyFiles
241 @URLWithQueryWithOnly @URLWithQueryWithout
242 @ExtraName @ExtraCondition @ExtraStatTypes @MaxNbOfExtra @MinHitExtra
243 @ExtraFirstColumnTitle @ExtraFirstColumnValues @ExtraFirstColumnFormat
244 @ExtraCodeFilter @ExtraConditionType @ExtraConditionTypeVal
245 @ExtraFirstColumnValuesType @ExtraFirstColumnValuesTypeVal
246 @ExtraAddAverageRow @ExtraAddSumRow
247 @PluginsToLoad
248 /;
249 @MiscListOrder=('AddToFavourites','JavascriptDisabled','JavaEnabled','DirectorSupport','FlashSupport','RealPlayerSupport','QuickTimeSupport','WindowsMediaPlayerSupport','PDFSupport');
250 %MiscListCalc=('TotalMisc'=>'','AddToFavourites'=>'u','JavascriptDisabled'=>'hm','JavaEnabled'=>'hm','DirectorSupport'=>'hm','FlashSupport'=>'hm','RealPlayerSupport'=>'hm','QuickTimeSupport'=>'hm','WindowsMediaPlayerSupport'=>'hm','PDFSupport'=>'hm');
251 @OSFamily=('win','mac');
252 %BrowsersFamily=('msie'=>1,'firefox'=>2,'netscape'=>3);
253 rizwank 1.1 @SessionsRange=('0s-30s','30s-2mn','2mn-5mn','5mn-15mn','15mn-30mn','30mn-1h','1h+');
254 %SessionsAverage=('0s-30s',15,'30s-2mn',75,'2mn-5mn',210,'5mn-15mn',600,'15mn-30mn',1350,'30mn-1h',2700,'1h+',3600);
255 # HTTP-Accept or Lang parameter => AWStats code to use for lang
256 # ISO-639-1 or 2 or other => awstats-xx.txt where xx is ISO-639-1
257 %LangBrowserToLangAwstats=(
258 'sq'=>'al','ar'=>'ar','ba'=>'ba','bg'=>'bg','zh-tw'=>'tw','zh'=>'cn','cz'=>'cz',
259 'de'=>'de','da'=>'dk',
260 'en'=>'en','et'=>'et','fi'=>'fi','fr'=>'fr','gl'=>'gl',
261 'es'=>'es','eu'=>'eu','ca'=>'ca',
262 'el'=>'gr','hu'=>'hu','is'=>'is','in'=>'id','it'=>'it',
263 'ja'=>'jp','ko'=>'kr','lv'=>'lv','nl'=>'nl','no'=>'nb','nb'=>'nb','nn'=>'nn',
264 'pl'=>'pl','pt'=>'pt','pt-br'=>'br','ro'=>'ro','ru'=>'ru','sr'=>'sr','sk'=>'sk',
265 'sv'=>'se','th'=>'th','tr'=>'tr','uk'=>'ua','cy'=>'cy','wlk'=>'cy'
266 );
267 %LangAWStatsToFlagAwstats=( # If flag (country ISO-3166 two letters) is not same than AWStats Lang code
268 'ca'=>'es_cat','et'=>'ee','eu','es_eu',
269 'cy'=>'wlk',
270 'gl'=>'glg',
271 'he'=>'il',
272 'ar'=>'sa',
273 'sr'=>'cs'
274 rizwank 1.1 );
275 @HostAliases = @AllowAccessFromWebToFollowingAuthenticatedUsers=();
276 @DefaultFile = @SkipDNSLookupFor = ();
277 @SkipHosts = @SkipUserAgents = @SkipFiles = ();
278 @OnlyHosts = @OnlyUserAgents = @OnlyFiles = ();
279 @URLWithQueryWithOnly = @URLWithQueryWithout = ();
280 @ExtraName = @ExtraCondition = @ExtraStatTypes = @MaxNbOfExtra = @MinHitExtra = ();
281 @ExtraFirstColumnTitle = @ExtraFirstColumnValues = @ExtraFirstColumnFormat = ();
282 @ExtraCodeFilter = @ExtraConditionType = @ExtraConditionTypeVal = ();
283 @ExtraFirstColumnValuesType = @ExtraFirstColumnValuesTypeVal = ();
284 @ExtraAddAverageRow = @ExtraAddSumRow = ();
285 @PluginsToLoad = ();
286 # ---------- Init hash arrays --------
287 use vars qw/
288 %BrowsersHashIDLib %BrowsersHashIcon %BrowsersHereAreGrabbers
289 %DomainsHashIDLib
290 %MimeHashLib %MimeHashIcon %MimeHashFamily
291 %OSHashID %OSHashLib
292 %RobotsHashIDLib %RobotsAffiliateLib
293 %SearchEnginesHashID %SearchEnginesHashLib %SearchEnginesWithKeysNotInQuery %SearchEnginesKnownUrl %NotSearchEnginesKeys
294 %WormsHashID %WormsHashLib %WormsHashTarget
295 rizwank 1.1 /;
296 use vars qw/
297 %HTMLOutput %NoLoadPlugin %FilterIn %FilterEx
298 %BadFormatWarning
299 %MonthNumLib
300 %ValidHTTPCodes %ValidSMTPCodes
301 %TrapInfosForHTTPErrorCodes %NotPageList %DayBytes %DayHits %DayPages %DayVisits
302 %MaxNbOf %MinHit
303 %ListOfYears %HistoryAlreadyFlushed %PosInFile %ValueInFile
304 %val %nextval %egal
305 %TmpDNSLookup %TmpOS %TmpRefererServer %TmpRobot %TmpBrowser %MyDNSTable
306 /;
307 %HTMLOutput = %NoLoadPlugin = %FilterIn = %FilterEx = ();
308 %BadFormatWarning = ();
309 %MonthNumLib = ();
310 %ValidHTTPCodes = %ValidSMTPCodes = ();
311 %TrapInfosForHTTPErrorCodes=(); $TrapInfosForHTTPErrorCodes{404}=1; # TODO Add this in config file
312 %NotPageList=();
313 %DayBytes = %DayHits = %DayPages = %DayVisits = ();
314 %MaxNbOf = %MinHit = ();
315 %ListOfYears = %HistoryAlreadyFlushed = %PosInFile = %ValueInFile = ();
316 rizwank 1.1 %val = %nextval = %egal = ();
317 %TmpDNSLookup = %TmpOS = %TmpRefererServer = %TmpRobot = %TmpBrowser = %MyDNSTable = ();
318 use vars qw/
319 %FirstTime %LastTime
320 %MonthHostsKnown %MonthHostsUnknown
321 %MonthUnique %MonthVisits
322 %MonthPages %MonthHits %MonthBytes
323 %MonthNotViewedPages %MonthNotViewedHits %MonthNotViewedBytes
324 %_session %_browser_h
325 %_domener_p %_domener_h %_domener_k %_errors_h %_errors_k
326 %_filetypes_h %_filetypes_k %_filetypes_gz_in %_filetypes_gz_out
327 %_host_p %_host_h %_host_k %_host_l %_host_s %_host_u
328 %_waithost_e %_waithost_l %_waithost_s %_waithost_u
329 %_keyphrases %_keywords %_os_h %_pagesrefs_p %_pagesrefs_h %_robot_h %_robot_k %_robot_l %_robot_r
330 %_worm_h %_worm_k %_worm_l %_login_h %_login_p %_login_k %_login_l %_screensize_h
331 %_misc_p %_misc_h %_misc_k
332 %_cluster_p %_cluster_h %_cluster_k
333 %_se_referrals_p %_se_referrals_h %_sider404_h %_referer404_h %_url_p %_url_k %_url_e %_url_x
334 %_unknownreferer_l %_unknownrefererbrowser_l
335 %_emails_h %_emails_k %_emails_l %_emailr_h %_emailr_k %_emailr_l
336 /;
337 rizwank 1.1 &Init_HashArray();
338 # ---------- Init Regex --------
339 use vars qw/ $regclean1 $regclean2 $regdate /;
340 $regclean1=qr/<(recnb|\/td)>/i;
341 $regclean2=qr/<\/?[^<>]+>/i;
342 $regdate=qr/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;
343
344 # ---------- Init Tie::hash arrays --------
345 # Didn't find a tie that increase speed
346 #use Tie::StdHash;
347 #use Tie::Cache::LRU;
348 #tie %_host_p, 'Tie::StdHash';
349 #tie %TmpOS, 'Tie::Cache::LRU';
350
351 # PROTOCOL CODES
352 use vars qw/ %httpcodelib %ftpcodelib %smtpcodelib /;
353
354 # DEFAULT MESSAGE
355 use vars qw/ @Message /;
356 @Message=(
357 'Unknown',
358 rizwank 1.1 'Unknown (unresolved ip)',
359 'Others',
360 'View details',
361 'Day',
362 'Month',
363 'Year',
364 'Statistics for',
365 'First visit',
366 'Last visit',
367 'Number of visits',
368 'Unique visitors',
369 'Visit',
370 'different keywords',
371 'Search',
372 'Percent',
373 'Traffic',
374 'Domains/Countries',
375 'Visitors',
376 'Pages-URL',
377 'Hours',
378 'Browsers',
379 rizwank 1.1 '',
380 'Referers',
381 'Never updated (See \'Build/Update\' on awstats_setup.html page)',
382 'Visitors domains/countries',
383 'hosts',
384 'pages',
385 'different pages-url',
386 'Viewed',
387 'Other words',
388 'Pages not found',
389 'HTTP Error codes',
390 'Netscape versions',
391 'IE versions',
392 'Last Update',
393 'Connect to site from',
394 'Origin',
395 'Direct address / Bookmarks',
396 'Origin unknown',
397 'Links from an Internet Search Engine',
398 'Links from an external page (other web sites except search engines)',
399 'Links from an internal page (other page on same site)',
400 rizwank 1.1 'Keyphrases used on search engines',
401 'Keywords used on search engines',
402 'Unresolved IP Address',
403 'Unknown OS (Referer field)',
404 'Required but not found URLs (HTTP code 404)',
405 'IP Address',
406 'Error Hits',
407 'Unknown browsers (Referer field)',
408 'different robots',
409 'visits/visitor',
410 'Robots/Spiders visitors',
411 'Free realtime logfile analyzer for advanced web statistics',
412 'of',
413 'Pages',
414 'Hits',
415 'Versions',
416 'Operating Systems',
417 'Jan',
418 'Feb',
419 'Mar',
420 'Apr',
421 rizwank 1.1 'May',
422 'Jun',
423 'Jul',
424 'Aug',
425 'Sep',
426 'Oct',
427 'Nov',
428 'Dec',
429 'Navigation',
430 'File type',
431 'Update now',
432 'Bandwidth',
433 'Back to main page',
434 'Top',
435 'dd mmm yyyy - HH:MM',
436 'Filter',
437 'Full list',
438 'Hosts',
439 'Known',
440 'Robots',
441 'Sun',
442 rizwank 1.1 'Mon',
443 'Tue',
444 'Wed',
445 'Thu',
446 'Fri',
447 'Sat',
448 'Days of week',
449 'Who',
450 'When',
451 'Authenticated users',
452 'Min',
453 'Average',
454 'Max',
455 'Web compression',
456 'Bandwidth saved',
457 'Compression on',
458 'Compression result',
459 'Total',
460 'different keyphrases',
461 'Entry',
462 'Code',
463 rizwank 1.1 'Average size',
464 'Links from a NewsGroup',
465 'KB',
466 'MB',
467 'GB',
468 'Grabber',
469 'Yes',
470 'No',
471 'Info.',
472 'OK',
473 'Exit',
474 'Visits duration',
475 'Close window',
476 'Bytes',
477 'Search Keyphrases',
478 'Search Keywords',
479 'different refering search engines',
480 'different refering sites',
481 'Other phrases',
482 'Other logins (and/or anonymous users)',
483 'Refering search engines',
484 rizwank 1.1 'Refering sites',
485 'Summary',
486 'Exact value not available in "Year" view',
487 'Data value arrays',
488 'Sender EMail',
489 'Receiver EMail',
490 'Reported period',
491 'Extra/Marketing',
492 'Screen sizes',
493 'Worm/Virus attacks',
494 'Add to favorites (estimated)',
495 'Days of month',
496 'Miscellaneous',
497 'Browsers with Java support',
498 'Browsers with Macromedia Director Support',
499 'Browsers with Flash Support',
500 'Browsers with Real audio playing support',
501 'Browsers with Quictime audio playing support',
502 'Browsers with Windows Media audio playing support',
503 'Browsers with PDF support',
504 'SMTP Error codes',
505 rizwank 1.1 'Countries',
506 'Mails',
507 'Size',
508 'First',
509 'Last',
510 'Exclude filter',
511 'Codes shown here gave hits or traffic "not viewed" by visitors, so they are not included in other charts.',
512 'Cluster',
513 'Robots shown here gave hits or traffic "not viewed" by visitors, so they are not included in other charts.',
514 'Numbers after + are successful hits on "robots.txt" files',
515 'Worms shown here gave hits or traffic "not viewed" by visitors, so thay are not included in other charts.',
516 'Not viewed traffic includes traffic generated by robots, worms, or replies with special HTTP status codes.',
517 'Traffic viewed',
518 'Traffic not viewed',
519 'Monthly history',
520 'Worms',
521 'different worms',
522 'Mails successfully sent',
523 'Mails failed/refused',
524 'Sensitive targets',
525 'Javascript disabled',
526 rizwank 1.1 'Created by',
527 'plugins'
528 );
529
530
531
532 #------------------------------------------------------------------------------
533 # Functions
534 #------------------------------------------------------------------------------
535
536 #------------------------------------------------------------------------------
537 # Function: Write on ouput header of HTTP answer
538 # Parameters: None
539 # Input: $HeaderHTTPSent $BuildReportFormat $PageCode $Expires
540 # Output: $HeaderHTTPSent=1
541 # Return: None
542 #------------------------------------------------------------------------------
543 sub http_head {
544 if (! $HeaderHTTPSent) {
545 if ($BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml') { print ($ENV{'HTTP_USER_AGENT'}=~/MSIE|Googlebot/i?"Content-type: text/html; charset=$PageCode\n":"Content-type: text/xml; charset=$PageCode\n"); }
546 else { print "Content-type: text/html; charset=$PageCode\n"; }
547 rizwank 1.1
548 # Expires must be GMT ANSI asctime and must be after Content-type to avoid pb with some servers (SAMBAR)
549 if ($Expires =~ /^\d+$/) {
550 print "Cache-Control: public\n";
551 print "Last-Modified: ".gmtime($starttime)."\n";
552 print "Expires: ".(gmtime($starttime+$Expires))."\n";
553 }
554 print "\n";
555 }
556 $HeaderHTTPSent++;;
557 }
558
559 #------------------------------------------------------------------------------
560 # Function: Write on ouput header of HTML page
561 # Parameters: None
562 # Input: %HTMLOutput $PluginMode $Expires $Lang $StyleSheet $HTMLHeadSection $PageCode $PageDir
563 # Output: $HeaderHTMLSent=1
564 # Return: None
565 #------------------------------------------------------------------------------
566 sub html_head {
567 my $dir=$PageDir?'right':'left';
568 rizwank 1.1 if (scalar keys %HTMLOutput || $PluginMode) {
569 my $MetaRobot=0; # meta robots
570 my $periodtitle=" ($YearRequired".($MonthRequired ne 'all'?"-$MonthRequired":"").")";
571 # Write head section
572 if ($BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml') {
573 if ($PageCode) { print "<?xml version=\"1.0\" encoding=\"$PageCode\"?>\n"; }
574 else { print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"; };
575 if ($FrameName ne 'index') { print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; }
576 else { print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n"; }
577 print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$Lang\">\n";
578 } else {
579 if ($FrameName ne 'index') { print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n\n"; }
580 else { print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\">\n\n"; }
581 print "<html lang='$Lang'".($PageDir?" dir='rtl'":"").">\n";
582 }
583 print "<head>\n";
584
585 print "<meta name=\"generator\" content=\"AWStats $VERSION from config file awstats.$SiteConfig.conf (http://awstats.sourceforge.net)\" />\n";
586
587 if ($MetaRobot) { print "<meta name=\"robots\" content=\"".($FrameName eq 'mainleft'?'no':'')."index,nofollow\" />\n"; }
588 else { print "<meta name=\"robots\" content=\"noindex,nofollow\" />\n"; }
589 rizwank 1.1
590 # Affiche tag meta content-type
591 if ($BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml') { print ($ENV{'HTTP_USER_AGENT'}=~/MSIE|Googlebot/i?"<meta http-equiv=\"content-type\" content=\"text/html; charset=".($PageCode?$PageCode:"iso-8859-1")."\" />\n":"<meta http-equiv=\"content-type\" content=\"text/xml; charset=".($PageCode?$PageCode:"iso-8859-1")."\" />\n"); }
592 else { print "<meta http-equiv=\"content-type\" content=\"text/html; charset=".($PageCode?$PageCode:"iso-8859-1")."\" />\n"; }
593
594 if ($Expires) { print "<meta http-equiv=\"expires\" content=\"".(gmtime($starttime+$Expires))."\" />\n"; }
595 print "<meta http-equiv=\"description\" content=\"".ucfirst($PROG)." - Advanced Web Statistics for $SiteDomain$periodtitle\" />\n";
596 if ($MetaRobot && $FrameName ne 'mainleft') { print "<meta http-equiv=\"keywords\" content=\"$SiteDomain, free, advanced, realtime, web, server, logfile, log, analyzer, analysis, statistics, stats, perl, analyse, performance, hits, visits\" />\n"; }
597 print "<title>$Message[7] $SiteDomain$periodtitle</title>\n";
598 if ($FrameName ne 'index') {
599
600 # A STYLE section must be in head section. Do not use " for number in a style section
601 print "<style type=\"text/css\">\n";
602 if ($BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml') { print ($ENV{'HTTP_USER_AGENT'}=~/Firebird/i?"<!--\n":"<![CDATA[\n"); }
603 else { print "<!--\n"; }
604 print "body { font: 11px verdana, arial, helvetica, sans-serif; background-color: #$color_Background; margin-top: 0; margin-bottom: 0; }\n";
605 print ".aws_bodyl { }\n";
606 print ".aws_border { background-color: #$color_TableBG; padding: 1px 1px ".($BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml'?"2px":"1px")." 1px; margin-top: 0; margin-bottom: 0; }\n";
607 print ".aws_title { font: 13px verdana, arial, helvetica, sans-serif; font-weight: bold; background-color: #$color_TableBGTitle; text-align: center; margin-top: 0; margin-bottom: 0; padding: 1px 1px 1px 1px; color: #$color_TableTitle; }\n";
608 print ".aws_blank { font: 13px verdana, arial, helvetica, sans-serif; background-color: #".($ENV{'HTTP_USER_AGENT'} && $ENV{'HTTP_USER_AGENT'}=~/MSIE/i?$color_Background:$color_TableBG)."; text-align: center; margin-bottom: 0; padding: 1px 1px 1px 1px; }\n";
609 print <<EOF;
610 rizwank 1.1 .aws_data {
611 background-color: #$color_Background;
612 border-top-width: 1px;
613 border-left-width: 0px;
614 border-right-width: 0px;
615 border-bottom-width: 0px;
616 }
617 .aws_formfield { font: 13px verdana, arial, helvetica; }
618 .aws_button {
619 font-family: arial,verdana,helvetica, sans-serif;
620 font-size: 12px;
621 border: 1px solid #ccd7e0;
622 background-image : url($DirIcons/other/button.gif);
623 }
624 th { border-color: #$color_TableBorder; border-left-width: 0px; border-right-width: 1px; border-top-width: 0px; border-bottom-width: 1px; padding: 1px 2px 1px 1px; font: 11px verdana, arial, helvetica, sans-serif; text-align:center; color: #$color_titletext; }
625 th.aws { border-color: #$color_TableBorder; border-left-width: 0px; border-right-width: 1px; border-top-width: 0px; border-bottom-width: 1px; padding: 1px 2px 1px 1px; font-size: 13px; font-weight: bold; }
626 td { border-color: #$color_TableBorder; border-left-width: 0px; border-right-width: 1px; border-top-width: 0px; border-bottom-width: 1px; font: 11px verdana, arial, helvetica, sans-serif; text-align:center; color: #$color_text; }
627 td.aws { border-color: #$color_TableBorder; border-left-width: 0px; border-right-width: 1px; border-top-width: 0px; border-bottom-width: 1px; font: 11px verdana, arial, helvetica, sans-serif; text-align:$dir; color: #$color_text; padding: 0px;}
628 td.awsm { border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; font: 11px verdana, arial, helvetica, sans-serif; text-align:$dir; color: #$color_text; padding: 0px; }
629 b { font-weight: bold; }
630 a { font: 11px verdana, arial, helvetica, sans-serif; }
631 rizwank 1.1 a:link { color: #$color_link; text-decoration: none; }
632 a:visited { color: #$color_link; text-decoration: none; }
633 a:hover { color: #$color_hover; text-decoration: underline; }
634 .currentday { font-weight: bold; }
635 EOF
636 # Call to plugins' function AddHTMLStyles
637 foreach my $pluginname (keys %{$PluginsLoaded{'AddHTMLStyles'}}) {
638 my $function="AddHTMLStyles_$pluginname()";
639 eval("$function");
640 }
641
642 if ($BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml') { print ($ENV{'HTTP_USER_AGENT'}=~/Firebird/i?"//-->\n":"]]>\n"); }
643 else { print "//-->\n"; }
644 print "</style>\n";
645
646 if ($StyleSheet) {
647 print "<link rel=\"stylesheet\" href=\"$StyleSheet\" />\n";
648 }
649 }
650 print "</head>\n\n";
651 if ($FrameName ne 'index') {
652 rizwank 1.1 print "<body style=\"margin-top: 0px\"";
653 if ($FrameName eq 'mainleft') { print " class=\"aws_bodyl\""; }
654 print ">\n";
655 }
656 }
657 $HeaderHTMLSent++;
658 }
659
660 #------------------------------------------------------------------------------
661 # Function: Write on ouput end of HTML page
662 # Parameters: 0|1 (0=no list plugins,1=list plugins)
663 # Input: %HTMLOutput $HTMLEndSection $FrameName $BuildReportFormat
664 # Output: None
665 # Return: None
666 #------------------------------------------------------------------------------
667 sub html_end {
668 my $listplugins=shift||0;
669 if (scalar keys %HTMLOutput) {
670
671 # Call to plugins' function AddHTMLBodyFooter
672 foreach my $pluginname (keys %{$PluginsLoaded{'AddHTMLBodyFooter'}}) {
673 rizwank 1.1 my $function="AddHTMLBodyFooter_$pluginname()";
674 eval("$function");
675 }
676
677 if ($FrameName ne 'index' && $FrameName ne 'mainleft') {
678 print "$Center<br /><br />\n";
679 print "<span dir=\"ltr\" style=\"font: 11px verdana, arial, helvetica; color: #$color_text;\">";
680 print "<b>Advanced Web Statistics $VERSION</b> - <a href=\"http://awstats.sourceforge.net\" target=\"awstatshome\">";
681 print $Message[169]." $PROG";
682 if ($listplugins) {
683 my $atleastoneplugin=0;
684 foreach my $pluginname (keys %{$PluginsLoaded{'init'}}) {
685 if (! $atleastoneplugin) { $atleastoneplugin=1; print " ($Message[170]: "; }
686 else { print ", "; }
687 print "$pluginname";
688 }
689 if ($atleastoneplugin) { print ")"; }
690 }
691 print "</a></span><br />\n";
692 if ($HTMLEndSection) { print "<br />\n$HTMLEndSection\n"; }
693 }
694 rizwank 1.1 print "\n";
695 if ($FrameName ne 'index') {
696 if ($FrameName ne 'mainleft' && $BuildReportFormat eq 'html') { print "<br />\n"; }
697 print "</body>\n";
698 }
699 print "</html>\n";
700 # print "<!-- NEW PAGE --><!-- NEW SHEET -->\n";
701 }
702 }
703
704 #------------------------------------------------------------------------------
705 # Function: Print on stdout tab header of a chart
706 # Parameters: $title $tooltipnb [$width percentage of chart title]
707 # Input: None
708 # Output: None
709 # Return: None
710 #------------------------------------------------------------------------------
711 sub tab_head {
712 my $title=shift;
713 my $tooltipnb=shift;
714 my $width=shift||70;
715 rizwank 1.1 my $class=shift;
716 if ($width == 70 && $QueryString =~ /buildpdf/i) { print "<table class=\"aws_border\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"800\">\n"; }
717 else { print "<table class=\"aws_border\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n"; }
718
719 if ($tooltipnb) {
720 print "<tr><td class=\"aws_title\" width=\"$width%\"".Tooltip($tooltipnb,$tooltipnb).">$title </td>";
721 }
722 else {
723 print "<tr><td class=\"aws_title\" width=\"$width%\">$title </td>";
724 }
725 print "<td class=\"aws_blank\"> </td></tr>\n";
726 print "<tr><td colspan=\"2\">\n";
727 if ($width == 70 && $QueryString =~ /buildpdf/i) { print "<table class=\"aws_data\" border=\"1\" bordercolor=\"#$color_TableBorder\" cellpadding=\"2\" cellspacing=\"0\" width=\"796\">\n"; }
728 else { print "<table class=\"aws_data\" border=\"1\" bordercolor=\"#$color_TableBorder\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n"; }
729 }
730
731 #------------------------------------------------------------------------------
732 # Function: Print on stdout tab ender of a chart
733 # Parameters: None
734 # Input: None
735 # Output: None
736 rizwank 1.1 # Return: None
737 #------------------------------------------------------------------------------
738 sub tab_end {
739 my $string=shift;
740 print "</table></td></tr></table>";
741 if ($string) { print "<span style=\"font: 11px verdana, arial, helvetica;\">$string</span><br />\n"; }
742 print "<br />\n\n";
743 }
744
745 #------------------------------------------------------------------------------
746 # Function: Write error message and exit
747 # Parameters: $message $secondmessage $thirdmessage $donotshowsetupinfo
748 # Input: $HeaderHTTPSent $HeaderHTMLSent %HTMLOutput $LogSeparator $LogFormat
749 # Output: None
750 # Return: None
751 #------------------------------------------------------------------------------
752 sub error {
753 my $message=shift||''; if (scalar keys %HTMLOutput) { $message =~ s/\</</g; $message =~ s/\>/>/g; }
754 my $secondmessage=shift||'';
755 my $thirdmessage=shift||'';
756 my $donotshowsetupinfo=shift||0;
757 rizwank 1.1
758 if (! $HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'}) { http_head(); }
759 if (! $HeaderHTMLSent && scalar keys %HTMLOutput) { print "<html><body>\n"; $HeaderHTMLSent=1; }
760 if ($Debug) { debug("$message $secondmessage $thirdmessage",1); }
761 my $tagbold=''; my $tagunbold=''; my $tagbr=''; my $tagfontred=''; my $tagfontgrey=''; my $tagunfont='';
762 if (scalar keys %HTMLOutput) {
763 $tagbold='<b>'; $tagunbold='</b>'; $tagbr='<br />';
764 $tagfontred='<span style="color: #880000">';
765 $tagfontgrey='<span style="color: #888888">';
766 $tagunfont='</span>';
767 }
768 if (! $ErrorMessages && $message =~ /^Format error$/i) {
769 # Files seems to have bad format
770 if (scalar keys %HTMLOutput) { print "<br /><br />\n"; }
771 if ($message !~ $LogSeparator) {
772 # Bad LogSeparator parameter
773 print "${tagfontred}AWStats did not found the ${tagbold}LogSeparator${tagunbold} in your log records.${tagbr}${tagunfont}\n";
774 }
775 else {
776 # Bad LogFormat parameter
777 print "AWStats did not find any valid log lines that match your ${tagbold}LogFormat${tagunbold} parameter, in the ${NbOfLinesForCorruptedLog}th first non commented lines read of your log.${tagbr}\n";
778 rizwank 1.1 print "${tagfontred}Your log file ${tagbold}$thirdmessage${tagunbold} must have a bad format or ${tagbold}LogFormat${tagunbold} parameter setup does not match this format.${tagbr}${tagbr}${tagunfont}\n";
779 print "Your AWStats ${tagbold}LogFormat${tagunbold} parameter is:\n";
780 print "${tagbold}$LogFormat${tagunbold}${tagbr}\n";
781 print "This means each line in your web server log file need to have ";
782 if ($LogFormat == 1) {
783 print "${tagbold}\"combined log format\"${tagunbold} like this:${tagbr}\n";
784 print (scalar keys %HTMLOutput?"$tagfontgrey<i>":"");
785 print "111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] \"GET / HTTP/1.1\" 200 1234 \"http://www.fromserver.com/from.htm\" \"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)\"\n";
786 print (scalar keys %HTMLOutput?"</i>$tagunfont${tagbr}${tagbr}\n":"");
787 }
788 if ($LogFormat == 2) {
789 print "${tagbold}\"MSIE Extended W3C log format\"${tagunbold} like this:${tagbr}\n";
790 print (scalar keys %HTMLOutput?"$tagfontgrey<i>":"");
791 print "date time c-ip c-username cs-method cs-uri-sterm sc-status sc-bytes cs-version cs(User-Agent) cs(Referer)\n";
792 print (scalar keys %HTMLOutput?"</i>$tagunfont${tagbr}${tagbr}\n":"");
793 }
794 if ($LogFormat == 3) {
795 print "${tagbold}\"WebStar native log format\"${tagunbold}${tagbr}\n";
796 }
797 if ($LogFormat == 4) {
798 print "${tagbold}\"common log format\"${tagunbold} like this:${tagbr}\n";
799 rizwank 1.1 print (scalar keys %HTMLOutput?"$tagfontgrey<i>":"");
800 print "111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] \"GET / HTTP/1.1\" 200 1234\n";
801 print (scalar keys %HTMLOutput?"</i>$tagunfont${tagbr}${tagbr}\n":"");
802 }
803 if ($LogFormat == 5) {
804 print "${tagbold}\"ISA native log format\"${tagunbold}${tagbr}\n";
805 }
806 if ($LogFormat == 6) {
807 print "${tagbold}\"Lotus Notes/Lotus Domino\"${tagunbold}${tagbr}\n";
808 print (scalar keys %HTMLOutput?"$tagfontgrey<i>":"");
809 print "111.22.33.44 - Firstname Middlename Lastname [10/Jan/2001:02:14:14 +0200] \"GET / HTTP/1.1\" 200 1234 \"http://www.fromserver.com/from.htm\" \"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)\"\n";
810 print (scalar keys %HTMLOutput?"</i></span>${tagbr}${tagbr}\n":"");
811 }
812 if ($LogFormat !~ /^[1-6]$/) {
813 print "the following personalized log format:${tagbr}\n";
814 print (scalar keys %HTMLOutput?"$tagfontgrey<i>":"");
815 print "$LogFormat\n";
816 print (scalar keys %HTMLOutput?"</i>$tagunfont${tagbr}${tagbr}\n":"");
817 }
818 print "And this is an example of records AWStats found in your log file (the record number $NbOfLinesForCorruptedLog in your log):\n";
819 print (scalar keys %HTMLOutput?"<br />$tagfontgrey<i>":"");
820 rizwank 1.1 print "$secondmessage";
821 print (scalar keys %HTMLOutput?"</i>$tagunfont${tagbr}${tagbr}":"");
822 print "\n";
823 }
824 #print "Note: If your $NbOfLinesForCorruptedLog first lines in your log files are wrong because of ";
825 #print "a worm virus attack, you can increase the NbOfLinesForCorruptedLog parameter in config file.\n";
826 #print "\n";
827 }
828 else {
829 print (scalar keys %HTMLOutput?"<br />$tagfontred\n":"");
830 print ($ErrorMessages?"$ErrorMessages":"Error: $message");
831 print (scalar keys %HTMLOutput?"\n</span><br />":"");
832 print "\n";
833 }
834 if (! $ErrorMessages && ! $donotshowsetupinfo) {
835 if ($message =~ /Couldn.t open config file/i) {
836 my $dir=$DIR;
837 if ($dir =~ /^\./) { $dir.='/../..'; }
838 else { $dir =~ s/[\\\/]?wwwroot[\/\\]cgi-bin[\\\/]?//; }
839 print "${tagbr}\n";
840 if ($ENV{'GATEWAY_INTERFACE'}) {
841 rizwank 1.1 print "- ${tagbold}Did you use the correct URL ?${tagunbold}${tagbr}\n";
842 print "Example: http://localhost/awstats/awstats.pl?config=mysite${tagbr}\n";
843 print "Example: http://127.0.0.1/cgi-bin/awstats.pl?config=mysite${tagbr}\n";
844 } else {
845 print "- ${tagbold}Did you use correct config parameter ?${tagunbold}${tagbr}\n";
846 print "Example: If your config file is awstats.mysite.conf, use -config=mysite\n";
847 }
848 print "- ${tagbold}Did you create your config file 'awstats.$SiteConfig.conf' ?${tagunbold}${tagbr}\n";
849 print "If not, you can run \"$dir/tools/awstats_configure.pl\"\nfrom command line, or create it manually.${tagbr}\n";
850 print "${tagbr}\n";
851 }
852 else { print "${tagbr}${tagbold}Setup (".($FileConfig?"'".$FileConfig."'":"Config")." file, web server or permissions) may be wrong.${tagunbold}${tagbr}\n"; }
853 print "Check config file, permissions and AWStats documentation (in 'docs' directory).\n";
854 }
855 # Remove lock if not a lock message
856 if ($EnableLockForUpdate && $message !~ /lock file/) { &Lock_Update(0); }
857 if (scalar keys %HTMLOutput) { print "</body></html>\n"; }
858 exit 1;
859 }
860
861 #------------------------------------------------------------------------------
862 rizwank 1.1 # Function: Write a warning message
863 # Parameters: $message
864 # Input: $HeaderHTTPSent $HeaderHTMLSent $WarningMessage %HTMLOutput
865 # Output: None
866 # Return: None
867 #------------------------------------------------------------------------------
868 sub warning {
869 my $messagestring=shift;
870
871 if (! $HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'}) { http_head(); }
872 if (! $HeaderHTMLSent) { html_head(); }
873 if ($Debug) { debug("$messagestring",1); }
874 if ($WarningMessages) {
875 if (scalar keys %HTMLOutput) {
876 $messagestring =~ s/\n/\<br\>/g;
877 print "$messagestring<br />\n";
878 }
879 else {
880 print "$messagestring\n";
881 }
882 }
883 rizwank 1.1 }
884
885 #------------------------------------------------------------------------------
886 # Function: Write debug message and exit
887 # Parameters: $string $level
888 # Input: %HTMLOutput $Debug=required level $DEBUGFORCED=required level forced
889 # Output: None
890 # Return: None
891 #------------------------------------------------------------------------------
892 sub debug {
893 my $level = $_[1] || 1;
894
895 if (! $HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'}) { http_head(); } # To send the HTTP header and see debug
896 if ($level <= $DEBUGFORCED) {
897 my $debugstring = $_[0];
898 if (! $DebugResetDone) { open(DEBUGFORCEDFILE,"debug.log"); close DEBUGFORCEDFILE; chmod 0666,"debug.log"; $DebugResetDone=1; }
899 open(DEBUGFORCEDFILE,">>debug.log");
900 print DEBUGFORCEDFILE localtime(time)." - $$ - DEBUG $level - $debugstring\n";
901 close DEBUGFORCEDFILE;
902 }
903 if ($DebugMessages && $level <= $Debug) {
904 rizwank 1.1 my $debugstring = $_[0];
905 if (scalar keys %HTMLOutput) { $debugstring =~ s/^ / /; $debugstring .= "<br />"; }
906 print localtime(time)." - DEBUG $level - $debugstring\n";
907 }
908 }
909
910 #------------------------------------------------------------------------------
911 # Function: Optimize an array removing duplicate entries
912 # Parameters: @Array notcasesensitive=0|1
913 # Input: None
914 # Output: None
915 # Return: None
916 #------------------------------------------------------------------------------
917 sub OptimizeArray {
918 my $array=shift;
919 my @arrayunreg=map{if (/\(\?[-\w]*:(.*)\)/) { $1 } } @$array;
920 my $notcasesensitive=shift;
921 my $searchlist=0;
922 if ($Debug) { debug("OptimizeArray (notcasesensitive=$notcasesensitive)",4); }
923 while ($searchlist>-1 && @arrayunreg) {
924 my $elemtoremove=-1;
925 rizwank 1.1 OPTIMIZELOOP:
926 foreach my $i ($searchlist..(scalar @arrayunreg)-1) {
927 # Search if $i elem is already treated by another elem
928 foreach my $j (0..(scalar @arrayunreg)-1) {
929 if ($i == $j) { next; }
930 my $parami=$notcasesensitive?lc($arrayunreg[$i]):$arrayunreg[$i];
931 my $paramj=$notcasesensitive?lc($arrayunreg[$j]):$arrayunreg[$j];
932 if ($Debug) { debug(" Compare $i ($parami) to $j ($paramj)",4); }
933 if (index($parami,$paramj)>-1) {
934 if ($Debug) { debug(" Elem $i ($arrayunreg[$i]) already treated with elem $j ($arrayunreg[$j])",4); }
935 $elemtoremove=$i;
936 last OPTIMIZELOOP;
937 }
938 }
939 }
940 if ($elemtoremove > -1) {
941 if ($Debug) { debug(" Remove elem $elemtoremove - $arrayunreg[$elemtoremove]",4); }
942 splice @arrayunreg, $elemtoremove, 1;
943 $searchlist=$elemtoremove;
944 }
945 else {
946 rizwank 1.1 $searchlist=-1;
947 }
948 }
949 if ($notcasesensitive) { return map{qr/$_/i} @arrayunreg; }
950 return map{qr/$_/} @arrayunreg;
951 }
952
953 #------------------------------------------------------------------------------
954 # Function: Check if parameter is in SkipDNSLookupFor array
955 # Parameters: ip @SkipDNSLookupFor (a NOT case sensitive precompiled regex array)
956 # Return: 0 Not found, 1 Found
957 #------------------------------------------------------------------------------
958 sub SkipDNSLookup {
959 foreach (@SkipDNSLookupFor) { if ($_[0] =~ /$_/) { return 1; } }
960 0; # Not in @SkipDNSLookupFor
961 }
962
963 #------------------------------------------------------------------------------
964 # Function: Check if parameter is in SkipHosts array
965 # Parameters: host @SkipHosts (a NOT case sensitive precompiled regex array)
966 # Return: 0 Not found, 1 Found
967 rizwank 1.1 #------------------------------------------------------------------------------
968 sub SkipHost {
969 foreach (@SkipHosts) { if ($_[0] =~ /$_/) { return 1; } }
970 0; # Not in @SkipHosts
971 }
972
973 #------------------------------------------------------------------------------
974 # Function: Check if parameter is in SkipUserAgents array
975 # Parameters: useragent @SkipUserAgents (a NOT case sensitive precompiled regex array)
976 # Return: 0 Not found, 1 Found
977 #------------------------------------------------------------------------------
978 sub SkipUserAgent {
979 foreach (@SkipUserAgents) { if ($_[0] =~ /$_/) { return 1; } }
980 0; # Not in @SkipUserAgent
981 }
982
983 #------------------------------------------------------------------------------
984 # Function: Check if parameter is in SkipFiles array
985 # Parameters: url @SkipFiles (a NOT case sensitive precompiled regex array)
986 # Return: 0 Not found, 1 Found
987 #------------------------------------------------------------------------------
988 rizwank 1.1 sub SkipFile {
989 foreach (@SkipFiles) { if ($_[0] =~ /$_/) { return 1; } }
990 0; # Not in @SkipFiles
991 }
992
993 #------------------------------------------------------------------------------
994 # Function: Check if parameter is in OnlyHosts array
995 # Parameters: host @OnlyHosts (a NOT case sensitive precompiled regex array)
996 # Return: 0 Not found, 1 Found
997 #------------------------------------------------------------------------------
998 sub OnlyHost {
999 foreach (@OnlyHosts) { if ($_[0] =~ /$_/) { return 1; } }
1000 0; # Not in @OnlyHosts
1001 }
1002
1003 #------------------------------------------------------------------------------
1004 # Function: Check if parameter is in OnlyUserAgents array
1005 # Parameters: useragent @OnlyUserAgents (a NOT case sensitive precompiled regex array)
1006 # Return: 0 Not found, 1 Found
1007 #------------------------------------------------------------------------------
1008 sub OnlyUserAgent {
1009 rizwank 1.1 foreach (@OnlyUserAgents) { if ($_[0] =~ /$_/) { return 1; } }
1010 0; # Not in @OnlyHosts
1011 }
1012
1013 #------------------------------------------------------------------------------
1014 # Function: Check if parameter is in OnlyFiles array
1015 # Parameters: url @OnlyFiles (a NOT case sensitive precompiled regex array)
1016 # Return: 0 Not found, 1 Found
1017 #------------------------------------------------------------------------------
1018 sub OnlyFile {
1019 foreach (@OnlyFiles) { if ($_[0] =~ /$_/) { return 1; } }
1020 0; # Not in @OnlyFiles
1021 }
1022
1023 #------------------------------------------------------------------------------
1024 # Function: Return day of week of a day
1025 # Parameters: $day $month $year
1026 # Return: 0-6
1027 #------------------------------------------------------------------------------
1028 sub DayOfWeek {
1029 my ($day, $month, $year) = @_;
1030 rizwank 1.1 if ($Debug) { debug("DayOfWeek for $day $month $year",4); }
1031 if ($month < 3) { $month += 10; $year--; }
1032 else { $month -= 2; }
1033 my $cent = sprintf("%1i",($year/100));
1034 my $y = ($year % 100);
1035 my $dw = (sprintf("%1i",(2.6*$month)-0.2) + $day + $y + sprintf("%1i",($y/4)) + sprintf("%1i",($cent/4)) - (2*$cent)) % 7;
1036 $dw += 7 if ($dw<0);
1037 if ($Debug) { debug(" is $dw",4); }
1038 return $dw;
1039 }
1040
1041 #------------------------------------------------------------------------------
1042 # Function: Return 1 if a date exists
1043 # Parameters: $day $month $year
1044 # Return: 1 if date exists else 0
1045 #------------------------------------------------------------------------------
1046 sub DateIsValid {
1047 my ($day, $month, $year) = @_;
1048 if ($Debug) { debug("DateIsValid for $day $month $year",4); }
1049 if ($day < 1) { return 0; }
1050 if ($day > 31) { return 0; }
1051 rizwank 1.1 if ($month==4 || $month==6 || $month==9 || $month==11) {
1052 if ($day > 30) { return 0; }
1053 }
1054 elsif ($month==2) {
1055 my $leapyear=($year%4==0?1:0); # A leap year every 4 years
1056 if ($year%100==0 && $year%400!=0) { $leapyear=0; } # Except if year is 100x and not 400x
1057 if ($day > (28+$leapyear)) { return 0; }
1058 }
1059 return 1;
1060 }
1061
1062 #------------------------------------------------------------------------------
1063 # Function: Return string of visit duration
1064 # Parameters: $starttime $endtime
1065 # Input: None
1066 # Output: None
1067 # Return: A string that identify the visit duration range
1068 #------------------------------------------------------------------------------
1069 sub GetSessionRange {
1070 my $starttime = my $endtime;
1071 if (shift =~ /$regdate/o) { $starttime = Time::Local::timelocal($6,$5,$4,$3,$2-1,$1); }
1072 rizwank 1.1 if (shift =~ /$regdate/o) { $endtime = Time::Local::timelocal($6,$5,$4,$3,$2-1,$1); }
1073 my $delay=$endtime-$starttime;
1074 if ($Debug) { debug("GetSessionRange $endtime - $starttime = $delay",4); }
1075 if ($delay <= 30) { return $SessionsRange[0]; }
1076 if ($delay <= 120) { return $SessionsRange[1]; }
1077 if ($delay <= 300) { return $SessionsRange[2]; }
1078 if ($delay <= 900) { return $SessionsRange[3]; }
1079 if ($delay <= 1800) { return $SessionsRange[4]; }
1080 if ($delay <= 3600) { return $SessionsRange[5]; }
1081 return $SessionsRange[6];
1082 }
1083
1084 #------------------------------------------------------------------------------
1085 # Function: Read config file
1086 # Parameters: None or configdir to scan
1087 # Input: $DIR $PROG $SiteConfig
1088 # Output: Global variables
1089 # Return: -
1090 #------------------------------------------------------------------------------
1091 sub Read_Config {
1092 # Check config file in common possible directories :
1093 rizwank 1.1 # Windows : "$DIR" (same dir than awstats.pl)
1094 # Standard, Mandrake and Debian package : "/etc/awstats"
1095 # Other possible directories : "/usr/local/etc/awstats", "/etc"
1096 # FHS standard, Suse package : "/etc/opt/awstats"
1097 my $configdir=shift;
1098 my @PossibleConfigDir=();
1099
1100 if ($configdir) { @PossibleConfigDir=("$configdir"); }
1101 else { @PossibleConfigDir=("$DIR","/etc/awstats","/usr/local/etc/awstats","/etc","/etc/opt/awstats"); }
1102
1103 # Open config file
1104 $FileConfig=$FileSuffix='';
1105 foreach (@PossibleConfigDir) {
1106 my $searchdir=$_;
1107 if ($searchdir && $searchdir !~ /[\\\/]$/) { $searchdir .= "/"; }
1108 if (open(CONFIG,"$searchdir$PROG.$SiteConfig.conf")) { $FileConfig="$searchdir$PROG.$SiteConfig.conf"; $FileSuffix=".$SiteConfig"; last; }
1109 if (open(CONFIG,"$searchdir$PROG.conf")) { $FileConfig="$searchdir$PROG.conf"; $FileSuffix=''; last; }
1110 }
1111 if (! $FileConfig) { error("Couldn't open config file \"$PROG.$SiteConfig.conf\" nor \"$PROG.conf\" after searching in path \"".join(',',@PossibleConfigDir)."\": $!"); }
1112
1113 # Analyze config file content and close it
1114 rizwank 1.1 &Parse_Config( *CONFIG , 1 , $FileConfig);
1115 close CONFIG;
1116
1117 # If parameter NotPageList not found, init for backward compatibility
1118 if (! $FoundNotPageList) {
1119 %NotPageList=('css'=>1,'js'=>1,'class'=>1,'gif'=>1,'jpg'=>1,'jpeg'=>1,'png'=>1,'bmp'=>1,'ico'=>1,'swf'=>1);
1120 }
1121 # If parameter ValidHTTPCodes empty, init for backward compatibility
1122 if (! scalar keys %ValidHTTPCodes) { $ValidHTTPCodes{"200"}=$ValidHTTPCodes{"304"}=1; }
1123 # If parameter ValidSMTPCodes empty, init for backward compatibility
1124 if (! scalar keys %ValidSMTPCodes) { $ValidSMTPCodes{"1"}=$ValidSMTPCodes{"250"}=1; }
1125 }
1126
1127 #------------------------------------------------------------------------------
1128 # Function: Parse content of a config file
1129 # Parameters: opened file handle, depth level, file name
1130 # Input: -
1131 # Output: Global variables
1132 # Return: -
1133 #------------------------------------------------------------------------------
1134 sub Parse_Config {
1135 rizwank 1.1 my ( $confighandle ) = $_[0];
1136 my $level = $_[1];
1137 my $configFile = $_[2];
1138 my $versionnum=0;
1139 my $conflinenb=0;
1140
1141 if ($level > 10) { error("$PROG can't read down more than 10 level of includes. Check that no 'included' config files include their parent config file (this cause infinite loop)."); }
1142
1143 while (<$confighandle>) {
1144 chomp $_; s/\r//;
1145 $conflinenb++;
1146
1147 # Extract version from first line
1148 if (! $versionnum && $_ =~ /^# AWSTATS CONFIGURE FILE (\d+).(\d+)/i) {
1149 $versionnum=($1*1000)+$2;
1150 #if ($Debug) { debug(" Configure file version is $versionnum",1); }
1151 next;
1152 }
1153
1154 if ($_ =~ /^\s*$/) { next; }
1155
1156 rizwank 1.1 # Check includes
1157 if ($_ =~ /^Include "([^\"]+)"/ || $_ =~ /^#include "([^\"]+)"/) { # #include kept for backward compatibility
1158 my $includeFile = $1;
1159 if ($Debug) { debug("Found an include : $includeFile",2); }
1160 if ( $includeFile !~ /^[\\\/]/ ) {
1161 # Correct relative include files
1162 if ($FileConfig =~ /^(.*[\\\/])[^\\\/]*$/) { $includeFile = "$1$includeFile"; }
1163 }
1164 if ($level > 1) {
1165 warning("Warning: Perl versions before 5.6 cannot handle nested includes");
1166 next;
1167 }
1168 if ( open( CONFIG_INCLUDE, $includeFile ) ) {
1169 &Parse_Config( *CONFIG_INCLUDE , $level+1, $includeFile);
1170 close( CONFIG_INCLUDE );
1171 }
1172 else {
1173 error("Could not open include file: $includeFile" );
1174 }
1175 next;
1176 }
1177 rizwank 1.1
1178 # Remove comments
1179 if ($_ =~ /^\s*#/) { next; }
1180 $_ =~ s/\s#.*$//;
1181
1182 # Extract param and value
1183 my ($param,$value)=split(/=/,$_,2);
1184 $param =~ s/^\s+//; $param =~ s/\s+$//;
1185
1186 # If not a param=value, try with next line
1187 if (! $param) { warning("Warning: Syntax error line $conflinenb in file '$configFile'. Config line is ignored."); next; }
1188 if (! defined $value) { warning("Warning: Syntax error line $conflinenb in file '$configFile'. Config line is ignored."); next; }
1189
1190 if ($value) {
1191 $value =~ s/^\s+//; $value =~ s/\s+$//;
1192 $value =~ s/^\"//; $value =~ s/\";?$//;
1193 # Replace __MONENV__ with value of environnement variable MONENV
1194 # Must be able to replace __VAR_1____VAR_2__
1195 while ($value =~ /__([^\s_]+(?:_[^\s_]+)*)__/) { my $var=$1; $value =~ s/__${var}__/$ENV{$var}/g; }
1196 }
1197
1198 rizwank 1.1 # Initialize parameter for (param,value)
1199 if ($param =~ /^LogFile/) {
1200 if ($QueryString !~ /logfile=([^\s&]+)/i) { $LogFile=$value; }
1201 next;
1202 }
1203 if ($param =~ /^DirIcons/) {
1204 if ($QueryString !~ /diricons=([^\s&]+)/i) { $DirIcons=$value; }
1205 next;
1206 }
1207 if ($param =~ /^SiteDomain/) {
1208 # No regex test as SiteDomain is always exact value
1209 $SiteDomain=$value;
1210 next;
1211 }
1212 if ($param =~ /^HostAliases/) {
1213 foreach my $elem (split(/\s+/,$value)) {
1214 if ($elem =~ s/^\@//) { # If list of hostaliases in a file
1215 open(DATAFILE,"<$elem") || error("Failed to open file '$elem' declared in HostAliases parameter");
1216 my @val=map(/^(.*)$/i,<DATAFILE>);
1217 push @HostAliases, map{qr/^$_$/i} @val;
1218 close(DATAFILE);
1219 rizwank 1.1 }
1220 else {
1221 if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
1222 else { $elem='^'.quotemeta($elem).'$'; }
1223 if ($elem) { push @HostAliases, qr/$elem/i; }
1224 }
1225 }
1226 next;
1227 }
1228 # Special optional setup params
1229 if ($param =~ /^SkipDNSLookupFor/) {
1230 foreach my $elem (split(/\s+/,$value)) {
1231 if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
1232 else { $elem='^'.quotemeta($elem).'$'; }
1233 if ($elem) { push @SkipDNSLookupFor, qr/$elem/i; }
1234 }
1235 next;
1236 }
1237 if ($param =~ /^AllowAccessFromWebToFollowingAuthenticatedUsers/) {
1238 foreach (split(/\s+/,$value)) { push @AllowAccessFromWebToFollowingAuthenticatedUsers,$_; }
1239 next;
1240 rizwank 1.1 }
1241 if ($param =~ /^DefaultFile/) {
1242 foreach my $elem (split(/\s+/,$value)) {
1243 # No REGEX for this option
1244 #if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
1245 #else { $elem='^'.quotemeta($elem).'$'; }
1246 if ($elem) { push @DefaultFile,$elem; }
1247 }
1248 next;
1249 }
1250 if ($param =~ /^SkipHosts/) {
1251 foreach my $elem (split(/\s+/,$value)) {
1252 if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
1253 else { $elem='^'.quotemeta($elem).'$'; }
1254 if ($elem) { push @SkipHosts, qr/$elem/i; }
1255 }
1256 next;
1257 }
1258 if ($param =~ /^SkipUserAgents/) {
1259 foreach my $elem (split(/\s+/,$value)) {
1260 if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
1261 rizwank 1.1 else { $elem='^'.quotemeta($elem).'$'; }
1262 if ($elem) { push @SkipUserAgents, qr/$elem/i; }
1263 }
1264 next;
1265 }
1266 if ($param =~ /^SkipFiles/) {
1267 foreach my $elem (split(/\s+/,$value)) {
1268 if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
1269 else { $elem='^'.quotemeta($elem).'$'; }
1270 if ($elem) { push @SkipFiles, qr/$elem/i; }
1271 }
1272 next;
1273 }
1274 if ($param =~ /^OnlyHosts/) {
1275 foreach my $elem (split(/\s+/,$value)) {
1276 if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
1277 else { $elem='^'.quotemeta($elem).'$'; }
1278 if ($elem) { push @OnlyHosts, qr/$elem/i; }
1279 }
1280 next;
1281 }
1282 rizwank 1.1 if ($param =~ /^OnlyUserAgents/) {
1283 foreach my $elem (split(/\s+/,$value)) {
1284 if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
1285 else { $elem='^'.quotemeta($elem).'$'; }
1286 if ($elem) { push @OnlyUserAgents, qr/$elem/i; }
1287 }
1288 next;
1289 }
1290 if ($param =~ /^OnlyFiles/) {
1291 foreach my $elem (split(/\s+/,$value)) {
1292 if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
1293 else { $elem='^'.quotemeta($elem).'$'; }
1294 if ($elem) { push @OnlyFiles, qr/$elem/i; }
1295 }
1296 next;
1297 }
1298 if ($param =~ /^NotPageList/) {
1299 foreach (split(/\s+/,$value)) { $NotPageList{$_}=1; }
1300 $FoundNotPageList=1;
1301 next;
1302 }
1303 rizwank 1.1 if ($param =~ /^ValidHTTPCodes/) {
1304 foreach (split(/\s+/,$value)) { $ValidHTTPCodes{$_}=1; }
1305 next;
1306 }
1307 if ($param =~ /^ValidSMTPCodes/) {
1308 foreach (split(/\s+/,$value)) { $ValidSMTPCodes{$_}=1; }
1309 next;
1310 }
1311 if ($param =~ /^URLWithQueryWithOnlyFollowingParameters$/) {
1312 @URLWithQueryWithOnly=split(/\s+/,$value);
1313 next;
1314 }
1315 if ($param =~ /^URLWithQueryWithoutFollowingParameters$/) {
1316 @URLWithQueryWithout=split(/\s+/,$value);
1317 next;
1318 }
1319
1320 # Extra parameters
1321 if ($param =~ /^ExtraSectionName(\d+)/) { $ExtraName[$1]=$value; next; }
1322 if ($param =~ /^ExtraSectionCodeFilter(\d+)/) { @{$ExtraCodeFilter[$1]}=split(/\s+/,$value); next; }
1323 if ($param =~ /^ExtraSectionCondition(\d+)/) { $ExtraCondition[$1]=$value; next; }
1324 rizwank 1.1 if ($param =~ /^ExtraSectionStatTypes(\d+)/) { $ExtraStatTypes[$1]=$value; next; }
1325 if ($param =~ /^ExtraSectionFirstColumnTitle(\d+)/) { $ExtraFirstColumnTitle[$1]=$value; next; }
1326 if ($param =~ /^ExtraSectionFirstColumnValues(\d+)/) { $ExtraFirstColumnValues[$1]=$value; next; }
1327 if ($param =~ /^ExtraSectionFirstColumnFormat(\d+)/) { $ExtraFirstColumnFormat[$1]=$value; next; }
1328 if ($param =~ /^ExtraSectionAddAverageRow(\d+)/) { $ExtraAddAverageRow[$1]=$value; next; }
1329 if ($param =~ /^ExtraSectionAddSumRow(\d+)/) { $ExtraAddSumRow[$1]=$value; next; }
1330 if ($param =~ /^MaxNbOfExtra(\d+)/) { $MaxNbOfExtra[$1]=$value; next; }
1331 if ($param =~ /^MinHitExtra(\d+)/) { $MinHitExtra[$1]=$value; next; }
1332 # Special appearance parameters
1333 if ($param =~ /^LoadPlugin/) { push @PluginsToLoad, $value; next; }
1334 # Other parameter checks we need to put after MaxNbOfExtra and MinHitExtra
1335 if ($param =~ /^MaxNbOf(\w+)/) { $MaxNbOf{$1}=$value; next; }
1336 if ($param =~ /^MinHit(\w+)/) { $MinHit{$1}=$value; next; }
1337 # Check if this is a known parameter
1338 # if (! $ConfOk{$param}) { error("Unknown config parameter '$param' found line $conflinenb in file \"configFile\""); }
1339 # If parameters was not found previously, defined variable with name of param to value
1340 $$param=$value;
1341 }
1342
1343 # For backward compatibility
1344 if ($versionnum < 5001) { $BarHeight=$BarHeight>>1; }
1345 rizwank 1.1
1346 if ($Debug) { debug("Config file read was \"$configFile\" (level $level)"); }
1347 }
1348
1349 #------------------------------------------------------------------------------
1350 # Function: Load the reference databases
1351 # Parameters: List of files to load
1352 # Input: $DIR
1353 # Output: Arrays and Hash tables are defined
1354 # Return: -
1355 #------------------------------------------------------------------------------
1356 sub Read_Ref_Data {
1357 # Check lib files in common possible directories :
1358 # Windows and standard package: "$DIR/lib" (lib in same dir than awstats.pl)
1359 # Debian package: "/usr/share/awstats/lib"
1360 my @PossibleLibDir=("$DIR/lib","/usr/share/awstats/lib");
1361 my %FilePath=(); my %DirAddedInINC=();
1362 my @FileListToLoad=();
1363 while (my $file=shift) { push @FileListToLoad, "$file.pm"; }
1364 if ($Debug) { debug("Call to Read_Ref_Data with files to load: ".(join(',',@FileListToLoad))); }
1365 foreach my $file (@FileListToLoad) {
1366 rizwank 1.1 foreach my $dir (@PossibleLibDir) {
1367 my $searchdir=$dir;
1368 if ($searchdir && (!($searchdir =~ /\/$/)) && (!($searchdir =~ /\\$/)) ) { $searchdir .= "/"; }
1369 if (! $FilePath{$file}) { # To not load twice same file in different path
1370 if (-s "${searchdir}${file}") {
1371 $FilePath{$file}="${searchdir}${file}";
1372 if ($Debug) { debug("Call to Read_Ref_Data [FilePath{$file}=\"$FilePath{$file}\"]"); }
1373 # Note: cygwin perl 5.8 need a push + require file
1374 if (! $DirAddedInINC{"$dir"}) {
1375 push @INC, "$dir";
1376 $DirAddedInINC{"$dir"}=1;
1377 }
1378 my $loadret=require "$file";
1379 #my $loadret=(require "$FilePath{$file}"||require "${file}");
1380 }
1381 }
1382 }
1383 if (! $FilePath{$file}) {
1384 my $filetext=$file; $filetext =~ s/\.pm$//; $filetext =~ s/_/ /g;
1385 warning("Warning: Can't read file \"$file\" ($filetext detection will not work correctly).\nCheck if file is in \"".($PossibleLibDir[0])."\" directory and is readable.");
1386 }
1387 rizwank 1.1 }
1388 # Sanity check (if loaded)
1389 if ((scalar keys %OSHashID) && @OSSearchIDOrder != scalar keys %OSHashID) { error("Not same number of records of OSSearchIDOrder (".(@OSSearchIDOrder)." entries) and OSHashID (".(scalar keys %OSHashID)." entries) in OS database. Check your file ".$FilePath{"operating_systems.pm"}); }
1390 if ((scalar keys %SearchEnginesHashID) && (@SearchEnginesSearchIDOrder_list1+@SearchEnginesSearchIDOrder_list2+@SearchEnginesSearchIDOrder_listgen) != scalar keys %SearchEnginesHashID) { error("Not same number of records of SearchEnginesSearchIDOrder_listx (total is ".(@SearchEnginesSearchIDOrder_list1+@SearchEnginesSearchIDOrder_list2+@SearchEnginesSearchIDOrder_listgen)." entries) and SearchEnginesHashID (".(scalar keys %SearchEnginesHashID)." entries) in Search Engines database. Check your file ".$FilePath{"search_engines.pm"}." is up to date."); }
1391 if ((scalar keys %BrowsersHashIDLib) && @BrowsersSearchIDOrder != (scalar keys %BrowsersHashIDLib) - 3) { error("Not same number of records of BrowsersSearchIDOrder (".(@BrowsersSearchIDOrder)." entries) and BrowsersHashIDLib (".((scalar keys %BrowsersHashIDLib) - 3)." entries without msie,netscape,firefox) in Browsers database. May be you updated AWStats without updating browsers.pm file or you made changed into browsers.pm not correctly. Check your file ".$FilePath{"browsers.pm"}." is up to date."); }
1392 if ((scalar keys %RobotsHashIDLib) && (@RobotsSearchIDOrder_list1+@RobotsSearchIDOrder_list2+@RobotsSearchIDOrder_listgen) != (scalar keys %RobotsHashIDLib) - 1) { error("Not same number of records of RobotsSearchIDOrder_listx (total is ".(@RobotsSearchIDOrder_list1+@RobotsSearchIDOrder_list2+@RobotsSearchIDOrder_listgen)." entries) and RobotsHashIDLib (".((scalar keys %RobotsHashIDLib) - 1)." entries without 'unknown') in Robots database. Check your file ".$FilePath{"robots.pm"}." is up to date."); }
1393 }
1394
1395
1396 #------------------------------------------------------------------------------
1397 # Function: Get the messages for a specified language
1398 # Parameters: LanguageId
1399 # Input: $DirLang $DIR
1400 # Output: $Message table is defined in memory
1401 # Return: None
1402 #------------------------------------------------------------------------------
1403 sub Read_Language_Data {
1404 # Check lang files in common possible directories :
1405 # Windows and standard package: "$DIR/lang" (lang in same dir than awstats.pl)
1406 # Debian package : "/usr/share/awstats/lang"
1407 my @PossibleLangDir=("$DirLang","$DIR/lang","/usr/share/awstats/lang");
1408 rizwank 1.1
1409 my $FileLang='';
1410 foreach (@PossibleLangDir) {
1411 my $searchdir=$_;
1412 if ($searchdir && (!($searchdir =~ /\/$/)) && (!($searchdir =~ /\\$/)) ) { $searchdir .= "/"; }
1413 if (open(LANG,"${searchdir}awstats-$_[0].txt")) { $FileLang="${searchdir}awstats-$_[0].txt"; last; }
1414 }
1415 # If file not found, we try english
1416 if (! $FileLang) {
1417 foreach (@PossibleLangDir) {
1418 my $searchdir=$_;
1419 if ($searchdir && (!($searchdir =~ /\/$/)) && (!($searchdir =~ /\\$/)) ) { $searchdir .= "/"; }
1420 if (open(LANG,"${searchdir}awstats-en.txt")) { $FileLang="${searchdir}awstats-en.txt"; last; }
1421 }
1422 }
1423 if ($Debug) { debug("Call to Read_Language_Data [FileLang=\"$FileLang\"]"); }
1424 if ($FileLang) {
1425 my $i = 0;
1426 binmode LANG; # Might avoid 'Malformed UTF-8 errors'
1427 my $cregcode=qr/^PageCode=[\t\s\"\']*([\w-]+)/i;
1428 my $cregdir=qr/^PageDir=[\t\s\"\']*([\w-]+)/i;
1429 rizwank 1.1 my $cregmessage=qr/^Message\d+=/i;
1430 while (<LANG>) {
1431 chomp $_; s/\r//;
1432 if ($_ =~ /$cregcode/o) { $PageCode = $1; }
1433 if ($_ =~ /$cregdir/o) { $PageDir = $1; }
1434 if ($_ =~ s/$cregmessage//o) {
1435 $_ =~ s/^#.*//; # Remove comments
1436 $_ =~ s/\s+#.*//; # Remove comments
1437 $_ =~ tr/\t / /s; # Change all blanks into " "
1438 $_ =~ s/^\s+//; $_ =~ s/\s+$//;
1439 $_ =~ s/^\"//; $_ =~ s/\"$//;
1440 $Message[$i] = $_;
1441 $i++;
1442 }
1443 }
1444 close(LANG);
1445 }
1446 else {
1447 warning("Warning: Can't find language files for \"$_[0]\". English will be used.");
1448 }
1449 # Some language string changes
1450 rizwank 1.1 if ($LogType eq 'M') { # For mail
1451 $Message[8]=$Message[151];
1452 $Message[9]=$Message[152];
1453 $Message[57]=$Message[149];
1454 $Message[75]=$Message[150];
1455 }
1456 if ($LogType eq 'F') { # For web
1457
1458 }
1459 }
1460
1461
1462 #------------------------------------------------------------------------------
1463 # Function: Check if all parameters are correctly defined. If not set them to default.
1464 # Parameters: None
1465 # Input: All global variables
1466 # Output: Change on some global variables
1467 # Return: None
1468 #------------------------------------------------------------------------------
1469 sub Check_Config {
1470 if ($Debug) { debug("Call to Check_Config"); }
1471 rizwank 1.1
1472 my %MonthNumLibEn = ("01","Jan","02","Feb","03","Mar","04","Apr","05","May","06","Jun","07","Jul","08","Aug","09","Sep","10","Oct","11","Nov","12","Dec");
1473
1474 # Show initial values of main parameters before check
1475 if ($Debug) {
1476 debug(" LogFile='$LogFile'",2);
1477 debug(" LogType='$LogType'",2);
1478 debug(" LogFormat='$LogFormat'",2);
1479 debug(" LogSeparator='$LogSeparator'",2);
1480 debug(" DNSLookup='$DNSLookup'",2);
1481 debug(" DirData='$DirData'",2);
1482 debug(" DirCgi='$DirCgi'",2);
1483 debug(" DirIcons='$DirIcons'",2);
1484 debug(" NotPageList ".(join(',',keys %NotPageList)),2);
1485 debug(" ValidHTTPCodes ".(join(',',keys %ValidHTTPCodes)),2);
1486 debug(" ValidSMTPCodes ".(join(',',keys %ValidSMTPCodes)),2);
1487 debug(" UseFramesWhenCGI=$UseFramesWhenCGI",2);
1488 debug(" BuildReportFormat=$BuildReportFormat",2);
1489 debug(" BuildHistoryFormat=$BuildHistoryFormat",2);
1490 debug(" URLWithQueryWithOnlyFollowingParameters=".(join(',',@URLWithQueryWithOnly)),2);
1491 debug(" URLWithQueryWithoutFollowingParameters=".(join(',',@URLWithQueryWithout)),2);
1492 rizwank 1.1 }
1493
1494 # Main section
1495 while ($LogFile =~ /%([ymdhwYMDHWNSO]+)-(\(\d+\)|\d+)/) {
1496 # Accept tag %xx-dd and %xx-(dd)
1497 my $timetag="$1";
1498 my $timephase=quotemeta("$2");
1499 my $timephasenb="$2"; $timephasenb=~s/[^\d]//g;
1500 if ($Debug) { debug(" Found a time tag '$timetag' with a phase of '$timephasenb' hour in log file name",1); }
1501 # Get older time
1502 my ($oldersec,$oldermin,$olderhour,$olderday,$oldermonth,$olderyear,$olderwday,$olderyday) = localtime($starttime-($timephasenb*3600));
1503 my $olderweekofmonth=int($olderday/7);
1504 my $olderweekofyear=int(($olderyday-1+6-($olderwday==0?6:$olderwday-1))/7)+1; if ($olderweekofyear > 52) { $olderweekofyear = 1; }
1505 my $olderdaymod=$olderday%7;
1506 $olderwday++;
1507 my $olderns=Time::Local::timegm(0,0,0,$olderday,$oldermonth,$olderyear);
1508 if ($olderdaymod <= $olderwday) { if (($olderwday != 7) || ($olderdaymod != 0)) { $olderweekofmonth=$olderweekofmonth+1; } }
1509 if ($olderdaymod > $olderwday) { $olderweekofmonth=$olderweekofmonth+2; }
1510 # Change format of time variables
1511 $olderweekofmonth = "0$olderweekofmonth";
1512 if ($olderweekofyear < 10) { $olderweekofyear = "0$olderweekofyear"; }
1513 rizwank 1.1 if ($olderyear < 100) { $olderyear+=2000; } else { $olderyear+=1900; }
1514 my $oldersmallyear=$olderyear;$oldersmallyear =~ s/^..//;
1515 if (++$oldermonth < 10) { $oldermonth = "0$oldermonth"; }
1516 if ($olderday < 10) { $olderday = "0$olderday"; }
1517 if ($olderhour < 10) { $olderhour = "0$olderhour"; }
1518 if ($oldermin < 10) { $oldermin = "0$oldermin"; }
1519 if ($oldersec < 10) { $oldersec = "0$oldersec"; }
1520 # Replace tag with new value
1521 if ($timetag eq 'YYYY') { $LogFile =~ s/%YYYY-$timephase/$olderyear/ig; next; }
1522 if ($timetag eq 'YY') { $LogFile =~ s/%YY-$timephase/$oldersmallyear/ig; next; }
1523 if ($timetag eq 'MM') { $LogFile =~ s/%MM-$timephase/$oldermonth/ig; next; }
1524 if ($timetag eq 'MO') { $LogFile =~ s/%MO-$timephase/$MonthNumLibEn{$oldermonth}/ig; next; }
1525 if ($timetag eq 'DD') { $LogFile =~ s/%DD-$timephase/$olderday/ig; next; }
1526 if ($timetag eq 'HH') { $LogFile =~ s/%HH-$timephase/$olderhour/ig; next; }
1527 if ($timetag eq 'NS') { $LogFile =~ s/%NS-$timephase/$olderns/ig; next; }
1528 if ($timetag eq 'WM') { $LogFile =~ s/%WM-$timephase/$olderweekofmonth/g; next; }
1529 if ($timetag eq 'Wm') { my $olderweekofmonth0=$olderweekofmonth-1; $LogFile =~ s/%Wm-$timephase/$olderweekofmonth0/g; next; }
1530 if ($timetag eq 'WY') { $LogFile =~ s/%WY-$timephase/$olderweekofyear/g; next; }
1531 if ($timetag eq 'Wy') { my $olderweekofyear0=sprintf("%02d",$olderweekofyear-1); $LogFile =~ s/%Wy-$timephase/$olderweekofyear0/g; next; }
1532 if ($timetag eq 'DW') { $LogFile =~ s/%DW-$timephase/$olderwday/g; next; }
1533 if ($timetag eq 'Dw') { my $olderwday0=$olderwday-1; $LogFile =~ s/%Dw-$timephase/$olderwday0/g; next; }
1534 rizwank 1.1 # If unknown tag
1535 error("Unknown tag '\%$timetag' in LogFile parameter.");
1536 }
1537 # Replace %YYYY %YY %MM %DD %HH with current value. Kept for backward compatibility.
1538 $LogFile =~ s/%YYYY/$nowyear/ig;
1539 $LogFile =~ s/%YY/$nowsmallyear/ig;
1540 $LogFile =~ s/%MM/$nowmonth/ig;
1541 $LogFile =~ s/%MO/$MonthNumLibEn{$nowmonth}/ig;
1542 $LogFile =~ s/%DD/$nowday/ig;
1543 $LogFile =~ s/%HH/$nowhour/ig;
1544 $LogFile =~ s/%NS/$nowns/ig;
1545 $LogFile =~ s/%WM/$nowweekofmonth/g;
1546 my $nowweekofmonth0=$nowweekofmonth-1; $LogFile =~ s/%Wm/$nowweekofmonth0/g;
1547 $LogFile =~ s/%WY/$nowweekofyear/g;
1548 my $nowweekofyear0=$nowweekofyear-1; $LogFile =~ s/%Wy/$nowweekofyear0/g;
1549 $LogFile =~ s/%DW/$nowwday/g;
1550 my $nowwday0=$nowwday-1; $LogFile =~ s/%Dw/$nowwday0/g;
1551 if (! $LogFile) { error("LogFile parameter is not defined in config/domain file"); }
1552 if ($LogType !~ /[WSMF]/i) { $LogType='W'; }
1553 $LogFormat =~ s/\\//g;
1554 if (! $LogFormat) { error("LogFormat parameter is not defined in config/domain file"); }
1555 rizwank 1.1 if ($LogFormat =~ /^\d$/ && $LogFormat !~ /[1-6]/) { error("LogFormat parameter is wrong in config/domain file. Value is '$LogFormat' (should be 1,2,3,4,5 or a 'personalized AWStats log format string')"); }
1556 $LogSeparator||="\\s";
1557 $DirData||='.';
1558 $DirCgi||='/cgi-bin';
1559 $DirIcons||='/icon';
1560 if ($DNSLookup !~ /[0-2]/) { error("DNSLookup parameter is wrong in config/domain file. Value is '$DNSLookup' (should be 0 or 1)"); }
1561 if (! $SiteDomain) { error("SiteDomain parameter not defined in your config/domain file. You must add it for using this version of AWStats."); }
1562 if ($AllowToUpdateStatsFromBrowser !~ /[0-1]/) { $AllowToUpdateStatsFromBrowser=0; }
1563 if ($AllowFullYearView !~ /[0-3]/) { $AllowFullYearView=2; }
1564 # Optional setup section
1565 if ($EnableLockForUpdate !~ /[0-1]/) { $EnableLockForUpdate=0; }
1566 $DNSStaticCacheFile||='dnscache.txt';
1567 $DNSLastUpdateCacheFile||='dnscachelastupdate.txt';
1568 if ($DNSStaticCacheFile eq $DNSLastUpdateCacheFile) { error("DNSStaticCacheFile and DNSLastUpdateCacheFile must have different values."); }
1569 if ($AllowAccessFromWebToAuthenticatedUsersOnly !~ /[0-1]/) { $AllowAccessFromWebToAuthenticatedUsersOnly=0; }
1570 if ($CreateDirDataIfNotExists !~ /[0-1]/) { $CreateDirDataIfNotExists=0; }
1571 if ($BuildReportFormat !~ /html|xhtml|xml/i) { $BuildReportFormat='html'; }
1572 if ($BuildHistoryFormat !~ /text|xml/) { $BuildHistoryFormat='text'; }
1573 if ($SaveDatabaseFilesWithPermissionsForEveryone !~ /[0-1]/) { $SaveDatabaseFilesWithPermissionsForEveryone=0; }
1574 if ($PurgeLogFile !~ /[0-1]/) { $PurgeLogFile=0; }
1575 if ($ArchiveLogRecords !~ /[0-1]/) { $ArchiveLogRecords=0; }
1576 rizwank 1.1 if ($KeepBackupOfHistoricFiles !~ /[0-1]/) { $KeepBackupOfHistoricFiles=0; }
1577 $DefaultFile[0]||='index.html';
1578 if ($AuthenticatedUsersNotCaseSensitive !~ /[0-1]/) { $AuthenticatedUsersNotCaseSensitive=0; }
1579 if ($URLNotCaseSensitive !~ /[0-1]/) { $URLNotCaseSensitive=0; }
1580 if ($URLWithAnchor !~ /[0-1]/) { $URLWithAnchor=0; }
1581 $URLQuerySeparators =~ s/\s//g;
1582 if (! $URLQuerySeparators) { $URLQuerySeparators='?;'; }
1583 if ($URLWithQuery !~ /[0-1]/) { $URLWithQuery=0; }
1584 if ($URLReferrerWithQuery !~ /[0-1]/) { $URLReferrerWithQuery=0; }
1585 if ($WarningMessages !~ /[0-1]/) { $WarningMessages=1; }
1586 if ($DebugMessages !~ /[0-1]/) { $DebugMessages=1; }
1587 if ($NbOfLinesForCorruptedLog !~ /^\d+/ || $NbOfLinesForCorruptedLog<1) { $NbOfLinesForCorruptedLog=50; }
1588 if ($Expires !~ /^\d+/) { $Expires=0; }
1589 if ($DecodeUA !~ /[0-1]/) { $DecodeUA=0; }
1590 $MiscTrackerUrl||='/js/awstats_misc_tracker.js';
1591 # Optional accuracy setup section
1592 if ($LevelForWormsDetection !~ /^\d+/) { $LevelForWormsDetection=0; }
1593 if ($LevelForRobotsDetection !~ /^\d+/) { $LevelForRobotsDetection=2; }
1594 if ($LevelForBrowsersDetection !~ /^\d+/) { $LevelForBrowsersDetection=2; }
1595 if ($LevelForOSDetection !~ /^\d+/) { $LevelForOSDetection=2; }
1596 if ($LevelForRefererAnalyze !~ /^\d+/) { $LevelForRefererAnalyze=2; }
1597 rizwank 1.1 if ($LevelForFileTypesDetection !~ /^\d+/) { $LevelForFileTypesDetection=2; }
1598 if ($LevelForSearchEnginesDetection !~ /^\d+/) { $LevelForSearchEnginesDetection=2; }
1599 if ($LevelForKeywordsDetection !~ /^\d+/) { $LevelForKeywordsDetection=2; }
1600 # Optional extra setup section
1601 foreach my $extracpt (1..@ExtraName-1) {
1602 if ($ExtraStatTypes[$extracpt] !~ /[PHBL]/) { $ExtraStatTypes[$extracpt]='PHBL'; }
1603 if ($MaxNbOfExtra[$extracpt] !~ /^\d+$/ || $MaxNbOfExtra[$extracpt]<1) { $MaxNbOfExtra[$extracpt]=20; }
1604 if ($MinHitExtra[$extracpt] !~ /^\d+$/ || $MinHitExtra[$extracpt]<1) { $MinHitExtra[$extracpt]=1; }
1605 if (! $ExtraFirstColumnValues[$extracpt]) { error("Extra section number $extracpt is defined without ExtraSectionFirstColumnValues$extracpt parameter"); }
1606 if (! $ExtraFirstColumnFormat[$extracpt]) { $ExtraFirstColumnFormat[$extracpt] = '%s'; }
1607 }
1608 # Optional appearance setup section
1609 if ($MaxRowsInHTMLOutput !~ /^\d+/ || $MaxRowsInHTMLOutput<1) { $MaxRowsInHTMLOutput=1000; }
1610 if ($ShowMenu !~ /[01]/) { $ShowMenu=1; }
1611 if ($ShowMonthStats !~ /[01UVPHB]/) { $ShowMonthStats='UVPHB'; }
1612 if ($ShowDaysOfMonthStats !~ /[01VPHB]/) { $ShowDaysOfMonthStats='VPHB'; }
1613 if ($ShowDaysOfWeekStats !~ /[01PHBL]/) { $ShowDaysOfWeekStats='PHBL'; }
1614 if ($ShowHoursStats !~ /[01PHBL]/) { $ShowHoursStats='PHBL'; }
1615 if ($ShowDomainsStats !~ /[01PHB]/) { $ShowDomainsStats='PHB'; }
1616 if ($ShowHostsStats !~ /[01PHBL]/) { $ShowHostsStats='PHBL'; }
1617 if ($ShowAuthenticatedUsers !~ /[01PHBL]/) { $ShowAuthenticatedUsers=0; }
1618 rizwank 1.1 if ($ShowRobotsStats !~ /[01HBL]/) { $ShowRobotsStats='HBL'; }
1619 if ($ShowWormsStats !~ /[01HBL]/) { $ShowWormsStats='HBL'; }
1620 if ($ShowEMailSenders !~ /[01HBML]/) { $ShowEMailSenders=0; }
1621 if ($ShowEMailReceivers !~ /[01HBML]/) { $ShowEMailReceivers=0; }
1622 if ($ShowSessionsStats !~ /[01]/) { $ShowSessionsStats=1; }
1623 if ($ShowPagesStats !~ /[01PBEX]/i) { $ShowPagesStats='PBEX'; }
1624 if ($ShowFileTypesStats !~ /[01HBC]/) { $ShowFileTypesStats='HB'; }
1625 if ($ShowFileSizesStats !~ /[01]/) { $ShowFileSizesStats=1; }
1626 if ($ShowOSStats !~ /[01]/) { $ShowOSStats=1; }
1627 if ($ShowBrowsersStats !~ /[01]/) { $ShowBrowsersStats=1; }
1628 if ($ShowScreenSizeStats !~ /[01]/) { $ShowScreenSizeStats=0; }
1629 if ($ShowOriginStats !~ /[01PH]/) { $ShowOriginStats='PH'; }
1630 if ($ShowKeyphrasesStats !~ /[01]/) { $ShowKeyphrasesStats=1; }
1631 if ($ShowKeywordsStats !~ /[01]/) { $ShowKeywordsStats=1; }
1632 if ($ShowClusterStats !~ /[01PHB]/) { $ShowClusterStats=0; }
1633 if ($ShowMiscStats !~ /[01anjdfrqwp]/) { $ShowMiscStats='a'; }
1634 if ($ShowHTTPErrorsStats !~ /[01]/) { $ShowHTTPErrorsStats=1; }
1635 if ($ShowSMTPErrorsStats !~ /[01]/) { $ShowSMTPErrorsStats=0; }
1636 if ($AddDataArrayMonthStats !~ /[01]/) { $AddDataArrayMonthStats=1; }
1637 if ($AddDataArrayShowDaysOfMonthStats !~ /[01]/) { $AddDataArrayShowDaysOfMonthStats=1; }
1638 if ($AddDataArrayShowDaysOfWeekStats !~ /[01]/) { $AddDataArrayShowDaysOfWeekStats=1; }
1639 rizwank 1.1 if ($AddDataArrayShowHoursStats !~ /[01]/) { $AddDataArrayShowHoursStats=1; }
1640 my @maxnboflist=('Domain','HostsShown','LoginShown','RobotShown','WormsShown','PageShown','OsShown','BrowsersShown','ScreenSizesShown','RefererShown','KeyphrasesShown','KeywordsShown','EMailsShown');
1641 my @maxnboflistdefaultval=(10,10,10,10,5,10,10,10,5,10,10,10,20);
1642 foreach my $i (0..(@maxnboflist-1)) {
1643 if (! $MaxNbOf{$maxnboflist[$i]} || $MaxNbOf{$maxnboflist[$i]} !~ /^\d+$/ || $MaxNbOf{$maxnboflist[$i]}<1) { $MaxNbOf{$maxnboflist[$i]}=$maxnboflistdefaultval[$i]; }
1644 }
1645 my @minhitlist=('Domain','Host','Login','Robot','Worm','File','Os','Browser','ScreenSize','Refer','Keyphrase','Keyword','EMail');
1646 my @minhitlistdefaultval=(1,1,1,1,1,1,1,1,1,1,1,1,1);
1647 foreach my $i (0..(@minhitlist-1)) {
1648 if (! $MinHit{$minhitlist[$i]} || $MinHit{$minhitlist[$i]} !~ /^\d+$/ || $MinHit{$minhitlist[$i]}<1) { $MinHit{$minhitlist[$i]}=$minhitlistdefaultval[$i]; }
1649 }
1650 if ($FirstDayOfWeek !~ /[01]/) { $FirstDayOfWeek=1; }
1651 if ($UseFramesWhenCGI !~ /[01]/) { $UseFramesWhenCGI=1; }
1652 if ($DetailedReportsOnNewWindows !~ /[012]/) { $DetailedReportsOnNewWindows=1; }
1653 if ($ShowLinksOnUrl !~ /[01]/) { $ShowLinksOnUrl=1; }
1654 if ($MaxLengthOfShownURL !~ /^\d+/ || $MaxLengthOfShownURL<1) { $MaxLengthOfShownURL=64; }
1655 if ($ShowLinksToWhoIs !~ /[01]/) { $ShowLinksToWhoIs=0; }
1656 $Logo||='awstats_logo6.png';
1657 $LogoLink||='http://awstats.sourceforge.net';
1658 if ($BarWidth !~ /^\d+/ || $BarWidth<1) { $BarWidth=260; }
1659 if ($BarHeight !~ /^\d+/ || $BarHeight<1) { $BarHeight=90; }
1660 rizwank 1.1 $color_Background =~ s/#//g; if ($color_Background !~ /^[0-9|A-H]+$/i) { $color_Background='FFFFFF'; }
1661 $color_TableBGTitle =~ s/#//g; if ($color_TableBGTitle !~ /^[0-9|A-H]+$/i) { $color_TableBGTitle='CCCCDD'; }
1662 $color_TableTitle =~ s/#//g; if ($color_TableTitle !~ /^[0-9|A-H]+$/i) { $color_TableTitle='000000'; }
1663 $color_TableBG =~ s/#//g; if ($color_TableBG !~ /^[0-9|A-H]+$/i) { $color_TableBG='CCCCDD'; }
1664 $color_TableRowTitle =~ s/#//g; if ($color_TableRowTitle !~ /^[0-9|A-H]+$/i) { $color_TableRowTitle='FFFFFF'; }
1665 $color_TableBGRowTitle =~ s/#//g; if ($color_TableBGRowTitle !~ /^[0-9|A-H]+$/i) { $color_TableBGRowTitle='ECECEC'; }
1666 $color_TableBorder =~ s/#//g; if ($color_TableBorder !~ /^[0-9|A-H]+$/i) { $color_TableBorder='ECECEC'; }
1667 $color_text =~ s/#//g; if ($color_text !~ /^[0-9|A-H]+$/i) { $color_text='000000'; }
1668 $color_textpercent =~ s/#//g; if ($color_textpercent !~ /^[0-9|A-H]+$/i) { $color_textpercent='606060'; }
1669 $color_titletext =~ s/#//g; if ($color_titletext !~ /^[0-9|A-H]+$/i) { $color_titletext='000000'; }
1670 $color_weekend =~ s/#//g; if ($color_weekend !~ /^[0-9|A-H]+$/i) { $color_weekend='EAEAEA'; }
1671 $color_link =~ s/#//g; if ($color_link !~ /^[0-9|A-H]+$/i) { $color_link='0011BB'; }
1672 $color_hover =~ s/#//g; if ($color_hover !~ /^[0-9|A-H]+$/i) { $color_hover='605040'; }
1673 $color_other =~ s/#//g; if ($color_other !~ /^[0-9|A-H]+$/i) { $color_other='666688'; }
1674 $color_u =~ s/#//g; if ($color_u !~ /^[0-9|A-H]+$/i) { $color_u='FFA060'; }
1675 $color_v =~ s/#//g; if ($color_v !~ /^[0-9|A-H]+$/i) { $color_v='F4F090'; }
1676 $color_p =~ s/#//g; if ($color_p !~ /^[0-9|A-H]+$/i) { $color_p='4477DD'; }
1677 $color_h =~ s/#//g; if ($color_h !~ /^[0-9|A-H]+$/i) { $color_h='66EEFF'; }
1678 $color_k =~ s/#//g; if ($color_k !~ /^[0-9|A-H]+$/i) { $color_k='2EA495'; }
1679 $color_s =~ s/#//g; if ($color_s !~ /^[0-9|A-H]+$/i) { $color_s='8888DD'; }
1680 $color_e =~ s/#//g; if ($color_e !~ /^[0-9|A-H]+$/i) { $color_e='CEC2E8'; }
1681 rizwank 1.1 $color_x =~ s/#//g; if ($color_x !~ /^[0-9|A-H]+$/i) { $color_x='C1B2E2'; }
1682
1683 # Correct param if default value is asked
1684 if ($ShowMonthStats eq '1') { $ShowMonthStats = 'UVPHB'; }
1685 if ($ShowDaysOfMonthStats eq '1') { $ShowDaysOfMonthStats = 'VPHB'; }
1686 if ($ShowDaysOfWeekStats eq '1') { $ShowDaysOfWeekStats = 'PHBL'; }
1687 if ($ShowHoursStats eq '1') { $ShowHoursStats = 'PHBL'; }
1688 if ($ShowDomainsStats eq '1') { $ShowDomainsStats = 'PHB'; }
1689 if ($ShowHostsStats eq '1') { $ShowHostsStats = 'PHBL'; }
1690 if ($ShowEMailSenders eq '1') { $ShowEMailSenders = 'HBML'; }
1691 if ($ShowEMailReceivers eq '1') { $ShowEMailReceivers = 'HBML'; }
1692 if ($ShowAuthenticatedUsers eq '1') { $ShowAuthenticatedUsers = 'PHBL'; }
1693 if ($ShowRobotsStats eq '1') { $ShowRobotsStats = 'HBL'; }
1694 if ($ShowWormsStats eq '1') { $ShowWormsStats = 'HBL'; }
1695 if ($ShowPagesStats eq '1') { $ShowPagesStats = 'PBEX'; }
1696 if ($ShowFileTypesStats eq '1') { $ShowFileTypesStats = 'HB'; }
1697 if ($ShowOriginStats eq '1') { $ShowOriginStats = 'PH'; }
1698 if ($ShowClusterStats eq '1') { $ShowClusterStats = 'PHB'; }
1699 if ($ShowMiscStats eq '1') { $ShowMiscStats = 'anjdfrqwp'; }
1700
1701 # Convert extra sections data into @ExtraConditionType, @ExtraConditionTypeVal...
1702 rizwank 1.1 foreach my $extranum (1..@ExtraName-1) {
1703 my $part=0;
1704 foreach my $conditioncouple (split(/\s*\|\|\s*/, $ExtraCondition[$extranum])) {
1705 my ($conditiontype, $conditiontypeval)=split(/[,:]/,$conditioncouple,2);
1706 $ExtraConditionType[$extranum][$part]=$conditiontype;
1707 if ($conditiontypeval =~ /^REGEX\[(.*)\]$/i) { $conditiontypeval=$1; }
1708 #else { $conditiontypeval=quotemeta($conditiontypeval); }
1709 $ExtraConditionTypeVal[$extranum][$part]=qr/$conditiontypeval/i;
1710 $part++;
1711 }
1712 $part=0;
1713 foreach my $rowkeycouple (split(/\s*\|\|\s*/, $ExtraFirstColumnValues[$extranum])) {
1714 my ($rowkeytype, $rowkeytypeval)=split(/[,:]/,$rowkeycouple,2);
1715 $ExtraFirstColumnValuesType[$extranum][$part]=$rowkeytype;
1716 if ($rowkeytypeval =~ /^REGEX\[(.*)\]$/i) { $rowkeytypeval=$1; }
1717 #else { $rowkeytypeval=quotemeta($rowkeytypeval); }
1718 $ExtraFirstColumnValuesTypeVal[$extranum][$part]=qr/$rowkeytypeval/i;
1719 $part++;
1720 }
1721 }
1722
1723 rizwank 1.1 # Show definitive value for major parameters
1724 if ($Debug) {
1725 debug(" LogFile='$LogFile'",2);
1726 debug(" LogFormat='$LogFormat'",2);
1727 debug(" LogSeparator='$LogSeparator'",2);
1728 debug(" DNSLookup='$DNSLookup'",2);
1729 debug(" DirData='$DirData'",2);
1730 debug(" DirCgi='$DirCgi'",2);
1731 debug(" DirIcons='$DirIcons'",2);
1732 debug(" SiteDomain='$SiteDomain'",2);
1733 debug(" MiscTrackerUrl='$MiscTrackerUrl'",2);
1734 foreach (keys %MaxNbOf) { debug(" MaxNbOf{$_}=$MaxNbOf{$_}",2); }
1735 foreach (keys %MinHit) { debug(" MinHit{$_}=$MinHit{$_}",2); }
1736 foreach my $extranum (1..@ExtraName-1) {
1737 debug(" ExtraCodeFilter[$extranum] is array ".join(',',@{$ExtraCodeFilter[$extranum]}),2);
1738 debug(" ExtraConditionType[$extranum] is array ".join(',',@{$ExtraConditionType[$extranum]}),2);
1739 debug(" ExtraConditionTypeVal[$extranum] is array ".join(',',@{$ExtraConditionTypeVal[$extranum]}),2);
1740 debug(" ExtraFirstColumnValuesType[$extranum] is array ".join(',',@{$ExtraFirstColumnValuesType[$extranum]}),2);
1741 debug(" ExtraFirstColumnValuesTypeVal[$extranum] is array ".join(',',@{$ExtraFirstColumnValuesTypeVal[$extranum]}),2);
1742 }
1743 }
1744 rizwank 1.1
1745 # Deny URLWithQueryWithOnlyFollowingParameters and URLWithQueryWithoutFollowingParameters both set
1746 if (@URLWithQueryWithOnly && @URLWithQueryWithout) {
1747 error("URLWithQueryWithOnlyFollowingParameters and URLWithQueryWithoutFollowingParameters can't be both set at the same time");
1748 }
1749 # Deny $ShowHTTPErrorsStats and $ShowSMTPErrorsStats both set
1750 if ($ShowHTTPErrorsStats && $ShowSMTPErrorsStats) {
1751 error("ShowHTTPErrorsStats and ShowSMTPErrorsStats can't be both set at the same time");
1752 }
1753
1754 # Deny LogFile if contains a pipe and PurgeLogFile || ArchiveLogRecords set on
1755 if (($PurgeLogFile || $ArchiveLogRecords) && $LogFile =~ /\|\s*$/) {
1756 error("A pipe in log file name is not allowed if PurgeLogFile and ArchiveLogRecords are not set to 0");
1757 }
1758 # If not a migrate, check if DirData is OK
1759 if (! $MigrateStats && ! -d $DirData) {
1760 if ($CreateDirDataIfNotExists) {
1761 if ($Debug) { debug(" Make directory $DirData",2); }
1762 my $mkdirok=mkdir "$DirData", 0766;
1763 if (! $mkdirok) { error("$PROG failed to create directory DirData (DirData=\"$DirData\", CreateDirDataIfNotExists=$CreateDirDataIfNotExists)."); }
1764 }
1765 rizwank 1.1 else {
1766 error("AWStats database directory defined in config file by 'DirData' parameter ($DirData) does not exist or is not writable.");
1767 }
1768 }
1769
1770 if ($LogType eq 'S') { $NOTSORTEDRECORDTOLERANCE=1000000; }
1771 }
1772
1773
1774 #------------------------------------------------------------------------------
1775 # Function: Common function used by init function of plugins
1776 # Parameters: AWStats version required by plugin
1777 # Input: $VERSION
1778 # Output: None
1779 # Return: '' if ok, "Error: xxx" if error
1780 #------------------------------------------------------------------------------
1781 sub Check_Plugin_Version {
1782 my $PluginNeedAWStatsVersion=shift;
1783 if (! $PluginNeedAWStatsVersion) { return 0; }
1784 $VERSION =~ /^(\d+)\.(\d+)/;
1785 my $numAWStatsVersion=($1*1000)+$2;
1786 rizwank 1.1 $PluginNeedAWStatsVersion =~ /^(\d+)\.(\d+)/;
1787 my $numPluginNeedAWStatsVersion=($1*1000)+$2;
1788 if ($numPluginNeedAWStatsVersion > $numAWStatsVersion) {
1789 return "Error: AWStats version $PluginNeedAWStatsVersion or higher is required. Detected $VERSION.";
1790 }
1791 return '';
1792 }
1793
1794
1795 #------------------------------------------------------------------------------
1796 # Function: Return a checksum for an array of string
1797 # Parameters: Array of string
1798 # Input: None
1799 # Output: None
1800 # Return: Checksum number
1801 #------------------------------------------------------------------------------
1802 sub CheckSum {
1803 my $string=shift;
1804 my $checksum=0;
1805 # use MD5;
1806 # $checksum = MD5->hexhash($string);
1807 rizwank 1.1 my $i=0; my $j=0;
1808 while ($i < length($string)) {
1809 my $c=substr($string,$i,1);
1810 $checksum+=(ord($c)<<(8*$j));
1811 if ($j++ > 3) { $j=0; }
1812 $i++;
1813 }
1814 return $checksum;
1815 }
1816
1817
1818 #------------------------------------------------------------------------------
1819 # Function: Load plugins files
1820 # Parameters: None
1821 # Input: $DIR @PluginsToLoad
1822 # Output: None
1823 # Return: None
1824 #------------------------------------------------------------------------------
1825 sub Read_Plugins {
1826 # Check plugin files in common possible directories :
1827 # Windows and standard package: "$DIR/plugins" (plugins in same dir than awstats.pl)
1828 rizwank 1.1 # Redhat : "/usr/local/awstats/wwwroot/cgi-bin/plugins"
1829 # Debian package : "/usr/share/awstats/plugins"
1830 my @PossiblePluginsDir=("$DIR/plugins","/usr/local/awstats/wwwroot/cgi-bin/plugins","/usr/share/awstats/plugins");
1831 my %DirAddedInINC=();
1832
1833 foreach my $key (keys %NoLoadPlugin) { if ($NoLoadPlugin{$key} < 0) { push @PluginsToLoad, $key; } }
1834 if ($Debug) { debug("Call to Read_Plugins with list: ".join(',',@PluginsToLoad)); }
1835 foreach my $plugininfo (@PluginsToLoad) {
1836 my ($pluginfile,$pluginparam)=split(/\s+/,$plugininfo,2);
1837 $pluginfile =~ s/\.pm$//i;
1838 $pluginfile =~ /([^\/\\]+)$/;
1839 my $pluginname=$1; # pluginname is pluginfile without any path
1840 # Check if plugin is not disabled
1841 if ($NoLoadPlugin{$pluginname} && $NoLoadPlugin{$pluginname} > 0) {
1842 if ($Debug) { debug(" Plugin load for '$pluginfile' has been disabled from parameters"); }
1843 next;
1844 }
1845 if ($pluginname) {
1846 if (! $PluginsLoaded{'init'}{"$pluginname"}) { # Plugin not already loaded
1847 my %pluginisfor=('timehires'=>'u','ipv6'=>'u','hashfiles'=>'u','geoip'=>'u','geoipfree'=>'u',
1848 'geoip_region_maxmind'=>'mou','timezone'=>'ou',
1849 rizwank 1.1 'decodeutfkeys'=>'o','hostinfo'=>'o','rawlog'=>'o','userinfo'=>'o','urlalias'=>'o','tooltips'=>'o');
1850 if ($pluginisfor{$pluginname}) { # If it's a known plugin, may be we don't need to load it
1851 # Do not load "menu handler plugins" if output only and mainleft frame
1852 if (! $UpdateStats && scalar keys %HTMLOutput && $FrameName eq 'mainleft' && $pluginisfor{$pluginname} !~ /m/) { $PluginsLoaded{'init'}{"$pluginname"}=1; next; }
1853 # Do not load "update plugins" if output only
1854 if (! $UpdateStats && scalar keys %HTMLOutput && $pluginisfor{$pluginname} !~ /o/) { $PluginsLoaded{'init'}{"$pluginname"}=1; next; }
1855 # Do not load "output plugins" if update only
1856 if ($UpdateStats && ! scalar keys %HTMLOutput && $pluginisfor{$pluginname} !~ /u/) { $PluginsLoaded{'init'}{"$pluginname"}=1; next; }
1857 }
1858 # Load plugin
1859 foreach my $dir (@PossiblePluginsDir) {
1860 my $searchdir=$dir;
1861 if ($searchdir && (!($searchdir =~ /\/$/)) && (!($searchdir =~ /\\$/)) ) { $searchdir .= "/"; }
1862 my $pluginpath="${searchdir}${pluginfile}.pm";
1863 if (-s "$pluginpath") {
1864 $PluginDir="${searchdir}"; # Set plugin dir
1865 if ($Debug) { debug(" Try to init plugin '$pluginname' ($pluginpath) with param '$pluginparam'",1); }
1866 if (! $DirAddedInINC{"$dir"}) {
1867 push @INC, "$dir";
1868 $DirAddedInINC{"$dir"}=1;
1869 }
1870 rizwank 1.1 my $loadret=0;
1871 my $modperl=$ENV{"MOD_PERL"}? eval { require mod_perl; $mod_perl::VERSION >= 1.99 ? 2 : 1 } : 0;
1872 if ($modperl == 2) { $loadret=require "$pluginpath"; }
1873 else { $loadret=require "$pluginfile.pm"; }
1874 if (! $loadret || $loadret =~ /^error/i) {
1875 # Load failed, we stop here
1876 error("Plugin load for plugin '$pluginname' failed with return code: $loadret");
1877 }
1878 my $ret; # To get init return
1879 my $initfunction="\$ret=Init_$pluginname('$pluginparam')";
1880 my $initret=eval("$initfunction");
1881 if ($initret eq 'xxx') { $initret='Error: The PluginHooksFunctions variable defined in plugin file does not contain list of hooked functions'; }
1882 if (! $initret || $initret =~ /^error/i) {
1883 # Init function failed, we stop here
1884 error("Plugin init for plugin '$pluginname' failed with return code: ".($initret?"$initret":"$@ (A module required by plugin might be missing)."));
1885 }
1886 # Plugin load and init successfull
1887 foreach my $elem (split(/\s+/,$initret)) {
1888 # Some functions can only be plugged once
1889 my @uniquefunc=('GetCountryCodeByName','GetCountryCodeByAddr','ChangeTime','GetTimeZoneTitle','GetTime','SearchFile','LoadCache','SaveHash','ShowMenu');
1890 my $isuniquefunc=0;
1891 rizwank 1.1 foreach my $function (@uniquefunc) {
1892 if ("$elem" eq "$function") {
1893 # We try to load a 'unique' function, so we check and stop if already loaded
1894 foreach my $otherpluginname (keys %{$PluginsLoaded{"$elem"}}) {
1895 error("Conflict between plugin '$pluginname' and '$otherpluginname'. They both implements the 'must be unique' function '$elem'.\nYou must choose between one of them. Using together is not possible.");
1896 }
1897 $isuniquefunc=1;
1898 last;
1899 }
1900 }
1901 if ($isuniquefunc) {
1902 # TODO Use $PluginsLoaded{"$elem"}="$pluginname"; for unique func
1903 $PluginsLoaded{"$elem"}{"$pluginname"}=1;
1904 }
1905 else { $PluginsLoaded{"$elem"}{"$pluginname"}=1; }
1906 if ("$elem" =~ /SectionInitHashArray/) { $AtLeastOneSectionPlugin=1; }
1907 }
1908 $PluginsLoaded{'init'}{"$pluginname"}=1;
1909 if ($Debug) { debug(" Plugin '$pluginname' now hooks functions '$initret'",1); }
1910 last;
1911 }
1912 rizwank 1.1 }
1913 if (! $PluginsLoaded{'init'}{"$pluginname"}) {
1914 error("AWStats config file contains a directive to load plugin \"$pluginname\" (LoadPlugin=\"$plugininfo\") but AWStats can't open plugin file \"$pluginfile.pm\" for read.\nCheck if file is in \"".($PossiblePluginsDir[0])."\" directory and is readable.");
1915 }
1916 }
1917 else {
1918 warning("Warning: Tried to load plugin \"$pluginname\" twice. Fix config file.");
1919 }
1920 }
1921 else {
1922 error("Plugin \"$pluginfile\" is not a valid plugin name.");
1923 }
1924 }
1925 # In output mode, geo ip plugins are not loaded, so message changes are done here (can't be done in plugin init function)
1926 if ($PluginsLoaded{'init'}{'geoip'} || $PluginsLoaded{'init'}{'geoipfree'}) { $Message[17]=$Message[25]=$Message[148]; }
1927 }
1928
1929 #------------------------------------------------------------------------------
1930 # Function: Read history file and create/update tmp history file
1931 # Parameters: year,month,withupdate,withpurge,part_to_load[,lastlinenb,lastlineoffset,lastlinechecksum]
1932 # Input: $DirData $PROG $FileSuffix $LastLine
1933 rizwank 1.1 # Output: None
1934 # Return: Tmp history file name created/updated or '' if withupdate is 0
1935 #------------------------------------------------------------------------------
1936 sub Read_History_With_TmpUpdate {
1937
1938 my $year=sprintf("%04i",shift||0);
1939 my $month=sprintf("%02i",shift||0);
1940 my $withupdate=shift||0;
1941 my $withpurge=shift||0;
1942 my $part=shift||'';
1943
1944 my $xml=($BuildHistoryFormat eq 'xml'?1:0);
1945 my $xmleb='</table><nu>'; my $xmlrb='<tr><td>';
1946
1947 my $lastlinenb=shift||0;
1948 my $lastlineoffset=shift||0;
1949 my $lastlinechecksum=shift||0;
1950
1951 my %allsections=('general'=>1,'misc'=>2,'time'=>3,'visitor'=>4,'day'=>5,
1952 'domain'=>6,'cluster'=>7,'login'=>8,'robot'=>9,'worms'=>10,'emailsender'=>11,'emailreceiver'=>12,
1953 'session'=>13,'sider'=>14,'filetypes'=>15,
1954 rizwank 1.1 'os'=>16,'browser'=>17,'screensize'=>18,'unknownreferer'=>19,'unknownrefererbrowser'=>20,
1955 'origin'=>21,'sereferrals'=>22,'pagerefs'=>23,
1956 'searchwords'=>24,'keywords'=>25,
1957 'errors'=>26);
1958 my $order=(scalar keys %allsections)+1;
1959 foreach (keys %TrapInfosForHTTPErrorCodes) { $allsections{"sider_$_"}=$order++; }
1960 foreach (1..@ExtraName-1) { $allsections{"extra_$_"}=$order++; }
1961 foreach (keys %{$PluginsLoaded{'SectionInitHashArray'}}) { $allsections{"plugin_$_"}=$order++; }
1962 my $withread=0;
1963
1964 # Variable used to read old format history files
1965 my $readvisitorforbackward=0;
1966
1967 # In standard use of AWStats, the DayRequired variable is always empty
1968 if ($DayRequired) { if ($Debug) { debug("Call to Read_History_With_TmpUpdate [$year,$month,withupdate=$withupdate,withpurge=$withpurge,part=$part,lastlinenb=$lastlinenb,lastlineoffset=$lastlineoffset,lastlinechecksum=$lastlinechecksum] ($DayRequired)"); } }
1969 else { if ($Debug) { debug("Call to Read_History_With_TmpUpdate [$year,$month,withupdate=$withupdate,withpurge=$withpurge,part=$part,lastlinenb=$lastlinenb,lastlineoffset=$lastlineoffset,lastlinechecksum=$lastlinechecksum]"); } }
1970
1971 # Define SectionsToLoad (which sections to load)
1972 my %SectionsToLoad = ();
1973 if ($part eq 'all') { # Load all needed sections
1974 my $order=1;
1975 rizwank 1.1 $SectionsToLoad{'general'}=$order++;
1976 # When
1977 $SectionsToLoad{'time'}=$order++; # Always loaded because needed to count TotalPages, TotalHits, TotalBandwidth
1978 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowHostsStats) || $HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'} || $HTMLOutput{'unknownip'}) { $SectionsToLoad{'visitor'}=$order++; } # Must be before day, sider and session section
1979 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && ($ShowDaysOfWeekStats || $ShowDaysOfMonthStats)) || $HTMLOutput{'alldays'}) { $SectionsToLoad{'day'}=$order++; }
1980 # Who
1981 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowDomainsStats) || $HTMLOutput{'alldomains'}) { $SectionsToLoad{'domain'}=$order++; }
1982 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowAuthenticatedUsers) || $HTMLOutput{'alllogins'} || $HTMLOutput{'lastlogins'}) { $SectionsToLoad{'login'}=$order++; }
1983 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowRobotsStats) || $HTMLOutput{'allrobots'} || $HTMLOutput{'lastrobots'}) { $SectionsToLoad{'robot'}=$order++; }
1984 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowWormsStats) || $HTMLOutput{'allworms'} || $HTMLOutput{'lastworms'}) { $SectionsToLoad{'worms'}=$order++; }
1985 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowEMailSenders) || $HTMLOutput{'allemails'} || $HTMLOutput{'lastemails'}) { $SectionsToLoad{'emailsender'}=$order++; }
1986 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowEMailReceivers) || $HTMLOutput{'allemailr'} || $HTMLOutput{'lastemailr'}) { $SectionsToLoad{'emailreceiver'}=$order++; }
1987 # Navigation
1988 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowSessionsStats) || $HTMLOutput{'sessions'}) { $SectionsToLoad{'session'}=$order++; }
1989 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowPagesStats) || $HTMLOutput{'urldetail'} || $HTMLOutput{'urlentry'} || $HTMLOutput{'urlexit'}) { $SectionsToLoad{'sider'}=$order++; }
1990 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowFileTypesStats) || $HTMLOutput{'filetypes'}) { $SectionsToLoad{'filetypes'}=$order++; }
1991 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowOSStats) || $HTMLOutput{'osdetail'}) { $SectionsToLoad{'os'}=$order++; }
1992 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowBrowsersStats) || $HTMLOutput{'browserdetail'}) { $SectionsToLoad{'browser'}=$order++; }
1993 if ($UpdateStats || $MigrateStats || $HTMLOutput{'unknownos'}) { $SectionsToLoad{'unknownreferer'}=$order++; }
1994 if ($UpdateStats || $MigrateStats || $HTMLOutput{'unknownbrowser'}) { $SectionsToLoad{'unknownrefererbrowser'}=$order++; }
1995 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowScreenSizeStats)) { $SectionsToLoad{'screensize'}=$order++; }
1996 rizwank 1.1 # Referers
1997 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowOriginStats) || $HTMLOutput{'origin'}) { $SectionsToLoad{'origin'}=$order++; }
1998 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowOriginStats) || $HTMLOutput{'refererse'}) { $SectionsToLoad{'sereferrals'}=$order++; }
1999 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowOriginStats) || $HTMLOutput{'refererpages'}) { $SectionsToLoad{'pagerefs'}=$order++; }
2000 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowKeyphrasesStats) || $HTMLOutput{'keyphrases'} || $HTMLOutput{'keywords'}) { $SectionsToLoad{'searchwords'}=$order++; }
2001 if (! $withupdate && $HTMLOutput{'main'} && $ShowKeywordsStats) { $SectionsToLoad{'keywords'}=$order++; } # If we update, dont need to load
2002 # Others
2003 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowMiscStats)) { $SectionsToLoad{'misc'}=$order++; }
2004 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && ($ShowHTTPErrorsStats || $ShowSMTPErrorsStats)) || $HTMLOutput{'errors'}) { $SectionsToLoad{'errors'}=$order++; }
2005 foreach (keys %TrapInfosForHTTPErrorCodes) {
2006 if ($UpdateStats || $MigrateStats || $HTMLOutput{"errors$_"}) { $SectionsToLoad{"sider_$_"}=$order++; }
2007 }
2008 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowClusterStats)) { $SectionsToLoad{'cluster'}=$order++; }
2009 foreach (1..@ExtraName-1) {
2010 if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ExtraStatTypes[$_]) || $HTMLOutput{"extra$_"}) { $SectionsToLoad{"extra_$_"}=$order++; }
2011 }
2012 foreach (keys %{$PluginsLoaded{'SectionInitHashArray'}}) {
2013 if ($UpdateStats || $MigrateStats || $HTMLOutput{"plugin_$_"}) { $SectionsToLoad{"plugin_$_"}=$order++; }
2014 }
2015 }
2016 else { # Load only required sections
2017 rizwank 1.1 my $order=1;
2018 foreach (split(/\s+/,$part)) { $SectionsToLoad{$_}=$order++; }
2019 }
2020
2021 # Define SectionsToSave (which sections to save)
2022 my %SectionsToSave = ();
2023 if ($withupdate) { %SectionsToSave=%allsections; }
2024
2025 if ($Debug) {
2026 debug(" List of sections marked for load : ".join(' ',(sort { $SectionsToLoad{$a} <=> $SectionsToLoad{$b} } keys %SectionsToLoad)),2);
2027 debug(" List of sections marked for save : ".join(' ',(sort { $SectionsToSave{$a} <=> $SectionsToSave{$b} } keys %SectionsToSave)),2);
2028 }
2029
2030 # Define value for filetowrite and filetoread (Month before Year kept for backward compatibility)
2031 my $filetowrite='';
2032 my $filetoread='';
2033 if ($HistoryAlreadyFlushed{"$year$month"} && -s "$DirData/$PROG$month$year$FileSuffix.tmp.$$") {
2034 # tmp history file was already flushed
2035 $filetoread="$DirData/$PROG$month$year$FileSuffix.tmp.$$";
2036 $filetowrite="$DirData/$PROG$month$year$FileSuffix.tmp.$$.bis";
2037 }
2038 rizwank 1.1 else {
2039 $filetoread="$DirData/$PROG$DayRequired$month$year$FileSuffix.txt";
2040 $filetowrite="$DirData/$PROG$month$year$FileSuffix.tmp.$$";
2041 }
2042 if ($Debug) { debug(" History file to read is '$filetoread'",2); }
2043
2044 # Is there an old data file to read or, if migrate, can we open the file for read
2045 if (-s $filetoread || $MigrateStats) { $withread=1; }
2046
2047 # Open files
2048 if ($withread) {
2049 open(HISTORY,$filetoread) || error("Couldn't open file \"$filetoread\" for read: $!","","",$MigrateStats);
2050 binmode HISTORY; # Avoid premature EOF due to history files corrupted with \cZ or bin chars
2051 }
2052 if ($withupdate) {
2053 open(HISTORYTMP,">$filetowrite") || error("Couldn't open file \"$filetowrite\" for write: $!");
2054 binmode HISTORYTMP;
2055 if ($xml) { print HISTORYTMP "<xml>\n\n"; }
2056 Save_History("header",$year,$month);
2057 }
2058
2059 rizwank 1.1 # Loop on read file
2060 my $xmlold=0;
2061 if ($withread) {
2062 my $countlines=0;
2063 my $versionnum=0;
2064 my @field=();
2065 while (<HISTORY>) {
2066 chomp $_; s/\r//;
2067 $countlines++;
2068
2069 # Test if it's xml
2070 if (! $xmlold && $_ =~ /^<xml/) {
2071 $xmlold=1;
2072 if ($Debug) { debug(" Data file format is 'xml'",1); }
2073 next;
2074 }
2075
2076 # Extract version from first line
2077 if (! $versionnum && $_ =~ /^AWSTATS DATA FILE (\d+).(\d+)/i) {
2078 $versionnum=($1*1000)+$2;
2079 if ($Debug) { debug(" Data file version is $versionnum",1); }
2080 rizwank 1.1 next;
2081 }
2082
2083 # Analyze fields
2084 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_));
2085 if (! $field[0]) { next; }
2086
2087 # Here version MUST be defined, or file will be processed as an old data file
2088
2089 # BEGIN_GENERAL
2090 # TODO Manage GENERAL in a loop like other sections. Need to return error if data file version < 5000 (no END_GENERAL) to say that history files < 5.0 can't be used
2091 if ($field[0] eq 'BEGIN_GENERAL') {
2092 if ($Debug) { debug(" Begin of GENERAL section"); }
2093 next;
2094 }
2095 if ($field[0] eq 'LastLine' || $field[0] eq "${xmlrb}LastLine") {
2096 if (! $LastLine || $LastLine < int($field[1])) { $LastLine=int($field[1]); };
2097 if ($field[2]) { $LastLineNumber=int($field[2]); }
2098 if ($field[3]) { $LastLineOffset=int($field[3]); }
2099 if ($field[4]) { $LastLineChecksum=int($field[4]); }
2100 next;
2101 rizwank 1.1 }
2102 if ($field[0] eq 'FirstTime' || $field[0] eq "${xmlrb}FirstTime") { if (! $FirstTime{$year.$month} || $FirstTime{$year.$month} > int($field[1])) { $FirstTime{$year.$month}=int($field[1]); }; next; }
2103 if ($field[0] eq 'LastTime' || $field[0] eq "${xmlrb}LastTime") { if (! $LastTime{$year.$month} || $LastTime{$year.$month} < int($field[1])) { $LastTime{$year.$month}=int($field[1]); }; next; }
2104 if ($field[0] eq 'LastUpdate' || $field[0] eq "${xmlrb}LastUpdate") {
2105 if ($LastUpdate < $field[1]) {
2106 $LastUpdate=int($field[1]);
2107 #$LastUpdateLinesRead=int($field[2]);
2108 #$LastUpdateNewLinesRead=int($field[3]);
2109 #$LastUpdateLinesCorrupted=int($field[4]);
2110 };
2111 next;
2112 }
2113 if ($field[0] eq 'TotalVisits' || $field[0] eq "${xmlrb}TotalVisits") {
2114 if (! $withupdate) { $MonthVisits{$year.$month}+=int($field[1]); }
2115 # Save in MonthVisits also if migrate from a file < 4.x for backward compatibility
2116 if ($MigrateStats && $versionnum < 4000 && ! $MonthVisits{$year.$month}) {
2117 if ($Debug) { debug("File is version < 4000. We save ".int($field[1])." visits in DayXxx arrays",1); }
2118 $DayHits{$year.$month."00"}+=0;
2119 $DayVisits{$year.$month."00"}+=int($field[1]);
2120 }
2121 next;
2122 rizwank 1.1 }
2123 if ($field[0] eq 'TotalUnique' || $field[0] eq "${xmlrb}TotalUnique") { if (! $withupdate) { $MonthUnique{$year.$month}+=int($field[1]); } next; }
2124 if ($field[0] eq 'MonthHostsKnown' || $field[0] eq "${xmlrb}MonthHostsKnown") { if (! $withupdate) { $MonthHostsKnown{$year.$month}+=int($field[1]); } next; }
2125 if ($field[0] eq 'MonthHostsUnknown' || $field[0] eq "${xmlrb}MonthHostsUnknown") { if (! $withupdate) { $MonthHostsUnknown{$year.$month}+=int($field[1]); } next; }
2126 if (($field[0] eq 'END_GENERAL' || $field[0] eq "${xmleb}END_GENERAL") # END_GENERAL didn't exist for history files < 5.0
2127 || ($versionnum < 5000 && $SectionsToLoad{"general"} && $FirstTime{$year.$month} && $LastTime{$year.$month}) ) {
2128 if ($Debug) { debug(" End of GENERAL section"); }
2129 # Show migrate warning for backward compatibility
2130 if ($versionnum < 5000 && ! $MigrateStats && ! $BadFormatWarning{$year.$month}) {
2131 if ($FrameName ne 'mainleft') {
2132 $BadFormatWarning{$year.$month}=1;
2133 my $message="Warning: Data file '$filetoread' has an old history file format (version $versionnum). You should upgrade it...\nFrom command line: $PROG.$Extension -migrate=\"$filetoread\"";
2134 if ($ENV{'GATEWAY_INTERFACE'} && $AllowToUpdateStatsFromBrowser) { $message.="\nFrom your browser with URL: <a href=\"http://".$ENV{"SERVER_NAME"}.$ENV{"SCRIPT_NAME"}."?migrate=$filetoread\">http://".$ENV{"SERVER_NAME"}.$ENV{"SCRIPT_NAME"}."?migrate=$filetoread</a>"; }
2135 warning("$message");
2136 }
2137 }
2138 if (! ($versionnum < 5000) && $MigrateStats && ! $BadFormatWarning{$year.$month}) {
2139 $BadFormatWarning{$year.$month}=1;
2140 warning("Warning: You are migrating a file that is already a recent version (migrate not required for files version $versionnum).","","",1);
2141 }
2142 # If migrate and version < 4.x we need to include BEGIN_UNKNOWNIP into BEGIN_VISITOR for backward compatibility
2143 rizwank 1.1 if ($MigrateStats && $versionnum < 4000) {
2144 if ($Debug) { debug("File is version < 4000. We add UNKNOWNIP in sections to load",1); }
2145 $SectionsToLoad{'unknownip'}=99;
2146 }
2147
2148 delete $SectionsToLoad{'general'};
2149 if ($SectionsToSave{'general'}) { Save_History('general',$year,$month,$lastlinenb,$lastlineoffset,$lastlinechecksum); delete $SectionsToSave{'general'}; }
2150
2151 # Test for backward compatibility
2152 if ($versionnum < 5000 && ! $withupdate) {
2153 # We must find another way to init MonthUnique MonthHostsKnown and MonthHostsUnknown
2154 if ($Debug) { debug(" We ask to count MonthUnique, MonthHostsKnown and MonthHostsUnknown in visitor section because they are not stored in general section for this data file (version $versionnum)."); }
2155 $readvisitorforbackward=($SectionsToLoad{"visitor"}?1:2);
2156 $SectionsToLoad{"visitor"}=4;
2157 }
2158 else {
2159 if (! scalar %SectionsToLoad) {
2160 if ($Debug) { debug(" Stop reading history file. Got all we need."); }
2161 last;
2162 }
2163 }
2164 rizwank 1.1 if ($versionnum >= 5000) { next; } # We can forget 'END_GENERAL' line and read next one
2165 }
2166
2167 # BEGIN_MISC
2168 if ($field[0] eq 'BEGIN_MISC') {
2169 if ($Debug) { debug(" Begin of MISC section"); }
2170 $field[0]='';
2171 my $count=0;my $countloaded=0;
2172 do {
2173 if ($field[0]) {
2174 $count++;
2175 if ($SectionsToLoad{'misc'}) {
2176 $countloaded++;
2177 if ($field[1]) { $_misc_p{$field[0]}+=int($field[1]); }
2178 if ($field[2]) { $_misc_h{$field[0]}+=int($field[2]); }
2179 if ($field[3]) { $_misc_k{$field[0]}+=int($field[3]); }
2180 }
2181 }
2182 $_=<HISTORY>;
2183 chomp $_; s/\r//;
2184 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2185 rizwank 1.1 }
2186 until ($field[0] eq 'END_MISC' || $field[0] eq "${xmleb}END_MISC" || ! $_);
2187 if ($field[0] ne 'END_MISC' && $field[0] ne "${xmleb}END_MISC") { error("History file \"$filetoread\" is corrupted (End of section MISC not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2188 if ($Debug) { debug(" End of MISC section ($count entries, $countloaded loaded)"); }
2189 delete $SectionsToLoad{'misc'};
2190 if ($SectionsToSave{'misc'}) {
2191 Save_History('misc',$year,$month); delete $SectionsToSave{'misc'};
2192 if ($withpurge) { %_misc_p=(); %_misc_h=(); %_misc_k=(); }
2193 }
2194 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2195 next;
2196 }
2197
2198 # BEGIN_CLUSTER
2199 if ($field[0] eq 'BEGIN_CLUSTER') {
2200 if ($Debug) { debug(" Begin of CLUSTER section"); }
2201 $field[0]='';
2202 my $count=0;my $countloaded=0;
2203 do {
2204 if ($field[0]) {
2205 $count++;
2206 rizwank 1.1 if ($SectionsToLoad{'cluster'}) {
2207 $countloaded++;
2208 if ($field[1]) { $_cluster_p{$field[0]}+=int($field[1]); }
2209 if ($field[2]) { $_cluster_h{$field[0]}+=int($field[2]); }
2210 if ($field[3]) { $_cluster_k{$field[0]}+=int($field[3]); }
2211 }
2212 }
2213 $_=<HISTORY>;
2214 chomp $_; s/\r//;
2215 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2216 }
2217 until ($field[0] eq 'END_CLUSTER' || $field[0] eq "${xmleb}END_CLUSTER" || ! $_);
2218 if ($field[0] ne 'END_CLUSTER' && $field[0] ne "${xmleb}END_CLUSTER") { error("History file \"$filetoread\" is corrupted (End of section CLUSTER not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2219 if ($Debug) { debug(" End of CLUSTER section ($count entries, $countloaded loaded)"); }
2220 delete $SectionsToLoad{'cluster'};
2221 if ($SectionsToSave{'cluster'}) {
2222 Save_History('cluster',$year,$month); delete $SectionsToSave{'cluster'};
2223 if ($withpurge) { %_cluster_p=(); %_cluster_h=(); %_cluster_k=(); }
2224 }
2225 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2226 next;
2227 rizwank 1.1 }
2228
2229 # BEGIN_TIME
2230 if ($field[0] eq 'BEGIN_TIME') {
2231 my $monthpages=0;my $monthhits=0;my $monthbytes=0;
2232 my $monthnotviewedpages=0;my $monthnotviewedhits=0;my $monthnotviewedbytes=0;
2233 if ($Debug) { debug(" Begin of TIME section"); }
2234 $field[0]='';
2235 my $count=0;my $countloaded=0;
2236 do {
2237 if ($field[0] ne '') { # Test on ne '' because field[0] is '0' for hour 0)
2238 $count++;
2239 if ($SectionsToLoad{'time'}) {
2240 if ($withupdate || $MonthRequired eq 'all' || $MonthRequired eq "$month") { # Still required
2241 $countloaded++;
2242 if ($field[1]) { $_time_p[$field[0]]+=int($field[1]); }
2243 if ($field[2]) { $_time_h[$field[0]]+=int($field[2]); }
2244 if ($field[3]) { $_time_k[$field[0]]+=int($field[3]); }
2245 if ($field[4]) { $_time_nv_p[$field[0]]+=int($field[4]); }
2246 if ($field[5]) { $_time_nv_h[$field[0]]+=int($field[5]); }
2247 if ($field[6]) { $_time_nv_k[$field[0]]+=int($field[6]); }
2248 rizwank 1.1 }
2249 $monthpages+=int($field[1]);
2250 $monthhits+=int($field[2]);
2251 $monthbytes+=int($field[3]);
2252 $monthnotviewedpages+=int($field[4]||0);
2253 $monthnotviewedhits+=int($field[5]||0);
2254 $monthnotviewedbytes+=int($field[6]||0);
2255 }
2256 }
2257 $_=<HISTORY>;
2258 chomp $_; s/\r//;
2259 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2260 }
2261 until ($field[0] eq 'END_TIME' || $field[0] eq "${xmleb}END_TIME" || ! $_);
2262 if ($field[0] ne 'END_TIME' && $field[0] ne "${xmleb}END_TIME") { error("History file \"$filetoread\" is corrupted (End of section TIME not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2263 if ($Debug) { debug(" End of TIME section ($count entries, $countloaded loaded)"); }
2264 $MonthPages{$year.$month}+=$monthpages;
2265 $MonthHits{$year.$month}+=$monthhits;
2266 $MonthBytes{$year.$month}+=$monthbytes;
2267 $MonthNotViewedPages{$year.$month}+=$monthnotviewedpages;
2268 $MonthNotViewedHits{$year.$month}+=$monthnotviewedhits;
2269 rizwank 1.1 $MonthNotViewedBytes{$year.$month}+=$monthnotviewedbytes;
2270 delete $SectionsToLoad{'time'};
2271 if ($SectionsToSave{'time'}) {
2272 Save_History('time',$year,$month); delete $SectionsToSave{'time'};
2273 if ($withpurge) { @_time_p=(); @_time_h=(); @_time_k=(); @_time_nv_p=(); @_time_nv_h=(); @_time_nv_k=(); }
2274 }
2275 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2276 next;
2277 }
2278
2279 # BEGIN_ORIGIN
2280 if ($field[0] eq 'BEGIN_ORIGIN') {
2281 if ($Debug) { debug(" Begin of ORIGIN section"); }
2282 $field[0]='';
2283 my $count=0;my $countloaded=0;
2284 do {
2285 if ($field[0]) {
2286 $count++;
2287 if ($SectionsToLoad{'origin'}) {
2288 if ($field[0] eq 'From0') { $_from_p[0]+=$field[1]; $_from_h[0]+=$field[2]; }
2289 elsif ($field[0] eq 'From1') { $_from_p[1]+=$field[1]; $_from_h[1]+=$field[2]; }
2290 rizwank 1.1 elsif ($field[0] eq 'From2') { $_from_p[2]+=$field[1]; $_from_h[2]+=$field[2]; }
2291 elsif ($field[0] eq 'From3') { $_from_p[3]+=$field[1]; $_from_h[3]+=$field[2]; }
2292 elsif ($field[0] eq 'From4') { $_from_p[4]+=$field[1]; $_from_h[4]+=$field[2]; }
2293 elsif ($field[0] eq 'From5') { $_from_p[5]+=$field[1]; $_from_h[5]+=$field[2]; }
2294 }
2295 }
2296 $_=<HISTORY>;
2297 chomp $_; s/\r//;
2298 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2299 }
2300 until ($field[0] eq 'END_ORIGIN' || $field[0] eq "${xmleb}END_ORIGIN" || ! $_);
2301 if ($field[0] ne 'END_ORIGIN' && $field[0] ne "${xmleb}END_ORIGIN") { error("History file \"$filetoread\" is corrupted (End of section ORIGIN not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2302 if ($Debug) { debug(" End of ORIGIN section ($count entries, $countloaded loaded)"); }
2303 delete $SectionsToLoad{'origin'};
2304 if ($SectionsToSave{'origin'}) {
2305 Save_History('origin',$year,$month); delete $SectionsToSave{'origin'};
2306 if ($withpurge) { @_from_p=(); @_from_h=(); }
2307 }
2308 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2309 next;
2310 }
2311 rizwank 1.1 # BEGIN_DAY
2312 if ($field[0] eq 'BEGIN_DAY') {
2313 if ($Debug) { debug(" Begin of DAY section"); }
2314 $field[0]='';
2315 my $count=0;my $countloaded=0;
2316 do {
2317 if ($field[0]) {
2318 $count++;
2319 if ($SectionsToLoad{'day'}) {
2320 $countloaded++;
2321 if ($field[1]) { $DayPages{$field[0]}+=int($field[1]); }
2322 $DayHits{$field[0]}+=int($field[2]); # DayHits always load (should be >0 and if not it's a day YYYYMM00 resulting of an old file migration)
2323 if ($field[3]) { $DayBytes{$field[0]}+=int($field[3]); }
2324 if ($field[4]) { $DayVisits{$field[0]}+=int($field[4]); }
2325 }
2326 }
2327 $_=<HISTORY>;
2328 chomp $_; s/\r//;
2329 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2330 }
2331 until ($field[0] eq 'END_DAY' || $field[0] eq "${xmleb}END_DAY" || ! $_);
2332 rizwank 1.1 if ($field[0] ne 'END_DAY' && $field[0] ne "${xmleb}END_DAY") { error("History file \"$filetoread\" is corrupted (End of section DAY not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2333 if ($Debug) { debug(" End of DAY section ($count entries, $countloaded loaded)"); }
2334 delete $SectionsToLoad{'day'};
2335 # WE DO NOT SAVE SECTION NOW BECAUSE VALUES CAN BE CHANGED AFTER READING VISITOR
2336 #if ($SectionsToSave{'day'}) { # Must be made after read of visitor
2337 # Save_History('day',$year,$month); delete $SectionsToSave{'day'};
2338 # if ($withpurge) { %DayPages=(); %DayHits=(); %DayBytes=(); %DayVisits=(); }
2339 #}
2340 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2341 next;
2342 }
2343 # BEGIN_VISITOR
2344 if ($field[0] eq 'BEGIN_VISITOR') {
2345 if ($Debug) { debug(" Begin of VISITOR section"); }
2346 $field[0]='';
2347 my $count=0;my $countloaded=0;
2348 do {
2349 if ($field[0]) {
2350 $count++;
2351
2352 # For backward compatibility
2353 rizwank 1.1 if ($readvisitorforbackward) {
2354 if ($field[1]) { $MonthUnique{$year.$month}++; }
2355 if ($MonthRequired ne 'all') {
2356 if ($field[0] !~ /^\d+\.\d+\.\d+\.\d+$/ && $field[0] !~ /^[0-9A-F]*:/i) { $MonthHostsKnown{$year.$month}++; }
2357 else { $MonthHostsUnknown{$year.$month}++; }
2358 }
2359 }
2360
2361 # Process data saved in 'wait' arrays
2362 if ($withupdate && $_waithost_e{$field[0]}){
2363 my $timehostl=int($field[4]||0);
2364 my $timehosts=int($field[5]||0);
2365 my $newtimehosts=($_waithost_s{$field[0]}?$_waithost_s{$field[0]}:$_host_s{$field[0]});
2366 my $newtimehostl=($_waithost_l{$field[0]}?$_waithost_l{$field[0]}:$_host_l{$field[0]});
2367 if ($newtimehosts > $timehostl + $VISITTIMEOUT ) {
2368 if ($Debug) { debug(" Visit for $field[0] in 'wait' arrays is a new visit different than last in history",4); }
2369 if ($field[6]) { $_url_x{$field[6]}++; }
2370 $_url_e{$_waithost_e{$field[0]}}++;
2371 $newtimehosts =~ /^(\d\d\d\d\d\d\d\d)/; $DayVisits{$1}++;
2372 if ($timehosts && $timehostl) { $_session{GetSessionRange($timehosts,$timehostl)}++; }
2373 if ($_waithost_s{$field[0]}) {
2374 rizwank 1.1 # First session found in log was followed by another one so it's finished
2375 $_session{GetSessionRange($newtimehosts,$newtimehostl)}++;
2376 }
2377 # Here $_host_l $_host_s and $_host_u are correctly defined
2378 }
2379 else {
2380 if ($Debug) { debug(" Visit for $field[0] in 'wait' arrays is following of last visit in history",4); }
2381 if ($_waithost_s{$field[0]}) {
2382 # First session found in log was followed by another one so it's finished
2383 $_session{GetSessionRange(MinimumButNoZero($timehosts,$newtimehosts),$timehostl>$newtimehostl?$timehostl:$newtimehostl)}++;
2384 # Here $_host_l $_host_s and $_host_u are correctly defined
2385 }
2386 else {
2387 # We correct $_host_l $_host_s and $_host_u
2388 if ($timehostl > $newtimehostl) {
2389 $_host_l{$field[0]}=$timehostl;
2390 $_host_u{$field[0]}=$field[6];
2391 }
2392 if ($timehosts < $newtimehosts) {
2393 $_host_s{$field[0]}=$timehosts;
2394 }
2395 rizwank 1.1 }
2396 }
2397 delete $_waithost_e{$field[0]};
2398 delete $_waithost_l{$field[0]};
2399 delete $_waithost_s{$field[0]};
2400 delete $_waithost_u{$field[0]};
2401 }
2402
2403 # Load records
2404 if ($readvisitorforbackward!=2 && $SectionsToLoad{'visitor'}) { # if readvisitorforbackward==2 we do not load
2405 my $loadrecord=0;
2406 if ($withupdate) {
2407 $loadrecord=1;
2408 }
2409 else {
2410 if ($HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'}) {
2411 if ((!$FilterIn{'host'} || $field[0] =~ /$FilterIn{'host'}/i)
2412 && (!$FilterEx{'host'} || $field[0] !~ /$FilterEx{'host'}/i)) { $loadrecord=1; }
2413 }
2414 elsif ($MonthRequired eq 'all' || $field[2] >= $MinHit{'Host'}) {
2415 if ($HTMLOutput{'unknownip'} && ($field[0] =~ /^\d+\.\d+\.\d+\.\d+$/ || $field[0] =~ /^[0-9A-F]*:/i)) { $loadrecord=1; }
2416 rizwank 1.1 elsif ($HTMLOutput{'main'} && ($MonthRequired eq 'all' || $countloaded < $MaxNbOf{'HostsShown'})) { $loadrecord=1; }
2417 }
2418 }
2419 if ($loadrecord) {
2420 if ($field[1]) { $_host_p{$field[0]}+=$field[1]; }
2421 if ($field[2]) { $_host_h{$field[0]}+=$field[2]; }
2422 if ($field[3]) { $_host_k{$field[0]}+=$field[3]; }
2423 if ($field[4] && ! $_host_l{$field[0]}) { # We save last connexion params if not previously defined
2424 $_host_l{$field[0]}=int($field[4]);
2425 if ($withupdate) { # field[5] field[6] are used only for update
2426 if ($field[5] && ! $_host_s{$field[0]}) { $_host_s{$field[0]}=int($field[5]); }
2427 if ($field[6] && ! $_host_u{$field[0]}) { $_host_u{$field[0]}=$field[6]; }
2428 }
2429 }
2430 $countloaded++;
2431 }
2432 }
2433 }
2434 $_=<HISTORY>;
2435 chomp $_; s/\r//;
2436 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2437 rizwank 1.1 }
2438 until ($field[0] eq 'END_VISITOR' || $field[0] eq "${xmleb}END_VISITOR" || ! $_);
2439 if ($field[0] ne 'END_VISITOR' && $field[0] ne "${xmleb}END_VISITOR") { error("History file \"$filetoread\" is corrupted (End of section VISITOR not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2440 if ($Debug) { debug(" End of VISITOR section ($count entries, $countloaded loaded)"); }
2441 delete $SectionsToLoad{'visitor'};
2442 # WE DO NOT SAVE SECTION NOW TO BE SURE TO HAVE THIS LARGE SECTION NOT AT THE BEGINNING OF FILE
2443 #if ($SectionsToSave{'visitor'}) {
2444 # Save_History('visitor',$year,$month); delete $SectionsToSave{'visitor'};
2445 # if ($withpurge) { %_host_p=(); %_host_h=(); %_host_k=(); %_host_l=(); %_host_s=(); %_host_u=(); }
2446 #}
2447 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2448 next;
2449 }
2450 # BEGIN_UNKNOWNIP for backward compatibility
2451 if ($field[0] eq 'BEGIN_UNKNOWNIP') {
2452 my %iptomigrate=();
2453 if ($Debug) { debug(" Begin of UNKNOWNIP section"); }
2454 $field[0]='';
2455 my $count=0;my $countloaded=0;
2456 do {
2457 if ($field[0]) {
2458 rizwank 1.1 $count++;
2459 if ($SectionsToLoad{'unknownip'}) {
2460 $iptomigrate{$field[0]}=$field[1]||0;
2461 $countloaded++;
2462 }
2463 }
2464 $_=<HISTORY>;
2465 chomp $_; s/\r//;
2466 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2467 }
2468 until ($field[0] eq 'END_UNKNOWNIP' || $field[0] eq "${xmleb}END_UNKNOWNIP" || ! $_);
2469 if ($field[0] ne 'END_UNKNOWNIP' && $field[0] ne "${xmleb}END_UNKNOWNIP") { error("History file \"$filetoread\" is corrupted (End of section UNKOWNIP not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2470 if ($Debug) { debug(" End of UNKOWNIP section ($count entries, $countloaded loaded)"); }
2471 delete $SectionsToLoad{'visitor'};
2472 # THIS SECTION IS NEVER SAVED. ONLY READ FOR MIGRATE AND CONVERTED INTO VISITOR SECTION
2473 foreach (keys %iptomigrate) {
2474 $_host_p{$_}+=int($_host_p{'Unknown'}/$countloaded);
2475 $_host_h{$_}+=int($_host_h{'Unknown'}/$countloaded);
2476 $_host_k{$_}+=int($_host_k{'Unknown'}/$countloaded);
2477 if ($iptomigrate{$_} > 0) { $_host_l{$_}=$iptomigrate{$_} };
2478 }
2479 rizwank 1.1 delete $_host_p{'Unknown'};
2480 delete $_host_h{'Unknown'};
2481 delete $_host_k{'Unknown'};
2482 delete $_host_l{'Unknown'};
2483 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2484 next;
2485 }
2486 # BEGIN_LOGIN
2487 if ($field[0] eq 'BEGIN_LOGIN') {
2488 if ($Debug) { debug(" Begin of LOGIN section"); }
2489 $field[0]='';
2490 my $count=0;my $countloaded=0;
2491 do {
2492 if ($field[0]) {
2493 $count++;
2494 if ($SectionsToLoad{'login'}) {
2495 $countloaded++;
2496 if ($field[1]) { $_login_p{$field[0]}+=$field[1]; }
2497 if ($field[2]) { $_login_h{$field[0]}+=$field[2]; }
2498 if ($field[3]) { $_login_k{$field[0]}+=$field[3]; }
2499 if (! $_login_l{$field[0]} && $field[4]) { $_login_l{$field[0]}=int($field[4]); }
2500 rizwank 1.1 }
2501 }
2502 $_=<HISTORY>;
2503 chomp $_; s/\r//;
2504 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2505 }
2506 until ($field[0] eq 'END_LOGIN' || $field[0] eq "${xmleb}END_LOGIN" || ! $_);
2507 if ($field[0] ne 'END_LOGIN' && $field[0] ne "${xmleb}END_LOGIN") { error("History file \"$filetoread\" is corrupted (End of section LOGIN not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2508 if ($Debug) { debug(" End of LOGIN section ($count entries, $countloaded loaded)"); }
2509 delete $SectionsToLoad{'login'};
2510 if ($SectionsToSave{'login'}) {
2511 Save_History('login',$year,$month); delete $SectionsToSave{'login'};
2512 if ($withpurge) { %_login_p=(); %_login_h=(); %_login_k=(); %_login_l=(); }
2513 }
2514 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2515 next;
2516 }
2517 # BEGIN_DOMAIN
2518 if ($field[0] eq 'BEGIN_DOMAIN') {
2519 if ($Debug) { debug(" Begin of DOMAIN section"); }
2520 $field[0]='';
2521 rizwank 1.1 my $count=0;my $countloaded=0;
2522 do {
2523 if ($field[0]) {
2524 $count++;
2525 if ($SectionsToLoad{'domain'}) {
2526 $countloaded++;
2527 if ($field[1]) { $_domener_p{$field[0]}+=$field[1]; }
2528 if ($field[2]) { $_domener_h{$field[0]}+=$field[2]; }
2529 if ($field[3]) { $_domener_k{$field[0]}+=$field[3]; }
2530 }
2531 }
2532 $_=<HISTORY>;
2533 chomp $_; s/\r//;
2534 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2535 }
2536 until ($field[0] eq 'END_DOMAIN' || $field[0] eq "${xmleb}END_DOMAIN" || ! $_);
2537 if ($field[0] ne 'END_DOMAIN' && $field[0] ne "${xmleb}END_DOMAIN") { error("History file \"$filetoread\" is corrupted (End of section DOMAIN not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2538 if ($Debug) { debug(" End of DOMAIN section ($count entries, $countloaded loaded)"); }
2539 delete $SectionsToLoad{'domain'};
2540 if ($SectionsToSave{'domain'}) {
2541 Save_History('domain',$year,$month); delete $SectionsToSave{'domain'};
2542 rizwank 1.1 if ($withpurge) { %_domener_p=(); %_domener_h=(); %_domener_k=(); }
2543 }
2544 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2545 next;
2546 }
2547 # BEGIN_SESSION
2548 if ($field[0] eq 'BEGIN_SESSION') {
2549 if ($Debug) { debug(" Begin of SESSION section"); }
2550 $field[0]='';
2551 my $count=0;my $countloaded=0;
2552 do {
2553 if ($field[0]) {
2554 $count++;
2555 if ($SectionsToLoad{'session'}) {
2556 $countloaded++;
2557 if ($field[1]) { $_session{$field[0]}+=$field[1]; }
2558 }
2559 }
2560 $_=<HISTORY>;
2561 chomp $_; s/\r//;
2562 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2563 rizwank 1.1 }
2564 until ($field[0] eq 'END_SESSION' || $field[0] eq "${xmleb}END_SESSION" || ! $_);
2565 if ($field[0] ne 'END_SESSION' && $field[0] ne "${xmleb}END_SESSION") { error("History file \"$filetoread\" is corrupted (End of section SESSION not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2566 if ($Debug) { debug(" End of SESSION section ($count entries, $countloaded loaded)"); }
2567 delete $SectionsToLoad{'session'};
2568 # WE DO NOT SAVE SECTION NOW BECAUSE VALUES CAN BE CHANGED AFTER READING VISITOR
2569 #if ($SectionsToSave{'session'}) {
2570 # Save_History('session',$year,$month); delete $SectionsToSave{'session'}; }
2571 # if ($withpurge) { %_session=(); }
2572 #}
2573 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2574 next;
2575 }
2576 # BEGIN_OS
2577 if ($field[0] eq 'BEGIN_OS') {
2578 if ($Debug) { debug(" Begin of OS section"); }
2579 $field[0]='';
2580 my $count=0;my $countloaded=0;
2581 do {
2582 if ($field[0]) {
2583 $count++;
2584 rizwank 1.1 if ($SectionsToLoad{'os'}) {
2585 $countloaded++;
2586 if ($field[1]) { $_os_h{$field[0]}+=$field[1]; }
2587 }
2588 }
2589 $_=<HISTORY>;
2590 chomp $_; s/\r//;
2591 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2592 }
2593 until ($field[0] eq 'END_OS' || $field[0] eq "${xmleb}END_OS" || ! $_);
2594 if ($field[0] ne 'END_OS' && $field[0] ne "${xmleb}END_OS") { error("History file \"$filetoread\" is corrupted (End of section OS not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2595 if ($Debug) { debug(" End of OS section ($count entries, $countloaded loaded)"); }
2596 delete $SectionsToLoad{'os'};
2597 if ($SectionsToSave{'os'}) {
2598 Save_History('os',$year,$month); delete $SectionsToSave{'os'};
2599 if ($withpurge) { %_os_h=(); }
2600 }
2601 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2602 next;
2603 }
2604 # BEGIN_BROWSER
2605 rizwank 1.1 if ($field[0] eq 'BEGIN_BROWSER') {
2606 if ($Debug) { debug(" Begin of BROWSER section"); }
2607 $field[0]='';
2608 my $count=0;my $countloaded=0;
2609 do {
2610 if ($field[0]) {
2611 $count++;
2612 if ($SectionsToLoad{'browser'}) {
2613 $countloaded++;
2614 if ($field[1]) { $_browser_h{$field[0]}+=$field[1]; }
2615 }
2616 }
2617 $_=<HISTORY>;
2618 chomp $_; s/\r//;
2619 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2620 }
2621 until ($field[0] eq 'END_BROWSER' || $field[0] eq "${xmleb}END_BROWSER" || ! $_);
2622 if ($field[0] ne 'END_BROWSER' && $field[0] ne "${xmleb}END_BROWSER") { error("History file \"$filetoread\" is corrupted (End of section BROWSER not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2623 if ($Debug) { debug(" End of BROWSER section ($count entries, $countloaded loaded)"); }
2624 delete $SectionsToLoad{'browser'};
2625 if ($SectionsToSave{'browser'}) {
2626 rizwank 1.1 Save_History('browser',$year,$month); delete $SectionsToSave{'browser'};
2627 if ($withpurge) { %_browser_h=(); }
2628 }
2629 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2630 next;
2631 }
2632 # BEGIN_UNKNOWNREFERER
2633 if ($field[0] eq 'BEGIN_UNKNOWNREFERER') {
2634 if ($Debug) { debug(" Begin of UNKNOWNREFERER section"); }
2635 $field[0]='';
2636 my $count=0;my $countloaded=0;
2637 do {
2638 if ($field[0]) {
2639 $count++;
2640 if ($SectionsToLoad{'unknownreferer'}) {
2641 $countloaded++;
2642 if (! $_unknownreferer_l{$field[0]}) { $_unknownreferer_l{$field[0]}=int($field[1]); }
2643 }
2644 }
2645 $_=<HISTORY>;
2646 chomp $_; s/\r//;
2647 rizwank 1.1 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2648 }
2649 until ($field[0] eq 'END_UNKNOWNREFERER' || $field[0] eq "${xmleb}END_UNKNOWNREFERER" || ! $_);
2650 if ($field[0] ne 'END_UNKNOWNREFERER' && $field[0] ne "${xmleb}END_UNKNOWNREFERER") { error("History file \"$filetoread\" is corrupted (End of section UNKNOWNREFERER not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2651 if ($Debug) { debug(" End of UNKNOWNREFERER section ($count entries, $countloaded loaded)"); }
2652 delete $SectionsToLoad{'unknownreferer'};
2653 if ($SectionsToSave{'unknownreferer'}) {
2654 Save_History('unknownreferer',$year,$month); delete $SectionsToSave{'unknownreferer'};
2655 if ($withpurge) { %_unknownreferer_l=(); }
2656 }
2657 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2658 next;
2659 }
2660 # BEGIN_UNKNOWNREFERERBROWSER
2661 if ($field[0] eq 'BEGIN_UNKNOWNREFERERBROWSER') {
2662 if ($Debug) { debug(" Begin of UNKNOWNREFERERBROWSER section"); }
2663 $field[0]='';
2664 my $count=0;my $countloaded=0;
2665 do {
2666 if ($field[0]) {
2667 $count++;
2668 rizwank 1.1 if ($SectionsToLoad{'unknownrefererbrowser'}) {
2669 $countloaded++;
2670 if (! $_unknownrefererbrowser_l{$field[0]}) { $_unknownrefererbrowser_l{$field[0]}=int($field[1]); }
2671 }
2672 }
2673 $_=<HISTORY>;
2674 chomp $_; s/\r//;
2675 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2676 }
2677 until ($field[0] eq 'END_UNKNOWNREFERERBROWSER' || $field[0] eq "${xmleb}END_UNKNOWNREFERERBROWSER" || ! $_);
2678 if ($field[0] ne 'END_UNKNOWNREFERERBROWSER' && $field[0] ne "${xmleb}END_UNKNOWNREFERERBROWSER") { error("History file \"$filetoread\" is corrupted (End of section UNKNOWNREFERERBROWSER not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2679 if ($Debug) { debug(" End of UNKNOWNREFERERBROWSER section ($count entries, $countloaded loaded)"); }
2680 delete $SectionsToLoad{'unknownrefererbrowser'};
2681 if ($SectionsToSave{'unknownrefererbrowser'}) {
2682 Save_History('unknownrefererbrowser',$year,$month); delete $SectionsToSave{'unknownrefererbrowser'};
2683 if ($withpurge) { %_unknownrefererbrowser_l=(); }
2684 }
2685 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2686 next;
2687 }
2688 # BEGIN_SCREENSIZE
2689 rizwank 1.1 if ($field[0] eq 'BEGIN_SCREENSIZE') {
2690 if ($Debug) { debug(" Begin of SCREENSIZE section"); }
2691 $field[0]='';
2692 my $count=0;my $countloaded=0;
2693 do {
2694 if ($field[0]) {
2695 $count++;
2696 if ($SectionsToLoad{'screensize'}) {
2697 $countloaded++;
2698 if ($field[1]) { $_screensize_h{$field[0]}+=$field[1]; }
2699 }
2700 }
2701 $_=<HISTORY>;
2702 chomp $_; s/\r//;
2703 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2704 }
2705 until ($field[0] eq 'END_SCREENSIZE' || $field[0] eq "${xmleb}END_SCREENSIZE" || ! $_);
2706 if ($field[0] ne 'END_SCREENSIZE' && $field[0] ne "${xmleb}END_SCREENSIZE") { error("History file \"$filetoread\" is corrupted (End of section SCREENSIZE not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2707 if ($Debug) { debug(" End of SCREENSIZE section ($count entries, $countloaded loaded)"); }
2708 delete $SectionsToLoad{'screensize'};
2709 if ($SectionsToSave{'screensize'}) {
2710 rizwank 1.1 Save_History('screensize',$year,$month); delete $SectionsToSave{'screensize'};
2711 if ($withpurge) { %_screensize_h=(); }
2712 }
2713 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2714 next;
2715 }
2716 # BEGIN_ROBOT
2717 if ($field[0] eq 'BEGIN_ROBOT') {
2718 if ($Debug) { debug(" Begin of ROBOT section"); }
2719 $field[0]='';
2720 my $count=0;my $countloaded=0;
2721 do {
2722 if ($field[0]) {
2723 $count++;
2724 if ($SectionsToLoad{'robot'}) {
2725 $countloaded++;
2726 if ($field[1]) { $_robot_h{$field[0]}+=$field[1]; }
2727 if ($versionnum < 5000 || ! $field[3]) { # For backward compatibility
2728 if (! $_robot_l{$field[0]}) { $_robot_l{$field[0]}=int($field[2]); }
2729 }
2730 else {
2731 rizwank 1.1 $_robot_k{$field[0]}+=$field[2];
2732 if (! $_robot_l{$field[0]}) { $_robot_l{$field[0]}=int($field[3]); }
2733 }
2734 if ($field[4]) { $_robot_r{$field[0]}+=$field[4]; }
2735 }
2736 }
2737 $_=<HISTORY>;
2738 chomp $_; s/\r//;
2739 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2740 }
2741 until ($field[0] eq 'END_ROBOT' || $field[0] eq "${xmleb}END_ROBOT" || ! $_);
2742 if ($field[0] ne 'END_ROBOT' && $field[0] ne "${xmleb}END_ROBOT") { error("History file \"$filetoread\" is corrupted (End of section ROBOT not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2743 if ($Debug) { debug(" End of ROBOT section ($count entries, $countloaded loaded)"); }
2744 delete $SectionsToLoad{'robot'};
2745 if ($SectionsToSave{'robot'}) {
2746 Save_History('robot',$year,$month); delete $SectionsToSave{'robot'};
2747 if ($withpurge) { %_robot_h=(); %_robot_k=(); %_robot_l=(); %_robot_r=(); }
2748 }
2749 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2750 next;
2751 }
2752 rizwank 1.1 # BEGIN_WORMS
2753 if ($field[0] eq 'BEGIN_WORMS') {
2754 if ($Debug) { debug(" Begin of WORMS section"); }
2755 $field[0]='';
2756 my $count=0;my $countloaded=0;
2757 do {
2758 if ($field[0]) {
2759 $count++;
2760 if ($SectionsToLoad{'worms'}) {
2761 $countloaded++;
2762 if ($field[1]) { $_worm_h{$field[0]}+=$field[1]; }
2763 $_worm_k{$field[0]}+=$field[2];
2764 if (! $_worm_l{$field[0]}) { $_worm_l{$field[0]}=int($field[3]); }
2765 }
2766 }
2767 $_=<HISTORY>;
2768 chomp $_; s/\r//;
2769 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2770 }
2771 until ($field[0] eq 'END_WORMS' || $field[0] eq "${xmleb}END_WORMS" || ! $_);
2772 if ($field[0] ne 'END_WORMS' && $field[0] ne "${xmleb}END_WORMS") { error("History file \"$filetoread\" is corrupted (End of section WORMS not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2773 rizwank 1.1 if ($Debug) { debug(" End of WORMS section ($count entries, $countloaded loaded)"); }
2774 delete $SectionsToLoad{'worms'};
2775 if ($SectionsToSave{'worms'}) {
2776 Save_History('worms',$year,$month); delete $SectionsToSave{'worms'};
2777 if ($withpurge) { %_worm_h=(); %_worm_k=(); %_worm_l=(); }
2778 }
2779 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2780 next;
2781 }
2782 # BEGIN_EMAILS
2783 if ($field[0] eq 'BEGIN_EMAILSENDER') {
2784 if ($Debug) { debug(" Begin of EMAILSENDER section"); }
2785 $field[0]='';
2786 my $count=0;my $countloaded=0;
2787 do {
2788 if ($field[0]) {
2789 $count++;
2790 if ($SectionsToLoad{'emailsender'}) {
2791 $countloaded++;
2792 if ($field[1]) { $_emails_h{$field[0]}+=$field[1]; }
2793 if ($field[2]) { $_emails_k{$field[0]}+=$field[2]; }
2794 rizwank 1.1 if (! $_emails_l{$field[0]}) { $_emails_l{$field[0]}=int($field[3]); }
2795 }
2796 }
2797 $_=<HISTORY>;
2798 chomp $_; s/\r//;
2799 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2800 }
2801 until ($field[0] eq 'END_EMAILSENDER' || $field[0] eq "${xmleb}END_EMAILSENDER" || ! $_);
2802 if ($field[0] ne 'END_EMAILSENDER' && $field[0] ne "${xmleb}END_EMAILSENDER") { error("History file \"$filetoread\" is corrupted (End of section EMAILSENDER not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2803 if ($Debug) { debug(" End of EMAILSENDER section ($count entries, $countloaded loaded)"); }
2804 delete $SectionsToLoad{'emailsender'};
2805 if ($SectionsToSave{'emailsender'}) {
2806 Save_History('emailsender',$year,$month); delete $SectionsToSave{'emailsender'};
2807 if ($withpurge) { %_emails_h=(); %_emails_k=(); %_emails_l=(); }
2808 }
2809 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2810 next;
2811 }
2812 # BEGIN_EMAILR
2813 if ($field[0] eq 'BEGIN_EMAILRECEIVER') {
2814 if ($Debug) { debug(" Begin of EMAILRECEIVER section"); }
2815 rizwank 1.1 $field[0]='';
2816 my $count=0;my $countloaded=0;
2817 do {
2818 if ($field[0]) {
2819 $count++;
2820 if ($SectionsToLoad{'emailreceiver'}) {
2821 $countloaded++;
2822 if ($field[1]) { $_emailr_h{$field[0]}+=$field[1]; }
2823 if ($field[2]) { $_emailr_k{$field[0]}+=$field[2]; }
2824 if (! $_emailr_l{$field[0]}) { $_emailr_l{$field[0]}=int($field[3]); }
2825 }
2826 }
2827 $_=<HISTORY>;
2828 chomp $_; s/\r//;
2829 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2830 }
2831 until ($field[0] eq 'END_EMAILRECEIVER' || $field[0] eq "${xmleb}END_EMAILRECEIVER" || ! $_);
2832 if ($field[0] ne 'END_EMAILRECEIVER' && $field[0] ne "${xmleb}END_EMAILRECEIVER") { error("History file \"$filetoread\" is corrupted (End of section EMAILRECEIVER not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2833 if ($Debug) { debug(" End of EMAILRECEIVER section ($count entries, $countloaded loaded)"); }
2834 delete $SectionsToLoad{'emailreceiver'};
2835 if ($SectionsToSave{'emailreceiver'}) {
2836 rizwank 1.1 Save_History('emailreceiver',$year,$month); delete $SectionsToSave{'emailreceiver'};
2837 if ($withpurge) { %_emailr_h=(); %_emailr_k=(); %_emailr_l=(); }
2838 }
2839 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2840 next;
2841 }
2842 # BEGIN_SIDER
2843 if ($field[0] eq 'BEGIN_SIDER') {
2844 if ($Debug) { debug(" Begin of SIDER section"); }
2845 $field[0]='';
2846 my $count=0;my $countloaded=0;
2847 do {
2848 if ($field[0]) {
2849 $count++;
2850 if ($SectionsToLoad{'sider'}) {
2851 my $loadrecord=0;
2852 if ($withupdate) {
2853 $loadrecord=1;
2854 }
2855 else {
2856 if ($HTMLOutput{'main'}) {
2857 rizwank 1.1 if ($MonthRequired eq 'all') { $loadrecord=1; }
2858 else {
2859 if ($countloaded < $MaxNbOf{'PageShown'} && $field[1] >= $MinHit{'File'}) { $loadrecord=1; }
2860 $TotalDifferentPages++;
2861 }
2862 }
2863 else { # This is for $HTMLOutput = urldetail, urlentry or urlexit
2864 if ($MonthRequired eq 'all' ) {
2865 if ((!$FilterIn{'url'} || $field[0] =~ /$FilterIn{'url'}/)
2866 && (!$FilterEx{'url'} || $field[0] !~ /$FilterEx{'url'}/)) { $loadrecord=1; }
2867 }
2868 else {
2869 if ((!$FilterIn{'url'} || $field[0] =~ /$FilterIn{'url'}/)
2870 && (!$FilterEx{'url'} || $field[0] !~ /$FilterEx{'url'}/)
2871 && $field[1] >= $MinHit{'File'}) { $loadrecord=1; }
2872 $TotalDifferentPages++;
2873 }
2874 }
2875 # Posssibilite de mettre if ($FilterIn{'url'} && $field[0] =~ /$FilterIn{'url'}/) mais il faut gerer TotalPages de la meme maniere
2876 if ($versionnum < 4000) { # For history files < 4.0
2877 $TotalEntries+=($field[2]||0);
2878 rizwank 1.1 }
2879 else {
2880 $TotalBytesPages+=($field[2]||0);
2881 $TotalEntries+=($field[3]||0);
2882 $TotalExits+=($field[4]||0);
2883 }
2884 }
2885 if ($loadrecord) {
2886 if ($field[1]) { $_url_p{$field[0]}+=$field[1]; }
2887 if ($versionnum < 4000) { # For history files < 4.0
2888 if ($field[2]) { $_url_e{$field[0]}+=$field[2]; }
2889 $_url_k{$field[0]}=0;
2890 }
2891 else {
2892 if ($field[2]) { $_url_k{$field[0]}+=$field[2]; }
2893 if ($field[3]) { $_url_e{$field[0]}+=$field[3]; }
2894 if ($field[4]) { $_url_x{$field[0]}+=$field[4]; }
2895 }
2896 $countloaded++;
2897 }
2898 }
2899 rizwank 1.1 }
2900 $_=<HISTORY>;
2901 chomp $_; s/\r//;
2902 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2903 }
2904 until ($field[0] eq 'END_SIDER' || $field[0] eq "${xmleb}END_SIDER" || ! $_);
2905 if ($field[0] ne 'END_SIDER' && $field[0] ne "${xmleb}END_SIDER") { error("History file \"$filetoread\" is corrupted (End of section SIDER not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2906 if ($Debug) { debug(" End of SIDER section ($count entries, $countloaded loaded)"); }
2907 delete $SectionsToLoad{'sider'};
2908 # WE DO NOT SAVE SECTION NOW BECAUSE VALUES CAN BE CHANGED AFTER READING VISITOR
2909 #if ($SectionsToSave{'sider'}) {
2910 # Save_History('sider',$year,$month); delete $SectionsToSave{'sider'};
2911 # if ($withpurge) { %_url_p=(); %_url_k=(); %_url_e=(); %_url_x=(); }
2912 #}
2913 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2914 next;
2915 }
2916 # BEGIN_FILETYPES
2917 if ($field[0] eq 'BEGIN_FILETYPES') {
2918 if ($Debug) { debug(" Begin of FILETYPES section"); }
2919 $field[0]='';
2920 rizwank 1.1 my $count=0;my $countloaded=0;
2921 do {
2922 if ($field[0]) {
2923 $count++;
2924 if ($SectionsToLoad{'filetypes'}) {
2925 $countloaded++;
2926 if ($field[1]) { $_filetypes_h{$field[0]}+=$field[1]; }
2927 if ($field[2]) { $_filetypes_k{$field[0]}+=$field[2]; }
2928 if ($field[3]) { $_filetypes_gz_in{$field[0]}+=$field[3]; }
2929 if ($field[4]) { $_filetypes_gz_out{$field[0]}+=$field[4]; }
2930 }
2931 }
2932 $_=<HISTORY>;
2933 chomp $_; s/\r//;
2934 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2935 }
2936 until ($field[0] eq 'END_FILETYPES' || $field[0] eq "${xmleb}END_FILETYPES" || ! $_);
2937 if ($field[0] ne 'END_FILETYPES' && $field[0] ne "${xmleb}END_FILETYPES") { error("History file \"$filetoread\" is corrupted (End of section FILETYPES not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2938 if ($Debug) { debug(" End of FILETYPES section ($count entries, $countloaded loaded)"); }
2939 delete $SectionsToLoad{'filetypes'};
2940 if ($SectionsToSave{'filetypes'}) {
2941 rizwank 1.1 Save_History('filetypes',$year,$month); delete $SectionsToSave{'filetypes'};
2942 if ($withpurge) { %_filetypes_h=(); %_filetypes_k=(); %_filetypes_gz_in=(); %_filetypes_gz_out=(); }
2943 }
2944 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2945 next;
2946 }
2947 # BEGIN_SEREFERRALS
2948 if ($field[0] eq 'BEGIN_SEREFERRALS') {
2949 if ($Debug) { debug(" Begin of SEREFERRALS section"); }
2950 $field[0]='';
2951 my $count=0;my $countloaded=0;
2952 do {
2953 if ($field[0]) {
2954 $count++;
2955 if ($SectionsToLoad{'sereferrals'}) {
2956 $countloaded++;
2957 if ($versionnum < 5004) { # For history files < 5.4
2958 my $se=$field[0]; $se=~s/\./\\./g;
2959 if ($SearchEnginesHashID{$se}) {
2960 $_se_referrals_h{$SearchEnginesHashID{$se}}+=$field[1]||0;
2961 }
2962 rizwank 1.1 else {
2963 $_se_referrals_h{$field[0]}+=$field[1]||0;
2964 }
2965 }
2966 elsif ($versionnum < 5091) { # For history files < 5.91
2967 my $se=$field[0]; $se=~s/\./\\./g;
2968 if ($SearchEnginesHashID{$se}) {
2969 $_se_referrals_p{$SearchEnginesHashID{$se}}+=$field[1]||0;
2970 $_se_referrals_h{$SearchEnginesHashID{$se}}+=$field[2]||0;
2971 }
2972 else {
2973 $_se_referrals_p{$field[0]}+=$field[1]||0;
2974 $_se_referrals_h{$field[0]}+=$field[2]||0;
2975 }
2976 } else {
2977 if ($field[1]) { $_se_referrals_p{$field[0]}+=$field[1]; }
2978 if ($field[2]) { $_se_referrals_h{$field[0]}+=$field[2]; }
2979 }
2980 }
2981 }
2982 $_=<HISTORY>;
2983 rizwank 1.1 chomp $_; s/\r//;
2984 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
2985 }
2986 until ($field[0] eq 'END_SEREFERRALS' || $field[0] eq "${xmleb}END_SEREFERRALS" || ! $_);
2987 if ($field[0] ne 'END_SEREFERRALS' && $field[0] ne "${xmleb}END_SEREFERRALS") { error("History file \"$filetoread\" is corrupted (End of section SEREFERRALS not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
2988 if ($Debug) { debug(" End of SEREFERRALS section ($count entries, $countloaded loaded)"); }
2989 delete $SectionsToLoad{'sereferrals'};
2990 if ($SectionsToSave{'sereferrals'}) {
2991 Save_History('sereferrals',$year,$month); delete $SectionsToSave{'sereferrals'};
2992 if ($withpurge) { %_se_referrals_p=(); %_se_referrals_h=(); }
2993 }
2994 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
2995 next;
2996 }
2997 # BEGIN_PAGEREFS
2998 if ($field[0] eq 'BEGIN_PAGEREFS') {
2999 if ($Debug) { debug(" Begin of PAGEREFS section"); }
3000 $field[0]='';
3001 my $count=0;my $countloaded=0;
3002 do {
3003 if ($field[0]) {
3004 rizwank 1.1 $count++;
3005 if ($SectionsToLoad{'pagerefs'}) {
3006 my $loadrecord=0;
3007 if ($withupdate) {
3008 $loadrecord=1;
3009 }
3010 else {
3011 if ((!$FilterIn{'refererpages'} || $field[0] =~ /$FilterIn{'refererpages'}/)
3012 && (!$FilterEx{'refererpages'} || $field[0] !~ /$FilterEx{'refererpages'}/)) { $loadrecord=1; }
3013 }
3014 if ($loadrecord) {
3015 if ($versionnum < 5004) { # For history files < 5.4
3016 if ($field[1]) { $_pagesrefs_h{$field[0]}+=int($field[1]); }
3017 } else {
3018 if ($field[1]) { $_pagesrefs_p{$field[0]}+=int($field[1]); }
3019 if ($field[2]) { $_pagesrefs_h{$field[0]}+=int($field[2]); }
3020 }
3021 $countloaded++;
3022 }
3023 }
3024 }
3025 rizwank 1.1 $_=<HISTORY>;
3026 chomp $_; s/\r//;
3027 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
3028 }
3029 until ($field[0] eq 'END_PAGEREFS' || $field[0] eq "${xmleb}END_PAGEREFS" || ! $_);
3030 if ($field[0] ne 'END_PAGEREFS' && $field[0] ne "${xmleb}END_PAGEREFS") { error("History file \"$filetoread\" is corrupted (End of section PAGEREFS not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
3031 if ($Debug) { debug(" End of PAGEREFS section ($count entries, $countloaded loaded)"); }
3032 delete $SectionsToLoad{'pagerefs'};
3033 if ($SectionsToSave{'pagerefs'}) {
3034 Save_History('pagerefs',$year,$month); delete $SectionsToSave{'pagerefs'};
3035 if ($withpurge) { %_pagesrefs_p=(); %_pagesrefs_h=(); }
3036 }
3037 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
3038 next;
3039 }
3040 # BEGIN_SEARCHWORDS
3041 if ($field[0] eq 'BEGIN_SEARCHWORDS') {
3042 if ($Debug) { debug(" Begin of SEARCHWORDS section ($MaxNbOf{'KeyphrasesShown'},$MinHit{'Keyphrase'})"); }
3043 $field[0]='';
3044 my $count=0;my $countloaded=0;
3045 do {
3046 rizwank 1.1 if ($field[0]) {
3047 $count++;
3048 if ($SectionsToLoad{'searchwords'}) {
3049 my $loadrecord=0;
3050 if ($withupdate) {
3051 $loadrecord=1;
3052 }
3053 else {
3054 if ($HTMLOutput{'main'}) {
3055 if ($MonthRequired eq 'all') { $loadrecord=1; }
3056 else {
3057 if ($countloaded < $MaxNbOf{'KeyphrasesShown'} && $field[1] >= $MinHit{'Keyphrase'}) { $loadrecord=1; }
3058 $TotalDifferentKeyphrases++;
3059 $TotalKeyphrases+=($field[1]||0);
3060 }
3061 }
3062 elsif ($HTMLOutput{'keyphrases'}) { # Load keyphrases for keyphrases chart
3063 if ($MonthRequired eq 'all' ) { $loadrecord=1; }
3064 else {
3065 if ($field[1] >= $MinHit{'Keyphrase'}) { $loadrecord=1; }
3066 $TotalDifferentKeyphrases++;
3067 rizwank 1.1 $TotalKeyphrases+=($field[1]||0);
3068 }
3069 }
3070 if ($HTMLOutput{'keywords'}) { # Load keyphrases for keywords chart
3071 $loadrecord=2;
3072 }
3073 }
3074 if ($loadrecord) {
3075 if ($field[1]) {
3076 if ($loadrecord==2) {
3077 foreach (split(/\+/,$field[0])) { # field[0] is "val1+val2+..."
3078 $_keywords{$_}+=$field[1];
3079 }
3080 }
3081 else {
3082 $_keyphrases{$field[0]}+=$field[1];
3083 }
3084 }
3085 $countloaded++;
3086 }
3087 }
3088 rizwank 1.1 }
3089 $_=<HISTORY>;
3090 chomp $_; s/\r//;
3091 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
3092 }
3093 until ($field[0] eq 'END_SEARCHWORDS' || $field[0] eq "${xmleb}END_SEARCHWORDS" || ! $_);
3094 if ($field[0] ne 'END_SEARCHWORDS' && $field[0] ne "${xmleb}END_SEARCHWORDS") { error("History file \"$filetoread\" is corrupted (End of section SEARCHWORDS not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
3095 if ($Debug) { debug(" End of SEARCHWORDS section ($count entries, $countloaded loaded)"); }
3096 delete $SectionsToLoad{'searchwords'};
3097 if ($SectionsToSave{'searchwords'}) {
3098 Save_History('searchwords',$year,$month); delete $SectionsToSave{'searchwords'}; # This save searwords and keywords sections
3099 if ($withpurge) { %_keyphrases=(); }
3100 }
3101 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
3102 next;
3103 }
3104 # BEGIN_KEYWORDS
3105 if ($field[0] eq 'BEGIN_KEYWORDS') {
3106 if ($Debug) { debug(" Begin of KEYWORDS section ($MaxNbOf{'KeywordsShown'},$MinHit{'Keyword'})"); }
3107 $field[0]='';
3108 my $count=0;my $countloaded=0;
3109 rizwank 1.1 do {
3110 if ($field[0]) {
3111 $count++;
3112 if ($SectionsToLoad{'keywords'}) {
3113 my $loadrecord=0;
3114 if ($MonthRequired eq 'all') { $loadrecord=1; }
3115 else {
3116 if ($countloaded < $MaxNbOf{'KeywordsShown'} && $field[1] >= $MinHit{'Keyword'}) { $loadrecord=1; }
3117 $TotalDifferentKeywords++;
3118 $TotalKeywords+=($field[1]||0);
3119 }
3120 if ($loadrecord) {
3121 if ($field[1]) { $_keywords{$field[0]}+=$field[1]; }
3122 $countloaded++;
3123 }
3124 }
3125 }
3126 $_=<HISTORY>;
3127 chomp $_; s/\r//;
3128 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
3129 }
3130 rizwank 1.1 until ($field[0] eq 'END_KEYWORDS' || $field[0] eq "${xmleb}END_KEYWORDS" || ! $_);
3131 if ($field[0] ne 'END_KEYWORDS' && $field[0] ne "${xmleb}END_KEYWORDS") { error("History file \"$filetoread\" is corrupted (End of section KEYWORDS not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
3132 if ($Debug) { debug(" End of KEYWORDS section ($count entries, $countloaded loaded)"); }
3133 delete $SectionsToLoad{'keywords'};
3134 if ($SectionsToSave{'keywords'}) {
3135 Save_History('keywords',$year,$month); delete $SectionsToSave{'keywords'};
3136 if ($withpurge) { %_keywords=(); }
3137 }
3138 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
3139 next;
3140 }
3141 # BEGIN_ERRORS
3142 if ($field[0] eq 'BEGIN_ERRORS') {
3143 if ($Debug) { debug(" Begin of ERRORS section"); }
3144 $field[0]='';
3145 my $count=0;my $countloaded=0;
3146 do {
3147 if ($field[0]) {
3148 $count++;
3149 if ($SectionsToLoad{'errors'}) {
3150 $countloaded++;
3151 rizwank 1.1 if ($field[1]) { $_errors_h{$field[0]}+=$field[1]; }
3152 if ($field[2]) { $_errors_k{$field[0]}+=$field[2]; }
3153 }
3154 }
3155 $_=<HISTORY>;
3156 chomp $_; s/\r//;
3157 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
3158 }
3159 until ($field[0] eq 'END_ERRORS' || $field[0] eq "${xmleb}END_ERRORS" || ! $_);
3160 if ($field[0] ne 'END_ERRORS' && $field[0] ne "${xmleb}END_ERRORS") { error("History file \"$filetoread\" is corrupted (End of section ERRORS not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
3161 if ($Debug) { debug(" End of ERRORS section ($count entries, $countloaded loaded)"); }
3162 delete $SectionsToLoad{'errors'};
3163 if ($SectionsToSave{'errors'}) {
3164 Save_History('errors',$year,$month); delete $SectionsToSave{'errors'};
3165 if ($withpurge) { %_errors_h=(); %_errors_k=(); }
3166 }
3167 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
3168 next;
3169 }
3170 # BEGIN_SIDER_xxx
3171 foreach my $code (keys %TrapInfosForHTTPErrorCodes) {
3172 rizwank 1.1 if ($field[0] eq "BEGIN_SIDER_$code") {
3173 if ($Debug) { debug(" Begin of SIDER_$code section"); }
3174 $field[0]='';
3175 my $count=0;my $countloaded=0;
3176 do {
3177 if ($field[0]) {
3178 $count++;
3179 if ($SectionsToLoad{"sider_$code"}) {
3180 $countloaded++;
3181 if ($field[1]) { $_sider404_h{$field[0]}+=$field[1]; }
3182 if ($withupdate || $HTMLOutput{"errors$code"}) {
3183 if ($field[2]) { $_referer404_h{$field[0]}=$field[2]; }
3184 }
3185 }
3186 }
3187 $_=<HISTORY>;
3188 chomp $_; s/\r//;
3189 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
3190 }
3191 until ($field[0] eq "END_SIDER_$code" || $field[0] eq "${xmleb}END_SIDER_$code" || ! $_);
3192 if ($field[0] ne "END_SIDER_$code" && $field[0] ne "${xmleb}END_SIDER_$code") { error("History file \"$filetoread\" is corrupted (End of section SIDER_$code not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
3193 rizwank 1.1 if ($Debug) { debug(" End of SIDER_$code section ($count entries, $countloaded loaded)"); }
3194 delete $SectionsToLoad{"sider_$code"};
3195 if ($SectionsToSave{"sider_$code"}) {
3196 Save_History("sider_$code",$year,$month); delete $SectionsToSave{"sider_$code"};
3197 if ($withpurge) { %_sider404_h=(); %_referer404_h=(); }
3198 }
3199 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
3200 next;
3201 }
3202 }
3203 # BEGIN_EXTRA_xxx
3204 foreach my $extranum (1..@ExtraName-1) {
3205 if ($field[0] eq "BEGIN_EXTRA_$extranum") {
3206 if ($Debug) { debug(" Begin of EXTRA_$extranum"); }
3207 $field[0]='';
3208 my $count=0;my $countloaded=0;
3209 do {
3210 if ($field[0] ne '') {
3211 $count++;
3212 if ($SectionsToLoad{"extra_$extranum"}) {
3213 if ($ExtraStatTypes[$extranum] =~ /P/i && $field[1]) { ${'_section_' . $extranum . '_p'}{$field[0]}+=$field[1]; }
3214 rizwank 1.1 ${'_section_' . $extranum . '_h'}{$field[0]}+=$field[2];
3215 if ($ExtraStatTypes[$extranum] =~ /B/i && $field[3]) { ${'_section_' . $extranum . '_k'}{$field[0]}+=$field[3]; }
3216 if ($ExtraStatTypes[$extranum] =~ /L/i && ! ${'_section_' . $extranum . '_l'}{$field[0]} && $field[4]) { ${'_section_' . $extranum . '_l'}{$field[0]}=int($field[4]); }
3217 $countloaded++;
3218 }
3219 }
3220 $_=<HISTORY>;
3221 chomp $_; s/\r//;
3222 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
3223 }
3224 until ($field[0] eq "END_EXTRA_$extranum" || $field[0] eq "${xmleb}END_EXTRA_$extranum" || ! $_);
3225 if ($field[0] ne "END_EXTRA_$extranum" && $field[0] ne "${xmleb}END_EXTRA_$extranum") { error("History file \"$filetoread\" is corrupted (End of section EXTRA_$extranum not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
3226 if ($Debug) { debug(" End of EXTRA_$extranum section ($count entries, $countloaded loaded)"); }
3227 delete $SectionsToLoad{"extra_$extranum"};
3228 if ($SectionsToSave{"extra_$extranum"}) {
3229 Save_History("extra_$extranum",$year,$month); delete $SectionsToSave{"extra_$extranum"};
3230 if ($withpurge) { %{'_section_' . $extranum . '_p'}=(); %{'_section_' . $extranum . '_h'}=(); %{'_section_' . $extranum . '_b'}=(); %{'_section_' . $extranum . '_l'}=(); }
3231 }
3232 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
3233 next;
3234 }
3235 rizwank 1.1 }
3236
3237 # BEGIN_PLUGINS
3238 if ($AtLeastOneSectionPlugin && $field[0] =~ /^BEGIN_PLUGIN_(\w+)$/i) {
3239 my $pluginname=$1;
3240 my $found=0;
3241 foreach (keys %{$PluginsLoaded{'SectionInitHashArray'}}) {
3242 if ($pluginname eq $_) {
3243 # The plugin for this section was loaded
3244 $found=1;
3245 my $issectiontoload=$SectionsToLoad{"plugin_$pluginname"};
3246 my $function="SectionReadHistory_$pluginname(\$issectiontoload,\$xmlold,\$xmleb,\$countlines)";
3247 eval("$function");
3248 delete $SectionsToLoad{"plugin_$pluginname"};
3249 if ($SectionsToSave{"plugin_$pluginname"}) {
3250 Save_History("plugin_$pluginname",$year,$month);
3251 delete $SectionsToSave{"plugin_$pluginname"};
3252 if ($withpurge) {
3253 my $function="SectionInitHashArray_$pluginname()";
3254 eval("$function");
3255 }
3256 rizwank 1.1 }
3257 last;
3258 }
3259 }
3260 if (! scalar %SectionsToLoad) { debug(" Stop reading history file. Got all we need."); last; }
3261 # The plugin for this section was not loaded
3262 if (! $found) {
3263 do {
3264 $_=<HISTORY>;
3265 chomp $_; s/\r//;
3266 @field=split(/\s+/,($xmlold?CleanFromTags($_):$_)); $countlines++;
3267 }
3268 until ($field[0] eq "END_PLUGIN_$pluginname" || $field[0] eq "${xmleb}END_PLUGIN_$pluginname" || ! $_);
3269 }
3270 next;
3271 }
3272
3273 # For backward compatibility (ORIGIN section was "HitFromx" in old history files)
3274 if ($SectionsToLoad{'origin'}) {
3275 if ($field[0] eq 'HitFrom0') { $_from_p[0]+=0; $_from_h[0]+=$field[1]; next; }
3276 if ($field[0] eq 'HitFrom1') { $_from_p[1]+=0; $_from_h[1]+=$field[1]; next; }
3277 rizwank 1.1 if ($field[0] eq 'HitFrom2') { $_from_p[2]+=0; $_from_h[2]+=$field[1]; next; }
3278 if ($field[0] eq 'HitFrom3') { $_from_p[3]+=0; $_from_h[3]+=$field[1]; next; }
3279 if ($field[0] eq 'HitFrom4') { $_from_p[4]+=0; $_from_h[4]+=$field[1]; next; }
3280 if ($field[0] eq 'HitFrom5') { $_from_p[5]+=0; $_from_h[5]+=$field[1]; next; }
3281 }
3282 }
3283 }
3284
3285 if ($withupdate) {
3286 # Process rest of data saved in 'wait' arrays (data for hosts that are not in history file or no history file found)
3287 # This can change some values for day, sider and session sections
3288 if ($Debug) { debug(" Processing data in 'wait' arrays",3); }
3289 foreach (keys %_waithost_e) {
3290 if ($Debug) { debug(" Visit in 'wait' array for $_ is a new visit",4); }
3291 my $newtimehosts=($_waithost_s{$_}?$_waithost_s{$_}:$_host_s{$_});
3292 my $newtimehostl=($_waithost_l{$_}?$_waithost_l{$_}:$_host_l{$_});
3293 $_url_e{$_waithost_e{$_}}++;
3294 $newtimehosts =~ /^(\d\d\d\d\d\d\d\d)/; $DayVisits{$1}++;
3295 if ($_waithost_s{$_}) {
3296 # There was also a second session in processed log
3297 $_session{GetSessionRange($newtimehosts,$newtimehostl)}++;
3298 rizwank 1.1 }
3299 }
3300 }
3301
3302 # Write all unwrote sections in section order ('general','time', 'day','sider','session' and other...)
3303 if ($Debug) { debug(" Check and write all unwrote sections: ".join(',',keys %SectionsToSave),2); }
3304 foreach my $key (sort { $SectionsToSave{$a} <=> $SectionsToSave{$b} } keys %SectionsToSave) {
3305 Save_History("$key",$year,$month,$lastlinenb,$lastlineoffset,$lastlinechecksum);
3306 }
3307 %SectionsToSave=();
3308
3309 # Update offset in map section and last data in general section then close files
3310 if ($withupdate) {
3311 if ($xml) { print HISTORYTMP "\n\n</xml>\n"; }
3312
3313 # Update offset of sections in the MAP section
3314 foreach (sort { $PosInFile{$a} <=> $PosInFile{$b} } keys %ValueInFile) {
3315 if ($Debug) { debug(" Update offset of section $_=$ValueInFile{$_} in file at offset $PosInFile{$_}"); }
3316 if ($PosInFile{"$_"}) {
3317 seek(HISTORYTMP,$PosInFile{"$_"},0); print HISTORYTMP $ValueInFile{"$_"};
3318 }
3319 rizwank 1.1 }
3320 # Save last data in general sections
3321 if ($Debug) { debug(" Update MonthVisits=$MonthVisits{$year.$month} in file at offset $PosInFile{TotalVisits}"); }
3322 seek(HISTORYTMP,$PosInFile{"TotalVisits"},0); print HISTORYTMP $MonthVisits{$year.$month};
3323 if ($Debug) { debug(" Update MonthUnique=$MonthUnique{$year.$month} in file at offset $PosInFile{TotalUnique}"); }
3324 seek(HISTORYTMP,$PosInFile{"TotalUnique"},0); print HISTORYTMP $MonthUnique{$year.$month};
3325 if ($Debug) { debug(" Update MonthHostsKnown=$MonthHostsKnown{$year.$month} in file at offset $PosInFile{MonthHostsKnown}"); }
3326 seek(HISTORYTMP,$PosInFile{"MonthHostsKnown"},0); print HISTORYTMP $MonthHostsKnown{$year.$month};
3327 if ($Debug) { debug(" Update MonthHostsUnknown=$MonthHostsUnknown{$year.$month} in file at offset $PosInFile{MonthHostsUnknown}"); }
3328 seek(HISTORYTMP,$PosInFile{"MonthHostsUnknown"},0); print HISTORYTMP $MonthHostsUnknown{$year.$month};
3329 close(HISTORYTMP) || error("Failed to write temporary history file");
3330 }
3331 if ($withread) {
3332 close(HISTORY) || error("Command for pipe '$filetoread' failed");
3333 }
3334
3335 # Purge data
3336 if ($withpurge) { &Init_HashArray(); }
3337
3338 # If update, rename tmp file bis into tmp file or set HistoryAlreadyFlushed
3339 if ($withupdate) {
3340 rizwank 1.1 if ($HistoryAlreadyFlushed{"$year$month"}) {
3341 debug("Rename tmp history file bis '$filetoread' to '$filetowrite'");
3342 if (rename($filetowrite,$filetoread)==0) {
3343 error("Failed to update tmp history file $filetoread");
3344 }
3345 }
3346 else {
3347 $HistoryAlreadyFlushed{"$year$month"}=1;
3348 }
3349 if (! $ListOfYears{"$year"} || $ListOfYears{"$year"} lt "$month") { $ListOfYears{"$year"}="$month"; }
3350 }
3351
3352 # For backward compatibility, if LastLine does not exist, set to LastTime
3353 $LastLine||=$LastTime{$year.$month};
3354
3355 return ($withupdate?"$filetowrite":"");
3356 }
3357
3358 #------------------------------------------------------------------------------
3359 # Function: Save a part of history file
3360 # Parameters: sectiontosave,year,month[,lastlinenb,lastlineoffset,lastlinechecksum]
3361 rizwank 1.1 # Input: $VERSION HISTORYTMP $nowyear $nowmonth $nowday $nowhour $nowmin $nowsec $LastLineNumber $LastLineOffset $LastLineChecksum
3362 # Output: None
3363 # Return: None
3364 #------------------------------------------------------------------------------
3365 sub Save_History {
3366 my $sectiontosave=shift||'';
3367 my $year=shift||'';
3368 my $month=shift||'';
3369
3370 my $xml=($BuildHistoryFormat eq 'xml'?1:0);
3371 my ($xmlbb,$xmlbs,$xmlbe,$xmlhb,$xmlhs,$xmlhe,$xmlrb,$xmlrs,$xmlre,$xmleb,$xmlee)=('','','','','','','','','','','');
3372 if ($xml) { ($xmlbb,$xmlbs,$xmlbe,$xmlhb,$xmlhs,$xmlhe,$xmlrb,$xmlrs,$xmlre,$xmleb,$xmlee)=("</comment><nu>\n",'</nu><recnb>','</recnb><table>','<tr><th>','</th><th>','</th></tr>','<tr><td>','</td><td>','</td></tr>','</table><nu>',"\n</nu></section>" ); }
3373 else { $xmlbs=' '; $xmlhs=' '; $xmlrs=' '; }
3374
3375 my $lastlinenb=shift||0;
3376 my $lastlineoffset=shift||0;
3377 my $lastlinechecksum=shift||0;
3378 if (! $lastlinenb) { # This happens for migrate
3379 $lastlinenb=$LastLineNumber;
3380 $lastlineoffset=$LastLineOffset;
3381 $lastlinechecksum=$LastLineChecksum;
3382 rizwank 1.1 }
3383
3384 if ($Debug) { debug(" Save_History [sectiontosave=$sectiontosave,year=$year,month=$month,lastlinenb=$lastlinenb,lastlineoffset=$lastlineoffset,lastlinechecksum=$lastlinechecksum]",1); }
3385 my $spacebar=" ";
3386 my %keysinkeylist=();
3387
3388 # Header
3389 if ($sectiontosave eq 'header') {
3390 if ($xml) { print HISTORYTMP "<version><lib>\n"; }
3391 print HISTORYTMP "AWSTATS DATA FILE $VERSION\n";
3392 if ($xml) { print HISTORYTMP "</lib><comment>\n"; }
3393 print HISTORYTMP "# If you remove this file, all statistics for date $year-$month will be lost/reset.\n";
3394 if ($xml) { print HISTORYTMP "</comment></version>\n"; }
3395 print HISTORYTMP "\n";
3396 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3397 print HISTORYTMP "# Position (offset in bytes) in this file of beginning of each section for\n";
3398 print HISTORYTMP "# direct I/O access. If you made changes somewhere in this file, you should\n";
3399 print HISTORYTMP "# also remove completely the MAP section (AWStats will rewrite it at next\n";
3400 print HISTORYTMP "# update).\n";
3401 print HISTORYTMP "${xmlbb}BEGIN_MAP${xmlbs}".(26+(scalar keys %TrapInfosForHTTPErrorCodes)+(scalar @ExtraName?scalar @ExtraName-1:0)+(scalar keys %{$PluginsLoaded{'SectionInitHashArray'}}))."${xmlbe}\n";
3402 print HISTORYTMP "${xmlrb}POS_GENERAL${xmlrs}";$PosInFile{"general"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3403 rizwank 1.1 # When
3404 print HISTORYTMP "${xmlrb}POS_TIME${xmlrs}";$PosInFile{"time"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3405 print HISTORYTMP "${xmlrb}POS_VISITOR${xmlrs}";$PosInFile{"visitor"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3406 print HISTORYTMP "${xmlrb}POS_DAY${xmlrs}";$PosInFile{"day"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3407 # Who
3408 print HISTORYTMP "${xmlrb}POS_DOMAIN${xmlrs}";$PosInFile{"domain"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3409 print HISTORYTMP "${xmlrb}POS_LOGIN${xmlrs}";$PosInFile{"login"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3410 print HISTORYTMP "${xmlrb}POS_ROBOT${xmlrs}";$PosInFile{"robot"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3411 print HISTORYTMP "${xmlrb}POS_WORMS${xmlrs}";$PosInFile{"worms"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3412 print HISTORYTMP "${xmlrb}POS_EMAILSENDER${xmlrs}";$PosInFile{"emailsender"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3413 print HISTORYTMP "${xmlrb}POS_EMAILRECEIVER${xmlrs}";$PosInFile{"emailreceiver"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3414 # Navigation
3415 print HISTORYTMP "${xmlrb}POS_SESSION${xmlrs}";$PosInFile{"session"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3416 print HISTORYTMP "${xmlrb}POS_SIDER${xmlrs}";$PosInFile{"sider"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3417 print HISTORYTMP "${xmlrb}POS_FILETYPES${xmlrs}";$PosInFile{"filetypes"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3418 print HISTORYTMP "${xmlrb}POS_OS${xmlrs}";$PosInFile{"os"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3419 print HISTORYTMP "${xmlrb}POS_BROWSER${xmlrs}";$PosInFile{"browser"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3420 print HISTORYTMP "${xmlrb}POS_SCREENSIZE${xmlrs}";$PosInFile{"screensize"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3421 print HISTORYTMP "${xmlrb}POS_UNKNOWNREFERER${xmlrs}";$PosInFile{'unknownreferer'}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3422 print HISTORYTMP "${xmlrb}POS_UNKNOWNREFERERBROWSER${xmlrs}";$PosInFile{'unknownrefererbrowser'}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3423 # Referers
3424 rizwank 1.1 print HISTORYTMP "${xmlrb}POS_ORIGIN${xmlrs}";$PosInFile{"origin"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3425 print HISTORYTMP "${xmlrb}POS_SEREFERRALS${xmlrs}";$PosInFile{"sereferrals"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3426 print HISTORYTMP "${xmlrb}POS_PAGEREFS${xmlrs}";$PosInFile{"pagerefs"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3427 print HISTORYTMP "${xmlrb}POS_SEARCHWORDS${xmlrs}";$PosInFile{"searchwords"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3428 print HISTORYTMP "${xmlrb}POS_KEYWORDS${xmlrs}";$PosInFile{"keywords"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3429 # Others
3430 print HISTORYTMP "${xmlrb}POS_MISC${xmlrs}";$PosInFile{"misc"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3431 print HISTORYTMP "${xmlrb}POS_ERRORS${xmlrs}";$PosInFile{"errors"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3432 print HISTORYTMP "${xmlrb}POS_CLUSTER${xmlrs}";$PosInFile{"cluster"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3433 foreach (keys %TrapInfosForHTTPErrorCodes) {
3434 print HISTORYTMP "${xmlrb}POS_SIDER_$_${xmlrs}";$PosInFile{"sider_$_"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3435 }
3436 foreach (1..@ExtraName-1) {
3437 print HISTORYTMP "${xmlrb}POS_EXTRA_$_${xmlrs}";$PosInFile{"extra_$_"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3438 }
3439 foreach (keys %{$PluginsLoaded{'SectionInitHashArray'}}) {
3440 print HISTORYTMP "${xmlrb}POS_PLUGIN_$_${xmlrs}";$PosInFile{"plugin_$_"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3441 }
3442 print HISTORYTMP "${xmleb}END_MAP${xmlee}\n";
3443 }
3444
3445 rizwank 1.1 # General
3446 if ($sectiontosave eq 'general') {
3447 if ($LastUpdate < int("$nowyear$nowmonth$nowday$nowhour$nowmin$nowsec")) { $LastUpdate=int("$nowyear$nowmonth$nowday$nowhour$nowmin$nowsec"); }
3448 print HISTORYTMP "\n";
3449 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3450 print HISTORYTMP "# LastLine = Date of last record processed - Last record line number in last log - Last record offset in last log - Last record signature value\n";
3451 print HISTORYTMP "# FirstTime = Date of first visit for history file\n";
3452 print HISTORYTMP "# LastTime = Date of last visit for history file\n";
3453 print HISTORYTMP "# LastUpdate = Date of last update - Nb of parsed records - Nb of parsed old records - Nb of parsed new records - Nb of parsed corrupted - Nb of parsed dropped\n";
3454 print HISTORYTMP "# TotalVisits = Number of visits\n";
3455 print HISTORYTMP "# TotalUnique = Number of unique visitors\n";
3456 print HISTORYTMP "# MonthHostsKnown = Number of hosts known\n";
3457 print HISTORYTMP "# MonthHostsUnKnown = Number of hosts unknown\n";
3458 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3459 print HISTORYTMP "${xmlbb}BEGIN_GENERAL${xmlbs}8${xmlbe}\n";
3460 print HISTORYTMP "${xmlrb}LastLine${xmlrs}".($LastLine>0?$LastLine:$LastTime{$year.$month})." $lastlinenb $lastlineoffset $lastlinechecksum${xmlre}\n";
3461 print HISTORYTMP "${xmlrb}FirstTime${xmlrs}$FirstTime{$year.$month}${xmlre}\n";
3462 print HISTORYTMP "${xmlrb}LastTime${xmlrs}$LastTime{$year.$month}${xmlre}\n";
3463 print HISTORYTMP "${xmlrb}LastUpdate${xmlrs}$LastUpdate $NbOfLinesParsed $NbOfOldLines $NbOfNewLines $NbOfLinesCorrupted $NbOfLinesDropped${xmlre}\n";
3464 print HISTORYTMP "${xmlrb}TotalVisits${xmlrs}";$PosInFile{"TotalVisits"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3465 print HISTORYTMP "${xmlrb}TotalUnique${xmlrs}";$PosInFile{"TotalUnique"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3466 rizwank 1.1 print HISTORYTMP "${xmlrb}MonthHostsKnown${xmlrs}";$PosInFile{"MonthHostsKnown"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3467 print HISTORYTMP "${xmlrb}MonthHostsUnknown${xmlrs}";$PosInFile{"MonthHostsUnknown"}=tell HISTORYTMP;print HISTORYTMP "$spacebar${xmlre}\n";
3468 print HISTORYTMP "${xmleb}".(${xmleb}?"\n":"")."END_GENERAL${xmlee}\n"; # END_GENERAL on a new line following xml tag because END_ detection does not work like other sections
3469 }
3470
3471 # When
3472 if ($sectiontosave eq 'time') {
3473 print HISTORYTMP "\n";
3474 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3475 print HISTORYTMP "# Hour - Pages - Hits - Bandwidth - Not viewed Pages - Not viewed Hits - Not viewed Bandwidth\n";
3476 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3477 print HISTORYTMP "${xmlbb}BEGIN_TIME${xmlbs}24${xmlbe}\n";
3478 for (my $ix=0; $ix<=23; $ix++) { print HISTORYTMP "${xmlrb}$ix${xmlrs}".int($_time_p[$ix])."${xmlrs}".int($_time_h[$ix])."${xmlrs}".int($_time_k[$ix])."${xmlrs}".int($_time_nv_p[$ix])."${xmlrs}".int($_time_nv_h[$ix])."${xmlrs}".int($_time_nv_k[$ix])."${xmlre}\n"; }
3479 print HISTORYTMP "${xmleb}END_TIME${xmlee}\n";
3480 }
3481 if ($sectiontosave eq 'day') { # This section must be saved after VISITOR section is read
3482 print HISTORYTMP "\n";
3483 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3484 print HISTORYTMP "# Date - Pages - Hits - Bandwidth - Visits\n";
3485 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3486 print HISTORYTMP "${xmlbb}BEGIN_DAY${xmlbs}".(scalar keys %DayHits)."${xmlbe}\n";
3487 rizwank 1.1 my $monthvisits=0;
3488 foreach (sort keys %DayHits) {
3489 if ($_ =~ /^$year$month/i) { # Found a day entry of the good month
3490 my $page=$DayPages{$_}||0;
3491 my $hits=$DayHits{$_}||0;
3492 my $bytes=$DayBytes{$_}||0;
3493 my $visits=$DayVisits{$_}||0;
3494 print HISTORYTMP "${xmlrb}$_${xmlrs}$page${xmlrs}$hits${xmlrs}$bytes${xmlrs}$visits${xmlre}\n";
3495 $monthvisits+=$visits;
3496 }
3497 }
3498 $MonthVisits{$year.$month}=$monthvisits;
3499 print HISTORYTMP "${xmleb}END_DAY${xmlee}\n";
3500 }
3501
3502 # Who
3503 if ($sectiontosave eq 'domain') {
3504 print HISTORYTMP "\n";
3505 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><sortfor>$MaxNbOf{'Domain'}</sortfor><comment>\n"; }
3506 print HISTORYTMP "# Domain - Pages - Hits - Bandwidth\n";
3507 print HISTORYTMP "# The $MaxNbOf{'Domain'} first Pages must be first (order not required for others)\n";
3508 rizwank 1.1 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3509 print HISTORYTMP "${xmlbb}BEGIN_DOMAIN${xmlbs}".(scalar keys %_domener_h)."${xmlbe}\n";
3510 # We save page list in score sorted order to get a -output faster and with less use of memory.
3511 &BuildKeyList($MaxNbOf{'Domain'},$MinHit{'Domain'},\%_domener_h,\%_domener_p);
3512 my %keysinkeylist=();
3513 foreach (@keylist) {
3514 $keysinkeylist{$_}=1;
3515 my $page=$_domener_p{$_}||0;
3516 my $bytes=$_domener_k{$_}||0; # ||0 could be commented to reduce history file size
3517 print HISTORYTMP "${xmlrb}$_${xmlrs}$page${xmlrs}$_domener_h{$_}${xmlrs}$bytes${xmlre}\n";
3518 }
3519 foreach (keys %_domener_h) {
3520 if ($keysinkeylist{$_}) { next; }
3521 my $page=$_domener_p{$_}||0;
3522 my $bytes=$_domener_k{$_}||0; # ||0 could be commented to reduce history file size
3523 print HISTORYTMP "${xmlrb}$_${xmlrs}$page${xmlrs}$_domener_h{$_}${xmlrs}$bytes${xmlre}\n";
3524 }
3525 print HISTORYTMP "${xmleb}END_DOMAIN${xmlee}\n";
3526 }
3527 if ($sectiontosave eq 'visitor') {
3528 print HISTORYTMP "\n";
3529 rizwank 1.1 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><sortfor>$MaxNbOf{'HostsShown'}</sortfor><comment>\n"; }
3530 print HISTORYTMP "# Host - Pages - Hits - Bandwidth - Last visit date - [Start date of last visit] - [Last page of last visit]\n";
3531 print HISTORYTMP "# [Start date of last visit] and [Last page of last visit] are saved only if session is not finished\n";
3532 print HISTORYTMP "# The $MaxNbOf{'HostsShown'} first Hits must be first (order not required for others)\n";
3533 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3534 print HISTORYTMP "${xmlbb}BEGIN_VISITOR${xmlbs}".(scalar keys %_host_h)."${xmlbe}\n";
3535 my $monthhostsknown=0;
3536 # We save page list in score sorted order to get a -output faster and with less use of memory.
3537 &BuildKeyList($MaxNbOf{'HostsShown'},$MinHit{'Host'},\%_host_h,\%_host_p);
3538 my %keysinkeylist=();
3539 foreach my $key (@keylist) {
3540 if ($key !~ /^\d+\.\d+\.\d+\.\d+$/ && $key !~ /^[0-9A-F]*:/i) { $monthhostsknown++; }
3541 $keysinkeylist{$key}=1;
3542 my $page=$_host_p{$key}||0;
3543 my $bytes=$_host_k{$key}||0;
3544 my $timehostl=$_host_l{$key}||0;
3545 my $timehosts=$_host_s{$key}||0;
3546 my $lastpage=$_host_u{$key}||'';
3547 if ($timehostl && $timehosts && $lastpage) {
3548 if (($timehostl+$VISITTIMEOUT) < $LastLine) {
3549 # Session for this user is expired
3550 rizwank 1.1 if ($timehosts) { $_session{GetSessionRange($timehosts,$timehostl)}++; }
3551 if ($lastpage) { $_url_x{$lastpage}++; }
3552 delete $_host_s{$key};
3553 delete $_host_u{$key};
3554 print HISTORYTMP "${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlre}\n";
3555 }
3556 else {
3557 # If this user has started a new session that is not expired
3558 print HISTORYTMP "${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlrs}$timehosts${xmlrs}$lastpage${xmlre}\n";
3559 }
3560 }
3561 else {
3562 my $hostl=$timehostl||'';
3563 print HISTORYTMP "${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$hostl${xmlre}\n";
3564 }
3565 }
3566 foreach my $key (keys %_host_h) {
3567 if ($keysinkeylist{$key}) { next; }
3568 if ($key !~ /^\d+\.\d+\.\d+\.\d+$/ && $key !~ /^[0-9A-F]*:/i) { $monthhostsknown++; }
3569 my $page=$_host_p{$key}||0;
3570 my $bytes=$_host_k{$key}||0;
3571 rizwank 1.1 my $timehostl=$_host_l{$key}||0;
3572 my $timehosts=$_host_s{$key}||0;
3573 my $lastpage=$_host_u{$key}||'';
3574 if ($timehostl && $timehosts && $lastpage) {
3575 if (($timehostl+$VISITTIMEOUT) < $LastLine) {
3576 # Session for this user is expired
3577 if ($timehosts) { $_session{GetSessionRange($timehosts,$timehostl)}++; }
3578 if ($lastpage) { $_url_x{$lastpage}++; }
3579 delete $_host_s{$key};
3580 delete $_host_u{$key};
3581 print HISTORYTMP "${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlre}\n";
3582 }
3583 else {
3584 # If this user has started a new session that is not expired
3585 print HISTORYTMP "${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlrs}$timehosts${xmlrs}$lastpage${xmlre}\n";
3586 }
3587 }
3588 else {
3589 my $hostl=$timehostl||'';
3590 print HISTORYTMP "${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$hostl${xmlre}\n";
3591 }
3592 rizwank 1.1 }
3593 $MonthUnique{$year.$month}=(scalar keys %_host_p);
3594 $MonthHostsKnown{$year.$month}=$monthhostsknown;
3595 $MonthHostsUnknown{$year.$month}=(scalar keys %_host_h) - $monthhostsknown;
3596 print HISTORYTMP "${xmleb}END_VISITOR${xmlee}\n";
3597 }
3598 if ($sectiontosave eq 'login') {
3599 print HISTORYTMP "\n";
3600 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><sortfor>$MaxNbOf{'LoginShown'}</sortfor><comment>\n"; }
3601 print HISTORYTMP "# Login - Pages - Hits - Bandwidth - Last visit\n";
3602 print HISTORYTMP "# The $MaxNbOf{'LoginShown'} first Pages must be first (order not required for others)\n";
3603 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3604 print HISTORYTMP "${xmlbb}BEGIN_LOGIN${xmlbs}".(scalar keys %_login_h)."${xmlbe}\n";
3605 # We save login list in score sorted order to get a -output faster and with less use of memory.
3606 &BuildKeyList($MaxNbOf{'LoginShown'},$MinHit{'Login'},\%_login_h,\%_login_p);
3607 my %keysinkeylist=();
3608 foreach (@keylist) {
3609 $keysinkeylist{$_}=1;
3610 print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_login_p{$_}||0)."${xmlrs}".int($_login_h{$_}||0)."${xmlrs}".int($_login_k{$_}||0)."${xmlrs}".($_login_l{$_}||'')."${xmlre}\n";
3611 }
3612 foreach (keys %_login_h) {
3613 rizwank 1.1 if ($keysinkeylist{$_}) { next; }
3614 print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_login_p{$_}||0)."${xmlrs}".int($_login_h{$_}||0)."${xmlrs}".int($_login_k{$_}||0)."${xmlrs}".($_login_l{$_}||'')."${xmlre}\n";
3615 }
3616 print HISTORYTMP "${xmleb}END_LOGIN${xmlee}\n";
3617 }
3618 if ($sectiontosave eq 'robot') {
3619 print HISTORYTMP "\n";
3620 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><sortfor>$MaxNbOf{'RobotShown'}</sortfor><comment>\n"; }
3621 print HISTORYTMP "# Robot ID - Hits - Bandwidth - Last visit - Hits on robots.txt\n";
3622 print HISTORYTMP "# The $MaxNbOf{'RobotShown'} first Hits must be first (order not required for others)\n";
3623 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3624 print HISTORYTMP "${xmlbb}BEGIN_ROBOT${xmlbs}".(scalar keys %_robot_h)."${xmlbe}\n";
3625 # We save robot list in score sorted order to get a -output faster and with less use of memory.
3626 &BuildKeyList($MaxNbOf{'RobotShown'},$MinHit{'Robot'},\%_robot_h,\%_robot_h);
3627 my %keysinkeylist=();
3628 foreach (@keylist) {
3629 $keysinkeylist{$_}=1;
3630 print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_robot_h{$_})."${xmlrs}".int($_robot_k{$_})."${xmlrs}$_robot_l{$_}${xmlrs}".int($_robot_r{$_})."${xmlre}\n";
3631 }
3632 foreach (keys %_robot_h) {
3633 if ($keysinkeylist{$_}) { next; }
3634 rizwank 1.1 print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_robot_h{$_})."${xmlrs}".int($_robot_k{$_})."${xmlrs}$_robot_l{$_}${xmlrs}".int($_robot_r{$_})."${xmlre}\n";
3635 }
3636 print HISTORYTMP "${xmleb}END_ROBOT${xmlee}\n";
3637 }
3638 if ($sectiontosave eq 'worms') {
3639 print HISTORYTMP "\n";
3640 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><sortfor>$MaxNbOf{'WormsShown'}</sortfor><comment>\n"; }
3641 print HISTORYTMP "# Worm ID - Hits - Bandwidth - Last visit\n";
3642 print HISTORYTMP "# The $MaxNbOf{'WormsShown'} first Hits must be first (order not required for others)\n";
3643 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3644 print HISTORYTMP "${xmlbb}BEGIN_WORMS${xmlbs}".(scalar keys %_worm_h)."${xmlbe}\n";
3645 # We save worm list in score sorted order to get a -output faster and with less use of memory.
3646 &BuildKeyList($MaxNbOf{'WormsShown'},$MinHit{'Worm'},\%_worm_h,\%_worm_h);
3647 my %keysinkeylist=();
3648 foreach (@keylist) {
3649 $keysinkeylist{$_}=1;
3650 print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_worm_h{$_})."${xmlrs}".int($_worm_k{$_})."${xmlrs}$_worm_l{$_}${xmlre}\n";
3651 }
3652 foreach (keys %_worm_h) {
3653 if ($keysinkeylist{$_}) { next; }
3654 print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_worm_h{$_})."${xmlrs}".int($_worm_k{$_})."${xmlrs}$_worm_l{$_}${xmlre}\n";
3655 rizwank 1.1 }
3656 print HISTORYTMP "${xmleb}END_WORMS${xmlee}\n";
3657 }
3658 if ($sectiontosave eq 'emailsender') {
3659 print HISTORYTMP "\n";
3660 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><sortfor>$MaxNbOf{'EMailsShown'}</sortfor><comment>\n"; }
3661 print HISTORYTMP "# EMail - Hits - Bandwidth - Last visit\n";
3662 print HISTORYTMP "# The $MaxNbOf{'EMailsShown'} first Hits must be first (order not required for others)\n";
3663 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3664 print HISTORYTMP "${xmlbb}BEGIN_EMAILSENDER${xmlbs}".(scalar keys %_emails_h)."${xmlbe}\n";
3665 # We save sender email list in score sorted order to get a -output faster and with less use of memory.
3666 &BuildKeyList($MaxNbOf{'EMailsShown'},$MinHit{'EMail'},\%_emails_h,\%_emails_h);
3667 my %keysinkeylist=();
3668 foreach (@keylist) {
3669 $keysinkeylist{$_}=1;
3670 print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_emails_h{$_}||0)."${xmlrs}".int($_emails_k{$_}||0)."${xmlrs}$_emails_l{$_}${xmlre}\n";
3671 }
3672 foreach (keys %_emails_h) {
3673 if ($keysinkeylist{$_}) { next; }
3674 print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_emails_h{$_}||0)."${xmlrs}".int($_emails_k{$_}||0)."${xmlrs}$_emails_l{$_}${xmlre}\n";
3675 }
3676 rizwank 1.1 print HISTORYTMP "${xmleb}END_EMAILSENDER${xmlee}\n";
3677 }
3678 if ($sectiontosave eq 'emailreceiver') {
3679 print HISTORYTMP "\n";
3680 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><sortfor>$MaxNbOf{'EMailsShown'}</sortfor><comment>\n"; }
3681 print HISTORYTMP "# EMail - Hits - Bandwidth - Last visit\n";
3682 print HISTORYTMP "# The $MaxNbOf{'EMailsShown'} first hits must be first (order not required for others)\n";
3683 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3684 print HISTORYTMP "${xmlbb}BEGIN_EMAILRECEIVER${xmlbs}".(scalar keys %_emailr_h)."${xmlbe}\n";
3685 # We save receiver email list in score sorted order to get a -output faster and with less use of memory.
3686 &BuildKeyList($MaxNbOf{'EMailsShown'},$MinHit{'EMail'},\%_emailr_h,\%_emailr_h);
3687 my %keysinkeylist=();
3688 foreach (@keylist) {
3689 $keysinkeylist{$_}=1;
3690 print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_emailr_h{$_}||0)."${xmlrs}".int($_emailr_k{$_}||0)."${xmlrs}$_emailr_l{$_}${xmlre}\n";
3691 }
3692 foreach (keys %_emailr_h) {
3693 if ($keysinkeylist{$_}) { next; }
3694 print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_emailr_h{$_}||0)."${xmlrs}".int($_emailr_k{$_}||0)."${xmlrs}$_emailr_l{$_}${xmlre}\n";
3695 }
3696 print HISTORYTMP "${xmleb}END_EMAILRECEIVER${xmlee}\n";
3697 rizwank 1.1 }
3698
3699 # Navigation
3700 if ($sectiontosave eq 'session') { # This section must be saved after VISITOR section is read
3701 print HISTORYTMP "\n";
3702 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3703 print HISTORYTMP "# Session range - Number of visits\n";
3704 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3705 print HISTORYTMP "${xmlbb}BEGIN_SESSION${xmlbs}".(scalar keys %_session)."${xmlbe}\n";
3706 foreach (keys %_session) { print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_session{$_})."${xmlre}\n"; }
3707 print HISTORYTMP "${xmleb}END_SESSION${xmlee}\n";
3708 }
3709 if ($sectiontosave eq 'sider') { # This section must be saved after VISITOR section is read
3710 print HISTORYTMP "\n";
3711 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><sortfor>$MaxNbOf{'PageShown'}</sortfor><comment>\n"; }
3712 print HISTORYTMP "# URL - Pages - Bandwidth - Entry - Exit\n";
3713 print HISTORYTMP "# The $MaxNbOf{'PageShown'} first Pages must be first (order not required for others)\n";
3714 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3715 print HISTORYTMP "${xmlbb}BEGIN_SIDER${xmlbs}".(scalar keys %_url_p)."${xmlbe}\n";
3716 # We save page list in score sorted order to get a -output faster and with less use of memory.
3717 &BuildKeyList($MaxNbOf{'PageShown'},$MinHit{'File'},\%_url_p,\%_url_p);
3718 rizwank 1.1 %keysinkeylist=();
3719 foreach (@keylist) {
3720 $keysinkeylist{$_}=1;
3721 my $newkey=$_;
3722 $newkey =~ s/([^:])\/\//$1\//g; # Because some targeted url were taped with 2 / (Ex: //rep//file.htm). We must keep http://rep/file.htm
3723 print HISTORYTMP "${xmlrb}$newkey${xmlrs}".int($_url_p{$_}||0)."${xmlrs}".int($_url_k{$_}||0)."${xmlrs}".int($_url_e{$_}||0)."${xmlrs}".int($_url_x{$_}||0)."${xmlre}\n";
3724 }
3725 foreach (keys %_url_p) {
3726 if ($keysinkeylist{$_}) { next; }
3727 my $newkey=$_;
3728 $newkey =~ s/([^:])\/\//$1\//g; # Because some targeted url were taped with 2 / (Ex: //rep//file.htm). We must keep http://rep/file.htm
3729 print HISTORYTMP "${xmlrb}$newkey ".int($_url_p{$_}||0)."${xmlrs}".int($_url_k{$_}||0)."${xmlrs}".int($_url_e{$_}||0)."${xmlrs}".int($_url_x{$_}||0)."${xmlre}\n";
3730 }
3731 print HISTORYTMP "${xmleb}END_SIDER${xmlee}\n";
3732 }
3733 if ($sectiontosave eq 'filetypes') {
3734 print HISTORYTMP "\n";
3735 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3736 print HISTORYTMP "# Files type - Hits - Bandwidth - Bandwidth without compression - Bandwidth after compression\n";
3737 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3738 print HISTORYTMP "${xmlbb}BEGIN_FILETYPES${xmlbs}".(scalar keys %_filetypes_h)."${xmlbe}\n";
3739 rizwank 1.1 foreach (keys %_filetypes_h) {
3740 my $hits=$_filetypes_h{$_}||0;
3741 my $bytes=$_filetypes_k{$_}||0;
3742 my $bytesbefore=$_filetypes_gz_in{$_}||0;
3743 my $bytesafter=$_filetypes_gz_out{$_}||0;
3744 print HISTORYTMP "${xmlrb}$_${xmlrs}$hits${xmlrs}$bytes${xmlrs}$bytesbefore${xmlrs}$bytesafter${xmlre}\n";
3745 }
3746 print HISTORYTMP "${xmleb}END_FILETYPES${xmlee}\n";
3747 }
3748 if ($sectiontosave eq 'os') {
3749 print HISTORYTMP "\n";
3750 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3751 print HISTORYTMP "# OS ID - Hits\n";
3752 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3753 print HISTORYTMP "${xmlbb}BEGIN_OS${xmlbs}".(scalar keys %_os_h)."${xmlbe}\n";
3754 foreach (keys %_os_h) { print HISTORYTMP "${xmlrb}$_${xmlrs}$_os_h{$_}${xmlre}\n"; }
3755 print HISTORYTMP "${xmleb}END_OS${xmlee}\n";
3756 }
3757 if ($sectiontosave eq 'browser') {
3758 print HISTORYTMP "\n";
3759 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3760 rizwank 1.1 print HISTORYTMP "# Browser ID - Hits\n";
3761 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3762 print HISTORYTMP "${xmlbb}BEGIN_BROWSER${xmlbs}".(scalar keys %_browser_h)."${xmlbe}\n";
3763 foreach (keys %_browser_h) { print HISTORYTMP "${xmlrb}$_${xmlrs}$_browser_h{$_}${xmlre}\n"; }
3764 print HISTORYTMP "${xmleb}END_BROWSER${xmlee}\n";
3765 }
3766 if ($sectiontosave eq 'screensize') {
3767 print HISTORYTMP "\n";
3768 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3769 print HISTORYTMP "# Screen size - Hits\n";
3770 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3771 print HISTORYTMP "${xmlbb}BEGIN_SCREENSIZE${xmlbs}".(scalar keys %_screensize_h)."${xmlbe}\n";
3772 foreach (keys %_screensize_h) { print HISTORYTMP "${xmlrb}$_${xmlrs}$_screensize_h{$_}${xmlre}\n"; }
3773 print HISTORYTMP "${xmleb}END_SCREENSIZE${xmlee}\n";
3774 }
3775
3776 # Referer
3777 if ($sectiontosave eq 'unknownreferer') {
3778 print HISTORYTMP "\n";
3779 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3780 print HISTORYTMP "# Unknown referer OS - Last visit date\n";
3781 rizwank 1.1 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3782 print HISTORYTMP "${xmlbb}BEGIN_UNKNOWNREFERER${xmlbs}".(scalar keys %_unknownreferer_l)."${xmlbe}\n";
3783 foreach (keys %_unknownreferer_l) { print HISTORYTMP "${xmlrb}$_${xmlrs}$_unknownreferer_l{$_}${xmlre}\n"; }
3784 print HISTORYTMP "${xmleb}END_UNKNOWNREFERER${xmlee}\n";
3785 }
3786 if ($sectiontosave eq 'unknownrefererbrowser') {
3787 print HISTORYTMP "\n";
3788 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3789 print HISTORYTMP "# Unknown referer Browser - Last visit date\n";
3790 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3791 print HISTORYTMP "${xmlbb}BEGIN_UNKNOWNREFERERBROWSER${xmlbs}".(scalar keys %_unknownrefererbrowser_l)."${xmlbe}\n";
3792 foreach (keys %_unknownrefererbrowser_l) { print HISTORYTMP "${xmlrb}$_${xmlrs}$_unknownrefererbrowser_l{$_}${xmlre}\n"; }
3793 print HISTORYTMP "${xmleb}END_UNKNOWNREFERERBROWSER${xmlee}\n";
3794 }
3795 if ($sectiontosave eq 'origin') {
3796 print HISTORYTMP "\n";
3797 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3798 print HISTORYTMP "# Origin - Pages - Hits \n";
3799 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3800 print HISTORYTMP "${xmlbb}BEGIN_ORIGIN${xmlbs}6"."${xmlbe}\n";
3801 print HISTORYTMP "${xmlrb}From0${xmlrs}".int($_from_p[0])."${xmlrs}".int($_from_h[0])."${xmlre}\n";
3802 rizwank 1.1 print HISTORYTMP "${xmlrb}From1${xmlrs}".int($_from_p[1])."${xmlrs}".int($_from_h[1])."${xmlre}\n";
3803 print HISTORYTMP "${xmlrb}From2${xmlrs}".int($_from_p[2])."${xmlrs}".int($_from_h[2])."${xmlre}\n";
3804 print HISTORYTMP "${xmlrb}From3${xmlrs}".int($_from_p[3])."${xmlrs}".int($_from_h[3])."${xmlre}\n";
3805 print HISTORYTMP "${xmlrb}From4${xmlrs}".int($_from_p[4])."${xmlrs}".int($_from_h[4])."${xmlre}\n"; # Same site
3806 print HISTORYTMP "${xmlrb}From5${xmlrs}".int($_from_p[5])."${xmlrs}".int($_from_h[5])."${xmlre}\n"; # News
3807 print HISTORYTMP "${xmleb}END_ORIGIN${xmlee}\n";
3808 }
3809 if ($sectiontosave eq 'sereferrals') {
3810 print HISTORYTMP "\n";
3811 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3812 print HISTORYTMP "# Search engine referers ID - Pages - Hits\n";
3813 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3814 print HISTORYTMP "${xmlbb}BEGIN_SEREFERRALS${xmlbs}".(scalar keys %_se_referrals_h)."${xmlbe}\n";
3815 foreach (keys %_se_referrals_h) { print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_se_referrals_p{$_}||0)."${xmlrs}$_se_referrals_h{$_}${xmlre}\n"; }
3816 print HISTORYTMP "${xmleb}END_SEREFERRALS${xmlee}\n";
3817 }
3818 if ($sectiontosave eq 'pagerefs') {
3819 print HISTORYTMP "\n";
3820 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><sortfor>$MaxNbOf{'RefererShown'}</sortfor><comment>\n"; }
3821 print HISTORYTMP "# External page referers - Pages - Hits\n";
3822 print HISTORYTMP "# The $MaxNbOf{'RefererShown'} first Pages must be first (order not required for others)\n";
3823 rizwank 1.1 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3824 print HISTORYTMP "${xmlbb}BEGIN_PAGEREFS${xmlbs}".(scalar keys %_pagesrefs_h)."${xmlbe}\n";
3825 # We save page list in score sorted order to get a -output faster and with less use of memory.
3826 &BuildKeyList($MaxNbOf{'RefererShown'},$MinHit{'Refer'},\%_pagesrefs_h,\%_pagesrefs_p);
3827 %keysinkeylist=();
3828 foreach (@keylist) {
3829 $keysinkeylist{$_}=1;
3830 my $newkey=$_;
3831 $newkey =~ s/^http(s|):\/\/([^\/]+)\/$/http$1:\/\/$2/i; # Remove / at end of http://.../ but not at end of http://.../dir/
3832 print HISTORYTMP "${xmlrb}".XMLEncodeForHisto($newkey)."${xmlrs}".int($_pagesrefs_p{$_}||0)."${xmlrs}$_pagesrefs_h{$_}${xmlre}\n";
3833 }
3834 foreach (keys %_pagesrefs_h) {
3835 if ($keysinkeylist{$_}) { next; }
3836 my $newkey=$_;
3837 $newkey =~ s/^http(s|):\/\/([^\/]+)\/$/http$1:\/\/$2/i; # Remove / at end of http://.../ but not at end of http://.../dir/
3838 print HISTORYTMP "${xmlrb}".XMLEncodeForHisto($newkey)."${xmlrs}".int($_pagesrefs_p{$_}||0)."${xmlrs}$_pagesrefs_h{$_}${xmlre}\n";
3839 }
3840 print HISTORYTMP "${xmleb}END_PAGEREFS${xmlee}\n";
3841 }
3842 if ($sectiontosave eq 'searchwords') {
3843 print HISTORYTMP "\n";
3844 rizwank 1.1 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><sortfor>$MaxNbOf{'KeyphrasesShown'}</sortfor><comment>\n"; }
3845 print HISTORYTMP "# Search keyphrases - Number of search\n";
3846 print HISTORYTMP "# The $MaxNbOf{'KeyphrasesShown'} first number of search must be first (order not required for others)\n";
3847 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3848 print HISTORYTMP "${xmlbb}BEGIN_SEARCHWORDS${xmlbs}".(scalar keys %_keyphrases)."${xmlbe}\n";
3849 # We will also build _keywords
3850 %_keywords=();
3851 # We save key list in score sorted order to get a -output faster and with less use of memory.
3852 &BuildKeyList($MaxNbOf{'KeywordsShown'},$MinHit{'Keyword'},\%_keyphrases,\%_keyphrases);
3853 %keysinkeylist=();
3854 foreach my $key (@keylist) {
3855 $keysinkeylist{$key}=1;
3856 my $keyphrase=$key;
3857 print HISTORYTMP "${xmlrb}$keyphrase${xmlrs}$_keyphrases{$key}${xmlre}\n";
3858 foreach (split(/\+/,$key)) { $_keywords{$_}+=$_keyphrases{$key}; } # To init %_keywords
3859 }
3860 foreach my $key (keys %_keyphrases) {
3861 if ($keysinkeylist{$key}) { next; }
3862 my $keyphrase=$key;
3863 print HISTORYTMP "${xmlrb}$keyphrase${xmlrs}$_keyphrases{$key}${xmlre}\n";
3864 foreach (split(/\+/,$key)) { $_keywords{$_}+=$_keyphrases{$key}; } # To init %_keywords
3865 rizwank 1.1 }
3866 print HISTORYTMP "${xmleb}END_SEARCHWORDS${xmlee}\n";
3867
3868 # Now save keywords section
3869 print HISTORYTMP "\n";
3870 if ($xml) { print HISTORYTMP "<section id='keywords'><sortfor>$MaxNbOf{'KeywordsShown'}</sortfor><comment>\n"; }
3871 print HISTORYTMP "# Search keywords - Number of search\n";
3872 print HISTORYTMP "# The $MaxNbOf{'KeywordsShown'} first number of search must be first (order not required for others)\n";
3873 $ValueInFile{"keywords"}=tell HISTORYTMP;
3874 print HISTORYTMP "${xmlbb}BEGIN_KEYWORDS${xmlbs}".(scalar keys %_keywords)."${xmlbe}\n";
3875 # We save key list in score sorted order to get a -output faster and with less use of memory.
3876 &BuildKeyList($MaxNbOf{'KeywordsShown'},$MinHit{'Keyword'},\%_keywords,\%_keywords);
3877 %keysinkeylist=();
3878 foreach (@keylist) {
3879 $keysinkeylist{$_}=1;
3880 my $keyword=$_;
3881 print HISTORYTMP "${xmlrb}$keyword${xmlrs}$_keywords{$_}${xmlre}\n";
3882 }
3883 foreach (keys %_keywords) {
3884 if ($keysinkeylist{$_}) { next; }
3885 my $keyword=$_;
3886 rizwank 1.1 print HISTORYTMP "${xmlrb}$keyword${xmlrs}$_keywords{$_}${xmlre}\n";
3887 }
3888 print HISTORYTMP "${xmleb}END_KEYWORDS${xmlee}\n";
3889
3890 }
3891
3892 # Other - Errors
3893 if ($sectiontosave eq 'cluster') {
3894 print HISTORYTMP "\n";
3895 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3896 print HISTORYTMP "# Cluster ID - Pages - Hits - Bandwidth\n";
3897 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3898 print HISTORYTMP "${xmlbb}BEGIN_CLUSTER${xmlbs}".(scalar keys %_cluster_h)."${xmlbe}\n";
3899 foreach (keys %_cluster_h) { print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_cluster_p{$_}||0)."${xmlrs}".int($_cluster_h{$_}||0)."${xmlrs}".int($_cluster_k{$_}||0)."${xmlre}\n"; }
3900 print HISTORYTMP "${xmleb}END_CLUSTER${xmlee}\n";
3901 }
3902 if ($sectiontosave eq 'misc') {
3903 print HISTORYTMP "\n";
3904 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3905 print HISTORYTMP "# Misc ID - Pages - Hits - Bandwidth\n";
3906 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3907 rizwank 1.1 print HISTORYTMP "${xmlbb}BEGIN_MISC${xmlbs}".(scalar keys %MiscListCalc)."${xmlbe}\n";
3908 foreach (keys %MiscListCalc) { print HISTORYTMP "${xmlrb}$_${xmlrs}".int($_misc_p{$_}||0)."${xmlrs}".int($_misc_h{$_}||0)."${xmlrs}".int($_misc_k{$_}||0)."${xmlre}\n"; }
3909 print HISTORYTMP "${xmleb}END_MISC${xmlee}\n";
3910 }
3911 if ($sectiontosave eq 'errors') {
3912 print HISTORYTMP "\n";
3913 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3914 print HISTORYTMP "# Errors - Hits - Bandwidth\n";
3915 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3916 print HISTORYTMP "${xmlbb}BEGIN_ERRORS${xmlbs}".(scalar keys %_errors_h)."${xmlbe}\n";
3917 foreach (keys %_errors_h) { print HISTORYTMP "${xmlrb}$_${xmlrs}$_errors_h{$_}${xmlrs}".int($_errors_k{$_}||0)."${xmlre}\n"; }
3918 print HISTORYTMP "${xmleb}END_ERRORS${xmlee}\n";
3919 }
3920 # Other - Trapped errors
3921 foreach my $code (keys %TrapInfosForHTTPErrorCodes) {
3922 if ($sectiontosave eq "sider_$code") {
3923 print HISTORYTMP "\n";
3924 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><comment>\n"; }
3925 print HISTORYTMP "# URL with $code errors - Hits - Last URL referer\n";
3926 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3927 print HISTORYTMP "${xmlbb}BEGIN_SIDER_$code${xmlbs}".(scalar keys %_sider404_h)."${xmlbe}\n";
3928 rizwank 1.1 foreach (keys %_sider404_h) {
3929 my $newkey=$_;
3930 my $newreferer=$_referer404_h{$_}||'';
3931 print HISTORYTMP "${xmlrb}".XMLEncodeForHisto($newkey)."${xmlrs}$_sider404_h{$_}${xmlrs}".XMLEncodeForHisto($newreferer)."${xmlre}\n";
3932 }
3933 print HISTORYTMP "${xmleb}END_SIDER_$code${xmlee}\n";
3934 }
3935 }
3936 # Other - Extra stats sections
3937 foreach my $extranum (1..@ExtraName-1) {
3938 if ($sectiontosave eq "extra_$extranum") {
3939 print HISTORYTMP "\n";
3940 if ($xml) { print HISTORYTMP "<section id='$sectiontosave'><sortfor>$MaxNbOfExtra[$extranum]</sortfor><comment>\n"; }
3941 print HISTORYTMP "# Extra key - Pages - Hits - Bandwidth - Last access\n";
3942 print HISTORYTMP "# The $MaxNbOfExtra[$extranum] first number of hits are first\n";
3943 $ValueInFile{$sectiontosave}=tell HISTORYTMP;
3944 print HISTORYTMP "${xmlbb}BEGIN_EXTRA_$extranum${xmlbs}".scalar (keys %{'_section_' . $extranum . '_h'})."${xmlbe}\n";
3945 &BuildKeyList($MaxNbOfExtra[$extranum],$MinHitExtra[$extranum],\%{'_section_' . $extranum . '_h'},\%{'_section_' . $extranum . '_p'});
3946 %keysinkeylist=();
3947 foreach (@keylist) {
3948 $keysinkeylist{$_}=1;
3949 rizwank 1.1 my $page=${'_section_' . $extranum . '_p'}{$_}||0;
3950 my $bytes=${'_section_' . $extranum . '_k'}{$_}||0;
3951 my $lastaccess=${'_section_' . $extranum . '_l'}{$_}||'';
3952 print HISTORYTMP "${xmlrb}".XMLEncodeForHisto($_)."${xmlrs}$page${xmlrs}", ${'_section_' . $extranum . '_h'}{$_}, "${xmlrs}$bytes${xmlrs}$lastaccess${xmlre}\n"; next;
3953 }
3954 foreach (keys %{'_section_' . $extranum . '_h'}) {
3955 if ($keysinkeylist{$_}) { next; }
3956 my $page=${'_section_' . $extranum . '_p'}{$_}||0;
3957 my $bytes=${'_section_' . $extranum . '_k'}{$_}||0;
3958 my $lastaccess=${'_section_' . $extranum . '_l'}{$_}||'';
3959 print HISTORYTMP "${xmlrb}".XMLEncodeForHisto($_)."${xmlrs}$page${xmlrs}", ${'_section_' . $extranum . '_h'}{$_}, "${xmlrs}$bytes${xmlrs}$lastaccess${xmlre}\n"; next;
3960 }
3961 print HISTORYTMP "${xmleb}END_EXTRA_$extranum${xmlee}\n";
3962 }
3963 }
3964
3965 # Other - Plugin sections
3966 if ($AtLeastOneSectionPlugin && $sectiontosave =~ /^plugin_(\w+)$/i) {
3967 my $pluginname=$1;
3968 if ($PluginsLoaded{'SectionInitHashArray'}{"$pluginname"}) {
3969 my $function="SectionWriteHistory_$pluginname(\$xml,\$xmlbb,\$xmlbs,\$xmlbe,\$xmlrb,\$xmlrs,\$xmlre,\$xmleb,\$xmlee)";
3970 rizwank 1.1 eval("$function");
3971 }
3972 }
3973
3974 %keysinkeylist=();
3975 }
3976
3977 #--------------------------------------------------------------------
3978 # Function: Rename all tmp history file into history
3979 # Parameters: None
3980 # Input: $DirData $PROG $FileSuffix
3981 # $KeepBackupOfHistoricFile $SaveDatabaseFilesWithPermissionsForEveryone
3982 # Output: None
3983 # Return: 1 Ok, 0 at least one error (tmp files are removed)
3984 #--------------------------------------------------------------------
3985 sub Rename_All_Tmp_History {
3986 my $pid=$$;
3987 my $renameok=1;
3988
3989 if ($Debug) { debug("Call to Rename_All_Tmp_History (FileSuffix=$FileSuffix)"); }
3990
3991 rizwank 1.1 opendir(DIR,"$DirData");
3992 my $regfilesuffix=quotemeta($FileSuffix);
3993 foreach (grep /^$PROG(\d\d\d\d\d\d)$regfilesuffix\.tmp\.$pid$/, sort readdir DIR) {
3994 /^$PROG(\d\d\d\d\d\d)$regfilesuffix\.tmp\.$pid$/;
3995 if ($renameok) { # No rename error yet
3996 if ($Debug) { debug(" Rename new tmp history file $PROG$1$FileSuffix.tmp.$$ into $PROG$1$FileSuffix.txt",1); }
3997 if (-s "$DirData/$PROG$1$FileSuffix.tmp.$$") { # Rename tmp files if size > 0
3998 if ($KeepBackupOfHistoricFiles) {
3999 if (-s "$DirData/$PROG$1$FileSuffix.txt") { # History file already exists. We backup it
4000 if ($Debug) { debug(" Make a backup of old history file into $PROG$1$FileSuffix.bak before",1); }
4001 #if (FileCopy("$DirData/$PROG$1$FileSuffix.txt","$DirData/$PROG$1$FileSuffix.bak")) {
4002 if (rename("$DirData/$PROG$1$FileSuffix.txt", "$DirData/$PROG$1$FileSuffix.bak")==0) {
4003 warning("Warning: Failed to make a backup of \"$DirData/$PROG$1$FileSuffix.txt\" into \"$DirData/$PROG$1$FileSuffix.bak\".");
4004 }
4005 if ($SaveDatabaseFilesWithPermissionsForEveryone) {
4006 chmod 0666,"$DirData/$PROG$1$FileSuffix.bak";
4007 }
4008 }
4009 else {
4010 if ($Debug) { debug(" No need to backup old history file",1); }
4011 }
4012 rizwank 1.1 }
4013 if (rename("$DirData/$PROG$1$FileSuffix.tmp.$$", "$DirData/$PROG$1$FileSuffix.txt")==0) {
4014 $renameok=0; # At least one error in renaming working files
4015 # Remove tmp file
4016 unlink "$DirData/$PROG$1$FileSuffix.tmp.$$";
4017 warning("Warning: Failed to rename \"$DirData/$PROG$1$FileSuffix.tmp.$$\" into \"$DirData/$PROG$1$FileSuffix.txt\".\nWrite permissions on \"$PROG$1$FileSuffix.txt\" might be wrong".($ENV{'GATEWAY_INTERFACE'}?" for an 'update from web'":"")." or file might be opened.");
4018 next;
4019 }
4020 if ($SaveDatabaseFilesWithPermissionsForEveryone) {
4021 chmod 0666,"$DirData/$PROG$1$FileSuffix.txt";
4022 }
4023 }
4024 }
4025 else { # Because of rename error, we remove all remaining tmp files
4026 unlink "$DirData/$PROG$1$FileSuffix.tmp.$$";
4027 }
4028 }
4029 close DIR;
4030 return $renameok;
4031 }
4032
4033 rizwank 1.1 #------------------------------------------------------------------------------
4034 # Function: Load DNS cache file entries into a memory hash array
4035 # Parameters: Hash array ref to load into,
4036 # File name to load,
4037 # File suffix to use
4038 # Save to a second plugin file if not up to date
4039 # Input: None
4040 # Output: Hash array is loaded
4041 # Return: 1 No DNS Cache file found, 0 OK
4042 #------------------------------------------------------------------------------
4043 sub Read_DNS_Cache {
4044 my $hashtoload=shift;
4045 my $dnscachefile=shift;
4046 my $filesuffix=shift;
4047 my $savetohash=shift;
4048
4049 my $dnscacheext='';
4050 my $filetoload='';
4051 my $timetoload = time();
4052
4053 if ($Debug) { debug("Call to Read_DNS_Cache [file=\"$dnscachefile\"]"); }
4054 rizwank 1.1 if ($dnscachefile =~ s/(\.\w+)$//) { $dnscacheext=$1; }
4055 foreach my $dir ("$DirData",".","") {
4056 my $searchdir=$dir;
4057 if ($searchdir && (!($searchdir =~ /\/$/)) && (!($searchdir =~ /\\$/)) ) { $searchdir .= "/"; }
4058 if (-f "${searchdir}$dnscachefile$filesuffix$dnscacheext") { $filetoload="${searchdir}$dnscachefile$filesuffix$dnscacheext"; }
4059 # Plugin call : Change filetoload
4060 if ($PluginsLoaded{'SearchFile'}{'hashfiles'}) { SearchFile_hashfiles($searchdir,$dnscachefile,$filesuffix,$dnscacheext,$filetoload); }
4061 if ($filetoload) { last; } # We found a file to load
4062 }
4063
4064 if (! $filetoload) {
4065 if ($Debug) { debug(" No DNS Cache file found"); }
4066 return 1;
4067 }
4068
4069 # Plugin call : Load hashtoload
4070 if ($PluginsLoaded{'LoadCache'}{'hashfiles'}) { LoadCache_hashfiles($filetoload,$hashtoload); }
4071 if (! scalar keys %$hashtoload) {
4072 open(DNSFILE,"$filetoload") or error("Couldn't open DNS Cache file \"$filetoload\": $!");
4073 #binmode DNSFILE; # If we set binmode here, it seems that the load is broken on ActiveState 5.8
4074 # This is a fast way to load with regexp
4075 rizwank 1.1 %$hashtoload = map(/^(?:\d{0,10}\s+)?([0-9A-F:\.]+)\s+([^\s]+)$/oi,<DNSFILE>);
4076 close DNSFILE;
4077 if ($savetohash) {
4078 # Plugin call : Save hash file (all records) with test if up to date to save
4079 if ($PluginsLoaded{'SaveHash'}{'hashfiles'}) { SaveHash_hashfiles($filetoload,$hashtoload,1,0); }
4080 }
4081 }
4082 if ($Debug) { debug(" Loaded ".(scalar keys %$hashtoload)." items from $filetoload in ".(time()-$timetoload)." seconds.",1); }
4083 return 0;
4084 }
4085
4086 #------------------------------------------------------------------------------
4087 # Function: Save a memory hash array into a DNS cache file
4088 # Parameters: Hash array ref to save,
4089 # File name to save,
4090 # File suffix to use
4091 # Input: None
4092 # Output: None
4093 # Return: 0 OK, 1 Error
4094 #------------------------------------------------------------------------------
4095 sub Save_DNS_Cache_File {
4096 rizwank 1.1 my $hashtosave=shift;
4097 my $dnscachefile=shift;
4098 my $filesuffix=shift;
4099
4100 my $dnscacheext='';
4101 my $filetosave='';
4102 my $timetosave = time();
4103 my $nbofelemtosave=$NBOFLASTUPDATELOOKUPTOSAVE;
4104 my $nbofelemsaved=0;
4105
4106 if ($Debug) { debug("Call to Save_DNS_Cache_File [file=\"$dnscachefile\"]"); }
4107 if (! scalar keys %$hashtosave) {
4108 if ($Debug) { debug(" No data to save"); }
4109 return 0;
4110 }
4111 if ($dnscachefile =~ s/(\.\w+)$//) { $dnscacheext=$1; }
4112 $filetosave="$dnscachefile$filesuffix$dnscacheext";
4113 # Plugin call : Save hash file (only $NBOFLASTUPDATELOOKUPTOSAVE records) with no test if up to date
4114 if ($PluginsLoaded{'SaveHash'}{'hashfiles'}) { SaveHash_hashfiles($filetosave,$hashtosave,0,$nbofelemtosave,$nbofelemsaved); }
4115 if (! $nbofelemsaved) {
4116 $filetosave="$dnscachefile$filesuffix$dnscacheext";
4117 rizwank 1.1 if ($Debug) { debug(" Save data ".($nbofelemtosave?"($nbofelemtosave records max)":"(all records)")." into file $filetosave"); }
4118 if (! open(DNSFILE,">$filetosave")) {
4119 warning("Warning: Failed to open for writing last update DNS Cache file \"$filetosave\": $!");
4120 return 1;
4121 }
4122 binmode DNSFILE;
4123 my $starttimemin=int($starttime/60);
4124 foreach my $key (keys %$hashtosave) {
4125 #if ($hashtosave->{$key} ne '*') {
4126 my $ipsolved=$hashtosave->{$key};
4127 print DNSFILE "$starttimemin\t$key\t".($ipsolved eq 'ip'?'*':$ipsolved)."\n"; # Change 'ip' to '*' for backward compatibility
4128 if (++$nbofelemsaved >= $NBOFLASTUPDATELOOKUPTOSAVE) { last; }
4129 #}
4130 }
4131 close DNSFILE;
4132
4133 if ($SaveDatabaseFilesWithPermissionsForEveryone) {
4134 chmod 0666,"$filetosave";
4135 }
4136
4137 }
4138 rizwank 1.1 if ($Debug) { debug(" Saved $nbofelemsaved items into $filetosave in ".(time()-$timetosave)." seconds.",1); }
4139 return 0;
4140 }
4141
4142 #------------------------------------------------------------------------------
4143 # Function: Return time elapsed since last call in miliseconds
4144 # Parameters: 0|1 (0 reset counter, 1 no reset)
4145 # Input: None
4146 # Output: None
4147 # Return: Number of miliseconds elapsed since last call
4148 #------------------------------------------------------------------------------
4149 sub GetDelaySinceStart {
4150 if (shift) { $StartSeconds=0; } # Reset chrono
4151 my ($newseconds, $newmicroseconds)=(time(),0);
4152 # Plugin call : Return seconds and milliseconds
4153 if ($PluginsLoaded{'GetTime'}{'timehires'}) { GetTime_timehires($newseconds, $newmicroseconds); }
4154 if (! $StartSeconds) { $StartSeconds=$newseconds; $StartMicroseconds=$newmicroseconds; }
4155 return (($newseconds-$StartSeconds)*1000+int(($newmicroseconds-$StartMicroseconds)/1000));
4156 }
4157
4158 #------------------------------------------------------------------------------
4159 rizwank 1.1 # Function: Reset all variables whose name start with _ because a new month start
4160 # Parameters: None
4161 # Input: $YearRequired All variables whose name start with _
4162 # Output: All variables whose name start with _
4163 # Return: None
4164 #------------------------------------------------------------------------------
4165 sub Init_HashArray {
4166 if ($Debug) { debug("Call to Init_HashArray"); }
4167 # Reset global hash arrays
4168 %FirstTime = %LastTime = ();
4169 %MonthHostsKnown = %MonthHostsUnknown = ();
4170 %MonthVisits = %MonthUnique = ();
4171 %MonthPages = %MonthHits = %MonthBytes = ();
4172 %MonthNotViewedPages = %MonthNotViewedHits = %MonthNotViewedBytes = ();
4173 %DayPages = %DayHits = %DayBytes = %DayVisits = ();
4174 # Reset all arrays with name beginning by _
4175 for (my $ix=0; $ix<6; $ix++) { $_from_p[$ix]=0; $_from_h[$ix]=0; }
4176 for (my $ix=0; $ix<24; $ix++) { $_time_h[$ix]=0; $_time_k[$ix]=0; $_time_p[$ix]=0; $_time_nv_h[$ix]=0; $_time_nv_k[$ix]=0; $_time_nv_p[$ix]=0; }
4177 # Reset all hash arrays with name beginning by _
4178 %_session = %_browser_h = ();
4179 %_domener_p = %_domener_h = %_domener_k = %_errors_h = %_errors_k = ();
4180 rizwank 1.1 %_filetypes_h = %_filetypes_k = %_filetypes_gz_in = %_filetypes_gz_out = ();
4181 %_host_p = %_host_h = %_host_k = %_host_l = %_host_s = %_host_u = ();
4182 %_waithost_e = %_waithost_l = %_waithost_s = %_waithost_u = ();
4183 %_keyphrases = %_keywords = %_os_h = %_pagesrefs_p = %_pagesrefs_h = %_robot_h = %_robot_k = %_robot_l = %_robot_r = ();
4184 %_worm_h = %_worm_k = %_worm_l = %_login_p = %_login_h = %_login_k = %_login_l = %_screensize_h = ();
4185 %_misc_p = %_misc_h = %_misc_k = ();
4186 %_cluster_p = %_cluster_h = %_cluster_k = ();
4187 %_se_referrals_p = %_se_referrals_h = %_sider404_h = %_referer404_h = %_url_p = %_url_k = %_url_e = %_url_x = ();
4188 %_unknownreferer_l = %_unknownrefererbrowser_l = ();
4189 %_emails_h = %_emails_k = %_emails_l = %_emailr_h = %_emailr_k = %_emailr_l = ();
4190 for (my $ix=1; $ix < @ExtraName; $ix++) {
4191 %{'_section_' . $ix . '_h'} = %{'_section_' . $ix . '_o'} = %{'_section_' . $ix . '_k'} =
4192 %{'_section_' . $ix . '_l'} = %{'_section_' . $ix . '_p'} = ();
4193 }
4194 foreach my $pluginname (keys %{$PluginsLoaded{'SectionInitHashArray'}}) {
4195 my $function="SectionInitHashArray_$pluginname()";
4196 eval("$function");
4197 }
4198 }
4199
4200 #------------------------------------------------------------------------------
4201 rizwank 1.1 # Function: Change word separators of a keyphrase string into space and
4202 # remove bad coded chars
4203 # Parameters: stringtodecode
4204 # Input: None
4205 # Output: None
4206 # Return: decodedstring
4207 #------------------------------------------------------------------------------
4208 sub ChangeWordSeparatorsIntoSpace {
4209 $_[0] =~ s/%0[ad]/ /ig; # LF CR
4210 $_[0] =~ s/%2[02789abc]/ /ig; # space " ' ( ) * + ,
4211 $_[0] =~ s/%3a/ /ig; # :
4212 $_[0] =~ tr/\+\'\(\)\"\*,:/ /s; # "&" and "=" must not be in this list
4213 }
4214
4215 #------------------------------------------------------------------------------
4216 # Function: Transforms special chars by entities as needed in XML/XHTML
4217 # Parameters: stringtoencode
4218 # Return: encodedstring
4219 #------------------------------------------------------------------------------
4220 sub XMLEncode {
4221 if ($BuildReportFormat ne 'xhtml' && $BuildReportFormat ne 'xml') { return shift; }
4222 rizwank 1.1 my $string = shift;
4223 $string =~ s/&/&/g;
4224 $string =~ s/</</g;
4225 $string =~ s/>/>/g;
4226 $string =~ s/\"/&aquot;/g;
4227 $string =~ s/\'/'/g;
4228 return $string;
4229 }
4230
4231 #------------------------------------------------------------------------------
4232 # Function: Transforms spaces into %20 and special chars by entities as needed in XML/XHTML
4233 # Parameters: stringtoencode
4234 # Return: encodedstring
4235 #------------------------------------------------------------------------------
4236 sub XMLEncodeForHisto {
4237 my $string = shift;
4238 $string =~ s/\s/%20/g;
4239 if ($BuildHistoryFormat ne 'xml') { return $string; }
4240 $string =~ s/&/&/g;
4241 $string =~ s/</</g;
4242 $string =~ s/>/>/g;
4243 rizwank 1.1 $string =~ s/\"/&aquot;/g;
4244 $string =~ s/\'/'/g;
4245 return $string;
4246 }
4247
4248 #------------------------------------------------------------------------------
4249 # Function: Encode a binary string into an ASCII string
4250 # Parameters: stringtoencode
4251 # Return: encodedstring
4252 #------------------------------------------------------------------------------
4253 sub EncodeString {
4254 my $string = shift;
4255 # use bytes;
4256 $string =~ s/([\x2B\x80-\xFF])/sprintf ("%%%2x", ord($1))/eg;
4257 # no bytes;
4258 $string =~ tr/ /+/s;
4259 return $string;
4260 }
4261
4262 #------------------------------------------------------------------------------
4263 # Function: Decode an only text string into a binary string
4264 rizwank 1.1 # Parameters: stringtodecode
4265 # Input: None
4266 # Output: None
4267 # Return: decodedstring
4268 #------------------------------------------------------------------------------
4269 sub DecodeEncodedString {
4270 my $stringtodecode=shift;
4271 $stringtodecode =~ tr/\+/ /s;
4272 $stringtodecode =~ s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/ieg;
4273 return $stringtodecode;
4274 }
4275
4276 #------------------------------------------------------------------------------
4277 # Function: Decode an precompiled regex value to a common regex value
4278 # Parameters: compiledregextodecode
4279 # Input: None
4280 # Output: None
4281 # Return: standardregex
4282 #------------------------------------------------------------------------------
4283 sub UnCompileRegex {
4284 shift =~ /\(\?[-\w]*:(.*)\)/;
4285 rizwank 1.1 return $1;
4286 }
4287
4288 #------------------------------------------------------------------------------
4289 # Function: Clean a string of all chars that are not char or _ - \ / . \s
4290 # Parameters: stringtoclean
4291 # Input: None
4292 # Output: None
4293 # Return: cleanedstring
4294 #------------------------------------------------------------------------------
4295 sub Sanitize {
4296 my $stringtoclean=shift;
4297 $stringtoclean =~ s/[^\w_\-\\\/\.\s]//g;
4298 return $stringtoclean;
4299 }
4300
4301 #------------------------------------------------------------------------------
4302 # Function: Clean a string of HTML tags to avoid 'Cross Site Scripting attacks'
4303 # Parameters: stringtoclean
4304 # Input: None
4305 # Output: None
4306 rizwank 1.1 # Return: cleanedstring
4307 #------------------------------------------------------------------------------
4308 sub CleanFromCSSA {
4309 my $stringtoclean=shift;
4310 $stringtoclean =~ s/</</g;
4311 $stringtoclean =~ s/>/>/g;
4312 return $stringtoclean;
4313 }
4314
4315 #------------------------------------------------------------------------------
4316 # Function: Clean tags in a string
4317 # Parameters: stringtodecode
4318 # Input: None
4319 # Output: None
4320 # Return: decodedstring
4321 #------------------------------------------------------------------------------
4322 sub CleanFromTags {
4323 my $stringtoclean=shift;
4324 $stringtoclean =~ s/$regclean1/ /g; # Replace <recnb> or </td> with space
4325 $stringtoclean =~ s/$regclean2//g; # Remove <xxx>
4326 return $stringtoclean;
4327 rizwank 1.1 }
4328
4329 #------------------------------------------------------------------------------
4330 # Function: Copy one file into another
4331 # Parameters: sourcefilename targetfilename
4332 # Input: None
4333 # Output: None
4334 # Return: 0 if copy is ok, 1 else
4335 #------------------------------------------------------------------------------
4336 sub FileCopy {
4337 my $filesource = shift;
4338 my $filetarget = shift;
4339 if ($Debug) { debug("FileCopy($filesource,$filetarget)",1); }
4340 open(FILESOURCE,"$filesource") || return 1;
4341 open(FILETARGET,">$filetarget") || return 1;
4342 binmode FILESOURCE;
4343 binmode FILETARGET;
4344 # ...
4345 close(FILETARGET);
4346 close(FILESOURCE);
4347 if ($Debug) { debug(" File copied",1); }
4348 rizwank 1.1 return 0;
4349 }
4350
4351 #------------------------------------------------------------------------------
4352 # Function: Show flags for other language translations
4353 # Parameters: Current languade id (en, fr, ...)
4354 # Input: None
4355 # Output: None
4356 # Return: None
4357 #------------------------------------------------------------------------------
4358 sub Show_Flag_Links {
4359 my $CurrentLang = shift;
4360
4361 # Build flags link
4362 my $NewLinkParams=$QueryString;
4363 my $NewLinkTarget='';
4364 if ($ENV{'GATEWAY_INTERFACE'}) {
4365 $NewLinkParams =~ s/(^|&)update(=\w*|$)//i;
4366 $NewLinkParams =~ s/(^|&)staticlinks(=\w*|$)//i;
4367 $NewLinkParams =~ s/(^|&)framename=[^&]*//i;
4368 $NewLinkParams =~ s/(^|&)lang=[^&]*//i;
4369 rizwank 1.1 if ($FrameName eq 'mainright') { $NewLinkTarget=" target=\"_parent\""; }
4370 $NewLinkParams =~ tr/&/&/s; $NewLinkParams =~ s/^&//; $NewLinkParams =~ s/&$//;
4371 if ($NewLinkParams) { $NewLinkParams="${NewLinkParams}&"; }
4372 }
4373 else {
4374 $NewLinkParams=($SiteConfig?"config=$SiteConfig&":"")."year=$YearRequired&month=$MonthRequired&";
4375 }
4376 if ($FrameName eq 'mainright') { $NewLinkParams.='framename=index&'; }
4377
4378 foreach my $lng (split(/\s+/,$ShowFlagLinks)) {
4379 $lng=$LangBrowserToLangAwstats{$lng}?$LangBrowserToLangAwstats{$lng}:$lng;
4380 if ($lng ne $CurrentLang) {
4381 my %lngtitle=('en','English','fr','French','de','German','it','Italian','nl','Dutch','es','Spanish');
4382 my $lngtitle=($lngtitle{$lng}?$lngtitle{$lng}:$lng);
4383 my $flag=($LangAWStatsToFlagAwstats{$lng}?$LangAWStatsToFlagAwstats{$lng}:$lng);
4384 print "<a href=\"".XMLEncode("$AWScript?${NewLinkParams}lang=$lng")."\"$NewLinkTarget><img src=\"$DirIcons\/flags\/$flag.png\" height=\"14\" border=\"0\"".AltTitle("$lngtitle")." /></a> \n";
4385 }
4386 }
4387 }
4388
4389 #------------------------------------------------------------------------------
4390 rizwank 1.1 # Function: Format value in bytes in a string (Bytes, Kb, Mb, Gb)
4391 # Parameters: bytes (integer value or "0.00")
4392 # Input: None
4393 # Output: None
4394 # Return: "x.yz MB" or "x.yy KB" or "x Bytes" or "0"
4395 #------------------------------------------------------------------------------
4396 sub Format_Bytes {
4397 my $bytes = shift||0;
4398 my $fudge = 1;
4399 # Do not use exp/log function to calculate 1024power, function make segfault on some unix/perl versions
4400 if ($bytes >= ($fudge << 30)) { return sprintf("%.2f", $bytes/1073741824)." $Message[110]"; }
4401 if ($bytes >= ($fudge << 20)) { return sprintf("%.2f", $bytes/1048576)." $Message[109]"; }
4402 if ($bytes >= ($fudge << 10)) { return sprintf("%.2f", $bytes/1024)." $Message[108]"; }
4403 if ($bytes < 0) { $bytes="?"; }
4404 return int($bytes).(int($bytes)?" $Message[119]":"");
4405 }
4406
4407 #------------------------------------------------------------------------------
4408 # Function: Format a number
4409 # Parameters: number
4410 # Input: None
4411 rizwank 1.1 # Output: None
4412 # Return: "999 999 999 999"
4413 #------------------------------------------------------------------------------
4414 sub Format_Number {
4415 my $number = shift||0;
4416 $number=~s/(\d)(\d\d\d)$/$1 $2/;
4417 $number=~s/(\d)(\d\d\d\s\d\d\d)$/$1 $2/;
4418 $number=~s/(\d)(\d\d\d\s\d\d\d\s\d\d\d)$/$1 $2/;
4419 return $number;
4420 }
4421
4422 #------------------------------------------------------------------------------
4423 # Function: Return " alt=string title=string"
4424 # Parameters: string
4425 # Input: None
4426 # Output: None
4427 # Return: "alt=string title=string"
4428 #------------------------------------------------------------------------------
4429 sub AltTitle {
4430 my $string = shift||'';
4431 return " alt='$string' title='$string'";
4432 rizwank 1.1 # return " alt=\"$string\" title=\"$string\"";
4433 # return ($BuildReportFormat?"":" alt=\"$string\"")." title=\"$string\"";
4434 }
4435
4436 #------------------------------------------------------------------------------
4437 # Function: Tell if an email is a local or external email
4438 # Parameters: email
4439 # Input: $SiteDomain(exact string) $HostAliases(quoted regex string)
4440 # Output: None
4441 # Return: -1, 0 or 1
4442 #------------------------------------------------------------------------------
4443 sub IsLocalEMail {
4444 my $email=shift||'unknown';
4445 if ($email !~ /\@(.*)$/) { return 0; }
4446 my $domain=$1;
4447 if ($domain =~ /^$SiteDomain$/i) { return 1; }
4448 foreach (@HostAliases) { if ($domain =~ /$_/) { return 1; } }
4449 return -1;
4450 }
4451
4452 #------------------------------------------------------------------------------
4453 rizwank 1.1 # Function: Format a date according to Message[78] (country date format)
4454 # Parameters: String date YYYYMMDDHHMMSS
4455 # Option 0=LastUpdate and LastTime date
4456 # 1=Arrays date except daymonthvalues
4457 # 2=daymonthvalues date (only year month and day)
4458 # Input: $Message[78]
4459 # Output: None
4460 # Return: Date with format defined by Message[78] and option
4461 #------------------------------------------------------------------------------
4462 sub Format_Date {
4463 my $date=shift;
4464 my $option=shift||0;
4465 my $year=substr("$date",0,4);
4466 my $month=substr("$date",4,2);
4467 my $day=substr("$date",6,2);
4468 my $hour=substr("$date",8,2);
4469 my $min=substr("$date",10,2);
4470 my $sec=substr("$date",12,2);
4471 my $dateformat=$Message[78];
4472 if ($option == 2) {
4473 $dateformat =~ s/^[^ymd]+//g;
4474 rizwank 1.1 $dateformat =~ s/[^ymd]+$//g;
4475 }
4476 $dateformat =~ s/yyyy/$year/g;
4477 $dateformat =~ s/yy/$year/g;
4478 $dateformat =~ s/mmm/$MonthNumLib{$month}/g;
4479 $dateformat =~ s/mm/$month/g;
4480 $dateformat =~ s/dd/$day/g;
4481 $dateformat =~ s/HH/$hour/g;
4482 $dateformat =~ s/MM/$min/g;
4483 $dateformat =~ s/SS/$sec/g;
4484 return "$dateformat";
4485 }
4486
4487 #------------------------------------------------------------------------------
4488 # Function: Return 1 if string contains only ascii chars
4489 # Parameters: string
4490 # Input: None
4491 # Output: None
4492 # Return: 0 or 1
4493 #------------------------------------------------------------------------------
4494 sub IsAscii {
4495 rizwank 1.1 my $string=shift;
4496 if ($Debug) { debug("IsAscii($string)",5); }
4497 if ($string =~ /^[\w\+\-\/\\\.%,;:=\"\'&?!\s]+$/) {
4498 if ($Debug) { debug(" Yes",6); }
4499 return 1; # Only alphanum chars (and _) or + - / \ . % , ; : = " ' & ? space \t
4500 }
4501 if ($Debug) { debug(" No",6); }
4502 return 0;
4503 }
4504
4505 #------------------------------------------------------------------------------
4506 # Function: Return the lower value between 2 but exclude value if 0
4507 # Parameters: Val1 and Val2
4508 # Input: None
4509 # Output: None
4510 # Return: min(Val1,Val2)
4511 #------------------------------------------------------------------------------
4512 sub MinimumButNoZero {
4513 my ($val1,$val2)=@_;
4514 return ($val1&&($val1<$val2||!$val2)?$val1:$val2);
4515 }
4516 rizwank 1.1
4517 #------------------------------------------------------------------------------
4518 # Function: Add a val from sorting tree
4519 # Parameters: keytoadd keyval [firstadd]
4520 # Input: None
4521 # Output: None
4522 # Return: None
4523 #------------------------------------------------------------------------------
4524 sub AddInTree {
4525 my $keytoadd=shift;
4526 my $keyval=shift;
4527 my $firstadd=shift||0;
4528 if ($firstadd==1) { # Val is the first one
4529 if ($Debug) { debug(" firstadd",4); }
4530 $val{$keyval}=$keytoadd;
4531 $lowerval=$keyval;
4532 if ($Debug) { debug(" lowerval=$lowerval, nb elem val=".(scalar keys %val).", nb elem egal=".(scalar keys %egal).".",4); }
4533 return;
4534 }
4535 if ($val{$keyval}) { # Val is already in tree
4536 if ($Debug) { debug(" val is already in tree",4); }
4537 rizwank 1.1 $egal{$keytoadd}=$val{$keyval};
4538 $val{$keyval}=$keytoadd;
4539 if ($Debug) { debug(" lowerval=$lowerval, nb elem val=".(scalar keys %val).", nb elem egal=".(scalar keys %egal).".",4); }
4540 return;
4541 }
4542 if ($keyval <= $lowerval) { # Val is a new one lower (should happens only when tree is not full)
4543 if ($Debug) { debug(" keytoadd val=$keyval is lower or equal to lowerval=$lowerval",4); }
4544 $val{$keyval}=$keytoadd;
4545 $nextval{$keyval}=$lowerval;
4546 $lowerval=$keyval;
4547 if ($Debug) { debug(" lowerval=$lowerval, nb elem val=".(scalar keys %val).", nb elem egal=".(scalar keys %egal).".",4); }
4548 return;
4549 }
4550 # Val is a new one higher
4551 if ($Debug) { debug(" keytoadd val=$keyval is higher than lowerval=$lowerval",4); }
4552 $val{$keyval}=$keytoadd;
4553 my $valcursor=$lowerval; # valcursor is value just before keyval
4554 while ($nextval{$valcursor} && ($nextval{$valcursor} < $keyval)) { $valcursor=$nextval{$valcursor}; }
4555 if ($nextval{$valcursor}) { # keyval is between valcursor and nextval{valcursor}
4556 $nextval{$keyval}=$nextval{$valcursor};
4557 }
4558 rizwank 1.1 $nextval{$valcursor}=$keyval;
4559 if ($Debug) { debug(" lowerval=$lowerval, nb elem val=".(scalar keys %val).", nb elem egal=".(scalar keys %egal).".",4); }
4560 }
4561
4562 #------------------------------------------------------------------------------
4563 # Function: Remove a val from sorting tree
4564 # Parameters: None
4565 # Input: $lowerval %val %egal
4566 # Output: None
4567 # Return: None
4568 #------------------------------------------------------------------------------
4569 sub Removelowerval {
4570 my $keytoremove=$val{$lowerval}; # This is lower key
4571 if ($Debug) { debug(" remove for lowerval=$lowerval: key=$keytoremove",4); }
4572 if ($egal{$keytoremove}) {
4573 $val{$lowerval}=$egal{$keytoremove};
4574 delete $egal{$keytoremove};
4575 }
4576 else {
4577 delete $val{$lowerval};
4578 $lowerval=$nextval{$lowerval}; # Set new lowerval
4579 rizwank 1.1 }
4580 if ($Debug) { debug(" new lower value=$lowerval, val size=".(scalar keys %val).", egal size=".(scalar keys %egal),4); }
4581 }
4582
4583 #------------------------------------------------------------------------------
4584 # Function: Build @keylist array
4585 # Parameters: Size max for @keylist array,
4586 # Min value in hash for select,
4587 # Hash used for select,
4588 # Hash used for order
4589 # Input: None
4590 # Output: None
4591 # Return: @keylist response array
4592 #------------------------------------------------------------------------------
4593 sub BuildKeyList {
4594 my $ArraySize=shift||error("System error. Call to BuildKeyList function with incorrect value for first param","","",1);
4595 my $MinValue=shift||error("System error. Call to BuildKeyList function with incorrect value for second param","","",1);
4596 my $hashforselect=shift;
4597 my $hashfororder=shift;
4598 if ($Debug) { debug(" BuildKeyList($ArraySize,$MinValue,$hashforselect with size=".(scalar keys %$hashforselect).",$hashfororder with size=".(scalar keys %$hashfororder).")",3); }
4599 delete $hashforselect->{0};delete $hashforselect->{''}; # Those is to protect from infinite loop when hash array has an incorrect null key
4600 rizwank 1.1 my $count=0;
4601 $lowerval=0; # Global because used in AddInTree and Removelowerval
4602 %val=(); %nextval=(); %egal=();
4603 foreach my $key (keys %$hashforselect) {
4604 if ($count < $ArraySize) {
4605 if ($hashforselect->{$key} >= $MinValue) {
4606 $count++;
4607 if ($Debug) { debug(" Add in tree entry $count : $key (value=".($hashfororder->{$key}||0).", tree not full)",4); }
4608 AddInTree($key,$hashfororder->{$key}||0,$count);
4609 }
4610 next;
4611 }
4612 $count++;
4613 if (($hashfororder->{$key}||0)<=$lowerval) { next; }
4614 if ($Debug) { debug(" Add in tree entry $count : $key (value=".($hashfororder->{$key}||0)." > lowerval=$lowerval)",4); }
4615 AddInTree($key,$hashfororder->{$key}||0);
4616 if ($Debug) { debug(" Removelower in tree",4); }
4617 Removelowerval();
4618 }
4619
4620 # Build key list and sort it
4621 rizwank 1.1 if ($Debug) { debug(" Build key list and sort it. lowerval=$lowerval, nb elem val=".(scalar keys %val).", nb elem egal=".(scalar keys %egal).".",3); }
4622 my %notsortedkeylist=();
4623 foreach my $key (values %val) { $notsortedkeylist{$key}=1; }
4624 foreach my $key (values %egal) { $notsortedkeylist{$key}=1; }
4625 @keylist=();
4626 @keylist=(sort {($hashfororder->{$b}||0) <=> ($hashfororder->{$a}||0) } keys %notsortedkeylist);
4627 if ($Debug) { debug(" BuildKeyList End (keylist size=".(@keylist).")",3); }
4628 return;
4629 }
4630
4631 #------------------------------------------------------------------------------
4632 # Function: Lock or unlock update
4633 # Parameters: status (1 to lock, 0 to unlock)
4634 # Input: $DirLock (if status=0) $PROG $FileSuffix
4635 # Output: $DirLock (if status=1)
4636 # Return: None
4637 #------------------------------------------------------------------------------
4638 sub Lock_Update {
4639 my $status=shift;
4640 my $lock="$PROG$FileSuffix.lock";
4641 if ($status) {
4642 rizwank 1.1 # We stop if there is at least one lock file wherever it is
4643 foreach my $key ($ENV{"TEMP"},$ENV{"TMP"},"/tmp","/",".") {
4644 my $newkey =$key;
4645 $newkey =~ s/[\\\/]$//;
4646 if (-f "$newkey/$lock") { error("An AWStats update process seems to be already running for this config file. Try later.\nIf this is not true, remove manually lock file '$newkey/$lock'.","","",1); }
4647 }
4648 # Set lock where we can
4649 foreach my $key ($ENV{"TEMP"},$ENV{"TMP"},"/tmp","/",".") {
4650 if (! -d "$key") { next; }
4651 $DirLock=$key;
4652 $DirLock =~ s/[\\\/]$//;
4653 if ($Debug) { debug("Update lock file $DirLock/$lock is set"); }
4654 open(LOCK,">$DirLock/$lock") || error("Failed to create lock file $DirLock/$lock","","",1);
4655 print LOCK "AWStats update started by process $$ at $nowyear-$nowmonth-$nowday $nowhour:$nowmin:$nowsec\n";
4656 close(LOCK);
4657 last;
4658 }
4659 }
4660 else {
4661 # Remove lock
4662 if ($Debug) { debug("Update lock file $DirLock/$lock is removed"); }
4663 rizwank 1.1 unlink("$DirLock/$lock");
4664 }
4665 return;
4666 }
4667
4668 #------------------------------------------------------------------------------
4669 # Function: Signal handler to call Lock_Update to remove lock file
4670 # Parameters: Signal name
4671 # Input: None
4672 # Output: None
4673 # Return: None
4674 #------------------------------------------------------------------------------
4675 sub SigHandler {
4676 my $signame = shift;
4677 print ucfirst($PROG)." process (ID $$) interrupted by signal $signame.\n";
4678 &Lock_Update(0);
4679 exit 1;
4680 }
4681
4682 #------------------------------------------------------------------------------
4683 # Function: Convert an IPAddress into an integer
4684 rizwank 1.1 # Parameters: IPAddress
4685 # Input: None
4686 # Output: None
4687 # Return: Int
4688 #------------------------------------------------------------------------------
4689 sub Convert_IP_To_Decimal {
4690 my ($IPAddress) = @_;
4691 my @ip_seg_arr = split(/\./,$IPAddress);
4692 my $decimal_ip_address = 256 * 256 *256 * $ip_seg_arr[0] + 256 * 256 * $ip_seg_arr[1] + 256 * $ip_seg_arr[2] + $ip_seg_arr[3];
4693 return($decimal_ip_address);
4694 }
4695
4696 #------------------------------------------------------------------------------
4697 # Function: Test there is at least on value in list not null
4698 # Parameters: List of values
4699 # Input: None
4700 # Output: None
4701 # Return: 1 There is at least one not null value, 0 else
4702 #------------------------------------------------------------------------------
4703 sub AtLeastOneNotNull {
4704 if ($Debug) { debug(" Call to AtLeastOneNotNull (".join('-',@_).")",3); }
4705 rizwank 1.1 foreach my $val (@_) { if ($val) { return 1; } }
4706 return 0;
4707 }
4708
4709 #------------------------------------------------------------------------------
4710 # Function: Return the string to add in html tag to include popup javascript code
4711 # Parameters: tooltip number
4712 # Input: None
4713 # Output: None
4714 # Return: string with javascript code
4715 #------------------------------------------------------------------------------
4716 sub Tooltip {
4717 my $ttnb=shift;
4718 return ($TOOLTIPON?" onmouseover=\"ShowTip($ttnb);\" onmouseout=\"HideTip($ttnb);\"":"");
4719 }
4720
4721 #------------------------------------------------------------------------------
4722 # Function: Insert a form filter
4723 # Parameters: Name of filter field, default for filter field, default for exclude filter field
4724 # Input: $StaticLinks, $QueryString, $SiteConfig, $DirConfig
4725 # Output: HTML Form
4726 rizwank 1.1 # Return: None
4727 #------------------------------------------------------------------------------
4728 sub ShowFormFilter {
4729 my $fieldfiltername=shift;
4730 my $fieldfilterinvalue=shift;
4731 my $fieldfilterexvalue=shift;
4732 if (! $StaticLinks) {
4733 my $NewLinkParams=${QueryString};
4734 $NewLinkParams =~ s/(^|&)update(=\w*|$)//i;
4735 $NewLinkParams =~ s/(^|&)output(=\w*|$)//i;
4736 $NewLinkParams =~ s/(^|&)staticlinks(=\w*|$)//i;
4737 $NewLinkParams =~ tr/&/&/s; $NewLinkParams =~ s/^&//; $NewLinkParams =~ s/&$//;
4738 if ($NewLinkParams) { $NewLinkParams="${NewLinkParams}&"; }
4739 print "\n<form name=\"FormFilter\" action=\"".XMLEncode("$AWScript?${NewLinkParams}")."\" class=\"aws_border\">\n";
4740 print "<table valign=\"middle\" width=\"99%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\"><tr>\n";
4741 print "<td align=\"left\" width=\"50\">$Message[79] :</td>\n";
4742 print "<td align=\"left\" width=\"100\"><input type=\"text\" name=\"${fieldfiltername}\" value=\"$fieldfilterinvalue\" class=\"aws_formfield\" /></td>\n";
4743 print "<td> </td>";
4744 print "<td align=\"left\" width=\"100\">$Message[153] :</td>\n";
4745 print "<td align=\"left\" width=\"100\"><input type=\"text\" name=\"${fieldfiltername}ex\" value=\"$fieldfilterexvalue\" class=\"aws_formfield\" /></td>\n";
4746 print "<td>";
4747 rizwank 1.1 print "<input type=\"hidden\" name=\"output\" value=\"".join(',',keys %HTMLOutput)."\" />\n";
4748 if ($SiteConfig) { print "<input type=\"hidden\" name=\"config\" value=\"$SiteConfig\" />\n"; }
4749 if ($DirConfig) { print "<input type=\"hidden\" name=\"configdir\" value=\"$DirConfig\" />\n"; }
4750 if ($QueryString =~ /(^|&)year=(\d\d\d\d)/i) { print "<input type=\"hidden\" name=\"year\" value=\"$2\" />\n"; }
4751 if ($QueryString =~ /(^|&)month=(\d\d)/i || $QueryString =~ /(^|&)month=(all)/i) { print "<input type=\"hidden\" name=\"month\" value=\"$2\" />\n"; }
4752 if ($QueryString =~ /(^|&)lang=(\w+)/i) { print "<input type=\"hidden\" name=\"lang\" value=\"$2\" />\n"; }
4753 if ($QueryString =~ /(^|&)debug=(\d+)/i) { print "<input type=\"hidden\" name=\"debug\" value=\"$2\" />\n"; }
4754 if ($QueryString =~ /(^|&)framename=(\w+)/i) { print "<input type=\"hidden\" name=\"framename\" value=\"$2\" />\n"; }
4755 print "<input type=\"submit\" value=\" $Message[115] \" class=\"aws_button\" /></td>\n";
4756 print "<td> </td>";
4757 print "</tr></table>\n";
4758 print "</form>\n";
4759 print "<br />\n";
4760 print "\n";
4761 }
4762 }
4763
4764 #------------------------------------------------------------------------------
4765 # Function: Write other user info (with help of plugin)
4766 # Parameters: $user
4767 # Input: $SiteConfig
4768 rizwank 1.1 # Output: URL link
4769 # Return: None
4770 #------------------------------------------------------------------------------
4771 sub ShowUserInfo {
4772 my $user=shift;
4773 # Call to plugins' function ShowInfoUser
4774 foreach my $pluginname (sort keys %{$PluginsLoaded{'ShowInfoUser'}}) {
4775 my $function="ShowInfoUser_$pluginname('$user')";
4776 eval("$function");
4777 }
4778 }
4779
4780 #------------------------------------------------------------------------------
4781 # Function: Write other cluster info (with help of plugin)
4782 # Parameters: $clusternb
4783 # Input: $SiteConfig
4784 # Output: Cluster info
4785 # Return: None
4786 #------------------------------------------------------------------------------
4787 sub ShowClusterInfo {
4788 my $user=shift;
4789 rizwank 1.1 # Call to plugins' function ShowInfoCluster
4790 foreach my $pluginname (sort keys %{$PluginsLoaded{'ShowInfoCluster'}}) {
4791 my $function="ShowInfoCluster_$pluginname('$user')";
4792 eval("$function");
4793 }
4794 }
4795
4796 #------------------------------------------------------------------------------
4797 # Function: Write other host info (with help of plugin)
4798 # Parameters: $host
4799 # Input: $LinksToWhoIs $LinksToWhoIsIp
4800 # Output: None
4801 # Return: None
4802 #------------------------------------------------------------------------------
4803 sub ShowHostInfo {
4804 my $host=shift;
4805 # Call to plugins' function ShowInfoHost
4806 foreach my $pluginname (sort keys %{$PluginsLoaded{'ShowInfoHost'}}) {
4807 my $function="ShowInfoHost_$pluginname('$host')";
4808 eval("$function");
4809 }
4810 rizwank 1.1 }
4811
4812 #------------------------------------------------------------------------------
4813 # Function: Write other url info (with help of plugin)
4814 # Parameters: $url
4815 # Input: %Aliases $MaxLengthOfShownURL $ShowLinksOnUrl $SiteDomain $UseHTTPSLinkForUrl
4816 # Output: URL link
4817 # Return: None
4818 #------------------------------------------------------------------------------
4819 sub ShowURLInfo {
4820 my $url=shift;
4821 my $nompage=CleanFromCSSA($url);
4822
4823 # Call to plugins' function ShowInfoURL
4824 foreach my $pluginname (keys %{$PluginsLoaded{'ShowInfoURL'}}) {
4825 my $function="ShowInfoURL_$pluginname('$url')";
4826 eval("$function");
4827 }
4828
4829 if (length($nompage)>$MaxLengthOfShownURL) { $nompage=substr($nompage,0,$MaxLengthOfShownURL)."..."; }
4830 if ($ShowLinksOnUrl) {
4831 rizwank 1.1 my $newkey=CleanFromCSSA($url);
4832 if ($LogType eq 'W' || $LogType eq 'S') { # Web or streaming log file
4833 if ($newkey =~ /^http(s|):/i) { # URL seems to be extracted from a proxy log file
4834 print "<a href=\"".XMLEncode("$newkey")."\" target=\"url\">".XMLEncode($nompage)."</a>";
4835 }
4836 elsif ($newkey =~ /^\//) { # URL seems to be an url extracted from a web or wap server log file
4837 $newkey =~ s/^\/$SiteDomain//i;
4838 # Define urlprot
4839 my $urlprot='http';
4840 if ($UseHTTPSLinkForUrl && $newkey =~ /^$UseHTTPSLinkForUrl/) { $urlprot='https'; }
4841 print "<a href=\"".XMLEncode("$urlprot://$SiteDomain$newkey")."\" target=\"url\">".XMLEncode($nompage)."</a>";
4842 }
4843 else {
4844 print XMLEncode($nompage);
4845 }
4846 }
4847 elsif ($LogType eq 'F') { # Ftp log file
4848 print XMLEncode($nompage);
4849 }
4850 elsif ($LogType eq 'M') { # Smtp log file
4851 print XMLEncode($nompage);
4852 rizwank 1.1 }
4853 else { # Other type log file
4854 print XMLEncode($nompage);
4855 }
4856 }
4857 else {
4858 print XMLEncode($nompage);
4859 }
4860 }
4861
4862 #------------------------------------------------------------------------------
4863 # Function: Define value for PerlParsingFormat (used for regex log record parsing)
4864 # Parameters: -
4865 # Input: $LogFormat
4866 # Output: @fieldlib
4867 # Return: -
4868 #------------------------------------------------------------------------------
4869 sub DefinePerlParsingFormat {
4870 # Log records examples:
4871 # Apache combined: 62.161.78.73 user - [dd/mmm/yyyy:hh:mm:ss +0000] "GET / HTTP/1.1" 200 1234 "http://www.from.com/from.htm" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
4872 # Apache combined (408 error): my.domain.com - user [09/Jan/2001:11:38:51 -0600] "OPTIONS /mime-tmp/xxx file.doc HTTP/1.1" 408 - "-" "-"
4873 rizwank 1.1 # Apache combined (408 error): 62.161.78.73 user - [dd/mmm/yyyy:hh:mm:ss +0000] "-" 408 - "-" "-"
4874 # Apache common_with_mod_gzip_info1: %h %l %u %t \"%r\" %>s %b mod_gzip: %{mod_gzip_compression_ratio}npct.
4875 # Apache common_with_mod_gzip_info2: %h %l %u %t \"%r\" %>s %b mod_gzip: %{mod_gzip_result}n In:%{mod_gzip_input_size}n Out:%{mod_gzip_output_size}n:%{mod_gzip_compression_ratio}npct.
4876 # Apache deflate: %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" (%{ratio}n)
4877 # IIS: 2000-07-19 14:14:14 62.161.78.73 - GET / 200 1234 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0) http://www.from.com/from.htm
4878 # WebStar: 05/21/00 00:17:31 OK 200 212.242.30.6 Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt) http://www.cover.dk/ "www.cover.dk" :Documentation:graphics:starninelogo.white.gif 1133
4879 # Squid extended: 12.229.91.170 - - [27/Jun/2002:03:30:50 -0700] "GET http://www.callistocms.com/images/printable.gif HTTP/1.1" 304 354 "-" "Mozilla/5.0 Galeon/1.0.3 (X11; Linux i686; U;) Gecko/0" TCP_REFRESH_HIT:DIRECT
4880 if ($Debug) { debug("Call To DefinePerlParsingFormat (LogType='$LogType', LogFormat='$LogFormat')"); }
4881 @fieldlib=();
4882 if ($LogFormat =~ /^[1-6]$/) { # Pre-defined log format
4883 if ($LogFormat eq '1' || $LogFormat eq '6') { # Same than "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"".
4884 # %u (user) is "([^\\[]+)" instead of "[^ ]+" because can contain space (Lotus Notes). referer and ua might be "".
4885 # $PerlParsingFormat="([^ ]+) [^ ]+ ([^\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) (.+) [^\\\"]+\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\"";
4886 $PerlParsingFormat="([^ ]+) [^ ]+ ([^\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) ([^ ]+) [^\\\"]+\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\"";
4887 $pos_host=0;$pos_logname=1;$pos_date=2;$pos_method=3;$pos_url=4;$pos_code=5;$pos_size=6;$pos_referer=7;$pos_agent=8;
4888 @fieldlib=('host','logname','date','method','url','code','size','referer','ua');
4889 }
4890 elsif ($LogFormat eq '2') { # Same than "date time c-ip cs-username cs-method cs-uri-stem sc-status sc-bytes cs-version cs(User-Agent) cs(Referer)"
4891 $PerlParsingFormat="(\\S+ \\S+) (\\S+) (\\S+) (\\S+) (\\S+) ([\\d|-]+) ([\\d|-]+) \\S+ (\\S+) (\\S+)";
4892 $pos_date=0;$pos_host=1;$pos_logname=2;$pos_method=3;$pos_url=4;$pos_code=5;$pos_size=6;$pos_agent=7;$pos_referer=8;
4893 @fieldlib=('date','host','logname','method','url','code','size','ua','referer');
4894 rizwank 1.1 }
4895 elsif ($LogFormat eq '3') {
4896 $PerlParsingFormat="([^\\t]*\\t[^\\t]*)\\t([^\\t]*)\\t([\\d|-]*)\\t([^\\t]*)\\t([^\\t]*)\\t([^\\t]*)\\t[^\\t]*\\t([^\\t]*)\\t([\\d]*)";
4897 $pos_date=0;$pos_method=1;$pos_code=2;$pos_host=3;$pos_agent=4;$pos_referer=5;$pos_url=6;$pos_size=7;
4898 @fieldlib=('date','method','code','host','ua','referer','url','size');
4899 }
4900 elsif ($LogFormat eq '4') { # Same than "%h %l %u %t \"%r\" %>s %b"
4901 # %u (user) is "(.+)" instead of "[^ ]+" because can contain space (Lotus Notes).
4902 $PerlParsingFormat="([^ ]+) [^ ]+ (.+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) ([^ ]+) [^\\\"]+\\\" ([\\d|-]+) ([\\d|-]+)";
4903 $pos_host=0;$pos_logname=1;$pos_date=2;$pos_method=3;$pos_url=4;$pos_code=5;$pos_size=6;
4904 @fieldlib=('host','logname','date','method','url','code','size');
4905 }
4906 # This is a deprecated option, will be removed in a next version.
4907 elsif ($LogFormat eq '5') { # Same than "c-ip cs-username c-agent sc-authenticated date time s-svcname s-computername cs-referred r-host r-ip r-port time-taken cs-bytes sc-bytes cs-protocol cs-transport s-operation cs-uri cs-mime-type s-object-source sc-status s-cache-info"
4908 $PerlParsingFormat="([^\\t]*)\\t([^\\t]*)\\t([^\\t]*)\\t[^\\t]*\\t([^\\t]*\\t[^\\t]*)\\t[^\\t]*\\t[^\\t]*\\t([^\\t]*)\\t[^\\t]*\\t[^\\t]*\\t[^\\t]*\\t[^\\t]*\\t[^\\t]*\\t([^\\t]*)\\t[^\\t]*\\t[^\\t]*\\t([^\\t]*)\\t([^\\t]*)\\t[^\\t]*\\t[^\\t]*\\t([^\\t]*)\\t[^\\t]*";
4909 $pos_host=0;$pos_logname=1;$pos_agent=2;$pos_date=3;$pos_referer=4;$pos_size=5;$pos_method=6;$pos_url=7;$pos_code=8;
4910 @fieldlib=('host','logname','ua','date','referer','size','method','url','code');
4911 }
4912 }
4913 else { # Personalized log format
4914 my $LogFormatString=$LogFormat;
4915 rizwank 1.1 # Replacement for Notes format string that are not Apache
4916 $LogFormatString =~ s/%vh/%virtualname/g;
4917 # Replacement for Apache format string
4918 $LogFormatString =~ s/%v(\s)/%virtualname$1/g; $LogFormatString =~ s/%v$/%virtualname/g;
4919 $LogFormatString =~ s/%h(\s)/%host$1/g; $LogFormatString =~ s/%h$/%host/g;
4920 $LogFormatString =~ s/%l(\s)/%other$1/g; $LogFormatString =~ s/%l$/%other/g;
4921 $LogFormatString =~ s/\"%u\"/%lognamequot/g;
4922 $LogFormatString =~ s/%u(\s)/%logname$1/g; $LogFormatString =~ s/%u$/%logname/g;
4923 $LogFormatString =~ s/%t(\s)/%time1$1/g; $LogFormatString =~ s/%t$/%time1/g;
4924 $LogFormatString =~ s/\"%r\"/%methodurl/g;
4925 $LogFormatString =~ s/%>s/%code/g;
4926 $LogFormatString =~ s/%b(\s)/%bytesd$1/g; $LogFormatString =~ s/%b$/%bytesd/g;
4927 $LogFormatString =~ s/\"%{Referer}i\"/%refererquot/g;
4928 $LogFormatString =~ s/\"%{User-Agent}i\"/%uaquot/g;
4929 $LogFormatString =~ s/%{mod_gzip_input_size}n/%gzipin/g;
4930 $LogFormatString =~ s/%{mod_gzip_output_size}n/%gzipout/g;
4931 $LogFormatString =~ s/%{mod_gzip_compression_ratio}n/%gzipratio/g;
4932 $LogFormatString =~ s/\(%{ratio}n\)/%deflateratio/g;
4933 # Replacement for a IIS and ISA format string
4934 $LogFormatString =~ s/cs-uri-query/%query/g; # Must be before cs-uri
4935 $LogFormatString =~ s/date\stime/%time2/g;
4936 rizwank 1.1 $LogFormatString =~ s/c-ip/%host/g;
4937 $LogFormatString =~ s/cs-username/%logname/g;
4938 $LogFormatString =~ s/cs-method/%method/g; # GET, POST, SMTP, RETR STOR
4939 $LogFormatString =~ s/cs-uri-stem/%url/g; $LogFormatString =~ s/cs-uri/%url/g;
4940 $LogFormatString =~ s/sc-status/%code/g;
4941 $LogFormatString =~ s/sc-bytes/%bytesd/g;
4942 $LogFormatString =~ s/cs-version/%other/g; # Protocol
4943 $LogFormatString =~ s/cs\(User-Agent\)/%ua/g; $LogFormatString =~ s/c-agent/%ua/g;
4944 $LogFormatString =~ s/cs\(Referer\)/%referer/g; $LogFormatString =~ s/cs-referred/%referer/g;
4945 $LogFormatString =~ s/sc-authenticated/%other/g;
4946 $LogFormatString =~ s/s-svcname/%other/g;
4947 $LogFormatString =~ s/s-computername/%other/g;
4948 $LogFormatString =~ s/r-host/%virtualname/g;
4949 $LogFormatString =~ s/r-ip/%other/g;
4950 $LogFormatString =~ s/r-port/%other/g;
4951 $LogFormatString =~ s/time-taken/%other/g;
4952 $LogFormatString =~ s/cs-bytes/%other/g;
4953 $LogFormatString =~ s/cs-protocol/%other/g;
4954 $LogFormatString =~ s/cs-transport/%other/g;
4955 $LogFormatString =~ s/s-operation/%method/g; # GET, POST, SMTP, RETR STOR
4956 $LogFormatString =~ s/cs-mime-type/%other/g;
4957 rizwank 1.1 $LogFormatString =~ s/s-object-source/%other/g;
4958 $LogFormatString =~ s/s-cache-info/%other/g;
4959 # Added for MMS
4960 $LogFormatString =~ s/protocol/%protocolmms/g; # cs-method might not be available
4961 $LogFormatString =~ s/c-status/%codemms/g; # c-status used when sc-status not available
4962 if ($Debug) { debug(" LogFormatString=$LogFormatString"); }
4963 # $LogFormatString has an AWStats format, so we can generate PerlParsingFormat variable
4964 my $i = 0;
4965 my $LogSeparatorWithoutStar=$LogSeparator; $LogSeparatorWithoutStar =~ s/[\*\+]//g;
4966 foreach my $f (split(/\s+/,$LogFormatString)) {
4967 # Add separator for next field
4968 if ($PerlParsingFormat) { $PerlParsingFormat.="$LogSeparator"; }
4969 # Special for logname
4970 if ($f =~ /%lognamequot$/) {
4971 $pos_logname = $i; $i++; push @fieldlib, 'logname';
4972 $PerlParsingFormat .= "\\\"?([^\\\"]*)\\\"?"; # logname can be "value", "" and - in same log (Lotus notes)
4973 }
4974 # Date format
4975 elsif ($f =~ /%time1$/ || $f =~ /%time1b$/) { # [dd/mmm/yyyy:hh:mm:ss +0000] or [dd/mmm/yyyy:hh:mm:ss], time1b kept for backward compatibility
4976 $pos_date = $i; $i++; push @fieldlib, 'date';
4977 $pos_tz = $i; $i++; push @fieldlib, 'tz';
4978 rizwank 1.1 $PerlParsingFormat .= "\\[([^$LogSeparatorWithoutStar]+)( [^$LogSeparatorWithoutStar]+)?\\]";
4979 }
4980 elsif ($f =~ /%time2$/) { # yyyy-mm-dd hh:mm:ss
4981 $pos_date = $i; $i++; push @fieldlib, 'date';
4982 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+\\s[^$LogSeparatorWithoutStar]+)"; # Need \s for Exchange log files
4983 }
4984 elsif ($f =~ /%time3$/) { # mon d hh:mm:ss or mon dd hh:mm:ss yyyy or day mon dd hh:mm:ss or day mon dd hh:mm:ss yyyy
4985 $pos_date = $i; $i++; push @fieldlib, 'date';
4986 $PerlParsingFormat .= "(?:\\w\\w\\w )?(\\w\\w\\w \\s?\\d+ \\d\\d:\\d\\d:\\d\\d(?: \\d\\d\\d\\d)?)";
4987 }
4988 elsif ($f =~ /%time4$/) { # ddddddddddddd
4989 $pos_date = $i; $i++; push @fieldlib, 'date';
4990 $PerlParsingFormat .= "(\\d+)";
4991 }
4992 # Special for methodurl and methodurlnoprot
4993 elsif ($f =~ /%methodurl$/) {
4994 $pos_method = $i; $i++; push @fieldlib, 'method';
4995 $pos_url = $i; $i++; push @fieldlib, 'url';
4996 $PerlParsingFormat .= "\\\"([^$LogSeparatorWithoutStar]+) ([^$LogSeparatorWithoutStar]+) [^\\\"]+\\\"";
4997 }
4998 elsif ($f =~ /%methodurlnoprot$/) {
4999 rizwank 1.1 $pos_method = $i; $i++; push @fieldlib, 'method';
5000 $pos_url = $i; $i++; push @fieldlib, 'url';
5001 $PerlParsingFormat .= "\\\"([^$LogSeparatorWithoutStar]+) ([^$LogSeparatorWithoutStar]+)\\\"";
5002 }
5003 # Common command tags
5004 elsif ($f =~ /%virtualname$/) {
5005 $pos_vh = $i; $i++; push @fieldlib, 'vhost';
5006 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5007 }
5008 elsif ($f =~ /%host_r$/) {
5009 $pos_hostr = $i; $i++; push @fieldlib, 'hostr';
5010 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5011 }
5012 elsif ($f =~ /%host$/) {
5013 $pos_host = $i; $i++; push @fieldlib, 'host';
5014 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5015 }
5016 elsif ($f =~ /%logname$/) {
5017 $pos_logname = $i; $i++; push @fieldlib, 'logname';
5018 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5019 }
5020 rizwank 1.1 elsif ($f =~ /%method$/) {
5021 $pos_method = $i; $i++; push @fieldlib, 'method';
5022 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5023 }
5024 elsif ($f =~ /%url$/) {
5025 $pos_url = $i; $i++; push @fieldlib, 'url';
5026 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5027 }
5028 elsif ($f =~ /%query$/) {
5029 $pos_query = $i; $i++; push @fieldlib, 'query';
5030 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5031 }
5032 elsif ($f =~ /%code$/) {
5033 $pos_code = $i; $i++; push @fieldlib, 'code';
5034 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5035 }
5036 elsif ($f =~ /%bytesd$/) {
5037 $pos_size = $i; $i++; push @fieldlib, 'size';
5038 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5039 }
5040 elsif ($f =~ /%refererquot$/) {
5041 rizwank 1.1 $pos_referer = $i; $i++; push @fieldlib, 'referer';
5042 $PerlParsingFormat .= "\\\"([^\\\"]*)\\\""; # referer might be ""
5043 }
5044 elsif ($f =~ /%referer$/) {
5045 $pos_referer = $i; $i++; push @fieldlib, 'referer';
5046 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5047 }
5048 elsif ($f =~ /%uaquot$/) {
5049 $pos_agent = $i; $i++; push @fieldlib, 'ua';
5050 $PerlParsingFormat .= "\\\"([^\\\"]*)\\\""; # ua might be ""
5051 }
5052 elsif ($f =~ /%uabracket$/) {
5053 $pos_agent = $i; $i++; push @fieldlib, 'ua';
5054 $PerlParsingFormat .= "\\\[([^\\\]]*)\\\]"; # ua might be []
5055 }
5056 elsif ($f =~ /%ua$/) {
5057 $pos_agent = $i; $i++; push @fieldlib, 'ua';
5058 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5059 }
5060 elsif ($f =~ /%gzipin$/ ) {
5061 $pos_gzipin=$i;$i++; push @fieldlib, 'gzipin';
5062 rizwank 1.1 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5063 }
5064 elsif ($f =~ /%gzipout/ ) { # Compare $f to /%gzipout/ and not to /%gzipout$/ like other fields
5065 $pos_gzipout=$i;$i++; push @fieldlib, 'gzipout';
5066 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5067 }
5068 elsif ($f =~ /%gzipratio/ ) { # Compare $f to /%gzipratio/ and not to /%gzipratio$/ like other fields
5069 $pos_compratio=$i;$i++; push @fieldlib, 'gzipratio';
5070 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5071 }
5072 elsif ($f =~ /%deflateratio/ ) { # Compare $f to /%deflateratio/ and not to /%deflateratio$/ like other fields
5073 $pos_compratio=$i;$i++; push @fieldlib, 'deflateratio';
5074 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5075 }
5076 elsif ($f =~ /%email_r$/) {
5077 $pos_emailr = $i; $i++; push @fieldlib, 'email_r';
5078 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5079 }
5080 elsif ($f =~ /%email$/) {
5081 $pos_emails = $i; $i++; push @fieldlib, 'email';
5082 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5083 rizwank 1.1 }
5084 elsif ($f =~ /%cluster$/) {
5085 $pos_cluster = $i; $i++; push @fieldlib, 'clusternb';
5086 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5087 }
5088 elsif ($f =~ /%timetaken$/) {
5089 $pos_timetaken = $i; $i++; push @fieldlib, 'timetaken';
5090 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5091 }
5092 # Special for protocolmms, used for method if method not already found (for MMS)
5093 elsif ($f =~ /%protocolmms$/) {
5094 if ($pos_method < 0) {
5095 $pos_method = $i; $i++; push @fieldlib, 'method';
5096 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5097 }
5098 }
5099 # Special for codemms, used for code only if code not already found (for MMS)
5100 elsif ($f =~ /%codemms$/) {
5101 if ($pos_code < 0) {
5102 $pos_code = $i; $i++; push @fieldlib, 'code';
5103 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5104 rizwank 1.1 }
5105 }
5106 # Extra tag
5107 elsif ($f =~ /%extra(\d+)$/) {
5108 $pos_extra[$1] = $i; $i++; push @fieldlib, "extra$1";
5109 $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
5110 }
5111 # Other tag
5112 elsif ($f =~ /%other$/) {
5113 $PerlParsingFormat .= "[^$LogSeparatorWithoutStar]+";
5114 }
5115 elsif ($f =~ /%otherquot$/) {
5116 $PerlParsingFormat .= "\\\"[^\\\"]*\\\"";
5117 }
5118 # Unknown tag (no parenthesis)
5119 else {
5120 $PerlParsingFormat .= "[^$LogSeparatorWithoutStar]+";
5121 }
5122 }
5123 if (! $PerlParsingFormat) { error("No recognized format tag in personalized LogFormat string"); }
5124 }
5125 rizwank 1.1 if ($pos_host < 0) { error("Your personalized LogFormat does not include all fields required by AWStats (Add \%host in your LogFormat string)."); }
5126 if ($pos_date < 0) { error("Your personalized LogFormat does not include all fields required by AWStats (Add \%time1 or \%time2 in your LogFormat string)."); }
5127 if ($pos_method < 0) { error("Your personalized LogFormat does not include all fields required by AWStats (Add \%methodurl or \%method in your LogFormat string)."); }
5128 if ($pos_url < 0) { error("Your personalized LogFormat does not include all fields required by AWStats (Add \%methodurl or \%url in your LogFormat string)."); }
5129 if ($pos_code < 0) { error("Your personalized LogFormat does not include all fields required by AWStats (Add \%code in your LogFormat string)."); }
5130 if ($pos_size < 0) { error("Your personalized LogFormat does not include all fields required by AWStats (Add \%bytesd in your LogFormat string)."); }
5131 $PerlParsingFormat=qr/^$PerlParsingFormat/;
5132 if ($Debug) { debug(" PerlParsingFormat is $PerlParsingFormat"); }
5133 }
5134
5135
5136 sub ShowMenuCateg {
5137 my ($categ,$categtext,$categicon,$frame,$targetpage,$linkanchor,$NewLinkParams,$NewLinkTarget)=(shift,shift,shift,shift,shift,shift,shift,shift);
5138 $categicon=''; # Comment this to enabme category icons
5139 my ($menu,$menulink,$menutext)=(shift,shift,shift);
5140 my $linetitle=0;
5141 # Call to plugins' function AddHTMLMenuLink
5142 foreach my $pluginname (keys %{$PluginsLoaded{'AddHTMLMenuLink'}}) {
5143 my $function="AddHTMLMenuLink_$pluginname('$categ',\$menu,\$menulink,\$menutext)";
5144 eval("$function");
5145 }
5146 rizwank 1.1 foreach my $key (%$menu) { if ($menu->{$key}>0) { $linetitle++; last; } }
5147 if (! $linetitle) { return; }
5148 # At least one entry in menu for this category, we can show categpry and entries
5149 my $WIDTHMENU1=($FrameName eq 'mainleft'?$FRAMEWIDTH:150);
5150 print "<tr><td class=\"awsm\" width=\"$WIDTHMENU1\"".($frame?"":" valign=\"top\"").">".($categicon?"<img src=\"$DirIcons/other/$categicon\" /> ":"")."<b>$categtext:</b></td>\n";
5151 print ($frame?"</tr>\n":"<td class=\"awsm\">");
5152 foreach my $key (sort { $menu->{$a} <=> $menu->{$b} } keys %$menu) {
5153 if ($menu->{$key}==0) { next; }
5154 if ($menulink->{$key}==1) { print ($frame?"<tr><td class=\"awsm\">":""); print "<a href=\"$linkanchor#$key\"$targetpage>$menutext->{$key}</a>"; print ($frame?"</td></tr>\n":" "); }
5155 if ($menulink->{$key}==2) { print ($frame?"<tr><td class=\"awsm\"> <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> ":""); print "<a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=$key"):"$PROG$StaticLinks.$key.$StaticExt")."\"$NewLinkTarget>$menutext->{$key}</a>\n"; print ($frame?"</td></tr>\n":" "); }
5156 }
5157 print ($frame?"":"</td></tr>\n");
5158 }
5159
5160
5161 sub ShowEmailSendersChart {
5162 my $NewLinkParams=shift;
5163 my $NewLinkTarget=shift;
5164 my $MaxLengthOfShownEMail=48;
5165
5166 my $total_p;my $total_h;my $total_k;
5167 rizwank 1.1 my $max_p;my $max_h;my $max_k;
5168 my $rest_p;my $rest_h;my $rest_k;
5169
5170 # Show filter form
5171 #&ShowFormFilter("emailsfilter",$EmailsFilter);
5172 # Show emails list
5173
5174 print "$Center<a name=\"emailsenders\"> </a><br />\n";
5175 my $title;
5176 if ($HTMLOutput{'allemails'} || $HTMLOutput{'lastemails'}) {
5177 $title="$Message[131]";
5178 }
5179 else {
5180 $title="$Message[131] ($Message[77] $MaxNbOf{'EMailsShown'}) - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=allemails"):"$PROG$StaticLinks.allemails.$StaticExt")."\"$NewLinkTarget>$Message[80]</a>";
5181 if ($ShowEMailSenders =~ /L/i) { $title.=" - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=lastemails"):"$PROG$StaticLinks.lastemails.$StaticExt")."\"$NewLinkTarget>$Message[9]</a>"; }
5182 }
5183 &tab_head("$title",19,0,'emailsenders');
5184 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"3\">$Message[131] : ".(scalar keys %_emails_h)."</th>";
5185 if ($ShowEMailSenders =~ /H/i) { print "<th rowspan=\"2\" bgcolor=\"#$color_h\" width=\"80\"".Tooltip(4).">$Message[57]</th>"; }
5186 if ($ShowEMailSenders =~ /B/i) { print "<th rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\"".Tooltip(5).">$Message[75]</th>"; }
5187 if ($ShowEMailSenders =~ /M/i) { print "<th rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>"; }
5188 rizwank 1.1 if ($ShowEMailSenders =~ /L/i) { print "<th rowspan=\"2\" width=\"120\">$Message[9]</th>"; }
5189 print "</tr>\n";
5190 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"30%\">Local</th><th> </th><th width=\"30%\">External</th></tr>";
5191 $total_p=$total_h=$total_k=0;
5192 $max_h=1; foreach (values %_emails_h) { if ($_ > $max_h) { $max_h = $_; } }
5193 $max_k=1; foreach (values %_emails_k) { if ($_ > $max_k) { $max_k = $_; } }
5194 my $count=0;
5195 if (! $HTMLOutput{'allemails'} && ! $HTMLOutput{'lastemails'}) { &BuildKeyList($MaxNbOf{'EMailsShown'},$MinHit{'EMail'},\%_emails_h,\%_emails_h); }
5196 if ($HTMLOutput{'allemails'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'EMail'},\%_emails_h,\%_emails_h); }
5197 if ($HTMLOutput{'lastemails'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'EMail'},\%_emails_h,\%_emails_l); }
5198 foreach my $key (@keylist) {
5199 my $newkey=$key;
5200 if (length($key)>$MaxLengthOfShownEMail) { $newkey=substr($key,0,$MaxLengthOfShownEMail)."..."; }
5201 my $bredde_h=0;my $bredde_k=0;
5202 if ($max_h > 0) { $bredde_h=int($BarWidth*$_emails_h{$key}/$max_h)+1; }
5203 if ($max_k > 0) { $bredde_k=int($BarWidth*$_emails_k{$key}/$max_k)+1; }
5204 print "<tr>";
5205 my $direction=IsLocalEMail($key);
5206 if ($direction > 0) { print "<td class=\"aws\">$newkey</td><td>-></td><td> </td>"; }
5207 if ($direction == 0) { print "<td colspan=\"3\"><span style=\"color: #$color_other\">$newkey</span></td>"; }
5208 if ($direction < 0) { print "<td class=\"aws\"> </td><td><-</td><td>$newkey</td>"; }
5209 rizwank 1.1 if ($ShowEMailSenders =~ /H/i) { print "<td>$_emails_h{$key}</td>"; }
5210 if ($ShowEMailSenders =~ /B/i) { print "<td>".Format_Bytes($_emails_k{$key})."</td>"; }
5211 if ($ShowEMailSenders =~ /M/i) { print "<td>".Format_Bytes($_emails_k{$key}/($_emails_h{$key}||1))."</td>"; }
5212 if ($ShowEMailSenders =~ /L/i) { print "<td>".($_emails_l{$key}?Format_Date($_emails_l{$key},1):'-')."</td>"; }
5213 print "</tr>\n";
5214 #$total_p += $_emails_p{$key};
5215 $total_h += $_emails_h{$key};
5216 $total_k += $_emails_k{$key};
5217 $count++;
5218 }
5219 $rest_p=0; # $rest_p=$TotalPages-$total_p;
5220 $rest_h=$TotalHits-$total_h;
5221 $rest_k=$TotalBytes-$total_k;
5222 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other sender emails
5223 print "<tr><td colspan=\"3\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
5224 if ($ShowEMailSenders =~ /H/i) { print "<td>$rest_h</td>"; }
5225 if ($ShowEMailSenders =~ /B/i) { print "<td>".Format_Bytes($rest_k)."</td>"; }
5226 if ($ShowEMailSenders =~ /M/i) { print "<td>".Format_Bytes($rest_k/($rest_h||1))."</td>"; }
5227 if ($ShowEMailSenders =~ /L/i) { print "<td> </td>"; }
5228 print "</tr>\n";
5229 }
5230 rizwank 1.1 &tab_end();
5231 }
5232
5233
5234 sub ShowEmailReceiversChart {
5235 my $NewLinkParams=shift;
5236 my $NewLinkTarget=shift;
5237 my $MaxLengthOfShownEMail=48;
5238
5239 my $total_p;my $total_h;my $total_k;
5240 my $max_p;my $max_h;my $max_k;
5241 my $rest_p;my $rest_h;my $rest_k;
5242
5243 # Show filter form
5244 #&ShowFormFilter("emailrfilter",$EmailrFilter);
5245 # Show emails list
5246
5247 print "$Center<a name=\"emailreceivers\"> </a><br />\n";
5248 my $title;
5249 if ($HTMLOutput{'allemailr'} || $HTMLOutput{'lastemailr'}) {
5250 $title="$Message[132]";
5251 rizwank 1.1 }
5252 else {
5253 $title="$Message[132] ($Message[77] $MaxNbOf{'EMailsShown'}) - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=allemailr"):"$PROG$StaticLinks.allemailr.$StaticExt")."\"$NewLinkTarget>$Message[80]</a>";
5254 if ($ShowEMailReceivers =~ /L/i) { $title.=" - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=lastemailr"):"$PROG$StaticLinks.lastemailr.$StaticExt")."\"$NewLinkTarget>$Message[9]</a>"; }
5255 }
5256 &tab_head("$title",19,0,'emailreceivers');
5257 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"3\">$Message[132] : ".(scalar keys %_emailr_h)."</th>";
5258 if ($ShowEMailReceivers =~ /H/i) { print "<th rowspan=\"2\" bgcolor=\"#$color_h\" width=\"80\"".Tooltip(4).">$Message[57]</th>"; }
5259 if ($ShowEMailReceivers =~ /B/i) { print "<th rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\"".Tooltip(5).">$Message[75]</th>"; }
5260 if ($ShowEMailReceivers =~ /M/i) { print "<th rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>"; }
5261 if ($ShowEMailReceivers =~ /L/i) { print "<th rowspan=\"2\" width=\"120\">$Message[9]</th>"; }
5262 print "</tr>\n";
5263 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"30%\">Local</th><th> </th><th width=\"30%\">External</th></tr>";
5264 $total_p=$total_h=$total_k=0;
5265 $max_h=1; foreach (values %_emailr_h) { if ($_ > $max_h) { $max_h = $_; } }
5266 $max_k=1; foreach (values %_emailr_k) { if ($_ > $max_k) { $max_k = $_; } }
5267 my $count=0;
5268 if (! $HTMLOutput{'allemailr'} && ! $HTMLOutput{'lastemailr'}) { &BuildKeyList($MaxNbOf{'EMailsShown'},$MinHit{'EMail'},\%_emailr_h,\%_emailr_h); }
5269 if ($HTMLOutput{'allemailr'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'EMail'},\%_emailr_h,\%_emailr_h); }
5270 if ($HTMLOutput{'lastemailr'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'EMail'},\%_emailr_h,\%_emailr_l); }
5271 foreach my $key (@keylist) {
5272 rizwank 1.1 my $newkey=$key;
5273 if (length($key)>$MaxLengthOfShownEMail) { $newkey=substr($key,0,$MaxLengthOfShownEMail)."..."; }
5274 my $bredde_h=0;my $bredde_k=0;
5275 if ($max_h > 0) { $bredde_h=int($BarWidth*$_emailr_h{$key}/$max_h)+1; }
5276 if ($max_k > 0) { $bredde_k=int($BarWidth*$_emailr_k{$key}/$max_k)+1; }
5277 print "<tr>";
5278 my $direction=IsLocalEMail($key);
5279 if ($direction > 0) { print "<td class=\"aws\">$newkey</td><td><-</td><td> </td>"; }
5280 if ($direction == 0) { print "<td colspan=\"3\"><span style=\"color: #$color_other\">$newkey</span></td>"; }
5281 if ($direction < 0) { print "<td class=\"aws\"> </td><td>-></td><td>$newkey</td>"; }
5282 if ($ShowEMailReceivers =~ /H/i) { print "<td>$_emailr_h{$key}</td>"; }
5283 if ($ShowEMailReceivers =~ /B/i) { print "<td>".Format_Bytes($_emailr_k{$key})."</td>"; }
5284 if ($ShowEMailReceivers =~ /M/i) { print "<td>".Format_Bytes($_emailr_k{$key}/($_emailr_h{$key}||1))."</td>"; }
5285 if ($ShowEMailReceivers =~ /L/i) { print "<td>".($_emailr_l{$key}?Format_Date($_emailr_l{$key},1):'-')."</td>"; }
5286 print "</tr>\n";
5287 #$total_p += $_emailr_p{$key};
5288 $total_h += $_emailr_h{$key};
5289 $total_k += $_emailr_k{$key};
5290 $count++;
5291 }
5292 $rest_p=0; # $rest_p=$TotalPages-$total_p;
5293 rizwank 1.1 $rest_h=$TotalHits-$total_h;
5294 $rest_k=$TotalBytes-$total_k;
5295 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other receiver emails
5296 print "<tr><td colspan=\"3\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
5297 if ($ShowEMailReceivers =~ /H/i) { print "<td>$rest_h</td>"; }
5298 if ($ShowEMailReceivers =~ /B/i) { print "<td>".Format_Bytes($rest_k)."</td>"; }
5299 if ($ShowEMailReceivers =~ /M/i) { print "<td>".Format_Bytes($rest_k/($rest_h||1))."</td>"; }
5300 if ($ShowEMailReceivers =~ /L/i) { print "<td> </td>"; }
5301 print "</tr>\n";
5302 }
5303 &tab_end();
5304 }
5305
5306
5307
5308 #------------------------------------------------------------------------------
5309 # MAIN
5310 #------------------------------------------------------------------------------
5311 ($DIR=$0) =~ s/([^\/\\]+)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1;
5312 $DIR||='.'; $DIR =~ s/([^\/\\])[\\\/]+$/$1/;
5313
5314 rizwank 1.1 $starttime=time();
5315
5316 # Get current time (time when AWStats was started)
5317 ($nowsec,$nowmin,$nowhour,$nowday,$nowmonth,$nowyear,$nowwday,$nowyday) = localtime($starttime);
5318 $nowweekofmonth=int($nowday/7);
5319 $nowweekofyear=int(($nowyday-1+6-($nowwday==0?6:$nowwday-1))/7)+1; if ($nowweekofyear > 52) { $nowweekofyear = 1; }
5320 $nowdaymod=$nowday%7;
5321 $nowwday++;
5322 $nowns=Time::Local::timegm(0,0,0,$nowday,$nowmonth,$nowyear);
5323 if ($nowdaymod <= $nowwday) { if (($nowwday != 7) || ($nowdaymod != 0)) { $nowweekofmonth=$nowweekofmonth+1; } }
5324 if ($nowdaymod > $nowwday) { $nowweekofmonth=$nowweekofmonth+2; }
5325 # Change format of time variables
5326 $nowweekofmonth="0$nowweekofmonth";
5327 if ($nowweekofyear < 10) { $nowweekofyear = "0$nowweekofyear"; }
5328 if ($nowyear < 100) { $nowyear+=2000; } else { $nowyear+=1900; }
5329 $nowsmallyear=$nowyear;$nowsmallyear =~ s/^..//;
5330 if (++$nowmonth < 10) { $nowmonth = "0$nowmonth"; }
5331 if ($nowday < 10) { $nowday = "0$nowday"; }
5332 if ($nowhour < 10) { $nowhour = "0$nowhour"; }
5333 if ($nowmin < 10) { $nowmin = "0$nowmin"; }
5334 if ($nowsec < 10) { $nowsec = "0$nowsec"; }
5335 rizwank 1.1 $nowtime=int($nowyear.$nowmonth.$nowday.$nowhour.$nowmin.$nowsec);
5336 # Get tomorrow time (will be used to discard some record with corrupted date (future date))
5337 my ($tomorrowsec,$tomorrowmin,$tomorrowhour,$tomorrowday,$tomorrowmonth,$tomorrowyear) = localtime($starttime+86400);
5338 if ($tomorrowyear < 100) { $tomorrowyear+=2000; } else { $tomorrowyear+=1900; }
5339 if (++$tomorrowmonth < 10) { $tomorrowmonth = "0$tomorrowmonth"; }
5340 if ($tomorrowday < 10) { $tomorrowday = "0$tomorrowday"; }
5341 if ($tomorrowhour < 10) { $tomorrowhour = "0$tomorrowhour"; }
5342 if ($tomorrowmin < 10) { $tomorrowmin = "0$tomorrowmin"; }
5343 if ($tomorrowsec < 10) { $tomorrowsec = "0$tomorrowsec"; }
5344 $tomorrowtime=int($tomorrowyear.$tomorrowmonth.$tomorrowday.$tomorrowhour.$tomorrowmin.$tomorrowsec);
5345
5346 # Allowed option
5347 my @AllowedCLIArgs=('migrate','config',
5348 'logfile','output','runascli','update',
5349 'staticlinks','staticlinksext','noloadplugin','loadplugin',
5350 'hostfilter','urlfilter','refererpagesfilter',
5351 'lang','month','year','framename','debug',
5352 'showsteps','showdropped','showcorrupted','showunknownorigin',
5353 'limitflush','confdir','updatefor',
5354 'hostfilter','hostfilterex','urlfilter','urlfilterex','refererpagesfilter','refererpagesfilterex',
5355 'pluginmode','filterrawlog');
5356 rizwank 1.1
5357 $QueryString='';
5358 # AWStats use GATEWAY_INTERFACE to known if ran as CLI or CGI. AWSTATS_DEL_GATEWAY_INTERFACE can
5359 # be set to force AWStats to be ran as CLI even from a web page.
5360 if ($ENV{'AWSTATS_DEL_GATEWAY_INTERFACE'}) { $ENV{'GATEWAY_INTERFACE'}=''; }
5361 if ($ENV{'GATEWAY_INTERFACE'}) { # Run from a browser as CGI
5362 # Prepare QueryString
5363 if ($ENV{'CONTENT_LENGTH'}) {
5364 binmode STDIN;
5365 read(STDIN, $QueryString, $ENV{'CONTENT_LENGTH'});
5366 }
5367 if ($ENV{'QUERY_STRING'}) { $QueryString = $ENV{'QUERY_STRING'}; }
5368
5369 $QueryString = CleanFromCSSA($QueryString);
5370
5371 # Security test
5372 if ($QueryString =~ /LogFile=([^&]+)/i) { error("Logfile parameter can't be overwritten when AWStats is used from a CGI"); }
5373
5374 # No update but report by default when run from a browser
5375 $UpdateStats=($QueryString=~/update=1/i?1:0);
5376
5377 rizwank 1.1 if ($QueryString =~ /config=([^&]+)/i) { $SiteConfig=&DecodeEncodedString("$1"); }
5378 if ($QueryString =~ /diricons=([^&]+)/i) { $DirIcons=&DecodeEncodedString("$1"); }
5379 if ($QueryString =~ /pluginmode=([^&]+)/i) { $PluginMode=&Sanitize(&DecodeEncodedString("$1")); }
5380 if ($QueryString =~ /configdir=([^&]+)/i) { $DirConfig=&Sanitize(&DecodeEncodedString("$1")); }
5381 # All filters
5382 if ($QueryString =~ /hostfilter=([^&]+)/i) { $FilterIn{'host'}=&DecodeEncodedString("$1"); } # Filter on host list can also be defined with hostfilter=filter
5383 if ($QueryString =~ /hostfilterex=([^&]+)/i) { $FilterEx{'host'}=&DecodeEncodedString("$1"); } #
5384 if ($QueryString =~ /urlfilter=([^&]+)/i) { $FilterIn{'url'}=&DecodeEncodedString("$1"); } # Filter on URL list can also be defined with urlfilter=filter
5385 if ($QueryString =~ /urlfilterex=([^&]+)/i) { $FilterEx{'url'}=&DecodeEncodedString("$1"); } #
5386 if ($QueryString =~ /refererpagesfilter=([^&]+)/i) { $FilterIn{'refererpages'}=&DecodeEncodedString("$1"); } # Filter on referer list can also be defined with refererpagesfilter=filter
5387 if ($QueryString =~ /refererpagesfilterex=([^&]+)/i) { $FilterEx{'refererpages'}=&DecodeEncodedString("$1"); } #
5388 # All output
5389 if ($QueryString =~ /output=allhosts:([^&]+)/i) { $FilterIn{'host'}=&DecodeEncodedString("$1"); } # Filter on host list can be defined with output=allhosts:filter to reduce number of lines read and showed
5390 if ($QueryString =~ /output=lasthosts:([^&]+)/i) { $FilterIn{'host'}=&DecodeEncodedString("$1"); } # Filter on host list can be defined with output=lasthosts:filter to reduce number of lines read and showed
5391 if ($QueryString =~ /output=urldetail:([^&]+)/i) { $FilterIn{'url'}=&DecodeEncodedString("$1"); } # Filter on URL list can be defined with output=urldetail:filter to reduce number of lines read and showed
5392 if ($QueryString =~ /output=refererpages:([^&]+)/i) { $FilterIn{'refererpages'}=&DecodeEncodedString("$1"); } # Filter on referer list can be defined with output=refererpages:filter to reduce number of lines read and showed
5393
5394 # If migrate
5395 if ($QueryString =~ /(^|-|&)migrate=([^&]+)/i) {
5396 $MigrateStats=&DecodeEncodedString("$2");
5397 $MigrateStats =~ /^(.*)$PROG(\d{0,2})(\d\d)(\d\d\d\d)(.*)\.txt$/;
5398 rizwank 1.1 $SiteConfig=$5?$5:'xxx'; $SiteConfig =~ s/^\.//; # SiteConfig is used to find config file
5399 }
5400 }
5401 else { # Run from command line
5402 # Prepare QueryString
5403 for (0..@ARGV-1) {
5404 # If migrate
5405 if ($ARGV[$_] =~ /(^|-|&)migrate=([^&]+)/i) {
5406 $MigrateStats="$2";
5407 $MigrateStats =~ /^(.*)$PROG(\d{0,2})(\d\d)(\d\d\d\d)(.*)\.txt$/;
5408 $SiteConfig=$5?$5:'xxx'; $SiteConfig =~ s/^\.//; # SiteConfig is used to find config file
5409 next;
5410 }
5411 # TODO Check if ARGV is in @AllowedArg
5412 if ($QueryString) { $QueryString .= '&'; }
5413 my $NewLinkParams=$ARGV[$_]; $NewLinkParams =~ s/^-+//;
5414 $QueryString .= "$NewLinkParams";
5415 }
5416
5417 $QueryString = CleanFromCSSA($QueryString);
5418
5419 rizwank 1.1 # Security test
5420 if ($ENV{'AWSTATS_DEL_GATEWAY_INTERFACE'} && $QueryString =~ /LogFile=([^&]+)/i) { error("Logfile parameter can't be overwritten when AWStats is used from a CGI"); }
5421
5422 # Update with no report by default when run from command line
5423 $UpdateStats=1;
5424
5425 if ($QueryString =~ /config=([^&]+)/i) { $SiteConfig="$1"; }
5426 if ($QueryString =~ /diricons=([^&]+)/i) { $DirIcons="$1"; }
5427 if ($QueryString =~ /pluginmode=([^&]+)/i) { $PluginMode=&Sanitize("$1"); }
5428 if ($QueryString =~ /configdir=([^&]+)/i) { $DirConfig=&Sanitize("$1"); }
5429 # All filters
5430 if ($QueryString =~ /hostfilter=([^&]+)/i) { $FilterIn{'host'}="$1"; } # Filter on host list can also be defined with hostfilter=filter
5431 if ($QueryString =~ /hostfilterex=([^&]+)/i) { $FilterEx{'host'}="$1"; } #
5432 if ($QueryString =~ /urlfilter=([^&]+)/i) { $FilterIn{'url'}="$1"; } # Filter on URL list can also be defined with urlfilter=filter
5433 if ($QueryString =~ /urlfilterex=([^&]+)/i) { $FilterEx{'url'}="$1"; } #
5434 if ($QueryString =~ /refererpagesfilter=([^&]+)/i) { $FilterIn{'refererpages'}="$1"; } # Filter on referer list can also be defined with refererpagesfilter=filter
5435 if ($QueryString =~ /refererpagesfilterex=([^&]+)/i) { $FilterEx{'refererpages'}="$1"; } #
5436 # All output
5437 if ($QueryString =~ /output=allhosts:([^&]+)/i) { $FilterIn{'host'}="$1"; } # Filter on host list can be defined with output=allhosts:filter to reduce number of lines read and showed
5438 if ($QueryString =~ /output=lasthosts:([^&]+)/i) { $FilterIn{'host'}="$1"; } # Filter on host list can be defined with output=lasthosts:filter to reduce number of lines read and showed
5439 if ($QueryString =~ /output=urldetail:([^&]+)/i) { $FilterIn{'url'}="$1"; } # Filter on URL list can be defined with output=urldetail:filter to reduce number of lines read and showed
5440 rizwank 1.1 if ($QueryString =~ /output=refererpages:([^&]+)/i) { $FilterIn{'refererpages'}="$1"; } # Filter on referer list can be defined with output=refererpages:filter to reduce number of lines read and showed
5441 # Config parameters
5442 if ($QueryString =~ /LogFile=([^&]+)/i) { $LogFile="$1"; }
5443
5444 # If show options
5445 if ($QueryString =~ /showsteps/i) { $ShowSteps=1; $QueryString=~s/showsteps[^&]*//i; }
5446 if ($QueryString =~ /showcorrupted/i) { $ShowCorrupted=1; $QueryString=~s/showcorrupted[^&]*//i; }
5447 if ($QueryString =~ /showdropped/i) { $ShowDropped=1; $QueryString=~s/showdropped[^&]*//i; }
5448 if ($QueryString =~ /showunknownorigin/i) { $ShowUnknownOrigin=1; $QueryString=~s/showunknownorigin[^&]*//i; }
5449 }
5450 if ($QueryString =~ /(^|&)staticlinks/i) { $StaticLinks=".$SiteConfig"; }
5451 if ($QueryString =~ /(^|&)staticlinks=([^&]+)/i) { $StaticLinks=".$2"; } # When ran from awstatsbuildstaticpages.pl
5452 if ($QueryString =~ /(^|&)staticlinksext=([^&]+)/i) { $StaticExt="$2"; }
5453 if ($QueryString =~ /(^|&)framename=([^&]+)/i) { $FrameName="$2"; }
5454 if ($QueryString =~ /(^|&)debug=(\d+)/i) { $Debug=$2; }
5455 if ($QueryString =~ /(^|&)updatefor=(\d+)/i) { $UpdateFor=$2; }
5456 if ($QueryString =~ /(^|&)noloadplugin=([^&]+)/i) { foreach (split(/,/,$2)) { $NoLoadPlugin{&Sanitize("$_")}=1; } }
5457 if ($QueryString =~ /(^|&)loadplugin=([^&]+)/i) { foreach (split(/,/,$2)) { $NoLoadPlugin{&Sanitize("$_")}=-1; } }
5458 if ($QueryString =~ /(^|&)limitflush=(\d+)/i) { $LIMITFLUSH=$2; }
5459 # Get/Define output
5460 if ($QueryString =~ /(^|&)output(=[^&]*|)(.*)&output(=[^&]*|)(&|$)/i) { error("Only 1 output option is allowed","","",1); }
5461 rizwank 1.1 if ($QueryString =~ /(^|&)output(=[^&]*|)(&|$)/i) {
5462 # At least one output expected. We define %HTMLOutput
5463 my $outputlist="$2";
5464 if ($outputlist) {
5465 $outputlist =~ s/^=//;
5466 foreach my $outputparam (split(/,/,$outputlist)) {
5467 $outputparam=~s/:(.*)$//;
5468 if ($outputparam) { $HTMLOutput{lc($outputparam)}="$1"||1; }
5469 }
5470 }
5471 # If on command line and no update
5472 if (! $ENV{'GATEWAY_INTERFACE'} && $QueryString !~ /update/i) { $UpdateStats=0; }
5473 # If no output defined, used default value
5474 if (! scalar keys %HTMLOutput) { $HTMLOutput{'main'}=1; }
5475 }
5476 if ($ENV{'GATEWAY_INTERFACE'} && ! scalar keys %HTMLOutput) { $HTMLOutput{'main'}=1; }
5477
5478 # Remove -output option with no = from QueryString
5479 $QueryString=~s/(^|&)output(&|$)/$1/i; $QueryString=~s/&+$//;
5480
5481 # Check year and month parameters
5482 rizwank 1.1 if ($QueryString =~ /(^|&)month=(year)/i) { error("month=year is a deprecated option. Use month=all instead."); }
5483 if ($QueryString =~ /(^|&)year=(\d\d\d\d)/i) { $YearRequired=sprintf("%04d",$2); }
5484 else { $YearRequired="$nowyear"; }
5485 if ($QueryString =~ /(^|&)month=(\d{1,2})/i) { $MonthRequired=sprintf("%02d",$2); }
5486 elsif ($QueryString =~ /(^|&)month=(all)/i) { $MonthRequired='all'; }
5487 else { $MonthRequired="$nowmonth"; }
5488 if ($QueryString =~ /(^|&)day=(\d{1,2})/i) { $DayRequired=sprintf("%02d",$2); } # day is a hidden option. Must not be used (Make results not understandable). Available for users that rename history files with day.
5489 else { $DayRequired=''; }
5490
5491 # Check parameter validity
5492 # TODO
5493
5494 # Print AWStats and Perl version
5495 if ($Debug) {
5496 debug(ucfirst($PROG)." - $VERSION - Perl $^X $]",1);
5497 debug("DIR=$DIR PROG=$PROG",2);
5498 debug("QUERY_STRING=$QueryString",2);
5499 debug("HTMLOutput=".join(',',keys %HTMLOutput),1);
5500 debug("YearRequired=$YearRequired, MonthRequired=$MonthRequired",2);
5501 debug("UpdateFor=$UpdateFor",2);
5502 debug("PluginMode=$PluginMode",2);
5503 rizwank 1.1 debug("DirConfig=$DirConfig",2);
5504 }
5505
5506 # Force SiteConfig if AWSTATS_FORCE_CONFIG is defined
5507 if ($ENV{'AWSTATS_CONFIG'}) { $ENV{'AWSTATS_FORCE_CONFIG'}=$ENV{'AWSTATS_CONFIG'}; } # For backward compatibility
5508 if ($ENV{'AWSTATS_FORCE_CONFIG'}) {
5509 if ($Debug) { debug("AWSTATS_FORCE_CONFIG parameter is defined to '".$ENV{'AWSTATS_FORCE_CONFIG'}."'. $PROG will use this as config value."); }
5510 $SiteConfig=&Sanitize($ENV{'AWSTATS_FORCE_CONFIG'});
5511 }
5512
5513 if ((! $ENV{'GATEWAY_INTERFACE'}) && (! $SiteConfig)) {
5514 &Read_Ref_Data('browsers','domains','operating_systems','robots','search_engines','worms');
5515 print "----- $PROG $VERSION (c) 2000-2004 Laurent Destailleur -----\n";
5516 print "AWStats is a free web server logfile analyzer to show you advanced web\n";
5517 print "statistics.\n";
5518 print "AWStats comes with ABSOLUTELY NO WARRANTY. It's a free software distributed\n";
5519 print "with a GNU General Public License (See LICENSE file for details).\n";
5520 print "\n";
5521 print "Syntax: $PROG.$Extension -config=virtualhostname [options]\n";
5522 print "\n";
5523 print " This runs $PROG in command line to update statistics of a web site, from\n";
5524 rizwank 1.1 print " the log file defined in AWStats config file (with -update option), or build\n";
5525 print " a HTML report (with -output option).\n";
5526 print " First, $PROG tries to read $PROG.virtualhostname.conf as the config file.\n";
5527 print " If not found, $PROG tries to read $PROG.conf\n";
5528 print " Note 1: Config files ($PROG.virtualhostname.conf or $PROG.conf) must be\n";
5529 print " in /etc/awstats, /usr/local/etc/awstats, /etc or same directory than\n";
5530 print " awstats.pl script file.\n";
5531 print " Note 2: If AWSTATS_FORCE_CONFIG environment variable is defined, AWStats will\n";
5532 print " use it as the \"config\" value, whatever is the value on command line or URL.\n";
5533 print " See AWStats documentation for all setup instrutions.\n";
5534 print "\n";
5535 print "Options to update statistics:\n";
5536 print " -update to update statistics (default)\n";
5537 print " -showsteps to add benchmark information every $NBOFLINESFORBENCHMARK lines processed\n";
5538 print " -showcorrupted to add output for each corrupted lines found, with reason\n";
5539 print " -showdropped to add output for each dropped lines found, with reason\n";
5540 print " -updatefor=n to stop the update process after parsing n lines\n";
5541 print " -LogFile=x to change log to analyze whatever is 'LogFile' in config file\n";
5542 print " Be care to process log files in chronological order when updating statistics.\n";
5543 print "\n";
5544 print "Options to show statistics:\n";
5545 rizwank 1.1 print " -output to output main HTML report (no update made except with -update)\n";
5546 print " -output=x to output other report pages where x is:\n";
5547 print " alldomains to build page of all domains/countries\n";
5548 print " allhosts to build page of all hosts\n";
5549 print " lasthosts to build page of last hits for hosts\n";
5550 print " unknownip to build page of all unresolved IP\n";
5551 print " allemails to build page of all email senders (maillog)\n";
5552 print " lastemails to build page of last email senders (maillog)\n";
5553 print " allemailr to build page of all email receivers (maillog)\n";
5554 print " lastemailr to build page of last email receivers (maillog)\n";
5555 print " alllogins to build page of all logins used\n";
5556 print " lastlogins to build page of last hits for logins\n";
5557 print " allrobots to build page of all robots/spider visits\n";
5558 print " lastrobots to build page of last hits for robots\n";
5559 print " urldetail to list most often viewed pages \n";
5560 print " urldetail:filter to list most often viewed pages matching filter\n";
5561 print " urlentry to list entry pages\n";
5562 print " urlentry:filter to list entry pages matching filter\n";
5563 print " urlexit to list exit pages\n";
5564 print " urlexit:filter to list exit pages matching filter\n";
5565 print " osdetail to build page with os detailed versions\n";
5566 rizwank 1.1 print " browserdetail to build page with browsers detailed versions\n";
5567 print " unknownbrowser to list 'User Agents' with unknown browser\n";
5568 print " unknownos to list 'User Agents' with unknown OS\n";
5569 print " refererse to build page of all refering search engines\n";
5570 print " refererpages to build page of all refering pages\n";
5571 #print " referersites to build page of all refering sites\n";
5572 print " keyphrases to list all keyphrases used on search engines\n";
5573 print " keywords to list all keywords used on search engines\n";
5574 print " errors404 to list 'Referers' for 404 errors\n";
5575 print " -staticlinks to have static links in HTML report page\n";
5576 print " -staticlinksext=xxx to have static links with .xxx extension instead of .html\n";
5577 print " -lang=LL to output a HTML report in language LL (en,de,es,fr,it,nl,...)\n";
5578 print " -month=MM to output a HTML report for an old month MM\n";
5579 print " -year=YYYY to output a HTML report for an old year YYYY\n";
5580 print " Those 'date' options doesn't allow you to process old log file. They only\n";
5581 print " allow you to see a past report for a chosen month/year period instead of\n";
5582 print " current month/year.\n";
5583 print "\n";
5584 print "Other options:\n";
5585 print " -debug=X to add debug informations lesser than level X (speed reduced)\n";
5586 print "\n";
5587 rizwank 1.1 print "Now supports/detects:\n";
5588 print " Web/Ftp/Mail log analyze (and load balanced log files)\n";
5589 print " Reverse DNS lookup (IPv4 and IPv6) and GeoIP lookup\n";
5590 print " Number of visits, number of unique visitors\n";
5591 print " Visits duration and list of last visits\n";
5592 print " Authenticated users\n";
5593 print " Days of week and rush hours\n";
5594 print " Hosts list and unresolved IP addresses list\n";
5595 print " Most viewed, entry and exit pages\n";
5596 print " Files type and Web compression (mod_gzip, mod_deflate stats)\n";
5597 print " Screen size\n";
5598 print " Number of times site is 'added to favorites bookmarks'\n";
5599 print " Ratio of Browsers with support of: Java, Flash, RealG2 reader,\n";
5600 print " Quicktime reader, WMA reader, PDF reader\n";
5601 print " Configurable personalized reports\n";
5602 print " ".(scalar keys %DomainsHashIDLib)." domains/countries\n";
5603 print " ".(scalar keys %RobotsHashIDLib)." robots\n";
5604 print " ".(scalar keys %WormsHashLib)." worm's families\n";
5605 print " ".(scalar keys %OSHashLib)." operating systems\n";
5606 print " ".(scalar keys %BrowsersHashIDLib)." browsers\n";
5607 print " ".(scalar keys %SearchEnginesHashLib)." search engines (and keyphrases/keywords used from them)\n";
5608 rizwank 1.1 print " All HTTP errors with last referrer\n";
5609 print " Report by day/month/year\n";
5610 print " Dynamic or static HTML or XHTML reports, static PDF reports\n";
5611 print " Indexed text or XML monthly database\n";
5612 print " And a lot of other advanced features and options...\n";
5613 print "New versions and FAQ at http://awstats.sourceforge.net\n";
5614 exit 2;
5615 }
5616 $SiteConfig||=&Sanitize($ENV{'SERVER_NAME'});
5617 #$ENV{'SERVER_NAME'}||=$SiteConfig; # For thoose who use __SERVER_NAME__ in conf file and use CLI.
5618 $ENV{'AWSTATS_CURRENT_CONFIG'}=$SiteConfig;
5619
5620 # Read config file (SiteConfig must be defined)
5621 &Read_Config($DirConfig);
5622
5623 # Check language
5624 if ($QueryString =~ /(^|&)lang=([^&]+)/i) { $Lang="$2"; }
5625 if (! $Lang || $Lang eq 'auto') { # If lang not defined or forced to auto
5626 my $langlist=$ENV{'HTTP_ACCEPT_LANGUAGE'}||''; $langlist =~ s/;[^,]*//g;
5627 if ($Debug) { debug("Search an available language among HTTP_ACCEPT_LANGUAGE=$langlist",1); }
5628 foreach my $code (split(/,/,$langlist)) { # Search for a valid lang in priority
5629 rizwank 1.1 if ($LangBrowserToLangAwstats{$code}) { $Lang=$LangBrowserToLangAwstats{$code}; if ($Debug) { debug(" Will try to use Lang=$Lang",1); } last; }
5630 $code =~ s/-.*$//;
5631 if ($LangBrowserToLangAwstats{$code}) { $Lang=$LangBrowserToLangAwstats{$code}; if ($Debug) { debug(" Will try to use Lang=$Lang",1); } last; }
5632 }
5633 }
5634 if (! $Lang || $Lang eq 'auto') {
5635 if ($Debug) { debug(" No language defined or available. Will use Lang=en",1); }
5636 $Lang='en';
5637 }
5638
5639 # Check and correct bad parameters
5640 &Check_Config();
5641 # Now SiteDomain is defined
5642
5643 # Define frame name and correct variable for frames
5644 if (! $FrameName) {
5645 if ($ENV{'GATEWAY_INTERFACE'} && $UseFramesWhenCGI && $HTMLOutput{'main'} && ! $PluginMode) { $FrameName='index'; }
5646 else { $FrameName='main'; }
5647 }
5648
5649 # Load Message files, Reference data files and Plugins
5650 rizwank 1.1 if ($Debug) { debug("FrameName=$FrameName",1); }
5651 if ($FrameName ne 'index') {
5652 &Read_Language_Data($Lang);
5653 if ($FrameName ne 'mainleft') {
5654 my %datatoload=();
5655 if ($UpdateStats) { # If update
5656 if ($LevelForFileTypesDetection<2) { $datatoload{'mime'}=1; } # Only if need to filter on known extensions
5657 if ($LevelForRobotsDetection) { $datatoload{'robots'}=1; } # ua
5658 if ($LevelForWormsDetection) { $datatoload{'worms'}=1; } # url
5659 if ($LevelForBrowsersDetection) { $datatoload{'browsers'}=1; } # ua
5660 if ($LevelForOSDetection) { $datatoload{'operating_systems'}=1; } # ua
5661 if ($LevelForRefererAnalyze) { $datatoload{'search_engines'}=1; } # referer
5662 # if (...) { $datatoload{'referer_spam'}=1; }
5663 }
5664 if (scalar keys %HTMLOutput) { # If output
5665 if ($ShowDomainsStats) { $datatoload{'domains'}=1; }
5666 if ($ShowFileTypesStats) { $datatoload{'mime'}=1; }
5667 if ($ShowRobotsStats) { $datatoload{'robots'}=1; }
5668 if ($ShowWormsStats) { $datatoload{'worms'}=1; }
5669 if ($ShowBrowsersStats) { $datatoload{'browsers'}=1; }
5670 if ($ShowOSStats) { $datatoload{'operating_systems'}=1; }
5671 rizwank 1.1 if ($ShowOriginStats) { $datatoload{'search_engines'}=1; }
5672 if ($ShowHTTPErrorsStats) { $datatoload{'status_http'}=1; }
5673 if ($ShowSMTPErrorsStats) { $datatoload{'status_smtp'}=1; }
5674 }
5675 &Read_Ref_Data(keys %datatoload);
5676 }
5677 &Read_Plugins();
5678 }
5679 # Here charset is defined, so we can send the http header (Need BuildReportFormat,PageCode)
5680 if (! $HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'}) { http_head(); } # Run from a browser as CGI
5681
5682 # Init other parameters
5683 $NBOFLINESFORBENCHMARK--;
5684 if ($ENV{'GATEWAY_INTERFACE'}) { $DirCgi=''; }
5685 if ($DirCgi && !($DirCgi =~ /\/$/) && !($DirCgi =~ /\\$/)) { $DirCgi .= '/'; }
5686 if (! $DirData || $DirData =~ /^\./) {
5687 if (! $DirData || $DirData eq '.') { $DirData="$DIR"; } # If not defined or chosen to '.' value then DirData is current dir
5688 elsif ($DIR && $DIR ne '.') { $DirData="$DIR/$DirData"; }
5689 }
5690 $DirData||='.'; # If current dir not defined then we put it to '.'
5691 $DirData =~ s/[\\\/]+$//;
5692 rizwank 1.1
5693 if ($FirstDayOfWeek == 1) { @DOWIndex = (1,2,3,4,5,6,0); }
5694 else { @DOWIndex = (0,1,2,3,4,5,6); }
5695
5696 # Should we link to ourselves or to a wrapper script
5697 $AWScript=($WrapperScript?"$WrapperScript":"$DirCgi$PROG.$Extension");
5698
5699 # Print html header (Need HTMLOutput,Expires,Lang,StyleSheet,HTMLHeadSectionExpires defined by Read_Config, PageCode defined by Read_Language_Data)
5700 if (! $HeaderHTMLSent) { &html_head; }
5701
5702 # AWStats output is replaced by a plugin output
5703 if ($PluginMode) {
5704 my $function="BuildFullHTMLOutput_$PluginMode()";
5705 eval("$function");
5706 if ($? || $@) { error("$@"); }
5707 &html_end(0);
5708 exit 0;
5709 }
5710
5711 # Security check
5712 if ($AllowAccessFromWebToAuthenticatedUsersOnly && $ENV{'GATEWAY_INTERFACE'}) {
5713 rizwank 1.1 if ($Debug) { debug("REMOTE_USER=".$ENV{"REMOTE_USER"}); }
5714 if (! $ENV{"REMOTE_USER"}) {
5715 error("Access to statistics is only allowed from an authenticated session to authenticated users.");
5716 }
5717 if (@AllowAccessFromWebToFollowingAuthenticatedUsers) {
5718 my $userisinlist=0;
5719 my $currentuser=qr/^$ENV{"REMOTE_USER"}$/i;
5720 $currentuser =~ s/\s/%20/g; # Allow authenticated user with space in name to be compared to allowed user list
5721 foreach (@AllowAccessFromWebToFollowingAuthenticatedUsers) {
5722 if (/$currentuser/o) { $userisinlist=1; last; }
5723 }
5724 if (! $userisinlist) {
5725 error("User '".$ENV{"REMOTE_USER"}."' is not allowed to access statistics of this domain/config.");
5726 }
5727 }
5728 }
5729 if ($AllowAccessFromWebToFollowingIPAddresses && $ENV{'GATEWAY_INTERFACE'}) {
5730 my $useripaddress=&Convert_IP_To_Decimal($ENV{"REMOTE_ADDR"});
5731 my @allowaccessfromipaddresses = split (/[\s,]+/, $AllowAccessFromWebToFollowingIPAddresses);
5732 my $allowaccess = 0;
5733 foreach my $ipaddressrange (@allowaccessfromipaddresses) {
5734 rizwank 1.1 if ($ipaddressrange !~ /^(\d+\.\d+\.\d+\.\d+)(?:-(\d+\.\d+\.\d+\.\d+))*$/) {
5735 error("AllowAccessFromWebToFollowingIPAddresses is defined to '$AllowAccessFromWebToFollowingIPAddresses' but does not match the correct syntax: IPAddressMin[-IPAddressMax]");
5736 }
5737 my $ipmin=&Convert_IP_To_Decimal($1);
5738 my $ipmax=$2?&Convert_IP_To_Decimal($2):$ipmin;
5739 # Is it an authorized ip ?
5740 if (($useripaddress >= $ipmin) && ($useripaddress <= $ipmax)) {
5741 $allowaccess = 1;
5742 last;
5743 }
5744 }
5745 if (! $allowaccess) {
5746 error("Access to statistics is not allowed from your IP Address ".$ENV{"REMOTE_ADDR"});
5747 }
5748 }
5749 if (($UpdateStats || $MigrateStats) && (! $AllowToUpdateStatsFromBrowser) && $ENV{'GATEWAY_INTERFACE'}) {
5750 error("".($UpdateStats?"Update":"Migrate")." of statistics has not been allowed from a browser (AllowToUpdateStatsFromBrowser should be set to 1).");
5751 }
5752 if (scalar keys %HTMLOutput && $MonthRequired eq 'all') {
5753 if (! $AllowFullYearView) { error("Full year view has not been allowed (AllowFullYearView is set to 0)."); }
5754 if ($AllowFullYearView < 3 && $ENV{'GATEWAY_INTERFACE'}) { error("Full year view has not been allowed from a browser (AllowFullYearView should be set to 3)."); }
5755 rizwank 1.1 }
5756
5757
5758 #------------------------------------------
5759 # MIGRATE PROCESS (Must be after reading config cause we need MaxNbOf... and Min...)
5760 #------------------------------------------
5761 if ($MigrateStats) {
5762 if ($Debug) { debug("MigrateStats is $MigrateStats",2); }
5763 if ($MigrateStats !~ /^(.*)$PROG(\d{0,2})(\d\d)(\d\d\d\d)(.*)\.txt$/) {
5764 error("AWStats history file name must match following syntax: ${PROG}MMYYYY[.config].txt","","",1);
5765 }
5766 $DirData="$1";
5767 $DayRequired="$2";
5768 $MonthRequired="$3";
5769 $YearRequired="$4";
5770 $FileSuffix="$5";
5771 # Correct DirData
5772 if (! $DirData || $DirData =~ /^\./) {
5773 if (! $DirData || $DirData eq '.') { $DirData="$DIR"; } # If not defined or chosen to '.' value then DirData is current dir
5774 elsif ($DIR && $DIR ne '.') { $DirData="$DIR/$DirData"; }
5775 }
5776 rizwank 1.1 $DirData||='.'; # If current dir not defined then we put it to '.'
5777 $DirData =~ s/[\\\/]+$//;
5778 print "Start migration for file '$MigrateStats'."; print $ENV{'GATEWAY_INTERFACE'}?"<br />\n":"\n";
5779 if ($EnableLockForUpdate) { &Lock_Update(1); }
5780 my $newhistory=&Read_History_With_TmpUpdate($YearRequired,$MonthRequired,1,0,'all');
5781 if (rename("$newhistory","$MigrateStats")==0) {
5782 unlink "$newhistory";
5783 error("Failed to rename \"$newhistory\" into \"$MigrateStats\".\nWrite permissions on \"$MigrateStats\" might be wrong".($ENV{'GATEWAY_INTERFACE'}?" for a 'migration from web'":"")." or file might be opened.");
5784 }
5785 if ($EnableLockForUpdate) { &Lock_Update(0); }
5786 print "Migration for file '$MigrateStats' successful."; print $ENV{'GATEWAY_INTERFACE'}?"<br />\n":"\n";
5787 &html_end(1);
5788 exit 0;
5789 }
5790
5791 # Output main frame page and exit. This must be after the security check.
5792 if ($FrameName eq 'index') {
5793 # Define the NewLinkParams for main chart
5794 my $NewLinkParams=${QueryString};
5795 $NewLinkParams =~ s/(^|&)framename=[^&]*//i;
5796 $NewLinkParams =~ tr/&/&/s; $NewLinkParams =~ s/^&//; $NewLinkParams =~ s/&$//;
5797 rizwank 1.1 if ($NewLinkParams) { $NewLinkParams="${NewLinkParams}&"; }
5798 # Exit if main frame
5799 print "<frameset cols=\"$FRAMEWIDTH,*\" border=\"0\" framespacing=\"2\" frameborder=\"0\">\n";
5800 print "<frame name=\"mainleft\" src=\"".XMLEncode("$AWScript?${NewLinkParams}framename=mainleft")."\" noresize=\"0\" frameborder=\"0\" />\n";
5801 print "<frame name=\"mainright\" src=\"".XMLEncode("$AWScript?${NewLinkParams}framename=mainright")."\" noresize=\"0\" scrolling=\"YES\" frameborder=\"0\" />\n";
5802 print "<noframes><body>";
5803 print "Your browser does not support frames.<br />\n";
5804 print "You must set AWStats UseFramesWhenCGI parameter to 0\n";
5805 print "to see your reports.<br />\n";
5806 print "</body></noframes>\n";
5807 print "</frameset>\n";
5808 &html_end(0);
5809 exit 0;
5810 }
5811
5812 %MonthNumLib = ("01","$Message[60]","02","$Message[61]","03","$Message[62]","04","$Message[63]","05","$Message[64]","06","$Message[65]","07","$Message[66]","08","$Message[67]","09","$Message[68]","10","$Message[69]","11","$Message[70]","12","$Message[71]");
5813
5814 # Build ListOfYears list with all existing years
5815 if ($Debug) { debug("Scan for last history files into DirData='$DirData'"); }
5816 $lastyearbeforeupdate=0;
5817 opendir(DIR,"$DirData");
5818 rizwank 1.1 foreach (grep /^$PROG(\d\d)(\d\d\d\d)$FileSuffix\.txt(|\.gz)$/i, sort readdir DIR) {
5819 /^$PROG(\d\d)(\d\d\d\d)$FileSuffix\.txt(|\.gz)$/i;
5820 if (! $ListOfYears{"$2"} || "$1" gt $ListOfYears{"$2"}) {
5821 $ListOfYears{"$2"}="$1"; # ListOfYears contains max month found
5822 if ("$2" gt $lastyearbeforeupdate) { $lastyearbeforeupdate="$2"; }
5823 }
5824 }
5825 close DIR;
5826
5827 # Get value for LastLine
5828 if ($lastyearbeforeupdate) {
5829 # Read 'general' section of last history file for LastLine
5830 &Read_History_With_TmpUpdate($lastyearbeforeupdate,$ListOfYears{$lastyearbeforeupdate},0,0,"general");
5831 }
5832 if ($Debug) {
5833 debug("Last year=$lastyearbeforeupdate - Last month=$ListOfYears{$lastyearbeforeupdate}");
5834 debug("LastLine=$LastLine");
5835 debug("LastLineNumber=$LastLineNumber");
5836 debug("LastLineOffset=$LastLineOffset");
5837 debug("LastLineChecksum=$LastLineChecksum");
5838 }
5839 rizwank 1.1
5840 # Init vars
5841 &Init_HashArray();
5842
5843
5844 #------------------------------------------
5845 # UPDATE PROCESS
5846 #------------------------------------------
5847 my $lastlinenb=0; my $lastlineoffset=0; my $lastlineoffsetnext=0;
5848
5849 if ($Debug) { debug("UpdateStats is $UpdateStats",2); }
5850 if ($UpdateStats && $FrameName ne 'index' && $FrameName ne 'mainleft') { # Update only on index page or when not framed to avoid update twice
5851
5852 my %MonthNum = ("Jan","01","jan","01","Feb","02","feb","02","Mar","03","mar","03","Apr","04","apr","04","May","05","may","05","Jun","06","jun","06","Jul","07","jul","07","Aug","08","aug","08","Sep","09","sep","09","Oct","10","oct","10","Nov","11","nov","11","Dec","12","dec","12"); # MonthNum must be in english because used to translate log date in apache log files
5853
5854 if (! scalar keys %HTMLOutput) {
5855 print "Update for config \"$FileConfig\"\n";
5856 print "With data in log file \"$LogFile\"...\n";
5857 }
5858
5859 my $lastprocessedyear=$lastyearbeforeupdate;
5860 rizwank 1.1 my $lastprocessedmonth=$ListOfYears{$lastyearbeforeupdate}||0;
5861 my $lastprocessedyearmonth=sprintf("%04i%02i",$lastprocessedyear,$lastprocessedmonth);
5862
5863 my @list;
5864 # Init RobotsSearchIDOrder required for update process
5865 @list=();
5866 if ($LevelForRobotsDetection >= 1) {
5867 foreach (1..$LevelForRobotsDetection) { push @list,"list$_"; }
5868 push @list,"listgen"; # Always added
5869 }
5870 foreach my $key (@list) {
5871 push @RobotsSearchIDOrder,@{"RobotsSearchIDOrder_$key"};
5872 if ($Debug) { debug("Add ".@{"RobotsSearchIDOrder_$key"}." elements from RobotsSearchIDOrder_$key into RobotsSearchIDOrder",2); }
5873 }
5874 if ($Debug) { debug("RobotsSearchIDOrder has now ".@RobotsSearchIDOrder." elements",1); }
5875 # Init SearchEnginesIDOrder required for update process
5876 @list=();
5877 if ($LevelForSearchEnginesDetection >= 1) {
5878 foreach (1..$LevelForSearchEnginesDetection) { push @list,"list$_"; }
5879 push @list,"listgen"; # Always added
5880 }
5881 rizwank 1.1 foreach my $key (@list) {
5882 push @SearchEnginesSearchIDOrder,@{"SearchEnginesSearchIDOrder_$key"};
5883 if ($Debug) { debug("Add ".@{"SearchEnginesSearchIDOrder_$key"}." elements from SearchEnginesSearchIDOrder_$key into SearchEnginesSearchIDOrder",2); }
5884 }
5885 if ($Debug) { debug("SearchEnginesSearchIDOrder has now ".@SearchEnginesSearchIDOrder." elements",1); }
5886
5887 # Complete HostAliases array
5888 my $sitetoanalyze=quotemeta(lc($SiteDomain));
5889 if (! @HostAliases) {
5890 warning("Warning: HostAliases parameter is not defined, $PROG choose \"$SiteDomain localhost 127.0.0.1\".");
5891 push @HostAliases,qr/^$sitetoanalyze$/i; push @HostAliases,qr/^localhost$/i; push @HostAliases,qr/^127\.0\.0\.1$/i;
5892 }
5893 else { unshift @HostAliases,qr/^$sitetoanalyze$/i; } # Add SiteDomain as first value
5894
5895 # Optimize arrays
5896 @HostAliases=&OptimizeArray(\@HostAliases,1); if ($Debug) { debug("HostAliases precompiled regex list is now @HostAliases",1); }
5897 @SkipDNSLookupFor=&OptimizeArray(\@SkipDNSLookupFor,1); if ($Debug) { debug("SkipDNSLookupFor precompiled regex list is now @SkipDNSLookupFor",1); }
5898 @SkipHosts=&OptimizeArray(\@SkipHosts,1); if ($Debug) { debug("SkipHosts precompiled regex list is now @SkipHosts",1); }
5899 @SkipUserAgents=&OptimizeArray(\@SkipUserAgents,1); if ($Debug) { debug("SkipUserAgents precompiled regex list is now @SkipUserAgents",1); }
5900 @SkipFiles=&OptimizeArray(\@SkipFiles,$URLNotCaseSensitive); if ($Debug) { debug("SkipFiles precompiled regex list is now @SkipFiles",1); }
5901 @OnlyHosts=&OptimizeArray(\@OnlyHosts,1); if ($Debug) { debug("OnlyHosts precompiled regex list is now @OnlyHosts",1); }
5902 rizwank 1.1 @OnlyUserAgents=&OptimizeArray(\@OnlyUserAgents,1); if ($Debug) { debug("OnlyUserAgents precompiled regex list is now @OnlyUserAgents",1); }
5903 @OnlyFiles=&OptimizeArray(\@OnlyFiles,$URLNotCaseSensitive); if ($Debug) { debug("OnlyFiles precompiled regex list is now @OnlyFiles",1); }
5904 # Precompile the regex search strings with qr
5905 @RobotsSearchIDOrder=map{qr/$_/i} @RobotsSearchIDOrder;
5906 @WormsSearchIDOrder=map{qr/$_/i} @WormsSearchIDOrder;
5907 @BrowsersSearchIDOrder=map{qr/$_/i} @BrowsersSearchIDOrder;
5908 @OSSearchIDOrder=map{qr/$_/i} @OSSearchIDOrder;
5909 @SearchEnginesSearchIDOrder=map{qr/$_/i} @SearchEnginesSearchIDOrder;
5910 my $miscquoted=quotemeta("$MiscTrackerUrl");
5911 my $defquoted=quotemeta("/$DefaultFile[0]");
5912 my $sitewithoutwww=lc($SiteDomain); $sitewithoutwww =~ s/www\.//; $sitewithoutwww=quotemeta($sitewithoutwww);
5913 # Define precompiled regex
5914 my $regmisc=qr/^$miscquoted/;
5915 my $regfavico=qr/\/favicon\.ico$/i;
5916 my $regrobot=qr/^\/robots\.txt$/i;
5917 my $regtruncanchor=qr/#(\w*)$/;
5918 my $regtruncurl=qr/([$URLQuerySeparators])(.*)$/;
5919 my $regext=qr/\.(\w{1,6})$/;
5920 my $regdefault;
5921 if ($URLNotCaseSensitive) { $regdefault=qr/$defquoted$/i; }
5922 else { $regdefault=qr/$defquoted$/; }
5923 rizwank 1.1 my $regipv4=qr/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
5924 my $regipv6=qr/^[0-9A-F]*:/i;
5925 my $regvermsie=qr/msie([+_ ]|)([\d\.]*)/i;
5926 my $regvernetscape=qr/netscape.?\/([\d\.]*)/i;
5927 my $regverfirefox=qr/firefox\/([\d\.]*)/i;
5928 my $regvermozilla=qr/mozilla(\/|)([\d\.]*)/i;
5929 my $regnotie=qr/webtv|omniweb|opera/i;
5930 my $regnotnetscape=qr/gecko|compatible|opera|galeon|safari/i;
5931 my $regreferer=qr/^(\w+):\/\/([^\/:]+)(:\d+|)/;
5932 my $regreferernoquery=qr/^([^$URLQuerySeparators]+)/;
5933 my $reglocal=qr/^(www\.|)$sitewithoutwww/i;
5934 my $regget=qr/get/i;
5935 my $regsent=qr/sent/i;
5936 my $regput=qr/put/i;
5937
5938 # Define value of $PerlParsingFormat and @fieldlib
5939 &DefinePerlParsingFormat();
5940
5941 # Load DNS Cache Files
5942 #------------------------------------------
5943 if ($DNSLookup) {
5944 rizwank 1.1 &Read_DNS_Cache(\%MyDNSTable,"$DNSStaticCacheFile","",1); # Load with save into a second plugin file if plugin enabled and second file not up to date. No use of FileSuffix
5945 if ($DNSLookup == 1) { # System DNS lookup required
5946 #if (! eval("use Socket;")) { error("Failed to load perl module Socket."); }
5947 #use Socket;
5948 &Read_DNS_Cache(\%TmpDNSLookup,"$DNSLastUpdateCacheFile","$FileSuffix",0); # Load with no save into a second plugin file. Use FileSuffix
5949 }
5950 }
5951
5952 # Processing log
5953 #------------------------------------------
5954
5955 if ($EnableLockForUpdate) {
5956 # Trap signals to remove lock
5957 $SIG{INT} = \&SigHandler; # 2
5958 #$SIG{KILL} = \&SigHandler; # 9
5959 #$SIG{TERM} = \&SigHandler; # 15
5960 # Set AWStats update lock
5961 &Lock_Update(1);
5962 }
5963
5964 if ($Debug) { debug("Start Update process (lastprocessedmonth=$lastprocessedmonth, lastprocessedyear=$lastprocessedyear)"); }
5965 rizwank 1.1
5966 # Open log file
5967 if ($Debug) { debug("Open log file \"$LogFile\""); }
5968 open(LOG,"$LogFile") || error("Couldn't open server log file \"$LogFile\" : $!");
5969 binmode LOG; # Avoid premature EOF due to log files corrupted with \cZ or bin chars
5970
5971 # Define local variables for loop scan
5972 my @field=();
5973 my $counterforflushtest=0;
5974 my $qualifdrop='';
5975 my $countedtraffic=0;
5976 # Reset chrono for benchmark (first call to GetDelaySinceStart)
5977 &GetDelaySinceStart(1);
5978 if (! scalar keys %HTMLOutput) { print "Phase 1 : First bypass old records, searching new record...\n"; }
5979
5980 # Can we try a direct seek access in log ?
5981 my $line;
5982 if ($LastLine && $LastLineNumber && $LastLineOffset && $LastLineChecksum) {
5983 # Try a direct seek access to save time
5984 if ($Debug) { debug("Try a direct access to LastLine=$LastLine, LastLineNumber=$LastLineNumber, LastLineOffset=$LastLineOffset, LastLineChecksum=$LastLineChecksum"); }
5985 seek(LOG,$LastLineOffset,0);
5986 rizwank 1.1 if ($line=<LOG>) {
5987 chomp $line; $line =~ s/\r$//;
5988 @field=map(/$PerlParsingFormat/,$line);
5989 if ($Debug) {
5990 my $string='';
5991 foreach (0..@field-1) { $string.="$fieldlib[$_]=$field[$_] "; }
5992 if ($Debug) { debug(" Read line after direct access: $string",1); }
5993 }
5994 my $checksum=&CheckSum($line);
5995 if ($Debug) { debug(" LastLineChecksum=$LastLineChecksum, Read line checksum=$checksum",1); }
5996 if ($checksum == $LastLineChecksum ) {
5997 if (! scalar keys %HTMLOutput) { print "Direct access after last parsed record (after line $LastLineNumber)\n"; }
5998 $lastlinenb=$LastLineNumber;
5999 $lastlineoffset=$LastLineOffset;
6000 $lastlineoffsetnext=tell LOG;
6001 $NewLinePhase=1;
6002 }
6003 else {
6004 if (! scalar keys %HTMLOutput) { print "Direct access to last remembered record has fallen on another record.\nSo searching new records from beginning of log file...\n"; }
6005 $lastlinenb=0;
6006 $lastlineoffset=0;
6007 rizwank 1.1 $lastlineoffsetnext=0;
6008 seek(LOG,0,0);
6009 }
6010 }
6011 else {
6012 if (! scalar keys %HTMLOutput) { print "Direct access to last remembered record is out of file.\nSo searching it from beginning of log file...\n"; }
6013 $lastlinenb=0;
6014 $lastlineoffset=0;
6015 $lastlineoffsetnext=0;
6016 seek(LOG,0,0);
6017 }
6018 }
6019 else {
6020 # No try of direct seek access
6021 if (! scalar keys %HTMLOutput) { print "Searching new records from beginning of log file...\n"; }
6022 $lastlinenb=0;
6023 $lastlineoffset=0;
6024 $lastlineoffsetnext=0;
6025 }
6026
6027 while ($line=<LOG>) {
6028 rizwank 1.1 chomp $line; $line =~ s/\r$//;
6029 if ($UpdateFor && $NbOfLinesParsed >= $UpdateFor) { last; }
6030 $NbOfLinesParsed++;
6031
6032 $lastlineoffset=$lastlineoffsetnext; $lastlineoffsetnext=tell LOG;
6033
6034 if ($ShowSteps) {
6035 if ((++$NbOfLinesShowsteps & $NBOFLINESFORBENCHMARK) == 0) {
6036 my $delay=&GetDelaySinceStart(0);
6037 print "$NbOfLinesParsed lines processed (".($delay>0?$delay:1000)." ms, ".int(1000*$NbOfLinesShowsteps/($delay>0?$delay:1000))." lines/second)\n";
6038 }
6039 }
6040
6041 # Parse line record to get all required fields
6042 if (! (@field=map(/$PerlParsingFormat/,$line))) {
6043 $NbOfLinesCorrupted++;
6044 if ($ShowCorrupted) {
6045 if ($line =~ /^#/ || $line =~ /^!/) { print "Corrupted record line ".($lastlinenb+$NbOfLinesParsed)." (comment line): $line\n"; }
6046 elsif ($line =~ /^\s*$/) { print "Corrupted record line ".($lastlinenb+$NbOfLinesParsed)." (blank line)\n"; }
6047 else { print "Corrupted record line ".($lastlinenb+$NbOfLinesParsed)." (record format does not match LogFormat parameter): $line\n"; }
6048 }
6049 rizwank 1.1 if ($NbOfLinesParsed >= $NbOfLinesForCorruptedLog && $NbOfLinesParsed == $NbOfLinesCorrupted) { error("Format error",$line,$LogFile); } # Exit with format error
6050 if ($line =~ /^__end_of_file__/i) { last; } # For test purpose only
6051 next;
6052 }
6053
6054 if ($Debug) {
6055 my $string='';
6056 foreach (0..@field-1) { $string.="$fieldlib[$_]=$field[$_] "; }
6057 if ($Debug) { debug(" Correct format line ".($lastlinenb+$NbOfLinesParsed).": $string",4); }
6058 }
6059
6060 # Drop wrong virtual host name
6061 #----------------------------------------------------------------------
6062 if ($pos_vh>=0 && $field[$pos_vh] !~ /^$SiteDomain$/i) {
6063 my $skip=1;
6064 foreach (@HostAliases) {
6065 if ($field[$pos_vh] =~ /$_/) { $skip=0; last; }
6066 }
6067 if ($skip) {
6068 $NbOfLinesDropped++;
6069 if ($ShowDropped) { print "Dropped record (virtual hostname '$field[$pos_vh]' does not match SiteDomain='$SiteDomain' nor HostAliases parameters): $line\n"; }
6070 rizwank 1.1 next;
6071 }
6072 }
6073
6074 # Drop wrong method/protocol
6075 #---------------------------
6076 if ($LogType ne 'M') { $field[$pos_url] =~ s/\s/%20/g; }
6077 if ($LogType eq 'W' && ($field[$pos_method] eq 'GET' || $field[$pos_method] eq 'POST' || $field[$pos_method] eq 'HEAD' || $field[$pos_method] =~ /OK/i || $field[$pos_method] =~ /ERR\!/i)) {
6078 # HTTP request. Keep only GET, POST, HEAD, *OK* and ERR! for Webstar. Do not keep OPTIONS, TRACE
6079 }
6080 elsif (($LogType eq 'W' || $LogType eq 'S') && ($field[$pos_method] eq 'GET' || $field[$pos_method] eq 'mms' || $field[$pos_method] eq 'rtsp' || $field[$pos_method] eq 'http' || $field[$pos_method] eq 'RTP')) {
6081 # Streaming request (windows media server, realmedia or darwin streaming server)
6082 }
6083 elsif ($LogType eq 'M' && $field[$pos_method] eq 'SMTP') {
6084 # Mail request ('SMTP' for mail log with maillogconvert.pl preprocessor)
6085 }
6086 elsif ($LogType eq 'F' && ($field[$pos_method] eq 'RETR' || $field[$pos_method] eq 'o' || $field[$pos_method] =~ /$regget/o)) {
6087 # FTP GET request
6088 }
6089 elsif ($LogType eq 'F' && ($field[$pos_method] eq 'STOR' || $field[$pos_method] eq 'i' || $field[$pos_method] =~ /$regsent/o || $field[$pos_method] =~ /$regput/o)) {
6090 # FTP SENT request
6091 rizwank 1.1 }
6092 else {
6093 $NbOfLinesDropped++;
6094 if ($ShowDropped) { print "Dropped record (method/protocol '$field[$pos_method]' not qualified when LogType=$LogType): $line\n"; }
6095 next;
6096 }
6097
6098 $field[$pos_date] =~ tr/,-\/ \t/:::::/s; # " \t" is used instead of "\s" not known with tr
6099 my @dateparts=split(/:/,$field[$pos_date]); # tr and split faster than @dateparts=split(/[\/\-:\s]/,$field[$pos_date])
6100 # Detected date format: dddddddddd, YYYY-MM-DD HH:MM:SS (IIS), MM/DD/YY\tHH:MM:SS,
6101 # DD/Month/YYYY:HH:MM:SS (Apache), DD/MM/YYYY HH:MM:SS, Mon DD HH:MM:SS
6102 if (! $dateparts[1]) { # Unix timestamp
6103 ($dateparts[5],$dateparts[4],$dateparts[3],$dateparts[0],$dateparts[1],$dateparts[2]) = localtime(int($field[$pos_date]));
6104 $dateparts[1]++;$dateparts[2]+=1900;
6105 }
6106 elsif ($dateparts[0] =~ /^....$/) { my $tmp=$dateparts[0]; $dateparts[0]=$dateparts[2]; $dateparts[2]=$tmp; }
6107 elsif ($field[$pos_date] =~ /^..:..:..:/) { $dateparts[2]+=2000; my $tmp=$dateparts[0]; $dateparts[0]=$dateparts[1]; $dateparts[1]=$tmp; }
6108 elsif ($dateparts[0] =~ /^...$/) { my $tmp=$dateparts[0]; $dateparts[0]=$dateparts[1]; $dateparts[1]=$tmp; $tmp=$dateparts[5]; $dateparts[5]=$dateparts[4]; $dateparts[4]=$dateparts[3]; $dateparts[3]=$dateparts[2]; $dateparts[2]=$tmp||$nowyear; }
6109 if ($MonthNum{$dateparts[1]}) { $dateparts[1]=$MonthNum{$dateparts[1]}; } # Change lib month in num month if necessary
6110
6111 # Now @dateparts is (DD,MM,YYYY,HH,MM,SS) and we're going to create $timerecord=YYYYMMDDHHMMSS
6112 rizwank 1.1 # Plugin call : Convert a @datepart into another @datepart
6113 if ($PluginsLoaded{'ChangeTime'}{'timezone'}) { @dateparts=ChangeTime_timezone(\@dateparts); }
6114 my $yearrecord=int($dateparts[2]);
6115 my $monthrecord=int($dateparts[1]);
6116 my $hourrecord=int($dateparts[3]);
6117 my $yearmonthdayrecord=sprintf("$dateparts[2]%02i%02i",$dateparts[1],$dateparts[0]);
6118 my $timerecord=((int("$yearmonthdayrecord")*100+$dateparts[3])*100+$dateparts[4])*100+$dateparts[5];
6119
6120 # Check date
6121 #-----------------------
6122 if ($LogType eq 'M' && $timerecord > $tomorrowtime) {
6123 # Postfix/Sendmail does not store year, so we assume that year is year-1 if record is in future
6124 $yearrecord--;
6125 $yearmonthdayrecord=sprintf("$yearrecord%02i%02i",$dateparts[1],$dateparts[0]);
6126 $timerecord=((int("$yearmonthdayrecord")*100+$dateparts[3])*100+$dateparts[4])*100+$dateparts[5];
6127 }
6128 if ($timerecord < 10000000000000 || $timerecord > $tomorrowtime) {
6129 $NbOfLinesCorrupted++;
6130 if ($ShowCorrupted) { print "Corrupted record (invalid date, timerecord=$timerecord): $line\n"; }
6131 next; # Should not happen, kept in case of parasite/corrupted line
6132 }
6133 rizwank 1.1 if ($NewLinePhase) {
6134 # TODO NOTSORTEDRECORDTOLERANCE does not work around midnight
6135 if ($timerecord < ($LastLine - $NOTSORTEDRECORDTOLERANCE)) {
6136 # Should not happen, kept in case of parasite/corrupted old line
6137 $NbOfLinesCorrupted++;
6138 if ($ShowCorrupted) { print "Corrupted record (date $timerecord lower than $LastLine-$NOTSORTEDRECORDTOLERANCE): $line\n"; } next;
6139 }
6140 }
6141 else {
6142 if ($timerecord <= $LastLine) { # Already processed
6143 $NbOfOldLines++;
6144 next;
6145 }
6146 # We found a new line. This will replace comparison "<=" with "<" between timerecord and LastLine (we should have only new lines now)
6147 $NewLinePhase=1; # We will never enter here again
6148 if ($ShowSteps) {
6149 if ($NbOfLinesShowsteps > 1 && ($NbOfLinesShowsteps & $NBOFLINESFORBENCHMARK)) {
6150 my $delay=&GetDelaySinceStart(0);
6151 print "".($NbOfLinesParsed-1)." lines processed (".($delay>0?$delay:1000)." ms, ".int(1000*($NbOfLinesShowsteps-1)/($delay>0?$delay:1000))." lines/second)\n";
6152 }
6153 &GetDelaySinceStart(1); $NbOfLinesShowsteps=1;
6154 rizwank 1.1 }
6155 if (! scalar keys %HTMLOutput) {
6156 print "Phase 2 : Now process new records (Flush history on disk after ".($LIMITFLUSH<<2)." hosts)...\n";
6157 #print "Phase 2 : Now process new records (Flush history on disk after ".($LIMITFLUSH<<2)." hosts or ".($LIMITFLUSH)." URLs)...\n";
6158 }
6159 }
6160
6161 # Convert URL for Webstar to common URL
6162 if ($LogFormat eq '3') {
6163 $field[$pos_url]=~s/:/\//g;
6164 if ($field[$pos_code] eq '-') { $field[$pos_code]='200'; }
6165 }
6166
6167 # Here, field array, timerecord and yearmonthdayrecord are initialized for log record
6168 if ($Debug) { debug(" This is a not already processed record ($timerecord)",4); }
6169
6170 # We found a new line
6171 #----------------------------------------
6172 if ($timerecord > $LastLine) { $LastLine = $timerecord; } # Test should always be true except with not sorted log files
6173
6174 # Skip for some client host IP addresses, some URLs, other URLs
6175 rizwank 1.1 if (@SkipHosts && (&SkipHost($field[$pos_host]) || ($pos_hostr && &SkipHost($field[$pos_hostr])))) { $qualifdrop="Dropped record (host $field[$pos_host]".($pos_hostr?" and $field[$pos_hostr]":"")." not qualified by SkipHosts)"; }
6176 elsif (@SkipFiles && &SkipFile($field[$pos_url])) { $qualifdrop="Dropped record (URL $field[$pos_url] not qualified by SkipFiles)"; }
6177 elsif (@SkipUserAgents && $pos_agent >= 0 && &SkipUserAgent($field[$pos_agent])) { $qualifdrop="Dropped record (user agent '$field[$pos_agent]' not qualified by SkipUserAgents)"; }
6178 elsif (@OnlyHosts && ! &OnlyHost($field[$pos_host]) && (! $pos_hostr || ! &OnlyHost($field[$pos_hostr]))) { $qualifdrop="Dropped record (host $field[$pos_host]".($pos_hostr?" and $field[$pos_hostr]":"")." not qualified by OnlyHosts)"; }
6179 elsif (@OnlyFiles && ! &OnlyFile($field[$pos_url])) { $qualifdrop="Dropped record (URL $field[$pos_url] not qualified by OnlyFiles)"; }
6180 elsif (@OnlyUserAgents && ! &OnlyUserAgent($field[$pos_agent])) { $qualifdrop="Dropped record (user agent '$field[$pos_agent]' not qualified by OnlyUserAgents)"; }
6181 if ($qualifdrop) {
6182 $NbOfLinesDropped++;
6183 if ($Debug) { debug("$qualifdrop: $line",4); }
6184 if ($ShowDropped) { print "$qualifdrop: $line\n"; }
6185 $qualifdrop='';
6186 next;
6187 }
6188
6189 # Record is approved
6190 #-------------------
6191
6192 # Is it in a new month section ?
6193 #-------------------------------
6194 if ((($monthrecord > $lastprocessedmonth) && ($yearrecord >= $lastprocessedyear)) || ($yearrecord > $lastprocessedyear)) {
6195 # A new month to process
6196 rizwank 1.1 if ($lastprocessedmonth) {
6197 # We save data of processed month
6198 &Read_History_With_TmpUpdate($lastprocessedyear,$lastprocessedmonth,1,1,"all",($lastlinenb+$NbOfLinesParsed),$lastlineoffset,&CheckSum($line));
6199 $counterforflushtest=0; # We reset counterforflushtest
6200 }
6201 $lastprocessedyearmonth=sprintf("%04i%02i",$lastprocessedyear=$yearrecord,$lastprocessedmonth=$monthrecord);
6202 }
6203
6204 $countedtraffic=0;
6205 $NbOfNewLines++;
6206
6207 # Convert $field[$pos_size]
6208 # if ($field[$pos_size] eq '-') { $field[$pos_size]=0; }
6209
6210 # Define a clean target URL and referrer URL
6211 # We keep a clean $field[$pos_url] and
6212 # we store original value for urlwithnoquery, tokenquery and standalonequery
6213 #---------------------------------------------------------------------------
6214 if ($URLNotCaseSensitive) { $field[$pos_url]=lc($field[$pos_url]); }
6215 # Possible URL syntax for $field[$pos_url]: /mydir/mypage.ext?param1=x¶m2=y#aaa, /mydir/mypage.ext#aaa, /
6216 my $urlwithnoquery; my $tokenquery; my $standalonequery; my $anchor='';
6217 rizwank 1.1 if ($field[$pos_url] =~ s/$regtruncanchor//o) { $anchor=$1; } # Remove and save anchor
6218 if ($URLWithQuery) {
6219 $urlwithnoquery=$field[$pos_url];
6220 my $foundparam=($urlwithnoquery =~ s/$regtruncurl//o);
6221 $tokenquery=$1||'';
6222 $standalonequery=$2||'';
6223 # For IIS setup, if pos_query is enabled we need to combine the URL to query strings
6224 if (! $foundparam && $pos_query >=0 && $field[$pos_query] && $field[$pos_query] ne '-') {
6225 $foundparam=1;
6226 $tokenquery='?';
6227 $standalonequery=$field[$pos_query];
6228 # Define query
6229 $field[$pos_url] .= '?'.$field[$pos_query];
6230 }
6231 if ($foundparam) {
6232 # Keep only params that are defined in URLWithQueryWithOnlyFollowingParameters
6233 my $newstandalonequery='';
6234 if (@URLWithQueryWithOnly) {
6235 foreach (@URLWithQueryWithOnly) {
6236 foreach my $p (split(/&/,$standalonequery)) {
6237 if ($URLNotCaseSensitive) { if ($p =~ /^$_=/i) { $newstandalonequery.="$p&"; last; } }
6238 rizwank 1.1 else { if ($p =~ /^$_=/) { $newstandalonequery.="$p&"; last; } }
6239 }
6240 }
6241 chop $newstandalonequery;
6242 }
6243 # Remove params that are marked to be ignored in URLWithQueryWithoutFollowingParameters
6244 elsif (@URLWithQueryWithout) {
6245 foreach my $p (split(/&/,$standalonequery)) {
6246 my $found=0;
6247 foreach (@URLWithQueryWithout) {
6248 #if ($Debug) { debug(" Check if '$_=' is param '$p' to remove it from query",5); }
6249 if ($URLNotCaseSensitive) { if ($p =~ /^$_=/i) { $found=1; last; } }
6250 else { if ($p =~ /^$_=/) { $found=1; last; } }
6251 }
6252 if (! $found) { $newstandalonequery.="$p&"; }
6253 }
6254 chop $newstandalonequery;
6255 }
6256 else { $newstandalonequery=$standalonequery; }
6257 # Define query
6258 $field[$pos_url]=$urlwithnoquery;
6259 rizwank 1.1 if ($newstandalonequery) { $field[$pos_url].="$tokenquery$newstandalonequery"; }
6260 }
6261 }
6262 else {
6263 # Trunc parameters of URL
6264 $field[$pos_url] =~ s/$regtruncurl//o;
6265 $urlwithnoquery=$field[$pos_url];
6266 $tokenquery=$1||'';
6267 $standalonequery=$2||'';
6268 # For IIS setup, if pos_query is enabled we need to use it for query strings
6269 if ($pos_query >=0 && $field[$pos_query] && $field[$pos_query] ne '-') {
6270 $tokenquery='?';
6271 $standalonequery=$field[$pos_query];
6272 }
6273 }
6274 if ($URLWithAnchor && $anchor) { $field[$pos_url].="#$anchor"; } # Restore anchor
6275 # Here now urlwithnoquery is /mydir/mypage.ext, /mydir, /, /page#XXX
6276 # Here now tokenquery is '' or '?' or ';'
6277 # Here now standalonequery is '' or 'param1=x'
6278
6279 # Define page and extension
6280 rizwank 1.1 #--------------------------
6281 my $PageBool=1;
6282 # Extension
6283 my $extension;
6284 if ($urlwithnoquery =~ /$regext/o || ($urlwithnoquery =~ /[\\\/]$/ && $DefaultFile[0] =~ /$regext/o)) {
6285 $extension=($LevelForFileTypesDetection>=2 || $MimeHashFamily{$1})?lc($1):'Unknown';
6286 if ($NotPageList{$extension}) { $PageBool=0; }
6287 }
6288 else {
6289 $extension='Unknown';
6290 }
6291
6292 # Analyze: misc tracker (must be before return code)
6293 #---------------------------------------------------
6294 if ($urlwithnoquery =~ /$regmisc/o) {
6295 if ($Debug) { debug(" Found an URL that is a MiscTracker record with standalonequery=$standalonequery",2); }
6296 my $foundparam=0;
6297 foreach (split(/&/,$standalonequery)) {
6298 if ($_ =~ /^screen=(\d+)x(\d+)/i) { $foundparam++; $_screensize_h{"$1x$2"}++; next; }
6299 #if ($_ =~ /cdi=(\d+)/i) { $foundparam++; $_screendepth_h{"$1"}++; next; }
6300 if ($_ =~ /^nojs=(\w+)/i) { $foundparam++; if ($1 eq 'y') { $_misc_h{"JavascriptDisabled"}++; } next; }
6301 rizwank 1.1 if ($_ =~ /^java=(\w+)/i) { $foundparam++; if ($1 eq 'true') { $_misc_h{"JavaEnabled"}++; } next; }
6302 if ($_ =~ /^shk=(\w+)/i) { $foundparam++; if ($1 eq 'y') { $_misc_h{"DirectorSupport"}++; } next; }
6303 if ($_ =~ /^fla=(\w+)/i) { $foundparam++; if ($1 eq 'y') { $_misc_h{"FlashSupport"}++; } next; }
6304 if ($_ =~ /^rp=(\w+)/i) { $foundparam++; if ($1 eq 'y') { $_misc_h{"RealPlayerSupport"}++; } next; }
6305 if ($_ =~ /^mov=(\w+)/i) { $foundparam++; if ($1 eq 'y') { $_misc_h{"QuickTimeSupport"}++; } next; }
6306 if ($_ =~ /^wma=(\w+)/i) { $foundparam++; if ($1 eq 'y') { $_misc_h{"WindowsMediaPlayerSupport"}++; } next; }
6307 if ($_ =~ /^pdf=(\w+)/i) { $foundparam++; if ($1 eq 'y') { $_misc_h{"PDFSupport"}++; } next; }
6308 }
6309 if ($foundparam) { $_misc_h{"TotalMisc"}++; }
6310 }
6311
6312 # Analyze: favicon (countedtraffic=>1)
6313 #-------------------------------------
6314 if ($pos_referer >= 0 && $field[$pos_referer] && $urlwithnoquery =~ /$regfavico/o) {
6315 if (($field[$pos_code] != 404 || $urlwithnoquery !~ /\/.+\/favicon\.ico$/i) && ($field[$pos_agent] =~ /MSIE/)) {
6316 # We don't count one hit if (not on root and error) and MSIE
6317 # If error not on root, another hit will be made on root. If not MSIE, hit are made not only for "Adding".
6318 $_misc_h{'AddToFavourites'}++; # Hit on favicon on root or without error, we count it
6319 }
6320 $countedtraffic=1; # favicon is the only case not counted anywhere
6321 }
6322 rizwank 1.1
6323 # Analyze: Worms (countedtraffic=>1 if worm)
6324 #-------------------------------------------
6325 if (! $countedtraffic) {
6326 if ($LevelForWormsDetection) {
6327 foreach (@WormsSearchIDOrder) {
6328 if ($field[$pos_url] =~ /$_/) {
6329 # It's a worm
6330 my $worm=&UnCompileRegex($_);
6331 if ($Debug) { debug(" Record is a hit from a worm identified by '$worm'",2); }
6332 $worm=$WormsHashID{$worm}||'unknown';
6333 $_worm_h{$worm}++;
6334 $_worm_k{$worm}+=int($field[$pos_size]);
6335 $_worm_l{$worm}=$timerecord;
6336 $countedtraffic=1;
6337 if ($PageBool) { $_time_nv_p[$hourrecord]++; }
6338 $_time_nv_h[$hourrecord]++;
6339 $_time_nv_k[$hourrecord]+=int($field[$pos_size]);
6340 last;
6341 }
6342 }
6343 rizwank 1.1 }
6344 }
6345
6346 # Analyze: Status code (countedtraffic=>1 if error)
6347 #--------------------------------------------------
6348 if (! $countedtraffic) {
6349 if ($LogType eq 'W' || $LogType eq 'S') { # HTTP record or Stream record
6350 if ($ValidHTTPCodes{$field[$pos_code]}) { # Code is valid
6351 if ($field[$pos_code] == 304) { $field[$pos_size]=0; }
6352 }
6353 else { # Code is not valid
6354 if ($field[$pos_code] !~ /^\d\d\d$/) { $field[$pos_code]=999; }
6355 $_errors_h{$field[$pos_code]}++;
6356 $_errors_k{$field[$pos_code]}+=int($field[$pos_size]);
6357 foreach my $code (keys %TrapInfosForHTTPErrorCodes) {
6358 if ($field[$pos_code] == $code) {
6359 # This is an error code which referrer need to be tracked
6360 my $newurl=substr($field[$pos_url],0,$MaxLengthOfStoredURL);
6361 $newurl =~ s/[$URLQuerySeparators].*$//;
6362 $_sider404_h{$newurl}++;
6363 my $newreferer=$field[$pos_referer];
6364 rizwank 1.1 if (! $URLReferrerWithQuery) { $newreferer =~ s/[$URLQuerySeparators].*$//; }
6365 $_referer404_h{$newurl}=$newreferer;
6366 last;
6367 }
6368 }
6369 if ($Debug) { debug(" Record stored in the status code chart (status code=$field[$pos_code])",2); }
6370 $countedtraffic=1;
6371 if ($PageBool) { $_time_nv_p[$hourrecord]++; }
6372 $_time_nv_h[$hourrecord]++;
6373 $_time_nv_k[$hourrecord]+=int($field[$pos_size]);
6374 }
6375 }
6376 elsif ($LogType eq 'M') { # Mail record
6377 if (! $ValidSMTPCodes{$field[$pos_code]}) { # Code is not valid
6378 $_errors_h{$field[$pos_code]}++;
6379 $_errors_k{$field[$pos_code]}+=int($field[$pos_size]); # Size is often 0 when error
6380 if ($Debug) { debug(" Record stored in the status code chart (status code=$field[$pos_code])",2); }
6381 $countedtraffic=1;
6382 if ($PageBool) { $_time_nv_p[$hourrecord]++; }
6383 $_time_nv_h[$hourrecord]++;
6384 $_time_nv_k[$hourrecord]+=int($field[$pos_size]);
6385 rizwank 1.1 }
6386 }
6387 elsif ($LogType eq 'F') { # FTP record
6388 }
6389 }
6390
6391 # Analyze: Robot from robot database (countedtraffic=>1 if robot)
6392 #----------------------------------------------------------------
6393 if (! $countedtraffic) {
6394 if ($pos_agent >= 0) {
6395 if ($DecodeUA) { $field[$pos_agent] =~ s/%20/_/g; } # This is to support servers (like Roxen) that writes user agent with %20 in it
6396 $UserAgent=$field[$pos_agent];
6397
6398 if ($LevelForRobotsDetection) {
6399
6400 my $uarobot=$TmpRobot{$UserAgent};
6401 if (! $uarobot) {
6402 #study $UserAgent; Does not increase speed
6403 foreach (@RobotsSearchIDOrder) {
6404 if ($UserAgent =~ /$_/) {
6405 my $bot=&UnCompileRegex($_);
6406 rizwank 1.1 $TmpRobot{$UserAgent}=$uarobot="$bot"; # Last time, we won't search if robot or not. We know it is.
6407 if ($Debug) { debug(" UserAgent '$UserAgent' is added to TmpRobot with value '$bot'",2); }
6408 last;
6409 }
6410 }
6411 if (! $uarobot) { # Last time, we won't search if robot or not. We know it's not.
6412 $TmpRobot{$UserAgent}=$uarobot='-';
6413 }
6414 }
6415 if ($uarobot ne '-') {
6416 # If robot, we stop here
6417 if ($Debug) { debug(" UserAgent '$UserAgent' contains robot ID '$uarobot'",2); }
6418 $_robot_h{$uarobot}++;
6419 $_robot_k{$uarobot}+=int($field[$pos_size]);
6420 $_robot_l{$uarobot}=$timerecord;
6421 if ($urlwithnoquery =~ /$regrobot/o) { $_robot_r{$uarobot}++; }
6422 $countedtraffic=1;
6423 if ($PageBool) { $_time_nv_p[$hourrecord]++; }
6424 $_time_nv_h[$hourrecord]++;
6425 $_time_nv_k[$hourrecord]+=int($field[$pos_size]);
6426 }
6427 rizwank 1.1 }
6428 }
6429 }
6430
6431 # Analyze: Robot from "hit on robots.txt" file (countedtraffic=>1 if robot)
6432 # -------------------------------------------------------------------------
6433 if (! $countedtraffic) {
6434 if ($urlwithnoquery =~ /$regrobot/o) {
6435 if ($Debug) { debug(" It's an unknown robot",2); }
6436 $_robot_h{'unknown'}++;
6437 $_robot_k{'unknown'}+=int($field[$pos_size]);
6438 $_robot_l{'unknown'}=$timerecord;
6439 $_robot_r{'unknown'}++;
6440 $countedtraffic=1;
6441 if ($PageBool) { $_time_nv_p[$hourrecord]++; }
6442 $_time_nv_h[$hourrecord]++;
6443 $_time_nv_k[$hourrecord]+=int($field[$pos_size]);
6444 }
6445 }
6446
6447 # Analyze: File type - Compression
6448 rizwank 1.1 #---------------------------------
6449 if (! $countedtraffic) {
6450 if ($LevelForFileTypesDetection) {
6451 $_filetypes_h{$extension}++;
6452 $_filetypes_k{$extension}+=int($field[$pos_size]); # TODO can cause a warning
6453 # Compression
6454 if ($pos_gzipin>=0 && $field[$pos_gzipin]) { # If in and out in log
6455 my ($notused,$in)=split(/:/,$field[$pos_gzipin]);
6456 my ($notused1,$out,$notused2)=split(/:/,$field[$pos_gzipout]);
6457 if ($out) {
6458 $_filetypes_gz_in{$extension}+=$in;
6459 $_filetypes_gz_out{$extension}+=$out;
6460 }
6461 }
6462 elsif ($pos_compratio>=0 && ($field[$pos_compratio] =~ /(\d+)/)) { # Calculate in/out size from percentage
6463 if ($fieldlib[$pos_compratio] eq 'gzipratio') {
6464 # with mod_gzip: % is size (before-after)/before (low for jpg) ??????????
6465 $_filetypes_gz_in{$extension}+=int($field[$pos_size]*100/((100-$1)||1));
6466 } else {
6467 # with mod_deflate: % is size after/before (high for jpg)
6468 $_filetypes_gz_in{$extension}+=int($field[$pos_size]*100/($1||1));
6469 rizwank 1.1 }
6470 $_filetypes_gz_out{$extension}+=int($field[$pos_size]);
6471 }
6472 }
6473
6474 # Analyze: Date - Hour - Pages - Hits - Kilo
6475 #-------------------------------------------
6476 if ($PageBool) {
6477 # Replace default page name with / only ('if' is to increase speed when only 1 value in @DefaultFile)
6478 if (@DefaultFile > 1) { foreach my $elem (@DefaultFile) { if ($field[$pos_url] =~ s/\/$elem$/\//o) { last; } } }
6479 else { $field[$pos_url] =~ s/$regdefault/\//o; }
6480 # FirstTime and LastTime are First and Last human visits (so changed if access to a page)
6481 $FirstTime{$lastprocessedyearmonth}||=$timerecord;
6482 $LastTime{$lastprocessedyearmonth}=$timerecord;
6483 $DayPages{$yearmonthdayrecord}++;
6484 $_url_p{$field[$pos_url]}++; #Count accesses for page (page)
6485 $_url_k{$field[$pos_url]}+=int($field[$pos_size]);
6486 $_time_p[$hourrecord]++; #Count accesses for hour (page)
6487 # TODO Use an id for hash key of url
6488 # $_url_t{$_url_id}
6489 }
6490 rizwank 1.1 $_time_h[$hourrecord]++;
6491 $_time_k[$hourrecord]+=int($field[$pos_size]);
6492 $DayHits{$yearmonthdayrecord}++; #Count accesses for hour (hit)
6493 $DayBytes{$yearmonthdayrecord}+=int($field[$pos_size]); #Count accesses for hour (kb)
6494
6495 # Analyze: Login
6496 #---------------
6497 if ($pos_logname>=0 && $field[$pos_logname] && $field[$pos_logname] ne '-') {
6498 $field[$pos_logname] =~ s/ /_/g; # This is to allow space in logname
6499 if ($LogFormat eq '6') { $field[$pos_logname] =~ s/^\"//; $field[$pos_logname] =~ s/\"$//;} # logname field has " with Domino 6+
6500 if ($AuthenticatedUsersNotCaseSensitive) { $field[$pos_logname]=lc($field[$pos_logname]); }
6501
6502 # We found an authenticated user
6503 if ($PageBool) { $_login_p{$field[$pos_logname]}++; } #Count accesses for page (page)
6504 $_login_h{$field[$pos_logname]}++; #Count accesses for page (hit)
6505 $_login_k{$field[$pos_logname]}+=int($field[$pos_size]); #Count accesses for page (kb)
6506 $_login_l{$field[$pos_logname]}=$timerecord;
6507 }
6508 }
6509
6510 # Do DNS lookup
6511 rizwank 1.1 #--------------
6512 my $Host=$field[$pos_host];
6513 my $HostResolved='';
6514
6515 if (! $countedtraffic) {
6516 my $ip=0;
6517 if ($DNSLookup) { # DNS lookup is 1 or 2
6518 if ($Host =~ /$regipv4/o) { $ip=4; } # IPv4
6519 elsif ($Host =~ /$regipv6/o) { $ip=6; } # IPv6
6520 if ($ip) {
6521 # Check in static DNS cache file
6522 $HostResolved=$MyDNSTable{$Host};
6523 if ($HostResolved) {
6524 if ($Debug) { debug(" DNS lookup asked for $Host and found in static DNS cache file: $HostResolved",4); }
6525 }
6526 elsif ($DNSLookup==1) {
6527 # Check in session cache (dynamic DNS cache file + session DNS cache)
6528 $HostResolved=$TmpDNSLookup{$Host};
6529 if (! $HostResolved) {
6530 if (@SkipDNSLookupFor && &SkipDNSLookup($Host)) {
6531 $HostResolved=$TmpDNSLookup{$Host}='*';
6532 rizwank 1.1 if ($Debug) { debug(" No need of reverse DNS lookup for $Host, skipped at user request.",4); }
6533 }
6534 else {
6535 if ($ip == 4) {
6536 my $lookupresult=gethostbyaddr(pack("C4",split(/\./,$Host)),AF_INET); # This is very slow, may spend 20 seconds
6537 if (! $lookupresult || $lookupresult =~ /$regipv4/o || ! IsAscii($lookupresult)) {
6538 $TmpDNSLookup{$Host}=$HostResolved='*';
6539 }
6540 else {
6541 $TmpDNSLookup{$Host}=$HostResolved=$lookupresult;
6542 }
6543 if ($Debug) { debug(" Reverse DNS lookup for $Host done: $HostResolved",4); }
6544 }
6545 elsif ($ip == 6) {
6546 if ($PluginsLoaded{'GetResolvedIP'}{'ipv6'}) {
6547 my $lookupresult=GetResolvedIP_ipv6($Host);
6548 if (! $lookupresult || ! IsAscii($lookupresult)) {
6549 $TmpDNSLookup{$Host}=$HostResolved='*';
6550 }
6551 else {
6552 $TmpDNSLookup{$Host}=$HostResolved=$lookupresult;
6553 rizwank 1.1 }
6554 } else {
6555 $TmpDNSLookup{$Host}=$HostResolved='*';
6556 warning("Reverse DNS lookup for $Host not available without ipv6 plugin enabled.");
6557 }
6558 }
6559 else { error("Bad value vor ip"); }
6560 }
6561 }
6562 }
6563 else {
6564 $HostResolved='*';
6565 if ($Debug) { debug(" DNS lookup by static DNS cache file asked for $Host but not found.",4); }
6566 }
6567 }
6568 else {
6569 if ($Debug) { debug(" DNS lookup asked for $Host but this is not an IP address.",4); }
6570 $DNSLookupAlreadyDone=$LogFile;
6571 }
6572 }
6573 else {
6574 rizwank 1.1 if ($Host =~ /$regipv4/o) { $HostResolved='*'; $ip=4; } # IPv4
6575 elsif ($Host =~ /$regipv6/o) { $HostResolved='*'; $ip=6; } # IPv6
6576 if ($Debug) { debug(" No DNS lookup asked.",4); }
6577 }
6578
6579 # Analyze: Country (Top-level domain)
6580 #------------------------------------
6581 if ($Debug) { debug(" Search country (Host=$Host HostResolved=$HostResolved ip=$ip)",4); }
6582 my $Domain='ip';
6583 # Set $HostResolved to host and resolve domain
6584 if ($HostResolved eq '*') {
6585 # $Host is an IP address and is not resolved (failed or not asked) or resolution gives an IP address
6586 $HostResolved = $Host;
6587 # Resolve Domain
6588 if ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoipfree'}) { $Domain=GetCountryCodeByAddr_geoipfree($HostResolved); }
6589 elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip'}) { $Domain=GetCountryCodeByAddr_geoip($HostResolved); }
6590 if ($AtLeastOneSectionPlugin) {
6591 foreach my $pluginname (keys %{$PluginsLoaded{'SectionProcessIp'}}) {
6592 my $function="SectionProcessIp_$pluginname(\$HostResolved)";
6593 eval("$function");
6594 }
6595 rizwank 1.1 }
6596 }
6597 else {
6598 # $Host was already a host name ($ip=0, $Host=name, $HostResolved='') or has been resolved ($ip>0, $Host=ip, $HostResolved defined)
6599 $HostResolved = lc($HostResolved?$HostResolved:$Host);
6600 # Resolve Domain
6601 if ($ip) { # If we have ip, we use it in priority instead of hostname
6602 if ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoipfree'}) { $Domain=GetCountryCodeByAddr_geoipfree($Host); }
6603 elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip'}) { $Domain=GetCountryCodeByAddr_geoip($Host); }
6604 elsif ($HostResolved =~ /\.(\w+)$/) { $Domain=$1; }
6605 if ($AtLeastOneSectionPlugin) {
6606 foreach my $pluginname (keys %{$PluginsLoaded{'SectionProcessIp'}}) {
6607 my $function="SectionProcessIp_$pluginname(\$Host)";
6608 eval("$function");
6609 }
6610 }
6611 }
6612 else {
6613 if ($PluginsLoaded{'GetCountryCodeByName'}{'geoipfree'}) { $Domain=GetCountryCodeByName_geoipfree($HostResolved); }
6614 elsif ($PluginsLoaded{'GetCountryCodeByName'}{'geoip'}) { $Domain=GetCountryCodeByName_geoip($HostResolved); }
6615 elsif ($HostResolved =~ /\.(\w+)$/) { $Domain=$1; }
6616 rizwank 1.1 if ($AtLeastOneSectionPlugin) {
6617 foreach my $pluginname (keys %{$PluginsLoaded{'SectionProcessHostname'}}) {
6618 my $function="SectionProcessHostname_$pluginname(\$HostResolved)";
6619 eval("$function");
6620 }
6621 }
6622 }
6623 }
6624 # Store country
6625 if ($PageBool) { $_domener_p{$Domain}++; }
6626 $_domener_h{$Domain}++;
6627 $_domener_k{$Domain}+=int($field[$pos_size]);
6628
6629 # Analyze: Host, URL entry+exit and Session
6630 #------------------------------------------
6631 if ($PageBool) {
6632 my $timehostl=$_host_l{$HostResolved};
6633 if ($timehostl) {
6634 # A visit for this host was already detected
6635 # TODO everywhere there is $VISITTIMEOUT
6636 # $timehostl =~ /^\d\d\d\d\d\d(\d\d)/; my $daytimehostl=$1;
6637 rizwank 1.1 # if ($timerecord > ($timehostl+$VISITTIMEOUT+($dateparts[3]>$daytimehostl?$NEWDAYVISITTIMEOUT:0))) {
6638 if ($timerecord > ($timehostl+$VISITTIMEOUT)) {
6639 # This is a second visit or more
6640 if (! $_waithost_s{$HostResolved}) {
6641 # This is a second visit or more
6642 # We count 'visit','exit','entry','DayVisits'
6643 if ($Debug) { debug(" This is a second visit for $HostResolved.",4); }
6644 my $timehosts=$_host_s{$HostResolved};
6645 my $page=$_host_u{$HostResolved};
6646 if ($page) { $_url_x{$page}++; }
6647 $_url_e{$field[$pos_url]}++;
6648 $DayVisits{$yearmonthdayrecord}++;
6649 # We can't count session yet because we don't have the start so
6650 # we save params of first 'wait' session
6651 $_waithost_l{$HostResolved}=$timehostl;
6652 $_waithost_s{$HostResolved}=$timehosts;
6653 $_waithost_u{$HostResolved}=$page;
6654 }
6655 else {
6656 # This is third visit or more
6657 # We count 'session','visit','exit','entry','DayVisits'
6658 rizwank 1.1 if ($Debug) { debug(" This is a third visit or more for $HostResolved.",4); }
6659 my $timehosts=$_host_s{$HostResolved};
6660 my $page=$_host_u{$HostResolved};
6661 if ($page) { $_url_x{$page}++; }
6662 $_url_e{$field[$pos_url]}++;
6663 $DayVisits{$yearmonthdayrecord}++;
6664 if ($timehosts) { $_session{GetSessionRange($timehosts,$timehostl)}++; }
6665 }
6666 # Save new session properties
6667 $_host_s{$HostResolved}=$timerecord;
6668 $_host_l{$HostResolved}=$timerecord;
6669 $_host_u{$HostResolved}=$field[$pos_url];
6670 }
6671 elsif ($timerecord > $timehostl) {
6672 # This is a same visit we can count
6673 if ($Debug) { debug(" This is same visit still running for $HostResolved. host_l/host_u changed to $timerecord/$field[$pos_url]",4); }
6674 $_host_l{$HostResolved}=$timerecord;
6675 $_host_u{$HostResolved}=$field[$pos_url];
6676 }
6677 elsif ($timerecord == $timehostl) {
6678 # This is a same visit we can count
6679 rizwank 1.1 if ($Debug) { debug(" This is same visit still running for $HostResolved. host_l/host_u changed to $timerecord/$field[$pos_url]",4); }
6680 $_host_u{$HostResolved}=$field[$pos_url];
6681 }
6682 elsif ($timerecord < $_host_s{$HostResolved}) {
6683 # Should happens only with not correctly sorted log files
6684 if ($Debug) { debug(" This is same visit still running for $HostResolved with start not in order. host_s changed to $timerecord (entry page also changed if first visit)",4); }
6685 if (! $_waithost_s{$HostResolved}) {
6686 # We can reorder entry page only if it's the first visit found in this update run (The saved entry page was $_waithost_e if $_waithost_s{$HostResolved} is not defined. If second visit or more, entry was directly counted and not saved)
6687 $_waithost_e{$HostResolved}=$field[$pos_url];
6688 }
6689 else {
6690 # We can't change entry counted as we dont't know what was the url counted as entry
6691 }
6692 $_host_s{$HostResolved}=$timerecord;
6693 }
6694 else {
6695 if ($Debug) { debug(" This is same visit still running for $HostResolved with hit between start and last hits. No change",4); }
6696 }
6697 }
6698 else {
6699 # This is a new visit (may be). First new visit found for this host. We save in wait array the entry page to count later
6700 rizwank 1.1 if ($Debug) { debug(" New session (may be) for $HostResolved. Save in wait array to see later",4); }
6701 $_waithost_e{$HostResolved}=$field[$pos_url];
6702 # Save new session properties
6703 $_host_u{$HostResolved}=$field[$pos_url];
6704 $_host_s{$HostResolved}=$timerecord;
6705 $_host_l{$HostResolved}=$timerecord;
6706 }
6707 $_host_p{$HostResolved}++;
6708 }
6709 $_host_h{$HostResolved}++;
6710 $_host_k{$HostResolved}+=int($field[$pos_size]);
6711
6712 # Analyze: Browser - OS
6713 #----------------------
6714 if ($pos_agent >= 0 && $UserAgent) {
6715
6716 if ($LevelForBrowsersDetection) {
6717
6718 # Analyze: Browser
6719 #-----------------
6720 my $uabrowser=$TmpBrowser{$UserAgent};
6721 rizwank 1.1 if (! $uabrowser) {
6722 my $found=1;
6723 # IE ?
6724 if ($UserAgent =~ /$regvermsie/o && $UserAgent !~ /$regnotie/o) {
6725 $_browser_h{"msie$2"}++;
6726 $TmpBrowser{$UserAgent}="msie$2";
6727 }
6728 # Firefox ?
6729 elsif ($UserAgent =~ /$regverfirefox/o) {
6730 $_browser_h{"firefox$1"}++;
6731 $TmpBrowser{$UserAgent}="firefox$1";
6732 }
6733 # Netscape 6.x, 7.x ... ?
6734 elsif ($UserAgent =~ /$regvernetscape/o) {
6735 $_browser_h{"netscape$1"}++;
6736 $TmpBrowser{$UserAgent}="netscape$1";
6737 }
6738 # Netscape 3.x, 4.x ... ?
6739 elsif ($UserAgent =~ /$regvermozilla/o && $UserAgent !~ /$regnotnetscape/o) {
6740 $_browser_h{"netscape$2"}++;
6741 $TmpBrowser{$UserAgent}="netscape$2";
6742 rizwank 1.1 }
6743 # Other known browsers ?
6744 else {
6745 $found=0;
6746 foreach (@BrowsersSearchIDOrder) { # Search ID in order of BrowsersSearchIDOrder
6747 if ($UserAgent =~ /$_/) {
6748 my $browser=&UnCompileRegex($_);
6749 # TODO If browser is in a family, use version
6750 $_browser_h{"$browser"}++;
6751 $TmpBrowser{$UserAgent}="$browser";
6752 $found=1;
6753 last;
6754 }
6755 }
6756 }
6757 # Unknown browser ?
6758 if (!$found) {
6759 $_browser_h{'Unknown'}++;
6760 $TmpBrowser{$UserAgent}='Unknown';
6761 my $newua=$UserAgent; $newua =~ tr/\+ /__/;
6762 $_unknownrefererbrowser_l{$newua}=$timerecord;
6763 rizwank 1.1 }
6764 }
6765 else {
6766 $_browser_h{$uabrowser}++;
6767 if ($uabrowser eq 'Unknown') {
6768 my $newua=$UserAgent; $newua =~ tr/\+ /__/;
6769 $_unknownrefererbrowser_l{$newua}=$timerecord;
6770 }
6771 }
6772
6773 }
6774
6775 if ($LevelForOSDetection) {
6776
6777 # Analyze: OS
6778 #------------
6779 my $uaos=$TmpOS{$UserAgent};
6780 if (! $uaos) {
6781 my $found=0;
6782 # in OSHashID list ?
6783 foreach (@OSSearchIDOrder) { # Search ID in order of OSSearchIDOrder
6784 rizwank 1.1 if ($UserAgent =~ /$_/) {
6785 my $osid=$OSHashID{&UnCompileRegex($_)};
6786 $_os_h{"$osid"}++;
6787 $TmpOS{$UserAgent}="$osid";
6788 $found=1;
6789 last;
6790 }
6791 }
6792 # Unknown OS ?
6793 if (!$found) {
6794 $_os_h{'Unknown'}++;
6795 $TmpOS{$UserAgent}='Unknown';
6796 my $newua=$UserAgent; $newua =~ tr/\+ /__/;
6797 $_unknownreferer_l{$newua}=$timerecord;
6798 }
6799 }
6800 else {
6801 $_os_h{$uaos}++;
6802 if ($uaos eq 'Unknown') {
6803 my $newua=$UserAgent; $newua =~ tr/\+ /__/;
6804 $_unknownreferer_l{$newua}=$timerecord;
6805 rizwank 1.1 }
6806 }
6807
6808 }
6809
6810 }
6811 else {
6812 $_browser_h{'Unknown'}++;
6813 $_os_h{'Unknown'}++;
6814 }
6815
6816 # Analyze: Referer
6817 #-----------------
6818 my $found=0;
6819 if ($pos_referer >= 0 && $LevelForRefererAnalyze && $field[$pos_referer]) {
6820
6821 # Direct ?
6822 if ($field[$pos_referer] eq '-' || $field[$pos_referer] eq 'bookmarks') { # "bookmarks" is sent by Netscape, '-' by all others browsers
6823 # Direct access
6824 if ($PageBool) { $_from_p[0]++; }
6825 $_from_h[0]++;
6826 rizwank 1.1 $found=1;
6827 }
6828 else {
6829 $field[$pos_referer] =~ /$regreferer/o;
6830 my $refererprot=$1;
6831 my $refererserver=($2||'').(! $3 || $3 eq ':80'?'':$3); # refererserver is www.xxx.com or www.xxx.com:81 but not www.xxx.com:80
6832 # HTML link ?
6833 if ($refererprot =~ /^http/i) {
6834 #if ($Debug) { debug(" Analyze referer refererprot=$refererprot refererserver=$refererserver",5); }
6835
6836 # Kind of origin
6837 if (!$TmpRefererServer{$refererserver}) { # is "=" if same site, "search egine key" if search engine, not defined otherwise
6838 if ($refererserver =~ /$reglocal/o) {
6839 # Intern (This hit came from another page of the site)
6840 if ($Debug) { debug(" Server '$refererserver' is added to TmpRefererServer with value '='",2); }
6841 $TmpRefererServer{$refererserver}='=';
6842 $found=1;
6843 }
6844 else {
6845 foreach (@HostAliases) {
6846 if ($refererserver =~ /$_/) {
6847 rizwank 1.1 # Intern (This hit came from another page of the site)
6848 if ($Debug) { debug(" Server '$refererserver' is added to TmpRefererServer with value '='",2); }
6849 $TmpRefererServer{$refererserver}='=';
6850 $found=1;
6851 last;
6852 }
6853 }
6854 if (! $found) {
6855 # Extern (This hit came from an external web site).
6856
6857 if ($LevelForSearchEnginesDetection) {
6858
6859 foreach (@SearchEnginesSearchIDOrder) { # Search ID in order of SearchEnginesSearchIDOrder
6860 if ($refererserver =~ /$_/) {
6861 my $key=&UnCompileRegex($_);
6862 if (! $NotSearchEnginesKeys{$key} || $refererserver !~ /$NotSearchEnginesKeys{$key}/i) {
6863 # This hit came from the search engine $key
6864 if ($Debug) { debug(" Server '$refererserver' is added to TmpRefererServer with value '$key'",2); }
6865 $TmpRefererServer{$refererserver}=$SearchEnginesHashID{$key};
6866 $found=1;
6867 }
6868 rizwank 1.1 last;
6869 }
6870 }
6871
6872 }
6873 }
6874 }
6875 }
6876
6877 my $tmprefererserver=$TmpRefererServer{$refererserver};
6878 if ($tmprefererserver) {
6879 if ($tmprefererserver eq '=') {
6880 # Intern (This hit came from another page of the site)
6881 if ($PageBool) { $_from_p[4]++; }
6882 $_from_h[4]++;
6883 $found=1;
6884 }
6885 else {
6886 # This hit came from a search engine
6887 if ($PageBool) { $_from_p[2]++; $_se_referrals_p{$tmprefererserver}++; }
6888 $_from_h[2]++;
6889 rizwank 1.1 $_se_referrals_h{$tmprefererserver}++;
6890 $found=1;
6891 if ($PageBool && $LevelForKeywordsDetection) {
6892 # we will complete %_keyphrases hash array
6893 my @refurl=split(/\?/,$field[$pos_referer],2); # TODO Use \? or [$URLQuerySeparators] ?
6894 if ($refurl[1]) {
6895 # Extract params of referer query string (q=cache:mmm:www/zzz+aaa+bbb q=aaa+bbb/ccc key=ddd%20eee lang_en ie=UTF-8 ...)
6896 if ($SearchEnginesKnownUrl{$tmprefererserver}) { # Search engine with known URL syntax
6897 foreach my $param (split(/&/,$KeyWordsNotSensitive?lc($refurl[1]):$refurl[1])) {
6898 if ($param =~ s/^$SearchEnginesKnownUrl{$tmprefererserver}//) {
6899 # We found good parameter
6900 # Now param is keyphrase: "cache:mmm:www/zzz+aaa+bbb/ccc+ddd%20eee'fff,ggg"
6901 $param =~ s/^(cache|related):[^\+]+//; # Should be useless since this is for hit on 'not pages'
6902 &ChangeWordSeparatorsIntoSpace($param); # Change [ aaa+bbb/ccc+ddd%20eee'fff,ggg ] into [ aaa bbb/ccc ddd eee fff ggg]
6903 $param =~ s/^ +//; $param =~ s/ +$//; $param =~ tr/ /\+/s;
6904 if ((length $param) > 0) { $_keyphrases{$param}++; }
6905 last;
6906 }
6907 }
6908 }
6909 elsif ($LevelForKeywordsDetection >= 2) { # Search engine with unknown URL syntax
6910 rizwank 1.1 foreach my $param (split(/&/,$KeyWordsNotSensitive?lc($refurl[1]):$refurl[1])) {
6911 my $foundexcludeparam=0;
6912 foreach my $paramtoexclude (@WordsToCleanSearchUrl) {
6913 if ($param =~ /$paramtoexclude/i) { $foundexcludeparam=1; last; } # Not the param with search criteria
6914 }
6915 if ($foundexcludeparam) { next; }
6916 # We found good parameter
6917 $param =~ s/.*=//;
6918 # Now param is keyphrase: "aaa+bbb/ccc+ddd%20eee'fff,ggg"
6919 $param =~ s/^(cache|related):[^\+]+//; # Should be useless since this is for hit on 'not pages'
6920 &ChangeWordSeparatorsIntoSpace($param); # Change [ aaa+bbb/ccc+ddd%20eee'fff,ggg ] into [ aaa bbb/ccc ddd eee fff ggg ]
6921 $param =~ s/^ +//; $param =~ s/ +$//; $param =~ tr/ /\+/s;
6922 if ((length $param) > 2) { $_keyphrases{$param}++; last; }
6923 }
6924 }
6925 } # End of elsif refurl[1]
6926 elsif ($SearchEnginesWithKeysNotInQuery{$tmprefererserver}) {
6927 # If search engine with key inside page url like a9 (www.a9.com/searchkey1%20searchkey2)
6928 if ($refurl[0] =~ /$SearchEnginesKnownUrl{$tmprefererserver}(.*)$/) {
6929 my $param=$1;
6930 &ChangeWordSeparatorsIntoSpace($param);
6931 rizwank 1.1 if ((length $param) > 0) { $_keyphrases{$param}++; }
6932 }
6933 }
6934
6935 }
6936 }
6937 } # End of if ($TmpRefererServer)
6938 else {
6939 # This hit came from a site other than a search engine
6940 if ($PageBool) { $_from_p[3]++; }
6941 $_from_h[3]++;
6942 # http://www.mysite.com/ must be same referer than http://www.mysite.com but .../mypage/ differs of .../mypage
6943 #if ($refurl[0] =~ /^[^\/]+\/$/) { $field[$pos_referer] =~ s/\/$//; } # Code moved in Save_History
6944 # TODO: lowercase the value for referer server to have refering server not case sensitive
6945 if ($URLReferrerWithQuery) {
6946 if ($PageBool) { $_pagesrefs_p{$field[$pos_referer]}++; }
6947 $_pagesrefs_h{$field[$pos_referer]}++;
6948 }
6949 else {
6950 # We discard query for referer
6951 if ($field[$pos_referer]=~/$regreferernoquery/o) {
6952 rizwank 1.1 if ($PageBool) { $_pagesrefs_p{"$1"}++; }
6953 $_pagesrefs_h{"$1"}++;
6954 }
6955 else {
6956 if ($PageBool) { $_pagesrefs_p{$field[$pos_referer]}++; }
6957 $_pagesrefs_h{$field[$pos_referer]}++;
6958 }
6959 }
6960 $found=1;
6961 }
6962 }
6963
6964 # News Link ?
6965 if (! $found && $refererprot =~ /^news/i) {
6966 $found=1;
6967 if ($PageBool) { $_from_p[5]++; }
6968 $_from_h[5]++;
6969 }
6970 }
6971 }
6972
6973 rizwank 1.1 # Origin not found
6974 if (!$found) {
6975 if ($ShowUnknownOrigin) { print "Unknown origin: $field[$pos_referer]\n"; }
6976 if ($PageBool) { $_from_p[1]++; }
6977 $_from_h[1]++;
6978 }
6979
6980 # Analyze: EMail
6981 #---------------
6982 if ($pos_emails>=0 && $field[$pos_emails]) {
6983 if ($field[$pos_emails] eq '<>') { $field[$pos_emails]='Unknown'; }
6984 elsif ($field[$pos_emails] !~ /\@/) { $field[$pos_emails].="\@$SiteDomain"; }
6985 $_emails_h{lc($field[$pos_emails])}++; #Count accesses for sender email (hit)
6986 $_emails_k{lc($field[$pos_emails])}+=int($field[$pos_size]); #Count accesses for sender email (kb)
6987 $_emails_l{lc($field[$pos_emails])}=$timerecord;
6988 }
6989 if ($pos_emailr>=0 && $field[$pos_emailr]) {
6990 if ($field[$pos_emailr] !~ /\@/) { $field[$pos_emailr].="\@$SiteDomain"; }
6991 $_emailr_h{lc($field[$pos_emailr])}++; #Count accesses for receiver email (hit)
6992 $_emailr_k{lc($field[$pos_emailr])}+=int($field[$pos_size]); #Count accesses for receiver email (kb)
6993 $_emailr_l{lc($field[$pos_emailr])}=$timerecord;
6994 rizwank 1.1 }
6995 }
6996
6997 # Check cluster
6998 #--------------
6999 if ($pos_cluster>=0) {
7000 if ($PageBool) { $_cluster_p{$field[$pos_cluster]}++; } #Count accesses for page (page)
7001 $_cluster_h{$field[$pos_cluster]}++; #Count accesses for page (hit)
7002 $_cluster_k{$field[$pos_cluster]}+=int($field[$pos_size]); #Count accesses for page (kb)
7003 }
7004
7005 # Analyze: Extra
7006 #---------------
7007 foreach my $extranum (1..@ExtraName-1) {
7008 if ($Debug) { debug(" Process extra analyze $extranum",4); }
7009
7010 # Check code
7011 my $conditionok=0;
7012 foreach my $condnum (0..@{$ExtraCodeFilter[$extranum]}-1) {
7013 if ($Debug) { debug(" Check code '$field[$pos_code]' must be '$ExtraCodeFilter[$extranum][$condnum]'",5); }
7014 if ($field[$pos_code] eq "$ExtraCodeFilter[$extranum][$condnum]") { $conditionok=1; last; }
7015 rizwank 1.1 }
7016 if (! $conditionok && @{$ExtraCodeFilter[$extranum]}) { next; } # End for this section
7017 if ($Debug) { debug(" No check on code or code is OK. Now we check other conditions.",5); }
7018
7019 # Check conditions
7020 $conditionok=0;
7021 foreach my $condnum (0..@{$ExtraConditionType[$extranum]}-1) {
7022 my $conditiontype=$ExtraConditionType[$extranum][$condnum];
7023 my $conditiontypeval=$ExtraConditionTypeVal[$extranum][$condnum];
7024 if ($conditiontype eq 'URL') {
7025 if ($Debug) { debug(" Check condition '$conditiontype' must contain '$conditiontypeval' in '$urlwithnoquery'",5); }
7026 if ($urlwithnoquery =~ /$conditiontypeval/) { $conditionok=1; last; }
7027 }
7028 elsif ($conditiontype eq 'QUERY_STRING') {
7029 if ($Debug) { debug(" Check condition '$conditiontype' must contain '$conditiontypeval' in '$standalonequery'",5); }
7030 if ($standalonequery =~ /$conditiontypeval/) { $conditionok=1; last; }
7031 }
7032 elsif ($conditiontype eq 'REFERER') {
7033 if ($Debug) { debug(" Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_referer]'",5); }
7034 if ($field[$pos_referer] =~ /$conditiontypeval/) { $conditionok=1; last; }
7035 }
7036 rizwank 1.1 elsif ($conditiontype eq 'UA') {
7037 if ($Debug) { debug(" Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_agent]'",5); }
7038 if ($field[$pos_agent] =~ /$conditiontypeval/) { $conditionok=1; last; }
7039 }
7040 elsif ($conditiontype eq 'HOST') {
7041 if ($Debug) { debug(" Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_host]'",5); }
7042 if ($HostResolved =~ /$conditiontypeval/) { $conditionok=1; last; }
7043 }
7044 elsif ($conditiontype =~ /extra(\d+)/i) {
7045 if ($Debug) { debug(" Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_extra[$1]]'",5); }
7046 if ($field[$pos_extra[$1]] =~ /$conditiontypeval/) { $conditionok=1; last; }
7047 }
7048 else { error("Wrong value of parameter ExtraSectionCondition$extranum"); }
7049 }
7050 if (! $conditionok && @{$ExtraConditionType[$extranum]}) { next; } # End for this section
7051 if ($Debug) { debug(" No condition or condition is OK. Now we extract value for first column of extra chart.",5); }
7052
7053 # Determine actual column value to use.
7054 my $rowkeyval;
7055 my $rowkeyok=0;
7056 foreach my $rowkeynum (0..@{$ExtraFirstColumnValuesType[$extranum]}-1) {
7057 rizwank 1.1 my $rowkeytype=$ExtraFirstColumnValuesType[$extranum][$rowkeynum];
7058 my $rowkeytypeval=$ExtraFirstColumnValuesTypeVal[$extranum][$rowkeynum];
7059 if ($rowkeytype eq 'URL') {
7060 if ($urlwithnoquery =~ /$rowkeytypeval/) { $rowkeyval = "$1"; $rowkeyok = 1; last; }
7061 }
7062 elsif ($rowkeytype eq 'QUERY_STRING') {
7063 if ($Debug) { debug(" Extract value from '$standalonequery' with regex '$rowkeytypeval'.",5); }
7064 if ($standalonequery =~ /$rowkeytypeval/) { $rowkeyval = "$1"; $rowkeyok = 1; last; }
7065 }
7066 elsif ($rowkeytype eq 'REFERER') {
7067 if ($field[$pos_referer] =~ /$rowkeytypeval/) { $rowkeyval = "$1"; $rowkeyok = 1; last; }
7068 }
7069 elsif ($rowkeytype eq 'UA') {
7070 if ($field[$pos_agent] =~ /$rowkeytypeval/) { $rowkeyval = "$1"; $rowkeyok = 1; last; }
7071 }
7072 elsif ($rowkeytype eq 'HOST') {
7073 if ($HostResolved =~ /$rowkeytypeval/) { $rowkeyval = "$1"; $rowkeyok = 1; last; }
7074 }
7075 elsif ($rowkeytype =~ /extra(\d+)/i) {
7076 if ($field[$pos_extra[$1]] =~ /$rowkeytypeval/) { $rowkeyval = "$1"; $rowkeyok = 1; last; }
7077 }
7078 rizwank 1.1 else { error("Wrong value of parameter ExtraSectionFirstColumnValues$extranum"); }
7079 }
7080 if (! $rowkeyok) { next; } # End for this section
7081 if ($Debug) { debug(" Key val was found: $rowkeyval",5); }
7082
7083 # Here we got all values to increase counters
7084 if ($PageBool && $ExtraStatTypes[$extranum] =~ /P/i) { ${'_section_' . $extranum . '_p'}{$rowkeyval}++; }
7085 ${'_section_' . $extranum . '_h'}{$rowkeyval}++; # Must be set
7086 if ($ExtraStatTypes[$extranum] =~ /B/i) { ${'_section_' . $extranum . '_k'}{$rowkeyval}+=int($field[$pos_size]); }
7087 if ($ExtraStatTypes[$extranum] =~ /L/i) {
7088 if (${'_section_' . $extranum . '_l'}{$rowkeyval}||0 < $timerecord) { ${'_section_' . $extranum . '_l'}{$rowkeyval}=$timerecord; }
7089 }
7090 # Check to avoid too large extra sections
7091 if (scalar keys %{'_section_' . $extranum . '_h'} > $ExtraTrackedRowsLimit) {
7092 error(<<END_ERROR_TEXT);
7093 The number of values found for extra section $extranum has grown too large.
7094 In order to prevent awstats from using an excessive amount of memory, the number
7095 of values is currently limited to $ExtraTrackedRowsLimit. Perhaps you should consider
7096 revising extract parameters for extra section $extranum. If you are certain you
7097 want to track such a large data set, you can increase the limit by setting
7098 ExtraTrackedRowsLimit in your awstats configuration file.
7099 rizwank 1.1 END_ERROR_TEXT
7100 }
7101 }
7102
7103 # Every 20,000 approved lines after a flush, we test to clean too large hash arrays to flush data in tmp file
7104 if (++$counterforflushtest >= 20000) {
7105 #if (++$counterforflushtest >= 1) {
7106 if ((scalar keys %_host_u) > ($LIMITFLUSH<<2) || (scalar keys %_url_p) > $LIMITFLUSH) {
7107 # warning("Warning: Try to run AWStats update process more frequently to analyze smaler log files.");
7108 if ($^X =~ /activestate/i || $^X =~ /activeperl/i) {
7109 # We don't flush if perl is activestate to avoid slowing process because of memory hole
7110 }
7111 else {
7112 # Clean tmp hash arrays
7113 #%TmpDNSLookup = ();
7114 %TmpOS = %TmpRefererServer = %TmpRobot = %TmpBrowser = ();
7115 # We flush if perl is not activestate
7116 print "Flush history file on disk";
7117 if ((scalar keys %_host_u) > ($LIMITFLUSH<<2)) { print " (unique hosts reach flush limit of ".($LIMITFLUSH<<2).")"; }
7118 if ((scalar keys %_url_p) > $LIMITFLUSH) { print " (unique url reach flush limit of ".($LIMITFLUSH).")"; }
7119 print "\n";
7120 rizwank 1.1 if ($Debug) {
7121 debug("End of set of $counterforflushtest records: Some hash arrays are too large. We flush and clean some.",2);
7122 print " _host_p:".(scalar keys %_host_p)." _host_h:".(scalar keys %_host_h)." _host_k:".(scalar keys %_host_k)." _host_l:".(scalar keys %_host_l)." _host_s:".(scalar keys %_host_s)." _host_u:".(scalar keys %_host_u)."\n";
7123 print " _url_p:".(scalar keys %_url_p)." _url_k:".(scalar keys %_url_k)." _url_e:".(scalar keys %_url_e)." _url_x:".(scalar keys %_url_x)."\n";
7124 print " _waithost_e:".(scalar keys %_waithost_e)." _waithost_l:".(scalar keys %_waithost_l)." _waithost_s:".(scalar keys %_waithost_s)." _waithost_u:".(scalar keys %_waithost_u)."\n";
7125 }
7126 &Read_History_With_TmpUpdate($lastprocessedyear,$lastprocessedmonth,1,1,"all",($lastlinenb+$NbOfLinesParsed),$lastlineoffset,&CheckSum($_));
7127 &GetDelaySinceStart(1); $NbOfLinesShowsteps=1;
7128 }
7129 }
7130 $counterforflushtest=0;
7131 }
7132
7133 } # End of loop for processing new record.
7134
7135 if ($Debug) {
7136 debug(" _host_p:".(scalar keys %_host_p)." _host_h:".(scalar keys %_host_h)." _host_k:".(scalar keys %_host_k)." _host_l:".(scalar keys %_host_l)." _host_s:".(scalar keys %_host_s)." _host_u:".(scalar keys %_host_u)."\n",1);
7137 debug(" _url_p:".(scalar keys %_url_p)." _url_k:".(scalar keys %_url_k)." _url_e:".(scalar keys %_url_e)." _url_x:".(scalar keys %_url_x)."\n",1);
7138 debug(" _waithost_e:".(scalar keys %_waithost_e)." _waithost_l:".(scalar keys %_waithost_l)." _waithost_s:".(scalar keys %_waithost_s)." _waithost_u:".(scalar keys %_waithost_u)."\n",1);
7139 debug("End of processing log file (AWStats memory cache is TmpDNSLookup=".(scalar keys %TmpDNSLookup)." TmpBrowser=".(scalar keys %TmpBrowser)." TmpOS=".(scalar keys %TmpOS)." TmpRefererServer=".(scalar keys %TmpRefererServer)." TmpRobot=".(scalar keys %TmpRobot).")",1);
7140 }
7141 rizwank 1.1
7142 # Save current processed month $lastprocessedmonth
7143 # If lastprocessedmonth > 0 means there is at least one approved new record in log or at least one existing history file
7144 if ($lastprocessedmonth) { # TODO: Do not save if we are sure a flush was just already done
7145 # Get last line
7146 seek(LOG,$lastlineoffset,0);
7147 my $line=<LOG>;
7148 chomp $line; $line =~ s/\r$//;
7149 if (! $NbOfLinesParsed) {
7150 # TODO If there was no lines parsed (log was empty), we only update LastUpdate line with YYYYMMDDHHMMSS 0 0 0 0 0
7151 &Read_History_With_TmpUpdate($lastprocessedyear,$lastprocessedmonth,1,1,"all",($lastlinenb+$NbOfLinesParsed),$lastlineoffset,&CheckSum($line));
7152 }
7153 else {
7154 &Read_History_With_TmpUpdate($lastprocessedyear,$lastprocessedmonth,1,1,"all",($lastlinenb+$NbOfLinesParsed),$lastlineoffset,&CheckSum($line));
7155 }
7156 }
7157
7158 if ($Debug) { debug("Close log file \"$LogFile\""); }
7159 close LOG || error("Command for pipe '$LogFile' failed");
7160
7161 # Process the Rename - Archive - Purge phase
7162 rizwank 1.1 my $renameok=1; my $archiveok=1;
7163
7164 # Open Log file for writing if PurgeLogFile is on
7165 if ($PurgeLogFile == 1) {
7166 if ($ArchiveLogRecords == 1) {
7167 $ArchiveFileName="$DirData/${PROG}_archive$FileSuffix.log";
7168 open(LOG,"+<$LogFile") || error("Enable to archive log records of \"$LogFile\" into \"$ArchiveFileName\" because source can't be opened for read and write: $!<br />\n");
7169 }
7170 else {
7171 open(LOG,"+<$LogFile");
7172 }
7173 binmode LOG;
7174 }
7175
7176 # Rename all HISTORYTMP files into HISTORYTXT
7177 &Rename_All_Tmp_History;
7178
7179 # Purge Log file if option is on and all renaming are ok
7180 if ($PurgeLogFile == 1) {
7181 # Archive LOG file into ARCHIVELOG
7182 if ($ArchiveLogRecords == 1) {
7183 rizwank 1.1 if ($Debug) { debug("Start of archiving log file"); }
7184 open(ARCHIVELOG,">>$ArchiveFileName") || error("Couldn't open file \"$ArchiveFileName\" to archive log: $!");
7185 binmode ARCHIVELOG;
7186 while (<LOG>) {
7187 if (! print ARCHIVELOG $_) { $archiveok=0; last; }
7188 }
7189 close(ARCHIVELOG) || error("Archiving failed during closing archive: $!");
7190 if ($SaveDatabaseFilesWithPermissionsForEveryone) { chmod 0666,"$ArchiveFileName"; }
7191 if ($Debug) { debug("End of archiving log file"); }
7192 }
7193 # If rename and archive ok
7194 if ($renameok && $archiveok) {
7195 if ($Debug) { debug("Purge log file"); }
7196 my $bold=($ENV{'GATEWAY_INTERFACE'}?'<b>':'');
7197 my $unbold=($ENV{'GATEWAY_INTERFACE'}?'</b>':'');
7198 my $br=($ENV{'GATEWAY_INTERFACE'}?'<br />':'');
7199 truncate(LOG,0) || warning("Warning: $bold$PROG$unbold couldn't purge logfile \"$bold$LogFile$unbold\".$br\nChange your logfile permissions to allow write for your web server CGI process or change PurgeLogFile=1 into PurgeLogFile=0 in configure file and think to purge sometimes manually your logfile (just after running an update process to not loose any not already processed records your log file contains).");
7200 }
7201 close(LOG);
7202 }
7203
7204 rizwank 1.1 if ($DNSLookup==1 && $DNSLookupAlreadyDone) {
7205 # DNSLookup warning
7206 my $bold=($ENV{'GATEWAY_INTERFACE'}?'<b>':'');
7207 my $unbold=($ENV{'GATEWAY_INTERFACE'}?'</b>':'');
7208 my $br=($ENV{'GATEWAY_INTERFACE'}?'<br />':'');
7209 warning("Warning: $bold$PROG$unbold has detected that some hosts names were already resolved in your logfile $bold$DNSLookupAlreadyDone$unbold.$br\nIf DNS lookup was already made by the logger (web server), you should change your setup DNSLookup=$DNSLookup into DNSLookup=0 to increase $PROG speed.");
7210 }
7211 if ($DNSLookup==1 && $NbOfNewLines) {
7212 # Save new DNS last update cache file
7213 Save_DNS_Cache_File(\%TmpDNSLookup,"$DirData/$DNSLastUpdateCacheFile","$FileSuffix"); # Save into file using FileSuffix
7214 }
7215
7216 if ($EnableLockForUpdate) {
7217 # Remove lock
7218 &Lock_Update(0);
7219 # Restore signals handler
7220 $SIG{INT} = 'DEFAULT'; # 2
7221 #$SIG{KILL} = 'DEFAULT'; # 9
7222 #$SIG{TERM} = 'DEFAULT'; # 15
7223 }
7224
7225 rizwank 1.1 }
7226 # End of log processing if ($UPdateStats)
7227
7228
7229 #---------------------------------------------------------------------
7230 # SHOW REPORT
7231 #---------------------------------------------------------------------
7232
7233 if (scalar keys %HTMLOutput) {
7234
7235 my $max_p; my $max_h; my $max_k; my $max_v;
7236 my $total_u; my $total_v; my $total_p; my $total_h; my $total_k; my $total_e; my $total_x; my $total_s; my $total_l; my $total_r;
7237 my $average_u; my $average_v; my $average_p; my $average_h; my $average_k; my $average_s;
7238 my $rest_p; my $rest_h; my $rest_k; my $rest_e; my $rest_x; my $rest_s; my $rest_l; my $rest_r;
7239 my $average_nb;
7240
7241 # Define the NewLinkParams for main chart
7242 my $NewLinkParams=${QueryString};
7243 $NewLinkParams =~ s/(^|&)update(=\w*|$)//i;
7244 $NewLinkParams =~ s/(^|&)output(=\w*|$)//i;
7245 $NewLinkParams =~ s/(^|&)staticlinks(=\w*|$)//i;
7246 rizwank 1.1 $NewLinkParams =~ s/(^|&)framename=[^&]*//i;
7247 my $NewLinkTarget='';
7248 if ($DetailedReportsOnNewWindows) { $NewLinkTarget=" target=\"awstatsbis\""; }
7249 if (($FrameName eq 'mainleft' || $FrameName eq 'mainright') && $DetailedReportsOnNewWindows < 2) {
7250 $NewLinkParams.="&framename=mainright";
7251 $NewLinkTarget=" target=\"mainright\"";
7252 }
7253 $NewLinkParams =~ tr/&/&/s; $NewLinkParams =~ s/^&//; $NewLinkParams =~ s/&$//;
7254 if ($NewLinkParams) { $NewLinkParams="${NewLinkParams}&"; }
7255
7256 if ($FrameName ne 'mainleft') {
7257
7258 # READING DATA
7259 #-------------
7260 &Init_HashArray();
7261
7262 # Loop on each month of year
7263 for (my $ix=12; $ix>=1; $ix--) {
7264 my $monthix=sprintf("%02s",$ix);
7265 if ($MonthRequired eq 'all' || $monthix eq $MonthRequired) {
7266 &Read_History_With_TmpUpdate($YearRequired,$monthix,0,0,"all"); # Read full history file
7267 rizwank 1.1 }
7268 elsif (($HTMLOutput{'main'} && $ShowMonthStats) || $HTMLOutput{'alldays'}) {
7269 &Read_History_With_TmpUpdate($YearRequired,$monthix,0,0,"general time"); # Read general and time sections.
7270 }
7271 }
7272 }
7273
7274 # HTMLHeadSection
7275 if ($FrameName ne 'index' && $FrameName ne 'mainleft') {
7276 print "<a name=\"top\"> </a>\n\n";
7277 print "$HTMLHeadSection\n";
7278 print "\n";
7279 }
7280
7281 # Call to plugins' function AddHTMLBodyHeader
7282 foreach my $pluginname (keys %{$PluginsLoaded{'AddHTMLBodyHeader'}}) {
7283 my $function="AddHTMLBodyHeader_$pluginname()";
7284 eval("$function");
7285 }
7286
7287 my $WIDTHMENU1=($FrameName eq 'mainleft'?$FRAMEWIDTH:150);
7288 rizwank 1.1
7289 # TOP BAN
7290 #---------------------------------------------------------------------
7291 if ($ShowMenu || $FrameName eq 'mainleft') {
7292 my $frame=($FrameName eq 'mainleft');
7293
7294 if ($Debug) { debug("ShowTopBan",2); }
7295 print "$Center<a name=\"menu\"> </a>\n";
7296
7297 if ($FrameName ne 'mainleft') {
7298 my $NewLinkParams=${QueryString};
7299 $NewLinkParams =~ s/(^|&)update(=\w*|$)//i;
7300 $NewLinkParams =~ s/(^|&)staticlinks(=\w*|$)//i;
7301 $NewLinkParams =~ s/(^|&)year=[^&]*//i;
7302 $NewLinkParams =~ s/(^|&)month=[^&]*//i;
7303 $NewLinkParams =~ s/(^|&)framename=[^&]*//i;
7304 $NewLinkParams =~ tr/&/&/s; $NewLinkParams =~ s/^&//; $NewLinkParams =~ s/&$//;
7305 my $NewLinkTarget='';
7306 if ($FrameName eq 'mainright') { $NewLinkTarget=" target=\"_parent\""; }
7307 print "<form name=\"FormDateFilter\" action=\"".XMLEncode("$AWScript?${NewLinkParams}")."\" style=\"padding: 0px 0px 0px 0px; margin-top: 0\"$NewLinkTarget>\n";
7308 }
7309 rizwank 1.1
7310 if ($QueryString !~ /buildpdf/i) {
7311 print "<table class=\"aws_border\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
7312 print "<tr><td>\n";
7313 print "<table class=\"aws_data\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"100%\">\n";
7314 }
7315 else {
7316 print "<table width=\"100%\">\n";
7317 }
7318
7319 if ($FrameName ne 'mainright') {
7320 # Print Statistics Of
7321 if ($FrameName eq 'mainleft') {
7322 my $shortSiteDomain=$SiteDomain;
7323 if (length($SiteDomain) > 30) { $shortSiteDomain=substr($SiteDomain,0,20)."...".substr($SiteDomain,length($SiteDomain)-5,5); }
7324 print "<tr><td class=\"awsm\"><b>$Message[7]:</b></td></tr><tr><td class=\"aws\"><span style=\"font-size: 12px;\">$shortSiteDomain</span></td>";
7325 }
7326 else { print "<tr><td class=\"aws\" valign=\"middle\"><b>$Message[7]:</b> </td><td class=\"aws\" valign=\"middle\"><span style=\"font-size: 14px;\">$SiteDomain</span></td>"; }
7327
7328 # Logo and flags
7329 if ($FrameName ne 'mainleft') {
7330 rizwank 1.1 if ($LogoLink =~ "http://awstats.sourceforge.net") {
7331 print "<td align=\"right\" rowspan=\"3\"><a href=\"".XMLEncode($LogoLink)."\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\"".AltTitle(ucfirst($PROG)." Web Site")." /></a>";
7332 }
7333 else {
7334 print "<td align=\"right\" rowspan=\"3\"><a href=\"".XMLEncode($LogoLink)."\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\" /></a>";
7335 }
7336 if (! $StaticLinks) { print "<br />"; Show_Flag_Links($Lang); }
7337 print "</td>";
7338 }
7339 print "</tr>\n";
7340 }
7341 if ($FrameName ne 'mainleft') {
7342 # Print Last Update
7343 print "<tr valign=\"middle\"><td class=\"aws\" valign=\"middle\" width=\"$WIDTHMENU1\"><b>$Message[35]:</b> </td>";
7344 print "<td class=\"aws\" valign=\"middle\"><span style=\"font-size: 12px;\">";
7345 if ($LastUpdate) { print Format_Date($LastUpdate,0); }
7346 else {
7347 # Here NbOfOldLines = 0 (because LastUpdate is not defined)
7348 if (! $UpdateStats) { print "<span style=\"color: #880000\">$Message[24]</span>"; }
7349 else { print "<span style=\"color: #880000\">No qualified records found in log ($NbOfLinesCorrupted corrupted, $NbOfLinesDropped dropped)</span>"; }
7350
7351 rizwank 1.1 }
7352 print "</span>";
7353 # Print Update Now link
7354 if ($AllowToUpdateStatsFromBrowser && ! $StaticLinks) {
7355 my $NewLinkParams=${QueryString};
7356 $NewLinkParams =~ s/(^|&)update(=\w*|$)//i;
7357 $NewLinkParams =~ s/(^|&)staticlinks(=\w*|$)//i;
7358 $NewLinkParams =~ s/(^|&)framename=[^&]*//i;
7359 if ($FrameName eq 'mainright') { $NewLinkParams.="&framename=mainright"; }
7360 $NewLinkParams =~ tr/&/&/s; $NewLinkParams =~ s/^&//; $NewLinkParams =~ s/&$//;
7361 if ($NewLinkParams) { $NewLinkParams="${NewLinkParams}&"; }
7362 print " ";
7363 print "<a href=\"".XMLEncode("$AWScript?${NewLinkParams}update=1")."\">$Message[74]</a>";
7364 }
7365 print "</td>";
7366
7367 # Logo and flags
7368 if ($FrameName eq 'mainright') {
7369 if ($LogoLink =~ "http://awstats.sourceforge.net") {
7370 print "<td align=\"right\" rowspan=\"2\"><a href=\"".XMLEncode($LogoLink)."\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\"".AltTitle(ucfirst($PROG)." Web Site")." /></a>\n";
7371 }
7372 rizwank 1.1 else {
7373 print "<td align=\"right\" rowspan=\"2\"><a href=\"".XMLEncode($LogoLink)."\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\" /></a>\n";
7374 }
7375 if (! $StaticLinks) { print "<br />"; Show_Flag_Links($Lang); }
7376 print "</td>";
7377 }
7378
7379 print "</tr>\n";
7380 # Print selected period of analysis (month and year required)
7381 print "<tr><td class=\"aws\" valign=\"middle\"><b>$Message[133]:</b></td>";
7382 print "<td class=\"aws\" valign=\"middle\">";
7383 if ($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks) {
7384 print "<select class=\"aws_formfield\" name=\"month\">\n";
7385 foreach (1..12) { my $monthix=sprintf("%02s",$_); print "<option".($MonthRequired eq "$monthix"?" selected=\"true\"":"")." value=\"$monthix\">$MonthNumLib{$monthix}</option>\n"; }
7386 if ($AllowFullYearView >= 2) {
7387 print "<option".($MonthRequired eq 'all'?" selected=\"true\"":"")." value=\"all\">- $Message[6] -</option>\n";
7388 }
7389 print "</select>\n";
7390 print "<select class=\"aws_formfield\" name=\"year\">\n";
7391 # Add YearRequired in list if not in ListOfYears
7392 $ListOfYears{$YearRequired}||=$MonthRequired;
7393 rizwank 1.1 foreach (sort keys %ListOfYears) { print "<option".($YearRequired eq "$_"?" selected=\"true\"":"")." value=\"$_\">$_</option>\n"; }
7394 print "</select>\n";
7395 print "<input type=\"hidden\" name=\"output\" value=\"".join(',',keys %HTMLOutput)."\" />\n";
7396 if ($SiteConfig) { print "<input type=\"hidden\" name=\"config\" value=\"$SiteConfig\" />\n"; }
7397 if ($DirConfig) { print "<input type=\"hidden\" name=\"configdir\" value=\"$DirConfig\" />\n"; }
7398 if ($QueryString =~ /lang=(\w+)/i) { print "<input type=\"hidden\" name=\"lang\" value=\"$1\" />\n"; }
7399 if ($QueryString =~ /debug=(\d+)/i) { print "<input type=\"hidden\" name=\"debug\" value=\"$1\" />\n"; }
7400 if ($FrameName eq 'mainright') { print "<input type=\"hidden\" name=\"framename\" value=\"index\" />\n"; }
7401 print "<input type=\"submit\" value=\" $Message[115] \" class=\"aws_button\" />";
7402 }
7403 else {
7404 print "<span style=\"font-size: 14px;\">";
7405 if ($MonthRequired eq 'all') { print "$Message[6] $YearRequired"; }
7406 else { print "$Message[5] $MonthNumLib{$MonthRequired} $YearRequired"; }
7407 print "</span>";
7408 }
7409 print "</td></tr>\n";
7410 }
7411 if ($QueryString !~ /buildpdf/i) {
7412 print "</table>\n";
7413 print "</td></tr></table>\n";
7414 rizwank 1.1 }
7415 else {
7416 print "</table>\n";
7417 }
7418
7419 if ($FrameName ne 'mainleft') { print "</form>\n"; }
7420 else { print "<br />\n"; }
7421 print "\n";
7422 }
7423
7424 # Call to plugins' function AddHTMLMenuHeader
7425 foreach my $pluginname (keys %{$PluginsLoaded{'AddHTMLMenuHeader'}}) {
7426 my $function="AddHTMLMenuHeader_$pluginname()";
7427 eval("$function");
7428 }
7429
7430 # MENU
7431 #---------------------------------------------------------------------
7432 if ($ShowMenu || $FrameName eq 'mainleft') {
7433 my $frame=($FrameName eq 'mainleft');
7434
7435 rizwank 1.1 if ($Debug) { debug("ShowMenu",2); }
7436
7437 # Print menu links
7438 if (($HTMLOutput{'main'} && $FrameName ne 'mainright') || $FrameName eq 'mainleft') { # If main page asked
7439 # Define link anchor
7440 my $linkanchor=($FrameName eq 'mainleft'?"$AWScript?${NewLinkParams}":"");
7441 if ($linkanchor && ($linkanchor !~ /framename=mainright/)) { $linkanchor.="framename=mainright"; }
7442 $linkanchor =~ s/&$//; $linkanchor=XMLEncode("$linkanchor");
7443 # Define target
7444 my $targetpage=($FrameName eq 'mainleft'?" target=\"mainright\"":"");
7445 # Print Menu
7446 my $linetitle; # TODO a virer
7447 if (! $PluginsLoaded{'ShowMenu'}{'menuapplet'}) {
7448 my $menuicon=0; # TODO a virer
7449 # Menu HTML
7450 print "<table".($frame?" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"":"").">\n";
7451 if ($FrameName eq 'mainleft' && $ShowMonthStats) { print ($frame?"<tr><td class=\"awsm\">":""); print "<a href=\"$linkanchor#top\"$targetpage>$Message[128]</a>"; print ($frame?"</td></tr>\n":" "); }
7452 my %menu=(); my %menulink=(); my %menutext=();
7453 # When
7454 %menu=('month'=>$ShowMonthStats?1:0,'daysofmonth'=>$ShowDaysOfMonthStats?2:0,'daysofweek'=>$ShowDaysOfWeekStats?3:0,'hours'=>$ShowHoursStats?4:0);
7455 %menulink=('month'=>1,'daysofmonth'=>1,'daysofweek'=>1,'hours'=>1);
7456 rizwank 1.1 %menutext=('month'=>$Message[162],'daysofmonth'=>$Message[138],'daysofweek'=>$Message[91],'hours'=>$Message[20]);
7457 ShowMenuCateg('when',$Message[93],'menu4.png',$frame,$targetpage,$linkanchor,$NewLinkParams,$NewLinkTarget,\%menu,\%menulink,\%menutext);
7458 # Who
7459 %menu=('countries'=>$ShowDomainsStats?1:0,'alldomains'=>$ShowDomainsStats?2:0,'visitors'=>$ShowHostsStats?3:0,'allhosts'=>$ShowHostsStats?4:0,'lasthosts'=>($ShowHostsStats =~ /L/i)?5:0,'unknownip'=>$ShowHostsStats?6:0,'logins'=>$ShowAuthenticatedUsers?7:0,'alllogins'=>$ShowAuthenticatedUsers?8:0,'lastlogins'=>($ShowAuthenticatedUsers =~ /L/i)?9:0,'emailsenders'=>$ShowEMailSenders?10:0,'allemails'=>$ShowEMailSenders?11:0,'lastemails'=>($ShowEMailSenders =~ /L/i)?12:0,'emailreceivers'=>$ShowEMailReceivers?13:0,'allemailr'=>$ShowEMailReceivers?14:0,'lastemailr'=>($ShowEMailReceivers =~ /L/i)?15:0,'robots'=>$ShowRobotsStats?16:0,'allrobots'=>$ShowRobotsStats?17:0,'lastrobots'=>($ShowRobotsStats =~ /L/i)?18:0,'worms'=>$ShowWormsStats?19:0);
7460 %menulink=('countries'=>1,'alldomains'=>2,'visitors'=>1,'allhosts'=>2,'lasthosts'=>2,'unknownip'=>2,'logins'=>1,'alllogins'=>2,'lastlogins'=>2,'emailsenders'=>1,'allemails'=>2,'lastemails'=>2,'emailreceivers'=>1,'allemailr'=>2,'lastemailr'=>2,'robots'=>1,'allrobots'=>2,'lastrobots'=>2,'worms'=>1);
7461 %menutext=('countries'=>$Message[148],'alldomains'=>$Message[80],'visitors'=>$Message[81],'allhosts'=>$Message[80],'lasthosts'=>$Message[9],'unknownip'=>$Message[45],'logins'=>$Message[94],'alllogins'=>$Message[80],'lastlogins'=>$Message[9],'emailsenders'=>$Message[131],'allemails'=>$Message[80],'lastemails'=>$Message[9],'emailreceivers'=>$Message[132],'allemailr'=>$Message[80],'lastemailr'=>$Message[9],'robots'=>$Message[53],'allrobots'=>$Message[80],'lastrobots'=>$Message[9],'worms'=>$Message[136]);
7462 ShowMenuCateg('who',$Message[92],'menu5.png',$frame,$targetpage,$linkanchor,$NewLinkParams,$NewLinkTarget,\%menu,\%menulink,\%menutext);
7463 # Navigation
7464 $linetitle=&AtLeastOneNotNull($ShowSessionsStats,$ShowPagesStats,$ShowFileTypesStats,$ShowFileSizesStats,$ShowOSStats,$ShowBrowsersStats,$ShowScreenSizeStats);
7465 if ($linetitle) { print "<tr><td class=\"awsm\"".($frame?"":" valign=\"top\"").">".($menuicon?"<img src=\"$DirIcons/other/menu2.png\" /> ":"")."<b>$Message[72]:</b></td>\n"; }
7466 if ($linetitle) { print ($frame?"</tr>\n":"<td class=\"awsm\">"); }
7467 if ($ShowSessionsStats) { print ($frame?"<tr><td class=\"awsm\">":""); print "<a href=\"$linkanchor#sessions\"$targetpage>$Message[117]</a>"; print ($frame?"</td></tr>\n":" "); }
7468 if ($ShowFileTypesStats) { print ($frame?"<tr><td class=\"awsm\">":""); print "<a href=\"$linkanchor#filetypes\"$targetpage>$Message[73]</a>"; print ($frame?"</td></tr>\n":" "); }
7469 if ($ShowPagesStats) { print ($frame?"<tr><td class=\"awsm\">":""); print "<a href=\"$linkanchor#urls\"$targetpage>$Message[29]</a>\n"; print ($frame?"</td></tr>\n":" "); }
7470 if ($ShowPagesStats) { print ($frame?"<tr><td class=\"awsm\"> <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> ":""); print "<a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=urldetail"):"$PROG$StaticLinks.urldetail.$StaticExt")."\"$NewLinkTarget>$Message[80]</a>\n"; print ($frame?"</td></tr>\n":" "); }
7471 if ($ShowPagesStats =~ /E/i) { print ($frame?"<tr><td class=\"awsm\"> <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> ":""); print "<a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=urlentry"):"$PROG$StaticLinks.urlentry.$StaticExt")."\"$NewLinkTarget>$Message[104]</a>\n"; print ($frame?"</td></tr>\n":" "); }
7472 if ($ShowPagesStats =~ /X/i) { print ($frame?"<tr><td class=\"awsm\"> <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> ":""); print "<a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=urlexit"):"$PROG$StaticLinks.urlexit.$StaticExt")."\"$NewLinkTarget>$Message[116]</a>\n"; print ($frame?"</td></tr>\n":" "); }
7473 if ($ShowOSStats) { print ($frame?"<tr><td class=\"awsm\">":""); print "<a href=\"$linkanchor#os\"$targetpage>$Message[59]</a>"; print ($frame?"</td></tr>\n":" "); }
7474 if ($ShowOSStats) { print ($frame?"<tr><td class=\"awsm\"> <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> ":""); print "<a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=osdetail"):"$PROG$StaticLinks.osdetail.$StaticExt")."\"$NewLinkTarget>$Message[58]</a>\n"; print ($frame?"</td></tr>\n":" "); }
7475 if ($ShowOSStats) { print ($frame?"<tr><td class=\"awsm\"> <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> ":""); print "<a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=unknownos"):"$PROG$StaticLinks.unknownos.$StaticExt")."\"$NewLinkTarget>$Message[0]</a>\n"; print ($frame?"</td></tr>\n":" "); }
7476 if ($ShowBrowsersStats) { print ($frame?"<tr><td class=\"awsm\">":""); print "<a href=\"$linkanchor#browsers\"$targetpage>$Message[21]</a>"; print ($frame?"</td></tr>\n":" "); }
7477 rizwank 1.1 if ($ShowBrowsersStats) { print ($frame?"<tr><td class=\"awsm\"> <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> ":""); print "<a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=browserdetail"):"$PROG$StaticLinks.browserdetail.$StaticExt")."\"$NewLinkTarget>$Message[58]</a>\n"; print ($frame?"</td></tr>\n":" "); }
7478 if ($ShowBrowsersStats) { print ($frame?"<tr><td class=\"awsm\"> <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> ":""); print "<a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=unknownbrowser"):"$PROG$StaticLinks.unknownbrowser.$StaticExt")."\"$NewLinkTarget>$Message[0]</a>\n"; print ($frame?"</td></tr>\n":" "); }
7479 if ($ShowScreenSizeStats) { print ($frame?"<tr><td class=\"awsm\">":""); print "<a href=\"$linkanchor#screensizes\"$targetpage>$Message[135]</a>"; print ($frame?"</td></tr>\n":" "); }
7480 if ($linetitle) { print ($frame?"":"</td></tr>\n"); }
7481 # Referers
7482 %menu=('referer'=>$ShowOriginStats?1:0,'refererse'=>$ShowOriginStats?2:0,'refererpages'=>$ShowOriginStats?3:0,'keys'=>($ShowKeyphrasesStats || $ShowKeywordsStats)?4:0,'keyphrases'=>$ShowKeyphrasesStats?5:0,'keywords'=>$ShowKeywordsStats?6:0);
7483 %menulink=('referer'=>1,'refererse'=>2,'refererpages'=>2,'keys'=>1,'keyphrases'=>2,'keywords'=>2);
7484 %menutext=('referer'=>$Message[37],'refererse'=>$Message[126],'refererpages'=>$Message[127],'keys'=>$Message[14],'keyphrases'=>$Message[120],'keywords'=>$Message[121]);
7485 ShowMenuCateg('referers',$Message[23],'menu7.png',$frame,$targetpage,$linkanchor,$NewLinkParams,$NewLinkTarget,\%menu,\%menulink,\%menutext);
7486 # Others
7487 %menu=('filetypes'=>($ShowFileTypesStats =~ /C/i)?1:0,'misc'=>$ShowMiscStats?2:0,'errors'=>($ShowHTTPErrorsStats||$ShowSMTPErrorsStats)?3:0,'clusters'=>$ShowClusterStats?5:0);
7488 %menulink=('filetypes'=>1,'misc'=>1,'errors'=>1,'clusters'=>1);
7489 %menutext=('filetypes'=>$Message[98],'misc'=>$Message[139],'errors'=>($ShowSMTPErrorsStats?$Message[147]:$Message[32]),'clusters'=>$Message[155]);
7490 foreach (keys %TrapInfosForHTTPErrorCodes) {
7491 $menu{"errors$_"}=$ShowHTTPErrorsStats?4:0;
7492 $menulink{"errors$_"}=2;
7493 $menutext{"errors$_"}=$Message[31];
7494 }
7495 ShowMenuCateg('others',$Message[2],'menu8.png',$frame,$targetpage,$linkanchor,$NewLinkParams,$NewLinkTarget,\%menu,\%menulink,\%menutext);
7496 # Extra/Marketing
7497 %menu=();
7498 rizwank 1.1 %menulink=();
7499 %menutext=();
7500 foreach (1..@ExtraName-1) {
7501 $menu{"extra$_"}=1;
7502 $menulink{"extra$_"}=1;
7503 $menutext{"extra$_"}=$ExtraName[$_];
7504 }
7505 ShowMenuCateg('extra',$Message[134],'',$frame,$targetpage,$linkanchor,$NewLinkParams,$NewLinkTarget,\%menu,\%menulink,\%menutext);
7506 print "</table>\n";
7507 }
7508 else {
7509 # Menu Applet
7510 if ($frame) { }
7511 else {}
7512 }
7513 #print ($frame?"":"<br />\n");
7514 print "<br />\n";
7515 }
7516 # Print Back link
7517 elsif (! $HTMLOutput{'main'}) {
7518 print "<table>\n";
7519 rizwank 1.1 $NewLinkParams =~ s/(^|&)hostfilter=[^&]*//i;
7520 $NewLinkParams =~ s/(^|&)urlfilter=[^&]*//i;
7521 $NewLinkParams =~ s/(^|&)refererpagesfilter=[^&]*//i;
7522 $NewLinkParams =~ tr/&/&/s; $NewLinkParams =~ s/&$//;
7523 if (! $DetailedReportsOnNewWindows || $FrameName eq 'mainright' || $QueryString =~ /buildpdf/i) {
7524 print "<tr><td class=\"aws\"><a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript".(${NewLinkParams}?"?${NewLinkParams}":"")):"$PROG$StaticLinks.$StaticExt")."\">$Message[76]</a></td></tr>\n";
7525 }
7526 else {
7527 print "<tr><td class=\"aws\"><a href=\"javascript:parent.window.close();\">$Message[118]</a></td></tr>\n";
7528 }
7529 print "</table>\n";
7530 print "\n";
7531 }
7532 }
7533
7534 # Call to plugins' function AddHTMLMenuFooter
7535 foreach my $pluginname (keys %{$PluginsLoaded{'AddHTMLMenuFooter'}}) {
7536 my $function="AddHTMLMenuFooter_$pluginname()";
7537 eval("$function");
7538 }
7539
7540 rizwank 1.1 # Exit if left frame
7541 if ($FrameName eq 'mainleft') {
7542 &html_end(0);
7543 exit 0;
7544 }
7545
7546 # FirstTime LastTime TotalVisits TotalUnique TotalPages TotalHits TotalBytes TotalHostsKnown TotalHostsUnknown
7547 my $FirstTime=0;
7548 my $LastTime=0;
7549 $TotalUnique=$TotalVisits=$TotalPages=$TotalHits=$TotalBytes=0;
7550 $TotalNotViewedPages=$TotalNotViewedHits=$TotalNotViewedBytes=0;
7551 $TotalHostsKnown=$TotalHostsUnknown=0;
7552 my $beginmonth=$MonthRequired;my $endmonth=$MonthRequired;
7553 if ($MonthRequired eq 'all') { $beginmonth=1;$endmonth=12; }
7554 for (my $month=$beginmonth; $month<=$endmonth; $month++) {
7555 my $monthix=sprintf("%02s",$month);
7556 if ($FirstTime{$YearRequired.$monthix} && ($FirstTime == 0 || $FirstTime > $FirstTime{$YearRequired.$monthix})) { $FirstTime = $FirstTime{$YearRequired.$monthix}; }
7557 if ($LastTime < ($LastTime{$YearRequired.$monthix}||0)) { $LastTime = $LastTime{$YearRequired.$monthix}; }
7558 $TotalHostsKnown+=$MonthHostsKnown{$YearRequired.$monthix}||0; # Wrong in year view
7559 $TotalHostsUnknown+=$MonthHostsUnknown{$YearRequired.$monthix}||0; # Wrong in year view
7560 $TotalUnique+=$MonthUnique{$YearRequired.$monthix}||0; # Wrong in year view
7561 rizwank 1.1 $TotalVisits+=$MonthVisits{$YearRequired.$monthix}||0;
7562 $TotalPages+=$MonthPages{$YearRequired.$monthix}||0;
7563 $TotalHits+=$MonthHits{$YearRequired.$monthix}||0;
7564 $TotalBytes+=$MonthBytes{$YearRequired.$monthix}||0;
7565 $TotalNotViewedPages+=$MonthNotViewedPages{$YearRequired.$monthix}||0;
7566 $TotalNotViewedHits+=$MonthNotViewedHits{$YearRequired.$monthix}||0;
7567 $TotalNotViewedBytes+=$MonthNotViewedBytes{$YearRequired.$monthix}||0;
7568 }
7569 # TotalHitsErrors TotalBytesErrors
7570 my $TotalHitsErrors=0; my $TotalBytesErrors=0;
7571 foreach (keys %_errors_h) { $TotalHitsErrors+=$_errors_h{$_}; $TotalBytesErrors+=$_errors_k{$_}; }
7572 # TotalEntries (if not already specifically counted, we init it from _url_e hash table)
7573 if (!$TotalEntries) { foreach (keys %_url_e) { $TotalEntries+=$_url_e{$_}; } }
7574 # TotalExits (if not already specifically counted, we init it from _url_x hash table)
7575 if (!$TotalExits) { foreach (keys %_url_x) { $TotalExits+=$_url_x{$_}; } }
7576 # TotalBytesPages (if not already specifically counted, we init it from _url_k hash table)
7577 if (!$TotalBytesPages) { foreach (keys %_url_k) { $TotalBytesPages+=$_url_k{$_}; } }
7578 # TotalKeyphrases (if not already specifically counted, we init it from _keyphrases hash table)
7579 if (!$TotalKeyphrases) { foreach (keys %_keyphrases) { $TotalKeyphrases+=$_keyphrases{$_}; } }
7580 # TotalKeywords (if not already specifically counted, we init it from _keywords hash table)
7581 if (!$TotalKeywords) { foreach (keys %_keywords) { $TotalKeywords+=$_keywords{$_}; } }
7582 rizwank 1.1 # TotalSearchEnginesPages (if not already specifically counted, we init it from _se_referrals_p hash table)
7583 if (!$TotalSearchEnginesPages) { foreach (keys %_se_referrals_p) { $TotalSearchEnginesPages+=$_se_referrals_p{$_}; } }
7584 # TotalSearchEnginesHits (if not already specifically counted, we init it from _se_referrals_h hash table)
7585 if (!$TotalSearchEnginesHits) { foreach (keys %_se_referrals_h) { $TotalSearchEnginesHits+=$_se_referrals_h{$_}; } }
7586 # TotalRefererPages (if not already specifically counted, we init it from _pagesrefs_p hash table)
7587 if (!$TotalRefererPages) { foreach (keys %_pagesrefs_p) { $TotalRefererPages+=$_pagesrefs_p{$_}; } }
7588 # TotalRefererHits (if not already specifically counted, we init it from _pagesrefs_h hash table)
7589 if (!$TotalRefererHits) { foreach (keys %_pagesrefs_h) { $TotalRefererHits+=$_pagesrefs_h{$_}; } }
7590 # TotalDifferentPages (if not already specifically counted, we init it from _url_p hash table)
7591 $TotalDifferentPages||=scalar keys %_url_p;
7592 # TotalDifferentKeyphrases (if not already specifically counted, we init it from _keyphrases hash table)
7593 $TotalDifferentKeyphrases||=scalar keys %_keyphrases;
7594 # TotalDifferentKeywords (if not already specifically counted, we init it from _keywords hash table)
7595 $TotalDifferentKeywords||=scalar keys %_keywords;
7596 # TotalDifferentSearchEngines (if not already specifically counted, we init it from _se_referrals_h hash table)
7597 $TotalDifferentSearchEngines||=scalar keys %_se_referrals_h;
7598 # TotalDifferentReferer (if not already specifically counted, we init it from _pagesrefs_h hash table)
7599 $TotalDifferentReferer||=scalar keys %_pagesrefs_h;
7600
7601 # Define firstdaytocountaverage, lastdaytocountaverage, firstdaytoshowtime, lastdaytoshowtime
7602 my $firstdaytocountaverage=$nowyear.$nowmonth."01"; # Set day cursor to 1st day of month
7603 rizwank 1.1 my $firstdaytoshowtime=$nowyear.$nowmonth."01"; # Set day cursor to 1st day of month
7604 my $lastdaytocountaverage=$nowyear.$nowmonth.$nowday; # Set day cursor to today
7605 my $lastdaytoshowtime=$nowyear.$nowmonth."31"; # Set day cursor to last day of month
7606 if ($MonthRequired eq 'all') {
7607 $firstdaytocountaverage=$YearRequired."0101"; # Set day cursor to 1st day of the required year
7608 }
7609 if (($MonthRequired ne $nowmonth && $MonthRequired ne 'all') || $YearRequired ne $nowyear) {
7610 if ($MonthRequired eq 'all') {
7611 $firstdaytocountaverage=$YearRequired."0101"; # Set day cursor to 1st day of the required year
7612 $firstdaytoshowtime=$YearRequired."1201"; # Set day cursor to 1st day of last month of required year
7613 $lastdaytocountaverage=$YearRequired."1231"; # Set day cursor to last day of the required year
7614 $lastdaytoshowtime=$YearRequired."1231"; # Set day cursor to last day of last month of required year
7615 }
7616 else {
7617 $firstdaytocountaverage=$YearRequired.$MonthRequired."01"; # Set day cursor to 1st day of the required month
7618 $firstdaytoshowtime=$YearRequired.$MonthRequired."01"; # Set day cursor to 1st day of the required month
7619 $lastdaytocountaverage=$YearRequired.$MonthRequired."31"; # Set day cursor to last day of the required month
7620 $lastdaytoshowtime=$YearRequired.$MonthRequired."31"; # Set day cursor to last day of the required month
7621 }
7622 }
7623 if ($Debug) {
7624 rizwank 1.1 debug("firstdaytocountaverage=$firstdaytocountaverage, lastdaytocountaverage=$lastdaytocountaverage",1);
7625 debug("firstdaytoshowtime=$firstdaytoshowtime, lastdaytoshowtime=$lastdaytoshowtime",1);
7626 }
7627
7628 # Call to plugins' function AddHTMLContentHeader
7629 foreach my $pluginname (keys %{$PluginsLoaded{'AddHTMLContentHeader'}}) {
7630 my $function="AddHTMLContentHeader_$pluginname()";
7631 eval("$function");
7632 }
7633
7634 # Output particular part
7635 #-----------------------
7636 if (scalar keys %HTMLOutput == 1) {
7637
7638 if ($HTMLOutput{'alldomains'}) {
7639 print "$Center<a name=\"domains\"> </a><br />\n";
7640 # Show domains list
7641 my $title=''; my $cpt=0;
7642 if ($HTMLOutput{'alldomains'}) { $title.="$Message[25]"; $cpt=(scalar keys %_domener_h); }
7643 &tab_head("$title",19,0,'domains');
7644 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\"> </th><th colspan=\"2\">$Message[17]</th>";
7645 rizwank 1.1 if ($ShowDomainsStats =~ /P/i) { print "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>"; }
7646 if ($ShowDomainsStats =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>"; }
7647 if ($ShowDomainsStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>"; }
7648 print "<th> </th>";
7649 print "</tr>\n";
7650 $total_p=$total_h=$total_k=0;
7651 $max_h=1; foreach (values %_domener_h) { if ($_ > $max_h) { $max_h = $_; } }
7652 $max_k=1; foreach (values %_domener_k) { if ($_ > $max_k) { $max_k = $_; } }
7653 my $count=0;
7654 &BuildKeyList($MaxRowsInHTMLOutput,1,\%_domener_h,\%_domener_p);
7655 foreach my $key (@keylist) {
7656 my $bredde_p=0;my $bredde_h=0;my $bredde_k=0;
7657 if ($max_h > 0) { $bredde_p=int($BarWidth*$_domener_p{$key}/$max_h)+1; } # use max_h to enable to compare pages with hits
7658 if ($_domener_p{$key} && $bredde_p==1) { $bredde_p=2; }
7659 if ($max_h > 0) { $bredde_h=int($BarWidth*$_domener_h{$key}/$max_h)+1; }
7660 if ($_domener_h{$key} && $bredde_h==1) { $bredde_h=2; }
7661 if ($max_k > 0) { $bredde_k=int($BarWidth*($_domener_k{$key}||0)/$max_k)+1; }
7662 if ($_domener_k{$key} && $bredde_k==1) { $bredde_k=2; }
7663 my $newkey=lc($key);
7664 if ($newkey eq 'ip' || ! $DomainsHashIDLib{$newkey}) {
7665 print "<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/ip.png\" height=\"14\"".AltTitle("$Message[0]")." /></td><td class=\"aws\">$Message[0]</td><td>$newkey</td>";
7666 rizwank 1.1 }
7667 else {
7668 print "<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/$newkey.png\" height=\"14\"".AltTitle("$newkey")." /></td><td class=\"aws\">$DomainsHashIDLib{$newkey}</td><td>$newkey</td>";
7669 }
7670 if ($ShowDomainsStats =~ /P/i) { print "<td>$_domener_p{$key}</td>"; }
7671 if ($ShowDomainsStats =~ /H/i) { print "<td>$_domener_h{$key}</td>"; }
7672 if ($ShowDomainsStats =~ /B/i) { print "<td>".Format_Bytes($_domener_k{$key})."</td>"; }
7673 print "<td class=\"aws\">";
7674 if ($ShowDomainsStats =~ /P/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"5\"".AltTitle("$Message[56]: ".int($_domener_p{$key}))." /><br />\n"; }
7675 if ($ShowDomainsStats =~ /H/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\"".AltTitle("$Message[57]: ".int($_domener_h{$key}))." /><br />\n"; }
7676 if ($ShowDomainsStats =~ /B/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"5\"".AltTitle("$Message[75]: ".Format_Bytes($_domener_k{$key}))." />"; }
7677 print "</td>";
7678 print "</tr>\n";
7679 $total_p += $_domener_p{$key};
7680 $total_h += $_domener_h{$key};
7681 $total_k += $_domener_k{$key}||0;
7682 $count++;
7683 }
7684 $rest_p=$TotalPages-$total_p;
7685 $rest_h=$TotalHits-$total_h;
7686 $rest_k=$TotalBytes-$total_k;
7687 rizwank 1.1 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other domains (known or not)
7688 print "<tr><td width=\"$WIDTHCOLICON\"> </td><td colspan=\"2\" class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
7689 if ($ShowDomainsStats =~ /P/i) { print "<td>$rest_p</td>"; }
7690 if ($ShowDomainsStats =~ /H/i) { print "<td>$rest_h</td>"; }
7691 if ($ShowDomainsStats =~ /B/i) { print "<td>".Format_Bytes($rest_k)."</td>"; }
7692 print "<td class=\"aws\"> </td>";
7693 print "</tr>\n";
7694 }
7695 &tab_end();
7696 &html_end(1);
7697 }
7698 if ($HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'}) {
7699 print "$Center<a name=\"hosts\"> </a><br />\n";
7700 # Show filter form
7701 &ShowFormFilter("hostfilter",$FilterIn{'host'},$FilterEx{'host'});
7702 # Show hosts list
7703 my $title=''; my $cpt=0;
7704 if ($HTMLOutput{'allhosts'}) { $title.="$Message[81]"; $cpt=(scalar keys %_host_h); }
7705 if ($HTMLOutput{'lasthosts'}) { $title.="$Message[9]"; $cpt=(scalar keys %_host_h); }
7706 &tab_head("$title",19,0,'hosts');
7707 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
7708 rizwank 1.1 if ($FilterIn{'host'} || $FilterEx{'host'}) { # With filter
7709 if ($FilterIn{'host'}) { print "$Message[79] '<b>$FilterIn{'host'}</b>'"; }
7710 if ($FilterIn{'host'} && $FilterEx{'host'}) { print " - "; }
7711 if ($FilterEx{'host'}) { print " Exlude $Message[79] '<b>$FilterEx{'host'}</b>'"; }
7712 if ($FilterIn{'host'} || $FilterEx{'host'}) { print ": "; }
7713 print "$cpt $Message[81]";
7714 if ($MonthRequired ne 'all') {
7715 if ($HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'}) { print "<br />$Message[102]: $TotalHostsKnown $Message[82], $TotalHostsUnknown $Message[1] - $TotalUnique $Message[11]"; }
7716 }
7717 }
7718 else { # Without filter
7719 if ($MonthRequired ne 'all') { print "$Message[102] : $TotalHostsKnown $Message[82], $TotalHostsUnknown $Message[1] - $TotalUnique $Message[11]"; }
7720 else { print "$Message[102] : ".(scalar keys %_host_h); }
7721 }
7722 print "</th>";
7723 &ShowHostInfo('__title__');
7724 if ($ShowHostsStats =~ /P/i) { print "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>"; }
7725 if ($ShowHostsStats =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>"; }
7726 if ($ShowHostsStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>"; }
7727 if ($ShowHostsStats =~ /L/i) { print "<th width=\"120\">$Message[9]</th>"; }
7728 print "</tr>\n";
7729 rizwank 1.1 $total_p=$total_h=$total_k=0;
7730 my $count=0;
7731 if ($HTMLOutput{'allhosts'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Host'},\%_host_h,\%_host_p); }
7732 if ($HTMLOutput{'lasthosts'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Host'},\%_host_h,\%_host_l); }
7733 foreach my $key (@keylist) {
7734 my $host=CleanFromCSSA($key);
7735 print "<tr><td class=\"aws\">".($_robot_l{$key}?'<b>':'')."$host".($_robot_l{$key}?'</b>':'')."</td>";
7736 &ShowHostInfo($key);
7737 if ($ShowHostsStats =~ /P/i) { print "<td>".($_host_p{$key}?$_host_p{$key}:" ")."</td>"; }
7738 if ($ShowHostsStats =~ /H/i) { print "<td>$_host_h{$key}</td>"; }
7739 if ($ShowHostsStats =~ /B/i) { print "<td>".Format_Bytes($_host_k{$key})."</td>"; }
7740 if ($ShowHostsStats =~ /L/i) { print "<td>".($_host_l{$key}?Format_Date($_host_l{$key},1):'-')."</td>"; }
7741 print "</tr>\n";
7742 $total_p += $_host_p{$key};
7743 $total_h += $_host_h{$key};
7744 $total_k += $_host_k{$key}||0;
7745 $count++;
7746 }
7747 if ($Debug) { debug("Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",2); }
7748 $rest_p=$TotalPages-$total_p;
7749 $rest_h=$TotalHits-$total_h;
7750 rizwank 1.1 $rest_k=$TotalBytes-$total_k;
7751 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other visitors (known or not)
7752 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
7753 &ShowHostInfo('');
7754 if ($ShowHostsStats =~ /P/i) { print "<td>".($rest_p?$rest_p:" ")."</td>"; }
7755 if ($ShowHostsStats =~ /H/i) { print "<td>$rest_h</td>"; }
7756 if ($ShowHostsStats =~ /B/i) { print "<td>".Format_Bytes($rest_k)."</td>"; }
7757 if ($ShowHostsStats =~ /L/i) { print "<td> </td>"; }
7758 print "</tr>\n";
7759 }
7760 &tab_end();
7761 &html_end(1);
7762 }
7763 if ($HTMLOutput{'unknownip'}) {
7764 print "$Center<a name=\"unknownip\"> </a><br />\n";
7765 &tab_head("$Message[45]",19,0,'unknownwip');
7766 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>".(scalar keys %_host_h)." $Message[1]</th>";
7767 &ShowHostInfo('__title__');
7768 if ($ShowHostsStats =~ /P/i) { print "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>"; }
7769 if ($ShowHostsStats =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>"; }
7770 if ($ShowHostsStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>"; }
7771 rizwank 1.1 if ($ShowHostsStats =~ /L/i) { print "<th width=\"120\">$Message[9]</th>"; }
7772 print "</tr>\n";
7773 $total_p=$total_h=$total_k=0;
7774 my $count=0;
7775 &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Host'},\%_host_h,\%_host_p);
7776 foreach my $key (@keylist) {
7777 my $host=CleanFromCSSA($key);
7778 print "<tr><td class=\"aws\">$host</td>";
7779 &ShowHostInfo($key);
7780 if ($ShowHostsStats =~ /P/i) { print "<td>".($_host_p{$key}?$_host_p{$key}:" ")."</td>"; }
7781 if ($ShowHostsStats =~ /H/i) { print "<td>$_host_h{$key}</td>"; }
7782 if ($ShowHostsStats =~ /B/i) { print "<td>".Format_Bytes($_host_k{$key})."</td>"; }
7783 if ($ShowHostsStats =~ /L/i) { print "<td>".($_host_l{$key}?Format_Date($_host_l{$key},1):'-')."</td>"; }
7784 print "</tr>\n";
7785 $total_p += $_host_p{$key};
7786 $total_h += $_host_h{$key};
7787 $total_k += $_host_k{$key}||0;
7788 $count++;
7789 }
7790 if ($Debug) { debug("Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",2); }
7791 $rest_p=$TotalPages-$total_p;
7792 rizwank 1.1 $rest_h=$TotalHits-$total_h;
7793 $rest_k=$TotalBytes-$total_k;
7794 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other visitors (known or not)
7795 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[82]</span></td>";
7796 &ShowHostInfo('');
7797 if ($ShowHostsStats =~ /P/i) { print "<td>".($rest_p?$rest_p:" ")."</td>"; }
7798 if ($ShowHostsStats =~ /H/i) { print "<td>$rest_h</td>"; }
7799 if ($ShowHostsStats =~ /B/i) { print "<td>".Format_Bytes($rest_k)."</td>"; }
7800 if ($ShowHostsStats =~ /L/i) { print "<td> </td>"; }
7801 print "</tr>\n";
7802 }
7803 &tab_end();
7804 &html_end(1);
7805 }
7806 if ($HTMLOutput{'allemails'} || $HTMLOutput{'lastemails'}) {
7807 &ShowEmailSendersChart($NewLinkParams,$NewLinkTarget);
7808 &html_end(1);
7809 }
7810 if ($HTMLOutput{'allemailr'} || $HTMLOutput{'lastemailr'}) {
7811 &ShowEmailReceiversChart($NewLinkParams,$NewLinkTarget);
7812 &html_end(1);
7813 rizwank 1.1 }
7814 if ($HTMLOutput{'alllogins'} || $HTMLOutput{'lastlogins'}) {
7815 print "$Center<a name=\"logins\"> </a><br />\n";
7816 my $title='';
7817 if ($HTMLOutput{'alllogins'}) { $title.="$Message[94]"; }
7818 if ($HTMLOutput{'lastlogins'}) { $title.="$Message[9]"; }
7819 &tab_head("$title",19,0,'logins');
7820 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[94] : ".(scalar keys %_login_h)."</th>";
7821 &ShowUserInfo('__title__');
7822 if ($ShowAuthenticatedUsers =~ /P/i) { print "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>"; }
7823 if ($ShowAuthenticatedUsers =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>"; }
7824 if ($ShowAuthenticatedUsers =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>"; }
7825 if ($ShowAuthenticatedUsers =~ /L/i) { print "<th width=\"120\">$Message[9]</th>"; }
7826 print "</tr>\n";
7827 $total_p=$total_h=$total_k=0;
7828 my $count=0;
7829 if ($HTMLOutput{'alllogins'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Host'},\%_login_h,\%_login_p); }
7830 if ($HTMLOutput{'lastlogins'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Host'},\%_login_h,\%_login_l); }
7831 foreach my $key (@keylist) {
7832 print "<tr><td class=\"aws\">$key</td>";
7833 &ShowUserInfo($key);
7834 rizwank 1.1 if ($ShowAuthenticatedUsers =~ /P/i) { print "<td>".($_login_p{$key}?$_login_p{$key}:" ")."</td>"; }
7835 if ($ShowAuthenticatedUsers =~ /H/i) { print "<td>$_login_h{$key}</td>"; }
7836 if ($ShowAuthenticatedUsers =~ /B/i) { print "<td>".Format_Bytes($_login_k{$key})."</td>"; }
7837 if ($ShowAuthenticatedUsers =~ /L/i) { print "<td>".($_login_l{$key}?Format_Date($_login_l{$key},1):'-')."</td>"; }
7838 print "</tr>\n";
7839 $total_p += $_login_p{$key}||0;
7840 $total_h += $_login_h{$key};
7841 $total_k += $_login_k{$key}||0;
7842 $count++;
7843 }
7844 if ($Debug) { debug("Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",2); }
7845 $rest_p=$TotalPages-$total_p;
7846 $rest_h=$TotalHits-$total_h;
7847 $rest_k=$TotalBytes-$total_k;
7848 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other logins and/or anonymous
7849 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[125]</span></td>";
7850 &ShowUserInfo('');
7851 if ($ShowAuthenticatedUsers =~ /P/i) { print "<td>".($rest_p?$rest_p:" ")."</td>"; }
7852 if ($ShowAuthenticatedUsers =~ /H/i) { print "<td>$rest_h</td>"; }
7853 if ($ShowAuthenticatedUsers =~ /B/i) { print "<td>".Format_Bytes($rest_k)."</td>"; }
7854 if ($ShowAuthenticatedUsers =~ /L/i) { print "<td> </td>"; }
7855 rizwank 1.1 print "</tr>\n";
7856 }
7857 &tab_end();
7858 &html_end(1);
7859 }
7860 if ($HTMLOutput{'allrobots'} || $HTMLOutput{'lastrobots'}) {
7861 print "$Center<a name=\"robots\"> </a><br />\n";
7862 my $title='';
7863 if ($HTMLOutput{'allrobots'}) { $title.="$Message[53]"; }
7864 if ($HTMLOutput{'lastrobots'}) { $title.="$Message[9]"; }
7865 &tab_head("$title",19,0,'robots');
7866 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>".(scalar keys %_robot_h)." $Message[51]</th>";
7867 if ($ShowRobotsStats =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>"; }
7868 if ($ShowRobotsStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>"; }
7869 if ($ShowRobotsStats =~ /L/i) { print "<th width=\"120\">$Message[9]</th>"; }
7870 print "</tr>\n";
7871 $total_p=$total_h=$total_k=$total_r=0;
7872 my $count=0;
7873 if ($HTMLOutput{'allrobots'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Robot'},\%_robot_h,\%_robot_h); }
7874 if ($HTMLOutput{'lastrobots'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Robot'},\%_robot_h,\%_robot_l); }
7875 foreach my $key (@keylist) {
7876 rizwank 1.1 print "<tr><td class=\"aws\">".($RobotsHashIDLib{$key}?$RobotsHashIDLib{$key}:$key)."</td>";
7877 if ($ShowRobotsStats =~ /H/i) { print "<td>".($_robot_h{$key}-$_robot_r{$key}).($_robot_r{$key}?"+$_robot_r{$key}":"")."</td>"; }
7878 if ($ShowRobotsStats =~ /B/i) { print "<td>".Format_Bytes($_robot_k{$key})."</td>"; }
7879 if ($ShowRobotsStats =~ /L/i) { print "<td>".($_robot_l{$key}?Format_Date($_robot_l{$key},1):'-')."</td>"; }
7880 print "</tr>\n";
7881 #$total_p += $_robot_p{$key}||0;
7882 $total_h += $_robot_h{$key};
7883 $total_k += $_robot_k{$key}||0;
7884 $total_r += $_robot_r{$key}||0;
7885 $count++;
7886 }
7887 # For bots we need to count Totals
7888 my $TotalPagesRobots = 0; #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
7889 my $TotalHitsRobots = 0; foreach (values %_robot_h) { $TotalHitsRobots+=$_; }
7890 my $TotalBytesRobots = 0; foreach (values %_robot_k) { $TotalBytesRobots+=$_; }
7891 my $TotalRRobots = 0; foreach (values %_robot_r) { $TotalRRobots+=$_; }
7892 $rest_p=0; #$rest_p=$TotalPagesRobots-$total_p;
7893 $rest_h=$TotalHitsRobots-$total_h;
7894 $rest_k=$TotalBytesRobots-$total_k;
7895 $rest_r=$TotalRRobots-$total_r;
7896 if ($Debug) { debug("Total real / shown : $TotalPagesRobots / $total_p - $TotalHitsRobots / $total_h - $TotalBytesRobots / $total_k",2); }
7897 rizwank 1.1 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0) { # All other robots
7898 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
7899 if ($ShowRobotsStats =~ /H/i) { print "<td>$rest_h</td>"; }
7900 if ($ShowRobotsStats =~ /B/i) { print "<td>".(Format_Bytes($rest_k))."</td>"; }
7901 if ($ShowRobotsStats =~ /L/i) { print "<td> </td>"; }
7902 print "</tr>\n";
7903 }
7904 &tab_end("* $Message[156]".($TotalRRobots?" $Message[157]":""));
7905 &html_end(1);
7906 }
7907 if ($HTMLOutput{'urldetail'} || $HTMLOutput{'urlentry'} || $HTMLOutput{'urlexit'}) {
7908 # Call to plugins' function ShowPagesFilter
7909 foreach my $pluginname (keys %{$PluginsLoaded{'ShowPagesFilter'}}) {
7910 my $function="ShowPagesFilter_$pluginname()";
7911 eval("$function");
7912 }
7913 print "$Center<a name=\"urls\"> </a><br />\n";
7914 # Show filter form
7915 &ShowFormFilter("urlfilter",$FilterIn{'url'},$FilterEx{'url'});
7916 # Show URL list
7917 my $title=''; my $cpt=0;
7918 rizwank 1.1 if ($HTMLOutput{'urldetail'}) { $title=$Message[19]; $cpt=(scalar keys %_url_p); }
7919 if ($HTMLOutput{'urlentry'}) { $title=$Message[104]; $cpt=(scalar keys %_url_e); }
7920 if ($HTMLOutput{'urlexit'}) { $title=$Message[116]; $cpt=(scalar keys %_url_x); }
7921 &tab_head("$title",19,0,'urls');
7922 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
7923 if ($FilterIn{'url'} || $FilterEx{'url'}) {
7924 if ($FilterIn{'url'}) { print "$Message[79] <b>$FilterIn{'url'}</b>"; }
7925 if ($FilterIn{'url'} && $FilterEx{'url'}) { print " - "; }
7926 if ($FilterEx{'url'}) { print "Exclude $Message[79] <b>$FilterEx{'url'}</b>"; }
7927 if ($FilterIn{'url'} || $FilterEx{'url'}) { print ": "; }
7928 print "$cpt $Message[28]";
7929 if ($MonthRequired ne 'all') {
7930 if ($HTMLOutput{'urldetail'}) { print "<br />$Message[102]: $TotalDifferentPages $Message[28]"; }
7931 }
7932 }
7933 else { print "$Message[102]: $cpt $Message[28]"; }
7934 print "</th>";
7935 if ($ShowPagesStats =~ /P/i) { print "<th bgcolor=\"#$color_p\" width=\"80\">$Message[29]</th>"; }
7936 if ($ShowPagesStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>"; }
7937 if ($ShowPagesStats =~ /E/i) { print "<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>"; }
7938 if ($ShowPagesStats =~ /X/i) { print "<th bgcolor=\"#$color_x\" width=\"80\">$Message[116]</th>"; }
7939 rizwank 1.1 # Call to plugins' function ShowPagesAddField
7940 foreach my $pluginname (keys %{$PluginsLoaded{'ShowPagesAddField'}}) {
7941 my $function="ShowPagesAddField_$pluginname('title')";
7942 eval("$function");
7943 }
7944 print "<th> </th></tr>\n";
7945 $total_p=$total_k=$total_e=$total_x=0;
7946 my $count=0;
7947 if ($HTMLOutput{'urlentry'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'File'},\%_url_e,\%_url_e); }
7948 elsif ($HTMLOutput{'urlexit'}) { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'File'},\%_url_x,\%_url_x); }
7949 else { &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'File'},\%_url_p,\%_url_p); }
7950 $max_p=1; $max_k=1;
7951 foreach my $key (@keylist) {
7952 if ($_url_p{$key} > $max_p) { $max_p = $_url_p{$key}; }
7953 if ($_url_k{$key}/($_url_p{$key}||1) > $max_k) { $max_k = $_url_k{$key}/($_url_p{$key}||1); }
7954 }
7955 foreach my $key (@keylist) {
7956 print "<tr><td class=\"aws\">";
7957 &ShowURLInfo($key);
7958 print "</td>";
7959 my $bredde_p=0; my $bredde_e=0; my $bredde_x=0; my $bredde_k=0;
7960 rizwank 1.1 if ($max_p > 0) { $bredde_p=int($BarWidth*($_url_p{$key}||0)/$max_p)+1; }
7961 if (($bredde_p==1) && $_url_p{$key}) { $bredde_p=2; }
7962 if ($max_p > 0) { $bredde_e=int($BarWidth*($_url_e{$key}||0)/$max_p)+1; }
7963 if (($bredde_e==1) && $_url_e{$key}) { $bredde_e=2; }
7964 if ($max_p > 0) { $bredde_x=int($BarWidth*($_url_x{$key}||0)/$max_p)+1; }
7965 if (($bredde_x==1) && $_url_x{$key}) { $bredde_x=2; }
7966 if ($max_k > 0) { $bredde_k=int($BarWidth*(($_url_k{$key}||0)/($_url_p{$key}||1))/$max_k)+1; }
7967 if (($bredde_k==1) && $_url_k{$key}) { $bredde_k=2; }
7968 if ($ShowPagesStats =~ /P/i) { print "<td>$_url_p{$key}</td>"; }
7969 if ($ShowPagesStats =~ /B/i) { print "<td>".($_url_k{$key}?Format_Bytes($_url_k{$key}/($_url_p{$key}||1)):" ")."</td>"; }
7970 if ($ShowPagesStats =~ /E/i) { print "<td>".($_url_e{$key}?$_url_e{$key}:" ")."</td>"; }
7971 if ($ShowPagesStats =~ /X/i) { print "<td>".($_url_x{$key}?$_url_x{$key}:" ")."</td>"; }
7972 # Call to plugins' function ShowPagesAddField
7973 foreach my $pluginname (keys %{$PluginsLoaded{'ShowPagesAddField'}}) {
7974 my $function="ShowPagesAddField_$pluginname('$key')";
7975 eval("$function");
7976 }
7977 print "<td class=\"aws\">";
7978 # alt and title are not provided to reduce page size
7979 if ($ShowPagesStats =~ /P/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"4\" /><br />"; }
7980 if ($ShowPagesStats =~ /B/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"4\" /><br />"; }
7981 rizwank 1.1 if ($ShowPagesStats =~ /E/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\" /><br />"; }
7982 if ($ShowPagesStats =~ /X/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'hx'}\" width=\"$bredde_x\" height=\"4\" />"; }
7983 print "</td></tr>\n";
7984 $total_p += $_url_p{$key};
7985 $total_e += $_url_e{$key};
7986 $total_x += $_url_x{$key};
7987 $total_k += $_url_k{$key};
7988 $count++;
7989 }
7990 if ($Debug) { debug("Total real / shown : $TotalPages / $total_p - $TotalEntries / $total_e - $TotalExits / $total_x - $TotalBytesPages / $total_k",2); }
7991 $rest_p=$TotalPages-$total_p;
7992 $rest_k=$TotalBytesPages-$total_k;
7993 $rest_e=$TotalEntries-$total_e;
7994 $rest_x=$TotalExits-$total_x;
7995 if ($rest_p > 0 || $rest_e > 0 || $rest_k > 0) {
7996 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
7997 if ($ShowPagesStats =~ /P/i) { print "<td>".($rest_p?$rest_p:" ")."</td>"; }
7998 if ($ShowPagesStats =~ /B/i) { print "<td>".($rest_k?Format_Bytes($rest_k/($rest_p||1)):" ")."</td>"; }
7999 if ($ShowPagesStats =~ /E/i) { print "<td>".($rest_e?$rest_e:" ")."</td>"; }
8000 if ($ShowPagesStats =~ /X/i) { print "<td>".($rest_x?$rest_x:" ")."</td>"; }
8001 # Call to plugins' function ShowPagesAddField
8002 rizwank 1.1 foreach my $pluginname (keys %{$PluginsLoaded{'ShowPagesAddField'}}) {
8003 my $function="ShowPagesAddField_$pluginname('')";
8004 eval("$function");
8005 }
8006 print "<td> </td></tr>\n";
8007 }
8008 &tab_end();
8009 &html_end(1);
8010 }
8011 if ($HTMLOutput{'unknownos'}) {
8012 print "$Center<a name=\"unknownos\"> </a><br />\n";
8013 my $title="$Message[46]";
8014 &tab_head("$title",19,0,'unknownos');
8015 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>User agent (".(scalar keys %_unknownreferer_l).")</th><th>$Message[9]</th></tr>\n";
8016 $total_l=0;
8017 my $count=0;
8018 &BuildKeyList($MaxRowsInHTMLOutput,1,\%_unknownreferer_l,\%_unknownreferer_l);
8019 foreach my $key (@keylist) {
8020 my $useragent=CleanFromCSSA($key);
8021 print "<tr><td class=\"aws\">$useragent</td>";
8022 print "<td>".Format_Date($_unknownreferer_l{$key},1)."</td>";
8023 rizwank 1.1 print "</tr>\n";
8024 $total_l+=1;
8025 $count++;
8026 }
8027 $rest_l=(scalar keys %_unknownreferer_l)-$total_l;
8028 if ($rest_l > 0) {
8029 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
8030 print "<td>-</td>";
8031 print "</tr>\n";
8032 }
8033 &tab_end();
8034 &html_end(1);
8035 }
8036 if ($HTMLOutput{'unknownbrowser'}) {
8037 print "$Center<a name=\"unknownbrowser\"> </a><br />\n";
8038 my $title="$Message[50]";
8039 &tab_head("$title",19,0,'unknownbrowser');
8040 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>User agent (".(scalar keys %_unknownrefererbrowser_l).")</th><th>$Message[9]</th></tr>\n";
8041 $total_l=0;
8042 my $count=0;
8043 &BuildKeyList($MaxRowsInHTMLOutput,1,\%_unknownrefererbrowser_l,\%_unknownrefererbrowser_l);
8044 rizwank 1.1 foreach my $key (@keylist) {
8045 my $useragent=CleanFromCSSA($key);
8046 print "<tr><td class=\"aws\">$useragent</td><td>".Format_Date($_unknownrefererbrowser_l{$key},1)."</td></tr>\n";
8047 $total_l+=1;
8048 $count++;
8049 }
8050 $rest_l=(scalar keys %_unknownrefererbrowser_l)-$total_l;
8051 if ($rest_l > 0) {
8052 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
8053 print "<td>-</td>";
8054 print "</tr>\n";
8055 }
8056 &tab_end();
8057 &html_end(1);
8058 }
8059 if ($HTMLOutput{'osdetail'}) {
8060 # Show os versions
8061 print "$Center<a name=\"osversions\"> </a><br />";
8062 my $title="$Message[59]";
8063 &tab_head("$title",19,0,'osversions');
8064 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[58]</th>";
8065 rizwank 1.1 print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
8066 print "<th> </th>";
8067 print "</tr>\n";
8068 $total_h=0;
8069 my $count=0;
8070 &BuildKeyList(MinimumButNoZero(scalar keys %_os_h,500),1,\%_os_h,\%_os_h);
8071 my %keysinkeylist=();
8072 $max_h=1;
8073 # Count total by family
8074 my %totalfamily_h=();
8075 my $TotalFamily=0;
8076 OSLOOP: foreach my $key (@keylist) {
8077 $total_h+=$_os_h{$key};
8078 if ($_os_h{$key} > $max_h) { $max_h = $_os_h{$key}; }
8079 foreach my $family (@OSFamily) { if ($key =~ /^$family/i) { $totalfamily_h{$family}+=$_os_h{$key}; $TotalFamily+=$_os_h{$key}; next OSLOOP; } }
8080 }
8081 # Write records grouped in a browser family
8082 foreach my $family (@OSFamily) {
8083 my $p=' ';
8084 if ($total_h) { $p=int($totalfamily_h{$family}/$total_h*1000)/10; $p="$p %"; }
8085 my $familyheadershown=0;
8086 rizwank 1.1 foreach my $key (reverse sort keys %_os_h) {
8087 if ($key =~ /^$family(.*)/i) {
8088 if (! $familyheadershown) {
8089 print "<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>".uc($family)."</b></td>";
8090 print "<td><b>".int($totalfamily_h{$family})."</b></td><td><b>$p</b></td><td> </td>";
8091 print "</tr>\n";
8092 $familyheadershown=1;
8093 }
8094 $keysinkeylist{$key}=1;
8095 my $ver=$1;
8096 my $p=' ';
8097 if ($total_h) { $p=int($_os_h{$key}/$total_h*1000)/10; $p="$p %"; }
8098 print "<tr>";
8099 print "<td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/os\/$key.png\"".AltTitle("")." /></td>";
8100 print "<td class=\"aws\">$OSHashLib{$key}</td>";
8101 my $bredde_h=0;
8102 if ($max_h > 0) { $bredde_h=int($BarWidth*($_os_h{$key}||0)/$max_h)+1; }
8103 if (($bredde_h==1) && $_os_h{$key}) { $bredde_h=2; }
8104 print "<td>$_os_h{$key}</td><td>$p</td>";
8105 print "<td class=\"aws\">";
8106 # alt and title are not provided to reduce page size
8107 rizwank 1.1 if ($ShowOSStats) { print "<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />"; }
8108 print "</td>";
8109 print "</tr>\n";
8110 $count++;
8111 }
8112 }
8113 }
8114 # Write other records
8115 my $familyheadershown=0;
8116 foreach my $key (@keylist) {
8117 if ($keysinkeylist{$key}) { next; }
8118 if (! $familyheadershown) {
8119 my $p=' ';
8120 if ($total_h) { $p=int(($total_h-$TotalFamily)/$total_h*1000)/10; $p="$p %"; }
8121 print "<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$Message[2]</b></td>";
8122 print "<td><b>".($total_h-$TotalFamily)."</b></td><td><b>$p</b></td><td> </td>";
8123 print "</tr>\n";
8124 $familyheadershown=1;
8125 }
8126 my $p=' ';
8127 if ($total_h) { $p=int($_os_h{$key}/$total_h*1000)/10; $p="$p %"; }
8128 rizwank 1.1 print "<tr>";
8129 if ($key eq 'Unknown') {
8130 print "<td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/browser\/unknown.png\"".AltTitle("")." /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
8131 }
8132 else {
8133 my $keywithoutcumul=$key; $keywithoutcumul =~ s/cumul$//i;
8134 my $libos=$OSHashLib{$keywithoutcumul}||$keywithoutcumul;
8135 my $nameicon=$keywithoutcumul; $nameicon =~ s/[^\w]//g;
8136 print "<td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/os\/$nameicon.png\"".AltTitle("")." /></td><td class=\"aws\">$libos</td>";
8137 }
8138 my $bredde_h=0;
8139 if ($max_h > 0) { $bredde_h=int($BarWidth*($_os_h{$key}||0)/$max_h)+1; }
8140 if (($bredde_h==1) && $_os_h{$key}) { $bredde_h=2; }
8141 print "<td>$_os_h{$key}</td><td>$p</td>";
8142 print "<td class=\"aws\">";
8143 # alt and title are not provided to reduce page size
8144 if ($ShowOSStats) { print "<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />"; }
8145 print "</td>";
8146 print "</tr>\n";
8147 }
8148 &tab_end();
8149 rizwank 1.1 &html_end(1);
8150 }
8151 if ($HTMLOutput{'browserdetail'}) {
8152 # Show browsers versions
8153 print "$Center<a name=\"browsersversions\"> </a><br />";
8154 my $title="$Message[21]";
8155 &tab_head("$title",19,0,'browsersversions');
8156 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[58]</th>";
8157 print "<th width=\"80\">$Message[111]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
8158 print "<th> </th>";
8159 print "</tr>\n";
8160 $total_h=0;
8161 my $count=0;
8162 &BuildKeyList(MinimumButNoZero(scalar keys %_browser_h,500),1,\%_browser_h,\%_browser_h);
8163 my %keysinkeylist=();
8164 $max_h=1;
8165 # Count total by family
8166 my %totalfamily_h=();
8167 my $TotalFamily=0;
8168 BROWSERLOOP: foreach my $key (@keylist) {
8169 $total_h+=$_browser_h{$key};
8170 rizwank 1.1 if ($_browser_h{$key} > $max_h) { $max_h = $_browser_h{$key}; }
8171 foreach my $family (keys %BrowsersFamily) { if ($key =~ /^$family/i) { $totalfamily_h{$family}+=$_browser_h{$key}; $TotalFamily+=$_browser_h{$key}; next BROWSERLOOP; } }
8172 }
8173 # Write records grouped in a browser family
8174 foreach my $family (sort { $BrowsersFamily{$a} <=> $BrowsersFamily{$b} } keys %BrowsersFamily) {
8175 my $p=' ';
8176 if ($total_h) { $p=int($totalfamily_h{$family}/$total_h*1000)/10; $p="$p %"; }
8177 my $familyheadershown=0;
8178 foreach my $key (reverse sort keys %_browser_h) {
8179 if ($key =~ /^$family(.*)/i) {
8180 if (! $familyheadershown) {
8181 print "<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>".uc($family)."</b></td>";
8182 print "<td> </td><td><b>".int($totalfamily_h{$family})."</b></td><td><b>$p</b></td><td> </td>";
8183 print "</tr>\n";
8184 $familyheadershown=1;
8185 }
8186 $keysinkeylist{$key}=1;
8187 my $ver=$1;
8188 my $p=' ';
8189 if ($total_h) { $p=int($_browser_h{$key}/$total_h*1000)/10; $p="$p %"; }
8190 print "<tr>";
8191 rizwank 1.1 print "<td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/browser\/$family.png\"".AltTitle("")." /></td>";
8192 print "<td class=\"aws\">".ucfirst($family)." ".($ver?"$ver":"?")."</td>";
8193 print "<td>".($BrowsersHereAreGrabbers{$family}?"<b>$Message[112]</b>":"$Message[113]")."</td>";
8194 my $bredde_h=0;
8195 if ($max_h > 0) { $bredde_h=int($BarWidth*($_browser_h{$key}||0)/$max_h)+1; }
8196 if (($bredde_h==1) && $_browser_h{$key}) { $bredde_h=2; }
8197 print "<td>$_browser_h{$key}</td><td>$p</td>";
8198 print "<td class=\"aws\">";
8199 # alt and title are not provided to reduce page size
8200 if ($ShowBrowsersStats) { print "<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />"; }
8201 print "</td>";
8202 print "</tr>\n";
8203 $count++;
8204 }
8205 }
8206 }
8207 # Write other records
8208 my $familyheadershown=0;
8209 foreach my $key (@keylist) {
8210 if ($keysinkeylist{$key}) { next; }
8211 if (! $familyheadershown) {
8212 rizwank 1.1 my $p=' ';
8213 if ($total_h) { $p=int(($total_h-$TotalFamily)/$total_h*1000)/10; $p="$p %"; }
8214 print "<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$Message[2]</b></td>";
8215 print "<td> </td><td><b>".($total_h-$TotalFamily)."</b></td><td><b>$p</b></td><td> </td>";
8216 print "</tr>\n";
8217 $familyheadershown=1;
8218 }
8219 my $p=' ';
8220 if ($total_h) { $p=int($_browser_h{$key}/$total_h*1000)/10; $p="$p %"; }
8221 print "<tr>";
8222 if ($key eq 'Unknown') {
8223 print "<td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/browser\/unknown.png\"".AltTitle("")." /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td width=\"80\">?</td>";
8224 }
8225 else {
8226 my $keywithoutcumul=$key; $keywithoutcumul =~ s/cumul$//i;
8227 my $libbrowser=$BrowsersHashIDLib{$keywithoutcumul}||$keywithoutcumul;
8228 my $nameicon=$BrowsersHashIcon{$keywithoutcumul}||"notavailable";
8229 print "<td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/browser\/$nameicon.png\"".AltTitle("")." /></td><td class=\"aws\">$libbrowser</td><td>".($BrowsersHereAreGrabbers{$key}?"<b>$Message[112]</b>":"$Message[113]")."</td>";
8230 }
8231 my $bredde_h=0;
8232 if ($max_h > 0) { $bredde_h=int($BarWidth*($_browser_h{$key}||0)/$max_h)+1; }
8233 rizwank 1.1 if (($bredde_h==1) && $_browser_h{$key}) { $bredde_h=2; }
8234 print "<td>$_browser_h{$key}</td><td>$p</td>";
8235 print "<td class=\"aws\">";
8236 # alt and title are not provided to reduce page size
8237 if ($ShowBrowsersStats) { print "<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />"; }
8238 print "</td>";
8239 print "</tr>\n";
8240 }
8241 &tab_end();
8242 &html_end(1);
8243 }
8244 if ($HTMLOutput{'refererse'}) {
8245 print "$Center<a name=\"refererse\"> </a><br />\n";
8246 my $title="$Message[40]";
8247 &tab_head("$title",19,0,'refererse');
8248 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$TotalDifferentSearchEngines $Message[122]</th>";
8249 print "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
8250 print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
8251 print "</tr>\n";
8252 $total_s=0;
8253 my $count=0;
8254 rizwank 1.1 &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Refer'},\%_se_referrals_h,((scalar keys %_se_referrals_p)?\%_se_referrals_p:\%_se_referrals_h)); # before 5.4 only hits were recorded
8255 foreach my $key (@keylist) {
8256 my $newreferer=CleanFromCSSA($SearchEnginesHashLib{$key}||$key);
8257 my $p_p; my $p_h;
8258 if ($TotalSearchEnginesPages) { $p_p=int($_se_referrals_p{$key}/$TotalSearchEnginesPages*1000)/10; }
8259 if ($TotalSearchEnginesHits) { $p_h=int($_se_referrals_h{$key}/$TotalSearchEnginesHits*1000)/10; }
8260 print "<tr><td class=\"aws\">$newreferer</td>";
8261 print "<td>".($_se_referrals_p{$key}?$_se_referrals_p{$key}:' ')."</td>";
8262 print "<td>".($_se_referrals_p{$key}?"$p_p %":' ')."</td>";
8263 print "<td>$_se_referrals_h{$key}</td>";
8264 print "<td>$p_h %</td>";
8265 print "</tr>\n";
8266 $total_p += $_se_referrals_p{$key};
8267 $total_h += $_se_referrals_h{$key};
8268 $count++;
8269 }
8270 if ($Debug) { debug("Total real / shown : $TotalSearchEnginesPages / $total_p - $TotalSearchEnginesHits / $total_h",2); }
8271 $rest_p=$TotalSearchEnginesPages-$total_p;
8272 $rest_h=$TotalSearchEnginesHits-$total_h;
8273 if ($rest_p > 0 || $rest_h > 0) {
8274 my $p_p;my $p_h;
8275 rizwank 1.1 if ($TotalSearchEnginesPages) { $p_p=int($rest_p/$TotalSearchEnginesPages*1000)/10; }
8276 if ($TotalSearchEnginesHits) { $p_h=int($rest_h/$TotalSearchEnginesHits*1000)/10; }
8277 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
8278 print "<td>".($rest_p?$rest_p:' ')."</td>";
8279 print "<td>".($rest_p?"$p_p %":' ')."</td>";
8280 print "<td>$rest_h</td>";
8281 print "<td>$p_h %</td>";
8282 print "</tr>\n";
8283 }
8284 &tab_end();
8285 &html_end(1);
8286 }
8287 if ($HTMLOutput{'refererpages'}) {
8288 print "$Center<a name=\"refererpages\"> </a><br />\n";
8289 # Show filter form
8290 &ShowFormFilter("refererpagesfilter",$FilterIn{'refererpages'},$FilterEx{'refererpages'});
8291 my $title="$Message[41]"; my $cpt=0;
8292 $cpt=(scalar keys %_pagesrefs_h);
8293 &tab_head("$title",19,0,'refererpages');
8294 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
8295 if ($FilterIn{'refererpages'} || $FilterEx{'refererpages'}) {
8296 rizwank 1.1 if ($FilterIn{'refererpages'}) { print "$Message[79] <b>$FilterIn{'refererpages'}</b>"; }
8297 if ($FilterIn{'refererpages'} && $FilterEx{'refererpages'}) { print " - "; }
8298 if ($FilterEx{'refererpages'}) { print "Exclude $Message[79] <b>$FilterEx{'refererpages'}</b>"; }
8299 if ($FilterIn{'refererpages'} || $FilterEx{'refererpages'}) { print ": "; }
8300 print "$cpt $Message[28]";
8301 #if ($MonthRequired ne 'all') {
8302 # if ($HTMLOutput{'refererpages'}) { print "<br />$Message[102]: $TotalDifferentPages $Message[28]"; }
8303 #}
8304 }
8305 else { print "$Message[102]: $cpt $Message[28]"; }
8306 print "</th>";
8307 print "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
8308 print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
8309 print "</tr>\n";
8310 $total_s=0;
8311 my $count=0;
8312 &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Refer'},\%_pagesrefs_h,((scalar keys %_pagesrefs_p)?\%_pagesrefs_p:\%_pagesrefs_h));
8313 foreach my $key (@keylist) {
8314 my $nompage=CleanFromCSSA($key);
8315 if (length($nompage)>$MaxLengthOfShownURL) { $nompage=substr($nompage,0,$MaxLengthOfShownURL)."..."; }
8316 my $p_p; my $p_h;
8317 rizwank 1.1 if ($TotalRefererPages) { $p_p=int($_pagesrefs_p{$key}/$TotalRefererPages*1000)/10; }
8318 if ($TotalRefererHits) { $p_h=int($_pagesrefs_h{$key}/$TotalRefererHits*1000)/10; }
8319 print "<tr><td class=\"aws\">";
8320 &ShowURLInfo($key);
8321 print "</td>";
8322 print "<td>".($_pagesrefs_p{$key}?$_pagesrefs_p{$key}:' ')."</td><td>".($_pagesrefs_p{$key}?"$p_p %":' ')."</td>";
8323 print "<td>".($_pagesrefs_h{$key}?$_pagesrefs_h{$key}:' ')."</td><td>".($_pagesrefs_h{$key}?"$p_h %":' ')."</td>";
8324 print "</tr>\n";
8325 $total_p += $_pagesrefs_p{$key};
8326 $total_h += $_pagesrefs_h{$key};
8327 $count++;
8328 }
8329 if ($Debug) { debug("Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",2); }
8330 $rest_p=$TotalRefererPages-$total_p;
8331 $rest_h=$TotalRefererHits-$total_h;
8332 if ($rest_p > 0 || $rest_h > 0) {
8333 my $p_p; my $p_h;
8334 if ($TotalRefererPages) { $p_p=int($rest_p/$TotalRefererPages*1000)/10; }
8335 if ($TotalRefererHits) { $p_h=int($rest_h/$TotalRefererHits*1000)/10; }
8336 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
8337 print "<td>".($rest_p?$rest_p:' ')."</td>";
8338 rizwank 1.1 print "<td>".($rest_p?"$p_p %":' ')."</td>";
8339 print "<td>$rest_h</td>";
8340 print "<td>$p_h %</td>";
8341 print "</tr>\n";
8342 }
8343 &tab_end();
8344 &html_end(1);
8345 }
8346 if ($HTMLOutput{'keyphrases'}) {
8347 print "$Center<a name=\"keyphrases\"> </a><br />\n";
8348 &tab_head($Message[43],19,0,'keyphrases');
8349 print "<tr bgcolor=\"#$color_TableBGRowTitle\"".Tooltip(15)."><th>$TotalDifferentKeyphrases $Message[103]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
8350 $total_s=0;
8351 my $count=0;
8352 &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Keyphrase'},\%_keyphrases,\%_keyphrases);
8353 foreach my $key (@keylist) {
8354 my $mot;
8355 # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
8356 if ($PluginsLoaded{'DecodeKey'}{'decodeutfkeys'}) { $mot=CleanFromCSSA(DecodeKey_decodeutfkeys($key,$PageCode||'iso-8859-1')); }
8357 else { $mot = CleanFromCSSA(DecodeEncodedString($key)); }
8358 my $p;
8359 rizwank 1.1 if ($TotalKeyphrases) { $p=int($_keyphrases{$key}/$TotalKeyphrases*1000)/10; }
8360 print "<tr><td class=\"aws\">".XMLEncode($mot)."</td><td>$_keyphrases{$key}</td><td>$p %</td></tr>\n";
8361 $total_s += $_keyphrases{$key};
8362 $count++;
8363 }
8364 if ($Debug) { debug("Total real / shown : $TotalKeyphrases / $total_s",2); }
8365 $rest_s=$TotalKeyphrases-$total_s;
8366 if ($rest_s > 0) {
8367 my $p;
8368 if ($TotalKeyphrases) { $p=int($rest_s/$TotalKeyphrases*1000)/10; }
8369 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[124]</span></td><td>$rest_s</td>";
8370 print "<td>$p %</td></tr>\n";
8371 }
8372 &tab_end();
8373 &html_end(1);
8374 }
8375 if ($HTMLOutput{'keywords'}) {
8376 print "$Center<a name=\"keywords\"> </a><br />\n";
8377 &tab_head($Message[44],19,0,'keywords');
8378 print "<tr bgcolor=\"#$color_TableBGRowTitle\"".Tooltip(15)."><th>$TotalDifferentKeywords $Message[13]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
8379 $total_s=0;
8380 rizwank 1.1 my $count=0;
8381 &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Keyword'},\%_keywords,\%_keywords);
8382 foreach my $key (@keylist) {
8383 my $mot;
8384 # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
8385 if ($PluginsLoaded{'DecodeKey'}{'decodeutfkeys'}) { $mot=CleanFromCSSA(DecodeKey_decodeutfkeys($key,$PageCode||'iso-8859-1')); }
8386 else { $mot = CleanFromCSSA(DecodeEncodedString($key)); }
8387 my $p;
8388 if ($TotalKeywords) { $p=int($_keywords{$key}/$TotalKeywords*1000)/10; }
8389 print "<tr><td class=\"aws\">".XMLEncode($mot)."</td><td>$_keywords{$key}</td><td>$p %</td></tr>\n";
8390 $total_s += $_keywords{$key};
8391 $count++;
8392 }
8393 if ($Debug) { debug("Total real / shown : $TotalKeywords / $total_s",2); }
8394 $rest_s=$TotalKeywords-$total_s;
8395 if ($rest_s > 0) {
8396 my $p;
8397 if ($TotalKeywords) { $p=int($rest_s/$TotalKeywords*1000)/10; }
8398 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td><td>$rest_s</td>";
8399 print "<td>$p %</td></tr>\n";
8400 }
8401 rizwank 1.1 &tab_end();
8402 &html_end(1);
8403 }
8404 foreach my $code (keys %TrapInfosForHTTPErrorCodes) {
8405 if ($HTMLOutput{"errors$code"}) {
8406 print "$Center<a name=\"errors$code\"> </a><br />\n";
8407 &tab_head($Message[47],19,0,"errors$code");
8408 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>URL (".(scalar keys %_sider404_h).")</th><th bgcolor=\"#$color_h\">$Message[49]</th><th>$Message[23]</th></tr>\n";
8409 $total_h=0;
8410 my $count=0;
8411 &BuildKeyList($MaxRowsInHTMLOutput,1,\%_sider404_h,\%_sider404_h);
8412 foreach my $key (@keylist) {
8413 my $nompage=XMLEncode(CleanFromCSSA($key));
8414 #if (length($nompage)>$MaxLengthOfShownURL) { $nompage=substr($nompage,0,$MaxLengthOfShownURL)."..."; }
8415 my $referer=XMLEncode(CleanFromCSSA($_referer404_h{$key}));
8416 print "<tr><td class=\"aws\">$nompage</td>";
8417 print "<td>$_sider404_h{$key}</td>";
8418 print "<td class=\"aws\">".($referer?"$referer":" ")."</td>";
8419 print "</tr>\n";
8420 $total_s += $_sider404_h{$key};
8421 $count++;
8422 rizwank 1.1 }
8423 # TODO Build TotalErrorHits
8424 # if ($Debug) { debug("Total real / shown : $TotalErrorHits / $total_h",2); }
8425 # $rest_h=$TotalErrorHits-$total_h;
8426 # if ($rest_h > 0) {
8427 # my $p;
8428 # if ($TotalErrorHits) { $p=int($rest_h/$TotalErrorHits*1000)/10; }
8429 # print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td>";
8430 # print "<td>$rest_h</td>";
8431 # print "<td>...</td>";
8432 # print "</tr>\n";
8433 # }
8434 &tab_end();
8435 &html_end(1);
8436 }
8437 }
8438 if ($HTMLOutput{'info'}) {
8439 # Not yet available
8440 print "$Center<a name=\"info\"> </a><br />";
8441 &html_end(1);
8442 }
8443 rizwank 1.1
8444 my $htmloutput='';
8445 foreach my $key (keys %HTMLOutput) { $htmloutput=$key; }
8446 if ($htmloutput =~ /^plugin_(\w+)$/) {
8447 my $pluginname=$1;
8448 print "$Center<a name=\"plugin_$pluginname\"> </a><br />";
8449 my $function="AddHTMLGraph_$pluginname()";
8450 eval("$function");
8451 &html_end(1);
8452 }
8453 }
8454
8455 # Output main page
8456 #-----------------
8457
8458 if ($HTMLOutput{'main'}) {
8459
8460 # SUMMARY
8461 #---------------------------------------------------------------------
8462 if ($ShowMonthStats) {
8463 if ($Debug) { debug("ShowSummary",2); }
8464 rizwank 1.1 #print "$Center<a name=\"summary\"> </a><br />\n";
8465 my $title="$Message[128]";
8466 &tab_head("$title",0,0,'month');
8467
8468 my $NewLinkParams=${QueryString};
8469 $NewLinkParams =~ s/(^|&)update(=\w*|$)//i;
8470 $NewLinkParams =~ s/(^|&)staticlinks(=\w*|$)//i;
8471 $NewLinkParams =~ s/(^|&)year=[^&]*//i;
8472 $NewLinkParams =~ s/(^|&)month=[^&]*//i;
8473 $NewLinkParams =~ s/(^|&)framename=[^&]*//i;
8474 $NewLinkParams =~ tr/&/&/s; $NewLinkParams =~ s/^&//; $NewLinkParams =~ s/&$//;
8475 if ($NewLinkParams) { $NewLinkParams="${NewLinkParams}&"; }
8476 my $NewLinkTarget='';
8477 if ($FrameName eq 'mainright') { $NewLinkTarget=" target=\"_parent\""; }
8478
8479 # Ratio
8480 my $RatioVisits=0; my $RatioPages=0; my $RatioHits=0; my $RatioBytes=0;
8481 if ($TotalUnique > 0) { $RatioVisits=int($TotalVisits/$TotalUnique*100)/100; }
8482 if ($TotalVisits > 0) { $RatioPages=int($TotalPages/$TotalVisits*100)/100; }
8483 if ($TotalVisits > 0) { $RatioHits=int($TotalHits/$TotalVisits*100)/100; }
8484 if ($TotalVisits > 0) { $RatioBytes=int(($TotalBytes/1024)*100/($LogType eq 'M'?$TotalHits:$TotalVisits))/100; }
8485 rizwank 1.1
8486 my $colspan=5;
8487 my $w='20';
8488 if ($LogType eq 'W' || $LogType eq 'S') { $w='17'; $colspan=6; }
8489
8490 # Show first/last
8491 print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
8492 print "<td class=\"aws\"><b>$Message[133]</b></td><td class=\"aws\" colspan=\"".($colspan-1)."\">\n";
8493 print ($MonthRequired eq 'all'?"$Message[6] $YearRequired":"$Message[5] ".$MonthNumLib{$MonthRequired}." $YearRequired");
8494 print "</td></tr>\n";
8495 print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
8496 print "<td class=\"aws\"><b>$Message[8]</b></td>\n";
8497 print "<td class=\"aws\" colspan=\"".($colspan-1)."\">".($FirstTime?Format_Date($FirstTime,0):"NA")."</td>";
8498 print "</tr>\n";
8499 print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
8500 print "<td class=\"aws\"><b>$Message[9]</b></td>\n";
8501 print "<td class=\"aws\" colspan=\"".($colspan-1)."\">".($LastTime?Format_Date($LastTime,0):"NA")."</td>\n";
8502 print "</tr>\n";
8503
8504 # Show main indicators title row
8505 print "<tr>";
8506 rizwank 1.1 if ($LogType eq 'W' || $LogType eq 'S') { print "<td bgcolor=\"#$color_TableBGTitle\"> </td>"; }
8507 if ($ShowMonthStats =~ /U/i) { print "<td width=\"$w%\" bgcolor=\"#$color_u\"".Tooltip(2).">$Message[11]</td>"; } else { print "<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\"> </td>"; }
8508 if ($ShowMonthStats =~ /V/i) { print "<td width=\"$w%\" bgcolor=\"#$color_v\"".Tooltip(1).">$Message[10]</td>"; } else { print "<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\"> </td>"; }
8509 if ($ShowMonthStats =~ /P/i) { print "<td width=\"$w%\" bgcolor=\"#$color_p\"".Tooltip(3).">$Message[56]</td>"; } else { print "<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\"> </td>"; }
8510 if ($ShowMonthStats =~ /H/i) { print "<td width=\"$w%\" bgcolor=\"#$color_h\"".Tooltip(4).">$Message[57]</td>"; } else { print "<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\"> </td>"; }
8511 if ($ShowMonthStats =~ /B/i) { print "<td width=\"$w%\" bgcolor=\"#$color_k\"".Tooltip(5).">$Message[75]</td>"; } else { print "<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\"> </td>"; }
8512 print "</tr>\n";
8513 # Show main indicators values for viewed traffic
8514 print "<tr>";
8515 if ($LogType eq 'M') {
8516 print "<td class=\"aws\">$Message[165]</td>";
8517 print "<td> <br /> </td>\n";
8518 print "<td> <br /> </td>\n";
8519 if ($ShowMonthStats =~ /H/i) { print "<td><b>$TotalHits</b>".($LogType eq 'M'?"":"<br />($RatioHits ".lc($Message[57]."/".$Message[12]).")</td>"); } else { print "<td> </td>"; }
8520 if ($ShowMonthStats =~ /B/i) { print "<td><b>".Format_Bytes(int($TotalBytes))."</b><br />($RatioBytes $Message[108]/".lc($Message[($LogType eq 'M'?149:12)]).")</td>"; } else { print "<td> </td>"; }
8521 }
8522 else {
8523 if ($LogType eq 'W' || $LogType eq 'S') { print "<td class=\"aws\">$Message[160] *</td>"; }
8524 if ($ShowMonthStats =~ /U/i) { print "<td>".($MonthRequired eq 'all'?"<b><= $TotalUnique</b><br />$Message[129]":"<b>$TotalUnique</b><br /> ")."</td>"; } else { print "<td> </td>"; }
8525 if ($ShowMonthStats =~ /V/i) { print "<td><b>$TotalVisits</b><br />($RatioVisits $Message[52])</td>"; } else { print "<td> </td>"; }
8526 if ($ShowMonthStats =~ /P/i) { print "<td><b>$TotalPages</b><br />($RatioPages ".lc($Message[56]."/".$Message[12]).")</td>"; } else { print "<td> </td>"; }
8527 rizwank 1.1 if ($ShowMonthStats =~ /H/i) { print "<td><b>$TotalHits</b>".($LogType eq 'M'?"":"<br />($RatioHits ".lc($Message[57]."/".$Message[12]).")</td>"); } else { print "<td> </td>"; }
8528 if ($ShowMonthStats =~ /B/i) { print "<td><b>".Format_Bytes(int($TotalBytes))."</b><br />($RatioBytes $Message[108]/".lc($Message[($LogType eq 'M'?149:12)]).")</td>"; } else { print "<td> </td>"; }
8529 }
8530 print "</tr>\n";
8531 # Show main indicators values for not viewed traffic values
8532 if ($LogType eq 'M' || $LogType eq 'W' || $LogType eq 'S') {
8533 print "<tr>";
8534 if ($LogType eq 'M') {
8535 print "<td class=\"aws\">$Message[166]</td>";
8536 print "<td> <br /> </td>\n";
8537 print "<td> <br /> </td>\n";
8538 if ($ShowMonthStats =~ /H/i) { print "<td><b>$TotalNotViewedHits</b></td>"; } else { print "<td> </td>"; }
8539 if ($ShowMonthStats =~ /B/i) { print "<td><b>".Format_Bytes(int($TotalNotViewedBytes))."</b></td>"; } else { print "<td> </td>"; }
8540 }
8541 else {
8542 if ($LogType eq 'W' || $LogType eq 'S') { print "<td class=\"aws\">$Message[161] *</td>"; }
8543 print "<td colspan=\"2\"> <br /> </td>\n";
8544 if ($ShowMonthStats =~ /P/i) { print "<td><b>$TotalNotViewedPages</b></td>"; } else { print "<td> </td>"; }
8545 if ($ShowMonthStats =~ /H/i) { print "<td><b>$TotalNotViewedHits</b></td>"; } else { print "<td> </td>"; }
8546 if ($ShowMonthStats =~ /B/i) { print "<td><b>".Format_Bytes(int($TotalNotViewedBytes))."</b></td>"; } else { print "<td> </td>"; }
8547 }
8548 rizwank 1.1 print "</tr>\n";
8549 }
8550 &tab_end($LogType eq 'W' || $LogType eq 'S'?"* $Message[159]":"");
8551 }
8552
8553 # BY MONTH
8554 #---------------------------------------------------------------------
8555 if ($ShowMonthStats) {
8556
8557 if ($Debug) { debug("ShowMonthStats",2); }
8558 print "$Center<a name=\"month\"> </a><br />\n";
8559 my $title="$Message[162]";
8560 &tab_head("$title",0,0,'month');
8561 print "<tr><td align=\"center\">\n";
8562 print "<center>\n";
8563
8564 $average_nb=$average_u=$average_v=$average_p=$average_h=$average_k=0;
8565 $total_u=$total_v=$total_p=$total_h=$total_k=0;
8566
8567 $max_v=$max_p=$max_h=$max_k=1;
8568 # Define total and max
8569 rizwank 1.1 for (my $ix=1; $ix<=12; $ix++) {
8570 my $monthix=sprintf("%02s",$ix);
8571 $total_u+=$MonthUnique{$YearRequired.$monthix}||0;
8572 $total_v+=$MonthVisits{$YearRequired.$monthix}||0;
8573 $total_p+=$MonthPages{$YearRequired.$monthix}||0;
8574 $total_h+=$MonthHits{$YearRequired.$monthix}||0;
8575 $total_k+=$MonthBytes{$YearRequired.$monthix}||0;
8576 #if (($MonthUnique{$YearRequired.$monthix}||0) > $max_v) { $max_v=$MonthUnique{$YearRequired.$monthix}; }
8577 if (($MonthVisits{$YearRequired.$monthix}||0) > $max_v) { $max_v=$MonthVisits{$YearRequired.$monthix}; }
8578 #if (($MonthPages{$YearRequired.$monthix}||0) > $max_p) { $max_p=$MonthPages{$YearRequired.$monthix}; }
8579 if (($MonthHits{$YearRequired.$monthix}||0) > $max_h) { $max_h=$MonthHits{$YearRequired.$monthix}; }
8580 if (($MonthBytes{$YearRequired.$monthix}||0) > $max_k) { $max_k=$MonthBytes{$YearRequired.$monthix}; }
8581 }
8582 # Define average
8583 # TODO
8584
8585 # Show bars for month
8586 if ($PluginsLoaded{'ShowGraph'}{'graphapplet'}) {
8587 my @blocklabel=();
8588 for (my $ix=1; $ix<=12; $ix++) {
8589 my $monthix=sprintf("%02s",$ix);
8590 rizwank 1.1 push @blocklabel,"$MonthNumLib{$monthix}\§$YearRequired";
8591 }
8592 my @vallabel=("$Message[11]","$Message[10]","$Message[56]","$Message[57]","$Message[75]");
8593 my @valcolor=("$color_u","$color_v","$color_p","$color_h","$color_k");
8594 my @valmax=($max_v,$max_v,$max_h,$max_h,$max_k);
8595 my @valtotal=($total_u,$total_v,$total_p,$total_h,$total_k);
8596 my @valaverage=();
8597 #my @valaverage=($average_v,$average_p,$average_h,$average_k);
8598 my @valdata=();
8599 my $xx=0;
8600 for (my $ix=1; $ix<=12; $ix++) {
8601 my $monthix=sprintf("%02s",$ix);
8602 $valdata[$xx++]=$MonthUnique{$YearRequired.$monthix}||0;
8603 $valdata[$xx++]=$MonthVisits{$YearRequired.$monthix}||0;
8604 $valdata[$xx++]=$MonthPages{$YearRequired.$monthix}||0;
8605 $valdata[$xx++]=$MonthHits{$YearRequired.$monthix}||0;
8606 $valdata[$xx++]=$MonthBytes{$YearRequired.$monthix}||0;
8607 }
8608 ShowGraph_graphapplet("$title","month",$ShowMonthStats,\@blocklabel,\@vallabel,\@valcolor,\@valmax,\@valtotal,\@valaverage,\@valdata);
8609 }
8610 else {
8611 rizwank 1.1 print "<table>\n";
8612 print "<tr valign=\"bottom\">";
8613 print "<td> </td>\n";
8614 for (my $ix=1; $ix<=12; $ix++) {
8615 my $monthix=sprintf("%02s",$ix);
8616 my $bredde_u=0; my $bredde_v=0;my $bredde_p=0;my $bredde_h=0;my $bredde_k=0;
8617 if ($max_v > 0) { $bredde_u=int(($MonthUnique{$YearRequired.$monthix}||0)/$max_v*$BarHeight)+1; }
8618 if ($max_v > 0) { $bredde_v=int(($MonthVisits{$YearRequired.$monthix}||0)/$max_v*$BarHeight)+1; }
8619 if ($max_h > 0) { $bredde_p=int(($MonthPages{$YearRequired.$monthix}||0)/$max_h*$BarHeight)+1; }
8620 if ($max_h > 0) { $bredde_h=int(($MonthHits{$YearRequired.$monthix}||0)/$max_h*$BarHeight)+1; }
8621 if ($max_k > 0) { $bredde_k=int(($MonthBytes{$YearRequired.$monthix}||0)/$max_k*$BarHeight)+1; }
8622 print "<td>";
8623 if ($ShowMonthStats =~ /U/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vu'}\" height=\"$bredde_u\" width=\"6\"".AltTitle("$Message[11]: ".($MonthUnique{$YearRequired.$monthix}||0))." />"; }
8624 if ($ShowMonthStats =~ /V/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"6\"".AltTitle("$Message[10]: ".($MonthVisits{$YearRequired.$monthix}||0))." />"; }
8625 if ($QueryString !~ /buildpdf/i) { print " "; }
8626 if ($ShowMonthStats =~ /P/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\"".AltTitle("$Message[56]: ".($MonthPages{$YearRequired.$monthix}||0))." />"; }
8627 if ($ShowMonthStats =~ /H/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\"".AltTitle("$Message[57]: ".($MonthHits{$YearRequired.$monthix}||0))." />"; }
8628 if ($ShowMonthStats =~ /B/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\"".AltTitle("$Message[75]: ".Format_Bytes($MonthBytes{$YearRequired.$monthix}))." />"; }
8629 print "</td>\n";
8630 }
8631 print "<td> </td>";
8632 rizwank 1.1 print "</tr>\n";
8633 # Show lib for month
8634 print "<tr valign=\"middle\">";
8635 # if (!$StaticLinks) {
8636 # print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=12&year=".($YearRequired-1))."\"><<</a></td>";
8637 # }
8638 # else {
8639 print "<td> </td>";
8640 # }
8641 for (my $ix=1; $ix<=12; $ix++) {
8642 my $monthix=sprintf("%02s",$ix);
8643 # if (!$StaticLinks) {
8644 # print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=$monthix&year=$YearRequired")."\">$MonthNumLib{$monthix}<br />$YearRequired</a></td>";
8645 # }
8646 # else {
8647 print "<td>".(! $StaticLinks && $monthix==$nowmonth && $YearRequired==$nowyear?'<font class="currentday">':'');
8648 print "$MonthNumLib{$monthix}<br />$YearRequired";
8649 print (! $StaticLinks && $monthix==$nowmonth && $YearRequired==$nowyear?'</font>':'');
8650 print "</td>";
8651 # }
8652 }
8653 rizwank 1.1 # if (!$StaticLinks) {
8654 # print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=1&year=".($YearRequired+1))."\">>></a></td>";
8655 # }
8656 # else {
8657 print "<td> </td>";
8658 # }
8659 print "</tr>\n";
8660 print "</table>\n";
8661 }
8662 print "<br />\n";
8663
8664 # Show data array for month
8665 if ($AddDataArrayMonthStats) {
8666 print "<table>\n";
8667 print "<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[5]</td>";
8668 if ($ShowMonthStats =~ /U/i) { print "<td width=\"80\" bgcolor=\"#$color_u\"".Tooltip(2).">$Message[11]</td>"; }
8669 if ($ShowMonthStats =~ /V/i) { print "<td width=\"80\" bgcolor=\"#$color_v\"".Tooltip(1).">$Message[10]</td>"; }
8670 if ($ShowMonthStats =~ /P/i) { print "<td width=\"80\" bgcolor=\"#$color_p\"".Tooltip(3).">$Message[56]</td>"; }
8671 if ($ShowMonthStats =~ /H/i) { print "<td width=\"80\" bgcolor=\"#$color_h\"".Tooltip(4).">$Message[57]</td>"; }
8672 if ($ShowMonthStats =~ /B/i) { print "<td width=\"80\" bgcolor=\"#$color_k\"".Tooltip(5).">$Message[75]</td>"; }
8673 print "</tr>\n";
8674 rizwank 1.1 for (my $ix=1; $ix<=12; $ix++) {
8675 my $monthix=sprintf("%02s",$ix);
8676 print "<tr>";
8677 print "<td>".(! $StaticLinks && $monthix==$nowmonth && $YearRequired==$nowyear?'<font class="currentday">':'');
8678 print "$MonthNumLib{$monthix} $YearRequired";
8679 print (! $StaticLinks && $monthix==$nowmonth && $YearRequired==$nowyear?'</font>':'');
8680 print "</td>";
8681 if ($ShowMonthStats =~ /U/i) { print "<td>",$MonthUnique{$YearRequired.$monthix}?$MonthUnique{$YearRequired.$monthix}:"0","</td>"; }
8682 if ($ShowMonthStats =~ /V/i) { print "<td>",$MonthVisits{$YearRequired.$monthix}?$MonthVisits{$YearRequired.$monthix}:"0","</td>"; }
8683 if ($ShowMonthStats =~ /P/i) { print "<td>",$MonthPages{$YearRequired.$monthix}?$MonthPages{$YearRequired.$monthix}:"0","</td>"; }
8684 if ($ShowMonthStats =~ /H/i) { print "<td>",$MonthHits{$YearRequired.$monthix}?$MonthHits{$YearRequired.$monthix}:"0","</td>"; }
8685 if ($ShowMonthStats =~ /B/i) { print "<td>",Format_Bytes(int($MonthBytes{$YearRequired.$monthix}||0)),"</td>"; }
8686 print "</tr>\n";
8687 }
8688 # Average row
8689 # TODO
8690 # Total row
8691 print "<tr><td bgcolor=\"#$color_TableBGRowTitle\">$Message[102]</td>";
8692 if ($ShowMonthStats =~ /U/i) { print "<td bgcolor=\"#$color_TableBGRowTitle\">$total_u</td>"; }
8693 if ($ShowMonthStats =~ /V/i) { print "<td bgcolor=\"#$color_TableBGRowTitle\">$total_v</td>"; }
8694 if ($ShowMonthStats =~ /P/i) { print "<td bgcolor=\"#$color_TableBGRowTitle\">$total_p</td>"; }
8695 rizwank 1.1 if ($ShowMonthStats =~ /H/i) { print "<td bgcolor=\"#$color_TableBGRowTitle\">$total_h</td>"; }
8696 if ($ShowMonthStats =~ /B/i) { print "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Bytes($total_k)."</td>"; }
8697 print "</tr>\n";
8698 print "</table>\n<br />\n";
8699 }
8700
8701 print "</center>\n";
8702 print "</td></tr>\n";
8703 &tab_end();
8704 }
8705
8706 print "\n<a name=\"when\"> </a>\n\n";
8707
8708 # BY DAY OF MONTH
8709 #---------------------------------------------------------------------
8710 if ($ShowDaysOfMonthStats) {
8711 if ($Debug) { debug("ShowDaysOfMonthStats",2); }
8712 print "$Center<a name=\"daysofmonth\"> </a><br />\n";
8713 my $title="$Message[138]";
8714 &tab_head("$title",0,0,'daysofmonth');
8715 print "<tr>";
8716 rizwank 1.1 print "<td align=\"center\">\n";
8717 print "<center>\n";
8718
8719 my $NewLinkParams=${QueryString};
8720 $NewLinkParams =~ s/(^|&)update(=\w*|$)//i;
8721 $NewLinkParams =~ s/(^|&)staticlinks(=\w*|$)//i;
8722 $NewLinkParams =~ s/(^|&)year=[^&]*//i;
8723 $NewLinkParams =~ s/(^|&)month=[^&]*//i;
8724 $NewLinkParams =~ s/(^|&)framename=[^&]*//i;
8725 $NewLinkParams =~ tr/&/&/s; $NewLinkParams =~ s/^&//; $NewLinkParams =~ s/&$//;
8726 if ($NewLinkParams) { $NewLinkParams="${NewLinkParams}&"; }
8727 my $NewLinkTarget='';
8728 if ($FrameName eq 'mainright') { $NewLinkTarget=" target=\"_parent\""; }
8729
8730 $average_nb=$average_u=$average_v=$average_p=$average_h=$average_k=0;
8731 $total_u=$total_v=$total_p=$total_h=$total_k=0;
8732 # Define total and max
8733 $max_v=$max_h=$max_k=0; # Start from 0 because can be lower than 1
8734 foreach my $daycursor ($firstdaytoshowtime..$lastdaytoshowtime) {
8735 $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
8736 my $year=$1; my $month=$2; my $day=$3;
8737 rizwank 1.1 if (! DateIsValid($day,$month,$year)) { next; } # If not an existing day, go to next
8738 $total_v+=$DayVisits{$year.$month.$day}||0;
8739 $total_p+=$DayPages{$year.$month.$day}||0;
8740 $total_h+=$DayHits{$year.$month.$day}||0;
8741 $total_k+=$DayBytes{$year.$month.$day}||0;
8742 if (($DayVisits{$year.$month.$day}||0) > $max_v) { $max_v=$DayVisits{$year.$month.$day}; }
8743 #if (($DayPages{$year.$month.$day}||0) > $max_p) { $max_p=$DayPages{$year.$month.$day}; }
8744 if (($DayHits{$year.$month.$day}||0) > $max_h) { $max_h=$DayHits{$year.$month.$day}; }
8745 if (($DayBytes{$year.$month.$day}||0) > $max_k) { $max_k=$DayBytes{$year.$month.$day}; }
8746 }
8747 # Define average
8748 foreach my $daycursor ($firstdaytocountaverage..$lastdaytocountaverage) {
8749 $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
8750 my $year=$1; my $month=$2; my $day=$3;
8751 if (! DateIsValid($day,$month,$year)) { next; } # If not an existing day, go to next
8752 $average_nb++; # Increase number of day used to count
8753 $average_v+=($DayVisits{$daycursor}||0);
8754 $average_p+=($DayPages{$daycursor}||0);
8755 $average_h+=($DayHits{$daycursor}||0);
8756 $average_k+=($DayBytes{$daycursor}||0);
8757 }
8758 rizwank 1.1 if ($average_nb) {
8759 $average_v=$average_v/$average_nb;
8760 $average_p=$average_p/$average_nb;
8761 $average_h=$average_h/$average_nb;
8762 $average_k=$average_k/$average_nb;
8763 if ($average_v > $max_v) { $max_v=$average_v; }
8764 #if ($average_p > $max_p) { $max_p=$average_p; }
8765 if ($average_h > $max_h) { $max_h=$average_h; }
8766 if ($average_k > $max_k) { $max_k=$average_k; }
8767 }
8768 else {
8769 $average_v="?";
8770 $average_p="?";
8771 $average_h="?";
8772 $average_k="?";
8773 }
8774
8775 # Show bars for day
8776 if ($PluginsLoaded{'ShowGraph'}{'graphapplet'}) {
8777 my @blocklabel=();
8778 foreach my $daycursor ($firstdaytoshowtime..$lastdaytoshowtime) {
8779 rizwank 1.1 $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
8780 my $year=$1; my $month=$2; my $day=$3;
8781 if (! DateIsValid($day,$month,$year)) { next; } # If not an existing day, go to next
8782 my $bold=($day==$nowday && $month==$nowmonth && $year==$nowyear?':':'');
8783 my $weekend=(DayOfWeek($day,$month,$year)=~/[06]/?'!':'');
8784 push @blocklabel,"$day§$MonthNumLib{$month}$weekend$bold";
8785 }
8786 my @vallabel=("$Message[10]","$Message[56]","$Message[57]","$Message[75]");
8787 my @valcolor=("$color_v","$color_p","$color_h","$color_k");
8788 my @valmax=($max_v,$max_h,$max_h,$max_k);
8789 my @valtotal=($total_v,$total_p,$total_h,$total_k);
8790 $average_v=sprintf("%.2f",$average_v);
8791 $average_p=sprintf("%.2f",$average_p);
8792 $average_h=sprintf("%.2f",$average_h);
8793 $average_k=(int($average_k)?Format_Bytes(sprintf("%.2f",$average_k)):"0.00");
8794 my @valaverage=($average_v,$average_p,$average_h,$average_k);
8795 my @valdata=();
8796 my $xx=0;
8797 foreach my $daycursor ($firstdaytoshowtime..$lastdaytoshowtime) {
8798 $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
8799 my $year=$1; my $month=$2; my $day=$3;
8800 rizwank 1.1 if (! DateIsValid($day,$month,$year)) { next; } # If not an existing day, go to next
8801 $valdata[$xx++]=$DayVisits{$year.$month.$day}||0;
8802 $valdata[$xx++]=$DayPages{$year.$month.$day}||0;
8803 $valdata[$xx++]=$DayHits{$year.$month.$day}||0;
8804 $valdata[$xx++]=$DayBytes{$year.$month.$day}||0;
8805 }
8806 ShowGraph_graphapplet("$title","daysofmonth",$ShowDaysOfMonthStats,\@blocklabel,\@vallabel,\@valcolor,\@valmax,\@valtotal,\@valaverage,\@valdata);
8807 }
8808 else {
8809 print "<table>\n";
8810 print "<tr valign=\"bottom\">\n";
8811 foreach my $daycursor ($firstdaytoshowtime..$lastdaytoshowtime) {
8812 $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
8813 my $year=$1; my $month=$2; my $day=$3;
8814 if (! DateIsValid($day,$month,$year)) { next; } # If not an existing day, go to next
8815 my $bredde_v=0; my $bredde_p=0; my $bredde_h=0; my $bredde_k=0;
8816 if ($max_v > 0) { $bredde_v=int(($DayVisits{$year.$month.$day}||0)/$max_v*$BarHeight)+1; }
8817 if ($max_h > 0) { $bredde_p=int(($DayPages{$year.$month.$day}||0)/$max_h*$BarHeight)+1; }
8818 if ($max_h > 0) { $bredde_h=int(($DayHits{$year.$month.$day}||0)/$max_h*$BarHeight)+1; }
8819 if ($max_k > 0) { $bredde_k=int(($DayBytes{$year.$month.$day}||0)/$max_k*$BarHeight)+1; }
8820 print "<td>";
8821 rizwank 1.1 if ($ShowDaysOfMonthStats =~ /V/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"4\"".AltTitle("$Message[10]: ".int($DayVisits{$year.$month.$day}||0))." />"; }
8822 if ($ShowDaysOfMonthStats =~ /P/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"4\"".AltTitle("$Message[56]: ".int($DayPages{$year.$month.$day}||0))." />"; }
8823 if ($ShowDaysOfMonthStats =~ /H/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"4\"".AltTitle("$Message[57]: ".int($DayHits{$year.$month.$day}||0))." />"; }
8824 if ($ShowDaysOfMonthStats =~ /B/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"4\"".AltTitle("$Message[75]: ".Format_Bytes($DayBytes{$year.$month.$day}))." />"; }
8825 print "</td>\n";
8826 }
8827 print "<td> </td>";
8828 # Show average value cell
8829 print "<td>";
8830 my $bredde_v=0; my $bredde_p=0; my $bredde_h=0; my $bredde_k=0;
8831 if ($max_v > 0) { $bredde_v=int($average_v/$max_v*$BarHeight)+1; }
8832 if ($max_h > 0) { $bredde_p=int($average_p/$max_h*$BarHeight)+1; }
8833 if ($max_h > 0) { $bredde_h=int($average_h/$max_h*$BarHeight)+1; }
8834 if ($max_k > 0) { $bredde_k=int($average_k/$max_k*$BarHeight)+1; }
8835 $average_v=sprintf("%.2f",$average_v);
8836 $average_p=sprintf("%.2f",$average_p);
8837 $average_h=sprintf("%.2f",$average_h);
8838 $average_k=(int($average_k)?Format_Bytes(sprintf("%.2f",$average_k)):"0.00");
8839 if ($ShowDaysOfMonthStats =~ /V/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"4\"".AltTitle("$Message[10]: $average_v")." />"; }
8840 if ($ShowDaysOfMonthStats =~ /P/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"4\"".AltTitle("$Message[56]: $average_p")." />"; }
8841 if ($ShowDaysOfMonthStats =~ /H/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"4\"".AltTitle("$Message[57]: $average_h")." />"; }
8842 rizwank 1.1 if ($ShowDaysOfMonthStats =~ /B/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"4\"".AltTitle("$Message[75]: $average_k")." />"; }
8843 print "</td>\n";
8844 print "</tr>\n";
8845 # Show lib for day
8846 print "<tr valign=\"middle\">";
8847 foreach my $daycursor ($firstdaytoshowtime..$lastdaytoshowtime) {
8848 $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
8849 my $year=$1; my $month=$2; my $day=$3;
8850 if (! DateIsValid($day,$month,$year)) { next; } # If not an existing day, go to next
8851 my $dayofweekcursor=DayOfWeek($day,$month,$year);
8852 print "<td".($dayofweekcursor=~/[06]/?" bgcolor=\"#$color_weekend\"":"").">";
8853 print (! $StaticLinks && $day==$nowday && $month==$nowmonth && $year==$nowyear?'<font class="currentday">':'');
8854 print "$day<br /><span style=\"font-size: ".($FrameName ne 'mainright' && $QueryString !~ /buildpdf/i?"9":"8")."px;\">".$MonthNumLib{$month}."</span>";
8855 print (! $StaticLinks && $day==$nowday && $month==$nowmonth && $year==$nowyear?'</font>':'');
8856 print "</td>\n";
8857 }
8858 print "<td> </td>";
8859 print "<td valign=\"middle\"".Tooltip(18).">$Message[96]</td>\n";
8860 print "</tr>\n";
8861 print "</table>\n";
8862 }
8863 rizwank 1.1 print "<br />\n";
8864
8865 # Show data array for days
8866 if ($AddDataArrayShowDaysOfMonthStats) {
8867 print "<table>\n";
8868 print "<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[4]</td>";
8869 if ($ShowDaysOfMonthStats =~ /V/i) { print "<td width=\"80\" bgcolor=\"#$color_v\"".Tooltip(1).">$Message[10]</td>"; }
8870 if ($ShowDaysOfMonthStats =~ /P/i) { print "<td width=\"80\" bgcolor=\"#$color_p\"".Tooltip(3).">$Message[56]</td>"; }
8871 if ($ShowDaysOfMonthStats =~ /H/i) { print "<td width=\"80\" bgcolor=\"#$color_h\"".Tooltip(4).">$Message[57]</td>"; }
8872 if ($ShowDaysOfMonthStats =~ /B/i) { print "<td width=\"80\" bgcolor=\"#$color_k\"".Tooltip(5).">$Message[75]</td>"; }
8873 print "</tr>";
8874 foreach my $daycursor ($firstdaytoshowtime..$lastdaytoshowtime) {
8875 $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
8876 my $year=$1; my $month=$2; my $day=$3;
8877 if (! DateIsValid($day,$month,$year)) { next; } # If not an existing day, go to next
8878 my $dayofweekcursor=DayOfWeek($day,$month,$year);
8879 print "<tr".($dayofweekcursor=~/[06]/?" bgcolor=\"#$color_weekend\"":"").">";
8880 print "<td>".(! $StaticLinks && $day==$nowday && $month==$nowmonth && $year==$nowyear?'<font class="currentday">':'');
8881 print Format_Date("$year$month$day"."000000",2);
8882 print (! $StaticLinks && $day==$nowday && $month==$nowmonth && $year==$nowyear?'</font>':'');
8883 print "</td>";
8884 rizwank 1.1 if ($ShowDaysOfMonthStats =~ /V/i) { print "<td>",$DayVisits{$year.$month.$day}?$DayVisits{$year.$month.$day}:"0","</td>"; }
8885 if ($ShowDaysOfMonthStats =~ /P/i) { print "<td>",$DayPages{$year.$month.$day}?$DayPages{$year.$month.$day}:"0","</td>"; }
8886 if ($ShowDaysOfMonthStats =~ /H/i) { print "<td>",$DayHits{$year.$month.$day}?$DayHits{$year.$month.$day}:"0","</td>"; }
8887 if ($ShowDaysOfMonthStats =~ /B/i) { print "<td>",Format_Bytes(int($DayBytes{$year.$month.$day}||0)),"</td>"; }
8888 print "</tr>\n";
8889 }
8890 # Average row
8891 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><td>$Message[96]</td>";
8892 if ($ShowDaysOfMonthStats =~ /V/i) { print "<td>$average_v</td>"; }
8893 if ($ShowDaysOfMonthStats =~ /P/i) { print "<td>$average_p</td>"; }
8894 if ($ShowDaysOfMonthStats =~ /H/i) { print "<td>$average_h</td>"; }
8895 if ($ShowDaysOfMonthStats =~ /B/i) { print "<td>$average_k</td>"; }
8896 print "</tr>\n";
8897 # Total row
8898 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><td>$Message[102]</td>";
8899 if ($ShowDaysOfMonthStats =~ /V/i) { print "<td>$total_v</td>"; }
8900 if ($ShowDaysOfMonthStats =~ /P/i) { print "<td>$total_p</td>"; }
8901 if ($ShowDaysOfMonthStats =~ /H/i) { print "<td>$total_h</td>"; }
8902 if ($ShowDaysOfMonthStats =~ /B/i) { print "<td>".Format_Bytes($total_k)."</td>"; }
8903 print "</tr>\n";
8904 print "</table>\n<br />";
8905 rizwank 1.1 }
8906
8907 print "</center>\n";
8908 print "</td></tr>\n";
8909 &tab_end();
8910 }
8911
8912 # BY DAY OF WEEK
8913 #-------------------------
8914 if ($ShowDaysOfWeekStats) {
8915 if ($Debug) { debug("ShowDaysOfWeekStats",2); }
8916 print "$Center<a name=\"daysofweek\"> </a><br />\n";
8917 my $title="$Message[91]";
8918 &tab_head("$title",18,0,'daysofweek');
8919 print "<tr>";
8920 print "<td align=\"center\">";
8921 print "<center>\n";
8922
8923 $max_h=$max_k=0; # Start from 0 because can be lower than 1
8924 # Get average value for day of week
8925 my @avg_dayofweek_nb=(); my @avg_dayofweek_p=(); my @avg_dayofweek_h=(); my @avg_dayofweek_k=();
8926 rizwank 1.1 foreach my $daycursor ($firstdaytocountaverage..$lastdaytocountaverage) {
8927 $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
8928 my $year=$1; my $month=$2; my $day=$3;
8929 if (! DateIsValid($day,$month,$year)) { next; } # If not an existing day, go to next
8930 my $dayofweekcursor=DayOfWeek($day,$month,$year);
8931 $avg_dayofweek_nb[$dayofweekcursor]++; # Increase number of day used to count for this day of week
8932 $avg_dayofweek_p[$dayofweekcursor]+=($DayPages{$daycursor}||0);
8933 $avg_dayofweek_h[$dayofweekcursor]+=($DayHits{$daycursor}||0);
8934 $avg_dayofweek_k[$dayofweekcursor]+=($DayBytes{$daycursor}||0);
8935 }
8936 for (@DOWIndex) {
8937 if ($avg_dayofweek_nb[$_]) {
8938 $avg_dayofweek_p[$_]=$avg_dayofweek_p[$_]/$avg_dayofweek_nb[$_];
8939 $avg_dayofweek_h[$_]=$avg_dayofweek_h[$_]/$avg_dayofweek_nb[$_];
8940 $avg_dayofweek_k[$_]=$avg_dayofweek_k[$_]/$avg_dayofweek_nb[$_];
8941 #if ($avg_dayofweek_p[$_] > $max_p) { $max_p = $avg_dayofweek_p[$_]; }
8942 if ($avg_dayofweek_h[$_] > $max_h) { $max_h = $avg_dayofweek_h[$_]; }
8943 if ($avg_dayofweek_k[$_] > $max_k) { $max_k = $avg_dayofweek_k[$_]; }
8944 }
8945 else {
8946 $avg_dayofweek_p[$_]="?";
8947 rizwank 1.1 $avg_dayofweek_h[$_]="?";
8948 $avg_dayofweek_k[$_]="?";
8949 }
8950 }
8951
8952 # Show bars for days of week
8953 if ($PluginsLoaded{'ShowGraph'}{'graphapplet'}) {
8954 my @blocklabel=();
8955 for (@DOWIndex) { push @blocklabel,($Message[$_+84].($_=~/[06]/?"!":"")); }
8956 my @vallabel=("$Message[56]","$Message[57]","$Message[75]");
8957 my @valcolor=("$color_p","$color_h","$color_k");
8958 my @valmax=(int($max_h),int($max_h),int($max_k));
8959 my @valtotal=($total_p,$total_h,$total_k);
8960 $average_p=sprintf("%.2f",$average_p);
8961 $average_h=sprintf("%.2f",$average_h);
8962 $average_k=(int($average_k)?Format_Bytes(sprintf("%.2f",$average_k)):"0.00");
8963 my @valaverage=($average_p,$average_h,$average_k);
8964 my @valdata=();
8965 my $xx=0;
8966 for (@DOWIndex) {
8967 $valdata[$xx++]=$avg_dayofweek_p[$_]||0;
8968 rizwank 1.1 $valdata[$xx++]=$avg_dayofweek_h[$_]||0;
8969 $valdata[$xx++]=$avg_dayofweek_k[$_]||0;
8970 # Round to be ready to show array
8971 $avg_dayofweek_p[$_]=sprintf("%.2f",$avg_dayofweek_p[$_]);
8972 $avg_dayofweek_h[$_]=sprintf("%.2f",$avg_dayofweek_h[$_]);
8973 $avg_dayofweek_k[$_]=sprintf("%.2f",$avg_dayofweek_k[$_]);
8974 # Remove decimal part that are .0
8975 if ($avg_dayofweek_p[$_] == int($avg_dayofweek_p[$_])) { $avg_dayofweek_p[$_]=int($avg_dayofweek_p[$_]); }
8976 if ($avg_dayofweek_h[$_] == int($avg_dayofweek_h[$_])) { $avg_dayofweek_h[$_]=int($avg_dayofweek_h[$_]); }
8977 }
8978 ShowGraph_graphapplet("$title","daysofweek",$ShowDaysOfWeekStats,\@blocklabel,\@vallabel,\@valcolor,\@valmax,\@valtotal,\@valaverage,\@valdata);
8979 }
8980 else {
8981 print "<table>\n";
8982 print "<tr valign=\"bottom\">\n";
8983 for (@DOWIndex) {
8984 my $bredde_p=0; my $bredde_h=0; my $bredde_k=0;
8985 if ($max_h > 0) { $bredde_p=int($avg_dayofweek_p[$_]/$max_h*$BarHeight)+1; }
8986 if ($max_h > 0) { $bredde_h=int($avg_dayofweek_h[$_]/$max_h*$BarHeight)+1; }
8987 if ($max_k > 0) { $bredde_k=int($avg_dayofweek_k[$_]/$max_k*$BarHeight)+1; }
8988 $avg_dayofweek_p[$_]=sprintf("%.2f",$avg_dayofweek_p[$_]);
8989 rizwank 1.1 $avg_dayofweek_h[$_]=sprintf("%.2f",$avg_dayofweek_h[$_]);
8990 $avg_dayofweek_k[$_]=sprintf("%.2f",$avg_dayofweek_k[$_]);
8991 # Remove decimal part that are .0
8992 if ($avg_dayofweek_p[$_] == int($avg_dayofweek_p[$_])) { $avg_dayofweek_p[$_]=int($avg_dayofweek_p[$_]); }
8993 if ($avg_dayofweek_h[$_] == int($avg_dayofweek_h[$_])) { $avg_dayofweek_h[$_]=int($avg_dayofweek_h[$_]); }
8994 print "<td valign=\"bottom\">";
8995 if ($ShowDaysOfWeekStats =~ /P/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\"".AltTitle("$Message[56]: $avg_dayofweek_p[$_]")." />"; }
8996 if ($ShowDaysOfWeekStats =~ /H/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\"".AltTitle("$Message[57]: $avg_dayofweek_h[$_]")." />"; }
8997 if ($ShowDaysOfWeekStats =~ /B/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\"".AltTitle("$Message[75]: ".Format_Bytes($avg_dayofweek_k[$_]))." />"; }
8998 print "</td>\n";
8999 }
9000 print "</tr>\n";
9001 print "<tr".Tooltip(17).">\n";
9002 for (@DOWIndex) {
9003 print "<td".($_=~/[06]/?" bgcolor=\"#$color_weekend\"":"").">".(! $StaticLinks && $_==($nowwday-1) && $MonthRequired==$nowmonth && $YearRequired==$nowyear?'<font class="currentday">':'');
9004 print $Message[$_+84];
9005 print (! $StaticLinks && $_==($nowwday-1) && $MonthRequired==$nowmonth && $YearRequired==$nowyear?'</font>':'');
9006 print "</td>";
9007 }
9008 print "</tr>\n</table>\n";
9009 }
9010 rizwank 1.1 print "<br />\n";
9011
9012 # Show data array for days of week
9013 if ($AddDataArrayShowDaysOfWeekStats) {
9014 print "<table>\n";
9015 print "<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[4]</td>";
9016 if ($ShowDaysOfWeekStats =~ /P/i) { print "<td width=\"80\" bgcolor=\"#$color_p\"".Tooltip(3).">$Message[56]</td>"; }
9017 if ($ShowDaysOfWeekStats =~ /H/i) { print "<td width=\"80\" bgcolor=\"#$color_h\"".Tooltip(4).">$Message[57]</td>"; }
9018 if ($ShowDaysOfWeekStats =~ /B/i) { print "<td width=\"80\" bgcolor=\"#$color_k\"".Tooltip(5).">$Message[75]</td></tr>"; }
9019 for (@DOWIndex) {
9020 print "<tr".($_=~/[06]/?" bgcolor=\"#$color_weekend\"":"").">";
9021 print "<td>".(! $StaticLinks && $_==($nowwday-1) && $MonthRequired==$nowmonth && $YearRequired==$nowyear?'<font class="currentday">':'');
9022 print $Message[$_+84];
9023 print (! $StaticLinks && $_==($nowwday-1) && $MonthRequired==$nowmonth && $YearRequired==$nowyear?'</font>':'');
9024 print "</td>";
9025 if ($ShowDaysOfWeekStats =~ /P/i) { print "<td>",$avg_dayofweek_p[$_],"</td>"; }
9026 if ($ShowDaysOfWeekStats =~ /H/i) { print "<td>",$avg_dayofweek_h[$_],"</td>"; }
9027 if ($ShowDaysOfWeekStats =~ /B/i) { print "<td>",Format_Bytes($avg_dayofweek_k[$_]),"</td>"; }
9028 print "</tr>\n";
9029 }
9030 print "</table>\n<br />\n";
9031 rizwank 1.1 }
9032
9033 print "</center></td>";
9034 print "</tr>\n";
9035 &tab_end();
9036 }
9037
9038 # BY HOUR
9039 #----------------------------
9040 if ($ShowHoursStats) {
9041 if ($Debug) { debug("ShowHoursStats",2); }
9042 print "$Center<a name=\"hours\"> </a><br />\n";
9043 my $title="$Message[20]";
9044 if ($PluginsLoaded{'GetTimeZoneTitle'}{'timezone'}) { $title.=" (GMT ".(GetTimeZoneTitle_timezone()>=0?"+":"").int(GetTimeZoneTitle_timezone()).")"; }
9045 &tab_head("$title",19,0,'hours');
9046 print "<tr><td align=\"center\">\n";
9047 print "<center>\n";
9048
9049 $max_h=$max_k=1;
9050 for (my $ix=0; $ix<=23; $ix++) {
9051 #if ($_time_p[$ix]>$max_p) { $max_p=$_time_p[$ix]; }
9052 rizwank 1.1 if ($_time_h[$ix]>$max_h) { $max_h=$_time_h[$ix]; }
9053 if ($_time_k[$ix]>$max_k) { $max_k=$_time_k[$ix]; }
9054 }
9055
9056 # Show bars for hour
9057 if ($PluginsLoaded{'ShowGraph'}{'graphapplet'}) {
9058 my @blocklabel=(0..23);
9059 my @vallabel=("$Message[56]","$Message[57]","$Message[75]");
9060 my @valcolor=("$color_p","$color_h","$color_k");
9061 my @valmax=(int($max_h),int($max_h),int($max_k));
9062 my @valtotal=($total_p,$total_h,$total_k);
9063 my @valaverage=($average_p,$average_h,$average_k);
9064 my @valdata=();
9065 my $xx=0;
9066 for (0..23) {
9067 $valdata[$xx++]=$_time_p[$_]||0;
9068 $valdata[$xx++]=$_time_h[$_]||0;
9069 $valdata[$xx++]=$_time_k[$_]||0;
9070 }
9071 ShowGraph_graphapplet("$title","hours",$ShowHoursStats,\@blocklabel,\@vallabel,\@valcolor,\@valmax,\@valtotal,\@valaverage,\@valdata);
9072 }
9073 rizwank 1.1 else {
9074 print "<table>\n";
9075 print "<tr valign=\"bottom\">\n";
9076 for (my $ix=0; $ix<=23; $ix++) {
9077 my $bredde_p=0;my $bredde_h=0;my $bredde_k=0;
9078 if ($max_h > 0) { $bredde_p=int($BarHeight*$_time_p[$ix]/$max_h)+1; }
9079 if ($max_h > 0) { $bredde_h=int($BarHeight*$_time_h[$ix]/$max_h)+1; }
9080 if ($max_k > 0) { $bredde_k=int($BarHeight*$_time_k[$ix]/$max_k)+1; }
9081 print "<td>";
9082 if ($ShowHoursStats =~ /P/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\"".AltTitle("$Message[56]: ".int($_time_p[$ix]))." />"; }
9083 if ($ShowHoursStats =~ /H/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\"".AltTitle("$Message[57]: ".int($_time_h[$ix]))." />"; }
9084 if ($ShowHoursStats =~ /B/i) { print "<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\"".AltTitle("$Message[75]: ".Format_Bytes($_time_k[$ix]))." />"; }
9085 print "</td>\n";
9086 }
9087 print "</tr>\n";
9088 # Show hour lib
9089 print "<tr".Tooltip(17).">";
9090 for (my $ix=0; $ix<=23; $ix++) {
9091 print "<th width=\"19\">$ix</th>\n"; # width=19 instead of 18 to avoid a MacOS browser bug.
9092 }
9093 print "</tr>\n";
9094 rizwank 1.1 # Show clock icon
9095 print "<tr".Tooltip(17).">\n";
9096 for (my $ix=0; $ix<=23; $ix++) {
9097 my $hrs=($ix>=12?$ix-12:$ix);
9098 my $hre=($ix>=12?$ix-11:$ix+1);
9099 my $apm=($ix>=12?"pm":"am");
9100 print "<td><img src=\"$DirIcons\/clock\/hr$hre.png\" width=\"10\" alt=\"$hrs:00 - $hre:00 $apm\" /></td>\n";
9101 }
9102 print "</tr>\n";
9103 print "</table>\n";
9104 }
9105 print "<br />\n";
9106
9107 # Show data array for hours
9108 if ($AddDataArrayShowHoursStats) {
9109 print "<table width=\"650\"><tr>\n";
9110 print "<td align=\"center\"><center>\n";
9111
9112 print "<table>\n";
9113 print "<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[20]</td>";
9114 if ($ShowHoursStats =~ /P/i) { print "<td width=\"80\" bgcolor=\"#$color_p\"".Tooltip(3).">$Message[56]</td>"; }
9115 rizwank 1.1 if ($ShowHoursStats =~ /H/i) { print "<td width=\"80\" bgcolor=\"#$color_h\"".Tooltip(4).">$Message[57]</td>"; }
9116 if ($ShowHoursStats =~ /B/i) { print "<td width=\"80\" bgcolor=\"#$color_k\"".Tooltip(5).">$Message[75]</td>"; }
9117 print "</tr>";
9118 for (my $ix=0; $ix<=11; $ix++) {
9119 my $monthix=($ix<10?"0$ix":"$ix");
9120 print "<tr>";
9121 print "<td>$monthix</td>";
9122 if ($ShowHoursStats =~ /P/i) { print "<td>",$_time_p[$monthix]?$_time_p[$monthix]:"0","</td>"; }
9123 if ($ShowHoursStats =~ /H/i) { print "<td>",$_time_h[$monthix]?$_time_h[$monthix]:"0","</td>"; }
9124 if ($ShowHoursStats =~ /B/i) { print "<td>",Format_Bytes(int($_time_k[$monthix])),"</td>"; }
9125 print "</tr>\n";
9126 }
9127 print "</table>\n";
9128
9129 print "</center></td>";
9130 print "<td width=\"10\"> </td>";
9131 print "<td align=\"center\"><center>\n";
9132
9133 print "<table>\n";
9134 print "<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[20]</td>";
9135 if ($ShowHoursStats =~ /P/i) { print "<td width=\"80\" bgcolor=\"#$color_p\"".Tooltip(3).">$Message[56]</td>"; }
9136 rizwank 1.1 if ($ShowHoursStats =~ /H/i) { print "<td width=\"80\" bgcolor=\"#$color_h\"".Tooltip(4).">$Message[57]</td>"; }
9137 if ($ShowHoursStats =~ /B/i) { print "<td width=\"80\" bgcolor=\"#$color_k\"".Tooltip(5).">$Message[75]</td>"; }
9138 print "</tr>\n";
9139 for (my $ix=12; $ix<=23; $ix++) {
9140 my $monthix=($ix<10?"0$ix":"$ix");
9141 print "<tr>";
9142 print "<td>$monthix</td>";
9143 if ($ShowHoursStats =~ /P/i) { print "<td>",$_time_p[$monthix]?$_time_p[$monthix]:"0","</td>"; }
9144 if ($ShowHoursStats =~ /H/i) { print "<td>",$_time_h[$monthix]?$_time_h[$monthix]:"0","</td>"; }
9145 if ($ShowHoursStats =~ /B/i) { print "<td>",Format_Bytes(int($_time_k[$monthix])),"</td>"; }
9146 print "</tr>\n";
9147 }
9148 print "</table>\n";
9149
9150 print "</center></td></tr></table>\n";
9151 print "<br />\n";
9152 }
9153
9154 print "</center></td></tr>\n";
9155 &tab_end();
9156 }
9157 rizwank 1.1
9158 print "\n<a name=\"who\"> </a>\n\n";
9159
9160 # BY COUNTRY/DOMAIN
9161 #---------------------------
9162 if ($ShowDomainsStats) {
9163 if ($Debug) { debug("ShowDomainsStats",2); }
9164 print "$Center<a name=\"countries\"> </a><br />\n";
9165 my $title="$Message[25] ($Message[77] $MaxNbOf{'Domain'}) - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=alldomains"):"$PROG$StaticLinks.alldomains.$StaticExt")."\"$NewLinkTarget>$Message[80]</a>";
9166 &tab_head("$title",19,0,'countries');
9167 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\"> </th><th colspan=\"2\">$Message[17]</th>";
9168 if ($ShowDomainsStats =~ /P/i) { print "<th bgcolor=\"#$color_p\" width=\"80\"".Tooltip(3).">$Message[56]</th>"; }
9169 if ($ShowDomainsStats =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\"".Tooltip(4).">$Message[57]</th>"; }
9170 if ($ShowDomainsStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\"".Tooltip(5).">$Message[75]</th>"; }
9171 print "<th> </th>";
9172 print "</tr>\n";
9173 $total_p=$total_h=$total_k=0;
9174 $max_h=1; foreach (values %_domener_h) { if ($_ > $max_h) { $max_h = $_; } }
9175 $max_k=1; foreach (values %_domener_k) { if ($_ > $max_k) { $max_k = $_; } }
9176 my $count=0;
9177 &BuildKeyList($MaxNbOf{'Domain'},$MinHit{'Domain'},\%_domener_h,\%_domener_p);
9178 rizwank 1.1 foreach my $key (@keylist) {
9179 my $bredde_p=0;my $bredde_h=0;my $bredde_k=0;
9180 if ($max_h > 0) { $bredde_p=int($BarWidth*$_domener_p{$key}/$max_h)+1; } # use max_h to enable to compare pages with hits
9181 if ($_domener_p{$key} && $bredde_p==1) { $bredde_p=2; }
9182 if ($max_h > 0) { $bredde_h=int($BarWidth*$_domener_h{$key}/$max_h)+1; }
9183 if ($_domener_h{$key} && $bredde_h==1) { $bredde_h=2; }
9184 if ($max_k > 0) { $bredde_k=int($BarWidth*($_domener_k{$key}||0)/$max_k)+1; }
9185 if ($_domener_k{$key} && $bredde_k==1) { $bredde_k=2; }
9186 my $newkey=lc($key);
9187 if ($newkey eq 'ip' || ! $DomainsHashIDLib{$newkey}) {
9188 print "<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/ip.png\" height=\"14\"".AltTitle("$Message[0]")." /></td><td class=\"aws\">$Message[0]</td><td>$newkey</td>";
9189 }
9190 else {
9191 print "<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/$newkey.png\" height=\"14\"".AltTitle("$newkey")." /></td><td class=\"aws\">$DomainsHashIDLib{$newkey}</td><td>$newkey</td>";
9192 }
9193 if ($ShowDomainsStats =~ /P/i) { print "<td>".($_domener_p{$key}?$_domener_p{$key}:' ')."</td>"; }
9194 if ($ShowDomainsStats =~ /H/i) { print "<td>$_domener_h{$key}</td>"; }
9195 if ($ShowDomainsStats =~ /B/i) { print "<td>".Format_Bytes($_domener_k{$key})."</td>"; }
9196 print "<td class=\"aws\">";
9197 if ($ShowDomainsStats =~ /P/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"5\"".AltTitle("")." /><br />\n"; }
9198 if ($ShowDomainsStats =~ /H/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\"".AltTitle("")." /><br />\n"; }
9199 rizwank 1.1 if ($ShowDomainsStats =~ /B/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"5\"".AltTitle("")." />"; }
9200 print "</td>";
9201 print "</tr>\n";
9202 $total_p += $_domener_p{$key};
9203 $total_h += $_domener_h{$key};
9204 $total_k += $_domener_k{$key}||0;
9205 $count++;
9206 }
9207 $rest_p=$TotalPages-$total_p;
9208 $rest_h=$TotalHits-$total_h;
9209 $rest_k=$TotalBytes-$total_k;
9210 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other domains (known or not)
9211 print "<tr><td width=\"$WIDTHCOLICON\"> </td><td colspan=\"2\" class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
9212 if ($ShowDomainsStats =~ /P/i) { print "<td>$rest_p</td>"; }
9213 if ($ShowDomainsStats =~ /H/i) { print "<td>$rest_h</td>"; }
9214 if ($ShowDomainsStats =~ /B/i) { print "<td>".Format_Bytes($rest_k)."</td>"; }
9215 print "<td class=\"aws\"> </td>";
9216 print "</tr>\n";
9217 }
9218 &tab_end();
9219 }
9220 rizwank 1.1
9221 # BY HOST/VISITOR
9222 #--------------------------
9223 if ($ShowHostsStats) {
9224 if ($Debug) { debug("ShowHostsStats",2); }
9225 print "$Center<a name=\"visitors\"> </a><br />\n";
9226 my $title="$Message[81] ($Message[77] $MaxNbOf{'HostsShown'}) - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=allhosts"):"$PROG$StaticLinks.allhosts.$StaticExt")."\"$NewLinkTarget>$Message[80]</a> - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=lasthosts"):"$PROG$StaticLinks.lasthosts.$StaticExt")."\"$NewLinkTarget>$Message[9]</a> - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=unknownip"):"$PROG$StaticLinks.unknownip.$StaticExt")."\"$NewLinkTarget>$Message[45]</a>";
9227 &tab_head("$title",19,0,'visitors');
9228 print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
9229 print "<th>";
9230 if ($MonthRequired ne 'all') { print "$Message[81] : $TotalHostsKnown $Message[82], $TotalHostsUnknown $Message[1]<br />$TotalUnique $Message[11]</th>"; }
9231 else { print "$Message[81] : ".(scalar keys %_host_h)."</th>"; }
9232 &ShowHostInfo('__title__');
9233 if ($ShowHostsStats =~ /P/i) { print "<th bgcolor=\"#$color_p\" width=\"80\"".Tooltip(3).">$Message[56]</th>"; }
9234 if ($ShowHostsStats =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\"".Tooltip(4).">$Message[57]</th>"; }
9235 if ($ShowHostsStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\"".Tooltip(5).">$Message[75]</th>"; }
9236 if ($ShowHostsStats =~ /L/i) { print "<th width=\"120\">$Message[9]</th>"; }
9237 print "</tr>\n";
9238 $total_p=$total_h=$total_k=0;
9239 my $count=0;
9240 &BuildKeyList($MaxNbOf{'HostsShown'},$MinHit{'Host'},\%_host_h,\%_host_p);
9241 rizwank 1.1 foreach my $key (@keylist) {
9242 print "<tr>";
9243 print "<td class=\"aws\">$key</td>";
9244 &ShowHostInfo($key);
9245 if ($ShowHostsStats =~ /P/i) { print "<td>".($_host_p{$key}||" ")."</td>"; }
9246 if ($ShowHostsStats =~ /H/i) { print "<td>$_host_h{$key}</td>"; }
9247 if ($ShowHostsStats =~ /B/i) { print "<td>".Format_Bytes($_host_k{$key})."</td>"; }
9248 if ($ShowHostsStats =~ /L/i) { print "<td>".($_host_l{$key}?Format_Date($_host_l{$key},1):'-')."</td>"; }
9249 print "</tr>\n";
9250 $total_p += $_host_p{$key};
9251 $total_h += $_host_h{$key};
9252 $total_k += $_host_k{$key}||0;
9253 $count++;
9254 }
9255 $rest_p=$TotalPages-$total_p;
9256 $rest_h=$TotalHits-$total_h;
9257 $rest_k=$TotalBytes-$total_k;
9258 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other visitors (known or not)
9259 print "<tr>";
9260 print "<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
9261 &ShowHostInfo('');
9262 rizwank 1.1 if ($ShowHostsStats =~ /P/i) { print "<td>$rest_p</td>"; }
9263 if ($ShowHostsStats =~ /H/i) { print "<td>$rest_h</td>"; }
9264 if ($ShowHostsStats =~ /B/i) { print "<td>".Format_Bytes($rest_k)."</td>"; }
9265 if ($ShowHostsStats =~ /L/i) { print "<td> </td>"; }
9266 print "</tr>\n";
9267 }
9268 &tab_end();
9269 }
9270
9271 # BY SENDER EMAIL
9272 #----------------------------
9273 if ($ShowEMailSenders) {
9274 &ShowEmailSendersChart($NewLinkParams,$NewLinkTarget);
9275 }
9276
9277 # BY RECEIVER EMAIL
9278 #----------------------------
9279 if ($ShowEMailReceivers) {
9280 &ShowEmailReceiversChart($NewLinkParams,$NewLinkTarget);
9281 }
9282
9283 rizwank 1.1 # BY LOGIN
9284 #----------------------------
9285 if ($ShowAuthenticatedUsers) {
9286 if ($Debug) { debug("ShowAuthenticatedUsers",2); }
9287 print "$Center<a name=\"logins\"> </a><br />\n";
9288 my $title="$Message[94] ($Message[77] $MaxNbOf{'LoginShown'}) - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=alllogins"):"$PROG$StaticLinks.alllogins.$StaticExt")."\"$NewLinkTarget>$Message[80]</a>";
9289 if ($ShowAuthenticatedUsers =~ /L/i) { $title.=" - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=lastlogins"):"$PROG$StaticLinks.lastlogins.$StaticExt")."\"$NewLinkTarget>$Message[9]</a>"; }
9290 &tab_head("$title",19,0,'logins');
9291 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[94] : ".(scalar keys %_login_h)."</th>";
9292 &ShowUserInfo('__title__');
9293 if ($ShowAuthenticatedUsers =~ /P/i) { print "<th bgcolor=\"#$color_p\" width=\"80\"".Tooltip(3).">$Message[56]</th>"; }
9294 if ($ShowAuthenticatedUsers =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\"".Tooltip(4).">$Message[57]</th>"; }
9295 if ($ShowAuthenticatedUsers =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\"".Tooltip(5).">$Message[75]</th>"; }
9296 if ($ShowAuthenticatedUsers =~ /L/i) { print "<th width=\"120\">$Message[9]</th>"; }
9297 print "</tr>\n";
9298 $total_p=$total_h=$total_k=0;
9299 $max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
9300 $max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
9301 my $count=0;
9302 &BuildKeyList($MaxNbOf{'LoginShown'},$MinHit{'Login'},\%_login_h,\%_login_p);
9303 foreach my $key (@keylist) {
9304 rizwank 1.1 my $bredde_p=0;my $bredde_h=0;my $bredde_k=0;
9305 if ($max_h > 0) { $bredde_p=int($BarWidth*$_login_p{$key}/$max_h)+1; } # use max_h to enable to compare pages with hits
9306 if ($max_h > 0) { $bredde_h=int($BarWidth*$_login_h{$key}/$max_h)+1; }
9307 if ($max_k > 0) { $bredde_k=int($BarWidth*$_login_k{$key}/$max_k)+1; }
9308 print "<tr><td class=\"aws\">$key</td>";
9309 &ShowUserInfo($key);
9310 if ($ShowAuthenticatedUsers =~ /P/i) { print "<td>".($_login_p{$key}?$_login_p{$key}:" ")."</td>"; }
9311 if ($ShowAuthenticatedUsers =~ /H/i) { print "<td>$_login_h{$key}</td>"; }
9312 if ($ShowAuthenticatedUsers =~ /B/i) { print "<td>".Format_Bytes($_login_k{$key})."</td>"; }
9313 if ($ShowAuthenticatedUsers =~ /L/i) { print "<td>".($_login_l{$key}?Format_Date($_login_l{$key},1):'-')."</td>"; }
9314 print "</tr>\n";
9315 $total_p += $_login_p{$key};
9316 $total_h += $_login_h{$key};
9317 $total_k += $_login_k{$key};
9318 $count++;
9319 }
9320 $rest_p=$TotalPages-$total_p;
9321 $rest_h=$TotalHits-$total_h;
9322 $rest_k=$TotalBytes-$total_k;
9323 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other logins
9324 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">".($PageDir eq 'rtl'?"<span dir=\"ltr\">":"")."$Message[125]".($PageDir eq 'rtl'?"</span>":"")."</span></td>";
9325 rizwank 1.1 &ShowUserInfo('');
9326 if ($ShowAuthenticatedUsers =~ /P/i) { print "<td>".($rest_p?$rest_p:" ")."</td>"; }
9327 if ($ShowAuthenticatedUsers =~ /H/i) { print "<td>$rest_h</td>"; }
9328 if ($ShowAuthenticatedUsers =~ /B/i) { print "<td>".Format_Bytes($rest_k)."</td>"; }
9329 if ($ShowAuthenticatedUsers =~ /L/i) { print "<td> </td>"; }
9330 print "</tr>\n";
9331 }
9332 &tab_end();
9333 }
9334
9335 # BY ROBOTS
9336 #----------------------------
9337 if ($ShowRobotsStats) {
9338 if ($Debug) { debug("ShowRobotStats",2); }
9339 print "$Center<a name=\"robots\"> </a><br />\n";
9340 &tab_head("$Message[53] ($Message[77] $MaxNbOf{'RobotShown'}) - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=allrobots"):"$PROG$StaticLinks.allrobots.$StaticExt")."\"$NewLinkTarget>$Message[80]</a> - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=lastrobots"):"$PROG$StaticLinks.lastrobots.$StaticExt")."\"$NewLinkTarget>$Message[9]</a>",19,0,'robots');
9341 print "<tr bgcolor=\"#$color_TableBGRowTitle\"".Tooltip(16)."><th>".(scalar keys %_robot_h)." $Message[51]*</th>";
9342 if ($ShowRobotsStats =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>"; }
9343 if ($ShowRobotsStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>"; }
9344 if ($ShowRobotsStats =~ /L/i) { print "<th width=\"120\">$Message[9]</th>"; }
9345 print "</tr>\n";
9346 rizwank 1.1 $total_p=$total_h=$total_k=$total_r=0;
9347 my $count=0;
9348 &BuildKeyList($MaxNbOf{'RobotShown'},$MinHit{'Robot'},\%_robot_h,\%_robot_h);
9349 foreach my $key (@keylist) {
9350 print "<tr><td class=\"aws\">".($PageDir eq 'rtl'?"<span dir=\"ltr\">":"").($RobotsHashIDLib{$key}?$RobotsHashIDLib{$key}:$key).($PageDir eq 'rtl'?"</span>":"")."</td>";
9351 if ($ShowRobotsStats =~ /H/i) { print "<td>".($_robot_h{$key}-$_robot_r{$key}).($_robot_r{$key}?"+$_robot_r{$key}":"")."</td>"; }
9352 if ($ShowRobotsStats =~ /B/i) { print "<td>".Format_Bytes($_robot_k{$key})."</td>"; }
9353 if ($ShowRobotsStats =~ /L/i) { print "<td>".($_robot_l{$key}?Format_Date($_robot_l{$key},1):'-')."</td>"; }
9354 print "</tr>\n";
9355 #$total_p += $_robot_p{$key};
9356 $total_h += $_robot_h{$key};
9357 $total_k += $_robot_k{$key}||0;
9358 $total_r += $_robot_r{$key}||0;
9359 $count++;
9360 }
9361 # For bots we need to count Totals
9362 my $TotalPagesRobots = 0; #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
9363 my $TotalHitsRobots = 0; foreach (values %_robot_h) { $TotalHitsRobots+=$_; }
9364 my $TotalBytesRobots = 0; foreach (values %_robot_k) { $TotalBytesRobots+=$_; }
9365 my $TotalRRobots = 0; foreach (values %_robot_r) { $TotalRRobots+=$_; }
9366 $rest_p=0; #$rest_p=$TotalPagesRobots-$total_p;
9367 rizwank 1.1 $rest_h=$TotalHitsRobots-$total_h;
9368 $rest_k=$TotalBytesRobots-$total_k;
9369 $rest_r=$TotalRRobots-$total_r;
9370 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0) { # All other robots
9371 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
9372 if ($ShowRobotsStats =~ /H/i) { print "<td>".($rest_h-$rest_r).($rest_r?"+$rest_r":"")."</td>"; }
9373 if ($ShowRobotsStats =~ /B/i) { print "<td>".(Format_Bytes($rest_k))."</td>"; }
9374 if ($ShowRobotsStats =~ /L/i) { print "<td> </td>"; }
9375 print "</tr>\n";
9376 }
9377 &tab_end("* $Message[156]".($TotalRRobots?" $Message[157]":""));
9378 }
9379
9380 # BY WORMS
9381 #----------------------------
9382 if ($ShowWormsStats) {
9383 if ($Debug) { debug("ShowWormsStats",2); }
9384 print "$Center<a name=\"worms\"> </a><br />\n";
9385 &tab_head("$Message[163] ($Message[77] $MaxNbOf{'WormsShown'})",19,0,'worms');
9386 print "<tr bgcolor=\"#$color_TableBGRowTitle\"".Tooltip(21).">";
9387 print "<th>".(scalar keys %_worm_h)." $Message[164]*</th>";
9388 rizwank 1.1 print "<th>$Message[167]</th>";
9389 if ($ShowWormsStats =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>"; }
9390 if ($ShowWormsStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>"; }
9391 if ($ShowWormsStats =~ /L/i) { print "<th width=\"120\">$Message[9]</th>"; }
9392 print "</tr>\n";
9393 $total_p=$total_h=$total_k=0;
9394 my $count=0;
9395 &BuildKeyList($MaxNbOf{'WormsShown'},$MinHit{'Worm'},\%_worm_h,\%_worm_h);
9396 foreach my $key (@keylist) {
9397 print "<tr>";
9398 print "<td class=\"aws\">".($PageDir eq 'rtl'?"<span dir=\"ltr\">":"").($WormsHashLib{$key}?$WormsHashLib{$key}:$key).($PageDir eq 'rtl'?"</span>":"")."</td>";
9399 print "<td class=\"aws\">".($PageDir eq 'rtl'?"<span dir=\"ltr\">":"").($WormsHashTarget{$key}?$WormsHashTarget{$key}:$key).($PageDir eq 'rtl'?"</span>":"")."</td>";
9400 if ($ShowWormsStats =~ /H/i) { print "<td>".$_worm_h{$key}."</td>"; }
9401 if ($ShowWormsStats =~ /B/i) { print "<td>".Format_Bytes($_worm_k{$key})."</td>"; }
9402 if ($ShowWormsStats =~ /L/i) { print "<td>".($_worm_l{$key}?Format_Date($_worm_l{$key},1):'-')."</td>"; }
9403 print "</tr>\n";
9404 #$total_p += $_worm_p{$key};
9405 $total_h += $_worm_h{$key};
9406 $total_k += $_worm_k{$key}||0;
9407 $count++;
9408 }
9409 rizwank 1.1 # For worms we need to count Totals
9410 my $TotalPagesWorms = 0; #foreach (values %_worm_p) { $TotalPagesWorms+=$_; }
9411 my $TotalHitsWorms = 0; foreach (values %_worm_h) { $TotalHitsWorms+=$_; }
9412 my $TotalBytesWorms = 0; foreach (values %_worm_k) { $TotalBytesWorms+=$_; }
9413 $rest_p=0; #$rest_p=$TotalPagesRobots-$total_p;
9414 $rest_h=$TotalHitsWorms-$total_h;
9415 $rest_k=$TotalBytesWorms-$total_k;
9416 if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other worms
9417 print "<tr>";
9418 print "<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
9419 print "<td class=\"aws\">-</td>";
9420 if ($ShowWormsStats =~ /H/i) { print "<td>".($rest_h)."</td>"; }
9421 if ($ShowWormsStats =~ /B/i) { print "<td>".(Format_Bytes($rest_k))."</td>"; }
9422 if ($ShowWormsStats =~ /L/i) { print "<td> </td>"; }
9423 print "</tr>\n";
9424 }
9425 &tab_end("* $Message[158]");
9426 }
9427
9428 print "\n<a name=\"how\"> </a>\n\n";
9429
9430 rizwank 1.1 # BY SESSION
9431 #----------------------------
9432 if ($ShowSessionsStats) {
9433 if ($Debug) { debug("ShowSessionsStats",2); }
9434 print "$Center<a name=\"sessions\"> </a><br />\n";
9435 my $title="$Message[117]";
9436 &tab_head($title,19,0,'sessions');
9437 my $Totals=0; foreach (@SessionsRange) { $average_s+=($_session{$_}||0)*$SessionsAverage{$_}; $Totals+=$_session{$_}||0; }
9438 if ($Totals) { $average_s=int($average_s/$Totals); }
9439 else { $average_s='?'; }
9440 print "<tr bgcolor=\"#$color_TableBGRowTitle\"".Tooltip(1)."><th>$Message[10]: $TotalVisits - $Message[96]: $average_s s</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[10]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
9441 $average_s=0;
9442 $total_s=0;
9443 my $count=0;
9444 foreach my $key (@SessionsRange) {
9445 my $p=0;
9446 if ($TotalVisits) { $p=int($_session{$key}/$TotalVisits*1000)/10; }
9447 $total_s+=$_session{$key}||0;
9448 print "<tr><td class=\"aws\">$key</td>";
9449 print "<td>".($_session{$key}?$_session{$key}:" ")."</td>";
9450 print "<td>".($_session{$key}?"$p %":" ")."</td>";
9451 rizwank 1.1 print "</tr>\n";
9452 $count++;
9453 }
9454 $rest_s=$TotalVisits-$total_s;
9455 if ($rest_s > 0) { # All others sessions
9456 my $p=0;
9457 if ($TotalVisits) { $p=int($rest_s/$TotalVisits*1000)/10; }
9458 print "<tr".Tooltip(20)."><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
9459 print "<td>$rest_s</td>";
9460 print "<td>".($rest_s?"$p %":" ")."</td>";
9461 print "</tr>\n";
9462 }
9463 &tab_end();
9464 }
9465
9466 # BY FILE TYPE
9467 #-------------------------
9468 if ($ShowFileTypesStats) {
9469 if ($Debug) { debug("ShowFileTypesStatsCompressionStats",2); }
9470 print "$Center<a name=\"filetypes\"> </a><br />\n";
9471 my $Totalh=0; foreach (keys %_filetypes_h) { $Totalh+=$_filetypes_h{$_}; }
9472 rizwank 1.1 my $Totalk=0; foreach (keys %_filetypes_k) { $Totalk+=$_filetypes_k{$_}; }
9473 my $title="$Message[73]";
9474 if ($ShowFileTypesStats =~ /C/i) { $title.=" - $Message[98]"; }
9475 &tab_head("$title",19,0,'filetypes');
9476 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"3\">$Message[73]</th>";
9477 if ($ShowFileTypesStats =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\"".Tooltip(4).">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>"; }
9478 if ($ShowFileTypesStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\"".Tooltip(5).">$Message[75]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[15]</th>"; }
9479 if ($ShowFileTypesStats =~ /C/i) { print "<th bgcolor=\"#$color_k\" width=\"100\">$Message[100]</th><th bgcolor=\"#$color_k\" width=\"100\">$Message[101]</th><th bgcolor=\"#$color_k\" width=\"100\">$Message[99]</th>"; }
9480 print "</tr>\n";
9481 my $total_con=0; my $total_cre=0;
9482 my $count=0;
9483 &BuildKeyList($MaxRowsInHTMLOutput,1,\%_filetypes_h,\%_filetypes_h);
9484 foreach my $key (@keylist) {
9485 my $p_h=' '; my $p_k=' ';
9486 if ($Totalh) { $p_h=int($_filetypes_h{$key}/$Totalh*1000)/10; $p_h="$p_h %"; }
9487 if ($Totalk) { $p_k=int($_filetypes_k{$key}/$Totalk*1000)/10; $p_k="$p_k %"; }
9488 if ($key eq 'Unknown') {
9489 print "<tr><td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/mime\/unknown.png\"".AltTitle("")." /></td><td class=\"aws\" colspan=\"2\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
9490 }
9491 else {
9492 my $nameicon=$MimeHashIcon{$key}||"notavailable";
9493 rizwank 1.1 my $nametype=$MimeHashLib{$MimeHashFamily{$key}||""}||" ";
9494 print "<tr><td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/mime\/$nameicon.png\"".AltTitle("")." /></td><td class=\"aws\">$key</td>";
9495 print "<td class=\"aws\">$nametype</td>";
9496 }
9497 if ($ShowFileTypesStats =~ /H/i) { print "<td>$_filetypes_h{$key}</td><td>$p_h</td>"; }
9498 if ($ShowFileTypesStats =~ /B/i) { print "<td>".Format_Bytes($_filetypes_k{$key})."</td><td>$p_k</td>"; }
9499 if ($ShowFileTypesStats =~ /C/i) {
9500 if ($_filetypes_gz_in{$key}) {
9501 my $percent=int(100*(1-$_filetypes_gz_out{$key}/$_filetypes_gz_in{$key}));
9502 printf("<td>%s</td><td>%s</td><td>%s (%s%)</td>",Format_Bytes($_filetypes_gz_in{$key}),Format_Bytes($_filetypes_gz_out{$key}),Format_Bytes($_filetypes_gz_in{$key}-$_filetypes_gz_out{$key}),$percent);
9503 $total_con+=$_filetypes_gz_in{$key};
9504 $total_cre+=$_filetypes_gz_out{$key};
9505 }
9506 else {
9507 print "<td> </td><td> </td><td> </td>";
9508 }
9509 }
9510 print "</tr>\n";
9511 $count++;
9512 }
9513 # Add total (only usefull if compression is enabled)
9514 rizwank 1.1 if ($ShowFileTypesStats =~ /C/i) {
9515 my $colspan=3;
9516 if ($ShowFileTypesStats =~ /H/i) { $colspan+=2; }
9517 if ($ShowFileTypesStats =~ /B/i) { $colspan+=2; }
9518 print "<tr>";
9519 print "<td class=\"aws\" colspan=\"$colspan\"><b>$Message[98]</b></td>";
9520 if ($ShowFileTypesStats =~ /C/i) {
9521 if ($total_con) {
9522 my $percent=int(100*(1-$total_cre/$total_con));
9523 printf("<td>%s</td><td>%s</td><td>%s (%s%)</td>",Format_Bytes($total_con),Format_Bytes($total_cre),Format_Bytes($total_con-$total_cre),$percent);
9524 }
9525 else {
9526 print "<td> </td><td> </td><td> </td>";
9527 }
9528 }
9529 print "</tr>\n";
9530 }
9531 &tab_end();
9532 }
9533
9534 # BY FILE SIZE
9535 rizwank 1.1 #-------------------------
9536 if ($ShowFileSizesStats) {
9537
9538 }
9539
9540 # BY FILE/URL
9541 #-------------------------
9542 if ($ShowPagesStats) {
9543 if ($Debug) { debug("ShowPagesStats (MaxNbOf{'PageShown'}=$MaxNbOf{'PageShown'} TotalDifferentPages=$TotalDifferentPages)",2); }
9544 print "$Center<a name=\"urls\"> </a><a name=\"entry\"> </a><a name=\"exit\"> </a><br />\n";
9545 my $title="$Message[19] ($Message[77] $MaxNbOf{'PageShown'}) - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=urldetail"):"$PROG$StaticLinks.urldetail.$StaticExt")."\"$NewLinkTarget>$Message[80]</a>";
9546 if ($ShowPagesStats =~ /E/i) { $title.=" - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=urlentry"):"$PROG$StaticLinks.urlentry.$StaticExt")."\"$NewLinkTarget>$Message[104]</a>"; }
9547 if ($ShowPagesStats =~ /X/i) { $title.=" - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=urlexit"):"$PROG$StaticLinks.urlexit.$StaticExt")."\"$NewLinkTarget>$Message[116]</a>"; }
9548 &tab_head("$title",19,0,'urls');
9549 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$TotalDifferentPages $Message[28]</th>";
9550 if ($ShowPagesStats =~ /P/i && $LogType ne 'F') { print "<th bgcolor=\"#$color_p\" width=\"80\">$Message[29]</th>"; }
9551 if ($ShowPagesStats =~ /[PH]/i && $LogType eq 'F') { print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>"; }
9552 if ($ShowPagesStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>"; }
9553 if ($ShowPagesStats =~ /E/i) { print "<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>"; }
9554 if ($ShowPagesStats =~ /X/i) { print "<th bgcolor=\"#$color_x\" width=\"80\">$Message[116]</th>"; }
9555 # Call to plugins' function ShowPagesAddField
9556 rizwank 1.1 foreach my $pluginname (keys %{$PluginsLoaded{'ShowPagesAddField'}}) {
9557 my $function="ShowPagesAddField_$pluginname('title')";
9558 eval("$function");
9559 }
9560 print "<th> </th></tr>\n";
9561 $total_p=$total_e=$total_x=$total_k=0;
9562 $max_p=1; $max_k=1;
9563 my $count=0;
9564 &BuildKeyList($MaxNbOf{'PageShown'},$MinHit{'File'},\%_url_p,\%_url_p);
9565 foreach my $key (@keylist) {
9566 if ($_url_p{$key} > $max_p) { $max_p = $_url_p{$key}; }
9567 if ($_url_k{$key}/($_url_p{$key}||1) > $max_k) { $max_k = $_url_k{$key}/($_url_p{$key}||1); }
9568 }
9569 foreach my $key (@keylist) {
9570 print "<tr><td class=\"aws\">";
9571 &ShowURLInfo($key);
9572 print "</td>";
9573 my $bredde_p=0; my $bredde_e=0; my $bredde_x=0; my $bredde_k=0;
9574 if ($max_p > 0) { $bredde_p=int($BarWidth*($_url_p{$key}||0)/$max_p)+1; }
9575 if (($bredde_p==1) && $_url_p{$key}) { $bredde_p=2; }
9576 if ($max_p > 0) { $bredde_e=int($BarWidth*($_url_e{$key}||0)/$max_p)+1; }
9577 rizwank 1.1 if (($bredde_e==1) && $_url_e{$key}) { $bredde_e=2; }
9578 if ($max_p > 0) { $bredde_x=int($BarWidth*($_url_x{$key}||0)/$max_p)+1; }
9579 if (($bredde_x==1) && $_url_x{$key}) { $bredde_x=2; }
9580 if ($max_k > 0) { $bredde_k=int($BarWidth*(($_url_k{$key}||0)/($_url_p{$key}||1))/$max_k)+1; }
9581 if (($bredde_k==1) && $_url_k{$key}) { $bredde_k=2; }
9582 if ($ShowPagesStats =~ /P/i && $LogType ne 'F') { print "<td>$_url_p{$key}</td>"; }
9583 if ($ShowPagesStats =~ /[PH]/i && $LogType eq 'F') { print "<td>$_url_p{$key}</td>"; }
9584 if ($ShowPagesStats =~ /B/i) { print "<td>".($_url_k{$key}?Format_Bytes($_url_k{$key}/($_url_p{$key}||1)):" ")."</td>"; }
9585 if ($ShowPagesStats =~ /E/i) { print "<td>".($_url_e{$key}?$_url_e{$key}:" ")."</td>"; }
9586 if ($ShowPagesStats =~ /X/i) { print "<td>".($_url_x{$key}?$_url_x{$key}:" ")."</td>"; }
9587 # Call to plugins' function ShowPagesAddField
9588 foreach my $pluginname (keys %{$PluginsLoaded{'ShowPagesAddField'}}) {
9589 my $function="ShowPagesAddField_$pluginname('$key')";
9590 eval("$function");
9591 }
9592 print "<td class=\"aws\">";
9593 if ($ShowPagesStats =~ /P/i && $LogType ne 'F') { print "<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"4\"".AltTitle("")." /><br />"; }
9594 if ($ShowPagesStats =~ /[PH]/i && $LogType eq 'F') { print "<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_p\" height=\"4\"".AltTitle("")." /><br />"; }
9595 if ($ShowPagesStats =~ /B/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"4\"".AltTitle("")." /><br />"; }
9596 if ($ShowPagesStats =~ /E/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\"".AltTitle("")." /><br />"; }
9597 if ($ShowPagesStats =~ /X/i) { print "<img src=\"$DirIcons\/other\/$BarPng{'hx'}\" width=\"$bredde_x\" height=\"4\"".AltTitle("")." />"; }
9598 rizwank 1.1 print "</td></tr>\n";
9599 $total_p += $_url_p{$key};
9600 $total_e += $_url_e{$key};
9601 $total_x += $_url_x{$key};
9602 $total_k += $_url_k{$key};
9603 $count++;
9604 }
9605 $rest_p=$TotalPages-$total_p;
9606 $rest_e=$TotalEntries-$total_e;
9607 $rest_x=$TotalExits-$total_x;
9608 $rest_k=$TotalBytesPages-$total_k;
9609 if ($rest_p > 0 || $rest_k > 0 || $rest_e > 0 || $rest_x > 0) { # All other urls
9610 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
9611 if ($ShowPagesStats =~ /P/i && $LogType ne 'F') { print "<td>$rest_p</td>"; }
9612 if ($ShowPagesStats =~ /[PH]/i && $LogType eq 'F') { print "<td>$rest_p</td>"; }
9613 if ($ShowPagesStats =~ /B/i) { print "<td>".($rest_k?Format_Bytes($rest_k/($rest_p||1)):" ")."</td>"; }
9614 if ($ShowPagesStats =~ /E/i) { print "<td>".($rest_e?$rest_e:" ")."</td>"; }
9615 if ($ShowPagesStats =~ /X/i) { print "<td>".($rest_x?$rest_x:" ")."</td>"; }
9616 # Call to plugins' function ShowPagesAddField
9617 foreach my $pluginname (keys %{$PluginsLoaded{'ShowPagesAddField'}}) {
9618 my $function="ShowPagesAddField_$pluginname('')";
9619 rizwank 1.1 eval("$function");
9620 }
9621 print "<td> </td></tr>\n";
9622 }
9623 &tab_end();
9624 }
9625
9626 # BY OS
9627 #----------------------------
9628 if ($ShowOSStats) {
9629 if ($Debug) { debug("ShowOSStats",2); }
9630 print "$Center<a name=\"os\"> </a><br />\n";
9631 my $Totalh=0; my %new_os_h=();
9632 OSLOOP: foreach my $key (keys %_os_h) {
9633 $Totalh+=$_os_h{$key};
9634 foreach my $family (@OSFamily) { if ($key =~ /^$family/i) { $new_os_h{"${family}cumul"}+=$_os_h{$key}; next OSLOOP; } }
9635 $new_os_h{$key}+=$_os_h{$key};
9636 }
9637 my $title="$Message[59] ($Message[77] $MaxNbOf{'OsShown'}) - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=osdetail"):"$PROG$StaticLinks.osdetail.$StaticExt")."\"$NewLinkTarget>$Message[80]/$Message[58]</a> - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=unknownos"):"$PROG$StaticLinks.unknownos.$StaticExt")."\"$NewLinkTarget>$Message[0]</a>";
9638 &tab_head("$title",19,0,'os');
9639 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\"> </th><th>$Message[59]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th></tr>\n";
9640 rizwank 1.1 $total_h=0;
9641 my $count=0;
9642 &BuildKeyList($MaxNbOf{'OsShown'},$MinHit{'Os'},\%new_os_h,\%new_os_h);
9643 foreach my $key (@keylist) {
9644 my $p=' ';
9645 if ($Totalh) { $p=int($new_os_h{$key}/$Totalh*1000)/10; $p="$p %"; }
9646 if ($key eq 'Unknown') {
9647 print "<tr><td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/os\/unknown.png\"".AltTitle("")." /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td>$_os_h{$key}</td><td>$p</td></tr>\n";
9648 }
9649 else {
9650 my $keywithoutcumul=$key; $keywithoutcumul =~ s/cumul$//i;
9651 my $libos=$OSHashLib{$keywithoutcumul}||$keywithoutcumul;
9652 my $nameicon=$keywithoutcumul; $nameicon =~ s/[^\w]//g;
9653 # TODO Use OSFamilyLib
9654 if ($libos eq 'win') { $libos="<b>Windows</b>"; }
9655 if ($libos eq 'mac') { $libos="<b>Macintosh</b>"; }
9656 print "<tr><td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/os\/$nameicon.png\"".AltTitle("")." /></td><td class=\"aws\">$libos</td><td>$new_os_h{$key}</td><td>$p</td></tr>\n";
9657 }
9658 $total_h += $new_os_h{$key};
9659 $count++;
9660 }
9661 rizwank 1.1 if ($Debug) { debug("Total real / shown : $Totalh / $total_h",2); }
9662 $rest_h=$Totalh-$total_h;
9663 if ($rest_h > 0) {
9664 my $p;
9665 if ($Totalh) { $p=int($rest_h/$Totalh*1000)/10; }
9666 print "<tr>";
9667 print "<td> </td>";
9668 print "<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td><td>$rest_h</td>";
9669 print "<td>$p %</td></tr>\n";
9670 }
9671 &tab_end();
9672 }
9673
9674 # BY BROWSER
9675 #----------------------------
9676 if ($ShowBrowsersStats) {
9677 if ($Debug) { debug("ShowBrowsersStats",2); }
9678 print "$Center<a name=\"browsers\"> </a><br />\n";
9679 my $Totalh=0; my %new_browser_h=();
9680 BROWSERLOOP: foreach my $key (keys %_browser_h) {
9681 $Totalh+=$_browser_h{$key};
9682 rizwank 1.1 foreach my $family (keys %BrowsersFamily) { if ($key =~ /^$family/i) { $new_browser_h{"${family}cumul"}+=$_browser_h{$key}; next BROWSERLOOP; } }
9683 $new_browser_h{$key}+=$_browser_h{$key};
9684 }
9685 my $title="$Message[21] ($Message[77] $MaxNbOf{'BrowsersShown'}) - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=browserdetail"):"$PROG$StaticLinks.browserdetail.$StaticExt")."\"$NewLinkTarget>$Message[80]/$Message[58]</a> - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=unknownbrowser"):"$PROG$StaticLinks.unknownbrowser.$StaticExt")."\"$NewLinkTarget>$Message[0]</a>";
9686 &tab_head("$title",19,0,'browsers');
9687 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\"> </th><th>$Message[21]</th><th width=\"80\">$Message[111]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th></tr>\n";
9688 $total_h=0;
9689 my $count=0;
9690 &BuildKeyList($MaxNbOf{'BrowsersShown'},$MinHit{'Browser'},\%new_browser_h,\%new_browser_h);
9691 foreach my $key (@keylist) {
9692 my $p=' ';
9693 if ($Totalh) { $p=int($new_browser_h{$key}/$Totalh*1000)/10; $p="$p %"; }
9694 if ($key eq 'Unknown') {
9695 print "<tr><td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/browser\/unknown.png\"".AltTitle("")." /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td width=\"80\">?</td><td>$_browser_h{$key}</td><td>$p</td></tr>\n";
9696 }
9697 else {
9698 my $keywithoutcumul=$key; $keywithoutcumul =~ s/cumul$//i;
9699 my $libbrowser=$BrowsersHashIDLib{$keywithoutcumul}||$keywithoutcumul;
9700 my $nameicon=$BrowsersHashIcon{$keywithoutcumul}||"notavailable";
9701 if ($BrowsersFamily{$keywithoutcumul}) { $libbrowser="<b>$libbrowser</b>"; }
9702 print "<tr><td".($count?"":" width=\"$WIDTHCOLICON\"")."><img src=\"$DirIcons\/browser\/$nameicon.png\"".AltTitle("")." /></td><td class=\"aws\">".($PageDir eq 'rtl'?"<span dir=\"ltr\">":"")."$libbrowser".($PageDir eq 'rtl'?"</span>":"")."</td><td>".($BrowsersHereAreGrabbers{$key}?"<b>$Message[112]</b>":"$Message[113]")."</td><td>$new_browser_h{$key}</td><td>$p</td></tr>\n";
9703 rizwank 1.1 }
9704 $total_h += $new_browser_h{$key};
9705 $count++;
9706 }
9707 if ($Debug) { debug("Total real / shown : $Totalh / $total_h",2); }
9708 $rest_h=$Totalh-$total_h;
9709 if ($rest_h > 0) {
9710 my $p;
9711 if ($Totalh) { $p=int($rest_h/$Totalh*1000)/10; }
9712 print "<tr>";
9713 print "<td> </td>";
9714 print "<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td><td> </td><td>$rest_h</td>";
9715 print "<td>$p %</td></tr>\n";
9716 }
9717 &tab_end();
9718 }
9719
9720 # BY SCREEN SIZE
9721 #----------------------------
9722 if ($ShowScreenSizeStats) {
9723 if ($Debug) { debug("ShowScreenSizeStats",2); }
9724 rizwank 1.1 print "$Center<a name=\"screensizes\"> </a><br />\n";
9725 my $Totalh=0; foreach (keys %_screensize_h) { $Totalh+=$_screensize_h{$_}; }
9726 my $title="$Message[135] ($Message[77] $MaxNbOf{'ScreenSizesShown'})";
9727 &tab_head("$title",0,0,'screensizes');
9728 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[135]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th></tr>\n";
9729 my $total_h=0;
9730 my $count=0;
9731 &BuildKeyList($MaxNbOf{'ScreenSizesShown'},$MinHit{'ScreenSize'},\%_screensize_h,\%_screensize_h);
9732 foreach my $key (@keylist) {
9733 my $p=' ';
9734 if ($Totalh) { $p=int($_screensize_h{$key}/$Totalh*1000)/10; $p="$p %"; }
9735 $total_h+=$_screensize_h{$key}||0;
9736 print "<tr>";
9737 if ($key eq 'Unknown') {
9738 print "<td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
9739 print "<td>$p</td>";
9740 }
9741 else {
9742 my $screensize=$key;
9743 print "<td class=\"aws\">$screensize</td>";
9744 print "<td>$p</td>";
9745 rizwank 1.1 }
9746 print "</tr>\n";
9747 $count++;
9748 }
9749 $rest_h=$Totalh-$total_h;
9750 if ($rest_h > 0) { # All others sessions
9751 my $p=0;
9752 if ($Totalh) { $p=int($rest_h/$Totalh*1000)/10; }
9753 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
9754 print "<td>".($rest_h?"$p %":" ")."</td>";
9755 print "</tr>\n";
9756 }
9757 &tab_end();
9758 }
9759
9760 print "\n<a name=\"refering\"> </a>\n\n";
9761
9762 # BY REFERENCE
9763 #---------------------------
9764 if ($ShowOriginStats) {
9765 if ($Debug) { debug("ShowOriginStats",2); }
9766 rizwank 1.1 print "$Center<a name=\"referer\"> </a><br />\n";
9767 my $Totalp=0; foreach (0..5) { $Totalp+=($_ != 4 || $IncludeInternalLinksInOriginSection)?$_from_p[$_]:0; }
9768 my $Totalh=0; foreach (0..5) { $Totalh+=($_ != 4 || $IncludeInternalLinksInOriginSection)?$_from_h[$_]:0; }
9769 &tab_head($Message[36],19,0,'referer');
9770 my @p_p=(0,0,0,0,0,0);
9771 if ($Totalp > 0) {
9772 $p_p[0]=int($_from_p[0]/$Totalp*1000)/10;
9773 $p_p[1]=int($_from_p[1]/$Totalp*1000)/10;
9774 $p_p[2]=int($_from_p[2]/$Totalp*1000)/10;
9775 $p_p[3]=int($_from_p[3]/$Totalp*1000)/10;
9776 $p_p[4]=int($_from_p[4]/$Totalp*1000)/10;
9777 $p_p[5]=int($_from_p[5]/$Totalp*1000)/10;
9778 }
9779 my @p_h=(0,0,0,0,0,0);
9780 if ($Totalh > 0) {
9781 $p_h[0]=int($_from_h[0]/$Totalh*1000)/10;
9782 $p_h[1]=int($_from_h[1]/$Totalh*1000)/10;
9783 $p_h[2]=int($_from_h[2]/$Totalh*1000)/10;
9784 $p_h[3]=int($_from_h[3]/$Totalh*1000)/10;
9785 $p_h[4]=int($_from_h[4]/$Totalh*1000)/10;
9786 $p_h[5]=int($_from_h[5]/$Totalh*1000)/10;
9787 rizwank 1.1 }
9788 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[37]</th>";
9789 if ($ShowOriginStats =~ /P/i) { print "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>"; }
9790 if ($ShowOriginStats =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>"; }
9791 print "</tr>\n";
9792 #------- Referrals by direct address/bookmarks
9793 print "<tr><td class=\"aws\"><b>$Message[38]</b></td>";
9794 if ($ShowOriginStats =~ /P/i) { print "<td>".($_from_p[0]?$_from_p[0]:" ")."</td><td>".($_from_p[0]?"$p_p[0] %":" ")."</td>"; }
9795 if ($ShowOriginStats =~ /H/i) { print "<td>".($_from_h[0]?$_from_h[0]:" ")."</td><td>".($_from_h[0]?"$p_h[0] %":" ")."</td>"; }
9796 print "</tr>\n";
9797 #------- Referrals by news group
9798 print "<tr><td class=\"aws\"><b>$Message[107]</b></td>";
9799 if ($ShowOriginStats =~ /P/i) { print "<td>".($_from_p[5]?$_from_p[5]:" ")."</td><td>".($_from_p[5]?"$p_p[5] %":" ")."</td>"; }
9800 if ($ShowOriginStats =~ /H/i) { print "<td>".($_from_h[5]?$_from_h[5]:" ")."</td><td>".($_from_h[5]?"$p_h[5] %":" ")."</td>"; }
9801 print "</tr>\n";
9802 #------- Referrals by search engines
9803 print "<tr".Tooltip(13)."><td class=\"aws\"><b>$Message[40]</b> - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=refererse"):"$PROG$StaticLinks.refererse.$StaticExt")."\"$NewLinkTarget>$Message[80]</a><br />\n";
9804 if (scalar keys %_se_referrals_h) {
9805 print "<table>\n";
9806 $total_p=0; $total_h=0;
9807 my $count=0;
9808 rizwank 1.1 &BuildKeyList($MaxNbOf{'RefererShown'},$MinHit{'Refer'},\%_se_referrals_h,((scalar keys %_se_referrals_p)?\%_se_referrals_p:\%_se_referrals_h));
9809 foreach my $key (@keylist) {
9810 my $newreferer=CleanFromCSSA($SearchEnginesHashLib{$key}||$key);
9811 print "<tr><td class=\"aws\">- $newreferer</td>";
9812 print "<td>".($_se_referrals_p{$key}?$_se_referrals_p{$key}:'0')."</td>";
9813 print "<td>$_se_referrals_h{$key}</td>";
9814 print "</tr>\n";
9815 $total_p += $_se_referrals_p{$key};
9816 $total_h += $_se_referrals_h{$key};
9817 $count++;
9818 }
9819 if ($Debug) { debug("Total real / shown : $TotalSearchEnginesPages / $total_p - $TotalSearchEnginesHits / $total_h",2); }
9820 $rest_p=$TotalSearchEnginesPages-$total_p;
9821 $rest_h=$TotalSearchEnginesHits-$total_h;
9822 if ($rest_p > 0 || $rest_h > 0) {
9823 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">- $Message[2]</span></td>";
9824 print "<td>$rest_p</td>";
9825 print "<td>$rest_h</td>";
9826 print "</tr>\n";
9827 }
9828 print "</table>";
9829 rizwank 1.1 }
9830 print "</td>\n";
9831 if ($ShowOriginStats =~ /P/i) { print "<td valign=\"top\">".($_from_p[2]?$_from_p[2]:" ")."</td><td valign=\"top\">".($_from_p[2]?"$p_p[2] %":" ")."</td>"; }
9832 if ($ShowOriginStats =~ /H/i) { print "<td valign=\"top\">".($_from_h[2]?$_from_h[2]:" ")."</td><td valign=\"top\">".($_from_h[2]?"$p_h[2] %":" ")."</td>"; }
9833 print "</tr>\n";
9834 #------- Referrals by external HTML link
9835 print "<tr".Tooltip(14)."><td class=\"aws\"><b>$Message[41]</b> - <a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=refererpages"):"$PROG$StaticLinks.refererpages.$StaticExt")."\"$NewLinkTarget>$Message[80]</a><br />\n";
9836 if (scalar keys %_pagesrefs_h) {
9837 print "<table>\n";
9838 $total_p=0; $total_h=0;
9839 my $count=0;
9840 &BuildKeyList($MaxNbOf{'RefererShown'},$MinHit{'Refer'},\%_pagesrefs_h,((scalar keys %_pagesrefs_p)?\%_pagesrefs_p:\%_pagesrefs_h));
9841 foreach my $key (@keylist) {
9842 print "<tr><td class=\"aws\">- ";
9843 &ShowURLInfo($key);
9844 print "</td>";
9845 print "<td>".($_pagesrefs_p{$key}?$_pagesrefs_p{$key}:'0')."</td>";
9846 print "<td>$_pagesrefs_h{$key}</td>";
9847 print "</tr>\n";
9848 $total_p += $_pagesrefs_p{$key};
9849 $total_h += $_pagesrefs_h{$key};
9850 rizwank 1.1 $count++;
9851 }
9852 if ($Debug) { debug("Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",2); }
9853 $rest_p=$TotalRefererPages-$total_p;
9854 $rest_h=$TotalRefererHits-$total_h;
9855 if ($rest_p > 0 || $rest_h > 0) {
9856 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">- $Message[2]</span></td>";
9857 print "<td>$rest_p</td>";
9858 print "<td>$rest_h</td>";
9859 print "</tr>\n";
9860 }
9861 print "</table>";
9862 }
9863 print "</td>\n";
9864 if ($ShowOriginStats =~ /P/i) { print "<td valign=\"top\">".($_from_p[3]?$_from_p[3]:" ")."</td><td valign=\"top\">".($_from_p[3]?"$p_p[3] %":" ")."</td>"; }
9865 if ($ShowOriginStats =~ /H/i) { print "<td valign=\"top\">".($_from_h[3]?$_from_h[3]:" ")."</td><td valign=\"top\">".($_from_h[3]?"$p_h[3] %":" ")."</td>"; }
9866 print "</tr>\n";
9867 #------- Referrals by internal HTML link
9868 if ($IncludeInternalLinksInOriginSection) {
9869 print "<tr><td class=\"aws\"><b>$Message[42]</b></td>";
9870 if ($ShowOriginStats =~ /P/i) { print "<td>".($_from_p[4]?$_from_p[4]:" ")."</td><td>".($_from_p[4]?"$p_p[4] %":" ")."</td>"; }
9871 rizwank 1.1 if ($ShowOriginStats =~ /H/i) { print "<td>".($_from_h[4]?$_from_h[4]:" ")."</td><td>".($_from_h[4]?"$p_h[4] %":" ")."</td>"; }
9872 print "</tr>\n";
9873 }
9874 #------- Unknown origin
9875 print "<tr><td class=\"aws\"><b>$Message[39]</b></td>";
9876 if ($ShowOriginStats =~ /P/i) { print "<td>".($_from_p[1]?$_from_p[1]:" ")."</td><td>".($_from_p[1]?"$p_p[1] %":" ")."</td>"; }
9877 if ($ShowOriginStats =~ /H/i) { print "<td>".($_from_h[1]?$_from_h[1]:" ")."</td><td>".($_from_h[1]?"$p_h[1] %":" ")."</td>"; }
9878 print "</tr>\n";
9879 &tab_end();
9880 }
9881
9882 print "\n<a name=\"keys\"> </a>\n\n";
9883
9884 # BY SEARCH KEYWORDS AND/OR KEYPHRASES
9885 #-------------------------------------
9886 if ($ShowKeyphrasesStats) { print "$Center<a name=\"keyphrases\"> </a>"; }
9887 if ($ShowKeywordsStats) { print "$Center<a name=\"keywords\"> </a>"; }
9888 if ($ShowKeyphrasesStats || $ShowKeywordsStats) { print "<br />\n"; }
9889 if ($ShowKeyphrasesStats && $ShowKeywordsStats) { print "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr>"; }
9890 if ($ShowKeyphrasesStats) {
9891 # By Keyphrases
9892 rizwank 1.1 if ($ShowKeyphrasesStats && $ShowKeywordsStats) { print "<td width=\"50%\" valign=\"top\">\n"; }
9893 if ($Debug) { debug("ShowKeyphrasesStats",2); }
9894 &tab_head("$Message[120] ($Message[77] $MaxNbOf{'KeyphrasesShown'})<br /><a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=keyphrases"):"$PROG$StaticLinks.keyphrases.$StaticExt")."\"$NewLinkTarget>$Message[80]</a>",19,($ShowKeyphrasesStats && $ShowKeywordsStats)?95:70,'keyphrases');
9895 print "<tr bgcolor=\"#$color_TableBGRowTitle\"".Tooltip(15)."><th>$TotalDifferentKeyphrases $Message[103]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
9896 $total_s=0;
9897 my $count=0;
9898 &BuildKeyList($MaxNbOf{'KeyphrasesShown'},$MinHit{'Keyphrase'},\%_keyphrases,\%_keyphrases);
9899 foreach my $key (@keylist) {
9900 my $mot;
9901 # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
9902 if ($PluginsLoaded{'DecodeKey'}{'decodeutfkeys'}) { $mot=CleanFromCSSA(DecodeKey_decodeutfkeys($key,$PageCode||'iso-8859-1')); }
9903 else { $mot = CleanFromCSSA(DecodeEncodedString($key)); }
9904 my $p;
9905 if ($TotalKeyphrases) { $p=int($_keyphrases{$key}/$TotalKeyphrases*1000)/10; }
9906 print "<tr><td class=\"aws\">".XMLEncode($mot)."</td><td>$_keyphrases{$key}</td><td>$p %</td></tr>\n";
9907 $total_s += $_keyphrases{$key};
9908 $count++;
9909 }
9910 if ($Debug) { debug("Total real / shown : $TotalKeyphrases / $total_s",2); }
9911 $rest_s=$TotalKeyphrases-$total_s;
9912 if ($rest_s > 0) {
9913 rizwank 1.1 my $p;
9914 if ($TotalKeyphrases) { $p=int($rest_s/$TotalKeyphrases*1000)/10; }
9915 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[124]</span></td><td>$rest_s</td>";
9916 print "<td>$p %</td></tr>\n";
9917 }
9918 &tab_end();
9919 if ($ShowKeyphrasesStats && $ShowKeywordsStats) { print "</td>\n"; }
9920 }
9921 if ($ShowKeyphrasesStats && $ShowKeywordsStats) { print "<td> </td>"; }
9922 if ($ShowKeywordsStats) {
9923 # By Keywords
9924 if ($ShowKeyphrasesStats && $ShowKeywordsStats) { print "<td width=\"50%\" valign=\"top\">\n"; }
9925 if ($Debug) { debug("ShowKeywordsStats",2); }
9926 &tab_head("$Message[121] ($Message[77] $MaxNbOf{'KeywordsShown'})<br /><a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=keywords"):"$PROG$StaticLinks.keywords.$StaticExt")."\"$NewLinkTarget>$Message[80]</a>",19,($ShowKeyphrasesStats && $ShowKeywordsStats)?95:70,'keywords');
9927 print "<tr bgcolor=\"#$color_TableBGRowTitle\"".Tooltip(15)."><th>$TotalDifferentKeywords $Message[13]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
9928 $total_s=0;
9929 my $count=0;
9930 &BuildKeyList($MaxNbOf{'KeywordsShown'},$MinHit{'Keyword'},\%_keywords,\%_keywords);
9931 foreach my $key (@keylist) {
9932 my $mot;
9933 # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
9934 rizwank 1.1 if ($PluginsLoaded{'DecodeKey'}{'decodeutfkeys'}) { $mot=CleanFromCSSA(DecodeKey_decodeutfkeys($key,$PageCode||'iso-8859-1')); }
9935 else { $mot = CleanFromCSSA(DecodeEncodedString($key)); }
9936 my $p;
9937 if ($TotalKeywords) { $p=int($_keywords{$key}/$TotalKeywords*1000)/10; }
9938 print "<tr><td class=\"aws\">".XMLEncode($mot)."</td><td>$_keywords{$key}</td><td>$p %</td></tr>\n";
9939 $total_s += $_keywords{$key};
9940 $count++;
9941 }
9942 if ($Debug) { debug("Total real / shown : $TotalKeywords / $total_s",2); }
9943 $rest_s=$TotalKeywords-$total_s;
9944 if ($rest_s > 0) {
9945 my $p;
9946 if ($TotalKeywords) { $p=int($rest_s/$TotalKeywords*1000)/10; }
9947 print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td><td>$rest_s</td>";
9948 print "<td>$p %</td></tr>\n";
9949 }
9950 &tab_end();
9951 if ($ShowKeyphrasesStats && $ShowKeywordsStats) { print "</td>\n"; }
9952 }
9953 if ($ShowKeyphrasesStats && $ShowKeywordsStats) { print "</tr></table>\n"; }
9954
9955 rizwank 1.1 print "\n<a name=\"other\"> </a>\n\n";
9956
9957 # BY MISC
9958 #----------------------------
9959 if ($ShowMiscStats) {
9960 if ($Debug) { debug("ShowMiscStats",2); }
9961 print "$Center<a name=\"misc\"> </a><br />\n";
9962 my $Totalh=0; my %new_browser_h=();
9963 if ($_misc_h{'AddToFavourites'}) {
9964 foreach my $key (keys %_browser_h) {
9965 $Totalh+=$_browser_h{$key};
9966 if ($key =~ /^msie/i) { $new_browser_h{"msiecumul"}+=$_browser_h{$key}; }
9967 }
9968 if ($new_browser_h{'msiecumul'}) { $_misc_h{'AddToFavourites'}=int(0.5+$_misc_h{'AddToFavourites'}*$Totalh/$new_browser_h{'msiecumul'}); }
9969 }
9970 my $title="$Message[139]";
9971 &tab_head("$title",19,0,'misc');
9972 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[139]</th>";
9973 print "<th width=\"100\"> </th>";
9974 print "<th width=\"100\"> </th>";
9975 print "</tr>\n";
9976 rizwank 1.1 my %label=('AddToFavourites'=>$Message[137],'JavascriptDisabled'=>$Message[168],'JavaEnabled'=>$Message[140],'DirectorSupport'=>$Message[141],
9977 'FlashSupport'=>$Message[142],'RealPlayerSupport'=>$Message[143],'QuickTimeSupport'=>$Message[144],
9978 'WindowsMediaPlayerSupport'=>$Message[145],'PDFSupport'=>$Message[146]);
9979 foreach my $key (@MiscListOrder) {
9980 my $mischar=substr($key,0,1);
9981 if ($ShowMiscStats !~ /$mischar/i) { next; }
9982 my $total=0;
9983 my $p;
9984 if ($MiscListCalc{$key} eq 'v') { $total=$TotalVisits; }
9985 if ($MiscListCalc{$key} eq 'u') { $total=$TotalUnique; }
9986 if ($MiscListCalc{$key} eq 'hm') { $total=$_misc_h{'TotalMisc'}||0; }
9987 if ($total) { $p=int($_misc_h{$key}/$total*1000)/10; }
9988 print "<tr>";
9989 print "<td class=\"aws\">".($PageDir eq 'rtl'?"<span dir=\"ltr\">":"").$label{$key}.($PageDir eq 'rtl'?"</span>":"")."</td>";
9990 if ($MiscListCalc{$key} eq 'v') { print "<td>".($_misc_h{$key}||0)." / $total $Message[12]</td>"; }
9991 if ($MiscListCalc{$key} eq 'u') { print "<td>".($_misc_h{$key}||0)." / $total $Message[18]</td>"; }
9992 if ($MiscListCalc{$key} eq 'hm') { print "<td>-</td>"; }
9993 print "<td>".($total?"$p %":" ")."</td>";
9994 print "</tr>\n";
9995 }
9996 &tab_end();
9997 rizwank 1.1 }
9998
9999 # BY HTTP STATUS
10000 #----------------------------
10001 if ($ShowHTTPErrorsStats) {
10002 if ($Debug) { debug("ShowHTTPErrorsStats",2); }
10003 print "$Center<a name=\"errors\"> </a><br />\n";
10004 my $title="$Message[32]";
10005 &tab_head("$title",19,0,'errors');
10006 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[32]*</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th></tr>\n";
10007 $total_h=0;
10008 my $count=0;
10009 &BuildKeyList($MaxRowsInHTMLOutput,1,\%_errors_h,\%_errors_h);
10010 foreach my $key (@keylist) {
10011 my $p=int($_errors_h{$key}/$TotalHitsErrors*1000)/10;
10012 print "<tr".Tooltip($key,$key).">";
10013 if ($TrapInfosForHTTPErrorCodes{$key}) { print "<td><a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=errors$key"):"$PROG$StaticLinks.errors$key.$StaticExt")."\"$NewLinkTarget>$key</a></td>"; }
10014 else { print "<td valign=\"top\">$key</td>"; }
10015 print "<td class=\"aws\">".($httpcodelib{$key}?$httpcodelib{$key}:'Unknown error')."</td><td>$_errors_h{$key}</td><td>$p %</td><td>".Format_Bytes($_errors_k{$key})."</td>";
10016 print "</tr>\n";
10017 $total_h+=$_errors_h{$key};
10018 rizwank 1.1 $count++;
10019 }
10020 &tab_end("* $Message[154]");
10021 }
10022
10023 # BY SMTP STATUS
10024 #----------------------------
10025 if ($ShowSMTPErrorsStats) {
10026 if ($Debug) { debug("ShowSMTPErrorsStats",2); }
10027 print "$Center<a name=\"errors\"> </a><br />\n";
10028 my $title="$Message[147]";
10029 &tab_head("$title",19,0,'errors');
10030 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[147]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th></tr>\n";
10031 $total_h=0;
10032 my $count=0;
10033 &BuildKeyList($MaxRowsInHTMLOutput,1,\%_errors_h,\%_errors_h);
10034 foreach my $key (@keylist) {
10035 my $p=int($_errors_h{$key}/$TotalHitsErrors*1000)/10;
10036 print "<tr".Tooltip($key,$key).">";
10037 print "<td valign=\"top\">$key</td>";
10038 print "<td class=\"aws\">".($smtpcodelib{$key}?$smtpcodelib{$key}:'Unknown error')."</td><td>$_errors_h{$key}</td><td>$p %</td><td>".Format_Bytes($_errors_k{$key})."</td>";
10039 rizwank 1.1 print "</tr>\n";
10040 $total_h+=$_errors_h{$key};
10041 $count++;
10042 }
10043 &tab_end();
10044 }
10045
10046 # BY CLUSTER
10047 #----------------------------
10048 if ($ShowClusterStats) {
10049 if ($Debug) { debug("ShowClusterStats",2); }
10050 print "$Center<a name=\"clusters\"> </a><br />\n";
10051 my $title="$Message[155]";
10052 &tab_head("$title",19,0,'clusters');
10053 print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[155]</th>";
10054 &ShowClusterInfo('__title__');
10055 if ($ShowClusterStats =~ /P/i) { print "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>"; }
10056 if ($ShowClusterStats =~ /H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>"; }
10057 if ($ShowClusterStats =~ /B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[15]</th>"; }
10058 print "</tr>\n";
10059 $total_p=$total_h=$total_k=0;
10060 rizwank 1.1 # Cluster feature might have been enable in middle of month so we recalculate
10061 # total for cluster section only, to calculate ratio, instead of using global total
10062 foreach my $key (keys %_cluster_h) {
10063 $total_p+=int($_cluster_p{$key}||0);
10064 $total_h+=int($_cluster_h{$key}||0);
10065 $total_k+=int($_cluster_k{$key}||0);
10066 }
10067 my $count=0;
10068 foreach my $key (keys %_cluster_h) {
10069 my $p_p=int($_cluster_p{$key}/$total_p*1000)/10;
10070 my $p_h=int($_cluster_h{$key}/$total_h*1000)/10;
10071 my $p_k=int($_cluster_k{$key}/$total_k*1000)/10;
10072 print "<tr>";
10073 print "<td class=\"aws\">Computer $key</td>";
10074 &ShowClusterInfo($key);
10075 if ($ShowClusterStats =~ /P/i) { print "<td>".($_cluster_p{$key}?$_cluster_p{$key}:" ")."</td><td>$p_p %</td>"; }
10076 if ($ShowClusterStats =~ /H/i) { print "<td>$_cluster_h{$key}</td><td>$p_h %</td>"; }
10077 if ($ShowClusterStats =~ /B/i) { print "<td>".Format_Bytes($_cluster_k{$key})."</td><td>$p_k %</td>"; }
10078 print "</tr>\n";
10079 $count++;
10080 }
10081 rizwank 1.1 &tab_end();
10082 }
10083
10084 # BY EXTRA SECTIONS
10085 #----------------------------
10086 foreach my $extranum (1..@ExtraName-1) {
10087 if ($Debug) { debug("ExtraName$extranum",2); }
10088 print "$Center<a name=\"extra$extranum\"> </a><br />";
10089 my $title=$ExtraName[$extranum];
10090 &tab_head("$title",19,0,"extra$extranum");
10091 print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
10092 print "<th>".$ExtraFirstColumnTitle[$extranum]."</th>";
10093 if ($ExtraStatTypes[$extranum] =~ m/P/i) { print "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>"; }
10094 if ($ExtraStatTypes[$extranum] =~ m/H/i) { print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>"; }
10095 if ($ExtraStatTypes[$extranum] =~ m/B/i) { print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>"; }
10096 if ($ExtraStatTypes[$extranum] =~ m/L/i) { print "<th width=\"120\">$Message[9]</th>"; }
10097 print "</tr>\n";
10098 $total_p=$total_h=$total_k=0;
10099 #$max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
10100 #$max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
10101 my $count=0;
10102 rizwank 1.1 if ($ExtraStatTypes[$extranum] =~ m/P/i) {
10103 &BuildKeyList($MaxNbOfExtra[$extranum],$MinHitExtra[$extranum],\%{'_section_' . $extranum . '_h'},\%{'_section_' . $extranum . '_p'});
10104 }
10105 else {
10106 &BuildKeyList($MaxNbOfExtra[$extranum],$MinHitExtra[$extranum],\%{'_section_' . $extranum . '_h'},\%{'_section_' . $extranum . '_h'});
10107 }
10108 foreach my $key (@keylist) {
10109 my $firstcol = CleanFromCSSA(DecodeEncodedString($key));
10110 $total_p+=${'_section_' . $extranum . '_p'}{$key};
10111 $total_h+=${'_section_' . $extranum . '_h'}{$key};
10112 $total_k+=${'_section_' . $extranum . '_k'}{$key};
10113 print "<tr>";
10114 printf("<td class=\"aws\">$ExtraFirstColumnFormat[$extranum]</td>", $firstcol, $firstcol, $firstcol, $firstcol, $firstcol);
10115 if ($ExtraStatTypes[$extranum] =~ m/P/i) { print "<td>" . ${'_section_' . $extranum . '_p'}{$key} . "</td>"; }
10116 if ($ExtraStatTypes[$extranum] =~ m/H/i) { print "<td>" . ${'_section_' . $extranum . '_h'}{$key} . "</td>"; }
10117 if ($ExtraStatTypes[$extranum] =~ m/B/i) { print "<td>" . Format_Bytes(${'_section_' . $extranum . '_k'}{$key}) . "</td>"; }
10118 if ($ExtraStatTypes[$extranum] =~ m/L/i) { print "<td>" . (${'_section_' . $extranum . '_l'}{$key}?Format_Date(${'_section_' . $extranum . '_l'}{$key},1):'-') . "</td>"; }
10119 print "</tr>\n";
10120 $count++;
10121 }
10122 if ($ExtraAddAverageRow[$extranum]) {
10123 rizwank 1.1 print "<tr>";
10124 print "<td class=\"aws\"><b>$Message[96]</b></td>";
10125 if ($ExtraStatTypes[$extranum] =~ m/P/i) { print "<td>" . ($count?($total_p/$count):" ") . "</td>"; }
10126 if ($ExtraStatTypes[$extranum] =~ m/H/i) { print "<td>" . ($count?($total_h/$count):" ") . "</td>"; }
10127 if ($ExtraStatTypes[$extranum] =~ m/B/i) { print "<td>" . ($count?Format_Bytes($total_k/$count):" ") . "</td>"; }
10128 if ($ExtraStatTypes[$extranum] =~ m/L/i) { print "<td> </td>"; }
10129 print "</tr>\n";
10130 }
10131 if ($ExtraAddSumRow[$extranum]) {
10132 print "<tr>";
10133 print "<td class=\"aws\"><b>$Message[102]</b></td>";
10134 if ($ExtraStatTypes[$extranum] =~ m/P/i) { print "<td>" . ($total_p) . "</td>"; }
10135 if ($ExtraStatTypes[$extranum] =~ m/H/i) { print "<td>" . ($total_h) . "</td>"; }
10136 if ($ExtraStatTypes[$extranum] =~ m/B/i) { print "<td>" . Format_Bytes($total_k) . "</td>"; }
10137 if ($ExtraStatTypes[$extranum] =~ m/L/i) { print "<td> </td>"; }
10138 print "</tr>\n";
10139 }
10140 &tab_end();
10141 }
10142
10143 &html_end(1);
10144 rizwank 1.1 }
10145 }
10146 else {
10147 print "Jumped lines in file: $lastlinenb\n";
10148 if ($lastlinenb) { print " Found $lastlinenb already parsed records.\n"; }
10149 print "Parsed lines in file: $NbOfLinesParsed\n";
10150 print " Found $NbOfLinesDropped dropped records,\n";
10151 print " Found $NbOfLinesCorrupted corrupted records,\n";
10152 print " Found $NbOfOldLines old records,\n";
10153 print " Found $NbOfNewLines new qualified records.\n";
10154 }
10155
10156 #sleep 10;
10157
10158 0; # Do not remove this line
10159
10160
10161 #-------------------------------------------------------
10162 # ALGORITHM SUMMARY
10163 #
10164 # Read_Config();
10165 rizwank 1.1 # Check_Config() and Init variables
10166 # if 'frame not index'
10167 # &Read_Language_Data($Lang);
10168 # if 'frame not mainleft'
10169 # &Read_Ref_Data();
10170 # &Read_Plugins();
10171 # html_head
10172 #
10173 # If 'migrate'
10174 # We create/update tmp file with
10175 # &Read_History_With_TmpUpdate(year,month,UPDATE,NOPURGE,"all");
10176 # Rename the tmp file
10177 # html_end
10178 # Exit
10179 # End of 'migrate'
10180 #
10181 # Get last history file name
10182 # Get value for $LastLine $LastLineNumber $LastLineOffset $LastLineChecksum with
10183 # &Read_History_With_TmpUpdate(lastyear,lastmonth,NOUPDATE,NOPURGE,"general");
10184 #
10185 # &Init_HashArray()
10186 rizwank 1.1 #
10187 # If 'update'
10188 # Loop on each new line in log file
10189 # lastlineoffset=lastlineoffsetnext; lastlineoffsetnext=file pointer position
10190 # If line corrupted, skip --> next on loop
10191 # Drop wrong virtual host --> next on loop
10192 # Drop wrong method/protocol --> next on loop
10193 # Check date --> next on loop
10194 # If line older than $LastLine, skip --> next on loop
10195 # So it's new line
10196 # $LastLine = time or record
10197 # Skip if url is /robots.txt --> next on loop
10198 # Skip line for @SkipHosts --> next on loop
10199 # Skip line for @SkipFiles --> next on loop
10200 # Skip line for @SkipUserAgent --> next on loop
10201 # Skip line for not @OnlyHosts --> next on loop
10202 # Skip line for not @OnlyFiles --> next on loop
10203 # Skip line for not @OnlyUserAgent --> next on loop
10204 # So it's new line approved
10205 # If other month/year, create/update tmp file and purge data arrays with
10206 # &Read_History_With_TmpUpdate(lastprocessedyear,lastprocessedmonth,UPDATE,PURGE,"all",lastlinenb,lastlineoffset,CheckSum($_));
10207 rizwank 1.1 # Define a clean Url and Query (set urlwithnoquery, tokenquery and standalonequery and $field[$pos_url])
10208 # Define PageBool and extension
10209 # Analyze: Misc tracker --> complete %misc
10210 # Analyze: Add to favorites --> complete %_misc, countedtraffic=1 (not counted anywhere)
10211 # If (!countedtraffic) Analyze: Worms --> complete %_worms, countedtraffic=1
10212 # If (!countedtraffic) Analyze: Status code --> complete %_error_, %_sider404, %_referrer404 --> countedtraffic=1
10213 # If (!countedtraffic) Analyze: Robots known --> complete %_robot, countedtraffic=1
10214 # If (!countedtraffic) Analyze: Robots unknown on robots.txt --> complete %_robot, countedtraffic=1
10215 # If (!countedtraffic) Analyze: File types - Compression
10216 # If (!countedtraffic) Analyze: Date - Hour - Pages - Hits - Kilo
10217 # If (!countedtraffic) Analyze: Login
10218 # If (!countedtraffic) Do DNS Lookup
10219 # If (!countedtraffic) Analyze: Country
10220 # If (!countedtraffic) Analyze: Host - Url - Session
10221 # If (!countedtraffic) Analyze: Browser - OS
10222 # If (!countedtraffic) Analyze: Referer
10223 # If (!countedtraffic) Analyze: EMail
10224 # Analyze: Cluster
10225 # Analyze: Extra (must be after 'Define a clean Url and Query')
10226 # If too many records, we flush data arrays with
10227 # &Read_History_With_TmpUpdate($lastprocessedyear,$lastprocessedmonth,UPDATE,PURGE,"all",lastlinenb,lastlineoffset,CheckSum($_));
10228 rizwank 1.1 # End of loop
10229 # Create/update tmp file
10230 # Seek to lastlineoffset to read and get last line into $_
10231 # &Read_History_With_TmpUpdate($lastprocessedyear,$lastprocessedmonth,UPDATE,PURGE,"all",lastlinenb,lastlineoffset,CheckSum($_))
10232 # Rename all tmp files
10233 # End of 'update'
10234 #
10235 # &Init_HashArray()
10236 #
10237 # If 'output'
10238 # Loop for each month of required year
10239 # &Read_History_With_TmpUpdate($YearRequired,monthloop,NOUPDATE,NOPURGE,"all" or "general time" if not required month)
10240 # End of loop
10241 # Show data arrays in HTML page
10242 # html_end
10243 # End of 'output'
10244 #-------------------------------------------------------
10245
10246 #-------------------------------------------------------
10247 # DNS CACHE FILE FORMATS SUPPORTED BY AWSTATS
10248 # Format /etc/hosts x.y.z.w hostname
10249 rizwank 1.1 # Format analog UT/60 x.y.z.w hostname
10250 #-------------------------------------------------------
10251
10252 #-------------------------------------------------------
10253 # IP Format (d=decimal on 16 bits, x=hexadecimal on 16 bits)
10254 #
10255 # 13.1.68.3 IPv4 (d.d.d.d)
10256 # 0:0:0:0:0:0:13.1.68.3 IPv6 (x:x:x:x:x:x:d.d.d.d)
10257 # ::13.1.68.3
10258 # 0:0:0:0:0:FFFF:13.1.68.3 IPv6 (x:x:x:x:x:x:d.d.d.d)
10259 # ::FFFF:13.1.68.3 IPv6
10260 #
10261 # 1070:0:0:0:0:800:200C:417B IPv6
10262 # 1070:0:0:0:0:800:200C:417B IPv6
10263 # 1070::800:200C:417B IPv6
10264 #-------------------------------------------------------
|