2 #**************************************************************************
3 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
5 # This program is free software; you can redistribute it and/or modify *
6 # it under the terms of the GNU General Public License as published by *
7 # the Free Software Foundation; either version 2 of the License, or *
8 # (at your option) any later version. *
10 # This program is distributed in the hope that it will be useful, *
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 # GNU General Public License for more details. *
15 # You should have received a copy of the GNU General Public License *
16 # along with this program; if not, write to the *
17 # Free Software Foundation, Inc., *
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 #**************************************************************************/
22 use CGI qw/:standard/;
25 use DBD::Pg qw(:pg_types);
30 use warnings FATAL => 'all';
34 local $ND::req = Apache2::Request->new($ND::r, POST_MAX => "1M");
43 local $ND::PAGE = $ND::req->param('page');
45 if ($ENV{'SCRIPT_NAME'} =~ /(\w+)(\.(pl|php|pm))?$/){
46 $ND::PAGE = $1 unless $1 eq 'index' and $3 eq 'pl';
49 return Apache2::Const::OK;
53 our $DBH = ND::DB::DB();
54 our $USER = $ENV{'REMOTE_USER'};
55 my $error;# = $ND::r->param('page');
57 chdir '/var/www/ndawn/code';
59 our $TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl', global_vars => 1, cache => 1);
61 our ($UID,$PLANET) = $DBH->selectrow_array('SELECT uid,planet FROM users WHERE username = ?'
62 ,undef,$ENV{'REMOTE_USER'});
64 our ($TICK) = $DBH->selectrow_array('SELECT tick()',undef);
67 my $query = $DBH->prepare('SELECT groupname,attack,gid from groupmembers NATURAL JOIN groups WHERE uid = ?');
68 $query->execute($UID);
72 while (my ($name,$attack,$gid) = $query->fetchrow()){
73 $GROUPS{$name} = $gid;
74 $ATTACKER = 1 if $attack;
78 our $LOG = $DBH->prepare('INSERT INTO log (uid,text) VALUES(?,?)');
81 if ($ND::PAGE =~ /^(main|check|motd|points|covop|top100|launchConfirmation|addintel|defrequest|raids|editRaid|calls|intel|users|alliances|memberIntel|resources|planetNaps)$/){
86 $XML = 1 if param('xml') and $page =~ /^(raids)$/;
90 my $type = 'text/html';
93 $ND::TEMPLATE = HTML::Template->new(filename => "templates/xml.tmpl", cache => 1);
94 $ND::BODY = HTML::Template->new(filename => "templates/${page}.xml.tmpl", cache => 1);
96 $ND::BODY = HTML::Template->new(filename => "templates/${page}.tmpl", global_vars => 1, cache => 1);
97 $ND::BODY->param(PAGE => $page);
101 unless (my $return = do "${page}.pl"){
102 $error .= "<p><b>couldn't parse $page: $@</b></p>" if $@;
103 $error .= "<p><b>couldn't do $page: $!</b></p>" unless defined $return;
104 $error .= "<p><b>couldn't run $page</b></p>" unless $return;
108 my $fleetupdate = $DBH->selectrow_array('SELECT landing_tick FROM fleets WHERE uid = ? AND fleet = 0',undef,$UID);
111 $TEMPLATE->param(Tick => $TICK);
112 $TEMPLATE->param(isMember => (($TICK - $fleetupdate < 24) || isScanner()) && $PLANET && isMember());
113 $TEMPLATE->param(isHC => isHC());
114 $TEMPLATE->param(isDC => isDC());
115 $TEMPLATE->param(isBC => isBC());
116 $TEMPLATE->param(isIntel => isBC());
117 $TEMPLATE->param(isAttacker => $ATTACKER && (!isMember() || ((($TICK - $fleetupdate < 24) || isScanner()) && $PLANET)));
118 if ($ATTACKER && (!isMember() || ((($TICK - $fleetupdate < 24) || isScanner()) && $PLANET))){
119 $ND::TEMPLATE->param(Targets => listTargets());
121 $TEMPLATE->param(Coords => param('coords') ? param('coords') : '1:1:1');
122 $TEMPLATE->param(Error => $error);
125 $ND::TEMPLATE->param(BODY => $ND::BODY->output);
126 my $output = $TEMPLATE->output;
127 print header(-type=> $type, -charset => 'utf-8', -Content_Length => length $output);