summaryrefslogtreecommitdiffstats
path: root/samba_wizard/Samba.pm
blob: 54f14d8081cf2a66afbab3c81a7bd0caeaada7eb (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
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
#!/usr/bin/perl

# Drakwizard
# Copyright (C) 2002,2005 Mandriva
#
# Authors: Arnaud Desmons <adesmons@mandrakesoft.com>
#          Florent Villard <warly@mandrakesoft.com>
#          antoine Ginies <aginies@mandriva>
#
# 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.

package MDK::Wizard::Samba;
use strict;

use common;
use services;
use MDK::Wizard::Wizcommon;

use Libconf::Templates;
use Libconf::Glueconf::Samba::Smb_conf;

my $wiz = new MDK::Wizard::Wizcommon;

my $DOMAINNAME = chomp_(`dnsdomainname`);
my $SHORTHOSTNAME = chomp_(`hostname -s`);
my $wiz_samba_etc = "/etc/sysconfig/wizard_samba";
my @listshare;

my $o = {
	 name => 'Samba wizard',
	 var => {
		 wiz_box_list => '',
		 wiz_netbios => '',
		 wiz_hosts_allow => '',
		 wiz_do_file_sharing => '',
		 wiz_all_printers => '',
		 wiz_level => '',
		 wiz_printers => '', wiz_do_printer_sharing => '', wiz_printers_comment => '',
		 wiz_printers_browseable => '', wiz_printers_guestok => '', wiz_printers_createmode => '',
		 wiz_do_homes => '',
		 wiz_workgroup => '',
		 wiz_dir => '',
		 wiz_share_comment => '', wiz_share_browseable => '', wiz_share_writable => '',
		 wiz_banner => '',
		 wiz_write_list => '',
		 wiz_read_list => '',
		 wiz_hosts_deny => '',
		 wiz_log_file => '', wiz_log_level => '', wiz_max_log_size => '',
		 list_printers => '',
		 wiz_home_writable => '', wiz_home_browseable => '', wiz_home_createmode => '',
		 wiz_home_comment => '',
		 wiz_local_master => '',
		 wiz_os_level => '',
		 wiz_security => '',
		 wiz_domain_logons => '',
		 wiz_domain_master => '',
		 wiz_password_server => '',
		 wiz_passdb_backend => '', wiz_passdb_backend_yn => '',
		 wiz_domain => '',
		 wiz_ldap_admin_dn => '', wiz_ldap_suffix => '', wiz_ldap_root_pw => '', wiz_ldap_root_pw_2 => '',
		 wiz_addshare_comment => '', wiz_addshare_browseable => '', wiz_addshare_writable => '',
		 wiz_addshare_createmode => '', wiz_addshare_dotfiles => '',
		 wiz_selected_share => '', 
		 wiz_selected_share_comment => '',
		},
	 init => sub {
           test_host_domain($SHORTHOSTNAME, $DOMAINNAME);
         },
	 needed_rpm => [ 'samba-server' ],
	 defaultimage => "/usr/share/wizards/samba_wizard/images/samba.png"
	};

# we ask glueconf to give us the structure representing /etc/samba/smb.conf
my $samba = new Libconf::Glueconf::Samba::Smb_conf({ filename => '/etc/samba/smb.conf', show_commented_info => 1 });

#debug
use Data::Dumper;
#print Dumper($samba);

my %level = (
    1 => N('All - No access restriction'),
    2 => N('My rules - Ask me allowed and denied hosts')
);

my %type = (
	    1 => N('BDC - backup domain controller'),
	    2 => N('PDC - primary domain controller'),
	    3 => N('Standalone - standalone server'),
	    4 => N('Member - member of a domain'),
	    5 => N('Share - Manage your share'),
	   );

my %share = (
	     1 => N('Add - add a share'),
	     2 => N('Remove - remove a share'),
	     3 => N('Modify - modify a share'),
	     4 => N('CDrom - share a CDrom'),
	    );

my @yesorno = qw(yes no);# push @yesorno, " ";
my @loglevel = qw(0 1 2 3 4 5 6 7 8 9 10);

$o->{pages} = {
	       welcome => {
			   name => N('Samba Configuration Wizard') . "\n\n" . N('Samba allows your server to behave as a file and print server for workstations running non-Linux systems.') . "\n\n" . N('This wizard will help you configuring the Samba services of your server.') . "\n\n" . N('PDC: primary domain controller') . "\n" . N('BDC: backup domain controller') . "\n" . N('standalone: standalone server') . "\n" . N('Member: member of a domain'),
			   no_back => 1,
                           pre => sub {
			     if (-f $wiz_samba_etc) {
			       $::in->ask_warn(N("Information"), N("It seems you previously setup a Samba server. This wizard will re-read your old configuration, and show you the Samba server type you choose"));
			       my $data = cat_($wiz_samba_etc);
			       # detect old Samba type
			       my ($old_type) = $data =~ /type=(\d)/;
			       $o->{var}{wiz_type} = chomp_($old_type);
			     } else { $o->{var}{wiz_type} = 2 }
			   },
			   next => 'ask_type',
			   post => sub {
                             if ($o->{var}{wiz_type} == 2) {
                               return 'pdc' }
                             elsif ($o->{var}{wiz_type} == 1) {
                               return 'bdc' }
                             elsif ($o->{var}{wiz_type} == 3) {
			       return 'ask_workgroup' }
                             elsif ($o->{var}{wiz_type} == 4) {
			       return 'member' }
                             elsif ($o->{var}{wiz_type} == 5 and -f $wiz_samba_etc) {
			       return 'share_menu';
			     }
                           },
                           data => [
                                    { label => N("Wich type of Samba server do you you want:"), val => \$o->{var}{wiz_type}, list => [ keys %type ], format => sub { $type{$_[0]} } },
                                   ],
                          },
	       pdc => {
		       name => N('PDC server: primary domain controller')  . "\n\n" . N('Server configured as a PDC is responsible for Windows authentication throughout the domain.') . "\n" . N('Single server installations may use smbpasswd or tdbsam password backends, but large installations should use the LDAP backend to provide centralized management of both Posix users and Windows users.') . "\n" . N('Domain master = yes, causes the server to register the NetBIOS name <pdc name>1B. This name will be recognized by other servers.'),
		       pre => sub {
			       $o->{var}{wiz_domain_master} = "yes";
			       $o->{var}{wiz_security} = "user";
			       $o->{var}{wiz_domain_logons} = "yes";
			       $o->{var}{wiz_wins_support} ||= $samba->{global}{'wins support'};
			       if ($samba->{'os level'}) {
				 $o->{var}{wiz_oslevel} = $samba->{'os level'};
			       } else {
				 $o->{var}{wiz_oslevel} = "64";
			       }
			       if ($samba->{global}{'passdb backend'}) {
				 $o->{var}{wiz_passdb_backend_yn} = "yes"
			       } else {
				 $o->{var}{wiz_passdb_backend_yn} = "no"
			       }
			     },
		       post => sub {
			 $o->{var}{wiz_passdb_backend_yn} =~ /yes/ and return 'ldap_conf';
		       },
		       data => [
				{ label => N('Domain logons:'), fixed_val => \$o->{var}{wiz_domain_logons} },
				{ label => N('Domain master:'), fixed_val => \$o->{var}{wiz_domain_master} },
				{ label => N('Security:'), fixed_val => \$o->{var}{wiz_security} },
				{ label => N('Wins support:'), val => \$o->{var}{wiz_wins_support}, fixed_list => \@yesorno },
				{ label => N('Os level:'), fixed_val => \$o->{var}{wiz_oslevel}, help =>N("The global os level option dictates the operating system level at which Samba will masquerade during a browser election. If you wish to have Samba win an election and become the master browser, you can set the level above that of the operating system on your network with the highest current value. ie: os level = 34") },
				{ label => N('Use LDAP Passdb backend'), val => \$o->{var}{wiz_passdb_backend_yn}, fixed_list => \@yesorno },
			       ],
		       complete => sub {
				    if (!$o->{var}{wiz_domain_master}) {
				      $::in->ask_warn(N("Error"), N("The domain is wrong."));
				      return 1
				    } else { return 0 };
				   },
		       next => 'ask_workgroup',
		      },
	       bdc => {
		       name => N('BDC server: backup domain controller') . "\n\n" . N('This enables BDCs to carry much of the network logon processing. A BDC on a local segment handles logon requests and authenticates users when the PDC is busy on the local network. When a segment becomes heavily loaded, the reponsibility is offloaded to another segment\'s BDC or to the PDC. Therefore, you can optimize resources and add robustness to network services by deploying BDCs throughout the network.'),
		       pre => sub {
			       $o->{var}{wiz_domain_master} = "no";
			       $o->{var}{wiz_security} = "user";
			       if ($samba->{'os level'}) {
				 $o->{var}{wiz_oslevel} = $samba->{'os level'};
			       } else {
				 $o->{var}{wiz_oslevel} = "64";
			       }
			     },
		       data => [
				{ label => N('Security:'), fixed_val => \$o->{var}{wiz_security} },
				{ label => N('Domain master:'), fixed_val => \$o->{var}{wiz_domain_master} },
			       ],
		       complete => sub {
				    if (!$o->{var}{wiz_domain_master}) {
				      $::in->ask_warn(N("Error"), N("The domain is wrong."));
				      return 1
				    } else { return 0 };
				   },
		       next => 'ask_workgroup',
		      },
	       member => {
			  name => N('Member of a domain') . "\n\n" . ('Share data, users home or printers.') . "\n" . N('Please enter the domain you want to join.'),
			  pre => sub {
				  $o->{var}{wiz_security} = "domain";
				  $o->{var}{wiz_domain_master} = "no";
				  $o->{var}{wiz_password_server} ||= $samba->{global}{'password server'};
				  $o->{var}{wiz_domain} ||= $samba->{global}{domain};
				  if ($samba->{global}{'passdb backend'}) {
				    $o->{var}{wiz_passdb_backend_yn} = "yes"
				  } else {
				    $o->{var}{wiz_passdb_backend_yn} = "no"
				  }
				},
			  post => sub {
			    $o->{var}{wiz_passdb_backend_yn} =~ /yes/ and return 'ldap_conf';
			  },
			  data => [
				   { label => N('Password server'), val => \$o->{var}{wiz_password_server} },
				   { label => N('Domain:'), val => \$o->{var}{wiz_domain} },
				   { label => N('Use LDAP Passdb backend'), val => \$o->{var}{wiz_passdb_backend_yn}, fixed_list => \@yesorno },
				   { label => N('Security:'), fixed_val => \$o->{var}{wiz_security} },
				   { label => N('Domain master:'), fixed_val => \$o->{var}{wiz_domain_master} },
				  ],
			  complete => sub {
				       if (!$o->{var}{wiz_domain}) {
					 $::in->ask_warn(N("Error"), N("The domain is wrong."));
					 return 1
				       } else { return 0 };
				      },
			  next => 'ask_workgroup',
			 },
	       share_menu => {
			      name => N('What do you want todo with your share ?') . "\n\n" . N('add/remove/modify a share'),
			      data => [
				       { label => N("what do you want:"), val => \$o->{var}{wiz_share}, list => [ keys %share ], format => sub { $share{$_[0]} } },
				      ],
			      post => sub {
				if ($o->{var}{wiz_share} == 1) {
				  return 'add_share' }
				elsif ($o->{var}{wiz_share} == 2) {
				  return 'choose_share' }
				elsif ($o->{var}{wiz_share} == 3) {
				  return 'choose_share' }
				elsif ($o->{var}{wiz_share} == 4) {
				  return 'add_cdrom_share' }
			      },
			      no_back => 1,
			     },
	       choose_share => {
				name => N('Manage wich share ?') . "\n\n" . N('Please choose the share you want to manage.'),
				pre => \&list_all_shares,
				post => sub {
				  if ($o->{var}{wiz_share} == 2) {
				    return 'delete_share';
				  } else {
				    return 'modify_share';
				  }
				},
				data => [
					 { label => N('Choose share you want to manage:'), val => \$o->{var}{wiz_selected_share}, fixed_list => \@listshare },
					],
				complete => sub {
				  if ($o->{var}{wiz_selected_share} =~ /cdrom/ || $o->{var}{wiz_share} == 2) {
				    $::in->ask_warn(N('Error'), N('Can\'t modify cdrom share, please choose another share.'));
				    return 1;
				  }
				},
			       },
	       delete_share => {
				name => N('Remove a share'),
				pre => sub {
					my $dshare = $o->{var}{wiz_selected_share};
					$o->{var}{wiz_selected_share_comment} = $samba->{$dshare}{comment};
				       },
				data => [
					 { label => N('Delete this share:'), fixed_val => \$o->{var}{wiz_selected_share} },
					 { label => N('Comment for this share:'), fixed_val => \$o->{var}{wiz_selected_share_comment} },
					],
				next => 'summary_delete',
			       },
	       modify_share => {
				name => N('Modify a share'),
				pre => sub {
				  my $share = $o->{var}{wiz_selected_share};
				  $o->{var}{wiz_share_comment} = $samba->{$share}{comment};
				  $o->{var}{wiz_add_share_writable} = $samba->{$share}{writable};
				  $o->{var}{wiz_share_browseable} = $samba->{$share}{browseable};
				  $o->{var}{wiz_share_path} = $samba->{$share}{path};
				  $o->{var}{wiz_share_public} = $samba->{$share}{public};
				},
				complete => sub {
				  if (!($o->{var}{wiz_share_comment})) {
				    $::in->ask_warn(N('Error'), N('Please enter a share comment.'));
				    return 1;
				  }
				},
				data => [
					 { label => N('Name of the share:'), fixed_val => \$o->{var}{wiz_selected_share} },
					 { label => N('Comment:'), val => \$o->{var}{wiz_share_comment} },
					 { label => N('Path:'), val => \$o->{var}{wiz_share_path} },
					 { label => N('Browseable:'), val => \$o->{var}{wiz_share_browseable}, fixed_list => \@yesorno, help => N("Allows share to be displayed in list of share.") },
					 { label => N('Writable:'), val => \$o->{var}{wiz_share_writable}, fixed_list => \@yesorno },
					 { label => N('Public:'), val => \$o->{var}{wiz_share_public}, fixed_list => \@yesorno },
					],
				next => 'modify_share_options',
			       },
	       modify_share_options => {
					name => N('Modify a share') . "\n\n" . N('Advanced options, use them if you know what you are doing.'),
					pre => sub {
					  my $share = $o->{var}{wiz_selected_share};
					  $o->{var}{wiz_share_createmode} = $samba->{$share}{'create mode'};
					  $o->{var}{wiz_share_readlist} = exists $samba->{$share}{'read list'};
					  $o->{var}{wiz_share_writelist} = exists $samba->{$share}{'write list'};
					  $o->{var}{wiz_share_dotfiles} = exists $samba->{$share}{'hide dot files'};
					},
					data => [
						 { label => N('Create mode:'), val => \$o->{var}{wiz_share_createmode} },
						 { label => N('Read list:'), val => \$o->{var}{wiz_share_readlist}, help => N('Specifies a list of users that have read-only access to a writable share. ie: root fred @users @wheel') },
						 { label => N('Write list:'), val => \$o->{var}{wiz_share_writelist}, help => N('Specifies a list of users that have read-write access to a read-only share. ie: root fred @users @wheel') },
						 { label => N('Show dot files:'), val => \$o->{var}{wiz_share_dotfiles}, fixed_list => \@yesorno, help => N("The hide dot files option hides any files on the server that begin with a dot (.)") },
						 { label => N('Hide files:'), val => \$o->{var}{wiz_share_hidefiles}, help => N("The hide files option provides one or more directory or filename patterns to Samba. Any file matching this pattern will be treated as a hidden file from the perspective of the client. ie: /.icewm/") },
						],
					next => 'summary_modify',
				       },
	       add_share => {
			     name => N('Add a share') . "\n" . N('Comment: description of the share') . "\n" . N('Browseable: view share') . "\n" . N('Writable: user can write in the share'),
			     data => [
				      { label => N('Name of the share:'), val => \$o->{var}{wiz_addshare_name} },
				      { label => N('Comment:'), val => \$o->{var}{wiz_addshare_comment} },
				      { label => N('Path:'), val => \$o->{var}{wiz_addshare_path} },
				      { label => N('Browseable:'), val => \$o->{var}{wiz_addshare_browseable}, fixed_list => \@yesorno, help => N("Allows share to be displayed in list of share.") },
				      { label => N('Public:'), val => \$o->{var}{wiz_addshare_public}, fixed_list => \@yesorno },
				     ],
			     complete => sub {
			       foreach my $clef (keys %$samba) {
				 if ($clef =~ /$o->{var}{wiz_addshare_name}/) {
				   $::in->ask_warn(N("Error"), N("Share with the same name already exist, please choose another name."));
				   return 1
				 }
			       }
			     },
			     next => 'add_share_options',
			    },
	       add_cdrom_share => {
				   name => N('Add a CDROM share'),
				   pre => sub {
				     if ($samba->{cdrom}{comment}) {
				       $o->{var}{wiz_cdrom_comment} = $samba->{cdrom}{comment};
				     } else {
				       $o->{var}{wiz_cdrom_comment} = "%L CDrom";
				     }
				     if ($samba->{cdrom}{path}) {
				       $o->{var}{wiz_cdrom_path} = $samba->{cdrom}{path}
				     } else {
				       $o->{var}{wiz_cdrom_path} = "/mnt/cdrom";
				     }
				     $o->{var}{wiz_cdrom_browseable} = "yes";
				     $o->{var}{wiz_cdrom_pre} = "/bin/mount /mnt/cdrom";
				     $o->{var}{wiz_cdrom_post} = "/bin/umount /mnt/cdrom";
				     $o->{var}{wiz_cdrom_public} = "yes";
				   },
				   data => [
					 { label => N('Comment:'), fixed_val => \$o->{var}{wiz_cdrom_comment} },
					 { label => N('CDrom path:'), fixed_val => \$o->{var}{wiz_cdrom_path} },
					 { label => N('Browseable:'), fixed_val => \$o->{var}{wiz_cdrom_browseable} },
					 { label => N('Root preexec:'), fixed_val => \$o->{var}{wiz_cdrom_pre} },
					 { label => N('Root postexec:'), fixed_val => \$o->{var}{wiz_cdrom_post} },
					 { label => N('Public:'), fixed_val => \$o->{var}{wiz_cdrom_public} },
					],
				   next => 'summary_addcdromshare',
				  },
	       add_share_options => {
				     name =>  N('Add a share') . "\n" . N('If you doesn\'t want to use one of this options, leave it blanck.'),
				     pre => sub {
				       $o->{var}{wiz_addshare_createmode} = "0700";
				       $o->{var}{wiz_addshare_public} = "no";
				     },
				     data => [
					      { label => N('Writable:'), val => \$o->{var}{wiz_addshare_writable}, fixed_list => \@yesorno },
					      { label => N('Create mode:'), val => \$o->{var}{wiz_addshare_createmode} },
					      { label => N('Read list:'), val => \$o->{var}{wiz_addshare_readlist}, help => N('Specifies a list \of users that have read-only access to a writable share. ie: root fred @users @wheel') },
					      { label => N('Write list:'), val => \$o->{var}{wiz_addshare_writelist}, help => N('Specifies a lis\t of users that have read-write access to a read-only share. ie: root fred @users @wheel') },
					      { label => N('Show dot files:'), val => \$o->{var}{wiz_addshare_dotfiles}, fixed_list => \@yesorno, help => N("The hide dot files option hides any files on the server that begin with a dot (.)") },
					      { label => N('Hide files:'), val => \$o->{var}{wiz_addshare_hidefiles}, help => N("The hide files option provides one or more directory or filename patterns to Samba. Any file matching this pattern will be treated as a hidden file from the perspective of the client. ie: /.icewm/") },
					     ],
				     next => 'summary_addshare',
				    },
	       ldap_conf => {
			     name => N('LDAP configuration for Domain Controlling') . "\n\n" . N('The account (dn) that samba uses to access the LDAP server. This account needs to have write access to the LDAP tree. You will need to give samba the password for this dn.'),
			     pre => sub {
			       if ($samba->{global}{'ldap suffix'}) {
				 $o->{var}{wiz_ldap_suffix} = $samba->{global}{'ldap suffix'};
			       } else {
				 $o->{var}{wiz_ldap_suffix} = "dc=mydomain, dc=com";
			       }
			       if ($samba->{global}{'ldap admin dn'})
				 { $o->{var}{wiz_ldap_admin_dn} ||= $samba->{global}{'ldap admin dn'}
				 } else {
				   $o->{var}{wiz_ldap_admin_dn} = "root";
				 }
			       if ($samba->{global}{'passdb backend'}) {
				 $o->{var}{wiz_passdb_backend} = $samba->{global}{'passdb backend'}
			       } else {
				 $o->{var}{wiz_passdb_backend} = "ldapsam:ldap://localhost";
			       }
			     },
			     data => [
				      { label => N('Passdb backend'), val => \$o->{var}{wiz_passdb_backend}, help => "ldapsam:ldap://<ldap server name>" },
				      { label => N('LDAP administrator'), val => \$o->{var}{wiz_ldap_admin_dn}, help => "root" },
				      { label => N('LDAP suffix'), val => \$o->{var}{wiz_ldap_suffix}, help => "dc=$DOMAINNAME,dc=com" },
				      { label => N('LDAP password'), hidden => 1, val => \$o->{var}{wiz_ldap_root_pw} },
				      { label => N('LDAP password check:'), hidden => 1, val => \$o->{var}{wiz_ldap_root_pw_2} },
				     ],
			     complete => sub {
			       if (!($o->{var}{wiz_ldap_suffix})) {
				 $::in->ask_warn(N('Error'), N('Please provide an LDAP suffix.'));
				 return 1;
			       }
                               if (! ($o->{var}{wiz_ldap_admin_dn})) {
                                 $::in->ask_warn(N('Error'), N('Please enter an LDAP administrator.'));
                                 return 1;
                               }
			       if (! ($o->{var}{wiz_ldap_root_pw})) {
				 $::in->ask_warn(N('Error'), N('Please enter an LDAP password.'));
				 return 1;
			       }
			       if ($o->{var}{wiz_ldap_root_pw} ne $o->{var}{wiz_ldap_root_pw_2}) {
				 $::in->ask_warn(N('Error'), N('Pasword dont match.'));
				 return 1;
			       }
			     },
			     next => 'ask_workgroup',
			    },
	       ask_workgroup => {
				 name => N('Workgroup') . "\n\n" . N('Samba needs to know the Windows Workgroup it will serve.'),
				 pre => sub {
				   $o->{var}{wiz_workgroup} ||= $samba->{global}{workgroup};
				   $o->{var}{wiz_netbios} ||= $samba->{global}{netbios};
				 },
				 data => [
					  { label => N('Workgroup:'), val => \$o->{var}{wiz_workgroup} },
					 ],
				 complete => sub {
				   if (!$o->{var}{wiz_workgroup}) {
                                     $::in->ask_warn(N("Error"), N("The Workgroup is wrong."));
				     return 1
				   } else { return 0 };
				 },
				 next => 'ask_banner',
				},
	       ask_banner => {
			      name => N('Server Banner.') . "\n\n" . N('The banner is the way this server will be described in the Windows workstations.'),
			      pre => sub {
				$o->{var}{wiz_banner} ||= $samba->{global}{'server string'}
			      },
			      data => [
				       { label => N('Banner:'), val => \$o->{var}{wiz_banner}, help => "Samba Server %v" },
				      ],
			      complete => sub {
				if (!$o->{var}{wiz_banner}) {
				  $::in->ask_warn(N("Error"), N("The Server Banner is incorrect."));
				  return 1
				} else { return 0 };
			      },
			      next => 'ask_log',
			     },
	       ask_log => {
			   name => N('Samba Log') . "\n\n" . N('Log file: use file.%m to use a separate log file for each machine that connects') . "\n" . N('Log level: set the log (verbosity) level (0 <= log level <= 10)') . "\n" . N('Max Log size: put a capping on the size of the log files (in Kb).'),
			   pre => sub {
			     $o->{var}{wiz_log_file} ||= $samba->{global}{'log file'};
			     $o->{var}{wiz_log_level} ||= $samba->{global}{'log level'};
			     $o->{var}{wiz_max_log_size} ||= $samba->{global}{'max log size'};
			   },
			   data => [
				    { label => N('Log file:'), val => \$o->{var}{wiz_log_file}, help => "/var/log/samba/log.%m" },
				    { label => N('Max log size:'), val => \$o->{var}{wiz_max_log_size}, help => "50" },
				    { label => N('Log level:'), val => \$o->{var}{wiz_log_level}, fixed_list => \@loglevel },
				   ],
			   next => 'ask_services',
			  },
	       ask_netmask => {
			       name => N('Access control') . "\n\n" . N('* Example 1: allow all IPs in 150.203.*.*; except one\nhosts allow = 150.203. EXCEPT 150.203.6.66') . "\n\n" . N('* Example 2: allow hosts that match the given network/netmask\nhosts allow = 150.203.15.0/255.255.255.0') . "\n\n" . N('* Example 3: allow a couple of hosts\nhosts allow = lapland, arvidsjaur') . "\n\n" . N('* Example 4: allow only hosts in NIS netgroup "foonet",  but deny access from one particular host\nhosts allow = @foonet\nhosts deny = pirate') . "\n\n" . N('Note that access still requires suitable user-level passwords.'),
			       pre => sub {
				 $o->{var}{wiz_hosts_allow} ||= $samba->{global}{'hosts allow'};
				 $o->{var}{wiz_hosts_allow} ||= $samba->{global}{'hosts deny'};
			       },
			       post => \&check,
			       data => [
					{ label => N('Allow hosts:'), val => \$o->{var}{wiz_allow_host}, help => "150.203. EXCEPT 150.203.6.66" },
					{ label => N('Deny hosts:'), val => \$o->{var}{wiz_deny_host}, help => "guibux, 10.0.1.253" },				       ],
			       next => 'ask_services',
			      },
	       ask_services => {
				name => N('Enabled Samba Services') . "\n\n" . N('Samba can provide a common file sharing area to your Windows workstation, and can also provide printer sharing for the printers connected to your server.'),
				pre => sub {
				  $o->{var}{wiz_do_file_sharing} ||= exists $samba->{public};
				  $o->{var}{wiz_do_printer_sharing} ||= exists $samba->{printers};
				  $o->{var}{wiz_do_homes} ||= exists $samba->{homes};
				},
				data => [
					 { text => N('Enable file sharing area'), type => 'bool', val => \$o->{var}{wiz_do_file_sharing} },
					 { text => N('Enable Server Printer Sharing'), type => 'bool', val => \$o->{var}{wiz_do_printer_sharing} },
					 { text => N('Make home directories available for their owners'), type => 'bool', val => \$o->{var}{wiz_do_homes} },
					],
				post => sub {
				  if ($o->{var}{wiz_do_file_sharing} == 1) {
				    return 'ask_dir';
				  } elsif ($o->{var}{wiz_do_printer_sharing} == 1) {
				    return 'ask_printers';
				  } elsif ($o->{var}{wiz_do_homes} == 1) {
				    return 'ask_homes';
				  } else { return 'summary' }
				},
				next => 'ask_dir',
			       },
	       ask_dir => {
			   name => N('Shared directory:') . "\n\n" . N('Type the path of the directory you want being shared.'),
			   pre => sub {
			     $o->{var}{wiz_dir} ||= $samba->{public}{path};
			     if ($samba->{public}{comment}) {
			       $o->{var}{wiz_share_comment} ||= $samba->{public}{comment}
			     } else {
			       $o->{var}{wiz_share_comment} = "Public Share";
			     }
			     $o->{var}{wiz_share_browseable} ||= $samba->{public}{browseable};
			     $o->{var}{wiz_share_writable} ||= $samba->{public}{writable};
			   },
			   data => [
				    { label => N('Comment:'), val => \$o->{var}{wiz_share_comment} },
				    { label => N('Shared directory:'), val => \$o->{var}{wiz_dir} },
				    { label => N('Browseable:'), val => \$o->{var}{wiz_share_browseable}, fixed_list => \@yesorno, help => N("Allows share to be displayed in list of share.") },
				    { label => N('Writable:'), val => \$o->{var}{wiz_share_writable}, fixed_list => \@yesorno },
				    { text => N("Create shared directory if it doesn't exist"), type => 'bool', val => \$o->{var}{create_missing_directory} },
				   ],
			   complete => sub {
			     if(!$o->{var}{wiz_dir}) {
			       $::in->ask_warn(N("Error"), N("Please enter directory path."));
			     } else {
			       if (! -d $o->{var}{wiz_dir} and $o->{var}{create_missing_directory}) {
				 wiz_mkdir_p($o->{var}{wiz_dir}) or $::in->ask_warn(N("Error"), N("Failed to create directory."));
				 return 1;
			       }
			     }
			   },
			   next => 'ask_access'
			  },
	       ask_access => {
			      name => N('File permissions') . "\n\n" . N('Type users or group separated by a comma (groups must be preceded by a \'@\') like this :') . "\n". N('root, fred, @users, @wheel for each kind of permission.') . "\n" . N('You need to use filesystem with ACL support, like XFS or ext3 mounted with ACL options, or you file permissions won\'t work.'),
			      pre => sub {
				$o->{var}{wiz_read_list} ||= $samba->{public}{'read list'};
				$o->{var}{wiz_write_list} ||= $samba->{public}{'write list'};
			      },
			      post => sub {
				if ($o->{var}{wiz_do_printer_sharing} == 1) {
				  return 'ask_printers';
				} elsif ($o->{var}{wiz_do_homes} == 1) {
				  return 'ask_homes';
				}
			      },
			      data => [
				       { label => N('read list:'), help => N('Specifies a list of users that have read-only access to a writable share. ie: root fred @users @wheel'), val => \$o->{var}{wiz_read_list} },
				       { label => N('write list:'), help => N('Specifies a list of users that have read-write access to a read-only share. ie: root fred @users @wheel'), val => \$o->{var}{wiz_write_list} },
				      ],
			      next => 'summary',
			     },
	       ask_printers => {
				name => N('Select which printers you want to be accessible from known users'),
				pre => sub {
				  $o->{var}{list_printers} ||= [ list_printers() ];
				  $o->{var}{wiz_box_list} ||= [];
				},
				data => [
					 { text => N('Enable all printers'), type => 'bool', val => \$o->{var}{wiz_all_printers} },
					 { val => \$o->{var}{wiz_box_list}, boolean_list => \$o->{var}{list_printers}, disabled => sub { $o->{var}{wiz_all_printers} and return 1; 0 } },
					],
				next => 'ask_printers_options',
			       },
	       ask_printers_options => {
					name => N('Now you can configure your printers service. Change value only if you know what your are doing.'),
					pre => sub {
					  if ($samba->{printers}{comment}) {
					    $o->{var}{wiz_printers_comment} ||= $samba->{printers}{comment}
					  } else {
					    $o->{var}{wiz_printers_comment} = "All Printers";
					  }
					  $o->{var}{wiz_printers_browseable} ||= $samba->{printers}{browseable};
					  $o->{var}{wiz_printers_guestok} ||= $samba->{printers}{'guest ok'};
					  if ($samba->{printers}{'create mode'}) {
					    $o->{var}{wiz_printers_createmode} ||= $samba->{printers}{'create mode'}
					  } else {
					    $o->{var}{wiz_printers_createmode} = "0700";
					  }
					},
					post => sub {
					  if ($o->{var}{wiz_do_homes} == 1) {
					    return 'ask_homes';
					  }
					},
					data => [
						 { label => N('Comment:'), val => \$o->{var}{wiz_printers_comment} },
						 { label => N('Create mode:'), val => \$o->{var}{wiz_printers_createmode} },
						 { label => N('Browseable:'), val => \$o->{var}{wiz_printers_browseable}, fixed_list => \@yesorno },
						 { label => N('Guest ok:'), val => \$o->{var}{wiz_printers_guestok}, fixed_list => \@yesorno },
						],
					next => 'summary',
				       },
	       ask_homes => {
			     name => N('Users home options') . "\n" . N('You have selected to allow user access their home directories via samba but you/they must use smbpasswd to set a password.') . "\n" . N('Comment: description of users home directory') . "\n" . N('Browseable: view share') . "\n" . N('Writable: user can write in their home') . "\n" . N('Create mode: man chmod for more info'),
			     pre => sub {
			       if ($samba->{homes}{comment}) {
				 $o->{var}{wiz_home_comment} ||= $samba->{homes}{comment};
			       } else {
				 $o->{var}{wiz_home_comment} = "Home Directories";
			       }
			       $o->{var}{wiz_home_browseable} ||= $samba->{homes}{browseable};
			       $o->{var}{wiz_home_writable} ||= $samba->{homes}{writable};
			       if ($samba->{homes}{'create mode'}) {
				 $o->{var}{wiz_home_createmode} ||= $samba->{homes}{'create mode'};
			       } else {
				 $o->{var}{wiz_home_createmode} = "0755";
			       }
			     },
			     data => [
				      { label => N('Comment:'), val => \$o->{var}{wiz_home_comment} },
				      { label => N('Browseable:'), val => \$o->{var}{wiz_home_browseable}, fixed_list => \@yesorno },
				      { label => N('Writable:'), val => \$o->{var}{wiz_home_writable}, fixed_list => \@yesorno },
				      { label => N('Create mode:'), val => \$o->{var}{wiz_home_createmode} },
				     ],
			     next => 'summary',
			    },
	       summary_modify => {
				  name => N('Summary modify a share') . "\n\n" . N('If you really want to modify this share, click the Next button or use the Back button.'),
				  data => [
					   { label => N('Name of the share:'), fixed_val => \$o->{var}{wiz_share_name} },
					   { label => N('Comment:'), fixed_val => \$o->{var}{wiz_share_comment} },
					   { label => N('Browseable:'), fixed_val => \$o->{var}{wiz_share_browseable} },
					   { label => N('Writable:'), fixed_val => \$o->{var}{wiz_share_writable} },
					   { label => N('Public:'), fixed_val => \$o->{var}{wiz_share_public} },
					   { label => N('Create mode:'), fixed_val => \$o->{var}{wiz_share_createmode} },
					   { label => N('Read list:'), fixed_val => \$o->{var}{wiz_share_readlist} },
					   { label => N('Write list:'), fixed_val => \$o->{var}{wiz_share_writelist} },
					   { label => N('Show dot files:'), fixed_val => \$o->{var}{wiz_share_dotfiles} },
					   { label => N('Hide files:'), fixed_val => \$o->{var}{wiz_share_hidefiles} },
					  ],
				  post => \&do_it_modify_share,
				  next => 'end_modify_share',
				 },
	       summary_addcdromshare => {
					 name => N('CDROM') . "\n\n" . N('If you really want to share a CDROM, click the Next button or use the Back button.'),
					 post => \&do_it_add_cdromshare,
					 data => [
						  { label => N('Comment:'), fixed_val => \$o->{var}{wiz_cdrom_comment} },
						  { label => N('Cdrom path:'), fixed_val => \$o->{var}{wiz_cdrom_path} },
						  { label => N('Browseable:'), fixed_val => \$o->{var}{wiz_cdrom_browseable} },
						  { label => N('Root preexec:'), fixed_val => \$o->{var}{wiz_cdrom_pre} },
						  { label => N('Root postexec:'), fixed_val => \$o->{var}{wiz_cdrom_post} },
						  { label => N('Public:'), fixed_val => \$o->{var}{wiz_cdrom_public} },
						 ],
					 next => 'end_add_share',
					},
	       summary_addshare => {
				    name => N('Summary add share') . "\n\n" . N('If you really want to add this this share, click the Next button or use the Back button.'),
				    post => \&do_it_add_share,
				    data => [
					     { label => N('Name of the share:'), fixed_val => \$o->{var}{wiz_addshare_name} },
					     { label => N('Comment:'), fixed_val => \$o->{var}{wiz_addshare_comment} },
					     { label => N('Browseable:'), fixed_val => \$o->{var}{wiz_addshare_browseable} },
					     { label => N('Writable:'), fixed_val => \$o->{var}{wiz_addshare_writable} },
					     { label => N('Public:'), fixed_val => \$o->{var}{wiz_addshare_public} },
					     { label => N('Create mode:'), fixed_val => \$o->{var}{wiz_addshare_createmode} },
					     { label => N('Read list:'), fixed_val => \$o->{var}{wiz_addshare_readlist} },
					     { label => N('Write list:'), fixed_val => \$o->{var}{wiz_addshare_writelist} },
					     { label => N('Show dot files:'), fixed_val => \$o->{var}{wiz_addshare_dotfiles} },
					    ],
				    next => 'end_add_share',
				   },
	       summary_delete => {
				  name => N('Summary remove a share') . "\n\n" . N('If you really want to remove this share, click the Next button or use the Back button.'),
				    data => [
					     { label => N('Name of the share to delete:'), fixed_val => \$o->{var}{wiz_selected_share} },
					    ],
				  post => \&do_it_remove_share,
				  next => 'end_delete_share',
				 },
	       summary => {
			   name =>  N('Configuring Samba') . "\n\n" . N('The wizard collected the following parameters to configure Samba.') . "\n\n" . N('To accept these values, and configure your server, click the Next button or use the Back button to correct them.') . "\n\n" . N('If you have previously create some shares, they will appear in this configuration. Re-run wizard and choose: Manage share to remove/add/modify them.'),
			   pre => sub {
			     $o->{var}{printers} = get_printers();
			     $o->{var}{file_sharing} = $o->{var}{wiz_do_file_sharing} ? N("enabled") : N("disabled");
			     $o->{var}{printer_sharing} = $o->{var}{wiz_do_printer_sharing} ? N("enabled") : N("disabled");
			     $o->{var}{shared_homes} = $o->{var}{wiz_do_homes} ? N("enabled") : N("disabled")
			   },
			   data => [
				    { label => N('Workgroup:'), fixed_val => \$o->{var}{wiz_workgroup} },
				    { label => N('Server Banner:'), fixed_val => \$o->{var}{wiz_banner} },
				    { label => N('File Sharing:'), fixed_val => \$o->{var}{file_sharing} },
				    { label => N('Print Server:'), fixed_val => \$o->{var}{printer_sharing} },
				    { label => N('Home:'), fixed_val => \$o->{var}{shared_homes} },
				   ],
			   post => \&do_it,
			   next => 'end'
			  },
	       end => {
		       name => N('Congratulations') . "\n\n" . N('The wizard successfully configured your Samba server.'),
		       post => sub {
			 store_samba_type($o->{var}{wiz_type});
		       },
		       end => 1,
		       next => 0
		      },
	       end_modify_share => {
				 name => N('Congratulations') . "\n\n" . N('The wizard successfully modify your share.'),
				 end => 1,
				 next => 0
				},
	       end_add_share => {
				 name => N('Congratulations') . "\n\n" . N('The wizard successfully add your share.'),
				 end => 1,
				 next => 0
				},
	       end_delete_share => {
				    name => N('Congratulations') . "\n\n" . N('The wizard successfully remove your share.'),
				    end => 1,
				    next => 0
				   },
	       error_end => {
			     name => N("Failed"),
			     data => [ { label => N("Please relaunch drakwizard, and try to change some parameters.") } ],
			     no_back => 1,
			     end => 1,
			     next => 0,
			    },
	      };

sub new {
  my ($class, $conf) = @_;
  bless {
	 o   => $o,
	}, $class;
}

sub wiz_mkdir_p {
  my ($dir) = @_;
  if (-d $dir) {
    # Do nothing, directory exists
  } elsif (-e $dir) {
    # Directory is file, we are not going to delete it
    return 0;
  } else {
    # Create parent directory
    wiz_mkdir_p(dirname($dir)) or return 0;
    # Create our directory
    mkdir($dir, 0755) or return 0;
    chown "nobody", "users", $dir;
  }
  1;
}

sub check() {
    $> and return 1;
    $wiz->{net}->is_dhcp() and return 2;
    0;
}

#section has the name of the printer
sub add_printer {
    my ($printer) = @_;
    $samba->{$printer}{printer} = $printer;
    $samba->{$printer}{printable} = 'yes';
}

sub remove_share {
  my ($share) = @_;
  delete $samba->{$share};
}

sub remove_printer {
  my ($printer) = @_;
  delete $samba->{$printer};
}

sub list_printers() {
    my @list if 0;
    return @list if @list;
    @list = sort grep /^(?!\#).+/, map {
        my ($printer) = split(':', $_);
    } cat_("/etc/printcap");
    if (@list) {
	@list
    } else { () }
}

sub list_all_shares() {
  undef @listshare;
  foreach my $clef (keys %$samba) {
    if ($samba->{$clef}{printable} =~ /yes/i) {
      print "$clef is a printer\n";
    } elsif ($clef =~ /global/ or $clef =~ /print\$/) {
      print "unwanted\n";
    } else {
      push @listshare, $clef;
    }
  }
  return @listshare;
}

sub printer_sharing() {
  # create default sedction for printers with default value
  $samba->{printers};
  $samba->{printers}{comment} = $o->{var}{wiz_printers_comment};
  $samba->{printers}{browseable} = $o->{var}{wiz_printers_browseable};
  $samba->{printers}{'guest ok'} = $o->{var}{wiz_printers_guestok};
  $samba->{printers}{'create mode'} = $o->{var}{wiz_printers_createmode};
  # dont want user to change those value...
  $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";
  for (my $i; $i < @{$o->{var}{wiz_box_list}}; $i++) {
    my $printer = $o->{var}{list_printers}[$i];
    if ($o->{var}{wiz_box_list}[$i]) {
      add_printer($printer);
    } else {
      remove_printer($printer);
    }
  }
}

sub global_special_options() {
  # detect Samab type 3 is standalone
  if ($o->{var}{wiz_type} == "3") {
    exists $samba->{global}{'domain_master'} and delete $samba->{global}{'domain_master'};
    $samba->{global}{'security'} = "share";
    exists $samba->{global}{'domain logons'} and delete $samba->{global}{'domain logons'};
    exists $samba->{global}{'wins support'} and delete $samba->{global}{'wins support'};
    exists $samba->{global}{'os level'} and delete $samba->{global}{'os level'};
  } else {
    # so pdc, bdc or member
    $o->{var}{wiz_domain_master} and $samba->{global}{'domain master'} = $o->{var}{wiz_domain_master};
    $o->{var}{wiz_security} and $samba->{global}{security} = $o->{var}{wiz_security};
    $o->{var}{wiz_domain_logons} and $samba->{global}{'domain logons'} = $o->{var}{wiz_domain_logons};
    $o->{var}{wiz_oslevel} and $samba->{global}{'os level'} = $o->{var}{wiz_oslevel};
    $o->{var}{wiz_passdb_backend} and $samba->{global}{'passdb backend'} = $o->{var}{wiz_passdb_backend};
    $o->{var}{wiz_wins_support} and $samba->{global}{'wins support'} = $o->{var}{wiz_wins_support};
    $o->{var}{wiz_password_server} and $samba->{global}{'password server'} = $o->{var}{wiz_password_server};
    $o->{var}{wiz_domain} and $samba->{global}{domain} = $o->{var}{wiz_domain};
    # ldap options if needed
    if ($o->{var}{wiz_passdb_backend_yn} == "yes" ) {
      $samba->{global}{'passdb backend'} = $o->{var}{wiz_passdb_backend};
      $samba->{global}{'ldap admin_dn'} = $o->{var}{wiz_ldap_admin_dn};
      $samba->{global}{'ldap suffix'} = $o->{var}{wiz_ldap_suffix};
    }
    # delete ldap options if exist
    exists $samba->{global}{'passdb backend'} and delete $samba->{global}{'passdb backend'};
    exists $samba->{global}{'ldap admin_dn'} and delete $samba->{global}{'ldap admin_dn'};
    exists $samba->{global}{'ldap suffix'} and delete $samba->{global}{'ldap suffix'};
  }
}

sub get_printers() {
    if ($o->{var}{wiz_do_printer_sharing}) {
	my $string;
	$o->{var}{wiz_all_printers} and return "all printers";
	for (my $i; $i < @{$o->{var}{wiz_box_list}}; $i++) {
	    $string .= "$o->{var}{list_printers}[$i]\n" if $o->{var}{wiz_box_list}[$i]
	}
	$string;
    }
    else {
	'disabled';
    }
}

sub store_samba_type {
  # write config file to store Samba type
  my ($type) = @_;
  output($wiz_samba_etc, <<EOF);
#  1 = BDC - backup domain controller
#  2 = PDC - primary domain controller
#  3 = Standalone - standalone server
#  4 = Member - member of a domain
EOF

  append_to_file($wiz_samba_etc, "type=$type\n");
}

sub write_conf_restart_smb {
  $samba->write_conf("/etc/samba/smb.conf");
  if (services::is_service_running('smb')) {
    services::restart('smb')
    } else { services::start('smb') }
}

sub do_it_remove_share {
  $::testing and return;
  my $in = 'interactive'->vnew('su', 'Samba');
  my $w = $in->wait_message(N("Samba server"), N("Configuring your Samba server..."));
  my $share = $o->{var}{wiz_selected_share};
  delete $samba->{$share};

  write_conf_restart_smb();
  undef $w;
  check_started('smbd');
}

sub do_it_modify_share {
  $::testing and return;
  my $in = 'interactive'->vnew('su', 'Samba');
  my $w = $in->wait_message(N("Samba server"), N("Configuring your Samba server..."));
  my $share = $o->{var}{wiz_selected_share};
  $samba->{$share};
  $samba->{$share}{comment} = $o->{var}{wiz_share_comment};
  $samba->{$share}{browseable} = $o->{var}{wiz_share_browseable};
  $samba->{$share}{writable} = $o->{var}{wiz_share_writable};
  $samba->{$share}{public} = $o->{var}{wiz_share_public};
  $o->{var}{wiz_share_hidefiles} and $samba->{$share}{'hide files'} = $o->{var}{wiz_share_hidefiles};
  $o->{var}{wiz_share_dotfiles} and $samba->{$share}{'hide dot files'} = $o->{var}{wiz_share_dotfiles};
  $o->{var}{wiz_share_readlist} and $samba->{$share}{'read list'} = $o->{var}{wiz_share_readlist};
  $o->{var}{wiz_share_writelist} and $samba->{$share}{'write list'} = $o->{var}{wiz_share_writelist};
  $o->{var}{wiz_share_createmode} and $samba->{$share}{'create mode'} = $o->{var}{wiz_share_createmode};

  write_conf_restart_smb();
  undef $w;
  check_started('smbd');
}

sub do_it_add_cdromshare {
  $::testing and return;
  my $in = 'interactive'->vnew('su', 'Samba');
  my $w = $in->wait_message(N("Samba server"), N("Configuring your Samba server..."));
  $samba->{cdrom}{comment} = $o->{var}{wiz_cdrom_comment};
  $samba->{cdrom}{path} = $o->{var}{wiz_cdrom_path};
  $samba->{cdrom}{path} = $o->{var}{wiz_cdrom_path};
  $samba->{cdrom}{browseable} = $o->{var}{wiz_cdrom_browseable};
  $samba->{cdrom}{'root preexec'} = $o->{var}{wiz_cdrom_pre};
  $samba->{cdrom}{'root postexec'} = $o->{var}{wiz_cdrom_post};
  $samba->{cdrom}{public} = $o->{var}{wiz_cdrom_public};

  write_conf_restart_smb();
  undef $w;
  check_started('smbd');
}

sub do_it_add_share {
  $::testing and return;
  my $in = 'interactive'->vnew('su', 'Samba');
  my $w = $in->wait_message(N("Samba server"), N("Configuring your Samba server..."));

  my $share = $o->{var}{wiz_addshare_name};
  $samba->{$share};
  $samba->{$share}{comment} = $o->{var}{wiz_addshare_comment};
  $samba->{$share}{path} = $o->{var}{wiz_addshare_path};
  $samba->{$share}{browseable} = $o->{var}{wiz_addshare_browseable};
  $samba->{$share}{writable} = $o->{var}{wiz_addshare_writable};
  $samba->{$share}{public} = $o->{var}{wiz_addshare_public};
  $o->{var}{wiz_addshare_dotfiles} and $samba->{$share}{'hide dot files'} = $o->{var}{wiz_addshare_dotfiles};
  $o->{var}{wiz_addshare_hidefiles} and $samba->{$share}{'hide files'} = $o->{var}{wiz_addshare_hidefiles};
  $o->{var}{wiz_addshare_readlist} and $samba->{$share}{'read list'} = $o->{var}{wiz_addshare_readlist};
  $o->{var}{wiz_addshare_writelist} and $samba->{$share}{'write list'} = $o->{var}{wiz_addshare_writelist};
  $o->{var}{wiz_addshare_createmode} and $samba->{$share}{'create mode'} = $o->{var}{wiz_addshare_createmode};

  write_conf_restart_smb();
  undef $w;
  check_started('smbd');
}

# remember one variable cannot be commented and not in the same file.
sub do_it {
    $::testing and return;
    # display a wait dialog box
    my $in = 'interactive'->vnew('su', 'Samba');
    my $w = $in->wait_message(N("Samba server"), N("Configuring your Samba server..."));

    # global section
    $samba->{global}{workgroup} = $o->{var}{wiz_workgroup};
    $samba->{global}{'server string'} = $o->{var}{wiz_banner};

    if ($o->{var}{wiz_netbios}) {
      $samba->{global}{netbios} = $o->{var}{wiz_netbios};
    }

    # add special global options
    global_special_options;

    # log level in global section
    $samba->{global}{'log file'} = $o->{var}{wiz_log_file};
    if ($o->{var}{wiz_log_level}) {
      $samba->{global}{'log level'} = $o->{var}{wiz_log_level};
    }

    $samba->{global}{'max log size'} = $o->{var}{wiz_max_log_size};

    # public share
    if ($o->{var}{wiz_do_file_sharing}) {
      $samba->{public};
      $o->{var}{wiz_write_list} and $samba->{public}{'write list'} = $o->{var}{wiz_write_list};
      $o->{var}{wiz_read_list} and $samba->{public}{'read list'} = $o->{var}{wiz_read_list};
      # enable options if exist
      $o->{var}{wiz_share_comment} and $samba->{public}{comment} = $o->{var}{wiz_share_comment};
      $o->{var}{wiz_share_browseable} and $samba->{public}{browseable} = $o->{var}{wiz_share_browseable};
      $o->{var}{wiz_share_writable} and $samba->{public}{writable} = $o->{var}{wiz_share_writable};
      standalone->explanations("Enabling $o->{var}{wiz_dir} samba file sharing");
      $samba->{public}{path} = $o->{var}{wiz_dir};
    } else {
      standalone->explanations("Disabling samba file sharing");
      delete $samba->{public};
    }

    # share home dir
    if ($o->{var}{wiz_do_homes}) {
      standalone->explanations("Enabling samba homes sharing");
      $samba->{homes};
      $samba->{homes}{comment} = $o->{var}{wiz_home_comment};
      $samba->{homes}{browseable} = $o->{var}{wiz_home_browseable};
      $samba->{homes}{writable} = $o->{var}{wiz_home_writable};
      $samba->{homes}{'create mode'} = $o->{var}{wiz_home_createmode};
    } else {
      standalone->explanations("Disabling samba homes sharing");
      delete $samba->{homes};
    }
    standalone->explanations("Samba deny $o->{var}{wiz_hosts_deny}");
    standalone->explanations("Samba allow $o->{var}{wiz_hosts_allow}");

    # get comment
#    my $v = $samba->get_comments('{printers}');
#    print $v->{normal};
#    print $v->{right_inline};

    # share printers
    if ($o->{var}{wiz_do_printer_sharing}) {
      standalone->explanations("Enabling printer sharing");
      printer_sharing();
    } else {
      standalone->explanations("Disabling printer sharing");
      if ($o->{var}{wiz_box_list}) {
	for(my $i; $i < @{$o->{var}{wiz_box_list}}; $i++) {
	  $o->{var}{list_printers}[$i] and remove_printer($o->{var}{list_printers}[$i]);
	}
      }
      delete $samba->{printers};
    }

    write_conf_restart_smb();
    # remove wait message
    undef $w;
    check_started('smbd');
  }
1;