#!/usr/bin/perl -w ################################################################################ # # # # # Copyright (C) 2003 MandrakeSoft # # # Daouda Lo # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License Version 2 as # # published by the Free Software Foundation. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ################################################################################ use strict; use lib qw(/usr/lib/libDrakX); use standalone; use common; use any; use interactive; use ugtk2 qw(:all); use USER; my $us = {} ;#my $us = USER::ADMIN->new; #$ent = $us->lookup_user_name("daouda"); #!$ent and print "ent est vide"; $us->{VERSION} = 0.91; my $pixdir = '/usr/share/userdrake/pixmaps/'; my $h = USER::ADMIN->new; $h->start(); my $in = interactive->vnew('su', 'default'); sub HelpSystem { system("drakhelp Drakxtools-Guide.html/userdrake.html &") }; sub DisplayAllUsers { } $us->{wnd} = ugtk2->new(N("Mandrake Linux Users Management Tool") . " " . $us->{VERSION}, center => 1); gtkset_size_request($us->{wnd}{window}, 580, 440); my $utree_model = Gtk2::ListStore->new(Gtk2::GType->STRING, Gtk2::GType->INT, Gtk2::GType->STRING, Gtk2::GType->STRING, Gtk2::GType->STRING, Gtk2::GType->STRING); 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 ($menu, $factory) = create_factory_menu($us->{wnd}{rwindow}, ({ path => N("/_File"), type => '' }, { path => N("/_File") . N("/_Refresh"), callback => \&Refresh }, { path => N("/_File") . N("/_Save"), callback => \&save_global }, { path => N("/_File") . N("/_Quit"), callback => \&quit_global }, { path => N("/_Actions"), type => '' }, { path => N("/_Actions") . N("/_Add User"), callback => \&AddUser }, { path => N("/_Actions") . N("/Add _Group"), callback => \&AddGroup }, { path => N("/_Actions") . N("/_Edit"), callback => \&Edit }, { path => N("/_Actions") . N("/_Delete"), callback => \&Delete }, { path => N("/_Options"), type => '' }, { path => N("/_Options") . N("/_All Users"), type => '', callback => sub { $showallusers = $checkall->active; DisplayAllUsers($showallusers) } }, { path => N("/_Help"), type => '' }, { path => N("/_Help").N("/_Help"), callback => \&HelpSystem }, { path => N("/_Help").N("/_Report Bug"), callback => sub { system("drakhelp https://qa.mandrakesoft.com &") } }, { path => N("/_Help").N("/_About..."), callback => \&about_mdk_userdrake } ) ); $checkall = $factory->get_widget("
" . N("/Options") . N("/All Users")); my $toolb = Gtk2::Toolbar->new; gtkappend_page(my $nb = Gtk2::Notebook->new, gtkpack(create_scrolled_window($usertree)), gtkshow(Gtk2::Label->new(N("Users")))); gtkappend_page($nb, gtkpack(create_scrolled_window($grouptree)), gtkshow(Gtk2::Label->new(N("Group Users")))); $nb->set_show_border(0); gtkadd($us->{wnd}{window}, gtkpack_(Gtk2::VBox->new(0, 0), 0, $menu, 0, $toolb, 1, $nb )); my @ucolsize = (80, 60, 60, 120, 80, 80, -1); my @gcolsize =(100, 80, 160, -1) ; each_index { my $col = Gtk2::TreeViewColumn->new_with_attributes($_, Gtk2::CellRendererText->new, 'text' => $::i); $col->set_min_width($ucolsize[$::i]); $usertree->append_column($col); } (N("User Name"), N("User ID"), N("Primary Group"), N("Full Name"), N("Login Shell"), N("Home Directory")); each_index { my $col = Gtk2::TreeViewColumn->new_with_attributes($_, Gtk2::CellRendererText->new, 'text' => $::i); $col->set_min_width($gcolsize[$::i]); $grouptree->append_column($col); } (N("Group Name"), N("Group ID"), N("Group Members")); map { $toolb->append_item($_->[0], $_->[1], $_->[2], Gtk2::Image->new_from_file($pixdir . $_->[2] . '.png'), $_->[3], $toolb); } ( [ N("Add User"), N("Add a user to the system"), 'user_add', \&AddUser ], [ N("Add Group"), N("Add a group to the system"), 'group_add', \&AddGroup ], [ N("Edit"), N("Edit selected row"), 'user_conf', \&Edit ], [ N("Delete"), N("Delete selected row"), 'user_del', \&Delete ], [ N("Refresh"), N("Refresh the list"), 'refresh', \&Refresh ], [ N("Help"), N("Generic help on userdrake"), 'help', \&HelpSystem ] ); $us->{wnd}{rwindow}->show_all; Gtk2->main; ugtk2->exit; sub AddUser { my $w = ugtk2->new(N("Create New User"), grab => 1); my $mode = 0; gtkadd($w->{window}, gtkpack_(Gtk2::VBox->new(0, 2), 0, BuildUui(), 0, Gtk2::HSeparator->new, 0, $us->{o}->{addusercheck} = Gtk2::CheckButton->new(N("Create home Directory")), 0, gtkpack_(Gtk2::HBox->new(0, 4), 0, Gtk2::Label->new(N("Home Directory: ")), 0, $us->{o}->{homedir} = Gtk2::Entry->new() ), 0, $us->{o}->{privategroup} = Gtk2::CheckButton->new(N("Create a private group for the user")), 0, $us->{o}->{userid} = Gtk2::CheckButton->new(N("Specify user ID manually")), 0, gtkset_sensitive(my $h = Gtk2::HBox->new(0, 4), 0), 0, Gtk2::HSeparator->new, 0, gtkpack(Gtk2::HBox->new(1, 20), map { my $r = $_->[1]; gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub { if (!$r) { print ("Ok clicked\n"); } Gtk2->main_quit }) } ([ N("Cancel"), 1 ], [ N("Ok"), 0 ])), ) ); map { $us->{o}->{$_}->set_active } (qw(privategroup addusercheck)); $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); GrayBox($us->{o}->{userid}, $h, 0); $w->{rwindow}->show_all; $w->main; } sub AddGroup { my $w = ugtk2->new(N("Create New User"), grab => 1); my $mode = 0; gtkadd($w->{window}, gtkpack_(Gtk2::VBox->new(0, 2), 0, BuildGui(), 0, Gtk2::HSeparator->new, 0, $us->{o}->{groupid} = Gtk2::CheckButton->new(N("Specify group ID manually")), 0, gtkset_sensitive(my $h = Gtk2::HBox->new(0, 4), 0), 0, Gtk2::HSeparator->new, 0, gtkpack(Gtk2::HBox->new(1, 20), map { my $r = $_->[1]; gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub { if (!$r) { print ("Ok clicked\n"); } Gtk2->main_quit }) } ([ N("Cancel"), 1 ], [ N("Ok"), 0 ])), ) ); $us->{o}->{gid} = Gtk2::SpinButton->new(Gtk2::Adjustment->new(500, 1, 65000, 1, 10, 10), 1, 0); $h->pack_end($us->{o}->{gid}, 0, 0, 4); $h->pack_end(Gtk2::Label->new(N("GID: ")), 0, 0, 4); $us->{o}->{groupid}->signal_connect('clicked' => sub { $mode = !$mode; $h->set_sensitive($mode) }); $w->{rwindow}->show_all; $w->main; } sub Delete { } # Gtk Facilities sub CreateTree { my ($tree_model) = @_; my $tree = Gtk2::TreeView->new_with_model($tree_model); $tree->get_selection->set_mode('browse'); $tree->set_headers_visible(1); $tree->set_rules_hint(1); $tree } sub gtkentry_hidepass { my ($text) = @_; my $e = Gtk2::Entry->new(); $text and $e->set_text($text); $e->set_visibility(0); $e } sub gtkentry_sized { my $i = shift; my $e = Gtk2::Entry->new_with_max_length($i); $e->set_size_request(30, 20); $e } 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("Full Name") . " :", $us->{o}->{fullname} = Gtk2::Entry->new() ], [ N("Password") . " :", $us->{o}->{passwd} = gtkentry_hidepass() ], [ N("Confirm Password:") . " :", $us->{o}->{confpasswd} = gtkentry_hidepass() ], [ N("Login Shell") . " :", $us->{o}->{shells} = Gtk2::Combo->new ] ) ); $vbox } sub BuildGui { gtkpack_(my $vbox = Gtk2::VBox->new(0, 2), 1, create_packtable({ homogeneous => 1, col_spacings => 5, row_spacings =>5 }, [ N("Group Name") . " :", $us->{o}->{groupname} = Gtk2::Entry->new() ] ) ); $vbox } sub Edit { my $w = ugtk2->new('userdrake', grab => 1); map { my $tr = $_->[0]; my $ch = $_->[1]; my $co = $_->[2]; my $tree_model = Gtk2::ListStore->new(Gtk2::GType->BOOLEAN, Gtk2::GType->STRING); $us->{$tr} = Gtk2::TreeView->new_with_model($tree_model); $us->{$tr}->get_selection->set_mode('browse'); $us->{$ch} = Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererToggle->new, 'active' => 0); $us->{$co} = Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 0); $us->{$tr}->append_column($us->{$ch}); $us->{$tr}->append_column($us->{$co}); $us->{$tr}->set_headers_visible(0); } (["utree", "ucheck", "ucol"], ["gtree", "gcheck", "gcol"]); my $p = $nb->get_current_page(); print " Page = $p"; my $nbU = Gtk2::Notebook->new; my $nbG = Gtk2::Notebook->new; if ($p == 0) { gtkappend_page($nbU, gtkpack_(Gtk2::VBox->new(0, 2), 1, BuildUui(), 1, create_packtable({ homogeneous => 1, col_spacings => 5, row_spacings => 5 }, [ N("Home") . " :", $us->{o}->{homedir} = Gtk2::Entry->new() ] ) ), gtkshow(Gtk2::Label->new(N("User Data")))); my $m = 0; my $s = 0; gtkappend_page($nbU, gtkpack_(Gtk2::VBox->new(0, 2), 0, $us->{o}->{acheckexpire} = Gtk2::CheckButton->new(N("Enable account expiration")), 0, gtkpack__(my $h = Gtk2::HBox->new(0, 10), 0, Gtk2::Label->new(N("Account expires") . " MM/DD/YYYY :"), 1, map { my $s = $_->[0]; my $t = $_->[1]; $us->{o}->{$s} = gtkentry_sized($t), } (['expm', 2], ['expd', 2], ['expy', 4]), ), 0, Gtk2::HSeparator->new, 0, $us->{o}->{lockuser} = Gtk2::CheckButton->new(N("Lock User Account")) ), gtkshow(Gtk2::Label->new(N("Account Info")))); GrayBox($us->{o}->{acheckexpire}, $h, 0); gtkappend_page($nbU, gtkpack_(Gtk2::VBox->new(0, 2), 0, $us->{o}->{pcheckexpire} = Gtk2::CheckButton->new(N("Enable Password Expiration")), 1, gtkpack_(my $v = Gtk2::VBox->new(0,1), 1, create_packtable({ homogeneous => 1, col_spacings => 5, row_spacings => 5 }, [ N("Days before change allowed :"), $us->{o}->{dbca} = Gtk2::Entry->new(0) ], [ N("Days before change required :"), $us->{o}->{dbcr} = Gtk2::Entry->new(0) ], [ N("Days warning before change :"), $us->{o}->{bwbc} = Gtk2::Entry->new(0) ], [ N("Days before account inactive :"), $us->{o}->{dbai} = Gtk2::Entry->new(0) ] ) )), gtkshow(Gtk2::Label->new(N("Password Info")))); GrayBox($us->{o}->{pcheckexpire}, $v, 0); gtkappend_page($nbU, gtkpack_(Gtk2::VBox->new(0, 2), 0, Gtk2::Label->new(N("Select the groups that the user will be a member of:")), 1, $us->{utree} ), gtkshow(Gtk2::Label->new(N("Account Info")))); } else { $nbG->set_size_request(300, 200); gtkappend_page($nbG, gtkpack_(Gtk2::VBox->new(0, 2), 1, BuildGui()), gtkshow(Gtk2::Label->new(N("Group Data")))); gtkappend_page($nbG, gtkpack_(Gtk2::VBox->new(0, 1), 0, Gtk2::Label->new(N("Select the users to join this group :")), 1, $us->{gtree}), gtkshow(Gtk2::Label->new(N("Group Users")))); } gtkadd($w->{window}, gtkpack_(Gtk2::VBox->new(0,5), 1, !$p ? $nbU : $nbG, 0, Gtk2::HSeparator->new, 0, gtkpack(Gtk2::HBox->new(1, 20), map { my $retv = $_->[1]; gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub { if (!$retv) { #my ($model, $iter) = $tree->get_selection->get_selected; #$model and $w->{retval} = { sel => $model->get($iter, 0) }; #$iter and $iter->free; } Gtk2->main_quit }) } ([ N("Cancel"), 1 ], [ N("Ok"), 0 ])), )); my %roots; # $tree_model->append_set($roots{$_->{land}} ||= $tree_model->append_set(undef, [ 0 => $_->{land} ]), # [ 0 => $_->{url} ])->free foreach @mirrors; # $w->{window}->set_size_request(400, 300); $w->{rwindow}->show_all; $w->main } sub GrayBox { my ($o, $v, $m) = @_; $v->set_sensitive($m); $o->signal_connect('clicked' => sub { $m = !$m; $v->set_sensitive($m) }); } sub save_global { } sub Refresh { print ("User Refreshed\n"); } sub quit_global { Gtk2->main_quit; } sub InDialog { my ($title, $label) = @_; my $w = ugtk2->new($title, grab => 1); gtkadd($w->{window}, gtkpack_(Gtk2::VBox->new, 1, Gtk2::Label->new($label), 0, Gtk2::HSeparator->new, 0, gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub { Gtk2->main_quit }) ), ); $w->{rwindow}->show_all; $w->main } sub about_mdk_userdrake { InDialog(N("About Userdrake"), N("\n\nMandrake User Management Tool\n Name :\t Userdrake \n Version :\t %s \n Author : \tDaouda Lo {VERSION})) }