#!/usr/bin/perl

package pseek;

########################################################################
# COPYRIGHT NOTICE:
#
# Copyright 2008 FocalMedia.Net All Rights Reserved.
#
# Selling the code for this program without prior written consent 
# from FocalMedia.Net is expressly forbidden. You may not 
# redistribute this program in any shape or form.
# 
# This program is distributed "as is" and without warranty of any
# kind, either express or implied. In no event shall the liability 
# of FocalMedia.Net for any damages, losses and/or causes of action 
# exceed the total amount paid by the user for this software.
#
########################################################################

#### EDIT HERE -- FOR WINDOWS/IIS BASED INSTALLATIONS ONLY #######

$config_cgi = "config.cgi";

# THE PATH ON A WINDOWS INSTALLATION WILL LOOK SOMETHING LIKE THIS:
# $config_cgi = "c:/inetpub/webpub/cgi-bin/pseek/config.cgi";

#### DO NOT CHANGE ANYTHING BELOW THIS LINE #################

#use FindBin;
#use lib $FindBin::Bin;

use CGI::Carp qw(fatalsToBrowser);
use CGI;
use Time::Local;
use IO::Socket;
use MIME::Base64 qw(decode_base64 encode_base64);
#use Net::SMTP;

require Exporter;

use vars qw/@ISA @EXPORT @EXPORT_OK $copyright $prgname/;

@ISA = qw(Exporter);

@EXPORT = qw(get_file_contents
				 encode_dir
				 decode_dir
				 new_gsettings
				 decode_date
				 get_rating_images
				 setCookie
				 getCookies
				 ts_insert_template_includes
				 send_email
				 remove_leading_spacing
				 get_cid_cat
				 fill_vars
				 insert_images
				 remove_html
				 get_imgboxes
				 get_imgboxes_cc
				 check_img_auth
				 check_img_auth_cc
				 accesscheck
				 fill_cp_vars
				 insert_go_back_buttons
				 get_more_info_file_name
				 );


@EXPORT_OK = qw($thefile
					 $enc_string
					 $decoded_string
					 $rdvalue
					 $images
					 @rawCookies1
					 $tmpl_page
					 $chopped_string
					 $cidret
					 $filledvar
					 $ihtml
					 $imgb
					 $error_ind
					 $tofvar
					 $selq
					 $lnktitle
					 $url
					 $moreinfo_url);

&get_setup;

$default_permissions = 0777;



#####################################



sub insert_go_back_buttons
{
my ($tmplcode, $link_id, $categ_id) = @_;


$gsettings = new_gsettings pseek;

if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
$dbh = DBI->connect($dsn, $db_username, $db_password);
if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }

#### GET CATEGORIES

$sql = "SELECT * FROM dirs WHERE cid = '$categ_id'";
$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror \n From: $sql";}
$selq = "";

$lv = 1;
while ( @row = $sth->fetchrow() )
	{
	for ($ms = 2; $ms < 18; $ms++) 
		{
		if ($row[$ms] ne "")
			{
			
			if ($gsettings->{dyn_stat} eq "Static")
				{
				$ecat = $ecat . &encode_dir($row[$ms]) . "/";
				$selq = $selq . qq[<a href="$web_url/$ecat">$row[$ms]</a>] . " " . $gsettings->{location_seperator} . " ";
				}
				else
				{
				$ecat = $ecat . &encode_dir($row[$ms]) . "-";
				$rlcat = substr($ecat, 0, length($ecat)-1);
				$selq = $selq . qq[<a href="$script_url/dirs.cgi?lv=$lv&ct=$rlcat">$row[$ms]</a>] . " " . $gsettings->{location_seperator} . " ";
				}
				
			$lv++;
			}
		}
	}
	
$selq = substr($selq, 0, length($selq) - (length($gsettings->{location_seperator}) + 1)); 

$sql = "SELECT * FROM links WHERE lnkid = '$link_id'";
$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror \n From: $sql";}
while ( @row = $sth->fetchrow() )
	{
	$lnktitle = $row[2];
	$url = $row[5];
	}

$sth->finish;
$dbh->disconnect;



if ($gsettings->{dyn_stat} eq "Static")
	{


	if ($gsettings->{more_info_naming} eq "linktitles")
		{
		#$moreinfo_url = "$web_url/" . $ecat . &get_more_info_file_name($lnktitle) . $gsettings->{gen_file_ext};
		$moreinfo_url = "$web_url/" . $ecat . &get_more_info_file_name($lnktitle) . "_" . $link_id . $gsettings->{gen_file_ext};
		}
		else
		{
		$moreinfo_url = "$web_url/" . $ecat . $link_id . $gsettings->{gen_file_ext};
		}
	
	
	}
	else
	{
	$moreinfo_url = "$script_url/linfo.cgi?id=" . $link_id;
	}
				
$new_tmplcode = $tmplcode;

$new_tmplcode =~ s/!!title_without_link!!/$lnktitle/gi;
$new_tmplcode =~ s/!!url!!/$url/gi;
$new_tmplcode =~ s/!!more_info_url!!/$moreinfo_url/gi;
$new_tmplcode =~ s/!!category_with_link!!/$selq/gi;

return ($new_tmplcode);

######## category string with link, $lnktitle, $url, $moreinfo_url


}





sub accesscheck
{

my ($passed_user, $passed_pass, $addurl_click) = @_;


$topvar = pseek::get_file_contents("$data_dir/frontlink.dat");
	
if ($passed_user =~ /'/) { $passed_user = ""; } if ($passed_user =~ /\\/) { $passed_user = ""; }
if ($passed_pass =~ /'/) { $passed_pass = ""; } if ($passed_pass =~ /\\/) { $passed_pass = ""; }

##### CHECK COOKIES

$query = new CGI;
$usercookie = $query->cookie('cpuser');
$passcookie = $query->cookie('cppass');

if (($usercookie ne "") and ($passcookie ne "") and ($passed_user eq "") and ($passed_pass eq ""))
	{
	$cookie_set = "True";
	$passed_user = $usercookie;
	$passed_pass = $passcookie;
	}


if (($passed_user eq "") and ($passed_pass eq "") and ($addurl_click eq "LOGIN_LINK"))
	{
	print "Content-type: text/html\n\n";
	$login_template = pseek::get_file_contents("$data_dir/rgs_login.html");
	$login_template = pseek::ts_insert_template_includes($login_template);
	$login_template = pseek::fill_vars($login_template);
	$login_template =~ s/!!error_text!!//gi;
	$login_template =~ s/!!rgs_login!!/$script_url\/rgs_cp\.cgi/gi;
	
	if ($topvar eq ""){$login_template =~ s/!!top!!/$script_url\/fp\.cgi/gi;}else{$login_template =~ s/!!top!!/$topvar/gi;}
	
	print $login_template;
	exit;
	}


### IF ADD URL BUTTON PRESSED
if (($passed_user eq "") and ($passed_pass eq "") and ($addurl_click eq "ADDURL_CL"))
	{
	$addurl_template = pseek::get_file_contents("$data_dir/rgs_register.html");
	$login_template = pseek::get_file_contents("$data_dir/rgs_msgregister.html");
	$login_template = pseek::ts_insert_template_includes($login_template);
	$login_template = pseek::fill_vars($login_template);
	$login_template =~ s/!!rgs_login!!/$script_url\/rgs_login\.cgi/gi;
	
	if ($topvar eq ""){$login_template =~ s/!!top!!/$script_url\/fp\.cgi/gi;}else{$login_template =~ s/!!top!!/$topvar/gi;}
	
	$login_template =~ s/!!account_create!!/$script_url\/rgs_register\.cgi/gi;
	$login_template =~ s/!!retreive_password!!/$script_url\/rgs_repass\.cgi/gi;	
	print "$login_template";
	exit;
	}

 
if (($passed_user eq "") and ($passed_pass eq "") and ($addurl_click eq "MOD_LINK"))
	{
	$login_template = pseek::get_file_contents("$data_dir/rgs_modify_instructions.html");
	$login_template = pseek::ts_insert_template_includes($login_template);
	$login_template = pseek::fill_vars($login_template);
	$login_template =~ s/!!rgs_login!!/$script_url\/rgs_login\.cgi/gi;
	
	if ($topvar eq ""){$login_template =~ s/!!top!!/$script_url\/fp\.cgi/gi;}else{$login_template =~ s/!!top!!/$topvar/gi;}
	
	$login_template =~ s/!!account_create!!/$script_url\/rgs_register\.cgi/gi;
	$login_template =~ s/!!retreive_password!!/$script_url\/rgs_repass\.cgi/gi;	
	print "$login_template";
	exit;
	}


if (($passed_user eq "") or ($passed_pass eq "")) ### IF NOTHING ENTERED INTO LOGIN BOXES
	{
	print "Content-type: text/html\n\n";
	$login_template = pseek::get_file_contents("$data_dir/rgs_login.html");
	$login_template = pseek::ts_insert_template_includes($login_template);
	$login_template = pseek::fill_vars($login_template);
	$login_template =~ s/!!rgs_login!!/$script_url\/rgs_cp\.cgi/gi;
	
	if ($topvar eq ""){$login_template =~ s/!!top!!/$script_url\/fp\.cgi/gi;}else{$login_template =~ s/!!top!!/$topvar/gi;}

	$rgtext = pseek::get_file_contents("$data_dir/regusers.txt"); 
	@regtext = split (/\n/, $rgtext);
	
	$login_template =~ s/!!error_text!!/$regtext[7]/gi;
	print $login_template;		
	exit;
	}



##### CHECK USER NAME AND PASSWORD

if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
$dbh = DBI->connect($dsn, $db_username, $db_password);
if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }

#$sql = "SELECT * FROM lnkusers WHERE rgsuser = '$passed_user' AND rgspass = '$passed_pass' AND activated = 'Y'";
$sql = "SELECT * FROM lnkusers WHERE rgsuser = '$passed_user' AND rgspass = '$passed_pass'";
$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror - From: $sql";}
$rows = $sth->rows(); 

	while ( @row = $sth->fetchrow() )	
		{
		$RGSuserid = $row[0];
		$activated_status = $row[15];
		}

$sth->finish;
$dbh->disconnect;


$gsettings = new_gsettings pseek;


if (($activated_status ne "Y") and ($gsettings->{new_account_validation} eq "Yes") and ($rows > 0))
	{

	print "Content-type: text/html\n\n";	
	
	$login_template = pseek::get_file_contents("$data_dir/rgs_login.html");
	$login_template = pseek::ts_insert_template_includes($login_template);
	$login_template = pseek::fill_vars($login_template);
	$login_template =~ s/!!rgs_login!!/$script_url\/rgs_cp\.cgi/gi;
	
	if ($topvar eq ""){$login_template =~ s/!!top!!/$script_url\/fp\.cgi/gi;}else{$login_template =~ s/!!top!!/$topvar/gi;}

	$rgtext = pseek::get_file_contents("$data_dir/regusers.txt"); 
	@regtext = split (/\n/, $rgtext);
	$login_template =~ s/!!error_text!!/$regtext[20]/gi;
	
	print $login_template;		
	exit;	

	
	}
elsif ($rows < 1)
	{
	print "Content-type: text/html\n\n";	
	$login_template = pseek::get_file_contents("$data_dir/rgs_login.html");
	$login_template = pseek::ts_insert_template_includes($login_template);
	$login_template = pseek::fill_vars($login_template);
	$login_template =~ s/!!rgs_login!!/$script_url\/rgs_cp\.cgi/gi;
	
	
	if ($topvar eq ""){$login_template =~ s/!!top!!/$script_url\/fp\.cgi/gi;}else{$login_template =~ s/!!top!!/$topvar/gi;}

	
	$rgtext = pseek::get_file_contents("$data_dir/regusers.txt"); 
	@regtext = split (/\n/, $rgtext);
	$login_template =~ s/!!error_text!!/$regtext[7]/gi;
	
	print $login_template;		
	exit;	
	}
elsif ($cookie_set ne "True") ### SET COOKIE
	{
	
	$thecookie1 = $query->cookie(-name=>'cpuser',
				    					  -value=>$passed_user,
				    					  -expires=>'+24h',
				    					  -path=>'/');
	
	$thecookie2 = $query->cookie(	-name=>'cppass',
				    						-value=>$passed_pass,
				    						-expires=>'+24h',
				    						-path=>'/');
	
	print $query->header(-cookie=>[$thecookie1, $thecookie2]);

	print qq[<html>
			<head>
			<title>Powerseek</title>
			<meta HTTP-EQUIV="REFRESH" CONTENT="0;URL=$script_url/rgs_cp.cgi">
			</head>
			<body>
			</body>
			</html>
		  ];
	exit;
	}


return ($RGSuserid);

}




sub check_img_auth
{

$query = new CGI;

$uncr = &decode_ps($query->param('ia'));

$uncr =~ s/\.gif//gi;

($img1, $img2, $img3, $img4) = split (/O/, $uncr);

$letter1 = chr(substr($img1, 9, length($img1) - 9));
$letter2 = chr(substr($img2, 9, length($img2) - 9));
$letter3 = chr(substr($img3, 9, length($img3) - 9));
$letter4 = chr(substr($img4, 9, length($img4) - 9));

$lbox = $letter1 . $letter2 . $letter3 . $letter4;

$ia = $query->param('ia');

$letters = $query->param('letters');
$letters = lc($letters);

if ($letters ne $lbox) { $error_ind = "false"; }

return ($error_ind);

}

####



sub get_imgboxes ### IMAGE AUTHENTICATION
{
my ($ls1, $ls2, $ls3, $ls4, $alpha, @alpharray, $alpha1, $alpha2, $alpha3, $alpha4, $alpha_number1,
$alpha_number2, $alpha_number3, $alpha_number4, @files, $filename, $img1, $img2, $img3, $img4,
$iname1, $iname2, $iname3, $iname4, $un_crypted_str, $crypted_str, $imgb);


$ls1 = int(rand(4));
$ls1++;
if ($ls1 < 1) { $ls1 = 1; }
if ($ls1 == 1){ $ls1 = 49; }if ($ls1 == 2){ $ls1 = 50; }if ($ls1 == 3){ $ls1 = 51; }if ($ls1 == 4){ $ls1 = 52; }

$ls2 = int(rand(4));
$ls2++;
if ($ls2 < 1) { $ls2 = 1; }
if ($ls2 == 1){ $ls2 = 49; }if ($ls2 == 2){ $ls2 = 50; }if ($ls2 == 3){ $ls2 = 51; }if ($ls2 == 4){ $ls2 = 52; }

$ls3 = int(rand(4));
$ls3++;
if ($ls3 < 1) { $ls3 = 1; }
if ($ls3 == 1){ $ls3 = 49; }if ($ls3 == 2){ $ls3 = 50; }if ($ls3 == 3){ $ls3 = 51; }if ($ls3 == 4){ $ls3 = 52; }

$ls4 = int(rand(4));
$ls4++;
if ($ls4 < 1) { $ls4 = 1; }
if ($ls4 == 1){ $ls4 = 49; }if ($ls4 == 2){ $ls4 = 50; }if ($ls4 == 3){ $ls4 = 51; }if ($ls4 == 4){ $ls4 = 52; }



#print "--> $ls1 <BR>";

$alpha++;
@alpharray = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");

$alpha1 = rand(26);
$alpha_number1 = ord($alpharray[$alpha1]);

$alpha2 = rand(26);
$alpha_number2 = ord($alpharray[$alpha2]);

$alpha3 = rand(26);
$alpha_number3 = ord($alpharray[$alpha3]);

$alpha4 = rand(26);
$alpha_number4 = ord($alpharray[$alpha4]);


#print "1:$alpha_number1 - $ls1<BR>";
#print "2:$alpha_number2 - $ls2<BR>";
#print "3:$alpha_number3 - $ls3<BR>";
#print "4:$alpha_number4 - $ls4<BR>";


opendir(DIR,"$web_dir");
	@files = readdir(DIR);
	foreach $filename (@files)
		{
			if (($filename ne ".") and ($filename ne ".."))
			{
			
				#print "->" . substr($filename, 9, length($filename)- 9) . "<BR>";

				if ((substr($filename, 5, 2) ==  $ls1) and (substr($filename, 9, length($filename)- 9) ==  $alpha_number1))
					{
					$img1 = "<img src=\"" . "$web_url/$filename\">";
					$iname1 = $filename;
					#print "-1-> $filename - $alpha_number1 - $img1<BR>";
					}

				if ((substr($filename, 5, 2) ==  $ls2) and (substr($filename, 9, length($filename)- 9) ==  $alpha_number2))
					{
					$img2 = "<img src=\"" . "$web_url/$filename\">";
					$iname2 = $filename;
					#print "-2-> $filename - $alpha_number2 - $img2<BR>";
					}					

				if ((substr($filename, 5, 2) ==  $ls3) and (substr($filename, 9, length($filename)- 9) ==  $alpha_number3))
					{
					$img3 = "<img src=\"" . "$web_url/$filename\">";
					$iname3 = $filename;
					#print "-3-> $filename - $alpha_number3 - $img3<BR>";
					}					

				if ((substr($filename, 5, 2) ==  $ls4) and (substr($filename, 9, length($filename)- 9) ==  $alpha_number4))
					{
					$img4 = "<img src=\"" . "$web_url/$filename\">";
					$iname4 = $filename;
					#print "-4-> $filename - $alpha_number4 - $img4<BR>";
					}					

			}
		}
closedir(DIR);

$un_crypted_str = $iname1 ."O". $iname2 . "O" . $iname3 . "O" . $iname4;
$crypted_str = &encode_ps($un_crypted_str);

$imgb = "$img1 $img2 $img3 $img4 :::" . $crypted_str;

return ($imgb);

}






sub get_imgboxes_cc ### IMAGE AUTHENTICATION
{
my ($ls1, $ls2, $ls3, $ls4, $alpha, @alpharray, $alpha1, $alpha2, $alpha3, $alpha4, $alpha_number1,
$alpha_number2, $alpha_number3, $alpha_number4, @files, $filename, $img1, $img2, $img3, $img4,
$iname1, $iname2, $iname3, $iname4, $un_crypted_str, $crypted_str, $imgb);


$ls1 = int(rand(4));
$ls1++;
if ($ls1 < 1) { $ls1 = 1; }
if ($ls1 == 1){ $ls1 = 49; }if ($ls1 == 2){ $ls1 = 50; }if ($ls1 == 3){ $ls1 = 51; }if ($ls1 == 4){ $ls1 = 52; }

$ls2 = int(rand(4));
$ls2++;
if ($ls2 < 1) { $ls2 = 1; }
if ($ls2 == 1){ $ls2 = 49; }if ($ls2 == 2){ $ls2 = 50; }if ($ls2 == 3){ $ls2 = 51; }if ($ls2 == 4){ $ls2 = 52; }

$ls3 = int(rand(4));
$ls3++;
if ($ls3 < 1) { $ls3 = 1; }
if ($ls3 == 1){ $ls3 = 49; }if ($ls3 == 2){ $ls3 = 50; }if ($ls3 == 3){ $ls3 = 51; }if ($ls3 == 4){ $ls3 = 52; }

$ls4 = int(rand(4));
$ls4++;
if ($ls4 < 1) { $ls4 = 1; }
if ($ls4 == 1){ $ls4 = 49; }if ($ls4 == 2){ $ls4 = 50; }if ($ls4 == 3){ $ls4 = 51; }if ($ls4 == 4){ $ls4 = 52; }



#print "--> $ls1 <BR>";

$alpha++;
@alpharray = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");

$alpha1 = rand(26);
$alpha_number1 = ord($alpharray[$alpha1]);

$alpha2 = rand(26);
$alpha_number2 = ord($alpharray[$alpha2]);

$alpha3 = rand(26);
$alpha_number3 = ord($alpharray[$alpha3]);

$alpha4 = rand(26);
$alpha_number4 = ord($alpharray[$alpha4]);


#print "1:$alpha_number1 - $ls1<BR>";
#print "2:$alpha_number2 - $ls2<BR>";
#print "3:$alpha_number3 - $ls3<BR>";
#print "4:$alpha_number4 - $ls4<BR>";


opendir(DIR,"$web_dir");
	@files = readdir(DIR);
	foreach $filename (@files)
		{
			if (($filename ne ".") and ($filename ne ".."))
			{
			
				#print "->" . substr($filename, 9, length($filename)- 9) . "<BR>";

				if ((substr($filename, 5, 2) ==  $ls1) and (substr($filename, 9, length($filename)- 9) ==  $alpha_number1))
					{
					$img1 = "<img src=\"" . "$web_url/$filename\">";
					$iname1 = $filename;
					#print "-1-> $filename - $alpha_number1 - $img1<BR>";
					}

				if ((substr($filename, 5, 2) ==  $ls2) and (substr($filename, 9, length($filename)- 9) ==  $alpha_number2))
					{
					$img2 = "<img src=\"" . "$web_url/$filename\">";
					$iname2 = $filename;
					#print "-2-> $filename - $alpha_number2 - $img2<BR>";
					}					

				if ((substr($filename, 5, 2) ==  $ls3) and (substr($filename, 9, length($filename)- 9) ==  $alpha_number3))
					{
					$img3 = "<img src=\"" . "$web_url/$filename\">";
					$iname3 = $filename;
					#print "-3-> $filename - $alpha_number3 - $img3<BR>";
					}					

				if ((substr($filename, 5, 2) ==  $ls4) and (substr($filename, 9, length($filename)- 9) ==  $alpha_number4))
					{
					$img4 = "<img src=\"" . "$web_url/$filename\">";
					$iname4 = $filename;
					#print "-4-> $filename - $alpha_number4 - $img4<BR>";
					}					

			}
		}
closedir(DIR);

$un_crypted_str = $iname1 ."O". $iname2 . "O" . $iname3 . "O" . $iname4;
$crypted_str = &encode_ps($un_crypted_str);

########################

$ip = $ENV{'REMOTE_ADDR'};
$cip = crypt($ip, $password);
$crypted_str = $crypted_str . "oo-oo" . $cip;


$imgb = "$img1 $img2 $img3 $img4 :::" . $crypted_str;

return ($imgb);

}





sub check_img_auth_cc
{

$query = new CGI;

($ostr, $crstr) = split (/oo-oo/, $query->param('ia'));

$uncr = &decode_ps($ostr);

$uncr =~ s/\.gif//gi;

($img1, $img2, $img3, $img4) = split (/O/, $uncr);

$letter1 = chr(substr($img1, 9, length($img1) - 9));
$letter2 = chr(substr($img2, 9, length($img2) - 9));
$letter3 = chr(substr($img3, 9, length($img3) - 9));
$letter4 = chr(substr($img4, 9, length($img4) - 9));

$lbox = $letter1 . $letter2 . $letter3 . $letter4;

$ia = $query->param('ia');

$letters = $query->param('letters');
$letters = lc($letters);

if ($letters ne $lbox) { $error_ind = "false"; }

$ip = $ENV{'REMOTE_ADDR'};
$cip = crypt($ip, $password);
if ($cip ne $crstr) { $error_ind = "false"; }


return ($error_ind);

}





sub encode_ps
{
   my($cc) = @_;
   my($rcc, $ccount, $rndchar, $onechar);
   $rcc = "";
   $ccount = 0;
   while ($ccount < length($cc))
     {
       $ccount++;
       $rndchar = int(rand(24)) + 97;
       $onechar = ord(substr($cc, length($cc) - $ccount, 1));
       $onechar = $onechar + 1;
       $rcc = $rcc . chr($onechar) . chr($rndchar);
    }

$lcnt = 0;
while ($lcnt < length($rcc))
	{
	$onechar = substr($rcc,$lcnt,1);
	$ordchar = ord($onechar);
	
	if (length($ordchar) == 1) { $ordchar = "00" . $ordchar; }
	if (length($ordchar) == 2) { $ordchar = "0" . $ordchar; }
	
	$retrcc = $retrcc  . $ordchar;
	
	$lcnt++;
	}
	

return ($retrcc);
}

 



sub decode_ps
{

my($cc) = @_;
my($rcc, $ccount, $ccount2, $rndchar, $rchar);

$lcnt = 0; $thrc = 1;
while ($lcnt < length($cc))
	{
	if ($thrc == 1) 
		{
		$to_dec = $to_dec . substr($cc, $lcnt, 1); 
		$thrc = 2;
		}
	elsif ($thrc == 2)
		{
		$to_dec = $to_dec . substr($cc, $lcnt, 1); 
		$thrc = 3;
		}
	elsif ($thrc == 3)
		{
		$to_dec = $to_dec . substr($cc, $lcnt, 1); 
		$thrc = 1;
		
		$real_c = $real_c . chr($to_dec);
		$to_dec = "";
		}
	
	$lcnt++;
	}

$cc = $real_c;

$cc = "_" . $cc;

####

  $rcc = ""; $ccount = 0; $d1 = 2;

  while ($ccount < length($cc) )
        {
            if ($d1 == 2)
            {
            $rchar = substr($cc, length($cc) - $ccount, 1);
            $rchar = ord($rchar);
            $rchar = $rchar - 1;
            $rchar = chr($rchar);
            $rcc = $rcc . $rchar;
            $d1 = 0;
            }
            $d1++;
            $ccount++;
        }

return (substr($rcc, 1, length($rcc)));

}







sub remove_html
{
($html_ecode) = @_;

$html_ecode =~ s/<[^>]*>//g;
$html_ecode =~ s/>//g;
$html_ecode =~ s/<//g;

my $h_removed = $html_ecode;

return ($h_removed);

}



sub insert_images
{
my ($ihtml, $iurl) = @_;

$crit = "<img src=\""; $ihtml =~ s/\[img\]/$crit/gi;
$crit = "\">"; $ihtml =~ s/\[\/img\]/$crit/gi;
$crit = "<a href=\"$iurl\"><img src=\""; $ihtml =~ s/\[imglnk\]/$crit/gi;
$crit = "\" border=\"0\"></a>"; $ihtml =~ s/\[\/imglnk\]/$crit/gi;							

return ($ihtml);
}


sub fill_cp_vars
{

my ($tofvar) = @_;

$tofvar =~ s/!!edit_account_details!!/$script_url\/rgs_editacc\.cgi/g;

return ($tofvar);
}



sub fill_vars
{

my ($filledvar) = @_;

$filledvar =~ s/!!scripts_url!!/$script_url/g;
$filledvar =~ s/!!tseeksearch!!/$script_url\/search\.cgi/g;
$filledvar =~ s/!build_url!/$web_url/g;
$filledvar =~ s/!!build_url!!/$web_url/g;

open (GSETT, "$data_dir/gsettings.dat");
	@conflines = <GSETT>;
close (GSETT);
$statsetting = $conflines[29];
chop($statsetting);


####
if ($statsetting =~ /dyn_stat=Dynamic/)
	{
	$filledvar =~ s/!!whatsnew!!/$script_url\/dirs\.cgi?newpop=new/g;
	$filledvar =~ s/!!tophits!!/$script_url\/dirs\.cgi?newpop=pop/g;
	}
	else
	{
	$filledvar =~ s/!!whatsnew!!/$web_url\/new\//g;
	$filledvar =~ s/!!tophits!!/$web_url\/pop\//g;
	}

$filledvar =~ s/!!modify_link_url!!/$script_url\/modify\.cgi/g;
$filledvar =~ s/!!add_url_link!!/$script_url\/addurl\.cgi/g;
$filledvar =~ s/!!add_premium_url_link!!/$script_url\/addurl\.cgi?p=1/g;
$filledvar =~ s/!!rgs_login!!/$script_url\/rgs_login\.cgi?p=1/g;

$topvar = pseek::get_file_contents("$data_dir/frontlink.dat");
if ($topvar eq ""){$filledvar =~ s/!!top!!/$script_url\/fp\.cgi/gi;}else{$filledvar =~ s/!!top!!/$topvar/gi;}

$filledvar =~ s/!!register!!/$script_url\/rgs_register\.cgi?p=1/g;
$filledvar =~ s/!!log_out!!/$script_url\/rgs_logout\.cgi/g;
$filledvar =~ s/!!advanced!!/$script_url\/searchadv\.cgi/g;
$filledvar =~ s/!!my_links!!/$script_url\/rgs_login\.cgi/g;
$filledvar =~ s/!!account_details!!/$script_url\/rgs_adet\.cgi/g;

$filledvar =~ s/!!retrieve_password!!/$script_url\/rgs_repass\.cgi/g;
$filledvar =~ s/!!resend_activation!!/$script_url\/rgs_resend2\.cgi/g;
$filledvar =~ s/!!favorites_link!!/$script_url\/fav\.cgi/g;



$query = new CGI;
$searched_keywords = $query->param('keywords');
$filledvar =~ s/!!keywords!!/$searched_keywords/g;


return ($filledvar);
}





sub get_cid_cat
{

my ($dstring) = @_;

my (@alldirs, $lvcount, $ccats, $item44, $readycat, $sqlstr, $sql, $cidret);

@alldirs = split (/\//, $dstring);

$lvcount = 1;
$ccats = "";
foreach $item44 (@alldirs)
	{
	$item44 =~ s/'/\\'/g;
	
	$ccats = $ccats . "(l" . $lvcount . " = '$item44') AND ";
	
	$readycat = substr($ccats, 0, length($ccats) - 4);
	
	$sqlstr = $sqlstr . "($readycat AND (level = '$lvcount')) OR";
	
	$lvcount++;
	}

$sqlstr = substr($sqlstr, 0, length($sqlstr) - 2);

$sql = "SELECT cid FROM dirs WHERE $sqlstr ORDER BY level";

#print "$sql \n\n";

### CONNECT TO DB
if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
$dbh = DBI->connect($dsn, $db_username, $db_password);
if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }


$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror - From: $sql";}

$cidret = "";
while ( @row = $sth->fetchrow() )
	{
	$cidret = $cidret . $row[0] . "-";
	}

$sth->finish;
$dbh->disconnect;

$cidret = substr($cidret, 0, length($cidret) - 1);

return ($cidret);

}




sub remove_leading_spacing
{
my ($ostring) = @_;
my ($ds, $wfound);

for ($ds = 0; $ds < length($ostring); $ds++) 
	{
	if ((substr($ostring, length($ostring) - 1, 1) eq " ") and ($wfound ne "true"))
		{
		chop($ostring);
		}
		else
		{
		$wfound = "true";
		}
	
	}

$chopped_string = $ostring;

return ($chopped_string);
}




sub send_email
{
my($sendername1, $fromemail1, $toemail1, $mail_subject1, $email_message1) = @_;

if ($mail_method eq "smtp_pm")
	{
	&send_mail_smtp_pm($toemail1, $fromemail1, $sendername1, $mail_subject1, $email_message1, $smtp_server);
	}
elsif ($mail_method eq "smtp")
	{
	&send_mail_smtp($toemail1, $fromemail1, $sendername1, $mail_subject1, $email_message1, $smtp_server);
	}
elsif ($mail_method eq "sendmail")
	{
	&send_mail_sendmail ($sendername1, $fromemail1, $toemail1, $mail_subject1, $email_message1);
	}
elsif ($mail_method eq "smtp_auth")
	{
	&send_mail_smtp_auth($toemail1, $fromemail1, $sendername1, $mail_subject1, $email_message1, $smtp_server, $smtp_user, $smtp_pass);	
	}
	

}









sub send_mail_smtp_auth
{

my ($to_email, $from_email, $from_name, $email_subject, $email_msg, $smtp_server_ss, $e_user, $e_pass) = @_;

$e_user = encode_base64($e_user);
$e_pass = encode_base64($e_pass);

chomp($e_user);
chomp($e_pass);

$remote = IO::Socket::INET->new(
 										Proto => "tcp",
                              PeerAddr  => $smtp_server_ss,
                              PeerPort  => 25
                                 );

        unless ($remote)
        		{
        		print "Connection failed when trying to connect to $smtp_server_ss";
        		$TCPconnect = "False";
        		exit;
        		}

open (MAITH, "> $data_dir/mailauth.log");

if ($TCPconnect ne "False")
	{
	$remote->autoflush(1);
	
	send($remote, "EHLO localhost\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "EHLO localhost -> $buffer\n";

	### AUTHENTICATE #####################################################
	
	send($remote, "AUTH LOGIN\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "AUTH LOGIN SENT -> $buffer\n";

	send($remote, "$e_user\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "$e_user - USER NAME SENT -> $buffer\n";

	send($remote, "$e_pass\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "$e_pass - PASS SENT -> $buffer\n";

	### SEND MAIL ########################################################
	
	send($remote, "MAIL From:<$from_email>\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "MAIL From [$from_email] -> $buffer\n";

	send($remote, "RCPT To:<$to_email>\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "RCPT To: [$to_email] -> $buffer\n";


	send($remote, "DATA\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "DATA -> $buffer\n";

	send($remote, "From: $from_name <$from_email>\r\n", 0);
	send($remote, "Subject: $email_subject\r\n", 0);
	
	send($remote, $email_msg, 0); ### SEND MESSAGE

	send($remote, "\r\n.\r\n", 0);
	send($remote, "QUIT\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "QUIT -> $buffer\n\n\n\n\n";
	
close $remote;

	}

close (MAITH);

}











sub send_mail_sendmail
{

# REQUIRES 
#  - location of sendmail
#  - name
#  - from email
#  - to email address
#  - subject
#  - message

my($sendername, $fromemail, $toemail, $mail_subject, $email_message) = @_;
my ($ftext);

$sendername =~ s/\n//g;
$fromemail =~ s/\n//g;
$toemail =~ s/\n//g;
$mail_subject =~ s/\n//g;

### check for attacks

$toemail =~ s/\;//g;
$toemail =~ s/^\s+//g;
$toemail =~ s/\s+$//g;
if ($toemail =~ /^\S+\@\S+$/)
{
$ftext = "<" . "$fromemail" . ">";

open (SENDMAIL, "| $sendmail $toemail");
print SENDMAIL <<End_of_Mail;
From: $sendername $ftext
To: $toemail
Reply-To: $fromemail
Subject: $mail_subject
Sender: $fromemail

$email_message

End_of_Mail
}
}






sub send_mail_smtp
{
my ($to_email, $from_email, $from_name, $email_subject, $email_msg, $smtp_server_ss) = @_;


$remote = IO::Socket::INET->new(
 										Proto => "tcp",
                              PeerAddr  => $smtp_server_ss,
                              PeerPort  => 25
                                 );

        unless ($remote)
        		{
        		print "Connection failed when trying to connect to $smtp_server_ss";
        		$TCPconnect = "False";
        		exit;
        		}

if ($TCPconnect ne "False")
	{
   sleep(1);
   $remote->autoflush(1);

	send($remote, "HELO localhost\n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /220/) { $remote_error = $buffer; }
	#print "HELO localhost -> $buffer <Br><Br>";

	if ($remote_error eq "")
	{
	send($remote, "MAIL From: <$from_email>\n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /250/) { $remote_error = $buffer; }
	#print "MAIL From [$from_email] -> $buffer <Br><Br>";
	}

	if ($remote_error eq "")
	{
	send($remote, "RCPT To: <$to_email>\n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /250/) { $remote_error = $buffer; }
	#print "RCPT To: [$to_email] -> $buffer <Br><Br>";
	}

	if ($remote_error eq "")
	{
	send($remote, "DATA\n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /250/) { $remote_error = $buffer; }
	#print "DATA -> $buffer <Br><Br>";
	}

	send($remote, "From: $from_email\n", 0); # was $from_name
	send($remote, "Subject: $email_subject\n", 0);

	send($remote, $email_msg, 0);

	send($remote, "\r\n.\r\n", 0);
	send($remote, "QUIT\n", 0);

close $remote;

	}

}






sub ts_insert_template_includes
{

my ($tmpl_page) = @_;


opendir(DIR,"$data_dir");
@files = readdir(DIR);
closedir(DIR);

if ($tmpl_page =~ /%%incl_/)
	{
	foreach $ifilen (@files)
		{
		if (substr($ifilen, 0, 5) eq "incl_")
			{
			$incl = $ifilen;
			$incl =~ s/\.html//g;
			$incl = "%%" . $incl . "%%";
				
				if ($tmpl_page =~ /$incl/)
					{
					$theincl = &get_file_contents ("$data_dir/$ifilen");
					$tmpl_page =~ s/$incl/$theincl/g;
					}
				
			}
		}
	}


########
$tmpl_settings = &get_file_contents ("$data_dir/gsettings.dat");
@tmpl_sett = split (/\n/, $tmpl_settings);

foreach $titem (@tmpl_sett)
	{
	if ($titem =~ /searchmeth/)
		{
		if ($titem =~ /fulltext/i)
			{
			$search_rpl = "$script_url/search2\.cgi";
			}
		}
	
	}

if ($search_rpl eq "") 
	{ 
	$tmpl_page =~ s/!!tseeksearch!!/$script_url\/search\.cgi/g;
	}
	else
	{
	$tmpl_page =~ s/!!tseeksearch!!/$search_rpl/g;
	}
#########


$tmpl_page =~ s/!build_url!/$web_url/g;
$tmpl_page =~ s/!!scripts_url!!/$script_url/g;
$tmpl_page =~ s/!!rgs_login!!/$script_url\/rgs_login\.cgi/g;


$topvar = pseek::get_file_contents("$data_dir/frontlink.dat");
if ($topvar eq ""){$tmpl_page =~ s/!!top!!/$script_url\/fp\.cgi/gi;}else{$tmpl_page =~ s/!!top!!/$topvar/gi;}

$tmpl_page =~ s/!!my_links!!/$script_url\/rgs_login\.cgi/g;
$tmpl_page =~ s/!!register!!/$script_url\/rgs_register\.cgi?p=1/g;
$tmpl_page =~ s/!!log_out!!/$script_url\/rgs_logout\.cgi/g;
$tmpl_page =~ s/!!advanced!!/$script_url\/searchadv\.cgi/g;
$tmpl_page =~ s/!!account_details!!/$script_url\/rgs_adet\.cgi/g;
$tmpl_page =~ s/!!retrieve_password!!/$script_url\/rgs_repass\.cgi/g;
$tmpl_page =~ s/!!resend_activation!!/$script_url\/rgs_resend2\.cgi/g;
$tmpl_page =~ s/!!favorites_link!!/$script_url\/fav\.cgi/g;


$query = new CGI;
$searched_keywords = $query->param('keywords');
$tmpl_page =~ s/!!keywords!!/$searched_keywords/g;

return ($tmpl_page);

}







sub decode_date
{

my ($tvalue) = @_;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst,@marray, $rdvalue, $ampm);

open (GSETT, "$data_dir/gsettings.dat");
	@conflines = <GSETT>;
close (GSETT);
$dateformat = $conflines[48];
chop($dateformat);


($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime($tvalue);
$year = "20" . substr($year, 1, 2);
@marray = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

if (length($min) == 1) {$min = "0" . $min;}
if (length($min) == 1) {$min = "0" . $min;}

if ($hour == 0){$hour = 12;}

if ($dateformat eq "date_format=0")
	{
	$rdvalue = "$marray[$mon] $mday, $year";
	}
	elsif ($dateformat eq "date_format=1")
	{
	$rdvalue = "$mday $marray[$mon] $year";
	}
	elsif ($dateformat eq "date_format=2")
	{
	$mon++;
	if (length($mday) == 1) { $mday = "0" . $mday; }
	if (length($mon) == 1) { $mon = "0" . $mon; }
	$rdvalue = "$year-$mon-$mday";
	}
	elsif ($dateformat eq "date_format=3")
	{
	$mon++;
	if (length($mday) == 1) { $mday = "0" . $mday; }
	if (length($mon) == 1) { $mon = "0" . $mon; }
	$rdvalue = "$mon-$mday-$year";
	}
	elsif ($dateformat eq "date_format=4")
	{
	$mon++;
	if (length($mday) == 1) { $mday = "0" . $mday; }
	if (length($mon) == 1) { $mon = "0" . $mon; }
	$rdvalue = "$mday-$mon-$year";
	}

#print "==>$dateformat $rdvalue <BR>";

return ($rdvalue);

}





sub new_gsettings
{
my $this = {};

$scnts = &get_file_contents("$data_dir/gsettings.dat");
@all_obj_items = split (/\n/, $scnts);

foreach $obji (@all_obj_items)
	{
	($obj_prp, $obj_val) = split (/=/, $obji);
	$this->{$obj_prp} = $obj_val;
	}

bless $this;
return $this;
}





sub encode_dir
{

my ($fstring) = @_;
my ($ms, $enc_string, $oneletter, $bstr);

$fstring =~ s/ /_/g;

 for ($ms = 0; $ms < length($fstring); $ms++) 
	{
	
	$oneletter = substr($fstring, $ms, 1);
	
	if (($oneletter !~ /[0-9a-zA-Z]/) and ($oneletter ne "_"))
		{
			$bstr = ord($oneletter);
			if (length($bstr) == 1) {$bstr = "00" . $bstr;}
			if (length($bstr) == 2) {$bstr = "0" . $bstr;}
			$bstr = "," . $bstr;
			$enc_string = $enc_string . $bstr;
		}
		else
		{
			$enc_string = $enc_string . $oneletter;
		}
	}

return ($enc_string);

}






sub decode_dir
{

my ($coded_string) = @_;
my ($ms, $oneletter, $decoded_string, $plusval, $dechar, $fdchar);

$coded_string =~ s/_/ /g;

$plusval = 0;

 for ($ms = 0; $ms < length($coded_string); $ms++) 
	{
	$oneletter = substr($coded_string, $ms, 1);

	if ($plusval != 0)
		{
		$plusval++;
		if ($plusval == 4) {$plusval = 0;}
		}
	elsif ($oneletter eq ",")
		{
		$dechar = substr($coded_string, ($ms+1), 3);
		$dechar = int($dechar);
		$dechar = chr($dechar);
		
		$dechar =~ s/<//g;
		
		$decoded_string = $decoded_string . $dechar;
		$plusval++;
		}
	else 
		{
		$decoded_string = $decoded_string . $oneletter;
		}

	}

return($decoded_string);
}



#####################################

sub get_file_contents
{

my ($filename) = @_;
my ($filesize, $filesize, $thefile);

if ((-e "$filename") > 0) 
	{
$filesize = (-s "$filename");
open (TFILECNTS, "$filename") || die "$filename";
	read(TFILECNTS,$thefile,$filesize);
close (TFILECNTS);
	}

return ($thefile);

}





sub get_rating_images
{
my ($rating) = @_;
my ($image_rate, $decm, $images);

	if ($rating > 0)
			{
			($image_rate, $decm) = split (/\./, $rating);
		
			if (length($decm) == 1)
				{
				if ($decm > 4) {$image_rate++;}
				}
			if (length($decm) == 2)
				{
				if ($decm > 49) {$image_rate++;}
				}
		
			$image_rate = "r" . $image_rate . ".gif";
			$image_rate =~ s/ //g;
			$images = "<img src=\"$web_url/$image_rate\">";
			}

return ($images);
}




sub setCookie
{
my($name, $value) = @_;

$query = new CGI;

$tcookie = $query->cookie(-name=>$name,
	     -value=>$value,
        -expires=>'+12M');
print "Set-Cookie: $tcookie\n";
}






sub getCookies
{
my (@rawCookies1);

$query = new CGI;

	$rwc = 0;
	foreach $name ($query->cookie()) 
			{
			$rawCookies1[$rwc] = $name . "=" . $query->cookie($name);
         $rwc++;
         }

	#foreach $item (@rawCookies1){print "==> $item <br>";}

return (@rawCookies1);
}





sub send_mail_smtp_pm
{

my ($to_email, $from_email, $from_name, $email_subject, $email_msg, $smtp_server_ss) = @_;

#print "$to_email, $from_email, $from_name, $email_subject, $email_msg, $smtp_server_ss";

eval('use Net::SMTP; 1;') or acs::problem_popup("The Perl module called Net::SMTP is not installed. Please install it. Perl version $]");


   $smtp = Net::SMTP->new($smtp_server_ss,
			  Hello => $smtp_server_ss,
			  Timeout => 30,
			  Debug   => 0
			  );

    $smtp->mail($to_email);
    $smtp->to($to_email);
    
    $smtp->data();
    $smtp->datasend("To: $to_email\n");
    $smtp->datasend("From: $from_name <$from_email>\n");
    $smtp->datasend("Subject: $email_subject\n");
    $smtp->datasend("\n");
    $smtp->datasend("$email_msg\n");
    $smtp->dataend();

    $smtp->quit;    


}





sub get_more_info_file_name
{

my ($title_without_link) = @_;

		$title_without_link_tmp = $title_without_link;
		
			$more_info_pg_name = ""; $title_without_link_tmp =~ s/ /_/gi;
			for ($ms = 0; $ms < length($title_without_link_tmp); $ms++) 
				{
				$oneletter1 = substr($title_without_link_tmp, $ms, 1);
					if (($oneletter1 =~ /[0-9a-zA-Z]/) or ($oneletter1 eq "_"))
					{
					$more_info_pg_name = $more_info_pg_name . $oneletter1;
					}
				}
			$more_info_pg_name = lc($more_info_pg_name);
			if (length($more_info_pg_name) > 80) { $more_info_pg_name = substr($more_info_pg_name, 0, 80); }
			

return ($more_info_pg_name);

}




#### 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 =~ /^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 =~ /^MYSQL_HOSTNAME/){$mysql_hostname = &get_setup_line($line, MYSQL_HOSTNAME);}
if ($line =~ /^MYSQL_PORT/){$mysql_port = &get_setup_line($line, MYSQL_PORT);}

if ($line =~ /^SCRIPT_URL/){$script_url = &get_setup_line($line, SCRIPT_URL);}
if ($line =~ /^ADMIN_URL/){$admin_url = &get_setup_line($line, ADMIN_URL);}
if ($line =~ /^WEB_URL/){$web_url = &get_setup_line($line, WEB_URL);}
if ($line =~ /^WEB_DIR/){$web_dir = &get_setup_line($line, WEB_DIR);}
if ($line =~ /^DATA_DIR/){$data_dir = &get_setup_line($line, DATA_DIR);}

if ($line =~ /^USERNAME/){$username = &get_setup_line($line, USERNAME);}
if ($line =~ /^PASSWORD/){$password = &get_setup_line($line, PASSWORD);}

if ($line =~ /^MAIL_METHOD/){$mail_method = &get_setup_line($line, MAIL_METHOD);}
if ($line =~ /^SENDMAIL/){$sendmail = &get_setup_line($line, SENDMAIL);}
if ($line =~ /^SMTP_SERVER/){$smtp_server = &get_setup_line($line, SMTP_SERVER);}
if ($line =~ /^SMTP_USER/){$smtp_user = &get_setup_line($line, SMTP_USER);}
if ($line =~ /^SMTP_PASS/){$smtp_pass = &get_setup_line($line, SMTP_PASS);}


			}
	close (STP);
	
	}
}




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;
