diff --git a/config.ru b/config.ru index 6fe1a68..516d985 100644 --- a/config.ru +++ b/config.ru @@ -13,6 +13,10 @@ module PrivatePub end PrivatePub.set_config secret_token: ENV['SECRET_KEY'] +require 'logger' +Faye.logger = Logger.new(STDOUT) +Faye.logger.level = Logger::INFO + require './lib/private_faye' options = { @@ -27,8 +31,9 @@ options = { } Faye::WebSocket.load_adapter('thin') -run Faye::RackAdapter.new(options) +client = Faye::RackAdapter.new(options) -require 'logger' -Faye.logger = Logger.new(STDOUT) -Faye.logger.level = Logger::INFO +client.on(:disconnect) do |client_id| + Faye.logger.info "#{client_id} has been disconnected" +end +run client diff --git a/lib/private_faye.rb b/lib/private_faye.rb index b726f6d..2e0036f 100644 --- a/lib/private_faye.rb +++ b/lib/private_faye.rb @@ -9,6 +9,10 @@ def incoming(message, callback) end def authenticate_subscribe(message) + Faye.logger.info("!!! Attempting authenticated subscription for:") + Faye.logger.info(message) + Faye.logger.info("!!!") + if message["ext"].nil? message["error"] = "Extension data is missing" return message @@ -17,8 +21,12 @@ def authenticate_subscribe(message) subscription = PrivatePub.subscription(:channel => message["subscription"], :timestamp => message["ext"]["private_pub_timestamp"]) if message["ext"]["private_pub_signature"] != subscription[:signature] message["error"] = "Incorrect signature." + Faye.logger.info "WARNING!!!" + Faye.logger.info message["error"] elsif PrivatePub.signature_expired? message["ext"]["private_pub_timestamp"].to_i message["error"] = "Signature has expired." + Faye.logger.info "WARNING!!!" + Faye.logger.info message["error"] end end def authenticate_publish(message) @@ -31,6 +39,8 @@ def authenticate_publish(message) raise Error, "No secret_token config set, ensure private_pub.yml is loaded properly." elsif message["ext"]["private_pub_token"] != PrivatePub.config[:secret_token] message["error"] = "Incorrect token." + Faye.logger.info "WARNING!!!" + Faye.logger.info message["error"] else message["ext"]["private_pub_token"] = nil end