spior 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ module Spior
2
+ module Menu
3
+ extend self
4
+
5
+ def run
6
+ banner
7
+ loop do
8
+ Msg.head
9
+ puts %q{Please select an option:
10
+
11
+ 1. Redirect traffic through tor
12
+ 2. Reload tor and change your ip
13
+ 3. Clear and restore your files
14
+ 4. Check info on your current ip
15
+ 5. Quit}
16
+
17
+ puts
18
+ print ">> "
19
+ case gets.chomp
20
+ when '1'
21
+ Spior::Iptables::Tor.new.run!
22
+ when '2'
23
+ Spior::Tor.restart
24
+ when '3'
25
+ Spior::Clear.all
26
+ when '4'
27
+ Spior::Status.info
28
+ when '5'
29
+ exit
30
+ end
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def banner
37
+ puts "┏━┓┏━┓╻┏━┓┏━┓"
38
+ puts "┗━┓┣━┛┃┃ ┃┣┳┛"
39
+ puts "┗━┛╹ ╹┗━┛╹┗╸"
40
+ # generated with toilet -F crop -f future spior
41
+ end
42
+ end
43
+ end
@@ -1,25 +1,32 @@
1
1
  require 'rainbow'
2
2
 
3
3
  module Msg
4
- def self.head
4
+ extend self
5
+
6
+ def head
5
7
  puts Rainbow("------------------------------------------------").cyan
6
8
  end
7
9
 
8
- def self.p(text)
10
+ def p(text)
9
11
  puts Rainbow("[").cyan + Rainbow("+").white + Rainbow("]").cyan + " " + text
10
12
  end
11
13
 
12
- def self.err(text)
14
+ def err(text)
13
15
  puts Rainbow("[").red + Rainbow("-").white + Rainbow("]").red + " " + text
14
16
  end
15
17
 
16
- def self.info(text)
18
+ def info(text)
17
19
  puts Rainbow("-").blue + Rainbow("-").white + Rainbow("-").blue + " " + text + " " + Rainbow("-").blue + Rainbow("-").white + Rainbow("-").blue
18
20
  end
19
21
 
20
- def self.report(text)
22
+ def report(text)
21
23
  puts ""
22
24
  info text
23
25
  puts "Please, report this issue at https://github.com/szorfein/spior/issues"
26
+ puts ""
27
+ end
28
+
29
+ def for_no_systemd
30
+ puts "Init system is not yet supported. You can contribute to add it."
24
31
  end
25
32
  end
@@ -1,5 +1,4 @@
1
1
  require 'interfacez'
2
- require_relative 'msg'
3
2
 
4
3
  module Spior
5
4
  class Network
@@ -1,15 +1,11 @@
1
1
  require 'optparse'
2
- require_relative 'reload'
3
- require_relative 'status'
4
- require_relative 'clear'
5
2
 
6
3
  module Spior
7
4
  class Options
8
- attr_reader :install , :mac , :interface , :tor , :persist
5
+ attr_reader :install , :tor , :persist
9
6
 
10
7
  def initialize(argv)
11
8
  @install = false
12
- @mac = false
13
9
  @tor = false
14
10
  @persist = false
15
11
  parse(argv)
@@ -19,45 +15,43 @@ module Spior
19
15
 
20
16
  def parse(argv)
21
17
  OptionParser.new do |opts|
22
- opts.on("-i", "--install", "Install and update dependencies") do
18
+ opts.on("-i", "--install", "Check and install dependencies") do
23
19
  @install = true
24
20
  end
25
21
 
26
- opts.on("-n", "--net-card NAME", "The name of the target network card") do |net|
27
- @interface = net
28
- end
29
-
30
- opts.on("-m", "--mac", "Change your mac") do
31
- @mac = true
32
- end
33
-
34
22
  opts.on("-t", "--tor", "Redirect traffic through TOR") do
35
23
  @tor = true
36
24
  end
37
25
 
38
26
  opts.on("-r", "--reload", "Reload TOR to change your ip") do
39
- Spior::Reload::tor
27
+ Spior::Tor.restart
28
+ exit
40
29
  end
41
30
 
42
- opts.on("-c", "--clear", "Clear iptables rules and restore files") do
43
- Spior::Clear::all
31
+ opts.on("-c", "--clearnet", "Reset iptables and return to clearnet navigation") do
32
+ Spior::Clear.all
44
33
  end
45
34
 
46
35
  opts.on("-s", "--status", "Look infos about your current ip") do
47
- Spior::Status::info
36
+ Spior::Status.info
37
+ exit
48
38
  end
49
39
 
50
40
  opts.on("-p", "--persist", "Active Spior at every boot.") do
51
41
  @persist = true
52
42
  end
53
43
 
44
+ opts.on("-m", "--menu", "Display an interactive menu") do
45
+ Spior::Menu.run
46
+ end
47
+
54
48
  opts.on("-h", "--help", "Show this message") do
55
49
  puts opts
56
50
  exit
57
51
  end
58
52
 
59
53
  begin
60
- argv = ["-h"] if argv.empty?
54
+ argv = ["-m"] if argv.empty?
61
55
  opts.parse!(argv)
62
56
  rescue OptionParser::ParseError => e
63
57
  STDERR.puts e.message, "\n", opts
@@ -1,38 +1,50 @@
1
1
  require 'nomansland'
2
2
  require 'tty-which'
3
- require_relative 'copy'
4
- require_relative 'msg'
5
3
 
6
4
  module Spior
7
5
  module Persist
8
6
  extend self
9
7
 
10
- def all(card_name)
11
- @card_name = card_name
12
- @services=[ "tor", "iptables", "deceitmac@" + @card_name ]
13
- search_for_systemd
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
14
15
  end
15
16
 
16
17
  private
17
18
 
18
- def search_for_systemd
19
- return if !TTY::Which.exist?('systemctl')
20
- Spior::Copy::systemd_services
21
- @services.each do |service|
22
- Msg.p "Search for service #{service}..."
23
- system("if ! systemctl is-enabled #{service} ; then sudo systemctl enable #{service} ; fi")
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")
24
30
  end
25
- iptables_systemd
26
31
  end
27
32
 
28
- def iptables_systemd
29
- case Nomansland::installer?
30
- when :pacman
31
- system('sudo iptables-save -f /etc/iptables/iptables.rules')
32
- when :emerge
33
- system('sudo systemctl start iptables-store')
34
- else
35
- Msg.report "Fail for save iptables-rule, your system is not yet supported"
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}")
36
48
  end
37
49
  end
38
50
  end
@@ -1,20 +1,38 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  require 'open-uri'
2
+ require 'json'
4
3
 
5
4
  module Spior
6
- class Status
5
+ module Status
6
+ def self.enable
7
+ begin
8
+ status = "Disable"
9
+ api_check = "https://check.torproject.org/api/ip"
10
+ URI.open(api_check) do |l|
11
+ hash = JSON.parse l.read
12
+ status = "Enable" if hash["IsTor"] == true
13
+ end
14
+ status
15
+ rescue OpenURI::HTTPError => error
16
+ res = error.io
17
+ puts "Fail to join server #{res.status}"
18
+ end
19
+ end
7
20
 
8
- # TODO: if someone want help, i have trouble to make JSON.parse() work here
9
- # the output is very very ugly !
10
21
  def self.info
11
- uri = URI.parse("https://ipleak.net/json")
12
- uri.open {|f|
13
- f.each_line {|line|
14
- p line.chomp.delete("/\",{}")
15
- }
16
- }
22
+ begin
23
+ api_check = "https://ipleak.net/json"
24
+ URI.open(api_check) do |l|
25
+ hash = JSON.parse l.read
26
+ puts
27
+ puts " Current ip ===> #{hash["ip"]}"
28
+ puts " Continent ===> #{hash["continent_name"]}"
29
+ puts " Timezone ===> #{hash["time_zone"]}"
30
+ end
31
+ puts " Status ===> #{enable}"
32
+ rescue OpenURI::HTTPError => error
33
+ res = error.io
34
+ puts "Fail to join server #{res.status}"
35
+ end
17
36
  end
18
-
19
37
  end
20
38
  end
@@ -1,41 +1,7 @@
1
- require 'pathname'
2
- require 'nomansland'
3
- require_relative 'msg'
4
-
5
1
  module Spior
6
- class Tor
7
- attr_accessor :dns, :uid, :trans_port, :virt_addr
8
-
9
- def initialize
10
- @dns = search_dns
11
- @uid = search_uid
12
- @trans_port = search_trans_port
13
- @virt_addr = search_virt_addr
14
- end
15
-
16
- private
17
-
18
- def search_dns
19
- 9061
20
- end
21
-
22
- def search_uid
23
- case Nomansland::distro?
24
- when :debian
25
- `id -u debian-tor`.chomp
26
- when :ubuntu
27
- `id -u debian-tor`.chomp
28
- else
29
- `id -u tor`.chomp
30
- end
31
- end
32
-
33
- def search_trans_port
34
- 9040
35
- end
36
-
37
- def search_virt_addr
38
- "10.192.0.0/10"
39
- end
2
+ module Tor
40
3
  end
41
4
  end
5
+
6
+ require_relative 'tor/info'
7
+ require_relative 'tor/restart'
@@ -0,0 +1,113 @@
1
+ require 'pathname'
2
+ require 'nomansland'
3
+ require 'tty-which'
4
+
5
+ module Spior
6
+ module Tor
7
+ class Info
8
+ attr_accessor :dns, :uid, :trans_port, :virt_addr
9
+
10
+ def initialize
11
+ @systemctl = Helpers::Exec.new("systemctl")
12
+ check_deps
13
+ @dns = search_dns
14
+ @uid = search_uid
15
+ @trans_port = search_trans_port
16
+ @virt_addr = search_virt_addr
17
+ end
18
+
19
+ private
20
+
21
+ def check_deps
22
+ Spior::Install::check_deps
23
+ Spior::Copy.new.save
24
+ add_resolv
25
+ add_torrc
26
+ verify_service
27
+ end
28
+
29
+ def add_resolv
30
+ string = "nameserver 127.0.0.1"
31
+ new_file = Helpers::NewFile.new(string, "resolv.conf", "/etc")
32
+ new_file.add
33
+ new_file.perm("root", "644")
34
+ end
35
+
36
+ def self.grep?(file, regex)
37
+ is_found = false
38
+ return is_found if ! File.exist? file
39
+ File.open(file) do |f|
40
+ f.each do |line|
41
+ is_found = true if line.match(regex)
42
+ end
43
+ end
44
+ is_found
45
+ end
46
+
47
+ def add_torrc
48
+ user = ""
49
+ pid = ""
50
+ dir = "DataDirectory /var/lib/tor/data"
51
+ case Nomansland::distro?
52
+ when :gentoo
53
+ user = "User tor"
54
+ pid = "PIDFile /run/tor/tor.pid"
55
+ end
56
+ string = <<EOF
57
+ # Generated by Spior
58
+ #{user}
59
+ #{pid}
60
+ #{dir}
61
+ GeoIPExcludeUnknown 1
62
+ DNSPort 127.0.0.1:9061
63
+ AutomapHostsOnResolve 1
64
+ AutomapHostsSuffixes .exit,.onion
65
+ SocksPort 9050
66
+ VirtualAddrNetworkIPv4 10.192.0.0/10
67
+ TransPort 9040 IsolateClientAddr IsolateClientProtocol IsolateDestAddr IsolateDestPort
68
+ TestSocks 1
69
+ MaxCircuitDirtiness 600
70
+ EOF
71
+ new_file = Helpers::NewFile.new(string, "torrc", "/etc/tor")
72
+ new_file.add
73
+ new_file.perm("root", "644")
74
+ end
75
+
76
+ def search_dns
77
+ 9061
78
+ end
79
+
80
+ def search_uid
81
+ case Nomansland::distro?
82
+ when :debian
83
+ `id -u debian-tor`.chomp
84
+ when :ubuntu
85
+ `id -u debian-tor`.chomp
86
+ else
87
+ `id -u tor`.chomp
88
+ end
89
+ end
90
+
91
+ def search_trans_port
92
+ 9040
93
+ end
94
+
95
+ def search_virt_addr
96
+ "10.192.0.0/10"
97
+ end
98
+
99
+ def verify_service
100
+ if TTY::Which.exist?('systemctl')
101
+ state = `systemctl is-active tor`.chomp
102
+ if state == 'active'
103
+ @systemctl.run('restart tor')
104
+ else
105
+ @systemctl.run('start tor')
106
+ end
107
+ else
108
+ Msg.for_no_systemd
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -1,11 +1,11 @@
1
1
  require 'tty-which'
2
- require_relative 'msg'
3
2
 
4
3
  module Spior
5
- module Reload
6
- def self.tor
4
+ module Tor
5
+ module_function
6
+ def restart
7
7
  if TTY::Which.exist?('systemctl')
8
- system('sudo systemctl restart tor')
8
+ Helpers::Exec.new("systemctl").run("restart tor")
9
9
  Msg.p "ip changed"
10
10
  end
11
11
  end