diff options
-rwxr-xr-x | samba_wizard/Sambasharing.pm | 231 |
1 files changed, 138 insertions, 93 deletions
diff --git a/samba_wizard/Sambasharing.pm b/samba_wizard/Sambasharing.pm index e7e674db..dcd01bc2 100755 --- a/samba_wizard/Sambasharing.pm +++ b/samba_wizard/Sambasharing.pm @@ -32,6 +32,7 @@ use Libconf::Glueconf::Samba::Smb_conf; my $wiz = new MDK::Wizard::Wizcommon; my @listshare; +my @listshare_tomodify; my $o = { name => 'Samba wizard', @@ -44,10 +45,11 @@ my $o = { wiz_hosts_deny => '', wiz_home_writable => '', wiz_home_browseable => '', wiz_home_createmode => '', wiz_home_comment => '', - wiz_addshare_comment => '', wiz_addshare_browseable => '', wiz_addshare_writable => '', - wiz_addshare_createmode => '', wiz_addshare_dotfiles => '', + wiz_share_comment => '', wiz_share_browseable => '', wiz_share_writable => '', + wiz_share_createmode => '', wiz_share_dotfiles => '', wiz_share_hidefiles => '', wiz_selected_share => '', wiz_selected_share_comment => '', + wiz_understanding => '', }, needed_rpm => [ 'samba-server' ], defaultimage => "/usr/share/wizards/samba_wizard/images/samba.png" @@ -60,9 +62,14 @@ use Data::Dumper; #print Dumper($samba); my %level = ( - 1 => N('All - No access restriction'), - 2 => N('My rules - Ask me allowed and denied hosts') -); + 1 => N('All - No access restriction'), + 2 => N('My rules - Ask me allowed and denied hosts') + ); + +my %understanding = ( + 1 => N('Newbie - classical options'), + 2 => N('Master - advanced options'), + ); my %share = ( 1 => N('Add - add a share'), @@ -72,11 +79,20 @@ my %share = ( 5 => N('Homes - share home user dir'), ); -my @yesorno = qw(yes no);# push @yesorno, " "; +my @yesorno = qw(yes no); push @yesorno, ""; +my @scase = qw(lower upper); push @scase, ""; +my $wiz_samba_etc = "/etc/sysconfig/wizard_samba"; $o->{pages} = { welcome => { name => N('What do you want todo with your share ?') . "\n\n" . N('add/remove/modify a share'), + pre => sub { + if (! -f $wiz_samba_etc) { + $::in->ask_warn(N("Information"), N("It seems that you don\'t setup a Samba server. Please setup a Samba server with Samba wizard before manage your share.")); + exit(1); + } + $o->{var}{wiz_share} = 1; + }, data => [ { label => N("what do you want:"), val => \$o->{var}{wiz_share}, list => [ keys %share ], format => sub { $share{$_[0]} } }, ], @@ -84,61 +100,53 @@ $o->{pages} = { if ($o->{var}{wiz_share} == 1) { return 'add_share' } elsif ($o->{var}{wiz_share} == 2) { - return 'choose_share' } + return 'choose_share_to_delete' } elsif ($o->{var}{wiz_share} == 3) { - return 'choose_share' } + return 'understanding' } elsif ($o->{var}{wiz_share} == 4) { return 'add_cdrom_share' } elsif ($o->{var}{wiz_share} == 5) { - return 'ask_homes' } + return 'add_homes' } }, 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'; - } + understanding => { + name => N('Now i need to know your undestanding in Samba server configuration'), + data => [ + { label => N("What kind of user are you:"), val => \$o->{var}{wiz_understanding}, list => [ keys %understanding ], format => sub { $understanding{$_[0]} } }, + ], + next => 'choose_share_to_modify', }, - 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; - } - if ($o->{var}{wiz_selected_share} =~ /homes/ || $o->{var}{wiz_share} == 2) { - $::in->ask_warn(N('Error'), N('Can\'t modify homes 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', - }, + choose_share_to_delete => { + name => N('Delete wich share ?') . "\n\n" . N('Please choose the share you want to remove.'), + pre => \&list_all_shares, + data => [ + { label => N('Share you want to delete:'), val => \$o->{var}{wiz_selected_share}, fixed_list => \@listshare }, + ], + next => 'summary_delete', + }, + choose_share_to_modify => { + name => N('Modify wich share ?') . "\n\n" . N('Please choose the share you want to modify.'), + pre => \&list_all_shares_to_modify, + data => [ + { label => N('Share you want to modify:'), val => \$o->{var}{wiz_selected_share}, fixed_list => \@listshare_tomodify }, + ], + next => 'modify_share', + }, 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}; + if (!$o->{var}{wiz_selected_share}) { + $::in->ask_warn(N("Information"), N("There is no share to modify, please add one.")); + exit(1); + } else { + my $share = $o->{var}{wiz_selected_share}; + exists $samba->{$share}{comment} and $o->{var}{wiz_share_comment} = $samba->{$share}{comment}; + exists $samba->{$share}{writable} and $o->{var}{wiz_share_writable} = $samba->{$share}{writable}; + exists $samba->{$share}{browseable} and $o->{var}{wiz_share_browseable} = $samba->{$share}{browseable}; + exists $samba->{$share}{path} and $o->{var}{wiz_share_path} = $samba->{$share}{path}; + exists $samba->{$share}{public} and $o->{var}{wiz_share_public} = $samba->{$share}{public}; + } }, complete => sub { if (!($o->{var}{wiz_share_comment})) { @@ -146,33 +154,68 @@ $o->{pages} = { return 1; } }, + post => sub { + if ($o->{var}{wiz_understanding} == 1) { + return 'summary_modify'; + } elsif ($o->{var}{wiz_understanding} == 2) { + return 'modify_share_options'; + } else { + print "perdu\n"; + } + }, 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('Comment:'), val => \$o->{var}{wiz_share_comment}, help => N('This is a text field that is seen next to a share when a client does a queries the server') }, { 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('Writable:'), val => \$o->{var}{wiz_share_writable}, fixed_list => \@yesorno, help => ('Inverted synonym for read only.') }, { label => N('Public:'), val => \$o->{var}{wiz_share_public}, fixed_list => \@yesorno }, ], + no_back => 1, 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.'), + name => N('Advanced options, step 1') . "\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'}; + exists $samba->{$share}{'read list'} and $o->{var}{wiz_share_readlist} = $samba->{$share}{'read list'}; + exists $samba->{$share}{'write list'} and $o->{var}{wiz_share_writelist} = $samba->{$share}{'write list'}; + exists $samba->{$share}{'hide dot files'} and $o->{var}{wiz_share_dotfiles} = $samba->{$share}{'hide dot files'}; + exists $samba->{$share}{'hide files'} and $o->{var}{wiz_share_hidefiles} = $samba->{$share}{'hide files'}; + exists $samba->{$share}{'valid users'} and $o->{var}{wiz_share_valid_users} = $samba->{$share}{'valid users'}; + exists $samba->{$share}{'admin users'} and $o->{var}{wiz_share_admin_users} = $samba->{$share}{'admin users'}; }, 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('valid users'), val => \$o->{var}{wiz_share_valid_users}, help => N('To restrict the share to a particular set of users. If this is empty (the default) then any user can login. ie: guibo, anne') }, + { label => N('admin users'), val => \$o->{var}{wiz_share_admin_users}, help => N('This is a list of users who will be granted administrative privileges on the share. This means that they will do all file operations as the super-user (root). You should use this option very carefully, as any user in this list will be able to do anything they like on the share, irrespective of file permissions.') }, { 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/") }, + { 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 (.)") }, ], - next => 'summary_modify', + next => 'modify_share_options2', + }, + modify_share_options2 => { + name => N('Advanced options, step 2') . "\n\n" . N('Advanced options, use them only if you know what you are doing.'), + pre => sub { + my $share = $o->{var}{wiz_selected_share}; + exists $samba->{$share}{'preserve case'} and $o->{var}{wiz_share_preserve_case} = $samba->{$share}{'preserve case'}; + exists $samba->{$share}{'short preserve case'} and $o->{var}{wiz_share_short_preserve_case} = $samba->{$share}{'short preserve case'}; + exists $samba->{$share}{'create mask'} and $o->{var}{wiz_share_create_mask} = $samba->{$share}{'create mask'}; + exists $samba->{$share}{'force create mode'} and $o->{var}{wiz_share_force_create_mode} = $samba->{$share}{'force create mode'}; + exists $samba->{$share}{'force directory mode'} and $o->{var}{wiz_share_force_directory_mode} = $samba->{$share}{'force directory mode'}; + exists $samba->{$share}{'force group'} and $o->{var}{wiz_share_force_group} = $samba->{$share}{'force group'}; + exists $samba->{$share}{'default case'} and $o->{var}{wiz_share_default_case} = $samba->{$share}{'default case'}; + }, + data => [ + { label => N('create mask'), val => \$o->{var}{wiz_share_create_mask}, help => N('When a file is created, the necessary permissions are calculated according to the mapping from DOS modes to UNIX permissions, and the resulting UNIX mode is then bit-wise \'AND\'ed with this parameter. This parameter may be thought of as a bit-wise MASK for the UNIX modes of a file. Any bit not set here will be removed from the modes set on a file when it is created.') }, + { label => N('force create mode'), val => \$o->{var}{wiz_share_force_create_mode}, help => N('This parameter specifies a set of UNIX mode bit permissions that will always be set on a file created by Samba. This is done by bitwise \'OR\'ing these bits onto the mode bits of a file that is being created or having its permissions changed. The default for this parameter is (in octal) 000. ie: force create mode = 0700 ') }, + { label => N('force directory mode'), val => \$o->{var}{wiz_share_force_directory_mode}, help => N('This parameter specifies a set of UNIX mode bit permissions that will always be set on a directory created by Samba. This is done by bitwise \'OR\'ing these bits onto the mode bits of a directory that is being created. The default for this parameter is (in octal) 0000 which will not add any extra permission bits to a created directory. Default: ie: force directory mode = 0755') }, + { label => N('force group'), val => \$o->{var}{wiz_share_force_group}, help => N('This specifies a UNIX group name that will be assigned as the default primary group for all users connecting to this service. This is useful for sharing files by ensuring that all access to files on service will use the named group for their permissions checking. ie: force group = agroup') }, + { label => N('default case'), val => \$o->{var}{wiz_share_default_case}, fixed_list => \@scase, help => N('lower or upper') }, + { label => N('preserve case'), val => \$o->{var}{wiz_share_preserve_case}, fixed_list => \@yesorno, help => N('This controls if new filenames are created with the case that the client passes, or if they are forced to be the default case') }, + ], + 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'), @@ -186,10 +229,20 @@ $o->{pages} = { 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 + $::in->ask_warn(N("Error"), N("Share with the same name already exist or share name empty, please choose another name.")); + return 1; } } + if (!$o->{var}{wiz_addshare_path}) { + $::in->ask_warn(N("Error"), N("Can\'t create the directory, please enter a correct path.")) and return 1; + } + if (!$o->{var}{wiz_addshare_comment}) { + $::in->ask_warn(N("Error"), N("Please enter a Comment for this share.")) and return 1; + } + if (! -d $o->{var}{wiz_addshare_path}) { + mkdir_p($o->{var}{wiz_addshare_path}) or $::in->ask_warn(N("Error"), N("Can\'t create the directory, please enter a correct path.")); + return 1; + } else { return 0 } }, next => 'add_share_options', }, @@ -229,7 +282,7 @@ $o->{pages} = { }, 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('Create mask:'), val => \$o->{var}{wiz_addshare_createmask} }, { 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 (.)") }, @@ -237,7 +290,7 @@ $o->{pages} = { ], next => 'summary_addshare', }, - ask_homes => { + add_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}) { @@ -280,11 +333,6 @@ $o->{pages} = { { 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', @@ -309,9 +357,9 @@ $o->{pages} = { { 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('Create mask:'), fixed_val => \$o->{var}{wiz_addshare_createmask} }, { 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} }, @@ -320,9 +368,14 @@ $o->{pages} = { }, 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} }, - ], + 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} }, + ], post => \&do_it_remove_share, next => 'end_delete_share', }, @@ -365,32 +418,24 @@ sub new { }, $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; } -sub remove_share { - my ($share) = @_; - delete $samba->{$share}; +sub list_all_shares_to_modify() { + undef @listshare_tomodify; + foreach my $clef (keys %$samba) { + if ($samba->{$clef}{printable} =~ /yes/i) { + print "$clef is a printer\n"; + } elsif ($clef =~ /global/ or $clef =~ /print\$/ or $clef =~ /cdrom/ or $clef =~ /homes/) { + print "unwanted\n"; + } else { + push @listshare_tomodify, $clef; + } + } + return @listshare_tomodify; } sub list_all_shares() { |