From 04d89320a8487acb9e24e635a409a0745be8329c Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 31 Jul 2014 22:54:28 +0100 Subject: [PATCH] Squashed commit of the following: * Support for stuffing other locations into @INC at runtime * Reports config is now a list (see ReleaseNotes) commit 19756faf57728533dc6b431d2cd3dca70637f13c Merge: 2e8afbe 29d3ac7 Author: Oliver Gorwits Date: Thu Jul 31 21:32:30 2014 +0100 Merge branch 'master' into og-autoload Conflicts: Netdisco/share/public/javascripts/netdisco_portcontrol.js commit 2e8afbeea615562d05e367fd912dc8f27258bc9c Merge: d340c3b 18f507e Author: Oliver Gorwits Date: Wed Jul 23 20:09:18 2014 +0100 Merge branch 'master' into og-autoload commit d340c3b135c2ebc3c8d45abad373f8a7695f77fa Author: Oliver Gorwits Date: Mon Jul 7 22:25:38 2014 +0100 tweak dirty css commit 032cd82c46c074d8bac396fc9c0222d6c79f75cd Author: Oliver Gorwits Date: Sun Jul 6 23:05:17 2014 +0100 add dirty classes commit 2b72c989fa9002344da65e80437e4ce5a51900fa Merge: 1b8ac7c b77025f Author: Oliver Gorwits Date: Fri Jul 4 11:28:01 2014 +0100 Merge branch 'og-autoload' of ssh://git.code.sf.net/p/netdisco/netdisco-ng into og-autoload commit b77025f34c02c6163186fc8ae22e26ddbe95ff05 Author: Oliver Gorwits Date: Thu Jul 3 23:35:35 2014 +0100 hide save icon commit 5df5a73aed175767f7bae08594a30ac462c80245 Author: Oliver Gorwits Date: Wed Jul 2 22:31:18 2014 +0100 blue color commit a3bf20f07462b976f7a9e0ad878f6bccff6d6261 Merge: 1839f26 db53c00 Author: Oliver Gorwits Date: Wed Jul 2 15:17:25 2014 +0100 Merge branch 'master' into og-autoload commit 1b8ac7ca1fff76c287bfa35cb59a8099822683f8 Merge: 1839f26 db53c00 Author: Oliver Gorwits Date: Wed Jul 2 09:23:31 2014 +0100 Merge branch 'master' into og-autoload commit 1839f2634b1d70dc61a409a683e644239cd2d7d0 Author: Oliver Gorwits Date: Wed Jul 2 03:43:53 2014 +0100 add jquery.fix.clone.js commit 3eee9f19975787882cf0ce774ccfaa1fe0877e6c Author: Oliver Gorwits Date: Wed Jul 2 00:08:27 2014 +0100 save button css commit 95b6cb61b36d4476f3584c965c876d8436da4c82 Merge: 13957e8 58e5d05 Author: Oliver Gorwits Date: Tue Jul 1 21:50:01 2014 +0100 Merge branch 'master' into og-autoload Conflicts: Netdisco/share/config.yml commit 13957e82dcefe366c04fe633a81bd4d4e67b5980 Merge: bedbec6 6abceba Author: Oliver Gorwits Date: Mon Jun 30 22:50:40 2014 +0100 Merge branch 'og-autoload' of ssh://git.code.sf.net/p/netdisco/netdisco-ng into og-autoload commit bedbec6b4ba1dcd7ad101b8b0f745a62527647d3 Author: Oliver Gorwits Date: Mon Jun 30 22:49:49 2014 +0100 css fixes commit 6e2d5a4b48ab527a6b6fc4bf922cdfd723a6e135 Author: Oliver Gorwits Date: Mon Jun 30 21:30:26 2014 +0100 css fixes commit 755fc92c595ba4caee8906384ff839d87dfe6a22 Author: Oliver Gorwits Date: Mon Jun 30 13:05:43 2014 +0100 reports now a list not a hash commit 6abcebafbe2514fb13588b973250e2b8e12992db Author: Oliver Gorwits Date: Sun Jun 29 12:41:47 2014 +0100 start as non-root if port switch not required commit e5e0c0c8d1092042066eebf5d6eb1739998a6b9f Author: Oliver Gorwits Date: Sat Jun 28 13:10:51 2014 +0100 fix err in docs commit 6d680aabed3b64aa0f7157a6de40ff926c1d7563 Author: Oliver Gorwits Date: Sat Jun 28 11:10:23 2014 +0100 move content commit d2668d6db7b25dc46c577b9bf52991bc2f452c9d Author: Oliver Gorwits Date: Fri Jun 27 00:30:54 2014 +0100 minor styling commit e46cbd252de846fae556ee45ed38b8c585c9edb2 Author: Oliver Gorwits Date: Thu Jun 26 23:19:19 2014 +0100 add bootstrap-switch checkbox styling commit 5b0a723c9ffd3e4029c901e834275f8ca3490826 Author: Oliver Gorwits Date: Wed Jun 25 22:20:57 2014 +0100 typo in defaults commit e45fa89c44ea75196e65b6914a659ddc501fca95 Author: Oliver Gorwits Date: Tue Jun 24 22:42:45 2014 +0100 css for configuration pane commit 62c53a5e4925d5b70a5fc9d0b2313c54a527538c Author: Oliver Gorwits Date: Mon Jun 23 23:33:26 2014 +0100 minor typo commit caedbdadc694e3b03e873f4dafb030e2a051ab20 Author: Oliver Gorwits Date: Mon Jun 23 20:35:30 2014 +0100 properly search the template path!! [#103] commit 5742bc7856c331e503a240bfb4aa67200d3f5a49 Author: Oliver Gorwits Date: Sun Jun 22 23:13:53 2014 +0100 fix registering template paths commit 2b09476f29a4906226d43c6c48956f2358741882 Author: Oliver Gorwits Date: Sun Jun 22 22:19:35 2014 +0100 allow INC stuffing via NETDISCO_INC env var commit 7c47a277beaa8c7236c09bb80b4bf1f3ec5c0dd6 Merge: 128e96f 3a1cd19 Author: Oliver Gorwits Date: Sun Jun 22 22:17:11 2014 +0100 Merge branch 'master' into og-autoload commit 128e96f9a345e86630c5dbed40b9882825ad1043 Author: Oliver Gorwits Date: Sun Jun 22 20:48:01 2014 +0100 use Module::Find to load Auto things and Web --- Netdisco/Changes | 4 ++- Netdisco/Makefile.PL | 1 + Netdisco/bin/netdisco-daemon-fg | 3 +++ Netdisco/bin/netdisco-web-fg | 3 +++ Netdisco/lib/App/Netdisco.pm | 3 +++ Netdisco/lib/App/Netdisco/Configuration.pm | 13 ++++++++++ .../lib/App/Netdisco/Manual/Configuration.pod | 18 +++++++++---- .../lib/App/Netdisco/Manual/ReleaseNotes.pod | 25 +++++++++++++++++++ .../App/Netdisco/Manual/WritingPlugins.pod | 6 ++--- Netdisco/lib/App/Netdisco/Web.pm | 15 +++-------- .../lib/App/Netdisco/Web/GenericReport.pm | 6 ++--- Netdisco/share/config.yml | 4 ++- 12 files changed, 77 insertions(+), 24 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index f88e712a..b017614e 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,8 +1,10 @@ -2.028014 +2.029000 [ENHANCEMENTS] * [#108] Port Bounce port control feature (down and up in succession) + * Support for stuffing other locations into @INC at runtime + * Reports config is now a list (see ReleaseNotes) [BUG FIXES] diff --git a/Netdisco/Makefile.PL b/Netdisco/Makefile.PL index b3ef5d02..4c4b642f 100644 --- a/Netdisco/Makefile.PL +++ b/Netdisco/Makefile.PL @@ -28,6 +28,7 @@ requires 'HTTP::Tiny' => 0.029; requires 'JSON' => 0; requires 'List::MoreUtils' => 0.33; requires 'MIME::Base64' => 3.13; +requires 'Module::Find' => 0.12; requires 'Module::Load' => 0.32; requires 'Moo' => 1.001000; requires 'MCE' => 1.408; diff --git a/Netdisco/bin/netdisco-daemon-fg b/Netdisco/bin/netdisco-daemon-fg index f10e332c..69a73c39 100755 --- a/Netdisco/bin/netdisco-daemon-fg +++ b/Netdisco/bin/netdisco-daemon-fg @@ -12,6 +12,9 @@ BEGIN { unshift @INC, dir($FindBin::RealBin)->parent->subdir('lib')->stringify, dir($FindBin::RealBin, 'lib')->stringify; + + unshift @INC, + split m/:/, ($ENV{NETDISCO_INC} || ''); } use App::Netdisco; diff --git a/Netdisco/bin/netdisco-web-fg b/Netdisco/bin/netdisco-web-fg index c84129f7..14c6d656 100755 --- a/Netdisco/bin/netdisco-web-fg +++ b/Netdisco/bin/netdisco-web-fg @@ -18,6 +18,9 @@ BEGIN { unshift @INC, dir($FindBin::RealBin)->parent->subdir('lib')->stringify, dir($FindBin::RealBin, 'lib')->stringify; + + unshift @INC, + split m/:/, ($ENV{NETDISCO_INC} || ''); } use App::Netdisco; diff --git a/Netdisco/lib/App/Netdisco.pm b/Netdisco/lib/App/Netdisco.pm index f52e472e..305353d3 100644 --- a/Netdisco/lib/App/Netdisco.pm +++ b/Netdisco/lib/App/Netdisco.pm @@ -7,6 +7,9 @@ use 5.010_000; our $VERSION = '2.028013'; use App::Netdisco::Configuration; +use Module::Find (); +Module::Find::usesub 'App::NetdiscoE::Init'; + =head1 NAME App::Netdisco - An open source web-based network management tool. diff --git a/Netdisco/lib/App/Netdisco/Configuration.pm b/Netdisco/lib/App/Netdisco/Configuration.pm index 91bec56c..762f2d70 100644 --- a/Netdisco/lib/App/Netdisco/Configuration.pm +++ b/Netdisco/lib/App/Netdisco/Configuration.pm @@ -3,6 +3,11 @@ package App::Netdisco::Configuration; use App::Netdisco::Environment; use Dancer ':script'; +BEGIN { + # stuff useful locations into @INC + unshift @INC, @{ (setting('include_paths') || []) }; +} + # set up database schema config from simple config vars if (ref {} eq ref setting('database')) { my $name = (setting('database')->{name} || 'netdisco'); @@ -60,6 +65,14 @@ setting('schedule')->{expire} ||= setting('schedule')->{expiry} if setting('schedule') and exists setting('schedule')->{expiry}; delete config->{'schedule'}->{'expiry'}; +# upgrade reports config from hash to list +if (setting('reports') and ref {} eq ref setting('reports')) { + config->{'reports'} = [ map {{ + tag => $_, + %{ setting('reports')->{$_} } + }} keys %{ setting('reports') } ]; +} + # set max outstanding requests for AnyEvent::DNS $ENV{'PERL_ANYEVENT_MAX_OUTSTANDING_DNS'} = setting('dns')->{max_outstanding} || 50; diff --git a/Netdisco/lib/App/Netdisco/Manual/Configuration.pod b/Netdisco/lib/App/Netdisco/Manual/Configuration.pod index e89a1f5a..e03d1ac9 100644 --- a/Netdisco/lib/App/Netdisco/Manual/Configuration.pod +++ b/Netdisco/lib/App/Netdisco/Manual/Configuration.pod @@ -72,6 +72,14 @@ Value: Format String. Default: C<< '[%P] %U %L %m' >>. Structure of the log messages. See L for details. +=head3 C + +Value: List. Default: Empty List. + +Additional library paths for the application (both web frontend and backend +poller daemons). You can also use a colon-separated list in the +"C" environment variable. + =head2 Web Frontend =head3 C @@ -224,13 +232,13 @@ C setting. =head3 C -Value: Dictionary of Reports Hashes. Default: None. +Value: List of Reports Hashes. Default: None. Use this configuration to add reports to Netdisco without writing any Perl code or HTML templates. For example: reports: - power_inventory: + - tag: power_inventory category: Device label: 'Power Supply Inventory' columns: @@ -242,8 +250,8 @@ code or HTML templates. For example: FROM device d ORDER BY name -Each key of the C configuration is an alias for the report, and -becomes part of the web path. +The C of each item in the C configuration is an alias for the +report, and becomes part of the web path. You can munge the data retrieved from the database by placing a Perl script with the same name as the C key into the C directory of @@ -604,7 +612,7 @@ token-ring-default,fddinet-default,trnet-default. On some devices, per-VLAN macsuck will timeout with specific VLAN numbers. You can put those numbers (or their names) into this list to have them skipped. -=head3 C +=head3 C Value: List of "IP:vlan-number" or "IP:vlan-name". Default: Empty List. diff --git a/Netdisco/lib/App/Netdisco/Manual/ReleaseNotes.pod b/Netdisco/lib/App/Netdisco/Manual/ReleaseNotes.pod index 4d1ead8c..e72330ff 100644 --- a/Netdisco/lib/App/Netdisco/Manual/ReleaseNotes.pod +++ b/Netdisco/lib/App/Netdisco/Manual/ReleaseNotes.pod @@ -36,6 +36,31 @@ but they are backwards compatible. =back +=head1 2.029000 + +=head2 General Notices + +The configuration item C is now a list (used to be a dictionary). +Each item in the list must have a C entry which was previously the +dictionary key. For example, now use: + + reports: + - tag: power_inventory + category: Device + label: 'Power Supply Inventory' + columns: + - {name: 'Name'} + - {ps1_type: 'PS1 Type'} + - {ps1_status: 'PS1 Status'} + query: | + SELECT d.name, d.ps1_type, d.ps1_status + FROM device d + WHERE d.ps1_type IS NOT NULL + ORDER BY name + +Old configuration will be continue to work, but we recommend you reconfigure +anyway. + =head1 2.028000 =head2 Incompatible Changes diff --git a/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod b/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod index 0c487301..40ba2c68 100644 --- a/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod +++ b/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod @@ -345,9 +345,9 @@ template file of your own in your plugin, you need a new path: register_template_path( dist_dir( 'App-Netdisco-Web-Plugin-Search-MyNewFeature' )); -The registered path will be searched before the built-in C -path. We recommend use of the L module to package and ship -templates along with your plugin, as shown. +The "C" subdirectory of the registered path will be searched before the +built-in C path. We recommend use of the L +module to package and ship templates along with your plugin, as shown. Each path added using C is searched I any existing paths in the template config. See the diff --git a/Netdisco/lib/App/Netdisco/Web.pm b/Netdisco/lib/App/Netdisco/Web.pm index e238be06..37747fe1 100644 --- a/Netdisco/lib/App/Netdisco/Web.pm +++ b/Netdisco/lib/App/Netdisco/Web.pm @@ -10,20 +10,13 @@ use Socket6 (); # to ensure dependency is met use HTML::Entities (); # to ensure dependency is met use URI::QueryParam (); # part of URI, to add helper methods use Path::Class 'dir'; +use Module::Find (); use Module::Load (); use App::Netdisco::Util::Web 'interval_to_daterange'; -use App::Netdisco::Web::AuthN; -use App::Netdisco::Web::Static; -use App::Netdisco::Web::Search; -use App::Netdisco::Web::Device; -use App::Netdisco::Web::Report; -use App::Netdisco::Web::AdminTask; -use App::Netdisco::Web::TypeAhead; -use App::Netdisco::Web::PortControl; -use App::Netdisco::Web::Statistics; -use App::Netdisco::Web::Password; -use App::Netdisco::Web::GenericReport; +# FIXME: need to avoid splat so that this can be reordered +Module::Find::usesub 'App::NetdiscoE::Web'; +Module::Find::usesub 'App::Netdisco::Web'; sub _load_web_plugins { my $plugin_list = shift; diff --git a/Netdisco/lib/App/Netdisco/Web/GenericReport.pm b/Netdisco/lib/App/Netdisco/Web/GenericReport.pm index 2f86fa7f..bc31e19d 100644 --- a/Netdisco/lib/App/Netdisco/Web/GenericReport.pm +++ b/Netdisco/lib/App/Netdisco/Web/GenericReport.pm @@ -11,8 +11,8 @@ use Safe; use vars qw/$config @data/; -foreach my $r (keys %{setting('reports')}) { - my $report = setting('reports')->{$r}; +foreach my $report (@{setting('reports')}) { + my $r = $report->{tag}; register_report({ tag => $r, @@ -41,7 +41,7 @@ foreach my $r (keys %{setting('reports')}) { # Data Munging support... my $compartment = Safe->new; - $config = setting('reports')->{$r}; + $config = $report; $compartment->share(qw/$config @data/); $compartment->permit_only(qw/:default sort/); diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index aba89351..ac486977 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -11,6 +11,7 @@ log: 'warning' logger_format: '[%P] %U %L %m' +include_paths: [] # ------------ # WEB FRONTEND @@ -78,7 +79,7 @@ web_plugins: extra_web_plugins: [] jobqueue_refresh: 10 safe_password_store: true -reports: {} +reports: [] table_pagesize: 10 # ------------- @@ -271,6 +272,7 @@ engines: start_tag: '[%' end_tag: '%]' PRE_CHOMP: 1 + INCLUDE_PATH: [] layout: 'main' plugins: Auth::Extensible: