1 #!/usr/bin/perl -w
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;
12 use Date::Format;
14 my $CACHE_FILE = '/var/spool/squid/quota.db';
15 my $FORMAT = "A16 A5 S S L A5 L L L";
17 my %cache;
19 sub min2time
20 {
21 my $min = shift;
22 return sprintf("%2d:%02d",$min/60,$min%60);
23 }
25 sub show_user
26 {
27 my $uid = shift;
29 my (
30 $modifyTimestamp, $gosaProxyAcctFlags, $gosaProxyWorkingStart,
31 $gosaProxyWorkingStop, $gosaProxyQuota, $gosaProxyQuotaPeriod,
32 $trafficUsage, $firstRequest, $lastRequest
33 ) = unpack($FORMAT, $cache{$uid});
35 my ($ts_Y, $ts_M, $ts_D, $ts_h, $ts_m, $ts_s)
36 = $modifyTimestamp =~ /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/g;
37 my $ts = "$ts_D\.$ts_M\.$ts_Y $ts_h:$ts_m:$ts_s GMT";
39 $gosaProxyAcctFlags =~ s/[\[\]]//g;
40 $gosaProxyAcctFlags =~ s/F/unwanted content, /g;
41 $gosaProxyAcctFlags =~ s/T/work time, /g;
42 $gosaProxyAcctFlags =~ s/B/traffic/g;
44 $gosaProxyQuotaPeriod =~ s/h/hour/;
45 $gosaProxyQuotaPeriod =~ s/d/day/;
46 $gosaProxyQuotaPeriod =~ s/w/week/;
47 $gosaProxyQuotaPeriod =~ s/m/month/;
48 $gosaProxyQuotaPeriod =~ s/y/year/;
50 $firstRequest = localtime($firstRequest);
51 $lastRequest = localtime($lastRequest);
53 printf "User: %s
54 LDAP modify timestamp\t%s
55 Limited by\t\t%s
56 Work time from\t%s
57 Work time to\t\t%s
58 Quota period\t\tOne %s
59 Traffic quota size\t%s bytes
60 Current traffic usage\t%s bytes
61 First request time\t%s
62 Last request time\t%s\n",
63 $uid, $ts, $gosaProxyAcctFlags, min2time($gosaProxyWorkingStart),
64 min2time($gosaProxyWorkingStop), $gosaProxyQuotaPeriod, $gosaProxyQuota,
65 $trafficUsage, $firstRequest, $lastRequest;
66 }
68 #------------------------
69 tie(%cache, 'DB_File', $CACHE_FILE, O_CREAT|O_RDWR);
71 if($ARGV[0])
72 {
73 show_user($ARGV[0]);
74 }
75 else
76 {
77 print "eee\n";
78 printf "LAST STRING: %d\nLAST CACHE UPDATE: %s\nLDAP LAST CHANGE: %s\n",
79 $cache{STRING_NUMBER},
80 time2str("%d.%m.%Y %H:%M:%S",$cache{TIMESTAMP}),
81 $cache{MODIFY_TIMESTAMP};
83 foreach my $user (keys %cache)
84 {
85 next if $user eq "TIMESTAMP";
86 next if $user eq "STRING_NUMBER";
87 next if $user eq "MODIFY_TIMESTAMP";
88 show_user($user);
89 }
90 }
92 untie %cache;