mullvadrb 0.0.5 → 0.0.7

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: 6d3b81115b6138a117c121c0725b47153364d8dc37f8515a3e933491360fa7d1
4
+ data.tar.gz: 795ea1aced15a02a1fd3bf4f43c154e63ac424ef039db87a888fac02070a2008
5
5
  SHA512:
6
- metadata.gz: 949b88bc19849a85ff9981b7e7e1e151cc766fb54289eb9f3d5fbf718654960c1dcfa66c5629f76b20f060f0c5be6e50e45498c9ef373617e253a726d731b00d
7
- data.tar.gz: 2e5c26fb1ffc1a2395dd4b993acf6b5b6bda7a806f378e2bbf16c7391a293cb58888be308b141395724ee3563c9196b7318a2f60b04d92f20e56dab722c523b8
6
+ metadata.gz: 8c31f37cb83e5b10c0ede4534f6ba1590f0d51671b88fd9a710e5ac3dda1a69a51c0c88b197af82b6d40a62701d69afff3ca22bdf8ad817384852811ae57c62a
7
+ data.tar.gz: 7fd4c145ea2e57481a48ff103fb9703f70c353d049fee924d1917fcb606b67e47b096ec9390e849cc667e93b2ecc4028326367f35b1593ad1632474a136ba41b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.0.7
2
+
3
+ - Fixes settings configuration, updates Settings code.
4
+
5
+ # 0.0.6
6
+
7
+ - Adds DNS Blockers functionality.
8
+ - Refactors settings into `Mullvadrb::Settings` module.
9
+
1
10
  # 0.0.5
2
11
 
3
12
  - 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,52 @@
1
+ module Mullvadrb
2
+ module Settings
3
+ CONFIG_FILE = File.expand_path('~/.local/share/mullvadrb/mullvadrb.yml').freeze
4
+
5
+ def load_config
6
+ return unless File.exist?(CONFIG_FILE)
7
+
8
+ config_file = YAML.load(File.read(CONFIG_FILE))
9
+ @backend = config_file[:backend]
10
+ @locale = config_file[:locale]
11
+ @wg = (@backend == 'wg')
12
+ load_servers unless @wg
13
+ require 'mullvadrb/wg_manager' if @wg
14
+ end
15
+
16
+ def save_config!
17
+ dir = File.expand_path('~/.local/share/mullvadrb/')
18
+ system 'mkdir', '-p', dir unless File.exist?(dir)
19
+ config = {
20
+ backend: @backend,
21
+ locale: @locale || I18n.locale
22
+ }
23
+ File.open(CONFIG_FILE, 'w+') do |f|
24
+ f.write(config.to_yaml)
25
+ end
26
+ end
27
+
28
+ def load_servers
29
+ @servers = Mullvadrb::Servers.servers
30
+ end
31
+
32
+ def ask_backend
33
+ backend = TTY::Prompt.new.select(I18n.t(:backend_which), cycle: true) do |menu|
34
+ menu.choice name: I18n.t(:backend_wg), value: 'wg'
35
+ menu.choice name: I18n.t(:backend_mullvad), value: 'mullvad'
36
+ end
37
+ @wg = (backend == 'wg')
38
+ require 'mullvadrb/wg_manager' if @wg
39
+ backend
40
+ end
41
+
42
+ def languages
43
+ language = TTY::Prompt.new.select(I18n.t(:language_which), cycle: true) do |menu|
44
+ menu.choice name: I18n.t(:language_en), value: 'en'
45
+ menu.choice name: I18n.t(:language_es), value: 'es'
46
+ end
47
+ @locale = language.to_sym
48
+ I18n.locale = @locale
49
+ save_config!
50
+ end
51
+ end
52
+ 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,24 @@ 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
20
+ include Mullvadrb::Settings
19
21
 
20
22
  def initialize
21
23
  # To determine if we're using WireGuard or mullvad cli, attempt to load a pre-saved
22
24
  # configuration or prompt the user which one to use:
23
25
  load_config
24
- @backend ||= ask_backend
26
+ @backend ||= Mullvadrb::Settings.ask_backend
25
27
  puts I18n.t(:backend_using, backend: @backend)
26
28
  I18n.locale = @locale || I18n.default_locale
27
29
  save_config!
28
30
  puts Mullvadrb::Connection.status
29
31
  end
30
32
 
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
33
  def main_menu
79
34
  choices = common_menu_choices
80
35
  choices.merge!(mullvad_cli_choices) unless @wg
81
36
  choices.merge!({ "❌ #{I18n.t(:exit)}" => 'exit' })
82
- TTY::Prompt.new.select(I18n.t(:main_menu), choices, cycle: true, per_page: 12)
37
+ TTY::Prompt.new.select(I18n.t(:main_menu), choices, cycle: true, per_page: 20)
83
38
  end
84
39
 
85
40
  def common_menu_choices
@@ -90,7 +45,8 @@ module Mullvadrb
90
45
  "🗺 #{I18n.t(:choose_specific)}" => 'specific',
91
46
  "🔌 #{I18n.t(:disconnect)}" => 'disconnect',
92
47
  "⚙ #{I18n.t(:change_backend)}" => 'backend',
93
- "🗣 #{I18n.t(:languages)}" => 'languages'
48
+ "🗣 #{I18n.t(:languages)}" => 'languages',
49
+ "📟 #{I18n.t(:dns_blockers)}" => 'dns_blockers'
94
50
  }
95
51
  end
96
52
 
@@ -127,6 +83,8 @@ module Mullvadrb
127
83
  Mullvadrb::Account.devices
128
84
  when 'languages'
129
85
  languages
86
+ when 'dns_blockers'
87
+ Mullvadrb::DNS.blockers
130
88
  end
131
89
  rescue SystemExit, Interrupt
132
90
  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.7'
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.7
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: []