diff options
author | yorhel <yorhel@1fe2e327-d9db-4752-bcf7-ef0cb4a1748b> | 2008-06-06 15:33:01 +0000 |
---|---|---|
committer | yorhel <yorhel@1fe2e327-d9db-4752-bcf7-ef0cb4a1748b> | 2008-06-06 15:33:01 +0000 |
commit | 8ca9a520d993d0a1a8b7bbcd800b68bf7543b7c3 (patch) | |
tree | 1db0d1842a67ed0da169e02e6ade4b3324ad117f /util | |
parent | d667908bb47626b789344048537b3eb9e00d6828 (diff) |
Removed old stuff and passwords. All passwords in older revisions have been changed :)
git-svn-id: svn://vndb.org/vndb@22 1fe2e327-d9db-4752-bcf7-ef0cb4a1748b
Diffstat (limited to 'util')
-rw-r--r-- | util/fcgi.pl | 123 | ||||
-rw-r--r-- | util/multi.pl | 21 |
2 files changed, 131 insertions, 13 deletions
diff --git a/util/fcgi.pl b/util/fcgi.pl new file mode 100644 index 00000000..60f3c324 --- /dev/null +++ b/util/fcgi.pl @@ -0,0 +1,123 @@ +#!/usr/bin/perl + +package FCGI::Handler; + +use strict; +use warnings; +use lib '/www/vndb/lib'; + +use strict; +use warnings; +use FCGI; +use CGI::Minimal (); +use Cookie::XS; +use Time::HiRes; +use VNDB; + +my $elog = "/www/err.log"; + +our $req = FCGI::Request(); +our $c; +our $outputted = 0; + +my $VNDB = VNDB->new(%VNDB::VNDBopts); + +our @WRN; +$SIG{__WARN__} = sub { push @FCGI::Handler::WRN, @_; }; + +while($req->Accept() >= 0) { + # lighty doesn't always split the query string from REQUEST_URI + ($ENV{REQUEST_URI}, $ENV{QUERY_STRING}) = split /\?/, $ENV{REQUEST_URI} + if ($ENV{REQUEST_URI}||'') =~ /\?/; + + # re-init CGI::Minimal (can die()) + eval { + CGI::Minimal::reset_globals; + CGI::Minimal::allow_hybrid_post_get(1); + $c = CGI::Minimal->new(); + }; + if($@) { + send500(); + $req->Finish(); + next; + } + + # figure out some required variables + my $o = $VNDB; + my $start = [ Time::HiRes::gettimeofday ] if $o->{debug}; + + # call appropriate functions in VNDB.pm + my $e = eval { + if($c->truncated) { + send500(); + warn "Truncated post request!\n"; + } else { + $o->DBCheck; + $o->get_page; # automatically calls DBCommit on success + } + 1; + }; + + # Error handling + if(@WRN && $e && !$@ && open(my $F, '>>', $elog)) { + for (@WRN) { + chomp; + printf $F "[%s] %s: %s\n", scalar localtime(), $ENV{HTTP_HOST}.$ENV{REQUEST_URI}.'?'.$ENV{QUERY_STRING}, $_; + } + close $F; + } + if(!defined $e && $@ && open(my $F, '>>', $elog)) { + printf $F "[%s] %s: FATAL ERROR!\n", scalar localtime(), $ENV{HTTP_HOST}.$ENV{REQUEST_URI}.'?'.$ENV{QUERY_STRING}; + print $F " ENV-dump:\n"; + printf $F " %s: %s\n", $_, $ENV{$_} for (sort keys %ENV); + print $F " PARAM-dump:\n"; + printf $F " %s: %s\n", $_, $c->param($_) for (sort $c->param()); + my $err = $@; chomp($err); + printf $F " ERROR:\n %s\n", $err; + if(@WRN) { + print $F " WARNINGS:\n"; + for (@WRN) { + chomp; + printf $F " %s\n", $_; + } + } + print $F "\n"; + close $F; + eval { $o->DBRollBack; }; + send500() if !$outputted; + } + + # Debug info + if($o->{debug} && open(my $F, '>>', $elog)) { + my($sqlt, $sqlc) = (0, 0); + for (@{$o->{_DB}->{Queries}}) { + if($_->[0]) { + $sqlc++; + $sqlt += $_->[1]; + } + } + my $time = Time::HiRes::tv_interval($start); + my $tpl = $o->{_Res}->{_tpltime} ? $o->{_Res}->{_tpltime}/$time*100 : 0; + my $gzip = 0; + $gzip = 100 - $o->{_Res}->{_gzip}->[1]/$o->{_Res}->{_gzip}->[0]*100 + if($o->{_Res}->{_gzip} && ref($o->{_Res}->{_gzip}) eq 'ARRAY' && $o->{_Res}->{_gzip}->[0] > 0); + printf $F "Took %3dms (SQL/TPL/perl: %4.1f%% %4.1f%% %4.1f%%) (GZIP: %4.1f%%) to parse %s\n", + $time*1000, $sqlt/$time*100, $tpl, 100-($sqlt/$time*100)-$tpl, $gzip, $ENV{REQUEST_URI}; + close $F; + } + + # reset vars + @WRN = (); + $outputted = 0; + undef $o->{_Res}; + undef $o->{_Req}; + + $req->Finish(); +} + +sub send500 { + print "HTTP/1.0 500 Internal Server Error\n"; + print "Content-Type: text/html\n"; + print "X-Sendfile: /www/vndb/www/files/err.html\n\n"; +} + diff --git a/util/multi.pl b/util/multi.pl index d45150fb..9a072d02 100644 --- a/util/multi.pl +++ b/util/multi.pl @@ -25,12 +25,6 @@ use DBI; use lib '/www/vndb/lib'; use Multi::Core; -use Multi::RG; -use Multi::Image; -use Multi::Sitemap; -use Multi::Anime; -use Multi::Maintenance; -use Multi::IRC; BEGIN { require 'global.pl' } @@ -50,20 +44,21 @@ if(grep /^-a$/, @ARGV) { exit; } - # one shared pgsql connection for all sessions our $SQL = DBI->connect(@VNDB::DBLOGIN, { PrintError => 1, RaiseError => 0, AutoCommit => 1, pg_enable_utf8 => 1 }); Multi::Core->spawn(); -Multi::RG->spawn(); -Multi::Image->spawn(); -Multi::Sitemap->spawn(); -Multi::Anime->spawn() if !$VNDB::DEBUG; # no need to update anime from the beta -Multi::Maintenance->spawn(); -Multi::IRC->spawn() if !$VNDB::DEBUG; +# dynamically load and spawn modules +for (0..(@$VNDB::MULTI/2+1)) { + my($mod, $args) = @{$VNDB::MULTI}[$_*2, $_*2+1]; + next if !$args || ref($args) ne 'HASH'; + require "Multi/$mod.pm"; + # I'm surprised the strict pagma isn't complaining about this + "Multi::$mod"->spawn(%$args); +} $SIG{__WARN__} = sub {(local$_=shift)=~s/\r?\n//;$poe_kernel->call(core=>log=>1,'__WARN__: '.$_)}; |