diff options
author | Matteo Pasotti <matteo.pasotti@gmail.com> | 2014-10-09 19:57:31 +0200 |
---|---|---|
committer | Matteo Pasotti <matteo.pasotti@gmail.com> | 2014-10-09 19:57:31 +0200 |
commit | 8551902ed3639307e321930a088604a41c115fe6 (patch) | |
tree | d51a75eeac61db46a2df9d242edeff9bcbe8bce1 /lib | |
parent | 108cb44c1e86aaabf334ec3d63eebe5286b4f780 (diff) | |
parent | 0ebbb4d0eb180c6b95da35667ea70d740085a2dd (diff) | |
download | manatools-8551902ed3639307e321930a088604a41c115fe6.tar manatools-8551902ed3639307e321930a088604a41c115fe6.tar.gz manatools-8551902ed3639307e321930a088604a41c115fe6.tar.bz2 manatools-8551902ed3639307e321930a088604a41c115fe6.tar.xz manatools-8551902ed3639307e321930a088604a41c115fe6.zip |
Merge branch 'master' of ssh://git.mageia.org/software/adminpanel
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AdminPanel/Module.pm | 2 | ||||
-rw-r--r-- | lib/AdminPanel/Module/Clock.pm | 1 | ||||
-rw-r--r-- | lib/AdminPanel/Module/LogViewer.pm | 1 | ||||
-rw-r--r-- | lib/AdminPanel/Module/Services.pm | 1 | ||||
-rw-r--r-- | lib/AdminPanel/Module/Users.pm | 72 | ||||
-rw-r--r-- | lib/AdminPanel/Shared/GUI.pm | 7 | ||||
-rw-r--r-- | lib/AdminPanel/Shared/JournalCtl.pm | 4 | ||||
-rw-r--r-- | lib/AdminPanel/Shared/Users.pm | 95 |
8 files changed, 119 insertions, 64 deletions
diff --git a/lib/AdminPanel/Module.pm b/lib/AdminPanel/Module.pm index acddc8ff..cdb54a0b 100644 --- a/lib/AdminPanel/Module.pm +++ b/lib/AdminPanel/Module.pm @@ -30,8 +30,6 @@ Version 0.01 our $VERSION = '1.0.0'; -use strict; -use warnings; use diagnostics; use yui; diff --git a/lib/AdminPanel/Module/Clock.pm b/lib/AdminPanel/Module/Clock.pm index b96f1c70..5a75f328 100644 --- a/lib/AdminPanel/Module/Clock.pm +++ b/lib/AdminPanel/Module/Clock.pm @@ -53,7 +53,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA use Moose; use diagnostics; -use strict; use AdminPanel::Shared::GUI; use AdminPanel::Shared::Locales; diff --git a/lib/AdminPanel/Module/LogViewer.pm b/lib/AdminPanel/Module/LogViewer.pm index 28c0d67a..a91a1642 100644 --- a/lib/AdminPanel/Module/LogViewer.pm +++ b/lib/AdminPanel/Module/LogViewer.pm @@ -51,7 +51,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA use Moose; use diagnostics; -use strict; use open OUT => ':utf8'; use AdminPanel::Shared::GUI; diff --git a/lib/AdminPanel/Module/Services.pm b/lib/AdminPanel/Module/Services.pm index 006ca49d..4704c802 100644 --- a/lib/AdminPanel/Module/Services.pm +++ b/lib/AdminPanel/Module/Services.pm @@ -57,7 +57,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA use Moose; -use strict; use English; use MDK::Common::String qw(formatAlaTeX); diff --git a/lib/AdminPanel/Module/Users.pm b/lib/AdminPanel/Module/Users.pm index a3210ef2..f7815f4f 100644 --- a/lib/AdminPanel/Module/Users.pm +++ b/lib/AdminPanel/Module/Users.pm @@ -66,8 +66,8 @@ our $VERSION = '1.0.0'; ## ############################################### +use Moose; -use strict; use POSIX qw(ceil); use Config::Auto; use File::ShareDir ':ALL'; @@ -83,7 +83,6 @@ use AdminPanel::Shared::Locales; use AdminPanel::Shared::Users; use MDK::Common::DataStructure qw(member); -use Moose; extends qw( AdminPanel::Module ); has '+icon' => ( @@ -124,14 +123,6 @@ has 'action_menu' => ( ); -## 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, -); - has 'edit_tab_widgets' => ( traits => ['Hash'], default => sub { {} }, @@ -846,7 +837,7 @@ sub addUserDialog { $hbox = $factory->createHBox($align); my $uidManually = $factory->createCheckBox($hbox, $self->loc->N("Specify user ID manually"), 0); $factory->createHSpacing($hbox, 2.0); - my $UID = $factory->createIntField($hbox, $self->loc->N("UID"), 1, 65000, $self->min_UID); + my $UID = $factory->createIntField($hbox, $self->loc->N("UID"), 1, 65000, $self->sh_users->min_UID); $UID->setEnabled($uidManually->value()); $uidManually->setNotify(1); # $uidManually->setWeight($yui::YD_HORIZ, 2); @@ -933,10 +924,10 @@ sub addUserDialog { } my $uid = -1; if ($continue && $uidManually->value()) { - if (($uid = $UID->value()) < $self->min_UID) { + if (($uid = $UID->value()) < $self->sh_users->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)}); + my $uidchoice = $self->sh_gui->ask_YesOrNo({title => $self->loc->N("User Uid is < %d", $self->sh_users->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->sh_users->min_UID)}); $continue = $uidchoice; } } @@ -1131,8 +1122,11 @@ sub _refreshUsers { my $strfilt = $self->get_widget('filter')->value(); my $filterusers = $self->get_widget('filter_system')->isChecked(); - my ($users, $group, $groupnm, $expr); - defined $self->sh_users->ctx and $users = $self->sh_users->ctx->UsersEnumerateFull; + my $usersInfo = $self->sh_users->getUsersInfo({ + username_filter => $strfilt, + filter_system => $filterusers, + }); + $self->dialog->startMultipleChanges(); #for some reasons QT send an event using table->selectItem() @@ -1140,46 +1134,26 @@ sub _refreshUsers { $self->get_widget('table')->setImmediateMode(0); $self->get_widget('table')->deleteAllItems(); - my @UserReal; - LOOP: foreach my $l (@$users) { - 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->sh_users->USER_GetValue); - if (!defined $uid) { - warn "bogus user at line $i\n"; - next; - } - my $a = $l->Gid($self->sh_users->USER_GetValue); - $group = $self->sh_users->ctx->LookupGroupById($a); - $groupnm = ''; - $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->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", - "$fulln", - "$shell", - "$homedir", - "$expr"); + foreach my $username (keys %{$usersInfo}) { + my $info = $usersInfo->{$username}; + my $item = new yui::YTableItem ( + "$username", + "$info->{uid}", + "$info->{group}", + "$info->{fullname}", + "$info->{shell}", + "$info->{home}", + "$info->{status}" + ); + # TODO workaround to get first cell at least until we don't # a cast from YItem $item->setLabel( $username ); $itemColl->push($item); $item->DISOWN(); } + $self->get_widget('table')->addItems($itemColl); my $item = $self->get_widget('table')->selectedItem(); $self->get_widget('table')->selectItem($item, 0) if $item; diff --git a/lib/AdminPanel/Shared/GUI.pm b/lib/AdminPanel/Shared/GUI.pm index 22dd0871..ca0f91eb 100644 --- a/lib/AdminPanel/Shared/GUI.pm +++ b/lib/AdminPanel/Shared/GUI.pm @@ -53,8 +53,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA =cut -use strict; -use warnings; +use Moose; + use diagnostics; use yui; @@ -62,9 +62,6 @@ use AdminPanel::Shared qw(pathList2hash); use AdminPanel::Shared::Locales; -use Moose; - - has 'loc' => ( is => 'rw', init_arg => undef, diff --git a/lib/AdminPanel/Shared/JournalCtl.pm b/lib/AdminPanel/Shared/JournalCtl.pm index 1514252b..8cee01bd 100644 --- a/lib/AdminPanel/Shared/JournalCtl.pm +++ b/lib/AdminPanel/Shared/JournalCtl.pm @@ -49,11 +49,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. =cut +use Moose; use diagnostics; -use strict; - -use Moose; has 'this_boot' => ( diff --git a/lib/AdminPanel/Shared/Users.pm b/lib/AdminPanel/Shared/Users.pm index cd253bd9..0c23cc27 100644 --- a/lib/AdminPanel/Shared/Users.pm +++ b/lib/AdminPanel/Shared/Users.pm @@ -51,8 +51,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA =cut +use Moose; use diagnostics; -use strict; use Config::Auto; use Data::Password::Meter; @@ -69,7 +69,6 @@ use POSIX qw/ceil/; use AdminPanel::Shared::Locales; use AdminPanel::Shared; -use Moose; #============================================================= @@ -150,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, +); #============================================================= @@ -685,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 |