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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
|
#!/usr/bin/perl
# -*- coding: utf-8 -*-
#
# Copyright (C) 2006 by Mandriva aginies _ateuh_ mandriva.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# 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.
my $version = "0.2";
use utf8;
use strict;
use lib qw(/usr/lib/libDrakX);
use standalone;
use common;
use network::network;
use interactive;
use mygtk2 qw(gtknew);
use ugtk2 qw(:ask :wrappers :create :dialogs);
use Gtk2::SimpleList;
use Gtk2::Gdk::Keysyms;
use run_program;
# use libconf
use Libconf::Templates;
use Libconf::Glueconf::Samba::Smb_conf;
my $in = 'interactive'->vnew('su');
$in->do_pkgs->ensure_is_installed('samba-server', '/usr/sbin/smbd') or return;
#if (!-f "/etc/sysconfig/wizard_samba") {
# $in->do_pkgs->ensure_is_installed('drakwizard', '/usr/sbin/drakwizard');
# err_dialog(N("Error"), N("Please setup a samba server")) and return;
#}
my $icon_path = "/usr/lib/libDrakX/icons";
my $fileshare_icon = "$icon_path/IC-winacces2-16.png";
my $printershare_icon = "$icon_path/IC-sambaprt-16.png";
my $sambauser_icon = "$icon_path/ic82-users-16.png";
my $pixbuf_file = Gtk2::Gdk::Pixbuf->new_from_file($fileshare_icon);
my $pixbuf_printer = Gtk2::Gdk::Pixbuf->new_from_file($printershare_icon);
my $pixbuf_user = Gtk2::Gdk::Pixbuf->new_from_file($sambauser_icon);
my $printer_list = create_printer_list();
my $share_list = create_share_list();
my $user_list = create_user_list();
sub create_user_list() {
my $user_list = Gtk2::SimpleList->new('' => 'pixbuf',
N("User name") => 'text',
);
$user_list;
}
sub create_share_list() {
my $share_list = Gtk2::SimpleList->new('' => 'pixbuf',
N("Share name") => 'text',
N("Share directory") => 'text',
N("Comment") => 'text',
N("Browseable") => 'text',
N("Public") => 'text',
N("Writable") => 'text',
N("Create mask") => 'text',
N("Directory mask") => 'text',
N("Read list") => 'text',
N("Write list") => 'text',
N("Admin users") => 'text',
N("Valid users") => 'text',
N("Inherit Permissions") => 'text',
N("Hide dot files") => 'text',
N("Hide files") => 'text',
N("Preserve case") => 'text',
N("Force create mode") => 'text',
N("Force group") => 'text',
N("Default case") => 'text',
);
$share_list->set_headers_clickable(1);
foreach ($share_list->get_columns) {
$_->set_resizable(1);
}
foreach (1, 2, 3) {
$share_list->get_column($_)->signal_connect('clicked', \&sort_by_column, $share_list->get_model);
$share_list->get_column($_)->set_sort_column_id($_ == 0 ? 1 : $_ + 2);
}
$share_list;
}
sub create_printer_list() {
my $printer_list = Gtk2::SimpleList->new('' => 'pixbuf',
N("Printer name") => 'text',
N("Path") => 'text',
N("Comment") => 'text',
N("Browseable") => 'text',
N("Printable") => 'text',
N("Print Command") => 'text',
N("LPQ command") => 'text',
N("Guest ok") => 'text',
N("Writable") => 'text',
N("Write list") => 'text',
N("Inherit permissions") => 'text',
N("Printing") => 'text',
N("Create mode") => 'text',
N("Use client driver") => 'text',
);
$printer_list->set_headers_clickable(1);
foreach (1, 2, 3) {
$printer_list->get_column($_)->signal_connect('clicked', \&sort_by_column, $printer_list->get_model);
$printer_list->get_column($_)->set_sort_column_id($_ == 0 ? 1 : $_ + 2);
}
$printer_list;
}
sub sort_by_column {
my ($column, $model) = @_;
my $col_id = $column->get_sort_column_id;
my ($old_id, $old_order) = $model->get_sort_column_id;
$model->set_sort_column_id($col_id, $old_id == $col_id && $old_order ne 'descending' ? 'ascending' : 'descending');
}
#path comment browseable printable print command guest ok writable write list inherit permissions printing lpq command create mode use client driver
my $samba = Libconf::Glueconf::Samba::Smb_conf->new({ filename => '/etc/samba/smb.conf' });
my (@listshare, @listprinters, @listusers);
my @yesno = qw(yes no); push @yesno, "";
my @default_case = qw(upper lower); push @default_case, "";
my %adv_options = (
read_list => N("Read List"),
write_list => N("Write List"),
admin_users => N("Admin users"),
valid_users => N("Valid users"),
hide_dot_files => N("Hide dot files"),
hide_files => N("Hide files"),
force_group => N("Force Group"),
force_create_mode => N("Force create group"),
default_case => N("Default case"),
preserve_case => N("Preserve case"),
create_mask => N("Create mask"),
directory_mask => N("Directory mask"),
inherit_permissions => N("Inherit permissions"),
);
my $window;
sub get_items() {
my @items = (
[ N("/_File"), undef, undef, undef, '<Branch>', ],
[ N("/_File") . N("/_Write conf"), undef, \&write_conf, 1, '<Item>', ],
[ N("/_File") . N("/_Quit"), N("<control>Q"), \&quit_all, 1, '<Item>', ],
[ N("/_Samba Server"), undef, undef, undef, '<Branch>', ],
[ N("/_Samba Server") . N("/_Restart"), undef, \&restart_dialog, 1, '<Item>', ],
[ N("/_Samba Server") . N("/R_eload"), undef, \&reload_dialog, 1, '<Item>', ],
[ N("/_About") . N("/_Report Bug"), undef, sub { run_program::raw({ detach => 1 }, 'drakbug', '--report', 'draksambashare') }, 1, '<Item>', ],
[ N("/_About") . N("/About..."), undef, sub {
my $license = formatAlaTeX(translate($::license));
$license =~ s/\n/\n\n/sg; # nicer formatting
my $w = gtknew('AboutDialog', name => N("Draksambashare"),
version => '2007',
copyright => N("Copyright (C) %s by Mandriva", '2001-2006'),
license => $license, wrap_license => 1,
comments => N("This is a simple tool to easily manage Samba configuration."),
website => 'http://mandrivalinux.com',
website_label => N("Mandriva Linux"),
authors => 'Antoine Ginies <aginies@mandriva.com>',
artists => 'Hélène Durosini <ln@mandriva.com>',
translator_credits =>
#-PO: put here name(s) and email(s) of translator(s) (eg: "John Smith <jsmith@nowhere.com>")
N("_: Translator(s) name(s) & email(s)\n"),
transient_for => $window->{real_window}, modal => 1, position_policy => 'center-on-parent',
);
$w->show_all;
$w->run;
}, 1, '<Item>', ],
);
return @items;
}
sub quit_all() {
ugtk2->exit;
}
sub restart_dialog() {
wait_action("service smb restart");
}
sub reload_dialog() {
wait_action("service smb reload");
}
sub wait_action {
my ($cmd) = @_;
my $w = $in->wait_message(N("Please wait"), N("Restarting/Reloading Samba server..."));
run_program::get_stdout($cmd) !~ /unknown|error/ or err_dialog(N("Error!"), N("Error Restarting/Reloading Samba server")) and return;
undef $w;
}
my %size_groups = map { $_ => Gtk2::SizeGroup->new('horizontal') } qw(label widget button);
my $label_and_widgets = sub {
my ($label, $widget, $button) = @_;
gtkpack_(Gtk2::HBox->new(0,1),
0, gtkadd_widget($size_groups{label}, $label),
0, gtkadd_widget($size_groups{widget}, $widget),
if_($button, 0, gtkadd_widget($size_groups{button}, $button)),
);
};
my $fdwidget = sub {
my ($data) = @_;
my $fd = new Gtk2::FileSelection(N("Directory Selection"));
$fd->set_modal(1);
$fd->signal_connect("destroy", sub { $fd->hide });
$fd->ok_button->signal_connect(clicked => sub {
my $file = $fd->get_filename;
-d $file or err_dialog(N("Error!"), N("Should be a directory.")) and return;
$data->set_text($file);
$fd->hide;
}, $fd);
$fd->cancel_button->signal_connect(clicked => sub { $fd->hide });
return $fd;
};
sub get_samba_share() {
undef @listshare;
foreach my $clef (keys %$samba) {
if ($samba->{$clef}{printable} =~ /yes/i || $clef =~ /print\$/) {
print "$clef is a printer\n";
} elsif ($clef =~ /global/ || $clef =~ /cdrom$/ || $clef eq "Profiles") {
print "unwanted (special shares)\n";
} else {
push @listshare, {
share_name => $clef,
path => $samba->{$clef}{path},
comment => $samba->{$clef}{comment},
browseable => $samba->{$clef}{browseable},
public => $samba->{$clef}{public},
writable => $samba->{$clef}{writable},
create_mask => $samba->{$clef}{'create mask'},
directory_mask => $samba->{$clef}{'directory mask'},
read_list => $samba->{$clef}{'read list'},
write_list => $samba->{$clef}{'write list'},
admin_users => $samba->{$clef}{'admin users'},
valid_users => $samba->{$clef}{'valid users'},
hide_dot_files => $samba->{$clef}{'hide dot files'},
hide_files => $samba->{$clef}{'hide files'},
preserve_case => $samba->{$clef}{'preserve case'},
force_create_mode => $samba->{$clef}{'force create mode'},
force_group => $samba->{$clef}{'force group'},
default_case => $samba->{$clef}{'default case'},
inherit_permissions => $samba->{$clef}{'inherit permissions'},
};
}
}
return @listshare;
}
sub get_samba_user() {
undef @listusers;
foreach (cat_("/etc/samba/smbpasswd")) {
my ($user) = m!^(\w+):!;
$user and push @listusers, {
user_name => $user,
};
}
return @listusers;
}
sub get_samba_printers() {
undef @listprinters;
foreach my $clef (keys %$samba) {
if ($samba->{$clef}{printable} =~ /yes/i || $clef =~ /print\$/) {
push @listprinters, {
share_name => $clef,
path => $samba->{$clef}{path},
comment => $samba->{$clef}{comment},
browseable => $samba->{$clef}{browseable},
printable => $samba->{$clef}{printable},
print_command => $samba->{$clef}{'print command'},
lpq_command => $samba->{$clef}{'lpq command'},
guest_ok => $samba->{$clef}{'guest ok'},
writable => $samba->{$clef}{writable},
write_list => $samba->{$clef}{'write list'},
inherit_permissions => $samba->{$clef}{'inherit permissions'},
printing => $samba->{$clef}{printing},
create_mode => $samba->{$clef}{'create mode'},
use_client_driver => $samba->{$clef}{'use client driver'},
};
}
}
return @listprinters;
}
sub write_conf() {
$samba->write_conf("/etc/samba/smb.conf");
}
sub printdollar_section() {
$samba->{'print$'}{browseable} = "yes";
$samba->{'print$'}{path} = "/var/lib/samba/printers";
$samba->{'print$'}{browseable} = "yes";
$samba->{'print$'}{'write list'} = '@adm root';
$samba->{'print$'}{'guest ok'} = "yes";
$samba->{'print$'}{'inherit permissions'} = "yes";
}
sub pdf_section() {
$samba->{'pdf-gen'}{path} = "/var/tmp";
$samba->{'pdf-gen'}{'guest ok'} = "no";
$samba->{'pdf-gen'}{printable} = "yes";
$samba->{'pdf-gen'}{comment} = "PDF Generator (only valid users)";
$samba->{'pdf-gen'}{printing} = "bsd";
$samba->{'pdf-gen'}{'print command'} = '/usr/share/samba/scripts/print-pdf %s %H \//%L/%u\ %m %I %J &';
$samba->{'pdf-gen'}{'lpq command'} = "/bin/true";
}
sub printers_section() {
$samba->{printers}{comment} = "All Printers";
$samba->{printers}{browseable} = "no";
$samba->{printers}{'guest ok'} = "yes";
$samba->{printers}{'create mode'} = "0700";
$samba->{printers}{path} = "/var/spool/samba";
$samba->{printers}{writable} = "no";
$samba->{printers}{printable} = "yes";
$samba->{printers}{'print command'} = 'lpr-cups -P %p -o raw %s -r';
$samba->{printers}{'use client driver'} = "yes";
}
sub add_entry() {
my ($addshare_name, $addshare_comment, $addshare_dir);
$_ = Gtk2::Entry->new foreach $addshare_name, $addshare_comment, $addshare_dir;
my $file_dialog = $fdwidget->($addshare_dir, "");
my $button = Gtk2::Button->new(N("Open"));
$button->signal_connect(clicked => sub { $file_dialog->show });
my $dialog = _create_dialog(N("DrakSamba add entry"), { transient_for => $::main_window, modal => 1 });
local $::main_window = $dialog;
gtkpack_($dialog->vbox,
0, gtkadd(Gtk2::Frame->new(N("Add a share")),
gtkpack_(gtkset_border_width(Gtk2::VBox->new, 3),
0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1),
0, $label_and_widgets->(N("Name of the share:"), $addshare_name, ""),
0, $label_and_widgets->(N("Comment:"), $addshare_comment, ""),
0, $label_and_widgets->(N("Directory:"), $addshare_dir, $button),
),
0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1),
0, create_okcancel({
cancel_clicked => sub { $dialog->destroy },
ok_clicked => sub {
my $share = $addshare_name->get_text;
my $comment = $addshare_comment->get_text;
my $test_dir = $addshare_dir->get_text;
foreach my $clef (keys %$samba) {
if ($clef =~ /$share/) {
err_dialog(N("Error"), N("Share with the same name already exist or share name empty, please choose another name.")) and return;
}
}
if ($share ne 'homes' && !-d $test_dir) {
err_dialog(N("Error!"), N("Please enter a directory to share.")) and return;
}
if (! -d $test_dir) {
mkdir_p($test_dir) or err_dialog(N("Error"), N("Can't create the directory, please enter a correct path.")) and return;
}
if (! $comment) {
err_dialog(N("Error"), N("Please enter a Comment for this share.")) and return;
}
push @{$share_list->{data}}, [
$pixbuf_file,
$share,
$test_dir,
$comment,
];
# update listshare
push @listshare, {
share_name => $share,
path => $test_dir,
comment => $comment,
};
# update samba conf
$samba->{$share}{path} = $test_dir;
$samba->{$share}{comment} = $comment;
$dialog->destroy;
}
}
),
),
),
),
);
$dialog->show_all;
}
sub add_printers_entry() {
require wizards;
my %print = (
1 => N("pdf-gen - a PDF generator"),
2 => N("printers - all printers available"),
);
my $wiz_todo;
my $wiz = wizards->new({
name => N("Add Special Printer share"),
pages => {
welcome => {
name => N("Goal of this wizard is to easily create a new special printer Samba share."),
data => [
{ label => "", type => 'list', val => \$wiz_todo, list => [ keys %print ], format => sub { $print{$_[0]} } }
],
next => 'end_add',
post => sub {
if ($wiz_todo == 1) {
exists $samba->{'pdf-gen'} and err_dialog(N("Error"), N("A PDF generator already exists.")) and return 'welcome';
&pdf_section;
push @{$printer_list->{data}}, [
$pixbuf_printer,
'pdf-gen',
$samba->{'pdf-gen'}{path},
$samba->{'pdf-gen'}{comment}, "",
$samba->{'pdf-gen'}{printable},
$samba->{'pdf-gen'}{'print command'},
$samba->{'pdf-gen'}{'lpq command'},
$samba->{'pdf-gen'}{'guest ok'}, "", "", "",
$samba->{'pdf-gen'}{printing}, "", "",
];
push @listprinters, {
share_name => $samba->{'pdf-gen'},
path => $samba->{'pdf-gen'}{path},
comment => $samba->{'pdf-gen'}{comment},
printebale => $samba->{'pdf-gen'}{printable},
printing => $samba->{'pdf-gen'}{printing},
print_command => $samba->{'pdf-gen'}{'print command'},
lpq_command => $samba->{'pdf-gen'}{'lpq command'},
guest_ok => $samba->{'pdf-gen'}{'guest ok'},
};
} elsif ($wiz_todo == 2) {
exists $samba->{'print$'} || exists $samba->{printers} and err_dialog(N("Error"), N("Printers and print\$ already exist.")) and return 'welcome';
&printdollar_section;
&printers_section;
push @{$printer_list->{data}}, [
$pixbuf_printer,
'print$',
$samba->{'print$'}{path}, "",
$samba->{'print$'}{browseable}, "", "", "",
$samba->{'print$'}{'guest ok'}, "",
$samba->{'print$'}{'write list'},
$samba->{'print$'}{'inherit permissions'},
];
push @{$printer_list->{data}}, [
$pixbuf_printer,
'printers',
$samba->{printers}{path},
$samba->{printers}{comment},
$samba->{printers}{browseable},
$samba->{printers}{printable},
$samba->{printers}{'print command'}, "",
$samba->{printers}{'guest ok'},
$samba->{printers}{writable}, "", "", "",
$samba->{printers}{'create mode'},
$samba->{printers}{'use client driver'},
];
push @listprinters, {
share_name => 'print$',
path => $samba->{'print$'}{path},
browseable => $samba->{'print$'}{browseable},
write_list => $samba->{'print$'}{'write list'},
guest_ok => $samba->{'print$'}{'guest ok'},
inherit_permissions => $samba->{'print$'}{'inherit permissions'},
};
push @listprinters, {
share_name => "printers",
comment => $samba->{printers}{comment},
browseable => $samba->{printers}{browseable},
guest_ok => $samba->{printers}{'guest ok'},
create_mode => $samba->{printers}{'create mode'},
path => $samba->{printers}{path},
writable => $samba->{printers}{writable},
printable => $samba->{printers}{printable},
print_command => $samba->{printers}{'print command'},
use_client_driver => $samba->{printers}{'use client driver'},
};
}
return;
},
},
end_add => {
name => N("Congratulations"),
data => [ { label => N("The wizard successfully added the printer Samba share") } ],
no_back => 1,
end => 1,
next => 0,
},
}
});
eval { $wiz->process($in) };
my $err = $@;
$::isWizard = 0;
$::WizardWindow->destroy;
undef $::WizardTable;
undef $::WizardWindow;
# gtkset_mousecursor_normal()
if ($err && $err !~ /wizcancel/) {
err_dialog(N("Error"), N("Failed to add printers.") . "\n\n" . $err);
}
}
sub modify_printers_entry {
my ($selected) = @_;
my ($dir, $comment, $print_command, $guest_ok, $share_name, $browseable, $printable, $write_list, $printing, $lpq_command, $create_mode, $writable, $use_client_driver, $inherit_permissions);
$share_name = Gtk2::Label->new;
$_ = Gtk2::Entry->new foreach $dir, $comment, $print_command, $write_list, $printing, $lpq_command, $create_mode;
$_ = Gtk2::OptionMenu->new foreach $browseable, $printable, $guest_ok, $writable, $use_client_driver, $inherit_permissions;
$_->set_popdown_strings(@yesno) foreach $browseable, $printable, $guest_ok, $writable, $use_client_driver, $inherit_permissions;
my $s = $printer_list->{data}[$selected][1];
$s or info_dialog(N("Error"), N("Please add or select a Samba printer share to be able to modify it.")) and return; $share_name->set_text($s);
$dir->set_text($printer_list->{data}[$selected][2]);
$comment->set_text($printer_list->{data}[$selected][3]);
$browseable->set_text($printer_list->{data}[$selected][4]);
$printable->set_text($printer_list->{data}[$selected][5]);
$print_command->set_text($printer_list->{data}[$selected][6]);
$lpq_command->set_text($printer_list->{data}[$selected][7]);
$guest_ok->set_text($printer_list->{data}[$selected][8]);
$writable->set_text($printer_list->{data}[$selected][9]);
$write_list->set_text($printer_list->{data}[$selected][10]);
$inherit_permissions->set_text($printer_list->{data}[$selected][11]);
$printing->set_text($printer_list->{data}[$selected][12]);
$create_mode->set_text($printer_list->{data}[$selected][13]);
$use_client_driver->set_text($printer_list->{data}[$selected][14]);
my $file_dialog = $fdwidget->($dir, "");
my $button = Gtk2::Button->new(N("Open"));
$button->signal_connect(clicked => sub { $file_dialog->show });
my $dialog = _create_dialog(N("DrakSamba Printers entry"), { transient_for => $::main_window, modal => 1 });
local $::main_window = $dialog;
if ($s eq "printers") { $printable->set_text("yes");
$printing->set_text("");
$_->set_sensitive(0) foreach $printable, $printing;
}
if ($s eq "pdf-gen") { $printing->set_text("bsd");
$printing->set_sensitive(0);
}
gtkpack_($dialog->vbox,
0, gtkadd(Gtk2::Frame->new(N("Printer share")),
gtkpack_(gtkset_border_width(Gtk2::HBox->new, 3),
0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1),
0, $label_and_widgets->(N("Printer name:"), $share_name, ""),
0, $label_and_widgets->(N("Comment:"), $comment, ""),
0, $label_and_widgets->(N("Directory:"), $dir, $button),
),
0, Gtk2::VSeparator->new,
0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1),
0, $label_and_widgets->(N("Writable:"), $writable, ""),
0, $label_and_widgets->(N("Browseable:"), $browseable, ""),
0, $label_and_widgets->(N("Printable"), $printable, ""),
),
),
),
0, gtkadd(Gtk2::Frame->new(N("Advanced options")),
gtkpack_(gtkset_border_width(Gtk2::HBox->new, 3),
0, gtkadd(Gtk2::Frame->new(N("Printer access")),
gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1),
0, $label_and_widgets->(N("Write list"), $write_list, ""),
0, $label_and_widgets->(N("Inherit permissions"), $inherit_permissions, ""),
0, $label_and_widgets->(N("Guest ok:"), $guest_ok, ""),
0, $label_and_widgets->(N("Create mode:"), $create_mode, ""),
),
),
0, Gtk2::VSeparator->new,
0, gtkadd(Gtk2::Frame->new(N("Printer command")),
gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1),
0, $label_and_widgets->(N("Print command:"), $print_command, ""),
0, $label_and_widgets->(N("LPQ command:"), $lpq_command, ""),
0, $label_and_widgets->(N("Printing:"), $printing, ""),
),
),
),
),
0, create_okcancel({
cancel_clicked => sub { $dialog->destroy },
ok_clicked => sub {
my $share = $share_name->get_text;
my $test_dir = $dir->get_text;
$comment->get_text or err_dialog(N("Information"), N("Please enter a Comment for this share.")) and return 1;
if (!-d $test_dir) {
err_dialog(N("Error!"), N("Please enter a directory to share.")) and return;
}
foreach ($create_mode->get_text) {
if ($_ && !/^\d+$/) {
err_dialog(N("Error"), N("create mode should be numeric. ie: 0755.")) and return 1;
}
}
# update gui SimpleList
remove_entry($selected, $printer_list);
push @{$printer_list->{data}}, [
$pixbuf_printer,
$share,
$dir->get_text,
$comment->get_text,
$browseable->get_text,
$printable->get_text,
$print_command->get_text,
$lpq_command->get_text,
$guest_ok->get_text,
$writable->get_text,
$write_list->get_text,
$inherit_permissions->get_text,
$printing->get_text,
$create_mode->get_text,
$use_client_driver->get_text,
];
# update $samba
$samba->{$share}{path} = $dir->get_text;
$samba->{$share}{comment} = $comment->get_text;
$browseable->get_text and $samba->{$share}{browseable} = $browseable->get_text || delete $samba->{$share}{browseable};
$printable->get_text and $samba->{$share}{printable} = $printable->get_text || delete $samba->{$share}{printable};
$print_command->get_text and $samba->{$share}{'print command'} = $print_command->get_text || delete $samba->{$share}{'print command'};
$lpq_command->get_text and $samba->{$share}{'lpq command'} = $lpq_command->get_text || delete $samba->{$share}{'lpq command'};
$guest_ok->get_text and $samba->{$share}{'guest ok'} = $guest_ok->get_text || delete $samba->{$share}{'guest ok'};
$writable->get_text and $samba->{$share}{writable} = $writable->get_text || delete $samba->{$share}{writable};
$write_list->get_text and $samba->{$share}{'write list'} = $write_list->get_text || delete $samba->{$share}{'write list'};
$inherit_permissions->get_text and $samba->{$share}{'inherit permissions'} = $inherit_permissions->get_text || delete $samba->{$share}{'inherit permissions'};
$printing->get_text and $samba->{$share}{printing} = $printing->get_text || delete $samba->{$share}{printing};
$create_mode->get_text and $samba->{$share}{'create mode'} = $create_mode->get_text || delete $samba->{$share}{'create mode'};
$use_client_driver->get_text and $samba->{$share}{'use client driver'} = $use_client_driver->get_text || delete $samba->{$share}{'use client driver'};
#
$dialog->destroy;
}
},
),
);
$dialog->show_all;
}
sub modify_entry {
my ($selected) = @_;
my ($dir, $comment, $create_mask, $directory_mask, $read_list, $write_list, $admin_users, $valid_users, $force_group, $browseable, $public, $writable, $hide_files, $hide_dot_files, $force_create_mode, $preserve_case, $default_case, $inherit_permissions, $share_name);
$share_name = Gtk2::Label->new;
$_ = Gtk2::Entry->new foreach $dir, $comment, $create_mask, $directory_mask, $hide_files;
$_ = Gtk2::Entry->new foreach $read_list, $write_list, $admin_users, $valid_users, $force_group, $force_create_mode;
$_ = Gtk2::OptionMenu->new foreach $browseable, $public, $writable, $default_case, $preserve_case, $hide_dot_files, $inherit_permissions;
$default_case->set_popdown_strings(@default_case);
$_->set_popdown_strings(@yesno) foreach $browseable, $public, $writable, $hide_dot_files, $preserve_case, $inherit_permissions;
my $file_dialog = $fdwidget->($dir, "");
my $button = Gtk2::Button->new(N("Open"));
$button->signal_connect(clicked => sub { $file_dialog->show });
my $w = ugtk2->new(N("DrakSamba entry"));
$w->{window}->set_modal(1);
$w->{window}->set_position('center');
my $s = $share_list->{data}[$selected][1];
$s or info_dialog(N("Error"), N("Please add or select a Samba share to be able to modify it.")) and return;
$share_name->set_text($s);
$dir->set_text($share_list->{data}[$selected][2]);
$comment->set_text($share_list->{data}[$selected][3]);
$browseable->set_text($share_list->{data}[$selected][4]);
$public->set_text($share_list->{data}[$selected][5]);
$writable->set_text($share_list->{data}[$selected][6]);
$create_mask->set_text($share_list->{data}[$selected][7]);
$directory_mask->set_text($share_list->{data}[$selected][8]);
$read_list->set_text($share_list->{data}[$selected][9]);
$write_list->set_text($share_list->{data}[$selected][10]);
$admin_users->set_text($share_list->{data}[$selected][11]);
$valid_users->set_text($share_list->{data}[$selected][12]);
$inherit_permissions->set_text($share_list->{data}[$selected][13]);
$hide_dot_files->set_text($share_list->{data}[$selected][14]);
$hide_files->set_text($share_list->{data}[$selected][15]);
$preserve_case->set_text($share_list->{data}[$selected][16]);
$force_create_mode->set_text($share_list->{data}[$selected][17]);
$force_group->set_text($share_list->{data}[$selected][18]);
$default_case->set_text($share_list->{data}[$selected][19]);
my $expander_user = Gtk2::Expander->new('User options (user access, mask option, force mode)');
$expander_user->add(gtkpack_(Gtk2::HBox->new,
0, gtkadd(Gtk2::Frame->new(N("Samba user access")),
gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1),
0, $label_and_widgets->($adv_options{read_list}, $read_list, ""),
0, $label_and_widgets->($adv_options{write_list}, $write_list, ""),
0, $label_and_widgets->($adv_options{admin_users}, $admin_users, ""),
0, $label_and_widgets->($adv_options{valid_users}, $valid_users, ""),
),
),
0, gtkadd(Gtk2::Frame->new(N("Mask options")),
gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1),
0, $label_and_widgets->($adv_options{create_mask}, $create_mask, ""),
0, $label_and_widgets->($adv_options{directory_mask}, $directory_mask, ""),
0, $label_and_widgets->($adv_options{force_group}, $force_group, ""),
0, $label_and_widgets->($adv_options{force_create_mode}, $force_create_mode, ""),
0, $label_and_widgets->($adv_options{inherit_permissions}, $inherit_permissions, ""),
),
),
),
);
my $expander_file = Gtk2::Expander->new('File options (hide files, case)');
$expander_file->add(gtkpack_(Gtk2::VBox->new,
0, gtkadd(Gtk2::Frame->new(N("Display options")),
gtkpack_(gtkset_border_width(Gtk2::HBox->new, 1),
0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 0),
0, $label_and_widgets->($adv_options{hide_dot_files}, $hide_dot_files, ""),
0, $label_and_widgets->($adv_options{hide_files}, $hide_files, ""),
),
0, Gtk2::VSeparator->new,
0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 0),
0, $label_and_widgets->($adv_options{default_case}, $default_case, ""),
0, $label_and_widgets->($adv_options{preserve_case}, $preserve_case, ""),
),
),
),
),
);
$_->signal_connect(activate => sub {
$w->shrink_topwindow;
}) foreach $expander_file, $expander_user;
gtkadd($w->{window},
gtknew('VBox', spacing => 0, children_loose => [
gtkadd(Gtk2::Frame->new(N("Samba share directory")),
gtkpack_(gtkset_border_width(Gtk2::HBox->new, 1),
0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 0),
0, $label_and_widgets->(N("Share name:"), $share_name),
0, $label_and_widgets->(N("Directory:"), $dir, $button),
0, $label_and_widgets->(N("Comment:"), $comment, ""),
),
0, Gtk2::VSeparator->new,
0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 0),
0, $label_and_widgets->(N("Public:"), $public, ""),
0, $label_and_widgets->(N("Writable:"), $writable, ""),
0, $label_and_widgets->(N("Browseable:"), $browseable, ""),
),
),
),
gtkadd(Gtk2::Frame->new("Advanced options"),
gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1),
0, $expander_user,
0, Gtk2::HSeparator->new,
0, $expander_file,
),
),
create_okcancel({
cancel_clicked => sub { $w->destroy },
ok_clicked => sub {
my $share = $share_name->get_text;
my $test_dir = $dir->get_text;
$comment->get_text or err_dialog(N("Information"), N("Please enter a Comment for this share.")) and return 1;
if ($share ne 'homes' && !-d $test_dir) {
err_dialog(N("Error!"), N("Please enter a directory to share.")) and return;
}
foreach ($create_mask->get_text, $directory_mask->get_text) {
if ($_ && !/^\d+$/) {
err_dialog(N("Error"), N("Create mask, create mode and directory mask should be numeric. ie: 0755.")) and return 1;
}
}
foreach ($read_list->get_text, $write_list->get_text, $admin_users->get_text, $valid_users->get_text) {
my @users = split(" ", $_);
foreach my $user (@users) {
if (!(any { /^$user:/ } cat_("/etc/samba/smbpasswd")) && !/\@/) {
err_dialog(N("Error"), N("Please create this Samba user: %s", $user)) and return;
}
}
}
# update gui SimpleList
remove_entry($selected, $share_list);
push @{$share_list->{data}}, [
$pixbuf_file,
$share_name->get_text,
$dir->get_text,
$comment->get_text,
$browseable->get_text,
$public->get_text,
$writable->get_text,
$create_mask->get_text,
$directory_mask->get_text,
$read_list->get_text,
$write_list->get_text,
$admin_users->get_text,
$valid_users->get_text,
$hide_dot_files->get_text,
$hide_files->get_text,
$preserve_case->get_text,
$force_create_mode->get_text,
$force_group->get_text,
$default_case->get_text,
$inherit_permissions->get_text,
];
# update $samba with the new value
# $samba->{$share};
$samba->{$share}{path} = $dir->get_text;
$samba->{$share}{comment} = $comment->get_text;
$browseable->get_text and $samba->{$share}{browseable} = $browseable->get_text || delete $samba->{$share}{browseable};
$public->get_text and $samba->{$share}{public} = $public->get_text || delete $samba->{$share}{public};
$writable->get_text and $samba->{$share}{writable} = $writable->get_text || delete $samba->{$share}{writable};
$create_mask->get_text and $samba->{$share}{'create mask'} = $create_mask->get_text || delete $samba->{$share}{'create mask'};
$directory_mask->get_text and $samba->{$share}{'directory mask'} = $directory_mask->get_text || delete $samba->{$share}{'directory mask'};
$read_list->get_text and $samba->{$share}{'read list'} = $read_list->get_text || delete $samba->{$share}{'read list'};
$write_list->get_text and $samba->{$share}{'write list'} = $write_list->get_text || delete $samba->{$share}{'write list'};
$admin_users->get_text and $samba->{$share}{'admin users'} = $admin_users->get_text || delete $samba->{$share}{'admin users'};
$valid_users->get_text and $samba->{$share}{'valid users'} = $valid_users->get_text || delete $samba->{$share}{'valid users'};
$hide_dot_files->get_text and $samba->{$share}{'hide dot files'} = $hide_dot_files->get_text || delete $samba->{$share}{'hide dot files'};
$hide_files->get_text and $samba->{$share}{'hide files'} = $hide_files->get_text || delete $samba->{$share}{'hide files'};
$preserve_case->get_text and $samba->{$share}{'preserve case'} = $preserve_case->get_text || delete $samba->{$share}{'preserve case'};
$force_create_mode->get_text and $samba->{$share}{'force create mode'} = $force_create_mode->get_text || delete $samba->{$share}{'force create mode'};
$force_group->get_text and $samba->{$share}{'force group'} = $force_group->get_text || delete $samba->{$share}{'force group'};
$default_case->get_text and $samba->{$share}{'default case'} = $default_case->get_text || delete $samba->{$share}{'default case'};
$inherit_permissions->get_text and $samba->{$share}{'inherit permissions'} = $inherit_permissions->get_text || delete $samba->{$share}{'inherit permissions'};
# update listshare
push @listshare, {
share_name => $share,
path => $samba->{$share}{path},
comment => $samba->{$share}{comment},
browseable => $samba->{$share}{browseable},
public => $samba->{$share}{public},
writable => $samba->{$share}{writable},
create_mask => $samba->{$share}{'create mask'},
directory_mask => $samba->{$share}{'directory mask'},
read_list => $samba->{$share}{'read list'},
write_list => $samba->{$share}{'write list'},
admin_users => $samba->{$share}{'admin users'},
valid_users => $samba->{$share}{'valid users'},
hide_dot_files => $samba->{$share}{'hide dot files'},
hide_files => $samba->{$share}{'hide files'},
preserve_case => $samba->{$share}{'preserve case'},
force_create_mode => $samba->{$share}{'force create mode'},
force_group => $samba->{$share}{'force group'},
default_case => $samba->{$share}{'default case'},
inherit_permissions => $samba->{$share}{'inherit permissions'},
};
$w->destroy;
},
},
),
]
),
);
$w->{window}->show_all;
}
sub remove_entry {
my ($selected, $list) = @_;
my $share_name = $list->{data}[$selected][1];
splice @{$list->{data}}, $selected, 1;
delete $samba->{$share_name};
}
sub remove_user {
my ($user) = @_;
system("smbpasswd -x $user");
}
sub get_user() {
my $conf = "/etc/passwd";
my @data = map { if_(m/^([^#:]+):[^:]+:([^:]+):/ && $2 > 499, $1) } cat_($conf);
return sort(@data, " ");
}
sub modify_user_info {
my ($user, $_passwd, $todo) = @_;
my ($buser, $bpasswd);
my $dialog = new Gtk2::Dialog();
$dialog->set_title(N("Add Samba user"));
$dialog->set_modal(1);
$dialog->set_position('center');
$dialog->set_resizable(0);
if ($todo eq "add") {
$buser = Gtk2::ComboBox->new_with_strings([ get_user() ]);
$buser->set_wrap_width(3);
} else {
$buser = Gtk2::Label->new;
$buser->set_text($user);
}
$bpasswd = Gtk2::Entry->new;
$bpasswd->set_visibility(0);
gtkpack_($dialog->vbox,
0, gtkadd(Gtk2::Frame->new(N("User information")),
gtkpack_(gtkset_border_width(Gtk2::VBox->new, 5),
0, $label_and_widgets->(N("User name:"), $buser, ""),
0, $label_and_widgets->(N("Password:"), $bpasswd, ""),
),
),
0, create_okcancel({
cancel_clicked => sub { $dialog->destroy },
ok_clicked => sub {
my $user_selected = $buser->get_text;
if ($todo eq "add") {
if (any { /^$user_selected:/ } cat_("/etc/samba/smbpasswd")) {
err_dialog(N("Error"), ("Samba User already exist")) and return;
}
system("smbpasswd -a $user_selected -n");
push @{$user_list->{data}}, [
$pixbuf_user,
$user_selected,
];
push @listusers, {
user_name => $user_selected,
};
}
my $passwd_e = $bpasswd->get_text;
set_user_passwd($user_selected, $passwd_e);
$dialog->destroy;
}
},
),
);
$dialog->show_all;
}
sub set_user_passwd {
my ($user, $passwd) = @_;
my $F;
open($F, '|' . qq(smbpasswd $user -s));
print $F "$passwd\n";
print $F "$passwd\n";
close $F;
}
sub add_data_share_list {
my ($share_list) = @_;
get_samba_share();
foreach my $data (@listshare) {
push @{$share_list->{data}}, [
$pixbuf_file,
$data->{share_name},
$data->{path},
$data->{comment},
$data->{browseable},
$data->{public},
$data->{writable},
$data->{create_mask},
$data->{directory_mask},
$data->{read_list},
$data->{write_list},
$data->{admin_users},
$data->{valid_users},
$data->{inherit_permissions},
$data->{hide_dot_files},
$data->{hide_files},
$data->{preserve_case},
$data->{force_create_mode},
$data->{force_group},
$data->{default_case},
];
}
}
sub add_data_user_list {
my ($user_list) = @_;
get_samba_user();
foreach my $data (@listusers) {
push @{$user_list->{data}}, [
$pixbuf_user,
$data->{user_name},
];
}
}
sub add_data_printer_list {
my ($printer_list) = @_;
get_samba_printers();
foreach my $data (@listprinters) {
push @{$printer_list->{data}}, [
$pixbuf_printer,
$data->{share_name},
$data->{path},
$data->{comment},
$data->{browseable},
$data->{printable},
$data->{print_command},
$data->{lpq_command},
$data->{guest_ok},
$data->{writable},
$data->{write_list},
$data->{inherit_permissions},
$data->{printing},
$data->{create_mode},
$data->{use_client_driver},
];
}
}
###############
# Main Program
###############
# create model
add_data_share_list($share_list);
add_data_printer_list($printer_list);
add_data_user_list($user_list);
$_->set_rules_hint(1) foreach $share_list, $printer_list, $user_list;
$ugtk2::wm_icon = $fileshare_icon;
$window = ugtk2->new(N("Manage Samba configuration"));
$::main_window = $window->{real_window};
$window->{rwindow}->set_size_request(600, 410) unless $::isEmbedded;
$window->{rwindow}->set_position('center') if !$::isEmbedded;
my $W = $window->{window};
$W->signal_connect(delete_event => sub { ugtk2->exit });
# double clic and popup modify window
$share_list->signal_connect(button_press_event => sub {
my (undef, $event) = @_;
my ($selected) = $share_list->get_selected_indices;
$share_list->{data}[$selected][1] and modify_entry($selected) if $event->type eq '2button-press';
});
$printer_list->signal_connect(button_press_event => sub {
my (undef, $event) = @_;
my ($selected) = $printer_list->get_selected_indices;
$printer_list->{data}[$selected][1] and modify_printers_entry($selected) if $event->type eq '2button-press';
});
$user_list->signal_connect(button_press_event => sub {
my (undef, $event) = @_;
my ($selected) = $user_list->get_selected_indices;
$user_list->{data}[$selected][1] and modify_user_info($user_list->{data}[$selected][1], "", "change") if $event->type eq '2button-press';
});
# dont know why "$event->type eq '2button-press'" when starting draksambashare so i can't use mapn :/
#mapn {
# $_[0]->signal_connect(button_press_event => sub {
# my (undef, $event) = @_;
# my ($selected) = $_[0]->get_selected_indices;
# return unless $event->type eq '2button-press';
# $_[0]->{data}[$selected][1] and $_[1]($selected); # if $event->type eq '2button-press';
# });
#} [ $share_list, $printer_list, $user_list ], [ modify_entry, modify_printers_entry, modify_user_info ];
# create popup menu
my $menupopup = Gtk2::Menu->new;
my $menuitem1 = Gtk2::MenuItem->new(N("Modify"));
my $menuitem2 = Gtk2::MenuItem->new(N("Remove"));
$menuitem1->signal_connect(activate => sub {
my ($selected) = $share_list->get_selected_indices;
modify_entry($selected);
});
$menuitem2->signal_connect(activate => sub {
my ($selected) = $share_list->get_selected_indices;
ask_okcancel("Remove entry ?", "Remove $share_list->{data}[$selected][1]") or return;
remove_entry($selected, $share_list);
});
$_->show foreach $menuitem1, $menuitem2;
$menupopup->append($_) foreach $menuitem1, $menuitem2;
$share_list->signal_connect('button-press-event' => sub {
my (undef, $event) = @_;
return unless $event->button == 3;
$menupopup->popup(undef, undef, undef, undef, $event->button, $event->time);
}
);
$share_list->signal_connect(key_press_event => sub {
my (undef, $event) = @_;
return unless $event->keyval == $Gtk2::Gdk::Keysyms{Return};
my ($selected) = $share_list->get_selected_indices;
modify_entry($selected);
return 1;
});
# create menu
my @items = get_items();
my $factory = Gtk2::ItemFactory->new('Gtk2::MenuBar', '<main>', undef);
$factory->create_items('menu', @items);
my $menu = $factory->get_widget('<main>');
my $okcancel = create_okcancel({
cancel_clicked => sub { ugtk2->exit },
ok_clicked => sub { &write_conf; ugtk2->exit },
},
);
gtkappend_page(my $nb = Gtk2::Notebook->new, gtkpack_(gtkset_border_width(Gtk2::HBox->new, 0),
1, create_scrolled_window($share_list),
0, gtkpack_(create_vbox('start'),
0, gtksignal_connect(Gtk2::Button->new(N("Add")), clicked => \&add_entry),
0, Gtk2::HSeparator->new,
0, gtksignal_connect(Gtk2::Button->new(N("Modify")), clicked => sub {
my ($selected) = $share_list->get_selected_indices;
eval { modify_entry($selected) };
my $err = $@;
if ($err) {
err_dialog(N("Error"), N("Failed to Modify Samba share.") . "\n\n" . $err);
}
}),
0, gtksignal_connect(Gtk2::Button->new(N("Remove")), clicked => sub {
my ($selected) = $share_list->get_selected_indices;
ask_okcancel("Remove entry ?", "Remove $share_list->{data}[$selected][1]") or return;
eval { remove_entry($selected, $share_list) };
my $err = $@;
if ($err) {
err_dialog(N("Error"), N("Failed to remove a Samba share.") . "\n\n" . $err);
}
}),
),
),
gtkshow(gtkpack_(Gtk2::HBox->new(0,0),
0, Gtk2::Image->new_from_file($fileshare_icon),
0, Gtk2::Label->new(N("File share")),
),
),
);
gtkappend_page($nb, gtkpack_(gtkset_border_width(Gtk2::HBox->new, 0),
1, create_scrolled_window($printer_list),
0, gtkpack_(create_vbox('start'),
0, gtksignal_connect(Gtk2::Button->new(N("Add")), clicked => \&add_printers_entry),
0, Gtk2::HSeparator->new,
0, gtksignal_connect(Gtk2::Button->new(N("Modify")), clicked => sub {
my ($selected) = $printer_list->get_selected_indices;
eval { modify_printers_entry($selected) };
my $err = $@;
if ($err) {
err_dialog(N("Error"), N("Failed to Modify.") . "\n\n" . $err);
}
}),
0, gtksignal_connect(Gtk2::Button->new(N("Remove")), clicked => sub {
my ($selected) = $printer_list->get_selected_indices;
ask_okcancel("Remove entry ?", "Remove $printer_list->{data}[$selected][1]") or return;
eval { remove_entry($selected, $printer_list) };
my $err = $@;
if ($err) {
err_dialog(N("Error"), N("Failed to remove.") . "\n\n" . $err);
}
}),
),
),
gtkshow(gtkpack_(Gtk2::HBox->new(0,0),
0, Gtk2::Image->new_from_file($printershare_icon),
0, Gtk2::Label->new(N("Printers")),
),
),
);
gtkappend_page($nb, gtkpack_(gtkset_border_width(Gtk2::HBox->new, 0),
1, create_scrolled_window($user_list),
0, gtkpack_(create_vbox('start'),
0, gtksignal_connect(Gtk2::Button->new(N("Add")), clicked => sub {
eval { modify_user_info("", "", "add") };
my $err = $@;
if ($err) {
err_dialog(N("Error"), N("Failed to add user.") . "\n\n" . $err);
}
}),
0, Gtk2::HSeparator->new,
0, gtksignal_connect(Gtk2::Button->new(N("Modify")), clicked => sub {
my ($selected) = $user_list->get_selected_indices;
eval { modify_user_info($user_list->{data}[$selected][1], "", "change") };
my $err = $@;
if ($err) {
err_dialog(N("Error"), N("Failed to change user password.") . "\n\n" . $err);
}
}),
0, gtksignal_connect(Gtk2::Button->new(N("Remove")), clicked => sub {
my ($selected) = $user_list->get_selected_indices;
ask_okcancel("Remove entry ?", "Remove $user_list->{data}[$selected][1]") or return;
eval {
remove_user($user_list->{data}[$selected][1]);
remove_entry($selected, $user_list);
};
my $err = $@;
if ($err) {
err_dialog(N("Error"), N("Failed to delete user.") . "\n\n" . $err);
}
}),
0, Gtk2::HSeparator->new,
# FIXME: Why do we have both an "add" button and a "userdrake" one ???
0, gtksignal_connect(Gtk2::Button->new(N("Userdrake")), clicked => sub {
run_program::raw({ detach => 1 }, 'userdrake');
}
),
),
),
gtkshow(gtkpack_(Gtk2::HBox->new(0,0),
0, Gtk2::Image->new_from_file($sambauser_icon),
0, Gtk2::Label->new(N("Samba Users"))),
),
);
$nb->set_show_border(0);
# main interface
$W->add(gtkpack_(Gtk2::VBox->new(0,0),
0, $menu,
0, Gtk2::Banner->new('IC-winacces1-48', N("DrakSamba manage Samba shares")),
#if_($::isEmbedded, 0, Gtk2::Label->new("Here you can add, remove and alter Samba shares.")),
1, $nb,
0, $okcancel,
),
);
$W->show_all;
Gtk2->main;
|