siriproxy 0.4.4 → 0.5.0
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.
- data/Gemfile +12 -5
- data/config.example.yml +11 -0
- data/lib/siriproxy.rb +12 -3
- data/lib/siriproxy/command_line.rb +36 -13
- data/lib/siriproxy/connection.rb +9 -3
- data/lib/siriproxy/connection/iphone.rb +0 -1
- data/lib/siriproxy/dns.rb +67 -0
- data/lib/siriproxy/plugin.rb +6 -0
- data/lib/siriproxy/plugin_manager.rb +20 -11
- data/lib/siriproxy/version.rb +1 -1
- data/siriproxy.gemspec +2 -1
- metadata +21 -4
data/Gemfile
CHANGED
@@ -5,21 +5,28 @@ gemspec
|
|
5
5
|
# load plugins
|
6
6
|
require 'yaml'
|
7
7
|
require 'ostruct'
|
8
|
+
config_file = File.expand_path(File.join('~', '.siriproxy', 'config.yml'));
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
unless File.exists?(config_file)
|
11
|
+
default_config = config_file
|
12
|
+
config_file = File.expand_path(File.join(File.dirname(__FILE__), 'config.example.yml'))
|
13
|
+
puts "[Notice - Configuration] ==================== Important Configuration Notice =========================="
|
14
|
+
puts "[Notice - Configuration] '#{default_config}' not found. Using '#{config_file}'"
|
15
|
+
puts "[Notice - Configuration] "
|
16
|
+
puts "[Notice - Configuration] Remove this message by copying '#{config_file}' into '~/.siriproxy/'"
|
17
|
+
puts "[Notice - Configuration] =============================================================================="
|
12
18
|
end
|
13
19
|
|
14
20
|
gem 'cora', '0.0.4'
|
15
21
|
|
16
|
-
config = OpenStruct.new(YAML.load_file(File.expand_path(
|
22
|
+
config = OpenStruct.new(YAML.load_file(File.expand_path(config_file)))
|
17
23
|
if config.plugins
|
24
|
+
puts "[Info - Configuration] Loading plugins -- If any fail to load, run `siriproxy bundle` (not `bundle install`) to resolve."
|
18
25
|
config.plugins.each do |plugin|
|
19
26
|
if plugin.is_a? String
|
20
27
|
gem "siriproxy-#{plugin.downcase}"
|
21
28
|
else
|
22
|
-
|
29
|
+
gem "siriproxy-#{plugin['gem'] || plugin['name'].downcase}", :path => plugin['path'], :git => plugin['git'], :branch => plugin['branch'], :require => plugin['require']
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|
data/config.example.yml
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
listen: 0.0.0.0
|
2
2
|
port: 443
|
3
3
|
log_level: 1
|
4
|
+
|
5
|
+
#Create an array of DNS servers for use by internal DNS server and resolving guzzoni.apple.com
|
6
|
+
upstream_dns: [8.8.8.8, 8.8.4.4]
|
7
|
+
|
8
|
+
#Set your computer's IP for use by the internal DNS server
|
9
|
+
# server_ip: 192.168.1.100
|
10
|
+
|
11
|
+
#Set effective user when running as root. Supply a non-privileged user (such as 'nobody')
|
12
|
+
# user: nobody
|
13
|
+
|
14
|
+
|
4
15
|
plugins:
|
5
16
|
# NOTE: run bundle after changing plugin configurations to update required gems
|
6
17
|
|
data/lib/siriproxy.rb
CHANGED
@@ -13,25 +13,34 @@ class SiriProxy
|
|
13
13
|
def initialize()
|
14
14
|
# @todo shouldnt need this, make centralize logging instead
|
15
15
|
$LOG_LEVEL = $APP_CONFIG.log_level.to_i
|
16
|
+
|
16
17
|
EventMachine.run do
|
18
|
+
if Process.uid == 0 && !$APP_CONFIG.user
|
19
|
+
puts "[Notice - Server] ======================= WARNING: Running as root ============================="
|
20
|
+
puts "[Notice - Server] You should use -l or the config.yml to specify and non-root user to run under"
|
21
|
+
puts "[Notice - Server] Running the server as root is dangerous."
|
22
|
+
puts "[Notice - Server] =============================================================================="
|
23
|
+
end
|
24
|
+
|
17
25
|
begin
|
18
26
|
listen_addr = $APP_CONFIG.listen || "0.0.0.0"
|
19
|
-
puts "Starting SiriProxy on #{listen_addr}:#{$APP_CONFIG.port}.."
|
27
|
+
puts "[Info - Server] Starting SiriProxy on #{listen_addr}:#{$APP_CONFIG.port}.."
|
20
28
|
EventMachine::start_server(listen_addr, $APP_CONFIG.port, SiriProxy::Connection::Iphone, $APP_CONFIG.upstream_dns) { |conn|
|
21
29
|
puts "[Info - Guzzoni] Starting conneciton #{conn.inspect}" if $LOG_LEVEL < 1
|
22
30
|
conn.plugin_manager = SiriProxy::PluginManager.new()
|
23
31
|
conn.plugin_manager.iphone_conn = conn
|
24
32
|
}
|
25
|
-
puts "SiriProxy up and running."
|
33
|
+
puts "[Info - Server] SiriProxy up and running."
|
26
34
|
rescue RuntimeError => err
|
27
35
|
if err.message == "no acceptor"
|
28
|
-
raise "Cannot start the server on port #{$APP_CONFIG.port} - are you root, or have another process on this port already?"
|
36
|
+
raise "[Error - Server] Cannot start the server on port #{$APP_CONFIG.port} - are you root, or have another process on this port already?"
|
29
37
|
else
|
30
38
|
raise
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
34
42
|
EventMachine.set_effective_user($APP_CONFIG.user) if $APP_CONFIG.user
|
43
|
+
|
35
44
|
end
|
36
45
|
end
|
37
46
|
end
|
@@ -27,7 +27,7 @@ update [dir] Updates to the latest code from GitHub or from a provided dire
|
|
27
27
|
help Show this usage information
|
28
28
|
|
29
29
|
Options:
|
30
|
-
Option Command
|
30
|
+
Option Command Description
|
31
31
|
EOS
|
32
32
|
|
33
33
|
def initialize
|
@@ -42,6 +42,7 @@ Options:
|
|
42
42
|
when 'console' then run_console
|
43
43
|
when 'update' then update(subcommand)
|
44
44
|
when 'help' then usage
|
45
|
+
when 'dnsonly' then dns
|
45
46
|
else usage
|
46
47
|
end
|
47
48
|
end
|
@@ -97,6 +98,11 @@ Options:
|
|
97
98
|
end
|
98
99
|
|
99
100
|
def start_server
|
101
|
+
if $APP_CONFIG.server_ip
|
102
|
+
require 'siriproxy/dns'
|
103
|
+
dns_server = SiriProxy::Dns.new
|
104
|
+
dns_server.start()
|
105
|
+
end
|
100
106
|
proxy = SiriProxy.new
|
101
107
|
proxy.start()
|
102
108
|
end
|
@@ -137,6 +143,13 @@ Options:
|
|
137
143
|
end
|
138
144
|
end
|
139
145
|
|
146
|
+
def dns
|
147
|
+
require 'siriproxy/dns'
|
148
|
+
$APP_CONFIG.use_dns = true
|
149
|
+
server = SiriProxy::Dns.new
|
150
|
+
server.run(Logger::DEBUG)
|
151
|
+
end
|
152
|
+
|
140
153
|
def usage
|
141
154
|
puts "\n#{@option_parser}\n"
|
142
155
|
end
|
@@ -144,35 +157,45 @@ Options:
|
|
144
157
|
private
|
145
158
|
|
146
159
|
def parse_options
|
147
|
-
|
160
|
+
config_file = File.expand_path(File.join('~', '.siriproxy', 'config.yml'));
|
161
|
+
|
162
|
+
unless File.exists?(config_file)
|
163
|
+
default_config = config_file
|
164
|
+
config_file = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config.example.yml'))
|
165
|
+
end
|
166
|
+
|
167
|
+
$APP_CONFIG = OpenStruct.new(YAML.load_file(config_file))
|
148
168
|
|
149
169
|
# Google Public DNS servers
|
150
170
|
$APP_CONFIG.upstream_dns ||= %w[8.8.8.8 8.8.4.4]
|
151
171
|
|
152
172
|
@branch = nil
|
153
173
|
@option_parser = OptionParser.new do |opts|
|
154
|
-
opts.on('-
|
155
|
-
$APP_CONFIG.
|
174
|
+
opts.on('-d', '--dns ADDRESS', '[server] Launch DNS server guzzoni.apple.com with ADDRESS (requires root)') do |ip|
|
175
|
+
$APP_CONFIG.server_ip = ip
|
156
176
|
end
|
157
|
-
opts.on('-
|
158
|
-
$APP_CONFIG.port = port_num
|
159
|
-
end
|
160
|
-
opts.on('-l', '--log LOG_LEVEL', '[server] The level of debug information displayed (higher is more)') do |log_level|
|
177
|
+
opts.on('-l', '--log LOG_LEVEL', '[server] The level of debug information displayed (higher is more)') do |log_level|
|
161
178
|
$APP_CONFIG.log_level = log_level
|
162
179
|
end
|
163
|
-
opts.on(
|
180
|
+
opts.on('-L', '--listen ADDRESS', '[server] Address to listen on (central or node)') do |listen|
|
181
|
+
$APP_CONFIG.listen = listen
|
182
|
+
end
|
183
|
+
opts.on('-D', '--upstream-dns SERVERS', Array, '[server] List of upstream DNS servers to use. Defaults to \'[8.8.8.8, 8.8.4.4]\'') do |servers|
|
164
184
|
$APP_CONFIG.upstream_dns = servers
|
165
185
|
end
|
166
|
-
opts.on('-
|
186
|
+
opts.on('-p', '--port PORT', '[server] Port number for server (central or node)') do |port_num|
|
187
|
+
$APP_CONFIG.port = port_num
|
188
|
+
end
|
189
|
+
opts.on('-u', '--user USER', '[server] The user to run as after launch') do |user|
|
167
190
|
$APP_CONFIG.user = user
|
168
191
|
end
|
169
|
-
opts.on('-b', '--branch BRANCH',
|
192
|
+
opts.on('-b', '--branch BRANCH', '[update] Choose the branch to update from (default: master)') do |branch|
|
170
193
|
@branch = branch
|
171
194
|
end
|
172
|
-
opts.on('-n', '--name CA_NAME',
|
195
|
+
opts.on('-n', '--name CA_NAME', '[gencerts] Define a common name for the CA (default: "SiriProxyCA")') do |ca_name|
|
173
196
|
@ca_name = ca_name
|
174
197
|
end
|
175
|
-
opts.on_tail('-v', '--version', '
|
198
|
+
opts.on_tail('-v', '--version', ' Show version') do
|
176
199
|
require "siriproxy/version"
|
177
200
|
puts "SiriProxy version #{SiriProxy::VERSION}"
|
178
201
|
exit
|
data/lib/siriproxy/connection.rb
CHANGED
@@ -55,9 +55,15 @@ class SiriProxy::Connection < EventMachine::Connection
|
|
55
55
|
self.consumed_ace = true;
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
begin
|
59
|
+
process_compressed_data()
|
60
|
+
|
61
|
+
flush_output_buffer()
|
62
|
+
rescue
|
63
|
+
puts "[Info - #{self.name}] Got invalid data (non-ACE protocol?), terminating the connection."
|
64
|
+
|
65
|
+
self.close_connection
|
66
|
+
end
|
61
67
|
end
|
62
68
|
|
63
69
|
def flush_output_buffer
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'rubydns'
|
2
|
+
|
3
|
+
class SiriProxy::Dns
|
4
|
+
attr_accessor :interfaces, :upstream, :thread
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@interfaces = [
|
8
|
+
[:tcp, "0.0.0.0", 53],
|
9
|
+
[:udp, "0.0.0.0", 53]
|
10
|
+
]
|
11
|
+
|
12
|
+
servers = []
|
13
|
+
|
14
|
+
$APP_CONFIG.upstream_dns.each { |dns_addr|
|
15
|
+
servers << [:udp, dns_addr, 53]
|
16
|
+
servers << [:tcp, dns_addr, 53]
|
17
|
+
}
|
18
|
+
|
19
|
+
@upstream = RubyDNS::Resolver.new(servers)
|
20
|
+
end
|
21
|
+
|
22
|
+
def start(log_level=Logger::WARN)
|
23
|
+
@thread = Thread.new {
|
24
|
+
begin
|
25
|
+
self.run(log_level)
|
26
|
+
rescue RuntimeError => e
|
27
|
+
if e.message.match /^no acceptor/
|
28
|
+
puts "[Error - Server] You must be root to run the DNS server, DNS server is disabled"
|
29
|
+
else
|
30
|
+
puts "[Error - Server] DNS Error: #{e.message}"
|
31
|
+
puts "[Error - Server] DNS Server has crashed. Terminating SiriProxy"
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
rescue Exception => e
|
35
|
+
puts "[Error - Server] DNS Error: #{e.message}"
|
36
|
+
puts "[Error - Server] DNS Server has crashed. Terminating SiriProxy"
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def stop
|
43
|
+
Thread.kill(@thread)
|
44
|
+
end
|
45
|
+
|
46
|
+
def run(log_level=Logger::WARN,server_ip=$APP_CONFIG.server_ip)
|
47
|
+
if server_ip
|
48
|
+
upstream = @upstream
|
49
|
+
|
50
|
+
# Start the RubyDNS server
|
51
|
+
RubyDNS::run_server(:listen => @interfaces) do
|
52
|
+
@logger.level = log_level
|
53
|
+
|
54
|
+
match(/guzzoni.apple.com/, Resolv::DNS::Resource::IN::A) do |_host, transaction|
|
55
|
+
transaction.respond!(server_ip)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Default DNS handler
|
59
|
+
otherwise do |transaction|
|
60
|
+
transaction.passthrough!(upstream)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
puts "[Info - Server] DNS Server started, tainting 'guzzoni.apple.com' with #{server_ip}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/siriproxy/plugin.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'cora'
|
2
2
|
|
3
3
|
class SiriProxy::Plugin < Cora::Plugin
|
4
|
+
attr_accessor :plugin_name
|
5
|
+
|
4
6
|
def initialize(config)
|
5
7
|
|
6
8
|
end
|
@@ -55,4 +57,8 @@ class SiriProxy::Plugin < Cora::Plugin
|
|
55
57
|
self.class.filters
|
56
58
|
end
|
57
59
|
|
60
|
+
def to_s
|
61
|
+
self.plugin_name
|
62
|
+
end
|
63
|
+
|
58
64
|
end
|
@@ -12,20 +12,29 @@ class SiriProxy::PluginManager < Cora
|
|
12
12
|
@plugins = []
|
13
13
|
if $APP_CONFIG.plugins
|
14
14
|
$APP_CONFIG.plugins.each do |pluginConfig|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
begin
|
16
|
+
if pluginConfig.is_a? String
|
17
|
+
className = pluginConfig
|
18
|
+
requireName = "siriproxy-#{className.downcase}"
|
19
|
+
else
|
20
|
+
className = pluginConfig['name']
|
21
|
+
requireName = pluginConfig['require'] || "siriproxy-#{className.downcase}"
|
22
|
+
end
|
23
|
+
require requireName
|
24
|
+
plugin = SiriProxy::Plugin.const_get(className).new(pluginConfig)
|
25
|
+
plugin.plugin_name = className
|
26
|
+
plugin.manager = self
|
27
|
+
@plugins << plugin
|
28
|
+
rescue
|
29
|
+
if pluginConfig['name']
|
30
|
+
puts "[Error] Failed to load plugin: #{pluginConfig['name']}"
|
31
|
+
else
|
32
|
+
puts "[Error] Failed to load a plugin that has no name, check your config.yml"
|
33
|
+
end
|
21
34
|
end
|
22
|
-
require requireName
|
23
|
-
plugin = SiriProxy::Plugin.const_get(className).new(pluginConfig)
|
24
|
-
plugin.manager = self
|
25
|
-
@plugins << plugin
|
26
35
|
end
|
27
36
|
end
|
28
|
-
log "Plugins loaded: #{@plugins}"
|
37
|
+
log "Plugins loaded: #{@plugins.join(', ')}"
|
29
38
|
end
|
30
39
|
|
31
40
|
def process_filters(object, direction)
|
data/lib/siriproxy/version.rb
CHANGED
data/siriproxy.gemspec
CHANGED
@@ -23,7 +23,8 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_runtime_dependency "CFPropertyList", "=2.1.2"
|
24
24
|
s.add_runtime_dependency "eventmachine"
|
25
25
|
s.add_runtime_dependency "uuidtools"
|
26
|
-
s.add_runtime_dependency "cora", "
|
26
|
+
s.add_runtime_dependency "cora", "=0.0.4"
|
27
27
|
s.add_runtime_dependency "bundler"
|
28
28
|
s.add_runtime_dependency "rake"
|
29
|
+
s.add_runtime_dependency "rubydns"
|
29
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: siriproxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-03-10 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: CFPropertyList
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirement: !ruby/object:Gem::Requirement
|
67
67
|
none: false
|
68
68
|
requirements:
|
69
|
-
- -
|
69
|
+
- - '='
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: 0.0.4
|
72
72
|
type: :runtime
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
version_requirements: !ruby/object:Gem::Requirement
|
75
75
|
none: false
|
76
76
|
requirements:
|
77
|
-
- -
|
77
|
+
- - '='
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: 0.0.4
|
80
80
|
- !ruby/object:Gem::Dependency
|
@@ -109,6 +109,22 @@ dependencies:
|
|
109
109
|
- - ! '>='
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rubydns
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
type: :runtime
|
121
|
+
prerelease: false
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
112
128
|
description: Siri Proxy is a proxy server for Apple's Siri "assistant." The idea is
|
113
129
|
to allow for the creation of custom handlers for different actions. This can allow
|
114
130
|
developers to easily add functionality to Siri.
|
@@ -133,6 +149,7 @@ files:
|
|
133
149
|
- lib/siriproxy/connection.rb
|
134
150
|
- lib/siriproxy/connection/guzzoni.rb
|
135
151
|
- lib/siriproxy/connection/iphone.rb
|
152
|
+
- lib/siriproxy/dns.rb
|
136
153
|
- lib/siriproxy/interpret_siri.rb
|
137
154
|
- lib/siriproxy/plugin.rb
|
138
155
|
- lib/siriproxy/plugin_manager.rb
|