[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Perl cgi-bin und Quota-Info-Abfrage



Hallo, Andreas...

> ich suche ein cgi-bin vorzugsweise in Perl zwecks Abfrage der
> Quota-Infos von Usern.

ich hatte mal zu Hause eine Quota-Testumgebung. Daraus entstand ein
Perl-Skript, dass ich mal etwas vereinfacht habe. Kann sein, dass es
nicht auf Anhieb für dich läuft, weil die Ausgabe des Quota-Befehls
mittlerweile anders aussieht. Aber mit dieser Vorlage müsstest du was
machen können. Es ist wichtig, dass dieses CGI mittels httpd.conf
(Apache) oder .htaccess so geschützt wird, dass der User bereits
authentifiziert ist, wenn dieses Skript aufgerufen wird, sonst ist die
REMOTE_USER-Variable nicht gesetzt. Unter zwei Pizzen lehne ich übrigens
jeden Support für dieses Code-Snippet ab. :)

========
#!/usr/bin/perl -w
# Christoph Haas (email@christoph-haas.de)

my $quota_cmd = "/usr/bin/quota";
my $username = $ENV{'REMOTE_USER'};
my $partition = '/home';

use CGI;
$q = new CGI;
$q->import_names('Q');

print $q->header();
print $q->start_html("Current quota for $username");

die "Not authenticated" unless $username;

# setuid
my $user_uid = (getpwnam($username))[2];
$>=$user_uid;
$<=$user_uid;

my $runquota = "$quota_cmd -v -u $username";
open (Q, "$runquota |") or die;
while (<Q> !~ /^$partition/){};
my $quota_line = <Q>;
close Q;

$quota_line =~ /^\s+(\d+)(\D+)(\d+)\s+(\d+)/ or die;

# 512 byte blocks
my $mb_used = int($1/2048);
my $mb_soft = int($3/2048);
my $mb_hard = int($4/2048);

print "Username: $username";
print "Used:".$mb_used;
print "Soft quota: $mb_soft MB";
print "Hard quota: $mb_hard MB";

print $q->end_html;
========

 Christoph

-- 
~
~
".signature" [Modified] 3 lines --100%--                3,41         All



Reply to: