Class: Yast::InternetClass
- Inherits:
-
Module
- Object
- Module
- Yast::InternetClass
- Defined in:
- ../../src/modules/Internet.rb
Instance Method Summary (collapse)
-
- (Object) Connected
Test if the interface is connected.
-
- (Object) GetDevices
Used if NetworkInterfaces cannot find anything (usually because NM runs) Calls ip.
- - (Object) main
-
- (Object) Reset
Reset values.
-
- (Object) SetDemand(demand)
Set dial-on-demand.
-
- (Object) ShutdownAllLocalDHCPClients
DANGEROUS function.
-
- (Object) Start(log)
Start the fastest interface.
-
- (Object) Status
Status of the fastest interface.
-
- (Object) Stop(log)
Stop the fastest interface.
Instance Method Details
- (Object) Connected
Test if the interface is connected
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 |
# File '../../src/modules/Internet.rb', line 190 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"), "ip -oneline addr list | grep 'scope global' >&2" ) == 0 end |
- (Object) GetDevices
Used if NetworkInterfaces cannot find anything (usually because NM runs) Calls ip
89 90 91 92 93 94 95 96 97 98 99 |
# File '../../src/modules/Internet.rb', line 89 def GetDevices if @devices == nil command = "ip -oneline link list | sed -e 's/^[0-9]*: \\([^:]*\\).*/\\1/' | 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 |
- (Object) main
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 |
# File '../../src/modules/Internet.rb', line 35 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 |
- (Object) Reset
Reset values.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File '../../src/modules/Internet.rb', line 72 def Reset @device = "" @type = "" @logfile = "" @provider = "" @password = "" @demand = false @askpassword = nil @capi_adsl = false @capi_isdn = false nil end |
- (Object) SetDemand(demand)
Set dial-on-demand
220 221 222 223 224 225 226 227 228 |
# File '../../src/modules/Internet.rb', line 220 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 |
- (Object) ShutdownAllLocalDHCPClients
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).
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 |
# File '../../src/modules/Internet.rb', line 233 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( "(kill -1 %1 && sleep 1); kill -9 %1 2>/dev/null;", process_ID ) ) end true end |
- (Object) Start(log)
Start the fastest interface
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 |
# File '../../src/modules/Internet.rb', line 104 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 if !Service.Start("isdn") Builtins.y2error("start failed") return false end 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, s_nm, @device ) end cmd = Ops.add(Ops.add(Ops.add(cmd, "> "), log), " 2>&1") if log != "" ret = nil if @askpassword == true ret = SCR.Execute(path(".target.bash_input"), cmd, @password) else ret = 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 if SCR.Execute( path(".target.bash"), Ops.add("/sbin/isdnctrl dial ", @device) ) != 0 Builtins.y2error("isdnctrl failed") return false end end true end |
- (Object) Status
Status of the fastest interface
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File '../../src/modules/Internet.rb', line 171 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"), "pgrep NetworkManager") == 0 end ret = Convert.to_integer( SCR.Execute(path(".target.bash"), Ops.add("/sbin/ifstatus ", @device)) ) Builtins.y2milestone("ifstatus %1: %2", @device, ret) ret == 0 || ret == 10 end |
- (Object) Stop(log)
Stop the fastest interface
161 162 163 164 165 166 167 |
# File '../../src/modules/Internet.rb', line 161 def Stop(log) # should also work for NM cmd = Ops.add("/sbin/ifdown ", @device) cmd = Ops.add(Ops.add(Ops.add(cmd, "> "), log), " 2>&1") if log != "" ret = Convert.to_integer(SCR.Execute(path(".target.bash"), cmd)) ret == 0 end |