complete Manage Pseudo Devices
This commit is contained in:
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user