#!/usr/bin/perl

package fms_acs;

use FindBin;
use lib $FindBin::Bin;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use lib ".";

require Exporter;

use vars qw/@ISA @EXPORT @EXPORT_OK $copyright $prgname/;


### WINDOWS USERS EDIT BELOW ##############################################
$config_cgi = "config.cgi"; ## <-- CHANGE THIS LINE TO THE FULL SERVER PATH TO config.cgi 
#$config_cgi = "e:/full/server/path/to/config.cgi";
###########################################################################

$thetime = time();
($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime($thetime);
$year = "20" . substr($year, 1, 2);

$version = "FM SiteSearch Pro Version 4.0";

$prgname = "FM SiteSearch";
$copyright = "Copyright 2002-$year FocalMedia.Net";

@ISA = qw(Exporter);

@EXPORT = qw(check_access 
				 gtemplate
				 check_search_spamming
				 get_heading_box
				 insbuttons
				 indexprogress); 

@EXPORT_OK = qw($tmp
					$template1);


$default_permissions = 0777;  ### DEFAULT PERMISSIONS THAT IS USED FOR LOG FILES

&get_setup;






sub indexprogress
{

my ($pauseint, $redirurl, $b_heading, $b_display, $cur_nr, $end_nr) = @_;

$perc = ($cur_nr / $end_nr) * 100;
#$perc = sprintf("%5.2f",$perc);
$perc = int($perc);


if ($redirurl ne "") 
	{
	$redgo = qq[<meta HTTP-EQUIV="REFRESH" CONTENT="$pauseint;URL=$redirurl">];
	$ani_img = qq[
	<table width="100%" border="0" cellpadding="6" cellspacing="1" class="border">
    <tr>
      <td width="0%" height="35" class="normaltext"><img src="$web_url/fms_ajl1.gif"></td>
      <td width="100%" background="$web_url/fms_bar6.gif" class="normaltext"><b>$b_heading</b></td>
    </tr>
  </table>	
	];
	}
	else
	{

$ani_img = qq[
	<table width="100%" border="0" cellpadding="6" cellspacing="1" class="border">
    <tr>
      <td height="35" background="$web_url/fms_bar6.gif" class="normaltext"><b>$b_heading</b></td>
    </tr>
  </table>
];	
	}

$perc1 = $perc;
$perc2 = 100 - $perc;

$retv = qq[<html>
<head>
<title>Search Index</title>
$redgo

<style type="text/css">
A {COLOR: #0000FF}
A:visited {COLOR: #0000FF}
A:active {COLOR: #000000}
A:hover {COLOR: #000000}

.verd
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
	line-height: 18px;
}

.border {
	border: 1px solid #E0E0E0;
}

p
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	line-height: 18px;
}

.normaltext
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	line-height: 18px;
}

.blanktext
{ color: #FFFFFF;
}

</style>
</head>
<body>

$ani_img
  
  <table border="0" cellpadding="0" cellspacing="0" width="100%"    background="$web_url/fms_shadow.gif">
  <tr>
    <td width="1%" bgcolor="#FFFFFF" class="blanktext"> _ </td>
    <td width="99%"></td>
  </tr>
</table>
 
  <table width="100%" border="0" class="border">
     <tr>
       <td width="97%"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#F9F9F9">
         <tr>
           <td background="$web_url/fms_bar.gif" width="1" class="normaltext"><b>&nbsp;&nbsp;$perc%</b></td>
           <td background="$web_url/fms_bar.gif" height="30" width="$perc1%">&nbsp;</td>
           <td width="$perc2%">&nbsp;</td>
         </tr>
       </table></td>
     </tr>
   </table>

 
<table width="100%" border="0" cellpadding="0" cellspacing="0"    background="$web_url/fms_shadow.gif">
  <tr>
    <td width="1%" bgcolor="#FFFFFF" class="blanktext"> _ </td>
    <td width="99%"></td>
  </tr>
</table>
<span class="normaltext">$b_display</span>


</body>
</html>
];

return ($retv);

}




sub get_heading_box
{
my ($h_icon, $h_heading, $h_text) = @_;

$h_return = qq[
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#E1E1E1">
  <tr>
    <td width="1%" valign="top" bgcolor="#FFFFFF"><p><img src="$h_icon"></p>
    </td>
    <td width="99%" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="6">
      <tr>
        <td background="$web_url/fms_bar6.gif"><strong class="normaltext">$h_heading</strong></td>
        </tr>
      <tr>
        <td class="normaltext">$h_text</td>
        </tr>
    </table></td>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%"    background="$web_url/fms_shadow.gif">
  <tr>
    <td width="1%" bgcolor="#FFFFFF" class="blanktext"> _ </td>
    <td width="99%"></td>
  </tr>
</table>
];

return ($h_return);
}





sub check_search_spamming
{

$settings_data = &get_file_contents2("$data_dir/settings.dat");
@settings = split (/\n/, $settings_data);
$nr_searches_per_hour = $settings[16];

if ($nr_searches_per_hour eq "") { $nr_searches_per_hour = 40; }


### CHECK IF TMP DIR EXISTS
if ((-e "$data_dir/tmpip") < 1) 
	{
	$status = mkdir("$data_dir/tmpip", $default_permissions);
	$stat = chmod($default_permissions,"$data_dir/tmpip","$data_dir/tmpip");
	}

### CLEAN UP tmpip DIR FOR OLDER SEARCHES

$ipaddress = $ENV{'REMOTE_ADDR'};
$ntime = time();

	opendir(DDIR,"$data_dir/tmpip");
	@afiles = readdir(DDIR);
	foreach $filenamea (@afiles)
		{
			if (($filenamea ne ".") and ($filenamea ne ".."))
			{
			($device,$inode,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$data_dir/tmpip/$filenamea");
				if ($mtime < ($ntime - 3600))
					{
					$stat = unlink ("$data_dir/tmpip/$filenamea");
					}
			}
		}
	closedir (DDIR);




### RECORD IP ADDRESS

if ((-e "$data_dir/tmpip/$ipaddress") < 1)
	{
	open (IPADD, "> $data_dir/tmpip/$ipaddress");
		print IPADD "1";
	close (IPADD);
	$stat = chmod($default_permissions,"$data_dir/tmpip/$ipaddress","$data_dir/tmpip/$ipaddress");
	}
	else
	{
	open (IPADD, "$data_dir/tmpip/$ipaddress");
		$ipnr = <IPADD>;
	close (IPADD);
	
	if ($ipnr >= $nr_searches_per_hour)
		{
		print "Maximum number of searches exceeded. Access denied."; exit;
		}
	
	$ipnr++;
	
	open (IPADD, "> $data_dir/tmpip/$ipaddress");
		print IPADD $ipnr;
	close (IPADD);
	}

}




sub check_access
{

my ($TheUsername, $ThePassword, $EnteredUser, $EnteredPass) = @_;
my ($usercookie, $passcookie, $query);

$query = new CGI;

$usercookie = $query->cookie('nuser');
$passcookie = $query->cookie('npass');

if (($EnteredUser ne "") and ($EnteredPass ne "")) {&do_login ($EnteredUser, $EnteredPass);}

if ((-e "$data_dir/setup2.cfg") < 1) 
	{
	open (SETPC, "> $data_dir/setup2.cfg");
	print SETPC "62,69,86,63,15,13,64,113,34,100,112,106,105,113,65,35,101,104,114,117,103,117,38,63,62,105,115,111,118,35,106,98,101,104,65,35,88,104,118,101,99,113,101,35,34,118,109,123,103,64,38,50,36,65,64,116,118,117,115,111,105,65,84,112,121,104,118,102,102,35,102,122,34,63,101,14,12,107,118,102,104,64,38,105,118,119,116,59,49,50,123,120,121,49,106,112,101,100,112,110,103,103,109,98,48,113,105,117,49,102,107,106,47,101,109,111,49,105,113,116,49,105,113,116,103,100,118,100,106,49,103,104,107,66,121,115,110,64,106,110,36,16,14,112,112,112,115,118,117,104,115,119,103,117,65,35,121,108,114,101,113,122,50,116,118,100,120,118,117,64,43,105,118,119,116,59,49,50,106,110,117,108,120,102,117,104,101,115,101,107,116,115,113,49,106,112,101,100,112,110,103,103,109,98,48,113,105,117,41,62,118,102,118,120,118,111,34,119,118,118,103,62,38,63,72,80,17,11,85,108,120,102,85,104,101,115,101,107,36,81,116,114,64,48,99,65,64,99,116,65,17,11,62,50,119,117,116,114,114,104,64,73,81,33,85,108,120,102,85,104,101,115,101,107,36,81,116,114,36,68,113,115,125,115,107,106,108,117,34,63,101,33,106,117,105,103,63,37,108,117,118,115,62,48,49,122,123,120,48,105,115,100,99,111,113,102,102,108,101,47,112,104,120,35,64,73,115,100,99,111,81,102,102,108,101,47,80,104,120,61,49,100,66,61,49,105,115,111,118,65,64,48,114,65,17,11,62,69,86,63\n";
	print SETPC "53,53,104,120,121,55,55,54,99,54,17,11,117,100,104,103,99,55,123,54,121,100,17,11,99,122,118,53,53,56,101,119,118,104,17,11,50,60,57,53,58,115,110,101,115,115,17,11,115,60,56,54,119,109,118,114,113,109,17,11,53,55,57,58,119,100,110,98,117,111,17,11,53,55,60,118,99,100,101,111,104,100,17,11,109,100,108,53,55,59,101,112,108,100,17,11,99,112,55,53,112,125,61,100,53,53,17,11,108,54,56,108,100,113,124,110,54,104,17,11,58,54,56,54,113,100,108,107,106,102,17,11,106,100,105,108,109,56,56,58,99,103,17,11,99,109,56,54,58,100,108,105,104,111,17,11,59,56,121,107,102,111,101,58,58,107,17,11,59,55,57,109,102,100,110,53,55,113,17,11,112,55,57,58,99,115,57,53,53,107,17,11,99,100,110,54,54,111,101,98,102,51,17,11,53,53,56,49,74,78,80,66,80,103,17,11,76,111,105,118,59,59,55,107,103,111,17,11,59,55,55,54,108,118,112,108,104,109,17,11,109,55,110,99,104,118,113,98,104,103,17,11,121,55,57,106,54,54,57,58,58,105,17,11,108,55,57,58,114,104,118,58,58,117,17,11,108,55,57,58,104,117,108,116,109,118,17,11,107,55,57,111,117,110,103,110,122,104,17,11,50,56,56,55,108,119,112,103,108,102,17,11,50,56,56,55,108,106,106,101,110,110,17,11,53,55,57,49,59,105,119,105,117,110,17,11,109,55,57,105,104,117,60,116,104,107,17,11,54,54,117,115,119,105,118,114,106,122,17,11,115,55,57,107,115,116,123,102,116,117,17,11,55,60,55,105,116,118,60,116,57,117,17,11,100,55,55,54,120,118,111,53,55,109,17,11,121,104,120,58,54,54,57,107,116,103";
	close (SETPC);
	}

if (($usercookie eq "") and ($passcookie eq "")){&login_screen;}

if (($usercookie ne $TheUsername) or ($passcookie ne $ThePassword)){&wrongps_screen;}

}





sub gtemplate
{
my ($wtempl) = @_;

$rv = &get_file_contents2("$data_dir/setup2.cfg");

	($rv1, $rv2) = split (/\n/, $rv);

	@alltitems = split (/,/, $rv2);
	
	$cnc = 1;
	foreach $tmitem(@alltitems)
		{
		$cnc++;
		if ($cnc == 5){$cnc = 1;}
		$tmitem = ($tmitem - $cnc);
		$asl = $asl . chr($tmitem);
		}
	@rk = split (/\n/, $asl);


	foreach $item (@rk)
		{
		$item =~ s/\n//g;
		$crit = chr(13); $item =~ s/$crit//g; $crit = chr(10); $item =~ s/$crit//g;	
		if ($rg eq $item){$rss = "true";}
		}


if ($wtempl eq "ctl")
	{

		#if ((-e "rgs_login.cgi") > 0)
		#{
		$psplugin = qq[<a href="$script_url/admin/admin.cgi"><img src="$web_url/sw_ps.gif" border="0"></a>];
		$rss = "true";
		#}

	
	if ($rss ne "true") { $version = $version . " - ". chr(85).chr(110).chr(114).chr(101).chr(103).chr(105).chr(115).chr(116).chr(101).chr(114).chr(101).chr(100); }
	$ctrp = chr(99).chr(111).chr(110).chr(116).chr(114).chr(111).chr(108).chr(95).chr(112).chr(97).chr(110).chr(101).chr(108).chr(46).chr(104).chr(116).chr(109).chr(108);
	#$template1 = &get_file_contents2("$data_dir/$ctrp");

	
	$template1 = qq[
	
<html>
<head>
<title>FM SiteSearch Pro</title>
<style type="text/css">
A {COLOR: #0000FF}
A:visited {COLOR: #0000FF}
A:active {COLOR: #000000}
A:hover {COLOR: #000000}

body
{
background-image:
url("!!weburl!!/fms_fcbg.jpg");
background-repeat: repeat-x;
background-attachment:
fixed
}

.verd
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
	line-height: 18px;
}


p
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	line-height: 18px;
}

.normaltext
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	line-height: 18px;
}


.blanktext
{ color: #FFFFFF;
}


.popup
{
COLOR: #0000FF;
CURSOR: help;
TEXT-DECORATION: none
}



</style>

<script LANGUAGE="JavaScript">
<!-- Hide

var popupwin = null;
  function popup(loc,ww,hh)
   {
    var mywidth = (ww + 0);
    var myheight = (hh + 0);
    var myspecs = "'menubar=0,status=1,resizable=1,location=0,titlebar=0,toolbar=1,scrollbars=1,width=" + mywidth + ",height=" + myheight + "'";
      if (popupwin == null || popupwin.closed)
			{
            popupwin = window.open (loc, 'popupwin', myspecs);
           }
		 else
		   {
            popupwin.focus();
            popupwin.location.href = loc;
          }
    }

pic = new Image();
pic2 = new Image();

function flip(pic, r, tsource)
  {
    if(r == 2) { document[pic].src = tsource; }
    if(r == 1) { document[pic].src = tsource; }
  }

// End Hide -->
</script>

</head>

<body  LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<div align="center"><center>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td width="759"><p align="left"><img src="!!weburl!!/fms_flogo.jpg" width="500" height="109"><br>
    </td>
    <td width="15">$psplugin</td>
    <td width="727" valign="middle"><p align="center"><font face="Verdana" size="3"
    color="#FFFFFF"><strong>FM SiteSearch Pro Admin Control Panel</strong></font><br>
    <a href="http://www.focalmedia.net/cgi-bin/fms/fmsearch.cgi?url=manual"><img
    src="!!weburl!!/fms_manual.gif" border="0"></a><a
    href="http://www.focalmedia.net/cgi-bin/fms/fmsearch.cgi?url=support"><img
    src="!!weburl!!/fms_support.gif" border="0"></a><br>
    <font face="Verdana" size="1" color="#FFFFFF">!!cwrite!!<br>
    <strong>!!version!!</strong><br>
    </font></td>
  </tr>
</table>
</center></div><div align="center"><center>

<table border="0" cellpadding="0" cellspacing="0" width="93%">
  <tr>
    <td>!!buttons!!</td>
    <td></td>
  </tr>
</table>
</center></div>


<div align="center"><center>

<table border="0" cellpadding="0" cellspacing="0" width="96%">
  <tr>
    <td width="1"><img src="!!weburl!!/fms_sn_cc1.gif" width="26" height="17"></td>

    <td width="98%" height="15" background="!!weburl!!/fms_sn_cctop.gif"></td>
    <td width="1" height="15" align="right"><img src="!!weburl!!/fms_sn_cc2.gif" width="26"
    height="17"></td>
  </tr>
  <tr>
    <td width="1" background="!!weburl!!/fms_sn_cl.gif"></td>
    <td width="99%"><div align="center"><center><table border="0" cellpadding="10"
    cellspacing="0" width="100%">
      <tr>
        <td width="100%" bgcolor="#FFFFFF">!!controlpanel!!</td>
      </tr>
    </table>
    </center></div></td>
    <td width="1" height="15" align="right" background="!!weburl!!/fms_sn_cr.gif"></td>
  </tr>

</table>
</center></div><div align="center"><center>

<table border="0" cellpadding="0" cellspacing="0" width="96%">
  <tr>
    <td width="1"><img src="!!weburl!!/fms_sn_c3.gif" width="26" height="18"></td>
    <td width="98%" height="15" align="right" background="!!weburl!!/fms_sn_cbot.gif"></td>
    <td width="1" height="15" align="right"><img src="!!weburl!!/fms_sn_c4.gif" width="26"
    height="18"></td>
  </tr>
</table>
</center></div>
<BR><BR>

</body>
</html>

	];
	
	
	}
	else
	{
	$thaz = chr(109).chr(97).chr(105).chr(110).chr(95).chr(108).chr(97).chr(121).chr(111).chr(117).chr(116).chr(46).chr(104).chr(116).chr(109).chr(108);
	$template1 = &get_file_contents2("$data_dir/$thaz");

		#if ((-e "rgs_login.cgi") > 0)
		#{
		$psplugin = qq[<a href="$script_url/admin/admin.cgi"><img src="$web_url/sw_ps.gif" border="0"></a>];
		$rss = "true";
		#}
	
	if ($rss ne "true")
		{
		$bdag = chr(60).chr(47).chr(98).chr(111).chr(100).chr(121).chr(62);
		
		@alltitems1 = split (/,/, $rv1);
		$cnc = 1;
		$asl = "";
		foreach $tmitem(@alltitems1)
			{
			$cnc++;
			if ($cnc == 5){$cnc = 1;}
			$tmitem = ($tmitem - $cnc);
			$asl = $asl . chr($tmitem);
			}
			$asl = $asl . $bdag;
		$template1 =~ s/$bdag/$asl/gi;
		}
	}

	$template1 =~ s/!!weburl!!/$web_url/g;
	$template1 =~ s/!!script_url!!/$script_url/g;
	$template1 =~ s/!!version!!/$version/g;
	$template1 =~ s/!!web_url!!/$web_url/g;
	$template1 =~ s/!!cwrite!!/$copyright/g;

	if ($use_mysql eq "Yes")
		{
		$slnk = "$script_url/fms_admin4.cgi?fct=web";
		$template1 =~ s/!!buildindex!!/$slnk/g;
		}
		else
		{
		$slnk = "$script_url/fms_admin3.cgi?fct=web";
		$template1 =~ s/!!buildindex!!/$slnk/g;
		}

return ($template1, $rss);

}







sub insbuttons
{

my ($templ99, $bloc) = @_;

$home = "fms_home2.gif";
$search_settings = "fms_searchset2.gif";
$what_to_search = "fms_whatsearch2.gif";
$templates = "fms_templates2.gif";
$build_search_index = "fms_saerchi2.gif";
$html_code = "fms_htmlcode2.gif";
$search_statistics = "fms_searchstat2.gif";

if ($bloc eq "HOME")
	{
	$home = "fms_home.gif";
	}
	elsif ($bloc eq "SEARCH_SETTINGS")
	{
	$search_settings = "fms_searchset.gif";
	}
	elsif ($bloc eq "WHAT_TO_SEARCH")
	{
	$what_to_search = "fms_whatsearch.gif";
	}
	elsif ($bloc eq "TEMPLATES")
	{
	$templates = "fms_templates.gif";
	}
	elsif ($bloc eq "BUILD_SEARCH_INDEX")
	{
	$build_search_index = "fms_saerchi.gif";
	}
	elsif ($bloc eq "HTML_CODE")
	{
	$html_code = "fms_htmlcode.gif";
	}
	elsif ($bloc eq "SEARCH_STATISTICS")
	{
	$search_statistics = "fms_searchstat.gif";
	}
	

	if ($use_mysql eq "Yes")
		{
		$slnk = "$script_url/fms_admin4.cgi?fct=web";
		$template1 =~ s/!!buildindex!!/$slnk/g;
		}
		else
		{
		$slnk = "$script_url/fms_admin3.cgi?fct=web";
		$template1 =~ s/!!buildindex!!/$slnk/g;
		}

	

$buttons = qq[<a href="$script_url/fms_admin.cgi" onMouseOver="javascript:flip('home', 2, '$web_url/fms_home.gif')" onMouseOut="javascript:flip('home', 1, '$web_url/$home')"><img src="$web_url/$home" Name="home" border="0"></a><a
href="$script_url/fms_admin.cgi?fct=search_settings" onMouseOver="javascript:flip('settings', 2, '$web_url/fms_searchset.gif')" onMouseOut="javascript:flip('settings', 1, '$web_url/$search_settings')"><img src="$web_url/$search_settings" name="settings" border="0"></a><a 
href="$script_url/fms_admin.cgi?fct=what_search"  onMouseOver="javascript:flip('whatsearch', 2, '$web_url/fms_whatsearch.gif')" onMouseOut="javascript:flip('whatsearch', 1, '$web_url/$what_to_search')"><img  src="$web_url/$what_to_search" border="0" name="whatsearch"></a><a
href="$script_url/fms_admin.cgi?fct=templates" onMouseOver="javascript:flip('templates', 2, '$web_url/fms_templates.gif')" onMouseOut="javascript:flip('templates', 1, '$web_url/$templates')"><img src="$web_url/$templates" border="0" name="templates"></a><a 
href="$slnk" onClick="popup('$slnk',600,400);return false;" onMouseOver="javascript:flip('sindex', 2, '$web_url/fms_saerchi.gif')" onMouseOut="javascript:flip('sindex', 1, '$web_url/$build_search_index')"><img src="$web_url/$build_search_index" name="sindex" border="0"></a><a 
href="$script_url/fms_admin.cgi?fct=html_code" onMouseOver="javascript:flip('htmlcode', 2, '$web_url/fms_htmlcode.gif')" onMouseOut="javascript:flip('htmlcode', 1, '$web_url/$html_code')"><img src="$web_url/$html_code" border="0" name="htmlcode"></a><a 
href="$script_url/fms_admin.cgi?fct=stats" onMouseOver="javascript:flip('sstats', 2, '$web_url/fms_searchstat.gif')" onMouseOut="javascript:flip('sstats', 1, '$web_url/$search_statistics')"><img src="$web_url/$search_statistics" border="0" name="sstats"></a>];

$templ99 =~ s/!!buttons!!/$buttons/gi;

return ($templ99);

}




sub do_login
{

my ($form_username, $form_password) = @_;

my ($query, $thecookie1, $thecookie2, $scripts_admin);

$query = new CGI;

$thecookie1 = $query->cookie(-name=>'nuser',
			    					  -value=>$form_username,
			    					  -expires =>  '+2d',
			    					  -path=>'/');

$thecookie2 = $query->cookie(	-name=>'npass',
			    						-value=>$form_password,
			    						-expires =>  '+2d',
			    						-path=>'/');

print $query->header(-cookie=>[$thecookie1, $thecookie2]); 


print "<html>
<head>
<title>FM SiteSearch Pro</title>
<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"1;URL=$script_url/fms_admin.cgi\">
</head>
<body>
</body>
</html>
";

exit;

}



sub login_screen
{

my ($newquery, $scripts_admin);
my $newquery = CGI->new;


print $newquery->header();
print $newquery->start_html("Control Panel");


print qq[<html>

<head>
<title>Login</title>
</head>

<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form method="POST" action="$script_url/fms_admin.cgi">
  <div align="center"><center><table border="0" cellpadding="5" cellspacing="0" width="300"
  style="border: 1px solid">
    <tr>
      <td width="350" height="1"><font color="#FFFFFF" face="Verdana" size="2"><strong>__</strong></font></td>
      <td width="350" height="1"></td>
    </tr>
    <tr>
      <td width="350" height="1"><div align="right"><p><font face="Verdana" size="2"><strong>User
      Name:</strong></font></td>
      <td width="350" height="1"><input type="text" name="username" size="20"></td>
    </tr>
    <tr>
      <td width="350" height="1"><div align="right"><p><font face="Verdana" size="2"><strong>Password:
      </strong></font></td>
      <td width="350" height="1"><input type="password" name="password" size="20"></td>
    </tr>
    <tr>
      <td width="350" height="1"></td>
      <td width="350" height="1"><input type="submit" value="Login" name="B1"><br>
      <font color="#FFFFFF">__</font></td>
    </tr>
  </table>
  </center></div>
</form>

<p>&nbsp;</p>
</body>
</html>
];


exit;

}



sub wrongps_screen
{

my ($scripts_admin);


my $query = CGI->new;
print $query->header();
print $query->start_html("Control Panel");


print qq[
<html>

<head>
<title>Login</title>
</head>

<body>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<form method="POST" action="$script_url/fms_admin.cgi">
  <div align="center"><center><table border="0" cellpadding="5" cellspacing="0" width="300"
  style="border: 1px solid">
    <tr>
      <td width="350" height="1"><font color="#FFFFFF" face="Verdana" size="2"><strong>__</strong></font></td>
      <td width="350" height="1"></td>
    </tr>
    <tr>
      <td width="350" height="1"><div align="right"><p><font face="Verdana" size="2"><strong>User
      Name:</strong></font></td>
      <td width="350" height="1"><input type="text" name="username" size="20"></td>
    </tr>
    <tr>
      <td width="350" height="1"><div align="right"><p><font face="Verdana" size="2"><strong>Password:
      </strong></font></td>
      <td width="350" height="1"><input type="password" name="password" size="20"></td>
    </tr>
    <tr>
      <td width="350" height="1"></td>
      <td width="350" height="1"><input type="submit" value="Login" name="B1"><br>
      <font color="#FFFFFF">__</font></td>
    </tr>
  </table>
  </center></div>
</form>

<p align="center"><font face="Verdana" size="2"><strong>The user name or password you
entered was incorrect.</strong> Please Retry.<strong><br>
</strong></font></p>
</body>
</html>
];


exit;

}





sub get_file_contents2
{

my ($filename) = @_;
my ($filesize, $filesize, $thefile);

$filesize = (-s "$filename");
open (TFILECNTS, "$filename");
 	read(TFILECNTS,$thefile,$filesize);
close (TFILECNTS);

return ($thefile);
}




#### GET CONFIGURATION ########################################################

sub get_setup
{

$exists = (-e "$config_cgi");
if ($exists > 0)
	{
	open (STP, "$config_cgi");
		while (defined($line=<STP>))
			{
			if ($line =~ m/#/g)
				{
				$r = pos($line);
				$line = substr($line, 0, $r - 1);
				}
				
				$line =~ s/\n//g;
	
if ($line =~ /^DATA_DIR/){$data_dir = &get_setup_line($line, DATA_DIR);}
if ($line =~ /^WEBROOT/){$webroot = &get_setup_line($line, WEBROOT);}
if ($line =~ /^URLROOT/){$urlroot = &get_setup_line($line, URLROOT);}
if ($line =~ /^WEB_URL/){$web_url = &get_setup_line($line, WEB_URL);}
if ($line =~ /^SCRIPT_URL/){$script_url = &get_setup_line($line, SCRIPT_URL);}
if ($line =~ /^USERNAME/){$username = &get_setup_line($line, USERNAME);}
if ($line =~ /^PASSWORD/){$password = &get_setup_line($line, PASSWORD);}

if ($line =~ /^USE_MYSQL/){$use_mysql = &get_setup_line($line, USE_MYSQL);}
if ($line =~ /^DB_NAME/){$db_name = &get_setup_line($line, DB_NAME);}
if ($line =~ /^DB_USERNAME/){$db_username = &get_setup_line($line, DB_USERNAME);}
if ($line =~ /^DB_PASSWORD/){$db_password = &get_setup_line($line, DB_PASSWORD);}
if ($line =~ /^RG/){$rg = &get_setup_line($line, RG);}
if ($line =~ /^MYSQL_HOSTNAME/){$mysql_hostname = &get_setup_line($line, MYSQL_HOSTNAME);}
if ($line =~ /^MYSQL_PORT/){$mysql_port = &get_setup_line($line, MYSQL_PORT);}

			}
	close (STP);
	
	}
	else
	{
	print "Could not find $config_cgi"; exit;
	
	}
}



sub get_setup_line
{
my ($setup_line, $setup_var) = @_;
$crit = "\"";
$setup_line =~ m/$crit/g;
$r1 = pos($setup_line);
$setup_line =~ m/$crit/g;
$r2 = pos($setup_line);
$setup_line = substr($setup_line, $r1, ($r2 - $r1 - 1));
$return_val = $setup_line;
return ($return_val);
}

#### END CONFIGURATION ########################################################




1;