complete Manage Pseudo Devices
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
* The netdisco-do script can run any one-off job
|
||||
* Select MAC Address display format on Node and Device Port search
|
||||
* Helper script to import the Netdisco 1.x Topology file to the database
|
||||
* Support for pseudo devices (useful for dummy device links)
|
||||
|
||||
[ENHANCEMENTS]
|
||||
|
||||
|
||||
@@ -5,6 +5,12 @@ use Dancer ':syntax';
|
||||
get '/admin/*' => sub {
|
||||
my ($tag) = splat;
|
||||
|
||||
if (! var('user')->admin) {
|
||||
status(302);
|
||||
header(Location => uri_for('/')->path_query());
|
||||
return;
|
||||
}
|
||||
|
||||
# trick the ajax into working as if this were a tabbed page
|
||||
params->{tab} = $tag;
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ sub _sanity_ok {
|
||||
my $happy = 0;
|
||||
|
||||
try {
|
||||
return 0 unless var('user')->admin;
|
||||
|
||||
return 0 unless length param('dns')
|
||||
and param('dns') =~ m/^[[:print:]]+$/
|
||||
and param('dns') !~ m/[[:space:]]/;
|
||||
@@ -57,7 +59,63 @@ ajax '/ajax/content/admin/pseudodevice/add' => sub {
|
||||
forward '/ajax/content/admin/pseudodevice';
|
||||
};
|
||||
|
||||
ajax '/ajax/content/admin/pseudodevice/del' => sub {
|
||||
forward '/ajax/content/admin/pseudodevice'
|
||||
unless _sanity_ok();
|
||||
|
||||
try {
|
||||
schema('netdisco')->txn_do(sub {
|
||||
my $device = schema('netdisco')->resultset('Device')
|
||||
->find({ip => param('ip')});
|
||||
|
||||
$device->ports->delete;
|
||||
$device->delete;
|
||||
});
|
||||
};
|
||||
|
||||
forward '/ajax/content/admin/pseudodevice';
|
||||
};
|
||||
|
||||
ajax '/ajax/content/admin/pseudodevice/update' => sub {
|
||||
forward '/ajax/content/admin/pseudodevice'
|
||||
unless _sanity_ok();
|
||||
|
||||
try {
|
||||
schema('netdisco')->txn_do(sub {
|
||||
my $device = schema('netdisco')->resultset('Device')
|
||||
->with_port_count->find({ip => param('ip')});
|
||||
my $count = $device->port_count;
|
||||
|
||||
if (param('ports') > $count) {
|
||||
my $start = $count + 1;
|
||||
try {
|
||||
schema('netdisco')->txn_do(sub {
|
||||
$device->ports->populate([
|
||||
['port'],
|
||||
map {["Port$_"]} @{[$start .. param('ports')]},
|
||||
]);
|
||||
});
|
||||
};
|
||||
}
|
||||
elsif (param('ports') < $count) {
|
||||
my $start = param('ports') + 1;
|
||||
try {
|
||||
schema('netdisco')->txn_do(sub {
|
||||
$device->ports
|
||||
->single({port => "Port$_"})->delete
|
||||
for ($start .. $count);
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
forward '/ajax/content/admin/pseudodevice';
|
||||
};
|
||||
|
||||
ajax '/ajax/content/admin/pseudodevice' => sub {
|
||||
return unless var('user')->admin;
|
||||
|
||||
my $set = schema('netdisco')->resultset('Device')
|
||||
->search(
|
||||
{vendor => 'netdisco'},
|
||||
|
||||
@@ -7,6 +7,8 @@ use Dancer::Plugin::DBIC;
|
||||
use Try::Tiny;
|
||||
|
||||
ajax '/ajax/portcontrol' => sub {
|
||||
return unless var('user')->port_control;
|
||||
|
||||
try {
|
||||
my $log = sprintf 'd:[%s] p:[%s] f:[%s]. a:[%s] v[%s]',
|
||||
param('device'), (param('port') || ''), param('field'),
|
||||
|
||||
@@ -26,9 +26,14 @@
|
||||
<td class="center_cell">[% row.ip | html_entity %]</td>
|
||||
<td class="center_cell"><input name="ports" type="number" value="[% row.port_count | html_entity %]"</td>
|
||||
<td class="center_cell">
|
||||
<input name="dns" type="hidden" value="[% row.dns | html_entity %]">
|
||||
<input name="ip" type="hidden" value="[% row.ip | html_entity %]">
|
||||
<button class="btn" name="update" type="submit"><i class="icon-save text-warning"></i></button>
|
||||
</form>
|
||||
<form name="del" class="nd_inline_form">
|
||||
<input name="dns" type="hidden" value="[% row.dns | html_entity %]">
|
||||
<input name="ip" type="hidden" value="[% row.ip | html_entity %]">
|
||||
<input name="ports" type="hidden" value="[% row.port_count | html_entity %]">
|
||||
<button class="btn" name="del" type="submit"><i class="icon-trash text-error"></i></button>
|
||||
</form>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user