summaryrefslogtreecommitdiffstats
path: root/samba_wizard
diff options
context:
space:
mode:
authorAntoine Ginies <aginies@mandriva.com>2005-05-27 01:45:51 +0000
committerAntoine Ginies <aginies@mandriva.com>2005-05-27 01:45:51 +0000
commit2b178ccf713cd383b5f4540be2753ce68656b29e (patch)
treeb09ea9019cdb68dc67f223acb9cf2687619430af /samba_wizard
parentd4010d321abd5f7db5bd4c6935fdaa32babe62c0 (diff)
downloaddrakwizard-2b178ccf713cd383b5f4540be2753ce68656b29e.tar
drakwizard-2b178ccf713cd383b5f4540be2753ce68656b29e.tar.gz
drakwizard-2b178ccf713cd383b5f4540be2753ce68656b29e.tar.bz2
drakwizard-2b178ccf713cd383b5f4540be2753ce68656b29e.tar.xz
drakwizard-2b178ccf713cd383b5f4540be2753ce68656b29e.zip
add more feature, various fix
Diffstat (limited to 'samba_wizard')
-rwxr-xr-xsamba_wizard/Samba.pm292
1 files changed, 204 insertions, 88 deletions
diff --git a/samba_wizard/Samba.pm b/samba_wizard/Samba.pm
index 1130879e..59726944 100755
--- a/samba_wizard/Samba.pm
+++ b/samba_wizard/Samba.pm
@@ -27,16 +27,14 @@ use strict;
use common;
use services;
use MDK::Wizard::Wizcommon;
-use Data::Dumper;
-use Libconf qw(:functions);
use Libconf::Templates;
use Libconf::Glueconf::Samba::Smb_conf;
my $wiz = new MDK::Wizard::Wizcommon;
my $DOMAINNAME = chomp_(`dnsdomainname`);
-my $HOSTNAME = chomp_(`hostname`);
+my $SHORTHOSTNAME = chomp_(`hostname -s`);
my $o = {
name => 'Samba wizard',
@@ -49,6 +47,10 @@ my $o = {
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 => '',
@@ -63,16 +65,27 @@ my $o = {
wiz_log_level => '',
wiz_max_log_size => '',
list_printers => '',
+ wiz_home_writable => '',
+ wiz_home_browseable => '',
+ wiz_home_createmode => '',
+ wiz_home_comment => '',
+ 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', });
#debug
+use Data::Dumper;
print Dumper($samba);
my %level = (
@@ -80,14 +93,73 @@ my %level = (
2 => N('My rules - Ask me allowed and denied hosts')
);
-my @yesorno = qw(yes no); push @yesorno, "";
+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.'),
+ 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,
- next => 'ask_workgroup'
- },
+ 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'),
+ data => [
+ { label => N('val:'), val => \$o->{var}{test} },
+ ],
+# complete => {},
+ next => 'ask_workgroup',
+ },
+ bdc => {
+ name => N('BDC server: backup domain controller'),
+ data => [
+ { label => N('val:'), val => \$o->{var}{test} },
+# { label => N(':'), val => \$o->{var}{} },
+ ],
+# complete => {},
+ next => 'ask_workgroup',
+ },
+ member => {
+ name => N('Member of a domain'),
+ data => [
+ { label => N('val:'), val => \$o->{var}{test} },
+# { label => N(':'), val => \$o->{var}{} },
+ ],
+# 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 {
@@ -103,7 +175,7 @@ $o->{pages} = {
return 1
} else { return 0 };
},
- next => 'ask_banner'
+ 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.'),
@@ -111,7 +183,7 @@ $o->{pages} = {
$o->{var}{wiz_banner} ||= $samba->{global}{'server string'}
},
data => [
- { label => N('Banner:'), val => \$o->{var}{wiz_banner} },
+ { label => N('Banner:'), val => \$o->{var}{wiz_banner} },
],
complete => sub {
if (!$o->{var}{wiz_banner}) {
@@ -119,21 +191,21 @@ $o->{pages} = {
return 1
} else { return 0 };
},
- next => 'ask_log'
+ next => 'ask_log',
},
ask_log => {
- name => N('Samba Log') . "\n\n" . N(''),
+ 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} },
+ { 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_net',
+ next => 'ask_services',
},
ask_net => {
name => N('Access control') . "\n\n" . N('') . "\n\n" . N(''),
@@ -155,9 +227,9 @@ $o->{pages} = {
post => \&check,
data => [
{ label => N('Allow hosts:'), val => \$o->{var}{wiz_allow_host} },
- { label => N('Deny hosts:'), val => \$o->{var}{wiz_deny_host} },
+ { label => N('Deny hosts:'), val => \$o->{var}{wiz_deny_host} },
],
- next => 'ask_services'
+ 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.'),
@@ -171,21 +243,17 @@ $o->{pages} = {
{ 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} },
],
- complete => sub {
+ post => sub {
if ($o->{var}{wiz_do_file_sharing} == 1) {
return 'ask_dir';
- } else {
- if ($o->{var}{wiz_do_printer_sharing}) { return 'ask_printers' }
- }
+ } 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'
+ next => 'ask_dir',
},
- warn_smbpasswd => {
- name => N('Warning.') . "\n\n" . N('You have selected to allow user access their home directories via samba but you/they must use smbpasswd to set a password.'),
- post => \&ask_dir,
- ignore => 1,
- next => 'summary'
- },
ask_dir => {
name => N('Shared directory:') . "\n\n" . N('Type the path of the directory you want being shared.'),
pre => sub {
@@ -195,10 +263,10 @@ $o->{pages} = {
$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 },
+ { 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 {
@@ -210,15 +278,17 @@ $o->{pages} = {
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 :\nroot, fred, @users, @wheel for each kind of permission.') . "\n\n" . N(''),
+ 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'};
},
- complete => sub {
- if ($o->{var}{wiz_do_printer_sharing}) {
+ post => sub {
+ if ($o->{var}{wiz_do_printer_sharing} == 1) {
return 'ask_printers';
- } else { return 'summary' }
+ } 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} },
@@ -229,18 +299,54 @@ $o->{pages} = {
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}{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 => 'summary'
+ 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
-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.'),
+ 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");
@@ -250,20 +356,25 @@ configure Samba.') . "\n\n" . N('To accept these values, and configure your serv
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('Shared directory:'), fixed_val => \$o->{var}{wiz_dir} },
- { label => N('Print Server:'), fixed_val => \$o->{var}{printer_sharing} },
+ { 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} },
- { label => N('Printers:'), fixed_val => \$o->{var}{printers} },
],
post => \&do_it,
next => 'end'
},
end => {
- name => N('Congratulations') . "\n\n" . N('The wizard successfully configured your Samba server.'),
+ 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 {
@@ -296,21 +407,15 @@ sub check {
0;
}
-sub check_services {
- $o->{var}{wiz_do_homes} and return 'warn_smbpasswd';
- $o->{var}{wiz_do_file_sharing} and return 'ask_dir';
- $o->{var}{wiz_do_printer_sharing} and return 'ask_printers';
-}
-
#section has the name of the printer
sub add_printer {
- my ($printer) = @_;
+ my ($printer) = @_;
$samba->{$printer}{printer} = $printer;
$samba->{$printer}{printable} = 'yes';
}
sub remove_printer {
- my ($printer) = @_;
+ my ($printer) = @_;
delete $samba->{$printer};
}
@@ -323,21 +428,42 @@ sub list_printers {
} cat_("/etc/printcap");
if (@list) {
@list
- } else {
- ()
- }
+ } else { () }
}
+sub list_share {
+ my @listshare;
+ my $share;
+ if ($samba->{$_}{printable} =~ /yes/) {
+ print "$share is a printer\n";
+ ()
+ } else {
+ print "$share is a share\n";
+ push @listshare, $share;
+ }
+}
sub printer_sharing {
- 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);
- }
+ # 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 get_printers {
@@ -354,15 +480,6 @@ sub get_printers {
}
}
-sub ask_acces {
- 10;
-}
-
-sub ask_dir {
- return 'ask_dir' if $o->{var}{wiz_do_file_sharing};
- return 'ask_printers' if $o->{var}{wiz_do_printer_sharing};
-}
-
# remember one variable cannot be commented and not in the same file.
sub do_it {
$::testing and return;
@@ -410,11 +527,10 @@ sub do_it {
if ($o->{var}{wiz_do_homes}) {
standalone->explanations("Enabling samba homes sharing");
$samba->{homes};
- $samba->{homes}{comment} = "Home Directories";
- $samba->{homes}{browseable} = "no";
- $samba->{homes}{writable} = "yes";
- $samba->{homes}{'create mode'} = "0700";
- $samba->{homes}{''} = "0600";
+ $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};
@@ -424,21 +540,21 @@ sub do_it {
# share printers
if ($o->{var}{wiz_do_printer_sharing}) {
- standalone->explanations("Enabling printer sharing");
- printer_sharing();
+ standalone->explanations("Enabling printer sharing");
+ printer_sharing();
} else {
- standalone->explanations("Disabling printer sharing");
- for(my $i; $i < @{$o->{var}{wiz_box_list}}; $i++) {
- remove_printer($o->{var}{list_printers}[$i]);
- }
- delete $samba->{printers};
+ 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')
- }
+ services::restart('smb')
+ } else { services::start('smb') }
undef $w;
check_started('smbd');
}