head	1.2;
access;
symbols;
locks; strict;
comment	@# @;


1.2
date	2000.05.13.17.06.37;	author jrobbins;	state dead;
branches;
next	1.1;

1.1
date	2000.04.28.01.41.37;	author manoj;	state Exp;
branches;
next	;


desc
@@


1.2
log
@removed files that have been replaced with newer files in helm/perl/scripts
@
text
@# ================================================================
# Copyright (c) 2000 Collab.Net.  All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 
# 3. The end-user documentation included with the redistribution, if
# any, must include the following acknowlegement: "This product includes
# software developed by Collab.Net (http://www.Collab.Net/)."
# Alternately, this acknowlegement may appear in the software itself, if
# and wherever such third-party acknowlegements normally appear.
# 
# 4. The hosted project names must not be used to endorse or promote
# products derived from this software without prior written
# permission. For written permission, please contact info@@collab.net.
# 
# 5. Products derived from this software may not use the "Tigris" name
# nor may "Tigris" appear in their names without prior written
# permission of Collab.Net.
# 
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ====================================================================
# 
# This software consists of voluntary contributions made by many
# individuals on behalf of Collab.Net.
#


# Helm/apache.pm
# $Id: apache.pm.in,v 1.1 2000/04/28 01:41:37 manoj Exp $
# ----------------------
# Provides functions to update apache configuration files

package Helm::apache;


use Helm::ToolHook;
@@ISA = qw(Helm::ToolHook);

use strict;





################################################################


sub projectAdd {
    my ($class, $project_name, $domain_name, $brand_name, $description) = @@_;

    add_vhost($class, $project_name, $domain_name, 0);
    #TODO: where does #force come from?
    set_up_pages($class, $project_name, $domain_name, $brand_name, $description);
}

sub projectDelete {
    my ($class, $project_name, $domain_name, $brand_name) = @@_;

    print "apache  : Update __SANDBOX__/tigrisa/conf/webmodules.conf to \n";
    print "          remove $project_name from $domain_name\n";
    print "apache  : In their place put up a 'sorry' page redirect for\n";
    print "          $project_name using brandname $brand_name\n";
}

# Just after a project is removed: del_project Class $db, $project;
# Returns an info string to convey to the user (undef for none)
sub projectEdit {
    print "apache  : do nothing\n";
}


################################################################

sub moduleAdd {
    print "apache  : do nothing\n";
}

sub moduleDelete {
    print "apache  : do nothing\n";
}

sub moduleEdit {
    print "apache  : do nothing\n";
}


################################################################

sub userAdd {
    print "apache  : do nothing\n";
}

sub userDelete {
    print "apache  : do nothing\n";
}

sub userEdit {
    print "apache  : do nothing\n";
}


################################################################

sub projMailAdd {
    print "apache  : do nothing\n";
}

sub projMailDelete {
    print "apache  : do nothing\n";
}

sub projMailEdit {
    print "apache  : do nothing\n";
}



################################################################


sub add_vhost {
    my ($class, $project_name, $domain_name, $force) = @@_;
    print "apache: Update __SANDBOX__/tigrisa/conf/webmodules.conf to add: " .
        $project_name . "." . $domain_name . "\n";
    print "SERVERROOT = " .  $ENV{'SERVERROOT'};
    print "SANDBOX = " .  $ENV{'SANDBOX'};
    #my $vhostlistdir = "/home/tigrisa";
    my $vhostlistdir = "__SANDBOX__/tigrisa/conf";
    my $webmodulesfilename = "webmodules.conf";
    my $vhostlistfile = $vhostlistdir . "/" . $webmodulesfilename;
    # TODO: get dir name from from database instead.

    my $already_exists = 0;
    
    if (-e $vhostlistfile) {
	open(VHOSTLIST, "<$vhostlistfile")
	    or die "Could not open $vhostlistfile: $!\n";
	
	print "apache: check if there is already an entry\n";
	while (<VHOSTLIST>) {
	    /^\s+[iI]nclude (\S)+/;
	    if ($1) {
		my $pos = index $1, $project_name;
		if ($pos != -1) {
		    $already_exists = 1;
		    last;
		}
	    }
	}
	CLOSE VHOSTLIST;
    }

    if ($already_exists == 0) {
	print "apache: append an entry to webmodules.conf\n";
	my $project_pathname = write_vhost_config($class, $project_name, $vhostlistdir, $force);

	
	open(VHOSTLIST, ">>$vhostlistfile")
	    or die "Could not open $vhostlistfile: $!\n";
	print VHOSTLIST "\n\nInclude $project_pathname\n";
	CLOSE VHOSTLIST;
    }
    else {
	print "apache: found existing an entry to webmodules.conf\n";
    }
}



sub write_vhost_config {
    my ($class, $project, $vhostlistdir, $force) = @@_;
    my $project_filename = "proj_" . $project . ".conf";
    my $project_pathname = $vhostlistdir . "/" . $project_filename;
    #my $htdocs = $db->config('apache_htdocs');
    #my $dir = $db->config('apache_configdir');
    #TODO: get pathnames from database


    if ($force == 0 && -e $project_pathname) {
	die "apache: project config file already exists! giving up! \n";
    }
    
    print "apache: writing project config file";

    open(CONFIG, ">$project_pathname")
	or die "Could not open $project_pathname: $!\n";
    
    #print CONFIG "# THIS FILE WAS AUTOMATICALLY GENERATED - DO NOT EDIT\n";
    #print CONFIG "# output from Helm::ApacheConfig\n\n";

    # Set up the virtual host for name-based vhost-ing
    #my $ip = $db->config('apache_hostip');
    #my $port = $db->config('apache_hostport');
    #my $domain = $db->config('domain_dns');
    # TODO: get pathnames from databse

    my $ip = '63.211.145.5';
    my $port = 80;
    my $domain = 'tigris.org';
    my $htdocs = '/home/httpd/html';
    #TODO: use $SANDBOX?
    
    print CONFIG "NameVirtualHost $ip:$port\n";

    # Look in the module_website 
    #my $sth = $db->dbh->prepare("SELECT project,module,vhost,root "
    #				. "FROM module_website");
    #$sth->execute;

    #while (my ($project, $module, $vhost, $root) = $sth->fetchrow_array) {

    print CONFIG "\n# Configuration for Web module $project\n";
    print CONFIG <<"EOF";
<VirtualHost $ip:$port>
ServerAdmin webmaster\@@$project.$domain
DocumentRoot $htdocs/$project/www
ServerName $project.$domain
ErrorLog logs/project-$project-error.log
CustomLog logs/project-$project-access.log common

EOF



    print CONFIG <<"EOF";
#
# rewrite rules
#
  <IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteLog logs/rewrite_log
  RewriteLogLevel 0
EOF

                if ($project eq "www") {
                    print CONFIG <<"EOF";
  RewriteRule ^([/]*)\$                 \$1 [PT]
  RewriteRule ^(/index.html)\$          \$1 [PT]
EOF
}

                print CONFIG <<"EOF";
  RewriteRule ^(/.*/nonav/.*)\$        \$1 [PT]
  RewriteRule ^(/bugs)\$               \$1 [PT]
  RewriteRule ^(/bugs/.*)\$            \$1 [PT]
  RewriteRule ^(/source/.*)\$          \$1 [PT]
  RewriteRule ^(/search/.*)\$          \$1 [PT]
  RewriteRule ^(.*/)\$                 /helm/TView?page=\$1/index.html [PT]
  RewriteRule ^(/.*\.html)\$           /helm/TView?page=\$1 [QSA,PT]
  RewriteRule ^(/.*\.js)\$             \$1 [PT]
  RewriteRule ^/([A-Za-z0-9_]+)\$      /helm/\$1 [PT]
</IfModule>

EOF
                print CONFIG <<"EOF";
</VirtualHost>
EOF


	# The options should be configurable
	print CONFIG <<"EOF";
<Directory $htdocs/$project/www>
Options Indexes FollowSymLinks
AllowOverride None
order allow,deny
allow from all
</Directory>
EOF

    close CONFIG;

}

sub set_up_pages {
    my ($class, $project_name, $domain_name, $brand_name, $description) = @@_;
    print "apache: Check in template files for project: " .
        $project_name . " using brandname " . $brand_name . "\n";

}


# update Helm::CVSUsers $db;
# We just process the list of modules and add them. Trivial, really.
sub update {
    my ($class, $db) = @@_;
    my $htdocs = $db->config('apache_htdocs');
    my $dir = $db->config('apache_configdir');

    open(CONFIG, ">$dir/webmodules.conf")
	or die "Could not open $dir/webmodules.conf: $!\n";

    print CONFIG "# THIS FILE WAS AUTOMATICALLY GENERATED - DO NOT EDIT\n";
    print CONFIG "# output from Helm::ApacheConfig\n\n";

    # Set up the virtual host for name-based vhost-ing
    my $ip = $db->config('apache_hostip');
    my $port = $db->config('apache_hostport');
    print CONFIG "NameVirtualHost $ip:$port\n";

    my $domain = $db->config('domain_dns');

    # Look in the module_website 
    my $sth = $db->dbh->prepare("SELECT project,module,vhost,root "
				. "FROM module_website");
    $sth->execute;

    while (my ($project, $module, $vhost, $root) = $sth->fetchrow_array) {
	print CONFIG "\n# Configuration for Web module $project-$module\n";

	if ($vhost eq 'Y') {
	    if ($root eq '/') {
		print CONFIG <<"EOF";
<VirtualHost $ip:$port>
ServerAdmin webmaster\@@$project.$domain
DocumentRoot $htdocs/$project/$module
ServerName $project.$domain
ErrorLog logs/project-$project-error.log
CustomLog logs/project-$project-access.log common

EOF



                print CONFIG <<"EOF";
#
# rewrite rules
#
  <IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteLog logs/rewrite_log
  RewriteLogLevel 0
EOF

                if ($project eq "www") {
                    print CONFIG <<"EOF";
  RewriteRule ^([/]*)\$                 \$1 [PT]
  RewriteRule ^(/index.html)\$          \$1 [PT]
EOF
}

                print CONFIG <<"EOF";
  RewriteRule ^(/.*/nonav/.*)\$        \$1 [PT]
  RewriteRule ^(/bugs)\$               \$1 [PT]
  RewriteRule ^(/bugs/.*)\$            \$1 [PT]
  RewriteRule ^(/source/.*)\$          \$1 [PT]
  RewriteRule ^(/search/.*)\$          \$1 [PT]
  RewriteRule ^(.*/)\$                 /helm/TView?page=\$1/index.html [PT]
  RewriteRule ^(/.*\.html)\$           /helm/TView?page=\$1 [QSA,PT]
  RewriteRule ^(/.*\.js)\$             \$1 [PT]
  RewriteRule ^/([A-Za-z0-9_]+)\$      /helm/\$1 [PT]
</IfModule>

EOF
                print CONFIG <<"EOF";
</VirtualHost>
EOF
	    } else {
		# TODO.
		die "Oops... non-root vhosts not currently implemented\n";
	    }
	} else {
	    print CONFIG "Alias $root $htdocs/$project/$module/\n"
	}

	# The options should be configurable
	print CONFIG <<"EOF";
<Directory $htdocs/$project/$module>
Options Indexes FollowSymLinks
AllowOverride None
order allow,deny
allow from all
</Directory>
EOF
    }

    close CONFIG;
}

# Nothing special beyond updating
sub add_project {
}
sub del_project {
}
@


1.1
log
@Changes to match the New World Order of paths.
@
text
@d49 1
a49 1
# $Id: apache.pm,v 1.1 2000/03/24 20:33:58 jrobbins Exp $
@

