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

# Drakwizard
# Copyright (C) 2002,2003 Mandrakesoft
#
# 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 $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_domain => '',
		 test => '',
		},
	 init => sub {
           test_host_domain($SHORTHOSTNAME, $DOMAINNAME);
         },
	 needed_rpm => [ 'samba-server' ],
	 defaultimage => "/usr/share/wizards/samba_wizard/images/samba.png"
	};

#pdc #bdc #standalone #membre #share_files #share_printers

# 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'),
	   );

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 {
                             $o->{var}{wiz_type} ||= 1;
                           },
			   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 'standalone' }
                             elsif ($o->{var}{wiz_type} == 4) {
			       return 'member' }
                           },
                           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_passdb_backend} ||=  $samba->{global}{'passdb backend'};
			       $o->{var}{wiz_wins_support} ||=  $samba->{global}{'wins support'};
			     },
		       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('Passdb backend'), val => \$o->{var}{wiz_passdb_backend}, help => "ldapsam:ldap://<ldap server name>" },
			       ],
#		       complete => {},
		       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";
			      },
		       data => [
				{ label => N('Security:'), fixed_val => \$o->{var}{wiz_security} },
				{ label => N('Domain master:'), fixed_val => \$o->{var}{wiz_domain_master} },
			       ],
#		       complete => {},
		       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};
				  $o->{var}{wiz_passdb_backend} ||=  $samba->{global}{'passdb backend'};;
				 },
			  data => [
				   { label => N('Password server'), val => \$o->{var}{wiz_password_server} },
				   { label => N('Domain:'), val => \$o->{var}{wiz_domain} },
				   { label => N('Passdb backend'), val => \$o->{var}{wiz_passdb_backend}, help => "ldapsam:ldap://<ldap server name>" },
				   { label => N('Security:'), fixed_val => \$o->{var}{wiz_security} },
				   { label => N('Domain master:'), fixed_val => \$o->{var}{wiz_domain_master} },
				  ],
#			  complete => {},
			  next => 'ask_workgroup',
			 },
	       standalone => {
			      name => N('Standalone server') . "\n\n" . ('Share data, users home or printers.'),
			      data => [
				       { label => N('val:'), val => \$o->{var}{test} },
#				       { label => N(':'),  val => \$o->{var}{} },
				      ],
#			      complete => {},
			      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} },
				      ],
			      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} },
				    { label => N('Max log size:'), val => \$o->{var}{wiz_max_log_size} },
				    { label => N('Log level:'), val => \$o->{var}{wiz_log_level}, fixed_list => \@loglevel },
				   ],
			   next => 'ask_services',
			  },
	       ask_net => {
			   name => N('Access control') . "\n\n" . N('') . "\n\n" . N(''),
			   pre => sub {
			     $o->{var}{wiz_level} ||= 1
			   },
			   post => sub { return 'ask_netmask' if $o->{var}{wiz_level} == 2 },
			   data => [
				    { label => N('Access level :'), val => \$o->{var}{wiz_level}, list => [ keys %level ], format => sub { $level{$_[0]} } },
				   ],
			   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} },
					{ label => N('Deny hosts:'), val => \$o->{var}{wiz_deny_host} },
				       ],
			       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};
			     $o->{var}{wiz_share_comment} ||= $samba->{public}{comment};
			     $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 },
				    { 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} },
				   ],
			   post => sub {
			     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;
			     } else { return 0 }
			   },
			   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",
			      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('root, fred, @users, @wheel'), val => \$o->{var}{wiz_read_list} },
				       { label => N('write list:'), help => N('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 {
					  $o->{var}{wiz_printers_comment} ||= $samba->{printers}{comment};
					  $o->{var}{wiz_printers_browseable} ||= $samba->{printers}{browseable};
					  $o->{var}{wiz_printers_guestok} ||= $samba->{printers}{'guest ok'};
					  $o->{var}{wiz_printers_createmode} ||= $samba->{printers}{'create mode'};
					},
					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 {
			       $o->{var}{wiz_home_comment} ||= $samba->{homes}{comment};
			       $o->{var}{wiz_home_browseable} ||= $samba->{homes}{browseable};
			       $o->{var}{wiz_home_writable} ||= $samba->{homes}{writable};
			       $o->{var}{wiz_home_createmode} ||= $samba->{homes}{'create mode'};
			     },
			     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 => {
			   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.'),
			   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.'),
		       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_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_share {
  my @listshare;
  foreach my $clef (keys %$samba) {
    if ($samba->{$clef}{printable} =~ /yes/i) {
      print "$clef est une imprimante\n";
    } else {
      push @listshare, $clef;
    }
    print "------------- \n";
    foreach (@listshare) { print "$_\n"; }
  }
}

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 {
  $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_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};
}

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';
    }
}

# 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};
      if ($o->{var}{wiz_write_list}) {
	$samba->{public}{'write list'} = $o->{var}{wiz_write_list};
      }
      if ($o->{var}{wiz_read_list}) {
	$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}");

    print "---------debug D\n";
    my $v = $samba->get_comments('{printers}');
    print $v->{normal};
    #    print $v->{right_inline};
    print "\n-------debug E\n";
#    list_share;

    # 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++) {
	  remove_printer($o->{var}{list_printers}[$i]);
	}
      }
      delete $samba->{printers};
    }
    $samba->write_conf("/etc/samba/smb.conf");
    if (services::is_service_running('smb')) {
      services::restart('smb')
      } else { services::start('smb') }
    undef $w;
    check_started('smbd');
  }
1;