X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=index.pl;h=e1067c4f436bc4dc3615e3bc9bb31772f94cd8fb;hb=8d1ec9372fa9786009022fca3503ef3c79974f3e;hp=bfb7a738813a39aec091cf9e114954606d86e70c;hpb=e8b88c192ac9a54ca2310d955677ad4b8be9c68e;p=ndwebbie.git diff --git a/index.pl b/index.pl index bfb7a73..e1067c4 100755 --- a/index.pl +++ b/index.pl @@ -31,12 +31,9 @@ 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'}; -$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){ @@ -46,10 +43,11 @@ for my $file ("db.pl","include.pl"){ } } -($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 = ?'); $query->execute($UID); @@ -61,21 +59,26 @@ while (my ($name,$attack,$gid) = $query->fetchrow()){ $ATTACKER = 1 if $attack; } -$TEMPLATE->param(Tick => $TICK); -$TEMPLATE->param(isMember => isMember()); -$TEMPLATE->param(isHC => isHC()); -$TEMPLATE->param(isDC => isDC()); -$TEMPLATE->param(isBC => isBC()); -$TEMPLATE->param(isAttacker => $ATTACKER); - +our $LOG = $DBH->prepare('INSERT INTO log (uid,text) VALUES(?,?)'); my $page = 'main'; -if (param('page') =~ /^(main)$/){ +if (param('page') =~ /^(main|check|motd|points|covop|top100|launchConfirmation|addintel|defrequest|raids)$/){ $page = $1; } -$ND::BODY = HTML::Template->new(filename => "templates/${page}.tmpl"); +our $XML = 0; +$XML = 1 if param('xml') and $page =~ /^(raids)$/; + +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"); +} + unless (my $return = do "${page}.pl"){ print "

couldn't parse $page: $@

" if $@; @@ -83,14 +86,30 @@ unless (my $return = do "${page}.pl"){ print "

couldn't run $page

" unless $return; } -print header; +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(isAttacker => $ATTACKER && (!isMember() || ((($TICK - $fleetupdate < 24) || isScanner()) && $PLANET))); + if ($ATTACKER && (!isMember() || ((($TICK - $fleetupdate < 24) || isScanner()) && $PLANET))){ + $ND::TEMPLATE->param(Targets => listTargets()); + } + +} $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;