spior 0.1.6 → 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.
@@ -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,6 +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'
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.6'.freeze
4
+ VERSION = '0.2.8'
3
5
  end
data/lib/spior.rb CHANGED
@@ -1,44 +1,37 @@
1
- require_relative 'spior/clear'
2
- require_relative 'spior/copy'
1
+ # frozen_string_literal: true
2
+
3
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
9
  require_relative 'spior/menu'
11
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
- Dep.install
29
- Copy.new.save
30
- end
31
-
32
- Dep.check
33
-
34
- if options.tor
35
- Msg.head
36
- Iptables::Tor.new.run!
37
- end
38
-
39
- if options.persist
40
- Persist.enable
41
- end
32
+ def x
33
+ Msg.banner
34
+ Options.new(@argv)
42
35
  end
43
36
  end
44
37
  end
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.5'
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.3')
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spior
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - szorfein
@@ -10,89 +10,90 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIETTCCArWgAwIBAgIBATANBgkqhkiG9w0BAQsFADAoMSYwJAYDVQQDDB1zem9y
14
- ZmVpbi9EQz1wcm90b25tYWlsL0RDPWNvbTAeFw0yMTA1MTEyMTAzNDZaFw0yMjA1
15
- MTEyMTAzNDZaMCgxJjAkBgNVBAMMHXN6b3JmZWluL0RDPXByb3Rvbm1haWwvREM9
16
- Y29tMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAxCTYZRndCTRy18rE
17
- exr2wig/staa0G5kt99xqaBYD0dnIRBr/GO5dFntlBVwmefQlTrNbygVUIYTb8Vg
18
- B1oX3v/LLW9SRQcWaZwou0tARqanm5WhgV1ZYQTs22endTazsDHw0uhM3V+FgDh+
19
- eR5wM9vU+SkRFHWzjVS1OxyTSCBVWb3+nrYTr/OKZ5Fm3Vo1dEQdwBEWLLXuUBxs
20
- dWEDmBk7iTJbvNdd5Kk2wfMKRMOl9NGicJl3Cb5yl5ITeZsXdOsrLBBPepTpNeq2
21
- k1goew3mEd/4pVXrdw6S5Qr6RTbTCLpKNRxWtx01vue9NN1cQ/Ds5FRkCp/Ntw/k
22
- Xroyofo4MW5fEPq+udgvVpdTfguQkpmuJg7TRiq9F5hDhEMnKUsdM2fSev9u8EvL
23
- OkidKy8bnhUOoG9qDxEG/I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nsXZWsXtRQ119LeAvrI2A+xmYAb
32
+ FPE5bD3Jx1JCoJdVN1DmE4YYdM8mVmb0XjCK9Tp1M01EDKDvAX7f3B+X6A5D7uBq
33
+ 63X6Kx09VkntVOrifd3W4TwjDlyAMpB+50OIi3ErPnH2R4i09qnCiZmcVWATBVKw
34
+ e2QSloIAUZJwEFkrRqWPNVi8sr+BcMeuKpXaOwpbkP+xq/W2EKlUQKhPXMXS4jvC
35
+ MuTi+RjpSNKZxzBrOlK2eMIpiFrugF7nzKcM9EGnWRWUb899drCcD4VJhjPtgpn+
36
+ aEJeKq4/BlIwMlXPe+W5C8zp2i8hgG1/OYbwbGE1p2iRi1NIK7G/HyRqQjOqJxzE
37
+ LLknX69FN7/G
37
38
  -----END CERTIFICATE-----
38
- date: 2021-12-30 00:00:00.000000000 Z
39
+ date: 2022-09-16 00:00:00.000000000 Z
39
40
  dependencies:
40
41
  - !ruby/object:Gem::Dependency
41
- name: rainbow
42
+ name: interfacez
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - '='
45
+ - - "~>"
45
46
  - !ruby/object:Gem::Version
46
- version: 3.0.0
47
+ version: '1.0'
47
48
  type: :runtime
48
49
  prerelease: false
49
50
  version_requirements: !ruby/object:Gem::Requirement
50
51
  requirements:
51
- - - '='
52
+ - - "~>"
52
53
  - !ruby/object:Gem::Version
53
- version: 3.0.0
54
+ version: '1.0'
54
55
  - !ruby/object:Gem::Dependency
55
- name: interfacez
56
+ name: nomansland
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
- - - '='
59
+ - - "~>"
59
60
  - !ruby/object:Gem::Version
60
- version: 1.0.3
61
+ version: '0.0'
61
62
  type: :runtime
62
63
  prerelease: false
63
64
  version_requirements: !ruby/object:Gem::Requirement
64
65
  requirements:
65
- - - '='
66
+ - - "~>"
66
67
  - !ruby/object:Gem::Version
67
- version: 1.0.3
68
+ version: '0.0'
68
69
  - !ruby/object:Gem::Dependency
69
- name: nomansland
70
+ name: rainbow
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
- - - '='
73
+ - - "~>"
73
74
  - !ruby/object:Gem::Version
74
- version: 0.0.3
75
+ version: '3.1'
75
76
  type: :runtime
76
77
  prerelease: false
77
78
  version_requirements: !ruby/object:Gem::Requirement
78
79
  requirements:
79
- - - '='
80
+ - - "~>"
80
81
  - !ruby/object:Gem::Version
81
- version: 0.0.3
82
+ version: '3.1'
82
83
  - !ruby/object:Gem::Dependency
83
84
  name: tty-which
84
85
  requirement: !ruby/object:Gem::Requirement
85
86
  requirements:
86
- - - '='
87
+ - - "~>"
87
88
  - !ruby/object:Gem::Version
88
- version: 0.4.2
89
+ version: '0.5'
89
90
  type: :runtime
90
91
  prerelease: false
91
92
  version_requirements: !ruby/object:Gem::Requirement
92
93
  requirements:
93
- - - '='
94
+ - - "~>"
94
95
  - !ruby/object:Gem::Version
95
- version: 0.4.2
96
+ version: '0.5'
96
97
  description: " A tool to make TOR your default gateway\n"
97
98
  email: szorfein@protonmail.com
98
99
  executables:
@@ -102,8 +103,10 @@ extra_rdoc_files:
102
103
  - README.md
103
104
  - CHANGELOG.md
104
105
  files:
106
+ - ".github/workflows/rubocop-analysis.yml"
105
107
  - ".gitignore"
106
108
  - CHANGELOG.md
109
+ - Gemfile
107
110
  - LICENSE
108
111
  - README.md
109
112
  - Rakefile
@@ -111,24 +114,27 @@ files:
111
114
  - ext/ipt_mod.conf
112
115
  - ext/iptables.service
113
116
  - lib/spior.rb
114
- - lib/spior/clear.rb
115
- - lib/spior/copy.rb
116
117
  - lib/spior/dep.rb
117
118
  - lib/spior/helpers.rb
118
119
  - lib/spior/iptables.rb
119
120
  - lib/spior/iptables/default.rb
120
121
  - lib/spior/iptables/root.rb
122
+ - lib/spior/iptables/rules.rb
121
123
  - lib/spior/iptables/tor.rb
122
124
  - lib/spior/menu.rb
123
125
  - lib/spior/msg.rb
124
126
  - lib/spior/options.rb
125
- - lib/spior/persist.rb
126
127
  - lib/spior/service.rb
128
+ - lib/spior/service/enable.rb
127
129
  - lib/spior/service/restart.rb
128
130
  - lib/spior/service/start.rb
131
+ - lib/spior/service/stop.rb
129
132
  - lib/spior/status.rb
130
133
  - lib/spior/tor.rb
131
- - lib/spior/tor/info.rb
134
+ - lib/spior/tor/config.rb
135
+ - lib/spior/tor/data.rb
136
+ - lib/spior/tor/start.rb
137
+ - lib/spior/tor/stop.rb
132
138
  - lib/spior/version.rb
133
139
  - man/spior.1
134
140
  - man/spior.1.html
@@ -151,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
157
  requirements:
152
158
  - - ">="
153
159
  - !ruby/object:Gem::Version
154
- version: '2.5'
160
+ version: '2.6'
155
161
  required_rubygems_version: !ruby/object:Gem::Requirement
156
162
  requirements:
157
163
  - - ">="
@@ -160,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
166
  requirements:
161
167
  - tor
162
168
  - iptables
163
- rubygems_version: 3.2.32
169
+ rubygems_version: 3.3.19
164
170
  signing_key:
165
171
  specification_version: 4
166
172
  summary: A tool to make TOR your default gateway
metadata.gz.sig CHANGED
Binary file
data/lib/spior/clear.rb DELETED
@@ -1,35 +0,0 @@
1
- require 'nomansland'
2
-
3
- module Spior
4
- module Clear
5
- extend self
6
-
7
- def all
8
- iptables
9
- Spior::Copy.new.restore
10
- end
11
-
12
- private
13
-
14
- def iptables
15
- puts "Clearing rules.."
16
- ipt = Spior::Iptables::Default.new
17
- ipt.stop!
18
- #if File.exist?("/var/lib/iptables/rules-save")
19
- # ipt_restore "/var/lib/iptables/rules-save"
20
- #elsif File.exist?("/etc/iptables/rules.save")
21
- # ipt_restore "/etc/iptables/iptables.rules"
22
- #elsif File.exist?("/etc/iptables.rules")
23
- # ipt_restore "/etc/iptables.rules"
24
- #else
25
- #Msg.p "Couldn't find any previous rules for iptables, create basic rules..."
26
- ipt.run!
27
- #end
28
- end
29
-
30
- def ipt_restore(path)
31
- puts "Restoring rules #{path}..."
32
- Helpers::Exec.new("iptables-restore").run("#{path}")
33
- end
34
- end
35
- end
data/lib/spior/copy.rb DELETED
@@ -1,84 +0,0 @@
1
- require 'digest'
2
-
3
- module Spior
4
- class Copy
5
- def initialize
6
- @cp = Helpers::Exec.new("cp -a")
7
- @files = []
8
- search_conf_dir
9
- config_files
10
- list
11
- end
12
-
13
- def save
14
- @files.each { |f|
15
- backup = "#{f}_backup"
16
- if ! File.exist? backup
17
- Msg.p "#{f} saved"
18
- @cp.run("#{f} #{backup}")
19
- end
20
- }
21
- end
22
-
23
- def restore
24
- @files.each { |f|
25
- backup = "#{f}_backup"
26
- if File.exist? backup
27
- Msg.p "#{f} restored"
28
- @cp.run("#{backup} #{f}")
29
- end
30
- }
31
- end
32
-
33
- private
34
-
35
- def config_files
36
- copy_file("#{@conf_dir}/ipt_mod.conf", "/etc/modules-load.d/ipt_mod.conf")
37
- end
38
-
39
- def list
40
- add "/etc/tor/torrc"
41
- add "/etc/systemd/resolved.conf"
42
- add "/var/lib/iptables/rules-save" # gentoo
43
- add "/etc/iptables/iptables.rules" # arch
44
- add "/etc/iptables/rules.v4" # debian
45
- end
46
-
47
- def add(file)
48
- @files << file if File.exist? file
49
- end
50
-
51
- def search_conf_dir
52
- # ebuild on gentoo copy the ext dir at lib/ext
53
- @conf_dir = File.expand_path('../..' + '/lib/ext', __dir__)
54
- if ! Dir.exist?(@conf_dir)
55
- @conf_dir = File.expand_path('../..' + '/ext', __dir__)
56
- end
57
- end
58
-
59
- def previous_copy(target)
60
- backup=`ls #{target}.backup-* | head -1`.chomp
61
- return false if ! File.exist? backup
62
- check_hash(backup, target)
63
- end
64
-
65
- def add_file(target)
66
- @cp.run("#{@config_file} #{target}")
67
- Msg.p "File #{@config_file} has been successfully copied at #{target}"
68
- end
69
-
70
- def copy_file(conf, target)
71
- @config_file = conf
72
- add_file target if ! File.exist? target
73
- return if check_hash(@config_file, target)
74
- add_file target
75
- end
76
-
77
- def check_hash(src, target)
78
- return if not File.exist?(target)
79
- sha256conf = Digest::SHA256.file src
80
- sha256target = Digest::SHA256.file target
81
- sha256conf === sha256target
82
- end
83
- end
84
- end
data/lib/spior/persist.rb DELETED
@@ -1,51 +0,0 @@
1
- require 'nomansland'
2
- require 'tty-which'
3
-
4
- module Spior
5
- module Persist
6
- extend self
7
-
8
- def enable
9
- case Nomansland::distro?
10
- when :gentoo
11
- for_gentoo
12
- else
13
- Msg.p "Your distro is not yet supported."
14
- end
15
- end
16
-
17
- private
18
-
19
- def for_gentoo
20
- if TTY::Which.exist?('systemctl')
21
- systemd_start("iptables-store")
22
- systemd_enable("iptables-restore")
23
- systemd_enable("tor")
24
- else
25
- system("sudo /etc/init.d/iptables save")
26
- rc_upd = Helpers::Exec.new("rc-update")
27
- rc_upd.run("rc-update add iptables boot")
28
- rc_upd.run("rc-update add tor")
29
- rc_upd.run("rc-update add tor default")
30
- end
31
- end
32
-
33
- def systemd_enable(service)
34
- systemctl = Helpers::Exec.new("systemctl")
35
- Msg.p "Search for service #{service}..."
36
- `systemctl is-enabled #{service}`
37
- if not $?.success? then
38
- systemctl.run("enable #{service}")
39
- end
40
- end
41
-
42
- def systemd_start(service)
43
- systemctl = Helpers::Exec.new("systemctl")
44
- Msg.p "Search for service #{service}..."
45
- `systemctl is-active #{service}`
46
- if not $?.success? then
47
- systemctl.run("start #{service}")
48
- end
49
- end
50
- end
51
- end