#!/usr/pkg/bin/perl # # Distributed.net Personal Proxy Statistics Log Analyzer # University of Southern Maine Computer Users Group # Copyright (C) Kevin Pesce (kpesce@netscape.net) 1998, 1999 # # See Readme.txt for a description and system requirements for this script. # See Install.txt for step by step instructions on how to install this script. # See License.txt for the licensing terms of the GNU General Public License. # See ChangeLog.txt for revision history information. # See Todo.txt for a listing of outstanding issues. # # Edit the ppstats-rc5.ini file to customize this script for your team. # There should not be a need to modify this file directly. # # use warnings 'all'; no warnings 'signal'; #--- Priority ---------------------------------------------------------------- # Set script to nice priority. Comment out the following line for use on NT. # For NT users, try Thomas Minor's program for setting script priority at # http://www.geocities.com/Area51/Quadrant/2530/files/dNetPProxyStats/runit-idle.zip setpriority(0,0,5); # Begin main subroutine. umask("002"); &init(); &collect_data(); &write_css(); &write_index(); &write_exec(); &write_byemail(); &write_byhost() if ($userprefs{"showbyhost"}); &write_byos(); &write_bycpu(); &write_byver(); &write_byfull(); &write_bydomain(); &write_byhour(); &write_bydate(); &write_byweek(); &write_bymonth(); &write_byyear(); &write_bydayofweek(); exit; #----------------------------------------------------------------------------- # # Initialize internal script variables. Do not edit these settings. # #----------------------------------------------------------------------------- sub init { # Contest specific information. $contestname = "Bovine RC5-64"; $contestsuffix = "rc5"; $conteststatsurlpre = "http://stats.distributed.net/rc5-64/"; $contestsize = 64; $blockbase = 28; $blockweight = 1; # Set name, path, version, and debug variables. $appver = "7.1"; ($appdir, $app) = split(m|([^/]+)$|, $0, 2); $appini = "ppstats-$contestsuffix.ini"; $debug_enable = 0; # Figure timestamp in GMT. use Time::Local; $time_begin = time; # Parse the command line variables. &parse_cmd_line("-debug", 0, "-version", 0, "-help", 0); &enable_debug_messages() if ($opt{'-debug'}); &display_usage() if ($opt{'-help'}); &display_version() if ($opt{'-version'}); &debugln("Entering init() ..."); # Known OS types. @osid = ( "Unknown", "Windows 95/98/NT", "PC-DOS/MS-DOS", "FreeBSD", "Linux", "BeOS", "Macintosh OS", "IRIX", "VMS", "Digital UNIX", "UnixWare", "OS/2 Warp", "HP-UX", "NetBSD", "SunOS", "Solaris", "OS9", "Java VM", "BSDI", "NeXTStep", "SCO", "QNX", "OSF/1", "MINIX", "MACH10", "AIX", "AUX", "Rhapsody", "AmigaOS", "OpenBSD", "NetWare", "MVS", "Ultrix", "Newton", "RiscOS", "DG/UX", "Windows 3.x (Win32s)", "SINIX", "DYNIX", "OS/390", "MASPAR", "Windows 3.x (Win16)", "DEScracker" ); # Image icons in the icons/os directory. Contributions are welcome! @osiconid = ( "unknown.gif", "windows.gif", "dos.gif", "bsd.gif", "linux.gif", "be.gif", "macos.gif", "irix.gif", "vms.gif", "digital.gif", "sco.gif", "warp.gif", "hp.gif", "bsd.gif", "sun.gif", "sun.gif", "unknown.gif", "java.gif", "bsdi.gif", "next.gif", "sco.gif", "qnx.gif", "digital.gif", "unknown.gif", "unknown.gif", "aix.gif", "ibm.gif", "apple.gif", "amiga.gif", "openbsd.gif", "netware.gif", "unknown.gif", "digital.gif", "apple.gif", "acorn.gif", "unknown.gif", "windows.gif", "unknown.gif", "unknown.gif", "ibm.gif", "unknown.gif", "windows.gif", "unknown.gif" ); # Known CPU types. @cpuid = ( "Unknown", "x86", "PowerPC", "MIPS", "Alpha", "PA-RISC", "m68k", "SPARC", "Java VM", "POWER", "VAX", "StrongARM", "m88k", "KSR1", "S390", "MASPAR", "DEScracker" ); # Image icons in the icons/cpu directory. Contributions are welcome! @cpuiconid = ( "unknown.gif", "intel.gif", "motorola.gif", "mips.gif", "digital.gif", "hp.gif", "motorola.gif", "sun.gif", "java.gif", "ibm.gif", "digital.gif", "intel.gif", "motorola.gif", "unknown.gif", "ibm.gif", "unknown.gif", "unknown.gif" ); # Known countries. Contributions are welcome! Note that "need" means we don't # have a flag for that domain yet. http://www.thrall.org/domains.htm %country = ( "com" => "US Commercial", "edu" => "US Educational", "gov" => "US Government", "mil" => "US Military", "net" => "Network", "org" => "Non-Profit Organization", "int" => "International", "arpa" => "Arpanet", # need "nato" => "Nato field", "ad" => "Andorra", "ae" => "United Arab Emirates", "af" => "Afghanistan", "ag" => "Antigua and Barbuda", "ai" => "Anguilla", "al" => "Albania", "am" => "Armenia", "an" => "Netherlands Antilles", "ao" => "Angola", "aq" => "Antartica", "ar" => "Argentina", "as" => "American Samoa", "at" => "Austria", "au" => "Australia", "aw" => "Aruba", "az" => "Azerbaijan", "ba" => "Bosnia and Herzegovina", "bb" => "Barbados", "bd" => "Bangladesh", "be" => "Belgium", "bf" => "Burkina Faso", "bg" => "Bulgaria", "bh" => "Bahrain", "bi" => "Burundi", "bj" => "Benin", "bm" => "Bermuda", "bn" => "Brunei Darussalam", "bo" => "Bolivia", "br" => "Brazil", "bs" => "Bahamas", "bt" => "Bhutan", "bv" => "Bouvet Island", "bw" => "Botswana", "by" => "Belorussia", "bz" => "Belize", "ca" => "Canada", "cc" => "Cocos (Keeling) Islands", "cd" => "Democatric Republic of Congo", "cf" => "Central African Republic", "cg" => "Congo", "ch" => "Switzerland", "ci" => "Cote D'Ivoire (Ivory Coast)", "ck" => "Cook Islands", "cl" => "Chile", "cm" => "Cameroon", "cn" => "China", "co" => "Colombia", "cr" => "Costa Rica", "cs" => "Czechoslovakia", "cu" => "Cuba", "cv" => "Cape Verde", "cx" => "Christmas Island", "cy" => "Cyprus", "cz" => "Czech", "de" => "Germany", "dj" => "Djibouti", "dk" => "Denmark", "dm" => "Dominica", "do" => "Dominican Republic", "dz" => "Algeria", "ec" => "Ecuador", "ee" => "Estonia", "eg" => "Egypt", "eh" => "Western Sahara", "er" => "Eritrea", "es" => "Spain", "et" => "Ethiopia", "fi" => "Finland", "fj" => "Fiji", "fk" => "Falkland Islands (Malvinas)", "fm" => "Micronesia", "fo" => "Faroe Islands", "fr" => "France", "fx" => "France, Metropolitan", "ga" => "Gabon", "gb" => "Great Britain", "gd" => "Grenada", "ge" => "Georgia", "gf" => "French Guiana", "gh" => "Ghana", "gi" => "Gibraltar", "gl" => "Greenland", "gm" => "Gambia", "gn" => "Guinea", "gp" => "Guadelope", "gq" => "Equatorial Guinea", "gr" => "Greece", "gs" => "S.Georgia and S.Sandwich Isls.", "gt" => "Guatemala", "gu" => "Guam", "gw" => "Guinea Bissau", "gy" => "Gyana", "hk" => "Hong Kong", "hm" => "Heard and McDonald Islands", "hn" => "Honduras", "hr" => "Croatia", "ht" => "Haiti", "hu" => "Hungary", "id" => "Indonesia", "ie" => "Ireland", "il" => "Israel", "in" => "India", "io" => "British Idian Ocean Territory", "iq" => "Iraq", "ir" => "Iran", "is" => "Iceland", "it" => "Italy", "jm" => "Jamaica", "jo" => "Jordan", "jp" => "Japan", "ke" => "Kenya", "kg" => "Kyrgyzstan", "kh" => "Cambodia", "ki" => "Kiribati", "km" => "Comoros", "kn" => "Saint Kitts and Nevis", "kp" => "North Korea", "kr" => "South Korea", "kw" => "Kuwait", "ky" => "Cayman Islands", "kz" => "Kazakhstan", "la" => "Laos", "lb" => "Lebanon", "lc" => "Saint Lucia", "li" => "Liechtenstein", "lk" => "Sri Lanka", "lr" => "Liberia", "ls" => "Lesotho", "lt" => "Lithuania", "lu" => "Luxembourg", "lv" => "Latvia", "ly" => "Lybia", "ma" => "Marocco", "mc" => "Monaco", "md" => "Moldova", "mg" => "Madagascar", # need "mh" => "Marshall Islands", # need "mk" => "Macedonia", "ml" => "Mali", # need "mm" => "Myanmar", # need "mn" => "Mongolia", # need "mo" => "Macau", # need "mp" => "Northern Mariana Islands", # need "mq" => "Martinique", "mr" => "Mauritania", "ms" => "Montserrat", # need "mt" => "Malta", "mu" => "Mauritius", "mv" => "Maldives", # need "mw" => "Malawi", # need "mx" => "Mexico", "my" => "Malaysia", "mz" => "Mozambique", # need "na" => "Namibia", "nc" => "New Caledonia", # need "ne" => "Niger", "nf" => "Norfolk Island", # need "ng" => "Nigeria", "ni" => "Nicaragua", "nl" => "Netherlands", "no" => "Norway", "np" => "Nepal", "nr" => "Nauru", # need "nt" => "Neutral Zone", # need "nu" => "Niue", "nz" => "New Zealand", "om" => "Oman", "pa" => "Panama", "pe" => "Peru", "pf" => "French Polynesia", "pg" => "Papua New Guinea", # need "ph" => "Philippines", "pk" => "Pakistan", "pl" => "Poland", "pm" => "St. Pierre and Miquelon", # need "pn" => "Pitcairn", # need "pr" => "Puerto Rico", # need "pt" => "Portugal", "pw" => "Palau", # need "py" => "Paraguay", "qa" => "Qatar", "re" => "Reunion", # need "ro" => "Romania", "ru" => "Russian Federation", "rw" => "Rwanda", "sa" => "Saudi Arabia", "sb" => "Solomon Islands", "sc" => "Seychelles", # need "sd" => "Sudan", # need "se" => "Sweden", "sg" => "Singapore", "sh" => "St. Helena", # need "si" => "Slovania", "sj" => "Svalbard and Jan Mayen Islands", # need "sk" => "Slovak Republic", "sl" => "Sierra Leone", # need "sm" => "San Marino", # need "sn" => "Senegal", # need "so" => "Somalia", # need "sr" => "Suriname", # need "st" => "Sao Tome and Principe", # need "su" => "Soviet Union", "sv" => "El Salvador", # need "sy" => "Syria", "sz" => "Swaziland", "tc" => "Turks and Caicos Islands", "td" => "Chad", "tf" => "French Southern Territories", "tg" => "Togo", "th" => "Thailand", "tj" => "Tajikistan", # need "tk" => "Tokelau", "tm" => "Turkmenistan", "tn" => "Tunisia", "to" => "Tonga", "tp" => "East Timor", # need "tr" => "Turkey", "tt" => "Trinidad and Tobago", "tv" => "Tuvalu", # need "tw" => "Taiwan", "tz" => "Tanzania", "ua" => "Ukraine", "ug" => "Uganda", "uk" => "United Kingdom", "um" => "US Minor Outlying Islands", "us" => "United States", "uy" => "Uruguay", "uz" => "Uzbekistan", "va" => "Vatican City State (Holy See)", "vc" => "Saint Vincent and the Grenadines", "ve" => "Venezuela", "vg" => "Virgin Islands (British)", "vi" => "Virgin Islands (US)", "vn" => "Vietnam", "wf" => "Wallis and Futuna Islands", "ws" => "Samoa", "ye" => "Yemen", "yt" => "Mayotte", "yu" => "Yugoslavia", "za" => "South Africa", "ze" => "Zaire", "zm" => "Zambia", "zw" => "Zimbabwe" ); @months = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); @days = ( "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ); @ups = ( # Team Information "team", "teamhome", "teamid", "uselogo", "logdir", "logpre", "logsuf", "processziplogs", # Input Options "logzipsuf", "logtmpsuf", "logdecompressor", "maxdays", "htmldir", "icondir", "htmlteam", "htmlexec", # Output Options "htmlmail", "htmlhost", "htmlos", "htmlcpu", "htmlver", "htmlfull", "htmldomain", "htmlhour", "htmldate", "htmlweek", "htmlmonth", "htmlyear", "htmldayofweek", "htmlindvemail", "htmlemailhist", "htmlhostsbyemail", "htmlindvhost", "htmlhosthist", "htmlemailsbyhost", "css", "cachefile", "cachedays", "gnuplot", "gnuplotconfig", "gnuplotdata", "gnuplotoutput", "usecounter", "counter", "showbyhost", "chartlinestyle", "chartwidth", "chartheight", # Format Options "dayaverage", "movementdays", "maxrows", "dayshist", "blockhistory", "useheaderbanner", "usefooterbanner", "conshosts", "colorlastseen", "lastseenwarningtime", "lastseencriticaltime", "lastseenwarningcolor", "lastseencriticalcolor", "moveupcolor", "movedowncolor", "usemetarefresh", "metarefreshperiod", "backgroundcolor", "linkbarcolor", "linkbartitlefontcolor", # Color Configuration "sectiontitlebarcolor", "sectiontitlefontcolor", "sectionlowlightcolor", "sectionhighlightcolor", "sectionnotefontcolor", "historycolor", "avehistorycolor", "ndayhistorycolor", "textcolor", "linkcolor", "visitedlinkcolor", "activelinkcolor", "fontstyle" ); # Calculate timestamp. ($year, $month, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $timestamp = "$mday $months[$month-1] $year $hour:$min"; # Calculate standard variables for today. $secs_today = $hour * 3600 + $min * 60 + $sec; if ($secs_today == 0) { $secs_today = 1; } # Read in user initialization file. &debugln("Reading initialization file $appdir$appini ..."); open(INIFILE, "$appdir$appini") or die "Personal Proxy Statistics : Cannot open $appdir$appini ($!)\n"; while (defined($entry = )) { chomp($entry); # no newline $entry =~ s/#.*//; # no comments $entry =~ s/^\s+//; # no leading white $entry =~ s/\s+$//; # no trailing white next unless length($entry); # anything left? my ($var, $value) = split(/\s*=\s*/, $entry, 2); $value =~ s/\"//g; # remove "'s $var =~ tr/A-Z/a-z/; # convert to lowercase $userprefs{$var} = $value # set var to value } close INIFILE; # Make sure all user preferences are accounted for. &validate_userprefs(); &debugln("Exiting init() ..."); } # init #----------------------------------------------------------------------------- # # Collect the stats from the proxy log files. # #----------------------------------------------------------------------------- sub collect_data { &debugln("Entering collect_data() ..."); # Get logfiles in reverse order. $logglob = $userprefs{"logpre"} . "*." . $userprefs{"logsuf"}; @logfiles = <$userprefs{"logdir"}$logglob>; # Handle compressed log files. The check for a valid log file suffix is # to prevent problems where all files would be processed as if zipped. if ($userprefs{"processziplogs"} && defined($userprefs{"logzipsuf"})) { $logglob = $userprefs{"logpre"} . "*." . $userprefs{"logzipsuf"}; push @logfiles, <$userprefs{"logdir"}$logglob>; } @logfiles = reverse sort @logfiles; # Put each stat into an array of hashes such that: # %stat[0] = Total values # %stat[1] = Today's values # %stat[2] = Yesterday's values # %stat[k+2] = value from k days ago. $day = 1; $lastblockday = 0; $prev_lastday = 0; for ($y = 0; $y < 7; $y++) { $dayofweek[$y] = 0; } for ($y = 0; $y < 24; $y++) { $hourofday[$y] = 0; } $blocks[0] = 0; foreach $ulogfile (@logfiles) { # Break out of loop if we have reached our maximum number of days. if ($userprefs{"maxdays"} != 0 && $day > $userprefs{"maxdays"}) { last; } # Handle compressed log files. $logfile = $ulogfile; $logfilesuf = $userprefs{"logsuf"}; $iscompressed = 0; if ($userprefs{"processziplogs"} && (substr($logfile, -length($userprefs{"logzipsuf"}), length($userprefs{"logzipsuf"})) eq $userprefs{"logzipsuf"}) && defined($userprefs{"logzipsuf"})) { $tmplogfile = $appdir . substr($logfile, -(length($userprefs{"logpre"})+8+1+length($userprefs{"logzipsuf"})), length($userprefs{"logpre"})+8+1) . $userprefs{"logtmpsuf"}; $logfilesuf = $userprefs{"logtmpsuf"}; system($userprefs{"logdecompressor"} . " $logfile > $tmplogfile") == 0 or die "Personal Proxy Statistics : Cannot execute " . $userprefs{"logdecompressor"} . " $logfile > $tmplogfile ($?)\n"; $logfile = $tmplogfile; $iscompressed = 1; } $blocks[$day] = 0; ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($day - 1) * (24*60*60)); $yeartoday = substr($logfile, length($logfile) - length($logfilesuf) - 9, 4); $monthtoday = substr($logfile, length($logfile) - length($logfilesuf) - 5, 2); $daytoday = substr($logfile, length($logfile) - length($logfilesuf) - 3, 2); # Correct for missing logfiles, invalid logfile names will likely hang on this loop. $currday = $day; while (!(($yeartoday == $year) && ($monthtoday == $mon) && ($daytoday == $mday))) { $blocks[$currday] = 0; $currday++; # Break out of loop if we have reached our maximum number of days. if ($userprefs{"maxdays"} != 0 && $currday > $userprefs{"maxdays"}) { last; } ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($currday - 1) * (24*60*60)); } # Break out of loop if we have reached our maximum number of days. if ($userprefs{"maxdays"} != 0 && $currday > $userprefs{"maxdays"}) { # If the file compressed, delete the temporary uncompressed file. if ($iscompressed) { unlink("$tmplogfile") == 1 or die "Personal Proxy Statistics : Cannot delete $tmplogfile ($?)\n"; $iscompressed = 0; } last; } $day = $currday; open(LOGFILE, "$logfile") or die "Personal Proxy Statistics : Cannot open $logfile ($!)\n"; # Record the last day a block was submitted. if ($lastblockday != 0 && $prev_lastday == 0) { $prev_lastday = $day; } if ($lastblockday == 0) { $lastblockday = $day; } while (defined($entry = )) { # Trim off the fat and convert to lowercase chomp($entry); $entry =~ tr/A-Z/a-z/; # Format of the log file: "Date/Time HostIP, Email, Block, Block Size, OS, CPU, Client Version" ($datetime, $ipaddr, $email, $block, $nkeys, $os, $cpu, $ver) = split(/,/, $entry); # Do a little error checking for corrupt log files. if ($datetime eq "" or $ipaddr eq "" or $email eq "" or $block eq "" or $nkeys eq "" or $os eq "" or $cpu eq "" or $ver eq "") { die "Personal Proxy Statistics : Logfile is corrupted.\n$logfile\n$entry\n"; } # HACK: Hamiller/dyfa auseinanderhalten if ($yeartoday < 2000 and $ipaddr eq "195.63.63.121") { $ipaddr = "195.8.249.36"; } # Convert nkeys to proper format, only used for compatibility with older logfiles. if ($nkeys == (2**28)) { $nkeys = 1; } # Parse the log file date and time field # We aren't using the $date in ($date, $time) just yet so ignore it. (undef, $time) = split(/ /, $datetime); ($hour, $min, $sec) = split(/:/, $time); # Create Full Detail key if (defined($osid[$os])) { $tmos = $osid[$os]; } else { $tmos = "Unknown"; } if (defined($cpuid[$cpu])) { $tmcpu = $cpuid[$cpu]; } else { $tmcpu = "Unknown"; } $tm = $tmos . ", " . $tmcpu . ", " . $ver; $full_icon{$tm}[0] = $os; $full_icon{$tm}[1] = $cpu; # Add to blocks array totals $blocks[0] += $nkeys; # Add to individual days $blocks[$day] += $nkeys; # Add to stat totals if (defined($emails{$email}[0])) { $emails{$email}[0] += $nkeys; } else { $emails{$email}[0] = $nkeys; } if ($userprefs{"showbyhost"}) { if (defined($ipaddrs{$ipaddr}[0])) { $ipaddrs{$ipaddr}[0] += $nkeys; } else { $ipaddrs{$ipaddr}[0] = $nkeys; } } if (defined($oss{$os}[0])) { $oss{$os}[0] += $nkeys; } else { $oss{$os}[0] = $nkeys; } if (defined($cpus{$cpu}[0])) { $cpus{$cpu}[0] += $nkeys; } else { $cpus{$cpu}[0] = $nkeys; } if (defined($vers{$ver}[0])) { $vers{$ver}[0] += $nkeys; } else { $vers{$ver}[0] = $nkeys; } if (defined($full{$tm}[0])) { $full{$tm}[0] += $nkeys; } else { $full{$tm}[0] = $nkeys; } $domain = undef; if ($email =~ /\.(\w+)$/) { $domain = $1; } else { $domain = 'Unknown'; } if (defined($domain) && defined($country{$domain})) { if (defined($domains{$domain}[0])) { $domains{$domain}[0] += $nkeys; } else { $domains{$domain}[0] = $nkeys; } $domain_count{$domain}{$email} = 1; } else { if (defined($domains{"Unknown"}[0])) { $domains{"Unknown"}[0] += $nkeys; } else { $domains{"Unknown"}[0] = $nkeys; } $domain_count{"Unknown"}{$email} = 1; } # Assuming log file will always be read oldest to newest if (!defined($team_ls[0]) || $team_ls[0] == $day - 1) { $team_ls[0] = $day - 1; $team_ls[1] = $hour; $team_ls[2] = $min; $team_ls[3] = $sec; } # Add to individual email stats if (!defined($emails_lastday{$email})) { $emails_lastday{$email} = $day; } if (($emails_lastday{$email} != $day) && !defined($emails_prev_lastday{$email})) { $emails_prev_lastday{$email} = $day; } $emails_firstday{$email} = $day; if (defined($emails{$email}[$day])) { $emails{$email}[$day] += $nkeys; } else { $emails{$email}[$day] = $nkeys; } if ($userprefs{"showbyhost"}) { if (defined($email2ipaddrs{$email}{$ipaddr})) { $email2ipaddrs{$email}{$ipaddr} += $nkeys; } else { $email2ipaddrs{$email}{$ipaddr} = $nkeys; } } # Assuming log file will always be read oldest to newest if (!defined($emails_ls{$email}[0]) || $emails_ls{$email}[0] == $day - 1) { $emails_ls{$email}[0] = $day - 1; $emails_ls{$email}[1] = $hour; $emails_ls{$email}[2] = $min; $emails_ls{$email}[3] = $sec; } # Add to individual ipaddrs stats if ($userprefs{"showbyhost"}) { if (!defined($ipaddrs_lastday{$ipaddr})) { $ipaddrs_lastday{$ipaddr} = $day; } if (($ipaddrs_lastday{$ipaddr} != $day) && !defined($ipaddrs_prev_lastday{$ipaddr})) { $ipaddrs_prev_lastday{$ipaddr} = $day; } $ipaddrs_firstday{$ipaddr} = $day; if (defined($ipaddrs{$ipaddr}[$day])) { $ipaddrs{$ipaddr}[$day] += $nkeys; } else { $ipaddrs{$ipaddr}[$day] = $nkeys; } if (defined($ipaddr2emails{$ipaddr}{$email})) { $ipaddr2emails{$ipaddr}{$email} += $nkeys; } else { $ipaddr2emails{$ipaddr}{$email} = $nkeys; } # Assuming log file will always be read oldest to newest if (!defined($ipaddrs_ls{$ipaddr}[0]) || $ipaddrs_ls{$ipaddr}[0] == $day - 1) { $ipaddrs_ls{$ipaddr}[0] = $day - 1; $ipaddrs_ls{$ipaddr}[1] = $hour; $ipaddrs_ls{$ipaddr}[2] = $min; $ipaddrs_ls{$ipaddr}[3] = $sec; $ipaddrs_ls{$ipaddr}[4] = $ver; } } # Assuming log file will always be read oldest to newest if (!defined($oss_ls{$os}[0]) || $oss_ls{$os}[0] == $day - 1) { $oss_ls{$os}[0] = $day - 1; $oss_ls{$os}[1] = $hour; $oss_ls{$os}[2] = $min; $oss_ls{$os}[3] = $sec; } # Assuming log file will always be read oldest to newest if (!defined($cpus_ls{$cpu}[0]) || $cpus_ls{$cpu}[0] == $day - 1) { $cpus_ls{$cpu}[0] = $day - 1; $cpus_ls{$cpu}[1] = $hour; $cpus_ls{$cpu}[2] = $min; $cpus_ls{$cpu}[3] = $sec; } # Assuming log file will always be read oldest to newest if (!defined($vers_ls{$ver}[0]) || $vers_ls{$ver}[0] == $day - 1) { $vers_ls{$ver}[0] = $day - 1; $vers_ls{$ver}[1] = $hour; $vers_ls{$ver}[2] = $min; $vers_ls{$ver}[3] = $sec; } # Assuming log file will always be read oldest to newest if (!defined($full_ls{$tm}[0]) || $full_ls{$tm}[0] == $day - 1) { $full_ls{$tm}[0] = $day - 1; $full_ls{$tm}[1] = $hour; $full_ls{$tm}[2] = $min; $full_ls{$tm}[3] = $sec; } # Assuming log file will always be read oldest to newest if (!defined($domains_ls{$domain}[0]) || $domains_ls{$domain}[0] == $day - 1) { $domains_ls{$domain}[0] = $day - 1; $domains_ls{$domain}[1] = $hour; $domains_ls{$domain}[2] = $min; $domains_ls{$domain}[3] = $sec; } # Add to hour of day $hourofday[$hour] += $nkeys; # Add to day of week $dayofweek[$wday] += $nkeys; # Add to individual days if ($day <= $userprefs{"dayshist"}) { if (defined($oss{$os}[$day])) { $oss{$os}[$day] += $nkeys; } else { $oss{$os}[$day] = $nkeys; } if (defined($cpus{$cpu}[$day])) { $cpus{$cpu}[$day] += $nkeys; } else { $cpus{$cpu}[$day] = $nkeys; } if (defined($vers{$ver}[$day])) { $vers{$ver}[$day] += $nkeys; } else { $vers{$ver}[$day] = $nkeys; } if (defined($full{$tm}[$day])) { $full{$tm}[$day] += $nkeys; } else { $full{$tm}[$day] = $nkeys; } if (defined($domain) && defined($country{$domain})) { if (defined($domains{$domain}[$day])) { $domains{$domain}[$day] += $nkeys; } else { $domains{$domain}[$day] = $nkeys; } } else { if (defined($domains{"Unknown"}[$day])) { $domains{"Unknown"}[$day] += $nkeys; } else { $domains{"Unknown"}[$day] = $nkeys; } } } } close LOGFILE; # If the file compressed, delete the temporary uncompressed file. if ($iscompressed) { unlink("$tmplogfile") == 1 or die "Personal Proxy Statistics : Cannot delete $tmplogfile ($?)\n"; $iscompressed = 0; } $day++; &debug("."); } &debugln("") if ($day > 1); # Resolve IP address to DNS names. &resolve_hosts() if ($userprefs{"showbyhost"}); &lookup_rank(); &debugln("Exiting collect_data() ..."); } # collect_data #----------------------------------------------------------------------------- # # Resolve IP addresses to hostnames. # #----------------------------------------------------------------------------- sub resolve_hosts { &debugln("Entering resolve_hosts() ..."); my $ipaddr; my $host; my $count; # Read in cached host names. &read_host_cache(); # Read in user defined domain consolidation file. &debugln("Reading domain consolidation file $appdir$contestsuffix-domain.cons ..."); $count = 0; open(CONSFILE, "$appdir$contestsuffix-domain.cons") or die "Personal Proxy Statistics : Cannot open $appdir$contestsuffix-domain.cons ($!)\n"; while (defined($entry = )) { chomp($entry); # no newline $entry =~ s/#.*//; # no comments $entry =~ s/^\s+//; # no leading white $entry =~ s/\s+$//; # no trailing white next unless length($entry); # anything left? $count += 1; push(@cons_domains, $entry); # save this entry } close CONSFILE; &debugln("Read $count domain consolidation entries ..."); # Read in user defined IP consolidation file. &debugln("Reading IP consolidation file $appdir$contestsuffix-ip.cons ..."); $count = 0; open(CONSFILE, "$appdir$contestsuffix-ip.cons") or die "Personal Proxy Statistics : Cannot open $appdir$contestsuffix-ip.cons ($!)\n"; while (defined($entry = )) { chomp($entry); # no newline $entry =~ s/#.*//; # no comments $entry =~ s/^\s+//; # no leading white $entry =~ s/\s+$//; # no trailing white next unless length($entry); # anything left? $count += 1; push(@cons_ips, $entry); # save this entry } close CONSFILE; &debugln("Read $count IP consolidation entries ..."); &debugln("Resolving Email to Host and Host to Email participation ..."); foreach $ipaddr (keys %ipaddrs) { $host = $host_cache{$ipaddr}; if ($userprefs{"conshosts"}) { if ($host ne $ipaddr) { $host =~ s/\d+/\*/g; } } if ($userprefs{"conshosts"}) { $host =~ s/(\d+\.\d+\.\d+\.)\d+$/$1\*/; } foreach (@cons_domains) { $host =~ s/.*$_$/\*\.$_/; } foreach (@cons_ips) { $host =~ s/^$_\..*/$_\.\*/; } foreach $email (keys %{ $ipaddr2emails{$ipaddr} }) { if (defined($host2emails{$host}{$email})) { $host2emails{$host}{$email} += defined($ipaddr2emails{$ipaddr}{$email}) ? $ipaddr2emails{$ipaddr}{$email} : 0; } else { $host2emails{$host}{$email} = defined($ipaddr2emails{$ipaddr}{$email}) ? $ipaddr2emails{$ipaddr}{$email} : 0; } } foreach $email (keys %email2ipaddrs) { foreach $loop_ipaddr (keys %{ $email2ipaddrs{$email} }) { if ($loop_ipaddr eq $ipaddr) { if (defined($email2hosts{$email}{$host})) { $email2hosts{$email}{$host} += $email2ipaddrs{$email}{$loop_ipaddr}; } else { $email2hosts{$email}{$host} = $email2ipaddrs{$email}{$loop_ipaddr}; } } } } # Gather information for each new hostname for ($y = $ipaddrs_firstday{$ipaddr}; $y >= 0; $y--) { if (defined($hosts{$host}[$y])) { $hosts{$host}[$y] += defined($ipaddrs{$ipaddr}[$y]) ? $ipaddrs{$ipaddr}[$y] : 0; } else { $hosts{$host}[$y] = defined($ipaddrs{$ipaddr}[$y]) ? $ipaddrs{$ipaddr}[$y] : 0; } } if (!defined($hosts_lastday{$host}) || ($hosts_lastday{$host} > $ipaddrs_lastday{$ipaddr})) { $hosts_lastday{$host} = $ipaddrs_lastday{$ipaddr}; } if (!defined($hosts_prev_lastday{$host}) && defined($ipaddrs_prev_lastday{$ipaddr}) || defined($ipaddrs_prev_lastday{$ipaddr}) && ($hosts_prev_lastday{$host} > $ipaddrs_prev_lastday{$ipaddr})) { $hosts_prev_lastday{$host} = $ipaddrs_prev_lastday{$ipaddr}; } if (($ipaddrs_firstday{$ipaddr} == $ipaddrs_lastday{$ipaddr}) && ($ipaddrs_firstday{$ipaddr}) != 1) { if (!defined($hosts_prev_lastday{$host})) { $hosts_prev_lastday{$host} = $ipaddrs_firstday{$ipaddr}; } elsif ($hosts_prev_lastday{$host} > $ipaddrs_firstday{$ipaddr}) { $hosts_prev_lastday{$host} = $ipaddrs_firstday{$ipaddr}; } } if (!defined($hosts_firstday{$host}) || ($hosts_firstday{$host} < $ipaddrs_firstday{$ipaddr})) { $hosts_firstday{$host} = $ipaddrs_firstday{$ipaddr}; } if (defined($hosts_ips{$host})) { $hosts_ips{$host} += 1; } else { $hosts_ips{$host} = 1; } if (!defined($hosts_ls{$host}[0])) { $hosts_ls{$host}[0] = $ipaddrs_ls{$ipaddr}[0]; $hosts_ls{$host}[1] = $ipaddrs_ls{$ipaddr}[1]; $hosts_ls{$host}[2] = $ipaddrs_ls{$ipaddr}[2]; $hosts_ls{$host}[3] = $ipaddrs_ls{$ipaddr}[3]; $hosts_ls{$host}[4] = $ipaddrs_ls{$ipaddr}[4]; } elsif ($hosts_ls{$host}[0] >= $ipaddrs_ls{$ipaddr}[0]) { $hosttime = $hosts_ls{$host}[1]*60*60 + $hosts_ls{$host}[2]*60 + $hosts_ls{$host}[3]; $iptime = $ipaddrs_ls{$ipaddr}[1]*60*60 + $ipaddrs_ls{$ipaddr}[2]*60 + $ipaddrs_ls{$ipaddr}[3]; if ($hosts_ls{$host}[0] > $ipaddrs_ls{$ipaddr}[0] || $hosttime < $iptime) { $hosts_ls{$host}[0] = $ipaddrs_ls{$ipaddr}[0]; $hosts_ls{$host}[1] = $ipaddrs_ls{$ipaddr}[1]; $hosts_ls{$host}[2] = $ipaddrs_ls{$ipaddr}[2]; $hosts_ls{$host}[3] = $ipaddrs_ls{$ipaddr}[3]; $hosts_ls{$host}[4] = $ipaddrs_ls{$ipaddr}[4]; } } } &debugln("Exiting resolve_hosts() ..."); } # resolve_hosts #----------------------------------------------------------------------------- # # Read cached hostnames and resolve and cache any new ip addresses. # #----------------------------------------------------------------------------- sub read_host_cache { &debugln("Entering read_host_cache() ..."); my $count; # Read the cache file and save the hosts currently being used. if (-r $appdir . $userprefs{"cachefile"}) { &debugln("Reading DNS cache file $appdir" . $userprefs{"cachefile"} . " ..."); $count = 0; open(CACHEFILE, $appdir . $userprefs{"cachefile"}); while (defined($entry = )) { $count += 1; # Trim off the fat and convert to lowercase chomp($entry); $entry =~ tr/A-Z/a-z/; # Format of the cache file: "HostIP, Host, LastUpdated" ($ipaddr, $host, $updated) = split(/,/, $entry); # Determine if address is cached and use it if so. if (defined($ipaddrs{$ipaddr})) { ($cache_year, $cache_mon, $cache_mday) = split(/\//, $updated); ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($userprefs{"cachedays"} - 1) * (60*60*24)); # Determine if cached copy needs to be refreshed. if (int($cache_year.$cache_mon.$cache_mday) < int($year.$mon.$mday)) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); &debugln("Looking up $ipaddr ..."); $host = gethostbyaddr((pack "C4", split(/\./, $ipaddr)), 2); if (!defined($host)) { $host = $ipaddr; } $host =~ tr/A-Z/a-z/; $updated = $year."/".$mon."/".$mday; } $host_cache{$ipaddr} = $host; $update_cache{$ipaddr} = $updated; } } close CACHEFILE; &debugln("Read $count host cache entries ..."); } else { &debugln("No DNS cache file found, this could take several minutes ..."); } # Lookup new ips that are not in the cache. foreach $ipaddr (keys %ipaddrs) { if (!defined($host_cache{$ipaddr})) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); &debugln("Looking up $ipaddr ..."); $host = gethostbyaddr((pack "C4", split(/\./, $ipaddr)), 2); if (!defined($host)) { $host = $ipaddr; } $host =~ tr/A-Z/a-z/; $host_cache{$ipaddr} = $host; $update_cache{$ipaddr} = $year."/".$mon."/".$mday; } } # Save the new cache back to file. &debugln("Writing DNS cache file $appdir" . $userprefs{"cachefile"} . " ..."); $count = 0; open(CACHEFILE, ">$appdir" . $userprefs{"cachefile"}) or die "Personal Proxy Statistics : Cannot open $appdir" . $userprefs{"cachefile"} . " ($!)\n"; foreach $ipaddr (keys %ipaddrs) { $count += 1; $line = $ipaddr.",".$host_cache{$ipaddr}.",".$update_cache{$ipaddr}."\n"; print CACHEFILE $line; } close CACHEFILE; &debugln("Wrote $count host cache entries ..."); &debugln("Exiting read_host_cache() ..."); } # read_host_cache #----------------------------------------------------------------------------- # # Count number of records in each category and record rank displacement. # #----------------------------------------------------------------------------- sub lookup_rank { &debugln("Entering lookup_rank() ..."); my $y; # Save count and yesterdays rank for email addresses. $numemail = 0; foreach $email (keys %emails) { $numemail += 1; $emails_by{$email} = $emails{$email}[0]; for ($y = 1; $y <= $userprefs{"movementdays"}; $y++) { $emails_by{$email} -= (defined($emails{$email}[$y]) ? $emails{$email}[$y] : 0); } } $count = 0; foreach $email (sort { $emails_by{$b} <=> $emails_by{$a} || $a cmp $b } keys %emails_by) { $count += 1; if ($emails_by{$email} == 0) { $emails_ry{$email} = 0; } else { $emails_ry{$email} = $count; } } # Save count and yesterdays rank for host names. if ($userprefs{"showbyhost"}) { $numipaddr = 0; foreach $ipaddr (keys %ipaddrs) { $numipaddr += 1; } $numhost = 0; foreach $host (keys %hosts) { $numhost += 1; $hosts_by{$host} = $hosts{$host}[0]; for ($y = 1; $y <= $userprefs{"movementdays"}; $y++) { $hosts_by{$host} -= (defined($hosts{$host}[$y]) ? $hosts{$host}[$y] : 0); } } $count = 0; foreach $host (sort { $hosts_by{$b} <=> $hosts_by{$a} || $a cmp $b } keys %hosts_by) { $count += 1; if ($hosts_by{$host} == 0) { $hosts_ry{$host} = 0; } else { $hosts_ry{$host} = $count; } } } # Save count and yesterdays rank for operating systems. $numos = 0; foreach $os (keys %oss) { $numos += 1; $oss_by{$os} = $oss{$os}[0]; for ($y = 1; $y <= $userprefs{"movementdays"}; $y++) { $oss_by{$os} -= (defined($oss{$os}[$y]) ? $oss{$os}[$y] : 0); } } $count = 0; foreach $os (sort { $oss_by{$b} <=> $oss_by{$a} || $a <=> $b } keys %oss_by) { $count += 1; if ($oss_by{$os} == 0) { $oss_ry{$os} = 0; } else { $oss_ry{$os} = $count; } } # Save count and yesterdays rank for CPU types. $numcpu = 0; foreach $cpu (keys %cpus) { $numcpu += 1; $cpus_by{$cpu} = $cpus{$cpu}[0]; for ($y = 1; $y <= $userprefs{"movementdays"}; $y++) { $cpus_by -= (defined($cpus{$cpu}[$y]) ? $cpus{$cpu}[$y] : 0); } } $count = 0; foreach $cpu (sort { $cpus_by{$b} <=> $cpus_by{$a} || $a <=> $b } keys %cpus_by) { $count += 1; if ($cpus_by{$cpu} == 0) { $cpus_ry{$cpu} = 0; } else { $cpus_ry{$cpu} = $count; } } # Save count and yesterdays rank for client version. $numver = 0; foreach $ver (keys %vers) { $numver += 1; $vers_by{$ver} = $vers{$ver}[0]; for ($y = 1; $y <= $userprefs{"movementdays"}; $y++) { $vers_by{$ver} -= (defined($vers{$ver}[$y]) ? $vers{$ver}[$y] : 0); } } $count = 0; foreach $ver (sort { $vers_by{$b} <=> $vers_by{$a} || $a <=> $b } keys %vers_by) { $count += 1; if ($vers_by{$ver} == 0) { $vers_ry{$ver} = 0; } else { $vers_ry{$ver} = $count; } } # Save count and yesterdays rank for full details. $numtm = 0; foreach $tm (keys %full) { $numtm += 1; $full_by{$tm} = $full{$tm}[0]; for ($y = 1; $y <= $userprefs{"movementdays"}; $y++) { $full_by{$tm} -= (defined($full{$tm}[$y]) ? $full{$tm}[$y] : 0); } } $count = 0; foreach $tm (sort { $full_by{$b} <=> $full_by{$a} || $a cmp $b } keys %full_by) { $count += 1; if ($full_by{$tm} == 0) { $full_ry{$tm} = 0; } else { $full_ry{$tm} = $count; } } # Save count and yesterdays rank for email address domains. $numdomain = 0; foreach $domain (keys %domains) { $numdomain += 1; $domains_by{$domain} = $domains{$domain}[0]; for ($y = 1; $y <= $userprefs{"movementdays"}; $y++) { $domains_by{$domain} -= (defined($domains{$domain}[$y]) ? $domains{$domain}[$y] : 0); } } $count = 0; foreach $domain (sort { $domains_by{$b} <=> $domains_by{$a} || $a cmp $b } keys %domains_by) { $count += 1; if ($domains_by{$domain} == 0) { $domains_ry{$domain} = 0; } else { $domains_ry{$domain} = $count; } } &debugln("Exiting lookup_rank() ..."); } # lookup_rank #----------------------------------------------------------------------------- # # Write the cascading style sheet file. # #----------------------------------------------------------------------------- sub write_css { &debugln("Entering write_css() ..."); open(OUTFILE, ">" . $userprefs{"htmldir"} . $userprefs{"css"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . $userprefs{"css"} . " ($!)\n"; print OUTFILE "BODY {\n", " font-family: " . $userprefs{"fontstyle"} . ";\n", " font-size: 10pt;\n", " color: #" . $userprefs{"textcolor"} . ";\n", " background: #" . $userprefs{"backgroundcolor"} . ";\n", "}\n\n"; print OUTFILE "P {\n", " font-family: " . $userprefs{"fontstyle"} . ";\n", " font-size: 10pt;\n", " color: #" . $userprefs{"textcolor"} . ";\n", "}\n\n"; print OUTFILE "TH {\n", " font-family: " . $userprefs{"fontstyle"} . ";\n", " font-size: 10pt;\n", " color: #" . $userprefs{"linkbartitlefontcolor"} . ";\n", "}\n\n"; print OUTFILE "TD {\n", " font-family: " . $userprefs{"fontstyle"} . ";\n", " font-size: 10pt;\n", " color: #" . $userprefs{"textcolor"} . ";\n", "}\n\n"; print OUTFILE "TD.section {\n", " color: #" . $userprefs{"sectiontitlefontcolor"} . ";\n", " background: #" . $userprefs{"sectiontitlebarcolor"} . ";\n", "}\n\n"; print OUTFILE "TD.linkbar {\n", " background: #" . $userprefs{"linkbarcolor"} . ";\n", "}\n\n"; print OUTFILE "TD.title {\n", " font-size: 12pt;\n", " color: #" . $userprefs{"sectiontitlefontcolor"} . ";\n", " background: #" . $userprefs{"sectiontitlebarcolor"} . ";\n", "}\n\n"; print OUTFILE "TD.subtitle {\n", " font-size: 12pt;\n", " color: #" . $userprefs{"linkbartitlefontcolor"} . ";\n", "}\n\n"; print OUTFILE "TD.note { color: #" . $userprefs{"sectionnotefontcolor"} . "; }\n\n"; print OUTFILE "TD.history { background: #" . $userprefs{"historycolor"} . "; }\n\n"; print OUTFILE "TD.normal { color: #" . $userprefs{"textcolor"} . "; }\n\n"; print OUTFILE "TD.warning { color: #" . $userprefs{"lastseenwarningcolor"} . "; }\n\n"; print OUTFILE "TD.critical { color: #" . $userprefs{"lastseencriticalcolor"} . "; }\n\n"; print OUTFILE "TR.odd { background: #" . $userprefs{"sectionlowlightcolor"} . "; }\n\n"; print OUTFILE "TR.even { background: #" . $userprefs{"sectionhighlightcolor"} . "; }\n\n"; print OUTFILE "SPAN.moveup { color: #" . $userprefs{"moveupcolor"} . "; }\n\n"; print OUTFILE "SPAN.movedown { color: #" . $userprefs{"movedowncolor"} . "; }\n\n"; print OUTFILE "A:link {\n", " color: #" . $userprefs{"linkcolor"} . ";\n", " text-decoration: none;\n", "}\n\n"; print OUTFILE "A:active {\n", " color: #" . $userprefs{"activelinkcolor"} . ";\n", " text-decoration: none;\n", "}\n\n"; print OUTFILE "A:visited {\n", " color: #" . $userprefs{"visitedlinkcolor"} . ";\n", " text-decoration: none;\n", "}\n\n"; print OUTFILE "A:hover {\n", " color: #" . $userprefs{"activelinkcolor"} . ";\n", "}\n\n"; close OUTFILE; &debugln("Exiting write_css() ..."); } # write_css #----------------------------------------------------------------------------- # # Write main team stats page. # #----------------------------------------------------------------------------- sub write_index { &debugln("Entering write_index() ..."); for ($y = $userprefs{"dayshist"}; $y > 0; $y--) { $blocks[$y] = defined($blocks[$y]) ? $blocks[$y] : 0; } open(OUTFILE, ">" . $userprefs{"htmldir"} . $userprefs{"htmlteam"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . $userprefs{"htmlteam"} . " ($!)\n"; &write_header(); print OUTFILE " \n"; print OUTFILE " \n"; for ($y = $userprefs{"dayshist"} - 1; $y > 1; $y--) { ($year, $month, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - $y * (24*60*60)); print OUTFILE " \n"; } if ($userprefs{"dayshist"} > 1) { print OUTFILE " \n", } if ($userprefs{"dayshist"} > 0) { print OUTFILE " \n"; } print OUTFILE " \n", " \n"; print OUTFILE " \n"; for ($y = $userprefs{"dayshist"}; $y > 0; $y--) { print OUTFILE " \n"; } print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n"; # Print out day history list for all days before today for ($y = $userprefs{"dayshist"}; $y > 1; $y--) { $rate = &ratef(&rate_day($blocks[$y])); print OUTFILE " \n"; } # Print out day history list for today if (($day - 1) <= 0) { $rate = 0; } else { $rate = &rate_day($blocks[1]) / ($secs_today / (60*60*24)); } if ($userprefs{"dayshist"} > 0) { $rate = &ratef($rate); print OUTFILE " \n"; } $prev_daysworking = $day - $prev_lastday; $totaldays = $day - $lastblockday; # Blocks done today do not count towards the average if ($lastblockday == 1) { if ($totaldays == 1) { $averate = 0; $aveblocks = 0; } else { $averate = &rate_day($blocks[0] - $blocks[1]) / $prev_daysworking; $aveblocks = int(($blocks[0] - $blocks[1]) / $prev_daysworking); } } else { $averate = &rate_day($blocks[0]) / $totaldays; $aveblocks = int($blocks[0] / $totaldays); } # Print out total for day history list $averatef = &ratef($averate); print OUTFILE " \n"; print OUTFILE " \n"; $colsp = 1 + $userprefs{"dayshist"}; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n"; print OUTFILE "
Blocks
$days[$wday]
Blocks
Yesterday
Blocks
Today
Blocks
Total
$blocks[$y]$blocks[0]
${rate}k/s${rate}k/s${averatef}k/s
\n", "  \n", "
\n", " Graphical Team History for $contestname
\n", " Rate (kkeys/sec) by Day of Month\n", "
\n", "
Totals Days: $totaldays days - Average Blocks: $aveblocks blocks - Average Rate: ${averatef}keys/sec\n", "
\n", "  \n", "
\n", " \""\n", "
\n", "  \n", "
\n", " For past days: Mkeys/sec = $blockweight * blocks / 322
\n", " For today: Mkeys/sec = ($blockweight * blocks / 322) / (seconds today / (60*60*24))\n", "
\n"; &write_footer(); close OUTFILE; open(GNUPLOTDATA, ">" . $userprefs{"htmldir"} . $userprefs{"gnuplotdata"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . $userprefs{"gnuplotdata"} . " ($!)\n"; # Write out data file in format "Date, Rate". &clear_nday_ave(); for ($x = $day - 1; $x > 1; $x--) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($x - 1) * (24*60*60)); $rate = sprintf("%.2f", &rate_day($blocks[$x])); $line = "$year/$mon/$mday $rate"; &push_nday_ave($rate); $rate = &calc_nday_ave(); $line .= " $rate"; print GNUPLOTDATA "$line\n"; } ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $rate = sprintf("%.2f", &rate_day($blocks[1]) / ($secs_today / (60*60*24))); $line = "$year/$mon/$mday $rate"; &push_nday_ave($rate); $rate = &calc_nday_ave(); $line .= " $rate"; print GNUPLOTDATA "$line\n"; close GNUPLOTDATA; ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin + (24*60*60)); $lastday = "$year/$mon/$mday"; ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($day - 1) * (24*60*60)); $firstday = "$year/$mon/$mday"; if ($blocks[0] == 0) { $range = 1; } else { $range = "*"; } &plot_gui_graph($userprefs{"htmldir"}, "History Plot for $contestname\\nTeam " . $userprefs{"team"}, $firstday, $lastday, $range, $averate); &debugln("Exiting write_index() ..."); } # write_index #----------------------------------------------------------------------------- # # Write Executive Team Summary. # #----------------------------------------------------------------------------- sub write_exec { &debugln("Entering write_exec() ..."); if ($day == 1) { $firstblockdate = "No Blocks Submitted"; } else { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - (($day - 2) * (60*60*24))); $firstblockdate = "$mday $months[$mon-1] $year GMT"; } if ($lastblockday == 0) { $lastblockdate = "No Blocks Submitted"; } else { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - (($lastblockday - 1) * (60*60*24))); $lastblockdate = "$mday $months[$mon-1] $year GMT"; } $prev_daysworking = $day - $prev_lastday; $totaldays = $day - $lastblockday; # Print out the Last Seen column. if ($lastblockday == 0) { $lastseen = "No Blocks Submitted"; $lastseencolor = $userprefs{"textcolor"}; } else { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $lastseentime = $team_ls[0]*24*60*60 + ($hour - $team_ls[1])*60*60 + ($min - $team_ls[2])*60 + $sec - $team_ls[3]; $lastseen = &ls($lastseentime); $lastseencolor = &ls_color($lastseentime); } # Blocks done today do not count towards the average if ($lastblockday == 1) { if ($totaldays == 1) { $rate = &ratef(0); $aveblocks = 0; } else { $rate = &ratef(&rate_day($blocks[0] - $blocks[1]) / $prev_daysworking); $aveblocks = int(($blocks[0] - $blocks[1]) / $prev_daysworking); } } else { $rate = &ratef(&rate_day($blocks[0]) / $totaldays); $aveblocks = int($blocks[0] / $totaldays); } $rateyesterday = &ratef(&rate_day($blocks[2])); $blocksyesterday = defined($blocks[2]) ? $blocks[2] : 0; $totalblocks = defined($blocks[0]) ? $blocks[0] : 0; $contestblocks = &get_contest_blocks(); $keyschecked = &keysf($totalblocks); $percentcomplete = &percentf($totalblocks, 6); open(OUTFILE, ">" . $userprefs{"htmldir"} . $userprefs{"htmlexec"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . $userprefs{"htmlexec"} . " ($!)\n"; &write_header(); print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; if ($blocksyesterday == 0) { print OUTFILE " \n", " \n", " \n"; } else { $percentcomplete = &percentf($blocksyesterday, 8); print OUTFILE " \n", " \n", " \n"; } print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE "
\n", " Team " . $userprefs{"team"} . "
\n", " Executive Team Summary\n", "
\n", "  \n", "
\n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; if ($userprefs{"showbyhost"}) { print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; } print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE "
\n", " Team Summary for " . $userprefs{"team"} . "\n", "
\n", " Total Blocks to Search\n", " \n", " $contestblocks blocks\n", "
\n", " Total Blocks Checked\n", " \n", " $totalblocks blocks\n", "
\n", " Keyspace Exhausted\n", " \n", " $percentcomplete%\n", "
\n", " Total Keys Checked\n", " \n", " $keyschecked\n", "
\n", " Total Participants\n", " \n", " $numemail\n", "
\n", " Total Unique IPs\n", " \n", " $numipaddr\n", "
\n", " Total Hosts\n", " \n", " $numhost\n", "
\n", " Total Operating Systems\n", " \n", " $numos\n", "
\n", " Total CPUs\n", " \n", " $numcpu\n", "
\n", " Total Client Versions\n", " \n", " $numver\n", "
\n", " Total Email Domains\n", " \n", " $numdomain\n", "
\n", " Time Working\n", " \n", " $totaldays days\n", "
\n", " Last Seen\n", " \n", " $lastseen\n", "
\n", " First Block Submitted\n", " \n", " $firstblockdate\n", "
\n", " Last Block Submitted\n", " \n", " $lastblockdate\n", "
\n", " Overall Rate\n", " \n", " ${rate}keys/sec\n", "
\n", " Average Blocks\n", " \n", " $aveblocks per day\n", "
\n", " Distributed.Net Rank\n", " \n", " " . $userprefs{"team"} . "\n", "
\n", "
\n", "  \n", "
\n", " No one submitted any blocks yesterday, someone needs to get cracking!\n", "
\n", " $blocksyesterday blocks were completed yesterday ($percentcomplete% of the keyspace)
at a sustained rate of ${rateyesterday}keys/sec!\n", "
\n", "  \n", "
\n", " Team History for the Last " . $userprefs{"blockhistory"} . " Days\n", "
\n", "  \n", "
\n", " \n"; print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n"; for ($x = 1; $x <= $userprefs{"blockhistory"}; $x++) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($x - 1) * (24*60*60)); $blockdate = "$mday $months[$mon-1] $year GMT"; $blocks[$x] = defined($blocks[$x]) ? $blocks[$x] : 0; if ($x == 1) { $rate = &ratef(&rate_day($blocks[1]) / ($secs_today / (60*60*24))); } else { $rate = &ratef(&rate_day($blocks[$x])); } $keyschecked = &keysf($blocks[$x]); $percentcomplete = &percentf($blocks[$x], 8); if ($x % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n"; } print OUTFILE "
\n", " Day History\n", " \n", " Blocks Submitted\n", " \n", " Keys Checked\n", " \n", " Key Rate\n", " \n", " Keyspace\n", "
\n", " $blockdate\n", " \n", " $blocks[$x] blocks\n", " \n", " $keyschecked\n", " \n", " ${rate}k/s\n", " \n", " $percentcomplete%\n", "
\n", "
\n"; &write_footer(); close OUTFILE; &debugln("Exiting write_exec() ..."); } # write_exec #----------------------------------------------------------------------------- # # Write stats ordered by email. # #----------------------------------------------------------------------------- sub write_byemail { &debugln("Entering write_byemail() ..."); my $count = 0; my $pagecount = 1; my $msg; my $displacement; my $y; my $lastseen; my $lastseentime; my $lastseencolor; &write_section_header("", "Email Address", $userprefs{"htmlmail"}); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } foreach $email (sort { $emails{$b}[0] <=> $emails{$a}[0] || $a cmp $b } keys %emails) { $count += 1; # Start a new file if maxinum number of rows has been reached. if ($count > $userprefs{"maxrows"} * $pagecount) { &write_section_footer($pagecount, $numemail, 0, $userprefs{"htmlmail"}, "Please click on the \"@\" symbol for detailed participant information."); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } $pagecount += 1; &write_section_header($pagecount, "Email Address", $userprefs{"htmlmail"}); } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $emails{$email}[$y] = defined($emails{$email}[$y]) ? $emails{$email}[$y] : 0; } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $pageblocks[$y] += defined($emails{$email}[$y]) ? $emails{$email}[$y] : 0; } $pageblocks[0] += defined($emails{$email}[0]) ? $emails{$email}[0] : 0; if ($count % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } # Print out the Rank and Movement column. $displacement = $emails_ry{$email} == 0 ? $numemail - $count : $emails_ry{$email} - $count; $msg = &create_move_msg($displacement); print OUTFILE "  $count$msg\n"; $domain = undef; if ($email =~ /\.(\w+)$/) { $domain = $1; } if (defined($domain) && defined($country{$domain})) { $label = $country{$domain}; if (-e $userprefs{"htmldir"} . $userprefs{"icondir"} . "flags/$domain.gif") { $icon = "$domain.gif"; } else { $icon = "unknown.gif"; } } else { $label = "Unknown"; $icon = "unknown.gif"; } $emaildir = "e" . $count; ($head, $tail) = split(/@/, $email); if (!defined($head)) { $head = ""; } if (!defined($tail)) { $tail = ""; } print OUTFILE " \"$label\" $head\@$tail\n"; for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { if ($emails{$email}[$y] == 0) { print OUTFILE " -\n"; } else { print OUTFILE " $emails{$email}[$y]\n"; } } print OUTFILE " $emails{$email}[0]\n"; # Print out the Last Seen column. ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $lastseentime = $emails_ls{$email}[0]*24*60*60 + ($hour - $emails_ls{$email}[1])*60*60 + ($min - $emails_ls{$email}[2])*60 + $sec - $emails_ls{$email}[3]; $lastseen = &ls($lastseentime); $lastseencolor = &ls_color($lastseentime); print OUTFILE " $lastseen\n"; # Print out the Percent column. $percentofteam = sprintf("%.2f", 100 * $emails{$email}[0] / $blocks[0]); print OUTFILE " $percentofteam%\n", " \n"; } &write_section_footer($pagecount, $numemail, 0, $userprefs{"htmlmail"}, "Please click on the \"@\" symbol for detailed participant information."); &write_indvemail(); &debugln("Exiting write_byemail() ..."); } # write_byemail #----------------------------------------------------------------------------- # # Write stats ordered by host. # #----------------------------------------------------------------------------- sub write_byhost { &debugln("Entering write_byhost() ..."); my $count = 0; my $pagecount = 1; my $msg; my $displacement; my $y; my $lastseen; my $lastseentime; my $lastseencolor; &write_section_header("", "Hostname", $userprefs{"htmlhost"}); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } foreach $host (sort { $hosts{$b}[0] <=> $hosts{$a}[0] || $a cmp $b } keys %hosts) { $count += 1; # Start a new file if maxinum number of rows has been reached. if ($count > $userprefs{"maxrows"} * $pagecount) { &write_section_footer($pagecount, $numhost, 0, $userprefs{"htmlhost"}, "Please click on the highest level domain name for detailed host information."); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } $pagecount += 1; &write_section_header($pagecount, "Hostname", $userprefs{"htmlhost"}); } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $hosts{$host}[$y] = defined($hosts{$host}[$y]) ? $hosts{$host}[$y] : 0; } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $pageblocks[$y] += defined($hosts{$host}[$y]) ? $hosts{$host}[$y] : 0; } $pageblocks[0] += defined($hosts{$host}[0]) ? $hosts{$host}[0] : 0; if ($count % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } # Print out the Rank and Movement column. $displacement = $hosts_ry{$host} == 0 ? $numhost - $count : $hosts_ry{$host} - $count; $msg = &create_move_msg($displacement); print OUTFILE "  $count$msg\n"; $domain = undef; if ($host =~ /\.(\w+)$/) { $domain = $1; } if (defined($domain) && defined($country{$domain})) { $label = $country{$domain}; if (-e $userprefs{"htmldir"} . $userprefs{"icondir"} . "flags/$domain.gif") { $icon = "$domain.gif"; } else { $icon = "unknown.gif"; } } else { $label = "Unknown"; $icon = "unknown.gif"; } $hostdir = "h" . $count; ($head, $tail) = split /\./, $host, 2; if (defined($tail)) { $hostlink = "$head.$tail"; } else { $hostlink = "$head"; } print OUTFILE " \"$label\" $hostlink\n"; for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { if ($hosts{$host}[$y] == 0) { print OUTFILE " -\n"; } else { print OUTFILE " $hosts{$host}[$y]\n"; } } print OUTFILE " $hosts{$host}[0]\n"; # Print out the Last Seen column. ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $lastseentime = $hosts_ls{$host}[0]*24*60*60 + ($hour - $hosts_ls{$host}[1])*60*60 + ($min - $hosts_ls{$host}[2])*60 + $sec - $hosts_ls{$host}[3]; $lastseen = &ls($lastseentime); $lastseencolor = &ls_color($lastseentime); print OUTFILE " $lastseen\n"; # Print out the Percent column. $percentofteam = sprintf("%.2f", 100 * $hosts{$host}[0] / $blocks[0]); print OUTFILE " $percentofteam%\n", " \n"; } &write_section_footer($pagecount, $numhost, 0, $userprefs{"htmlhost"}, "Please click on the highest level domain name for detailed host information."); &write_indvhost(); &debugln("Exiting write_byhost() ..."); } # write_byhost #----------------------------------------------------------------------------- # # Write stats ordered by OS. # #----------------------------------------------------------------------------- sub write_byos { &debugln("Entering write_byos() ..."); my $count = 0; my $pagecount = 1; my $msg; my $displacement; my $y; my $lastseen; my $lastseentime; my $lastseencolor; &write_section_header("", "Operating System", $userprefs{"htmlos"}); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } foreach $os (sort { $oss{$b}[0] <=> $oss{$a}[0] || $a <=> $b } keys %oss) { $count += 1; # Start a new file if maxinum number of rows has been reached. if ($count > $userprefs{"maxrows"} * $pagecount) { &write_section_footer($pagecount, $numos, 0, $userprefs{"htmlos"}, ""); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } $pagecount += 1; &write_section_header($pagecount, "Operating System", $userprefs{"htmlos"}); } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $oss{$os}[$y] = defined($oss{$os}[$y]) ? $oss{$os}[$y] : 0; } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $pageblocks[$y] += defined($oss{$os}[$y]) ? $oss{$os}[$y] : 0; } $pageblocks[0] += defined($oss{$os}[0]) ? $oss{$os}[0] : 0; if ($count % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } # Print out the Rank and Movement column. $displacement = $oss_ry{$os} == 0 ? $numos - $count : $oss_ry{$os} - $count; $msg = &create_move_msg($displacement); print OUTFILE "  $count$msg\n"; if (defined($osiconid[$os])) { $icon = $osiconid[$os]; } else { $icon = "unknown.gif"; } if (defined($osid[$os])) { $label = $osid[$os]; } else { $label = "Unknown"; } print OUTFILE " \"$label\" $label\n"; for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { if ($oss{$os}[$y] == 0) { print OUTFILE " -\n"; } else { print OUTFILE " $oss{$os}[$y]\n"; } } print OUTFILE " $oss{$os}[0]\n"; # Print out the Last Seen column. ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $lastseentime = $oss_ls{$os}[0]*24*60*60 + ($hour - $oss_ls{$os}[1])*60*60 + ($min - $oss_ls{$os}[2])*60 + $sec - $oss_ls{$os}[3]; $lastseen = &ls($lastseentime); $lastseencolor = &ls_color($lastseentime); print OUTFILE " $lastseen\n"; # Print out the Percent column. $percentofteam = sprintf("%.2f", 100 * $oss{$os}[0] / $blocks[0]); print OUTFILE " $percentofteam%\n", " \n"; } &write_section_footer($pagecount, $numos, 0, $userprefs{"htmlos"}, ""); &debugln("Exiting write_byos() ..."); } # write_byos #----------------------------------------------------------------------------- # # Write stats ordered by CPU. # #----------------------------------------------------------------------------- sub write_bycpu { &debugln("Entering write_bycpu() ..."); my $count = 0; my $pagecount = 1; my $msg; my $displacement; my $y; my $lastseen; my $lastseentime; my $lastseencolor; &write_section_header("", "CPU Type", $userprefs{"htmlcpu"}); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } foreach $cpu (sort { $cpus{$b}[0] <=> $cpus{$a}[0] || $a <=> $b } keys %cpus) { $count += 1; # Start a new file if maxinum number of rows has been reached. if ($count > $userprefs{"maxrows"} * $pagecount) { &write_section_footer($pagecount, $numcpu, 0, $userprefs{"htmlcpu"}, ""); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } $pagecount += 1; &write_section_header($pagecount, "CPU Type", $userprefs{"htmlcpu"}); } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $cpus{$cpu}[$y] = defined($cpus{$cpu}[$y]) ? $cpus{$cpu}[$y] : 0; } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $pageblocks[$y] += defined($cpus{$cpu}[$y]) ? $cpus{$cpu}[$y] : 0; } $pageblocks[0] += defined($cpus{$cpu}[0]) ? $cpus{$cpu}[0] : 0; if ($count % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } # Print out the Rank and Movement column. $displacement = $cpus_ry{$cpu} == 0 ? $numcpu - $count : $cpus_ry{$cpu} - $count; $msg = &create_move_msg($displacement); print OUTFILE "  $count$msg\n"; if (defined($cpuiconid[$cpu])) { $icon = $cpuiconid[$cpu]; } else { $icon = "unknown.gif"; } if (defined($cpuid[$cpu])) { $label = $cpuid[$cpu]; } else { $label = "Unknown"; } print OUTFILE " \"$label\" $label\n"; for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { if ($cpus{$cpu}[$y] == 0) { print OUTFILE " -\n"; } else { print OUTFILE " $cpus{$cpu}[$y]\n"; } } print OUTFILE " $cpus{$cpu}[0]\n"; # Print out the Last Seen column. ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $lastseentime = $cpus_ls{$cpu}[0]*24*60*60 + ($hour - $cpus_ls{$cpu}[1])*60*60 + ($min - $cpus_ls{$cpu}[2])*60 + $sec - $cpus_ls{$cpu}[3]; $lastseen = &ls($lastseentime); $lastseencolor = &ls_color($lastseentime); print OUTFILE " $lastseen\n"; # Print out the Percent column. $percentofteam = sprintf("%.2f", 100 * $cpus{$cpu}[0] / $blocks[0]); print OUTFILE " $percentofteam%\n", " \n"; } &write_section_footer($pagecount, $numcpu, 0, $userprefs{"htmlcpu"}, ""); &debugln("Exiting write_bycpu() ..."); } # write_bycpu #----------------------------------------------------------------------------- # # Write stats ordered by Client Version. # #----------------------------------------------------------------------------- sub write_byver { &debugln("Entering write_byver() ..."); my $count = 0; my $pagecount = 1; my $msg; my $displacement; my $y; my $lastseen; my $lastseentime; my $lastseencolor; &write_section_header("", "Client Version", $userprefs{"htmlver"}); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } foreach $ver (sort { $vers{$b}[0] <=> $vers{$a}[0] || $a <=> $b } keys %vers) { $count += 1; # Start a new file if maxinum number of rows has been reached. if ($count > $userprefs{"maxrows"} * $pagecount) { &write_section_footer($pagecount, $numver, 0, $userprefs{"htmlver"}, ""); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } $pagecount += 1; &write_section_header($pagecount, "Client Version", $userprefs{"htmlver"}); } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $vers{$ver}[$y] = defined($vers{$ver}[$y]) ? $vers{$ver}[$y] : 0; } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $pageblocks[$y] += defined($vers{$ver}[$y]) ? $vers{$ver}[$y] : 0; } $pageblocks[0] += defined($vers{$ver}[0]) ? $vers{$ver}[0] : 0; if ($count % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } # Print out the Rank and Movement column. $displacement = $vers_ry{$ver} == 0 ? $numver - $count : $vers_ry{$ver} - $count; $msg = &create_move_msg($displacement); print OUTFILE "  $count$msg\n"; print OUTFILE " $ver\n"; for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { if ($vers{$ver}[$y] == 0) { print OUTFILE " -\n"; } else { print OUTFILE " $vers{$ver}[$y]\n"; } } print OUTFILE " $vers{$ver}[0]\n"; # Print out the Last Seen column. ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $lastseentime = $vers_ls{$ver}[0]*24*60*60 + ($hour - $vers_ls{$ver}[1])*60*60 + ($min - $vers_ls{$ver}[2])*60 + $sec - $vers_ls{$ver}[3]; $lastseen = &ls($lastseentime); $lastseencolor = &ls_color($lastseentime); print OUTFILE " $lastseen\n"; # Print out the Percent column. $percentofteam = sprintf("%.2f", 100 * $vers{$ver}[0] / $blocks[0]); print OUTFILE " $percentofteam%\n", " \n"; } &write_section_footer($pagecount, $numver, 0, $userprefs{"htmlver"}, ""); &debugln("Exiting write_byver() ..."); } # write_byver #----------------------------------------------------------------------------- # # Write stats ordered by OS, CPU, and Client Version. # #----------------------------------------------------------------------------- sub write_byfull { &debugln("Entering write_byfull() ..."); my $count = 0; my $pagecount = 1; my $msg; my $displacement; my $y; my $lastseen; my $lastseentime; my $lastseencolor; &write_section_header("", "Full Detail", $userprefs{"htmlfull"}); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } foreach $tm (sort { $full{$b}[0] <=> $full{$a}[0] || $a cmp $b } keys %full) { $count += 1; # Start a new file if maxinum number of rows has been reached. if ($count > $userprefs{"maxrows"} * $pagecount) { &write_section_footer($pagecount, $numtm, 0, $userprefs{"htmlfull"}, ""); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } $pagecount += 1; &write_section_header($pagecount, "Full Detail", $userprefs{"htmlfull"}); } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $full{$tm}[$y] = defined($full{$tm}[$y]) ? $full{$tm}[$y] : 0; } for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { $pageblocks[$y] += defined($full{$tm}[$y]) ? $full{$tm}[$y] : 0; } $pageblocks[0] += defined($full{$tm}[0]) ? $full{$tm}[0] : 0; if ($count % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } # Print out the Rank and Movement column. $displacement = $full_ry{$tm} == 0 ? $numtm - $count : $full_ry{$tm} - $count; $msg = &create_move_msg($displacement); print OUTFILE "  $count$msg\n"; if (defined($osiconid[$full_icon{$tm}[0]])) { $osicon = $osiconid[$full_icon{$tm}[0]]; } else { $osicon = "unknown.gif"; } if (defined($osid[$full_icon{$tm}[0]])) { $oslabel = $osid[$full_icon{$tm}[0]]; } else { $oslabel = "Unknown"; } if (defined($cpuiconid[$full_icon{$tm}[1]])) { $cpuicon = $cpuiconid[$full_icon{$tm}[1]]; } else { $cpuicon = "unknown.gif"; } if (defined($cpuid[$full_icon{$tm}[1]])) { $cpulabel = $cpuid[$full_icon{$tm}[1]]; } else { $cpulabel = "Unknown"; } print OUTFILE " \"$oslabel\" \"$cpulabel\" $tm\n"; for ($y = $userprefs{"dayshist"} - 3; $y > 0; $y--) { if ($full{$tm}[$y] == 0) { print OUTFILE " -\n"; } else { print OUTFILE " $full{$tm}[$y]\n"; } } print OUTFILE " $full{$tm}[0]\n"; # Print out the Last Seen column. ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $lastseentime = $full_ls{$tm}[0]*24*60*60 + ($hour - $full_ls{$tm}[1])*60*60 + ($min - $full_ls{$tm}[2])*60 + $sec - $full_ls{$tm}[3]; $lastseen = &ls($lastseentime); $lastseencolor = &ls_color($lastseentime); print OUTFILE " $lastseen\n"; # Print out the Percent column. $percentofteam = sprintf("%.2f", 100 * $full{$tm}[0] / $blocks[0]); print OUTFILE " $percentofteam%\n", " \n"; } &write_section_footer($pagecount, $numtm, 0, $userprefs{"htmlfull"}, ""); &debugln("Exiting write_byfull() ..."); } # write_byfull #----------------------------------------------------------------------------- # # Write header for By Domain section. # #----------------------------------------------------------------------------- sub write_bydomain_header { my $page = shift @_; my $y; open(OUTFILE, ">" . $userprefs{"htmldir"} . $page . $userprefs{"htmldomain"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . $page . $userprefs{"htmldomain"} . " ($!)\n"; &write_header(); print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; for ($y = $userprefs{"dayshist"} - 5; $y > 1; $y--) { ($year, $month, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - $y * (24*60*60)); print OUTFILE " \n"; } if ($userprefs{"dayshist"} - 4 > 1) { print OUTFILE " \n"; } if ($userprefs{"dayshist"} - 4 > 0) { print OUTFILE " \n"; } print OUTFILE " \n", " \n", " \n", " \n", " \n"; } # write_bydomain_header #----------------------------------------------------------------------------- # # Write stats ordered by Email Address Domain. # #----------------------------------------------------------------------------- sub write_bydomain { &debugln("Entering write_bydomain() ..."); my $count = 0; my $pagecount = 1; my $msg; my $displacement; my $y; my $lastseen; my $lastseentime; my $lastseencolor; &write_bydomain_header(""); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } foreach $domain (sort { $domains{$b}[0] <=> $domains{$a}[0] || $a cmp $b } keys %domains) { $count += 1; # Start a new file if maxinum number of rows has been reached. if ($count > $userprefs{"maxrows"} * $pagecount) { &write_section_footer($pagecount, $numdomain, 1, $userprefs{"htmldomain"}, ""); for ($y = $userprefs{"dayshist"}; $y >= 0; $y--) { $pageblocks[$y] = 0; } $pagecount += 1; &write_bydomain_header($pagecount); } for ($y = $userprefs{"dayshist"} - 4; $y > 0; $y--) { $domains{$domain}[$y] = defined($domains{$domain}[$y]) ? $domains{$domain}[$y] : 0; } for ($y = $userprefs{"dayshist"} - 4; $y > 0; $y--) { $pageblocks[$y] += defined($domains{$domain}[$y]) ? $domains{$domain}[$y] : 0; } $pageblocks[0] += defined($domains{$domain}[0]) ? $domains{$domain}[0] : 0; $numdomainemail = 0; foreach $email (keys %{$domain_count{$domain}}) { $numdomainemail += 1; } if ($count % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } # Print out the Rank and Movement column. $displacement = $domains_ry{$domain} == 0 ? $numdomain - $count : $domains_ry{$domain} - $count; $msg = &create_move_msg($displacement); print OUTFILE " \n"; if (defined($country{$domain})) { $label = $country{$domain}; if (-e $userprefs{"htmldir"} . $userprefs{"icondir"} . "flags/$domain.gif") { $icon = "$domain.gif"; } else { $icon = "unknown.gif"; } } else { $label = "Unknown"; $icon = "unknown.gif"; } print OUTFILE " \n"; for ($y = $userprefs{"dayshist"} - 4; $y > 0; $y--) { if ($domains{$domain}[$y] == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } } print OUTFILE " \n", " \n"; # Print out the Last Seen column. ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $lastseentime = $domains_ls{$domain}[0]*24*60*60 + ($hour - $domains_ls{$domain}[1])*60*60 + ($min - $domains_ls{$domain}[2])*60 + $sec - $domains_ls{$domain}[3]; $lastseen = &ls($lastseentime); $lastseencolor = &ls_color($lastseentime); print OUTFILE " \n"; # Print out the Percent column. $percentofteam = sprintf("%.2f", 100 * $domains{$domain}[0] / $blocks[0]); print OUTFILE " \n", " \n"; } &write_section_footer($pagecount, $numdomain, 1, $userprefs{"htmldomain"}, ""); &debugln("Exiting write_bydomain() ..."); } # write_bydomain #----------------------------------------------------------------------------- # # Write main team stats by hour of day. # #----------------------------------------------------------------------------- sub write_byhour { &debugln("Entering write_byhour() ..."); open(OUTFILE, ">" . $userprefs{"htmldir"} . $userprefs{"htmlhour"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . $userprefs{"htmlhour"} . " ($!)\n"; &write_header(); print OUTFILE "
RankEmail Address DomainBlocks
$days[$wday]
Blocks
Yesterday
Blocks
Today
Blocks
Total
Email
Count
Last
Seen
Percent
 $count$msg\"$label\" $label-$domains{$domain}[$y]$domains{$domain}[0]$numdomainemail$lastseen$percentofteam%
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n"; # Calculate best day of week $best = 0; for ($y = 0; $y < 24; $y++) { if ($hourofday[$y] > $best) { $best = $hourofday[$y]; } } # Calculate past rates and display rates. if ($day > 1) { for ($y = 0; $y < 24; $y++) { # $x = (($y - 1) % 12) + 1; $x = sprintf('%02d', $y); $clock = ($y % 12) + 1; if ($y < 12) { $ampm = "am"; } else { $ampm = "pm"; } if ($best == 0) { $width = 0; } else { $width = int($hourofday[$y] * 100 / $best); } $antiwidth = 100 - $width; if ($hourofday[$y] == 0) { $rate = &ratef(0); } else { $rate = &ratef(&rate_day(24 * $hourofday[$y]) / $day - 1); } # Print out the Percent column. $percentofteam = sprintf("%.2f", 100 * $hourofday[$y] / $blocks[0]); $line = " \n"; # $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; print OUTFILE "$line"; } } print OUTFILE "
Hour of Day GMT Blocks Graphical Rate in Blocks Key Rate Percent
\"$x:00$ampm-$x:59$ampm\" $x:00$ampm-$x:59$ampm\"$x:00 $x:00 - $x:59 $hourofday[$y] 
  
 ${rate}k/s $percentofteam%
\n"; &write_footer(); close OUTFILE; &debugln("Exiting write_byhour() ..."); } # write_byhour #----------------------------------------------------------------------------- # # Write main team stats by date. # #----------------------------------------------------------------------------- sub write_bydate { &debugln("Entering write_bydate() ..."); open(OUTFILE, ">" . $userprefs{"htmldir"} . $userprefs{"htmldate"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . $userprefs{"htmldate"} . " ($!)\n"; &write_header(); print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n"; # Calculate best day $best = 0; for ($y = 2; $y < $day; $y++) { if ($blocks[$y] > $best) { $best = $blocks[$y]; } } # Calculate past rates for ($y = 2; $y < $day; $y++) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($y - 1) * (24*60*60)); $blocks[$y] = $blocks[$y]; if ($best == 0) { $width = 0; } else { $width = int($blocks[$y] * 100 / $best); } $antiwidth = 100 - $width; $rate = &ratef(&rate_day($blocks[$y])); $line = " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; print OUTFILE "$line"; } print OUTFILE "
Date Blocks Graphical Rate in Blocks Key Rate
$mday $months[$mon-1] $year GMT $blocks[$y] 
  
 ${rate}k/s
\n"; &write_footer(); close OUTFILE; &debugln("Exiting write_bydate() ..."); } # write_bydate #----------------------------------------------------------------------------- # # Write main team stats by week. # #----------------------------------------------------------------------------- sub write_byweek { &debugln("Entering write_byweek() ..."); open(OUTFILE, ">" . $userprefs{"htmldir"} . $userprefs{"htmlweek"}) or die "Personal Proxy Statistics : Cannot open " . $userpefs{"htmldir"} . $userpefs{"htmlweek"} . " ($!)\n"; &write_header(); print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n"; # Calculate best week $best = 0; $numblocks = 0; for ($y = 2; $y < $day; $y++) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($y - 1) * (24*60*60)); if ($wday == 6) { if ($numblocks > $best) { $best = $numblocks; } $numblocks = 0; } $numblocks += $blocks[$y]; } if ($numblocks > $best) { $best = $numblocks; } ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - 1 * (24*60*60)); ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - (1 + $wday) * (24*60*60)); $prev = $mday . " " . $months[$mon-1] . " " . $year; $numblocks = 0; $numdays = 0; # Calculate past rates for ($y = 2; $y < $day; $y++) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($y - 1) * (24*60*60)); ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($y - 1 + $wday) * (24*60*60)); $curr = $mday . " " . $months[$mon-1] . " " . $year; if ($curr ne $prev) { $width = int($numblocks * 100 / $best); $antiwidth = 100 - $width; $rate = &ratef(&rate_day($numblocks) / $numdays); $line = " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; print OUTFILE "$line"; $prev = $mday . " " . $months[$mon-1] . " " . $year; $numblocks = 0; $numdays = 0; } $numblocks += $blocks[$y]; $numdays += 1; } if ($day > 2) { if ($best == 0) { $width = 100; } else { $width = int($numblocks * 100 / $best); } $antiwidth = 100 - $width; $rate = &ratef(&rate_day($numblocks) / $numdays); $line = " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; print OUTFILE "$line"; } print OUTFILE "
Week Blocks Graphical Rate in Blocks Key Rate
$prev GMT $numblocks 
  
 ${rate}k/s
$prev GMT $numblocks 
  
 ${rate}k/s
\n"; &write_footer(); close OUTFILE; &debugln("Exiting write_byweek() ..."); } # write_byweek #----------------------------------------------------------------------------- # # Write main team stats by month. # #----------------------------------------------------------------------------- sub write_bymonth { &debugln("Entering write_bymonth() ..."); open(OUTFILE, ">" . $userprefs{"htmldir"} . $userprefs{"htmlmonth"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . $userprefs{"htmlmonth"} . " ($!)\n"; &write_header(); print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n"; # Calculate best month ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - 1 * (24*60*60)); $prev = $months[$mon-1] . " " . $year; $numblocks = 0; $best = 0; for ($y = 2; $y < $day; $y++) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($y - 1) * (24*60*60)); $curr = $months[$mon-1] . " " . $year; if ($curr ne $prev) { if ($numblocks > $best) { $best = $numblocks; } $prev = $months[$mon-1] . " " . $year; $numblocks = 0; } $numblocks += $blocks[$y]; } if ($numblocks > $best) { $best = $numblocks; } ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - 1 * (24*60*60)); $prev = $months[$mon-1] . " " . $year; $numblocks = 0; $numdays = 0; # Calculate past rates for ($y = 2; $y < $day; $y++) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($y - 1) * (24*60*60)); $curr = $months[$mon-1] . " " . $year; if ($curr ne $prev) { $width = int($numblocks * 100 / $best); $antiwidth = 100 - $width; $rate = &ratef(&rate_day($numblocks) / $numdays); $line = " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; print OUTFILE "$line"; $prev = $months[$mon-1] . " " . $year; $numblocks = 0; $numdays = 0; } $numblocks += $blocks[$y]; $numdays += 1; } if ($day > 2) { if ($best == 0) { $width = 100; } else { $width = int($numblocks * 100 / $best); } $antiwidth = 100 - $width; $rate = &ratef(&rate_day($numblocks) / $numdays); $line = " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; print OUTFILE "$line"; } print OUTFILE "
Month Days Blocks Graphical Rate in Blocks Key Rate
$prev GMT $numdays $numblocks 
  
 ${rate}k/s
$prev GMT $numdays $numblocks 
  
 ${rate}k/s
\n"; &write_footer(); close OUTFILE; &debugln("Exiting write_bymonth() ..."); } # write_bymonth #----------------------------------------------------------------------------- # # Write main team stats by year. # #----------------------------------------------------------------------------- sub write_byyear { &debugln("Entering write_byyear() ..."); open(OUTFILE, ">" . $userprefs{"htmldir"} . $userprefs{"htmlyear"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . $userprefs{"htmlyear"} . " ($!)\n"; &write_header(); print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n"; # Calculate best year ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - 1 * (24*60*60)); $prev = $year; $numblocks = 0; $best = 0; for ($y = 2; $y < $day; $y++) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($y - 1) * (24*60*60)); if ($year ne $prev) { if ($numblocks > $best) { $best = $numblocks; } $prev = $year; $numblocks = 0; } $numblocks += $blocks[$y]; } if ($numblocks > $best) { $best = $numblocks; } ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - 1 * (24*60*60)); $prev = $year; $numblocks = 0; $numdays = 0; # Calculate past rates for ($y = 2; $y < $day; $y++) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($y - 1) * (24*60*60)); if ($year ne $prev) { $width = int($numblocks * 100 / $best); $antiwidth = 100 - $width; $rate = &ratef(&rate_day($numblocks) / $numdays); $line = " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; print OUTFILE "$line"; $prev = $year; $numblocks = 0; $numdays = 0; } $numblocks += $blocks[$y]; $numdays += 1; } if ($day > 2) { if ($best == 0) { $width = 100; } else { $width = int($numblocks * 100 / $best); } $antiwidth = 100 - $width; $rate = &ratef(&rate_day($numblocks) / $numdays); $line = " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; print OUTFILE "$line"; } print OUTFILE "
Year Days Blocks Graphical Rate in Blocks Key Rate
$prev GMT $numdays $numblocks 
  
 ${rate}k/s
$prev GMT $numdays $numblocks 
  
 ${rate}k/s
\n"; &write_footer(); close OUTFILE; &debugln("Exiting write_byyear() ..."); } # write_byyear #----------------------------------------------------------------------------- # # Write main team stats by day of week. # #----------------------------------------------------------------------------- sub write_bydayofweek { &debugln("Entering write_bydayofweek() ..."); open(OUTFILE, ">" . $userprefs{"htmldir"} . $userprefs{"htmldayofweek"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . $userprefs{"htmldayofweek"} . " ($!)\n"; &write_header(); print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n"; # Blocks done today do not count towards total ($year, $month, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $dayofweek[$wday] -= $blocks[1]; # Calculate best day of week $best = 0; for ($y = 0; $y < 7; $y++) { if ($dayofweek[$y] > $best) { $best = $dayofweek[$y]; } } # Yes, there are better algorithms for this for ($y = 0; $y < 7; $y++) { $numdays[$y] = 0; } for ($y = 2; $y < $day; $y++) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($y - 1) * (24*60*60)); $numdays[$wday] += 1; } # Calculate past rates, display only if there is at least one full day if ($day > 2) { for ($y = 0; $y < 7; $y++) { if ($best == 0) { $width = 0; } else { $width = int($dayofweek[$y] * 100 / $best); } $antiwidth = 100 - $width; if ($numdays[$y] == 0) { $rate = &ratef(0); } else { $rate = &ratef(&rate_day($dayofweek[$y]) / $numdays[$y]); } # Print out the Percent column. $percentofteam = sprintf("%.2f", 100 * $dayofweek[$y] / $blocks[0]); $line = " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; $line .= " \n"; print OUTFILE "$line"; } } print OUTFILE "
Day of Week Days Blocks Graphical Rate in Blocks Key Rate Percent
$days[$y] GMT $numdays[$y] $dayofweek[$y] 
  
 ${rate}k/s $percentofteam%
\n"; &write_footer(); close OUTFILE; &debugln("Exiting write_bydayofweek() ..."); } # write_bydayofweek #----------------------------------------------------------------------------- # # Routine to write individual email info. # #----------------------------------------------------------------------------- sub write_indvemail { my $count = 0; my $msg; my $displacement; foreach $email (sort { $emails{$b}[0] <=> $emails{$a}[0] || $a cmp $b } keys %emails) { $count += 1; # Print out the Rank and Movement column. $displacement = $emails_ry{$email} == 0 ? $numemail - $count : $emails_ry{$email} - $count; $msg = &create_move_msg($displacement); $daysworking = $emails_firstday{$email} - $emails_lastday{$email} + 1; $prev_daysworking = $emails_firstday{$email} - (defined($emails_prev_lastday{$email}) ? $emails_prev_lastday{$email} : 0) + 1; ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - (($emails_firstday{$email} - 1) * (60*60*24))); $firstblockdate = "$mday $months[$mon-1] $year GMT"; ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - (($emails_lastday{$email} - 1) * (60*60*24))); $lastblockdate = "$mday $months[$mon-1] $year GMT"; # Print out the Last Seen column. ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $lastseentime = $emails_ls{$email}[0]*24*60*60 + ($hour - $emails_ls{$email}[1])*60*60 + ($min - $emails_ls{$email}[2])*60 + $sec - $emails_ls{$email}[3]; $lastseen = &ls($lastseentime); $lastseencolor = &ls_color($lastseentime); # Blocks done today do not count towards the average. if ($emails_lastday{$email} == 1) { if ($daysworking == 1) { $rate = 0; $aveblocks = 0; } else { $rate = &rate_day($emails{$email}[0] - $emails{$email}[1]) / $prev_daysworking; $aveblocks = int(($emails{$email}[0] - $emails{$email}[1]) / $prev_daysworking); } } else { $rate = &rate_day($emails{$email}[0]) / $daysworking; $aveblocks = int($emails{$email}[0] / $daysworking); } $averate = $rate; $averatef = &ratef($rate); $rateyesterday = &ratef(&rate_day($emails{$email}[2])); $blocksyesterday = defined($emails{$email}[2]) ? $emails{$email}[2] : 0; $contestblocks = &get_contest_blocks(); $keyschecked = &keysf($emails{$email}[0]); $percentcomplete = &percentf($emails{$email}[0], 6); $percentofteam = sprintf("%.2f", 100 * $emails{$email}[0] / $blocks[0]); $domain = undef; if ($email =~ /\.(\w+)$/) { $domain = $1; } if (defined($domain) && defined($country{$domain})) { $label = $country{$domain}; if (-e $userprefs{"htmldir"} . $userprefs{"icondir"} . "flags/$domain.gif") { $icon = "$domain.gif"; } else { $icon = "unknown.gif"; } } else { $label = "Unknown"; $icon = "unknown.gif"; } $emaildir = "e" . $count; mkdir($userprefs{"htmldir"} . "$emaildir", 0755); open(OUTFILE, ">" . $userprefs{"htmldir"} . "$emaildir/" . $userprefs{"htmlindvemail"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . "$emaildir/" . $userprefs{"htmlindvemail"} . " ($!)\n"; &write_header(); print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; if ($blocksyesterday == 0) { print OUTFILE " \n", " \n", " \n"; } else { $percentcomplete = &percentf($blocksyesterday, 8); print OUTFILE " \n", " \n", " \n"; } print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; if ($userprefs{"showbyhost"}) { print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; } print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE "
\n", " Participant $email
\n", " Executive Participant Summary\n", "
\n", "  \n", "
\n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE "
\n", " Participant Summary for $email\n", "
\n", " Current Team Rank\n", " \n", " $count$msg\n", "
\n", " Percent of Team\n", " \n", " $percentofteam%\n", "
\n", " Total Blocks to Search\n", " \n", " $contestblocks blocks\n", "
\n", " Total Blocks Checked\n", " \n", " $emails{$email}[0] blocks\n", "
\n", " Keyspace Exhausted\n", " \n", " $percentcomplete%\n", "
\n", " Total Keys Checked\n", " \n", " $keyschecked\n", "
\n", " Time Working\n", " \n", " $daysworking days\n", "
\n", " Last Seen\n", " \n", " $lastseen\n", "
\n", " First Block Submitted\n", " \n", " $firstblockdate\n", "
\n", " Last Block Submitted\n", " \n", " $lastblockdate\n", "
\n", " Overall Rate\n", " \n", " ${averatef}keys/sec\n", "
\n", " Average Blocks\n", " \n", " $aveblocks per day\n", "
\n", " Distributed.Net Rank\n", " \n", " $email\n", "
\n", " Participant Domain\n", " \n", " $label \"$label\"\n", "
\n", "
\n", "  \n", "
\n", " This participant didn't submit any blocks yesterday, someone tell them to get cracking!\n", "
\n", " $blocksyesterday blocks were completed yesterday ($percentcomplete% of the keyspace)
at a sustained rate of ${rateyesterday}keys/sec!\n", "
\n", "  \n", "
\n", " Click here to goto the Graphical Participant History page.\n", "
\n", "  \n", "
\n", " Click here to goto the Hostnames working for this Participant page.\n", "
\n", "  \n", "
\n", " Participant History for the Last " . $userprefs{"blockhistory"} . " Days\n", "
\n", "  \n", "
\n", " \n"; print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n"; for ($x = 1; $x <= $userprefs{"blockhistory"}; $x++) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($x - 1) * (24*60*60)); $blockdate = "$mday $months[$mon-1] $year GMT"; $emails{$email}[$x] = defined($emails{$email}[$x]) ? $emails{$email}[$x] : 0; if ($blocks[$x] == 0) { $percentofteam = sprintf("%.2f", 0); } else { $percentofteam = sprintf("%.2f", 100 * $emails{$email}[$x] / $blocks[$x]); } if ($x == 1) { $rate = &ratef(&rate_day($emails{$email}[1]) / ($secs_today / (60*60*24))); } else { $rate = &ratef(&rate_day($emails{$email}[$x])); } $keyschecked = &keysf($emails{$email}[$x]); $percentcomplete = &percentf($emails{$email}[$x], 8); if ($x % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n"; } print OUTFILE "
\n", " Day History\n", " \n", " Blocks Submitted\n", " \n", " Percent\n", " \n", " Keys Checked\n", " \n", " Key Rate\n", " \n", " Keyspace\n", "
\n", " $blockdate\n", " \n", " $emails{$email}[$x] blocks\n", " \n", " $percentofteam%\n", " \n", " $keyschecked\n", " \n", " ${rate}k/s\n", " \n", " $percentcomplete%\n", "
\n", "
\n"; &write_footer(); close OUTFILE; &write_emailchart(); &write_hostsbyemail() if ($userprefs{"showbyhost"}); &debug("."); } &debugln("") if ($count > 0); } # write_indvemail #----------------------------------------------------------------------------- # # Routine to create the Graphical Participant History plot, write the GNUplot # config file and plot a chart for this Participant. # #----------------------------------------------------------------------------- sub write_emailchart { open(OUTFILE, ">" . $userprefs{"htmldir"} . "$emaildir/" . $userprefs{"htmlemailhist"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . "$emaildir/" . $userprefs{"htmlemailhist"} ." ($!)\n"; &write_header(); print OUTFILE " \n"; print OUTFILE " \n"; for ($y = $userprefs{"dayshist"} - 1; $y > 1; $y--) { ($year, $month, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - $y * (24*60*60)); print OUTFILE " \n"; } if ($userprefs{"dayshist"} > 1) { print OUTFILE " \n", } if ($userprefs{"dayshist"} > 0) { print OUTFILE " \n"; } print OUTFILE " \n", " \n"; print OUTFILE " \n"; for ($y = $userprefs{"dayshist"}; $y > 0; $y--) { $emails{$email}[$y] = defined($emails{$email}[$y]) ? $emails{$email}[$y] : 0; print OUTFILE " \n"; } print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n"; # Print out day history list for all days before today for ($y = $userprefs{"dayshist"}; $y > 1; $y--) { $rate = &ratef(&rate_day($emails{$email}[$y])); print OUTFILE " \n"; } # Print out day history list for today if (($day - 1) <= 0) { $rate = 0; } else { $rate = &rate_day($emails{$email}[1]) / ($secs_today / (60*60*24)); } if ($userprefs{"dayshist"} > 0) { $rate = &ratef($rate); print OUTFILE " \n"; } # Print out total for day history list print OUTFILE " \n"; print OUTFILE " \n"; $colsp = 1 + $userprefs{"dayshist"}; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; if ($userprefs{"showbyhost"}) { print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; } print OUTFILE "
Blocks
$days[$wday]
Blocks
Yesterday
Blocks
Today
Blocks
Total
$emails{$email}[$y]$emails{$email}[0]
${rate}k/s${rate}k/s${averatef}k/s
\n", "  \n", "
\n", " Participant $email
\n", " Graphical Participant History\n", "
\n", "
Totals Days: $daysworking days - Average Blocks: $aveblocks blocks - Average Rate: ${averatef}keys/sec\n", "
\n", "  \n", "
\n", " \"$email\"\n", "
\n", "  \n", "
\n", " For past days: Mkeys/sec = $blockweight * blocks / 322
\n", " For today: Mkeys/sec = ($blockweight * blocks / 322) / (seconds today / (60*60*24))\n", "
\n", "  \n", "
\n", " Click here to goto the Executive Participant Summary page.\n", "
\n", "  \n", "
\n", " Click here to goto the Hostnames working for this Participant page.\n", "
\n"; &write_footer(); close OUTFILE; open(GNUPLOTDATA, ">" . $userprefs{"htmldir"} . "$emaildir/" . $userprefs{"gnuplotdata"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . "$emaildir/" . $userprefs{"gnuplotdata"} . " ($!)\n"; # Write out data file in format "Date, Rate". &clear_nday_ave(); for ($x = $emails_firstday{$email}; $x >= $emails_lastday{$email}; $x--) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($x - 1) * (24*60*60)); $emails{$email}[$x] = defined($emails{$email}[$x]) ? $emails{$email}[$x] : 0; if ($x == 1) { $rate = sprintf("%.2f", &rate_day($emails{$email}[$x]) / ($secs_today / (60*60*24))); } else { $rate = sprintf("%.2f", &rate_day($emails{$email}[$x])); } $line = "$year/$mon/$mday $rate"; &push_nday_ave($rate); $rate = &calc_nday_ave(); $line .= " $rate"; print GNUPLOTDATA "$line\n"; } close GNUPLOTDATA; ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($emails_lastday{$email} - 2) * (24*60*60)); $lastday = "$year/$mon/$mday"; ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - $emails_firstday{$email} * (24*60*60)); $firstday = "$year/$mon/$mday"; &plot_gui_graph($userprefs{"htmldir"} . "$emaildir/", "History Plot for $contestname\\nParticipant $email", $firstday, $lastday, "*", $averate); } # write_emailchart #----------------------------------------------------------------------------- # # Routine to write all hostnames being used by a give email address. # #----------------------------------------------------------------------------- sub write_hostsbyemail { my $count = 0; open(OUTFILE, ">" . $userprefs{"htmldir"} . "$emaildir/" . $userprefs{"htmlhostsbyemail"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . "$emaildir/" . $userprefs{"htmlhostsbyemail "} ." ($!)\n"; &write_header(); print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE "
\n", " Participant $email
\n", " Hostnames working for this Participant\n", "
\n", "
Totals Days: $daysworking days - Average Blocks: $aveblocks blocks - Average Rate: ${averatef}keys/sec\n", "
\n", "  \n", "
\n", " \n"; print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n"; foreach $host (sort { $email2hosts{$email}{$b} <=> $email2hosts{$email}{$a} } keys %{ $email2hosts{$email} }) { $count++; if ($count % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } $domain = undef; if ($host =~ /\.(\w+)$/) { $domain = $1; } if (defined($domain) && defined($country{$domain})) { $label = $country{$domain}; if (-e $userprefs{"htmldir"} . $userprefs{"icondir"} . "flags/$domain.gif") { $icon = "$domain.gif"; } else { $icon = "unknown.gif"; } } else { $label = "Unknown"; $icon = "unknown.gif"; } $percentofemail = sprintf("%.2f", 100 * $email2hosts{$email}{$host} / $emails{$email}[0]); $keyschecked = &keysf($email2hosts{$email}{$host}); $percentcomplete = &percentf($email2hosts{$email}{$host}, 6); # Lookup host position $pos = 1; foreach $lookup (sort { $hosts{$b}[0] <=> $hosts{$a}[0] } keys %hosts) { if ($lookup eq $host) { last; } $pos += 1; } $hostdir = "h" . $pos; ($head, $tail) = split /\./, $host, 2; if (defined($tail)) { $hostlink = "$head.$tail"; } else { $hostlink = "$head"; } print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n"; } print OUTFILE "
\n", " Hostname\n", " \n", " Blocks Submitted\n", " \n", " Percent\n", " \n", " Keys Checked\n", " \n", " Keyspace\n", "
\n", " \"$label\" $hostlink\n", " \n", " $email2hosts{$email}{$host}\n", " \n", " $percentofemail%\n", " \n", " $keyschecked\n", " \n", " $percentcomplete%\n", "
\n", "
\n", "  \n", "
\n", " Click here to goto the Executive Participant Summary page.\n", "
\n", "  \n", "
\n", " Click here to goto the Graphical Participant History page.\n", "
\n"; &write_footer(); close OUTFILE; } # write_hostsbyemail #----------------------------------------------------------------------------- # # Routine to write individual host info. # #----------------------------------------------------------------------------- sub write_indvhost { my $count = 0; my $msg; my $displacement; foreach $host (sort { $hosts{$b}[0] <=> $hosts{$a}[0] || $a cmp $b } keys %hosts) { $count += 1; # Print out the Rank and Movement column. $displacement = $hosts_ry{$host} == 0 ? $numhost - $count : $hosts_ry{$host} - $count; $msg = &create_move_msg($displacement); $daysworking = $hosts_firstday{$host} - $hosts_lastday{$host} + 1; $prev_daysworking = $hosts_firstday{$host} - (defined($hosts_prev_lastday{$host}) ? $hosts_prev_lastday{$host} : 0) + 1; ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - (($hosts_firstday{$host} - 1) * (60*60*24))); $firstblockdate = "$mday $months[$mon-1] $year GMT"; ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - (($hosts_lastday{$host} - 1) * (60*60*24))); $lastblockdate = "$mday $months[$mon-1] $year GMT"; # Print out the Last Seen column. ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin); $lastseentime = $hosts_ls{$host}[0]*24*60*60 + ($hour - $hosts_ls{$host}[1])*60*60 + ($min - $hosts_ls{$host}[2])*60 + $sec - $hosts_ls{$host}[3]; $lastseen = &ls($lastseentime); $lastseencolor = &ls_color($lastseentime); # Blocks done today do not count towards the average. if ($hosts_lastday{$host} == 1) { if ($daysworking == 1) { $rate = 0; $aveblocks = 0; } else { $rate = &rate_day($hosts{$host}[0] - $hosts{$host}[1]) / $prev_daysworking; $aveblocks = int(($hosts{$host}[0] - $hosts{$host}[1]) / $prev_daysworking); } } else { $rate = &rate_day($hosts{$host}[0]) / $daysworking; $aveblocks = int($hosts{$host}[0] / $daysworking); } $averate = $rate; $averatef = &ratef($rate); $rateyesterday = &ratef(&rate_day($hosts{$host}[2])); $blocksyesterday = defined($hosts{$host}[2]) ? $hosts{$host}[2] : 0; $contestblocks = &get_contest_blocks(); $keyschecked = &keysf($hosts{$host}[0]); $percentcomplete = &percentf($hosts{$host}[0], 6); $percentofteam = sprintf("%.2f", 100 * $hosts{$host}[0] / $blocks[0]); $domain = undef; if ($host =~ /\.(\w+)$/) { $domain = $1; } if (defined($domain) && defined($country{$domain})) { $label = $country{$domain}; if (-e $userprefs{"htmldir"} . $userprefs{"icondir"} . "flags/$domain.gif") { $icon = "$domain.gif"; } else { $icon = "unknown.gif"; } } else { $label = "Unknown"; $icon = "unknown.gif"; } $hostdir = "h" . $count; mkdir($userprefs{"htmldir"} . "$hostdir", 0755); open(OUTFILE, ">" . $userprefs{"htmldir"} . "$hostdir/" . $userprefs{"htmlindvhost"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . "$hostdir/" . $userprefs{"htmlindvhost"} . " ($!)\n"; &write_header(); print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; if ($blocksyesterday == 0) { print OUTFILE " \n", " \n", " \n"; } else { $percentcomplete = &percentf($blocksyesterday, 8); print OUTFILE " \n", " \n", " \n"; } print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE "
\n", " Hostname $host
\n", " Executive Hostname Summary\n", "
\n", "  \n", "
\n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n", " \n"; print OUTFILE "
\n", " Hostname Summary for $host\n", "
\n", " Current Team Rank\n", " \n", " $count$msg\n", "
\n", " Percent of Team\n", " \n", " $percentofteam%\n", "
\n", " Total Blocks to Search\n", " \n", " $contestblocks blocks\n", "
\n", " Total Blocks Checked\n", " \n", " $hosts{$host}[0] blocks\n", "
\n", " Keyspace Exhausted\n", " \n", " $percentcomplete%\n", "
\n", " Total Keys Checked\n", " \n", " $keyschecked\n", "
\n", " Total Unique IPs\n", " \n", " $hosts_ips{$host}\n", "
\n", " Time Working\n", " \n", " $daysworking days\n", "
\n", " Last Seen\n", " \n", " $lastseen\n", "
\n", " First Block Submitted\n", " \n", " $firstblockdate\n", "
\n", " Last Block Submitted\n", " \n", " $lastblockdate\n", "
\n", " Overall Rate\n", " \n", " ${averatef}keys/sec\n", "
\n", " Average Blocks\n", " \n", " $aveblocks per day\n", "
\n", " Last Version Reported\n", " \n", " $hosts_ls{$host}[4]\n", "
\n", " Hostname Domain\n", " \n", " $label \"$label\"\n", "
\n", "
\n", "  \n", "
\n", " This host didn't submit any blocks yesterday, someone get that cpu cracking!\n", "
\n", " $blocksyesterday blocks were completed yesterday ($percentcomplete% of the keyspace)
at a sustained rate of ${rateyesterday}keys/sec!\n", "
\n", "  \n", "
\n", " Click here to goto the Graphical Hostname History page.\n", "
\n", "  \n", "
\n", " Click here to goto the Participants working for this Hostname page.\n", "
\n", "  \n", "
\n", " Hostname History for the Last " . $userprefs{"blockhistory"} . " Days\n", "
\n", "  \n", "
\n", " \n"; print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n"; for ($x = 1; $x <= $userprefs{"blockhistory"}; $x++) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($x - 1) * (24*60*60)); $blockdate = "$mday $months[$mon-1] $year GMT"; $hosts{$host}[$x] = defined($hosts{$host}[$x]) ? $hosts{$host}[$x] : 0; if ($blocks[$x] == 0) { $percentofteam = sprintf("%.2f", 0); } else { $percentofteam = sprintf("%.2f", 100 * $hosts{$host}[$x] / $blocks[$x]); } if ($x == 1) { $rate = &ratef(&rate_day($hosts{$host}[1]) / ($secs_today / (60*60*24))); } else { $rate = &ratef(&rate_day($hosts{$host}[$x])); } $keyschecked = &keysf($hosts{$host}[$x]); $percentcomplete = &percentf($hosts{$host}[$x], 8); if ($x % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n"; } print OUTFILE "
\n", " Day History\n", " \n", " Blocks Submitted\n", " \n", " Percent\n", " \n", " Keys Checked\n", " \n", " Key Rate\n", " \n", " Keyspace\n", "
\n", " $blockdate\n", " \n", " $hosts{$host}[$x] blocks\n", " \n", " $percentofteam%\n", " \n", " $keyschecked\n", " \n", " ${rate}k/s\n", " \n", " $percentcomplete%\n", "
\n", "
\n"; &write_footer(); close OUTFILE; &write_hostchart; &write_emailsbyhost; &debug("."); } &debugln("") if ($count > 0); } # write_indvhost #----------------------------------------------------------------------------- # # Routine to create the Graphical Hostname History plot, write the GNUplot # config file and plot a chart for this Hostname. # #----------------------------------------------------------------------------- sub write_hostchart { open(OUTFILE, ">" . $userprefs{"htmldir"} . "$hostdir/" . $userprefs{"htmlhosthist"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . "$hostdir/" . $userprefs{"htmlhosthist"} . " ($!)\n"; &write_header(); print OUTFILE " \n"; print OUTFILE " \n"; for ($y = $userprefs{"dayshist"} - 1; $y > 1; $y--) { ($year, $month, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - $y * (24*60*60)); print OUTFILE " \n"; } if ($userprefs{"dayshist"} > 1) { print OUTFILE " \n", } if ($userprefs{"dayshist"} > 0) { print OUTFILE " \n"; } print OUTFILE " \n", " \n"; print OUTFILE " \n"; for ($y = $userprefs{"dayshist"}; $y > 0; $y--) { $hosts{$host}[$y] = defined($hosts{$host}[$y]) ? $hosts{$host}[$y] : 0; print OUTFILE " \n"; } print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n"; # Print out day history list for all days before today for ($y = $userprefs{"dayshist"}; $y > 1; $y--) { $rate = &ratef(&rate_day($hosts{$host}[$y])); print OUTFILE " \n"; } # Print out day history list for today if (($day - 1) <= 0) { $rate = 0; } else { $rate = &rate_day($hosts{$host}[1]) / ($secs_today / (60*60*24)); } if ($userprefs{"dayshist"} > 0) { $rate = &ratef($rate); print OUTFILE " \n"; } # Print out total for day history list print OUTFILE " \n"; print OUTFILE " \n"; $colsp = 1 + $userprefs{"dayshist"}; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE "
Blocks
$days[$wday]
Blocks
Yesterday
Blocks
Today
Blocks
Total
$hosts{$host}[$y]$hosts{$host}[0]
${rate}k/s${rate}k/s${averatef}k/s
\n", "  \n", "
\n", " Hostname $host
\n", " Graphical Hostname History\n", "
\n", "
Totals Days: $daysworking days - Average Blocks: $aveblocks blocks - Average Rate: ${averatef}keys/sec\n", "
\n", "  \n", "
\n", " \"$host\"\n", "
\n", "  \n", "
\n", " For past days: Mkeys/sec = $blockweight * blocks / 322
\n", " For today: Mkeys/sec = ($blockweight * blocks / 322) / (seconds today / (60*60*24))\n", "
\n", "  \n", "
\n", " Click here to goto the Executive Hostname Summary page.\n", "
\n", "  \n", "
\n", " Click here to goto the Participants working for this Hostname page.\n", "
\n"; &write_footer(); close OUTFILE; open(GNUPLOTDATA, ">" . $userprefs{"htmldir"} . "$hostdir/" . $userprefs{"gnuplotdata"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . "$hostdir/" . $userprefs{"gnuplotdata"} . " ($!)\n"; # Write out data file in format "Date, Rate". &clear_nday_ave(); for ($x = $hosts_firstday{$host}; $x >= $hosts_lastday{$host}; $x--) { ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($x - 1) * (24*60*60)); $hosts{$host}[$x] = defined($hosts{$host}[$x]) ? $hosts{$host}[$x] : 0; if ($x == 1) { $rate = sprintf("%.2f", &rate_day($hosts{$host}[$x]) / ($secs_today / (60*60*24))); } else { $rate = sprintf("%.2f", &rate_day($hosts{$host}[$x])); } $line = "$year/$mon/$mday $rate"; &push_nday_ave($rate); $rate = &calc_nday_ave(); $line .= " $rate"; print GNUPLOTDATA "$line\n"; } close GNUPLOTDATA; ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - ($hosts_lastday{$host} - 2) * (24*60*60)); $lastday = "$year/$mon/$mday"; ($year, $mon, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - $hosts_firstday{$host} * (24*60*60)); $firstday = "$year/$mon/$mday"; &plot_gui_graph($userprefs{"htmldir"} . "$hostdir/", "History Plot for $contestname\\nHostname $host", $firstday, $lastday, "*", $averate); } # write_hostchart #----------------------------------------------------------------------------- # # Routine to write all hostnames being used by a give email address. # #----------------------------------------------------------------------------- sub write_emailsbyhost { my $count = 0; open(OUTFILE, ">" . $userprefs{"htmldir"} . "$hostdir/" . $userprefs{"htmlemailsbyhost"}) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . "$hostdir/" . $userprefs{"htmlemailsbyhost"} . " ($!)\n"; &write_header(); print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; print OUTFILE "
\n", " Hostname $host
\n", " Participants working for this Hostname\n", "
\n", "
Totals Days: $daysworking days - Average Blocks: $aveblocks blocks - Average Rate: ${averatef}keys/sec\n", "
\n", "  \n", "
\n", " \n"; print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n", " \n"; foreach $email (sort { $host2emails{$host}{$b} <=> $host2emails{$host}{$a} } keys %{ $host2emails{$host} }) { $count++; if ($count % 2 == 0) { print OUTFILE " \n"; } else { print OUTFILE " \n"; } $domain = undef; if ($email =~ /\.(\w+)$/) { $domain = $1; } if (defined($domain) && defined($country{$domain})) { $label = $country{$domain}; if (-e $userprefs{"htmldir"} . $userprefs{"icondir"} . "flags/$domain.gif") { $icon = "$domain.gif"; } else { $icon = "unknown.gif"; } } else { $label = "Unknown"; $icon = "unknown.gif"; } $percentofhost = sprintf("%.2f", 100 * $host2emails{$host}{$email} / $hosts{$host}[0]); $keyschecked = &keysf($host2emails{$host}{$email}); $percentcomplete = &percentf($host2emails{$host}{$email}, 6); # Lookup email position $pos = 1; foreach $lookup (sort { $emails{$b}[0] <=> $emails{$a}[0] } keys %emails) { if ($lookup eq $email) { last; } $pos += 1; } $emaildir = "e" . $pos; ($head, $tail) = split(/@/, $email); if (!defined($head)) { $head = ""; } if (!defined($tail)) { $tail = ""; } print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n"; } print OUTFILE "
\n", " Participant\n", " \n", " Blocks Submitted\n", " \n", " Percent\n", " \n", " Keys Checked\n", " \n", " Keyspace\n", "
\n", " \"$label\" $head\@$tail\n", " \n", " $host2emails{$host}{$email}\n", " \n", " $percentofhost%\n", " \n", " $keyschecked\n", " \n", " $percentcomplete%\n", "
\n", "
\n", "  \n", "
\n", " Click here to goto the Executive Hostname Summary page.\n", "
\n", "  \n", "
\n", " Click here to goto the Graphical Hostname History page.\n", "
\n"; &write_footer(); close OUTFILE; } # write_emailsbyhost #----------------------------------------------------------------------------- # # Subroutine to create GNUplot config file and system call to execute it. # #----------------------------------------------------------------------------- sub plot_gui_graph { my ($path, $title, $xmin, $xmax, $range, $averate) = @_; open(GNUPLOTCONFIG, ">$path" . $userprefs{"gnuplotconfig"}) or die "Personal Proxy Statistics : Cannot open $path" . $userprefs{"gnuplotconfig"} . " ($!)\n"; print GNUPLOTCONFIG "set title \"$title\\n\"\n"; if ($userprefs{"chartlinestyle"} == 1) { print GNUPLOTCONFIG "set data style impulses\n"; } elsif ($userprefs{"chartlinestyle"} == 2) { print GNUPLOTCONFIG "set data style lines\n"; } elsif ($userprefs{"chartlinestyle"} == 3) { print GNUPLOTCONFIG "set data style linespoints\n"; } else { print GNUPLOTCONFIG "set data style impulses\n"; } print GNUPLOTCONFIG "set key top left\n", "set timefmt '%Y/%m/%d'\n", "set xdata time\n", "set xrange ['$xmin':'$xmax'] noreverse nowriteback\n", "set format x '%Y-%m-%d'\n", "set xtics rotate\n", "set ylabel 'Rate (kkeys/sec)'\n", "set yrange [0:$range] noreverse nowriteback\n", "set grid\n", "set bmargin 8\n", "set terminal png small color\n", # "set terminal gif transparent interlace size " . $userprefs{"chartwidth"} . "," . $userprefs{"chartheight"} . " x" . $userprefs{"backgroundcolor"} . " x" . $userprefs{"textcolor"} . " x" . $userprefs{"textcolor"} . " x" . $userprefs{"historycolor"} . " x" . $userprefs{"avehistorycolor"} . " x" . $userprefs{"ndayhistorycolor"} . "\n", "set output '$path/" . $userprefs{"gnuplotoutput"} . "'\n"; $line = "plot '$path/" . $userprefs{"gnuplotdata"} . "' using 1:2 title 'daily', $averate title 'overall'"; if ($userprefs{"dayaverage"} > 1) { $line .= ", '$path/" . $userprefs{"gnuplotdata"} . "' using 1:3 title '" . $userprefs{"dayaverage"} . " day'"; } print GNUPLOTCONFIG "$line\n"; close GNUPLOTCONFIG; system($userprefs{"gnuplot"}, "$path" . $userprefs{"gnuplotconfig"}) == 0 or die "Personal Proxy Statistics : Cannot execute " . $userprefs{"gnuplot"} . " $path" . $userprefs{"gnuplotconfig"} . " ($?)\n"; } # plot_gui_graph #----------------------------------------------------------------------------- # # Write zeros to the nth-day average array, initializing the array. # #----------------------------------------------------------------------------- sub clear_nday_ave { my $x; for ($x = 0; $x < $userprefs{"dayaverage"}; $x++) { $nday_ave[$x] = 0; } } # clear_nday_ave #----------------------------------------------------------------------------- # # Shift all values of the nth-day average down and insert the new rate. # #----------------------------------------------------------------------------- sub push_nday_ave { my $x; my $rate = shift @_; if ($userprefs{"dayaverage"} > 1) { for ($x = 1; $x < $userprefs{"dayaverage"}; $x++) { $nday_ave[$x - 1] = $nday_ave[$x]; } $nday_ave[$userprefs{"dayaverage"} - 1] = $rate; } } # push_nday_ave #----------------------------------------------------------------------------- # # Calculate the nth-day average. # #----------------------------------------------------------------------------- sub calc_nday_ave { my $x; my $sum = 0; if ($userprefs{"dayaverage"} < 2) { return 0; } for ($x = 0; $x < $userprefs{"dayaverage"}; $x++) { $sum += $nday_ave[$x]; } return sprintf("%.2f", $sum / $userprefs{"dayaverage"}); } # calc_nday_ave #----------------------------------------------------------------------------- # # Subroutine to write HTML header. # #----------------------------------------------------------------------------- sub write_header { print OUTFILE "\n", "\n", " \n", " \n", " Team " . $userprefs{"team"} . " $contestname Statistics\n"; if ($userprefs{"usemetarefresh"}) { print OUTFILE " \n"; } print OUTFILE " \n", " \n", " \n", " \n", " \n", " \n"; &write_banner() if ($userprefs{"useheaderbanner"}); print OUTFILE " \n", " \n", " \n", " \n", " \n", "
\n", " \n"; print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n", " \n"; print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n"; if ($userprefs{"usecounter"}) { print OUTFILE " Hit Count: \"Hit
\n"; } print OUTFILE "
\n", " Last Updated GMT:
\n", " $timestamp
\n", "
\n", "   Team " . $userprefs{"team"} . "\n", "
\n", "   $contestname\n", "
\n", "   Teams & Groups\n", "
\n", "   Individuals\n", "
\n", "
\n"; if ($userprefs{"uselogo"}) { print OUTFILE "

\n", " \""\n", "

\n"; } } # write_header #----------------------------------------------------------------------------- # # Subroutine to write HTML footer. # #----------------------------------------------------------------------------- sub write_footer { print OUTFILE "
\n", "
\n"; &write_banner if ($userprefs{"usefooterbanner"}); print OUTFILE "

\n", " Personal Proxy Statistics\n", " ppstats-$contestsuffix-$appver.zip
\n", " Copyright (C) Kevin Pesce 1998, 1999
\n", " University of Southern Maine Computer Users Group\n", "

\n", " \n", "\n"; } # write_footer #----------------------------------------------------------------------------- # # Write header for by category section. # #----------------------------------------------------------------------------- sub write_section_header { my ($page, $title, $htmlfile) = @_; my $y; open(OUTFILE, ">" . $userprefs{"htmldir"} . $page . $htmlfile) or die "Personal Proxy Statistics : Cannot open " . $userprefs{"htmldir"} . $page . $htmlfile . " ($!)\n"; &write_header(); print OUTFILE " \n"; print OUTFILE " \n", " \n", " \n"; for ($y = $userprefs{"dayshist"} - 4; $y > 1; $y--) { ($year, $month, $mday, $hour, $min, $sec, $wday) = &nice_gmtime($time_begin - $y * (24*60*60)); print OUTFILE " \n"; } if ($userprefs{"dayshist"} - 3 > 1) { print OUTFILE " \n"; } if ($userprefs{"dayshist"} - 3 > 0) { print OUTFILE " \n"; } print OUTFILE " \n", " \n", " \n", " \n"; } # write_section_header #----------------------------------------------------------------------------- # # Write footer for by category section. # #----------------------------------------------------------------------------- sub write_section_footer { my ($page, $totalrows, $offset, $htmlfile, $msg) = @_; my $percentofteam; my $colsp; my $y; if ($totalrows > $userprefs{"maxrows"}) { print OUTFILE " \n", " \n", " \n"; for ($y = $userprefs{"dayshist"} - 3 - $offset; $y > 0; $y--) { print OUTFILE " \n"; } print OUTFILE " \n"; for ($y = 0; $y <= $offset + 1; $y++) { print OUTFILE " \n"; } print OUTFILE " \n"; } print OUTFILE " \n", " \n", " \n"; for ($y = $userprefs{"dayshist"} - 3 - $offset; $y > 0; $y--) { print OUTFILE " \n"; } print OUTFILE " \n"; for ($y = 0; $y <= $offset + 1; $y++) { print OUTFILE " \n"; } print OUTFILE " \n"; if ($totalrows > $userprefs{"maxrows"}) { print OUTFILE " \n", " \n", " \n"; for ($y = $userprefs{"dayshist"} - 3 - $offset; $y > 0; $y--) { if ($blocks[$y] == 0) { $percentofteam = sprintf("%.2f", 100); } else { $percentofteam = sprintf("%.2f", 100 * $pageblocks[$y] / $blocks[$y]); } print OUTFILE " \n", } if ($blocks[0] == 0) { $percentofteam = sprintf("%.2f", 100); } else { $percentofteam = sprintf("%.2f", 100 * $pageblocks[0] / $blocks[0]); } print OUTFILE " \n"; for ($y = 0; $y <= $offset + 1; $y++) { print OUTFILE " \n"; } print OUTFILE " \n"; } $colsp = 5 + $offset; if ($userprefs{"dayshist"} > 2 + $offset) { $colsp = $userprefs{"dayshist"} + 2; } if ($totalrows > $userprefs{"maxrows"}) { print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; } if ($msg ne "") { print OUTFILE " \n", " \n", " \n"; print OUTFILE " \n", " \n", " \n"; } print OUTFILE "
Rank$titleBlocks
$days[$wday]
Blocks
Yesterday
Blocks
Today
Blocks
Total
Last
Seen
Percent
 Page Total$pageblocks[$y]$pageblocks[0] 
 Blocks Total $blocks[$y]  $blocks[0]  
 Percent$percentofteam%$percentofteam% 
\n", "  \n", "
\n", " Goto Page:" . &goto_page($page, $totalrows, $htmlfile) . "\n", "
\n", "  \n", "
\n", " $msg\n", "
\n"; &write_footer(); close OUTFILE; } # write_section_footer #----------------------------------------------------------------------------- # # Subroutine to write Distributed banner. # #----------------------------------------------------------------------------- sub write_banner { print OUTFILE "

\n", " \"Distributed\n", "

\n"; } # write_banner #----------------------------------------------------------------------------- # # Construct and return the Goto Page url string. # #----------------------------------------------------------------------------- sub goto_page { my ($page, $totalrows, $htmlfile) = @_; my $retval = ""; my ($url, $x, $y); if ($page > 1) { if ($page == 2) { $url = $userprefs{"htmlroot"} . $htmlfile; } else { $url = $userprefs{"htmlroot"} . ($page - 1) . $htmlfile; } $retval .= " [<< Prev]"; } $x = 0; $y = 0; while ($y < $totalrows) { $x += 1; $y += $userprefs{"maxrows"}; if ($x == 1) { $url = $userprefs{"htmlroot"} . $htmlfile; } else { $url = $userprefs{"htmlroot"} . $x . $htmlfile; } if ($x == $page) { $retval .= " ($x)"; } else { $retval .= " $x"; } } if ($page != $x) { $url = $userprefs{"htmlroot"} . ($page + 1) . $htmlfile; $retval .= " [Next >>]"; } return $retval; } # goto_page #----------------------------------------------------------------------------- # # Routine to create a displacement move message. # #----------------------------------------------------------------------------- sub create_move_msg { my $displacement = shift @_; my $retval = ""; if ($displacement > 0) { $retval = " (\"Up $displacement)"; } elsif ($displacement < 0) { $retval = " (\"Down " . -$displacement . ")"; } return $retval; } # create_move_msg #----------------------------------------------------------------------------- # # Returns formated last seen time. # #----------------------------------------------------------------------------- sub ls { my $lastseentime = shift @_; my $lastseen; # Print out the Last Seen column. if ($lastseentime >= 365*24*60*60) { $lastseen = int($lastseentime / (365*24*60*60)) . "+ years"; } elsif ($lastseentime >= 2*24*60*60) { $lastseen = int($lastseentime / (24*60*60)) . " days"; } elsif ($lastseentime >= 2*60*60) { $lastseen = int($lastseentime / (60*60)) . " hours"; } elsif ($lastseentime >= 2*60) { $lastseen = int($lastseentime / 60) . " mins"; } elsif ($lastseentime >= 0) { $lastseen = $lastseentime . " secs"; } else { $lastseen = "0 secs"; } return $lastseen; } # ls #----------------------------------------------------------------------------- # # Returns the appropriate color class given a last seen time. # #----------------------------------------------------------------------------- sub ls_color { my $lastseentime = shift @_; my $lastseencolor = "normal"; if ($userprefs{"colorlastseen"}) { if ($lastseentime >= $userprefs{"lastseencriticaltime"}) { $lastseencolor = "critical"; } elsif ($lastseentime >= $userprefs{"lastseenwarningtime"}) { $lastseencolor = "warning"; } } return $lastseencolor; } # ls_color #----------------------------------------------------------------------------- # # Returns rate for day (24 h) in kilo keys/sec # #----------------------------------------------------------------------------- sub rate_day { my $blocks = shift @_; if (!defined($blocks)) { $blocks = 0; } return ($blockweight * 1000 * $blocks / 322); } # rate_day #----------------------------------------------------------------------------- # # Get formatted rate string # ex. 3.10 M, or 983.34 k # #----------------------------------------------------------------------------- sub ratef { my $rate = shift @_; if (!defined($rate)) { $rate = 0; } if ($rate < 10**3) { $rate = sprintf("%.2f", $rate) . " k"; } elsif ($rate < 10**6) { $rate = sprintf("%.2f", $rate / 10**3) . " M"; } elsif ($rate < 10**9) { $rate = sprintf("%.2f", $rate / 10**6) . " G"; } elsif ($rate < 10**12) { $rate = sprintf("%.2f", $rate / 10**9) . " T"; } elsif ($rate < 10**15) { $rate = sprintf("%.2f", $rate / 10**12) . " P"; } elsif ($rate < 10**18) { $rate = sprintf("%.2f", $rate / 10**15) . " E"; } elsif ($rate < 10**21) { $rate = sprintf("%.2f", $rate / 10**18) . " Z"; } else { $rate = sprintf("%.2f", $rate / 10**21) . " Y"; } return $rate; } # ratef #----------------------------------------------------------------------------- # # Return the total number of blocks in this contest. # #----------------------------------------------------------------------------- sub get_contest_blocks { return sprintf("%.0f", 2**($contestsize - $blockbase - $blockweight + 1)); } # get_contest_blocks #----------------------------------------------------------------------------- # # Return formatted number of keys checked given blocks done. # #----------------------------------------------------------------------------- sub keysf { my $blocks = shift @_; my $keys; if (!defined($blocks)) { $blocks = 0; } $keys = $blocks * (2**($blockbase + $blockweight - 1)); if ($keys <= 0) { $keys = "None"; } elsif ($keys < 10**6) { $keys = sprintf("%.2f", $keys / 10**3) . " Thousand"; } elsif ($keys < 10**9) { $keys = sprintf("%.2f", $keys / 10**6) . " Million"; } elsif ($keys < 10**12) { $keys = sprintf("%.2f", $keys / 10**9) . " Billion"; } elsif ($keys < 10**15) { $keys = sprintf("%.2f", $keys / 10**12) . " Trillion"; } elsif ($keys < 10**18) { $keys = sprintf("%.2f", $keys / 10**15) . " Quadrillion"; } elsif ($keys < 10**21) { $keys = sprintf("%.2f", $keys / 10**18) . " Quintillion"; } elsif ($keys < 10**24) { $keys = sprintf("%.2f", $keys / 10**21) . " Sextillion"; } else { $keys = sprintf("%.2f", $keys / 10**24) . " Septillion"; } return $keys; } # keysf #----------------------------------------------------------------------------- # # Return a formatted percent given the number of blocks. # #----------------------------------------------------------------------------- sub percentf { my ($blocks, $percision) = @_; if (!defined($blocks)) { $blocks = 0; } if (!defined($percision)) { $percision = 0; } return sprintf("%." . $percision . "f", 100 * $blocks / &get_contest_blocks()); } # percentf #----------------------------------------------------------------------------- # # Get preformatted GMT array (year,mon,mday,hour,min,sec,wday) # #----------------------------------------------------------------------------- sub nice_gmtime { my @gmt = gmtime shift @_; my $i; $gmt[4]++; $gmt[5] += 1900; for ($i = 0; $i < 5; $i++) { while (length($gmt[$i]) < 2) { $gmt[$i] = "0" . $gmt[$i]; } } $gmt[6]--; if ($gmt[6]<0) { $gmt[6] += 7; } return ($gmt[5], $gmt[4], $gmt[3], $gmt[2], $gmt[1], $gmt[0], $gmt[6]); } # nice_gmtime #----------------------------------------------------------------------------- # # parsecmdline takes a list of possible options and a boolean indicating # whether the option has a value following, and sets up an associative array # %opt of the values of the options given on the command line. It removes all # the arguments it uses from @ARGV and returns them in @optArgs. # #----------------------------------------------------------------------------- sub parse_cmd_line { local (@optval) = @_; local ($opt, @opts, %valFollows, @newargs); while (@optval) { $opt = shift(@optval); push(@opts,$opt); $valFollows{$opt} = shift(@optval); } @optArgs = (); %opt = (); arg: while ($arg = shift(@ARGV)) { foreach $opt (@opts) { if ($arg eq $opt) { push(@optArgs, $arg); if ($valFollows{$opt}) { if (@ARGV == 0) { &Usage(); } $opt{$opt} = shift(@ARGV); push(@optArgs, $opt{$opt}); } else { $opt{$opt} = 1; } next arg; } } push(@newargs, $arg); } @ARGV = @newargs; } # parse_cmd_line #----------------------------------------------------------------------------- # # Check for the existence of all referenced variables that are read from the # user preference file. Warn in case of malformed values, die if missing. # #----------------------------------------------------------------------------- sub validate_userprefs { # Verify each user preference, die if not defined. foreach $up (@ups) { if (!defined($userprefs{$up})) { die "Personal Proxy Statistics : Required user variable '$up' not defined, please verify ppstats-$contestsuffix.ini file.\n"; } # Print out each INI file variable and its value. &debugln("$up=" . $userprefs{$up}); } } # validate_userprefs #----------------------------------------------------------------------------- # # If debug flag is turned on, print out debug, message and line break # to standard error. # #----------------------------------------------------------------------------- sub debugln { my ($msg) = shift @_; if ($debug_enable == 1) { if ($msg ne "") { print STDERR "debug: $msg\n"; } else { print STDERR "\n"; } } } # debugln #----------------------------------------------------------------------------- # # If debug flag is turned on, print out message to standard error. # #----------------------------------------------------------------------------- sub debug { my ($msg) = shift @_; if ($debug_enable == 1 && $msg ne "") { print STDERR "$msg"; } } # debug #----------------------------------------------------------------------------- # # Turn on system debuging. # #----------------------------------------------------------------------------- sub enable_debug_messages { print "\nPersonal Proxy Statistics v$appver\n", "Debug is enabled. Runtime information will be sent to STDERR.\n\n"; $debug_enable = 1; } # enable_debug_messages #----------------------------------------------------------------------------- # # Display program name and options. # #----------------------------------------------------------------------------- sub display_usage { print "\nPersonal Proxy Statistics v$appver\n", "usage: $app [-debug] [-version] [-help]\n\n", " -debug Display debug information while script executes\n", " -version Display version and copyright information and exit\n", " -help Print this help and exit\n\n"; exit; } # display_usage #----------------------------------------------------------------------------- # # Display program name and version information. # #----------------------------------------------------------------------------- sub display_version { print "\nPersonal Proxy Statistics v$appver\n", "University of Southern Maine Computer Users Group\n", "Developed by Kevin Pesce (kpesce\@netscape.net)\n", "Copyright (C) 1998, 1999 Kevin Pesce\n\n", "This program is licenced under the GNU Public Lisence. See License.txt\n", "for more information. Comments and suggestions are welcome!\n\n"; exit; } # display_version