aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaouda Lo <daouda@mandriva.com>2003-06-05 08:42:07 +0000
committerDaouda Lo <daouda@mandriva.com>2003-06-05 08:42:07 +0000
commit19f1d67373316ad2762885b915dbebf22147ae95 (patch)
treefc16e73e04cb4a6b5c00627fcf61afd062eab01f
parentfc8fd7875cced7b44f4d8555c744bb206841f061 (diff)
downloaduserdrake-19f1d67373316ad2762885b915dbebf22147ae95.tar
userdrake-19f1d67373316ad2762885b915dbebf22147ae95.tar.gz
userdrake-19f1d67373316ad2762885b915dbebf22147ae95.tar.bz2
userdrake-19f1d67373316ad2762885b915dbebf22147ae95.tar.xz
userdrake-19f1d67373316ad2762885b915dbebf22147ae95.zip
- add home directory and populate it.
- delete home when deleting user
-rwxr-xr-xuserdrake2172
1 files changed, 130 insertions, 42 deletions
diff --git a/userdrake2 b/userdrake2
index 67213ba..8fc3c30 100755
--- a/userdrake2
+++ b/userdrake2
@@ -40,7 +40,7 @@ my $in = interactive->vnew('su', 'default');
my $us = {} ;
$us->{VERSION} = 0.91;
my $error = 0;
-
+my $GetValue = -65533;
my %prefs = getVarsFromSh($conffile);
my $sysfilter = text2bool($prefs{FILTER});
@@ -53,11 +53,10 @@ my $utree_model = Gtk2::ListStore->new(Gtk2::GType->STRING, Gtk2::GType->INT, Gt
my $gtree_model = Gtk2::ListStore->new(Gtk2::GType->STRING, Gtk2::GType->INT, Gtk2::GType->STRING );
my ($usertree, $grouptree);
$usertree = CreateTree($utree_model); $grouptree = CreateTree($gtree_model);
-my ($showallusers, $checkall);
+my ($checkedit, $checkdel, $checkall);
my ($menu, $factory) = create_factory_menu($us->{wnd}{rwindow},
({ path => N("/_File"), type => '<Branch>' },
- { path => N("/_File") . N("/_Refresh"), callback => \&Refresh },
- { path => N("/_File") . N("/_Save"), callback => \&save_global },
+ { path => N("/_File") . N("/_Refresh"), callback => sub { Refresh($sysfilter)} },
{ path => N("/_File") . N("/_Quit"), callback => \&quit_global },
{ path => N("/_Actions"), type => '<Branch>' },
{ path => N("/_Actions") . N("/_Add User"), callback => \&AddUser },
@@ -66,7 +65,7 @@ my ($menu, $factory) = create_factory_menu($us->{wnd}{rwindow},
{ path => N("/_Actions") . N("/_Delete"), callback => \&Delete },
{ path => N("/_Options"), type => '<Branch>' },
{ path => N("/_Options") . N("/_Filter system users"), type => '<CheckItem>',
- callback => sub { $sysfilter = $checkall->active; Refresh_Users_Full($sysfilter); Refresh_Groups_Full($sysfilter) } },
+ callback => sub { $sysfilter = $checkall->active; Refresh($sysfilter) } },
{ path => N("/_Help"), type => '<Branch>' },
{ path => N("/_Help").N("/_Help"), callback => \&HelpSystem },
{ path => N("/_Help").N("/_Report Bug"), callback => sub { system("drakhelp https://qa.mandrakesoft.com &") } },
@@ -74,6 +73,8 @@ my ($menu, $factory) = create_factory_menu($us->{wnd}{rwindow},
)
);
$checkall = $factory->get_widget("<main>" . N("/Options") . N("/Filter system users"));
+$checkedit = $factory->get_widget("<main>" . N("/Actions") . N("/Edit"));
+$checkdel = $factory->get_widget("<main>" . N("/Actions") . N("/Delete"));
$checkall->set_active($sysfilter);
my $toolb = Gtk2::Toolbar->new;
my $searchBox = Gtk2::HBox->new(0,5);
@@ -113,24 +114,51 @@ map {
[ N("Help"), N("Generic help on userdrake"), 'help', \&HelpSystem ]
);
my ($tbuser, $tbgroup, $tbedit, $tbdel, $tbref, $tbhelp) = @toolbwg;
-foreach (($tbedit, $tbdel)) { $_->set_sensitive(0) };
-
+foreach (($tbedit, $tbdel, $checkedit, $checkdel)) { $_->set_sensitive(0) };
my $ctx = USER::ADMIN->new;
-Refresh_Users_Full($sysfilter);
-Refresh_Groups_Full($sysfilter);
+Refresh($sysfilter);
+$nb->signal_connect('switch-page' => sub { NotebookSwitch() });
+GetEvent($usertree); GetEvent($grouptree);
$us->{wnd}{rwindow}->show_all;
Gtk2->main;
ugtk2->exit;
+sub TreeUnselect {
+ my $treev = shift;
+ $treev->get_selection->unselect_all;
+ foreach (($tbedit, $tbdel, $checkedit, $checkdel)) { $_->set_sensitive(0) };
+}
+sub NotebookSwitch {
+ my $page = $nb->get_current_page();
+ $page and TreeUnselect($usertree) or TreeUnselect($grouptree);
+}
+sub GetEvent {
+ my $treev = shift;
+ $treev->signal_connect(button_press_event => sub {
+ my (undef, $event) = @_;
+ my (undef, $iter) = $treev->get_selection->get_selected;
+ return unless $iter;
+ foreach (($tbedit, $tbdel, $checkedit, $checkdel)) { $_->set_sensitive(1) };
+ Edit($iter) if $event->type eq '2button-press';
+ $iter->free;
+ });
+ $treev->signal_connect(key_press_event => sub {
+ my (undef, $event) = @_;
+ my (undef, $iter) = $treev->get_selection->get_selected;
+ return unless $iter;
+ Edit($iter) if ($event->keyval == Gtk2::Gdk::Event::Key->Sym_Return);
+ $iter->free;
+ });
+}
sub Refresh_Users_Full {
my $filterusers = shift;
my $users = $ctx->UsersEnumerateFull();
$utree_model->clear();
my @UserReal;
- LOOP: foreach my $l (@$users) { next LOOP if ($filterusers && $l->Uid(-65533) <= 499 || $l->Uid(-65533) == 65534) ; push(@UserReal, $l) };
+ LOOP: foreach my $l (@$users) { next LOOP if ($filterusers && $l->Uid($GetValue) <= 499 || $l->Uid($GetValue) == 65534) ; push(@UserReal, $l) };
foreach my $l (@UserReal) {
- my $a = $l->Gid(-65533); my $group = $ctx->LookupGroupById($a);
- $utree_model->append_set([ 0 => $l->UserName(-65533), 1 => $l->Uid(-65533), 2 => $group->GroupName(-65533), 3 => $l->Gecos(-65533), 4 => $l->LoginShell(-65533), 5 => $l->HomeDir(-65533) ]);
+ my $a = $l->Gid($GetValue); my $group = $ctx->LookupGroupById($a);
+ $utree_model->append_set([ 0 => $l->UserName($GetValue), 1 => $l->Uid($GetValue), 2 => $group->GroupName($GetValue), 3 => $l->Gecos($GetValue), 4 => $l->LoginShell($GetValue), 5 => $l->HomeDir($GetValue) ]);
}
}
@@ -139,18 +167,22 @@ sub Refresh_Groups_Full {
my $groups = $ctx->GroupsEnumerateFull();
$gtree_model->clear();
my @GroupReal;
- LOOP:foreach my $g (@$groups) { next LOOP if ($filtergroups && $g->Gid(-65533) <= 499 || $g->Gid(-65533) == 65534); push(@GroupReal, $g) };
+ LOOP:foreach my $g (@$groups) { next LOOP if ($filtergroups && $g->Gid($GetValue) <= 499 || $g->Gid($GetValue) == 65534); push(@GroupReal, $g) };
foreach my $g (@GroupReal) {
- my $a = $g->Gid(-65533); my $group = $ctx->LookupGroupById($a);
- my $u_b_g = $ctx->EnumerateUsersByGroup($g->GroupName(-65533));
+ my $a = $g->Gid($GetValue); my $group = $ctx->LookupGroupById($a);
+ my $u_b_g = $ctx->EnumerateUsersByGroup($g->GroupName($GetValue));
my $listUbyG = join(',', @$u_b_g);
- $gtree_model->append_set([ 0 => $g->GroupName(-65533), 1 => $g->Gid(-65533), 2 => $listUbyG ]);
+ $gtree_model->append_set([ 0 => $g->GroupName($GetValue), 1 => $g->Gid($GetValue), 2 => $listUbyG ]);
}
}
-
+sub Refresh {
+ my $filt = shift;
+ Refresh_Users_Full($filt);
+ Refresh_Groups_Full($filt);
+}
sub AddUser {
my $w = ugtk2->new(N("Create New User"), grab => 1);
- my $createhomedir = 1; my $is_system = 0;
+ my $dontcreatehomedir = 0; my $is_system = 0;
my %u; my %sec = getVarsFromSh($secfile);
gtkadd($w->{window},
gtkpack_(Gtk2::VBox->new(0, 2),
@@ -170,17 +202,26 @@ sub AddUser {
my $r = $_->[1];
gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub {
if (!$r) {
- $u{username} = $us->{o}->{log}->get_text();
+ $u{username} = $us->{o}->{login}->get_text(); $error = 0;
if (!valid($u{username})) { raiseerror($us->{error}); $error = 1 };
my $nm = $ctx->LookupUserByName($u{username});
- if ($nm) { raiseerror(N("User already exists, please choose another User Name")); $error = 1 ; $us->{o}->{log}->set_text('') };
+ if ($nm) { raiseerror(N("User already exists, please choose another User Name")); $error = 1 ; $us->{o}->{login}->set_text('') };
$u{passwd} = $us->{o}->{passwd}->get_text();
- if ($us->{o}->{passwd}->get_text() ne $us->{o}->{confpasswd}->get_text()) { raiseerror(N("Password Mismatch")); $error = 1 };
+ if ($u{passwd} ne $us->{o}->{confpasswd}->get_text()) { raiseerror(N("Password Mismatch")); $error = 1 };
if ($sec{SECURE_LEVEL} > 3 && length($u{passwd}) < 6) { raiseerror(N("This password is too simple. \n Good passwords should be > 6 caracters")); $error = 1 };
+ my $userEnt = $ctx->InitUser($u{username}, $is_system);
+ if ($us->{o}->{createhomedir}->get_active) {
+ $dontcreatehomedir = 0;
+ $u{homedir} = $us->{o}->{homedir}->get_text();
+ $userEnt->HomeDir($u{homedir});
+ } else {
+ $dontcreatehomedir = 1
+ }
if ($us->{o}->{userid}->get_active) {
- if ((my $u{uid} = $us->{o}->{uid}->get_value) < 500) {
- print 1;
- }
+ if (($u{uid} = $us->{o}->{uid}->get_value) < 500) {
+ 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});
+ } else { $userEnt->Uid($u{uid}) }
};
if ($us->{o}{privategroup}->get_active) {
if (!$error) {
@@ -190,29 +231,36 @@ sub AddUser {
my $groupchoice = ChooseGroup();
if ($groupchoice == 0 && !$error) {
#You choose to put it in the existing group
- $u{gid} = $gr->Gid(-65533);
+ $u{gid} = $gr->Gid($GetValue);
+ #debug Info (to be removed before final)
printf("EXISTGROUP: le Gid du group sera %d\n groupchoice = %d\n", $u{gid}, $groupchoice);
} elsif ($groupchoice == 1) {
# Put it in 'users' group
$u{gid} = Add2UsersGroup();
+ #debug Info (to be removed before final)
printf("USERGROUP: le Gid du group sera %d\n groupchoice = %d\n", $u{gid}, $groupchoice);
}
} else {
#it's a new group: Add it
- my $newgroup = $ctx->AddGroup($u{username},$is_system);
- $u{gid} = $newgroup->Gid(-65533);
+ my $newgroup = $ctx->InitGroup($u{username},$is_system);
+ $u{gid} = $newgroup->Gid($GetValue);
+ $ctx->GroupAdd($newgroup);
+ #debug Info (to be removed before final
printf("NEWGROUP : le Gid du group sera %d\n", $u{gid});
}
}
} else {
$u{gid} = Add2UsersGroup();
+ #debug Info (to be removed before final)
printf("le Gid du group sera %d", $u{gid});
}
if(!$error) {
print "############# Test Succesfull ##############\n";
- $u{gecos} = $us->{o}->{fullname}->get_text();
- $u{homedir} = $us->{o}->{homedir}->get_text() || "";
- $u{loginshell} = $us->{o}->{shells}->entry->get_text();
+ $u{gecos} = $us->{o}->{fullname}->get_text(); $u{loginshell} = $us->{o}->{shells}->entry->get_text();
+ $userEnt->Gecos($u{gecos}); $userEnt->LoginShell($u{loginshell}); $userEnt->Gid($u{gid});
+ $ctx->UserAdd($userEnt, $is_system, $dontcreatehomedir);
+ $ctx->UserSetPass($userEnt, $u{passwd});
+ Refresh($sysfilter);
}
}
!$error and Gtk2->main_quit; $error = 0 })
@@ -220,7 +268,11 @@ sub AddUser {
)
);
map { $us->{o}->{$_}->set_active } (qw(privategroup createhomedir));
- $us->{o}->{log}->signal_connect('focus_out_event' => sub { $us->{o}->{homedir}->set_text("/home/".$us->{o}->{log}->get_text()); $us->{o}->{fullname}->set_text($us->{o}->{log}->get_text()) });
+ $us->{o}->{login}->signal_connect('focus_out_event' => sub {
+ my $fullname = $us->{o}->{fullname}->get_text();
+ $us->{o}->{homedir}->set_text("/home/".$us->{o}->{login}->get_text());
+ $fullname or $us->{o}->{fullname}->set_text($us->{o}->{login}->get_text())
+ });
$us->{o}->{uid} = Gtk2::SpinButton->new(Gtk2::Adjustment->new(500, 1, 65000, 1, 10, 10), 1, 0);
$h->pack_end($us->{o}->{uid}, 0, 0, 4);
$h->pack_end(Gtk2::Label->new(N("UID: ")), 0, 0, 4);
@@ -230,9 +282,9 @@ sub AddUser {
}
sub Add2UsersGroup() {
my $usersgroup = $ctx->LookupGroupByName('users');
- return $usersgroup->Gid(-65533);
+ return $usersgroup->Gid($GetValue);
}
-sub ChooseGroup {
+sub ChooseGroup() {
my $w = ugtk2->new(N("Choose Group"), grab => 1, center => 1);
my $choice;
my @radio = gtkradio(N("Add to the existing group"), (N("Add to the existing group"), N("Add to the 'users' group")));
@@ -250,11 +302,26 @@ sub ChooseGroup {
$w->main;
$choice;
}
-
-
+sub GimmeChoice {
+ my ($title, $text) = @_;
+ my $w = ugtk2->new($title, grab => 1, center => 1);
+ my $choice;
+ gtkadd($w->{window},
+ gtkpack__(Gtk2::VBox->new(0,5),
+ Gtk2::Label->new($text),
+ Gtk2::HSeparator->new,
+ gtkpack(create_hbox(),
+ gtksignal_connect(Gtk2::Button->new(N("Yes")), clicked => sub {
+ $choice = 1;
+ Gtk2->main_quit;
+ }),
+ gtksignal_connect(Gtk2::Button->new(N("No")), clicked => sub { $choice = $w->{retval} = 0; $error = 1; Gtk2->main_quit }))));
+ $w->main;
+ $choice;
+}
sub AddGroup {
my $w = ugtk2->new(N("Create New User"), grab => 1);
- my $mode = 0;
+ my $mode = 0; my %g; my $is_system = 0;
gtkadd($w->{window},
gtkpack_(Gtk2::VBox->new(0, 2),
0, BuildGui(),
@@ -267,9 +334,23 @@ sub AddGroup {
my $r = $_->[1];
gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub {
if (!$r) {
- print ("Ok clicked\n");
+ $g{groupname} = $us->{o}->{groupname}->get_text(); $error = 0;
+ if (!valid($g{groupname})) { raiseerror($us->{error}); $error = 1 };
+ my $nm = $ctx->LookupUserByName($g{groupname});
+ if ($nm) { raiseerror(N("Group already exists, please choose another Group Name")); $error = 1 ; $us->{o}->{groupname}->set_text('') };
+ my $groupEnt = $ctx->InitGroup($g{groupname}, $is_system);
+ if ($us->{o}->{groupid}->get_active) {
+ if (($g{gid} = $us->{o}->{gid}->get_value) < 500) {
+ my $gidchoice = GimmeChoice(N(" Group Gid is < 500"), N("Creating a group with a GID less than 500 is not recommended.\n Are you sure you want to do this?\n\n"));
+ $gidchoice and $groupEnt->Gid($g{gid});
+ } else { $groupEnt->Gid($g{gid}) }
+ };
+ if(!$error) {
+ $ctx->GroupAdd($groupEnt);
+ Refresh($sysfilter);
+ }
}
- Gtk2->main_quit })
+ !$error and Gtk2->main_quit; $error = 0; })
} ([ N("Cancel"), 1 ], [ N("Ok"), 0 ])),
)
);
@@ -283,6 +364,12 @@ sub AddGroup {
}
sub Delete {
+ my $page = $nb->get_current_page();
+ if ($page == 0) {
+ print "page 0\n";
+ } elsif ($page == 1) {
+ print "page 1\n";
+ }
}
# Gtk Facilities
@@ -310,7 +397,7 @@ sub gtkentry_sized {
sub BuildUui {
gtkpack_(my $vbox = Gtk2::VBox->new(0, 2),
1, create_packtable({ homogeneous => 1, col_spacings => 5, row_spacings => 5 },
- [ N("Login") . " :", $us->{o}->{log} = Gtk2::Entry->new() ],
+ [ N("Login") . " :", $us->{o}->{login} = Gtk2::Entry->new() ],
[ N("Full Name") . " :", $us->{o}->{fullname} = Gtk2::Entry->new() ],
[ N("Password") . " :", $us->{o}->{passwd} = gtkentry_hidepass() ],
[ N("Confirm Password:") . " :", $us->{o}->{confpasswd} = gtkentry_hidepass() ],
@@ -330,6 +417,7 @@ sub BuildGui {
$vbox
}
sub Edit {
+ my $iter = shift;
my $w = ugtk2->new('userdrake', grab => 1);
map {
my $tr = $_->[0]; my $ch = $_->[1]; my $co = $_->[2];
@@ -453,9 +541,9 @@ sub about_mdk_userdrake {
$window_about->show_all;
}
sub valid {
- $_[0] or $us->{error} = N("User Name field is empty please provide a Username"), return 0;
- $_[0] =~ /^[a-z]+?[a-z0-9_-]*?$/ or $us->{error} = N("The user name must contain only lower cased letters, numbers, `-' and `_'"), return 0;
- length($_[0]) <= 32 or $us->{error} = N("The user name is too long"), return 0;
+ $_[0] or $us->{error} = N("Name field is empty please provide a name"), return 0;
+ $_[0] =~ /^[a-z]+?[a-z0-9_-]*?$/ or $us->{error} = N("The name must contain only lower cased letters, numbers, `-' and `_'"), return 0;
+ length($_[0]) <= 32 or $us->{error} = N("Name is too long"), return 0;
return 1;
}
sub raiseerror {