diff --git a/Build.PL b/Build.PL index 3fb6f8c4..5097b335 100644 --- a/Build.PL +++ b/Build.PL @@ -26,6 +26,7 @@ Module::Build->new( 'App::cpanminus' => '1.6108', 'App::local::lib::helper' => '0.07', 'Archive::Extract' => '0', + 'Authen::Radius' => '0', 'CGI::Expand' => '2.05', 'Data::Printer' => '0', 'DBD::Pg' => '0', diff --git a/lib/App/Netdisco/DB.pm b/lib/App/Netdisco/DB.pm index baa9bd21..75040b9c 100644 --- a/lib/App/Netdisco/DB.pm +++ b/lib/App/Netdisco/DB.pm @@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces( ); our # try to hide from kwalitee - $VERSION = 58; # schema version used for upgrades, keep as integer + $VERSION = 59; # schema version used for upgrades, keep as integer use Path::Class; use File::ShareDir 'dist_dir'; diff --git a/lib/App/Netdisco/DB/Result/User.pm b/lib/App/Netdisco/DB/Result/User.pm index 612019db..6e525547 100644 --- a/lib/App/Netdisco/DB/Result/User.pm +++ b/lib/App/Netdisco/DB/Result/User.pm @@ -29,6 +29,8 @@ __PACKAGE__->add_columns( { data_type => "boolean", default_value => \"false", is_nullable => 1 }, "ldap", { data_type => "boolean", default_value => \"false", is_nullable => 1 }, + "radius", + { data_type => "boolean", default_value => \"false", is_nullable => 1 }, "admin", { data_type => "boolean", default_value => \"false", is_nullable => 1 }, "fullname", diff --git a/lib/App/Netdisco/DB/Result/Virtual/UserRole.pm b/lib/App/Netdisco/DB/Result/Virtual/UserRole.pm index af960260..7e9f2910 100644 --- a/lib/App/Netdisco/DB/Result/Virtual/UserRole.pm +++ b/lib/App/Netdisco/DB/Result/Virtual/UserRole.pm @@ -20,6 +20,9 @@ __PACKAGE__->result_source_instance->view_definition(<realm_settings; my $username_column = $settings->{users_username_column} || 'username'; -# return $user->ldap -# ? $self->match_with_ldap($password, $user->$username_column) -# : $self->match_with_local_pass($password, $user); - my $pwmatch_result=0; + my $pwmatch_result = 0; my $username = $user->$username_column; if ($user->ldap) { - $pwmatch_result = $self->match_with_ldap($password, $user->$username_column); - } else { - if ( setting('radius') and ref {} eq ref setting('radius') ) { - $pwmatch_result = ( $self->match_with_radius($password, $username) || $self->match_with_local_pass($password, $user) ); - } else { - $pwmatch_result = $self->match_with_local_pass($password, $user); - } - } + $pwmatch_result = $self->match_with_ldap($password, $username); + } + elsif ($user->raidus) { + $pwmatch_result = $self->match_with_radius($password, $username); + } + else { + $pwmatch_result = $self->match_with_local_pass($password, $user); + } + + return $pwmatch_result; } sub match_with_local_pass { @@ -230,21 +226,27 @@ sub _ldap_search { return undef; } + sub match_with_radius { - my($self, $pass, $user) = @_; - return unless setting('radius') and ref {} eq ref setting('radius'); - my $conf = setting('radius'); - my $radius = new Authen::Radius(Host => $conf->{server}, Secret => $conf->{secret}); - Authen::Radius->load_dictionary(); - $radius->add_attributes( - { Name=> 'User-Name', Value => $user }, - { Name=> 'User-Password', Value => $pass }, - { Name => 'h323-return-code', Value => '0' }, # Cisco AV pair - { Name => 'Digest-Attributes', Value => { Method => 'REGISTER' } } - ); - $radius->send_packet(ACCESS_REQUEST); - my $type = $radius->recv_packet(); - my $radius_return = ($type eq ACCESS_ACCEPT)?1:0; - return $radius_return; + my($self, $pass, $user) = @_; + return unless setting('radius') and ref {} eq ref setting('radius'); + + my $conf = setting('radius'); + my $radius = Authen::Radius->new(Host => $conf->{server}, Secret => $conf->{secret}); + Authen::Radius->load_dictionary(); + + $radius->add_attributes( + { Name => 'User-Name', Value => $user }, + { Name => 'User-Password', Value => $pass }, + { Name => 'h323-return-code', Value => '0' }, # Cisco AV pair + { Name => 'Digest-Attributes', Value => { Method => 'REGISTER' } } + ); + $radius->send_packet(ACCESS_REQUEST); + + my $type = $radius->recv_packet(); + my $radius_return = ($type eq ACCESS_ACCEPT) ? 1 : 0; + + return $radius_return; } + 1; diff --git a/lib/App/Netdisco/Web/Plugin/AdminTask/Users.pm b/lib/App/Netdisco/Web/Plugin/AdminTask/Users.pm index 94893702..712e26ca 100644 --- a/lib/App/Netdisco/Web/Plugin/AdminTask/Users.pm +++ b/lib/App/Netdisco/Web/Plugin/AdminTask/Users.pm @@ -41,6 +41,7 @@ ajax '/ajax/control/admin/users/add' => require_role setting('defanged_admin') = password => _make_password(param('password')), fullname => param('fullname'), ldap => (param('ldap') ? \'true' : \'false'), + radius => (param('radius') ? \'true' : \'false'), port_control => (param('port_control') ? \'true' : \'false'), admin => (param('admin') ? \'true' : \'false'), note => param('note'), @@ -71,6 +72,7 @@ ajax '/ajax/control/admin/users/update' => require_role setting('defanged_admin' : ()), fullname => param('fullname'), ldap => (param('ldap') ? \'true' : \'false'), + radius => (param('radius') ? \'true' : \'false'), port_control => (param('port_control') ? \'true' : \'false'), admin => (param('admin') ? \'true' : \'false'), note => param('note'), diff --git a/share/schema_versions/App-Netdisco-DB-58-59-PostgreSQL.sql b/share/schema_versions/App-Netdisco-DB-58-59-PostgreSQL.sql new file mode 100644 index 00000000..8262af36 --- /dev/null +++ b/share/schema_versions/App-Netdisco-DB-58-59-PostgreSQL.sql @@ -0,0 +1,7 @@ +BEGIN; + +ALTER TABLE users ADD radius boolean; + +ALTER TABLE users ALTER radius SET DEFAULT false; + +COMMIT; diff --git a/share/views/ajax/admintask/users.tt b/share/views/ajax/admintask/users.tt index ab766b2e..7131a2a5 100644 --- a/share/views/ajax/admintask/users.tt +++ b/share/views/ajax/admintask/users.tt @@ -5,6 +5,7 @@ Username Password LDAP Auth + RADIUS Auth Port Control Administrator Created @@ -19,6 +20,7 @@ + @@ -45,6 +47,9 @@ + + + diff --git a/share/views/ajax/admintask/users_csv.tt b/share/views/ajax/admintask/users_csv.tt index 315e29c1..5005c6e8 100644 --- a/share/views/ajax/admintask/users_csv.tt +++ b/share/views/ajax/admintask/users_csv.tt @@ -1,6 +1,6 @@ [% USE CSV -%] [% CSV.dump([ 'Full Name' 'Username' - 'LDAP Auth' 'Port Control' 'Administrator' 'Created' + 'LDAP Auth' 'RADIUS Auth' 'Port Control' 'Administrator' 'Created' 'Last Login' 'Note']) %] [% FOREACH row IN results %] @@ -8,6 +8,7 @@ [% mylist.push(row.fullname) %] [% mylist.push(row.username) %] [% mylist.push(row.ldap) %] + [% mylist.push(row.radius) %] [% mylist.push(row.port_control) %] [% mylist.push(row.admin) %] [% mylist.push(row.created) %] diff --git a/share/views/layouts/main.tt b/share/views/layouts/main.tt index f1b12a34..c3ecac2f 100644 --- a/share/views/layouts/main.tt +++ b/share/views/layouts/main.tt @@ -181,7 +181,7 @@ [% session.logged_in_fullname || session.logged_in_user | html_entity %]