sendxmpp 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a0e5fe224abe1427c9c2523e9ad3b0e86422f8d
4
+ data.tar.gz: 0e22571caec9351c6467c9fdc9435933f3d68755
5
+ SHA512:
6
+ metadata.gz: 8ca65c1302527956fba6ade6e5b8127b98fb04e0604aac0d2b66cb5d152f1cb9b1b878a4dad2ed7e92d5207582d453a2db38e762d070da783f65a3cc7646dd71
7
+ data.tar.gz: 50dbad308aaca2a54628e63743d006f9caea03f34e33176312094248dbe96af041bde843fce035da23d378ab573d191be0a638cf23ed431894cbbc49a45c275b
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ local/
3
+ settings.ini
4
+ Makefile
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.1
8
+ - ruby-head
9
+
10
+ notifications:
11
+ disabled: true
12
+
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sendxmpp (0.0.1)
5
+ hashr
6
+ inifile (~> 2.0)
7
+ thor (~> 0.19, >= 0.19.1)
8
+ xmpp4r (~> 0.5)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ hashr (0.0.22)
14
+ inifile (2.0.2)
15
+ rake (10.3.1)
16
+ thor (0.19.1)
17
+ xmpp4r (0.5.6)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ rake (~> 10.1)
24
+ sendxmpp!
data/README.md ADDED
File without changes
data/TODO.md ADDED
File without changes
data/bin/sendxmpprb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ $:.unshift File.expand_path('../../lib', __FILE__)
5
+
6
+ require 'sendxmpp'
7
+ Sendxmpp::CLI.start
data/lib/sendxmpp.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'logger'
2
+ module Sendxmpp
3
+ require 'sendxmpp/version'
4
+ require 'sendxmpp/config'
5
+ require 'sendxmpp/log'
6
+ require 'sendxmpp/message'
7
+ require 'sendxmpp/cli'
8
+ end
@@ -0,0 +1,120 @@
1
+ require 'thor'
2
+ require 'inifile'
3
+
4
+ module Sendxmpp
5
+
6
+ # Class CLI
7
+ #
8
+ # Input via STDIN or -m option:
9
+ #
10
+ # Examples
11
+ # sendxmpprb -m "server down notification" user mosny@jabber.org
12
+ # echo "server down"|sendxmpprb user mosny@jabber.org
13
+ # ...
14
+ #
15
+ class CLI < Thor
16
+ include Config
17
+
18
+ class_option :server, default: "", type: :string, aliases: "-s", required: false
19
+ class_option :port, default: 5222, type: :numeric, aliases: "-p", required: false
20
+ class_option :tls, default: true, type: :boolean, aliases: "-t", required: false
21
+ class_option :tls_verify_peer, default: true, type: :boolean, required: false
22
+ class_option :tls_ca, default: "", type: :string, required: false
23
+ class_option :resource, default: "Sendxmpp", type: :string, required: false
24
+ class_option :password, default: "", type: :string, required: false
25
+ class_option :message, default: "", type: :string, aliases: '-m', required: false
26
+ class_option :jid, default: "", type: :string, required: false
27
+ class_option :config, default: "#{ENV['HOME']}/.sendxmpprbrc", type: :string, aliases: "-c", required: false
28
+ class_option :logfile, default: nil, aliases: '-l', required: false
29
+
30
+ # Public: logger
31
+ attr_reader :log
32
+
33
+ # Public: Initialize a new Object from CLI
34
+ #
35
+ # args - Arguments, passed to Thor
36
+ #
37
+ # Raises IniFile::Error on invalid configuration
38
+ # Raises ArgumentError if the main hash key was not found
39
+ def initialize(*args)
40
+ super
41
+ if File.exists?(options[:config])
42
+ conf = IniFile.load(options[:config])["sendxmpp"]
43
+ if conf.nil? || conf.empty?
44
+ raise ArgumentError, "No [sendxmpp] section in ini file found!"
45
+ end
46
+ local_conf = options.dup
47
+ local_conf.delete_if{|k,v|v.nil?||(v.kind_of?(String) && v.empty?)}
48
+ conf.merge!(local_conf)
49
+ update_config(conf)
50
+ end
51
+ Log.logger.debug("finished loading configuration.")
52
+ $stdout.sync = true
53
+ end
54
+
55
+ desc "user [USER1],[USER2],...", "send a message to jabber users"
56
+ # Public: Send a message to multiple users.
57
+ # Message will be sent to each user seperately
58
+ #
59
+ # jids - Receipient(s) can be one or more
60
+ #
61
+ # Examples
62
+ # user(["mosny@jabber.org"])
63
+ # user(["mosny@jabber.org", "someone@jabber.org"])
64
+ # ...
65
+ #
66
+ # Returns 0 or 1 exit codes
67
+ def user(*jids)
68
+ Log.logger.debug("Received call for user method")
69
+ unless jids.kind_of?(Array)
70
+ Log.logger.error("Throwing ArgumentError because Jids is not an array.")
71
+ raise ArgumentError, "Jids needs to be an Array got #{jids.class}"
72
+ end
73
+
74
+ if options.message.empty?
75
+ Log.logger.error("No message to send. Exiting.")
76
+ Log.logger.error("See https://github.com/nirnanaaa/sendxmpprb/wiki/Sending-messages for available message formats.")
77
+ exit 1
78
+ end
79
+
80
+ Message.batch do
81
+ jids.each do |jid|
82
+ Message.message_to_user(jid)
83
+ end
84
+ end
85
+ end
86
+
87
+ desc "chat [CHAT1],[CHAT2],...", "send a message to multiple multi user chats"
88
+ # Public: Send a message to a single/multiple multi user chatrooms.
89
+ # Messages will be sent to each chat seperately
90
+ #
91
+ # jids - Array of MUC(Multi user chat) jids.
92
+ #
93
+ # Examples
94
+ # chat(["edv@conference.jabber.org"])
95
+ # chat(["edv@conference.jabber.org", "staff@conference.jabber.org"])
96
+ #
97
+ # Returns 0 or 1 exit codes
98
+ def chat(*jids)
99
+ Log.logger.debug("Received call for chat method")
100
+ unless jids.kind_of?(Array)
101
+ Log.logger.error("Throwing ArgumentError because Jids is not an array.")
102
+ raise ArgumentError, "Jids needs to be an Array got #{jids.class}"
103
+ end
104
+
105
+ if options.message.empty?
106
+ Log.logger.error("No message to send. Exiting.")
107
+ Log.logger.error("See https://github.com/nirnanaaa/sendxmpprb/wiki/Sending-messages for available message formats.")
108
+ exit 1
109
+ end
110
+
111
+ Message.batch do
112
+ jids.each do |jid|
113
+ Message.message_to_room(jid)
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ end
120
+ end
@@ -0,0 +1,49 @@
1
+ require 'hashr'
2
+ module Sendxmpp
3
+
4
+ # Private: This class provides access to the main configuration
5
+ #
6
+ # Should not be used without Config module
7
+ class InternalConfiguration < Hashr
8
+
9
+ # Public: Static singleton
10
+ #
11
+ # Gets a singleton object
12
+ def self.config
13
+ @conf ||= self.new
14
+ end
15
+
16
+ # Public: Merge new configuration
17
+ #
18
+ # Use Config.update_config instead!
19
+ #
20
+ # Returns nothing
21
+ def self.merge_config(newconfig)
22
+ @conf = self.new(newconfig)
23
+ end
24
+ end
25
+
26
+ # Public: Configuration module. Should be included
27
+ #
28
+ # Usage
29
+ # include Config
30
+ #
31
+ # def some_method
32
+ # config.configbla
33
+ # end
34
+ module Config
35
+
36
+ # Public: Gets the configuration from InternalConfiguration
37
+ #
38
+ # Returns a singleton object of InternalConfiguration
39
+ def config
40
+ InternalConfiguration.config
41
+ end
42
+
43
+ # Public: Updates the configuration of InternalConfiguration
44
+ #
45
+ def update_config(new)
46
+ InternalConfiguration.merge_config(new)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ require 'logger'
2
+ module Sendxmpp
3
+ class Log < Logger
4
+ include Config
5
+ attr_accessor :logger_ins
6
+
7
+ def self.logger
8
+ @logger ||= self.new
9
+ end
10
+
11
+ def initialize
12
+ if config.logfile
13
+ super(config.logfile)
14
+ else
15
+ super(STDOUT)
16
+ end
17
+ self.level = config.loglevel.to_i || 2
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,172 @@
1
+ require 'xmpp4r/client'
2
+ module Sendxmpp
3
+
4
+ # Public: Message class
5
+ #
6
+ # requires an initialized Config class.
7
+ #
8
+ class Message
9
+ include Config
10
+ include ::Jabber
11
+
12
+ # Public: Getter for the batch status
13
+ attr_reader :batch
14
+
15
+ # Public: Getter / Setter for the jabber client
16
+ attr_accessor :client
17
+
18
+ # Public: Getter for receipients
19
+ #
20
+ # Returns an Array
21
+ def receipients
22
+ @receipients ||= []
23
+ end
24
+
25
+ # Public: Initializer
26
+ #
27
+ #
28
+ def initialize
29
+ @batch=false
30
+ if config.jid.nil? || config.jid.empty?
31
+ raise ArgumentError, <<-RAISE
32
+ \rJID is not configured. Please use the configuration file or specify the
33
+ \r-j option.
34
+ RAISE
35
+ end
36
+
37
+ jid = JID.new(config.jid)
38
+ Log.logger.debug("Initializing a new Jabber client instance.")
39
+ self.client = Client.new(jid)
40
+ Log.logger.debug("Initialized a new Jabber client instance.")
41
+
42
+ Log.logger.debug("Connecting to Jabber server.")
43
+ client.connect(config.server, config.port)
44
+ Log.logger.debug("Connected to Jabber server.")
45
+
46
+ Log.logger.debug("Authenticating with Jabber server.")
47
+ client.auth(config.password)
48
+ Log.logger.debug("Authenticating with Jabber server.")
49
+ end
50
+
51
+ # Public: Singleton object getter
52
+ def self.myself
53
+ @self ||= self.new
54
+ end
55
+
56
+ # Public: Batch relay
57
+ def self.batch(&block)
58
+ myself.process_batch(&block)
59
+ end
60
+
61
+ # Public: Send a message to a user
62
+ #
63
+ # user - Receipient
64
+ #
65
+ def self.message_to_user(user)
66
+ myself.message(type: :user, user: user)
67
+ end
68
+
69
+ # Public: Send a message to a chatroom
70
+ #
71
+ # room - Room to send message to
72
+ #
73
+ def self.message_to_room(room)
74
+ myself.message(type: :group, user: room)
75
+ end
76
+
77
+ # Public: Split a special formatted JID into the following
78
+ # parts:
79
+ # JID - normal XMPP JID
80
+ # Password - XMPP room password
81
+ #
82
+ # user - JID to split up
83
+ #
84
+ # Returns an Array of 2 elements
85
+ def split_password(user)
86
+ user.split(":")
87
+ end
88
+
89
+ # Public: Send a message
90
+ #
91
+ # options - Message hash options
92
+ #
93
+ # Examples
94
+ # message(type: :user, user: "jid@server.com")
95
+ # message(type: :group, user: "jid@conference.server.com:password")
96
+ #
97
+ def message(options)
98
+ return if config.message.empty?
99
+ if batch == true
100
+ receipients << options
101
+ else
102
+ if options[:type] == :user
103
+ send_message(config.message, options[:user])
104
+ else
105
+ group, password = split_password(options[:user])
106
+ send_muc_message(config.message, group, password)
107
+ end
108
+ end
109
+ end
110
+
111
+ # Public: Enables batch procession for this session
112
+ #
113
+ # block - Block to execute as a batch
114
+ #
115
+ # Returns false
116
+ def process_batch(&block)
117
+ Log.logger.info("Batch procession started.")
118
+ unless block_given?
119
+ raise ArgumentError, "Do not use this function without a block"
120
+ end
121
+ @batch=true
122
+ yield
123
+ send_batch
124
+ @batch=false
125
+ end
126
+
127
+ # Public: Send a message to a single user
128
+ #
129
+ # user - JID of the receipient
130
+ #
131
+ # Returns nothing
132
+ def send_message(user)
133
+ Log.logger.debug("sending message to user %s" % user)
134
+ m = Jabber::Message.new(user, config.message)
135
+ client.send(m)
136
+ Log.logger.debug("sent message")
137
+ end
138
+
139
+ # Public: Send a message to a MUC (Multi User Chat)
140
+ #
141
+ # room - Room to send the message to
142
+ # password - Password for the chatroom if required
143
+ #
144
+ # Returns nothing
145
+ def send_muc_message(room, password=nil)
146
+ Log.logger.debug("including file xmpp4r/muc")
147
+ require 'xmpp4r/muc'
148
+ m = Jabber::Message.new(room, config.message)
149
+ muc = MUC::MUCClient.new(client)
150
+ if !muc.active?
151
+ Log.logger.info("Joining room %s" % room)
152
+ muc.join(JID.new(room + '/' + config.resource), password)
153
+ Log.logger.info("Joined room %s" % room)
154
+ end
155
+ muc.send m
156
+ end
157
+
158
+ # Public: Send the batch out
159
+ def send_batch
160
+ receipients.flatten.each do |rcpt|
161
+ user, password = split_password(rcpt[:user])
162
+ if rcpt[:type] == :user
163
+ send_message(user)
164
+ elsif rcpt[:type] == :group
165
+ send_muc_message(user, password)
166
+ end
167
+ Log.logger.debug("Removing item %p from queue" % rcpt)
168
+ receipients.delete(rcpt)
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,5 @@
1
+ module Sendxmpp
2
+
3
+ # Public: version number
4
+ VERSION="0.0.1"
5
+ end
data/sendxmpp.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sendxmpp/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sendxmpp"
7
+ s.version = Sendxmpp::VERSION
8
+ s.authors = ["Florian Kasper"]
9
+ s.email = ["florian.kasper@corscience.de"]
10
+ s.homepage = "http://git.er.corscience.de"
11
+ s.summary = %q{Send messages from the console to a XMPP server}
12
+ s.description = %q{Send messages from the console to a XMPP server}
13
+
14
+ s.rubyforge_project = "sendxmpp"
15
+ s.license = "MIT"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+
23
+ s.add_runtime_dependency "thor", "~> 0.19", '>= 0.19.1'
24
+ s.add_runtime_dependency "inifile", "~> 2.0"
25
+ s.add_runtime_dependency "xmpp4r", "~> 0.5"
26
+ s.add_dependency "hashr"
27
+
28
+ s.add_development_dependency "rake", "~> 10.1"
29
+ end
@@ -0,0 +1,42 @@
1
+ [sendxmpp]
2
+
3
+ # The JID of the sending user
4
+ # Default: ""
5
+ jid=bla@jabberdomain.example.com
6
+
7
+ # The Password of the sending user
8
+ # Default: ""
9
+ # password=
10
+
11
+ # The Resource to send messages from
12
+ # Default: Sendxmpp
13
+ # resource=YODA
14
+
15
+ # Use TLS
16
+ # Default: true
17
+ # tls=true
18
+
19
+ # Port of the Jabber Server
20
+ # Default: 5222
21
+ # port=5222
22
+
23
+ # Server to send messages over. If no server is provided DNS SRV record from jid will be used
24
+ # Default: ""
25
+ # server=jabber.org
26
+
27
+ # Verify TLS identity.
28
+ # Default: true
29
+ # tls_verify_peer=true
30
+
31
+ # Logfile to log in to
32
+ # Default: STDOUT
33
+ # logfile = "/var/log/sendxmpp.log"
34
+
35
+ # Loglevel
36
+ # VALUES:
37
+ # err - 3
38
+ # warn - 2
39
+ # info - 1
40
+ # debug - 0
41
+ # Default: 2
42
+ loglevel = 2
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sendxmpp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Florian Kasper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.19.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.19'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.19.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: inifile
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: xmpp4r
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.5'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.5'
61
+ - !ruby/object:Gem::Dependency
62
+ name: hashr
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '10.1'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '10.1'
89
+ description: Send messages from the console to a XMPP server
90
+ email:
91
+ - florian.kasper@corscience.de
92
+ executables:
93
+ - sendxmpprb
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - ".gitignore"
98
+ - ".travis.yml"
99
+ - Gemfile
100
+ - Gemfile.lock
101
+ - README.md
102
+ - TODO.md
103
+ - bin/sendxmpprb
104
+ - lib/sendxmpp.rb
105
+ - lib/sendxmpp/cli.rb
106
+ - lib/sendxmpp/config.rb
107
+ - lib/sendxmpp/log.rb
108
+ - lib/sendxmpp/message.rb
109
+ - lib/sendxmpp/version.rb
110
+ - sendxmpp.gemspec
111
+ - settings.ini.sample
112
+ homepage: http://git.er.corscience.de
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project: sendxmpp
132
+ rubygems_version: 2.2.2
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Send messages from the console to a XMPP server
136
+ test_files: []