#!/usr/bin/perl
########################################################################
# 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 DBI;
use pseek;
use fmspm;
&get_setup;
fmspm::check_spamb("rprtb2.cgi", "header", "$data_dir");
$q = CGI->new;
#################
$lnkid = $q->param('id'); $lnkid =~ s/[^0-9]//g;
$cid = $q->param('cid'); $cid =~ s/[^0-9]//g;
if (($cid eq "") or ($lnkid eq "")) { print "Error: Invalid link"; exit; }
### CHECK IMAGE AUTHENTICATION IF REQUIRED
$gsettings = new_gsettings tseek;
if ($gsettings->{img_auth_brlinks} eq "Yes")
{
$img_auth_check = pseek::check_img_auth;
if ($img_auth_check eq "false")
{
$addurltext = pseek::get_file_contents("$data_dir/addurl2.txt");
@ctexts = split (/\n/, $addurltext);
$brtempl = pseek::get_file_contents("$data_dir/brokenlink.html");
$brtempl =~ s/!!problem!!/$ctexts[15]/gi;
$imgbox = pseek::get_imgboxes;
($imdisp, $imgnames) = split (/:::/, $imgbox);
$imgnames =~ s/\.gif//gi;
$hinv = qq[ ];
$brtempl =~ s/<\/form>/$hinv<\/form>/gi;
$brtempl =~ s/%%imgbox%%/$imdisp/g;
$brtempl =~ s/!build_url!/$web_url/g;
$brtempl =~ s/!!build_url!!/$web_url/g;
$brtempl = pseek::ts_insert_template_includes($brtempl);
$brtempl = pseek::fill_vars($brtempl);
$cid = $q->param('cid'); $cid =~ s/[^0-9]//g;
$lnkid = $q->param('id'); $lnkid =~ s/[^0-9]//g;
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 LINK INFO
$wsql = "SELECT * FROM links WHERE lnkid = '$lnkid'";
$sth = $dbh->prepare($wsql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror - From: $wsql";}
while ( @row = $sth->fetchrow() )
{
$title_with_link = $row[2];
$url = $row[5];
}
if (($url eq "http://") or ($url eq ""))
{
$title_with_link = "$title_with_link";
}
else
{
$title_with_link = "$title_with_link";
}
$brtempl =~ s/%%title_with_link%%/$title_with_link/gi;
$brtempl =~ s/!!title_with_link!!/$title_with_link/gi;
$brtempl =~ s/!!id!!/$lnkid/gi;
$brtempl =~ s/!!cid!!/$cid/gi;
$brtempl =~ s/!!broken_link_script!!/$script_url\/rprtb2\.cgi/gi;
$notesbox = qq[];
$brtempl =~ s/%%notesbox%%/$notesbox/gi;
$brtempl = pseek::insert_go_back_buttons($brtempl, $lnkid, $cid);
##### iNSERT IMAGES
$sth->finish;
$dbh->disconnect;
print "Content-type: text/html\n\n";
print "$brtempl";
exit;
}
}
$link_problem = $q->param('problem'); $link_problem =~ s/'/\\'/g;
$link_notes = $q->param('notes'); $link_notes =~ s/'/\\'/g; $link_notes =~ s//g; $link_notes =~ s/>//g;
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 = "INSERT INTO brokenlnks SET lnkid = '$lnkid',
cid = '$cid',
lnkproblem = '$link_problem',
lnknotes = '$link_notes'";
$sth = $dbh->prepare($sql);
$sth->execute;
#$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror - From: $sql";}
$sth->finish;
$dbh->disconnect;
$gsettings = new_gsettings tseek;
$stemplte = pseek::get_file_contents("$data_dir/brokenlink_success.html");
$stemplte = pseek::ts_insert_template_includes($stemplte);
$stemplte = pseek::fill_vars($stemplte, $gsettings->{dyn_stat});
$stemplte = pseek::insert_go_back_buttons($stemplte, $lnkid, $cid);
print "Content-type: text/html\n\n";
print "$stemplte";
sub get_setup
{
$exists = (-e "$config_cgi");
if ($exists > 0)
{
open (STP, "$config_cgi");
while (defined($line=))
{
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);}
}
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 ########################################################