#!/usr/bin/perl

###############################################################################
###############################################################################
# WebAPP - Automated Perl Portal - www.web-app.org                            #
#-----------------------------------------------------------------------------#
# install.cgi	                                                              #
# Last Modified: v0.9.9.9                                                     #
#                                                                             #
# Install to Subfolder by: Abywn (www.abywn.net) and Jos (www.bantychick.com) #
# Date Dropdown Fix by: Anton                                                 #
# Installer Use of ver.txt for version by: Jos                                #
#                                                                             #
#   ###  WebAPP Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008        #
#   ###  M. Carter Brown                                                      #
#   ###  Jocelyn Brown                                                        #
#   ###  Web-APP.org                                                          #
#                                                                             #
#   ### See individual files for more details on copyrights by                #
#   ### contributing developers, per file and per subroutine as noted.        #
#   ### Misrepresentation of the origin of this material is prohibited.       #
#                                                                             #
# This file is part of WebAPP.                                                #
#                                                                             #
# WebAPP 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 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# WebAPP 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 WebAPP; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.               #
#                                                                             #
# File: Modified: 2005 by Jos Brown ("bantychick")                            #
# Modified: 7 June, 19 June, 21 June, 25 June, 18 Aug 2006 by Jos             #
# Modified: 30 Aug, 15 Sept, 2 Oct 2006 by Jos for 0.9.9.4                    #
# Modified: 2007 by Jos for 0.9.9.5 and 0.9.9.6                               #
# Modified: 3 Aug, 19 Sept, 5 Oct 2007 by Jos for 0.9.9.8                     #
# Modified: 2 Apr; 16, 19, 22 May; 6 June by Jos and 8, 18, 23, 30 Apr;       #
# 10, 11, 14, 22, 25 May 2008 by my2cents for 0.9.9.9                         #
###############################################################################
###############################################################################

 # this works in either standard or cgi subfolder directory layout
 # reads folder and file names, renamed or not

use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";

$installscriptname = "WebAPP";
$webappscriptname = "WebAPP - Automated Perl Portal"; # script name

open (VERSION,"./db/ver.txt") || print "cannot open ./db/ver.txt";
chomp($installversion = <VERSION>);
close(VERSION);

# Version Specific Settings ####################################################
$installupdatename = "Requin";
$installbuildnumber = "001";
################################################################################

&getcgi();

if ($input{'action'} eq "config2") {
	&setup_config2;
}

if ($input{'action'} eq "config3") {
	&setup_config3;
}

$scriptpath = "";
$hosturl = "";
$rootpath = "";
$givemail =  "";
$smtpfun = "";
$subdir = "";
$cookiestring = "";
$cookienameuid = "";
$cookienamepwd = "";
$cookienamethm = "";
$cookienamelng = "";
$webappurl  = "";

&getinfo();

&setup_config();

############
sub getcgi {
############

	read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
	@pairs = split(/&/, $input);
	foreach $pair(@pairs) {

		($name, $value) = split(/=/, $pair);
		$name =~ tr/+/ /;
		$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		$input{$name} = $value;
	}
	@vars = split(/&/, $ENV{QUERY_STRING});
	foreach $var(@vars) {
		($v,$i) = split(/=/, $var);
		$v =~ tr/+/ /;
		$v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		$i =~ tr/+/ /;
		$i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		$i =~ s/<!--(.|\n)*-->//g;
		$input{$v} = $i;
	}
}

################
sub chmod_file {
################

	$chmodfailed = "0";
	my ($destination, $permissions) = @_;
	unless(chmod(oct($permissions), $destination)) {
		$chmodfailed = "1";
		print qq~<font color="red" size="4"><b>>>> Cannot set permissions on $destination file!</b></font><br>~;
	}
}

##################
sub setup_config {
##################

	$filename = "./install-saveconfig.cgi";
	if (-e "$filename") {chmod 0755,$filename}

	print qq~<html>
<head>
<title>$installscriptname $installversion - Automated Perl Portal Installer</title>
</head>
<body>
<center><h2><font color="#000070">$installscriptname v$installversion ($installupdatename) Build:$installbuildnumber<br>Automated Perl Portal Installer</font></h2></center>
<p>
<h3><center>Welcome to the $installscriptname v$installversion Installer. This program will ease the Perl installation process and config.pl setup.<br>On most linux servers this information should be <i>almost</i> correct.</center></h3>
<hr>
<br>
<center><h2><font color=red><b>If you do not know your correct path information, please check with your web hosting provider first!</b></h2></font></center>
<hr>
<center><h3>The correct paths should have been generated <b>automatically</b> for you, but please check to see if they are correct!</h3>
<h3>If your images and themes directories are not found at...<br>
<font color="green">http://$hosturl/images/</font>
<br><font color="green">http://$hosturl/themes/</font><br>
...these will have to be changed!</h3></center>
<!-- hr -->
<!-- center --><!-- a href="install-saveconfig.cgi" --><!-- Click Here for Advanced/Upgrade Install --><!-- /a --><!-- br --><!-- (recommended for experienced users only) --><!-- /center -->
<hr>
<center><h3><b><u>Site Setup</u></b></h3></center>
<form action="install.cgi" method="POST">
<input type="hidden" name="action" value="config2">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><b><u>General Settings</u></b></td>
</tr>
<tr>
<td>Pagename</td>
<td><input type="text" name="pagename" value="$hosturl" size="30"></td>
</tr>
<tr>
<td>Pageurl (<b>Change the cgi-bin if you have a different directory</b>)</td>
<td><input type="text" name="pageurl" value="$webappurl" size="80"></td>
</tr>
<tr>
<td>Pagetitle</td>
<td><input type="text" name="pagetitle" value="$hosturl" size="30"></td>
</tr>
<tr>
<td>Script Filename</td>
<td><input type="text" name="cgi" value="index.cgi" size="30"></td>
</tr>
<tr>
<td colspan="2"><hr><b><u>Cookies</u></b>&nbsp;&nbsp;&nbsp;&nbsp;(<b><u>Note:</u></b> If your Pagename is <b>My Site</b> you should name your Cookies - mysiteuid, mysitepwd, mysitethm & mysitelng.<b>)</b></td>
</tr>
<tr>
<td>Username Cookie</td>
<td><input type="text" name="cookieusername" value="$cookienameuid" size="30"></td>
</tr>
<tr>
<td>Password Cookie</td>
<td><input type="text" name="cookiepassword" value="$cookienamepwd" size="30"></td>
</tr>
<tr>
<td>Theme Cookie</td>
<td><input type="text" name="cookieusertheme" value="$cookienamethm" size="30"></td>
</tr>
<tr>
<td>Language Cookie</td>
<td><input type="text" name="cookieuserlang" value="$cookienamelng" size="30"></td>
</tr>
<tr>
<td colspan="2"><hr><b><u>E-Mail Settings</u></b></td>
</tr>
<tr>
<td>Mailer type</td>
<td><select name="mailtype">
<option selected value="0">sendmail</option>
<option value="1">SMTP</option>
</select></td>
</tr>
<tr>
<td>Path to mail program</td>
<td><input type="text" name="mailprogram" value="/usr/sbin/sendmail -t" size="80"></td>
</tr>
<tr>
<td>SMTP-Server</td>
<td><input type="text" name="smtp_server" value="smtp.$smtpfun" size="80"></td>
</tr>
<tr>
<td colspan="2"><hr><b><u>Paths</u></b></td>
</tr>
<tr>
<td>Path to website root directory</td>
<td><input type="text" name="basedir" value="$rootpath" size="80"></td>
</tr>
<tr>
<td>Main URL to website root</td>
<td><input type="text" name="baseurl" value="http://$hosturl" size="80"></td>
</tr>
<tr>
<td>Main script URL to $installscriptname site (<b>Change the cgi-bin if you have a different directory</b>)</td>
<td><input type="text" name="scripturl" value="$webappurl" size="80"></td>
</tr>
<tr>
<td>Path to main script directory</td>
<td><input type="text" name="scriptdir" value="$scriptpath" size="80"></td>
</tr>
<tr>
<td>Path to script sources</td>
<td><input type="text" name="sourcedir" value="$scriptpath/cgi-lib" size="80"></td>
</tr>
<tr>
<td>Path to Perl Modules</td>
<td><input type="text" name="module_dir" value="$scriptpath/modules" size="80"></td>
</tr>
<tr>
<td>Path to data directory</td>
<td><input type="text" name="datadir" value="$scriptpath/db" size="80"></td>
</tr>
<tr>
<td>Path to members directory</td>
<td><input type="text" name="memberdir" value="$scriptpath/db/members" size="80"></td>
</tr>
<tr>
<td>Path to images directory</td>
<td><input type="text" name="imagesdir" value="$rootpath/images" size="80"></td>
</tr>
<tr>
<td>Path to themes directory</td>
<td><input type="text" name="themesdir" value="$rootpath/themes" size="80"></td>
</tr>
<tr>
<td>URL to images directory</td>
<td><input type="text" name="imagesurl" value="http://$hosturl/images" size="80"></td>
</tr>
<tr>
<td>URL to themes directory</td>
<td><input type="text" name="themesurl" value="http://$hosturl/themes" size="80"></td>
</tr>
<tr>
<td>Path to Uploaded Images Directory</td>
<td><input type="text" name="uploaddir" value="$rootpath/images/uploads" size="80"></td>
</tr>
<tr>
<td>URL to Uploaded Images Directory</td>
<td><input type="text" name="uploadurl" value="http://$hosturl/images/uploads" size="80"></td>
</tr>
<tr>
<td>Max Uploaded Image Size (KB)</td>
<td><input type="text" name="maxuploadsize" value="150" size="5"></td>
</tr>
<tr>
<td colspan="2"><hr><b><u>Language Support</u></b></td>
</tr>
<tr>
<td>Language Directory</td>
<td><input type="text" name="lang_dir" value="$scriptpath/lang" size="80"><BR></td>
</tr>
<tr>
<td>Site Language</td>
<td><input type="text" name="backup_lang" value="$scriptpath/lang/english/english.lng" size="80"><BR></td>
</tr>
<tr>
<td>Default Language</td>
<td><input type="text" name="default_lang" value="english.lng" size="30"><BR></td>
</tr>
<tr>
<td colspan="2"><hr><b><u>Contact Info</u></b></td>
</tr>
<tr>
<td>Company Name</td>
<td><input type="text" name="compname" value="$hosturl" size="80"></td>
</tr>
<tr>
<td>Company Address</td>
<td><input type="text" name="compadd" value="5555 Lane" size="80"></td>
</tr>
<tr>
<td>Company City</td>
<td><input type="text" name="compcity" value="Some Town" size="80"></td>
</tr>
<tr>
<td>Company State</td>
<td><input type="text" name="compstate" value="State" size="80"></td>
</tr>
<tr>
<td>Company Zip</td>
<td><input type="text" name="compzip" value="Zip" size="80"></td>
</tr>
<tr>
<td>Company Phone</td>
<td><input type="text" name="compphone" value="Phone" size="80"></td>
</tr>
<tr>
<td>Company Fax</td>
<td><input type="text" name="compfax" value="Fax" size="80"></td>
</tr>
<tr>
<td>Company E-Mail</td>
<td><input type="text" name="compemail" value="Company E-Mail" size="80"></td>
</tr>
<tr>
<td>Webmaster E-Mail</td>
<td><input type="text" name="webmaster_email" value="Webmaster E-Mail" size="80"></td>
</tr>
<tr>
<td colspan="2"><hr><b><u>Articles</u></b></td>
</tr>
<tr>
<td>Path to topics directory</td>
<td><input type="text" name="topicsdir" value="$scriptpath/db/topics" size="80"></td>
</tr>
<tr>
<td colspan="2"><hr><b><u>Forums</u></b></td>
</tr>
<tr>
<td>Path to forums directory</td>
<td><input type="text" name="boardsdir" value="$scriptpath/db/forum" size="80"></td>
</tr>
<tr>
<td>Path to messages directory</td>
<td><input type="text" name="messagedir" value="$scriptpath/db/forum/messages" size="80"></td>
</tr>
<tr>
<td colspan="2"><hr><b><u>Statistics</u></b></td>
</tr>
<tr>
<td>Path to stats directory</td>
<td><input type="text" name="logdir" value="$scriptpath/db/stats" size="80"></td>
</tr>
<tr>
<td colspan="2"><hr><b><u>Links</u></b></td>
</tr>
<tr>
<td>Path to links directory</td>
<td><input type="text" name="linksdir" value="$scriptpath/db/links" size="80"></td>
</tr>
<tr>
<td colspan="2"><hr><b><u>Downloads</u></b></td>
</tr>
<tr>
<td>Path to downloads directory</td>
<td><input type="text" name="downloadsdir" value="$scriptpath/db/downloads" size="80"></td>
</tr>
<tr>
<td colspan="2"><hr><b><u>Other Settings</u></b></td>
</tr>
<tr>
<td>Time Difference</td>
<td><select name="timeoffset">~;

	open (ZONES,"./db/timezones.dat") || print "cannot open ./db/timezones.dat";
	while(<ZONES>){
		chomp;
		@zitem = split(/\|/);

		if (! $zitem[1] && $zitem[0] ne "0") { next; }

		if ($zitem[0] eq "0") {
			print qq~<option value="$zitem[0]" selected>$zitem[1]</option>~;
		} else {
			print qq~<option value="$zitem[0]">$zitem[1]</option>~;
		}
	}
	close (ZONES);

	print qq~</select>~;

	($sec, $min, $hour, $mday, $mon, $year) = (localtime(time))[0..5];
	if ($hour < 10) { $hour = "0" . $hour; }
	if ($min < 10) { $min = "0" . $min; }
	if ($sec < 10) { $sec = "0" . $sec; } 
	$year += 1900;
	if ($mday < 10) { $mday = "0" . $mday; }

	my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
	$currenttime = "$hour:$min:$sec on $mday $months[$mon] $year Server Time"; # get current server time

	print qq~ $currenttime</td>
</tr>
<tr>
<td>Time Zone</td>
<td><select name="timezone">
~;

	open (ZONES,"./db/timezones.dat") || print "cannot open ./db/timezones.dat";

	while(<ZONES>){
		chomp;
		@zitem = split(/\|/);
		if ($zitem[0] eq 0) {
			print qq~<option value="$zitem[0]" selected>$zitem[2] $zitem[3]: $zitem[5]</option>~;
		} else {
			print qq~<option value="$zitem[0]">$zitem[2] $zitem[3]: $zitem[5]</option>~;
		}
	}

	close (ZONES);

	print qq~</select>
</td>
</tr>
<tr>
<td>Date Format</td>
<td><select name="check_date">
<option selected value="american">American (mm/dd/yy)</option>
<option value="european">European (dd/mm/yy)</option>
</select>
</td>
</tr>
<tr>
<td>File Locking</td>
<td><select name="use_flock">
<option selected value="1">On</option>
<option value="0">Off</option>
</select></td>
</tr>
<tr>
<td>LOCK_EX</td>
<td><input type="text" maxlength="2" name="LOCK_EX" value="2" size="1"></td>
</tr>
<tr>
<td>LOCK_UN</td>
<td><input type="text" maxlength="2" name="LOCK_UN" value="8" size="1"></td>
</tr>
<tr>
<td>IIS</td>
<td><select name="IIS">
<option value="0">Auto</option>
<option value="1">IIS</option>
<option selected value="2">Apache</option>
</select></td>
</tr>
<tr>
<td>Server OS</td>
<td><select name="server_os">
<option selected value="linux">Linux</option>
<option value="windows">Windows</option>
</select></td>
</tr>
<tr>
<td colspan="2"><hr></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="Save"></td>
</tr>
</table>
</form>
</body>
</html>
~;

	exit;
}

###################
sub setup_config2 {
###################

	if ($input{'timeoffset'} eq "") {$input{'timeoffset'} = "0";}
	if ($input{'timezone'} eq "") {$input{'timezone'} = "0";}

	%conf=();
	##################
	# General Settings
	##################
	$conf{'page_name'}=$input{'pagename'};
	$conf{'page_url'}=$input{'pageurl'};
	$conf{'page_title'}=$input{'pagetitle'};
	$conf{'cgi'}=$input{'cgi'};
	$conf{'cookieusername'}=$input{'cookieusername'};
	$conf{'cookiepassword'}=$input{'cookiepassword'};
	$conf{'cookieusertheme'}=$input{'cookieusertheme'};
	$conf{'cookieuserlang'}=$input{'cookieuserlang'};
	$conf{'mailtype'}=$input{'mailtype'};
	$conf{'mailprog'}=$input{'mailprogram'};
	$conf{'smtp_server'}=$input{'smtp_server'};
	$conf{'base_dir'}=$input{'basedir'};
	$conf{'base_url'}=$input{'baseurl'};
	$conf{'script_url'}=$input{'scripturl'};
	$conf{'script_dir'}=$input{'scriptdir'};
	$conf{'lib_dir'}=$input{'sourcedir'};
	$conf{'data_dir'}=$input{'datadir'};
	$conf{'member_dir'}=$input{'memberdir'};
	$conf{'images_dir'}=$input{'imagesdir'};
	$conf{'themes_dir'}=$input{'themesdir'};
	$conf{'images_url'}=$input{'imagesurl'};
	$conf{'themes_url'}=$input{'themesurl'};
	$conf{'lang_dir'}=$input{'lang_dir'};
	$conf{'default_lang'}=$input{'default_lang'};
	$conf{'backup_lang'}=$input{'backup_lang'};
	$conf{'tar_loc'}="/bin/tar";
	$conf{'gzip_loc'}="/bin/gzip";
	########################
	# Contact Settings
	########################
	$conf{'compname'}=$input{'compname'};
	$conf{'compadd'}=$input{'compadd'};
	$conf{'compcity'}=$input{'compcity'};
	$conf{'compstate'}=$input{'compstate'};
	$conf{'compzip'}=$input{'compzip'};
	$conf{'compphone'}=$input{'compphone'};
	$conf{'compfax'}=$input{'compfax'};
	$conf{'compemail'}=$input{'compemail'};
	$conf{'webmaster_email'}=$input{'webmaster_email'};
	########################
	# IM Settings
	########################
	$conf{'bmheadercolor'}="#000070";
	$conf{'bmbgcolor'}="#FFFFFF";
	$conf{'welcome_im'}="1";
	$conf{'newuser_im'}="1";
	$conf{'article_im'}="1";
	########################
	# Information Settings
	########################
	$conf{'image1'}="$input{'imagesurl'}/perl.gif";
	$conf{'link1'}="http://www.perlmonks.com/";
	$conf{'image2'}="$input{'imagesurl'}/gnugpl.png";
	$conf{'link2'}="http://www.gnu.org/copyleft/gpl.html";
	$conf{'image3'}="$input{'imagesurl'}/webapp.gif";
	$conf{'link3'}="http://www.web-app.org/";
	########################
	# News Specific Settings
	########################
	$conf{'topic_dir'}=$input{'topicsdir'};
	$conf{'maxnews'}="5";
	$conf{'maxtopics'}="25";
	$conf{'enable_userarticles'}="1";
	$conf{'allow_html'}="1";
	$conf{'enable_topicguestposting'}="0";
	$conf{'enable_autopublish'}="1";
	$conf{'article_imrecip'}="admin";
	$conf{'topicimgupld'}="1";
	$conf{'allowcomments'}="1";
	##########################
	# Forums Specific Settings
	##########################
	$conf{'forum_dir'}=$input{'boardsdir'};
	$conf{'message_dir'}=$input{'messagedir'};
	$conf{'enable_guestposting'}="0";
	$conf{'enable_notification'}="1";
	$conf{'maxdisplay'}="25";
	$conf{'maxmessagedisplay'}="15";
	$conf{'insert_original'}="1";
	$conf{'max_log_days_old'}="21";
	$conf{'forumimgupld'}="1";
	$conf{'imagebuttons'}="1";
	$conf{'show_foruminfo'}="0";
	$conf{'showlisttoguests'}="0";
	$conf{'show_forumtop5'}="0";
	#########################
	# Smilies/UBBC Settings
	#########################
	$conf{'enable_ubbc'}="1";
	$conf{'enable_smile'}="1";
	$conf{'imageicons'}="0";
	#########################
	# Stats Specific Settings
	#########################
	$conf{'log_dir'}=$input{'logdir'};
	$conf{'ip_time'}="0";
	$conf{'top_browsers'}="1";
	$conf{'top_os'}="1";
	$conf{'nologcache'}="0";
	#########################
	# Links Specific Settings
	#########################
	$conf{'links_dir'}=$input{'linksdir'};
	$conf{'maxlinks'}="30";
	$conf{'adminonlyl'}="1";
	$conf{'showlatestlinks'}="1";
	#########################
	# Downloads Specific Settings
	#########################
	$conf{'download_dir'}=$input{'downloadsdir'};
	$conf{'maxdownloads'}="30";
	$conf{'antileech'}="1";
	$conf{'adminonlyd'}="1";
	$conf{'showlatestdownloads'}="1";
	############################
	# Admin Assistant Settings
	############################
	$conf{'dispmost'}="1";
	$conf{'dispstat'}="0";
	$conf{'infoblockmod'}="1";
	$conf{'dispfrad'}="1";
	$conf{'showcon'}="1";
	$conf{'showcon2'}="1";
	$conf{'hidemail'}="1";
	$conf{'letmemdel'}="0";
	$conf{'letmemlng'}="1";
	$conf{'letmemthm'}="1";
	$conf{'searchmod'}="1";
	$conf{'hidememlist'}="0";
	$conf{'maxmembersdisplay'}="30";
	$conf{'modulecal'}="0";
	$conf{'modulenl'}="1";
	$conf{'pollmod'}="1";
	$conf{'multiplevoting'}="0";
	$conf{'modulenlmem'}="0";
	$conf{'botkiller'}="0";
	$conf{'signupmethod'}="0";
	$conf{'timezone'}=$input{'timezone'};
	$conf{'defaulttheme'}="standard";
	$conf{'check_date'}=$input{'check_date'};
	$conf{'galleryon'}="1";
	$conf{'showavatars'}="1";
	$conf{'guestpostpoll'}="0";
	$conf{'notifycomment'}="1";
	$conf{'enable_membersonly'}="0";
	$conf{'showwelcome'}="1";
	$conf{'showsecalert'}="1";
	$conf{'max_size'}="275";

	################
	# Admin Access
	################
	$conf{'editwelc'}="0";
	$conf{'editabout'}="0";
	$conf{'editim'}="0";
	$conf{'editbanner'}="0";
	$conf{'editfaq'}="0";
	$conf{'editdown'}="0";
	$conf{'editlink'}="0";
	$conf{'modadmin'}="0";
	$conf{'editcats'}="1";
	$conf{'editboards'}="1";
	$conf{'editcensor'}="1";
	$conf{'editpoll'}="1";
	$conf{'pubnews'}="1";
	$conf{'editnews'}="1";
	$conf{'editshow'}="0";
	$conf{'editmenuman'}="0";
	$conf{'editnewusers'}="0";
	$conf{'edituserranks'}="0";
	$conf{'edituserstat'}="0";
	$conf{'editprodata'}="0";
	$conf{'editeula'}="0";
	$conf{'edittops'}="0";
	$conf{'editlblk'}="0";
	$conf{'editrblk'}="0";
	$conf{'edittblk'}="0";
	$conf{'editbtmblk'}="0";
	$conf{'editfpage'}="0";
	$conf{'editcolumns'}="0";
	$conf{'editcal'}="0";
	$conf{'editnl'}="0";
	$conf{'editip'}="1";
	################
	# Other Settings
	################
	$conf{'timeoffset'}=$input{'timeoffset'};
	$conf{'memberpic_height'}="0";
	$conf{'memberpic_width'}="60";
	$conf{'maxuploadsize'}=$input{'maxuploadsize'};
	$conf{'rows'}="10";
	$conf{'cols'}="40";
	$conf{'hotreplycnt'}="25";
	$conf{'vhotreplycnt'}="50";
	$conf{'hotviewcnt'}="200";
	$conf{'vhotviewcnt'}="300";
	$conf{'upload_url'}=$input{'uploadurl'};
	$conf{'upload_dir'}=$input{'uploaddir'};
	$conf{'use_flock'}=$input{'use_flock'};
	$conf{'LOCK_EX'}=$input{'LOCK_EX'};
	$conf{'LOCK_UN'}=$input{'LOCK_UN'};
	$conf{'IIS'}=$input{'IIS'};
	$conf{'server_os'}=$input{'server_os'};

	##################
	# Captcha Settings
	##################
	$conf{'ablevisual'}="yes";
	$conf{'allownorefer'}="no";
	$conf{'allowgrec'}="yes";
	$conf{'limitadminip'}="";

	################
	# Module Paths
	################
	$conf{'poll_dir'}="$input{'datadir'}/polls";
	$conf{'newsletter_dir'}="$input{'datadir'}/newsletter";
	$conf{'module_dir'}=$input{'module_dir'};
	
	################
	# Mods Paths
	################
	$conf{'mods_dir'}="$input{'scriptdir'}/mods";
	$conf{'mods_url'}="$input{'scripturl'}/mods";
	################
	# Misc Paths
	################
	$conf{'user_lib'}="$input{'scriptdir'}/user-lib";
	$conf{'upgrade_lib'}="$input{'scriptdir'}/upgrade-lib";
	################
	# WebAPP Settings
	################
	$conf{'scriptname'}=$webappscriptname;
	$conf{'updatever'}=$installupdatename;
	$conf{'scriptbuildnumber'}=$installbuildnumber;
	$conf{'web_dir'}=$input{'basedir'};

	# Define the Location of the config.dat File ###################################
	$filename="$input{'scriptdir'}/conf/config.dat";
	$config_dir = "$input{'scriptdir'}/conf";
	$config_script = "$input{'scriptdir'}/config.pl";

 # Write the config.dat File ####################################################
	open OTF,">$filename" or die ("Could not open $filename!");
	foreach $thing (keys %conf) {
		print OTF "$thing|$conf{$thing}\n";
	}
	close OTF;

 # Write config.pl ############################################################

 	open FILE,">$config_script" or die ("Could not open $config_script!");

	print FILE qq~###############################################################################
###############################################################################
# $webappscriptname - www.web-app.org                            #
#-----------------------------------------------------------------------------#
# config.pl                                                                   #
# v$installversion                                                            #
# Last Modified: WebAPP Version 0.9.9.9                                       #
#                                                                             #
# Security Patch by Big R                                                     #
# Patching System by Floyd                                                    #
#                                                                             #
#   ###  WebAPP Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008        #
#   ###  M. Carter Brown                                                      #
#   ###  Jocelyn Brown                                                        #
#   ###  Web-APP.org                                                          #
#                                                                             #
#   ### See individual files for more details on copyrights by                #
#   ### contributing developers, per file and per subroutine as noted.        #
#   ### Misrepresentation of the origin of this material is prohibited.       #
#                                                                             #
# This file is part of WebAPP.                                                #
#                                                                             #
# WebAPP 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 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# WebAPP 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 WebAPP; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.               #
###############################################################################
###############################################################################

use strict;

use vars qw(\$config_dir \$pagename \$pagetitle \$cookieusername \$cookiepassword
 \$cookieusertheme \$cookieuserlang \$mailtype \$mailprogram \$smtp_server \$basedir \$baseurl
 \$scripturl \$datadir \$memberdir \$imagesdir \$themesdir \$imagesurl \$themesurl \$language
 \$langdir \$lang \$compname \$compadd \$compcity \$compstate \$compzip \$compphone \$compfax
 \$compemail \$webmaster_email \$bmheadercolor \$bmbgcolor \$welcome_im \$newuser_im
 \$article_im \$image1 \$link1 \$image2 \$link2 \$image3 \$link3 \$topicsdir \$maxnews \$maxtopics
 \$enable_userarticles \$allow_html \$enable_topicguestposting \$enable_autopublish
 \$article_imrecip \$topicimgupld \$boardsdir \$messagedir \$enable_guestposting
 \$enable_notification \$maxdisplay \$maxmessagedisplay \$insert_original \$max_log_days_old
 \$forumimgupld \$enable_ubbc \$enable_smile \$imageicons \$logdir \$ip_time \$top_browsers
 \$top_os \$linksdir \$maxlinks \$adminonlyl \$showlatestlinks \$downloadsdir \$maxdownloads
 \$antileech \$adminonlyd \$showlatestdownloads \$dispmost \$dispstat \$infoblockmod \$dispfrad
 \$showcon \$showcon2 \$hidemail \$letmemdel \$letmemlng \$letmemthm \$searchmod \$hidememlist
 \$maxmembersdisplay \$modulecal \$modulenl \$pollmod \$multiplevoting \$modulenlmem \$botkiller
 \$signupmethod \$timezone \$defaulttheme \$check_date \$editwelc \$editabout \$editim
 \$editbanner \$editfaq \$editdown \$editlink \$modadmin \$editcats \$editboards \$editcensor
 \$editpoll \$pubnews \$editnews \$edittops \$editlblk \$editrblk \$edittblk \$editbtmblk
 \$editcal \$editnl \$editip \$timeoffset \$memberpic_height \$memberpic_width \$maxuploadsize
 \$uploaddir \$uploadurl \$use_flock \$LOCK_EX \$LOCK_UN \$IIS \$server_os \$poll_dir
 \$newsletter_dir \$mods_dir \$mods_url \$user_lib \$upgrade_lib \$updatever \$scriptbuildnumber
 \$web_dir \$galleryon \$showavatars \$guestpostpoll \$notifycomment \$enable_membersonly \$imagebuttons
 \$nologcache \$showwelcome \$rows \$cols \$allowcomments \$show_foruminfo \$showlisttoguests
 \$show_forumtop5 \$hotreplycnt \$vhotreplycnt \$hotviewcnt \$vhotviewcnt \$tar_loc \$gzip_loc
 \$editfpage \$editcolumns \$editshow \$editmenuman \$editnewusers \$edituserranks \$edituserstat
 \$editprodata \$editeula \$ablevisual \$allownorefer \$allowgrec \$limitadminip \$showsecalert \$max_size);
use vars qw(\$pageurl \$cgi \$sourcedir \$moduledir \$scriptdir \$scriptname \$adminurl);

\$config_dir='$config_dir';

loadConfig();

################
sub loadConfig {
################

	my \%waconf=();
	my \$next='';
	my \$key='';
	my \$val='';
	my \$conf_file="\$config_dir/config.dat";
	open INCFG,"<\$conf_file" or die ("Could not open \$conf_file\\n");
	while (\$next=<INCFG>) {
		chomp \$next;
		(\$key,\$val)=split(/\\|/,\$next);
		\$waconf{\$key}=\$val;
	}
	close INCFG;
	&exportConfig(\\%waconf);

}

##################
sub exportConfig {
##################

	my \$cref=shift;
	##################
	# General Settings
	##################
	\$pagename = \$\$cref{'page_name'};
	\$pageurl = \$\$cref{'page_url'};
	\$pagetitle = \$\$cref{'page_title'};

	\$cgi=\$\$cref{'cgi'};

	\$cookieusername = \$\$cref{'cookieusername'};
	\$cookiepassword = \$\$cref{'cookiepassword'};
	\$cookieusertheme = \$\$cref{'cookieusertheme'};
	\$cookieuserlang = \$\$cref{'cookieuserlang'};

	\$mailtype = \$\$cref{'mailtype'};
	\$mailprogram = \$\$cref{'mailprog'};
	\$smtp_server =  \$\$cref{'smtp_server'};

	\$basedir   = \$\$cref{'base_dir'};
	\$baseurl   = \$\$cref{'base_url'};
	\$scriptdir = \$\$cref{'script_dir'};
	\$scripturl = \$\$cref{'script_url'};
	\$sourcedir = \$\$cref{'lib_dir'};
	\$datadir   = \$\$cref{'data_dir'};
	\$memberdir = \$\$cref{'member_dir'};

	\$imagesdir = \$\$cref{'images_dir'};
	\$themesdir = \$\$cref{'themes_dir'};
	\$imagesurl = \$\$cref{'images_url'};
	\$themesurl = \$\$cref{'themes_url'};

	\$language = \$\$cref{'default_lang'};
	\$langdir = \$\$cref{'lang_dir'};
	\$lang = \$\$cref{'backup_lang'};

	\$tar_loc = \$\$cref{'tar_loc'};
	\$gzip_loc = \$\$cref{'gzip_loc'};

	##################
	# Contact Settings
	##################
	\$compname = \$\$cref{'compname'};
	\$compadd = \$\$cref{'compadd'};
	\$compcity = \$\$cref{'compcity'};
	\$compstate = \$\$cref{'compstate'};
	\$compzip = \$\$cref{'compzip'};
	\$compphone = \$\$cref{'compphone'};
	\$compfax = \$\$cref{'compfax'};
	\$compemail = \$\$cref{'compemail'};
	\$webmaster_email = \$\$cref{'webmaster_email'};

	#############
	# IM Settings
	#############
	\$bmheadercolor = \$\$cref{'bmheadercolor'};
	\$bmbgcolor = \$\$cref{'bmbgcolor'};
	\$welcome_im = \$\$cref{'welcome_im'};
	\$newuser_im = \$\$cref{'newuser_im'};
	\$article_im = \$\$cref{'article_im'};

	######################
	# Information Settings
	######################
	\$image1 = \$\$cref{'image1'};
	\$link1 = \$\$cref{'link1'};
	\$image2 = \$\$cref{'image2'};
	\$link2 = \$\$cref{'link2'};
	\$image3 = \$\$cref{'image3'};
	\$link3 = \$\$cref{'link3'};

	########################
	# News Specific Settings
	########################
	\$topicsdir = \$\$cref{'topic_dir'};
	\$maxnews = \$\$cref{'maxnews'};
	\$maxtopics = \$\$cref{'maxtopics'};
	\$enable_userarticles = \$\$cref{'enable_userarticles'};
	\$allow_html = \$\$cref{'allow_html'};
	\$enable_topicguestposting = \$\$cref{'enable_topicguestposting'};
	\$enable_autopublish = \$\$cref{'enable_autopublish'};
	\$article_imrecip = \$\$cref{'article_imrecip'};
	\$topicimgupld = \$\$cref{'topicimgupld'};
	\$allowcomments = \$\$cref{'allowcomments'};

	##########################
	# Forums Specific Settings
	##########################
	\$boardsdir = \$\$cref{'forum_dir'};
	\$messagedir = \$\$cref{'message_dir'};
	\$enable_guestposting = \$\$cref{'enable_guestposting'};
	\$enable_notification = \$\$cref{'enable_notification'};
	\$maxdisplay = \$\$cref{'maxdisplay'};
	\$maxmessagedisplay = \$\$cref{'maxmessagedisplay'};
	\$insert_original = \$\$cref{'insert_original'};
	\$max_log_days_old = \$\$cref{'max_log_days_old'};
	\$forumimgupld = \$\$cref{'forumimgupld'};
	\$imagebuttons = \$\$cref{'imagebuttons'};
	\$show_foruminfo = \$\$cref{'show_foruminfo'};
	\$showlisttoguests = \$\$cref{'showlisttoguests'};
	\$show_forumtop5 = \$\$cref{'show_forumtop5'};

	#######################
	# Smilies/UBBC Settings
	#######################
	\$enable_ubbc = \$\$cref{'enable_ubbc'};
	\$enable_smile = \$\$cref{'enable_smile'};
	\$imageicons = \$\$cref{'imageicons'};

	#########################
	# Stats Specific Settings
	#########################
	\$logdir = \$\$cref{'log_dir'};
	\$ip_time = \$\$cref{'ip_time'};
	\$top_browsers = \$\$cref{'top_browsers'};
	\$top_os = \$\$cref{'top_os'};
	\$nologcache = \$\$cref{'nologcache'};

	#########################
	# Links Specific Settings
	#########################
	\$linksdir = \$\$cref{'links_dir'};
	\$maxlinks = \$\$cref{'maxlinks'};
	\$adminonlyl = \$\$cref{'adminonlyl'};
	\$showlatestlinks = \$\$cref{'showlatestlinks'};

	#############################
	# Downloads Specific Settings
	#############################
	\$downloadsdir = \$\$cref{'download_dir'};
	\$maxdownloads = \$\$cref{'maxdownloads'};
	\$antileech = \$\$cref{'antileech'};
	\$adminonlyd = \$\$cref{'adminonlyd'};
	\$showlatestdownloads = \$\$cref{'showlatestdownloads'};

	##########################
	# Admin Assistant Settings
	##########################
	\$dispmost = \$\$cref{'dispmost'};
	\$dispstat = \$\$cref{'dispstat'};
	\$infoblockmod = \$\$cref{'infoblockmod'};
	\$dispfrad = \$\$cref{'dispfrad'};
	\$showcon = \$\$cref{'showcon'};
	\$showcon2 = \$\$cref{'showcon2'};
	\$hidemail = \$\$cref{'hidemail'};
	\$letmemdel = \$\$cref{'letmemdel'};
	\$letmemlng = \$\$cref{'letmemlng'};
	\$letmemthm = \$\$cref{'letmemthm'};
	\$searchmod = \$\$cref{'searchmod'};
	\$hidememlist = \$\$cref{'hidememlist'};
	\$maxmembersdisplay = \$\$cref{'maxmembersdisplay'};
	\$modulecal = \$\$cref{'modulecal'};
	\$modulenl = \$\$cref{'modulenl'};
	\$pollmod = \$\$cref{'pollmod'};
	\$multiplevoting = \$\$cref{'multiplevoting'};
	\$modulenlmem = \$\$cref{'modulenlmem'};
	\$botkiller = \$\$cref{'botkiller'};
	\$signupmethod = \$\$cref{'signupmethod'};
	\$timezone = \$\$cref{'timezone'};
	\$defaulttheme = \$\$cref{'defaulttheme'};
	\$check_date = \$\$cref{'check_date'};
	\$galleryon = \$\$cref{'galleryon'};
	\$showavatars = \$\$cref{'showavatars'};
	\$guestpostpoll = \$\$cref{'guestpostpoll'};
	\$notifycomment = \$\$cref{'notifycomment'};
	\$enable_membersonly = \$\$cref{'enable_membersonly'};
	\$showwelcome = \$\$cref{'showwelcome'};
	\$showsecalert = \$\$cref{'showsecalert'};
	\$max_size = \$\$cref{'max_size'};

	##############
	# Admin Access
	##############
	\$editwelc = \$\$cref{'editwelc'};
	\$editabout = \$\$cref{'editabout'};
	\$editim = \$\$cref{'editim'};
	\$editbanner = \$\$cref{'editbanner'};
	\$editfaq = \$\$cref{'editfaq'};
	\$editdown = \$\$cref{'editdown'};
	\$editlink = \$\$cref{'editlink'};
	\$modadmin = \$\$cref{'modadmin'};
	\$editcats = \$\$cref{'editcats'};
	\$editboards = \$\$cref{'editboards'};
	\$editcensor = \$\$cref{'editcensor'};
	\$editpoll = \$\$cref{'editpoll'};
	\$pubnews = \$\$cref{'pubnews'};
	\$editnews = \$\$cref{'editnews'};
	\$editshow = \$\$cref{'editshow'};
	\$editmenuman = \$\$cref{'editmenuman'};
	\$editnewusers = \$\$cref{'editnewusers'};
	\$edituserranks = \$\$cref{'edituserranks'};
	\$edituserstat = \$\$cref{'edituserstat'};
	\$editprodata = \$\$cref{'editprodata'};
	\$editeula = \$\$cref{'editeula'};
	\$edittops = \$\$cref{'edittops'};
	\$editlblk = \$\$cref{'editlblk'};
	\$editrblk = \$\$cref{'editrblk'};
	\$edittblk = \$\$cref{'edittblk'};
	\$editbtmblk = \$\$cref{'editbtmblk'};
	\$editfpage = \$\$cref{'editfpage'};
	\$editcolumns = \$\$cref{'editcolumns'};
	\$editcal = \$\$cref{'editcal'};
	\$editnl = \$\$cref{'editnl'};
	\$editip = \$\$cref{'editip'};

	################
	# Other Settings
	################
	\$timeoffset = \$\$cref{'timeoffset'};
	\$memberpic_height = \$\$cref{'memberpic_height'};
	\$memberpic_width = \$\$cref{'memberpic_width'};
	\$maxuploadsize = \$\$cref{'maxuploadsize'};
	\$rows = \$\$cref{'rows'};
	\$cols = \$\$cref{'cols'};
	\$hotreplycnt = \$\$cref{'hotreplycnt'};
	\$vhotreplycnt = \$\$cref{'vhotreplycnt'};
	\$hotviewcnt = \$\$cref{'hotviewcnt'};
	\$vhotviewcnt = \$\$cref{'vhotviewcnt'};
	\$uploaddir = \$\$cref{'upload_dir'};
	\$uploadurl = \$\$cref{'upload_url'};
	\$use_flock = \$\$cref{'use_flock'};
	\$LOCK_EX = \$\$cref{'LOCK_EX'};
	\$LOCK_UN = \$\$cref{'LOCK_UN'};
	\$IIS =  \$\$cref{'IIS'};
	\$server_os =  \$\$cref{'server_os'};

	##################
	# Captcha Settings
	##################
	\$ablevisual = \$\$cref{'ablevisual'};
	\$allownorefer = \$\$cref{'allownorefer'};
	\$allowgrec = \$\$cref{'allowgrec'};
	\$limitadminip = \$\$cref{'limitadminip'};

	##############
	# Module Paths
	##############
	\$poll_dir = \$\$cref{'poll_dir'};
	\$newsletter_dir =  \$\$cref{'newsletter_dir'};
	\$moduledir = \$\$cref{'module_dir'};

	############
	# Mods Paths
	############
	\$mods_dir = \$\$cref{'mods_dir'};
	\$mods_url =  \$\$cref{'mods_url'};

	############
	# Misc Paths
	############
	\$user_lib = \$\$cref{'user_lib'};
	\$upgrade_lib =  \$\$cref{'upgrade_lib'};

	#################
	# WebAPP Settings
	#################
	\$scriptname = \$\$cref{'scriptname'};
	\$updatever = \$\$cref{'updatever'};
	\$scriptbuildnumber = \$\$cref{'scriptbuildnumber'};
	\$web_dir = \$\$cref{'web_dir'};

	\$adminurl = "\$scripturl/admin/siteadmin.cgi";

}

1; #return true
~;

	close(FILE);

 # Write calendar.cfg: ############################################################

	$input{'webmaster_email'} =~ s/\@/\\@/;

	open(DATA, ">./mods/calendar/data/calendar.cfg");

	print DATA qq~

	#---------------------------------
	# General Settings
	#---------------------------------
	\$cm_title                    = "Calendar";
	\$cm_requireAdminApproval     =  1;
	\$cm_emailAdminNewEventNotice =  1;
	\$cm_eventAdminEmailAddress   = "$input{'webmaster_email'}";

	#---------------------------------
	# Paths & Files
	#---------------------------------~;
	print DATA qq~
	\$cm_scriptDir           = "$input{'scriptdir'}";
	\$cm_dataDir             = "$input{'datadir'}/calendar";
	\$cm_langDir             = "$input{'lang_dir'}";
	\$cm_scriptUrl           = "$input{'scripturl'}/$input{'cgi'}?action=calendar";
	\$cm_adminScriptUrl      = "$input{'scripturl'}/admin/caladmin.cgi";
	\$cm_eventsFileName      = "calendar.dat";
	\$cm_langFileName        = "calendar.lng";
	\$cm_detailIconUrl       = "$input{'imagesurl'}/calendar/calendar.gif";

	#---------------------------------
	# Database Settings
	#---------------------------------
	\$cm_delimiter           = "	";
	\$cm_useFileLocking      =  1;

	#---------------------------------
	# Style Elements
	#---------------------------------
	# Sidebar Calendar
	#---------------------------------
	\$cmsb_cellSize          = "16";
	\$cmsb_borderWidth       = "0";
	\$cmsb_borderStyle       = "padding: 2px";
	\$cmsb_headFontStyle     = "text-align: center";
	\$cmsb_dayHeadFontStyle  = "font-size: 11px";
	\$cmsb_dayHeadCellStyle  = "text-align: center";
	\$cmsb_selFontStyle      = "font-size: 10px";
	\$cmsb_selCellStyle      = "font-weight:bold; background-color:#94a5e7";
	\$cmsb_stdFontStyle      = "font-size: 10px";
	\$cmsb_stdCellStyle      = "";
	\$cmsb_emptyCellStyle    = "font-size: 10px";

	#---------------------------------
	# Large Calendar (show detail)
	#---------------------------------
	\$cml_cellSize           = "60";
	\$cml_borderWidth        = "1";
	\$cml_borderStyle        = "padding: 2px";

	#---------------------------------
	# Small Calendar (hide detail)
	#---------------------------------
	\$cms_cellSize           = "30";
	\$cms_borderWidth        = "1";
	\$cms_borderStyle        = "padding: 2px";

	#---------------------------------
	# Large & Small Calendars
	#---------------------------------
	\$cm_headFontStyle       = "";
	\$cm_dayHeadFontStyle    = "";
	\$cm_dayHeadCellStyle    = "";
	\$cm_selFontStyle        = "";
	\$cm_selCellStyle        = "background-color:#ffffcc";
	\$cm_stdFontStyle        = "";
	\$cm_stdCellStyle        = "";
	\$cm_todayFontStyle      = "color: red; font-weight: bold";
	\$cm_emptyCellStyle      = "";

	1; #return true
~;

	close(DATA);

	$indexfile = "$input{'cgi'}";

	print qq~
<html>
<title>$installscriptname v$installversion - Automated Perl Portal Installer</title>
<body>
<form action="install.cgi">
<input type="hidden" name="action" value="config3">
<p><font color="green" size="4"><b>>>> Configuration Updated!!!</font></p>
~;

	chmod_file("$indexfile", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> $indexfile permissions set</b><br></font> ~;
	}

	chmod_file("captcha.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> captcha.cgi permissions set</b><br></font> ~;
	}

	chmod_file("tagbox.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> tagbox.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/banners.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/banners.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/blockleft.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/blockleft.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/blockright.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/blockright.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/blocktop.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/blocktop.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/blockbottom.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/blockbottom.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/downloadadmin.cgi", "0755");
	if ($chmodfailed ne "1") {
	print qq~<font color="green" size="4"><b>>>> /admin/downloadadmin.cgi permissions set</b><br></font> ~;}

	chmod_file("./admin/help.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/help.cgi permissions set</b><br></font>~;
	}

	chmod_file("./admin/language.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/language.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/linksadmin.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/linksadmin.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/siteadmin.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/siteadmin.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/showhtml.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/showhtml.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/prodata.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/prodata.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/themes.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/themes/*.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/menuman.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/menuman.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/columnadmin.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/columnadmin.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/frontpage.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/frontpage.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./scripts/upload.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /scripts/upload.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./scripts/galupload.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /scripts/galupload.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./mods/modmanager.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /mods/modmanager.cgi permissions set</b><br></font> ~;
	}

	chmod_file("./admin/caladmin.cgi", "0755");
	if ($chmodfailed ne "1") {
		print qq~<font color="green" size="4"><b>>>> /admin/caladmin.cgi permissions set</b><br></font> ~;
	}

	print qq~<hr>
<br>
First, was the installation successful?  <a href="./$indexfile" target="_blank">Click Here to See</a>.<br>
<br>
<b>If everything is correct:<br> <font color="red"> Remove the "install.cgi" file</font> from your /cgi-bin/ folder by clicking the submit button below!</b><br><br>
Make sure that the attributes (chmod) is set correctly:<br>
>>> $indexfile >>> chmod 755<br>
Also, make sure that you have the correct path information from your web hosting provider!<br><br>
<hr>
<br>
<b>click the button below to edit your "index.html" file </b>to reflect your new site.  Install.cgi will automatically be deleted after hitting "submit".<br><br>
<br><center>
<table>
<tr>
<td align="center" colspan="2">~;

	print qq~<input type="hidden" name="baseurl" value="$input{'baseurl'}">
<input type="hidden" name="basedir" value="$input{'basedir'}">
<input type="hidden" name="pagetitle" value="$input{'pagetitle'}">
<input type="hidden" name="pageurl" value="$input{'pageurl'}">
<input type="hidden" name="cgi" value="$indexfile">
<input type="submit" value="Submit"></td>
</tr>
</table>
</form></center>
</body>
</html>
~;

	exit;

}

###################
sub setup_config3 {
###################

	$indexfile = "$input{'cgi'}";

	open(FILE, ">$input{'basedir'}/index.html");

	print FILE
qq~<html>
<head>
<title>$input{'pagetitle'}</title>
<META NAME="revisit" CONTENT="12 days">
<meta NAME="Robot" CONTENT="allow">
</head>
<body>
<script language="javascript">window.location="$input{'pageurl'}/$indexfile";</script>
Click <a href="$input{'pageurl'}/$indexfile">here</a> to enter site<br>
</body>
</html>
~;

	close(FILE);

	print qq~<html>
<title>Finished $installscriptname Installation!
</title>
<body>
<br>
>>> index.html edited<br><br>
>>> Finished Installation!<br><br>
Follow the link <a href="./$indexfile">here</a> to go to your main page.<br>
</body>
</html>
~;

	if (-e "./install-saveconfig.cgi") {unlink("./install-saveconfig.cgi")}
	unlink("./install.cgi");

	exit;

}

#############
sub getinfo {
#############

	$scriptpath = $ENV{SCRIPT_FILENAME};
	$hosturl = $ENV{HTTP_HOST};
	$rootpath = $ENV{DOCUMENT_ROOT};
	$smtpfun = $ENV{SERVER_NAME};

	# find subdirectory if necessary:
	$subdir = $ENV{SCRIPT_NAME};
	$subdir =~ s/^\/(.*)\/install\.cgi$/$1/ig; # cgi-bin/subfolder

	$cookiestring = "$hosturl"; # pagename
	$cookiestring =~ s/\W|_//ig;
	$cookiestring =~ s/^www//ig;
	$cookienameuid = $cookiestring . "uid";
	$cookienamepwd = $cookiestring . "pwd";
	$cookienamethm = $cookiestring . "thm";
	$cookienamelng = $cookiestring . "lng";
	$webappurl  = "http://$hosturl/$subdir"; # scripturl and pageurl
	$webappurl =~ s/\/$//; # if no subfolder
	$scriptpath=~ s/\/[^\/]*$//isg;

}

1;
