enhanced lamdaemon test
This commit is contained in:
parent
c87dfec035
commit
c71cd3049d
|
@ -89,12 +89,6 @@ sub get_fs { # Load mountpoints from mtab if enabled quotas
|
||||||
if ($< == 0 ) { # we are root
|
if ($< == 0 ) { # we are root
|
||||||
# Drop root Previleges
|
# 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
|
# loop for every transmitted user
|
||||||
while (1) {
|
while (1) {
|
||||||
my $input = <STDIN>;
|
my $input = <STDIN>;
|
||||||
|
@ -102,6 +96,19 @@ if ($< == 0 ) { # we are root
|
||||||
$return = "";
|
$return = "";
|
||||||
@vals = split (' ', $input);
|
@vals = split (' ', $input);
|
||||||
switch: {
|
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
|
# Get user information
|
||||||
if (($vals[3] eq 'user') || ($vals[1] eq 'home')) { @user = getpwnam($vals[0]); }
|
if (($vals[3] eq 'user') || ($vals[1] eq 'home')) { @user = getpwnam($vals[0]); }
|
||||||
else { @user = getgrnam($vals[0]); }
|
else { @user = getgrnam($vals[0]); }
|
||||||
|
@ -156,7 +163,7 @@ if ($< == 0 ) { # we are root
|
||||||
last switch;
|
last switch;
|
||||||
};
|
};
|
||||||
$vals[1] eq 'quota' && do {
|
$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
|
get_fs(); # Load list of devices with enabled quotas
|
||||||
# Store quota information in array
|
# Store quota information in array
|
||||||
@quota_temp1 = split (':', $vals[4]);
|
@quota_temp1 = split (':', $vals[4]);
|
||||||
|
@ -234,7 +241,6 @@ if ($< == 0 ) { # we are root
|
||||||
print "$return\n";
|
print "$return\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
print "ERROR,Lamdaemon,Not called as root!\n";
|
print "ERROR,Lamdaemon,Not called as root!\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ if (!$stopTest) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
echo "<td bgcolor=\"red\">" . _("Error") . " </td>\n";
|
echo "<td bgcolor=\"red\">" . _("Error") . " </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;
|
$stopTest = true;
|
||||||
}
|
}
|
||||||
echo "</tr>\n";
|
echo "</tr>\n";
|
||||||
|
@ -143,21 +143,35 @@ if (!$stopTest) {
|
||||||
|
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
// run lamdaemon and get user quotas
|
$stopTest = lamTestLamdaemon("+ test basic\n", $stopTest, $handle, _("Execute lamdaemon"));
|
||||||
if (!$stopTest) {
|
$stopTest = lamTestLamdaemon("+ test quota\n", $stopTest, $handle, _("Lamdaemon: Quota module installed"));
|
||||||
echo "<tr class=\"userlist\">\n<td>" . _("Execute lamdaemon") . " </td>\n";
|
$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 . " </td>\n";
|
||||||
flush();
|
flush();
|
||||||
$lamdaemonOk = false;
|
$lamdaemonOk = false;
|
||||||
$errorMessage = "";
|
$errorMessage = "";
|
||||||
$shell = ssh2_exec($handle, "sudo " . $_SESSION['config']->scriptPath);
|
$shell = ssh2_exec($handle, "sudo " . $_SESSION['config']->scriptPath);
|
||||||
$stderr = ssh2_fetch_stream($shell, SSH2_STREAM_STDERR);
|
$stderr = ssh2_fetch_stream($shell, SSH2_STREAM_STDERR);
|
||||||
fwrite($shell, "+ quota get user\n");
|
fwrite($shell, $command);
|
||||||
$return = array();
|
$return = array();
|
||||||
$time = time() + 20;
|
$time = time() + 20;
|
||||||
while (sizeof($return) < 1) {
|
while (sizeof($return) < 1) {
|
||||||
if ($time < time()) {
|
if ($time < time()) {
|
||||||
$lamdaemonOk = false;
|
$lamdaemonOk = false;
|
||||||
$errorMessage = _("Timeout while executing lamdaemon commands!");
|
$return[] = "ERROR," . _("Timeout while executing lamdaemon commands!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
usleep(100);
|
usleep(100);
|
||||||
|
@ -188,6 +202,9 @@ if (!$stopTest) {
|
||||||
$stopTest = true;
|
$stopTest = true;
|
||||||
}
|
}
|
||||||
echo "</tr>\n";
|
echo "</tr>\n";
|
||||||
|
}
|
||||||
|
flush();
|
||||||
|
return $stopTest;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
|
|
Loading…
Reference in New Issue