Skip to content

Instantly share code, notes, and snippets.

@AgoristRadio
Forked from dreness/filesink.rb
Created October 28, 2013 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AgoristRadio/7206848 to your computer and use it in GitHub Desktop.
Save AgoristRadio/7206848 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'blather/client'
require 'awesome_print'
require 'nokogiri'
require 'pretty-xml'
require 'nokogiri-pretty'
include PrettyXML
# This is a Blather bot that receives file transfers that are sent using
# XEP 0096, using either p2p SOCKS5 (XEP 0065), or through the server
# using in-band bytestreams (XEP 0047).
# Does not work at all with servers that implement XEP 0198!
# Servers that require 0198 are incompatible with clients that don't implement
# Run with -D, and look for:
# xmlns:ack="http://www.xmpp.org/extensions/xep-0198.html#ns"
# So far, only tested with a client that had a proxy65 on its side.
setup 'filesink@xmpp.example.com', 'MyGreatPassword'
when_ready do
set_caps(
"http://dreness.com/filesink",
[{:type => "bot", :category => "client", :name => "csbot"}],
[
# In-band bytestreams: http://xmpp.org/extensions/xep-0047.html
"http://jabber.org/protocol/ibb",
# SOCKS5 Bytestreams: http://xmpp.org/extensions/xep-0065.html
"http://jabber.org/protocol/bytestreams",
# SI File Transfer: http://xmpp.org/extensions/xep-0096.html
"http://jabber.org/protocol/si",
# Namespace of stream initiation profile (specified in 0096)
"http://jabber.org/protocol/si/profile/file-transfer",
]
)
puts "Connected to #{client.jid}. Sent capabilities:"
send_caps
ap client.caps, :plain => true
puts
set_status(state = nil, msg = 'I dream of electric sheep')
end
# Auto approve subscription requests
subscription :request? do |s|
write_to_stream s.approve!
end
# Echo back what was said
message :chat?, :body do |m|
write_to_stream m.reply
end
# Accept SI file transfers
client.register_handler :file_transfer do |iq|
transfer = Blather::FileTransfer.new(client, iq)
transfer.accept(
Blather::FileTransfer::SimpleFileReceiver,
"/home/filesink/f/#{iq.si.file["name"]}", # destination path
iq.si.file["size"].to_i,
)
puts "Receiving file from #{iq.from}"
puts iq.si.file.to_xml
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment