remove Try::Tiny from web runtime
This commit is contained in:
@@ -6,7 +6,6 @@ use Dancer::Plugin::DBIC;
|
|||||||
|
|
||||||
use App::Netdisco::Web::Plugin;
|
use App::Netdisco::Web::Plugin;
|
||||||
use NetAddr::IP::Lite ':lower';
|
use NetAddr::IP::Lite ':lower';
|
||||||
use Try::Tiny;
|
|
||||||
|
|
||||||
register_admin_task({
|
register_admin_task({
|
||||||
tag => 'pseudodevice',
|
tag => 'pseudodevice',
|
||||||
@@ -14,9 +13,6 @@ register_admin_task({
|
|||||||
});
|
});
|
||||||
|
|
||||||
sub _sanity_ok {
|
sub _sanity_ok {
|
||||||
my $happy = 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
return 0 unless var('user')->admin;
|
return 0 unless var('user')->admin;
|
||||||
|
|
||||||
return 0 unless length param('dns')
|
return 0 unless length param('dns')
|
||||||
@@ -24,22 +20,18 @@ sub _sanity_ok {
|
|||||||
and param('dns') !~ m/[[:space:]]/;
|
and param('dns') !~ m/[[:space:]]/;
|
||||||
|
|
||||||
my $ip = NetAddr::IP::Lite->new(param('ip'));
|
my $ip = NetAddr::IP::Lite->new(param('ip'));
|
||||||
return 0 if $ip->addr eq '0.0.0.0';
|
return 0 unless ($ip and$ip->addr ne '0.0.0.0');
|
||||||
|
|
||||||
return 0 unless length param('ports')
|
return 0 unless length param('ports')
|
||||||
and param('ports') =~ m/^[[:digit:]]+$/;
|
and param('ports') =~ m/^[[:digit:]]+$/;
|
||||||
|
|
||||||
$happy = 1;
|
return 1;
|
||||||
};
|
|
||||||
|
|
||||||
return $happy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ajax '/ajax/content/admin/pseudodevice/add' => sub {
|
ajax '/ajax/content/admin/pseudodevice/add' => sub {
|
||||||
forward '/ajax/content/admin/pseudodevice'
|
forward '/ajax/content/admin/pseudodevice'
|
||||||
unless _sanity_ok();
|
unless _sanity_ok();
|
||||||
|
|
||||||
try {
|
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
my $device = schema('netdisco')->resultset('Device')
|
my $device = schema('netdisco')->resultset('Device')
|
||||||
->create({
|
->create({
|
||||||
@@ -48,13 +40,13 @@ ajax '/ajax/content/admin/pseudodevice/add' => sub {
|
|||||||
vendor => 'netdisco',
|
vendor => 'netdisco',
|
||||||
last_discover => \'now()',
|
last_discover => \'now()',
|
||||||
});
|
});
|
||||||
|
return unless $device;
|
||||||
|
|
||||||
$device->ports->populate([
|
$device->ports->populate([
|
||||||
['port'],
|
['port'],
|
||||||
map {["Port$_"]} @{[1 .. param('ports')]},
|
map {["Port$_"]} @{[1 .. param('ports')]},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
forward '/ajax/content/admin/pseudodevice';
|
forward '/ajax/content/admin/pseudodevice';
|
||||||
};
|
};
|
||||||
@@ -63,7 +55,6 @@ ajax '/ajax/content/admin/pseudodevice/del' => sub {
|
|||||||
forward '/ajax/content/admin/pseudodevice'
|
forward '/ajax/content/admin/pseudodevice'
|
||||||
unless _sanity_ok();
|
unless _sanity_ok();
|
||||||
|
|
||||||
try {
|
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
my $device = schema('netdisco')->resultset('Device')
|
my $device = schema('netdisco')->resultset('Device')
|
||||||
->find({ip => param('ip')});
|
->find({ip => param('ip')});
|
||||||
@@ -71,7 +62,6 @@ ajax '/ajax/content/admin/pseudodevice/del' => sub {
|
|||||||
$device->ports->delete;
|
$device->ports->delete;
|
||||||
$device->delete;
|
$device->delete;
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
forward '/ajax/content/admin/pseudodevice';
|
forward '/ajax/content/admin/pseudodevice';
|
||||||
};
|
};
|
||||||
@@ -80,35 +70,26 @@ ajax '/ajax/content/admin/pseudodevice/update' => sub {
|
|||||||
forward '/ajax/content/admin/pseudodevice'
|
forward '/ajax/content/admin/pseudodevice'
|
||||||
unless _sanity_ok();
|
unless _sanity_ok();
|
||||||
|
|
||||||
try {
|
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
my $device = schema('netdisco')->resultset('Device')
|
my $device = schema('netdisco')->resultset('Device')
|
||||||
->with_port_count->find({ip => param('ip')});
|
->with_port_count->find({ip => param('ip')});
|
||||||
|
return unless $device;
|
||||||
my $count = $device->port_count;
|
my $count = $device->port_count;
|
||||||
|
|
||||||
if (param('ports') > $count) {
|
if (param('ports') > $count) {
|
||||||
my $start = $count + 1;
|
my $start = $count + 1;
|
||||||
try {
|
|
||||||
schema('netdisco')->txn_do(sub {
|
|
||||||
$device->ports->populate([
|
$device->ports->populate([
|
||||||
['port'],
|
['port'],
|
||||||
map {["Port$_"]} @{[$start .. param('ports')]},
|
map {["Port$_"]} @{[$start .. param('ports')]},
|
||||||
]);
|
]);
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
elsif (param('ports') < $count) {
|
elsif (param('ports') < $count) {
|
||||||
my $start = param('ports') + 1;
|
my $start = param('ports') + 1;
|
||||||
try {
|
|
||||||
schema('netdisco')->txn_do(sub {
|
|
||||||
$device->ports
|
$device->ports
|
||||||
->single({port => "Port$_"})->delete
|
->single({port => "Port$_"})->delete
|
||||||
for ($start .. $count);
|
for ($start .. $count);
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
forward '/ajax/content/admin/pseudodevice';
|
forward '/ajax/content/admin/pseudodevice';
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use Dancer::Plugin::DBIC;
|
|||||||
|
|
||||||
use App::Netdisco::Web::Plugin;
|
use App::Netdisco::Web::Plugin;
|
||||||
use NetAddr::IP::Lite ':lower';
|
use NetAddr::IP::Lite ':lower';
|
||||||
use Try::Tiny;
|
|
||||||
|
|
||||||
register_admin_task({
|
register_admin_task({
|
||||||
tag => 'topology',
|
tag => 'topology',
|
||||||
@@ -14,31 +13,24 @@ register_admin_task({
|
|||||||
});
|
});
|
||||||
|
|
||||||
sub _sanity_ok {
|
sub _sanity_ok {
|
||||||
my $happy = 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
return 0 unless var('user')->admin;
|
return 0 unless var('user')->admin;
|
||||||
|
|
||||||
my $dev1 = NetAddr::IP::Lite->new(param('dev1'));
|
my $dev1 = NetAddr::IP::Lite->new(param('dev1'));
|
||||||
return 0 if $dev1->addr eq '0.0.0.0';
|
return 0 unless ($dev1 and $dev1->addr ne '0.0.0.0');
|
||||||
|
|
||||||
my $dev2 = NetAddr::IP::Lite->new(param('dev2'));
|
my $dev2 = NetAddr::IP::Lite->new(param('dev2'));
|
||||||
return 0 if $dev2->addr eq '0.0.0.0';
|
return 0 unless ($dev2 and $dev2->addr ne '0.0.0.0');
|
||||||
|
|
||||||
return 0 unless length param('port1');
|
return 0 unless length param('port1');
|
||||||
return 0 unless length param('port2');
|
return 0 unless length param('port2');
|
||||||
|
|
||||||
$happy = 1;
|
return 1;
|
||||||
};
|
|
||||||
|
|
||||||
return $happy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ajax '/ajax/content/admin/topology/add' => sub {
|
ajax '/ajax/content/admin/topology/add' => sub {
|
||||||
forward '/ajax/content/admin/topology'
|
forward '/ajax/content/admin/topology'
|
||||||
unless _sanity_ok();
|
unless _sanity_ok();
|
||||||
|
|
||||||
try {
|
|
||||||
my $device = schema('netdisco')->resultset('Topology')
|
my $device = schema('netdisco')->resultset('Topology')
|
||||||
->create({
|
->create({
|
||||||
dev1 => param('dev1'),
|
dev1 => param('dev1'),
|
||||||
@@ -46,7 +38,6 @@ ajax '/ajax/content/admin/topology/add' => sub {
|
|||||||
dev2 => param('dev2'),
|
dev2 => param('dev2'),
|
||||||
port2 => param('port2'),
|
port2 => param('port2'),
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
forward '/ajax/content/admin/topology';
|
forward '/ajax/content/admin/topology';
|
||||||
};
|
};
|
||||||
@@ -55,7 +46,6 @@ ajax '/ajax/content/admin/topology/del' => sub {
|
|||||||
forward '/ajax/content/admin/topology'
|
forward '/ajax/content/admin/topology'
|
||||||
unless _sanity_ok();
|
unless _sanity_ok();
|
||||||
|
|
||||||
try {
|
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
my $device = schema('netdisco')->resultset('Topology')
|
my $device = schema('netdisco')->resultset('Topology')
|
||||||
->search({
|
->search({
|
||||||
@@ -65,7 +55,6 @@ ajax '/ajax/content/admin/topology/del' => sub {
|
|||||||
port2 => param('port2'),
|
port2 => param('port2'),
|
||||||
})->delete;
|
})->delete;
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
forward '/ajax/content/admin/topology';
|
forward '/ajax/content/admin/topology';
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ use Dancer ':syntax';
|
|||||||
use Dancer::Plugin::Ajax;
|
use Dancer::Plugin::Ajax;
|
||||||
use Dancer::Plugin::DBIC;
|
use Dancer::Plugin::DBIC;
|
||||||
|
|
||||||
use Try::Tiny;
|
|
||||||
|
|
||||||
ajax '/ajax/portcontrol' => sub {
|
ajax '/ajax/portcontrol' => sub {
|
||||||
return unless var('user')->port_control;
|
return unless var('user')->port_control;
|
||||||
|
return unless param('device') and param('port') and param('field');
|
||||||
|
|
||||||
try {
|
|
||||||
my $log = sprintf 'd:[%s] p:[%s] f:[%s]. a:[%s] v[%s]',
|
my $log = sprintf 'd:[%s] p:[%s] f:[%s]. a:[%s] v[%s]',
|
||||||
param('device'), (param('port') || ''), param('field'),
|
param('device'), (param('port') || ''), param('field'),
|
||||||
(param('action') || ''), (param('value') || '');
|
(param('action') || ''), (param('value') || '');
|
||||||
@@ -23,6 +21,8 @@ ajax '/ajax/portcontrol' => sub {
|
|||||||
'c_power' => 'power',
|
'c_power' => 'power',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return unless (param('action') or param('value'));
|
||||||
|
|
||||||
my $action = $action_map{ param('field') };
|
my $action = $action_map{ param('field') };
|
||||||
my $subaction = ($action =~ m/^(?:power|portcontrol)/
|
my $subaction = ($action =~ m/^(?:power|portcontrol)/
|
||||||
? (param('action') ."-other")
|
? (param('action') ."-other")
|
||||||
@@ -38,10 +38,6 @@ ajax '/ajax/portcontrol' => sub {
|
|||||||
userip => request->remote_address,
|
userip => request->remote_address,
|
||||||
log => $log,
|
log => $log,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
catch {
|
|
||||||
send_error('Failed to parse params or add DB record');
|
|
||||||
};
|
|
||||||
|
|
||||||
content_type('application/json');
|
content_type('application/json');
|
||||||
to_json({});
|
to_json({});
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use Dancer::Plugin::Ajax;
|
|||||||
use Dancer::Plugin::DBIC;
|
use Dancer::Plugin::DBIC;
|
||||||
|
|
||||||
use App::Netdisco::Util::Web (); # for sort_port
|
use App::Netdisco::Util::Web (); # for sort_port
|
||||||
use Try::Tiny;
|
|
||||||
|
|
||||||
ajax '/ajax/data/devicename/typeahead' => sub {
|
ajax '/ajax/data/devicename/typeahead' => sub {
|
||||||
my $q = param('query') || param('term');
|
my $q = param('query') || param('term');
|
||||||
@@ -38,14 +37,13 @@ ajax '/ajax/data/port/typeahead' => sub {
|
|||||||
my $port = param('port1') || param('port2');
|
my $port = param('port1') || param('port2');
|
||||||
return unless length $dev;
|
return unless length $dev;
|
||||||
|
|
||||||
my $set = undef;
|
my $device = schema('netdisco')->resultset('Device')
|
||||||
try {
|
->find({ip => $dev});
|
||||||
$set = schema('netdisco')->resultset('Device')
|
return unless $device;
|
||||||
->find({ip => $dev})->ports({},{order_by => 'port'});
|
|
||||||
|
my $set = $device->ports({},{order_by => 'port'});
|
||||||
$set = $set->search({port => { -ilike => "\%$port\%" }})
|
$set = $set->search({port => { -ilike => "\%$port\%" }})
|
||||||
if length $port;
|
if length $port;
|
||||||
};
|
|
||||||
return unless defined $set;
|
|
||||||
|
|
||||||
my $results = [ sort { &App::Netdisco::Util::Web::sort_port($a->port, $b->port) } $set->all ];
|
my $results = [ sort { &App::Netdisco::Util::Web::sort_port($a->port, $b->port) } $set->all ];
|
||||||
return unless scalar @$results;
|
return unless scalar @$results;
|
||||||
|
|||||||
Reference in New Issue
Block a user