Module: Yast::NetworkWidgetsInclude

Defined in:
../../src/include/network/widgets.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) common_mtu_items



250
251
252
253
254
255
256
257
# File '../../src/include/network/widgets.rb', line 250

def common_mtu_items
  [
    # translators: MTU value description (size in bytes, desc)
    ["1500", _("1500 (Ethernet, DSL broadband)")],
    ["1492", _("1492 (PPPoE broadband)")],
    ["576", _("576 (dial-up)")]
  ]
end

- (Object) CreateSlaveItems(itemIds, enslavedIfaces)

Builds content for slave configuration dialog (used e.g. when configuring bond slaves) according the given list of itemIds (see LanItems::Items)

Parameters:

  • itemIds (Array<Fixnum>)

    list of indexes into LanItems::Items

  • enslavedIfaces (Array<String>)

    list of device names of already enslaved devices

Raises:

  • (ArgumentError)


542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File '../../src/include/network/widgets.rb', line 542

def CreateSlaveItems(itemIds, enslavedIfaces)
  raise ArgumentError, "no slave device defined" if itemIds.nil?

  items = []

  itemIds.each do |itemId|
    dev_name = LanItems.GetDeviceName(itemId)

    next if dev_name.nil? || dev_name.empty?

    dev_type = LanItems.GetDeviceType(itemId)

    if ["tun", "tap"].include? dev_type
      description = NetworkInterfaces.GetDevTypeDescription(dev_type, true)
    else
      ifcfg = LanItems.GetDeviceMap(itemId) || {}

      description = BuildDescription(
        dev_type,
        dev_name,
        ifcfg,
        [LanItems.GetLanItem(itemId)["hwinfo"] || {}]
      )

      # this conditions origin from bridge configuration
      # if enslaving a configured device then its configuration is rewritten
      # to "0.0.0.0/32"
      #
      # translators: a note that listed device is already configured
      description += " " + _("configured") if ifcfg["IPADDR"] != "0.0.0.0"
    end

    selected = false
    selected = enslavedIfaces.include?(dev_name) if enslavedIfaces

    items << Item(
      Id(dev_name),
      "#{dev_name} - #{description}",
      selected
    )
  end

  items
end

- (Object) enableDevices(enable)



508
509
510
511
512
513
# File '../../src/include/network/widgets.rb', line 508

def enableDevices(enable)
  UI.ChangeWidget(:net_device, :Enabled, enable)
  UI.ChangeWidget(:net_expert, :Enabled, enable)

  nil
end

- (Object) firewall_widget



242
243
244
245
246
247
248
# File '../../src/include/network/widgets.rb', line 242

def firewall_widget
  if SuSEFirewall4Network.IsInstalled
    SuSEFirewall4Network.FirewallZonesComboBoxItems
  else
    [["", _("Firewall is not installed.")]]
  end
end

- (Object) getDeviceContens(selected)



478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File '../../src/include/network/widgets.rb', line 478

def getDeviceContens(selected)
  VBox(
    VSpacing(0.5),
    HBox(
      HSpacing(3),
      MinWidth(
        30,
        Label(
          Id(:net_device),
          Opt(:hstretch),
          GetDeviceDescription(selected)
        )
      ),
      HSpacing(1),
      PushButton(Id(:net_expert), _("&Change Device"))
    ),
    VSpacing(0.5)
  )
end

- (Object) GetDeviceDescription(device_id)



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File '../../src/include/network/widgets.rb', line 416

def GetDeviceDescription(device_id)
  device_name = NetworkInterfaces.GetValue(device_id, "NAME")
  if device_name.nil? || device_name == ""
    # TRANSLATORS: Informs that device name is not known
    device_name = _("Unknown device")
  end
  Builtins.y2milestone("device_name %1", device_name)
  # avoid too long device names
  # if (size(device_name) > 30) {
  #    device_name = substring (device_name, 0, 27) + "...";
  # }
  ip_addr = if Builtins.issubstring(NetworkInterfaces.GetValue(device_id, "BOOTPROTO"), "dhcp")
              # TRANSLATORS: Part of label, device with IP address assigned by DHCP
              _("DHCP address")
            else
              # TRANSLATORS: Part of label, device with static IP address
              NetworkInterfaces.GetValue(device_id, "IPADDR")
            end
  if ip_addr.nil? || ip_addr == ""
    # TRANSLATORS: Informs that no IP has been assigned to the device
    ip_addr = _("No IP address assigned")
  end
  output = Builtins.sformat(
    _("%1 \n%2 - %3"),
    device_name,
    NetworkInterfaces.GetDeviceTypeName(device_id),
    ip_addr
  )
  output
end

- (Object) getInternetItems



447
448
449
450
451
452
# File '../../src/include/network/widgets.rb', line 447

def getInternetItems
  NetworkInterfaces.Read
  items = NetworkInterfaces.List("")
  items = Builtins.filter(items) { |i| i != "lo" }
  deep_copy(items)
end

- (Object) getNetDeviceItems



454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# File '../../src/include/network/widgets.rb', line 454

def getNetDeviceItems
  NetworkInterfaces.Read
  ifaces = NetworkInterfaces.List("eth")
  Builtins.y2debug("ifaces=%1", ifaces)
  ifaces = Convert.convert(
    Builtins.union(ifaces, NetworkInterfaces.List("eth-pcmcia")),
    from: "list",
    to:   "list <string>"
  )
  Builtins.y2debug("ifaces=%1", ifaces)
  ifaces = Convert.convert(
    Builtins.union(ifaces, NetworkInterfaces.List("eth-usb")),
    from: "list",
    to:   "list <string>"
  )
  ifaces = Convert.convert(
    Builtins.union(ifaces, NetworkInterfaces.List("wlan")),
    from: "list",
    to:   "list <string>"
  ) # #186102
  Builtins.y2debug("ifaces=%1", ifaces)
  deep_copy(ifaces)
end

- (Object) handleDevice(items, selected)



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File '../../src/include/network/widgets.rb', line 521

def handleDevice(items, selected)
  items = deep_copy(items)
  # popup dialog title
  via_device = NetworkPopup.ChooseItem(
    _("Network Device Select"),
    items,
    selected
  )
  if !via_device.nil?
    UI.ChangeWidget(:net_device, :Value, GetDeviceDescription(via_device))
    Builtins.y2milestone("selected network device :%1", via_device)
    selected = via_device
  end
  selected
end

- (Object) handleIPv6(_key, event)



381
382
383
384
385
386
# File '../../src/include/network/widgets.rb', line 381

def handleIPv6(_key, event)
  if Ops.get_string(event, "EventReason", "") == "ValueChanged"
    Lan.SetIPv6(Convert.to_boolean(UI.QueryWidget(Id(:ipv6), :Value)))
  end
  nil
end

- (Object) handleStartmode(_key, _event)



170
171
172
173
174
175
176
177
# File '../../src/include/network/widgets.rb', line 170

def handleStartmode(_key, _event)
  UI.ChangeWidget(
    Id("IFPLUGD_PRIORITY"),
    :Enabled,
    UI.QueryWidget(Id("STARTMODE"), :Value) == "ifplugd"
  )
  nil
end

- (Object) init_ipoib_mode_widget(key)



215
216
217
218
219
220
221
222
223
224
225
# File '../../src/include/network/widgets.rb', line 215

def init_ipoib_mode_widget(key)
  ipoib_mode = LanItems.ipoib_mode

  return unless LanItems.ipoib_modes.keys.include?(ipoib_mode)

  UI.ChangeWidget(
    Id(key),
    :CurrentButton,
    ipoib_mode
  )
end

- (Object) initDevice(items)



498
499
500
501
502
503
504
505
506
# File '../../src/include/network/widgets.rb', line 498

def initDevice(items)
  items = deep_copy(items)
  # If only one device is present, disable "Change device" button
  if Ops.less_or_equal(Builtins.size(items), 1)
    UI.ChangeWidget(Id(:net_expert), :Enabled, false)
  end

  nil
end

- (Object) initialize_network_widgets(include_target)



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
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
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
# File '../../src/include/network/widgets.rb', line 31

def initialize_network_widgets(include_target)
  Yast.import "UI"

  textdomain "network"

  # Gradually all yast2-network UI will be converted to CWM
  # for easier maintenance.
  # This is just a start.

  Yast.import "IP"
  Yast.import "NetworkPopup"
  Yast.import "NetworkInterfaces"
  Yast.import "NetworkService"
  Yast.import "Lan"
  Yast.import "LanItems"

  Yast.include include_target, "network/complex.rb"

  @widget_descr = {
    # #23315
    "DIALPREFIXREGEX" => {
      "widget" => :textentry,
      # TextEntry label
      "label"  => _("&Dial Prefix Regular Expression"),
      "help"   =>
                  # dial prefix regex help
                  _(
                    "<p>When <b>Dial Prefix Regular Expression</b> is set, users can\n" \
                      "change the dial prefix in KInternet provided that it matches the expression.\n" \
                      "A recommended value is <tt>[09]?</tt>, allowing <tt>0</tt>, <tt>9</tt>,\n" \
                      "and the empty prefix. If the expression is empty, users are not allowed\n" \
                      "to change the prefix.</p>\n"
        )
    },
    # obsoleted by BOOTPROTO_*
    "BOOTPROTO"       => {
      "widget" => :radio_buttons,
      # radio button group label,method of setup
      "label"  => _(
        "Setup Method"
      ),
      # is this necessary?
      "items"  => [
        # radio button label
        ["dhcp", _("A&utomatic Address Setup (via DHCP)")],
        # radio button label
        ["static", _("S&tatic Address Setup")]
      ],
      "opt"    => [],
      "help"   => _("<p>H</p>")
    }
  }

  # This is the data for widget_descr["STARTMODE"].
  # It is separated because the list of items depends on the device type
  # and will be substituted dynamically.
  # Helps are rich text, but not paragraphs.
  @startmode_items = {
    # onboot, on and boot are aliases for auto
    # See NetworkInterfaces::CanonicalizeStartmode
    "auto"    =>
                 # is a part of the static help text
                 {
                   # Combo box option for Device Activation
                   "label" => _(
                     "At Boot Time"
                   ),
                   "help"  => ""
                 },
    "off"     =>
                 # is a part of the static help text
                 { "label" => _("Never"), "help" => "" },
    "managed" => {
      # Combo box option for Device Activation
      # DO NOT TRANSLATE NetworkManager, it is a program name
      "label" => _(
        "By NetworkManager"
      ),
      # help text for Device Activation
      # DO NOT TRANSLATE NetworkManager, it is a program name
      "help"  => _(
        "<b>By NetworkManager</b>: a desktop applet\ncontrols the interface. There is no need to set it up in YaST."
      )
    },
    "manual"  => {
      # Combo box option for Device Activation
      "label" => _("Manually"),
      # help text for Device Activation
      "help"  => _(
        "<p><b>Manually</b>: You control the interface manually\nvia 'ifup' or 'qinternet' (see 'User Controlled' below).</p>\n"
      )
    },
    "ifplugd" => {
      # Combo box option for Device Activation
      "label" => _(
        "On Cable Connection"
      ),
      # help text for Device Activation
      "help"  => _(
        "<b>On Cable Connection</b>:\n" \
          "The interface is watched for whether there is a physical\n" \
          "network connection. That means either the cable is connected or the\n" \
          "wireless interface can connect to an access point.\n"
      )
    },
    "hotplug" => {
      # Combo box option for Device Activation
      "label" => _("On Hotplug"),
      # help text for Device Activation
      "help"  => _(
        "With <b>On Hotplug</b>,\n" \
          "the interface is set up as soon as it is available. This is\n" \
          "nearly the same as 'At Boot Time', but does not result in an error at\n" \
          "boot time if the interface is not present.\n"
      )
    },
    "nfsroot" => {
      # Combo box option for Device Activation
      "label" => _("On NFSroot"),
      # help text for Device Activation
      "help"  => _(
        "Using <b>On NFSroot</b> is similar to <tt>auto</tt>. Interfaces with this startmode will never\n" \
          "be shut down via <tt>rcnetwork stop</tt>. <tt>ifdown <iface></tt> is still available.\n" \
          "Use this if you have an NFS or iSCSI root filesystem.\n"
      )
    }
  }
end

- (Object) initIPv6(_key)



375
376
377
378
379
# File '../../src/include/network/widgets.rb', line 375

def initIPv6(_key)
  UI.ChangeWidget(Id(:ipv6), :Value, Lan.ipv6 ? true : false)

  nil
end

- (Object) ipoib_mode_widget



231
232
233
234
235
236
237
238
239
240
# File '../../src/include/network/widgets.rb', line 231

def ipoib_mode_widget
  {
    "widget" => :radio_buttons,
    "items"  => LanItems.ipoib_modes.to_a,
    "label"  => _("IPoIB Device Mode"),
    "opt"    => [:hstretch],
    "init"   => fun_ref(method(:init_ipoib_mode_widget), "void (string)"),
    "store"  => fun_ref(method(:store_ipoib_mode_widget), "void (string, map)")
  }
end

- (Object) ipoib_mtu_items



259
260
261
262
263
264
265
# File '../../src/include/network/widgets.rb', line 259

def ipoib_mtu_items
  [
    # translators: MTU value description (size in bytes, desc)
    ["65520", _("65520 (IPoIB in connected mode)")],
    ["2044", _("2044 (IPoIB in datagram mode)")]
  ]
end

- (Object) ipv6_widget



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File '../../src/include/network/widgets.rb', line 398

def ipv6_widget
  {
    "widget"        => :custom,
    "custom_widget" => Frame(
      _("IPv6 Protocol Settings"),
      Left(CheckBox(Id(:ipv6), Opt(:notify), _("Enable IPv6")))
    ),
    "opt"           => [],
    "help"          => Ops.get_string(@help, "ipv6", ""),
    "init"          => fun_ref(method(:initIPv6), "void (string)"),
    "handle"        => fun_ref(
      method(:handleIPv6),
      "symbol (string, map)"
    ),
    "store"         => fun_ref(method(:storeIPv6), "void (string, map)")
  }
end

- (Object) MakeStartmode(ids)



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
# File '../../src/include/network/widgets.rb', line 179

def MakeStartmode(ids)
  ids = deep_copy(ids)
  ret = {
    "widget" => :combobox,
    # Combo box label - when to activate device (e.g. on boot, manually, never,..)
    "label"  => _("Activate &Device"),
    "opt"    => [:notify],
    "handle" => fun_ref(method(:handleStartmode), "symbol (string, map)"),
    "help"   =>
                # Device activation main help. The individual parts will be
                # substituted as %1
                _(
                  "<p><b><big>Device Activation</big></b></p> \n" \
                    "<p>Choose when to bring up the network interface. <b>At Boot Time</b> activates it during system boot, \n" \
                    "<b>Never</b> does not start the device.\n" \
                    "%1</p>\n"
      )
  }
  helps = ""
  items = Builtins.maplist(ids) do |id|
    helps = Ops.add(
      Ops.add(helps, " "),
      Ops.get(@startmode_items, [id, "help"], "")
    )
    [id, Ops.get(@startmode_items, [id, "label"], "")]
  end

  Ops.set(
    ret,
    "help",
    Builtins.sformat(Ops.get_string(ret, "help", "%1"), helps)
  )
  Ops.set(ret, "items", items)
  deep_copy(ret)
end

- (Object) managed_widget



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File '../../src/include/network/widgets.rb', line 354

def managed_widget
  {
    "widget"        => :custom,
    "custom_widget" => Frame(
      _("General Network Settings"),
      Left(
        ComboBox(
          Id(:managed),
          Opt(:hstretch),
          _("Network Setup Method"),
          []
        )
      )
    ),
    "opt"           => [],
    "help"          => @help["managed"] || "",
    "init"          => fun_ref(method(:ManagedInit), "void (string)"),
    "store"         => fun_ref(method(:ManagedStore), "void (string, map)")
  }
end

- (Object) ManagedInit(_key)

Initialize the NetworkManager widget

Parameters:

  • key (String)

    id of the widget



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File '../../src/include/network/widgets.rb', line 280

def ManagedInit(_key)
  items = []

  if NetworkService.is_backend_available(:network_manager)
    items << Item(
      Id("managed"),
      # the user can control the network with the NetworkManager program
      _("NetworkManager Service"),
      NetworkService.is_network_manager
    )
  end
  if NetworkService.is_backend_available(:netconfig)
    items << Item(
      Id("ifup"),
      # ifup is a program name
      _("Traditional ifup"),
      NetworkService.is_netconfig
    )
  end
  if NetworkService.is_backend_available(:wicked)
    items << Item(
      Id("wicked"),
      # wicked is network configuration backend like netconfig
      _("Wicked Service"),
      NetworkService.is_wicked
    )
  end

  items << Item(
    Id("disabled"),
    # used when no network service is active or to disable network service
    _("Network Services Disabled"),
    NetworkService.is_disabled
  )

  UI.ChangeWidget(Id(:managed), :Items, items)

  nil
end

- (Object) ManagedStore(_key, _event)

Store the NetworkManager widget

Parameters:

  • key (String)

    id of the widget

  • event (Hash)

    the event being handled



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File '../../src/include/network/widgets.rb', line 323

def ManagedStore(_key, _event)
  new_backend = UI.QueryWidget(Id(:managed), :Value)

  case new_backend
  when "ifup"
    NetworkService.use_netconfig
  when "managed"
    NetworkService.use_network_manager
  when "wicked"
    NetworkService.use_wicked
  else
    NetworkService.disable
  end

  if NetworkService.Modified
    LanItems.SetModified

    if Stage.normal && NetworkService.is_network_manager
      Popup.AnyMessage(
        _("Applet needed"),
        _(
          "NetworkManager is controlled by desktop applet\n" \
          "(KDE plasma widget and nm-applet for GNOME).\n" \
          "Be sure it's running and if not, start it manually."
       ))
    end
  end

  nil
end

- (Object) mtu_widget



267
268
269
270
271
272
273
274
275
276
# File '../../src/include/network/widgets.rb', line 267

def mtu_widget
  {
    "widget" => :combobox,
    # textentry label, Maximum Transfer Unit
    "label"  => _("Set &MTU"),
    "opt"    => [:hstretch, :editable],
    "items"  => [],
    "help"   => @help["mtu"] || ""
  }
end

- (Object) refreshDevice(via_device)



515
516
517
518
519
# File '../../src/include/network/widgets.rb', line 515

def refreshDevice(via_device)
  UI.ChangeWidget(:net_device, :Value, GetDeviceDescription(via_device))

  nil
end

- (Object) store_ipoib_mode_widget(key, _event)



227
228
229
# File '../../src/include/network/widgets.rb', line 227

def store_ipoib_mode_widget(key, _event)
  LanItems.ipoib_mode = UI.QueryWidget(Id(key), :CurrentButton)
end

- (Object) storeIPv6(_key, _event)



388
389
390
391
392
393
394
395
396
# File '../../src/include/network/widgets.rb', line 388

def storeIPv6(_key, _event)
  if Convert.to_boolean(UI.QueryWidget(Id(:ipv6), :Value))
    Lan.SetIPv6(true)
  else
    Lan.SetIPv6(false)
  end

  nil
end

- (Object) ValidateIP(key, _event)

Validator for IP adresses, no_popup

Parameters:

  • key (String)

    the widget being validated

  • event (Hash)

    the event being handled

Returns:

  • whether valid



164
165
166
167
168
# File '../../src/include/network/widgets.rb', line 164

def ValidateIP(key, _event)
  value = Convert.to_string(UI.QueryWidget(Id(key), :Value))
  return IP.Check(value) if value != ""
  true
end