sendxmpp 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cc050e0b5313028144349aee744b9e141529a79
4
- data.tar.gz: fdf58b28ed0f48c920d37f0047b38338a35879e2
3
+ metadata.gz: dace202f420d76b23bd6a0ae781ec756315f3a9a
4
+ data.tar.gz: 78d823036bd6713d0b700bc8fedff36d3002b791
5
5
  SHA512:
6
- metadata.gz: 8d873583af32693c81bf2360999174b03345523f222fd0f1c31cb1731366fb3aa89451f1dce98a48292d4659cd2a95d92d87c6e8c07ecc43e09a871b2193e1c1
7
- data.tar.gz: 9f28f0b8beaa4c656cc97b27a01b37a705f55da2933a9895f8a6da1ae389c6d703b82b9fe26e35288820b66dd5f8b337d7fbaaeba91eaef47be94f63b603b5f2
6
+ metadata.gz: 4dd3c0f7310d67652f4ee8174dc4b8252f2f6153a29a57aeb159621236477ffa3e11bd3d4f84e4a8c990dcc33e6ff06e498513f41be9d148bd6491f94f69b65b
7
+ data.tar.gz: 738b4619e1043f1b256c676f5eb37775e5b52d6e3c2604be52db6048cbb8e31b9f5467fc74dff6019505991d4eaf9dc608ae7133a066ae38001a631605d1fbd2
@@ -26,6 +26,7 @@ module Sendxmpp
26
26
  class_option :jid, default: "", type: :string, required: false, aliases: '-j'
27
27
  class_option :config, default: "#{ENV['HOME']}/.sendxmpprbrc", type: :string, aliases: "-c", required: false
28
28
  class_option :logfile, default: nil, aliases: '-l', required: false
29
+ class_option :subject, default: nil, type: :string, required: false
29
30
 
30
31
 
31
32
  # Public: Initialize a new Object from CLI
@@ -59,9 +60,13 @@ module Sendxmpp
59
60
  # jids - Receipient(s) can be one or more
60
61
  #
61
62
  # Examples
63
+ #
64
+ # sendxmpp user mosny@jabber.org -m "test"
65
+ # echo "test" | sendxmpp user mosny@jabber.org
66
+ # sendxmpp user mosny@jabber.org < /var/log/system.log
67
+ #
62
68
  # user(["mosny@jabber.org"])
63
69
  # user(["mosny@jabber.org", "someone@jabber.org"])
64
- # ...
65
70
  #
66
71
  # Returns 0 or 1 exit codes
67
72
  def user(*jids)
@@ -72,11 +77,7 @@ module Sendxmpp
72
77
  raise ArgumentError, "Jids needs to be an Array got #{jids.class}"
73
78
  end
74
79
 
75
- if config.message.empty?
76
- Log.logger.error("No message to send. Exiting.")
77
- Log.logger.error("See https://github.com/nirnanaaa/sendxmpprb/wiki/Sending-messages for available message formats.")
78
- exit 1
79
- end
80
+ check_messagequeue
80
81
 
81
82
  Message.batch do
82
83
  jids.each do |jid|
@@ -92,6 +93,11 @@ module Sendxmpp
92
93
  # jids - Array of MUC(Multi user chat) jids.
93
94
  #
94
95
  # Examples
96
+ #
97
+ # sendxmpp chat edv@conference.jabber.org -m "test"
98
+ # echo "test" | sendxmpp chat edv@conference.jabber.org:password
99
+ # sendxmpp chat edv@conference.jabber.org < /var/log/system.log
100
+ #
95
101
  # chat(["edv@conference.jabber.org"])
96
102
  # chat(["edv@conference.jabber.org", "staff@conference.jabber.org"])
97
103
  #
@@ -104,11 +110,7 @@ module Sendxmpp
104
110
  raise ArgumentError, "Jids needs to be an Array got #{jids.class}"
105
111
  end
106
112
 
107
- if config.message.empty?
108
- Log.logger.error("No message to send. Exiting.")
109
- Log.logger.error("See https://github.com/nirnanaaa/sendxmpprb/wiki/Sending-messages for available message formats.")
110
- exit 1
111
- end
113
+ check_messagequeue
112
114
 
113
115
  Message.batch do
114
116
  jids.each do |jid|
@@ -116,14 +118,83 @@ module Sendxmpp
116
118
  end
117
119
  end
118
120
 
121
+ end
122
+
123
+ desc "fromconf", "Read the receipients from configuration file"
124
+ # Public: Will read the receipients from configuration file and send the message to the users
125
+ #
126
+ # Examples
127
+ # sendxmpp fromconf -m "test"
128
+ # echo "test" |sendxmpp fromconf
129
+ # sendxmpp fromconf < /var/log/system.log
130
+ #
131
+ # Returns an exit code 0 or 1
132
+ def fromconf
133
+ Log.logger.debug("Received call for fromconf method")
134
+ if !config.receipients
135
+ Log.logger.error("No receipient(s) specified.")
136
+ Log.logger.error("Please read https://github.com/nirnanaaa/sendxmpprb/wiki/Configuration on how to specify receipients.")
137
+ exit 1
138
+ end
139
+ fetch_stdin
140
+ check_messagequeue
141
+ users, muc = parse_receipients
142
+ Message.batch do
143
+ users.each do |jid|
144
+ Message.message_to_user(jid)
145
+ end
146
+ muc.each do |jid|
147
+ Message.message_to_room(jid)
148
+ end
149
+ end
150
+
119
151
  end
120
152
  no_commands do
153
+
154
+ # Public: Check for presence of a message. The message is needed, because otherwise
155
+ # there would be nothing to do.
156
+ #
157
+ # Exits on failure
158
+ def check_messagequeue
159
+ if !config.message
160
+ Log.logger.error("No message to send. Exiting.")
161
+ Log.logger.error("See https://github.com/nirnanaaa/sendxmpprb/wiki/Sending-messages for available message formats.")
162
+ exit 1
163
+ end
164
+ end
165
+
166
+ # Public: read receipients from configuration
167
+ #
168
+ # Returns an array of types
169
+ def parse_receipients
170
+ types = [[],[]]
171
+ config.receipients.split(",").each do |r|
172
+ type, jid = r.split("->")
173
+ type == "muc" ? types.last << jid : types.first << jid
174
+ end
175
+ types
176
+ end
177
+
178
+ # Public: Fetch stdin input
179
+ #
180
+ # Before reading, stdin will be checked for presence.
181
+ #
182
+ # THIS METHOD ONLY WORKS ON UNIX BASED SYSTEMS, AS FCNTL
183
+ # IS NOT AVAILABLE ON WINDOWS
184
+ #
185
+ # Returns nothing
121
186
  def fetch_stdin
187
+ require 'fcntl'
122
188
  if !config.message
123
189
  Log.logger.info("messages empty. using stdin")
124
- while $stdin.gets
125
- config.message ||= ""
126
- config.message << $_
190
+ if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0
191
+ Log.logger.info("stdin not empty. Reading from it")
192
+ while $stdin.gets
193
+ config.message ||= ""
194
+ config.message << $_
195
+ end
196
+ else
197
+ return
127
198
  end
128
199
  end
129
200
  end
@@ -102,10 +102,10 @@ module Sendxmpp
102
102
  receipients << options
103
103
  else
104
104
  if options[:type] == :user
105
- send_message(config.message, options[:user])
105
+ send_message(options[:user])
106
106
  else
107
107
  group, password = split_password(options[:user])
108
- send_muc_message(config.message, group, password)
108
+ send_muc_message(group, password)
109
109
  end
110
110
  end
111
111
  end
@@ -134,7 +134,7 @@ module Sendxmpp
134
134
  # Returns nothing
135
135
  def send_message(user)
136
136
  Log.logger.debug("sending message to user %s" % user)
137
- m = Jabber::Message.new(user, config.message)
137
+ m = Jabber::Message.new(user, generate_message)
138
138
  client.send(m)
139
139
  Log.logger.debug("sent message")
140
140
  end
@@ -148,7 +148,7 @@ module Sendxmpp
148
148
  def send_muc_message(room, password=nil)
149
149
  Log.logger.debug("including file xmpp4r/muc")
150
150
  require 'xmpp4r/muc'
151
- m = Jabber::Message.new(room, config.message)
151
+ m = Jabber::Message.new(room, generate_message)
152
152
  muc = MUC::MUCClient.new(client)
153
153
  if !muc.active?
154
154
  Log.logger.info("Joining room %s" % room)
@@ -156,6 +156,9 @@ module Sendxmpp
156
156
  Log.logger.info("Joined room %s" % room)
157
157
  end
158
158
  muc.send m
159
+ rescue Jabber::ServerError => e
160
+ Log.logger.error("There was an error sending this message to room %s:" % room)
161
+ Log.logger.error(e.message)
159
162
  end
160
163
 
161
164
  # Public: Send the batch out
@@ -171,5 +174,26 @@ module Sendxmpp
171
174
  receipients.delete(rcpt)
172
175
  end
173
176
  end
177
+
178
+ private
179
+
180
+ # Private: Generates a message for sending. Combines subject and message
181
+ #
182
+ # Returns the message string
183
+ def generate_message
184
+ if config.subject
185
+ msg = ""
186
+ msg << "\n"
187
+ msg << "-----------------------------------------\n"
188
+ msg << "New Message:\n"
189
+ msg << "%s\n" % config.subject
190
+ msg << config.message
191
+ msg << "\n-----------------------------------------\n"
192
+ msg
193
+ else
194
+ config.message
195
+ end
196
+
197
+ end
174
198
  end
175
199
  end
@@ -1,5 +1,5 @@
1
1
  module Sendxmpp
2
2
 
3
3
  # Public: version number
4
- VERSION="0.0.4"
4
+ VERSION="0.1.0"
5
5
  end
@@ -20,6 +20,13 @@ jid=bla@jabberdomain.example.com
20
20
  # Default: 5222
21
21
  # port=5222
22
22
 
23
+ # Default receipients. This is used if you do not want to specify them via commandline
24
+ # Default: nil
25
+ # Comma seperated list of receipients
26
+ # receipients=muc->muc@jabber.org:password,\
27
+ # user->bla@jabberdomain.example.com,\
28
+ # muc->muc2@conference.example.com
29
+
23
30
  # Server to send messages over. If no server is provided DNS SRV record from jid will be used
24
31
  # Default: ""
25
32
  # server=jabber.org
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendxmpp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Kasper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-14 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor