#!perl -w
# Import server settings.
# Called by import.
#
BEGIN {
    @INC = ( '../../perl', '../../install/misc' );
}
use Cgi;
use BinUtil;
use Magnus;

$| = 1;
$isNT = -d '\\';
if ($isNT) {
    $libExt = ".dll";
    $libPrefix = "";
    $libLocation = "bin";
    $os = "WINNT";
} else {
    $libPrefix = "lib";
    $libLocation = "lib";
    chomp($os = `uname -s`);
    if ($os =~ /HP-UX/) {
	$libExt = ".sl";
    } else {
	if (!$os) {
	    print "<FONT COLOR=\"red\">Warning:</FONT> Cannot run <CODE>uname</CODE>.  Assuming this is <B>not</B> an HP machine.\n";
	}
	$libExt = ".so";
    }
}
%pkgList = BinUtil::getPkgList($ENV{'NETSITE_ROOT'});

$perl = "../../perl/perl";
$rootDir = $ENV{'NETSITE_ROOT'};
$binDir = "$rootDir/bin/https";
$libDir = "$binDir/$libLocation"; 
$sname = "https-$cgiVars{'name'}";
$trail = substr($cgiVars{'dir'}, length($cgiVars{'dir'})-1, length($cgiVars{'dir'}));
if ($trail eq "/" || $trail eq "\\") {
    chop($cgiVars{'dir'});
}
$newHome = "$rootDir/$sname";
$oldHome = "$cgiVars{'dir'}/$cgiVars{'server'}";

if($isNT) {
    # create NT-specific entries
    print "Creating Registry Keys and Service...\n";
    system("../../bin/ntregister -r$rootDir -i$cgiVars{'name'} > nul");
} else {
    # create Unix-specific scripts
    $ldlibrarypath = "\${SERVER_ROOT}/bin/\${PRODUCT_NAME}/lib:";
    if ($os =~ /AIX/) {
	# AIX requires /usr/lib and /lib to be in the path
	$ldlibrarypath .= "/usr/lib:/lib:";
    }
    $ldlibrarypath .= "\${LD_LIBRARY_PATH}";
    BinUtil::makeScript("ROOT=$rootDir", "SUBDIR=$newHome",
			'NAME=https', 'BIN=uxwdog',
			"LD_LIBRARY_PATH=$ldlibrarypath",
			"$rootDir/bin/https/install/misc/start",
			"$newHome/start");
    BinUtil::makeScript("ROOT=$rootDir", "SUBDIR=$newHome",
			"$rootDir/bin/https/install/misc/stop",
			"$newHome/stop");
    BinUtil::makeScript("ROOT=$rootDir", "SUBDIR=$newHome",
			"$rootDir/bin/https/install/misc/restart",
			"$newHome/restart");
    BinUtil::copyFile("$rootDir/bin/https/install/misc/rotate", "$newHome/rotate");
}

# create directories
mkdir("$newHome/logs", 0755);
mkdir("$newHome/config", 0755);
mkdir("$newHome/conf_bk", 0755);
if ($pkgList{'java'}) {
    mkdir("$newHome/ClassCache", 01777);
    mkdir("$newHome/SessionData", 01777);
    # mkdir's permissions are modified by umask,
    # so do a chmod to make sure it gets set correctly
    chmod(01777, "$newHome/ClassCache", "$newHome/SessionData");
}

# copy ACL files
print "Assimilating ACL settings...\n";
BinUtil::copyFile("$cgiVars{'dir'}/httpacl/generated.$cgiVars{'server'}.acl",
                  "$rootDir/httpacl/generated.${sname}.acl");
if ($cgiVars{'version'} eq "3.6") {
    open(ACL, ">> $rootDir/httpacl/generated.${sname}.acl") or
        die "<FONT COLOR=\"red\">[Error]</FONT> Cannot edit $rootDir/httpacl/generated.${sname}.acl: $!.\n";
    print ACL "\n";
    print ACL "acl \"es-internal\";\n";
    print ACL "allow (read, list, execute, info) user = \"anyone\";\n";
    print ACL "deny (write, delete) user = \"anyone\";\n\n";
    close(ACL);
  BinUtil::copyFile("$cgiVars{'dir'}/httpacl/genwork.$cgiVars{'server'}.acl",
                    "$rootDir/httpacl/genwork.${sname}.acl");
    open(ACL, ">> $rootDir/httpacl/genwork.${sname}.acl") or
        die "<FONT COLOR=\"red\">[Error]</FONT> Cannot edit $rootDir/httpacl/genwork.${sname}.acl: $!.\n";
    print ACL "\n";
    print ACL "acl \"es-internal\";\n";
    print ACL "allow (read, list, execute, info) user = \"anyone\";\n";
    print ACL "deny (write, delete) user = \"anyone\";\n\n";
    close(ACL);
}
if (!$isNT) {
    # change owner of acl files
    chown((getpwnam($cgiVars{'user'}))[2, 3],
          "$rootDir/httpacl/genwork.${sname}.acl",
          "$rootDir/httpacl/generated.${sname}.acl");
}

# handle magnus.conf
print "Assimilating <CODE>magnus.conf</CODE>...\n";
BinUtil::copyFile("$oldHome/config/magnus.conf", "$newHome/config/magnus.conf");
# strip out obsolete directives
my %obsoleteDirectives =(
			 'Certfile' =>1,
			 'Keyfile'  =>1
			);
removeObsoleteDirectives("$newHome/config/magnus.conf", \%obsoleteDirectives);
# translate paths
BinUtil::fixPaths("$newHome/config/magnus.conf",
		  2,
		  $oldHome, $cgiVars{'dir'},
		  $newHome, $rootDir,
		  '/logs/', '/httpacl/', '/alias/');
$magnus = new Magnus("$newHome/config/magnus.conf");
if ($cgiVars{'server'} ne "$sname") {
    # deal with any name changes
    $magnus->set('ServerID', $sname);
    if ($aclfile = $magnus->value('ACLFile')) {
	$aclfile =~ s/$cgiVars{'server'}/$sname/;
	$magnus->set('ACLFile', $aclfile);
    }
}
if ($isNT) {
    # fix ExtraPath
    my $extraPath = "$rootDir/bin/https/bin;";
    if ($pkgList{'java'}) {
	$rez = `../../bin/regconfig -l NSES_JRE`;
	if (!($rez =~ /Could not find/)) {
	    # assuming java v2 directory format
	    $extraPath .= "$rez/bin;$rez/bin/classic;";
	}
    }
    if ($pkgList{'wai'}) {
	$rez = `../../bin/regconfig -l ORB_DIR`;
	if (!($rez =~ /Could not find/)) {
	    $extraPath .= "$rez/bin;";
	}
    }
    $trail = substr($extraPath, length($extraPath)-1, length($extraPath));
    if ($trail eq ";") {
	chop($extraPath);
    }
    $magnus->set('ExtraPath', $extraPath);
}
if (!$isNT) {
    # deal with any user changes
    $user = $magnus->value('User');
    if ($cgiVars{'user'} and $cgiVars{'user'} ne $user) {
	$magnus->set('User', $cgiVars{'user'});
    }
    chown((getpwnam($cgiVars{'user'}))[2, 3], "$newHome/logs");
}
# this also removes any obsoleted Init directives
$magnus->flush();
# backup magnus.conf
BinUtil::backupFile($newHome, $sname, "magnus.conf");

# handle obj.conf
print "Assimilating <CODE>obj.conf</CODE>...\n";
BinUtil::copyFile("$oldHome/config/obj.conf", "$newHome/config/obj.conf");
if ($cgiVars{'version'} eq "3.6") {
    fixObjects("$newHome/config/obj.conf");
}
BinUtil::fixPaths("$newHome/config/obj.conf",
		  2,
		  $oldHome, $cgiVars{'dir'},
		  $newHome, $rootDir,
		  '/logs/', '/plugins/java/', '/plugins/search/', '/webpub.conf');
fixDocRoot("$oldHome/config/obj.conf", "$newHome/config/obj.conf");
# backup obj.conf
BinUtil::backupFile($newHome, $sname, "obj.conf");

# copy .clfilter files
BinUtil::copyFile("$oldHome/config/magnus.conf.clfilter", "$newHome/config/magnus.conf.clfilter");
BinUtil::copyFile("$oldHome/config/obj.conf.clfilter", "$newHome/config/obj.conf.clfilter");

# copy mime types
print "Assimilating <CODE>mime.types</CODE>...\n";
BinUtil::copyFile("$oldHome/config/mime.types", "$newHome/config/mime.types");
print "&nbsp;&nbsp;See <CODE>$binDir/install/misc/mime.types</CODE> for any new MIME types.\n";
# backup mime.types
BinUtil::backupFile($newHome, $sname, "mime.types");

# jvm.conf
createJvmConfig();
if ($cgiVars{'version'} ne "3.6") {
    print "&nbsp;&nbsp;<FONT COLOR=\"red\">Warning:</FONT> JVM configuration will be reset to the default.\n";
}

# create java rules/servlets/context.properties files
createProperties();

# call installResources to create res directory under config for java
`$perl $binDir/bin/installResources -r $rootDir -i $sname`;

exit;



sub xlateName {
    my $src = shift;
    my $numXs = shift;
    my @oldName = splice( @_, 0, $numXs );
    my @newName = splice( @_, 0, $numXs );
    my @data = ();
    my $i;

    open(SRC, $src) or die "<FONT COLOR=\"red\">[Error]</FONT> Cannot read $src: $!\n";
    while ($line = <SRC>) {
	for ( $i = 0 ; $i < $numXs ; ++$i ) {
	    if ($line =~ /$oldName[$i]/) {
		$line =~ s/$oldName[$i]/$newName[$i]/;
	    }
	}
	push(@data, $line);
    }
    close(SRC);
    open(DEST, "> $src") or die "<FONT COLOR=\"red\">[Error]</FONT> Cannot edit $src: $!\n";
    print DEST @data;
    close(DEST);
}

sub removeObsoleteDirectives {
    my $file = shift;
    my $obsolete = shift;
    my @data = ();
    my $directive;

    open(FILE, $file) or 
	die "<FONT COLOR=\"red\">[Error]</FONT> Cannot read $file: $!\n";
    while (<FILE>) {
	($directive) = split(/\s/, $_);
	push(@data, $_) unless exists($obsolete->{"$directive"});
    }
    close(FILE);
    open(FILE, "> $file") or 
	die "<FONT COLOR=\"red\">[Error]</FONT> Cannot edit $file: $!\n";
    print FILE @data;
    close(FILE);
}

sub fixDocRoot {
    my $src = shift;
    my $dest = shift;
    my $address;
    my %roots;
    my @data = ();

    # get original document root
    open(SRC, $src) or die "<FONT COLOR=\"red\">[Error]</FONT> Cannot read $src: $!\n";
    while (<SRC>) {
	if (/document-root/) {
	    /address=([\d\.\"]*)/;
	    $address = $1 ? $1 : 'none';
	    if ($cgiVars{'docroot'} eq "new") {
		/^(.*root=)(\S*)(.*)$/;
		$_ = "$1\"$rootDir/docs\" $3\n";
	    }
	    $roots{$address} = $_;
	}
    }
    close(SRC);
    # replace document root
    open(SRC, $dest) or die "<FONT COLOR=\"red\">[Error]</FONT> Cannot read $dest: $!\n";
    while ( <SRC> ) {
	if (/document-root/) {
	    /address=([\d\.\"]*)/;
	    $address = $1 ? $1 : 'none';
	    push(@data, $roots{$address});
	} else {
	    push(@data, $_);
	}
    }
    close(SRC);
    open(SRC, "> $dest") or 
	die "<FONT COLOR=\"red\">[Error]</FONT> Cannot edit $dest: $!\n";
    print SRC @data;
    close(SRC);
}

sub fixObjects {
    my $src = shift;
    my @data = ();
    my $initialized = 0;
    my $gotServletDir = 0;
    my $gotShtml = 0;
    my $gotSSJS = 0;
    my $gotSearch = 0;
    my %warned = ();

    open(SRC, $src) or die "<FONT COLOR=\"red\">[Error]</FONT> Cannot read $src: $!\n";
    while (<SRC>) {
	if (/Init/) {
	    if (!$initialized) {
		# new Init directives to add
		if ($pkgList{'java'}) {
		    push(@data, "Init fn=\"load-modules\" shlib=\"$binDir/");
		    push(@data, "$libLocation/$libPrefix"."NSServletPlugin$libExt\" ");
		    push(@data, "funcs=\"NSServletEarlyInit,NSServletLateInit,NSServletNameTrans,NSServletService\" shlib_flags=\"(global|now)\"\n");
		    push(@data, "Init fn=\"NSServletEarlyInit\" EarlyInit=yes\n");
		    push(@data, "Init fn=\"NSServletLateInit\"  LateInit=yes\n");
		}
		$initialized = 1;
	    } else {
		if (/fn=\"?load-modules\"?/) {
		    # obsolete Init fn="load-modules" directives to discard
		    if (/SJavaBootInit/ || /java-init/ || /java-run/ ||
			/java-find-applet/ || /java-run-applet/ ||
			/ns_agent/ || /agent_name_trans/ ||
			/rdm-init/ || /rdm-type/ || /rdm-service/ || /rdm-log/) {
			next;
		    }
		    # on AIX, library suffixes have changed
		    if ($os =~ /AIX/) {
			# change name from _shr.a to .so
			$_ =~ s/_shr\.a/\.so/;
		    }
		    # Init directives to modify
		    if (/livewireInit/) {
			if ($pkgList{'ssjs'}) {
			    /^(.*shlib=)(\S*)(.*)$/;
			    $_ = "$1\"$libDir/${libPrefix}httpdlw$libExt\" $3\n";
			    $gotSSJS = 1;
			    print "&nbsp;&nbsp;<FONT COLOR=\"red\">Warning:</FONT> Server Side JavaScript applications need to be recompiled and re-registered using the JavaScript Application Manager.\n";
			} else {
			    if (!$warned{'ssjs'}) {
				print "&nbsp;&nbsp;<FONT COLOR=\"red\">Warning:</FONT> Server Side Javascript support has not been enabled.\n";
				$warned{'ssjs'} = 1;
			    }
			    next;
			}
		    }
		    if (!$pkgList{'webpub'} && (/es-search/ || /CM_Init/)) {
			# remove webpub Init directives if not installed
			if (!$warned{'webpub'}) {
			    print "&nbsp;&nbsp;<FONT COLOR=\"red\">Warning:</FONT> Web Publishing support has not been installed.\n";
			    $warned{'webpub'} = 1;
			}
			next;
		    }
		} elsif (/fn=\"?SJavaBootInit\"?/ ||
			 /fn=\"?java-init\"?/ || /fn=\"?java-run\"?/ ||
			 /fn=\"?java-find-applet\"?/ || /fn=\"?java-run-applet\"?/ ||
			 /fn=\"?ns_agentInit\"?/ || /fn=\"?rdm-init\"?/) {
		    # obsolete Init directives to discard
		    if ($pkgList{'java'} && /classpath/) {
			print "&nbsp;&nbsp;<FONT COLOR=\"red\">Warning:</FONT> If you added classes/jars/zips to the classpath directive, they have been discarded. ";
			print "Go to Manage Servers - Servlets - Configure JVM Atrributes to add your application classes. ";
			print "Or edit <CODE>$newHome/config/";
			if ($cgiVars{'javaVersion'} eq "1.2") {
			    print "jvm12.conf ";
			} else {
			    print "jvm.conf ";
			}
			print "</CODE> to define custom class path.\n";
		    }
		    next;
		} elsif (!$pkgList{'webpub'} && (/fn=\"?es-search-init\"?/ || /fn=\"?CM_Init\"?/)) {
		    # remove webpub Init directives if not installed
		    next;
		} elsif (/fn=\"?livewireInit\"?/) {
		    if ($pkgList{'ssjs'}) {
                        print "--> \[$_\]\n";
			if (/LateInit/) {
                            # make sure LateInit="yes"
                            if (!(/LateInit=\"?yes\"?/)) {
                                s/LateInit=\"?(\w*)\"?/LateInit=\"yes\"/;
                            }
			} else {
			    # add LateInit
			    chomp;
			    $_ .= " LateInit=\"yes\"\n";
			}
		    } else {
			# remove SSJS Init directives if not installed
			if (!$warned{'ssjs'}) {
			    print "&nbsp;&nbsp;<FONT COLOR=\"red\">Warning:</FONT> Server Side Javascript support has not been enabled.\n";
			    $warned{'ssjs'} = 1;
			}
		    }
		    next;
		}
	    }
	} elsif (/<.*Object/) {
	    if (/name=\"?default\"?/) {
		# in default object
		push(@data, $_);
		if ($pkgList{'java'}) {
		    push(@data, "NameTrans fn=\"NSServletNameTrans\" name=\"servlet\"\n");
		}
		$passedNameTransStage1 = 0;
		while (<SRC>) {
		    last if (/<\/Object>/);
		    # fix NameTrans directives:
		    if (/NameTrans/) {
			if (!$passedNameTransStage1 && /fn=\"?pfx2dir\"?/) {
			    # just completed assigned name subsection in NameTrans
			    if ($pkgList{'java'} && !$gotServletDir) {
				push(@data, "NameTrans fn=\"pfx2dir\" from=\"/servlet\" dir=\"$rootDir/docs/servlet\" name=\"ServletByExt\"\n");
			    }
			    push(@data, "NameTrans fn=\"pfx2dir\" from=\"/manual\" dir=\"$rootDir/manual/https\" name=\"es-internal\"\n");
			    $passedNameTransStage1 = 1;
			}
			if (/^(.*name=)\"?(servlets)\"?(.*)$/) {
			    if ($pkgList{'java'}) {
				$gotServletDir = 1;
			    } else {
				next;
			    }
			} elsif (!$pkgList{'ssjs'} && /fn=\"?livewireNameTrans\"?/) {
			    # remove the livewireNameTrans
			    next;
			} elsif (/fn=\"?java-find-applet\"?/) {
			    print "&nbsp;&nbsp;<FONT COLOR=\"red\">Warning:</FONT> Server Side Java Applets (HttpApplets) are no longer supported. Use Java Servlets and JSP instead.\n";
			    next;
			} elsif (/fn=\"?agent_name_trans\"?/) {
			    print "&nbsp;&nbsp;<FONT COLOR=\"red\">Warning:</FONT> Agents are no longer supported.\n";
			    next;
			} elsif (/$oldHome\/catalog/) {
			    print "&nbsp;&nbsp;<FONT COLOR=\"red\">Warning:</FONT> AutoCatalog is no longer supported.\n";
			    next;
			} elsif (!$pkgList{'webpub'} && 
				 (/fn=\"?es-search-nametrans\"?/ || /from=\"?\/publisher\"?/ ||
				  /from=\"?\/search-ui\"?/ || /from=\"?\/webpub-ui\"?/)) {
			    next;
			} elsif (/fn=\"?pfx2dir\"?/) {
			    if (/from=\"?\/ns-icons\"?/ || /from=\"?\/mc-icons\"?/ || /from=\"?\/help\"?/) {
				chomp;
				$_ .= " name=\"es-internal\"\n";
			    }
			}
		    } elsif (/^Service/) {
			if (/fn=\"?shtml_send\"?/) {
			    $gotShtml = 1;
			} elsif (/fn=\"?rdm-service\"?/) {
			    # obsolete services to discard
			    next;
			} elsif (!$pkgList{'webpub'} && 
				 (/fn=\"?CM_StopRev\"?/ || /fn=\"?CM_StartRev\"?/ ||
				  /fn=\"?CM_GetPS\"?/ || /fn=\"?CM_GetAttrNames\"?/ ||
				  /fn=\"?CM_GetAttr\"?/ || /fn=\"?CM_SetAttr\"?/ || 
				  /fn=\"?CM_RevNum\"?/ || /fn=\"?CM_RevAdd\"?/ || 
				  /fn=\"?CM_RevLog\"?/ || /fn=\"?CM_RevLabel\"?/ || 
				  /fn=\"?CM_Unlock\"?/ || /fn=\"?CM_Lock\"?/ || 
				  /fn=\"?CM_Save\"?/ || /fn=\"?CM_Unedit\"?/ || 
				  /fn=\"?CM_Edit\"?/ || /fn=\"?CM_Copy\"?/ || 
				  /fn=\"?CM_Post\"?/ || /fn=\"?CM_MkDir\"?/ || 
				  /fn=\"?CM_Move\"?/ || /fn=\"?CM_Put\"?/ || 
				  /fn=\"?CM_Get\"?/ || /fn=\"?CM_Index\"?/ || 
				  /fn=\"?CM_Delete\"?/)) {
			    # remove webpub directives if not installed
			    next;
			}
		    } else {
			# miscellanous obsolete directives to discard
			if (/fn=\"?rdm-type\"?/ || /fn=\"?rdm-log\"?/) {
			    next;
			}
		    }
		    push (@data, $_);
		}
	    } elsif (/name=\"?server-applets\"?/ || /name=\"?servlets\"?/ ||
		     /name=\"?agents\"?/) {
		# old objects to throw out
		while (<SRC>) {
		    last if (/<\/Object>/);
		}
		next;
	    } elsif (/name=\"?ServerSideJS\"?/) {
		if (!$pkgList{'ssjs'}) {
		    # throw out ServerSideJS object if not installed
		    while (<SRC>) {
			last if (/<\/Object>/);
		    }
		    next;
		}
		else {
		    push (@data, $_);
		    # fix up the authentication information if present
		    while (<SRC>) {
			last if (/<\/Object>/);
			if (/AuthTrans/) {
			    s/admin-serv/https-admserv/g;
			}
			push (@data, $_);
		    }
		}
	    } elsif (!$pkgList{'webpub'} &&
		     (/name=\"?search\"?/ || /ppath=\"?.*\/plugins\/content_mgr\/client\"?/)) {
		# throw out webpub objects if not installed
		while (<SRC>) {
		    last if (/<\/Object>/);
		}
		next;
	    }
	} elsif (/Service.*fn=\"?shtml_send\"?/) {
	    $gotShtml = 1;
	}
	push (@data, $_);
    }
    close(SRC);
    if ($pkgList{'java'}) {
	push(@data, "<Object name=\"servlet\">\n");
	push(@data, "ObjectType fn=force-type type=text/html\n");
	push(@data, "Service fn=\"NSServletService\"\n");
	push(@data, "</Object>\n\n");
	push(@data, "<Object name=\"jsp092\">\n");
	push(@data, "ObjectType fn=\"type-by-extension\"\n");
	push(@data, "ObjectType fn=\"change-type\" type=\"magnus-internal/jsp092\" if-type=\"magnus-internal/jsp\"\n");
	push(@data, "Service  fn=\"NSServletService\" type=\"magnus-internal/jsp092\"\n");
	push(@data, "</Object>\n\n");
	push(@data, "<Object name=\"ServletByExt\">\n");
	push(@data, "ObjectType fn=force-type type=magnus-internal/servlet\n");
	push(@data, "Service type=\"magnus-internal/servlet\" fn=\"NSServletService\"\n");
	push(@data, "</Object>\n\n");
    }
    # add es-internal object
    push(@data, "<Object name=\"es-internal\">\n");
    push(@data, "PathCheck fn=\"check-acl\" acl=\"es-internal\"\n");
    push(@data, "</Object>\n");

    # now write it all out
    open(DEST, "> $src") or die "<FONT COLOR=\"red\">[Error]</FONT> Cannot edit $src: $!.\n";
    if ($gotShtml) {
	$initialized = 0;
	foreach $line (@data) {
	    if (!$initialized && /Init/) {
		print DEST "Init funcs=\"shtml_init,shtml_send\" NativeThread=\"no\" ";
		print DEST "shlib=\"$libDir/$libPrefix"."Shtml$libExt\" fn=\"load-modules\"\n";
		print DEST "Init LateInit=\"yes\" fn=\"shtml_init\"\n";
		$initialized = 1;
	    }
	    print DEST $line;
	}
    } else {
	print DEST @data;
    }
    close(DEST);
    if ($gotSSJS) {
	createJsaConfig();
    }
}


sub createJvmConfig {

    my $version = $cgiVars{'javaVersion'};
    my $fileName;
    if ($version eq "1.2") {
	$fileName = "jvm12.conf";
    } else {
	$fileName = "jvm.conf";
    }
    my $filePath = "$newHome/config/$fileName";

    my $beansdir = "$rootDir/plugins/samples/servlets/beans";
    my $newbeansdir = "$rootDir/plugins/samples/servlets/beans.10";
    my $jardir = "$rootDir/bin/https/jar";

    my $javaPathSep;
    if ($isNT) {
	$javaPathSep = ";";
    } else {
	$javaPathSep = ":";
    }

    open(DEST, "> $filePath") or die "<FONT COLOR=\"red\">[Error]</FONT> Cannot edit $filePath: $!.\n";
    print DEST "[JVMConfig]\n";
    if ($version eq "1.2") {
	print DEST "#jvm.minHeapSize=1048576\n";
	print DEST "#jvm.maxHeapSize=16777216\n";
	print DEST "#jvm.enableClassGC=0\n";
	print DEST "#jvm.verboseMode=1\n";
	print DEST "#jvm.enableDebug=1\n";
	print DEST "#jvm.printErrors=0\n";
	print DEST "#jvm.option=-Xrunoii\n";
	print DEST "#jvm.profiler=optimizeit\n";
	print DEST "#jvm.disableThreadRecycling=0\n";
	print DEST "#jvm.serializeAttach=0\n";
	print DEST "#jvm.stickyAttach=0\n";
	print DEST "#jvm.trace=5\n";
	print DEST "#jvm.allowExit=0\n";
	print DEST "#java.compiler=NONE\n";
	print DEST "#OPTITDIR=D:/App/IntuitiveSystems/OptimizeIt30D\n";
	print DEST "#nes.jsp.enabledebug=1\n";
	if ($os =~ /OSF1/) {
	    print DEST "jvm.include.CLASSPATH=0\n";
	    print DEST "nes.jsp.forkjavac=1\n";
	} else {
	    print DEST "#jvm.include.CLASSPATH=1\n";
	    print DEST "#nes.jsp.forkjavac=0\n";
	}
	if ($os =~ /Linux/ || $os =~ /AIX/) {
	    print DEST "jvm.serializeFirstRequest=1\n";
	} else {
	    print DEST "#jvm.serializeFirstRequest=0\n";
	}
	if ($os =~ /Linux/) {
	    print DEST "#jvm.option=-Xrs\n";
	}
    } else {
	print DEST "#jvm.nativeStackSize=131072\n";
	print DEST "#jvm.javaStackSize=409600\n";
	print DEST "#jvm.minHeapSize=1048576\n";
	print DEST "#jvm.maxHeapSize=16777216\n";
	print DEST "#jvm.verifyMode=0\n";
	print DEST "#jvm.enableClassGC=1\n";
	print DEST "#jvm.enableVerboseGC=0\n";
	print DEST "#jvm.disableAsyncGC=0\n";
	print DEST "#jvm.verboseMode=1\n";
	print DEST "#jvm.enableDebug=1\n";
	print DEST "#jvm.printErrors=0\n";
	print DEST "#jvm.debugPort=2525\n";
	print DEST "#jvm.trace=5\n";
	print DEST "#jvm.allowExit=0\n";
	print DEST "#jvm.disableThreadRecycling=0\n";
	print DEST "#nes.jsp.enabledebug=1\n";
	if ($os =~ /HP-UX/) {
	    print DEST "#jvm.serializeFirstRequest=0\n";
	    print DEST "#jvm.include.CLASSPATH=1\n";
	    print DEST "#nes.jsp.forkjavac=0\n";
	    print DEST "#jvm.hpuxJIT=1\n";
	    print DEST "jvm.serializeAttach=1\n";
	    print DEST "jvm.stickyAttach=1\n";
	} else {
	    print DEST "#jvm.serializeAttach=0\n";
	    print DEST "#jvm.stickyAttach=0\n";
	    if ($os =~ /OSF1/) {
	    print DEST "#jvm.serializeFirstRequest=0\n";
		print DEST "jvm.include.CLASSPATH=0\n";
		print DEST "nes.jsp.forkjavac=1\n";
	    } else {
		print DEST "#jvm.include.CLASSPATH=1\n";
		print DEST "#nes.jsp.forkjavac=0\n";
	    }
	    if ($os =~ /Linux/) {
	    print DEST "jvm.option=-Xrs\n";
	    print DEST "jvm.serializeFirstRequest=1\n";
	    } else {
	    print DEST "#jvm.serializeFirstRequest=0\n";
	    }
	}
    }
    if ($isNT) {
        print DEST "#jvm.exitOnAbort=0\n";
    } else {
        print DEST "jvm.exitOnAbort=40\n";
    }
    print DEST "jvm.classpath=$newbeansdir/SDKBeans10.jar$javaPathSep$beansdir/SDKBeans.jar$javaPathSep$jardir/Bugbase.jar$javaPathSep$jardir/Calljsac.jar";
    close(DEST);
    # backup jvm[12].conf
    BinUtil::backupFile($newHome, $sname, $fileName);
}


sub createJsaConfig {

    open(JSA, "> $newHome/config/jsa.conf") or 
	die "<FONT COLOR=\"red\">[Error]</FONT> Cannot edit $newHome/config/jsa.conf: $!\n";
    print JSA "appmgr uri=/appmgr object=\"$rootDir/plugins/samples/js/appmgr/appmgr.web\" ";
    print JSA "home=home.html client-mode=client-cookie maxdbconnect=0\n";
    # bugbase app
    print JSA "bugbase uri=/bugbase object=\"$rootDir/plugins/samples/js/bugbase/bugbase.web\" ";
    print JSA "home=home.html start=start.html client-mode=client-cookie maxdbconnect=0\n";
    # cipher app
    print JSA "cipher uri=/cipher object=\"$rootDir/plugins/samples/js/cipher/cipher.web\" ";
    print JSA "home=cipher.html client-mode=client-cookie maxdbconnect=0\n";
    #dbadmin app
    print JSA "dbadmin uri=/dbadmin object=\"$rootDir/plugins/samples/js/dbadmin/dbadmin.web\" ";
    print JSA "home=home.html client-mode=client-cookie maxdbconnect=1\n";
    # hangman app
    print JSA "hangman uri=/hangman object=\"$rootDir/plugins/samples/js/hangman/hangman.web\" ";
    print JSA "home=hangman.html client-mode=client-cookie maxdbconnect=0\n";
    # jsacRemote app
    print JSA "jsacRemote uri=/jsacRemote object=\"$rootDir/plugins/samples/js/compiler/compiler.web\" ";
    print JSA "home=form.html client-mode=client-cookie maxdbconnect=1\n";
    # metadata app
    print JSA "metadata uri=/VJSmetadata ";
    print JSA "object=\"$rootDir/plugins/samples/js/metadata/metadata3.web\" ";
    print JSA "home=test.html start=initial.html client-mode=client-cookie maxdbconnect=1\n";
    # sendmail app
    print JSA "sendmail uri=/sendmail object=\"$rootDir/plugins/samples/js/mailform/mailform.web\" ";
    print JSA "home=mailform.html client-mode=client-cookie maxdbconnect=0\n";
    # oldvideo app
    print JSA "oldvideo uri=/oldvideo object=\"$rootDir/plugins/samples/js/oldvideo/oldvideo.web\" ";
    print JSA "home=home.htm client-mode=client-cookie maxdbconnect=1\n";
    # videoapp app
    print JSA "videoapp uri=/videoapp object=\"$rootDir/plugins/samples/js/videoapp/videoapp.web\" ";
    print JSA "home=home.htm client-mode=client-cookie maxdbconnect=1\n";
    # hello world app
    print JSA "world uri=/world object=\"$rootDir/plugins/samples/js/world/hello.web\" ";
    print JSA "home=hello.html client-mode=client-cookie maxdbconnect=0\n";
    close(JSA);
    # backup jsa.conf
    BinUtil::backupFile($newHome, $sname, "jsa.conf");
}

sub createProperties {

    # create servlet.properties file in migrated config dir
    open(PS, "> $newHome/config/servlets.properties") or
        die "<FONT COLOR=\"red\">[Error]</FONT> Cannot edit $newHome/config/servlets.properties: $!\n";

    print PS <<__PRINT_UPTO_THIS__;
# \@(#)servlets.properties (autogenerated)
#
# Servlets Properties
#
# servlet.<servlet name>.code=class name (foo or foo.class)
# servlet.<servlet name>.context=name of the context
# servlet.<servlet name>.classpath=the url or path to the directory where classes are located (no backslashes)
#                          or the list of directories (but not urls) or jar files, just like CLASSPATH
# servlet.<servlet name>.initArgs=list of {name, value} pairs which can be accessed
#                          by the servlet using the servlet API calls
# servlet.<servlet_name>.startup=true
#
# For example:
# servlet.wasp.code=WASPServlet
# servlet.wasp.classpath=this is optional
# servlet.wasp.initArgs=initial=0
# servlet.wasp.context=global
# servlet.wasp.startup=true
#
# General properties:
#
# Deprecated (use contexts.properties instead):
# servlets.config.docRoot=E:/Netscape/SuiteSpot/docs (forward slashes only)
# servlets.config.realPathFromRequest=false
# servlets.config.respondCookieVersion=0
# servlets.config.sessionExpireOnClose=false
# servlets.sessionmgr=com.netscape.server.http.session.SimpleSessionManager
# servlets.sessionmgr.initArgs=
# servlets.startup=hello,byebye
 (use servlet startup property instead)# servlets.config.reloadInterval=5
# servlets.config.bufferSize=0
################################# Servlets #############################
__PRINT_UPTO_THIS__
    close(PS);
    BinUtil::backupFile($newHome, $sname, "servlets.properties");

    # create rules.properties file in migrated config dir
    open(PR, "> $newHome/config/rules.properties") or
        die "<FONT COLOR=\"red\">[Error]</FONT> Cannot edit $newHome/config/rules.properties: $!\n";

    print PR <<__PRINT_UPTO_THIS__;
# Servlet rules properties	(autogenerated)
#
# This file specifies the translation rules for invoking servlets.
# The syntax is:
#	<virtual-path>=<servlet-name>
#	or 
#	\@regular_expression=<servlet-name> (use double back-slashes)
#
# where <virtual-path> is the virtual path used to invoke the servlet,
# and <servlet-name> is the name of the servlet. Surrounding white space
# is ignored. The ordering of the rules is not important, as the longest
# match will always be used first. Use of regular expression can lead to
# a heavy peformance penalty
#
# Example:
# /simple=SimpleServlet
# \@.*\\\.foo=wasp
################################# rules ################################
__PRINT_UPTO_THIS__
    close(PR);
    BinUtil::backupFile($newHome, $sname, "rules.properties");

    # create contexts.properties file in migrated config dir
    open(PC, ">$newHome/config/contexts.properties") or
        die "<FONT COLOR=\"red\">[Error]</FONT> Cannot edit $newHome/config/contexts.properties: $!\n";
     
    print PC <<__PRINT_UPTO_THIS__;
# \@(#)contexts.properties (autogenerated)
#
# Contexts Properties:
#
# context.<context_name>.sessionmgr=session manager (some session managers
#				(like MMapSessionManager) can only be instatiated once within the server
# context.<context_name>.sessionmgr.initArgs=list of (name, value) pairs which will
#				represent parameters specific to the session manager
# context.<context_name>.initArgs=list of (name, value) pairs which will be added to
#				this context's attributes
# context.<context_name>.realPathFromRequest=(true|false) tells the server wheather to
#				calculate getRealPath based on docRoot of the context or try to go through
#				normal NSAPI steps
# context.<context_name>.respondCookieVersion=(cookie version) tells the server wheather to
#				respond with specific cookie version
# context.<context_name>.sessionExpireOnClose(true|false) tells the server to mark session
#				cookies as directed to expire when the user quits the browser
# context.<context_name>.includeTransparency=(true|false) tells the server wheather to try
#				to honor setting headers from the included servlet
# context.<context_name>.tempDir=path (forward slashes only) - sets up Servlet API 2.2
#				property for the temporary directory
# context.<context_name>.reloadInterval=seconds - time interval within which the server
#				checks for jsp and servlet files being modified (global context only)
# context.<context_name>.javaBufferSize=bytes (deprecated)
# context.<context_name>.bufferSize=bytes - initial http output stream buffer size
# context.<context_name>.docRoot=path (forward slashes only) - this context document root
#				when not specified - web server's document root will be used (default)
# context.<context_name>.inputStreamLengthCheck=(true|false) - makes ServletInputStream
#				to stop reading data, when Content-Length bytes are read
# context.<context_name>.outputStreamFlushTimer=(seconds|0) - forces the stream to flush
#				the data if certain time elapsed since the last flush; 0 - ignore it
# context.<context_name>.uri=contex_uri_base - additional URI prefix which servces as
#				a context base
# context.<context_name>.host=hostname
# context.<context_name>.ip=ip
# context.<context_name>.authdb=name - authentication database
# context.<context_name>.classpath=name - global classpath for this context
# context.<context_name>.signleClassLoader=(true|false) - tells the servlet engine wheather
#				to use a single class loader for all servlets in the context
# context.<context_name>.serverName=name - server instance name
# context.<context_name>.contentTypeIgnoreFromSSI=(true|false) - ignore setContentType
#				when invoked from SSI
# context.<context_name>.parameterEncoding=(utf8,none,auto) - advises the web server on
#				how to decode parameters from forms
# context.<context_name>.sessionCookie=cookie name- define a name for the session cookie
# context.<context_name>.isModifiedCheckAggressive=(true|false) - determines whether to be
#              aggressively checking dependencies for the servlet loader to reload modified servlets
#
# <context_name>="global" is reserved for the global context. Every new context will inherit
#				initial settings of the global context
#
# Context properties:
# context.global.sessionmgr=com.netscape.server.http.session.SimpleSessionManager
# context.global.sessionmgr.initArgs=
# context.global.initArgs=initial=0
# context.global.realPathFromRequest=false
# context.global.respondCookieVersion=0
# context.global.sessionExpireOnClose=false
# context.global.includeTransparency=true
# context.global.tempDir=/tmp
# context.global.reloadInterval=5
# context.global.javaBufferSize=0
# context.global.bufferSize=4096
# context.global.docRoot=/foo/bar
# context.global.inputStreamLengthCheck=true
# context.global.outputStreamFlushTimer=0
# context.global.uri=/
# context.global.host=
# context.global.ip=
# context.global.authdb=default
# context.global.classpath=
# context.global.singleClassLoader=false
# context.global.contentTypeIgnoreFromSSI=true
# context.global.parameterEncoding=utf8
# context.global.sessionCookie=NSES40Session
# context.global.isModifiedCheckAggressive=false
#
################################# Contexts #############################
__PRINT_UPTO_THIS__
    close(PC);
    BinUtil::backupFile($newHome, $sname, "contexts.properties");
}
#create properties end

