spior 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27c8fa0d8922c53ef9e3a7105c34de378489f3e70ddd334fedca96fe354da0ca
4
- data.tar.gz: 70dbfd556eecb0db121145b43478129235c26b70a01c8a5c62a1194a9f98df7d
3
+ metadata.gz: 105d4a29ed0eb407f8116daa49be26a8d8714d999efb531e02676f02c6ed50f3
4
+ data.tar.gz: 0cfdf8f3a6f857e6d7a1541b103ade1316048c4554ab03076d5d287a2b1ffa1c
5
5
  SHA512:
6
- metadata.gz: f66d9d28077922f149b01a869a77b494d22d75713f6eeffb65a856efaed6556ec686346de7e1241ede0352328dc4f0e01a9f2c4983a5197aacb28b398413828b
7
- data.tar.gz: a14c7edbab9887624014b668377286efb71c5115aebd847ef28da081fedb6dd82882baf0cf8c4175822547d7322e581dd92eefbaf678d7ef69a985152f0190dd
6
+ metadata.gz: 37258c344e84aa8508a87d6a5b41dc821d54038a9cc163b1976e924301238b5b4debf03c2fba0e0a8015b6d17abedaf4313bdc3beb459eb7add6199f16eb8abe
7
+ data.tar.gz: fe90d4935a4c36efdfb16553153c67a0a956560edb5515ac8efd412a8319a4f897203027aa55883338a32c3add6be19aa5f96e81bfd1d455e6e71357d4e337ab
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,10 @@
1
+ ## 0.1.4, release 2020-05-21
2
+ * torrc and resolv.conf are generate dynamically
3
+ * Remove conf/resolv
4
+ * Correct path of conf_dir for the install on gentoo
5
+ * Remove self from lib/copy
6
+ * Correct little error on lib/copy with undefined method `deps`
7
+
1
8
  ## 0.1.3, release 2020-05-14
2
9
  * Rename conf dir by ext
3
10
  * Clearing all codes about MAC
@@ -0,0 +1,19 @@
1
+ # https://github.com/seattlerb/minitest#running-your-tests-
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/test_*.rb"]
8
+ end
9
+
10
+ namespace :gem do
11
+ desc "build the gem"
12
+ task :build do
13
+ Dir["spior*.gem"].each {|f| File.unlink(f) }
14
+ system("gem build spior.gemspec")
15
+ system("gem install spior-0.1.4.gem -P MediumSecurity")
16
+ end
17
+ end
18
+
19
+ task :default => :test
@@ -6,101 +6,114 @@ require_relative 'helpers'
6
6
 
7
7
  module Spior
8
8
  class Copy
9
+ class << self
9
10
 
10
- def self.config_files
11
- @cp = Helpers::Exec.new("cp -a")
12
- @conf_dir = File.expand_path('../..' + '/ext', __dir__)
13
- copy_torrc
14
- copy_file(@conf_dir + "/resolv.conf", "/etc/resolv.conf")
15
- copy_file(@conf_dir + "/ipt_mod.conf", "/etc/modules-load.d/ipt_mod.conf")
16
- end
11
+ def config_files
12
+ @cp = Helpers::Exec.new("cp -a")
13
+ search_conf_dir
14
+ copy_file(@conf_dir + "/ipt_mod.conf", "/etc/modules-load.d/ipt_mod.conf")
15
+ end
17
16
 
18
- def self.restore_files
19
- @cp = Helpers::Exec.new("cp -a")
20
- backup_exist("/etc/tor/torrc")
21
- backup_exist("/etc/resolv.conf")
22
- end
17
+ def backup(file, re = nil)
18
+ return if regex_match?(file, re)
19
+ @cp = Helpers::Exec.new("cp -a")
20
+ backup = file + "_backup"
21
+ if File.exist? backup
22
+ puts "File #{backup} exist with content:"
23
+ system("head -n 10 #{backup}")
24
+ print "...\nOverwrite this copy? (N/y) "
25
+ case gets.chomp
26
+ when /^y|^Y/
27
+ @cp.run("#{file} #{backup}")
28
+ Msg.p "Overwrite #{file}"
29
+ end
30
+ else
31
+ @cp.run("#{file} #{backup}")
32
+ Msg.p "#{file} saved"
33
+ end
34
+ end
35
+
36
+ def search_conf_dir
37
+ # ebuild on gentoo copy the ext dir at lib/ext
38
+ @conf_dir = File.expand_path('../..' + '/lib/ext', __dir__)
39
+ if not Dir.exist?(@conf_dir)
40
+ @conf_dir = File.expand_path('../..' + '/ext', __dir__)
41
+ end
42
+ end
23
43
 
24
- def self.search_systemd_dir
25
- if Dir.exist?("/usr/lib/systemd/system")
26
- @systemd_dir = '/usr/lib/systemd/system'
27
- elsif Dir.exist?("/lib/systemd/system")
28
- @systemd_dir = '/lib/systemd/system'
29
- else
30
- Msg.report "Directory systemd/system is no found on your system."
31
- exit(-1)
44
+ def restore(file)
45
+ @cp = Helpers::Exec.new("cp -a")
46
+ backup = file + "_backup"
47
+ if File.exist? backup
48
+ @cp.run("#{backup} #{file}")
49
+ end
32
50
  end
33
- end
34
51
 
35
- def self.systemd_services
36
- @cp = Helpers::Exec.new("cp -a")
37
- search_systemd_dir
38
- case Nomansland::installer?
39
- when :gentoo
40
- Msg.p "Copy #{@conf_dir}/iptables.service"
41
- copy_file(@conf_dir + "/iptables.service", @systemd_dir + "/iptables.service")
52
+ def restore_files
53
+ restore("/etc/tor/torrc")
54
+ restore("/etc/resolv.conf")
42
55
  end
43
- end
44
56
 
45
- private
57
+ private
46
58
 
47
- def self.copy_file(conf, target)
48
- @config_file = conf
49
- return if check_hash(@config_file, target)
50
- if File.exist? target then
51
- if ! previous_copy target
52
- backup_file(target)
53
- end
54
- add_file target
55
- else
56
- add_file target
59
+ def copy_file(conf, target)
60
+ @config_file = conf
61
+ return if check_hash(@config_file, target)
62
+ if File.exist? target then
63
+ if ! previous_copy target
64
+ backup_file(target)
65
+ end
66
+ add_file target
67
+ else
68
+ add_file target
69
+ end
57
70
  end
58
- end
59
71
 
60
- def self.copy_torrc
61
- case Nomansland::distro?
62
- when :archlinux
63
- copy_file(@conf_dir + "/torrc/torrc_archlinux", "/etc/tor/torrc")
64
- else
65
- copy_file(@conf_dir + "/torrc/torrc_default", "/etc/tor/torrc")
66
- Msg.report "If tor fail to start with the default torrc"
72
+ def previous_copy(target)
73
+ backup=`ls #{target}.backup-* | head -n 1`.chomp
74
+ return false if !File.exist?(backup)
75
+ check_hash(backup, target)
67
76
  end
68
- end
69
77
 
70
- def self.previous_copy(target)
71
- backup=`ls #{target}.backup-* | head -n 1`.chomp
72
- return false if !File.exist?(backup)
73
- check_hash(backup, target)
74
- end
78
+ def check_hash(src, target)
79
+ return if not File.exist?(target)
80
+ sha256conf = Digest::SHA256.file src
81
+ sha256target = Digest::SHA256.file target
82
+ sha256conf === sha256target
83
+ end
75
84
 
76
- def self.check_hash(src, target)
77
- return if not File.exist?(target)
78
- sha256conf = Digest::SHA256.file src
79
- sha256target = Digest::SHA256.file target
80
- sha256conf === sha256target
81
- end
85
+ def backup_file(target)
86
+ d = DateTime.now
87
+ backup = target + ".backup-" + d.strftime('%b-%d_%I-%M')
88
+ @cp.run("#{target} #{backup}")
89
+ puts "Renamed file #{backup}"
90
+ end
82
91
 
83
- def self.backup_file(target)
84
- d = DateTime.now
85
- backup = target + ".backup-" + d.strftime('%b-%d_%I-%M')
86
- @cp.run("#{target} #{backup}")
87
- puts "Renamed file #{backup}"
88
- end
92
+ def add_file(target)
93
+ @cp.run("#{@config_file} #{target}")
94
+ Msg.p "File #{@config_file} has been successfully copied at #{target}"
95
+ end
89
96
 
90
- def self.add_file(target)
91
- @cp.run("#{@config_file} #{target}")
92
- Msg.p "File #{@config_file} has been successfully copied at #{target}"
93
- end
97
+ def backup_exist(target)
98
+ backup=`ls #{target}.backup-* | head -n 1`.chomp
99
+ if File.exist? backup
100
+ if ! check_hash(target, backup)
101
+ @cp.run("#{backup} #{target}")
102
+ Msg.p "Restored #{backup}"
103
+ end
104
+ else
105
+ puts "No found previous backup for #{target}"
106
+ end
107
+ end
94
108
 
95
- def self.backup_exist(target)
96
- backup=`ls #{target}.backup-* | head -n 1`.chomp
97
- if File.exist? backup
98
- if ! check_hash(target, backup)
99
- @cp.run("#{backup} #{target}")
100
- Msg.p "Restored #{backup}"
109
+ def regex_match?(infile, re = nil)
110
+ return unless re
111
+ File.open(infile, 'r') do |file|
112
+ file.each do |line|
113
+ return true if line =~ re
114
+ end
101
115
  end
102
- else
103
- puts "No found previous backup for #{target}"
116
+ false
104
117
  end
105
118
  end
106
119
  end
@@ -1,8 +1,10 @@
1
+ require 'fileutils'
2
+ require 'tempfile'
3
+
1
4
  module Helpers
2
5
  class Exec
3
6
  def initialize(name)
4
- @search_uid=`id -u`.chomp
5
- @search_uid ||= 1000 unless $?.success?
7
+ @search_uid = Process::Sys.getuid
6
8
  @name = name
7
9
  end
8
10
 
@@ -16,4 +18,95 @@ module Helpers
16
18
  end
17
19
  end
18
20
  end
21
+
22
+ # Class Newfile
23
+ # Create a file and move at the dest
24
+ # === Example
25
+ # string = "nameserver 127.0.0.1"
26
+ # name = "resolv.conf"
27
+ # dest = "/etc"
28
+ # new_file = Helpers::Newfile.new(string, name, dest)
29
+ # new_file.add
30
+ class NewFile
31
+ # Method #new
32
+ # === Parameters
33
+ # * _string_ = string for the whole file
34
+ # * _name_ = name of the file (e.g: resolv.conf)
35
+ # * _dest_ = path (e.g: /etc)
36
+ def initialize(string, name, dest = "/tmp")
37
+ @string = string
38
+ @name = name
39
+ @dest = dest + "/" + @name
40
+ end
41
+
42
+ # Method #add
43
+ # Add the file at @dest
44
+ def add
45
+ @mv = Helpers::Exec.new("mv")
46
+ tmp = Tempfile.new(@name)
47
+ File.open(tmp.path, 'w') do |file|
48
+ file.puts @string
49
+ end
50
+ @mv.run("#{tmp.path} #{@dest}")
51
+ end
52
+
53
+ def perm(user, perm)
54
+ chown = Helpers::Exec.new("chown")
55
+ chmod = Helpers::Exec.new("chmod")
56
+ chown.run("#{user}:#{user} #{@dest}")
57
+ chmod.run("#{perm} #{@dest}")
58
+ end
59
+ end
60
+
61
+ # Class NewSystemd
62
+ # Used to create a systemd service
63
+ #
64
+ # === Example:
65
+ # require Helpers
66
+ # string = <<EOF
67
+ # [Description]
68
+ #
69
+ # [Service]
70
+ # Type=simple
71
+ #
72
+ # [Installation]
73
+ # WantedBy =
74
+ # EOF
75
+ # new_systemd = Helpers::NewSystemd.new(string, "tor.service")
76
+ # new_systemd.add
77
+ class NewSystemd < NewFile
78
+ # Method #new
79
+ # === Parameters:
80
+ # * _string_ = the string of for whole content file
81
+ # * _name_ = the name of the service (e.g: tor.service)
82
+ def initialise(string, name)
83
+ super
84
+ @systemd_dir = search_systemd_dir
85
+ @dest = @systemd_dir + "/" + @name
86
+ end
87
+
88
+ # Method #add
89
+ # Create a temporary file and move
90
+ # the service @name to the systemd directory
91
+ def add
92
+ @systemctl = Helpers::Exec.new("systemctl")
93
+ super
94
+ @systemctl.run("daemon-reload")
95
+ end
96
+
97
+ private
98
+ # Method search_systemd_dir
99
+ # Search the current directory for systemd services
100
+ # + Gentoo can install at /lib/systemd/system or /usr/lib/systemd/system
101
+ def search_systemd_dir
102
+ if Dir.exist? "/lib/systemd/system"
103
+ "/lib/systemd/system"
104
+ elsif Dir.exist? "/usr/lib/systemd/system"
105
+ "/usr/lib/systemd/system"
106
+ else
107
+ raise "No directory systemd found"
108
+ exit
109
+ end
110
+ end
111
+ end
19
112
  end
@@ -8,14 +8,51 @@ module Spior
8
8
  module Persist
9
9
  extend self
10
10
 
11
- def all(card_name)
12
- @card_name = card_name
11
+ def all
13
12
  @services=[ "tor", "iptables" ]
13
+ services
14
+ save_rules
14
15
  search_for_systemd
15
16
  end
16
17
 
17
18
  private
18
19
 
20
+ # Install a systemd service where needed. TODO: test on more distrib
21
+ # no need on: archlinux
22
+ # need on: gentoo, debian,
23
+ def services
24
+ return if !TTY::Which.exist?('systemctl')
25
+ path_bin = "/sbin/iptables-restore"
26
+ path_rules = ""
27
+ case Nomansland::distro?
28
+ when :gentoo
29
+ path_rules = "/var/lib/iptables/rules-save"
30
+ when :debian
31
+ path_rules = "/etc/iptables/rules.v4"
32
+ end
33
+ string = <<EOF
34
+ [Unit]
35
+ Description=IPv4 Packet Filtering Framework for Spior
36
+ Before=network-pre.target
37
+ Wants=network-pre.target
38
+
39
+ [Service]
40
+ Type=oneshot
41
+ ExecStart=#{path_bin} #{path_rules}
42
+ ExecReload=#{path_bin} #{path_rules}
43
+ RemainAfterExit=yes
44
+
45
+ [Install]
46
+ WantedBy=multi-user.target
47
+ EOF
48
+ case Nomansland::distro?
49
+ when :gentoo
50
+ new_systemd = Helpers::NewSystemd.new(string, "iptables.services")
51
+ new_systemd.add
52
+ new_systemd.perm("root", "644")
53
+ end
54
+ end
55
+
19
56
  def search_for_systemd
20
57
  return if !TTY::Which.exist?('systemctl')
21
58
  @systemctl = Helpers::Exec.new("systemctl")
@@ -28,14 +65,14 @@ module Spior
28
65
  @systemctl.run("enable #{service}")
29
66
  end
30
67
  end
31
- iptables_systemd
32
68
  end
33
69
 
34
- def iptables_systemd
70
+ def save_rules
35
71
  case Nomansland::installer?
36
72
  when :pacman
37
73
  @iptables_save.run("-f /etc/iptables/iptables.rules")
38
74
  when :emerge
75
+ @systemctl = Helpers::Exec.new("systemctl")
39
76
  @systemctl.run("start iptables-store")
40
77
  when :apt_get
41
78
  @iptables_save.run("> /etc/iptables/rules.v4")
@@ -16,7 +16,7 @@ module Spior
16
16
  def run
17
17
  if @options.install then
18
18
  Msg.head
19
- Spior::Install::deps
19
+ Spior::Install::check_deps
20
20
  Spior::Copy::config_files
21
21
  end
22
22
  if @options.tor then
@@ -27,10 +27,7 @@ module Spior
27
27
  Spior::Iptables::tor(@network.card)
28
28
  end
29
29
  if @options.persist then
30
- if not @network
31
- @network = Spior::Network.new(@options.interface)
32
- end
33
- Spior::Persist::all(@network.card)
30
+ Spior::Persist::all
34
31
  end
35
32
  end
36
33
  end
@@ -24,9 +24,50 @@ module Spior
24
24
  def check_deps
25
25
  Spior::Install::check_deps
26
26
  Spior::Copy::config_files
27
+ add_resolv
28
+ add_torrc
27
29
  verify_service
28
30
  end
29
31
 
32
+ def add_resolv
33
+ string = "nameserver 127.0.0.1"
34
+ Spior::Copy::backup("/etc/resolv.conf", /nameserver 127.0.0.1$/)
35
+ new_file = Helpers::NewFile.new(string, "resolv.conf", "/etc")
36
+ new_file.add
37
+ new_file.perm("root", "644")
38
+ end
39
+
40
+ def add_torrc
41
+ user = ""
42
+ pid = ""
43
+ dir = "DataDirectory /var/lib/tor/data"
44
+ case Nomansland::distro?
45
+ when :gentoo
46
+ user = "User tor"
47
+ pid = "PIDFile /run/tor/tor.pid"
48
+ end
49
+ string = <<EOF
50
+ # Generated by Spior
51
+ #{user}
52
+ #{pid}
53
+ #{dir}
54
+ GeoIPExcludeUnknown 1
55
+ DNSPort 127.0.0.1:9061
56
+ AutomapHostsOnResolve 1
57
+ AutomapHostsSuffixes .exit,.onion
58
+ SocksPort 9050
59
+ VirtualAddrNetworkIPv4 10.192.0.0/10
60
+ TransPort 9040 IsolateClientAddr IsolateClientProtocol IsolateDestAddr IsolateDestPort
61
+ TestSocks 1
62
+ MaxCircuitDirtiness 600
63
+ EOF
64
+ re = /# Generated by Spior/
65
+ Spior::Copy::backup("/etc/tor/torrc", re)
66
+ new_file = Helpers::NewFile.new(string, "torrc", "/etc/tor")
67
+ new_file.add
68
+ new_file.perm("root", "644")
69
+ end
70
+
30
71
  def search_dns
31
72
  9061
32
73
  end
@@ -54,10 +95,8 @@ module Spior
54
95
  if TTY::Which.exist?('systemctl')
55
96
  state = `systemctl is-active tor`.chomp
56
97
  if state == 'active'
57
- #puts "Restart tor"
58
98
  @systemctl.run('restart tor')
59
99
  else
60
- #puts "Start tor"
61
100
  @systemctl.run('start tor')
62
101
  end
63
102
  else
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "spior"
3
- s.version = "0.1.3"
4
- s.summary = "A tool to make TOR your default gateway and randomize your hardware"
3
+ s.version = "0.1.4"
4
+ s.summary = "A tool to make TOR your default gateway"
5
5
  s.description = <<-EOF
6
- A tool to make TOR your default gateway and randomize your hardware.
6
+ A tool to make TOR your default gateway
7
7
  EOF
8
8
  s.metadata = {
9
9
  "changelog_uri" => "https://github.com/szorfein/spior/blob/master/CHANGELOG.md",
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - szorfein
@@ -35,7 +35,7 @@ cert_chain:
35
35
  J/zT/q2Ac7BWpSLbv6p9lChBiEnD9j24x463LR5QQjDNS5SsjzRQfFuprsa9Nqf2
36
36
  Tw==
37
37
  -----END CERTIFICATE-----
38
- date: 2020-05-14 00:00:00.000000000 Z
38
+ date: 2020-05-21 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rainbow
@@ -93,7 +93,7 @@ dependencies:
93
93
  - - '='
94
94
  - !ruby/object:Gem::Version
95
95
  version: 0.4.2
96
- description: " A tool to make TOR your default gateway and randomize your hardware.\n"
96
+ description: " A tool to make TOR your default gateway\n"
97
97
  email: szorfein@protonmail.com
98
98
  executables:
99
99
  - spior
@@ -106,15 +106,13 @@ files:
106
106
  - CHANGELOG.md
107
107
  - LICENSE
108
108
  - README.md
109
+ - Rakefile
109
110
  - bin/spior
110
111
  - ext/ipt_mod.conf
111
112
  - ext/iptables.service
112
- - ext/resolv.conf
113
113
  - ext/ssh.conf
114
114
  - ext/sshd.conf
115
115
  - ext/sshuttle.service
116
- - ext/torrc/torrc_archlinux
117
- - ext/torrc/torrc_default
118
116
  - lib/spior/clear.rb
119
117
  - lib/spior/copy.rb
120
118
  - lib/spior/helpers.rb
@@ -159,7 +157,7 @@ requirements:
159
157
  rubygems_version: 3.1.2
160
158
  signing_key:
161
159
  specification_version: 4
162
- summary: A tool to make TOR your default gateway and randomize your hardware
160
+ summary: A tool to make TOR your default gateway
163
161
  test_files:
164
162
  - test/test_options.rb
165
163
  - test/test_install.rb
metadata.gz.sig CHANGED
Binary file
@@ -1 +0,0 @@
1
- nameserver 127.0.0.1
@@ -1,18 +0,0 @@
1
- DataDirectory /var/lib/tor/data
2
-
3
- Log notice stdout
4
-
5
- GeoIPExcludeUnknown 1
6
-
7
- ## Torified DNS
8
- DNSPort 127.0.0.1:9061
9
- AutomapHostsOnResolve 1
10
- AutomapHostsSuffixes .exit,.onion
11
-
12
- SocksPort 9050
13
-
14
- VirtualAddrNetworkIPv4 10.192.0.0/10
15
- TransPort 9040 IsolateClientAddr IsolateClientProtocol IsolateDestAddr IsolateDestPort
16
-
17
- TestSocks 1
18
- MaxCircuitDirtiness 600
@@ -1,20 +0,0 @@
1
- User tor
2
- PIDFile /run/tor/tor.pid
3
- DataDirectory /var/lib/tor/data
4
-
5
- Log notice stdout
6
-
7
- GeoIPExcludeUnknown 1
8
-
9
- ## Torified DNS
10
- DNSPort 127.0.0.1:9061
11
- AutomapHostsOnResolve 1
12
- AutomapHostsSuffixes .exit,.onion
13
-
14
- SocksPort 9050
15
-
16
- VirtualAddrNetworkIPv4 10.192.0.0/10
17
- TransPort 9040 IsolateClientAddr IsolateClientProtocol IsolateDestAddr IsolateDestPort
18
-
19
- TestSocks 1
20
- MaxCircuitDirtiness 600