#!/usr/bin/perl
#------------------------------------------------------------------------------
# Free realtime web server logfile analyzer to show advanced web statistics.
# Works from command line or as a CGI. You must use this script as often as
# necessary from your scheduler to update your statistics and from command
# line or a browser to read report results.
# See AWStats documentation (in docs/ directory) for all setup instructions.
#------------------------------------------------------------------------------
# $Revision: 1.971 $ - $Author: eldy $ - $Date: 2010/10/16 17:24:03 $
require 5.007;
#$|=1;
#use warnings; # Must be used in test mode only. This reduce a little process speed
#use diagnostics; # Must be used in test mode only. This reduce a lot of process speed
use strict;
no strict "refs";
use Time::Local
; # use Time::Local 'timelocal_nocheck' is faster but not supported by all Time::Local modules
use Socket;
use Encode;
#------------------------------------------------------------------------------
# Defines
#------------------------------------------------------------------------------
use vars qw/ $REVISION $VERSION /;
$REVISION = '$Revision: 1.971 $';
$REVISION =~ /\s(.*)\s/;
$REVISION = $1;
$VERSION = "7.0 (build $REVISION)";
# ----- Constants -----
use vars qw/
$DEBUGFORCED $NBOFLINESFORBENCHMARK $FRAMEWIDTH $NBOFLASTUPDATELOOKUPTOSAVE
$LIMITFLUSH $NEWDAYVISITTIMEOUT $VISITTIMEOUT $NOTSORTEDRECORDTOLERANCE
$WIDTHCOLICON $TOOLTIPON
$lastyearbeforeupdate $lastmonthbeforeupdate $lastdaybeforeupdate $lasthourbeforeupdate $lastdatebeforeupdate
$NOHTML
/;
$DEBUGFORCED = 0
; # Force debug level to log lesser level into debug.log file (Keep this value to 0)
$NBOFLINESFORBENCHMARK = 8192
; # Benchmark info are printing every NBOFLINESFORBENCHMARK lines (Must be a power of 2)
$FRAMEWIDTH = 240; # Width of left frame when UseFramesWhenCGI is on
$NBOFLASTUPDATELOOKUPTOSAVE =
500; # Nb of records to save in DNS last update cache file
$LIMITFLUSH =
5000; # Nb of records in data arrays after how we need to flush data on disk
$NEWDAYVISITTIMEOUT = 764041; # Delay between 01-23:59:59 and 02-00:00:00
$VISITTIMEOUT = 10000
; # Lapse of time to consider a page load as a new visit. 10000 = 1 hour (Default = 10000)
$NOTSORTEDRECORDTOLERANCE = 20000
; # Lapse of time to accept a record if not in correct order. 20000 = 2 hour (Default = 20000)
$WIDTHCOLICON = 32;
$TOOLTIPON = 0; # Tooltips plugin loaded
$NOHTML = 0; # Suppress the html headers
# ----- Running variables -----
use vars qw/
$DIR $PROG $Extension
$Debug $ShowSteps
$DebugResetDone $DNSLookupAlreadyDone
$RunAsCli $UpdateFor $HeaderHTTPSent $HeaderHTMLSent
$LastLine $LastLineNumber $LastLineOffset $LastLineChecksum $LastUpdate
$lowerval
$PluginMode
$MetaRobot
$AverageVisits $AveragePages $AverageHits $AverageBytes
$TotalUnique $TotalVisits $TotalHostsKnown $TotalHostsUnknown
$TotalPages $TotalHits $TotalBytes $TotalHitsErrors
$TotalNotViewedPages $TotalNotViewedHits $TotalNotViewedBytes
$TotalEntries $TotalExits $TotalBytesPages $TotalDifferentPages
$TotalKeyphrases $TotalKeywords $TotalDifferentKeyphrases $TotalDifferentKeywords
$TotalSearchEnginesPages $TotalSearchEnginesHits $TotalRefererPages $TotalRefererHits $TotalDifferentSearchEngines $TotalDifferentReferer
$FrameName $Center $FileConfig $FileSuffix $Host $YearRequired $MonthRequired $DayRequired $HourRequired
$QueryString $SiteConfig $StaticLinks $PageCode $PageDir $PerlParsingFormat $UserAgent
$pos_vh $pos_host $pos_logname $pos_date $pos_tz $pos_method $pos_url $pos_code $pos_size
$pos_referer $pos_agent $pos_query $pos_gzipin $pos_gzipout $pos_compratio $pos_timetaken
$pos_cluster $pos_emails $pos_emailr $pos_hostr @pos_extra
/;
$DIR = $PROG = $Extension = '';
$Debug = $ShowSteps = 0;
$DebugResetDone = $DNSLookupAlreadyDone = 0;
$RunAsCli = $UpdateFor = $HeaderHTTPSent = $HeaderHTMLSent = 0;
$LastLine = $LastLineNumber = $LastLineOffset = $LastLineChecksum = 0;
$LastUpdate = 0;
$lowerval = 0;
$PluginMode = '';
$MetaRobot = 0;
$AverageVisits = $AveragePages = $AverageHits = $AverageBytes = 0;
$TotalUnique = $TotalVisits = $TotalHostsKnown = $TotalHostsUnknown = 0;
$TotalPages = $TotalHits = $TotalBytes = $TotalHitsErrors = 0;
$TotalNotViewedPages = $TotalNotViewedHits = $TotalNotViewedBytes = 0;
$TotalEntries = $TotalExits = $TotalBytesPages = $TotalDifferentPages = 0;
$TotalKeyphrases = $TotalKeywords = $TotalDifferentKeyphrases = 0;
$TotalDifferentKeywords = 0;
$TotalSearchEnginesPages = $TotalSearchEnginesHits = $TotalRefererPages = 0;
$TotalRefererHits = $TotalDifferentSearchEngines = $TotalDifferentReferer = 0;
(
$FrameName, $Center, $FileConfig, $FileSuffix,
$Host, $YearRequired, $MonthRequired, $DayRequired,
$HourRequired, $QueryString, $SiteConfig, $StaticLinks,
$PageCode, $PageDir, $PerlParsingFormat, $UserAgent
)
= ( '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' );
# ----- Plugins variable -----
use vars qw/ %PluginsLoaded $PluginDir $AtLeastOneSectionPlugin /;
%PluginsLoaded = ();
$PluginDir = '';
$AtLeastOneSectionPlugin = 0;
# ----- Time vars -----
use vars qw/
$starttime
$nowtime $tomorrowtime
$nowweekofmonth $nowweekofyear $nowdaymod $nowsmallyear
$nowsec $nowmin $nowhour $nowday $nowmonth $nowyear $nowwday $nowyday $nowns
$StartSeconds $StartMicroseconds
/;
$StartSeconds = $StartMicroseconds = 0;
# ----- Variables for config file reading -----
use vars qw/
$FoundNotPageList
/;
$FoundNotPageList = 0;
# ----- Config file variables -----
use vars qw/
$StaticExt
$DNSStaticCacheFile
$DNSLastUpdateCacheFile
$MiscTrackerUrl
$Lang
$MaxRowsInHTMLOutput
$MaxLengthOfShownURL
$MaxLengthOfStoredURL
$MaxLengthOfStoredUA
%BarPng
$BuildReportFormat
$BuildHistoryFormat
$ExtraTrackedRowsLimit
$DatabaseBreak
$SectionsToBeSaved
/;
$StaticExt = 'html';
$DNSStaticCacheFile = 'dnscache.txt';
$DNSLastUpdateCacheFile = 'dnscachelastupdate.txt';
$MiscTrackerUrl = '/js/awstats_misc_tracker.js';
$Lang = 'auto';
$SectionsToBeSaved = 'all';
$MaxRowsInHTMLOutput = 1000;
$MaxLengthOfShownURL = 64;
$MaxLengthOfStoredURL = 256; # Note: Apache LimitRequestLine is default to 8190
$MaxLengthOfStoredUA = 256;
%BarPng = (
'vv' => 'vv.png',
'vu' => 'vu.png',
'hu' => 'hu.png',
'vp' => 'vp.png',
'hp' => 'hp.png',
'he' => 'he.png',
'hx' => 'hx.png',
'vh' => 'vh.png',
'hh' => 'hh.png',
'vk' => 'vk.png',
'hk' => 'hk.png'
);
$BuildReportFormat = 'html';
$BuildHistoryFormat = 'text';
$ExtraTrackedRowsLimit = 500;
$DatabaseBreak = 'month';
use vars qw/
$DebugMessages $AllowToUpdateStatsFromBrowser $EnableLockForUpdate $DNSLookup $AllowAccessFromWebToAuthenticatedUsersOnly
$BarHeight $BarWidth $CreateDirDataIfNotExists $KeepBackupOfHistoricFiles
$NbOfLinesParsed $NbOfLinesDropped $NbOfLinesCorrupted $NbOfLinesComment $NbOfLinesBlank $NbOfOldLines $NbOfNewLines
$NbOfLinesShowsteps $NewLinePhase $NbOfLinesForCorruptedLog $PurgeLogFile $ArchiveLogRecords
$ShowDropped $ShowCorrupted $ShowUnknownOrigin $ShowDirectOrigin $ShowLinksToWhoIs
$ShowAuthenticatedUsers $ShowFileSizesStats $ShowScreenSizeStats $ShowSMTPErrorsStats
$ShowEMailSenders $ShowEMailReceivers $ShowWormsStats $ShowClusterStats
$IncludeInternalLinksInOriginSection
$AuthenticatedUsersNotCaseSensitive
$Expires $UpdateStats $MigrateStats $URLNotCaseSensitive $URLWithQuery $URLReferrerWithQuery
$DecodeUA
/;
(
$DebugMessages,
$AllowToUpdateStatsFromBrowser,
$EnableLockForUpdate,
$DNSLookup,
$AllowAccessFromWebToAuthenticatedUsersOnly,
$BarHeight,
$BarWidth,
$CreateDirDataIfNotExists,
$KeepBackupOfHistoricFiles,
$NbOfLinesParsed,
$NbOfLinesDropped,
$NbOfLinesCorrupted,
$NbOfLinesComment,
$NbOfLinesBlank,
$NbOfOldLines,
$NbOfNewLines,
$NbOfLinesShowsteps,
$NewLinePhase,
$NbOfLinesForCorruptedLog,
$PurgeLogFile,
$ArchiveLogRecords,
$ShowDropped,
$ShowCorrupted,
$ShowUnknownOrigin,
$ShowDirectOrigin,
$ShowLinksToWhoIs,
$ShowAuthenticatedUsers,
$ShowFileSizesStats,
$ShowScreenSizeStats,
$ShowSMTPErrorsStats,
$ShowEMailSenders,
$ShowEMailReceivers,
$ShowWormsStats,
$ShowClusterStats,
$IncludeInternalLinksInOriginSection,
$AuthenticatedUsersNotCaseSensitive,
$Expires,
$UpdateStats,
$MigrateStats,
$URLNotCaseSensitive,
$URLWithQuery,
$URLReferrerWithQuery,
$DecodeUA
)
= (
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
);
use vars qw/
$DetailedReportsOnNewWindows
$FirstDayOfWeek $KeyWordsNotSensitive $SaveDatabaseFilesWithPermissionsForEveryone
$WarningMessages $ShowLinksOnUrl $UseFramesWhenCGI
$ShowMenu $ShowSummary $ShowMonthStats $ShowDaysOfMonthStats $ShowDaysOfWeekStats
$ShowHoursStats $ShowDomainsStats $ShowHostsStats
$ShowRobotsStats $ShowSessionsStats $ShowPagesStats $ShowFileTypesStats $ShowDownloadsStats
$ShowOSStats $ShowBrowsersStats $ShowOriginStats
$ShowKeyphrasesStats $ShowKeywordsStats $ShowMiscStats $ShowHTTPErrorsStats
$AddDataArrayMonthStats $AddDataArrayShowDaysOfMonthStats $AddDataArrayShowDaysOfWeekStats $AddDataArrayShowHoursStats
/;
(
$DetailedReportsOnNewWindows,
$FirstDayOfWeek,
$KeyWordsNotSensitive,
$SaveDatabaseFilesWithPermissionsForEveryone,
$WarningMessages,
$ShowLinksOnUrl,
$UseFramesWhenCGI,
$ShowMenu,
$ShowSummary,
$ShowMonthStats,
$ShowDaysOfMonthStats,
$ShowDaysOfWeekStats,
$ShowHoursStats,
$ShowDomainsStats,
$ShowHostsStats,
$ShowRobotsStats,
$ShowSessionsStats,
$ShowPagesStats,
$ShowFileTypesStats,
$ShowDownloadsStats,
$ShowOSStats,
$ShowBrowsersStats,
$ShowOriginStats,
$ShowKeyphrasesStats,
$ShowKeywordsStats,
$ShowMiscStats,
$ShowHTTPErrorsStats,
$AddDataArrayMonthStats,
$AddDataArrayShowDaysOfMonthStats,
$AddDataArrayShowDaysOfWeekStats,
$AddDataArrayShowHoursStats
)
= (
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
);
use vars qw/
$AllowFullYearView
$LevelForRobotsDetection $LevelForWormsDetection $LevelForBrowsersDetection $LevelForOSDetection $LevelForRefererAnalyze
$LevelForFileTypesDetection $LevelForSearchEnginesDetection $LevelForKeywordsDetection
/;
(
$AllowFullYearView, $LevelForRobotsDetection,
$LevelForWormsDetection, $LevelForBrowsersDetection,
$LevelForOSDetection, $LevelForRefererAnalyze,
$LevelForFileTypesDetection, $LevelForSearchEnginesDetection,
$LevelForKeywordsDetection
)
= ( 2, 2, 0, 2, 2, 2, 2, 2, 2 );
use vars qw/
$DirLock $DirCgi $DirConfig $DirData $DirIcons $DirLang $AWScript $ArchiveFileName
$AllowAccessFromWebToFollowingIPAddresses $HTMLHeadSection $HTMLEndSection $LinksToWhoIs $LinksToIPWhoIs
$LogFile $LogType $LogFormat $LogSeparator $Logo $LogoLink $StyleSheet $WrapperScript $SiteDomain
$UseHTTPSLinkForUrl $URLQuerySeparators $URLWithAnchor $ErrorMessages $ShowFlagLinks
/;
(
$DirLock, $DirCgi,
$DirConfig, $DirData,
$DirIcons, $DirLang,
$AWScript, $ArchiveFileName,
$AllowAccessFromWebToFollowingIPAddresses, $HTMLHeadSection,
$HTMLEndSection, $LinksToWhoIs,
$LinksToIPWhoIs, $LogFile,
$LogType, $LogFormat,
$LogSeparator, $Logo,
$LogoLink, $StyleSheet,
$WrapperScript, $SiteDomain,
$UseHTTPSLinkForUrl, $URLQuerySeparators,
$URLWithAnchor, $ErrorMessages,
$ShowFlagLinks
)
= (
'', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', ''
);
use vars qw/
$color_Background $color_TableBG $color_TableBGRowTitle
$color_TableBGTitle $color_TableBorder $color_TableRowTitle $color_TableTitle
$color_text $color_textpercent $color_titletext $color_weekend $color_link $color_hover $color_other
$color_h $color_k $color_p $color_e $color_x $color_s $color_u $color_v
/;
(
$color_Background, $color_TableBG, $color_TableBGRowTitle,
$color_TableBGTitle, $color_TableBorder, $color_TableRowTitle,
$color_TableTitle, $color_text, $color_textpercent,
$color_titletext, $color_weekend, $color_link,
$color_hover, $color_other, $color_h,
$color_k, $color_p, $color_e,
$color_x, $color_s, $color_u,
$color_v
)
= (
'', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', ''
);
# ---------- Init arrays --------
use vars qw/
@RobotsSearchIDOrder_list1 @RobotsSearchIDOrder_list2 @RobotsSearchIDOrder_listgen
@SearchEnginesSearchIDOrder_list1 @SearchEnginesSearchIDOrder_list2 @SearchEnginesSearchIDOrder_listgen
@BrowsersSearchIDOrder @OSSearchIDOrder @WordsToExtractSearchUrl @WordsToCleanSearchUrl
@WormsSearchIDOrder
@RobotsSearchIDOrder @SearchEnginesSearchIDOrder
@_from_p @_from_h
@_time_p @_time_h @_time_k @_time_nv_p @_time_nv_h @_time_nv_k
@DOWIndex @fieldlib @keylist
/;
@RobotsSearchIDOrder = @SearchEnginesSearchIDOrder = ();
@_from_p = @_from_h = ();
@_time_p = @_time_h = @_time_k = @_time_nv_p = @_time_nv_h = @_time_nv_k = ();
@DOWIndex = @fieldlib = @keylist = ();
use vars qw/
@MiscListOrder %MiscListCalc
%OSFamily %BrowsersFamily @SessionsRange %SessionsAverage
%LangBrowserToLangAwstats %LangAWStatsToFlagAwstats %BrowsersSafariBuildToVersionHash
@HostAliases @AllowAccessFromWebToFollowingAuthenticatedUsers
@DefaultFile @SkipDNSLookupFor
@SkipHosts @SkipUserAgents @SkipFiles @SkipReferrers @NotPageFiles
@OnlyHosts @OnlyUserAgents @OnlyFiles @OnlyUsers
@URLWithQueryWithOnly @URLWithQueryWithout
@ExtraName @ExtraCondition @ExtraStatTypes @MaxNbOfExtra @MinHitExtra
@ExtraFirstColumnTitle @ExtraFirstColumnValues @ExtraFirstColumnFunction @ExtraFirstColumnFormat
@ExtraCodeFilter @ExtraConditionType @ExtraConditionTypeVal
@ExtraFirstColumnValuesType @ExtraFirstColumnValuesTypeVal
@ExtraAddAverageRow @ExtraAddSumRow
@PluginsToLoad
/;
@MiscListOrder = (
'AddToFavourites', 'JavascriptDisabled',
'JavaEnabled', 'DirectorSupport',
'FlashSupport', 'RealPlayerSupport',
'QuickTimeSupport', 'WindowsMediaPlayerSupport',
'PDFSupport'
);
%MiscListCalc = (
'TotalMisc' => '',
'AddToFavourites' => 'u',
'JavascriptDisabled' => 'hm',
'JavaEnabled' => 'hm',
'DirectorSupport' => 'hm',
'FlashSupport' => 'hm',
'RealPlayerSupport' => 'hm',
'QuickTimeSupport' => 'hm',
'WindowsMediaPlayerSupport' => 'hm',
'PDFSupport' => 'hm'
);
@SessionsRange =
( '0s-30s', '30s-2mn', '2mn-5mn', '5mn-15mn', '15mn-30mn', '30mn-1h', '1h+' );
%SessionsAverage = (
'0s-30s', 15, '30s-2mn', 75, '2mn-5mn', 210,
'5mn-15mn', 600, '15mn-30mn', 1350, '30mn-1h', 2700,
'1h+', 3600
);
# HTTP-Accept or Lang parameter => AWStats code to use for lang
# ISO-639-1 or 2 or other => awstats-xx.txt where xx is ISO-639-1
%LangBrowserToLangAwstats = (
'sq' => 'al',
'ar' => 'ar',
'ba' => 'ba',
'bg' => 'bg',
'zh-tw' => 'tw',
'zh' => 'cn',
'cs' => 'cz',
'de' => 'de',
'da' => 'dk',
'en' => 'en',
'et' => 'et',
'fi' => 'fi',
'fr' => 'fr',
'gl' => 'gl',
'es' => 'es',
'eu' => 'eu',
'ca' => 'ca',
'el' => 'gr',
'hu' => 'hu',
'is' => 'is',
'in' => 'id',
'it' => 'it',
'ja' => 'jp',
'kr' => 'ko',
'lv' => 'lv',
'nl' => 'nl',
'no' => 'nb',
'nb' => 'nb',
'nn' => 'nn',
'pl' => 'pl',
'pt' => 'pt',
'pt-br' => 'br',
'ro' => 'ro',
'ru' => 'ru',
'sr' => 'sr',
'sk' => 'sk',
'sv' => 'se',
'th' => 'th',
'tr' => 'tr',
'uk' => 'ua',
'cy' => 'cy',
'wlk' => 'cy'
);
%LangAWStatsToFlagAwstats =
( # If flag (country ISO-3166 two letters) is not same than AWStats Lang code
'ca' => 'es_cat',
'et' => 'ee',
'eu' => 'es_eu',
'cy' => 'wlk',
'gl' => 'glg',
'he' => 'il',
'ko' => 'kr',
'ar' => 'sa',
'sr' => 'cs'
);
@HostAliases = @AllowAccessFromWebToFollowingAuthenticatedUsers = ();
@DefaultFile = @SkipDNSLookupFor = ();
@SkipHosts = @SkipUserAgents = @NotPageFiles = @SkipFiles = @SkipReferrers = ();
@OnlyHosts = @OnlyUserAgents = @OnlyFiles = @OnlyUsers = ();
@URLWithQueryWithOnly = @URLWithQueryWithout = ();
@ExtraName = @ExtraCondition = @ExtraStatTypes = ();
@MaxNbOfExtra = @MinHitExtra = ();
@ExtraFirstColumnTitle = @ExtraFirstColumnValues = ();
@ExtraFirstColumnFunction = @ExtraFirstColumnFormat = ();
@ExtraCodeFilter = @ExtraConditionType = @ExtraConditionTypeVal = ();
@ExtraFirstColumnValuesType = @ExtraFirstColumnValuesTypeVal = ();
@ExtraAddAverageRow = @ExtraAddSumRow = ();
@PluginsToLoad = ();
# ---------- Init hash arrays --------
use vars qw/
%BrowsersHashIDLib %BrowsersHashIcon %BrowsersHereAreGrabbers
%DomainsHashIDLib
%MimeHashLib %MimeHashFamily
%OSHashID %OSHashLib
%RobotsHashIDLib %RobotsAffiliateLib
%SearchEnginesHashID %SearchEnginesHashLib %SearchEnginesWithKeysNotInQuery %SearchEnginesKnownUrl %NotSearchEnginesKeys
%WormsHashID %WormsHashLib %WormsHashTarget
/;
use vars qw/
%HTMLOutput %NoLoadPlugin %FilterIn %FilterEx
%BadFormatWarning
%MonthNumLib
%ValidHTTPCodes %ValidSMTPCodes
%TrapInfosForHTTPErrorCodes %NotPageList %DayBytes %DayHits %DayPages %DayVisits
%MaxNbOf %MinHit
%ListOfYears %HistoryAlreadyFlushed %PosInFile %ValueInFile
%val %nextval %egal
%TmpDNSLookup %TmpOS %TmpRefererServer %TmpRobot %TmpBrowser %MyDNSTable
/;
%HTMLOutput = %NoLoadPlugin = %FilterIn = %FilterEx = ();
%BadFormatWarning = ();
%MonthNumLib = ();
%ValidHTTPCodes = %ValidSMTPCodes = ();
%TrapInfosForHTTPErrorCodes = ();
$TrapInfosForHTTPErrorCodes{404} = 1; # TODO Add this in config file
%NotPageList = ();
%DayBytes = %DayHits = %DayPages = %DayVisits = ();
%MaxNbOf = %MinHit = ();
%ListOfYears = %HistoryAlreadyFlushed = %PosInFile = %ValueInFile = ();
%val = %nextval = %egal = ();
%TmpDNSLookup = %TmpOS = %TmpRefererServer = %TmpRobot = %TmpBrowser = ();
%MyDNSTable = ();
use vars qw/
%FirstTime %LastTime
%MonthHostsKnown %MonthHostsUnknown
%MonthUnique %MonthVisits
%MonthPages %MonthHits %MonthBytes
%MonthNotViewedPages %MonthNotViewedHits %MonthNotViewedBytes
%_session %_browser_h
%_domener_p %_domener_h %_domener_k %_errors_h %_errors_k
%_filetypes_h %_filetypes_k %_filetypes_gz_in %_filetypes_gz_out
%_host_p %_host_h %_host_k %_host_l %_host_s %_host_u
%_waithost_e %_waithost_l %_waithost_s %_waithost_u
%_keyphrases %_keywords %_os_h %_pagesrefs_p %_pagesrefs_h %_robot_h %_robot_k %_robot_l %_robot_r
%_worm_h %_worm_k %_worm_l %_login_h %_login_p %_login_k %_login_l %_screensize_h
%_misc_p %_misc_h %_misc_k
%_cluster_p %_cluster_h %_cluster_k
%_se_referrals_p %_se_referrals_h %_sider404_h %_referer404_h %_url_p %_url_k %_url_e %_url_x
%_downloads
%_unknownreferer_l %_unknownrefererbrowser_l
%_emails_h %_emails_k %_emails_l %_emailr_h %_emailr_k %_emailr_l
/;
&Init_HashArray();
# ---------- Init Regex --------
use vars qw/ $regclean1 $regclean2 $regdate /;
$regclean1 = qr/<(recnb|\/td)>/i;
$regclean2 = qr/<\/?[^<>]+>/i;
$regdate = qr/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;
# ---------- Init Tie::hash arrays --------
# Didn't find a tie that increase speed
#use Tie::StdHash;
#use Tie::Cache::LRU;
#tie %_host_p, 'Tie::StdHash';
#tie %TmpOS, 'Tie::Cache::LRU';
# PROTOCOL CODES
use vars qw/ %httpcodelib %ftpcodelib %smtpcodelib /;
# DEFAULT MESSAGE
use vars qw/ @Message /;
@Message = (
'Unknown',
'Unknown (unresolved ip)',
'Others',
'View details',
'Day',
'Month',
'Year',
'Statistics for',
'First visit',
'Last visit',
'Number of visits',
'Unique visitors',
'Visit',
'different keywords',
'Search',
'Percent',
'Traffic',
'Domains/Countries',
'Visitors',
'Pages-URL',
'Hours',
'Browsers',
'',
'Referers',
'Never updated (See \'Build/Update\' on awstats_setup.html page)',
'Visitors domains/countries',
'hosts',
'pages',
'different pages-url',
'Viewed',
'Other words',
'Pages not found',
'HTTP Error codes',
'Netscape versions',
'IE versions',
'Last Update',
'Connect to site from',
'Origin',
'Direct address / Bookmarks',
'Origin unknown',
'Links from an Internet Search Engine',
'Links from an external page (other web sites except search engines)',
'Links from an internal page (other page on same site)',
'Keyphrases used on search engines',
'Keywords used on search engines',
'Unresolved IP Address',
'Unknown OS (Referer field)',
'Required but not found URLs (HTTP code 404)',
'IP Address',
'Error Hits',
'Unknown browsers (Referer field)',
'different robots',
'visits/visitor',
'Robots/Spiders visitors',
'Free realtime logfile analyzer for advanced web statistics',
'of',
'Pages',
'Hits',
'Versions',
'Operating Systems',
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
'Navigation',
'File type',
'Update now',
'Bandwidth',
'Back to main page',
'Top',
'dd mmm yyyy - HH:MM',
'Filter',
'Full list',
'Hosts',
'Known',
'Robots',
'Sun',
'Mon',
'Tue',
'Wed',
'Thu',
'Fri',
'Sat',
'Days of week',
'Who',
'When',
'Authenticated users',
'Min',
'Average',
'Max',
'Web compression',
'Bandwidth saved',
'Compression on',
'Compression result',
'Total',
'different keyphrases',
'Entry',
'Code',
'Average size',
'Links from a NewsGroup',
'KB',
'MB',
'GB',
'Grabber',
'Yes',
'No',
'Info.',
'OK',
'Exit',
'Visits duration',
'Close window',
'Bytes',
'Search Keyphrases',
'Search Keywords',
'different refering search engines',
'different refering sites',
'Other phrases',
'Other logins (and/or anonymous users)',
'Refering search engines',
'Refering sites',
'Summary',
'Exact value not available in "Year" view',
'Data value arrays',
'Sender EMail',
'Receiver EMail',
'Reported period',
'Extra/Marketing',
'Screen sizes',
'Worm/Virus attacks',
'Hit on favorite icon',
'Days of month',
'Miscellaneous',
'Browsers with Java support',
'Browsers with Macromedia Director Support',
'Browsers with Flash Support',
'Browsers with Real audio playing support',
'Browsers with Quictime audio playing support',
'Browsers with Windows Media audio playing support',
'Browsers with PDF support',
'SMTP Error codes',
'Countries',
'Mails',
'Size',
'First',
'Last',
'Exclude filter',
'Codes shown here gave hits or traffic "not viewed" by visitors, so they are not included in other charts.',
'Cluster',
'Robots shown here gave hits or traffic "not viewed" by visitors, so they are not included in other charts.',
'Numbers after + are successful hits on "robots.txt" files',
'Worms shown here gave hits or traffic "not viewed" by visitors, so thay are not included in other charts.',
'Not viewed traffic includes traffic generated by robots, worms, or replies with special HTTP status codes.',
'Traffic viewed',
'Traffic not viewed',
'Monthly history',
'Worms',
'different worms',
'Mails successfully sent',
'Mails failed/refused',
'Sensitive targets',
'Javascript disabled',
'Created by',
'plugins',
'Regions',
'Cities',
'Opera versions',
'Safari versions',
'Chrome versions',
'Konqueror versions',
',',
'Downloads',
);
#------------------------------------------------------------------------------
# Functions
#------------------------------------------------------------------------------
# Function to solve pb with openvms
sub file_filt (@) {
my @retval;
foreach my $fl (@_) {
$fl =~ tr/^//d;
push @retval, $fl;
}
return sort @retval;
}
#------------------------------------------------------------------------------
# Function: Write on output header of HTTP answer
# Parameters: None
# Input: $HeaderHTTPSent $BuildReportFormat $PageCode $Expires
# Output: $HeaderHTTPSent=1
# Return: None
#------------------------------------------------------------------------------
sub http_head {
if ( !$HeaderHTTPSent ) {
my $newpagecode = $PageCode ? $PageCode : "utf-8";
if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' ) {
print( $ENV{'HTTP_USER_AGENT'} =~ /MSIE|Googlebot/i
? "Content-type: text/html; charset=$newpagecode\n"
: "Content-type: text/xml; charset=$newpagecode\n"
);
}
else { print "Content-type: text/html; charset=$newpagecode\n"; }
# Expires must be GMT ANSI asctime and must be after Content-type to avoid pb with some servers (SAMBAR)
if ( $Expires =~ /^\d+$/ ) {
print "Cache-Control: public\n";
print "Last-Modified: " . gmtime($starttime) . "\n";
print "Expires: " . ( gmtime( $starttime + $Expires ) ) . "\n";
}
print "\n";
}
$HeaderHTTPSent++;
}
#------------------------------------------------------------------------------
# Function: Write on output header of HTML page
# Parameters: None
# Input: %HTMLOutput $PluginMode $Expires $Lang $StyleSheet $HTMLHeadSection $PageCode $PageDir
# Output: $HeaderHTMLSent=1
# Return: None
#------------------------------------------------------------------------------
sub html_head {
my $dir = $PageDir ? 'right' : 'left';
if ($NOHTML) { return; }
if ( scalar keys %HTMLOutput || $PluginMode ) {
my $periodtitle = " ($YearRequired";
$periodtitle .= ( $MonthRequired ne 'all' ? "-$MonthRequired" : "" );
$periodtitle .= ( $DayRequired ne '' ? "-$DayRequired" : "" );
$periodtitle .= ( $HourRequired ne '' ? "-$HourRequired" : "" );
$periodtitle .= ")";
# Write head section
if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' ) {
if ($PageCode) {
print "\n";
}
else { print "\n"; }
if ( $FrameName ne 'index' ) {
print
"\n";
}
else {
print
"\n";
}
print
"\n";
}
else {
if ( $FrameName ne 'index' ) {
print
"\n";
}
else {
print
"\n";
}
print '\n";
}
print "
\n";
my $endtag = '>';
if ( $BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml' ) {
$endtag = ' />';
}
# Affiche tag meta generator
print
" \n"
: " $Message[7] $SiteDomain$periodtitle"
. ( $k[0] ? " - " . $k[0] : "" )
. "\n";
if ( $FrameName ne 'index' ) {
if ($StyleSheet) {
print " \n";
}
# A STYLE section must be in head section. Do not use " for number in a style section
print "\n";
}
# les scripts necessaires pour trier avec Tablekit
# print "
# This make the browser sending a request to the attacker server that contains
# cookie used for AWStats server sessions. Attacker can this way caught this
# cookie and used it to go on AWStats server like original visitor. For this
# resaon, parameter received by AWStats must be sanitized by this function
# before beeing put inside a web page.
# Parameters: stringtoclean
# Input: None
# Output: None
# Return: cleanedstring
#------------------------------------------------------------------------------
sub CleanXSS {
my $stringtoclean = shift;
# To avoid html tags and javascript
$stringtoclean =~ s/</g;
$stringtoclean =~ s/>/>/g;
$stringtoclean =~ s/|//g;
# To avoid onload="
$stringtoclean =~ s/onload//g;
return $stringtoclean;
}
#------------------------------------------------------------------------------
# Function: Clean tags in a string
# AWStats data files are stored in ISO-8859-1.
# Parameters: stringtodecode
# Input: None
# Output: None
# Return: decodedstring
#------------------------------------------------------------------------------
sub XMLDecodeFromHisto {
my $stringtoclean = shift;
$stringtoclean =~ s/$regclean1/ /g; # Replace or with space
$stringtoclean =~ s/$regclean2//g; # Remove others
$stringtoclean =~ s/%3d/=/g;
$stringtoclean =~ s/&/&/g;
$stringtoclean =~ s/<//g;
$stringtoclean =~ s/"/\"/g;
$stringtoclean =~ s/'/\'/g;
return $stringtoclean;
}
#------------------------------------------------------------------------------
# Function: Copy one file into another
# Parameters: sourcefilename targetfilename
# Input: None
# Output: None
# Return: 0 if copy is ok, 1 else
#------------------------------------------------------------------------------
sub FileCopy {
my $filesource = shift;
my $filetarget = shift;
if ($Debug) { debug( "FileCopy($filesource,$filetarget)", 1 ); }
open( FILESOURCE, "$filesource" ) || return 1;
open( FILETARGET, ">$filetarget" ) || return 1;
binmode FILESOURCE;
binmode FILETARGET;
# ...
close(FILETARGET);
close(FILESOURCE);
if ($Debug) { debug( " File copied", 1 ); }
return 0;
}
#------------------------------------------------------------------------------
# Function: Format a QUERY_STRING
# Parameters: query
# Input: None
# Output: None
# Return: formated query
#------------------------------------------------------------------------------
# TODO Appeller cette fonction partout ou il y a des NewLinkParams
sub CleanNewLinkParamsFrom {
my $NewLinkParams = shift;
while ( my $param = shift ) {
$NewLinkParams =~ s/(^|&|&)$param(=[^&]*|$)//i;
}
$NewLinkParams =~ s/(&|&)+/&/i;
$NewLinkParams =~ s/^&//;
$NewLinkParams =~ s/&$//;
return $NewLinkParams;
}
#------------------------------------------------------------------------------
# Function: Show flags for other language translations
# Parameters: Current languade id (en, fr, ...)
# Input: None
# Output: None
# Return: None
#------------------------------------------------------------------------------
sub Show_Flag_Links {
my $CurrentLang = shift;
# Build flags link
my $NewLinkParams = $QueryString;
my $NewLinkTarget = '';
if ( $ENV{'GATEWAY_INTERFACE'} ) {
$NewLinkParams =
CleanNewLinkParamsFrom( $NewLinkParams,
( 'update', 'staticlinks', 'framename', 'lang' ) );
$NewLinkParams =~ s/(^|&|&)update(=\w*|$)//i;
$NewLinkParams =~ s/(^|&|&)staticlinks(=\w*|$)//i;
$NewLinkParams =~ s/(^|&|&)framename=[^&]*//i;
$NewLinkParams =~ s/(^|&|&)lang=[^&]*//i;
$NewLinkParams =~ s/(&|&)+/&/i;
$NewLinkParams =~ s/^&//;
$NewLinkParams =~ s/&$//;
if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&"; }
if ( $FrameName eq 'mainright' ) {
$NewLinkTarget = " target=\"_parent\"";
}
}
else {
$NewLinkParams =
( $SiteConfig ? "config=$SiteConfig&" : "" )
. "year=$YearRequired&month=$MonthRequired&";
}
if ( $NewLinkParams !~ /output=/ ) { $NewLinkParams .= 'output=main&'; }
if ( $FrameName eq 'mainright' ) {
$NewLinkParams .= 'framename=index&';
}
foreach my $lng ( split( /\s+/, $ShowFlagLinks ) ) {
$lng =
$LangBrowserToLangAwstats{$lng}
? $LangBrowserToLangAwstats{$lng}
: $lng;
if ( $lng ne $CurrentLang ) {
my %lngtitle = (
'en', 'English', 'fr', 'French', 'de', 'German',
'it', 'Italian', 'nl', 'Dutch', 'es', 'Spanish'
);
my $lngtitle = ( $lngtitle{$lng} ? $lngtitle{$lng} : $lng );
my $flag = (
$LangAWStatsToFlagAwstats{$lng}
? $LangAWStatsToFlagAwstats{$lng}
: $lng
);
print " \n";
}
}
}
#------------------------------------------------------------------------------
# Function: Format value in bytes in a string (Bytes, Kb, Mb, Gb)
# Parameters: bytes (integer value or "0.00")
# Input: None
# Output: None
# Return: "x.yz MB" or "x.yy KB" or "x Bytes" or "0"
#------------------------------------------------------------------------------
sub Format_Bytes {
my $bytes = shift || 0;
my $fudge = 1;
# Do not use exp/log function to calculate 1024power, function make segfault on some unix/perl versions
if ( $bytes >= ( $fudge << 30 ) ) {
return sprintf( "%.2f", $bytes / 1073741824 ) . " $Message[110]";
}
if ( $bytes >= ( $fudge << 20 ) ) {
return sprintf( "%.2f", $bytes / 1048576 ) . " $Message[109]";
}
if ( $bytes >= ( $fudge << 10 ) ) {
return sprintf( "%.2f", $bytes / 1024 ) . " $Message[108]";
}
if ( $bytes < 0 ) { $bytes = "?"; }
return int($bytes) . ( int($bytes) ? " $Message[119]" : "" );
}
#------------------------------------------------------------------------------
# Function: Format a number with commas or any other separator
# CL: courtesy of http://www.perlmonks.org/?node_id=2145
# Parameters: number
# Input: None
# Output: None
# Return: "999,999,999,999"
#------------------------------------------------------------------------------
sub Format_Number {
my $number = shift || 0;
$number =~ s/(\d)(\d\d\d)$/$1 $2/;
$number =~ s/(\d)(\d\d\d\s\d\d\d)$/$1 $2/;
$number =~ s/(\d)(\d\d\d\s\d\d\d\s\d\d\d)$/$1 $2/;
my $separator = $Message[177];
if ($separator eq '') { $separator=' '; } # For backward compatibility
$number =~ s/ /$separator/g;
return $number;
}
#------------------------------------------------------------------------------
# Function: Return " alt=string title=string"
# Parameters: string
# Input: None
# Output: None
# Return: "alt=string title=string"
#------------------------------------------------------------------------------
sub AltTitle {
my $string = shift || '';
return " alt='$string' title='$string'";
# return " alt=\"$string\" title=\"$string\"";
# return ($BuildReportFormat?"":" alt=\"$string\"")." title=\"$string\"";
}
#------------------------------------------------------------------------------
# Function: Tell if an email is a local or external email
# Parameters: email
# Input: $SiteDomain(exact string) $HostAliases(quoted regex string)
# Output: None
# Return: -1, 0 or 1
#------------------------------------------------------------------------------
sub IsLocalEMail {
my $email = shift || 'unknown';
if ( $email !~ /\@(.*)$/ ) { return 0; }
my $domain = $1;
if ( $domain =~ /^$SiteDomain$/i ) { return 1; }
foreach (@HostAliases) {
if ( $domain =~ /$_/ ) { return 1; }
}
return -1;
}
#------------------------------------------------------------------------------
# Function: Format a date according to Message[78] (country date format)
# Parameters: String date YYYYMMDDHHMMSS
# Option 0=LastUpdate and LastTime date
# 1=Arrays date except daymonthvalues
# 2=daymonthvalues date (only year month and day)
# Input: $Message[78]
# Output: None
# Return: Date with format defined by Message[78] and option
#------------------------------------------------------------------------------
sub Format_Date {
my $date = shift;
my $option = shift || 0;
my $year = substr( "$date", 0, 4 );
my $month = substr( "$date", 4, 2 );
my $day = substr( "$date", 6, 2 );
my $hour = substr( "$date", 8, 2 );
my $min = substr( "$date", 10, 2 );
my $sec = substr( "$date", 12, 2 );
my $dateformat = $Message[78];
if ( $option == 2 ) {
$dateformat =~ s/^[^ymd]+//g;
$dateformat =~ s/[^ymd]+$//g;
}
$dateformat =~ s/yyyy/$year/g;
$dateformat =~ s/yy/$year/g;
$dateformat =~ s/mmm/$MonthNumLib{$month}/g;
$dateformat =~ s/mm/$month/g;
$dateformat =~ s/dd/$day/g;
$dateformat =~ s/HH/$hour/g;
$dateformat =~ s/MM/$min/g;
$dateformat =~ s/SS/$sec/g;
return "$dateformat";
}
#------------------------------------------------------------------------------
# Function: Return 1 if string contains only ascii chars
# Parameters: string
# Input: None
# Output: None
# Return: 0 or 1
#------------------------------------------------------------------------------
sub IsAscii {
my $string = shift;
if ($Debug) { debug( "IsAscii($string)", 5 ); }
if ( $string =~ /^[\w\+\-\/\\\.%,;:=\"\'&?!\s]+$/ ) {
if ($Debug) { debug( " Yes", 6 ); }
return
1
; # Only alphanum chars (and _) or + - / \ . % , ; : = " ' & ? space \t
}
if ($Debug) { debug( " No", 6 ); }
return 0;
}
#------------------------------------------------------------------------------
# Function: Return the lower value between 2 but exclude value if 0
# Parameters: Val1 and Val2
# Input: None
# Output: None
# Return: min(Val1,Val2)
#------------------------------------------------------------------------------
sub MinimumButNoZero {
my ( $val1, $val2 ) = @_;
return ( $val1 && ( $val1 < $val2 || !$val2 ) ? $val1 : $val2 );
}
#------------------------------------------------------------------------------
# Function: Add a val from sorting tree
# Parameters: keytoadd keyval [firstadd]
# Input: None
# Output: None
# Return: None
#------------------------------------------------------------------------------
sub AddInTree {
my $keytoadd = shift;
my $keyval = shift;
my $firstadd = shift || 0;
if ( $firstadd == 1 ) { # Val is the first one
if ($Debug) { debug( " firstadd", 4 ); }
$val{$keyval} = $keytoadd;
$lowerval = $keyval;
if ($Debug) {
debug(
" lowerval=$lowerval, nb elem val="
. ( scalar keys %val )
. ", nb elem egal="
. ( scalar keys %egal ) . ".",
4
);
}
return;
}
if ( $val{$keyval} ) { # Val is already in tree
if ($Debug) { debug( " val is already in tree", 4 ); }
$egal{$keytoadd} = $val{$keyval};
$val{$keyval} = $keytoadd;
if ($Debug) {
debug(
" lowerval=$lowerval, nb elem val="
. ( scalar keys %val )
. ", nb elem egal="
. ( scalar keys %egal ) . ".",
4
);
}
return;
}
if ( $keyval <= $lowerval )
{ # Val is a new one lower (should happens only when tree is not full)
if ($Debug) {
debug(
" keytoadd val=$keyval is lower or equal to lowerval=$lowerval",
4
);
}
$val{$keyval} = $keytoadd;
$nextval{$keyval} = $lowerval;
$lowerval = $keyval;
if ($Debug) {
debug(
" lowerval=$lowerval, nb elem val="
. ( scalar keys %val )
. ", nb elem egal="
. ( scalar keys %egal ) . ".",
4
);
}
return;
}
# Val is a new one higher
if ($Debug) {
debug( " keytoadd val=$keyval is higher than lowerval=$lowerval", 4 );
}
$val{$keyval} = $keytoadd;
my $valcursor = $lowerval; # valcursor is value just before keyval
while ( $nextval{$valcursor} && ( $nextval{$valcursor} < $keyval ) ) {
$valcursor = $nextval{$valcursor};
}
if ( $nextval{$valcursor} )
{ # keyval is between valcursor and nextval{valcursor}
$nextval{$keyval} = $nextval{$valcursor};
}
$nextval{$valcursor} = $keyval;
if ($Debug) {
debug(
" lowerval=$lowerval, nb elem val="
. ( scalar keys %val )
. ", nb elem egal="
. ( scalar keys %egal ) . ".",
4
);
}
}
#------------------------------------------------------------------------------
# Function: Remove a val from sorting tree
# Parameters: None
# Input: $lowerval %val %egal
# Output: None
# Return: None
#------------------------------------------------------------------------------
sub Removelowerval {
my $keytoremove = $val{$lowerval}; # This is lower key
if ($Debug) {
debug( " remove for lowerval=$lowerval: key=$keytoremove", 4 );
}
if ( $egal{$keytoremove} ) {
$val{$lowerval} = $egal{$keytoremove};
delete $egal{$keytoremove};
}
else {
delete $val{$lowerval};
$lowerval = $nextval{$lowerval}; # Set new lowerval
}
if ($Debug) {
debug(
" new lower value=$lowerval, val size="
. ( scalar keys %val )
. ", egal size="
. ( scalar keys %egal ),
4
);
}
}
#------------------------------------------------------------------------------
# Function: Build @keylist array
# Parameters: Size max for @keylist array,
# Min value in hash for select,
# Hash used for select,
# Hash used for order
# Input: None
# Output: None
# Return: @keylist response array
#------------------------------------------------------------------------------
sub BuildKeyList {
my $ArraySize = shift || error(
"System error. Call to BuildKeyList function with incorrect value for first param",
"", "", 1
);
my $MinValue = shift || error(
"System error. Call to BuildKeyList function with incorrect value for second param",
"", "", 1
);
my $hashforselect = shift;
my $hashfororder = shift;
if ($Debug) {
debug(
" BuildKeyList($ArraySize,$MinValue,$hashforselect with size="
. ( scalar keys %$hashforselect )
. ",$hashfororder with size="
. ( scalar keys %$hashfororder ) . ")",
3
);
}
delete $hashforselect->{0};
delete $hashforselect->{ ''
}; # Those is to protect from infinite loop when hash array has an incorrect null key
my $count = 0;
$lowerval = 0; # Global because used in AddInTree and Removelowerval
%val = ();
%nextval = ();
%egal = ();
foreach my $key ( keys %$hashforselect ) {
if ( $count < $ArraySize ) {
if ( $hashforselect->{$key} >= $MinValue ) {
$count++;
if ($Debug) {
debug(
" Add in tree entry $count : $key (value="
. ( $hashfororder->{$key} || 0 )
. ", tree not full)",
4
);
}
AddInTree( $key, $hashfororder->{$key} || 0, $count );
}
next;
}
$count++;
if ( ( $hashfororder->{$key} || 0 ) <= $lowerval ) { next; }
if ($Debug) {
debug(
" Add in tree entry $count : $key (value="
. ( $hashfororder->{$key} || 0 )
. " > lowerval=$lowerval)",
4
);
}
AddInTree( $key, $hashfororder->{$key} || 0 );
if ($Debug) { debug( " Removelower in tree", 4 ); }
Removelowerval();
}
# Build key list and sort it
if ($Debug) {
debug(
" Build key list and sort it. lowerval=$lowerval, nb elem val="
. ( scalar keys %val )
. ", nb elem egal="
. ( scalar keys %egal ) . ".",
3
);
}
my %notsortedkeylist = ();
foreach my $key ( values %val ) { $notsortedkeylist{$key} = 1; }
foreach my $key ( values %egal ) { $notsortedkeylist{$key} = 1; }
@keylist = ();
@keylist = (
sort { ( $hashfororder->{$b} || 0 ) <=> ( $hashfororder->{$a} || 0 ) }
keys %notsortedkeylist
);
if ($Debug) {
debug( " BuildKeyList End (keylist size=" . (@keylist) . ")", 3 );
}
return;
}
#------------------------------------------------------------------------------
# Function: Lock or unlock update
# Parameters: status (1 to lock, 0 to unlock)
# Input: $DirLock (if status=0) $PROG $FileSuffix
# Output: $DirLock (if status=1)
# Return: None
#------------------------------------------------------------------------------
sub Lock_Update {
my $status = shift;
my $lock = "$PROG$FileSuffix.lock";
if ($status) {
# We stop if there is at least one lock file wherever it is
foreach my $key ( $ENV{"TEMP"}, $ENV{"TMP"}, "/tmp", "/", "." ) {
my $newkey = $key;
$newkey =~ s/[\\\/]$//;
if ( -f "$newkey/$lock" ) {
error(
"An AWStats update process seems to be already running for this config file. Try later.\nIf this is not true, remove manually lock file '$newkey/$lock'.",
"", "", 1
);
}
}
# Set lock where we can
foreach my $key ( $ENV{"TEMP"}, $ENV{"TMP"}, "/tmp", "/", "." ) {
if ( !-d "$key" ) { next; }
$DirLock = $key;
$DirLock =~ s/[\\\/]$//;
if ($Debug) { debug("Update lock file $DirLock/$lock is set"); }
open( LOCK, ">$DirLock/$lock" )
|| error( "Failed to create lock file $DirLock/$lock", "", "",
1 );
print LOCK
"AWStats update started by process $$ at $nowyear-$nowmonth-$nowday $nowhour:$nowmin:$nowsec\n";
close(LOCK);
last;
}
}
else {
# Remove lock
if ($Debug) { debug("Update lock file $DirLock/$lock is removed"); }
unlink("$DirLock/$lock");
}
return;
}
#------------------------------------------------------------------------------
# Function: Signal handler to call Lock_Update to remove lock file
# Parameters: Signal name
# Input: None
# Output: None
# Return: None
#------------------------------------------------------------------------------
sub SigHandler {
my $signame = shift;
print ucfirst($PROG) . " process (ID $$) interrupted by signal $signame.\n";
&Lock_Update(0);
exit 1;
}
#------------------------------------------------------------------------------
# Function: Convert an IPAddress into an integer
# Parameters: IPAddress
# Input: None
# Output: None
# Return: Int
#------------------------------------------------------------------------------
sub Convert_IP_To_Decimal {
my ($IPAddress) = @_;
my @ip_seg_arr = split( /\./, $IPAddress );
my $decimal_ip_address =
256 * 256 * 256 * $ip_seg_arr[0] + 256 * 256 * $ip_seg_arr[1] + 256 *
$ip_seg_arr[2] + $ip_seg_arr[3];
return ($decimal_ip_address);
}
#------------------------------------------------------------------------------
# Function: Test there is at least one value in list not null
# Parameters: List of values
# Input: None
# Output: None
# Return: 1 There is at least one not null value, 0 else
#------------------------------------------------------------------------------
sub AtLeastOneNotNull {
if ($Debug) {
debug( " Call to AtLeastOneNotNull (" . join( '-', @_ ) . ")", 3 );
}
foreach my $val (@_) {
if ($val) { return 1; }
}
return 0;
}
#------------------------------------------------------------------------------
# Function: Prints the command line interface help information
# Parameters: None
# Input: None
# Output: None
# Return: None
#------------------------------------------------------------------------------
sub PrintCLIHelp{
&Read_Ref_Data(
'browsers', 'domains', 'operating_systems', 'robots',
'search_engines', 'worms'
);
print "----- $PROG $VERSION (c) 2000-2010 Laurent Destailleur -----\n";
print
"AWStats is a free web server logfile analyzer to show you advanced web\n";
print "statistics.\n";
print
"AWStats comes with ABSOLUTELY NO WARRANTY. It's a free software distributed\n";
print "with a GNU General Public License (See LICENSE file for details).\n";
print "\n";
print "Syntax: $PROG.$Extension -config=virtualhostname [options]\n";
print "\n";
print
" This runs $PROG in command line to update statistics (-update option) of a\n";
print
" web site, from the log file defined in AWStats config file, or build a HTML\n";
print " report (-output option).\n";
print
" First, $PROG tries to read $PROG.virtualhostname.conf as the config file.\n";
print " If not found, $PROG tries to read $PROG.conf, and finally the full path passed to -config=\n";
print
" Note 1: Config files ($PROG.virtualhostname.conf or $PROG.conf) must be\n";
print
" in /etc/awstats, /usr/local/etc/awstats, /etc or same directory than\n";
print " awstats.pl script file.\n";
print
" Note 2: If AWSTATS_FORCE_CONFIG environment variable is defined, AWStats will\n";
print
" use it as the \"config\" value, whatever is the value on command line or URL.\n";
print " See AWStats documentation for all setup instrutions.\n";
print "\n";
print "Options to update statistics:\n";
print " -update to update statistics (default)\n";
print
" -showsteps to add benchmark information every $NBOFLINESFORBENCHMARK lines processed\n";
print
" -showcorrupted to add output for each corrupted lines found, with reason\n";
print
" -showdropped to add output for each dropped lines found, with reason\n";
print " -showunknownorigin to output referer when it can't be parsed\n";
print
" -showdirectorigin to output log line when origin is a direct access\n";
print " -updatefor=n to stop the update process after parsing n lines\n";
print
" -LogFile=x to change log to analyze whatever is 'LogFile' in config file\n";
print
" Be care to process log files in chronological order when updating statistics.\n";
print "\n";
print "Options to show statistics:\n";
print
" -output to output main HTML report (no update made except with -update)\n";
print " -output=x to output other report pages where x is:\n";
print
" alldomains to build page of all domains/countries\n";
print " allhosts to build page of all hosts\n";
print
" lasthosts to build page of last hits for hosts\n";
print
" unknownip to build page of all unresolved IP\n";
print
" allemails to build page of all email senders (maillog)\n";
print
" lastemails to build page of last email senders (maillog)\n";
print
" allemailr to build page of all email receivers (maillog)\n";
print
" lastemailr to build page of last email receivers (maillog)\n";
print " alllogins to build page of all logins used\n";
print
" lastlogins to build page of last hits for logins\n";
print
" allrobots to build page of all robots/spider visits\n";
print
" lastrobots to build page of last hits for robots\n";
print " urldetail to list most often viewed pages \n";
print
" urldetail:filter to list most often viewed pages matching filter\n";
print " urlentry to list entry pages\n";
print
" urlentry:filter to list entry pages matching filter\n";
print " urlexit to list exit pages\n";
print
" urlexit:filter to list exit pages matching filter\n";
print
" osdetail to build page with os detailed versions\n";
print
" browserdetail to build page with browsers detailed versions\n";
print
" unknownbrowser to list 'User Agents' with unknown browser\n";
print
" unknownos to list 'User Agents' with unknown OS\n";
print
" refererse to build page of all refering search engines\n";
print
" refererpages to build page of all refering pages\n";
#print " referersites to build page of all refering sites\n";
print
" keyphrases to list all keyphrases used on search engines\n";
print
" keywords to list all keywords used on search engines\n";
print " errors404 to list 'Referers' for 404 errors\n";
print
" allextraX to build page of all values for ExtraSection X\n";
print " -staticlinks to have static links in HTML report page\n";
print " -staticlinksext=xxx to have static links with .xxx extension instead of .html\n";
print
" -lang=LL to output a HTML report in language LL (en,de,es,fr,it,nl,...)\n";
print " -month=MM to output a HTML report for an old month MM\n";
print " -year=YYYY to output a HTML report for an old year YYYY\n";
print
" The 'date' options doesn't allow you to process old log file. They only\n";
print
" allow you to see a past report for a chosen month/year period instead of\n";
print " current month/year.\n";
print "\n";
print "Other options:\n";
print
" -debug=X to add debug informations lesser than level X (speed reduced)\n";
print "\n";
print "Now supports/detects:\n";
print
" Web/Ftp/Mail/streaming server log analyzis (and load balanced log files)\n";
print " Reverse DNS lookup (IPv4 and IPv6) and GeoIP lookup\n";
print " Number of visits, number of unique visitors\n";
print " Visits duration and list of last visits\n";
print " Authenticated users\n";
print " Days of week and rush hours\n";
print " Hosts list and unresolved IP addresses list\n";
print " Most viewed, entry and exit pages\n";
print " Files type and Web compression (mod_gzip, mod_deflate stats)\n";
print " Screen size\n";
print " Ratio of Browsers with support of: Java, Flash, RealG2 reader,\n";
print " Quicktime reader, WMA reader, PDF reader\n";
print " Configurable personalized reports\n";
print " " . ( scalar keys %DomainsHashIDLib ) . " domains/countries\n";
print " " . ( scalar keys %RobotsHashIDLib ) . " robots\n";
print " " . ( scalar keys %WormsHashLib ) . " worm's families\n";
print " " . ( scalar keys %OSHashLib ) . " operating systems\n";
print " " . ( scalar keys %BrowsersHashIDLib ) . " browsers";
&Read_Ref_Data('browsers_phone');
print " ("
. ( scalar keys %BrowsersHashIDLib )
. " with phone browsers database)\n";
print " "
. ( scalar keys %SearchEnginesHashLib )
. " search engines (and keyphrases/keywords used from them)\n";
print " All HTTP errors with last referrer\n";
print " Report by day/month/year\n";
print " Dynamic or static HTML or XHTML reports, static PDF reports\n";
print " Indexed text or XML monthly database\n";
print " And a lot of other advanced features and options...\n";
print "New versions and FAQ at http://awstats.sourceforge.net\n";
}
#------------------------------------------------------------------------------
# Function: Return the string to add in html tag to include popup javascript code
# Parameters: tooltip number
# Input: None
# Output: None
# Return: string with javascript code
#------------------------------------------------------------------------------
sub Tooltip {
my $ttnb = shift;
return (
$TOOLTIPON
? " onmouseover=\"ShowTip($ttnb);\" onmouseout=\"HideTip($ttnb);\""
: ""
);
}
#------------------------------------------------------------------------------
# Function: Insert a form filter
# Parameters: Name of filter field, default for filter field, default for exclude filter field
# Input: $StaticLinks, $QueryString, $SiteConfig, $DirConfig
# Output: HTML Form
# Return: None
#------------------------------------------------------------------------------
sub HTMLShowFormFilter {
my $fieldfiltername = shift;
my $fieldfilterinvalue = shift;
my $fieldfilterexvalue = shift;
if ( !$StaticLinks ) {
my $NewLinkParams = ${QueryString};
$NewLinkParams =~ s/(^|&|&)update(=\w*|$)//i;
$NewLinkParams =~ s/(^|&|&)output(=\w*|$)//i;
$NewLinkParams =~ s/(^|&|&)staticlinks(=\w*|$)//i;
$NewLinkParams =~ s/(&|&)+/&/i;
$NewLinkParams =~ s/^&//;
$NewLinkParams =~ s/&$//;
if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&"; }
print "\n\n";
print " \n";
print "\n";
}
}
#------------------------------------------------------------------------------
# Function: Write other user info (with help of plugin)
# Parameters: $user
# Input: $SiteConfig
# Output: URL link
# Return: None
#------------------------------------------------------------------------------
sub HTMLShowUserInfo {
my $user = shift;
# Call to plugins' function ShowInfoUser
foreach my $pluginname ( sort keys %{ $PluginsLoaded{'ShowInfoUser'} } ) {
# my $function="ShowInfoUser_$pluginname('$user')";
# eval("$function");
my $function = "ShowInfoUser_$pluginname";
&$function($user);
}
}
#------------------------------------------------------------------------------
# Function: Write other cluster info (with help of plugin)
# Parameters: $clusternb
# Input: $SiteConfig
# Output: Cluster info
# Return: None
#------------------------------------------------------------------------------
sub HTMLShowClusterInfo {
my $cluster = shift;
# Call to plugins' function ShowInfoCluster
foreach my $pluginname ( sort keys %{ $PluginsLoaded{'ShowInfoCluster'} } )
{
# my $function="ShowInfoCluster_$pluginname('$user')";
# eval("$function");
my $function = "ShowInfoCluster_$pluginname";
&$function($cluster);
}
}
#------------------------------------------------------------------------------
# Function: Write other host info (with help of plugin)
# Parameters: $host
# Input: $LinksToWhoIs $LinksToWhoIsIp
# Output: None
# Return: None
#------------------------------------------------------------------------------
sub HTMLShowHostInfo {
my $host = shift;
# Call to plugins' function ShowInfoHost
foreach my $pluginname ( sort keys %{ $PluginsLoaded{'ShowInfoHost'} } ) {
# my $function="ShowInfoHost_$pluginname('$host')";
# eval("$function");
my $function = "ShowInfoHost_$pluginname";
&$function($host);
}
}
#------------------------------------------------------------------------------
# Function: Write other url info (with help of plugin)
# Parameters: $url
# Input: %Aliases $MaxLengthOfShownURL $ShowLinksOnUrl $SiteDomain $UseHTTPSLinkForUrl
# Output: URL link
# Return: None
#------------------------------------------------------------------------------
sub HTMLShowURLInfo {
my $url = shift;
my $nompage = CleanXSS($url);
# Call to plugins' function ShowInfoURL
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowInfoURL'} } ) {
# my $function="ShowInfoURL_$pluginname('$url')";
# eval("$function");
my $function = "ShowInfoURL_$pluginname";
&$function($url);
}
if ( length($nompage) > $MaxLengthOfShownURL ) {
$nompage = substr( $nompage, 0, $MaxLengthOfShownURL ) . "...";
}
if ($ShowLinksOnUrl) {
my $newkey = CleanXSS($url);
if ( $LogType eq 'W' || $LogType eq 'S' ) { # Web or streaming log file
if ( $newkey =~ /^http(s|):/i )
{ # URL seems to be extracted from a proxy log file
print ""
. XMLEncode($nompage) . " ";
}
elsif ( $newkey =~ /^\// )
{ # URL seems to be an url extracted from a web or wap server log file
$newkey =~ s/^\/$SiteDomain//i;
# Define urlprot
my $urlprot = 'http';
if ( $UseHTTPSLinkForUrl && $newkey =~ /^$UseHTTPSLinkForUrl/ )
{
$urlprot = 'https';
}
print ""
. XMLEncode($nompage) . " ";
}
else {
print XMLEncode($nompage);
}
}
elsif ( $LogType eq 'F' ) { # Ftp log file
print XMLEncode($nompage);
}
elsif ( $LogType eq 'M' ) { # Smtp log file
print XMLEncode($nompage);
}
else { # Other type log file
print XMLEncode($nompage);
}
}
else {
print XMLEncode($nompage);
}
}
#------------------------------------------------------------------------------
# Function: Define value for PerlParsingFormat (used for regex log record parsing)
# Parameters: $LogFormat
# Input: -
# Output: $pos_xxx, @pos_extra, @fieldlib, $PerlParsingFormat
# Return: -
#------------------------------------------------------------------------------
sub DefinePerlParsingFormat {
my $LogFormat = shift;
$pos_vh = $pos_host = $pos_logname = $pos_date = $pos_tz = $pos_method =
$pos_url = $pos_code = $pos_size = -1;
$pos_referer = $pos_agent = $pos_query = $pos_gzipin = $pos_gzipout =
$pos_compratio = -1;
$pos_cluster = $pos_emails = $pos_emailr = $pos_hostr = -1;
@pos_extra = ();
@fieldlib = ();
$PerlParsingFormat = '';
# Log records examples:
# 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)"
# 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 - "-" "-"
# Apache combined (408 error): 62.161.78.73 user - [dd/mmm/yyyy:hh:mm:ss +0000] "-" 408 - "-" "-"
# Apache combined (400 error): 80.8.55.11 - - [28/Apr/2007:03:20:02 +0200] "GET /" 400 584 "-" "-"
# 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
# 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
# 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
# Log formats:
# Apache common_with_mod_gzip_info1: %h %l %u %t \"%r\" %>s %b mod_gzip: %{mod_gzip_compression_ratio}npct.
# 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.
# Apache deflate: %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" (%{ratio}n)
if ($Debug) {
debug(
"Call To DefinePerlParsingFormat (LogType='$LogType', LogFormat='$LogFormat')"
);
}
if ( $LogFormat =~ /^[1-6]$/ ) { # Pre-defined log format
if ( $LogFormat eq '1' || $LogFormat eq '6' )
{ # Same than "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"".
# %u (user) is "([^\\/\\[]+)" instead of "[^ ]+" because can contain space (Lotus Notes). referer and ua might be "".
# $PerlParsingFormat="([^ ]+) [^ ]+ ([^\\/\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) (.+) [^\\\"]+\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\"";
$PerlParsingFormat =
"([^ ]+) [^ ]+ ([^\\/\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) ([^ ]+)(?: [^\\\"]+|)\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\"";
$pos_host = 0;
$pos_logname = 1;
$pos_date = 2;
$pos_method = 3;
$pos_url = 4;
$pos_code = 5;
$pos_size = 6;
$pos_referer = 7;
$pos_agent = 8;
@fieldlib = (
'host', 'logname', 'date', 'method', 'url', 'code',
'size', 'referer', 'ua'
);
}
elsif ( $LogFormat eq '2' )
{ # Same than "date time c-ip cs-username cs-method cs-uri-stem sc-status sc-bytes cs-version cs(User-Agent) cs(Referer)"
$PerlParsingFormat =
"(\\S+ \\S+) (\\S+) (\\S+) (\\S+) (\\S+) ([\\d|-]+) ([\\d|-]+) \\S+ (\\S+) (\\S+)";
$pos_date = 0;
$pos_host = 1;
$pos_logname = 2;
$pos_method = 3;
$pos_url = 4;
$pos_code = 5;
$pos_size = 6;
$pos_agent = 7;
$pos_referer = 8;
@fieldlib = (
'date', 'host', 'logname', 'method', 'url', 'code',
'size', 'ua', 'referer'
);
}
elsif ( $LogFormat eq '3' ) {
$PerlParsingFormat =
"([^\\t]*\\t[^\\t]*)\\t([^\\t]*)\\t([\\d|-]*)\\t([^\\t]*)\\t([^\\t]*)\\t([^\\t]*)\\t[^\\t]*\\t([^\\t]*)\\t([\\d]*)";
$pos_date = 0;
$pos_method = 1;
$pos_code = 2;
$pos_host = 3;
$pos_agent = 4;
$pos_referer = 5;
$pos_url = 6;
$pos_size = 7;
@fieldlib = (
'date', 'method', 'code', 'host',
'ua', 'referer', 'url', 'size'
);
}
elsif ( $LogFormat eq '4' ) { # Same than "%h %l %u %t \"%r\" %>s %b"
# %u (user) is "(.+)" instead of "[^ ]+" because can contain space (Lotus Notes).
$PerlParsingFormat =
"([^ ]+) [^ ]+ (.+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) ([^ ]+)(?: [^\\\"]+|)\\\" ([\\d|-]+) ([\\d|-]+)";
$pos_host = 0;
$pos_logname = 1;
$pos_date = 2;
$pos_method = 3;
$pos_url = 4;
$pos_code = 5;
$pos_size = 6;
@fieldlib =
( 'host', 'logname', 'date', 'method', 'url', 'code', 'size' );
}
}
else { # Personalized log format
my $LogFormatString = $LogFormat;
# Replacement for Notes format string that are not Apache
$LogFormatString =~ s/%vh/%virtualname/g;
# Replacement for Apache format string
$LogFormatString =~ s/%v(\s)/%virtualname$1/g;
$LogFormatString =~ s/%v$/%virtualname/g;
$LogFormatString =~ s/%h(\s)/%host$1/g;
$LogFormatString =~ s/%h$/%host/g;
$LogFormatString =~ s/%l(\s)/%other$1/g;
$LogFormatString =~ s/%l$/%other/g;
$LogFormatString =~ s/\"%u\"/%lognamequot/g;
$LogFormatString =~ s/%u(\s)/%logname$1/g;
$LogFormatString =~ s/%u$/%logname/g;
$LogFormatString =~ s/%t(\s)/%time1$1/g;
$LogFormatString =~ s/%t$/%time1/g;
$LogFormatString =~ s/\"%r\"/%methodurl/g;
$LogFormatString =~ s/%>s/%code/g;
$LogFormatString =~ s/%b(\s)/%bytesd$1/g;
$LogFormatString =~ s/%b$/%bytesd/g;
$LogFormatString =~ s/\"%{Referer}i\"/%refererquot/g;
$LogFormatString =~ s/\"%{User-Agent}i\"/%uaquot/g;
$LogFormatString =~ s/%{mod_gzip_input_size}n/%gzipin/g;
$LogFormatString =~ s/%{mod_gzip_output_size}n/%gzipout/g;
$LogFormatString =~ s/%{mod_gzip_compression_ratio}n/%gzipratio/g;
$LogFormatString =~ s/\(%{ratio}n\)/%deflateratio/g;
# Replacement for a IIS and ISA format string
$LogFormatString =~ s/cs-uri-query/%query/g; # Must be before cs-uri
$LogFormatString =~ s/date\stime/%time2/g;
$LogFormatString =~ s/c-ip/%host/g;
$LogFormatString =~ s/cs-username/%logname/g;
$LogFormatString =~ s/cs-method/%method/g; # GET, POST, SMTP, RETR STOR
$LogFormatString =~ s/cs-uri-stem/%url/g;
$LogFormatString =~ s/cs-uri/%url/g;
$LogFormatString =~ s/sc-status/%code/g;
$LogFormatString =~ s/sc-bytes/%bytesd/g;
$LogFormatString =~ s/cs-version/%other/g; # Protocol
$LogFormatString =~ s/cs\(User-Agent\)/%ua/g;
$LogFormatString =~ s/c-agent/%ua/g;
$LogFormatString =~ s/cs\(Referer\)/%referer/g;
$LogFormatString =~ s/cs-referred/%referer/g;
$LogFormatString =~ s/sc-authenticated/%other/g;
$LogFormatString =~ s/s-svcname/%other/g;
$LogFormatString =~ s/s-computername/%other/g;
$LogFormatString =~ s/r-host/%virtualname/g;
$LogFormatString =~ s/cs-host/%virtualname/g;
$LogFormatString =~ s/r-ip/%other/g;
$LogFormatString =~ s/r-port/%other/g;
$LogFormatString =~ s/time-taken/%other/g;
$LogFormatString =~ s/cs-bytes/%other/g;
$LogFormatString =~ s/cs-protocol/%other/g;
$LogFormatString =~ s/cs-transport/%other/g;
$LogFormatString =~
s/s-operation/%method/g; # GET, POST, SMTP, RETR STOR
$LogFormatString =~ s/cs-mime-type/%other/g;
$LogFormatString =~ s/s-object-source/%other/g;
$LogFormatString =~ s/s-cache-info/%other/g;
$LogFormatString =~ s/cluster-node/%cluster/g;
$LogFormatString =~ s/s-sitename/%other/g;
$LogFormatString =~ s/s-ip/%other/g;
$LogFormatString =~ s/s-port/%other/g;
$LogFormatString =~ s/cs\(Cookie\)/%other/g;
$LogFormatString =~ s/sc-substatus/%other/g;
$LogFormatString =~ s/sc-win32-status/%other/g;
# Added for MMS
$LogFormatString =~
s/protocol/%protocolmms/g; # cs-method might not be available
$LogFormatString =~
s/c-status/%codemms/g; # c-status used when sc-status not available
if ($Debug) { debug(" LogFormatString=$LogFormatString"); }
# $LogFormatString has an AWStats format, so we can generate PerlParsingFormat variable
my $i = 0;
my $LogSeparatorWithoutStar = $LogSeparator;
$LogSeparatorWithoutStar =~ s/[\*\+]//g;
foreach my $f ( split( /\s+/, $LogFormatString ) ) {
# Add separator for next field
if ($PerlParsingFormat) { $PerlParsingFormat .= "$LogSeparator"; }
# Special for logname
if ( $f =~ /%lognamequot$/ ) {
$pos_logname = $i;
$i++;
push @fieldlib, 'logname';
$PerlParsingFormat .=
"\\\"?([^\\\"]*)\\\"?"
; # logname can be "value", "" and - in same log (Lotus notes)
}
elsif ( $f =~ /%logname$/ ) {
$pos_logname = $i;
$i++;
push @fieldlib, 'logname';
# %u (user) is "([^\\/\\[]+)" instead of "[^$LogSeparatorWithoutStar]+" because can contain space (Lotus Notes).
$PerlParsingFormat .= "([^\\/\\[]+)";
}
# Date format
elsif ( $f =~ /%time1$/ || $f =~ /%time1b$/ )
{ # [dd/mmm/yyyy:hh:mm:ss +0000] or [dd/mmm/yyyy:hh:mm:ss], time1b kept for backward compatibility
$pos_date = $i;
$i++;
push @fieldlib, 'date';
$pos_tz = $i;
$i++;
push @fieldlib, 'tz';
$PerlParsingFormat .=
"\\[([^$LogSeparatorWithoutStar]+)( [^$LogSeparatorWithoutStar]+)?\\]";
}
elsif ( $f =~ /%time2$/ ) { # yyyy-mm-dd hh:mm:ss
$pos_date = $i;
$i++;
push @fieldlib, 'date';
$PerlParsingFormat .=
"([^$LogSeparatorWithoutStar]+\\s[^$LogSeparatorWithoutStar]+)"
; # Need \s for Exchange log files
}
elsif ( $f =~ /%time3$/ )
{ # 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
$pos_date = $i;
$i++;
push @fieldlib, 'date';
$PerlParsingFormat .=
"(?:\\w\\w\\w )?(\\w\\w\\w \\s?\\d+ \\d\\d:\\d\\d:\\d\\d(?: \\d\\d\\d\\d)?)";
}
elsif ( $f =~ /%time4$/ ) { # ddddddddddddd
$pos_date = $i;
$i++;
push @fieldlib, 'date';
$PerlParsingFormat .= "(\\d+)";
}
# Special for methodurl and methodurlnoprot
elsif ( $f =~ /%methodurl$/ ) {
$pos_method = $i;
$i++;
push @fieldlib, 'method';
$pos_url = $i;
$i++;
push @fieldlib, 'url';
$PerlParsingFormat .=
#"\\\"([^$LogSeparatorWithoutStar]+) ([^$LogSeparatorWithoutStar]+) [^\\\"]+\\\"";
"\\\"([^$LogSeparatorWithoutStar]+) ([^$LogSeparatorWithoutStar]+)(?: [^\\\"]+|)\\\"";
}
elsif ( $f =~ /%methodurlnoprot$/ ) {
$pos_method = $i;
$i++;
push @fieldlib, 'method';
$pos_url = $i;
$i++;
push @fieldlib, 'url';
$PerlParsingFormat .=
"\\\"([^$LogSeparatorWithoutStar]+) ([^$LogSeparatorWithoutStar]+)\\\"";
}
# Common command tags
elsif ( $f =~ /%virtualnamequot$/ ) {
$pos_vh = $i;
$i++;
push @fieldlib, 'vhost';
$PerlParsingFormat .= "\\\"([^$LogSeparatorWithoutStar]+)\\\"";
}
elsif ( $f =~ /%virtualname$/ ) {
$pos_vh = $i;
$i++;
push @fieldlib, 'vhost';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%host_r$/ ) {
$pos_hostr = $i;
$i++;
push @fieldlib, 'hostr';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%host$/ ) {
$pos_host = $i;
$i++;
push @fieldlib, 'host';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%host_proxy$/ )
{ # if host_proxy tag used, host tag must not be used
$pos_host = $i;
$i++;
push @fieldlib, 'host';
$PerlParsingFormat .= "(.+?)(?:, .*)*";
}
elsif ( $f =~ /%method$/ ) {
$pos_method = $i;
$i++;
push @fieldlib, 'method';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%url$/ ) {
$pos_url = $i;
$i++;
push @fieldlib, 'url';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%query$/ ) {
$pos_query = $i;
$i++;
push @fieldlib, 'query';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%code$/ ) {
$pos_code = $i;
$i++;
push @fieldlib, 'code';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%bytesd$/ ) {
$pos_size = $i;
$i++;
push @fieldlib, 'size';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%refererquot$/ ) {
$pos_referer = $i;
$i++;
push @fieldlib, 'referer';
$PerlParsingFormat .=
"\\\"([^\\\"]*)\\\""; # referer might be ""
}
elsif ( $f =~ /%referer$/ ) {
$pos_referer = $i;
$i++;
push @fieldlib, 'referer';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%uaquot$/ ) {
$pos_agent = $i;
$i++;
push @fieldlib, 'ua';
$PerlParsingFormat .= "\\\"([^\\\"]*)\\\""; # ua might be ""
}
elsif ( $f =~ /%uabracket$/ ) {
$pos_agent = $i;
$i++;
push @fieldlib, 'ua';
$PerlParsingFormat .= "\\\[([^\\\]]*)\\\]"; # ua might be []
}
elsif ( $f =~ /%ua$/ ) {
$pos_agent = $i;
$i++;
push @fieldlib, 'ua';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%gzipin$/ ) {
$pos_gzipin = $i;
$i++;
push @fieldlib, 'gzipin';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%gzipout/ )
{ # Compare $f to /%gzipout/ and not to /%gzipout$/ like other fields
$pos_gzipout = $i;
$i++;
push @fieldlib, 'gzipout';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%gzipratio/ )
{ # Compare $f to /%gzipratio/ and not to /%gzipratio$/ like other fields
$pos_compratio = $i;
$i++;
push @fieldlib, 'gzipratio';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%deflateratio/ )
{ # Compare $f to /%deflateratio/ and not to /%deflateratio$/ like other fields
$pos_compratio = $i;
$i++;
push @fieldlib, 'deflateratio';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%email_r$/ ) {
$pos_emailr = $i;
$i++;
push @fieldlib, 'email_r';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%email$/ ) {
$pos_emails = $i;
$i++;
push @fieldlib, 'email';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%cluster$/ ) {
$pos_cluster = $i;
$i++;
push @fieldlib, 'clusternb';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
elsif ( $f =~ /%timetaken$/ ) {
$pos_timetaken = $i;
$i++;
push @fieldlib, 'timetaken';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
# Special for protocolmms, used for method if method not already found (for MMS)
elsif ( $f =~ /%protocolmms$/ ) {
if ( $pos_method < 0 ) {
$pos_method = $i;
$i++;
push @fieldlib, 'method';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
}
# Special for codemms, used for code only if code not already found (for MMS)
elsif ( $f =~ /%codemms$/ ) {
if ( $pos_code < 0 ) {
$pos_code = $i;
$i++;
push @fieldlib, 'code';
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
}
# Extra tag
elsif ( $f =~ /%extra(\d+)$/ ) {
$pos_extra[$1] = $i;
$i++;
push @fieldlib, "extra$1";
$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
}
# Other tag
elsif ( $f =~ /%other$/ ) {
$PerlParsingFormat .= "[^$LogSeparatorWithoutStar]+";
}
elsif ( $f =~ /%otherquot$/ ) {
$PerlParsingFormat .= "\\\"[^\\\"]*\\\"";
}
# Unknown tag (no parenthesis)
else {
$PerlParsingFormat .= "[^$LogSeparatorWithoutStar]+";
}
}
if ( !$PerlParsingFormat ) {
error("No recognized format tag in personalized LogFormat string");
}
}
if ( $pos_host < 0 ) {
error(
"Your personalized LogFormat does not include all fields required by AWStats (Add \%host in your LogFormat string)."
);
}
if ( $pos_date < 0 ) {
error(
"Your personalized LogFormat does not include all fields required by AWStats (Add \%time1 or \%time2 in your LogFormat string)."
);
}
if ( $pos_method < 0 ) {
error(
"Your personalized LogFormat does not include all fields required by AWStats (Add \%methodurl or \%method in your LogFormat string)."
);
}
if ( $pos_url < 0 ) {
error(
"Your personalized LogFormat does not include all fields required by AWStats (Add \%methodurl or \%url in your LogFormat string)."
);
}
if ( $pos_code < 0 ) {
error(
"Your personalized LogFormat does not include all fields required by AWStats (Add \%code in your LogFormat string)."
);
}
# if ( $pos_size < 0 ) {
# error(
#"Your personalized LogFormat does not include all fields required by AWStats (Add \%bytesd in your LogFormat string)."
# );
# }
$PerlParsingFormat = qr/^$PerlParsingFormat/;
if ($Debug) { debug(" PerlParsingFormat is $PerlParsingFormat"); }
}
#------------------------------------------------------------------------------
# Function: Prints a menu category for the frame or static header
# Parameters: -
# Input: $categ, $categtext, $categicon, $frame, $targetpage, $linkanchor,
# $NewLinkParams, $NewLinkTarget
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowMenuCateg {
my ( $categ, $categtext, $categicon, $frame, $targetpage, $linkanchor,
$NewLinkParams, $NewLinkTarget )
= ( shift, shift, shift, shift, shift, shift, shift, shift );
$categicon = ''; # Comment this to enabme category icons
my ( $menu, $menulink, $menutext ) = ( shift, shift, shift );
my $linetitle = 0;
# Call to plugins' function AddHTMLMenuLink
foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLMenuLink'} } ) {
# my $function="AddHTMLMenuLink_$pluginname('$categ',\$menu,\$menulink,\$menutext)";
# eval("$function");
my $function = "AddHTMLMenuLink_$pluginname";
&$function( $categ, $menu, $menulink, $menutext );
}
foreach my $key (%$menu) {
if ( $menu->{$key} && $menu->{$key} > 0 ) { $linetitle++; last; }
}
if ( !$linetitle ) { return; }
# At least one entry in menu for this category, we can show category and entries
my $WIDTHMENU1 = ( $FrameName eq 'mainleft' ? $FRAMEWIDTH : 150 );
print ""
. ( $categicon ? " " : "" )
. "$categtext: \n";
print( $frame? " \n" : "" );
foreach my $key ( sort { $menu->{$a} <=> $menu->{$b} } keys %$menu ) {
if ( $menu->{$key} == 0 ) { next; }
if ( $menulink->{$key} == 1 ) {
print( $frame? " " : "" );
print
"$menutext->{$key} ";
print( $frame? " \n" : " " );
}
if ( $menulink->{$key} == 2 ) {
print( $frame
? " "
: ""
);
print "$menutext->{$key} \n";
print( $frame? " \n" : " " );
}
}
print( $frame? "" : "\n" );
}
#------------------------------------------------------------------------------
# Function: Prints HTML to display an email senders chart
# Parameters: -
# Input: $NewLinkParams, NewLinkTarget
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowEmailSendersChart {
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
my $MaxLengthOfShownEMail = 48;
my $total_p;
my $total_h;
my $total_k;
my $max_p;
my $max_h;
my $max_k;
my $rest_p;
my $rest_h;
my $rest_k;
# Show filter form
#&ShowFormFilter("emailsfilter",$EmailsFilter);
# Show emails list
print "$Center \n";
my $title;
if ( $HTMLOutput{'allemails'} || $HTMLOutput{'lastemails'} ) {
$title = "$Message[131]";
}
else {
$title =
"$Message[131] ($Message[77] $MaxNbOf{'EMailsShown'}) - $Message[80] ";
if ( $ShowEMailSenders =~ /L/i ) {
$title .= " - $Message[9] ";
}
}
&tab_head( "$title", 19, 0, 'emailsenders' );
print
"$Message[131] : "
. ( scalar keys %_emails_h ) . " ";
if ( $ShowEMailSenders =~ /H/i ) {
print "$Message[57] ";
}
if ( $ShowEMailSenders =~ /B/i ) {
print
"$Message[75] ";
}
if ( $ShowEMailSenders =~ /M/i ) {
print
"$Message[106] ";
}
if ( $ShowEMailSenders =~ /L/i ) {
print "$Message[9] ";
}
print " \n";
print
"Local External ";
$total_p = $total_h = $total_k = 0;
$max_h = 1;
foreach ( values %_emails_h ) {
if ( $_ > $max_h ) { $max_h = $_; }
}
$max_k = 1;
foreach ( values %_emails_k ) {
if ( $_ > $max_k ) { $max_k = $_; }
}
my $count = 0;
if ( !$HTMLOutput{'allemails'} && !$HTMLOutput{'lastemails'} ) {
&BuildKeyList( $MaxNbOf{'EMailsShown'}, $MinHit{'EMail'}, \%_emails_h,
\%_emails_h );
}
if ( $HTMLOutput{'allemails'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emails_h,
\%_emails_h );
}
if ( $HTMLOutput{'lastemails'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emails_h,
\%_emails_l );
}
foreach my $key (@keylist) {
my $newkey = $key;
if ( length($key) > $MaxLengthOfShownEMail ) {
$newkey = substr( $key, 0, $MaxLengthOfShownEMail ) . "...";
}
my $bredde_h = 0;
my $bredde_k = 0;
if ( $max_h > 0 ) {
$bredde_h = int( $BarWidth * $_emails_h{$key} / $max_h ) + 1;
}
if ( $max_k > 0 ) {
$bredde_k = int( $BarWidth * $_emails_k{$key} / $max_k ) + 1;
}
print "";
my $direction = IsLocalEMail($key);
if ( $direction > 0 ) {
print "$newkey -> ";
}
if ( $direction == 0 ) {
print
"$newkey ";
}
if ( $direction < 0 ) {
print " <- $newkey ";
}
if ( $ShowEMailSenders =~ /H/i ) { print "$_emails_h{$key} "; }
if ( $ShowEMailSenders =~ /B/i ) {
print ""
. Format_Bytes( $_emails_k{$key} ) . " ";
}
if ( $ShowEMailSenders =~ /M/i ) {
print ""
. Format_Bytes( $_emails_k{$key} / ( $_emails_h{$key} || 1 ) )
. " ";
}
if ( $ShowEMailSenders =~ /L/i ) {
print ""
. ( $_emails_l{$key} ? Format_Date( $_emails_l{$key}, 1 ) : '-' )
. " ";
}
print " \n";
#$total_p += $_emails_p{$key};
$total_h += $_emails_h{$key};
$total_k += $_emails_k{$key};
$count++;
}
$rest_p = 0; # $rest_p=$TotalPages-$total_p;
$rest_h = $TotalHits - $total_h;
$rest_k = $TotalBytes - $total_k;
if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 ) { # All other sender emails
print
"$Message[2] ";
if ( $ShowEMailSenders =~ /H/i ) { print "$rest_h "; }
if ( $ShowEMailSenders =~ /B/i ) {
print "" . Format_Bytes($rest_k) . " ";
}
if ( $ShowEMailSenders =~ /M/i ) {
print ""
. Format_Bytes( $rest_k / ( $rest_h || 1 ) ) . " ";
}
if ( $ShowEMailSenders =~ /L/i ) { print " "; }
print " \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints HTML to display an email receivers chart
# Parameters: -
# Input: $NewLinkParams, NewLinkTarget
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowEmailReceiversChart {
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
my $MaxLengthOfShownEMail = 48;
my $total_p;
my $total_h;
my $total_k;
my $max_p;
my $max_h;
my $max_k;
my $rest_p;
my $rest_h;
my $rest_k;
# Show filter form
#&ShowFormFilter("emailrfilter",$EmailrFilter);
# Show emails list
print "$Center \n";
my $title;
if ( $HTMLOutput{'allemailr'} || $HTMLOutput{'lastemailr'} ) {
$title = "$Message[132]";
}
else {
$title =
"$Message[132] ($Message[77] $MaxNbOf{'EMailsShown'}) - $Message[80] ";
if ( $ShowEMailReceivers =~ /L/i ) {
$title .= " - $Message[9] ";
}
}
&tab_head( "$title", 19, 0, 'emailreceivers' );
print
"$Message[132] : "
. ( scalar keys %_emailr_h ) . " ";
if ( $ShowEMailReceivers =~ /H/i ) {
print "$Message[57] ";
}
if ( $ShowEMailReceivers =~ /B/i ) {
print
"$Message[75] ";
}
if ( $ShowEMailReceivers =~ /M/i ) {
print
"$Message[106] ";
}
if ( $ShowEMailReceivers =~ /L/i ) {
print "$Message[9] ";
}
print " \n";
print
"Local External ";
$total_p = $total_h = $total_k = 0;
$max_h = 1;
foreach ( values %_emailr_h ) {
if ( $_ > $max_h ) { $max_h = $_; }
}
$max_k = 1;
foreach ( values %_emailr_k ) {
if ( $_ > $max_k ) { $max_k = $_; }
}
my $count = 0;
if ( !$HTMLOutput{'allemailr'} && !$HTMLOutput{'lastemailr'} ) {
&BuildKeyList( $MaxNbOf{'EMailsShown'}, $MinHit{'EMail'}, \%_emailr_h,
\%_emailr_h );
}
if ( $HTMLOutput{'allemailr'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emailr_h,
\%_emailr_h );
}
if ( $HTMLOutput{'lastemailr'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'EMail'}, \%_emailr_h,
\%_emailr_l );
}
foreach my $key (@keylist) {
my $newkey = $key;
if ( length($key) > $MaxLengthOfShownEMail ) {
$newkey = substr( $key, 0, $MaxLengthOfShownEMail ) . "...";
}
my $bredde_h = 0;
my $bredde_k = 0;
if ( $max_h > 0 ) {
$bredde_h = int( $BarWidth * $_emailr_h{$key} / $max_h ) + 1;
}
if ( $max_k > 0 ) {
$bredde_k = int( $BarWidth * $_emailr_k{$key} / $max_k ) + 1;
}
print "";
my $direction = IsLocalEMail($key);
if ( $direction > 0 ) {
print "$newkey <- ";
}
if ( $direction == 0 ) {
print
"$newkey ";
}
if ( $direction < 0 ) {
print " -> $newkey ";
}
if ( $ShowEMailReceivers =~ /H/i ) {
print "$_emailr_h{$key} ";
}
if ( $ShowEMailReceivers =~ /B/i ) {
print ""
. Format_Bytes( $_emailr_k{$key} ) . " ";
}
if ( $ShowEMailReceivers =~ /M/i ) {
print ""
. Format_Bytes( $_emailr_k{$key} / ( $_emailr_h{$key} || 1 ) )
. " ";
}
if ( $ShowEMailReceivers =~ /L/i ) {
print ""
. ( $_emailr_l{$key} ? Format_Date( $_emailr_l{$key}, 1 ) : '-' )
. " ";
}
print " \n";
#$total_p += $_emailr_p{$key};
$total_h += $_emailr_h{$key};
$total_k += $_emailr_k{$key};
$count++;
}
$rest_p = 0; # $rest_p=$TotalPages-$total_p;
$rest_h = $TotalHits - $total_h;
$rest_k = $TotalBytes - $total_k;
if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
{ # All other receiver emails
print
"$Message[2] ";
if ( $ShowEMailReceivers =~ /H/i ) { print "$rest_h "; }
if ( $ShowEMailReceivers =~ /B/i ) {
print "" . Format_Bytes($rest_k) . " ";
}
if ( $ShowEMailReceivers =~ /M/i ) {
print ""
. Format_Bytes( $rest_k / ( $rest_h || 1 ) ) . " ";
}
if ( $ShowEMailReceivers =~ /L/i ) { print " "; }
print " \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the top banner of the inner frame or static page
# Parameters: $WIDTHMENU1
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLTopBanner{
my $WIDTHMENU1 = shift;
my $frame = ( $FrameName eq 'mainleft' );
if ($Debug) { debug( "ShowTopBan", 2 ); }
print "$Center \n";
if ( $FrameName ne 'mainleft' ) {
my $NewLinkParams = ${QueryString};
$NewLinkParams =~ s/(^|&|&)update(=\w*|$)//i;
$NewLinkParams =~ s/(^|&|&)staticlinks(=\w*|$)//i;
$NewLinkParams =~ s/(^|&|&)year=[^&]*//i;
$NewLinkParams =~ s/(^|&|&)month=[^&]*//i;
$NewLinkParams =~ s/(^|&|&)framename=[^&]*//i;
$NewLinkParams =~ s/(&|&)+/&/i;
$NewLinkParams =~ s/^&//;
$NewLinkParams =~ s/&$//;
my $NewLinkTarget = '';
if ( $FrameName eq 'mainright' ) {
$NewLinkTarget = " target=\"_parent\"";
}
print "\n"; }
else { print " \n"; }
print "\n";
}
#------------------------------------------------------------------------------
# Function: Prints the menu in a frame or below the top banner
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMenu{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
my $frame = ( $FrameName eq 'mainleft' );
if ($Debug) { debug( "ShowMenu", 2 ); }
# Print menu links
if ( ( $HTMLOutput{'main'} && $FrameName ne 'mainright' )
|| $FrameName eq 'mainleft' )
{ # If main page asked
# Define link anchor
my $linkanchor =
( $FrameName eq 'mainleft' ? "$AWScript${NewLinkParams}" : "" );
if ( $linkanchor && ( $linkanchor !~ /framename=mainright/ ) ) {
$linkanchor .= "framename=mainright";
}
$linkanchor =~ s/(&|&)$//;
$linkanchor = XMLEncode("$linkanchor");
# Define target
my $targetpage =
( $FrameName eq 'mainleft' ? " target=\"mainright\"" : "" );
# Print Menu
my $linetitle; # TODO a virer
if ( !$PluginsLoaded{'ShowMenu'}{'menuapplet'} ) {
my $menuicon = 0; # TODO a virer
# Menu HTML
print "\n";
if ( $FrameName eq 'mainleft' && $ShowMonthStats ) {
print( $frame? "" : "" );
print
"$Message[128] ";
print( $frame? " \n" : " " );
}
my %menu = ();
my %menulink = ();
my %menutext = ();
# When
%menu = (
'month' => $ShowMonthStats ? 1 : 0,
'daysofmonth' => $ShowDaysOfMonthStats ? 2 : 0,
'daysofweek' => $ShowDaysOfWeekStats ? 3 : 0,
'hours' => $ShowHoursStats ? 4 : 0
);
%menulink = (
'month' => 1,
'daysofmonth' => 1,
'daysofweek' => 1,
'hours' => 1
);
%menutext = (
'month' => $Message[162],
'daysofmonth' => $Message[138],
'daysofweek' => $Message[91],
'hours' => $Message[20]
);
HTMLShowMenuCateg(
'when', $Message[93],
'menu4.png', $frame,
$targetpage, $linkanchor,
$NewLinkParams, $NewLinkTarget,
\%menu, \%menulink,
\%menutext
);
# Who
%menu = (
'countries' => $ShowDomainsStats ? 1 : 0,
'alldomains' => $ShowDomainsStats ? 2 : 0,
'visitors' => $ShowHostsStats ? 3 : 0,
'allhosts' => $ShowHostsStats ? 4 : 0,
'lasthosts' => ( $ShowHostsStats =~ /L/i ) ? 5 : 0,
'unknownip' => $ShowHostsStats ? 6 : 0,
'logins' => $ShowAuthenticatedUsers ? 7 : 0,
'alllogins' => $ShowAuthenticatedUsers ? 8 : 0,
'lastlogins' => ( $ShowAuthenticatedUsers =~ /L/i ) ? 9 : 0,
'emailsenders' => $ShowEMailSenders ? 10 : 0,
'allemails' => $ShowEMailSenders ? 11 : 0,
'lastemails' => ( $ShowEMailSenders =~ /L/i ) ? 12 : 0,
'emailreceivers' => $ShowEMailReceivers ? 13 : 0,
'allemailr' => $ShowEMailReceivers ? 14 : 0,
'lastemailr' => ( $ShowEMailReceivers =~ /L/i ) ? 15 : 0,
'robots' => $ShowRobotsStats ? 16 : 0,
'allrobots' => $ShowRobotsStats ? 17 : 0,
'lastrobots' => ( $ShowRobotsStats =~ /L/i ) ? 18 : 0,
'worms' => $ShowWormsStats ? 19 : 0
);
%menulink = (
'countries' => 1,
'alldomains' => 2,
'visitors' => 1,
'allhosts' => 2,
'lasthosts' => 2,
'unknownip' => 2,
'logins' => 1,
'alllogins' => 2,
'lastlogins' => 2,
'emailsenders' => 1,
'allemails' => 2,
'lastemails' => 2,
'emailreceivers' => 1,
'allemailr' => 2,
'lastemailr' => 2,
'robots' => 1,
'allrobots' => 2,
'lastrobots' => 2,
'worms' => 1
);
%menutext = (
'countries' => $Message[148],
'alldomains' => $Message[80],
'visitors' => $Message[81],
'allhosts' => $Message[80],
'lasthosts' => $Message[9],
'unknownip' => $Message[45],
'logins' => $Message[94],
'alllogins' => $Message[80],
'lastlogins' => $Message[9],
'emailsenders' => $Message[131],
'allemails' => $Message[80],
'lastemails' => $Message[9],
'emailreceivers' => $Message[132],
'allemailr' => $Message[80],
'lastemailr' => $Message[9],
'robots' => $Message[53],
'allrobots' => $Message[80],
'lastrobots' => $Message[9],
'worms' => $Message[136]
);
HTMLShowMenuCateg(
'who', $Message[92],
'menu5.png', $frame,
$targetpage, $linkanchor,
$NewLinkParams, $NewLinkTarget,
\%menu, \%menulink,
\%menutext
);
# Navigation
$linetitle = &AtLeastOneNotNull(
$ShowSessionsStats, $ShowPagesStats,
$ShowFileTypesStats, $ShowFileSizesStats,
$ShowOSStats, $ShowBrowsersStats,
$ShowScreenSizeStats, $ShowDownloadsStats
);
if ($linetitle) {
print ""
. (
$menuicon
? " "
: ""
)
. "$Message[72]: \n";
}
if ($linetitle) {
print( $frame? " \n" : "" );
}
if ($ShowSessionsStats) {
print( $frame? " " : "" );
print
"$Message[117] ";
print( $frame? " \n" : " " );
}
if ($ShowFileTypesStats && $LevelForFileTypesDetection > 0) {
print( $frame? "" : "" );
print
"$Message[73] ";
print( $frame? " \n" : " " );
}
if ($ShowDownloadsStats && $LevelForFileTypesDetection > 0) {
print( $frame? "" : "" );
print
"$Message[178] ";
print( $frame? " \n" : " " );
print( $frame
? " "
: ""
);
print "$Message[80] \n";
print( $frame? " \n" : " " );
}
if ($ShowPagesStats) {
print( $frame? "" : "" );
print
"$Message[29] \n";
print( $frame? " \n" : " " );
}
if ($ShowPagesStats) {
print( $frame
? " "
: ""
);
print "$Message[80] \n";
print( $frame? " \n" : " " );
}
if ( $ShowPagesStats =~ /E/i ) {
print( $frame
? " "
: ""
);
print "$Message[104] \n";
print( $frame? " \n" : " " );
}
if ( $ShowPagesStats =~ /X/i ) {
print( $frame
? " "
: ""
);
print "$Message[116] \n";
print( $frame? " \n" : " " );
}
if ($ShowOSStats) {
print( $frame? "" : "" );
print
"$Message[59] ";
print( $frame? " \n" : " " );
}
if ($ShowOSStats) {
print( $frame
? " "
: ""
);
print "$Message[58] \n";
print( $frame? " \n" : " " );
}
if ($ShowOSStats) {
print( $frame
? " "
: ""
);
print "$Message[0] \n";
print( $frame? " \n" : " " );
}
if ($ShowBrowsersStats) {
print( $frame? "" : "" );
print
"$Message[21] ";
print( $frame? " \n" : " " );
}
if ($ShowBrowsersStats) {
print( $frame
? " "
: ""
);
print "$Message[58] \n";
print( $frame? " \n" : " " );
}
if ($ShowBrowsersStats) {
print( $frame
? " "
: ""
);
print "$Message[0] \n";
print( $frame? " \n" : " " );
}
if ($ShowScreenSizeStats) {
print( $frame? "" : "" );
print
"$Message[135] ";
print( $frame? " \n" : " " );
}
if ($linetitle) { print( $frame? "" : "\n" ); }
# Referers
%menu = (
'referer' => $ShowOriginStats ? 1 : 0,
'refererse' => $ShowOriginStats ? 2 : 0,
'refererpages' => $ShowOriginStats ? 3 : 0,
'keys' => ( $ShowKeyphrasesStats || $ShowKeywordsStats )
? 4
: 0,
'keyphrases' => $ShowKeyphrasesStats ? 5 : 0,
'keywords' => $ShowKeywordsStats ? 6 : 0
);
%menulink = (
'referer' => 1,
'refererse' => 2,
'refererpages' => 2,
'keys' => 1,
'keyphrases' => 2,
'keywords' => 2
);
%menutext = (
'referer' => $Message[37],
'refererse' => $Message[126],
'refererpages' => $Message[127],
'keys' => $Message[14],
'keyphrases' => $Message[120],
'keywords' => $Message[121]
);
HTMLShowMenuCateg(
'referers', $Message[23],
'menu7.png', $frame,
$targetpage, $linkanchor,
$NewLinkParams, $NewLinkTarget,
\%menu, \%menulink,
\%menutext
);
# Others
%menu = (
'filetypes' => ( $ShowFileTypesStats =~ /C/i ) ? 1 : 0,
'misc' => $ShowMiscStats ? 2 : 0,
'errors' => ( $ShowHTTPErrorsStats || $ShowSMTPErrorsStats )
? 3
: 0,
'clusters' => $ShowClusterStats ? 5 : 0
);
%menulink = (
'filetypes' => 1,
'misc' => 1,
'errors' => 1,
'clusters' => 1
);
%menutext = (
'filetypes' => $Message[98],
'misc' => $Message[139],
'errors' =>
( $ShowSMTPErrorsStats ? $Message[147] : $Message[32] ),
'clusters' => $Message[155]
);
foreach ( keys %TrapInfosForHTTPErrorCodes ) {
$menu{"errors$_"} = $ShowHTTPErrorsStats ? 4 : 0;
$menulink{"errors$_"} = 2;
$menutext{"errors$_"} = $Message[31];
}
HTMLShowMenuCateg(
'others', $Message[2],
'menu8.png', $frame,
$targetpage, $linkanchor,
$NewLinkParams, $NewLinkTarget,
\%menu, \%menulink,
\%menutext
);
# Extra/Marketing
%menu = ();
%menulink = ();
%menutext = ();
my $i = 1;
foreach ( 1 .. @ExtraName - 1 ) {
$menu{"extra$_"} = $i++;
$menulink{"extra$_"} = 1;
$menutext{"extra$_"} = $ExtraName[$_];
$menu{"allextra$_"} = $i++;
$menulink{"allextra$_"} = 2;
$menutext{"allextra$_"} = $Message[80];
}
HTMLShowMenuCateg(
'extra', $Message[134],
'', $frame,
$targetpage, $linkanchor,
$NewLinkParams, $NewLinkTarget,
\%menu, \%menulink,
\%menutext
);
print "
\n";
}
else {
# Menu Applet
if ($frame) { }
else { }
}
#print ($frame?"":" \n");
print " \n";
}
# Print Back link
elsif ( !$HTMLOutput{'main'} ) {
print "\n";
$NewLinkParams =~ s/(^|&|&)hostfilter=[^&]*//i;
$NewLinkParams =~ s/(^|&|&)urlfilter=[^&]*//i;
$NewLinkParams =~ s/(^|&|&)refererpagesfilter=[^&]*//i;
$NewLinkParams =~ s/(&|&)+/&/i;
$NewLinkParams =~ s/^&//;
$NewLinkParams =~ s/&$//;
if ( !$DetailedReportsOnNewWindows
|| $FrameName eq 'mainright'
|| $QueryString =~ /buildpdf/i )
{
print "$Message[76] \n";
}
else {
print
"$Message[118] \n";
}
print "
\n";
print "\n";
}
}
#------------------------------------------------------------------------------
# Function: Prints the File Type table
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainFileType{
if (!$LevelForFileTypesDetection > 0){return;}
if ($Debug) { debug( "ShowFileTypesStatsCompressionStats", 2 ); }
print "$Center \n";
my $Totalh = 0;
foreach ( keys %_filetypes_h ) { $Totalh += $_filetypes_h{$_}; }
my $Totalk = 0;
foreach ( keys %_filetypes_k ) { $Totalk += $_filetypes_k{$_}; }
my $title = "$Message[73]";
if ( $ShowFileTypesStats =~ /C/i ) { $title .= " - $Message[98]"; }
# build keylist at top
&BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_filetypes_h,
\%_filetypes_h );
&tab_head( "$title", 19, 0, 'filetypes' );
# Graph the top five in a pie chart
if (scalar @keylist > 1){
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ();
my @valdata = ();
my @valcolor = ($color_p);
my $cnt = 0;
foreach my $key (@keylist) {
push @valdata, int( $_filetypes_h{$key} / $Totalh * 1000 ) / 10;
push @blocklabel, "$key";
$cnt++;
if ($cnt > 4) { last; }
}
print "";
my $function = "ShowGraph_$pluginname";
&$function(
"$title", "filetypes",
0, \@blocklabel,
0, \@valcolor,
0, 0,
0, \@valdata
);
print " ";
}
}
print
"$Message[73] ";
if ( $ShowFileTypesStats =~ /H/i ) {
print "$Message[57] $Message[15] ";
}
if ( $ShowFileTypesStats =~ /B/i ) {
print "$Message[75] $Message[15] ";
}
if ( $ShowFileTypesStats =~ /C/i ) {
print
"$Message[100] $Message[101] $Message[99] ";
}
print " \n";
my $total_con = 0;
my $total_cre = 0;
my $count = 0;
foreach my $key (@keylist) {
my $p_h = ' ';
my $p_k = ' ';
if ($Totalh) {
$p_h = int( $_filetypes_h{$key} / $Totalh * 1000 ) / 10;
$p_h = "$p_h %";
}
if ($Totalk) {
$p_k = int( $_filetypes_k{$key} / $Totalk * 1000 ) / 10;
$p_k = "$p_k %";
}
if ( $key eq 'Unknown' ) {
print "$Message[0] ";
}
else {
my $nameicon = $MimeHashLib{$key}[0] || "notavailable";
my $nametype = $MimeHashFamily{$MimeHashLib{$key}[0]} || " ";
print "$key ";
print "$nametype ";
}
if ( $ShowFileTypesStats =~ /H/i ) {
print "".Format_Number($_filetypes_h{$key})." $p_h ";
}
if ( $ShowFileTypesStats =~ /B/i ) {
print ''
. Format_Bytes( $_filetypes_k{$key} )
. " $p_k ";
}
if ( $ShowFileTypesStats =~ /C/i ) {
if ( $_filetypes_gz_in{$key} ) {
my $percent = int(
100 * (
1 - $_filetypes_gz_out{$key} /
$_filetypes_gz_in{$key}
)
);
printf(
"%s %s %s (%s%) ",
Format_Bytes( $_filetypes_gz_in{$key} ),
Format_Bytes( $_filetypes_gz_out{$key} ),
Format_Bytes(
$_filetypes_gz_in{$key} -
$_filetypes_gz_out{$key}
),
$percent
);
$total_con += $_filetypes_gz_in{$key};
$total_cre += $_filetypes_gz_out{$key};
}
else {
print " ";
}
}
print " \n";
$count++;
}
# Add total (only usefull if compression is enabled)
if ( $ShowFileTypesStats =~ /C/i ) {
my $colspan = 3;
if ( $ShowFileTypesStats =~ /H/i ) { $colspan += 2; }
if ( $ShowFileTypesStats =~ /B/i ) { $colspan += 2; }
print "";
print
"$Message[98] ";
if ( $ShowFileTypesStats =~ /C/i ) {
if ($total_con) {
my $percent =
int( 100 * ( 1 - $total_cre / $total_con ) );
printf(
"%s %s %s (%s%) ",
Format_Bytes($total_con),
Format_Bytes($total_cre),
Format_Bytes( $total_con - $total_cre ),
$percent
);
}
else {
print " ";
}
}
print " \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the Browser Detail frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowBrowserDetail{
# Show browsers versions
print "$Center ";
my $title = "$Message[21]";
&tab_head( "$title", 19, 0, 'browsersversions' );
print
"$Message[58] ";
print
"$Message[111] $Message[57] $Message[15] ";
print " ";
print " \n";
my $total_h = 0;
my $count = 0;
&BuildKeyList( MinimumButNoZero( scalar keys %_browser_h, 500 ),
1, \%_browser_h, \%_browser_h );
my %keysinkeylist = ();
my $max_h = 1;
# Count total by family
my %totalfamily_h = ();
my $TotalFamily = 0;
BROWSERLOOP: foreach my $key (@keylist) {
$total_h += $_browser_h{$key};
if ( $_browser_h{$key} > $max_h ) {
$max_h = $_browser_h{$key};
}
foreach my $family ( keys %BrowsersFamily ) {
if ( $key =~ /^$family/i ) {
$totalfamily_h{$family} += $_browser_h{$key};
$TotalFamily += $_browser_h{$key};
next BROWSERLOOP;
}
}
}
# Write records grouped in a browser family
foreach my $family (
sort { $BrowsersFamily{$a} <=> $BrowsersFamily{$b} }
keys %BrowsersFamily
)
{
my $p = ' ';
if ($total_h) {
$p = int( $totalfamily_h{$family} / $total_h * 1000 ) / 10;
$p = "$p %";
}
my $familyheadershown = 0;
#foreach my $key ( reverse sort keys %_browser_h ) {
foreach my $key ( reverse sort SortBrowsers keys %_browser_h ) {
if ( $key =~ /^$family(.*)/i ) {
if ( !$familyheadershown ) {
print
""
. uc($family)
. " ";
print " "
. Format_Number(int( $totalfamily_h{$family} ))
. " $p ";
print " \n";
$familyheadershown = 1;
}
$keysinkeylist{$key} = 1;
my $ver = $1;
my $p = ' ';
if ($total_h) {
$p =
int( $_browser_h{$key} / $total_h * 1000 ) / 10;
$p = "$p %";
}
print "";
print " ";
print ""
. ucfirst($family) . " "
. ( $ver ? "$ver" : "?" ) . " ";
print ""
. (
$BrowsersHereAreGrabbers{$family}
? "$Message[112] "
: "$Message[113]"
)
. " ";
my $bredde_h = 0;
if ( $max_h > 0 ) {
$bredde_h =
int( $BarWidth * ( $_browser_h{$key} || 0 ) /
$max_h ) + 1;
}
if ( ( $bredde_h == 1 ) && $_browser_h{$key} ) {
$bredde_h = 2;
}
print "".Format_Number($_browser_h{$key})." $p ";
print "";
# alt and title are not provided to reduce page size
if ($ShowBrowsersStats) {
print
" ";
}
print " ";
print " \n";
$count++;
}
}
}
# Write other records
my $familyheadershown = 0;
foreach my $key (@keylist) {
if ( $keysinkeylist{$key} ) { next; }
if ( !$familyheadershown ) {
my $p = ' ';
if ($total_h) {
$p =
int( ( $total_h - $TotalFamily ) / $total_h * 1000 ) /
10;
$p = "$p %";
}
print
"$Message[2] ";
print " "
. Format_Number(( $total_h - $TotalFamily ))
. " $p ";
print " \n";
$familyheadershown = 1;
}
my $p = ' ';
if ($total_h) {
$p = int( $_browser_h{$key} / $total_h * 1000 ) / 10;
$p = "$p %";
}
print "";
if ( $key eq 'Unknown' ) {
print "$Message[0] ? ";
}
else {
my $keywithoutcumul = $key;
$keywithoutcumul =~ s/cumul$//i;
my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
|| $keywithoutcumul;
my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
|| "notavailable";
print "$libbrowser "
. (
$BrowsersHereAreGrabbers{$key}
? "$Message[112] "
: "$Message[113]"
)
. " ";
}
my $bredde_h = 0;
if ( $max_h > 0 ) {
$bredde_h =
int( $BarWidth * ( $_browser_h{$key} || 0 ) / $max_h ) +
1;
}
if ( ( $bredde_h == 1 ) && $_browser_h{$key} ) {
$bredde_h = 2;
}
print "".Format_Number($_browser_h{$key})." $p ";
print "";
# alt and title are not provided to reduce page size
if ($ShowBrowsersStats) {
print
" ";
}
print " ";
print " \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Unknown Browser Detail frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowBrowserUnknown{
print "$Center \n";
my $title = "$Message[50]";
&tab_head( "$title", 19, 0, 'unknownbrowser' );
print "User agent ("
. ( scalar keys %_unknownrefererbrowser_l )
. ") $Message[9] \n";
my $total_l = 0;
my $count = 0;
&BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_unknownrefererbrowser_l,
\%_unknownrefererbrowser_l );
foreach my $key (@keylist) {
my $useragent = XMLEncode( CleanXSS($key) );
print
"$useragent "
. Format_Date( $_unknownrefererbrowser_l{$key}, 1 )
. " \n";
$total_l += 1;
$count++;
}
my $rest_l = ( scalar keys %_unknownrefererbrowser_l ) - $total_l;
if ( $rest_l > 0 ) {
print
"$Message[2] ";
print "- ";
print " \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the OS Detail frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowOSDetail{
# Show os versions
print "$Center ";
my $title = "$Message[59]";
&tab_head( "$title", 19, 0, 'osversions' );
print
"$Message[58] ";
print
"$Message[57] $Message[15] ";
print " ";
print " \n";
my $total_h = 0;
my $count = 0;
&BuildKeyList( MinimumButNoZero( scalar keys %_os_h, 500 ),
1, \%_os_h, \%_os_h );
my %keysinkeylist = ();
my $max_h = 1;
# Count total by family
my %totalfamily_h = ();
my $TotalFamily = 0;
OSLOOP: foreach my $key (@keylist) {
$total_h += $_os_h{$key};
if ( $_os_h{$key} > $max_h ) { $max_h = $_os_h{$key}; }
foreach my $family ( keys %OSFamily ) {
if ( $key =~ /^$family/i ) {
$totalfamily_h{$family} += $_os_h{$key};
$TotalFamily += $_os_h{$key};
next OSLOOP;
}
}
}
# Write records grouped in a browser family
foreach my $family ( keys %OSFamily ) {
my $p = ' ';
if ($total_h) {
$p = int( $totalfamily_h{$family} / $total_h * 1000 ) / 10;
$p = "$p %";
}
my $familyheadershown = 0;
foreach my $key ( reverse sort keys %_os_h ) {
if ( $key =~ /^$family(.*)/i ) {
if ( !$familyheadershown ) {
my $family_name = '';
if ( $OSFamily{$family} ) {
$family_name = $OSFamily{$family};
}
print
"$family_name ";
print ""
. Format_Number(int( $totalfamily_h{$family} ))
. " $p ";
print " \n";
$familyheadershown = 1;
}
$keysinkeylist{$key} = 1;
my $ver = $1;
my $p = ' ';
if ($total_h) {
$p = int( $_os_h{$key} / $total_h * 1000 ) / 10;
$p = "$p %";
}
print "";
print " ";
print "$OSHashLib{$key} ";
my $bredde_h = 0;
if ( $max_h > 0 ) {
$bredde_h =
int( $BarWidth * ( $_os_h{$key} || 0 ) / $max_h )
+ 1;
}
if ( ( $bredde_h == 1 ) && $_os_h{$key} ) {
$bredde_h = 2;
}
print "".Format_Number($_os_h{$key})." $p ";
print "";
# alt and title are not provided to reduce page size
if ($ShowOSStats) {
print
" ";
}
print " ";
print " \n";
$count++;
}
}
}
# Write other records
my $familyheadershown = 0;
foreach my $key (@keylist) {
if ( $keysinkeylist{$key} ) { next; }
if ( !$familyheadershown ) {
my $p = ' ';
if ($total_h) {
$p =
int( ( $total_h - $TotalFamily ) / $total_h * 1000 ) /
10;
$p = "$p %";
}
print
"$Message[2] ";
print ""
. Format_Number(( $total_h - $TotalFamily ))
. " $p ";
print " \n";
$familyheadershown = 1;
}
my $p = ' ';
if ($total_h) {
$p = int( $_os_h{$key} / $total_h * 1000 ) / 10;
$p = "$p %";
}
print "";
if ( $key eq 'Unknown' ) {
print "$Message[0] ";
}
else {
my $keywithoutcumul = $key;
$keywithoutcumul =~ s/cumul$//i;
my $libos = $OSHashLib{$keywithoutcumul}
|| $keywithoutcumul;
my $nameicon = $keywithoutcumul;
$nameicon =~ s/[^\w]//g;
print "$libos ";
}
my $bredde_h = 0;
if ( $max_h > 0 ) {
$bredde_h =
int( $BarWidth * ( $_os_h{$key} || 0 ) / $max_h ) + 1;
}
if ( ( $bredde_h == 1 ) && $_os_h{$key} ) { $bredde_h = 2; }
print "".Format_Number($_os_h{$key})." $p ";
print "";
# alt and title are not provided to reduce page size
if ($ShowOSStats) {
print
" ";
}
print " ";
print " \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Unkown OS Detail frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowOSUnknown{
print "$Center \n";
my $title = "$Message[46]";
&tab_head( "$title", 19, 0, 'unknownos' );
print "User agent ("
. ( scalar keys %_unknownreferer_l )
. ") $Message[9] \n";
my $total_l = 0;
my $count = 0;
&BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_unknownreferer_l,
\%_unknownreferer_l );
foreach my $key (@keylist) {
my $useragent = XMLEncode( CleanXSS($key) );
print "$useragent ";
print ""
. Format_Date( $_unknownreferer_l{$key}, 1 ) . " ";
print " \n";
$total_l += 1;
$count++;
}
my $rest_l = ( scalar keys %_unknownreferer_l ) - $total_l;
if ( $rest_l > 0 ) {
print
"$Message[2] ";
print "- ";
print " \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Referers frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowReferers{
print "$Center \n";
my $title = "$Message[40]";
&tab_head( "$title", 19, 0, 'refererse' );
print
"".Format_Number($TotalDifferentSearchEngines)." $Message[122] ";
print
"$Message[56] $Message[15] ";
print
"$Message[57] $Message[15] ";
print " \n";
my $total_s = 0;
my $total_p = 0;
my $total_h = 0;
my $rest_p = 0;
my $rest_h = 0;
my $count = 0;
&BuildKeyList(
$MaxRowsInHTMLOutput,
$MinHit{'Refer'},
\%_se_referrals_h,
(
( scalar keys %_se_referrals_p )
? \%_se_referrals_p
: \%_se_referrals_h
)
); # before 5.4 only hits were recorded
foreach my $key (@keylist) {
my $newreferer = $SearchEnginesHashLib{$key} || CleanXSS($key);
my $p_p;
my $p_h;
if ($TotalSearchEnginesPages) {
$p_p =
int( $_se_referrals_p{$key} / $TotalSearchEnginesPages *
1000 ) / 10;
}
if ($TotalSearchEnginesHits) {
$p_h =
int( $_se_referrals_h{$key} / $TotalSearchEnginesHits *
1000 ) / 10;
}
print "$newreferer ";
print ""
. (
$_se_referrals_p{$key} ? $_se_referrals_p{$key} : ' ' )
. " ";
print ""
. ( $_se_referrals_p{$key} ? "$p_p %" : ' ' ) . " ";
print "".Format_Number($_se_referrals_h{$key})." ";
print "$p_h % ";
print " \n";
$total_p += $_se_referrals_p{$key};
$total_h += $_se_referrals_h{$key};
$count++;
}
if ($Debug) {
debug(
"Total real / shown : $TotalSearchEnginesPages / $total_p - $TotalSearchEnginesHits / $total_h",
2
);
}
$rest_p = $TotalSearchEnginesPages - $total_p;
$rest_h = $TotalSearchEnginesHits - $total_h;
if ( $rest_p > 0 || $rest_h > 0 ) {
my $p_p;
my $p_h;
if ($TotalSearchEnginesPages) {
$p_p =
int( $rest_p / $TotalSearchEnginesPages * 1000 ) / 10;
}
if ($TotalSearchEnginesHits) {
$p_h = int( $rest_h / $TotalSearchEnginesHits * 1000 ) / 10;
}
print
"$Message[2] ";
print "" . ( $rest_p ? Format_Number($rest_p) : ' ' ) . " ";
print "" . ( $rest_p ? "$p_p %" : ' ' ) . " ";
print "".Format_Number($rest_h)." ";
print "$p_h % ";
print " \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Referer Pages frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowRefererPages{
print "$Center \n";
my $total_p = 0;
my $total_h = 0;
my $rest_p = 0;
my $rest_h = 0;
# Show filter form
&HTMLShowFormFilter(
"refererpagesfilter",
$FilterIn{'refererpages'},
$FilterEx{'refererpages'}
);
my $title = "$Message[41]";
my $cpt = 0;
$cpt = ( scalar keys %_pagesrefs_h );
&tab_head( "$title", 19, 0, 'refererpages' );
print "";
if ( $FilterIn{'refererpages'} || $FilterEx{'refererpages'} ) {
if ( $FilterIn{'refererpages'} ) {
print "$Message[79] $FilterIn{'refererpages'} ";
}
if ( $FilterIn{'refererpages'} && $FilterEx{'refererpages'} ) {
print " - ";
}
if ( $FilterEx{'refererpages'} ) {
print
"Exclude $Message[79] $FilterEx{'refererpages'} ";
}
if ( $FilterIn{'refererpages'} || $FilterEx{'refererpages'} ) {
print ": ";
}
print "$cpt $Message[28]";
#if ($MonthRequired ne 'all') {
# if ($HTMLOutput{'refererpages'}) { print " $Message[102]: $TotalDifferentPages $Message[28]"; }
#}
}
else { print "$Message[102]: ".Format_Number($cpt)." $Message[28]"; }
print " ";
print
"$Message[56] $Message[15] ";
print
"$Message[57] $Message[15] ";
print " \n";
my $total_s = 0;
my $count = 0;
&BuildKeyList(
$MaxRowsInHTMLOutput,
$MinHit{'Refer'},
\%_pagesrefs_h,
(
( scalar keys %_pagesrefs_p )
? \%_pagesrefs_p
: \%_pagesrefs_h
)
);
foreach my $key (@keylist) {
my $nompage = CleanXSS($key);
if ( length($nompage) > $MaxLengthOfShownURL ) {
$nompage =
substr( $nompage, 0, $MaxLengthOfShownURL ) . "...";
}
my $p_p;
my $p_h;
if ($TotalRefererPages) {
$p_p =
int( $_pagesrefs_p{$key} / $TotalRefererPages * 1000 ) /
10;
}
if ($TotalRefererHits) {
$p_h =
int( $_pagesrefs_h{$key} / $TotalRefererHits * 1000 ) /
10;
}
print "";
&HTMLShowURLInfo($key);
print " ";
print ""
. ( $_pagesrefs_p{$key} ? Format_Number($_pagesrefs_p{$key}) : ' ' )
. " "
. ( $_pagesrefs_p{$key} ? "$p_p %" : ' ' ) . " ";
print ""
. ( $_pagesrefs_h{$key} ? Format_Number($_pagesrefs_h{$key}) : ' ' )
. " "
. ( $_pagesrefs_h{$key} ? "$p_h %" : ' ' ) . " ";
print " \n";
$total_p += $_pagesrefs_p{$key};
$total_h += $_pagesrefs_h{$key};
$count++;
}
if ($Debug) {
debug(
"Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",
2
);
}
$rest_p = $TotalRefererPages - $total_p;
$rest_h = $TotalRefererHits - $total_h;
if ( $rest_p > 0 || $rest_h > 0 ) {
my $p_p;
my $p_h;
if ($TotalRefererPages) {
$p_p = int( $rest_p / $TotalRefererPages * 1000 ) / 10;
}
if ($TotalRefererHits) {
$p_h = int( $rest_h / $TotalRefererHits * 1000 ) / 10;
}
print
"$Message[2] ";
print "" . ( $rest_p ? Format_Number($rest_p) : ' ' ) . " ";
print "" . ( $rest_p ? "$p_p %" : ' ' ) . " ";
print "".Format_Number($rest_h)." ";
print "$p_h % ";
print " \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Key Phrases frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowKeyPhrases{
print "$Center \n";
&tab_head( $Message[43], 19, 0, 'keyphrases' );
print "".Format_Number($TotalDifferentKeyphrases)." $Message[103] $Message[14] $Message[15] \n";
my $total_s = 0;
my $count = 0;
&BuildKeyList(
$MaxRowsInHTMLOutput, $MinHit{'Keyphrase'},
\%_keyphrases, \%_keyphrases
);
foreach my $key (@keylist) {
my $mot;
# Convert coded keywords (utf8,...) to be correctly reported in HTML page.
if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
$mot = CleanXSS(
DecodeKey_decodeutfkeys(
$key, $PageCode || 'iso-8859-1'
)
);
}
else { $mot = CleanXSS( DecodeEncodedString($key) ); }
my $p;
if ($TotalKeyphrases) {
$p =
int( $_keyphrases{$key} / $TotalKeyphrases * 1000 ) / 10;
}
print ""
. XMLEncode($mot)
. " $_keyphrases{$key} $p % \n";
$total_s += $_keyphrases{$key};
$count++;
}
if ($Debug) {
debug( "Total real / shown : $TotalKeyphrases / $total_s", 2 );
}
my $rest_s = $TotalKeyphrases - $total_s;
if ( $rest_s > 0 ) {
my $p;
if ($TotalKeyphrases) {
$p = int( $rest_s / $TotalKeyphrases * 1000 ) / 10;
}
print
"$Message[124] ".Format_Number($rest_s)." ";
print "$p % \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Keywords frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowKeywords{
print "$Center \n";
&tab_head( $Message[44], 19, 0, 'keywords' );
print "".Format_Number($TotalDifferentKeywords)." $Message[13] $Message[14] $Message[15] \n";
my $total_s = 0;
my $count = 0;
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Keyword'},
\%_keywords, \%_keywords );
foreach my $key (@keylist) {
my $mot;
# Convert coded keywords (utf8,...) to be correctly reported in HTML page.
if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
$mot = CleanXSS(
DecodeKey_decodeutfkeys(
$key, $PageCode || 'iso-8859-1'
)
);
}
else { $mot = CleanXSS( DecodeEncodedString($key) ); }
my $p;
if ($TotalKeywords) {
$p = int( $_keywords{$key} / $TotalKeywords * 1000 ) / 10;
}
print ""
. XMLEncode($mot)
. " $_keywords{$key} $p % \n";
$total_s += $_keywords{$key};
$count++;
}
if ($Debug) {
debug( "Total real / shown : $TotalKeywords / $total_s", 2 );
}
my $rest_s = $TotalKeywords - $total_s;
if ( $rest_s > 0 ) {
my $p;
if ($TotalKeywords) {
$p = int( $rest_s / $TotalKeywords * 1000 ) / 10;
}
print
"$Message[30] ".Format_Number($rest_s)." ";
print "$p % \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the HTTP Error code frame or static page
# Parameters: $code - the error code we're printing
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowErrorCodes{
my $code = shift;
print "$Center \n";
&tab_head( $Message[47], 19, 0, "errors$code" );
print "URL ("
. Format_Number(( scalar keys %_sider404_h ))
. ") $Message[49] $Message[23] \n";
my $total_h = 0;
my $count = 0;
&BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_sider404_h,
\%_sider404_h );
foreach my $key (@keylist) {
my $nompage = XMLEncode( CleanXSS($key) );
#if (length($nompage)>$MaxLengthOfShownURL) { $nompage=substr($nompage,0,$MaxLengthOfShownURL)."..."; }
my $referer = XMLEncode( CleanXSS( $_referer404_h{$key} ) );
print "$nompage ";
print "".Format_Number($_sider404_h{$key})." ";
print ""
. ( $referer ? "$referer" : " " ) . " ";
print " \n";
my $total_s += $_sider404_h{$key};
$count++;
}
# TODO Build TotalErrorHits
# if ($Debug) { debug("Total real / shown : $TotalErrorHits / $total_h",2); }
# $rest_h=$TotalErrorHits-$total_h;
# if ($rest_h > 0) {
# my $p;
# if ($TotalErrorHits) { $p=int($rest_h/$TotalErrorHits*1000)/10; }
# print "$Message[30] ";
# print "$rest_h ";
# print "... ";
# print " \n";
# }
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Loops through any defined extra sections and dumps the info to HTML
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowExtraSections{
foreach my $extranum ( 1 .. @ExtraName - 1 ) {
my $total_p = 0;
my $total_h = 0;
my $total_k = 0;
if ( $HTMLOutput{"allextra$extranum"} ) {
if ($Debug) { debug( "ExtraName$extranum", 2 ); }
print "$Center ";
my $title = $ExtraName[$extranum];
&tab_head( "$title", 19, 0, "extra$extranum" );
print "";
print "" . $ExtraFirstColumnTitle[$extranum] . " ";
if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
print
"$Message[56] ";
}
if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
print
"$Message[57] ";
}
if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
print
"$Message[75] ";
}
if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
print "$Message[9] ";
}
print " \n";
$total_p = $total_h = $total_k = 0;
#$max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
#$max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
my $count = 0;
if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
&BuildKeyList(
$MaxRowsInHTMLOutput,
$MinHitExtra[$extranum],
\%{ '_section_' . $extranum . '_h' },
\%{ '_section_' . $extranum . '_p' }
);
}
else {
&BuildKeyList(
$MaxRowsInHTMLOutput,
$MinHitExtra[$extranum],
\%{ '_section_' . $extranum . '_h' },
\%{ '_section_' . $extranum . '_h' }
);
}
my %keysinkeylist = ();
foreach my $key (@keylist) {
$keysinkeylist{$key} = 1;
my $firstcol = CleanXSS( DecodeEncodedString($key) );
$total_p += ${ '_section_' . $extranum . '_p' }{$key};
$total_h += ${ '_section_' . $extranum . '_h' }{$key};
$total_k += ${ '_section_' . $extranum . '_k' }{$key};
print "";
printf(
"$ExtraFirstColumnFormat[$extranum] ",
$firstcol, $firstcol, $firstcol, $firstcol, $firstcol );
if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
print ""
. ${ '_section_' . $extranum . '_p' }{$key} . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
print ""
. ${ '_section_' . $extranum . '_h' }{$key} . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
print ""
. Format_Bytes(
${ '_section_' . $extranum . '_k' }{$key} )
. " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
print ""
. (
${ '_section_' . $extranum . '_l' }{$key}
? Format_Date(
${ '_section_' . $extranum . '_l' }{$key}, 1 )
: '-'
)
. " ";
}
print " \n";
$count++;
}
# If we ask average or sum, we loop on all other records
if ( $ExtraAddAverageRow[$extranum]
|| $ExtraAddSumRow[$extranum] )
{
foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
if ( $keysinkeylist{$_} ) { next; }
$total_p += ${ '_section_' . $extranum . '_p' }{$_};
$total_h += ${ '_section_' . $extranum . '_h' }{$_};
$total_k += ${ '_section_' . $extranum . '_k' }{$_};
$count++;
}
}
# Add average row
if ( $ExtraAddAverageRow[$extranum] ) {
print "";
print "$Message[96] ";
if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
print ""
. ( $count ? Format_Number(( $total_p / $count )) : " " )
. " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
print ""
. ( $count ? Format_Number(( $total_h / $count )) : " " )
. " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
print ""
. (
$count
? Format_Bytes( $total_k / $count )
: " "
)
. " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
print " ";
}
print " \n";
}
# Add sum row
if ( $ExtraAddSumRow[$extranum] ) {
print "";
print "$Message[102] ";
if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
print "" . ($total_p) . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
print "" . ($total_h) . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
print "" . Format_Bytes($total_k) . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
print " ";
}
print " \n";
}
&tab_end();
&html_end(1);
}
}
}
#------------------------------------------------------------------------------
# Function: Prints the Robot details frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowRobots{
my $total_p = 0;
my $total_h = 0;
my $total_k = 0;
my $total_r = 0;
my $rest_p = 0;
my $rest_h = 0;
my $rest_k = 0;
my $rest_r = 0;
print "$Center \n";
my $title = '';
if ( $HTMLOutput{'allrobots'} ) { $title .= "$Message[53]"; }
if ( $HTMLOutput{'lastrobots'} ) { $title .= "$Message[9]"; }
&tab_head( "$title", 19, 0, 'robots' );
print ""
. Format_Number(( scalar keys %_robot_h ))
. " $Message[51] ";
if ( $ShowRobotsStats =~ /H/i ) {
print
"$Message[57] ";
}
if ( $ShowRobotsStats =~ /B/i ) {
print
"$Message[75] ";
}
if ( $ShowRobotsStats =~ /L/i ) {
print "$Message[9] ";
}
print " \n";
$total_p = $total_h = $total_k = $total_r = 0;
my $count = 0;
if ( $HTMLOutput{'allrobots'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Robot'},
\%_robot_h, \%_robot_h );
}
if ( $HTMLOutput{'lastrobots'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Robot'},
\%_robot_h, \%_robot_l );
}
foreach my $key (@keylist) {
print ""
. ( $RobotsHashIDLib{$key} ? $RobotsHashIDLib{$key} : $key )
. " ";
if ( $ShowRobotsStats =~ /H/i ) {
print ""
. Format_Number(( $_robot_h{$key} - $_robot_r{$key} ))
. ( $_robot_r{$key} ? "+$_robot_r{$key}" : "" ) . " ";
}
if ( $ShowRobotsStats =~ /B/i ) {
print "" . Format_Bytes( $_robot_k{$key} ) . " ";
}
if ( $ShowRobotsStats =~ /L/i ) {
print ""
. (
$_robot_l{$key}
? Format_Date( $_robot_l{$key}, 1 )
: '-'
)
. " ";
}
print " \n";
#$total_p += $_robot_p{$key}||0;
$total_h += $_robot_h{$key};
$total_k += $_robot_k{$key} || 0;
$total_r += $_robot_r{$key} || 0;
$count++;
}
# For bots we need to count Totals
my $TotalPagesRobots =
0; #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
my $TotalHitsRobots = 0;
foreach ( values %_robot_h ) { $TotalHitsRobots += $_; }
my $TotalBytesRobots = 0;
foreach ( values %_robot_k ) { $TotalBytesRobots += $_; }
my $TotalRRobots = 0;
foreach ( values %_robot_r ) { $TotalRRobots += $_; }
$rest_p = 0; #$rest_p=$TotalPagesRobots-$total_p;
$rest_h = $TotalHitsRobots - $total_h;
$rest_k = $TotalBytesRobots - $total_k;
$rest_r = $TotalRRobots - $total_r;
if ($Debug) {
debug(
"Total real / shown : $TotalPagesRobots / $total_p - $TotalHitsRobots / $total_h - $TotalBytesRobots / $total_k",
2
);
}
if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0 )
{ # All other robots
print
"$Message[2] ";
if ( $ShowRobotsStats =~ /H/i ) { print "".Format_Number($rest_h)." "; }
if ( $ShowRobotsStats =~ /B/i ) {
print "" . ( Format_Bytes($rest_k) ) . " ";
}
if ( $ShowRobotsStats =~ /L/i ) { print " "; }
print " \n";
}
&tab_end(
"* $Message[156]" . ( $TotalRRobots ? " $Message[157]" : "" ) );
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the URL, Entry or Exit details frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowURLDetail{
my $total_p = 0;
my $total_e = 0;
my $total_k = 0;
my $total_x = 0;
# Call to plugins' function ShowPagesFilter
foreach
my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesFilter'} } )
{
my $function = "ShowPagesFilter_$pluginname";
&$function();
}
print "$Center \n";
# Show filter form
&HTMLShowFormFilter( "urlfilter", $FilterIn{'url'}, $FilterEx{'url'} );
# Show URL list
my $title = '';
my $cpt = 0;
if ( $HTMLOutput{'urldetail'} ) {
$title = $Message[19];
$cpt = ( scalar keys %_url_p );
}
if ( $HTMLOutput{'urlentry'} ) {
$title = $Message[104];
$cpt = ( scalar keys %_url_e );
}
if ( $HTMLOutput{'urlexit'} ) {
$title = $Message[116];
$cpt = ( scalar keys %_url_x );
}
&tab_head( "$title", 19, 0, 'urls' );
print "";
if ( $FilterIn{'url'} || $FilterEx{'url'} ) {
if ( $FilterIn{'url'} ) {
print "$Message[79] $FilterIn{'url'} ";
}
if ( $FilterIn{'url'} && $FilterEx{'url'} ) { print " - "; }
if ( $FilterEx{'url'} ) {
print "Exclude $Message[79] $FilterEx{'url'} ";
}
if ( $FilterIn{'url'} || $FilterEx{'url'} ) { print ": "; }
print Format_Number($cpt)." $Message[28]";
if ( $MonthRequired ne 'all' ) {
if ( $HTMLOutput{'urldetail'} ) {
print
" $Message[102]: ".Format_Number($TotalDifferentPages)." $Message[28]";
}
}
}
else { print "$Message[102]: ".Format_Number($cpt)." $Message[28]"; }
print " ";
if ( $ShowPagesStats =~ /P/i ) {
print
"$Message[29] ";
}
if ( $ShowPagesStats =~ /B/i ) {
print
"$Message[106] ";
}
if ( $ShowPagesStats =~ /E/i ) {
print
"$Message[104] ";
}
if ( $ShowPagesStats =~ /X/i ) {
print
"$Message[116] ";
}
# Call to plugins' function ShowPagesAddField
foreach
my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
{
# my $function="ShowPagesAddField_$pluginname('title')";
# eval("$function");
my $function = "ShowPagesAddField_$pluginname";
&$function('title');
}
print " \n";
$total_p = $total_k = $total_e = $total_x = 0;
my $count = 0;
if ( $HTMLOutput{'urlentry'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_e,
\%_url_e );
}
elsif ( $HTMLOutput{'urlexit'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_x,
\%_url_x );
}
else {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_p,
\%_url_p );
}
my $max_p = 1;
my $max_k = 1;
foreach my $key (@keylist) {
if ( $_url_p{$key} > $max_p ) { $max_p = $_url_p{$key}; }
if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
$max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
}
}
foreach my $key (@keylist) {
print "";
&HTMLShowURLInfo($key);
print " ";
my $bredde_p = 0;
my $bredde_e = 0;
my $bredde_x = 0;
my $bredde_k = 0;
if ( $max_p > 0 ) {
$bredde_p =
int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
}
if ( ( $bredde_p == 1 ) && $_url_p{$key} ) { $bredde_p = 2; }
if ( $max_p > 0 ) {
$bredde_e =
int( $BarWidth * ( $_url_e{$key} || 0 ) / $max_p ) + 1;
}
if ( ( $bredde_e == 1 ) && $_url_e{$key} ) { $bredde_e = 2; }
if ( $max_p > 0 ) {
$bredde_x =
int( $BarWidth * ( $_url_x{$key} || 0 ) / $max_p ) + 1;
}
if ( ( $bredde_x == 1 ) && $_url_x{$key} ) { $bredde_x = 2; }
if ( $max_k > 0 ) {
$bredde_k =
int( $BarWidth *
( ( $_url_k{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
$max_k ) + 1;
}
if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
if ( $ShowPagesStats =~ /P/i ) {
print "".Format_Number($_url_p{$key})." ";
}
if ( $ShowPagesStats =~ /B/i ) {
print ""
. (
$_url_k{$key}
? Format_Bytes(
$_url_k{$key} / ( $_url_p{$key} || 1 )
)
: " "
)
. " ";
}
if ( $ShowPagesStats =~ /E/i ) {
print ""
. ( $_url_e{$key} ? Format_Number($_url_e{$key}) : " " ) . " ";
}
if ( $ShowPagesStats =~ /X/i ) {
print ""
. ( $_url_x{$key} ? Format_Number($_url_x{$key}) : " " ) . " ";
}
# Call to plugins' function ShowPagesAddField
foreach my $pluginname (
keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
{
# my $function="ShowPagesAddField_$pluginname('$key')";
# eval("$function");
my $function = "ShowPagesAddField_$pluginname";
&$function($key);
}
print "";
# alt and title are not provided to reduce page size
if ( $ShowPagesStats =~ /P/i ) {
print
" ";
}
if ( $ShowPagesStats =~ /B/i ) {
print
" ";
}
if ( $ShowPagesStats =~ /E/i ) {
print
" ";
}
if ( $ShowPagesStats =~ /X/i ) {
print
" ";
}
print " \n";
$total_p += $_url_p{$key};
$total_e += $_url_e{$key};
$total_x += $_url_x{$key};
$total_k += $_url_k{$key};
$count++;
}
if ($Debug) {
debug(
"Total real / shown : $TotalPages / $total_p - $TotalEntries / $total_e - $TotalExits / $total_x - $TotalBytesPages / $total_k",
2
);
}
my $rest_p = $TotalPages - $total_p;
my $rest_k = $TotalBytesPages - $total_k;
my $rest_e = $TotalEntries - $total_e;
my $rest_x = $TotalExits - $total_x;
if ( $rest_p > 0 || $rest_e > 0 || $rest_k > 0 ) {
print
"$Message[2] ";
if ( $ShowPagesStats =~ /P/i ) {
print "" . ( $rest_p ? Format_Number($rest_p) : " " ) . " ";
}
if ( $ShowPagesStats =~ /B/i ) {
print ""
. (
$rest_k
? Format_Bytes( $rest_k / ( $rest_p || 1 ) )
: " "
)
. " ";
}
if ( $ShowPagesStats =~ /E/i ) {
print "" . ( $rest_e ? Format_Number($rest_e) : " " ) . " ";
}
if ( $ShowPagesStats =~ /X/i ) {
print "" . ( $rest_x ? Format_Number($rest_x) : " " ) . " ";
}
# Call to plugins' function ShowPagesAddField
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
{
my $function = "ShowPagesAddField_$pluginname";
&$function('');
}
print " \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Login details frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowLogins{
my $total_p = 0;
my $total_h = 0;
my $total_k = 0;
my $rest_p = 0;
my $rest_h = 0;
my $rest_k = 0;
print "$Center \n";
my $title = '';
if ( $HTMLOutput{'alllogins'} ) { $title .= "$Message[94]"; }
if ( $HTMLOutput{'lastlogins'} ) { $title .= "$Message[9]"; }
&tab_head( "$title", 19, 0, 'logins' );
print "$Message[94] : "
. Format_Number(( scalar keys %_login_h )) . " ";
&HTMLShowUserInfo('__title__');
if ( $ShowAuthenticatedUsers =~ /P/i ) {
print
"$Message[56] ";
}
if ( $ShowAuthenticatedUsers =~ /H/i ) {
print
"$Message[57] ";
}
if ( $ShowAuthenticatedUsers =~ /B/i ) {
print
"$Message[75] ";
}
if ( $ShowAuthenticatedUsers =~ /L/i ) {
print "$Message[9] ";
}
print " \n";
$total_p = $total_h = $total_k = 0;
my $count = 0;
if ( $HTMLOutput{'alllogins'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'},
\%_login_h, \%_login_p );
}
if ( $HTMLOutput{'lastlogins'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'},
\%_login_h, \%_login_l );
}
foreach my $key (@keylist) {
print "$key ";
&HTMLShowUserInfo($key);
if ( $ShowAuthenticatedUsers =~ /P/i ) {
print ""
. ( $_login_p{$key} ? Format_Number($_login_p{$key}) : " " )
. " ";
}
if ( $ShowAuthenticatedUsers =~ /H/i ) {
print "".Format_Number($_login_h{$key})." ";
}
if ( $ShowAuthenticatedUsers =~ /B/i ) {
print "" . Format_Bytes( $_login_k{$key} ) . " ";
}
if ( $ShowAuthenticatedUsers =~ /L/i ) {
print ""
. (
$_login_l{$key}
? Format_Date( $_login_l{$key}, 1 )
: '-'
)
. " ";
}
print " \n";
$total_p += $_login_p{$key} || 0;
$total_h += $_login_h{$key};
$total_k += $_login_k{$key} || 0;
$count++;
}
if ($Debug) {
debug(
"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
2
);
}
$rest_p = $TotalPages - $total_p;
$rest_h = $TotalHits - $total_h;
$rest_k = $TotalBytes - $total_k;
if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
{ # All other logins and/or anonymous
print
"$Message[125] ";
&HTMLShowUserInfo('');
if ( $ShowAuthenticatedUsers =~ /P/i ) {
print "" . ( $rest_p ? Format_Number($rest_p) : " " ) . " ";
}
if ( $ShowAuthenticatedUsers =~ /H/i ) {
print "".Format_Number($rest_h)." ";
}
if ( $ShowAuthenticatedUsers =~ /B/i ) {
print "" . Format_Bytes($rest_k) . " ";
}
if ( $ShowAuthenticatedUsers =~ /L/i ) {
print " ";
}
print " \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Unknown IP/Host details frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowHostsUnknown{
my $total_p = 0;
my $total_h = 0;
my $total_k = 0;
my $rest_p = 0;
my $rest_h = 0;
my $rest_k = 0;
print "$Center \n";
&tab_head( "$Message[45]", 19, 0, 'unknownwip' );
print ""
. Format_Number(( scalar keys %_host_h ))
. " $Message[1] ";
&HTMLShowHostInfo('__title__');
if ( $ShowHostsStats =~ /P/i ) {
print
"$Message[56] ";
}
if ( $ShowHostsStats =~ /H/i ) {
print
"$Message[57] ";
}
if ( $ShowHostsStats =~ /B/i ) {
print
"$Message[75] ";
}
if ( $ShowHostsStats =~ /L/i ) {
print "$Message[9] ";
}
print " \n";
$total_p = $total_h = $total_k = 0;
my $count = 0;
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
\%_host_p );
foreach my $key (@keylist) {
my $host = CleanXSS($key);
print "$host ";
&HTMLShowHostInfo($key);
if ( $ShowHostsStats =~ /P/i ) {
print ""
. ( $_host_p{$key} ? Format_Number($_host_p{$key}) : " " )
. " ";
}
if ( $ShowHostsStats =~ /H/i ) {
print "".Format_Number($_host_h{$key})." ";
}
if ( $ShowHostsStats =~ /B/i ) {
print "" . Format_Bytes( $_host_k{$key} ) . " ";
}
if ( $ShowHostsStats =~ /L/i ) {
print ""
. (
$_host_l{$key}
? Format_Date( $_host_l{$key}, 1 )
: '-'
)
. " ";
}
print " \n";
$total_p += $_host_p{$key};
$total_h += $_host_h{$key};
$total_k += $_host_k{$key} || 0;
$count++;
}
if ($Debug) {
debug(
"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
2
);
}
$rest_p = $TotalPages - $total_p;
$rest_h = $TotalHits - $total_h;
$rest_k = $TotalBytes - $total_k;
if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
{ # All other visitors (known or not)
print
"$Message[82] ";
&HTMLShowHostInfo('');
if ( $ShowHostsStats =~ /P/i ) {
print "" . ( $rest_p ? Format_Number($rest_p) : " " ) . " ";
}
if ( $ShowHostsStats =~ /H/i ) { print "".Format_Number($rest_h)." "; }
if ( $ShowHostsStats =~ /B/i ) {
print "" . Format_Bytes($rest_k) . " ";
}
if ( $ShowHostsStats =~ /L/i ) { print " "; }
print " \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Host details frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowHosts{
my $total_p = 0;
my $total_h = 0;
my $total_k = 0;
my $rest_p = 0;
my $rest_h = 0;
my $rest_k = 0;
print "$Center \n";
# Show filter form
&HTMLShowFormFilter( "hostfilter", $FilterIn{'host'},
$FilterEx{'host'} );
# Show hosts list
my $title = '';
my $cpt = 0;
if ( $HTMLOutput{'allhosts'} ) {
$title .= "$Message[81]";
$cpt = ( scalar keys %_host_h );
}
if ( $HTMLOutput{'lasthosts'} ) {
$title .= "$Message[9]";
$cpt = ( scalar keys %_host_h );
}
&tab_head( "$title", 19, 0, 'hosts' );
print "";
if ( $FilterIn{'host'} || $FilterEx{'host'} ) { # With filter
if ( $FilterIn{'host'} ) {
print "$Message[79] '$FilterIn{'host'} '";
}
if ( $FilterIn{'host'} && $FilterEx{'host'} ) { print " - "; }
if ( $FilterEx{'host'} ) {
print " Exlude $Message[79] '$FilterEx{'host'} '";
}
if ( $FilterIn{'host'} || $FilterEx{'host'} ) { print ": "; }
print "$cpt $Message[81]";
if ( $MonthRequired ne 'all' ) {
if ( $HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'} ) {
print
" $Message[102]: ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1] - ".Format_Number($TotalUnique)." $Message[11]";
}
}
}
else { # Without filter
if ( $MonthRequired ne 'all' ) {
print
"$Message[102] : ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1] - ".Format_Number($TotalUnique)." $Message[11]";
}
else { print "$Message[102] : " . Format_Number(( scalar keys %_host_h )); }
}
print " ";
&HTMLShowHostInfo('__title__');
if ( $ShowHostsStats =~ /P/i ) {
print
"$Message[56] ";
}
if ( $ShowHostsStats =~ /H/i ) {
print
"$Message[57] ";
}
if ( $ShowHostsStats =~ /B/i ) {
print
"$Message[75] ";
}
if ( $ShowHostsStats =~ /L/i ) {
print "$Message[9] ";
}
print " \n";
$total_p = $total_h = $total_k = 0;
my $count = 0;
if ( $HTMLOutput{'allhosts'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
\%_host_p );
}
if ( $HTMLOutput{'lasthosts'} ) {
&BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
\%_host_l );
}
foreach my $key (@keylist) {
my $host = CleanXSS($key);
print ""
. ( $_robot_l{$key} ? '' : '' ) . "$host"
. ( $_robot_l{$key} ? ' ' : '' ) . " ";
&HTMLShowHostInfo($key);
if ( $ShowHostsStats =~ /P/i ) {
print ""
. ( $_host_p{$key} ? Format_Number($_host_p{$key}) : " " )
. " ";
}
if ( $ShowHostsStats =~ /H/i ) {
print "".Format_Number($_host_h{$key})." ";
}
if ( $ShowHostsStats =~ /B/i ) {
print "" . Format_Bytes( $_host_k{$key} ) . " ";
}
if ( $ShowHostsStats =~ /L/i ) {
print ""
. (
$_host_l{$key}
? Format_Date( $_host_l{$key}, 1 )
: '-'
)
. " ";
}
print " \n";
$total_p += $_host_p{$key};
$total_h += $_host_h{$key};
$total_k += $_host_k{$key} || 0;
$count++;
}
if ($Debug) {
debug(
"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
2
);
}
$rest_p = $TotalPages - $total_p;
$rest_h = $TotalHits - $total_h;
$rest_k = $TotalBytes - $total_k;
if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
{ # All other visitors (known or not)
print
"$Message[2] ";
&HTMLShowHostInfo('');
if ( $ShowHostsStats =~ /P/i ) {
print "" . ( $rest_p ? Format_Number($rest_p) : " " ) . " ";
}
if ( $ShowHostsStats =~ /H/i ) { print "".Format_Number($rest_h)." "; }
if ( $ShowHostsStats =~ /B/i ) {
print "" . Format_Bytes($rest_k) . " ";
}
if ( $ShowHostsStats =~ /L/i ) { print " "; }
print " \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Domains details frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowDomains{
my $total_p = 0;
my $total_h = 0;
my $total_k = 0;
my $total_v = 0;
my $total_u = 0;
my $rest_p = 0;
my $rest_h = 0;
my $rest_k = 0;
my $rest_v = 0;
my $rest_u = 0;
print "$Center \n";
# Show domains list
my $title = '';
my $cpt = 0;
if ( $HTMLOutput{'alldomains'} ) {
$title .= "$Message[25]";
$cpt = ( scalar keys %_domener_h );
}
&tab_head( "$title", 19, 0, 'domains' );
print
" $Message[17] ";
if ( $ShowDomainsStats =~ /U/i ) {
print
"$Message[11] ";
}
if ( $ShowDomainsStats =~ /V/i ) {
print
"$Message[10] ";
}
if ( $ShowDomainsStats =~ /P/i ) {
print
"$Message[56] ";
}
if ( $ShowDomainsStats =~ /H/i ) {
print
"$Message[57] ";
}
if ( $ShowDomainsStats =~ /B/i ) {
print
"$Message[75] ";
}
print " ";
print " \n";
$total_u = $total_v = $total_p = $total_h = $total_k = 0;
my $max_h = 1;
foreach ( values %_domener_h ) {
if ( $_ > $max_h ) { $max_h = $_; }
}
my $max_k = 1;
foreach ( values %_domener_k ) {
if ( $_ > $max_k ) { $max_k = $_; }
}
my $count = 0;
&BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_domener_h,
\%_domener_p );
foreach my $key (@keylist) {
my ( $_domener_u, $_domener_v );
my $bredde_p = 0;
my $bredde_h = 0;
my $bredde_k = 0;
if ( $max_h > 0 ) {
$bredde_p =
int( $BarWidth * $_domener_p{$key} / $max_h ) + 1;
} # use max_h to enable to compare pages with hits
if ( $_domener_p{$key} && $bredde_p == 1 ) { $bredde_p = 2; }
if ( $max_h > 0 ) {
$bredde_h =
int( $BarWidth * $_domener_h{$key} / $max_h ) + 1;
}
if ( $_domener_h{$key} && $bredde_h == 1 ) { $bredde_h = 2; }
if ( $max_k > 0 ) {
$bredde_k =
int( $BarWidth * ( $_domener_k{$key} || 0 ) / $max_k ) +
1;
}
if ( $_domener_k{$key} && $bredde_k == 1 ) { $bredde_k = 2; }
my $newkey = lc($key);
if ( $newkey eq 'ip' || !$DomainsHashIDLib{$newkey} ) {
print
"$Message[0] $newkey ";
}
else {
print
"$DomainsHashIDLib{$newkey} $newkey ";
}
## to add unique visitors and number of visits, by Josep Ruano @ CAPSiDE
if ( $ShowDomainsStats =~ /U/i ) {
$_domener_u = (
$_domener_p{$key}
? $_domener_p{$key} / $TotalPages
: 0
);
$_domener_u += ( $_domener_h{$key} / $TotalHits );
$_domener_u =
sprintf( "%.0f", ( $_domener_u * $TotalUnique ) / 2 );
print "".Format_Number($_domener_u)." ("
. sprintf( "%.1f%", 100 * $_domener_u / $TotalUnique )
. ") ";
}
if ( $ShowDomainsStats =~ /V/i ) {
$_domener_v = (
$_domener_p{$key}
? $_domener_p{$key} / $TotalPages
: 0
);
$_domener_v += ( $_domener_h{$key} / $TotalHits );
$_domener_v =
sprintf( "%.0f", ( $_domener_v * $TotalVisits ) / 2 );
print "".Format_Number($_domener_v)." ("
. sprintf( "%.1f%", 100 * $_domener_v / $TotalVisits )
. ") ";
}
if ( $ShowDomainsStats =~ /P/i ) {
print "".Format_Number($_domener_p{$key})." ";
}
if ( $ShowDomainsStats =~ /H/i ) {
print "".Format_Number($_domener_h{$key})." ";
}
if ( $ShowDomainsStats =~ /B/i ) {
print "" . Format_Bytes( $_domener_k{$key} ) . " ";
}
print "";
if ( $ShowDomainsStats =~ /P/i ) {
print
" \n";
}
if ( $ShowDomainsStats =~ /H/i ) {
print
" \n";
}
if ( $ShowDomainsStats =~ /B/i ) {
print
" ";
}
print " ";
print " \n";
$total_u += $_domener_u;
$total_v += $_domener_v;
$total_p += $_domener_p{$key};
$total_h += $_domener_h{$key};
$total_k += $_domener_k{$key} || 0;
$count++;
}
my $rest_u = $TotalUnique - $total_u;
my $rest_v = $TotalVisits - $total_v;
$rest_p = $TotalPages - $total_p;
$rest_h = $TotalHits - $total_h;
$rest_k = $TotalBytes - $total_k;
if ( $rest_u > 0
|| $rest_v > 0
|| $rest_p > 0
|| $rest_h > 0
|| $rest_k > 0 )
{ # All other domains (known or not)
print
" $Message[2] ";
if ( $ShowDomainsStats =~ /U/i ) { print "$rest_u "; }
if ( $ShowDomainsStats =~ /V/i ) { print "$rest_v "; }
if ( $ShowDomainsStats =~ /P/i ) { print "$rest_p "; }
if ( $ShowDomainsStats =~ /H/i ) { print "$rest_h "; }
if ( $ShowDomainsStats =~ /B/i ) {
print "" . Format_Bytes($rest_k) . " ";
}
print " ";
print " \n";
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Downloads code frame or static page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLShowDownloads{
my $regext = qr/\.(\w{1,6})$/;
print "$Center \n";
&tab_head( $Message[178], 19, 0, "downloads" );
print "$Message[178] ";
if ( $ShowFileTypesStats =~ /H/i ){print "$Message[57] "
."206 $Message[57] "; }
if ( $ShowFileTypesStats =~ /B/i ){
print "$Message[75] ";
print "$Message[106] ";
}
print " \n";
my $count = 0;
for my $u (sort {$_downloads{$b}->{'AWSTATS_HITS'} <=> $_downloads{$a}->{'AWSTATS_HITS'}}(keys %_downloads) ){
print "";
my $ext = Get_Extension($regext, $u);
if ( !$ext) {
print " ";
}
else {
my $nameicon = $MimeHashLib{$ext}[0] || "notavailable";
my $nametype = $MimeHashFamily{$MimeHashLib{$ext}[0]} || " ";
print " ";
}
print "";
&HTMLShowURLInfo($u);
print " ";
if ( $ShowFileTypesStats =~ /H/i ){
print "".Format_Number($_downloads{$u}->{'AWSTATS_HITS'})." ";
print "".Format_Number($_downloads{$u}->{'AWSTATS_206'})." ";
}
if ( $ShowFileTypesStats =~ /B/i ){
print "".Format_Bytes($_downloads{$u}->{'AWSTATS_SIZE'})." ";
print "".Format_Bytes(($_downloads{$u}->{'AWSTATS_SIZE'}/
($_downloads{$u}->{'AWSTATS_HITS'} + $_downloads{$u}->{'AWSTATS_206'})))." ";
}
print " \n";
$count++;
if ($count >= $MaxRowsInHTMLOutput){last;}
}
&tab_end();
&html_end(1);
}
#------------------------------------------------------------------------------
# Function: Prints the Summary section at the top of the main page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainSummary{
if ($Debug) { debug( "ShowSummary", 2 ); }
# FirstTime LastTime
my $FirstTime = 0;
my $LastTime = 0;
foreach my $key ( keys %FirstTime ) {
my $keyqualified = 0;
if ( $MonthRequired eq 'all' ) { $keyqualified = 1; }
if ( $key =~ /^$YearRequired$MonthRequired/ ) { $keyqualified = 1; }
if ($keyqualified) {
if ( $FirstTime{$key}
&& ( $FirstTime == 0 || $FirstTime > $FirstTime{$key} ) )
{
$FirstTime = $FirstTime{$key};
}
if ( $LastTime < ( $LastTime{$key} || 0 ) ) {
$LastTime = $LastTime{$key};
}
}
}
#print "$Center \n";
my $title = "$Message[128]";
&tab_head( "$title", 0, 0, 'month' );
my $NewLinkParams = ${QueryString};
$NewLinkParams =~ s/(^|&|&)update(=\w*|$)//i;
$NewLinkParams =~ s/(^|&|&)staticlinks(=\w*|$)//i;
$NewLinkParams =~ s/(^|&|&)year=[^&]*//i;
$NewLinkParams =~ s/(^|&|&)month=[^&]*//i;
$NewLinkParams =~ s/(^|&|&)framename=[^&]*//i;
$NewLinkParams =~ s/(&|&)+/&/i;
$NewLinkParams =~ s/^&//;
$NewLinkParams =~ s/&$//;
if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&"; }
my $NewLinkTarget = '';
if ( $FrameName eq 'mainright' ) {
$NewLinkTarget = " target=\"_parent\"";
}
# Ratio
my $RatioVisits = 0;
my $RatioPages = 0;
my $RatioHits = 0;
my $RatioBytes = 0;
if ( $TotalUnique > 0 ) {
$RatioVisits = int( $TotalVisits / $TotalUnique * 100 ) / 100;
}
if ( $TotalVisits > 0 ) {
$RatioPages = int( $TotalPages / $TotalVisits * 100 ) / 100;
}
if ( $TotalVisits > 0 ) {
$RatioHits = int( $TotalHits / $TotalVisits * 100 ) / 100;
}
if ( $TotalVisits > 0 ) {
$RatioBytes =
int( ( $TotalBytes / 1024 ) * 100 /
( $LogType eq 'M' ? $TotalHits : $TotalVisits ) ) / 100;
}
my $colspan = 5;
my $w = '20';
if ( $LogType eq 'W' || $LogType eq 'S' ) {
$w = '17';
$colspan = 6;
}
# Show first/last
print "";
print
"$Message[133] \n";
print( $MonthRequired eq 'all'
? "$Message[6] $YearRequired"
: "$Message[5] "
. $MonthNumLib{$MonthRequired}
. " $YearRequired"
);
print " \n";
print "";
print "$Message[8] \n";
print ""
. ( $FirstTime ? Format_Date( $FirstTime, 0 ) : "NA" ) . " ";
print " \n";
print "";
print "$Message[9] \n";
print ""
. ( $LastTime ? Format_Date( $LastTime, 0 ) : "NA" )
. " \n";
print " \n";
# Show main indicators title row
print "";
if ( $LogType eq 'W' || $LogType eq 'S' ) {
print " ";
}
if ( $ShowSummary =~ /U/i ) {
print "$Message[11] ";
}
else {
print
" ";
}
if ( $ShowSummary =~ /V/i ) {
print "$Message[10] ";
}
else {
print
" ";
}
if ( $ShowSummary =~ /P/i ) {
print "$Message[56] ";
}
else {
print
" ";
}
if ( $ShowSummary =~ /H/i ) {
print "$Message[57] ";
}
else {
print
" ";
}
if ( $ShowSummary =~ /B/i ) {
print "$Message[75] ";
}
else {
print
" ";
}
print " \n";
# Show main indicators values for viewed traffic
print "";
if ( $LogType eq 'M' ) {
print "$Message[165] ";
print " \n";
print " \n";
if ( $ShowSummary =~ /H/i ) {
print "".Format_Number($TotalHits)." "
. (
$LogType eq 'M'
? ""
: " ($RatioHits "
. lc( $Message[57] . "/" . $Message[12] ) . ")"
)
. " ";
}
else { print " "; }
if ( $ShowSummary =~ /B/i ) {
print ""
. Format_Bytes( int($TotalBytes) )
. " ($RatioBytes $Message[108]/"
. $Message[ ( $LogType eq 'M' ? 149 : 12 ) ]
. ") ";
}
else { print " "; }
}
else {
if ( $LogType eq 'W' || $LogType eq 'S' ) {
print "$Message[160] * ";
}
if ( $ShowSummary =~ /U/i ) {
print ""
. (
$MonthRequired eq 'all'
? "<= ".Format_Number($TotalUnique)." $Message[129]"
: "".Format_Number($TotalUnique)." "
)
. " ";
}
else { print " "; }
if ( $ShowSummary =~ /V/i ) {
print
"".Format_Number($TotalVisits)." ($RatioVisits $Message[52]) ";
}
else { print " "; }
if ( $ShowSummary =~ /P/i ) {
print "".Format_Number($TotalPages)." ($RatioPages "
. $Message[56] . "/"
. $Message[12]
. ") ";
}
else { print " "; }
if ( $ShowSummary =~ /H/i ) {
print "".Format_Number($TotalHits)." "
. (
$LogType eq 'M'
? ""
: " ($RatioHits "
. $Message[57] . "/"
. $Message[12] . ")"
)
. " ";
}
else { print " "; }
if ( $ShowSummary =~ /B/i ) {
print ""
. Format_Bytes( int($TotalBytes) )
. " ($RatioBytes $Message[108]/"
. $Message[ ( $LogType eq 'M' ? 149 : 12 ) ]
. ") ";
}
else { print " "; }
}
print " \n";
# Show main indicators values for not viewed traffic values
if ( $LogType eq 'M' || $LogType eq 'W' || $LogType eq 'S' ) {
print "";
if ( $LogType eq 'M' ) {
print "$Message[166] ";
print " \n";
print " \n";
if ( $ShowSummary =~ /H/i ) {
print "".Format_Number($TotalNotViewedHits)." ";
}
else { print " "; }
if ( $ShowSummary =~ /B/i ) {
print ""
. Format_Bytes( int($TotalNotViewedBytes) )
. " ";
}
else { print " "; }
}
else {
if ( $LogType eq 'W' || $LogType eq 'S' ) {
print "$Message[161] * ";
}
print " \n";
if ( $ShowSummary =~ /P/i ) {
print "".Format_Number($TotalNotViewedPages)." ";
}
else { print " "; }
if ( $ShowSummary =~ /H/i ) {
print "".Format_Number($TotalNotViewedHits)." ";
}
else { print " "; }
if ( $ShowSummary =~ /B/i ) {
print ""
. Format_Bytes( int($TotalNotViewedBytes) )
. " ";
}
else { print " "; }
}
print " \n";
}
&tab_end($LogType eq 'W'
|| $LogType eq 'S' ? "* $Message[159]" : "" );
}
#------------------------------------------------------------------------------
# Function: Prints the Monthly section on the main page
# Parameters: _
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainMonthly{
if ($Debug) { debug( "ShowMonthStats", 2 ); }
print "$Center \n";
my $title = "$Message[162]";
&tab_head( "$title", 0, 0, 'month' );
print "\n";
print "\n";
my $average_nb = my $average_u = my $average_v = my $average_p = 0;
my $average_h = my $average_k = 0;
my $total_u = my $total_v = my $total_p = my $total_h = my $total_k = 0;
my $max_v = my $max_p = my $max_h = my $max_k = 1;
# Define total and max
for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
my $monthix = sprintf( "%02s", $ix );
$total_u += $MonthUnique{ $YearRequired . $monthix } || 0;
$total_v += $MonthVisits{ $YearRequired . $monthix } || 0;
$total_p += $MonthPages{ $YearRequired . $monthix } || 0;
$total_h += $MonthHits{ $YearRequired . $monthix } || 0;
$total_k += $MonthBytes{ $YearRequired . $monthix } || 0;
#if (($MonthUnique{$YearRequired.$monthix}||0) > $max_v) { $max_v=$MonthUnique{$YearRequired.$monthix}; }
if (
( $MonthVisits{ $YearRequired . $monthix } || 0 ) > $max_v )
{
$max_v = $MonthVisits{ $YearRequired . $monthix };
}
#if (($MonthPages{$YearRequired.$monthix}||0) > $max_p) { $max_p=$MonthPages{$YearRequired.$monthix}; }
if ( ( $MonthHits{ $YearRequired . $monthix } || 0 ) > $max_h )
{
$max_h = $MonthHits{ $YearRequired . $monthix };
}
if ( ( $MonthBytes{ $YearRequired . $monthix } || 0 ) > $max_k )
{
$max_k = $MonthBytes{ $YearRequired . $monthix };
}
}
# Define average
# TODO
# Show bars for month
my $graphdone=0;
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ();
for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
my $monthix = sprintf( "%02s", $ix );
push @blocklabel,
"$MonthNumLib{$monthix}\n$YearRequired";
}
my @vallabel = (
"$Message[11]", "$Message[10]",
"$Message[56]", "$Message[57]",
"$Message[75]"
);
my @valcolor =
( "$color_u", "$color_v", "$color_p", "$color_h",
"$color_k" );
my @valmax = ( $max_v, $max_v, $max_h, $max_h, $max_k );
my @valtotal =
( $total_u, $total_v, $total_p, $total_h, $total_k );
my @valaverage = ();
#my @valaverage=($average_v,$average_p,$average_h,$average_k);
my @valdata = ();
my $xx = 0;
for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
my $monthix = sprintf( "%02s", $ix );
$valdata[ $xx++ ] = $MonthUnique{ $YearRequired . $monthix }
|| 0;
$valdata[ $xx++ ] = $MonthVisits{ $YearRequired . $monthix }
|| 0;
$valdata[ $xx++ ] = $MonthPages{ $YearRequired . $monthix }
|| 0;
$valdata[ $xx++ ] = $MonthHits{ $YearRequired . $monthix }
|| 0;
$valdata[ $xx++ ] = $MonthBytes{ $YearRequired . $monthix }
|| 0;
}
my $function = "ShowGraph_$pluginname";
&$function(
"$title", "month",
$ShowMonthStats, \@blocklabel,
\@vallabel, \@valcolor,
\@valmax, \@valtotal,
\@valaverage, \@valdata
);
$graphdone=1;
}
if (! $graphdone)
{
print "\n";
print "";
print " \n";
for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
my $monthix = sprintf( "%02s", $ix );
my $bredde_u = 0;
my $bredde_v = 0;
my $bredde_p = 0;
my $bredde_h = 0;
my $bredde_k = 0;
if ( $max_v > 0 ) {
$bredde_u =
int(
( $MonthUnique{ $YearRequired . $monthix } || 0 ) /
$max_v * $BarHeight ) + 1;
}
if ( $max_v > 0 ) {
$bredde_v =
int(
( $MonthVisits{ $YearRequired . $monthix } || 0 ) /
$max_v * $BarHeight ) + 1;
}
if ( $max_h > 0 ) {
$bredde_p =
int(
( $MonthPages{ $YearRequired . $monthix } || 0 ) /
$max_h * $BarHeight ) + 1;
}
if ( $max_h > 0 ) {
$bredde_h =
int( ( $MonthHits{ $YearRequired . $monthix } || 0 ) /
$max_h * $BarHeight ) + 1;
}
if ( $max_k > 0 ) {
$bredde_k =
int(
( $MonthBytes{ $YearRequired . $monthix } || 0 ) /
$max_k * $BarHeight ) + 1;
}
print "";
if ( $ShowMonthStats =~ /U/i ) {
print
" ";
}
if ( $ShowMonthStats =~ /V/i ) {
print
" ";
}
if ( $ShowMonthStats =~ /P/i ) {
print
" ";
}
if ( $ShowMonthStats =~ /H/i ) {
print
" ";
}
if ( $ShowMonthStats =~ /B/i ) {
print
" ";
}
print " \n";
}
print " ";
print " \n";
# Show lib for month
print "";
#if (!$StaticLinks) {
# print "<< ";
#}
#else {
print " ";
# }
for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
my $monthix = sprintf( "%02s", $ix );
# if (!$StaticLinks) {
# print "$MonthNumLib{$monthix} $YearRequired ";
# }
# else {
print ""
. (
!$StaticLinks
&& $monthix == $nowmonth
&& $YearRequired == $nowyear
? ''
: ''
);
print "$MonthNumLib{$monthix} $YearRequired";
print( !$StaticLinks
&& $monthix == $nowmonth
&& $YearRequired == $nowyear ? ' ' : '' );
print " ";
# }
}
# if (!$StaticLinks) {
# print ">> ";
# }
# else {
print " ";
# }
print " \n";
print "
\n";
}
print " \n";
# Show data array for month
if ($AddDataArrayMonthStats) {
print "\n";
print
"$Message[5] ";
if ( $ShowMonthStats =~ /U/i ) {
print "$Message[11] ";
}
if ( $ShowMonthStats =~ /V/i ) {
print "$Message[10] ";
}
if ( $ShowMonthStats =~ /P/i ) {
print "$Message[56] ";
}
if ( $ShowMonthStats =~ /H/i ) {
print "$Message[57] ";
}
if ( $ShowMonthStats =~ /B/i ) {
print "$Message[75] ";
}
print " \n";
for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
my $monthix = sprintf( "%02s", $ix );
print "";
print ""
. (
!$StaticLinks
&& $monthix == $nowmonth
&& $YearRequired == $nowyear
? ''
: ''
);
print "$MonthNumLib{$monthix} $YearRequired";
print( !$StaticLinks
&& $monthix == $nowmonth
&& $YearRequired == $nowyear ? ' ' : '' );
print " ";
if ( $ShowMonthStats =~ /U/i ) {
print "",
Format_Number($MonthUnique{ $YearRequired . $monthix }
? $MonthUnique{ $YearRequired . $monthix }
: "0"), " ";
}
if ( $ShowMonthStats =~ /V/i ) {
print "",
Format_Number($MonthVisits{ $YearRequired . $monthix }
? $MonthVisits{ $YearRequired . $monthix }
: "0"), " ";
}
if ( $ShowMonthStats =~ /P/i ) {
print "",
Format_Number($MonthPages{ $YearRequired . $monthix }
? $MonthPages{ $YearRequired . $monthix }
: "0"), " ";
}
if ( $ShowMonthStats =~ /H/i ) {
print "",
Format_Number($MonthHits{ $YearRequired . $monthix }
? $MonthHits{ $YearRequired . $monthix }
: "0"), " ";
}
if ( $ShowMonthStats =~ /B/i ) {
print "",
Format_Bytes(
int( $MonthBytes{ $YearRequired . $monthix } || 0 )
), " ";
}
print " \n";
}
# Average row
# TODO
# Total row
print
"$Message[102] ";
if ( $ShowMonthStats =~ /U/i ) {
print
"".Format_Number($total_u)." ";
}
if ( $ShowMonthStats =~ /V/i ) {
print
"".Format_Number($total_v)." ";
}
if ( $ShowMonthStats =~ /P/i ) {
print
"".Format_Number($total_p)." ";
}
if ( $ShowMonthStats =~ /H/i ) {
print
"".Format_Number($total_h)." ";
}
if ( $ShowMonthStats =~ /B/i ) {
print ""
. Format_Bytes($total_k) . " ";
}
print " \n";
print "
\n \n";
}
print " \n";
print " \n";
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the Daily section on the main page
# Parameters: $firstdaytocountaverage, $lastdaytocountaverage
# $firstdaytoshowtime, $lastdaytoshowtime
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainDaily{
my $firstdaytocountaverage = shift;
my $lastdaytocountaverage = shift;
my $firstdaytoshowtime = shift;
my $lastdaytoshowtime = shift;
if ($Debug) { debug( "ShowDaysOfMonthStats", 2 ); }
print "$Center \n";
my $title = "$Message[138]";
&tab_head( "$title", 0, 0, 'daysofmonth' );
print "";
print "\n";
print "\n";
my $NewLinkParams = ${QueryString};
$NewLinkParams =~ s/(^|&|&)update(=\w*|$)//i;
$NewLinkParams =~ s/(^|&|&)staticlinks(=\w*|$)//i;
$NewLinkParams =~ s/(^|&|&)year=[^&]*//i;
$NewLinkParams =~ s/(^|&|&)month=[^&]*//i;
$NewLinkParams =~ s/(^|&|&)framename=[^&]*//i;
$NewLinkParams =~ s/(&|&)+/&/i;
$NewLinkParams =~ s/^&//;
$NewLinkParams =~ s/&$//;
if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&"; }
my $NewLinkTarget = '';
if ( $FrameName eq 'mainright' ) {
$NewLinkTarget = " target=\"_parent\"";
}
my $average_v = my $average_p = 0;
my $average_h = my $average_k = 0;
my $total_u = my $total_v = my $total_p = my $total_h = my $total_k = 0;
my $max_v = my $max_h = my $max_k = 0; # Start from 0 because can be lower than 1
foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
{
$daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
my $year = $1;
my $month = $2;
my $day = $3;
if ( !DateIsValid( $day, $month, $year ) ) {
next;
} # If not an existing day, go to next
$total_v += $DayVisits{ $year . $month . $day } || 0;
$total_p += $DayPages{ $year . $month . $day } || 0;
$total_h += $DayHits{ $year . $month . $day } || 0;
$total_k += $DayBytes{ $year . $month . $day } || 0;
if ( ( $DayVisits{ $year . $month . $day } || 0 ) > $max_v ) {
$max_v = $DayVisits{ $year . $month . $day };
}
#if (($DayPages{$year.$month.$day}||0) > $max_p) { $max_p=$DayPages{$year.$month.$day}; }
if ( ( $DayHits{ $year . $month . $day } || 0 ) > $max_h ) {
$max_h = $DayHits{ $year . $month . $day };
}
if ( ( $DayBytes{ $year . $month . $day } || 0 ) > $max_k ) {
$max_k = $DayBytes{ $year . $month . $day };
}
}
$average_v = sprintf( "%.2f", $AverageVisits );
$average_p = sprintf( "%.2f", $AveragePages );
$average_h = sprintf( "%.2f", $AverageHits );
$average_k = sprintf( "%.2f", $AverageBytes );
# Show bars for day
my $graphdone=0;
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ();
foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
{
$daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
my $year = $1;
my $month = $2;
my $day = $3;
if ( !DateIsValid( $day, $month, $year ) ) {
next;
} # If not an existing day, go to next
my $bold =
( $day == $nowday
&& $month == $nowmonth
&& $year == $nowyear ? ':' : '' );
my $weekend =
( DayOfWeek( $day, $month, $year ) =~ /[06]/ ? '!' : '' );
push @blocklabel,
"$day\n$MonthNumLib{$month}$weekend$bold";
}
my @vallabel = (
"$Message[10]", "$Message[56]",
"$Message[57]", "$Message[75]"
);
my @valcolor =
( "$color_v", "$color_p", "$color_h", "$color_k" );
my @valmax = ( $max_v, $max_h, $max_h, $max_k );
my @valtotal = ( $total_v, $total_p, $total_h, $total_k );
my @valaverage =
( $average_v, $average_p, $average_h, $average_k );
my @valdata = ();
my $xx = 0;
foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
{
$daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
my $year = $1;
my $month = $2;
my $day = $3;
if ( !DateIsValid( $day, $month, $year ) ) {
next;
} # If not an existing day, go to next
$valdata[ $xx++ ] = $DayVisits{ $year . $month . $day }
|| 0;
$valdata[ $xx++ ] = $DayPages{ $year . $month . $day } || 0;
$valdata[ $xx++ ] = $DayHits{ $year . $month . $day } || 0;
$valdata[ $xx++ ] = $DayBytes{ $year . $month . $day } || 0;
}
my $function = "ShowGraph_$pluginname";
&$function(
"$title", "daysofmonth",
$ShowDaysOfMonthStats, \@blocklabel,
\@vallabel, \@valcolor,
\@valmax, \@valtotal,
\@valaverage, \@valdata
);
$graphdone=1;
}
# If graph was not printed by a plugin
if (! $graphdone) {
print "\n";
print "\n";
foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
{
$daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
my $year = $1;
my $month = $2;
my $day = $3;
if ( !DateIsValid( $day, $month, $year ) ) {
next;
} # If not an existing day, go to next
my $bredde_v = 0;
my $bredde_p = 0;
my $bredde_h = 0;
my $bredde_k = 0;
if ( $max_v > 0 ) {
$bredde_v =
int( ( $DayVisits{ $year . $month . $day } || 0 ) /
$max_v * $BarHeight ) + 1;
}
if ( $max_h > 0 ) {
$bredde_p =
int( ( $DayPages{ $year . $month . $day } || 0 ) /
$max_h * $BarHeight ) + 1;
}
if ( $max_h > 0 ) {
$bredde_h =
int( ( $DayHits{ $year . $month . $day } || 0 ) /
$max_h * $BarHeight ) + 1;
}
if ( $max_k > 0 ) {
$bredde_k =
int( ( $DayBytes{ $year . $month . $day } || 0 ) /
$max_k * $BarHeight ) + 1;
}
print "";
if ( $ShowDaysOfMonthStats =~ /V/i ) {
print
" ";
}
if ( $ShowDaysOfMonthStats =~ /P/i ) {
print
" ";
}
if ( $ShowDaysOfMonthStats =~ /H/i ) {
print
" ";
}
if ( $ShowDaysOfMonthStats =~ /B/i ) {
print
" ";
}
print " \n";
}
print " ";
# Show average value bars
print "";
my $bredde_v = 0;
my $bredde_p = 0;
my $bredde_h = 0;
my $bredde_k = 0;
if ( $max_v > 0 ) {
$bredde_v = int( $average_v / $max_v * $BarHeight ) + 1;
}
if ( $max_h > 0 ) {
$bredde_p = int( $average_p / $max_h * $BarHeight ) + 1;
}
if ( $max_h > 0 ) {
$bredde_h = int( $average_h / $max_h * $BarHeight ) + 1;
}
if ( $max_k > 0 ) {
$bredde_k = int( $average_k / $max_k * $BarHeight ) + 1;
}
$average_v = sprintf( "%.2f", $average_v );
$average_p = sprintf( "%.2f", $average_p );
$average_h = sprintf( "%.2f", $average_h );
$average_k = sprintf( "%.2f", $average_k );
if ( $ShowDaysOfMonthStats =~ /V/i ) {
print
" ";
}
if ( $ShowDaysOfMonthStats =~ /P/i ) {
print
" ";
}
if ( $ShowDaysOfMonthStats =~ /H/i ) {
print
" ";
}
if ( $ShowDaysOfMonthStats =~ /B/i ) {
print
" ";
}
print " \n";
print " \n";
# Show lib for day
print "";
foreach
my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
{
$daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
my $year = $1;
my $month = $2;
my $day = $3;
if ( !DateIsValid( $day, $month, $year ) ) {
next;
} # If not an existing day, go to next
my $dayofweekcursor = DayOfWeek( $day, $month, $year );
print "";
print(
!$StaticLinks
&& $day == $nowday
&& $month == $nowmonth
&& $year == $nowyear
? ''
: ''
);
print "$day"
. $MonthNumLib{$month}
. " ";
print( !$StaticLinks
&& $day == $nowday
&& $month == $nowmonth
&& $year == $nowyear ? ' ' : '' );
print " \n";
}
print " ";
print "$Message[96] \n";
print " \n";
print "
\n";
}
print " \n";
# Show data array for days
if ($AddDataArrayShowDaysOfMonthStats) {
print "\n";
print
"$Message[4] ";
if ( $ShowDaysOfMonthStats =~ /V/i ) {
print "$Message[10] ";
}
if ( $ShowDaysOfMonthStats =~ /P/i ) {
print "$Message[56] ";
}
if ( $ShowDaysOfMonthStats =~ /H/i ) {
print "$Message[57] ";
}
if ( $ShowDaysOfMonthStats =~ /B/i ) {
print "$Message[75] ";
}
print " ";
foreach
my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
{
$daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
my $year = $1;
my $month = $2;
my $day = $3;
if ( !DateIsValid( $day, $month, $year ) ) {
next;
} # If not an existing day, go to next
my $dayofweekcursor = DayOfWeek( $day, $month, $year );
print "";
print ""
. (
!$StaticLinks
&& $day == $nowday
&& $month == $nowmonth
&& $year == $nowyear
? ''
: ''
);
print Format_Date( "$year$month$day" . "000000", 2 );
print( !$StaticLinks
&& $day == $nowday
&& $month == $nowmonth
&& $year == $nowyear ? ' ' : '' );
print " ";
if ( $ShowDaysOfMonthStats =~ /V/i ) {
print "",
Format_Number($DayVisits{ $year . $month . $day }
? $DayVisits{ $year . $month . $day }
: "0"), " ";
}
if ( $ShowDaysOfMonthStats =~ /P/i ) {
print "",
Format_Number($DayPages{ $year . $month . $day }
? $DayPages{ $year . $month . $day }
: "0"), " ";
}
if ( $ShowDaysOfMonthStats =~ /H/i ) {
print "",
Format_Number($DayHits{ $year . $month . $day }
? $DayHits{ $year . $month . $day }
: "0"), " ";
}
if ( $ShowDaysOfMonthStats =~ /B/i ) {
print "",
Format_Bytes(
int( $DayBytes{ $year . $month . $day } || 0 ) ),
" ";
}
print " \n";
}
# Average row
print
"$Message[96] ";
if ( $ShowDaysOfMonthStats =~ /V/i ) {
print "".Format_Number(int($average_v))." ";
}
if ( $ShowDaysOfMonthStats =~ /P/i ) {
print "".Format_Number(int($average_p))." ";
}
if ( $ShowDaysOfMonthStats =~ /H/i ) {
print "".Format_Number(int($average_h))." ";
}
if ( $ShowDaysOfMonthStats =~ /B/i ) {
print "".Format_Bytes(int($average_k))." ";
}
print " \n";
# Total row
print
"$Message[102] ";
if ( $ShowDaysOfMonthStats =~ /V/i ) {
print "".Format_Number($total_v)." ";
}
if ( $ShowDaysOfMonthStats =~ /P/i ) {
print "".Format_Number($total_p)." ";
}
if ( $ShowDaysOfMonthStats =~ /H/i ) {
print "".Format_Number($total_h)." ";
}
if ( $ShowDaysOfMonthStats =~ /B/i ) {
print "" . Format_Bytes($total_k) . " ";
}
print " \n";
print "
\n ";
}
print " \n";
print " \n";
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the Days of the Week section on the main page
# Parameters: $firstdaytocountaverage, $lastdaytocountaverage
# Input: _
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainDaysofWeek{
my $firstdaytocountaverage = shift;
my $lastdaytocountaverage = shift;
if ($Debug) { debug( "ShowDaysOfWeekStats", 2 ); }
print "$Center \n";
my $title = "$Message[91]";
&tab_head( "$title", 18, 0, 'daysofweek' );
print "";
print "";
print "\n";
my $max_h = my $max_k = 0; # Start from 0 because can be lower than 1
# Get average value for day of week
my @avg_dayofweek_nb = ();
my @avg_dayofweek_p = ();
my @avg_dayofweek_h = ();
my @avg_dayofweek_k = ();
foreach my $daycursor (
$firstdaytocountaverage .. $lastdaytocountaverage )
{
$daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
my $year = $1;
my $month = $2;
my $day = $3;
if ( !DateIsValid( $day, $month, $year ) ) {
next;
} # If not an existing day, go to next
my $dayofweekcursor = DayOfWeek( $day, $month, $year );
$avg_dayofweek_nb[$dayofweekcursor]
++; # Increase number of day used to count for this day of week
$avg_dayofweek_p[$dayofweekcursor] +=
( $DayPages{$daycursor} || 0 );
$avg_dayofweek_h[$dayofweekcursor] +=
( $DayHits{$daycursor} || 0 );
$avg_dayofweek_k[$dayofweekcursor] +=
( $DayBytes{$daycursor} || 0 );
}
for (@DOWIndex) {
if ( $avg_dayofweek_nb[$_] ) {
$avg_dayofweek_p[$_] =
$avg_dayofweek_p[$_] / $avg_dayofweek_nb[$_];
$avg_dayofweek_h[$_] =
$avg_dayofweek_h[$_] / $avg_dayofweek_nb[$_];
$avg_dayofweek_k[$_] =
$avg_dayofweek_k[$_] / $avg_dayofweek_nb[$_];
#if ($avg_dayofweek_p[$_] > $max_p) { $max_p = $avg_dayofweek_p[$_]; }
if ( $avg_dayofweek_h[$_] > $max_h ) {
$max_h = $avg_dayofweek_h[$_];
}
if ( $avg_dayofweek_k[$_] > $max_k ) {
$max_k = $avg_dayofweek_k[$_];
}
}
else {
$avg_dayofweek_p[$_] = "?";
$avg_dayofweek_h[$_] = "?";
$avg_dayofweek_k[$_] = "?";
}
}
# Show bars for days of week
my $graphdone=0;
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ();
for (@DOWIndex) {
push @blocklabel,
( $Message[ $_ + 84 ] . ( $_ =~ /[06]/ ? "!" : "" ) );
}
my @vallabel =
( "$Message[56]", "$Message[57]", "$Message[75]" );
my @valcolor = ( "$color_p", "$color_h", "$color_k" );
my @valmax = ( int($max_h), int($max_h), int($max_k) );
my @valtotal = ( $TotalPages, $TotalHits, $TotalBytes );
# TEMP
my $average_p = my $average_h = my $average_k = 0;
$average_p = sprintf( "%.2f", $AveragePages );
$average_h = sprintf( "%.2f", $AverageHits );
$average_k = (
int($average_k)
? Format_Bytes( sprintf( "%.2f", $AverageBytes ) )
: "0.00"
);
my @valaverage = ( $average_p, $average_h, $average_k );
my @valdata = ();
my $xx = 0;
for (@DOWIndex) {
$valdata[ $xx++ ] = $avg_dayofweek_p[$_] || 0;
$valdata[ $xx++ ] = $avg_dayofweek_h[$_] || 0;
$valdata[ $xx++ ] = $avg_dayofweek_k[$_] || 0;
# Round to be ready to show array
$avg_dayofweek_p[$_] =
sprintf( "%.2f", $avg_dayofweek_p[$_] );
$avg_dayofweek_h[$_] =
sprintf( "%.2f", $avg_dayofweek_h[$_] );
$avg_dayofweek_k[$_] =
sprintf( "%.2f", $avg_dayofweek_k[$_] );
# Remove decimal part that are .0
if ( $avg_dayofweek_p[$_] == int( $avg_dayofweek_p[$_] ) ) {
$avg_dayofweek_p[$_] = int( $avg_dayofweek_p[$_] );
}
if ( $avg_dayofweek_h[$_] == int( $avg_dayofweek_h[$_] ) ) {
$avg_dayofweek_h[$_] = int( $avg_dayofweek_h[$_] );
}
}
my $function = "ShowGraph_$pluginname";
&$function(
"$title", "daysofweek",
$ShowDaysOfWeekStats, \@blocklabel,
\@vallabel, \@valcolor,
\@valmax, \@valtotal,
\@valaverage, \@valdata
);
$graphdone=1;
}
if (! $graphdone)
{
print "\n";
print "\n";
for (@DOWIndex) {
my $bredde_p = 0;
my $bredde_h = 0;
my $bredde_k = 0;
if ( $max_h > 0 ) {
$bredde_p = int(
(
$avg_dayofweek_p[$_] ne '?'
? $avg_dayofweek_p[$_]
: 0
) / $max_h * $BarHeight
) + 1;
}
if ( $max_h > 0 ) {
$bredde_h = int(
(
$avg_dayofweek_h[$_] ne '?'
? $avg_dayofweek_h[$_]
: 0
) / $max_h * $BarHeight
) + 1;
}
if ( $max_k > 0 ) {
$bredde_k = int(
(
$avg_dayofweek_k[$_] ne '?'
? $avg_dayofweek_k[$_]
: 0
) / $max_k * $BarHeight
) + 1;
}
$avg_dayofweek_p[$_] = sprintf(
"%.2f",
(
$avg_dayofweek_p[$_] ne '?'
? $avg_dayofweek_p[$_]
: 0
)
);
$avg_dayofweek_h[$_] = sprintf(
"%.2f",
(
$avg_dayofweek_h[$_] ne '?'
? $avg_dayofweek_h[$_]
: 0
)
);
$avg_dayofweek_k[$_] = sprintf(
"%.2f",
(
$avg_dayofweek_k[$_] ne '?'
? $avg_dayofweek_k[$_]
: 0
)
);
# Remove decimal part that are .0
if ( $avg_dayofweek_p[$_] == int( $avg_dayofweek_p[$_] ) ) {
$avg_dayofweek_p[$_] = int( $avg_dayofweek_p[$_] );
}
if ( $avg_dayofweek_h[$_] == int( $avg_dayofweek_h[$_] ) ) {
$avg_dayofweek_h[$_] = int( $avg_dayofweek_h[$_] );
}
print "";
if ( $ShowDaysOfWeekStats =~ /P/i ) {
print
" ";
}
if ( $ShowDaysOfWeekStats =~ /H/i ) {
print
" ";
}
if ( $ShowDaysOfWeekStats =~ /B/i ) {
print
" ";
}
print " \n";
}
print " \n";
print "\n";
for (@DOWIndex) {
print ""
. (
!$StaticLinks
&& $_ == ( $nowwday - 1 )
&& $MonthRequired == $nowmonth
&& $YearRequired == $nowyear
? ''
: ''
);
print $Message[ $_ + 84 ];
print( !$StaticLinks
&& $_ == ( $nowwday - 1 )
&& $MonthRequired == $nowmonth
&& $YearRequired == $nowyear ? ' ' : '' );
print " ";
}
print " \n
\n";
}
print " \n";
# Show data array for days of week
if ($AddDataArrayShowDaysOfWeekStats) {
print "\n";
print
"$Message[4] ";
if ( $ShowDaysOfWeekStats =~ /P/i ) {
print "$Message[56] ";
}
if ( $ShowDaysOfWeekStats =~ /H/i ) {
print "$Message[57] ";
}
if ( $ShowDaysOfWeekStats =~ /B/i ) {
print "$Message[75] ";
}
for (@DOWIndex) {
print "";
print ""
. (
!$StaticLinks
&& $_ == ( $nowwday - 1 )
&& $MonthRequired == $nowmonth
&& $YearRequired == $nowyear
? ''
: ''
);
print $Message[ $_ + 84 ];
print( !$StaticLinks
&& $_ == ( $nowwday - 1 )
&& $MonthRequired == $nowmonth
&& $YearRequired == $nowyear ? ' ' : '' );
print " ";
if ( $ShowDaysOfWeekStats =~ /P/i ) {
print "", Format_Number(int($avg_dayofweek_p[$_])), " ";
}
if ( $ShowDaysOfWeekStats =~ /H/i ) {
print "", Format_Number(int($avg_dayofweek_h[$_])), " ";
}
if ( $ShowDaysOfWeekStats =~ /B/i ) {
print "", Format_Bytes(int($avg_dayofweek_k[$_])),
" ";
}
print " \n";
}
print "
\n \n";
}
print " ";
print " \n";
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the Downloads chart and table
# Parameters: -
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainDownloads{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if (!$LevelForFileTypesDetection > 0){return;}
if ($Debug) { debug( "ShowDownloadStats", 2 ); }
my $regext = qr/\.(\w{1,6})$/;
print "$Center \n";
my $Totalh = 0;
if ($MaxNbOf{'DownloadsShown'} < 1){$MaxNbOf{'DownloadsShown'} = 10;} # default if undefined
my $title =
"$Message[178] ($Message[77] $MaxNbOf{'DownloadsShown'}) - $Message[80] ";
&tab_head( "$title", 0, 0, 'downloads' );
my $cnt=0;
for my $u (sort {$_downloads{$b}->{'AWSTATS_HITS'} <=> $_downloads{$a}->{'AWSTATS_HITS'}}(keys %_downloads) ){
$Totalh += $_downloads{$u}->{'AWSTATS_HITS'};
$cnt++;
if ($cnt > 4){last;}
}
# Graph the top five in a pie chart
if (scalar keys %_downloads > 1){
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ();
my @valdata = ();
my @valcolor = ($color_p);
my $cnt = 0;
for my $u (sort {$_downloads{$b}->{'AWSTATS_HITS'} <=> $_downloads{$a}->{'AWSTATS_HITS'}}(keys %_downloads) ){
push @valdata, ($_downloads{$u}->{'AWSTATS_HITS'} / $Totalh * 1000 ) / 10;
push @blocklabel, Get_Filename($u);
$cnt++;
if ($cnt > 4) { last; }
}
my $columns = 2;
if ($ShowDownloadsStats =~ /H/i){$columns += length($ShowDownloadsStats)+1;}
else{$columns += length($ShowDownloadsStats);}
print "";
my $function = "ShowGraph_$pluginname";
&$function(
"$Message[80]", "downloads",
0, \@blocklabel,
0, \@valcolor,
0, 0,
0, \@valdata
);
print " ";
}
}
my $total_dls = scalar keys %_downloads;
print "$Message[178]: $total_dls ";
if ( $ShowDownloadsStats =~ /H/i ){print "$Message[57] "
."206 $Message[57] "; }
if ( $ShowDownloadsStats =~ /B/i ){
print "$Message[75] ";
print "$Message[106] ";
}
print " \n";
my $count = 0;
for my $u (sort {$_downloads{$b}->{'AWSTATS_HITS'} <=> $_downloads{$a}->{'AWSTATS_HITS'}}(keys %_downloads) ){
print "";
my $ext = Get_Extension($regext, $u);
if ( !$ext) {
print " ";
}
else {
my $nameicon = $MimeHashLib{$ext}[0] || "notavailable";
my $nametype = $MimeHashFamily{$MimeHashLib{$ext}[0]} || " ";
print " ";
}
print "";
&HTMLShowURLInfo($u);
print " ";
if ( $ShowDownloadsStats =~ /H/i ){
print "".Format_Number($_downloads{$u}->{'AWSTATS_HITS'})." ";
print "".Format_Number($_downloads{$u}->{'AWSTATS_206'})." ";
}
if ( $ShowDownloadsStats =~ /B/i ){
print "".Format_Bytes($_downloads{$u}->{'AWSTATS_SIZE'})." ";
print "".Format_Bytes(($_downloads{$u}->{'AWSTATS_SIZE'}/
($_downloads{$u}->{'AWSTATS_HITS'} + $_downloads{$u}->{'AWSTATS_206'})))." ";
}
print " \n";
$count++;
if ($count >= $MaxNbOf{'DownloadsShown'}){last;}
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the hours chart and table
# Parameters: -
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainHours{
if ($Debug) { debug( "ShowHoursStats", 2 ); }
print "$Center \n";
my $title = "$Message[20]";
if ( $PluginsLoaded{'GetTimeZoneTitle'}{'timezone'} ) {
$title .= " (GMT "
. ( GetTimeZoneTitle_timezone() >= 0 ? "+" : "" )
. int( GetTimeZoneTitle_timezone() ) . ")";
}
&tab_head( "$title", 19, 0, 'hours' );
print "\n";
print "\n";
my $max_h = my $max_k = 1;
for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
#if ($_time_p[$ix]>$max_p) { $max_p=$_time_p[$ix]; }
if ( $_time_h[$ix] > $max_h ) { $max_h = $_time_h[$ix]; }
if ( $_time_k[$ix] > $max_k ) { $max_k = $_time_k[$ix]; }
}
# Show bars for hour
my $graphdone=0;
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ( 0 .. 23 );
my @vallabel =
( "$Message[56]", "$Message[57]", "$Message[75]" );
my @valcolor = ( "$color_p", "$color_h", "$color_k" );
my @valmax = ( int($max_h), int($max_h), int($max_k) );
my @valtotal = ( $TotalPages, $TotalHits, $TotalBytes );
my @valaverage = ( $AveragePages, $AverageHits, $AverageBytes );
my @valdata = ();
my $xx = 0;
for ( 0 .. 23 ) {
$valdata[ $xx++ ] = $_time_p[$_] || 0;
$valdata[ $xx++ ] = $_time_h[$_] || 0;
$valdata[ $xx++ ] = $_time_k[$_] || 0;
}
my $function = "ShowGraph_$pluginname";
&$function(
"$title", "hours",
$ShowHoursStats, \@blocklabel,
\@vallabel, \@valcolor,
\@valmax, \@valtotal,
\@valaverage, \@valdata
);
$graphdone=1;
}
if (! $graphdone)
{
print "\n";
print "\n";
for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
my $bredde_p = 0;
my $bredde_h = 0;
my $bredde_k = 0;
if ( $max_h > 0 ) {
$bredde_p =
int( $BarHeight * $_time_p[$ix] / $max_h ) + 1;
}
if ( $max_h > 0 ) {
$bredde_h =
int( $BarHeight * $_time_h[$ix] / $max_h ) + 1;
}
if ( $max_k > 0 ) {
$bredde_k =
int( $BarHeight * $_time_k[$ix] / $max_k ) + 1;
}
print "";
if ( $ShowHoursStats =~ /P/i ) {
print
" ";
}
if ( $ShowHoursStats =~ /H/i ) {
print
" ";
}
if ( $ShowHoursStats =~ /B/i ) {
print
" ";
}
print " \n";
}
print " \n";
# Show hour lib
print "";
for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
print "$ix \n"
; # width=19 instead of 18 to avoid a MacOS browser bug.
}
print " \n";
# Show clock icon
print "\n";
for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
my $hrs = ( $ix >= 12 ? $ix - 12 : $ix );
my $hre = ( $ix >= 12 ? $ix - 11 : $ix + 1 );
my $apm = ( $ix >= 12 ? "pm" : "am" );
print
" \n";
}
print " \n";
print "
\n";
}
print " \n";
# Show data array for hours
if ($AddDataArrayShowHoursStats) {
print "\n";
print "\n";
print "\n";
print
"$Message[20] ";
if ( $ShowHoursStats =~ /P/i ) {
print "$Message[56] ";
}
if ( $ShowHoursStats =~ /H/i ) {
print "$Message[57] ";
}
if ( $ShowHoursStats =~ /B/i ) {
print "$Message[75] ";
}
print " ";
for ( my $ix = 0 ; $ix <= 11 ; $ix++ ) {
my $monthix = ( $ix < 10 ? "0$ix" : "$ix" );
print "";
print "$monthix ";
if ( $ShowHoursStats =~ /P/i ) {
print "",
Format_Number($_time_p[$monthix] ? $_time_p[$monthix] : "0"),
" ";
}
if ( $ShowHoursStats =~ /H/i ) {
print "",
Format_Number($_time_h[$monthix] ? $_time_h[$monthix] : "0"),
" ";
}
if ( $ShowHoursStats =~ /B/i ) {
print "", Format_Bytes( int( $_time_k[$monthix] ) ),
" ";
}
print " \n";
}
print "
\n";
print " ";
print " ";
print "\n";
print "\n";
print
"$Message[20] ";
if ( $ShowHoursStats =~ /P/i ) {
print "$Message[56] ";
}
if ( $ShowHoursStats =~ /H/i ) {
print "$Message[57] ";
}
if ( $ShowHoursStats =~ /B/i ) {
print "$Message[75] ";
}
print " \n";
for ( my $ix = 12 ; $ix <= 23 ; $ix++ ) {
my $monthix = ( $ix < 10 ? "0$ix" : "$ix" );
print "";
print "$monthix ";
if ( $ShowHoursStats =~ /P/i ) {
print "",
Format_Number($_time_p[$monthix] ? $_time_p[$monthix] : "0"),
" ";
}
if ( $ShowHoursStats =~ /H/i ) {
print "",
Format_Number($_time_h[$monthix] ? $_time_h[$monthix] : "0"),
" ";
}
if ( $ShowHoursStats =~ /B/i ) {
print "", Format_Bytes( int( $_time_k[$monthix] ) ),
" ";
}
print " \n";
}
print "
\n";
print "
\n";
print " \n";
}
print " \n";
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the countries chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainCountries{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($Debug) { debug( "ShowDomainsStats", 2 ); }
print "$Center \n";
my $title =
"$Message[25] ($Message[77] $MaxNbOf{'Domain'}) - $Message[80] ";
&tab_head( "$title", 19, 0, 'countries' );
my $total_u = my $total_v = my $total_p = my $total_h = my $total_k = 0;
my $max_h = 1;
foreach ( values %_domener_h ) {
if ( $_ > $max_h ) { $max_h = $_; }
}
my $max_k = 1;
foreach ( values %_domener_k ) {
if ( $_ > $max_k ) { $max_k = $_; }
}
my $count = 0;
&BuildKeyList(
$MaxNbOf{'Domain'}, $MinHit{'Domain'},
\%_domener_h, \%_domener_p
);
# print the map
if (scalar @keylist > 1){
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ();
my @valdata = ();
my $cnt = 0;
foreach my $key (@keylist) {
push @valdata, int( $_domener_h{$key} );
push @blocklabel, $DomainsHashIDLib{$key};
$cnt++;
if ($cnt > 99) { last; }
}
print "";
my $function = "ShowGraph_$pluginname";
&$function(
"AWStatsCountryMap", "countries_map",
0, \@blocklabel,
0, 0,
0, 0,
0, \@valdata
);
print " ";
}
}
print
" $Message[17] ";
## to add unique visitors and number of visits by calculation of average of the relation with total
## pages and total hits, and total visits and total unique
## by Josep Ruano @ CAPSiDE
if ( $ShowDomainsStats =~ /U/i ) {
print "$Message[11] ";
}
if ( $ShowDomainsStats =~ /V/i ) {
print "$Message[10] ";
}
if ( $ShowDomainsStats =~ /P/i ) {
print "$Message[56] ";
}
if ( $ShowDomainsStats =~ /H/i ) {
print "$Message[57] ";
}
if ( $ShowDomainsStats =~ /B/i ) {
print "$Message[75] ";
}
print " ";
print " \n";
foreach my $key (@keylist) {
my ( $_domener_u, $_domener_v );
my $bredde_p = 0;
my $bredde_h = 0;
my $bredde_k = 0;
my $bredde_u = 0;
my $bredde_v = 0;
if ( $max_h > 0 ) {
$bredde_p =
int( $BarWidth * $_domener_p{$key} / $max_h ) + 1;
} # use max_h to enable to compare pages with hits
if ( $_domener_p{$key} && $bredde_p == 1 ) { $bredde_p = 2; }
if ( $max_h > 0 ) {
$bredde_h =
int( $BarWidth * $_domener_h{$key} / $max_h ) + 1;
}
if ( $_domener_h{$key} && $bredde_h == 1 ) { $bredde_h = 2; }
if ( $max_k > 0 ) {
$bredde_k =
int( $BarWidth * ( $_domener_k{$key} || 0 ) / $max_k ) +
1;
}
if ( $_domener_k{$key} && $bredde_k == 1 ) { $bredde_k = 2; }
my $newkey = lc($key);
if ( $newkey eq 'ip' || !$DomainsHashIDLib{$newkey} ) {
print
"$Message[0] $newkey ";
}
else {
print
"$DomainsHashIDLib{$newkey} $newkey ";
}
## to add unique visitors and number of visits, by Josep Ruano @ CAPSiDE
if ( $ShowDomainsStats =~ /U/i ) {
$_domener_u = (
$_domener_p{$key}
? $_domener_p{$key} / $TotalPages
: 0
);
$_domener_u += ( $_domener_h{$key} / $TotalHits );
$_domener_u =
sprintf( "%.0f", ( $_domener_u * $TotalUnique ) / 2 );
print "".Format_Number($_domener_u)." ("
. sprintf( "%.1f%", 100 * $_domener_u / $TotalUnique )
. ") ";
}
if ( $ShowDomainsStats =~ /V/i ) {
$_domener_v = (
$_domener_p{$key}
? $_domener_p{$key} / $TotalPages
: 0
);
$_domener_v += ( $_domener_h{$key} / $TotalHits );
$_domener_v =
sprintf( "%.0f", ( $_domener_v * $TotalVisits ) / 2 );
print "".Format_Number($_domener_v)." ("
. sprintf( "%.1f%", 100 * $_domener_v / $TotalVisits )
. ") ";
}
if ( $ShowDomainsStats =~ /P/i ) {
print ""
. ( $_domener_p{$key} ? Format_Number($_domener_p{$key}) : ' ' )
. " ";
}
if ( $ShowDomainsStats =~ /H/i ) {
print "".Format_Number($_domener_h{$key})." ";
}
if ( $ShowDomainsStats =~ /B/i ) {
print "" . Format_Bytes( $_domener_k{$key} ) . " ";
}
print "";
if ( $ShowDomainsStats =~ /P/i ) {
print
" \n";
}
if ( $ShowDomainsStats =~ /H/i ) {
print
" \n";
}
if ( $ShowDomainsStats =~ /B/i ) {
print
" ";
}
print " ";
print " \n";
$total_u += $_domener_u;
$total_v += $_domener_v;
$total_p += $_domener_p{$key};
$total_h += $_domener_h{$key};
$total_k += $_domener_k{$key} || 0;
$count++;
}
my $rest_u = $TotalUnique - $total_u;
my $rest_v = $TotalVisits - $total_v;
my $rest_p = $TotalPages - $total_p;
my $rest_h = $TotalHits - $total_h;
my $rest_k = $TotalBytes - $total_k;
if ( $rest_u > 0
|| $rest_v > 0
|| $rest_p > 0
|| $rest_h > 0
|| $rest_k > 0 )
{ # All other domains (known or not)
print
" $Message[2] ";
if ( $ShowDomainsStats =~ /U/i ) { print "$rest_u "; }
if ( $ShowDomainsStats =~ /V/i ) { print "$rest_v "; }
if ( $ShowDomainsStats =~ /P/i ) { print "$rest_p "; }
if ( $ShowDomainsStats =~ /H/i ) { print "$rest_h "; }
if ( $ShowDomainsStats =~ /B/i ) {
print "" . Format_Bytes($rest_k) . " ";
}
print " ";
print " \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the hosts chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainHosts{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($Debug) { debug( "ShowHostsStats", 2 ); }
print "$Center \n";
my $title =
"$Message[81] ($Message[77] $MaxNbOf{'HostsShown'}) - $Message[80] - $Message[9] - $Message[45] ";
&tab_head( "$title", 19, 0, 'visitors' );
&BuildKeyList( $MaxNbOf{'HostsShown'}, $MinHit{'Host'}, \%_host_h,
\%_host_p );
# Graph the top five in a pie chart
if (scalar @keylist > 1){
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ();
my @valdata = ();
my @valcolor = ($color_p);
my $cnt = 0;
foreach my $key (@keylist) {
push @valdata, int( $_host_h{$key} / $TotalHits * 1000 ) / 10;
push @blocklabel, "$key";
$cnt++;
if ($cnt > 4) { last; }
}
print "";
my $function = "ShowGraph_$pluginname";
&$function(
"Hosts", "hosts",
0, \@blocklabel,
0, \@valcolor,
0, 0,
0, \@valdata
);
print " ";
}
}
print "";
print "";
if ( $MonthRequired ne 'all' ) {
print
"$Message[81] : ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1] ".Format_Number($TotalUnique)." $Message[11] ";
}
else {
print "$Message[81] : " . ( scalar keys %_host_h ) . "";
}
&HTMLShowHostInfo('__title__');
if ( $ShowHostsStats =~ /P/i ) {
print "$Message[56] ";
}
if ( $ShowHostsStats =~ /H/i ) {
print "$Message[57] ";
}
if ( $ShowHostsStats =~ /B/i ) {
print "$Message[75] ";
}
if ( $ShowHostsStats =~ /L/i ) {
print "$Message[9] ";
}
print " \n";
my $total_p = my $total_h = my $total_k = 0;
my $count = 0;
foreach my $key (@keylist) {
print "";
print "$key ";
&HTMLShowHostInfo($key);
if ( $ShowHostsStats =~ /P/i ) {
print '' . ( Format_Number($_host_p{$key}) || " " ) . ' ';
}
if ( $ShowHostsStats =~ /H/i ) {
print "".Format_Number($_host_h{$key})." ";
}
if ( $ShowHostsStats =~ /B/i ) {
print '' . Format_Bytes( $_host_k{$key} ) . ' ';
}
if ( $ShowHostsStats =~ /L/i ) {
print ''
. (
$_host_l{$key}
? Format_Date( $_host_l{$key}, 1 )
: '-'
)
. ' ';
}
print " \n";
$total_p += $_host_p{$key};
$total_h += $_host_h{$key};
$total_k += $_host_k{$key} || 0;
$count++;
}
my $rest_p = $TotalPages - $total_p;
my $rest_h = $TotalHits - $total_h;
my $rest_k = $TotalBytes - $total_k;
if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
{ # All other visitors (known or not)
print "";
print
"$Message[2] ";
&HTMLShowHostInfo('');
if ( $ShowHostsStats =~ /P/i ) { print "".Format_Number($rest_p)." "; }
if ( $ShowHostsStats =~ /H/i ) { print "".Format_Number($rest_h)." "; }
if ( $ShowHostsStats =~ /B/i ) {
print "" . Format_Bytes($rest_k) . " ";
}
if ( $ShowHostsStats =~ /L/i ) { print " "; }
print " \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the logins chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainLogins{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($Debug) { debug( "ShowAuthenticatedUsers", 2 ); }
print "$Center \n";
my $title =
"$Message[94] ($Message[77] $MaxNbOf{'LoginShown'}) - $Message[80] ";
if ( $ShowAuthenticatedUsers =~ /L/i ) {
$title .= " - $Message[9] ";
}
&tab_head( "$title", 19, 0, 'logins' );
print "$Message[94] : "
. Format_Number(( scalar keys %_login_h )) . " ";
&HTMLShowUserInfo('__title__');
if ( $ShowAuthenticatedUsers =~ /P/i ) {
print "$Message[56] ";
}
if ( $ShowAuthenticatedUsers =~ /H/i ) {
print "$Message[57] ";
}
if ( $ShowAuthenticatedUsers =~ /B/i ) {
print "$Message[75] ";
}
if ( $ShowAuthenticatedUsers =~ /L/i ) {
print "$Message[9] ";
}
print " \n";
my $total_p = my $total_h = my $total_k = 0;
my $max_h = 1;
foreach ( values %_login_h ) {
if ( $_ > $max_h ) { $max_h = $_; }
}
my $max_k = 1;
foreach ( values %_login_k ) {
if ( $_ > $max_k ) { $max_k = $_; }
}
my $count = 0;
&BuildKeyList( $MaxNbOf{'LoginShown'}, $MinHit{'Login'}, \%_login_h,
\%_login_p );
foreach my $key (@keylist) {
my $bredde_p = 0;
my $bredde_h = 0;
my $bredde_k = 0;
if ( $max_h > 0 ) {
$bredde_p = int( $BarWidth * $_login_p{$key} / $max_h ) + 1;
} # use max_h to enable to compare pages with hits
if ( $max_h > 0 ) {
$bredde_h = int( $BarWidth * $_login_h{$key} / $max_h ) + 1;
}
if ( $max_k > 0 ) {
$bredde_k = int( $BarWidth * $_login_k{$key} / $max_k ) + 1;
}
print "$key ";
&HTMLShowUserInfo($key);
if ( $ShowAuthenticatedUsers =~ /P/i ) {
print ""
. ( $_login_p{$key} ? Format_Number($_login_p{$key}) : " " )
. " ";
}
if ( $ShowAuthenticatedUsers =~ /H/i ) {
print "".Format_Number($_login_h{$key})." ";
}
if ( $ShowAuthenticatedUsers =~ /B/i ) {
print "" . Format_Bytes( $_login_k{$key} ) . " ";
}
if ( $ShowAuthenticatedUsers =~ /L/i ) {
print ""
. (
$_login_l{$key}
? Format_Date( $_login_l{$key}, 1 )
: '-'
)
. " ";
}
print " \n";
$total_p += $_login_p{$key};
$total_h += $_login_h{$key};
$total_k += $_login_k{$key};
$count++;
}
my $rest_p = $TotalPages - $total_p;
my $rest_h = $TotalHits - $total_h;
my $rest_k = $TotalBytes - $total_k;
if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
{ # All other logins
print
""
. ( $PageDir eq 'rtl' ? "" : "" )
. "$Message[125]"
. ( $PageDir eq 'rtl' ? " " : "" )
. " ";
&HTMLShowUserInfo('');
if ( $ShowAuthenticatedUsers =~ /P/i ) {
print "" . ( $rest_p ? Format_Number($rest_p) : " " ) . " ";
}
if ( $ShowAuthenticatedUsers =~ /H/i ) {
print "".Format_Number($rest_h)." ";
}
if ( $ShowAuthenticatedUsers =~ /B/i ) {
print "" . Format_Bytes($rest_k) . " ";
}
if ( $ShowAuthenticatedUsers =~ /L/i ) {
print " ";
}
print " \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the robots chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainRobots{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($Debug) { debug( "ShowRobotStats", 2 ); }
print "$Center \n";
&tab_head(
"$Message[53] ($Message[77] $MaxNbOf{'RobotShown'}) - $Message[80] - $Message[9] ",
19, 0, 'robots'
);
print ""
. Format_Number(( scalar keys %_robot_h ))
. " $Message[51]* ";
if ( $ShowRobotsStats =~ /H/i ) {
print
"$Message[57] ";
}
if ( $ShowRobotsStats =~ /B/i ) {
print
"$Message[75] ";
}
if ( $ShowRobotsStats =~ /L/i ) {
print "$Message[9] ";
}
print " \n";
my $total_p = my $total_h = my $total_k = my $total_r = 0;
my $count = 0;
&BuildKeyList( $MaxNbOf{'RobotShown'}, $MinHit{'Robot'}, \%_robot_h,
\%_robot_h );
foreach my $key (@keylist) {
print ""
. ( $PageDir eq 'rtl' ? "" : "" )
. ( $RobotsHashIDLib{$key} ? $RobotsHashIDLib{$key} : $key )
. ( $PageDir eq 'rtl' ? " " : "" ) . " ";
if ( $ShowRobotsStats =~ /H/i ) {
print ""
. Format_Number(( $_robot_h{$key} - $_robot_r{$key} ))
. ( $_robot_r{$key} ? "+$_robot_r{$key}" : "" ) . " ";
}
if ( $ShowRobotsStats =~ /B/i ) {
print "" . Format_Bytes( $_robot_k{$key} ) . " ";
}
if ( $ShowRobotsStats =~ /L/i ) {
print ""
. (
$_robot_l{$key}
? Format_Date( $_robot_l{$key}, 1 )
: '-'
)
. " ";
}
print " \n";
#$total_p += $_robot_p{$key};
$total_h += $_robot_h{$key};
$total_k += $_robot_k{$key} || 0;
$total_r += $_robot_r{$key} || 0;
$count++;
}
# For bots we need to count Totals
my $TotalPagesRobots =
0; #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
my $TotalHitsRobots = 0;
foreach ( values %_robot_h ) { $TotalHitsRobots += $_; }
my $TotalBytesRobots = 0;
foreach ( values %_robot_k ) { $TotalBytesRobots += $_; }
my $TotalRRobots = 0;
foreach ( values %_robot_r ) { $TotalRRobots += $_; }
my $rest_p = 0; #$rest_p=$TotalPagesRobots-$total_p;
my $rest_h = $TotalHitsRobots - $total_h;
my $rest_k = $TotalBytesRobots - $total_k;
my $rest_r = $TotalRRobots - $total_r;
if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0 )
{ # All other robots
print
"$Message[2] ";
if ( $ShowRobotsStats =~ /H/i ) {
print ""
. Format_Number(( $rest_h - $rest_r ))
. ( $rest_r ? "+$rest_r" : "" ) . " ";
}
if ( $ShowRobotsStats =~ /B/i ) {
print "" . ( Format_Bytes($rest_k) ) . " ";
}
if ( $ShowRobotsStats =~ /L/i ) { print " "; }
print " \n";
}
&tab_end(
"* $Message[156]" . ( $TotalRRobots ? " $Message[157]" : "" ) );
}
#------------------------------------------------------------------------------
# Function: Prints the worms chart and table
# Parameters: -
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainWorms{
if ($Debug) { debug( "ShowWormsStats", 2 ); }
print "$Center \n";
&tab_head( "$Message[163] ($Message[77] $MaxNbOf{'WormsShown'})",
19, 0, 'worms' );
print "";
print "" . Format_Number(( scalar keys %_worm_h )) . " $Message[164]* ";
print "$Message[167] ";
if ( $ShowWormsStats =~ /H/i ) {
print
"$Message[57] ";
}
if ( $ShowWormsStats =~ /B/i ) {
print
"$Message[75] ";
}
if ( $ShowWormsStats =~ /L/i ) {
print "$Message[9] ";
}
print " \n";
my $total_p = my $total_h = my $total_k = 0;
my $count = 0;
&BuildKeyList( $MaxNbOf{'WormsShown'}, $MinHit{'Worm'}, \%_worm_h,
\%_worm_h );
foreach my $key (@keylist) {
print "";
print ""
. ( $PageDir eq 'rtl' ? "" : "" )
. ( $WormsHashLib{$key} ? $WormsHashLib{$key} : $key )
. ( $PageDir eq 'rtl' ? " " : "" ) . " ";
print ""
. ( $PageDir eq 'rtl' ? "" : "" )
. ( $WormsHashTarget{$key} ? $WormsHashTarget{$key} : $key )
. ( $PageDir eq 'rtl' ? " " : "" ) . " ";
if ( $ShowWormsStats =~ /H/i ) {
print "" . Format_Number($_worm_h{$key}) . " ";
}
if ( $ShowWormsStats =~ /B/i ) {
print "" . Format_Bytes( $_worm_k{$key} ) . " ";
}
if ( $ShowWormsStats =~ /L/i ) {
print ""
. (
$_worm_l{$key}
? Format_Date( $_worm_l{$key}, 1 )
: '-'
)
. " ";
}
print " \n";
#$total_p += $_worm_p{$key};
$total_h += $_worm_h{$key};
$total_k += $_worm_k{$key} || 0;
$count++;
}
# For worms we need to count Totals
my $TotalPagesWorms =
0; #foreach (values %_worm_p) { $TotalPagesWorms+=$_; }
my $TotalHitsWorms = 0;
foreach ( values %_worm_h ) { $TotalHitsWorms += $_; }
my $TotalBytesWorms = 0;
foreach ( values %_worm_k ) { $TotalBytesWorms += $_; }
my $rest_p = 0; #$rest_p=$TotalPagesRobots-$total_p;
my $rest_h = $TotalHitsWorms - $total_h;
my $rest_k = $TotalBytesWorms - $total_k;
if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 ) { # All other worms
print "";
print
"$Message[2] ";
print "- ";
if ( $ShowWormsStats =~ /H/i ) {
print "" . Format_Number(($rest_h)) . " ";
}
if ( $ShowWormsStats =~ /B/i ) {
print "" . ( Format_Bytes($rest_k) ) . " ";
}
if ( $ShowWormsStats =~ /L/i ) { print " "; }
print " \n";
}
&tab_end("* $Message[158]");
}
#------------------------------------------------------------------------------
# Function: Prints the sessions chart and table
# Parameters: -
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainSessions{
if ($Debug) { debug( "ShowSessionsStats", 2 ); }
print "$Center \n";
my $title = "$Message[117]";
&tab_head( $title, 19, 0, 'sessions' );
my $Totals = 0;
my $average_s = 0;
foreach (@SessionsRange) {
$average_s += ( $_session{$_} || 0 ) * $SessionsAverage{$_};
$Totals += $_session{$_} || 0;
}
if ($Totals) { $average_s = int( $average_s / $Totals ); }
else { $average_s = '?'; }
print "$Message[10]: ".Format_Number($TotalVisits)." - $Message[96]: ".Format_Number($average_s)." s $Message[10] $Message[15] \n";
$average_s = 0;
my $total_s = 0;
my $count = 0;
foreach my $key (@SessionsRange) {
my $p = 0;
if ($TotalVisits) {
$p = int( $_session{$key} / $TotalVisits * 1000 ) / 10;
}
$total_s += $_session{$key} || 0;
print "$key ";
print ""
. ( $_session{$key} ? Format_Number($_session{$key}) : " " ) . " ";
print ""
. ( $_session{$key} ? "$p %" : " " ) . " ";
print " \n";
$count++;
}
my $rest_s = $TotalVisits - $total_s;
if ( $rest_s > 0 ) { # All others sessions
my $p = 0;
if ($TotalVisits) {
$p = int( $rest_s / $TotalVisits * 1000 ) / 10;
}
print "$Message[0] ";
print "".Format_Number($rest_s)." ";
print "" . ( $rest_s ? "$p %" : " " ) . " ";
print " \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the pages chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainPages{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($Debug) {
debug(
"ShowPagesStats (MaxNbOf{'PageShown'}=$MaxNbOf{'PageShown'} TotalDifferentPages=$TotalDifferentPages)",
2
);
}
my $regext = qr/\.(\w{1,6})$/;
print
"$Center \n";
my $title =
"$Message[19] ($Message[77] $MaxNbOf{'PageShown'}) - $Message[80] ";
if ( $ShowPagesStats =~ /E/i ) {
$title .= " - $Message[104] ";
}
if ( $ShowPagesStats =~ /X/i ) {
$title .= " - $Message[116] ";
}
&tab_head( "$title", 19, 0, 'urls' );
print
"".Format_Number($TotalDifferentPages)." $Message[28] ";
if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
print
"$Message[29] ";
}
if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
print
"$Message[57] ";
}
if ( $ShowPagesStats =~ /B/i ) {
print
"$Message[106] ";
}
if ( $ShowPagesStats =~ /E/i ) {
print
"$Message[104] ";
}
if ( $ShowPagesStats =~ /X/i ) {
print
"$Message[116] ";
}
# Call to plugins' function ShowPagesAddField
foreach
my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
{
# my $function="ShowPagesAddField_$pluginname('title')";
# eval("$function");
my $function = "ShowPagesAddField_$pluginname";
&$function('title');
}
print " \n";
my $total_p = my $total_e = my $total_x = my $total_k = 0;
my $max_p = 1;
my $max_k = 1;
my $count = 0;
&BuildKeyList( $MaxNbOf{'PageShown'}, $MinHit{'File'}, \%_url_p,
\%_url_p );
foreach my $key (@keylist) {
if ( $_url_p{$key} > $max_p ) { $max_p = $_url_p{$key}; }
if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
$max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
}
}
foreach my $key (@keylist) {
print "";
&HTMLShowURLInfo($key);
print " ";
my $bredde_p = 0;
my $bredde_e = 0;
my $bredde_x = 0;
my $bredde_k = 0;
if ( $max_p > 0 ) {
$bredde_p =
int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
}
if ( ( $bredde_p == 1 ) && $_url_p{$key} ) { $bredde_p = 2; }
if ( $max_p > 0 ) {
$bredde_e =
int( $BarWidth * ( $_url_e{$key} || 0 ) / $max_p ) + 1;
}
if ( ( $bredde_e == 1 ) && $_url_e{$key} ) { $bredde_e = 2; }
if ( $max_p > 0 ) {
$bredde_x =
int( $BarWidth * ( $_url_x{$key} || 0 ) / $max_p ) + 1;
}
if ( ( $bredde_x == 1 ) && $_url_x{$key} ) { $bredde_x = 2; }
if ( $max_k > 0 ) {
$bredde_k =
int( $BarWidth *
( ( $_url_k{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
$max_k ) + 1;
}
if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
print "".Format_Number($_url_p{$key})." ";
}
if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
print "".Format_Number($_url_p{$key})." ";
}
if ( $ShowPagesStats =~ /B/i ) {
print ""
. (
$_url_k{$key}
? Format_Bytes(
$_url_k{$key} / ( $_url_p{$key} || 1 )
)
: " "
)
. " ";
}
if ( $ShowPagesStats =~ /E/i ) {
print ""
. ( $_url_e{$key} ? Format_Number($_url_e{$key}) : " " ) . " ";
}
if ( $ShowPagesStats =~ /X/i ) {
print ""
. ( $_url_x{$key} ? Format_Number($_url_x{$key}) : " " ) . " ";
}
# Call to plugins' function ShowPagesAddField
foreach my $pluginname (
keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
{
# my $function="ShowPagesAddField_$pluginname('$key')";
# eval("$function");
my $function = "ShowPagesAddField_$pluginname";
&$function($key);
}
print "";
if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
print
" ";
}
if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
print
" ";
}
if ( $ShowPagesStats =~ /B/i ) {
print
" ";
}
if ( $ShowPagesStats =~ /E/i ) {
print
" ";
}
if ( $ShowPagesStats =~ /X/i ) {
print
" ";
}
print " \n";
$total_p += $_url_p{$key} || 0;
$total_e += $_url_e{$key} || 0;
$total_x += $_url_x{$key} || 0;
$total_k += $_url_k{$key} || 0;
$count++;
}
my $rest_p = $TotalPages - $total_p;
my $rest_e = $TotalEntries - $total_e;
my $rest_x = $TotalExits - $total_x;
my $rest_k = $TotalBytesPages - $total_k;
if ( $rest_p > 0 || $rest_k > 0 || $rest_e > 0 || $rest_x > 0 )
{ # All other urls
print
"$Message[2] ";
if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
print "".Format_Number($rest_p)." ";
}
if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
print "".Format_Number($rest_p)." ";
}
if ( $ShowPagesStats =~ /B/i ) {
print ""
. (
$rest_k
? Format_Bytes( $rest_k / ( $rest_p || 1 ) )
: " "
)
. " ";
}
if ( $ShowPagesStats =~ /E/i ) {
print "" . ( $rest_e ? Format_Number($rest_e) : " " ) . " ";
}
if ( $ShowPagesStats =~ /X/i ) {
print "" . ( $rest_x ? Format_Number($rest_x) : " " ) . " ";
}
# Call to plugins' function ShowPagesAddField
foreach my $pluginname (
keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
{
# my $function="ShowPagesAddField_$pluginname('')";
# eval("$function");
my $function = "ShowPagesAddField_$pluginname";
&$function('');
}
print " \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the OS chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainOS{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($Debug) { debug( "ShowOSStats", 2 ); }
print "$Center \n";
my $Totalh = 0;
my %new_os_h = ();
OSLOOP: foreach my $key ( keys %_os_h ) {
$Totalh += $_os_h{$key};
foreach my $family ( keys %OSFamily ) {
if ( $key =~ /^$family/i ) {
$new_os_h{"${family}cumul"} += $_os_h{$key};
next OSLOOP;
}
}
$new_os_h{$key} += $_os_h{$key};
}
my $title =
"$Message[59] ($Message[77] $MaxNbOf{'OsShown'}) - $Message[80]/$Message[58] - $Message[0] ";
&tab_head( "$title", 19, 0, 'os' );
&BuildKeyList( $MaxNbOf{'OsShown'}, $MinHit{'Os'}, \%new_os_h,
\%new_os_h );
# Graph the top five in a pie chart
if (scalar @keylist > 1){
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ();
my @valdata = ();
my @valcolor = ($color_p);
my $cnt = 0;
foreach my $key (@keylist) {
push @valdata, int( $new_os_h{$key} / $Totalh * 1000 ) / 10;
if ($key eq 'Unknown'){push @blocklabel, "$key"; }
else{
my $keywithoutcumul = $key;
$keywithoutcumul =~ s/cumul$//i;
my $libos = $OSHashLib{$keywithoutcumul}
|| $keywithoutcumul;
my $nameicon = $keywithoutcumul;
$nameicon =~ s/[^\w]//g;
if ( $OSFamily{$keywithoutcumul} ) {
$libos = $OSFamily{$keywithoutcumul};
}
push @blocklabel, "$libos";
}
$cnt++;
if ($cnt > 4) { last; }
}
print "";
my $function = "ShowGraph_$pluginname";
&$function(
"Top 5 Operating Systems", "oss",
0, \@blocklabel,
0, \@valcolor,
0, 0,
0, \@valdata
);
print " ";
}
}
print
" $Message[59] $Message[57] $Message[15] \n";
my $total_h = 0;
my $count = 0;
foreach my $key (@keylist) {
my $p = ' ';
if ($Totalh) {
$p = int( $new_os_h{$key} / $Totalh * 1000 ) / 10;
$p = "$p %";
}
if ( $key eq 'Unknown' ) {
print "$Message[0] ".Format_Number($_os_h{$key})." $p \n";
}
else {
my $keywithoutcumul = $key;
$keywithoutcumul =~ s/cumul$//i;
my $libos = $OSHashLib{$keywithoutcumul}
|| $keywithoutcumul;
my $nameicon = $keywithoutcumul;
$nameicon =~ s/[^\w]//g;
if ( $OSFamily{$keywithoutcumul} ) {
$libos = "" . $OSFamily{$keywithoutcumul} . " ";
}
print "$libos ".Format_Number($new_os_h{$key})." $p \n";
}
$total_h += $new_os_h{$key};
$count++;
}
if ($Debug) {
debug( "Total real / shown : $Totalh / $total_h", 2 );
}
my $rest_h = $Totalh - $total_h;
if ( $rest_h > 0 ) {
my $p;
if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
print "";
print " ";
print
"$Message[2] ".Format_Number($rest_h)." ";
print "$p % \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the Browsers chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainBrowsers{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($Debug) { debug( "ShowBrowsersStats", 2 ); }
print "$Center \n";
my $Totalh = 0;
my %new_browser_h = ();
BROWSERLOOP: foreach my $key ( keys %_browser_h ) {
$Totalh += $_browser_h{$key};
foreach my $family ( keys %BrowsersFamily ) {
if ( $key =~ /^$family/i ) {
$new_browser_h{"${family}cumul"} += $_browser_h{$key};
next BROWSERLOOP;
}
}
$new_browser_h{$key} += $_browser_h{$key};
}
my $title =
"$Message[21] ($Message[77] $MaxNbOf{'BrowsersShown'}) - $Message[80]/$Message[58] - $Message[0] ";
&tab_head( "$title", 19, 0, 'browsers' );
&BuildKeyList(
$MaxNbOf{'BrowsersShown'}, $MinHit{'Browser'},
\%new_browser_h, \%new_browser_h
);
# Graph the top five in a pie chart
if (scalar @keylist > 1){
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ();
my @valdata = ();
my @valcolor = ($color_p);
my $cnt = 0;
foreach my $key (@keylist) {
push @valdata, int( $new_browser_h{$key} / $TotalHits * 1000 ) / 10;
if ($key eq 'Unknown'){push @blocklabel, "$key"; }
else{
my $keywithoutcumul = $key;
$keywithoutcumul =~ s/cumul$//i;
my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
|| $keywithoutcumul;
my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
|| "notavailable";
if ( $BrowsersFamily{$keywithoutcumul} ) {
$libbrowser = "$libbrowser";
}
push @blocklabel, "$libbrowser";
}
$cnt++;
if ($cnt > 4) { last; }
}
print "";
my $function = "ShowGraph_$pluginname";
&$function(
"Top 5 Browsers", "browsers",
0, \@blocklabel,
0, \@valcolor,
0, 0,
0, \@valdata
);
print " ";
}
}
print
" $Message[21] $Message[111] $Message[57] $Message[15] \n";
my $total_h = 0;
my $count = 0;
foreach my $key (@keylist) {
my $p = ' ';
if ($Totalh) {
$p = int( $new_browser_h{$key} / $Totalh * 1000 ) / 10;
$p = "$p %";
}
if ( $key eq 'Unknown' ) {
print "$Message[0] ? ".Format_Number($_browser_h{$key})." $p \n";
}
else {
my $keywithoutcumul = $key;
$keywithoutcumul =~ s/cumul$//i;
my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
|| $keywithoutcumul;
my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
|| "notavailable";
if ( $BrowsersFamily{$keywithoutcumul} ) {
$libbrowser = "$libbrowser ";
}
print ""
. ( $PageDir eq 'rtl' ? "" : "" )
. "$libbrowser"
. ( $PageDir eq 'rtl' ? " " : "" )
. " "
. (
$BrowsersHereAreGrabbers{$key}
? "$Message[112] "
: "$Message[113]"
)
. " ".Format_Number($new_browser_h{$key})." $p \n";
}
$total_h += $new_browser_h{$key};
$count++;
}
if ($Debug) {
debug( "Total real / shown : $Totalh / $total_h", 2 );
}
my $rest_h = $Totalh - $total_h;
if ( $rest_h > 0 ) {
my $p;
if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
print "";
print " ";
print
"$Message[2] $rest_h ";
print "$p % \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the ScreenSize chart and table
# Parameters: -
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainScreenSize{
if ($Debug) { debug( "ShowScreenSizeStats", 2 ); }
print "$Center \n";
my $Totalh = 0;
foreach ( keys %_screensize_h ) { $Totalh += $_screensize_h{$_}; }
my $title =
"$Message[135] ($Message[77] $MaxNbOf{'ScreenSizesShown'})";
&tab_head( "$title", 0, 0, 'screensizes' );
print
"$Message[135] $Message[15] \n";
my $total_h = 0;
my $count = 0;
&BuildKeyList( $MaxNbOf{'ScreenSizesShown'},
$MinHit{'ScreenSize'}, \%_screensize_h, \%_screensize_h );
foreach my $key (@keylist) {
my $p = ' ';
if ($Totalh) {
$p = int( $_screensize_h{$key} / $Totalh * 1000 ) / 10;
$p = "$p %";
}
$total_h += $_screensize_h{$key} || 0;
print "";
if ( $key eq 'Unknown' ) {
print
"$Message[0] ";
print "$p ";
}
else {
my $screensize = $key;
print "$screensize ";
print "$p ";
}
print " \n";
$count++;
}
my $rest_h = $Totalh - $total_h;
if ( $rest_h > 0 ) { # All others sessions
my $p = 0;
if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
print
"$Message[2] ";
print "" . ( $rest_h ? "$p %" : " " ) . " ";
print " \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the Referrers chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainReferrers{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($Debug) { debug( "ShowOriginStats", 2 ); }
print "$Center \n";
my $Totalp = 0;
foreach ( 0 .. 5 ) {
$Totalp +=
( $_ != 4 || $IncludeInternalLinksInOriginSection )
? $_from_p[$_]
: 0;
}
my $Totalh = 0;
foreach ( 0 .. 5 ) {
$Totalh +=
( $_ != 4 || $IncludeInternalLinksInOriginSection )
? $_from_h[$_]
: 0;
}
&tab_head( $Message[36], 19, 0, 'referer' );
my @p_p = ( 0, 0, 0, 0, 0, 0 );
if ( $Totalp > 0 ) {
$p_p[0] = int( $_from_p[0] / $Totalp * 1000 ) / 10;
$p_p[1] = int( $_from_p[1] / $Totalp * 1000 ) / 10;
$p_p[2] = int( $_from_p[2] / $Totalp * 1000 ) / 10;
$p_p[3] = int( $_from_p[3] / $Totalp * 1000 ) / 10;
$p_p[4] = int( $_from_p[4] / $Totalp * 1000 ) / 10;
$p_p[5] = int( $_from_p[5] / $Totalp * 1000 ) / 10;
}
my @p_h = ( 0, 0, 0, 0, 0, 0 );
if ( $Totalh > 0 ) {
$p_h[0] = int( $_from_h[0] / $Totalh * 1000 ) / 10;
$p_h[1] = int( $_from_h[1] / $Totalh * 1000 ) / 10;
$p_h[2] = int( $_from_h[2] / $Totalh * 1000 ) / 10;
$p_h[3] = int( $_from_h[3] / $Totalh * 1000 ) / 10;
$p_h[4] = int( $_from_h[4] / $Totalh * 1000 ) / 10;
$p_h[5] = int( $_from_h[5] / $Totalh * 1000 ) / 10;
}
print
"$Message[37] ";
if ( $ShowOriginStats =~ /P/i ) {
print
"$Message[56] $Message[15] ";
}
if ( $ShowOriginStats =~ /H/i ) {
print
"$Message[57] $Message[15] ";
}
print " \n";
#------- Referrals by direct address/bookmark/link in email/etc...
print "$Message[38] ";
if ( $ShowOriginStats =~ /P/i ) {
print ""
. ( $_from_p[0] ? Format_Number($_from_p[0]) : " " )
. " "
. ( $_from_p[0] ? "$p_p[0] %" : " " ) . " ";
}
if ( $ShowOriginStats =~ /H/i ) {
print ""
. ( $_from_h[0] ? Format_Number($_from_h[0]) : " " )
. " "
. ( $_from_h[0] ? "$p_h[0] %" : " " ) . " ";
}
print " \n";
#------- Referrals by search engines
print "$Message[40] - $Message[80] \n";
if ( scalar keys %_se_referrals_h ) {
print "\n";
my $total_p = 0;
my $total_h = 0;
my $count = 0;
&BuildKeyList(
$MaxNbOf{'RefererShown'},
$MinHit{'Refer'},
\%_se_referrals_h,
(
( scalar keys %_se_referrals_p )
? \%_se_referrals_p
: \%_se_referrals_h
)
);
foreach my $key (@keylist) {
my $newreferer = $SearchEnginesHashLib{$key}
|| CleanXSS($key);
print "- $newreferer ";
print ""
. (
Format_Number($_se_referrals_p{$key} ? $_se_referrals_p{$key} : '0' ))
. " ";
print " / ".Format_Number($_se_referrals_h{$key})." ";
print " \n";
$total_p += $_se_referrals_p{$key};
$total_h += $_se_referrals_h{$key};
$count++;
}
if ($Debug) {
debug(
"Total real / shown : $TotalSearchEnginesPages / $total_p - $TotalSearchEnginesHits / $total_h",
2
);
}
my $rest_p = $TotalSearchEnginesPages - $total_p;
my $rest_h = $TotalSearchEnginesHits - $total_h;
if ( $rest_p > 0 || $rest_h > 0 ) {
print
"- $Message[2] ";
print "".Format_Number($rest_p)." ";
print " / ".Format_Number($rest_h)." ";
print " \n";
}
print "
";
}
print " \n";
if ( $ShowOriginStats =~ /P/i ) {
print ""
. ( $_from_p[2] ? Format_Number($_from_p[2]) : " " )
. " "
. ( $_from_p[2] ? "$p_p[2] %" : " " ) . " ";
}
if ( $ShowOriginStats =~ /H/i ) {
print ""
. ( $_from_h[2] ? Format_Number($_from_h[2]) : " " )
. " "
. ( $_from_h[2] ? "$p_h[2] %" : " " ) . " ";
}
print " \n";
#------- Referrals by external HTML link
print "$Message[41] - $Message[80] \n";
if ( scalar keys %_pagesrefs_h ) {
print "\n";
my $total_p = 0;
my $total_h = 0;
my $count = 0;
&BuildKeyList(
$MaxNbOf{'RefererShown'},
$MinHit{'Refer'},
\%_pagesrefs_h,
(
( scalar keys %_pagesrefs_p )
? \%_pagesrefs_p
: \%_pagesrefs_h
)
);
foreach my $key (@keylist) {
print "- ";
&HTMLShowURLInfo($key);
print " ";
print ""
. Format_Number(( $_pagesrefs_p{$key} ? $_pagesrefs_p{$key} : '0' ))
. " ";
print "".Format_Number($_pagesrefs_h{$key})." ";
print " \n";
$total_p += $_pagesrefs_p{$key};
$total_h += $_pagesrefs_h{$key};
$count++;
}
if ($Debug) {
debug(
"Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",
2
);
}
my $rest_p = $TotalRefererPages - $total_p;
my $rest_h = $TotalRefererHits - $total_h;
if ( $rest_p > 0 || $rest_h > 0 ) {
print
"- $Message[2] ";
print "".Format_Number($rest_p)." ";
print "".Format_Number($rest_h)." ";
print " \n";
}
print "
";
}
print " \n";
if ( $ShowOriginStats =~ /P/i ) {
print ""
. ( $_from_p[3] ? Format_Number($_from_p[3]) : " " )
. " "
. ( $_from_p[3] ? "$p_p[3] %" : " " ) . " ";
}
if ( $ShowOriginStats =~ /H/i ) {
print ""
. ( $_from_h[3] ? Format_Number($_from_h[3]) : " " )
. " "
. ( $_from_h[3] ? "$p_h[3] %" : " " ) . " ";
}
print " \n";
#------- Referrals by internal HTML link
if ($IncludeInternalLinksInOriginSection) {
print "$Message[42] ";
if ( $ShowOriginStats =~ /P/i ) {
print ""
. ( $_from_p[4] ? Format_Number($_from_p[4]) : " " )
. " "
. ( $_from_p[4] ? "$p_p[4] %" : " " ) . " ";
}
if ( $ShowOriginStats =~ /H/i ) {
print ""
. ( $_from_h[4] ? Format_Number($_from_h[4]) : " " )
. " "
. ( $_from_h[4] ? "$p_h[4] %" : " " ) . " ";
}
print " \n";
}
#------- Referrals by news group
#print "$Message[107] ";
#if ($ShowOriginStats =~ /P/i) { print "".($_from_p[5]?$_from_p[5]:" ")." ".($_from_p[5]?"$p_p[5] %":" ")." "; }
#if ($ShowOriginStats =~ /H/i) { print "".($_from_h[5]?$_from_h[5]:" ")." ".($_from_h[5]?"$p_h[5] %":" ")." "; }
#print " \n";
#------- Unknown origin
print "$Message[39] ";
if ( $ShowOriginStats =~ /P/i ) {
print ""
. ( $_from_p[1] ? Format_Number($_from_p[1]) : " " )
. " "
. ( $_from_p[1] ? "$p_p[1] %" : " " ) . " ";
}
if ( $ShowOriginStats =~ /H/i ) {
print ""
. ( $_from_h[1] ? Format_Number($_from_h[1]) : " " )
. " "
. ( $_from_h[1] ? "$p_h[1] %" : " " ) . " ";
}
print " \n";
&tab_end();
# 0: Direct
# 1: Unknown
# 2: SE
# 3: External link
# 4: Internal link
# 5: Newsgroup (deprecated)
}
#------------------------------------------------------------------------------
# Function: Prints the Key Phrases and Keywords chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainKeys{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($ShowKeyphrasesStats) {
print "$Center ";
}
if ($ShowKeywordsStats) {
print "$Center ";
}
if ( $ShowKeyphrasesStats || $ShowKeywordsStats ) { print " \n"; }
if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
print
"";
}
if ($ShowKeyphrasesStats) {
# By Keyphrases
if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
print "\n";
}
if ($Debug) { debug( "ShowKeyphrasesStats", 2 ); }
&tab_head(
"$Message[120] ($Message[77] $MaxNbOf{'KeyphrasesShown'})$Message[80] ",
19,
( $ShowKeyphrasesStats && $ShowKeywordsStats ) ? 95 : 70,
'keyphrases'
);
print " $TotalDifferentKeyphrases $Message[103] $Message[14] $Message[15] \n";
my $total_s = 0;
my $count = 0;
&BuildKeyList( $MaxNbOf{'KeyphrasesShown'},
$MinHit{'Keyphrase'}, \%_keyphrases, \%_keyphrases );
foreach my $key (@keylist) {
my $mot;
# Convert coded keywords (utf8,...) to be correctly reported in HTML page.
if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
$mot = CleanXSS(
DecodeKey_decodeutfkeys(
$key, $PageCode || 'iso-8859-1'
)
);
}
else { $mot = CleanXSS( DecodeEncodedString($key) ); }
my $p;
if ($TotalKeyphrases) {
$p =
int( $_keyphrases{$key} / $TotalKeyphrases * 1000 ) / 10;
}
print ""
. XMLEncode($mot)
. " $_keyphrases{$key} $p % \n";
$total_s += $_keyphrases{$key};
$count++;
}
if ($Debug) {
debug( "Total real / shown : $TotalKeyphrases / $total_s", 2 );
}
my $rest_s = $TotalKeyphrases - $total_s;
if ( $rest_s > 0 ) {
my $p;
if ($TotalKeyphrases) {
$p = int( $rest_s / $TotalKeyphrases * 1000 ) / 10;
}
print
"$Message[124] $rest_s ";
print "$p % \n";
}
&tab_end();
if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
print "\n";
}
}
if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
print " ";
}
if ($ShowKeywordsStats) {
# By Keywords
if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
print "\n";
}
if ($Debug) { debug( "ShowKeywordsStats", 2 ); }
&tab_head(
"$Message[121] ($Message[77] $MaxNbOf{'KeywordsShown'})$Message[80] ",
19,
( $ShowKeyphrasesStats && $ShowKeywordsStats ) ? 95 : 70,
'keywords'
);
print " $TotalDifferentKeywords $Message[13] $Message[14] $Message[15] \n";
my $total_s = 0;
my $count = 0;
&BuildKeyList( $MaxNbOf{'KeywordsShown'},
$MinHit{'Keyword'}, \%_keywords, \%_keywords );
foreach my $key (@keylist) {
my $mot;
# Convert coded keywords (utf8,...) to be correctly reported in HTML page.
if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
$mot = CleanXSS(
DecodeKey_decodeutfkeys(
$key, $PageCode || 'iso-8859-1'
)
);
}
else { $mot = CleanXSS( DecodeEncodedString($key) ); }
my $p;
if ($TotalKeywords) {
$p = int( $_keywords{$key} / $TotalKeywords * 1000 ) / 10;
}
print ""
. XMLEncode($mot)
. " $_keywords{$key} $p % \n";
$total_s += $_keywords{$key};
$count++;
}
if ($Debug) {
debug( "Total real / shown : $TotalKeywords / $total_s", 2 );
}
my $rest_s = $TotalKeywords - $total_s;
if ( $rest_s > 0 ) {
my $p;
if ($TotalKeywords) {
$p = int( $rest_s / $TotalKeywords * 1000 ) / 10;
}
print
"$Message[30] $rest_s ";
print "$p % \n";
}
&tab_end();
if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
print "\n";
}
}
if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
print "
\n";
}
}
#------------------------------------------------------------------------------
# Function: Prints the miscellaneous table
# Parameters: -
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainMisc{
if ($Debug) { debug( "ShowMiscStats", 2 ); }
print "$Center \n";
my $title = "$Message[139]";
&tab_head( "$title", 19, 0, 'misc' );
print
"$Message[139] ";
print " ";
print " ";
print " \n";
my %label = (
'AddToFavourites' => $Message[137],
'JavascriptDisabled' => $Message[168],
'JavaEnabled' => $Message[140],
'DirectorSupport' => $Message[141],
'FlashSupport' => $Message[142],
'RealPlayerSupport' => $Message[143],
'QuickTimeSupport' => $Message[144],
'WindowsMediaPlayerSupport' => $Message[145],
'PDFSupport' => $Message[146]
);
foreach my $key (@MiscListOrder) {
my $mischar = substr( $key, 0, 1 );
if ( $ShowMiscStats !~ /$mischar/i ) { next; }
my $total = 0;
my $p;
if ( $MiscListCalc{$key} eq 'v' ) { $total = $TotalVisits; }
if ( $MiscListCalc{$key} eq 'u' ) { $total = $TotalUnique; }
if ( $MiscListCalc{$key} eq 'hm' ) {
$total = $_misc_h{'TotalMisc'} || 0;
}
if ($total) {
$p =
int( ( $_misc_h{$key} ? $_misc_h{$key} : 0 ) / $total *
1000 ) / 10;
}
print "";
print ""
. ( $PageDir eq 'rtl' ? "" : "" )
. $label{$key}
. ( $PageDir eq 'rtl' ? " " : "" ) . " ";
if ( $MiscListCalc{$key} eq 'v' ) {
print ""
. Format_Number(( $_misc_h{$key} || 0 ))
. " / ".Format_Number($total)." $Message[12] ";
}
if ( $MiscListCalc{$key} eq 'u' ) {
print ""
. Format_Number(( $_misc_h{$key} || 0 ))
. " / ".Format_Number($total)." $Message[18] ";
}
if ( $MiscListCalc{$key} eq 'hm' ) { print "- "; }
print "" . ( $total ? "$p %" : " " ) . " ";
print " \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the Status codes chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainHTTPStatus{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($Debug) { debug( "ShowHTTPErrorsStats", 2 ); }
print "$Center \n";
my $title = "$Message[32]";
&tab_head( "$title", 19, 0, 'errors' );
&BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_errors_h, \%_errors_h );
# Graph the top five in a pie chart
if (scalar @keylist > 1){
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ();
my @valdata = ();
my @valcolor = ($color_p);
my $cnt = 0;
foreach my $key (@keylist) {
push @valdata, int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
push @blocklabel, "$key";
$cnt++;
if ($cnt > 4) { last; }
}
print "";
my $function = "ShowGraph_$pluginname";
&$function(
"$title", "httpstatus",
0, \@blocklabel,
0, \@valcolor,
0, 0,
0, \@valdata
);
print " ";
}
}
print
"$Message[32]* $Message[57] $Message[15] $Message[75] \n";
my $total_h = 0;
my $count = 0;
foreach my $key (@keylist) {
my $p = int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
print "";
if ( $TrapInfosForHTTPErrorCodes{$key} ) {
print "$key ";
}
else { print "$key "; }
print ""
. (
$httpcodelib{$key} ? $httpcodelib{$key} : 'Unknown error' )
. " ".Format_Number($_errors_h{$key})." $p % "
. Format_Bytes( $_errors_k{$key} ) . " ";
print " \n";
$total_h += $_errors_h{$key};
$count++;
}
&tab_end("* $Message[154]");
}
#------------------------------------------------------------------------------
# Function: Prints the Status codes chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainSMTPStatus{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($Debug) { debug( "ShowSMTPErrorsStats", 2 ); }
print "$Center \n";
my $title = "$Message[147]";
&tab_head( "$title", 19, 0, 'errors' );
print
"$Message[147] $Message[57] $Message[15] $Message[75] \n";
my $total_h = 0;
my $count = 0;
&BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_errors_h, \%_errors_h );
foreach my $key (@keylist) {
my $p = int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
print "";
print "$key ";
print ""
. (
$smtpcodelib{$key} ? $smtpcodelib{$key} : 'Unknown error' )
. " ".Format_Number($_errors_h{$key})." $p % "
. Format_Bytes( $_errors_k{$key} ) . " ";
print " \n";
$total_h += $_errors_h{$key};
$count++;
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints the cluster information chart and table
# Parameters: $NewLinkParams, $NewLinkTarget
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainCluster{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
if ($Debug) { debug( "ShowClusterStats", 2 ); }
print "$Center \n";
my $title = "$Message[155]";
&tab_head( "$title", 19, 0, 'clusters' );
&BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_cluster_p, \%_cluster_p );
# Graph the top five in a pie chart
if (scalar @keylist > 1){
foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
{
my @blocklabel = ();
my @valdata = ();
my @valcolor = ($color_p);
my $cnt = 0;
foreach my $key (@keylist) {
push @valdata, int( $_cluster_p{$key} / $TotalHits * 1000 ) / 10;
push @blocklabel, "$key";
$cnt++;
if ($cnt > 4) { last; }
}
print "";
my $function = "ShowGraph_$pluginname";
&$function(
"$title", "cluster",
0, \@blocklabel,
0, \@valcolor,
0, 0,
0, \@valdata
);
print " ";
}
}
print
"$Message[155] ";
&HTMLShowClusterInfo('__title__');
if ( $ShowClusterStats =~ /P/i ) {
print
"$Message[56] $Message[15] ";
}
if ( $ShowClusterStats =~ /H/i ) {
print
"$Message[57] $Message[15] ";
}
if ( $ShowClusterStats =~ /B/i ) {
print
"$Message[75] $Message[15] ";
}
print " \n";
my $total_p = my $total_h = my $total_k = 0;
# Cluster feature might have been enable in middle of month so we recalculate
# total for cluster section only, to calculate ratio, instead of using global total
foreach my $key (@keylist) {
$total_p += int( $_cluster_p{$key} || 0 );
$total_h += int( $_cluster_h{$key} || 0 );
$total_k += int( $_cluster_k{$key} || 0 );
}
my $count = 0;
foreach my $key (@keylist) {
my $p_p = int( $_cluster_p{$key} / $total_p * 1000 ) / 10;
my $p_h = int( $_cluster_h{$key} / $total_h * 1000 ) / 10;
my $p_k = int( $_cluster_k{$key} / $total_k * 1000 ) / 10;
print "";
print "Computer $key ";
&HTMLShowClusterInfo($key);
if ( $ShowClusterStats =~ /P/i ) {
print ""
. ( $_cluster_p{$key} ? Format_Number($_cluster_p{$key}) : " " )
. " $p_p % ";
}
if ( $ShowClusterStats =~ /H/i ) {
print "".Format_Number($_cluster_h{$key})." $p_h % ";
}
if ( $ShowClusterStats =~ /B/i ) {
print ""
. Format_Bytes( $_cluster_k{$key} )
. " $p_k % ";
}
print " \n";
$count++;
}
&tab_end();
}
#------------------------------------------------------------------------------
# Function: Prints a chart or table for each extra section
# Parameters: $NewLinkParams, $NewLinkTarget, $extranum
# Input: -
# Output: HTML
# Return: -
#------------------------------------------------------------------------------
sub HTMLMainExtra{
my $NewLinkParams = shift;
my $NewLinkTarget = shift;
my $extranum = shift;
if ($Debug) { debug( "ExtraName$extranum", 2 ); }
print "$Center ";
my $title = $ExtraName[$extranum];
&tab_head( "$title", 19, 0, "extra$extranum" );
print "";
print "" . $ExtraFirstColumnTitle[$extranum];
print " - $Message[80] ";
print " ";
if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
print
"$Message[56] ";
}
if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
print
"$Message[57] ";
}
if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
print
"$Message[75] ";
}
if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
print "$Message[9] ";
}
print " \n";
my $total_p = my $total_h = my $total_k = 0;
#$max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
#$max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
my $count = 0;
if ( $MaxNbOfExtra[$extranum] ) {
if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
&BuildKeyList(
$MaxNbOfExtra[$extranum],
$MinHitExtra[$extranum],
\%{ '_section_' . $extranum . '_h' },
\%{ '_section_' . $extranum . '_p' }
);
}
else {
&BuildKeyList(
$MaxNbOfExtra[$extranum],
$MinHitExtra[$extranum],
\%{ '_section_' . $extranum . '_h' },
\%{ '_section_' . $extranum . '_h' }
);
}
}
else {
@keylist = ();
}
my %keysinkeylist = ();
foreach my $key (@keylist) {
$keysinkeylist{$key} = 1;
my $firstcol = CleanXSS( DecodeEncodedString($key) );
$total_p += ${ '_section_' . $extranum . '_p' }{$key};
$total_h += ${ '_section_' . $extranum . '_h' }{$key};
$total_k += ${ '_section_' . $extranum . '_k' }{$key};
print "";
printf(
"$ExtraFirstColumnFormat[$extranum] ",
$firstcol, $firstcol, $firstcol, $firstcol, $firstcol );
if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
print ""
. ${ '_section_' . $extranum . '_p' }{$key} . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
print ""
. ${ '_section_' . $extranum . '_h' }{$key} . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
print ""
. Format_Bytes(
${ '_section_' . $extranum . '_k' }{$key} )
. " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
print ""
. (
${ '_section_' . $extranum . '_l' }{$key}
? Format_Date(
${ '_section_' . $extranum . '_l' }{$key}, 1 )
: '-'
)
. " ";
}
print " \n";
$count++;
}
# If we ask average or sum, we loop on all other records
if ( $ExtraAddAverageRow[$extranum] || $ExtraAddSumRow[$extranum] )
{
foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
if ( $keysinkeylist{$_} ) { next; }
$total_p += ${ '_section_' . $extranum . '_p' }{$_};
$total_h += ${ '_section_' . $extranum . '_h' }{$_};
$total_k += ${ '_section_' . $extranum . '_k' }{$_};
$count++;
}
}
# Add average row
if ( $ExtraAddAverageRow[$extranum] ) {
print "";
print "$Message[96] ";
if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
print ""
. ( $count ? Format_Number(( $total_p / $count )) : " " ) . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
print ""
. ( $count ? Format_Number(( $total_h / $count )) : " " ) . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
print ""
. (
$count ? Format_Bytes( $total_k / $count ) : " " )
. " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
print " ";
}
print " \n";
}
# Add sum row
if ( $ExtraAddSumRow[$extranum] ) {
print "";
print "$Message[102] ";
if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
print "" . Format_Number(($total_p)) . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
print "" . Format_Number(($total_h)) . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
print "" . Format_Bytes($total_k) . " ";
}
if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
print " ";
}
print " \n";
}
&tab_end();
}
#------------------------------------------------------------------------------
# MAIN
#------------------------------------------------------------------------------
( $DIR = $0 ) =~ s/([^\/\\]+)$//;
( $PROG = $1 ) =~ s/\.([^\.]*)$//;
$Extension = $1;
$DIR ||= '.';
$DIR =~ s/([^\/\\])[\\\/]+$/$1/;
$starttime = time();
# Get current time (time when AWStats was started)
( $nowsec, $nowmin, $nowhour, $nowday, $nowmonth, $nowyear, $nowwday, $nowyday )
= localtime($starttime);
$nowweekofmonth = int( $nowday / 7 );
$nowweekofyear =
int( ( $nowyday - 1 + 6 - ( $nowwday == 0 ? 6 : $nowwday - 1 ) ) / 7 ) + 1;
if ( $nowweekofyear > 52 ) { $nowweekofyear = 1; }
$nowdaymod = $nowday % 7;
$nowwday++;
$nowns = Time::Local::timegm( 0, 0, 0, $nowday, $nowmonth, $nowyear );
if ( $nowdaymod <= $nowwday ) {
if ( ( $nowwday != 7 ) || ( $nowdaymod != 0 ) ) {
$nowweekofmonth = $nowweekofmonth + 1;
}
}
if ( $nowdaymod > $nowwday ) { $nowweekofmonth = $nowweekofmonth + 2; }
# Change format of time variables
$nowweekofmonth = "0$nowweekofmonth";
if ( $nowweekofyear < 10 ) { $nowweekofyear = "0$nowweekofyear"; }
if ( $nowyear < 100 ) { $nowyear += 2000; }
else { $nowyear += 1900; }
$nowsmallyear = $nowyear;
$nowsmallyear =~ s/^..//;
if ( ++$nowmonth < 10 ) { $nowmonth = "0$nowmonth"; }
if ( $nowday < 10 ) { $nowday = "0$nowday"; }
if ( $nowhour < 10 ) { $nowhour = "0$nowhour"; }
if ( $nowmin < 10 ) { $nowmin = "0$nowmin"; }
if ( $nowsec < 10 ) { $nowsec = "0$nowsec"; }
$nowtime = int( $nowyear . $nowmonth . $nowday . $nowhour . $nowmin . $nowsec );
# Get tomorrow time (will be used to discard some record with corrupted date (future date))
my (
$tomorrowsec, $tomorrowmin, $tomorrowhour,
$tomorrowday, $tomorrowmonth, $tomorrowyear
)
= localtime( $starttime + 86400 );
if ( $tomorrowyear < 100 ) { $tomorrowyear += 2000; }
else { $tomorrowyear += 1900; }
if ( ++$tomorrowmonth < 10 ) { $tomorrowmonth = "0$tomorrowmonth"; }
if ( $tomorrowday < 10 ) { $tomorrowday = "0$tomorrowday"; }
if ( $tomorrowhour < 10 ) { $tomorrowhour = "0$tomorrowhour"; }
if ( $tomorrowmin < 10 ) { $tomorrowmin = "0$tomorrowmin"; }
if ( $tomorrowsec < 10 ) { $tomorrowsec = "0$tomorrowsec"; }
$tomorrowtime =
int( $tomorrowyear
. $tomorrowmonth
. $tomorrowday
. $tomorrowhour
. $tomorrowmin
. $tomorrowsec );
# Allowed option
my @AllowedCLIArgs = (
'migrate', 'config',
'logfile', 'output',
'runascli', 'update',
'staticlinks', 'staticlinksext',
'noloadplugin', 'loadplugin',
'hostfilter', 'urlfilter',
'refererpagesfilter', 'lang',
'month', 'year',
'framename', 'debug',
'showsteps', 'showdropped',
'showcorrupted', 'showunknownorigin',
'showdirectorigin', 'limitflush',
'confdir', 'updatefor',
'hostfilter', 'hostfilterex',
'urlfilter', 'urlfilterex',
'refererpagesfilter', 'refererpagesfilterex',
'pluginmode', 'filterrawlog'
);
# Parse input parameters and sanitize them for security reasons
$QueryString = '';
# AWStats use GAT