Skip to content
Snippets Groups Projects
Commit 454d5479 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Merge branch 'config-file' into 'master'

Add support for a configuration file



See merge request !2
parents 14f0dce2 2f32ba7f
No related branches found
No related tags found
1 merge request!2Add support for a configuration file
...@@ -22,6 +22,11 @@ use warnings; ...@@ -22,6 +22,11 @@ use warnings;
use Term::ANSIColor; use Term::ANSIColor;
use Getopt::Long; 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 # Check IO::Socket::INET6
if (!eval {require IO::Socket::INET6; 1;}) { if (!eval {require IO::Socket::INET6; 1;}) {
print STDERR "You're missing IO::Socket::INET6, try 'apt-get install libio-socket-inet6-perl'\n"; 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'})) { ...@@ -70,6 +75,16 @@ if (defined($optctl{'version'})) {
exit 0; 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 # Pull in hostname
my $hostSpec = shift(@ARGV) // ""; my $hostSpec = shift(@ARGV) // "";
my ($host,$port) = split(':',$hostSpec); my ($host,$port) = split(':',$hostSpec);
...@@ -127,7 +142,7 @@ print STDERR "\n"; ...@@ -127,7 +142,7 @@ print STDERR "\n";
my $ldap = Net::LDAP->new('ldaps://XXX', my $ldap = Net::LDAP->new($ldapURL,
# 'debug' => 15 # 'debug' => 15
); );
if (!defined($ldap)) { if (!defined($ldap)) {
...@@ -136,11 +151,11 @@ if (!defined($ldap)) { ...@@ -136,11 +151,11 @@ if (!defined($ldap)) {
} }
# Bind # Bind
my $mesg = $ldap->bind("cn=$username,ou=Users,YYY",password => $password); my $mesg = $ldap->bind("cn=$username,ou=Users,$ldapDC",password => $password);
# Search # Search
$mesg = $ldap->search( $mesg = $ldap->search(
base => "ou=Servers,ZZZ", base => "ou=Servers,$ldapDC",
filter => "(|(cn=$host)(awitLoginHost=$host)(awitLoginHostAlias=$host))", filter => "(|(cn=$host)(awitLoginHost=$host)(awitLoginHostAlias=$host))",
); );
# Check for error # Check for error
...@@ -226,7 +241,7 @@ if ($ldapEntry) { ...@@ -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