Skip to content

Commit

Permalink
Improved imput validation in the routing dialog. bnc#1105230
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Aug 31, 2018
1 parent 963f1d6 commit fa9220a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/include/network/services/routing.rb
Expand Up @@ -272,7 +272,7 @@ def RoutingEditDialog(id, entry, devs)
end
route = Builtins.add(route, val)
val = Convert.to_string(UI.QueryWidget(Id(:genmask), :Value))
if val != "-" && val != "0.0.0.0" && !valid_netmask?(val)
if val != "-" && !valid_netmask?(val)
# Popup::Error text
Popup.Error(_("Subnetmask is invalid."))
UI.SetFocus(Id(:genmask))
Expand Down Expand Up @@ -429,9 +429,19 @@ def handleRouting(_key, event)
nil
end

# Checks if the param is valid IPv4 / IPv6
#
# @param gw [String] IPv4 or IPv6 address
# @return [Bolean] true if given param is valid
def valid_gateway?(gw)
!gw.nil? && (gw.empty? || IP.Check(gw))
end

# An input validator for the Routing dialog
def validateRouting(_key, _event)
gw = UI.QueryWidget(Id(:gw), :Value)
return true if gw == "" || IP.Check(gw)

return true if valid_gateway?(gw)

Popup.Error(_("The default gateway is invalid."))
UI.SetFocus(Id(:gw))
Expand Down

0 comments on commit fa9220a

Please sign in to comment.