syndi 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -8
- data/Rakefile +6 -2
- data/WINDOWS.md +2 -2
- data/bin/syndi +1 -1
- data/bin/syndi-conf +1 -1
- data/ext/csyndi/libauto.c +1 -1
- data/ext/csyndi/logger.c +3 -2
- data/include/syndi/csyndi.h +3 -3
- data/include/syndi/logger.h +1 -2
- data/include/syndi.h +2 -2
- data/lib/csyndi.so +0 -0
- data/lib/syndi/bot.rb +1 -5
- data/lib/syndi/config.rb +1 -1
- data/lib/syndi/events.rb +27 -11
- data/lib/syndi/irc/protocol.rb +1 -4
- data/lib/syndi/irc/sasl/mech/dh_blowfish.rb +1 -1
- data/lib/syndi/irc/sasl/mech.rb +2 -10
- data/lib/syndi/version.rb +1 -1
- data/lib/syndi.rb +9 -1
- data/spec/helper.rb +9 -4
- data/spec/syndi/events_spec.rb +55 -9
- data/tasks/compile.rake +1 -1
- metadata +3 -8
- data/INSTALL.md +0 -86
- data/lib/syndi/api/events.rb +0 -170
- data/lib/syndi/api/plugin.rb +0 -155
- data/lib/syndi/configure/cli.rb +0 -23
- data/lib/syndi/configure/generator.rb +0 -410
- data/lib/syndi/configure.rb +0 -19
@@ -1,410 +0,0 @@
|
|
1
|
-
# Copyright (c) 2013, Autumn Perrault, et al. All rights reserved.
|
2
|
-
# This free software is distributed under the FreeBSD license (see LICENSE).
|
3
|
-
|
4
|
-
require 'colored'
|
5
|
-
require 'highline'
|
6
|
-
require 'yaml'
|
7
|
-
|
8
|
-
$S = '>>>'.blue
|
9
|
-
|
10
|
-
|
11
|
-
# Check To make sure that we have a decent ruby version. There is no reason to support a
|
12
|
-
# version that has reached EOL.
|
13
|
-
if RUBY_VERSION < "1.9"
|
14
|
-
puts <<-EOM
|
15
|
-
The version of ruby that you are using is out dated. Please upgrade to a version of at least
|
16
|
-
1.9.1 to run syndi. The ruby source code is located here http://ruby-lang.org/en/downloads
|
17
|
-
EOM
|
18
|
-
end
|
19
|
-
|
20
|
-
# namespace Syndi
|
21
|
-
module Syndi
|
22
|
-
|
23
|
-
# A library for configuration generation. It depends upon the highline gem.
|
24
|
-
#
|
25
|
-
# @version 1.02
|
26
|
-
# @author swarley
|
27
|
-
# @author noxgirl
|
28
|
-
#
|
29
|
-
# @!attribute hl
|
30
|
-
# @return [HighLine] HighLine instance.
|
31
|
-
#
|
32
|
-
# @!attribute conf
|
33
|
-
# @return [Hash{}] The configuration hash.
|
34
|
-
class Configure
|
35
|
-
|
36
|
-
syndiload :Shell, 'syndi/configure/shell'
|
37
|
-
# Load the shell.
|
38
|
-
def shell
|
39
|
-
Syndi::Configure::Shell.new(@hl)
|
40
|
-
end
|
41
|
-
|
42
|
-
VERSION = '1.02'.freeze
|
43
|
-
SYNDIDIR = File.join(Dir.home, '.config', 'syndibot')
|
44
|
-
|
45
|
-
attr_accessor :hl, :conf
|
46
|
-
|
47
|
-
# Produce a new instance of Syndi::Configure.
|
48
|
-
def initialize
|
49
|
-
|
50
|
-
# Produce a new instance of HighLine.
|
51
|
-
@hl = HighLine.new
|
52
|
-
# Prepare for configuration.
|
53
|
-
@conf = Hash.new
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
# Initiate configuration.
|
58
|
-
def generate
|
59
|
-
|
60
|
-
greeting = <<-EOM
|
61
|
-
Greetings! ^.^
|
62
|
-
|
63
|
-
I am going to assist you in configuring your installation of Syndi. :) I suggest
|
64
|
-
that, if you're not already reading it, you consult the installation guide:
|
65
|
-
https://github.com/Syndi/Syndi/wiki/Install-Guide
|
66
|
-
|
67
|
-
When specifying lists, separate elements by commas.
|
68
|
-
|
69
|
-
Remember, if you need additional help, you're free to use the mailing list at
|
70
|
-
https://groups.google.com/group/syndibot-talk, or to join the official IRC
|
71
|
-
channel at #syndi on irc.freenode.net. :)
|
72
|
-
|
73
|
-
Let us begin!
|
74
|
-
EOM
|
75
|
-
puts greeting.yellow.bold
|
76
|
-
|
77
|
-
conf_libraries
|
78
|
-
conf_database
|
79
|
-
|
80
|
-
dump
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
# Configure libraries.
|
85
|
-
def conf_libraries
|
86
|
-
puts ">>> Currently, the only available library is the IRC library. I will load this automatically.".cyan.bold
|
87
|
-
@conf['libraries'] = ['irc']
|
88
|
-
|
89
|
-
conf_irclib
|
90
|
-
end
|
91
|
-
|
92
|
-
# Configure the IRC library.
|
93
|
-
def conf_irclib
|
94
|
-
|
95
|
-
# Create the configuration hash.
|
96
|
-
@conf['irc'] = {}
|
97
|
-
|
98
|
-
# Add the first server.
|
99
|
-
conf_irc_add_server
|
100
|
-
|
101
|
-
# Add subsequent servers.
|
102
|
-
another = @hl.agree("#$S Would you like to add another IRC server? ") { |q| q.default = 'n' }
|
103
|
-
while another
|
104
|
-
conf_irc_add_server
|
105
|
-
another = @hl.agree("#$S Would you like to add another IRC server? ") { |q| q.default = 'n' }
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
# Add an IRC server.
|
111
|
-
def conf_irc_add_server
|
112
|
-
|
113
|
-
# We need a name.
|
114
|
-
name = @hl.ask("#$S What is the name of this IRC server? ")
|
115
|
-
while @conf['irc'].include? name
|
116
|
-
puts "You've already specified that server. Use a different name.".red.bold
|
117
|
-
name = @hl.ask("#$S What is the name of this IRC server?")
|
118
|
-
end
|
119
|
-
|
120
|
-
# We need an address.
|
121
|
-
address = @hl.ask("#$S What is the address of <%= color('#{name}', :blue, :bold) %>? ")
|
122
|
-
|
123
|
-
# And a port.
|
124
|
-
port = @hl.ask("#$S What is the port of <%= color('#{name}', :blue, :bold) %>? ", Integer) { |q| q.default = 6667 }
|
125
|
-
|
126
|
-
# Does it use SSL?
|
127
|
-
ssl = @hl.agree("#$S Does <%= color('#{address}:#{port}', :blue, :bold) %> use SSL? ") { |q| q.default = 'n' }
|
128
|
-
|
129
|
-
# What nickname(s) should we use?
|
130
|
-
nicks = @hl.ask("#$S What nicknames should I use on <%= color('#{name}', :blue, :bold) %> (list in descending priority)? ",
|
131
|
-
->(str) { str.split(/,\s*/) }) { |q| q.default = 'syndi' }
|
132
|
-
nicksvalid = true
|
133
|
-
nicks.each { |n| nicksvalid = false unless n =~ /^[\w\d\[\]\{\}\^\-\_\`]+$/ }
|
134
|
-
until nicksvalid
|
135
|
-
puts "You entered an invalid nickname. Try again.".red.bold
|
136
|
-
nicks = @hl.ask("#$S What nicknames should I use on <%= color('#{name}', :blue, :bold) %> (list in descending priority)? ",
|
137
|
-
->(str) { str.split(/,\s*/) }) { |q| q.default = 'syndi' }
|
138
|
-
nicksvalid = true
|
139
|
-
nicks.each { |n| nicksvalid = false unless n =~ /^[\w\d\[\]\{\}\^\-\_\`]+$/ }
|
140
|
-
end
|
141
|
-
|
142
|
-
# What username?
|
143
|
-
user = @hl.ask("#$S What username should I use on <%= color('#{name}', :blue, :bold) %>? ") { |q| q.default = 'syndi' }
|
144
|
-
|
145
|
-
# What GECOS?
|
146
|
-
gecos = @hl.ask("#$S What real name or GECOS should I use on <%= color('#{name}', :blue, :bold) %>? ") { |q| q.default = 'Syndi (http://syndi.syndiproj.org)' }
|
147
|
-
|
148
|
-
# Save the data.
|
149
|
-
@conf['irc'][name] = {
|
150
|
-
'address' => address,
|
151
|
-
'port' => port,
|
152
|
-
'useSSL' => ssl,
|
153
|
-
'nickname' => nicks,
|
154
|
-
'username' => user,
|
155
|
-
'realName' => gecos
|
156
|
-
}
|
157
|
-
|
158
|
-
# Should we use SASL?
|
159
|
-
sasl = @hl.agree("#$S Should I use SASL to authenticate with services on <%= color('#{name}', :blue, :bold) %>? ") { |q| q.default = 'n' }
|
160
|
-
|
161
|
-
if sasl
|
162
|
-
|
163
|
-
sasl_user = @hl.ask("#$S What username (i.e. accountname) should I use in SASL authentication? ")
|
164
|
-
sasl_pass = @hl.ask("#$S What is the password for <%= color('#{sasl_user}', :blue, :bold) %>? ") { |q| q.echo = false }
|
165
|
-
sasl_to = @hl.ask("#$S After how many seconds should SASL authentication time out? ", Integer) { |q| q.default = 15 }
|
166
|
-
|
167
|
-
@conf['irc'][name]['SASL'] = {
|
168
|
-
'username' => sasl_user,
|
169
|
-
'password' => sasl_pass,
|
170
|
-
'timeout' => sasl_to,
|
171
|
-
}
|
172
|
-
|
173
|
-
else
|
174
|
-
# Perhaps NickServ or some other service?
|
175
|
-
auth = @hl.agree("#$S OK. Should I identify with a service (e.g. NickServ)? ") { |q| q.default = 'n' }
|
176
|
-
|
177
|
-
if auth
|
178
|
-
|
179
|
-
service = @hl.ask("#$S What service should I message? ") { |q| q.default = 'NickServ' }
|
180
|
-
command = @hl.ask("#$S What command should I use to identify? ") { |q| q.default = 'IDENTIFY' }
|
181
|
-
password = @hl.ask("#$S What password should I use? ") { |q| q.echo = false }
|
182
|
-
|
183
|
-
@conf['irc'][name]['nickIdentify'] = {
|
184
|
-
'service' => service,
|
185
|
-
'command' => command,
|
186
|
-
'password' => password
|
187
|
-
}
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
end
|
192
|
-
|
193
|
-
# Setup syndijoin.
|
194
|
-
conf_irc_syndijoin name
|
195
|
-
|
196
|
-
end
|
197
|
-
|
198
|
-
# Configure syndijoin.
|
199
|
-
#
|
200
|
-
# @param [String] name Name of IRC server.
|
201
|
-
def conf_irc_syndijoin(name)
|
202
|
-
another = @hl.agree("#$S Should I automatically join a channel on <%= color('#{name}', :blue, :bold) %>? ") { |q| q.default = 'y' }
|
203
|
-
@conf['irc'][name]['syndijoin'] = []
|
204
|
-
|
205
|
-
while another
|
206
|
-
@conf['irc'][name]['syndijoin'] << conf_irc_add_channel
|
207
|
-
another = @hl.agree("#$S Should I automatically join another channel? ") { |q| q.default = 'n' }
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
# Add an IRC channel.
|
212
|
-
#
|
213
|
-
# @param [String] server The name of the IRC server.
|
214
|
-
def conf_irc_add_channel
|
215
|
-
|
216
|
-
# What's it called?
|
217
|
-
name = @hl.ask("#$S What is the name of the channel? ") { |q| q.default = '#syndi' }
|
218
|
-
|
219
|
-
# Does it use a key?
|
220
|
-
usekey = @hl.agree("#$S Does <%= color('#{name}', :blue, :bold) %> use a key (+k)? ") { |q| q.default = 'n' }
|
221
|
-
key = nil
|
222
|
-
|
223
|
-
if usekey
|
224
|
-
key = @hl.ask("#$S What is the key? ")
|
225
|
-
end
|
226
|
-
|
227
|
-
{'name' => name, 'key' => key}
|
228
|
-
end
|
229
|
-
|
230
|
-
# Configure the database.
|
231
|
-
def conf_database
|
232
|
-
@conf['database'] = Hash.new
|
233
|
-
|
234
|
-
msg = <<-eom
|
235
|
-
>> Syndi supports three database management systems: SQLite 3, MySQL, and Postgres.
|
236
|
-
>> If you use SQLite 3, you need the 'sqlite3' gem.
|
237
|
-
>> If you use MySQL, you need the 'mysqlplus' gem.
|
238
|
-
>> If you use Postgres, you need the 'pg' gem.
|
239
|
-
>> See https://github.com/Syndi/Syndi/wiki/Install-Guide for more information.
|
240
|
-
eom
|
241
|
-
puts msg.cyan
|
242
|
-
|
243
|
-
type = @hl.ask("#$S What database management system should I use? (sqlite, mysql, or postgres) ") do |q|
|
244
|
-
q.default = 'sqlite'
|
245
|
-
q.validate = /^(sqlite|mysql|postgres)$/
|
246
|
-
end
|
247
|
-
@conf['database']['type'] = type
|
248
|
-
|
249
|
-
if type == 'sqlite'
|
250
|
-
|
251
|
-
file = @hl.ask("#$S What should be the filename of the database? (relative to <%= color('#{SYNDIDIR}', :blue, :bold) %>) ") do |q|
|
252
|
-
q.default = File.join SYNDIDIR, 'syndi.db'
|
253
|
-
end
|
254
|
-
|
255
|
-
unless Dir.exists File.dirname(file)
|
256
|
-
puts "Warning: Directory #{File.dirname(file)} does not exist.".red.bold
|
257
|
-
end
|
258
|
-
|
259
|
-
@conf['database']['name'] = file
|
260
|
-
|
261
|
-
else # mysql and pg
|
262
|
-
|
263
|
-
address = @hl.ask("#$S What is the host address of the <%= color('#{type}', :blue, :bold) %> server? ") { |q| q.default = 'localhost' }
|
264
|
-
name = @hl.ask("#$S What is the database name on the <%= color('#{type}', :blue, :bold) %> server? ") { |q| q.default = 'syndi' }
|
265
|
-
username = @hl.ask("#$S What username should I use to connect to <%= color('#{type}', :blue, :bold) %> server? ") { |q| q.default = 'syndi' }
|
266
|
-
password = @hl.ask("#$S What is the password for <%= color('#{username}', :blue, :bold) %>? ") { |q| q.echo = false }
|
267
|
-
|
268
|
-
@conf['database'].merge!({
|
269
|
-
'address' => address,
|
270
|
-
'name' => name,
|
271
|
-
'username' => username,
|
272
|
-
'password' => password
|
273
|
-
})
|
274
|
-
|
275
|
-
end
|
276
|
-
|
277
|
-
end
|
278
|
-
|
279
|
-
# Dump configuration.
|
280
|
-
def dump
|
281
|
-
|
282
|
-
# A sanity check.
|
283
|
-
if @conf.empty?
|
284
|
-
puts "Configuration is inexplicably empty: aborting.".red.bold
|
285
|
-
exit 1
|
286
|
-
end
|
287
|
-
|
288
|
-
# Produce file.
|
289
|
-
data = <<-EOD
|
290
|
-
# Configuration file generated by syndi-conf
|
291
|
-
# version #{Syndi::Configure::VERSION}
|
292
|
-
# at #{Time.now}
|
293
|
-
|
294
|
-
#{YAML.dump(@conf)}
|
295
|
-
EOD
|
296
|
-
|
297
|
-
# Produce message.
|
298
|
-
final = <<-EOM
|
299
|
-
OK! Your configuration file is ready! :D
|
300
|
-
|
301
|
-
I just need to know one last thing: where to write this fabulous configuration.
|
302
|
-
|
303
|
-
By default, I will write this to <YOUR_HOME_DIRECTORY>/.config/syndibot/syndi.yml,
|
304
|
-
which is perfect for you if you're using the 'syndibot' gem, because this is the
|
305
|
-
standard file for which the gem will look when executed.
|
306
|
-
|
307
|
-
However, if you are running a standalone installation, you probably want to
|
308
|
-
write this to your conf/ directory as syndi.yml (if you're running #$0 from the
|
309
|
-
main directory, "conf/syndi.yml"), as the standalone Syndi will look for that
|
310
|
-
when it is executed.
|
311
|
-
|
312
|
-
In any event, you are free to write this anywhere you please. Just remember
|
313
|
-
that if it is not a default path, you must specify it when running Syndi:
|
314
|
-
|
315
|
-
$ syndi --config=path/to/config/file.yml
|
316
|
-
|
317
|
-
Caution: The specified file will be overwritten if it already exists.
|
318
|
-
EOM
|
319
|
-
puts final.green.bold
|
320
|
-
|
321
|
-
# Save our directories of interest into easily accessible variables.
|
322
|
-
configdir = File.join(Dir.home, '.config')
|
323
|
-
|
324
|
-
# Ensure that said directories exist regardless of any other conditions.
|
325
|
-
unless Dir.exists? configdir
|
326
|
-
puts "~ Creating missing directory #{configdir}".magenta
|
327
|
-
Dir.mkdir configdir
|
328
|
-
end
|
329
|
-
unless Dir.exists? SYNDIDIR
|
330
|
-
puts "~ Creating missing directory #{SYNDIDIR}".magenta
|
331
|
-
Dir.mkdir SYNDIDIR
|
332
|
-
end
|
333
|
-
|
334
|
-
# Ask for a path.
|
335
|
-
path = @hl.ask("#$S To where should the configuration be written? ", String) do |q|
|
336
|
-
|
337
|
-
# Default is ~/.config/syndibot/syndi.yml
|
338
|
-
q.default = File.join(syndidir, 'syndi.yml')
|
339
|
-
|
340
|
-
# A proc to validate the path
|
341
|
-
q.validate = proc do |path|
|
342
|
-
return false unless path =~ /\.yml$/ # it should end in .yml
|
343
|
-
return false unless Dir.exists? File.dirname(path) # the directory should exist
|
344
|
-
# We should be able to write to the file:
|
345
|
-
begin
|
346
|
-
File.open(path, 'w') { |io| io.puts "# Configuration file generated by syndi-conf" }
|
347
|
-
rescue => e
|
348
|
-
return false
|
349
|
-
end
|
350
|
-
true
|
351
|
-
end
|
352
|
-
|
353
|
-
# A proc to be called in the event of an invalid path
|
354
|
-
q.responses[:not_valid] = proc do
|
355
|
-
|
356
|
-
# Choose an emergency file in ~/.config/syndibot/ to which to save.
|
357
|
-
emerg_file = File.join(syndidir, "syndi.yml.#{Time.now.strftime('%s')}")
|
358
|
-
puts "Invalid path! Attempting to write to #{emerg_file}.....".red
|
359
|
-
File.open(path, 'w') do |io|
|
360
|
-
io.write data
|
361
|
-
end
|
362
|
-
|
363
|
-
end
|
364
|
-
|
365
|
-
end # ask()
|
366
|
-
|
367
|
-
File.open(path, 'w') { |io| io.write data } # Dump the data into the file.
|
368
|
-
|
369
|
-
# We're done.
|
370
|
-
puts "I have successfully written your configuration file to #{path}. Thank you for using Syndi.".green.bold
|
371
|
-
|
372
|
-
end
|
373
|
-
|
374
|
-
end # class Configure
|
375
|
-
|
376
|
-
end # module Syndi
|
377
|
-
|
378
|
-
# This will fix a certain undesirable output.
|
379
|
-
#
|
380
|
-
# HighLine::Question#append_default appends an ugly manifestation of the
|
381
|
-
# default answer.
|
382
|
-
#
|
383
|
-
# This destroys that provided by HighLine::Question and in lieu uses a prettier
|
384
|
-
# one.
|
385
|
-
class HighLine
|
386
|
-
class Question
|
387
|
-
def append_default
|
388
|
-
str = ''
|
389
|
-
if @default == 'y'
|
390
|
-
str = "<%= color('Y', :green) %>/<%= color('n', :red) %>"
|
391
|
-
elsif @default == 'n'
|
392
|
-
str = "<%= color('y', :green) %>/<%= color('N', :red) %>"
|
393
|
-
else
|
394
|
-
str = "<%= color('#@default', :bold) %>"
|
395
|
-
end
|
396
|
-
|
397
|
-
if @question =~ /([\t ]+)\Z/
|
398
|
-
@question << "[#{str}]#{$1}"
|
399
|
-
elsif @question == ""
|
400
|
-
@question << "[#{str}] "
|
401
|
-
elsif @question[-1, 1] == "\n"
|
402
|
-
@question[-2, 0] = " [#{str}]"
|
403
|
-
else
|
404
|
-
@question << " [#{str}]"
|
405
|
-
end
|
406
|
-
end
|
407
|
-
end
|
408
|
-
end
|
409
|
-
|
410
|
-
# vim: set ts=4 sts=2 sw=2 et:
|
data/lib/syndi/configure.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# Copyright (c) 2013, Autumn Perrault, et al. All rights reserved.
|
2
|
-
# This free software is distributed under the FreeBSD license (see LICENSE).
|
3
|
-
|
4
|
-
module Syndi
|
5
|
-
|
6
|
-
# A configuration management suite.
|
7
|
-
module Configure
|
8
|
-
|
9
|
-
# syndi-conf version
|
10
|
-
VERSION = '2.00'
|
11
|
-
|
12
|
-
syndiload :CLI, 'syndi/configure/cli'
|
13
|
-
syndiload :Generator, 'syndi/configure/generator'
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
# vim: set ts=4 sts=2 sw=2 et:
|