X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=index.pl;h=abedcdfc83464c5e4247414554705069be8e50e9;hb=3bed0704bb7fa0d3b6b8e8501b8ca6bbca7762bd;hp=e1067c4f436bc4dc3615e3bc9bb31772f94cd8fb;hpb=8d1ec9372fa9786009022fca3503ef3c79974f3e;p=ndwebbie.git diff --git a/index.pl b/index.pl index e1067c4..abedcdf 100755 --- a/index.pl +++ b/index.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl -w -T #************************************************************************** # Copyright (C) 2006 by Michael Andreen * # * @@ -25,21 +25,22 @@ use DBI; use DBD::Pg qw(:pg_types); use strict; - my $cgi = new CGI; - -chdir $ENV{'DOCUMENT_ROOT'}; - our $DBH = undef; our $USER = $ENV{'REMOTE_USER'}; +my $error; -our $TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl'); +if ($ENV{'DOCUMENT_ROOT'} =~ m{((\w|/)+)}){ + chdir $1; +} + +our $TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl', global_vars => 1); 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; } } @@ -63,41 +64,48 @@ 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)$/; +our $AJAX = 1; + my $type = 'text/html'; if ($XML){ $type = 'text/xml'; $ND::TEMPLATE = HTML::Template->new(filename => "templates/xml.tmpl"); $ND::BODY = HTML::Template->new(filename => "templates/${page}.xml.tmpl"); }else{ - $ND::BODY = HTML::Template->new(filename => "templates/${page}.tmpl"); + $ND::BODY = HTML::Template->new(filename => "templates/${page}.tmpl", global_vars => 1); + $ND::BODY->param(PAGE => $page); } 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()); $TEMPLATE->param(isDC => isDC()); $TEMPLATE->param(isBC => isBC()); + $TEMPLATE->param(isIntel => isBC()); $TEMPLATE->param(isAttacker => $ATTACKER && (!isMember() || ((($TICK - $fleetupdate < 24) || isScanner()) && $PLANET))); 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); @@ -113,7 +121,7 @@ $USER = undef; $PLANET = undef; $TEMPLATE = undef; $TICK = undef; -%GROUPS = undef; +undef %GROUPS; $ND::BODY = undef; exit;