#!/usr/bin/perl

#------------------------------------------------------------------------------------------
# Edit the settings below and run 
#      perl install.pl
#
# Please: Double check your httpd owner! if unsure run "ps auxww |grep httpd"
#
#------------------------------------------------------------------------------------------
    #
    # CGIDIR is the directory where web calendar cgi scripts reside. 

    $CGIDIR="/usr/local/apache/cgi-bin/wcal";

    # used only when htpassword authentication is selected. It is
    # shared by all your virtual servers.
    $SIGNUPCGINAME="/usr/local/apache/cgi-bin/wcalsignup/signup.pl";

    # IMAGEDIR is the directory to store webcalendar icons. Must be
    # accessible by your webserver.
     
    $IMAGEDIR="/usr/local/apache/htdocs/wcal/images";

    # webCal support two types of authentication: HTTP_COOKIE and HTTP_PASSWORD
    # Use cookie authentication if at all possible. Most modern browser support
    # cookies. 

    #$AUTHMETHOD="password";
    $AUTHMETHOD="cookie";

    # if you run sendmail on your webserver, the path of sendmail 
    $SENDMAIL="/usr/bin/sendmail";
    # otherwise, choose smtp and define SMTPTO and SMTPFROM.
    # SMTPTO   is the DNS name of your smtp server.
    # SMTPFROM is the DNS name of your web server.
    $SMTPTO="";
    $SMTPFROM="";

    # CGINAME is the REAL FULL PATHNAME of the cgi script, this is where the 
    # script is installed. Your server should be able to execute script from
    # this location. CGILINK, CGIUPLOAD and CGIIMPORT are help scripts used 
    # by webcalendar.
 
    $CGINAME="$CGIDIR/x.pl";
    $CGILINK="$CGIDIR/x-link.pl";
    $CGIUPLOAD="$CGIDIR/x-upload.pl";
    $CGIIMPORT="$CGIDIR/x-import.pl";

    # DAEMONNAME is the full pathname of the webcald. If you want your calendar
    # to send you email reminders, you need to have a way to start this daemon
    # each time your server is rebooted. 
    #
    $DAEMONNAME="$CGIDIR/wcald";

#------------------------------------------------------------------------------------------
#
#
%servers = (
  # you have to have a default server. It must be named 'default_server'.
  # It is the only server if you don't install webcal on more than one virtual servers.

  'default_server' =>  {  
      'servername'       => 'localhost',
      'http'             => 'http',             # http or https
      'owner'            => 'nobody',           # owner of http*d

      # email address to be used on the From line of email reminders 
      'daemonEmail'      => 'webcal@my.domain.org',

      # Directory to store calendar data
      'spooldir'         => '/usr/local/apache/wcal/server1',     

      # if you use htpassword authentication and you have more than one
      # virtual servers, define the next variable. The CGI scripts
      # must resides on a distinct subdirectory for each virtual
      # server. You have to reconfigure your virtual web servers 
      # so that they can execute webcal scripts. For apache,
      # insert a ScriptAlias directive in your httpd.conf for
      # each cgidir.
      #'cgidir'            => '/usr/local/apache/cgi-bin/wcal',

      # URLs of cgi, relative to / 
      'cginame'           => '/cgi-bin/wcal/wcal.pl', 
      'cgilink'           => '/cgi-bin/wcal/wcal-link.pl',
      'cgiimport'         => '/cgi-bin/wcal/wcal-import.pl',
      'cgiupload'         => '/cgi-bin/wcal/wcal-upload.pl',

      'imgdirurl'        => '/wcal/images',
		
      # the next variable is used only if you use htpassword authentication  
      'signupurl'        => '/cgi-bin/wcalsignup/signup.pl',
     
      # subdirectories to hold user uploads. They are sub directories of $IMAGEDIR
      'uploadtmpsubdir'  => 'uploads',
      'uploadsubdir'     => 'uis',
      
      # banner setup, if any. See banner.perl for examples
      'banner'           => '',
      
      # Greeting page setup
      'greetingfile'     => '/usr/local/apache/htdocs/wcal/index.html',
      'greetingurl'      => '/wcal/index.html',

      # Other variables in %webcalConcig:c may also be redefined.
      # See webcalConfig for a complete list of configurable variables.
  },
	    
  # Define the above table for each virtual server you plan
  # to run webcalendar. 

);


#==========================================================================================
#  You don't need to edit the rest of this file
#==========================================================================================
sub do_install {
    if($ENV{'SERVER_NAME'}) {
	print "Content-type: text/html\n\n";
	print "<html><body bgcolor=#ffffff>\n";
	print "<center><h1>WebCalendar Installation Log</h1></center>\n";
	print "<pre>\n";
    } else {
	print "\nWebCalendar Installation Log\n\n";
    }

    &check_virtual_server_subdir;
    &install_script;
    map {install_one_server($_);} (keys %servers);

    if($ENV{'SERVER_NAME'}) {
	print "</body></html>";
    }
}
#------------------------------------------------------------------------------------------
@ansi_colors = ("[44;32m ", "[42;44m", "[43;32m", "[41;32m","[40;32m",
		"[39;32m", "[38;32m");
$color_counter = 0;

sub printmsg {
    my ($msg , $btag, $etag) = (@_);
    if($ENV{'SERVER_NAME'}) {
	if($btag and $etag) { print $btag, $msg, $etag;}
	else {print "<font size=2> $msg </font>";}
#    } elsif($btag and $etag) {
#	my $clr = $ansi_colors[$color_counter];  $color_counter=($color_counter+1)%7;
#	my ($b, $m, $e);
#	if( $msg =~ /([\n]*)([^\n]+)([\s|\n]*)/) {$b = $1; $m = $2; $e=$3;} else {$m=$msg;}
#	print $b, $clr, $m , "[m", $e;
    } else {
	print $msg;
    }
}
#------------------------------------------------------------------------------------------
sub vserver_passwd_auth_info {
    my ($msg) = (@_);
    printmsg "=========================================================================================\n";
    printmsg "      To use htpassword authentication with more than one virtual servers,\n", 
    "<font color=#ff0000><b>", "</b></font>";
    printmsg "      you have to define the variable \"cgidir\" for each virtual server. \n",
    "<font color=#ff0000><b>", "</b></font>";
    printmsg "      Furthermore, this directory should be distinct for all virtual servers.\n", 
    "<font color=#ff0000><b>", "</b></font>";
    printmsg "      WebCalendar script will be installed in $CGIDIR, \n",
    "<font color=#ff0000><b>", "</b></font>";
    printmsg "      and are symbolically linked to all virtual server cgi directories.\n",
    "<font color=#ff0000><b>", "</b></font>";
    printmsg "=========================================================================================\n";
    printmsg "$msg", "<font size=+1 color=#ff00ff><b>", "<b></font>" if $msg;
    exit 100;
}

#------------------------------------------------------------------------------------------
sub check_virtual_server_subdir {
    my @all_servers = (keys %servers);
    my %cgidirhash = ();
    my %cginamehash = ();
    my $nservers = 0+@all_servers;
    if( 1 ) {
	foreach $server (@all_servers) {
	    my $cgidir = $servers{$server}->{'cgidir'};
	    my $sname =$servers{$server}->{'servername'};
	    if($nservers > 1 and ! $cgidir and $AUTHMETHOD eq 'password') {
		my $msg = "\ncgidir is underfined for \"$server\" ($sname)";
		vserver_passwd_auth_info($msg);
	    }
	    $cgidirhash{$sname} = $cgidir;
	    $cginamehash{$sname} = $servers{$server}->{'cginame'};
	}
	foreach $server (@all_servers) { 
	    my $cgidir = $servers{$server}->{'cgidir'};
	    foreach $other (@all_servers) { 
		next if $other eq $server;
		my $dir = $servers{$other}->{'cgidir'};
		if($nservers > 1 and $cgidir eq $dir and  $AUTHMETHOD eq 'password') {
		    my $msg = "\nServer \"$server\" and \"$other\" use the same cgidir \"$dir\"";
		    vserver_passwd_auth_info($msg);
		}
	    }
	}
	my $error = 0;
	if($nservers > 1 and  $AUTHMETHOD eq 'password') {
	    foreach $server (@all_servers) { 
		my $cginame = $servers{$server}->{'cginame'};
		foreach $other (@all_servers) { 
		    next if $other eq $server;
		    my $name = $servers{$other}->{'cginame'};
		    if($cginame eq $name) {
			printmsg "=========================================================================================\n";
			printmsg "\nServer ",  "<font color=#ff0000><b>", "</b></font>";
			printmsg "$server ",  "<font color=#0000ff><b>", "</b></font>";
			printmsg "and ",  "<font color=#ff0000><b>", "</b></font>";
			printmsg "$other ",  "<font color=#0000ff><b>", "</b></font>";
			printmsg "use the same cginame ", "<font color=#ff0000><b>", "</b></font>";
			printmsg "\"$name\"\n","<font color=#0000ff><b>", "</b></font>";
			printmsg "This is probably not what you want. ",  "<font color=#ff0000><b>", "</b></font>"; 
			printmsg "Please double check your cgi pathnames.\n","<font color=#ff0000><b>", "</b></font>"; 
			printmsg "=========================================================================================\n";
			$error = 1;
			last;
		    }
		}
		last if $error;
	    }
	}
    }
    printmsg "\n\n";
    printmsg "=========================================================================================\n";
    printmsg "Please configure your webserver to use the following CGI directories\n\n",
    "<font color=#009900><b>", "</b></font>"; 
    my $dsvrname = $servers{'default_server'}->{'servername'};
    printmsg "Server=$dsvrname, ",  "<font color=#0000ff><b>", "</b></font>"; 
    printmsg "cgidir=$CGIDIR ", "<font color=#ff0000><b>", "</b></font>"; 	
    printmsg "\n\n";
    if($AUTHMETHOD eq 'password') {
	my $sdir = $SIGNUPCGINAME; $sdir =~ s/[^\/]+$//g;
	my $surl = $servers{'default_server'}->{'signupurl'};
	printmsg "Server=$dsvrname, ",  "<font color=#0000ff><b>", "</b></font>"; 
	printmsg "cgidir=$sdir ", "<font color=#ff0000><b>", "</b></font>"; 	
	printmsg "cginame=$surl\n\n", "<font color=#009900><b>", "</b></font>"; 	
    }
    for $k (keys %cgidirhash) {
	$dir = $cgidirhash{$k}; if(! $dir) { $dir = $CGIDIR;}
	$name = $cginamehash{$k};
	printmsg "Server=$k, ",  "<font color=#0000ff><b>", "</b></font>"; 
	printmsg "cgidir=$dir ", "<font color=#ff0000><b>", "</b></font>"; 
	printmsg "cginame=$name\n\n", "<font color=#009900><b>", "</b></font>"; 
    }
    printmsg "=========================================================================================\n";
    printmsg "\n\n";	
}
#------------------------------------------------------------------------------------------
sub copy_server_setup {
    my $server = @_[0];
    my $ref = $servers{$server};
    my $ans="";
    my $servername = "";
    if($ref and $ref->{'spooldir'}) {
	my $http = $ref->{'http'};
	my $tmp = $ref->{'cginame'};
	$servername=$ref->{'servername'};
	$ref->{'fcginame'} = "$http://$servername$tmp";
	$tmp = $ref->{'imgdirurl'};
	$ref->{'fimgdirurl'} = "$http://$servername$tmp";	
	$ref->{'imgdir'} = "$IMAGEDIR";	
	foreach $k (keys %$ref) {
	    if( $k ne 'http' and $k ne 'cgidir' and $k ne 'owner') {
		my $v = $ref->{$k}; $v=~ s/\'/\\\'/g;
		$tmp = "\'$k\' => \'$v\',\n";
		$ans .= $tmp;
	    }
	}
    }
    return ($servername, $ans);
}

#--------------

sub mkdirhier {
    my ($pathname) = (@_);
    my ($abspath, @path);
    if($pathname =~ /^\//) { $abspath = $pathname;}
    elsif($pathname =~ /^\.\//) { 
	use Cwd;
	my $tmp = cwd();
	$pathname =~ s/^\.\///;
	$abspath = "$tmp/$pathname";
    } else {
	printmsg "Don't know how to mkdir $pathname", "<font color=#ff0000><b>", "</b></font>";
	exit 1;
    }
    @path = split(/\//, $abspath);
    $pathname="";
    for $k (@path) {
	if($k) {
	    $pathname .= "/$k";
	    if(! -d "$pathname") {
		printmsg "------ create directory $pathname\n", "<font color=#0000ff><b>", "</b></font>";
		if(! mkdir($pathname, 0755) ) {
		    printmsg  "Cannot mkdir \"$pathname\"", "<font color=#ff0000><b>", "</b></font>";
		    exit 1;
		}
	    }
	}
    }
}

#--------------

sub system1 {
    printmsg "      " .  join(' ', @_) . "\n";
    if( system(@_)) {
	printmsg "        Command failed: $! ", "<font color=#ff0000><b>", "</b></font>";
	printmsg " == Trying to continue ==\n", "<font color=#00cc00><b>", "</b></font>";
    } 
}

#--------------

sub install_script {
    if( $SENDMAIL ) {
	if( ! -f "$SENDMAIL" )  { 
	    printmsg "$SENDMAIL does not exist", "<font color=#ff0000><b>", "</b></font>";
	    exit 2;
	}
	elsif(! -x "$SENDMAIL") {
	    printmsg "$SENDMAIL does not to be the \'sendmail\' binary.", "<font color=#ff0000><b>", "</b></font>";
	    exit 3;
	}
    } else {
	if(! "$SMTPTO" or  ! "$SMTPFROM") {
	    printmsg "Please specify your SMTP server.",  "<font color=#ff0000><b>", "</b></font>";
	    exit 4;
	}
    }

    $PERL=`which perl`;
    if(! $PERL) { 
	printmsg "Could NOT locate your perl binary. Please make sure perl5 or later is installed.",
	"<font color=#ff0000 size=+1><b>", "</b></font>";
	exit 5;
    }
    
    
    if(! $CGINAME) {
	printmsg "CGINAME cannot be empty.", "<font color=#ff0000><b>", "</b></font>";
	exit 6;
    }

    if( ! $CGILINK) {
	printmsg "CGILINK cannot be empty."  , "<font color=#ff0000><b>", "</b></font>";
	exit 7;
    }
    if(! $CGIUPLOAD) {
	printmsg "CGIUPLOAD cannot be empty." , "<font color=#ff0000><b>", "</b></font>"; 
	exit 8;
    }
    
    if(! $CGIIMPORT) {
	printmsg "CGIIMPORT cannot be empty." , "<font color=#ff0000><b>", "</b></font>";
	exit 9;
    }

    if( "$AUTHMETHOD" eq "password" ) {
	if(! $SIGNUPCGINAME) {
	    printmsg "SIGNUPCGINAME cannot be empty.", "<font color=#ff0000><b>", "</b></font>";  
	    exit 10;
	}
    }

    
    mkdirhier($CGIDIR)  if ! -d $CGIDIR;
    chmod 0755, $CGIDIR;
    mkdirhier($IMAGEDIR)  if !  -d $IMAGEDIR;
    chmod 0755, $IMAGEDIR;

    my $tdir = $CGINAME; $tdir =~ s/[^\/]+$//g;

    if(! -d "$tdir") {
	mkdirhier($tdir);
    }
    chmod  0755, $tdir;

    if( "$AUTHMETHOD" eq "password" ) {    
	$tdir = $SIGNUPCGINAME;
	$SIGNUPCGIDIR=$tdir;
	$tdir =~ s/\/[^\/]+$//;
	if( ! -d $tdir) {
	    mkdirhier($tdir);
	}
	chmod  0755, $tdir;
	$SIGNUPCGIDIR=$tdir;
    }

    printmsg "------ copy scripts\n",  "<font color=#0000ff><b>", "</b></font>";
    while(<*.perl>) {  system1( "cp", $_, $CGIDIR); }
    install_perl_script("webcal.pl", $CGINAME);
    install_perl_script("webcal-iupload.pl", $CGIUPLOAD);
    install_perl_script("webcal-import.pl", $CGIIMPORT);
    install_perl_script("webcal-link.pl", $CGILINK);
    install_perl_script("webcald.pl", $DAEMONNAME);
    system1("cp", "webcalVirtual.pm", "$CGIDIR");
    system1("cp", "webcalSupport.pm", "$CGIDIR");
    system1("cp", "webcalMoon.pm", "$CGIDIR");
    system1("cp", "webcalSync.pm", "$CGIDIR");
    system1("cp", "webcal_vcal_sync_server.pl", "$CGIDIR");
    system1("cp", "webcal_vcal_sync_client.pl", "$CGIDIR");
    system1("cp", "webcal_cmd_server.pl", "$CGIDIR");
    system1("cp", "webcal_cmd.pl", "$CGIDIR");
    system1("cp", "smtplib.pm", "$CGIDIR");

    if( "$AUTHMETHOD" eq "password" ) { 
	while(<$SIGNUPCGIDIR/*>) { rename $_ , $_ . "-old";}
	while(<$CGIDIR/*>) { system1("ln", "-s", "$_", "$SIGNUPCGIDIR");}
	system1("ln", "-s", "$CGINAME", "$SIGNUPCGINAME");
    }
    
    printmsg "------ Copy webcalConfig.pm template\n", "<font color=#0000ff><b>", "</b></font>";
    if(open(SRC, "<./webcalConfig.pm") and open(TGT, ">$CGIDIR/webcalConfig.pm")) {
	while(<SRC>) { 
	    if(/\'cookieAuth\'/) {
		if($AUTHMETHOD eq "password") { $_ = "      \'cookieAuth\'=>0,\n";}
		else {  $_ = "      \'cookieAuth\'=>1,\n";}
	    }
	    print TGT $_ if not /aAa/; 
	}
	close SRC; close TGT;
    }


    
    printmsg "------ Copy icons to $IMAGEDIR\n", "<font color=#0000ff><b>", "</b></font>";
    while(<images/*>) { system("cp", $_, $IMAGEDIR) if -f "$_"; }
}

#--------------

sub install_perl_script {
    my ($src, $dest) = (@_);
    chop($PERL=`which perl`);
    if(open SRC, "<$src" and open TGT, ">$dest") {
	print TGT "#!$PERL\n\n";
	my $tmp = $CGIDIR;
	print TGT "use lib \"$tmp\";\n\n";

	while(<SRC>) { print TGT $_;}
	close SRC; close TGT;
	chmod 0755, $dest;
    }
}

#--------------

sub make_link_if_needed {
    my ($src, $target) = (@_);
    my ($srcbase, $targetbase);
    if($src and $target) {
	if($src =~ /([^\/]+$)/ ) { $srcbase = $1; $srcdir = $src; $srcdir =~ s/[^\/]+$//;}
	if($target =~ /([^\/]+$)/ ) { $targetbase = $1;}
        if($srcbase and $targetbase and $srcbase ne $targetbase) {
	    if( -f "$srcdir$targetbase") { 
		rename "$srcdir$targetbase", "$srcdir$targetbase" . "-old";
	    }
	    system1( "ln", "-s", "$src", "$srcdir$targetbase");
	}
    }
}

#--------------

sub install_one_server {
    my ($name) =(@_);
    
    printmsg "\n+++++++++++ install server \"$name\" ++++++++++++\n\n", "<font color=#ff0066 size=+1><b>", "</b></font>";

    $config_dist = "./webcalConfig.pm";
    $config = "$CGIDIR/webcalConfig.pm";
    if( ! -f "$config") { system1( "cp", "$config_dist", "$config"); }
    $httpdowner = $servers{$name}->{'owner'};
    $spooldir = $servers{$name}->{'spooldir'};

    &make_link_if_needed($CGINAME, $servers{$name}->{'cginame'});
    &make_link_if_needed($CGILINK, $servers{$name}->{'cgilink'});
    &make_link_if_needed($CGIUPLOAD, $servers{$name}->{'cgiupload'});
    &make_link_if_needed($CGIIMPORT, $servers{$name}->{'cgiimport'});
    
    my $cgidir = $servers{$name}->{'cgidir'};
    if(defined $cgidir and $cgidir and $cgidir ne $CGIDIR) {
	mkdirhier($cgidir) if ! -d $cgifir;
	while(<$cgidir/*>) { rename $_ , $_ . "-old"; } # delete current content first
	while(<$CGIDIR/*>) { system1('ln' , '-s', "$_", "$cgidir"); }
    }

    # install .htaccess
    if("$AUTHMETHOD" eq "password") {
	my @all_servers = (keys %servers);
	my $nservers = 0 + @all_servers;
	if(! $cgidir and $nservers == 1) { $cgidir = $CGIDIR;}
	
	if(! -d $cgidir) { &vserver_passwd_auth_info;}
	if( -f "$cgidir/.htaccess") { unlink "$cgidir/.htaccess";}
	if(open FILE, ">$cgidir/.htaccess") {
	    print FILE <<END_OF_FILE;
AuthUserFile $spooldir/passwd
AuthGroupFile /dev/null
AuthName Calendar
AuthType Basic
<Limit GET POST PUT>
require valid-user
</Limit>
END_OF_FILE
    ;
	}
	chmod 0444,  "$cgidir/.htaccess";
    } else {
	if( $cgidir and  -f "$cgidir/.htaccess" ) { unlink  "$cgidir/.htaccess";}
    }

    
    ($server_name, $server_setup) = copy_server_setup($name);

    $tt = time;
    $tfile = "/tmp/wcal$tt";
    if(open SRC, "<$config" and open TGT, ">$tfile") {
	if($name eq 'default_server') {
	    while(<SRC>) { 
                s/\$SENDMAIL=.+;/\$SENDMAIL=\"$SENDMAIL\";/g;
                s/\$SMTPTO=.+;/\$SMTPTO=\"$SMTPTO\";/g;
                s/\$SMTPFROM=.+;/\$SMTPFROM=\"$SMTPFROM\";/g;
		s/insert_default_server_setup_here/\n$server_setup\n\n/;
		print TGT $_;
#"
	    }
	} else {
	    while(<SRC>) { 
		print TGT $_;
		if(/insert_virtual_server_setup_here/) {
		    print TGT "\'$name\'=>{\n", $server_setup, "\n},\n\n\n";
		}
	    }
	} 
	close SRC; close TGT;
    }
    system1("cp", "$tfile", "$config");
    unlink "$tfile" if -f "$tfile";

    mkdirhier("$spooldir");
    if(! -f "$spooldir/passwd") {   system1("cp", "./passwd", "$spooldir/passwd");}
    chmod 0600, "$spooldir/passwd"; 
    if(! -f "$spooldir/.htaccess" ) { system1("cp", "./htaccess","$spooldir/.htaccess");}
    chmod 0444, "$spooldir/.htaccess";
    if(open FILE, ">$spooldir/log") { print FILE "\n"; close FILE;}
    system1("chown", "-R", $httpdowner, $spooldir);
    chmod 0711, "$spooldir";

    my $imagedir = $IMAGEDIR;
    my $udir = $servers{$name}->{'uploadtmpsubdir'};
    mkdirhier("$imagedir/$udir"); system1("chown", "-R", $httpdowner, "$imagedir/$udir");
    $udir = $servers{$name}->{'uploadsubdir'}; 
    mkdirhier("$imagedir/$udir"); system1("chown", "-R", $httpdowner, "$imagedir/$udir");
    my $gfile = $servers{$name}->{'greetingfile'};
    $udir = $gfile; $udir =~ s/[^\/]+$//;
    mkdirhier("$udir") if ! -d "$udir";

    my $fullcgiurl = $servers{$name}->{'fcginame'};
    my $signupurl = $servers{$name}->{'signupurl'};

    if($signupurl =~ /^\//) {
        my $tmp = $fullcgiurl;
        my $base = "";
        if($tmp =~ /^(http.?:\/\/[^\/]+)\//) { $base = $1;}
        $signupurl = "$base$signupurl";
    }

    if(open FILE, ">$gfile") {
	if("$AUTHMETHOD" eq "password") {
	    print FILE <<EOF
<HTML>
<TITLE>Welcome to Web Calendar</TITLE>
<body bgcolor="#eeeedd" TEXT="#000000" LINK="#666600"> <br><br><br>
<center>
<br>
<table border=10 cellpadding=10 cellspacing=4 width=60%>
<tr><td bgcolor="#eeeedd" align=center><br><h1><b>Welcome to Web Calendar</b></h1></td></tr>
<tr><td bgcolor="#eeeedd" align=center noWrap> 
<br>
To access your calendar, please <a href="$fullcgiurl">login</a> <br> <br> 
To setup a new calendar, please <a href="$signupurl">signup</a>
<br>
<br>
</tr></td>
</table>
</center>
</body>
</HTML> 
EOF
    ;
	    printmsg "\n\n";
	    printmsg "        Please use the following url to access your webcalendar server\n", "<font size=+1><b>", "</b></font>";
	    printmsg "               ";
	    printmsg "$fullcgiurl ", "<a href=\"$fullcgiurl\"><font color=#0000ff size=+1><b>", "</b></font></a>";
	    printmsg "\n";
	    printmsg "        and use the following url to signup\n","<font size=+1><b>", "</b></font>";
	    printmsg "               ";
	    printmsg "$signupurl ", "<a href=\"$signupurl\"><font color=#0000ff size=+1><b>", "</b></font></a>";
	    printmsg "\n\n";
	    
	} else {
	    print FILE <<EOF
<HTML>
<TITLE></TITLE>
<META HTTP-EQUIV="refresh" content="0; URL=$fullcgiurl">
<body onload="document.location=\"$fullcgiurl\""> 
</body>
</HTML> 
EOF
    ;
	    printmsg "\n\n";
	    printmsg "        Please use the following url to access your webcalendar server\n", "<font size=+1><b>", "</b></font>";
	    printmsg "               ";
	    printmsg "$fullcgiurl", "<a href=\"$fullcgiurl\"><font color=#0000ff size=+1><b>", "</b></font></a>";
	    printmsg "\n\n";
	}
	close FILE;
    } else {
	printmsg "    Cannot write to $gfile. Installation failed.", "<font color=#ff0000 size=+1><b>", "</b></font></a>";
    }
}

#------------------------------------------------------------------------------------------
&do_install;
#------------------------------------------------------------------------------------------
