Files
netdisco/Netdisco/lib/App/Netdisco/Web.pm
Oliver Gorwits 04d89320a8 Squashed commit of the following:
* Support for stuffing other locations into @INC at runtime
* Reports config is now a list (see ReleaseNotes)

commit 19756faf57
Merge: 2e8afbe 29d3ac7
Author: 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

commit 2e8afbeea6
Merge: d340c3b 18f507e
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 23 20:09:18 2014 +0100

    Merge branch 'master' into og-autoload

commit d340c3b135
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jul 7 22:25:38 2014 +0100

    tweak dirty css

commit 032cd82c46
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jul 6 23:05:17 2014 +0100

    add dirty classes

commit 2b72c989fa
Merge: 1b8ac7c b77025f
Author: 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

commit b77025f34c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jul 3 23:35:35 2014 +0100

    hide save icon

commit 5df5a73aed
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 2 22:31:18 2014 +0100

    blue color

commit a3bf20f074
Merge: 1839f26 db53c00
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 2 15:17:25 2014 +0100

    Merge branch 'master' into og-autoload

commit 1b8ac7ca1f
Merge: 1839f26 db53c00
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 2 09:23:31 2014 +0100

    Merge branch 'master' into og-autoload

commit 1839f2634b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 2 03:43:53 2014 +0100

    add jquery.fix.clone.js

commit 3eee9f1997
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 2 00:08:27 2014 +0100

    save button css

commit 95b6cb61b3
Merge: 13957e8 58e5d05
Author: 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

commit 13957e82dc
Merge: bedbec6 6abceba
Author: 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

commit bedbec6b4b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jun 30 22:49:49 2014 +0100

    css fixes

commit 6e2d5a4b48
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jun 30 21:30:26 2014 +0100

    css fixes

commit 755fc92c59
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jun 30 13:05:43 2014 +0100

    reports now a list not a hash

commit 6abcebafbe
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 29 12:41:47 2014 +0100

    start as non-root if port switch not required

commit e5e0c0c8d1
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jun 28 13:10:51 2014 +0100

    fix err in docs

commit 6d680aabed
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jun 28 11:10:23 2014 +0100

    move content

commit d2668d6db7
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Jun 27 00:30:54 2014 +0100

    minor styling

commit e46cbd252d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jun 26 23:19:19 2014 +0100

    add bootstrap-switch checkbox styling

commit 5b0a723c9f
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jun 25 22:20:57 2014 +0100

    typo in defaults

commit e45fa89c44
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Jun 24 22:42:45 2014 +0100

    css for configuration pane

commit 62c53a5e49
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jun 23 23:33:26 2014 +0100

    minor typo

commit caedbdadc6
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jun 23 20:35:30 2014 +0100

    properly search the template path!! [#103]

commit 5742bc7856
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 22 23:13:53 2014 +0100

    fix registering template paths

commit 2b09476f29
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 22 22:19:35 2014 +0100

    allow INC stuffing via NETDISCO_INC env var

commit 7c47a277be
Merge: 128e96f 3a1cd19
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 22 22:17:11 2014 +0100

    Merge branch 'master' into og-autoload

commit 128e96f9a3
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 22 20:48:01 2014 +0100

    use Module::Find to load Auto things and Web
2014-07-31 22:54:28 +01:00

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;