2017-01-16 20:59:50 +01:00
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2015-07-01 16:58:58 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
* that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
* following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
* materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2015-09-15 14:48:50 +02:00
|
|
|
using System.Drawing;
|
2015-07-01 16:58:58 +02:00
|
|
|
using System.Windows.Forms;
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
using XenAdmin.Core;
|
2015-08-21 16:18:18 +02:00
|
|
|
using XenAdmin.Model;
|
2015-07-01 16:58:58 +02:00
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
2015-07-29 09:44:41 +02:00
|
|
|
namespace XenAdmin.Dialogs.HealthCheck
|
2015-07-01 16:58:58 +02:00
|
|
|
{
|
2015-07-29 09:44:41 +02:00
|
|
|
public partial class HealthCheckSettingsDialog : XenDialogBase
|
2015-07-01 16:58:58 +02:00
|
|
|
{
|
2015-09-15 14:48:50 +02:00
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
2015-07-01 16:58:58 +02:00
|
|
|
private readonly Pool pool;
|
2015-07-29 09:44:41 +02:00
|
|
|
private HealthCheckSettings healthCheckSettings;
|
2015-07-01 16:58:58 +02:00
|
|
|
private bool authenticationRequired;
|
|
|
|
private bool authenticated;
|
|
|
|
private string authenticationToken;
|
2015-08-27 01:30:02 +02:00
|
|
|
private string diagnosticToken;
|
2015-07-06 18:02:55 +02:00
|
|
|
private string xsUserName;
|
|
|
|
private string xsPassword;
|
2015-07-01 16:58:58 +02:00
|
|
|
|
2020-06-02 05:49:10 +02:00
|
|
|
internal override string HelpName => "HealthCheckSettingsDialog";
|
2016-02-18 14:09:53 +01:00
|
|
|
|
2015-07-29 09:44:41 +02:00
|
|
|
public HealthCheckSettingsDialog(Pool pool, bool enrollNow)
|
2019-10-10 18:15:16 +02:00
|
|
|
:base(pool.Connection)
|
2015-07-01 16:58:58 +02:00
|
|
|
{
|
|
|
|
this.pool = pool;
|
2017-09-03 04:33:29 +02:00
|
|
|
healthCheckSettings = pool.HealthCheckSettings();
|
2015-07-06 18:02:55 +02:00
|
|
|
if (enrollNow)
|
2015-07-29 09:44:41 +02:00
|
|
|
healthCheckSettings.Status = HealthCheckStatus.Enabled;
|
2015-08-27 01:30:02 +02:00
|
|
|
authenticated = healthCheckSettings.TryGetExistingTokens(pool.Connection, out authenticationToken, out diagnosticToken);
|
|
|
|
authenticationRequired = !authenticated;
|
2020-06-01 15:14:50 +02:00
|
|
|
xsUserName = healthCheckSettings.GetSecretInfo(pool.Connection, HealthCheckSettings.UPLOAD_CREDENTIAL_USER_SECRET);
|
|
|
|
xsPassword = healthCheckSettings.GetSecretInfo(pool.Connection, HealthCheckSettings.UPLOAD_CREDENTIAL_PASSWORD_SECRET);
|
2015-07-01 16:58:58 +02:00
|
|
|
InitializeComponent();
|
2021-03-16 02:50:45 +01:00
|
|
|
|
|
|
|
rubricLabel.Text = string.Format(rubricLabel.Text, BrandManager.Cis, BrandManager.ProductBrand);
|
|
|
|
label3.Text = string.Format(label3.Text, BrandManager.ProductBrand);
|
|
|
|
decentGroupBox1.Text = string.Format(decentGroupBox1.Text, BrandManager.Cis);
|
|
|
|
decentGroupBoxXSCredentials.Text = string.Format(decentGroupBoxXSCredentials.Text, BrandManager.ProductBrand);
|
|
|
|
currentXsCredentialsRadioButton.Text = string.Format(currentXsCredentialsRadioButton.Text, BrandManager.BrandConsole);
|
|
|
|
|
2015-07-01 16:58:58 +02:00
|
|
|
PopulateControls();
|
|
|
|
InitializeControls();
|
|
|
|
UpdateButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PopulateControls()
|
|
|
|
{
|
|
|
|
var list = BuildDays();
|
|
|
|
var ds = new BindingSource(list, null);
|
|
|
|
dayOfWeekComboBox.DataSource = ds;
|
|
|
|
dayOfWeekComboBox.ValueMember = "key";
|
|
|
|
dayOfWeekComboBox.DisplayMember = "value";
|
|
|
|
|
|
|
|
var list1 = BuildHours();
|
|
|
|
var ds1 = new BindingSource(list1, null);
|
|
|
|
timeOfDayComboBox.DataSource = ds1;
|
|
|
|
timeOfDayComboBox.ValueMember = "key";
|
|
|
|
timeOfDayComboBox.DisplayMember = "value";
|
|
|
|
}
|
|
|
|
|
|
|
|
private Dictionary<int, string> BuildDays()
|
|
|
|
{
|
|
|
|
Dictionary<int, string> days = new Dictionary<int, string>();
|
|
|
|
foreach (var dayOfWeek in Enum.GetValues(typeof(DayOfWeek)))
|
|
|
|
{
|
2016-04-27 15:22:50 +02:00
|
|
|
days.Add((int)dayOfWeek, HelpersGUI.DayOfWeekToString((DayOfWeek)dayOfWeek, true));
|
2015-07-01 16:58:58 +02:00
|
|
|
}
|
|
|
|
return days;
|
|
|
|
}
|
|
|
|
|
|
|
|
private SortedDictionary<int, string> BuildHours()
|
|
|
|
{
|
|
|
|
SortedDictionary<int, string> hours = new SortedDictionary<int, string>();
|
|
|
|
for (int hour = 0; hour <= 23; hour++)
|
|
|
|
{
|
|
|
|
DateTime time = new DateTime(1900, 1, 1, hour, 0, 0);
|
|
|
|
hours.Add(hour, HelpersGUI.DateTimeToString(time, Messages.DATEFORMAT_HM, true));
|
|
|
|
}
|
|
|
|
return hours;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void InitializeControls()
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
Text = String.Format(Messages.HEALTHCHECK_ENROLLMENT_TITLE, pool.Name());
|
2020-06-02 05:49:10 +02:00
|
|
|
tableLayoutPanel5.Visible = false;
|
2017-02-09 16:16:11 +01:00
|
|
|
|
2020-06-02 05:49:10 +02:00
|
|
|
if (authenticationRequired)
|
2017-02-09 16:16:11 +01:00
|
|
|
{
|
2020-06-02 05:49:10 +02:00
|
|
|
string noAuthTokenMessage = string.Format(Messages.HEALTHCHECK_AUTHENTICATION_RUBRIC_NO_TOKEN,
|
2021-03-16 02:50:45 +01:00
|
|
|
BrandManager.Cis, Messages.MY_CITRIX_CREDENTIALS_URL);
|
2020-06-02 05:49:10 +02:00
|
|
|
|
2017-02-09 16:16:11 +01:00
|
|
|
authRubricLinkLabel.Text = noAuthTokenMessage;
|
2020-06-02 05:49:10 +02:00
|
|
|
authRubricLinkLabel.LinkArea = new LinkArea(noAuthTokenMessage.IndexOf(Messages.MY_CITRIX_CREDENTIALS_URL),
|
|
|
|
Messages.MY_CITRIX_CREDENTIALS_URL.Length);
|
2017-02-09 16:16:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-16 02:50:45 +01:00
|
|
|
authRubricLinkLabel.Text = string.Format(Messages.HEALTHCHECK_AUTHENTICATION_RUBRIC_EXISTING_TOKEN,
|
|
|
|
BrandManager.Cis, BrandManager.BrandConsole);
|
2020-06-02 05:49:10 +02:00
|
|
|
authRubricLinkLabel.LinkArea = new LinkArea(0, 0);
|
2017-02-09 16:16:11 +01:00
|
|
|
}
|
2015-07-29 09:44:41 +02:00
|
|
|
|
|
|
|
enrollmentCheckBox.Checked = healthCheckSettings.Status != HealthCheckStatus.Disabled;
|
|
|
|
frequencyNumericBox.Value = healthCheckSettings.IntervalInWeeks;
|
|
|
|
dayOfWeekComboBox.SelectedValue = (int)healthCheckSettings.DayOfWeek;
|
|
|
|
timeOfDayComboBox.SelectedValue = healthCheckSettings.TimeOfDay;
|
2015-07-06 18:02:55 +02:00
|
|
|
|
2015-07-01 16:58:58 +02:00
|
|
|
existingAuthenticationRadioButton.Enabled = existingAuthenticationRadioButton.Checked = !authenticationRequired;
|
|
|
|
newAuthenticationRadioButton.Checked = authenticationRequired;
|
2015-07-06 18:02:55 +02:00
|
|
|
SetMyCitrixCredentials(existingAuthenticationRadioButton.Checked);
|
|
|
|
|
|
|
|
bool useCurrentXsCredentials = string.IsNullOrEmpty(xsUserName) || xsUserName == pool.Connection.Username;
|
|
|
|
newXsCredentialsRadioButton.Checked = !useCurrentXsCredentials;
|
|
|
|
currentXsCredentialsRadioButton.Checked = useCurrentXsCredentials;
|
|
|
|
SetXSCredentials(currentXsCredentialsRadioButton.Checked);
|
2015-07-01 16:58:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private bool ChangesMade()
|
|
|
|
{
|
2015-07-29 09:44:41 +02:00
|
|
|
if (enrollmentCheckBox.Checked && healthCheckSettings.Status != HealthCheckStatus.Enabled)
|
2015-07-01 16:58:58 +02:00
|
|
|
return true;
|
2015-07-29 09:44:41 +02:00
|
|
|
if (!enrollmentCheckBox.Checked && healthCheckSettings.Status != HealthCheckStatus.Disabled)
|
2015-07-01 16:58:58 +02:00
|
|
|
return true;
|
2015-07-29 09:44:41 +02:00
|
|
|
if (frequencyNumericBox.Value != healthCheckSettings.IntervalInWeeks)
|
2015-07-01 16:58:58 +02:00
|
|
|
return true;
|
2015-07-29 09:44:41 +02:00
|
|
|
if (dayOfWeekComboBox.SelectedIndex != (int)healthCheckSettings.DayOfWeek)
|
2015-07-01 16:58:58 +02:00
|
|
|
return true;
|
2015-07-29 09:44:41 +02:00
|
|
|
if (timeOfDayComboBox.SelectedIndex != healthCheckSettings.TimeOfDay)
|
2015-07-01 16:58:58 +02:00
|
|
|
return true;
|
2020-06-01 15:14:50 +02:00
|
|
|
if (authenticationToken != healthCheckSettings.GetSecretInfo(pool.Connection, HealthCheckSettings.UPLOAD_TOKEN_SECRET))
|
2015-07-01 04:35:59 +02:00
|
|
|
return true;
|
2015-07-06 18:02:55 +02:00
|
|
|
if (textboxXSUserName.Text != xsUserName)
|
2015-07-01 04:35:59 +02:00
|
|
|
return true;
|
2015-07-06 18:02:55 +02:00
|
|
|
if (textboxXSPassword.Text != xsPassword)
|
2015-07-01 16:58:58 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateButtons()
|
|
|
|
{
|
2020-06-02 05:49:10 +02:00
|
|
|
okButton.Enabled = CheckCredentialsEntered() && !errorLabel.Visible;
|
2015-07-01 16:58:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
|
|
{
|
2020-06-02 05:49:10 +02:00
|
|
|
if (enrollmentCheckBox.Checked && newAuthenticationRadioButton.Checked)
|
|
|
|
CheckUploadAuthentication();
|
|
|
|
else
|
|
|
|
SaveAndClose();
|
|
|
|
}
|
2015-07-06 18:02:55 +02:00
|
|
|
|
2020-06-02 05:49:10 +02:00
|
|
|
private void SaveAndClose()
|
|
|
|
{
|
2015-07-01 16:58:58 +02:00
|
|
|
if (ChangesMade())
|
|
|
|
{
|
2015-08-27 01:30:02 +02:00
|
|
|
var newHealthCheckSettings = new HealthCheckSettings(pool.health_check_config);
|
|
|
|
|
|
|
|
newHealthCheckSettings.Status = enrollmentCheckBox.Checked ? HealthCheckStatus.Enabled : HealthCheckStatus.Disabled;
|
|
|
|
newHealthCheckSettings.IntervalInDays = (int)(frequencyNumericBox.Value * 7);
|
|
|
|
newHealthCheckSettings.DayOfWeek = (DayOfWeek)dayOfWeekComboBox.SelectedValue;
|
|
|
|
newHealthCheckSettings.TimeOfDay = (int)timeOfDayComboBox.SelectedValue;
|
|
|
|
newHealthCheckSettings. RetryInterval = HealthCheckSettings.DEFAULT_RETRY_INTERVAL;
|
|
|
|
|
2015-11-04 13:06:52 +01:00
|
|
|
new SaveHealthCheckSettingsAction(pool, newHealthCheckSettings, authenticationToken, diagnosticToken, textboxXSUserName.Text.Trim(), textboxXSPassword.Text, false).RunAsync();
|
|
|
|
new TransferHealthCheckSettingsAction(pool, newHealthCheckSettings, textboxXSUserName.Text.Trim(), textboxXSPassword.Text, true).RunAsync();
|
2015-07-01 16:58:58 +02:00
|
|
|
}
|
2020-06-02 05:49:10 +02:00
|
|
|
|
2015-07-01 16:58:58 +02:00
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void enrollmentCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
{
|
2017-04-28 16:39:55 +02:00
|
|
|
if (!enrollmentCheckBox.Checked)
|
|
|
|
HideTestCredentialsStatus();
|
2015-07-01 16:58:58 +02:00
|
|
|
UpdateButtons();
|
|
|
|
}
|
|
|
|
|
2020-06-02 05:49:10 +02:00
|
|
|
private void newXsCredentialsRadioButton_CheckedChanged(object sender, EventArgs e)
|
2015-07-06 18:02:55 +02:00
|
|
|
{
|
|
|
|
SetXSCredentials(currentXsCredentialsRadioButton.Checked);
|
2015-09-23 14:26:45 +02:00
|
|
|
testCredentialsButton.Enabled = newXsCredentialsRadioButton.Checked &&
|
2015-11-04 13:06:52 +01:00
|
|
|
!string.IsNullOrEmpty(textboxXSUserName.Text.Trim()) && !string.IsNullOrEmpty(textboxXSPassword.Text);
|
2017-04-28 16:39:55 +02:00
|
|
|
UpdateButtons();
|
2015-07-06 18:02:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void SetXSCredentials(bool useCurrent)
|
2015-07-01 16:58:58 +02:00
|
|
|
{
|
2015-07-06 18:02:55 +02:00
|
|
|
if (useCurrent)
|
|
|
|
{
|
|
|
|
textboxXSUserName.Text = pool.Connection.Username;
|
|
|
|
textboxXSPassword.Text = pool.Connection.Password;
|
|
|
|
textboxXSUserName.Enabled = false;
|
|
|
|
textboxXSPassword.Enabled = false;
|
|
|
|
}
|
|
|
|
else
|
2015-07-01 16:58:58 +02:00
|
|
|
{
|
2015-07-06 18:02:55 +02:00
|
|
|
textboxXSUserName.Text = xsUserName;
|
|
|
|
textboxXSPassword.Text = xsPassword;
|
|
|
|
textboxXSUserName.Enabled = true;
|
|
|
|
textboxXSPassword.Enabled = true;
|
|
|
|
}
|
2015-07-01 16:58:58 +02:00
|
|
|
}
|
|
|
|
|
2015-07-06 18:02:55 +02:00
|
|
|
private void SetMyCitrixCredentials(bool useExisting)
|
|
|
|
{
|
|
|
|
if (useExisting)
|
|
|
|
{
|
|
|
|
//textBoxMyCitrixUsername.Text = String.Empty;
|
|
|
|
//textBoxMyCitrixPassword.Text = String.Empty;
|
|
|
|
textBoxMyCitrixUsername.Enabled = false;
|
|
|
|
textBoxMyCitrixPassword.Enabled = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//textBoxMyCitrixUsername.Text = String.Empty;
|
|
|
|
//textBoxMyCitrixPassword.Text = String.Empty;
|
|
|
|
textBoxMyCitrixUsername.Enabled = true;
|
|
|
|
textBoxMyCitrixPassword.Enabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool CheckCredentialsEntered()
|
|
|
|
{
|
2017-04-28 16:39:55 +02:00
|
|
|
if (!enrollmentCheckBox.Checked)
|
2015-07-06 18:02:55 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (newAuthenticationRadioButton.Checked &&
|
2015-11-04 13:06:52 +01:00
|
|
|
(string.IsNullOrEmpty(textBoxMyCitrixUsername.Text.Trim()) || string.IsNullOrEmpty(textBoxMyCitrixPassword.Text)))
|
2015-07-06 18:02:55 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (newXsCredentialsRadioButton.Checked &&
|
2015-11-04 13:06:52 +01:00
|
|
|
(string.IsNullOrEmpty(textboxXSUserName.Text.Trim()) || string.IsNullOrEmpty(textboxXSPassword.Text)))
|
2015-07-06 18:02:55 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-02 05:49:10 +02:00
|
|
|
private void CheckUploadAuthentication()
|
2015-07-06 18:02:55 +02:00
|
|
|
{
|
2015-09-03 12:49:53 +02:00
|
|
|
var action = new HealthCheckAuthenticationAction(textBoxMyCitrixUsername.Text.Trim(), textBoxMyCitrixPassword.Text.Trim(),
|
2015-07-29 09:44:41 +02:00
|
|
|
Registry.HealthCheckIdentityTokenDomainName, Registry.HealthCheckUploadGrantTokenDomainName, Registry.HealthCheckUploadTokenDomainName,
|
2021-03-16 12:18:16 +01:00
|
|
|
Registry.HealthCheckDiagnosticDomainName, Registry.HealthCheckProductKey, 0, true, true);
|
2020-06-02 05:49:10 +02:00
|
|
|
action.Completed += action_Completed;
|
2015-07-06 18:02:55 +02:00
|
|
|
|
2020-06-02 05:49:10 +02:00
|
|
|
okButton.Enabled = false;
|
|
|
|
pictureBoxStatus.Image = Images.StaticImages.ajax_loader;
|
|
|
|
labelStatus.Text = action.Description;
|
|
|
|
labelStatus.ForeColor = SystemColors.ControlText;
|
|
|
|
tableLayoutPanel5.Visible = true;
|
|
|
|
action.RunAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void action_Completed(ActionBase a)
|
|
|
|
{
|
|
|
|
Program.Invoke(this, () =>
|
2015-07-06 18:02:55 +02:00
|
|
|
{
|
2020-06-02 05:49:10 +02:00
|
|
|
if (!a.Succeeded || !(a is HealthCheckAuthenticationAction action))
|
|
|
|
{
|
|
|
|
authenticationToken = null;
|
|
|
|
authenticated = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
authenticationToken = action.UploadToken; // current upload token
|
|
|
|
diagnosticToken = action.DiagnosticToken; // current diagnostic token
|
|
|
|
authenticated = !string.IsNullOrEmpty(authenticationToken) && !string.IsNullOrEmpty(diagnosticToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!authenticated)
|
|
|
|
{
|
|
|
|
pictureBoxStatus.Image = Images.StaticImages._000_error_h32bit_16;
|
|
|
|
labelStatus.Text = a.Exception != null ? a.Exception.Message : Messages.ERROR_UNKNOWN;
|
|
|
|
labelStatus.ForeColor = Color.Red;
|
|
|
|
okButton.Enabled = true;
|
|
|
|
return;
|
|
|
|
}
|
2015-07-06 18:02:55 +02:00
|
|
|
|
2020-06-02 05:49:10 +02:00
|
|
|
tableLayoutPanel5.Visible = false;
|
|
|
|
okButton.Enabled = true;
|
|
|
|
SaveAndClose();
|
|
|
|
});
|
2015-07-06 18:02:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void credentials_TextChanged(object sender, EventArgs e)
|
2015-07-01 16:58:58 +02:00
|
|
|
{
|
2020-06-02 05:49:10 +02:00
|
|
|
tableLayoutPanel5.Visible = false;
|
2015-07-01 16:58:58 +02:00
|
|
|
UpdateButtons();
|
|
|
|
}
|
2015-08-27 14:50:35 +02:00
|
|
|
|
2015-09-15 14:48:50 +02:00
|
|
|
private void xsCredentials_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
testCredentialsButton.Enabled = newXsCredentialsRadioButton.Checked &&
|
2015-11-04 13:06:52 +01:00
|
|
|
!string.IsNullOrEmpty(textboxXSUserName.Text.Trim()) && !string.IsNullOrEmpty(textboxXSPassword.Text);
|
2015-09-15 14:48:50 +02:00
|
|
|
HideTestCredentialsStatus();
|
|
|
|
}
|
|
|
|
|
2015-08-27 14:50:35 +02:00
|
|
|
private void PolicyStatementLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|
|
|
{
|
2015-09-10 14:08:49 +02:00
|
|
|
new HealthCheckPolicyStatementDialog().ShowDialog(this);
|
2015-08-27 14:50:35 +02:00
|
|
|
}
|
2015-09-15 14:48:50 +02:00
|
|
|
|
|
|
|
private void testCredentialsButton_Click(object sender, EventArgs e)
|
|
|
|
{
|
2017-04-28 16:39:55 +02:00
|
|
|
okButton.Enabled = false;
|
2015-09-15 14:48:50 +02:00
|
|
|
CheckXenServerCredentials();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CheckXenServerCredentials()
|
|
|
|
{
|
2015-11-04 13:06:52 +01:00
|
|
|
if (string.IsNullOrEmpty(textboxXSUserName.Text.Trim()) || string.IsNullOrEmpty(textboxXSPassword.Text))
|
2015-09-15 14:48:50 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
bool passedRbacChecks = false;
|
|
|
|
DelegatedAsyncAction action = new DelegatedAsyncAction(connection,
|
|
|
|
Messages.CREDENTIALS_CHECKING, "", "",
|
|
|
|
delegate
|
|
|
|
{
|
|
|
|
Session elevatedSession = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
elevatedSession = connection.ElevatedSession(textboxXSUserName.Text.Trim(), textboxXSPassword.Text);
|
|
|
|
if (elevatedSession != null && (elevatedSession.IsLocalSuperuser || SessionAuthorized(elevatedSession, Role.ValidRoleList("pool.set_health_check_config", connection))))
|
|
|
|
passedRbacChecks = true;
|
|
|
|
}
|
2015-11-09 23:34:32 +01:00
|
|
|
catch (Failure f)
|
|
|
|
{
|
|
|
|
if (f.ErrorDescription.Count > 0 && f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED)
|
|
|
|
{
|
|
|
|
// we use a different error message here from the standard one in friendly names
|
|
|
|
throw new Exception(Messages.HEALTH_CHECK_USER_HAS_NO_PERMISSION_TO_CONNECT);
|
|
|
|
}
|
|
|
|
throw;
|
|
|
|
}
|
2015-09-15 14:48:50 +02:00
|
|
|
finally
|
|
|
|
{
|
|
|
|
if (elevatedSession != null)
|
|
|
|
{
|
|
|
|
elevatedSession.Connection.Logout(elevatedSession);
|
|
|
|
elevatedSession = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
|
|
|
|
action.Completed += delegate
|
|
|
|
{
|
|
|
|
log.DebugFormat("Logging with the new credentials returned: {0} ", passedRbacChecks);
|
|
|
|
Program.Invoke(Program.MainWindow, () =>
|
|
|
|
{
|
|
|
|
if (passedRbacChecks)
|
2017-04-28 16:39:55 +02:00
|
|
|
{
|
2020-06-02 05:49:10 +02:00
|
|
|
ShowTestCredentialsStatus(Images.StaticImages._000_Tick_h32bit_16, null);
|
2017-04-28 16:39:55 +02:00
|
|
|
okButton.Enabled = true;
|
|
|
|
}
|
2015-09-15 14:48:50 +02:00
|
|
|
else
|
2017-04-28 16:39:55 +02:00
|
|
|
{
|
|
|
|
okButton.Enabled = false;
|
2020-06-02 05:49:10 +02:00
|
|
|
ShowTestCredentialsStatus(Images.StaticImages._000_error_h32bit_16, action.Exception != null ? action.Exception.Message : Messages.HEALTH_CHECK_USER_NOT_AUTHORIZED);
|
2017-04-28 16:39:55 +02:00
|
|
|
}
|
2015-09-23 14:26:45 +02:00
|
|
|
textboxXSUserName.Enabled = textboxXSPassword.Enabled = testCredentialsButton.Enabled = newXsCredentialsRadioButton.Checked;
|
2015-09-15 14:48:50 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
log.Debug("Testing logging in with the new credentials");
|
2020-06-02 05:49:10 +02:00
|
|
|
ShowTestCredentialsStatus(Images.StaticImages.ajax_loader, null);
|
2015-09-23 14:26:45 +02:00
|
|
|
textboxXSUserName.Enabled = textboxXSPassword.Enabled = testCredentialsButton.Enabled = false;
|
2015-09-15 14:48:50 +02:00
|
|
|
action.RunAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ShowTestCredentialsStatus(Image image, string errorMessage)
|
|
|
|
{
|
|
|
|
testCredentialsStatusImage.Visible = true;
|
|
|
|
testCredentialsStatusImage.Image = image;
|
|
|
|
errorLabel.Text = errorMessage;
|
|
|
|
errorLabel.Visible = !string.IsNullOrEmpty(errorMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HideTestCredentialsStatus()
|
|
|
|
{
|
|
|
|
testCredentialsStatusImage.Visible = false;
|
|
|
|
errorLabel.Visible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool SessionAuthorized(Session s, List<Role> authorizedRoles)
|
|
|
|
{
|
|
|
|
UserDetails ud = s.CurrentUserDetails;
|
|
|
|
foreach (Role r in s.Roles)
|
|
|
|
{
|
|
|
|
if (authorizedRoles.Contains(r))
|
|
|
|
{
|
2015-09-23 14:26:45 +02:00
|
|
|
log.DebugFormat("Subject '{0}' is authorized to complete the action", ud.UserName ?? ud.UserSid);
|
2015-09-15 14:48:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-09-23 14:26:45 +02:00
|
|
|
log.DebugFormat("Subject '{0}' is not authorized to complete the action", ud.UserName ?? ud.UserSid);
|
2015-09-15 14:48:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-19 15:15:59 +01:00
|
|
|
|
2020-06-02 05:49:10 +02:00
|
|
|
private void newAuthenticationRadioButton_CheckedChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
tableLayoutPanel5.Visible = false;
|
|
|
|
SetMyCitrixCredentials(existingAuthenticationRadioButton.Checked);
|
|
|
|
}
|
|
|
|
|
2017-02-09 16:16:11 +01:00
|
|
|
private void existingAuthenticationRadioButton_CheckedChanged(object sender, EventArgs e)
|
2016-01-19 15:15:59 +01:00
|
|
|
{
|
2020-06-02 05:49:10 +02:00
|
|
|
tableLayoutPanel5.Visible = false;
|
2017-02-09 16:16:11 +01:00
|
|
|
UpdateButtons();
|
2016-01-19 15:15:59 +01:00
|
|
|
}
|
2016-07-25 14:54:47 +02:00
|
|
|
|
2017-02-09 16:16:11 +01:00
|
|
|
private void authRubricLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
2016-07-25 14:54:47 +02:00
|
|
|
{
|
2017-02-09 16:16:11 +01:00
|
|
|
Program.OpenURL(Messages.MY_CITRIX_CREDENTIALS_URL);
|
2016-07-25 14:54:47 +02:00
|
|
|
}
|
2015-07-01 16:58:58 +02:00
|
|
|
}
|
2016-01-19 15:15:59 +01:00
|
|
|
}
|