aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatteo Pasotti <matteo.pasotti@gmail.com>2014-10-05 21:42:06 +0200
committerMatteo Pasotti <matteo.pasotti@gmail.com>2014-10-05 21:42:06 +0200
commit108cb44c1e86aaabf334ec3d63eebe5286b4f780 (patch)
treef56f5c0d245574689129b60f2534f77056459cc0
parente1fe8ea0cb369036246522e7bf9401466b0c8174 (diff)
parent5b42f3332afcc5f42e9c028113af0ad65a5acf23 (diff)
downloadmanatools-108cb44c1e86aaabf334ec3d63eebe5286b4f780.tar
manatools-108cb44c1e86aaabf334ec3d63eebe5286b4f780.tar.gz
manatools-108cb44c1e86aaabf334ec3d63eebe5286b4f780.tar.bz2
manatools-108cb44c1e86aaabf334ec3d63eebe5286b4f780.tar.xz
manatools-108cb44c1e86aaabf334ec3d63eebe5286b4f780.zip
Merge branch 'master' of ssh://git.mageia.org/software/adminpanel
-rw-r--r--lib/AdminPanel/Module/Users.pm384
-rw-r--r--lib/AdminPanel/Shared.pm29
-rw-r--r--lib/AdminPanel/Shared/Users.pm532
3 files changed, 685 insertions, 260 deletions
diff --git a/lib/AdminPanel/Module/Users.pm b/lib/AdminPanel/Module/Users.pm
index 81ee1f41..a3210ef2 100644
--- a/lib/AdminPanel/Module/Users.pm
+++ b/lib/AdminPanel/Module/Users.pm
@@ -72,8 +72,6 @@ use POSIX qw(ceil);
use Config::Auto;
use File::ShareDir ':ALL';
-## USER is from userdrake
-use USER;
use utf8;
use Sys::Syslog;
use Glib;
@@ -125,20 +123,6 @@ has 'action_menu' => (
init_arg => undef,
);
-## Used by USER (for getting values? TODO need explanations, where?)
-has 'USER_GetValue' => (
- default => -65533,
- is => 'ro',
- isa => 'Int',
- init_arg => undef,
-);
-
-## Used by USER (for getting values? TODO need explanations, where?)
-has 'ctx' => (
- is => 'ro',
- init_arg => undef,
- builder => '_USERInitialize',
-);
## min UID was 500 now is 1000, let's change in a single point
has 'min_UID' => (
@@ -148,17 +132,6 @@ has 'min_UID' => (
init_arg => undef,
);
-sub _USERInitialize {
- my $self = shift;
-
- # $EUID: effective user identifier
- if ($EUID == 0) {
- return USER::ADMIN->new;
- }
-
- return undef;
-}
-
has 'edit_tab_widgets' => (
traits => ['Hash'],
default => sub { {} },
@@ -400,33 +373,6 @@ sub ChooseGroup {
#=============================================================
-=head2 _updateOrDelUsersInGroup
-
-=head3 INPUT
-
- $name: username
-
-=head3 DESCRIPTION
-
- Fixes user deletion into groups.
-
-=cut
-
-#=============================================================
-sub _updateOrDelUserInGroup {
- my ($self, $name) = @_;
- my $groups = $self->ctx->GroupsEnumerateFull;
- foreach my $g (@$groups) {
- my $members = $g->MemberName(1, 0);
- if ($self->_inArray($name, $members)) {
- eval { $g->MemberName($name, 2) };
- eval { $self->ctx->GroupModify($g) };
- }
- }
-}
-
-#=============================================================
-
=head2 _deleteGroupDialog
=head3 INPUT
@@ -483,21 +429,18 @@ sub _deleteGroupDialog {
last;
}
elsif ($widget == $deleteButton) {
- my $groupEnt = $self->ctx->LookupGroupByName($groupname);
- my $members = $self->ctx->EnumerateUsersByGroup($groupname);
- my $continue = 1;
- GLOOP: foreach my $username (@$members) {
- my $userEnt = $self->ctx->LookupUserByName($username);
- if ($userEnt && $userEnt->Gid($self->USER_GetValue) == $groupEnt->Gid($self->USER_GetValue)) {
- $self->sh_gui->msgBox({text => $self->loc->N("%s is a primary group for user %s\n Remove the user first",
- $groupname, $username)});
- $continue = 0;
- last GLOOP;
- }
+ my $username = $self->sh_users->isPrimaryGroup($groupname);
+ if (defined($username)) {
+ $self->sh_gui->msgBox({
+ text => $self->loc->N("%s is a primary group for user %s\n Remove the user first",
+ $groupname, $username
+ )
+ });
}
- if ($continue) {
- Sys::Syslog::syslog('info|local1', $self->loc->N("Removing group: %s", $groupname));
- eval { $self->ctx->GroupDel($groupEnt) };
+ else {
+ if ($self->sh_users->deleteGroup($groupname)) {
+ Sys::Syslog::syslog('info|local1', $self->loc->N("Removing group: %s", $groupname));
+ }
$self->_refresh();
}
last;
@@ -536,8 +479,9 @@ sub _deleteUserDialog {
}
my $username = $item->label();
- my $userEnt = $self->ctx->LookupUserByName($username);
- my $homedir = $userEnt->HomeDir($self->USER_GetValue);
+ my $homedir = $self->sh_users->getUserHome($username);
+ return if !defined($homedir);
+
## push application title
my $appTitle = yui::YUI::app()->applicationTitle();
@@ -583,25 +527,13 @@ sub _deleteUserDialog {
}
elsif ($widget == $deleteButton) {
Sys::Syslog::syslog('info|local1', $self->loc->N("Removing user: %s", $username));
- $self->ctx->UserDel($userEnt);
- $self->_updateOrDelUserInGroup($username);
- #Let's check out the user's primary group
- my $usergid = $userEnt->Gid($self->USER_GetValue);
- my $groupEnt = $self->ctx->LookupGroupById($usergid);
- if ($groupEnt) {
- my $member = $groupEnt->MemberName(1, 0);
- if (scalar(@$member) == 0 && $groupEnt->Gid($self->USER_GetValue) > 499) {
- $self->ctx->GroupDel($groupEnt);
- }
- }
- if ($checkhome->isChecked()) {
- eval { $self->ctx->CleanHome($userEnt) };
- $@ and $self->sh_gui->msgBox({text => $@}) and last;
- }
- if ($checkspool->isChecked()) {
- eval { $self->ctx->CleanSpool($userEnt) };
- $@ and $self->sh_gui->msgBox({text => $@}) and last;
- }
+ my $option = undef;
+ $option->{clean_home} = $checkhome->isChecked() if $checkhome->isChecked();
+ $option->{clean_spool} = $checkspool->isChecked() if $checkspool->isChecked();
+
+ my $err = $self->sh_users->deleteUser($username, $option);
+ $self->sh_gui->msgBox({text => $err}) if (defined($err));
+
#remove added icon
$self->sh_users->removeKdmIcon($username);
$self->_refresh();
@@ -678,31 +610,26 @@ sub _addGroupDialog {
## check data
my $groupname = $groupName->value();
my ($continue, $errorString) = $self->sh_users->valid_groupname($groupname);
- my $nm = $continue && $self->ctx->LookupGroupByName($groupname);
+ my $nm = $continue && $self->sh_users->groupNameExist($groupname);
if ($nm) {
$groupName->setValue("");
$errorString = $self->loc->N("Group already exists, please choose another Group Name");
$continue = 0;
}
- my $groupEnt = $self->ctx->InitGroup($groupname, $is_system);
-
+
my $gid = 0;
if ($continue && $gidManually->value()) {
if (($gid = $GID->value()) < 500) {
$errorString = "";
my $gidchoice = $self->sh_gui->ask_YesOrNo({ title => $self->loc->N(" Group Gid is < 500"),
text => $self->loc->N("Creating a group with a GID less than 500 is not recommended.\n Are you sure you want to do this?\n\n")});
- $continue = $gidchoice and $groupEnt->Gid($gid);
- } else {
- my $g = $self->ctx->LookupGroupById($gid);
- if ($g) {
+ $continue = $gidchoice;
+ } else {
+ if ($self->sh_users->groupIDExists($gid)) {
$errorString = "";
my $gidchoice = $self->sh_gui->ask_YesOrNo({title => $self->loc->N(" Group ID is already used "),
text => $self->loc->N("Creating a group with a non unique GID?\n\n")});
- $continue = $gidchoice and $groupEnt->Gid($gid);
- }
- else {
- $groupEnt and $groupEnt->Gid($gid);
+ $continue = $gidchoice;
}
}
}
@@ -714,7 +641,11 @@ sub _addGroupDialog {
}
else {
Sys::Syslog::syslog('info|local1', $self->loc->N("Adding group: %s ", $groupname));
- $self->ctx->GroupAdd($groupEnt);
+ $self->sh_users->addGroup({
+ groupname => $groupname,
+ gid => $gid,
+ is_system => $is_system,
+ });
$self->_refresh();
last;
}
@@ -757,7 +688,7 @@ sub _buildUserData {
my ($self, $layout, $selected_shell) = @_;
- my @shells = @{$self->ctx->GetUserShells};
+ my @shells = @{$self->sh_users->getUserShells()};
my $factory = yui::YUI::widgetFactory;
@@ -971,7 +902,7 @@ sub addUserDialog {
## check data
my $username = $userData{ login_name }->value();
my ($continue, $errorString) = $self->sh_users->valid_username($username);
- my $nm = $continue && $self->ctx->LookupUserByName($username);
+ my $nm = $continue && $self->sh_users->userNameExists($username);
if ($nm) {
$userData{ login_name }->setValue("");
$homeDir->setValue("");
@@ -987,46 +918,42 @@ sub addUserDialog {
$errorString = $self->loc->N("This password is too simple. \n Good passwords should be > 6 characters");
$continue = 0;
}
- my $userEnt = $continue && $self->ctx->InitUser($username, $is_system);
+ my $homedir;
if ($continue && $createHome->value()) {
- my $homedir = $homeDir->value();
+ $homedir = $homeDir->value();
if ( -d $homedir) {
$errorString = $self->loc->N("Home directory <%s> already exists.\nPlease uncheck the home creation option, or change the directory path name", $homedir);
$continue = 0;
}
else {
$dontcreatehomedir = 0;
- $userEnt and $userEnt->HomeDir($homedir);
}
} else {
$dontcreatehomedir = 1;
}
- my $uid = 0;
+ my $uid = -1;
if ($continue && $uidManually->value()) {
if (($uid = $UID->value()) < $self->min_UID) {
$errorString = "";
my $uidchoice = $self->sh_gui->ask_YesOrNo({title => $self->loc->N("User Uid is < %d", $self->min_UID),
text => $self->loc->N("Creating a user with a UID less than %d is not recommended.\nAre you sure you want to do this?\n\n", $self->min_UID)});
- $continue = $uidchoice and $userEnt->Uid($uid);
- } else {
- $userEnt and $userEnt->Uid($uid);
+ $continue = $uidchoice;
}
}
- my $gid = 0;
+ my $gid = undef;
if ($createGroup->value()) {
if ($continue) {
#Check if group exist
- my $gr = $self->ctx->LookupGroupByName($username);
- if ($gr) {
+ if ($self->sh_users->groupNameExists($username)) {
my $groupchoice = $self->ChooseGroup();
if ($groupchoice == 0 ) {
#You choose to put it in the existing group
- $gid = $gr->Gid($self->USER_GetValue);
+ $gid = $self->sh_users->groupID($username);
} elsif ($groupchoice == 1) {
# Put it in 'users' group
Sys::Syslog::syslog('info|local1', $self->loc->N("Putting %s to 'users' group",
$username));
- $gid = $self->sh_users->Add2UsersGroup($username, $self->ctx);
+ $gid = $self->sh_users->Add2UsersGroup($username);
}
else {
$errorString = "";
@@ -1034,14 +961,15 @@ sub addUserDialog {
}
} else {
#it's a new group: Add it
- my $newgroup = $self->ctx->InitGroup($username,$is_system);
+ $gid = $self->sh_users->addGroup({
+ groupname => $username,
+ is_system => $is_system,
+ });
Sys::Syslog::syslog('info|local1', $self->loc->N("Creating new group: %s", $username));
- $gid = $newgroup->Gid($self->USER_GetValue);
- $self->ctx->GroupAdd($newgroup);
}
}
} else {
- $continue and $gid = $self->sh_users->Add2UsersGroup($username, $self->ctx);
+ $continue and $gid = $self->sh_users->Add2UsersGroup($username);
}
if (!$continue) {
@@ -1055,12 +983,20 @@ sub addUserDialog {
my $loginshell = $userData{ login_shell }->value();
my $fullname = $userData{ full_name }->value();
utf8::decode($fullname);
- $userEnt->Gecos($fullname); $userEnt->LoginShell($loginshell);
- $userEnt->Gid($gid);
- $userEnt->ShadowMin(-1); $userEnt->ShadowMax(99999);
- $userEnt->ShadowWarn(-1); $userEnt->ShadowInact(-1);
- $self->ctx->UserAdd($userEnt, $is_system, $dontcreatehomedir);
- $self->ctx->UserSetPass($userEnt, $passwd);
+
+ my $userParams = {
+ username => $username,
+ is_system => $is_system,
+ donotcreatehome => $dontcreatehomedir,
+ shell => $loginshell,
+ fullname => $fullname,
+ gid => $gid,
+ password => $passwd,
+ };
+ $userParams->{uid} = $uid if $uid != -1;
+ $userParams->{homedir} = $homedir if !$dontcreatehomedir;
+ $self->sh_users->addUser($userParams);
+
defined $icon->label() and
$self->sh_users->addKdmIcon($username, $icon->label());
### TODO Migration wizard
@@ -1171,34 +1107,7 @@ sub _createGroupTable {
}
-#=============================================================
-
-=head2 _computeLockExpire
-=head3 INPUT
-
- $l: login user info
-
-=head3 OUTPUT
-
- $status: Locked, Expired, or empty string
-
-=head3 DESCRIPTION
-
- This method returns if the login is Locked, Expired or ok.
- Note this function is meant for internal use only
-
-=cut
-
-#=============================================================
-sub _computeLockExpire {
- my ( $self, $l ) = @_;
- my $ep = $l->ShadowExpire($self->USER_GetValue);
- my $tm = ceil(time()/(24*60*60));
- $ep = -1 if int($tm) <= $ep;
- my $status = $self->ctx->IsLocked($l) ? $self->loc->N("Locked") : ($ep != -1 ? $self->loc->N("Expired") : '');
- $status;
-}
#=============================================================
@@ -1223,7 +1132,7 @@ sub _refreshUsers {
my $filterusers = $self->get_widget('filter_system')->isChecked();
my ($users, $group, $groupnm, $expr);
- defined $self->ctx and $users = $self->ctx->UsersEnumerateFull;
+ defined $self->sh_users->ctx and $users = $self->sh_users->ctx->UsersEnumerateFull;
$self->dialog->startMultipleChanges();
#for some reasons QT send an event using table->selectItem()
@@ -1233,31 +1142,31 @@ sub _refreshUsers {
my @UserReal;
LOOP: foreach my $l (@$users) {
- next LOOP if $filterusers && $l->Uid($self->USER_GetValue) <= 499 || $l->Uid($self->USER_GetValue) == 65534;
- next LOOP if $filterusers && $l->Uid($self->USER_GetValue) > 499 && $l->Uid($self->USER_GetValue) < $self->min_UID &&
- ($l->HomeDir($self->USER_GetValue) =~ /^\/($|var\/|run\/)/ || $l->LoginShell($self->USER_GetValue) =~ /(nologin|false)$/);
- push @UserReal, $l if $l->UserName($self->USER_GetValue) =~ /^\Q$strfilt/;
+ next LOOP if $filterusers && $l->Uid($self->sh_users->USER_GetValue) <= 499 || $l->Uid($self->sh_users->USER_GetValue) == 65534;
+ next LOOP if $filterusers && $l->Uid($self->sh_users->USER_GetValue) > 499 && $l->Uid($self->sh_users->USER_GetValue) < $self->min_UID &&
+ ($l->HomeDir($self->sh_users->USER_GetValue) =~ /^\/($|var\/|run\/)/ || $l->LoginShell($self->sh_users->USER_GetValue) =~ /(nologin|false)$/);
+ push @UserReal, $l if $l->UserName($self->sh_users->USER_GetValue) =~ /^\Q$strfilt/;
}
my $i;
my $itemColl = new yui::YItemCollection;
foreach my $l (@UserReal) {
$i++;
- my $uid = $l->Uid($self->USER_GetValue);
+ my $uid = $l->Uid($self->sh_users->USER_GetValue);
if (!defined $uid) {
warn "bogus user at line $i\n";
next;
}
- my $a = $l->Gid($self->USER_GetValue);
- $group = $self->ctx->LookupGroupById($a);
+ my $a = $l->Gid($self->sh_users->USER_GetValue);
+ $group = $self->sh_users->ctx->LookupGroupById($a);
$groupnm = '';
- $expr = $self->_computeLockExpire($l);
- $group and $groupnm = $group->GroupName($self->USER_GetValue);
- my $fulln = $l->Gecos($self->USER_GetValue);
+ $expr = $self->sh_users->computeLockExpire($l);
+ $group and $groupnm = $group->GroupName($self->sh_users->USER_GetValue);
+ my $fulln = $l->Gecos($self->sh_users->USER_GetValue);
utf8::decode($fulln);
- my $username = $l->UserName($self->USER_GetValue);
- my $Uid = $l->Uid($self->USER_GetValue);
- my $shell = $l->LoginShell($self->USER_GetValue);
- my $homedir = $l->HomeDir($self->USER_GetValue);
+ my $username = $l->UserName($self->sh_users->USER_GetValue);
+ my $Uid = $l->Uid($self->sh_users->USER_GetValue);
+ my $shell = $l->LoginShell($self->sh_users->USER_GetValue);
+ my $homedir = $l->HomeDir($self->sh_users->USER_GetValue);
my $item = new yui::YTableItem ("$username",
"$Uid",
"$groupnm",
@@ -1303,7 +1212,7 @@ sub _refreshGroups {
my $filtergroups = $self->get_widget('filter_system')->isChecked();
my $groups;
- defined $self->ctx and $groups = $self->ctx->GroupsEnumerateFull;
+ defined $self->sh_users->ctx and $groups = $self->sh_users->ctx->GroupsEnumerateFull;
$self->dialog->startMultipleChanges();
#for some reasons QT send an event using table->selectItem()
@@ -1312,18 +1221,18 @@ sub _refreshGroups {
$self->get_widget('table')->deleteAllItems();
my @GroupReal;
LOOP: foreach my $g (@$groups) {
- next LOOP if $filtergroups && $g->Gid($self->USER_GetValue) <= 499 || $g->Gid($self->USER_GetValue) == 65534;
- push @GroupReal, $g if $g->GroupName($self->USER_GetValue) =~ /^\Q$strfilt/;
+ next LOOP if $filtergroups && $g->Gid($self->sh_users->USER_GetValue) <= 499 || $g->Gid($self->sh_users->USER_GetValue) == 65534;
+ push @GroupReal, $g if $g->GroupName($self->sh_users->USER_GetValue) =~ /^\Q$strfilt/;
}
my $itemColl = new yui::YItemCollection;
foreach my $g (@GroupReal) {
- my $a = $g->GroupName($self->USER_GetValue);
+ my $a = $g->GroupName($self->sh_users->USER_GetValue);
#my $group = $ctx->LookupGroupById($a);
- my $u_b_g = $a && $self->ctx->EnumerateUsersByGroup($a);
+ my $u_b_g = $a && $self->sh_users->ctx->EnumerateUsersByGroup($a);
my $listUbyG = join(',', @$u_b_g);
- my $group_id = $g->Gid($self->USER_GetValue);
- my $groupname = $g->GroupName($self->USER_GetValue);
+ my $group_id = $g->Gid($self->sh_users->USER_GetValue);
+ my $groupname = $g->GroupName($self->sh_users->USER_GetValue);
my $item = new yui::YTableItem ("$groupname",
"$group_id",
"$listUbyG");
@@ -1402,14 +1311,14 @@ sub _getUserInfo {
my %userData;
$userData{username} = $item->label();
- my $userEnt = $self->ctx->LookupUserByName($userData{username});
+ my $userEnt = $self->sh_users->ctx->LookupUserByName($userData{username});
- my $s = $userEnt->Gecos($self->USER_GetValue);
+ my $s = $userEnt->Gecos($self->sh_users->USER_GetValue);
utf8::decode($s);
$userData{full_name} = $s;
- $userData{shell} = $userEnt->LoginShell($self->USER_GetValue);
- $userData{homedir} = $userEnt->HomeDir($self->USER_GetValue);
- $userData{UID} = $userEnt->Uid($self->USER_GetValue);
+ $userData{shell} = $userEnt->LoginShell($self->sh_users->USER_GetValue);
+ $userData{homedir} = $userEnt->HomeDir($self->sh_users->USER_GetValue);
+ $userData{UID} = $userEnt->Uid($self->sh_users->USER_GetValue);
# default expiration time
my ($day, $mo, $ye) = (localtime())[3, 4, 5];
@@ -1417,7 +1326,7 @@ sub _getUserInfo {
$userData{acc_expm} = $mo+1;
$userData{acc_expd} = $day;
$userData{acc_check_exp} = 0;
- my $expire = $userEnt->ShadowExpire($self->USER_GetValue);
+ my $expire = $userEnt->ShadowExpire($self->sh_users->USER_GetValue);
if ($expire && $expire != -1) {
my $times = _TimeOfArray($expire, 1);
$userData{acc_expy} = $times->{year};
@@ -1432,14 +1341,14 @@ sub _getUserInfo {
$userData{password1} = undef;
# Check if user account is locked
- $userData{lockuser} = $self->ctx->IsLocked($userEnt);
+ $userData{lockuser} = $self->sh_users->ctx->IsLocked($userEnt);
$userData{icon_face} = $self->sh_users->GetFaceIcon($userData{username});
$userData{pwd_check_exp} = 0;
- $userData{pwd_exp_min} = $userEnt->ShadowMin($self->USER_GetValue);
- $userData{pwd_exp_max} = $userEnt->ShadowMax($self->USER_GetValue);
- $userData{pwd_exp_warn} = $userEnt->ShadowWarn($self->USER_GetValue);
- $userData{pwd_exp_inact} = $userEnt->ShadowInact($self->USER_GetValue);
+ $userData{pwd_exp_min} = $userEnt->ShadowMin($self->sh_users->USER_GetValue);
+ $userData{pwd_exp_max} = $userEnt->ShadowMax($self->sh_users->USER_GetValue);
+ $userData{pwd_exp_warn} = $userEnt->ShadowWarn($self->sh_users->USER_GetValue);
+ $userData{pwd_exp_inact} = $userEnt->ShadowInact($self->sh_users->USER_GetValue);
if ($userData{pwd_exp_min} && $userData{pwd_exp_min} != -1 ||
$userData{pwd_exp_max} && $userData{pwd_exp_max} != 99999 ||
@@ -1448,8 +1357,8 @@ sub _getUserInfo {
$userData{pwd_check_exp} = 1;
}
- $userData{members} = $self->ctx->EnumerateGroupsByUser($userData{username});
- $userData{primary_group} = $userEnt->Gid($self->USER_GetValue);
+ $userData{members} = $self->sh_users->ctx->EnumerateGroupsByUser($userData{username});
+ $userData{primary_group} = $userEnt->Gid($self->sh_users->USER_GetValue);
return %userData;
@@ -1494,8 +1403,8 @@ sub _getGroupInfo {
$groupData{start_groupname} = $item->label();
$groupData{groupname} = $item->label();
- my $groupEnt = $self->ctx->LookupGroupByName($groupData{groupname});
- $groupData{members} = $self->ctx->EnumerateUsersByGroup($groupData{groupname});
+ my $groupEnt = $self->sh_users->ctx->LookupGroupByName($groupData{groupname});
+ $groupData{members} = $self->sh_users->ctx->EnumerateUsersByGroup($groupData{groupname});
return %groupData;
@@ -1569,8 +1478,8 @@ sub _storeDataFromUserEditPreviousTab {
$userData{members} = [ @members ];
if ($self->get_edit_tab_widget('primary_group')->selectedItem()) {
- my $Gent = $self->ctx->LookupGroupByName($self->get_edit_tab_widget('primary_group')->selectedItem()->label());
- my $primgroup = $Gent->Gid($self->USER_GetValue);
+ my $Gent = $self->sh_users->ctx->LookupGroupByName($self->get_edit_tab_widget('primary_group')->selectedItem()->label());
+ my $primgroup = $Gent->Gid($self->sh_users->USER_GetValue);
$userData{primary_group} = $primgroup;
}
@@ -1766,8 +1675,8 @@ sub _userPasswordInfoTabWidget {
my $layout = $factory->createVBox($replace_pnt);
my %userPasswordWidget;
- my $userEnt = $self->ctx->LookupUserByName($userData{username});
- my $lastchg = $userEnt->ShadowLastChange($self->USER_GetValue);
+ my $userEnt = $self->sh_users->ctx->LookupUserByName($userData{username});
+ my $lastchg = $userEnt->ShadowLastChange($self->sh_users->USER_GetValue);
my $align = $factory->createLeft($layout);
my $hbox = $factory->createHBox($align);
@@ -1849,8 +1758,8 @@ sub _groupUsersTabWidget {
$groupUsersWidget{members} = $mgaFactory->createCBTable($layout, $yTableHeader, $yui::YCBTableCheckBoxOnFirstColumn);
- my $groupEnt = $self->ctx->LookupGroupByName($groupData{groupname});
- my $users = $self->ctx->UsersEnumerate;
+ my $groupEnt = $self->sh_users->ctx->LookupGroupByName($groupData{groupname});
+ my $users = $self->sh_users->ctx->UsersEnumerate;
my @susers = sort(@$users);
my $itemCollection = new yui::YItemCollection;
@@ -1884,8 +1793,8 @@ sub _userGroupsTabWidget {
$replace_pnt->deleteChildren();
my %userGroupsWidget;
- my $userEnt = $self->ctx->LookupUserByName($userData{username});
- my $lastchg = $userEnt->ShadowLastChange($self->USER_GetValue);
+ my $userEnt = $self->sh_users->ctx->LookupUserByName($userData{username});
+ my $lastchg = $userEnt->ShadowLastChange($self->sh_users->USER_GetValue);
my $layout = _labeledFrameBox($replace_pnt, $self->loc->N("Select groups that the user will be member of:"));
@@ -1895,7 +1804,7 @@ sub _userGroupsTabWidget {
$userGroupsWidget{members} = $mgaFactory->createCBTable($layout, $yTableHeader, $yui::YCBTableCheckBoxOnFirstColumn);
- my $grps = $self->ctx->GroupsEnumerate;
+ my $grps = $self->sh_users->ctx->GroupsEnumerate;
my @sgroups = sort @$grps;
my $itemCollection = new yui::YItemCollection;
@@ -1911,8 +1820,8 @@ sub _userGroupsTabWidget {
$userGroupsWidget{members}->setNotify(1);
my $primgroup = '';
if ($userData{primary_group} != -1) {
- my $Gent = $self->ctx->LookupGroupById($userData{primary_group});
- $primgroup = $Gent->GroupName($self->USER_GetValue);
+ my $Gent = $self->sh_users->ctx->LookupGroupById($userData{primary_group});
+ $primgroup = $Gent->GroupName($self->sh_users->USER_GetValue);
}
my $align = $factory->createLeft($layout);
@@ -1948,30 +1857,30 @@ sub _groupEdit_Ok {
$self->sh_gui->msgBox({text => $errorString}) if ($errorString);
return $continue;
}
- my $groupEnt = $self->ctx->LookupGroupByName($groupData{start_groupname});
+ my $groupEnt = $self->sh_users->ctx->LookupGroupByName($groupData{start_groupname});
if ($groupData{start_groupname} ne $groupData{groupname}) {
$groupEnt->GroupName($groupData{groupname});
}
my $members = $groupData{members};
- my $gid = $groupEnt->Gid($self->USER_GetValue);
- my $users = $self->ctx->UsersEnumerate;
+ my $gid = $groupEnt->Gid($self->sh_users->USER_GetValue);
+ my $users = $self->sh_users->ctx->UsersEnumerate;
my @susers = sort(@$users);
foreach my $user (@susers) {
- my $uEnt = $self->ctx->LookupGroupByName($user);
+ my $uEnt = $self->sh_users->ctx->LookupGroupByName($user);
if ($uEnt) {
- my $ugid = $uEnt->Gid($self->USER_GetValue);
- my $m = $self->ctx->EnumerateUsersByGroup($groupData{start_groupname});
+ my $ugid = $uEnt->Gid($self->sh_users->USER_GetValue);
+ my $m = $self->sh_users->ctx->EnumerateUsersByGroup($groupData{start_groupname});
if (MDK::Common::DataStructure::member($user, @$members)) {
- if (!$self->_inArray($user, $m)) {
+ if (!AdminPanel::Shared::inArray($user, $m)) {
if ($ugid != $gid) {
eval { $groupEnt->MemberName($user,1) };
}
}
}
else {
- if ($self->_inArray($user, $m)) {
+ if (AdminPanel::Shared::inArray($user, $m)) {
if ($ugid == $gid) {
$self->sh_gui->msgBox({text => $self->loc->N("You cannot remove user '%s' from their primary group", $user)});
return 0;
@@ -1984,7 +1893,7 @@ sub _groupEdit_Ok {
}
}
- $self->ctx->GroupModify($groupEnt);
+ $self->sh_users->ctx->GroupModify($groupEnt);
$self->_refresh();
return 1;
@@ -2006,39 +1915,39 @@ sub _userEdit_Ok {
$self->sh_gui->msgBox({text => $self->loc->N("Password Mismatch")});
return 0;
}
- my $userEnt = $self->ctx->LookupUserByName($userData{username});
+ my $userEnt = $self->sh_users->ctx->LookupUserByName($userData{username});
if ($userData{password} ne '') {
if ($self->sh_users->weakPasswordForSecurityLevel($userData{password})) {
$self->sh_gui->msgBox({text => $self->loc->N("This password is too simple. \n Good passwords should be > 6 characters")});
return 0;
}
- $self->ctx->UserSetPass($userEnt, $userData{password});
+ $self->sh_users->ctx->UserSetPass($userEnt, $userData{password});
}
$userEnt->UserName($userData{username});
$userEnt->Gecos($userData{full_name});
$userEnt->HomeDir($userData{homedir});
$userEnt->LoginShell($userData{shell});
- my $username = $userEnt->UserName($self->USER_GetValue);
- my $grps = $self->ctx->GroupsEnumerate;
+ my $username = $userEnt->UserName($self->sh_users->USER_GetValue);
+ my $grps = $self->sh_users->ctx->GroupsEnumerate;
my @sgroups = sort @$grps;
my $members = $userData{members};
foreach my $group (@sgroups) {
- my $gEnt = $self->ctx->LookupGroupByName($group);
- my $ugid = $gEnt->Gid($self->USER_GetValue);
+ my $gEnt = $self->sh_users->ctx->LookupGroupByName($group);
+ my $ugid = $gEnt->Gid($self->sh_users->USER_GetValue);
my $m = $gEnt->MemberName(1,0);
if (MDK::Common::DataStructure::member($group, @$members)) {
- if (!$self->_inArray($username, $m) && $userData{primary_group} != $ugid) {
+ if (!AdminPanel::Shared::inArray($username, $m) && $userData{primary_group} != $ugid) {
eval { $gEnt->MemberName($username, 1) };
- $self->ctx->GroupModify($gEnt);
+ $self->sh_users->ctx->GroupModify($gEnt);
}
}
else {
- if ($self->_inArray($username, $m)) {
+ if (AdminPanel::Shared::inArray($username, $m)) {
eval { $gEnt->MemberName($username, 2) };
- $self->ctx->GroupModify($gEnt);
+ $self->sh_users->ctx->GroupModify($gEnt);
}
}
}
@@ -2086,13 +1995,13 @@ sub _userEdit_Ok {
$userEnt->ShadowInact(-1);
}
- $self->ctx->UserModify($userEnt);
+ $self->sh_users->ctx->UserModify($userEnt);
if ($userData{lockuser}) {
- !$self->ctx->IsLocked($userEnt) and $self->ctx->Lock($userEnt);
+ !$self->sh_users->ctx->IsLocked($userEnt) and $self->sh_users->ctx->Lock($userEnt);
}
else {
- $self->ctx->IsLocked($userEnt) and $self->ctx->UnLock($userEnt);
+ $self->sh_users->ctx->IsLocked($userEnt) and $self->sh_users->ctx->UnLock($userEnt);
}
defined $userData{icon_face} and $self->sh_users->addKdmIcon($userData{username}, $userData{icon_face});
@@ -2261,8 +2170,8 @@ sub _editUserDialog {
for(my $i=0;$i < $tbl->itemsCount();$i++) {
if ($tbl->toCBYTableItem($tbl->item($i))->checked()) {
my $pgItem = new yui::YItem ($tbl->item($i)->label(), 0);
- my $Gent = $self->ctx->LookupGroupById($userData{primary_group});
- my $primgroup = $Gent->GroupName($self->USER_GetValue);
+ my $Gent = $self->sh_users->ctx->LookupGroupById($userData{primary_group});
+ my $primgroup = $Gent->GroupName($self->sh_users->USER_GetValue);
$pgItem->setSelected(1) if ($pgItem->label() eq $primgroup);
$itemColl->push($pgItem);
@@ -2747,33 +2656,6 @@ sub _skipShortcut {
return ($label);
}
-#=============================================================
-
-=head2 _inArray
-
-=head3 INPUT
-
- $self: this object
- $item: item to search
- $arr: array container
-
-=head3 OUTPUT
-
- true: if the array contains the item
-
-=head3 DESCRIPTION
-
-This method returns if an item is into the array container
-
-=cut
-
-#=============================================================
-sub _inArray {
- my ($self, $item, $arr) = @_;
-
- return grep( /^$item$/, @$arr );
-}
-
sub _ValidInt {
foreach my $i (@_) { $i =~ /\d+/ or return 0 }
diff --git a/lib/AdminPanel/Shared.pm b/lib/AdminPanel/Shared.pm
index b6c8fe15..51039970 100644
--- a/lib/AdminPanel/Shared.pm
+++ b/lib/AdminPanel/Shared.pm
@@ -89,6 +89,9 @@ our @EXPORT = qw(
distName
apcat
find
+ inArray
+ disable_x_screensaver
+ enable_x_screensaver
);
@@ -214,6 +217,32 @@ sub trim {
return $st;
}
+#=============================================================
+
+=head2 inArray
+
+=head3 INPUT
+
+ $self: this object
+ $item: item to search
+ $arr: array container
+
+=head3 OUTPUT
+
+ true: if the array contains the item
+
+=head3 DESCRIPTION
+
+This method returns if an item is into the array container
+
+=cut
+
+#=============================================================
+sub inArray {
+ my ($self, $item, $arr) = @_;
+
+ return grep( /^$item$/, @{$arr} );
+}
#=============================================================
diff --git a/lib/AdminPanel/Shared/Users.pm b/lib/AdminPanel/Shared/Users.pm
index 8797e848..cd253bd9 100644
--- a/lib/AdminPanel/Shared/Users.pm
+++ b/lib/AdminPanel/Shared/Users.pm
@@ -51,8 +51,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
=cut
-
-
use diagnostics;
use strict;
@@ -63,6 +61,11 @@ use File::Basename;
use File::Copy;
use File::Remove 'remove';
+## USER is from userdrake
+use USER;
+use English;
+use POSIX qw/ceil/;
+
use AdminPanel::Shared::Locales;
use AdminPanel::Shared;
@@ -121,6 +124,32 @@ sub _localeInitialize {
# TODO if we want to give the opportunity to test locally add dir_name => 'path'
}
+## Used by USER (for getting values? TODO need explanations, where?)
+has 'USER_GetValue' => (
+ default => -65533,
+ is => 'ro',
+ isa => 'Int',
+ init_arg => undef,
+);
+
+## Used by USER (for getting values? TODO need explanations, where?)
+has 'ctx' => (
+ is => 'ro',
+ init_arg => undef,
+ builder => '_USERInitialize',
+);
+
+sub _USERInitialize {
+ my $self = shift;
+
+ # $EUID: effective user identifier
+ if ($EUID == 0) {
+ return USER::ADMIN->new;
+ }
+
+ return undef;
+}
+
#=============================================================
@@ -238,13 +267,13 @@ sub face2png {
#=============================================================
-sub facenames() {
+sub facenames {
my $self = shift;
my $dir = $self->face_dir;
my @files = io->dir($dir)->all_files;
my @l = grep { /^[A-Z]/ } @files;
- my @namelist = map { my $f =fileparse($_->filename, qr/\Q.png\E/) } (@l ? @l : @files);
+ my @namelist = map { my $f = fileparse($_->filename, qr/\Q.png\E/) } (@l ? @l : @files);
return \@namelist;
}
@@ -400,6 +429,493 @@ sub valid_groupname {
#=============================================================
+=head2 updateOrDelUsersInGroup
+
+=head3 INPUT
+
+ $name: username
+
+=head3 DESCRIPTION
+
+ Fixes user deletion into groups.
+
+=cut
+
+#=============================================================
+sub updateOrDelUserInGroup {
+ my ($self, $name) = @_;
+ my $groups = $self->ctx->GroupsEnumerateFull;
+ foreach my $g (@$groups) {
+ my $members = $g->MemberName(1, 0);
+ if (AdminPanel::Shared::inArray($name, $members)) {
+ eval { $g->MemberName($name, 2) };
+ eval { $self->ctx->GroupModify($g) };
+ }
+ }
+}
+
+
+#=============================================================
+
+=head2 groupNameExists
+
+=head3 INPUT
+
+$groupname: the name of the group to check
+
+=head3 OUTPUT
+
+if group exists
+
+=head3 DESCRIPTION
+
+This method return if a given group exists
+
+=cut
+
+#=============================================================
+sub groupNameExists {
+ my ($self, $groupname) = @_;
+
+ return 0 if (!defined($groupname));
+
+ return (defined($self->ctx->LookupGroupByName($groupname)));
+}
+
+#=============================================================
+
+=head2 groupIDExists
+
+=head3 INPUT
+
+$group: the id of the group to check
+
+=head3 OUTPUT
+
+if group exists
+
+=head3 DESCRIPTION
+
+This method return if a given group exists
+
+=cut
+
+#=============================================================
+sub groupIDExists {
+ my ($self, $group) = @_;
+
+ return 0 if (!defined($group));
+
+ return (defined($self->ctx->LookupGroupById($group)));
+}
+
+
+#=============================================================
+
+=head2 groupID
+
+=head3 INPUT
+
+$groupname: group name
+
+=head3 OUTPUT
+
+groupid or undef
+
+=head3 DESCRIPTION
+
+This method returns the group id for the group name
+
+=cut
+
+#=============================================================
+sub groupID {
+ my ($self, $groupname) = @_;
+
+ my $gr = $self->ctx->LookupGroupByName($groupname);
+ return $gr->Gid($self->USER_GetValue) if ($gr);
+
+ return undef;
+}
+#=============================================================
+
+=head2 addGroup
+
+=head3 INPUT
+
+$params: HASH reference containing:
+ groupname => name of teh group to be added
+ gid => group id of the group to be added
+ is_system => is a system group?
+
+=head3 OUTPUT
+
+ $gid the actual group id
+
+=head3 DESCRIPTION
+
+This method add a group to system
+
+=cut
+
+#=============================================================
+
+sub addGroup {
+ my ($self, $params) = @_;
+
+ my $is_system = defined($params->{is_system}) ?
+ $params->{is_system} :
+ 0;
+
+ return -1 if !defined($params->{groupname});
+
+ my $groupEnt = $self->ctx->InitGroup($params->{groupname}, $is_system);
+
+ return -1 if !defined($groupEnt);
+
+ $groupEnt->Gid($params->{gid}) if defined($params->{gid});
+
+ $self->ctx->GroupAdd($groupEnt);
+
+ return $groupEnt->Gid($self->USER_GetValue);
+}
+
+#=============================================================
+
+=head2 groupMembers
+
+=head3 INPUT
+
+$groupname: The group name
+
+=head3 OUTPUT
+
+$members: ARRAY reference containing all the user belonging
+ to the given $groupname
+
+=head3 DESCRIPTION
+
+This method gets the group name and returns the users belonging
+to it
+
+=cut
+
+#=============================================================
+sub groupMembers {
+ my ($self, $groupname) = @_;
+
+ return $groupname if !defined($groupname);
+
+ my $groupEnt = $self->ctx->LookupGroupByName($groupname);
+ my $members = $self->ctx->EnumerateUsersByGroup($groupname);
+
+ return $members;
+}
+
+
+#=============================================================
+
+=head2 isPrimaryGroup
+
+=head3 INPUT
+
+$groupname: the name of the group
+
+=head3 OUTPUT
+
+$username: undef if it is primary group or the username for
+ which the group is the primary one.
+
+=head3 DESCRIPTION
+
+This methods check if the given group name is primary group
+for any users belonging to the group
+
+=cut
+
+#=============================================================
+sub isPrimaryGroup {
+ my ($self, $groupname) = @_;
+
+ return $groupname if !defined($groupname);
+
+ my $groupEnt = $self->ctx->LookupGroupByName($groupname);
+ my $members = $self->ctx->EnumerateUsersByGroup($groupname);
+ foreach my $username (@$members) {
+ my $userEnt = $self->ctx->LookupUserByName($username);
+ if ($userEnt && $userEnt->Gid($self->USER_GetValue) == $groupEnt->Gid($self->USER_GetValue)) {
+ return $username;
+ }
+ }
+ return undef;
+}
+
+
+#=============================================================
+
+=head2 deleteGroup
+
+=head3 INPUT
+
+$groupname: in_par_description
+
+=head3 OUTPUT
+
+0: if error occurred
+1: if removed
+
+=head3 DESCRIPTION
+
+This method remove the group from the system
+
+=cut
+
+#=============================================================
+sub deleteGroup {
+ my ($self, $groupname) = @_;
+
+ return 0 if !defined($groupname);
+
+ my $groupEnt = $self->ctx->LookupGroupByName($groupname);
+ eval { $self->ctx->GroupDel($groupEnt) };
+ return 0 if $@;
+
+ return 1;
+}
+
+#=============================================================
+
+=head2 getUserHome
+
+=head3 INPUT
+
+ $username: given user name
+
+=head3 OUTPUT
+
+ $homedir: user home directory
+
+=head3 DESCRIPTION
+
+ This method return the home directory belonging to the given
+ username
+
+=cut
+
+#=============================================================
+sub getUserHome {
+ my ($self, $username) = @_;
+
+ return $username if !defined($username);
+
+ my $userEnt = $self->ctx->LookupUserByName($username);
+ my $homedir = $userEnt->HomeDir($self->USER_GetValue);
+
+ return $homedir;
+}
+
+#=============================================================
+
+=head2 userNameExists
+
+=head3 INPUT
+
+$username: the name of the user to check
+
+=head3 OUTPUT
+
+if user exists
+
+=head3 DESCRIPTION
+
+This method return if a given user exists
+
+=cut
+
+#=============================================================
+sub userNameExists {
+ my ($self, $username) = @_;
+
+ return 0 if (!defined($username));
+
+ return (defined($self->ctx->LookupUserByName($username)));
+}
+
+#=============================================================
+
+=head2 computeLockExpire
+
+=head3 INPUT
+
+ $l: login user info
+
+=head3 OUTPUT
+
+ $status: Locked, Expired, or empty string
+
+=head3 DESCRIPTION
+
+ This method returns if the login is Locked, Expired or ok.
+ Note this function is meant for internal use only
+
+=cut
+
+#=============================================================
+sub computeLockExpire {
+ my ( $self, $l ) = @_;
+ my $ep = $l->ShadowExpire($self->USER_GetValue);
+ my $tm = ceil(time()/(24*60*60));
+ $ep = -1 if int($tm) <= $ep;
+ my $status = $self->ctx->IsLocked($l) ? $self->loc->N("Locked") : ($ep != -1 ? $self->loc->N("Expired") : '');
+ $status;
+}
+
+#=============================================================
+
+=head2 addUser
+
+=head3 INPUT
+
+$params: HASH reference containing:
+ username => name of teh user to be added
+ uid => user id of the username to be added
+ is_system => is a system user?
+ homedir => user home directory
+ donotcreatehome => do not create the home directory
+ shell => user shall
+ fullname => user full name
+ gid => group id for the user
+ shadowMin => min time password validity
+ shadowMax => max time password validity
+ shadowInact =>
+ shadowWarn =>
+ password => user password
+
+=head3 OUTPUT
+
+ 0 if errors 1 if ok
+
+=head3 DESCRIPTION
+
+This method add a user to system
+
+=cut
+
+#=============================================================
+
+sub addUser {
+ my ($self, $params) = @_;
+
+ return 0 if !defined($params->{username});
+
+ my $is_system = defined($params->{is_system}) ?
+ $params->{is_system} :
+ 0;
+
+ my $userEnt = $self->ctx->InitUser($params->{username}, $is_system);
+ return 0 if !defined($userEnt);
+
+
+ $userEnt->HomeDir($params->{homedir}) if defined($params->{homedir});
+ $userEnt->Uid($params->{uid}) if defined($params->{uid});
+ $userEnt->Gecos($params->{fullname}) if defined($params->{fullname});
+ $userEnt->LoginShell($params->{shell}) if defined($params->{shell});
+ $userEnt->Gid($params->{gid}) if defined ($params->{gid});
+ my $shd = defined ($params->{shadowMin}) ? $params->{shadowMin} : -1;
+ $userEnt->ShadowMin($shd);
+ $shd = defined ($params->{shadowMax}) ? $params->{shadowMax} : 99999;
+ $userEnt->ShadowMax($shd);
+ $shd = defined ($params->{shadowWarn}) ? $params->{shadowWarn} : -1;
+ $userEnt->ShadowWarn($shd);
+ $shd = defined ($params->{shadowInact}) ? $params->{shadowInact} : -1;
+ $userEnt->ShadowInact($shd);
+ $self->ctx->UserAdd($userEnt, $is_system, $params->{donotcreatehome});
+ $self->ctx->UserSetPass($userEnt, $params->{password});
+
+ return 1;
+}
+
+
+#=============================================================
+
+=head2 deleteUser
+
+=head3 INPUT
+
+$username: username to be deleted
+$options: HASH reference containing
+ clean_home => if home has to be removed
+ clean_spool => if sppol has to be removed
+
+=head3 OUTPUT
+
+error string or undef if no errors occurred
+
+=head3 DESCRIPTION
+
+This method delete a user from the system.
+
+=cut
+
+#=============================================================
+sub deleteUser {
+ my ($self, $username, $options) = @_;
+
+ return $username if !defined($username);
+
+ my $userEnt = $self->ctx->LookupUserByName($username);
+
+ $self->ctx->UserDel($userEnt);
+ $self->updateOrDelUserInGroup($username);
+ #Let's check out the user's primary group
+ my $usergid = $userEnt->Gid($self->USER_GetValue);
+ my $groupEnt = $self->ctx->LookupGroupById($usergid);
+ if ($groupEnt) {
+ my $member = $groupEnt->MemberName(1, 0);
+ # TODO check if 499 is ok nowadays
+ if (scalar(@$member) == 0 && $groupEnt->Gid($self->USER_GetValue) > 499) {
+ $self->ctx->GroupDel($groupEnt);
+ }
+ }
+ if (defined($options)) {
+ ## testing jusr if exists also undef is allowed
+ ## as valid option
+ if (exists($options->{clean_home})) {
+ eval { $self->ctx->CleanHome($userEnt) };
+ return $@ if $@;
+ }
+ if (exists($options->{clean_spool})) {
+ eval { $self->ctx->CleanSpool($userEnt) };
+ return $@ if $@;
+ }
+ }
+ return undef;
+}
+
+#=============================================================
+
+=head2 getUserShells
+
+
+=head3 OUTPUT
+
+GetUserShells: from libUSER
+
+=head3 DESCRIPTION
+
+This method returns the available shell
+
+=cut
+
+#=============================================================
+
+sub getUserShells {
+ my $self = shift;
+
+ return $self->ctx->GetUserShells;
+}
+#=============================================================
+
=head2 GetFaceIcon
=head3 INPUT
@@ -540,7 +1056,6 @@ sub weakPasswordForSecurityLevel {
=head3 INPUT
$name: username
- $ctx: USER::ADMIN object
=head3 OUTPUT
@@ -554,12 +1069,11 @@ Adds the given username $name to 'users' group
#=============================================================
sub Add2UsersGroup {
- my ($self, $name, $ctx) = @_;
- my $GetValue = -65533; ## Used by USER (for getting values? TODO need explanations, where?)
+ my ($self, $name) = @_;
- my $usersgroup = $ctx->LookupGroupByName('users');
+ my $usersgroup = $self->ctx->LookupGroupByName('users');
$usersgroup->MemberName($name, 1);
- return $usersgroup->Gid($GetValue);
+ return $usersgroup->Gid($self->USER_GetValue);
}