xmpp4r 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/COPYING +340 -0
  2. data/ChangeLog +28 -0
  3. data/LICENSE +59 -0
  4. data/README +20 -0
  5. data/Rakefile +103 -0
  6. data/UPDATING +40 -0
  7. data/data/doc/xmpp4r/examples/advanced/adventure/README +57 -0
  8. data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
  9. data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
  10. data/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
  11. data/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
  12. data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +425 -0
  13. data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
  14. data/data/doc/xmpp4r/examples/advanced/fileserve.rb +344 -0
  15. data/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
  16. data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
  17. data/data/doc/xmpp4r/examples/advanced/migrate.rb +89 -0
  18. data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
  19. data/data/doc/xmpp4r/examples/advanced/recvfile.rb +83 -0
  20. data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +130 -0
  21. data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
  22. data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
  23. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
  24. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
  25. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
  26. data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +90 -0
  27. data/data/doc/xmpp4r/examples/advanced/xmpping.rb +134 -0
  28. data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +9 -0
  29. data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
  30. data/data/doc/xmpp4r/examples/basic/client.rb +68 -0
  31. data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
  32. data/data/doc/xmpp4r/examples/basic/echo_nonthreaded.rb +32 -0
  33. data/data/doc/xmpp4r/examples/basic/echo_threaded.rb +32 -0
  34. data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
  35. data/data/doc/xmpp4r/examples/basic/mass_sender.rb +67 -0
  36. data/data/doc/xmpp4r/examples/basic/mucinfo.rb +39 -0
  37. data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +83 -0
  38. data/data/doc/xmpp4r/examples/basic/register.rb +25 -0
  39. data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
  40. data/data/doc/xmpp4r/examples/basic/roster.rb +42 -0
  41. data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
  42. data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
  43. data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +172 -0
  44. data/data/doc/xmpp4r/examples/basic/send_vcard.rb +68 -0
  45. data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
  46. data/data/doc/xmpp4r/examples/buggy/jabber2jabber/jabber2jabber.rb +18 -0
  47. data/data/doc/xmpp4r/examples/buggy/miniedgarr_cgi.rb +192 -0
  48. data/data/doc/xmpp4r/examples/buggy/miniedgarr_watch.rb +82 -0
  49. data/lib/callbacks.rb +122 -0
  50. data/lib/xmpp4r/authenticationfailure.rb +13 -0
  51. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +315 -0
  52. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +256 -0
  53. data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +30 -0
  54. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +46 -0
  55. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +151 -0
  56. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +85 -0
  57. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +178 -0
  58. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +56 -0
  59. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +61 -0
  60. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +177 -0
  61. data/lib/xmpp4r/bytestreams/iq/si.rb +221 -0
  62. data/lib/xmpp4r/bytestreams.rb +11 -0
  63. data/lib/xmpp4r/client.rb +249 -0
  64. data/lib/xmpp4r/component.rb +103 -0
  65. data/lib/xmpp4r/connection.rb +166 -0
  66. data/lib/xmpp4r/dataforms/x/data.rb +248 -0
  67. data/lib/xmpp4r/dataforms.rb +1 -0
  68. data/lib/xmpp4r/debuglog.rb +34 -0
  69. data/lib/xmpp4r/delay/x/delay.rb +100 -0
  70. data/lib/xmpp4r/delay.rb +1 -0
  71. data/lib/xmpp4r/discovery/iq/discoinfo.rb +225 -0
  72. data/lib/xmpp4r/discovery/iq/discoitems.rb +162 -0
  73. data/lib/xmpp4r/discovery.rb +2 -0
  74. data/lib/xmpp4r/error.rb +230 -0
  75. data/lib/xmpp4r/errorexception.rb +32 -0
  76. data/lib/xmpp4r/feature_negotiation/iq/feature.rb +42 -0
  77. data/lib/xmpp4r/feature_negotiation.rb +1 -0
  78. data/lib/xmpp4r/idgenerator.rb +37 -0
  79. data/lib/xmpp4r/iq.rb +229 -0
  80. data/lib/xmpp4r/jid.rb +167 -0
  81. data/lib/xmpp4r/message.rb +171 -0
  82. data/lib/xmpp4r/muc/helper/mucbrowser.rb +107 -0
  83. data/lib/xmpp4r/muc/helper/mucclient.rb +382 -0
  84. data/lib/xmpp4r/muc/helper/simplemucclient.rb +222 -0
  85. data/lib/xmpp4r/muc/x/muc.rb +98 -0
  86. data/lib/xmpp4r/muc/x/mucuserinvite.rb +58 -0
  87. data/lib/xmpp4r/muc/x/mucuseritem.rb +148 -0
  88. data/lib/xmpp4r/muc.rb +6 -0
  89. data/lib/xmpp4r/presence.rb +255 -0
  90. data/lib/xmpp4r/query.rb +43 -0
  91. data/lib/xmpp4r/rexmladdons.rb +826 -0
  92. data/lib/xmpp4r/roster/helper/roster.rb +514 -0
  93. data/lib/xmpp4r/roster/iq/roster.rb +244 -0
  94. data/lib/xmpp4r/roster/x/roster.rb +155 -0
  95. data/lib/xmpp4r/roster.rb +4 -0
  96. data/lib/xmpp4r/sasl.rb +167 -0
  97. data/lib/xmpp4r/stream.rb +543 -0
  98. data/lib/xmpp4r/streamparser.rb +77 -0
  99. data/lib/xmpp4r/vcard/helper/vcard.rb +86 -0
  100. data/lib/xmpp4r/vcard/iq/vcard.rb +102 -0
  101. data/lib/xmpp4r/vcard.rb +3 -0
  102. data/lib/xmpp4r/version/helper/responder.rb +71 -0
  103. data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
  104. data/lib/xmpp4r/version/iq/version.rb +118 -0
  105. data/lib/xmpp4r/version.rb +3 -0
  106. data/lib/xmpp4r/x.rb +43 -0
  107. data/lib/xmpp4r/xmlstanza.rb +174 -0
  108. data/lib/xmpp4r/xmpp4r.rb +16 -0
  109. data/lib/xmpp4r.rb +122 -0
  110. data/setup.rb +1360 -0
  111. data/test/bytestreams/tc_ibb.rb +186 -0
  112. data/test/bytestreams/tc_socks5bytestreams.rb +57 -0
  113. data/test/delay/tc_xdelay.rb +51 -0
  114. data/test/lib/clienttester.rb +110 -0
  115. data/test/muc/tc_muc_mucclient.rb +569 -0
  116. data/test/muc/tc_muc_simplemucclient.rb +72 -0
  117. data/test/roster/.tc_helper.rb.swp +0 -0
  118. data/test/roster/tc_helper.rb +389 -0
  119. data/test/roster/tc_iqqueryroster.rb +140 -0
  120. data/test/roster/tc_xroster.rb +70 -0
  121. data/test/tc_callbacks.rb +128 -0
  122. data/test/tc_class_names.rb +129 -0
  123. data/test/tc_client.rb +30 -0
  124. data/test/tc_error.rb +103 -0
  125. data/test/tc_idgenerator.rb +30 -0
  126. data/test/tc_iq.rb +109 -0
  127. data/test/tc_iqquery.rb +31 -0
  128. data/test/tc_jid.rb +202 -0
  129. data/test/tc_message.rb +114 -0
  130. data/test/tc_presence.rb +148 -0
  131. data/test/tc_stream.rb +182 -0
  132. data/test/tc_streamError.rb +87 -0
  133. data/test/tc_streamSend.rb +59 -0
  134. data/test/tc_streamThreaded.rb +168 -0
  135. data/test/tc_xmlstanza.rb +76 -0
  136. data/test/ts_xmpp4r.rb +34 -0
  137. data/test/vcard/tc_iqvcard.rb +52 -0
  138. data/test/version/tc_helper.rb +46 -0
  139. data/test/version/tc_iqqueryversion.rb +96 -0
  140. data/tools/doctoweb.bash +30 -0
  141. data/tools/gen_requires.bash +10 -0
  142. metadata +232 -0
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ $:.unshift '../../lib'
4
+ require 'shellmgr'
5
+ require 'xmpp4r'
6
+ include Jabber
7
+
8
+ if ARGV.length != 3
9
+ puts "usage: ./shellmgr_jabber.rb jid_to_use password jid_to_authorize"
10
+ exit(1)
11
+ end
12
+
13
+ myjid = JID::new(ARGV[0])
14
+ mypassword = ARGV[1]
15
+ authjid = JID::new(ARGV[2])
16
+
17
+ myjid = JID::new(myjid.node, myjid.domain, 'RSM')
18
+ cl = Client::new(myjid)
19
+ cl.connect
20
+ cl.auth(mypassword)
21
+ mainthread = Thread.current
22
+ sh = Shell::new { |str|
23
+ puts "-----RECEIVING-----\n#{str}"
24
+ cl.send(Message::new(authjid, str)) }
25
+ cl.add_message_callback do |m|
26
+ if JID::new(m.from).strip.to_s != authjid.strip.to_s
27
+ puts "Received message from non-authorized user #{m.from}"
28
+ else
29
+ if m.body == "killshell"
30
+ cl.send(Message::new(authjid, "Exiting..."))
31
+ mainthread.wakeup
32
+ else
33
+ puts "-----EXECUTING-----\n#{m.body}"
34
+ sh.puts(m.body)
35
+ end
36
+ end
37
+ end
38
+ cl.send(Presence::new)
39
+ puts "Connected ! Ask #{authjid.to_s} to send commands to #{myjid.to_s}"
40
+ cl.send(Message::new(authjid, "I'm ready to receive commands from you."))
41
+ Thread.stop
42
+ cl.close
43
+ sh.kill
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ require 'shellmgr'
4
+
5
+ sh = Shell::new { |s| puts s }
6
+
7
+ while true do
8
+ l = gets
9
+ sh.puts l
10
+ end
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # This script will request the version information of a list of JID given
4
+ # on stdin.
5
+
6
+ $:.unshift '../lib'
7
+
8
+ require 'optparse'
9
+ require 'xmpp4r/client'
10
+ require 'xmpp4r/version/iq/version'
11
+ include Jabber
12
+ #Jabber::debug = true
13
+
14
+ # settings
15
+ jid = JID::new('bot@localhost/Bot')
16
+ password = 'bot'
17
+ domains = []
18
+ OptionParser::new do |opts|
19
+ opts.banner = 'Usage: versionpoll.rb -j jid -p password -d DOMAINS'
20
+ opts.separator ''
21
+ opts.on('-j', '--jid JID', 'sets the jid') { |j| jid = JID::new(j) }
22
+ opts.on('-p', '--password PASSWORD', 'sets the password') { |p| password = p }
23
+ opts.on('-d', '--domain DOMAIN', 'sets the domain') { |d| domains << d }
24
+ opts.on_tail('-h', '--help', 'Show this message') {
25
+ puts opts
26
+ exit
27
+ }
28
+ opts.parse!(ARGV)
29
+ end
30
+
31
+ cl = Client::new(jid)
32
+ cl.connect
33
+ cl.auth(password)
34
+ sent = []
35
+ queried = []
36
+ activity = false
37
+ cl.add_iq_callback do |i|
38
+ fjid = JID::new(i.from)
39
+ if i.type == :result and fjid.resource == "admin"
40
+ domain = fjid.domain
41
+ items = i.first_element('item')
42
+ raise "items nil" if items.nil?
43
+ items.each_element('user') do |e|
44
+ j = e.attribute('jid')
45
+ if not queried.include?(j)
46
+ activity = true
47
+ queried << j
48
+ cl.send(Iq::new_browseget.set_to(j))
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ cl.add_iq_callback do |i|
55
+ if i.type == :result
56
+ u = i.first_element('user')
57
+ if u
58
+ u.each_element('user') do |e|
59
+ if (a = e.attribute('type'))
60
+ if a.value == 'client'
61
+ activity = true
62
+ iq = Iq::new(:get)
63
+ iq.query = Version::IqQueryVersion::new
64
+ iq.set_to(JID::new(e.attribute('jid').to_s))
65
+ cl.send(iq)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ cl.add_iq_callback do |iq|
73
+ if iq.type == :result and iq.query.class == Version::IqQueryVersion
74
+ activity = true
75
+ r = [ iq.from.to_s, iq.query.iname, iq.query.version, iq.query.os ]
76
+ puts r.inspect
77
+ end
78
+ end
79
+ cl.send(Presence::new)
80
+ for d in domains do
81
+ cl.send(Iq::new_browseget.set_to("#{d}/admin"))
82
+ end
83
+
84
+ activity = true
85
+ while activity
86
+ activity = false
87
+ # other threads might set activity to true
88
+ sleep 10
89
+ end
90
+ cl.close
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This is PING for Jabber
4
+ #
5
+ # Please customize your ~/.xmppingrc
6
+
7
+
8
+ require 'xmpp4r'
9
+ require 'xmpp4r/version/iq/version'
10
+ require 'xmpp4r/discovery/iq/discoinfo'
11
+ require 'optparse'
12
+ require 'yaml'
13
+ require 'thread'
14
+
15
+
16
+ ##
17
+ # Options
18
+ ##
19
+
20
+ interval = 5
21
+ jid = nil
22
+ conf_filename = "#{ENV['HOME']}/.xmppingrc"
23
+ accountname = 'default'
24
+
25
+ OptionParser.new { |opts|
26
+ opts.banner = 'Usage: xmpping.rb [-d] [-a ACCOUNT] [-c FILENAME] [-i SECONDS] -t <JID>'
27
+ opts.separator 'Ping a destination JID with various <iq/> stanzas'
28
+ opts.on('-t', '--to JID', 'Destionation Jabber-ID') { |j| jid = Jabber::JID.new(j) }
29
+ opts.on('-a', '--account ACCOUNT', 'Account tag to use (default: default)') { |a| accountname = a }
30
+ opts.on('-c', '--config FILENAME', 'Configuration file (default: ~/.xmppingrc)') { |c| conf_filename = c }
31
+ opts.on('-i', '--interval SECONDS', 'Wait SECONDS between each stanza (default: 5)') { |sec| interval = sec.to_i }
32
+ opts.on('-d', '--debug', 'Enable XMPP4R debugging (print stanzas)') { Jabber::debug = true }
33
+ opts.on_tail('-h', '--help', 'Show help') {
34
+ puts opts
35
+ exit
36
+ }
37
+ opts.parse!(ARGV)
38
+
39
+ unless jid
40
+ puts opts
41
+ exit
42
+ end
43
+ }
44
+
45
+
46
+ ##
47
+ # Configuration
48
+ ##
49
+
50
+ begin
51
+ conf_file = File.new(conf_filename)
52
+ rescue Exception => e
53
+ puts "Unable to open config file: #{e.to_s}"
54
+ exit
55
+ end
56
+
57
+ conf = YAML::load(conf_file)
58
+ unless conf
59
+ puts "#{conf_filename} is no valid YAML document"
60
+ exit
61
+ end
62
+ account = conf[accountname]
63
+ unless account
64
+ puts "Account #{accountname} not found in #{conf_filename}"
65
+ exit
66
+ end
67
+
68
+ ##
69
+ # Connection
70
+ ##
71
+
72
+ cl = Jabber::Client.new(Jabber::JID.new(account['jid']))
73
+ cl.connect(account['host'], (account['port'] ? account['port'].to_i : 5222))
74
+ cl.auth(account['password'])
75
+
76
+ ##
77
+ # Reply printer
78
+ ##
79
+
80
+ def print_reply(iq, roundtrip)
81
+ roundtrip_s = ((roundtrip * 100).round / 100.0).to_s + " sec"
82
+ output = "Received a #{iq.query.namespace} #{iq.type} from #{iq.from} (#{roundtrip_s}): "
83
+
84
+ if iq.query.kind_of?(Jabber::Version::IqQueryVersion)
85
+ output += "#{iq.query.iname}-#{iq.query.version} #{iq.query.os}"
86
+ elsif iq.query.namespace == 'jabber:iq:time'
87
+ output += "#{iq.query.first_element_text('display')} (#{iq.query.first_element_text('tz')})"
88
+ elsif iq.query.kind_of?(Jabber::Discovery::IqQueryDiscoInfo)
89
+ identity = iq.query.identity
90
+ if identity
91
+ output += "#{identity.iname} (#{identity.category} #{identity.type})"
92
+ else
93
+ output += "<identity/> missing"
94
+ end
95
+ else
96
+ output += iq.query.to_s
97
+ end
98
+
99
+ puts output
100
+ end
101
+
102
+ ##
103
+ # Main loop
104
+ ##
105
+
106
+ puts "XMPPING #{cl.jid} -> #{jid}"
107
+ query_methods = ['jabber:iq:version', 'jabber:iq:time', 'http://jabber.org/protocol/disco#info']
108
+ query_method = 0
109
+
110
+ loop {
111
+ Thread.new {
112
+ iq = Jabber::Iq.new_query(:get, jid)
113
+ iq.query.add_namespace(query_methods[query_method])
114
+
115
+ time1 = Time.new
116
+
117
+ begin
118
+ cl.send_with_id(iq) { |reply|
119
+ print_reply(reply, Time.new - time1)
120
+ true
121
+ }
122
+ rescue Jabber::ErrorException => e
123
+ puts "Error for #{iq.query.namespace} to #{iq.to}: #{e.error.to_s.inspect}"
124
+ end
125
+ }
126
+
127
+ query_method += 1
128
+ if query_method >= query_methods.size
129
+ query_method = 0
130
+ end
131
+
132
+ sleep(interval)
133
+ }
134
+
@@ -0,0 +1,9 @@
1
+ default:
2
+ jid: user@host/xmpping
3
+ password: secret
4
+
5
+ other_account:
6
+ jid: me@domain/ping
7
+ password: xxx
8
+ host: 127.0.0.1
9
+ port: 65222
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # A tool to change the password of a Jabber account
4
+ #
5
+
6
+
7
+ $:.unshift('../../../../../lib')
8
+
9
+ require 'xmpp4r'
10
+ include Jabber
11
+
12
+ def with_status(str, &block)
13
+ print "#{str}..."
14
+ $stdout.flush
15
+ begin
16
+ yield
17
+ puts " Ok"
18
+ rescue Exception => e
19
+ puts " Error: #{e.to_s}"
20
+ raise e
21
+ end
22
+ end
23
+
24
+
25
+ # settings
26
+ if ARGV.length != 3
27
+ puts "Run with ./change_password.rb user@server/resource oldpassword newpassword"
28
+ exit 1
29
+ end
30
+ my_jid = JID::new(ARGV[0])
31
+ my_jid.resource = 'change_password' if my_jid.resource.nil?
32
+ old_password = ARGV[1]
33
+ new_password = ARGV[2]
34
+
35
+ cl = Client::new(my_jid)
36
+
37
+ with_status('Connecting') { cl.connect }
38
+ with_status('Authenticating') { cl.auth(old_password) }
39
+ with_status('Changing password') { cl.password = new_password }
40
+
41
+ cl.close
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Basic console client that does nothing, but easy to modify to test things.
4
+ # to test, start, then type :
5
+ # connect login@server/resource password
6
+ # auth
7
+
8
+ require 'xmpp4r/client'
9
+ include Jabber
10
+
11
+ Jabber::debug = true
12
+
13
+ class BasicClient
14
+ def initialize
15
+ puts "Welcome to this Basic Console Jabber Client!"
16
+ quit = false
17
+ # main loop
18
+ while not quit do
19
+ print "> "
20
+ $defout.flush
21
+ line = gets
22
+ quit = true if line.nil?
23
+ if not quit
24
+ command, args = line.split(' ', 2)
25
+ args.chomp!
26
+ # main case
27
+ case command
28
+ when 'exit'
29
+ quit = true
30
+ when 'connect'
31
+ do_connect(args)
32
+ when 'help'
33
+ do_help
34
+ when 'auth'
35
+ do_auth
36
+ else
37
+ puts "Command \"#{command}\" unknown"
38
+ end
39
+ end
40
+ end
41
+ puts "Goodbye!"
42
+ end
43
+
44
+ def do_help
45
+ puts <<-EOF
46
+ # exit - exits
47
+ # connect user@server/resource password - connects
48
+ # auth - sends authentification
49
+ EOF
50
+ end
51
+
52
+ ##
53
+ # connect <jid> <password>
54
+ def do_connect(args)
55
+ @jid, @password = args.split(' ', 3)
56
+ @jid = JID::new(@jid)
57
+ @cl = Client::new(@jid)
58
+ @cl.connect
59
+ end
60
+
61
+ ##
62
+ # auth
63
+ def do_auth
64
+ @cl.auth(@password, false)
65
+ end
66
+ end
67
+
68
+ BasicClient::new
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift '../../../../../lib'
4
+
5
+ require 'xmpp4r'
6
+ include Jabber
7
+
8
+ c = Component::new('tada', 'localhost', 60001)
9
+ c.connect
10
+ c.auth('jabber-rocks')
11
+ Thread.stop
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # This bot will reply to every message it receives. To end the game, send 'exit'
4
+ # NON-THREADED VERSION
5
+
6
+ require 'xmpp4r'
7
+ include Jabber
8
+
9
+ # settings
10
+ if ARGV.length != 2
11
+ puts "Run with ./echo_thread.rb user@server/resource password"
12
+ exit 1
13
+ end
14
+ myJID = JID::new(ARGV[0])
15
+ myPassword = ARGV[1]
16
+ cl = Client::new(myJID, false)
17
+ cl.connect
18
+ cl.auth(myPassword)
19
+ cl.send(Presence::new)
20
+ puts "Connected ! send messages to #{myJID.strip.to_s}."
21
+ exit = false
22
+ cl.add_message_callback { |m|
23
+ cl.send(Message::new(m.from, "You sent: #{m.body}"))
24
+ if m.body == 'exit'
25
+ cl.send(Message::new(m.from, "Exiting ..."))
26
+ exit = true
27
+ end
28
+ }
29
+ while not exit
30
+ cl.process
31
+ end
32
+ cl.close
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # This bot will reply to every message it receives. To end the game, send 'exit'
4
+ # THREADED VERSION
5
+
6
+ require 'xmpp4r/client'
7
+ include Jabber
8
+
9
+ # settings
10
+ if ARGV.length != 2
11
+ puts "Run with ./echo_thread.rb user@server/resource password"
12
+ exit 1
13
+ end
14
+ myJID = JID::new(ARGV[0])
15
+ myPassword = ARGV[1]
16
+ cl = Client::new(myJID)
17
+ cl.connect
18
+ cl.auth(myPassword)
19
+ cl.send(Presence::new)
20
+ puts "Connected ! send messages to #{myJID.strip.to_s}."
21
+ mainthread = Thread.current
22
+ cl.add_message_callback do |m|
23
+ if m.type != :error
24
+ cl.send(Message::new(m.from, "You sent: #{m.body}"))
25
+ if m.body == 'exit'
26
+ cl.send(Message::new(m.from, "Exiting ..."))
27
+ mainthread.wakeup
28
+ end
29
+ end
30
+ end
31
+ Thread.stop
32
+ cl.close
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # This script will send a jabber message to the specified JID. The subject can be
4
+ # specified using the '-s' option, and the message will be taken from stdin.
5
+
6
+ $:.unshift '../../../../../lib'
7
+
8
+ require 'optparse'
9
+ require 'xmpp4r'
10
+ include Jabber
11
+
12
+ # settings
13
+ myJID = JID::new('bot@localhost/Bot')
14
+ myPassword = 'bot'
15
+
16
+ to = nil
17
+ subject = ''
18
+ OptionParser::new do |opts|
19
+ opts.banner = 'Usage: jabbersend.rb -s \'subject\' -t dest@domain'
20
+ opts.separator ''
21
+ opts.on('-s', '--subject SUBJECT', 'sets the message\'s subject') { |s| subject = s }
22
+ opts.on('-t', '--to DESTJID', 'sets the receiver') { |t| to = JID::new(t) }
23
+ opts.on_tail('-h', '--help', 'Show this message') {
24
+ puts opts
25
+ exit
26
+ }
27
+ opts.parse!(ARGV)
28
+ end
29
+
30
+ if to.nil?
31
+ puts "No receiver specified. See jabbersend -h"
32
+ end
33
+
34
+ cl = Client::new(myJID, false)
35
+ cl.connect
36
+ cl.auth(myPassword)
37
+ body = STDIN.readlines.join
38
+ m = Message::new(to, body).set_type(:normal).set_id('1').set_subject(subject)
39
+ puts m.to_s
40
+ cl.send(m)
41
+ cl.close
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # This script will send a jabber message to a list of JID given on stdin.
4
+
5
+ $:.unshift '../../../../../lib'
6
+
7
+ require 'optparse'
8
+ require 'xmpp4r'
9
+ include Jabber
10
+ #Jabber::debug = true
11
+
12
+ # - message in file
13
+ # - subject in command line
14
+ # - JID list on stdin
15
+
16
+ # settings
17
+ jid = JID::new('bot@localhost/Bot')
18
+ password = 'bot'
19
+ filename = 'message.txt'
20
+
21
+ subject = "Message de test"
22
+
23
+ OptionParser::new do |opts|
24
+ opts.banner = 'Usage: mass_sender.rb -j jid -p password'
25
+ opts.separator ''
26
+ opts.on('-j', '--jid JID', 'sets the jid') { |j| jid = JID::new(j) }
27
+ opts.on('-p', '--password PASSWORD', 'sets the password') { |p| password = p }
28
+ opts.on('-f', '--filename MESSAGE', 'sets the filename containing the message') { |f| filename = f }
29
+ opts.on('-s', '--subject SUBJECT', 'sets the subject') { |s| subject = s }
30
+ opts.on_tail('-h', '--help', 'Show this message') {
31
+ puts opts
32
+ exit
33
+ }
34
+ opts.parse!(ARGV)
35
+ end
36
+
37
+ body = IO::read(filename).chomp
38
+
39
+ cl = Client::new(jid, false)
40
+ cl.connect
41
+ cl.auth(password)
42
+ exit = false
43
+ sent = []
44
+ cl.add_message_callback do |m|
45
+ if m.type != :error
46
+ if !sent.include?(m.from)
47
+ cl.send(Message::new(m.from, "Je suis un robot. Si tu souhaites contacter un administrateur du serveur, envoie un message à lucas@nussbaum.fr ou rejoins la salle jabberfr@chat.jabberfr.org."))
48
+ sent << m.from
49
+ end
50
+ if m.body == 'exitnowplease'
51
+ cl.send(Message::new(m.from, "Exiting ..."))
52
+ exit = true
53
+ end
54
+ cl.send(Message::new('lucas@nussbaum.fr', "From #{m.from}: #{m.body.to_s}"))
55
+ end
56
+ end
57
+ cl.send(Presence::new)
58
+ m = Message::new(nil, body)
59
+ STDIN.each_line { |l|
60
+ l.chomp!
61
+ m.set_to(JID::new(l).to_s)
62
+ cl.send(m)
63
+ }
64
+ while not exit do
65
+ cl.process(1)
66
+ end
67
+ cl.close
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'xmpp4r'
4
+ require 'xmpp4r/muc/helper/mucbrowser'
5
+
6
+ if ARGV.size != 3
7
+ puts "Usage: #{$0} <jid> <password> <muc-jid>"
8
+ exit
9
+ end
10
+
11
+ jid, password, muc_jid = Jabber::JID.new(ARGV.shift), ARGV.shift, Jabber::JID.new(ARGV.shift)
12
+
13
+ cl = Jabber::Client.new(jid)
14
+ cl.connect
15
+ cl.auth(password)
16
+
17
+ browser = Jabber::MUC::MUCBrowser.new(cl)
18
+
19
+ print "Querying #{muc_jid} for identity..."; $stdout.flush
20
+ name = browser.muc_name(muc_jid)
21
+
22
+ if name.nil?
23
+ puts " Sorry, but the queried MUC component doesn't seem to support MUC or Groupchat."
24
+ else
25
+ puts " #{name}"
26
+
27
+ print "Querying #{muc_jid} for its rooms..."; $stdout.flush
28
+ rooms = browser.muc_rooms(muc_jid)
29
+ puts " #{rooms.size} rooms found"
30
+
31
+ max_room_length = 0
32
+ rooms.each_key { |jid| max_room_length = jid.to_s.size if jid.to_s.size > max_room_length }
33
+
34
+ rooms.each { |jid,name|
35
+ puts "#{jid.to_s.ljust(max_room_length)} #{name}"
36
+ }
37
+ end
38
+
39
+ cl.close