Class: Yast::DSLClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) Add

Add a new device

Returns:

  • true if success



401
402
403
404
405
406
407
# File '../../src/modules/DSL.rb', line 401

def Add
  @operation = nil
  return false if Select("") != true
  NetworkInterfaces.Add
  @operation = :add
  true
end

- (Object) Adding

Used to see whether we are in the process of adding a new interface or editing an existing one.

Returns:

  • adding?



591
592
593
# File '../../src/modules/DSL.rb', line 591

def Adding
  @operation == :add
end

- (Object) Commit

Commit the pending operation

Returns:

  • true if success



433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File '../../src/modules/DSL.rb', line 433

def Commit
  Builtins.y2debug("Commit(%1)", @operation)

  if @operation == :add || @operation == :edit
    newdev = {
      "STARTMODE"    => @startmode,
      "USERCONTROL"  => @usercontrol ? "yes" : "no",
      "BOOTPROTO"    => "none",
      "UDI"          => @unique,
      "NAME"         => @description,
      "PPPMODE"      => @pppmode,
      "PROVIDER"     => Provider.Name,
      # "PROVIDER_NAME"	: Provider::Current["PROVIDER"]:"",
      "PPPD_OPTIONS" => @PPPDoptions
    }
    Ops.set(newdev, "DEVICE", @interface)
    Ops.set(newdev, "VPIVCI", @vpivci)
    Ops.set(newdev, "MODEM_IP", @modemip)

    NetworkInterfaces.Name = @device
    NetworkInterfaces.Current = deep_copy(newdev)
    NetworkInterfaces.Commit
  elsif @operation == :delete
    NetworkInterfaces.Commit
  else
    Builtins.y2error("Unknown operation: %1", @operation)
    return false
  end

  @modified = true
  @operation = nil
  true
end

- (Object) Delete(name)

Delete the given device

Parameters:

  • name (String)

    device to delete

Returns:

  • true if success



423
424
425
426
427
428
429
# File '../../src/modules/DSL.rb', line 423

def Delete(name)
  @operation = nil
  return false if Select(name) != true
  NetworkInterfaces.Delete(name)
  @operation = :delete
  true
end

- (Object) Edit(name)

Edit the given device

Parameters:

  • name (String)

    device to edit

Returns:

  • true if success



412
413
414
415
416
417
418
# File '../../src/modules/DSL.rb', line 412

def Edit(name)
  @operation = nil
  return false if Select(name) != true
  NetworkInterfaces.Edit(name)
  @operation = :edit
  true
end

- (Object) Export

Export data

Returns:

  • dumped settings (later acceptable by Import())



497
498
499
500
501
502
# File '../../src/modules/DSL.rb', line 497

def Export
  {
    "devices"   => NetworkInterfaces.Export("dsl"),
    "providers" => Provider.Export("dsl")
  }
end

- (Object) Import(settings)

Import data

Parameters:

  • settings (Hash)

    settings to be imported

Returns:

  • true on success



488
489
490
491
492
493
# File '../../src/modules/DSL.rb', line 488

def Import(settings)
  settings = deep_copy(settings)
  NetworkInterfaces.Import("dsl", Ops.get_map(settings, "devices", {}))
  Provider.Import("dsl", Ops.get_map(settings, "providers", {}))
  true
end

- (Object) main



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
# File '../../src/modules/DSL.rb', line 36

def main
  Yast.import "UI"
  textdomain "network"

  Yast.import "Confirm"
  Yast.import "NetHwDetection"
  Yast.import "Lan"
  Yast.import "NetworkInterfaces"
  Yast.import "NetworkService"
  Yast.import "Provider"
  Yast.import "Progress"
  Yast.import "Summary"
  Yast.import "SuSEFirewall4Network"

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

  # general stuff
  @description = ""
  @type = ""
  @device = ""
  @unique = ""
  @startmode = "manual"
  @usercontrol = false
  @hotplug = ""
  # FIXME so far does nothing, add code like in Lan and Modem
  @Requires = []

  # Special Capi-ADSL mode -- different presets for the first device.
  # Used for ISDN-DSL combined hardware.
  @capiadsl = nil

  # Ethernet network interface
  @interface = ""

  # VPI/VCI
  @vpivci = ""

  # DSL modem IP (used for PPTP)
  @modemip = "10.0.0.138"

  # PPP mode: pppoe or pppoatm
  @pppmode = "pppoe"

  @PPPDoptions = ""

  # Provider settings
  # authorization settings
  @username = ""
  @password = ""

  # connection settings
  @idletime = 300
  @dialondemand = false
  @dns1 = ""
  @dns2 = ""

  # something already proposed?
  @proposal_valid = false

  #--------------
  # PRIVATE DATA

  # Hardware information
  # @see #ReadHardware
  @Hardware = []

  # FIXME: HW
  @HWDetected = false

  # Abort function
  # return boolean return true if abort
  @AbortFunction = nil

  # Data was modified?
  @modified = false

  # Which operation is pending?
  @operation = nil

  @write_only = false

  Yast.include self, "network/hardware.rb"
  Yast.include self, "network/routines.rb"
  Yast.include self, "network/runtime.rb"
end

- (Object) Modified

Data was modified?

Returns:

  • true if modified



127
128
129
130
# File '../../src/modules/DSL.rb', line 127

def Modified
  Builtins.y2debug("modified=%1", @modified)
  @modified
end

- (Object) Overview

Create an overview table with all configured devices

Returns:

  • table items



533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File '../../src/modules/DSL.rb', line 533

def Overview
  res = BuildOverview("dsl", @Hardware)
  Builtins.maplist(
    Convert.convert(res, :from => "list", :to => "list <term>")
  ) do |card|
    id = Ops.get_string(card, [0, 0], "")
    desc = [
      Ops.get_string(card, 1, ""),
      Ops.get_string(card, 2, ""),
      Ops.get_string(card, 3, "")
    ]
    {
      "id"          => id,
      "rich_descr"  => Ops.get_locale(
        card,
        4,
        Ops.get_locale(desc, 1, _("Unknown"))
      ),
      "table_descr" => desc
    }
  end
end

- (Object) Packages



571
572
573
574
575
576
# File '../../src/modules/DSL.rb', line 571

def Packages
  if Ops.less_than(Builtins.size(NetworkInterfaces.List("dsl")), 1)
    return []
  end
  ["smpppd", "ppp", "pptp", "libatm1"]
end

- (Object) Propose

Propose a configuration

Returns:

  • true if something was proposed



469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File '../../src/modules/DSL.rb', line 469

def Propose
  Builtins.y2milestone("Hardware=%1", @Hardware)

  # y2milestone("Devices=%1", Devices);
  #
  # /* Something is already configured -> do nothing * /
  # if(size(Devices) > 0) {
  # 	y2milestone("Something already configured: don't propose.");
  # 	return false;
  # }

  Add()

  true
end

- (Object) Read

Read all network settings from the SCR

Returns:

  • true on success



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
170
171
172
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
# File '../../src/modules/DSL.rb', line 134

def Read
  cache = :cache

  # Read dialog caption
  caption = _("Initializing DSL Configuration")
  steps = 5

  sl = 0 # 1000; /* TESTING
  Builtins.sleep(sl)

  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/5
      _("Detect DSL devices"),
      # Progress stage 2/5
      _("Read current configuration"),
      # Progress stage 3/5
      _("Read firewall configuration"),
      # Progress stage 4/5
      _("Read providers"),
      # Progress stage 5/5
      _("Read network card configuration")
    ],
    [],
    ""
  )

  return false if Abort()

  # check the environment
  return false if !Confirm.MustBeRoot

  # Progress step 1/5
  ProgressNextStage(_("Detecting DSL devices..."))
  NetHwDetection.Start if !NetHwDetection.running
  @Hardware = Convert.convert(
    Builtins.union(ReadHardware("dsl"), ReadHardware("pppoe")),
    :from => "list",
    :to   => "list <map>"
  )

  # In case of capiadsl we can emulate the detection with the parameters
  # from ISDN. Advantage: we can setup the dialog items correctly.
  @Hardware = Builtins.add(@Hardware, @capiadsl) if @capiadsl != nil
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 2/5
  ProgressNextStage(_("Reading current configuration..."))
  NetworkInterfaces.Read
  NetworkService.Read
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 3/5
  ProgressNextStage(_("Reading firewall configuration..."))
  progress_orig = Progress.set(false)
  SuSEFirewall4Network.Read
  Progress.set(progress_orig)
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 4/5
  ProgressNextStage(_("Reading providers..."))
  Provider.Read
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 5/5
  ProgressNextStage(_("Reading network card configuration..."))
  if !@proposal_valid
    progress_orig2 = Progress.set(false)
    Lan.Read(cache)
    Progress.set(progress_orig2)
  end
  Builtins.sleep(sl)

  # Confirmation: label text (detecting hardware: xxx)
  if Confirm.Detection(_("PPPoE DSL Devices"), "yast-dsl")
    # it doesn't do anything except looking whether probe.pppoe is empty
    # FIXME: HW
    pppoe = Convert.to_list(SCR.Read(path(".probe.pppoe")))
    # FIXME: testing pppoe = [ $["a" : "b"] ];
    if pppoe != nil && Ops.greater_than(Builtins.size(pppoe), 0)
      @HWDetected = true
    end
  end

  return false if Abort()
  # Final progress step
  ProgressNextStage(_("Finished"))
  Builtins.sleep(sl)

  return false if Abort()
  @modified = false
  true
end

- (Object) Select(dev)

Select the given device

Parameters:

  • dev (String)

    device to select (“” for new device, default values)

Returns:

  • true if success



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File '../../src/modules/DSL.rb', line 336

def Select(dev)
  Builtins.y2debug("dev=%1", dev)
  # defaults for a new device
  devmap = {
    "STARTMODE"   => "manual", # see also #44804
    "USERCONTROL" => "yes"
  }

  # dev=="" -> Add
  if dev == ""
    @type = "dsl"
    @device = Builtins.sformat(
      "dsl%1",
      NetworkInterfaces.GetFreeDevice(@type)
    )
  else
    typ = NetworkInterfaces.device_type(dev)
    num = NetworkInterfaces.device_num(dev)

    NetworkInterfaces.Edit(dev)
    devmap = deep_copy(NetworkInterfaces.Current)
    @type = typ
    @device = Builtins.sformat("%1%2", @type, num)
    @operation = :edit
  end

  # general stuff
  @description = BuildDescription(@type, @device, devmap, @Hardware)
  @unique = Ops.get_string(devmap, "UDI", "")
  @startmode = Ops.get_string(devmap, "STARTMODE", "manual")
  @usercontrol = Ops.get_string(devmap, "USERCONTROL", "no") == "yes"

  # DSL settings
  @vpivci = Ops.get_string(devmap, "VPIVCI", "")
  @modemip = Ops.get_string(devmap, "MODEM_IP", "10.0.0.138")
  @pppmode = Ops.get_string(devmap, "PPPMODE", "")
  @interface = Ops.get_string(devmap, "DEVICE", "")
  @PPPDoptions = Ops.get_string(devmap, "PPPD_OPTIONS", "")

  # provider settings
  Provider.Name = Ops.get_string(devmap, "PROVIDER", "")

  # ppp mode heuristics
  if @pppmode == nil || @pppmode == ""
    country = Provider.GetCountry
    Builtins.y2debug("country=%1", country)

    pppmodes = {
      # pptp removed because we no longer have ppp_mppe.ko, #73043
      # I leave related code in for the case it comes back
      # reenabled on request from aj@suse.de
      "AT" => "pptp",
      "CZ" => "pptp",
      "DE" => "pppoe",
      "GB" => "pppoatm",
      "CA" => "pppoe"
    }
    @pppmode = Ops.get_string(pppmodes, country, "pppoe")
  end

  true
end

- (Object) SelectHW(which)

Select the hardware component

Parameters:

  • which (Fixnum)

    index of the component



562
563
564
565
566
567
568
569
# File '../../src/modules/DSL.rb', line 562

def SelectHW(which)
  sel = SelectHardware(@Hardware, which)

  @pppmode = Ops.get_string(sel, "pppmode", "capi-adsl")
  @startmode = Ops.get_string(sel, "startmode", "manual")

  nil
end

- (Object) Summary(split)

Create a textual summary and a list of unconfigured devices

Parameters:

  • split (Boolean)

    split configured and unconfigured?

Returns:

  • summary of the current configuration



507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File '../../src/modules/DSL.rb', line 507

def Summary(split)
  sum = BuildSummary("dsl", @Hardware, split, false)
  return deep_copy(sum) if @HWDetected != true

  hwdet = Summary.DevicesList(
    [
      "<li>" +
        # Summary label
        _("Unknown (PPPoE-style) DSL Device Detected") + "</li>"
    ]
  )
  # FIXME: HW

  Builtins.y2milestone("hwdet=%1", @HWDetected)
  Builtins.y2milestone("sum=%1", sum)
  if Ops.get_string(sum, 0, "") == Summary.DevicesList([])
    Ops.set(sum, 0, hwdet)
  else
    Ops.set(sum, 0, Ops.add(Ops.get_string(sum, 0, ""), hwdet))
  end

  deep_copy(sum)
end

- (Object) Unconfigured



556
557
558
# File '../../src/modules/DSL.rb', line 556

def Unconfigured
  BuildUnconfigured("dsl", @Hardware)
end

- (Object) UsesDevice(device)

Return true if the device is used by any DSL connection

Parameters:

  • device (String)

    device to be tested

Returns:

  • true if yes



581
582
583
584
585
586
# File '../../src/modules/DSL.rb', line 581

def UsesDevice(device)
  Ops.greater_than(
    Builtins.size(NetworkInterfaces.Locate("DEVICE", device)),
    0
  )
end

- (Object) Write

Update the SCR according to network settings

Returns:

  • true on success



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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
# File '../../src/modules/DSL.rb', line 237

def Write
  return true if !@modified && !Provider.Modified("dsl")
  Builtins.y2milestone("Writing configuration")

  # Write dialog caption
  caption = _("Saving DSL Configuration")
  steps = 7

  sl = 0 # 1000; /* TESTING
  Builtins.sleep(sl)

  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/7
      _("Write configuration"),
      # Progress stage 2/7
      _("Write network card configuration"),
      # Progress stage 3/7
      _("Write firewall settings"),
      # Progress stage 4/7
      _("Write providers"),
      # Progress stage 5/7
      _("Set up network services"),
      # Progress stage 6/7
      _("Set up smpppd"),
      # Progress stage 9
      _("Activate network services")
    ],
    [],
    ""
  )

  # Stop the detection
  NetHwDetection.Stop if NetHwDetection.running

  return false if Abort()
  # Progress step 1/7
  ProgressNextStage(_("Writing configuration..."))
  NetworkInterfaces.Write("dsl")
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 2/7
  ProgressNextStage(_("Writing network card configuration..."))
  progress_orig = Progress.set(false)
  Lan.Write
  Progress.set(progress_orig)
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 3/7
  ProgressNextStage(_("Writing firewall settings..."))
  progress_orig = Progress.set(false)
  SuSEFirewall4Network.Write
  Progress.set(progress_orig)
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 4/7
  ProgressNextStage(_("Writing providers..."))
  Provider.Write("dsl")
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 5/7
  ProgressNextStage(_("Setting up network services..."))
  NetworkService.EnableDisable
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 6/7
  ProgressNextStage(_("Setting up smpppd(8)..."))
  SetupSMPPPD(true)
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 9
  ProgressNextStage(_("Activating network services..."))
  if !@write_only
    #	NetworkModules::HwUp (); // this is needed too
    NetworkService.StartStop
  end
  Builtins.sleep(sl)

  return false if Abort()
  # Final progress step
  ProgressNextStage(_("Finished"))
  Builtins.sleep(sl)

  return false if Abort()
  true
end