Class: VagrantWinNFSd::Plugin

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

Class Method Summary collapse

Class Method Details

.init_pluginObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/vagrant-winnfsd/plugin.rb', line 52

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

  rule_name = 'VagrantWinNFSd-'.concat(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)
    xp_rule = "netsh firewall add allowedprogram \"#{program}\" #{rule_name} ENABLE"

    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 "netsh #{in_rule}\n"
      puts "netsh #{out_rule}\n"
      puts I18n.t('vagrant_winnfsd.firewall.xp_error')
      puts xp_rule
    end
  end
end