#! /srvtools/http/bin/perl
#############################################################################
#  
#   File:          Prepare.pl
#
#   Author:        Jungmin Kim
#
#   Created:       03/30/95
#   Modified:      
#   Version: 
#
#   Input:      
#   Output:     
#          
#
#   Description:
#               
#   Usage:      
#
#
#############################################################################

require "ParseArg.pl";

%in = ();
&ParseArg(*in);	

print "Content-type: text/html\n\n";
print "\n";
print "<TITLE> INSTALL of WeBBoard </TITLE>\n";
print "<H1> Installation of WeBBoard</H1><P>\n";
print "<HR><P>\n";

### check out passwords
if($in{'passwd1'} ne $in{'passwd2'}) {
    print "You entered wrong passwords!<P>";
    print "Press <B>Back</B> button to return to the previous page<P>.\n";
    print "<HR>\n";
    # Address and copyright
    Address();
    return;
}

### make source directory
if( !mkdir("source", 0700) ) {
       print " Cannot open $in{'source'}: $!<P>";
       return;
}

### make check directory
if( !mkdir($in{'check'}, 0700) ) {
       print " Cannot open $in{'check'}: $!<P>"; 
       return;
} 


### generate passwd file
$file = "> $in{'checkfile'}";
open(OUTFILE, $file);
print OUTFILE "administrator\:$in{'passwd1'}\:administrator\:$in{'email'}\n";
close(OUTFILE);

### generate conference file
$file = "> $in{'conffile'}";
open(OUTFILE, $file);
close(OUTFILE);

### generate letter to be emailed

$file = "> $in{'check'}\/letter";
open(OUTFILE,  $file);
print OUTFILE "$in{'emailletter'}\n";
close(OUTFILE);



### generate Global.pl program
$file = "Global\.pl";
$comm = "rm $file";
system($comm);

$webboardhome =~ s/\s//g;

open(OUTFILE, "> $file");
print OUTFILE "#! /usr/local/bin/perl\n";
print OUTFILE "#\n";
print OUTFILE "# THIS FILE IS AUTOMATICALLY GENERATED BY INSTALL PROGRAM\n";
print OUTFILE "#\n\n";
print OUTFILE "sub Global \{\n";
print OUTFILE "\$webboardhome = \"$in{'webboardhome'}\"\;\n";
print OUTFILE "\$version = \"$in{'version'}\"\;\n";
print OUTFILE "\$webboard = \"$in{'webboard'}\"\;\n";
print OUTFILE "\$action = \"$in{'action'}\"\;\n";
print OUTFILE "\$change = \"$in{'change'}\"\;\n";
print OUTFILE "\$getname = \"$in{'getname'}\"\;\n";
print OUTFILE "\$check = \"$in{'check'}\"\;\n";
print OUTFILE "\$checkfile = \"$in{'checkfile'}\"\;\n";
print OUTFILE "\$fcheckfile = \"\"\;\n";
print OUTFILE "\$help = \"$in{'help'}\"\;\n";
print OUTFILE "\$gif = \"$in{'gif'}\"\;\n";
print OUTFILE "\$webteam = \"$in{'webteam'}\"\;\n";
print OUTFILE "\$versioninfo = \"$in{'versioninfo'}\"\;\n";
print OUTFILE "\$index = \"$in{'index'}\"\;\n";
print OUTFILE "\$findex = \"\"\;\n";
print OUTFILE "\$conffile = \"$in{'conffile'}\"\;\n";
print OUTFILE "\$fconffile = \"\"\;\n";
print OUTFILE "\$cutoff = \"$in{'cutoff'}\"\;\n";
print OUTFILE "\$range = \"$in{'range'}\"\;\n";
print OUTFILE "\$allow = \"$in{'allow'}\"\;\n";
print OUTFILE "\$autoreply = \"$in{'autoreply'}\"\;\n";
#print OUTFILE "\$emailletter = \"$in{'emailletter'}\"\;\n";

print OUTFILE "\}\n";
print OUTFILE "1\;\n";
close(OUTFILE);
chmod 0755, $file;


### move all files to the directory 'source'
system("cp * source");
system("rm *");
system("mv source/WeBBoard .");

print "WeBBoard is installed.\n";
print "Click the following URL to go to the WeBBoard<P>\n";
print "<A HREF=\"$in{'action'}\">$in{'action'}</A><P>\n";

# Address and copyright
Address();

