complete Manage Pseudo Devices

This commit is contained in:
Oliver Gorwits
2013-05-06 22:01:13 +01:00
parent 024f4d9a83
commit 9690a31f19
6 changed files with 72 additions and 1 deletions

View File

@@ -7,6 +7,7 @@
* The netdisco-do script can run any one-off job * The netdisco-do script can run any one-off job
* Select MAC Address display format on Node and Device Port search * Select MAC Address display format on Node and Device Port search
* Helper script to import the Netdisco 1.x Topology file to the database * Helper script to import the Netdisco 1.x Topology file to the database
* Support for pseudo devices (useful for dummy device links)
[ENHANCEMENTS] [ENHANCEMENTS]

View File

@@ -5,6 +5,12 @@ use Dancer ':syntax';
get '/admin/*' => sub { get '/admin/*' => sub {
my ($tag) = splat; 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 # trick the ajax into working as if this were a tabbed page
params->{tab} = $tag; params->{tab} = $tag;

View File

@@ -17,6 +17,8 @@ sub _sanity_ok {
my $happy = 0; my $happy = 0;
try { try {
return 0 unless var('user')->admin;
return 0 unless length param('dns') return 0 unless length param('dns')
and param('dns') =~ m/^[[:print:]]+$/ and param('dns') =~ m/^[[:print:]]+$/
and param('dns') !~ m/[[:space:]]/; and param('dns') !~ m/[[:space:]]/;
@@ -57,7 +59,63 @@ ajax '/ajax/content/admin/pseudodevice/add' => sub {
forward '/ajax/content/admin/pseudodevice'; 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 { ajax '/ajax/content/admin/pseudodevice' => sub {
return unless var('user')->admin;
my $set = schema('netdisco')->resultset('Device') my $set = schema('netdisco')->resultset('Device')
->search( ->search(
{vendor => 'netdisco'}, {vendor => 'netdisco'},

View File

@@ -7,6 +7,8 @@ use Dancer::Plugin::DBIC;
use Try::Tiny; use Try::Tiny;
ajax '/ajax/portcontrol' => sub { ajax '/ajax/portcontrol' => sub {
return unless var('user')->port_control;
try { 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'),

View File

@@ -26,9 +26,14 @@
<td class="center_cell">[% row.ip | html_entity %]</td> <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="ports" type="number" value="[% row.port_count | html_entity %]"</td>
<td class="center_cell"> <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> <button class="btn" name="update" type="submit"><i class="icon-save text-warning"></i></button>
</form> </form>
<form name="del" class="nd_inline_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> <button class="btn" name="del" type="submit"><i class="icon-trash text-error"></i></button>
</form> </form>
</td> </td>

1
TODO
View File

@@ -17,7 +17,6 @@ DAEMON
CORE CORE
==== ====
* pseudo-device support
* VRF support * VRF support
DOCS DOCS