Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !/usr/bin/env ruby
- require 'logger'
- require 'rest-client'
- #require 'pry-byebug'
- $stdout.sync = true
- $stdin.sync = true
- path = "//home/deepak/ejabberd-16.06/logs/auth.log"
- file = File.open(path, File::WRONLY | File::APPEND | File::CREAT)
- file.sync = true
- logger = Logger.new(file)
- logger.level = Logger::DEBUG
- logger.info "Starting point"
- def auth(username, password)
- RestClient.post("dpkubuntu:3000", :username => username, :password => password)
- return true
- rescue RestClient::Exception
- return false
- end
- logger.info "Starting ejabberd authentication service"
- loop do
- begin
- $stdin.eof? # wait for input
- start = Time.now
- msg = $stdin.read(2)
- # logger.info msg
- if !msg.nil?
- logger.info msg
- length = msg.unpack('n').first
- msg = $stdin.read(length)
- cmd, *data = msg.split(":")
- logger.info "Incoming Request: '#{cmd}'"
- success = case cmd
- when "auth"
- logger.info "Authenticating #{data[0]}@#{data[1]}"
- auth(data[0], data[2])
- when "isuser"
- logger.info "Is user"
- false
- else
- false
- end
- bool = success ? 1 : 0
- $stdout.write [2, bool].pack("nn")
- logger.info "Response: #{success ? "success" : "failure"}"
- end
- rescue => e
- logger.error "#{e.class.name}: #{e.message}"
- logger.error e.backtrace.join("\n\t")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement