* Support for stuffing other locations into @INC at runtime * Reports config is now a list (see ReleaseNotes) commit19756faf57Merge:2e8afbe29d3ac7Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Jul 31 21:32:30 2014 +0100 Merge branch 'master' into og-autoload Conflicts: Netdisco/share/public/javascripts/netdisco_portcontrol.js commit2e8afbeea6Merge:d340c3b18f507eAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed Jul 23 20:09:18 2014 +0100 Merge branch 'master' into og-autoload commitd340c3b135Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Jul 7 22:25:38 2014 +0100 tweak dirty css commit032cd82c46Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jul 6 23:05:17 2014 +0100 add dirty classes commit2b72c989faMerge:1b8ac7cb77025fAuthor: Oliver Gorwits <oliver@cpan.org> 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 commitb77025f34cAuthor: Oliver Gorwits <oliver@cpan.org> Date: Thu Jul 3 23:35:35 2014 +0100 hide save icon commit5df5a73aedAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed Jul 2 22:31:18 2014 +0100 blue color commita3bf20f074Merge:1839f26db53c00Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Jul 2 15:17:25 2014 +0100 Merge branch 'master' into og-autoload commit1b8ac7ca1fMerge:1839f26db53c00Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Jul 2 09:23:31 2014 +0100 Merge branch 'master' into og-autoload commit1839f2634bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed Jul 2 03:43:53 2014 +0100 add jquery.fix.clone.js commit3eee9f1997Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Jul 2 00:08:27 2014 +0100 save button css commit95b6cb61b3Merge:13957e858e5d05Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Jul 1 21:50:01 2014 +0100 Merge branch 'master' into og-autoload Conflicts: Netdisco/share/config.yml commit13957e82dcMerge:bedbec66abcebaAuthor: Oliver Gorwits <oliver@cpan.org> 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 commitbedbec6b4bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Mon Jun 30 22:49:49 2014 +0100 css fixes commit6e2d5a4b48Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Jun 30 21:30:26 2014 +0100 css fixes commit755fc92c59Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Jun 30 13:05:43 2014 +0100 reports now a list not a hash commit6abcebafbeAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 29 12:41:47 2014 +0100 start as non-root if port switch not required commite5e0c0c8d1Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Jun 28 13:10:51 2014 +0100 fix err in docs commit6d680aabedAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Jun 28 11:10:23 2014 +0100 move content commitd2668d6db7Author: Oliver Gorwits <oliver@cpan.org> Date: Fri Jun 27 00:30:54 2014 +0100 minor styling commite46cbd252dAuthor: Oliver Gorwits <oliver@cpan.org> Date: Thu Jun 26 23:19:19 2014 +0100 add bootstrap-switch checkbox styling commit5b0a723c9fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed Jun 25 22:20:57 2014 +0100 typo in defaults commite45fa89c44Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Jun 24 22:42:45 2014 +0100 css for configuration pane commit62c53a5e49Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Jun 23 23:33:26 2014 +0100 minor typo commitcaedbdadc6Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Jun 23 20:35:30 2014 +0100 properly search the template path!! [#103] commit5742bc7856Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 22 23:13:53 2014 +0100 fix registering template paths commit2b09476f29Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 22 22:19:35 2014 +0100 allow INC stuffing via NETDISCO_INC env var commit7c47a277beMerge:128e96f3a1cd19Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 22 22:17:11 2014 +0100 Merge branch 'master' into og-autoload commit128e96f9a3Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 22 20:48:01 2014 +0100 use Module::Find to load Auto things and Web
114 lines
3.2 KiB
Perl
114 lines
3.2 KiB
Perl
package App::Netdisco::Web;
|
|
|
|
use Dancer ':syntax';
|
|
use Dancer::Plugin::Ajax;
|
|
|
|
use Dancer::Plugin::DBIC;
|
|
use Dancer::Plugin::Auth::Extensible;
|
|
|
|
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';
|
|
|
|
# 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;
|
|
|
|
foreach my $plugin (@$plugin_list) {
|
|
$plugin =~ s/^X::/+App::NetdiscoX::Web::Plugin::/;
|
|
$plugin = 'App::Netdisco::Web::Plugin::'. $plugin
|
|
if $plugin !~ m/^\+/;
|
|
$plugin =~ s/^\+//;
|
|
|
|
debug "loading Netdisco plugin $plugin";
|
|
Module::Load::load $plugin;
|
|
}
|
|
}
|
|
|
|
if (setting('web_plugins') and ref [] eq ref setting('web_plugins')) {
|
|
_load_web_plugins( setting('web_plugins') );
|
|
}
|
|
|
|
if (setting('extra_web_plugins') and ref [] eq ref setting('extra_web_plugins')) {
|
|
unshift @INC, dir(($ENV{NETDISCO_HOME} || $ENV{HOME}), 'site_plugins')->stringify;
|
|
_load_web_plugins( setting('extra_web_plugins') );
|
|
}
|
|
|
|
# after plugins are loaded, add our own template path
|
|
push @{ config->{engines}->{netdisco_template_toolkit}->{INCLUDE_PATH} },
|
|
setting('views');
|
|
|
|
# workaround for https://github.com/PerlDancer/Dancer/issues/935
|
|
hook after_error_render => sub { setting('layout' => 'main') };
|
|
|
|
# this hook should be loaded _after_ all plugins
|
|
hook 'before_template' => sub {
|
|
my $tokens = shift;
|
|
|
|
# allow portable static content
|
|
$tokens->{uri_base} = request->base->path
|
|
if request->base->path ne '/';
|
|
|
|
# allow portable dynamic content
|
|
$tokens->{uri_for} = sub { uri_for(@_)->path_query };
|
|
|
|
# access to logged in user's roles
|
|
$tokens->{user_has_role} = sub { user_has_role(@_) };
|
|
|
|
# create date ranges from within templates
|
|
$tokens->{to_daterange} = sub { interval_to_daterange(@_) };
|
|
|
|
# fix Plugin Template Variables to be only path+query
|
|
$tokens->{$_} = $tokens->{$_}->path_query
|
|
for qw/search_node search_device device_ports/;
|
|
|
|
# allow very long lists of ports
|
|
$Template::Directive::WHILE_MAX = 10_000;
|
|
|
|
# allow hash keys with leading underscores
|
|
$Template::Stash::PRIVATE = undef;
|
|
};
|
|
|
|
# remove empty lines from CSV response
|
|
# this makes writing templates much more straightforward!
|
|
hook 'after' => sub {
|
|
my $r = shift; # a Dancer::Response
|
|
|
|
if ($r->content_type and $r->content_type eq 'text/comma-separated-values') {
|
|
my @newlines = ();
|
|
my @lines = split m/\n/, $r->content;
|
|
|
|
foreach my $line (@lines) {
|
|
push @newlines, $line if $line !~ m/^\s*$/;
|
|
}
|
|
|
|
$r->content(join "\n", @newlines);
|
|
}
|
|
};
|
|
|
|
any qr{.*} => sub {
|
|
var('notfound' => true);
|
|
status 'not_found';
|
|
template 'index';
|
|
};
|
|
|
|
{
|
|
# https://github.com/PerlDancer/Dancer/issues/967
|
|
no warnings 'redefine';
|
|
*Dancer::_redirect = sub {
|
|
my ($destination, $status) = @_;
|
|
my $response = Dancer::SharedData->response;
|
|
$response->status($status || 302);
|
|
$response->headers('Location' => $destination);
|
|
};
|
|
}
|
|
|
|
true;
|