#!/usr/bin/perl # Drakwizard # Copyright (C) 2005 Mandriva # # Authors: antoine Ginies # # 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::Sambashare; 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 $in = interactive->vnew; my @listshare; my @listshare_tomodify; my $o = { name => 'Samba wizard', var => { wiz_do_homes => '', wiz_dir => '', wiz_share_comment => '', wiz_share_browseable => '', wiz_share_writable => '', wiz_write_list => '', wiz_read_list => '', wiz_hosts_deny => '', wiz_home_writable => '', wiz_home_browseable => '', wiz_home_createmode => '', wiz_home_comment => '', wiz_share_comment => '', wiz_share_browseable => '', wiz_share_writable => '', wiz_share_create_mask => '', 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/IC-sambashare-48.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'}); #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 %understanding = ( 1 => N("Newbie - classical options"), 2 => N("Expert - advanced options"), ); my %menu_root_share = ( 1 => N("Add/remove/modify share (expert only)"), 2 => N("Special share (CDrom, Homes, Profiles)"), 3 => N("Public share"), 4 => N("User share"), ); my %menu_special_share = ( 1 => N("CDrom - share a CDrom"), 2 => N("Homes - share home user dir"), 3 => N("Profiles - profiles directory on the fly"), ); my %menu_manage = ( 1 => N("Add - add a share"), 2 => N("Remove - remove a share"), 3 => N("Modify - modify a 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"), 5 => N("Homes - share home user dir"), 6 => N("Profiles - profiles directory on the fly"), ); 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 to do?") . "\n\n" . N("Manage, create special share, create public/user share"), pre => sub { if (! -f $wiz_samba_etc) { $in->ask_warn(N("Information"), N("It seems that you haven't setup a Samba server. Please setup a Samba server with Samba wizard before manage your shares.")) or $in->exit; } $o->{var}{wiz_share} = 0; }, data => [ { label => '', val => \$o->{var}{wiz_share}, type => 'list', list => [ sort keys %menu_root_share ], format => sub { $menu_root_share{$_[0]} } }, ], post => sub { if ($o->{var}{wiz_share} == 1) { return 'manage_share' } elsif ($o->{var}{wiz_share} == 2) { return 'special_share' } elsif ($o->{var}{wiz_share} == 3) { return 'add_public_share' } elsif ($o->{var}{wiz_share} == 4) { return 'add_user_share' } }, no_back => 1, }, manage_share => { name => N("What do you want to do with your share?") . "\n\n" . N("add/remove/modify a share"), pre => sub { $o->{var}{manage_share} = 0 }, data => [ { label => '', val => \$o->{var}{manage_share}, type => 'list', list => [ keys %menu_manage ], format => sub { $menu_manage{$_[0]} } }, ], post => sub { if ($o->{var}{manage_share} == 1) { return 'add_share' } elsif ($o->{var}{manage_share} == 2) { return 'choose_share_to_delete' } elsif ($o->{var}{manage_share} == 3) { return 'choose_share_to_modify' } }, no_back => 1, }, special_share => { name => N("Create a special share, what kind?"), pre => sub { $o->{var}{special_share} = 1 }, data => [ { label => '', val => \$o->{var}{special_share}, type => 'list', list => [ keys %menu_special_share ], format => sub { $menu_special_share{$_[0]} } }, ], post => sub { if ($o->{var}{special_share} == 1) { return 'add_cdrom_share' } elsif ($o->{var}{special_share} == 2) { return 'add_homes' } elsif ($o->{var}{special_share} == 3) { return 'add_profiles' } }, no_back => 1, }, understanding => { name => N("Now I need to know your understanding 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 => 'modify_share', }, choose_share_to_delete => { name => N("Delete which share?") . "\n\n" . N("Please choose the share you want to remove."), pre => \&list_all_shares, data => [ { label => '', type => 'list', val => \$o->{var}{wiz_selected_share}, list_ref => \@listshare }, ], next => 'summary_delete', }, choose_share_to_modify => { name => N("Modify which share?") . "\n\n" . N("Please choose the share you want to modify."), pre => \&list_all_shares_to_modify, data => [ { label => '', type => 'list', val => \$o->{var}{wiz_selected_share}, list_ref => \@listshare_tomodify }, ], post => sub { if ($o->{var}{wiz_selected_share} eq 'homes') { return 'modify_homes_share' } }, next => 'understanding', }, modify_homes_share => { name => N("Modify Homes share"), pre => sub { exists $samba->{homes}{comment} and $o->{var}{wiz_homes_commment} = $samba->{homes}{comment}; exists $samba->{homes}{writable} and $o->{var}{wiz_homes_writable} = $samba->{homes}{writable}; exists $samba->{homes}{browseable} and $o->{var}{wiz_homes_browseable} = $samba->{homes}{browseable}; exists $samba->{homes}{'create mode'} and $o->{var}{wiz_homes_create_mode} = $samba->{homes}{'create mode'}; exists $samba->{homes}{'create mask'} and $o->{var}{wiz_homes_create_mask} = $samba->{homes}{'create mask'}; exists $samba->{homes}{'directory mask'} and $o->{var}{wiz_homes_directory_mask} = $samba->{homes}{'directory mask'}; }, data => [ { label => N("Comment:"), val => \$o->{var}{wiz_homes_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("Writable:"), val => \$o->{var}{wiz_homes_writable}, list_ref => \@yesorno }, { label => N("Browseable:"), val => \$o->{var}{wiz_homes_browseable}, list_ref => \@yesorno }, { label => N("Create mode:"), val => \$o->{var}{wiz_homes_create_mode} }, { label => N("Create mask:"), val => \$o->{var}{wiz_homes_create_mask} }, { label => N("Directory mask:"), val => \$o->{var}{wiz_homes_directory_mask} }, ], complete => sub { map { if ($_ and !/^\d+$/) { $in->ask_warn(N("Error"), N("Create mask, create mode and directory mask should be numeric. ie: 0755.")) and return 1; } } $o->{var}{wiz_homes_create_mask}, $o->{var}{wiz_homes_directory_mask}, $o->{var}{wiz_homes_create_mode}; }, next => 'summary_modify_homes_share', }, modify_share => { name => N("Modify a share"), pre => sub { 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})) { $in->ask_warn(N("Error"), N("Please enter a share comment.")); 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:"), val_ref => \$o->{var}{wiz_selected_share} }, { 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}, list_ref => \@yesorno, help => N("Allows share to be displayed in list of share.") }, { label => N("Writable:"), val => \$o->{var}{wiz_share_writable}, list_ref => \@yesorno, help => ('Inverted synonym for read only.') }, { label => N("Public:"), val => \$o->{var}{wiz_share_public}, list_ref => \@yesorno }, ], no_back => 1, next => 'modify_share_options', }, modify_share_options => { name => N("Advanced options, step 1") . "\n\n" . N("Advanced options, use them if you know what you are doing.") . "\n" . N("If you choose Write list wizard will create the samba user without password. Use: smbpasswd [username] to redefine samba user password."), pre => sub { my $share = $o->{var}{wiz_selected_share}; 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'}; $o->{var}{wiz_owner} = "0"; 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("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: anne") }, { label => N("Write list:"), val => \$o->{var}{wiz_share_writelist}, help => N("Specifies a user that have read-write access to a share. ie: fred") }, { label => N("User own directory:"), type => 'bool', val => \$o->{var}{wiz_owner} }, { label => N("valid users"), val => \$o->{var}{wiz_share_valid_users}, help => N("To restrict the share to a particular user. If this is empty (the default) then any user can login. ie: guibo") }, { 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("Hide dot files:"), val => \$o->{var}{wiz_share_dotfiles}, list_ref => \@yesorno, help => N("The hide dot files option hides any files on the server that begin with a dot (.)") }, ], complete => sub { map { my @users = split(" ", $_); foreach my $user (@users) { print "$user\n"; if ($user and !any { /^$user:/ } cat_("/etc/passwd")) { $in->ask_warn(N("Error"), N("Please provide a system user, %s not present.", $user)); return 1; $_; } } } $o->{var}{wiz_share_writelist}, $o->{var}{wiz_share_readlist}, $o->{var}{wiz_share_valid_users}; }, 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'} or $samba->{$share}{'create mask'} = "664"; exists $samba->{$share}{'directory mask'} and $o->{var}{wiz_share_directory_mask} = $samba->{$share}{'directory mask'} or $samba->{$share}{'directory mask'} = 775; 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. 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}, list_ref => \@scase, help => N("lower or upper") }, { label => N("preserve case"), val => \$o->{var}{wiz_share_preserve_case}, list_ref => \@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") }, ], complete => sub { map { if ($_ and $_ !~ /^\d+$/) { $in->ask_warn(N("Error"), N("Create mask, force directory mode and force create mode should be numeric. ie: 0755.")) and return 1; } } $o->{var}{wiz_share_create_mask}, $o->{var}{wiz_share_force_directory_mode}, $o->{var}{wiz_share_force_create_mode}; }, 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}, list_ref => \@yesorno, help => N("Allows share to be displayed in list of share.") }, { label => N("Public:"), val => \$o->{var}{wiz_addshare_public}, list_ref => \@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 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', no_back => 1, }, add_cdrom_share => { name => N("Share a CDROM"), 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:"), val_ref => \$o->{var}{wiz_cdrom_comment} }, { label => N("CDrom path:"), val_ref => \$o->{var}{wiz_cdrom_path} }, { label => N("Browseable:"), val_ref => \$o->{var}{wiz_cdrom_browseable} }, { label => N("Root preexec:"), val_ref => \$o->{var}{wiz_cdrom_pre} }, { label => N("Root postexec:"), val_ref => \$o->{var}{wiz_cdrom_post} }, { label => N("Public:"), val_ref => \$o->{var}{wiz_cdrom_public} }, ], next => 'summary_addcdromshare', }, add_user_share => { name => N("Add a user share") . "\n", pre => sub { $o->{var}{wiz_add_user_share_browseable} = "yes"; $o->{var}{wiz_add_user_share_public} = "no"; $o->{var}{wiz_add_user_share_createmode} = "0700"; $o->{var}{wiz_add_user_share_createmask} = "664"; $o->{var}{wiz_add_user_share_directorymask} = "775"; }, data => [ { label => N("Name of the share:"), val => \$o->{var}{wiz_add_user_share_name} }, { label => N("Comment:"), val => \$o->{var}{wiz_add_user_share_comment} }, { label => N("Path:"), val => \$o->{var}{wiz_add_user_share_path} }, { label => N("Write list:"), val => \$o->{var}{wiz_add_user_share_writelist} }, { label => N("Read list:"), val => \$o->{var}{wiz_add_user_share_readlist} }, ], complete => sub { foreach my $clef (keys %$samba) { if ($clef =~ /$o->{var}{wiz_add_user_share_name}/) { $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_add_user_share_path}) { $in->ask_warn(N("Error"), N("Can\'t create the directory, please enter a correct path.")) and return 1; } if (!$o->{var}{wiz_add_user_share_comment}) { $in->ask_warn(N("Error"), N("Please enter a comment for this share.")) and return 1; } if (! -d $o->{var}{wiz_add_user_share_path}) { mkdir_p($o->{var}{wiz_add_user_share_path}) or $in->ask_warn(N("Error"), N("Can\'t create the directory, please enter a correct path.")); return 1; } else { return 0 } map { my @users = split(" ", $_); foreach my $user (@users) { if ($user and !any { /^$user:/ } cat_("/etc/passwd")) { $in->ask_warn(N("Error"), N("Please provide a system user, %s not present.", $user)); return 1; $_; } } } $o->{var}{wiz_add_user_share_writelist}, $o->{var}{wiz_add_user_share_readlist}; }, next => 'summary_add_user_share', }, add_public_share => { name => N("Add a public share"), pre => sub { $o->{var}{wiz_add_public_share_browseable} = "yes"; $o->{var}{wiz_add_public_share_public} = "yes"; $o->{var}{wiz_add_public_share_createmode} = "0700"; $o->{var}{wiz_add_public_owner} = ""; $o->{var}{wiz_add_public_share_createmask} = "664"; $o->{var}{wiz_add_public_share_directorymask} = "775"; }, data => [ { label => N("Name of the share:"), val => \$o->{var}{wiz_add_public_share_name} }, { label => N("Comment:"), val => \$o->{var}{wiz_add_public_share_comment} }, { label => N("Path:"), val => \$o->{var}{wiz_add_public_share_path} }, { label => N("Writable:"), val => \$o->{var}{wiz_add_public_share_writable}, list_ref => \@yesorno }, { label => N("Public:"), val_ref => \$o->{var}{wiz_add_public_share_public} }, ], complete => sub { foreach my $clef (keys %$samba) { if ($clef =~ /$o->{var}{wiz_add_public_share_name}/) { $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_add_public_share_writable} eq 'yes') { $in->ask_okcancel(N("WARNING"), N("Be careful, you define your public share writable. This wizard will change permission to nobody.users, so do not use this feature on a home directory !")) or return 1; } if (!$o->{var}{wiz_add_public_share_path}) { $in->ask_warn(N("Error"), N("Can't create the directory, please enter a correct path.")) and return 1; } if (!$o->{var}{wiz_add_public_share_comment}) { $in->ask_warn(N("Error"), N("Please enter a comment for this share.")) and return 1; } if (! -d $o->{var}{wiz_add_public_share_path}) { mkdir_p($o->{var}{wiz_add_public_share_path}) or $in->ask_warn(N("Error"), N("Can't create the directory, please enter a correct path.")); return 1; } else { return 0 } }, next => 'summary_add_public_share', }, add_share_options => { name => N("Add a share") . "\n" . N("If you don't want to use one of this options, leave it blank."), pre => sub { $o->{var}{wiz_addshare_createmode} = "0700"; $o->{var}{wiz_owner} = "0"; $o->{var}{wiz_addshare_createmask} = "664"; $o->{var}{wiz_addshare_directorymask} = "775"; }, data => [ { label => N("Writable:"), val => \$o->{var}{wiz_addshare_writable}, list_ref => \@yesorno }, # { 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: aginies") }, { label => N("Write list:"), val => \$o->{var}{wiz_addshare_writelist}, help => N("Specifies a user that have read-write access to a share. ie: guibo") }, { label => N("User own directory:"), type => 'bool', val => \$o->{var}{wiz_owner} }, { label => N("Hide dot files:"), val => \$o->{var}{wiz_addshare_dotfiles}, list_ref => \@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/") }, ], complete => sub { map { my @users = split(" ", $_); foreach my $user (@users) { if ($user and !any { /^$user:/ } cat_("/etc/passwd")) { $in->ask_warn(N("Error"), N("Please provide a system user, %s not present.", $user)); return 1; $_; } } } $o->{var}{wiz_addshare_writelist}, $o->{var}{wiz_addshare_readlist}; if ($o->{var}{wiz_addshare_createmask} and $o->{var}{wiz_addshare_createmask} !~ /^\d+$/) { $in->ask_warn(N("Error"), N("Create mask should be a number. ie: 0755.")) and return 1; } }, next => 'summary_addshare', }, 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}) { $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}, list_ref => \@yesorno }, { label => N("Writable:"), val => \$o->{var}{wiz_home_writable}, list_ref => \@yesorno }, # { label => N("Create mode:"), val => \$o->{var}{wiz_home_createmode} }, ], next => 'summary_homeshare', complete => sub { if ($o->{var}{wiz_home_createmode} and $o->{var}{wiz_home_createmode} !~ /^\d+$/) { $in->ask_warn(N("Error"), N("Create mode should be a number. ie: 0755.")) and return 1; } }, }, add_profiles => { name => N("Specific roving profile share, use the user's home directory"), pre => sub { $o->{var}{wiz_profiles_path} = "/var/lib/samba/profiles"; $o->{var}{wiz_profiles_comment} = "User Profiles"; $o->{var}{wiz_profiles_browseable} = "no"; $o->{var}{wiz_profiles_guest_ok} = "yes"; $o->{var}{wiz_profiles_writable} = "yes"; }, data => [ { label => N("Path:"), val_ref => \$o->{var}{wiz_profiles_path} }, { label => N("Browseable:"), val_ref => \$o->{var}{wiz_profiles_browseable} }, { label => N("Guest access:"), val_ref => \$o->{var}{wiz_profiles_guest_ok} }, { label => N("Writable:"), val_ref => \$o->{var}{wiz_profiles_writable} }, ], next => 'end_add_profiles', post => \&do_it_add_profiles, }, summary_homeshare => { name => N("Summary add home share") . "\n\n" . N("If you really want to add this share, click the Next button or use the Back button."), post => \&do_it_add_homeshare, data => [ { label => N("Comment:"), val_ref => \$o->{var}{wiz_home_comment} }, { label => N("Browseable:"), val_ref => \$o->{var}{wiz_home_browseable}, }, { label => N("Writable:"), val_ref => \$o->{var}{wiz_home_writable}, }, { label => N("Create mode:"), val_ref => \$o->{var}{wiz_home_createmode} }, ], next => 'end_add_share', }, 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:"), val_ref => \$o->{var}{wiz_selected_share} }, { label => N("Comment:"), val_ref => \$o->{var}{wiz_share_comment} }, { label => N("Browseable:"), val_ref => \$o->{var}{wiz_share_browseable} }, { label => N("Writable:"), val_ref => \$o->{var}{wiz_share_writable} }, { label => N("Public:"), val_ref => \$o->{var}{wiz_share_public} }, ], 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:"), val_ref => \$o->{var}{wiz_cdrom_comment} }, { label => N("Cdrom path:"), val_ref => \$o->{var}{wiz_cdrom_path} }, { label => N("Browseable:"), val_ref => \$o->{var}{wiz_cdrom_browseable} }, { label => N("Root preexec:"), val_ref => \$o->{var}{wiz_cdrom_pre} }, { label => N("Root postexec:"), val_ref => \$o->{var}{wiz_cdrom_post} }, { label => N("Public:"), val_ref => \$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 share, click the Next button or use the Back button."), post => \&do_it_add_share, data => [ { label => N("Name of the share:"), val_ref => \$o->{var}{wiz_addshare_name} }, { label => N("Comment:"), val_ref => \$o->{var}{wiz_addshare_comment} }, { label => N("Browseable:"), val_ref => \$o->{var}{wiz_addshare_browseable} }, { label => N("Create mask:"), val_ref => \$o->{var}{wiz_addshare_createmask} }, { label => N("Writable:"), val_ref => \$o->{var}{wiz_addshare_writable} }, { label => N("Public:"), val_ref => \$o->{var}{wiz_addshare_public} }, { label => N("Read list:"), val_ref => \$o->{var}{wiz_addshare_readlist} }, { label => N("Write list:"), val_ref => \$o->{var}{wiz_addshare_writelist} }, { label => N("Hide dot files:"), val_ref => \$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."), pre => sub { my $dshare = $o->{var}{wiz_selected_share}; $o->{var}{wiz_selected_share_comment} = $samba->{$dshare}{comment}; }, data => [ { label => N("Delete this share:"), val_ref => \$o->{var}{wiz_selected_share} }, { label => N("Comment for this share:"), val_ref => \$o->{var}{wiz_selected_share_comment} }, ], post => \&do_it_remove_share, next => 'end_delete_share', no_back => 1, }, summary_modify_homes_share => { name => N("Summary of modify homes share"), data => [ { label => N("Comment:"), val_ref => \$o->{var}{wiz_homes_comment} }, { label => N("Writable:"), val_ref => \$o->{var}{wiz_homes_writable} }, { label => N("Browseable:"), val_ref => \$o->{var}{wiz_homes_browseable} }, { label => N("Create mode:"), val_ref => \$o->{var}{wiz_homes_create_mode} }, { label => N("Create mask:"), val_ref => \$o->{var}{wiz_homes_create_mask} }, { label => N("Directory mask:"), val_ref => \$o->{var}{wiz_homes_directory_mask} }, ], post => \&do_it_modify_homes_share, next => 'end_add_user_share', no_back => 1, }, summary_add_user_share => { name => N("Summary of add a user share") . "\n\n" . N("If you really want to add this share, click the Next button or use the Back button."), data => [ { label => N("Name of the share:"), val_ref => \$o->{var}{wiz_add_user_share_name} }, { label => N("Comment:"), val_ref => \$o->{var}{wiz_add_user_share_comment} }, { label => N("Path:"), val_ref => \$o->{var}{wiz_add_user_share_path} }, { label => N("Write list:"), val_ref => \$o->{var}{wiz_add_user_share_writelist} }, ], post => \&do_it_add_user_share, next => 'end_add_user_share', }, summary_add_public_share => { name => N("Summary of add a public share") . "\n\n" . N("If you really want to add this share, click the Next button or use the Back button."), data => [ { label => N("Name of the share:"), val => \$o->{var}{wiz_add_public_share_name} }, { label => N("Comment:"), val => \$o->{var}{wiz_add_public_share_comment} }, { label => N("Path:"), val => \$o->{var}{wiz_add_public_share_path} }, { label => N("Public:"), val_ref => \$o->{var}{wiz_add_public_share_public} }, { label => N("Writable:"), val_ref => \$o->{var}{wiz_add_public_share_writable} }, ], post => \&do_it_add_public_share, next => 'end_add_public_share', }, end => { name => N("Congratulations") . "\n\n" . N("The wizard successfully configured your Samba."), post => sub { store_samba_type($o->{var}{wiz_type}); }, end => 1, next => 0, no_back => 1, }, end_modify_share => { name => N("Congratulations") . "\n\n" . N("The wizard successfully modified your share."), end => 1, next => 0, no_back => 1, }, end_add_share => { name => N("Congratulations") . "\n\n" . N("The wizard successfully added your share."), end => 1, next => 0, no_back => 1, }, end_add_user_share => { name => N("Congratulations") . "\n\n" . N("The wizard successfully added your user share."), end => 1, next => 0, no_back => 1, }, end_add_public_share => { name => N("Congratulations") . "\n\n" . N("The wizard successfully added your public share."), end => 1, next => 0, no_back => 1, }, end_add_profiles => { name => N("Congratulations") . "\n\n" . N("The wizard successfully added your Profiles share."), end => 1, next => 0, no_back => 1, }, end_delete_share => { name => N("Congratulations") . "\n\n" . N("The wizard successfully removed your share."), end => 1, next => 0, no_back => 1, }, 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, $class; } sub check() { $> and return 1; $wiz->{net}->is_dhcp and return 2; 0; } 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 =~ /profiles/) { print "unwanted\n"; } else { push @listshare_tomodify, $clef; } } return @listshare_tomodify; } 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 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 share"), N("Configuring your Samba server...")); my $share = $o->{var}{wiz_selected_share}; delete $samba->{$share}; if ($share =~ /Profiles/) { delete $samba->{global}{'logon home'} } write_conf_restart_smb(); undef $w; check_started('smbd'); } sub create_smbuser { my ($list) = @_; my @users = split(" ", $list); foreach my $user (@users) { if (!any { /^$user:/ } cat_("/etc/samba/smbpasswd")) { system("smbpasswd -a $user -n"); } } } sub do_it_modify_share { $::testing and return; my $in = 'interactive'->vnew('su', 'Samba'); my $share = $o->{var}{wiz_selected_share}; $samba->{$share}; $samba->{$share}{path} = $o->{var}{wiz_share_path}; if (!-d $samba->{$share}{path}) { mkdir($samba->{$share}{path}); if (!-d $samba->{$share}{path}) { $in->ask_warn(N("Error"), N("Can\'t create %s. Please check why wizard can\'t create this directory.", $samba->{$share}{path})); } } my $w = $in->wait_message(N("Samba share"), N("Configuring your Samba server...")); $samba->{$share}{comment} = $o->{var}{wiz_share_comment}; $o->{var}{wiz_share_browseable} and $samba->{$share}{browseable} = $o->{var}{wiz_share_browseable}; $o->{var}{wiz_share_writable} and $samba->{$share}{writable} = $o->{var}{wiz_share_writable}; $o->{var}{wiz_share_public} and $samba->{$share}{public} = $o->{var}{wiz_share_public}; # master level if ($o->{var}{wiz_understanding} == 2) { $o->{var}{wiz_share_readlist} and $samba->{$share}{'read list'} = $o->{var}{wiz_share_readlist}; if ($o->{var}{wiz_share_writelist}) { $samba->{$share}{'write list'} = $o->{var}{wiz_share_writelist}; if ($o->{var}{wiz_owner}) { system("chown -R $o->{var}{wiz_share_writelist}.users $o->{var}{wiz_share_path}"); } create_smbuser($o->{var}{wiz_share_writelist}); } if ($o->{var}{wiz_share_valid_users}) { $samba->{$share}{'valid users'} = $o->{var}{wiz_share_valid_users}; create_smbuser($o->{var}{wiz_share_valid_users}); } if ($o->{var}{wiz_share_admin_users}) { $samba->{$share}{'admin users'} = $o->{var}{wiz_share_admin_users}; create_smbuser($o->{var}{wiz_share_admin_users}); } $o->{var}{wiz_share_dotfiles} and $samba->{$share}{'hide dot files'} = $o->{var}{wiz_share_dotfiles}; $o->{var}{wiz_share_hidefiles} and $samba->{$share}{'hide files'} = $o->{var}{wiz_share_hidefiles}; $o->{var}{wiz_share_preserve_case} and $samba->{$share}{'preserve case'} = $o->{var}{wiz_share_preserve_case}; $o->{var}{wiz_share_short_preserve_case} and $samba->{$share}{'short preserve case'} = $o->{var}{wiz_share_short_preserve_case}; $o->{var}{wiz_share_create_mask} and $samba->{$share}{'create mask'} = $o->{var}{wiz_share_create_mask}; $o->{var}{wiz_share_directory_mask} and $samba->{$share}{'directory mask'} = $o->{var}{wiz_share_directory_mask}; $o->{var}{wiz_share_force_create_mode} and $samba->{$share}{'force create mode'} = $o->{var}{wiz_share_force_create_mode}; $o->{var}{wiz_share_force_directory_mode} and $samba->{$share}{'force directory mode'} = $o->{var}{wiz_share_force_directory_mode}; $o->{var}{wiz_share_force_group} and $samba->{$share}{'force group'} = $o->{var}{wiz_share_force_group}; $o->{var}{wiz_share_default_case} and $samba->{$share}{'default case'} = $o->{var}{wiz_share_default_case}; } write_conf_restart_smb(); undef $w; check_started('smbd'); } sub do_it_add_profiles { $::testing and return; my $in = 'interactive'->vnew('su', 'Samba'); my $w = $in->wait_message(N("Samba share"), N("Configuring your Samba server...")); $samba->{Profiles}{path} = $o->{var}{wiz_profiles_path}; $samba->{global}{'logon home'} = "\\\\%L\\Profiles\\%u"; $samba->{Profiles}{browseable} = $o->{var}{wiz_profiles_browseable}; $samba->{Profiles}{'guest ok'} = $o->{var}{wiz_profiles_guest_ok}; $samba->{Profiles}{comment} = $o->{var}{wiz_profiles_comment}; $samba->{Profiles}{writable} = $o->{var}{wiz_profiles_writable}; $samba->{Profiles}{'root preexec'} = "PROFILE='/var/lib/samba/profiles/\%u'; if [ ! -e \$PROFILE ]; then mkdir -pm700 \$PROFILE; chown '\%u':'\%g' \$PROFILE;fi"; write_conf_restart_smb(); undef $w; check_started('smbd'); } sub do_it_modify_homes_share { $::testing and return; my $in = 'interactive'->vnew('su', 'Samba'); my $w = $in->wait_message(N("Samba homes share"), N("Configuring your Samba server...")); $o->{var}{wiz_homes_commment} and $samba->{homes}{comment} = $o->{var}{wiz_homes_commment}; $o->{var}{wiz_homes_writable} and $samba->{homes}{writable} = $o->{var}{wiz_homes_writable}; $o->{var}{wiz_homes_browseable} and $samba->{homes}{browseable} = $o->{var}{wiz_homes_browseable}; $o->{var}{wiz_homes_create_mode} and $samba->{homes}{'create mode'} = $o->{var}{wiz_homes_create_mode}; $o->{var}{wiz_homes_create_mask} and $samba->{homes}{'create mask'} = $o->{var}{wiz_homes_create_mask}; $o->{var}{wiz_homes_directory_mask} and $samba->{homes}{'directory mask'} = $o->{var}{wiz_homes_directory_mask}; 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 share"), N("Configuring your Samba server...")); $samba->{cdrom}{comment} = $o->{var}{wiz_cdrom_comment}; $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_homeshare { $::testing and return; my $in = 'interactive'->vnew('su', 'Samba'); my $w = $in->wait_message(N("Samba share"), N("Configuring your Samba server...")); $samba->{homes}; $samba->{homes}{comment} = $o->{var}{wiz_home_comment}; $o->{var}{wiz_home_browseable} and $samba->{homes}{browseable} = $o->{var}{wiz_home_browseable}; $o->{var}{wiz_home_writable} and $samba->{homes}{writable} = $o->{var}{wiz_home_writable}; $o->{var}{wiz_home_createmode} and $samba->{homes}{'create mode'} = $o->{var}{wiz_home_createmode}; write_conf_restart_smb(); undef $w; check_started('smbd'); } sub do_it_add_public_share { $::testing and return; my $in = 'interactive'->vnew('su', 'Samba'); my $share = $o->{var}{wiz_add_public_share_name}; my $w = $in->wait_message(N("Samba share"), N("Configuring your Samba server...")); $samba->{$share}; $samba->{$share}{browseable} = $o->{var}{wiz_add_public_share_browseable}; $samba->{$share}{public} = $o->{var}{wiz_add_public_share_public}; $samba->{$share}{'create mask'} = $o->{var}{wiz_add_public_share_createmask}; $samba->{$share}{'directory mask'} = $o->{var}{wiz_add_public_share_directorymask}; $samba->{$share}{comment} = $o->{var}{wiz_add_public_share_comment}; $samba->{$share}{path} = $o->{var}{wiz_add_public_share_path}; if ($o->{var}{wiz_add_public_share_writable} eq 'yes') { $samba->{$share}{'writable'} = $o->{var}{wiz_add_public_share_writable}; system("chown -R nobody.users $o->{var}{wiz_add_public_share_path}"); } write_conf_restart_smb(); undef $w; check_started('smbd'); } sub do_it_add_user_share { $::testing and return; my $in = 'interactive'->vnew('su', 'Samba'); my $share = $o->{var}{wiz_add_user_share_name}; my $w = $in->wait_message(N("Samba share"), N("Configuring your Samba server...")); $samba->{$share}; $samba->{$share}{browseable} = $o->{var}{wiz_add_user_share_browseable}; $samba->{$share}{public} = $o->{var}{wiz_add_user_share_public}; $samba->{$share}{path} = $o->{var}{wiz_add_user_share_createmode}; $samba->{$share}{'create mask'} = $o->{var}{wiz_add_user_share_createmask}; $samba->{$share}{'directory mask'} = $o->{var}{wiz_add_user_share_directorymask}; $samba->{$share}{comment} = $o->{var}{wiz_add_user_share_comment}; $samba->{$share}{path} = $o->{var}{wiz_add_user_share_path}; $samba->{$share}{'write list'} = $o->{var}{wiz_add_user_share_writelist}; system("chown -R $o->{var}{wiz_add_user_share_writelist}.users $o->{var}{wiz_add_user_share_path}"); create_smbuser($o->{var}{wiz_add_user_share_writelist}); write_conf_restart_smb(); undef $w; check_started('smbd'); } sub do_it_add_share { $::testing and return; my $in = 'interactive'->vnew('su', 'Samba'); my $share = $o->{var}{wiz_addshare_name}; $samba->{$share}; $samba->{$share}{path} = $o->{var}{wiz_addshare_path}; if (!-d $samba->{$share}{path}) { system("mkdir $samba->{$share}{path}"); if (!-d $samba->{$share}{path}) { $in->ask_warn(N("Error"), N("Can\'t create %s. Please check why wizard can\'t create this directory.", $samba->{$share}{path})); } } my $w = $in->wait_message(N("Samba share"), N("Configuring your Samba server...")); $samba->{$share}{comment} = $o->{var}{wiz_addshare_comment}; $o->{var}{wiz_addshare_browseable} and $samba->{$share}{browseable} = $o->{var}{wiz_addshare_browseable}; $o->{var}{wiz_addshare_writable} and $samba->{$share}{writable} = $o->{var}{wiz_addshare_writable}; $o->{var}{wiz_addshare_public} and $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}; if ($o->{var}{wiz_addshare_readlist}) { $samba->{$share}{'read list'} = $o->{var}{wiz_addshare_readlist}; create_smbuser($o->{var}{wiz_addshare_readlist}); } if ($o->{var}{wiz_addshare_writelist}) { $samba->{$share}{'write list'} = $o->{var}{wiz_addshare_writelist}; if ($o->{var}{wiz_owner}) { system("chown -R $o->{var}{wiz_addshare_writelist}.users $o->{var}{wiz_addshare_path}"); } create_smbuser($o->{var}{wiz_addshare_writelist}); } $o->{var}{wiz_addshare_createmask} and $samba->{$share}{'create mask'} = $o->{var}{wiz_addshare_createmask}; $o->{var}{wiz_addshare_directorymask} and $samba->{$share}{'directory mask'} = $o->{var}{wiz_addshare_directorymask}; write_conf_restart_smb(); undef $w; check_started('smbd'); } 1;