aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2014-10-11 19:06:25 +0200
committerAngelo Naselli <anaselli@linux.it>2014-10-11 19:06:25 +0200
commit26413fb9b2dd04171253d1480b8402cf5d74f0ad (patch)
tree447cec94818d1a9e76f6a1b3464a18aa4072d499 /lib
parent68df8b379529df413788a324044127f0a89476a0 (diff)
downloadmanatools-26413fb9b2dd04171253d1480b8402cf5d74f0ad.tar
manatools-26413fb9b2dd04171253d1480b8402cf5d74f0ad.tar.gz
manatools-26413fb9b2dd04171253d1480b8402cf5d74f0ad.tar.bz2
manatools-26413fb9b2dd04171253d1480b8402cf5d74f0ad.tar.xz
manatools-26413fb9b2dd04171253d1480b8402cf5d74f0ad.zip
moved getUserInfo to Shared
Diffstat (limited to 'lib')
-rw-r--r--lib/AdminPanel/Module/Users.pm48
-rw-r--r--lib/AdminPanel/Shared/Users.pm61
2 files changed, 83 insertions, 26 deletions
diff --git a/lib/AdminPanel/Module/Users.pm b/lib/AdminPanel/Module/Users.pm
index a238b7a0..ec995b04 100644
--- a/lib/AdminPanel/Module/Users.pm
+++ b/lib/AdminPanel/Module/Users.pm
@@ -1281,15 +1281,14 @@ sub _getUserInfo {
}
my %userData;
- $userData{username} = $item->label();
- my $userEnt = $self->sh_users->ctx->LookupUserByName($userData{username});
+ $userData{username} = $item->label();
+
+ my $userInfo = $self->sh_users->getUserInfo($userData{username});
- my $s = $userEnt->Gecos($self->sh_users->USER_GetValue);
- utf8::decode($s);
- $userData{full_name} = $s;
- $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);
+ $userData{full_name} = $userInfo->{fullname};
+ $userData{shell} = $userInfo->{shell};
+ $userData{homedir} = $userInfo->{home};
+ $userData{UID} = $userInfo->{uid};
# default expiration time
my ($day, $mo, $ye) = (localtime())[3, 4, 5];
@@ -1297,9 +1296,10 @@ sub _getUserInfo {
$userData{acc_expm} = $mo+1;
$userData{acc_expd} = $day;
$userData{acc_check_exp} = 0;
- my $expire = $userEnt->ShadowExpire($self->sh_users->USER_GetValue);
+
+ my $expire = $userInfo->{expire};
if ($expire && $expire != -1) {
- my $times = _TimeOfArray($expire, 1);
+ my $times = _TimeOfArray($expire, 1);
$userData{acc_expy} = $times->{year};
$userData{acc_expm} = $times->{month};
$userData{acc_expd} = $times->{dayint};
@@ -1310,29 +1310,27 @@ sub _getUserInfo {
# to change it has to insert a new one
$userData{password} = undef;
$userData{password1} = undef;
- # Check if user account is locked
-
- $userData{lockuser} = $self->sh_users->ctx->IsLocked($userEnt);
+ $userData{lockuser} = $userInfo->{locked};
+ $DB::single = 1;
$userData{icon_face} = $self->sh_users->GetFaceIcon($userData{username});
+
$userData{pwd_check_exp} = 0;
- $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 ||
- $userData{pwd_exp_warn} && $userData{pwd_exp_warn} != 7 && $userData{pwd_exp_warn} != -1 ||
+ $userData{pwd_exp_min} = $userInfo->{exp_min};
+ $userData{pwd_exp_max} = $userInfo->{exp_max};
+ $userData{pwd_exp_warn} = $userInfo->{exp_warn};
+ $userData{pwd_exp_inact} = $userInfo->{exp_inact};
+ if ($userData{pwd_exp_min} && $userData{pwd_exp_min} != -1 ||
+ $userData{pwd_exp_max} && $userData{pwd_exp_max} != 99999 ||
+ $userData{pwd_exp_warn} && $userData{pwd_exp_warn} != 7 && $userData{pwd_exp_warn} != -1 ||
$userData{pwd_exp_inact} && $userData{pwd_exp_inact} != -1) {
$userData{pwd_check_exp} = 1;
}
- $userData{members} = $self->sh_users->ctx->EnumerateGroupsByUser($userData{username});
- $userData{primary_group} = $userEnt->Gid($self->sh_users->USER_GetValue);
-
- return %userData;
+ $userData{members} = $userInfo->{members};
+ $userData{primary_group} = $userInfo->{gid};
+ return %userData;
}
#=============================================================
diff --git a/lib/AdminPanel/Shared/Users.pm b/lib/AdminPanel/Shared/Users.pm
index 52e939b6..58b1a418 100644
--- a/lib/AdminPanel/Shared/Users.pm
+++ b/lib/AdminPanel/Shared/Users.pm
@@ -775,6 +775,65 @@ sub getGroupsInfo {
#=============================================================
+=head2 getUserInfo
+
+=head3 INPUT
+
+ $username: user name
+
+=head3 OUTPUT
+
+$userInfo: HASH reference containing
+ uid => user identifier
+ gid => group identifier
+ fullname => user full name
+ home => home directory
+ shell => user shell
+ expire => shadow expire time
+ locked => is locked?
+ exp_min => shadow Min
+ exp_max => shadow Max
+ exp_warn => shadow Warn
+ exp_inact=> shadow Inact
+ members => groups the user belongs to
+
+=head3 DESCRIPTION
+
+This method get all the information for the given user
+
+=cut
+
+#=============================================================
+sub getUserInfo {
+ my ($self, $username) = @_;
+
+ my $userInfo = {};
+ return $userInfo if !defined $self->ctx;
+
+ my $userEnt = $self->ctx->LookupUserByName($username);
+ return $userInfo if !defined($userEnt);
+
+ my $fullname = $userEnt->Gecos($self->USER_GetValue);
+ utf8::decode($fullname);
+ $userInfo->{fullname} = $fullname;
+ $userInfo->{shell} = $userEnt->LoginShell($self->USER_GetValue);
+ $userInfo->{home} = $userEnt->HomeDir($self->USER_GetValue);
+ $userInfo->{uid} = $userEnt->Uid($self->USER_GetValue);
+ $userInfo->{gid} = $userEnt->Gid($self->USER_GetValue);
+ $userInfo->{expire} = $userEnt->ShadowExpire($self->USER_GetValue);
+ $userInfo->{locked} = $self->ctx->IsLocked($userEnt);
+
+ $userInfo->{exp_min} = $userEnt->ShadowMin($self->USER_GetValue);
+ $userInfo->{exp_max} = $userEnt->ShadowMax($self->USER_GetValue);
+ $userInfo->{exp_warn} = $userEnt->ShadowWarn($self->USER_GetValue);
+ $userInfo->{exp_inact} = $userEnt->ShadowInact($self->USER_GetValue);
+ $userInfo->{members} = $self->ctx->EnumerateGroupsByUser($username);
+
+ return $userInfo;
+}
+
+#=============================================================
+
=head2 getUsersInfo
=head3 INPUT
@@ -943,7 +1002,7 @@ sub computeLockExpire {
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;
+ return $status;
}
#=============================================================