spior 0.3.7 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e9226877b6a3f11c1b02a6cea0dd51f6342096772624dbf332fdf7928c77f5e
4
- data.tar.gz: 00b1d3325b22ddf4ef2bd3423125151a1cfaa951670d7ceeb3e7eb8a071e0d5d
3
+ metadata.gz: 35ecc00833e5ba627984058a35375d1773ebdb707fb9218bb5060029d91a08a8
4
+ data.tar.gz: d688befe355c53c3af9bdf110144f3d91f9a9f2c254b6a5b0ea995f8beec85ab
5
5
  SHA512:
6
- metadata.gz: 26fe94bd00c3fdfe3e4edfac13bb75780ed00401bb218c90f35496d0b084bec68785cb71461c3ddbbef1d9df7d4ee9c5751dc4be3c2997627114d6511ea17f55
7
- data.tar.gz: e1b403d42966e8010d3634b7cddb50e0df4bef5539891534b3da4ed6ebc3c45afb4e6fb63cd8744efaa730974e5898036770ee94a9b5bcc652b6becc13ba0b52
6
+ metadata.gz: df077eb2f83b2b084a2a78378fe1f46d5b8f47fc9482a60e980250fed407e4e662d9c14abe9e8880a3fb0307ad40e1be9e465a4e0ba9bf70bca082ce7b150401
7
+ data.tar.gz: 703939ff956cf9601aa367be2e28c987e63b3a8e5560318e7c16eb02ce5d956604a96b71270454d1d9de36fa7f26ade4ac463a2ab7ca0a67e644a6e57cafb41d
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,48 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+ pull_request:
7
+ branches: [ "master" ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ packages: write
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - name: Set up Ruby 2.6
20
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
21
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
22
+ # uses: ruby/setup-ruby@v1
23
+ uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
24
+ with:
25
+ ruby-version: 2.6.10
26
+
27
+ - name: Publish to GPR
28
+ run: |
29
+ mkdir -p $HOME/.gem
30
+ touch $HOME/.gem/credentials
31
+ chmod 0600 $HOME/.gem/credentials
32
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
33
+ gem build *.gemspec
34
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
35
+ env:
36
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
37
+ OWNER: ${{ github.repository_owner }}
38
+
39
+ # - name: Publish to RubyGems
40
+ # run: |
41
+ # mkdir -p $HOME/.gem
42
+ # touch $HOME/.gem/credentials
43
+ # chmod 0600 $HOME/.gem/credentials
44
+ # printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
45
+ # gem build *.gemspec
46
+ # gem push *.gem
47
+ # env:
48
+ # GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.5.0, release 2024-10
2
+ * Correct runtime with openrc on Gentoo
3
+ * Remove a lots of old codes.
4
+ * Correct `root`, `doas` or `sudo` detection.
5
+ * For Debian, enable iptables-legacy instead of nftables, see
6
+ https://wiki.debian.org/iptables (you need to use `spior -i`).
7
+ * Persist Mode on Debian add a script under /etc/network/if-pre-up.d/iptables
8
+ like in the doc.
9
+
1
10
  ## 0.3.7, release 2023-10-27
2
11
  * Persist mode may require manual intervention to work, look the [readme](https://github.com/szorfein/spior/tree/master#left-over)
3
12
  * Persist and runtime corrected on Voidlinux.
data/README.md CHANGED
@@ -10,7 +10,6 @@
10
10
 
11
11
  </div>
12
12
 
13
-
14
13
  (Spider|Tor) A tool to redirect all your local traffic to the [Tor](https://www.torproject.org/) network.
15
14
 
16
15
  ## Install
@@ -31,6 +30,20 @@ Spior use `iptables` and `tor`, which can be installed with (if your distro is s
31
30
 
32
31
  $ spior --install
33
32
 
33
+ ## Configuration
34
+ Spior look the /etc/tor/torrc for any of:
35
+
36
+ ```conf
37
+ DNSPort 9061
38
+ TransPort 9040
39
+ VirtualAddrNetworkIpv4 10.192.0.0/10
40
+ ```
41
+
42
+ You can customize any of theses variables.
43
+
44
+ When using `spior -c | --clearnet`, if you want Spior load custom iptables rules, place
45
+ them at `/etc/iptables/simple_firewall.rules`.
46
+
34
47
  ## Usage
35
48
 
36
49
  $ spior -h
@@ -54,6 +67,7 @@ Return to clearnet navigation
54
67
 
55
68
  ## Left Over
56
69
 
70
+ ### [Check for Leak](https://github.com/brainfucksec/kalitorify#checking-for-leaks)
57
71
  ### Troubleshoooting
58
72
  When you enable the `--persist` mode, Spior try to block ipv6 with sysctl. It can fail on some system, so you may need to manually disable ipv6 via kernel argument.
59
73
  An exemple with GRUB, edit `/etc/default/grub.cfg` and change the line bellow:
@@ -62,13 +76,13 @@ An exemple with GRUB, edit `/etc/default/grub.cfg` and change the line bellow:
62
76
  GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 quiet"
63
77
  ```
64
78
 
65
- Recompile the initrd after that and it should be good.
79
+ Reload grub after that `grub-mkconfig -o /boot/grub/grub.cfg`
66
80
 
67
81
  ### Issues
68
82
  For any questions, comments, feedback or issues, submit a [new issue](https://github.com/szorfein/spior/issues/new).
69
83
 
70
84
  ### links
71
- + https://rubyreferences.github.io/rubyref
72
- + https://rubystyle.guide/
73
85
  + https://gitlab.torproject.org/legacy/trac/-/wikis/doc/TransparentProxy
74
86
  + https://github.com/epidemics-scepticism/writing/blob/master/misconception.md
87
+ + [in perl - Nipe](https://github.com/htrgouvea/nipe)
88
+ + [in bash - Kalitorify](https://github.com/brainfucksec/kalitorify)
data/bin/spior CHANGED
@@ -2,5 +2,45 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'spior'
5
+ require 'optparse'
5
6
 
6
- Spior::Main.new(ARGV)
7
+ Msg.banner
8
+
9
+ OptionParser.new do |opts|
10
+ opts.on('-i', '--install', 'Install the dependencies.') do
11
+ Spior::Dep.looking
12
+ end
13
+
14
+ opts.on('-t', '--tor', 'Redirect traffic through TOR.') do
15
+ Spior::Service.start
16
+ end
17
+
18
+ opts.on('-r', '--reload', 'Reload TOR to change your IP.') do
19
+ Spior::Service.restart
20
+ exit
21
+ end
22
+
23
+ opts.on('-c', '--clearnet', 'Reset iptables and return to clearnet navigation.') do
24
+ Spior::Service.stop
25
+ end
26
+
27
+ opts.on('-s', '--status', 'Look infos about your current IP.') do
28
+ Spior::Status.info
29
+ exit
30
+ end
31
+
32
+ opts.on('-p', '--persist', 'Active Spior at every boot.') do
33
+ Spior::Service::Enable.new
34
+ end
35
+
36
+ opts.on('-m', '--menu', 'Display an interactive menu.') do
37
+ Spior::Menu.run
38
+ end
39
+
40
+ begin
41
+ opts.parse!(['-m']) if ARGV.empty?
42
+ rescue OptionParser::ParseError => e
43
+ warn e.message, "\n", opts
44
+ exit(-1)
45
+ end
46
+ end.parse!
data/lib/spior/dep.rb CHANGED
@@ -11,42 +11,44 @@ module Spior
11
11
  def looking
12
12
  case Nomansland.distro?
13
13
  when :archlinux
14
- installing_deps('Arch', %w[iptables tor])
14
+ installing_deps('pacman -S', %w[iptables tor])
15
15
  when :debian
16
- installing_deps('Debian', %w[iptables tor])
16
+ installing_deps('apt-get install', %w[iptables tor])
17
+ use_iptables
17
18
  when :gentoo
18
- installing_deps('Gentoo', %w[iptables tor])
19
+ installing_deps('emerge -av', %w[iptables tor])
19
20
  when :void
20
- installing_deps('Void', %w[iptables tor])
21
+ installing_deps('xbps-install -S', %w[iptables tor])
22
+ when :fedora
23
+ installing_deps('dnf install -y', %w[iptables tor])
24
+ when :suse
25
+ installing_deps('zypper install -y', %w[iptables tor])
21
26
  else
22
27
  Msg.report 'Install for your distro is not yet supported.'
23
28
  end
24
29
  end
25
30
 
26
- def installing_deps(distro, names)
31
+ def installing_deps(distro_cmd, names)
27
32
  names.map do |n|
28
- Msg.p "Search #{n} for #{distro}..."
29
- install(n) unless search_dep(n)
33
+ Msg.p "Search #{n}..."
34
+ install(distro_cmd, n) unless search_dep(n)
30
35
  end
31
36
  end
32
37
 
33
- def install(name)
34
- case Nomansland.installer?
35
- when :apt_get
36
- Helpers::Exec.new('apt-get').run("install #{name}")
37
- when :emerge
38
- Helpers::Exec.new('emerge').run("-av #{name}")
39
- when :pacman
40
- Helpers::Exec.new('pacman').run("-S #{name}")
41
- when :void
42
- Helpers::Exec.new('xbps-install').run("-y #{name}")
43
- when :yum
44
- Helpers::Exec.new('yum').run("install #{name}")
45
- end
38
+ def install(cmd, package)
39
+ Helpers.cmd("#{cmd} #{package}")
46
40
  end
47
41
 
48
42
  def search_dep(name)
49
43
  TTY::Which.exist?(name) ? true : false
50
44
  end
45
+
46
+ # https://wiki.debian.org/iptables
47
+ def use_iptables
48
+ Helpers.cmd('update-alternatives --set iptables /usr/sbin/iptables-legacy')
49
+ Helpers.cmd('update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy')
50
+ Helpers.cmd('update-alternatives --set arptables /usr/sbin/arptables-legacy')
51
+ Helpers.cmd('update-alternatives --set ebtables /usr/sbin/ebtables-legacy')
52
+ end
51
53
  end
52
54
  end
data/lib/spior/helpers.rb CHANGED
@@ -5,21 +5,47 @@ require 'tempfile'
5
5
  require 'open3'
6
6
 
7
7
  module Helpers
8
+ def self.auth?
9
+ return :root if Process.uid == '0'
10
+ return :doas if File.exist?('/bin/doas') || File.exist?('/sbin/doas')
11
+ return :sudo if File.exist?('/bin/sudo') || File.exist?('/sbin/sudo')
12
+ end
13
+
14
+ def self.cmd(command)
15
+ case auth?
16
+ when :root
17
+ syscmd(command)
18
+ when :doas
19
+ syscmd("doas #{command}")
20
+ when :sudo
21
+ syscmd("sudo #{command}")
22
+ end
23
+ end
24
+
25
+ def self.syscmd(cmd)
26
+ Open3.popen2e(cmd) do |_, stdout_and_stderr, wait_thr|
27
+ puts stdout_and_stderr.gets while stdout_and_stderr.gets
28
+ exit_status = wait_thr.value
29
+ raise "Error, Running #{cmd}" unless exit_status.success?
30
+ end
31
+ end
32
+
33
+ def self.mv(src, dest)
34
+ if Process::Sys.getuid == '0'
35
+ FileUtils.mv(src, dest)
36
+ else
37
+ cmd("mv #{src} #{dest}")
38
+ end
39
+ end
40
+
8
41
  # Execute program using sudo when permission is required
9
42
  class Exec
10
43
  def initialize(name)
11
- @search_uid = Process::Sys.getuid
12
44
  @name = name
13
45
  end
14
46
 
15
47
  def run(args)
16
- cmd = (@search_uid == '0' ? @name : "sudo #{@name}")
17
- Open3.popen2e("#{cmd} #{args}") do |_, stdout_err, wait_thr|
18
- puts stdout_err.gets while stdout_err.gets
19
-
20
- exit_status = wait_thr.value
21
- raise "Error, Running #{cmd} #{args}" unless exit_status.success?
22
- end
48
+ Helpers.cmd("#{@name} #{args}")
23
49
  end
24
50
  end
25
51
 
@@ -10,19 +10,17 @@ module Spior
10
10
  class Rules
11
11
  def initialize
12
12
  @tmp_iptables_rules = Tempfile.new('iptables_rules')
13
- @tmp_spior_rules = Tempfile.new('spior_rules')
14
13
  @save_path = search_iptables_config
15
14
  end
16
15
 
17
16
  def save
18
- save_rules(@tmp_iptables_rules)
19
- insert_comment(@tmp_spior_rules, @tmp_iptables_rules)
20
- create_file(@tmp_spior_rules, @save_path)
17
+ Helpers.cmd("iptables-save > #{@tmp_iptables_rules.path}")
18
+ Helpers.mv(@tmp_iptables_rules.path, @save_path)
21
19
  Msg.p "Iptables rules saved at #{@save_path}"
22
20
  end
23
21
 
24
22
  def restore
25
- return if restoring_older_rules(@save_path)
23
+ return if restoring_older_rules
26
24
 
27
25
  Msg.p 'Adding clearnet navigation...'
28
26
  Iptables::Default.new.run!
@@ -30,59 +28,15 @@ module Spior
30
28
 
31
29
  protected
32
30
 
33
- def save_rules(tmp_file)
34
- Msg.p 'Saving Iptables rules...'
35
- Helpers::Exec.new('iptables-save').run("> #{tmp_file.path}")
36
- end
37
-
38
- def insert_comment(spior_file, iptable_file)
39
- outfile = File.open(spior_file.path, 'w')
40
- outfile.puts '# Rules saved by Spior.'
41
- outfile.puts(File.read(iptable_file.path))
42
- outfile.close
43
- end
44
-
45
- def search_for_comment(filename)
46
- return false unless File.exist? filename
47
-
48
- File.open(filename) do |f|
49
- f.each do |line|
50
- return true if line.match(/saved by Spior/)
51
- end
52
- end
53
- false
54
- end
55
-
56
- def move(src, dest)
57
- if Process::Sys.getuid == '0'
58
- FileUtils.mv(src, dest)
59
- else
60
- Helpers::Exec.new('mv').run("#{src} #{dest}")
61
- end
62
- end
63
-
64
- def create_file(tmpfile, dest)
65
- if File.exist? dest
66
- if search_for_comment(dest)
67
- Msg.p "Older Spior rules found #{dest}, erasing..."
68
- else
69
- Msg.p "File exist #{dest}, create backup #{dest}-backup..."
70
- move(dest, "#{dest}-backup")
71
- end
72
- end
73
- move(tmpfile.path, dest)
74
- end
75
-
76
- def restoring_older_rules(filename)
77
- files = %W[#{filename}-backup /etc/iptables/simple_firewall.rules #{filename}]
31
+ def restoring_older_rules
32
+ files = %w[/etc/iptables/simple_firewall.rules /usr/share/iptables/simple_firewall.rules]
78
33
  files.each do |f|
79
- next unless File.exist?(f) || search_for_comment(f)
34
+ next unless File.exist?(f)
80
35
 
81
36
  Iptables::Root.new.stop!
82
37
  Msg.p "Found older rules #{f}, restoring..."
83
- Helpers::Exec.new('cp').run("#{f} #{@save_path}")
84
- Helpers::Exec.new('iptables-restore').run(@save_path)
85
-
38
+ Helpers.cmd("cp #{f} #{@save_path}")
39
+ Helpers.cmd("iptables-restore < #{@save_path}")
86
40
  return true
87
41
  end
88
42
  false
@@ -92,16 +46,12 @@ module Spior
92
46
 
93
47
  def search_iptables_config
94
48
  case Nomansland.distro?
95
- when :archlinux
96
- '/etc/iptables/iptables.rules'
97
- when :void
98
- '/etc/iptables/iptables.rules'
99
49
  when :debian
100
50
  '/etc/iptables.up.rules'
101
51
  when :gentoo
102
52
  '/var/lib/iptables/rules-save'
103
53
  else
104
- Msg.report 'I don`t know where you distro save the rules for iptables yet'
54
+ '/etc/iptables/iptables.rules'
105
55
  end
106
56
  end
107
57
  end
data/lib/spior/ipv6.rb CHANGED
@@ -1,4 +1,3 @@
1
- # lib/ipv6.rb
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'auth'
@@ -8,41 +7,35 @@ module Spior
8
7
  # Block or Allow ipv6 traffic with sysctl
9
8
  class Ipv6
10
9
  def initialize
11
- @changed = false
10
+ @dest = '/etc/sysctl.d/40-ipv6.conf'
11
+ gen_flags
12
12
  end
13
13
 
14
14
  def allow
15
- apply_option('net.ipv6.conf.all.disable_ipv6', '0')
16
- apply_option('net.ipv6.conf.default.disable_ipv6', '0')
17
- Msg.p 'ipv6 allowed' if @changed
15
+ @flags.each { |f| Helpers.cmd("sysctl -w '#{f}=0'") }
16
+ Msg.p 'ipv6 allowed'
17
+ Helpers.cmd("rm #{@dest}") if File.exist? @dest
18
18
  end
19
19
 
20
20
  def block
21
- apply_option('net.ipv6.conf.all.disable_ipv6', '1')
22
- apply_option('net.ipv6.conf.default.disable_ipv6', '1')
23
- Msg.p 'ipv6 blocked' if @changed
21
+ @flags.each { |f| Helpers.cmd("sysctl -w '#{f}=1'") }
22
+ Msg.p 'ipv6 blocked'
24
23
  end
25
24
 
26
25
  def block_persist
27
26
  Auth.new.mkdir '/etc/sysctl.d'
28
- interfaces = ['net.ipv6.conf.all.disable_ipv6 = 1',
29
- 'net.ipv6.conf.default.disable_ipv6 = 1']
30
- Interfacez.all { |i| interfaces << "net.ipv6.conf.#{i}.disable_ipv6 = 1" }
31
- if Process::Sys.getuid == '0'
32
- File.write('/etc/sysctl.d/40-ipv6.conf', interfaces.join("\n"))
33
- else
34
- Auth.new.write(interfaces.join("\n"), '/etc/sysctl.d/40-ipv6.conf')
35
- end
27
+ myflags = []
28
+ @flags.each { |f| myflags << "#{f}=1" }
29
+ File.write('/tmp/flags.conf', myflags.join("\n"))
30
+ Helpers.cmd("cp /tmp/flags.conf #{@dest}")
36
31
  end
37
32
 
38
33
  private
39
34
 
40
- def apply_option(flag, value)
41
- flag_path = flag.gsub('.', '/')
42
- return unless File.exist?("/proc/sys/#{flag_path}")
43
-
44
- Auth.new.sysctl(flag, value)
45
- @changed = true
35
+ def gen_flags
36
+ @flags = ['net.ipv6.conf.all.disable_ipv6',
37
+ 'net.ipv6.conf.default.disable_ipv6']
38
+ Interfacez.all { |i| @flags << "net.ipv6.conf.#{i}.disable_ipv6" }
46
39
  end
47
40
  end
48
41
  end
data/lib/spior/options.rb CHANGED
@@ -1,61 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'optparse'
4
-
5
3
  module Spior
6
4
  # Options for the CLI
7
5
  class Options
8
- def initialize(argv)
9
- parse(argv)
10
- end
11
-
12
- private
13
-
14
- def parse(argv)
15
- OptionParser.new do |opts|
16
- opts.on('-i', '--install', 'Install the dependencies.') do
17
- Dep.looking
18
- end
19
-
20
- opts.on('-t', '--tor', 'Redirect traffic through TOR.') do
21
- Service.start
22
- end
23
-
24
- opts.on('-r', '--reload', 'Reload TOR to change your IP.') do
25
- Service.restart
26
- exit
27
- end
28
-
29
- opts.on('-c', '--clearnet', 'Reset iptables and return to clearnet navigation.') do
30
- Service.stop
31
- end
32
-
33
- opts.on('-s', '--status', 'Look infos about your current IP.') do
34
- Status.info
35
- exit
36
- end
37
-
38
- opts.on('-p', '--persist', 'Active Spior at every boot.') do
39
- Service::Enable.new
40
- end
41
-
42
- opts.on('-m', '--menu', 'Display an interactive menu.') do
43
- Menu.run
44
- end
45
-
46
- opts.on('-h', '--help', 'Show this message.') do
47
- puts opts
48
- exit
49
- end
50
-
51
- begin
52
- argv = ['-m'] if argv.empty?
53
- opts.parse!(argv)
54
- rescue OptionParser::ParseError => e
55
- warn e.message, "\n", opts
56
- exit(-1)
57
- end
58
- end
59
- end
60
6
  end
61
7
  end
@@ -19,6 +19,8 @@ module Spior
19
19
  for_arch
20
20
  when :void
21
21
  for_void
22
+ when :debian
23
+ for_debian
22
24
  else
23
25
  Msg.report 'Your distro is not yet supported.'
24
26
  end
@@ -27,19 +29,19 @@ module Spior
27
29
  protected
28
30
 
29
31
  def for_gentoo
30
- Iptables::Rules.new.save
31
32
  case Nomansland.init?
32
33
  when :systemd
34
+ Iptables::Rules.new.save
33
35
  systemd_enable('iptables-restore', 'tor')
34
36
  when :openrc
35
- rc_upd = Helpers::Exec.new('rc-update')
36
- rc_upd.run('rc-update add iptables boot')
37
- rc_upd.run('rc-update add tor')
38
- rc_upd.run('rc-update add tor default')
37
+ Helpers.cmd('rc-service iptables save')
38
+ Helpers.cmd('rc-update add iptables boot') # default or boot ?
39
+ Helpers.cmd('rc-update add tor default')
39
40
  else
40
41
  Msg.report 'Init no yet supported for start Iptables at boot'
41
42
  end
42
43
  Ipv6.new.block_persist
44
+ Msg.p 'Persist enabled for Gentoo...'
43
45
  end
44
46
 
45
47
  def for_arch
@@ -58,14 +60,26 @@ module Spior
58
60
  Msg.p 'Persist enabled for Void...'
59
61
  end
60
62
 
63
+ # https://wiki.debian.org/iptables
64
+ def for_debian
65
+ Iptables::Rules.new.save
66
+ Tor::Config.new(Tempfile.new('torrc')).backup
67
+ systemd_enable('tor')
68
+ File.write('/tmp/start_iptables',
69
+ "#!/bin/sh\n/sbin/iptables-restore < /etc/iptables.up.rules\n")
70
+ Helpers.mv('/tmp/start_iptables', '/etc/network/if-pre-up.d/iptables')
71
+ Helpers.cmd('chmod +x /etc/network/if-pre-up.d/iptables')
72
+ Ipv6.new.block_persist
73
+ Msg.p 'Persist mode enabled for Debian...'
74
+ end
75
+
61
76
  private
62
77
 
63
78
  def systemd_enable(*services)
64
- systemctl = Helpers::Exec.new('systemctl')
65
79
  services.each do |s|
66
80
  next if system("systemctl is-enabled #{s} >/dev/null")
67
81
 
68
- systemctl.run("enable #{s}")
82
+ Helpers.cmd("systemctl enable #{s}")
69
83
  Msg.p "Enabling #{s}..."
70
84
  end
71
85
  end
@@ -74,17 +88,16 @@ module Spior
74
88
  services.each do |s|
75
89
  next if File.exist? "/var/service/#{s}"
76
90
 
77
- Helpers::Exec.new('ln').run("-s /etc/sv/#{s} /var/service/#{s}")
91
+ Helpers.cmd("ln -s /etc/sv/#{s} /var/service/#{s}")
78
92
  Msg.p "Enabling #{s}"
79
93
  end
80
94
  end
81
95
 
82
96
  def systemd_start(service)
83
- systemctl = Helpers::Exec.new('systemctl')
84
97
  return if system("systemctl is-active #{service} >/dev/null")
85
98
 
86
99
  Msg.p "Search for service #{service}..."
87
- systemctl.run("start #{service}")
100
+ Helpers.cmd("systemctl start #{service}")
88
101
  end
89
102
  end
90
103
  end
@@ -1,14 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'nomansland'
4
+
3
5
  module Spior
4
6
  # Interact with Spior::Tor and Spior::Iptables
5
7
  module Service
6
8
  module_function
7
9
 
8
10
  def restart
9
- Service.stop(clean: false)
10
- Service.start
11
- Msg.p 'ip changed.'
11
+ case Nomansland.init?
12
+ when :systemd
13
+ Helpers.cmd('systemctl restart tor')
14
+ when :openrc
15
+ Helpers.cmd('/etc/init.d/tor restart')
16
+ when :runit
17
+ Helpers.cmd('sv restart tor')
18
+ else
19
+ puts 'No init found (systemd, openrc, runit)...'
20
+ end
21
+ Msg.p 'Tor restarting, ip changed.'
12
22
  end
13
23
  end
14
24
  end
data/lib/spior/status.rb CHANGED
@@ -38,6 +38,8 @@ module Spior
38
38
  puts " Timezone ===> #{hash['time_zone']}"
39
39
  end
40
40
  puts " Status ===> #{enable}"
41
+ rescue SocketError => e
42
+ Msg.err e
41
43
  rescue OpenURI::HTTPError => e
42
44
  res = e.io
43
45
  puts "Fail to join server #{res.status}"
@@ -32,7 +32,7 @@ module Spior
32
32
  cn = @content.join("\n")
33
33
  File.write(@filename.path, "#{cn}\n")
34
34
  Msg.p "Generating #{@config_spiorrc}..."
35
- move(@filename.path, @config_spiorrc)
35
+ Helpers.mv(@filename.path, @config_spiorrc)
36
36
  end
37
37
 
38
38
  def write_file(content, file, mode = 'a')
@@ -55,7 +55,7 @@ module Spior
55
55
  write_file @content_torrc, @filename.path, 'w'
56
56
 
57
57
  Msg.p 'Saving Tor options...'
58
- move(@filename.path, @config_spiorrc)
58
+ Helpers.mv(@filename.path, @config_spiorrc)
59
59
  end
60
60
 
61
61
  protected
@@ -64,9 +64,9 @@ module Spior
64
64
  return if Dir.exist? @config_dir
65
65
 
66
66
  if Process::Sys.getuid == '0'
67
- File.mkdir @config_dir
67
+ FileUtils.mkdir_p @config_dir
68
68
  else
69
- Auth.new.mkdir @config_dir
69
+ Helpers.cmd("mkdir -p #{@config_dir}")
70
70
  end
71
71
  end
72
72
 
@@ -75,7 +75,7 @@ module Spior
75
75
  content = File.read(@config_torrc)
76
76
  adding content, "%include #{@config_dir}/*.conf"
77
77
  write_file content, temp.path
78
- move(temp.path, @config_torrc)
78
+ Helpers.mv(temp.path, @config_torrc)
79
79
  end
80
80
 
81
81
  def generate_content(content)
@@ -112,26 +112,6 @@ module Spior
112
112
  md5_dest = Digest::MD5.file dest
113
113
  md5_src == md5_dest
114
114
  end
115
-
116
- # Permission for Archlinux on a torrc are chmod 644, chown root:root
117
- def fix_perm(file)
118
- if Process::Sys.getuid == '0'
119
- file.chown(0, 0)
120
- else
121
- Helpers::Exec.new('chown').run("root:root #{file}")
122
- end
123
- end
124
-
125
- def move(src, dest)
126
- return if digest_match? src, dest
127
-
128
- fix_perm(@filename.path)
129
- if Process::Sys.getuid == '0'
130
- FileUtils.mv(src, dest)
131
- else
132
- Helpers::Exec.new('mv').run("#{src} #{dest}")
133
- end
134
- end
135
115
  end
136
116
  end
137
117
  end
@@ -45,6 +45,8 @@ module Spior
45
45
  case Nomansland.distro?
46
46
  when :debian || :ubuntu
47
47
  `id -u debian-tor`.chomp
48
+ when :fedora
49
+ `id -u toranon`.chomp
48
50
  else
49
51
  `id -u #{@user}`.chomp
50
52
  end
@@ -38,28 +38,22 @@ module Spior
38
38
  return if state == 'active'
39
39
 
40
40
  Msg.p 'Starting Tor with Systemd...'
41
- Helpers::Exec.new('systemctl').run('start tor')
41
+ Helpers.cmd('systemctl start tor')
42
42
  end
43
43
 
44
44
  def start_openrc
45
45
  Msg.p 'Starting Tor with OpenRC...'
46
- Helpers::Exec.new('/etc/init.d/tor').run('start')
46
+ Helpers.cmd('/etc/init.d/tor start')
47
47
  end
48
48
 
49
49
  def start_runit
50
50
  Msg.p 'Starting Tor with Runit...'
51
51
  if File.exist? '/var/service/tor'
52
- Helpers::Exec.new('sv').run('start tor')
52
+ Helpers.cmd('sv start tor')
53
53
  else
54
- Helpers::Exec.new('ln').run('-s /etc/sv/tor /var/service/tor')
54
+ Helpers.cmd('ln -s /etc/sv/tor /var/service/tor')
55
55
  end
56
56
  end
57
-
58
- def x(arg)
59
- auth = (Process::Sys.getuid == '0' ? '' : 'sudo')
60
- pid = spawn("#{auth} #{arg}", out: '/dev/null') or raise 'Error'
61
- Process.wait pid
62
- end
63
57
  end
64
58
  end
65
59
  end
data/lib/spior/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spior
4
- VERSION = '0.3.7'
4
+ VERSION = '0.5.0'
5
5
  end
data/lib/spior.rb CHANGED
@@ -21,19 +21,4 @@ module Spior
21
21
  # Spior::CONFIG.user = 'Tor-User-System'
22
22
  # Spior::CONFIG.virt_addr = '10.192.0.0/10'
23
23
  CONFIG = Tor::Data.new
24
-
25
- # Main for the CLI
26
- class Main
27
- def initialize(argv)
28
- @argv = argv
29
- x
30
- end
31
-
32
- private
33
-
34
- def x
35
- Msg.banner
36
- Options.new(@argv)
37
- end
38
- end
39
24
  end
data/spior.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "#{File.dirname(__FILE__)}/lib/spior/version"
3
+ require_relative "lib/spior/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'spior'
@@ -31,8 +31,8 @@ Gem::Specification.new do |s|
31
31
 
32
32
  s.test_files = Dir['test/test_*.rb']
33
33
 
34
- s.cert_chain = ['certs/szorfein.pem']
35
- s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
34
+ #s.cert_chain = ['certs/szorfein.pem']
35
+ #s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
36
36
 
37
37
  s.requirements << 'tor'
38
38
  s.requirements << 'iptables'
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.3.7
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - szorfein
@@ -36,7 +36,7 @@ cert_chain:
36
36
  urXgRIzALxd/xazPCnoLSXPzfJSI6Y77S1EBvhPd9RaSO8IyH9RhPDP9mnTvW2Kl
37
37
  NAUnoL+txK5a
38
38
  -----END CERTIFICATE-----
39
- date: 2023-10-27 00:00:00.000000000 Z
39
+ date: 2024-10-10 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: interfacez
@@ -103,6 +103,7 @@ extra_rdoc_files:
103
103
  - README.md
104
104
  - CHANGELOG.md
105
105
  files:
106
+ - ".github/workflows/gem-push.yml"
106
107
  - ".github/workflows/rubocop-analysis.yml"
107
108
  - ".gitignore"
108
109
  - CHANGELOG.md
metadata.gz.sig CHANGED
Binary file