enhanced lamdaemon test
This commit is contained in:
parent
c87dfec035
commit
c71cd3049d
|
@ -89,150 +89,156 @@ 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>;
|
||||
chop($input);
|
||||
$return = "";
|
||||
@vals = split (' ', $input);
|
||||
switch: {
|
||||
# Get user information
|
||||
if (($vals[3] eq 'user') || ($vals[1] eq 'home')) { @user = getpwnam($vals[0]); }
|
||||
else { @user = getgrnam($vals[0]); }
|
||||
$vals[1] eq 'home' && do {
|
||||
switch2: {
|
||||
$vals[2] eq 'add' && do {
|
||||
# split homedir to set all directories below the last dir. to 0755
|
||||
my $path = $user[7];
|
||||
$path =~ s,/(?:[^/]*)$,,;
|
||||
($<, $>) = ($>, $<); # Get root privileges
|
||||
if (! -e $path) {
|
||||
system 'mkdir', '-m', '0755', '-p', $path; # Create paths to homedir
|
||||
# loop for every transmitted user
|
||||
while (1) {
|
||||
my $input = <STDIN>;
|
||||
chop($input);
|
||||
$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]); }
|
||||
$vals[1] eq 'home' && do {
|
||||
switch2: {
|
||||
$vals[2] eq 'add' && do {
|
||||
# split homedir to set all directories below the last dir. to 0755
|
||||
my $path = $user[7];
|
||||
$path =~ s,/(?:[^/]*)$,,;
|
||||
($<, $>) = ($>, $<); # Get root privileges
|
||||
if (! -e $path) {
|
||||
system 'mkdir', '-m', '0755', '-p', $path; # Create paths to homedir
|
||||
}
|
||||
if (! -e $user[7]) {
|
||||
system 'mkdir', '-m', '0755', $user[7]; # Create homedir itself
|
||||
system ("(cd /etc/skel && tar cf - .) | (cd $user[7] && tar xmf -)"); # Copy /etc/sekl into homedir
|
||||
system 'chown', '-hR', "$user[2]:$user[3]" , $user[7]; # Change owner to new user
|
||||
if (-e '/usr/sbin/useradd.local') {
|
||||
system '/usr/sbin/useradd.local', $user[0]; # run useradd-script
|
||||
}
|
||||
if (! -e $user[7]) {
|
||||
system 'mkdir', '-m', '0755', $user[7]; # Create homedir itself
|
||||
system ("(cd /etc/skel && tar cf - .) | (cd $user[7] && tar xmf -)"); # Copy /etc/sekl into homedir
|
||||
system 'chown', '-hR', "$user[2]:$user[3]" , $user[7]; # Change owner to new user
|
||||
if (-e '/usr/sbin/useradd.local') {
|
||||
system '/usr/sbin/useradd.local', $user[0]; # run useradd-script
|
||||
$return = "Ok";
|
||||
}
|
||||
else {
|
||||
$return = "ERROR,Lamdaemon,Home directory already exists.";
|
||||
}
|
||||
($<, $>) = ($>, $<); # Give up root previleges
|
||||
last switch2;
|
||||
};
|
||||
$vals[2] eq 'rem' && do {
|
||||
($<, $>) = ($>, $<); # Get root previliges
|
||||
if (-d $user[7] && $user[7] ne '/') {
|
||||
if ((stat($user[7]))[4] eq $user[2]) {
|
||||
system 'rm', '-R', $user[7]; # Delete Homedirectory
|
||||
if (-e '/usr/sbin/userdel.local') {
|
||||
system '/usr/sbin/userdel.local', $user[0];
|
||||
}
|
||||
$return = "Ok";
|
||||
}
|
||||
else {
|
||||
$return = "ERROR,Lamdaemon,Home directory already exists.";
|
||||
$return = "ERROR,Lamdaemon,Home directory not owned by $user[2].";
|
||||
}
|
||||
($<, $>) = ($>, $<); # Give up root previleges
|
||||
last switch2;
|
||||
};
|
||||
$vals[2] eq 'rem' && do {
|
||||
($<, $>) = ($>, $<); # Get root previliges
|
||||
if (-d $user[7] && $user[7] ne '/') {
|
||||
if ((stat($user[7]))[4] eq $user[2]) {
|
||||
system 'rm', '-R', $user[7]; # Delete Homedirectory
|
||||
if (-e '/usr/sbin/userdel.local') {
|
||||
system '/usr/sbin/userdel.local', $user[0];
|
||||
}
|
||||
$return = "Ok";
|
||||
}
|
||||
else {
|
||||
$return = "ERROR,Lamdaemon,Home directory not owned by $user[2].";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$return = "ERROR,Lamdaemon,Home directory does not exist.";
|
||||
}
|
||||
($<, $>) = ($>, $<); # Give up root previleges
|
||||
last switch2;
|
||||
};
|
||||
# Show error if undfined command is used
|
||||
$return = "ERROR,Lamdaemon,Unknown command $vals[2].";
|
||||
}
|
||||
last switch;
|
||||
};
|
||||
$vals[1] eq 'quota' && do {
|
||||
use 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]);
|
||||
$group=0;
|
||||
$i=0;
|
||||
while ($quota_temp1[$i]) {
|
||||
$j=0;
|
||||
@temp = split (',', $quota_temp1[$i]);
|
||||
while ($temp[$j]) {
|
||||
$quota[$i][$j] = $temp[$j];
|
||||
$j++;
|
||||
else {
|
||||
$return = "ERROR,Lamdaemon,Home directory does not exist.";
|
||||
}
|
||||
($<, $>) = ($>, $<); # Give up root previleges
|
||||
last switch2;
|
||||
};
|
||||
# Show error if undfined command is used
|
||||
$return = "ERROR,Lamdaemon,Unknown command $vals[2].";
|
||||
}
|
||||
last switch;
|
||||
};
|
||||
$vals[1] eq 'quota' && do {
|
||||
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]);
|
||||
$group=0;
|
||||
$i=0;
|
||||
while ($quota_temp1[$i]) {
|
||||
$j=0;
|
||||
@temp = split (',', $quota_temp1[$i]);
|
||||
while ($temp[$j]) {
|
||||
$quota[$i][$j] = $temp[$j];
|
||||
$j++;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
if ($vals[3] eq 'user') { $group=false; }
|
||||
else {
|
||||
$group=1;
|
||||
@quota_usr = @quota_grp;
|
||||
}
|
||||
switch2: {
|
||||
$vals[2] eq 'rem' && do {
|
||||
$i=0;
|
||||
($<, $>) = ($>, $<); # Get root privileges
|
||||
while ($quota_usr[$i][0]) {
|
||||
$dev = Quota::getqcarg($quota_usr[$i][1]);
|
||||
$return = Quota::setqlim($dev,$user[2],0,0,0,0,1,$group);
|
||||
$i++;
|
||||
}
|
||||
($<, $>) = ($>, $<); # Give up root previleges
|
||||
last switch2;
|
||||
};
|
||||
$vals[2] eq 'set' && do {
|
||||
$i=0;
|
||||
($<, $>) = ($>, $<); # Get root privileges
|
||||
while ($quota_usr[$i][0]) {
|
||||
$dev = Quota::getqcarg($quota[$i][0]);
|
||||
$return = Quota::setqlim($dev,$user[2],$quota[$i][1],$quota[$i][2],$quota[$i][3],$quota[$i][4],1,$group);
|
||||
if ($return == -1) {
|
||||
$return = "ERROR,Lamdaemon,Unable to set quota!";
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
if ($vals[3] eq 'user') { $group=false; }
|
||||
else {
|
||||
$group=1;
|
||||
@quota_usr = @quota_grp;
|
||||
}
|
||||
switch2: {
|
||||
$vals[2] eq 'rem' && do {
|
||||
$i=0;
|
||||
($<, $>) = ($>, $<); # Get root privileges
|
||||
while ($quota_usr[$i][0]) {
|
||||
}
|
||||
($<, $>) = ($>, $<); # Give up root previleges
|
||||
last switch2;
|
||||
};
|
||||
$vals[2] eq 'get' && do {
|
||||
$i=0;
|
||||
($<, $>) = ($>, $<); # Get root privileges
|
||||
while ($quota_usr[$i][0]) {
|
||||
if ($vals[0]ne'+') {
|
||||
$dev = Quota::getqcarg($quota_usr[$i][1]);
|
||||
$return = Quota::setqlim($dev,$user[2],0,0,0,0,1,$group);
|
||||
$i++;
|
||||
}
|
||||
($<, $>) = ($>, $<); # Give up root previleges
|
||||
last switch2;
|
||||
};
|
||||
$vals[2] eq 'set' && do {
|
||||
$i=0;
|
||||
($<, $>) = ($>, $<); # Get root privileges
|
||||
while ($quota_usr[$i][0]) {
|
||||
$dev = Quota::getqcarg($quota[$i][0]);
|
||||
$return = Quota::setqlim($dev,$user[2],$quota[$i][1],$quota[$i][2],$quota[$i][3],$quota[$i][4],1,$group);
|
||||
if ($return == -1) {
|
||||
$return = "ERROR,Lamdaemon,Unable to set quota!";
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
($<, $>) = ($>, $<); # Give up root previleges
|
||||
last switch2;
|
||||
};
|
||||
$vals[2] eq 'get' && do {
|
||||
$i=0;
|
||||
($<, $>) = ($>, $<); # Get root privileges
|
||||
while ($quota_usr[$i][0]) {
|
||||
if ($vals[0]ne'+') {
|
||||
$dev = Quota::getqcarg($quota_usr[$i][1]);
|
||||
@temp = Quota::query($dev,$user[2],$group);
|
||||
if ($temp[0]ne'') {
|
||||
if ($temp == -1) {
|
||||
$return = "ERROR,Lamdaemon,Unable to read quota!";
|
||||
}
|
||||
else {
|
||||
$return = "$quota_usr[$i][1],$temp[0],$temp[1],$temp[2],$temp[3],$temp[4],$temp[5],$temp[6],$temp[7]:$return";
|
||||
}
|
||||
@temp = Quota::query($dev,$user[2],$group);
|
||||
if ($temp[0]ne'') {
|
||||
if ($temp == -1) {
|
||||
$return = "ERROR,Lamdaemon,Unable to read quota!";
|
||||
}
|
||||
else {
|
||||
$return = "$quota_usr[$i][1],$temp[0],$temp[1],$temp[2],$temp[3],$temp[4],$temp[5],$temp[6],$temp[7]:$return";
|
||||
}
|
||||
else { $return = "$quota_usr[$i][1],0,0,0,0,0,0,0,0:$return"; }
|
||||
}
|
||||
else { $return = "$quota_usr[$i][1],0,0,0,0,0,0,0,0:$return"; }
|
||||
$i++;
|
||||
}
|
||||
($<, $>) = ($>, $<); # Give up root previleges
|
||||
last switch2;
|
||||
};
|
||||
$return = "ERROR,Lamdaemon,Unknown command $vals[2].";
|
||||
}
|
||||
};
|
||||
last switch;
|
||||
$return = "ERROR,Lamdaemon,Unknown command $vals[1].";
|
||||
else { $return = "$quota_usr[$i][1],0,0,0,0,0,0,0,0:$return"; }
|
||||
$i++;
|
||||
}
|
||||
($<, $>) = ($>, $<); # Give up root previleges
|
||||
last switch2;
|
||||
};
|
||||
$return = "ERROR,Lamdaemon,Unknown command $vals[2].";
|
||||
}
|
||||
};
|
||||
print "$return\n";
|
||||
}
|
||||
last switch;
|
||||
$return = "ERROR,Lamdaemon,Unknown command $vals[1].";
|
||||
};
|
||||
print "$return\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -93,7 +93,7 @@ if (!$stopTest) {
|
|||
}
|
||||
else {
|
||||
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;
|
||||
}
|
||||
echo "</tr>\n";
|
||||
|
@ -143,51 +143,68 @@ if (!$stopTest) {
|
|||
|
||||
flush();
|
||||
|
||||
// run lamdaemon and get user quotas
|
||||
if (!$stopTest) {
|
||||
echo "<tr class=\"userlist\">\n<td>" . _("Execute lamdaemon") . " </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 . " </td>\n";
|
||||
flush();
|
||||
$lamdaemonOk = false;
|
||||
$errorMessage = "";
|
||||
$shell = ssh2_exec($handle, "sudo " . $_SESSION['config']->scriptPath);
|
||||
$stderr = ssh2_fetch_stream($shell, SSH2_STREAM_STDERR);
|
||||
fwrite($shell, $command);
|
||||
$return = array();
|
||||
$time = time() + 20;
|
||||
while (sizeof($return) < 1) {
|
||||
if ($time < time()) {
|
||||
$lamdaemonOk = false;
|
||||
$return[] = "ERROR," . _("Timeout while executing lamdaemon commands!");
|
||||
break;
|
||||
}
|
||||
usleep(100);
|
||||
$read = split("\n", trim(fread($shell, 100000)));
|
||||
if ((sizeof($read) == 1) && (!isset($read[0]) || ($read[0] == ""))) continue;
|
||||
for ($i = 0; $i < sizeof($read); $i++) {
|
||||
$return[] = $read[$i];
|
||||
}
|
||||
}
|
||||
$errOut = @fread($stderr, 100000);
|
||||
if ((stripos($errOut, "sudoers") !== false) || (stripos($errOut, "sorry") !== false)) {
|
||||
$return[] = "ERROR," . _("Sudo is not setup correctly!") . "," . str_replace(",", " ", $errOut);
|
||||
}
|
||||
if ((sizeof($return) == 1) && (stripos($return[0], "error") === false)) {
|
||||
$lamdaemonOk = true;
|
||||
}
|
||||
if ($lamdaemonOk) {
|
||||
echo "<td bgcolor=\"green\">" . _("Ok") . "</td>";
|
||||
echo "<td bgcolor=\"green\">" . _("Lamdaemon successfully run.") . "</td>";
|
||||
}
|
||||
else {
|
||||
echo "<td bgcolor=\"red\">" . _("Error") . " </td>\n";
|
||||
echo "<td bgcolor=\"red\">\n";
|
||||
for ($i = 0; $i < sizeof($return); $i++) {
|
||||
call_user_func_array('StatusMessage', split(",", $return[$i]));
|
||||
}
|
||||
echo "</td>\n";
|
||||
$stopTest = true;
|
||||
}
|
||||
echo "</tr>\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");
|
||||
$return = array();
|
||||
$time = time() + 20;
|
||||
while (sizeof($return) < 1) {
|
||||
if ($time < time()) {
|
||||
$lamdaemonOk = false;
|
||||
$errorMessage = _("Timeout while executing lamdaemon commands!");
|
||||
break;
|
||||
}
|
||||
usleep(100);
|
||||
$read = split("\n", trim(fread($shell, 100000)));
|
||||
if ((sizeof($read) == 1) && (!isset($read[0]) || ($read[0] == ""))) continue;
|
||||
for ($i = 0; $i < sizeof($read); $i++) {
|
||||
$return[] = $read[$i];
|
||||
}
|
||||
}
|
||||
$errOut = @fread($stderr, 100000);
|
||||
if ((stripos($errOut, "sudoers") !== false) || (stripos($errOut, "sorry") !== false)) {
|
||||
$return[] = "ERROR," . _("Sudo is not setup correctly!") . "," . str_replace(",", " ", $errOut);
|
||||
}
|
||||
if ((sizeof($return) == 1) && (stripos($return[0], "error") === false)) {
|
||||
$lamdaemonOk = true;
|
||||
}
|
||||
if ($lamdaemonOk) {
|
||||
echo "<td bgcolor=\"green\">" . _("Ok") . "</td>";
|
||||
echo "<td bgcolor=\"green\">" . _("Lamdaemon successfully run.") . "</td>";
|
||||
}
|
||||
else {
|
||||
echo "<td bgcolor=\"red\">" . _("Error") . " </td>\n";
|
||||
echo "<td bgcolor=\"red\">\n";
|
||||
for ($i = 0; $i < sizeof($return); $i++) {
|
||||
call_user_func_array('StatusMessage', split(",", $return[$i]));
|
||||
}
|
||||
echo "</td>\n";
|
||||
$stopTest = true;
|
||||
}
|
||||
echo "</tr>\n";
|
||||
return $stopTest;
|
||||
}
|
||||
|
||||
echo "</table>\n";
|
||||
|
|
Loading…
Reference in New Issue