Class: VagrantPlugins::VagrantWinNFSd::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-winnfsd/plugin.rb

Class Method Summary collapse

Class Method Details

.init_pluginObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/vagrant-winnfsd/plugin.rb', line 37

def self.init_plugin
  I18n.load_path << File.expand_path('locales/en.yml', VagrantWinNFSd.source_root)
  I18n.reload!

  rule_name = "VagrantWinNFSd-".concat(VagrantPlugins::VagrantWinNFSd::VERSION)
  program = VagrantWinNFSd.get_path_for_file("winnfsd.exe")
  rule_exist = "netsh advfirewall firewall show rule name=\"%s\">nul"

  unless system(sprintf(rule_exist, rule_name))
    cleanup_rule = "advfirewall firewall delete rule name='winnfsd.exe'"
    rule = "advfirewall firewall add rule name='%s' dir='%s' action=allow protocol=any program='%s' profile=any"
    in_rule = sprintf(rule, rule_name, 'in', program)
    out_rule = sprintf(rule, rule_name, 'out', program)

    firewall_script = VagrantWinNFSd.get_path_for_file("setupfirewall.vbs")
    firewall_rule = "cscript //nologo #{firewall_script} \"#{cleanup_rule}\" \"#{in_rule}\" \"#{out_rule}\""

    unless system(firewall_rule)
      puts I18n.t("vagrant_winnfsd.firewall.error")
      puts "#{in_rule}\n"
      puts "#{out_rule}\n"
    end
  end
end