summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ChangeLog3
-rw-r--r--lib/Multi/Anime.pm2
-rw-r--r--lib/Multi/IRC.pm2
-rw-r--r--lib/VNDB.pm138
-rw-r--r--lib/VNDB/Util/Response.pm2
-rw-r--r--lib/global.pl44
-rw-r--r--util/fcgi.pl123
-rw-r--r--util/multi.pl21
8 files changed, 183 insertions, 152 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 8570477b..1513b5af 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -14,6 +14,9 @@ TODO:
1.17 - 2008-05-23
- Added PS3 and Xbox 360 to platforms
- Relation graph generation improvements: Unicode, anti-aliassing, async
+ - Removed all passwords from the main code, and created a seperate config
+ file to override all options - not available on SVN
+ - Dynamic loading, several bugfixes, and code cleanup for Multi
1.16 - 2008-05-22
- Release dates in the current year or month without a specified day will
diff --git a/lib/Multi/Anime.pm b/lib/Multi/Anime.pm
index 68fcce4e..6f329bd5 100644
--- a/lib/Multi/Anime.pm
+++ b/lib/Multi/Anime.pm
@@ -58,8 +58,6 @@ sub spawn {
},
PeerPort => 9000,
# AniDB UDP API options
- user => 'vnmulti',
- pass => '',
client => 'multi',
clientver => 1,
# Misc settings
diff --git a/lib/Multi/IRC.pm b/lib/Multi/IRC.pm
index e143d56b..23b476ab 100644
--- a/lib/Multi/IRC.pm
+++ b/lib/Multi/IRC.pm
@@ -31,7 +31,7 @@ sub spawn {
],
heap => { irc => $irc,
o => {
- user => 'Multi',
+ user => 'Multi_test'.$$,
server => 'irc.synirc.net',
ircname => 'VNDB.org Multi',
channel => '#vndb',
diff --git a/lib/VNDB.pm b/lib/VNDB.pm
index 5ac3bc87..2e316324 100644
--- a/lib/VNDB.pm
+++ b/lib/VNDB.pm
@@ -5,34 +5,6 @@ use warnings;
BEGIN { require 'global.pl'; }
our $DEBUG;
-our %VNDBopts = (
- CookieDomain => '.vndb.org',
- root_url => $DEBUG ? 'http://beta.vndb.org' : 'http://vndb.org',
- static_url => $DEBUG ? 'http://static.beta.vndb.org' : 'http://static.vndb.org',
- debug => $DEBUG,
- tplopts => {
- filename => 'main',
- searchdir => '/www/vndb/data/tpl',
- compiled => '/www/vndb/data/tplcompiled.pm',
- namespace => 'VNDB::Util::Template::tpl',
- pre_chomp => 1,
- post_chomp => 1,
- rm_newlines => 0,
- deep_reload => $DEBUG,
- },
- ranks => [
- [ [ qw| visitor loser user mod admin | ], [] ],
- {map{$_,1}qw| hist |}, # 0 - visitor (not logged in)
- {map{$_,1}qw| hist |}, # 1 - loser
- {map{$_,1}qw| hist edit |}, # 2 - user
- {map{$_,1}qw| hist edit mod lock |}, # 3 - mod
- {map{$_,1}qw| hist edit mod lock del userlist useredit |}, # 4 - admin
- ],
- imgpath => '/www/vndb/static/cv',
- mappath => '/www/vndb/data/rg',
- docpath => '/www/vndb/data/docs',
-);
-$VNDBopts{ranks}[0][1] = { (map{$_,1} map { keys %{$VNDBopts{ranks}[$_]} } 1..5) };
require Time::HiRes if $DEBUG;
require Data::Dumper if $DEBUG;
@@ -168,6 +140,9 @@ my %OLDuris = (
'p+' => {
hist=>{rss => sub { shift->ResRedirect('/p'.(shift).'/hist/rss.xml', 'perm') } },
},
+ 'r+' => {
+ hist=>{rss => sub { shift->ResRedirect('/r'.(shift).'/hist/rss.xml', 'perm') } },
+ },
hist=>{rss => sub { shift->ResRedirect('/hist/rss.xml', 'perm') } },
);
@@ -241,110 +216,3 @@ sub uri2page {
1;
-
-__END__
-
-# O L D C O D E - N O T U S E D A N Y M O R E
-
-
-# Apache 2 handler
-sub handler ($$) {
- my $r = shift;
-
- # we don't handle internal redirects! (fixes ErrorDocument directives)
- return Apache2::Const::DECLINED
- if $r->prev || $r->next;
-
- my $start = [Time::HiRes::gettimeofday()] if $DEBUG;
- @WARN = ();
- my($code, $res, $err);
- $SIG{__WARN__} = sub { push(@VNDB::WARN, @_); warn @_; };
-
- $err = eval {
-
- @Time::CTime::DoW = qw|Sun Mon Tue Wed Thu Fri Sat|;
- @Time::CTime::DayOfWeek = qw|Sunday Monday Tuesday Wednesday Thursday Friday Saturday|;
- @Time::CTime::MoY = qw|Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec|;
- @Time::CTime::MonthOfYear = qw|January February March April May June July August September October November December|;
-
- $VNDB = VNDB->new(%VNDBopts) if !$VNDB;
- $VNDB->{r} = $r;
-
- # let apache handle static files
- (my $uri = lc($r->uri())) =~ s/\/+//;
- if(index($uri, '..') == -1 && -f '/www/vndb/www/' . $uri) {
- $code = Apache2::Const::DECLINED;
- return $code;
- }
-
- $VNDB->DBCheck();
- ($res, $code) = $VNDB->get_page($r);
- if($DEBUG) {
- my($sqlt, $sqlc) = (0, 0);
- foreach (@{$res->{_DB}->{Queries}}) {
- if($_->[0]) {
- $sqlc++;
- $sqlt += $_->[1];
- }
- }
- my $time = Time::HiRes::tv_interval($start);
- my $tpl = $res->{_Res}->{_tpltime} ? $res->{_Res}->{_tpltime}/$time*100 : 0;
- my $gzip = 0;
- $gzip = 100 - $res->{_Res}->{_gzip}->[1]/$res->{_Res}->{_gzip}->[0]*100
- if($res->{_Res}->{_gzip} && ref($res->{_Res}->{_gzip}) eq 'ARRAY' && $res->{_Res}->{_gzip}->[0] > 0);
- printf STDERR "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, $r->uri();
- }
-
- };
-
- # error occured, create a dump file
- if(!defined $err && $@ && $DEBUG) {
- undef $res->{_Res};
- undef $res->{_Req};
- die $@;
- } elsif(!defined $err && $@) {
- if(open(my $E, sprintf '>/www/vndb/data/errors/%04d-%02d-%02d-%d',
- (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3], time)) {
- print $E 'Error @ ' . scalar localtime;
-
- print $E "\n\nRequest:\n" . $r->the_request . "\n";
- print $E "$_: " . $r->headers_in->{$_} . "\n"
- for (keys %{$r->headers_in});
-
- print $E "\nParams:\n";
- my $re = Apache2::Request->new($r);
- print $E "$_: " . $re->param($_) . "\n"
- for ($re->param());
-
- print $E "\nError:\n$@\n\n";
- print $E "Warnings:\n".join('', @WARN)."\n";
- close($E);
- }
- $VNDB->DBRollBack();
- undef $res->{_Res};
- undef $res->{_Req};
- die "Error, check dumpfile!\n";
- }
-
- undef $res->{_Res};
- undef $res->{_Req};
- # let apache handle 404's
- $code = Apache2::Const::DECLINED if $code == 404;
- return $code;
-}
-
-
-sub mod_perl_init {
- require Apache2::RequestRec;
- require Apache2::RequestIO;
- $VNDB = __PACKAGE__->new(%VNDBopts);
- return 0;
-}
-
-
-sub mod_perl_exit {
- $VNDB->DBExit() if defined $VNDB && ref $VNDB eq __PACKAGE__;
- return 0;
-}
-
diff --git a/lib/VNDB/Util/Response.pm b/lib/VNDB/Util/Response.pm
index 8d3f33b8..c5e9a704 100644
--- a/lib/VNDB/Util/Response.pm
+++ b/lib/VNDB/Util/Response.pm
@@ -12,7 +12,7 @@ use Exporter 'import';
require bytes;
use vars ('$VERSION', '@EXPORT');
-$VERSION = $NTL::VERSION;
+$VERSION = $VNDB::VERSION;
@EXPORT = qw| ResRedirect ResNotFound ResDenied ResFile
ResForceBody ResSetContentType ResAddHeader ResAddTpl ResAddDefaultStuff
ResStartXML ResGetXML ResGetBody ResGet ResGetCGI ResSetModPerl |;
diff --git a/lib/global.pl b/lib/global.pl
index 37839a42..817f8928 100644
--- a/lib/global.pl
+++ b/lib/global.pl
@@ -5,6 +5,45 @@ our @SHMOPTS = ( -key => 'VNDB', -create => 'yes', -destroy => 'no', -mode => 06
our $DEBUG = 1;
our $VERSION = '1.17';
+our $MULTI = [
+ RG => {},
+ Image => {},
+ Sitemap => {},
+ #Anime => { user => '', pass => '' },
+ Maintenance => {},
+ #IRC => { user => 'Multi'},
+];
+
+our %VNDBopts = (
+ CookieDomain => '.vndb.org',
+ root_url => 'http://vndb.org',
+ static_url => 'http://static.vndb.org',
+ debug => $DEBUG,
+ tplopts => {
+ filename => 'main',
+ searchdir => '/www/vndb/data/tpl',
+ compiled => '/www/vndb/data/tplcompiled.pm',
+ namespace => 'VNDB::Util::Template::tpl',
+ pre_chomp => 1,
+ post_chomp => 1,
+ rm_newlines => 0,
+ deep_reload => $DEBUG,
+ },
+ ranks => [
+ [ [ qw| visitor loser user mod admin | ], [] ],
+ {map{$_,1}qw| hist |}, # 0 - visitor (not logged in)
+ {map{$_,1}qw| hist |}, # 1 - loser
+ {map{$_,1}qw| hist edit |}, # 2 - user
+ {map{$_,1}qw| hist edit mod lock |}, # 3 - mod
+ {map{$_,1}qw| hist edit mod lock del userlist useredit |}, # 4 - admin
+ ],
+ imgpath => '/www/vndb/static/cv',
+ mappath => '/www/vndb/data/rg',
+ docpath => '/www/vndb/data/docs',
+);
+$VNDBopts{ranks}[0][1] = { (map{$_,1} map { keys %{$VNDBopts{ranks}[$_]} } 1..5) };
+
+
our $PLAT = {
win => 'Windows',
lin => 'Linux',
@@ -597,5 +636,10 @@ our $LANG = {
# 'zun' => q|Zuni|,
};
+
+# override config vars
+require '/www/vndb/data/config.pl' if -e '/www/vndb/data/config.pl';
+
+
1;
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__: '.$_)};