aboutsummaryrefslogtreecommitdiffstats
path: root/userdrake2
blob: 7c886ffc349bb097a1468d852c1d54139271b803 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/usr/bin/perl -w
################################################################################
#                                                                              # 
#                                                                              #
# Copyright (C) 2003 MandrakeSoft                                              #
#
# Daouda Lo <daouda@mandrakesoft.com>                                          #
#                                                                              #
# 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 => '<Branch>' },
					    { 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 => '<Branch>' },
					    { 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 => '<Branch>' },
                                            { path => N("/_Options") . N("/_All Users"), type => '<CheckItem>', 
					      callback => sub { $showallusers = $checkall->active; DisplayAllUsers($showallusers) } },
					    { 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 &") } },
                                            { path => N("/_Help").N("/_About..."), callback => \&about_mdk_userdrake }
					   )
					  );
$checkall = $factory->get_widget("<main>" . 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 <daouda\@mandrakesoft.com\n\n", $us->{VERSION}))
}