Skip to content
Permalink
Browse files

Merge pull request #283 from kaifengz/CA-146821-master

CA-146821: Accept IPv6 address when configuring WLB
  • Loading branch information
Stephen Turner
Stephen Turner committed Jan 6, 2015
2 parents 36fb880 + e89907b commit e4729a640265b5fa2191e9f7361124d8398f49c7
Showing with 27 additions and 9 deletions.
  1. +27 −9 XenAdmin/Dialogs/Wlb/WlbCredentialsDialog.cs
@@ -34,6 +34,8 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;

@@ -165,7 +167,11 @@ private bool EnableWlb()
private bool InitializeWLB()
{
//combine url and port
string wlbUrl = textboxWlbUrl.Text + ":" + textboxWLBPort.Text;
string wlbHost = textboxWlbUrl.Text;
string wlbPort = textboxWLBPort.Text;
IPAddress address;
string wlbUrl = (IPAddress.TryParse(wlbHost, out address) && address.AddressFamily == AddressFamily.InterNetworkV6) ?
("[" + wlbHost + "]:" + wlbPort) : (wlbHost + ":" + wlbPort);

//handle the wlb creds
string wlbUserName = textboxWlbUserName.Text;
@@ -194,7 +200,7 @@ private bool checkEnabled_OkButton()
{
int dummy;
return (textboxWlbUrl.Text.Length > 0) &&
(IsValidUri(textboxWlbUrl.Text)) &&
(IsValidServerAddress(textboxWlbUrl.Text)) &&
(textboxWLBPort.Text.Length > 0) &&
(int.TryParse(textboxWLBPort.Text, out dummy)) &&
(textboxWlbUserName.Text.Length > 0) &&
@@ -203,16 +209,28 @@ private bool checkEnabled_OkButton()
(textboxXSPassword.Text.Length>0);
}

private bool IsValidUri(string uri)
private bool IsValidServerAddress(string addr)
{
bool result = false;
try
// A valid server address should be an IPv4 / IPv6 address or a valid domain name

IPAddress address;
if (IPAddress.TryParse(addr, out address))
{
UriBuilder ub = new UriBuilder(uri);
result = true;
return address.AddressFamily == AddressFamily.InterNetwork || address.AddressFamily == AddressFamily.InterNetworkV6;
}
else
{
try
{
// adopt UriBuilder as a quick validator
UriBuilder ub = new UriBuilder(string.Format("http://user:password@{0}:80/", addr));
return ub.Host == addr;
}
catch
{
return false;
}
}
catch { }
return result;
}

private void textboxWLBPort_TextChanged(object sender, EventArgs e)

0 comments on commit e4729a6

Please sign in to comment.
You can’t perform that action at this time.