* none is not a valid value for min-width, so set it to zero * these 2 "checked" if statements need a space in front of them, else they will attach to the previous element id="nd_showspeed"checked="checked" * multiple tag has no options according to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select also, don't close select before we've gotten to the option tags * multiple tag has no options according to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select also, don't close select before we've gotten to the option tags * just to be sure put a space in front of these optional tags as well, * $a is technically allowed but is considered not best practice
89 lines
2.3 KiB
Perl
89 lines
2.3 KiB
Perl
package App::Netdisco::Web::PortControl;
|
|
|
|
use Dancer ':syntax';
|
|
use Dancer::Plugin::Ajax;
|
|
use Dancer::Plugin::DBIC;
|
|
use Dancer::Plugin::Auth::Extensible;
|
|
|
|
use App::Netdisco::JobQueue qw/jq_insert jq_userlog/;
|
|
|
|
ajax '/ajax/portcontrol' => require_any_role [qw(admin port_control)] => sub {
|
|
send_error('No device/port/field', 400)
|
|
unless param('device') and (param('port') or param('field'));
|
|
|
|
my $log = sprintf 'd:[%s] p:[%s] f:[%s]. a:[%s] v[%s]',
|
|
param('device'), (param('port') || ''), param('field'),
|
|
(param('action') || ''), (param('value') || '');
|
|
|
|
my %action_map = (
|
|
'location' => 'location',
|
|
'contact' => 'contact',
|
|
'c_port' => 'portcontrol',
|
|
'c_name' => 'portname',
|
|
'c_pvid' => 'vlan',
|
|
'c_power' => 'power',
|
|
);
|
|
|
|
my $action = $action_map{ param('field') };
|
|
my $subaction = ($action =~ m/^(?:power|portcontrol)/
|
|
? (param('action') ."-other")
|
|
: param('value'));
|
|
|
|
schema('netdisco')->txn_do(sub {
|
|
if (param('port')) {
|
|
my $act = "$action $subaction";
|
|
$act =~ s/-other$//;
|
|
$act =~ s/^portcontrol/port/;
|
|
|
|
schema('netdisco')->resultset('DevicePortLog')->create({
|
|
ip => param('device'),
|
|
port => param('port'),
|
|
action => $act,
|
|
username => session('logged_in_user'),
|
|
userip => request->remote_address,
|
|
reason => (param('reason') || 'other'),
|
|
log => param('log'),
|
|
});
|
|
}
|
|
|
|
jq_insert({
|
|
device => param('device'),
|
|
port => param('port'),
|
|
action => $action,
|
|
subaction => $subaction,
|
|
username => session('logged_in_user'),
|
|
userip => request->remote_address,
|
|
log => $log,
|
|
});
|
|
});
|
|
|
|
content_type('application/json');
|
|
to_json({});
|
|
};
|
|
|
|
ajax '/ajax/userlog' => require_login sub {
|
|
my @jobs = jq_userlog( session('logged_in_user') );
|
|
|
|
my %status = (
|
|
'done' => [
|
|
map {s/\[\]/<empty>/; $_}
|
|
map { $_->log }
|
|
grep { $_->status eq 'done' }
|
|
grep { defined }
|
|
@jobs
|
|
],
|
|
'error' => [
|
|
map {s/\[\]/<empty>/; $_}
|
|
map { $_->log }
|
|
grep { $_->status eq 'error' }
|
|
grep { defined }
|
|
@jobs
|
|
],
|
|
);
|
|
|
|
content_type('application/json');
|
|
to_json(\%status);
|
|
};
|
|
|
|
true;
|