spior 0.1.5 → 0.2.8

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.github/workflows/rubocop-analysis.yml +47 -0
  4. data/.gitignore +1 -0
  5. data/CHANGELOG.md +21 -0
  6. data/Gemfile +5 -0
  7. data/README.md +27 -4
  8. data/Rakefile +21 -10
  9. data/lib/spior/dep.rb +59 -0
  10. data/lib/spior/helpers.rb +19 -19
  11. data/lib/spior/iptables/default.rb +19 -13
  12. data/lib/spior/iptables/root.rb +36 -41
  13. data/lib/spior/iptables/rules.rb +103 -0
  14. data/lib/spior/iptables/tor.rb +24 -26
  15. data/lib/spior/iptables.rb +3 -0
  16. data/lib/spior/menu.rb +16 -23
  17. data/lib/spior/msg.rb +22 -12
  18. data/lib/spior/options.rb +17 -20
  19. data/lib/spior/service/enable.rb +63 -0
  20. data/lib/spior/service/restart.rb +13 -0
  21. data/lib/spior/service/start.rb +14 -0
  22. data/lib/spior/service/stop.rb +12 -0
  23. data/lib/spior/service.rb +12 -0
  24. data/lib/spior/status.rb +32 -24
  25. data/lib/spior/tor/config.rb +100 -0
  26. data/lib/spior/tor/data.rb +53 -0
  27. data/lib/spior/tor/start.rb +59 -0
  28. data/lib/spior/tor/stop.rb +32 -0
  29. data/lib/spior/tor.rb +8 -2
  30. data/lib/spior/version.rb +3 -1
  31. data/lib/spior.rb +18 -23
  32. data/man/spior.1 +53 -0
  33. data/man/spior.1.html +122 -0
  34. data/man/spior.1.ronn +46 -0
  35. data/spior.gemspec +24 -21
  36. data/test/test_install.rb +2 -2
  37. data/test/test_options.rb +2 -0
  38. data.tar.gz.sig +0 -0
  39. metadata +67 -57
  40. metadata.gz.sig +0 -0
  41. data/lib/spior/clear.rb +0 -36
  42. data/lib/spior/copy.rb +0 -85
  43. data/lib/spior/install.rb +0 -33
  44. data/lib/spior/network.rb +0 -45
  45. data/lib/spior/persist.rb +0 -51
  46. data/lib/spior/tor/info.rb +0 -113
  47. data/lib/spior/tor/restart.rb +0 -13
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nomansland'
4
+ require 'tempfile'
5
+
6
+ module Spior
7
+ module Tor
8
+ extend self
9
+
10
+ # start should start the Tor service on your distribution
11
+ def start
12
+ tmp_file = Tempfile.new('torrc')
13
+
14
+ Tor::Config.new(tmp_file).generate
15
+
16
+ # Use Kernel.spawn here
17
+ x("tor -f #{tmp_file.path}") unless File.zero? tmp_file.path
18
+
19
+ case Nomansland.init?
20
+ when :systemd
21
+ start_systemd
22
+ when :openrc
23
+ Msg.p 'Starting Tor with Openrc...'
24
+ Helpers::Exec.new('/etc/init.d/tor').run('start')
25
+ when :runit
26
+ start_runit
27
+ else
28
+ Msg.report "Don't known yet how to start Tor for your system."
29
+ end
30
+ end
31
+
32
+ protected
33
+
34
+ def start_systemd
35
+ state = `systemctl is-active tor`.chomp
36
+ unless state == 'active'
37
+ Msg.p 'Starting Tor with Systemd...'
38
+ Helpers::Exec.new('systemctl').run('start tor')
39
+ end
40
+ end
41
+
42
+ def start_runit
43
+ Msg.p 'Starting Tor with Runit...'
44
+ if File.exist? '/var/service/tor'
45
+ Helpers::Exec.new('sv').run('start tor')
46
+ else
47
+ Helpers::Exec.new('ln').run('-s /etc/sv/tor /var/service/tor')
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def x(arg)
54
+ auth = (Process::Sys.getuid == '0' ? '' : 'sudo')
55
+ pid = spawn("#{auth} #{arg}", out: '/dev/null') or raise 'Error'
56
+ Process.wait pid
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spior
4
+ module Tor
5
+ module_function
6
+
7
+ # Stop Tor service on your distribution (linux)
8
+ # It also kill previous instance run by Spior
9
+ def stop
10
+ old_pid = `pgrep -f "tor -f /tmp/torrc*"`.chomp
11
+
12
+ if old_pid != ''
13
+ Msg.p "Found old pid > #{old_pid}, killing it..."
14
+ Helpers::Exec.new('kill').run("-9 #{old_pid}")
15
+ end
16
+
17
+ case Nomansland.init?
18
+ when :systemd
19
+ Msg.p 'Stopping Tor with Systemd...'
20
+ Helpers::Exec.new('systemctl').run('stop tor')
21
+ when :runit
22
+ Msg.p 'Stopping Tor with Runit...'
23
+ Helpers::Exec.new('sv').run('stop tor')
24
+ when :openrc
25
+ Msg.p 'Stopping Tor with Openrc...'
26
+ Helpers::Exec.new('/etc/init.d/tor').run('stop')
27
+ else
28
+ Msg.report 'Don\'t known how to stop Tor on your system.'
29
+ end
30
+ end
31
+ end
32
+ end
data/lib/spior/tor.rb CHANGED
@@ -1,7 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spior
4
+
5
+ # The module Tor interract with Tor on your system.
2
6
  module Tor
3
7
  end
4
8
  end
5
9
 
6
- require_relative 'tor/info'
7
- require_relative 'tor/restart'
10
+ require_relative 'tor/data'
11
+ require_relative 'tor/config'
12
+ require_relative 'tor/start'
13
+ require_relative 'tor/stop'
data/lib/spior/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spior
2
- VERSION = '0.1.5'.freeze
4
+ VERSION = '0.2.8'
3
5
  end
data/lib/spior.rb CHANGED
@@ -1,42 +1,37 @@
1
- require_relative 'spior/clear'
2
- require_relative 'spior/copy'
3
- require_relative 'spior/install'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'spior/dep'
4
4
  require_relative 'spior/iptables'
5
5
  require_relative 'spior/msg'
6
6
  require_relative 'spior/options'
7
7
  require_relative 'spior/status'
8
8
  require_relative 'spior/tor'
9
- require_relative 'spior/persist'
10
- require_relative 'spior/network'
11
9
  require_relative 'spior/menu'
10
+ require_relative 'spior/service'
12
11
  require_relative 'spior/helpers'
13
12
 
14
13
  module Spior
14
+ # Contain value of Tor::Data
15
+ # Can be customized, e.g:
16
+ #
17
+ # Spior::CONFIG.dns_port = '5353'
18
+ # Spior::CONFIG.trans_port = '8888'
19
+ # Spior::CONFIG.uid = '666'
20
+ # Spior::CONFIG.user = 'Tor-User-System'
21
+ # Spior::CONFIG.virt_addr = '10.192.0.0/10'
22
+ CONFIG = Tor::Data.new
23
+
15
24
  class Main
16
25
  def initialize(argv)
17
26
  @argv = argv
18
- run
27
+ x
19
28
  end
20
29
 
21
30
  private
22
31
 
23
- def run
24
- options = Options.new(@argv)
25
-
26
- if options.install
27
- Msg.head
28
- Install::check_deps
29
- Copy.new.save
30
- end
31
-
32
- if options.tor
33
- Msg.head
34
- Iptables::Tor.new.run!
35
- end
36
-
37
- if options.persist
38
- Persist.enable
39
- end
32
+ def x
33
+ Msg.banner
34
+ Options.new(@argv)
40
35
  end
41
36
  end
42
37
  end
data/man/spior.1 ADDED
@@ -0,0 +1,53 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "SPIOR" "1" "December 2021" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBspior\fR \- Redirect all traffic to the Tor network
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBspior\fR [\fIOPTIONS\fR\.\.\.]
11
+ .
12
+ .SH "DESCRIPTION"
13
+ \fBSpior\fR can redirect all the local traffic to the Tor network\.
14
+ .
15
+ .SH "OPTIONS"
16
+ .
17
+ .TP
18
+ \fB\-h\fR, \fB\-\-help\fR
19
+ Display the help and exit\.
20
+ .
21
+ .TP
22
+ \fB\-t\fR, \fB\-\-tor\fR
23
+ Spior will backup and create a new \fB/etc/tor/torrc\fR to add the required \fBtor\fR options and finally use \fBiptables\fR to create a transparent proxy throught Tor\.
24
+ .
25
+ .TP
26
+ \fB\-p\fR, \fB\-\-persist\fR
27
+ This option use \fBiptable\-save\fR to save actual rules and try to enable the service \fBiptables\fR for boot\.
28
+ .
29
+ .TP
30
+ \fB\-r\fR, \fB\-\-reload\fR
31
+ This option reload the Tor circuit which change your current ip address\. Use this option if your actual ip is blacklisted\.
32
+ .
33
+ .TP
34
+ \fB\-c\fR, \fB\-\-clearnet\fR
35
+ This option stop to redirect to Tor (by cleaning \fBiptables\fR rules) and use the normal connection\.
36
+ .
37
+ .SH "EXAMPLES"
38
+ Display the help:
39
+ .
40
+ .br
41
+ $ spior \-h
42
+ .
43
+ .P
44
+ Redirect all the traffic throught Tor:
45
+ .
46
+ .br
47
+ $ spior \-\-tor
48
+ .
49
+ .SH "SEE ALSO"
50
+ iptables(8), tor(1)
51
+ .
52
+ .SH "ISSUES"
53
+ You are free to report any new bugs|features|issues at https://github\.com/szorfein/spior/issues\.
data/man/spior.1.html ADDED
@@ -0,0 +1,122 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv='content-type' value='text/html;charset=utf8'>
5
+ <meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
6
+ <title>spior(1) - Redirect all traffic to the Tor network</title>
7
+ <style type='text/css' media='all'>
8
+ /* style: man */
9
+ body#manpage {margin:0}
10
+ .mp {max-width:100ex;padding:0 9ex 1ex 4ex}
11
+ .mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
12
+ .mp h2 {margin:10px 0 0 0}
13
+ .mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
14
+ .mp h3 {margin:0 0 0 4ex}
15
+ .mp dt {margin:0;clear:left}
16
+ .mp dt.flush {float:left;width:8ex}
17
+ .mp dd {margin:0 0 0 9ex}
18
+ .mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
19
+ .mp pre {margin-bottom:20px}
20
+ .mp pre+h2,.mp pre+h3 {margin-top:22px}
21
+ .mp h2+pre,.mp h3+pre {margin-top:5px}
22
+ .mp img {display:block;margin:auto}
23
+ .mp h1.man-title {display:none}
24
+ .mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
25
+ .mp h2 {font-size:16px;line-height:1.25}
26
+ .mp h1 {font-size:20px;line-height:2}
27
+ .mp {text-align:justify;background:#fff}
28
+ .mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
29
+ .mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
30
+ .mp u {text-decoration:underline}
31
+ .mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
32
+ .mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
33
+ .mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
34
+ .mp b.man-ref {font-weight:normal;color:#434241}
35
+ .mp pre {padding:0 4ex}
36
+ .mp pre code {font-weight:normal;color:#434241}
37
+ .mp h2+pre,h3+pre {padding-left:0}
38
+ ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
39
+ ol.man-decor {width:100%}
40
+ ol.man-decor li.tl {text-align:left}
41
+ ol.man-decor li.tc {text-align:center;letter-spacing:4px}
42
+ ol.man-decor li.tr {text-align:right;float:right}
43
+ </style>
44
+ </head>
45
+ <!--
46
+ The following styles are deprecated and will be removed at some point:
47
+ div#man, div#man ol.man, div#man ol.head, div#man ol.man.
48
+
49
+ The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
50
+ .man-navigation should be used instead.
51
+ -->
52
+ <body id='manpage'>
53
+ <div class='mp' id='man'>
54
+
55
+ <div class='man-navigation' style='display:none'>
56
+ <a href="#NAME">NAME</a>
57
+ <a href="#SYNOPSIS">SYNOPSIS</a>
58
+ <a href="#DESCRIPTION">DESCRIPTION</a>
59
+ <a href="#OPTIONS">OPTIONS</a>
60
+ <a href="#EXAMPLES">EXAMPLES</a>
61
+ <a href="#SEE-ALSO">SEE ALSO</a>
62
+ <a href="#ISSUES">ISSUES</a>
63
+ </div>
64
+
65
+ <ol class='man-decor man-head man head'>
66
+ <li class='tl'>spior(1)</li>
67
+ <li class='tc'></li>
68
+ <li class='tr'>spior(1)</li>
69
+ </ol>
70
+
71
+ <h2 id="NAME">NAME</h2>
72
+ <p class="man-name">
73
+ <code>spior</code> - <span class="man-whatis">Redirect all traffic to the Tor network</span>
74
+ </p>
75
+
76
+ <h2 id="SYNOPSIS">SYNOPSIS</h2>
77
+
78
+ <p><code>spior</code> [<var>OPTIONS</var>...]</p>
79
+
80
+ <h2 id="DESCRIPTION">DESCRIPTION</h2>
81
+
82
+ <p><strong>Spior</strong> can redirect all the local traffic to the Tor network.</p>
83
+
84
+ <h2 id="OPTIONS">OPTIONS</h2>
85
+
86
+ <dl>
87
+ <dt><code>-h</code>, <code>--help</code></dt><dd><p>Display the help and exit.</p></dd>
88
+ <dt><code>-t</code>, <code>--tor</code></dt><dd><p>Spior will backup and create a new <code>/etc/tor/torrc</code> to add the required
89
+ <code>tor</code> options and finally use <code>iptables</code> to create a transparent proxy
90
+ throught Tor.</p></dd>
91
+ <dt><code>-p</code>, <code>--persist</code></dt><dd><p>This option use <code>iptable-save</code> to save actual rules and try to enable the service <code>iptables</code> for boot.</p></dd>
92
+ <dt><code>-r</code>, <code>--reload</code></dt><dd><p>This option reload the Tor circuit which change your current ip address. Use this option if your actual ip is blacklisted.</p></dd>
93
+ <dt><code>-c</code>, <code>--clearnet</code></dt><dd><p>This option stop to redirect to Tor (by cleaning <code>iptables</code> rules) and use the normal connection.</p></dd>
94
+ </dl>
95
+
96
+
97
+ <h2 id="EXAMPLES">EXAMPLES</h2>
98
+
99
+ <p>Display the help:<br />
100
+ $ spior -h</p>
101
+
102
+ <p>Redirect all the traffic throught Tor:<br />
103
+ $ spior --tor</p>
104
+
105
+ <h2 id="SEE-ALSO">SEE ALSO</h2>
106
+
107
+ <p><span class="man-ref">iptables<span class="s">(8)</span></span>, <span class="man-ref">tor<span class="s">(1)</span></span></p>
108
+
109
+ <h2 id="ISSUES">ISSUES</h2>
110
+
111
+ <p>You are free to report any new bugs|features|issues at https://github.com/szorfein/spior/issues.</p>
112
+
113
+
114
+ <ol class='man-decor man-foot man foot'>
115
+ <li class='tl'></li>
116
+ <li class='tc'>December 2021</li>
117
+ <li class='tr'>spior(1)</li>
118
+ </ol>
119
+
120
+ </div>
121
+ </body>
122
+ </html>
data/man/spior.1.ronn ADDED
@@ -0,0 +1,46 @@
1
+ spior(1) -- Redirect all traffic to the Tor network
2
+ ====================================================
3
+
4
+ ## SYNOPSIS
5
+
6
+ `spior` [<OPTIONS>...]
7
+
8
+ ## DESCRIPTION
9
+
10
+ **Spior** can redirect all the local traffic to the Tor network.
11
+
12
+ ## OPTIONS
13
+
14
+ * `-h`, `--help`:
15
+ Display the help and exit.
16
+
17
+ * `-t`, `--tor`:
18
+ Spior will backup and create a new `/etc/tor/torrc` to add the required
19
+ `tor` options and finally use `iptables` to create a transparent proxy
20
+ throught Tor.
21
+
22
+ * `-p`, `--persist`:
23
+ This option use `iptable-save` to save actual rules and try to enable the service `iptables` for boot.
24
+
25
+ * `-r`, `--reload`:
26
+ This option reload the Tor circuit which change your current ip address. Use this option if your actual ip is blacklisted.
27
+
28
+ * `-c`, `--clearnet`:
29
+ This option stop to redirect to Tor (by cleaning `iptables` rules) and use the normal connection.
30
+
31
+ ## EXAMPLES
32
+
33
+ Display the help:<br>
34
+ $ spior -h
35
+
36
+ Redirect all the traffic throught Tor:<br>
37
+ $ spior --tor
38
+
39
+
40
+ ## SEE ALSO
41
+
42
+ iptables(8), tor(1)
43
+
44
+ ## ISSUES
45
+
46
+ You are free to report any new bugs|features|issues at https://github.com/szorfein/spior/issues.
data/spior.gemspec CHANGED
@@ -1,18 +1,20 @@
1
- require File.dirname(__FILE__) + "/lib/spior/version"
1
+ # frozen_string_literal: true
2
+
3
+ require File.dirname(__FILE__) + '/lib/spior/version'
2
4
 
3
5
  Gem::Specification.new do |s|
4
- s.name = "spior"
6
+ s.name = 'spior'
5
7
  s.version = Spior::VERSION
6
- s.summary = "A tool to make TOR your default gateway"
7
- s.description = <<-EOF
8
+ s.summary = 'A tool to make TOR your default gateway'
9
+ s.description = <<-DESC
8
10
  A tool to make TOR your default gateway
9
- EOF
11
+ DESC
10
12
  s.metadata = {
11
- "changelog_uri" => "https://github.com/szorfein/spior/blob/master/CHANGELOG.md",
12
- "bug_tracker_uri" => "https://github.com/szorfein/spior/issues",
13
- "wiki_uri" => "https://github.com/szorfein/spior"
13
+ 'changelog_uri' => 'https://github.com/szorfein/spior/blob/master/CHANGELOG.md',
14
+ 'bug_tracker_uri' => 'https://github.com/szorfein/spior/issues',
15
+ 'wiki_uri' => 'https://github.com/szorfein/spior'
14
16
  }
15
- s.author = ['szorfein']
17
+ s.author = 'szorfein'
16
18
 
17
19
  s.platform = Gem::Platform::RUBY
18
20
 
@@ -20,24 +22,25 @@ Gem::Specification.new do |s|
20
22
  s.email = 'szorfein@protonmail.com'
21
23
  s.homepage = 'https://github.com/szorfein/spior'
22
24
 
23
- s.files = `git ls-files`.split(" ")
24
- s.files.reject! { |fn| fn.include? "certs" }
25
- s.files.reject! { |fn| fn.include? "Makefile" }
26
- s.executables = [ 'spior' ]
25
+ s.files = `git ls-files`.split(' ')
26
+ s.files.reject! { |fn| fn.include? 'certs' }
27
+ s.files.reject! { |fn| fn.include? 'test' }
28
+ s.executables = ['spior']
29
+
30
+ s.extra_rdoc_files = Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt']
27
31
 
28
- s.extra_rdoc_files = Dir["README.md", "CHANGELOG.md", "LICENSE.txt"]
32
+ s.test_files = Dir['test/test_*.rb']
29
33
 
30
- s.test_files = Dir["test/test_*.rb"]
31
34
  s.cert_chain = ['certs/szorfein.pem']
32
- s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
35
+ s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
33
36
 
34
37
  s.requirements << 'tor'
35
38
  s.requirements << 'iptables'
36
39
 
37
- s.required_ruby_version = '>=2.4'
40
+ s.required_ruby_version = '>= 2.6'
38
41
 
39
- s.add_runtime_dependency('rainbow', '3.0.0')
40
- s.add_runtime_dependency('interfacez', '1.0.3')
41
- s.add_runtime_dependency('nomansland', '0.0.2')
42
- s.add_runtime_dependency('tty-which', '0.4.2')
42
+ s.add_runtime_dependency('interfacez', '~> 1.0')
43
+ s.add_runtime_dependency('nomansland', '~> 0.0')
44
+ s.add_runtime_dependency('rainbow', '~> 3.1')
45
+ s.add_runtime_dependency('tty-which', '~> 0.5')
43
46
  end
data/test/test_install.rb CHANGED
@@ -1,12 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require_relative '../lib/spior/install'
3
5
  require 'pathname'
4
6
 
5
7
  class TestInstall < Minitest::Test
6
-
7
8
  def test_sudo_is_installed
8
9
  sudo = `which sudo`
9
10
  assert_match(/sudo/, sudo, "sudo isn't installed?")
10
11
  end
11
-
12
12
  end
data/test/test_options.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require_relative '../lib/spior/options'
3
5
 
data.tar.gz.sig CHANGED
Binary file