Files
netdisco/Netdisco/lib/App/Netdisco/Web.pm
Oliver Gorwits 9685eb182a Merge pluggable job queue branch.
Squashed commit of the following:

commit e2ca15c0f8
Merge: 0a90308 ffcf6ed
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed May 21 21:18:58 2014 +0100

    Merge branch 'master' into og-pluggable-daemon

commit 0a90308ecf
Merge: e80c575 ee398fc
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 22:20:40 2014 +0100

    Merge branch 'master' into og-pluggable-daemon

    Conflicts:
    	Netdisco/lib/App/Netdisco.pm

commit e80c575c57
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 22:14:44 2014 +0100

    move worker sleep into jobqueue

commit c83b999597
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 22:01:43 2014 +0100

    support disable manager from jobqueue dynamic code

commit 4792b0dc49
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 21:34:28 2014 +0100

    fix pod name

commit 187fc84937
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 21:22:06 2014 +0100

    better naming

commit 1c43aaa0f4
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 21:18:49 2014 +0100

    make worker use only JobQueue not LocalQueue directly

commit 5316058ba8
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 20:42:19 2014 +0100

    remove unecessary scrub subroutine

commit 8077e3de9d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 20:31:18 2014 +0100

    remove any duplicate jobs when locking

commit d4b5e4e6cd
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 20:20:32 2014 +0100

    rename DefaultSettings to Configuration

commit aacb149d09
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 19:57:45 2014 +0100

    no need to check - mgr is not started if 0 workers

commit 46ebe4cd6a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 19:50:37 2014 +0100

    remove unecessary job scrub

commit 60522fe555
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 19:27:53 2014 +0100

    fixes for DefaultSettings

commit 2c6f0dd0f7
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 19:11:50 2014 +0100

    rename housekeeping to schedule

commit c12034d2b0
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 19:06:22 2014 +0100

    new DefaultSettings package, and mv queue to be key of workers

commit 49e9079f9a
Merge: ec8ad3b 213f44e
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 17 08:00:02 2014 +0100

    Merge branch 'master' into og-pluggable-daemon

commit ec8ad3b2d8
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun May 11 01:18:21 2014 +0100

    fix entered_stamp

commit 471724dd89
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 10 23:44:14 2014 +0100

    fix auto hack

commit 4620deff33
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 10 23:27:11 2014 +0100

    final migration

commit 5413e34e83
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 10 23:18:12 2014 +0100

    more JobQueue migration

commit 9569bda4d8
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 10 22:44:20 2014 +0100

    migrate to JobQueue :)

commit 41ee8f91f2
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 10 22:38:20 2014 +0100

    simplify again

commit 58cba4da24
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 10 22:06:41 2014 +0100

    add POD for JobQueue

commit c9afbab26b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 10 21:36:01 2014 +0100

    use Module::Load tricks to avoid some other mess

commit 50c72c1d64
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat May 10 21:12:52 2014 +0100

    use Module::Load for dynamic loading

commit 54510a1560
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu May 8 22:05:10 2014 +0100

    hack to make functional and OO interface

commit b8c706a2e7
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu May 8 21:29:31 2014 +0100

    simplify role apply for jobqueue

commit 8a816b9764
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue May 6 22:20:50 2014 +0100

    remove debug print

commit f3131adfc8
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue May 6 21:47:30 2014 +0100

    big patch to remove knowledge of DB from most worker code

commit 39a0efb3c3
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Apr 28 23:46:10 2014 +0100

    port Worker Common to pluggable jobqueue

commit 8c0614357a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Apr 28 23:04:13 2014 +0100

    port Scheduler to pluggable jobqueue

commit 3882c157ec
Merge: 44e6c49 2480646
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Apr 28 22:36:57 2014 +0100

    Merge branch 'master' into og-pluggable-daemon

commit 44e6c49419
Merge: fdeeffc 5fc6209
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Apr 28 22:35:53 2014 +0100

    Merge branch 'master' into og-pluggable-daemon

commit 5fc62090e2
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Apr 28 22:15:07 2014 +0100

    edge topology
      17   * Use

commit fdeeffcbe4
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 24 23:13:20 2014 +0100

    book specifically same jobs which were seen

commit 0d97c2b819
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 24 22:57:37 2014 +0100

    fix typos

commit 47265a5292
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 24 21:56:52 2014 +0100

    rename file to follow name change

commit fd169149c4
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 24 21:52:57 2014 +0100

    remove job types from web code

commit 319489ae00
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 24 21:46:30 2014 +0100

    remove job types from scheduler

commit ccdeca600c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 24 21:33:01 2014 +0100

    remove job types from netdisco-daemon-fg

commit 349bddf609
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 24 21:05:42 2014 +0100

    move default env settings to Netdisco.pm

commit b4b5cce00a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 24 21:01:26 2014 +0100

    remove job type knowledge from code into config
2014-05-21 21:20:27 +01:00

117 lines
3.3 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::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;
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') );
}
# 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;