Skip to content
Permalink
Browse files

Big changes for 0.5.0

-Cleaned up some of the logging.
-Added some error handling.
-Improved messaging on config.yml given that you can now install from rubygems
-Improved messaging about running as root (there's a warning now).

Oh, and added a built in DNS forwarder (based on rubydns).

This means that DNSMasq is no longer needed to use SiriProxy. You can now use the `-d` option and provide your SiriProxy server's address and it will set up a DNS forwarder for you. Just point your iPhone's DNS to your forwarder and you're good to go!
  • Loading branch information...
plamoni committed Mar 10, 2013
1 parent fa99226 commit 7d71cd1442c4cd9ecdb97a0838f198d79d85753c
17 Gemfile
@@ -5,21 +5,28 @@ gemspec
# load plugins
require 'yaml'
require 'ostruct'
config_file = File.expand_path(File.join('~', '.siriproxy', 'config.yml'));

if !File.exists?(File.expand_path('~/.siriproxy/config.yml'))
$stderr.puts "config.yml not found. Copy config.example.yml to config.yml, then modify it."
exit 1
unless File.exists?(config_file)
default_config = config_file
config_file = File.expand_path(File.join(File.dirname(__FILE__), 'config.example.yml'))
puts "[Notice - Configuration] ==================== Important Configuration Notice =========================="
puts "[Notice - Configuration] '#{default_config}' not found. Using '#{config_file}'"
puts "[Notice - Configuration] "
puts "[Notice - Configuration] Remove this message by copying '#{config_file}' into '~/.siriproxy/'"
puts "[Notice - Configuration] =============================================================================="
end

gem 'cora', '0.0.4'

config = OpenStruct.new(YAML.load_file(File.expand_path('~/.siriproxy/config.yml')))
config = OpenStruct.new(YAML.load_file(File.expand_path(config_file)))
if config.plugins
puts "[Info - Configuration] Loading plugins -- If any fail to load, run `siriproxy bundle` (not `bundle install`) to resolve."
config.plugins.each do |plugin|
if plugin.is_a? String
gem "siriproxy-#{plugin.downcase}"
else
gem "siriproxy-#{plugin['gem'] || plugin['name'].downcase}", :path => plugin['path'], :git => plugin['git'], :branch => plugin['branch'], :require => plugin['require']
gem "siriproxy-#{plugin['gem'] || plugin['name'].downcase}", :path => plugin['path'], :git => plugin['git'], :branch => plugin['branch'], :require => plugin['require']
end
end
end
@@ -1,6 +1,17 @@
listen: 0.0.0.0
port: 443
log_level: 1

#Create an array of DNS servers for use by internal DNS server and resolving guzzoni.apple.com
upstream_dns: [8.8.8.8, 8.8.4.4]

#Set your computer's IP for use by the internal DNS server
# server_ip: 192.168.1.100

#Set effective user when running as root. Supply a non-privileged user (such as 'nobody')
# user: nobody


plugins:
# NOTE: run bundle after changing plugin configurations to update required gems

@@ -13,25 +13,34 @@ class SiriProxy
def initialize()
# @todo shouldnt need this, make centralize logging instead
$LOG_LEVEL = $APP_CONFIG.log_level.to_i

EventMachine.run do
if Process.uid == 0 && !$APP_CONFIG.user
puts "[Notice - Server] ======================= WARNING: Running as root ============================="
puts "[Notice - Server] You should use -l or the config.yml to specify and non-root user to run under"
puts "[Notice - Server] Running the server as root is dangerous."
puts "[Notice - Server] =============================================================================="
end

begin
listen_addr = $APP_CONFIG.listen || "0.0.0.0"
puts "Starting SiriProxy on #{listen_addr}:#{$APP_CONFIG.port}.."
puts "[Info - Server] Starting SiriProxy on #{listen_addr}:#{$APP_CONFIG.port}.."
EventMachine::start_server(listen_addr, $APP_CONFIG.port, SiriProxy::Connection::Iphone, $APP_CONFIG.upstream_dns) { |conn|
puts "[Info - Guzzoni] Starting conneciton #{conn.inspect}" if $LOG_LEVEL < 1
conn.plugin_manager = SiriProxy::PluginManager.new()
conn.plugin_manager.iphone_conn = conn
}
puts "SiriProxy up and running."
puts "[Info - Server] SiriProxy up and running."
rescue RuntimeError => err
if err.message == "no acceptor"
raise "Cannot start the server on port #{$APP_CONFIG.port} - are you root, or have another process on this port already?"
raise "[Error - Server] Cannot start the server on port #{$APP_CONFIG.port} - are you root, or have another process on this port already?"
else
raise
end
end

EventMachine.set_effective_user($APP_CONFIG.user) if $APP_CONFIG.user

end
end
end
@@ -27,7 +27,7 @@ class SiriProxy::CommandLine
help Show this usage information
Options:
Option Command Description
Option Command Description
EOS

def initialize
@@ -42,6 +42,7 @@ def initialize
when 'console' then run_console
when 'update' then update(subcommand)
when 'help' then usage
when 'dnsonly' then dns
else usage
end
end
@@ -97,6 +98,11 @@ def run_server(subcommand='start')
end

def start_server
if $APP_CONFIG.server_ip
require 'siriproxy/dns'
dns_server = SiriProxy::Dns.new
dns_server.start()
end
proxy = SiriProxy.new
proxy.start()
end
@@ -137,42 +143,59 @@ def update(directory=nil)
end
end

def dns
require 'siriproxy/dns'
$APP_CONFIG.use_dns = true
server = SiriProxy::Dns.new
server.run(Logger::DEBUG)
end

def usage
puts "\n#{@option_parser}\n"
end

private

def parse_options
$APP_CONFIG = OpenStruct.new(YAML.load_file(File.expand_path('~/.siriproxy/config.yml')))
config_file = File.expand_path(File.join('~', '.siriproxy', 'config.yml'));

unless File.exists?(config_file)
default_config = config_file
config_file = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config.example.yml'))
end

$APP_CONFIG = OpenStruct.new(YAML.load_file(config_file))

# Google Public DNS servers
$APP_CONFIG.upstream_dns ||= %w[8.8.8.8 8.8.4.4]

@branch = nil
@option_parser = OptionParser.new do |opts|
opts.on('-L', '--listen ADDRESS', '[server] address to listen on (central or node)') do |listen|
$APP_CONFIG.listen = listen
opts.on('-d', '--dns ADDRESS', '[server] Launch DNS server guzzoni.apple.com with ADDRESS (requires root)') do |ip|
$APP_CONFIG.server_ip = ip
end
opts.on('-p', '--port PORT', '[server] port number for server (central or node)') do |port_num|
$APP_CONFIG.port = port_num
end
opts.on('-l', '--log LOG_LEVEL', '[server] The level of debug information displayed (higher is more)') do |log_level|
opts.on('-l', '--log LOG_LEVEL', '[server] The level of debug information displayed (higher is more)') do |log_level|
$APP_CONFIG.log_level = log_level
end
opts.on( '--upstream-dns SERVERS', Array, '[server] List of upstream DNS servers to query for the real guzzoni.apple.com. Defaults to Google DNS servers') do |servers|
opts.on('-L', '--listen ADDRESS', '[server] Address to listen on (central or node)') do |listen|
$APP_CONFIG.listen = listen
end
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|
$APP_CONFIG.upstream_dns = servers
end
opts.on('-u', '--user USER', '[server] The user to run as after launch') do |user|
opts.on('-p', '--port PORT', '[server] Port number for server (central or node)') do |port_num|
$APP_CONFIG.port = port_num
end
opts.on('-u', '--user USER', '[server] The user to run as after launch') do |user|
$APP_CONFIG.user = user
end
opts.on('-b', '--branch BRANCH', '[update] Choose the branch to update from (default: master)') do |branch|
opts.on('-b', '--branch BRANCH', '[update] Choose the branch to update from (default: master)') do |branch|
@branch = branch
end
opts.on('-n', '--name CA_NAME', '[gencerts] Define a common name for the CA (default: "SiriProxyCA")') do |ca_name|
opts.on('-n', '--name CA_NAME', '[gencerts] Define a common name for the CA (default: "SiriProxyCA")') do |ca_name|
@ca_name = ca_name
end
opts.on_tail('-v', '--version', ' show version') do
opts.on_tail('-v', '--version', ' Show version') do
require "siriproxy/version"
puts "SiriProxy version #{SiriProxy::VERSION}"
exit
@@ -55,9 +55,15 @@ def receive_binary_data(data)
self.consumed_ace = true;
end

process_compressed_data()

flush_output_buffer()
begin
process_compressed_data()

flush_output_buffer()
rescue
puts "[Info - #{self.name}] Got invalid data (non-ACE protocol?), terminating the connection."

self.close_connection
end
end

def flush_output_buffer
@@ -5,7 +5,6 @@
#####
class SiriProxy::Connection::Iphone < SiriProxy::Connection
def initialize upstream_dns
puts "Create server for iPhone connection"
super()
self.name = "iPhone"
@upstream_dns = upstream_dns
@@ -0,0 +1,67 @@
require 'rubydns'

class SiriProxy::Dns
attr_accessor :interfaces, :upstream, :thread

def initialize
@interfaces = [
[:tcp, "0.0.0.0", 53],
[:udp, "0.0.0.0", 53]
]

servers = []

$APP_CONFIG.upstream_dns.each { |dns_addr|
servers << [:udp, dns_addr, 53]
servers << [:tcp, dns_addr, 53]
}

@upstream = RubyDNS::Resolver.new(servers)
end

def start(log_level=Logger::WARN)
@thread = Thread.new {
begin
self.run(log_level)
rescue RuntimeError => e
if e.message.match /^no acceptor/
puts "[Error - Server] You must be root to run the DNS server, DNS server is disabled"
else
puts "[Error - Server] DNS Error: #{e.message}"
puts "[Error - Server] DNS Server has crashed. Terminating SiriProxy"
exit 1
end
rescue Exception => e
puts "[Error - Server] DNS Error: #{e.message}"
puts "[Error - Server] DNS Server has crashed. Terminating SiriProxy"
exit 1
end
}
end

def stop
Thread.kill(@thread)
end

def run(log_level=Logger::WARN,server_ip=$APP_CONFIG.server_ip)
if server_ip
upstream = @upstream

# Start the RubyDNS server
RubyDNS::run_server(:listen => @interfaces) do
@logger.level = log_level

match(/guzzoni.apple.com/, Resolv::DNS::Resource::IN::A) do |_host, transaction|
transaction.respond!(server_ip)
end

# Default DNS handler
otherwise do |transaction|
transaction.passthrough!(upstream)
end
end

puts "[Info - Server] DNS Server started, tainting 'guzzoni.apple.com' with #{server_ip}"
end
end
end
@@ -1,6 +1,8 @@
require 'cora'

class SiriProxy::Plugin < Cora::Plugin
attr_accessor :plugin_name

def initialize(config)

end
@@ -55,4 +57,8 @@ def filters
self.class.filters
end

def to_s
self.plugin_name
end

end
@@ -12,20 +12,29 @@ def load_plugins()
@plugins = []
if $APP_CONFIG.plugins
$APP_CONFIG.plugins.each do |pluginConfig|
if pluginConfig.is_a? String
className = pluginConfig
requireName = "siriproxy-#{className.downcase}"
else
className = pluginConfig['name']
requireName = pluginConfig['require'] || "siriproxy-#{className.downcase}"
begin
if pluginConfig.is_a? String
className = pluginConfig
requireName = "siriproxy-#{className.downcase}"
else
className = pluginConfig['name']
requireName = pluginConfig['require'] || "siriproxy-#{className.downcase}"
end
require requireName
plugin = SiriProxy::Plugin.const_get(className).new(pluginConfig)
plugin.plugin_name = className
plugin.manager = self
@plugins << plugin
rescue
if pluginConfig['name']
puts "[Error] Failed to load plugin: #{pluginConfig['name']}"
else
puts "[Error] Failed to load a plugin that has no name, check your config.yml"
end
end
require requireName
plugin = SiriProxy::Plugin.const_get(className).new(pluginConfig)
plugin.manager = self
@plugins << plugin
end
end
log "Plugins loaded: #{@plugins}"
log "Plugins loaded: #{@plugins.join(', ')}"
end

def process_filters(object, direction)
@@ -1,3 +1,3 @@
class SiriProxy
VERSION = "0.4.4"
VERSION = "0.5.0"
end
@@ -23,7 +23,8 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "CFPropertyList", "=2.1.2"
s.add_runtime_dependency "eventmachine"
s.add_runtime_dependency "uuidtools"
s.add_runtime_dependency "cora", ">=0.0.4"
s.add_runtime_dependency "cora", "=0.0.4"
s.add_runtime_dependency "bundler"
s.add_runtime_dependency "rake"
s.add_runtime_dependency "rubydns"
end

0 comments on commit 7d71cd1

Please sign in to comment.
You can’t perform that action at this time.