Renamed fields.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2022-04-12 15:36:01 +01:00
parent 07f2de6786
commit 889ef5adce
5 changed files with 51 additions and 55 deletions

View File

@ -194,38 +194,34 @@ namespace XenAdmin.Dialogs.Wlb
private bool checkEnabled_OkButton()
{
int dummy;
return (textboxWlbUrl.Text.Length > 0) &&
(IsValidServerAddress(textboxWlbUrl.Text)) &&
(textboxWLBPort.Text.Length > 0) &&
(int.TryParse(textboxWLBPort.Text, out dummy)) &&
(textboxWlbUserName.Text.Length > 0) &&
(textboxWlbPassword.Text.Length > 0) &&
(textboxXSUserName.Text.Length>0) &&
(textboxXSPassword.Text.Length>0);
return textboxWlbUrl.Text.Length > 0 &&
IsValidServerAddress(textboxWlbUrl.Text) &&
textboxWLBPort.Text.Length > 0 &&
int.TryParse(textboxWLBPort.Text, out _) &&
textboxWlbUserName.Text.Length > 0 &&
textboxWlbPassword.Text.Length > 0 &&
textboxXSUserName.Text.Length > 0 &&
textboxXSPassword.Text.Length > 0;
}
private bool IsValidServerAddress(string addr)
{
// A valid server address should be an IPv4 / IPv6 address or a valid domain name
IPAddress address;
if (IPAddress.TryParse(addr, out address))
if (IPAddress.TryParse(addr, out var address))
{
return address.AddressFamily == AddressFamily.InterNetwork || address.AddressFamily == AddressFamily.InterNetworkV6;
}
else
try
{
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;
}
// use UriBuilder as a quick validator
var ub = new UriBuilder($"http://{addr}:80/");
return ub.Host == addr;
}
catch
{
return false;
}
}

View File

@ -59,7 +59,7 @@ namespace XenAdmin
/// Anybody who chooses this for their password deserves a crash:
/// MODIFIER LETTER REVERSED GLOTTAL STOP, NKO SYMBOL GBAKURUNEN, CHAM PUNCTUATION DOUBLE DANDA, BOPOMOFO LETTER INNN
/// </summary>
private const string NO_PASSWORD = "\x02c1\x07f7\xaa5e\x31b3";
private const string MARKER_VALUE = "\x02c1\x07f7\xaa5e\x31b3";
private const string DISCONNECTED = "disconnected";
private const string CONNECTED = "connected";
@ -288,8 +288,8 @@ namespace XenAdmin
connection.Username = entryComps[0];
connection.Hostname = entryComps[1];
connection.Port = port;
// If password is NO_PASSWORD, this indicates we didn't save a password for this connection
if (entryComps[3] == NO_PASSWORD)
// If password is MARKER_VALUE, this indicates we didn't save a password for this connection
if (entryComps[3] == MARKER_VALUE)
{
connection.Password = null;
connection.ExpectPasswordIsCorrect = false;
@ -518,7 +518,7 @@ namespace XenAdmin
if (password == null)
{
// We don't have a password saved for this connection: save a special marker value
password = NO_PASSWORD;
password = MARKER_VALUE;
}
string entryStr = string.Join(SEPARATOR.ToString(), new string[] { username, serverName, port.ToString(), password, (saveDisconnected ? DISCONNECTED : CONNECTED), friendlyName });
if (poolMembers != null && poolMembers.Count > 0)

View File

@ -774,7 +774,7 @@ namespace XenAdmin.TabPages
if (result != DialogResult.Ignore)
{
creds.Add(DisableAdAction.KEY_USER, passPrompt.Username);
creds.Add(DisableAdAction.KEY_PASSWORD, passPrompt.Password);
creds.Add(DisableAdAction.KEY_PASS, passPrompt.Password);
}
new DisableAdAction(_connection, creds).RunAsync();

View File

@ -40,7 +40,7 @@ namespace XenAdmin.Actions
public class DisableAdAction : PureAsyncAction
{
public static readonly string KEY_USER = "user";
public static readonly string KEY_PASSWORD = "pass";
public static readonly string KEY_PASS = "pass";
private Dictionary<string, string> creds;
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

View File

@ -50,15 +50,10 @@ namespace XenAdmin.Actions
private string uploadToken;
private string diagnosticToken;
private const string identityTokenUrl = "/auth/api/create_identity/";
private const string uploadGrantTokenUrl = "/feeds/api/create_grant/";
private const string uploadTokenUrl = "/feeds/api/create_upload/";
private const string diagnosticTokenUrl = "/diag_sdk/token_grant/";
private readonly string identityTokenDomainName = "https://cis.citrix.com";
private readonly string uploadGrantTokenDomainName = "https://rttf.citrix.com";
private readonly string uploadTokenDomainName = "https://rttf.citrix.com";
private readonly string diagnosticTokenDomainName = " https://cis.citrix.com";
private readonly string _identityDomain = "https://cis.citrix.com";
private readonly string _uploadGrantDomain = "https://rttf.citrix.com";
private readonly string _uploadDomain = "https://rttf.citrix.com";
private readonly string _diagnosticDomain = " https://cis.citrix.com";
private readonly string productKey = "1a2d94a4263cd016dd7a7d510bde87f058a0b75d";
@ -75,20 +70,25 @@ namespace XenAdmin.Actions
}
public HealthCheckAuthenticationAction(string username, string password,
string identityTokenDomainName, string uploadGrantTokenDomainName, string uploadTokenDomainName, string diagnosticTokenDomainName,
string identityDomain, string uploadGrantDomain, string uploadDomain, string diagnosticDomain,
string productKey, long tokenExpiration, bool diagnosticTokenRequired, bool suppressHistory)
: this(username, password, tokenExpiration, suppressHistory)
{
if (!string.IsNullOrEmpty(identityTokenDomainName))
this.identityTokenDomainName = identityTokenDomainName;
if (!string.IsNullOrEmpty(uploadGrantTokenDomainName))
this.uploadGrantTokenDomainName = uploadGrantTokenDomainName;
if (!string.IsNullOrEmpty(uploadTokenDomainName))
this.uploadTokenDomainName = uploadTokenDomainName;
if (!string.IsNullOrEmpty(diagnosticTokenDomainName))
this.diagnosticTokenDomainName = diagnosticTokenDomainName;
if (!string.IsNullOrEmpty(identityDomain))
_identityDomain = identityDomain;
if (!string.IsNullOrEmpty(uploadGrantDomain))
_uploadGrantDomain = uploadGrantDomain;
if (!string.IsNullOrEmpty(uploadDomain))
_uploadDomain = uploadDomain;
if (!string.IsNullOrEmpty(diagnosticDomain))
_diagnosticDomain = diagnosticDomain;
if (!string.IsNullOrEmpty(productKey))
this.productKey = productKey;
this.diagnosticTokenRequired = diagnosticTokenRequired;
}
@ -131,21 +131,21 @@ namespace XenAdmin.Actions
username,
password
});
var urlString = string.Format("{0}{1}", identityTokenDomainName, identityTokenUrl);
var urlString = $"{_identityDomain}/auth/api/create_identity/";
try
{
return GetToken(urlString, json, null);
}
catch (WebException e)
{
log.Info($"WebException while getting identity token from {identityTokenDomainName}.", e);
log.Info($"WebException while getting identity token from {_identityDomain}.", e);
if (e.Status == WebExceptionStatus.ProtocolError && ((HttpWebResponse) e.Response).StatusCode == HttpStatusCode.Forbidden)
throw new HealthCheckAuthenticationException(Messages.HEALTH_CHECK_AUTHENTICATION_INVALID_CREDENTIALS, e);
throw;
}
catch (Exception e)
{
log.Info($"Exception while getting identity token from {identityTokenDomainName}.", e);
log.Info($"Exception while getting identity token from {_identityDomain}.", e);
throw;
}
}
@ -164,7 +164,7 @@ namespace XenAdmin.Actions
expiration = tokenExpiration
});
}
var urlString = string.Format("{0}{1}", uploadGrantTokenDomainName, uploadGrantTokenUrl);
var urlString = $"{_uploadGrantDomain}/feeds/api/create_grant/";
try
{
@ -172,7 +172,7 @@ namespace XenAdmin.Actions
}
catch (Exception e)
{
log.Info($"Exception while getting upload grant token from {uploadGrantTokenDomainName}.", e);
log.Info($"Exception while getting upload grant token from {_uploadGrantDomain}.", e);
throw;
}
}
@ -185,14 +185,14 @@ namespace XenAdmin.Actions
product_key = productKey,
expiration = tokenExpiration
});
var urlString = string.Format("{0}{1}", uploadTokenDomainName, uploadTokenUrl);
var urlString = $"{_uploadDomain}/feeds/api/create_upload/";
try
{
return GetToken(urlString, json, null);
}
catch (Exception e)
{
log.Info($"Exception while getting upload token from {uploadTokenDomainName}.", e);
log.Info($"Exception while getting upload token from {_uploadDomain}.", e);
throw;
}
}
@ -204,7 +204,7 @@ namespace XenAdmin.Actions
agent = "XenServer",
max_age = tokenExpiration
});
var urlString = string.Format("{0}{1}", diagnosticTokenDomainName, diagnosticTokenUrl);
var urlString = $"{_diagnosticDomain}/diag_sdk/token_grant/";
try
{
@ -212,7 +212,7 @@ namespace XenAdmin.Actions
}
catch (Exception e)
{
log.Info($"Exception while getting diagnostic token from {diagnosticTokenDomainName}.", e);
log.Info($"Exception while getting diagnostic token from {_diagnosticDomain}.", e);
throw;
}
}