# listPoolSnap.pl
#
# by Vijayababu Dandi
# Version 1.0
# Aug 31, 2009
##############################################################################################
# Perl must be installed and running on the Linux server where this utility will be used.
# NSS must be installed to get the VFS support.
# (The SDK for this API set can be downloaded from http://developer.novell.com/wiki/index.php/# Virtual_File_Services_for_NetWare.)
##############################################################################################
#
# This is used to get the user quotas assigned to a volume.
#
##############################################################################################
sub SetDataStream($*)
{
my $fh = $_[0];
my $datastream = $_[1];
my $command;
my $result;
my $error;
$command = "";
seek $fh, 0, 0;
if (!syswrite($fh, $command, length($command)))
{
$result .= "Unable to send datastream command to NDS management. ";
seek $fh, 0, 0;
if (sysread($fh,$error, 1000))
{
$result .= $error;
}
$result .= "\n";
}
return $result;
}
sub WriteCommand($*)
{
my $fh = $_[0];
my $result;
my $reply;
my $error;
my $command = $_[1];
seek $fh, 0, 0;
if (!syswrite($fh, $command, length($command)))
{
$result .= "Unable to send command to virtual file. ";
seek $fh, 0, 0;
if (sysread($fh, $error, 1000))
{
$result .= $error;
}
$result .= "\n";
}
else
{
seek $fh, 0, 0;
my $readLen = 999;
while ($readLen)
{
$readLen = sysread($fh, $reply, 1000);
$result .= $reply;
}
}
return $result;
}
sub userQuota($)
{
my $volName = $_[0];
my $result;
my $ret;
my $nssResult;
$command = "00000000-0000-0000-00-00-000000000000100
";
if (!($ret = SetDataStream(FILE, "command")))
{
$result .= $ret;
$nssResult = WriteCommand(FILE,"$command");
}
ParseUserQuota($nssResult);
}
sub ParseUserQuota($)
{
my $xml = $_[0];
my $result;
my @xml;
my $ret;
my $size;
my $errno;
my $usedSize;
my $description;
my $reporter;
my $userCount = 0;
@xml = $xml =~ /(.*?)<\/userQuota>/gs;
$ret ='';
foreach $result (@xml)
{
if ($result =~ //s)
{
$errno = $1;
}
if ($result =~ /(.*?)<\/description>/gs)
{
$description = $1;
}
if ($result =~ /(.*?)<\/reporter>/gs)
{
$reporter = $1;
}
if ($errno != 0)
{
print "\n-----------------------------------------------------------\n".
"Error No : $errno\n".
"Description : $description\n".
"Reporter : $reporter\n".
"-----------------------------------------------------------\n";
return;
}
@xmlTemp = $result =~ /(.*?)<\/user>/gs;
foreach $result (@xmlTemp)
{
my $userName = "";
if ($result =~ /(.*?)<\/userName>/s)
{
$userName = $1;
$userCount++;
}
if ($result =~ /(.*?)<\/quota>/s)
{
$size = $1 / (1024 * 1024);
}
else
{
$size = "fullyRestricted";
}
if ($result =~ /(.*?)<\/spaceUsed>/s)
{
$usedSize = $1 / (1024 * 1024);
}
print "\n---------------------------------------------------------\n".
"user Name : $userName \n".
"quota (in MB) : $size \n".
"used Space (in MB) : $usedSize \n".
"----------------------------------------------------------\n";
}
}
if ($userCount == 0)
{
print "\n------------------------------------------------\n".
" No User Quotas \n".
"-------------------------------------------------\n";
}
return 0;
}
open(FILE,"+>", "/_admin/Manage_NSS/user.cmd")
or die "Error opening NSS management file ($!) on server";
MAIN :while (1)
{
my $action;
do
{
print "1.To get user quota on a volume\n".
"2.Exit\n".
"Select Action: ";
chomp($action = );
}while ($action != 0 && ($action < 1 || $action > 2));
if ($action == 1)
{
my $dirName;
print "Enter Volume Name to find user quotas: ";
chomp($dirName = );
userQuota($dirName);
}
else
{
exit(0);
}
}
close(FILE);