X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=index.pl;h=31beaf5ce486f3a2159fb571bf263ea700825ea0;hb=6eacbf94cc13b8b6df3018df1159065fc9a5140e;hp=061cbfa089e6e417b4f3c7a1e35e563380034da1;hpb=e63c14e793686ca3d8a47df6866134c21a77e4b7;p=ndwebbie.git diff --git a/index.pl b/index.pl index 061cbfa..31beaf5 100755 --- a/index.pl +++ b/index.pl @@ -31,25 +31,23 @@ my $cgi = new CGI; chdir $ENV{'DOCUMENT_ROOT'}; our $DBH = undef; -our $UID = undef; -our $PLANET = undef; -our $TEMPLATE = undef; -our $TICK = undef; +our $USER = $ENV{'REMOTE_USER'}; +my $error; -$ND::TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl'); +our $TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl'); for my $file ("db.pl","include.pl"){ unless (my $return = do $file){ - warn "couldn't parse $file: $@" if $@; - warn "couldn't do $file: $!" unless defined $return; - warn "couldn't run $file" unless $return; + print "couldn't parse $file: $@" if $@; + print "couldn't do $file: $!" unless defined $return; + print "couldn't run $file" unless $return; } } -($UID,$PLANET) = $DBH->selectrow_array('SELECT uid,planet FROM users WHERE username = ?' +our ($UID,$PLANET) = $DBH->selectrow_array('SELECT uid,planet FROM users WHERE username = ?' ,undef,$ENV{'REMOTE_USER'}); -($TICK) = $DBH->selectrow_array('SELECT tick()',undef); +our ($TICK) = $DBH->selectrow_array('SELECT tick()',undef); my $query = $DBH->prepare('SELECT groupname,attack,gid from groupmembers NATURAL JOIN groups WHERE uid = ?'); @@ -66,32 +64,33 @@ while (my ($name,$attack,$gid) = $query->fetchrow()){ our $LOG = $DBH->prepare('INSERT INTO log (uid,text) VALUES(?,?)'); my $page = 'main'; -if (param('page') =~ /^(main|check|motd|points|covop|top100|launchConfirmation|addintel|defrequest|raids)$/){ +if (param('page') =~ /^(main|check|motd|points|covop|top100|launchConfirmation|addintel|defrequest|raids|editRaid|calls|intel|users|alliances|memberIntel|resources)$/){ $page = $1; } our $XML = 0; $XML = 1 if param('xml') and $page =~ /^(raids)$/; +my $type = 'text/html'; if ($XML){ - print header(-type=>'text/xml'); + $type = 'text/xml'; $ND::TEMPLATE = HTML::Template->new(filename => "templates/xml.tmpl"); $ND::BODY = HTML::Template->new(filename => "templates/${page}.xml.tmpl"); }else{ - print header; $ND::BODY = HTML::Template->new(filename => "templates/${page}.tmpl"); } unless (my $return = do "${page}.pl"){ - print "

couldn't parse $page: $@

" if $@; - print "

couldn't do $page: $!

" unless defined $return; - print "

couldn't run $page

" unless $return; + $error .= "

couldn't parse $page: $@

" if $@; + $error .= "

couldn't do $page: $!

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

couldn't run $page

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