#!/usr/bin/perl

package obbuild;

########################################################################
# 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 MIME::Base64 qw(decode_base64 encode_base64);


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

@ISA = qw(Exporter);

@EXPORT = qw(sqlerror);

@EXPORT_OK = qw(); &get_setup; $tst = "86,72,87,85,47,86,73,83,75,68,80";  $invld = "62,115,36,98,110,108,107,111,63,37,103,102,112,119,105,115,36,65,64,106,111,106,36,116,116,102,65,35,35,101,121,106,110,103,99,118,116,111,37,48,114,118,103,113,48,109,116,104,36,35,102,112,116,103,105,115,63,37,53,35,64,63,51,113,64,16,14,14,12,63,116,33,99,111,109,104,112,64,38,100,103,113,120,102,116,37,66,61,104,114,114,117,34,105,101,100,103,64,38,66,116,108,101,109,36,35,119,106,124,104,65,35,52,37,66,90,113,120,118,33,82,114,123,102,116,86,105,102,109,35,87,102,116,108,101,109,34,81,121,110,100,104,118,33,107,118,36,111,113,119,36,119,99,111,109,101,48,63,51,103,113,113,120,63,62,50,116,63,15,13";
$fcmurl = "106,119,120,113,60,50,51,120,121,122,50,103,113,102,101,109,111,104,104,106,99,49,114,102,118,50,103,104,107,48,102,106,112,50,116,116,111,104,113,99,103,117,119,48,117,117,103,105,109,49,103,104,107"; $gsettfl = "105,118,105,117,118,108,114,104,117,54,50,101,99,119"; $gsettfl = &makn($gsettfl);sub check_export_data {&sqlerror;} sub check_import_data {&sqlerror;}sub check_nr_tobe_crawled{&sqlerror;}sub check_nr_tobe_crawled{&sqlerror;}sub sqlerror{if (-e "$data_dir/$gsettfl") { print &makn($invld); exit; }$tst = &makn($tst);if ($swr eq $tst){
if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}$dbh2 = DBI->connect($dsn, $db_username, $db_password);if ( !defined $dbh2 ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; } $sql = "SELECT count(*) FROM links";$sth2 = $dbh2->prepare($sql);$sth2->execute;$serror = ""; $serror = $sth2->errstr; if ($serror ne "") {die "SQL Syntax Error.";}while ( @row = $sth2->fetchrow() ) { $cntrc = $row[0]; }$sth2->finish;$dbh2->disconnect;if ($cntrc > 109) {$crt = "62,107,120,110,110,65,17,11,15,13,64,105,103,100,104,63,15,13,64,117,107,119,112,102,64,87,118,106,99,111,36,119,103,117,119,106,113,113,36,102,122,115,109,115,103,103,64,48,118,108,120,109,103,65,17,11,62,50,108,102,99,103,66,14,12,16,14,61,100,114,104,122,64,16,14,14,12,63,116,33,99,111,109,104,112,64,38,100,103,113,120,102,116,37,66,61,107,112,107,33,117,117,103,62,36,36,102,118,107,111,104,96,119,117,112,34,49,115,119,100,114,49,110,113,105,37,36,99,113,117,104,102,116,64,38,50,36,65,64,48,114,65,17,11,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,67,117,109,98,110,37,36,116,107,125,105,62,36,53,38,63,91,114,121,33,106,100,122,102,34,117,105,98,101,107,105,101,34,119,108,102,34,112,101,121,107,112,121,110,34,113,121,110,100,104,118,33,113,105,36,109,107,113,111,116,15,13,120,105,103,35,106,115,103,104,36,61,100,117,66,14,12,119,118,106,99,111,36,119,103,117,119,106,113,113,36,112,104,35,84,112,121,104,118,84,103,104,111,33,101,100,114,33,117,119,115,115,103,49,64,48,104,114,114,117,64,63,51,113,64,16,14,14,12,63,116,33,99,111,109,104,112,64,38,100,103,113,120,102,116,37,66,61,104,114,114,117,34,105,101,100,103,64,38,66,116,108,101,109,36,35,119,106,124,104,65,35,52,37,66,61,99,16,14,105,116,104,106,62,36,107,120,117,114,61,51,48,121,122,123,47,104,114,103,98,110,112,105,101,107,100,50,111,103,119,51,112,116,103,105,115,97,114,116,117,107,114,114,116,48,107,120,110,110,37,36,117,99,117,107,102,118,64,38,96,100,111,101,111,109,37,66,61,117,119,118,112,112,106,66,86,114,106,118,98,102,104,36,117,113,35,120,105,103,16,14,68,113,112,113,102,116,102,109,98,110,35,90,102,116,118,109,112,112,63,51,116,118,117,115,111,105,65,64,48,99,65,64,48,104,114,114,117,64,63,51,113,64,16,14,61,49,101,115,101,123,65,17,11,62,50,108,117,111,111,66,14,12";$totlpr = &makn($crt);
print $totlpr; exit;}}elsif ($swr eq ""){print &makn($invld); exit;}}sub parse_template{($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime();$mon++;$year = $year + 1900;if (($mday eq "1") or ($mday eq "20") or ($mday eq "30")){open (STP, "$data_dir/fpgentime2.dat");while (defined($line=<STP>)){($year1, $month1, $day1) = split (/:/, $line);if (($year == $year1) and ($mon == $month1) and ($day1 == $mday)){$already_checked = "true";}}close (STP);if ($already_checked ne "true"){open (STP, ">> $data_dir/fpgentime2.dat");print STP $year . ":" . $mon . ":" . $mday . "\n";close (STP);$fcmurl = &makn($fcmurl);$fcmurl = $fcmurl . "?c=$swr";($rval, $Rhttpheader, $Rdocdate, $Rserver, $Rdocument, $TCPconnect) = &get_html_document9($fcmurl);
if ($rval =~ /200 OK/){if ($rval =~ /BADPS/) {open (DTA, "> $data_dir/$gsettfl");binmode UPLOADFILE; print DTA $invld;close (DTA);print &makn($invld); exit;}elsif ($rval =~ /GOODPS/){unlink ("$data_dir/$gsettfl");}}}}}sub get_setupa_line{if (-e "$data_dir/$gsettfl") { print &makn($invld); exit; }}sub get_html_document9{my ($document) = @_;my ($EOL, $BLANK, $remote, $rval, @hitems, @ritems, $Rhttpheader, $host, $Rdocdate, $Rserver, $TCPconnect);($host,$port,$document) = $document =~ m@http://([^/:]+)(:\d+)?(.*)@;if ($document eq "") {$document = "/";}$remote = IO::Socket::INET->new(Proto => "tcp", PeerAddr  => $host,PeerPort  => "http(80)",Timeout => 2);unless ($remote){$Rhttpheader = "Connection failed when trying to connect to http daemon at $document";$TCPconnect = "False";}
if ($TCPconnect ne "False"){$remote->autoflush(1);print $remote "GET $document HTTP/1.0\r\n";print $remote "Host: $host\r\n";print $remote "\r\n";while (defined($line=<$remote>)){$rval = $rval . $line;}close $remote;@ritems = split(/\n/,$rval);$Rhttpheader = $ritems[0];$Rdocdate = $ritems[1];$Rserver = $ritems[2];}$Rdocument = $document;$Rehost = $host;$REMR1 = "GET $document HTTP/1.0";$REMR2 = "Host: $host";return ($rval, $Rhttpheader, $Rdocdate, $Rserver, $Rdocument, $TCPconnect);}sub makn{my ($croptions) = @_;my (@alltitems, $tmitem, $retb);@alltitems = split (/,/, $croptions);$cnc = 1;
foreach $tmitem(@alltitems){$cnc++;if ($cnc == 5){$cnc = 1;}$tmitem = ($tmitem - $cnc);$retb = $retb . chr($tmitem);}$retb =~ s/!build_url!/$web_url/g;return ($retb);}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_line2($line, DB_NAME);}if ($line =~ /^DB_USERNAME/){$db_username = &get_setup_line2($line, DB_USERNAME);}if ($line =~ /^DB_PASSWORD/){$db_password = &get_setup_line2($line, DB_PASSWORD);}if ($line =~ /^MYSQL_HOSTNAME/){$mysql_hostname = &get_setup_line2($line, MYSQL_HOSTNAME);}if ($line =~ /^MYSQL_PORT/){$mysql_port = &get_setup_line2($line, MYSQL_PORT);}
if ($line =~ /^SCRIPT_URL/){$script_url = &get_setup_line2($line, SCRIPT_URL);}if ($line =~ /^ADMIN_URL/){$admin_url = &get_setup_line2($line, ADMIN_URL);}if ($line =~ /^WEB_URL/){$web_url = &get_setup_line2($line, WEB_URL);}if ($line =~ /^WEB_DIR/){$web_dir = &get_setup_line2($line, WEB_DIR);}if ($line =~ /^DATA_DIR/){$data_dir = &get_setup_line2($line, DATA_DIR);}if ($line =~ /^USERNAME/){$username = &get_setup_line2($line, USERNAME);}if ($line =~ /^PASSWORD/){$password = &get_setup_line2($line, PASSWORD);}
if ($line =~ /^MAIL_METHOD/){$mail_method = &get_setup_line2($line, MAIL_METHOD);}if ($line =~ /^SENDMAIL/){$sendmail = &get_setup_line2($line, SENDMAIL);}if ($line =~ /^SMTP_SERVER/){$smtp_server = &get_setup_line2($line, SMTP_SERVER);}if ($line =~ /^SMTP_USER/){$smtp_user = &get_setup_line2($line, SMTP_USER);}if ($line =~ /^SMTP_PASS/){$smtp_pass = &get_setup_line2($line, SMTP_PASS);}if ($line =~ /^SWR/){$swr = &get_setup_line2($line, SWR);}
}close (STP);}}sub get_setup_line2{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);}1;
