diff options
author | Arnaud Desmons <adesmons@mandriva.com> | 2002-10-18 13:36:33 +0000 |
---|---|---|
committer | Arnaud Desmons <adesmons@mandriva.com> | 2002-10-18 13:36:33 +0000 |
commit | c30630a03ea000a276e620b8a6b1fd4a0621847f (patch) | |
tree | 82f92a2c94b82c600a81164afb8a6ca07b2d2bc3 /samba_wizard/scripts/Smbconf.pm | |
parent | 40bcc5be304a306e7740cac42be04ff10b6df2b0 (diff) | |
download | drakwizard-c30630a03ea000a276e620b8a6b1fd4a0621847f.tar drakwizard-c30630a03ea000a276e620b8a6b1fd4a0621847f.tar.gz drakwizard-c30630a03ea000a276e620b8a6b1fd4a0621847f.tar.bz2 drakwizard-c30630a03ea000a276e620b8a6b1fd4a0621847f.tar.xz drakwizard-c30630a03ea000a276e620b8a6b1fd4a0621847f.zip |
new improved samba wizard, network access selection under construction
Diffstat (limited to 'samba_wizard/scripts/Smbconf.pm')
-rwxr-xr-x | samba_wizard/scripts/Smbconf.pm | 137 |
1 files changed, 109 insertions, 28 deletions
diff --git a/samba_wizard/scripts/Smbconf.pm b/samba_wizard/scripts/Smbconf.pm index 1466caf0..4f2ab90d 100755 --- a/samba_wizard/scripts/Smbconf.pm +++ b/samba_wizard/scripts/Smbconf.pm @@ -4,8 +4,9 @@ package Smbconf; require "__WIZ_HOME__/common/scripts/Vareqval.pm"; require "__WIZ_HOME__/common/scripts/DrakconnectConf.pm"; use MDK::Common; -use strict; +#use strict; use Data::Dumper; + # All possibilies in the config file must be precedeed by ";" # This script can just comment, uncomment or/and change values # but can not add anything. @@ -31,6 +32,9 @@ sub check_dir { 1; } +# the "__" before comment is to avoid conflicts with possible "comment" variable +# for variables value is in value key and comment idem (no risque of conflict) + sub read_conf { my $self = {}; my ($file) = @_; @@ -55,6 +59,8 @@ sub read_conf { bless $self; } +# we parse @tab to check for values in the struct. + sub write_conf { my $self = shift; my ($file) = @_; @@ -74,7 +80,26 @@ sub write_conf { } } } - + +#section has the name of the printer +sub add_printer { + my $self = shift; + my ($printer) = @_; + + if (exists $self->{conf}->{$printer}) { + $self->comment_menu($printer, ""); + } + else { + $self->{conf}->{$printer}{printable}{comment} = ""; + $self->{conf}->{$printer}{printer}{comment} = ""; + push @{$self->{tab}}, "[$printer]\n"; + push @{$self->{tab}}, "printer = \n"; + push @{$self->{tab}}, "printable = \n"; + $self->{conf}->{$printer}{printer}{value} = $printer; + $self->{conf}->{$printer}{printable}{value} = "yes"; + } +} + sub list_printers { my $file = "/etc/printcap"; my $i; @@ -95,6 +120,7 @@ sub comment_menu { my $self = shift; my ($menu, $str) = @_; + return if (!$menu or !exists $self->{conf}->{$menu}); $self->{conf}->{$menu}{__comment} = $str; foreach (keys %{$self->{conf}->{$menu}}) { ($_ eq "__comment") and next; @@ -116,24 +142,47 @@ sub chg_var { $self->{conf}->{$menu}{$var}{value} = $str; } -sub file_sharing { +sub printer_sharing { my $self = shift; - standalone->explanations("Enabling $ENV{wiz_dir} samba file sharing"); - $self->comment_menu("public", ""); - $self->chg_var("global", "security", "share"); -} + my $printer; -sub homes { - my $self = shift; - standalone->explanations("Enabling samba homes access"); - $self->comment_menu("homes", ""); - $self->chg_var("global", "security", "share"); + if ($ENV{wiz_all_printers}) { + $self->comment_menu("printers", ""); + foreach $printer (keys (%::bool)) { + $self->comment_menu($printer, ";"); + } + } + else { + $self->comment_menu("printers", ";"); + foreach $printer (keys (%::bool)) { + if (int($::bool{$printer})) { + $self->comment_menu($printer, ""); + $self->add_printer($printer); + } + else { + $self->comment_menu($printer, ";"); + } + } + } } -sub printer_sharing { - my $self = shift; - standalone->explanations("Enabling samba printer sharing"); - $self->comment_menu("printers", ""); +sub get_printers { + my $printers; + + if ($ENV{wiz_do_printer_sharing}) { + $ENV{wiz_all_printers} and return "all printers"; + foreach (keys (%::bool)) { + $printers .= "$_, " if int($::bool{$_}); + } + $/ = " "; + chomp $printers; + $/ = ","; + chomp $printers; + "$printers"; + } + else { + "disabled"; + } } sub check_workgroup { @@ -145,12 +194,6 @@ sub ask_acces { 10; } -sub check_printers { - foreach (keys %::bool) { - print "$::bool{$_}\n"; - } -} - my $old = read_conf("/etc/samba/smb.conf"); sub get_write { @@ -183,18 +226,57 @@ sub ask_dir { sub get_dir { $old->{conf}->{public}{path}{value}; } -# remember one variable cannot be commented and not in the same file. +sub get_file_sharing { + return 0 if ($old->{conf}->{public}{__comment} =~ /\;|\#/); + 1; +} + +sub get_home_sharing { + return 0 if ($old->{conf}->{homes}{__comment} =~ /\;|\#/); + 1; +} + +# remember one variable cannot be commented and not in the same file. sub do_it { - my $conf = read_conf("__WIZ_HOME__/samba_wizard/scripts/smb.conf.default"); + my $file = "__WIZ_HOME__/samba_wizard/scripts/smb.conf.default"; + + my $conf = read_conf($file); + $conf->chg_var("global", "security", "share"); $conf->chg_var("global", "workgroup", $ENV{wiz_workgroup}); $conf->chg_var("global", "server string", $ENV{wiz_banner}); $conf->chg_var("public", "write list", $ENV{wiz_write_list}) if $ENV{wiz_do_file_sharing}; $conf->chg_var("public", "read list", $ENV{wiz_read_list}) if $ENV{wiz_do_file_sharing}; my $ip = $o->get_from_known_dev("IP"); - $conf->file_sharing() if $ENV{wiz_do_file_sharing}; - $conf->printer_sharing() if $ENV{wiz_do_printer_sharing}; - $conf->homes() if $ENV{wiz_do_homes}; + if ($ENV{wiz_do_printer_sharing}) { + standalone->explanations("Enabling printer sharing"); + $conf->printer_sharing(); + } + else { + standalone->explanations("Disabling printer sharing"); + foreach $printer (keys (%::bool)) { + if (!int($::bool{$printer})) { + $conf->comment_menu("$printer", ";"); + } + } + $conf->comment_menu("printers", ";"); + } + if ($ENV{wiz_do_file_sharing}) { + standalone->explanations("Enabling $ENV{wiz_dir} samba file sharing"); + $conf->comment_menu("public", ""); + } + else { + standalone->explanations("Disabling samba file sharing"); + $conf->comment_menu("public", ";"); + } + if ($ENV{wiz_do_homes}) { + standalone->explanations("Enabling samba homes sharing"); + $conf->comment_menu("homes", " "); + } + else { + standalone->explanations("Disabling samba homes sharing"); + $conf->comment_menu("homes", ";"); + } $conf->chg_var("global", "hosts allow", $ip); $conf->chg_var("global", "security", "share"); $conf->chg_var("public", "path", $ENV{wiz_dir}) if $ENV{wiz_dir}; @@ -203,4 +285,3 @@ sub do_it { 10; } 1; - |