mullvadrb 0.0.4 → 0.0.6

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: 6b06202dd0245fa8332044957b4915e35b1d5ef452e99e84a0c757bbe829b0c4
4
- data.tar.gz: 7cce851045dacc5223bd0dde4ae672745d02f017fa4628339595c889c0d8b218
3
+ metadata.gz: 62025cd992ac7eb3131759b79871deac11d0005d138bc859ac0d25bce2cc0cc5
4
+ data.tar.gz: '0458bee533857011a1f195b710119c9f2e69a9d78a6051b01be9ff6da61834ba'
5
5
  SHA512:
6
- metadata.gz: 5d93386a5e958dfce396a29da52b2c245799abf3816056889494dcc3315bb7e23087487dd113f07f407c781f72a757a240924c605c770cb35adfe970e3dac2e3
7
- data.tar.gz: e1025f30b585fd45917c8d96ff837a4da6665019e8f982b217c237c923e86d3fd5d6c8ae176f91a560409a22291e070ca2981b26c5f5286efa4f0f17dce00a88
6
+ metadata.gz: ab28e8cbbba0b1bb7428c9bc5ad2e2878cd55f3321dd081c0d16dc2222fb2e0840e196ff3ab08302a75bb2e0a9b2e3c196ecb2ce74e75b94d121128005aa1307
7
+ data.tar.gz: e8a804c0c70e5b9fd1e15cfe9a1b2c87af1d72616601ccdde35f57f63bf7fbd868ce5bf838023fef028081444f43a2bd682d557ae7f879fbd634be82c702e1e0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 0.0.6
2
+
3
+ - Adds DNS Blockers functionality.
4
+ - Refactors settings into `Mullvadrb::Settings` module.
5
+
6
+ # 0.0.5
7
+
8
+ - Updates display for menu, adds separation between main functionality and settings.
9
+ - Sets the process name to 'mullvadrb'
10
+
1
11
  # 0.0.4
2
12
 
3
13
  Adds support for internationalization, translations can be added easily now. ¡Disponible en Español! The configuration file `backend.conf` has been replaced by `mullvadrb.yml` which will store the backend and locale preferences.
@@ -11,7 +11,7 @@ en:
11
11
  connecting: "📞 Connecting ☎ \n"
12
12
  connecting_to: "Connecting to %{server}"
13
13
  devices: "Devices"
14
- disconnect: "Disconnect"
14
+ disconnect: "Disconnect\n"
15
15
  disconnected: "\n⚠ 🚨 DISCONNECTED 🚨⚠"
16
16
  error_connecting: "Error connecting"
17
17
  error_disconnecting: "Error disconnecting"
@@ -31,3 +31,5 @@ en:
31
31
  language_which: "Which language would you like to use?"
32
32
  language_en: "English"
33
33
  language_es: "Spanish"
34
+ dns_blockers: "DNS Blockers"
35
+ dns_blockers_menu: "DNS Blockers - Press Enter↲ to confirm:"
@@ -11,7 +11,7 @@ es:
11
11
  connecting: "📞 Conectando ☎ \n"
12
12
  connecting_to: "Conectándose a %{server}"
13
13
  devices: "Dispositivos"
14
- disconnect: "Desconectar"
14
+ disconnect: "Desconectar\n"
15
15
  disconnected: "\n⚠ 🚨 DESCONECTADO 🚨⚠"
16
16
  error_connecting: "Error conectando"
17
17
  error_disconnecting: "Error desconectando "
@@ -31,3 +31,5 @@ es:
31
31
  language_which: "¿Qué idioma quieres usar?"
32
32
  language_en: "Inglés"
33
33
  language_es: "Español"
34
+ dns_blockers: "Bloqueadores DNS"
35
+ dns_blockers_menu: "Bloqueadores DNS - Presiona Enter↲ para confirmar:"
@@ -0,0 +1,49 @@
1
+ module Mullvadrb
2
+ # Displays a menu to set DNS blockers
3
+ module DNS
4
+ class << self
5
+ def blockers
6
+ status = cli_status
7
+ selected = selected(status)
8
+
9
+ choices = TTY::Prompt.new.multi_select(I18n.t(:dns_blockers_menu)) do |menu|
10
+ menu.default(*selected) unless selected.empty?
11
+ status.each_key do |k|
12
+ menu.choice k.to_sym
13
+ end
14
+ end
15
+
16
+ puts `mullvad dns set default #{cli_parameters(choices)}`
17
+ end
18
+
19
+ # Sets the parameters as arguments for `mullvad dns set``
20
+ def cli_parameters(choices)
21
+ choices.map do |choice|
22
+ "--block-#{choice.gsub(' ', '-')}"
23
+ end.join(' ')
24
+ end
25
+
26
+ # Gets the current status to show ones already selected
27
+ def cli_status
28
+ status = {}
29
+ data = `mullvad dns get`.gsub('Block ', '').split("\n").reject { |a| a.start_with?('Custom') }
30
+ data.map { |a| a.split(':') }.map do |entry|
31
+ status[entry[0]] = convert_to_boolean(entry[1].strip)
32
+ end
33
+ status
34
+ end
35
+
36
+ # Get the index of the values that are already set (true). The multi_select uses `menu.default
37
+ # 1, 2, n` to display selected: To mark choice(s) as selected use the default option with
38
+ # either index(s) of the choice(s) starting from 1 or choice name(s) (why I add 1 to i)
39
+ def selected(status)
40
+ status.map.with_index { |(_, v), i| (i + 1) if v == true }.compact
41
+ end
42
+
43
+ # Convert string to booleans
44
+ def convert_to_boolean(string)
45
+ !!(string == 'true')
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,54 @@
1
+ module Mullvadrb
2
+ module Settings
3
+ CONFIG_FILE = File.expand_path('~/.local/share/mullvadrb/mullvadrb.yml').freeze
4
+
5
+ class << self
6
+ def load_config
7
+ return unless File.exist?(CONFIG_FILE)
8
+
9
+ config_file = YAML.load(File.read(CONFIG_FILE))
10
+ @backend = config_file[:backend]
11
+ @locale = config_file[:locale]
12
+ @wg = (@backend == 'wg')
13
+ load_servers unless @wg
14
+ require 'mullvadrb/wg_manager' if @wg
15
+ end
16
+
17
+ def save_config!
18
+ dir = File.expand_path('~/.local/share/mullvadrb/')
19
+ system 'mkdir', '-p', dir unless File.exist?(dir)
20
+ config = {
21
+ backend: @backend,
22
+ locale: @locale || I18n.locale
23
+ }
24
+ File.open(CONFIG_FILE, 'w+') do |f|
25
+ f.write(config.to_yaml)
26
+ end
27
+ end
28
+
29
+ def load_servers
30
+ @servers = Mullvadrb::Servers.servers
31
+ end
32
+
33
+ def ask_backend
34
+ backend = TTY::Prompt.new.select(I18n.t(:backend_which), cycle: true) do |menu|
35
+ menu.choice name: I18n.t(:backend_wg), value: 'wg'
36
+ menu.choice name: I18n.t(:backend_mullvad), value: 'mullvad'
37
+ end
38
+ @wg = (backend == 'wg')
39
+ require 'mullvadrb/wg_manager' if @wg
40
+ backend
41
+ end
42
+
43
+ def languages
44
+ language = TTY::Prompt.new.select(I18n.t(:language_which), cycle: true) do |menu|
45
+ menu.choice name: I18n.t(:language_en), value: 'en'
46
+ menu.choice name: I18n.t(:language_es), value: 'es'
47
+ end
48
+ @locale = language.to_sym
49
+ I18n.locale = @locale
50
+ save_config!
51
+ end
52
+ end
53
+ end
54
+ end
data/lib/mullvadrb.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
+ Process.setproctitle('mullvadrb')
2
3
 
3
4
  require 'i18n'
4
5
  require 'tty-prompt'
5
6
  require 'mullvadrb/account'
6
7
  require 'mullvadrb/command_manager'
7
8
  require 'mullvadrb/connection'
9
+ require 'mullvadrb/dns'
8
10
  require 'mullvadrb/servers'
11
+ require 'mullvadrb/settings'
9
12
  require 'yaml'
10
13
 
11
14
  module Mullvadrb
@@ -14,71 +17,23 @@ module Mullvadrb
14
17
  # Main object instantiated, saves backend, i18n if set, and persists.
15
18
  class Main
16
19
  include Mullvadrb::CommandManager
17
- CONFIG_FILE = File.expand_path('~/.local/share/mullvadrb/mullvadrb.yml').freeze
18
20
 
19
21
  def initialize
20
22
  # To determine if we're using WireGuard or mullvad cli, attempt to load a pre-saved
21
23
  # configuration or prompt the user which one to use:
22
- load_config
23
- @backend ||= ask_backend
24
+ Mullvadrb::Settings.load_config
25
+ @backend ||= Mullvadrb::Settings.ask_backend
24
26
  puts I18n.t(:backend_using, backend: @backend)
25
27
  I18n.locale = @locale || I18n.default_locale
26
- save_config!
28
+ Mullvadrb::Settings.save_config!
27
29
  puts Mullvadrb::Connection.status
28
30
  end
29
31
 
30
- def ask_backend
31
- backend = TTY::Prompt.new.select(I18n.t(:backend_which), cycle: true) do |menu|
32
- menu.choice name: I18n.t(:backend_wg), value: 'wg'
33
- menu.choice name: I18n.t(:backend_mullvad), value: 'mullvad'
34
- end
35
- @wg = (backend == 'wg')
36
- require 'mullvadrb/wg_manager' if @wg
37
- backend
38
- end
39
-
40
- def languages
41
- language = TTY::Prompt.new.select(I18n.t(:language_which), cycle: true) do |menu|
42
- menu.choice name: I18n.t(:language_en), value: 'en'
43
- menu.choice name: I18n.t(:language_es), value: 'es'
44
- end
45
- @locale = language.to_sym
46
- I18n.locale = @locale
47
- save_config!
48
- end
49
-
50
- def load_config
51
- return unless File.exist?(CONFIG_FILE)
52
-
53
- config_file = YAML.load(File.read(CONFIG_FILE))
54
- @backend = config_file[:backend]
55
- @locale = config_file[:locale]
56
- @wg = (@backend == 'wg')
57
- load_servers unless @wg
58
- require 'mullvadrb/wg_manager' if @wg
59
- end
60
-
61
- def save_config!
62
- dir = File.expand_path('~/.local/share/mullvadrb/')
63
- system 'mkdir', '-p', dir unless File.exist?(dir)
64
- config = {
65
- backend: @backend,
66
- locale: @locale || I18n.locale
67
- }
68
- File.open(CONFIG_FILE, 'w+') do |f|
69
- f.write(config.to_yaml)
70
- end
71
- end
72
-
73
- def load_servers
74
- @servers = Mullvadrb::Servers.servers
75
- end
76
-
77
32
  def main_menu
78
33
  choices = common_menu_choices
79
34
  choices.merge!(mullvad_cli_choices) unless @wg
80
35
  choices.merge!({ "❌ #{I18n.t(:exit)}" => 'exit' })
81
- TTY::Prompt.new.select(I18n.t(:main_menu), choices, cycle: true, per_page: 12)
36
+ TTY::Prompt.new.select(I18n.t(:main_menu), choices, cycle: true, per_page: 20)
82
37
  end
83
38
 
84
39
  def common_menu_choices
@@ -89,7 +44,8 @@ module Mullvadrb
89
44
  "🗺 #{I18n.t(:choose_specific)}" => 'specific',
90
45
  "🔌 #{I18n.t(:disconnect)}" => 'disconnect',
91
46
  "⚙ #{I18n.t(:change_backend)}" => 'backend',
92
- "🗣 #{I18n.t(:languages)}" => 'languages'
47
+ "🗣 #{I18n.t(:languages)}" => 'languages',
48
+ "📟 #{I18n.t(:dns_blockers)}" => 'dns_blockers'
93
49
  }
94
50
  end
95
51
 
@@ -112,7 +68,7 @@ module Mullvadrb
112
68
  when 'status', 'disconnect', 'country', 'specific', 'random'
113
69
  send(selection)
114
70
  when 'backend'
115
- ask_backend
71
+ Mullvadrb::Settings.ask_backend
116
72
  # Only when using mullvad cli and not wg:
117
73
  when 'update_servers'
118
74
  Mullvadrb::Servers.update
@@ -125,7 +81,9 @@ module Mullvadrb
125
81
  when 'account_devices'
126
82
  Mullvadrb::Account.devices
127
83
  when 'languages'
128
- languages
84
+ Mullvadrb::Settings.languages
85
+ when 'dns_blockers'
86
+ Mullvadrb::DNS.blockers
129
87
  end
130
88
  rescue SystemExit, Interrupt
131
89
  abort("\n\nTioraidh!\n")
data/mullvadrb.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mullvadrb'
3
- s.version = '0.0.4'
3
+ s.version = '0.0.6'
4
4
  s.summary = 'A TUI to use with Mullvad VPN'
5
5
  s.description = 'A Terminal User Interface to use with Mullvad VPN'
6
6
  s.authors = ['Fernando Briano']
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.files = `git ls-files`.split($/)
9
9
  s.require_paths = ['lib']
10
10
  s.homepage = 'https://github.com/picandocodigo/mullvad-ruby'
11
- s.license = 'GPL-3.0'
11
+ s.license = 'GPL-3.0-only'
12
12
  s.required_ruby_version = '>= 3.0'
13
13
  s.executables << 'mullvadrb'
14
14
  s.add_dependency 'countries'
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
17
17
  s.metadata = {
18
18
  'bug_tracker_uri' => 'https://github.com/picandocodigo/mullvadrb/issues',
19
19
  'changelog_uri' => 'https://github.com/picandocodigo/mullvadrb/blob/master/CHANGELOG.md',
20
- 'homepage_uri' => 'https://github.com/picandocodigo/mullvadrb',
21
20
  'source_code_uri' => 'https://github.com/picandocodigo/mullvadrb'
22
21
  }
23
22
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mullvadrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Briano
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-07 00:00:00.000000000 Z
10
+ date: 2025-05-13 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: countries
@@ -71,18 +70,18 @@ files:
71
70
  - lib/mullvadrb/account.rb
72
71
  - lib/mullvadrb/command_manager.rb
73
72
  - lib/mullvadrb/connection.rb
73
+ - lib/mullvadrb/dns.rb
74
74
  - lib/mullvadrb/servers.rb
75
+ - lib/mullvadrb/settings.rb
75
76
  - lib/mullvadrb/wg_manager.rb
76
77
  - mullvadrb.gemspec
77
78
  homepage: https://github.com/picandocodigo/mullvad-ruby
78
79
  licenses:
79
- - GPL-3.0
80
+ - GPL-3.0-only
80
81
  metadata:
81
82
  bug_tracker_uri: https://github.com/picandocodigo/mullvadrb/issues
82
83
  changelog_uri: https://github.com/picandocodigo/mullvadrb/blob/master/CHANGELOG.md
83
- homepage_uri: https://github.com/picandocodigo/mullvadrb
84
84
  source_code_uri: https://github.com/picandocodigo/mullvadrb
85
- post_install_message:
86
85
  rdoc_options: []
87
86
  require_paths:
88
87
  - lib
@@ -97,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
96
  - !ruby/object:Gem::Version
98
97
  version: '0'
99
98
  requirements: []
100
- rubygems_version: 3.5.23
101
- signing_key:
99
+ rubygems_version: 3.6.3
102
100
  specification_version: 4
103
101
  summary: A TUI to use with Mullvad VPN
104
102
  test_files: []