Class: Hooray::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/hooray/settings.rb

Overview

App settings

Constant Summary collapse

CONFIG_DIR =
ENV['HOME'] + '/.hooray/'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.allObject

Returns the value of attribute all.



7
8
9
# File 'lib/hooray/settings.rb', line 7

def all
  @all
end

Class Method Details

.device(mac) ⇒ Object



40
41
42
# File 'lib/hooray/settings.rb', line 40

def device(mac)
  devices[mac.to_sym] || devices[mac.to_s]
end

.devicesObject



48
49
50
# File 'lib/hooray/settings.rb', line 48

def devices
  @devices ||= {}
end

.listObject



32
33
34
35
36
37
38
# File 'lib/hooray/settings.rb', line 32

def list
  out = 'SCAN: '
  out += ' SYN' if syn_scan
  out += ' SERVICE' if service_scan
  out += ' OS' if os_fingerprint
  out
end

.load!Object



15
16
17
18
19
20
21
# File 'lib/hooray/settings.rb', line 15

def load!
  no_config_folder unless Dir.exist?(CONFIG_DIR)
  @all = YAML.load_file(CONFIG_DIR + 'settings.yml')
  @services = YAML.load_file(CONFIG_DIR + 'services.yml')
  @devices  = YAML.load_file(CONFIG_DIR + 'devices.yml')
  read_mac_prefixes
end

.manufacturer(mac) ⇒ Object Also known as: family



60
61
62
63
# File 'lib/hooray/settings.rb', line 60

def manufacturer(mac)
  prefix = mac.to_s.gsub(':', '')[0, 6].upcase
  manufacturers[prefix]
end

.manufacturersObject



56
57
58
# File 'lib/hooray/settings.rb', line 56

def manufacturers
  @macs || {}
end

.method_missing(meth, *params) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/hooray/settings.rb', line 70

def method_missing(meth, *params)
  if meth =~ /=/
    all[meth.to_s.gsub('=', '')] = params.first
  else
    arg = meth.to_s.gsub('?', '')
    all[arg] || all[arg.to_sym]
  end
end

.no_config_folderObject



9
10
11
12
13
# File 'lib/hooray/settings.rb', line 9

def no_config_folder
  pa "No config folder, run `#{$PROGRAM_NAME} init`", :red
  puts
  exit 1
end

.read_mac_prefixesObject



23
24
25
26
27
28
29
30
# File 'lib/hooray/settings.rb', line 23

def read_mac_prefixes
  @macs = {}
  File.read(CONFIG_DIR + 'nmap-mac-prefixes').each_line do |line|
    next if line =~ /^\s*#/
    prefix, *name = *line.split(/\s/)
    @macs.store(prefix, name.join(' '))
  end
end

.service(name) ⇒ Object



44
45
46
# File 'lib/hooray/settings.rb', line 44

def service(name)
  services[name.to_sym] || services[name.to_s]
end

.servicesObject



52
53
54
# File 'lib/hooray/settings.rb', line 52

def services
  @services ||= {}
end