summaryrefslogtreecommitdiffstats
path: root/samba_wizard/scripts/Smbconf.pm
diff options
context:
space:
mode:
authorArnaud Desmons <adesmons@mandriva.com>2002-08-26 13:16:43 +0000
committerArnaud Desmons <adesmons@mandriva.com>2002-08-26 13:16:43 +0000
commitbd52264f669ee3b2b60470df91ee00f116dd3814 (patch)
tree964401ecb48fede8f81623c24a825bd8e93cd4e1 /samba_wizard/scripts/Smbconf.pm
parent153cb4bec0391c88e0d7a7b1aa2cf284f2567ce0 (diff)
downloaddrakwizard-bd52264f669ee3b2b60470df91ee00f116dd3814.tar
drakwizard-bd52264f669ee3b2b60470df91ee00f116dd3814.tar.gz
drakwizard-bd52264f669ee3b2b60470df91ee00f116dd3814.tar.bz2
drakwizard-bd52264f669ee3b2b60470df91ee00f116dd3814.tar.xz
drakwizard-bd52264f669ee3b2b60470df91ee00f116dd3814.zip
OO and get_workgroup, get_banner fillfunc
Diffstat (limited to 'samba_wizard/scripts/Smbconf.pm')
-rwxr-xr-xsamba_wizard/scripts/Smbconf.pm70
1 files changed, 44 insertions, 26 deletions
diff --git a/samba_wizard/scripts/Smbconf.pm b/samba_wizard/scripts/Smbconf.pm
index 62b57ed2..f2331235 100755
--- a/samba_wizard/scripts/Smbconf.pm
+++ b/samba_wizard/scripts/Smbconf.pm
@@ -11,10 +11,8 @@ use strict;
# but can not add anything.
# so one variable cannot be commented and not in the same file.
-my %conf;
-my @tab;
-
my $o = DrakconnectConf->new();
+my $old = read_conf("/etc/samba/smb.conf");
sub check {
$> and return 1;
@@ -28,8 +26,11 @@ sub check_services {
}
sub read_conf {
+ my $self = {};
my ($file) = @_;
my $menu;
+ my @tab;
+ my %conf;
open(FH, $file) or die "$!";
while (<FH>) {
@@ -43,20 +44,24 @@ sub read_conf {
}
push @tab, $_;
}
+ $self->{conf} = \%conf;
+ $self->{tab} = \@tab;
+ bless $self;
}
sub write_conf {
+ my $self = shift;
my ($file) = @_;
my $menu;
open(FH, "> $file") or die "$!";
- foreach (@tab) {
+ foreach (@{$self->{tab}}) {
if (/^\s*\;?\s*\[(.*)\].*/) {
$menu = $1;
- print FH "$conf{$menu}{__comment}"."[$menu]\n";
+ print FH "$self->{conf}->{$menu}{__comment}"."[$menu]\n";
}
elsif (/^(?!\#)\s*\;*\s*(.*?)\s*=/) {
- print FH "$conf{$menu}{$1}{comment}"."$1" ." = ". "$conf{$menu}{$1}{value}\n";
+ print FH "$self->{conf}->{$menu}{$1}{comment}"."$1" ." = ". "$self->{conf}->{$menu}{$1}{value}\n";
}
else {
print FH $_;
@@ -65,60 +70,73 @@ sub write_conf {
}
sub comment_menu {
+ my $self = shift;
my ($menu, $str) = @_;
- $conf{$menu}{__comment} = $str;
- foreach (keys %{$conf{$menu}}) {
+ $self->{conf}->{$menu}{__comment} = $str;
+ foreach (keys %{$self->{conf}->{$menu}}) {
($_ eq "__comment") and next;
- $conf{$menu}{$_}{comment} = $str;
+ $self->{conf}->{$menu}{$_}{comment} = $str;
}
}
sub comment_var {
+ my $self = shift;
my ($menu, $var, $str) = @_;
- $conf{$menu}{$var}{comment} = $str;
+ $self->{conf}->{$menu}{$var}{comment} = $str;
}
sub chg_var {
+ my $self = shift;
my ($menu, $var, $str) = @_;
- $conf{$menu}{$var}{value} = $str;
+ $self->{conf}->{$menu}{$var}{value} = $str;
}
sub file_sharing {
+ my $self = shift;
mkdir_p("/home/samba/public");
standalone->explanations("Enabling samba /home/samba/public sharing");
# comment_menu("homes", ";");
- comment_menu("public", "");
- chg_var("global", "security", "share");
+ $self->comment_menu("public", "");
+ $self->chg_var("global", "security", "share");
}
sub homes {
+ my $self = shift;
standalone->explanations("Enabling samba /home/samba/public sharing");
- comment_menu("homes", "");
- chg_var("global", "security", "share");
+ $self->comment_menu("homes", "");
+ $self->chg_var("global", "security", "share");
}
sub printer_sharing {
+ my $self = shift;
standalone->explanations("Enabling samba printer sharing");
- comment_menu("printers", "");
+ $self->comment_menu("printers", "");
+}
+
+sub get_workgroup {
+ $old->{conf}->{global}{workgroup}{value};
+}
+
+sub get_banner {
+ $old->{conf}->{global}{"server string"}{value};
}
# remember one variable cannot be commented and not in the same file.
sub do_it {
-
- read_conf("__WIZ_HOME__/samba_wizard/scripts/smb.conf.default");
- chg_var("global", "workgroup", $ENV{wiz_workgroup});
- chg_var("global", "server string", $ENV{wiz_banner});
+ my $conf = read_conf("__WIZ_HOME__/samba_wizard/scripts/smb.conf.default");
+ $conf->chg_var("global", "workgroup", $ENV{wiz_workgroup});
+ $conf->chg_var("global", "server string", $ENV{wiz_banner});
my $ip = $o->get_from_known_dev("IP");
- file_sharing() if $ENV{wiz_do_file_sharing};
- printer_sharing() if $ENV{wiz_do_printer_sharing};
- homes() if $ENV{wiz_do_homes};
- chg_var("global", "hosts allow", $ip);
- chg_var("global", "security", "share");
- write_conf("/etc/samba/smb.conf");
+ $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};
+ $conf->chg_var("global", "hosts allow", $ip);
+ $conf->chg_var("global", "security", "share");
+ $conf->write_conf("/etc/samba/smb.conf");
system("/etc/rc.d/init.d/smb restart");
10;
}