tor-control 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in peekaboo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alex Smith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,24 @@
1
+ = tor-control
2
+
3
+ http://fury-badge.herokuapp.com/rb/tor-control.png
4
+
5
+ {<img src="https://travis-ci.org/aosmith/tor-control.png?branch=master" />}[https://travis-ci.org/aosmith/tor-control?branch=master]
6
+
7
+ == Usage
8
+
9
+ Mantra-tor depends upon a running tor instance.
10
+
11
+ A Singleton variable is used to interact with the tor instance:
12
+
13
+ TorControl.password = "password"
14
+ TorControl.host = "localhost"
15
+ TorControl.port = 9051
16
+ TorControl.connect
17
+ TorControl.authenticate
18
+ TorControl.new_identity
19
+ TorControl.close
20
+
21
+ I use socksify[https://rubygems.org/gems/socksify] to proxy my tcp connections:
22
+
23
+ TCPSocket::socks_server = "127.0.0.1"
24
+ TCPSocket::socks_port = 9050
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'MantraPresenters'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+
29
+ require 'rspec/core/rake_task'
30
+
31
+ RSpec::Core::RakeTask.new(:spec)
32
+
33
+
34
+ #require 'rake/testtask'
35
+
36
+ #Rake::TestTask.new(:test) do |t|
37
+ # t.libs << 'lib'
38
+ # t.libs << 'test'
39
+ # t.pattern = 'spec/**/*_test.rb'
40
+ # t.verbose = false
41
+ #end
42
+
43
+
44
+ task :default => :spec
45
+
@@ -0,0 +1,3 @@
1
+ module TorControl
2
+ VERSION = "0.0.5"
3
+ end
@@ -0,0 +1,92 @@
1
+ require 'tor-control/version'
2
+ require 'socket'
3
+ require 'logger'
4
+
5
+ module TorControl
6
+ @host = 'localhost'
7
+ @control_port = 9051
8
+ @connection = false
9
+ @password = false
10
+ @logger = false
11
+ class << self
12
+ attr_accessor :connection, :host, :control_port, :password
13
+
14
+ def configure(options={})
15
+ if options[:host]
16
+ @host = options[:host].to_s
17
+ end
18
+ if options[:control_port]
19
+ @port = options[:control_port].to_i
20
+ end
21
+ end
22
+
23
+ def new_identity
24
+ connect
25
+ authenticate
26
+ signal_new_identity
27
+ close
28
+ end
29
+
30
+ def logger
31
+ return @logger if @logger
32
+ @logger = Logger.new(STDERR)
33
+ end
34
+
35
+ def connect
36
+ return @connection if @connection
37
+ # begin
38
+ @connection = TCPSocket.new(@host, @control_port)
39
+ # rescue
40
+ #logger.error "TorControl: Failed to connection to tor service"
41
+ # end
42
+ end
43
+
44
+ def signal_new_identity
45
+ check_connection
46
+ send_line "SIGNAL NEWNYM"
47
+ check_response { logger.error "TorControl: Error getting new indentity" }
48
+ end
49
+
50
+ def authenticate
51
+ check_connection
52
+ if @password
53
+ send_line "AUTHENTICATE \"#{@password}\""
54
+ else
55
+ send_line "AUTHENTICATE"
56
+ end
57
+ check_response { logger.error "Tor Control: Authentication Failure!" }
58
+ end
59
+
60
+ def close
61
+ check_connection
62
+ send_line "QUIT"
63
+ not @connection = false
64
+ end
65
+
66
+ private
67
+
68
+ def send_line command
69
+ check_connection
70
+ @connection.write command.to_s + "\r\n"
71
+ @connection.flush
72
+ end
73
+
74
+ def read_line
75
+ check_connection
76
+ @connection.readline.chomp
77
+ end
78
+
79
+ def check_connection
80
+ raise "Not connected" unless @connection
81
+ true
82
+ end
83
+
84
+ def check_response(&block)
85
+ unless read_line == "250 OK"
86
+ block.call
87
+ end
88
+ true
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'tor-control'
5
+
6
+
7
+ RSpec.configure do |config|
8
+
9
+ end
10
+
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'stub' do
4
+ it 'should pass' do
5
+ # pass
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tor-control/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tor-control"
8
+ spec.version = TorControl::VERSION
9
+ spec.authors = ["Alex Smith"]
10
+ spec.email = ["aosmith@gmail.com"]
11
+ spec.description = %q{A tor control gem.}
12
+ spec.summary = %q{Hide behind the onion!}
13
+ spec.homepage = "http://alexsmith.io/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "rspec", "~> 2.13.0"
25
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tor-control
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.13.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.13.0
78
+ description: A tor control gem.
79
+ email:
80
+ - aosmith@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.rdoc
89
+ - Rakefile
90
+ - lib/tor-control.rb
91
+ - lib/tor-control/version.rb
92
+ - spec/spec_helper.rb
93
+ - spec/tor_config_spec.rb
94
+ - tor-control.gemspec
95
+ homepage: http://alexsmith.io/
96
+ licenses:
97
+ - MIT
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.25
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Hide behind the onion!
120
+ test_files:
121
+ - spec/spec_helper.rb
122
+ - spec/tor_config_spec.rb
123
+ has_rdoc: