enhanced lamdaemon test

This commit is contained in:
Roland Gruber 2006-11-05 12:16:07 +00:00
parent c87dfec035
commit c71cd3049d
2 changed files with 197 additions and 174 deletions

View File

@ -89,12 +89,6 @@ sub get_fs { # Load mountpoints from mtab if enabled quotas
if ($< == 0 ) { # we are root
# Drop root Previleges
($<, $>) = ($>, $<);
if ($ARGV[0] eq "*test") {
use Quota; # Needed to get and set quotas
print "Perl quota module successfully installed.\n";
print "If you haven't seen any errors lamdaemon.pl was set up successfully.\n";
}
else {
# loop for every transmitted user
while (1) {
my $input = <STDIN>;
@ -102,6 +96,19 @@ if ($< == 0 ) { # we are root
$return = "";
@vals = split (' ', $input);
switch: {
# test if lamdaemon can be run
if (($vals[1] eq 'test')) {
# basic test
if ($vals[2] eq 'basic') {
$return = "Ok";
}
# quota test
elsif ($vals[2] eq 'quota') {
require Quota;
$return = "Ok";
}
last switch;
}
# Get user information
if (($vals[3] eq 'user') || ($vals[1] eq 'home')) { @user = getpwnam($vals[0]); }
else { @user = getgrnam($vals[0]); }
@ -156,7 +163,7 @@ if ($< == 0 ) { # we are root
last switch;
};
$vals[1] eq 'quota' && do {
use Quota; # Needed to get and set quotas
require Quota; # Needed to get and set quotas
get_fs(); # Load list of devices with enabled quotas
# Store quota information in array
@quota_temp1 = split (':', $vals[4]);
@ -234,7 +241,6 @@ if ($< == 0 ) { # we are root
print "$return\n";
}
}
}
else {
print "ERROR,Lamdaemon,Not called as root!\n";
}

View File

@ -93,7 +93,7 @@ if (!$stopTest) {
}
else {
echo "<td bgcolor=\"red\">" . _("Error") . "&nbsp;&nbsp;</td>\n";
echo "<td bgcolor=\"red\">" . _("Your LAM admin user must be a valid Unix account to work with lamdaemon!") . "</td>";
echo "<td bgcolor=\"red\">" . sprintf(_("Your LAM admin user (%s) must be a valid Unix account to work with lamdaemon!"), $credentials[0]) . "</td>";
$stopTest = true;
}
echo "</tr>\n";
@ -143,21 +143,35 @@ if (!$stopTest) {
flush();
// run lamdaemon and get user quotas
if (!$stopTest) {
echo "<tr class=\"userlist\">\n<td>" . _("Execute lamdaemon") . "&nbsp;&nbsp;</td>\n";
$stopTest = lamTestLamdaemon("+ test basic\n", $stopTest, $handle, _("Execute lamdaemon"));
$stopTest = lamTestLamdaemon("+ test quota\n", $stopTest, $handle, _("Lamdaemon: Quota module installed"));
$stopTest = lamTestLamdaemon("+ quota get user\n", $stopTest, $handle, _("Lamdaemon: read quotas"));
/**
* Runs a test case of lamdaemon.
*
* @param string $command test command
* @param boolean $stopTest specifies if test should be run
* @param connection $handle SSH connection
* @param string $testText describing text
* @return boolean true, if errors occured
*/
function lamTestLamdaemon($command, $stopTest, $handle, $testText) {
// run lamdaemon and get user quotas
if (!$stopTest) {
echo "<tr class=\"userlist\">\n<td>" . $testText . "&nbsp;&nbsp;</td>\n";
flush();
$lamdaemonOk = false;
$errorMessage = "";
$shell = ssh2_exec($handle, "sudo " . $_SESSION['config']->scriptPath);
$stderr = ssh2_fetch_stream($shell, SSH2_STREAM_STDERR);
fwrite($shell, "+ quota get user\n");
fwrite($shell, $command);
$return = array();
$time = time() + 20;
while (sizeof($return) < 1) {
if ($time < time()) {
$lamdaemonOk = false;
$errorMessage = _("Timeout while executing lamdaemon commands!");
$return[] = "ERROR," . _("Timeout while executing lamdaemon commands!");
break;
}
usleep(100);
@ -188,6 +202,9 @@ if (!$stopTest) {
$stopTest = true;
}
echo "</tr>\n";
}
flush();
return $stopTest;
}
echo "</table>\n";