Top Level Namespace

Defined Under Namespace

Modules: ApplicationHelper, ClientHelper, JobHelper, JobmediaHelper, MediaHelper, MiscHelper, PoolHelper Classes: ApplicationController, Client, ClientController, Job, JobController, Jobmedia, JobmediaController, Media, MediaController, MiscController, Pool, PoolController

Instance Method Summary collapse

Instance Method Details

#build_client_map(path, glob) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/client_finder.rb', line 54

def build_client_map(path, glob)
  path = path || '/etc/bacula'
  glob = glob || '*.conf'
  conf = config_file_ingest(File.join(path, glob))
  map = {}
  begin
    for e in conf
      if e[0] and e[0][1] == 'client'
        name = e.assoc('name')
        addr = e.assoc('address')
        port = e.assoc('port')
        if name and addr
          map[name[1]] = addr[1] + (port ? (':' + port[1]) : '')
        end
      end
    end
  rescue
    printf "Error extracting client name/host address pairs\n"
    return {}
  end
  return map
end

#config_file_ingest(path) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/client_finder.rb', line 36

def config_file_ingest(path)
  files = 0
  cfg = []
  Dir.glob(path).each { |fn|
    begin
      fd = File.open(fn)
      while (e = get_element(fd))
        cfg << e
      end
    rescue
      print "Error processing config file ", fn, "\n"
    end
    files = files + 1
  }
  print "Read ", files, " configuration files from ", path, "\n"
  return cfg
end

#get_element(fd) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/client_finder.rb', line 23

def get_element(fd)
  t = get_token(fd)
  if !t or t[0] != '{'
    return t
  else
    element = [ t ]
    begin
      element << ( t = get_element(fd) )
    end until t[0] == '}'
    return element
  end
end

#get_token(fd) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/client_finder.rb', line 1

def get_token(fd)
  if (r = fd.gets)
    r.strip!
    doc = r.sub!(/\s*(#.*)/, '') ? $1 : nil        
    case r
    when /\s*(\w+)\s*\{/
      return [ '{', $1, doc ]
    when /\s*(\w+(\s+\w+)?)\s*=\s*(.+)/
      return [ $1.downcase.tr(' ', ''), $3, doc ]
    when /\s*\}/
      return [ '}', nil, doc ]
    when /^\s*@(.*)/
      return [ '@', $1, doc ]
    when /^$/
      return [ nil, nil, doc ]
    else
      p [ :ELSE, r ]
      return []
    end
  end
end