thc 0.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 93c7fa9457a2fc5b67aa8b203536a758eb52f5a2
4
+ data.tar.gz: 2b67577664cf8e25de5ad4df3342677cbbfb92e0
5
+ SHA512:
6
+ metadata.gz: 97bd10fa3686c6f21cfd23e517f85fe6518fd3a1ca12a21f5e60f0402ac330443068e4dae3ea8e7a1560b400c20e765ca1edf1705a730e079498da0a9f7cf4c2
7
+ data.tar.gz: 220d41d224eb4cf9b3783c9b7f68758df10336603512f5c5122b1a8614d1179b0d2978c2fd544e9b7bf8338c7a465aaff95f51a40312d594e9c7502d1c7be6c8
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ gem "tor", "~> 0.1.2"
9
+
10
+ group :development do
11
+ gem "rdoc", "~> 3.12"
12
+ gem "bundler", "~> 1.0"
13
+ gem "jeweler", "~> 2.0.1"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,58 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ faraday (0.9.0)
9
+ multipart-post (>= 1.2, < 3)
10
+ git (1.2.8)
11
+ github_api (0.12.1)
12
+ addressable (~> 2.3)
13
+ descendants_tracker (~> 0.0.4)
14
+ faraday (~> 0.8, < 0.10)
15
+ hashie (>= 3.2)
16
+ multi_json (>= 1.7.5, < 2.0)
17
+ nokogiri (~> 1.6.3)
18
+ oauth2
19
+ hashie (3.3.1)
20
+ highline (1.6.21)
21
+ jeweler (2.0.1)
22
+ builder
23
+ bundler (>= 1.0)
24
+ git (>= 1.2.5)
25
+ github_api
26
+ highline (>= 1.6.15)
27
+ nokogiri (>= 1.5.10)
28
+ rake
29
+ rdoc
30
+ json (1.8.1)
31
+ jwt (1.0.0)
32
+ mini_portile (0.6.0)
33
+ multi_json (1.10.1)
34
+ multi_xml (0.5.5)
35
+ multipart-post (2.0.0)
36
+ nokogiri (1.6.3.1)
37
+ mini_portile (= 0.6.0)
38
+ oauth2 (1.0.0)
39
+ faraday (>= 0.8, < 0.10)
40
+ jwt (~> 1.0)
41
+ multi_json (~> 1.3)
42
+ multi_xml (~> 0.5)
43
+ rack (~> 1.2)
44
+ rack (1.5.2)
45
+ rake (10.3.2)
46
+ rdoc (3.12.2)
47
+ json (~> 1.4)
48
+ thread_safe (0.3.4)
49
+ tor (0.1.2)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler (~> 1.0)
56
+ jeweler (~> 2.0.1)
57
+ rdoc (~> 3.12)
58
+ tor (~> 0.1.2)
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org>
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ thc
2
+ ===
3
+ Tor Hidden-Service Controller - No drugs here
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "thc"
18
+ gem.homepage = "https://github.com/thez3ro/thc"
19
+ gem.license = "Unlicense"
20
+ gem.summary = %Q{Tor HiddenService Controller}
21
+ gem.description = %Q{Manage HiddenService configured in your Tor}
22
+ gem.email = "io@thezero.org"
23
+ gem.authors = ["thez3ro"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rdoc/task'
29
+ Rake::RDocTask.new do |rdoc|
30
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
31
+
32
+ rdoc.rdoc_dir = 'rdoc'
33
+ rdoc.title = "ruby-unfollow #{version}"
34
+ rdoc.rdoc_files.include('README*')
35
+ rdoc.rdoc_files.include('lib/**/*.rb')
36
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
data/bin/thc ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #Dir.chdir(File.split(__FILE__)[0])
4
+ #$LOAD_PATH << './'
5
+
6
+ require 'optparse'
7
+ require 'tor'
8
+ require 'thc'
9
+
10
+ options = {}
11
+ action = ""
12
+ help = nil
13
+ config = []
14
+
15
+ if Tor.available? then
16
+ begin
17
+ OptionParser.new do |opts|
18
+ opts.banner = "Usage: thc [options]"
19
+
20
+ opts.separator ""
21
+ opts.separator "Specific options:"
22
+
23
+ opts.on('-A', '--add DPORT,SPORT', Array, 'Add hidden service') do |port|
24
+ action = "add"
25
+ options[:dport] = port[0]
26
+ options[:sport] = port[1]
27
+ opts.on('-e ID', 'Add to existent hidden service') do |id|
28
+ options[:id] = id
29
+ end
30
+ end
31
+ opts.on('-L', '--list', 'List hidden service') do
32
+ action = "list"
33
+ end
34
+ opts.on('-D', '--delete ID', 'Delete hidden service') do |id|
35
+ action = "delete"
36
+ options[:id] = id
37
+ end
38
+ opts.on('-F FILE', String, 'torrc file') do |file|
39
+ options[:file] = file
40
+ end
41
+
42
+ opts.separator ""
43
+ opts.separator "Common options:"
44
+
45
+ # No argument, shows at tail. This will print an options summary.
46
+ # Try it and see!
47
+ opts.on_tail("-h", "--help", "Show this message") do
48
+ puts THC::NAME+" - "+THC::VERSION.green
49
+ puts opts
50
+ action = "help"
51
+ end
52
+
53
+ # Another typical switch to print the version.
54
+ opts.on_tail("--version", "Show version") do
55
+ puts THC::NAME+" - "+THC::VERSION.green
56
+ action = "version"
57
+ end
58
+
59
+ help=opts
60
+ end.parse!
61
+ rescue => e
62
+ puts "Error: ".red+e.message
63
+ end
64
+
65
+ if action == ""
66
+ puts help
67
+ else
68
+ puts "Tor version: "+Tor.version
69
+ puts "Tor folder: "+Tor.program_path
70
+ THC.load(options[:file])
71
+
72
+ case action
73
+ when "add"
74
+ # add hidden service
75
+ begin
76
+ THC::RC.add_hs(options[:dport],options[:sport],config.count+1)
77
+ puts "Hidden service added: \n["+(config.count+1).to_s+"] - Destination port: "+options[:dport]+" Source port: "+options[:sport]
78
+ puts "Restart Tor to apply the changes"
79
+ rescue Exception => e
80
+ puts "Error: ".red+e.message
81
+ end
82
+ when "list"
83
+ # list hidden service
84
+ puts THC.count.to_s+" Active Hidden service/s"
85
+ i=0
86
+ THC.service.each do |s|
87
+ puts "["+(i+1).to_s+"] Serivce at: "+s["path"]
88
+ host_file = File.expand_path("hostname", s["path"])
89
+ if File.exist?(host_file) then
90
+ hostname = File.read(host_file).chomp
91
+ puts "["+(i+1).to_s+"] - Url: http://"+hostname
92
+ end
93
+ s["service"].each do |a|
94
+ puts "["+(i+1).to_s+"] - Destination port: "+a["dport"].to_s+" Source port: "+a["sport"].to_s
95
+ end
96
+ i+=1
97
+ end
98
+ when "delete"
99
+ # delete hidden service
100
+ begin
101
+ THC::RC.rm_hs(options[:id].to_i)
102
+ puts "Hidden service deleted: ID = "+options[:id]
103
+ puts "Restart Tor to apply the changes"
104
+ rescue Exception => e
105
+ puts "Error: ".red+e.message
106
+ end
107
+ end
108
+ end
109
+ end
data/lib/thc.rb ADDED
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'colorize'
3
+ rescue Exception => e
4
+ require 'thc/color'
5
+ puts "Alert:".brown+" colorize gem don't found, fallback to thc/color"
6
+ end
7
+
8
+ require 'thc/rc'
9
+
10
+ module THC
11
+ attr_accessor :service
12
+ VERSION="0.0.2"
13
+ NAME="thc - Tor Hidden-Service Controller"
14
+ @config = []
15
+
16
+ def self.load(path)
17
+ path = if path != "" and path != nil then
18
+ path
19
+ else
20
+ RC::DEFAULT_TORRC
21
+ end
22
+ RC.init(path)
23
+ RC.load(@config)
24
+ end
25
+
26
+ def self.count()
27
+ @config.count
28
+ end
29
+
30
+ def self.service()
31
+ @config
32
+ end
33
+ end
data/lib/thc/color.rb ADDED
@@ -0,0 +1,8 @@
1
+ class String
2
+ def black; "\033[30m#{self}\033[0m" end
3
+ def red; "\033[31m#{self}\033[0m" end
4
+ def green; "\033[32m#{self}\033[0m" end
5
+ def brown; "\033[33m#{self}\033[0m" end
6
+ def blue; "\033[34m#{self}\033[0m" end
7
+ def bold; "\033[1m#{self}\033[22m" end
8
+ end
data/lib/thc/rc.rb ADDED
@@ -0,0 +1,101 @@
1
+ require 'fileutils'
2
+
3
+ module THC
4
+ class RC
5
+ DEFAULT_TORRC = "/etc/tor/torrc"
6
+ HEADER = "# THC"
7
+ @torrc = DEFAULT_TORRC
8
+
9
+ def self.init(path)
10
+ @torrc = path
11
+ y=false
12
+ File.open(@torrc, 'r') do |f|
13
+ f.each_line do |line|
14
+ if line.include?(HEADER)
15
+ y=true
16
+ end
17
+ end
18
+ end
19
+ if !y
20
+ FileUtils.cp(@torrc, @torrc+"-old")
21
+ File.open(@torrc, 'a+') do |f|
22
+ f.puts HEADER
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.load(config)
28
+ count=-1;
29
+ File.open(@torrc, 'r') do |f|
30
+ f.each_line do |line|
31
+ if line.include?("HiddenServiceDir")
32
+ config << {'path' => line.split(" ").last, 'service' => []}
33
+ count+=1;
34
+ elsif line.include?("HiddenServicePort")
35
+ config[count]['service'] << {'dport' => line.split(" ")[1].to_i, 'sport' => line.split(" ").last.split(":").last.to_i}
36
+ #puts config.to_s
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ def self.check(dp,sp)
43
+ c=-1
44
+ p=""
45
+ File.open(@torrc, 'r') do |f|
46
+ f.each_line do |line|
47
+ if (line.include?("HiddenServicePort")) && (c == -1)
48
+ if line.split(" ")[1].to_i == dp
49
+ c=dp
50
+ p="destination"
51
+ break
52
+ end
53
+ if line.split(" ").last.split(":").last.to_i == sp
54
+ c=sp
55
+ p="source"
56
+ break
57
+ end
58
+ end
59
+ end
60
+ end
61
+ return c,p
62
+ end
63
+
64
+ def self.add_hs(dport,sport,id)
65
+ c,p=RC::check(dport.to_i,sport.to_i)
66
+ if c<0
67
+ File.open(@torrc, 'a+') do |f|
68
+ f.puts "HiddenServiceDir /var/tor/.tor_hidden_"+id.to_s+"/\nHiddenServicePort "+dport+" 127.0.0.1:"+sport
69
+ end
70
+ else
71
+ raise "Hidden Service already exist on "+p+" port: "+c.to_s
72
+ end
73
+ end
74
+
75
+ def self.rm_hs(id)
76
+ y=false
77
+ c=0
78
+ File.open(@torrc+"_temp", "w") do |out_file|
79
+ File.foreach(@torrc) do |line|
80
+ if line.include?(HEADER)
81
+ y=true
82
+ out_file.puts line
83
+ elsif y && line.include?("HiddenServiceDir")
84
+ c+=1
85
+ if id != c
86
+ out_file.puts line
87
+ end
88
+ elsif y && line.include?("HiddenServicePort")
89
+ if id != c
90
+ out_file.puts line
91
+ end
92
+ else
93
+ out_file.puts line
94
+ end
95
+ end
96
+ end
97
+
98
+ FileUtils.mv(@torrc+"_temp", @torrc)
99
+ end
100
+ end
101
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - thez3ro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
69
+ description: Manage HiddenService configured in your Tor
70
+ email: io@thezero.org
71
+ executables:
72
+ - thc
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - LICENSE
76
+ - README.rdoc
77
+ files:
78
+ - .document
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE
82
+ - README.rdoc
83
+ - Rakefile
84
+ - VERSION
85
+ - bin/thc
86
+ - lib/thc.rb
87
+ - lib/thc/color.rb
88
+ - lib/thc/rc.rb
89
+ homepage: https://github.com/thez3ro/thc
90
+ licenses:
91
+ - Unlicense
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Tor HiddenService Controller
113
+ test_files: []