]> ruin.nu Git - ndwebbie.git/blob - NDWeb/Pages/AddIntel.pm
01d28505919079799f19159358993d7f5ee81d40
[ndwebbie.git] / NDWeb / Pages / AddIntel.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
4 #   This program is free software; you can redistribute it and/or modify  *
5 #   it under the terms of the GNU General Public License as published by  *
6 #   the Free Software Foundation; either version 2 of the License, or     *
7 #   (at your option) any later version.                                   *
8 #                                                                         *
9 #   This program is distributed in the hope that it will be useful,       *
10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 #   GNU General Public License for more details.                          *
13 #                                                                         *
14 #   You should have received a copy of the GNU General Public License     *
15 #   along with this program; if not, write to the                         *
16 #   Free Software Foundation, Inc.,                                       *
17 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18 #**************************************************************************/
19
20 package ND::Web::Pages::AddIntel;
21 use strict;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
24 use ND::Web::Forum;
25 use ND::Web::Include;
26
27 use base qw/ND::Web::XMLPage/;
28
29 $ND::Web::Page::PAGES{addintel} = 'ND::Web::Pages::AddIntel';
30
31 sub render_body {
32         my $self = shift;
33         my ($BODY) = @_;
34
35         my $DBH = $self->{DBH};
36
37         $self->{TITLE} = 'Add Intel and Scans';
38
39         my $error;
40
41         return $self->noAccess unless $self->isMember;
42
43         if (defined param('cmd')){
44                 if (param('cmd') eq 'submit' || param('cmd') eq 'submit_message'){
45                         my $findscan = $DBH->prepare("SELECT scan_id FROM scans WHERE scan_id = ? AND tick >= tick() - 168");
46                         my $addscan = $DBH->prepare('INSERT INTO scans (scan_id,tick,"type") VALUES (?,tick(),?)');
47                         my $addpoint = $DBH->prepare('UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? ');
48                         my $intel = param('intel');
49                         my @scans;
50                         while ($intel =~ m/http:\/\/game.planetarion.com\/.+?scan(?:_id)?=(\d+)/g){
51                                 my %scan;
52                                 $scan{Scan} = $1;
53                                 $scan{Message} = "Scan $1: ";
54                                 $findscan->execute($1);
55                                 if ($findscan->rows == 0){
56                                         if ($addscan->execute($1,$ND::UID)){
57                                                 $addpoint->execute($ND::UID);
58                                                 $scan{Message} .= '<i>added</i>';
59                                         }else{
60                                                 $scan{Message} .= "<b>something went wrong:</b> <i>$DBH->errstr</i>";
61                                         }
62                                 }else{
63                                         $scan{Message} .= '<b>already exists</b>';
64                                 }
65                                 push @scans,\%scan;
66                         }
67                         $BODY->param(Scans => \@scans);
68                         my $tick = $self->{TICK};
69                         $tick = param('tick') if $tick =~ /^(\d+)$/;
70                         my $addintel = $DBH->prepare(qq{SELECT add_intel(?,?,?,?,?,?,?,?,?,?,?)});
71                         while ($intel =~ m/(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\*?\s+.+(?:Ter|Cat|Xan|Zik|Etd)?\s+(\d+)\s+(Attack|Defend)\s+(\d+)/g){
72                                 $addintel->execute($tick,$9, $1,$2,$3,$4,$5,$6,$7,$8,$ND::UID) or $error .= $DBH->errstr;
73                         }
74                 }
75                 if (param('cmd') eq 'submit_message'){
76                         my $board = {id => 12};
77                         my $subject = param('subject');
78                         unless ($subject){
79                                 if (param('intel') =~ /(.*\w.*)/){
80                                         $subject = $1;
81                                 }
82
83                         }
84                         if (my $thread = addForumThread $DBH,$board,$ND::UID,$subject){
85                                 $error .= p 'Intel message added' if addForumPost $DBH,$thread,$ND::UID,param('intel')
86                         }
87                 }
88         }
89         $BODY->param(Tick => $self->{TICK});
90         $BODY->param(Error => $error);
91         return $BODY;
92 }
93 1;