blib/lib/App/Netdisco/Web/Plugin/Report/PortLog.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 66 CC 2 SCAR 11.5
CC
2
Cov
0%
_sanity_ok
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.1
1 package App::Netdisco::Web::Plugin::Report::PortLog;
2  
3 use Dancer ':syntax';
4 use Dancer::Plugin::Ajax;
5 use Dancer::Plugin::DBIC;
6 use Dancer::Plugin::Auth::Extensible;
7  
8 use App::Netdisco::Web::Plugin;
9  
10 register_report({
11 tag => 'portlog',
12 label => 'Port Control Log',
13 category => 'Port', # not used
14 hidden => true,
15 });
16  
17 sub _sanity_ok {
18 return 0 unless
19 param('ip') =~ m/^[[:print:]]+$/
20 and param('port') =~ m/^[[:print:]]+$/
21 and param('log') =~ m/^[[:print:]]+$/;
22  
23 return 1;
24 }
25  
26 ajax '/ajax/control/report/portlog/add' => require_login sub {
27 send_error('Bad Request', 400) unless _sanity_ok();
28  
29 schema(vars->{'tenant'})->txn_do(sub {
30 my $user = schema(vars->{'tenant'})->resultset('DevicePortLog')
31 ->create({
32 ip => param('ip'),
33 port => param('port'),
34 reason => 'other',
35 log => param('log'),
36 username => session('logged_in_user'),
37 userip => request->remote_address,
38 action => 'comment',
39 });
40 });
41 };
42  
43 ajax '/ajax/content/report/portlog' => require_login sub {
44 my $device = param('q');
45 my $port = param('f');
46 send_error('Bad Request', 400) unless $device and $port;
47  
48 $device = schema(vars->{'tenant'})->resultset('Device')
49 ->search_for_device($device);
50 return unless $device;
51  
52 my $set = schema(vars->{'tenant'})->resultset('DevicePortLog')->search({
53 ip => $device->ip,
54 port => $port,
55 }, {
56 order_by => { -desc => [qw/creation/] },
57 rows => 200,
58 })->with_times;
59  
60 content_type('text/html');
61 template 'ajax/report/portlog.tt', {
62 results => $set,
63 }, { layout => 'noop' };
64 };
65  
66 true;