aboutsummaryrefslogtreecommitdiffstats
path: root/lib/AdminPanel/Shared/Users.pm
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2014-10-06 23:04:13 +0200
committerAngelo Naselli <anaselli@linux.it>2014-10-06 23:04:13 +0200
commit0ebbb4d0eb180c6b95da35667ea70d740085a2dd (patch)
treea20f30dfb50e5635e28a63ac05e3570ba2cb3cdd /lib/AdminPanel/Shared/Users.pm
parentf4ac24e95ef87873b9ba8d05d359a60db0166913 (diff)
downloadcolin-keep-0ebbb4d0eb180c6b95da35667ea70d740085a2dd.tar
colin-keep-0ebbb4d0eb180c6b95da35667ea70d740085a2dd.tar.gz
colin-keep-0ebbb4d0eb180c6b95da35667ea70d740085a2dd.tar.bz2
colin-keep-0ebbb4d0eb180c6b95da35667ea70d740085a2dd.tar.xz
colin-keep-0ebbb4d0eb180c6b95da35667ea70d740085a2dd.zip
moved getUsersInfo to Shared::Users and updated
_refreshUsers accordingly
Diffstat (limited to 'lib/AdminPanel/Shared/Users.pm')
-rw-r--r--lib/AdminPanel/Shared/Users.pm92
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/AdminPanel/Shared/Users.pm b/lib/AdminPanel/Shared/Users.pm
index ce6f41a..0c23cc2 100644
--- a/lib/AdminPanel/Shared/Users.pm
+++ b/lib/AdminPanel/Shared/Users.pm
@@ -149,6 +149,13 @@ sub _USERInitialize {
return undef;
}
+## min UID was 500 now is 1000, let's change in a single point
+has 'min_UID' => (
+ default => 1000,
+ is => 'ro',
+ isa => 'Int',
+ init_arg => undef,
+);
#=============================================================
@@ -684,6 +691,91 @@ sub deleteGroup {
#=============================================================
+=head2 getUsersInfo
+
+=head3 INPUT
+
+$options: HASH reference containing
+ username_filter => username search string
+ filter_system => hides system users
+
+=head3 OUTPUT
+
+%users: HASH reference containing
+ username-1 => {
+ uid => user identifier
+ group => primary group name
+ gid => group identifier
+ fullname => user full name
+ home => home directory
+ shell => user shell
+ status => login status (locked, expired, etc)
+ }
+ username-2 => {
+ ...
+ }
+
+=head3 DESCRIPTION
+
+This method get users information (all or by using a filter)
+
+=cut
+
+#=============================================================
+sub getUsersInfo {
+ my ($self, $options) = @_;
+
+ my $usersInfo = {};
+ return $usersInfo if !defined $self->ctx;
+
+ my $strfilt = $options->{username_filter} if exists($options->{username_filter});
+ my $filterusers = $options->{filter_system} if exists($options->{filter_system});
+
+ my ($users, $group, $groupnm, $expr);
+ $users = $self->ctx->UsersEnumerateFull;
+
+ 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/;
+ }
+ my $i;
+ my $itemColl = new yui::YItemCollection;
+ foreach my $l (@UserReal) {
+ $i++;
+ my $uid = $l->Uid($self->USER_GetValue);
+ if (!defined $uid) {
+ warn "bogus user at line $i\n";
+ next;
+ }
+ my $gid = $l->Gid($self->USER_GetValue);
+ $group = $self->ctx->LookupGroupById($gid);
+ $groupnm = '';
+ $expr = $self->computeLockExpire($l);
+ $group and $groupnm = $group->GroupName($self->USER_GetValue);
+ my $fulln = $l->Gecos($self->USER_GetValue);
+ utf8::decode($fulln);
+ my $username = $l->UserName($self->USER_GetValue);
+ my $shell = $l->LoginShell($self->USER_GetValue);
+ my $homedir = $l->HomeDir($self->USER_GetValue);
+ $usersInfo->{"$username"} = {
+ uid => $uid,
+ group => $groupnm,
+ gid => $gid,
+ fullname => $fulln,
+ home => $homedir,
+ status => $expr,
+ shell => $shell,
+ };
+ }
+
+ return $usersInfo;
+}
+
+#=============================================================
+
=head2 getUserHome
=head3 INPUT