diff options
-rw-r--r-- | Makefile | 25 | ||||
-rwxr-xr-x | client_wizard/Bind_client.pm | 7 | ||||
-rwxr-xr-x | dhcp_wizard/Dhcp.pm | 39 | ||||
-rwxr-xr-x | drakwizard.pl | 4 | ||||
-rw-r--r-- | drakwizard.spec | 7 | ||||
-rwxr-xr-x | ftp_wizard/Proftpd.pm | 189 | ||||
-rwxr-xr-x | news_wizard/Inn.pm | 115 | ||||
-rwxr-xr-x | postfix_wizard/Postfix.pm | 10 | ||||
-rwxr-xr-x | proxy_wizard/Squid.pm | 240 | ||||
-rwxr-xr-x | samba_wizard/Samba.pm | 517 | ||||
-rwxr-xr-x | web_wizard/Apache.pm | 21 |
11 files changed, 1001 insertions, 173 deletions
@@ -32,8 +32,8 @@ install: mkdir -p --mode=u=rwx,g=rx,o=rx ${prefix}/share/wizards/client_wizard/images mkdir -p ${prefix}/$(PERL_VENDORLIB)/MDK/Wizard/ install -p drakwizard.pl ${prefix}/sbin/drakwizard - perl -i -pe "s|__WIZ_HOME__|$(WIZ_HOME)/|g" ${prefix}/sbin/drakwizard - perl -i -pe "s|\$::DEBUG = 1|\$::DEBUG = 0|g" ${prefix}/sbin/drakwizard + perl -i -pe "s|__WIZ_HOME__|$(WIZ_HOME)/|g; s|$$ENV{__WIZ_HOME__}|$(WIZ_HOME)/|g" ${prefix}/sbin/drakwizard + perl -i -pe "s|new IFCFG|new MDK::Wizard::IFCFG|g" common/Wizcommon.pm for l in $(OTHER); do \ $(MAKE) -C $$l $@; \ done @@ -43,18 +43,33 @@ install: install --mode=a=r -p $$l/images/*.png ${prefix}/share/wizards/client_wizard/images; \ done find ${prefix}/share/wizards -type f -regex ".*\.wiz$$\|.*.pm$$\|.*\.sh$$" -exec \ - perl -i -pe "s|__WIZ_HOME__|$(WIZ_HOME)|g" \{\} \; + perl -i -pe "s|__WIZ_HOME__|$(WIZ_HOME)|g; s|$$ENV{__WIZ_HOME__}|$(WIZ_HOME)/|g" \{\} \; clean: $(MAKE) -C po $@ rm -f *~ -tar: clean +dis: clean cd ..; cp -rf wizard_perl $(NAME) cd ..; tar cf - $(NAME) | bzip2 -9 > $(TAR) cd ..; rm -rf $(NAME) -rpm: tar +changelog: ../common/username + ( cvs2cl -U ../common/username -I ChangeLog -I tmp/ ; \ + rm -f ChangeLog.bak ; \ + cvs commit -m "Generated by cvs2cl the `date '+%c'`" ChangeLog ; \ + ) + +cvstag: + cvs commit + cvs tag $(RELTAG) + +rpm: changelog cvstag dis ../$(NAME)-$(VERSION).tar.bz2 $(RPM) + cp -f ../$(NAME)-$(VERSION).tar.bz2 $(RPM)/SOURCES + -rpm -ba --clean $(NAME).spec + rm -f ../$(NAME)-$(VERSION).tar.bz2 + +localrpm: dis cp -f ../$(TAR) $(RPM)/SOURCES cp -f $(NAME).spec $(RPM)/SPECS/ -rpm -ba $(NAME).spec diff --git a/client_wizard/Bind_client.pm b/client_wizard/Bind_client.pm index a29a6b23..fc7996f3 100755 --- a/client_wizard/Bind_client.pm +++ b/client_wizard/Bind_client.pm @@ -36,7 +36,8 @@ my $o = { client_ip => '', client_name => '' }, - needed_rpm => [ ] + needed_rpm => [ ], + defaultimage => "$ENV{__WIZ_HOME__}client_wizard/images/DNS.png" }; $o->{pages} = { @@ -54,7 +55,6 @@ $o->{pages} = { }, post => \&check, data => [ - { label => '' }, { label => N('Name of the machine:'), val => \$o->{var}{client_name} }, { label => N('IP number of the machine:'), val => \$o->{var}{client_ip} }, ], @@ -79,7 +79,6 @@ $o->{pages} = { name => N('Adding a new client to your network') . "\n\n" . N('The wizard collected the following parameters needed to add a client to your network:') . "\n\n" . N('To accept these values, and add your client, click the Next button or use the Back button to correct them.'), data => [ { label => N('Client name'), fixed_val => \$o->{var}{client_name} }, - { label => '' }, { label => N('Client IP:'), fixed_val => \$o->{var}{client_ip} }, ], post => \&do_it, @@ -146,7 +145,7 @@ sub test { } sub do_it { - $::DEBUG and return; + $::testing and return; my $date = `date`; chomp($date); my $wiz_ip_net = "$1.$2.$3.0" if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/; diff --git a/dhcp_wizard/Dhcp.pm b/dhcp_wizard/Dhcp.pm index ba9b71d1..b8168450 100755 --- a/dhcp_wizard/Dhcp.pm +++ b/dhcp_wizard/Dhcp.pm @@ -34,9 +34,11 @@ my $o = { name => N('DHCP Wizard'), var => { ip1 => '', - ip2 => '' + ip2 => '', + interface => $wiz->{net}->default_itf() }, - needed_rpm => [ 'dhcp-server' ] + needed_rpm => [ 'dhcp-server' ], + defaultimage => "$ENV{__WIZ_HOME__}dhcp_wizard/images/DHCP.png" }; $o->{pages} = { @@ -54,12 +56,21 @@ $o->{pages} = { }, post => \&check, data => [ - { label => '' }, { label => N('Lowest IP Address:'), val => \$o->{var}{ip1} }, { label => N('Highest IP Address:'), val => \$o->{var}{ip2} }, ], next => 'summary' }, + interface => { + name => N('Interface the dhcp server must listen to'), + pre => sub { + $o->{var}{interface} ||= $wiz->{net}->default_itf() + }, + data => [ + { list => [ keys %{$wiz->{net}{itf}} ], val => \$o->{var}{interface} }, + ], + next => 'summary' + }, dhcp_warning => { name => N('Warning'), data => [ { label => N('You are in dhcp, server may not work with your configuration.') } ], @@ -84,8 +95,8 @@ $o->{pages} = { name => N('Configuring the DHCP Server') . "\n\n" . N('The wizard collected the following parameters needed to configure your DHCP service:'), data => [ { label => N('Lowest IP Address:'), fixed_val => \$o->{var}{ip1} }, - { label => '' }, { label => N('Highest IP Address:'), fixed_val => \$o->{var}{ip2} }, + { label => N('Interface:'), fixed_val => \$o->{var}{interface} }, ], post => \&do_it, next => 'end' @@ -129,11 +140,12 @@ sub check { } if (!$d1 || !$d2 || $d1 > $d2) { standalone::explanations("DHCP wizard : bad range"); return 'ip_range_error'} if ($ds >= $d1 && $ds <= $d2) { standalone::explanations("DHCP wizard : server in range"); return 'server_in_range'} + return 'interface' if keys %{$wiz->{net}{itf}} > 1; 0 } sub do_it { - $::DEBUG and return; + $::testing and return; my $wiz_domain_name = $wiz->{net}->network_get("DOMAINNAME"); my $wiz_host_name = $wiz->{net}->network_get("HOSTNAME"); my $wiz_gateway = $wiz->{net}->network_get("GATEWAY"); @@ -151,7 +163,7 @@ sub do_it { my $wiz_ip_range1 = $o->{var}{ip1}; my $wiz_ip_range2 = $o->{var}{ip2}; my $wiz_ip_netmask = $wiz->{net}->itf_get("NETMASK"); - my $wiz_device = $wiz->{net}->default_itf(); + my $wiz_device = $o->{var}{interface}; # patch to rewrite when got new file about dhcp with INTERFACES value # currently, I put the device to configure as dhcp server # in /etc/sysconfig/dhcpd @@ -159,25 +171,18 @@ sub do_it { #[ -f /etc/sysconfig/dhcpd ] && cp -f /etc/sysconfig/dhcpd /var/tmp/wiz_bck/orig/dhcpd my $file = "/etc/sysconfig/dhcpd"; -f $file and MDK::Common::cp_af($file, $file.".orig"); - - $file = "/etc/rc.d/init.d/dhcpd"; -# now patching etc/rc.d/init.d/dhcpd - standalone::explanations("now patching etc/rc.d/init.d/dhcpd"); + standalone::explanations("now patching etc/sysconfig/dhcpd"); if (!`grep INTERFACES $file`){ - MDK::Common::append_to_file($file, "\nINTERFACES=$wiz_device"); - MDK::Common::cp_af($file, $file . ".orig"); my $tmp = `/bin/mktemp /tmp/Dhcpconf.XXXXXX` or die "can't make a temp file: $!"; open(NEW, "> $tmp") or die "can't open $tmp: $!"; open(OLD, "< $file") or die "can't open default: $!"; while (<OLD>) { - if (m|daemon\s*/usr/sbin/dhcp|) { - print NEW "\tif [ -f /etc/sysconfig/dhcpd ]; then -\t\t. /etc/sysconfig/dhcpd -\t\tDEV=\$INTERFACES -\tfi\n"; + if (m|INTERFACE|) { + print NEW "# $_"; } print NEW $_; } + MDK::Common::append_to_file($tmp, "\n# Added by drakwizard\nINTERFACES=$wiz_device"); close(OLD); close(NEW); chomp($tmp); diff --git a/drakwizard.pl b/drakwizard.pl index 192f1e41..2e3631cb 100755 --- a/drakwizard.pl +++ b/drakwizard.pl @@ -28,7 +28,6 @@ use common; #- I18N. push @::textdomains, 'drakwizard'; -$::DEBUG = 0; $::isWizard = 1; $::Wizard_no_previous = 1; $::Wizard_title = "Drakwizard"; @@ -36,7 +35,6 @@ $::Wiz_dir = '__WIZ_HOME__'; my $in = interactive->vnew; my $standalone = 1; - my %wiz = ( apache => ['Apache', "Apache web server"], dhcp => ['Dhcp', "Dhcp server"], @@ -113,7 +111,7 @@ sub check_rpm { foreach my $rpm (@$rpms) { if (!$in->do_pkgs->is_installed($rpm)) { if ($in->ask_okcancel("error", N("%s is not installed\nClick \"Next\" to install or \"Cancel\" to quit", c::from_utf8($rpm)))) { - $::DEBUG and next; + $::testing and next; if (!$in->do_pkgs->install($rpm)) { $::Wizard_finished = 1; $in->ask_okcancel("error", N("installation failed")); diff --git a/drakwizard.spec b/drakwizard.spec index de073d15..f163a459 100644 --- a/drakwizard.spec +++ b/drakwizard.spec @@ -1,5 +1,5 @@ %define name drakwizard -%define version 2.0 +%define version 2.1 %define release 1mdk Name: %{name} @@ -51,6 +51,11 @@ rm -rf $RPM_BUILD_DIR/$RPM_PACKAGE_NAME %{perl_vendorlib}/MDK/ %changelog +* Tue Sep 02 2003 Warly <warly@mandrakesoft.com> 2.1-1mdk +- complete squid/proftpd/inn wizard +- add own images to wizards +- add boolean list handling + * Fri Aug 22 2003 Warly <warly@mandrakesoft.com> 2.0-1mdk - remove all the XML/shell part, now it is just perl - everything should be broken diff --git a/ftp_wizard/Proftpd.pm b/ftp_wizard/Proftpd.pm index 500bd5b5..fbee9a5b 100755 --- a/ftp_wizard/Proftpd.pm +++ b/ftp_wizard/Proftpd.pm @@ -27,56 +27,62 @@ require MDK::Wizard::Wizcommon; my $wiz = new MDK::Wizard::Wizcommon; my $o = { - name => 'configuration wizard', + name => 'FTP wizard', var => { - ip1 => '', - ip2 => '' - } + wiz_ftp_external => '', + wiz_ftp_anon => '', + wiz_ftp_home => '' + }, + needed_rpm => [ 'proftpd' ], + defaultimage => "$ENV{__WIZARD_HOME__}ftp_wizard/images/FTP.png" }; $o->{pages} = { welcome => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), + name => N('FTP Server Configuration Wizard') . "\n\n" . N('This wizard will help you configuring the FTP Server for your network.'), no_back => 1, - next => 'ip_range' + post => \&check, + next => 'config' }, - confige => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), + config => { + name => N('FTP Server') . "\n\n" . N('Your server can act as an FTP Server toward your internal network (intranet) and as an FTP Server for the Internet.') . "\n\n" . N('Select the kind of FTP service you want to activate:') . "\n\n" . N('Don\'t check any box if you don\'t want to activate your FTP Server.'), pre => sub { - $o->{var}{ip1} ||= f1(); - $o->{var}{ip2} ||= f2(); + $o->{var}{wiz_ftp_internal} ||= 1; + $o->{var}{wiz_ftp_external} ||= 0; }, - post => \&check, data => [ - { label => '' }, - { label => N(''), val => \$o->{var}{ip1} }, - { label => N(''), val => \$o->{var}{ip2} }, + { text => N('Enable the FTP Server for the Intranet'), type => 'bool', val => \$o->{var}{wiz_ftp_internal} }, + { text => N('Enable the FTP Server for the Internet'), type => 'bool', val => \$o->{var}{wiz_ftp_external} }, ], next => 'summary' }, - warning => { + warning_dhcp => { name => N('Warning.'), - data => [ { label => N('') } ], + data => [ { label => N('Warning\nYou are in dhcp, server may not work with your configuration.') } ], next => 'summary' }, - error => { + must_be_root => { name => N('Error.'), - data => [ { label => N('') } ], + data => [ { label => N('Sorry, you must be root to do this...') } ], next => 'config' }, summary => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), - data => [ - { label => N(''), type => 'field', val => \$o->{var}{ip1} }, - { label => '' }, - { label => N(''), type => 'field', val => \$o->{var}{ip2} }, + name => N('Configuring the FTP Server') . "\n\n" . N('The wizard collected the following parameters +needed to configure your FTP Server') . "\n\n" . N('To accept these values, and configure your server, click the Next button or use the Back button to correct them'), + pre => sub { + $o->{var}{internal} = $o->{var}{wiz_ftp_internal} ? N("enabled") : N("disabled"); + $o->{var}{external} = $o->{var}{wiz_ftp_external} ? N("enabled") : N("disabled") + }, + data => [ + { label => N('Intranet FTP Server:'), fixed_val => \$o->{var}{internal} }, + { label => N('Internet FTP Server:'), fixed_val => \$o->{var}{external} }, ], post => \&do_it, next => 'end' }, end => { name => N('Congratulation'), - data => [ { label => N('') } ], + data => [ { label => N('The wizard successfully configured your Intranet/Internet FTP Server') } ], end => 1, next => 0 }, @@ -89,4 +95,139 @@ sub new { }, $class; } +sub true { + my ($val) = @_; + + $val eq "1" || $val eq "\'1\'" || $val eq "\"1\"" || + $val eq "true" || $val eq "\'true\'" || $val eq "\"true\"" and + return 1; + 0; +} + +sub check_dir { + -d $o->{var}{wiz_dir} and return 10; + 1; +} + +sub get_dir { + my $file = "/etc/proftpd.conf"; + die "no ftp configuration file found ! warning." if (!-f $file); + open(NEW, "< $file") or die "error while opening $file: $!"; + + while (<NEW>) { # we need 3 elements to consider section as known + if (m/^\s*<drakwizard>/s...m/^\s*<\/drakwizard>/s ) { + if (m/^\s*<Anonymous\s*(.*)>/s ) { + return $1; + } + } + } + return ""; +} + +sub check { + $> and return 'must_be_root'; + $wiz->{net}->is_dhcp() and return 'warning_dhcp'; + ''; +} + +sub print_anonymous() { + print ' +#<drakwizard> +<Anonymous '.$_[0].'> + User ftp + Group ftp + UserAlias anonymous ftp + MaxClients 10 + <Limit WRITE> + DenyAll + </Limit> +</Anonymous> +#</drakwizard> +'; +} + +sub do_it { + $::testing and return; + my $wiz_ftp_internal = $o->{var}{wiz_ftp_external} ? 1 : true $o->{var}{wiz_ftp_internal}; + my $wiz_ftp_external = true $o->{var}{wiz_ftp_external}; + my $file = "/etc/proftpd.conf"; + die "no ftp configuration file found ! warning." if (!-f $file); + MDK::Common::cp_af($file, $file . ".orig"); + open(NEW, "< $file") or die "error while opening $file: $!"; + my $allow = "all"; + if ($wiz_ftp_internal && !$wiz_ftp_external) { + ($allow) = $wiz->{net}->itf_get("IPADDR") =~ qr/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)\d{1,3}$/; + $allow .= " 127.0.0.1"; + } + elsif (!$wiz_ftp_external) { + $allow = "none"; + } + my $file = "/etc/proftpd.conf"; + open (NEW, "< $file"); + my $exist = 0; + while (<NEW>) { # we need 3 elements to consider section as known + if (m/^\s*<Global>/s...m/^\s*<\/Global>/s ) { + if (m/^\s*<Limit LOGIN>/s...m/^\s*<\/Limit>/s ) { + if (/^\s*(?!\#)\s*Order .*$/) { + $exist++; + } + if (/^\s*(?!\#)\s*Allow .*$/) { + $exist++; + } + if (/^\s*(?!\#)\s*Deny .*$/) { + $exist++; + } + } + } + } + close (NEW); + if ($exist < 3) { # Odd parameters are commented if exists to then add a known section + substInFile { + if (m/^\s*<Global>/s...m/^\s*<\/Global>/s ) { + if (m/^\s*<Limit LOGIN>/s...m/^\s*<\/Limit>/s ) { + s/^\s*(?!\#)\s*Order .*$/\#$&\n/s; + s/^\s*(?!\#)\s*Allow .*$/\#$&\n/s; + s/^\s*(?!\#)\s*Deny .*$/\#$&\n/s; + } + } + } $file; + open (NEW, ">> $file"); + print NEW ' +#<drakwizard> +<Global> + <Limit LOGIN> + Order allow,deny + Allow from '.$allow.' + Deny from all + </Limit> +</Global> +#</drakwizard>'; + close NEW; + } + else { # the known section (3 parameters ) is replaced with our needs + substInFile { + if (m/^\s*<Global>/s...m/^\s*<\/Global>/s ) { + if (m/^\s*<Limit LOGIN>/s...m/^\s*<\/Limit>/s ) { + if (/^\s*(?!\#)\s*Order .*$/i) { + if (!/\s*Order\s*allow,\s*deny\s*$/) { + s//\#$&\n Order allow,deny\n/; + } + } + if (/^\s*(?!\#)\s*Allow .*$/i) { + if (!/\s*Allow\s*from\s*$allow\s*$/) { + s//\#$&\n Allow from $allow/; + } + } + if (/^\s*(?!\#)\s*Deny .*$/i) { + if (!/\s*Deny\s*from\s*all\s*$/) { + s//\#$&\n Deny from all\n/; + } + } + } + } + } $file; + } + system("/etc/rc.d/init.d/proftpd restart"); +} + 1; diff --git a/news_wizard/Inn.pm b/news_wizard/Inn.pm index 713f2041..71e33c1f 100755 --- a/news_wizard/Inn.pm +++ b/news_wizard/Inn.pm @@ -23,60 +23,76 @@ use strict; use common; require MDK::Wizard::Wizcommon; +use MDK::Wizard::Varspaceval; my $wiz = new MDK::Wizard::Wizcommon; my $o = { - name => 'configuration wizard', + name => 'News Wizard', var => { - ip1 => '', - ip2 => '' - } + wiz_news_server => '', + wiz_news_freq => '' + }, + needed_rpm => [ 'inn' ], + defaultimage => "$ENV{__WIZARD_HOME__}news_wizard/images/news.png" }; $o->{pages} = { welcome => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), + name => N('Welcome to the News Wizard') . "\n\n" . N('This wizard will help you configuring the Internet News services for your network.'), no_back => 1, - next => 'ip_range' + next => 'ask_news_server' }, - confige => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), + ask_news_server => { + name => N('News Server') . "\n\n" . N('The news server name is the name of the host providing the Internet news to your network; the name is usually provided by your provider.') . "\n\n" . N('Internet host names must be in the form \qhost.domain.domaintype\q; for example, if your provider is \qprovider.com\q, the internet news server is usually \qnews.provider.com\q.'), pre => sub { - $o->{var}{ip1} ||= f1(); - $o->{var}{ip2} ||= f2(); + $o->{var}{news_server} ||= get_server(); }, - post => \&check, data => [ - { label => '' }, - { label => N(''), val => \$o->{var}{ip1} }, - { label => N(''), val => \$o->{var}{ip2} }, + { label => N('News Server Name:'), val => \$o->{var}{news_server} }, ], + post => sub { $o->{var}{news_server} or 'error_in_news_server' }, + next => 'ask_news_freq' + }, + ask_news_freq => { + name => N('Polling Period') . "\n\n" . N('Your server will regularly poll the News Server for obtaning the latest Internet News; the polling period set the interval between two consecutive polling.') . "\n\n" . N('Depending on the kind of internet connection you have, an appropriate polling period can change between 6 and 24 hours.'), + pre => sub { + $o->{var}{news_freq} ||= 24; + }, + data => [ + { label => N('Polling Period (Hours):'), val => \$o->{var}{news_freq} }, + ], + post => \&check_valid_hours, next => 'summary' }, - warning => { + warning => { name => N('Warning.'), data => [ { label => N('') } ], next => 'summary' }, - error => { + error_in_news_server => { name => N('Error.'), - data => [ { label => N('') } ], - next => 'config' + data => [ { label => N('The news server name is not correct') } ], + next => 'ask_news_server' + }, + error_in_polling_time => { + name => N('Error.'), + data => [ { label => N('The polling period is not correct') } ], + next => 'ask_news_freq' }, summary => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), + name => N('Configuring the Internet News') . "\n\n" . N('The wizard collected the following parameters +needed to configure your Internet News Service:') . "\n\n" . N('To accept these values, and configure your server, click the Next button or use the Back button to correct them.'), data => [ - { label => N(''), type => 'field', val => \$o->{var}{ip1} }, - { label => '' }, - { label => N(''), type => 'field', val => \$o->{var}{ip2} }, + { label => N('News Server:'), fixed_val => \$o->{var}{news_server} }, + { label => N('Polling Interval:'), fixed_val => \$o->{var}{news_freq} }, ], post => \&do_it, next => 'end' }, end => { name => N('Congratulation'), - data => [ { label => N('') } ], + data => [ { label => N('The wizard successfully configured your Internet News service of your server.') } ], end => 1, next => 0 }, @@ -89,4 +105,57 @@ sub new { }, $class; } +sub check_valid_hours { + $o->{var}{news_freq} =~ /^\d+$/ or return 'error_in_polling_time' +} + +sub normalize_freq { + my ($freq) = @_; + + if ($freq =~ /(\d*)/) { + $freq = $1; + } + if ($freq <= 0) { + $freq = 0; + } + if ($freq >= 24) { + $freq = 24; + } + $freq; +} + +sub get_server { + my %mdk = MDK::Wizard::Varspaceval->get("/etc/leafnode/config"); + $mdk{server} +} + +sub normalize_server { + my ($server) = @_; + $server +} + +sub do_it { + $::testing and return; + $o->{var}{wiz_news_freq} and my $freq = normalize_freq($o->{var}{wiz_news_freq}) or + die "freq not defined: $!"; + $o->{var}{wiz_news_server} and my $server = normalize_server($o->{var}{wiz_news_server}) or + die "server not defined: $!"; + my $file = "/etc/leafnode/config"; + output($file, map { + s|__server__|$server|g; + $_; + } cat_("__WIZ_HOME__/news_wizard/scripts/config.default")); + $file = "/var/spool/cron/news"; + my $file_c = "/etc/leafnode/crontab"; + if (-f $file) { + MDK::Common::cp_af($file, $file_c); + MDK::Common::cp_af($file, $file . ".orig"); + } + output($file_c, map { + s|__freq__|$freq|g; + $_; + } cat_("__WIZ_HOME__/news_wizard/scripts/news.cron")); + system("crontab -u news /etc/leafnode/crontab"); +} + 1; diff --git a/postfix_wizard/Postfix.pm b/postfix_wizard/Postfix.pm index 7a78fb83..20fd9af7 100755 --- a/postfix_wizard/Postfix.pm +++ b/postfix_wizard/Postfix.pm @@ -35,7 +35,9 @@ my $o = { var => { wiz_mail_masquerade => '', wiz_ext_mail_relay => '' - } + }, + needed_rpm => [ 'postfix' ], + defaultimage => "$ENV{__WIZARD_HOME__}postfix_wizard/images/courrier.png" }; $o->{pages} = { @@ -51,7 +53,6 @@ $o->{pages} = { }, post => \&check_masquerade, data => [ - { label => '' }, { label => N("Mail Address:"), val => \$o->{var}{wiz_mail_masquerade} }, ], next => 'isp' @@ -60,7 +61,6 @@ $o->{pages} = { name => N("Warning:"), data => [ { label => N("You entered an empty address for the mail gateway.") }, - { label => "" }, { label => N("Your choice can be accepted, but this will not allow you to send mail outside your local network. Press next to continue, or back to enter a value.") } ], next => 'summary' @@ -77,7 +77,6 @@ $o->{pages} = { }, post => \&check_relay, data => [ - { label => '' }, { label => N("Mail Server Name:"), val => \$o->{var}{wiz_ext_mail_relay} }, ], next => 'summary' @@ -86,7 +85,6 @@ $o->{pages} = { name => N("Configuring the Internet Mail") . "\n\n" . N("The wizard collected the following parameters needed to configure your Internet Mail Service:") . "\n\n" . N("To accept these values, and configure your server, click the Next button or use the Back button to correct them."), data => [ { label => N("Internet Mail Gateway"), fixed_val => \$o->{var}{wiz_ext_mail_relay} }, - { label => '' }, { label => N("Form of the Address"), fixed_val => \$o->{var}{wiz_mail_masquerade} }, ], post => \&do_it, @@ -135,7 +133,7 @@ sub get_mail_relay { } sub do_it { - $::DEBUG and return + $::testing and return my @conf = qw(/etc/postfix/aliases /etc/postfix/canonical /etc/postfix/main.cf diff --git a/proxy_wizard/Squid.pm b/proxy_wizard/Squid.pm index 3c1d87d9..001cabf5 100755 --- a/proxy_wizard/Squid.pm +++ b/proxy_wizard/Squid.pm @@ -26,58 +26,152 @@ use common; require MDK::Wizard::Wizcommon; my $wiz = new MDK::Wizard::Wizcommon; +my $df = -d '/var/spool/squid' ? `/bin/df -m /var/spool/squid` : `/bin/df -m /var/spool`; +my ($free_disk) = $df =~ m/\d+\s+\d+\s+\d+\s+(\d+)/; +my $mem = `/usr/bin/free -m`; +($mem) = $mem =~ /Mem:\s+(\d+)/; +my %level = ( + 1 => N('All - No access restriction'), + 2 => N('Local Network - access for local network (recommended)'), + 3 => N('Localhost - access restricted to this server only') +); +my %upper = ( + 1 => N('No upper level proxy (recommended)'), + 2 => N('Define an upper level proxy') +); my $o = { - name => 'configuration wizard', + name => 'Squid wizard', var => { - ip1 => '', - ip2 => '' - } + wiz_squid_level => '', + wiz_squid_mem => '', + wiz_squid_port => '', + wiz_squid_mynetw => '', + wiz_squid_defdir => '', + wiz_squid_cachepeer => '', + wiz_squid_peerport => '', + wiz_squid_menupeer => '', + wiz_squid_disk => '' + }, + needed_rpm => [ 'squid' ], + defaultimage => "$ENV{__WIZARD_HOME__}proxy_wizard/images/proxy.png" }; $o->{pages} = { welcome => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), + name => N('Proxy Configuration Wizard') . "\n\n" . N('Squid is a web caching proxy server, it allows faster web access for your local network.') . "\n\n" . N('This wizard will help you in configuring your proxy server.'), no_back => 1, - next => 'ip_range' + next => 'port' }, - confige => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), + port => { + name => N('Proxy Port') . "\n\n" . N('Proxy port value sets what port the proxy server will listen on for http requests. Default is 3128, other common value can be 8080, the port value needs to be greater than 1024.') . "\n\n" . N(''), pre => sub { - $o->{var}{ip1} ||= f1(); - $o->{var}{ip2} ||= f2(); + $o->{var}{wiz_squid_port} ||= 3128; }, - post => \&check, + post => \&testport, data => [ - { label => '' }, - { label => N(''), val => \$o->{var}{ip1} }, - { label => N(''), val => \$o->{var}{ip2} }, + { label => N('Proxy port:'), val => \$o->{var}{wiz_squid_port} }, ], - next => 'summary' + next => 'memory' + }, + warning_port => { + name => N('Warning.') . "\n\n" . N('You have entered a port that may be useful for this service:') . "\n\n" . N('Press Next if you want to keep this value, or Back to correct your choice.'), + data => [ + { label => '/etc/services:', fixed_val => \$o->{var}{used_by} }, + ], + next => 'memory' }, - warning => { + error_low => { name => N('Warning.'), - data => [ { label => N('') } ], - next => 'summary' + data => [ + { label => N('You must choose a port greater than 1024 and lower than 65535') }, + { label => N('Press back to change the value.') } + ], + next => 'memory' + }, + memory => { + name => N('Proxy Cache Size') . "\n\n" . N('Memory Cache is the amount of RAM dedicated to cache memory operations (note that actual memory usage of the whole squid process is bigger).') . "\n\n" . N('Disk Cache is the amount of disk space that can be used for caching on disk.') . "\n\n" . N('For your information, here is /var/spool/squid space on disk:') . "\n\n" . $df, + pre => sub { + $o->{var}{wiz_squid_mem} ||= int ($mem / 4); + $o->{var}{wiz_squid_disk} ||= int ($free_disk/2); + }, + data => [ + { label => N('Memory cache (MB):'), val => \$o->{var}{wiz_squid_mem} }, + { label => N('Disk space (MB):'), val => \$o->{var}{wiz_squid_disk} }, + ], + next => 'level' + }, + level => { + name => N('Access Control') . "\n\n" . N('The proxy can be configured to use different access control levels') . "\n\n" . N('Choose the level that suits your needs. If you don\'t know, the Local Network level is usually the most appropriate. Beware that the All level may be not secure.'), + pre => sub { + $o->{var}{wiz_squid_level} ||= 2; + }, + data => [ + { label => '', val => \$o->{var}{wiz_squid_level}, list => [ keys %level ], format => sub { $level{$_[0]} } }, + ], + post => sub { + return 'shownet' if $o->{var}{wiz_squid_level} == 2 + }, + next => 'cachepeer' + }, + shownet => { + name => N('Grant access on local network') . "\n\n" . N('Access will be allowed for hosts on the network. Here is the information found about your current local network, you can modify it if needed.') . "\n\n" . N('You can use either a numeric format like \q192.168.1.0/255.255.255.0\q or a text format like \q.domain.net\q'), + pre => sub { + $o->{var}{wiz_squid_mynetw} ||= network_mask() + }, + data => [ + { label => 'Authorized network:', val => \$o->{var}{wiz_squid_mynetw}, help => N('Use numeric format like \q192.168.1.0/255.255.255.0\q or a text format like \q.domain.net\q') }, + ], + next => 'cachepeer' + }, + cachepeer => { + name => N('Cache hierarchy') . "\n\n" . N('As an option, Squid can be configured in proxy cascading. You can add a new upper level proxy by specifying its hostname and port.') . "\n\n" . N('You can safely select \qNo upper level proxy\q if you don\'t need this feature.'), + pre => sub { + $o->{var}{wiz_squid_menupeer} ||= 1 + }, + data => [ + { label => '', val => \$o->{var}{wiz_squid_menupeer}, list => [ keys %upper ], format => sub { $upper{$_[0]} } }, + ], + post => sub { + return 'valcachepeer' if $o->{var}{wiz_squid_menupeer} == 2 + }, + next => 'summary_2' }, - error => { - name => N('Error.'), - data => [ { label => N('') } ], - next => 'config' + valcachepeer => { + name => N('Cache hierarchy') . "\n\n" . N('Enter the qualified hostname (like \qcache.domain.net\q) and the port of the proxy to use.'), + data => [ + { label => 'Upper level proxy hostname:', val => \$o->{var}{wiz_squid_cachepeer} }, + { label => 'Upper level proxy port:', val => \$o->{var}{wiz_squid_peerport} }, + ], + next => 'summary' }, summary => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), + name => N('Configuring the Proxy') . "\n\n" . N('The wizard collected the following parameters needed to configure your proxy:') . "\n\n" . N('To accept these values, and configure your server, click the Next button or use the Back button to correct them.'), data => [ - { label => N(''), type => 'field', val => \$o->{var}{ip1} }, - { label => '' }, - { label => N(''), type => 'field', val => \$o->{var}{ip2} }, + { label => N('Port:'), type => 'field', val => \$o->{var}{wiz_squid_port} }, + { label => N('Memory cache (MB):'), type => 'field', val => \$o->{var}{wiz_squid_mem} }, + { label => N('Disk space (MB):'), type => 'field', val => \$o->{var}{wiz_squid_disk} }, + { label => N('Access Control:'), type => 'field', val => \$o->{var}{wiz_squid_mynetw} }, + { label => N('Upper level proxy hostname:'), type => 'field', val => \$o->{var}{wiz_squid_cachepeer} }, + { label => N('Upper level proxy port:'), type => 'field', val => \$o->{var}{wiz_squid_peerport} }, + ], + post => \&do_it, + next => 'end' + }, + summary_2 => { + name => N('Configuring the Proxy') . "\n\n" . N('The wizard collected the following parameters needed to configure your proxy:') . "\n\n" . N('To accept these values, and configure your server, click the Next button or use the Back button to correct them.'), + data => [ + { label => N('Port:'), type => 'field', val => \$o->{var}{wiz_squid_port} }, + { label => N('Memory cache (MB):'), type => 'field', val => \$o->{var}{wiz_squid_mem} }, + { label => N('Disk space (MB):'), type => 'field', val => \$o->{var}{wiz_squid_disk} }, + { label => N('Access Control:'), type => 'field', val => \$o->{var}{wiz_squid_mynetw} }, ], post => \&do_it, next => 'end' }, end => { name => N('Congratulation'), - data => [ { label => N('') } ], + data => [ { label => N('The wizard successfully configured your proxy server.') } ], end => 1, next => 0 }, @@ -90,4 +184,96 @@ sub new { }, $class; } +sub network_mask { + my $o = IFCFG->new(); + my $wiz_ip_server = $wiz->{net}->itf_get("IPADDR"); + my $mask = $wiz->{net}->itf_get("NETMASK"); + "$1.$2.$3.0/$mask" if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/; +} + +sub testport { + if ($o->{var}{wiz_squid_port} == 3128 || $o->{var}{wiz_squid_port} == 8080) { + return '' + } + elsif ($o->{var}{wiz_squid_port} <= 1024 || $o->{var}{wiz_squid_port} >= 65536) { + return 'error_low'; + } + $o->{var}{used_by} = `/bin/grep $o->{var}{wiz_squid_port} /etc/services`; + if ($o->{var}{used_by}) { + return 'warning_port' + } +} + +sub port { + my $ret; + my @lines = grep(/$o->{var}{wiz_squid_port}\/tcp/, cat_("/etc/services")); + foreach (@lines) { + s/\t/ /g; + $ret .= "\n$_"; + } + $ret; +} + +sub do_it { + $::testing and return; + my $file="/etc/squid/squid.conf"; + -f $file and MDK::Common::cp_af($file, $file.".orig"); + MDK::Common::cp_af("__WIZ_HOME__/proxy_wizard/scripts/squid.conf.default", $file); + substInFile { + s|^\s*\#?\s*(cache_dir.*$o->{var}{wiz_squid_defdir}\s*)\d*(.*)|$1$o->{var}{wiz_squid_disk}$2|; + s|^\s*\#?\s*(acl\s*mynetwork\s*src\s*).*$|$1$o->{var}{wiz_squid_mynetw}\n|; + s|^\s*\#?\s*(cache_mem\s*)\d*(\s*MB.*)|$1$o->{var}{wiz_squid_mem}$2|; + s|^\s*\#?\s*(http_port\s*)\d*(.*)|$1$o->{var}{wiz_squid_port}$2|; + } $file; + print "LEVEL $o->{var}{'wiz_squid_level'}\n\n"; + exit; + standalone::explanations("$file: cache_dir = $o->{var}{wiz_squid_defdir} $o->{var}{wiz_squid_disk} +mynetw = $o->{var}{wiz_squid_mynetw} cache_mem = $o->{var}{wiz_squid_mem} http_port = $o->{var}{wiz_squid_port} +level = $o->{var}{wiz_squid_level}"); + if ($o->{var}{wiz_squid_level} == 1) { + substInFile { + s|^\s*\#?\s*(http_access\s*)deny(\s*all.*)|\#$&\n$1allow$2|; + } $file; + } + elsif ($o->{var}{wiz_squid_level} == 2) { + substInFile { + s|^\s*\#?\s*(http_access\s*)allow(\s*all.*)|\#$&\n$1deny$2|; + s|^\s*\#?\s*(http_access\s*allow\s*)localhost|\#$&\n$1mynetwork|; + } $file; + } + elsif ($o->{var}{wiz_squid_level} == 3) { + substInFile { + s|^\s*\#?\s*(http_access\s*)allow(\s*all.*)|\#$&\n$1deny$2|; + s|^\s*\#?\s*(http_access\s*allow\s*)mynetwork|\#$&\n$1localhost|; + } $file; + } else { # should not happen + die "wiz_squid_level error"; + } + my $t = 0; + foreach (cat_($file)) { + if (/^\s*cache_peer.*/) { + $t = $_;; + last; + } + } + if ($o->{var}{wiz_squid_menupeer} == 1 && length $t) { + substInFile { + s|^\s*!\#\s*(cache_peer.*)|\#$&|; + } $file; + } + elsif ($o->{var}{wiz_squid_menupeer} == 2 && length $o->{var}{wiz_squid_cachepeer}) { + if (lenght $t) { + substInFile { + s|^\s*\#?\s*(cache_peer.*)|\#$&|; + } $file; + } + append_to_file($file, "cache_peer $o->{var}{wiz_squid_cachepeer} parent $o->{var}{wiz_squid_peerport} 3130"); + } + system("/sbin/chkconfig --level 345 squid on"); + if (services::is_service_running('squid')) { + services::restart('squid') + } else { + services::start('squid') + } +} 1; diff --git a/samba_wizard/Samba.pm b/samba_wizard/Samba.pm index a72578e0..f310fcb2 100755 --- a/samba_wizard/Samba.pm +++ b/samba_wizard/Samba.pm @@ -28,59 +28,203 @@ use MDK::Wizard::Wizcommon; my $wiz = new MDK::Wizard::Wizcommon; my $o = { - name => 'configuration wizard', + name => 'Samba wizard', var => { - ip1 => '', - ip2 => '' - } + wiz_box_list => '', + wiz_hosts_allow => '', + wiz_do_file_sharing => '', + wiz_all_printers => '', + wiz_level => '', + wiz_printers => '', + wiz_do_printer_sharing => '', + wiz_do_homes => '', + wiz_workgroup => '', + wiz_dir => '', + wiz_banner => '', + wiz_write_list => '', + wiz_read_list => '', + wiz_hosts_deny => '', + list_printers => '' + }, + needed_rpm => [ 'samba-server' ], + defaultimage => "$ENV{__WIZ_HOME__}samba_wizard/images/samba.png" }; +my $old = read_conf("/etc/samba/smb.conf"); + +my %level = ( + 1 => N('All - No access restriction'), + 2 => N('My rules - Ask me allowed and denied hosts') +); + $o->{pages} = { - welcome => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), - no_back => 1, - next => 'ip_range' - }, - confige => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), - pre => sub { - $o->{var}{ip1} ||= f1(); - $o->{var}{ip2} ||= f2(); - }, - post => \&check, - data => [ - { label => '' }, - { label => N(''), val => \$o->{var}{ip1} }, - { label => N(''), val => \$o->{var}{ip2} }, - ], - next => 'summary' - }, - warning => { - name => N('Warning.'), - data => [ { label => N('') } ], - next => 'summary' - }, - error => { - name => N('Error.'), - data => [ { label => N('') } ], - next => 'config' - }, - summary => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), - data => [ - { label => N(''), type => 'field', val => \$o->{var}{ip1} }, - { label => '' }, - { label => N(''), type => 'field', val => \$o->{var}{ip2} }, - ], - post => \&do_it, - next => 'end' - }, - end => { - name => N('Congratulation'), - data => [ { label => N('') } ], - end => 1, - next => 0 - }, + welcome => { + name => N('Samba Configuration Wizard') . "\n\n" . N('Samba allows your server to behave as a file and print server for workstations running non-Linux systems.') . "\n\n" . N('This wizard will help you configuring the Samba services of your server.'), + no_back => 1, + next => 'ask_workgroup' + }, + ask_workgroup => { + name => N('Workgroup') . "\n\n" . N('Samba needs to know the Windows Workgroup it will serve.') . "\n\n" . N('Samba needs to know the Windows Workgroup it will serve.'), + pre => sub { + $o->{var}{wiz_workgroup} ||= get_workgroup() + }, + data => [ + { label => N('Workgroup:'), val => \$o->{var}{wiz_workgroup} }, + ], + post => \&check_workgroup, + next => 'ask_banner' + }, + error_in_workgroup => { + name => N('Error.'), + data => [ + { label => N('The Workgroup is wrong') }, + ], + post => \&check_workgroup, + next => 'ask_workgroup' + }, + ask_banner => { + name => N('Server Banner.') . "\n\n" . N('The banner is the way this server will be described in the Windows workstations.') . "\n\n" . N('The banner is the way this server will be described in the Windows workstations.'), + pre => sub { + $o->{var}{wiz_banner} ||= get_banner() + }, + post => \&check_banner, + data => [ + { label => N('Banner:'), val => \$o->{var}{wiz_banner} }, + ], + next => 'ask_net' + }, + error_in_banner => { + name => N('Error.'), + data => [ + { label => N('The Server Banner is incorrect') }, + ], + next => 'ask_banner' + }, + ask_net => { + name => N('Access control') . "\n\n" . N('') . "\n\n" . N(''), + pre => sub { + $o->{var}{wiz_level} ||= 1 + }, + post => sub { return 'ask_netmask' if $o->{var}{wiz_level} == 2 }, + data => [ + { label => N('Access level :'), val => \$o->{var}{wiz_level}, list => [ keys %level ], format => sub { $level{$_[0]} } }, + ], + next => 'ask_services' + }, + ask_netmask => { + name => N('Access control') . "\n\n" . N('* Example 1: allow all IPs in 150.203.*.*; except one\nhosts allow = 150.203. EXCEPT 150.203.6.66') . "\n\n" . N('* Example 2: allow hosts that match the given network/netmask\nhosts allow = 150.203.15.0/255.255.255.0') . "\n\n" . N('* Example 3: allow a couple of hosts\nhosts allow = lapland, arvidsjaur') . "\n\n" . N('* Example 4: allow only hosts in NIS netgroup \qfoonet\q, but deny access from one particular host\nhosts allow = @foonet\nhosts deny = pirate') . "\n\n" . N('Note that access still requires suitable user-level passwords.'), + pre => sub { + $o->{var}{wiz_hosts_allow} ||= get_allow_host(); + $o->{var}{wiz_hosts_allow} ||= get_deny_host() + }, + post => \&check, + data => [ + { label => N('Allow hosts:'), val => \$o->{var}{wiz_allow_host} }, + { label => N('Deny hosts:'), val => \$o->{var}{wiz_deny_host} }, + ], + next => 'ask_services' + }, + ask_services => { + name => N('Enabled Samba Services') . "\n\n" . N('Samba can provide a common file sharing area to your Windows workstation, and can also provide printer sharing for the printers connected to your server.'), + pre => sub { + $o->{var}{wiz_do_file_sharing} ||= get_file_sharing(); + $o->{var}{wiz_do_printer_sharing} ||= 1; + $o->{var}{wiz_do_homes} ||= get_home_sharing() + }, + post => \&check_services, + data => [ + { text => N('Enable file sharing area'), type => 'bool', val => \$o->{var}{wiz_do_file_sharing} }, + { text => N('Enable Server Printer Sharing'), type => 'bool', val => \$o->{var}{wiz_do_printer_sharing} }, + { text => N('Make home directories available for their owners'), type => 'bool', val => \$o->{var}{wiz_do_homes} }, + ], + next => 'ask_dir' + }, + warn_smbpasswd => { + name => N('Warning.') . "\n\n" . N('You have selected to allow user access their home directories via samba but you/they must use smbpasswd to set a password.'), + post => \&ask_dir, + next => 'summary' + }, + ask_dir => { + name => N('Shared directory:') . "\n\n" . N('Type the path of the directory you want being shared.'), + pre => sub { + $o->{var}{wiz_dir} ||= get_dir() + }, + post => \&check_dir, + data => [ + { label => N('Shared directory:'), val => \$o->{var}{wiz_dir} }, + ], + next => 'ask_access' + }, + error_in_dir => { + name => N('Error.'), + data => [ + { label => N('The path you entered does not exist.') }, + ], + next => 'ask_dir' + }, + ask_access => { + name => N('File permissions') . "\n\n" . N('Type users or group separated by a comma (groups must be preceded by a \'@\') like this :\nroot, fred, @users, @wheel for each kind of permission.') . "\n\n" . N(''), + pre => sub { + $o->{var}{wiz_read_list} ||= get_read(); + $o->{var}{wiz_write_list} ||= get_write() + }, + post => \&check_users, + data => [ + { label => N('read list:'), help => N('root, fred, @users, @wheel'), val => \$o->{var}{wiz_read_list} }, + { label => N('write list:'), help => N('root, fred, @users, @wheel'), val => \$o->{var}{wiz_write_list} }, + ], + next => 'ask_printers' + }, + ask_printers => { + name => N('Select which printers you want to be accessible from known users'), + pre => sub { + $o->{var}{list_printers} ||= [ list_printers() ]; + $o->{var}{wiz_box_list} ||= [] + }, + post => \&check, + data => [ + { text => N('Enable all printers'), type => 'bool', val => \$o->{var}{wiz_all_printers} }, + { val => \$o->{var}{wiz_box_list}, boolean_list => \$o->{var}{list_printers}, disabled => sub { $o->{var}{wiz_all_printers} and return 1; 0 } }, + ], + next => 'summary' + }, + warning => { + name => N('Warning.'), + data => [ { label => N('') } ], + next => 'summary' + }, + error => { + name => N('Error.'), + data => [ { label => N('') } ], + next => 'config' + }, + summary => { + name => N('Configuring Samba') . "\n\n" . N('The wizard collected the following parameters +configure Samba.') . "\n\n" . N('To accept these values, and configure your server, click the Next button or use the Back button to correct them.'), + pre => sub { + $o->{var}{printers} = get_printers(); + $o->{var}{file_sharing} = $o->{var}{wiz_do_file_sharing} ? N("enabled") : N("disabled"); + $o->{var}{printer_sharing} = $o->{var}{wiz_do_printer_sharing} ? N("enabled") : N("disabled"); + $o->{var}{shared_homes} = $o->{var}{wiz_do_homes} ? N("enabled") : N("disabled") + }, + data => [ + { label => N('Workgroup:'), fixed_val => \$o->{var}{wiz_workgroup} }, + { label => N('Server Banner:'), fixed_val => \$o->{var}{wiz_banner} }, + { label => N('File Sharing:'), fixed_val => \$o->{var}{file_sharing} }, + { label => N('Shared directory:'), fixed_val => \$o->{var}{wiz_dir} }, + { label => N('Print Server:'), fixed_val => \$o->{var}{printer_sharing} }, + { label => N('Home:'), fixed_val => \$o->{var}{shared_homes} }, + { label => N('Printers:'), fixed_val => \$o->{var}{printers} }, + ], + post => \&do_it, + next => 'end' + }, + end => { + name => N('Congratulation'), + data => [ { label => N('The wizard successfully configured your Samba server.') } ], + end => 1, + next => 0 + }, }; sub new { @@ -90,4 +234,279 @@ sub new { }, $class; } +sub check { + $> and return 1; + $o->is_dhcp() and return 2; + 0; +} + +sub check_services { + $o->{var}{wiz_do_homes} and return 'warn_smbpasswd'; + $o->{var}{wiz_do_file_sharing} and return 'ask_dir'; + $o->{var}{wiz_do_printer_sharing} and return 'ask_printers'; +} + +sub check_dir { + -d ($o->{var}{wiz_dir}) or return 'error_in_dir' +} + +# 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) = @_; + my $menu; + my @tab; + my %conf; + + open(FH, $file) or die "$! ($file)"; + 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, $_; + } + $self->{conf} = \%conf; + $self->{tab} = \@tab; + bless $self; +} + +# we parse @tab to check for values in the struct. + +sub write_conf { + my $self = shift; + my ($file) = @_; + my $menu; + + open(FH, "> $file") or die "$!"; + foreach (@{$self->{tab}}) { + if (/^\s*\;?\s*\[(.*)\].*/) { + $menu = $1; + print FH "$self->{conf}->{$menu}{__comment}"."[$menu]\n"; + } + elsif (/^(?!\#)\s*\;*\s*(.*?)\s*=/) { + print FH "$self->{conf}->{$menu}{$1}{comment}"."$1" ." = ". "$self->{conf}->{$menu}{$1}{value}\n"; + } + else { + print FH $_; + } + } +} + +#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 = $printer\n"; + push @{$self->{tab}}, "printable = yes\n"; + $self->{conf}->{$printer}{printer}{value} = $printer; + $self->{conf}->{$printer}{printable}{value} = "yes"; + } +} + +sub list_printers { + my @list if 0; + + return @list if @list; + @list = sort grep /^(?!\#).*/, map { + my ($printer) = split(':', $_); + } cat_("/etc/printcap"); + @list +} + + +sub check_users { + return 'ask_printers' if $o->{var}{wiz_do_printer_sharing} +} + +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; + $self->{conf}->{$menu}{$_}{comment} = $str; + } +} + +sub comment_var { + my $self = shift; + my ($menu, $var, $str) = @_; + + $self->{conf}->{$menu}{$var}{comment} = $str; +} + +sub chg_var { + my $self = shift; + my ($menu, $var, $str) = @_; + + $self->{conf}->{$menu}{$var}{value} = $str; +} + +# all or selected printers +sub printer_sharing { + my $self = shift; + + if ($o->{var}{wiz_all_printers}) { + $self->comment_menu("printers", " "); + foreach my $printer (keys (%::bool)) { + $self->comment_menu($printer, ";"); + } + } + else { + $self->comment_menu("printers", ";"); + foreach my $printer (keys (%::bool)) { + if (int($::bool{$printer})) { + $self->comment_menu($printer, " "); + $self->add_printer($printer); + } + else { + $self->comment_menu($printer, ";"); + } + } + } +} + +sub get_printers { + if ($o->{var}{wiz_do_printer_sharing}) { + my $string; + $o->{var}{wiz_all_printers} and return "all printers"; + for (my $i; $i < @{$o->{var}{wiz_box_list}}; $i++) { + $string .= "$o->{var}{list_printers}[$i]\n" if $o->{var}{wiz_box_list}[$i] + } + "$string"; + } + else { + "disabled"; + } +} + +sub check_workgroup { + $o->{var}{wiz_workgroup} or return 'error_in_workgroup' +} + +sub ask_acces { + 10; +} + +sub get_write { + $old->{conf}->{public}{"write list"}{value}; +} + +sub get_read { + $old->{conf}->{public}{"read list"}{value}; +} + +sub check_banner { + $o->{var}{wiz_banner} or return 'error_in_banner' +} + +sub get_workgroup { + $old->{conf}->{global}{workgroup}{value} +} + +sub get_banner { + $old->{conf}->{global}{"server string"}{value}; +} + +sub ask_dir { + return 'ask_dir' if $o->{var}{wiz_do_file_sharing}; + return 'ask_printers' if $o->{var}{wiz_do_printer_sharing}; +} + +sub get_dir { + $old->{conf}->{public}{path}{value}; +} + +sub get_file_sharing { + return 0 if ($old->{conf}->{public}{__comment} =~ /\;|\#/); + 1; +} + +sub get_home_sharing { + return 0 if ($old->{conf}->{homes}{__comment} =~ /\;|\#/); + 1; +} + +sub get_netmask { + "192.168.100.1/255.255.255.0"; +} + +sub get_allow_host { + $old->{conf}->{global}{"hosts allow"}{value}; +} + +sub get_deny_host { + $old->{conf}->{global}{"hosts deny"}{value}; +} + +# remember one variable cannot be commented and not in the same file. +sub do_it { + $::testing and return; + my $file = "__WIZ_HOME__/samba_wizard/scripts/smb.conf.default"; + + my $conf = read_conf($file); + $conf->chg_var("global", "workgroup", $o->{var}{wiz_workgroup}); + $conf->chg_var("global", "server string", $o->{var}{wiz_banner}); + $conf->chg_var("public", "write list", $o->{var}{wiz_write_list}) if $o->{var}{wiz_do_file_sharing}; + $conf->chg_var("public", "read list", $o->{var}{wiz_read_list}) if $o->{var}{wiz_do_file_sharing}; + my $ip = $o->itf_get("IPADDR"); + if ($o->{var}{wiz_do_file_sharing}) { + standalone->explanations("Enabling $o->{var}{wiz_dir} samba file sharing"); + $conf->comment_menu("public", " "); + $conf->chg_var("public", "path", $o->{var}{wiz_dir}); + } + else { + standalone->explanations("Disabling samba file sharing"); + $conf->comment_menu("public", ";"); + } + if ($o->{var}{wiz_do_homes}) { + standalone->explanations("Enabling samba homes sharing"); + $conf->comment_menu("homes", " "); + } + else { + standalone->explanations("Disabling samba homes sharing"); + $conf->comment_menu("homes", ";"); + } + standalone->explanations("Samba deny $o->{var}{wiz_hosts_deny}"); + standalone->explanations("Samba allow $o->{var}{wiz_hosts_allow}"); +# $conf->chg_var("global", "hosts deny", $o->{var}{wiz_hosts_deny}); +# $conf->chg_var("global", "hosts allow", $o->{var}{wiz_hosts_allow}); + + if ($o->{var}{wiz_do_printer_sharing}) { + standalone->explanations("Enabling printer sharing"); + $conf->printer_sharing(); + } + else { + standalone->explanations("Disabling printer sharing"); + foreach my $printer (keys (%::bool)) { + if (!int($::bool{$printer})) { + $conf->comment_menu("$printer", ";"); + } + } + $conf->comment_menu("printers", ";"); + } + $conf->write_conf("/etc/samba/smb.conf"); + if (services::is_service_running('smb')) { + services::restart('smb') + } else { + services::start('smb') + } +} 1; diff --git a/web_wizard/Apache.pm b/web_wizard/Apache.pm index 55a19bbe..91095ea2 100755 --- a/web_wizard/Apache.pm +++ b/web_wizard/Apache.pm @@ -41,7 +41,8 @@ my $o = { user_dir => '', shared_dir => '' }, - needed_rpm => [ ( $config->{ver} == 2 ? 'apache2' : 'apache') ] + needed_rpm => [ ( $config->{ver} == 2 ? 'apache2' : 'apache') ], + defaultimage => "$ENV{__WIZARD_HOME__}web_wizard/images/apache.png" }; $o->{pages} = { @@ -54,7 +55,6 @@ $o->{pages} = { config => { name => N('Web Server') . "\n\n" . N('Your server can act as a Web Server toward your internal network (intranet) and as a Web Server for the Internet.') . "\n\n" . N('Select the kind of Web service you want to activate:') . "\n\n" . N('Don\'t check any box if you don\'t want to activate your Web Server.'), data => [ - { label => '' }, { text => N('Enable the Web Server for the Intranet'), type => 'bool', val => \$o->{var}{web_internal} }, { text => N('Enable the Web Server for the Internet'), type => 'bool', val => \$o->{var}{web_external} }, ], @@ -69,7 +69,6 @@ $o->{pages} = { name => N('Modules :') . "\n\n" . N('* User module : allows users to have a directory in their home directories available on your http server via http://www.yourserver.com/~user, you will be asked for the name of this directory afterward.'), pre => sub { $o->{var}{user_mod} = is_last_user_mod()}, data => [ - { label => '' }, { text => N('Allows users to get a directory in their homes directories available on your http server via http://www.yourserver.com/~user.'), type => 'bool', val => \$o->{var}{user_mod} }, ], @@ -80,7 +79,6 @@ available on your http server via http://www.yourserver.com/~user.'), type => 'b name => N('Type the name of the directory users should create in their homes (whitout ~/) to get it available via http://www.yourserver.com/~user'), pre => sub { $o->{var}{user_dir} ||= 'public_html' }, data => [ - { label => '' }, { label => N('user http sub-directory : ~/'), help => N('Type the name of the directory users should create in their homes (whitout ~/) to get it available via http://www.yourserver.com/~user'), val => \$o->{var}{user_dir} }, ], next => 'ask_dir' @@ -89,7 +87,6 @@ available on your http server via http://www.yourserver.com/~user.'), type => 'b name => N('Type the path of the directory you want being the document root.'), pre => sub { $o->{var}{shared_dir} ||= $root }, data => [ - { label => '' }, { label => N('Document Root:'), val => \$o->{var}{shared_dir} }, ], post => \&check_dir, @@ -97,8 +94,9 @@ available on your http server via http://www.yourserver.com/~user.'), type => 'b }, error_in_dir => { name => N('Error.'), - data => [ { label => '' }, - { label => N('The path you entered does not exist.') } ], + data => [ + { label => N('The path you entered does not exist.') } + ], next => 'ask_dir' }, error => { @@ -114,11 +112,8 @@ available on your http server via http://www.yourserver.com/~user.'), type => 'b }, data => [ { label => N('Intranet web server:'), fixed_val => \$o->{var}{internal} }, - { label => '' }, { label => N('Internet web server:'), fixed_val => \$o->{var}{external} }, - { label => '' }, { label => N('Document root:'), fixed_val => \$o->{var}{shared_dir} }, - { label => '' }, { label => N('User directory:'), fixed_val => \$o->{var}{user_dir} }, ], post => \&do_it, @@ -127,7 +122,6 @@ available on your http server via http://www.yourserver.com/~user.'), type => 'b end => { name => N('Congratulation'), data => [ - { label => '' }, { label => N('The wizard successfully configured your Intranet/Internet Web Server') } ], end => 1, next => 0 @@ -144,7 +138,6 @@ sub new { if (/^\s*\#?\s*DocumentRoot\s+(.*)/) { close($FH); $root = $1; - print "ROOT $root\n"; last; } } @@ -191,7 +184,7 @@ sub is_last_user_mod { } sub get_user_dir { - my %conf = Varspaceval->get("/etc/httpd/conf/commonhttpd.conf"); + my %conf = MDK::Wizard::Varspaceval->get("/etc/httpd/conf/commonhttpd.conf"); $conf{UserDir}; } @@ -214,7 +207,7 @@ sub chg_user_dir { } sub do_it { - $::DEBUG and return; + $::testing and return; my $file = "/etc/httpd/conf/commonhttpd.conf"; my $that = "localhost"; |