From 150bc87396011253a541ca0ad32250e926ab0ecc Mon Sep 17 00:00:00 2001 From: Florent Villard Date: Fri, 22 Aug 2003 19:59:48 +0000 Subject: switch to perl only --- web_wizard/Apache.pm | 242 ++++++++++++++++++++++++++++++++++++++ web_wizard/scripts/Apache2conf.pm | 1 + 2 files changed, 243 insertions(+) create mode 100755 web_wizard/Apache.pm (limited to 'web_wizard') diff --git a/web_wizard/Apache.pm b/web_wizard/Apache.pm new file mode 100755 index 00000000..2585211b --- /dev/null +++ b/web_wizard/Apache.pm @@ -0,0 +1,242 @@ +#!/usr/bin/perl + +# Drakwizard + +# Copyright (C) 2002 Arnaud Desmons +# 2003 Florent Villard +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +package Apache; +use lib qw(/usr/lib/libDrakX); +use strict; + +use standalone; +use interactive; +use common; +use MDK::Wizard::Wizcommon; +use MDK::Wizard::Varspaceval; + +my $wiz = new Wizcommon; + +my $file; +my $root; + +my $config; +my $o = { + name => N('Web wizard'), + var => { + web_internal => '', + web_external => '', + user_mod => '', + user_dir => '', + shared_dir => '' + }, + needed_rpm => [ ( $config->{ver} == 2 ? 'apache2' : 'apache') ] +}; + +$o->{pages} = { + welcome => { + name => N('Web Server Configuration Wizard') . "\n\n" . N('This wizard will help you configuring the Web Server for your network.'), + post => sub { $wiz->check_dhcp }, + no_back => 1, + next => 'config' + }, + 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} }, + ], + next => 'ask_mod' + }, + dhcp_warning => { + name => N('Warning.'), + data => [ { label => N('You are in dhcp, server may not work with your configuration.') } ], + next => 'summary' + }, + ask_mod => { + 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} }, + ], + post => sub { return 'user_dir' if $o->{var}{user_mod} }, + next => 'ask_dir' + }, + user_dir => { + 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' + }, + ask_dir => { + 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, + next => 'summary' + }, + error_in_dir => { + name => N('Error.'), + data => [ { label => '' }, + { label => N('The path you entered does not exist.') } ], + next => 'ask_dir' + }, + error => { + name => N('Error.'), + data => [ { label => N('') } ], + next => 'config' + }, + summary => { + name => N('Configuring the Web Server') . "\n\n" . N('The wizard collected the following parameters needed to configure your Web 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}{web_internal} ? N("enabled") : N("disabled"); + $o->{var}{external} = $o->{var}{web_external} ? N("enabled") : N("disabled") + }, + 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, + next => 'end' + }, + end => { + name => N('Congratulation'), + data => [ + { label => '' }, + { label => N('The wizard successfully configured your Intranet/Internet Web Server') } ], + end => 1, + next => 0 + }, +}; + +sub new { + my ($class, $conf) = @_; + $config = $conf; + $file = $config->{ver} == 2 ? "/etc/httpd/conf/httpd2.conf" : "/etc/httpd/conf/httpd.conf"; + if (-f $file) { + open my $FH, $file or die "$! ($file)"; + while (<$FH>) { + if (/^\s*\#?\s*DocumentRoot\s+(.*)/) { + close($FH); + $root = $1; + print "ROOT $root\n"; + last; + } + } + close($FH); + } else { + return (0, N("%s does not exist.", $file)) + } + bless { + o => $o, + }, $class; +} + +sub check_dir { + -d $o->{var}{shared_dir} or return 'error_in_dir' +} + +sub chg_docroot { + my $old; + substInFile { + s|(^\s*\#?\s*DocumentRoot\s*)(\S*).*|$1$o->{var}{shared_dir}| and $old ||=$2; + } $file; + + substInFile { + s|^\s*|{var}{shared_dir}>|; + } "/etc/httpd/conf/commonhttpd.conf" if $old; + + substInFile { + s|^\s*|{var}{shared_dir}>|; + } "/etc/httpd/conf/commonhttpd.conf"; +} + +sub is_user_mod { + if ($o->{var}{user_mod}) { + return 1; + } + $o->{var}{user_mod} = "disabled"; + 0; +} + +sub is_last_user_mod { + my $root = get_user_dir(); + chomp($root); + !($root eq 'disabled'); +} + +sub get_user_dir { + my %conf = Varspaceval->get("/etc/httpd/conf/commonhttpd.conf"); + $conf{UserDir}; +} + +sub chg_user_dir { + my $root = get_user_dir(); + if ($o->{var}{user_mod}) { + substInFile { + s|(/home/\*/)$root(/?)|$1$o->{var}{user_dir}$2|g; + } "/etc/httpd/conf/commonhttpd.conf"; + substInFile { + s|(\s*)UserDir\s*$root(/?)|$1UserDir $o->{var}{user_dir}$2|g; + s|(/home/\*/)$root(/?)|$1$o->{var}{user_dir}$2|g; + } "/etc/httpd/conf/commonhttpd.conf"; + } + else { + substInFile { + s|(\s*)UserDir\s*$root(/?)|$1UserDir disabled$2|g; + } "/etc/httpd/conf/commonhttpd.conf"; + } +} + +sub do_it { + $::DEBUG and return; + my $file = "/etc/httpd/conf/commonhttpd.conf"; + my $that = "localhost"; + + if ($o->{var}{web_external} eq "1") { + $that = "all"; + } + elsif ($o->{var}{web_internal} eq "1") { + ($that) = $o->itf_get("IPADDR") =~ qr/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)\d{1,3}$/; + $that .= " 127.0.0.1"; + } + cp_af($file, $file.".orig"); + substInFile { + if( m /^\s*/s...m/^\s*<\/Directory>/s ) { + { s /^\s*Allow .*$/ Allow from $that\n/s;} + ;} + } $file; + chg_docroot(); + chg_user_dir(); + system("/etc/rc.d/init.d/httpd restart"); +} + +1; diff --git a/web_wizard/scripts/Apache2conf.pm b/web_wizard/scripts/Apache2conf.pm index b538fe74..94d284ce 100644 --- a/web_wizard/scripts/Apache2conf.pm +++ b/web_wizard/scripts/Apache2conf.pm @@ -15,6 +15,7 @@ sub check { 0; } +a my $file = "/etc/httpd/conf/httpd2.conf"; my $root; -- cgit v1.2.1