1 #!/usr/bin/perl
2 #
3 # Show user info from cache
4 #
5 # Igor Muratov <migor@altlinux.org>
6 #
7 # $Id: goQuotaView.pl,v 1.2 2005/04/03 00:46:14 migor-guest Exp $
8 #
10 use strict;
11 use DB_File;
13 my $CACHE_FILE = '/var/spool/squid/quota.db';
14 my $FORMAT = "A16 A5 S S L A5 L L L";
16 my %cache;
18 sub min2time
19 {
20 my $min = shift;
21 return sprintf("%2d:%02d",$min/60,$min%60);
22 }
24 sub show_user
25 {
26 my $uid = shift;
28 my (
29 $modifyTimestamp, $gosaProxyAcctFlags, $gosaProxyWorkingStart,
30 $gosaProxyWorkingStop, $gosaProxyQuota, $gosaProxyQuotaPeriod,
31 $trafficUsage, $firstRequest, $lastRequest
32 ) = unpack($FORMAT, $cache{$uid});
34 my ($ts_Y, $ts_M, $ts_D, $ts_h, $ts_m, $ts_s)
35 = $modifyTimestamp =~ /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/g;
36 my $ts = "$ts_D\.$ts_M\.$ts_Y $ts_h:$ts_m:$ts_s GMT";
38 $gosaProxyAcctFlags =~ s/[\[\]]//g;
39 $gosaProxyAcctFlags =~ s/F/unwanted content, /g;
40 $gosaProxyAcctFlags =~ s/T/work time, /g;
41 $gosaProxyAcctFlags =~ s/B/traffic/g;
43 $gosaProxyQuotaPeriod =~ s/h/hour/;
44 $gosaProxyQuotaPeriod =~ s/d/day/;
45 $gosaProxyQuotaPeriod =~ s/w/week/;
46 $gosaProxyQuotaPeriod =~ s/m/month/;
47 $gosaProxyQuotaPeriod =~ s/y/year/;
49 $firstRequest = localtime($firstRequest);
50 $lastRequest = localtime($lastRequest);
52 printf "User: %s
53 LDAP modify timestamp\t%s
54 Limited by\t\t%s
55 Work time from\t%s
56 Work time to\t\t%s
57 Quota period\t\tOne %s
58 Traffic quota size\t%s bytes
59 Current traffic usage\t%s bytes
60 First request time\t%s
61 Last request time\t%s\n",
62 $uid, $ts, $gosaProxyAcctFlags, min2time($gosaProxyWorkingStart),
63 min2time($gosaProxyWorkingStop), $gosaProxyQuotaPeriod, $gosaProxyQuota,
64 $trafficUsage, $firstRequest, $lastRequest;
65 }
67 #------------------------
68 tie(%cache, 'DB_File', $CACHE_FILE, O_CREAT|O_RDWR);
70 if($ARGV[0])
71 {
72 show_user($ARGV[0]);
73 }
74 else
75 {
76 print "eee\n";
77 printf "LAST STRING: %d\nLAST CACHE UPDATE: %s\nLDAP LAST CHANGE: %s\n",
78 $cache{STRING_NUMBER},
79 time2str("%d.%m.%Y %H:%M:%S",$cache{TIMESTAMP}),
80 $cache{MODIFY_TIMESTAMP};
82 foreach my $user (keys %cache)
83 {
84 next if $user eq "TIMESTAMP";
85 next if $user eq "STRING_NUMBER";
86 next if $user eq "MODIFY_TIMESTAMP";
87 show_user($user);
88 }
89 }
91 untie %cache;