Class: ShadowsocksRuby::Cli::SslocalRunner
- Inherits:
-
Object
- Object
- ShadowsocksRuby::Cli::SslocalRunner
- Defined in:
- lib/shadowsocks_ruby/cli/sslocal_runner.rb
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(argv = ARGV, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = Kernel) ⇒ SslocalRunner
constructor
A new instance of SslocalRunner.
Constructor Details
#initialize(argv = ARGV, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = Kernel) ⇒ SslocalRunner
Returns a new instance of SslocalRunner.
6 7 8 9 10 11 12 |
# File 'lib/shadowsocks_ruby/cli/sslocal_runner.rb', line 6 def initialize(argv = ARGV, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = Kernel) @argv = argv $kernel = kernel $stdin = stdin $stdout = stdout $stderr = stderr end |
Instance Method Details
#execute! ⇒ Object
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/shadowsocks_ruby/cli/sslocal_runner.rb', line 14 def execute! # here sets default options = { :port => 8388, :local_addr => '0.0.0.0', :local_port => 1080, :packet_name => 'origin', :cipher_name => 'aes-256-cfb', :timeout => 300 } lazy_default = { :config => 'config.json', :obfs_name => 'http_simple' } version = ShadowsocksRuby::VERSION config_help = "path to config file (lazy default: #{lazy_default[:config]})" server_addr_help = "server address" server_port_help = "server port (default: #{[:port]})" local_addr_help = "local binding address (default: #{[:local_addr]})" local_port_help = "local port (default: default: #{[:local_port]})" password_help = "password" packet_protocol_help = "packet protocol (default: #{[:packet_name]})" packet_param_help = "packet protocol parameters" cipher_help = "cipher protocol (default: #{[:cipher_name]})" obfs_protocol_help = "obfuscate protocol (lazy default: #{lazy_default[:obfs_name]})" obfs_param_help = "obfuscate protocol parameters" timeout_help = "timeout in seconds, default: #{[:timeout]}" fast_open_help = "use TCP_FASTOPEN, requires Linux 3.7+" einhorn_help = "Use Einhorn socket manager" help_help = "display help message" version_help = "show version information" verbose_help = "verbose mode" quiet_help = "quiet mode, only show warnings/errors" get_help = "run #{File.basename($0)} -h to get help" option_parser = OptionParser.new do |op| op. = "A SOCKS like tunnel proxy that helps you bypass firewalls." op.separator "" op.separator "Usage: #{File.basename($0)} [options]" op.separator "" op.separator "Proxy options:" op.on("-c", "--config [CONFIG]", config_help) { |value| [:config] = value } op.on("-s", "--server SERVER_ADDR", server_addr_help) { |value| [:server] = value } op.on("-p", "--port SERVER_PORT", server_port_help) { |value| [:port] = value.to_i } op.on("-b", "--bind_addr LOCAL_ADDR", local_addr_help) { |value| [:local_addr] = value } op.on("-l", "--local_port LOCAL_PORT", local_port_help) { |value| [:local_port] = value.to_i } op.on("-k", "--password PASSWORD", password_help) { |value| [:password] = value } op.on("-O", "--packet-protocol NAME", packet_protocol_help) { |value| [:packet_name] = value } op.on("-G", "--packet-param PARAM", packet_param_help) { |value| [:packet_param] = value } op.on("-m", "--cipher-protocol NAME", cipher_help) { |value| [:cipher_name] = value } op.on("-o", "--obfs-protocol [NAME]", obfs_protocol_help) { |value| [:obfs_name] = value } op.on("-g", "--obfs-param PARAM", obfs_param_help) { |value| [:obfs_param] = value } op.on("-t", "--timeout TIMEOUT", timeout_help) { |value| [:timeout] = value.to_i } op.on( "--fast-open", fast_open_help) { |value| [:tcp_fast_open] = value } op.on('-E', '--einhorn', einhorn_help) { |value| @options[:einhorn] = true } op.separator "" op.separator "Common options:" op.on("-h", "--help", help_help) { puts op.to_s; $kernel.exit } op.on("-v", "--vv", verbose_help) { [:verbose] = true } op.on("-q", "--qq", quiet_help) { [:quiet] = true } op.on( "--version", version_help) { puts version; $kernel.exit } op.separator "" end begin option_parser.parse!(@argv) rescue OptionParser::MissingArgument => e $kernel.abort("#{e.}\n#{get_help}") end if .include?(:config) [:config] = 'config.json' if [:config] == nil = {} begin open([:config], 'r') do |f| = JSON.load(f, nil, {:symbolize_names => true}) end rescue Errno::ENOENT $kernel.abort("#{[:config]} doesn't exists") rescue JSON::ParserError $kernel.abort("#{[:config]} parse error") end = .merge() end if .include?(:obfs_name) [:obfs_name] = lazy_default[:obfs_name] if [:obfs_name] == nil end if !.include?(:password) $kernel.abort("--password is required\n#{get_help}") end if !.include?(:server) $kernel.abort("--server is required\n#{get_help}") end [:__client] = true App. = App.instance.run! end |