Class: Yast::WOLClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/WOL.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) Add(mac, host)



36
37
38
39
40
41
42
43
# File '../../src/modules/WOL.rb', line 36

def Add(mac, host)
  @mac_addresses = Builtins.add(
    @mac_addresses,
    { "mac" => mac, "host" => host }
  )
  @modified = true
  true
end

- (Object) Change(old_mac, mac, host)



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File '../../src/modules/WOL.rb', line 45

def Change(old_mac, mac, host)
  new = []
  Builtins.foreach(
    Convert.convert(
      @mac_addresses,
      :from => "list <map>",
      :to   => "list <map <string, any>>"
    )
  ) do |row|
    if Ops.get_string(row, "mac", "") != old_mac
      new = Builtins.add(new, row)
    else
      new = Builtins.add(new, { "mac" => mac, "host" => host })
    end
  end
  @mac_addresses = deep_copy(new)
  true
end

- (Object) main



28
29
30
31
32
33
34
# File '../../src/modules/WOL.rb', line 28

def main
  textdomain "wol"
  Yast.import "Popup"

  @mac_addresses = []
  @modified = false
end

- (Object) Overview



131
132
133
134
135
136
137
138
# File '../../src/modules/WOL.rb', line 131

def Overview
  overview = Builtins.maplist(@mac_addresses) do |m|
    mac = Ops.get_string(m, "mac", "")
    host = Ops.get_string(m, "host", "")
    Item(Id(mac), mac, host)
  end
  deep_copy(overview)
end

- (Object) Read



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File '../../src/modules/WOL.rb', line 64

def Read
  if Ops.greater_than(
      SCR.Read(path(".target.size"), "/var/lib/YaST2/wol"),
      0
    )
    wolfile = Convert.to_string(
      SCR.Read(path(".target.string"), "/var/lib/YaST2/wol")
    )
    pairs = Builtins.splitstring(wolfile, "\n")
    pairs = Builtins.filter(pairs) { |p| p != "" }
    @mac_addresses = Builtins.maplist(pairs) do |m|
      line = Builtins.splitstring(m, " ")
      { "mac" => Ops.get(line, 0, ""), "host" => Ops.get(line, 1, "") }
    end
  elsif Ops.greater_than(
      SCR.Read(path(".target.size"), "/etc/dhcpd.conf"),
      0
    )
    # read mac addr. from dhcpd.conf
    tmp = Ops.add(
      Convert.to_string(SCR.Read(path(".target.tmpdir"))),
      "/wol"
    )
    cmd = Builtins.sformat(
      "/usr/bin/wol-dhcpdconf < /etc/dhcpd.conf > %1",
      tmp
    )
    SCR.Execute(path(".target.bash"), cmd)
    wolfile = Convert.to_string(SCR.Read(path(".target.string"), tmp))
    pairs = Builtins.splitstring(wolfile, "\n")
    pairs = Builtins.filter(pairs) { |p| p != "" }
    @mac_addresses = Builtins.maplist(pairs) do |m|
      line = Builtins.splitstring(m, " ")
      { "mac" => Ops.get(line, 0, ""), "host" => Ops.get(line, 1, "") }
    end
    if Ops.greater_than(Builtins.size(@mac_addresses), 0)
      ret = Popup.YesNo(
        _(
          "No previously configured clients found.\n" +
            "However, a DHCP configuration was found on this system. Import the host\n" +
            "configuration data (MAC addresses and host names) from \n" +
            "'/etc/dhcpd.conf'?\n"
        )
      )
      if !ret
        @mac_addresses = []
      else
        @modified = true
      end
    end
  end
  true
end

- (Object) Write



118
119
120
121
122
123
124
125
126
127
128
129
# File '../../src/modules/WOL.rb', line 118

def Write
  Builtins.y2debug("mac_addresses: %1", @mac_addresses)
  lines = Builtins.maplist(@mac_addresses) do |m|
    Ops.add(
      Ops.add(Ops.get_string(m, "mac", ""), " "),
      Ops.get_string(m, "host", "")
    )
  end
  wolfile = Builtins.mergestring(lines, "\n")
  SCR.Write(path(".target.string"), "/var/lib/YaST2/wol", wolfile)
  true
end