Class: Yast::InternetClass

Inherits:
Module
  • Object
show all
Defined in:
library/network/src/modules/Internet.rb

Instance Method Summary collapse

Instance Method Details

#ConnectedObject

Test if the interface is connected

Returns:

  • true if connected



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
# File 'library/network/src/modules/Internet.rb', line 181

def Connected
  if @type == "dsl" || @type == "modem" || (@type == "isdn" && @capi_isdn)
    tmp1 = Convert.to_string(
      SCR.Read(
        path(".target.string"),
        Ops.add(Ops.add("/var/lib/smpppd/ifcfg-", @device), ".info")
      )
    )
    tmp2 = Builtins.splitstring(tmp1, "\n")
    return Builtins.contains(tmp2, "status: connected")
  end

  if @type == "isdn" && !@capi_isdn
    return SCR.Execute(
      path(".target.bash"),
      "/usr/bin/grep -q pppd /etc/resolv.conf"
    ) == 0
  end

  # NM: we have to wait until the interface comes up (or fails)
  # - dbus message filter
  # - grep ip addr list $device
  SCR.Execute(
    path(".target.bash"),
    "/bin/ip -oneline addr list | /usr/bin/grep 'scope global' >&2"
  ) == 0
end

#GetDevicesObject

Used if NetworkInterfaces cannot find anything (usually because NM runs) Calls ip



87
88
89
90
91
92
93
94
95
96
97
# File 'library/network/src/modules/Internet.rb', line 87

def GetDevices
  if @devices.nil?
    command = "/bin/ip -oneline link list | /usr/bin/sed -e 's/^[0-9]*: \\([^:]*\\).*/\\1/' | /usr/bin/grep -v 'lo\\|sit0'"
    out = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))
    @devices = Builtins.filter(
      Builtins.splitstring(Ops.get_string(out, "stdout", ""), "\n")
    ) { |i| i != "" }
    @devices = Builtins.filter(@devices) { |i| i != "lo" && i != "sit0" }
  end
  deep_copy(@devices)
end

#mainObject



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
# File 'library/network/src/modules/Internet.rb', line 34

def main
  Yast.import "Map"
  Yast.import "NetworkService"
  Yast.import "Service"

  # Flag to remember if user wants to run internet test
  @do_test = true

  # Flag to remember if user wants to run suse register
  @suse_register = true

  # Flag to remember if you should be started
  @do_you = false

  # Flag to remember status of internet test:
  # nil   - skipped
  # true  - passed
  # false - failed
  @test = false

  # cache for GetDevices
  @devices = nil

  # Values for selected connection.
  @device = ""
  @type = ""
  @logfile = ""
  @provider = ""
  @password = ""
  @demand = false
  @askpassword = nil
  @capi_adsl = false
  @capi_isdn = false
end

#ResetObject

Reset values.



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'library/network/src/modules/Internet.rb', line 70

def Reset
  @device = ""
  @type = ""
  @logfile = ""
  @provider = ""
  @password = ""
  @demand = false
  @askpassword = nil
  @capi_adsl = false
  @capi_isdn = false

  nil
end

#SetDemand(demand) ⇒ Object

Set dial-on-demand

Parameters:

  • demand (Boolean)

    true if dial-on-demand should be set



211
212
213
214
215
216
217
218
219
# File 'library/network/src/modules/Internet.rb', line 211

def SetDemand(demand)
  pp = path(".sysconfig.network.providers.v")
  pp = Builtins.add(pp, @provider)
  pp = Builtins.add(pp, "DEMAND")
  SCR.Write(pp, (demand == true) ? "yes" : "no")
  SCR.Write(path(".sysconfig.network.providers"), nil)

  nil
end

#ShutdownAllLocalDHCPClientsObject

DANGEROUS function. Searches for all standard PID files of dhcpcd, then kills all dhcpcds running (first SIGHUP, then SIGKILL). Works via WFM (only for local dhcpcd).



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
# File 'library/network/src/modules/Internet.rb', line 224

def ShutdownAllLocalDHCPClients
  pid_directory = "/var/run/"

  dhcp_pidfiles = Convert.convert(
    WFM.Read(path(".local.dir"), pid_directory),
    from: "any",
    to:   "list <string>"
  )
  # only dhcpcd files
  dhcp_pidfiles = Builtins.filter(dhcp_pidfiles) do |one_pidfile|
    Builtins.regexpmatch(one_pidfile, "dhcpcd-.*.pid")
  end

  Builtins.y2milestone(
    "DHCPCD uses these file under %1 directory: %2",
    pid_directory,
    dhcp_pidfiles
  )

  return true if Builtins.size(dhcp_pidfiles) == 0

  Builtins.foreach(dhcp_pidfiles) do |one_pidfile|
    process_ID = Convert.to_string(
      WFM.Read(
        path(".local.string"),
        Builtins.sformat("%1%2", pid_directory, one_pidfile)
      )
    )
    Builtins.y2milestone("Killing process ID: %1", process_ID)
    # Calls a correct kill command for SIGHUP and waits
    # Then a confirmation SIGKILL is called (should be ignored because process has hopefully already ended)
    WFM.Execute(
      path(".local.bash"),
      Builtins.sformat(
        "(/usr/bin/kill -1 %1 && /usr/bin/sleep 1); /usr/bin/kill -9 %1 2>/dev/null;",
        process_ID.to_s.shellescape
      )
    )
  end

  true
end

#Start(log) ⇒ Object

Start the fastest interface

Parameters:

  • log (String)

    file for the commands output

Returns:

  • true if successful started



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
# File 'library/network/src/modules/Internet.rb', line 102

def Start(log)
  if (@type == "dsl" && @capi_adsl) || @type == "isdn"
    status = Service.Status("isdn")
    Builtins.y2milestone("We need ISDN service, status: %1", status)
    if status != 0 && !Service.Start("isdn")
      Builtins.y2error("start failed")
      return false
    end
  end

  cmd = Ops.add("/sbin/ifup ", @device)
  if NetworkService.IsManaged
    d_nm = "org.freedesktop.NetworkManager"
    s_nm = "/org/freedesktop/NetworkManager"
    # dbus-send [options] object interface.method arguments...
    cmd = Builtins.sformat(
      "dbus-send --system --dest=%1 %2 %1.setActiveDevice objpath:%2/Devices/%3",
      d_nm.shellescape,
      s_nm.shellescape,
      @device.shellescape
    )
  end

  cmd = Ops.add(Ops.add(Ops.add(cmd, "> "), log), " 2>&1") if log != ""

  ret = if @askpassword == true
    SCR.Execute(path(".target.bash_input"), cmd, @password)
  else
    SCR.Execute(path(".target.bash"), cmd)
  end
  if ret != 0
    Builtins.y2error(
      "%1",
      NetworkService.IsManaged ? "NM.setActiveDevice failed" : "ifup failed"
    )
    return false
  end

  if @type == "isdn" && !@capi_isdn && (SCR.Execute(
    path(".target.bash"),
    "/sbin/isdnctrl dial #{@device.shellescape}"
  ) != 0)
    Builtins.y2error("isdnctrl failed")
    return false
  end

  true
end

#StatusObject

Status of the fastest interface

Returns:

  • true if interface is up (which is not equal to connected)



164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'library/network/src/modules/Internet.rb', line 164

def Status
  # Skip test in case of NM because it returns code 3 (interface under NM controll)
  if NetworkService.IsManaged
    Builtins.y2milestone(
      "Skipping interface status test because of NetworkManager"
    )
    # only check if NM has not crashed
    return SCR.Execute(path(".target.bash"), "/usr/bin/pgrep NetworkManager") == 0
  end

  ret = SCR.Execute(path(".target.bash"), "/sbin/ifstatus #{@device.shellescape}")
  Builtins.y2milestone("ifstatus %1: %2", @device, ret)
  [0, 10].include?(ret)
end

#Stop(log) ⇒ Object

Stop the fastest interface

Parameters:

  • log (String)

    file for the commands output

Returns:

  • true if successful stopped



154
155
156
157
158
159
160
# File 'library/network/src/modules/Internet.rb', line 154

def Stop(log)
  # should also work for NM
  cmd = "/sbin/ifdown #{@device.shellescape}"
  cmd << "> #{log.shellescape} 2>&1" if log != ""

  SCR.Execute(path(".target.bash"), cmd) == 0
end