<commit_before>require 'win32ole'

Facter.add('firewall_rules') do
  confine :operatingsystem => 'windows'
  setcode do
    system_rules = WIN32OLE.new("HNetCfg.FwPolicy2").rules
    rule_hash = Hash.new()
    attr_names = Hash.new()
    attr_names['protocol'] = 'protocol'
    attr_names['localports'] = 'local_ports'
    attr_names['remoteports'] = 'remote_ports'
    attr_names['localaddresses'] = 'local_addresses'
    attr_names['remoteaddresses'] = 'remote_addresses'
    attr_names['direction'] = 'direction'
    attr_names['action'] = 'action'

    system_rules.select('enabled', true).each do |rule|
      attr_hash = Hash.new()
      attr_names.keys.each do |key|
        attr_value = rule.invoke(key)
        if attr_value != ''
          attr_hash[attr_names[key]] = attr_value
        end
      end
      rule_hash[rule.name] = attr_hash
    end

    return rule_hash
  end
end<commit_msg>firewall_rules fact in ruby<commit_after>require 'win32ole'

Facter.add('firewall_rules') do
  confine :operatingsystem => 'windows'
  setcode do
    system_rules = WIN32OLE.new("HNetCfg.FwPolicy2").rules
    rule_hash = Hash.new()
    attr_names = Hash.new()
    attr_names['protocol'] = 'protocol'
    attr_names['localports'] = 'local_ports'
    attr_names['remoteports'] = 'remote_ports'
    attr_names['localaddresses'] = 'local_addresses'
    attr_names['remoteaddresses'] = 'remote_addresses'
    attr_names['direction'] = 'direction'
    attr_names['action'] = 'action'

    system_rules.select('enabled', true).each do |rule|
      attr_hash = Hash.new()
      attr_names.keys.each do |key|
        attr_value = rule.invoke(key)
        if attr_value != ''
          attr_hash[attr_names[key]] = attr_value
        end
      end
      rule_hash[rule.name] = attr_hash
    end

    return rule_hash.to_json.to_s
  end
end
{'fraction_non_alphanumeric': 0.12561441835062806, 'fraction_numerical': 0.005461496450027308, 'mean_word_length': 3.4901960784313726, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6686323', 'n_tokens_mistral': 620, 'n_tokens_neox': 618, 'n_words': 108}