Skip to content
Snippets Groups Projects
Commit 2f32ba7f authored by Robert Spencer's avatar Robert Spencer
Browse files

Add support for a configuration file

parent 14f0dce2
No related branches found
No related tags found
1 merge request!2Add support for a configuration file
......@@ -22,6 +22,11 @@ use warnings;
use Term::ANSIColor;
use Getopt::Long;
# Check Config::IniFiles
if (!eval {require Config::IniFiles; 1;}) {
print STDERR "You're missing Config::IniFiles, try 'apt-get install libconfig-inifiles-perl'\n";
exit 1;
}
# Check IO::Socket::INET6
if (!eval {require IO::Socket::INET6; 1;}) {
print STDERR "You're missing IO::Socket::INET6, try 'apt-get install libio-socket-inet6-perl'\n";
......@@ -70,6 +75,16 @@ if (defined($optctl{'version'})) {
exit 0;
}
# Check for config and read
my $configFile = $ENV{"HOME"}.'/.awit-ssh.conf';
if (! -f $configFile) {
print STDERR sprintf("Your configuration file '%s' is missing!\n",$configFile);
exit 1;
}
my $config = Config::IniFiles->new(-file => $configFile);
my $ldapURL = $config->val("ldap","url");
my $ldapDC = $config->val("ldap","dc");
# Pull in hostname
my $hostSpec = shift(@ARGV) // "";
my ($host,$port) = split(':',$hostSpec);
......@@ -127,7 +142,7 @@ print STDERR "\n";
my $ldap = Net::LDAP->new('ldaps://XXX',
my $ldap = Net::LDAP->new($ldapURL,
# 'debug' => 15
);
if (!defined($ldap)) {
......@@ -136,11 +151,11 @@ if (!defined($ldap)) {
}
# Bind
my $mesg = $ldap->bind("cn=$username,ou=Users,YYY",password => $password);
my $mesg = $ldap->bind("cn=$username,ou=Users,$ldapDC",password => $password);
# Search
$mesg = $ldap->search(
base => "ou=Servers,ZZZ",
base => "ou=Servers,$ldapDC",
filter => "(|(cn=$host)(awitLoginHost=$host)(awitLoginHostAlias=$host))",
);
# Check for error
......@@ -226,7 +241,7 @@ if ($ldapEntry) {
# TODO for forawarding
# TODO for forwarding
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment