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: