/
server.rb
44 lines (32 loc) · 1 KB
/
server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'drb'
require 'socket'
module Synack
class Server
DEFAULT_OPTIONS = {
host: 'localhost',
port: 11113
}
attr_reader :host, :port, :socket
# Class methods ================================================================================
def self.start(options={})
options = DEFAULT_OPTIONS.merge(options)
@host = options[:host]
@port = options[:port].to_i
@@server = Synack::Server.new
puts "Synack Server Running. Fire at will."
::DRb.start_service("druby://#{@host}:#{@port}", @@server)
::DRb.thread.join
end
def self.stop
::DRb.stop_service
end
# Instance methods =============================================================================
def sanitize(message)
message && message.gsub(/[^0-9A-z\.\-\'\, ]/, '_')
end
def say(message)
puts message
system "/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -message \"#{sanitize(message)}\""
end
end
end