#!/usr/bin/env ruby
# This file is part of LCR-AGI.
#
# LCR-AGI is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LCR-AGI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LCR-AGI. If not, see .
#
# Copyright (C) 2009 Alkaloid Networks LLC
# Author: Ben Klang
# Alkaloid Networks LLC - http://projects.alkaloid.net
# $Id$
require 'ldap'
require 'logger'
# Load our configuration from ./config.rb
require 'config'
require 'rubygems'
require 'ragi/call_server'
require 'pp'
require 'dbi'
require 'active_support'
# Custom functionality libraries
require 'lib/lcr.rb'
require 'lib/routes.rb'
$logger = Logger.new($logfile)
$logger.level = $loglevel
$logger.formatter = Logger::Formatter.new
def getDB
uri = ['DBI', 'Mysql', $dbParams[:dbname], $dbParams[:host]].join(':')
$dbh = DBI.connect(uri, $dbParams[:user], $dbParams[:pass])
end
def getLDAP
$logger.debug{"Entering getLDAP()"}
retryCounter = 0
begin
$ldapClient = LDAP::Conn.new($ldapParams[:host], $ldapParams[:port])
$ldapClient.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
$ldapClient.bind($ldapParams[:binddn], $ldapParams[:bindpw])
rescue Errno::ECONNREFUSED, Timeout::Error, SocketError, LDAP::ResultError,
RuntimeError
if (retryCounter < $ldapParams[:retryLimit])
retryCounter += 1
$logger.warn{"Unable to connect to LDAP server. Trying again in #{$ldapParams[:retryTimer]} seconds."}
sleep $ldapParams[:retryTimer]
retry
else
$logger.error{"ERROR: Retry limit exceeded for connection to LDAP server!"}
return false
end
end
$logger.info{"Successfully connected to LDAP"}
return true
end
getDB
getLDAP
server = RAGI::CallServer.new({:DefaultHandler => 'LCR', :Logger => $logger})