Merge branch 'master' into og-multiple-domain-suffix
This commit is contained in:
@@ -59,13 +59,20 @@ ajax qr{/ajax/control/admin/(?:\w+/)?delete} => require_role setting('defanged_a
|
||||
get '/admin/*' => require_role admin => sub {
|
||||
my ($tag) = splat;
|
||||
|
||||
# trick the ajax into working as if this were a tabbed page
|
||||
params->{tab} = $tag;
|
||||
if (exists setting('_admin_tasks')->{ $tag }) {
|
||||
# trick the ajax into working as if this were a tabbed page
|
||||
params->{tab} = $tag;
|
||||
|
||||
var(nav => 'admin');
|
||||
template 'admintask', {
|
||||
task => setting('_admin_tasks')->{ $tag },
|
||||
};
|
||||
var(nav => 'admin');
|
||||
template 'admintask', {
|
||||
task => setting('_admin_tasks')->{ $tag },
|
||||
};
|
||||
}
|
||||
else {
|
||||
var('notfound' => true);
|
||||
status 'not_found';
|
||||
template 'index';
|
||||
}
|
||||
};
|
||||
|
||||
true;
|
||||
|
||||
@@ -13,6 +13,7 @@ use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Passphrase;
|
||||
use Digest::MD5;
|
||||
use Net::LDAP;
|
||||
use Authen::Radius;
|
||||
use Try::Tiny;
|
||||
|
||||
sub authenticate_user {
|
||||
@@ -103,9 +104,20 @@ sub match_password {
|
||||
my $settings = $self->realm_settings;
|
||||
my $username_column = $settings->{users_username_column} || 'username';
|
||||
|
||||
return $user->ldap
|
||||
? $self->match_with_ldap($password, $user->$username_column)
|
||||
: $self->match_with_local_pass($password, $user);
|
||||
my $pwmatch_result = 0;
|
||||
my $username = $user->$username_column;
|
||||
|
||||
if ($user->ldap) {
|
||||
$pwmatch_result = $self->match_with_ldap($password, $username);
|
||||
}
|
||||
elsif ($user->radius) {
|
||||
$pwmatch_result = $self->match_with_radius($password, $username);
|
||||
}
|
||||
else {
|
||||
$pwmatch_result = $self->match_with_local_pass($password, $user);
|
||||
}
|
||||
|
||||
return $pwmatch_result;
|
||||
}
|
||||
|
||||
sub match_with_local_pass {
|
||||
@@ -215,4 +227,28 @@ sub _ldap_search {
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub match_with_radius {
|
||||
my($self, $pass, $user) = @_;
|
||||
return unless setting('radius') and ref {} eq ref setting('radius');
|
||||
|
||||
my $conf = setting('radius');
|
||||
my $radius = Authen::Radius->new(Host => $conf->{server}, Secret => $conf->{secret});
|
||||
# my $dict_dir = Path::Class::Dir->new( dist_dir('App-Netdisco') )
|
||||
# ->subdir('radius_dictionaries')->stringify;
|
||||
Authen::Radius->load_dictionary(); # put $dict_dir in here once it's useful
|
||||
|
||||
$radius->add_attributes(
|
||||
{ Name => 'User-Name', Value => $user },
|
||||
{ Name => 'User-Password', Value => $pass },
|
||||
{ Name => 'h323-return-code', Value => '0' }, # Cisco AV pair
|
||||
{ Name => 'Digest-Attributes', Value => { Method => 'REGISTER' } }
|
||||
);
|
||||
$radius->send_packet(ACCESS_REQUEST);
|
||||
|
||||
my $type = $radius->recv_packet();
|
||||
my $radius_return = ($type eq ACCESS_ACCEPT) ? 1 : 0;
|
||||
|
||||
return $radius_return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
@@ -36,7 +36,7 @@ ajax '/ajax/control/admin/pseudodevice/add' => require_role admin => sub {
|
||||
ip => param('ip'),
|
||||
dns => param('dns'),
|
||||
vendor => 'netdisco',
|
||||
layers => '00000100',
|
||||
layers => param('layers'),
|
||||
last_discover => \'now()',
|
||||
});
|
||||
return unless $device;
|
||||
@@ -87,6 +87,9 @@ ajax '/ajax/control/admin/pseudodevice/update' => require_role admin => sub {
|
||||
})->delete;
|
||||
}
|
||||
}
|
||||
|
||||
# also set layers
|
||||
$device->update({layers => param('layers')});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ ajax '/ajax/control/admin/users/add' => require_role setting('defanged_admin') =
|
||||
password => _make_password(param('password')),
|
||||
fullname => param('fullname'),
|
||||
ldap => (param('ldap') ? \'true' : \'false'),
|
||||
radius => (param('radius') ? \'true' : \'false'),
|
||||
port_control => (param('port_control') ? \'true' : \'false'),
|
||||
admin => (param('admin') ? \'true' : \'false'),
|
||||
note => param('note'),
|
||||
@@ -71,6 +72,7 @@ ajax '/ajax/control/admin/users/update' => require_role setting('defanged_admin'
|
||||
: ()),
|
||||
fullname => param('fullname'),
|
||||
ldap => (param('ldap') ? \'true' : \'false'),
|
||||
radius => (param('radius') ? \'true' : \'false'),
|
||||
port_control => (param('port_control') ? \'true' : \'false'),
|
||||
admin => (param('admin') ? \'true' : \'false'),
|
||||
note => param('note'),
|
||||
|
||||
@@ -31,7 +31,7 @@ get '/ajax/content/device/ports' => require_login sub {
|
||||
# change wildcard chars to SQL
|
||||
$f =~ s/\*/%/g;
|
||||
$f =~ s/\?/_/g;
|
||||
# set wilcards at param boundaries
|
||||
# set wildcards at param boundaries
|
||||
if ($f !~ m/[%_]/) {
|
||||
$f =~ s/^\%*/%/;
|
||||
$f =~ s/\%*$/%/;
|
||||
@@ -82,6 +82,8 @@ get '/ajax/content/device/ports' => require_login sub {
|
||||
});
|
||||
}
|
||||
delete $port_state{free};
|
||||
# showing free ports requires showing down ports
|
||||
++$port_state{down};
|
||||
}
|
||||
|
||||
if (scalar keys %port_state < 3) {
|
||||
|
||||
@@ -47,7 +47,7 @@ get '/ajax/content/report/nodevendor/data' => require_login sub {
|
||||
my $match = $vendor eq 'blank' ? undef : $vendor;
|
||||
|
||||
$rs = $rs->search( { 'oui.abbrev' => $match },
|
||||
{ '+columns' => [qw/ device.dns device.name oui.abbrev /],
|
||||
{ '+columns' => [qw/ device.dns device.name oui.abbrev oui.company /],
|
||||
join => [qw/ oui device /],
|
||||
collapse => 1,
|
||||
});
|
||||
@@ -86,7 +86,7 @@ get '/ajax/content/report/nodevendor' => require_login sub {
|
||||
my $match = $vendor eq 'blank' ? undef : $vendor;
|
||||
|
||||
$rs = $rs->search( { 'oui.abbrev' => $match },
|
||||
{ '+columns' => [qw/ device.dns device.name oui.abbrev /],
|
||||
{ '+columns' => [qw/ device.dns device.name oui.abbrev oui.company /],
|
||||
join => [qw/ oui device /],
|
||||
collapse => 1,
|
||||
});
|
||||
@@ -102,9 +102,9 @@ get '/ajax/content/report/nodevendor' => require_login sub {
|
||||
$rs = $rs->search(
|
||||
{ },
|
||||
{ join => 'oui',
|
||||
select => [ 'oui.abbrev', { count => {distinct => 'me.mac'}} ],
|
||||
as => [qw/ vendor count /],
|
||||
group_by => [qw/ oui.abbrev /]
|
||||
select => [ 'oui.abbrev', 'oui.company', { count => {distinct => 'me.mac'}} ],
|
||||
as => [qw/ abbrev vendor count /],
|
||||
group_by => [qw/ oui.abbrev oui.company /]
|
||||
}
|
||||
)->order_by( { -desc => 'count' } );
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ get '/ajax/content/report/portutilization' => require_login sub {
|
||||
my $age_num = param('age_num') || 3;
|
||||
my $age_unit = param('age_unit') || 'months';
|
||||
my @results = schema('netdisco')->resultset('Virtual::PortUtilization')
|
||||
->search(undef, { bind => [ "$age_num $age_unit" ] })->hri->all;
|
||||
->search(undef, { bind => [ "$age_num $age_unit", "$age_num $age_unit", "$age_num $age_unit" ] })->hri->all;
|
||||
|
||||
if (request->is_ajax) {
|
||||
my $json = to_json (\@results);
|
||||
|
||||
@@ -6,6 +6,7 @@ use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
|
||||
use NetAddr::IP::Lite ':lower';
|
||||
use Regexp::Common 'net';
|
||||
use NetAddr::MAC ();
|
||||
|
||||
use App::Netdisco::Web::Plugin;
|
||||
@@ -23,10 +24,14 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
my ( $start, $end ) = param('daterange') =~ m/(\d+-\d+-\d+)/gmx;
|
||||
|
||||
my $mac = NetAddr::MAC->new(mac => $node);
|
||||
undef $mac if ($mac and $mac->as_ieee and ($mac->as_ieee eq '00:00:00:00'));
|
||||
my @active = (param('archived') ? () : (-bool => 'active'));
|
||||
undef $mac if
|
||||
($mac and $mac->as_ieee
|
||||
and (($mac->as_ieee eq '00:00:00:00:00:00')
|
||||
or ($mac->as_ieee !~ m/$RE{net}{MAC}/)));
|
||||
|
||||
my @active = (param('archived') ? () : (-bool => 'active'));
|
||||
my (@times, @wifitimes, @porttimes);
|
||||
|
||||
if ( $start and $end ) {
|
||||
$start = $start . ' 00:00:00';
|
||||
$end = $end . ' 23:59:59';
|
||||
|
||||
@@ -6,6 +6,7 @@ use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
|
||||
use App::Netdisco::Util::Web 'sql_match';
|
||||
use Regexp::Common 'net';
|
||||
use NetAddr::MAC ();
|
||||
|
||||
hook 'before_template' => sub {
|
||||
@@ -39,7 +40,11 @@ get '/search' => require_login sub {
|
||||
my $nd = $s->resultset('Device')->search_fuzzy($q);
|
||||
my ($likeval, $likeclause) = sql_match($q);
|
||||
my $mac = NetAddr::MAC->new($q);
|
||||
undef $mac if ($mac and $mac->as_ieee and ($mac->as_ieee eq '00:00:00:00'));
|
||||
|
||||
undef $mac if
|
||||
($mac and $mac->as_ieee
|
||||
and (($mac->as_ieee eq '00:00:00:00:00:00')
|
||||
or ($mac->as_ieee !~ m/$RE{net}{MAC}/)));
|
||||
|
||||
if ($nd and $nd->count) {
|
||||
if ($nd->count == 1) {
|
||||
|
||||
Reference in New Issue
Block a user