Permalink
Browse files

restrict access to jabber bot

  • Loading branch information...
1 parent 72e6a3c commit 65da6f7e944dafe532c3d02f3643f456c4c06d17 @rlane committed May 25, 2009
Showing with 8 additions and 0 deletions.
  1. +2 −0 etc/config.yaml.template
  2. +6 −0 lib/dci/proxy/jabber.rb
View
@@ -18,3 +18,5 @@ jabber_password: 'password'
dc_username: 'user'
location: 'laptop'
sharesize: 406232539641
+users:
+- test@example.com
View
@@ -25,7 +25,12 @@ def initialize username, password
@roster.add_subscription_request_callback(0, nil) { |item,pres| on_subscription_request item, pres }
end
+ def legal_user? u
+ CFG['users'].member? u.strip.to_s
+ end
+
def on_subscription_request item, pres
+ (log.warn "subscription request from illegal user #{pres.from}"; return) unless legal_user? pres.from
@roster.accept_subscription(pres.from)
log.info "accepted subscription request from #{pres.from}"
end
@@ -40,6 +45,7 @@ def on_message m
begin
return if m.body.nil?
log.info "got message from #{m.from}: #{m.body.inspect}"
+ (log.warn "message from illegal user #{m.from}"; return) unless legal_user? m.from
cmd, arg = m.body.split(nil, 2)
cmd ||= ""
arg ||= ""

0 comments on commit 65da6f7

Please sign in to comment.