aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2013-12-09 23:42:54 +0100
committerAngelo Naselli <anaselli@linux.it>2013-12-09 23:42:54 +0100
commitd602e5a6131be1f3c737b898b4bdde5aa7389cdd (patch)
treee9b0d268c3f6576533a531a89b87a62dee78434e
parent3cb9fc2980fe586b599b5704e2db95bf50b56b87 (diff)
downloadmanatools-d602e5a6131be1f3c737b898b4bdde5aa7389cdd.tar
manatools-d602e5a6131be1f3c737b898b4bdde5aa7389cdd.tar.gz
manatools-d602e5a6131be1f3c737b898b4bdde5aa7389cdd.tar.bz2
manatools-d602e5a6131be1f3c737b898b4bdde5aa7389cdd.tar.xz
manatools-d602e5a6131be1f3c737b898b4bdde5aa7389cdd.zip
Added back GID/UID checks
-rw-r--r--AdminPanel/Users/GUsers.pm135
-rw-r--r--AdminPanel/Users/users.pm19
2 files changed, 130 insertions, 24 deletions
diff --git a/AdminPanel/Users/GUsers.pm b/AdminPanel/Users/GUsers.pm
index 388b9227..f61e7bfc 100644
--- a/AdminPanel/Users/GUsers.pm
+++ b/AdminPanel/Users/GUsers.pm
@@ -35,6 +35,7 @@ use run_program;
## USER is from userdrake
use USER;
use utf8;
+use log;
use Glib;
use yui;
@@ -47,6 +48,95 @@ our @EXPORT = qw(addUserDialog
);
+sub labeledFrameBox()
+{
+ my ($parent, $label) = @_;
+
+ my $factory = yui::YUI::widgetFactory;
+
+ my $frame = $factory->createFrame($parent, $label);
+ $frame->setWeight( $yui::YD_HORIZ, 1);
+
+ $frame = $factory->createHVCenter( $frame );
+ $frame = $factory->createVBox( $frame );
+ return $frame;
+}
+
+######################################
+##
+## ChooseGroup
+##
+## creates a popup dialog to ask if
+## adding user to existing group or
+## to 'users' group.
+##
+## returns 0 or 1 (choice done)
+## -1 cancel, or exit
+##
+sub ChooseGroup() {
+ my $choice = -1;
+
+ ## push application title
+ my $appTitle = yui::YUI::app()->applicationTitle();
+ ## set new title to get it in dialog
+ yui::YUI::app()->setApplicationTitle(N("Choose group"));
+
+ my $factory = yui::YUI::widgetFactory;
+
+ my $dlg = $factory->createPopupDialog();
+ my $layout = $factory->createVBox($dlg);
+
+
+ my $frame = $factory->createFrame($layout, N("A group with this name already exists. What would you like to do?"));
+ $frame->setWeight( $yui::YD_HORIZ, 1);
+ $frame = $factory->createHVCenter( $frame );
+ $frame = $factory->createVBox( $frame );
+
+ my $rbg = $factory->createRadioButtonGroup( $frame );
+ $frame = $factory->createVBox( $rbg );
+ my $align = $factory->createLeft($frame);
+
+ my $rb1 = $factory->createRadioButton( $align, N("Add to the existing group"), 1);
+ $rb1->setNotify(1);
+ $rbg->addRadioButton( $rb1 );
+ $align = $factory->createLeft($frame);
+ my $rb2 = $factory->createRadioButton( $align, N("Add to the 'users' group"), 0);
+ $rb2->setNotify(1);
+ $rbg->addRadioButton( $rb2 );
+
+ my $hbox = $factory->createHBox($layout);
+ $align = $factory->createRight($hbox);
+ my $cancelButton = $factory->createPushButton($align, N("Cancel"));
+ my $okButton = $factory->createPushButton($hbox, N("Ok"));
+ while(1) {
+ my $event = $dlg->waitForEvent();
+ my $eventType = $event->eventType();
+
+ #event type checking
+ if ($eventType == $yui::YEvent::CancelEvent) {
+ last;
+ }
+ elsif ($eventType == $yui::YEvent::WidgetEvent) {
+ # widget selected
+ my $widget = $event->widget();
+ if ($widget == $cancelButton) {
+ last;
+ }
+ if ($widget == $okButton) {
+ $choice = $rb1->value() ? 0 : 1 ;
+ last;
+ }
+ }
+ }
+
+ destroy $dlg;
+
+ #restore old application title
+ yui::YUI::app()->setApplicationTitle($appTitle);
+
+ return $choice;
+}
+
sub addUserDialog {
my $GetValue = -65533; ## Used by USER (for getting values? TODO need explanations, where?)
my $dontcreatehomedir = 0; my $is_system = 0;
@@ -131,7 +221,7 @@ sub addUserDialog {
$align = $factory->createRight($hbox);
my $UID = 0;
if ($optional->hasSlider()) {
- $UID = $optional->createSlider($align, N("UID"), 500, 65000, 500);
+ $UID = $optional->createSlider($align, N("UID"), 1, 65000, 500);
}
else {
# UID must checked in ncurses, value is entered by keyboard without
@@ -215,12 +305,10 @@ sub addUserDialog {
my $uid = 0;
if ($continue && $uidManually->value()) {
if (($uid = $UID->value()) < 500) {
- $errorString = N("User Uid is < 500");
- $continue = 0;
-# TODO uidchoice
-# my $uidchoice = GimmeChoice(N("User Uid is < 500"),
-# N("Creating a user with a UID less than 500 is not recommended.\n Are you sure you want to do this?\n\n"));
-# $uidchoice and $userEnt->Uid($u{uid});
+ $errorString = "";
+ my $uidchoice = AdminPanel::Shared::ask_YesOrNo(N("User Uid is < 500"),
+ N("Creating a user with a UID less than 500 is not recommended.\nAre you sure you want to do this?\n\n"));
+ $continue = $uidchoice and $userEnt->Uid($uid);
} else {
$userEnt and $userEnt->Uid($uid);
}
@@ -231,23 +319,24 @@ sub addUserDialog {
#Check if group exist
my $gr = $ctx->LookupGroupByName($username);
if ($gr) {
-# TODO ChooseGroup
-# my $groupchoice = ChooseGroup();
-# if ($groupchoice == 0 && !$error) {
-# #You choose to put it in the existing group
-# $u{gid} = $gr->Gid($GetValue);
-# } elsif ($groupchoice == 1) {
-# # Put it in 'users' group
-# log::explanations(N("Putting %s to 'users' group",
-# $u{username}));
-# $u{gid} = Add2UsersGroup($u{username});
-# }
- $errorString = "TODO " . N("Choose group");
- $continue = 0;
+ my $groupchoice = ChooseGroup();
+ if ($groupchoice == 0 ) {
+ #You choose to put it in the existing group
+ $gid = $gr->Gid($GetValue);
+ } elsif ($groupchoice == 1) {
+ # Put it in 'users' group
+ log::explanations(N("Putting %s to 'users' group",
+ $username));
+ $gid = AdminPanel::Users::user::Add2UsersGroup($username);
+ }
+ else {
+ $errorString = "";
+ $continue = 0;
+ }
} else {
#it's a new group: Add it
my $newgroup = $ctx->InitGroup($username,$is_system);
-# log::explanations(N("Creating new group: %s", $u{username}));
+ log::explanations(N("Creating new group: %s", $username));
$gid = $newgroup->Gid($GetValue);
$ctx->GroupAdd($newgroup);
}
@@ -260,12 +349,12 @@ sub addUserDialog {
if (!$continue) {
#---rasie error
- AdminPanel::Shared::msgBox($errorString);
+ AdminPanel::Shared::msgBox($errorString) if ($errorString);
}
else {
## OK let's create the user
print N("Adding user: ") . $username . " \n";
-# log::explanations(N("Adding user: %s", $u{username}));
+ log::explanations(N("Adding user: %s"), $username);
my $loginshell = $loginShell->value();
my $fullname = $fullName->value();
$userEnt->Gecos($fullname); $userEnt->LoginShell($loginshell);
diff --git a/AdminPanel/Users/users.pm b/AdminPanel/Users/users.pm
index 1b876a33..a94aa056 100644
--- a/AdminPanel/Users/users.pm
+++ b/AdminPanel/Users/users.pm
@@ -20,6 +20,7 @@ our @EXPORT = qw(
valid_username
valid_groupname
GetFaceIcon
+ Add2UsersGroup
);
sub facesdir() {
@@ -101,8 +102,24 @@ sub GetFaceIcon {
return $current_icon;
}
+##################################################
+## Add2UsersGroup
+## params
+##
+## 'name' username
+## 'ctx' USER::ADMIN object
+##
+## return
+## gid group id
+##
+sub Add2UsersGroup {
+ my ($name, $ctx) = @_;
+ my $GetValue = -65533; ## Used by USER (for getting values? TODO need explanations, where?)
-
+ my $usersgroup = $ctx->LookupGroupByName('users');
+ $usersgroup->MemberName($name, 1);
+ return $usersgroup->Gid($GetValue);
+}
1;