summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaud Desmons <adesmons@mandriva.com>2002-07-26 09:27:04 +0000
committerArnaud Desmons <adesmons@mandriva.com>2002-07-26 09:27:04 +0000
commitff4638889d241e8c6e9d6b8bbcb411d77f459e74 (patch)
tree592fa0a4af364cfdfafd7b835a8f69dc4b3abba5
parent8713aefb261a6574396bc11929f8d445360c5ffd (diff)
downloaddrakwizard-ff4638889d241e8c6e9d6b8bbcb411d77f459e74.tar
drakwizard-ff4638889d241e8c6e9d6b8bbcb411d77f459e74.tar.gz
drakwizard-ff4638889d241e8c6e9d6b8bbcb411d77f459e74.tar.bz2
drakwizard-ff4638889d241e8c6e9d6b8bbcb411d77f459e74.tar.xz
drakwizard-ff4638889d241e8c6e9d6b8bbcb411d77f459e74.zip
first perl traduction
-rwxr-xr-xsamba_wizard/scripts/Smbconf.pm116
-rw-r--r--web_wizard/scripts/Webconf.pm62
2 files changed, 178 insertions, 0 deletions
diff --git a/samba_wizard/scripts/Smbconf.pm b/samba_wizard/scripts/Smbconf.pm
new file mode 100755
index 00000000..0b3f8e87
--- /dev/null
+++ b/samba_wizard/scripts/Smbconf.pm
@@ -0,0 +1,116 @@
+#! /usr/bin/perl -w
+
+package Smbconf;
+require "__WIZ_HOME__/common/scripts/Vareqval.pm";
+
+use strict;
+
+# 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.
+# so one variable cannot be commented and not in the same file.
+
+my %conf;
+my @tab;
+
+sub read_conf {
+ my ($file) = @_;
+ my $menu;
+
+ open(FH, $file) or die "$!";
+ while (<FH>) {
+ if (/^(\s*\;?\s*)\[(.*)\].*/) {
+ $menu = $2;
+ $conf{$menu}{__comment} = $1;
+ }
+ elsif (/^(?!\#)(\s*\;*\s*)(.*?)\s*=\s*(.*)\s*$/) {
+ $conf{$menu}{$2}{value} = $3;
+ $conf{$menu}{$2}{comment} = $1;
+ }
+ push @tab, $_;
+ }
+}
+
+sub write_conf {
+ my ($file) = @_;
+ my $menu;
+
+ open(FH, "> $file") or die "$!";
+ foreach (@tab) {
+ if (/^\s*\;?\s*\[(.*)\].*/) {
+ $menu = $1;
+ print FH "$conf{$menu}{__comment}"."[$menu]\n";
+ }
+ elsif (/^(?!\#)\s*\;*\s*(.*?)\s*=/) {
+ print FH "$conf{$menu}{$1}{comment}"."$1" ." = ". "$conf{$menu}{$1}{value}\n";
+ }
+ else {
+ print FH $_;
+ }
+ }
+}
+
+sub comment_menu {
+ my ($menu, $str) = @_;
+
+ $conf{$menu}{__comment} = $str;
+ foreach (keys %{$conf{$menu}}) {
+ ($_ eq "__comment") and next;
+ $conf{$menu}{$_}{comment} = $str;
+ }
+}
+
+sub comment_var {
+ my ($menu, $var, $str) = @_;
+
+ $conf{$menu}{$var}{comment} = $str;
+}
+
+sub chg_var {
+ my ($menu, $var, $str) = @_;
+
+ $conf{$menu}{$var}{value} = $str;
+}
+
+sub file_sharing {
+ comment_menu("homes", ";");
+ comment_menu("public", "");
+ chg_var("global", "security", "share");
+}
+
+sub printer_sharing {
+ comment_menu("printers", "");
+}
+
+# remember one variable cannot be commented and not in the same file.
+
+sub hello {
+ my ($str) = @_;
+
+ print $str."\n";
+}
+
+sub finish {
+ my ($file, $device, $ip);
+
+ read_conf("__WIZ_HOME__/samba_wizard/scripts/smb.conf.default");
+ $file = "/etc/sysconfig/mdk_serv";
+ my %mdk = Vareqval->get($file);
+ $mdk{wiz_banner} = $ENV{wiz_banner};
+ $mdk{wiz_workgroup} = $ENV{wiz_workgroup};
+ $mdk{wiz_do_printer_sharing} = $ENV{wiz_do_printer_sharing};
+ $mdk{wiz_do_file_sharing} = $ENV{wiz_do_file_sharing};
+ Vareqval->commit($file, \%mdk);
+ chg_var("global", "workgroup", $ENV{wiz_workgroup});
+ chg_var("global", "server string", $ENV{wiz_banner});
+ $device = $mdk{wiz_device};
+ my %mdk = Vareqval->get("/etc/sysconfig/network-scripts/ifcfg-".$device);
+ $ip = $mdk{IPADDR};
+ ($ENV{wiz_do_file_sharing} eq "true") and file_sharing();
+ ($ENV{wiz_do_printer_sharing} eq "enabled") and printer_sharing();
+ chg_var("global", "hosts allow", $ip);
+ chg_var("global", "security", "share");
+ write_conf("/etc/samba/smb.conf");
+ system("/etc/rc.d/init.d/smb restart >/dev/null 2>&1");
+}
+1;
diff --git a/web_wizard/scripts/Webconf.pm b/web_wizard/scripts/Webconf.pm
new file mode 100644
index 00000000..69f99194
--- /dev/null
+++ b/web_wizard/scripts/Webconf.pm
@@ -0,0 +1,62 @@
+#!/usr/bin/perl
+
+package Webconf;
+require "__WIZ_HOME__/common/scripts/Vareqval.pm";
+
+use strict;
+
+my $that;
+my %mdk;
+my $device;
+my $s;
+
+sub finish {
+ my $old = "/etc/httpd/conf/commonhttpd.conf";
+ my $new = "/tmp/commonhttpd.conf";
+ my $bak = "/etc/httpd/conf/commonhttpd.conf.orig";
+
+ open(OLD, "< $old") or die "can't open $old: $!";
+ open(NEW, "> $new") or die "can't open $new: $!";
+
+ if ($ENV{wiz_web_external} eq "1") {
+ $that = "all";
+ }
+ elsif ($ENV{wiz_web_internal} eq "1") {
+ $device = $mdk{wiz_device};
+ %mdk = Vareqval->get("/etc/sysconfig/network-scripts/ifcfg-".$device);
+ $that = "$mdk{IPADDR}";
+ }
+ else {
+ $that = "localhost";
+ }
+
+ if ($ENV{wiz_web_external} eq "1") {
+ my $that = "all";
+ }
+ elsif ($ENV{wiz_web_internal} eq "1") {
+ %mdk = Vareqval->get("/etc/sysconfig/mdk_serv");
+ defined $mdk{wiz_device} and $device = $mdk{wiz_device} or die "wiz_device not found in mdk_serv\n";
+ %mdk = Vareqval->get("/etc/sysconfig/network-scripts/ifcfg-".$device);
+ defined $mdk{IPADDR} and $that = $mdk{IPADDR} or die "IPADDR not found in /etc/sysconfig/network-scripts/ifcfg-xxx\n";
+ }
+ else {
+ $that = "localhost";
+ print "hello\n"
+ }
+ while (<OLD>) {
+ if( m /^[[:space:]]*<Directory \/home/s...m/^[[:space:]]*<\/Directory>/s ) {
+ { s /^[[:space:]]*Allow .*$/ Allow from $that\n/s;}
+ ;}
+ if( m /^[[:space:]]*<Directory \/var\/www/s...m/^[[:space:]]*<\/Directory>/s ) {
+ { s /^[[:space:]]*Allow .*$/ Allow from $that\n/s;}
+ ;}
+ print NEW $_ or die "can't write to $new: $!";
+ }
+ close(OLD) or die "can't close $old: $!";
+ close(NEW) or die "can't close $new: $!";
+
+ rename($old, $bak) or die "can't rename $old to $bak: $!";
+ rename($new, $old) or die "can't rename $new to $old: $!";
+}
+
+1;