Diff for /db/prgsrc/db.cgi between versions 1.129 and 1.130

version 1.129, 2004/02/08 00:35:29 version 1.130, 2004/03/11 07:14:14
Line 8  use POSIX qw(locale_h); Line 8  use POSIX qw(locale_h);
 use locale;  use locale;
 use vars qw($opt_z);  use vars qw($opt_z);
 use Getopt::Std;  use Getopt::Std;
   my ($dbuser,$dbname,$dbpass,$dbhost);
   require "dbdefs.pl";
   $dbuser||="piataev";
   $dbname||="chgk";
   $dbpass||="";
   $dbhost||="localhost";
 getopts('z');  getopts('z');
 $opt_z||=param("makehtml");  $opt_z||=param("makehtml");
 my $timestamp="_timestamp.tmp";  my $timestamp="_timestamp.tmp";
   my $usehash=0;
 my $paramtour;  my $paramtour;
 my $withanswers=param('answer')||param('answers');  my $withanswers=param('answer')||param('answers');
 open STDERR, ">/var/tmp/errors1";  open STDERR, ">/var/tmp/errors1";
Line 33  if ($^O =~ /win/i) { Line 40  if ($^O =~ /win/i) {
 {  {
   $realHTMLDIR="/home/piataev/public_html/dimrub/db/files/";    $realHTMLDIR="/home/piataev/public_html/dimrub/db/files/";
 }  }
   my $url=url||'';
   
 my $usehtml=$opt_z||0;  my $usehtml=$opt_z||0;
 $usehtml=1;  $usehtml=1;
   $usehtml=0 if $url=~/zaba/;
   
 my $usewas=0;  my $usewas=0;
 my $cashednumber=500;  my $cashednumber=500;
 my $outputnumber=10;  my $outputnumber=10;
 my ($proxyptext,$proxysstr);  my ($proxyptext,$proxysstr);
 my $printqueries=0;  my $printqueries=0;
 my $url=url||'';  
 my $qs=query_string;  my $qs=query_string;
 my $globaloutput;  my $globaloutput;
 my %forbidden=();  my %forbidden=();
 my $debug=0; #added by R7  my $debug=0; #added by R7
   my $metod=param('metod')||'';
 my $outputkvo=param('kvo') ||$outputnumber;  my $outputkvo=param('kvo') ||$outputnumber;
 $outputkvo=100 if $outputkvo>100;  $outputkvo=100 if $outputkvo>100;
   
 if (param('debug')) {$debug=1; $printqueries=1}  if (param('debug')) {$debug=1; $printqueries=1}
 *STDERR=*STDOUT if $debug;  *STDERR=*STDOUT if $debug;
 if ($url !~ /db\.chgk\.info/ && $url !~ /localhost/ && $url !~ /bilbo/) {  if ($url !~ /db\.chgk\.info/ && $url !~ /localhost/ && $url !~ /bilbo/ && $url !~ /zaba/) {
    my $u="http://db.chgk.info/cgi-bin/db.cgi?$qs";     my $u="http://db.chgk.info/cgi-bin/db.cgi?$qs";
    Redirect ($u);     Redirect ($u);
    exit;     exit;
 }  }
   
   if ($metod=~/proxy/ && $url !~ /localhost/ && $url !~ /bilbo/ && $url !~ /zaba/) {
      my $u="http://chgk.zaba.ru/cgi-bin/db.cgi?$qs";
      Redirect ($u);
      exit;
   }
   
 #if (!param('sstr') && param('all')) {  #if (!param('sstr') && param('all')) {
 #          my $destination='http://db.chgk.info/all.html';  #          my $destination='http://db.chgk.info/all.html';
 #               Redirect($destination);  #               Redirect($destination);
Line 1481  sub Get12Random { Line 1499  sub Get12Random {
         srand;          srand;
         my $where=0;          my $where=0;
         my $r=int (rand(10000));          my $r=int (rand(10000));
         my $w1=$r<5000? "QuestionId<5000 ":"QuestionId>=5000";          my $w1=$r<5000? "QuestionId<50000 ":"QuestionId>=50000";
           $w1=1 if $url=~/zaba/;
         $w1=1 if $type!~/Ч/;          $w1=1 if $type!~/Ч/;
         foreach (split '', $type)          foreach (split '', $type)
         {          {
Line 1909  MAIN: Line 1928  MAIN:
         $tour = (param('tour')) ? param('tour') : 0;          $tour = (param('tour')) ? param('tour') : 0;
         my $texttour=$tour;          my $texttour=$tour;
         my ($sth,$dbh);          my ($sth,$dbh);
         $dbh = DBI->connect("DBI:mysql:chgk", "piataev", "")          my($dsn) = "DBI:mysql:database=$dbname;host=$dbhost";
           $dbh = DBI->connect($dsn, $dbuser, $dbpass) 
   #       $dbh = DBI->connect("DBI:mysql:$dbname", $username, $dbpass)
                 or do {                  or do {
                         print h1("Временные проблемы") . "База вопросов временно не                          print header.h1("Временные проблемы") . "База вопросов временно не
                         работает. Заходите попозже.";                          работает. Заходите попозже.";
                         print &Include_virtual("$reklama") if $url!~/localhost/;                          print &Include_virtual("$reklama") if $url!~/localhost/;
                     print end_html;                      print end_html;
Line 1920  MAIN: Line 1941  MAIN:
   
   
         if (param('qid') && (param('qid')=~/^\d+$/) || $tour && $tour=~/^\d+$/) {          if (param('qid') && (param('qid')=~/^\d+$/) || $tour && $tour=~/^\d+$/) {
            my $destination='http://db.chgk.info/search.html';             my $destination='http://chgk.zaba.ru/search.html';
 #               print header (-'Content-Type' => 'text/html',  #               print header (-'Content-Type' => 'text/html',
 #                -'Location:'=> 'http:\\db.chgk.info');  #                -'Location:'=> 'http:\\db.chgk.info');
                 Redirect($destination);                  Redirect($destination);
Line 1976  print br.br.$d; Line 1997  print br.br.$d;
   
         if ($text && !param ('comp')) {          if ($text && !param ('comp')) {
                 print header('text/plain');                  print header('text/plain');
         } elsif (!param('comp')) {print header;}          } elsif (!param('comp')) {
                   print header(-charset =>'koi8-r')}
           my $sstr=param('sstr');            my $sstr=param('sstr');
           $opt_z||=param("makehtml");            $opt_z||=param("makehtml");
           if (param('qid')) {            if (param('qid')) {
Line 2043  th {font-size: x-small; font-family : sa Line 2065  th {font-size: x-small; font-family : sa
                 $globaloutput.=&Include_virtual("$reklama")||'';                  $globaloutput.=&Include_virtual("$reklama")||'';
         }          }
   
        if (!$opt_z && length ($qs)<=255 && $qs !~ /(sstr)|(rand)|(comp)|(all=)/i) {         if ($usehash && !$opt_z && length ($qs)<=255 && $qs !~ /(sstr)|(rand)|(comp)|(all=)/i) {
                 my $sth=$dbh->prepare("SELECT page,times,t from hash where query=".$dbh->quote($qs));                  my $sth=$dbh->prepare("SELECT page,times,t from hash where query=".$dbh->quote($qs));
                 $sth->execute();                  $sth->execute();
                 my ($p,$times,$t)=$sth->fetchrow();                  my ($p,$times,$t)=$sth->fetchrow();
Line 2228  my ($sth) = $dbh->prepare("SELECT t1.Id, Line 2250  my ($sth) = $dbh->prepare("SELECT t1.Id,
         }          }
         if (!$opt_z){           if (!$opt_z){ 
           print $globaloutput;            print $globaloutput;
           if (($qs!~ /(rand)|(sstr)|(comp)/i) && (length $qs<=255)) {            if (($qs!~ /(rand)|(sstr)|(comp)/i) && (length $qs<=255) && $usehash) {
                 $globaloutput=  $dbh->quote($globaloutput);                  $globaloutput=  $dbh->quote($globaloutput);
                 $dbh->do("insert into hash (query,page) values (".                  $dbh->do("insert into hash (query,page) values (".
                 $dbh->quote($qs).                  $dbh->quote($qs).

Removed from v.1.129  
changed lines
  Added in v.1.130


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>