X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;ds=sidebyside;f=ND.pm;h=404c8795648e042764cc2c28443b56a476e85981;hb=d40637f048a03d16cc7d43bca6fddaf721251346;hp=d62a7ea89537bc94d3f6f16c3af452c9624ba26a;hpb=c10765bfab69c9d2abdb96bf05a6662088cf8b3f;p=ndwebbie.git diff --git a/ND.pm b/ND.pm index d62a7ea..404c879 100755 --- a/ND.pm +++ b/ND.pm @@ -31,7 +31,6 @@ use Fcntl 'O_RDONLY'; use strict; use warnings FATAL => 'all'; -tie our @PAGES, 'Tie::File', "/var/www/ndawn/code/pages", mode => O_RDONLY or die $!; sub handler { local $ND::r = shift; @@ -49,23 +48,24 @@ sub handler { if ($ENV{'SCRIPT_NAME'} =~ /(\w+)(\.(pl|php|pm))?$/){ $ND::PAGE = $1 unless $1 eq 'index' and $3 eq 'pl'; } + $ND::PAGE = '' unless defined $ND::PAGE; page(); return Apache2::Const::OK; } sub page { our $DBH = ND::DB::DB(); - our $USER = $ENV{'REMOTE_USER'}; - my $error;# = $ND::r->param('page'); + my $error = ''; chdir '/var/www/ndawn/code'; our $TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl', global_vars => 1, cache => 1); - our ($UID,$PLANET) = $DBH->selectrow_array('SELECT uid,planet FROM users WHERE username = ?' + our ($UID,$PLANET,$USER) = $DBH->selectrow_array('SELECT uid,planet,username FROM users WHERE username ILIKE ?' ,undef,$ENV{'REMOTE_USER'}); our ($TICK) = $DBH->selectrow_array('SELECT tick()',undef); + $TICK = 0 unless defined $TICK; my $query = $DBH->prepare('SELECT groupname,attack,gid from groupmembers NATURAL JOIN groups WHERE uid = ?'); @@ -81,7 +81,8 @@ sub page { our $LOG = $DBH->prepare('INSERT INTO log (uid,text) VALUES(?,?)'); - $ND::PAGE = 'main' unless grep { /^$ND::PAGE$/ } @PAGES; + tie my @pages, 'Tie::File', "/var/www/ndawn/code/pages", mode => O_RDONLY, memory => 0 or die $!; + $ND::PAGE = 'main' unless grep { /^$ND::PAGE$/ } @pages; our $XML = 0; $XML = 1 if param('xml') and $ND::PAGE =~ /^(raids)$/; @@ -98,16 +99,16 @@ sub page { $ND::BODY->param(PAGE => $ND::PAGE); } - unless (my $return = do "$ND::PAGE.pl"){ - $error .= "

couldn't parse $ND::page: $@

" if $@; - $error .= "

couldn't do $ND::page: $!

" unless defined $return; - $error .= "

couldn't run $ND::page

" unless $return; + $error .= "

couldn't parse $ND::PAGE: $@

" if $@; + $error .= "

couldn't do $ND::PAGE: $!

" unless defined $return && defined $!; + $error .= "

couldn't run $ND::PAGE

" unless $return; } unless ($XML){ my $fleetupdate = $DBH->selectrow_array('SELECT landing_tick FROM fleets WHERE uid = ? AND fleet = 0',undef,$UID); + $fleetupdate = 0 unless defined $fleetupdate; $TEMPLATE->param(Tick => $TICK); $TEMPLATE->param(isMember => (($TICK - $fleetupdate < 24) || isScanner()) && $PLANET && isMember()); @@ -120,15 +121,16 @@ sub page { $ND::TEMPLATE->param(Targets => listTargets()); } $TEMPLATE->param(Coords => param('coords') ? param('coords') : '1:1:1'); - $TEMPLATE->param(Error => $error); } + $TEMPLATE->param(Error => $error); $ND::TEMPLATE->param(BODY => $ND::BODY->output); my $output = $TEMPLATE->output; print header(-type=> $type, -charset => 'utf-8', -Content_Length => length $output); print $output; + $DBH->rollback; $DBH->disconnect; $DBH = undef; $UID = undef;