Module: Yast::NisServerSlavesInclude

Defined in:
../../src/include/nis_server/slaves.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) ChooseHostName(hosts)

Give me one name from the list of hosts

Parameters:

  • hosts (Array<String>)

    list of hosts

Returns:

  • hostname or nil



61
62
63
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
# File '../../src/include/nis_server/slaves.rb', line 61

def ChooseHostName(hosts)
  hosts = deep_copy(hosts)
  hname = nil

  UI.OpenDialog(
    VBox(
      HSpacing(40),
      HBox(
        VSpacing(10),
        # To translators: selection box label
        SelectionBox(Id(:hosts), _("&Remote hosts"), hosts)
      ),
      HBox(
        PushButton(Id(:ok), Opt(:default), Label.OKButton),
        PushButton(Id(:cancel), Label.CancelButton)
      )
    )
  )
  ret = nil
  begin
    ret = UI.UserInput
  end while ret != :cancel && ret != :ok

  if ret == :ok
    hname = Convert.to_string(UI.QueryWidget(Id(:hosts), :CurrentItem))
  end

  UI.CloseDialog

  hname
end

- (Object) initialize_nis_server_slaves(include_target)



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File '../../src/include/nis_server/slaves.rb', line 42

def initialize_nis_server_slaves(include_target)
  Yast.import "UI"

  textdomain "nis_server"

  Yast.import "Hostname"
  Yast.import "Label"
  Yast.import "NisServer"
  Yast.import "Popup"
  Yast.import "Wizard"

  Yast.include include_target, "nis_server/routines.rb"

  @hosts = nil
end

- (Object) MastersSlavesDialog

Slaves dialog

Returns:

  • back,abort or `next



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File '../../src/include/nis_server/slaves.rb', line 173

def MastersSlavesDialog
  # help text 1/1
  helptext = _(
    "<p>Here, enter the names of hosts to configure as NIS server slaves. Use <i>Add</i> to add a new one, <i>Edit</i>  to change an existing entry, and <i>Delete</i> to remove an entry.</p>"
  )

  slaves = deep_copy(NisServer.ypservers)

  buttons = HBox(
    PushButton(Id(:add), Label.AddButton),
    PushButton(Id(:edit), Label.EditButton),
    PushButton(Id(:delete), Label.DeleteButton),
    HStretch()
  )

  contents = VBox(
    ReplacePoint(
      Id(:replace),
      # To translators: selection box label
      SelectionBox(
        Id(:slaves),
        Opt(:notify),
        _("&Slaves"),
        Builtins.sort(slaves)
      )
    ),
    buttons
  )

  # To translators: dialog label
  Wizard.SetContents(
    _("NIS Master Server Slaves Setup"),
    contents,
    helptext,
    true,
    true
  )

  ui = nil
  begin
    anyslaves = UI.QueryWidget(Id(:slaves), :CurrentItem) != nil
    UI.ChangeWidget(Id(:edit), :Enabled, anyslaves)
    UI.ChangeWidget(Id(:delete), :Enabled, anyslaves)

    ui = Convert.to_symbol(UI.UserInput)
    ui = :abort if ui == :cancel

    if ui == :edit
      selected = Convert.to_string(
        UI.QueryWidget(Id(:slaves), :CurrentItem)
      )
      next if selected == nil
      edited = YPSlavePopup(selected)
      if edited != nil
        slaves = Builtins.filter(slaves) { |e| e != selected }
        slaves = Builtins.add(slaves, edited)
        UI.ReplaceWidget(
          Id(:replace),
          SelectionBox(
            Id(:slaves),
            Opt(:notify),
            _("&Slaves"),
            Builtins.sort(slaves)
          )
        )
      end
    elsif ui == :delete
      selected = Convert.to_string(
        UI.QueryWidget(Id(:slaves), :CurrentItem)
      )
      next if selected == nil
      slaves = Builtins.filter(slaves) { |e| e != selected }
      UI.ReplaceWidget(
        Id(:replace),
        SelectionBox(
          Id(:slaves),
          Opt(:notify),
          _("&Slaves"),
          Builtins.sort(slaves)
        )
      )
    elsif ui == :add
      edited = YPSlavePopup("")
      if edited != nil && !Builtins.contains(slaves, edited)
        slaves = Builtins.add(slaves, edited)
        UI.ReplaceWidget(
          Id(:replace),
          SelectionBox(
            Id(:slaves),
            Opt(:notify),
            _("&Slaves"),
            Builtins.sort(slaves)
          )
        )
      end
    end

    ui = :again if ui == :abort && !Popup.ReallyAbort(NisServer.modified)
  end until Builtins.contains([:back, :next, :abort], ui)

  if ui == :next && Builtins.sort(NisServer.ypservers) != slaves
    NisServer.ypservers = deep_copy(slaves)
    NisServer.modified = true
  end

  ui
end

- (Object) YPSlavePopup(slave)

Popup for editing a slaver server hostname

Parameters:

  • slave (String)

    hostname

Returns:

  • hostname or nil if canceled



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File '../../src/include/nis_server/slaves.rb', line 97

def YPSlavePopup(slave)
  hbox = HBox(
    # To translators: textentry label
    InputField(Id(:slave), Opt(:hstretch), _("&Slave's host name"), slave),
    VBox(
      VSpacing(),
      PushButton(Id(:browse), Opt(:key_F6), Label.BrowseButton)
    )
  )

  contents = HBox(
    HSpacing(),
    VBox(
      VSpacing(0.3),
      # To translators: popup dialog heading
      Heading(_("Edit slave")),
      VSpacing(0.5),
      hbox,
      VSpacing(0.3),
      ButtonBox(
        PushButton(Id(:ok), Opt(:default), Label.OKButton),
        PushButton(Id(:cancel), Label.CancelButton)
      ),
      VSpacing(0.3)
    ),
    HSpacing()
  )

  UI.OpenDialog(contents)
  UI.SetFocus(Id(:slave))

  ui = nil
  begin
    ui = Convert.to_symbol(UI.UserInput)

    if ui == :ok
      slave = Builtins.tolower(
        Convert.to_string(UI.QueryWidget(Id(:slave), :Value))
      )

      if !Hostname.CheckFQ(slave)
        UI.SetFocus(Id(:slave))
        Popup.Error(Hostname.ValidFQ)
        ui = :again
      end
    elsif ui == :browse
      if @hosts == nil
        # To translators: label message
        UI.OpenDialog(Label(_("Scanning for hosts on this LAN...")))
        @hosts = Builtins.sort(
          Builtins.filter(
            Convert.convert(
              SCR.Read(path(".net.hostnames")),
              :from => "any",
              :to   => "list <string>"
            )
          ) { |host2| Hostname.CheckFQ(host2) }
        )
        UI.CloseDialog
        @hosts = [] if @hosts == nil
      end
      host = ChooseHostName(@hosts)
      if host != nil
        slave = host
        UI.ChangeWidget(Id(:slave), :Value, host)
      end
    end
  end until ui == :ok || ui == :cancel

  UI.CloseDialog

  ui == :ok ? slave : nil
end