Commit c9748c2d authored by Francesc Guasch's avatar Francesc Guasch
Browse files

prepare for ldap auth

parent 1548d763
......@@ -6,6 +6,10 @@ use Data::Dumper;
use DBIx::Connector;
use Mojolicious::Lite;
use lib 'lib';
use Ravada::Auth::LDAP;
our $HOST = 'vsertel.upc.es';
our $CON = DBIx::Connector->new("DBI:mysql:ravada"
......@@ -17,13 +21,16 @@ our $TIMEOUT = 120;
any '/' => sub {
my $c = shift;
my $login = ($c->param('login') or '');
my $password = ($c->param('login') or '');
my $id_base = ($c->param('id_base') or 1);
if (!$login ) {
$c->render(login => $login ,template => 'index' , id_base => $id_base
, base => list_bases());
} else {
show_link($c, $id_base, $login);
if ( $login ) {
if (Ravada::Auth::LDAP::login($login, $password)) {
return show_link($c, $id_base, $login);
}
}
$c->render(login => $login ,template => 'index' , id_base => $id_base
, base => list_bases());
};
get '/ip' => sub {
......
package Ravada::Auth::LDAP;
use Net::LDAPS;
our $LDAP;
sub login {
my ($username, $password) = @_;
_init_ldap();
my $search = $ldap->search( # Search for the user
base => 'DC=casa,DC=guru',
scope => 'sub',
filter => "(&(uid=$username))",
attrs => ['dn']
);
die "not found" if not $search->count;
my $user_dn = $search->entry->dn;
warn $user_dn;
$LDAP->bind( $user_dn, password => $pass );
return 1 if !$ldap->error;
warn "ERROR: ".$ldap->error. "Bad credentials for $username";
return;
}
sub _init_ldap {
# TODO ping ldap and reconnect
return if $LDAP;
my ($host, $port) = ('localhost', 389);
$LDAP = Net::LDAPS->new($host, port => $port, verify => 'none')
or die "I can't connect to LDAP server at $host / $port : $@";
}
1;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment