#!/usr/bin/perl -w
use strict;
use warnings;
use CGI;
use Search2;
my $query = CGI->new ;
my $search = Search2->new;
loadPage ();
sub loadPage {
my $page = "";
$page = $query->param("page");
if ($page eq 'search') {
$search->say_hello();
}else {
print "Content-Type: text/html\n\n";
print "error";
}
}
####
#!/usr/bin/perl -w
package Search2;
use strict;
use MyDB;
use SharedVariable qw ($action $session_dir $dir $dirLang $dirError $imgdir $session_id $can_do_gzip $current_ip $lang $LANG %ARTICLE %SESSION %SERVER %USER $CGISESSID %LABEL %ERROR %VALUE $COMMANDID %COMMAND %DATE %PAYPALL $INDEX %LINK $query $session $host $t0 $client);
use LoadProperties;
our $db = MyDB->new();
our $lp = LoadProperties->new();
sub new {
my $class = shift;
my ($opts)= @_;
my $self = {};
return bless $self, $class;
}
sub search {
}
sub do_search {
}
sub do_search_indexed {
}
sub say_hello () {
print "Content-Type: text/html\n\n";
print "Hello Search Package";
}
BEGIN {
use Exporter ();
@DB::ISA = qw(Exporter);
@DB::EXPORT = qw();
@DB::EXPORT_OK = qw(new say_hello);
}
1;
####
package SharedVariable;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Time::HiRes qw(gettimeofday);
use Compress::Zlib;
use CGI::Session qw/-ip-match/;
use vars qw (%ENV $session_dir $cookie $page $dir $dirLang $dirError $imgdir $action $t0 $session_id $can_do_gzip $current_ip $lang $LANG %ARTICLE %SESSION %SERVER %USER $CGISESSID %LABEL %ERROR %VALUE $COMMANDID %COMMAND %DATE %PAYPALL $INDEX %LINK $query $session $host $t0 $client);
#Set the values to the global variables
$query = CGI->new ;
$cookie = "";
$current_ip = $ENV{'REMOTE_ADDR'};
$client = $ENV{'HTTP_USER_AGENT'};
$t0 = gettimeofday();
$host = "http://avant-garde.no-ip.biz";
%ERROR = ();%LABEL = ();$LANG = "";%LINK = ();%ARTICLE = ();%SESSION = ();%SERVER = (); %
$action = $query->param('action');
$page = $query->param("page");
$session_id = $query->param('session');
$can_do_gzip = ($ENV{'HTTP_ACCEPT_ENCODING'} =~ /gzip/i) ? 1 : 0;
$dir = "/home/alexandre/apache/site/recordz1/";
$dirLang = "/home/alexandre/apache/site/recordz1/lang";
$dirError = "/home/alexandre/apache/site/recordz1/lang";
$imgdir= "/home/alexandre/apache/site/recordz1/upload";
$session_dir = "/home/alexandre/apache/site/recordz/sessions";
$action = $query->param('action');
$session_id = $query->param('session');
#load html label
loadLanguage ();
#load error label
loadError();
sub new {
my $class = shift;
my ($opts)= @_;
my $self = {};
return bless $self, $class;
}
sub loadLanguage {
$lang = "FR";
$lang = $query->param("lang");
#$lang = substr ($ENV{'HTTP_ACCEPT_LANGUAGE'},0,2);
#$lang =~ s/[^A-Za-z0-9 ]//;
$lang = uc ($lang);
open (FILE, "<$dirLang/$lang.conf") or die "cannot open file $dirLang/$lang.conf";
while () {
(my $label, my $value) = split(/=/);
$SERVER{$label} = $value;
}
close (FILE);
}
sub loadError {
$lang = lc ($query->param('lang'));#=~ s/[^A-Za-z0-9 ]//;
#$lang=~ s/[^A-Za-z0-9 ]//;
open (FILE, "<$dirError/$lang.error.conf") or die "cannot open file $dirError/$lang.error.conf";
while () {
(my $label, my $value) = split(/=/);
$ERROR{$label} = $value;
}
close (FILE);
}
BEGIN {
use Exporter ();
@SharedVariable::ISA = qw(Exporter);
@SharedVariable::EXPORT = qw(gettimeofday());
@SharedVariable::EXPORT_OK = qw ($session_dir $cookie $page $action $dir $dirLang $dirError $imgdir $session_id $can_do_gzip $current_ip $lang $LANG %ARTICLE %SESSION %SERVER %USER $CGISESSID %LABEL %ERROR %VALUE $COMMANDID %COMMAND %DATE %PAYPALL $INDEX %LINK $query $session $host $t0 $client);
}
1;
####
#!/usr/bin/perl -w
package MyDB;
use strict;
use DBI;
use SharedVariable qw ($action $dir $dirLang $dirError $imgdir $session_dir $session_id $can_do_gzip $current_ip $lang $LANG %ARTICLE %SESSION %SERVER %USER $CGISESSID %LABEL %ERROR %VALUE $COMMANDID %COMMAND %DATE %PAYPALL $INDEX %LINK $query $session $host $t0 $client);
our $dbh = DBI->connect( "DBI:mysql:recordz:localhost", "root", "XXXXXXXXXXXXX",{ RaiseError => 1, AutoCommit => 1 } );
sub new {
my $class = shift;
my ($opts)= @_;
my $self = {};
return bless $self, $class;
}
sub sqlConnect {
my $dbname = shift || '';
my $dbusername = shift || '';
my $dbpassword = shift || '';
$dbh = DBI->connect( "DBI:mysql:recordz:localhost", "root", "alexandre",{ RaiseError => 1, AutoCommit => 1 } );
if (!$dbh) {
}
kill 9, $$ unless $dbh;
}
sub sqlSelect {
my $from = shift || '';
my $select = shift || '';
my $where = shift || '';
my $other = shift || '';
my $other2 = shift || '';
my $sql="SELECT $select ";
$sql.="FROM $where ";
$sql.="WHERE $other ";
#$sql.="$other";
#$sql.="$other2"; #$sql = $dbh->quote ($sql);
my ($c)=$dbh->prepare($sql) or die "Sql has gone to hell\n";
#print "Content-Type: text/html\n\n";
#print "SQL : $sql \n";
# print "Content-Type: text/html\n\n";
# print "SQL : $sql \n";
if(not ($c->execute())) {
my $err=$dbh->errstr;
return undef;
}
my (@r)=$c->fetchrow();
$c->finish();
return @r;
}
sub sqlSelect1 {
my $from = shift || '';
my $select = shift || '';
my $where = shift || '';
my $other = shift || '';
my $other2 = shift || '';
my $sql="SELECT $select ";
$sql.="FROM $where ";
$sql.="WHERE $other ";
#$sql.="$other";
#$sql.="$other2"; #$sql = $dbh->quote ($sql);
# print "Content-Type: text/html\n\n";
# print "SQL : $sql \n";
my ($c)=$dbh->prepare($sql) or die "Sql has gone to hell\n";
#print "Content-Type: text/html\n\n";
#print "SQL : $sql \n";
if(not ($c->execute())) {
my $err=$dbh->errstr;
return undef;
}
my (@r)=$c->fetchrow();
$c->finish();
return @r;
}
sub sqlSelect2 {
my $from = shift || '';
my $select = shift || '';
my $where = shift || '';
my $other = shift || '';
my $other2 = shift || '';
my $sql="SELECT $select ";
$sql.="FROM $where ";
$sql.="WHERE $other ";
#$sql.="$other";
#$sql.="$other2"; #$sql = $dbh->quote ($sql);
my ($c)=$dbh->prepare($sql) or die "Sql has gone to hell\n";
if(not ($c->execute())) {
my $err=$dbh->errstr;
return undef;
}
my (@r)=$c->fetchrow();
$c->finish();
return @r;
}
sub sqlInsert {
my $invoke = shift || '';
my($table,%data)=@_;
my($names,$values);
$dbh||=sqlConnect();
foreach (keys %data) {
if (/^-/) {$values.="\n ".$data{$_}.","; s/^-//;}
else { $values.="\n ".$dbh->quote($data{$_}).","; }
$names.="$_,";
}
chop($names);
chop($values);
my $sql="INSERT INTO $table ($names) VALUES($values)\n";
#$sql = $dbh->quote ($sql);
if(!$dbh->do($sql)) {
my $err=$dbh->errstr;
}
}
sub sqlInsert2 {
my $invoke = shift || '';
my($table, %data)=@_;
print "Content-type: text/html\n\n";
my($names,$values);
$dbh||=sqlConnect();
foreach (keys %data) {
if (/^-/) {
$values.="\n ".$data{$_}.",";
print "if\n";
print $values;
s/^-//;
$names.="$_,";
#INSERT INTO ( NULL, 'text', 'question', 'ref_emetteur', 'date') VALUES (2013-05-31 15:25:28,,1,commentaire,this is the description
#INSERT INTO ( 'text', 'question', NULL, 'ref_emetteur', 'date') VALUES (,1,2013-05-31 15:26:49,commentaire,this is the description
}
else {
$values.="\n ".$data{$_}.",";
s/^-//;
$names.="$_,";
}
}
chop($names);
chop($values);
my $sql="INSERT INTO $table ($names) VALUES ($values)\n";
#$sql = $dbh->quote ($sql);
#print "Content-Type: text/html\n\n";
#print "$sql
";
if(!$dbh->do($sql)) {
my $err=$dbh->errstr;
}
}
sub sqlUpdate {
my $invoke = shift || '';
my ($table, $where, %data)=@_;
my $sql="UPDATE $table SET";
foreach (keys %data) {
if (/^-/) {
s/^-//;
$sql.=" $_ = $data{-$_} " . ",";
} else {
$sql.=" $_ = ".$dbh->quote($data{$_}).",";
}
}
chop($sql);
$sql.=" WHERE $where ";
#print "Content-Type: text/html\n\n";
#print "SQL : $sql \n";
if(!$dbh->do($sql)) {
my $err=$dbh->errstr;
}
}
sub sqlUpdate3 {
my $invoke = shift || '';
my $table = shift || '';
my $where = shift || '';
my %data = shift || '';
my $other = shift || '';
my ($names,$values);
my $sql="UPDATE $where SET";
foreach (keys %data) {
if (/^-/) {$values.="\n ".$data{$_}.","; s/^-//;}
else { $values.="\n ".$dbh->quote($data{$_}).","; }
$names.="$_,";
chop($names);
chop($values);
$sql.=" $names WHERE $other ";
}
print "Content-Type: text/html\n\n";
print "SQL : $sql \n";
$dbh->do($sql);
$dbh->disconnect();
}
sub sqlUpdate1 {
my $invoke = shift || '';
my $table = shift || '';
my $where = shift || '';
my %data = shift || '';
my $other = shift || '';
my ($names,$values);
my $sql="UPDATE $where SET";
foreach (keys %data) {
if (/^-/) {$values.="\n ".$data{$_}.","; s/^-//;}
else { $values.="\n ".$dbh->quote($data{$_}).","; }
$names.="$_,";
chop($names);
chop($values);
$sql.=" $names WHERE $where ";
}
$dbh->do($sql);
$dbh->disconnect();
}
sub sqlSelectMany {
my $from = shift || '';
my $select = shift || '';
my $where = shift || '';
my $other = shift || '';
my $other2 = shift || '';
my $sql="SELECT $select ";
$sql.="FROM $where ";
$sql.="WHERE $other ";
my $c=$dbh->prepare($sql);
#print "Content-Type: text/html\n\n";
# print "SQL : $sql \n";
if($c->execute()) {
return $c;
} else {
$c->finish();
my $err=$dbh->errstr;
return undef;
kill 9,$$
}
}
sub sqlDelete {
my $fromtable = shift || '';
my $condition = shift || '';
my $sql = '';
if ($condition) {
$sql = "DELETE from $fromtable WHERE $condition";
} else {
$sql = "DELETE from $fromtable";
}
#print "Content-Type: text/html\n\n";
#print "$sql";
#$sql = $dbh->quote ($sql);
if (!$dbh->do($sql)) {
my $err=$dbh->errstr;
}
}
BEGIN {
use Exporter ();
@DB::ISA = qw(Exporter);
@DB::EXPORT = qw();
@DB::EXPORT_OK = qw(new sqlSelectMany1 sqlConnect sqlSelect sqlInsert sqlUpdate sqlSelectMany sqlDelete);
}
1;
####
[Fri Dec 28 14:11:18 2018] [error] [client 127.0.0.1] [Fri Dec 28 14:11:18 2018] Search2.pm: Subroutine new redefined at Search2.pm line 13.