From 0bbc6eb6e259b999bdfac033ea7b6e81a87f5896 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 14 Sep 2011 19:30:38 +0200 Subject: [PATCH 1/3] Get rid of getCurrentIP There are several problems with getCurrentIP: - the method used to determine the IP is fragile at best since it returns the address of the interface that is able to reach an route to the target host - so it cannot be used to get the ip of a specific interface - it breaks if there is no route to the target host - it does not belong into the frontend There is a corresponding patch for the rest-service that adds the required functionality to the backend. I'll push it into my provide_actual_ipaddr branch on github. --- .../app/controllers/network_controller.rb | 24 ++++--------------- .../network/app/views/network/index.html.erb | 2 +- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/plugins/network/app/controllers/network_controller.rb b/plugins/network/app/controllers/network_controller.rb index 373b2614..69dccb2c 100644 --- a/plugins/network/app/controllers/network_controller.rb +++ b/plugins/network/app/controllers/network_controller.rb @@ -19,17 +19,6 @@ # you may find current contact information at www.novell.com #++ -require 'socket' -def getCurrentIP - ip, orig, Socket.do_not_reverse_lookup = "", Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily - UDPSocket.open do |s| - s.connect '64.233.187.99', 1 - ip = s.addr.last - end - ensure Socket.do_not_reverse_lookup = orig - return ip -end - class NetworkController < ApplicationController before_filter :login_required @@ -95,13 +84,7 @@ def index @bootproto = ifc.bootproto @bootproto = STATIC_BOOT_ID if @bootproto.blank? - if @bootproto == STATIC_BOOT_ID - ipaddr = ifc.ipaddr - else - ipaddr = "/" - end - - @ip, @netmask = ipaddr.split "/" + @ip, @netmask = @bootproto == STATIC_BOOT_ID ? ifc.ipaddr.split("/"): nil # when detect PREFIXLEN with leading "/" if ifc.bootproto == STATIC_BOOT_ID && NETMASK_RANGE.include?(@netmask.to_i) @netmask = "/"+@netmask @@ -113,8 +96,9 @@ def index @name = hn.name @domain = hn.domain - @dhcp_ip = getCurrentIP; - + if @bootproto == "dhcp" + @actual_ip, @actual_netmask = ifc.actual_ipaddr.split("/") + end @dhcp_hostname_enabled = hn.attributes.include?("dhcp_hostname") @dhcp_hostname = @dhcp_hostname_enabled && hn.dhcp_hostname=="1" @nameservers = dns.nameservers diff --git a/plugins/network/app/views/network/index.html.erb b/plugins/network/app/views/network/index.html.erb index 0e3e93bc..48379e92 100644 --- a/plugins/network/app/views/network/index.html.erb +++ b/plugins/network/app/views/network/index.html.erb @@ -179,7 +179,7 @@
<%=_("Current IP address (DHCP)")%> - <%= @dhcp_ip %> + <%= @actual_ip %>
From fc8203ad135e3a3b09ddcfc084c55b4443a1ff81 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 20 Sep 2011 16:38:58 +0200 Subject: [PATCH 2/3] Preserve the old behavior wrt @ip, @netmask when @bootproto != 'static' --- plugins/network/app/controllers/network_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/network/app/controllers/network_controller.rb b/plugins/network/app/controllers/network_controller.rb index 69dccb2c..2b82c62c 100644 --- a/plugins/network/app/controllers/network_controller.rb +++ b/plugins/network/app/controllers/network_controller.rb @@ -84,7 +84,7 @@ def index @bootproto = ifc.bootproto @bootproto = STATIC_BOOT_ID if @bootproto.blank? - @ip, @netmask = @bootproto == STATIC_BOOT_ID ? ifc.ipaddr.split("/"): nil + @ip, @netmask = @bootproto == STATIC_BOOT_ID ? ifc.ipaddr.split("/"): ["", ""] # when detect PREFIXLEN with leading "/" if ifc.bootproto == STATIC_BOOT_ID && NETMASK_RANGE.include?(@netmask.to_i) @netmask = "/"+@netmask From 26d0169a78fc1da726b56e3d74ee61561eaac257 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 20 Sep 2011 16:39:58 +0200 Subject: [PATCH 3/3] Don't show the current ip if it couldn't be determined --- plugins/network/app/views/network/index.html.erb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/network/app/views/network/index.html.erb b/plugins/network/app/views/network/index.html.erb index 48379e92..067e9b84 100644 --- a/plugins/network/app/views/network/index.html.erb +++ b/plugins/network/app/views/network/index.html.erb @@ -176,12 +176,14 @@ <%=text_field_tag :searchdomains, @searchdomains.join(" "), :class=>"searchdomains", :disabled => write_disabled %> -
- - <%=_("Current IP address (DHCP)")%> - <%= @actual_ip %> - -
+ <% if @actual_ip %> +
+ + <%=_("Current IP address (DHCP)")%> + <%= @actual_ip %> + +
+ <% end %>