X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=ND.pm;h=c54bb77a085b828793d0d6391594d932e10ba951;hb=6d6177b5221cc6d74b58c73c91f33bc8132649db;hp=70000c8094192ea30107bc00295b976982b0d4fd;hpb=0a5d682ce0185df2588004b2b965159abdb5ef2a;p=ndwebbie.git diff --git a/ND.pm b/ND.pm index 70000c8..c54bb77 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; @@ -44,25 +43,28 @@ sub handler { local $ND::BODY; local $ND::TICK; local %ND::GROUPS; + local $ND::ERROR; local $ND::PAGE = $ND::req->param('page'); 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 = ''; + $DBH->do(q{SET timezone = 'GMT'}); + + our $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); @@ -82,7 +84,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)$/; @@ -100,9 +103,9 @@ sub page { } unless (my $return = do "$ND::PAGE.pl"){ - $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; + $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){ @@ -123,7 +126,7 @@ sub page { $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);