summaryrefslogtreecommitdiffstats
path: root/samba_wizard/Samba.pm
diff options
context:
space:
mode:
authorAntoine Ginies <aginies@mandriva.com>2005-05-31 02:57:49 +0000
committerAntoine Ginies <aginies@mandriva.com>2005-05-31 02:57:49 +0000
commit0c64b8f540819b29db71a0cc3857be4d7ee61ad3 (patch)
treed37d2aaad79b6aabeade0172423a9616351da180 /samba_wizard/Samba.pm
parentc21aa28a2cb02a125d0481af214f3e1cf3b7a5f4 (diff)
downloaddrakwizard-0c64b8f540819b29db71a0cc3857be4d7ee61ad3.tar
drakwizard-0c64b8f540819b29db71a0cc3857be4d7ee61ad3.tar.gz
drakwizard-0c64b8f540819b29db71a0cc3857be4d7ee61ad3.tar.bz2
drakwizard-0c64b8f540819b29db71a0cc3857be4d7ee61ad3.tar.xz
drakwizard-0c64b8f540819b29db71a0cc3857be4d7ee61ad3.zip
various improvement (managing share)
Diffstat (limited to 'samba_wizard/Samba.pm')
-rwxr-xr-xsamba_wizard/Samba.pm247
1 files changed, 192 insertions, 55 deletions
diff --git a/samba_wizard/Samba.pm b/samba_wizard/Samba.pm
index 61dbe434..224c9016 100755
--- a/samba_wizard/Samba.pm
+++ b/samba_wizard/Samba.pm
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# Drakwizard
-# Copyright (C) 2002,2003 Mandrakesoft
+# Copyright (C) 2002,2005 Mandriva
#
# Authors: Arnaud Desmons <adesmons@mandrakesoft.com>
# Florent Villard <warly@mandrakesoft.com>
@@ -89,7 +89,7 @@ my $o = {
wiz_addshare_writable => '',
wiz_addshare_createmode => '',
wiz_selected_share => '',
- test => '',
+ wiz_selected_share_comment => '',
},
init => sub {
test_host_domain($SHORTHOSTNAME, $DOMAINNAME);
@@ -98,14 +98,12 @@ my $o = {
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);
+#print Dumper($samba);
my %level = (
1 => N('All - No access restriction'),
@@ -117,7 +115,7 @@ my %type = (
2 => N('PDC - primary domain controller'),
3 => N('Standalone - standalone server'),
4 => N('Member - member of a domain'),
- 5 => N('Share - modify a share'),
+ 5 => N('Share - Manage your share'),
);
my %share = (
@@ -126,7 +124,7 @@ my %share = (
3 => N('Modify - modify a share'),
);
-my @yesorno = qw(yes no); #push @yesorno, "";
+my @yesorno = qw(yes no);
my @loglevel = qw(0 1 2 3 4 5 6 7 8 9 10);
$o->{pages} = {
@@ -137,6 +135,7 @@ $o->{pages} = {
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 }
@@ -251,7 +250,8 @@ $o->{pages} = {
return 'choose_share' }
elsif ($o->{var}{wiz_share} == 3) {
return 'choose_share' }
- }
+ },
+ no_back => 1,
},
choose_share => {
name => N('Modify a share'),
@@ -269,45 +269,94 @@ $o->{pages} = {
},
delete_share => {
name => N('Delete a share'),
- # pre => sub {
- # $samba->{$o->{var}{wiz_selected_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} },
],
- complete => sub {
- remove_share($o->{var}{wiz_selected_share});
- },
- next => 'summary',
+ next => 'summary_delete',
},
modify_share => {
name => N('Modify a share'),
- # pre => sub {
- # $samba->{$o->{var}{wiz_selected_share}};
- # },
- next => 'summary',
+ 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_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('Browseable:'), val => \$o->{var}{wiz_share_browseable}, fixed_list => \@yesorno },
+ { 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'),
+ 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'};
+ },
+ data => [
+ { label => N('Create mode:'), val => \$o->{var}{wiz_share_createmode} },
+ { label => N('Read list:'), val => \$o->{var}{wiz_share_readlist}, help => N('root fred @users @wheel') },
+ { label => N('Write list:'), val => \$o->{var}{wiz_share_writelist}, help => N('root fred @users @wheel') },
+ ],
+ next => 'summary_modify',
+ },
add_share => {
- name => N('Add a share') . "\n" . N('You have selected to add a share.') . "\n" . N('Comment: description of the share') . "\n" . N('Browseable: view share') . "\n" . N('Writable: user can write in the share') . "\n" . N('Create mode: man chmod for more info'),
+ 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('Browseable:'), val => \$o->{var}{wiz_addshare_browseable}, fixed_list => \@yesorno },
- { label => N('Writable:'), val => \$o->{var}{wiz_add_share_writable}, fixed_list => \@yesorno },
- { label => N('Create mode:'), val => \$o->{var}{wiz_addshare_createmode} },
+ { label => N('Public:'), val => \$o->{var}{wiz_addshare_public}, fixed_list => \@yesorno },
],
complete => sub {
- chack_share_doesnt_exist($o->{var}{wiz_addshare_name});
+ 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 => 'summary_addshare',
+ next => 'add_share_options',
},
+ add_share_options => {
+ name => N('Add a share') . "\n" . N('If you doesn\'t want to use one 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('root fred @users @wheel') },
+ { label => N('Write list:'), val => \$o->{var}{wiz_addshare_writelist}, help => N('root fred @users @wheel') }
+ ],
+ 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";
+ $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'}
@@ -394,17 +443,6 @@ $o->{pages} = {
],
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 {
@@ -485,8 +523,8 @@ $o->{pages} = {
}
},
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} },
+ { 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',
},
@@ -555,8 +593,43 @@ $o->{pages} = {
],
next => 'summary',
},
+ summary_modify => {
+ name => N('Summary modify a share'),
+ 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} },
+ ],
+ post => \&do_it_modify_share,
+ next => 'end_modify_share',
+ },
+ summary_addshare => {
+ name => N('Summary add share'),
+ 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} },
+ ],
+ next => 'end_add_share',
+ },
+ summary_delete => {
+ name => N('Summary remove a 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.'),
+ 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");
@@ -581,7 +654,22 @@ $o->{pages} = {
end => 1,
next => 0
},
- error_end => {
+ 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,
@@ -633,8 +721,8 @@ sub remove_share {
}
sub remove_printer {
- my ($printer) = @_;
- delete $samba->{$printer};
+ my ($printer) = @_;
+ delete $samba->{$printer};
}
sub list_printers() {
@@ -649,17 +737,18 @@ sub list_printers() {
}
sub list_all_shares() {
+ undef @listshare;
foreach my $clef (keys %$samba) {
if ($samba->{$clef}{printable} =~ /yes/i) {
- print "$clef est une imprimante\n";
+ print "$clef is a printer\n";
} elsif ($clef =~ /global/ or $clef =~ /print\$/) {
print "unwanted\n";
} else {
push @listshare, $clef;
}
}
- print "------------- \n";
- foreach (@listshare) { print "$_\n"; }
+# print "------------- \n";
+# foreach (@listshare) { print "$_\n"; }
return @listshare;
}
@@ -700,6 +789,10 @@ sub global_special_options() {
$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() {
@@ -717,6 +810,7 @@ sub get_printers() {
}
sub store_samba_type {
+ # write config file to store Samba type
my ($type) = @_;
output($wiz_samba_etc, <<EOF);
# 1 = BDC - backup domain controller
@@ -728,6 +822,54 @@ 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 $share = $o->{var}{wiz_selected_share};
+ delete $samba->{$share};
+
+ write_conf_restart_smb();
+ check_started('smbd');
+}
+
+sub do_it_modify_share {
+ $::testing and return;
+ 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_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();
+ check_started('smbd');
+}
+
+sub do_it_add_share {
+ $::testing and return;
+ my $share = $o->{var}{wiz_addshare_name};
+ $samba->{$share};
+ $samba->{$share}{comment} = $o->{var}{wiz_addshare_comment};
+ $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_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();
+ check_started('smbd');
+}
+
# remember one variable cannot be commented and not in the same file.
sub do_it {
$::testing and return;
@@ -785,12 +927,10 @@ sub do_it {
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;
+ # get comment
+# my $v = $samba->get_comments('{printers}');
+# print $v->{normal};
+# print $v->{right_inline};
# share printers
if ($o->{var}{wiz_do_printer_sharing}) {
@@ -805,11 +945,8 @@ sub do_it {
}
delete $samba->{printers};
}
- $samba->write_conf("/etc/samba/smb.conf");
- if (services::is_service_running('smb')) {
- services::restart('smb')
- } else { services::start('smb') }
+ write_conf_restart_smb();
# remove wait message
undef $w;
check_started('smbd');