Class: Yast::ModemClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) Add

Add a new device

Returns:

  • true if success



378
379
380
381
382
383
384
# File '../../src/modules/Modem.rb', line 378

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?



529
530
531
# File '../../src/modules/Modem.rb', line 529

def Adding
  @operation == :add
end

- (Object) Commit

Commit the pending operation

Returns:

  • true if success



411
412
413
414
415
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
446
447
# File '../../src/modules/Modem.rb', line 411

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,
      "INIT1"           => @Init1,
      "INIT2"           => @Init2,
      "INIT3"           => @Init3,
      "SPEED"           => Builtins.sformat("%1", @BaudRate),
      "INIT8"           => @Speaker ? "ATM1" : "ATM0",
      "INIT9"           => @Carrier ? "" : "ATX3",
      "DIALCOMMAND"     => @PulseDial ? "ATDP" : "ATDT",
      "MODEM_DEVICE"    => @Device,
      "DIALPREFIX"      => @DialPrefix,
      "DIALPREFIXREGEX" => @DialPrefixRx,
      "PROVIDER"        => Provider.Name,
      # "PROVIDER_NAME"	: Provider::Current["PROVIDER"]:"",
      "PPPD_OPTIONS"    => @PPPDoptions
    }
    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



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

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



389
390
391
392
393
394
395
# File '../../src/modules/Modem.rb', line 389

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())



461
462
463
464
465
466
# File '../../src/modules/Modem.rb', line 461

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

- (Object) Import(settings)

Import data

Parameters:

  • settings (Hash)

    settings to be imported

Returns:

  • true on success



452
453
454
455
456
457
# File '../../src/modules/Modem.rb', line 452

def Import(settings)
  settings = deep_copy(settings)
  NetworkInterfaces.Import("modem", Ops.get_map(settings, "devices", {}))
  Provider.Import("modem", 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
# File '../../src/modules/Modem.rb', line 36

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

  Yast.import "NetworkInterfaces"
  Yast.import "NetworkService"
  Yast.import "Provider"
  Yast.import "Progress"
  Yast.import "Routing"
  Yast.import "Service"
  Yast.import "Summary"
  Yast.import "Message"
  Yast.import "SuSEFirewall4Network"

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

  # general stuff
  @description = ""
  @type = ""
  @device = ""
  @unique = ""
  @startmode = "manual"
  @usercontrol = false
  @Requires = []

  # Hotplug type ("" if not hot pluggable)
  @hotplug = ""

  # modem settings
  @Init1 = "ATZ"
  @Init2 = "AT Q0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
  @Init3 = ""
  @BaudRate = 57600

  @PulseDial = true
  @Carrier = true
  @Speaker = true

  @Device = "/dev/modem"
  @DialPrefix = ""
  @DialPrefixRx = ""
  @PPPDoptions = ""

  # something already proposed?
  @proposal_valid = false

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

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

  # 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



111
112
113
114
# File '../../src/modules/Modem.rb', line 111

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

- (Object) Overview

Create an overview table with all configured devices

Returns:

  • table items



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File '../../src/modules/Modem.rb', line 477

def Overview
  res = BuildOverview("modem", @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



519
520
521
522
523
524
# File '../../src/modules/Modem.rb', line 519

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

- (Object) Read

Read all network settings from the SCR

Returns:

  • true on success



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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File '../../src/modules/Modem.rb', line 118

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

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

  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/4
      _("Detect modems"),
      # Progress stage 2/4
      _("Read current configuration"),
      # Progress stage 3/4
      _("Read firewall settings"),
      # Progress stage 4/4
      _("Read providers"),
      # Progress stage 5/5
      _("Read routing")
    ],
    [],
    ""
  )

  return false if Abort()

  # check the environment
  return false if !Confirm.MustBeRoot


  # Progress step 1/4
  ProgressNextStage(_("Detecting modems..."))
  @Hardware = ReadHardware("modem")
  Builtins.sleep(sl)

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

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

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

  return false if Abort()
  # Progress step 4/4
  ProgressNextStage(_("Reading routes..."))
  Routing.Read if !@proposal_valid
  Builtins.sleep(sl)

  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



316
317
318
319
320
321
322
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File '../../src/modules/Modem.rb', line 316

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

  # dev=="" -> Add
  if dev == ""
    @type = "modem"
    @device = Builtins.sformat(
      "modem%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) 
    # FIXME: why is this here? 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"

  # modem settings
  @Init1 = Ops.get_string(devmap, "INIT1", "ATZ")
  @Init2 = Ops.get_string(
    devmap,
    "INIT2",
    "AT Q0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
  )
  @Init3 = Ops.get_string(devmap, "INIT3", "")
  @BaudRate = Builtins.tointeger(Ops.get_string(devmap, "SPEED", "57600"))

  # PulseDial = devmap["DIALCOMMAND"]:"ATDT" == "ATDP";
  # better heuristics:
  @PulseDial = Builtins.filterchars(
    Ops.get_string(devmap, "DIALCOMMAND", "ATDT"),
    "P"
  ) == "P"
  @Speaker = Ops.get_string(devmap, "INIT8", "ATM1") == "ATM1"
  @Carrier = Ops.get_string(devmap, "INIT9", "") == ""

  @Device = Ops.get_string(devmap, "MODEM_DEVICE", "/dev/modem")
  @DialPrefix = Ops.get_string(devmap, "DIALPREFIX", "")
  @DialPrefixRx = Ops.get_string(devmap, "DIALPREFIXREGEX", "")
  @PPPDoptions = Ops.get_string(devmap, "PPPD_OPTIONS", "")

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

  true
end

- (Object) SelectHW(which)

Select the hardware component

Parameters:

  • which (Fixnum)

    index of the component



506
507
508
509
510
511
512
513
514
515
516
517
# File '../../src/modules/Modem.rb', line 506

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

  @Init1 = Ops.get_string(sel, "init1", "")
  @Init2 = Ops.get_string(sel, "init2", "")
  @Device = Ops.get_string(sel, "device_name", "")
  @BaudRate = Ops.get_integer(sel, "speed", 57600)
  @PPPDoptions = Ops.get_string(sel, "pppd_options", "")
  @type = "modem"

  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



471
472
473
# File '../../src/modules/Modem.rb', line 471

def Summary(split)
  BuildSummary("modem", @Hardware, split, false)
end

- (Object) Unconfigured



500
501
502
# File '../../src/modules/Modem.rb', line 500

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

- (Object) Write

Update the SCR according to network settings

Returns:

  • true on success



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

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

  # Write dialog caption
  caption = _("Saving Modem Configuration")
  steps = 6

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

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

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

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

  return false if Abort()
  # Progress step 3/6
  ProgressNextStage(_("Writing providers..."))
  Provider.Write("modem")
  Builtins.sleep(sl)

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

  # Setup SL modem
  if Builtins.contains(@Requires, "smartlink-softmodem")
    if !PackageSystem.CheckAndInstallPackages(@Requires)
      Popup.Error(
        Builtins.sformat(
          "%1 : smartlink-softmodem",
          Message.CannotContinueWithoutPackagesInstalled
        )
      )
    end
    Builtins.y2milestone("Setting up smartlink-softmodem ...")

    Service.Stop("slmodemd")

    country = Provider.GetCountry
    keys = Convert.to_map(
      Builtins.eval(SCR.Read(path(".target.yast2"), "modem-t35-keys.ycp"))
    )
    country = Ops.get_string(keys, country, "")

    Builtins.y2milestone("Setting up slmodemd (%1)", country)
    if country != nil && country != ""
      SCR.Write(
        path(".sysconfig.slmodemd.SLMODEMD_COUNTRY"),
        Builtins.toupper(country)
      )
      SCR.Write(path(".sysconfig.slmodemd"), nil)
    end

    Service.Enable("slmodemd")
    Service.Start("slmodemd")
  end

  return false if Abort()
  # Progress step 5/6
  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