mullvadrb 0.0.5 → 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: 5ea238a3050a91a341b127d1592a584f5e3284c6a1d4a55efc54984f42721446
4
- data.tar.gz: ee88ee974f1cf2d0c0d2b8ecb2cdd0ed137d36a0784ab18f562ca90da9939d03
3
+ metadata.gz: 62025cd992ac7eb3131759b79871deac11d0005d138bc859ac0d25bce2cc0cc5
4
+ data.tar.gz: '0458bee533857011a1f195b710119c9f2e69a9d78a6051b01be9ff6da61834ba'
5
5
  SHA512:
6
- metadata.gz: 949b88bc19849a85ff9981b7e7e1e151cc766fb54289eb9f3d5fbf718654960c1dcfa66c5629f76b20f060f0c5be6e50e45498c9ef373617e253a726d731b00d
7
- data.tar.gz: 2e5c26fb1ffc1a2395dd4b993acf6b5b6bda7a806f378e2bbf16c7391a293cb58888be308b141395724ee3563c9196b7318a2f60b04d92f20e56dab722c523b8
6
+ metadata.gz: ab28e8cbbba0b1bb7428c9bc5ad2e2878cd55f3321dd081c0d16dc2222fb2e0840e196ff3ab08302a75bb2e0a9b2e3c196ecb2ce74e75b94d121128005aa1307
7
+ data.tar.gz: e8a804c0c70e5b9fd1e15cfe9a1b2c87af1d72616601ccdde35f57f63bf7fbd868ce5bf838023fef028081444f43a2bd682d557ae7f879fbd634be82c702e1e0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.0.6
2
+
3
+ - Adds DNS Blockers functionality.
4
+ - Refactors settings into `Mullvadrb::Settings` module.
5
+
1
6
  # 0.0.5
2
7
 
3
8
  - Updates display for menu, adds separation between main functionality and settings.
@@ -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:"
@@ -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
@@ -6,7 +6,9 @@ require 'tty-prompt'
6
6
  require 'mullvadrb/account'
7
7
  require 'mullvadrb/command_manager'
8
8
  require 'mullvadrb/connection'
9
+ require 'mullvadrb/dns'
9
10
  require 'mullvadrb/servers'
11
+ require 'mullvadrb/settings'
10
12
  require 'yaml'
11
13
 
12
14
  module Mullvadrb
@@ -15,71 +17,23 @@ module Mullvadrb
15
17
  # Main object instantiated, saves backend, i18n if set, and persists.
16
18
  class Main
17
19
  include Mullvadrb::CommandManager
18
- CONFIG_FILE = File.expand_path('~/.local/share/mullvadrb/mullvadrb.yml').freeze
19
20
 
20
21
  def initialize
21
22
  # To determine if we're using WireGuard or mullvad cli, attempt to load a pre-saved
22
23
  # configuration or prompt the user which one to use:
23
- load_config
24
- @backend ||= ask_backend
24
+ Mullvadrb::Settings.load_config
25
+ @backend ||= Mullvadrb::Settings.ask_backend
25
26
  puts I18n.t(:backend_using, backend: @backend)
26
27
  I18n.locale = @locale || I18n.default_locale
27
- save_config!
28
+ Mullvadrb::Settings.save_config!
28
29
  puts Mullvadrb::Connection.status
29
30
  end
30
31
 
31
- def ask_backend
32
- backend = TTY::Prompt.new.select(I18n.t(:backend_which), cycle: true) do |menu|
33
- menu.choice name: I18n.t(:backend_wg), value: 'wg'
34
- menu.choice name: I18n.t(:backend_mullvad), value: 'mullvad'
35
- end
36
- @wg = (backend == 'wg')
37
- require 'mullvadrb/wg_manager' if @wg
38
- backend
39
- end
40
-
41
- def languages
42
- language = TTY::Prompt.new.select(I18n.t(:language_which), cycle: true) do |menu|
43
- menu.choice name: I18n.t(:language_en), value: 'en'
44
- menu.choice name: I18n.t(:language_es), value: 'es'
45
- end
46
- @locale = language.to_sym
47
- I18n.locale = @locale
48
- save_config!
49
- end
50
-
51
- def load_config
52
- return unless File.exist?(CONFIG_FILE)
53
-
54
- config_file = YAML.load(File.read(CONFIG_FILE))
55
- @backend = config_file[:backend]
56
- @locale = config_file[:locale]
57
- @wg = (@backend == 'wg')
58
- load_servers unless @wg
59
- require 'mullvadrb/wg_manager' if @wg
60
- end
61
-
62
- def save_config!
63
- dir = File.expand_path('~/.local/share/mullvadrb/')
64
- system 'mkdir', '-p', dir unless File.exist?(dir)
65
- config = {
66
- backend: @backend,
67
- locale: @locale || I18n.locale
68
- }
69
- File.open(CONFIG_FILE, 'w+') do |f|
70
- f.write(config.to_yaml)
71
- end
72
- end
73
-
74
- def load_servers
75
- @servers = Mullvadrb::Servers.servers
76
- end
77
-
78
32
  def main_menu
79
33
  choices = common_menu_choices
80
34
  choices.merge!(mullvad_cli_choices) unless @wg
81
35
  choices.merge!({ "❌ #{I18n.t(:exit)}" => 'exit' })
82
- 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)
83
37
  end
84
38
 
85
39
  def common_menu_choices
@@ -90,7 +44,8 @@ module Mullvadrb
90
44
  "🗺 #{I18n.t(:choose_specific)}" => 'specific',
91
45
  "🔌 #{I18n.t(:disconnect)}" => 'disconnect',
92
46
  "⚙ #{I18n.t(:change_backend)}" => 'backend',
93
- "🗣 #{I18n.t(:languages)}" => 'languages'
47
+ "🗣 #{I18n.t(:languages)}" => 'languages',
48
+ "📟 #{I18n.t(:dns_blockers)}" => 'dns_blockers'
94
49
  }
95
50
  end
96
51
 
@@ -113,7 +68,7 @@ module Mullvadrb
113
68
  when 'status', 'disconnect', 'country', 'specific', 'random'
114
69
  send(selection)
115
70
  when 'backend'
116
- ask_backend
71
+ Mullvadrb::Settings.ask_backend
117
72
  # Only when using mullvad cli and not wg:
118
73
  when 'update_servers'
119
74
  Mullvadrb::Servers.update
@@ -126,7 +81,9 @@ module Mullvadrb
126
81
  when 'account_devices'
127
82
  Mullvadrb::Account.devices
128
83
  when 'languages'
129
- languages
84
+ Mullvadrb::Settings.languages
85
+ when 'dns_blockers'
86
+ Mullvadrb::DNS.blockers
130
87
  end
131
88
  rescue SystemExit, Interrupt
132
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.5'
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']
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.5
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-21 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,7 +70,9 @@ 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
@@ -81,7 +82,6 @@ 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
84
  source_code_uri: https://github.com/picandocodigo/mullvadrb
84
- post_install_message:
85
85
  rdoc_options: []
86
86
  require_paths:
87
87
  - lib
@@ -96,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
- rubygems_version: 3.5.23
100
- signing_key:
99
+ rubygems_version: 3.6.3
101
100
  specification_version: 4
102
101
  summary: A TUI to use with Mullvad VPN
103
102
  test_files: []