#!/usr/bin/perl
package acs;
########################################################################
# 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"; ## <-- CHANGE THIS LINE TO THE FULL SERVER PATH TO 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 DBI;
use IO::Socket;
use MIME::Base64 qw(decode_base64 encode_base64);
require Exporter;
use vars qw/@ISA @EXPORT @EXPORT_OK $copyright $prgname/;
@ISA = qw(Exporter);
@EXPORT = qw(check_access
get_template
encode_dir
decode_dir
problem_popup
get_chopped_path
remove_leading_spacing
update_numbers
get_location_string
get_file_contents
get_last_dirname
get_rid
decode_complete_dir
get_extra_vars
decode_date
extend_login
update_setting
htmlencode
get_heading_box
write_config
psmakedir
update_cat_numbers
get_tooltip
);
@EXPORT_OK = qw($template1
$enc_string
$decoded_string
$chopped_path
$chopped_string
$locstr_ret
$thefile
$drval
$mcid_str
$decstr
$extrakfd
$rdvalue
$str2
$h_return
$dir_to_create
$tootltipd);
$thetime = time();
($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime($thetime);
$year = "20" . substr($year, 1, 2);
$version = "PowerSeek SQL Version 4.2.1";
$prgname = "PowerSeek Version 4.2.1";
$copyright = "Copyright 2003-$year FocalMedia.Net";
$default_permissions = 0777; ### PERMISSIONS THAT IS USED FOR TEMPORARY DATA FILES
&get_setup;
##################################################################################################################
sub get_tooltip
{
# border-right-width: 1px;
# border-bottom-width: 1px;
$tootltipd = qq[
];
return ($tootltipd);
}
sub write_config
{
my ($conf_item, $conf_value) = @_;
open (GSETT, "$data_dir/gsettings.dat");
@conflines = ;
close (GSETT);
foreach $ccitem (@conflines)
{
($obj, $ident) = split (/=/, $ccitem);
if ($obj eq $conf_item)
{
$newfile = $newfile . $conf_item . "=" . $conf_value . "\n";
}
else
{
$newfile = $newfile . $ccitem;
}
}
open (GSETT, "> $data_dir/gsettings.dat");
print GSETT $newfile;
close (GSETT);
}
sub update_cat_numbers
{
my ($cid_id, $link_number_counter) = @_; ### CID / NUMBERS TO ADD
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 cid, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, shortname
FROM dirs WHERE cid = '$cid_id'";
$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";}
$nrcounter = 0;
while ( @row = $sth->fetchrow() )
{
$cats = "";
for ($ms = 1; $ms < 17; $ms++)
{
if ($row[$ms] ne "")
{
$cats = $cats . $row[$ms] . "::-::";
}
}
$cats = substr($cats, 0, length($cats) - 5);
}
@to_update_cat = split (/::-::/, $cats);
$lvc = 1;
foreach $catlevel (@to_update_cat)
{
$catlevel = $dbh->quote($catlevel);
$levelsql = $levelsql . " (l" . $lvc . " = $catlevel) AND";
$use_levelsql = $levelsql . " (l" . ($lvc + 1) . " = '')";
$sql = "UPDATE dirs SET linknrs = linknrs + $link_number_counter WHERE $use_levelsql";
$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";}
$lvc++;
}
if (defined($sth)){$sth->finish; }
$dbh->disconnect;
}
sub quick_help
{
my ($help_heading, $help_text) = @_;
$helpcrit = qq[
 |
|
];
return ($helpcrit);
}
sub get_heading_box
{
my ($h_icon, $h_heading, $h_text) = @_;
$h_return = qq[

|
|
];
return ($h_return);
}
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 = ;
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 = &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/!!favorites_link!!/$script_url\/fav\.cgi/g;
$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;
$query = new CGI;
$searched_keywords = $query->param('keywords');
$filledvar =~ s/!!keywords!!/$searched_keywords/g;
return ($filledvar);
}
sub update_setting
{
my ($keyname, $keyval) = @_;
$scnts = &get_file_contents("$data_dir/gsettings.dat");
@allitems = split (/\n/, $scnts);
foreach $item (@allitems)
{
($sobj, $sval) = split (/=/, $item);
if ($sobj eq $keyname)
{
$the_setting = $the_setting . "$sobj=$keyval\n";
}
else
{
$the_setting = $the_setting . $item . "\n";
}
}
open (PSETTINGS, "> $data_dir/gsettings.dat");
print PSETTINGS $the_setting;
close (PSETTINGS);
}
sub get_extra_vars
{
my ($keydata1, @akeys1, $knr1, $kcount1, $k_item1,
$k_keyname1, $k_visible1, $k_size1, $k_searched1, $k_description1, $k_image1, $extrakfd);
$keydata1 = &get_file_contents("$data_dir/keys.dat");
@akeys1 = split (/\n/, $keydata1);
$knr1 = @akeys1;
if ($knr1 > 0)
{
$kcount1 = 0;
foreach $k_item1 (@akeys1)
{
($k_keyname1, $k_visible1, $k_size1, $k_searched1, $k_description1, $k_image1, $tmp, $nmbup) = split (/\t/, $k_item1);
if ($nmbup ne "Upload")
{
$extrakfd = $extrakfd . "%%$k_keyname1%%
";
$kcount1++;
}
}
}
return ($extrakfd);
}
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\n 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 decode_complete_dir
{
my ($complete_dir) = @_;
my (@dits, $dritem, $decstr);
@dits = split (/-/, $complete_dir);
$decstr = "Root ";
foreach $dritem (@dits)
{
$decstr = $decstr . " > " . &decode_dir($dritem);
}
return ($decstr);
}
#######################
sub get_rid
{
my ($ecat) = @_;
@dcats = split (/-/, $ecat);
$gcntr = 0;
$lvcnt = 1;
foreach $item (@dcats)
{
$item = &decode_dir($item);
$item =~ s/'/\\'/g;
$fieldnames[$gcntr] = "l" . $lvcnt;
$fieldvalues[$gcntr] = $item;
$fncount = 0;
$fieldsel = "";
foreach $field_name_item (@fieldnames)
{
$fieldsel = $fieldsel . " ($field_name_item = '$fieldvalues[$fncount]') and";
$fncount++;
}
$fieldsel = substr($fieldsel, 0, length($fieldsel) -3);
$qstring = $qstring . " ((level = '$lvcnt') and $fieldsel) or";
$lvcnt++;
$gcntr++;
}
$qstring = substr($qstring, 0, length($qstring) - 2);
$qstring = "SELECT cid,level FROM dirs WHERE $qstring ORDER BY level ASC";
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("$qstring");
if ( !defined $dbh ) {die "Cannot connect to mSQL server: $DBI::errstr\n"; }
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";}
$mcid_str = "";
$updc = 0;
while ( @row = $sth->fetchrow() )
{
$mcid_str = $mcid_str . "$row[0]" . "-";
}
$mcid_str = substr($mcid_str, 0, length($mcid_str) -1);
$sth->finish;
$dbh->disconnect;
return ($mcid_str);
}
sub get_last_dirname
{
my ($complete_dir) = @_;
@allds = split (/-/, $complete_dir);
$dnr = @allds; $dnr = $dnr - 1;
$drval = $allds[$dnr];
$drval = &decode_dir($drval);
return ($drval);
}
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 get_file_contents
{
my ($filename) = @_;
my ($filesize, $thefile);
if ((-e "$filename") > 0)
{
$filesize = (-s "$filename");
open (TFILECNTS, "$filename") || die "$filename";
read(TFILECNTS,$thefile,$filesize);
close (TFILECNTS);
}
return ($thefile);
}
sub update_numbers
{
my ($plus_minus, $nr, $ctg) = @_;
my (@allds, $item, $qsel);
$nowtime = time();
@allds = split (/-/, $ctg);
$qc = 0;
$lvl = 1;
$qstring = "SELECT cid, level, linknrs FROM dirs WHERE ";
foreach $item (@allds)
{
$qstring = $qstring . "(cid = '$item') or ";
}
$qstring = substr ($qstring, 0, length($qstring) - 3);
$qstring = $qstring . " ORDER BY level";
#print "$qstring
";
########
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("$qstring");
if ( !defined $dbh ) {die "Cannot connect to mSQL server: $DBI::errstr\n"; }
$sth->execute;
$updc = 0;
while ( @row = $sth->fetchrow() )
{
if ($plus_minus eq "+")
{
$updatetime = ",newindate = '$nowtime'";
$newc = $row[2] + $nr;
}
else
{
$newc = $row[2] - $nr;
}
$update_arr[$updc] = "$row[0]-$row[1]-$newc";
$updc++;
#print "=> $row[0]-$row[1]-$newc
";
}
foreach $item (@update_arr)
{
($icid, $ilv, $link_count) = split (/-/, $item);
$sth = $dbh->prepare("UPDATE dirs SET linknrs = '$link_count'
$updatetime
WHERE cid = '$icid'");
if ( !defined $dbh ) {die "Cannot connect to mSQL server: $DBI::errstr\n"; }
$sth->execute;
}
$sth->finish;
$dbh->disconnect;
}
sub get_location_string
{
my ($lcstring) = @_;
my (@als, $item);
@als = split (/-/, $lcstring);
$locstr_ret = "Root";
foreach $item (@als)
{
$locstr_ret = $locstr_ret . " > " . &decode_dir($item);
}
return ($locstr_ret);
}
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 get_chopped_path
{
my ($fpath) = @_;
$chopped_path = "";
@alldi = split (/\//, $fpath);
$inr = @alldi;
$inr = $inr -1;
for ($ds = 0; $ds < $inr; $ds++)
{
if ($ds != 0)
{
$chopped_path = $chopped_path . "/$alldi[$ds]";
}
else
{
$chopped_path = $chopped_path . "$alldi[$ds]";
}
}
return ($chopped_path);
}
######################
sub check_access
{
my ($TheUsername, $ThePassword, $EnteredUser, $EnteredPass) = @_;
my ($usercookie, $passcookie, $query);
if ($TheUsername =~ /'/) { &wrongps_screen; } if ($TheUsername =~ /\\/) { &wrongps_screen; }
if ($ThePassword =~ /'/) { &wrongps_screen; } if ($ThePassword =~ /\\/) { &wrongps_screen; }
if ($EnteredUser =~ /'/) { &wrongps_screen; } if ($EnteredUser =~ /\\/) { &wrongps_screen; }
if ($EnteredPass =~ /'/) { &wrongps_screen; } if ($EnteredPass =~ /\\/) { &wrongps_screen; }
if (-e "$web_dir/$db_name.sql")
{
$tmp = unlink("$web_dir/$db_name.sql");
}
if (($username ne "") and ($password ne "")) ### IF CONTROL PANEL USER/PASS ENABLED
{
$query = new CGI;
$usercookie = $query->cookie('nuser');
$passcookie = $query->cookie('npass');
#print "Content-type: text/html\n\n";
#print "==> $usercookie $passcookie";
if (($EnteredUser ne "") and ($EnteredPass ne "")) {&do_login ($EnteredUser, $EnteredPass);}
if (($usercookie eq "") and ($passcookie eq "")){&login_screen;}
if (($usercookie ne $TheUsername) or ($passcookie ne $ThePassword)){&wrongps_screen;}
}
}
sub extend_login
{
$query = new CGI;
$thecookie1 = $query->cookie(-name=>'nuser',
-value=>$username,
-expires=>'+24h',
-path=>'/');
$thecookie2 = $query->cookie( -name=>'npass',
-value=>$password,
-expires=>'+24h',
-path=>'/');
print $query->header(-cookie=>[$thecookie1, $thecookie2]);
}
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=>'+24h',
-path=>'/');
$thecookie2 = $query->cookie( -name=>'npass',
-value=>$form_password,
-expires=>'+24h',
-path=>'/');
print $query->header(-cookie=>[$thecookie1, $thecookie2]);
#print "Content-type: text/html\n\n";
$rndnr = rand(100);
print "
Powerseek
";
exit;
}
sub login_screen
{
my ($scripts_admin);
my $newquery = CGI->new;
print $newquery->header();
print $newquery->start_html("Control Panel");
print <
Login