complete the topology editor (add/delete)
This commit is contained in:
@@ -5,6 +5,7 @@ use Dancer::Plugin::Ajax;
|
|||||||
use Dancer::Plugin::DBIC;
|
use Dancer::Plugin::DBIC;
|
||||||
|
|
||||||
use App::Netdisco::Web::Plugin;
|
use App::Netdisco::Web::Plugin;
|
||||||
|
use NetAddr::IP::Lite ':lower';
|
||||||
use Try::Tiny;
|
use Try::Tiny;
|
||||||
|
|
||||||
register_admin_task({
|
register_admin_task({
|
||||||
@@ -18,15 +19,14 @@ sub _sanity_ok {
|
|||||||
try {
|
try {
|
||||||
return 0 unless var('user')->admin;
|
return 0 unless var('user')->admin;
|
||||||
|
|
||||||
return 0 unless length param('dns')
|
my $dev1 = NetAddr::IP::Lite->new(param('dev1'));
|
||||||
and param('dns') =~ m/^[[:print:]]+$/
|
return 0 if $dev1->addr eq '0.0.0.0';
|
||||||
and param('dns') !~ m/[[:space:]]/;
|
|
||||||
|
|
||||||
my $ip = NetAddr::IP::Lite->new(param('ip'));
|
my $dev2 = NetAddr::IP::Lite->new(param('dev2'));
|
||||||
return 0 if $ip->addr eq '0.0.0.0';
|
return 0 if $dev2->addr eq '0.0.0.0';
|
||||||
|
|
||||||
return 0 unless length param('ports')
|
return 0 unless length param('port1');
|
||||||
and param('ports') =~ m/^[[:digit:]]+$/;
|
return 0 unless length param('port2');
|
||||||
|
|
||||||
$happy = 1;
|
$happy = 1;
|
||||||
};
|
};
|
||||||
@@ -39,19 +39,12 @@ ajax '/ajax/content/admin/topology/add' => sub {
|
|||||||
unless _sanity_ok();
|
unless _sanity_ok();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
schema('netdisco')->txn_do(sub {
|
my $device = schema('netdisco')->resultset('Topology')
|
||||||
my $device = schema('netdisco')->resultset('Device')
|
|
||||||
->create({
|
->create({
|
||||||
ip => param('ip'),
|
dev1 => param('dev1'),
|
||||||
dns => param('dns'),
|
port1 => param('port1'),
|
||||||
vendor => 'netdisco',
|
dev2 => param('dev2'),
|
||||||
last_discover => \'now()',
|
port2 => param('port2'),
|
||||||
});
|
|
||||||
|
|
||||||
$device->ports->populate([
|
|
||||||
['port'],
|
|
||||||
map {["Port$_"]} @{[1 .. param('ports')]},
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -64,11 +57,13 @@ ajax '/ajax/content/admin/topology/del' => sub {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
my $device = schema('netdisco')->resultset('Device')
|
my $device = schema('netdisco')->resultset('Topology')
|
||||||
->find({ip => param('ip')});
|
->search({
|
||||||
|
dev1 => param('dev1'),
|
||||||
$device->ports->delete;
|
port1 => param('port1'),
|
||||||
$device->delete;
|
dev2 => param('dev2'),
|
||||||
|
port2 => param('port2'),
|
||||||
|
})->delete;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
[% WHILE (row = results.next) %]
|
[% WHILE (row = results.next) %]
|
||||||
<tr>
|
<tr>
|
||||||
<form name="update">
|
<form name="del">
|
||||||
<td class="center_cell"><a class="nd_linkcell"
|
<td class="center_cell"><a class="nd_linkcell"
|
||||||
href="[% device_ports %]&q=[% row.dev1 | uri %]">[% row.dev1 | html_entity %]</a></td>
|
href="[% device_ports %]&q=[% row.dev1 | uri %]">[% row.dev1 | html_entity %]</a></td>
|
||||||
<td class="center_cell">[% row.port1 | html_entity %]</td>
|
<td class="center_cell">[% row.port1 | html_entity %]</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user