From f9122ce72e1153eac5822e6600dbc6cd1c3fa410 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 1 Jan 2015 16:48:18 +0000 Subject: [PATCH 1/7] update M::I --- Netdisco/META.yml | 10 +++++----- Netdisco/inc/Module/Install.pm | 18 +++++++++--------- Netdisco/inc/Module/Install/Base.pm | 2 +- Netdisco/inc/Module/Install/Can.pm | 2 +- Netdisco/inc/Module/Install/Fetch.pm | 2 +- Netdisco/inc/Module/Install/Makefile.pm | 4 ++-- Netdisco/inc/Module/Install/Metadata.pm | 6 +++--- Netdisco/inc/Module/Install/Scripts.pm | 2 +- Netdisco/inc/Module/Install/Share.pm | 2 +- Netdisco/inc/Module/Install/Win32.pm | 2 +- Netdisco/inc/Module/Install/WriteAll.pm | 2 +- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Netdisco/META.yml b/Netdisco/META.yml index a58d7f29..885716b3 100644 --- a/Netdisco/META.yml +++ b/Netdisco/META.yml @@ -7,11 +7,11 @@ build_requires: ExtUtils::MakeMaker: 6.59 Test::More: 0.88 configure_requires: - DBIx::Class: 0.082801 + DBIx::Class: '0.082801' ExtUtils::MakeMaker: 6.59 distribution_type: module dynamic_config: 1 -generated_by: 'Module::Install version 1.06' +generated_by: 'Module::Install version 1.12' license: bsd meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -39,7 +39,7 @@ requires: DBIx::Class: 0.08281 DBIx::Class::Helpers: 2.024 Daemon::Control: 0.001006 - Dancer: 1.3132 + Dancer: '1.3132' Dancer::Plugin::Auth::Extensible: 0.3 Dancer::Plugin::DBIC: 0.2001 Dancer::Plugin::Passphrase: 2.0.1 @@ -68,7 +68,7 @@ requires: Plack::Middleware::ReverseProxy: 0.15 Role::Tiny: 1.002005 SNMP::Info: 3.18 - SQL::Translator: 0.11018 + SQL::Translator: '0.11018' Sereal: 0 Socket6: 0.23 Starman: 0.4008 @@ -91,4 +91,4 @@ resources: homepage: http://netdisco.org/ license: http://opensource.org/licenses/bsd-license.php repository: git://git.code.sf.net/p/netdisco/netdisco-ng -version: 2.029014 +version: '2.029014' diff --git a/Netdisco/inc/Module/Install.pm b/Netdisco/inc/Module/Install.pm index 4ecf46b9..5460dd50 100644 --- a/Netdisco/inc/Module/Install.pm +++ b/Netdisco/inc/Module/Install.pm @@ -17,7 +17,7 @@ package Module::Install; # 3. The ./inc/ version of Module::Install loads # } -use 5.005; +use 5.006; use strict 'vars'; use Cwd (); use File::Find (); @@ -31,7 +31,7 @@ BEGIN { # This is not enforced yet, but will be some time in the next few # releases once we can make sure it won't clash with custom # Module::Install extensions. - $VERSION = '1.06'; + $VERSION = '1.12'; # Storage for the pseudo-singleton $MAIN = undef; @@ -156,10 +156,10 @@ END_DIE sub autoload { my $self = shift; my $who = $self->_caller; - my $cwd = Cwd::cwd(); + my $cwd = Cwd::getcwd(); my $sym = "${who}::AUTOLOAD"; $sym->{$cwd} = sub { - my $pwd = Cwd::cwd(); + my $pwd = Cwd::getcwd(); if ( my $code = $sym->{$pwd} ) { # Delegate back to parent dirs goto &$code unless $cwd eq $pwd; @@ -239,7 +239,7 @@ sub new { # ignore the prefix on extension modules built from top level. my $base_path = Cwd::abs_path($FindBin::Bin); - unless ( Cwd::abs_path(Cwd::cwd()) eq $base_path ) { + unless ( Cwd::abs_path(Cwd::getcwd()) eq $base_path ) { delete $args{prefix}; } return $args{_self} if $args{_self}; @@ -338,7 +338,7 @@ sub find_extensions { if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) { my $content = Module::Install::_read($subpath . '.pm'); my $in_pod = 0; - foreach ( split //, $content ) { + foreach ( split /\n/, $content ) { $in_pod = 1 if /^=\w/; $in_pod = 0 if /^=cut/; next if ($in_pod || /^=cut/); # skip pod text @@ -434,7 +434,7 @@ END_OLD # _version is for processing module versions (eg, 1.03_05) not # Perl versions (eg, 5.8.1). -sub _version ($) { +sub _version { my $s = shift || 0; my $d =()= $s =~ /(\.)/g; if ( $d >= 2 ) { @@ -450,12 +450,12 @@ sub _version ($) { return $l + 0; } -sub _cmp ($$) { +sub _cmp { _version($_[1]) <=> _version($_[2]); } # Cloned from Params::Util::_CLASS -sub _CLASS ($) { +sub _CLASS { ( defined $_[0] and diff --git a/Netdisco/inc/Module/Install/Base.pm b/Netdisco/inc/Module/Install/Base.pm index 802844aa..f9bf5de5 100644 --- a/Netdisco/inc/Module/Install/Base.pm +++ b/Netdisco/inc/Module/Install/Base.pm @@ -4,7 +4,7 @@ package Module::Install::Base; use strict 'vars'; use vars qw{$VERSION}; BEGIN { - $VERSION = '1.06'; + $VERSION = '1.12'; } # Suspend handler for "redefined" warnings diff --git a/Netdisco/inc/Module/Install/Can.pm b/Netdisco/inc/Module/Install/Can.pm index 22167b8f..b4e5e3b4 100644 --- a/Netdisco/inc/Module/Install/Can.pm +++ b/Netdisco/inc/Module/Install/Can.pm @@ -8,7 +8,7 @@ use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.06'; + $VERSION = '1.12'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } diff --git a/Netdisco/inc/Module/Install/Fetch.pm b/Netdisco/inc/Module/Install/Fetch.pm index bee0c4fb..54f14fb5 100644 --- a/Netdisco/inc/Module/Install/Fetch.pm +++ b/Netdisco/inc/Module/Install/Fetch.pm @@ -6,7 +6,7 @@ use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.06'; + $VERSION = '1.12'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } diff --git a/Netdisco/inc/Module/Install/Makefile.pm b/Netdisco/inc/Module/Install/Makefile.pm index 7052f365..81cddd55 100644 --- a/Netdisco/inc/Module/Install/Makefile.pm +++ b/Netdisco/inc/Module/Install/Makefile.pm @@ -8,7 +8,7 @@ use Fcntl qw/:flock :seek/; use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.06'; + $VERSION = '1.12'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } @@ -133,7 +133,7 @@ sub makemaker_args { return $args; } -# For mm args that take multiple space-seperated args, +# For mm args that take multiple space-separated args, # append an argument to the current list. sub makemaker_append { my $self = shift; diff --git a/Netdisco/inc/Module/Install/Metadata.pm b/Netdisco/inc/Module/Install/Metadata.pm index 58430f30..2c66b1e2 100644 --- a/Netdisco/inc/Module/Install/Metadata.pm +++ b/Netdisco/inc/Module/Install/Metadata.pm @@ -6,7 +6,7 @@ use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.06'; + $VERSION = '1.12'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } @@ -347,7 +347,7 @@ sub name_from { ^ \s* package \s* ([\w:]+) - \s* ; + [\s|;]* /ixms ) { my ($name, $module_name) = ($1, $1); @@ -705,7 +705,7 @@ sub _write_mymeta_data { my @yaml = Parse::CPAN::Meta::LoadFile('META.yml'); my $meta = $yaml[0]; - # Overwrite the non-configure dependency hashs + # Overwrite the non-configure dependency hashes delete $meta->{requires}; delete $meta->{build_requires}; delete $meta->{recommends}; diff --git a/Netdisco/inc/Module/Install/Scripts.pm b/Netdisco/inc/Module/Install/Scripts.pm index 419286f3..66a33504 100644 --- a/Netdisco/inc/Module/Install/Scripts.pm +++ b/Netdisco/inc/Module/Install/Scripts.pm @@ -6,7 +6,7 @@ use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.06'; + $VERSION = '1.12'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } diff --git a/Netdisco/inc/Module/Install/Share.pm b/Netdisco/inc/Module/Install/Share.pm index 4e2b602a..a67f6e00 100644 --- a/Netdisco/inc/Module/Install/Share.pm +++ b/Netdisco/inc/Module/Install/Share.pm @@ -8,7 +8,7 @@ use ExtUtils::Manifest (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.06'; + $VERSION = '1.12'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } diff --git a/Netdisco/inc/Module/Install/Win32.pm b/Netdisco/inc/Module/Install/Win32.pm index eeaa3fed..e48c32d9 100644 --- a/Netdisco/inc/Module/Install/Win32.pm +++ b/Netdisco/inc/Module/Install/Win32.pm @@ -6,7 +6,7 @@ use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.06'; + $VERSION = '1.12'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } diff --git a/Netdisco/inc/Module/Install/WriteAll.pm b/Netdisco/inc/Module/Install/WriteAll.pm index 85d8018c..409ef40c 100644 --- a/Netdisco/inc/Module/Install/WriteAll.pm +++ b/Netdisco/inc/Module/Install/WriteAll.pm @@ -6,7 +6,7 @@ use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.06'; + $VERSION = '1.12'; @ISA = qw{Module::Install::Base}; $ISCORE = 1; } From 06f62f97b73ca67d2d6ff2c2f9a409012e52a9e6 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 1 Jan 2015 17:48:25 +0000 Subject: [PATCH 2/7] [#4] Allow comment on device port in the log, for any user --- Netdisco/Changes | 4 +++ .../lib/App/Netdisco/DB/Result/DevicePort.pm | 22 +++++++++++++ .../App/Netdisco/DB/ResultSet/DevicePort.pm | 1 + Netdisco/lib/App/Netdisco/Web/Device.pm | 1 + .../App/Netdisco/Web/Plugin/Report/PortLog.pm | 26 ++++++++++++++++ Netdisco/share/views/ajax/device/ports.tt | 11 +++++-- Netdisco/share/views/ajax/report/portlog.tt | 21 ++++++++++--- Netdisco/share/views/js/report.js | 31 +++++++++++++++++++ 8 files changed, 110 insertions(+), 7 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index cc01e03c..d0286d10 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,5 +1,9 @@ 2.029015 + [NEW FEATURES] + + * [#4] Allow comment on device port in the log, for any user + [ENHANCEMENTS] * Request net-snmp-devel on Fedora/Red-Hat builds diff --git a/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm b/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm index 93b94367..8093e42e 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm @@ -160,6 +160,16 @@ __PACKAGE__->has_many( active_nodes_with_age => 'App::Netdisco::DB::Result::Virt cascade_copy => 0, cascade_update => 0, cascade_delete => 0 }, ); +=head2 logs + +Returns the set of C entries associated with this Port. + +=cut + +__PACKAGE__->has_many( logs => 'App::Netdisco::DB::Result::DevicePortLog', + { 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port' }, +); + =head2 power Returns a row from the C table if one refers to this @@ -345,4 +355,16 @@ Returns the C column instantiated into a L object. sub net_mac { return NetAddr::MAC->new(mac => (shift)->mac) } +=head2 last_comment + +Returns the most recent comment from the logs for this device port. + +=cut + +sub last_comment { + my $row = (shift)->logs->search(undef, + { order_by => { -desc => 'creation' }, rows => 1 })->first; + return ($row ? $row->log : ''); +} + 1; diff --git a/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm b/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm index 4b471617..91ee2682 100644 --- a/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm +++ b/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm @@ -157,6 +157,7 @@ sub delete { DevicePortVlan DevicePortWireless DevicePortSsid + DevicePortLog /) { $schema->resultset($set)->search( { ip => { '-in' => $ports->as_query }}, diff --git a/Netdisco/lib/App/Netdisco/Web/Device.pm b/Netdisco/lib/App/Netdisco/Web/Device.pm index 23ea7caa..2235d7d9 100644 --- a/Netdisco/lib/App/Netdisco/Web/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Device.pm @@ -14,6 +14,7 @@ hook 'before' => sub { my @default_port_columns_right = ( { name => 'c_descr', label => 'Description', default => '' }, + { name => 'c_comment', label => 'Last Comment', default => '' }, { name => 'c_type', label => 'Type', default => '' }, { name => 'c_duplex', label => 'Duplex', default => '' }, { name => 'c_lastchange', label => 'Last Change', default => '' }, diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/PortLog.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/PortLog.pm index 73ca2700..5c8c9081 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/PortLog.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/PortLog.pm @@ -14,6 +14,32 @@ register_report({ hidden => true, }); +sub _sanity_ok { + return 0 unless + param('ip') =~ m/^[[:print:]]+$/ + and param('port') =~ m/^[[:print:]]+$/ + and param('log') =~ m/^[[:print:]]+$/; + + return 1; +} + +ajax '/ajax/control/report/portlog/add' => require_login sub { + send_error('Bad Request', 400) unless _sanity_ok(); + + schema('netdisco')->txn_do(sub { + my $user = schema('netdisco')->resultset('DevicePortLog') + ->create({ + ip => param('ip'), + port => param('port'), + reason => 'other', + log => param('log'), + username => session('logged_in_user'), + userip => request->remote_address, + action => 'comment', + }); + }); +}; + ajax '/ajax/content/report/portlog' => require_role port_control => sub { my $device = param('q'); my $port = param('f'); diff --git a/Netdisco/share/views/ajax/device/ports.tt b/Netdisco/share/views/ajax/device/ports.tt index 4e23349c..f91bf468 100644 --- a/Netdisco/share/views/ajax/device/ports.tt +++ b/Netdisco/share/views/ajax/device/ports.tt @@ -82,6 +82,10 @@ rel="tooltip" data-placement="top" data-offset="3" data-animation="" data-title="Enable Port"> + [% END %] + [% ELSE %] + [% END %] @@ -89,9 +93,6 @@ rel="tooltip" data-placement="top" data-offset="3" data-animation="" data-title="View Port Log"> - [% ELSE %] - - [% END %] [% IF row.is_master %] @@ -121,6 +122,10 @@ [% row.descr | html_entity %] [% END %] + [% IF params.c_comment %] + [% row.last_comment | html_entity %] + [% END %] + [% IF params.c_type %] [% row.type | html_entity %] [% END %] diff --git a/Netdisco/share/views/ajax/report/portlog.tt b/Netdisco/share/views/ajax/report/portlog.tt index 777e32d1..b229065e 100644 --- a/Netdisco/share/views/ajax/report/portlog.tt +++ b/Netdisco/share/views/ajax/report/portlog.tt @@ -1,6 +1,3 @@ -[% IF results.count == 0 %] -
This port's log is empty.
-[% ELSE %] @@ -10,9 +7,24 @@ + + + + + + + + + + + + + [% WHILE (row = results.next) %] @@ -21,15 +33,16 @@ + [% END %]
Action Reason LogAction
-[% session.logged_in_user | html_entity %]-commentOther + +
[% row.creation_stamp | html_entity %][% row.action | html_entity %] [% settings.port_control_reasons.item(row.reason) || row.reason | html_entity %] [% row.log || '-' | html_entity %]
-[% END %]