2013-03-10 23:14:31 +00:00
|
|
|
#!/usr/bin/env ruby
|
2013-06-13 07:01:06 +00:00
|
|
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
2015-05-08 13:58:28 +00:00
|
|
|
# rubocop:disable Rails/TimeZone
|
|
|
|
|
2012-07-23 22:22:23 +00:00
|
|
|
$LOAD_PATH << './lib'
|
|
|
|
require 'rubygems'
|
|
|
|
require 'eventmachine'
|
|
|
|
require 'em-websocket'
|
|
|
|
require 'json'
|
|
|
|
require 'fileutils'
|
2013-08-21 18:35:22 +00:00
|
|
|
require 'sessions'
|
2012-07-23 22:22:23 +00:00
|
|
|
require 'optparse'
|
2013-03-10 23:14:31 +00:00
|
|
|
require 'daemons'
|
2012-07-23 22:22:23 +00:00
|
|
|
|
|
|
|
# Look for -o with argument, and -I and -D boolean arguments
|
2012-08-06 06:29:39 +00:00
|
|
|
@options = {
|
2015-04-27 13:42:53 +00:00
|
|
|
p: 6042,
|
|
|
|
b: '0.0.0.0',
|
|
|
|
s: false,
|
|
|
|
v: false,
|
|
|
|
d: false,
|
|
|
|
k: '/path/to/server.key',
|
|
|
|
c: '/path/to/server.crt',
|
|
|
|
i: Dir.pwd.to_s + '/tmp/pids/websocket.pid'
|
2012-07-23 22:22:23 +00:00
|
|
|
}
|
2013-03-10 23:14:31 +00:00
|
|
|
|
2012-08-02 09:30:30 +00:00
|
|
|
tls_options = {}
|
2012-07-23 22:22:23 +00:00
|
|
|
OptionParser.new do |opts|
|
2015-04-27 13:20:16 +00:00
|
|
|
opts.banner = 'Usage: websocket-server.rb start|stop [options]'
|
2012-07-23 22:22:23 +00:00
|
|
|
|
2015-04-27 13:20:16 +00:00
|
|
|
opts.on('-d', '--daemon', 'start as daemon') do |d|
|
2012-08-06 06:29:39 +00:00
|
|
|
@options[:d] = d
|
|
|
|
end
|
2015-04-27 13:20:16 +00:00
|
|
|
opts.on('-v', '--verbose', 'enable debug messages') do |d|
|
2013-03-10 23:14:31 +00:00
|
|
|
@options[:v] = d
|
|
|
|
end
|
2015-04-27 13:20:16 +00:00
|
|
|
opts.on('-p', '--port [OPT]', 'port of websocket server') do |p|
|
2012-08-06 06:29:39 +00:00
|
|
|
@options[:p] = p
|
2012-07-23 22:22:23 +00:00
|
|
|
end
|
2015-04-27 13:20:16 +00:00
|
|
|
opts.on('-b', '--bind [OPT]', 'bind address') do |b|
|
2012-08-06 06:29:39 +00:00
|
|
|
@options[:b] = b
|
2012-07-23 22:22:23 +00:00
|
|
|
end
|
2015-04-27 13:20:16 +00:00
|
|
|
opts.on('-s', '--secure', 'enable secure connections') do |s|
|
2012-08-06 06:29:39 +00:00
|
|
|
@options[:s] = s
|
2012-08-02 09:17:22 +00:00
|
|
|
end
|
2015-04-27 13:20:16 +00:00
|
|
|
opts.on('-i', '--pid [OPT]', 'pid, default is tmp/pids/websocket.pid') do |i|
|
2013-01-15 22:46:35 +00:00
|
|
|
@options[:i] = i
|
|
|
|
end
|
2015-04-27 13:20:16 +00:00
|
|
|
opts.on('-k', '--private-key [OPT]', '/path/to/server.key for secure connections') do |k|
|
2012-08-02 09:30:30 +00:00
|
|
|
tls_options[:private_key_file] = k
|
2012-08-02 09:17:22 +00:00
|
|
|
end
|
2015-04-27 13:20:16 +00:00
|
|
|
opts.on('-c', '--certificate [OPT]', '/path/to/server.crt for secure connections') do |c|
|
2012-08-02 09:30:30 +00:00
|
|
|
tls_options[:cert_chain_file] = c
|
2012-08-02 09:17:22 +00:00
|
|
|
end
|
2012-07-23 22:22:23 +00:00
|
|
|
end.parse!
|
|
|
|
|
2013-06-19 00:40:42 +00:00
|
|
|
if ARGV[0] != 'start' && ARGV[0] != 'stop'
|
2013-06-30 15:54:54 +00:00
|
|
|
puts "Usage: #{File.basename(__FILE__)} start|stop [options]"
|
2015-04-30 17:54:08 +00:00
|
|
|
exit
|
2013-06-19 00:40:42 +00:00
|
|
|
end
|
|
|
|
|
2015-07-03 15:18:01 +00:00
|
|
|
puts "Starting websocket server on #{@options[:b]}:#{@options[:p]} (secure:#{@options[:s]},pid:#{@options[:i]})"
|
2012-08-02 09:17:22 +00:00
|
|
|
#puts options.inspect
|
2012-07-23 22:22:23 +00:00
|
|
|
|
2013-03-10 23:14:31 +00:00
|
|
|
if ARGV[0] == 'stop'
|
|
|
|
|
|
|
|
# read pid
|
2015-04-27 14:41:03 +00:00
|
|
|
pid = File.open( @options[:i].to_s ).read
|
2015-04-27 13:20:16 +00:00
|
|
|
pid.gsub!(/\r|\n/, '')
|
2013-03-10 23:14:31 +00:00
|
|
|
|
|
|
|
# kill
|
|
|
|
Process.kill( 9, pid.to_i )
|
|
|
|
exit
|
|
|
|
end
|
2015-04-27 14:41:03 +00:00
|
|
|
if ARGV[0] == 'start' && @options[:d]
|
2013-03-10 23:14:31 +00:00
|
|
|
|
|
|
|
Daemons.daemonize
|
|
|
|
|
|
|
|
# create pid file
|
2015-05-08 10:47:25 +00:00
|
|
|
daemon_pid = File.new( @options[:i].to_s, 'w' )
|
|
|
|
daemon_pid.sync = true
|
|
|
|
daemon_pid.puts(Process.pid.to_s)
|
|
|
|
daemon_pid.close
|
2013-03-10 23:14:31 +00:00
|
|
|
end
|
2013-01-15 22:33:51 +00:00
|
|
|
|
2012-07-23 22:22:23 +00:00
|
|
|
@clients = {}
|
|
|
|
EventMachine.run {
|
2015-04-27 13:42:53 +00:00
|
|
|
EventMachine::WebSocket.start( host: @options[:b], port: @options[:p], secure: @options[:s], tls_options: tls_options ) do |ws|
|
2012-07-23 22:22:23 +00:00
|
|
|
|
|
|
|
# register client connection
|
|
|
|
ws.onopen {
|
2013-06-22 17:00:58 +00:00
|
|
|
client_id = ws.object_id.to_s
|
2012-08-06 06:29:39 +00:00
|
|
|
log 'notice', 'Client connected.', client_id
|
2015-04-27 13:42:53 +00:00
|
|
|
Sessions.create( client_id, {}, { type: 'websocket' } )
|
2012-07-23 22:22:23 +00:00
|
|
|
|
|
|
|
if !@clients.include? client_id
|
|
|
|
@clients[client_id] = {
|
2015-05-10 20:53:15 +00:00
|
|
|
websocket: ws,
|
|
|
|
last_ping: Time.now.utc.to_i,
|
2015-04-27 13:42:53 +00:00
|
|
|
error_count: 0,
|
2012-08-06 06:29:39 +00:00
|
|
|
}
|
2012-07-23 22:22:23 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# unregister client connection
|
|
|
|
ws.onclose {
|
2013-06-22 17:00:58 +00:00
|
|
|
client_id = ws.object_id.to_s
|
2012-08-06 06:29:39 +00:00
|
|
|
log 'notice', 'Client disconnected.', client_id
|
2012-08-04 13:35:55 +00:00
|
|
|
|
|
|
|
# removed from current client list
|
2012-07-23 22:22:23 +00:00
|
|
|
if @clients.include? client_id
|
|
|
|
@clients.delete client_id
|
|
|
|
end
|
2012-08-04 13:35:55 +00:00
|
|
|
|
2013-08-21 18:35:22 +00:00
|
|
|
Sessions.destory( client_id )
|
2012-07-23 22:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# manage messages
|
|
|
|
ws.onmessage { |msg|
|
|
|
|
|
2013-06-22 17:00:58 +00:00
|
|
|
client_id = ws.object_id.to_s
|
2015-07-03 15:18:01 +00:00
|
|
|
log 'debug', "received: #{msg} ", client_id
|
2012-08-06 06:29:39 +00:00
|
|
|
begin
|
|
|
|
data = JSON.parse(msg)
|
|
|
|
rescue => e
|
2015-07-03 15:18:01 +00:00
|
|
|
log 'error', "can't parse message: #{msg}, #{e.inspect}", client_id
|
2012-08-06 06:29:39 +00:00
|
|
|
next
|
|
|
|
end
|
2012-07-23 22:22:23 +00:00
|
|
|
|
2012-08-07 05:33:47 +00:00
|
|
|
# check if connection already exists
|
|
|
|
next if !@clients[client_id]
|
|
|
|
|
2012-11-02 16:10:22 +00:00
|
|
|
# spool messages for new connects
|
|
|
|
if data['spool']
|
2013-08-21 18:35:22 +00:00
|
|
|
Sessions.spool_create(msg)
|
2012-11-02 16:10:22 +00:00
|
|
|
end
|
|
|
|
|
2013-06-10 07:01:37 +00:00
|
|
|
# get spool messages and send them to new client connection
|
2012-11-02 16:10:22 +00:00
|
|
|
if data['action'] == 'spool'
|
2012-11-04 10:24:03 +00:00
|
|
|
|
2013-06-30 15:54:54 +00:00
|
|
|
# error handling
|
|
|
|
if data['timestamp']
|
2015-05-10 19:47:17 +00:00
|
|
|
log 'notice', "request spool data > '#{Time.at(data['timestamp']).utc.iso8601}'", client_id
|
2013-06-30 15:54:54 +00:00
|
|
|
else
|
2015-04-27 13:20:16 +00:00
|
|
|
log 'notice', 'request spool with init data', client_id
|
2013-06-30 15:54:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if @clients[client_id] && @clients[client_id][:session] && @clients[client_id][:session]['id']
|
2013-08-21 18:35:22 +00:00
|
|
|
spool = Sessions.spool_list( data['timestamp'], @clients[client_id][:session]['id'] )
|
2013-06-22 22:33:16 +00:00
|
|
|
spool.each { |item|
|
|
|
|
|
|
|
|
# create new msg to push to client
|
|
|
|
if item[:type] == 'direct'
|
2015-07-03 15:18:01 +00:00
|
|
|
log 'notice', "send spool to (user_id=#{@clients[client_id][:session]['id']})", client_id
|
2015-05-12 11:31:32 +00:00
|
|
|
websocket_send(client_id, item[:message])
|
2013-06-22 22:33:16 +00:00
|
|
|
else
|
2015-04-27 13:20:16 +00:00
|
|
|
log 'notice', 'send spool', client_id
|
2015-05-12 11:31:32 +00:00
|
|
|
websocket_send(client_id, item[:message])
|
2013-06-22 22:33:16 +00:00
|
|
|
end
|
|
|
|
}
|
2013-06-30 15:54:54 +00:00
|
|
|
else
|
|
|
|
log 'error', "can't send spool, session not authenticated", client_id
|
2013-06-22 22:33:16 +00:00
|
|
|
end
|
2013-06-02 15:56:07 +00:00
|
|
|
|
|
|
|
# send spool:sent event to client
|
2015-04-27 13:20:16 +00:00
|
|
|
log 'notice', 'send spool:sent event', client_id
|
2015-05-12 08:46:07 +00:00
|
|
|
message = {
|
|
|
|
event: 'spool:sent',
|
|
|
|
data: {
|
2015-05-12 11:31:32 +00:00
|
|
|
timestamp: Time.now.utc.to_i,
|
2015-05-12 08:46:07 +00:00
|
|
|
},
|
|
|
|
}
|
2015-05-12 11:31:32 +00:00
|
|
|
websocket_send(client_id, message)
|
2012-11-02 16:10:22 +00:00
|
|
|
end
|
|
|
|
|
2012-07-23 22:22:23 +00:00
|
|
|
# get session
|
|
|
|
if data['action'] == 'login'
|
|
|
|
@clients[client_id][:session] = data['session']
|
2015-04-27 13:42:53 +00:00
|
|
|
Sessions.create( client_id, data['session'], { type: 'websocket' } )
|
2012-08-04 13:35:55 +00:00
|
|
|
|
2013-06-13 07:01:06 +00:00
|
|
|
# remember ping, send pong back
|
2012-08-04 13:35:55 +00:00
|
|
|
elsif data['action'] == 'ping'
|
2014-07-13 21:42:36 +00:00
|
|
|
Sessions.touch(client_id)
|
2015-05-10 20:53:15 +00:00
|
|
|
@clients[client_id][:last_ping] = Time.now.utc.to_i
|
2015-05-12 08:46:07 +00:00
|
|
|
message = {
|
|
|
|
action: 'pong',
|
|
|
|
}
|
2015-05-12 11:31:32 +00:00
|
|
|
websocket_send(client_id, message)
|
2012-10-28 23:47:38 +00:00
|
|
|
|
2013-06-13 07:01:06 +00:00
|
|
|
# broadcast
|
2012-10-28 23:47:38 +00:00
|
|
|
elsif data['action'] == 'broadcast'
|
2012-11-04 10:24:03 +00:00
|
|
|
|
|
|
|
# list all current clients
|
2013-08-21 18:35:22 +00:00
|
|
|
client_list = Sessions.list
|
2012-11-27 00:59:46 +00:00
|
|
|
client_list.each {|local_client_id, local_client|
|
2013-06-22 17:00:58 +00:00
|
|
|
if local_client_id != client_id
|
2013-06-28 22:26:04 +00:00
|
|
|
|
2012-11-04 10:24:03 +00:00
|
|
|
# broadcast to recipient list
|
2013-06-28 22:26:04 +00:00
|
|
|
if data['recipient']
|
|
|
|
if data['recipient'].class != Hash
|
2015-07-03 15:18:01 +00:00
|
|
|
log 'error', "recipient attribute isn't a hash '#{data['recipient'].inspect}'"
|
2013-05-10 09:33:17 +00:00
|
|
|
else
|
2015-04-30 17:34:33 +00:00
|
|
|
if !data['recipient'].key?('user_id')
|
2015-07-03 15:18:01 +00:00
|
|
|
log 'error', "need recipient.user_id attribute '#{data['recipient'].inspect}'"
|
2013-05-10 09:33:17 +00:00
|
|
|
else
|
2013-06-28 22:26:04 +00:00
|
|
|
if data['recipient']['user_id'].class != Array
|
2015-07-03 15:18:01 +00:00
|
|
|
log 'error', "recipient.user_id attribute isn't an array '#{data['recipient']['user_id'].inspect}'"
|
2012-11-27 00:59:46 +00:00
|
|
|
else
|
2013-06-28 22:26:04 +00:00
|
|
|
data['recipient']['user_id'].each { |user_id|
|
2015-05-07 09:04:40 +00:00
|
|
|
|
|
|
|
next if local_client[:user]['id'].to_i != user_id.to_i
|
|
|
|
|
|
|
|
log 'notice', "send broadcast from (#{client_id}) to (user_id=#{user_id})", local_client_id
|
|
|
|
if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
|
2015-05-12 11:31:32 +00:00
|
|
|
websocket_send(local_client_id, data)
|
2015-05-07 09:04:40 +00:00
|
|
|
else
|
2015-05-12 08:46:07 +00:00
|
|
|
Sessions.send(local_client_id, data)
|
2013-05-10 09:33:17 +00:00
|
|
|
end
|
|
|
|
}
|
2012-11-27 00:59:46 +00:00
|
|
|
end
|
2012-11-04 10:24:03 +00:00
|
|
|
end
|
2013-05-10 09:33:17 +00:00
|
|
|
end
|
2012-11-27 00:59:46 +00:00
|
|
|
|
2013-06-13 07:01:06 +00:00
|
|
|
# broadcast every client
|
2012-11-04 10:24:03 +00:00
|
|
|
else
|
2015-05-06 09:30:39 +00:00
|
|
|
log 'notice', "send broadcast from (#{client_id})", local_client_id
|
2012-11-27 00:59:46 +00:00
|
|
|
if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
|
2015-05-12 11:31:32 +00:00
|
|
|
websocket_send(local_client_id, data)
|
2012-11-27 00:59:46 +00:00
|
|
|
else
|
2015-05-12 08:46:07 +00:00
|
|
|
Sessions.send(local_client_id, data)
|
2012-11-27 00:59:46 +00:00
|
|
|
end
|
2012-11-04 10:24:03 +00:00
|
|
|
end
|
2013-06-11 06:18:18 +00:00
|
|
|
else
|
2015-04-27 13:20:16 +00:00
|
|
|
log 'notice', 'do not send broadcast to it self', client_id
|
2012-10-28 23:47:38 +00:00
|
|
|
end
|
|
|
|
}
|
2012-08-04 13:35:55 +00:00
|
|
|
end
|
2012-07-23 22:22:23 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2013-02-01 00:06:33 +00:00
|
|
|
# check unused connections
|
|
|
|
EventMachine.add_timer(0.5) {
|
|
|
|
check_unused_connections
|
|
|
|
}
|
|
|
|
|
2012-11-27 00:59:46 +00:00
|
|
|
# check open unused connections, kick all connection without activitie in the last 2 minutes
|
2012-08-06 06:29:39 +00:00
|
|
|
EventMachine.add_periodic_timer(120) {
|
2012-12-24 13:53:50 +00:00
|
|
|
check_unused_connections
|
2012-08-06 06:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EventMachine.add_periodic_timer(20) {
|
2012-11-26 05:04:44 +00:00
|
|
|
|
|
|
|
# websocket
|
2015-07-03 15:18:01 +00:00
|
|
|
log 'notice', "Status: websocket clients: #{@clients.size}"
|
2015-05-07 09:49:46 +00:00
|
|
|
@clients.each { |client_id, _client|
|
2012-08-06 06:29:39 +00:00
|
|
|
log 'notice', 'working...', client_id
|
|
|
|
}
|
2012-11-26 05:04:44 +00:00
|
|
|
|
|
|
|
# ajax
|
2013-08-21 18:35:22 +00:00
|
|
|
client_list = Sessions.list
|
2012-11-26 05:04:44 +00:00
|
|
|
clients = 0
|
2015-05-07 09:49:46 +00:00
|
|
|
client_list.each {|_client_id, client|
|
2012-11-26 05:04:44 +00:00
|
|
|
next if client[:meta][:type] == 'websocket'
|
|
|
|
clients = clients + 1
|
|
|
|
}
|
2015-07-03 15:18:01 +00:00
|
|
|
log 'notice', "Status: ajax clients: #{clients}"
|
2012-11-26 05:04:44 +00:00
|
|
|
client_list.each {|client_id, client|
|
|
|
|
next if client[:meta][:type] == 'websocket'
|
|
|
|
log 'notice', 'working...', client_id
|
|
|
|
}
|
|
|
|
|
2012-08-06 06:29:39 +00:00
|
|
|
}
|
|
|
|
|
2012-11-02 16:10:22 +00:00
|
|
|
EventMachine.add_periodic_timer(0.4) {
|
2012-08-06 06:29:39 +00:00
|
|
|
next if @clients.size == 0
|
2015-05-12 08:46:07 +00:00
|
|
|
#log 'debug', 'checking for data to send...'
|
2012-07-23 22:22:23 +00:00
|
|
|
@clients.each { |client_id, client|
|
2012-08-07 05:33:47 +00:00
|
|
|
next if client[:disconnect]
|
2012-08-06 06:29:39 +00:00
|
|
|
log 'debug', 'checking for data...', client_id
|
2012-07-23 22:22:23 +00:00
|
|
|
begin
|
2013-08-21 18:35:22 +00:00
|
|
|
queue = Sessions.queue( client_id )
|
2012-07-23 22:22:23 +00:00
|
|
|
if queue && queue[0]
|
2015-04-27 13:20:16 +00:00
|
|
|
log 'notice', 'send data to client', client_id
|
2015-05-12 11:31:32 +00:00
|
|
|
websocket_send(client_id, queue)
|
2012-07-23 22:22:23 +00:00
|
|
|
end
|
2012-08-03 22:46:05 +00:00
|
|
|
rescue => e
|
2012-08-06 06:29:39 +00:00
|
|
|
|
|
|
|
log 'error', 'problem:' + e.inspect, client_id
|
|
|
|
|
|
|
|
# disconnect client
|
2012-08-07 05:33:47 +00:00
|
|
|
client[:error_count] += 1
|
2013-06-22 17:00:58 +00:00
|
|
|
if client[:error_count] > 20
|
2012-08-07 05:33:47 +00:00
|
|
|
if @clients.include? client_id
|
|
|
|
@clients.delete client_id
|
|
|
|
end
|
2012-08-06 06:29:39 +00:00
|
|
|
end
|
2012-07-23 22:22:23 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|
2012-11-02 16:10:22 +00:00
|
|
|
|
2015-05-12 11:31:32 +00:00
|
|
|
def websocket_send(client_id, data)
|
|
|
|
if data.class != Array
|
|
|
|
msg = "[#{data.to_json}]"
|
|
|
|
else
|
|
|
|
msg = data.to_json
|
|
|
|
end
|
2015-05-12 08:46:07 +00:00
|
|
|
log 'debug', "send #{msg}", client_id
|
|
|
|
if !@clients[client_id]
|
|
|
|
log 'error', "no such @clients for #{client_id}", client_id
|
|
|
|
return
|
|
|
|
end
|
2015-05-12 11:31:32 +00:00
|
|
|
@clients[client_id][:websocket].send(msg)
|
2015-05-12 08:46:07 +00:00
|
|
|
end
|
|
|
|
|
2012-12-24 13:53:50 +00:00
|
|
|
def check_unused_connections
|
2015-04-27 13:20:16 +00:00
|
|
|
log 'notice', 'check unused idle connections...'
|
2012-12-24 13:53:50 +00:00
|
|
|
|
2015-02-25 22:17:34 +00:00
|
|
|
idle_time_in_sec = 4 * 60
|
2012-12-24 13:53:50 +00:00
|
|
|
|
2015-01-13 16:03:58 +00:00
|
|
|
# close unused web socket sessions
|
2012-12-24 13:53:50 +00:00
|
|
|
@clients.each { |client_id, client|
|
|
|
|
|
2015-05-10 20:53:15 +00:00
|
|
|
next if ( client[:last_ping].to_i + idle_time_in_sec ) >= Time.now.utc.to_i
|
2012-12-24 13:53:50 +00:00
|
|
|
|
2015-05-07 09:04:40 +00:00
|
|
|
log 'notice', 'closing idle websocket connection', client_id
|
2012-12-24 13:53:50 +00:00
|
|
|
|
2015-05-07 09:04:40 +00:00
|
|
|
# remember to not use this connection anymore
|
|
|
|
client[:disconnect] = true
|
|
|
|
|
|
|
|
# try to close regular
|
|
|
|
client[:websocket].close_websocket
|
|
|
|
|
|
|
|
# delete session from client list
|
|
|
|
sleep 0.3
|
|
|
|
@clients.delete(client_id)
|
2012-12-24 13:53:50 +00:00
|
|
|
}
|
|
|
|
|
2015-01-13 16:03:58 +00:00
|
|
|
# close unused ajax long polling sessions
|
2015-02-25 22:17:34 +00:00
|
|
|
clients = Sessions.destory_idle_sessions(idle_time_in_sec)
|
2014-06-27 06:43:37 +00:00
|
|
|
clients.each { |client_id|
|
2015-04-27 13:20:16 +00:00
|
|
|
log 'notice', 'closing idle long polling connection', client_id
|
2012-12-24 13:53:50 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2012-08-06 06:29:39 +00:00
|
|
|
def log( level, data, client_id = '-' )
|
2013-03-10 23:14:31 +00:00
|
|
|
if !@options[:v]
|
2012-08-06 06:29:39 +00:00
|
|
|
return if level == 'debug'
|
|
|
|
end
|
2015-07-03 15:18:01 +00:00
|
|
|
puts "#{Time.now.utc.iso8601}:client(#{client_id}) #{data}"
|
2015-05-12 08:46:07 +00:00
|
|
|
#puts "#{Time.now.utc.iso8601}:#{ level }:client(#{ client_id }) #{ data }"
|
2012-08-03 22:46:05 +00:00
|
|
|
end
|
2012-07-23 22:22:23 +00:00
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
}
|