+++ /dev/null
-#**************************************************************************
-# Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
-# *
-# This program is free software; you can redistribute it and/or modify *
-# it under the terms of the GNU General Public License as published by *
-# the Free Software Foundation; either version 2 of the License, or *
-# (at your option) any later version. *
-# *
-# This program is distributed in the hope that it will be useful, *
-# but WITHOUT ANY WARRANTY; without even the implied warranty of *
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
-# GNU General Public License for more details. *
-# *
-# You should have received a copy of the GNU General Public License *
-# along with this program; if not, write to the *
-# Free Software Foundation, Inc., *
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
-#**************************************************************************/
-
-package NDWeb::Pages::AddIntel;
-use strict;
-use warnings;
-use CGI qw/:standard/;
-use NDWeb::Forum;
-use NDWeb::Include;
-
-use base qw/NDWeb::XMLPage/;
-
-$NDWeb::Page::PAGES{addintel} = 'NDWeb::Pages::AddIntel';
-
-sub render_body {
- my $self = shift;
- my ($BODY) = @_;
-
- my $DBH = $self->{DBH};
-
- $self->{TITLE} = 'Add Intel and Scans';
-
- my $error;
-
- return $self->noAccess unless $self->isMember;
-
- if (defined param('cmd')){
- if (param('cmd') eq 'submit' || param('cmd') eq 'submit_message'){
- my $findscan = $DBH->prepare(q{SELECT scan_id FROM scans WHERE scan_id = ? AND tick >= tick() - 168 AND groupscan = ?});
- my $addscan = $DBH->prepare(q{INSERT INTO scans (scan_id,tick,uid,groupscan) VALUES (?,tick(),?,?)});
- my $addpoint = $DBH->prepare(q{UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? });
- my $intel = param('intel');
- my @scans;
- while ($intel =~ m{http://[\w.]+/.+?scan(_id|_grp)?=(\d+)}g){
- my $groupscan = (defined $1 && $1 eq '_grp') || 0;
- my %scan;
- $scan{Scan} = $2;
- $scan{Message} = ($groupscan ? b 'Group':'')."Scan $2: ";
- $findscan->execute($2,$groupscan);
- if ($findscan->rows == 0){
- if ($addscan->execute($2,$ND::UID,$groupscan)){
- $addpoint->execute($ND::UID) unless $groupscan;
- $scan{Message} .= '<i>added</i>';
- }else{
- $scan{Message} .= "<b>something went wrong:</b> <i>$DBH->errstr</i>";
- }
- }else{
- $scan{Message} .= '<b>already exists</b>';
- }
- push @scans,\%scan;
- }
- $BODY->param(Scans => \@scans);
- my $tick = $self->{TICK};
- $tick = param('tick') if defined param('tick')
- && param('tick') =~ /^(\d+)$/;
- my $addintel = $DBH->prepare(q{INSERT INTO fleets
- (name,mission,tick,target,sender,eta,amount,ingal,back,uid)
- VALUES($1,$2,$3,planetid($4,$5,$6,$10),planetid($7,$8,$9,$10)
- ,$11,$12,$13,$14,$15)
- });
- my $findplanet = $DBH->prepare(q{SELECT planetid(?,?,?,?)});
- while ($intel =~ m/(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)
- \*?\s+(.+)(?:Ter|Cat|Xan|Zik|Etd)?
- \s+(\d+)\s+(Attack|Defend)\s+(\d+)/gx){
- my $ingal = ($1 == $4 && $2 == $5) || 0;
- my $lt = $tick + $10;
- my $back = ($ingal ? $lt + 4 : undef);
- warn "Added: $&\n";
- $addintel->execute($7,$9,$lt,$1,$2,$3,$4,$5,$6,$tick,$10,$8
- ,$ingal,$back, $ND::UID) or warn $DBH->errstr;
- }
- }
- if (param('cmd') eq 'submit_message'){
- my $board = {id => 12};
- my $subject = param('subject');
- unless ($subject){
- if (param('intel') =~ /(.*\w.*)/){
- $subject = $1;
- }
- }
- if (my $thread = addForumThread $DBH,$board,$ND::UID,$subject){
- $error .= 'Intel message added' if addForumPost $DBH,$thread,$ND::UID,param('intel')
- }
- }
- }
- $BODY->param(Tick => $self->{TICK});
- $BODY->param(Error => $error);
- return $BODY;
-}
-1;
sub newThread : Local {
my ( $self, $c, $board ) = @_;
- my $dbh = $c->model;
$c->forward('findBoard');
$board = $c->stash->{board};
unless ($c->stash->{board}->{post}){
$c->acl_access_denied('test',$c->action,'No post access to board.')
}
-
+
+ $c->forward('insertThread');
+ $c->forward('addPost',[$c->stash->{thread}]);
+}
+
+sub insertThread : Private {
+ my ( $self, $c, $board ) = @_;
+ my $dbh = $c->model;
+
my $insert = $dbh->prepare(q{INSERT INTO forum_threads (ftid,fbid,subject,uid)
VALUES(DEFAULT,$1,$2,$3) RETURNING (ftid);
});
-
- $insert->execute($board->{fbid},html_escape($c->req->param('subject')),$c->stash->{UID});
- my $thread = $insert->fetchrow;
+ $insert->execute($board,html_escape($c->req->param('subject')),$c->stash->{UID});
+ $c->stash(thread => $insert->fetchrow);
$insert->finish;
- $c->forward('addPost',[$thread]);
-
}
sub addPost : Local {
$c->stash(members => \@members);
}
+sub addintel : Local {
+ my ( $self, $c, $order ) = @_;
+
+ $c->stash(intel => $c->flash->{intel});
+ $c->stash(scans => $c->flash->{scans});
+ $c->stash(intelmessage => $c->flash->{intelmessage});
+}
+
+sub postintel : Local {
+ my ( $self, $c, $order ) = @_;
+
+ $c->forward('insertintel');
+
+ $c->res->redirect($c->uri_for('addintel'));
+}
+
+sub postintelmessage : Local {
+ my ( $self, $c, $order ) = @_;
+
+ unless ($c->req->param('subject')){
+ if ($c->req->param('message') =~ /(.*\w.*)/){
+ $c->req->param(subject => $1);
+ }
+ }
+
+ $c->forward('/forum/insertThread',[12]);
+ $c->forward('/forum/insertPost',[$c->stash->{thread}]);
+ $c->flash(intelmessage => 1);
+
+ $c->forward('insertintel');
+
+ $c->res->redirect($c->uri_for('addintel'));
+}
+
+sub insertintel : Private {
+ my ( $self, $c, $order ) = @_;
+ my $dbh = $c->model;
+
+ $dbh->begin_work;
+ my $findscan = $dbh->prepare(q{SELECT scan_id FROM scans
+ WHERE scan_id = ? AND tick >= tick() - 168 AND groupscan = ?
+ });
+ my $addscan = $dbh->prepare(q{INSERT INTO scans (scan_id,tick,uid,groupscan)
+ VALUES (?,tick(),?,?)
+ });
+ my $addpoint = $dbh->prepare(q{UPDATE users SET scan_points = scan_points + 1
+ WHERE uid = ?
+ });
+ my @scans;
+ my $intel = $c->req->param('message');
+ while ($intel =~ m{http://[\w.]+/.+?scan(_id|_grp)?=(\d+)}g){
+ my $groupscan = (defined $1 && $1 eq '_grp') || 0;
+ my %scan;
+ $scan{id} = $2;
+ $scan{group} = $groupscan;
+ $findscan->execute($2,$groupscan);
+ if ($findscan->rows == 0){
+ if ($addscan->execute($2,$c->user->id,$groupscan)){
+ $addpoint->execute($c->user->id) unless $groupscan;
+ $scan{added} = 1;
+ }
+ }else{
+ $scan{message} = 'already exists';
+ }
+ push @scans,\%scan;
+ }
+ my $tick = $c->req->param('tick');
+ unless ($tick =~ /^(\d+)$/){
+ $tick = $c->stash->{game}->{tick};
+ }
+ my $addintel = $dbh->prepare(q{INSERT INTO fleets
+ (name,mission,tick,target,sender,eta,amount,ingal,back,uid)
+ VALUES($1,$2,$3,planetid($4,$5,$6,$10),planetid($7,$8,$9,$10)
+ ,$11,$12,$13,$14,$15)
+ });
+ my @intel;
+ while ($intel =~ m/(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)
+ \*?\s+(.+)(?:Ter|Cat|Xan|Zik|Etd)?
+ \s+(\d+)\s+(Attack|Defend)\s+(\d+)/gx){
+ my $ingal = ($1 == $4 && $2 == $5) || 0;
+ my $lt = $tick + $10;
+ my $back = ($ingal ? $lt + 4 : undef);
+ eval {
+ $addintel->execute($7,$9,$lt,$1,$2,$3,$4,$5,$6,$tick,$10,$8
+ ,$ingal,$back, $c->user->id);
+ push @intel,"Added $&";
+ };
+ if ($@){
+ push @intel,"Couldn't add $&: ".$dbh->errstr;
+ }
+ }
+ $dbh->commit;
+ $c->flash(intel => \@intel);
+ $c->flash(scans => \@scans);
+}
+
=head1 AUTHOR
Michael Andreen (harv@ruin.nu)
--- /dev/null
+[% META title = 'Add intel and scans' %]
+[% IF scans.size > 0 %]
+<div class="leftinfo">
+<h3>Added the following scans:</h3>
+ [% FOR s IN scans %]
+<p>[%IF s.group %]<b>Group </b>[%END%][% s.id %]: [% IF s.added %]<i>added</i>
+ [%ELSE%]<b>[% s.message %]</b>[%END%]</p>
+ [% END %]
+</div>
+[% END %]
+
+[% IF intel.size > 0 %]
+<div class="leftinfo">
+<h3>Added the following intel:</h3>
+ [% FOR i IN intel %]
+<p>[% i %]</p>
+ [% END %]
+</div>
+[% END %]
+
+[% IF intelmessage %]
+<p style="clear: both"><b>Intel message has been forwarrded to intel dept</b></p>
+[% END %]
+
+<div style="clear: left" class="leftinfo">
+ <form action="[% c.uri_for('postintel') %]" method="post"><fieldset> <legend>Intel/scans</legend>
+ <p>Paste <b>scan urls</b> and intel from <b>gal status</b> here</p>
+ <textarea rows="20" cols="50" name="message"></textarea>
+ <p>Tick:<input type="text" name="tick" value="[% game.tick %]">
+ <input type="submit" name="cmd" value="Submit">
+ </p>
+ </fieldset></form>
+</div>
+
+<div class="leftinfo">
+<form action="[% c.uri_for('postintelmessage') %]" method="post"><fieldset> <legend>Intel</legend>
+ <p>Write other messages to intel dept here (sms numbers, relay channels, bots etc) (<b>NOT gal status</b>):</p>
+ <textarea rows="20" cols="50" name="message"></textarea>
+ <p>Subject: <input type="text" name="subject" value="">
+ Tick:<input style='width: 4em' type="text" name="tick" value="[% game.tick %]">
+ <input type="submit" name="cmd" value="Submit"></p>
+</fieldset></form>
+</div>
+
+
+
+++ /dev/null
-<TMPL_VAR NAME=Error>
-<TMPL_LOOP Scans>
-<p><TMPL_VAR NAME=Scan> <TMPL_VAR NAME=Message></p>
-</TMPL_LOOP>
-<div class="leftinfo">
- <form action="<TMPL_VAR NAME=PAGE>" method="post"><fieldset> <legend>Intel/scans</legend>
- <p>Paste <b>scan urls</b> and intel from <b>gal status</b> here</p>
- <textarea rows="20" cols="50" name="intel"></textarea>
- <input type="hidden" name="cmd" value="submit"/>
- <input type="hidden" name="page" value="<TMPL_VAR NAME=PAGE>"/>
- <br/>Tick:<input type="text" name="tick" value="<TMPL_VAR NAME=Tick>"/>
- <input type="submit" value="Submit"/>
- </fieldset></form>
-</div>
-
-<div class="leftinfo">
-<form action="<TMPL_VAR NAME=PAGE>" method="post"><fieldset> <legend>Intel</legend>
- <p>Write other messages to intel dept here (sms numbers, relay channels, bots etc) (<b>NOT gal status</b>):</p>
- <textarea rows="20" cols="50" name="intel"></textarea>
- <input type="hidden" name="cmd" value="submit_message"/>
- <input type="hidden" name="page" value="<TMPL_VAR NAME=PAGE>"/>
- <br/>Subject: <input type="text" name="subject" value=""/>
- <input type="submit" value="Submit"/>
-</fieldset></form>
-</div>