enhance protocol radius
This commit is contained in:
parent
d1f51ed32f
commit
73c5a932b4
|
@ -78,22 +78,21 @@ sub new {
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'hostname:s' => { name => 'hostname' },
|
||||||
"hostname:s" => { name => 'hostname' },
|
'port:s' => { name => 'port', default => 1812 },
|
||||||
"port:s" => { name => 'port', default => 1812 },
|
'secret:s' => { name => 'secret' },
|
||||||
"secret:s" => { name => 'secret' },
|
'username:s' => { name => 'username' },
|
||||||
"username:s" => { name => 'username' },
|
'password:s' => { name => 'password' },
|
||||||
"password:s" => { name => 'password' },
|
'warning:s' => { name => 'warning' },
|
||||||
"warning:s" => { name => 'warning' },
|
'critical:s' => { name => 'critical' },
|
||||||
"critical:s" => { name => 'critical' },
|
'timeout:s' => { name => 'timeout', default => 5 },
|
||||||
"timeout:s" => { name => 'timeout', default => 5 },
|
'retry:s' => { name => 'retry', default => 0 },
|
||||||
"retry:s" => { name => 'retry', default => 0 },
|
'radius-attribute:s%' => { name => 'radius_attribute' },
|
||||||
'radius-attribute:s%' => { name => 'radius_attribute' },
|
'radius-dictionary:s@' => { name => 'radius_dictionary' },
|
||||||
'radius-dictionary:s' => { name => 'radius_dictionary' },
|
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
'critical-status:s' => { name => 'critical_status', default => '%{status} ne "accepted"' }
|
||||||
"critical-status:s" => { name => 'critical_status', default => '%{status} ne "accepted"' },
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
@ -110,11 +109,10 @@ sub check_options {
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined($self->{option_results}->{radius_attribute}) &&
|
$self->{radius_dictionary} = [];
|
||||||
(!defined($self->{option_results}->{radius_dictionary}) || $self->{option_results}->{radius_dictionary} eq '')) {
|
if (defined($self->{option_results}->{radius_attribute})) {
|
||||||
$self->{output}->add_option_msg(short_msg => "Please set radius-dictionary option");
|
$self->{radius_dictionary} = $self->{option_results}->{radius_attribute};
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{option_results}->{retry} = 0 if (!defined($self->{option_results}->{retry}) || $self->{option_results}->{retry} !~ /^\d+$/);
|
$self->{option_results}->{retry} = 0 if (!defined($self->{option_results}->{retry}) || $self->{option_results}->{retry} !~ /^\d+$/);
|
||||||
|
@ -151,7 +149,11 @@ sub radius_attr_connection {
|
||||||
local $SIG{__WARN__} = sub { $message = join(' - ', @_); };
|
local $SIG{__WARN__} = sub { $message = join(' - ', @_); };
|
||||||
local $SIG{__DIE__} = sub { $message = join(' - ', @_); };
|
local $SIG{__DIE__} = sub { $message = join(' - ', @_); };
|
||||||
|
|
||||||
Authen::Radius->load_dictionary($self->{option_results}->{radius_dictionary});
|
foreach my $dic (@{$self->{radius_dictionary}}) {
|
||||||
|
next if ($dic eq '');
|
||||||
|
Authen::Radius->load_dictionary($dic);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (keys %{$self->{option_results}->{radius_attribute}}) {
|
foreach (keys %{$self->{option_results}->{radius_attribute}}) {
|
||||||
$self->{radius_session}->add_attributes({ Name => $_, Value => $self->{option_results}->{radius_attribute}->{$_} });
|
$self->{radius_session}->add_attributes({ Name => $_, Value => $self->{option_results}->{radius_attribute}->{$_} });
|
||||||
}
|
}
|
||||||
|
@ -192,7 +194,11 @@ sub manage_selection {
|
||||||
Secret => $self->{option_results}->{secret},
|
Secret => $self->{option_results}->{secret},
|
||||||
TimeOut => $self->{option_results}->{timeout},
|
TimeOut => $self->{option_results}->{timeout},
|
||||||
);
|
);
|
||||||
|
if (!defined($self->{radius_session})) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => 'failure: ' . Authen::Radius::strerror());
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
|
||||||
if (defined($self->{option_results}->{radius_attribute})) {
|
if (defined($self->{option_results}->{radius_attribute})) {
|
||||||
$self->radius_attr_connection();
|
$self->radius_attr_connection();
|
||||||
} else {
|
} else {
|
||||||
|
@ -257,7 +263,7 @@ Example: --radius-attribute="User-Password=test"
|
||||||
|
|
||||||
=item B<--radius-dictionary>
|
=item B<--radius-dictionary>
|
||||||
|
|
||||||
Set radius-dictionary file (mandatory with --radius-attribute).
|
Set radius-dictionary file (mandatory with --radius-attribute) (multiple option).
|
||||||
|
|
||||||
=item B<--warning-status>
|
=item B<--warning-status>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue