From c30630a03ea000a276e620b8a6b1fd4a0621847f Mon Sep 17 00:00:00 2001 From: Arnaud Desmons Date: Fri, 18 Oct 2002 13:36:33 +0000 Subject: new improved samba wizard, network access selection under construction --- samba_wizard/scripts/Smbconf.pm | 137 ++++++++++++++++++++++++++++++++-------- 1 file changed, 109 insertions(+), 28 deletions(-) (limited to 'samba_wizard/scripts/Smbconf.pm') 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; - -- cgit v1.2.1